summaryrefslogtreecommitdiff
path: root/octave/random_topo.octave
blob: 48a207f9e50004365453fd4762d687abd7727461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/octave --norc
%% config
% TODO: read these values from external definition
num_neurons = 1000;
connection_density = 0.1;
inhibitory_fraction = 0.2;

min_weight = 0;
max_weight = 0.004;
% implicit: fee = 1;
fie = - 0.9; % orig: - 1;
fei = 15 / 20;
fii = 0;

min_delay = 0.001; % hae? -> >= 0.1 ms
max_delay = 0.005; % hae? -> < 2 ms

max_fan_out = 126;
fan_out = max_fan_out + 1;
fan_out_miss = false;

% fix seed
% TODO: allow passing seed as param
% TODO: change PRNG to MT
rand("seed", str2num(argv(){1}));

%% init weights
while fan_out > max_fan_out,
  if fan_out_miss,
    fprintf(1,"generation failed: max fan out was %d, limit is %d\n", int32(fan_out), int32(max_fan_out));
  end;
  fan_out_miss = true;

  % init with rand in [0.1]
  weights = min_weight + (max_weight - min_weight) * rand(num_neurons);
  weights = weights .* (rand(num_neurons) < connection_density);
  
  l = num_neurons - inhibitory_fraction * num_neurons + 1;
  h = num_neurons;

  % make incoming and outgoing weight of each inhibitory neuron proportional
  weights(1:(l-1), l:h) = weights(l:h, 1:(l-1))';

  % scaling weights for inhibitory connections
  weights(l:h, 1:(l-1)) = fie * weights(l:h, 1:(l-1));
  weights(l:h, l:h)     = fii * weights(l:h, l:h);
  weights(1:(l-1), l:h) = fei * weights(1:(l-1), l:h);

  % count fan_out
  fan_out = max(sum(weights ~= 0, 2));
end

%% init delays
delay = min_delay + (max_delay - min_delay) * rand(num_neurons);

%% make inhibitory delays shorter
delay(1:(l-1), l:h) = 0.1 * delay(1:(l-1), l:h);
delay(l:h, 1:(l-1)) = 0.1 * delay(l:h, 1:(l-1));

%% output
format long E

% topology config
[ a, b ] = find(weights ~= 0);
index = find(weights ~= 0);
res = [ a, b, delay(index), weights(index) ];
for i=1:length(res),
  fprintf(2,"%d %d %e %e\n", int32(res(i,1))-1, int32(res(i,2))-1, res(i,3), res(i,4));
end

fprintf(1,"generation succesfull: %d synapses have been created, max fan out was %d (limit is %d)\n", int32(length(res)), int32(fan_out), int32(max_fan_out));
contact: Jan Huwald // Impressum