%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PHOTOIONISATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Computing $\mbox{\boldmath $f''(\omega)$ } $}
From equation~\ref{eq:fpp-sigma} we see that in order to determine the imaginary
component of the anomalous form factor $f''$ we need to know the total
photoionisation cross section. Therefore the basic tool that is required is the
computation of the photo-electric matrix element which will give as the
photoionisation amplitude. This matrix element can then be used in two
approaches to computing $f''$ such as:
\begin{itemize}
    \item Relativistic First Order Perturbation Theory
    \item Second Order S-Matrix Theory
\end{itemize}
We have concentrated on obtaining results for the form factor
using second order S-Matrix theory.
The purpose is to attempt to obtain analytic solutions to these problems.
Numerical techniques will be used when it is no longer possible to solve a
problem analytically.

\section{Amplitude for Photoionisation}
The relativistic photon absorption and emission operators for many electron atoms are
defined~\cite{Kissel-S-Matrix} as:
\begin{eqnarray} \label{eq:photon-abs-emis}
    \mathcal{A}_i       & = & \sum_j \Alpha \cdot \hat{\epsilon}_j \Exp{k_i}{r_j} \\
    \mathcal{A}_f^{\dag}   & = & \sum_j \Alpha \cdot \hat{\epsilon}_j \ExpM{k_f}{r_j}
\end{eqnarray}
where the sum is over all the electrons in an atom, $\Alpha$ is the Dirac alpha
matrix, $\mb{r_j}$ is the position of the $j$-th electron, $\hat{\epsilon}_j$ is
the polarisation of the photon and $\mb{k}$ is the wave vector of the photon.
The subscripts $i$ and $f$ indicate initial and final states respectively. This
is needed if we are considering for example Compton (inelastic) scattering where
the momentum of the photon changes in a scattering process. However, for the
case of Rayleigh scattering the photon momentum is unchanged
($\hbar \omega_i = \hbar \omega_f$) and as such in this case we drop the
subscripts and just use the symbols $\omega$ and $\mb{k}$.
\begin{figure}[h]
    \begin{center}
        \includegraphics[angle=-90,width=7cm]{coords.eps}
    \end{center}
    \caption{Coordinate System for Photoionisation~\cite{Bransden-Joachain}}
    \label{fig:coordinates}
\end{figure}

We also need to define the coordinate system to be used to describe
photoionisation. The coordinate system setup is shown in figure~\ref{fig:coordinates}.
The small case angles $(\theta,\phi)$ are used to describe the
angular position of an electron bound to an atom, whereas the angles
$(\Theta,\Phi)$ are used to describe the electron ejected angle.
We make the following assumptions:
\begin{itemize}
    \item The incident photon has energy $\hbar \omega$ and is traveling
          in the $+Z$ direction with a momentum wave-vector
          $\mb{k} = (k_x,k_y,k_z)$.
    \item The photon has a constant well defined polarisation. We will consider photon
          polarisations in the $x$ and $y$ directions.
    \item The ejected electron has a wave-vector $\mb{k'} = {k'_x,k'_y,k'_y}$
          which defines its linear momentum and ejection direction/angles since:
          \begin{equation} \label{eq:ejection-angles}
          \begin{array}{cccc}
            k'_x & = & |k'| \sin(\Theta) \cos(\Phi) & \\
            k'_y & = & |k'| \sin(\Theta) \sin(\Phi) & \\
            k'_z & = & |k'| \cos(\Theta)&
          \end{array}
          \end{equation}
    \item The atom is initially in it's ground state, and is represented by a
          $\ket{1S_{1/2}}$ (or $\ket{0}$ or $\psi_0$) wave-function
          (non relativistic or relativistic).
    \item After photoionisation the ejected electron will be represented by a
          continuum (or free electron) state $\ket{c}$ (or $\psi_c$),
          (non relativistic or relativistic).
\end{itemize}

\subsection{Photoionisation to a Continuum State}
    We first consider the first order photo-electric matrix element for a single
    electron atom using~\ref{eq:photon-abs-emis}:
    \(
        A_1 = \bra{\psi_c} \mathcal{A} \ket{\psi_0} = \bra{\psi_c} \Exp{k}{r} \Alpha_j \ket{\psi_0} .
    \)
    In the case that the incident photon is polarised either in the $x$ or $y$
    direction, and knowing that the second components of the ground state
    and continuum states are both zero ($\psi_{02} = 0$ and $\psi_{c2} = 0$)
    results in the following form for $A_1$:
    \[
        A_1 = \bra{\psi_c} \Exp{k}{r} \Alpha_j \ket{\psi_0} =
        \left\{
        \begin{array}{llllll}

            \int \state{c}{1}^{*} \Exp{k}{r} \state{0}{4} \; d^3 \mb{r}
            & + &
            \int \state{c}{4}^{*} \Exp{k}{r} \state{0}{1} \; d^3 \mb{r}
            & = & m_1 + m_2
            & \mbox{, if $j = x$}

            \\[3mm]

            -i \int \state{c}{1}^{*} \Exp{k}{r} \state{0}{4} \; d^3 \mb{r}
            & + &
             i \int \state{c}{4}^{*} \Exp{k}{r} \state{0}{1} \; d^3 \mb{r}
            & = & -i m_1 + i m_2
            & \mbox{, if $j = y$}

        \end{array}
        \right .
    \]
    With known values for the spinor components $\state{c}{1}$, $\state{c}{4}$,
    $\state{0}{1}$ and $\state{0}{4}$ we can determine the integrals $m_1$ and
    $m_2$.

    With $\state{c}{1}^{*} = \ExpM{k'}{r}$ and
    $\state{0}{4} = -i\sqrt{\frac{2}{3}} Y_{11}(\theta,\phi) f_0(r)
                  =  \frac{i}{\sqrt{4 \pi}} \sin(\theta) e^{i \phi} f_0(r)$
    we obtain for the $m_1$ integral:
    \[
    m_1 = \frac{i}{\sqrt{4\pi}} \int \sin(\theta)
          e^{i \phi} \Exp{k}{r} \ExpM{k'}{r} f_0(r) \; d^3 \mb{r}
    \]
    To do the integration we change to spherical polar coordinates,
    $\mb{r} = r (\sin\phi \cos\theta,\sin\phi \sin\theta, \cos\phi)$, and we
    define
    \begin{equation}
        \Muq = q_x \sin\phi \cos\theta +
               q_y \sin\phi \sin\theta +
               q_z \cos\phi
    \end{equation}
    where $\mb{q} = \mb{k} - \mb{k'} = (q_x,q_y,q_z)$.
    Using the definition of $\Muq$ and using
    $f_0(r) = F_0 G_0 r^{\gamma_1 - 1} e^{-\frac{1}{2}\sigma_1 r}$, $m_1$
becomes:
    \[
    m_1 = F_0 G_0 \frac{i}{\sqrt{4\pi}} \int
          \sin(\theta) e^{i\phi} e^{i\Muq} r^{\gamma_1 - 1}
          e^{-\frac{1}{2}\sigma_1 r} \; d^3 \mb{r}
    \]
    We can now convert the integral over all space into one using spherical
    polar coordinates.
    \[
    m_1 = F_0 G_0 \frac{i}{\sqrt{4\pi}}
          \int_{0}^{2\pi}
          \int_{0}^{\pi}
          \int_{0}^{\infty}
            \sin^2(\theta) e^{i\phi} r^{\gamma_1 + 1}
            e^{-[ \frac{1}{2}\sigma_1 - i \Muq ] r }
          \; dr \; d\theta \; d\phi
    \]
    The angular integrations over $\theta$ and $\phi$ cannot be solved
    analytically due to the fact that $\Muq$ is a non simple function
    of $\theta$ and $\phi$. However, using the fact that
    \(
        \int_0^\infty e^{-ax} dx = \Gamma(n+1)/a^{n+1}
    \)
    the radial integral can be solved.
    \[
    m_1 = \frac{i}{\sqrt{4\pi}} F_0 G_0 \Gamma(\gamma_1 + 2)
          \int_{0}^{2\pi}
          \int_{0}^{\pi}
            \left[
                \frac{\sin^2(\theta) e^{i\phi} }{
                    \left(
                        \frac{1}{2} \sigma_1 - i \Muq
                    \right)^{\gamma_1 + 2}
                }
            \right]
          \; d\theta
          \; d\phi
    \]

    We can determine the integral $m_2$ following a similar process to that used
    to determine $m_1$. In the case of $m_2$ the spinor components are given by
    $\state{c}{4}^{*} = \xi(k'_x - ik'_y)\ExpM{k'}{r}$ and
    $\state{0}{1} = Y_{00}g_0(r)
                  = \frac{1}{\sqrt{4\pi}} G_0
                     e^{-\frac{1}{2}\sigma_1 r} r^{\gamma_1 - 1}$
    we obtain for $m_2$:
    \[
    m_2 = \frac{\xi(k'_x -ik'_y)}{\sqrt{4\pi}} G_0 \Gamma(\gamma_1 + 2)
          \int_{0}^{2\pi}
          \int_{0}^{\pi}
            \left[
                \frac{\sin(\theta) }{
                    \left(
                        \frac{1}{2} \sigma_1 - i \Muq
                    \right)^{\gamma_1 + 2}
                }
            \right]
          \; d\theta
          \; d\phi
    \]

    Using $m_1$ and $m_2$ we can obtain an equation for the first order
    photo-electric amplitude $A_1(\mb{k},\mb{k'})_j$, where $j$ denotes
    the polarisation direction.

        % X DIRECTION

    \begin{equation} \label{eq:A1-X}
    \boxed{
    A_1(\mb{k},\mb{k'})_x =
    \frac{G_0 \Gamma(\gamma_1 + 2)}{\sqrt{4\pi}}
    \int_{0}^{2\pi}
    \int_{0}^{\pi}
        \left[
            \frac {
            \sin(\theta) [ \xi(k'_x - ik'_y) + i F_0 \sin(\theta) e^{i\phi} ]
%                i F_0 \sin^2(\theta) e^{i\phi} + \xi(k'_x - ik'_y)\sin(\theta)
            } {
                (\frac{1}{2}\sigma_1 - i \Muq )^{\gamma_1 + 2}
            }
       \right]
    \; d\theta
    \; d\phi
    }
    \end{equation}

        % Y DIRECTION

    \begin{equation} \label{eq:A1-Y}
    \boxed{
    A_1(\mb{k},\mb{k'})_y =
    \frac{G_0 \Gamma(\gamma_1 + 2)}{\sqrt{4\pi}}
    \int_{0}^{2\pi}
    \int_{0}^{\pi}
        \left[
            \frac
            {
            i \sin(\theta) [ \xi(k'_x - ik'_y) - i F_0 \sin(\theta) e^{i\phi} ]
%                F_0 \sin^2(\theta) e^{i\phi} + \xi(k'_y + ik'_x)\sin(\theta)
            } {
                (\frac{1}{2}\sigma_1 - i \Muq )^{\gamma_1 + 2}
            }
        \right]
    \; d\theta
    \; d\phi
    }
    \end{equation}
    These results have been derived without any approximations to the plane wave
    form of the electromagnetic field ($\Exp{k}{r}$) in the absorption and
    emission operators. This is the ``all poles'' approach.
    In the electric dipole (E1) approximation we have $\Exp{k}{r} \approx 1$.
    We can interpret this as having no information about the propagation
    direction of the incident photon and hence in the electric dipole
    approximation $\mb{k} = 0$.
    Therefore to obtain results for the electric dipole approximation from
    equations~\ref{eq:A1-X} and~\ref{eq:A1-Y} it is simply a matter of
    setting $\mb{k} = 0$.
    \begin{equation} \label{eq:A1-Dipole}
    \boxed{
        A_1^{E1}(\mb{k},\mb{k'})_j = A_1(0,\mb{k'})_j
    }
    \end{equation}

\subsection{Photoionisation in the Forward Scattering Direction}
The integrals $m_1$ and $m_2$ defined in the previous section cannot be solved
analytically in general. However, it is possible to obtain an analytic solution
for some special cases. One such case is when the incident photon is traveling
in the $+z$-direction with a propagation vector $k\hat{\mb{n}} = (0,0,k)$ and
the electron is ejected in the $\Theta = 0$ (or forward scattering direction).
In this case, the propagation vector for the ejected electron is
$k'\hat{\mb{n}}' = (0,0,k')$.

We note from these assumptions that the integral $m_2 = 0$ because it is
multiplied by the factor $\xi (k_x' - i k_y')$ and in the forward scattering
direction $k_x' = 0$ and $k_y' = 0$. We also note that the the function $\Muq$
is simplified to $\Muq = q_z \cos(\theta)$. We these new assumption we can
rewrite the integral for $m_1$ and attempt an analytic solution.
\[
    m_1 = \frac{i}{\sqrt{4\pi}}
    \int_{0}^{\infty}
    \int_{0}^{2\pi}
    \int_{0}^{\pi}
        \sin^2(\theta) e^{iq_z \cos(\theta)} e^{i\phi} r^2 f_0(r)
    \; d\theta
    \; d\phi
    \; dr
\]
Integrating over $\phi$ gives $2i$ and making use of the trigonometric
identity $2\sin^2(\theta) = 1-\cos(\theta)$, $m_1$ can be written as:
\begin{eqnarray*}
    m_1 & = & \frac{-2}{\sqrt{4\pi}}
    \int_0^\infty
        f_0(r) r^2
        \left[
            \frac{1}{2}
            \int_0^\pi
                e^{i q_z r \cos(\theta) }
            \; d\theta
            +
            \frac{1}{2}
            \int_0^\pi
                \cos(2\theta) e^{i q_z r \cos(\theta) }
            \; d\theta
        \right]
    \; dr
    \\
    & = &
    \frac{-2}{\sqrt{4\pi}}
    \int_0^\infty
    f_0(r) r^2
    \left[
        \frac{1}{2} ( \pi J_0(q_z r)  +  \pi J_2(q_z r) )
    \right]
    \; dr
    \\
    & = &
    \frac{-\pi F_0 G_0}{\sqrt{4\pi}}
    \left[
        \int_0^\infty
            J_0(q_z r) r^{\gamma_1 + 1} e^{-\frac{1}{2} \sigma_1 r}
        \; dr
        +
        \int_0^\infty
            J_2(q_z r) r^{\gamma_1 + 1} e^{-\frac{1}{2} \sigma_1 r}
        \; dr
    \right]
\end{eqnarray*}
where $J_n(x)$ is a Bessel function of the first kind of order $n$.
The integrals involving the Bessel functions can be solved in terms of the
hypergeometric function $_2 F_1(a,b;c;z)$~\footnote{These integrals were solved
using Mathematica 3.0}. Since $m_2$ is zero, the first order amplitude is given
in terms of $m_1$, where we have $A(k,k')_x = m_1$ and $A(k,k')_y = -i m_1$, for
photon polarisations in the $x$ and $y$ directions respectively.
Using this information, and substituting in the for the constants $F_0$,
$G_0$ and $\sigma_1$ which were defined earlier, the analytic solutions
for the first order photo-electric matrix elements in the forward scattering
direction are given by:
\begin{equation} \label{eq:A1-Forward}
\boxed{
\begin{split}
     A_1 & (k,k')_x  =  \frac{\pi}{\sqrt{\pi}}
                        \left( \frac{2Z}{a_0} \right)^{3/2}
                        \sqrt{ \frac{1 - \epsilon_1}{
                                    2 \Gamma(2\gamma_1 + 1)
                               } } \times \\
    & \Biggl\{
        \left( \frac{Z}{a_0} \right)^{-(\gamma_1 + 2)}
    \Gamma(\gamma_1 + 2)
    \; _2 F_1 \left(
                \frac{\gamma_1 + 2}{2} ,
                \frac{\gamma_1 + 3}{2} ;
                1 ;
                - \left(
                    \frac{2a_0}{Z}
                \right)^2
                (k - k')^2
           \right)
    + \\ &
    \frac{1}{8} (k - k')^2
    \left( \frac{Z}{a_0} \right)^{-(\gamma_1 + 4)}
    \Gamma(\gamma_1 + 4)
    \; _2 F_1 \left(
                \frac{\gamma_1 + 4}{2} ,
                \frac{\gamma_1 + 5}{2} ;
                1 ;
                - \left( \frac{2a_0}{Z} \right)^2
                (k - k')^2
            \right)
    \Biggr\}
\end{split}
}
\end{equation}
\begin{equation}
\boxed{
    A_1(k,k')_y = -i A_1(k,k')_x
}
\end{equation}
This implies that in the forward scattering direction, the probability of
photoionisation is the same for a photon polarised in the $x$ or $y$ direction,
because \( |A_1(k,k')_x|^2 = |A_1(k,k')_y|^2 \).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% S-MATRIX THEORY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{S-Matrix Theory}
S-matrix theory as developed in covariant perturbation theory (or quantum field
theory) is used to solve a large number of scattering problems in quantum
mechanics~\cite{Sakurai-Advanced,Greiner,Yndurain,Akhiezer,Weinberg}.
The use of S-matrix theory to compute atomic form factors has been applied by
Kissel and Pratt~\cite{Kissel-S-Matrix}.
For a given photon of energy $\hbar \omega$ the second order S-matrix (scattering)
amplitude $A_2(\omega)$ is related to the imaginary component of the form factor
$f''(\omega)$ and to the total cross section $\sigma^{TOT}(\omega)$ through the
following relation:
\begin{equation}
    \mathrm{Im} A_2(\omega) = r_0 f''(\omega) = \frac{\omega}{4 \pi c} \sigma^{TOT}(\omega)
\end{equation}
The relationship between the total cross section and $f''(\omega)$ is the same
as equation~\ref{eq:fpp-sigma}. Although here we will only be considering the
photoionisation cross section, $\sigma^{TOT}(\omega)$ may also include partial cross
section contributions from other process such as bound-bound transitions.
In addition to this we also have that:
\begin{itemize}
    \item The second order amplitude considers only the forward scattering direction.\\
          $A_2(\omega) = A_2(\omega,\Theta=0)$.
    \item The sign of $f''$ as define by Kissel and Pratt~\cite{Kissel-S-Matrix}
          is opposite of that used in the crystallography literature
          $(f''_{Kissel} = -f''_{cl})$. We will follow the convention of the
          crystallography community.
    literature.
\end{itemize}

The second order S-matrix amplitude is defined as follows:
\begin{equation}
     A_2 =
     -r_0 mc^2 \sum_p
     \left[
     \frac{
        \bra{m} \mathcal{A}_f^\dag \ket{p}
        \bra{p} \mathcal{A}_i \ket{n}
     }{
        E_n - E_p + \hbar\omega_f + i0_+
     }
     +
     \frac{
        \bra{m} \mathcal{A}_i \ket{p}
        \bra{p} \mathcal{A}_f^\dag \ket{n}
     }{
        E_n - E_p - \hbar\omega_i + i0_+
     }
     \right]
\end{equation}
where the state $\ket{\psi}$ is a four component relativistic spinor which
satisfies the Dirac equation (equation~\ref{eq:dirac-equation}). The equation describes a second
order scattering process with the subscript $i$ denoting the initial situation
and $f$ denoting the final situation. The two components correspond to the
processes of photoabsorption followed by photoemission, and photoemission
followed by photoabsorption, as shown in the Feynmann diagrams in
figure~\ref{fig:feynmann}.
\begin{figure}[h]
    \begin{center}
        \includegraphics[angle=-90,width=7.0cm]{feynmann.eps}
    \end{center}
    \caption{Second Order Photon Scattering}
    \label{fig:feynmann}
\end{figure}

The initial state of the atom (which we will make
the ground state) is $\ket{n}$, the final state is $\ket{m}$ and we have
a sum of all intermediate states $\ket{p}$. The energy of the initial state is
$E_n$, the energy of the intermediate states is $E_p$, and initial and and final
energy of the photon are $\hbar \omega_i$ and $\hbar \omega_f$ respectively.
The denominator of both components of $A_2(\omega)$ includes a small complex
positive value $i0_+$.

For the case of Rayleigh scattering,
$\hbar \omega_i = \hbar \omega_f = \hbar \omega$, and the final atomic state is the
same as the the initial atomic state ($\ket{n} = \ket{m}$).
We can then define the form factor $f''$ in terms of the second order elastic
(Rayleigh) S-matrix $\mathrm{Im}A_2^R(\omega)$.
\begin{equation}
    f''(\omega) = \frac{\mathrm{Im}A_2^R(\omega)}{r_0}
                = \frac{\omega}{4\pi c r_0} \sigma^{TOT}(\omega)
\end{equation}
If the initial state is the ground state of the hydrogen atom $\ket{\psi_0}$,
and we substitute in for the the emission and absorption operators previously
defined (without the summation since we only have a single electron) we
obtain:
\begin{equation}
        A_2^R(\omega) =
        -r_0 mc^2 \sum_p \left[
        \frac{
            \bra{\psi_0} \ExpM{k}{r} \Alpha_j \ket{\psi_p}
            \bra{\psi_p} \Exp{k}{r}  \Alpha_j \ket{\psi_0}
        }{
            E_0 - E_p + \hbar\omega + i0_+
        }
     +
        \frac{
           \bra{\psi_0} \Exp{k}{r}   \Alpha_j \ket{\psi_p}
           \bra{\psi_p} \ExpM{k}{r}  \Alpha_j \ket{\psi_0}
        }{
           E_0 - E_p - \hbar\omega - i0_+
        }
        \right]
\end{equation}
Making use of
\(
    \bra{a} X^\dag \ket{b} \bra{b} X \ket{a}
  = \bra{b} X \ket{a}^* \bra{b} X \ket{a} = | \bra{b} X \ket{a} |^2
\)
and splitting the sum into a sum over discrete states (bound excited states of
the hydrogen atom) and an integral over
continuum states ($\ket{\psi_c}$ is the free electron continuum state) we obtain:
%\begin{equation}
%\begin{split}
\begin{multline}
    A_2^R(\omega)   =
         -r_0 mc^2  \int_0^\infty
        \left[
             \frac{
            | \bra{\psi_c} \Exp{k}{r}  \Alpha_j \ket{\psi_0} |^2
        }{
            E_0 - E_c + \hbar\omega + i0_+
        }
        +
        \frac{
           | \bra{\psi_c} \ExpM{k}{r}  \Alpha_j \ket{\psi_0} |^2
        }{
           E_0 - E_c - \hbar\omega - i0_+
        }
        \right]
        dEc
        \\
         -r_0 mc^2  \sum_p
        \left[
        \frac{
            | \bra{\psi_p} \Exp{k}{r}  \Alpha_j \ket{\psi_0} |^2
        }{
            E_0 - E_p + \hbar\omega + i0_+
        }
     +
        \frac{
           | \bra{\psi_p} \ExpM{k}{r}  \Alpha_j \ket{\psi_0} |^2
        }{
           E_0 - E_p - \hbar\omega - i0_+
        }
        \right]
\end{multline}
%\end{split}
%\end{equation}
Ideally both continuum and bound-bound components would be included in
a calculation of the S-matrix amplitude. However, due to time constraints the
calculations focused on the continuum component. From the standard
non relativistic understanding of the photo-electric
effect~\cite{Sakurai-Modern,Kissel-S-Matrix,Chantler-Book} we know that the
ground state to continuum amplitude dominates over the bound-bound transition
amplitudes. However Chapter 5 of this report contains some results for
bound-bound, transitions which may be used as a basis for determining
atomic form factors.

Therefore, we can now write down the second order S-matrix amplitude which needs
be calculated. We see that the matrix elements in the numerators are simply
the first order photoionisation matrix elements
(equations~\ref{eq:A1-X},~\ref{eq:A1-Y},~\ref{eq:A1-Forward}) so we can write
the second order amplitude in terms of first order amplitudes.
($\omega = kc$).
\begin{equation} \label{eq:A2}
\boxed{
     A_2^R(\omega) = A_2(\mb{k},\mb{k'})_j =
         -r_0 mc^2
        \left[
        \int_0^\infty
             \frac{
             | A_1(\mb{k},\mb{k'})_j |^2
        }{
            E_0 - E_c + \hbar\omega + i0_+
        }
        dEc
        +
        \int_0^\infty
        \frac{
            |A_1(\mb{-k},\mb{k'})_j |^2
        }{
           E_0 - E_c - \hbar\omega - i0_+
        }
        dEc
        \right]
}
\end{equation}
The second order amplitude for the electric dipole approximation,
as for the first order matrix elements is simply given by setting $\mb{k}=0$.
\begin{equation} \label{eq:A2-Dipole}
    \boxed{
       A_2^{E1}(\mb{k},\mb{k'})_j  = A_2(0,\mb{k'})_j
    }
\end{equation}
\subsection{Computational Method}
To compute $f''$, we need to compute the value of equation~\ref{eq:A2}
over a range of photon energies ($\hbar \omega$),
take the imaginary component and then divide by $r_0$.
This was done by developing a computer program in the C++ language to perform
the computations using
numerical integration methods to solve the integrals in equations~\ref{eq:A1-X}
and~\ref{eq:A1-Y} and the integral over the continuum state (ejected electron
energies).
\begin{itemize}
    \item One of the main computation issues faced was the problem of multi
          dimensional integrals. Although there was a single outer integral
          over continuum energies to compute the first order matrix element
          required the numerical computation of a two dimensional angular integral.
    \item The integration methods used originally elementary algorithms
          based on the Simpson's and Trapezoidal rules. The main problem with
          these methods was computation speed and accuracy.
          Performance and accuracy of results improved when the integration
          routines where changed to a 10-point Gauss-Legendre
          integration method~\cite{Koonin}.
    \item The integration method used for the integral over continuum states
          had to handle integrating over a singularity. This was handled by
          implementing a numerical version of the Cauchy principal value
          technique~\cite{Engineering-Maths}. The integral was split into
          three regions, below the singularity, near the singularity and
          above the singularity to infinity. The integral to infinity was
          numerically by making an appropriate change of variable, changing
          the integral from one that was over an open interval to one that
          was over a closed interval.
    \item All the computations where done in atomic units (a.u.)
          giving the standard units of electrons/atom for $f''$.
          The energy axes in keV were converted after the computation
          was performed.
    \item Since $f''(\omega)$ is calculated using the imaginary component
          of the second order S-matrix amplitude the size of the small
          positive complex value $i0_+$ was expected to effect the results.
The pseudo-code below gives an outline of the depth level of all the
numerical integrations involved in the calculation, showing why computation
speed was an issue.
\end{itemize}
 \begin{verbatim}
    PROGRAM
    {
        For E = Min_Photon_Energy To Max_Photon_Energy With Step=EnergyStep
            Compute 2nd Order Matrix Element
                Integrate A2 Over All Continuum Energies
                    Compute 1st Order Matrix Element
                        Integrate Over Phi From 0 To 2Pi
                            Integrate Over Theta From 0 To Pi
    }
\end{verbatim}

\subsection{Results for $f''(\omega)$ and
            Possible Problems With S-Matrix Theory as Currently Implemented}
Figure~\ref{fig:compare-poles} shows a logplot the form factor ($\log_{10}(f'')$)
for a range of photon energies to 100 keV. The plot compares the result obtained
using the all poles approach with that obtained for $f''$ using the electric
dipole approximation. As can be seen, the all pole and electric dipole approach
are closer in agreement at lower energies. We expect that the electric dipole
approximation breaks down the higher the photon energy we have and this is
indeed the case in the results obtained. This is because the electric dipole
approximation makes the assumption that the wavelength of the photon is much
larger than the size of the atom it is interacting with. At higher energies,
and hence shorter wavelengths, this approximation begins to break down as
is evident in figure~\ref{fig:compare-poles}.
\begin{figure}[h]
\begin{center}
    \includegraphics[width=7cm]{compare_poles_1.eps}
\end{center}
    \caption{Relativistic Form Factor $f''$ -- Comparing Electric Dipole
            to All Poles Result}
    \label{fig:compare-poles}
\end{figure}
\begin{figure}[h]
\begin{center}
    \includegraphics[width=7cm]{compare_fpp_1.eps}
    \includegraphics[width=7cm]{compare_fpp_2.eps}
    \includegraphics[width=7cm]{compare_fpp_3.eps}
    \caption{Comparing Current Results for $f''$ with those of Chantler
             and those of Kissel and Pratt}
    \label{fig:fpp-compare}
\end{center}
\end{figure}
Figure~\ref{fig:fpp-compare} shows three plots of $f''(\omega)$ at an energy
range encompassing an edge (in this case the ionisation energy of the hydrogen
atom $E_0 = 13.6$ eV. The plots contain comparisons between these new results,
the S-matrix results of Kissel and Pratt~\cite{Kissel-S-Matrix}, and
the recent results of Chantler~\cite{Chantler-Tabulation}.
The three plots show the new results for three different values of the
small complex value $i0_+ = 7\times 10^{-8},8\times 10^{-8},9\times 10^{-8}$.
Clearly, the results are affected by the change in size of $i0_+$.
All three theories predict the correct edge at 13.6 eV, all qualitatively
have a similar shape, but there is disagreement between all three.

With regards to the new results, there clearly are some issues that need
to be addressed. The main one is the dependence on $i0_+$. One way to attempt
to solve this problem would be to try to change the integration scheme used
from a non-convergent method (Gauss-Legendre) used to obtain the current results
to a method such as a form of Romberg integration which converges to a result.
This may or may not fix the problem with regard to the size of $i0_+$.
If the problem still persists, then it could possibly suggest there are still
some problems with S-matrix theory as currently implemented in the area of
calculating atomic form factors.

\subsection{Results for Angular Dependence}
The mod-squared of the second order S-matrix element $|A_2(\mb{k},\mb{k'})_j|$
cannot also be used to study the angular distribution of the ejected electron
(or photoelectrons) at selected energies. We keep the direction
of the photon wave-vector the same ($\mb{k} = k(0,0,1)$) as when calculating
$f''$, just changing the magnitude for different photon energies.
However the ejected electron wave vector is described by the ejection
angles $(\Theta,\Phi)$ (see equation ~\ref{eq:ejection-angles}).
In the $f''$ case we were interested in the forward scattering direction
so we set $\Theta = 0$. Alternatively, we can set $\Phi = 0$ and vary
$\Theta$ over a range from $0$ to $2 \pi$.
This gives as an ejected electron angular distribution for all values of $\Theta$ in
the $\Phi = 0$ plane.

\begin{figure}[h]
\begin{center}
\begin{tabular}{cc}
    \includegraphics[width=7cm]{ang_100eV_both.eps}
    &
    \includegraphics[width=7cm]{ang_200eV_ap.eps}
    \\
    \includegraphics[width=7cm]{ang_500eV_ap.eps}
    &
    \includegraphics[width=7cm]{ang_1keV_ap.eps}
\end{tabular}
    \caption{Ejected Electron Angular Distributions at Photon Energies of
             100 eV, 200 eV, 500 eV and 1 keV}
    \label{fig:angular-plots}
\end{center}
\end{figure}

The results for $|A_2(\mb{k},\mb{k'})_j|$ at photon energies of
100 eV, 200 eV, 500 eV and 1 keV are shown in figure~\ref{fig:angular-plots}.
The top left plot for a photon energy of 100 eV also shows the distribution
for the electric dipole approximation.
At the lower energies we see that the plots exhibit a $\sin^2(\Theta)$
distribution. As the energy is increased we see finer definition
of the ejection lobes in all directions, indicating the very precise
directions of electron ejection.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% RELATIVISTIC PERTURBATION THEORY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\section{Relativistic Perturbation Theory}
%\begin{equation}
%    \frac{d\sigma}{d\Omega} =
%    \frac{\alpha k'}{2 m_e \pi \omega}
%    | \bra{\psi_c} \Exp{k}{r} \Alpha \cdot \hat{\epsilon}_j \ket{\psi_0} |^2
%    = \frac{\alpha k'}{2 m_e \pi \omega} |A_1(k,k')_j|^2
%\end{equation}


\subsection{Reorganization following removal or addition of neurons}

The final and most challenging experiment is to test how the RSOM can cope
with degenerative cases, where either neurons die out (removal) or new units are added to the map (addition). Figure~\ref{fig:reorganization:results}A illustrates an example of a well-formed neural space (black outlined discs), a removal (red disks) and an addition (black dots). For both removal and addition, we applied a LLoyd relaxation scheme to achieve a new quasi-centroidal Voronoi tesselation. Figures \ref{fig:reorganization:results}B and \ref{fig:reorganization:results}C depicts the Voronoi tesselations after $100$ iterations starting from the initial tesselation shown in panel \ref{fig:reorganization:results}A.

In order to conserve as much as possible the original topology, we used a differentiated procedure depending on if we are dealing with a removal or an addition. In case of removal, only the remaining neurons that were previously connected to a removed unit are allowed to connect to a new unit unconditionally. For the rest of the units, they might reconnect to a nearby unit if this unit is much closer than its closest current neighbour (85\% of the smallest distance to its current neighbours). In case of addition, new units can connect unconditionally to the nearest neighbours while old unit can only connect to the newly added unit if this unit is much closer than its current closest neighbour (85\% of the smallest distance to its current neighbours). This procedure guarantees that the topology is approximately conserved as shown in figures \ref{fig:reorganization:results}D-F. We tested the alternative of recomputing the graph from scratch but the resulting topology is quite different from the original because of micro-displacements of every units following the Lloyd relaxation.

Learning is performed in two steps. First we iterate $25,000$ epochs using the intact map, then we perform removal and addition and learning is iterated for another $5,000$ epochs for all three maps (orginal map, map with added units and map with removed units). The final self-organization is shown in figures \ref{fig:reorganization:results}G-I where we can observe strong similarities in the organization. For example, the central red patch is conserved in all three maps and the overall structure is visually similar. Of course, these results depend on the number of removed or added units (that needs to be relatively small compared to the size of the whole map) and their spatial distribution.
%\gid{the last two paragraphs are not too clear, they seem confusing}

%\gid{TODO Add a few more words here. Maybe make a connection to neuroscience facts about reorganization.} \npr{maybe in the discussion instead} \gid{Agreed} \nrp{Done}.

%Previous studies have shown that after an ablation or addition of units the map undergoes a reorganization of its neural representations. The immediate  consequence of a reorganization is the acquisition of new receptive fields. When an ablation takes place, unaffected neurons try to recover representations that got lost due to neurons death. In addition, on the other hand, the surplus neurons have to get their share of the representations and thus the entire map undergoes a reorganization.

%The induced topology shares similarity with the original topology (before ablation or addition).

% It is known that this sort of reorganization takes place naturally within brain. More precisely, neurogenesis happens in the subgranular zone of the Dentate Gyrus (DG) of the hippocampus and in the subventricular zone of the lateral ventricle~\cite{Alvarez:2004}. On the other hand, when neural tissue in the cerebral cortex~\cite{Merzenich:1984,Taub:2014} or the spinal cord~\cite{Bareyre:2004,Liu:1958}, the undamaged neurons reorganize their receptive fields and undamaged nerves sprout new connections, respectively, partially or fully restore functionality. Therefore, the study of reorganization after a neural ablation or neurogenesis within a self-organizing map is detrimental.

\begin{figure}
  \includegraphics[width=\columnwidth]{experiment-reorganization.pdf}
  \caption{%
  {\bfseries \sffamily Reorganization (results).}
  %
  An initial set of 248 neurons (outlined discs on panel \textbf{A}) has been modified with the addition of 25 neurons (black discs) or the removal of 25 neurons (red discs). Panels \textbf{B} and \textbf{C} show the final position of neurons after 100 iterations of the centroidal Voronoi tesselation. Lines shows individual movement of neurons. Panels \textbf{D}, \textbf{E} and \textbf{F} show the 2-neighbors induced topology for \textbf{A}, \textbf{B} and \textbf{C} respectively. Panels \textbf{G}, \textbf{H} and \textbf{I} show the map
  map codebook for each map in neural space after learnin. Each voronoi cell of a neuron is painted with the color of the related codeword.
  %
  }
  \label{fig:reorganization:results}
\end{figure}


%\documentclass{article}
\newcommand{\set}[3]{$\textup{#1}_{\textit{#2#3}}$}
\newcommand{\insieme}[1]{$\textup{#1}$}
\newcommand{\map}[3]{\mathrm{#1}_{\textit{#2#3}}} % \textsl
\newcommand{\mapnumb}[1]{\mathrm{#1}}
\newcommand{\setbound}[4]{$\textup{#1}_{\textit{#2#3}}^{#4}$}
\newcommand{\variabile}[1]{\textit{#1}}
\newcommand{\inversemap}[3]{\mathrm{#1}_{{#2#3}}^{-1}}
\newcommand{\vect}[1]{\textit{\textbf{#1}}}
\newcommand{\point}[1]{\textsf{#1}}
\newcommand{\scalar}[2]{(#1 #2)}
\newcommand{\const}[1]{\textrm{#1}}
\newcommand{\myangle}{\theta}
\newcommand{\mytime}{\tau}
\newcommand{\mynormal}{$\boldsymbol{\nu}$}
\newcommand{\lineai}{\variabile{j}}
\newcommand{\lineaj}{\variabile{k}}
\newcommand{\lineak}{\variabile{l}}
\newcommand{\nline}{\textrm{Nl}}
\newcommand{\npath}{\textrm{Np}}
\newcommand{\nbin}{\textrm{Nb}}
\newcommand{\nrays}{\textrm{Nr}}
\newcommand{\n}{\variabile{n}}
\newcommand{\optangle}{t}
\newcommand{\psangle}{\tau}
\newcommand{\position}[2]{\variabile{q}_{\textrm{#1} \textit{#2}}}
\newcommand{\direction}[2]{\variabile{p}_{\textrm{#1} \textit{#2}}}
\newcommand{\pos}[2]{\variabile{q}_{\textrm{#1} \textit{#2}}}
\newcommand{\dir}[2]{\variabile{p}_{\textrm{#1} \textit{#2}}}
\newcommand{\qmin}[1]{$\variabile{q}^{\textrm{\,min}}$}
%\newcommand{\qmax}[1]{$\variabile{q}^{\textrm{\,max}}$}
%\newcommand{\setbound}[4]{$\emph{#1}_{\textit{#2#3}}^{#4}$}
\chapter*{List of symbols}
\begin{longtable}{l l}
$\Phi_{\textrm{r}}$ &{radiant flux, [W]}\\
$Q$ &{total energy emitted from a light source or received by a target, [J]}\\
$\mytime$ & {time, [sec]}\\
$\Phi$ &{luminous flux, [lm]}\\
$y$ &{luminous efficacy function, [lm/W]}\\
$\lambda$ &{wavelength}\\
$\Psi_{\textrm{r}}$ & {spectral radiant flux, [W/m]}\\
$\Psi$ & {spectral luminous flux, [lm/m]}\\
$\bar{y}(\lambda)$ & {luminosity efficiency function}\\
$E$ &{illuminance, [lm/$\textrm{m}^2$]}\\
$P$ &{irradiance (radiant flux density), [W/$\textrm{m}^2$]}\\
${\Omega}$ & {solid angle}\\
$\boldsymbol{\nu}$ & {surface normal}\\
$I$ &{intensity, [cd = lm/sr]}\\
$L$ &{luminance, [cd/$\textrm{m}^2$]}\\
$U$ &{\'{e}tendue, [$\textrm{m}^2\,$sr]}\\
$\n$ &{index of refraction}\\
$\myangle$& {polar angle between $\boldsymbol{\nu}$ and the direction of the central line of $\textrm{d}\Omega$}\\
$\phi$ & {azimuthal angle between $\boldsymbol{\nu}$ and the direction of the central line of $\textrm{d}\Omega$}\\
$\vect{t}_\textrm{i}$ &{direction of the incident ray}\\
$\vect{t}_\textrm{r}$ &{direction of the reflected ray}\\
$\vect{t}_\textrm{t}$ &{direction of the transmitted ray}\\
\variabile{s} &{arc length}\\
$\n_\textrm{i}$ &{index of refraction of the medium in which the incident ray travels}\\
$\n_\textrm{r}$ &{index of refraction of the medium in which the reflected ray is located}\\
$\n_\textrm{t}$ &{index of refraction of the medium in which the transmitted ray travels}\\
$\myangle_\textrm{i}$& {angle between the incident ray and the normal \mynormal}\\
$\myangle_\textrm{r}$ &{angle between the reflected ray and the normal \mynormal}\\
$\myangle_\textrm{t}$ & {angle between the transmitted ray and the normal \mynormal}\\
$P_{\textrm{i}}$ &{incident radiant flux density}\\
$P_{\textrm{r}}$ &{reflected radiant flux density}\\
$P_{\textrm{t}}$ &{transmitted radiant flux density}\\
$\mathcal{E}$ &{electric field}\\
$\mathcal{B}$ &{magnetic field}\\
$\mathcal{E}_0$ &{amplitude of the electric field}\\
$\mathcal{B}_0$ &{amplitude of the magnetic field}\\
$\mu$ &{permeability}\\
$\varepsilon$ &{permittivity}\\
$\omega$ &{angular frequency}\\
$c$ &{speed of light in vacuum}\\
$v$ &{speed of light in medium}\\
$r$ &{amplitude coefficient for the reflected light}\\
$t$ &{amplitude coefficient for the transmitted light}\\
$r_{\textrm{s}}$ &{amplitude coefficient for reflected \textrm{s}-polarized light}\\
$t_{\textrm{s}}$ &{amplitude coefficient for transmitted s-polarized light}\\
$r_{\textrm{p}}$ &{amplitude coefficient for reflected p-polarized light}\\
$t_{\textrm{p}}$ &{amplitude coefficient for transmitted p-polarized light}\\
$\mathcal{R}$ &{reflectance}\\
$\mathcal{T}$ &{transmittance}\\
$\mathcal{R}_{\textrm{s}}$ &{reflectance for s-polarized light}\\
$\mathcal{T}_{\textrm{s}}$ &{transmittance for s-polarized light}\\
$\mathcal{R}_{\textrm{p}}$ &{reflectance for p-polarized light}\\
$\mathcal{T}_{\textrm{p}}$ &{transmittance for p-polarized light}\\
$\myangle_\const{c}$& {critical angle}\\
$\myangle_\const{p}$& {Brewster's angle for $\n_{\textrm{t}}<\n_{\textrm{i}}$}\\
$\myangle_\const{p}^{\prime}$ & {Brewster's angle for $\n_{\textrm{t}}>\n_{\textrm{i}}$}\\
$\point{S}$ &{light source}\\
\point{T} &{light target}\\
$(\variabile{x}_{\lineai}, \variabile{z}_{\lineai})$
&{coordinates of the intersection point of the rays with line $\lineai$ in real space}\\
$\optangle_\lineai$ &{angle that the ray incident line $\lineai$ makes with respect to the optical axis}\\
$\vect{r}(\variabile{s}) $ & ray parametrization\\
$\nrays$ & number of rays \\
$\nbin$ & number of bins \\
$\n_{\lineai}$ &{index of refraction of the medium in which line $\lineai$ is located}\\
$\nline$ &{number of lines that constitute the system = Index of the target}\\
$\vect{Y}$ &{random variable}\\
$\vect{y}$ &{values that a random variable assumes}\\
$\rho(\vect{y})$ &{probability density function}\\
$\mathbb{E}[f]$ &{expected value of $f$}\\
$\textrm{Var}[f] = \sigma$ &{variance of $f$}\\
$\sigma^2 [f]$ &{standard deviation of $f$}\\
$(\variabile{x}_{\lineai}, \variabile{z}_{\lineai})$
&{Position coordinates of the on line $\lineai$ of the $\lineai$-th ray traced}\\
$\optangle_\lineai$ &{angular coordinate of the $\lineai$-th ray traced}\\
$\hat{I}_{\textrm{MC}}$ &{averaged and normalized Monte Carlo intensity}\\
$\hat{I}_{\textrm{QMC}}$ &{averaged and normalized Quasi-Monte Carlo intensity}\\
$\textrm{card}(\mbox{\insieme{A}})$ &{cardinality of the set $\insieme{A}$}\\
$D_{N}(\mbox{\insieme{Y}})$ &{discrepancy of the finite set $\insieme{Y}$ of $N$ points.}\\
$D_{N}^*(\mbox{\insieme{Y}})$ &{discrepancy of the finite set $\insieme{Y}$ of $N$ points.}\\
$V(f)$ &{Hardy-Krause variation function.}\\
$\insieme{Q}$ &{set of the position coordinates of the rays}\\
$\insieme{P}$  &{set of the direction coordinates of the rays}\\
\set{S}{}{}=\set{Q}{}{} $\times$ \set{P}{}{} & phase space of the rays with position in \set{Q}{}{} and direction in \set{P}{}{}\\
$\insieme{S}$ &{source phase space}\\
$\insieme{T}$ &{target phase space}\\
$(\variabile{q}_1, \variabile{q}_1)$
&{coordinates of the ray on source PS \insieme{S}}\\
$(\variabile{q}, \variabile{q})$
&{coordinates of the ray on target PS \insieme{T}}\\
$\Pi$ &{ray path}\\
$\map{M}{}{}$ &{ray mapping form source to target PS}\\
\insieme{R}$_\textrm{s}(\Pi)$ &{ $\mbox{\insieme{R}}_1(\Pi)$ regions in source PS related to path $\Pi$}\\
\insieme{R}$_\textrm{t}(\Pi) $ &{$\mbox{\insieme{R}}_\textrm{t}(\Pi)$ positive luminance regions in target PS related to path $\Pi$}\\
$(\variabile{q}_1^{\variabile{k}}, \variabile{p}_1^{\variabile{k}})$
&{source PS coordinates of the \variabile{k}-th ray traced}\\
$\Pi^{\variabile{k}}$ &{path followed by the \variabile{k}-th ray traced}\\
$\npath$ &{Number of paths}\\
$\hat{I}_{\textrm{PS}}(\variabile{p})$ &{averaged and normalized phase space intensity at the target}\\
$\hat{I}_{\textrm{exact}}(\variabile{p})$ & {exact averaged and normalized target intensity} \\
$\hat{I}_{\textrm{ref}}(\variabile{p})$ & {reference averaged and normalized target intensity} \\
$\Pi_{\variabile{j}}$ &{\variabile{j}-th possible path ($\variabile{j}=1, \cdots, \npath$)}\\
$\varepsilon_\variabile{q}^\textrm{min}$ & {minimum triangulation parameter for the $\variabile{q}$-axis}\\
$\varepsilon_\variabile{p}^\textrm{min}$ & {minimum triangulation parameter for the $\variabile{p}$-axis}\\
$\varepsilon_\variabile{q}^\textrm{max}$ & {maximum triangulation parameter for the $\variabile{q}$-axis}\\
$\varepsilon_\variabile{p}^\textrm{max}$ & {Maximum triangulation parameter for the $\variabile{p}$-axis}\\
$\variabile{q}^\variabile{i}(\Pi, \variabile{p})$ &{$\variabile{q}$-coordinate on $\partial\mbox{\insieme{R}}(\Pi)$ along direction $\variabile{p}$}\\
$\variabile{q}^\textrm{min}(\Pi, \variabile{p}) $ &{minimum $\variabile{q}$-coordinate on $\partial\mbox{\insieme{R}}(\Pi)$ along direction $\variabile{p}$}\\
$\variabile{q}^\textrm{max}(\Pi, \variabile{p}) $ &{maximum $\variabile{q}$-coordinate on $\partial\mbox{\insieme{R}}(\Pi)$ along direction $\variabile{p}$}\\
\insieme{T} &{triangulation in $\mathbb{R}^2$}\\
\insieme{T}$^{\prime}$ &{Delaunay triangulation in $\mathbb{R}^2$}\\
\insieme{V}$_{\variabile{i}}$ &{Voronoi cell}\\
\insieme{V} &{Voronoi diagram}\\
\set{S}{i}{} & source phase space of line $\variabile{i}$ \\
\set{T}{i}{} & target phase space of line $\variabile{i}$ \\
\set{T}{i,}{j} & part of \set{T}{i}{} that is illuminated by line
$\variabile{j}$ with $\variabile{i}\neq \variabile{j}$ \\
$\pos{s,}{i}$ & position coordinates of the rays on \set{S}{i}{} \\
$\pos{t,}{j}$ & Position coordinates of the rays on \set{T}{j}{} \\
$\vect{$\nu$}_\variabile{i}$ & normal to line $\variabile{i}$\\
%$\tau_{\var{i}}$ & Angle between the ray that hits line $\var{i}$ and the normal $\vect{$\nu$}_\var{i}$, measured counterclockwise.\\
$\dir{s,}{i}$ & direction coordinates on \set{S}{i}{}, $\dir{s,}{i} = n_\variabile{i}\sin(\tau_{\variabile{i}})$ \\
$\dir{t,}{i}$ & direction coordinates on \set{T}{i}{}, $\dir{s,}{i} = n_\variabile{i}\sin(\tau_{\variabile{i}})$ \\
$\map{M}{$1$,}{\mbox{\textrm{Nl}}}$ & map from \set{S}{$1$}{} into \set{T}{Nl}{} \\
$\map{M}{$1$,}{\mbox{\textrm{Nl}}}(\Pi)$ & map from \set{S}{$1$}{} to \set{R}{}{}($\Pi$)\\
$\map{P}{i,}{j}$ & propagation map from \set{S}{i}{} to \set{T}{j}{}\\
$\map{R}{j}{}$ & reflection map from \set{T}{j}{} to \set{S}{j}{}\\
%$\var{q}^\textrm{\,min}(\Pi,\var{p})$ & Minimum position coordinate on $\partial$\set{R}{}{}($\Pi$) along the direction $\var{p}$.
%\\
%$\var{q}^\textrm{\,max}(\Pi,\var{p})$ & Maximum position coordinate on $\partial$\set{R}{}{}($\Pi$) along the direction $\var{p}$.\\
%$\pos{t,}{j}^\textrm{\,min}(\dir{}{})$ & Minimum position coordinate on \set{T}{j}{} with momentum $\dir{}{}$\\
%$\pos{t,}{j}^ \textrm{\,max}(\dir{}{})$ & Maximum position coordinate on \set{T}{j}{} with momentum $\dir{}{}$\\
$\variabile{u}_{\variabile{j},\variabile{i}}^\textrm{\,min}(\dir{}{})$ & minimum position coordinate on $\partial$\set{T}{j,}{i} along direction $\variabile{p}=\variabile{p}_{\textrm{t}, \variabile{j}}$ \\
$\variabile{u}_{\variabile{j},\variabile{i}}^\textrm{\,max}(\dir{}{})$ & maximum position coordinate on $\partial$\set{T}{j,}{i} along direction $\variabile{p}=\variabile{p}_{\textrm{t}, \variabile{j}}$ \\
$\variabile{v}_{\variabile{j},\variabile{i}}^\textrm{\,min}$ & $\max(\pos{j,}{i}^\textrm{\,min},\variabile{u}_{\variabile{j},\variabile{i}}^\textrm{\,min})$ \\
$\variabile{v}_{\variabile{j},\variabile{i}}^\textrm{\,max}$ & $\min(\pos{j,}{i}^\textrm{\,max},\variabile{u}_{\variabile{j},\variabile{i}}^\textrm{\,max})$ \\
$(\variabile{q}^{\,\textrm{a}}, \variabile{p})$ &{coordinates of the left end point of \insieme{T}}\\
$(\variabile{q}^{\,\textrm{b}}, \variabile{p})$ &{coordinates of the right end point of \insieme{T}}\\

%$\boldsymbol{\nu}_{\lineai}$ & {Normal to the line $\lineai$}\\
%$\optangle_\lineai$ & {Angle that the ray located on line $\lineai$ forms with respect to the optical axis}\\
%$\myangle_{\lineai}$ & {Angle between the ray and the normal $\boldsymbol{\nu}_{\lineai}$ to line $\lineai$ }\\
%$\n_\lineai$ &{Index of refraction of the medium in which line $\lineai$ is located}\\
\end{longtable}

%\end{document}


\subsection{Circle of convergence}


\section{Related Work}
\subsection{Secret Sharing Scheme}
here's another equation

\[ x^n + y^n = z^n \]

and here's an algorithm:
\begin{algorithm}
  \caption{Counting mismatches between two packed DNA strings
    \label{alg:packed-dna-hamming}}
  \begin{algorithmic}[1]
    \Require{$x$ and $y$ are packed DNA strings of equal length $n$}
    \Statex
    \Function{Distance}{$x, y$}
      \Let{$z$}{$x \oplus y$} \Comment{$\oplus$: bitwise exclusive-or}
      \Let{$\delta$}{$0$}
      \For{$i \gets 1 \textrm{ to } n$}
        \If{$z_i \neq 0$}
          \Let{$\delta$}{$\delta + 1$}
        \EndIf
      \EndFor
      \State \Return{$\delta$}
    \EndFunction
  \end{algorithmic}
\end{algorithm}

\begin{table}[!htbp]
    \centering
    \begin{tabular}{|c|c|}\hline
        Test1\tablefootnote{Footnote 1} & Test2\tablefootnote{Footnote 2} \\\hline
    \end{tabular}
    \caption{This is a table.\label{FirstTable}}
\end{table}


\chapter{Conclusions}
\label{chapter5}

Performing EDA for high-dimensional data by traditional statistical and VA techniques implicate a great effort from user to extract insights among all attributes at once, principally when context of the data is not widely known for deriving only the most meaningful attributes for understanding a real-world phenomenon. ML can support this process by, for instance, identifying groups or clusters of similar data instances and enabling user to focus the analysis where there is a main interest. DR and Clustering unsupervised algorithms are used to achieve this goal but having some problems related to lack of user feedback and interpretation.

Interactive ML and Interpretable ML are two sub-fields of relatively new interest intended to build user-centric ML systems. The main challenge of these sub-fields is determine the elements that need to be included in a system for maximizing the collaboration between a user and a ML model for more effectively fulfilling a real-world task. Some related concepts and principles have already been established being necessary to apply them in a more wide range of problems. In addition, an opportunity for combining these currently independent sub-fields is sighted.

In the context of DR and Clustering, a great variety of algorithms have been proposed having different learning strategies and implications for results understanding. As expected, some algorithms have had a particular interest, for instance, t-SNE for producing embeddings that enable the visual identification of clusters and K-Means for maintaining a good performance in contrast with its simplicity. Some systems for interacting and interpreting these algorithms have been proposed and, although presenting limitations, common interaction mechanism and interpretability strategies are derived.

The main contribution of this work is focused on developing MLExplore.js, a web interactive tool enabling domain-expert users for performing EDA in terms of cluster-oriented DR task sequences as verify clusters, name clusters and match cluster and classes. Two models are currently available in MLExplore.js: t-SNE and K-Means. Using model computation in the browser, users are able to explore the hyper-parameters space and visually validate the results in terms of the data. Complementary, the interface provides mechanisms for data navigation, attribute selection and export results. Integrating all of these components comprises an step forward with respect to the current proposals from the state of the art.

One real-world high-dimensional dataset is used to demonstrate the usefulness of MLExplore.js, the SALURBAL datasets. This datasets have around 80 attributes and 1.433 data instances. During the experimentation, the algorithms running in the browser present relatively good run-time performance as well as the user interactions with all the interface components. The EDA process followed is based in the model comparison when including different sets of attributes related to sub-cities attribute domains such as Street Design or Urban Landscape. The SALURBAL researchers provide Finitie Mixture Models profile memberships for the sub-cities for both domains, these categorical attributes are used for color encoding looking to find a set of t-SNE hyper-parameters that best visualizes the clusters and enables the naming of them in terms of the original attributes.

%For the FIFA dataset, the use case is focused on excluding the goalkeepers from the training data and comparing the model results with models with all players.

As future work, MLExplore.js can be extended for (1) supporting multiple dataset formats like JSON or excel, (2) including complementary idioms for dataset overview, (3) performing a more informed a priori attribute selection by, for instance, showing correlation metrics, (4) steering the hyper-parameter space exploration by better integrating the current nearest neighbors calculation, (5) highlighting attributes that maximize desired properties like class or cluster separability and (6) enabling more algorithms for experimentation. For larger datasets, computation in the browser can be very expensive, optimizing the model training on top on Tensorflow.js to take advantage of the WebGL standard continues being an great opportunity for delivering a tool that can be used for domain-expert users with more advanced requirements.


\section{Introduction}
This tutorial is an introduction to verifying C code with VCC. Our
primary audience is programmers who want to write correct code.
The only prerequisite is a working knowledge of C.

To use VCC, you first \emph{annotate} your code to specify
what your code does (e.g., that your sorting function sorts its input),
and why it works (e.g., suitable invariants for your loops and
data structures).
VCC then tries to \emph{prove} (mathematically) that
your program meets these specifications.  Unlike most program
analyzers, VCC doesn't look for bugs, or analyze an abstraction of
your program; if VCC certifies that your program is correct, then your
program really is correct%
\footnote{
  In reality, this isn't necessarily true, for two reasons.
  First, VCC itself might have bugs; in practice, these are unlikely to cause you to accidentally verify an
  incorrect program, unless you find and intentionally exploit such a
  bug. Second, there are a few checks needed for soundness that haven't yet
  been added to VCC, such as checking that ghost code terminates;
  these issues are listed in section \secref{caveats}.
  }.

To check your program, VCC uses the \emph{deductive verification} paradigm:
it generates a number of mathematical
statements (called \Def{verification conditions}), the validity of
which suffice to guarantee the program's correctness, and tries to
prove these statements using an automatic theorem prover. If any of
these proofs fail, VCC reflects these failures back to you in terms of
the program itself (as opposed to the formulas seen by the theorem
prover). Thus, you normally interact with VCC entirely at the level of
code and program states; you can usually ignore the mathematical
reasoning going on ``under the hood''.
For example, if your program uses division
somewhere, and VCC is unable to prove that the divisor is nonzero, it
will report this to you as a (potential) program error at that point in the
program. This doesn't mean that your program is necessarily incorrect;
most of the time, especially when verifying code that is already well-tested,
it is because you haven't provided enough information to allow VCC
to deduce that the suspected error doesn't occur.
(For example, you might have failed to specify that some function
parameter is required to be nonzero.)
Typically, you fix this ``error'' by strengthening your
annotations. This might lead to other error reports, forcing you to
add additional annotations, so verification is in
practice an iterative process.
Sometimes, this process will reveal a genuine programming error.
But even if it doesn't, you will have not only proved your code free from
such errors, but you will have produced the precise specifications for your
code -- a very useful form of documentation.

This tutorial covers basics of VCC annotation language. By the time
you have finished working through it, you should be able to use VCC to
verify some nontrivial programs. It doesn't cover the theoretical
background of VCC \cite{lci}, implementation details \cite{vcc}
or advanced topics;
information on these can be found on the VCC
homepage\footnote{\url{http://vcc.codeplex.com/}}.
More information on all topics covered in the tutorial can be found in the
VCC manual.

The examples in this tutorial are currently distributed with the VCC sources.%
\footnote{
Available from \url{http://vcc.codeplex.com/SourceControl/list/changesets}: click Download on the right,
get the zip file and navigate to \lstinline|vcc/Docs/Tutorial/c|.}

You can use VCC either from the command line or from Visual Studio
2008/2010 (VS); the VS interface offers easy access to different components of
VCC tool chain and is thus generally recommended.
VCC can be downloaded from the VCC homepage;
be sure to read the installation instructions\footnote{\url{http://vcc.codeplex.com/wikipage?title=Install}},
which provide important information about installation prerequisites
and how to set up tool paths.


Fitting logistic models uses many of the same ideas as in linear
models.

\subsection{Fitting Logistic Models}

\index{P}{glm@\texttt{glm}}
\index{P}{Modeling!glm@\texttt{glm}}
\index{C}{logistic regression!fitting}
The \code{glm} operator fits logistic models.  (It also fits other
kinds of models, but that's another story.)  \code{glm} takes model
design and data arguments that are identical to their counterparts in
\code{lm}.  Here's an example using the smoking/mortality data: \datasetWhickham
\begin{Schunk}
\begin{Sinput}
> whickham = fetchData("whickham.csv")
> mod = glm( outcome ~ age + smoker, data=whickham,
     family="binomial")
\end{Sinput}
\end{Schunk}
The last argument, \texttt{family="binomial"}, simply specifies to
\function{glm} that the logistic transformation should be used.
\function{glm} is short for Generalized Linear Modeling, a broad label
that covers logistic regression as well as other types of models
involving links and transformations.

\index{P}{summary@\texttt{summary}!for logistic regression}
\index{P}{Modeling!summary@\texttt{summary}!for logistic regression}
\index{P}{Hypothesis Testing!summary@\texttt{summary}!for logistic regression}
The regression report is produced with the \code{summary} operator,
which recognizes that the model was fit logistically and does the
right thing:
\begin{Schunk}
\begin{Sinput}
> summary(mod)
\end{Sinput}
\end{Schunk}

% latex table generated in R 2.13.0 by xtable 1.5-6 package
% Sun Aug 21 20:42:21 2011
\begin{tabular}{rrrrr}
  \hline
 & Estimate & Std. Error & z value & Pr($>$$|$z$|$) \\
  \hline
(Intercept) & -7.5992 & 0.4412 & -17.22 & 0.0000 \\
  age & 0.1237 & 0.0072 & 17.23 & 0.0000 \\
  smokerYes & 0.2047 & 0.1684 & 1.22 & 0.2242 \\
   \hline
\end{tabular}

Keep in mind that the coefficients refer to the intermediate model
values $Y$.  The probability $P$ will be $e^Y / (1 + e^Y )$.

\subsection{Fitted Model Values}

\index{P}{predict@\texttt{predict}!in logistic regression}
\index{P}{fitted@\texttt{fitted}!in logistic regression}
\index{P}{Modeling!predict@\texttt{predict}!in logistic regression}
\index{P}{Modeling!fitted@\texttt{fitted}!in logistic regression}
\index{C}{link value!in logistic regression}
\index{C}{probability values!in logistic regression}

Logistic regression involves two different kinds of fitted values:
the intermediate ``link'' value $Y$ and the probability $P$.  The
\code{fitted} operator returns the probabilities:
\begin{Schunk}
\begin{Sinput}
> probs = fitted(mod)
\end{Sinput}
\end{Schunk}
There is one fitted probability value for each case.

The link values can be gotten via the \code{predict} operator
\begin{Schunk}
\begin{Sinput}
> predict(mod, type="link")
\end{Sinput}
\end{Schunk}
\begin{Schunk}
\begin{Soutput}
     1      2      3      4      5      6      7      8
-4.550 -5.168  1.387  0.688  0.317 -2.695 -1.829  1.801
     9     10     11     12     13     14
-4.136 -4.260 -4.136 -3.189 -5.126  1.511
... for 1314 cases altogether ...
\end{Soutput}
\end{Schunk}

Notice that the link values are not necessarily between zero and one.

The \code{predict} operator can also be used to calculate the
probability values.
\begin{Schunk}
\begin{Sinput}
> predict(mod, type="response")
\end{Sinput}
\end{Schunk}
\begin{Schunk}
\begin{Soutput}
      1       2       3       4       5       6       7
0.01046 0.00566 0.80011 0.66542 0.57847 0.06330 0.13838
      8       9      10      11      12      13      14
0.85823 0.01573 0.01393 0.01573 0.03957 0.00591 0.81916
... for 1314 cases altogether ...
\end{Soutput}
\end{Schunk}

\noindent This is particularly useful when you want to use \code{predict} to
find the model values for inputs other than that original data frame
used for fitting.

\subsection{Which Level is ``Yes''?}

In fitting a logistic model, it's crucial that the response variable
be categorical, with two levels.  It happens that in the
\code{whickham} data, the \VN{outcome} variable fits the bill: the
levels are \code{Alive} and \code{Dead}.

The \code{glm} software will automatically recode the response
variable as 0/1.  The question is, which level gets mapped to 1?  In
some sense, it makes no difference since there are only two levels.
But if you're talking about the probability of dying, it's nice not
to mistake that for the probability of staying alive.  So make sure
that you know which level in the response variable corresponds to 1:
it's the second level.

Here is an easy way to make sure which level has been coded as ``Yes''.
First, fit the all-cases-the-same model, \model{\VN{outcome}}{1}.  The
fitted model value $P$ from this model will be the proportion of cases for
which the outcome was ``Yes.''
\begin{Schunk}
\begin{Sinput}
> mod2 = glm( outcome ~ 1, data=whickham, family="binomial")
\end{Sinput}
\end{Schunk}
\begin{Schunk}
\begin{Sinput}
> fitted(mod2)
\end{Sinput}
\end{Schunk}
\begin{Schunk}
\begin{Soutput}
    1     2     3     4     5
0.281 0.281 0.281 0.281 0.281
... for 1314 cases altogether ...
\end{Soutput}
\end{Schunk}
So, 28\% of the cases were ``Yes.''  But which of the two levels is ``Yes?''
Find out just by looking at the proportion of each level:
\begin{Schunk}
\begin{Sinput}
> props(outcome, data=whickham)
\end{Sinput}
\begin{Soutput}
Alive  Dead
0.719 0.281
\end{Soutput}
\end{Schunk}

If you want to dictate which of the two levels is going to be encoded
as 1, you can use a comparison operation to do so:
\begin{Schunk}
\begin{Sinput}
> mod3 = glm( outcome=="Alive" ~ 1, data=whickham,
    family="binomial")
\end{Sinput}
\end{Schunk}

\begin{Schunk}
\begin{Soutput}
    1     2     3     4     5
0.719 0.719 0.719 0.719 0.719
... for 1314 cases altogether ...
\end{Soutput}
\end{Schunk}

In this model, ``Yes'' means \code{Alive}.

\subsection{Analysis of Deviance}

The same basic logic used in analysis of variance applies to logistic
regression, although the quantity being broken down into parts is not
the sum of squares of the residuals but, rather, the \newword{deviance}.

The \code{anova} software will take apart a logistic model, term by
term, using the order specified in the model.
\index{P}{anova@\texttt{anova}!in logistic regression}
\begin{Schunk}
\begin{Sinput}
> anova(mod, test="Chisq")
\end{Sinput}
\end{Schunk}

% latex table generated in R 2.13.0 by xtable 1.5-6 package
% Sun Aug 21 20:42:21 2011
\begin{tabular}{lrrrrr}
  \hline
 & Df & Deviance & Resid. Df & Resid. Dev & P($>$$|$Chi$|$) \\
  \hline
NULL &  &  & 1313 & 1560.32 &  \\
  age & 1 & 613.81 & 1312 & 946.51 & 0.0000 \\
  smoker & 1 & 1.49 & 1311 & 945.02 & 0.2228 \\
   \hline
\end{tabular}

\noindent Notice the second argument, \code{test="Chisq"}, which instructs
\code{anova} to calculate a p-value for each term.  This involves a
slightly different test than the F test used in linear-model \ANOVA.

The format of the \ANOVA\ table for logistic regression is somewhat
different from that used in linear models, but the concepts of degrees
of freedom and partitioning still apply.  The basic idea is to ask
whether the reduction in deviance accomplished with the model terms is
greater than what would be expected if random terms were used instead.


% new chapter for contact models

\chapter{Contact Models}
\label{cp:contact}
In an attempt to apply deep learning in a contact dynamic system, the first step is to understand how the contact dynamic system is modeled and how system model is solved by numerical method. Therefore, this chapter focuses on rigid body simulations to help readers understand how computers simulate rigid dynamics based on traditional \textit{Newton-Euler} equations, including how \textit {Newton-Euler} describes rigid dynamics, how to set constraint equations and numerical solution for dynamic system equation.

\section{Overview}

In rigid body simulation, contact force is used to prevent the rigid bodies from penetrating each other. The accuracy of the calculated contact force has great influence on the fidelity of simulation. In order to achieve physical rationality, frictional forces are necessary. The formulae of friction contact force problems include the modeling of normal force constraint and friction force constraint. Because that frictional contact modeling is more complicated, I would just give a simple and general solution for normal contact forces. The frictional contact model would be mentioned briefly, rather than exploring details. Besides, the topic of the paper is about applying deep learning to contact simulation, I just want to do the simulation as simple as possible. So rigid bodies' shape would not be considered here. All the bodies would be a circle, which is similar to particles.

Before exporting the contact model, it is important to note that the simulation system is constrained by velocity-based location updates \cite{Erleben:2007:VSP:1243980.1243986}. Since collision detection is another big academic topic \cite{boulic2007collision} and this is a thesis on contact problems, the following models are given under the assumption that contact determination has already been performed.

\section{Rigid Dynamics Simulation}

\subsection{Classical Mechanics}
Simulation of the motion of a system of rigid bodies is based on a famous system of differential equations, the \textit{Newton–Euler equations}, which can be derived from Newton’s laws and other basic concepts from classical mechanics \cite{bender2014interactive}:

\begin{enumerate}
    \item Newton’s first law: The velocity of a body remains unchanged unless acted upon by a force.
    \item Newton’s second law: The time rate of change of momentum of r a body is equal to the applied force.
    \item Newton’s third law: For every force, there is an equal and opposite force.
\end{enumerate}

Before presenting the \textit{Newton–Euler} equations, we need to introduce a number of concepts from classical mechanics. I would start with one simple simulation with only position vector $\pmb{q}(t)$ and velocity vector $\pmb{v}(t)$. Then, we will introduce some concepts by adding rotation to pure simulation, rotational velocity $\pmb{\omega}(t)$, and moment $\pmb{\tau}$ (also known as a torque).

\subsection{Simulation Basics}

Firstly, we can start with a simple simulation with only position and velocity. Simulating the motion of a rigid body is almost the same as simulating the motion of a particle, so I will start with particle simulation. For particle simulation, we let function $\pmb{q}(t)$ describe the particle's location in world space at time $t$. Then we use the change of $\pmb{q}(t)$
to denote the velocity of the particle at time $t$.
\begin{equation}
    \pmb{v}(t) = \dot{\pmb{q}}(t)
\end{equation}
So, the state of a particle at a time $t$ is the particle's position and velocity. We generalize this concept by defining a state vector $\textbf{Y}(t)$ for a system: for a single particle,
\begin{equation}
    \textbf{Y}(t) = \left[
        \begin{array}{c}
            \pmb{q}_{1}(t) \\
            \pmb{v}_{1}(t) \\
        \end{array}
    \right]
\end{equation}

For a system with $n$ particles, we enlarge $\textbf{Y}(t)$ to be
\begin{equation}
    \textbf{Y}(t) = \left[
    \begin{array}{c}
        \pmb{q}_{1}(t) \\
        \pmb{v}_{1}(t) \\
        ... \\
        \pmb{q}_{n}(t) \\
        \pmb{v}_{n}(t) \\
    \end{array}
    \right]
\end{equation}

However, to simulate the motion of particles actually, we need to know one more thing -- the forces. $\pmb{f}(t)$ is defined as the force acting on the particle. If the mass of the particle is $m$, then the changes of $\textbf{Y}(t)$ will be given by
\begin{equation}
    \dot{\mathbf{Y}}(t) = \frac{\dif}{\dif(t)}\textbf{Y}(t) = \frac{\dif}{\dif(t)}\left[
        \begin{array}{c}
            \pmb{q}(t) \\
            \pmb{v}(t) \\
        \end{array} \right] = \left[
        \begin{array}{c}
            \pmb{v}(t) \\
            \pmb{f}(t)/m \\
        \end{array} \right]
\end{equation}

\subsection{Rigid Body Concepts}
Unlike a real particle, a rigid body occupies a volume of space and has a particular shape(including circle rigid objects). Rigid bodies are more complicated, besides translating them, we can rotate them as well. To locate a rigid body, we use $\pmb{q}(t)$ to denote their translation and a rotation matrix $\pmb{R}(t)$ to describe their rotation.

\subsection{Rigid Body Equations of Motions}
\label{sec:rigid_rm}
 Whereas linear momentum $\pmb{P}(t)$ is related to linear velocity with a scalar (the mass), angular momentum is related to the angular velocity with a matrix \(\pmb{I}\), called the angular inertia matrix. The reason for this is that objects generally have different angular inertias around different axes of rotation. Angular momentum is defined as \(\pmb{L}\). The linear momentum and angular momentum are defined in Equation \ref{mom}.
\begin{subequations}
\begin{align}
    m \dot{\pmb{v}}(t) = \pmb{f}(t) & \\
    \pmb{P}(t) = m \pmb{v} (t)  & \\
    \pmb{L}(t) = \pmb{I}(t)\pmb{\omega}(t) &
\end{align}
\label{mom}
\end{subequations}

The total torque $\pmb{\tau}$ applied to the body is equal to the rate of change of the angular momentum, as defined in \ref{tau}:
\begin{equation}
    \pmb{\tau} = \frac{\dif}{\dif t }\pmb{L} = \frac{\dif}{\dif t }(\pmb{I}\pmb{\omega})
    \label{tau}
\end{equation}

 Then we can covert all concepts we need to define stare $\textbf{Y}$ for a rigid body.

\begin{equation}
    \textbf{Y}(t) = \left[
        \begin{array}{c}
            \pmb{q}(t) \\
            \pmb{R}(t) \\
            \pmb{P}(t) \\
            \pmb{L}(t) \\
        \end{array}
    \right]
\end{equation}

Like what is expressed in $\textbf{Y}(t)$, the state of a rigid body mainly consists by its position and orientation (describing spatial information), and its linear and angular momentum(describe velocity information). Since mass $m$ and bodyspace inertia tensor $\pmb{I}_{body}$ are constants, we can the auxiliary quantities $\pmb{I}(t)$, $\pmb{\omega}(t)$ at any given time.
\begin{subequations}
\begin{align}
    \pmb{v}(t) & = \frac{\pmb{P}(t)}{m} \quad \\
    \pmb{I}(t) & = \pmb{R}(t)\pmb{I}_{body}\pmb{R}(t)^{T} \quad \\
    \pmb{\omega}(t) & = \pmb{I}(t)^{-1}\pmb{L}(t)
\end{align}
\end{subequations}

Then, the derivative $\dot{\textbf{Y}}(t)$ is
\begin{equation}
    \dot{\textbf{Y}}(t) = \frac{\dif}{\dif{t}}\textbf{Y}(t) = \frac{\dif}{\dif t}\left[
        \begin{array}{c}
            \pmb{q}(t) \\
            \pmb{R}(t) \\
            m \pmb{v}(t) \\
            \pmb{L}(t) \\
        \end{array}
    \right] = \left[
        \begin{array}{c}
            \pmb{v}(t) \\
            \pmb{\omega}(t)\times\pmb{R}(t) \\
            \pmb{f}(t) \\
            \pmb{\tau}(t) \\
        \end{array}
    \right]
\end{equation}

Then, we can evaluate Equation \ref{tau_ev} as follows:
\begin{equation}
    \begin{aligned}
        \pmb{\tau} &= \frac{\dif}{\dif t}(\pmb{I}\pmb{\omega}) \\
        &= \pmb{I}\dot{\pmb{\omega}} + \dot{\pmb{I}}\pmb{\omega} \\
        &= \pmb{I}\dot{\pmb{\omega}} + \frac{\dif}{\dif t}(\pmb{R}\pmb{I}_{body}\pmb{R}^{T})\pmb{\omega} \\
        &= \pmb{I}\dot{\pmb{\omega}} + (\dot{\pmb{R}}\pmb{I}_{body}\pmb{R}^{T} + \pmb{R}\pmb{I}_{body}\dot{\pmb{R}}^{T})\pmb{\omega} \\
        &= \pmb{I}\dot{\pmb{\omega}} + ([\pmb{\omega}]\pmb{R}\pmb{I}_{body}\pmb{R}^{T} + \pmb{R}\pmb{I}_{body}\pmb{R}^{T} \hat{\pmb{\omega}})\pmb{\omega} \\
        &= \pmb{I}\dot{\pmb{\omega}} + [\pmb{\omega}]\pmb{I}\pmb{\omega} - \pmb{I}[\pmb{\omega}]\pmb{\omega}
    \end{aligned}
    \label{tau_ev}
\end{equation}

Since $\pmb{\omega} \times \pmb{\omega}$ is zero, the final term can be cancels out. This relationship left is known as :
\begin{equation}
    \pmb{\tau} = \pmb{I}\dot{\pmb{\omega}} + [\pmb{\omega}]\pmb{I}\pmb{\omega}
    \label{tau}
\end{equation}

\subsection{Twist/Wrench}
\textbf{Twis}t is introduced to describe linear and angular velocity, and \textbf{Wrench}, is to describe forces and explain how these objects transform from one coordinate frame to another one.
    \subsubsection{Twist}
        A twist is a vector that expresses rigid motion or velocity. In Section \ref{sec:rigid_rm}, we saw how to parameterize the velocity of a rigid body as a linear velocity vector and an angular velocity vector. The coordinates of a twist are given as a 4-vector in $2$-D simulation, which we can check in \ref{twist}
            \begin{equation}
                \mathbf{v} = \left[ \begin{array}{c} \pmb{\omega} \\ \pmb{v} \\ \end{array} \right]
                \label{twist}
            \end{equation}.
        The defination can be found in \ref{twist}, containing a linear velocity vector \(\pmb{v}\) and an angular velocity \(\pmb{\omega}\). According to

    \subsubsection{Wrench}
        A wrench is a vector that expresses force and torque acting on a body. A wrench can be defined by
        \begin{equation}
            \mathbf{f} = \left[ \begin{array}{c} \pmb{\tau} \\ \pmb{f} \\ \end{array} \right]
            \label{wrench}
        \end{equation}

        A wrench contains an angular component $\pmb{\tau}$ and a linear component $f$, which are applied at the origin of the coordinate frame they are specified in.

\subsection{\textit{Newton-Euler} Equation}
    \textit{Newton-Euler} equations for a rigid body can now be written in terms of the body's acceleration twist $\mathbf{v}$ mentioned in \ref{twist} and the wrench $\mathbf{f}$ mentioned in \ref{wrench} acting on the body. We can simply write the Newton and Euler equations,

    \begin{equation}
        \left[ \begin{array}{c} \pmb{\tau} - \pmb{\omega} \times \pmb{I} \pmb{\omega}\\ \pmb{f} \end{array}\right] = \left[ \begin{array}{cc} \pmb{I} & \pmb{0} \\ \pmb{0}& m\pmb{1}_{d\times d}\end{array} \right] \dot{\mathbf{v}}
    \end{equation}
    $d$ stands for the number pf dimensions, like $d=2$ in $2$-\textit{D} and $3$ in $3$-\textit{D}. \\

    Then, we can rewrite \textit{Newton-Euler} equation as,
    \begin{equation}
        \pmb{M}\dot{\mathbf{v}} = \mathbf{F}
        \label{eq:newton}
    \end{equation}
    where $\pmb{M}$ and $\mathbf{h}$ are defined in Equation \ref{M} and \ref{F}.
    \begin{equation}
        \pmb{M} = \left[ \begin{array}{cc} \pmb{I} & \pmb{0} \\ \pmb{0} & m\pmb{1}_{d \times d}\end{array} \right]
        \label{M}
    \end{equation}
    \begin{equation}
        \mathbf{F} = \left[ \begin{array}{c} \pmb{\tau} - \pmb{\omega} \times \pmb{I} \pmb{\omega}\\ \pmb{f} \end{array}\right]
        \label{F}
    \end{equation}

\section{Velocity-Based Conatct Model}
    After getting some basic physical and mathematical knowledge about a dynamic system. Then,  the next step is to describe the equation of motion for the system with contact forces.

    When the collision happens, we can use contact forces to model the interactions between two colliding objects. The contact forces consist of both normal forces and frictional forces, which are subject to a set of constraints. The constraints are defined in Equation \ref{eq:constraint}.
    \begin{equation}
        \pmb{c}(\pmb{q}) = [c_1(\pmb{q}),c_2(\pmb{q}),...,c_n(\pmb{q})]
        \label{eq:constraint}
    \end{equation}

    the Jacobian, $\pmb{J}_{c}$ of Equation \ref{eq:constraint} is,
    \begin{equation}
        \pmb{J}_{c} =
        \begin{bmatrix}
            \frac{\partial{c_1}}{\partial{q_1}} & \frac{\partial{c_2}}{\partial{q_1}} & ... & \frac{\partial{c_n}}{\partial{q_1}} \\
            \frac{\partial{c_1}}{\partial{q_2}} & \frac{\partial{c_2}}{\partial{q_2}} & ... & \frac{\partial{c_n}}{\partial{q_2}} \\
            \vdots & \vdots & & \vdots\\
            \frac{\partial{c_1}}{\partial{q_n}} & \frac{\partial{c_2}}{\partial{q_n}} & ... & \frac{\partial{c_n}}{\partial{q_n}} \\
        \end{bmatrix}
        \label{Jacobianb}
    \end{equation}

    The constraints are added to Equation \ref{eq:newton} by applying the Lagrange multiplier method such that,
    \begin{equation}
        \pmb{M}\dot{\mathbf{v}} = \pmb{J}_{c}^{T}\pmb{\lambda} + \mathbf{F}_{ext}
        \label{eq:cone}
    \end{equation}
    where $\pmb{\lambda} = [\lambda_1, \lambda_2, ... , \lambda_n]^T$ are the Lagrange multipliers.

\subsection{Linear Complementarity Problem}
The classical method to solve contacts forces is to derive the contact problems as a linear complementarity problem formulation. I will give the definition of Linear Complementarity Problem below,

    (LCP): Given an unknown vector $\mathbf{x} \in \mathbb{R}^{m}$, a known fixed matrix $\pmb{A} \in \mathbb{R}^{m\times m}$, and a known fixed vector $\pmb{b} \in \mathbb{R}^{m}$, determine $\mathbf{x}$ such that,
    \begin{equation}
        f(\mathbf{x}) = \mathbf{x}^{T}(\pmb{A}\cdot\mathbf{x} + \pmb{b}) = 0
    \end{equation}
    subject to the constraints,
    \begin{subequations}
    \begin{align}
        \pmb{A}\cdot\mathbf{x} + \pmb{b} \ge \pmb{0} & \\
        \mathbf{x} \ge \pmb{0} &
    \end{align}
    \end{subequations}
    \textit{For LCPs, we adopt the shorthand notation, LCP($\pmb{A}, \pmb{b}$)}.

\subsection{Modeling Contact}
    The contact force problem can be stated as a linear complementarity problem (LCP)\cite{bender2014interactive}. I will derive this formulation. The focus of this chapter is on the contact force model, so the time stepping scheme and matrix layouts are based on the velocity-based formulation. If I just consider normal contact forces, the \textit{Newton–Euler} equations based on Equation \ref{eq:cone} can be rewritten as,

    \begin{equation}
        \pmb{M}\dot{\mathbf{v}} = \pmb{J}_{n}^{T}\pmb{\lambda}_n + \mathbf{F}_{ext}
    \end{equation}

    then we can get,

    \begin{equation}
        \dot{\mathbf{v}} = \pmb{M}^{-1}\mathbf{F}_{ext} + \pmb{M}^{-1}\pmb{J}_{n}^{T}\pmb{\lambda}_{n}
        \label{sys}
    \end{equation}

    The laws of physics must be incorporated into what we call ``instantaneous time'', which describes the continuous motion of the rigid bodies. After that, we discretize the model over time to obtain a `discrete-time' model, which is a series of time step sub-problems. Sub-problems are formulated and numerically solved at each time step to simulate the system.

    To discretize the system \ref{sys}, the acceleration can be approximated by \cite{anitescu1997modeling} as:
    \begin{equation}
        \dot{\mathbf{v}} \approx \frac{(\mathbf{v}_{t+1} - \mathbf{v}_t)}{\Delta t}
    \end{equation}
    $\mathbf{v}_t$ and $\mathbf{v}_{t+v}$ are the velocities at the beginning of the current time step, and the next time step, $\Delta t$ is the time step. Then we can get,
    \begin{equation}
        \mathbf{v}^{t+1} = \mathbf{v}^{t} + \pmb{M}^{-1}\pmb{J}_{n}^{T}\Delta{t}\pmb{\lambda}_{n} + \Delta{t}\pmb{M}^{-1}\mathbf{F}_{ext}
    \end{equation}

    Then we can define,
    \begin{equation}
    \begin{aligned}
        \mathbf{w} & = \pmb{J}_{n}\mathbf{v}^{t+1} \\
        & =  \underbrace{\pmb{J}_{n}\pmb{M}^{-1}\pmb{J}_{n}^{T}\Delta{t}}_{\pmb{A}}\pmb{\lambda}_{n} + \underbrace{\pmb{J}_{n}(\Delta{t}\pmb{M}^{-1}\mathbf{F}_{ext} + \mathbf{v}^{t})}_{\pmb{b}} \\
        & = \pmb{A}\pmb{\lambda}_{n} + \pmb{b}
    \end{aligned}
    \label{contactlcp}
    \end{equation}
    Also, for a general $\mathbf{w}$
    \begin{equation}
        \mathbf{w} = \pmb{J}\mathbf{v} = \frac{\dif{\pmb{c}}}{\dif{\pmb{q}}}\frac{\dif{\pmb{q}}}{\dif{t}} = \dot{\pmb{c}}
    \end{equation}
    Based on physics law, for each contact $\lambda = 0$ or $\dot{c} = 0$, then,
    $$\pmb{\lambda}^{T} \dot{\pmb{c}} = 0$$
    So Equation \ref{lcp} can be considered as one LCP. So finally, contact model is to find solution for,
    $$\pmb{\lambda} = \textit{LCP}(\pmb{A}, \pmb{b})$$
    \subsubsection{Modeling Friction}
    In order to make the virtual world more real, the friction is essential. However, when friction is imported to the model, the system will be more comlecated due to Coulomb’s friction law. We can rewrite Equation \ref{sys},
    \begin{equation}
        \dot{\mathbf{v}} = \pmb{M}^{-1}\mathbf{F}_{ext} + \pmb{M}^{-1}\pmb{J}_{n}^{T}\pmb{\lambda}_{n} + \pmb{M}^{-1}\pmb{J}_{t}^{T}\pmb{\lambda}_{t}
        %\label{sys}
    \end{equation}
    And the another constraints, $-\mu \lambda_{n} \le \lambda_t \le \mu \lambda_n$ for each contact, will be added to the system. Since the focus of paper is on find a solution by deep learning, I did not explore too much on frictinal contact model. I recommend Sarah and Kenny's paper \cite{poulsen2010heuristic, bender2014interactive}to know more details.

\section{The Numerical Solution Method}
    After obtaining discrete-time models, numerical methods must be applied to compute solutions. Normally, an iterative solution will be used to solve LCP. Projected Gauss-Seidel Solver is one of the most classic methods. One introduction will be given below,

    \subsection{Projected Gauss-Seidel(PGS) solver for contact forces}
    One of the most classic methods is projected gauss-seidel(PGS). Most open-source software for interactive real-time rigid body simulation uses the Projected Gauss-Seidel (PGS) method for computing contact forces, like \textit{Box2D}\footnote{\url{http://box2d.org/}} for 2-$D$ and \textit{Bullet}\footnote{\url{https://pybullet.org/wordpress/}} for 3-$D$.

    There are two main reasons why PGS is well suitable for interactive application \cite{Erleben:2007:VSP:1243980.1243986},
    \begin{enumerate}
        \item PGS is computationally very efficient with an iteration cost of $O(n)$, using a careful memory layout of sparse matrices allows for a memory footprint of $O(n)$.
        \item PGS is very robust and can deal gracefully with ill-conditioned problems (due to many redundant constraints) or ill-posed problems (due to badly defined constraints).
    \end{enumerate}
    I introduced PGS in Algorithm \ref{pgs}. Some experiment will be done to explore its convergence rate in section \ref{sphtest}.
    \begin{algorithm}[!h]
        \KwData{$N, \pmb{\lambda}_{init}, \pmb{A}, \pmb{b}$}
        \KwResult{Compute the values of $\pmb{\lambda}$, the convergence rate $\pmb{\theta}$}
        \For{$ k = 1~\textbf{To}~N$}{
            \If{$k=1$}{$\pmb{\lambda} \gets \pmb{\lambda}_{init}$}
            $\pmb{\lambda}_{old} \gets \pmb{\lambda}$ \\
            \For{all $i$}{
                $\pmb{r}_i \gets \pmb{A}_{i*}\pmb{\lambda} + \pmb{b}_i$ \;
                $\pmb{\lambda}_{i} \gets \text{max}(0, \pmb{\lambda}_i - \frac{\pmb{r}_i}{\pmb{A}_{ii}})$ \;
            }
            $\pmb{\theta}_{k} \gets \text{max}(|\pmb{\lambda}- \pmb{\lambda}_{old}|)$
        }
        \caption{\textit{pgs}($\pmb{A}, \pmb{b}, \pmb{\lambda}_{init}$)}
        \label{pgs}
    \end{algorithm}
    \subsubsection{Warm Starting}
    How fast the solver gets convergence is related to $\pmb{\lambda}_{init}$. Industrially, $\pmb{\lambda}$ would be provided a value which is normally determined by previous simulation. We call it \textbf{warm starting}. The central idea of this project is to use deep learning to provide a good warm starting to the solver.

    \subsubsection{Convergence Rate}
    PGS algorithm will return the final solution \(\pmb{\lambda}\) and a list of convergence rate $\pmb{\theta}$. Normally, the convergence rate can indicate the performance of an iterative solver. In order to represent the overall performance of the model or solver in the whole simulation, I use average convergence rate in each iteration. For a $T$ time-steps simulation. $\theta_{t}$ is the vector of convergence rates in time $t$.
    \begin{equation}
        \pmb{\theta} = \frac{1}{T}\sum_{t}^{T}\pmb{\theta}_t
    \end{equation}
    You can see the sample analysis in Section \ref{sphtest} to get more details.

    \subsection{Summary}
    As a summary, the contact problem would be derived in an LCP formulation then solved by one iterative solver. I only introduced one solver(PGS) here. Some other solvers are mentioned by Kenny in \cite{Erleben:2007:VSP:1243980.1243986, poulsen2010heuristic}. In the future, I would use $Slover(\pmb{A}, \pmb{b}, \pmb{\lambda}_{init})$ to represent the numerical solver used by our experiment. Our hope is to find values which are close to the final solution through deep learning. Then the values will be used as warm starting so that iterative solve can converge rapidly.


\chapter{{\tt InpMtx}: Input Matrix Object}
\label{chapter:InpMtx}
\par
The {\tt InpMtx} object has two functions:
\begin{itemize}
\item
It is used to assemble a sparse matrix (or just its structure)
from individual entries, rows, columns or dense submatrices
(or any combination of these) that may overlap.
\item
It is used to communicate entries of a matrix into a front during
the factorization.
\end{itemize}
We have designed this object to be easy to use, but it has one
significant drawback --- it is an in-core implementation,
and this is a disadvantage in situations where memory is limited.
Extending this object to work out-of-core is not difficult,
but we leave that {\it value-added} function to others in the
future.
\par
The {\tt InpMtx} object has three faces.
It can just manipulate $(i,j)$ pairs, where it assembles just the
nonzero structure of a matrix.
We use this functionality to generate a {\tt Graph} object
that is needed as input to the ordering software.
Alternatively, it can assemble and manipulate $(i,j,a_{i,j}$
triples where $a_{i,j}$ is either a real or complex number.
(At any one time, the object works with either no numbers,
real numbers or complex numbers but not mixtures of the three.)
The normal input to the {\tt InpMtx} object is a collection of
matrix entries in some form, e.g., single entries, (partial) rows
or columns, or dense submatrices.
\par
Here is a common sequence of events to use this object when we want
to build the structure of a sparse matrix.
\begin{enumerate}
\item
Create an instance of a {\tt InpMtx} object using
the {\tt InpMtx\_new()} method.
\item
Initialize the {\tt InpMtx} object using the {\tt InpMtx\_init()}
method; set the input mode to indices only,
maximum number of entries for the workspace, and the number of
vectors. (The latter two quantities may be zero, for the object
resizes its storage as required.)
\item
Call the method {\tt InpMtx\_changeCoordType()}
to set the coordinate type to rows.
\item
Load data into the object using one or more of the
five input methods:
{\tt InpMtx\_inputEntry()},
{\tt InpMtx\_inputRow()},
{\tt InpMtx\_inputColumn()},
{\tt InpMtx\_inputMatrix()} and
{\tt InpMtx\_inputTriples()} methods.
Each time the workspace fills up, the raw data is sorted and
compressed and then the workspace is resized.
If the input data overlaps, e.g., elemental matrices are being
assembled, it would be efficient to have sufficient elbow room
to minimize the number of sorts and compressions.
In this case, a tight upper bound on the necessary storage is the
sum of the sizes of the elemental matrices.
The entries are assembled
by a call to {\tt InpMtx\_changeStorageMode()}.
\item
Create an {\tt IVL} object that contains the full adjacency of
$A + A^T$ by calling the {\tt InpMtx\_fullAdjacency()} method.
\item
Create a {\tt Graph} object using the {\tt Graph\_init2()} method
and the {\tt IVL} object as an input argument.
\end{enumerate}
A similar functionality exists for creating a {\tt Graph} object
from a linear combination of two {\tt InpMtx} objects that
contains the matrices $A$ and $B$.
The {\tt InpMtx\_fullAdjacency2()} method returns an {\tt IVL}
object with the full adjacency of $(A+B) + (A+B)^T$.
These two methods are called by the {\tt DPencil\_fullAdjacency()}
methods to return the full adjacency of a matrix pencil.
\par
Here is a common sequence of events to use this object when we want
to assemble the entries of a sparse matrix.
\begin{enumerate}
\item
Create an instance of a {\tt InpMtx} object using
the {\tt InpMtx\_new()} method.
\item
Initialize the {\tt InpMtx} object using the {\tt InpMtx\_init()}
method; set the input mode to real or complex entries,
maximum number of entries for the workspace, and the number of
vectors. (The latter two quantities may be zero, for the object
resizes its storage as required.)
\item
Call the method {\tt InpMtx\_changeCoordType()}
to set the coordinate type to rows.
\item
Load data into the object using one or more of the
five input methods:
{\tt InpMtx\_inputEntry()},
{\tt InpMtx\_inputRow()},
{\tt InpMtx\_inputColumn()},
{\tt InpMtx\_inputMatrix()} and
{\tt InpMtx\_inputTriples()} methods.
Each time the workspace fills up, the raw data is sorted and
compressed and then the workspace is resized.
If the input data overlaps, e.g., elemental matrices are being
assembled, it would be efficient to have sufficient elbow room
to minimize the number of sorts and compressions.
In this case, a tight upper bound on the necessary storage is the
sum of the sizes of the elemental matrices.
The entries are assembled
by a call to {\tt InpMtx\_changeStorageMode()}.
\end{enumerate}
The {\tt InpMtx} object is now ready to be permuted, take part in a
matrix-vector multiply, become part of a {\tt Pencil} matrix pencil
object, or serve as input to a numeric factorization.
\par
{\bf NOTE:} to improve performance we have changed the
{\tt InpMtx\_fullAdjacency()} method.
The {\tt InpMtx} object must be in the chevron coordinate type
and have its storage mode be by vectors.
Previously, this was done if necessary inside the method.