\documentclass{beamer}

%%%%% title %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title[]{Scientific Computing --- Point Processes}
\author[]{Jan Benda}
\institute[]{Neuroethology}
\date[]{WS 14/15}
\titlegraphic{\includegraphics[width=0.3\textwidth]{UT_WBMW_Rot_RGB}}

%%%%% beamer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>
{
  \usetheme{Singapore}
  \setbeamercovered{opaque}
  \usecolortheme{tuebingen}
  \setbeamertemplate{navigation symbols}{}
  \usefonttheme{default}
  \useoutertheme{infolines}
  % \useoutertheme{miniframes}
}

%\AtBeginSection[]
%{
%  \begin{frame}<beamer>
%    \begin{center}
%      \Huge \insertsectionhead
%    \end{center}
%  \end{frame}
%}

\setbeamertemplate{blocks}[rounded][shadow=true]
\setcounter{tocdepth}{1}

%%%%% packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{bm} 
\usepackage{pslatex}   % nice font for pdf file
%\usepackage{multimedia}

\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}}

%%%% graphics %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{graphicx}
\newcommand{\texpicture}[1]{{\sffamily\small\input{#1.tex}}}

%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings}
\lstset{
 basicstyle=\ttfamily,
 numbers=left,
 showstringspaces=false,
 language=Matlab,
 commentstyle=\itshape\color{darkgray},
 keywordstyle=\color{blue},
 stringstyle=\color{green},
 backgroundcolor=\color{blue!10},
 breaklines=true,
 breakautoindent=true,
 columns=flexible,
 frame=single,
 captionpos=b,
 xleftmargin=1em,
 xrightmargin=1em,
 aboveskip=10pt
 }

 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} 

\begin{frame}[plain]
  \frametitle{}
  \vspace{-1cm}
  \titlepage % erzeugt Titelseite
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
  \frametitle{Content}
  \tableofcontents
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Point processes}

\begin{frame}
  \frametitle{Point process}
  \vspace{-3ex}
  \texpicture{pointprocessscetchA}

  A point process is a stochastic (or random) process that generates a sequence of events
  at times $\{t_i\}$, $t_i \in \reZ$.

  For each point process there is an underlying continuous-valued
  process evolving in time. The associated point process occurs when
  the underlying continuous process crosses a threshold.
  Examples:
  \begin{itemize}
  \item Spikes/heartbeat: generated by the dynamics of the membrane potential of neurons/heart cells.
  \item Earth quakes: generated by the pressure dynamics between the tectonic plates on either side of a geological fault line.
  \item Onset of cricket/frogs/birds/... songs: generated by the dynamics of the state of a nervous system.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Point process}
  \texpicture{pointprocessscetchB}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Homogeneous Poisson process}

\begin{frame}
  \frametitle{Homogeneous Poisson process}
  The probability $p(t)\delta t$ of an event occuring at time $t$
  is independent of $t$ and independent of any previous event
  (independent of event history).

  The probability $P$ for an event occuring within a time bin of width $\Delta t$
  is
  \[ P=\lambda \cdot \Delta t \]
  for a Poisson process with rate $\lambda$.
  \includegraphics[width=1\textwidth]{poissonraster100hz}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Interval statistics}

\begin{frame}
  \frametitle{Rate}
  Rate of events $r$ (``spikes per time'') measured in Hertz.
  \begin{itemize}
  \item Number of events $N$ per observation time $W$: $r = \frac{N}{W}$
  \item Without boundary effects: $r = \frac{N-1}{t_N-t_1}$
  \item Inverse interval: $r = \frac{1}{\mu_{ISI}}$
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{(Interspike) interval statistics}
  \begin{itemize}
  \item Histogram $p(T)$ of intervals $T$. Normalized to $\int_0^{\infty} p(T) \; dT = 1$
  \item Mean interval $\mu_{ISI} = \langle T \rangle = \frac{1}{n}\sum\limits_{i=1}^n T_i$
  \item Variance of intervals $\sigma_{ISI}^2 = \langle (T - \langle T \rangle)^2 \rangle$\vspace{1ex}
  \item Coefficient of variation $CV_{ISI} = \frac{\sigma_{ISI}}{\mu_{ISI}}$
  \item Diffusion coefficient $D_{ISI} = \frac{\sigma_{ISI}^2}{2\mu_{ISI}^3}$
  \vfill
  \end{itemize}
  \includegraphics[width=0.45\textwidth]{poissonisih100hz}\hfill
  \includegraphics[width=0.45\textwidth]{lifisih16}
\end{frame}

\begin{frame}
  \frametitle{Interval statistics of homogeneous Poisson process}
  \begin{itemize}
  \item Exponential distribution of intervals $T$: $p(T) = \lambda e^{-\lambda T}$
  \item Mean interval $\mu_{ISI} = \frac{1}{\lambda}$
  \item Variance of intervals $\sigma_{ISI}^2 = \frac{1}{\lambda^2}$
  \item Coefficient of variation $CV_{ISI} = 1$
  \end{itemize}
  \vfill
  \includegraphics[width=0.45\textwidth]{poissonisihexp20hz}\hfill
  \includegraphics[width=0.45\textwidth]{poissonisihexp100hz}
\end{frame}

\begin{frame}
  \frametitle{Interval return maps}
  Scatter plot between succeeding intervals separated by lag $k$.
  \vfill
  Poisson process $\lambda=100$\,Hz:
  \includegraphics[width=1\textwidth]{poissonreturnmap100hz}\hfill
\end{frame}

\begin{frame}
  \frametitle{Serial interval correlations}
  Correlation coefficients between succeeding intervals separated by lag $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)} \]
  \begin{itemize}
  \item $\rho_0=1$ (correlation of each interval with itself).
  \item Poisson process: $\rho_k =0$ for $k>0$ (renewal process!) 
  \end{itemize}
  \vfill
  \includegraphics[width=0.7\textwidth]{poissonserial100hz}
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Count statistics}

\begin{frame}
  \frametitle{Count statistics}
  Histogram of number of events $N$ (counts) within observation window of duration $W$.

  \vfill
  \includegraphics[width=0.48\textwidth]{poissoncounthist100hz10ms}\hfill
  \includegraphics[width=0.48\textwidth]{poissoncounthist100hz100ms}
\end{frame}

\begin{frame}
  \frametitle{Count statistics of Poisson process}
  Poisson distribution:
  \[ P(k) = \frac{(\lambda W)^ke^{\lambda W}}{k!} \]

  \vfill
  \includegraphics[width=0.48\textwidth]{poissoncounthistdist100hz10ms}\hfill
  \includegraphics[width=0.48\textwidth]{poissoncounthistdist100hz100ms}
\end{frame}

\begin{frame}
  \frametitle{Count statistics --- Fano factor}
  Statistics of number of events $N$ within observation window of duration $W$.
  \begin{itemize}
  \item Mean count: $\mu_N = \langle N \rangle$
  \item Count variance: $\sigma_N^2 = \langle (N - \langle N \rangle)^2 \rangle$
  \item Fano factor (variance divided by mean): $F = \frac{\sigma_N^2}{\mu_N}$
  \item Poisson process: $F=1$
  \end{itemize}
  \vfill
  Poisson process $\lambda=100$\,Hz:
  \includegraphics[width=1\textwidth]{poissonfano100hz}
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Integrate-and-fire models}

\begin{frame}
  \frametitle{Integrate-and-fire models}
  Leaky integrate-and-fire model (LIF):
  \[ \tau \frac{dV}{dt} = -V + RI + D\xi \]
  Whenever membrane potential $V(t)$ crosses the firing threshold $\theta$, a spike is emitted and
  $V(t)$ is reset to $V_{reset}$.
  \begin{itemize}
  \item $\tau$: membrane time constant (typically 10\,ms)
  \item $R$: input resistance (here 1\,mV (!))
  \item $D\xi$: additive Gaussian white noise of strength $D$
  \item $\theta$: firing threshold (here 10\,mV)
  \item $V_{reset}$: reset potential (here 0\,mV)
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Integrate-and-fire models}
  Discretization with time step $\Delta t$: $V(t) \rightarrow V_i,\;t_i = i \Delta t$.\\
  Euler integration:
  \begin{eqnarray*}
    \frac{dV}{dt} & \approx & \frac{V_{i+1} - V_i}{\Delta t} \\
    \Rightarrow \quad V_{i+1} & = & V_i + \Delta t \frac{-V_i+RI_i+\sqrt{2D\Delta t}N_i}{\tau}
  \end{eqnarray*}
  $N_i$ are normally distributed random numbers (Gaussian with zero mean and unit variance)
  --- the $\sqrt{\Delta t}$ is for white noise.

  \includegraphics[width=0.82\textwidth]{lifraster16}
\end{frame}

\begin{frame}
  \frametitle{Interval statistics of LIF}
  Interval distribution approaches Inverse Gaussian for large $I$:
  \[ p(T) = \frac{1}{\sqrt{4\pi D T^3}}\exp\left[-\frac{(T-\langle T \rangle)^2}{4DT\langle T \rangle^2}\right] \]
  where $\langle T \rangle$ is the mean interspike interval and $D$
  is the diffusion coefficient.
  \vfill
  \includegraphics[width=0.45\textwidth]{lifisihdistr08}\hfill
  \includegraphics[width=0.45\textwidth]{lifisihdistr16}
\end{frame}

\begin{frame}
  \frametitle{Interval statistics of PIF}
  For the perfect integrate-and-fire (PIF)
  \[ \tau \frac{dV}{dt} =  RI + D\xi \]
  (the canonical model or supra-threshold firing on a limit cycle)\\
  the Inverse Gaussian describes exactly the interspike interval distribution.
  \vfill
  \includegraphics[width=0.45\textwidth]{pifisihdistr01}\hfill
  \includegraphics[width=0.45\textwidth]{pifisihdistr10}
\end{frame}

\begin{frame}
  \frametitle{Interval return map of LIF}
  LIF $I=15.7$:
  \includegraphics[width=1\textwidth]{lifreturnmap16}
\end{frame}

\begin{frame}
  \frametitle{Serial correlations of LIF}
  LIF $I=15.7$:
  \includegraphics[width=1\textwidth]{lifserial16}\\
  Integrate-and-fire driven with white noise are still renewal processes!
\end{frame}

\begin{frame}
  \frametitle{Count statistics of LIF}
  LIF $I=15.7$:
  \includegraphics[width=1\textwidth]{liffano16}\\
  Fano factor is not one!
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
  \frametitle{Interval statistics of LIF with OU noise}
  \begin{eqnarray*}
    \tau \frac{dV}{dt} & = & -V + RI + U \\
    \tau_{OU} \frac{dU}{dt} & = & - U + D\xi
  \end{eqnarray*}
  Ohrnstein-Uhlenbeck noise is lowpass filtered white noise.
  \includegraphics[width=0.45\textwidth]{lifouisihdistr08-100ms}\hfill
  \includegraphics[width=0.45\textwidth]{lifouisihdistr16-100ms}\\
  More peaky than the inverse Gaussian!
\end{frame}

\begin{frame}
  \frametitle{Interval return map of LIF with OU noise}
  LIF $I=15.7$, $\tau_{OU}=100$\,ms:
  \includegraphics[width=1\textwidth]{lifoureturnmap16-100ms}
\end{frame}

\begin{frame}
  \frametitle{Serial correlations of LIF with OU noise}
  LIF $I=15.7$, $\tau_{OU}=100$\,ms:
  \includegraphics[width=1\textwidth]{lifouserial16-100ms}\\
  OU-noise introduces positive interval correlations!
\end{frame}

\begin{frame}
  \frametitle{Count statistics of LIF with OU noise}
  LIF $I=15.7$, $\tau_{OU}=100$\,ms:
  \includegraphics[width=1\textwidth]{lifoufano16-100ms}\\
  Fano factor increases with count window duration.
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
  \frametitle{Interval statistics of LIF with adaptation}
  \begin{eqnarray*}
    \tau \frac{dV}{dt} & = & -V - A + RI + D\xi \\
    \tau_{adapt} \frac{dA}{dt} & = & - A
  \end{eqnarray*}
  Adaptation $A$ with time constant $\tau_{adapt}$ and increment $\Delta A$ at spike.
  \includegraphics[width=0.45\textwidth]{lifadaptisihdistr08-100ms}\hfill
  \includegraphics[width=0.45\textwidth]{lifadaptisihdistr65-100ms}\\
  Similar to LIF with white noise.
\end{frame}

\begin{frame}
  \frametitle{Interval return map of LIF with adaptation}
  LIF $I=10$, $\tau_{adapt}=100$\,ms:
  \includegraphics[width=1\textwidth]{lifadaptreturnmap10-100ms}\\
  Negative correlation at lag one.
\end{frame}

\begin{frame}
  \frametitle{Serial correlations of LIF with adaptation}
  LIF $I=10$, $\tau_{adapt}=100$\,ms:
  \includegraphics[width=1\textwidth]{lifadaptserial10-100ms}\\
  Adaptation with white noise introduces negative interval correlations!
\end{frame}

\begin{frame}
  \frametitle{Count statistics of LIF with adaptation}
  LIF $I=10$, $\tau_{adapt}=100$\,ms:
  \includegraphics[width=1\textwidth]{lifadaptfano10-100ms}\\
  Fano factor decreases with count window duration.
\end{frame}


\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Non stationary}
\subsection{Inhomogeneous Poisson process}
\subsection{Firing rate}
\subsection{Instantaneous rate}
\subsection{Autocorrelation}
\subsection{Crosscorrelation}
\subsection{Joint PSTH}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Renewal process}
\subsection{Superthreshold firing}
\subsection{Subthreshold firing}
\section{Non-renewal processes}
\subsection{Bursting}
\subsection{Resonator}


\subsection{Standard distributions}
\subsubsection{Gamma}
\subsubsection{How to read ISI histograms}
refractoriness, poisson tail, sub-, supra-threshold, missed spikes


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Correlation with stimulus}
\subsection{Tuning curve}
\subsection{Linear filter}
\subsection{Spatiotemporal receptive field}
\subsection{Generalized linear model}

\begin{frame}
\end{frame}