summaryrefslogtreecommitdiff
path: root/code/matlab
diff options
context:
space:
mode:
authorJan Huwald <jh@sotun.de>2012-05-07 19:53:27 (GMT)
committerJan Huwald <jh@sotun.de>2012-05-07 19:53:27 (GMT)
commit00b209240138660db1ded3ef3870023964ce6e4e (patch)
tree8ffaec780b060bdc478929aa714b8af2ee760671 /code/matlab
Initial commitHEADmaster
Diffstat (limited to 'code/matlab')
-rw-r--r--code/matlab/Makefile10
-rw-r--r--code/matlab/analye-perfomance.m14
-rw-r--r--code/matlab/analye-stdp-freq-dep.m12
-rw-r--r--code/matlab/analyze_weight_development.m30
-rw-r--r--code/matlab/plot_stdp_param_scout.m51
-rw-r--r--code/matlab/random_spikes.m15
-rw-r--r--code/matlab/random_topo.m60
7 files changed, 192 insertions, 0 deletions
diff --git a/code/matlab/Makefile b/code/matlab/Makefile
new file mode 100644
index 0000000..3546e44
--- /dev/null
+++ b/code/matlab/Makefile
@@ -0,0 +1,10 @@
+.PHONY: all symlinks clean
+
+all: symlinks
+
+symlinks:
+ ls | grep '.m$$' | sed 's/\.m$$//' | xargs -n1 ln -f -s ../glue/exec-matlab
+
+clean:
+ ls | grep '.m$$' | sed 's/\.m$$//' | xargs rm || true
+ rm *~ || true \ No newline at end of file
diff --git a/code/matlab/analye-perfomance.m b/code/matlab/analye-perfomance.m
new file mode 100644
index 0000000..75b399b
--- /dev/null
+++ b/code/matlab/analye-perfomance.m
@@ -0,0 +1,14 @@
+%% load data
+perf = load('performance.out');
+perf = perf > 1.0;
+s = length(perf);
+
+%% compute sliding avergae
+ws = 250; % window size
+perf_avg = zeros(s-ws,1);
+for i = 1:(s-ws)
+ perf_avg(i,1) = mean(perf(i:(i+ws),1));
+end
+
+%% plot
+plot(perf_avg); \ No newline at end of file
diff --git a/code/matlab/analye-stdp-freq-dep.m b/code/matlab/analye-stdp-freq-dep.m
new file mode 100644
index 0000000..85c4030
--- /dev/null
+++ b/code/matlab/analye-stdp-freq-dep.m
@@ -0,0 +1,12 @@
+
+raw = load('synapse.destilled');
+
+res = [];
+for i=1:(floor(length(raw) / 200)),
+ row = raw(((i*200)-199):((i*200)-99),2)';
+ res(i,:) = [mean(row), var(row)];
+end
+
+for i=1:length(res),
+ fprintf(2,'%d, %f, %f\n', int32(i), res(i,1), res(i,2))
+end \ No newline at end of file
diff --git a/code/matlab/analyze_weight_development.m b/code/matlab/analyze_weight_development.m
new file mode 100644
index 0000000..da34cd4
--- /dev/null
+++ b/code/matlab/analyze_weight_development.m
@@ -0,0 +1,30 @@
+%% -- load the synapse file
+
+syn_raw = load('synapse.out');
+
+%% -- generate mean weights (and some config stuff)
+
+num_syn = 96227;
+num_steps = length(syn_raw) / num_syn;
+types = [ 1*ones(100,1); 2*ones(600,1); 3*ones(100,1); 4*ones(200,1) ];
+
+syn_mean = zeros(num_steps, 16);
+syn_count = zeros(num_steps, 16);
+for i = 1:num_steps
+ ba = (i-1)*num_syn+1;
+ for j = ba:(ba+num_syn-1)
+ l = syn_raw(j,:);
+ src = l(1,2) + 1;
+ dst = l(1,3) + 1;
+ w = l(1,5);
+
+ syn_mean(i, 4*types(src)+types(dst)-4) = syn_mean(i, 4*types(src)+types(dst)-4) + w;
+ syn_count(i, 4*types(src)+types(dst)-4) = syn_count(i, 4*types(src)+types(dst)-4) + 1;
+ end
+end
+syn_mean = syn_mean ./ syn_count;
+
+%% plot it
+
+plot(syn_mean);
+legend('II', 'IB', 'IO', 'IX', 'BI', 'BB', 'BO', 'BX', 'OI', 'OB', 'OO', 'OX', 'XI', 'XB', 'XO', 'XX'); \ No newline at end of file
diff --git a/code/matlab/plot_stdp_param_scout.m b/code/matlab/plot_stdp_param_scout.m
new file mode 100644
index 0000000..2342fd7
--- /dev/null
+++ b/code/matlab/plot_stdp_param_scout.m
@@ -0,0 +1,51 @@
+%% load the raw data from synapses output file
+raw = load('synapse.out');
+
+
+%% get mean and variance from the 1000 neurons
+ns = 999;
+l = floor(length(raw)/ns);
+raw2 = zeros(l,1);
+raw2_var = zeros(l,1);
+for i=1:l,
+ % hint: adapted to read only the first 100 out of 1000 neurons
+ raw2(i,1) = mean(raw((i*ns-ns+1):(i*ns-900), 4), 1);
+ raw2_var(i,1) = var(raw((i*ns-ns+1):(i*ns-900), 4), 1);
+end
+
+%% erase duplicate lines (the silence period of simulation)
+l2 = floor(l/2) - 1;
+raw3 = zeros(l2,1);
+raw3_var = zeros(l2,1);
+for i=0:l2,
+ raw3(i+1,1) = raw2((2*i+1),1);
+ raw3_var(i+1,1) = raw2_var((2*i+1),1);
+end
+
+%% display graphs
+nx = 4;
+nt = 100;
+res = zeros(nx,nx);
+k =1;
+for i=0:(nx-1),
+ for j=0:(nx-1),
+ cur = raw3( ((i*nx + j)*nt + 1):((i*nx + j)*nt + nt - 1), 1);
+ cur_var = raw3_var( ((i*nx + j)*nt + 1):((i*nx + j)*nt + nt - 1), 1);
+ tr = (cur(nt - 1) > 0) + 2 * (sum(cur < 0) > 0);
+ res(i+1,j+1) = tr;
+
+ %if ((mod(i,5) == 0) && (mod(j,5) == 0)),
+ %if (tr == 2),
+ %if (i<=10 && j>10),
+ subplot(nx, nx, k);
+ k = k + 1;
+ %if (tr == 3),
+ plot( [ 1:0.5:(nt/2) ]', [ cur, zeros(nt-1, 1), cur-cur_var, cur+cur_var ]);
+ title( sprintf('i=%d, j=%d', i, j));
+ %end;
+ %axis([-1 (nt+1) -1 1])
+ set(gca,'xtick',0:10:(nt/2))
+ %set(gca,'ytick',[])
+ %end;
+ end;
+end; \ No newline at end of file
diff --git a/code/matlab/random_spikes.m b/code/matlab/random_spikes.m
new file mode 100644
index 0000000..89baf02
--- /dev/null
+++ b/code/matlab/random_spikes.m
@@ -0,0 +1,15 @@
+% fill the extenrally
+%num_neurons = 2; % wich should receive a spike
+%spike_freq = 1; % local per neuron per second
+%duration = 2; % [s]
+
+current = 100; % this should drive my neurons crazy
+
+format long
+
+num = num_neurons * spike_freq * duration;
+res = [ sort(rand(num, 1) .* duration), floor(rand(num, 1) .* num_neurons), ones(num, 1) * current ];
+
+for i=1:length(res),
+ fprintf(2,'%f,%d,%f\n', res(i,1), int32(floor(res(i,2))), res(i,3))
+end
diff --git a/code/matlab/random_topo.m b/code/matlab/random_topo.m
new file mode 100644
index 0000000..73d94ac
--- /dev/null
+++ b/code/matlab/random_topo.m
@@ -0,0 +1,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