Started working on pointprocesses

This commit is contained in:
2015-10-25 22:22:54 +01:00
parent d9252e9cbf
commit 857373c125
24 changed files with 892 additions and 688 deletions

View File

@@ -0,0 +1,35 @@
BASENAME=pointprocesses
TEXFILES=$(wildcard $(BASENAME)??.tex)
EXERCISES=$(TEXFILES:.tex=.pdf)
SOLUTIONS=$(EXERCISES:pointprocesses%=pointprocesses-solutions%)
.PHONY: pdf exercises solutions watch watchexercises watchsolutions clean
pdf : $(SOLUTIONS) $(EXERCISES)
exercises : $(EXERCISES)
solutions : $(SOLUTIONS)
$(SOLUTIONS) : pointprocesses-solutions%.pdf : pointprocesses%.tex instructions.tex
{ echo "\\documentclass[answers,12pt,a4paper,pdftex]{exam}"; sed -e '1d' $<; } > $(patsubst %.pdf,%.tex,$@)
pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) || true
rm $(patsubst %.pdf,%,$@).[!p]*
$(EXERCISES) : %.pdf : %.tex instructions.tex
pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true
watch :
while true; do ! make -q pdf && make pdf; sleep 0.5; done
watchexercises :
while true; do ! make -q exercises && make exercises; sleep 0.5; done
watchsolutions :
while true; do ! make -q solutions && make solutions; sleep 0.5; done
clean :
rm -f *~ *.aux *.log *.out
cleanup : clean
rm -f $(SOLUTIONS) $(EXERCISES)

View File

@@ -0,0 +1,11 @@
\vspace*{-6.5ex}
\begin{center}
\textbf{\Large Einf\"uhrung in die wissenschaftliche Datenverarbeitung}\\[1ex]
{\large Jan Grewe, Jan Benda}\\[-3ex]
Abteilung Neuroethologie \hfill --- \hfill Institut f\"ur Neurobiologie \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\
\end{center}
\ifprintanswers%
\else
\fi

View File

@@ -0,0 +1,202 @@
\documentclass[12pt,a4paper,pdftex]{exam}
\usepackage[german]{babel}
\usepackage{pslatex}
\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref}
%%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry}
\pagestyle{headandfoot}
\ifprintanswers
\newcommand{\stitle}{: L\"osungen}
\else
\newcommand{\stitle}{}
\fi
\header{{\bfseries\large \"Ubung 6\stitle}}{{\bfseries\large Statistik}}{{\bfseries\large 27. Oktober, 2015}}
\firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email:
jan.benda@uni-tuebingen.de}
\runningfooter{}{\thepage}{}
\setlength{\baselineskip}{15pt}
\setlength{\parindent}{0.0cm}
\setlength{\parskip}{0.3cm}
\renewcommand{\baselinestretch}{1.15}
%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings}
\lstset{
language=Matlab,
basicstyle=\ttfamily\footnotesize,
numbers=left,
numberstyle=\tiny,
title=\lstname,
showstringspaces=false,
commentstyle=\itshape\color{darkgray},
breaklines=true,
breakautoindent=true,
columns=flexible,
frame=single,
xleftmargin=1em,
xrightmargin=1em,
aboveskip=10pt
}
%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{dsfont}
\newcommand{\naZ}{\mathds{N}}
\newcommand{\gaZ}{\mathds{Z}}
\newcommand{\raZ}{\mathds{Q}}
\newcommand{\reZ}{\mathds{R}}
\newcommand{\reZp}{\mathds{R^+}}
\newcommand{\reZpN}{\mathds{R^+_0}}
\newcommand{\koZ}{\mathds{C}}
%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\continue}{\ifprintanswers%
\else
\vfill\hspace*{\fill}$\rightarrow$\newpage%
\fi}
\newcommand{\continuepage}{\ifprintanswers%
\newpage
\else
\vfill\hspace*{\fill}$\rightarrow$\newpage%
\fi}
\newcommand{\newsolutionpage}{\ifprintanswers%
\newpage%
\else
\fi}
%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\qt}[1]{\textbf{#1}\\}
\newcommand{\pref}[1]{(\ref{#1})}
\newcommand{\extra}{--- Zusatzaufgabe ---\ \mbox{}}
\newcommand{\code}[1]{\texttt{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\input{instructions}
\begin{questions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\question \qt{Homogeneous Poisson process}
We use the Poisson process to generate spike trains on which we can test and imrpove some
standard analysis functions.
A homogeneous Poisson process of rate $\lambda$ (measured in Hertz) is a point process
where the probability of an event is independent of time $t$ and independent of previous events.
The probability $P$ of an event within a bin of width $\Delta t$ is
\[ P = \lambda \cdot \Delta t \]
for sufficiently small $\Delta t$.
\begin{parts}
\part Write a function that generates $n$ homogeneous Poisson spike trains of a given duration $T_{max}$
with rate $\lambda$.
\begin{solution}
\lstinputlisting{hompoissonspikes.m}
\end{solution}
\part Using this function, generate a few trials and display them in a raster plot.
\begin{solution}
\lstinputlisting{../code/spikeraster.m}
\begin{lstlisting}
spikes = hompoissonspikes( 10, 100.0, 0.5 );
spikeraster( spikes )
\end{lstlisting}
\mbox{}\\[-3ex]
\colorbox{white}{\includegraphics[width=0.7\textwidth]{poissonraster100hz}}
\end{solution}
\part Write a function that extracts a single vector of interspike intervals
from the spike times returned by the first function.
\begin{solution}
\lstinputlisting{../code/isis.m}
\end{solution}
\part Write a function that plots the interspike-interval histogram
from a vector of interspike intervals. The function should also
compute the mean, the standard deviation, and the CV of the intervals
and display the values in the plot.
\begin{solution}
\lstinputlisting{../code/isihist.m}
\end{solution}
\part Compute histograms for Poisson spike trains with rate
$\lambda=100$\,Hz. Play around with $T_{max}$ and $n$ and the bin width
(start with 1\,ms) of the histogram.
How many
interspike intervals do you approximately need to get a ``nice''
histogram? How long do you need to record from the neuron?
\begin{solution}
About 5000 intervals for 25 bins. This corresponds to a $5000 / 100\,\hertz = 50\,\second$ recording
of a neuron firing with 100\,\hertz.
\end{solution}
\part Compare the histogram with the true distribution of intervals $T$ of the Poisson process
\[ p(T) = \lambda e^{-\lambda T} \]
for various rates $\lambda$.
\begin{solution}
\lstinputlisting{hompoissonisih.m}
\colorbox{white}{\includegraphics[width=0.48\textwidth]{poissonisih100hz}}
\colorbox{white}{\includegraphics[width=0.48\textwidth]{poissonisih20hz}}
\end{solution}
\part What happens if you make the bin width of the histogram smaller than $\Delta t$
used for generating the Poisson spikes?
\begin{solution}
The bins between the discretization have zero entries. Therefore
the other ones become higher than they should be.
\end{solution}
\part Plot the mean interspike interval, the corresponding standard deviation, and the CV
as a function of the rate $\lambda$ of the Poisson process.
Compare the ../code with the theoretical expectations for the dependence on $\lambda$.
\begin{solution}
\lstinputlisting{hompoissonisistats.m}
\colorbox{white}{\includegraphics[width=0.98\textwidth]{poissonisistats}}
\end{solution}
\part Write a function that computes serial correlations for the interspike intervals
for a range of lags.
The serial correlations $\rho_k$ at lag $k$ are defined as
\[ \rho_k = \frac{\langle (T_{i+k} - \langle T \rangle)(T_i - \langle T \rangle) \rangle}{\langle (T_i - \langle T \rangle)^2\rangle} = \frac{{\rm cov}(T_{i+k}, T_i)}{{\rm var}(T_i)} \]
Use this function to show that interspike intervals of Poisson spikes are independent.
\begin{solution}
\lstinputlisting{../code/isiserialcorr.m}
\colorbox{white}{\includegraphics[width=0.98\textwidth]{poissonserial100hz}}
\end{solution}
\part Write a function that generates from spike times
a histogram of spike counts in a count window of given duration $W$.
The function should also plot the Poisson distribution
\[ P(k) = \frac{(\lambda W)^ke^{\lambda W}}{k!} \]
for the rate $\lambda$ determined from the spike trains.
\begin{solution}
\lstinputlisting{../code/counthist.m}
\colorbox{white}{\includegraphics[width=0.48\textwidth]{poissoncounthistdist100hz10ms}}
\colorbox{white}{\includegraphics[width=0.48\textwidth]{poissoncounthistdist100hz100ms}}
\end{solution}
\part Write a function that computes mean count, variance of count and the corresponding Fano factor
for a range of count window durations. The function should generate tow plots: one plotting
the count variance against the mean, the other one the Fano factor as a function of the window duration.
\begin{solution}
\lstinputlisting{../code/fano.m}
\colorbox{white}{\includegraphics[width=0.98\textwidth]{poissonfano100hz}}
\end{solution}
\end{parts}
\end{questions}
\end{document}

Binary file not shown.

View File

@@ -1,160 +0,0 @@
\documentclass[addpoints,10pt]{exam}
\usepackage{url}
\usepackage{color}
\usepackage{hyperref}
\usepackage{graphicx}
\pagestyle{headandfoot}
\runningheadrule
\firstpageheadrule
\firstpageheader{Scientific Computing}{Homogeneous Poisson process}{Oct 27, 2014}
%\runningheader{Homework 01}{Page \thepage\ of \numpages}{23. October 2014}
\firstpagefooter{}{}{}
\runningfooter{}{}{}
\pointsinmargin
\bracketedpoints
%\printanswers
\shadedsolutions
\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro
%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
numbers=left,
showstringspaces=false,
language=Matlab,
breaklines=true,
breakautoindent=true,
columns=flexible,
frame=single,
captionpos=t,
xleftmargin=2em,
xrightmargin=1em,
aboveskip=10pt,
%title=\lstname,
title={\protect\filename@parse{\lstname}\protect\filename@base.\protect\filename@ext}
}
\begin{document}
\sffamily
%%%%%%%%%%%%%% Questions %%%%%%%%%%%%%%%%%%%%%%%%%
\begin{questions}
\question \textbf{Homogeneous Poisson process}
We use the Poisson process to generate spike trains on which we can test and imrpove some
standard analysis functions.
A homogeneous Poisson process of rate $\lambda$ (measured in Hertz) is a point process
where the probability of an event is independent of time $t$ and independent of previous events.
The probability $P$ of an event within a bin of width $\Delta t$ is
\[ P = \lambda \cdot \Delta t \]
for sufficiently small $\Delta t$.
\begin{parts}
\part Write a function that generates $n$ homogeneous Poisson spike trains of a given duration $T_{max}$
with rate $\lambda$.
\begin{solution}
\lstinputlisting{hompoissonspikes.m}
\end{solution}
\part Using this function, generate a few trials and display them in a raster plot.
\begin{solution}
\lstinputlisting{simulations/spikeraster.m}
\begin{lstlisting}
spikes = hompoissonspikes( 10, 100.0, 0.5 );
spikeraster( spikes )
\end{lstlisting}
\mbox{}\\[-3ex]
\colorbox{white}{\includegraphics[width=0.7\textwidth]{poissonraster100hz}}
\end{solution}
\part Write a function that extracts a single vector of interspike intervals
from the spike times returned by the first function.
\begin{solution}
\lstinputlisting{simulations/isis.m}
\end{solution}
\part Write a function that plots the interspike-interval histogram
from a vector of interspike intervals. The function should also
compute the mean, the standard deviation, and the CV of the intervals
and display the values in the plot.
\begin{solution}
\lstinputlisting{simulations/isihist.m}
\end{solution}
\part Compute histograms for Poisson spike trains with rate
$\lambda=100$\,Hz. Play around with $T_{max}$ and $n$ and the bin width
(start with 1\,ms) of the histogram.
How many
interspike intervals do you approximately need to get a ``nice''
histogram? How long do you need to record from the neuron?
\begin{solution}
About 5000 intervals for 25 bins. This corresponds to a $5000 / 100\,\hertz = 50\,\second$ recording
of a neuron firing with 100\,\hertz.
\end{solution}
\part Compare the histogram with the true distribution of intervals $T$ of the Poisson process
\[ p(T) = \lambda e^{-\lambda T} \]
for various rates $\lambda$.
\begin{solution}
\lstinputlisting{hompoissonisih.m}
\colorbox{white}{\includegraphics[width=0.48\textwidth]{poissonisih100hz}}
\colorbox{white}{\includegraphics[width=0.48\textwidth]{poissonisih20hz}}
\end{solution}
\part What happens if you make the bin width of the histogram smaller than $\Delta t$
used for generating the Poisson spikes?
\begin{solution}
The bins between the discretization have zero entries. Therefore
the other ones become higher than they should be.
\end{solution}
\part Plot the mean interspike interval, the corresponding standard deviation, and the CV
as a function of the rate $\lambda$ of the Poisson process.
Compare the simulations with the theoretical expectations for the dependence on $\lambda$.
\begin{solution}
\lstinputlisting{hompoissonisistats.m}
\colorbox{white}{\includegraphics[width=0.98\textwidth]{poissonisistats}}
\end{solution}
\part Write a function that computes serial correlations for the interspike intervals
for a range of lags.
The serial correlations $\rho_k$ at lag $k$ are defined as
\[ \rho_k = \frac{\langle (T_{i+k} - \langle T \rangle)(T_i - \langle T \rangle) \rangle}{\langle (T_i - \langle T \rangle)^2\rangle} = \frac{{\rm cov}(T_{i+k}, T_i)}{{\rm var}(T_i)} \]
Use this function to show that interspike intervals of Poisson spikes are independent.
\begin{solution}
\lstinputlisting{simulations/isiserialcorr.m}
\colorbox{white}{\includegraphics[width=0.98\textwidth]{poissonserial100hz}}
\end{solution}
\part Write a function that generates from spike times
a histogram of spike counts in a count window of given duration $W$.
The function should also plot the Poisson distribution
\[ P(k) = \frac{(\lambda W)^ke^{\lambda W}}{k!} \]
for the rate $\lambda$ determined from the spike trains.
\begin{solution}
\lstinputlisting{simulations/counthist.m}
\colorbox{white}{\includegraphics[width=0.48\textwidth]{poissoncounthistdist100hz10ms}}
\colorbox{white}{\includegraphics[width=0.48\textwidth]{poissoncounthistdist100hz100ms}}
\end{solution}
\part Write a function that computes mean count, variance of count and the corresponding Fano factor
for a range of count window durations. The function should generate tow plots: one plotting
the count variance against the mean, the other one the Fano factor as a function of the window duration.
\begin{solution}
\lstinputlisting{simulations/fano.m}
\colorbox{white}{\includegraphics[width=0.98\textwidth]{poissonfano100hz}}
\end{solution}
\end{parts}
\end{questions}
\end{document}