\subsubsection{ComparisonStatistics}
\label{ComparisonStatistics}
The \textbf{ComparisonStatistics} post-processor computes statistics
for comparing two different dataObjects.  This is an experimental
post-processor, and it will definitely change as it is further
developed.

There are four nodes that are used in the post-processor.

\begin{itemize}
\item \xmlNode{kind}: specifies information to use for comparing the
  data that is provided.  This takes either uniformBins which makes
  the bin width uniform or equalProbability which makes the number
  of counts in each bin equal.  It can take the following attributes:
  \begin{itemize}
  \item \xmlAttr{numBins} which takes a number that directly
    specifies the number of bins
  \item \xmlAttr{binMethod} which takes a string that specifies the
    method used to calculate the number of bins.  This can be either
    square-root or sturges.
  \end{itemize}
\item \xmlNode{compare}: specifies the data to use for comparison.
  This can either be a normal distribution or a dataObjects:
  \begin{itemize}
  \item \xmlNode{data}: This will specify the data that is used.  The
    different parts are separated by $|$'s.
  \item \xmlNode{reference}: This specifies a reference distribution
    to be used.  It takes distribution to use that is defined in the
    distributions block.  A name parameter is used to tell which
    distribution is used.
  \end{itemize}
\item \xmlNode{fz}: If the text is true, then extra comparison
  statistics for using the $f_z$ function are generated.  These take
  extra time, so are not on by default.
\item \xmlNode{interpolation}: This switches the interpolation used
  for the cdf and the pdf functions between the default of quadratic
  or linear.
\end{itemize}

The \textbf{ComparisonStatistics} post-processor generates a variety
of data.  First for each data provided, it calculates bin boundaries,
and counts the numbers of data points in each bin.  From the numbers
in each bin, it creates a cdf function numerically, and from the cdf
takes the derivative to generate a pdf.  It also calculates statistics
of the data such as mean and standard deviation. The post-processor
can generate a CSV file only.

The post-processor uses the generated pdf and cdf function to
calculate various statistics.  The first is the cdf area difference which is:
\begin{equation}
  cdf\_area\_difference = \int_{-\infty}^{\infty}{\|CDF_a(x)-CDF_b(x)\|dx}
\end{equation}
This given an idea about how far apart the two pieces of data are, and
it will have units of $x$.

The common area between the two pdfs is calculated.  If there is
perfect overlap, this will be 1.0, if there is no overlap, this will
be 0.0.  The formula used is:
\begin{equation}
  pdf\_common\_area = \int_{-\infty}^{\infty}{\min(PDF_a(x),PDF_b(x))}dx
\end{equation}

The difference pdf between the two pdfs is calculated.  This is calculated as:
\begin{equation}
  f_Z(z) = \int_{-\infty}^{\infty}f_X(x)f_Y(x-z)dx
\end{equation}
This produces a pdf that contains information about the difference
between the two pdfs.  The mean can be calculated as (and will be
calculated only if fz is true):
\begin{equation}
  \bar{z} = \int_{-\infty}^{\infty}{z f_Z(z)dz}
\end{equation}
The mean can be used to get an signed difference between the pdfs,
which shows how their means compare.

The variance of the difference pdf can be calculated as (and will be
calculated only if fz is true):
\begin{equation}
  var = \int_{-\infty}^{\infty}{(z-\bar{z})^2 f_Z(z)dz}
\end{equation}

The sum of the difference function is calculated if fz is true, and is:
\begin{equation}
  sum = \int_{-\infty}^{\infty}{f_z(z)dz}
\end{equation}
This should be 1.0, and if it is different that
points to approximations in the calculation.

\textbf{Example:}
\begin{lstlisting}[style=XML]
<Simulation>
   ...
   <Models>
      ...
      <PostProcessor name="stat_stuff" subType="ComparisonStatistics">
      <kind binMethod='sturges'>uniformBins</kind>
      <compare>
        <data>OriData|Output|tsin_TEMPERATURE</data>
        <reference name='normal_410_2' />
      </compare>
      <compare>
        <data>OriData|Output|tsin_TEMPERATURE</data>
        <data>OriData|Output|tsout_TEMPERATURE</data>
      </compare>
      </PostProcessor>
      <PostProcessor name="stat_stuff2" subType="ComparisonStatistics">
        <kind numBins="6">equalProbability</kind>
        <compare>
          <data>OriData|Output|tsin_TEMPERATURE</data>
        </compare>
        <Distribution class='Distributions' type='Normal'>normal_410_2</Distribution>
      </PostProcessor>
      ...
   </Models>
   ...
   <Distributions>
      <Normal name='normal_410_2'>
         <mean>410.0</mean>
         <sigma>2.0</sigma>
      </Normal>
   </Distributions>
</Simulation>
\end{lstlisting}


\documentclass[12pt]{article}

\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{hyperref}

% This section ^^ is called a preample. Sometimes you need a ton of packages. Some Authors use like 400. Which is too stressful so I'm not including them.

\title{LaTeX Template}
\author{Matt Gonzalez}
\date{August 2021}

\begin{document}
\maketitle

\section{Introduction}
The following document provides a LaTeX template along with some comments/descriptions in the actual ``.tex'' Document

% Note that quotes need to be entered as follows: ``LaTeX is dumb'' as opposed to "LaTeX is dumb"

\subsection{Notes}
Here we use a subsection. \footnote{This is a footnote}

\section{Equations}

Here's an equation:

\begin{equation}
	\sum_{i=1}^N 2x +4
\end{equation}

Here's an inline equation $2+2=\beta$

\section{Bullets}

\begin{itemize}
	\item{Bullet points are fun}
	\item{\href{https://tex.stackexchange.com/} {stackX}}
	\item{\href{https://www.overleaf.com/learn/latex/Hyperlinks}{overleaf}}
\end{itemize}

\clearpage
% note that \newpage is also sufficient.

\section{Tables}

The next section shows basic table stuff. Use Stargazer and copy/paste. Or use Stata. Sometimes use a \href{https://www.tablesgenerator.com/}{table generator}: They get tricky and annoying

\begin{table}[!htbp] \centering
 \caption{Description of Missing Observations by Variable} % caption is table title
 \label{}  % lable is for referencing in other parts of document
\begin{tabular}{@{\extracolsep{5pt}} lcc} % lcc is alignment of columns (left, center, center
\\[-1.8ex]\hline
\hline \\[-1.8ex]  % hline is a horizontal line
 Variables & Total Missing & Missing (\%)\\
\hline \\[-1.8ex]
Apples & $0$ & $0$ \\  % note the use of \\ (means newline)
\hline\hline
\multicolumn{3}{c}{%
 \begin{minipage}{12cm}%
\smallskip % This notes format was annoying to figure out...copy it
\footnotesize{ \textit{Notes:} This is a caption} %
 \end{minipage}%
}\\
\end{tabular}
\end{table}

\end{document}


\section{Results and Discussion}
As has been mentioned, 10 test runs were executed. Each run entailed running the genetic algorithm with a different set of seeds. The best individual fitness, number of hits, mean squared error and runtime for each of the 10 runs are detailed in table \ref{tab:test_results}. To clarify, a single hit is a day for which the prediction of the best individual was within an average of 5\% of the actual cases, deaths or recoveries.

\begin{table}[H]
\resizebox{\textwidth}{!}{\begin{tabular}{|c|c|c|c|c|}
\hline
\textbf{Run} & \textbf{Best Individual Fitness} & \textbf{Number of Hits} & \textbf{Mean Squared Error} & \textbf{Runtime} \\ \hline
1            & 0.16981653012815615              & 11                      & 0.02884                     & 0m56.559s        \\ \hline
2            & 0.11708801796762536              & 18                      & 0.01371                     & 5m46.942s        \\ \hline
3            & 0.07924233842929927              & 39                      & 0.00628                     & 7m59.488s        \\ \hline
4            & 0.10260196769743599              & 36                      & 0.01053                     & 7m38.561s        \\ \hline
5            & 0.09179369543784227              & 33                      & 0.00843                     & 5m31.616s        \\ \hline
6            & 0.14551612276194176              & 10                      & 0.02117                     & 2m17.149s        \\ \hline
7            & 0.08699608922920267              & 49                      & 0.00757                     & 3m9.732s         \\ \hline
8            & 0.10736871065116832              & 22                      & 0.01153                     & 2m56.155s        \\ \hline
9            & 0.11435758695560931              & 21                      & 0.01308                     & 2m5.639s         \\ \hline
10           & 0.1395859048040605               & 14                      & 0.01948                     & 3m45.321s        \\ \hline
\end{tabular}}
\caption{Test Results}
\label{tab:test_results}
\end{table}

As can be derived from the results, the best mean squared error was 0.00628; the average mean squared error was 0.01354; the best fitness was 0.07924 and, lastly the average fitness was 0.10971.

When compared to the results of genetic programming approaches that were used to solve similar time-series problems \cite{hui2003using, de2005genetic} the results of these tests also indicate the effectiveness of the approach to perform time series predictions. Given the short run times, limited generations and relatively small population size the algorithm produced a function that could predict test data within a 7\% accuracy on average.

An area of concern, however, is that the functions produced have not yet been used for cross-validation. A part of the data set that could be used for cross validation has been separated as part of this assignment but performing the cross-validation has been left as an area for future work.


%%\documentclass[handout]{beamer}
%\documentclass[aspectratio=169,13pt]{beamer}

%\input{./preamble}

\subtitle{Partial Differential Equations}

\date{}
\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\section{Types and Applications of PDEs}
\begin{frame}{Partial Differential Equations}

\begin{itemize}
\item \coloremph{Partial differential equations (PDEs)} describe physical laws and other continuous phenomena:

\lgcond{
\begin{itemize}
\item They contain partial derivatives in multiple variables.
\mitem Examples include: electromagnetism, fluid flow, quantum mechanics, and general relativity.
\end{itemize}
}

\item The \coloremph{advection PDE} describes basic phenomena in fluid flow,
\[u_t = -a(t,x)u_x\]
where $u_t=\dee u/\dee t$ and $u_x=\dee u/\dee x$.

\lgcond{
\begin{itemize}
\item Generally, we impose an initial condition with respect to $t$, i.e., $u(0,x)=u_0(x)$.
\mitem \coloremph{Boundary conditions} are also often exposed on boundary of domain.
\mitem When $a(t,x)=c$ this is the \coloremph{Cauchy problem} with solution,
\[u(t,x)=u_0(x-ct).\]
\end{itemize}
}

\end{itemize}
\end{frame}

\begin{frame}{Types of PDEs}
\urcornerlinkdemo{11-sparse-matrices-pdes}{Time-dependent PDEs}

\begin{itemize}
\item Some of the most important PDEs are \coloremph{second order}:

\lgcond{
\begin{itemize}
\item Heat equation (diffusion), $u_t=u_{xx}$
\item Wave equation (oscillation), $u_{tt}=u_{xx}$
\item Laplace equation (steady-state), $u_{xx}+u_{yy}=0$
\end{itemize}
Any PDE of the form
\[au_{xx}+bu_{xy}+cu_{yy}+du_x+eu_y+fu+g=0\]
behaves (has the character) of one of the above equations.
}

\item The \coloremph{discriminant} determines the canonical form of second-order PDEs:

\lgcond{
The discriminant is $r=b^2-4ac$ and linear PDEs are classified as
\[\begin{cases}
  r>0 &: \text{\coloremph{hyperbolic}, wave-equation-like} \\
  r=0 &: \text{\coloremph{parabolic}, heat-equation-like} \\
  r<0 &: \text{\coloremph{elliptic}, Laplace-equation-like}
  \end{cases} \]
When coefficients are varying, a PDE may exhibit different behavior in different parts of the domain.
%These cases are insufficient to describe all PDEs (higher order and systems of PDEs can be very different),
%This characterization of the behavior (which may be different in different parts of the domain) of the bulk of typical PDE problems.
}

\end{itemize}

\end{frame}

\section{Hyperbolic and Parabolic PDEs}
\subsection{Characteristics}
\begin{frame}{Characteristic Curves}

\begin{itemize}
\item A \coloremph{characteristic} of a PDE is a level curve in the solution:
\lgcond{
\begin{itemize}
\item For the Cauchy form of the advection equation, $u_t=-cu_x$, a characteristic $\hat{x}(t)$ satisfies $u(t,\hat{x}(t))=\text{const}$.
\mitem One of their uses is identifying where boundary conditions must be imposed, e.g. for the Cauchy equation, it tells us whether boundary conditions are needed on the left or the right (in terms of $x$) of the domain.
\end{itemize}
}
\item More generally, characteristic curves describe curves in the solution field $u(t,x)$ that correspond to solutions of ODEs, e.g. for $u_t = -a(t,x)u_x$ with $u(0,x)=u_0(x)$,
\lgcond{
\[\hat{x}'(t) = -a(t,\hat{x}(t)) \text{ with initial condition } \hat{x}(0)=x_0.\]
These characteristic curves give solutions $\hat{u}(t,x)=u_0(\hat{x}(t))$, which satisfy the advection PDE $u_t = -a(t,x)u_x$, since
\[\hat{u}_t =\hat{x}'(t)u_0'(\hat{x}(t)) = -a(t,x)u_0'(\hat{x}(t)) = -a(t,x)\hat{u}_x.\]
%$u_x^{(0)}(\hat{x}(t))a(t,\hat{x}(t))=a(t,x)u_0'(h\hat{x}(t))$
}
\end{itemize}

%\item The order of a PDE is the highest-order of any partial derivative appearing in the PDE:
%
%\lgcond{
%\begin{itemize}
%\item The advection equation is a first order PDE.
%\mitem PDEs containing e.g. $u_{xy}$ or $u_{tt}$ are second order.
%\end{itemize}
%}
%\end{itemize}

\end{frame}

\subsection{Semidiscrete Methods}

\begin{frame}{Method of Lines}

\begin{itemize}
\item \coloremph{Semidiscrete methods} obtain an approximation to the PDE by solving a system of ODEs.
      Consider the heat equation,
      \[u_t = cu_{xx} \text{ on } 0 \leq x \leq 1, \quad u(0,x)=f(x), u(t,0)=u(t,1)=0.\]
\vspace*{-.2in}
\lgcond{
\begin{itemize}
\item
We discretize over $x$ and use finite differences to approximate
\[u_{xx} \approx  \frac{u(t,x_{i+1}) - 2u(t,x_i) + u(t,x_{i-1})}{(\Delta x)^2}.\]
\item
This approximation yields a system of ODE IVPs, where $y_i(t)\approx u(t,x_i)$,
\[y'_i(t) = \frac{c}{(\Delta x)^2}\Big(y_{i+1}(t) - 2y_{i}(t) + y_{i-1}(t)\Big), \quad y_i(0) = f(x_i).\]
\item
In vector form, we obtain a linear constant-coefficient ODE,
\(\B y'(t) = \B A \B y(t),\)
where $\B A$ is tridiagonal.
\end{itemize}
% with $a_{ii} = -2, a_{i,i+1}=a_{i+1,i}=1$.
}
\smcond{}
\item This \coloremph{method of lines} often yields a stiff ODE:

\mdcond{
\begin{itemize}
\item
The eigenvalues of $\B A$ are in $[-4c/(\Delta x)^2,0]$, which gives stiff ODE for $\Delta x\ll 1$.
\sitem
Heat dissipates very rapidly when concentrated, but slowly overall.
\end{itemize}
}

\end{itemize}

\end{frame}

\begin{frame}{Semidiscrete Collocation}

\begin{itemize}
\item Instead of finite-differences, we can express $u(t,x)$ in a spatial basis $\phi_1(x),\ldots,\phi_n(x)$ with time-dependent coefficients $\alpha_1(t),\ldots,\alpha_n(t)$:

\lgcond{
\[u(t,x) \approx v(t,x,\B \alpha(t)) = \sum_{j=1}^n \alpha_j(t) \phi_j(x)\]
\coloremph{Semidiscrete collocation} methods then ensure the approximation is exact on $x_1,\ldots, x_n$, yielding system of ODEs.
}

\item For the heat equation $u_t=cu_{xx}$, we obtain a linear constant-coefficient vector ODE:

\lgcond{
\[\sum_{j=1}^n \frac{\dee \alpha_j}{\dee t}(t)\underbrace{\phi_j(x_i)}_{m_{ij}} = c \sum_{j=1}^n \alpha_j(t)\underbrace{\frac{\dee^2 \phi_j}{\dee x^2}(x_i)}_{n_{ij}}\]
written in matrix form,
\[\B \alpha'(t) = c\B M^{-1} \B N\B \alpha(t)\]
}

\end{itemize}

\end{frame}

\subsection{Fully Discrete Methods for PDEs}

\begin{frame}{Fully Discrete Methods}

\begin{itemize}
\item Generally, both time and space dimensions are discretized, either by applying an ODE solver to a semidiscrete method or using finite differences.

\begin{itemize}
\atsmcond{
\item
Again consider the heat equation $u_t=c u_{xx}$ and discretize so $u^{(k)}_i \approx u(t_k,x_i)$,
}
\lgcond{
\[\frac{u_i^{(k+1)} - u_i^{(k)}}{\Delta t} = c\frac{u_{i+1}^{(k)}-2u_i^{(k)}+u^{(k)}_{i-1}}{(\Delta x)^2}.\]
}
\atsmcond{
\item This iterative scheme corresponds to a 3-point \coloremph{stencil},
}
\lgcond{
\[u_i^{(k+1)} = u_i^{(k)} + c\Delta t\frac{u_{i+1}^{(k)}-2u_i^{(k)}+u^{(k)}_{i-1}}{(\Delta x)^2}.\]
\item
The same scheme can be derived by applying Euler's method to the ODE given by the method of lines.
}
\end{itemize}
\lgcond{}

\end{itemize}

\end{frame}

\begin{frame}{Implicit Fully Discrete Methods}

\begin{itemize}
\item Using Euler's method for the heat equation, stability requirement is
\tmdcond{
\[\Delta t=O\big((\Delta x)^2\big)\]
}
\item This step-size restriction on stability can be circumvented by use of implicit time-stepper, such as backward Euler,
\tmdcond{
\[u_i^{(k+1)} = u_i^{(k)} + c\Delta t\frac{u_{i+1}^{(k+1)}-2u_i^{(k+1)}+u^{(k+1)}_{i-1}}{(\Delta x)^2}.\]
This scheme requires for a tridiagonal matrix system to be solved at each time-step, but obtains unconditional stability, albeit only first-order accuracy.
}
\item Using the trapezoid method to solve the ODE we obtain the second-order \coloremph{Crank-Nicolson method},
\tmdcond{
\[u_i^{(k+1)} = u_i^{(k)} + c\Delta t\frac{u_{i+1}^{(k+1)}-2u_i^{(k+1)}+u^{(k+1)}_{i-1}+u_{i+1}^{(k)}-2u_i^{(k)}+u^{(k)}_{i-1}}{2(\Delta x)^2}.\]
}
\end{itemize}

\end{frame}

\subsection{Convergence Criteria}

\begin{frame}{Convergence and Stability}

\begin{itemize}
\item \coloremph{Lax Equivalence Theorem}: consistency + stability = convergence

\algcond{
\begin{itemize}
\item
Consistency means that the local truncation error goes to zero, and is easy to verify by Taylor expansions.
\mitem
Stability implies that the approximate solution at any time $t$ must remain bounded.
\mitem
Together these conditions are necessary and sufficient for convergence.
\end{itemize}
}

\item Stability can be ascertained by spectral or Fourier analysis:

\algcond{

\begin{itemize}
\item
In the method of lines, we saw that the eigenvalues of the resulting ODE define the stability region.
\mitem
Fourier analysis decomposes the solution into a sum of harmonic functions and bounds their amplitudes.
\end{itemize}
}
\end{itemize}
\end{frame}

\begin{frame}{CFL Condition}

\begin{itemize}
\item The domain of dependence of a PDE for a given point $(t,x)$ is the portion of the problem domain influencing this point through the PDE:

\lgcond{
\begin{itemize}
\item
Generally determined by characteristics of PDE.
\mitem
For a stencil method, the numerical solution depends on the set of mesh-points influencing the mesh point at $(t,x)$.
\end{itemize}
}

\item \coloremph{The Courant, Friedrichs, and Lewy (CFL) condition} states that for an explicit finite-differencing scheme to be stable for a hyperbolic PDE, it is necessary that the domain of the dependence of the PDE must be contained in the domain of dependence of the scheme:

\lgcond{
Intuitively, we can then achieve stability for fixed $\Delta t$ in two ways,
\begin{itemize}
\mitem by choosing a sufficiently large grid spacing $\Delta x$, or
\mitem including more mesh points in our stencil.
\end{itemize}
}

\end{itemize}
\end{frame}

\section{Elliptic PDEs}

\subsection{Discretization}

\begin{frame}{Time-Independent PDEs}

\begin{itemize}
\item We now turn our focus to time-independent PDEs as exemplified by the \coloremph{Helmholtz equation}:
\[u_{xx} + u_{yy} +\lambda u = f(x,y)\]

\lgcond{
\begin{itemize}
\item $\lambda=0$ yields the Poisson equation.
\mitem $\lambda=0$ and $f=0$ yields the Laplace equation.
\mitem Boundary conditions (e.g. Dirichlet or Neumann or mixed) are imposed on domain surface.
\end{itemize}
}

\item We discretize as before, but no longer perform time stepping:

\lgcond{
For example given a domain $[0,1]^2$, we can
\begin{itemize}
\sitem tile it using $n\times n$ mesh points,
\mitem setup finite-difference equations on interior,
\mitem setup boundary-condition equations on perimeter.
\end{itemize}
}

\end{itemize}
\end{frame}

\begin{frame}{Finite-Differencing for Poisson}

\begin{itemize}
\item Consider the Poisson equation with equispaced mesh-points on $[0,1]$:

\lgcond{
\begin{itemize}
\item
If $\B u$ is a vector containing the mesh-points, we have that
\[\mathcal{D}_x \B u + \mathcal{D}_y \B u = \B b \text{ where } b_i=f(u_i)\]
where $\mathcal{D}_x$ and $\mathcal{D}_y$ are finite-difference operators along $x$ and $y$ dimensions, respectively.
\mitem
Given a differencing matrix $\B D$ (e.g. tridiagonal with $1,-2,1$), we obtain the matrix equation,
\[(\B I \otimes \B D + \B D \otimes \B I)\B u = \B b\]
where the \coloremph{Kronecker product} is defined as
\[\B C = \B A \otimes \B B = \begin{bmatrix} a_{11} \B B & a_{12} \B B & \cdots \\ a_{21} \B B & \ddots & \\ \vdots & & \end{bmatrix},\]
and the elements of $\B b$ contain the mesh elements in column-major (or row-major in this example) order.
\end{itemize}
}
\lgcond{}

\end{itemize}
\end{frame}

\begin{frame}{Multidimensional Finite Elements}

\begin{itemize}
\item There are many ways to define localized basis functions, for example in the 2D FEM method\footnote{\tiny Source: Comsol Multiphysics Cyclopedia \url{https://www.comsol.com/multiphysics/finite-element-method}}:

{

\centering

\includegraphics[width=2.8in]{diagrams/base-functions-overlap}

}

\lgcond{
We partition the domain into triangles (elements) and define linear basis functions that are $1$ at the intersection of three or more elements (nodes).
}
\end{itemize}

\end{frame}

\subsection{Sparse Direct Methods}
%\end{document}

\begin{frame}{Sparse Linear Systems}

\begin{itemize}
\item Finite-difference and finite-element methods for time-independent PDEs give rise to sparse linear systems:

\begin{itemize}
\asmcond{
\item typified by the 2D Laplace equation, where for both finite differences and FEM,
}
\lgcond{
  \[\underbrace{(\B I \otimes \B T + \B T \otimes \B I)}_{\B A} \B x = \B b \quad \text{where} \quad \B T = \frac{1}{h^2}\begin{bmatrix} -2 & 1 & \\ 1 & \ddots & \ddots \\ & \ddots & \end{bmatrix}\]
\item often have $O(1)$ nonzeros per row/column of the matrix,
\item for simple/regular problems matrices are near-\coloremph{Toeplitz} (same entry along each (sub/super)diagonal), permitting fast solvers via e.g. FFT.
}
\end{itemize}

\item \coloremph{Direct methods} apply LU or other factorization to $\B A$, while \coloremph{iterative methods} refine $\B x$ by minimizing $\B r = \B A\B x-\B b$, e.g. via Krylov subspace methods.

\lgcond{
\begin{itemize}
\item Direct methods provide a high-accuracy solution, but may not be effective at leveraging sparsity to reduce cost.
\item Iterative methods effectively leverage sparsity by computing matrix-vector products with $\B A$, but may require many iterations to achieve high-accuracy.
\end{itemize}
}

\end{itemize}
\end{frame}

\begin{frame}{Direct Methods for Sparse Linear Systems}

\begin{itemize}
\item It helps to think of $\B A$ as the adjacency matrix of graph $G=(V,E)$ where $V=\{1,\ldots\,n\}$ and $a_{ij}\neq 0$ if and only if $(i,j)\in E$:

\lgcond{
\begin{itemize}
\item The graph is invariant to permutation of vertices by permutation matrix $\B P$.
\mitem  Reordering $V$ accordingly transforms the adjacency matrix into $\B P^T \B A \B P$.
\mitem Such reorderings of variables essentially do not change the linear system,
\[\B P^T\B A \B P \underbrace{\B P^T \B x}_{\B{\hat{x}}} = \B b.\]
\end{itemize}
}
\item Factorizing the $l$th row/column in Gaussian elimination corresponds to removing node $i$, with nonzeros (new edges) introduces for each $k,l$ such that $(i,k)$ and $(i,l)$ are in the graph.

\lgcond{
\begin{itemize}
\item Creates clique (fully connected subgraph) among neighbors of vertex $i$.
\mitem Different orderings of vertices can result in radically different amounts of fill.
\mitem Finding optimal ordering to reduce fill is NP complete.
\end{itemize}
}

\end{itemize}
\end{frame}

\begin{frame}{Vertex Orderings for Direct Methods}

\urcornerlinkdemo{11-sparse-matrices-pdes}{Sparse Matrix Factorizations and Fill-In}

\begin{itemize}
\item Select the node of minimum degree at each step of factorization:

\mdcond{
Each step minimizes work, but not necessarily amount of fill at that step (depends on whether neighbors are already connected).
}

\item Graph partitioning also serves to bound fill, remove vertex separator $S \subset V$ so that $V \setminus S = V_1 \cup \cdots \cup V_k$ become disconnected, then order $V_1,\ldots,V_k, S$:

\lgcond{
Matrix takes on the form
\[\B A = \begin{bmatrix} \B{A}_{11} & & & \B{A}_{1S} \\ & \ddots & & \vdots \\ & & \B{A}_{kk} & \B{A}_{kS}\\ \B{A}_{S1} & \cdots & \B{A}_{Sk} & \B{A}_{SS} \end{bmatrix}\]
where each $\B{A}_{ii}$ for $i\in\{1,\ldots,k\}$ can be factored independently.
}

\item \coloremph{Nested dissection} ordering partitions graph into halves recursively, ordering each separator last.

\lgcond{

}

\end{itemize}
\end{frame}

\subsection{Sparse Iterative Methods}

\begin{frame}{Sparse Iterative Methods}

\begin{itemize}
\item Sparse iterative methods avoid overhead of fill in sparse direct factorization. \coloremph{Matrix splitting} methods provide the most basic iterative methods:

\lgcond{
\begin{itemize}
\item
These are linear fixed point iterations that solve the linear system:
\[\B M\B{x}_{k+1} = \B N\B x_k + \B b\]
\item The fixed point function is
\[\B g(\B x) = \B M^{-1}\B N \B x + \B M^{-1} \B b.\]
\item
We desire to have a fixed point whenever $\B A \B x = \B b$, which implies
\[\B M \B x = \B N \B x + \B A \B x.\]
\item Generally, $\B M$ and $\B N$ are chosen so that $\B M- \B N = \B A$.
\mitem To achieve convergence we need $\rho(\B g) = \rho(\B M^{-1}\B N)<1$.
\end{itemize}
}

\end{itemize}
\end{frame}

\begin{frame}{Sparse Iterative Methods}

\begin{itemize}

\item The \coloremph{Jacobi method} is the simplest iterative solver:

\lgcond{
\begin{itemize}
\item
We split up $\B A = \B D +\B L +\B U$ where $\B D$ is diagonal while $\B L$ and $\B U^T$ are strictly lower triangular.
\mitem
Jacobi iteration uses a fixed point scheme with $\B M = \B D$ and $\B N=-(\B L+\B U)$, yielding a diagonal system of equations,
\[ \B D \B x^{(k+1)} = -(\B L + \B U) \B x^{(k)} +\B b.\]
\item
The cost of each iteration of Jacobi is proportional to SpMV with $\B A$.
\end{itemize}
}

\item The Jacobi method converges if $\B A$ is strictly row-diagonally-dominant:

\lgcond{
\begin{itemize}
\item A strictly row-diagonally-dominant $\B A$ satisfies
\(|a_{ii}| < \sum_{j\neq i} |a_{ij}|,\)
which implies that for $\B B = \B D^{-1} (\B L + \B U)$,
\[\Big|\sum_{j} b_{ij}\Big| = \Big|\sum_{j\neq i} a_{ij} /a_{ii}\Big| < 1 \Rightarrow\rho(\B M^{-1}\B N)=\rho(\B B)<1.\]
\item
For the 2D Laplace problem, this condition holds.
\mitem
However, the coefficient in linear convergence $\cos(\pi h)\to 1$ as $h\to 0$.
\end{itemize}
}

%\item Convergence of iterative schemes depends on conditioning of matrix, so \coloremph{preconditioning} is often employed to accelerate iterative methods:
%
%\lgcond{
%We can think of $\B M$ as a preconditioner for $\B A$.
%In particular, a preconditioner $\B M$ approximates $\B A$ so that the matrix
%\[\B M^{-1} \B A \B x = \B M \B b\]
%}
%

\end{itemize}
\end{frame}

\begin{frame}{Gauss-Seidel Method}

\begin{itemize}

\item The Jacobi method takes weighted sums of $\B x^{(k)}$ to produce each entry of $\B x^{(k+1)}$, while Gauss-Seidel uses  the latest available values, i.e. to compute $x^{(k+1)}_i$ it uses a weighted sum of
\[x^{(k+1)}_1,\ldots x^{(k+1)}_{i-1},x^{(k)}_{i},\ldots,x^{(k)}_{n}.\]

\lgcond{
\begin{itemize}
\item
We can define the method by the splitting $\B M = \B D + \B L$ so that we have
\[(\B D + \B L)\B x^{(k+1)} = -\B U \B x^{(k)} + \B b.\]
\item
The Gauss-Seidel method performs an in-order traversal of the directed acyclic adjacency graph induced by the vertex ordering, and updates each vertex by taking newly computed values from incoming edges and values from the previous iteration from outgoing edges.
\end{itemize}
}
\mdcond{}

\item Gauss-Seidel provides somewhat better convergence than Jacobi:

\mdcond{
Convergence and efficiency depend on vertex ordering and connectivity:
\begin{itemize}
\mitem for 2-D Poisson, spectral radius is $\cos^2(\pi h)$,
\mitem computational cost is same as Jacobi, but less parallelism available.
\end{itemize}
}

%\item Convergence of iterative schemes depends on conditioning of matrix, so \coloremph{preconditioning} is often employed to accelerate iterative methods:
%
%\lgcond{
%We can think of $\B M$ as a preconditioner for $\B A$.
%In particular, a preconditioner $\B M$ approximates $\B A$ so that the matrix
%\[\B M^{-1} \B A \B x = \B M \B b\]
%}
%

\end{itemize}
\end{frame}

\begin{frame}{Successive Over-Relaxation}

\urcornerlinkdemo{11-sparse-matrices-pdes}{Stationary Iterative Methods}
\begin{itemize}
\item The \coloremph{successive over-relaxation} (SOR) method seeks to improve the spectral radius achieved by Gauss-Seidel, by choosing
\[\B M = \frac{1}{\omega} \B D + \B L, \quad \B N = \Big(\frac{1}{\omega} -1\Big)\B D - \B U\]

\lgcond{
\begin{itemize}
\item
In the resulting iterative scheme, we have
\[\Big(\frac{1}{\omega}\B D + \B L\Big)\B x^{(k+1)} = \Big(\Big(1-\frac{1}{\omega}\Big)\B D + \B U\Big) \B x^{(k)} + \B b.\]
\item If $\B x_\text{GS}^{(k+1)}$ is the iterate produced by Gauss-Seidel, SOR instead produces
\[\B x^{(k+1)} = (1-\omega)\B x^{(k)} + \omega \B x^{(k+1)}_\text{GS}.\]
\end{itemize}
}
\item The parameter $\omega$ in SOR controls the `step-size' of the iterative method:
\lgcond{
\begin{itemize}
\item over-relaxation corresponds to $\omega > 1$,
\sitem under-relaxation corresponds to $\omega < 1$,
\sitem generally best choice of $\omega\in (0,2)$ is hard to determine.
\end{itemize}
}

\end{itemize}

\end{frame}

\begin{frame}{Conjugate Gradient}

\urcornerlinkdemo{11-sparse-matrices-pdes}{Jacobi vs Conjugate Gradient}

\begin{itemize}
\item The solution to $\B A \B x = \B b$ when $\B A$ is symmetric positive definite is the minima of the quadratic optimization problem,
\[ \min_{\B x} \B x^T\B A\B x-\B x^T\B b\]

\mdcond{
We can leverage this and employ optimization methods such as conjugate gradient (CG) in the case when $\B A$ is SPD.
}
\item Conjugate gradient works by picking $\B A$-orthogonal descent directions

\mdcond{
Ensures search directions make progress and converge in at most $n$ iterations.
}

\item The convergence rate of CG is linear with coefficient $\frac{\sqrt{\kappa(\B A)}-1}{\sqrt{\kappa(\B A)}+1}$:

\mdcond{
This convergence rate motivates techniques to improve the conditioning of $\B A$ to accelerate convergence.
}

\end{itemize}

\end{frame}

\begin{frame}{Preconditioning}

\begin{itemize}
\item Preconditioning techniques choose matrix $\B M\approx \B A$ that is easy to invert and solve a modified linear system with an equivalent solution to $\B A \B x = \B b$,
\[\B M^{-1}\B A \B x = \B M^{-1} \B b\]

\lgcond{
We can then use Krylov subspace methods that build a Krylov subspace of $\B M^{-1} \B A$ rather than $\B A$ with actually forming the matrix $\B M^{-1}\B A$:
\begin{itemize}
\mitem cost of iteration depends on difficulty of applying $\B M^{-1}$,
\mitem convergence rate depends on how close $\B M$ is to $\B A$.
\end{itemize}
}

\item $\B M$ is chosen to be an effective approximation to $\B A$ with a simple structure:

\lgcond{
\begin{itemize}
\item Jacobi preconditioning takes $\B M= \B D$ where $\B D$ is the diagonal of $\B A$,
\mitem incomplete factorization (ILU) uses $\B A \approx \B L \B U$ where the sparsity pattern of $\B L$ and $\B U$ is restricted to that of $\B A$ (factorization is then generally inexact), and employs $\B M= \B L \B U$.
\end{itemize}
}

\end{itemize}

\end{frame}

%\end{document}


\documentclass[12pt]{scrartcl}
\usepackage{hyperref}
\usepackage[margin=0.7in]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage{amsmath}

\title{Beat Rater}
\author{
	Carter Walsh
}
\subtitle{https://github.com/car4p17/BeatRater}
\date{6/11/20}

\begin{document}
	\maketitle
	\section{Abstract}
	Beat Saber is a recent entry into the rhythm game category with the twist of being for virtual reality. Like Dance Dance Revolution and Guitar Hero before it, though, it runs into issues with limited official tracks and questionable quality user generated maps. In order to try and help with the second part of this problem this paper attempts to create a neural network to predict the quality of a given Beat Saber beat map. I use a dataset pulled from beatsaver.com input into a linear regression artificial neural network to predict the quality rating of the map.

	\section{Background}
	Beat Saber one of the most popular games for modern virtual reality (VR) headsets. It is a rhythm game in which the player hits blocks with two light sabers to the beat of a song. It includes music from some popular artists such as Green Day and Imagine Dragons but also provides users the ability to add their own music and associated beat maps. This ability to add custom songs to the game has resulted in thousands of user generated beat maps of varying quality. Websites such as beatsaver.com allow users to upload their maps as well as rate other users songs based on quality of the beat map. Using this data I created a Deep Neural Network to predict the user rating. This could help users find well made custom songs without the need for hundreds of user ratings as well as help verify the results of machine learning methods used to generate custom beat maps.

	\section{Related Work}
	The inspiration for this work is a tool called Beat Sage (beatsage.com). Beat Sage is a tool that uses twin neural networks to generate BeatSaber maps given only the audio file. Though the source code of this project is not available to the public they state on their website that Beat Sage’s architecture is nearly identical to a paper called Dance Dance Convolution.\\

	Dance Dance Convolution (Donahue et al., 2017) used two neural networks to generate step maps for the game Dance Dance Revolution. They used one neural network to predict the timing of steps and another to pick the direction of each step. They compared their results to the actual step map for thousands of user generated songs. \\

	(Nasreldin, 2018) Evaluated a variety of Machine Learning techniques on their ability to predict if a song was a hit. He achieved a maximum accuracy of 63\% for this prediction, slightly better than average.

	\section{Dataset}
	In this paper I pulled my dataset from beatsaver.com, a website that stores thousands of Beat Saber custom maps. I used a python script to pull 18,000 beat maps and their associated metadata from the website. Metadata includes up votes, down votes, total downloads, current popularity, and overall map rating. The map rating is the average of user ratings of the quality of a map. For this project I used the map rating and beat map as input but all of the data is still maintained in the dataset for future use.

	\section{Methods}
	To predict map ratings I used a linear regression artificial neural network. After some testing I settled on an architecture with an input layer, 3 hidden layers of 1000, 200, and 100 nodes with tanh activation functions, and an output layer of 1 node with a linear activation function. I used L2 regularization to prevent overfitting. My loss function was the squared error since I was trying to predict a single rating. As input I formatted all of the data from each beat map into uniform sized vectors. I used 33\% of my data as testing and the remainder for training. Due to hardware restraints I only trained on a uniformly distributed ~1k beat maps instead of the full 18k.

	\section{Evaluation and Results}
	The dataset is uniformly distributed between 75\% and 99\% ratings so the average RMSE would be ~5\%. After training the model for 100 epochs my network converged to a testing RMSE of 4.7\% and training RMSE of 4.5\%. This seems to show that there was minimal to no overfitting on the training data.

	\section{Conclusion}
	Though these results are not perfect they are at least better than average with roughly the same improvement as (Nasreldin, 2018)’s work. Unfortunately, this improvement is likely not enough for practical use yet. It would seem that only using the beat map without including song data may not be enough to completely predict the maps rating.

	\section{Future Work}
	Adding in music data to the neural network’s input seems like the next logical step for improvement of this architecture. With access to significantly more RAM/time it may also prove useful to train on a larger portion of the dataset. This seems less likely to provide any major improvements though since the model quickly reached 4.5\% RMSE with this subset of the

	\section{Bibliography}
	Custom Beat Saber Level Generator. (n.d.). Retrieved from https://beatsage.com/ \\

	Donahue, C., Lipton, Z., \& McAuley, J. (2017). Dance Dance Convolution. Retrieved from https://arxiv.org/pdf/1703.06891.pdf \\

	Nasreldin, M. (2018, May 14). Song Popularity Predictor. Retrieved from https://towardsdatascience.com/song-popularity-predictor-1ef69735e380
\end{document}


\documentclass{article}
\usepackage{graphicx}
\usepackage{titletoc}
\usepackage{titlesec}
\usepackage{geometry}
\usepackage{fontspec, xunicode, xltxtra}
\usepackage{float}
\usepackage{cite}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{titletoc}
\usepackage{bm}

\geometry{left=3cm,right=3cm,top=3cm,bottom=3cm}
\DeclareMathOperator*{\argmin}{argmin}
\DeclareMathOperator*{\argmax}{argmax}
\DeclareMathOperator*{\var}{var}
\DeclareMathOperator*{\expec}{E}

\begin{document}
\title{\textsf{Homework 4 for Pattern Recognition}}
\author{Fan JIN\quad (2015011506)}
\maketitle

\section*{Question 1}
{
    \subsection*{Visualization}
    {
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/glance.png}
            \caption{A glance at all the 10 categories}
        \end{figure}
    }

    \subsection*{Confusion Matrices}
    {
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/Confusion_5.png}
            \caption{Confusion matrix with 5 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/Confusion_10.png}
            \caption{Confusion matrix with 10 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/Confusion_20.png}
            \caption{Confusion matrix with 20 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/Confusion_40.png}
            \caption{Confusion matrix with 40 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/Confusion_100.png}
            \caption{Confusion matrix with 100 hidden nodes}
        \end{figure}

    }

    \subsection*{Performance Curves}
    {
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/Performance_5.png}
            \caption{Performance curve with 5 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/Performance_10.png}
            \caption{Performance curve with 10 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/Performance_20.png}
            \caption{Performance curve with 20 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/Performance_40.png}
            \caption{Performance curve with 40 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/Performance_100.png}
            \caption{Performance curve with 100 hidden nodes}
        \end{figure}
    }

    \subsection*{Plots of Rate of Correctness (ROC)}
    {
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/ROC_5.png}
            \caption{ROC curve with 5 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/ROC_10.png}
            \caption{ROC curve with 10 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/ROC_20.png}
            \caption{ROC curve with 20 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/ROC_40.png}
            \caption{ROC curve with 40 hidden nodes}
        \end{figure}
        \begin{figure}[H]
            \centering
            \includegraphics[width = 1.0\linewidth]{src1/ROC_100.png}
            \caption{ROC curve with 100 hidden nodes}
        \end{figure}
    }

    \subsection*{Conclusion}
    {
        \begin{itemize}
            \item \textbf{Confusion matrix:}\quad With more hidden nodes, the confusion rate drops accordingly. See the table below.
            \begin{table}[htb!]
                \centering
                \begin{tabular}{|c|c|}
                \hline
                Hidden nodes & Total confusion rate \\
                \hline
                5 & 11.5\% \\
                \hline
                10 & 8.9\% \\
                \hline
                20 & 5.6\% \\
                \hline
                40 & 2.9\% \\
                \hline
                100 & 1.9\% \\
                \hline
                \end{tabular}
                \caption{Confusion rates}
            \end{table}

            \item \textbf{Performance:}\quad With more hidden nodes, the error rates drop at both validation set and testing set. Meanwhile, it takes a longer time before it stops and converges, in spite of fewer iterations. Another interpretation: The network has better capability of fitting the pattern with more hidden nodes, and therefore the training process is smoother and we need fewer iterations in training. But it takes more time since we have much more parameters to train, which leads to a longer time for each iteration step.
            \begin{table}[htb!]
                \centering
                \begin{tabular}{|c|c|}
                \hline
                Hidden nodes & Total training epochs \\
                \hline
                5 & 500 \\
                \hline
                10 & 185 \\
                \hline
                20 & 125 \\
                \hline
                40 & 125 \\
                \hline
                100 & 110 \\
                \hline
                \end{tabular}
                \caption{Training iterations}
            \end{table}

            \item \textbf{ROC curve:}\quad With more hidden nodes, the ROC curve is closer to the left top corner, which indicates a better performance of classification.

        \end{itemize}
    }

    \subsection*{Max Confusion}
    {
        \begin{figure}[H]
            \centering
            \includegraphics[width = 0.7\linewidth]{src1/max_confusion.png}
            \caption{Max confusion at target value ``4'', which is mistakenly output as ``9''}
        \end{figure}
    }
}

\section*{Question 2.1}
{
        \begin{lstlisting}[language=MATLAB]

    target_size = [patchsize, patchsize, 1];
    source_size = size(IMAGES);
    indices = [randi(source_size(1) - target_size(1) + 1, [1, numpatches]); ...
        randi(source_size(2) - target_size(2) + 1, [1, numpatches]); ...
        randi(source_size(3) - target_size(3) + 1, [1, numpatches])];
    for i = 1 : numpatches
        t = indices(:, i)';
        temp = IMAGES(t(1) : (t(1) + target_size(1) - 1), ...
            t(2) : (t(2) + target_size(2) - 1), ...
            t(3) : (t(3) + target_size(3) - 1));
        patches(:, i) = reshape(temp, [numel(temp), 1]);
    end

        \end{lstlisting}
}

\section*{Question 2.2}
{
    The sizes of $W_1$, $w_1$, $W_2$ and $w_2$ are, respectively, $25\times 64$, $25\times 1$, $64\times 25$ and $64\times 1$. Every line of code is vectorized.

    \begin{lstlisting}[language=MATLAB]

    N = size(data, 2);
    x_0 = data;                % 64-by-N

    z_1 = W1 * data + w1;      % 25-by-N
    x_1 = sigmoid(z_1);        % 25-by-N

    z_2 = W2 * x_1 + w2;       % 64-by-N
    x_2 = sigmoid(z_2);        % 64-by-N

    % Forward propagation

    J = 1/2 * sumsqr(x_2 - x_0) / N;
    R = lambda/2 * (sumsqr(W1) + sumsqr(W2));
    rho_hat = mean(x_1, 2);    % 25-by-1
    rho = sparsityParam;
    S = beta * sum( rho*log(rho./rho_hat) + (1-rho)*log((1-rho)./(1-rho_hat)) );

    cost = J + R + S;

    % Back propagation

    delta_2 = (x_2 - x_0) .* x_2 .* (1 - x_2);                    % 64-by-N

    W2grad = (delta_2 * x_1') / N + lambda * W2;                  % 64-by-25
    w2grad = mean(delta_2, 2);                                    % 64-by-1

    rhograd_2 = beta * ( - rho./rho_hat + (1-rho)./(1-rho_hat) );

    rhograd_1 = (x_1 .* (1 - x_1)) * x_0' / N;

    rhograd_0 = mean(x_1 .* (1 - x_1), 2);

    delta_1 = (W2' * delta_2) .* x_1 .* (1 - x_1);                % 25-by-N

    W1grad = (delta_1 * x_0') / N + lambda * W1 + rhograd_2 .* rhograd_1; % 25-by-64
    w1grad = mean(delta_1, 2) + rhograd_2 .* rhograd_0;           % 25-by-1

    \end{lstlisting}
}

\section*{Question 2.3}
{
    \subsection*{(1)}
    {
        Note that $S$ does not depend on $z_i^2$, we obtain
        $$\delta_i^2 = \frac{\partial}{\partial z_i^2} {\left[ \frac{1}{2} \sum_{j=1}^{n}{(f(z_j^2) - x_j)^2} + S \right]} $$
        $$= (f(z_i^2) - x_i) \frac{\partial}{\partial z_i^2} {f(z_i^2)} $$
        $$= (f(z_i^2) - x_i) \cdot f(z_i^2) (1 - f(z_i^2))$$
        $$= (\hat{x}_i - x_i) \cdot \hat{x}_i (1 - \hat{x}_i)$$
        where $$f(z_i^2) = x_i^2 = \hat{x}_i = \frac{1}{1 + \exp{(-z_i^2)}} = \left[ 1 + \exp{(- w_0^2 - \sum_{j=1}^{n_1}{W_{ji}^2 x_j^1})} \right]^{-1}.$$
    }

    \subsection*{(2)}
    {
        By definition, the simple gradient descent algorithm uses the iterations below:
        $$W_{ij}^1 \leftarrow W_{ij}^1 - \alpha \frac{\partial J}{\partial W_{ij}^1},$$
        $$w_0^2 \leftarrow w_0^2 - \alpha \frac{\partial J}{\partial w_0^2},$$
        where $\alpha$ is the learning rate with the gradients
        $$\frac{\partial J}{\partial W_{ij}^1} = \frac{\partial J_s}{\partial z_j^1} \frac{\partial z_j^1}{\partial W_{ij}^1} + \frac{\partial R}{\partial W_{ij}^1} = d_j^1 x_i + \lambda W_{ij}^1,$$
        $$\frac{\partial J}{\partial w_0^2} = \frac{\partial J_s}{\partial z_j^2} \frac{\partial z_j^2}{\partial w_0^2} + \frac{\partial R}{\partial w_0^2} = d_j^2.$$
    }

    \subsection*{(3)}
    {
        By chain rule of multivariate derivatives, we obtain
        $$\delta_i^1 = \frac{\partial J}{\partial z_i^1} = \frac{\partial J}{\partial x_i^1} \frac{\partial x_i^1}{\partial z_i^1}$$
        $$= \frac{\partial J}{\partial x_i^1} \cdot x_i^1 (1 - x_i^1)$$
        $$= \left[ \frac{\partial J_s}{\partial x_i^1} + \frac{\partial S}{\partial x_i^1} \right] \cdot x_i^1 (1 - x_i^1)$$
        $$= \left[ \sum_{j=1}^{n_1}{\frac{\partial J_s}{\partial z_j^2} \frac{\partial z_j^2}{\partial x_i^1}} + \frac{\partial S}{\partial x_i^1} \right] \cdot x_i^1 (1 - x_i^1)$$
        $$= \left[ \sum_{j=1}^{n_1}{\delta_j^2 W_{ij}^2} + \frac{\partial S}{\partial x_i^1} \right] \cdot x_i^1 (1 - x_i^1),$$
        where $$\frac{\partial S}{\partial x_i^1} = \frac{\partial S}{\partial \hat{\rho}_i} = \beta \left( -\frac{\rho}{\hat{\rho}_i} + \frac{1 - \rho}{1 - \hat{\rho}_i} \right).$$
    }
}

\section*{Question 2.4}
{
    Given the hint, it is acceptable not to use vectorized manipulations here.

    \begin{lstlisting}[language=MATLAB]

    eps = 1e-6;
    for i = 1 : length(theta)
        dtheta = zeros(size(theta));
        dtheta(i) = eps;
        numgrad(i) = (J(theta + dtheta) - J(theta - dtheta)) / (2*eps);
    end

    \end{lstlisting}

    Run ``Step 3'' in ``train.m'', and the output indicates that the numerical and the analytical gradients correspond. The error is about $10^{-11}$.
    \begin{lstlisting}

    38.0000   38.0000
    12.0000   12.0000

    The above two columns you get should be very similar.
    (Left-Your Numerical Gradient, Right-Analytical Gradient)

    2.1452e-12

    Norm of the difference between numerical and analytical gradient (should be < 1e-9)

    8.2413e-11

    \end{lstlisting}

}

\section*{Question 2.5}
{
    Thanks to the vectorized expressions, the training process takes only 30 seconds before it stops at 400 iterations. The final cost is $0.4440$ with all paramters at default value.
}

\section*{Question 2.6}
{
    \begin{figure}[H]
        \centering
        \includegraphics[width = 0.7\linewidth]{src2/weights.jpg}
        \caption{Visualization of the weights}
    \end{figure}
}

\section*{Source Code}
{
    Please download the souece code from http://39.106.23.58/files/PR4\_2015011506.7z

    For Question 1, please ``cd ./src1'' and run ``main.m''. It may take minutes to train the network, but the result is reproducible because of the random seed.

    For Question 2, please ``cd ./src2'' and run ``train.m'' by section.
}

\clearpage
\end{document}


% !Mode:: "TeX:UTF-8"

\documentclass[11pt, a4paper]{article}
%\usepackage{xltxtra,fontspec,xunicode}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{breqn}
\usepackage{autobreak}
\usepackage{braket,mleftright}
\usepackage{amsfonts}
\usepackage[section]{placeins}
\usepackage{float}
\usepackage{siunitx}

\usepackage{indentfirst}
\usepackage{caption}
\usepackage{physics}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx

\geometry{top=1in, bottom=1in, left=1in, right=1in}
%\linespread{1.5}

\DeclareMathOperator*{\argmax}{argmax}
\DeclareMathOperator*{\argmin}{argmin}

\newcommand{\degc}{$\,^\circ$C}

\begin{document}

\title{Simulate co-transcriptional folding kinetics by genetic algorithm}
\author{Zhuoran Qiao}
\date{\today}

\maketitle

We developed a genetic algorithm based approach to simulate kinetics of co-transcriptional folding. Our method is built on two following assumptions:
\paragraph{1} All populated RNA secondary structures (SS) are linkage of locally optimal or sub-optimal structures at various folding sites;
\paragraph{2} Global structural rearrangement of a partial RNA segment is permitted only if it's folding to the optimal SS on that segment.
\\

Formally, we denote a domain $D_{A,\,B}$ as a segment between base $A$ and $B$ that all contacts on that segment are local. For simplicity, we denote \textbf{foldon}
as domains with optimal secondary structures: $D^{foldon}_{A,\,B} = \text{MFE(sequence[A,B])}$. Note that $'.'$ is a trival example of foldon.
Our assumption 1 can be rewritten as
\begin{equation}
  D_{A,\,B} = D^{foldon}_{A, i_1} \oplus D^{foldon}_{i_1, i_2} \oplus ... \oplus D^{foldon}_{i_n, B}
\end{equation}
Where $\oplus$ represents a link operation. Note that all structural information of $D_{A,\,B}$ is encoded by the sequential representation $[A,\, i_1,\, ...,\, i_n,\, B]$;
 as a foldon is also a linkage of smaller foldons, there could be multiple way to represent $D_{A,\,B}$. Here we introduce \textbf{Irreducible Foldon Representation} (IFR) as
 sequential representations for which linkage of every adjacent foldons is not another foldon: $\forall k,\, D^{foldon}_{i_k, i_{k+1}} \oplus D^{foldon}_{i_{k+1}, i_{k+2}} \neq D^{foldon}_{i_{k}, i_{k+2}}$.
 Then the sufficient and nessary condition for structural rearrangement is

\begin{center}
  $\langle D^{u}_{A,\,B} | \hat{\mathbf{T}} | D^{v}_{A,\,B} \rangle \neq 0$ if and only if $\exists\, i,\,j$ satisfies

  $i,\,j \in D^{u}_{A,\,B}$.IFR, $i,\,j \in D^{v}_{A,\,B}$.IFR;

  $D^{u}_{A,\,i} = D^{v}_{A,\,i},\, D^{u}_{j,\,B} = D^{v}_{j,\,B}$;

  $D^{u}_{i,\,j} = D^{foldon}_{i,\,j}$ or $D^{v}_{i,\,j} = D^{foldon}_{i,\,j}$.

  Then $\langle D^{u}_{A,\,B} | \hat{\mathbf{T}} | D^{v}_{A,\,B} \rangle = \langle D^{u}_{i,\,j} | \hat{\mathbf{T}} | D^{v}_{i,\,j} \rangle$.
\end{center}

\section{Algorithm procedure}

During every elongation step, an active species pool of strands with unique SS and diffrent population is updated. New candidate strands $D^{Candidate}_{0,\, L+\Delta L}$ with
length $L+\Delta L$ are generated by a recombination
process: for every old strand $D^{Strand}_{0, \text{ L}}$, all indices in its IFR is identified as possible rearrangement site, then its child strands is generated by linking partial domains
$D^{Strand}_{0, \text{ Site}}$ with a foldon $D^{foldon}_{\text{Site}, L+\Delta L}$ that terminated at $L+\Delta L$.

We assume that elongation will not change the inital population distribution
of secondary structures: child strands with the exact parental SS on $[0, L]$ ($D^{child}_{0, L+\Delta L} = D^{strand}_{0, L} \oplus D^{foldon}_{L, L+\Delta L}$) will also inherit the population of their parents.

After structual generation the rate matrix among all candidate strands within the new active species pool is calculated%(see part \ref{section:rate})
. Then the population
distribution of strands after elongation is computed by chemical master equation, and one iterative elongation step is finished.

Pseudocodes of the procedure are as follows:

\begin{algorithm}
  \begin{algorithmic}[1]
    \State Initalize ActivePool
    \While{$\text{sequence length} > \text{current length }$}
      \State $\text{OldPool} \gets \text{ActivePool }$
      \State $\text{renew ActivePool }$
      \State $\text{Current length} \gets \text{Current length} + dL$
      \State $\text{dt} \gets \text{dL / \text{Transcription rate}}$
      \For{$\text{left boundary} \in \text{\{0, dL, 2dL, ..., Current length - dL\}}$}\Comment{Get all new foldons}
        \State $D^{foldon}_{\text{left boundary}, \text{ Current length}} \gets \text{numpy.mfe(sequence[left boundary, Current length]})$
      \EndFor
      \For{$\text{Strand} \in \text{OldPool }$}\Comment{Recombination}
        \For{$\text{Site} \in \text{Strand.IFR }$}
          \State $D^{Candidate}_{0,\text{Current length}} \gets D^{Strand}_{0, \text{ Site}} \oplus D^{foldon}_{\text{Site}, \text{ Current length}}$
          \If {$D^{Candidate}_{0,\text{Current length}} \in \text{ActivePool }$}
            \State $\text{update $D^{Candidate}_{0,\text{Current length}}$.IFR}$
          \Else
            \State $\text{add $D^{Candidate}_{0,\text{Current length}}$ to ActivePool}$
          \EndIf
          \If {$\text{site} = \text{Current length} - dL$}
            \State $\langle \text{ActivePool}.\textbf{population}\,|D^{Candidate}_{0,\text{Current length}}\rangle \gets \langle \text{OldPool}.\textbf{population}\,|D^{Strand}_{0, \text{ Site}}\rangle$
          \EndIf
        \EndFor
      \EndFor
      \For{$D^{\text{u}}_{0,\text{Current length}} \neq D^{\text{v}}_{0,\text{Current length}} \in \text{ActivePool}$}\Comment{Calculate new rate matrix}
        \State $\text{calculate  } D^{u}_{\text{rearrange}} ,\ D^{v}_{\text{rearrange}}$\Comment{Find all helices involved in rearrangement}
        \State $\langle D^{u}_{\text{rearrange}} | \hat{\mathbf{T}} |D^{v}_{\text{rearrange}} \rangle \gets k_0 \exp(-\frac{1}{RT}(\Delta G^{Stack}_{u}+\Delta G^{Loop}_{v}) )$
      \EndFor
      \State $\langle \text{ActivePool}.\textbf{population}\,|\, \gets \langle \text{ActivePool}.\textbf{population}\,|\, \exp(\hat{\mathbf{T}}) $\Comment{Master equation}
      \State $\text{reserve top $N$ populated strands in ActivePool}$\Comment{Selection}
      \State $\text{renormalize }\langle \text{ActivePool}.\textbf{population}\,|$
    \EndWhile
  \end{algorithmic}
\caption{Co-transcriptional folding elongation procedure}
\end{algorithm}

%\section{Secondary structure generation}
%\paragraph{a.} Derived formalisms for transition path statistics based on Transition Path Theory and continuous-time random walk (CTRW) model;
%\paragraph{b.} Suggested an simple method to analytically predict transition path time (TPT) distribution on arbitrary 1-d free energy landscapes (FELs);
%\paragraph{c.} Calculated probability distribution of backward jumping within transition paths ensemble for 1-d toy landscapes.

%\section{Progress}
%\subsection{Transition path statistics of CTRW model}

%\section{Folding pathway identification \& Rate calculation} \label{section:rate}

%\paragraph{a.} Using a genetic-algorithm based method and NUPACK to predict populated RNA configurations during cotranscriptional folding (in progress);
%\paragraph{b.} Using master equation method to simulate evolution of folding configurations and SD sequence accessibility.

%In order to examine when the one-dimensional coordinate projection could be recognized as effective reaction coordinate,
%we then examine the probability distribution of committors for transition path trajectories $p(q|TP)$, for which a single peak of probability $p(q|TP)$ have been ultilized as a indicator for 'good' reaction coordinates.
% Firstly, We found that for harmonic toy model, the shape of $p(q|TP)$ is very sensitive to the definition of source/sink region. For illustration, $p(q|TP)$ for two different selection
%  of source/sink regions was compared: in the first case, only two free energy minimum was indentified as source or sink\textbf{(S1)}; in the second case, only the barrier top was
%  defined as the transition path, while other two region of the free energy landscape was calssified as source/sink\textbf{(S2)}.

%\cite{Jacobs2018,Chaudhury2010,Vanden-Eijnden2010,Metzner,Krivov}

\small
%\bibliographystyle{plain}
%\bibliography{0727}

\end{document}


\problemname{Stopwatch}

Robin just received a stopwatch from her grandfather. Robin's stopwatch has a single button. Pressing the button alternates between stopping and starting the stopwatch's timer. When the timer is on, the displayed time increases by 1 every second.

Initially the stopwatch is stopped and the timer reads 0 seconds. Given a sequence of times that the stopwatch button is pressed, determine what the stopwatch's timer displays.

\section*{Input}
The first line of input contains a single integer $N$ ($1 \leq N \leq 1\,000$), which is the number of times the stopwatch was pressed.

The next $N$ lines describe the times the stopwatch's button was pressed in increasing order. Each line contains a single integer $t$ ($0 \leq t \leq 10^6$), which is the time the button was pressed. No two button presses happen on the same second.

\section*{Output}
Display \texttt{still running} if the stopwatch's timer is still running after all button presses were made. Otherwise display the number of seconds displayed on the stopwatch's timer.


%==============================================================================
\chapter{3D biophysical model of biventricular rat heart contraction
mechanics}\label{cha:chapter02}
%==============================================================================
%
%
%
\begin{remark}{Outline}
    In this chapter, we systematically build a mathematical model of $3$D biventricular rat heart contraction mechanics. We start with modelling ion fluxes across each cell membrane using an ionic model for left ventricular myocytes at physiological temperature and pacing rate (Section~\ref{sec:ch2ionicmodel}). We then model active tension generation at the cellular level using a model of sarcomere contraction, which includes length- and velocity-tension dependencies (Section~\ref{sec:ch2contractionmodel}). We present the framework to build a $3$D computer representation (mesh) of rat biventricular anatomies from experimental data (Section~\ref{sec:ch2anatomy}). We finally describe passive material properties (Section~\ref{sec:ch2tissuemodel}), myocardial electrical activation (Section~\ref{sec:ch2electricalactivation}) and spatial and haemodynamic boundary conditions (Section~\ref{sec:ch2boundaryconditions}). We conclude with a brief summary (Section~\ref{sec:ch2summary}).
\end{remark}

\begin{figure}[ht!]
    \myfloatalign
    \includegraphics[width=\textwidth]{figures/chapter02/methods_schematic.pdf}
    \caption{The full $3$D biophysical model of biventricular rat heart contraction mechanics is a multi-scale framework of integrated sub-models describing the main mechanisms which regulate the heart contraction and relaxation at the cell, tissue and body scales.}
    \label{fig:methodssummaryinscale}
\end{figure}

%
%
%
\section{Ionic model}\label{sec:ch2ionicmodel}
We employed the Gattoni et al.~\cite{Gattoni:2016} model to simulate rat left ventricular myocytes electrophysiology and calcium dynamics at physiological pacing rate ($\SI{6}{\hertz}$) and temperature ($\SI{37}{\celsius}$). This model was selected as two variants of it exist~\cite{Gattoni:2017}, where the model was specifically tailored to represent the LV myocyte electrophysiology of a healthy control rat and a rat model of heart failure. In Chapter~\ref{cha:chapter4}, we will use magnetic resonance images to derive heart anatomies (meshes) for the same kind of animal models, and we were in a unique spot since the experiments used to create the two ionic models in~\cite{Gattoni:2017} were performed on the very same cohort of rats from which the medical images were obtained.

\vspace{0.2cm}
All the currents present in the Gattoni et al.~\cite{Gattoni:2016} model are summarised in Table~\ref{tab:gattonicurrentstab}, while the main ion channels, transporters and pumps are depicted in Figure~\ref{fig:gattonicurrentsfig}.

\begin{table}[ht!]
    \myfloatalign
    \begin{tabularx}{\textwidth}{lX}
    \toprule
    \tableheadline{Label} & \tableheadline{Definition} \\
    \midrule
    $I_{LCC}$    & L-type $\Ca$ current \\
    $I_{RyR}$    & ryanodine receptor current \\
    $I_{TRPN}$   & troponin buffering current \\
    $I_{SERCA}$  & sarcoplasmic $\Ca$ pump current \\
    $I_{SR\ell}$ & sarcoplasmic reticulum leakage current \\
    $I_{NCX}$    & $\Na$/$\Ca$ exchanger current \\
    $I_{PMCa}$   & plasma membrane $\Ca$ pump current \\
    $I_{Cab}$    & $\Ca$ leak current \\
    $I_{NaK}$    & $\Na$/$\K$ pump current \\
    $I_{Na}$     & $\Na$ current \\
    $I_{K1}$     & inwardly rectifying $\K$ current \\
    $I_{to}$     & transient outward $\K$ current \\
    $I_{ss}$     & steady-state outward $\K$ current \\
    $I_{f}$      & hyperpolarisation-activated current \\
    $I_{BNa}$    & $\Na$ background current \\
    $I_{BK}$     & $\K$ background current \\
    \bottomrule
    \end{tabularx}
    \caption{Gattoni et al.~\cite{Gattoni:2017} model's ionic currents.}
    \label{tab:gattonicurrentstab}
\end{table}

\begin{figure}[ht!]
    \myfloatalign
    \includegraphics[width=\textwidth]{figures/chapter02/new_ep.pdf}
    \caption{Main ion channels and pumps included in the Gattoni et al.~\cite{Gattoni:2016} model.}
    \label{fig:gattonicurrentsfig}
\end{figure}

%
%
%
\section{Contraction model}\label{sec:ch2contractionmodel}
We employed the Land et al.~\cite{Land:2012} myocyte contraction model to simulate both dynamic force generation at the sarcomere level in response to a calcium transient and the steady-state force-calcium relationship in the rat heart. This model describes the cooperative binding of $\Ca$ to TnC, which causes unblocking of the actin sites for myosin cross-bridge cycling. We selected this specific model because it is regulated by only $4$ ODEs, which makes it computationally inexpensive to be run. This was a desired feature, as we aim at incorporating the model within a larger multi-scale, whole-organ contraction mechanics model where general performances can be heavily affected by their cellular sub-unit model. Despite the low number of equations, the Land et al.~\cite{Land:2012} model is still able capture all the key mechanisms regulating sarcomeric function (previously discussed in Section~\ref{sec:cell_contr_modelling}), including active tension generation dependence on sarcomere length (Section~\ref{sec:ch2lengthdependence}) and velocity (Section~\ref{sec:ch2velocitydependence}). At the same time, this model was previously shown to be suitable for being incorporated within whole-heart computational frameworks~\cite{Land:2012, Lewalle:2018}.

\vspace{0.2cm}
The process of $\Ca$ binding to TnC is described via the following equation:
%
\begin{equation}\label{eq:landodesys1}
    \der{\trpn}{t} = \ktrpn\left[\left(\frac{\Cai}{\Caift}\right)^{\ntrpn}(1-\trpn)-\trpn\right]
\end{equation}

\noindent
where

\vspace{0.2cm}
\begin{tabular}{ll}
    $\trpn$  & proportion of bound $\Ca$-TnC complexes \\
    $\ktrpn$ & unbinding rate of $\Ca$ from TnC \\
    $\Cai$   & representative $\Ca$ transient \\
    $\Caift$ & $\Ca$ thin filament sensitivity \\
    $\ntrpn$ & $\Ca$-TnC binding degree of cooperativity
\end{tabular}

\vspace{0.2cm}
Tropomyosin kinetics and the cross-bridge cycle are represented by a two-state model. One state is the \textit{cross-bridge state} ($\xb$), where the cross-bridge is actively cycling and includes both the weakly, strongly, and unbound states all collapsed into one state, while the other state is the \textit{non-permissive state} ($N=1-\xb$). The transition between these two states is described via the following equation:
%
\begin{align}\label{eq:landodesys2}
    & \der{\xb}{t} = \kxb\left[\permtot(1-\xb)-\frac{1}{\permtot}\xb\right],\quad\text{with} \\
    & \permtot := \sqrt{\left(\frac{\trpn}{\trpnf}\right)^{\nxb}} \nonumber
\end{align}

\noindent
where

\vspace{0.2cm}
\begin{tabular}{ll}
    $\xb$    & proportion of formed cross-bridges \\
    $\kxb$   & cross-bridges cycling rate \\
    $\trpnf$ & fraction of $\Ca$-TnC bounds for half-maximal cross-bridges activation \\
    $\nxb$   & cross-bridge formation degree of cooperativity
\end{tabular}

\vspace{0.2cm}\noindent
$\trpn$ and $\xb$ variation over time within one cardiac cycle is shown in Figure~\ref{fig:catrpnxb}, where the representative calcium
transient from healthy, $\SI{6}{\hertz}$-paced rat left ventricular myocytes at $\SI{37}{\celsius}$ which was used to run the simulation is also displayed.

\begin{figure}[ht!]
    \myfloatalign
    \includegraphics[width=0.8\textwidth]{figures/chapter02/Ca_TRPN_XB.pdf}
    \caption{Fraction of bound $\Ca$-TnC complexes (TRPN) and of bound cross-bridges (XB) as a function of time. The intracellular $\textrm{Ca}^{2+}$ concentration variation over time is also displayed on a different scale (blue).}
    \label{fig:catrpnxb}
\end{figure}

\vspace{0.2cm}
In the Land et al.~\cite{Land:2012} model, normalised active force is defined as:
%
\begin{equation}\label{eq:normforce}
    F_n = g(Q)\cdot h(\lambda)\cdot \text{XB}
\end{equation}

\noindent
where

\vspace{0.2cm}
\begin{tabular}{ll}
    $h(\lambda)$ & length-dependence factor \\
    $g(Q)$       & velocity-dependence factor
\end{tabular}

\vspace{0.2cm}\noindent
Normalised force (equation~\eqref{eq:normforce}) is then scaled to actual tension using a reference tension $\tref$ scaling coefficient that encapsulates the total number of cross-bridges and the fraction of cycling cross-bridges in the force-generating state for any given time:
%
\begin{equation}
    T = \tref\cdot F_n
\end{equation}

%
%
%
\subsection{Length-dependence}\label{sec:ch2lengthdependence}
The active tension dependence on sarcomere length was based on filament overlap modelling:
%
\begin{align}
    h'(\lambda) &= 1+\beta_0\,[\lambda+\min(\lambda,\,0.87)-1.87] \\
    h(\lambda) &= \max(0,\,h'(\min(\lambda,\,1.2)))
\end{align}

\noindent
where

\vspace{0.2cm}
\begin{tabular}{ll}
    $\beta_0$ & phenomenological tension length-dependence scaling factor
\end{tabular}

\vspace{0.2cm}\noindent
This results in a linear length dependence near resting sarcomere length and a twice as steep decrease in tension when the sarcomere length falls below the thick filament length (at $\lambda = 0.87$).

\vspace{0.2cm}
A phenomenological representation of the thin filament calcium sensitivity shift in a length-dependent manner is also included as an important mechanism of tension length-dependence. This is implemented by $\Caift$ in equation~\eqref{eq:landodesys1}, which is further taken to be:
%
\begin{equation}\label{eq:Caift}
    \Caift:=\Caif[1 + \beta_1(\lambda - 1)]
\end{equation}

\noindent
where

\vspace{0.2cm}
\begin{tabular}{ll}
    $\Caif$   & reference $\Ca$ thin filament sensitivity \\
    $\beta_1$ & phenomenological tension length-dependence scaling factor \\
    $\lambda$ & extension ratio along the fibre direction
\end{tabular}

\vspace{0.2cm}\noindent
At the resting sarcomere configuration ($\lambda=1$), length-dependence effects are not present, and no consequent shift in the calcium sensitivity is observed ($\Caift=\Caif$).

%
%
%
\subsection{Velocity-dependence}\label{sec:ch2velocitydependence}
To phenomenologically represent the tension development dependence on cross-bridge kinetics, the \emph{fading memory model} was employed as previously done in~\cite{Niederer:2006}, describing the velocity response as several strain-rate-dependent variables that decay with time. In particular, this model describes the relationship between tension and sarcomere sliding velocity by separating tension development into a non-linear static component and a linear time-dependent component, as described by the following two equations:
%
\begin{equation}
    \der{Q_i}{t} = A_i\,\der{\lambda}{t}-\alpha_i\,Q_i,\quad i=1,2
\end{equation}

\noindent
where

\vspace{0.2cm}
\begin{tabular}{ll}
    $A_i,\,i=1,2$      & parameters related to the viscous and elastic moduli \\
    $\alpha_i,\,i=1,2$ & parameters related to the frequencies
\end{tabular}

\vspace{0.2cm}\noindent
The effect $g(Q)$ seen in equation~\eqref{eq:normforce} on tension is given by an equation derived from the Hill force-velocity curve extended to model stretch and shortening in a symmetric way as done in~\cite{Niederer:2006}:
%
\begin{equation}
    g(Q) = \begin{cases}
        \dfrac{a\,Q+1}{1-Q}\qquad & Q\le 0 \\
        \dfrac{1+(a+2)\,Q}{1+Q}\qquad & Q>0
    \end{cases}\,,\quad\text{with}\quad Q := \sum_{i=1}^2 Q_i
\end{equation}

\noindent
where

\vspace{0.2cm}
\begin{tabular}{ll}
    $a$ & slope of the Hill force-velocity relationship
\end{tabular}

\vspace{0.2cm}\noindent
Land et al.~\cite{Land:2012} cell contraction model's main mechanisms are summarised in the schematic provided in Figure~\ref{fig:cellcontrschematic}.

\begin{figure}[ht!]
    \myfloatalign
    \includegraphics[width=0.66\textwidth]{figures/chapter02/cellular_contraction_land.pdf}
    \caption{Land et al.~\cite{Land:2012} cell contraction model schematic. $\Ca$ binds to TnC, and when the fraction of bound complexes (TRPN) reaches $\trpnf$, half of the maximum number of cross-bridges has passed from the non-permissive state (N) to the actively cycling state (XB). Generated active force, which directly depends on the fraction of formed cross-bridges, causes tissue contraction, which backwards modulates the force generation itself in a length- and velocity-dependent manner.}
    \label{fig:cellcontrschematic}
\end{figure}

%
%
%
\subsection{Uncoupling the binding and unbinding rates}\label{sec:ch2uncoupling_binding_and_unbinding_rates}
We wanted to uncouple the unbinding rate from the binding rate in the $\Ca$-TnC relationship. This was achieved by assigning a different function to parameter $\ktrpn$ according to whether this was multiplying the first term or the second term in equation~\eqref{eq:landodesys1}:
%
\begin{align}
    \frac{d\text{TRPN}}{dt} &=\ktrpn\left[\left(\frac{\Cai}{\Caift}\right)^{\ntrpn}(1-\trpn)-\trpn\right] \\
    &= \underbrace{\ktrpn}_{\kon}\left(\frac{\Cai}{\Caift}\right)^{\ntrpn}(1-\trpn)-\underbrace{\ktrpn}_{\koff}\trpn \\
    &= \kon\left(\frac{\Cai}{\Caift}\right)^{\ntrpn}(1-\trpn)-\koff\trpn \label{eq:landodesys1mod}
\end{align}

\vspace{0.2cm}\noindent
Both the $\Ca$-independent part ($\kon$) of the binding rate and the unbinding rate ($\koff$) were set to the same model baseline $\ktrpn$ value, although now it is possible to treat them as two different parameters. This will serve the purpose of understanding the individual contribution of each of them in the active tension generation.

%
%
%
\subsection{The force-calcium relationship}\label{sec:ch2theforcecalciumrelationship}
The steady-state solutions of Equations~\eqref{eq:landodesys1mod}--\eqref{eq:landodesys2} are:
%
\begin{equation}\label{eq:landodesys1_ss}
    \trpn_{ss} = \dfrac{\left(\dfrac{\Cai}{\Caift}\right)^{\ntrpn}}{\dfrac{\koff}{\kon}+\left(\dfrac{\Cai}{\Caift}\right)^{\ntrpn}}
\end{equation}
%
\begin{equation}\label{eq:landodesys2_ss}
    \xb_{ss} = \frac{(\trpn)^{\nxb}}{(\trpnf)^{\nxb}+(\trpn)^{\nxb}}
\end{equation}

\noindent
In the case of isometric force studies, the length- ($h(\lambda)$) and velocity- ($g(Q)$) dependence terms equal to $1$, and the steady-state force is given by:
%
\begin{equation}\label{eq:landssforce}
    F = \tref\cdot \xb_{ss}
\end{equation}

\noindent
Equation~\eqref{eq:landssforce} can be re-written in a more classical form as
%
\begin{equation}\label{eq:forcess}
    \frac{F}{F_0} = \frac{x^{h(x)}}{1+x^{h(x)}}\,,\quad\text{with}\quad x:=\frac{\Cai}{\ecf}
\end{equation}

\noindent
where

\vspace{0.2cm}
\begin{tabular}{ll}
    $F_0$  & reference force ($=\tref$) \\
    $h(x)$ & Hill coefficient \\
    $\ecf$ & half-maximal effective concentration
\end{tabular}

\vspace{0.2cm}\noindent
The Hill coefficient $h(x)$ has the following form:
%
\begin{equation}
    h(x) = \nxb\left[\ntrpn-\log_{x}{\left(1-\trpnf(1-x^{\ntrpn})\right)}\right]
\end{equation}

\noindent
while the half-maximal effective concentration $\ecf$ is given as a function of five model parameters:
%
\begin{equation}\label{eq:ec50}
    \ecf = \Caift\left(\frac{\koff}{\kon}\frac{\trpnf}{1-\trpnf}\right)^{1/\ntrpn}
\end{equation}

By construction, the Land et al.~\cite{Land:2012} model has a biphasic Hill coefficient. To simplify the analysis, we approximated the steady-state force by characterising $F$ using a single Hill coefficient value $h$ defined as the slope at half-maximal activation:
%
\begin{equation}\label{eq:h}
    h := \lim_{x\to1}h(x) = \nxb\ntrpn(1-\trpnf)
\end{equation}

\noindent
As a result, the Hill coefficient does not depend on $\Cai$ and is a function of three model parameters. Using logarithmically-spaced calcium values, equation~\eqref{eq:forcess} becomes
%
\begin{align}\label{eq:FpCa}
    & \frac{F}{F_0} = \frac{1}{1+10^{h(\pCaf-\pCa)}}\,,\quad\text{with} \\
    & \pCa:=-\log{\Cai} \\
    & \pCaf:=-\log{\ecf}
\end{align}

\noindent
Equation~\eqref{eq:FpCa} takes the name of \textit{force-pCa} (\acs{F-pCa}) \textit{curve}.

%
%
%
\section{Anatomy model}\label{sec:ch2anatomy}
Rat biventricular anatomy was represented \textit{in silico} by a \textit{cubic Hermite} finite element mesh. This was generated using an automatic service for ventricular cardiac meshes personalisation developed by Lamata et al.~\cite{Lamata:2011, Lamata:2014}.

\vspace{0.2cm}
The mesh customisation pipeline starts from a binary image, which in general corresponds to a segmentation obtained from heart medical images (e.g. magnetic resonance images). An idealised template mesh composed of truncated ellipsoids is then tailored to the binary mask provided, and image registration is performed to assess the deformation field from template to real anatomy. During this step, the user can choose the so-called \textit{level of detail} (\acs{LoD}), which gives a trade-off between fitting accuracy and numerical stability. The LoD ranges from $1$ (coarse and most stable) to $5$ (accurate but less likely to be stable). After having calculated the warping function by image registration, this is used to map the template mesh to the deformed space using a variational technique. The last step of the pipeline involves enhancing the quality of the mesh by improving the regularity of each element by linearising internal nodes transmural positions with no loss of accuracy.

\vspace{0.2cm}
Rule-based fibres~\cite{Bayer:2012}, along with the generated meshes, complemented the anatomical description of the rat heart. We used a transmural variation of $\SI{-60}{\degree}$ to $\SI{80}{\degree}$ from epicardium to endocardium.

%
%
%
\section{Tissue model}\label{sec:ch2tissuemodel}
We modelled passive material properties using the transversely isotropic cardiac strain energy function proposed by Guccione et al.~\cite{Guccione:1991}:
%
\begin{align}\label{eq:guccstrainenergy}
    &W = W_g(\mathbf{E})\,,\quad\text{with} \\
    &W_g(\mathbf{E}) := \frac{1}{2}\,C_1\,(e^{Q(\mathbf{E})}-1) \\
    &Q(\mathbf{E}) := b_f E_{\text{ff}}^2 + b_{ft}(2E_{\text{fs}}^2+2E_{\text{fn}}^2) + b_t(E_{\text{ss}}^2+E_{\text{nn}}^2+2\,E_{\text{sn}}^2)
\end{align}

\noindent
where

\vspace{0.2cm}
\begin{tabular}{ll}
    $\mathbf{E}$ & Green strain tensor (introduced in Section~\ref{sec:tissue_mech_math_modelling}) \\
    $C_1$ & scaling coefficient (representing an overall tissue stiffness) \\
    $b_f,\,b_{ft},\,b_t$ & tissue mechanical response in the fibre, \\ & fibre-transverse shear and transverse planes \\
\end{tabular}

\vspace{0.2cm}\noindent
We adopted this formulation since it is widely used in the cardiac modelling community~\cite{Land:2015} and most importantly because it is regulated by a few parameters, with one ($C_1$) being particularly interesting for modelling purposes as it can be scaled to directly impact the whole tissue stiffness.

\vspace{0.2cm}
Cardiac tissue was further assumed to be fully incompressible. This was enforced by expanding the strain-energy function in equation~\eqref{eq:guccstrainenergy} with a \textit{Lagrange multiplier scheme}, in combination with an \textit{incompressibility penalty} to improve stability of mechanics simulations~\cite{Land:2015*b}:
%
\begin{align}\label{eq:landstrainenergy}
    &W = W_g(\mathbf{E}) - p(J - 1) + \frac{\kappa}{2}(J - 1)^2\,,\quad\text{with}\quad J:=\text{det}(\mathbf{F}) \\
    &\text{and with constraint:}\quad J=1
\end{align}

\noindent
where

\vspace{0.2cm}
\begin{tabular}{ll}
    $p$ & hydrostatic pressure \\
    $\kappa$ & penalty parameter \\
    $\mathbf{F}$ & deformation gradient tensor (introduced in Section~\ref{sec:tissue_mech_math_modelling})
\end{tabular}

%
%
%
\section{Electrical activation}\label{sec:ch2electricalactivation}
The calcium transient was assumed not to vary spatially, and it homogeneously activated contraction throughout the ventricular walls. Previous heart models have shown that heterogeneous activation patterns have negligible impact in the small rat heart~\cite{Land:2012}, and so activation was assumed instantaneous for simplicity and to improve computational tractability.

%
%
%
\section{Boundary conditions}\label{sec:ch2boundaryconditions}
We applied spatial boundary conditions to the mesh throughout the mechanics solution process. Specifically, we constrained all the ventricles basal plane mesh nodes along the apex-base axis and allowed no movement along any direction for one node on the interior LV wall. This constraint prevented free rotation and translation without limiting the deformation~\cite{Land:2012}.

\vspace{0.2cm}
We also set haemodynamic boundary conditions to control blood flow and pressures at the computational domain boundaries, thereby coupling the biventricular heart with the rest of the body circulatory system. We used a \textit{three-element windkessel model}~\cite{Westerhof:1971} to regulate ejection, and we used the windkessel model generalised formulation (equation~\eqref{eq:windkgeneral}) to regulate the other phases of the cardiac cycle, namely initial preload filling, isovolumetric contraction, isovolumetric relaxation and diastolic filling, as described in Section~\ref{sec:hemodynamics_math_modelling}. The RV boundary condition pressures (atrial and pulmonary artery) were set to be $1/3$ of the equivalent LV values and the RV windkessel parameters were scaled to be equal to $R/3$, $Z/3$, $3C$ from the reference LV windkessel parameter set ($R$, $Z$, $C$) as done in~\cite{Land:2015*b}, based on typical pressure differences between the ventricles~\cite{Sia:2002}.

%
%
%
\section{Numerical solvers}\label{sec:ch2numericalsolver}
We solved the whole-ventricles mechanics problem using \texttt{elecmech}~\cite{Land:2012*a, Land:2015*b}, an in-house software package developed at King's College London. This uses the standard \textit{Galerkin finite element method} to numerically solve the partial differential equations describing the solid mechanics problem. In particular, trilinear basis functions are used for the incompressibility constraint weak form, while tricubic Hermite basis functions are used for the weak form associated to the balance of stress to ensures continuity of the stresses and strains in the solution. In short, \texttt{elecmech} uses a $Q3-Q1$ formulation with Lagrange multiplier and penalty term~\cite{Land:2015}. The weak form integrals are approximated using \textit{Gaussian quadrature} at $4\times 4\times 4$ points, and the resulting non-linear system is solved for displacements and pressures using the \textit{Newton method} combined with a simple \textit{line search method} which repeatedly halves the search step to prevent the residual from increasing too much. The ODE system associated to the cell contraction model is solved using a standard \textit{fixed-point iterations} on a \textit{Crank-Nicolson scheme}, with an adaptive time stepping scheme which decreases the time step temporarily when slow convergence is detected. The default time step for the mechanics problem (when not adaptively changing) is $\SI{0.1}{\milli\second}$. Cubic Hermite finite-element meshes are used as the computational domain for \texttt{elecmech}. In this thesis, the two used biventricular meshes (Chapter~\ref{cha:chapter4}) were derived from magnetic resonance images with dimension of $128\times 128\times 9$ voxels and spacing of $0.39\times 0.39\times \SI{1.5}{\cubic\milli\meter}$. The meshes' resolution was $2$, $12$ and $6$ elements in the radial, circumferential and longitudinal directions, respectively. The meshes had $108$ elements and $174$/$177$ nodes, and collapsed elements were used in the apex of the left ventricle.

%
%
%
\section{Simulation protocol}\label{sec:ch2simulationprotocol}
The whole-organ complete cardiac cycle was simulated using the protocol described in~\cite{Land:2012, Lewalle:2018}. Briefly, dynamic changes in the LV and RV cavities' boundary conditions were cyclically applied. During diastole, a fixed atrial preload pressure and filling resistance was applied. At activation, the cavity boundary conditions were switched to an isovolumetric constraint in both chambers. When each chamber reached pre-set aortic and pulmonary artery pressures, a three-element windkessel model boundary condition was applied to each chamber to represent the aortic and pulmonary artery afterload. Once each chamber stopped ejecting, an isovolumetric boundary condition was applied to represent isovolumetric relaxation. Once the cavity pressure fell below its respective atrial pressure, the heart returned to the diastolic cavity boundary conditions to complete the PV loop.

%
%
%
\section{Summary}\label{sec:ch2summary}
We modelled the rat heart using a $3$D biventricular contraction mechanics model. Cellular electrophysiology was simulated using the Gattoni et al.~\cite{Gattoni:2016} model of rat LV myocytes at $\SI{37}{\celsius}$ and $\SI{6}{\hertz}$ pacing frequency. Active tension generation was described using the Land et al.~\cite{Land:2012} model of sarcomere contraction. LV and RV anatomy was represented by a cubic Hermite finite element mesh~\cite{Lamata:2011}. Rule-based fibres~\cite{Bayer:2012} were included with a transmural variation of $\SI{-60}{\degree}$ to $\SI{80}{\degree}$ from epicardium to endocardium. Passive material properties were modelled using the Guccione transversely isotropic cardiac strain energy function~\cite{Guccione:1991}, combined with a Lagrange multiplier scheme and a penalty term~\cite{Land:2015*b}. The $\Ca$ transient was assumed not to vary spatially, and it homogeneously activated contraction throughout the ventricular walls. Spatial boundary conditions were applied by constraining the movement of specific mesh nodes, and haemodynamic boundary conditions were described by a generalised three-element windkessel model~\cite{Westerhof:1991}. The resulting multi-scale model of coupled electromechanics was simulated using \texttt{elecmech} software package~\cite{Land:2012*a}.


\documentclass{beamer}

\usepackage[utf8]{inputenc}
\usepackage{ragged2e} %for justifying texts within frame usage
\usepackage{etoolbox}
\apptocmd{\frame}{}{\justifying}{} % Allow optional arguments after frame.
\usepackage{hyperref}
\usetheme{Madrid}
\usepackage{appendixnumberbeamer}
\DeclareMathOperator{\Tr}{Tr}

%Information to be included in the title page:
\title[Data Preprocessing]{Data Preprocessing for}
\subtitle{Pose Estimation \& Prediction with Geodesic Regression on SE(3)}
\author{Wu Shuang}
\date{May 2018}

\begin{document}

\frame{\titlepage}
\AtBeginSection[]
{
\begin{frame}
\frametitle{Table of Contents}
\tableofcontents[currentsection]
\end{frame}
}

\section{Preliminaries}

\begin{frame}
\frametitle{Modelling Articulate Objects with Kinematic Chains}
\begin{itemize}
	\justifying
	\item The problem of 3D pose estimation / prediction in articulate objects assumes an anatomically motivated skeletal structure.
	\item The predefined set of keypoints correspond to joint locations of the skeletal structure.
	\item A kinematic chain is a model for the skeletal structure (an assembly of bones connected and constrained by the joints).
	\item Since bones are rigid, any pose configuration can be represented as an ordered set of rigid transformations.
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Illustration of Skeletal Models}
\begin{figure}[H]
\centering
\includegraphics[width=0.9\textwidth]{Figures/models.pdf}
%\vspace{-3mm}
\caption
{An illustration of the skeletal models adopted for three different articulate objects: (from left to right) fish, mouse, and human hand. }
\label{fig:skeletalmodel}
\end{figure}
The rigid transformation connecting two joints is an element of the Special Euclidean SE(3) Lie group. Moving along a root joint to an end effector constitutes a kinematic chain and the ordered set of SE(3) transformations characterizes the pose.
\end{frame}

\begin{frame}
\frametitle{Rigid transformations and SE(3) group}
\begin{itemize}
\justifying
\item A rigid transformation in 3D consists of a rotation and a translation.
\item Any rigid transformation can be represented as matrices of the form $$\left(\begin{matrix} R & T \\ 0 & 1 \end{matrix}\right)$$
where $R$ is a $3\times3$ rotation matrix and $T$ is a 3D translation vector.
\item The set of all rigid transformations, together with the composition operation is a group structure known as the SE(3) group.
\end{itemize}
\begin{block}{Remark}
\justifying
In the above representation, composition of rigid transformations correspond to matrix multiplication. Check that SE(3) matrices indeed form a group.
\end{block}
\end{frame}

\begin{frame}
\frametitle{$\mathfrak{se}(3)$ Lie algebra}
\begin{itemize}
\justifying
\item In addition to its group structure, SE(3) also has a manifold structure (locally resembles \footnote{The technical term is diffeomorphism. An intuitive example of a manifold is the Earth which, as a spherical manifold, locally resembles a plane.} $\mathbb{R}^n$).
\item Technically, SE(3) is known as a Lie group and the tangent space at its identity is known as its Lie algebra $\mathfrak{se}(3)$.
\item The dimension of SE(3) and $\mathfrak{se}(3)$ is 6; every rigid transformation can be fully parametrized by 6 Lie algebra parameters.
\item The goal is to obtain the Lie algebra parametrization of a pose given the 3D joint locations (inverse kinematics) and vice versa (forward kinematics).
\end{itemize}
\begin{block}{Remark}
\justifying
Lie groups are geometric objects, i.e. manifolds while Lie algebras are linear objects, i.e. vector spaces. For this reason, it is advantageous to use Lie algebra parameters over the SE(3) matrix representation.
\end{block}
\end{frame}

\begin{frame} [label=SEtose]
\frametitle{Connecting the SE(3) matrix representation and $\mathfrak{se}(3)$ parameters}
\begin{itemize}
\justifying
\item The matrix exponential is a surjective map from $\mathfrak{se}(3)$ to SE(3) and the inverse is given by the matrix logarithm map.
\item Given $\left(\begin{matrix} R & T \\ 0 & 1 \end{matrix}\right)$, we obtain the $\mathfrak{se}(3)$ parametrization $\xi=\left(\begin{matrix} \omega \\ t \end{matrix}\right)$ where $\omega$ corresponds to the \href{https://en.wikipedia.org/wiki/Axis-angle_representation}{\alert{axis-angle representation}} of the rotation $R$ while $t$ can be identified with $T$ \footnote{Technically, $t\neq T$ but the correct expression for $t$ will not be useful for our project. For all practical purpose, it is sufficient to assign $t=T$.}.
\item For the axis-angle representation $\omega =\theta\hat{n}$, the angle of rotation is given by $\theta=\arccos\left(\frac{\Tr(R)-1}{2}\right)$ while the axis is given by
$$\hat{n}=\frac{1}{2\sin\theta}\left(\begin{matrix} R(3,2)- R(2,3) \\ R(1,3) -R(3,1) \\ R(2,1) - R(1,2) \end{matrix}\right).$$
\end{itemize}
\end{frame}

\begin{frame} [label=omegatoR]
\frametitle{Connecting the SE(3) matrix representation and $\mathfrak{se}(3)$ parameters}
\begin{itemize}
\justifying
\item Given the axis-angle representation $\omega =\theta\hat{n}$, the rotation matrix is obtained as $$R=I+\sin\theta\hat{n}_{\times}+(1-\cos\theta)\hat{n}_{\times}^2$$ where
$$\hat{n}_{\times}=\left(\begin{matrix}0 & -\hat{n}_3 & \hat{n}_2 \\ \hat{n}_3 & 0 & -\hat{n}_1 \\ -\hat{n}_2 & \hat{n}_1 & 0\end{matrix}\right).$$
\end{itemize}
\end{frame}

\section{Inverse Kinematics}
\begin{frame}
\frametitle{Parametrizing a Kinematic Chain with $\mathfrak{se}(3)$}
\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{Figures/KinematicChain.png}
%\vspace{-3mm}
\caption
{An illustration of a kinematic chain with n+1 joints and n bones; n=3.}
\label{fig:kinematicchain}
\end{figure}
\begin{itemize}
\justifying
\item Joint 0: Base joint, Joint 1-2: Internal joints, Joint 3: End effector
\item A local coordinate system is defined at each joint such that the x-axis of joint $i$ aligns with bone $i+1$.
\item The coordinate transformation is effectuated by $\xi_i$:\\
$\xi_0$ transforms the world reference frame to the local coordinates system of at joint 0; $\xi_1$ transforms the local coordinates system at joint 0 to the local coordinates system at joint 1 and so on $\cdots$
\end{itemize}
\end{frame}
\begin{frame}
Now you are ready to implement the inverse kinematics in \href{run:./inverse.m}{\beamerbutton{inverse.m}}.

If you need hints, click
%\hyperlink{inverse}{\beamerbutton{here}}.
\hyperref{Supplementary.pdf}{page}{1}{\beamerbutton{here}}.
\end{frame}

\section{Forward Kinematics}
\begin{frame}{Computing Joint Locations given $\mathfrak{se}(3)$ parameters}
Once you have obtained the $\mathfrak{se}(3)$ parameters, implement the forward kinematics in \href{run:./forward.m}{\beamerbutton{forward.m}}.

If you need hints, click
%\hyperlink{forward}{\beamerbutton{here}}.
\hyperref{Supplementary.pdf}{page}{2}{\beamerbutton{here}}.
\end{frame}

\appendix
\begin{frame} <0> [label=inverse]
\frametitle{Supplementary Details on Inverse Kinematics}
Click \href[page=11]{DataPreprocessing.pdf}{\beamerbutton{here}} to go back.
\begin{itemize}
\justifying
\item $t_0$ is just the coordinates of joint 0 in the world reference frame.
\item For $i>0$, $t_i=\left(\begin{matrix} l_i \\ 0 \\ 0 \end{matrix}\right)$ where $l_i$ is the length of the $i$-th bone.
\item To compute the axis-angle parameters $\omega_i$, denote the unit vectors of bone $i$ and $i+1$ as $u,v$ respectively. Bone $0$ is $\hat{x}=\left(\begin{matrix} 1 \\ 0 \\ 0 \end{matrix}\right)$. The axis-angle parameters aligning the x-axis of reference frames from joint $i$ to joint $i+1$ is given by $\frac{u\times v}{\lVert u\times v \rVert} \arccos(u\cdot v)$.
\item Hint: Do this in reverse fashion, i.e. start by finding the parameters for aligning the last bone.
\end{itemize}
\end{frame}

\begin{frame} <0> [label=forward]
\frametitle{Supplementary Details on Forward Kinematics}
Click \href[page=13]{DataPreprocessing.pdf}{\beamerbutton{here}} to go back.
\begin{itemize}
\justifying
\item Given $\xi=\left(\begin{matrix} \omega \\ t \end{matrix}\right)\in\mathfrak{se}(3)$, the SE(3) matrix representation is $$e^{\xi}\equiv\left(\begin{matrix} R(\xi) & T \\ 0 & 1 \end{matrix}\right)$$ where $R(\xi)$ is given in \hyperlink{omegatoR}{\beamerbutton{the axis-angle representation}}.
\item The 3D coordinates of joint $i$ in the world reference frame is simply given by the first 3 entries in
$$e^{\xi_0}e^{\xi_1} \cdots e^{\xi_i} \left(\begin{matrix} 0 \\ 0 \\ 0 \\1 \end{matrix}\right).$$
\item Why?
\end{itemize}
\end{frame}

\end{document}