finished solutions for spike counts

This commit is contained in:
2017-12-05 15:28:06 +01:00
parent b8b6e38792
commit 78b5c082d6
9 changed files with 63 additions and 33 deletions

View File

@@ -1,37 +1,33 @@
function fanoplot( spikes )
% computes fano factor as a function of window size
function fanoplot(spikes, titles)
% computes and plots fano factor as a function of window size
% spikes: a cell array of vectors of spike times
tmax = spikes{1}(end);
windows = 0.01:0.05:0.01*tmax;
% titles: string that is used as a title for the plots
windows = logspace(-3.0, -0.5, 100);
mc = windows;
vc = windows;
ff = windows;
for j = 1:length(windows)
w = windows( j );
% collect counts:
n = [];
for k = 1:length(spikes)
for tk = 0:w:tmax-w
nn = sum( ( spikes{k} >= tk ) & ( spikes{k} < tk+w ) );
%nn = length( find( ( spikes{k} >= tk ) & ( spikes{k} < tk+w ) ) );
n = [ n nn ];
end
end
w = windows(j);
counts = spikecounts(spikes, w);
% statistics for current window:
mc(j) = mean( n );
vc(j) = var( n );
ff(j) = vc( j )/mc( j );
mc(j) = mean(counts);
vc(j) = var(counts);
ff(j) = vc(j)/mc(j);
end
subplot( 1, 2, 1 );
scatter( mc, vc, 'filled' );
xlabel( 'Mean count' );
ylabel( 'Count variance' );
subplot(1, 2, 1);
scatter(mc, vc, 'filled');
title(titles);
xlabel('Mean count');
ylabel('Count variance');
subplot( 1, 2, 2 );
scatter( 1000.0*windows, ff, 'filled' );
xlabel( 'Window W [ms]' );
ylabel( 'Fano factor' );
subplot(1, 2, 2);
scatter(1000.0*windows, ff, 'filled');
title(titles);
xlabel('Window [ms]');
ylabel('Fano factor');
xlim(1000.0*[windows(1) windows(end)])
ylim([0.0 1.1]);
set(gca, 'XScale', 'log');
end

View File

@@ -0,0 +1,9 @@
spikes{1} = poissonspikes;
spikes{2} = pifouspikes;
spikes{3} = lifadaptspikes;
idents = {'poisson', 'pifou', 'lifadapt'};
for k = 1:3
figure(k)
fanoplot(spikes{k}, titles{k});
savefigpdf(gcf, sprintf('fanoplots%s.pdf', idents{k}), 20, 7);
end

View File

@@ -15,13 +15,14 @@ function counts = spikecounts(spikes, w)
counts = [];
for k = 1:length(spikes)
times = spikes{k};
% alternative 1: count the number of spikes in each window:
% method 1: count the number of spikes in each window:
% for tk = 0:w:tmax-w
% nn = sum((times >= tk) & (times < tk+w));
% %nn = length(times((times >= tk) & (times < tk+w)));
% %nn = length(find((times >= tk) & (times < tk+w)));
% counts = [counts nn];
% end
% alternative 2: use the hist() function to do that!
% method 2: use the hist() function to do that!
tbins = 0.5*w:w:tmax-0.5*w;
nn = hist(times, tbins);
counts = [counts nn];

View File

@@ -0,0 +1,17 @@
w = 0.1;
bins = 0.0:1.0:10.0;
counts{1} = spikecounts(poissonspikes, w);
counts{2} = spikecounts(pifouspikes, w);
counts{3} = spikecounts(lifadaptspikes, w);
titles = {'Poisson', 'PIF OU', 'LIF adapt'};
for k = 1:3
subplot(1, 3, k);
[h, b] = hist(counts{k}, bins);
bar(b, h/sum(h));
title(titles{k})
xlabel('Spike count');
xlim([-0.5, 8.5]);
ylim([0.0 0.8]);
end
savefigpdf(gcf, 'spikecountshists.pdf', 20, 7);