finished solutions for spike counts
This commit is contained in:
parent
b8b6e38792
commit
78b5c082d6
@ -1,37 +1,33 @@
|
|||||||
function fanoplot( spikes )
|
function fanoplot(spikes, titles)
|
||||||
% computes fano factor as a function of window size
|
% computes and plots fano factor as a function of window size
|
||||||
% spikes: a cell array of vectors of spike times
|
% spikes: a cell array of vectors of spike times
|
||||||
|
% titles: string that is used as a title for the plots
|
||||||
tmax = spikes{1}(end);
|
windows = logspace(-3.0, -0.5, 100);
|
||||||
windows = 0.01:0.05:0.01*tmax;
|
|
||||||
mc = windows;
|
mc = windows;
|
||||||
vc = windows;
|
vc = windows;
|
||||||
ff = windows;
|
ff = windows;
|
||||||
for j = 1:length(windows)
|
for j = 1:length(windows)
|
||||||
w = windows( j );
|
w = windows(j);
|
||||||
% collect counts:
|
counts = spikecounts(spikes, w);
|
||||||
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
|
|
||||||
% statistics for current window:
|
% statistics for current window:
|
||||||
mc(j) = mean( n );
|
mc(j) = mean(counts);
|
||||||
vc(j) = var( n );
|
vc(j) = var(counts);
|
||||||
ff(j) = vc( j )/mc( j );
|
ff(j) = vc(j)/mc(j);
|
||||||
end
|
end
|
||||||
|
|
||||||
subplot( 1, 2, 1 );
|
subplot(1, 2, 1);
|
||||||
scatter( mc, vc, 'filled' );
|
scatter(mc, vc, 'filled');
|
||||||
xlabel( 'Mean count' );
|
title(titles);
|
||||||
ylabel( 'Count variance' );
|
xlabel('Mean count');
|
||||||
|
ylabel('Count variance');
|
||||||
|
|
||||||
subplot( 1, 2, 2 );
|
subplot(1, 2, 2);
|
||||||
scatter( 1000.0*windows, ff, 'filled' );
|
scatter(1000.0*windows, ff, 'filled');
|
||||||
xlabel( 'Window W [ms]' );
|
title(titles);
|
||||||
ylabel( 'Fano factor' );
|
xlabel('Window [ms]');
|
||||||
|
ylabel('Fano factor');
|
||||||
|
xlim(1000.0*[windows(1) windows(end)])
|
||||||
|
ylim([0.0 1.1]);
|
||||||
|
set(gca, 'XScale', 'log');
|
||||||
end
|
end
|
||||||
|
|
||||||
|
9
pointprocesses/code/fanoplots.m
Normal file
9
pointprocesses/code/fanoplots.m
Normal 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
|
@ -15,13 +15,14 @@ function counts = spikecounts(spikes, w)
|
|||||||
counts = [];
|
counts = [];
|
||||||
for k = 1:length(spikes)
|
for k = 1:length(spikes)
|
||||||
times = spikes{k};
|
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
|
% for tk = 0:w:tmax-w
|
||||||
% nn = sum((times >= tk) & (times < tk+w));
|
% nn = sum((times >= tk) & (times < tk+w));
|
||||||
|
% %nn = length(times((times >= tk) & (times < tk+w)));
|
||||||
% %nn = length(find((times >= tk) & (times < tk+w)));
|
% %nn = length(find((times >= tk) & (times < tk+w)));
|
||||||
% counts = [counts nn];
|
% counts = [counts nn];
|
||||||
% end
|
% 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;
|
tbins = 0.5*w:w:tmax-0.5*w;
|
||||||
nn = hist(times, tbins);
|
nn = hist(times, tbins);
|
||||||
counts = [counts nn];
|
counts = [counts nn];
|
||||||
|
17
pointprocesses/code/spikecountshists.m
Normal file
17
pointprocesses/code/spikecountshists.m
Normal 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);
|
BIN
pointprocesses/exercises/fanoplotslifadapt.pdf
Normal file
BIN
pointprocesses/exercises/fanoplotslifadapt.pdf
Normal file
Binary file not shown.
BIN
pointprocesses/exercises/fanoplotspifou.pdf
Normal file
BIN
pointprocesses/exercises/fanoplotspifou.pdf
Normal file
Binary file not shown.
BIN
pointprocesses/exercises/fanoplotspoisson.pdf
Normal file
BIN
pointprocesses/exercises/fanoplotspoisson.pdf
Normal file
Binary file not shown.
@ -195,7 +195,7 @@ jan.benda@uni-tuebingen.de}
|
|||||||
|
|
||||||
\end{parts}
|
\end{parts}
|
||||||
|
|
||||||
\continue
|
\continuepage
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
\question \qt{Statistics of spike counts}
|
\question \qt{Statistics of spike counts}
|
||||||
Now let's have a look at the statistics of the spike counts.
|
Now let's have a look at the statistics of the spike counts.
|
||||||
@ -208,18 +208,25 @@ jan.benda@uni-tuebingen.de}
|
|||||||
width.
|
width.
|
||||||
\begin{solution}
|
\begin{solution}
|
||||||
\lstinputlisting{../code/spikecounts.m}
|
\lstinputlisting{../code/spikecounts.m}
|
||||||
% XXX
|
\newsolutionpage
|
||||||
|
\lstinputlisting{../code/spikecountshists.m}
|
||||||
|
\colorbox{white}{\includegraphics[width=1\textwidth]{spikecountshists}}
|
||||||
\end{solution}
|
\end{solution}
|
||||||
|
|
||||||
\part Write a function that computes for a range from window
|
\newsolutionpage
|
||||||
|
\part Write a function that computes for a range of window
|
||||||
widths the mean, the variance and the Fano factor of the
|
widths the mean, the variance and the Fano factor of the
|
||||||
corresponding spike counts. The function should the generate two
|
corresponding spike counts. The function should generate two
|
||||||
plots. One showing the spike count variance in dependence on the
|
plots. One showing the spike count variance in dependence on the
|
||||||
mean spike count. The other plot showing the Fano factor as a
|
mean spike count. The other plot showing the Fano factor as a
|
||||||
function of window width.
|
function of window width.
|
||||||
\begin{solution}
|
\begin{solution}
|
||||||
\lstinputlisting{../code/fanoplot.m}
|
\lstinputlisting{../code/fanoplot.m}
|
||||||
% XXX
|
\newsolutionpage
|
||||||
|
\lstinputlisting{../code/fanoplots.m}
|
||||||
|
\colorbox{white}{\includegraphics[width=1\textwidth]{fanoplotspoisson}}
|
||||||
|
\colorbox{white}{\includegraphics[width=1\textwidth]{fanoplotspifou}}
|
||||||
|
\colorbox{white}{\includegraphics[width=1\textwidth]{fanoplotslifadapt}}
|
||||||
\end{solution}
|
\end{solution}
|
||||||
|
|
||||||
\end{parts}
|
\end{parts}
|
||||||
|
BIN
pointprocesses/exercises/spikecountshists.pdf
Normal file
BIN
pointprocesses/exercises/spikecountshists.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user