diff --git a/header.tex b/header.tex index 65f1e75..d636561 100644 --- a/header.tex +++ b/header.tex @@ -10,6 +10,9 @@ \newcommand{\tr}[2]{#2} % de \usepackage[ngerman]{babel} +%%%% encoding %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usepackage[T1]{fontenc} + %%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage[left=25mm,right=25mm,top=20mm,bottom=30mm]{geometry} \usepackage{pslatex} % nice font for pdf file @@ -216,24 +219,34 @@ % Innerhalb der exercise Umgebung ist enumerate umdefiniert, um (a), (b), (c), .. zu erzeugen. \usepackage{ifthen} \usepackage{mdframed} +\usepackage{xstring} +\newcommand{\codepath}{} +\DeclareFloatingEnvironment[ + fileext=loe, + listname={\tr{Exercises}{\"Ubungen}}, + name={\tr{Exercise}{\"Ubung}}, + placement=t +]{exercisef} \newcounter{maxexercise} \setcounter{maxexercise}{10000} % show listings up to exercise maxexercise -\newcounter{exercise}[chapter] -\renewcommand{\theexercise}{\arabic{exercise}} -\newcommand{\codepath}{} \newenvironment{exercise}[2]% {\newcommand{\exercisesource}{#1}% + \newcommand{\exercisefile}{\protect\StrSubstitute{#1}{_}{\_}}% \newcommand{\exerciseoutput}{#2}% \setlength{\fboxsep}{2mm}% \newcommand{\saveenumi}{\theenumi}\renewcommand{\labelenumi}{(\alph{enumi})}% - \stepcounter{exercise}% + \captionsetup{singlelinecheck=off,hypcap=false,labelfont={large,sf,it,bf},font={large,sf,it,bf},skip={0.5ex}} \begin{mdframed}[linewidth=0pt,backgroundcolor=exerciseback]% - \noindent\textbf{\tr{Exercise}{\"Ubung} \thechapter.\theexercise:}\newline}% -{\ifthenelse{\equal{\exercisesource}{}}{}% - {\ifthenelse{\value{exercise}>\value{maxexercise}}{}% - {\lstinputlisting[belowskip=0pt]{\codepath\exercisesource}% - \ifthenelse{\equal{\exerciseoutput}{}}{}% - {\addtocounter{lstlisting}{-1}\lstinputlisting[language={},title={\textbf{\tr{Output}{Ausgabe}:}},nolol=true,belowskip=0pt]{\codepath\exerciseoutput}}}}% + \captionof{exercisef}[\exercisefile]{}% + \captionsetup{font={normal,sf,it}}% + }% + {\ifthenelse{\equal{\exercisesource}{}}{}% + {\ifthenelse{\value{exercise}>\value{maxexercise}}{}% + {\addtocounter{lstlisting}{-1}% + \lstinputlisting[belowskip=0pt,aboveskip=1ex,nolol=true,title={\textbf{Listing:} \exercisefile}]{\codepath\exercisesource}% + \ifthenelse{\equal{\exerciseoutput}{}}{}% + {\addtocounter{lstlisting}{-1}% + \lstinputlisting[language={},title={\textbf{\tr{Output}{Ausgabe}:}},nolol=true,belowskip=0pt]{\codepath\exerciseoutput}}}}% \end{mdframed}% \renewcommand{\theenumi}{\saveenumi}} diff --git a/pointprocesses/code/counthist.m b/pointprocesses/code/counthist.m index 15d431e..9d9889a 100644 --- a/pointprocesses/code/counthist.m +++ b/pointprocesses/code/counthist.m @@ -1,9 +1,13 @@ function [counts, bins] = counthist(spikes, w) -% computes count histogram and compare them with Poisson distribution +% computes count histogram and compare with Poisson distribution % % [counts, bins] = counthist(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: the histogram of counts normalized to probabilities % bins: the bin centers for the histogram @@ -27,11 +31,14 @@ function [counts, bins] = counthist(spikes, w) rate = (length(times)-1)/(times(end) - times(1)); r = [ r rate ]; end + % histogram of spike counts: maxn = max( n ); [counts, bins ] = hist( n, 0:1:maxn+10 ); % normalize to probabilities: counts = counts / sum( counts ); + + % plot: if nargout == 0 bar( bins, counts ); hold on; diff --git a/pointprocesses/code/isi_hist.m b/pointprocesses/code/isi_hist.m new file mode 100644 index 0000000..6194948 --- /dev/null +++ b/pointprocesses/code/isi_hist.m @@ -0,0 +1,29 @@ +function [pdf, centers] = isi_hist(isis, binwidth) +% Compute normalized histogram of interspike intervals. +% +% [pdf, centers] = isi_hist(isis, binwidth) +% +% Arguments: +% isis: vector of interspike intervals in seconds +% binwidth: optional width in seconds to be used for the isi bins +% +% Returns: +% pdf: vector with probability density of interspike intervals in Hz +% centers: vector with corresponding centers of interspikeintervalls in seconds + + if nargin < 2 + % compute good binwidth: + nperbin = 200; % average number of data points per bin + bins = length( isis )/nperbin; % number of bins + binwidth = max( isis )/bins; + if binwidth < 5e-4 % half a millisecond + binwidth = 5e-4; + end + end + bins = 0.5*binwidth:binwidth:max(isis); + % histogram data: + [ nelements, centers ] = hist(isis, bins); + % normalization (integral = 1): + pdf = nelements / sum(nelements) / binwidth; +end + diff --git a/pointprocesses/code/isihist.m b/pointprocesses/code/isihist.m deleted file mode 100644 index 17974cc..0000000 --- a/pointprocesses/code/isihist.m +++ /dev/null @@ -1,34 +0,0 @@ -function isihist( isis, binwidth ) -% plot histogram of interspike intervals -% -% isihist(isis, binwidth) -% isis: vector of interspike intervals in seconds -% binwidth: optional width in seconds to be used for the isi bins - - if nargin < 2 - nperbin = 200; % average number of data points per bin - bins = length( isis )/nperbin; % number of bins - binwidth = max( isis )/bins; - if binwidth < 5e-4 % half a millisecond - binwidth = 5e-4; - end - end - bins = 0.5*binwidth:binwidth:max(isis); - % histogram: - [ nelements, centers ] = hist( isis, bins ); - % normalization (integral = 1): - nelements = nelements / sum( nelements ) / binwidth; - % plot: - bar( 1000.0*centers, nelements ); - xlabel( 'ISI [ms]' ) - ylabel( 'p(ISI) [1/s]') - % annotation: - misi = mean( isis ); - sdisi = std( isis ); - disi = sdisi^2.0/2.0/misi^3; - text( 0.95, 0.8, sprintf( 'mean=%.1f ms', 1000.0*misi ), 'Units', 'normalized', 'HorizontalAlignment', 'right' ) - text( 0.95, 0.7, sprintf( 'std=%.1f ms', 1000.0*sdisi ), 'Units', 'normalized', 'HorizontalAlignment', 'right' ) - text( 0.95, 0.6, sprintf( 'CV=%.2f', sdisi/misi ), 'Units', 'normalized', 'HorizontalAlignment', 'right' ) - %text( 0.5, 0.3, sprintf( 'D=%.1f Hz', disi ), 'Units', 'normalized' ) -end - diff --git a/pointprocesses/code/isiserialcorr.m b/pointprocesses/code/isiserialcorr.m index c93fb5e..8b7aca9 100644 --- a/pointprocesses/code/isiserialcorr.m +++ b/pointprocesses/code/isiserialcorr.m @@ -1,9 +1,13 @@ -function isicorr = isiserialcorr( isis, maxlag ) +function isicorr = isiserialcorr(isis, maxlag) % serial correlation of interspike intervals % -% isicorr = isiserialcorr( isis, maxlag ) +% isicorr = isiserialcorr(isis, maxlag) +% +% Arguments: % isis: vector of interspike intervals in seconds % maxlag: the maximum lag in seconds +% +% Returns: % isicorr: vector with the serial correlations for lag 0 to maxlag lags = 0:maxlag; @@ -11,7 +15,7 @@ function isicorr = isiserialcorr( isis, maxlag ) for k = 1:length(lags) lag = lags(k); if length( isis ) > lag+10 % ensure "enough" data - % DANGER: the arguments to corr must be column vectors! + % NOTE: the arguments to corr must be column vectors! % We insure this in the isis() function that generats the isis. isicorr(k) = corr( isis(1:end-lag), isis(lag+1:end) ); end diff --git a/pointprocesses/code/plot_isi_hist.m b/pointprocesses/code/plot_isi_hist.m new file mode 100644 index 0000000..d49b5b2 --- /dev/null +++ b/pointprocesses/code/plot_isi_hist.m @@ -0,0 +1,28 @@ +function plot_isi_hist(isis, binwidth) +% Plot and annotate histogram of interspike intervals. +% +% isihist(isis, binwidth) +% +% Arguments: +% isis: vector of interspike intervals in seconds +% binwidth: optional width in seconds to be used for the isi bins + + if nargin < 2 + [pdf, centers] = isi_hist(isis); + else + [pdf, centers] = isi_hist(isis, binwidth); + end + + bar(1000.0*centers, nelements); % milliseconds on x-axis + xlabel('ISI [ms]') + ylabel('p(ISI) [1/s]') + % annotation: + misi = mean(isis); + sdisi = std(isis); + disi = sdisi^2.0/2.0/misi^3; + text(0.95, 0.8, sprintf('mean=%.1f ms', 1000.0*misi), 'Units', 'normalized', 'HorizontalAlignment', 'right') + text(0.95, 0.7, sprintf('std=%.1f ms', 1000.0*sdisi), 'Units', 'normalized', 'HorizontalAlignment', 'right') + text(0.95, 0.6, sprintf('CV=%.2f', sdisi/misi), 'Units', 'normalized', 'HorizontalAlignment', 'right') + %text(0.5, 0.3, sprintf('D=%.1f Hz', disi), 'Units', 'normalized') +end + diff --git a/pointprocesses/code/poissonspikes.m b/pointprocesses/code/poissonspikes.m index 37f2234..3eb4a86 100644 --- a/pointprocesses/code/poissonspikes.m +++ b/pointprocesses/code/poissonspikes.m @@ -1,10 +1,14 @@ -function spikes = poissonspikes( trials, rate, tmax ) -% Generate spike times of a homogeneous poisson process +function spikes = poissonspikes(trials, rate, tmax) +% Generate spike times of a homogeneous poisson process. % -% spikes = poissonspikes( trials, rate, tmax ) +% spikes = poissonspikes(trials, rate, tmax) +% +% Arguments: % trials: number of trials that should be generated % rate: the rate of the Poisson process in Hertz % tmax: the duration of each trial in seconds +% +% Returns: % spikes: a cell array of vectors of spike times in seconds dt = 3.33e-5; @@ -16,7 +20,8 @@ function spikes = poissonspikes( trials, rate, tmax ) end spikes = cell(trials, 1); for k=1:trials - x = rand(round(tmax/dt), 1); % uniform random numbers for each bin + % uniform random numbers for each bin: + x = rand(round(tmax/dt), 1); spikes{k} = find(x < p) * dt; end end diff --git a/pointprocesses/lecture/Makefile b/pointprocesses/lecture/Makefile index 308f276..44c7d3b 100644 --- a/pointprocesses/lecture/Makefile +++ b/pointprocesses/lecture/Makefile @@ -11,7 +11,7 @@ all: pdf slides thumbs # script: pdf : $(BASENAME)-chapter.pdf -$(BASENAME)-chapter.pdf : $(BASENAME)-chapter.tex $(BASENAME).tex $(GPTTEXFILES) $(PYPDFFILES) +$(BASENAME)-chapter.pdf : $(BASENAME)-chapter.tex $(BASENAME).tex ../../header.tex $(GPTTEXFILES) $(PYPDFFILES) CHAPTER=$$(( $$(sed -n -e '/contentsline {chapter}/{s/.*numberline {\([0123456789]*\)}.*/\1/; p}' $(BASENAME).aux) - 1 )); \ PAGE=$$(sed -n -e '/contentsline {chapter}/{s/.*numberline {.*}.*}{\(.*\)}{chapter.*/\1/; p}' $(BASENAME).aux); \ sed -i -e "s/setcounter{page}{.*}/setcounter{page}{$$PAGE}/; s/setcounter{chapter}{.*}/setcounter{chapter}{$$CHAPTER}/" $(BASENAME)-chapter.tex diff --git a/pointprocesses/lecture/pointprocesses.tex b/pointprocesses/lecture/pointprocesses.tex index 7f60d5a..516e118 100644 --- a/pointprocesses/lecture/pointprocesses.tex +++ b/pointprocesses/lecture/pointprocesses.tex @@ -54,7 +54,7 @@ erzeugt. Zum Beispiel: \begin{figure}[t] \texpicture{pointprocessscetch} \titlecaption{\label{pointprocessscetchfig} Statistik von - Punktprozessesen.}{Ein Punktprozess ist eine Abfolge von + Punktprozessen.}{Ein Punktprozess ist eine Abfolge von Zeitpunkten $t_i$ die auch durch die Intervalle $T_i=t_{i+1}-t_i$ oder die Anzahl der Ereignisse $n_i$ beschrieben werden kann. } \end{figure} @@ -89,7 +89,7 @@ kann mit den \"ublichen Gr\"o{\ss}en beschrieben werden. \end{figure} \begin{exercise}{isis.m}{} - Schreibe eine Funktion, die aus mehreren trials von Spiketrains die + Schreibe eine Funktion \code{isis()}, die aus mehreren trials von Spiketrains die Interspikeintervalle bestimmt und diese in einem Vektor zur\"uckgibt. Jeder trial der Spiketrains ist ein Vektor mit den Spikezeiten gegeben in Sekunden als Element in einem \codeterm{cell-array}. @@ -110,11 +110,18 @@ kann mit den \"ublichen Gr\"o{\ss}en beschrieben werden. \frac{\sigma_{ISI}^2}{2\mu_{ISI}^3}$. \end{itemize} -\begin{exercise}{isihist.m}{} - Schreibe eine Funktion, die einen Vektor mit Interspikeintervallen - entgegennimmt und daraus ein Histogramm der Interspikeintervalle - plottet. Das Histogramm soll zus\"atzlich mit Mittelwert, - Standardabweichung und Korrelationskoeffizient der +\begin{exercise}{isi_hist.m}{} + Schreibe eine Funktion \code{isi\_hist()}, die einen Vektor mit Interspikeintervallen + entgegennimmt und daraus ein normalisiertes Histogramm der Interspikeintervalle + berechnet. +\end{exercise} + +\begin{exercise}{plot_isi_hist.m}{} + Schreibe eine Funktion, die die Histogrammdaten der Funktion + \code{isi\_hist()} entgegennimmt, um das Histogramm zu plotten. Im + Plot sollen die Interspikeintervalle in Millisekunden aufgetragen + werden. Das Histogramm soll zus\"atzlich mit Mittelwert, + Standardabweichung und Variationskoeffizient der Interspikeintervalle annotiert werden. \end{exercise} @@ -141,6 +148,11 @@ zwischen aufeinander folgenden Intervallen getrennt durch \enterm{lag} $k$: aufgetragen (\figref{returnmapfig}). $\rho_0=1$ (Korrelation jedes Intervalls mit sich selber). +\begin{exercise}{isiserialcorr.m}{} + Schreibe eine Funktion \code{isiserialcorr()}, die einen Vektor mit Interspikeintervallen + entgegennimmt und daraus die seriellen Korrelationen berechnet und plottet. +\end{exercise} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Z\"ahlstatistik} @@ -180,6 +192,15 @@ Zeit, \determ{Feuerrate}) gemessen in Hertz % \titlecaption{\label{fanofig}Fano factor.}{} % \end{figure} +\begin{exercise}{counthist.m}{} + Schreibe eine Funktion \code{counthist()}, die aus mehreren trials + von Spiketrains die Verteilung der Anzahl der Spikes in Fenstern + einer der Funktion \"ubergegebenen Breite bestimmt, das Histogramm + plottet und zur\"uckgibt. Jeder trial der Spiketrains ist ein Vektor + mit den Spikezeiten gegeben in Sekunden als Element in einem + \codeterm{cell-array}. +\end{exercise} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Homogener Poisson Prozess} @@ -211,7 +232,7 @@ Zeit ab: $\lambda = \lambda(t)$. zweier Poissonprozesse.}{} \end{figure} -Der homogne Poissonprozess hat folgende Eigenschaften: +Der homogene Poissonprozess hat folgende Eigenschaften: \begin{itemize} \item Die Intervalle $T$ sind exponentiell verteilt: $p(T) = \lambda e^{-\lambda T}$ (\figref{hompoissonisihfig}). \item Das mittlere Intervall ist $\mu_{ISI} = \frac{1}{\lambda}$ . @@ -233,6 +254,12 @@ Der homogne Poissonprozess hat folgende Eigenschaften: \titlecaption{\label{hompoissoncountfig}Z\"ahlstatistik von Poisson Spikes.}{} \end{figure} +\begin{exercise}{poissonspikes.m}{} + Schreibe eine Funktion \code{poissonspikes()}, die die Spikezeiten + eines homogenen Poisson-Prozesses mit gegebener Rate in Hertz f\"ur + eine Anzahl von trials gegebener maximaler L\"ange in Sekunden in + einem \codeterm{cell-array} zur\"uckgibt. +\end{exercise} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/scientificcomputing-script.tex b/scientificcomputing-script.tex index 36c8cb2..8eaf472 100644 --- a/scientificcomputing-script.tex +++ b/scientificcomputing-script.tex @@ -13,6 +13,7 @@ \tableofcontents \listoffigures \lstlistoflistings +\listofexercisefs \listofiboxfs %\listofimportantfs