summaryrefslogtreecommitdiff
path: root/code/matlab/random_topo.m
blob: 73d94acda4150127a076982de52078c61f2b9ec6 (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
%% config
% the values below should be set externally
% num_neurons = 10;
% connection_density = 0.5;
% inhibitory_fraction = 0.2;

min_weight = 0;
max_weight = 0.004;
fie = - 1;
fei = 15 / 20;
fii = 0;

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


%% init weights

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);


%% 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));


%% print resulting topology config

[ a, b ] = find(weights ~= 0); 
index = find(weights ~= 0);

format long

res = [ a, b, delay(index), weights(index) ];

for i=1:length(res),
  constness = (max(res(i,1:2)) / num_neurons >= 1 - inhibitory_fraction) % is src or dst and inhibitory neuron?
  if (constness)
    fprintf(2,'%d,%d,1,%f,%f\n', int32(res(i,1))-1, int32(res(i,2))-1, res(i,3), res(i,4));
  else
    fprintf(2,'%d,%d,0,%f,%f\n', int32(res(i,1))-1, int32(res(i,2))-1, res(i,3), res(i,4));
  end
end

contact: Jan Huwald // Impressum