%
% begin at Jan. 2009, finished at Jan 29th; 2009 problems left behind:
% 1 for the integral force: the definition of the pt for the integral
% force is clear, but how can we do it in the real calculation? That
% means, how to convert the two principles below into the codes?  1.1
% the exponents of the basis sets are fixed to constant.  1.2 the
% position vectors in the basis sets are linear combination of the
% nuclear coordinates.
%
%
%
%

\chapter{Force Methods in Quantum Chemistry}\label{PULAY:1}
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}
%
% how to understand it
%
%
Most of the quantum chemistry study is based on the Born-Oppenheimer
approximation. In this approximation, the nucleus are considered to
move on the classic trajectory, so its motion is continuous and
smooth; where the motion of electrons is treated quantized, and able
to adapt simultaneously to the position change of nucleus.  Therefore,
the total energy of the whole molecular system is some function of the
nuclear coordinates; such dependence is called potential energy
hyper-surface (later shorted as PES).

Consequently, to determine the PES is vital in the quantum
chemistry. Such determination requires to get the energy derivatives
for an arbitrary nuclear configuration of \vect{R_{0}}, that is to
say, the PES around \vect{R_{0}} can be adequately characterized by
its Taylor series expansion:
\begin{equation}\label{PULAYeq:1}
  \begin{split}
    E(\mathbf{R}) &= E(\mathbf{R_{0}}) +
    \sum_{a}E^{a}\Delta\mathbf{R_{a}}
    +  \frac{1}{2!}\sum_{a,b}E^{ab}\Delta\mathbf{R_{a}}\Delta\mathbf{R_{b}} \\
    & +
    \frac{1}{3!}\sum_{a,b,c}E^{abc}\Delta\mathbf{R_{a}}\Delta\mathbf{R_{b}}
    \Delta\mathbf{R_{c}} + \cdots
  \end{split}
\end{equation}
Here the $E^{a}, E^{ab}$ etc. denote the first derivatives, second
derivatives etc. with respect to the total energy in the \vect{R_{0}};
and the $\Delta\mathbf{R_{a}}, \Delta\mathbf{R_{b}}$ etc. express the
small changes around the reference point of \vect{R_{0}} in the given
direction: $\Delta\mathbf{R_{a}} =
(\mathbf{R_{a}}-\mathbf{R_{0}})_{a}$.

The solution to this problem was firstly suggested by professor Peter
Pulay around $1969$. In this chapter, we will provide a thorough and
detailed analysis for this topic. The materials we are referring to,
are mainly from professor Pulay\cite{Pulay1, Pulay2, Pulay3, Pulay4,
  Pulay5}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{General derivatives expressions}
%
% derive the first and second order of derivatives in the general form
% the benefit to do this, is to make the relations in the derivatives
% more simpler.  1 non-constraint type 1.1 general functional
% expression of E 1.2 C can be seen as the function of R 1.3 the first
% and second derivatives 2 constraint type 2.1 the general Lagrangian
% functional of W under the constraint conditions 2.2 to express the
% variational conditions on W 2.3 derive the gradients, and the second
% derivatives
%
In this section, we firstly introduce some general formulas for the
derivatives of variational energy expressions.

First let's consider the energy functional:
\begin{equation}\label{PULAYeq:13}
  E = E(C,R)
\end{equation}
Here the $R$ represents the nuclear coordinates, and $C$ is the set of
variational parameter in the wave function; e.g.; in the case of SCF
wave function, $C$ is the SCF coefficients. Here we note that in the
(\ref{PULAYeq:13}) the parameters should be gotten through variation
condition:
\begin{equation}\label{PULAYeq:14}
  \frac{\partial E}{\partial C_{i}} = 0
\end{equation}
Thus for each reference coordinate of $R$ we can get a set of
variational parameters of $C$, so we can see that the $C$ is some
function of nuclear coordinates of $R$; $C = C(R)$:
\begin{equation}\label{}
  R \Rightarrow E \Rightarrow C \Rightarrow C= C(R)
\end{equation}
Therefore we can express the energy functional as:
\begin{equation}\label{PULAYeq:2}
  E = E(C(R), R)
\end{equation}
This is some simpler model for discussing the derivatives of the total
energy, for we have not imposed any further constraint conditions on
the $C$. Usually in the quantum chemistry, in the variation process of
(\ref{PULAYeq:14}) the SCF coefficients should keep orthogonal with
each other. Latter we will study this case.

Our aim is to derive the formulas for the expression of
(\ref{PULAYeq:2}) with respect to the nuclear coordinates of $R$.  For
the change of $R$ in the $a$ direction, according to the chain rule of
differentiation we have:
\begin{align}\label{PULAYeq:3}
  E_{a} &= \frac{\partial E}{\partial R_{a}} +\sum_{i}\frac{\partial
    E}{\partial C_{i}}\frac{\partial
    C_{i}}{\partial R_{a}} \nonumber \\
  &= \frac{\partial E}{\partial R_{a}}
\end{align}

In this derivation we have used the relation in the
(\ref{PULAYeq:14}). The results shows that the derivative of the
variational parameters (here is the $C$) do not enter into the
gradient formula. In the later content, as in the derivation of the
constraint variational process, we can see that the same fact holds,
too.

For the second derivatives, by differentiation of (\ref{PULAYeq:3}),
we can get:
\begin{align}\label{}
  E_{ab} &=\frac{\partial}{\partial R_{b}}\left(\frac{\partial
      E}{\partial
      R_{a}}\right) \nonumber \\
  &=\frac{\partial^{2} E}{\partial R_{a}\partial R_{b}}
  +\sum_{i}\frac{\partial^{2} E}{\partial R_{a}\partial
    C_{i}}\frac{\partial C_{i}}{\partial R_{b}}
\end{align}

So far, the discussion is all about the variational process without
constraints. However, it's usually required that in the variational
process, the orbitals or the approximated wave functions should keep
to be orthogonal with each other. Therefore, it's appropriate to
introduce the general functional with constraint conditions:
\begin{equation}\label{PULAYeq:8}
  W(C, R, \lambda) = E(C,R) - \sum_{m}f_{m}(C,R)\lambda_{m}
\end{equation}
Here the $W$ stands for the general Lagrangian functional. The
$f_{m}(C,R)$ generally denote the $m$ constraint conditions, normally
the constraints are the orthogonality conditions for the molecular
orbitals or the configurations. The $\lambda_{m}$ is simply the
Lagrangian factor. Here we note that the variation process defined in
the (\ref{PULAYeq:14}) does not hold true anymore, instead we have:
\begin{equation}\label{PULAYeq:5}
  \frac{\partial W}{\partial C_{i}} = 0 \quad (i=1,2, \cdots)
\end{equation}
On condition that:
\begin{equation}\label{PULAYeq:15}
  f_{m}(C,R) =  0 \quad (m=1,2, \cdots)
\end{equation}

Such conditions are sufficient to determine the unknown $C_{i}$ and
$\lambda_{m}$, hence we can consider the $C_{i}$ and $\lambda_{m}$ are
some functions of $R$:
\begin{equation}\label{}
  \left\{
    \begin{array}{ll}
      C_{i} = C(R),             & i=1,2,\cdots  \\
      \lambda_{m} = \lambda(R), & m=1,2,\cdots
    \end{array}
  \right.
\end{equation}

If the conditions in (\ref{PULAYeq:5}) have been satisfied, then from
the general functional in (\ref{PULAYeq:8}) we can get the total
energy:
\begin{equation}\label{PULAYeq:4}
  W(C, \lambda, R) \Rightarrow E(C, R)
\end{equation}

Now we begin to seek the expressions for the first derivative and
second derivatives related to the $E(C,R)$.

By the differentiation of $E(C,R)$, we have:
\begin{equation}\label{PULAYeq:6}
  E_{a} =\frac{\partial E}{\partial R_{a}} + \sum_{i}\frac{\partial
    E}{\partial C_{i}}\frac{\partial C_{i}}{\partial R_{a}}
\end{equation}
This is same with the (\ref{PULAYeq:3}). However, here we do not
simply have the $\frac{\partial E}{\partial C_{i}} = 0$, thus we have
to do some transformations.

For the constraint variation condition, we can further express the
(\ref{PULAYeq:5}) as:
\begin{align}\label{}
  \frac{\partial W}{\partial C_{i}} &= \frac{\partial E}{\partial
    C_{i}} - \sum_{m}\frac{\partial f_{m}(C,R)}{\partial
    C_{i}}\lambda_{m} \nonumber \\
  &= 0
\end{align}
By multiply the $\frac{\partial C_{i}}{\partial R_{a}}$ to the above
expression and sum over all the label of $i$, we can get:
\begin{equation}\label{PULAYeq:17}
  \sum_{i}\frac{\partial E}{\partial C_{i}}\frac{\partial
    C_{i}}{\partial R_{a}} - \sum_{m}\lambda_{m}\sum_{i}\frac{\partial
    f_{m}(C,R)}{\partial C_{i}}\frac{\partial C_{i}}{\partial R_{a}} = 0
\end{equation}

On the other hand, if we differentiate the constraint conditions of
(\ref{PULAYeq:15}) with respect to the $R_{a}$, we can have:
\begin{align}\label{PULAYeq:16}
  \frac{\partial f_{m}(C,R)}{\partial R_{a}} + \sum_{i}\frac{\partial
    f_{m}(C,R)}{\partial C_{i}}\frac{\partial C_{i}}{\partial R_{a}} =
  0
\end{align}
If we multiply the (\ref{PULAYeq:16}) with $\lambda_{m}$ and sum all
of label of $m$ together, we can get:
\begin{equation}\label{PULAYeq:18}
  \sum_{m}\lambda_{m}\frac{\partial f_{m}(C,R)}{\partial R_{a}} +
  \sum_{m}\lambda_{m}\sum_{i}\frac{\partial f_{m}(C,R)}{\partial
    C_{i}}\frac{\partial C_{i}}{\partial R_{a}} = 0
\end{equation}

By virtual of the results indicated in the (\ref{PULAYeq:17}) and
(\ref{PULAYeq:18}), we can have:
\begin{equation}\label{}
  \sum_{m}\lambda_{m}\frac{\partial f_{m}(C,R)}{\partial R_{a}} = -
  \sum_{i}\frac{\partial E}{\partial C_{i}}\frac{\partial
    C_{i}}{\partial R_{a}}
\end{equation}

Finally for the (\ref{PULAYeq:6}) we can have:
\begin{align}\label{PULAYeq:7}
  E_{a} &= \frac{\partial E}{\partial R_{a}} - \sum_{m}\frac{\partial
    f_{m}(C,R)}{\partial
    R_{a}}\lambda_{m} \nonumber \\
  &= \frac{\partial W}{\partial R_{a}}
\end{align}
Here the result shows the same important meaning with the
(\ref{PULAYeq:3}) that the derivatives of the variational parameters
do not enter the gradient formula. For example, in the HF calculation
(or the DFT calculation, which use the single determinant); the
evaluation of the MO coefficients can be avoided.  In the CI
calculation, the evaluation with respect to the coefficients for the
determinants can be neglected. In such scheme, only the derivatives of
the basis function integrals appearing in the energy formula need to
be calculated.

By differentiating the expression of (\ref{PULAYeq:7}) with respect to
the $R_{b}$, we can get:
\begin{align}\label{}
  E_{ab} &=\frac{\partial}{\partial R_{b}}\left(\frac{\partial
      W}{\partial
      R_{a}}\right) \nonumber \\
  &=\frac{\partial^{2} E}{\partial R_{a}\partial R_{b}} +
  \sum_{i}\frac{\partial^{2} E}{\partial R_{a}\partial
    C_{i}}\frac{\partial C_{i}}{\partial R_{b}} -
  \sum_{m}\frac{\partial^{2} f_{m}(C,R)}
  {\partial R_{a}\partial R_{b}}\lambda_{m} - \nonumber \\
  &\sum_{m}\sum_{i}\frac{\partial^{2} f_{m}(C,R)}{\partial
    R_{a}\partial C_{i}}\frac{\partial C_{i}}{\partial
    R_{b}}\lambda_{m} - \sum_{m}\frac{\partial f_{m}(C,R)}{\partial
    R_{a}}\frac{\partial \lambda_{m}}{\partial R_{b}}
\end{align}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Force calculation from SCF wave functions}
%
%
\subsection{Structure of the wave functions}
%
% 1 how to express the MCSCF wave functions 2 some gradient relations
%
%
In this section let's begin to derive the energy derivatives for the
MCSCF wave functions. Firstly, let's note that why we choose MCSCF
wave functions for calculation. In MCSCF calculation, both of the
coefficients of the determinants and the molecular orbitals are
assumed to vary, so if we fix the coefficients of the molecular
orbitals, then the whole method will recede to be the pure CI method;
if we eliminate the determinants, then it will be back to be the
Hatree-Fock method. Thus the discussion of MCSCF method will provide
us some flexibility for further discussion.

Let $\Phi$ be some normalized linear combination of orthogonal
configurations of $\Psi_{K}$:
\begin{equation}\label{}
  \Phi = \sum_{K}A_{K}\Psi_{K}
\end{equation}
With the constraint condition that:
\begin{equation}\label{}
  \langle\Psi_{K}|\Psi_{L}\rangle = \delta_{KL} \quad
  \sum_{K}A_{K}^{2} = 1
\end{equation}

Here the $\Psi_{K}$ are some fixed linear combinations of slater
determinants constructed from a set of orthogonal orbitals of
$\psi_{i}$; which is in turn $m$ linear combinations of the basis
functions of $\chi_{r}$:
\begin{equation}\label{PULAYeq:25}
  \psi_{i} = \sum_{r=1}^{m}c_{ri}\chi_{r}
\end{equation}

Since that the orbitals of $\psi$ should maintain the orthogonality
between each other, therefore the coefficients of the basis sets
should satisfy that:
\begin{align}\label{}
  \int\psi_{i}\psi_{j}d\tau &= \delta_{ij} \Rightarrow \nonumber \\
  \sum_{r}\sum_{s}c^{*}_{ri}c_{sj}\int\chi^{*}_{r}\chi_{s}d\tau &=
  \delta_{ij}
\end{align}
Sometimes it's more convenient to write it into the matrix form:
\begin{align}\label{PULAYeq:19}
  \sum_{i}\sum_{j}\sum_{r}\sum_{s}c^{*}_{ri}c_{sj}\int\chi^{*}_{r}\chi_{s}d\tau
  &= \sum_{i}\sum_{j}\delta_{ij} = n \Rightarrow \nonumber \\
  \sum_{i}\sum_{r}\sum_{s}c^{*}_{ri}c_{si}\int\chi^{*}_{r}\chi_{s}d\tau
  &= n \Rightarrow \nonumber \\
  Tr(C^{+}SC) &= Tr(I_{n})
\end{align}
Where $I_{n}$ is the unit matrix, $S_{pq} =
\langle\chi_{p}|\chi_{q}\rangle$. The $C$ represents the vectors of
the molecular orbitals:
\begin{equation}\label{}
  C = \begin{bmatrix}
    c_{11} & c_{12} & \cdots & c_{1n} \\
    c_{21} & c_{22} & \cdots & c_{2n} \\
    \cdots &\cdots  & \cdots & \cdots \\
    c_{n1} & c_{n2} & \cdots & c_{nn} \\
  \end{bmatrix}
\end{equation}
Here each column denotes one composition of molecular orbital, and the
row characterizes the weight of the specific $\chi_{i}$ in all the
molecular orbitals. $C^{+}$ is the unitary transformation of the $C$:
$C^{+}_{ij} = C_{ji}^{*}$. However, usually in the quantum chemistry
we use the real orbitals and the coefficients, thus we have that
$C^{+}_{ij} = C_{ji}$. Here below we follow such convention.

Now let's consider the expectation value for the $\Phi$:
\begin{equation}\label{PULAYeq:24}
  E = \bra{\Phi}\hat{H}\ket{\Phi}
\end{equation}
Here the $E$ has the same meaning with it's general form of $E(C,R)$
defined in (\ref{PULAYeq:8}). Furthermore, based on the constraint
conditions the variation process can be expressed as:
\begin{equation}\label{PULAYeq:10}
  \begin{split}
    \frac{\partial}{\partial A_{K}} \Big\{
    E -  \lambda(\sum_{K}A_{K}^{2} - 1)\Big\}&=  0  \\
    \frac{\partial}{\partial c_{ri}} \Big\{ E - Tr[\epsilon(C^{+}SC-
    I_{n})]\Big\}&=  0  \\
  \end{split}
\end{equation}
Hence we can express the Lagrangian functional defined in
(\ref{PULAYeq:8}) as:
\begin{equation}\label{PULAYeq:9}
  W = E - \lambda(\sum_{K}A_{K}^{2} - 1) - Tr[\epsilon(C^{+}SC -
  I_{n})]
\end{equation}

From the (\ref{PULAYeq:10}), we can obtains some relations concerned
with the gradients expression. They are useful in the following
contents. For the differentiation with respect to the $A_{X}$, we
have:
\begin{equation}\label{PULAYeq:11}
  \begin{split}
    \frac{\partial E}{\partial A_{X}} &=
    \lambda\frac{\partial (\sum_{K}A_{K}^{2} - 1)}{\partial A_{X}} \\
    &=2\lambda A_{X}
  \end{split}
\end{equation}

The derivation for the differentiation with respect to the $c_{xy}$ is
something more complicated, so below I try to give the redundant
details in the calculation. Hope that we can make it as self-clear as
it can.
\begin{align}\label{PULAYeq:12}
  \frac{\partial E}{\partial c_{xy}} &= \frac{\partial
    Tr[\epsilon(C^{+}SC - I_{n})]}{\partial c_{xy}} \nonumber \\
  &=\frac{\partial}{\partial c_{xy}}\left\{ \sum_{i}\sum_{r}\sum_{s}
    \epsilon_{ii}c_{ri}c_{si}S_{rs} -
    \sum_{i}\epsilon_{ii} \right\}\nonumber \\
  &=\frac{\partial}{\partial c_{xy}} \left\{\cdots + \sum_{s}
    \epsilon_{yy}c_{xy}c_{sy}S_{xs} + \cdots + \right.\nonumber \\
  &\left.\sum_{r} \epsilon_{yy}c_{ry}c_{xy}S_{rx} + \cdots -
    \sum_{i}\epsilon_{ii}\right\} \nonumber \\
  &=\sum_{s} \epsilon_{yy}c_{sy}S_{xs} + \sum_{r}
  \epsilon_{yy}c_{ry}S_{rx} \nonumber \\
  &=2\sum_{r} \epsilon_{yy}c_{ry}S_{xr} \nonumber \\
  &=2(SC\epsilon)_{xy}
\end{align}
In the derivation above the $S_{rs} =
\langle\chi_{r}|\chi_{s}\rangle$, and it's hermitian matrix so that
$S_{rs} = S_{sr}$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Dependent variables related to nuclear coordinates}
%
% how to understand the dependence between the other variables and the
% nuclear coordinates, the most important is the basis functions
% discussion
%
After setting up the structure of the wave functions, the next
question is: as the nuclear coordinate changes, in the energy
functional what kind of arguments have to make the corresponding
change?

Obviously, as the nuclear coordinate changes; the coefficients for the
determinants and the orbitals will all have to change coordinately:
\begin{equation}\label{}
  \delta R \Rightarrow \left\{
    \begin{array}{ll}
      \delta A_{K}   &   \\
      \delta c_{ri}  &
    \end{array}
  \right.
\end{equation}

On the other hand, we note that there's implicit dependence between
the basis functions and the nuclear coordinates. Because that the
Gaussian type basis functions or the Slater type of basis functions
used almost exclusively in quantum chemistry are all atomic type
functions, that is to say; they are all centered around the nucleus,
and decays in exponent way away from the nucleus; So it's reasonable
to rationalize that there's dependence between basis functions and the
nuclear coordinates. However, how can we construct the mathematical
dependent relationship between them?

Historically there had been a lot of arguments over this
issue\cite{meyer:2109, bishop:3515}. As Pulay had
suggested\cite{Pulay5}, that the basis functions are defined by their
general functional form which regraded as fixed, and by a set of
nonlinear parameters $p_{t}$, the most important orbital centers of
$\chi_{r}$ and the orbital exponents of $\varepsilon_{r}$. It's
assumed that basis functions depend explicitly on the nuclear
coordinates of $R_{a}$ through the parameter of $p_{t}$. The further
relationship will be further discussed in the following content.

Therefore, we can write that:
\begin{equation}\label{PULAYeq:12}
  E = E(R_{a}, A_{K}, c_{ri}, p_{t})
\end{equation}

In the next passage, we will further investigate the dependence by the
(\ref{PULAYeq:9}).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{First derivative of the SCF energy: general expression}
%
% 1 consider the general derivatives with respect to the 4 variables
% 1.1 the R_{a}: only in Hamiltonian, and nuclear-electron term 1.2
% deal with A_{k} 1.3 density force 1.4 integral force
%
%
As for the first derivative of the MCSCF wave functions, let's further
investigate the (\ref{PULAYeq:12}). We will discuss the
differentiation with respect to the $Ra$, $A_{K}$, $c_{ri}$ and
$p_{t}$; separately:
\begin{equation}\label{}
  E(R_{a}, A_{K}, c_{ri}, p_{t}) = \bra{\Phi}\hat{H}\ket{\Phi}
\end{equation}

For the $R_{a}$, it's only explicitly contained in the Hamiltonian,
thus the differentiation in terms of the $R_{a}$ only appear in the
operator of $\hat{H}$. Since that in the Hamiltonian only the
nuclear-electron term is related to the nuclear coordinates, therefore
the differentiation can be simply expressed as:
\begin{align}\label{}
  \frac{\partial \hat{H}}{\partial R_{a}} = \frac{\partial}{\partial
    R_{a}}\left[-\sum_{\alpha}\sum_{i}\frac{Z_{\alpha}}{r_{i\alpha}}\right]
  &=-\sum_{i}\frac{\partial}{\partial
    R_{a}}\left[\frac{Z_{a}}{r_{ia}}\right] \nonumber \\
  &=\sum_{i}\frac{Z_{a}}{(r_{ia})^{2}} \nonumber \\
  &=-Z_{a}\sum_{i}\frac{R_{i} - R_{a}}{(r_{ia})^{3}}
\end{align}
Here $r_{i\alpha}$ is defined as the distance between the electron $i$
and the nuclear $\alpha$: $r_{i\alpha} = R_{\alpha} - R_{i}$.
Moreover, we can define the Hellmann-Feynman force as:
\begin{equation}\label{}
  -f^{HF}_{a} = \left\langle\Phi|\frac{\partial \hat{H}}{\partial
      R_{a}}|\Phi\right\rangle
\end{equation}
We do so is because this expression is similar to the Hellmann-Feynman
theorem discussed in the quantum mechanics part.

For the differentiation related to the CI coefficients of $A_{K}$,
according to the (\ref{PULAYeq:11}); we have:
\begin{align}\label{}
  \sum_{K}\frac{\partial E}{\partial A_{K}}\frac{\partial
    A_{K}}{\partial R_{a}} &=2\lambda\sum_{K}A_{K}\frac{\partial
    A_{K}}{\partial R_{a}} \nonumber \\
  &=\lambda\frac{\partial}{\partial R_{a}}\sum_{K}
  \left(A_{K}^{2}\right)\nonumber \\
  &= 0
\end{align}
The result turns out that the variational parameters of $A_{K}$ does
not enter into the gradients expression, just coincide with the
conclusion we got from the (\ref{PULAYeq:7}).

For the term of differentiation with respect to the coefficients of
$c_{xy}$, according to the (\ref{PULAYeq:12}) we can have:
\begin{equation}\label{PULAYeq:21}
  \sum_{x}\sum_{y}\frac{\partial E}{\partial c_{xy}}\frac{\partial
    c_{xy}}{\partial R_{a}} =
  2\sum_{x}\sum_{y}\sum_{r}S_{xr}c_{ry}\epsilon_{yy}\frac{\partial
    c_{xy}}{\partial R_{a}}
\end{equation}

However, such expression is not easy to evaluate. Thus we wish to
transform it into the matrix expression. Before it, we are going to
investigate some similar process.

In the expression of (\ref{PULAYeq:19}), we have derived some relation
between the matrix expression and the sum of matrix elements:
\begin{align}\label{}
  Tr(C^{+}SC) &=
  Tr(I_{n}) \Rightarrow \nonumber \\
  \sum_{i}\sum_{r}\sum_{s}c_{ri}c_{si}S_{rs} &= n
\end{align}
Again, we note that $C^{+}_{ir} = C_{ri}$, and $S_{rs} = \int
\chi_{r}\chi_{s}d\tau$(all the coefficients and the basis functions
are assumed to be real).

We can see that if we multiply the $\epsilon_{ii}$ to the left side of
the above equation (here we have to remember that $\epsilon$ is some
diagonal matrix, with its diagonal element denotes the orbital
energy), we can get that:
\begin{align}\label{PULAYeq:20}
  \sum_{i}\sum_{r}\sum_{s}\epsilon_{ii}c_{ri}c_{si}S_{rs}
  &= \sum_{i}\epsilon_{ii} \nonumber \\
  \sum_{i}\sum_{r}\sum_{s}\epsilon_{ii}c_{ri}S_{rs}c_{si}
  &= \sum_{i}\epsilon_{ii} \Rightarrow \nonumber \\
  Tr(\epsilon C^{+}SC) &= Tr(\epsilon I_{n})
\end{align}

Analog to the above case, we can set up such one-to-one correspondence
between the elements in the (\ref{PULAYeq:20}) and elements in the
(\ref{PULAYeq:21}):
\begin{equation}\label{}
  \begin{split}
    \epsilon_{ii} &\Leftrightarrow S_{xr}  \\
    c_{ri}        &\Leftrightarrow c_{ry}  \\
    S_{rs}        &\Leftrightarrow \epsilon_{yy}  \\
    c_{si} &\Leftrightarrow \frac{\partial c_{xy}}{\partial R_{a}}
  \end{split}
\end{equation}
Therefore, we can write the (\ref{PULAYeq:21}) as:
\begin{equation}\label{}
  \sum_{x}\sum_{y}\frac{\partial E}{\partial c_{xy}}\frac{\partial
    c_{xy}}{\partial R_{a}} = 2Tr[SC\epsilon C^{a+}]
\end{equation}
Where the $C^{a+} = \frac{\partial C^{+}}{\partial R_{a}}$.

Now by the matrix expression, we can prove that the differentiation
related to the coefficients of $C$ can be transformed to the
differentiation related to the matrix density of $S$. For the
constraint condition related to the $C$, which is defined as:
\begin{equation}\label{}
  C^{+}SC = I_{n}
\end{equation}
By differentiating the above equation with respect to the $R_{a}$, we
have:
\begin{equation}\label{PULAYeq:23}
  C^{a+}SC + C^{+}SC^{a} = -C^{+}S^{a}C
\end{equation}
Multiply the matrix of $\epsilon$ and take the trace of the above
equation we obtain:
\begin{multline}\label{}
  2Tr[\epsilon C^{a+}SC] = 2Tr[C^{a+}SC\epsilon] = 2Tr[SC\epsilon
  C^{a+}] =\\
  -Tr[\epsilon C^{+}S^{a}C] = -Tr[C\epsilon C^{+}S^{a}]
\end{multline}
Here we have used the identities that $Tr[AB] = Tr[BA]$, and $Tr[C] =
Tr[C^{+}]$ in the above transformations. Therefore finally we have:
\begin{equation}\label{PULAYeq:22}
  \sum_{x}\sum_{y}\frac{\partial E}{\partial c_{xy}}\frac{\partial
    c_{xy}}{\partial R_{a}} = -Tr[C\epsilon C^{+}S^{a}]
\end{equation}

(\ref{PULAYeq:22}) shows that we do not need to calculate the
gradients of the coefficients of $C$ in terms of $R$, instead the
$S^{a}$ and $C\epsilon C^{+}$ are sufficient. According to
Pulay\cite{Pulay5}, this step is called the ``key step in deriving the
analytical form of the gradient''. Because of its connection with the
change in the density matrix as the nuclear coordinates change, so
this part is also called ``density force''.

Finally, it's very interesting to compare the (\ref{PULAYeq:22}) with
the (\ref{PULAYeq:7}). The (\ref{PULAYeq:7}) indicates that the
variational parameters do not enter into the gradient expression,
however; the results shows in (\ref{PULAYeq:22}) does not coincide
with such conclusion. In my opinion, this can be attributed from the
implicit dependence between the basis functions and the nuclear
coordinates. As indicated in the (\ref{PULAYeq:23}), the derivatives
on the $C$ with respect to the $R_{a}$ can be converted in to the
derivatives on the density; thus if the basis functions are irrelevant
to the change of nuclear coordinates; then the term on the right side
of (\ref{PULAYeq:23}) will be zero, and the the derivatives on the $C$
with respect to the $R_{a}$ will accordingly be zero, too.

Therefore, we can write the $S^{a}$ in the density force as:
\begin{equation}\label{}
  S^{a} = \sum_{t}\frac{\partial S}{\partial p_{t}}\frac{\partial
    p_{t}}{\partial R_{a}}
\end{equation}

Similarly, since that in the expression of $E$ there's integrals on
the basis functions, hence we can define the integral force in terms
of the differentiation on basis sets integral with respect to the
$R_{a}$:
\begin{equation}\label{}
  \sum_{t}\frac{\partial \bra{\Phi}\hat{H}\ket{\Phi}}{\partial p_{t}}
  \frac{\partial p_{t}}{\partial R_{a}}
\end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{First derivative of the SCF energy: final expression}
%
% 1 general expression 2 the concrete expansion for the E 3 apply the
% general gradient expression to the E 4 Hatree-Fock case, close shell
%
So far we can derive the gradient of MCSCF energy, it's simply the
addition of the four terms discussed in the above section:
\begin{align}\label{PULAYeq:26}
  E_{a} &= \frac{\partial E}{\partial R_{a}} + \sum_{K}\frac{\partial
    E}{\partial A_{K}}\frac{\partial A_{K}}{\partial R_{a}} +
  \sum_{x}\sum_{y}\frac{\partial E}{\partial c_{xy}}\frac{\partial
    c_{xy}}{\partial R_{a}} +\sum_{t}\frac{\partial E}{\partial p_{t}}
  \frac{\partial p_{t}}{\partial R_{a}} \nonumber
  \\
  &=\left\langle\Phi|\hat{H}^{a}|\Phi\right\rangle -Tr[C\epsilon
  C^{+}S^{a}] + \sum_{t}\frac{\partial
    \bra{\Phi}\hat{H}\ket{\Phi}}{\partial p_{t}} \frac{\partial
    p_{t}}{\partial R_{a}}
\end{align}

Now let's expand the total energy of $E$ into practical expression.
Firstly by spreading the coefficients $A_{K}$ of the determinants, the
total energy in the (\ref{PULAYeq:24}) can be:
\begin{equation}\label{}
  E = \sum_{K}\sum_{L}A_{K}A_{L}H_{KL}
\end{equation}
And the $H_{KL}$ is:
\begin{equation}\label{}
  H_{KL} =\bra{\Psi_{K}}\hat{H}\ket{\Psi_{L}}
\end{equation}

On the other hand, if we further expand the $H_{KL}$ with the
molecular orbitals, it can be expressed as:
\begin{equation}\label{}
  H_{KL} = \sum_{ij}q^{ij}_{KL}h_{ij} +
  \frac{1}{2}\sum_{ijkl}Q^{ijkl}_{KL}(ij|kl)
\end{equation}
With
\begin{align}\label{}
  h_{ij} &= \int \psi_{i}\hat{h}\psi_{j}d\tau \nonumber \\
  (ij|kl) &=\int \psi_{i}(1)\psi_{j}(1)\frac{1}{r_{12}}
  \psi_{k}(2)\psi_{l}(2)d\tau_{1}d\tau_{2}
\end{align}
This is some general form between two arbitrary slater determinants.
According to the Slater rules, for a close shell case if the
determinants of $K$ and $L$ are identical; then we have $q^{ij}_{KL} =
\delta_{ij}$, $Q^{ijkl}_{KL} = 4\delta_{ij}\delta_{kl} -
2\delta_{ik}\delta_{jl}$. Other cases can be derived in the similar
way.

It's helpful to introduce the ``density matrix'' based on the CI
coefficients:
\begin{align}\label{}
  \gamma_{ij} &= \sum_{KL}q^{ij}_{KL}A_{K}A_{L} \nonumber \\
  \Gamma_{ijkl} &=\sum_{KL}Q^{ijkl}_{KL}A_{K}A_{L}
\end{align}
With such notion, the total energy can be expressed as:
\begin{equation}\label{}
  E = \sum_{ij}\gamma_{ij}h_{ij} +
  \frac{1}{2}\sum_{ijkl}\Gamma_{ijkl}(ij|kl)
\end{equation}

Finally, the molecular orbitals should be expanded over the basis sets
functions. By inserting the (\ref{PULAYeq:25}) into the above
equation, we have:
\begin{equation}\label{PULAYeq:27}
  E = \sum_{pq}d_{pq}h_{pq} + \frac{1}{2}\sum_{pqrs}D_{pqrs}(pq|rs)
\end{equation}
In which the density matrices are given as:
\begin{align}\label{}
  d_{pq} &=\sum_{ij}c_{pi}c_{qj}\gamma_{ij} \nonumber \\
  D_{pqrs} &=\sum_{ijkl}c_{pi}c_{qj}c_{rk}c_{sl}\Gamma_{ijkl}
\end{align}

Now we can apply the result in the (\ref{PULAYeq:26}) to the final
energy expression of (\ref{PULAYeq:27}):
\begin{equation}\label{PULAYeq:28}
  E_{a} = \sum_{pq}d_{pq}h^{a}_{pq} +
  \frac{1}{2}\sum_{pqrs}D_{pqrs}(pq|rs)^{a} -Tr[C\epsilon C^{+}S^{a}]
\end{equation}
With
\begin{align}\label{}
  h^{a}_{pq} &= \bra{\chi_{p}}\hat{h}^{a}\ket{\chi_{q}} + \sum_{t}
  \bra{\frac{\partial \chi_{p}}{\partial
      p_{t}}}\hat{h}\ket{\chi_{q}}\frac{\partial p_{t}}{\partial
    R_{a}} + \cdots
  \nonumber \\
  (pq|rs)^{a} &=\sum_{t} \left\langle\frac{\partial
      \chi_{p}(1)}{\partial
      p_{t}}\chi_{q}(1)\left|\frac{1}{r_{12}}\right|
    \chi_{r}(2)\chi_{s}(2)\right\rangle\frac{\partial p_{t}}{\partial
    R_{a}} + \cdots
\end{align}
Here we note that we have omitted some terms, in which the
differentiation is on the $\chi_{q}$, $\chi_{r}$ etc.

For the close shell Hatree-Fock calculation, its total energy can be
expressed as:
\begin{equation}\label{}
  E = \sum_{pq}2D_{pq}h_{pq} + \sum_{pqrs}D_{pq}D_{rs}\left\{2(pq|rs)
    -(pr|qs)\right\}
\end{equation}
Where the $D_{pq}$ is the density matrix:
\begin{equation}\label{}
  D_{pq} = \sum_{i}c_{pi}c_{qi}
\end{equation}

Therefore, the gradients of the close Hatree-Fock energy can be:
\begin{multline}\label{}
  E_{a} =\sum_{pq}2D_{pq}
  \left\{\bra{\chi_{q}}\hat{h}^{a}\ket{\chi_{q}} +
    \left\langle\frac{\partial \chi_{p}}{\partial
        p_{t}}\left|\hat{h}\right|\chi_{q}\right\rangle\frac{\partial
      p_{t}}{\partial R_{a}} +
    \left\langle\chi_{p}\left|\hat{h}\right|\frac{\partial
        \chi_{q}}{\partial p_{t}}\right\rangle\frac{\partial
      p_{t}}{\partial
      R_{a}}\right\} \\
  +\sum_{pqrs}D_{pq}D_{rs}\left\{2(p^{a}q|rs) -(p^{a}r|qs) +
    2(pq^{a}|rs) -(pr^{a}|qs) \right. \\
  \left.+ 2(pq|r^{a}s) -(pr|q^{a}s) +
    2(pq|rs^{a})-(pr|qs^{a})\right\} \\
  -Tr[C\epsilon C^{+}S^{a}]
\end{multline}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Dependence between the basis sets and the integral force}
%
% this section is to illustrate that how to calculate the integral
% force 1 two ways to tackle this problem 2 the deficiency for the
% second method 3 how to use the first method
%
There are some different ways to define the dependence of the
non-linear parameter of $p_{t}$ over the nuclear
coordinates\cite{Pulay5, meyer:2109}:
\begin{itemize}
\item Define an arbitrary but physically reasonable and simple
  functional dependence of $p_{t}$ on the nuclear coordinates and
  evaluate the integral force with this definition of $\frac{\partial
    p_{t}}{\partial R_{a}}$.
\item Optimize the parameter of $p_{t}$ so that to make the energy as
  a minimum. Since we have to keep the orthogonality between the
  orbitals, the functional of $W = E - Tr[\epsilon(C^{+}SC- I_{n})]$
  is selected to make $\frac{\partial W}{\partial p_{t}} = 0$; then we
  can have:
  \begin{align}\label{}
    \frac{\partial E}{\partial p_{t}} &=
    Tr\left[\epsilon\left(C^{+}\frac{\partial S}{\partial
          p_{t}}C\right)\right] =Tr\left[C\epsilon C^{+}\frac{\partial
        S}{\partial p_{t}}\right] \Rightarrow \nonumber \\
    \sum_{t}\frac{\partial E}{\partial p_{t}}\frac{\partial
      p_{t}}{\partial R_{a}} &=\sum_{t}Tr\left[C\epsilon
      C^{+}\frac{\partial S}{\partial p_{t}}\right]\frac{\partial
      p_{t}}{\partial R_{a}}
  \end{align}
  Therefore, the integral force has been transformed into the density
  force. From the general force expression in (\ref{PULAYeq:26}), we
  can see that the density force and the integral force have
  compensated with each other (they have different sign), thus in
  (\ref{PULAYeq:26}) only the Hellmann-Feynman force left behind.
\end{itemize}

The second method is mathematically clear, and able to derive a very
simple expression for evaluating the first derivative for the given
system. However, the second method requires that the basis sets should
be highly flexible so that it's parameters can be varied in the SCF
optimization process. Such basis sets are called ``floating
functions''\cite{Pulay5}. Unfortunately, it turns out that such method
will cause too much computational efforts, which is not proportional
to the benefits it has brought in. Therefore, even this method was
frequently used at the early stage, now it's seldom used anymore.

On the other hand, the first method to evaluate the integral force has
been proved to be some good method which is as efficient as the second
one, but only cause the comparable computation efforts.

This method contains two points:
\begin{itemize}
\item the exponents of the basis sets are fixed to constant.
\item the position vectors in the basis sets are linear combination of
  the nuclear coordinates:
  \begin{equation}\label{PULAYeq:29}
    \chi_{r} = \sum_{a}\mu_{ra}R_{a}
  \end{equation}
\end{itemize}
Since that the basis sets are usually placed on the atom center or the
bonding line between the nucleus, thus as the $R_{a}$ varies there
will be at most two non-vanishing terms in the (\ref{PULAYeq:29}). For
example, if the basis sets are placed on the atom center (all the GTO
and STO belong to this type); then the integral force can be evaluated
as:
\begin{equation}\label{}
  \sum_{t}\frac{\partial E}{\partial p_{t}}\frac{\partial
    p_{t}}{\partial R_{a}} =\sum_{t}\frac{\partial E}{\partial
    p_{t}}\mu_{ra}
\end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../../main"
%%% End:


%------------------------------------------------------------------------------
\section{Satellite geometry model}
\label{sec:propagation-satellite-model}
%------------------------------------------------------------------------------

For the maintenance of an object catalogue in a space surveillance context, information about the shape of individual objects is, in general, limited or
even unavailable. However, for an accurate modelling of non-gravitational forces, detailed knowledge of the surface properties is inevitable. This problem
is typically dealt with by modelling the object as a point mass (or sphere of uniform density) and applying estimated values for the associated quantities in the
non-gravitational model equations, like the drag parameter or the \gls{acr:srp} coefficient.

That design approach was also selected for \neptune, being a 3-\gls{acr:dof} propagator to be used in a space surveillance and tracking context.
In contrast, a 6-\gls{acr:dof} propagation would not only require additional torque modelling, but also a detailed 3D modelling of the surfaces of the object under
consideration, which is the preferred solution for individual satellites, when high precision ephemerides (\acrshort{acr:poe}) with uncertainties in the cm-regime are to be
obtained.

The validation process of \neptune (\cha{cha:validation}) is based on comparing computed ephemerides to available \gls{acr:poe} for distinct satellites and epochs. While this
approach already showed quite good results, a further improvement to augment the 3-\gls{acr:dof} propagation is to apply simple \textit{box-wing-models} for some of those
satellites. It is thus possible to define individual surfaces for the \neptune propagation, with the following properties:
\begin{itemize}
 \item Surface area / \si{\metre\squared},
 \item specular and diffuse reflectivity coefficients as well as
 \item surface normal orientation.
\end{itemize}

The orientation of the surface normal can be described by two angles for the initial state. For satellites, that are not in a randomly tumbling mode, one can
also provide a model for the orientation during the propagation. Three different modes have been defined for \neptune with their associated angles to give
the orientation, as shown in \tab{tab:sat-model-orientation}.
\begin{table}[h!]
 \centering
 \caption{Orientation modes and the associated defining angles for \neptune box-wing model propagation.\label{tab:sat-model-orientation}}
 \begin{tabular}{p{3cm}p{6cm}p{6cm}}
  \toprule
  Orientation mode & First angle & Second angle \\
  \midrule
  Earth-oriented   & Azimuth in satellite-centered horizontal plane (\gls{acr:ocrf}) & Elevation in satellite-centered horizontal frame (\gls{acr:ocrf}). \\
  \midrule
  Sun-oriented     & Offset to the right ascension of the Sun in the equatorial plane (\gls{acr:gcrf}) & Offset to the declination of the Sun perpendicular to the equatorial plane
\gls{acr:gcrf}. \\
  \midrule
  Inertially fixed & Right ascension (\gls{acr:gcrf}) & Declination (\gls{acr:gcrf}) \\
  \bottomrule
 \end{tabular}
\end{table}
Each time, the cross-section of the satellite is requested by the force model, \neptune will evaluate the current orientation based on the orientation mode
and compute the value for that step. This might be, for example, the cross-section in relative velocity direction for the evaluation of the drag acceleration.
In that case, the inner product of the relative velocity vector and the surface normal vector is evaluated and summed for all surfaces where that product
is greater than zero:
\begin{equation}
 \gls{sym:area}_{\gls{idx:cross}}\left(\gls{sym:t}\right) = \sum_{i=0}^{n_{\gls{idx:srf}}} \gls{sym:area}_{i} \gls{sym:n0}\left(\gls{sym:t}\right)
\gls{sym:velvec}_{\gls{idx:rel}}\left(\gls{sym:t}\right), \quad \forall \gls{sym:n0}\left(\gls{sym:t}\right)
\gls{sym:velvec}_{\gls{idx:rel}}\left(\gls{sym:t}\right) > 0. \label{eq:satellite-model-normal}
\end{equation}

Note that this simple approach does not account for shadowing effects of individual surfaces. Also, due to the approach defined by \eq{eq:satellite-model-normal}, each defined
surface is only accounted for its positive normal direction. For instance, if modelling a single flat plate, it is important to account for both, the front and the rear side, as
shown exemplarily for a solar array in \gls{acr:leo} in \fig{fig:sat-model-solar-array}.
\begin{figure}[h!]
 \centering
 \input{07-Tikz/satModelSolarArray}
 \caption{Example for a Sun-oriented solar array with dimensions \SI{1}{\metre}$\times$\SI{1}{\metre} in a circular \gls{acr:leo}. The
cross-section in relative velocity direction is shown for both, a single defined surface, as well as a combined front and rear surface.\label{fig:sat-model-solar-array}}
\end{figure}
As expected, for a single surface, the cross-section is zero for half an orbit, as the angle between the surface normal direction and the relative velocity vector is greater than
\ang{90;;}. However, as a real flat plate would also experience drag on the rear side, the correct result is only obtained for modelling two surfaces with normal
directions being
\ang{180;;} apart.

In \fig{fig:sat-model-box-wing} an example is shown for the difference between a box-wing and a \textit{cannon-ball} model, where the latter corresponds to a sphere with a
cross-section that provides a best fit to the results of the box-winged satellite.
\begin{figure}[h!]
 \centering
 \input{07-Tikz/satModelBoxVsNoBox}
 \caption{Example for the difference between a box-wing and a cannon-ball model. An Earth-oriented cube (10 \si{\metre\squared} surface, each) with one Sun-oriented solar array
(10 \si{\metre\square} area) in a circular \gls{acr:leo}. The radial, along-track and cross-track components are shown.\label{fig:sat-model-box-wing}}
\end{figure}
It can be seen, that radial and along-track periodic variations are introduced, which are in the range of a few metres. A box-wing model can thus be used for improved comparisons
in the validation process of \neptune (\cha{cha:validation})\todo[Validation]{Use box-wing model for validation of NEPTUNE with POE.}.

In the example shown in \fig{fig:sat-model-box-wing}, two different orientations for the surfaces of the box-wing model were combined: an Earth-oriented cube and a Sun-oriented
solar array. In the current implementation, \neptune allows for an easy computation of a \textit{minimum solar incidence angle}, which is the minimum angle between the surface normal and the Sun
direction for a given orbit. For example, a geostationary orbit would experience a variation of the minimum incidence angle between \ang{0;;} and \ang{23.5;;} over the course of a
year due to its orientation with respect to the ecliptic.


%!TEX root = /Users/stevenmartell/Documents/CURRENT PROJECTS/iSCAM-trunk/fba/BC-herring-2011/WRITEUP/BCHerring2011.tex

\section{Discussion}

%Points to make
% Highlight the major changes in this years model incomparison to the previous HCAM Model and discuss the subtle differences.

% Discuss the integrated approach to estimating the stock-recruitment model parameters and moving towards the SSF. SPecific issues regarding the definition of MSY based referece points when there are multiple gears with different selectivities.  Determining MSY implies there is an allocation framework for each of these gears.

The simulation studies showed a minor upward bias in the estimates of \fmsy, MSY and a slight bias in steepness.  Unfortunately, the true parameter values used in the simulation study did not provide significant contrast in the data to generate information over a wide range of spawning depletion.  In general, such widely contrasting data are required to resolve parameter confounding \citep{hilborn1992quantitative}.  The simulated fishing mortality rates were extremely low (i.e., less than 0.3 between 1951 and 1969, and less than 0.1 post 1970.) and the stock was never depressed to a level where, on average, recruitment would be limited by spawner abundance.  Future simulation studies should impose a more severe mortality schedule to see if this resolves the slight parameter bias.

There are a few  significant differences between  \iscam\  and the previous assessment using HCAM, despite efforts to parametrize \iscam\ as close as possible to HCAM. These differences include: different likelihood function for the age-composition data, using the conditional maximum likelihood estimate of $q$, estimation of variance, and jointly estimating parameters for the stock recruitment relationship.  Here we briefly discuss how these structural differences influence model results.

In our attempts to parametrize the \iscam\ model to reproduce the results of last years HCAM assessment, we fixed the variance and variance partitioning parameters such that the same weights were placed on the spawn observation errors and variation in annual recruitment. The age-composition data, however, were not given the same weight as the multinomial samples sizes that were used in the HCAM model. In this case, the \iscam\ model assumes a homogenous variance in the age-composition data and the weight assigned to each observation is based on the conditional maximum likelihood estimate of the variance (i.e., this is akin to using concentrated likelihoods for the age-composition data).  The main affect of this difference in likelihood formulations is that in the \iscam\ model each year is given the same weight regardless of sample size (i.e., small and large sample sizes are given too much or too little weight, respectively, in comparison to the multinomial likelihood used in HCAM).  That being said, there is also much debate about what the effective sample size should be when using the multinomial likelihood due to correlation structure in the samples \citep[e.g.,][]{francis2011data}.  Another subtle difference between the two approaches is the pooling of samples that are less than 2\% of the age-composition into the adjacent year class.

A second major difference between the two modelling platforms is the how $q$ for the dive survey data is treated.  In the previous HCAM model, the dive survey $q$ was fixed at 1, and was not treated as a latent variable.  As a result the residuals between the observed and predicted survey data did not have a mean of 0 due to contradictions between the spawn survey data and the age-composition data in the SOG assessment. The residuals for the spawn survey data post 1988 were nearly all negative.  In the \iscam\ model, the conditional maximum likelihood estimate of $q$ was used to scale the spawn survey data along with a very informative prior for $q$ was used to force $q=1$ for the post 1988 spawn survey.  In \iscam\ model the sum of the residuals between the observed and predicted spawn survey data did have a mean equal to zero and there is no apparent bias in scaling parameters ($q$'s) associated with contradictions in data sources.

In the comparison between HCAM and  \iscam\ models, the variance parameters in the \iscam\ model were fixed such that the same observation error and process error were used in both models.  The fixed variance and fixed $q$ values could also partially explain the persistent negative residual patterns observed in the HCAM model; these data may be weighted less relative to the age-composition data.  Moreover, fixing these variance parameters  (specifically the ratio of observation to process errors) is also likely to bias estimates of uncertainty in spawning biomass, and other variables.  We also explored the possibility of estimating the total variance and the fraction associated with observation error for the SOG model.  In this case, reasonable estimates of the variance parameters were obtained and this is only possible because there is information on relative abundance and age-composition in this fishery.    We further estimate all the variance parameters in Part II of this document for all major and minor stock areas.
Estimates of uncertainty are likely to be less biased now that the variance parameters are jointly estimated.

Lastly, another less subtle difference between the two modelling approaches was the estimation of the stock recruitment parameters.  In the HCAM model an improper prior was used for the steepness parameter, where steepness was bound between 0.2-0.99 and a lognormal prior was used.  In \iscam, we used a Beta distribution as the prior rescaled for values in the range of 0.2-1.0 for the Beverton-Holt model.   Estimating the stock-recruitment parameters is critical in establishing reference points and moving towards the Sustainable Fisheries Framework (SFF).  If there are no information in the data to reliably estimate steepness, then the form of the prior distribution will influence derived reference points.

The default reference points suggested in the SFF are based on the concept of Maximum Sustainable Yield (e.g., the suggested LRP is 0.4\bmsy, and the USR is 0.8\bmsy).  Such a default requires that we can accurately calculate \bmsy.  In order to calculate \bmsy, precise estimates of population parameters (\bo, $h$), life-history parameters ($M,L_\infty,k,t_o,a,b,\dot{a},\dot{\gamma}$), and  selectivity parameters ($\hat{a},\hat{\gamma}$) are required. See parameters defined in Table \ref{Table2} for a full explanation of how these are related to \bmsy.  Estimating these parameters is one of the major goals of a fisheries stock assessment model, but calculating reference points based on the concept of MSY has a potential problem when there are multiple fleets involved that have very different selectivity curves. That problem relates to allocation of yield to each of the fleets.  If each fleet has the same selectivity curve, then each fleet imposes the same age-specific mortality and there will be no impacts on the MSY estimates.  If however one or more fleets harvest fish at a much younger (or older) age, then estimates of MSY (and the corresponding removal rate reference point) will shift up or down depending on the ratio of maturity to vulnerability.  In general, the later the fish recruit to the fishing gear, the higher the sustainable fishing mortality rate.

Calculating reference points for the SFF is more about determining allocation of herring to the purse seine and gillnet fleets.  The gillnet gear tends to catch older herring in comparison to the winter seine and seine roe fisheries.  Larger allocations to the seine fisheries come at a tradeoff of reducing potential yield for the gillnet fishery.  There is a real optimization problem here that goes just beyond the biology of the species, namely, profitability of each fishery. Furthermore, the calculation of reference points assumes that these data come from a unit-stock and not a collection of mixed sub-stocks that may differ in productivity.


% in RST now, don't edit here

\subsection{PVCorr\_AT}

\subsubsection{Description}

PVCorr\_AT uses a position-velocity slice to correlate distinct repeating
structures in this slice along the velocity (frequency) direction to find
emission or absorbtion lines.

Caveat: if the object of interest has very different types of emission regions,
e.g a nuclear and disk component which do not overlap, the detection may not work
as well.

\subsubsection{Use Case}

For weak lines (NGC253 has nice examples of this) none of the CubeStats or CubeSpectrum give
a reliable way to detect such lines, because they are essentially 1-dimensional cuts through the
cube and become essentially like noise.
When looking at a Position-Velocity slice, weak lines show up quite clearly to the eye,
because they are coherent 2D structures which mimick those of more obvious and stronger lines
in the same PVSlice. The idea is to cross-correlated an area around such strong lines along the
frequency axis and compute a cross-correlation coefficient.

There is also an interesting use case for virtual projects: imagine a PV slice with only
a weak line, but in another related ADMIT object (i.e. a PVslice from another spectrum window) it
is clearly detected. Formally a cross correlation can only be done in velocity space when the
VLSR is known, but within a spectral window the non-linear effects are small. Borrowing a
template from another spw with widely different frequencies should be used with caution.

\subsubsection{Input BDPs:}

\begin{description}

\item[PVSlice] The input PVSlice

\item[PVslice-2] Alternative PVSlice (presumably from another virtual project)

\item[CubeStats] Statistics on the parent cube

\end{description}

\subsubsection{Input keywords}

\begin{description}

\item[cutoff] a conservative cutoff above which an area is defined for the N-th strongest line.
Can also be given in terms of sigma in the parent cube.

\item[order]  Pick the N-th strongest line in this PV slice as the template.
Default:1

\end{description}

\subsubsection{Output BDPs}

\begin{description}

\item[PVCorr\_BDP] Table with cross-correlation coefficients

\end{description}

\subsubsection{Procedure}

After a template line is identified  (usually the strongest line in the PV Slice), a conservative
polygon (not too low a cutoff)
is defined around this, and cross correlated along the frequency axis. Currently this
needs to be a single polygon (really?)

Given the odd shape of the emission in a PVSlice, the correlation coefficient is not
exactly at the correct ``velocity''.  A correction factor needs to be determined
based on identifying the template line with a known line frequency, and VLSR. Since
line identifaction is the next step after this, this catch-22 situation needs to
be resolved, otherwise a small systemic offset can be present.

\subsubsection{CASA tasks used}

none exist yet that can do this. NEMO has a program written in C, and the idea in there will
need to be ported to python.

\clearpage


\documentclass[10pt]{article}

\usepackage{cite}
\usepackage{pgf}
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage{url}
\usepackage{tikz}
\usepackage{common}

\begin{document}

\title{Straight-line Programs: A Practical Test\thanks{The authors acknowledge support
from the Ministry for Education and Science of Russia, grant 2.1.1/13995, and
from the Russian Foundation for Basic Research, grant 10-01-00524.}}
\author{Ivan Burmistrov \and Lesha Khvorost}
\date{}

\maketitle

\begin{abstract}
We present an improvement of Rytter's algorithm that constructs a straight-line program for a given text and show that
the improved algorithm is optimal in the worst case with respect to the number of  AVL-tree rotations. Also we compare
Rytter's and ours  algorithms on various data sets and provide a comparative analysis of compression ratio achieved by
these algorithms, by LZ77 and by LZW.

\noindent \emph{Keywords: straight-line program, LZ-compression, AVL-tree.}
\end{abstract}

\section{Introduction}

Nowadays searching algorithms on huge data sets attract much attention. To reduce the input size one needs algorithms
that can work directly with a compressed representation of input data.

Various compressed representations of strings are known: straight-line programs (SLPs)~\cite{SLPConstruction},
collage-systems \cite{collages}, string representations using antidictionaries \cite{antidictionaries}, etc.  Nowadays
text compression based on context-free grammars such as SLPs has become a popular research direction. The reason for
this is not only that grammars provide well-structured compression but also that the SLP-based compression is, in a
sense, polynomially equivalent to the compression achieved by the Lempel-Ziv algorithm that is widely used in practice.
It means that, given a text $S$, there is a polynomial relation between the size of an SLP that derives $S$ and the size
of the dictionary stored by the Lempel-Ziv algorithm, see \cite{SLPConstruction}. It should also be noted that classical
LZ78 \cite{LZ78} and LZW \cite{LZW} algorithms can be considered as special cases of grammar compression. (At the same
time other compression algorithms from the Lempel-Ziv family---such as LZ77 \cite{LZ77} and run-length compression---do
not fit directly into grammar compression model.)

Using the fact that SLPs are nicely structured, several researchers keep developing analogues of classical string
algorithms that (at least theoretically) perform quite well on SLP-compressed representations: \textbf{Pattern matching}
\cite{PM_and_HD}, \textbf{Longest common substring} \cite{LCSubstring}, \textbf{Computing all palindromes} \cite{LCSubstring}, some
versions of \textbf{Longest common subsequence} \cite{LCS_P}. At the same time, constants hidden in big-O notation for
algorithms on SLPs are often very big. Also the aforementioned polynomial relation between the size of an SLP for a
given text and the size of the LZ77-dictionary for the same text does not yet guarantee that SLPs provide good
compression ratio in practice. Thus, a major questions is whether or not there exist SLP-based compression models suitable
to practical usage? This question splits into two sub-questions addressed in the present paper: How difficult is it to
compress data to an SLP-representation? How large compression ratio do SLPs provide as compared to
classic algorithms used in practice?

Let us describe in more detail the content of the paper and its structure. Section 2 gathers some preliminaries about
SLPs. In Section 3 we present an improved version of Rytter's algorithm~\cite{SLPConstruction} for constructing
an SLP-presentation of a given text. In Section 4 we compare the improved algorithm vs. the original algorithm
from~\cite{SLPConstruction} and also present results of a comparison of compression ratio between the two SLP-based
algorithms, LZ77 and LZW. In Section 5 we summarize our results.

\section{Preliminaries}

We consider strings of characters from a fixed finite alphabet $\Sigma$. The \emph{length} of a string
$S$ is the number of its characters and is denoted by $|S|$. The \emph{concatenation} of strings $S_1$ and $S_2$
is denoted by $S_1 \cdot S_2$. A \emph{position} in a string $S$ is a point between consecutive characters. We number
positions from left to right by $1,2,\dots,|S|-1$. It is convenient to consider also the position 0 preceding the text
and the position $|S|$ following it. For a string $S$ and an integer $0 \leq i < |S|$ we define $S[i]$ as character
between positions $i$ and $i+1$ of $S$. For example $S[0]$ is a first character of $S$. A \emph{substring} of $S$
starting at a position $\ell$ and ending at a position $r$, $0\leq \ell < r \leq |S|$, is denoted by $S[\ell \dots r]$ (in other
words $S[\ell \dots r] = S[\ell] \cdot S[\ell + 1] \cdot \mbox{\dots} \cdot S[r-1]$).

A \emph{straight-line program} (SLP) $\slp{S}$ is a sequence of assignments of the form: $$\slp{S}_1 = expr_1,\
\slp{S}_2 = expr_2, \dots, \slp{S}_n = expr_n,$$ where $\slp{S}_i$ are \emph{rules} and $expr_i$ are expressions of
the form:
\begin{itemize}
\item $expr_i$ is a character of $\Sigma$ (we call such rules \emph{terminal}), or
\item $expr_i = \slp{S}_\ell\cdot \slp{S}_r \ (\ell, r < i)$ (we call such rules \emph{nonterminal}).
\end{itemize}

Thus, an SLP is a context-free grammar in Chomsky normal form. Obviously every SLP generates exactly one string over
$\Sigma^+$. This string is referred to as the \emph{text} generated by an SLP. For a grammar $\slp{S}$ generating a text
$S$, we define \emph{parse-tree} of $S$ as a derivation tree of $S$ in $\slp{S}$. We identify terminal symbols with
their parents in this tree; after this identification every internal node has exactly two sons. We accept the
following conventions in the paper: every SLP is denoted by a capital blackboard bold letter, for example, $\slp{S}$.
Every rule of this SLP (and every internal node in its parse-tree) is denoted by the same letter with indices, for
example, $\slp{S}_1,\slp{S}_2,\dots$. The \emph{size} of an SLP $\slp{S}$ is the number of its rules and is denoted by
$|\slp{S}|$. The \emph{concatenation} of SLPs $\slp{S}_1$ and $\slp{S}_2$ is an SLP that derives
$S_1 \cdot S_2$ and denoted by $\slp{S}_1 \cdot \slp{S}_2$.

The \emph{height} of a node in a binary tree is defined as follows. The height of terminal node (leaf) is equal to 0 by
definition. The height of a nonterminal node is equal to 1 + the maximum of the heights of its children. An
\emph{AVL-tree} $\slp{T}$ is a binary tree such as for every non-terminal node the heights of its children can differ at
most by 1. In the paper we consider only SLPs whose parse-trees are AVL-trees. We denote the height of the rule
$\slp{S}_i$ by $h(\slp{S}_i)$.

\section{Algorithms for constructing SLPs}

\subsection{Rytter's algorithm and its bottleneck}

The problem of constructing a minimal size grammar generating a given text is known to be NP-hard \cite{SmallestCFG}. Hence we
should look for polynomial-time approximation algorithms. One of the key approaches of such algorithms is to construct a
factorization of a given text and to build some binary search tree using the factorization. It is obvious that the size
of the resulting grammar depends on factorization. In \cite{SLPConstruction} Rytter considered factorizations defined by
the LZ77 encoding algorithm.

\begin{definition}
The LZ-factorization of a text $S$ is given by a decomposition: $S = F_1 \cdot F_2 \cdot \mbox{\dots} \cdot F_k$, where
$F_1 = S[0]$ and $F_i$ is the longest prefix of $S\substr{|F_1\cdot \mbox{\dots} \cdot F_{i-1}|}{|S|}$ which occurs as
substring in $F_1 \cdot \mbox{\dots} \cdot F_{i-1}$ or $S[|F_1\cdot \mbox{\dots} \cdot F_{i-1}|]$ in case this prefix is
empty.
\end{definition}

The following theorem gives an estimation of the size of an SLP constructed on the basis on a LZ-factorization.

\begin{thm}[\rm{\cite{SLPConstruction}}]
Given a string $S$ of length $n$ and its LZ-factorization of length $k$, one can construct an SLP for $S$ of size $O(k
\log n)$ in time $O(k \log n)$.
\end{thm}

The proof of the above theorem contains an algorithm for constructing SLPs. We remind here some key ideas of the
algorithm as they are important for the further discussion. For efficient concatenation of grammars the algorithm uses
the following lemma:

\begin{lem}[{\rm\cite{SLPConstruction}}]
Assume $\slp{S}_1, \slp{S}_2$ are two nonterminals of AVL-balanced grammars. Then we can construct in $O(|h(\slp{S}_1) -
h(\slp{S}_2)|)$ time an AVL-balanced grammar $\slp{S} = \slp{S}_1 \cdot \slp{S}_2$ that derives the text $S_1\cdot S_2$
by adding only $O(|h(\slp{S}_1) - h(\slp{S}_2)|)$ nonterminals.
\end{lem}

\noindent \textsc{Problem:} \textbf{SLP Construction}

\noindent \textsc{Input:} a string $S$ and its LZ-factorization $F_1, F_2, \dots, F_k$.

\noindent \textsc{Output:} an SLP $\slp{S}$ that derives $S$.

\noindent \textsc{Algorithm:} The algorithm constructs an SLP by induction on $k$.

\textbf{Base:} Initially $\slp{S}$ is equal to the terminal rule that derives $S[0]$.

\textbf{Step:} Let $i > 1$ be an integer and an SLP $\slp{S}$ that derives $F_1 \cdot F_2 \cdot \mbox{\dots} \cdot F_i$
has already been constructed. Since a LZ-factorization of $S$ is fixed, an occurrence of $F_{i+1}$ in $F_1\cdot F_2
\cdot \mbox{\dots} \cdot F_i$ is known. From this, the algorithm extracts rules $\slp{S}_1, \dots, \slp{S}_\ell$ such
that $F_{i+1} = S_1 \cdot S_2 \cdot \mbox{\dots} \cdot S_\ell$. Since $\slp{S}$ is balanced, we have $\ell = O(\log
|S|)$. Then, using Lemma 3.2, the algorithm concatenates rules in some specific order (see \cite{SLPConstruction} for
details) and sets the next value of $\slp{S}$ to be equal to the result of concatenating the previous value of
$\slp{S}$ with $\slp{S}_1 \cdot \mbox{\dots} \cdot \slp{S}_\ell$.

\begin{center}
	\AVLrotations
\end{center}

It is well-known that adding a new rule to an AVL-tree is quite a complex operation. Every adding operation generates a
sequence of rotations of the tree. There are two types of rotations symbolically presented in Figure 1, see
\cite{SLPConstruction} for more details. Every rotation may generate at most three new rules. Also every rotation may
generate three unused rules. There are two possible directions for an optimization of the algorithm: to construct more
compact grammar and to minimize the number of queries to AVL-trees. Minimizing of the number of queries to AVL-trees
becomes important when the size of input text becomes huge and we cannot store an AVL-tree in the memory. Formally it
means that costs of a query to an AVL-tree are greater than costs of calculations in memory.

The following example illustrates a bottleneck of the algorithm from~\cite{SLPConstruction}:

\noindent \textbf{Example 1:} Let $n$ be an integer and $S$ be a text of length $2^n$. Suppose the algorithm has already
built an SLP $\slp{S}$ that derives $S\substr{0}{2^{n-1}}$. Let $F_1 \cdot F_2 \cdot \mbox{\dots} \cdot F_{n-1}$ be
LZ-factorization of $S\substr{2^{n-1}}{2^n}$ such that $|F_i| = 2^{n-i-1}$, where $i \in \overline{1\dots n-1}$.

Let us estimate the number of rotations that may be generated in the course of the sequence of concatenations
$(((\slp{S} \cdot \slp{F}_1)\cdot \slp{F}_2)\dots) \cdot \slp{F}_{n-1}$ in the worst case. In order to get an
upper bound, we suppose that the resulting tree grows after every concatenation. So we get the following estimation:
\begin{multline*}
\sum_{i=1}^{n-1} (\log{2^{n-1}} + (i-1) - \log{2^{n-i-1}}) = \frac{(n-1)(n-2)}{2}(1 + \log{2}) - (n-2) = \Theta(n^2).
\end{multline*}

Notice that if the algorithm could choose another order of concatenations, then the number of rotations generated by the
algorithm could be essentially smaller, namely, close to $O(n)$. For instance, in the case of concatenating in the
reverse order $\slp{S} \cdot (\slp{F}_1 \dots (\slp{F}_{n-2} \cdot \slp{F}_{n-1}))$, we get the following estimation:
$$\sum_{i=1}^{n-1} (\log{2^{n-i}} - \log{2^{n-i-1}}) = (n-1)\log{2} = \Theta(n).$$

Our next example shows that several factors can be processed together if they occur in a single SLP.

\noindent \textbf{Example 2:} Let $n > 0$ be an integer and $S = b\cdot a^{2^{n-1}}\cdot b \cdot a^{2^{n-2}} \cdot
\mbox{\dots} \cdot b \cdot a$. So the length of $S$ is equal to $2^n + n - 2$. Consider the LZ-factorization of $S$: $$
b \cdot a \cdot a \cdot a^2 \cdot a^4 \cdot \mbox{\dots} \cdot a^{2^{n-2} - 1} \cdot ba^{2^{n-2}} \cdot ba^{2^{n-3}}
\cdot \mbox{\dots} \cdot ba.$$ Let $\slp{S}_1$ be an SLP that derives $b \cdot a^{2^{n-1}}$. It is obvious that all
other factors starting with $b \cdot a^{2^{n-2}}$ occur in $S_1$, therefore the algorithm may process them together. So
the algorithm may construct SLPs $\slp{S}_2$ that derives $b \cdot a^{2^{n-2}}$, $\slp{S}_3$ that derives $b \cdot
a^{2^{n-3}}$, etc. Finally the algorithm may concatenate the SLPs in the following order:
$\slp{S}_1\cdot(\dots(\slp{S}_{n-3}\cdot(\slp{S}_{n-2} \cdot \slp{S}_{n-1})))$.

The main ideas of our improved  algorithm are to process several factors together and to concatenate each group of
factors choosing an optimal order. The intuition behind the algorithm is very simple: if the algorithm has already
constructed a huge SLP, then most factors occur in the text generated by this SLP and may be processed together.

\subsection{An improved algorithm}

\noindent \textsc{Input:} a text $S$ and its LZ-factorization $F_1, F_2, \dots, F_k$.

\noindent \textsc{Output:} an SLP $\slp{S}$ that derives $S$.

\noindent \textsc{Algorithm:} The algorithm constructs an SLP by induction on $k$.

\textbf{Base:} Initially $\slp{S}$ is equal to the terminal rule that derives $S[0]$.

\textbf{Step:} Let $i$ be an integer and $\slp{S}$ be an SLP that derives $F_1\cdot F_2 \cdot \mbox{\dots} \cdot F_i$.
Let $\ell \geq 1$ be a maximal integer such that $F_{i+\ell}$ occurs in $F_1 \cdot \mbox{\dots} \cdot F_i$. Since the
LZ-factorization of $S$ is fixed, the value of $\ell$ can be found by using a linear time search on factors. Let
$\slp{F}_1$ be an SLP that derives $F_{i+1}$, let $\slp{F}_2$ be an SLP that derives $F_{i+2}$, etc.

Initially the algorithm concatenates $\slp{F}_{i+1}, \dots, \slp{F}_{i+k}$ using dynamic programming. Let $\varphi(p,
q)$ be the function that calculates an upper bound of the number of rotations of a grammar tree that are performed
during the process of concatenation of $\slp{F}_p, \slp{F}_{p+1}, \dots, \slp{F}_q$. The algorithm uses the following
recurrent formula to calculate $\varphi(p,q)$:
$$\varphi(p, q) = \begin{cases}
0 &\text{if } p=q, \\
\min_{r = p}^q(\varphi(p, r) + \varphi(r+1, q) +&\\
|\log(|f_{i+p}| + \mbox{\dots} + |f_{i+r}|) - \log(|f_{i+r+1}| + \mbox{\dots} + |f_{i+q}|)|) &\mbox{otherwise}.
\end{cases}$$
The formula is correct since the concatenation of $\slp{F}_p$ and $\slp{F}_q$ generates at most $2\cdot|h(\slp{F}_p) -
h(\slp{F}_q)|$ rotations. In the formula we omit the constant factor 2 since, otherwise, all values of $\varphi$
will be proportional to the factor.

The algorithm calculates the values of $\varphi(p, q)$ using a $\varphi$-table. The $\varphi$-table is a $(k-1) \times
(k-1)$-table that stores information about the value of $\varphi(p,q)$ and about the optimal value of index $r$. The
cell in the $p$-th row and the $q$-th column where $p \leq q$ always contains zero values. Initially the algorithm fills
out cells such that $q - p = 1$, next it fills out cells such that $q - p = 2$, etc. Thus, the algorithm does not
recompute recursively the values of $\varphi(p, r)$ and $\varphi(r+1, q)$ since they already exist in the $\varphi$-table.

Every single value of $\varphi(p, q)$ can be calculated using $O(k)$ time (the pseudo-code of the corresponding
procedure is presented in Figure 2). Thus, the algorithm fills out the $\varphi$-table using $O(k^3)$ time and $O(k^2)$ space.

\begin{figure}[th]
\ComputingFiValue
\end{figure}

Notice that $\varphi(1, k)$ is equal to the optimal number of rotations of the grammar tree in the worst case (i.e.\ in
the case when each concatenation of $\slp{F}_p$ and $\slp{F}_q$ generates $O(|h(\slp{F}_p) - h(\slp{F}_q)|)$ rotations).
Since the $\varphi$-table contains information about the optimal value of index $r$ in every cell, the algorithm can
determine an optimal order of concatenations for $\slp{F}_{i+1}, \dots, \slp{F}_{i+k}$. Using the optimal order, the
algorithm constructs an SLP $\slp{F}$ that derives $F_{i+1}, F_{i+2}, \dots, F_{i+l}$. Finally the algorithm
concatenates $\slp{S}$ and $\slp{F}$ and sets $\slp{S}$ to be equal to $\slp{S} \cdot \slp{F}$.

\begin{thm}
Let $f_1, f_2, \dots, f_k$ be the LZ-factorization of a text $w$. The above algorithm constructs an SLP for $w$ of size
$O(k\log n)$.
\end{thm}
\proof{} The LZ-factorization can be divided into independent groups of factors. Let $\ell$ be the number of the groups
and let $k_1, k_2, \dots, k_\ell$ be the sizes of the corresponding groups. The number of new rules generated during
concatenation of all factors in the $i$-th group is upper bounded by $2\cdot(\log (|f_{k_i}| + |f_{k_i + 1}| +
\mbox{\dots}  + |f_{k_{i+1}-1}|) \cdot (k_{i+1} - k_i))$. So the number of new rules generated during a single step of
the algorithm is upper bounded by $2\cdot(\log(|f_{k_1}| + |f_{k_1 + 1}| + \mbox{\dots} + |f_{k_i -1}|) + (k_{i+1} - k_i
- 1) \cdot (\log (|f_{k_i}| + \mbox{\dots} + |f_{k_{i+1}-1}|))$. Finally the number of rotations is upper bounded by
$2\cdot(k_{i+1} - k_i) \cdot \log n$.

Totally the algorithm generates at most $O(k\log n)$ new rules.

Since concatenation of groups of factors is optimal in the worst case, it is difficult to determine the precise time
complexity of the improved algorithm as a function of input size. Notice that if the size of every group of factors is
equal to 1 then we have the algorithm from \cite{SLPConstruction}. Otherwise the new algorithm generates less rotations
than the standard algorithm but the new algorithm spends some extra time for calculating order of concatenation. In
the next section we propose a practical comparison between the two algorithms.

\section{Practical results}

\subsection{Setup of experiments}
Obviously, the nature of input strings highly affects compression time and compression ratio. In this paper we consider
three types of strings:

\begin{itemize}
  \item DNA sequences from DNA Data Bank of Japan (\url{http://www.ddbj.nig.ac.jp/});
  \item Fibonacci strings;
  \item random strings over four letters alphabet.
\end{itemize}

These types of strings have been chosen for the following reasons. Fibonacci strings are one of the best inputs to the
SLP Construction problem. So we can estimate potential of SLPs as compression model. Random strings are considered
to be incompressible and, potentially, they are the worst input for the SLP Construction problem. DNA sequences are real
data used in practice.

Let us introduce algorithms that have been tested. Our test suite contains a classic version of the Lempel-Ziv algorithm
proposed in \cite{LZ77}. We use the following brief notation for it: \textbf{lz77}. The size of scanning window is equal
to 32Kb. The reader may think that 32Kb is too short but we choose this value to study how the window size influences
compression ratio.

Notice that the size of scanning window affects the length of factors and the total size of a LZ-factorization. So if we
want to compress longer factors, then we need to spend more space. In other words, the size of scanning window directly
affects the size of compressed presentation. In the same time there is no direct relation between the structure of an
SLP and the size of the text derived from it. Therefore using shorter LZ-factorizations leads to constructing more
compact SLPs. From this argument it follows that there is a reason to consider a version of the Lempel-Ziv algorithm
with an infinite scanning window. We use the following brief notation for it: \textbf{lz77inf}.

Additionally we test yet another classic algorithm from the Lempel-Ziv family: the Lempel-Ziv-Welch algorithm (briefly
\textbf{lzw}). Finally our test suite contains the classic algorithm for SLP Construction problem (briefly
\textbf{SLPclassic}) proposed in \cite{SLPConstruction} and the algorithm presented in Section~3 (briefly
\textbf{SLPnew}).

For convenience, we accept the following common notation for the tested algorithms in all following graphs:

\algorithmNotations

We estimate the performance of a compression algorithm in terms of compression ratio and execution time. For SLP
compression algorithms we additionally calculate the number of rotations. We calculate compression ratio as the ratio
between the size of compressed presentation and the size of input string. We measure compression ratio in percents. For
example, the formula for SLP compression ratio looks like $\frac{|\slp{S}|}{|S|} \cdot 100$. Since ratio between
serialized SLP rule representation and serialized LZ-factor representation is greater than 1 (but constant) we may
encounter the following situation: SLP compression ratio is less than LZ compression ratio but the file containing an
SLP is larger than the file containing the corresponding LZ-dictionary. We should note that the situation changes with
input growing.

All algorithms have been implemented using Java SE and tested on Intel Core i-5(661), 4Gb RAM (Microsoft Windows 7 x64
OS).

\subsection{SLP construction results}

In this subsection we discuss performance of both SLP construction algorithms.

As expected, both algorithms work infinitely fast on Fibonacci strings and construct extremely compact representations.
For example, on the 36-th Fibonacci word of size 36.9Mb both algorithms work within 1ms and build SLPs of size 100. This
fact shows that there is a class of strings whereon the SLP compression model is very efficient.

A diagram at Figure 3 shows how the suggested optimization of concatenation affects the number of rotations of AVL trees
on DNA sequences.

To illustrate how the optimization affects  construction time we present two tests. In the first one, the algorithms
have stored all SLPs being constructed in operational memory, while in the second one, the SLPs have been stored in an
external file so that every rotation of an AVL-tree forces I/O operations with the file. We expect that there is no big
difference between the algorithms in the first setting since the new algorithm spends extra time when computing the
most efficient order of concatenation. But what happens when costs of accessing AVL-trees are greater than costs of
computing the order? This situation naturally appears when the size of input is huge and we cannot store all the trees
in operational memory. Figures 4 and 5 present the execution time statistic for both ways of SLPs storing.

\begin{center}
	\DNARotations
\end{center}

\begin{center}
	\DNASpeedTestInMemory
\end{center}

\begin{center}
	\DNASpeedTestInFile
\end{center}

Figures 6, 7 and 8 present the results of testing both algorithms on random strings.

\begin{center}
	\RandomRotations
\end{center}

\begin{center}
	\RandomSpeedTestInMemory
\end{center}

\begin{center}
	\RandomSpeedTestInFile
\end{center}

The Figures 3-8 shows that the new algorithm is more stable since it is on average as fast as the classic algorithm in
operational memory and on average two times faster when a file system is used.

\subsection{Compression ratio results}

Here we present a comparative analysis of compression ratios for DNA sequences and random strings.

Figures 9 and 10 shows that compression ratio provided by the new algorithm is close to compression ratio provided by
the classic algorithm. In case of DNA sequences the new algorithm generates many rotations of small AVL trees and as
a result it constructs a wider SLP than the classic algorithm. Also tests shows that SLP compression ratio directly
depends on the size of LZ-factorization (fluctuations in the results obtained by both classic and new algorithms are
similar to fluctuations in the results obtained by \textbf{lz77inf} and the size of compressed presentation obtained by
\textbf{lz77inf} is equal to the LZ-factorization size).

\begin{center}
	\DNACompression
\end{center}

\begin{center}
	\RandomCompression
\end{center}

\section{Conclusion}

In this paper we present an improved algorithm for SLP construction. The algorithm is similar to Rytter's algorithm
proposed in \cite{SLPConstruction} but it seems to be more efficient on large inputs. However, there is an open
issue related to the new algorithm: how to manage groups of factors optimally? For example, suppose that we already have
built an SLP $\slp{L}$ of height $h$ and suppose that the next group of factors generates an SLP $\slp{R}$ of height
$2h$. It looks inefficient to construct the whole $\slp{R}$ and then concatenate it with $\slp{L}$. A possible solution
is to let the allowed size of the group gradually grow as the algorithm progresses on the input string.

In the paper we also present practical tests of SLPs as compression model. As a result we should conclude that the
existing ways of SLP construction are quite slow. On the other hand, the tests confirm that compression ratio provided by
SLPs is close to compression ratio provided by the family of Lempel-Ziv algorithms (and may be even closer than we
initially expected).

\section*{Acknowledgment}

The authors would like to thank \emph{Mikhail V. Volkov} for his encouragement and critical notes and \emph{Anna
Kozlova} for her help in gathering statistics.

\bibliography{references}
\bibliographystyle{plain}

\end{document}


\subsubsection{\stid{6.02} LLNL ATDM Math Libraries}

\paragraph{Overview}

The LLNL ATDM Mathematical Libraries project performs work in the MFEM library
\cite{MFEM} that is focused on providing high-performance mathematical algorithms
and finite element discretizations to next-gen high-order ECP/ATDM
applications. A main component of these efforts is the development of
ATDM-specific physics enhancements in the finite element algorithms in MFEM and
the MFEM-based BLAST Arbitrary Lagrangian-Eulerian (ALE) code \cite{BLAST}, in
order to provide efficient discretization components for LLNL's ATDM efforts,
including the MARBL application (ECP's LLNLApp).

A second main task in the project is the development of unique unstructured
adaptive mesh refinement (AMR) algorithms in MFEM, that focus on generality,
parallel scalability, and ease of integration in unstructured mesh
applications. The new AMR capabilities can benefit a variety of ECP apps that
use unstructured meshes, as well as many other applications in industry and the
SciDAC program.

Another aspect of the work is the preparation of the MFEM finite element library
and related codes for exascale platforms by using mathematical algorithms and
software implementations that exploit increasing on-node concurrency targeting
multiple complex architectures (e.g. GPUs). This part of the project is
synergistic with and leverages efforts from the ECP CEED co-design center.

MFEM is an open-source finite element library with ~3000 downloads/year from 70+
countries. It is freely available at \url{mfem.org}, on GitHub
at \url{github.com/mfem}, where the MFEM community includes more than 165
members), as well as via Spack and OpenHPC. The application outreach and the
integration in the ECP ecosystem is further facilitated by MFEM's participation
in ECP's xSDK project.

\paragraph{Key Challenges}

The key challenges addressed by the LLNL ATDM Mathematical Libraries project are:

\noindent
{\bf \em Robust high-order finite element methods for ALE compressible flow.}
While high-order methods offer significant advantages in terms of HPC performance,
their application to complicated ALE problems requires careful considerations to
control oscillations and ensure accuracy.

\begin{figure}[htb]
\centering
\includegraphics[width=\textwidth]{projects/2.3.6-NNSA/2.3.6.02-LLNL-ATDM/mfem-amr}
\caption{\label{fig:mfem-amr}AMR implementation in MFEM allows many applications to benefit from non-conforming adaptivity, without significant changes in their codes.}
\end{figure}

\noindent
{\bf \em Scalable algorithms for unstructured adaptive mesh refinement.}
Adaptive mesh refinement is a common way to increasing application efficiency
in problems with localized features. While block-structured AMR has been
well-studied, applying AMR in unstructured settings is challenging, especially
in terms of derefinement, anisotropic refinement, parallel rebalance and
scalability.

\noindent
{\bf \em GPU porting of finite element codes.}
Due to the relatively high complexity of the finite element machinery, MFEM,
BLAST and related codes use object-oriented C++ design that allows generality
and flexibility, but poses challenges in terms of porting to GPU architectures.
Finding the right balance between generality and performance in the GPU context
is an important challenge for many finite element-based codes that remains
outstanding in the current software and programming model environment.

\paragraph{Solution Strategy}

The MFEM team has performed and documented a lot of research in
high-performance mathematical algorithms and finite element discretizations
of interest to ATDM applications
\cite{BLAST18,BLASTFCT18,BLASTFCT17,BLAST16,BLAST14,BLAST13,BLAST12,BLAST11}.
Our work has demonstrated that the high-order finite element approach can
successfully handle coupled multi-material ALE, radiation-diffusion and MHD.
We have also shown how high-order methods can be adapted for monotonicity
(positivity preservation), handling of artificial viscosity (shock capturing),
sub-zonal physics via closure models, etc.

To enable many applications to take advantage of unstructured mesh adaptivity,
the MFEM team is developing AMR algorithms at library level, targeting both
{\em conforming} local refinement on simplex meshes and {\em non-conforming}
refinement for quad/hex meshes. Our approach is fairly general, allowing for
any high-order finite element space, H1, H(curl), H(div), on any high-order
curved mesh in 2D and 3D, arbitrary order hanging nodes, anisotropic refinement,
derifenement and parallel load balancing.
An important feature of our library approach is that it is independent of
the physics, and thus easy to incorporate in apps, see Figure \ref{fig:mfem-amr}.

As part of the efforts in the ECP co-design Center for Efficient Exascale
Discretizations (CEED), the MFEM team is also developing mathematical algorithms
and software implementations for finite element methods that exploit increasingq
on-node concurrency targeting multiple complex architectures (e.g. GPUs). This
work includes the libCEED low-level API library, the Laghos miniapp, and several
other efforts available through CEED.

To reach its many customers and partners in NNSA, DOE Office of Science, academia
and industry, the MFEM team delivers regular releases on GitHub (e.g. mfem-3.3 and
mfem-3.3.2 in 2017, mfem-3.4 in 2018) that include detailed documentation and
many example codes.
Code quality is ensured by smoke tests with Travis CI on Linux, Mac, Windows and
nightly regression testing at LLNL.

\paragraph{Recent Progress}

Selected recent highlights:
\begin{itemize}
\item
Developed a new formulation for discretizing problems with 1D spherical symmetry
in BLAST. Extended BLAST to the 3T-model (separate equations for the electron
and ion internal energies). Added support for changing masses during the
Lagrangian phase.
\item
Completed the delivery of discretization support for the FY18 MARBL ATDM L2
milestone, including new 3T radiation-diffusion algorithms, and a simulation
capability for problems with spherical and cylindrical symmetry via weight
adjustments. With this and other support from the MFEM team, the MARBL team
successfully defended its ATDM L2 milestone.
\item
Worked on high-order ALE algorithms in BLAST: developed remap step for density
component masses, various code improvements and bugs fixes related to L2
milestone.
\item
MFEM version 3.4 was released with many new features including: significantly
improved non-conforming unstructured AMR scalability; integration with PUMI;
block nonlinear operators and variable order NURBS; Conduit mesh blueprint
support; general high-order-to-low-order refined field transfer; new specialized
time integrators and 12 new examples and miniapps.
\item
Implemented an initial draft of MFEM’s ``engine'' interface extension to support
GPUs and other accelerators. Performed tests with the new ``engine'' extension
on Sierra. Explored its use in the Laghos miniapp and BLAST.
\item
Improvements in AMR interpolation matrix for better construction of
communication groups and performance monitoring in the Laghos miniapp.
\item
Several AMR improvements, including better local conforming tetrahedral
refinement (collaborating with a GitHub user), fix for boundary coefficient
projection, and general communication groups on for non-conforming AMR
supporting the AMR integration in BLAST.
\item
With summer student made progress on matrix-free algorithms for high-order field
monotonicity, targeting performance improvements in the remap phase of
MARBL/BLAST.
\item
GLVis version 3.4 was released with several new features including: 10 new color
palettes, better multi-screen window manager support, capability to show element
and vertex numbering in 2D, use of X.509 certificates in secure sockets, and a
new CMake build system.
\item
Developed a new version of the hogtess high order experimental visualization
tool based on modern OpenGL 4.3 compute shaders that does correct cutting of
high order meshes in 3D.
\end{itemize}

\paragraph{Next Steps}

Our next steps include:
test the new engine API on Sierra using MFEM examples and the Laghos miniapp;
prepare and release the next version of MFEM, v4.0, with initial support for
GPU architectures;
continue to attend and contribute to the weekly MARBL and BLAST meetings;
and provide support for the upcoming MARBL L2 milestones.


Input to the Recharge (RCH) Package is read from the file that has type ``RCH6'' in the Name File.  Any number of RCH Packages can be specified for a single groundwater flow model.

Recharge input can be specified using lists or arrays.  Array-based input for recharge is activated by providing READASARRAYS within the OPTIONS block.   Instructions for specifying list-based recharge is described in the previous section.  Array-based input for recharge provides a similar approach for providing recharge rates as previous MODFLOW versions.  Array-based input for recharge can be used only with the DIS and DISV Packages.  Array-based input for recharge cannot be used with the DISU Package.

When array-based input is used for recharge, the DIMENSIONS block should not be specified.  The array size is determined from the model grid.

\vspace{5mm}
\subsubsection{Structure of Blocks}
\vspace{5mm}

\noindent \textit{FOR EACH SIMULATION}
\lstinputlisting[style=blockdefinition]{./mf6ivar/tex/gwf-rcha-options.dat}
\vspace{5mm}
\noindent \textit{FOR ANY STRESS PERIOD}
\lstinputlisting[style=blockdefinition]{./mf6ivar/tex/gwf-rcha-period.dat}
\packageperioddescription

\vspace{5mm}
\subsubsection{Explanation of Variables}
\begin{description}
\input{./mf6ivar/tex/gwf-rcha-desc.tex}
\end{description}

\vspace{5mm}
\subsubsection{Example Input File}
\lstinputlisting[style=inputfile]{./mf6ivar/examples/gwf-rcha-example.dat}


\documentclass[11pt]{article}%
\usepackage{preamble}

\title{Hawkes EM with basis functions}
\date{\vspace{-5ex}} % avoid date

\begin{document}

\maketitle

\noindent
{\bf Notes on the implementation of the non parametric Hawkes estimation
algorithm presented in the \citep{zhou2013learning}
}

\vskip 1cm
\section{The original paper}
\subsection{Notations}
\begin{itemize}
\item $c$ : an id that identifies the realization of the process
\item $T_c$ : the duration of the realization $c$
\item $u$ : component
\item $i$ or $j$ : some events
\item $u_i^c$ : the component associated to the event $i$ in the realization $c$
\item $t_i$ : the time of event $i$
\item $d$ : an id that identifies the kernel components (there are $D$ kernels $g_d(t)$)
\item $\Delta t$ : the discretization step of the kernels
\item $m$ : an index used for discretzing the kernels $g_d(m\Delta t)$
\item $M\Delta t$ : the size of the support of the kernels
\end{itemize}
\subsection{The model}
\begin{equation}
\lambda_u(t) = \mu_u + \sum_{i:t_i<t} \sum_{d=1}^D a_{uu_i}^d g_d(t-t_i)
\end{equation}
\subsection{The formula for estimation (as given in the original paper)}
\subsubsection{The probabilities}
\begin{equation}
p_{ii}^c =
\frac
{\mu_{u_i^c}^{(k)}}
{\mu_{u_i^c}^{(k)} + \sum_{j=1}^{i-1}\sum_d a_{u_i^cu_j^c}^{d,(k)}g_d^{(k)}(t_i^c-t_j^c)}
\end{equation}
\begin{equation}
p_{ijd}^c =
\frac
{a_{u_i^cu_j^c}^{d,(k)} g_d^{(k)}(t_i^c - t_j^c)}
{\mu_{u_i^c}^{(k)} + \sum_{j=1}^{i-1}\sum_d a_{u_i^cu_j^c}^{d,(k)}g_d^{(k)}(t_i^c-t_j^c)}.
\end{equation}
\subsubsection{\texorpdfstring{Going from $k$-step to $k+1$-step for $\mu_u$ and the amplitudes $a_{uu'}$}
                              {Change step for amplitude}}
The update of the exogenous intensity $\mu_u$
\begin{equation}
\mu_u^{(k+1)} = \frac{1}{\sum_c T_c} \left( \sum_c \sum_{i=1,u_i^c=u}^{n_c} p_{ii}^c\right).
\end{equation}
The update of the amplitudes (there is an error in the paper $\alpha$ is written instead of $2\alpha$)
\begin{equation}
\label{ak}
a_{u,v}^{d,(k+1)} =
\left(
\frac
{a_{uv}^{d,(k)}\sum_c \sum_{i:u_i^c=u} \sum_{j<i,u_j^c=v} p_{ijd}^c}
{\sum_c \sum_{j:u_j^c=v} \int_0^{T_c-t_j^c} g_d^{(k)}(t)dt + 2\alpha}
\right)^{\frac 1 2}
\end{equation}
\subsubsection{\texorpdfstring{Going from $k$-step to $k+1$-step for the kernel functions $g_d(m\Delta t)$}
                              {Change step for the kernel functions}}
We first compute (let us note that both $C_{m}^d$ and $D_{m}^d$ are noted $C_m$ and $D_m$ in the original paper and a small index bug in $C_m$)
\begin{equation}
C_{m}^d = \frac{1}{g_d^{(k)}(m\Delta t)} \sum_c \sum_{u=1}^U\sum_{i=1}^{n_c} a_{uu_i^c}^{d,(k)} \mathbf{I}[m\Delta t \le T_c - t_i^c]
\end{equation}
and
\begin{equation}
D_{m}^d = \frac 1 {\Delta t} \sum_c \sum_{i,j:m\Delta t \le t_i^c-t_j^c<(m+1)\Delta t} p_{ijd}^c.
\end{equation}
Then independantly for each $d$, we set $g_{dm} = g_d(m\Delta t)$ then we iterate the following algo until convergence
\begin{itemize}
\item for $m=1$ to $M$ solve the quadratic following equation in $g_{dm}$ (fixing the other $g_{dm'}$ with $m'\neq m$)
\begin{equation}
\label{ODE}
-2\alpha \frac{g_{d,m+1} -2g_{dm}+g_{d,m-1}}{\Delta^2} + C_{m}^dg_{dm} = \frac{D_{m}^d}{g_{dm}}
\end{equation}
\end{itemize}
Let us point out that $C_m^d$ can be rewritten :
\begin{eqnarray}
C_{m}^d & = & \frac{1}{g_d^{(k)}(m\Delta t)} \sum_c \sum_{u=1}^U\sum_{v=1}^U a_{uv}^{d,(k)} \sum_{i=1, u_i^c = v}^{n_c}  \mathbf{I}[m\Delta t \le T_c - t_i^c] \\
& = &\frac{1}{g_d^{(k)}(m\Delta t)} \sum_c \sum_{v=1}^U \left( \sum_{u=1}^U a_{uv}^{d,(k)}\right)
\left( \sum_{i=1, u_i^c = v}^{n_c}   \mathbf{I}[m\Delta t \le T_c - t_i^c] \right)\\
& = &\frac{1}{g_d^{(k)}(m\Delta t)} \sum_c \sum_{u=1}^U
\left(\sum_{v=1}^U a_{vu}^{d,(k)}\right)
\left(\sum_{i=1, u_i^c = u}^{n_c}\mathbf{I}[m\Delta t \le T_c - t_i^c] \right) \\
& = &\frac{1}{g_d^{(k)}(m\Delta t)} \sum_c \sum_{u=1}^U
\left(\sum_{v=1}^U a_{vu}^{d,(k)}\right)
\left(\#\{i~/ ~u_i^c=u,~t_i^c\le T_c-m\Delta t\}\right)
\end{eqnarray}
\section{Our implementation}
\subsection{New notations}
The core computation will be made for a fixed component $u$ and a fixed realization $c$ (we will be able to parallelize the computations for each component).
So we set
\begin{equation}
\mu_u^c = \sum_{i=1,u_i^c=u}^{n_c} p_{ii}^c, ~~~\mbox{such that}~~
\mu_u = \frac{1}{\sum_c T_c} \sum_c \mu_u^c.
\end{equation}
Moreover
\begin{equation}
q_{uv}^{d,c} = a_{uv}^d \sum_{i:u_i^c=u} \sum_{j<i,u_j^c = v} p_{ijd}^c
\end{equation}
and
\begin{equation}
r_u^{d,c} = \sum_{j:u_j^c=u} \int_0^{T_c-t_j^c} g_d^{(k)}(t)dt
\end{equation}
so that formula \eqref{ak} writes
\begin{equation}
a_{u,v}^{d,(k+1)} =
\left(
\frac
{\sum_c q_{uv}^{d,c,(k)}}
{\sum_c r_{v}^{d,c} + 2\alpha}
\right)^{\frac 1 2}
\end{equation}
and in the same way
\begin{equation}
C_{m,u}^{c,d} =
\frac{1}{g_d^{(k)}(m\Delta t)}
\left(\sum_{v=1}^U a_{vu}^{d,(k)}\right)
\left(\#\{i~/ ~u_i^c=u,~t_i^c\le T_c-m\Delta t\}\right),~~\mbox{such that}~~C_{m}^d = \sum_c \sum_{u=1}^U C_{m,u}^{c,d}
\end{equation}
and
\begin{equation}
D_{m,u}^{c,d} = \frac 1 {\Delta t} \sum_{i,j:u^i = u, m\Delta t \le t_i^c-t_j^c<(m+1)\Delta t} p_{ijd}^c~~\mbox{such that}~~D_{m}^d = \sum_c \sum_{u=1}^U D_{m,u}^{c,d}
\end{equation}

\subsection{Solving the ODE}
The quadratic equation \eqref{ODE} in $g_{d,m}$  writes
\begin{equation}
-2\alpha \frac{g_{d,m+1} -2g_{dm}+g_{d,m-1}}{\Delta t^2} + C_{m}^dg_{dm} = \frac{D_{m}^d}{g_{dm}}
\end{equation}
\begin{equation}
\left(\frac{4\alpha}{\Delta t^2} + C_{m}^d\right) g_{dm}^2
-\frac{2\alpha}{\Delta t^2}
\left(
 g_{d,m+1} +g_{d,m-1}
 \right)g_{dm}
  - D_{m}^d = 0
\end{equation}

\subsection{The basic methods in the tick package}

\vskip .5cm
\noindent
{\bf The {\em compute\_r} method} \\
For fixed $u$ and a fixed realization $c$ this function performs the update
\begin{itemize}
\item $\forall d$, $\sum_{c'<c} r_u^{d,c'} \longrightarrow \sum_{c'\le c} r_u^{d,c'}$
\end{itemize}
\begin{algorithmic}[1]
\STATE \% In this function {\bf $u$ and $c$ are fixed}
\STATE \% {\bf The arguments are}
\STATE \% $T \gets$ a read-only parameter which corresponds to $T_c$
\STATE \% $\Delta t \gets$ a read-only parameter which corresponds to $\Delta t$
\STATE \% $g_d(m\Delta t) \gets$ a read-only $D \times M$ matrix representing the kernels $g_d(m\Delta t)$
\STATE \% $G_d(m\Delta t) \gets$ a read-only $D \times M$ matrix representing $\int_0^{(m+1)\Delta t} g_d(t) dt$
\STATE \% $r[d] \gets$ a $D$-vector which corresponds to $\sum_{c'<c} r_u^{d,c'}$ (will be updated)
\STATE \% {\bf The function starts here}
\FOR{$j$ all events of $u$}
\STATE $m_0 \gets floor((T-t_j)/\Delta t)$
\FOR{$d=0 \ldots D-1$}
\STATE $r[d] \gets r[d] + G_d[m_0-1] + (T-t_j-m_0\Delta t)g_d(m_0\Delta t)$
\ENDFOR
\ENDFOR
\end{algorithmic}

\vskip .5cm
\noindent
{\bf The {\em compute\_C} method} \\
For fixed $u$ and a fixed realization $c$ this function performs the update
\begin{itemize}
\item  $\forall m,~~\sum_{c'<c} C_{m,u}^{c',d} \longrightarrow \sum_{c'\le c} C_{m,u}^{c',d}$
\end{itemize}
\begin{algorithmic}[1]
\STATE \% In this function {\bf $u$ and $c$ are fixed}
\STATE \% {\bf The arguments are}
\STATE \% $T \gets$ a read-only parameter which corresponds to $T_c$
\STATE \% $\Delta t \gets$ a read-only parameter which corresponds to $\Delta t$
\STATE \% $g_d(m\Delta t) \gets$ a read-only $D \times M$ matrix representing the kernels
\STATE \% $a\_sum[d] \gets$ a read-only $D$-vector which corresponds to $\sum_{v=1}^U a_{vu}^{d}$
\STATE \% $C[d,m] \gets$ a $D \times M$ matrix which corresponds to $\sum_{c'<c} C_{m,u}^{c',d}$ (will be updated)
\STATE \% {\bf The function starts here}
\FOR{$m=0 \ldots M-1$}
\STATE $i \gets$ the greatest $i$ such that $t_i \le T-m\Delta t$
\FOR{$d=0 \ldots D-1$}
\STATE $C[d,m] \gets C[d,m] + a\_sum[d]*i/g_d(m\Delta t)$
\ENDFOR
\ENDFOR
\end{algorithmic}

\vskip .5cm
\noindent
{\bf The {\em compute\_mu\_q\_D} method} \\
For a fixed component $u$ and a fixed realization $c$ this function basically
performs the updates
\begin{itemize}
\item $\sum_{c'<c} \mu_u^{c'} \longrightarrow \sum_{c'\le c} \mu_u^{c'}$
\item  $\forall v,d~~\sum_{c'<c} q_{u,v}^{c',d} \longrightarrow \sum_{c'\le c} q_{u,v}^{c',d}$
\item  $\forall m,d~~\sum_{c'<c} D_{m,u}^{c',d} \longrightarrow \sum_{c'\le c} D_{m,u}^{c',d}$
\end{itemize}

\begin{algorithmic}[1]
\STATE \% In this function {\bf $u$ and $c$ are fixed}
\STATE \% {\bf The arguments are}
\STATE \% $T \gets$ a read-only parameter which corresponds to $T_c$
\STATE \% $\Delta t \gets$ a read-only parameter which corresponds to $\Delta t$
\STATE \% $g_d(m\Delta t) \gets$ a read-only $D \times M$ matrix representing the kernels
\STATE \% $a[v,d] \gets$ a read-only $U \times D$ matrix which corresponds to $\{a_{uv}^{d}\}_{vd}$
\STATE \% $q[v,d] \gets$ a $U \times D$ matrix which corresponds to $\sum_{c'<c} q_{u,v}^{c',d}$ (will be updated)
\STATE \% $D[d,m] \gets$ a $D \times M$ matrix which corresponds to $\sum_{c'<c} D_{m,u}^{c',d}$ (will be updated)
\STATE \% $\mu \gets$ a number which corresponds to $\sum_{c'<c} \mu_u^{c'}$ (will be updated)
\STATE \% {\bf The function starts here}
\STATE $v\_indices \gets$ a vector of size $U$ initialized to the last indices of each component
\STATE $mu\_out \gets 0$
\FOR{$i$ all events of $u$ reverse order}
\STATE \% Then we take care of the other quantitites
\STATE $norm \gets 0$ ~~~ \% used to store the normalization factor such that $\sum_{j,d} p_{ijd}=1$
\STATE $q\_temp \gets 0$ ~~~\% a $U \times D$ matrix that is needed as a buffer for $q[v,d]$
\STATE $D\_temp \gets 0$ ~~~\% a $D \times M$ matrix that is needed as a buffer for $C[d,m]$
\FOR{$v$ all components}
  \STATE Update the $v\_indices[v]$ to point to the last event $j_0$ of $v$  such that $t_{j_0}\le t_i$
  \STATE If no such event then skip to the next component $v$ (i.e., continue loop)
  \FOR{$j=j_0\ldots 0$}
  \IF{u==v and j==i}
  \STATE $norm \gets norm + \mu$
  \ELSE
  \IF{$t_i-t_j > Support(g_d)$}
   \STATE break loop since probability $p_{ijd}=0$
  \ENDIF
  \FOR{$d=1\ldots D$}
   \STATE $val \gets a[v,d]*g_d(t_i-t_j)$
  \STATE $m \gets (t_i-t_j)/\Delta t$
   \STATE $q\_temp[v,d] \gets q\_temp[v,d] + val$
   \STATE $D\_temp[d,m] \gets D\_temp[d,m]+ val$
   \STATE $norm \gets norm + val$
  \ENDFOR
  \ENDIF
  \ENDFOR
  \ENDFOR
  \STATE \% We are ready to perform proba normalization such that $\sum_{j,d} p_{ijd}=1$
  \STATE $mu\_out \gets mu\_out+mu/norm$
  \STATE \% The following is performed for all $v,d,m$
  \STATE $q[v,d] \gets q[v,d]+a[v,d]*q\_temp[v,d]/norm$
  \STATE $D[d,m] \gets D[d,m]+D\_temp[d,m]/(norm*\Delta t)$
  \ENDFOR
  \STATE $\mu \gets mu\_out$

\end{algorithmic}

\vskip .5cm
\noindent
{\bf The {\em compute\_g} method} \\
This method is pretty straightforward, so it is not described here.

\bibliographystyle{plainnat}
\bibliography{ref}

\end{document}