From 61bdeb160ab119eb3f07b2f808db6288634ade50 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Tue, 23 Oct 2018 09:45:23 +0200 Subject: [PATCH 1/5] [plotting] simple beginner's script --- plotting/code/simple_plot.m | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 plotting/code/simple_plot.m diff --git a/plotting/code/simple_plot.m b/plotting/code/simple_plot.m new file mode 100644 index 0000000..71bb549 --- /dev/null +++ b/plotting/code/simple_plot.m @@ -0,0 +1,8 @@ +frequency = 5; % frequency of the sine wave in Hz +time = 0.01:0.01:1.0; % the time axis +signal = sin(2 * pi * time * frequency); + +plot(time, signal); +xlabel('time [s]'); +ylabel('signal'); +title('5Hz sine wave') From 780fba24c41a9261d6df8a76a2dc2d3d3428b78c Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Fri, 2 Nov 2018 11:01:31 +0100 Subject: [PATCH 2/5] [figures] make py3 compatible --- bootstrap/lecture/bootstrapsem.py | 4 ++-- bootstrap/lecture/permutecorrelation.py | 2 +- likelihood/lecture/mlemean.py | 2 +- pointprocesses/lecture/firingrates.py | 2 +- pointprocesses/lecture/isihexamples.py | 6 +++--- pointprocesses/lecture/rasterexamples.py | 4 ++-- pointprocesses/lecture/returnmapexamples.py | 6 +++--- pointprocesses/lecture/serialcorrexamples.py | 6 +++--- pointprocesses/lecture/sta.py | 2 +- statistics/lecture/displayunivariatedata.py | 4 ++-- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bootstrap/lecture/bootstrapsem.py b/bootstrap/lecture/bootstrapsem.py index 347f40f..66154ce 100644 --- a/bootstrap/lecture/bootstrapsem.py +++ b/bootstrap/lecture/bootstrapsem.py @@ -15,13 +15,13 @@ x = rng.randn(nsamples) # bootstrap the mean: mus = [] -for i in xrange(nresamples) : +for i in range(nresamples) : mus.append(np.mean(x[rng.randint(0, nsamples, nsamples)])) hmus, _ = np.histogram(mus, bins, density=True) # many SRS: musrs = [] -for i in xrange(nresamples) : +for i in range(nresamples) : musrs.append(np.mean(rng.randn(nsamples))) hmusrs, _ = np.histogram(musrs, bins, density=True) diff --git a/bootstrap/lecture/permutecorrelation.py b/bootstrap/lecture/permutecorrelation.py index ab1a583..9b4d4f8 100644 --- a/bootstrap/lecture/permutecorrelation.py +++ b/bootstrap/lecture/permutecorrelation.py @@ -19,7 +19,7 @@ rd = np.corrcoef(x, y)[0, 1] # permutation: nperm = 1000 rs = [] -for i in xrange(nperm) : +for i in np.arange(nperm) : xr=rng.permutation(x) yr=rng.permutation(y) rs.append( np.corrcoef(xr, yr)[0, 1] ) diff --git a/likelihood/lecture/mlemean.py b/likelihood/lecture/mlemean.py index 892e663..f0b6506 100644 --- a/likelihood/lecture/mlemean.py +++ b/likelihood/lecture/mlemean.py @@ -41,7 +41,7 @@ for mu in mus : ax.text(mu-0.1, 0.04, '?', zorder=1, ha='right') else : ax.text(mu+0.1, 0.04, '?', zorder=1) -for k in xrange(len(mus)) : +for k in np.arange(len(mus)) : ax.plot(x, g[:,k], zorder=5) ax.scatter(xd, 0.05*rng.rand(len(xd))+0.2, s=30, zorder=10) diff --git a/pointprocesses/lecture/firingrates.py b/pointprocesses/lecture/firingrates.py index 6b98732..d6d1666 100644 --- a/pointprocesses/lecture/firingrates.py +++ b/pointprocesses/lecture/firingrates.py @@ -86,7 +86,7 @@ def plot_isi_rate(spike_times, max_t=30, dt=1e-4): def get_binned_rate(times, bin_width=0.05, max_t=30., dt=1e-4): time = np.arange(0., max_t, dt) bins = np.arange(0., max_t, bin_width) - bin_indices = bins / dt + bin_indices = np.asarray(bins / dt, np.int) hist, _ = sp.histogram(times, bins) rate = np.zeros(time.shape) diff --git a/pointprocesses/lecture/isihexamples.py b/pointprocesses/lecture/isihexamples.py index b03d2a9..74a4b88 100644 --- a/pointprocesses/lecture/isihexamples.py +++ b/pointprocesses/lecture/isihexamples.py @@ -31,7 +31,7 @@ def pifspikes(input, trials, dt, D=0.1) : times = [] v = vreset noise = np.sqrt(2.0*D)*np.random.randn(len(input))/np.sqrt(dt) - for k in xrange(len(noise)) : + for k in np.arange(len(noise)) : v += (input[k]+noise[k])*dt/tau if v >= vthresh : v = vreset @@ -41,7 +41,7 @@ def pifspikes(input, trials, dt, D=0.1) : def isis( spikes ) : isi = [] - for k in xrange(len(spikes)) : + for k in np.arange(len(spikes)) : isi.extend(np.diff(spikes[k])) return isi @@ -76,7 +76,7 @@ rng = np.random.RandomState(54637281) time = np.arange(0.0, duration, dt) x = np.zeros(time.shape)+rate n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate -for k in xrange(1,len(x)) : +for k in np.arange(1,len(x)) : x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau x[x<0.0] = 0.0 diff --git a/pointprocesses/lecture/rasterexamples.py b/pointprocesses/lecture/rasterexamples.py index 9c66897..042bda2 100644 --- a/pointprocesses/lecture/rasterexamples.py +++ b/pointprocesses/lecture/rasterexamples.py @@ -31,7 +31,7 @@ def pifspikes(input, trials, dt, D=0.1) : times = [] v = vreset noise = np.sqrt(2.0*D)*np.random.randn(len(input))/np.sqrt(dt) - for k in xrange(len(noise)) : + for k in range(len(noise)) : v += (input[k]+noise[k])*dt/tau if v >= vthresh : v = vreset @@ -55,7 +55,7 @@ rng = np.random.RandomState(54637281) time = np.arange(0.0, duration, dt) x = np.zeros(time.shape)+rate n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate -for k in xrange(1,len(x)) : +for k in range(1,len(x)) : x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau x[x<0.0] = 0.0 diff --git a/pointprocesses/lecture/returnmapexamples.py b/pointprocesses/lecture/returnmapexamples.py index 96803ff..829cf6d 100644 --- a/pointprocesses/lecture/returnmapexamples.py +++ b/pointprocesses/lecture/returnmapexamples.py @@ -31,7 +31,7 @@ def pifspikes(input, trials, dt, D=0.1) : times = [] v = vreset noise = np.sqrt(2.0*D)*np.random.randn(len(input))/np.sqrt(dt) - for k in xrange(len(noise)) : + for k in range(len(noise)) : v += (input[k]+noise[k])*dt/tau if v >= vthresh : v = vreset @@ -41,7 +41,7 @@ def pifspikes(input, trials, dt, D=0.1) : def isis( spikes ) : isi = [] - for k in xrange(len(spikes)) : + for k in range(len(spikes)) : isi.extend(np.diff(spikes[k])) return np.array( isi ) @@ -84,7 +84,7 @@ rng = np.random.RandomState(54637281) time = np.arange(0.0, duration, dt) x = np.zeros(time.shape)+rate n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate -for k in xrange(1,len(x)) : +for k in range(1,len(x)) : x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau x[x<0.0] = 0.0 diff --git a/pointprocesses/lecture/serialcorrexamples.py b/pointprocesses/lecture/serialcorrexamples.py index e7fff9c..a2dc853 100644 --- a/pointprocesses/lecture/serialcorrexamples.py +++ b/pointprocesses/lecture/serialcorrexamples.py @@ -31,7 +31,7 @@ def pifspikes(input, trials, dt, D=0.1) : times = [] v = vreset noise = np.sqrt(2.0*D)*np.random.randn(len(input))/np.sqrt(dt) - for k in xrange(len(noise)) : + for k in range(len(noise)) : v += (input[k]+noise[k])*dt/tau if v >= vthresh : v = vreset @@ -41,7 +41,7 @@ def pifspikes(input, trials, dt, D=0.1) : def isis( spikes ) : isi = [] - for k in xrange(len(spikes)) : + for k in range(len(spikes)) : isi.extend(np.diff(spikes[k])) return np.array( isi ) @@ -95,7 +95,7 @@ rng = np.random.RandomState(54637281) time = np.arange(0.0, duration, dt) x = np.zeros(time.shape)+rate n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate -for k in xrange(1,len(x)) : +for k in range(1,len(x)) : x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau x[x<0.0] = 0.0 diff --git a/pointprocesses/lecture/sta.py b/pointprocesses/lecture/sta.py index c5d702b..127c5ae 100644 --- a/pointprocesses/lecture/sta.py +++ b/pointprocesses/lecture/sta.py @@ -6,7 +6,7 @@ from IPython import embed def plot_sta(times, stim, dt, t_min=-0.1, t_max=.1): count = 0 - sta = np.zeros((abs(t_min) + abs(t_max))/dt) + sta = np.zeros(int((abs(t_min) + abs(t_max))/dt)) time = np.arange(t_min, t_max, dt) if len(stim.shape) > 1 and stim.shape[1] > 1: stim = stim[:,1] diff --git a/statistics/lecture/displayunivariatedata.py b/statistics/lecture/displayunivariatedata.py index 546d4ff..55130a8 100644 --- a/statistics/lecture/displayunivariatedata.py +++ b/statistics/lecture/displayunivariatedata.py @@ -53,7 +53,7 @@ ax.annotate('mean plus\nstd. dev.', arrowprops=dict(arrowstyle="->", relpos=(0.5,0.0), connectionstyle="angle3,angleA=-60,angleB=80") ) -ax = fig.add_axes([xpos, ypos, width, height], axis_bgcolor='none') +ax = fig.add_axes([xpos, ypos, width, height]) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.spines['left'].set_visible(False) @@ -92,7 +92,7 @@ ax.annotate('median', arrowprops=dict(arrowstyle="->", relpos=(0.8,0.0), connectionstyle="angle3,angleA=-60,angleB=20") ) -ax = fig.add_axes([xpos+width+0.03, ypos, 0.98-(xpos+width+0.03), height], axis_bgcolor='none') +ax = fig.add_axes([xpos+width+0.03, ypos, 0.98-(xpos+width+0.03), height]) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.xaxis.set_ticks_position('bottom') From 5cf23aba8576560d6b95d929da6bbdc41ed229f5 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Fri, 2 Nov 2018 11:03:04 +0100 Subject: [PATCH 3/5] [global] switch off solutions, set py3 explicitly (bad) --- chapter.mk | 3 ++- scientificcomputing-script.tex | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/chapter.mk b/chapter.mk index 8a0e56e..d9aa865 100644 --- a/chapter.mk +++ b/chapter.mk @@ -8,7 +8,8 @@ PYPDFFILES=$(PYFILES:.py=.pdf) pythonplots : $(PYPDFFILES) $(PYPDFFILES) : %.pdf: %.py - python $< + echo $$(which python) + python3 $< cleanpythonplots : rm -f $(PYPDFFILES) diff --git a/scientificcomputing-script.tex b/scientificcomputing-script.tex index 22bbed8..03d8c8e 100644 --- a/scientificcomputing-script.tex +++ b/scientificcomputing-script.tex @@ -67,7 +67,7 @@ \lstset{inputpath=regression/code} \include{regression/lecture/regression} -\setboolean{showexercisesolutions}{true} +\setboolean{showexercisesolutions}{false} \graphicspath{{likelihood/lecture/}{likelihood/lecture/figures/}} \lstset{inputpath=likelihood/code} \include{likelihood/lecture/likelihood} From 79f282f7b324cc99c688e7b9b334ed1afbe3efc3 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Fri, 2 Nov 2018 11:05:02 +0100 Subject: [PATCH 4/5] fixes in a few chapters --- plotting/lecture/plotting.tex | 2 +- programming/lecture/programming.tex | 10 ++++------ programmingstyle/lecture/programmingstyle.tex | 2 +- regression/lecture/regression.tex | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/plotting/lecture/plotting.tex b/plotting/lecture/plotting.tex index 57fa70b..f631189 100644 --- a/plotting/lecture/plotting.tex +++ b/plotting/lecture/plotting.tex @@ -146,7 +146,7 @@ additional options consult the help. The following listing shows a simple line plot with axis labeling and a title \lstinputlisting[caption={A simple plot showing a sinewave.}, - label=niceplotlisting]{simple_plot.m} + label=simpleplotlisting]{simple_plot.m} \subsection{Changing properties of a line plot} diff --git a/programming/lecture/programming.tex b/programming/lecture/programming.tex index 65a907d..fdbb736 100644 --- a/programming/lecture/programming.tex +++ b/programming/lecture/programming.tex @@ -40,14 +40,12 @@ variable. \begin{figure} \centering \begin{subfigure}{.5\textwidth} - \includegraphics[width=0.8\textwidth]{variable} - \label{variable:a} + \includegraphics[width=0.8\textwidth]{variable}\label{variable:a} \end{subfigure}% \begin{subfigure}{.5\textwidth} - \includegraphics[width=.8\textwidth]{variableB} - \label{variable:b} + \includegraphics[width=.8\textwidth]{variableB}\label{variable:b} \end{subfigure} - \titlecaption{Variables} point to a memory + \titlecaption{Variables}{ point to a memory address. They further are described by their name and data type. The variable's value is stored as a pattern of binary values (0 or 1). When reading the variable this pattern is @@ -630,7 +628,7 @@ matrix). The function \code{cat()} allows to concatenate n-dimensional matrices. To request the length of a vector we used the function -\code{length()}. This function is \tetbf{not} suited to request +\code{length()}. This function is \textbf{not} suited to request information about the size of a matrix. As mentioned above, \code{length()} would return the length of the largest dimension. The function \code{size()} however, returns the length in each dimension diff --git a/programmingstyle/lecture/programmingstyle.tex b/programmingstyle/lecture/programmingstyle.tex index 735082a..a4e29ac 100644 --- a/programmingstyle/lecture/programmingstyle.tex +++ b/programmingstyle/lecture/programmingstyle.tex @@ -345,7 +345,7 @@ access (read or write) variables of the calling function. Interaction with the local function requires to pass all required arguments and to take care of the return values of the function. -\emp{Nested functions} are different in this respect. They are +\emph{Nested functions} are different in this respect. They are defined within the body of the parent function (between the keywords \code{function} and \code{end}) and have full access to all variables defined in the parent function. Working (in particular changing) the diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index dae32aa..c60b926 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -86,7 +86,7 @@ large deviations. $f_{cost}(\{(x_i, y_i)\}|\{y^{est}_i\})$ is a so called \enterm{objective function} or \enterm{cost function}. We aim to adapt the model parameters to minimize the error (mean square error) and -thus the \emph{objective function}. In Chapter~\ref{maximumlikelihood} +thus the \emph{objective function}. In Chapter~\ref{maximumlikelihoodchapter} we will show that the minimization of the mean square error is equivalent to maximizing the likelihood that the observations originate from the model (assuming a normal distribution of the data @@ -270,7 +270,7 @@ The gradient is given by partial derivatives (Box~\ref{partialderivativebox}) with respect to the parameters $m$ and $b$ of the linear equation. There is no need to calculate it analytically but it can be estimated from the partial derivatives -using the difference quotient (Box~\ref{differentialquotient}) for +using the difference quotient (Box~\ref{differentialquotientbox}) for small steps $\Delta m$ und $\Delta b$. For example the partial derivative with respect to $m$: From e85ba2e8a046a6fd5f5a8423330b9627ea8470da Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Fri, 2 Nov 2018 11:05:33 +0100 Subject: [PATCH 5/5] [pointprocesses] translations 1 --- pointprocesses/lecture/pointprocesses.tex | 368 +++++++++++----------- 1 file changed, 186 insertions(+), 182 deletions(-) diff --git a/pointprocesses/lecture/pointprocesses.tex b/pointprocesses/lecture/pointprocesses.tex index 4b0850f..7e64f40 100644 --- a/pointprocesses/lecture/pointprocesses.tex +++ b/pointprocesses/lecture/pointprocesses.tex @@ -1,186 +1,186 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\chapter{Analyse von Spiketrains} +\chapter{Spiketrain analysis} -\selectlanguage{ngerman} +\selectlanguage{english} -\determ[Aktionspotential]{Aktionspotentiale} (\enterm{spikes}) sind die Tr\"ager der -Information in Nervensystemen. Dabei ist in erster Linie nur der -Zeitpunkt des Auftretens eines Aktionspotentials von Bedeutung. Die -genaue Form des Aktionspotentials spielt keine oder nur eine -untergeordnete Rolle. +\enterm[Actionspotentials]{Actionspotentials} (\enterm{spikes}) are +the carriers of information in the nervous system. Thereby it is +mainly the time at which the spikes are generated that is of +importance. The waveform of the action potential is largely +stereotyped and does not carry information. -Nach etwas Vorverarbeitung haben elektrophysiologische Messungen -deshalb Listen von Spikezeitpunkten als Ergebniss --- sogenannte -\enterm{spiketrains}. Diese Messungen k\"onnen wiederholt werden und -es ergeben sich mehrere \enterm{trials} von Spiketrains -(\figref{rasterexamplesfig}). +The result of the processing of electrophysiological recordings are +series of spike times, which are then termed \enterm{spiketrains}. If +measurements are repeated we yield several \enterm{trials} of +spiketrains (\figref{rasterexamplesfig}). -Spiketrains sind Zeitpunkte von Ereignissen --- den Aktionspotentialen ---- und deren Analyse f\"allt daher in das Gebiet der Statistik von -sogenannten \determ[Punktprozess]{Punktprozessen}. +Spiketrains are times of events, the action potentials. The analysis +of these leads into the realm of the so called \enterm[point + process]{point processes}. \begin{figure}[ht] \includegraphics[width=1\textwidth]{rasterexamples} - \titlecaption{\label{rasterexamplesfig}Raster-Plot.}{Raster-Plot von - jeweils 10 Realisierungen eines station\"arenen Punktprozesses - (homogener Poisson Prozess mit Rate $\lambda=20$\;Hz, links) und - eines nicht-station\"aren Punktprozesses (perfect - integrate-and-fire Neuron getrieben mit Ohrnstein-Uhlenbeck - Rauschen mit Zeitkonstante $\tau=100$\,ms, rechts). Jeder - vertikale Strich markiert den Zeitpunkt eines Ereignisses. - Jede Zeile zeigt die Ereignisse eines trials.} + \titlecaption{\label{rasterexamplesfig}Raster-plot.}{Raster-plot of + ten realizations of a stationary point process (homogeneous point + process with a rate $\lambda=20$\;Hz, left) and an inhomogeneous + point process (perfect integrate-and-fire neuron dirven by + Ohrnstein-Uhlenbeck noise with a time-constant $\tau=100$\,ms, + right). Each vertical dash illustrates the time at which the + action potential was observed. Each line represents the event of + each trial.} \end{figure} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\section{Punktprozesse} +\section{Point processes} -Ein zeitlicher Punktprozess (\enterm{point process}) ist ein -stochastischer Prozess, der eine Abfolge von Ereignissen zu den Zeiten -$\{t_i\}$, $t_i \in \reZ$, generiert. +A temporal \enterm{point process} is a stochastic process that +generates a sequence of events at times $\{t_i\}$, $t_i \in +\reZ$. -\begin{ibox}{Beispiele von Punktprozessen} -Jeder Punktprozess wird durch einen sich in der Zeit kontinuierlich -entwickelnden Prozess generiert. Wann immer dieser Prozess eine -Schwelle \"uberschreitet wird ein Ereigniss des Punktprozesses -erzeugt. Zum Beispiel: -\begin{itemize} -\item Aktionspotentiale/Herzschlag: wird durch die Dynamik des - Membranpotentials eines Neurons/Herzzelle erzeugt. -\item Erdbeben: wird durch die Dynamik des Druckes zwischen - tektonischen Platten auf beiden Seiten einer geologischen Verwerfung - erzeugt. -\item Zeitpunkt eines Grillen/Frosch/Vogelgesangs: wird durch die - Dynamik des Nervensystems und des Muskelapparates erzeugt. -\end{itemize} +\begin{ibox}{Examples of point processes} + Every point process is generated by a temporally continuously + developing process. An event is generated whenever this process + reaches a certain threshold. For example: + \begin{itemize} + \item Action potentials/heart beat: created by the dynamics of the + neuron/sinoatrial node + \item Earthquake: defined by the dynamics of the pressure between + tectonical plates. + \item Evoked communication calls in crickets/frogs/birds: shaped by + the dynamics of nervous system and the muscle appartus. + \end{itemize} \end{ibox} \begin{figure}[t] \texpicture{pointprocessscetch} - \titlecaption{\label{pointprocessscetchfig} Statistik 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. } + \titlecaption{\label{pointprocessscetchfig} Statistics of point + processes.}{A point process is a sequence of instances in time + $t_i$ that can be characterized through the inter-event-intervals + $T_i=t_{i+1}-t_i$ and the number of events $n_i$. } \end{figure} -F\"ur die Neurowissenschaften ist die Statistik der Punktprozesse -besonders wichtig, da die Zeitpunkte der Aktionspotentiale als -zeitlicher Punktprozess betrachtet werden k\"onnen und entscheidend -f\"ur die Informations\"ubertragung sind. +In the neurosciences, the statistics of point processes is of +importance since the timing of the neuronal events (the action +potentials) is crucial for information transmission and can be treated +as such a process. -Bei Punktprozessen k\"onnen wir die Zeitpunkte $t_i$ ihres Auftretens, -die Intervalle zwischen diesen Zeitpunkten $T_i=t_{i+1}-t_i$, sowie -die Anzahl der Ereignisse $n_i$ bis zu einer bestimmten Zeit betrachten -(\figref{pointprocessscetchfig}). - -Zwei Punktprozesse mit verschiedenen Eigenschaften sind in -\figref{rasterexamplesfig} als Rasterplot dargestellt, bei dem die -Zeitpunkte der Ereignisse durch senkrechte Striche markiert werden. +Point processes can be described using the intervals between +successive events $T_i=t_{i+1}-t_i$ and the number of observed events +within a certain time window $n_i$ (\figref{pointprocessscetchfig}). +The events originating from a point process can be illustrated in form +of a scatter- or raster plot in which each vertical line indicates the +time of an event. The event from two different point processes are +shown in \figref{rasterexamplesfig}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\section{Intervallstatistik} +\section{Intervalstatistics} -Die Intervalle $T_i=t_{i+1}-t_i$ zwischen aufeinanderfolgenden -Ereignissen sind reelle, positive Zahlen. Bei Aktionspotentialen -heisen die Intervalle auch \determ{Interspikeintervalle} -(\enterm{interspike intervals}). Deren Statistik kann mit den -\"ublichen Gr\"o{\ss}en beschrieben werden. +The intervals $T_i=t_{i+1}-t_i$ between successive events are real +positive numbers. In the context of action potentials they are +referred to as \enterm{interspike intervals}. The statistics of these +are described using the common measures. \begin{figure}[t] \includegraphics[width=0.96\textwidth]{isihexamples}\vspace{-2ex} - \titlecaption{\label{isihexamplesfig}Interspikeintervall Histogramme}{der in - \figref{rasterexamplesfig} gezeigten Spikes.} + \titlecaption{\label{isihexamplesfig}Interspike interval + histogram}{of the spikes depicted in \figref{rasterexamplesfig}.} \end{figure} \begin{exercise}{isis.m}{} - 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}. + Implement a function \code{isis()} that calculates the interspike + intervals from several spike trains. The function should return a + single vector of intervals. The action potentials recorded in the + individual trials are stored as vectors of spike times within a + \codeterm{cell-array}. Spike times are given in seconds. \end{exercise} -\subsection{Intervallstatistik erster Ordnung} +\subsection{First order interval statistics} \begin{itemize} -\item Wahrscheinlichkeitsdichte $p(T)$ der Intervalle $T$ - (\figref{isihexamplesfig}). Normiert auf $\int_0^{\infty} p(T) \; dT +\item Probability density $p(T)$ of the intervals $T$ + (\figref{isihexamplesfig}). Normalized to $\int_0^{\infty} p(T) \; dT = 1$. -\item Mittleres Intervall: $\mu_{ISI} = \langle T \rangle = +\item Average interval: $\mu_{ISI} = \langle T \rangle = \frac{1}{n}\sum\limits_{i=1}^n T_i$. -\item Standardabweichung der Intervalle: $\sigma_{ISI} = \sqrt{\langle (T - \langle T - \rangle)^2 \rangle}$\vspace{1ex} -\item \determ{Variationskoeffizient} (\enterm{coefficient of variation}): $CV_{ISI} = +\item Standard deviation of the interspike intervals: $\sigma_{ISI} = \sqrt{\langle (T - \langle T + \rangle)^2 \rangle}$\vspace{1ex} +\item \enterm{Coefficient of variation}: $CV_{ISI} = \frac{\sigma_{ISI}}{\mu_{ISI}}$. -\item \determ{Diffusionskoeffizient} (\enterm{diffusion coefficient}): $D_{ISI} = +\item \enterm{Diffusion coefficient}): $D_{ISI} = \frac{\sigma_{ISI}^2}{2\mu_{ISI}^3}$. \end{itemize} \begin{exercise}{isihist.m}{} - Schreibe eine Funktion \code{isiHist()}, die einen Vektor mit Interspikeintervallen - entgegennimmt und daraus ein normiertes Histogramm der Interspikeintervalle - berechnet. + Implement a function \code{isiHist()} that calculates the normalized + interspike interval histogram. The function should take two input + arguments; (i) a vector of interspike intervals and (ii) the width + of the bins used for the histogram. It further returns the + probability density as well as the centers of the bins. \end{exercise} \begin{exercise}{plotisihist.m}{} - Schreibe eine Funktion, die die Histogrammdaten der Funktion - \code{isiHist()} 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. + Implement a function that takes the return values of + \code{isiHist()} as input arguments and then plots the data. The + plot should show the histogram with the x-axis scaled to + milliseconds and should be annotated with the average ISI, the + standard deviation and the coefficient of variation. \end{exercise} -\subsection{Korrelationen der Intervalle} -In \enterm{return maps} werden die um das \enterm{lag} $k$ verz\"ogerten -Intervalle $T_{i+k}$ gegen die Intervalle $T_i$ geplottet. Dies macht -m\"ogliche Abh\"angigkeiten von aufeinanderfolgenden Intervallen -sichtbar. +\subsection{Interval correlations} +So called \enterm{return maps} are used to illustrate +interdependencies between successive interspike intervals. The return +map plots the delayed interval $T_{i+k}$ against the interval +$T_i$. The parameter $k$ is called the \enterm{lag} $k$. Stationary +and non-stationary return maps are distinctly different +\figref{returnmapfig}. \begin{figure}[t] \includegraphics[width=1\textwidth]{returnmapexamples} \includegraphics[width=1\textwidth]{serialcorrexamples} - \titlecaption{\label{returnmapfig}Interspikeintervall return maps und - serielle Korrelationen}{zwischen aufeinander folgenden Intervallen - im Abstand des Lags $k$.} + \titlecaption{\label{returnmapfig}Interspike interval analyses of a + stationary and a non-stationary pointprocess.}{Upper plots show the + return maps and the lower panels depict the serial correlation of + successive intervals separated by the lag $k$.} \end{figure} -Solche Ab\"angigkeiten werden durch die \determ{serielle - Korrelationen} (\enterm{serial correlations}) der Intervalle -quantifiziert. Das ist der \determ{Korrelationskoeffizient} zwischen -aufeinander folgenden Intervallen getrennt durch lag $k$: +Such dependencies can be further quantified using the \enterm{serial + correlations} \figref{returnmapfig}. The serial correlation is the +correlation coefficient of the intervals $T_i$ and the intervals +delayed by the lag $T_{i+k}$: \[ \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)} -= {\rm corr}(T_{i+k}, T_i) \] -\"Ublicherweise wird die Korrelation $\rho_k$ gegen den Lag $k$ -aufgetragen (\figref{returnmapfig}). $\rho_0=1$ (Korrelation jedes -Intervalls mit sich selber). += {\rm corr}(T_{i+k}, T_i) \] The resulting correlation coefficient +$\rho_k$ is usually plotted against the lag $k$ +\figref{returnmapfig}. $\rho_0=1$ is the correlation of each interval +with itself and is always 1. \begin{exercise}{isiserialcorr.m}{} - Schreibe eine Funktion \code{isiserialcorr()}, die einen Vektor mit Interspikeintervallen - entgegennimmt und daraus die seriellen Korrelationen berechnet und plottet. - \pagebreak[4] + Implement a function \code{isiserialcorr()} that takes a vector of + interspike intervals as input argument and calculates the serial + correlation. The function should further plot the serial + correlation. \pagebreak[4] \end{exercise} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\section{Z\"ahlstatistik} +\section{Count statistics} % \begin{figure}[t] % \includegraphics[width=0.48\textwidth]{poissoncounthist100hz10ms}\hfill % \includegraphics[width=0.48\textwidth]{poissoncounthist100hz100ms} % \titlecaption{\label{countstatsfig}Count Statistik.}{} % \end{figure} - -Die Anzahl der Ereignisse $n_i$ in Zeifenstern $i$ der -L\"ange $W$ ergeben ganzzahlige, positive Zufallsvariablen, die meist -durch folgende Sch\"atzer charakterisiert werden: +The number of events $n_i$ (counts) in a time window $i$ of the duration $W$ +yields positive integer random numbers that are commonly quantified +using the following measures: \begin{itemize} -\item Histogramm der counts $n_i$. -\item Mittlere Anzahl von Ereignissen: $\mu_N = \langle n \rangle$. -\item Varianz der Anzahl: $\sigma_n^2 = \langle (n - \langle n \rangle)^2 \rangle$. -\item \determ{Fano Faktor} (Varianz geteilt durch Mittelwert): $F = \frac{\sigma_n^2}{\mu_n}$. +\item Histogram of the counts $n_i$. +\item Average number of events: $\mu_N = \langle n \rangle$. +\item Variance of the counts: $\sigma_n^2 = \langle (n - \langle n \rangle)^2 \rangle$. +\item \determ{Fano Faktor} (The variance divided by the average): $F = \frac{\sigma_n^2}{\mu_n}$. \end{itemize} -Insbesondere ist die mittlere Rate der Ereignisse $r$ (Spikes pro -Zeit, \determ{Feuerrate}) gemessen in Hertz \sindex[term]{Feuerrate!mittlere Rate} +And in particular the average firing rate $r$ (spike count per time interval +, \determ{Feuerrate}) that is given in Hertz \sindex[term]{Feuerrate!mittlere Rate} \begin{equation} \label{firingrate} r = \frac{\langle n \rangle}{W} \; . @@ -200,110 +200,114 @@ Zeit, \determ{Feuerrate}) gemessen in Hertz \sindex[term]{Feuerrate!mittlere Rat % \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}. + Implement a function \code{counthist()} that calculates and plots + the distribution of spike counts observed in a certain time + window. The function should take two input arguments: (i) a + \codeterm{cell-array} of vectors containing the spike times in + seconds observed in a number of trials and (ii) the duration of the + time window that is used to evaluate the counts. \end{exercise} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\section{Homogener Poisson Prozess} -F\"ur kontinuierliche Me{\ss}gr\"o{\ss}en ist die Normalverteilung -u.a. wegen dem Zentralen Grenzwertsatz die Standardverteilung. Eine -\"ahnliche Rolle spielt bei Punktprozessen der \determ{Poisson - Prozess}. - -Beim \determ[Poisson Prozess!homogener]{homogenen Poisson Prozess} -treten Ereignisse mit einer festen Rate $\lambda=\text{const.}$ auf -und sind unabh\"angig von der Zeit $t$ und unabh\"angig von den -Zeitpunkten fr\"uherer Ereignisse (\figref{hompoissonfig}). Die -Wahrscheinlichkeit zu irgendeiner Zeit ein Ereigniss in einem kleinen -Zeitfenster der Breite $\Delta t$ zu bekommen ist +\section{Homogeneous Poisson process} + +The Gaussian distribution is, due to the central limit theorem, the +standard for continuous measures. The equivalent in the realm of point +processes is the \enterm{Poisson distribution}. + +In a \enterm[Poisson process!homogeneous]{homogeneous Poisson process} +the events occur at a fixed rate $\lambda=\text{const.}$ and are +independent of both the time $t$ and occurrence of previous events +(\figref{hompoissonfig}). The probability of observing an even within a +small time window of width $\Delta t$ is given by \begin{equation} \label{hompoissonprob} - P = \lambda \cdot \Delta t \; . + P = \lambda \cdot \Delta t \; . \end{equation} -Beim \determ[Poisson Prozess!inhomogener]{inhomogenen Poisson Prozess} -h\"angt die Rate $\lambda$ von der Zeit ab: $\lambda = \lambda(t)$. + +In an \enterm[Poisson process!inhomogeneous]{inhomogeneous Poisson + process}, however, the rate $\lambda$ depends on the time: $\lambda = +\lambda(t)$. \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. Benutze \eqnref{hompoissonprob} - um die Spikezeiten zu bestimmen. + Implement a function \code{poissonspikes()} that uses a homogeneous + Poisson process to generate events at a given rate for a certain + duration and a number of trials. The rate should be given in Hertz + and the duration of the trials is given in seconds. The function + should return the event times in a cell-array. Each entry in this + array represents the events observed in one trial. Apply + \eqnref{hompoissonprob} to generate the event times. \end{exercise} \begin{figure}[t] \includegraphics[width=1\textwidth]{poissonraster100hz} - \titlecaption{\label{hompoissonfig}Rasterplot von Spikes eines homogenen - Poisson Prozesses mit $\lambda=100$\,Hz.}{} + \titlecaption{\label{hompoissonfig}Rasterplot of spikes of a + homogeneous Poisson process with a rate $\lambda=100$\,Hz.}{} \end{figure} \begin{figure}[t] \includegraphics[width=0.45\textwidth]{poissonisihexp20hz}\hfill \includegraphics[width=0.45\textwidth]{poissonisihexp100hz} - \titlecaption{\label{hompoissonisihfig}Interspikeintervallverteilungen - zweier Poissonprozesse.}{} + \titlecaption{\label{hompoissonisihfig}Distribution of interspike intervals of two Poisson processes.}{} \end{figure} -Der homogene Poissonprozess hat folgende Eigenschaften: +The homogeneous Poisson process has the following properties: \begin{itemize} -\item Die Intervalle $T$ sind exponentiell verteilt (\figref{hompoissonisihfig}): +\item Intervals $T$ are exponentially distributed (\figref{hompoissonisihfig}): \begin{equation} \label{poissonintervals} p(T) = \lambda e^{-\lambda T} \; . \end{equation} -\item Das mittlere Intervall ist $\mu_{ISI} = \frac{1}{\lambda}$ . -\item Die Varianz der Intervalle ist $\sigma_{ISI}^2 = \frac{1}{\lambda^2}$ . -\item Der Variationskoeffizient ist also immer $CV_{ISI} = 1$ . -\item Die \determ[serielle Korrelationen]{seriellen Korrelationen} - $\rho_k =0$ f\"ur $k>0$, da das Auftreten der Ereignisse - unabh\"angig von der Vorgeschichte ist. Ein solcher Prozess wird - auch \determ{Erneuerungsprozess} genannt (\enterm{renewal process}). -\item Die Anzahl der Ereignisse $k$ innerhalb eines Fensters der - L\"ange W ist \determ[Poisson-Verteilung]{Poissonverteilt}: +\item The average interval is $\mu_{ISI} = \frac{1}{\lambda}$ . +\item The variance of the intervals is $\sigma_{ISI}^2 = \frac{1}{\lambda^2}$ . +\item Thus, the coefficient of variation is always $CV_{ISI} = 1$ . +\item The serial correlation is $\rho_k =0$ for $k>0$, since the + occurrence of an event is independent of all previous events. Such a + process is also called a \enterm{renewal process}. +\item The number of events $k$ within a temporal window of duration + $W$ is Poisson distributed: \[ P(k) = \frac{(\lambda W)^ke^{\lambda W}}{k!} \] - (\figref{hompoissoncountfig}) -\item Der \determ{Fano Faktor} ist immer $F=1$ . +(\figref{hompoissoncountfig}) +\item The Fano Faktor is always $F=1$ . \end{itemize} \begin{exercise}{hompoissonspikes.m}{} - Schreibe eine Funktion \code{hompoissonspikes()}, 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. Benutze die exponentiell-verteilten - Interspikeintervalle \eqnref{poissonintervals}, um die Spikezeiten zu erzeugen. + Implement a function \code{hompoissonspikes()} that uses a + homogeneous Poisson process to generate spike events at a given rate + for a certain duration and a number of trials. The rate should be + given in Hertz and the duration of the trials is given in + seconds. The function should return the event times in a + cell-array. Each entry in this array represents the events observed + in one trial. Apply \eqnref{poissonintervals} to generate the event + times. \end{exercise} \begin{figure}[t] \includegraphics[width=0.48\textwidth]{poissoncounthistdist100hz10ms}\hfill \includegraphics[width=0.48\textwidth]{poissoncounthistdist100hz100ms} - \titlecaption{\label{hompoissoncountfig}Z\"ahlstatistik von Poisson Spikes.}{} + \titlecaption{\label{hompoissoncountfig}Count statistics of Poisson + spiketrains.}{} \end{figure} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\section{Zeitabh\"angige Feuerraten} - -Bisher haben wir station\"are Spiketrains betrachtet, deren Statistik -sich innerhalb der Analysezeit nicht ver\"andert (station\"are -Punktprozesse). Meistens jedoch \"andert sich die Statistik der -Spiketrains eines Neurons mit der Zeit. Z.B. kann ein sensorisches -Neuron auf einen Reiz hin mit einer erh\"ohten Feuerrate antworten -(nichtstation\"arer Punktprozess). - -Wie die mittlere Anzahl der Spikes sich mit der Zeit ver\"andert, die -\determ{Feuerrate} $r(t)$, ist die wichtigste Gr\"o{\ss}e bei -nicht-station\"aren Spiketrains. Die Einheit der Feuerrate ist Hertz, -also Anzahl Aktionspotentiale pro Sekunde. Es gibt verschiedene -Methoden diese zu bestimmen. Drei solcher Methoden sind in Abbildung -\ref{psthfig} dargestellt. Alle Methoden haben ihre Berechtigung und -ihre Vor- und Nachteile. Im folgenden werden die drei Methoden aus -Abbildung \ref{psthfig} n\"aher erl\"autert. +\section{Time-dependent firing rate} + +So far we discussed stationary spiketrains. The statistical properties +of these did not change within the observation time (stationary point +processes. Most commonly, however, this is not the case. A sensory +neuron, for example, might respond to a stimulus by modulating its +firing rate (non-stationary point process). + +How the firing rate $r(t)$ changes over time is the most important +measure, when analyzing non-stationary spike trains. The unit of the +firing rate is Hertz, i.e. the number of action potentials per +second. There are different ways to estimate the firing rate and three +of these methods will are illustrated in \figref{psthfig}. All of +these have their own justifications and pros- and cons. In the +following we will discuss the methods shown in \figref{psthfig} more +closely. \begin{figure}[tp] \includegraphics[width=\columnwidth]{firingrates}