From 41379087b7d87f2d248de7362ea02fbc23eac191 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 4 Dec 2017 23:05:33 +0100 Subject: [PATCH] added fano factor exercise --- pointprocesses/code/fanoplot.m | 37 +++++++++++++++++++ pointprocesses/code/spikecounts.m | 29 +++++++++++++++ pointprocesses/exercises/pointprocesses01.tex | 25 ++++++++++++- 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 pointprocesses/code/fanoplot.m create mode 100644 pointprocesses/code/spikecounts.m diff --git a/pointprocesses/code/fanoplot.m b/pointprocesses/code/fanoplot.m new file mode 100644 index 0000000..7998859 --- /dev/null +++ b/pointprocesses/code/fanoplot.m @@ -0,0 +1,37 @@ +function fanoplot( spikes ) +% computes 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; + 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 + % statistics for current window: + mc(j) = mean( n ); + vc(j) = var( n ); + ff(j) = vc( j )/mc( j ); + end + + subplot( 1, 2, 1 ); + scatter( mc, vc, 'filled' ); + xlabel( 'Mean count' ); + ylabel( 'Count variance' ); + + subplot( 1, 2, 2 ); + scatter( 1000.0*windows, ff, 'filled' ); + xlabel( 'Window W [ms]' ); + ylabel( 'Fano factor' ); +end + diff --git a/pointprocesses/code/spikecounts.m b/pointprocesses/code/spikecounts.m new file mode 100644 index 0000000..0703e4b --- /dev/null +++ b/pointprocesses/code/spikecounts.m @@ -0,0 +1,29 @@ +function counts = spikecounts(spikes, w) +% Compute vector of spike counts. +% +% counts = spikecounts(spikes, w) +% +% Arguments: +% spikes: a cell array of vectors of spike times in seconds +% w: observation window duration in seconds for computing the counts +% +% Returns: +% counts: vector of spike counts + + % collect spike counts: + tmax = spikes{1}(end); + counts = []; + for k = 1:length(spikes) + times = spikes{k}; +% alternative 1: count the number of spikes in each window: +% for tk = 0:w:tmax-w +% nn = sum((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! + tbins = 0.5*w:w:tmax-0.5*w; + nn = hist(times, tbins); + counts = [counts nn]; + end +end diff --git a/pointprocesses/exercises/pointprocesses01.tex b/pointprocesses/exercises/pointprocesses01.tex index 15cc5a2..ce2a417 100644 --- a/pointprocesses/exercises/pointprocesses01.tex +++ b/pointprocesses/exercises/pointprocesses01.tex @@ -173,7 +173,8 @@ jan.benda@uni-tuebingen.de} \colorbox{white}{\includegraphics[width=1\textwidth]{isihist}} \end{solution} - \part XXX Add return map!!! XXX Write a function that computes and plots the serial + % XXX Add return map!!! XXX + \part Write a function that computes and plots the serial correlations of interspike intervals for lags upto \code{maxlag}. The serial correlations $\rho_k$ for lag $k$ of the interspike intervals $T_i$ are the correlation coefficients @@ -192,6 +193,28 @@ jan.benda@uni-tuebingen.de} \colorbox{white}{\includegraphics[width=1\textwidth]{serialcorr}} \end{solution} + \part Write a function that counts and returns the number of + spikes in windows of a given width $W$. + + Use this function to generate a histogram of spike counts for the + data of the three types of neurons. Use 100\,ms for the window + width. + \begin{solution} + \lstinputlisting{../code/spikecounts.m} + % XXX + \end{solution} + + \part Write a function that computes for a range from window + widths the mean, the variance and the Fano factor of the + corresponding spike counts. The function should the generate two + plots. One showing the spike count variance in dependence on the + mean spike count. The other plot showing the Fano factor as a + function of window width. + \begin{solution} + \lstinputlisting{../code/fanoplot.m} + % XXX + \end{solution} + \end{parts} \end{questions}