%%%%%%%%%% config.tex %%%%%%%%%%
%
% $Id: formulae.tex,v 1.1 2009/12/17 17:43:53 lbaldini Exp $
%
\documentclass[fleqn,twoside,draft]{article}

%
% Dimensions
%
\textheight      9.0in               % Height of text part of page
\textwidth       7.0in               % Width of text part of page
\topmargin      -0.25in              % Nominal distance from top of page
\oddsidemargin  -0.25in              % Left margin on odd-numbered pages.
\evensidemargin -0.25in              % Left margin on even-numbered pages.

%
% Common commands
%
\newcommand{\myIt}[1]{{\em #1}}
\newcommand{\register}[1]{{\em #1}}
\newcommand{\secref}[1]{sec. \ref{#1}}
\newcommand{\appendref}[1]{appendix \ref{#1}}
\newcommand{\Secref}[1]{Sec. \ref{#1}}
\newcommand{\Appendref}[1]{Appendix \ref{#1}}
\newcommand{\xmlNode}[1]{$<$#1$>$}
\newcommand{\executable}[1]{{\tt #1}}
\newcommand{\regMask}[1]{{\tt #1}}
%
% Packages
%
% To include postscript figures
\usepackage{graphicx}
% landscape tables
%\usepackage[figuresright]{rotating}
\usepackage{amsmath}

%
% Declarations for front matter
%
\title{Formuale for ACD Reconstruction}

\author{E. Charles, L. Baldini}

\begin{document}

% typeset front matter
\maketitle

%
% Abstract
%
\begin{abstract}

This document describes various formulae used in the ACD reconstruction.
\vspace{1pc}
\end{abstract}

%
% Text proper
%
\section{Introduction \label{sec:introduction}}

All the ACD geometrical calculations are trying to establish answers to a simple question: {\em How close did a given track come to the edge a particular tile or ribbon?}.  The complications arise because of distinctions between 2D and 3D distances of closest approach as questions as to where the track parameters are defined.

The ACD reconstruction uses three different types of calculations.
\begin{enumerate}
  {\item Finding the point of closest approach to a point.}
  {\item Finding the point of closest approach to a ray.}
  {\item Projecting a track to a plane.}
\end{enumerate}

In the first two cases the relevant quantities are the point of closest approach (POCA), the vector of closest approach (VOCA) the distance of closest approach (DOCA), and the projection of the track covariance matrix along the vector of closest approach, which is also the estimate of the error on the DOCA.  In the last case the relevant quantities are the intersection point, the distances along the plane to the edges of the tile, and projection of the track covariance matrix onto the plane.
%
% Section on Formualae
%   Sub-sections: Trigger, General, ACD, CAL, TKR
%
\section{Formulae \label{sec:formulae}}

\subsection{Conventions}

\subsubsection{Tracks}

The TKR Kalman fit expresses the track parameters and covariance matrix in terms of the slope and intercept in each projection $(x_0,s_x,y_0,s_y)$ where the free parameter is $z$.  Since some of the ACD tiles are not oriented in X-Y plane it is much easier to work in terms of a track express as vector and a reference point $(v_x,v_y,v_z,x_0,y_0)$ with the free parameter being the path-length along the track $s$.  The transformation equations are:

\begin{subequations}
  \begin{gather}
    \hat{v}_x = \frac{s_x}{(1 + {s_x}^2 + {s_y}^2)^{1/2}} \\
    \hat{v}_y = \frac{s_y}{(1 + {s_x}^2 + {s_y}^2)^{1/2}} \\
    \hat{v}_z = \frac{1}{(1 + {s_x}^2 + {s_y}^2)^{1/2}} \\
    x_0 = x_0 \\
    y_0 = y_0
  \end{gather}
\end{subequations}

The corresponding covariance $5\times4$ derivative matrix is:

\begin{equation}
  A =
  \begin{pmatrix}
    0 & \hat{v}_z ( 1 - { \hat{v}_x } ^2 ) & 0 & -\hat{v}_x\hat{v}_y\hat{v}_z \\
    0 & -\hat{v}_x\hat{v}_y\hat{v}_z & 0 & \hat{v}_z ( 1 - { \hat{v}_y } ^2 ) \\
    0 & -\hat{v}_x{\hat{v}_z}^2 & 0 & -\hat{v}_y{\hat{v}_z}^2\\
    1 & 0 & 0 & 0 \\
    0 & 0 & 1 & 0
  \end{pmatrix}
\end{equation}

Given these equations we can express an track parameters in the form $(\hat{v},\vec{x})$ and transform the covariance matrix from the $4\times4$ slope-intercept (${\sigma_{x,s}}^2$) to the $5\times5$ vector-point form (${\sigma_{v,x}}^2$):
\begin{equation}
  (\sigma_{v,x})^2 = A {\sigma_{v,x}}^2 A^T
\end{equation}

It is also useful to write down esplicitly the inverse transformation, which turns out to be handy when one needs to convert to the tracker representation a track which is espressed in the $(\hat{v},\vec{x})$. This is needed, for instance, if one wants to Kalman propagate to the ACD a calorimeter track (i.e. the direction of a calorimeter cluster).
The transformation equations read:
\begin{subequations}
  \begin{gather}
   x_0 = x_0\\
    s_x = \frac{\hat{v}_x}{\hat{v}_z}\\
    y_0 = y_0\\
    s_y = \frac{\hat{v}_y}{\hat{v}_z}
  \end{gather}
\end{subequations}
and the corresponding $4\times5$ covariance matrix is:
\begin{equation}
  B =
  \begin{pmatrix}
   0  & 0 & 0 & 1 & 0\\
   1/\hat{v}_z  & 0 & -\hat{v}_x/\hat{v}_z^2 & 0 & 0\\
   0  & 0 & 0 & 0 & 1\\
   0  & 1/\hat{v}_z & -\hat{v}_y/\hat{v}_z^2 & 0 & 0\\
  \end{pmatrix}
    =
  \begin{pmatrix}
   0  & 0 & 0 & 1 & 0\\
   (1 + s_x^2 + s_y^2)^{1/2}  & 0 & -s_x(1 + s_x^2 + s_y^2)^{1/2} & 0 & 0\\
    0 & 0 & 0 & 0 & 1\\
    0 & (1 + s_x^2 + s_y^2)^{1/2} & -s_y(1 + s_x^2 + s_y^2)^{1/2} & 0 & 0\\
  \end{pmatrix}
\end{equation}
We wrote the last matrix in terms of both the old and the new variables in such a way it is immediate to verify that:
\begin{equation}
  BA =
  \begin{pmatrix}
   0  & 0 & 0 & 1 & 0\\
   1/\hat{v}_z  & 0 & -\hat{v}_x/\hat{v}_z^2 & 0 & 0\\
   0  & 0 & 0 & 0 & 1\\
   0  & 1/\hat{v}_z & -\hat{v}_y/\hat{v}_z^2 & 0 & 0\\
  \end{pmatrix}
  \begin{pmatrix}
    0 & \hat{v}_z ( 1 - { \hat{v}_x } ^2 ) & 0 & -\hat{v}_x\hat{v}_y\hat{v}_z \\
    0 & -\hat{v}_x\hat{v}_y\hat{v}_z & 0 & \hat{v}_z ( 1 - { \hat{v}_y } ^2 ) \\
    0 & -\hat{v}_x{\hat{v}_z}^2 & 0 & -\hat{v}_y{\hat{v}_z}^2\\
    1 & 0 & 0 & 0 \\
    0 & 0 & 1 & 0
  \end{pmatrix}
  = {\rm I_{4\times4}}
\end{equation}
On a side, we note that the trick in the other verse does not work. The $5\times5$ matrix $BA$ is not ${\rm I_{5\times5}}$, which apparently is a well known feature of the Jacobian matrices involving a change of dimensionality (the mapping from a 5-dimensional space to a 4-dimensional one is not unique).

\subsubsection{ACD Tiles}

For the most part ACD tiles are defined as flat planes.  A total of 10 tile on the sides of the top of the ACD which are bent to cover gaps in the ACD are approximated as two orthogonal planes.  In either case all the geometrical calculations are made with respect to the tile planes.

Any given plane is defined in terms of a center point $\vec{q}$ and orientation matrix $R$.  The rows of the orientation matrix define unit vectors along the tile local $x,y,z$ axes, ($\hat{r}_{x},\hat{r}_{y},\hat{r}_{z}$).  The local axes are oriented so that the tile extends in $x,y$ and the the $z$ axis points out of the LAT.  Sometime we refer the normal to the plane $\hat{r}_{z}$ as the normal vector $\hat{n}$.  Finally, the active region of the plane is defined by the extent of the tile in local $x,y$.

For three dimensional calculations we use the corners of the tile $\vec{c}_i$.  We also define the 4 rays that connect each set of adjacent corners.  Each ray is specified by a direction vector and a start point $(\hat{r}_i,\vec{q}_i)$.  Note that $\hat{r}_i = \vec{c}_i - \vec{c}_{i+1}$ and $\vec{q}_i = \vec{c}_i$.

For tracks that pass inside the tile it is sufficient to find with edge ray the track comes closest to.  However, for tracks that miss the tile we must also consider all four corners, as the point of closest approach might not fall inside any of the tile edges.

\subsubsection{ACD Ribbons}

The ACD ribbons are modeled as a series of rays with a direction and a start point $(\hat{r}_i,\vec{q}_i)$.

For each of the ribbon rays we check if the POCA falls along that ray.  If it does not we must also consider the POCA at the relevant end of the ray.  The POCA w.r.t. the entire ribbon is the closest POCA of any of the various segments.

\subsection{POCA Between a Track and a Point}

Given a track defined by $(\hat{v},\vec{x})$ with a corresponding covariance matrix $(\sigma_{v,x})^2$ and a point $\vec{q}$, the POCA ($\vec{p}$), VOCA ($\vec{J}$) and DOCA ($d$) are:

\begin{subequations}
\begin{gather}
  \vec{p} = \vec{x} + s \hat{v} \\
  \vec{J} = \vec{\Delta} + s \hat{v} \\
  d = |\vec{J}|
\end{gather}
\end{subequations}

Where $\vec{\Delta}$ is the vector between track and ray reference points: $\vec{\Delta} = \vec{x} - \vec{q}$.  Furthermore, $s$ is the path-length along the track where the POCA occurs.  It is given by:
\begin{equation}
  s = \vec{\Delta} \cdot \hat{v}
\end{equation}

The derivatives to transform the covariance matrix from the $(\vec{v},\vec{x})$ representation to the errors on $\vec{p}$ are:
\begin{subequations}
\begin{gather}
  \frac{\partial J_{i}}{\partial v_{j}} = \Delta_i \hat{v}_{j} + s \delta_{ij} \\
  \frac{\partial J_{i}}{\partial x_{j}} = \hat{v}_{i} \hat{v}_{j} + \delta_{ij} \\
\end{gather}
\end{subequations}

Given these equations we can work out the 3 X 5 derivative matrix $B_{(point)}$ as:

\begin{equation}
  B_{(point)} =
\begin{pmatrix}
  \Delta_0 \hat{v}_{0} + s &
  \Delta_0 \hat{v}_{1} &
  \Delta_0 \hat{v}_{2} &
  \hat{v}_{0} \hat{v}_{0} + 1 &
  \hat{v}_{0} \hat{v}_{1} \\
  \Delta_1 \hat{v}_{0} &
  \Delta_0 \hat{v}_{1} + s &
  \Delta \hat{v}_{2} &
  \hat{v}_{1} \hat{v}_{0} &
  \hat{v}_{1} \hat{v}_{1} + 1 \\
  \Delta_2 \hat{v}_{0} &
  \Delta_1 \hat{v}_{1} &
  \Delta \hat{v}_{2} + s &
  \hat{v}_{2} \hat{v}_{0} &
  \hat{v}_{2} \hat{v}_{1}
\end{pmatrix}
\end{equation}

Then the errors on the vector of closest approach (${\sigma_{J}}^2$) and the distance of closest approach (${\sigma_{d}}^2$) are given by:

\begin{subequations}
\begin{gather}
  {\sigma_{J}}^2 =  B {\sigma_{v,x}}^2 B^{T} \\
  {\sigma_{d}}^2 =  J {\sigma_{J}}^2 p^T = p B {\sigma_{v,x}}^2 B^{T} J^T
\end{gather}
\end{subequations}

\subsection{POCA Between a Track and a Ray}

Given a track defined by $(\hat{v},\vec{x})$ with a corresponding covariance matrix $({\sigma_{v,x}}^2)$ and a ray defined by $(\hat{r},\vec{q})$, the track POCA $(\vec{p})$, VOCA $(\vec{J})$ and DOCA $(d)$ are given by:

\begin{subequations}
\begin{gather}
  \vec{p} = \vec{x} + s \hat{v} \\
  \vec{J} = \vec{\Delta} + s \hat{v} - t \hat{r} \\
  d = |\vec{J}|
\end{gather}
\end{subequations}

Where $\vec{\Delta}$ is the vector between track and ray reference points: $\vec{\Delta} = \vec{x} - \vec{q}$.  Furthermore, $s$ and $t$ are respectively the path-lengths along the track and the ray at with the POCA occurs.  They can be expressed in terms of the dot product between the track and ray directions $b = \hat{v} \cdot \hat{r}$.  The formulae are:

\begin{subequations}
\begin{gather}
  s = \frac{ b (\hat{r} \cdot \vec{\Delta}) - (\hat{v} \cdot \vec{\Delta})}{ 1 - b^2 } \\
  t = \frac{ (\hat{r} \cdot \vec{\Delta}) - b (\hat{v} \cdot \vec{\Delta})}{ 1 - b^2 }
\end{gather}
\end{subequations}

The derivatives to transform the covariance matrix from the $(\vec{v},\vec{x})$ representation to the errors on $\vec{J}$ are:
\begin{subequations}
\begin{gather}
  \frac{\partial J_{i}}{\partial v_{j}} = \frac{ \alpha_{0i} \hat{v}_j + \alpha_{1i} \hat{r}_j}{ 1 - b^2 }
                                        + s \delta_{ij} \\
  \frac{\partial J_{i}}{\partial x_{j}} = \frac{ \beta_{0i} \hat{v}_j - \beta{_1i} \hat{r}_j}{ 1 - b^2 }
                                        + \delta_{ij}
\end{gather}
\end{subequations}

Where $\vec{\alpha}_0, \vec{\alpha}_1, \vec{\beta}_0, \vec{\beta}_1$ are various useful vectors defined by:

\begin{subequations}
\begin{gather}
  \vec{\alpha}_0 = (\hat{r} \cdot \vec{\Delta} + 2bs) \hat{r} - \vec{\Delta} \\
  \vec{\alpha}_1 = (\hat{v} \cdot \vec{\Delta} + 2bt) \hat{r} - b\vec{\Delta} \\
  \vec{\beta}_0 =  b\hat{r} + \hat{v} \\
  \vec{\beta}_1 =  \hat{r} + b\hat{v}
\end{gather}
\end{subequations}

Given these equations we can work out the 3 x 5 derivative matrix $B_{(ray)}$ as:

\begin{equation}
  B_{(ray)} =
\begin{pmatrix}
    \frac{ \alpha_{00} \hat{v}_0 + \alpha_{10} \hat{r}_0}{ 1 - b^2 } + s &
    \frac{ \alpha_{00} \hat{v}_1 + \alpha_{10} \hat{r}_1}{ 1 - b^2 } &
    \frac{ \alpha_{00} \hat{v}_2 + \alpha_{10} \hat{r}_2}{ 1 - b^2 } &
    \frac{ \beta_{00} \hat{v}_0 - \beta{_10} \hat{r}_0}{ 1 - b^2 } + 1 &
    \frac{ \beta_{00} \hat{v}_1 - \beta{_10} \hat{r}_1}{ 1 - b^2 } \\
    \frac{ \alpha_{01} \hat{v}_0 + \alpha_{11} \hat{r}_0}{ 1 - b^2 } &
    \frac{ \alpha_{01} \hat{v}_1 + \alpha_{11} \hat{r}_1}{ 1 - b^2 } + s &
    \frac{ \alpha_{01} \hat{v}_2 + \alpha_{11} \hat{r}_2}{ 1 - b^2 } &
    \frac{ \beta_{01} \hat{v}_0 - \beta{_11} \hat{r}_0}{ 1 - b^2 } &
    \frac{ \beta_{01} \hat{v}_1 - \beta{_11} \hat{r}_1}{ 1 - b^2 } + 1 \\
    \frac{ \alpha_{02} \hat{v}_0 + \alpha_{12} \hat{r}_0}{ 1 - b^2 } &
    \frac{ \alpha_{02} \hat{v}_1 + \alpha_{12} \hat{r}_1}{ 1 - b^2 } &
    \frac{ \alpha_{02} \hat{v}_2 + \alpha_{12} \hat{r}_2}{ 1 - b^2 } + s &
    \frac{ \beta_{02} \hat{v}_0 - \beta{_12} \hat{r}_0}{ 1 - b^2 } &
    \frac{ \beta_{02} \hat{v}_1 - \beta{_12} \hat{r}_1}{ 1 - b^2 }
\end{pmatrix}
\end{equation}

Then the errors on the vector of closest approach (${\sigma_{J}}^2$) and the distance of closest approach (${\sigma_{d}}^2$) are given by:

\begin{subequations}
\begin{gather}
  {\sigma_{J}}^2 =  B {\sigma_{v,x}}^2 B^T \\
  {\sigma_{d}}^2 =  J {\sigma_{J}}^2 J^T = J B {\sigma_{v,x}}^2 B^T J^T
\end{gather}
\end{subequations}

\subsection{POCA Between a Track and a Plane}

This section is largely adapted from R. Johnson's earlier note \cite{planeError}.  Given a track defined by $(\hat{v},\vec{x})$ with a corresponding covariance matrix $({\sigma_{v,x}}^2)$ and a plane defined by a point ($\vec{q}$) and orientation matrix ($R = \hat{r}_x,\hat{r}_y,\hat{r}_z$, with $\hat{n} = \hat{r}_z$ normal to the plane), the track crosses the plane at a point the global frame $(\vec{p})$ and in the local frame of the place defined $(\vec{l})$  by:

\begin{subequations}
\begin{gather}
  \vec{p} = \vec{x} + s \hat{v} \\
  \vec{l} = R \vec{p} + \vec{q}
\end{gather}
\end{subequations}

Where the path-length along the track of the crossing point ($s$) can be calculated in terms of the vector between the reference points ($\vec{\Delta} = \vec{x} - \vec{q}$) and the plane normal vector $\hat{n}$.  The formula is:

\begin{equation}
  s = \frac{\vec{\Delta} \cdot \hat{n}}{ \hat{v} \cdot \hat{n}}
\end{equation}

The derivatives to transform the covariance matrix from the $(\vec{v},\vec{x})$ representation to the errors on $\vec{p}$ are:
\begin{subequations}
\begin{gather}
  \frac{\partial p_{i}}{\partial v_{j}} = \frac{- \hat{n}_j}{\hat{v}\cdot\hat{n}} \hat{v}_i
                                        + s \delta_{ij} \\
  \frac{\partial p_{i}}{\partial x_{j}} = -\frac{\Delta\cdot\hat{n}}{(\hat{v}\cdot\hat{n})^2}\hat{n}_{j}\hat{v}_i
                                        + \delta_{ij}
\end{gather}
\end{subequations}

Given these equations we can work out the 3 X 5 derivative matrix $B_{(plane)}$ as:

\begin{equation}
  B_{(plane)} =
\begin{pmatrix}
  \frac{- \hat{n}_0}{\hat{v}\cdot\hat{n}}\hat{v}_0 + s &
  \frac{- \hat{n}_1}{\hat{v}\cdot\hat{n}}\hat{v}_0 &
  \frac{- \hat{n}_2}{\hat{v}\cdot\hat{n}}\hat{v}_0 &
  1 - \frac{\Delta\cdot\hat{n}}{(\hat{v}\cdot\hat{n})^2}\hat{n}_0\hat{v}_0 &
  \frac{\Delta\cdot\hat{n}}{(\hat{v}\cdot\hat{n})^2}\hat{n}_1\hat{v}_0 \\
  \frac{- \hat{n}_0}{\hat{v}\cdot\hat{n}}\hat{v}_1 &
  \frac{- \hat{n}_1}{\hat{v}\cdot\hat{n}}\hat{v}_1 + s &
  \frac{- \hat{n}_2}{\hat{v}\cdot\hat{n}}\hat{v}_1 &
  - \frac{\Delta\cdot\hat{n}}{(\hat{v}\cdot\hat{n})^2}\hat{n}_0\hat{v}_0 &
  1 - \frac{\Delta\cdot\hat{n}}{(\hat{v}\cdot\hat{n})^2}\hat{n}_1\hat{v}_0 \\
  \frac{- \hat{n}_0}{\hat{v}\cdot\hat{n}}\hat{v}_2 &
  \frac{- \hat{n}_1}{\hat{v}\cdot\hat{n}}\hat{v}_2 &
  \frac{- \hat{n}_2}{\hat{v}\cdot\hat{n}}\hat{v}_2 + s&
  - \frac{\Delta\cdot\hat{n}}{(\hat{v}\cdot\hat{n})^2}\hat{n}_0\hat{v}_0 &
  - \frac{\Delta\cdot\hat{n}}{(\hat{v}\cdot\hat{n})^2}\hat{n}_1\hat{v}_0
\end{pmatrix}
\end{equation}

Then the errors on the intersection point (${\sigma_{p}}^2$) and the projection into the plane (${\sigma_{l}}^2$) are given by:

\begin{subequations}
\begin{gather}
  {\sigma_{p}}^2 =  B {\sigma_{v,x}}^2 B^T \\
  {\sigma_{l}}^2 =  R {\sigma_{p}}^2 R^T = R B {\sigma_{v,x}}^2 B^T R^T
\end{gather}
\end{subequations}

\clearpage

%
% End of Main body.
%
%

%
% appendices.
%   sections:  Registers, ACD Maps in GEM, LPA votes syntax. LCI votes syntax.  Ancillary Files syntax.
%
\appendix

\clearpage

\begin{thebibliography}{9}

%\cite{planeError}
\bibitem{planeError}
R. Johnson
``Projection of the Track Covariance Matrix onto an Arbitrary Plane''

\end{thebibliography}

\end{document}


%!TEX root = ../dissertation.tex

\chapter{Discussion}

\newthought{The preceding results} point clearly to the relative efficacy of our new temperature-dependent cellulose simulation protocol. Figure \ref{fig:single_gdp} shows the inadequacy of conventional techniques when applied to a single cellobiose unit; the computed spectrum, shown in black, fails to agree with the experimental spectrum in red. The simulation places the main (\SI{1100}{cm^{-1}}) peak at the wrong frequency, and predicts a large peak at \SI{1400}{cm^{-1}} that is not observed. Generally, the simulated spectrum is much sharper with more distinct peaks than the experimental one.

The application of the new protocol produces a simulated spectrum much closer to that of real cellulose, as shown in Figure \ref{fig:money_single}. Here, the main peak is located properly, and has the correct shape, with two distinct shoulders to the right of the main peak. The spectrum appears much smoother, and the peaks are generally confined to low (0\textendash600 \si{cm^{-1}}), middle (1000\textendash1200 \si{cm^{-1}}), and high (1300\textendash1500 \si{cm^{-1}}) frequency regions, as is seen in the cellulose spectrum. There are some notable deviations between the two data sets, particularly a distinct peak at approximately \SI{1500}{cm^{-1}} that appears in the simulation but not in the experiment. We suspect such deviations arise from the fact that our isolated cellobiose units do not capture the effects of interchain hydrogen bonding that occurs in real cellulose, and presumably suppresses certain vibrational modes.

The peak assignments listed in Table \ref{tbl:assignments} suggest that the three frequency regions discussed above map clearly onto three distinct types of vibrations. The low frequency region is comprised of large-scale vibrations distributed over many atoms and bonds in the glucose rings. The middle frequencies about the main peak are caused by heavy atom stretching, or changes in the bond lengths between carbon and oxygen atoms. Finally, the high frequency region corresponds to bending modes, where bond angles involving both heavy atoms and hydrogen atoms change. There is also another vibrational region, consisting of hydrogen-oxygen and hydrogen-carbon stretching modes, that occurs above \SI{3200}{cm^{-1}}; however, due to a lack of comparable experimental data in this region, it will be neglected from further analysis until such data becomes available. It is worth noting that these rough assignments agree with the conclusions reached in past work on cellulose's vibrational spectra\cite{RefWorks:39}.

Figures \ref{fig:main_peak_shift} and \ref{fig:1330_peak_shift} show that the simulation is capable of accurately predicting the effect of changing temperature on mode frequency in the stretching region, but not in the bending region; for the main stretching peak, the simulation predicts that the frequency of the peak should shift by \SI{-0.02}{cm^{-1}} per Kelvin, in excellent agreement with an observed redshift of \SI{-0.03}{cm^{-1}} per Kelvin. We attribute this redshift to the anharmonicity of the Lennard-Jones potential describing atom-to-atom repulsion and attraction; essentially, at higher temperatures, the atoms in the molecule vibrate more vigorously, and go both closer and farther away from each other as stretching vibrations occur. For a perfectly harmonic potential, this would not affect the frequency, but for a Lennard-Jones potential, larger separation distances lead to a restoring force that is weaker than that of a simple quadratic potential. Therefore atoms that travel farther from the equilibrium distance spend more time in the relatively weak anharmonic region, feeling a weaker average restoring force and vibrating at a lower frequency.

The inability of the simulations to capture the behavior of the bending modes is attributed to the fact that the majority of the bending motions describe the behavior of hydrogen atoms attached to in-ring carbons. These are the precisely the hydrogens that had to be added manually to the otherwise temperature-dependent cellobiose structures. Therefore these hydrogens are essentially unaffected by the simulated temperature, and their bending motions do not change as the simulation temperature increases. This is the cause of the slope mismatch evident in Figure \ref{fig:1330_peak_shift}. It is a distinct shortcoming of this computational approach that it does not permit quantitative analysis of modes in the bending region.

The data in Table \ref{tbl:temp_freqs} represent our most comprehensive attempt to understand the effect of increasing temperature on different types of vibrations. It lists the computed frequency of all 129 vibrational modes of cellobiose at each examined temperature up to 500K. For each mode, a linear regression has been performed, and the slope of the best-fit line describing the linear relationship between temperature and frequency is listed. This is accompanied by the absolute value of the Pearson product-moment correlation function, which measures the linearity of the temperature-frequency relationship. A value of 1 for this function implies a perfect linear relationship between the two variables, and a value of 0 implies no linear relationship.

The results indicate that the vibrations most clearly affected by increasing temperature are the stretching vibrations. No non-stretching mode has a linear correlation function value higher than 0.43; carbon-oxygen and hydrogen-oxygen stretches have correlations as high as 0.9.	Low-frequency skeletal modes display little linear dependence on temperature, with correlations below 0.25 and typically below 0.1. The bending modes also have very weak linear correlations, though for the reasons described above, simulation data for these modes are probably not useful.

Vibrations associated with movement of the glycosidic linkage are affected by temperature. Modes 50 and 55, asymmetric and symmetric stretches of the linkage respectively, both display a redshift with respective linear correlations of 0.78 and 0.80 respectively.


\chapter{{\tt testMPI.c} --- A MPI Driver Program}
\label{chapter:MPI_driver}

\begin{verbatim}
/*  testMPI.c  */

#include "../BridgeMPI.h"

void JimMatMulMPI ( ) ;
void JimSolveMPI ( ) ;

/*--------------------------------------------------------------------*/

void main ( int argc, char *argv[] )
/*
   -----------------------------------------------------------------
   MPI environment: read in Harwell-Boeing matrices, using factor,
   solve, and multiply routines based on spooles, invoke eigensolver

   created  -- 98mar31, jcp
   modified -- 98dec18, cca
   -----------------------------------------------------------------
*/
{
BridgeMPI   bridge ;
MPI_Comm    comm ;

char      *inFileName_A, *inFileName_B, *parmFileName, *type ;
char      buffer[20], pbtype[4], which[4] ;
int       error, fstevl, lfinit, lstevl, msglvl, myid, mxbksz, ncol,
          ndiscd, neig, neigvl, nfound, nnonzeros, nproc, nrhs, nrow,
          prbtyp, rc, retc, rfinit, seed, warnng ;
int       c__5 = 5, output = 6 ;
int       *lanczos_wksp ;
InpMtx    *inpmtxA, *inpmtxB ;
FILE      *msgFile, *parmFile ;
double    lftend, rhtend, center, shfscl, t1, t2 ;
double    c__1 = 1.0, c__4 = 4.0, tolact = 2.309970868130169e-11 ;
double    eigval[1000], sigma[2] ;
double    *evec;
/*
   ---------------------------------------------------------------
   find out the identity of this process and the number of process
   ---------------------------------------------------------------
*/
MPI_Init(&argc, &argv) ;
MPI_Comm_dup(MPI_COMM_WORLD, &comm) ;
MPI_Comm_rank(comm, &myid) ;
MPI_Comm_size(comm, &nproc) ;
fprintf(stdout, "\n myid = %d", myid) ;
fflush(stdout) ;
/*--------------------------------------------------------------------*/
/*
   -----------------------------
   decode the command line input
   -----------------------------
*/
if ( argc != 7 ) {
   fprintf(stdout,
      "\n\n usage : %s msglvl msgFile parmFile seed inFileA inFileB"
      "\n    msglvl   -- message level"
      "\n    msgFile  -- message file"
      "\n    parmFile -- input parameters file"
      "\n    seed     -- random number seed, used for ordering"
      "\n    inFileA  -- stiffness matrix, in Harwell-Boeing format"
      "\n    inFileB  -- mass matrix, in Harwell-Boeing format"
      "\n                used for prbtyp = 1 or 2"
      "\n", argv[0]) ;
   return ;
}
msglvl = atoi(argv[1]) ;
if ( strcmp(argv[2], "stdout") == 0 ) {
   msgFile = stdout ;
} else {
   int    length = strlen(argv[2]) + 1 + 4 ;
   char   *buffer = CVinit(length, '\0') ;
   sprintf(buffer, "%s.%d", argv[2], myid) ;
   if ( (msgFile = fopen(buffer, "w")) == NULL ) {
      fprintf(stderr, "\n fatal error in %s"
              "\n unable to open file %s\n",
              argv[0], buffer) ;
      return ;
   }
   CVfree(buffer) ;
}
parmFileName = argv[3] ;
seed         = atoi(argv[4]) ;
inFileName_A = argv[5] ;
inFileName_B = argv[6] ;
fprintf(msgFile,
        "\n %s "
        "\n msglvl                -- %d"
        "\n message file          -- %s"
        "\n parameter file        -- %s"
        "\n stiffness matrix file -- %s"
        "\n mass matrix file      -- %s"
        "\n random number seed    -- %d"
        "\n",
        argv[0], msglvl, argv[2], parmFileName, inFileName_A,
        inFileName_B, seed) ;
fflush(msgFile) ;
if ( strcmp(inFileName_A, "none") == 0 ) {
   fprintf(msgFile, "\n no file to read from") ;
   exit(0) ;
}
/*--------------------------------------------------------------------*/
if ( myid == 0 ) {
/*
   ----------------------------------------------
   processor zero reads in the matrix header info
   ----------------------------------------------
*/
   MARKTIME(t1) ;
   readHB_info(inFileName_A, &nrow, &ncol, &nnonzeros, &type, &nrhs) ;
   MARKTIME(t2) ;
   fprintf(msgFile, "\n CPU %8.3f : read in harwell-boeing header info",
           t2 - t1) ;
   fflush(msgFile) ;
}
MPI_Bcast((void *) &nrow, 1, MPI_INT, 0, MPI_COMM_WORLD) ;
/*--------------------------------------------------------------------*/
/*
   ---------------------------------------------------------------
   read in eigenvalue problem data
   neigvl -- # of desired eigenvalues
   which  -- which eigenvalues to compute
     'l' or 'L' lowest (smallest magnitude)
     'h' or 'H' highest (largest magnitude)
     'n' or 'N' nearest to central value
     'c' or 'C' nearest to central value
     'a' or 'A' all eigenvalues in interval
   pbtype -- type of problem
     'v' or 'V' generalized symmetric problem (K,M)
                with M positive semidefinite (vibration problem)
     'b' or 'B' generalized symmetric problem (K,K_s)
                with K positive semidefinite
                with K_s posibly indefinite (buckling problem)
     'o' or 'O' ordinary symmetric eigenproblem
   lfinit -- if true, lftend is restriction on lower bound of
             eigenvalues. if false, no restriction on lower bound
   lftend -- left endpoint of interval
   rfinit -- if true, rhtend is restriction on upper bound of
             eigenvalues.  if false, no restriction on upper bound
   rhtend -- right endpoint of interval
   center -- center of interval
   mxbksz -- upper bound on block size for Lanczos recurrence
   shfscl -- shift scaling parameter, an estimate on the magnitude
             of the smallest nonzero eigenvalues
   ---------------------------------------------------------------
*/
MARKTIME(t1) ;
parmFile = fopen(parmFileName, "r");
fscanf(parmFile, "%d %s %s %d %le %d %le %le %d %le",
       &neigvl, which, pbtype, &lfinit, &lftend,
       &rfinit, &rhtend, &center, &mxbksz, &shfscl) ;
fclose(parmFile);
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %8.3f : read in eigenvalue problem data",
        t2 - t1) ;
fflush(msgFile) ;
/*
   ----------------------------------------
   check and set the problem type parameter
   ----------------------------------------
*/
switch ( pbtype[1] ) {
case 'v' : case 'V' : prbtyp = 1 ; break ;
case 'b' : case 'B' : prbtyp = 2 ; break ;
case 'o' : case 'O' : prbtyp = 3 ; break ;
default :
   fprintf(stderr, "\n invalid problem type %s", pbtype) ;
   exit(-1) ;
}
/*
   ----------------------------
   Initialize Lanczos workspace
   ----------------------------
*/
MARKTIME(t1) ;
lanczos_init_ ( &lanczos_wksp ) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %8.3f : initialize Lanczos workspace",
        t2 - t1) ;
fflush(msgFile) ;
/*
   ----------------------------------
   initialize communication structure
   ----------------------------------
*/
MARKTIME(t1) ;
lanczos_set_parm( &lanczos_wksp, "order-of-problem", &nrow, &retc );
lanczos_set_parm( &lanczos_wksp, "accuracy-tolerance", &tolact, &retc );
lanczos_set_parm( &lanczos_wksp, "max-block-size", &mxbksz, &retc );
lanczos_set_parm( &lanczos_wksp, "shift-scale", &shfscl, &retc );
lanczos_set_parm( &lanczos_wksp, "message_level", &msglvl, &retc );
lanczos_set_parm( &lanczos_wksp, "mpi-communicator", &comm, &retc );
lanczos_set_parm( &lanczos_wksp, "qfile-pathname", "lqfil", &retc );
lanczos_set_parm( &lanczos_wksp, "mqfil-pathname", "lmqfil", &retc );
lanczos_set_parm( &lanczos_wksp, "evfil-pathname", "evcfil", &retc );
MARKTIME(t2) ;
fprintf(msgFile,
        "\n CPU %8.3f : init the lanczos communication structure",
        t2 - t1) ;
fflush(msgFile) ;
/*--------------------------------------------------------------------*/
if ( myid == 0 ) {
/*
   ------------------------------------
   processor zero reads in the matrices
   ------------------------------------
*/
   MARKTIME(t1) ;
   inpmtxA = InpMtx_new() ;
   InpMtx_readFromHBfile ( inpmtxA, inFileName_A ) ;
   MARKTIME(t2) ;
   fprintf(msgFile, "\n CPU %8.3f : read in first matrix", t2 - t1) ;
   fflush(msgFile) ;
   if ( msglvl > 2 ) {
      fprintf(msgFile, "\n\n InpMtx A object after loading") ;
      InpMtx_writeForHumanEye(inpmtxA, msgFile) ;
      fflush(msgFile) ;
   }
   lanczos_set_parm( &lanczos_wksp, "matrix-type", &c__1, &retc );
   if ( prbtyp != 3 ) {
      if ( strcmp(inFileName_B, "none") == 0 ) {
         fprintf(msgFile, "\n no file to read from") ;
         exit(0) ;
      }
      MARKTIME(t1) ;
      inpmtxB = InpMtx_new() ;
      InpMtx_readFromHBfile ( inpmtxB, inFileName_B ) ;
      MARKTIME(t2) ;
      fprintf(msgFile, "\n CPU %8.3f : read in first matrix", t2 - t1) ;
      fflush(msgFile) ;
      if ( msglvl > 2 ) {
         fprintf(msgFile, "\n\n InpMtx B object after loading") ;
         InpMtx_writeForHumanEye(inpmtxB, msgFile) ;
         fflush(msgFile) ;
      }
   } else {
      inpmtxB = NULL ;
      lanczos_set_parm( &lanczos_wksp, "matrix-type", &c__4, &retc );
   }
} else {
/*
   ------------------------------------------------
   other processors initialize their local matrices
   ------------------------------------------------
*/
   inpmtxA = InpMtx_new() ;
   InpMtx_init(inpmtxA, INPMTX_BY_CHEVRONS, SPOOLES_REAL, 0, 0) ;
   lanczos_set_parm( &lanczos_wksp, "matrix-type", &c__1, &retc );
   if ( prbtyp == 1 || prbtyp == 2 ) {
      inpmtxB = InpMtx_new() ;
      InpMtx_init(inpmtxB, INPMTX_BY_CHEVRONS, SPOOLES_REAL, 0, 0) ;
   } else {
      inpmtxB = NULL ;
      lanczos_set_parm( &lanczos_wksp, "matrix-type", &c__4, &retc );
   }
}
/*
   -----------------------------
   set up the solver environment
   -----------------------------
*/
MARKTIME(t1) ;
rc = SetupMPI((void *) &bridge, &prbtyp, &nrow, &mxbksz, inpmtxA,
              inpmtxB, &seed, &msglvl, msgFile, MPI_COMM_WORLD) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %8.3f : set up solver environment", t2 - t1) ;
fflush(msgFile) ;
if ( rc != 1 ) {
   fprintf(stderr, "\n fatal error return %d from SetupMPI()", rc) ;
   MPI_Finalize() ;
   exit(-1) ;
}
/*--------------------------------------------------------------------*/
/*
   -----------------------------------------------
   invoke eigensolver
   nfound -- # of eigenvalues found and kept
   ndisc  -- # of additional eigenvalues discarded
   -----------------------------------------------
*/
MARKTIME(t1) ;
lanczos_run ( &neigvl, &which[1] , &pbtype[1], &lfinit, &lftend,
	  &rfinit, &rhtend, &center, &lanczos_wksp, &bridge, &nfound,
	  &ndiscd, &warnng, &error, FactorMPI, JimMatMulMPI,
	  JimSolveMPI ) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %8.3f : time for lanczos run", t2 - t1) ;
fflush(msgFile) ;
if ( myid == 0 ) {
/*
   ----------------------------------------------
   processor 0 deals with eigenvalues and vectors
   ----------------------------------------------
*/
   MARKTIME(t1) ;
   neig   = nfound + ndiscd ;
   lstevl = nfound ;
   lanczos_eigenvalues (&lanczos_wksp, eigval, &neig, &retc);
   fstevl = 1 ;
   if ( nfound == 0 ) fstevl = -1 ;
   if ( ndiscd > 0 ) lstevl = -ndiscd ;
   hdslp5_ ("computed eigenvalues returned by hdserl",
            &neig, eigval, &output, 39L ) ;
   MARKTIME(t2) ;
   fprintf(msgFile, "\n CPU %8.3f : get and print eigenvalues",
           t2 - t1) ;
   fflush(msgFile) ;
/*
   -------------------------
   get eigenvectors and print
   -------------------------
*/
/*
   MARKTIME(t1) ;
   neig = min ( 50, nrow );
   Lncz_ALLOCATE(evec, double, nrow, retc);
   for (i = 1; i<= nfound; i++) {
      lanczos_eigenvector(&lanczos_wksp, &i, &i, newToOld,
                          evec, &nrow, &retc) ;
      hdslp5_("computed eigenvector returned by hdserc",
              &neig, evec, &output, 39L ) ;
   }
   MARKTIME(t2) ;
   fprintf(msgFile, "\n CPU %8.3f : get and print eigenvectors",
           t2 - t1) ;
   fflush(msgFile) ;
*/
}
/*
   ------------------------
   free the working storage
   ------------------------
*/
MARKTIME(t1) ;
lanczos_free(&lanczos_wksp) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %8.3f : free lanczos workspace", t2 - t1) ;
fflush(msgFile) ;
MARKTIME(t1) ;
CleanupMPI(&bridge) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %8.3f : free solver workspace", t2 - t1) ;
fflush(msgFile) ;

MPI_Finalize() ;

fprintf(msgFile, "\n") ;
fclose(msgFile) ;

return ; }

\end{verbatim}


\documentclass{article}

\bibliographystyle{unsrt}

\title{New features in minepoch for advanced particle tracing and noise reduction}
\author{B.F. McMillan and T. Goffrey}

\begin{document}

\maketitle

This describes certain new features added to the minepoch code as part of the NEPTUNE project (Milestones 4 and 5 of the Particles subproject).

The minepoch code is designed as a proxy app for computational performance testing with a minimal codebase, and therefore does not contain a full input deck parser. Certain parameters may be adjusted via the input deck (FORTRAN namelist), but more complex modifications require hard-coded setup subroutines; there is a string-valued namelist parameter 'problem' that selects which setup subroutine is used.

See the README file for a description of how to run relevant testcases.

We describe the foundations for the new algorithms, and in the final section note some practical implementation aspects.

\section{Advanced particle tracing (M4)}

\subsection{Substepping}

The normal PIC algorithm\cite{Arber_EPOCH} may be conceptually represented as a leapfrog method of the form:

\begin{itemize}
\item
  Advance particle momentum from $p_{t-3 h/2}$ to $p_{t-h/2}$ using $E_{t-h}, B_{t-h}$.
\item
  Advance particle position from $x_{t-h}$ to $x_{h}$ using velocity calculated from momentum $p_{t-h/2}$.
\item
  Deposit (time-integrated) current based on the previous and current
  position (this is the charge-conserving Esirkepov step\cite{ESIRKEPOV2001}.
\item
  Advance Electric and Magnetic fields from $E_{t-h}, B_{t-h}$ to $E_t, B_t$ using the currents calculated in the previous step.
\end{itemize}

In cases where the timestep limitation is due to particle gyration, a simple substepping method consists of repeating the first two of these operations $N$ times with a reduced timestep $H=h/N$. Each substep $n \in [1,N]$ is of the form
\begin{equation}
   (p_{t + (2 n - 3) H/2},x_{ t + (2 n -2 ) H} ) \rightarrow (p_{t + (2 n - 1) H/2},x_{t- (2 n -2 )H/2})
\end{equation}
with overall effect of $N$ substeps
  \begin{equation}
   (p_{t +  H/2},x_{ t} ) \rightarrow (p_{t + h + H/2},x_{t + h}).
\end{equation}
  In the simple substepping currently implemented in minepoch, the current is calculated using these endpoints, so that the field is no longer time-centred. This reduces the time-accuracy of the scheme to first order for time-varying $E$ and $B$ fields (for particle tracing in static fields the algorithm is second order).

Although correcting the currents to restore  second-order accuracy in time is possible, the main purpose of substepping is in conjunction with an implicit field solver.

\subsection{Drift-kinetic species}

We implement a minimal version of Drift-kinetics based on the long-wavelength general gyrokinetic formalism (the Lagrangian used to derive the Euler-Lagrange equations is eq. 9. of Ref. \cite{mcmillansharma}, with terms of order $\epsilon$ neglected). Users are expected to make sure (and possibly post-verify) that the drift-kinetic ordering is valid. For example, if the magnetic field strength is zero somewhere in the domain the ordering will break down and division-by-nearly-zero will occur; of course, for tokamak applications, this is not a problem.

Drift-kinetic species with phase-space coordinates $\mathbf{Z}=(\mathbf{R},v_{||},\mu)$ follow the Euler-Lagrange equations
\begin{equation}
  \frac{d \mathbf{R}}{dt} = \mathbf{b} v_{||}
  + \frac{\mathbf{E} \times \mathbf{B}}{B^2}
  + \frac{m v_{||}^2}{q B^2} \mathbf{B} \times \left( \mathbf{b} . \nabla \mathbf{b} \right)
  + \frac{\mu B}{2 q B^3} \mathbf{B} \times \nabla B,
\end{equation}
\begin{equation}
  m \frac{d v_{||}}{dt} = - \mathbf{b} . ( e \nabla \phi + \mu \nabla B )
\end{equation}
and
\begin{equation}
  \frac{d \mu}{dt} = 0.
\end{equation}
Here, $\mathbf{b} = \mathbf{B}/B$.

Free and bound (magnetisation and polarisation) currents are associated with a drift-kinetic particle. The free currents are found by using the particle displacement over the computational timestep using Esirkepov current deposition. That is, a current $J_{n+1/2}$ is found consistent with the particle displacement from $\mathbf{R}_n$ to $\mathbf{R}_{n-1/2}$. Bound currents are not calculated in the existing implementation of minepoch (for electromagnetic problems, or where the drift-kinetic species is not electrons, the bound currents are not generally negligible).

The second order drift kinetic solve is an explicit midpoint method of the form
\begin{itemize}
\item
  $\mathbf{Z}_{n+1}^0$ is found via an Euler step using the fields $\mathbf{B}_n,\mathbf{E}_n$.
\item
  $\mathbf{B}^0_{n+1},\mathbf{E}^0_{n+1}$ are found by stepping Maxwell's laws, evaluating the current due to the particles displacing from $\mathbf{R}_n$ to $\mathbf{R}_{n+1}^0$ using the Esirkepov method (as per standard PIC).
\item
  $\mathbf{Z}_{n+1}$ is found by evaluating the RHS of the Euler-Lagrange equations, estimating the midpoint $\mathbf{Z}_{n+1/2} = (\mathbf{Z}_n + \mathbf{Z}_{n+1}^0)/2$ and likewise the midpoint field values.
\item
  $\mathbf{B}_{n+1},\mathbf{E}_{n+1}$ are found by stepping Maxwell's laws, evaluating the current due to the particles displacing from $\mathbf{R}_n$ to $\mathbf{R}_{n+1}$.
\end{itemize}

Note that unlike in the standard-PIC method, all the particle and field attributes are stored at the same time-point, so the combination of drift-kinetics and substepping is second-order in time without further modification.

\section{Low-noise PIC (M5) }

The low-noise PIC method is documented in report 2047355-TN-01 and is not further discussed here.

\section{Technical details}

The initial version of the minepoch code implements the standard charge-conserving fully-electromagnetic PIC method. Some preparatory work was required to modularise the code in preparation for `advanced algorithm' implementation.

The main work was to  split the particle push loop into several subroutines. In particular, the field evaluation and current deposition were extracted from the push routine. The field interface is relatively simple, and consists of a pair of subroutines; a field (and derivative) evaluation at specific position, and a current deposition subroutine that take the particle initial and final positions as arguments. We also pass a structure
to allow temporary storage.

This also allows simple implementation of other particle evolution equations (e.g. drift-kinetic) as well as the use of external field solvers.

The drift-kinetic solver uses the first and second element in the momentum array to store $v_{||}$ and $\mu$ respectively; the transformation to these velocity-space coordinates is performed after the particle loading.

\subsection{Code releases and availability}

There are two releases associated with milestones 4 and 5. Version 1.0 contains the initial development of the methods described in this document. Version 1.1 includes some improvements and fixes to v1.0, as well as code documentation. The release(s) associated with milestones are available from the GitHub repository.

\bibliography{excal}

\end{document}


\vssub
\subsection{~Intra-spectral propagation} \label{sub:spec}
\vssub
\subsubsection{~General concepts}
\vsssub

The third step of the numerical fractional step algorithm considers refraction
and residual (current-induced) wavenumber shifts. Irrespective of the spatial
grid discretization and coordinate system, the equation to be solved in this
step becomes

%-----------------------------------%
% Step : Intra-spectral propagation %
%-----------------------------------%
% eq:step_intra
% eq:k_dot_g

\begin{equation}
\frac{\p N}{\p t} + \frac{\p}{\p k} \, \dot{k}_g N +
\frac{\p}{\p \theta} \, \dot{\theta}_g N = 0
\: , \label{eq:step_intra} \end{equation} \begin{equation}
\dot{k}_g  = \frac{\p \sigma}{\p d}
    \frac{{\bf U} \cdot \nabla_x d}{c_g}  -
    {\bf k} \cdot \frac{\p {\bf U}}{\p s}
\: , \label{eq:k_dot_g} \end{equation}

\noindent
where $\dot{k}_g$ is the wavenumber velocity relative to the grid, and
$\dot{\theta}_g$ is given by (\ref{eq:theta_g_dot}) and (\ref{eq:theta_dot}).
This equation does not require boundary conditions in $\theta$-space, as the
model by definition uses the full (closed) directional space. In $k$-space,
however, boundary conditions are required. At low wavenumbers, it is assumed
that no wave action exists outside the discrete domain. It is therefore
assumed that no action enters the model at the discrete low-wavenumber
boundary. At the high-wavenumber boundary, transport across the discrete
boundary is calculated assuming a parametric spectral shape as given by
Eq. (\ref{eq:tail_N_k}). The derivatives of the depth as needed in the
evaluation of $\dot{\theta}$ are mostly determined using central
differences. For points next to land, however, one-sided differences using sea
points only are used.

Propagation in $\theta$-space can cause practical problems in an explicit
numerical scheme, as the refraction velocity can become extreme for long waves
in extremely shallow water or due to strong current shears. Similarly,
the propagation in $k$-space suffers from similar problems in very shallow water.
To avoid the need of extremely small time steps
due to refraction, the propagation velocities in $\theta$-space and $k$-space
(\ref{eq:theta_dot}) are filtered,

% eq:theta_filter

\begin{equation}
\dot{\theta} = X_{rd}(\lambda,\phi,k)\left( \dot{\theta_d} +
\dot{\theta_c} + \dot{\theta_g} \right)\: , \label{eq:theta_filter} \end{equation}

\noindent
where the indices $d$, $c$ and $g$ refer to the depth, current and great-circle
related fraction of the refraction velocity in (\ref{eq:theta_dot}). The
filter factor $X_{rd}$ is calculated for every wavenumber and location
separately, and is determined so that the \cfl\ number for propagation in
$\theta$-space due to the {\em depth} refraction term cannot exceed a pre-set
(user defined) value (default 0.7). This corresponds to a reduction of the
bottom slope for some low frequency wave components. For mid-latitudes, the
affected components are expected to carry little energy because they are in
extremely shallow water. Long wave components carrying significant energy are
usually traveling toward the coast, where their energy is dissipated
anyway. This filtering is also important for short waves, and close to the
pole. The effect of this filter can be tested by reducing the time steps for
intraspectral refraction and by looking at the maximum CFL numbers in the
output of the model.  These are computed just before the filter is applied.

% \vspace{\baselineskip}
% \centerline{\ldots ADD DYNAMIC TIME INTEGRATION \ldots}

The spectral space is always discretized with constants directional increments
and a logarithmic frequency grid (\ref{eq:sigma_grid}) to accommodate
computations of the nonlinear interaction $S_{nl}$. First, second and third
orders schemes are available, and are presented in the following sections.


\chapter{The Community Earth System Model}
This%
\sidefigure{The \ac{CESM} model grid in comparison to a regular latitude / longitude grid.}[fig:cesm-grids]%
{\importpgf{figures/cesm/cesm-grid/}{cesm-grid-1.pgf}\\%
 \importpgf{figures/cesm/cesm-grid/}{cesm-grid-2.pgf}}%
chapter gives a brief introduction to \ac{CESM}, the climate model I have used for my simulations, and \ac{POP2}, the ocean model that is implemented in recent \ac{CESM} versions. \ac{CESM} is developed at the National Center of Atmospheric Research (NCAR), and the first version of its predecessor CCSM was released in 1983. \ac{CESM} is widely used by research groups around the world, and simulations were \eg included in several IPCC reports. In my experiments, I have used the current version of \ac{CESM}, \ac{CESM} 1.2.2, which was released during June 2014.

The following sections describe the structure of the dipole grids the solution is calculated on (\secref{sec:cesm-grid}), the initial state and forcing in the \ac{CESM} ocean model (\secref{sec:cesm-initial}), and the anisotropic lateral friction parameterization that is used by default (\secref{sec:cesm-friction}).

\section{Model Grids}
\label{sec:cesm-grid}
Since \ac{POP2} (and thus \ac{CESM}) operates only on grids that can be mapped onto a two-dimensional surface, every model grid necessarily contains two singularities, located at the poles in a na\"ive spherical coordinate mapping (\ie \(x = r \cos \theta \cos \phi\), \(y = r \cos\theta \sin\phi\) with radius \(r\), longitude \(\phi\), and latitude \(\theta\)). Since singularities may cause numerical problems during solution or post-processing, the model grid is constructed in such a way that both singularities are located above land masses (Greenland and Antarctica, \cf \figref{fig:cesm-grids}), leading to a smooth ocean grid.

These so-called \emph{dipole grids} were introduced by \citet{madec} and \citet{smith}, and are created through an iterative process where the North Pole is displaced gradually, while the latitude circles are enforced to join a standard Mercator grid at the equator. In the northern hemisphere of a dipole grid, vectors like the velocities \(u\) and \(v\) are generally \emph{not} strictly east-west / north-south aligned; however, for latitudes south of about \ang{60}N, this effect is small.

In the following numerical experiments with \ac{CESM}, two different grids are used:
%
\begin{itemize}
	\item[\grid{x1}:] \(384 \times 320\) grid cells in the horizontal, \(60\) in the vertical. Zonal resolution of \ang{1.125} (\SI{5}{\kilo\metre} at the poles vs. \SI{125}{\kilo\metre} at the equator), meridional between \ang{0.27} (\SI{28}{\kilo\metre}) and \ang{0.5} (\SI{72}{\kilo\metre}), leading to an effective resolution of about \ang{1}. Vertical layer height between \num{10} and \SI{250}{\metre}.
	\item[\grid{x3}:] \(116 \times 100\) horizontal grid cells. Zonal resolution \ang{3.6} (\SI{17}{\kilo\metre} at the poles vs. \SI{400}{\kilo\metre} at the equator), meridional between \ang{0.6} (\SI{40}{\kilo\metre}) and \ang{2.8} (\SI{380}{\kilo\metre}), effective resolution of about \ang{3}. Vertical layering as in \grid{x1} (see \figref{fig:bathymetry} for bathymetry).
\end{itemize}
%
Apart from the varying cell spacing, both grids are structurally identical.

Since the computational cost of the \grid{x1}-grid is one order of magnitude higher than that of the \grid{x3} grid, the \ang{3} model is still widely used. Most of my numerical experiments have been carried out on the \grid{x3}-grid (cf.\ \tabref{tab:runs}); only three reference runs have been made with the \grid{x1} version. A comparison of this low-resolution model to the intermediate and high-resolution \ac{CESM} models can be found in \cite{shields}.
%
\begin{figure}
	\centering
	\importpgf{figures/cesm/bathymetry/}{bathymetry.pgf}
	\caption{Bathymetry in the \grid{x1} grid.}
	\label{fig:bathymetry}
\end{figure}

\section{Initial Conditions \oldand Forcing}
\label{sec:cesm-initial}
The initial conditions used in the ocean component of \ac{CESM} are described in \cite{danabasoglu}. Tracer fields like temperature and salinity are initialized with a dataset created by blending data from \cite{levitus} and \cite{steele}, representing mean conditions in January. The ocean is spun-up from rest, \ie all velocities are initially zero.

Although \ac{CESM} is perfectly capable of running fully coupled climate simulations, I have only used the ocean model with a static atmosphere for the experiments in this thesis, since it requires much less computational resources and makes it easier to examine the response of the ocean without worrying about feedback with the atmosphere\sidenote[-2]{Since I am mostly looking at kinematic processes, the findings in this study should be equally valid in a coupled simulation.}. The static atmospheric forcing that is applied is described in \cite{largeforcing} and combines many different data sets from observations. In order to obtain a solution that is as close to the observed present-day values as possible, some parameters such as wind speed and relative humidity have been fine-tuned in certain regions.

\section{Lateral Friction in CESM}
\label{sec:cesm-friction}
The%
%
\sidefigure[Viscosity parameters \(A\) and \(B\) in \texttt{x3\_default}.]{Viscosity parameters \(A\) and \(B\) in \run{x3_default}. Note the wide Munk layer with viscosities of the order \(\SI{e5}{\metre\squared\per\second}\) and the comparably low background values \(\sim \SI{e3}{\metre\squared\per\second}\).}[fig:default-viscosity]%
{\importpgf{figures/cesm/viscosity/}{x3_default_lowsfwf.pgf}}%
%
actual lateral friction parameterization used in CESM was initially developed by \citet{large} and refined by \citet{smithvisc} and \citet{jochum}. It uses a set of seven different parameters (\tabref{tab:viscpar}), here denoted as \(\nu_A\), \(\nu_B\), \(\nu_M\), and \(\nu_1\) through \(\nu_4\). Apart from regions where \(u\) is not aligned in east-west direction, \ie away from the North pole, the lateral friction term is calculated as (\cite{pop2}):
%
\begin{equation}
\vec{\mathcal{F}}_H =
	\begin{pmatrix}
		Au_{xx} + Bu_{yy} \\
		Bv_{xx} + Av_{yy} \\
	\end{pmatrix}
	\label{eq:friction-cesm}
\end{equation}
%
with two spatially varying parameters \(A\) and \(B\). From the form of \eqref{eq:friction-cesm}, it becomes clear that \(A\) acts on curvature \emph{parallel} to the flow, while \(B\) acts on curvature \emph{perpendicular} to it. Note that while \(A\) and \(B\) are not strictly viscosities but rather a representation of diffusion through unresolved turbulence (cf.\ \secref{sec:friction-diff}), they are called viscosity parameters throughout \ac{CESM} / \ac{POP2}, so I will refer to these quantities as parallel (\(A\)) and perpendicular (\(B\)) viscosity parameters for the remainder of this study. This anisotropic formulation of the friction term has been chosen to allow for sharp features in the ocean circulation, while minimizing numerical noise (cf. \secref{sec:noise}).

The viscosity parameters \(A\) and \(B\) are calculated in two steps \citep{jochum}; first:
%
\begin{align}
	A' &= \max(A_\text{SGS},A_\text{Munk}) \\
	B' &= \max(B_\text{SGS},B_\text{Munk}),
\end{align}
%
and finally:
%
\begin{align}
	A &= \min(A',A_\text{cfl}) \\
	B &= \min(B',B_\text{cfl}).
\end{align}
%
The parameters \(A_\text{SGS}, B_\text{SGS}, A_\text{Munk}, B_\text{Munk}, A_\text{cfl}, B_\text{cfl}\) are calculated as follows:
%
\begin{items}
	\item \(A_\text{cfl}\) and \(B_\text{cfl}\) are the upper bounds imposed by a diffusive stability criterion (\cf \secref{sec:cfl}), and read:\sidenote[-1]{Formulation as in version 1.2.2 of the \ac{CESM} source code.}
	%
	\begin{equation}
	A_\text{cfl} = B_\text{cfl} = \frac{1}{8 \updel t} \left(\updel x^{-2} + \updel y^{-2}\right)^{-1}
	\end{equation}
	%
	with time step size \(\updel t\) and grid spacings \(\updel x\), \(\updel y\).
	\item \(A_\text{Munk}\) and \(B_\text{Munk}\) impose a lower bound on viscosity depending on the distance to a western boundary. The reasoning for introducing this term is that the characteristic boundary layer length scale in the Munk model is given by \eqref{eq:munkwidth}, \ie \((A_H/\beta)^{1/3}\). Thus, if the chosen viscosity becomes too small, the western boundary layer will not be resolved by the model, which may lead to unphysical behavior. The parameters are defined as
	%
	\begin{flalign}
		\hspace*{-6ex} A_\text{Munk}(\vec{x}) = B_\text{Munk}(\vec{x}) =
			\begin{cases}
				\nu_M \beta \updel x^3 & \text{if } \delta(\vec{x}) \leq \nu_3 \updel x \\
				\nu_M \beta \updel x^3 \exp\left(-\nu_2(\delta(\vec{x}) - \nu_3 \updel x)\right) & \text{else}
			\end{cases}
	\end{flalign}
	%
	with \(\delta\) denoting the zonal distance to the nearest western boundary at a position \(\vec{x}\).
	\item \(A_\text{SGS}\) and \(B_\text{SGS}\) are intended to represent all unresolved sub-grid scale physics. These parameters are chosen as:
	%
	\begin{align}
	A_\text{SGS} &= \nu_A \\
	B_\text{SGS} &= \nu_B \left( 1 + \nu_1 (1 - \cos(2\theta')) \right),
	\end{align}
	%
	with
	%
	\begin{equation}
	\theta' = \ang{90} \frac{\min(\abs{\theta},\nu_4)}{\nu_4},
	\end{equation}
	%
	such that \(B_\text{SGS} = \nu_B\) at the equator, increasing polewards until hitting the latitude \(\nu_4\), where \(B_\text{SGS} = (1 + 2\nu_1) \nu_B\).
\end{items}
%
Note that \(A_\text{cfl}\) and \(A_\text{Munk}\), and thus \(A\) and \(B\), are dependent on the grid spacings \(\updel x\), \(\updel y\). Hence, all parameters are fine-tuned in a heuristic manner to the resolution at hand. For an overview of the viscosity parameters \(\nu_A\), \(\nu_B\), \(\nu_M\), and \(\nu_1\) through \(\nu_4\) refer to \tabref{tab:viscpar}. The viscosity structure of the \grid{x3} default run is shown in \figref{fig:default-viscosity}, and that of all runs in \secref{sec:viscosity-all}.
%
\begin{table}
	\centering
	\begin{tabular}{lllll}
		\multicolumn{3}{c}{Parameter Name} & \multicolumn{2}{c}{Default value} \\ \cmidrule(l){1-3} \cmidrule(l){4-5}
		Here & \citeauthor{jochum} & \ac{CESM} & \ac{CESM} \grid{x1} & \ac{CESM} \grid{x3} \\ \cmidrule(l){1-5}
		\(\nu_A\) & \(A_\text{eddy}\) & \texttt{vconst\_1} & \SI{600}{\metre\squared\per\second} & \SI{1000}{\metre\squared\per\second} \\
		\(\nu_1\) & \(C_2\) & \texttt{vconst\_2} & 0.5 & 24.5 \\
		\(\nu_M\) & unnamed & \texttt{vconst\_3} & 0.16 & 0.2 \\
		\(\nu_2\) & unnamed & \texttt{vconst\_4} & \SI{2e-3}{\kilo\metre} & \SI{e-3}{\kilo\metre} \\
		\(\nu_3\) & unnamed & \texttt{vconst\_5} & 3 & 3 \\
		\(\nu_B\) & \(B_\text{eddy}\) & \texttt{vconst\_6} & \SI{600}{\metre\squared\per\second} & \SI{1000}{\metre\squared\per\second} \\
		\(\nu_4\) & \(\Phi_I\) & \texttt{vconst\_7} & \ang{45} & \ang{90}
	\end{tabular}
	\caption{Viscosity parameters in the parameterization used in \ac{CESM} and their default values.}
	\label{tab:viscpar}
\end{table}


\section{Computing Bootstrap Support}

\support{} computes bootstrap support values from a target tree and a file of
replicate trees. Say the target tree is in file \filename{HRV.nw} and the
replicates (20 of them) are in \filename{HRV\_20reps.nw}. You can attribute
support values to the target tree like this:

\svgCmdOutput{support_1}

In this case I have colored the support values red. Option \code{-p} uses
percentages instead of absolute counts.

\subsection{Notes}

There are many tree-building programs that compute bootstrap support. For
example, PhyML can do it, but for large tasks I typically have to distribute
the replicates over several jobs (say, 100 jobs of 10 replicates each). I then
collect all replicates files, concatenate them, and use \support{} to attribute
the values to the target tree.

\support{} assumes rooted trees (it may as well, since \nw{} is implicitly
rooted), and the target tree and replicates should be rooted the same way. Use
\reroot{} to ensure this.


\section{Conclusion}
After performing the Synthesis with Xilinx VIVAVO, we can say that in order to head into the \textbf{implementation} and generating the bitstream of the \textbf{Perceptron} we could use \textbf{another board with an higher i/o capacity}. The implementation part was not executed because of the results obtained will be biased by the i/o planning constraint; in our case this would lead only to partial conclusion.\\
On the other hand, for improving more the clock performance of the architecture, we can increase the maximum frequency of the board by \textbf{adding pipeline registers in a more frequent manner} (in the implementation there was a register after 3 FA modules) with the drawback of an higher resource utilization and an higher number of clock cycles needed to get the result.\\
Another optimization could be done in the adder architecture by adding some \textbf{carry generation logic} in order to get results with a lower number of clock cycles, even if it will make the design phase more complex.


    \filetitle{minus}{Create time-recursive lag of tseries object}{trec/minus}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
X{T-K}
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\item
  \texttt{X} {[} tseries {]} - Tseries object whose time-recursive lag
  will be created.
\item
  \texttt{T} {[} trec {]} - Initialized trec object.
\item
  \texttt{K} {[} numeric {]} - Integer scalar specifying the lag.
\end{itemize}

\paragraph{Description}\label{description}

The tseries object, \texttt{X}, referenced by \texttt{T-K} in a
time-recursive expression will, in each iteration, return a value that
corresponds to period \texttt{t-K}, where \texttt{t} is the currently
processed date from the vector of dates (or date range) associated with
the trec object, \texttt{T}.


Language model adaptation can be  applied when little training data is given for the
task at hand, but much more data from other less related sources is available.  {\tt tlm} supports two adaptation methods.

\subsection{Minimum Discriminative Information Adaptation}
MDI adaptation  is used  when domain related  data is very  little but
enough to  estimate a  unigram LM.  Basically,  the n-gram probs  of a
general  purpose (background)  LM are  scaled so  that they  match the
target unigram distribution.

\noindent
Relevant parameters:
\begin{itemize}
\item {\tt -ar=value}: the adaptation {\tt rate},  a real number ranging
 from 0 (=no adaptation) to 1 (=strong adaptation).

\item {\tt -ad=file}: the  adaptation file,  either a text  or a
  unigram table.

\item {\tt -ao=y}: open vocabulary mode, which  must be set if the adaptation file
 might contain new words to be added to the basic dictionary.
\end{itemize}

\noindent
As an example, we apply MDI adaptation on the ``adapt'' file:
\begin{small}
\begin{verbatim}
$> tlm -tr=train.www -lm=wb -n=3 -te=test -dub=1000000 -ad=adapt -ar=0.8 -ao=yes
   n=49984 LP=326327.8053 PP=684.470312 OVVRate=0.04193341869
\end{verbatim}
\end{small}

\noindent
\paragraph{Warning:}  modified shift-beta  smoothing  cannot  be applied  in  open
vocabulary mode  ({\tt -ao=yes}).  If  this is the  case, you  should either
change  smoothing method  or simply  add  the adaptation  text to  the
background LM (use {\tt -aug} parameter  of {\tt ngt}). In
general, this solution should  provide better performance.
\begin{small}
\begin{verbatim}
$> ngt -i=train.www -aug=adapt -o=train-adapt.www -n=3 -b=yes
$> tlm -tr=train-adapt.www -lm=msb -n=3 -te=test -dub=1000000 -ad=adapt -ar=0.8
  n=49984 LP=312276.1746 PP=516.7311396 OVVRate=0.04193341869
\end{verbatim}
\end{small}

\subsection{Mixture Adaptation}

\noindent
Mixture adaptation  is useful  when you have  enough training  data to
estimate a  bigram or  trigram LM and  you also have  data collections
from other domains.

\noindent
Relevant parameters:
\begin{itemize}
\item {\tt-lm=mix} : specifies mixture smoothing method
\item {\tt -slmi=<filename>}: specifies filename with information about LMs to combine.
\end{itemize}

\noindent
In the example directory, the file {\tt sublmi} contains the following lines:
\begin{verbatim}
2
-slm=msb -str=adapt -sp=0
-slm=msb -str=train.www -sp=0
\end{verbatim}

\noindent
This means  that we use train a  mixture model on the  {\tt adapt} data set and
combine it  with the train data. For each data  set the desired
smoothing method is specified  (disregard the parameter {\tt -sp}). The file
used for adaptation is the one in FIRST position.

\begin{verbatim}
$> tlm -tr=train.www -lm=mix -slmi=sublm -n=3 -te=test -dub=1000000
  n=49984 LP=307199.3273 PP=466.8244383 OVVRate=0.04193341869
\end{verbatim}

\noindent
{\bf Warning}: for  computational reasons it  is expected that  the $n$-gram
table  specified by {\tt -tr}  contains AT  LEAST the  $n$-grams of  the last
table specified in the slmi file, i.e. {\tt train.www} in  the example.
Faster computations are achieved by putting the largest dataset as the
last sub-model in the list and the union of all data sets as training
file.

\noindent
It is  also IMPORTANT  that a  large {\tt -dub} value  is specified  so that
probabilities  of  sub-LMs  can  be  correctly  computed  in  case  of
out-of-vocabulary words.


\item Discoveries:
    \begin{itemize}
      \item Dimensionality reduction and graph theoretic approaches
        give different insights into the data and identify different
        patterns as being relevant to cognition (different peak
        orders).
        \item An insight common to both approaches is that high-order
          (greater than first order) dynamic correlations are
          informative about ongoing high-level cognitive processing.
          As the level of cognitive processing decreases, cognition is
          reflected by lower-order correlations.
        \item Correlations at different orders are also associated
          with different networks of brain regions.  However, which
          networks reflect which types of interactions depends on the
          current task.  In general, lower order correlations during
          auditory listening reflect processing of low-level
          (auditory) features; mid-order correlations reflect speech
          and linguistic processing; higher-order correlations reflect
          across-sensory integration (e.g. ties to visual areas) and
          cognitive control areas.  This hierarchy dissolves during
          lower-order cognitive processing.
      \end{itemize}

      %%%%%%%

Based on prior work ~\citep{DemeEtal19} and following the direction of the field ~\citep{Turk13} we think our thoughts might be encoded in
dynamic network patterns, and possibly higher order network
patterns (Fig.~\ref{fig:direction_of_field}). We sought to test this hypothesis by developing an approach
to inferring high-order network dynamics from timeseries data.

One challenge in studying dynamic interactions is the
computational resources required to calculate higher-order correlations.
We developed a computationally tractable model of network dynamics (Fig.~\ref{fig:methods}) that takes in a feature
timeseries and outputs approximated first-order dynamics (i.e.,
dynamic functional correlations), second-order dynamics
(reflecting homologous networks that dynamically form and disperse),
and higher-order network dynamics (up to tenth-order dynamic
correlations).

We first validated our model using synthetic data, and explored how
recovery varied with different underlying data structures and kernels.   We then
applied the approach to an fMRI dataset
~\citep{SimoEtal16} in which participants listened to an audio
recording of a story, as well as scrambled versions of the same story
(where the scrambling was applied at different temporal scales).  We
trained classifiers to take the output of the model and decode the
timepoint in the story (or scrambled story) that the participants were
listening to. We found that, during the intact listening condition in the
experiment, classifiers that incorporated higher-order correlations
yielded consistently higher accuracy than classifiers trained only on
lower-order patterns (Fig.~\ref{fig:decoding_level},  a.\&d.).  By contrast, these
higher-order correlations were not necessary to support decoding the other
listening conditions and (minimally
above chance) during a control rest condition.  This suggests
that the cognitive processing that supported the most cogntively rich listening conditions
involved second-order (or higher) network dynamics.

Although we found decoding accuracy was best when incorporating
higher-order network dynamics for all but rest
  condition, it is unclear if this is a product of the brain or the
  data collection technique.  It could be that the brain is
  second-order or it could be that fMRI can
  only reliably give second-order interactions. Exploring this method
  with other data collection technique will be important to
  disentangle this question.

  \subsection*{Concluding remarks}

How can we better understand how brain patterns change over
time? How can we quantify the potential network dynamics that might be
driving these changes? One way to judge the techniques of the future is
to look at the trajectory of the fMRI field so far has taken so far
(Fig.~\ref{fig:methods}).  The field started with
univariate activation, measuring the average activity for each voxel.
Analyses of multivariate activation followed, looking at spatial patterns of
activity over voxels. Next, correlations of activity were explored, first
with measures like resting connectivity that take temporal correlation
between a seed voxel and all other voxels then with full connectivty
that measure all pairwise correlations.  Additionally, this path of increasing
complexity also moved from static to dynamic measurements.  One
logical next step in this trajectory would be dynamic higher-order
correlations. We have created a method
to support these calculations by scalably approximating dynamic higher-order
correlations.

% finally, we sought to identify which specific brain areas were
% involved in supporting cognition through high-order interactions.
% we used the eigenvector centrality results, which preserves the
% original feature space when characterizing high-order dynamic
% correlations.  we found that first and second-order correlations
% reflected auditory and speech processing in all of the story
% listening conditions.  during intact story listening, third order
% correlations reflected integration with visual areas, and fourth
% order correlations recruited high-level cognition regions.  however,
% during listening to temporally scrambled stories, these higher-order
% correlations did not involve visual areas or high-order cognitive
% control regions.  during rest we found a much different set of
% patterns.  first order correlations involved counting networks; second-order
% correlations recruited visual networks; third-order correlations
% recruited working memory networks; fourth-order correlations
% recruited episodic memory areas.

\subsubsection*{Reverse inference}
The dynamic patterns we examine comprise high-dimensional correlation
patterns at each timepoint.  To help interpret the resulting patterns
in the context of other studies, we created summary maps by computing
the across-timepoint average pairwise correlations at each order of
analysis (first order, second order, etc., up to fifteenth order
correlations).  We selected the 10 strongest (absolute value)
correlations at each order.  Each correlation is between the dynamic
activity patterns (or patterns of dynamic high-order correlations)
measured at two RBF nodes (see \textit{Hierarchical Topographic Factor
  Analysis}).  Therefore, the 10 strongest correlations involved up to
20 RBF nodes.  Each RBF defines a spatial function whose activations
range from 0 to 1.  We thresholded each RBF at 0.999 to construct a
map of spherical components that denoted the endpoints of the 10
strongest correlations.  We then carried out a meta analysis using
Neurosynth~\citep{RubiEtal17} to identify the 10 terms most commonly
associated with the given map.  This resulted in a set of 10 terms
associated with the average dynamic correlation patterns at each
order.

%%%%
For each order $n \in \{1, 2, 3, 4}$
we used the selected kernel to compute the $(n-1)^\mathrm{th}$-order
DISFC timeseries across all participants (for $n = 1$ we simply
averaged the ``order 0'' activity timeseries across participants).  We
then computed the average $n^\mathrm{th}$-order correlations (over
time) by correlating the columns of the $(n-1)^\mathrm{th}$-order
DISFC timeseries.  This yielded a single $K$ by $K$
$n^\mathrm{th}$-order correlation matrix.  Separately for each
experimental condition and order of correlations, we identified the
endpoints of the 10 strongest (absolute value) correlations
(Fig.~\ref{fig:neurosynth}).

We used this kernel to compute
%%%%

% we used temporal decoders to identify cognitivly relevant neural
% patterns in fMRI data (see forward inference section of methods).
% we explored two approaches to effiently computing high-order
% correlations: PCA (dimensionality reduction) and eigenvector
% centrality (graph measure).  both approaches yielded qualitatively
% similar results for the story listening conditions: intact story was
% best decoded using high-order correlations, whereas scrambled
% stories were best decoded using lower-order correlations.  both
% approaches also yielded slightly above-chance decoding of resting state times
% (perhaps picking up on decreasing attention and/or increasing
% mind-wandering as the resting state scan progressed).  The PCA-based
% approach achieved the highest decoding accuracy using
% non-correlational (activation-based) data, whereas the eigenvector
% centrality approach identified second-order correlations as being
% most informative about resting state times.

We next evaluated if our model of high-order correlations in brain activity can capture cognitively relevant brain patterns. We performed a decoding analysis, using cross validation to estimate (using other participants’ data) which parts of the story each weighted-mixture of higher-order brain activity pattern corresponded to (see \textit{Materials and methods}). We note that our primary goal was not to achieve perfect decoding accuracy, but rather to use decoding accuracy as a benchmark for assessing whether different neural features specifically capture cognitively relevant brain patterns.

Separately for each experimental condition, we divided participants
into two groups. For the zeroth order, we computed the mean factor
activity for each group.  For all subsequent orders up to the tenth
order, we computed the mean approximated dynamic ISFC of factor
activity for each group (see \textit{Materials and methods}), and
combined in a weighted mixutre with all previous orders
(i.e. cross-validation for the second
order contained a weighted-mixture of zeroth, first, and second order
(Fig.~\ref{fig:decoding_level}, c.\&f.).  For
each order, we correlated the group 1 activity patterns with group 2
activity patterns.  We then subdivided the group 1 to obtain an
optimal weighting parameter for each order’s correlation matrix using
the same cross validation method. We used the optimal weighting
parameters to obtain a weighted-mixture (see \textit{Materials and methods}) of each order’s correlation
matrix. Using these correlations, we labeled the group 1 timepoints
using the group 2 timepoints with which they were most highly
correlated; we then computed the proportion of correctly labeled group
1 timepoints. (We also performed the symmetric analysis whereby we
labeled the group 2 timepoints using the group 1 timepoints as a
template.) We repeated this procedure 100 times (randomly re-assigning
participants to the two groups each time) to obtain a distribution of
decoding accuracies for each experimental condition. There were 272
timepoints for paragraph condition, 300 timepoints for intact and word
conditions, and 400 timepoints for rest condition,  so chance
performance on this decoding test is was $\frac{1}{272}$,
$\frac{1}{300}$, and $\frac{1}{400}$ respectively.

We repeated this process for each set of parameters, varying kernel
type and width, and averaged over the reduction technique used to
approximate the higher-order correlations (PCA Fig.~\ref{fig:decoding_level},  a.-c. and eigenvector
centrality Fig.~\ref{fig:decoding_level},  d.-f.).  Since there is no ground truth in these analyses, and we did not know
which parameters best capture the data, we instead report a robustness
search by averaging over the parameters and reporting which results
consistently showed up across all parameters.
\begin{figure}
  \centering
  \includegraphics[width=\textwidth]{figs/brain_plots.pdf}
  \caption{\textbf{Average correlations by order for the intact listening condition.} Using eigenvector
    centrality to approximate higher-order correlations for the
    intact, paragraph scrambled, word scrambled, and rest condition.
    We plot the
    strongest 50\% absolute value
    mean correlation for \textbf{a.-d. first order, e.-h. second order,
      i.-l. third order, and m.-p. fourth order }, representing the degree of agreement by
    location pair over time.  To demonstrate how this method is
    computationally scalable, we also approximated
    \textbf{a.-d. fifteenth order} dynamic correlation, which would be
    possible to compute using conventional methods since it would require more bits to represent the solution than there are molecules in the universe.}
  \label{fig:brain_plots}
\end{figure}

The two methods used to approximate the higher-order correlations (PCA Fig.~\ref{fig:decoding_level},  a.-c. and eigenvector
centrality Fig.~\ref{fig:decoding_level},  d.-f.) capture different
facets of the activity patterns.  Using PCA, the higher-order
correlations are all linked to the original activity patterns, whereas
eigenvectory centrality breaks the immediate link with specific brain
areas and instead characterizes the position of the nodes in the
network that are similar over time.

We found for both PCA and eigenvector centrality, during the intact
condition in the experiment, classifiers that incorporated
higher-order correlations yielded consistently higher accuracy than
classifiers trained only on lower-order patterns
(Fig.~\ref{fig:decoding_level}, a.\&d.).  We plot the average
correlations for up to the fourth order for the intact condition
(Fig.~\ref{fig:brain_plots}) representing the degree of agreement by
location pair over time.  By contrast, we found that incorporating
higher-order (greater than first order) correlations did not further
improve decoding accuracy for the other listening conditions or rest
condition.  This suggests that the cognitive processing that supported
the most cognitively rich condition involved higher-order network
dynamics.

%synthetic data: we can recover dynamic correlations using different
%kernels
% wider kernels (Laplace, Gaussian) performed best when the
% correlations varied in a temporally structured way
% delta function kernels were best when the correlations varied
% randomly over time
% overall we recovered the structure we embedded in the data under all
% synthetic datasets we tested.  our approach performed best when the
% underlying correlational structure was either constant or gradually
% changing.  our approach performed worst when the underlying
% correlations varied randomly for one timepoint to the next.

\subsubsection*{Synthetic data}

To assess the performance of dynamic correlation recovery using
timecorr, we varied width the kernel and the specific structure of the
data. We applied timecorr, using delta and gaussian kernels
Fig.~\ref{fig:kernels}) to each of the following
synthetic datasets: constant, random, ramping, and block.  We then correlated each recovered
correlation matrix with the ground truth.

For the constant synthetic dataset, a gaussian kernel (width=10)
outperformed the delta kernel (Fig.~\ref{fig:synthetic_data},  a.).  This is in contrast with the random
synthetic dataset, for which the delta kernel best captures the
rapidly changing structure (Fig.~\ref{fig:synthetic_data},  b.). For
the ramping synthetic dataset, the slow changing strucutre within the
data is best
captured by the gaussian kernel and the best recovery occurs in the
middle (Ramping, Fig.~\ref{fig:synthetic_data},
c.). In addition to comparing the timecorr recovered correlation
matrices to the ground truth, we
further compared the ramping recovered correlation matrices to only the first random covariance matrix $K_{1}$
(First, Fig.~\ref{fig:synthetic_data},  c.) and to only the last
random covariance matrix $K_{2}$ (Last, Fig.~\ref{fig:synthetic_data},
c.), both of which perform best at the beginning and end respectively.

Similary for the block sythetic dataset, we compared the timecorr
recovered correlation matrices to the ground truth as well as to each
block-specific covariance matrix (Block 1-5,
Fig.~\ref{fig:synthetic_data},  d.).  Although the structure is
changing by block, the gaussian kernel once again outperforms the
delta kernel.  Performance does however drop near even boundaries for
when using the gaussian kernel.

For synthetic data where the true underyling dynamic correlations are
known, we are able to directly evaluate how well the recovered
correlations match the ground truth, for different choices of kernel
shape and width.  In contrast, or real-world data (where the ground
truth is not known), we use decoding accuracy to estimate whether a
given set of neural features reliably reflects ongoing stimulus-driven
cognitive processing.  However, under different circumstances,
different classifier properties (e.g., kernel shapes, kernel widths,
classification algorithm, etc.) will give rise to different decoding
accuracies.  We can average over different cross validation group
assignments to improve the stability of the decoding accuracy
assessments (to factor out effects due to particular group
assignments), but

cannot know whether a given

Because decoding accuracy is an indirect
reflection of how much a given set of neural features

We cannot know which choice of kernel most accurately
reflects the ``true'' information content of the data.

For example, a
given kernel might highlight particular temporal aspects of the data
in a way that enhances or diminishes decoding performance.
\textbf{JRM STOPPED HERE}

\subsubsection*{Timepoint decoding}

Prior work has shown participants share similar neural responses to
richly structured stimuli when compared to stimuli with less
structure.  To assess whether the moment-by-moment higher order
correlations were reliably preserved across participants, we used
inter-subject functional connectivity (ISFC) to isolate the
time-varying correlational structure (functional connectivity patterns
that were specifically driven by the story participants listened to.
Following the analyses conducted by (HTFA)~\cite{MannEtal18}, we first
applied \textit{hierarchical topographic factor analysis} (HTFA) to
the fMRI datasets to obtain a time series of 700 node activities for
every participant.  We then computed the dynamic weighted ISFC using a
range of kernels and widths.  Specifically, we used Gaussian, Laplace,
and mexican hat kernels, as well as widths of 5, 10, 20, and 50.  We
then approximated these dynamic correlation using two reduction measures, PCA and eigenvector centrality, and computed the dynamic weighted ISFC on the approximations.  We repeated this process up to 10th order approximated correlations.

To assess decoding accuracy, we randomly divided participants for each
stimulus into training and testing groups. For the zeroth order, we
computed the mean factor activity for each group.  For all subsequent
orders up to the tenth order, we computed the mean approximated
dynamic ISFC of factor activity for each group. To assess how
additional higher-order correlations contribute to decoding accuracy,
for each order we included a weighted-mixutre (described below) of the activity patterns of all
previous orders.  For each group of participants in turn, we compared these activity patterns (using Pearson correlations) to estimate the story times each pattern corresponded to. Specifically, we asked, for each timepoint: what are the correlations
between the first group's and second group's activity patterns at each
order. We note that the decoding test we used is a conservative in which we count a timepoint label as incorrect if it is not an exact match.

For each order we obtained the weighted-mixture of the correlation
matrices for the current order and all previous orders using mixing parameter, $\phi$, where $0 <\phi< 1$ reflects a
weighted mixture of order based decoding Fig.~\ref{fig:decoding_level}
Panel c. ). We calculated  $\phi$, by
subdividing the training group and using the quasi-Newton method of
Broyden, Fletcher, Goldfarb, and Shanno (BFGS ~\citep{NoceWrig06}) for optimization. We
repeated this cross-validation process 10 times for each parameter set.

\subsection*{Evaluation metrics}
We evaluate our approach to extracting dynamic correlations and
higher-order correlations using several metrics detailed next.  First,
we generated synthetic data using known time-varying correlations, and
then we evaluated the fidelity with which Equation~\ref{eqn:timecorr}
could recover those correlations (for synthetic datasets with
different properties, and using different kernels to define the
weights; Fig.~\ref{fig:kernels}).  We then turned to a series of
analyses on a (real) neuroimaging dataset where the ground truth
correlations were \textit{not} known.  We evaluated whether the
recovered correlations could be used to accurately label held-out
neuroimaging data with the time at which it was collected.  We used this latter evaluations (using timepoint
decoding) as a proxy for
gauging how much explanatory power the recovered correlations held
with respect to the observed data.

\subsubsection*{Generating synthetic data}
To explore recovery of a constant covariance (Fig.~\ref{fig:synthetic_data},  a.), we generated syntheic
data sampled from a constant covariance matrix. To do this, we created one random
covariance matrix, $K$, with 50 features, and for each of the 300 timepoints  we
sampled from a Gaussian distribution centered on $K$.  Similarly, we generated synthetic data
sampled from a random covariance matrix (Fig.~\ref{fig:synthetic_data}, b.) by creating a new random
covariance matrix $K(t)$, for each of the 300 timepoints and sampled from a
Gaussian distribution centered on $K(t)$.

To generate synthetic data from a dynamically changing covariance
matrix (Fig.~\ref{fig:synthetic_data},  c.),
we generated two random covariance
matrices, $K_{1}$ and $K_{2}$.  We then computed a weighted average covariance matrix
for each of the 300 timepoint, $K(t)$,
by taking the linearly spaced weights ($w$) of the two random matrices,
\begin{align}
K(t) = w(t) * K_{1} + (1 - w(t)) *  K_{2}, \\\label{eqn:ramping}
\end{align}
and for each of the 300 timepoints sampled from a
Gaussian distribution centered on $K(t)$.

Lastly, for the synthetic data containing block structure (Fig.~\ref{fig:synthetic_data},  d.), we followed the same
process of creating synthetic data sampled from a constant covariance
matrix (see above) but sampled from a new random covariance matrix
after 60 consecutive timepoints.  We then pieced the blocks together
to create a sythetic dataset with 300 total timepoints but drawn from
5 separate covariance matrices.

\subsubsection*{Recovery of ground truth parameters from synthetic
  data}

We applied timecorr, using delta and gaussian (width = 10) kernels
Fig.~\ref{fig:kernels}) to each of these
synthetic datasets, then correlated each recovered
correlation matrix with the ground truth.  We repeated this process 10
times and explored how recovery varies
with the kernel and the specific structure of the data. For the
ramping synthetic dataset (Fig.~\ref{fig:synthetic_data},  c.)  and for the
block synthetic dataset (Fig.~\ref{fig:synthetic_data},  d.)  we made further
comparisons of the timecorr recovered correlation matrices. We
compared the ramping recovered correlation matrices to only the first random covariance matrix $K_{1}$
(First, Fig.~\ref{fig:synthetic_data},  c.) and to only the last
random covariance matrix $K_{2}$ (Last, Fig.~\ref{fig:synthetic_data},
c.) from Equation~\ref{eqn:ramping}. We also compared the block recovered correlation matrices in to
the block specific covariance matrix (Block 1-5,
Fig.~\ref{fig:synthetic_data},  d.).

A major challenge to studying such patterns is that typically neither
the correlations nor the hierarchical organizations of those
correlations may be directly observed.  Rather, these fundamental
properties must be inferred indirectly by examining the observable
parts of the system-- e.g., the behaviors of the individual units of
that system.  Here we propose a series of mathematical operations that may be used to approximate dynamic correlations at a range of scales (i.e., orders of interaction).

There are two basic steps to our approach (Fig.~\ref{fig:methods_fig}).  In the first step, we take
a number-of-timepoints ($T$) by number-of-features ($F$)
\textit{matrix of observations} ($\mathbf{X}$) and we return a $T$ by
$\frac{F^2 - F}{2}$ \textit{matrix of dynamic correlations}
($\mathbf{Y}$).  Here $\mathbf{Y_0}$ describes, at each moment, how
all of the features (columns of $\mathbf{X}$) are inferred to be
interacting.  (Since the interactions are assumed to be non-recurrent
and symmetric, only the upper triangle of the full correlation matrix
is computed.)  In the second step, we project $\mathbf{Y_0}$ onto an
$F$-dimensional space, resulting in a new $T$ by $F$ matrix
$\mathbf{Y_1}$.  Note that $\mathbf{Y_1}$ contains information about
the correlation dynamics present in $\mathbf{X}$, but represented in a
compressed number of dimensions.  By repeatedly applying these two
steps in sequence, we can examine and explore higher order dynamic
correlations in $\mathbf{X}$.

To understand the neuronal computations that support cognition, we
must understand the cooperative dynamics of populations of neurons.
These populations of neurons interact within each brain structure, and
the structures interact to form complex and dynamic networks. These
interactions, at each scale, vary according to the functions our
brains are carrying out and recent work has shown these dynamic
complex patterns support consciousness~\citep{DemeEtal19}.

In the last several decades, advances in functional magnetic resonance
image (fMRI) analyses have evolved to better characterize these
interactions of brain structures.  As~\cite{Turk13} outlines,
analyses using multivariate patterns of activity have given an advance
over univariate activity patterns because they allow relative
contributions of voxels to be combined and better assess distrubted
representations. Resting-state connectivity (RS) fMRI, which is the
temporal correlation of regions during rest, has shed light on the
rich and complex spatiotemporal organization of spontaneous brain
activity.  Functional connectivity (FC) has further characterized the
cognitive state dependency of this network organization.

Recent work has shown that FC fluctuates over time~\citep{ChanGlov10}~\citep[for review]{LuriEtal18}, and the assumed stationarity of these analyses may be too
simple to capture the dynamic nature of brain activity.  Additionally,
recent work has shown that temporal
variability in functional connectivity predicts attention task
performance~\citep{FongEtal19} and that
dynamic correlations between multivariate voxel patterns can add an
additional boost compared to static multivariate voxel patterns alone~\citep{MannEtal18}.

  Most complex systems reflect dynamic interactions between myriad
  evolving components (e.g., interacting molecules, interacting brain
  systems, interacting individuals within a social network or
  ecological system, coordinated components within a mechanical or
  digital device, etc.).  Despite that these interactions are central
  to the full system's behavior (e.g., removing a component from the
  full system can change the entire system's behavior), dynamic
  interactions cannot typically be directly measured.  Rather, the
  interactions must be inferred through their hypothesized role in
  guiding the dynamics of system components.  Here we use a
  model-based approach to inferring dynamic interactions from
  timeseries data.  In addition to examining first-order interactions
  (e.g., between pairs of components) we also examine higher-order
  interactions (e.g., that characterize mirrored structure in the
  patterns of interaction dynamics displayed by different subsets of
  components).  We apply our approach to two datasets.  First, we use
  a synthetic dataset, for which the underlying dynamic interactions
  are known, to show that our model recovers those ground-truth
  dynamic interactions.  We also apply our model to a neuroimaging
  dataset and show that the high-order dynamic interactions exhibited
  by brain data vary meaningfully as a function of the cognitive
  ``richness'' of the stimulus people are experiencing.

%should we introduce the name levelup in the introduction? ie. "in the second step, levelup, we use..." -ecw
%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Methods}
%%%%%%%%%%%%%%%%%%%%%%%%

The mathematical theories behind the timecorr approach for calculating the moment-by-moment dynamic correlations in systems are described here. The function takes a number-of-timepoint by number-of-features matrix as well as a weight function to determine a moment-by-moment correlations matrix. To calculate the correlations, expectation values are found using equation 1:

\begin{equation}
\mathrm{corr}_{x,y}(t) = \frac{1}{T} \sum_{t} \frac{\left(x(t)-\mathbb{E}[x]\right)\left(y(t)-\mathbb{E}[y]\right)}{\sigma_{x}(t)\sigma_{y}(t)}
\end{equation}

%should the variables in this equation/description change to match the description in the intro?
Here, x is the timepoint component of the matrix and y is the feature component. Timepoint by timepoint, x by x, at each given moment (t) in the matrix is subtracted from the expectation value of the full timepoint matrix. The same process occurs for the features points (y) at each timepoint (t). The product of these are then divided by the standard deviation at that moment for both the timepoint and the feature. Only the upper triangle of the matrix is calculated as the interactions are assumed to be both symmetric and non-recurrent.

Two weight parameters have been used to calculate the connectivity of the data are a Gaussian weight parameter, equation 2, and a LaPlace weights parameter, equation 3.

%label as Gaussian?
\begin{equation}
\mathcal{N}\left( x | \mu, \sigma \right) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp\left(-\frac{|| x - \mu ||^2}{2\sigma^2}\right)
\end{equation}
where sigma squared is the variance and mu is the expected value.

%label as LaPlace?
\begin{equation}
\mathcal{L}\left( x | \mu, \lambda \right) = \frac{1}{2 \lambda}\left( x | \mu, \lambda \right) = \exp\left(-\frac{|x - \mu|}{\lambda}\right)
\end{equation}
where mu is the expectation values, lambda is a defined decay constant.

%figure showing the difference b/w two weights in same data set? Using the synthetic data?

When using the Gaussian weights parameter timepoints are more closely correlated to timepoints further away in the matrix than when using then the LaPlace weight function.

%Plot of kernels as Fig 1?

% New section? Mathematical Methods of Levelup?
In order to understand how the data is interconnected we use the function levelup. Levelup uses the same input as the timecorr function, a timepoint-by-function matrix.

%Diagram of input-->timecorr-->PCaA= levelup?

In the levelup method the the data first goes through the timecorr process and then is reduced using Principal Component Analysis (PCA). By utilizing PCA the output data maintains the same features as the input method. Not only does this allow for a sanity check, but also it allows for repeated use of the function. Using PCA or other reduction techniques is needed as without it the output data would get exponentially large. On the flip side using PCA, or any dimensionality reduction technique, makes the output data less accurate as information is lost.

%PCA equation?
%figure/ chart of how many levels we "go up" before data gets too muddled- depends on the correlation?

Timepoints that share high similarity across all subjects have a high probability of being stimulus driven.

To compute the correlations of multiple subjects the across mode of both timecorr and levelup are used. The across function compares one voxel in a sample to the averages of that voxel in the rest of the dataframe. This occurs throughout every voxel in the dataset. The output of the across mode is a correlation matrix that is a number of timepoints by features matrix.

%F^2-F/2 +F


\section{Discussion}
\subsection{Strengths}
\begin{enumerate}
	\item \textbf{Our model is simple and easy to understand} \\
	      Our model is the simplest model we can conceive to reflect the impact of concerned independent variables (factors regarding medication) and to solve the problem lifted by the question.

	      Our single-city model is based on the most elegant model in the field of epidemiology - the SIR model, and we reconstruct the model (mainly add two clusters of people) in order to introduce concerned independent variable into our system.

	      Our multi-city model is based on our single-city model and introduce only one `people flow` to obtain the geographic characteristic of the spread of disease.

	\item \textbf{Our model is effective and in good agreement with the reality} \\
	      Simple as they are, they are effective in reflecting the complex relationships between numerous variables and parameters, and they not only reveal the intrinsic characteristics of the spread of disease itself but also successfully link factors of medication to the spread of disease.

	      Comparing with the data we have find from several resources, the results of our model not only correspond the general trend of the records but also resemble the reality in some critical features.

	\item \textbf{Good extensibility} \\
	      Flow of people is a critical factor determining the spread of disease. Although our multi-city model only set the volume of people flow as a function of mere geographic distribution and population of cities, the determinants of people flow can be adjusted when other possible factors are considered. Then, the adjusted model can be applied to study the impact of other possible factors relating to epidemiology.

\end{enumerate}

\subsection{Weaknesses}
\begin{enumerate}
	\item \textbf{Our model is just a rough model} \\
	      For simplicity, we have neglected many potential parameters, variables or processes, and have made numerous assumptions. Eg. we did not consider the relationship between separate individuals and we did not dig deeper into the properties of social network which is a quite essential part determining the spread of disease. Some important general or specific factors are also neglected by us, a interesting example of which is a folk custom prevalent in the studied region that relatives kiss the death, which plays a significant role in the spread of disease and is categorized into \emph{Super Spread Event}(SSE) academically.

	\item \textbf{Our model is only a continuous model} \\
	      Numbers of people, number of shares of drug/vaccine, etc. are important quantities in all the process of modeling and computation. For simplicity, we regard the numbers as directly real numbers instead of integers. It is justifiable when the numbers are large, since the decimal part of the number is negligible; when the system scales down, however, the statistics dose not work and the outcome deviates a lot from reality.
\end{enumerate}