Handling of underscores in code filenames. Added code to pointprocesses.

This commit is contained in:
Jan Benda 2015-11-21 13:20:38 +01:00
parent 2fa2b4eab8
commit 788d6aa8ab
10 changed files with 141 additions and 61 deletions

View File

@ -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}%
\captionof{exercisef}[\exercisefile]{}%
\captionsetup{font={normal,sf,it}}%
}%
{\ifthenelse{\equal{\exercisesource}{}}{}%
{\ifthenelse{\value{exercise}>\value{maxexercise}}{}%
{\lstinputlisting[belowskip=0pt]{\codepath\exercisesource}%
{\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}}}}%
{\addtocounter{lstlisting}{-1}%
\lstinputlisting[language={},title={\textbf{\tr{Output}{Ausgabe}:}},nolol=true,belowskip=0pt]{\codepath\exerciseoutput}}}}%
\end{mdframed}%
\renewcommand{\theenumi}{\saveenumi}}

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -2,8 +2,12 @@ function isicorr = isiserialcorr( isis, maxlag )
% serial correlation of interspike intervals
%
% 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

View File

@ -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

View File

@ -1,10 +1,14 @@
function spikes = poissonspikes(trials, rate, tmax)
% Generate spike times of a homogeneous poisson process
% Generate spike times of a homogeneous poisson process.
%
% 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

View File

@ -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

View File

@ -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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@ -13,6 +13,7 @@
\tableofcontents
\listoffigures
\lstlistoflistings
\listofexercisefs
\listofiboxfs
%\listofimportantfs