%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Theoretical Background}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Transformers}

Vaswani et al\cite{vaswani2017attention} described transformers as sequence
models that solely focus on self-attention without the need for recurrence which
eliminates the need for unfolding during the backpropagation phase of learning.
In the paper, attention was defined with respect to keys, values, and queries.
The attention is computed with

\[
    attention(K,Q,V) = \left(\frac{QK^T}{\sqrt{dim(K)}}\right)V
\]

where K is the key matrix, Q is the query matrix, and V is the value matrix.
The dot product of Q and K is scaled by the square root of the dimension of K.

Transformer models take the whole input as a whole instead of recurrently meaning
that the model does not know the order of the words in the sequence. Hence, the
paper proposed the use of positional encodings through sinusoidal functions
added to the embedded vectors. Suppose that W is a matrix where each column
corresponds to a position pos and each row i corresponds to the individual
dimensions in the model which alters the frequency. Let
\begin{math}
    W=10000^2i/embedsize
\end{math}
where embedsize is a hyperparameter which is also the embedding size of the
embedded vectors. Then, the positional encoding is calculated by
\[
    POS(pos,i) = \sin\left(\frac{pos}{W}\right) \text{if \textit{i} is even and}
\]
\[
    POS(pos,i) = \cos\left(\frac{pos}{W}\right) \text{if \textit{i} is odd}
\]
The key component of transformers is the multi-headed attention layer, wherein
attention is computed multiple times and concatenated together. Transformers
were able to outperform established models for machine translation with
English-German translation.

\section{RoBERTa for Classification}
RoBERTa\cite{liu2019roberta} is a replication study of the original BERT
model by finer-tuning hyperparameters and removing the Next Sentence
Prediction task which was shown that it does not negatively affect the
performance of the model. While the original transformer by Vaswani et al.\
is a Seq2Seq transformer, RoBERTa is an autoencoder transformer trained on a
large corpus, which can be used with fine-tuning or transfer learning for
different downstream tasks such as classification\cite{pritzkau2021nlytics}.

In this paper, the researchers will use the CodeBERT\cite{feng2020codebert}
to be used with transfer learning on algorithm classification. The CodeBERT
model is a variant of RoBERTa pretrained on multiple programming languages
including Java, Python, and Javascript.

\subsection{Model Architecture}

The CodeBERT model is a bidirectional transformer using a similar architecture
with RoBERTa without any architectural modification.

\subsection{Dataset}

CodeBERT was trained on a large corpus of about 8million codes of both bimodal
and unimodal data. Bimodal data means that for each code snippet,
there is an accompanying natural language snippet while unimodal data
implies the absence of the natural language snippet. The data were gathered from
GitHub, which was collected by Husain et al\cite{husain2020codesearchnet}.

\section{Task-Constraint Feedback}

Knowledge About Task-Constraints (KTC) feedback systems employ the use of limiting
the submission by adding requirements, called \textit{constraints}, that will tell the
student if they haven’t completed the requirement.\cite{keuning2016towards} One of the methods used
is \textit{Hints on Task Requirements} (TR) wherein a hint will be given when a task was
not completed. As an example, suppose that the problem setter asked to balance a
binary search tree using red-black trees. However, the submitter was able to
complete the problem using an AVL tree. The TR system should give some feedback
that the Red-Black Tree is a requirement for the given problem.

\section{Algorithm Classification}
Algorithms and data structure can be written multiple ways with different stylistic
and data structure choices. The researchers define algorithm classification as to
what algorithm some code snippet is implementing, rather than the class such as
sorting, searching, etc. Introductory algorithm textbooks\cite{velivckovic2021clrs}\cite{skiena2020algorithm}\cite{sedgewick2011algorithms}
have a good resource on the algorithm names through its table of contents which will
be used as labels in the classifier. With this, this research defines algorithm
classification by tagging code snippets as to the question “what is the algorithm
name that this code snippet is implementing?”

In computer science education, students might use multiple algorithms into one file
and begin using different data structures for their implementations. As an example,
consider the task of implementing a \textit{priority queue} (the \textit{priority queue} is a classification).
The priority queue data structure can be implemented with \textit{binary heaps} or dictionaries
such as \textit{linked lists} and \textit{binary search trees}; in this example, assume that the priority
queue is implemented with a \textit{binary heap}. Introductory programming students might usually
be coding these algorithms and algorithms manually into one file and it is not enough to
say that the submission implements a \textit{priority queue} since a \textit{binary heap} is also implemented.

Suppose that the code snippet implements an algorithm and uses some data structure or
another algorithm using the language’s standard library, then the snippet will only be
classified using the manual implementation disregarding the standard library function.
Likewise, code snippets that do not belong to any algorithms stated in any of the
introductory algorithm textbooks are said not to use any algorithm. These code snippets
usually contain the \textit{main} function (but not always), setter and getter functions,
and boilerplate codes.


\chapter{central force motion solutions}
\begin{abox}
	Practice set 1 solutions
	\end{abox}
\begin{enumerate}
		\item The acceleration due to gravity $(g)$ on the surface of Earth is approximately $2.6$ times that on the surface of Mars. Given that the radius of Mars is about one half the radius of Earth, the ratio of the escape velocity on Earth to that on Mars is approximately
		{\exyear{NET JUNE 2011}}
	\begin{tasks}(2)
		\task[\textbf{A.}] $1.1$
		\task[\textbf{B.}]$1.3$
		\task[\textbf{C.}]$2.3$
		\task[\textbf{D.}]$5.2$
	\end{tasks}
\begin{answer}
\begin{align*}
	\text { Escape velocity }&=\sqrt{2 g R}\\
\frac{\text { Escape velocity of Earth }}{\text { Escape velocity of Mass }}&=\sqrt{\frac{g_{e} R_{e}}{g_{m} R_{m}}}=2.3 \quad \text { where } \frac{R_{e}}{R_{m}}=2 \text { and } \frac{g_{e}}{g_{m}}=2.6
\end{align*}
	THe correct option is \textbf{(c)}
\end{answer}
	\item Two particles of identical mass move in circular orbits under a central potential $V(r)=\frac{1}{2} k r^{2}$. Let $l_{1}$ and $l_{2}$ be the angular momenta and $r_{1}, r_{2}$ be the radii of the orbits respectively. If $\frac{l_{1}}{l_{2}}=2$, the value of $\frac{r_{1}}{r_{2}}$ is:
	{\exyear{NET DEC 2011}}
\begin{tasks}(2)
	\task[\textbf{A.}] $\sqrt{2}$
	\task[\textbf{B.}]$1 / \sqrt{2}$
	\task[\textbf{C.}] 2
	\task[\textbf{D.}] $1 / 2$
\end{tasks}
\begin{answer}
	\begin{align*}
	 V_{e f f}&=\frac{l^{2}}{2 m r^{2}}+\frac{1}{2} k r^{2}, \text{where $l$ is angular momentum. }\\
	\intertext{Condition for circular orbit} \frac{\partial V_{e f f}}{\partial r}&=0 \Rightarrow-\frac{l^{2}}{m r^{3}}+k r=0 \Rightarrow l^{2} \propto r^{4} \Rightarrow l \propto r^{2}.\\
	Thus \frac{l_{1}}{l_{2}}&=\left(\frac{r_{1}}{r_{2}}\right)^{2} \Rightarrow \frac{r_{1}}{r_{2}}=\sqrt{\frac{l_{1}}{l_{2}}} \Rightarrow \frac{r_{1}}{r_{2}}=\sqrt{2}\\
	since \frac{l_{1}}{l_{2}}&=2
	\end{align*}
	The correct option is \textbf{(a)}
\end{answer}
	\item A planet of mass $m$ moves in the inverse square central force field of the Sun of mass $M$. If the semi-major and semi-minor axes of the orbit are $a$ and $b$, respectively, the total energy of the planet is:
	{\exyear{NET DEC 2011}}
\begin{tasks}(2)
	\task[\textbf{A.}] $-\frac{G M m}{a+b}$
	\task[\textbf{B.}]$-G M m\left(\frac{1}{a}+\frac{1}{b}\right)$
	\task[\textbf{C.}]$-\frac{G M m}{a}\left(\frac{1}{b}-\frac{1}{a}\right)$
	\task[\textbf{D.}]$-G M m\left(\frac{a-b}{(a+b)^{2}}\right)$
\end{tasks}
\begin{answer}
 Assume Sun is at the centre of elliptical orbit. Conservation of energy\\
  $$\frac{1}{2} m v_{1}^{2}-\frac{G M m}{a}=\frac{1}{2} m v_{2}^{2}-\frac{G M m}{b}$$ Conservation of momentum $L=m v_{1} a=m v_{2} b$\\
  \begin{figure}[H]
  	\centering
  	\includegraphics[height=3cm,width=5cm]{diagram-20210926(12)-crop}
  \end{figure}
 \begin{align*}
 	&v_{2}=v_{1}\left(\frac{a}{b}\right) \\
 	&\frac{1}{2} m v_{1}^{2}-\frac{1}{2} m v_{2}^{2}=\frac{G M m}{a}-\frac{G M m}{b} \Rightarrow \frac{1}{2} m\left(v_{1}^{2}-v_{1}^{2} \frac{a^{2}}{b^{2}}\right)=G M m\left(\frac{b-a}{a b}\right) \\
 	&\frac{1}{2} m v_{1}^{2}\left(\frac{b^{2}-a^{2}}{b^{2}}\right)=G M m\left(\frac{b-a}{a b}\right) \Rightarrow \frac{1}{2} m v_{1}^{2}=G M m\left(\frac{b}{a}\right) \cdot \frac{1}{(b+a)} \\
 	&E=\frac{1}{2} m v_{1}^{2}-\frac{G M m}{a}=G M m \frac{b}{a} \frac{1}{(b+a)}-\frac{G M m}{a} \\
 	&=\frac{G M m}{a}\left(\frac{b}{(b+a)}-1\right)=\frac{G M m}{a}\left(\frac{b-b-a}{(b+a)}\right)=-\frac{G M m}{(b+a)}
 \end{align*}
 The correct option is \textbf{(a)}
\end{answer}

	\item A planet of mass $m$ moves in the gravitational field of the Sun (mass $M$ ). If the semimajor and semi-minor axes of the orbit are $a$ and $b$ respectively, the angular momentum of the planet is
	{\exyear{NET DEC 2012}}

\begin{tasks}(2)
	\task[\textbf{A.}]$\sqrt{2 G M m^{2}(a+b)}$
	\task[\textbf{B.}]$\sqrt{2 G M m^{2}(a-b)}$
	\task[\textbf{C.}]$\sqrt{\frac{2 G M m^{2} a b}{a-b}}$
	\task[\textbf{D.}]$\sqrt{\frac{2 G M m^{2} a b}{a+b}}$
\end{tasks}
\begin{answer}
	 Assume Sun is at the centre of elliptical orbit.\\\\
	Conservation of energy $\frac{1}{2} m v_{1}^{2}-\frac{G M m}{a}=\frac{1}{2} m v_{2}^{2}-\frac{G M m}{b}$\\\\
	Conservation of momentum $L=m v_{1} a=m v_{2} b$
	$$
	v_{2}=v_{1}\left(\frac{a}{b}\right)
	$$
	\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(12)-crop}
	\end{figure}
	\begin{align*}
		&\frac{1}{2} m v_{1}^{2}-\frac{1}{2} m v_{2}^{2}=\frac{G M m}{a}-\frac{G M m}{b} \Rightarrow \frac{1}{2} m\left(v_{1}^{2}-v_{1}^{2} \frac{a^{2}}{b^{2}}\right)=G M m\left(\frac{b-a}{a b}\right) \\
		&\frac{1}{2} m v_{1}^{2}\left(\frac{b^{2}-a^{2}}{b^{2}}\right)=G M m\left(\frac{b-a}{a b}\right) \Rightarrow \frac{1}{2} m v_{1}^{2}=G M m\left(\frac{b}{a}\right) \cdot \frac{1}{(b+a)} \\
		&v_{1}=\sqrt{2 G M\left(\frac{b}{a}\right) \cdot \frac{1}{(b+a)}} \\
		&L=m v_{1} a=m \sqrt{2 G M\left(\frac{b}{a}\right) \cdot\left(\frac{1}{b+a}\right)} \cdot a=m \sqrt{\frac{2 G M a b}{(b+a)}} \Rightarrow L=\sqrt{\frac{2 G M m^{2} a b}{a+b}}
	\end{align*}
	The correct option is \textbf{(d)}
\end{answer}
	\item A planet of mass $m$ and an angular momentum $L$ moves in a circular orbit in a potential, $V(r)=-k / r$, where $k$ is a constant. If it is slightly perturbed radially, the angular frequency of radial oscillations is
	{\exyear{NET JUNE 2013}}
\begin{tasks}(2)
	\task[\textbf{A.}] $m k^{2} / \sqrt{2} L^{3}$
	\task[\textbf{B.}]$m k^{2} / L^{3}$
	\task[\textbf{C.}]$\sqrt{2} m k^{2} / L^{3}$
	\task[\textbf{D.}]$\sqrt{3} m k^{2} / L^{3}$
\end{tasks}
\begin{answer}$\left. \right. $\\
	\begin{minipage}{0.5\textwidth}
	\begin{align*}
	V_{e f f}&=\frac{L^{2}}{2 m r^{2}}-\frac{k}{r} \\
	\intertext{For circular orbit} \frac{\partial V_{e f f}}{\partial r}&=-\frac{L^{2}}{m r^{3}}+\frac{k}{r^{2}}=0 \\
	\Rightarrow \frac{L^{2}}{m r^{3}}&=\frac{k}{r^{2}} \\
	\text{Thus} r&=r_{0}=\frac{L^{2}}{m k} \Rightarrow \omega=\sqrt{\frac{k}{m}},
	\end{align*}
	\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{figure}[H]
	\centering
	\includegraphics[height=4cm,width=5cm]{diagram-20210926(17)-crop}
\end{figure}
\end{minipage}
 \begin{align*}
 k&=\left.\frac{d^{2} V_{e f f}}{d r^{2}}\right|_{r=r_{0}}=+\frac{3 L^{2}}{m r^{4}}-\left.\frac{2 k}{r^{3}}\right|_{r=r_{0}}=\frac{3 L^{2}}{m\left(\frac{L^{2}}{m k}\right)^{4}}-\frac{2 k}{\left(\frac{L^{2}}{m k}\right)^{3}}=\frac{3 m^{3} k^{4}}{L^{6}}-\frac{2 m^{3} k^{4}}{L^{6}}=\frac{m^{3} k^{4}}{L^{6}}\\
 \omega&=\sqrt{\frac{\left.\frac{d^{2} V}{d r^{2}}\right|_{r=r_{0}}}{m}} \Rightarrow \omega=\frac{m k^{2}}{L^{3}}
 \end{align*}
 The correct option is \textbf{(b)}
\end{answer}

\item The radius of Earth is approximately $6400 \mathrm{~km}$. The height $h$ at which the acceleration due to Earth's gravity differs from $g$ at the Earth's surface by approximately $1 \%$ is
	{\exyear{NET DEC 2014}}
\begin{tasks}(2)
	\task[\textbf{A.}] $64 \mathrm{~km}$
	\task[\textbf{B.}] $48 \mathrm{~km}$
	\task[\textbf{C.}]$32 \mathrm{~km}$
	\task[\textbf{D.}]$16 \mathrm{~km}$
\end{tasks}
\begin{answer}
$\frac{g}{g^{\prime}}=1+\frac{2 h}{R} \Rightarrow \frac{g}{g^{\prime}}-1=\frac{2 h}{R} \Rightarrow \frac{\Delta g}{g^{\prime}}=\frac{2 h}{R} \Rightarrow h=32 k \cdot m$\\
The correct option is \textbf{(c)}
\end{answer}

	\item The probe Mangalyaan was sent recently to explore the planet Mars. The inter-planetary part of the trajectory is approximately a half-ellipse with the Earth (at the time of launch),Sun and Mars (at the time the probe reaches the destination) forming the major axis. Assuming that the orbits of Earth and Mars are approximately circular with radii $R_{E}$ and $R_{M}$, respectively, the velocity (with respect to the Sun) of the probe during its voyage when it is at a distance
		\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(22)-crop(1)}
	\end{figure}
	 $r\left(R_{E}<<r<<R_{M}\right) \text { from the Sun, neglecting the effect of Earth and Mars, is }$
	{\exyear{NET DEC 2014}}
\begin{tasks}(2)
	\task[\textbf{A.}] $\sqrt{2 G M \frac{\left(R_{E}+R_{M}\right)}{r\left(R_{E}+R_{M}-r\right)}}$
	\task[\textbf{B.}]$\sqrt{2 G M \frac{\left(R_{E}+R_{M}-r\right)}{r\left(R_{E}+R_{M}\right)}}$
	\task[\textbf{C.}]$\sqrt{2 G M \frac{R_{E}}{r R_{M}}}$
	\task[\textbf{D.}]$\sqrt{\frac{2 G M}{r}}$
\end{tasks}
\begin{answer}
	$\text { Total energy } E=-K / 2 a \text { where } 2 a \text { major axis and } 2 a=R_{E}+R_{M} \text {. }$
	$$\frac{1}{2} m v^{2}-\frac{G M m}{r}=-\frac{G M m}{\left(R_{E}+R_{M}\right)} \Rightarrow v=\sqrt{2 G M \frac{\left(R_{E}+R_{M}-r\right)}{r\left(R_{E}+R_{M}\right)}}$$
	The correct option is \textbf{(b)}
\end{answer}
	\item After a perfectly elastic collision of two identical balls, one of which was initially at rest, the velocities of both the balls are non zero. The angle $\theta$ between the final, velocities (in the lab frame) is
	{\exyear{NET DEC 2016}}
\begin{tasks}(2)
	\task[\textbf{A.}] $\theta=\frac{\pi}{2}$
	\task[\textbf{B.}]$\theta=\pi$
	\task[\textbf{C.}]$0<\theta \leq \frac{\pi}{2}$
	\task[\textbf{D.}] $\frac{\pi}{2}<\theta \leq \pi$
\end{tasks}
\begin{answer}
 Angle between two particle $\theta_{1}+\theta_{2}=0$
Conservation of momentum
\begin{align*}
&m u=m v_{1} \cos \theta_{1}+m v_{2} \cos \theta_{2} \\
&0=m v_{1} \sin \theta_{1}-m v_{2} \sin \theta_{2}
\intertext{conservation of kinetic energy }
&\frac{1}{2} m u^{2}=\frac{1}{2} m v_{1}^{2}+\frac{1}{2} m v_{2}^{2}\\
	&u^{2}=v_{1}^{2}+v_{2}^{2}+2 v_{1} v_{2}\left(\cos \theta_{1} \cos \theta_{2}-\sin \theta_{1} \sin \theta_{2}\right) \\
	&u^{2}=v_{1}^{2}+v_{2}^{2}+2 v_{1} v_{2} \cos \left(\theta_{1}+\theta_{2}\right) \\
	&u^{2}=v_{1}^{2}+v_{2}^{2} \\
	&v_{1}^{2}+v_{2}^{2}=v_{1}^{2}+v_{2}^{2}+2 v_{1} v_{2} \cos \left(\theta_{1}+\theta_{2}\right) \\
	&\cos \left(\theta_{1}+\theta_{2}\right)=0 \\
	&\theta_{1}+\theta_{2}=\frac{\pi}{2} \Rightarrow \theta=\frac{\pi}{2}
\end{align*}
The correct option is \textbf{(a)}
\end{answer}
	\item Consider circular orbits in a central force potential $V(r)=-\frac{k}{r^{n}}$, where $k>0$ and $0<n<2$. If the time period of a circular orbit of radius $R$ is $T_{1}$ and that of radius $2 R$ is $T_{2}$, then $\frac{T_{2}}{T_{1}}$
	{\exyear{NET DEC 2016}}
\begin{tasks}(2)
	\task[\textbf{A.}] $2^{\frac{n}{2}}$
	\task[\textbf{B.}]$2^{\frac{2}{3} n}$
	\task[\textbf{C.}]$2^{\frac{n}{2}+1}$
	\task[\textbf{D.}]$2^{n}$
\end{tasks}
\begin{answer}
	\begin{align*}
		&V_{e f f}=\frac{J^{2}}{2 m r^{2}}-\frac{k}{r^{n}}, \frac{\partial V_{e f f}}{\partial r}=-\frac{J^{2}}{m r^{3}}+\frac{n k}{r^{n+1}}=0\\
		&\because J=m r^{2} \omega \Rightarrow \frac{m^{2} \omega^{2} r^{4}}{r^{3}}=\frac{n k}{r^{n+1}} \Rightarrow \omega^{2} \propto \frac{1}{r^{n+2}} \Rightarrow \omega \propto r^{-(n+2) / 2} \Rightarrow T \propto r^{\frac{n}{2}+1} \\
		&\frac{T_{2}}{T_{1}}=\left(\frac{2 R}{R}\right)^{\frac{n+2}{2}}=2^{\frac{n}{2}+1}
	\end{align*}
	The correct option is \textbf{(c)}
\end{answer}
	\item A ball weighing $100 \mathrm{gm}$, released from a height of $5 \mathrm{~m}$, bounces perfectly elastically off a plate. The collision time between the ball and the plate is $0.5 \mathrm{~s}$. The average force on the plate is approximately
{	\exyear{NET JUNE 2017}}
\begin{tasks}(2)
	\task[\textbf{A.}] $3 N$
	\task[\textbf{B.}]$2 N$
	\task[\textbf{C.}]$5 N$
	\task[\textbf{D.}]$4 N$
\end{tasks}
\begin{answer}
\begin{align*}
m&=\frac{100}{1000}=0.1 \mathrm{~kg}\\
m g h&=\frac{1}{2} m v^{2} \\
v&=\sqrt{2 g h} \\
v & =10 \mathrm{~m} / \mathrm{sec}
\intertext{change in momentum during collision}
 (m v)-(-m v)&=2 k . g m / \mathrm{sec}\\
f&=\frac{\Delta P}{\Delta t}=\frac{2}{0.5}=4 N
\end{align*}
The correct option is \textbf{(d)}
\end{answer}
	\item Which of the following figures best describes the trajectory of a particle moving in a repulsive central potential $V(r)=\frac{a}{r}(a>0$ is a constant)?
	{\exyear{NET JUNE 2018}}
\begin{tasks}(2)
	\task[\textbf{A.}]\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(47)-crop}
	\end{figure}
	\task[\textbf{B.}]\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(48)-crop}
	\end{figure}
	\task[\textbf{C.}]\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(49)-crop}
	\end{figure}
	\task[\textbf{D.}]\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(50)-crop}
	\end{figure}
\end{tasks}
\begin{answer}
\begin{minipage}{0.5\textwidth}
	 The potential is $V(r)=\frac{a}{r}$ which is repulsive. So there is unbounded motion and mainly represent by scattering project
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{figure}[H]
	\centering
	\includegraphics[height=3cm,width=5cm]{diagram-20210926(51)-crop}
\end{figure}
\end{minipage}\\
The correct option is \textbf{(c)}
\end{answer}

	\item A particle of mass $m$ moves in a central potential $V(r)=-\frac{k}{r}$ in an elliptic orbit $r(\theta)=\frac{a\left(1-e^{2}\right)}{1+e \cos \theta}$, where $0 \leq \theta<2 \pi$ and $a$ and $e$ denote the semi-major axis and eccentricity, respectively. If its total energy is $E=-\frac{k}{2 a}$, the maximum kinetic energy is
	{\exyear{NET JUNE 2018}}
\begin{tasks}(2)
	\task[\textbf{A.}] $E\left(1-e^{2}\right)$
	\task[\textbf{B.}]$E \frac{(e+1)}{(e-1)}$
	\task[\textbf{C.}]$E /\left(1-e^{2}\right)$
	\task[\textbf{D.}]$E \frac{(e-1)}{(e+1)}$
\end{tasks}
\begin{answer}

\begin{align*}
 &E=T+V \quad T=E-V\\
&T=-\frac{k}{2 a}+\frac{k}{r} T=-\frac{k}{2 a}+\frac{k}{a\left(1-e^{2}\right)}(1+\cos \theta)
&\intertext{T is maximum when }
&\cos \theta=1\\
&T_{\max }=-\frac{k}{2 a}+\frac{k(1+e)}{a\left(1-e^{2}\right)}=-\frac{k}{2 a}+\frac{k}{a} \frac{(1+e)}{(1-e)(1+e)} \\
&=-\frac{k}{a}\left[\frac{1}{2}+\frac{1}{(1-e)}\right]=-\frac{k}{2 a}\left(\frac{1+e}{1-e}\right)=-E\left(\frac{1+e}{1-e}\right)
\end{align*}
The correct option is \textbf{(b)}
\end{answer}

	\item In the attractive Kepler problem described by the central potential $V(r)=\frac{-k}{r}($ where $k$ is a positive constant), a particle of mass $m$ with a non-zero angular momentum can never reach the centre due to the centrifugal barrier. If we modify the potential to
	$$
	V(r)=-\frac{k}{r}-\frac{\beta}{r^{3}}
	$$
	one finds that there is a critical value of the angular momentum $\ell_{c}$ below which there is no centrifugal barrier. This value of $\ell_{c}$ is
	{\exyear{NET DEC 2018}}

\begin{tasks}(2)
	\task[\textbf{A.}] $\left[12 \mathrm{~km}^{2} \beta\right]^{1 / 2}$
	\task[\textbf{B.}]$\left[12 \mathrm{~km}^{2} \beta\right]^{-1 / 2}$
	\task[\textbf{C.}]$\left[12 \mathrm{~km}^{2} \beta\right]^{1 / 4}$
	\task[\textbf{D.}]$\left[12 \mathrm{~km}^{2} \beta\right]^{-1 / 4}$
\end{tasks}
\begin{answer}
	\begin{align*}
		&V_{e f f}=\frac{L^{2}}{2 m r^{2}}-\frac{k}{r}=0 \Rightarrow-\frac{L^{2}}{m r^{3}}+\frac{k}{r^{2}}=0 \Rightarrow r_{0}=\frac{L^{2}}{m k}\\
	\intertext{when introduce new potential}
	&V_{e f f}=\frac{L^{2}}{2 m r^{2}}-\frac{k}{r}-\frac{\beta}{r^{3}}
	\\
	\intertext{For critical value}
	&\frac{\partial V_{e f f}}{\partial r}=\frac{-L^{2}}{m r^{3}}+\frac{k}{r^{2}}+\frac{3 \beta}{r^{4}} \\
	&\frac{\partial^{2} V_{e f f}}{\partial r^{2}}=\frac{+3 L^{2}}{m r^{4}} \frac{-2 k}{r^{3}}-\frac{12 \beta}{r^{5}} \geq 0\\
	\intertext{ For critical value }
	&=\frac{3 L^{2}}{m\left(\frac{L^{2}}{m k}\right)^{4}}-\frac{2 k}{\left(\frac{L^{2}}{m k}\right)^{3}}-\frac{12 \beta}{\left(\frac{L^{2}}{m k}\right)^{5}}=0=\frac{3 m^{3} k^{4}}{L^{6}}-\frac{2 m^{3} x^{4}}{L^{6}}-\frac{12 m^{5} x^{5} \beta}{L^{10}}=0 \\
	&L_{C}=\left(12 m^{2} k \beta\right)^{1 / 4} \frac{m^{3} k^{4}}{L^{6}}\left(3-2-12 \frac{m^{2} k \beta}{L^{4}}\right)=0 \Rightarrow L_{c}=\left(12 m^{2} k \beta\right)^{1 / 4}
	\end{align*}
	The correct option is \textbf{(c)}
\end{answer}
\end{enumerate}

\newpage
\begin{abox}
	Practice set 2 solutions
	\end{abox}
\begin{enumerate}
	\item In a central force field, the trajectory of a particle of mass $m$ and angular momentum $L$ in plane polar coordinates is given by,\\
	$$\frac{1}{r}=\frac{m}{l^{2}}(1+\varepsilon \cos \theta)$$
	where, $\varepsilon$ is the eccentricity of the particle's motion. Which one of the following choice for $\varepsilon$ gives rise to a parabolic trajectory?
	{\exyear{GATE 2012}}
\begin{tasks}(2)
	\task[\textbf{A.}] $\varepsilon=0$
	\task[\textbf{B.}]$\varepsilon=1$
	\task[\textbf{C.}] $0<\varepsilon<1$
	\task[\textbf{D.}] $\varepsilon>1$
\end{tasks}
\begin{answer}
	$$
	\frac{1}{r}=\frac{m}{l^{2}}(1+\varepsilon \cos \theta)
	$$
	For parabolic trajectory $\varepsilon=1$.\\
	The correct option is \textbf{(b)}
\end{answer}

	\item A particle of unit mass moves along the $x$-axis under the influence of a potential, $V(x)=x(x-2)^{2}$. The particle is found to be in stable equilibrium at the point $x=2$. The time period of oscillation of the particle is
	{\exyear{GATE 2012}}
\begin{tasks}(2)
	\task[\textbf{A.}] $\frac{\pi}{2}$
	\task[\textbf{B.}]$\pi$
	\task[\textbf{C.}]$\frac{3 \pi}{2}$
	\task[\textbf{D.}] $2 \pi$
\end{tasks}
\begin{answer}
	\begin{align*}
	&V(x)=x(x-2)^{2} \Rightarrow \frac{\partial V}{\partial x}=(x-2)^{2}+2 x(x-2)=0 \Rightarrow x=2, x=\frac{2}{3}\\
		&\frac{\partial^{2} V}{\partial x^{2}}=2(x-2)+2(x-2)+\left.2 x \Rightarrow \frac{\partial^{2} V}{\partial x^{2}}\right|_{x=2}=2 \times 2=4 \\
		&\Rightarrow \omega=\sqrt{\left.\frac{\partial^{2} V}{\partial x^{2}}\right|_{x=2}} \Rightarrow \omega=\frac{2 \pi}{T}=2 \Rightarrow T=\pi
	\end{align*}
	The correct option is \textbf{(b)}
\end{answer}
	\item $\text { A particle of mass } m \text { is in a potential given by }$
	$$V(r)=-\frac{a}{r}+\frac{a r_{0}^{2}}{3 r^{3}}$$
	where $a$ and $r_{0}$ are positive constants. When disturbed slightly from its stable equilibrium position it undergoes a simple harmonic oscillation. The time period of oscillation is
	{\exyear{GATE 2014}}
\begin{tasks}(2)
	\task[\textbf{A.}] $2 \pi \sqrt{\frac{m r_{0}^{3}}{2 a}}$
	\task[\textbf{B.}]$2 \pi \sqrt{\frac{m r_{0}{ }^{3}}{a}}$
	\task[\textbf{C.}]$2 \pi \sqrt{\frac{2 m r_{0}^{3}}{a}}$
	\task[\textbf{D.}]$4 \pi \sqrt{\frac{m r_{0}^{3}}{a}}$
\end{tasks}
\begin{answer}
	\begin{align*}
	V(r)&=-\frac{a}{r}+\frac{a r_{0}^{2}}{3 r^{3}}\\
	\text{For equilibrium} \frac{\partial V}{\partial r}&=\frac{a}{r^{2}}-\frac{3 a r_{0}^{2}}{3 r^{4}}=0, \quad r=\pm r_{0} \\
	\frac{\partial^{2} V}{\partial r^{2}}&=-\frac{2 a}{r^{3}}+\left.\frac{4 a r_{0}^{2}}{r^{5}}\right|_{r_{0}}=-\frac{2 a}{r_{0}^{3}}+\frac{4 a r_{0}^{2}}{r_{0}^{5}}=\frac{2 a}{r_{0}^{3}}\\
	\omega&=\sqrt{\frac{\left.\frac{\partial^{2} V}{\partial r^{2}}\right|_{r_{0}}}{m}} \Rightarrow T=2 \pi \sqrt{\frac{m r_{0}^{3}}{2 a}}
	\end{align*}
	The correct option is \textbf{(a)}
\end{answer}
	\item A planet of mass $m$ moves in a circular orbit of radius $r_{0}$ in the gravitational potential $V(r)=-\frac{k}{r}$, where $k$ is a positive constant. The orbit angular momentum of the planet is
	{\exyear{GATE 2014}}
\begin{tasks}(2)
	\task[\textbf{A.}] $2 r_{0} \mathrm{~km}$
	\task[\textbf{B.}]$\sqrt{2 r_{0} \mathrm{~km}}$
	\task[\textbf{C.}]$r_{0} k m$
	\task[\textbf{D.}]$\sqrt{r_{0} k m}$
\end{tasks}
\begin{answer}
\begin{align*}
	V_{\text {effctive }}&=\frac{J^{2}}{2 m r^{2}}-\frac{k}{r} \Rightarrow \frac{d V_{\text {effect }}}{d r}=-\frac{J^{2}}{m r^{3}}+\frac{k}{r^{2}}=0 \text { at } r=r_{0}\\
\text { so } J&=\sqrt{r_{0} k m}
\end{align*}
The correct option is \textbf{(d)}
\end{answer}
	\item An interstellar object has speed $v$ at the point of its shortest distance $R$ from a star of much larger mass $M$. Given $v^{2}=2 G M / R$, the trajectory of the object is
	{\exyear{GATE 2018}}
\begin{tasks}(2)
	\task[\textbf{A.}] circle
	\task[\textbf{B.}]ellipse
	\task[\textbf{C.}]parabola
	\task[\textbf{D.}]hyperbola
\end{tasks}
\begin{answer}
	\begin{align*}
	\text { At shortest distance } E&=\frac{J^{2}}{2 m R^{2}}-\frac{G M m}{R}\\
	Since, m v R&=J \Rightarrow J^{2}=m^{2} v^{2} R^{2}\\
	Now, J^{2}&=m^{2} 2 G M R=2 G M m^{2} R\\
	(Given that v^{2}&=\frac{2 G M}{R} )\\
	E&=\frac{2 G M m^{2} R}{2 m R^{2}}-\frac{G M m}{R}=\frac{G M m}{R}-\frac{G M m}{R}=0
	\end{align*}
	$\text { For Kepler's potential, if energy is zero, then the shape is parabola. }$\\
	The correct option is \textbf{(c)}
\end{answer}

\end{enumerate}

Classical Mechanics  -CSIR/chapter/central force motion solutions.tex


\documentclass[12pt]{article}
\input{physics1}
\begin{document}

\section*{NYU Physics I---ideal gas law}

Here we investigate the statistical properties of a large number of
free particles in a box.
Imagine you have $N$ particles, each of mass $m$, in a box of volume $V$.
For definiteness, imagine that the box is a cube of side length $\ell$.
Work with a partner and make sure you both agree on each part and understand
why at each stage. This is an introduction to statistical mechanics.

\paragraph{\theproblem}\refstepcounter{problem}%
Just for kicks, imagine that \emph{half} of the particles are moving
at speed $+v$ in the $x$-direction, and half are moving at speed $-v$
in the $x$-direction. When the particles hit the box walls, they
bounce elastically off them. How many particles per unit time, on
average, hit the wall that is perpendicular to the $x$ direction?
Make sure you have a good, simple argument, and that your answer is
dimensionally correct.

\paragraph{\theproblem}\refstepcounter{problem}%
If each particle bounces elastically and normally off the wall (that
is, there is no frictional force at the wall), then how much momentum
is delivered by the wall at each individual-particle impact? That is,
what is the impulse of each impact?

\paragraph{\theproblem}\refstepcounter{problem}%
If the average force is the average of momentum provided per unit
time, what is the mean force provided by the ``gas'' of particles to
the wall, and what is the mean pressure (force per area)? Do you see
why there is a mean force? If not, argue it out.

\paragraph{\theproblem}\refstepcounter{problem}%
Now imagine that each particle has not the same velocity, but some
mean squared velocity $\bar{v_x^2}$ in the $x$-direction. What is the
mean pressure in terms of the mean squared velocity?

\paragraph{\theproblem}\refstepcounter{problem}%
In high school, did you learn that $P\,V = n\,R\,T$? What were the
units of $P$, $V$, $P\,V$, $n$, $R$, $T$, and $n\,R\,T$?

\paragraph{\theproblem}\refstepcounter{problem}%
In statistical mechanics, the equation is $P\,V = N\,k\,T$, where $N$
is the number of molecules, and $k$ is the Boltzmann constant. What is
the ratio $R/k$, both conceptually and numerically?

\paragraph{\theproblem}\refstepcounter{problem}%
Space is three-dimensional, so the mean squared three-space
velocity can be written in terms of one-dimensional means $\bar{v^2} =
\bar{v_x^2} + \bar{v_y^2} + \bar{v_z^2}$. If the gas of particles is
isotropic, these three contributions to the mean velocity magnitude
ought to all be equal, or three times the mean-squared $x$ component.
Relate the pressure you got above to the mean-squred three-space velocity,
and also the mean kinetic energy per molecule $(1/2)\,m\,\bar{v^2}$.

\paragraph{\theproblem}\refstepcounter{problem}%
Rearrange your equation into the form $P\,V=\mbox{something}$. How can
you define $T$ in terms of the per-particle kinetic energy to make the
statistical mechanics equation $P\,V = N\,k\,T$ true? Do you have any
comments to make?

\paragraph{\theproblem}\refstepcounter{problem}%
Look up equipartition on the web and comment on the relationship
between what you got and what you expect from your web reading. Any
comments on the derivation above?

\end{document}


\documentclass[
  xhtml,%
  use filename%
]{internet}
%\usepackage{fancyvrb}
%\usepackage[scale=.8]{geometry}
\usepackage{tutorial}
\usepackage{hyperref}

\newtheorem{question}{Question}

\title{What's Your Angle?}

\begin{document}
\maketitle
\section{Introducing Logo}

\ \verb+Logo+ is a computer programming language built around giving instructions to a \emph{turtle} (can be either robotic or virtual).
You tell the turtle where to move, and as it moves then it draws a line to show its path.
The instructions are given as if telling the turtle where to go next.
So you might say ``Go forward \(50\) steps'' or ``Turn left \(30^\circ\)''.
Using these, and similar, commands you can get the turtle to draw quite intricate patterns.

There are a few other commands relating to the line that it draws.
You can change the colour and width of the line.
You can tell it to skip a section of the line.
In some implementations, you can tell it to \emph{fill} a shape that it has drawn (that isn't a feature of this version but you can find online \verb+Logo+ implementations to play with).

\section{Moving Your Turtle}

\begin{enumerate}
\item Go to \href{http://luacanvas.mathforge.org?project=Turtle}{http://luacanvas.mathforge.org?project=Turtle}
\item To make the turtle draw something, you give it the instructions inside the \verb+setup+ function.
It will then draw what you tell it when you run the code.

Your turtle is called just \verb+turtle+.
If you want to change its name, replace the lowercase \verb+turtle+ in the line \verb+turtle = Turtle()+ with your chosen name.
You can only use letters, and you can't use spaces (but capital letters are fine).
So \verb+Fred = Turtle()+ is okay.
If you change the name, you have to use that name exactly as you originally wrote it.
In this tutorial, we will assume that we haven't changed the name.

The commands are:
\begin{itemize}
\item To make the turtle go forwards, \verb+turtle:forward(30)+.

Note the colon, \verb+:+, between the \verb+turtle+ and \verb+forward+.
The number, in this case \(30\), tells it how much to go forwards.
The units are pixels (the tiny dots) on the screen.

The number can be negative, but \dots

\item To make the turtle go backwards, \verb+turtle:backward(30)+.

\item To turn the turtle to its left, \verb+turtle:left(30)+.

The key here is that the turn is from the point of view of the turtle.
It will turn to its left by \(30^\circ\).

The number can be negative, but \dots

\item To turn the turtle to its right, \verb+turtle:right(30)+.

\item To stop it drawing, use \verb+turtle:penUp()+.

Note the parentheses at the end.
This means that when the turtle moves it will not leave a trail behind it.

\item To resume drawing, use \verb+turtle:penDown()+.

\item To change the colour, use \verb+turtle:setPenColour(127,245,200)+ or \verb+turtle:setPenColour("blue")+.

For more on how to specify a colour, see the \href{Style.xhtml}{Programming with Style} tutorial in the \emph{Programming} section of the tutorials.

\item To change the width, use \verb+turtle:setPenWidth(3)+.

\end{itemize}

\item Put some commands in the code to see what happens.
For example, so that the start of your code looks like this:

\begin{verbatim}
function setup()
  turtle = Turtle()
  turtle:forward(100)
  turtle:right(60)
  turtle:forward(30)
  turtle:left(100)
  turtle:forward(50)
  protractor = Protractor()
  ruler = Ruler()
end
\end{verbatim}

\item When you run this code, the ``turtle'' will draw the lines you have told it to.
You will notice two other shapes on the screen (you may have noticed them in the code) which look a bit like a protractor and a ruler.
They are.
You can drag them around the screen and turn them to make measurements to plan your drawing.
They aren't labelled, but the marks are \(5^\circ\) on the protractor and \(5\) pixels on the ruler.
To move them, click near the middle of the shape and drag it.
To rotate them, click near the outside of the shape and drag it round.

\end{enumerate}

\section{A Regular Shape}

In a regular shape, all the sides have the same length and all the angles are the same.
You can easily make the turtle draw a regular shape by alternating a turn of a fixed angle with a forward of a fixed distance.
Written out in full, this would have a lot of repetition and would be tedious to change to make a new shape.
So we use a \emph{loop} to make it more concise.

To repeat something a set number of times, we put it in a \verb+for+ loop, like this:

\begin{verbatim}
for k=1,4 do
  turtle:forward(100)
  turtle:turn(50)
end
\end{verbatim}

This repeats the instructions a total of \(4\) times.
The start of your code should look like this:

\begin{verbatim}
function setup()
  turtle = Turtle()
  for k = 1,4 do
    turtle:forward(100)
    turtle:right(50)
  end
  protractor = Protractor()
  ruler = Ruler()
end
\end{verbatim}

This shape doesn't join up.
The first goal is to find an angle and a number of repetitions that do make a closed, simple shape.
``Closed'' means that the lines join up, ``simple'' means that the lines don't cross each other.

By changing the \verb+4+ in the line \verb+for k=1,4 do+ then we change the number of repetitions.
Changing the \verb+50+ changes the angle.
If your drawing is too big for the screen, change the \verb+100+ to something smaller.

Once you have found an angle and a number of repetitions that works, make sure that your number of repetitions is \emph{minimal}.
That means that if you reduce the number of repetitions further then the shape will no longer close up.
It will also mean that the turtle ends up at exactly the same place and in the same direction as it started.

\begin{question}
What is the relationship between the number of repetitions and the angle that the turtle turns each time?

Find some other angles and number of repetitions that also draw closed, simple shapes.

What is the general relationship?
\end{question}

\begin{question}
What happens if we no longer insist that the shape be \emph{simple}?
So we allow the lines to cross existing lines, but the turtle must end up back where it started and facing the same way as it started.
\end{question}

\section{Irregular Shapes}

In an irregular shape, we no longer insist that the angles and side lengths be the same.
Let us, though, insist that the shape be still a closed, simple shape.

Draw a closed, simple shape that only involves \emph{left} turns (i.e., left turns with a positive angle).

To draw your shape, start with a few instructions with turns and forwards, then run your code to see where your turtle ends up.
Keep adding some more instructions and running your code to see what happens.
You may find it useful to use the ruler and protractor, particularly when figuring out the last ``joining up'' line.

\begin{question}
What do you spot about the angles that you turn?

\end{question}

\emph{Hint: what do you get if you add them up?}

\begin{question}
Now include some right turns as well (but keep the shape simple: no intersections).
What do you notice about the angles now?
\end{question}

\emph{Hint: treat the left and right turns separately.}

\section{Spirals}

There are some additional drawing commands that can be used to make nice spirals.

\begin{itemize}
\item \verb+turtle:toPosition(20,30)+ moves the turtle to the coordinate \((20,30)\) (with origin in the centre of the screen).
If the turtle's pen is down, a line will be drawn as it moves.

\item \verb+turtle:toRelativePosition(20,30)+ moves the turtle to the
coordinate \((20,30)\) relative to its current position.
That is, it moves it \(20\) pixels across and \(30\) up.

\item \verb+turtle:toAngle(50)+ turns the turtle so that it makes an angle of \(50^\circ\) from the horizontal, measured anticlockwise.

\item \verb+turtle:toRelativeAngle(50)+ turns the turtle so that it makes an angle of \(50^\circ\) from the line joining it to its original position at the centre of the screen.
\end{itemize}

Here are some spirals to get you started.
Pick one and make some changes to the code to experiment with.

\begin{enumerate}

\item You can get a nice spiral with the following instructions:

\begin{verbatim}
turtle:penUp()
turtle:toPosition(10,0)
turtle:penDown()
for k = 1,100 do
  turtle:forward(10)
  turtle:toRelativeAngle(90)
end
\end{verbatim}

\item The \emph{Fibonacci Sequence} leads to a nice spiral:

\begin{verbatim}
local a,b = 5,5
turtle:right(135)
for k=1,10 do
  turtle:forward(a)
  turtle:left(90)
  a,b = b,a+b
end
\end{verbatim}

\item Spirals can go inwards as well as outwards:

\begin{verbatim}
local s = 100
for k=1,30 do
  turtle:forward(s)
  turtle:left(60)
  s = .9*s
end
\end{verbatim}
\end{enumerate}

\end{document}


\documentclass[12pt]{article}
\usepackage[pdftex]{graphicx}
\begin{document}
\newcounter{problem}
\thispagestyle{empty}

\section*{NYU General Physics 1---Problem set 2}

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
What is the mean acceleration $a$ of a dragster (that is, a
drag-racing automobile) that can travel 0.25~mi in 5.5~s, starting
from a dead stop?  Assume that the dragster accelerates with constant
acceleration throughout the 5.5~s (not a terrible assumption, but not
a good one either).  Give your answer in terms of the gravitational
acceleration $g$.  Does your answer seem reasonable?  What do you
predict, under the constant-acceleration assumption, for the final
speed $v_\mathrm{f}$ of the dragster as it crosses the finish line?
Convert your answer to $\mathrm{mi\,h^{-1}}$.  Search the web for the
current world-record quarter-mile drag-race time and final speed.

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
For the time interval $0<t<1~\mathrm{s}$, draw graphs of the vertical
position $y$ (height) as a function of time, the vertical velocity
$v_y$ as a function of time, and the vertical acceleration $a_y$ as a
function of time of a rock that is thrown precisely upwards at
$3~\mathrm{m\,s^{-1}}$ at time $t=0$.  For definiteness, set
$|\vec{g}|=10~\mathrm{m\,s^{-2}}$ and make the ``upwards'' direction the
positive-$y$ direction.  Where does the rock ``end up'' at the end of
the $1~\mathrm{s}$ period; that is, what is $y(1\,\mathrm{s})$?
Assume that the rock is large and dense enough that we can ignore air
resistance.

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
Below is a graph of velocity $v_x$ in the $x$ direction as a function
of time $t$.  Draw the corresponding graph of position $x$ \textit{vs} time $t$ and
acceleration $a_x$ \textit{vs} time $t$.  Be very careful with the transitions and the
vertical scales.\\
\includegraphics{../py/vx_vs_t.pdf}

\end{document}


\newif\ifPDF
\ifx\pdfoutput\undefined\PDFfalse
\else\ifnum\pdfoutput > 0\PDFtrue
	\else\PDFfalse
	\fi
\fi

\ifPDF
	\documentclass[pdftex,10pt]{article}
	\RequirePackage[hyperindex,colorlinks,plainpages=false]{hyperref}
	\hypersetup{pdfauthor={Heng Li},linkcolor=blue,citecolor=blue,urlcolor=blue}
	\usepackage{graphicx}
	\DeclareGraphicsRule{*}{mps}{*}{}
\else
	\documentclass[10pt]{article}
	\usepackage{graphicx}
\fi

\usepackage{amsmath}
\usepackage{amsthm}

\addtolength{\textwidth}{3cm}
\addtolength{\hoffset}{-1.5cm}
\addtolength{\textheight}{4cm}
\addtolength{\voffset}{-2cm}

\makeindex

\usepackage{natbib}
\bibliographystyle{apalike}

\title{The Pairwise Sequentially Markovian Coalescent Model}
\author{Heng Li and Richard Durbin}
\date{24 January 2008}

\begin{document}

\theoremstyle{plain} \newtheorem{lem}{Lemma}
\theoremstyle{plain} \newtheorem{thm}{Theorem}
\theoremstyle{plain} \newtheorem{cor}{Corollary}
\theoremstyle{remark} \newtheorem{rem}{Remark}

\maketitle

This document gives the mathematical basis for the PSMC, including all
necessary theorems and equations, with discussion. Lemma~\ref{lem:f1}
and~\ref{lem:sd} give two general facts which will be used
later. Theorem~\ref{thm:psmc} proves several central results of the
continuous-time PSMC model. This theorem establishes the foundation of
the whole PSMC theory. Corollary~\ref{cor:djp} and
Remark~\ref{rem:mutprob} show how to calculate or approximate various
probabilities when time is discretized. Remark~\ref{rem:hmm} presents
the construction of HMM, and Remark~\ref{rem:missdata} and
\ref{rem:overfit} explain several catches in
implementation. Remarks~\ref{rem:bootstrap}-\ref{rem:gof2} show methods
on estimating the variance and testing the goodness of fit (GOF).

\section{PSMC: The Pairwise Sequentially Markovian Model}

\subsection{General Fomulae}

This section presents two lemmas for general functions. Lemma~\ref{lem:f1}
will be used to prove the normalization of the conditioned transition probability in the PSMC continuous-time Markov chain; Lemma~\ref{lem:sd}
will be used to derive the stationary distribution of coalescent time.

\begin{lem}\label{lem:f1}
Given
\begin{equation}\label{equ:f}
  f(t|s)=h(t)\int_0^{\min\{s,t\}}\frac{g(u)}{\int_0^sg(w)\,dw} \cdot e^{-\int_u^th(v)\,dv}\,du
\end{equation}
where $g(t)$ and $h(t)$ are any functions that can be integrated on $[0,\infty)$, the
following equation always stands:
\[\int_0^{\infty}f(t|s)\,dt=1\]
\end{lem}

\begin{proof}
Let:
\[t=\phi(\tilde t)\]
and
\[\tilde g(\tilde u)=\frac{g(\phi(\tilde u))}{h(\phi(\tilde u))}\]
where $\phi(\tilde t)$ satisfies $\phi(0)=0$ and
\[\phi'(\tilde u)\cdot h(\phi(\tilde u))=1\]
The integral becomes:
\[f(t|s)\,dt=\frac{f(\phi(\tilde t)|\phi(\tilde s))}{h(\phi(\tilde t))}\,d\tilde t
=\frac{\int_0^{\min\{\tilde s,\tilde t\}}\tilde g(\tilde u)e^{-(\tilde t-\tilde u)}d\tilde u}
{\int_0^{\tilde s}\tilde g(\tilde u)d\tilde u}\,d\tilde t\]
If we note that for any $g(t)$ that can be integrated:
\begin{eqnarray*}
  &&\int_0^{\infty}e^{-v}dv\int_0^{\min\{v,t\}}g(u)e^u\,du\\
  &=&\int_0^tg(u)e^udu\Bigg(\int_u^te^{-v}dv+\int_t^{\infty}e^{-v}dv\Bigg)\\
  &=&\int_0^tg(u)\,du
\end{eqnarray*}
always stands, we get:
\[\int_0^{\infty}f(t|s)\,dt=\int_0^{\infty}\frac{\int_0^{\min\{\tilde s,\tilde t\}}\tilde g(\tilde u)e^{-(\tilde t-\tilde u)}d\tilde u}
{\int_0^{\tilde s}\tilde g(\tilde u)d\tilde u}\,d\tilde t=1\]
\end{proof}

\begin{lem}[Stationary distribution]\label{lem:sd}
  Let:
  \begin{equation}\label{equ:pi}
    \pi(t)=\frac{h(t)}{C}e^{-\int_0^th(v)dv}\int_0^tg(u)\,du
  \end{equation}
  where $C$ is a scaling constant:
  \begin{equation}
    C=\int_0^{\infty}g(u)e^{-\int_0^uh(v)dv}\,du
  \end{equation}
  The following equations always stand:
  \begin{equation*}
    \int_0^{\infty}f(t|s)\pi(s)\,ds=\pi(t)
  \end{equation*}
  \begin{equation*}
    \int_0^{\infty}\pi(t)\,dt=1
  \end{equation*}
\end{lem}

\begin{proof}
\begin{eqnarray*}
&&\int_0^{\infty}f(t|s)\pi(s)\,ds\\
&=&\frac{h(t)}{C}\int_0^{\infty}\frac{ds}{\int_0^sg(w)\,dw}\cdot
\Bigg[h(s)e^{-\int_0^sh(v)dv}\int_0^sg(w)\,dw\bigg]
\int_0^{\min\{s,t\}}g(u)\,e^{-\int_u^th(v)dv}\,du\\
&=&\frac{h(t)}{C}\int_0^{\infty}h(s)e^{-\int_0^sh(v)dv}ds
\int_0^{\min\{s,t\}}g(u)\,e^{-\int_u^th(v)dv}\,du\\
&=&\frac{h(t)}{C}\int_0^tg(u)\,e^{-\int_u^th(v)dv}\,du
\int_u^{\infty}e^{-\int_0^sh(v)dv}h(s)\,ds\\
&=&\frac{h(t)}{C}\int_0^tg(u)\,e^{-\int_u^th(v)dv}\,du\int_u^{\infty}
d\,\Big[-e^{-\int_0^sh(v)\,dv}\Big]\\
&=&\frac{h(t)}{C}\int_0^tg(u)\,e^{-\int_u^th(v)dv}\,e^{-\int_0^uh(v)dv}\,du\\
&=&\frac{h(t)}{C}e^{-\int_0^th(v)dv}\int_0^tg(u)\,du
\end{eqnarray*}
i.e.:
$$\int_0^{\infty}f(t|s)\pi(s)\,ds=\pi(t)$$
Then $\pi(t)$ is the density of the stationary distribution. Furthermore, as we require that
\begin{eqnarray*}
1&=&\int_0^{\infty}\pi(t)\,dt\\
&=&\int_0^{\infty}\frac{h(t)}{C}e^{-\int_0^th(v)dv}\,dt\int_0^tg(u)\,du\\
&=&\int_0^{\infty}g(u)\,du\int_u^{\infty}\frac{h(t)}{C}e^{-\int_0^th(v)dv}\,dt\\
&=&\frac{1}{C}\int_0^{\infty}g(u)\,du\int_u^{\infty}d\,
\Big[-e^{-\int_0^th(v)\,dv}\Big]\\
&=&\frac{1}{C}\int_0^{\infty}g(u)e^{-\int_0^uh(v)dv}\,du
\end{eqnarray*}
the constant $C$ can thus be calculated.
\end{proof}

\subsection{List of Symbols}
\begin{center}
\begin{tabular}{lll}
\hline
Symbol & Type & Meaning \\
\hline
$a,b$ & discrete & Coordinate on the sequence\\
$t,s,\Delta$ & continuous & Coalescent time \\
$T_a$ & continuous, r.v. & Coalescent time at $a$ \\
$R_a$ & binary, r.v. & Recombination or not between $a$ and $a+1$ \\
$X_a$ & binary, r.v. & Mutation or not at $a$ \\
$N,N_0$ & continuous & Population size \\
$\lambda,\lambda_0$ & continuous & Relative population size \\
$\theta,\theta_0$ & continuous & Per-site mutation rate \\
$\rho,\rho_0$ & continuous & Per-site recombination rate \\
$p,q$ & function & transition probability \\
$i,j,k,l$ & discrete & State of the HMM \\
$u,v,w$ & continuous & Coalescent time (in integration) \\
$C,C_{\pi},C_{\sigma}$ & continous & Scaling constant \\
\hline
\end{tabular}
\end{center}

\subsection{PSMC Model}

In this section, Theorem~\ref{thm:psmc} estabilishes the foundation of
the PSMC continuous-time Markov chain. It gives the equations of transition,
and the stationary distribution. The following corollaries
show how to approximate the constants in the Theorem when the scaled mutation
and recombination rates are small.

The discrete-time Markov chain, which will be presented in the next section,
is derived from the continuous-time Markov chain by integrating probability desities
in time intervals.

\begin{thm}[PSMC]\label{thm:psmc}
  Let the population size be:
  \begin{equation*}
    N(t)=N_0\lambda(t)
  \end{equation*}
  where $t$ equals the number of generations divided by $2N_0$. The
  scaled mutation rate and recombination rate per nucleotide are
  $\theta$ and $\rho$.  respectively. Given two haplotypes, let $T_a$ be
  the coalescent time at position $a\in[1,L]$, and define:
  \begin{equation*}
    R_a=\left\{\begin{array}{ll}
        1 & \mbox{a recombination happens between $a$ and $a+1$} \\
        0 & \mbox{otherwise}
      \end{array}\right.
  \end{equation*}
  \begin{equation*}
    \Lambda(t)=\int_0^t\lambda(u)\,du
  \end{equation*}
  \begin{equation}
    C_{\pi}=\int_0^{\infty}e^{-\int_0^u\frac{dv}{\lambda(v)}}\,du
  \end{equation}
  \begin{equation}
    C_{\sigma}=\int_0^{\infty}\frac{\pi(t)}{1-e^{-\rho t}}dt
  \end{equation}
  According to the SMC (Sequentially Markov Coalescent)
  model~\citep{McVean:2005lr,Marjoram:2006fk}, the following equations stand:
  \begin{equation}\label{equ:q}
    q(t|s)\,dt=\Pr\{T_{a+1}=t|T_a=s,R_a=1\}
    =\frac{dt}{\lambda(t)}\int_0^{\min\{s,t\}}\frac{1}{s}\cdot e^{-\int_u^t\frac{dv}{\lambda(v)}}\,du
  \end{equation}
  \begin{equation}\label{equ:pi2}
    \pi(t)=\Pr\{T_{a+1}=t|R_a=1\}=\frac{t}{C_{\pi}\lambda(t)}e^{-\int_0^t\frac{dv}{\lambda(v)}}
  \end{equation}
  \begin{equation}\label{equ:a}
    p(t|s)=\Pr\{T_{a+1}=t|T_a=s\}=(1-e^{-\rho s})q(t|s) + e^{-\rho s}\delta(t-s)
  \end{equation}
  \begin{equation}\label{equ:sigma1}
    \sigma(t)=\Pr\{T_a=t\}=\frac{\pi(t)}{C_{\sigma}(1-e^{-\rho t})}
  \end{equation}
  \begin{equation}\label{equ:px}
    \Pr\{R_a=1\}=\frac{1}{C_{\sigma}}
  \end{equation}
  Furthermore,
  \begin{equation}\label{equ:pi3}
    \int_0^{\infty}q(t|s)\pi(s)\,ds=\pi(t)
  \end{equation}
  \begin{equation}\label{equ:sigma2}
    \int_0^{\infty}p(t|s)\sigma(s)\,ds=\sigma(t)
  \end{equation}
  and
  \begin{equation}
    \int_0^{\infty}q(t|s)\,dt=\int_0^{\infty}p(t|s)\,dt=\int_0^{\infty}\pi(t)\,dt
    =\int_0^{\infty}\sigma(t)\,dt=1
  \end{equation}
\end{thm}

\begin{proof}
  Equation~\ref{equ:q} is the root of all the other equations.

  \begin{enumerate}

  \item When a recombination happens, the probability that it happens in $[u,u+du)$ is:
  \[P_1(u|s)\,du=\frac{1}{s}\,du\]
  At time $u$, two alleles coalesce at $[t,t+dt)$ is~\citep{Hein:2005yq,Griffiths:1994fk}:
  \[P_2(t|u)\,dt=\frac{1}{\lambda(t)}\exp\Bigg\{-\int_u^t\frac{dv}{\lambda(v)}\Bigg\}\,dt\]
  When we know $s$ and $t$, $u\in[0,\min\{s,t\})$. Then:
  \[q(t|s)=\int_0^{\min\{s,t\}}P_2(t|u)\cdot P_1(u|s)\,du
  =\frac{1}{\lambda(t)}\int_0^{\min\{s,t\}}\frac{1}{s}
  \cdot e^{-\int_u^t\frac{dv}{\lambda(v)}}\,du\]
  This proves Equation~\ref{equ:q}.

  \item In Lemma~\ref{lem:f1} and Lemma~\ref{lem:sd}, let $g(u)=1$ and
  $h(u)=1/\lambda(u)$. We have:
  \[\int_0^{\infty}q(t|s)\,dt=1\]
  \[\int_0^{\infty}q(t|s)\pi(s)\,ds=\pi(t)\]
  This proves Equation~\ref{equ:pi2} and~\ref{equ:pi3}.

  \item Equation~\ref{equ:a} comes \emph{naturally}, and
    \[ \int_0^{\infty}p(t|s)=(1-e^{-\rho s})\int_0^{\infty}q(t|s)\,dt + e^{-\rho s}=1 \]
  \begin{eqnarray*}
    \int_0^{\infty}p(t|s)\sigma(s)\,ds&=&\frac{1}{C_a}\int_0^{\infty}(1-e^{-\rho s})
    \frac{q(t|s)\pi(s)}{1-e^{-\rho s}}\,ds
    +\frac{e^{-\rho t}}{C_{\sigma}(1-e^{-\rho t})}\pi(t)\\
    &=&\frac{\pi(t)}{C_{\sigma}(1-e^{-\rho t})}\\
    &=&\sigma(t)
  \end{eqnarray*}
  This proves Equation~\ref{equ:sigma1} and~\ref{equ:sigma2}.

  \item Given coalescent time $T_a=t$, the probability that a
  recombination happens between $a$ and $a+1$ is:
  \begin{equation*}
    \Pr\{R_a=1|T_a=t\}=1-e^{-\rho t}
  \end{equation*}
  Then
  \[\Pr\{R_a=1\}=\int_0^{\infty}(1-e^{-\rho t})\sigma(t)\,dt=\frac{1}{C_{\sigma}}\]
  This proves Equation~\ref{equ:px}.

  \end{enumerate}
\end{proof}

\begin{cor}[Approximating $C_{\sigma}$]\label{cor:sigma}
  When $\rho_0$ is sufficiently small:
  \begin{equation}
    C_{\sigma}=\frac{1}{C_{\pi}\rho}+\frac{1}{2}+o(\rho)
  \end{equation}
\end{cor}
\begin{proof}
  \begin{eqnarray*}
  C_{\sigma}&=&\int_0^{\infty}\frac{t}{C_{\pi}\lambda(t)[1-e^{-\rho t}]}e^{-\int_0^t\frac{dv}{\lambda(v)}}\,dt\\
  &=&\frac{1}{C_{\pi}\rho}\int_0^{\infty}\Big[1+\frac{\rho t}{2}+o(\rho^2)\Big]
  \frac{1}{\lambda(t)}e^{-\int_0^t\frac{dv}{\lambda(v)}}\,dt\\
  &=&\frac{1}{C_{\pi}\rho}\int_0^{\infty}\frac{1}{\lambda(t)}e^{-\int_0^t\frac{dv}{\lambda(v)}}\,dt
  +\frac{1}{2}\int_0^{\infty}\pi(t)\,dt+o(\rho)\\
  &=&\frac{1}{C_{\pi}\rho}+\frac{1}{2}+o(\rho)
  \end{eqnarray*}
\end{proof}

\begin{cor}[Rate of pairwise difference]\label{cor:theta}
  When both $\theta_0$ and $\rho_0$ are sufficiently small:
  \begin{equation}\label{equ:theta}
    \Pr\{X_a=1\}=C_{\pi}\theta\cdot\big[1+o(\rho+\theta)\big]
  \end{equation}
\end{cor}
\begin{proof}
  \begin{eqnarray*}
    \Pr\{X_a=1\}&=&\int_0^{\infty}\Pr\{X_a=1|T_a=t\}\Pr\{T_a=t\}\,dt\\
    &=&\int_0^{\infty}(1-e^{-\theta t})\sigma(t)\,dt\\
    &=&\frac{1}{C_{\sigma}}\int\frac{1-e^{-\theta t}}{1-e^{-\rho t}}\pi(t)\,dt\\
    &=&\frac{1}{C_{\sigma}}\int\frac{\theta+o(\theta^2)}{\rho+o(\rho^2)}\pi(t)\,dt\\
    &=&\frac{\theta}{C_{\sigma}\rho}\int\Big[1+o(\rho+\theta)\Big]\pi(t)\,dt\\
    &=&C_{\pi}\theta\cdot\big[1+o(\rho+\theta)\big]
  \end{eqnarray*}
\end{proof}

\begin{cor}[First-order approximation]
  Under the first-order approximation with respect to $\theta$ and
  $\rho$, the following equations stand:
  \[
  \Pr\{R_a=1\}=\frac{1}{C_{\pi}}=C_{\pi}\rho
  \]
  \[
  \Pr\{X_a=1\}=C_{\pi}\theta
  \]
  \[
  \sigma(t)=\frac{1}{\lambda(t)}e^{-\int_0^t\frac{dv}{\lambda(v)}}
  \]
  \[
  \int_0^t\sigma(u)\,du=1-e^{-\int_0^t\frac{dv}{\lambda(v)}}
  \]
\end{cor}

\begin{rem}[Distribution of segment lengths]\label{cor:seglen}
  Let $L_{a+1}$ be the length of the segment following a recombination
  occurring at $a$. Conditional on the recombination, $L_{a+1}$ follows
  a exponential distribution (more precisely, a geometric distribution
  in fact):
  \[
  \Pr\{L_{a+1}=l|R_a=1,T_{a+1}=t\}\,dl = \rho te^{-\rho tl}\,dl
  \]
  Then,
  \[
  \Pr\{L=l\}\,dl=dl\int_0^{\infty}\frac{\rho t^2e^{-\rho tl}}{C_{\pi}\lambda(t)}e^{-\int_0^t\frac{dv}{\lambda(v)}}\,dt
  =dl\,\frac{\rho}{C_{\pi}}\int_0^{\infty}e^{-\int_0^t\frac{dv}{\lambda(v)}}\,d\Big(t^2e^{-\rho tl}\Big)
  \]
  The mean segment length is thus
  \begin{eqnarray*}
  &&\int_0^{\infty}\rho tl e^{-\rho tl}\,dl\int_0^{\infty}\frac{t}{C_{\pi}\lambda(t)}e^{-\int_0^t\frac{dv}{\lambda(v)}}\,dt\\
  &=&\frac{1}{C_{\pi}\rho}\int_0^{\infty}\frac{1}{\lambda(t)}e^{-\int_0^t\frac{dv}{\lambda(v)}}\,dt\\
  &=&\frac{1}{C_{\pi}\rho}\approx C_{\sigma}
  \end{eqnarray*}
\end{rem}

%\begin{cor}[PSMC']\label{cor:psmc2}
%  According to SMC', the following equation stands:
%  \begin{eqnarray*}
%    q'(t|s)\,dt&=&\Pr\{T_{a+1}=t|T_a=s,R_a=1\}\\
%    &=&\frac{1}{2}\delta(t-s)\Bigg[1-\int_0^s\frac{\lambda(u)\,du}{\int_0^s\lambda(w)\,dw}
%    e^{-\int_u^s\frac{2\,dv}{\lambda(v)}}\Bigg]\\
%    &&+\frac{dt}{\lambda(t)}\int_0^{\min\{s,t\}}\frac{\lambda(u)\,du}{\int_0^s\lambda(w)\,dw}
%    \cdot e^{-\int_u^{\min\{s,t\}}\frac{dv}{\lambda(v)}-\int_u^t\frac{dv}{\lambda(v)}}
%  \end{eqnarray*}
%\end{cor}
%\begin{proof}
%  At time $u$, there are three alleles $1$, $2$ and $3$. Allele $1$
%  coalesces with $2$ at time $[s,s+ds)$. If $2$ and $3$ coalesce at
%  $[t,t+dt)$, the probability is:
%  \begin{eqnarray*}
%    &&\frac{1}{3}\cdot3\cdot\frac{1}{\lambda(t)}e^{-\int_u^t\frac{3\,dv}{\lambda(v)}}\cdot\frac{1}{\lambda(s)}
%    e^{-\int_t^s\frac{dv}{\lambda(v)}}\,dtds\\
%    &=&\frac{1}{\lambda(t)}e^{-\int_u^t\frac{2\,dv}{\lambda(v)}}\cdot\frac{1}{\lambda(s)}
%    e^{-\int_u^s\frac{dv}{\lambda(v)}}\,dtds
%  \end{eqnarray*}
%  If $1$ and $2$ coalesce first and then coalesce with $3$ at $[t,t+dt)$,
%  the probability is:
%  \begin{eqnarray*}
%    &&\frac{1}{3}\cdot3\cdot\frac{1}{\lambda(s)}e^{-\int_u^s\frac{3\,dv}{\lambda(dv)}}\cdot\frac{1}{\lambda(t)}
%    e^{-\int_s^t\frac{dv}{\lambda(v)}}\,dtds\\
%    &=&\frac{1}{\lambda(t)}e^{-\int_u^s\frac{2\,dv}{\lambda(v)}}\cdot\frac{1}{\lambda(s)}
%    e^{-\int_u^t\frac{dv}{\lambda(v)}}\,dtds
%  \end{eqnarray*}
%  Condition on $s$ and $3$ coalesces with $1$ or above, we have:
%  \begin{equation*}
%    P'_2(t|u)\,dt=\frac{dt}{\lambda(t)}e^{-\int_u^{\min\{s,t\}}\frac{dv}{\lambda(v)}-\int_u^t\frac{dv}{\lambda(v)}}
%  \end{equation*}
%
%  If a recombination happens, the probability that it happens at
%  $[u,u+du)$ is:
%  \[P_1(u|s)\,du=\frac{\lambda(u)}{\int_0^s\lambda(w)\,dw}\,du\]
%  Then the probability that $3$ coalesces with $2$ under $s$ is:
%  \begin{equation*}
%    \int_0^s\,dt\int_0^tP'_2(t|u)P_1(u|s)\,du=\int_0^s\frac{dt}{\lambda(t)}\int_0^t
%    e^{-\int_u^t\frac{2\,dv}{\lambda(v)}}\frac{\lambda(u)\,du}{\int_0^s\lambda(w)\,dw}
%    =\frac{1}{2}\Bigg[1-\int_0^s\frac{\lambda(u)\,du}{\int_0^s\lambda(w)\,dw}e^{-\int_u^s\frac{2\,dv}{\lambda(v)}}\Bigg]
%  \end{equation*}
%\end{proof}
%
%\begin{rem}
%  Due to the theoretical complication, Corollary~\ref{cor:psmc2} is not
%  used in practice.
%\end{rem}

\subsection{Discrete-Time PSMC Model}

This section presents the discrete-time PSMC Markov Chain, its transition probabilities
between time intervals and the stationary distribution. The proof of Corolary~\ref{cor:djp}
is given in the Appendix.

\begin{cor}[Discrete-time PSMC]\label{cor:djp}
  Let
  \[ 0=t_0<t_1<\cdots<t_n<t_{n+1}=\infty \]
  Assume in each time interval $[t_k,t_{k+1})$ function $\lambda(t)$ is a
  constant $\lambda_k$. Define:
  \begin{equation*}
    \pi_k=\int_{t_k}^{t_{k+1}}\pi(t)\,dt
  \end{equation*}
  \begin{equation*}
    \sigma_k=\int_{t_k}^{t_{k+1}}\sigma(t)\,dt
  \end{equation*}
  \begin{equation*}
    q_{kl}=\frac{1}{\pi_k}\int_{t_k}^{t_{k+1}}ds\int_{t_l}^{t_{l+1}}q(t|s)\pi(s)\,dt
  \end{equation*}
  \begin{equation*}
    p_{kl}=\frac{1}{\sigma_k}\int_{t_k}^{t_{k+1}}ds\int_{t_l}^{t_{l+1}}p(t|s)\sigma(s)\,dt
  \end{equation*}
  Then:
  \begin{equation*}
    \pi_k=\frac{1}{C_{\pi}}\Bigg[(\alpha_k-\alpha_{k+1})\Big(\sum_{i=0}^{k-1}\tau_i+\lambda_k\Big)
    -\alpha_{k+1}\tau_k\Bigg]
  \end{equation*}
  \begin{equation}\label{equ:sigmak}
    \sigma_k=\frac{1}{C_{\sigma}}
    \Bigg[\frac{1}{C_{\pi}\rho}(\alpha_k-\alpha_{k+1})+\frac{\pi_k}{2}+o(\rho)\Bigg]
  \end{equation}
  Furthermore, for $l<k$:
  \begin{equation*}
    q_{kl}=\frac{\alpha_k-\alpha_{k+1}}{C_{\pi}\pi_k}\Bigg[(\alpha_l-\alpha_{l+1})\Big(\beta_l-\frac{\lambda_l}{\alpha_l}\Big)
    +(t_{l+1}-t_l)\Bigg]
  \end{equation*}
  for $l=k$:
  \begin{equation*}
    q_{kl}=\frac{1}{C_{\pi}\pi_k}\Bigg[(\alpha_k-\alpha_{k+1})^2\Big(\beta_k-\frac{\lambda_k}{\alpha_k}\Big)
    +2\lambda_k(\alpha_k-\alpha_{k+1})-2\alpha_{k+1}(t_{k+1}-t_k)\Bigg]
  \end{equation*}
  and for $l>k$:
  \begin{equation*}
    q_{kl}=\frac{\alpha_l-\alpha_{l+1}}{C_{\pi}\pi_k}
  \Bigg[(\alpha_k-\alpha_{k+1})\Big(\beta_k-\frac{\lambda_k}{\alpha_k}\Big)+(t_{k+1}-t_k)\Bigg]
  \end{equation*}
  and
  \begin{equation}\label{equ:pkl}
    p_{kl}=\frac{\pi_k}{C_{\sigma}\sigma_k}q_{kl} + \delta_{kl}\Big(1-\frac{\pi_k}{C_{\sigma}\sigma_k}\Big)
  \end{equation}
  where:
  \begin{equation*}
    \tau_k = t_{k+1}-t_k
  \end{equation*}
  \begin{equation*}
    \alpha_k=\exp\Bigg(-\sum_{i=0}^{k-1}\frac{t_{i+1}-t_i}{\lambda_i}\Bigg)
  \end{equation*}
  \begin{equation*}
    \beta_k=\sum_{i=0}^{k-1}\lambda_i\Big(\frac{1}{\alpha_{i+1}}-\frac{1}{\alpha_i}\Big)
  \end{equation*}
  \begin{equation*}
    C_{\pi}=\sum_{k=0}^n\lambda_k(\alpha_k-\alpha_{k+1})
  \end{equation*}
\end{cor}

\begin{rem}[Mutation probability]\label{rem:mutprob}
  The average mutation probability in an interval $[t_k,t_{k+1})$ cannot
  be analytically calculated. But we can seek another way. From
  Equation~\ref{equ:pkl}, a recombination occurs in $[t_k,t_{k+1})$ as if
  it occurs at time
  $-\log\Big[1-\pi_k/(C_{\sigma}\sigma_k)\Big]/\rho$. If we assume
  mutation also exactly occurs at this time point, the probability of a
  mutation is:
  \begin{equation}\label{equ:ek1}
    e_k(1) = \exp\Bigg[-\frac{\theta}{\rho}\log\Big(1-\frac{\pi_k}{C_{\sigma}\sigma_k}\Big)\Bigg]
    = \Big(1-\frac{\pi_k}{C_{\sigma}\sigma_k}\Big)^{\theta/\rho}
  \end{equation}
\end{rem}

\begin{rem}[Determining $N_0$]\label{rem:n0}
  If we know $\mu$, the neutral mutation rate, $N_0=\theta/4\mu$. On
  autosomes, $\mu$ is typically
  $2.5\times10^{-8}$~\citep{Nachman:2000rq}. Note that
  Equation~\ref{equ:theta} agrees with~\citet{Marth:2004vn} in case of
  two haplotypes.
\end{rem}

\section{PSMC Hidden Markov Model}

\subsection{The basic of HMM}

\begin{rem}[PSMC-HMM]\label{rem:hmm}
  We denote a hidden state in the HMM by $k$, which means a coalescence
  between the two haplotypes at this point in the sequence lies in the
  time interval $[t_k,t_{k+1})$. A mutation is emmitted with a
  probability $e_k(1)$ (Equation~\ref{equ:ek1}) and the transition
  probability is $p_{kl}$ (Equation~\ref{equ:pkl}). The stationary
  distribution of the hidden states is $\{\sigma_k\}$
  (Equation~\ref{equ:sigmak}). All these parameters can be analytically
  approximated with a precision of order-two Taylor expansion when
  $\rho_0$ is sufficiently small.
\end{rem}

%\begin{rem}[PSMC-PHMM]\label{rem:phmm}
%  It is possible to use PSMC to approximately model two diploid
%  sequences. In this case, a hidden state is $(k,l)$ and the transition
%  probability of $(k,l)\to(k',l')$ is $p_{kk'}p_{ll'}$. The stationary
%  distribution of hidden states is $\{\sigma_k\sigma_{k'}\}$.
%\end{rem}

\begin{rem}[Missing data]\label{rem:missdata}
  Missing data can be easily incorporated into an HMM. When there is no
  observation at $a$, $e_k(x_a)=1$ for all $k$.
\end{rem}

\begin{rem}[Choosing time intervals]
  We choose a set of $\{t_i\}_{i=0\ldots n}$ that are approximately
  evenly distributed in the log space, but because we require $t_0=0$,
  the intervals will not strictly evenly distributed. In practice, we
  set \[t_i=0.1(e^{\frac{i}{n}\log(1+10T_{max})}-1)\] where
  $T_{max}=t_n$ is chosen such that no more than a few percent of
  coalescences occur beyond $T_{max}$.
\end{rem}

\begin{rem}[Reducing parameters]\label{rem:overfit}
  In principle, we can estimate all the $n+1$ values of $\lambda_k$ with
  EM. However, at both small and large $t$, the expected number of
  segments is very small. Separate estimates of $\lambda_k$ in these
  intervals will lead to overfitting due to insufficient data. An
  effective way to tell whether overfitting occurs is to check
  $C_{\sigma}\pi_k$, the expected number of segments in the interval
  $[t_k,t_{k+1})$. If this number is small (less than $20$, for
  instance), the $\lambda_k$ estimated from EM cannot be trusted due to
  statistical fluctuations. In this case, we should use fewer free
  parameters by using the same $\lambda$ spanning several adjacent
  intervals. This will lower the resolution but will yield much better
  estimation.
\end{rem}

\subsection{Assessing variance and fitness}

\begin{rem}[Bootstrapping]\label{rem:bootstrap}
  The variance can be estimated by boostrapping. We split the input
  diploid sequence into $L'$-long non-overlapping segments and randomly
  resample the segments with replacement to generate a new diploid
  sequence of the same length as the original one.  Parameters are then
  estimated from the new sequence. We repeat this process $B$ times and
  regard the variance of the $B$ resampled estimates as the variance of
  the estimate on the original sequence. Typically, we take
  $L'=30,000,000$ and $B=100$.
\end{rem}

\begin{rem}[Measuring GOF with $\sigma_k$]\label{rem:gof-pi}
  On one hand, from Equation~\ref{equ:sigmak} we can calculate
  $\sigma_k$ from free parameters of the model without looking at the
  data. On the other hand, from forward-backward algorithm we can
  estimate the posterior expectation of the occurences $\hat{c}_k$
  of state $k$:
  \begin{equation*}
    \hat{c}_k=\frac{1}{P(D)}\sum_if_k(i)b_k(i)
  \end{equation*}
  Normalizing $\hat{c}_k$ gives:
  \begin{equation*}
    \hat{\sigma}_k=\frac{\sum_if_k(i)b_k(i)}{\sum_{k,i}f_k(i)b_k(i)}
  \end{equation*}
  where $f_k(i)$ is the forward function of sequence position $i$ and
  state $k$ and $b_k(i)$ is the backward function. If the model fits the
  data, we would expect to see $\{\hat{\sigma}_k\}$ is identical to
  $\{\sigma_k\}$. And therefore the relative entroy
  $D(\sigma||\hat{\sigma})$ would be an indicator of GOF:
  \begin{equation*}
    G^{\sigma}=\sum_k\sigma_k\log\frac{\sigma_k}{\hat{\sigma}_k}
  \end{equation*}
\end{rem}

\begin{rem}[Measuring GOF with $l$-long subsequences]\label{rem:gof2}
  \citet{MacKay-Altman:2004lr} pointed out we can test GOF by comparing
  the distribution of $l$-long subsequences from direct calculation with
  the observed distribution. Given an integer $n\in[0,2^l-1]$, let
  $\{p_n\}$ be the theoretical distribution of the binary sequence
  represented by $n$ and let $\{\hat{p}_n\}$ be the one directly counted
  from the observed sequence. The relative entroy between them is:
  \begin{equation*}
    G_l=\sum_{n=0}^{2^l-1}p_n\log\frac{p_n}{\hat{p}_n}
  \end{equation*}
  which measures GOF. Typically, $l$ is ranged from 10 to 20.
\end{rem}

\appendix

\section{Proof of Corollary~\ref{cor:djp}}\label{sec:pfl1}

\begin{proof}

\[
  C_{\pi}=\int_0^{\infty}e^{-\int_0^u\frac{dv}{\lambda(v)}}\,du
=\sum_{k=0}^{n}\alpha_k\int_{t_k}^{t_{k+1}} e^{-\frac{u-t_k}{\lambda_k}}du
=\sum_{k=0}^n\lambda_k(\alpha_k-\alpha_{k+1})
\]

\begin{eqnarray*}
  \pi_k&=&\int_{t_k}^{t_{k+1}}\pi(t)\,dt\\
  &=&\frac{1}{C_{\pi}}\int_{t_k}^{t_{k+1}}\frac{dt}{\lambda(t)}e^{-\int_0^t\frac{dv}{\lambda(v)}}\cdot t\\
  &=&\frac{1}{C_{\pi}\lambda_k}\int_{t_k}^{t_{k+1}}\alpha_k e^{-\frac{t-t_k}{\lambda_k}}\Bigg[\sum_{i=0}^{k-1}\tau_i
  +(t-t_k)\Bigg]\,dt\\
  &=&\frac{\alpha_k}{C_{\pi}\lambda_k}\Bigg[\sum_{i=0}^{k-1}\tau_i\int_{t_k}^{t_{k+1}}e^{-\frac{t-t_k}{\lambda_k}}dt
  +\int_{t_k}^{t_{k+1}}(t-t_k)e^{-\frac{t-t_k}{\lambda_k}}dt\Bigg]\\
  &=&\frac{\alpha_k}{C_{\pi}\lambda_k}\Bigg[\lambda_k\sum_{i=0}^{k-1}\tau_i\Big(1-e^{-\frac{\tau_k}{\lambda_k}}\Big)
  +\lambda_k^2\int_0^{\frac{\tau_k}{\lambda_k}}ue^{-u}du\Bigg]\\
  &=&\frac{\alpha_k}{C_{\pi}}\Bigg[\sum_{i=0}^{k-1}\tau_i\Big(1-e^{-\frac{\tau_k}{\lambda_k}}\Big)
  +\Big(\lambda_k-\lambda_k e^{-\frac{\tau_k}{\lambda_k}}-\tau_k e^{-\frac{\tau_k}{\lambda_k}}\Big)\Bigg]\\
  &=&\frac{1}{C_{\pi}}\Bigg[(\alpha_k-\alpha_{k+1})\Big(\sum_{i=0}^{k-1}\tau_i+\lambda_k\Big)
  -\alpha_{k+1}\tau_k\Bigg]
\end{eqnarray*}

\begin{eqnarray*}
  \sigma_k&=&\int_{t_k}^{t_{k+1}}\sigma(t)\,dt\\
  &=&\int_{t_k}^{t_{k+1}}\frac{1}{C_{\sigma}(1-e^{-\rho t})}\cdot\frac{t}{C_{\pi}\lambda(t)}
  e^{\int_0^t\frac{dv}{\lambda(v)}}\,dt\\
  &=&\frac{1}{C_{\sigma}C_{\pi}\rho}\int_{t_k}^{t_{k+1}}\Big[1+\frac{1}{2}\rho t+o(\rho^2)\Big]
  \frac{1}{\lambda(t)}e^{\int_0^t\frac{dv}{\lambda(v)}}\,dt\\
  &=&\frac{1}{C_{\sigma}C_{\pi}\rho}\Bigg[\int_{t_k}^{t_{k+1}}\frac{1}{\lambda(t)}e^{\int_0^t\frac{dv}{\lambda(v)}}\,dt
  +\frac{1}{2}C_{\pi}\rho\int_{t_k}^{t_{k+1}}\pi(t)\,dt+o(\rho^2)\Bigg]\\
  &=&\frac{1}{C_{\sigma}}\Bigg[\frac{1}{C_{\pi}\rho}(\alpha_k-\alpha_{k+1})
  +\frac{\pi_k}{2}+o(\rho)\Bigg]
\end{eqnarray*}

\begin{eqnarray*}
  q_{kl}&=&\frac{1}{\pi_k}\int_{t_k}^{t_{k+1}}ds\int_{t_l}^{t_{l+1}}q(t|s)\pi(s)\,dt\\
  &=&\frac{1}{C_{\pi}\pi_k}\int_{t_k}^{t_{k+1}}\frac{1}{\lambda(s)}e^{-\int_0^s\frac{dv}{\lambda(v)}}\,ds
  \int_{t_l}^{t_{l+1}}\frac{dt}{\lambda(t)}\int_0^{\min\{s,t\}}e^{-\int_{u}^{t}\frac{dw}{\lambda(w)}}du\\
  &=&\frac{\alpha_k}{C_{\pi}\pi_k\lambda_k\lambda_l}\int_{t_k}^{t_{k+1}}e^{-\frac{s-t_k}{\lambda_k}}\,ds
  \int_{t_l}^{t_{l+1}}dt\int_0^{\min\{s,t\}}e^{-\int_{u}^{t}\frac{dw}{\lambda(w)}}du
\end{eqnarray*}

$l<k$:
\begin{eqnarray*}
  q_{kl} &=&\frac{\alpha_k-\alpha_{k+1}}{C_{\pi}\pi_k\lambda_l}
  \int_{t_l}^{t_{l+1}}dt\,\Bigg(e^{-\frac{t-t_l}{\lambda_l}}\sum_{i=0}^{l-1}\frac{\alpha_l}{\alpha_i}
  \int_{t_i}^{t_{i+1}}e^{\frac{u-t_i}{\lambda_i}}\,du+\int_{t_l}^{t}e^{-\frac{t-u}{\lambda_l}}\,du\Bigg)\\
  &=&\frac{\alpha_k-\alpha_{k+1}}{C_{\pi}\pi_k\lambda_l}
  \int_{t_l}^{t_{l+1}}dt\,\Bigg[\alpha_le^{-\frac{t-t_l}{\lambda_l}}\sum_{i=0}^{l-1}\lambda_i
  \Big(\frac{1}{\alpha_{i+1}}-\frac{1}{\alpha_i}\Big)+\lambda_l\Big(1-e^{-\frac{t-t_l}{\lambda_l}}\Big)\Bigg]\\
  &=&\frac{\alpha_k-\alpha_{k+1}}{C_{\pi}\pi_k}
  \Big[\Big(1-\frac{\alpha_{l+1}}{\alpha_l}\Big)\beta_l\alpha_l+(t_{l+1}-t_l)-\lambda_l
  \Big(1-\frac{\alpha_{l+1}}{\alpha_l}\Big)\Big]\\
  &=&\frac{\alpha_k-\alpha_{k+1}}{C_{\pi}\pi_k}\Bigg[(\alpha_l-\alpha_{l+1})\Big(\beta_l-\frac{\lambda_l}{\alpha_l}\Big)
  +(t_{l+1}-t_l)\Bigg]
\end{eqnarray*}

$l>k$:
\begin{eqnarray*}
  q_{kl}&=&\frac{\alpha_k}{C_{\pi}\pi_k\lambda_k}\int_{t_k}^{t_{k+1}}e^{-\frac{s-t_k}{\lambda_k}}\,ds\cdot
  (\alpha_l-\alpha_{l+1})\Bigg[\beta_k+\frac{\lambda_k^2}{\alpha_k}\Big(e^{\frac{s-t_k}{\lambda_k}}-1\Big)\Bigg]\\
  &=&\frac{\alpha_k(\alpha_l-\alpha_{l+1})}{C_{\pi}\pi_k\lambda_k}\int_{t_k}^{t_{k+1}}e^{-\frac{s-t_k}{\lambda_k}}\,ds\cdot
  \Bigg[\Big(\beta_k-\frac{\lambda_k}{\alpha_k}\Big)+\frac{\lambda_k}{\alpha_k}e^{\frac{s-t_k}{\lambda_k}}\Bigg]\\
  &=&\frac{\alpha_l-\alpha_{l+1}}{C_{\pi}\pi_k}
  \Bigg[(\alpha_k-\alpha_{k+1})\Big(\beta_k-\frac{\lambda_k}{\alpha_k}\Big)+(t_{k+1}-t_k)\Bigg]
\end{eqnarray*}

$l=k$:
\begin{eqnarray*}
  q_{kl}&=&\frac{\alpha_k}{C_{\pi}\pi_k\lambda_k}\int_{t_k}^{t_{k+1}}e^{-\frac{s-t_k}{\lambda_k}}\,ds\cdot
  \Bigg[\beta_k(\alpha_k-\alpha_{k+1})+(s-t_k)-\frac{\lambda_k\alpha_{k+1}}{\alpha_k}
  \Big(e^{\frac{s-t_k}{\lambda_k}}-1\Big)\Bigg]\\
  &=&\frac{\alpha_k}{C_{\pi}\pi_k}\int_0^{\tau_k}e^{-u}\,du\cdot
  \Bigg[\beta_k(\alpha_k-\alpha_{k+1})+\frac{\lambda_k\alpha_{k+1}}{\alpha_k}
	+\lambda_ku-\frac{\lambda_k\alpha_{k+1}}{\alpha_k}e^u\Bigg]\\
  &=&\frac{1}{C_{\pi}\pi_k}\Bigg[\beta_k(\alpha_k-\alpha_{k+1})^2
  +\frac{\lambda_k}{\alpha_k}(\alpha_k-\alpha_{k+1})(\alpha_k+\alpha_{k+1})-2\tau_k\alpha_{k+1}\Bigg]\\
  &=&\frac{1}{C_{\pi}\pi_k}\Bigg[(\alpha_k-\alpha_{k+1})^2\Big(\beta_k-\frac{\lambda_k}{\alpha_k}\Big)
  +2\lambda_k(\alpha_k-\alpha_{k+1})-2\alpha_{k+1}(t_{k+1}-t_k)\Bigg]
\end{eqnarray*}

\begin{eqnarray*}
  p_{kl}&=&\frac{1}{\sigma_k}\int_{t_k}^{t_{k+1}}ds\int_{t_l}^{t_{l+1}}p(t|s)\sigma(s)\,dt\\
  &=&\frac{1}{\sigma_k}\int_{t_k}^{t_{k+1}}\frac{\pi(s)\,ds}{C_{\sigma}(1-e^{-\rho s})}
  \Bigg[\int_{t_l}^{t_{l+1}}(1-e^{-\rho s})q(t|s)\,dt+\delta_{kl}e^{-\rho s}\Bigg]\\
  &=&\frac{1}{C_{\sigma}\sigma_k}\int_{t_k}^{t_{k+1}}\pi(s)\,ds\int_{t_l}^{t_{l+1}}q(t|s)\,dt
  +\frac{\delta_{kl}}{C_{\sigma}\sigma_k}\int_{t_k}^{t_{k+1}}\Big(\frac{1}{1-e^{-\rho s}}-1\Big)\pi(s)\,ds\\
  &=&\frac{\pi_kq_{kl}}{C_{\sigma}\sigma_k}+\frac{\delta_{kl}}{C_{\sigma}\sigma_k}
  \Bigg[\int_{t_k}^{t_{k+1}}\frac{\pi(s)\,ds}{1-e^{-\rho s}}-\pi_k\Bigg]\\
  &=&\frac{\pi_k q_{kl}}{C_{\sigma}\sigma_k}+\delta_{kl}\Big(1-\frac{\pi_k}{C_{\sigma}\sigma_k}\Big)
\end{eqnarray*}

\end{proof}

\bibliography{psmc}

\end{document}


% !TEX root = ../main.tex

\section{Design and implementation}

\subsection{Pre-process data}
\begin{frame}{\insertsubsec}
  \begin{itemize}
    \item Pre-process image data
    \item Pre-process scalar data
    \item Generate pairs for training
  \end{itemize}

  \vspace{.5cm}
  Only 490 of the initial 671 could be used to fit a model because we needed the following
  requirements:
  \begin{itemize}
    \item CT scan
    \item Tumour annotations
    \item Radiomic features
    \item Clinical information
  \end{itemize}
\end{frame}

\begin{frame}{Image data pre-processing}
  \begin{figure}
    \centering
    \scalebox{.6}{\input{drawings/preprocess.tikz.tex}}
    \caption{Image data pre-processing}
  \end{figure}
\end{frame}

\begin{frame}{Scalar data pre-processing}
  \begin{itemize}
    \item Clinical information
    \begin{itemize}
      \item Patient's ID
      \item Age
      \item Sex
      \item Survival event
      \item Survival time
    \end{itemize}
    \item Radiomic features, up to 725
    \begin{itemize}
      \item Tumour shape
      \item Intensity
      \item Volume
      \item ...
    \end{itemize}
  \end{itemize}
\end{frame}
\begin{frame}
  \begin{figure}
    \centering
    \includegraphics[width=\textwidth]{images/features_original}
    \caption{Features before normalization}
  \end{figure}
\end{frame}
\begin{frame}
  \begin{figure}
    \centering
    \includegraphics[width=\textwidth]{images/features_normalized}
    \caption{Features after normalization}
  \end{figure}
\end{frame}

\begin{frame}{Pair generation}

  \begin{figure}
    \centering
    \scalebox{.7}{\input{drawings/pairs_sets.tikz.tex}}
    \caption{Types of pairs generated from train and test sets}
  \end{figure}

  \begin{block}{Conditions}
    \begin{itemize}
      \item Both of them are uncensored \( E_A = E_B = 1 \)
      \item The uncensored time of one is smaller than the censored time of the other
            \( T_A < T_B | E_A = 1; E_B = 0 \)
    \end{itemize}
  \end{block}
\end{frame}

\subsection{Create basic siamese model}
\begin{frame}{\insertsubsec}
  Step required from a software engineering perspective. Future models should implement the
  \( \operatorname{sister}(x) \) function.
  \begin{figure}
    \scalebox{.7}{\input{drawings/siamese_network.tikz.tex}}
    \caption{Siamese network illustration}
  \end{figure}
\end{frame}
\begin{frame}
  \begin{block}{Sister network}
    \begin{align*}
      \bm{O}_A &= \operatorname{sister}(\bm{X}_A) \\
      \bm{O}_B &= \operatorname{sister}(\bm{X}_B) \\
      \sigma(x) &= \frac{1}{1 + \exp(-x)} \\
      \hat{y} &= \sigma(||\bm{O}_B||_2 - ||\bm{O}_A||_2)
    \end{align*}
  \end{block}

  \begin{block}{Loss function}
    \[
      \mathcal{L}(\bm{y}, \hat{\bm{y}}) = -\frac{1}{N} \sum_{i = 1}^{N}
      (1 - y_i)\log(1 - \hat{y}_i) + y_i\log(\hat{y}_i)
    \]
  \end{block}

  \begin{block}{Cost function}

    \[
      C(\bm{y}, \hat{\bm{y}}) = \mathcal{L}(\bm{y}, \hat{\bm{y}}) +
      ||\bm{w}||_2
    \]
  \end{block}
\end{frame}

\subsection{Build volume only model}
\begin{frame}{\insertsubsec}
  Very simple model to have a baseline

  \[
    \operatorname{sister}(\bm{X}) = w\cdot X_{\text{scalar}_{26}} + b
  \]

  \begin{block}{Train parameters}
    \begin{itemize}
      \item Learning rate: 0,05
      \item Number of epochs: 200
      \item Batch size: The whole dataset
    \end{itemize}
  \end{block}
\end{frame}
\begin{frame}
  Previous state-of-the-art CI was 0,628.

  \begin{table}
    \centering
    \begin{tabular}{|c||c|c|c||c|c|c|}
      \cline{2-7}
      \multicolumn{1}{c|}{} & \multicolumn{3}{|c||}{\textbf{Pairs}} &
      \multicolumn{3}{c|}{\textbf{Concordance Index}} \\
      \hline
      \textbf{Fold} & \textbf{Mixed} & \textbf{Train} & \textbf{Test}
      & \textbf{Mixed} & \textbf{Train} & \textbf{Test} \\
      \hhline{=======}
      0 & 16.359 & 46.804 & 5.330 & 0,627 & 0,634 & 0,639 \\
      1 & 16.359 & 46.957 & 5.278 & 0,629 & 0,635 & 0,63 \\
      2 & 16.348 & 47.577 & 5.084 & 0,636 & 0,627 & 0,661 \\
      3 & 16.348 & 47.274 & 5.176 & 0,618 & 0,644 & 0,6 \\
      \hhline{=======}
      \textbf{Total} & 65.414 & 188.612 & 20.868 & 0,627 & 0,635 & 0,632 \\
      \hline
    \end{tabular}

    \caption[Volume Only 4-CV results]{
      Results for volume only model using 4-CV \label{tab:results-volume-4CV}
    }
  \end{table}
\end{frame}

\begin{frame}
  \begin{figure}
    \centering
    \includegraphics[width=.8\textwidth]{images/results/c-index_volume}
    \caption[LOOCV volume only model results]{
      Volume only model results using LOOCV \label{fig:results-volume-LOOCV}
    }
  \end{figure}
  LOOCV CI is 0,627.
\end{frame}

\subsection{Build shallow siamese network}
\begin{frame}{\insertsubsec}
  \begin{figure}
    \centering
    \scalebox{.7}{\input{drawings/siamese_0.tikz.tex}}
    \caption{Shallow siamese sister's network illustration \label{fig:shallow-implement}}
  \end{figure}
\end{frame}

\begin{frame}
  \begin{itemize}
    \item Learning rate: 0,05
    \item Number of epochs: 200
    \item Batch size: The whole dataset
  \end{itemize}

  \begin{table}
    \centering
    \begin{tabular}{|c||c|c|c||c|c|c|}
      \cline{2-7}
      \multicolumn{1}{c|}{} & \multicolumn{3}{|c||}{\textbf{Pairs}} &
      \multicolumn{3}{c|}{\textbf{Concordance Index}} \\
      \hline
      \textbf{Fold} & \textbf{Mixed} & \textbf{Train} & \textbf{Test} &
      \textbf{Mixed} & \textbf{Train} & \textbf{Test} \\
      \hhline{=======}
      0 & 65.436 & 187.216 & 21.320 & 0,43 & 0,42 & 0,419 \\
      1 & 65.436 & 187.828 & 21.112 & 0,444 & 0,431 & 0,459 \\
      2 & 65.392 & 190.308 & 20.336 & 0,472 & 0,474 & 0,426 \\
      3 & 65.392 & 189.096 & 20.704 & 0,514 & 0,512 & 0,514 \\
      \hhline{=======}
      \textbf{Total} & 261.656 & 754.448 & 83.472 & 0,465 & 0,459 & 0,455 \\
      \hline
    \end{tabular}

    \caption[Shallow 4-CV results]{
      Results for shallow model using 4-CV \label{tab:results-shallow-4CV}.
    }
  \end{table}
\end{frame}

\subsection{Build scalar only siamese network}
\begin{frame}{\insertsubsec}
  \begin{figure}
    \centering
    \input{drawings/scalar_0.tikz.tex}
    \caption{Scalar siamese network illustration \label{fig:scalar-implement}}
  \end{figure}
\end{frame}

\begin{frame}
  \begin{itemize}
    \item Learning rate: 0,001
    \item Regularization factor: 0,01
    \item Dropout probability: 20\%
    \item Number of epochs: 1000
    \item Batch size: The whole dataset
  \end{itemize}

  \begin{table}
    \centering
    \begin{tabular}{|c||c|c|c||c|c|c|}
      \cline{2-7}
      \multicolumn{1}{c|}{} & \multicolumn{3}{|c||}{\textbf{Pairs}} &
      \multicolumn{3}{c|}{\textbf{Concordance Index}} \\
      \hline
      \textbf{Fold} & \textbf{Mixed} & \textbf{Train} & \textbf{Test} &
      \textbf{Mixed} & \textbf{Train} & \textbf{Test} \\
      \hhline{=======}
      0 & 16.359 & 46.804 & 5.330 & 0,728 & 0,915 & 0,543 \\
      1 & 16.359 & 46.957 & 5.278 & 0,809 & 0,927 & 0,64 \\
      2 & 16.348 & 47.577 & 5.084 & 0,751 & 0,91 & 0,675 \\
      3 & 16.348 & 47.274 & 5.176 & 0,766 & 0,919 & 0,624 \\
      \hhline{=======}
      \textbf{Total} & 65.414 & 188.612 & 20.868 & 0,764 & 0,918 & 0,62   \\
      \hline
    \end{tabular}

    \caption[Scalar Only 4-CV results]{
      Results for scalar only model using 4-CV \label{tab:results-scalar-4CV}
    }
  \end{table}
\end{frame}

\begin{frame}
  \begin{figure}
    \centering
    \includegraphics[width=.8\textwidth]{images/results/c-index_scalar}
    \caption[LOOCV scalar only model results]{
      Scalar only model results using LOOCV \label{fig:results-scalar-LOOCV}
    }
  \end{figure}

  Final CI is 0,771
\end{frame}

\subsection{Build deep siamese network}
\begin{frame}{\insertsubsec}
  \begin{figure}
    \centering
    \scalebox{.7}{\input{drawings/residual_general.tikz.tex}}
    \caption[Deep siamese network main structure]{
      Deep siamese network main structure \label{fig:residual-general}
    }
  \end{figure}
\end{frame}

\begin{frame}
  \begin{itemize}
    \item Learning rate: 0,001
    \item Regularization factor: 0,01
    \item Dropout probability: 0,2/1
    \item Number of epochs: 15
    \item Batch size: 20
  \end{itemize}

  \begin{table}
    \centering
    \begin{tabular}{|c||c|c|c||c|c|c|}
      \cline{2-7}
      \multicolumn{1}{c|}{} & \multicolumn{3}{|c||}{\textbf{Pairs}} &
      \multicolumn{3}{c|}{\textbf{Concordance Index}} \\
      \hline
      \textbf{Fold} & \textbf{Mixed} & \textbf{Train} & \textbf{Test} &
      \textbf{Mixed} & \textbf{Train} & \textbf{Test} \\
      \hhline{=======}
      0 & 65.436 & 187.216 & 21.320 & 0,765 & 0,812 & 0,814 \\
      1 & 65.436 & 187.828 & 21.112 & 0,821 & 0,813 & 0,813 \\
      2 & 65.392 & 190.308 & 20.336 & 0,427 & 0,431 & 0,387 \\
      3 & 65.392 & 189.096 & 20.704 & 0,389 & 0,359 & 0,428 \\
      \hhline{=======}
      \textbf{Total} & 261.656 & 754.448 & 83.472 & 0,601 & 0,603 & 0,614 \\
      \hline
    \end{tabular}

    \caption[Residual 4-CV results]{
      Results for residual model using 4-CV \label{tab:results-residual-4CV}
    }
  \end{table}
\end{frame}

\begin{frame}
  \begin{figure}
    \centering
    \includegraphics[width=\textwidth]{images/results/residual_train}

    \caption{Training iterations CI
      \label{fig:results-residual-CI}
    }
  \end{figure}
\end{frame}

\subsection{Predict patient's survival}

\begin{frame}{\insertsubsec}
  Comparison function \( T_A < T_B \) gives a correct result 76,4 \% of the time.
  \begin{figure}
    \centering
    \includegraphics[width=.5\textwidth]{images/results/survival_scalar}

    \caption{Confusion matrix for survival classification}
  \end{figure}

  Final accuracy is 60\% (106 / 178)
\end{frame}