\section{Bayesian Preference Learning for Crowds}\label{sec:model}

We assume that a pair of items, $a$ and $b$, have utilities
$f(\bs x_a)$ and $f(\bs x_b)$, which represent their value to a user,
and that $f: \mathbb{R}^D \mapsto \mathbb{R}$
is a function of item features, where $\bs x_a$ and $\bs x_b$ are vectors
of length $D$ containing the features of items $a$ and $b$, respectively.
If $f(\bs x_a) > f(\bs x_b)$, then $a$ is preferred to $b$ (written $a \succ b$).
The outcome of a comparison between $a$ and $b$ is
a pairwise label, $y(a, b)$.
Assuming that pairwise labels never contain errors,
then $y(a, b)=1$ if $a \succ b$ and $0$ otherwise.
Given knowledge of $f$, we can compute the utilities
of items in a test set given their features, and the outcomes of pairwise comparisons.

\citet{thurstone1927law} proposed the random utility model,
which relaxes the assumption that pairwise labels, $y(a, b)$,
are always consistent with the ordering of $f(\bs x_a)$ and $f(\bs x_b)$.
Under the random utility model, the likelihood $p(y(a,b)=1)$
increases as $f_a - f_b$ increases, i.e.,
as the utility of item $a$ increases
relative to the utility of item $b$.
This reflects the greater consistency in a user's choices
when their preferences are stronger,
while accommodating
%However, since $0 < p(y(a,b)=1) < 1$, the model
%is uncertain about the value of $y(a,b)$,
labelling errors or variations in a user's choices over time.
%The uncertainty is lower if the values $f_a$ and $f_b$ are further apart,
%which
%The random utility model is defined by a likelihood function that
%maps the utilities to $p(y(a,b))$.
%or the Thurstone-Mosteller model.
%\begin{align}
%p(y(a, b) | f) & = \frac{1}{1 + \exp( f(\bs x_a) - f(\bs x_b) ) }
%\end{align}
In the Thurstone-Mosteller model, % case V model,
noise in the observations is explained by a Gaussian-distributed noise term, $\delta \sim \mathcal{N}(0, \sigma^2)$:
\begin{flalign}
 p(y(a, b) | f(\bs x_a) + \delta_{a}, f(\bs x_b) + \delta_{b} )
 \hspace{0.9cm} & = \begin{cases}
 1 & \text{if }f(\bs x_a) + \delta_{a} \geq f(b) + \delta_{b} \\
 0 & \text{otherwise,}
 \end{cases} &
 \label{eq:thurstone}
\end{flalign}
Integrating out the unknown values of $\delta_a$ and $\delta_b$ gives:
\begin{flalign}
& p( y(a, b) | f(\bs x_a), f(\bs x_b) )  & \label{eq:plphi}\\
& = \!\! \int\!\!\!\! \int \!\! p( y(a, b) | f(\bs x_a) + \delta_{a}, f(\bs x_b) + \delta_{b} ) \mathcal{N}\left(\delta_{a}; 0, \sigma^2\right)\mathcal{N}\left(\delta_{b}; 0, \sigma^2\right) d\delta_{a} d\delta_{b}
%= \Phi\left(\frac{f(\bs x_a) - f(\bs x_b)}{\sqrt{2\sigma^2}}\right)
= \Phi\left( z \right), & \nonumber
\end{flalign}
where $z = \frac{f(\bs x_a) - f(\bs x_b)}{\sqrt{2\sigma^2}}$,
and $\Phi$ is the cumulative distribution function of the standard normal distribution,
meaning that $\Phi(z)$ is a
probit likelihood.\footnote{Please note that a full list of symbols is provided for reference in Appendix $\ref{sec:not}$}
This likelihood is also used by
\citet{chu2005preference} for Gaussian process preference learning (GPPL), but here
we simplify the formulation by assuming that $\sigma^2 = 0.5$,
which leads to $z$ having a denominator of $\sqrt{2 \times 0.5}=1$,
hence $z = f(\bs x_a) - f(\bs x_b)$.
Instead, we model varying degrees of noise in the pairwise labels
by scaling $f$ itself, as we describe in the next section.

In practice, $f(\bs x_a)$ and $f(\bs x_b)$ must be inferred from
pairwise training labels, $\bs y$,
to obtain a posterior distribution over their values.
If this posterior is a multivariate Gaussian distribution,
then the probit likelihood allows us to analytically marginalise
$f(\bs x_a)$ and $f(\bs x_b)$
to obtain the probability of a pairwise label:
\begin{flalign}
p(y(a,b)| \bs y)
= \Phi(\hat{z}),& & \hat{z} = \frac{\hat{f}_a - \hat{f}_b}{\sqrt{1 + C_{a,a} + C_{b,b}
- 2C_{a,b}} }, \label{eq:predict_z} &&
\end{flalign}
where $\hat{f}_a$ and $\hat{f}_b$ are the means and
$\bs C$ is the posterior covariance matrix of the multivariate Gaussian over
$f(\bs x_a)$ and $f(\bs x_b)$.
Unlike other choices for the likelihood, such as a sigmoid,
the probit allows us to compute the posterior over a pairwise label
without further approximation,
% given this posterior over $f(\bs x_a)$ and $f(\bs x_b)$,
%numerical integration
hence we assume this pairwise label likelihood for our proposed preference learning model.
%Obtaining the posterior over $f$ is itself challenging, however,
%and therefore in Section $\ref{sec:inf}$ we propose
%an approximate inference method to address this problem.

\subsection{GPPL for Single User Preference Learning}

We can model the preferences of a single user by assuming
a Gaussian process prior over the user's utility function,
%is a function of item features and
$f \sim \mathcal{GP}(0, k_{\theta}/s)$, where $k_{\theta}$ is a kernel function with hyperparameters $\theta$
and $s$ is an inverse scale parameter.
The kernel function takes numerical item features as inputs and determines the covariance between values of $f$ for different items.
The choice of kernel function and its hyperparameters controls the shape and smoothness of the function
across the feature space and is often treated as a model selection problem.
Kernel functions suitable for a wide range of tasks include the \emph{squared exponential}
and the \emph{Mat\'ern}~\citep{rasmussen_gaussian_2006},
which both make minimal assumptions but
assign higher covariance to items with similar feature values.
We use $k_{\theta}$ to compute a covariance matrix $\bs K_{\theta}$,
between a set of $N$ observed items with features $\bs X = \{ \bs x_1, ..., \bs x_N \}$.

Here we extend the original definition of GPPL~\citep{chu2005preference},
by introducing the inverse scale, $s$,
which is drawn from a gamma prior,
$s \sim \mathcal{G}(\alpha_0, \beta_0)$, with shape $\alpha_0$ and scale $\beta_0$.
The value of $1/s$ determines the variance of $f$,
and therefore
the magnitude of differences between $f(\bs x_a)$ and $f(\bs x_b)$ for
items $a$ and $b$. This in turn affects the level of certainty
in the pairwise label likelihood as per Equation \ref{eq:plphi}.

Given a set of $P$ pairwise labels, %for a single user,
$\bs y=\{y_1,...,y_P\}$,
where %the $p$th label,
$y_p=y(a_p, b_p)$ is the preference label for items $a_p$ and $b_p$, % refers to items $\{ a_p, b_p \}$.
we can write the joint distribution over all variables as follows:
\begin{flalign}
p\left( \bs{y}, \bs f, s | k_{\theta}, \bs X, \alpha_0, \beta_0 \right)
=  \prod_{p=1}^P p( y_p | \bs f )
\mathcal{N}(\bs f; \bs 0, \bs K_{\theta}/s) \mathcal{G}(s; \alpha_0, \beta_0) %\nonumber \\
%=  \prod_{p=1}^P \Phi\left( z_p \right)
%\mathcal{N}(\bs f; \bs 0, \bs K_{\theta}/s) \mathcal{G}(s; \alpha_0, \beta_0), &
\label{eq:joint_single}
\end{flalign}
where
$\bs f = \{f(\bs {x}_1),...,f(\bs {x}_N)\}$
is a vector containing the utilities of the $N$ items referred to by $\bs y$,
and $p( y_p | \bs f ) = \Phi\left( z_p \right)$ is the pairwise likelihood (Equation \ref{eq:plphi}).
%We henceforth refer to this model simply as \emph{GPPL}.

\subsection{Crowd Preference Learning} \label{sec:crowd_model}

To predict the preferences of individuals in a crowd,
we could use an independent GPPL model for each user.
However, by modelling all users jointly, we can
exploit correlations between their interests
to improve predictions when preference data is sparse,
and reduce the memory cost of storing separate models.
Correlations between users
can arise from common interests over certain subsets of items,
such as in one particular genre in a book recommendation task.
Identifying such correlations helps to predict
 preferences from  fewer observations and is the core idea of collaborative filtering~\citep{resnick1997recommender} and matrix factorisation~\citep{koren2009matrix}.

As well as individual preferences,
we wish to predict the consensus by aggregating
preference labels from multiple users.
Individual biases of different users may affect consensus predictions,
particularly when data for certain items comes from a small subset of users.
The consensus could also help
predict preferences of users with little or no data
 by favouring popular items
and avoiding generally poor items.
We therefore propose
%address this problem by proposing
 \emph{crowdGPPL}, which jointly models
the preferences of individual users as well as the underlying consensus of the crowd.
Unlike previous methods for inferring the consensus,
such as \emph{CrowdBT}~\citep{chen2013pairwise}, we do not treat differences between users as simply the result of labelling errors,
but also account for their subjective biases
towards particular items.

% is there a better word than 'label sources' for the different sources of implicit feedback or other types of labeling?
%In a scenario with multiple users or label sources,
For crowdGPPL,
we represent utilities in a matrix, $\bs{F} \in \mathbb{R}^{N \times U}$,
with %$N$ rows corresponding to items and
$U$ columns corresponding to users.
Within $\bs F$, each entry $F_{a,j} = f(\bs x_a, \bs u_j)$ is the
utility for item $n$ for user $j$ with user features $\bs u_j$.
We assume that $\bs{F} = \bs{V}^T \bs{W} + \bs{t}\bs{1^T}$
 is the product of two low-rank matrices
plus a vector of consensus utilities, $\bs{t} \in \mathbb{R}^N$,
where $\bs{W} \in \mathbb{R}^{C \times U}$ is a latent representation
of the users,
$\bs{V} \in \mathbb{R}^{C \times N}$ is a latent representation of the items,
 $C$ is the number of latent \emph{components}, i.e., the dimension
of the latent representations,
and $\bs 1$ is a column vector of ones of length $U$.
The column $\bs v_{.,a}$ of $\bs V$, and the column $\bs w_{.,j}$ of $\bs W$,
 are latent vector representations of item $a$ and user $j$,
 respectively.
%Users with similar values for a certain feature will have similar preferences for
%the subset of items with corresponding feature values.
Each row of $\bs V$, $\bs v_c=\{
v_c(\bs{x}_1),...,v_c(\bs{x}_N)\}$,
contains evaluations of a latent function,
$v_c\sim \mathcal{GP}(\bs 0, k_{\theta} /s^{(v)}_c)$,
of item features, $\bs x_a$,
where $k$ is a kernel function, $s^{(v)}_c$ is an inverse function scale,
and $\theta$ are kernel hyperparameters.
%Since our goal is to infer a consensus from a crowd as well as to model individual
%users' preferences,
The consensus utilities, $\bs t = \{t(\bs {x}_1),...,t(\bs {x}_N)\}$,
are values of a consensus utility function over item features,
$t\sim \mathcal{GP}(\bs 0, k_{\theta} /s^{(t)})$, which is shared across all users,
with inverse scale $s^{(t)}$.
Similarly, each row of $\bs W$,
$\bs w_c=\{w_c(\bs u_1),...,w_c(\bs u_U)\}$,
 contains evaluations of a latent function,
$w_c \sim \mathcal{GP}(\bs 0, k_{\eta}/s_c^{(w)})$,
of user features, $\bs u_j$,
with inverse scale $s_c^{(w)}$
and kernel hyperparameters $\eta$.
Therefore, each utility in $\bs F$ can be written as
a weighted sum over the latent components:
\begin{flalign}
  f(\bs x_a, \bs u_j) = \sum_{c=1}^C  v_c(\bs x_a) w_c(\bs u_j) + t(\bs x_a),
  \label{eq:vw_plus_t}
\end{flalign}
where $\bs u_j$ are the features of user $j$ and $\bs x_a$ are the features of item $a$.
Each latent component corresponds to a utility function
for certain items, which is shared by a subset of users to differing degrees.
For example, in the case of book recommendation,
$c$ could relate to science fiction novels,
$v_c$ to a ranking over them,
and $w_c$ to the degree of agreement of users with that ranking.
%CrowdGPPL therefore combines latent features of items and
%users -- represented by the latent components -- with the
%utilities of the items according to an underlying consensus across users.
%Given the consensus, $t$,
%utility for item $a$, $t(\bs x_a)$,
The individual preferences of each user $j$ deviate from a consensus across users, $t$, according
to $\sum_{c=1}^C  v_c(\bs x_a) w_c(\bs u_j)$.
This allows us to subtract the effect of individual biases when inferring the consensus utilities.
The consensus can also help
when inferring personal preferences for %new users,
%new items or
new combinations of users and items that are
very different to those in the training data by
 accounting for any objective or widespread appeal that an item may have.
%We provide a Bayesian treatment to matrix factorization by placing Gaussian process priors over the latent functions.
%differently for each user and item. For example, the observed user feature 'age' may correlate with some latent interests of users, but certain users will deviate from their peer group.
% what happens if two users have identical features (say, the feature representation
% has only simple values, such as age in years)? They have 1-1 covariance, but there
% is variance in the GP at one location, so both can be drawn separately from the prior.
%It is not necessary to learn a separate scale for $w_c$, since $v_c$ and $w_c$ are multiplied with each other, making a single $s^{(v)}_c$ equivalent to the product of two separate scales.
%The choice of $C$ can be treated as a hyperparameter, or modeled using a non-parametric prior, such as
%the Indian Buffet Process, which assumes an infinite number of latent components ~\citep{ding2010nonparametric}.
%This section described a Bayesian matrix factorization model,
%which we will subsequently extend to a preference learning model for crowds of users and label sources.
% joint distribution
% notes about problems with inference.

Although the model assumes a fixed number of components, $C$,
the GP priors over $\bs w_c$ and $\bs v_c$ act as \emph{shrinkage}
or \emph{ARD priors} that favour values close to zero~\citep{mackay1995probable,psorakis2011overlapping}.
Components that are not required to explain the data will have posterior
expectations and scales $1/s^{(v)}$ and $1/s^{(w)}$ approaching zero.
Therefore, %due to our choice of prior,
it is not necessary to optimise the value of $C$ by hand,
providing a sufficiently large number is chosen.

Equation \ref{eq:vw_plus_t} is similar to
\emph{cross-task crowdsourcing}~\citep{mo2013cross}, which
uses matrix factorisation to model annotator performance in different tasks,
where $\bs t$ corresponds to the objective difficulty of a task.
However, unlike crowdGPPL, they do not use GPs to model the factors,
nor apply
the approach to preference learning.
For preference learning, collabGP~\citep{houlsby2012collaborative}
is a related model that
excludes the consensus and uses values in $\bs v_c$ to represent pairs
 rather than individual items, so does not infer item ratings.
It also omits scale parameters for the GPs that
encourage shrinkage when $C$ is larger than required.

We combine the matrix factorisation method with the preference likelihood of Equation \ref{eq:plphi}
to obtain the joint preference model for multiple users, \emph{crowdGPPL}:
%represent a consensus between users,
%if present, while allowing individual users' preferences to deviate from this value through $\bs V^T \bs W$.
%Hence, $\bs t$ can model the underlying ground truth or consensus in crowdsourcing scenarios, or when using
%multiple label sources to learn preferences for one individual.
\begin{flalign}
&p\left( \bs{y}, \bs V, \bs W, \bs t, s^{(v)}_1 \!\!, .., s^{(v)}_C\!\!, s^{(w)}_1\!\!, .., s^{(w)}_C\!\!, s^{(t)}
| k_{\theta}, \bs X, k_{\eta}, \bs U, \alpha_0^{(t)}\!\!, \beta_0^{(t)}\!\!,
\alpha_0^{(v)}\!\!, \beta_0^{(v)}\!\!, \alpha_0^{(w)}\!\!, \beta_0^{(w)} \right)
 & \nonumber \\
& = \prod_{p=1}^P \Phi\left( z_p \right)
\mathcal{N}(\bs t; \bs 0, \bs K_{\theta} /s^{(t)})
\mathcal{G}({s^{(t)}}; \alpha_0^{(t)}, \beta_0^{(t)})
\prod_{c=1}^C \left\{
\mathcal{N}(\bs v_c; \bs 0, \bs K_{\theta} /s^{(v)}_c)
\right.
 & \nonumber \\
&\left.
\mathcal{N}(\bs w_c; \bs 0, \bs L_{\eta}/s^{(w)}_c) \mathcal{G}(s^{(v)}_c; \alpha_0^{(v)}, \beta_0^{(v)})\mathcal{G}(s^{(w)}_c; \alpha_0^{(w)}, \beta_0^{(w)}) \right\}, &
\label{eq:joint_crowd}
\end{flalign}
where
$z_p = \bs v_{.,a_p}^T \bs{w}_{.,u_p} + t_{a_p} - \bs v_{.,b_p}^T \bs{w}_{.,u_p} - t_{b_p}$,
index $p$ refers to a user and a pair of items, $\{u_p, a_p, b_p \}$,
$\bs U$ is the set of feature vectors for all users,
$\bs K_{\theta}$ is the prior covariance for the items as in GPPL,
and $\bs L_{\eta}$ is the prior covariance for the users computed
using $k_{\eta}$.


\section{Model}

\begin{definition}\label{def:mp}
  A Markov process is a stochastic process $Q_1, Q_2, \dots$ for which
  \begin{equation*}
    p(Q_t=q_t \gv Q_1=q_1, Q_2=q_2, \dots, Q_{t-1}=q_{t-1}) = p(Q_t=q_t \gv Q_{t-1}=q_{t-1}).
  \end{equation*}
  The possible values of $Q_t$ form a finite set $\set{Q}$ called the state space.
\end{definition}

\begin{definition}\label{def:hmm}
  Let $\set{A}$ be a non-empty finite set of symbols. Let $Q_1, Q_2, \dots$ be a Markov process and
  let $S_1, S_2, \dots$ be a stochastic process for which
  \begin{equation*}
    p(S_t\in\set{A} \gv Q_1=q_1, Q_2=q_2, \dots, Q_t=q_t) = p(S_t\in\set{A} \gv Q_t=q_t).
  \end{equation*}
  The pair $(Q_t, S_t)$ is a hidden Markov model (HMM) with alphabet $\set{A}$.
\end{definition}

Let $\arr{z}=z_1z_2 \dots z_\ell$ be a sequence of symbols from alphabet $\set{A}$ of a given HMM.\@
The marginal likelihood of $\arr{z}$ is defined by
\begin{equation}\label{eq:hml}
  \mathrm{ML}(\arr{z}) \eqdef p(S_1=z_1, S_2=z_2, \dots, S_\ell=z_\ell).
\end{equation}

The standard HMM definition is often extended to include states that do not emit symbols. Those
states are referred to as silent states and are useful to describe a missing alignment position, for
example. This section goes a step further by defining a more general hidden Markov model that
accounts for states that instead emit sequence of symbols of variable length, including zero-length
sequences.

\begin{definition}
  Let $\set{A}$ be a non-empty finite set of symbols, $k\in\field{N}_0$, and define
  $\set{T}=\bigcup_{i=0}^k\set{A}^i$.
  Let $Q_1, Q_2, \dots$ be a Markov process and let $S_1, S_2, \dots$ be a stochastic process for
  which
  \begin{equation*}
    p(S_t\in\set{T} \gv Q_1=q_1, Q_2=q_2, \dots, Q_t=q_t)
    = p(S_t\in\set{T} \gv Q_t=q_t).
  \end{equation*}
  The pair $(Q_t, S_t)$ is an invisible Markov model (IMM) with alphabet $\set{A}$ and
  limit $k$.
\end{definition}

Let $\arr{z}=z_1z_2 \dots z_\ell$ be a sequence of symbols from alphabet $\set{A}$ of a given IMM.\@
The marginal likelihood of $\arr{z}$ cannot be written as in \Cref{eq:hml} since
we've lost the the order association between symbols and steps.
Instead, the marginal likelihood is given by
\begin{equation}\label{eq:ml}
  \mathrm{ML}(\arr{z}) \eqdef \sum_{t=1}^{\infty} p(S_{1..t}=\arr{z}, S_{t+1}\neq \emptyset),
\end{equation}
where $S_{1..t}$ denotes the concatenation of the random variables $S_1$, $S_2$, $\dots$, and $S_t$.
The inequality $S_{t+1}\neq \emptyset$ is necessary to avoid evaluating the same probability twice.
The infinity summation is also needed because of the possibility of existing cycles in the IMM
formed by states that are able to emmit empty sequences.

\begin{remark}
  The notation $p(S_{1..t}=\arr{z})$ is equal to the summation of the probabilities of every valid
  association between the random variables $S_1, S_2, \dots, S_t$ and the subsequences of $\arr{z}$,
  including empty subsequences. For example, let $a$ be a sequence composed of a single symbol. We
  have $p(S_{1..2}=a) = p(S_1=a, S_2=\emptyset) + p(S_1=\emptyset, S_2=a)$ by definition, where
  $\emptyset$ denotes an empty sequence.
\end{remark}

\subsection{Viterbi}

Let us consider first the Viterbi method applied to HMMs for a given sequence $\arr{z}$ of length
$\ell$.
Let
\begin{equation*}
  \viterbi(q_t) \eqdef \umax{q_{1..t-1}} \{ p(S_{1..t}=z_{1..t}, Q_{1..t}=q_{1..t}) \}
\end{equation*}
be the so-called Viterbi score. The $\max$ operator in the previous definition is the maximum across
all possible associations $Q_1=q_1, Q_2=q_2, \dots, Q_{t-1}=q_{t-1}$. Viterbi score is therefore the
maximum probability among all state paths that ends in $q_t$ and generates the prefix $z_{1..t}$
from sequence $\arr{z}$. The function domain of $\viterbi(q_t)$ is such that $t \in \{1, 2, \dots,
\ell\}$ and $q_t \in \set{Q}$.

Viterbi score can also be defined in a recursive fashion as follows:
\begin{equation*}
\begin{split}
  \viterbi(q_t)
  &= p(S_t=z_t \gv Q_t=q_t) \umax{q_{1..t-1}}
    \{ p(Q_t=q_t \gv Q_{t-1}=q_{t-1}) p(S_{1..t-1}=z_{1..t-1}, Q_{1..t-1}=q_{1..t-1}) \} \\
  &= p(S_t=z_t \gv Q_t=q_t) \umax{q_{t-1}}
    \{ p(Q_t=q_t \gv Q_{t-1}=q_{t-1})
    \umax{q_{1..t-2}} \{ p(S_{1..t}=z_{1..t-1}, Q_{1..t}=q_{1..t-1}) \} \} \\
  &= p(S_t=z_t \gv Q_t=q_t) \umax{q_{t-1}} \{ p(Q_t=q_t \gv Q_{t-1}=q_{t-1})
    \viterbi(q_{t-1}) \},
\end{split}
\end{equation*}
for $t>1$; and
\begin{equation*}
  \viterbi(q_1) = p(S_1=z_1 \gv Q_1=q_1) p(Q_1=q_1).
\end{equation*}

The simplicity of the notation $\viterbi(q_t)$ is no longer enough to define the Viterbi score for
IMMs as the index $t$ does not unambigously defines a prefix of $\arr{z}$. We will also make use of
an additional parameter $F_t\in \{0, 1, \dots, k\}$: $F_t=f_t$ means that $f_t$ is the length of the
sequence emitted by $S_t$.
For the sake of notation clarity, let us define $z_{i(f_t)..i} \eqdef
z_{i-f_t+1..i}$ as the $f_t$-length tail of a sequence $z_{1..i}$. The Viterbi score of an IMM
regarding a sequence $\arr{z}$ of length $\ell$ is defined by
\begin{equation}\label{eq:viterbi}
  \viterbi_{i}(q_t,f_t) \eqdef
    \umax{\substack{q_{1..t-1}\\f_{1..t-1}}}
    \{
      p(S_{1..t}=z_{1..i}, Q_{1..t}=q_{1..t} ~;~ F_{1..t}=f_{1..t})
    \}.
\end{equation}

The $\max$ operator in \Cref{eq:viterbi} is the maximum across all possible associations
$Q_1=q_1, Q_2=q_2, \dots, Q_{t-1}=q_{t-1}$ and $F_1=f_1, F_2=f_2, \dots, F_{t-1}=f_{t-1}$. Viterbi
score is therefore the maximum probability among all state paths that ends in $q_t$ emitting
$z_{i(f_t)..i}$ and generates the prefix $z_{1..i}$ from sequence $\arr{z}$. The function domain of
$\viterbi_{i}(q_t,f_t)$ is such that $t \in \{1, 2, \dots\}$, $i \in \{0, 1, \dots, \ell\}$, $f_t
\in \{0, 1, \dots, \min\{i, k\}\}$, and $q_t \in \set{Q}$.

Viterbi score for IMM can also be defined in a recursive way as follows:
\begin{equation*}
  \begin{split}
    \viterbi_{i}(q_t,f_t)
    &= p(S_t=z_{i(f_t)..i} \gv q_t)
      \uumax{q_{t-1}}{f_{t-1}}
      \{
        p(q_t \gv q_{t-1})
        \uumax{q_{1..t-2}}{f_{1..t-2}}
        \{
          p(S_{1..t-1}=z_{1..i-f_t}, q_{1..t-1} ~;~ f_{1..t-1})
        \}
      \}\\
    &= p(S_t=z_{i(f_t)..i} \gv q_t)
      \uumax{q_{t-1}}{f_{t-1}}
      \{
        p(q_t \gv q_{t-1}) \viterbi_{i-f_t}(q_{t-1},f_{t-1})
      \},
  \end{split}
\end{equation*}
for $t>1$; and
\begin{equation*}
  \viterbi_{f_1}(q_1,f_1) = p(S_1=z_{1..i} \gv Q_1=q_1) p(Q_1=q_1).
\end{equation*}


\chapter{Pseudo-code for Algorithms}
\label{chap:algorithms}
This chapter contains pseudo-code for the algorithms described in \sref{sec:definition_algorithms}. In the following sections, a graph $G$ consists of a set of vertices $V$ and a set of edges $E$. For undirected graphs, each edge is bidirectional, so if $(u, v) \in E$ then $(v, u) \in E$. Each vertex has a set of outgoing neighbors $N_\mathrm{out}(v) = \{u \in V | (v, u) \in E\}$ and a set of incoming neighbors $N_\mathrm{in}(v) = \{u \in V | (u, v) \in E\}$.

\section{Breadth-First Search (BFS)}

\begin{algorithm}[h!]
\begin{algorithmic}[1]
\Statex \textbf{input:} graph $G=(V,E)$, vertex $\textit{root}$
\Statex \textbf{output:} array $\textit{depth}$ storing vertex depths
\ForAll{$v \in V$}
  \State $\textit{depth}[v] \gets \infty$
\EndFor
\State $Q$ $\gets$  \textsc{create\_queue()}
\State \Call{$Q$.push}{$\textit{root}$}
\State $\textit{depth}[\textit{root}] \gets 0$
\While{\Call{$Q$.size}{} > 0}
  \State $v \gets $ \Call{$Q$.pop\_front}{ }
  \ForAll{$u \in N_\mathrm{out}(v)$}
    \If{$\textit{depth}[u] = \infty$}
      \State $\textit{depth}[u] \gets \textit{depth}[v] + 1$
      \State \Call{$Q$.push\_back}{$u$}
    \EndIf
  \EndFor
\EndWhile
\end{algorithmic}
\end{algorithm}

\section{PageRank (PR)}

\begin{algorithm}[h!]
\begin{algorithmic}[1]
\Statex \textbf{input:} graph $G=(V,E)$, integer $\textit{max\_iterations}$
\Statex \textbf{output:} array $\textit{rank}$ storing PageRank values
\ForAll{$v \in V$}
  \State $\textit{rank}[v] \gets \frac{1}{|V|}$
\EndFor
\For{$i=1,\ldots,\textit{max\_iterations}$}
\State $\textit{dangling\_sum} \gets 0$
\ForAll{$w \in V$}
  \If{$|N_\mathrm{out}(w)| = 0$}
    \State $\textit{dangling\_sum} \gets \textit{dangling\_sum} + \textit{rank}[w]$
  \EndIf
\EndFor
\ForAll{$v \in V$}
  \State $\textit{new\_rank}[v] \gets \frac{1-d}{|V|} + d \cdot \sum_{u \in N_\mathrm{in}(v)} \frac{\textit{rank}[u]}{|N_\mathrm{out}(u)|} + \frac{d}{|V|} \cdot \textit{dangling\_sum} $
\EndFor
\State $\textit{rank} \gets \textit{new\_rank}$
\EndFor
\end{algorithmic}
\end{algorithm}

\clearpage

\section{Weakly Connected Components (WCC)}

\begin{algorithm}[h!]
\begin{algorithmic}[1]
\Statex \textbf{input:} graph $G=(V,E)$
\Statex \textbf{output:} array $\textit{comp}$ storing component labels
\ForAll{$v \in V$}
  \State $\textit{comp}[v] \gets v$
\EndFor
\Repeat
\State $\textit{converged} \gets \text{true}$
\ForAll{$v \in V$}
  \ForAll{$u \in N_\mathrm{in}(v) \cup N_\mathrm{out}(v)$}
    \If{$\textit{comp}[v] > \textit{comp}[u]$}
      \State $\textit{comp}[v] \gets \textit{comp}[u]$
      \State $\textit{converged} \gets \text{false}$
     \EndIf
  \EndFor
\EndFor
\Until{$\textit{converged}$}
\end{algorithmic}
\end{algorithm}

\section{Local Clustering Coefficient (LCC)}

\begin{algorithm}[h!]
\begin{algorithmic}[1]
\Statex \textbf{input:} graph $G=(V,E)$
\Statex \textbf{output:} array $\textit{lcc}$ storing LCC values
\ForAll{$v \in V$}
   \State $d \gets |N_\mathrm{in}(v) \cup N_\mathrm{out}(v)|$
  \If {$d \geq 2$}
  \State $t \gets 0$
  \ForAll{$u \in N_\mathrm{in}(v) \cup N_\mathrm{out}(v)$}
    \ForAll{$w \in N_\mathrm{in}(v) \cup N_\mathrm{out}(v)$}
     \If{$(u, w) \in E$}
      \Comment{Check if edge $(u, w)$ exists}
      \State $t  \gets t + 1$
      \Comment{Found triangle $v-u-w$}
     \EndIf
    \EndFor
  \EndFor
    \State $\textit{lcc}[v] \gets \frac{t}{d(d-1)} $
  \Else
    \State $\textit{lcc}[v] \gets 0$
    \Comment{No triangles possible}
  \EndIf
\EndFor
\end{algorithmic}
\end{algorithm}

\clearpage

\section{Community Detection using Label Propagation (CDLP)}

\begin{algorithm}[h!]
\begin{algorithmic}[1]
\Statex \textbf{input:} graph $G=(V,E)$, integer $\textit{max\_iterations}$
\Statex \textbf{output:} array $\textit{labels}$ storing vertex communities
\ForAll{$v \in V$}
  \State $\textit{labels}[v] \gets v$
\EndFor
\For{$i=1, \ldots, \textit{max\_iterations}$}
 \ForAll{$v \in V$}
  \State $C$ $\gets$ \textsc{create\_histogram()}

  \ForAll{$u \in N_\mathrm{in}(v)$}
    \State \Call{$C$.add}{$\textit{labels}[u]$}
  \EndFor
  \ForAll{$u \in N_\mathrm{out}(v)$}
    \State \Call{$C$.add}{$\textit{labels}[u]$}
  \EndFor
  \State $\textit{freq} \gets $ \Call{$C$.get\_maximum\_frequency}{ }
  \Comment{Find maximum frequency of labels}
  \State $\textit{candidates} \gets$ \Call{$C$.get\_labels\_for\_frequency}{$\textit{freq}$}
  \Comment{Find labels with max.\ frequency}
  \State $\textit{new\_labels}[v] \gets$ \Call{min}{$\textit{candidates}$}
  \Comment{Select smallest label}
 \EndFor
 \State $\textit{labels} \gets \textit{new\_labels}$
\EndFor
\end{algorithmic}
\end{algorithm}

\section{Single-Source Shortest Paths (SSSP)}

\begin{algorithm}[h!]
\begin{algorithmic}[1]
\Statex \textbf{input:} graph $G=(V,E)$, vertex $\textit{root}$, edge weights $\textit{weight}$
\Statex \textbf{output:} array $\textit{dist}$ storing distances
\ForAll{$v \in V$}
  \State $\textit{dist}[v] \gets \infty$
\EndFor

\State $H$ $\gets \Call{create\_heap}{ }$
\State \Call{$H$.insert}{root, 0}
\State $\textit{dist}[\textit{root}] \gets 0$
\While{$\Call{$H$.size}{} > 0$}
  \State $v \gets$ \Call{$H$.delete\_minimum}{ }
  \Comment{Find vertex $v$ in $H$ such that $\textit{dist}[v]$ is minimal}
  \ForAll{$w \in N_\mathrm{out}(v)$}
    \If{$\textit{dist}[w] > \textit{dist}[v] + \textit{weight}[v,w]$}
      \State $\textit{dist}[w] \gets \textit{dist}[v] + \textit{weight}[v,w]$
      \State \Call{$H$.insert}{$w$, $\textit{dist}[w]$}
    \EndIf
  \EndFor
\EndWhile
\end{algorithmic}
\end{algorithm}


% Created 2020-03-11 mié 17:56
% Intended LaTeX compiler: pdflatex
\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{khpreamble}
\usepackage{pgfplots}
\usepackage{pdfpages}
\usepackage{circuitikz}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{positioning}
\renewcommand*{\not}[1]{\ensuremath{\bar{#1}}}
\renewcommand*{\not}[1]{\ensuremath{\overline{#1}}}
\author{Kjartan Halvorsen}
\date{2020-03-11}
\title{System identification of the tank}
\hypersetup{
 pdfauthor={Kjartan Halvorsen},
 pdftitle={System identification of the tank},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 26.3 (Org mode 9.3.6)},
 pdflang={English}}
\begin{document}

\maketitle

\section{Least squares, linear regression}
\label{sec:orgbed202b}

Consider observations from experiments below, where you have set some different values of the dependent variable  \(x\), run an experiments and observed the result \(y\).

  \begin{center}
  \begin{tikzpicture}
  \begin{axis}[
    width = 6cm,
    height = 4cm,
    ytick  = data,
    %    ytick = {0,4,6, 10},
    %xtick = {0,2, 4, 6, 8, 10, 12},
    %ymin = 0,
    %ymax = 10,
    ylabel = {$y$},
    xlabel = {$x$},
    ]

    \addplot[only marks, blue, domain=1:6, samples=6] { 1 + 3*x -0.4*x*x + 0.4*rand};

  \end{axis}
\end{tikzpicture}
\end{center}

Can you fit a suitable model to the data?

\subsection{Linear regression}
\label{sec:org21b8a5d}
Assume the model \(y = a_0x^2 + a_1x + a_2 + \epsilon\), where the residual \(\epsilon\) is the part of the observation \(y\) that cannot be explained by the model. We want to find the unknown parameters \(\theta = \begin{bmatrix} a_0 & a_1 & a_2\end{bmatrix}^T\) of the model given a set of experimental data \(\mathcal{D} = \{ (x_1, y_1),\, (x_2, y_2),\, \ldots, \, (x_N, y_N) \}\).

We can write the model as
\begin{equation}
\begin{align} \epsilon &= y - x^2a_0 - xa_1 - a_2 = y - \phi_0(x)a_0 - \phi_1(x)a_1 - \phi_2(x)a_2 = y - \underbrace{\begin{bmatrix}  \phi_0(x) & \phi_1(x) & \phi_2(x) \end{bmatrix}}_{\text{regressors}} \begin{bmatrix} a_0\\a_1\\a_3\end{bmatrix}\\ &= y - \phi(x)^T\theta.
\end{align}
\end{equation}
The model holds for all the observations, which gives
\begin{align*}
  \epsilon_1 &= y_1 - \phi(x_1)^T\theta\\
  \epsilon_2 &= y_2 - \phi(x_2)^T\theta\\
             &\vdots\\
  \epsilon_N &= y_n - \phi(x_N)^T\theta\\
\end{align*}

Linear regression, or least-squares fitting, is defined as the optimization problem
\begin{equation}
\begin{aligned}
\text{minimize}\quad  f(\theta) &= \frac{1}{2}\sum_{i=1}^N \epsilon_i^2  = \frac{1}{2} \sum_{i=1}^N (y_i - \phi(x_i)^T\theta)(y_i - \phi(x_i)^T\theta) \\ &= \frac{1}{2} \sum_{i=1}^N \Big(y_i^2 - 2y_i\phi(x_i)^T\theta + (\phi(x_i)^T\theta)^2\Big)
\end{aligned}
\end{equation}
This optimization problem has a closed-form solution found by setting the derivative of \(f\) wrt \(\theta\) equal to zero
\[ \frac{d}{d\theta} f(\theta) = 0 \]
\[ \frac{1}{2} \sum_{i=1}^N \Big( -2y_i\phi(x_i)}^T + 2(\phi(x_i)^T\theta)\phi(x_i)^T \big)
      = \sum_{i=1}^N \Big( -y_i\phi(x_i)^T + (\theta^T\phi(x_i))\phi(x_i)^T\big) = 0 \]
which is equivalent to (by taking the transpose on both sides)
\[ \sum_{i=1}^N \Big( \phi(x_i) \phi(x_i)^T \theta - \phi(x_i) y_i\Big) = 0.\]
\[ \Big(\sum_{i=1}^N \phi(x_i) \phi(x_i)^T\Big) \theta - \sum_{i=1}^N \phi(x_i) y_i = 0.\]
\[ \Big(\sum_{i=1}^N \phi(x_i) \phi(x_i)^T\Big) \theta =  \sum_{i=1}^N \phi(x_i) y_i .\]

Defining the matrices and vectors (with some abuse of notation)
\begin{align*}
  x &= \begin{bmatrix} x_1 & x_2 & \cdots & x_N \end{bmatrix}^T\\
  y &= \begin{bmatrix} y_1 & y_2 & \cdots & y_N \end{bmatrix}^T\\
  \epsilon &= \begin{bmatrix} \epsilon_1 & \epsilon_2 & \cdots & \epsilon_N \end{bmatrix}^T\\
  \Phi(x) &= \begin{bmatrix} \phi(x_1)^T\\\phi(x_2)^T\\\vdots\\\phi(x_N)^T\end{bmatrix}\\
\end{align*}
The problem can be written
\[
\text{minimize}\quad  f(\theta) = \frac{1}{2}\epsilon^T\epsilon = \frac{1}{2}(y -\Phi(x)\theta)^T(y-\Phi(x)\theta)\]
with solution
\[ \theta_{LS} = \Big( \Phi(x)^T\Phi(x) \Big)^{-1} \Phi(x)^T y\]

\subsection{In practice}
\label{sec:org8566269}
Given the model \(y = a_0x^2 + a_1x + a_2 + \epsilon\) and the data \(\mathcal{D} = \{ (x_1, y_1),\, (x_2, y_2),\, \ldots, \, (x_N, y_N) \}\), form the vectors and matrices

\begin{align*}
\Phi(x) &= \begin{bmatrix} x_1^2 & x_1 & 1\\x_2^2 & x_2 & 1\\\vdots & \vdots & \vdots\\x_N^2 & x_N & 1\end{bmatrix} \\
y &= \begin{bmatrix}y_1\\y_2\\\vdots\\y_N\end{bmatrix}
\end{align*}

Find the least-squares solution to
\[ \Phi(x)\theta = y.\]

In matlab
\begin{verbatim}
x = [x1, x2, x3, x4, x5, x6]';
y = [y1, y2, y3, y4, y5, y6]';
Phi = [x.^2, x, ones(size(x))];
theta = Phi \ y
\end{verbatim}

\subsection{What about fitting the model \(y = a_0 x^{a_1}\)?}
\label{sec:orgf11b322}
Take the logarithm (assuming positive \(x\) and \(y\))
\[ y = \log a_0 + a_1\log x\]

\section{The tank model}
\label{sec:org01022a6}

\subsection{ODE}
\label{sec:orga07be0b}

\[\frac{d}{dt} p = \alpha A \sqrt{p_s - p} = a (u_v - 5) \sqrt{p_s - p}\]

\subsection{Parameter estimation}
\label{sec:org275496d}
From experiments filling the tank with different values for \(u_v\) one obtains the following table (assuming u\textsubscript{s}=1V is p=1bar)
\begin{center}
\begin{tabular}{rrrrrr}
\(p_s\) & \(u_v\) & \(p\) & \(\Delta p\) & \(\Delta t\) & \(\dot{p}\)\\
\hline
5 & 5.5 & 0 & 0.86 & 1.51 & 0.56953642\\
5 & 6 & 0 & 0.84 & 0.22 & 3.8181818\\
5 & 9 & 0 & 1.16 & 0.238 & 4.8739496\\
\end{tabular}
\end{center}

The model is
\[ \begin{bmatrix} (u_{v_1} - 5)\sqrt{p_s - p_1} \\
                      (u_{v_2} - 5)\sqrt{p_s - p_2} \\
		      \vdots\\
		      (u_{v_N} - 5)\sqrt{p_s - p_N} \end{bmatrix} a = \begin{bmatrix} \dot{p}_1\\ \dot{p}_2\\\vdots\\ \dot{p}_N\end{bmatrix}
\]
\end{document}


\chapter{Search}
\label{chp:search}
Motion planning is about planning the motion of the robot to a certain target. Motion planning is all about finding the optimal or minimum cost path. This is illustrated in figure \ref{fig:search_mp}. A cost could be how long time it takes to reach a target by a certain path.

\myFigure{Theory/Search/motion_planning}{Motion Planning.}{fig:search_mp}{0.6}

Figure \ref{fig:search} illustrates an matrix with a start position 'S' and a goal position 'G'. All the grid cells which are filled out are closed cells. The goal is to find the shortest path to the goal from the start position. One way this can be done is be calculating the g(n) value for each cell. The g(n) value represents how many expansions it took to move to cell n.

\myFigure{Theory/Search/g_val}{Search.}{fig:search}{0.4}

This is just one example of a search algorithm. The problem with this algorithm is that with large matrices it become very inefficient. But with the knowledge of g(n) you can make it more efficient. A* is one example of this.
\section{A*}

A* is a search algorithm. It is variant of the search algorithm that is more efficient than expanding every cell or node.

\myFigure{Theory/Search/a_star}{A*.}{fig:a_star}{0.8}

In figure \ref{fig:a_star} a matrix like before is shown on the left, but with other obstacles, and a matrix with the heuristic values. The heuristic value h(n) is calculated by the distance from the node n to the goal.

A* utilizes this information by combining the heuristics cost and the expansion which is called f(n) = g(n) + h(n). This gives an advantage. With the knowledge of the heuristic function the computer can save calculation time because it does not need to search all nodes. This is represented by the green lines in figure \ref{fig:a_star}.


\documentclass[12pt]{pylatex}
\usepackage{examples}

\newbox\SlashInput
\setbox\SlashInput=\hbox{\tt\Large\verb|\Input|}

\begin{document}

\section*{Using {\copy\SlashInput}}

% \vspace{-5pt}

This simple example shows how {\tt\small\verb|\Input|} can be used in include other LaTeX sources within
the host source. Note the use of nested {\tt\small\verb|\Input|}'s. The merged file can be inspected by running

\begin{lstlisting}
   merge-src.py -i example-10.tex -o merged.tex
\end{lstlisting}

from the command line. The merged file will be named {\tt\small merged.tex}.

\PySetup{action=verbatim}

% Note: The * in the 1st column is to ensure the python preprocessor does not respond
%       to any of the \begin{...} or \end{...} lines. The \end{document} line is the
%       real problem as it terminates the preprocessing.
%       The * is hidden from LaTeX by way of the listinings option gobble=2.

\vspace{-5pt}

% ===================================================================
\section*{Source of example-10.tex}

\bgroup
\bgcolour{white}
\latexstyle
\begin{latex}
*   \Input{./example-10/limits/limits.tex}
*   \Input{./example-10/calculus/calculus.tex}
\end{latex}
\egroup

\vspace{10pt}

% ===================================================================
\section*{Source of example-10/limits/limits.tex}

\bgroup
\bgcolour{white}
\latexstyle
\begin{latex}
*   \section*{Limits}
*
*   \begin{python}
\end{latex}
\pythonstyle
\begin{python}
*      from sympy import *
*      a, n, x, dx = symbols('a n x dx')
*      ans = limit(sin(4*x)/x,x,0)                  # py (ans.301,ans)
*      ans = limit(2**x/x,x,oo)                     # py (ans.302,ans)
*      ans = limit(((x+dx)**2 - x**2)/dx, dx,0)     # py (ans.303,ans)
*      ans = limit((4*n + 1)/(3*n - 1),n,oo)        # py (ans.304,ans)
*      ans = limit((1+(a/n))**n,n,oo)               # py (ans.305,ans)
\end{python}
\latexstyle
\begin{latex}
*   \end{python}
*
*   \begin{align*}
*      &\py*{ans.301}\\
*      &\py*{ans.302}\\
*      &\py*{ans.303}\\
*      &\py*{ans.304}\\
*      &\py*{ans.305}
*   \end{align*}
\end{latex}
\egroup

\clearpage

% ===================================================================
\section*{Source of example-10/calculus/calculus.tex}
\begin{latex}
*   \Input{./example-10/calculus/derivs/derivs.tex}
*   \Input{./example-10/calculus/integrals/integrals.tex}
\end{latex}

% ===================================================================
\section*{Source of example-10/calculus/derivs/derivs.tex}

\bgroup
\bgcolour{white}
\latexstyle
\begin{latex}
*   \section*{Differentiation}
*
*   \begin{python}
\end{latex}
\pythonstyle
\begin{python}
*      ans = diff(x*sin(x),x)                                    # py (ans.501,ans)
*      ans = diff(x*sin(x),x).subs(x,pi/4)                       # py (ans.502,ans)
\end{python}
\latexstyle
\begin{latex}
*   \end{python}
*
*   \begin{align*}
*      &\py*{ans.501}\\
*      &\py*{ans.502}
*   \end{align*}
\end{latex}
\egroup

% ===================================================================
\section*{Source of example-10/calculus/integrals/integrals.tex}

\bgroup
\bgcolour{white}
\latexstyle
\begin{latex}
*   \section*{Integration}
*
*   \begin{python}
\end{latex}
\pythonstyle
\begin{python}
*      a, b, x, y = symbols('a b x y')
*      ans = integrate(2*sin(x)**2, (x,a,b))                     # py (ans.503,ans)
*      ans = Integral(2*exp(-x**2), (x,0,oo))                    # py (lhs.504,ans)
*      ans = ans.doit()                                          # py (ans.504,ans)
*      ans = Integral(Integral(x**2 + y**2, (y,0,x)), (x,0,1))   # py (lhs.505,ans)
*      ans = ans.doit()                                          # py (ans.505,ans)
\end{python}
\latexstyle
\begin{latex}
*   \end{python}
*
*   \begin{align*}
*      &\py*{ans.503}\\
*       \py{lhs.504}&=\Py{ans.504}\\
*       \py{lhs.505}&=\Py{ans.505}
*   \end{align*}
\end{latex}
\egroup

\clearpage

\PySetup{action=show}

\Input{./example-10/limits/limits.tex}
\Input{./example-10/calculus/calculus.tex}

\end{document}


\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{graphicx}
\usepackage{tabularx}

\usepackage{enumitem}

\usepackage[english]{babel}
\newtheorem{theorem}{Theorem}

% Geometry
\usepackage{geometry}
\geometry{letterpaper, left=15mm, top=20mm, right=15mm, bottom=20mm}

% Fancy Header
\usepackage{fancyhdr}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}
\fancyhf{}
\chead{MAT 341 - Linear Algebra}
\lfoot{CALU Fall 2021}
\rfoot{RDK}

% Add vertical spacing to tables
\renewcommand{\arraystretch}{1.4}

% Macros
\newcommand{\definition}[1]{\underline{\textbf{#1}}}

\newenvironment{rcases}
  {\left.\begin{aligned}}
  {\end{aligned}\right\rbrace}

% Begin Document
\begin{document}

\section*{Chapter 1: Theorems \& Defintions}

\vspace{5mm}

\begin{theorem}[Uniqueness of the Reduced Echelon Form]
  Each matrix is row equivalent to one and only one reduced echelon matrix.
\end{theorem}

\vspace{5mm}

\begin{theorem}[Existence and Uniqueness Theorem]
  A linear system is consistent if and only if the rightmost column of the augmented matrix is \textit{not} a pivot column; ie, if and only if an echelon form of the augmented matrix has no row of the form $[0 \cdots 0 b]$ with $b$ nonzero.
\end{theorem}

\vspace{5mm}

\definition{Spans}: If $v_1, \ldots, v_p$ are in $\mathbb{R}^2$ the the set of all linear combinations of $v_1, \ldots, v_p$ is denoted by \textbf{Span}$\{v_1, \ldots, v_p\}$ and is called the \definition{subset of $\mathbb{R}^2$ spanned by $v_1, \ldots, v_p$}. That is, \textbf{Span}$\{v_1, \ldots, v_p\}$ is the collection of all vectors, with scalars $c_1, \ldots, c_p$, that can be written as
\begin{equation*}
  c_1v_1 + c_2v_2 + \cdots + c_pv_p
\end{equation*}

\vspace{5mm}

\definition{Matrix Equation}: If $A$ is an $m \times n$ matrix, with columns $a_1, \ldots, a_n$, and if $x$ is in $\mathbb{R}^n$, then the product of $A \times x$, by $Ax$ is the linear combination of the columns of $A$ using the corresponding entries in $x$ as weights:
\begin{equation*}
  Ax = \begin{bmatrix}
    a_1 & a_2 & \cdots & a_n
  \end{bmatrix}
  \begin{bmatrix}
    x_1 \\ x_2 \\ \cdots \\ x_n
  \end{bmatrix}
  = x_1a_1 + x_2a_2 + \cdots + x_na_n
\end{equation*}

\vspace{5mm}

\begin{theorem}
  If $A$ is an $m \times n$ matrix, with columns $a_1, \ldots, a_n$, and if $b$ is in $\mathbb{R}^m$, then the matrix equation $Ax = b$ has the same solution set as the vector equation
  \begin{equation*}
    x_1a_1 + x_2a_2 + \cdots + x_na_n
  \end{equation*}
  which, in turn, has the same solution set as the system of linear equations whose augmented matrix is
  \begin{equation*}
    Ax = \begin{bmatrix}
      a_1 & a_2 & \cdots & a_n & b
    \end{bmatrix}
  \end{equation*}
\end{theorem}

\vspace{5mm}

\begin{theorem}
  Let $A$ be an $m \times n$ matrix. Then the following statements are logically equivalent. That is, for a particular $A$, either they are all true statements or they are all false.
  \begin{enumerate}[label=\alph*.)]
    \item For each $b$ in $\mathbb{R}^m$, the equation $Ax = b$ has a solution.
    \item Each $b$ in $\mathbb{R}^m$ is a linear combination of the columns of $A$.
    \item The columns of $A$ span $\mathbb{R}^m$.
    \item $A$ has a pivot position in every row.
  \end{enumerate}
\end{theorem}

\vspace{5mm}

\begin{theorem}
  If $A$ is an $m \times n$ matrix, $u$ and $v$ are vectors in $\mathbb{R}^n$, and $c$ is a scalar, then
  \begin{enumerate}[label=\alph*.)]
    \item $A(u + v) = Au + Av$
    \item $A(cu) = c(Au)$
  \end{enumerate}
\end{theorem}

\pagebreak

\definition{Homogeneous Systems}: A system of linear equations is said to be \textbf{homogeneous} if it can be written in the form $Ax = 0$, where $A$ is an $m \times n$ matrix and $0$ is the zero vector in $\mathbb{R}^m$.
\begin{itemize}
  \item Such a system \textit{always} has at least one solution, namely the \textbf{trivial solution}, the zero vector.
  \item Such a system has a nontrivial solution if and only if the equation has at least one free variable.
\end{itemize}

\vspace{5mm}

\definition{Linear Independence}: An indexed set of vectors $\{v_1, \ldots, v_p\}$ in $\mathbb{R}^n$ is said to be \textbf{linearly independent} if the vector equation
\begin{equation*}
  x_1v_1 + x_2v_2 + \cdots + x_pv_p
\end{equation*}
has only the trivial solution. The set $\{v_1, \ldots, v_p\}$ is said to be \textbf{linearly dependent} if there exist weights $\{c_1, \ldots, c_p\}$, not all zero, such that
\begin{equation*}
  c_1v_1 + c_2v_2 + \cdots + c_pv_p = 0
\end{equation*}

\vspace{5mm}

\begin{theorem}[Characterization of Linearly Dependent Sets]
  An indexed set $S = \{v_1, \ldots, v_p\}$ of two or more vectors is linearly dependent if and only if at least one of the vectors in $S$ is a linear combination of the others.
\end{theorem}

\vspace{5mm}

\begin{theorem}
  If a set contains more vectors than there are entries in each vector, then the set is linearly dependent. That is, any set $\{v_1, \ldots, v_p\}$ in $\mathbb{R}^n$ is linearly dependent if $p > n$.
\end{theorem}

\vspace{5mm}

\begin{theorem}
  If a set $S = \{v_1, \ldots, v_p\}$ in $\mathbb{R}^n$ contains the zero vector, then the set is linearly dependent.
\end{theorem}

\end{document}


\documentclass[letterpaper]{article}

\usepackage[utf8]{luainputenc}
\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{13 mars, 2015}
\maketitle
let $\epsilon>0$ and $f\in C[0,1]$
Then there is $N$ such that $||f-B_n(f)||_\infty<\epsilon$ for all $n>N$.

$B_n(f)=\sum\limits_{k=0}^n{f(\frac{k}{n}\binom{n}{k}x^k(1-x)^{n-k}}$

\begin{enumerate}
\item
since $[0,1]$ is compact and $f\in C[0,1]$ f is uniformly continuous on $[0,1]$ so there is $\delta$ such that $|f(x)-f(y)|<\frac{\epsilon}{2}$ when $|x-y|< \delta$
\item
$f$ is bounded on $[0,1]$ so $|f(x)|\le M=\sup\{|f(x)|\}$ for all $x\in [0,1]$
\item
now for $a\in [0,1]$, if $|x-a|<\delta$ then $|f(x)-f(a)|<\epsilon/2+\frac{2M}{\delta^2}(x-a)^2$

if $|x-a|\epsilon \delta$ then $|f(x)-f(a)\le|f(x)|+|f(a)|\le 2M\le 2M/\left(x-a)/\delta\right)^2\le \frac{2M}{\delta^2}(x-a)^2+\frac{\epsilon}{2}$

so for a fixed $a$, no matter what $x$ we let $|f(x)-f(a)|<\epsilon/2+\frac{2M}{\delta^2}(x-a)^2$.

this is not a good estimate, but it's an estimate that works no matter what.

\item
$B_n(f(x)-f(a)\cdot 1)=B_n(f(x))-B_n(f(a)\cdot1)=B_n(f(x))-f(a)B_n(1)=B_n(f(x))-f(a)\cdot 1$ where $1$ is the function that is one for all $x$ and $f(a)$ is a constant.

\end{enumerate}

so $|B_n(f(x))-f(a)|=|B_n(f(x)-f(a)\cdot1)|\le B_n(|f(x)-f(a)\cdot 1|)\le B_n(\epsilon/2+2M/\delta^2(x-a)^2)=B_n(\epsilon/2)+2M/\delta^2B_n((x-a)^2)=\epsilon/2+2M/\delta^2[B_n(x^2-2ax+a^2]=\frac{\epsilon}{2}+2M/\delta^2(B_n(x^2)-2aB_n(x)+a^2)=\frac{\epsilon}{2}+\frac{2M}{\delta^2}((x^2+\frac{x-x^2}{n})-2a(x)+a^2$

recall that $B_n(1)=1, B_n(x)=x,$ and $B_n(x^2)=\frac{x+(n-1)x^2}{n}=x^2+\frac{x-x^2}{n}$

if $g(x)=x-x^2$ then it's max in $[0,1]$ is $g(\frac{1}{2})=\frac{1}{4}$ and so $|(B_n(f))(a)-f(a)\cdot 1|<\epsilon/2+2M/\delta^2$

so $|(B_n(f))(a)-f(a)\cdot 1|<\epsilon/2+2M/\delta^2\frac{a-a^2}{n}$ so $|(B_n(f))(a)-f(a)\cdot 1|<\epsilon/2+2M/\delta^2(\frac{1}{4n})$

\subsubsection*{finish}
this inequality does not depend on $a$. $||B_n(f)-f||_\infty<\epsilon/2+\frac{2M}{\delta^2}\frac{1}{4n}$. Choos $N$ such that $N\ge \frac{M}{\delta^2\epsilon}$

so $\frac{M}{2\delta^2N}<\epsilon/2$ and $||B_n(f)-f||_\infty<\epsilon/2+\epsilon/2=\epsilon$ for any $n>N$ in other words, $\{B_n(f)\}$ converges to $f$ uniformly on $[0,1]$

\end{document}


\chapter{Physics Models}
\label{ch:models}

\apsq implements a variety of models to describe the physics of semiconductor detectors.
These models are implemented module-independently and can be selected via configuration parameters in the respective models.
This chapter serves as central reference for the different models.

\section{Charge Carrier Mobility}
\label{sec:mobility}

\apsq provides different charge carrier mobility models, the best-suited model depends on the simulated device and other simulation parameters.
Some models depend on the electric field strength to parametrize the mobility, others on the doping concentration of the device.
The charge carrier mobility models are used by all propagation modules and comprise the following models:

\subsection{Jacoboni-Canali Model}
\label{sec:mob:jac}

The Jacoboni-Canali model~\cite{jacoboni} is the most widely used parametrization of charge carrier mobility in Silicon as a function of the electric field $E$.
It has originally been derived for $\left<111\right>$ silicon lattice orientation, but is widely used also for the common $\left<100\right>$ orientation.
The mobility is parametrized as
\begin{equation}
    \label{eq:mob:jac}
    \mu (E) = \frac{v_m}{E_c} \frac{1}{\left(1 + (E / E_c)^\beta \right)^{1 / \beta}},
\end{equation}
where $v_m$, $E_c$, and $\beta$ are phenomenological parameters, defined for electrons and holes respectively.
The temperature dependence of these parameters is taken into account by scaling them with respect to a reference parameter value as
\begin{equation}
    A = A_{ref} \cdot T^{\gamma}
\end{equation}
where $A_{ref}$ is the reference parameter value, $T$ the temperature in units of \si{K}, and $\gamma$ the temperature scaling factor.

The parameter values implemented in \apsq are taken from Table~5 of~\cite{jacoboni} as:
\begin{equation*}
    \begin{split}
        v_{m,e} &= \num{1.53e9} \cdot T^{-0.87}\,\si{cm \per s}\\
        E_{c,e} &= \num{1.01} \cdot T^{1.55}\,\si{V \per cm}\\
        \beta_e &= \num{2.57e-2} \cdot T^{0.66}
    \end{split}
    \qquad
    \begin{split}
        v_{m,h} &= \num{1.62e8} \cdot T^{-0.52}\,\si{cm \per s}\\
        E_{c,h} &= \num{1.24} \cdot T^{1.68}\,\si{V \per cm}\\
        \beta_h &= \num{0.46} \cdot T^{0.17}
    \end{split}
\end{equation*}
for electrons and holes, respectively.

This model can be selected in the configuration file via the parameter \parameter{mobility_model = "jacoboni"}.

\subsection{Canali Model}
\label{sec:mob:can}

The Canali model~\cite{canali} differs from the Jacoboni-Canali model from equation~\eqref{eq:mob:jac} only by the value of $v_m$ for electrons.
The difference is most likely a typo in the Jacoboni reproduction of the parametrization, so this one can be considered the original parametrization derived from data.
The altered value is taken from equation~2a in~\cite{canali} and amounts to
\begin{equation*}
    v_{m,e} = \num{1.43e9} \cdot T^{-0.87}\,\si{cm \per s}
\end{equation*}

A comparison with other models exhibits a better accordance of the electron mobility compared to the Jacoboni-Canali parameter value, especially at very high values of the electric field.

This model can be selected in the configuration file via the parameter \parameter{mobility_model = "canali"}.

\subsection{Hamburg Model}

The Hamburg model~\cite{hamburg} presents an empirical parametrization of electron and hole mobility as a function of the electric field $E$ based on measurements of drift velocities in high-ohmic silicon with $\left<100\right>$ lattice orientation.
The mobility is parametrized as
\begin{align}
    \label{eq:mob:ham}
    \mu_e^{-1}(E) &= 1 / \mu_{0,e} + E / v_{sat} \nonumber \\
    \mu_h^{-1}(E) &= 1 / \mu_{0,h} &\quad \textrm{for} \quad E < E_0 \nonumber \\
                  &= 1 / \mu_{0,h} + b \cdot (E - E_0) + c \cdot (E - E_0)^2 &\quad \textrm{for} \quad E \geq E_0
\end{align}
as taken from equations~3 and~5 of~\cite{hamburg}.

The temperature dependence of the model parameters are calculated with respect to their reference values at a temperature of \SI{300}{K} via equation~6 of~\cite{hamburg} as
\begin{equation}
    \label{eq:mob:ham:temp}
    A_i = A_i(T = \SI{300}{K}) \cdot \left(\frac{T}{\SI{300}{K}}\right)^{\gamma_i}
\end{equation}
The hole mobility parameter $c$ is assumed to have no temperature dependence.

The parameter values implemented in \apsq are taken from Table~4 of~\cite{hamburg} as:
\begin{equation*}
    \begin{split}
        \mu_{0,e} &= \SI{1530}{cm^2 \per V \per s} \cdot (T / \SI{300}{K})^{-2.42}\\
        v_{sat}   &= \SI{1.03e7}{cm \per s} \cdot (T / \SI{300}{K})^{-0.226}\\
    \end{split}
    \qquad
    \begin{split}
      \mu_{0,h} &= \SI{464}{cm^2 \per V \per s} \cdot (T / \SI{300}{K})^{-2.20}\\
        b       &= \SI{9.57e-8}{cm \per s} \cdot (T / \SI{300}{K})^{-0.101}\\
        c       &= \SI{-3.31e-13}{s \per V}\\
        E_0     &= \SI{2640}{V \per cm} \cdot (T / \SI{300}{K})^{0.526}
    \end{split}
\end{equation*}
for electrons and holes, respectively.

This model can be selected in the configuration file via the parameter \parameter{mobility_model = "hamburg"}.

\subsection{Hamburg High-Field Model}

The Hamburg high-field model~\cite{hamburg} takes the same form as the Hamburg model provided in equation~\eqref{eq:mob:ham} but uses a different set of parameter values.
The values are taken from Table~3 of~\cite{hamburg} and are suitable for electric field strengths above \SI{2.5}{\kilo V/cm}.
Again, no temperature dependence is assumed on hole mobility parameter $c$, while all other parameters are scaled to temperatures different than \SI{300}{K} using equation~\eqref{eq:mob:ham:temp}.

The parameter values implemented in \apsq are:
\begin{equation*}
    \begin{split}
        \mu_{0,e} &= \SI{1430}{cm^2 \per V \per s} \cdot (T / \SI{300}{K})^{-1.99}\\
        v_{sat}   &= \SI{1.05e7}{cm \per s} \cdot (T / \SI{300}{K})^{-0.302}\\
    \end{split}
    \qquad
    \begin{split}
      \mu_{0,h} &= \SI{457}{cm^2 \per V \per s} \cdot (T / \SI{300}{K})^{-2.80}\\
        b       &= \SI{9.57e-8}{cm \per s} \cdot (T / \SI{300}{K})^{-0.155}\\
        c       &= \SI{-3.24e-13}{s \per V}\\
        E_0     &= \SI{2970}{V \per cm} \cdot (T / \SI{300}{K})^{0.563}
    \end{split}
\end{equation*}
for electrons and holes, respectively.

This model can be selected in the configuration file via the parameter \parameter{mobility_model = "hamburg_highfield"}.

\subsection{Masetti Model}
\label{sec:mob:mas}

The Masetti mobility model~\cite{masetti} parametrizes electron and hole mobility as a function of the total doping concentration $D$ of the silicon material.
This model requires a doping profile to be loaded for the detector in question, and an error will be returned if the doping profile is missing.

While this mobility model requires the \emph{total doping concentration} $N_D + N_A$ as parameter, the doping profile used throughout \apsq provides the \emph{effective doping concentration} $N_D - N_A$ since this also encodes the majority charge carriers via its sign.
However, in the parts of a silicon detector relevant for this simulation, i.e.\ the sensing volume, the difference between effective and total concentration is expected to be negligible.
Therefore the doping concentration in this model is taken as the absolute value $N = \left|N_D - N_A\right|$.

The mobility is parametrized as
\begin{equation}
    \label{eq:mob:mas}
    \begin{split}
        \mu_e(N) &= \mu_{0,e} + \frac{\mu_{max,e} - \mu_{0,e}}{1 + (N / C_{r,e})^{\alpha_e}} - \frac{\mu_{1,e}}{(1 + (C_{s,e} / N)^{\beta_e})}\\
        \mu_h(N) &= \mu_{0,h} + \frac{\mu_{max,h}}{1 + (N / C_{r,h})^{\alpha_h}} - \frac{\mu_{1,h}}{(1 + (C_{s,h} / N)^{\beta_h})} + e^{P_c / N}\\
\end{split}
\end{equation}
as taken from equations~1 (for electrons) and~4 (for holes) of~\cite{masetti}.

Only the parameters $\mu_{max}$ for both electrons and holes are temperature dependent and are scaled according to Equation~\eqref{eq:mob:ham:temp} with parameters $\gamma_e = -2.5$ for electrons and $\gamma_h = -2.2$ for holes.

The parameter values implemented in \apsq are taken from Table~I of~\cite{masetti} as:
\begin{equation*}
    \begin{split}
        \mu_{0,e}   &= \SI{52.2}{cm^2 \per V \per s}\\
        \mu_{max,e} &= \SI{1417}{cm^2 \per V \per s} \cdot (T / \SI{300}{K})^{-2.5}\\
        C_{r,e}     &= \SI{9.68e16}{\per \cubic \cm}\\
        \alpha_{e}  &= 0.68\\
        \mu_{1,e}   &= \SI{43.4}{cm^2 \per V \per s}\\
        C_{s,e}     &= \SI{3.43e20}{\per \cubic \cm}\\
        \beta_{e}   &= 2.0\\
    \end{split}
    \qquad
    \begin{split}
        \mu_{0,h}   &= \SI{44.9}{cm^2 \per V \per s}\\
        \mu_{max,h} &= \SI{470.5}{cm^2 \per V \per s} \cdot (T / \SI{300}{K})^{-2.2}\\
        C_{r,h}     &= \SI{2.23e17}{\per \cubic \cm}\\
        \alpha_{h}  &= 0.719\\
        \mu_{1,h}   &= \SI{29.0}{cm^2 \per V \per s}\\
        C_{s,h}     &= \SI{6.1e20}{\per \cubic \cm}\\
        \beta_{h}   &= 2.0\\
        P_{c}       &= \SI{9.23e16}{\per \cubic \cm}\\
    \end{split}
\end{equation*}
for electrons and holes, respectively.

This model can be selected in the configuration file via the parameter \parameter{mobility_model = "masetti"}.

\subsection{Arora Model}

The Arora mobility model~\cite{arora} parametrizes electron and hole mobility as a function of the total doping concentration of the silicon material.
This model requires a doping profile to be loaded for the detector in question, and an error will be returned if the doping profile is missing.
The same caveat to doping concentration information in \apsq applies as described in the previous section.

The mobility is parametrized as
\begin{equation}
    \label{eq:mob:aro}
    \begin{split}
        \mu_e(N) &= \mu_{min,e} + \mu_{0,e} / \left(1 + (N / N_{ref,e})^{\alpha}\right)\\
        \mu_h(N) &= \mu_{min,h} + \mu_{0,h} / \left(1 + (N / N_{ref,h})^{\alpha}\right)\\
    \end{split}
\end{equation}
as taken from equations~8 (for electrons) and~12 (for holes) of~\cite{arora}.

The parameter values are provided at the reference temperature of \SI{300}{K} and scaled to different temperatures according to Equation~\eqref{eq:mob:ham:temp}.
The values implemented in \apsq are taken from Table~1 of~\cite{arora} as:
\begin{equation*}
    \begin{split}
        \mu_{min,e} &= \SI{88.0}{cm^2 \per V \per s} \cdot (T / \SI{300}{K})^{-0.57}\\
        \mu_{0,e}   &= \SI{7.40e8}{cm^2 \per V \per s} \cdot (T / \SI{300}{K})^{-2.33}\\
        N_{ref,e}   &= \SI{1.26e17}{\per \cubic \cm} \cdot (T / \SI{300}{K})^{2.4}\\
    \end{split}
    \qquad
    \begin{split}
        \mu_{min,h} &= \SI{54.3}{cm^2 \per V \per s} \cdot (T / \SI{300}{K})^{-0.57}\\
        \mu_{0,h}   &= \SI{1.36e8}{cm^2 \per V \per s} \cdot (T / \SI{300}{K})^{-2.23}\\
        N_{ref,h}   &= \SI{2.35e17}{\per \cubic \cm} \cdot (T / \SI{300}{K})^{2.4}\\
        \alpha   &= 0.88 \cdot (T / \SI{300}{K})^{-0.146}
    \end{split}
\end{equation*}
for electrons and holes, respectively.

This model can be selected in the configuration file via the parameter \parameter{mobility_model = "arora"}.

\subsection{Extended Canali Model}

This model extends the Jacoboni/Canali model described in Section~\ref{sec:mob:jac} with other doping concentration dependent, low-field models such as the Masetti model described in Section~\ref{sec:mob:mas}.
This technique is for example used in the Synopsys Sentaurus TCAD software.

The mobility is then parametrized using the two models as:
\begin{equation}
    \label{eq:mob:mascan}
    \mu (E, N) = \frac{\mu_{m}(N)}{\left(1 + \left(\mu_{m}(N) \cdot E / v_{m} \right)^{\beta} \right)^{1 / \beta}}
\end{equation}
where $\mu_{m}(N)$ is the Masetti mobility from Equation~\eqref{eq:mob:mas}, and $v_{m}$, $\beta$ are the respective parameters from the Jacoboni/Canali model presented in Sections~\ref{sec:mob:jac}~and~\ref{sec:mob:can}.

This model can be selected in the configuration file via the parameter \parameter{mobility_model = "masetti_canali"}.

\section{Charge Carrier Lifetime \& Recombination}
\label{sec:recombination}

\apsq provides the possibility to simulate finite lifetimes of charge carriers as a function of the local doping concentration via non-radiative recombination processes.
While most of these models require the \emph{total doping concentration} $N_D + N_A$ as parameter, the doping profile used throughout \apsq provides the \emph{effective doping concentration} $N_D - N_A$ since this also encodes the majority charge carriers via its sign - an information relevant to some of the models.
However, in the parts of a silicon detector relevant for this simulation, i.e.\ the sensing volume, the difference between effective and total concentration is expected to be negligible.
Therefore the two values are treated as equivalent throughout the lifetime models and the doping concentration is taken as the absolute value $N = \left|N_D - N_A\right|$.

Whether a charge carrier has recombined with the lattice is calculated for every step of the simulation using the relation
\begin{equation}
    \label{eq:recomb:prob}
    p < 1 - e^{- dt / \tau(N)}
\end{equation}
where $p$ is a recombination probability, drawn from a uniform distribution with $[0, 1]$, $dt$ is the last time step of the charge carrier motion and $\tau$ the lifetime for the local doping concentration calculated by the models described in the following.
If Equation~\eqref{eq:recomb:prob} evaluates to \emph{false}, the charge carrier still exists, if it evaluates to \emph{true} it has been recombined with the lattice.

Finite charge carrier lifetime can be simulated by all propagation modules and comprise the following models:

\subsection{Shockley-Read-Hall Recombination}

This model describes the finite lifetime based on Shockley-Read-Hall or trap-assisted recombination of charge carriers with the lattice~\cite{shockley-read,hall}.
The lifetime is calculated using the Shockley-Read-Hall relation as given by~\cite{fossum-lee}:
\begin{equation}
    \tau(N) = \frac{\tau_0}{1 + \frac{N}{N_{d0}}}
\end{equation}
where $\tau_0$ and $N_{d0}$ are reference lifetime and doping concentration, for electrons and holes respectively.
The parameter values implemented in \apsq are taken from~\cite{fossum} as:
\begin{equation*}
    \begin{split}
        \tau_{0,e} &= \SI{1e-5}{s} \\
        N_{d0,e}   &= \SI{1e16}{\per \cubic \cm} \\
    \end{split}
    \qquad
    \begin{split}
        \tau_{0,e} &= \SI{4.0e-4}{s} \\
        N_{d0,e}   &= \SI{7.1e15}{\per \cubic \cm} \\
    \end{split}
\end{equation*}

This model can be selected in the configuration file via the parameter \parameter{recombination_model = "srh"}.

\subsection{Auger Recombination}

The charge carrier lifetime according to the Auger recombination model is calculated as:
\begin{equation}
    \tau(N) = \frac{1}{C_{a} \cdot N^2}
\end{equation}
where $C_{a}$ is the Auger coefficient, taken as $C_{a} = \SI{3.8e-31}{\cm^6 \per \s}$ from~\cite{dziewior}.

This recombination mode applies to minority charge carriers only, majority charge carriers have an infinite life time under this model and Equation~\eqref{eq:recomb:prob} will always evaluate to \emph{true}.

This model can be selected in the configuration file via the parameter \parameter{recombination_model = "auger"}.

\subsection{Combined SRH/Auger Recombination}

This model combines the charge carrier recombination from the Shockley-Read-Hall and the Auger model by inversely summing the individual lifetimes calculated by the models via
\begin{align}
    \label{eq:recom:combined}
    \tau^{-1}(N) &= \tau_{srh}^{-1}(N) + \tau_{a}^{-1}(N) &\quad \textrm{for \emph{minority} charge carriers} \nonumber \\
              &= \tau_{srh}^{-1}(N) &\quad \textrm{for \emph{majority} charge carriers}
\end{align}
where $\tau_{srh}(N)$ is the Shockley-Read-Hall and $\tau_{a}(N)$ the Auger lifetime.
The latter is only taken into account for minority charge carriers.

This model can be selected in the configuration file via the parameter \parameter{recombination_model = "srh_auger"}.


\newcommand{\bY}{\mathbf{Y}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\PP}{\text{PP}}
%\nipsfinalcopy % Uncomment for camera-ready version

% \subsection{Notation}
%
% Unless otherwise specified, we let lower-case English alphabet characters indicate scalars $x \in \Real$. Bold indicates column vectors $\mb{x} \in \Real^p$,
% and upper-case bold indicates matrices, $\bX \in \Real^{p \times q}$.  Parameters and constants are Greek characters.  Time is $t \in [0,T]$,
% $i \in [N]$ indexes the $N$ neurons, where $[N]=\{1,2,\ldots,N\}$. Script denotes sets and pipes denote the cardinality of the set, e.g. $|\mc{T}|$.  We let $\equiv$ denote ``is shorthand for''. San serif fonts, e.g., $\mathsf{H}$, denote functions.
% %\vspace{-.1in}
% \subsection{Input}
% %\vspace{-.1in}
% % \subsection{Data Model}
% Our data is a time-series of multielectrode recordings $\bX \equiv (\bx_1, \cdots, \bx_T)$, and consists of $T$ recordings from $M$ channels.
% The set of recording times lie on regular grid with interval length $\Delta$, while $\bx(t) \equiv \bx_t\in \mathbb{R}^M$ for all $t$.
% This time-series of electrical activity is driven by an unknown number of neurons;
% we do not wish to bound this number \emph{a priori}. %, though only a few of the infinite
% =======
% \subsection{Data Model}

Our data is a time-series of multielectrode recordings $\bX \equiv (\bx_1, \cdots, \bx_T)$, and consists of $T$ recordings from $M$ channels.
As in usual measurement systems, the recording times lie on regular grid, with interval length $\Delta$, and $\bx_t \in \mathbb{R}^M$ for all $t$.
Underlying these observations is a continuous-time electrical signal driven by an unknown number of neurons. %and
%we do not wish to bound this number \emph{a priori}. %, though only a few of the infinite
% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f
%neurons dominate. These neurons contribute the majority of the activity in any finite interval of time; however, as time passes, the total number of
%observed neurons increases {\color{red}(Justify?)}.
%Each neuron, has its own `shape' A natural model in such a situation is to
Each neuron generates a continuous-time voltage trace, and  the outputs of all neurons are superimposed and discretely sampled to produce
the recordings $\bX$.  At a high level, in \S \ref{sec:spike} we model the continuous-time output of each neuron as a
series of idealized Poisson events smoothed with appropriate kernels, while
\S \ref{sec:crm} uses the Gamma process to develop a nonparametric prior for an entire population.
\S \ref{sec:disc_time} then describes a discrete-time approximation based on the Bernoulli approximation to the Poisson process. For
conceptual clarity, we restrict ourselves to single channel recordings until \S \ref{sec:multi}, where we describe the complete model for multichannel data.
%, and apply this to the observed data.
%Each neuron has its own distribution over waveform shapes.
%
% We describe this in detail, starting first with a model for a single channel recording $\bx \equiv (x_1, \cdots, x_T)\T$.
% =======
%We start first with the model for the continuous-time output of a single neuron, $x(t)$.
%channel recording $\bx\T \equiv (x_1, \cdots, x_T)$.
% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f

%\vspace{-.1in}
\subsection{Modeling the continuous-time output of a single neuron} \label{sec:spike}
%\vspace{-.1in}
There is a rich literature characterizing the spiking activity of a single neuron \citep{gerst08} accounting in detail for factors like non-stationarity,
refractoriness and spike waveform. We however make a number of simplifying assumptions (some of which we later relax).
%, others we leave for future work).
%Figure \ref{fig:schematic} \jovo{@dec - is this fig gonna happen?} provides a schematic depiction of our generative process.
First, we model the spiking activity of each neuron as stationary and memoryless, so that its set of spike times are
distributed as a homogeneous Poisson process ($\PP$).  %{\color{red} justify?}
 We model the neurons themselves are heterogeneous, with the $i^{th}$ neuron having
an (unknown) firing rate $\lambda_i$.
% For the $i^{th}$ neuron, the $j^{th}$ spike time is denoted $\tau_{ij} \in \mc{T}_i$
Call the ordered set of spike times of the $i^{th}$ neuron $\mc{T}_i=(\tau_{i1}, \tau_{i2},\ldots)$; then the time between successive elements of $\mc{T}_i$ is
exponentially distributed with mean $1/\lambda_i$. We write this as
$ \mc{T}_i \sim \PP(\lambda_i)$.

The actual electrical output of a neuron is not binary; instead each spiking event is a smooth perturbation in voltage about a
resting state. This perturbation forms the shape of the spike, %and without any loss of generality, we set the resting state to zero.
%{(\color{red} figure? better biological description? comment on how we preprocess the data to get zero mean?)}.
with the spike shapes varying across neurons as well as across different spikes of the same neuron. However, each
neuron has its own characteristic distribution over shapes, and we let $\bth^*_i \in \Theta$ parametrize this distribution for neuron $i$.
 % having parameter $\bth^*_i$.
Whenever this neuron emits a
spike, a new shape is drawn independently from the corresponding distribution. %$p_{\bth_i}$, and
This waveform is then offset to the time of the spike, and contributes to the voltage trace associated with that spike.

The complete recording from
the neuron is the superposition of all these spike waveforms plus noise.
Rather that treating the noise as white as is common in the literature \citep{Lewicki}, we allow it to exhibit temporal correlation,
recognizing that the `noise' is in actual fact background neural activity.
We model it as a realization of a Gaussian process (GP) \citep{RasWil2006}, with the covariance kernel $\mathcal{K}$ of the GP determining
the temporal structure. We use an exponential kernel, modeling the noise as Markov.  %start by assuming the noise at each observation time is i.i.d.\ Gaussian.

% Comment on how this dictionary is obtained now, or in section on inference?)}.
We model each spike shape as weighted superpositions of a dictionary of $K$ basis functions
$\mathsf{\bd}(t) \equiv (\mathsf{d}_1(t), \cdots, \mathsf{d}_K(t))\T$. The
dictionary elements are shared across all neurons, and each is a real-valued function of time, i.e., $\mathsf{d}_k \in L_2$.
% For the $i^{th}$ neuron, the $j^{th}$ spike time $\tau_{ij} \in \mc{T}_i$,
Each spike time $\tau_{ij}$ is associated with a random $K$-dimensional weight vector $\tby_{ij} \equiv (\ty_{ij1}, \ldots \ty_{ijK})\T$, and the
shape of this spike at time $t$ is given by the weighted sum $\sum_{k=1}^K \ty_{ijk} \mathsf{d}_k(t-\tau_{ij})$. We assume $\tby_{ij} \sim \mathsf{N}_K(\mb{\mu}^*_i, \Sigma^*_i)$, indicating a $K$-dimensional
Gaussian distribution with mean and covariance given by $(\mb{\mu}^*_i, \Sigma^*_i)$; we let $ \theta^*_i \equiv (\mb{\mu}^*_i, \Sigma^*_i) $.   Then, at any time $t$, the output of neuron $i$ is
$
  x_{i}(t) = \sum_{j=1}^{|\mc{T}_i|} \sum_{k=1}^K \ty_{ijk} \mathsf{d}_k(t - \tau_{ij}).
$

%
%
%
% \begin{center}
% \begin{figure}
% % \includegraphics[width=\textwidth]{../figs/truefalsepositive}
% \caption{Schematic of our Generative Model.}
% \label{fig:schmetic}
% \end{figure}
% \end{center}
%
{The total signal received by any electrode  is the superposition of the outputs of all neurons. Assume for the moment there are $N$
neurons, and define $\mc{T} \equiv \cup_{i \in [N]} \mc{T}_i$ as
the (ordered) union of the spike times of all neurons.
Let $\tau_l \in \mc{T}$ indicate the time of the $l^{th}$ overall spike, whereas $\tau_{ij} \in \mc{T}_i$ is the time of the $j^{th}$ spike of neuron $i$.
%To map elements  $\tau_{ij} \in \mc{T}_i$ to elements  $\tau_l \in \mc{T}$,
This defines a pair of mappings: $\nu:[|\mc{T}|]\rightarrow [N]$, and $p:[|\mc{T}|]\rightarrow \mc{T}_{\nu_i}$, with %$(i = \nu(l))$, , which maps from the $j^{th}$ spikes of neuron $i$ to the $l^{th}$ overall spike.
$\tau_l = \tau_{\nu_l p_l}$.
%\jovo{i don't think the square brackets around $\mc{T}$ are correct, we are mapping from the set of spikes, not the number of spikes, right?}
In words, $\nu_l \in N$ is the neuron to which the $l^{th}$ element of $\mc{T}$ belongs,
while $p_l$ indexes this spike in the spike train $\mc{T}_{\nu_l}$.
%\jovo{``position'' is weird to me.  can we say: ``indexes which spike of neuron $\nu_l$'', or something like that?}.
Let $\bth_l \equiv (\mb{\mu}_l, \Sigma_l)$ be the neuron parameter associated with spike $l$, so that $\bth_l = \bth^*_{\nu_l}$.
Finally, define $\by_l \equiv (y_{l1}, \ldots, y_{lK})\T \equiv \tby_{\nu_j p_j}$ as the weight vector of spike $\tau_l$. Then, we have that}
% \begin{subequations}
\begin{align}
  x(t) &= \sum_{i \in [N]} x_{i}(t) =   \sum_{l \in |\mc{T}|} \sum_{k \in [K]} y_{lk} \mathsf{d}_k(t - \tau_{l}), \qquad %\label{eq:spk_sup} \\
% \intertext{where}
  \text{ where } \by_{l}  \sim \mathsf{N}_K(\mb{\mu}_{l}, \Sigma_{l}). \label{eq:spk}
\end{align}
% \end{subequations}
%
From the superposition property of the Poisson process \citep{kingman93}, the overall spiking activity $\mc{T}$ is
Poisson with rate $\Lambda = \sum_{i \in [N]} \lambda_i$. Each event $\tau_l \in \mc{T}$ has a pair of labels, its neuron parameter
$\bth_l \equiv (\mb{\mu}_l, \Sigma_l)$, and $\by_l$, the weight-vector characterizing the spike shape. We view these weight-vectors as the ``marks'' of a
marked Poisson process $\mc{T}$.  From the properties of the Poisson process, we have that the marks $\bth_l$ are drawn i.i.d. from a probability measure
$\  \mathsf{G}(\dd \bth) = 1/\Lambda\sum_{i \in [N]} \lambda_i \delta_{\bth^*_i}$.

With probability one, the neurons have distinct parameters, so that the mark $\bth_l$ identifies the neuron which produced spike $l$: $\mathsf{G}(\bth_l = \bth^*_i) = \mathsf{P}(\nu_l= i) = \lambda_i/$$\Lambda$. Given $\bth_l$, $\by_l$ is distributed as in
Eq.~\eqref{eq:spk}. The output waveform $x(t)$ is then a linear functional of this marked Poisson process. % (Eq.~\eqref{eq:spk_sup}).

%\vspace{-.1in}
\subsection{A nonparametric model of population activity}  \label{sec:crm}
%\vspace{-.1in}

%The previous section assumed a known number of neurons $N$;
In practice, the number of neurons driving the recorded activity is unknown. We do not wish to bound this number \emph{a priori},
moreover we expect this number to increase as we
record over longer intervals. This suggests a nonparametric Bayesian approach: allow the \emph{total}
number of underlying neurons to be infinite.
Over any finite interval, only a finite subset of these will be \emph{active}, and typically, these dominate spiking activity over any interval.
This elegant and flexible modeling approach allows the data to suggest how many neurons are active, and has already proved
successful in neuroscience applications \citep{WoodBla2008}.
%where we allow the number of neurons to be infinite.
%this leads to
%While the number of neurons observed over any finite observation interval is finite, this number increases with the observation interval.
%This makes sense in a biological context, in that as we record for longer (e.g., days, weeks, or months even), certain neurons will die or drop-out, and others will appear, simply by virtue of the electrodes moving, for example.
 %, moreover the total rate $\Lambda$ of all neurons must also be finite.
%the total rate $\Lambda$ must
%also be finite. Moreover, we want this to be dominated by a few $\lambda_i$: the corresponding neurons contribute the majority of the spiking
%activity in the observation interval.
% A natural framework that captures our  modeling requirements is that of \emph{completely random measures} (CRMs) \citep{Kingman:PJM67}.
% CRMs are stochastic processes that form flexible and convenient priors over
% infinite dimensional objects like probability distributions \citep{JamesLP09}, hazard functions \citep{Hjo1990}, latent features \citep{ThiJor2007}.
% These have been well studied in the Bayesian nonparametrics and machine learning communities, and there is a wealth of literature on
% theoretical properties, as well as posterior computation.
%
% Recall that each neuron is characterized by a pair of parameters $(\lambda_i, \bth^*_i)$; characterizing the distribution over spike times
% and shapes respectively. With Eq.~\eqref{eq:mark_distr} in mind, we map the infinite collection of pairs $\{(\lambda_i, \bth^*_i)\}$ to an atomic measure on $\Theta$:
% $\quad \mathsf{\Lambda}(\dd \bth) = \sum_{i=1}^{\infty} \lambda_i \delta_{\bth^*_i}$.
%
% =======
We use the framework of \emph{completely random measures} (CRMs) \citep{Kingman:PJM67} to model our data.
%CRMs are stochastic processes that form flexible and convenient priors over
%infinite dimensional objects like probability distributions \citep{JamesLP09}, hazard functions \citep{Hjo1990}, latent features \citep{ThiJor2007}.
CRMs have been well studied in the Bayesian nonparametrics community, and there is a wealth of literature on
theoretical properties, as well as posterior computation; see e.g.\ \citep{JamesLP09, Hjo1990, ThiJor2007}.
%Recall that each neuron is characterized by a pair of parameters $(\lambda_i, \bth^*_i)$; characterizing the distribution over spike times
%and shapes respectively.
Recalling that each neuron is characterized by a pair of parameters $(\lambda_i, \bth^*_i)$, %and with the measure $\mathsf{G}(\dd \bth)$ in mind,
we map the infinite collection of pairs $\{(\lambda_i, \bth^*_i)\}$ to an random measure $\Lambda(\cdot)$ on $\Theta$:
$\ \  \Lambda(\dd \bth) = \sum_{i=1}^{\infty} \lambda_i \delta_{\bth^*_i}$.

For a CRM, the distribution over measures is induced by distributions
over the infinite sequence of weights, and the infinite sequence of their locations.
The weights $\lambda_i$ are the jumps of a \Levy process \citep{Sato90}, and their distribution is characterized by a
\Levy measure $\rho(\lambda)$. The locations $\bth^*_i$ are drawn i.i.d.\  from a base probability measure $\mathsf{H}(\bth^*)$.
As is typical, we assume these to be independent. % (though this is not necessary).
%{\color{green} if there's space, I
%can elaborate on the construction of the CRM from its Levy measure, though this is not necessary}

We set the \Levy measure $\rho(\lambda) = \alpha \lambda^{-1}\exp(-\lambda)$,
resulting in a CRM called the Gamma process ($\Gamma$P) \citep{applebaum2004}.
The Gamma process has the convenient property that the
total rate $\Lambda \equiv {\Lambda}(\Theta) = \sum_{i=1}^{\infty} \lambda_i$ is Gamma distributed (and thus conjugate to the Poisson process prior on $\mc{T}$).
%\footnote{We abuse notation by using $\Lambda$ to denote both the measure as well as the total measure of $\Theta}
%The Gamma distribution has shape parameter $1$ and scale parameter $\alpha$.  Since this is finite almost surely, so too is $\mc{T}$.
The Gamma process is also closely connected with the Dirichlet process \citep{Ferguson73}, which will prove useful
later on.
% <<<<<<< HEAD
% Other choices of the \Levy intensity can be used to capture greater uncertainty in the number of neurons active in any finite interval, or to model
% power-law behavior in the number of spikes emitted by different neurons.
% %
% =======
%Other \Levy measures can be used to capture greater uncertainty in the number of neurons active in any finite interval, or to model
%power-law behavior in the number of spikes emitted by different neurons.
% >>>>>>> 7fea96c6e4a0bbe1b00f773309ab4c7a16108433
% To complete the specification on the Gamma process, we choose a base-measure $\mathsf{H}(\bth^*)$.
% %Recalling that $\bth^* \equiv (\mu^*, \Sigma^*)$ gives the mean and variance of the weight-vector $\by^*$ of a neuron,
% We set $\mathsf{H}(\bth^*)$
% to the conjugate normal-Wishart distribution with parameters $\phi$.
% =======
To complete the specification on the Gamma process, %we choose a base-measure $\mathsf{H}(\bth^*)$.
%Recalling that $\bth^* \equiv (\mu^*, \Sigma^*)$ gives the mean and variance of the weight-vector $\by^*$ of a neuron,
we set $\mathsf{H}_{\phi}(\bth^*)$
to the conjugate normal-Wishart distribution with hyperparameters $\phi$.
% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f
%Our overall model is then:
%\begin{subequations}
%\begin{align}
%  \mc{T}_i\ \  &\sim \mathsf{PP}(\lambda_i) \quad i \in \NN, \quad &\text{ where } \mathsf{\Lambda}(\cdot)&=\sum_{i=1}^{\infty} \lambda_i \delta_{\theta^*_i} \sim \Gamma \text{P}(\alpha, \mathsf{H}(\cdot| {\phi})), \\ %\mathcal{NW}(\mu, \Sigma)) \\ \\
%\vspace{-.8in}
%  x_i(t) &= \sum_{j = 1}^{|\mc{T}_i|}  \sum_{k = 1}^{K} y^*_{ijk} \mathsf{d}_k(t - \tau_{ij}), \quad &\text{ where }\by^*_{ij}  &\sim \mathsf{N}_K(\mb{\mu}^*_i, \Sigma^*_i) \quad i,j \in \NN, \\
%  x(t)   &= \sum_{i=1}^{\infty} x_i(t) + \eps_t, \quad &\text{ where at any time $t$, } \eps_t &\sim \mathsf{N}(0,\Sigma_x) \text{ independently}
%\end{align}
%\end{subequations}

%Each spike of each neuron is associated with a time $e$ and a weight vector $y$, and one can view the model above as a doubly stochastic Poisson
%process on the product space.
%
%\jovo{perhaps it is standard, but you sample $\Lambda$ and then the next line you have $\lambda_i$, but no explanation for how you from $\Lambda$ to $\lambda_i$. i also am confused as to why $\phi$ is a subscript on $H$, rather than in the $(\cdot)$}
%Atom $i$ of the CRM corresponds to a neuron with parameters $(\lambda_i, \theta^*_i)$.
It is easy to directly specify the resulting continuous-time model, we provide the equations in the Supplementary Material.
However it is more convenient to represent the model using the marked Poisson process of Eq.~\eqref{eq:spk}. % and \eqref{eq:spk_shape}.
There, the overall process $\mc{T}$ is a rate $\Lambda$ Poisson process,
and under a Gamma process prior, $\Lambda$ is Gamma$(\alpha,1)$ distributed %with shape and scale parameters $\alpha$ and $1$ respectively
\citep{Ferguson73}.
The labels $\bth_i$ assigning events to neurons are drawn i.i.d. from a normalized Gamma
process: % $\mathsf{G}(\dd \bth)$:
%\vspace{-.2in}
%\begin{align}
$ \mathsf{G}(\dd \bth) = \left(1/\Lambda\right) \sum_{l=1}^{\infty} \lambda_l$.
%\end{align}

$\mathsf{G}(\dd \bth)$ is a random probability measure (RPM) called a \emph{normalized random measure} \citep{JamesLP09}. Crucially, a
normalized Gamma process is the Dirichlet process (DP) \citep{Ferguson73}, so that
the spike parameters $\bth$ are i.i.d.\ draws with a DP-distributed RPM.
For spike $l$, the shape vector is drawn from a normal
with parameters $(\mb{\mu}_{l}, \Sigma_{l})$: these are thus
draws from a DP mixture (DPM) of Gaussians \citep{Lo1984}.

% <<<<<<< HEAD
% The connection with the DP allows us to simplify the representation of our model. In particular, we exploit a remarkable property of the DP that
% allows us to integrate out the infinite-dimensional variable $\mathsf{G}(\cdot)$. The resulting marginal distribution over observations follows the so-called
%  Chinese restaurant process ($\mathsf{CRP}$) \citep{Pit2002a}. Under this scheme, the $l^{th}$ spike is assigned the same parameter as an earlier spike with probability
% =======
%The connection with the DP allows us to simplify the representation of our model. In particular,
We can exploit the connection with the DP to %a remarkable property of the DP that allows us to
integrate out the infinite-dimensional measure $\mathsf{G}(\cdot)$ (and thus ${\Lambda}(\cdot)$), and assign spikes to neurons via
%. The resulting marginal distribution over observations follows
the so-called Chinese restaurant process (CRP) \citep{Pit2002a}. Under this scheme, the $l^{th}$ spike is assigned the same parameter as an earlier spike with probability
% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f
proportional to the number of earlier spikes having that parameter. It is assigned a new parameter (and thus, a new neuron is observed) with probability
proportional to $\alpha$. Letting $C_t$ be the number of neurons observed until time $t$, and  $\mc{T}^t_i = \mc{T}_i \cap [0,t)$ be the times of spikes
produced by neuron $i$ before time $t$,
we then have for spike $l$ at time $t = \tau_l$:
\vspace{-.07in}
\begin{align}
% <<<<<<< HEAD
%   \mathsf{P}({\nu_l} = i) & \propto
% =======
 \bth_l = \bth^*_{\nu_l} \text{, where }
  P({\nu_l} = i) & \propto
% >>>>>>> 7fea96c6e4a0bbe1b00f773309ab4c7a16108433
  \begin{cases}
   |\mc{T}^t_i| \quad i \in [C_{t}], \\
   \alpha \quad\ i = C_{t} + 1,
  \end{cases}
\label{eq:crp_marg_pr}
\end{align}
%\footnote{Strictly speaking, the process we just described is called a P\'olya urn scheme \citep{BlaMac1973}; for simplicity, we do not distinguish between this and the \mathsf{CRP}.}.
This marginalization property of the DP allows us to integrate out the infinite-dimensional rate vector ${\Lambda}(\cdot)$, and sequentially
assign spikes to neurons based on the assignments of earlier spikes.
%is assigned (or equivalently, the parameter $\bth$ associated with that neuron). These marks are drawn from a probability measure
%$\mathsf{G}(\dd \bth) = \frac{1}{R} R(\dd \bth)$. From the properties of the Gamma process, the probability measure $G$ a Dirichlet process,
This requires one last property: for the Gamma process, the RPM $\mathsf{G}(\cdot)$ is independent of the total mass $\Lambda$.
Consequently, the clustering of spikes (determined by $\mathsf{G}(\cdot)$) is independent of the rate $\Lambda$ at which they are produced. We then have
 the following model:
\vspace{-.04in}
\begin{subequations}
\begin{align}
  \mc{T} &\sim \PP(\Lambda), \qquad &\text{ where } \Lambda  &\sim \mathsf{\Gamma P}(\alpha, 1),
   \\
  \by_l &\sim \mathsf{N}_K(\mb{\mu}_{l}, \Sigma_{l}), \qquad &\text{ where } (\mb{\mu}_{l}, \Sigma_{l})  &\sim {\mathsf{CRP}}(\alpha, \mathsf{H}_{\phi}(\cdot)), \quad  l \in [|\mc{T}|],   \label{eq:CRP}\\
   % (\mb{\mu}_{l}, \Sigma_{l}) &\equiv \bth_l,  &\text{ where } \bth_l &\sim \text{\mathsf{CRP}}(\alpha, \mathsf{H}_{\phi}(\cdot)), \quad l \in [|\mc{T}|],   \label{eq:\mathsf{CRP}}\\
  x(t) &=   \textstyle{\sum_{l \in |\mc{T}|}} \sum_{k \in [K]} y_{lk} \mathsf{d}_k(t - \tau_{l}) + \eps_t  &\text{ where }  \eps &\sim \text{GP}(0,\mathcal{K}).  \label{eq:CRP_mix}  %\,  l \in [|\mc{T}|].
\end{align} \label{eq:marked_pp}
\end{subequations}
% Unlike most applications which observe the outputs of a $\mathsf{CRP}$, our observation at any time $t$ is a convolution-like function of the $\mathsf{CRP}$ outputs of all
% earlier times. Consequently, we cannot directly apply standard techniques for posterior inference. In \S \ref{sec:inf}, we develop a novel online
% algorithm for posterior inference; first, we provide a discrete-time approximation to our model.
% =======
%Unlike most applications which observe the outputs of a CRP, our observation at any time $t$ is a convolution-like function of the CRP outputs of all
%earlier times. Consequently, we cannot directly apply standard techniques for posterior inference. In \S \ref{sec:inf}, we develop a novel online
%algorithm for posterior inference; first, we provide a discrete-time approximation to our model.
% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f

%For neuron $i$, the sequence of spike times is distributed as a Poisson process with random rate $\lambda_i$.
%Each event $\tau_{ij}$ is associated with a mark or label $y_{ij}$ drawn from a normal distribution (again, with random parameters).
%More broadly, we can view the superposed process $\mc{T}$ as a rate $\Lambda$ Poisson process, with each event having a pair of marks, the neuron identity $i$,
%and weight $y$. From the properties of the Gamma process, the pair form a draw from a Dirichlet process.
%Our data is in a form that makes discrete-time modeling more natural, and an approach now is
%one based on the Beta process-binomial process.

%\vspace{-.1in}
% =======
\vspace{-.1in}
% >>>>>>> ff0f5b20cd09ef2d570aa2ed8ea5c6d04356249f
\subsection{A discrete-time approximation}  \label{sec:disc_time}
% \vspace{-.1in}
The previous subsections modeled the continuous-time voltage output of a neural population. Our data on the other hand consists of recordings
at a discrete set of times. While it is possible to make inferences about the continuous-time process underlying these discrete recordings,
in this paper, %for simplicity,
we restrict ourselves to the discrete case. %We thus provide a discrete-time approximation to the model above.
The marked Poisson process characterization of Eq.\ \ref{eq:marked_pp} leads to a simple
discrete-time approximation of our model.

Recall first the Bernoulli approximation to the Poisson process: a sample from a Poisson process with rate $\Lambda$ can be approximated by discretizing
time at a granularity $\Delta$, and assigning each bin an event independently with probability $\Lambda\Delta$ (the accuracy of the approximation increasing
as $\Delta$ tends to $0$).
%
%This suggests the following approximation at a time resolution $\Delta$. Draw the random Poisson process rate $\Lambda$ drawn from a Gamma$(1,\alpha)$
%distribution. Simultaneously, draw a random probability measure
% $G$ from a Dirichlet process. Assign an event to an interval independently with probability $\Lambda\Delta$, and to each event, assign a random mark drawn
To approximate the \emph{marked} Poisson process $\mc{T}$, all that is additionally required is to assign marks $\bth_i$ and $\by_i$ to each event
in the Bernoulli approximation. Following Eqs.~\eqref{eq:CRP} and \eqref{eq:CRP_mix}, the $\bth_l$'s are distributed according
to a Chinese restaurant process, while each $\by_l$ is drawn from a normal distribution parametrized by the corresponding $\bth_l$. We discretize the
elements of dictionary %$\mathsf{d}_k \equiv \{\mathsf{d}_k(t)\}_{t \in (0,T)}$
as well, %defining a mapping from $L_2$ to $\Real^L$
yielding discrete dictionary elements
$\mt{\bd}_{k,:}=(\mt{d}_{k,1}, \ldots, \mt{d}_{k,L})\T$. These form the rows of a ${K \times L}$ matrix $\mt{\bD}$ (we call its columns
$\mt{\bd}_{:,h}$). The shape of the $j^{th}$ spike is now a vector of length $L$, and for a weight vector
$\by$, is given by $\mt{\bD} \by$.

We can simplify notation a little for the discrete-time model.
Let $t$ index time-bins (so that for an observation interval of length
$T$, $t \in [T/\Delta]$). We use twiddles for variables indexed by bin-position.
Thus, $\mt{\nu}_t$ and $\mt{\theta}_t$ are the neuron and neuron parameter associate with time bin $t$, and $\mt{\by}_t$ is its weight-vector.
Let the binary variable $\mt{z}_t$ indicate whether or not a spike in present in time bin $t$ (recall that
$\mt{z}_t \sim \text{Bernoulli}(\Lambda \Delta)$).
If there is no spike associated with bin $t$, then we ignore the marks $\mt{\mu}$ and $\mt{\by}$.
Thus the output at time $t$, $x_t$ is given by
%\begin{align}
$\ x_t = \sum_{h = 1}^L \mt{z}_{t-h} \mathsf{\bd}_{:,h}^{\T} \mt{\by}_{t-h-1} + \eps_t$. % \text{,\quad where $\eps_t \iid \mathsf{N}(0,\sigma^2)$.}$
Note that the noise $\eps_t$ is now a discrete-time Markov Gaussian process. %In all experiments, we assume this evolves via a discrete-time first order
Let $a$ and $r_t$ be the decay and innovation of the resulting autoregressive (AR) process, so that $\eps_{t+1} = a \eps_t + r_t$.
%\end{align}
% \vspace{-.1in}
\subsection{Correlations in time and across electrodes}  \label{sec:multi}
% \vspace{-.1in}
So far, for simplicity, we restricted our model to recordings from a single channel. We now describe the full model we use in experiments with
multichannel recordings. We let every spike affect the recordings at all channels, with the spike shape varying across channels.
For spike $l$ in channel $m$, call the weight-vector $\by^m_l$. All these vectors must be correlated as they correspond to the same spike; we do this
simply by concatenating the set of vectors into
a single $MK$-element vector $\by_l = (\by^1_l;\cdots;\by^M_l)$, and modeling this as a multivariate normal. In principle, one might expect the associated
covariance matrix to possess a block structure (corresponding to subvector associated with each channel); however, rather than building this into the model,
we allow the data to inform us about any such structure.

We also relax the requirement that the parameters $\bth^*$ of each neuron remain constant, and instead allow $\mb{\mu}^*$, the mean of the weight-vector
distribution, to evolve with time (we keep the covariance parameter $\mb{\Sigma}^*_i$ fixed, however).
Such flexibility can capture effects like changing cell characteristics or moving electrodes.
Like the noise term, we model the time-evolution of this quantity as a realization of a Markov Gaussian process; again, in
%A consequence is that the
%means remain marginally Gaussian distributed at any time, on the other hand correlation between means across time is determined by the choice
%of the GP covariance kernel.
%We choose a stationary Markov kernel (where covariance decays exponentially with time); in
discrete-time, this corresponds to a simple first-order
AR process. With $\mb{B} \in \mathbb{R}^{K \times K}$ the transition matrix, and $\mb{r}_t \in \mathbb{R}^K$,
independent Gaussian {innovations}, we have
  $\mb{\mu}^*_{t+1} = \mathbf{B} \mb{\mu}^*_t + \mathbf{r}_t$.
%The first is the inclusion of measurement noise: {\color{red} Biology?}. Let $\eps_t$ be the noise at time $t$, we model this as independent, additive and Gaussian.
%However, rather than modeling the noise as independent across time, we model it as a first-order autoregressive process. This can capture
%effects like the movement of electrodes during the experiment.
%
% \begin{align}
% \end{align}
Where we previously had a DP mixture of Gaussians, we now have a DP mixture of GPs. Each neuron is now associated with a vector-valued function
$\bth^*(\cdot)$, rather than a constant. When a spike at time $\tau_l$ is assigned to neuron $i$, it is assigned a weight-vector $\by_l$ drawn from a
Gaussian with mean $\mb{\mu}^*_i(\tau_l)$. %Following \citep{wood2009}, a useful extension is to also allow the neuron assignment probabilities to evolve
%(corresponding to a time-varying Gamma process \citep{RaoTeh2009a}); we leave this for future work.
Algorithm \ref{alg:gen_proc} in the Supplementary Material summarizes the full generative mechanism for the full discrete-time model.
% <<<<<<< HEAD
% Our second extension is to generalize our model from a single electrode to the case of multielectrode recordings.
% We allow the shape of any spike to vary across channels: for spike $l$ in channel $m$, call the weight-vector $\by^m_l$.
% Of course, all these vectors need to be correlated as they correspond to the same spike. We do this simply by concatenating the set of vectors into
% a single $MK$-element vector $\by_l = (\by^1_l;\cdots;\by^M_l)$, and modeling this as a multivariate normal. In principle, one might expect the associated
% covariance matrix to possess a block structure (corresponding to subvector associated with each channel); however, rather than building this into the model,
% we allow the data to inform us about any such structure.
% Algorithm \ref{alg:gen_proc} in the supplementary material outlines generative mechanism of the data for the discrete-time model.
%
% \jovo{what's a semicolon in a sequence?}
% =======
% >>>>>>> 7fea96c6e4a0bbe1b00f773309ab4c7a16108433


\chapter{{\tt GPart}: Graph Partitioning Object}
\label{chapter:GPart:intro}
\par
The {\tt GPart} object is used to create a partition of a graph.
We use an explicit vertex separator to split a graph (or a
subgraph) into the separator and two or more connected components.
This process proceeds recursively until the subgraphs are too small
to split (given by some user-supplied parameter).
\par
At present, there is one path for splitting a graph (or a subgraph).
\begin{itemize}
\item
Find a {\it domain decomposition} of the graph.
The graph's vertices $V$ are partitioned into {\it domains},
$\Omega_1, \ldots, \Omega_m$, each a connected component,
and the interface vertices $\Phi$.
The boundary of a domain $\Omega_i$ (those vertices not in the domain
but adjacent to a vertex in the domain), written
$\mbox{adj}(\Omega_i)$, are a subset of $\Phi$, the interface
vertices.
We use the term {\it multisector} for $\Phi$, for it generalizes
the notion of bisector.
\par
We currently find the domain decomposition by growing domains from
random seed vertices.
Upper and lower bounds are placed on the weights of the domains.
\item
Given a domain decomposition of the graph $\langle \Phi, \Omega_1,
\ldots, \Omega_m \rangle$, we find a {\it 2-set partition}
$[S, B, W]$ of the vertices, where $S \subseteq \Phi$,
$\mbox{Adj}(B) \subseteq S$ and $\mbox{Adj}(W) \subseteq S$.
Note, it may be the case that $B$ and/or $W$ are not connected
components.
\par
We currently find a 2-set partition by forming a {\it
domain-segment} bipartite graph where the segments partition the
interface nodes $\Phi$.
We use a block Kernighan-Lin method to find an edge separator of
this domain-segment graph.
Since the ``edges'' are segments, an edge separator of the
domain-segment graph is truly a vertex separator of the original
graph.
\item
Given a 2-set decomposition $[S,B,W]$ of the graph, we improve
the partition by {\it smoothing} $S$.
The goal is to decrease the size of $S$, or improve the balance
of the two sets (minimize $\left| |B| - |W| \right |$, or both.
Our present approach is to generate a {\it wide separator} $Y$
where $S \subseteq Y$ and try to find a separator
$\widehat S \subseteq Y$ that induces a better partition
$[{\widehat S}, {\widehat B}, {\widehat W}]$.
\par
To do this, we form a network and solve a max flow problem.
The nodes in $B \setminus Y$ are condensed into the {\it source}
while the nodes in $W \setminus Y$ are condensed into the {\it sink}.
The rest of the network is formed using the structure of the
subgraph induced by $Y$.
Given a {\it min-cut} of the network we can identify a separator
${\widehat S} \subseteq Y$ that has minimal weight.
We examine two (possibly) different min-cuts and evaluate the
partitions induced via their minimal weight separators, and accept
a better partition if present.
\end{itemize}
This process we call {\tt DDSEP}, which is short for {\it {\tt D}omain
{\tt D}ecomposition {\tt SEP}arator},
explained in more detail in
\cite{ash97-DDSEP} and
\cite{ash98-maxflow}.
\par


\section{$k$-Nearest-Neighbors Algorithm}
\label{sec:TheoryKnn}
The $k$-Nearest-Neighbors ($k$-NN) algorithm performs a distribution free classification task. It uses a lazy learning approach which means that all the training data is saved. The Algorithm searches that data base for the $k$ closest data points to the point to classify. The distance measurement depends on the application. The class which is most often found in those $k$ nearest neighbors is the one the sample is classified as \cite[p.~338~f.]{bib:Alzate2007}.\\
The space of the data points is the PCA-reduced feature space described in section~\ref{sec:Features}. The distance used in our project is the DTW-distance described in section~\ref{sec:Distance}. The feature space version of a test sample is calculated and compared to all other feature vectors in the database from section~\ref{sec:Features}. This comparison table is then sorted by distance using the sorting algorithm built into Python. As output of the $k$-NN classification, the ratio of found neighbors to the total number of neighbors is given for the $k$ nearest neighbors. This can be interpreted as the probability of a point belonging to a class.