\chapter{Empirical Basis Functions for Max-stable Spatial Dependence}
\chaptermark{Empirical Basis Functions}
\label{appendix:c}

\section{Extreme value distributions} \label{eba:GEV}

The cumulative distribution function for the GEV is $F(y) = \exp\{-t(y)\}$ where
\begin{align} \label{ebeq:gevt}
  t(y) = \begin{cases}
      \left[1 + \xi \displaystyle \frac{y - \mu}{\sigma}\right]^{-1 / \xi}, \quad &\xi \neq 0 \\
      \\
      \exp\left\{- \displaystyle \frac{y - \mu}{\sigma}\right\}, &\xi = 0.
  \end{cases}
\end{align}
The probability density function for the GEV is given by $f(y) = \displaystyle \frac{1}{\sigma} t(x)^{\xi + 1} \exp\{-t(y)\}$ where $t(y)$ is defined in \eref{ebeq:gevt}.

\section{Grid approximation to PS density} \label{eba:gridapprox}

The PS($\alpha$) density can be challenging to use because it does not have a closed form.
From Section 2 of \citep{Stephenson2009}, the density can be expressed as
\begin{align}
  g_1(A) = \int_0^1 g_1(A, B) \dd B,
\end{align}
where
\begin{align}
  g_1(A, B) = \frac{\alpha}{1 - \alpha} \left( \frac{1}{A} \right)^{1 / 1 - \alpha} c(\pi B) \exp \left\{ -\left(\frac{1}{A}\right)^{\alpha / (1 - \alpha)} c(\pi B) \right\},
\end{align}
with
\begin{align}
  c(\psi) = \left[\frac{\sin(\alpha \psi)}{\sin(\psi)}\right]^{1 / (1 - \alpha)} \frac{\sin[(1 - \alpha) \psi]}{\sin(\alpha \psi)}.
\end{align}
\Citet{Stephenson2009} presents an auxiliary variable technique to deal with the integral in the density function, but we opt to numerically evaluate the integral because it is only one-dimensional.
To evaluate the integral, we use 50 evenly spaced quantiles of a Beta$(0.5, 0.5)$ distribution as the midpoints $B_1, \ldots, B_{50}$, and then use the midpoint rule to evaluate $\displaystyle \int_0^1 g_1(A, B) \dd B$.

\section{Standardized Gaussian kernel functions} \label{eba:gskfunctions}

\citet{Reich2012} use standardized Gaussian kernel functions as their spatial basis functions in the low-rank max-stable model.
Consider a set of $\bk_1, \ldots, \bk_L$ spatial knot locations in $\calD^2$, the region of interest.
Then
\begin{align}
  \hat{B}_{il} = \frac{\exp\left\{- \displaystyle\frac{||\bs_i - \bk_l||^2}{2 \rho^2} \right\}}{\displaystyle \sum_{j = 1}^L \exp\left\{- \frac{||\bs_i - \bk_j||^2}{2 \rho^2} \right\}}
\end{align}
where $|| \cdot ||$ is the Euclidean distance between a site and a knot location.

\section{Principal components} \label{eba:pca}

As a comparison to the EBFs, \fref{ebfig:fire-eigpanel} gives the first six principal components for the fire data, and \fref{ebfig:precip-eigpanel} gives the first six principal components for the precipitation data.
These figures show that the EBFs resemble the EOFs  for the uncersored precipitation data, but are quite different that the EOF from the censored fire data.
This is not surprising considering that the censoring results in only a small subset of data being used to estimate dependence.
\begin{figure}[htbp] % markdown/fire-analysis/basis-functions.R
  \centering
  \includegraphics[width=\linewidth]{plots/fire-eig-panel.pdf}

  \includegraphics[width=0.35\linewidth]{plots/firelambda-25.pdf}
  \caption{First six principal components and the cumulative sum of the first 25 eigenvalues for the Georgia fire data.}
  \label{ebfig:fire-eigpanel}
\end{figure}

% \begin{figure}[htbp] % markdown/fire-analysis/basis-functions.R
%   \centering
%   \includegraphics[width=0.5\linewidth]{plots/firelambda-25.pdf}
%   \caption{Cumulative sum of the first 25 eigenvalues.}
%   \label{ebfig:fire-eigpanel}
% \end{figure}

\begin{figure}[htbp]  % markdown/precipitation/cv-setup.R
  \centering
  \includegraphics[width=\linewidth]{plots/precip-eig-panel.pdf}

  \includegraphics[width=0.35\linewidth]{plots/preciplambda-25.pdf}
  \caption{First six principal components and the cumulative sum of the first 25 eigenvalues for the precipitation data.}
  \label{ebfig:precip-eigpanel}
\end{figure}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (c) 2003-2018 by The University of Queensland
% http://www.uq.edu.au
%
% Primary Business: Queensland, Australia
% Licensed under the Apache License, version 2.0
% http://www.apache.org/licenses/LICENSE-2.0
%
% Development until 2012 by Earth Systems Science Computational Center (ESSCC)
% Development 2012-2013 by School of Earth Sciences
% Development from 2014 by Centre for Geoscience Computing (GeoComp)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{The Diffusion Problem}
\label{DIFFUSION CHAP}

\subsection{\label{DIFFUSION OUT SEC}Outline}
In this section we discuss how to solve a time-dependent temperature
diffusion\index{diffusion equation} PDE for a given block of material.
Within the block there is a heat source which drives temperature diffusion.
On the surface, energy can radiate into the surrounding environment.
\fig{DIFFUSION FIG 1} shows the configuration.

\begin{figure}
\centerline{\includegraphics[width=\figwidth]{DiffusionDomain}}
\caption{Temperature Diffusion Problem with Circular Heat Source}
\label{DIFFUSION FIG 1}
\end{figure}

In \Sec{DIFFUSION TEMP SEC} we present the relevant model.
A time integration scheme is introduced to calculate the temperature at given time nodes $t^{(n)}$.
At each time step a Helmholtz equation\index{Helmholtz equation} must be solved.
The implementation of a Helmholtz equation solver will be discussed in \Sec{DIFFUSION HELM SEC}.
In Section~\ref{DIFFUSION TRANS SEC} this solver is used to build a solver for
the temperature diffusion problem.

\subsection{\label{DIFFUSION TEMP SEC}Temperature Diffusion}
The unknown temperature $T$ is a function of its location in the domain and time $t>0$.
The governing equation in the interior of the domain is given by
\begin{equation}
\rho c_p T_{,t} - (\kappa T_{,i})_{,i} = q_H
\label{DIFFUSION TEMP EQ 1}
\end{equation}
where $\rho c_p$ and $\kappa$ are given material constants.
In case of a composite material parameters depend on their location in the domain.
$q_H$ is a heat source (or sink) within the domain.
We use the Einstein summation convention\index{summation convention} as introduced in \Chap{FirstSteps}.
In our case we assume $q_H$ to be equal to a constant heat
production rate $q^{c}$ on a circle or sphere with center $x^c$ and radius $r$, and $0$ elsewhere:
\begin{equation}
q_H(x,t)=\left\{
\begin{array}{l l}
    q^c  & \quad\text{if $\|x-x^c\| \le r$}\\
    0    & \quad\text{else}\\
\end{array} \right.
\label{DIFFUSION TEMP EQ 1b}
\end{equation}
for all $x$ in the domain and time $t>0$.

On the surface of the domain we specify a radiation condition which prescribes
the normal component of the flux $\kappa T_{,i}$ to be proportional
to the difference of the current temperature to the surrounding temperature $T_{ref}$:
\begin{equation}
 \kappa T_{,i} n_i = \eta (T_{ref}-T)
\label{DIFFUSION TEMP EQ 2}
\end{equation}
$\eta$ is a given material coefficient depending on the material of the block and the surrounding medium.
$n_i$ is the $i$-th component of the outer normal field\index{outer normal field} at the surface of the domain.

To solve the time-dependent \eqn{DIFFUSION TEMP EQ 1} the initial temperature at time $t=0$ has to be given.
Here we assume that the initial temperature is the surrounding temperature:
\begin{equation}
T(x,0)=T_{ref}
\label{DIFFUSION TEMP EQ 4}
\end{equation}
for all $x$ in the domain. Note that the initial conditions satisfy the
boundary condition defined by \eqn{DIFFUSION TEMP EQ 2}.

The temperature is calculated at discrete time nodes $t^{(n)}$ where
$t^{(0)}=0$ and $t^{(n)}=t^{(n-1)}+h$, where $h>0$ is the step size which is assumed to be constant.
In the following, the upper index ${(n)}$ refers to a value at time $t^{(n)}$.
The simplest and most robust scheme to approximate the time derivative of the
temperature is the backward Euler\index{backward Euler} scheme.
The backward Euler scheme is based on the Taylor expansion of $T$ at time $t^{(n)}$:
\begin{equation}
T^{(n)}\approx T^{(n-1)}+T_{,t}^{(n)}(t^{(n)}-t^{(n-1)})
=T^{(n-1)} + h \cdot T_{,t}^{(n)}
\label{DIFFUSION TEMP EQ 6}
\end{equation}
This is inserted into \eqn{DIFFUSION TEMP EQ 1}. By separating the terms at
$t^{(n)}$ and $t^{(n-1)}$ one gets for $n=1,2,3\ldots$
\begin{equation}
\frac{\rho c_p}{h} T^{(n)} - (\kappa T^{(n)}_{,i})_{,i} = q_H +  \frac{\rho c_p}{h} T^{(n-1)}
\label{DIFFUSION TEMP EQ 7}
\end{equation}
where $T^{(0)}=T_{ref}$ is taken form the initial condition given by \eqn{DIFFUSION TEMP EQ 4}.
Together with the natural boundary condition
\begin{equation}
 \kappa T_{,i}^{(n)} n_i = \eta (T_{ref}-T^{(n)})
\label{DIFFUSION TEMP EQ 2222}
\end{equation}
taken from \eqn{DIFFUSION TEMP EQ 2} this forms a boundary value problem that
has to be solved for each time step.
As a first step to implement a solver for the temperature diffusion problem we
will implement a solver for the boundary value problem that has to be solved
at each time step.

\subsection{\label{DIFFUSION HELM SEC}Helmholtz Problem}
The partial differential equation to be solved for $T^{(n)}$ has the form
\begin{equation}
\omega T^{(n)} - (\kappa T^{(n)}_{,i})_{,i} = f
\label{DIFFUSION HELM EQ 1}
\end{equation}
and we set
\begin{equation}
\omega=\frac{\rho c_p}{h} \mbox{ and } f=q_H +\frac{\rho c_p}{h}T^{(n-1)} \;.
\label{DIFFUSION HELM EQ 1b}
\end{equation}
With $g=\eta T_{ref}$ the radiation condition defined by \eqn{DIFFUSION TEMP EQ 2222} takes the form
\begin{equation}
    \kappa T^{(n)}_{,i} n_{i} = g - \eta T^{(n)}\text{ on $\Gamma$}
\label{DIFFUSION HELM EQ 2}
\end{equation}
The partial differential \eqn{DIFFUSION HELM EQ 1} together with boundary
conditions of \eqn{DIFFUSION HELM EQ 2} is the Helmholtz equation\index{Helmholtz equation}.

We want to use the \LinearPDE class provided by \escript to define and solve a
general linear, steady, second order PDE such as the Helmholtz equation.
For a single PDE the \LinearPDE class supports the following form:
\begin{equation}\label{LINEARPDE.SINGLE.1 TUTORIAL}
-(A_{jl} u_{,l})_{,j}+D u = Y
\end{equation}
where we show only the coefficients relevant for the problem discussed here.
For the general form of a single PDE see \eqn{LINEARPDE.SINGLE.1}.
The coefficients $A$ and $Y$ have to be specified through \Data objects in
the \Function on the PDE or objects that can be converted into such \Data objects.
$A$ is a \RankTwo and $D$ and $Y$ are scalar.
The following natural boundary conditions\index{boundary condition!natural}
are considered on $\Gamma$:
\begin{equation}\label{LINEARPDE.SINGLE.2 TUTORIAL}
n_{j}A_{jl} u_{,l}+d u= y  \;.
\end{equation}
Notice that the coefficient $A$ is the same as in the PDE~\eqn{LINEARPDE.SINGLE.1 TUTORIAL}.
The coefficients $d$ and $y$ are each a \Scalar in the \FunctionOnBoundary.
Constraints\index{constraint} for the solution prescribe the value of the
solution at certain locations in the domain. They have the form
\begin{equation}\label{LINEARPDE.SINGLE.3 TUTORIAL}
u=r \mbox{ where } q>0
\end{equation}
Both $r$ and $q$ are a \Scalar where $q$ is the characteristic function\index{characteristic function} defining where the constraint is applied.
The constraints defined by \eqn{LINEARPDE.SINGLE.3 TUTORIAL} override any
other condition set by \eqn{LINEARPDE.SINGLE.1 TUTORIAL} or \eqn{LINEARPDE.SINGLE.2 TUTORIAL}.
The \Poisson class of the \linearPDEs module, which we have already used in
\Chap{FirstSteps}, is in fact a subclass of the more general \LinearPDE class.
The \linearPDEs module provides a \Helmholtz class but we will make direct use
of the general \LinearPDE class.

By inspecting the Helmholtz equation\index{Helmholtz equation}
(\ref{DIFFUSION HELM EQ 1}) and boundary condition (\ref{DIFFUSION HELM EQ 2}),
and substituting $u$ for $T^{(n)}$, we can easily assign values to the
coefficients in the general PDE of the \LinearPDE class:
\begin{equation}\label{DIFFUSION HELM EQ 3}
\begin{array}{llllll}
A_{ij}=\kappa \delta_{ij} & D=\omega & Y=f \\
d=\eta & y= g &  \\
\end{array}
\end{equation}
$\delta_{ij}$ is the Kronecker symbol\index{Kronecker symbol} defined
by $\delta_{ij}=1$ for $i=j$ and $0$ otherwise.
Undefined coefficients are assumed to be not present.\footnote{There is a
difference in \escript for a coefficient to be not present and set to zero.
Since in the former case the coefficient is not processed, it is more efficient
to leave it undefined instead of assigning zero to it.}
In this diffusion example we do not need to define a characteristic function
$q$ because the boundary conditions we consider in \eqn{DIFFUSION HELM EQ 2}
are just the natural boundary conditions which are already defined in the
\LinearPDE class (shown in \eqn{LINEARPDE.SINGLE.2 TUTORIAL}).

The Helmholtz equation can be set up the following way\footnote{Note that this
is not a complete code. The full source code can be found in ``helmholtz.py''.}:
\begin{python}
  mypde=LinearPDE(mydomain)
  mypde.setValue(A=kappa*kronecker(mydomain),D=omega,Y=f,d=eta,y=g)
  u=mypde.getSolution()
\end{python}
where we assume that \code{mydomain} is a \Domain object and
\code{kappa}, \code{omega}, \code{eta}, and \code{g} are given scalar values
typically \code{float} or \Data objects. The \method{setValue} method
assigns values to the coefficients of the general PDE.
The \method{getSolution} method solves the PDE and returns the solution
\code{u} of the PDE. \function{kronecker} is an \escript function returning
the Kronecker symbol.

The coefficients can be set by several calls to \method{setValue} in arbitrary
order.
If a value is assigned to a coefficient several times, the last assigned value
is used when the solution is calculated:
\begin{python}
  mypde = LinearPDE(mydomain)
  mypde.setValue(A=kappa*kronecker(mydomain), d=eta)
  mypde.setValue(D=omega, Y=f, y=g)
  mypde.setValue(d=2*eta) # overwrites d=eta
  u=mypde.getSolution()
\end{python}
In some cases the solver of the PDE can make use of the fact that the PDE is
symmetric\index{symmetric PDE}. A PDE is called symmetric if
\begin{equation}\label{LINEARPDE.SINGLE.4  TUTORIAL}
A_{jl}=A_{lj}\;.
\end{equation}
Note that $D$ and $d$ may have any value and the right hand sides $Y$, $y$ as
well as the constraints are not relevant. The Helmholtz problem is symmetric.
The \LinearPDE class provides the method \method{checkSymmetry} to check if
the given PDE is symmetric.
\begin{python}
  mypde = LinearPDE(mydomain)
  mypde.setValue(A=kappa*kronecker(mydomain), d=eta)
  print(mypde.checkSymmetry()) # returns True
  mypde.setValue(B=kronecker(mydomain)[0])
  print(mypde.checkSymmetry()) # returns False
  mypde.setValue(C=kronecker(mydomain)[0])
  print(mypde.checkSymmetry()) # returns True
\end{python}
Unfortunately, calling \method{checkSymmetry} is very expensive and is only
recommended for testing and debugging purposes.
The \method{setSymmetryOn} method is used to declare a PDE symmetric:
\begin{python}
  mypde = LinearPDE(mydomain)
  mypde.setValue(A=kappa*kronecker(mydomain))
  mypde.setSymmetryOn()
\end{python}
Now we want to see how we solve the Helmholtz equation on a
rectangular domain of length $l_{0}=5$ and height $l_{1}=1$.
We choose a simple test solution such that we can verify the returned solution
against the exact answer. We take $T=x_{0}$ (here
$q_H = 0$) and then calculate right hand side terms $f$ and $g$
such that the test solution becomes the solution of the problem.
If we assume $\kappa$ is constant, an easy calculation shows that we
have to choose $f=\omega \cdot x_{0}$.
On the boundary we get $\kappa n_{i} u_{,i}=\kappa n_{0}$, so we set $g=\kappa n_{0}+\eta x_{0}$.
The following script \file{helmholtz.py}\index{scripts!\file{helmholtz.py}}
which is available in the \ExampleDirectory implements this test problem using
the \finley PDE solver:
\begin{python}
  from esys.escript import *
  from esys.escript.linearPDEs import LinearPDE
  from esys.finley import Rectangle
  from esys.weipa import saveVTK
  # set some parameters
  kappa=1.
  omega=0.1
  eta=10.
  # generate domain
  mydomain = Rectangle(l0=5., l1=1., n0=50, n1=10)
  # open PDE and set coefficients
  mypde=LinearPDE(mydomain)
  mypde.setSymmetryOn()
  n=mydomain.getNormal()
  x=mydomain.getX()
  mypde.setValue(A=kappa*kronecker(mydomain), D=omega,Y=omega*x[0], \
                 d=eta, y=kappa*n[0]+eta*x[0])
  # calculate error of the PDE solution
  u=mypde.getSolution()
  print("error is ",Lsup(u-x[0]))
  saveVTK("x0.vtu", sol=u)
\end{python}
To visualize the solution `x0.vtu' you can use the command
\begin{verbatim}
mayavi2 -d x0.vtu -m Surface
\end{verbatim}
and it is easy to see that the solution $T=x_{0}$ is calculated.

The script is similar to the script \file{poisson.py} discussed in \Chap{FirstSteps}.
\code{mydomain.getNormal()} returns the outer normal field on the surface of the domain.
The function \function{Lsup} is imported by the \code{from esys.escript import *}
statement and returns the maximum absolute value of its argument.
The error shown by the print statement should be in the order of $10^{-7}$.
As piecewise bi-linear interpolation is used by \finley to approximate the
solution, and our solution is a linear function of the spatial coordinates,
one might expect that the error would be zero or in the order of machine
precision (typically $\approx 10^{-15}$).
However most PDE packages use an iterative solver which is terminated when a
given tolerance has been reached. The default tolerance is $10^{-8}$.
This value can be altered by using the \method{setTolerance} method of the
\LinearPDE class.

\subsection{The Transition Problem}
\label{DIFFUSION TRANS SEC}
Now we are ready to solve the original time-dependent problem. The main
part of the script is the loop over time $t$ which takes the following form:
\begin{python}
  t=0
  T=Tref
  mypde=LinearPDE(mydomain)
  mypde.setValue(A=kappa*kronecker(mydomain), D=rhocp/h, d=eta, y=eta*Tref)
  while t<t_end:
        mypde.setValue(Y=q+rhocp/h*T)
        T=mypde.getSolution()
        t+=h
\end{python}
\var{kappa}, \var{rhocp}, \var{eta} and \var{Tref} are input parameters of the model.
\var{q} is the heat source in the domain and \var{h} is the time step size.
The variable \var{T} holds the current temperature.
It is used to calculate the right hand side coefficient \var{f} in the
Helmholtz \eqn{DIFFUSION HELM EQ 1}.
The statement \code{T=mypde.getSolution()} overwrites \var{T} with the
temperature of the new time step $\var{t}+\var{h}$.
To get this iterative process going we need to specify the initial temperature
distribution, which is equal to $T_{ref}$.
The \LinearPDE object \var{mypde} and the coefficients that do not change over
time are set up before the loop is entered.
In each time step only the coefficient $Y$ is reset as it depends on the
temperature of the previous time step.
This allows the PDE solver to reuse information from previous time steps as
much as possible.

The heat source $q_H$ which is defined in \eqn{DIFFUSION TEMP EQ 1b}
is \var{qc} in an area defined as a circle of radius \var{r} and center
\var{xc}, and zero outside this circle. \var{q0} is a fixed constant.
The following script defines $q_H$ as desired:
\begin{python}
  from esys.escript import length,whereNegative
  xc=[0.02, 0.002]
  r=0.001
  x=mydomain.getX()
  qH=q0*whereNegative(length(x-xc)-r)
\end{python}
\var{x} is an \class{esys.escript.Data} object which contains locations in the \Domain \var{mydomain}.
The \function{length()} function (also from the \escript module) returns the
Euclidean norm:
\begin{equation}\label{DIFFUSION HELM EQ 3aba}
\|y\|=\sqrt{
y_{i}
y_{i}
} = \function{esys.escript.length}(y)
\end{equation}
So \code{length(x-xc)} calculates the distances of the location \var{x} to the
center of the circle \var{xc} where the heat source is acting.
Note that the coordinates of \var{xc} are defined as a list of floating point numbers.
It is automatically converted into a \Data class object before being
subtracted from \var{x}.
The function \function{whereNegative} applied to \code{length(x-xc)-r} returns
a \Data object which is equal to one where the object is negative (inside the
circle) and zero elsewhere.
After multiplication with \var{qc} we get a function with the desired property
of having value \var{qc} inside the circle and zero elsewhere.

Now we can put the components together to create the script \file{diffusion.py}
which is available in the \ExampleDirectory\index{scripts!\file{diffusion.py}}:
\begin{python}
  from esys.escript import *
  from esys.escript.linearPDEs import LinearPDE
  from esys.finley import Rectangle
  from esys.weipa import saveVTK
  #... set some parameters ...
  xc=[0.02, 0.002]
  r=0.001
  qc=50.e6
  Tref=0.
  rhocp=2.6e6
  eta=75.
  kappa=240.
  tend=5.
  # ... time, time step size and counter ...
  t=0
  h=0.1
  i=0
  #... generate domain ...
  mydomain = Rectangle(l0=0.05, l1=0.01, n0=250, n1=50)
  #... open PDE ...
  mypde=LinearPDE(mydomain)
  mypde.setSymmetryOn()
  mypde.setValue(A=kappa*kronecker(mydomain), D=rhocp/h, d=eta, y=eta*Tref)
  # ... set heat source: ....
  x=mydomain.getX()
  qH=qc*whereNegative(length(x-xc)-r)
  # ... set initial temperature ....
  T=Tref
  # ... start iteration:
  while t<tend:
        i+=1
        t+=h
        print("time step:",t)
        mypde.setValue(Y=qH+rhocp/h*T)
        T=mypde.getSolution()
        saveVTK("T.%d.vtu"%i, temp=T)
\end{python}
The script will create the files \file{T.1.vtu}, \file{T.2.vtu}, $\ldots$,
\file{T.50.vtu} in the directory where the script has been started.
The files contain the temperature distributions at time steps $1, 2, i,
\ldots, 50$ in the \VTK file format.

\begin{figure}
\centerline{\includegraphics[width=\figwidth]{DiffusionRes1}}
\centerline{\includegraphics[width=\figwidth]{DiffusionRes16}}
\centerline{\includegraphics[width=\figwidth]{DiffusionRes32}}
\centerline{\includegraphics[width=\figwidth]{DiffusionRes48}}
\caption{Results of the Temperature Diffusion Problem for Time Steps 1, 16, 32
         and 48 (top to bottom)}
\label{DIFFUSION FIG 2}
\end{figure}
\fig{DIFFUSION FIG 2} shows the result for some selected time steps.
An easy way to visualize the results is the command
\begin{verbatim}
mayavi2 -d T.1.vtu -m Surface
\end{verbatim}
Use the \emph{Configure Data} window in \mayavi to move forward and backward in time.


\subsection{Aggregate Demand (AD)}

For any given price level there is a corresponding IS-LM equilibrium, with an output level.

The Aggregate Demand curve models the relationship between the price level and equilibrium output.

As the price level rises, the real money supply falls. This means nominal interest rates rise to ensure LM equilibrium.

This rise in interest rates causes the IS curve to shift inwards, reducing output.

\(Y_d=Y_d(\dfrac{M}{P},G,T)\)

The slope of the Aggregate Demand curve


% arara: clean: { extensions: [ aux, bbl, blg, log, fdb_latexmk, fls, log, out, synctex.gz, toc ]}

\documentclass[12pt,a4paper]{article}

% Usepackages =============================================
% Standard et geometrie -----------------------------------
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[margin=2cm]{geometry}
\usepackage{enumitem}
\setlist[itemize,1]{label=\( \blacktriangleright \)}

% Maths ---------------------------------------------------
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage{mathtools,mathrsfs}

%Liens et dessins -----------------------------------------
\usepackage[colorlinks]{hyperref}
\usepackage[capitalize,nameinlink]{cleveref}
\usepackage{tikz}

% Couleurs ================================================
% definecolor ---------------------------------------------
\definecolor{coGB}{HTML}{1F77B4}
\definecolor{coOr}{HTML}{FF7F0E}
\definecolor{coWG}{HTML}{2CA02C}
\definecolor{coAR}{HTML}{D62728}
\definecolor{cMBP}{HTML}{9467BD}
\definecolor{coSM}{HTML}{8C564B}
\definecolor{coPP}{HTML}{E377C2}
\definecolor{coTG}{HTML}{7F7F7F}
\definecolor{coAG}{HTML}{BCBD22}
\definecolor{coBB}{HTML}{17BECF}
% hypersetup ----------------------------------------------
\hypersetup{
    colorlinks = True,
    linkcolor  = coAR,
    citecolor  = coWG,
    urlcolor   = coGB,
}

% Environment =============================================
\theoremstyle{definition}
\newtheorem{definition}{Definition}

\theoremstyle{plain}
\newtheorem{lemma}[definition]{Lemma}
\newtheorem{theorem}[definition]{Theorem}
\newtheorem{corollary}[definition]{Corollary}

\theoremstyle{remark}
\newtheorem{remark}[definition]{Remark}
\newtheorem{example}[definition]{Example}

% Maths ===================================================
% mathbb --------------------------------------------------
\newcommand{\bbA}{\mathbb{A}}
\newcommand{\bbB}{\mathbb{B}}
\newcommand{\bbC}{\mathbb{C}}
\newcommand{\bbD}{\mathbb{D}}
\newcommand{\bbN}{\mathbb{N}}
\newcommand{\bbR}{\mathbb{R}}
\newcommand{\bbS}{\mathbb{S}}
\newcommand{\bbT}{\mathbb{T}}
\newcommand{\bbZ}{\mathbb{Z}}

% mathcal --------------------------------------------------
\newcommand{\calD}{\mathcal{D}}
\newcommand{\calM}{\mathcal{M}}
\newcommand{\calN}{\mathcal{N}}
\newcommand{\calP}{\mathcal{P}}
\newcommand{\calV}{\mathcal{V}}

% mathscr --------------------------------------------------
\newcommand{\scrC}{\mathscr{C}}

% mathrm --------------------------------------------------
\newcommand{\rmL}{\mathrm{L}}
\newcommand{\rmH}{\mathrm{H}}

% Constants -----------------------------------------------
\newcommand{\ex}{\mathsf{e}}
\newcommand{\im}{\mathsf{i}}

% Fontions ------------------------------------------------
\newcommand{\bJ}{\mathop{}\!\mathsf{J}}
\newcommand{\bY}{\mathop{}\!\mathsf{Y}}
\newcommand{\Hu}{\mathop{}\!\mathsf{H}^{(1)}}
\newcommand{\Hd}{\mathop{}\!\mathsf{H}^{(2)}}
\newcommand{\bI}{\mathop{}\!\mathsf{I}}
\newcommand{\bK}{\mathop{}\!\mathsf{K}}

\newcommand{\bj}{\mathop{}\!\mathsf{j}}
\newcommand{\by}{\mathop{}\!\mathsf{y}}
\newcommand{\hu}{\mathop{}\!\mathsf{h}^{(1)}}
\newcommand{\hd}{\mathop{}\!\mathsf{h}^{(2)}}
\newcommand{\bi}{\mathop{}\!\mathsf{i}}
\newcommand{\bk}{\mathop{}\!\mathsf{k}}

\newcommand{\frj}{\mathop{}\!\mathfrak{j}}
\newcommand{\fry}{\mathop{}\!\mathfrak{y}}
\newcommand{\frh}{\mathop{}\!\mathfrak{h}^{(1)}}
\newcommand{\fri}{\mathop{}\!\mathfrak{i}}
\newcommand{\frk}{\mathop{}\!\mathfrak{K}}

% Operateurs ----------------------------------------------
\newcommand{\di}[1]{\mathop{}\!\mathrm{d}#1}
\DeclareMathOperator{\OO}{\mathcal{O}}
\DeclareMathOperator{\oo}{\mathcal{\scriptstyle O}}
\DeclareMathOperator{\Div}{div}
\DeclareMathOperator{\Rot}{\mathbf{curl}}
\newcommand{\Ind}[1]{\mathop{}\!\mathbf{1}_{#1}}
\newcommand{\restr}[2]{\left. #1\right\vert_{#2}}

% delimiters ----------------------------------------------
\newcommand{\plr}[1]{\left(#1\right)}
\newcommand{\clr}[1]{\left[#1\right]}
\newcommand{\blr}[1]{\left\lbrace#1\right\rbrace}
\newcommand{\abs}[1]{\left\lvert#1\right\rvert}
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}

% Vecteurs ------------------------------------------------
\newcommand{\vect}[1]{\boldsymbol{#1}}
\newcommand{\vx}{\boldsymbol{x}}

% Keywords ------------------------------------------------
\newcommand{\eps}{\varepsilon}
\newcommand{\comp}{\mathrm{comp}}
\newcommand{\loc}{\mathrm{loc}}
\newcommand{\inc}{\mathsf{in}}
\newcommand{\sca}{\mathsf{sc}}
\newcommand{\scav}{\sigma_\mathsf{c}}
\newcommand{\rcav}{\rho_\mathsf{c}}

% Titre ===================================================
\title{claudius: analytic computations for scattering \\ \Large \emph{calculs analytiques pour la diffusion des ondes}}
\author{Zoïs \textsc{Moitier}}

%==========================================================
\begin{document}

\maketitle

\begin{abstract}
    We solve scattering problem for cases where we have analytical expressions.
    All cavities consider will be invariant by rotation.
    The shape consider are disk, annulus, ball and spherical shell where the permittivity and permeability are radial function.
\end{abstract}

\tableofcontents

%=========================
\section{General settings}
%=========================

We consider the scattering by spherical cavities, disk or annulus in dimension \(2\), and ball or spherical shell in dimension \(3\).
We call \(\abs{\,\cdot\,}_d\) the euclidean norm in dimension \(d = 2, 3\).
Disk and ball are denoted by \(\bbB_\rho^d = \{\vx \in \bbR^d \mid \abs{\vx}_d < \rho\}\) for \(\rho > 0\), and annulus and spherical shell are denoted by \(\bbA_{\rho, \sigma}^d = \{\vx \in \bbR^d \mid \rho < \abs{\vx}_d < \sigma\}\) for \(0 < \rho < \sigma\).
The cavities will be compose of concentric spherical shell with impenetrable or penetrable core and denoted by \(\Omega\).
For a cavity with impenetrable core and \(N \ge 0\) layers, we have \(\Omega = \bbA_{\rho_1, \rho_2}^d \cup \bbA_{\rho_2, \rho_3}^d \cup \cdots \cup \bbA_{\rho_N, \rho_{N+1}}^d\) with \(0 < \rho_1 < \rho_2 < \cdots < \rho_{N+1}\).
For a cavity with penetrable core and \(N \ge 0\) layers, we have \(\Omega = \bbB_{\rho_1}^d \cup \bbA_{\rho_1, \rho_2}^d \cup \cdots \cup \bbA_{\rho_N, \rho_{N+1}}^d\) with \(0 = \rho_0 < \rho_1 < \cdots < \rho_{N+1}\).
The boundary/interfaces \(\Gamma\) of the different layers of the cavity \(\Omega\) is compose of concentric spheres \(\Gamma = \rho_1\bbS^{d-1} \cup \rho_2\bbS^{d-1} \cup \cdots \cup \rho_N\bbS^{d-1}\).

\bigskip

We define the function \(\eps \in \rmL^\infty(\bbR^d)\) and \(\mu \in \rmL^\infty(\bbR^d)\) as
\[
    \sigma(\vx) = \begin{dcases}
        \scav\plr{\abs{\vx}_d} & \text{if } \vx \in \Omega \\
        1                      & \text{otherwise}
    \end{dcases} \qquad
    \text{and} \qquad
    \rho(\vx) = \begin{dcases}
        \rcav\plr{\abs{\vx}_d} & \text{if } \vx \in \Omega \\
        1                      & \text{otherwise}
    \end{dcases}
\]
where
\[
    \scav = \sum_{n = 0}^{N} \eps_n \Ind{(\rho_n, \rho_{n+1})} \qquad
    \text{and} \qquad
    \rcav = \sum_{n = 0}^{N} \mu_n \Ind{(\rho_n, \rho_{n+1})}
\]
with \(\eps_n, \mu_n \in \scrC^\infty([\rho_n, \rho_{n+1}], \bbR^*)\) for \(0 \le n \le N\).
For the impenetrable case the index \(n = 0\) is not use.
In some context the function can be view as the permittivity ($\eps$) and the permeability ($\mu$) of a material.

\bigskip

A positive wavenumber is noted \(k\).
We only consider a plane wave incident field, we have \(u^\inc : \vx \mapsto \exp(\im\, k\, \vect{\nu} \cdot \vx)\) with \(\vect{\nu} \in \bbS^{d-1}\) the direction of the plane wave.
In the following, the scattered field is noted \(u^\sca\) and the total field is noted \(u\).

%=============================
\section{Helmholtz's equation}
%=============================

%----------------------------------
\subsection{The scattering problem}
%----------------------------------

We consider three type of problems: a cavity
\begin{itemize}
    \item with a penetrable core;
    \item with an impenetrable core and an homogeneous Dirichlet condition on the inner radius;
    \item with an impenetrable core and an homogeneous Neumann condition on the inner radius.
\end{itemize}
The domain of the operator \(u \mapsto -\mu^{-1}\Div(\eps^{-1}\, \nabla u)\) of domain depend on the type of problem:
\begin{align*}
    D^\calD & \coloneqq \{u \in \rmL^2(\bbR^d \setminus \bbB_{\rho_1}) \mid \Div(\eps^{-1}\, \nabla u) \in \rmL^2(\bbR^d \setminus \bbB_{\rho_1}) \text{ and } \restr{u}{\rho_1\bbS^{d-1}} = 0\}, \\
    D^\calN & \coloneqq \{u \in \rmL^2(\bbR^d \setminus \bbB_{\rho_1}) \mid \Div(\eps^{-1}\, \nabla u) \in \rmL^2(\bbR^d \setminus \bbB_{\rho_1})\},                                              \\
    D^\calP & \coloneqq \{u \in \rmL^2(\bbR^d) \mid \Div(\eps^{-1}\, \nabla u) \in \rmL^2(\bbR^d)\}
\end{align*}
and we define the ``locale'' version
\begin{align*}
    D_\loc^{\calD/\calN} & \coloneqq \{u \in \rmL_\loc^2(\bbR^d \setminus \bbB_{\rho_1}) \mid \forall \chi \in \scrC_\comp^\infty(\bbR^d),\ \chi u \in D^{\calD/\calN}\}, \\
    D_\loc^\calP         & \coloneqq \{u \in \rmL_\loc^2(\bbR^d) \mid \forall \chi \in \scrC_\comp^\infty(\bbR^d),\ \chi u \in D^\calP\}.
\end{align*}

\bigskip

We define the following scattering problem: Given a wavenumber \(k > 0\) and an incident field \(u^\inc\), find the scattering field \(u^\sca \in D_\loc^{\calD/\calN/\calP}\) such that the total field \(u = u^\inc + u^\sca\) satisfy
\begin{equation}\label{eq:scat_pde_im}
    (\calD / \calN)\begin{dcases}
        -\mu^{-1}\Div\plr{\eps^{-1} \nabla u} - k^2 u = 0                   & \text{in } \Omega \text{ and } \bbR^2 \setminus \overline{\bbB_{\rho_{N+1}}^d} \\[1ex]
        u = 0 \qquad \text{or} \qquad \partial_{\vect{n}}u = 0              & \text{on } \rho_1\bbS^{d-1}                                                    \\[1ex]
        \clr{u} = 0 \ \text{and}\ \clr{\eps^{-1} \partial_{\vect{n}} u} = 0 & \text{across } \rho_2\bbS^{d-1} \cup \cdots \cup \rho_{N+1}\bbS^{d-1}          \\[1ex]
        \text{$u^\sca$ is \(k\)-outgoing}
    \end{dcases}
\end{equation}
in the Dirichlet ($\calD$) or Neumann ($\calN$) case, or
\begin{equation}\label{eq:scat_pde}
    (\calP)\begin{dcases}
        -\mu^{-1}\Div\plr{\eps^{-1} \nabla u} - k^2 u = 0                   & \text{in } \Omega \text{ and } \bbR^2 \setminus \overline{\Omega}     \\[1ex]
        \clr{u} = 0 \ \text{and}\ \clr{\eps^{-1} \partial_{\vect{n}} u} = 0 & \text{across } \rho_1\bbS^{d-1} \cup \cdots \cup \rho_{N+1}\bbS^{d-1} \\[1ex]
        \text{$u^\sca$ is \(k\)-outgoing}
    \end{dcases}
\end{equation}
in the penetrable case, where \(\vect{n} : \Gamma \to \bbS^{d-1}\) are the outward unit normal and \(u^\sca\) is \(k\)-outgoing mean that, for \(|\vx| \ge \rho_N\), we have
\begin{subequations}\label{eq:OWC}
    \begin{align}
        u^\sca(\vx)
         & = \sum_{m \in \bbZ} \beta_m\, \Hu_m(k\, r)\, \ex^{\im\, m\, \theta},
         &                                                                                & \beta_m \in \bbC,
         &                                                                                & d = 2,                 \\
        u^\sca(\vx)
         & = \sum_{\ell = 0}^{+\infty} \sum_{m = -\ell}^\ell \beta_\ell^m\, \hu_\ell(k\, r)\, Y_\ell^m(\theta,\phi),
         &                                                                                & \beta_\ell^m \in \bbC,
         &                                                                                & d = 3,
    \end{align}
\end{subequations}
with \((r, \theta) \in \bbR_+ \times \bbR / 2\pi\bbZ\) the polar coordinate,
\((r, \theta, \phi) \in \bbR_+ \times \bbR / 2\pi\bbZ \times [0, \pi]\) the spherical coordinate, \(Y_\ell^m\) the spherical harmonic, and \(z \mapsto \Hu_m(z)\) (resp.\ \(z \mapsto \hu_m(z)\)) is the cylindrical (resp.\ spherical) Hankel function of the first kind of order \(m\).

%----------------------------
\subsection{The 1d reduction}
%----------------------------

We look for solution of problem of the form
\begin{align*}
    u(\vx)
     & = \sum_{m \in \bbZ} w_m(r)\, \ex^{\im\, m\, \theta}
     &                                                                                & \text{where } w_m(r) \coloneqq \frac{1}{2\pi} \int_0^{2\pi} u(r,\theta)\, \ex^{-\im\, m\, \theta} \di{\theta}
     &                                                                                & d = 2                                                                                \\
    u(\vx)
     & = \sum_{\ell = 0}^{+\infty} \sum_{m = -\ell}^\ell w_{\ell, m}(r)\, Y_\ell^m(\theta, \phi)
     &                                                                                & \text{where } w_{\ell, m}(r) \coloneqq \int_{\bbS^2} u(r, \theta, \phi)\, \overline{Y_\ell^m(\theta, \phi)} \di{\omega}
     &                                                                                & d = 3
\end{align*}
with \((r, \theta) \in \bbR_+ \times \bbR / 2\pi\bbZ\) the polar coordinate,
\((r, \theta, \phi) \in \bbR_+ \times [0, \pi] \times \bbR / 2\pi\bbZ\) the spherical coordinate.
Similarly, we write the same kind of expansion for \(u^\inc\) and \(u^\sca\).
Using \cref{eq:wave_expan_2,eq:wave_expan_3}, we deduce that, in dimension \(2\), we have \(w_m^\inc(r) = \bJ_m(k\, r)\) for \(m \in \bbZ\) and, in dimension \(3\), we have \(w_{\ell, 0}^\inc(r) = \im^\ell\, \sqrt{\frac{2\ell+1}{4\pi}}\, \bj_\ell(k\, r)\) for \(\ell \in \bbN\) and \(w_{\ell, m}^\inc(r) = 0\) for \(\ell \in \bbN^*\) and \(m \in \{-\ell, \ldots, -1, 1, \ldots, \ell\}\).
To treat dimension \(2\) and \(3\) in a unified manner, we set \(w_p^\inc(r) = c_p\frj_p(k\, r)\) and \(\widehat{p}_d \in \bbR_+\) where
\[
    \begin{array}{l@{\quad}l@{\quad}l@{\quad}l@{\qquad}l}
        p = m \in \bbZ,    & \frj_p = \bJ_m,    & c_p = 1,                                & \widehat{p}_d = p^2,    & \text{for } d = 2; \\
        p = \ell \in \bbN, & \frj_p = \bj_\ell, & c_p = \im^\ell\, \sqrt{4\pi (2\ell+1)}, & \widehat{p}_d = p(p+1), & \text{for } d = 3.
    \end{array}
\]
So \cref{eq:scat_pde_im,eq:scat_pde,eq:OWC} reduce to a family of problem index by \(p\): Given \(k > 0\) find \(w_p^\sca \in D^{\calD_p/\calN_p/\calP_p}_\loc\) such that \(w_p = w_p^\inc + w_p^\sca\) and
\begin{equation}
    (\calD_p/\calN_p) : \begin{dcases}
        -\frac{\mu^{-1}}{r^{d-1}} \partial_r\plr{\frac{r^{d-1}}{\eps}\, \partial_r w_p} + \dfrac{\widehat{p}_d}{r^2\, \eps\mu} w_p - k^2\, w_p = 0 & \text{in } \bigcup_{n=1}^N (\rho_n, \rho_{n+1}) \text{ and } (\rho_{N+1}, +\infty) \\
        w_p(\rho_1) = 0 \qquad \text{or} \qquad w_p'(\rho_1) = 0                                                                                & \text{on } \{\rho_1\}                                                              \\
        \clr{w_p} = 0 \quad\text{and}\quad \clr{\eps^{-1}\, w_p'} = 0                                                                              & \text{across } \{\rho_2, \ldots, \rho_{N+1}\}                                      \\
        w_p^\sca(r) \propto \frh_p(k\, r)                                                                                & r \ge \rho_{N+1}
    \end{dcases}
\end{equation}
in the Dirichlet ($\calD$) or Neumann ($\calN$) case, or
\begin{equation}
    (\calP_p) : \begin{dcases}
        -\frac{\mu^{-1}}{r^{d-1}} \partial_r\plr{\frac{r^{d-1}}{\eps}\, \partial_r w_p} + \dfrac{\widehat{p}_d}{r^2\, \eps\mu} w_p - k^2\, w_p = 0 & \text{in } \bigcup_{n=0}^N (\rho_n, \rho_{n+1}) \text{ and } (\rho_{N+1}, +\infty) \\
        w_0'(0) = 0                                                                                & \text{on } \{0\}                                                                   \\
        \clr{w_p} = 0 \quad\text{and}\quad \clr{\eps^{-1}\, w_p'} = 0                                                                              & \text{across } \{\rho_1, \ldots, \rho_{N+1}\}                                      \\
        w_p^\sca(r) \propto \frh_p(k\, r)                                                                                & r \ge \rho_{N+1}
    \end{dcases}
\end{equation}
in the penetrable case, where \(\propto\) meaning ``up to a multiplicative constant'', \(\frh_p = \Hu_m\) if \(d = 2\), \(\frh_p = \hu_\ell\) if \(d = 3\) and
\begin{align*}
    \calD^{\calD_p/\calN_p}_\loc & \coloneqq \{w \in \rmL_\loc^2((\rho_1, +\infty)) \mid \forall \chi \in \scrC_\comp^\infty(\bbR),\ \chi w \in D^{\calD_p/\calN_p}\}, \\
    \calD^{\calP_p}_\loc         & \coloneqq \{w \in \rmL_\loc^2(\bbR_+^*) \mid \forall \chi \in \scrC_\comp^\infty(\bbR),\ \chi w \in D^{\calP_p}\}
\end{align*}
with \(A_p w =  \partial_r(\eps^{-1}\, r^{d-1} \partial_r w) - \widehat{p}_d\, r^{d-3}\, \eps^{-1}\, w\) and
\begin{align*}
    D^{\calD_p} & \coloneqq \{w \in \rmL^2((\rho_1, +\infty), r^{d-1}\di{r}) \mid A_p w \in \rmL^2((\rho_1, +\infty)) \text{ and } w(\rho_1) = 0\}, \\
    D^{\calN_p} & \coloneqq \{w \in \rmL^2((\rho_1, +\infty), r^{d-1}\di{r}) \mid A_p w \in \rmL^2((\rho_1, +\infty))\},                            \\
    D^{\calP_p} & \coloneqq \{w \in \rmL^2(\bbR_+^*, r^{d-1}\di{r}) \mid A_p w  \in \rmL^2(\bbR_+^*)\}.
\end{align*}
In each layers \(n\) or in the core we assume that we have a solution basis of the ordinary differential equation
\[
    -\frac{1}{r^{d-1}\, \mu_n} \partial_r\plr{\frac{r^{d-1}}{\eps_n}\, \partial_r w_p} + \dfrac{\widehat{p}_d}{r^2\, \eps_n\, \mu_n} w_p - k^2 w_p = 0
\]
noted \(f_{n, p}\) and \(g_{n, p}\), we also assume that \(f_{n, p}\) is continues at \(0\).

\begin{example}
    If \(\eps_n\) and \(\mu_n\) are non zero constants, we have
    \[
        f_{n, p}(r) = \begin{dcases}
            \frj_p(\sqrt{\eps_n\mu_n}\, k\, r)  & \text{if } \Re(\eps_n\mu_n) > 0 \\
            \fri_p(\sqrt{-\eps_n\mu_n}\, k\, r) & \text{if } \Re(\eps_n\mu_n) < 0
        \end{dcases}
    \]
    and
    \[
        g_{n, p}(r) = \begin{dcases}
            \fry_p(\sqrt{\eps_n\mu_n}\, k\, r)  & \text{if } \Re(\eps_n\mu_n) > 0 \\
            \frk_p(\sqrt{-\eps_n\mu_n}\, k\, r) & \text{if } \Re(\eps_n\mu_n) < 0
        \end{dcases}
    \]
    where \(\frj_p, \fri_p, \fry_p, \frk_p\) are \(\bJ_m, \bI_m, \bY_m, \bK_m\) for the dimension \(2\) and \(\bj_\ell, \bi_\ell, \by_\ell, \bk_\ell\) for the dimension \(3\).
\end{example}

%----------------------------
\subsection{The solution}
%----------------------------

We write the solution \(w_p\) has
\begin{equation}
    w_p(r) = \begin{dcases}
        \alpha_{0, p}\, f_{0, p}(r)                              & \text{if } 0 \le r \le \rho_1                                     \\
        \alpha_{n, p}\, f_{n, p}(r) + \beta_{n, p}\, g_{n, p}(r) & \text{if } 1 \le n \le N \text{ and } \rho_n \le r \le \rho_{n+1} \\
        \beta_{N+1, p}\frh_p(k\, r)     + c_p\frj_p(k\, r)       & \text{if } r \ge \rho_{N+1}
    \end{dcases}
\end{equation}
The first coefficient \(\alpha_{0, p}\) is not use in the impenetrable cases.
To compute the coefficient \(\alpha_{0, p}\), \(\alpha_{1, p}, \beta_{1, p}, \ldots, \alpha_{N, p}, \beta_{N, p}\), and \(\beta_{N+1, p}\), we use the transmission conditions at the interfaces.
For \(n \in \{1, \ldots, N\}\), they give \(T_{n-1, p}(\rho_n)(\alpha_{n-1, p}, \beta_{n-1, p})^\intercal = T_{n, p}(\rho_n) (\alpha_{n, p}, \beta_{n, p})^\intercal\) where
\begin{equation}
    T_{0, p}(\rho) = \begin{pmatrix}
        f_{0, p}(\rho) \\[2ex]
        \dfrac{f_{0, p}'(\rho)}{\eps_n(\rho)}
    \end{pmatrix} \in \calM_{2, 1}(\bbC) \quad
    \text{and} \quad
    T_{n, p}(\rho) = \begin{pmatrix}
        f_{n, p}(\rho)                        & g_{n, p}(\rho)                        \\[2ex]
        \dfrac{f_{n, p}'(\rho)}{\eps_n(\rho)} & \dfrac{g_{n, p}'(\rho)}{\eps_n(\rho)}
    \end{pmatrix} \in \calM_{2, 2}(\bbC)
\end{equation}
and the last interface \(T_{N, p}(\rho_{N+1})(\alpha_{N, p}, \beta_{N, p})^\intercal = H_p \beta_{N+1, p} + (c_p\frj_p(k\, r), c_p k \frj_p'(k\, r))^\intercal\) where
\begin{equation}
    H_p = \begin{pmatrix}
        \frh_p(k\, \rho_{N+1}) \\[1ex]
        k{\frh_p}'(k\, \rho_{N+1})
    \end{pmatrix} \in \calM_{2, 1}(\bbC).
\end{equation}
In the impenetrable cases the Dirichlet or Neumann conditions give \(T_{1, p}^{\calD/\calN} (\alpha_{1, p}, \beta_{1, p})^\intercal = \vect{0}_{2, 1}\) where
\[
    T_{1, p}^\calD = \begin{pmatrix}
        f_{0, p}(\rho_1) & g_{0, p}(\rho_1)
    \end{pmatrix} \in \calM_{1, 2}(\bbC), \quad
    \text{and} \quad
    T_{1, p}^\calN = \begin{pmatrix}
        f_{0, p}'(\rho_1) & g_{0, p}'(\rho_1)
    \end{pmatrix} \in \calM_{1, 2}(\bbC).
\]
In addition, we define
\[
    J_{q, p} = (0, \ldots, 0, c_p\frj_p(k\, r), c_p k \frj_p'(k\, r))^\intercal \in \bbC^{q}.
\]
For the Dirichlet or Neumann case, the coefficient \(\alpha_{1, p}, \beta_{1, p}, \ldots, \alpha_{N, p}, \beta_{N, p}\), and \(\beta_{N+1, p}\) are solution of the system
\[
    M_{N, p}^{\calD/\calN} (\alpha_{1, p}, \beta_{1, p}, \ldots, \alpha_{N, p}, \beta_{N, p}, \beta_{N+1, p})^\intercal = J_{2N+1, p}
\]
where
\[
    M_{N, p}^{\calD/\calN} = \begin{pmatrix*}[r]
        T_{1, p}^{\calD/\calN}(\rho_1)\\
        T_{1, p}(\rho_2) & -T_{2, p}(\rho_2)\\
        & T_{2, p}(\rho_3) & -T_{3, p}(\rho_3)\\
        & \ddots & \ddots\\
        & & T_{N-1, p}(\rho_N) & -T_{N, p}(\rho_N)\\
        & & & T_{N, p}(\rho_{N+1}) & H_p
    \end{pmatrix*} \in \calM_{2N+1}(\bbC).
\]
For the penetrable case, the coefficient \(\alpha_{0, p}\), \(\alpha_{1, p}, \beta_{1, p}, \ldots, \alpha_{N, p}, \beta_{N, p}\), and \(\beta_{N+1, p}\) are solution of the system
\[
    M_{N, p}^\calP (\alpha_{0, p}, \alpha_{1, p}, \beta_{1, p}, \ldots, \alpha_{N, p}, \beta_{N, p}, \beta_{N+1, p})^\intercal = J_{2N+2, p}
\]
where
\[
    M_{N, p}^\calP = \begin{pmatrix*}[r]
        T_{0, p}(\rho_1) & -T_{1, p}(\rho_1)\\
        & T_{1, p}(\rho_2) & -T_{2, p}(\rho_2)\\
        & & T_{2, p}(\rho_3) & -T_{3, p}(\rho_3)\\
        & & \ddots & \ddots\\
        & & & T_{N-1, p}(\rho_N) & -T_{N, p}(\rho_N)\\
        & & & & T_{N, p}(\rho_{N+1}) & H_p
    \end{pmatrix*} \in \calM_{2N+2}(\bbC).
\]

%===========================
\section{Maxwell's equation}
%===========================

\appendix

%======================
\section{Miscellaneous}
%======================

%-----------------------
\subsection{Coordinates}
%-----------------------

%
\subsubsection{Polar}
%

In dimension two, the Cartesian coordinate \(\vx = (x, y) \in \bbR^2\) are describe in term of polar coordinate \((r, \theta) \in \bbR_+ \times \bbR / 2\pi\bbZ\) by
\[
    \begin{dcases}
        x = r \cos(\theta) \\
        y = r \sin(\theta)
    \end{dcases} \qquad
    \text{and} \qquad
    \begin{dcases}
        r = \sqrt{x^2 + y^2} \\
        \theta = \arg(x + \im y)
    \end{dcases}
\]

%
\subsubsection{Spherical}
%

In dimension three, the Cartesian coordinate \(\vx = (x, y, z) \in \bbR^3\) are describe in term of spherical coordinate \((r, \theta, \phi) \in \bbR_+ \times \bbR / 2\pi\bbZ \times [0, \pi]\) by
\[
    \begin{dcases}
        x = r \cos(\theta) \sin(\phi) \\
        y = r \sin(\theta) \sin(\phi) \\
        z = r \cos(\phi)
    \end{dcases} \qquad
    \text{and} \qquad
    \begin{dcases}
        r = \sqrt{x^2 + y^2 + z^2} \\
        \theta = \arg(x + \im y)   \\
        \phi = \arccos\plr{\frac{z}{r}}
    \end{dcases}.
\]

%------------------------------
\subsection{Bessel's functions}
%------------------------------

%
\subsubsection{Cylindrical}
%

The cylindrical Bessel's function \(\bJ_m\), \(\bY_m\), \(\Hu_m\), and \(\Hd_m\) are define in \cite[Sec.~10.2]{NIST:DLMF} and they are solutions of the ODE
\[
    -\frac{1}{z}\plr{z\, w'}' + \frac{m^2}{z^2}w - w = 0.
\]
The cylindrical modified Bessel's function \(\bI_m\) and \(\bK_m\) are define in \cite[Sec.~10.25]{NIST:DLMF} and they are solutions of the ODE
\[
    -\frac{1}{z}\plr{z\, w'}' + \frac{m^2}{z^2}w + w = 0.
\]

%
\subsubsection{Spherical}
%

The spherical Bessel's function \(\bj_m\), \(\by_m\), \(\hu_m\), \(\hd_m\) ($-$) and \(\bi_m\), \(\bk_m\) ($+$) are define in \cite[Sec.~10.47]{NIST:DLMF} and they are solutions of the ODE
\[
    -\frac{1}{z^2}\plr{z^2\, w'}' + \frac{\ell(\ell+1)}{z^2}w \mp w = 0
\]
We have the following relation between the cylindrical and spherical Bessel function
\[
    \mathsf{f}_\ell(z) = \sqrt{\frac{\pi}{2z}} \mathsf{F}_{\ell+\frac{1}{2}}(z)
\]
where the couples \((\mathsf{f}, \mathsf{F})\) are \((\bj, \bJ)\), \((\by, \bY)\), \((\hu, \Hu)\), \((\hd, \Hd)\), \((\bi, \bI)\), and \((\bk, \bK)\).

%------------------------------
\subsection{Spherical harmonic}
%------------------------------

For \(\ell \in \bbN\) and \(m \in \{-\ell, \ldots, 0, \ldots, \ell\}\), the spherical harmonic \(Y_\ell^m\) in the spherical coordinate is define by
\[
    Y_\ell^m(\theta, \phi) = \sqrt{\frac{2\ell+1}{4\pi}\, \frac{(\ell-m)!
        }{(\ell+m)!}}\, \ex^{\im\, m\, \theta}\, P_\ell^m(\cos(\phi))
\]
where \(P_\ell^m\) are the associated Legendre polynomial define by
\[
    P_\ell^m(x) = \frac{(-1)^m}{2^\ell\, \ell!}\, (1-x^2)^{\frac{m}{2}}\, \partial_x^{\ell+m} (x^2-1)^\ell.
\]

%--------------------------------------------------
\subsection{Spherical wave expansion of plane wave}\label{sec:plane_wave_expan}
%--------------------------------------------------

The Jacobi-Anger expansion \cite[Eq.~10.12.1]{NIST:DLMF} states that, for \(z \in \bbC\) and \(t \in \bbC^*\),
\[
    \ex^{\frac{z}{2}(t-t^{-1})} = \sum_{m \in \bbZ} \bJ_m(z)\, t^m.
\]
For a 2d plane wave of direction \((0, 1)^\intercal\) and wavenumber \(k > 0\), we get
\begin{equation}\label{eq:wave_expan_2}
    \ex^{\im\, k\, y} = \sum_{m \in \bbZ} \bJ_m(k\, r)\, \ex^{\im\, m\, \theta}
    = \bJ_0(k\, r) + \sum_{m = 1}^{+\infty} \bJ_m(k\, r)\, \plr{\ex^{\im\, m\, \theta} + (-1)^m\ex^{-\im\, m\, \theta}}
\end{equation}
where \((x, y)\) are the Cartesian coordinates and \((r, \theta)\) the corresponding polar coordinates.

\bigskip

For a 3d plane wave of direction \(\vect{\nu} = (1, \nu_\theta, \nu_\phi)^\intercal \in \bbS^2\) and wavenumber \(k > 0\), we have the following expansion
\[
    \ex^{\im\, k\, \vect{\nu} \cdot \vx} = 4\pi \sum_{\ell = 0}^{+\infty} \im^\ell\, \bj_\ell(k\, r) \sum_{m = -\ell}^\ell \overline{Y_\ell^m(\nu_\theta, \nu_\phi)}\, Y_\ell^m(\theta, \phi)
\]
where \(\vx = (x, y, z)\) are the Cartesian coordinates and \((r, \theta, \phi)\) the corresponding spherical coordinates.
For the particular direction \(\vect{\nu} = (0, 0, 1)^\intercal\) in Cartesian coordinates or \(\vect{\nu} = (1, 0, 0)^\intercal\) in spherical coordinates, we obtain
\begin{equation}\label{eq:wave_expan_3}
    \ex^{\im\, k\, z} = \sum_{\ell = 0}^{+\infty} \im^\ell \,\sqrt{4\pi(2\ell+1)}\, \bj_\ell(k\, r)\, Y_\ell^0(\theta, \phi).
\end{equation}

\bibliographystyle{alpha}
\bibliography{references}

\end{document}


\documentclass{tufte-handout}

%\geometry{showframe}% for debugging purposes -- displays the margins

\usepackage{amsmath}

% Set up the images/graphics package
\usepackage{asymptote} % for asymptote graphics
\usepackage{graphicx}
\setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio}
\graphicspath{{graphics/}}

\title{Algorithm Complexity}
\author[Warren MacEvoy]{Warren MacEvoy}
% \date{24 January 2009}  % if the \date{} command is left out, the current date will be used

% The following package makes prettier tables.  We're all about the bling!
\usepackage{booktabs}

\hypersetup{colorlinks} % Comment this line if you don't wish to have colored links
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{listings}
\usepackage{siunitx} % align decimals in tables
\usepackage{nth}     % 1st, 2nd, ...
\usepackage{microtype} % Improves character and word spacing
\usepackage{asymptote} % for asymptote graphics
\usepackage{ccicons}
\usepackage{lipsum} % Inserts dummy text
\usepackage{booktabs} % Better horizontal rules in tables
\usepackage{graphicx} % Needed to insert images into the document

% The units package provides nice, non-stacked fractions and better spacing
% for units.
\usepackage{units}

% The fancyvrb package lets us customize the formatting of verbatim
% environments.  We use a slightly smaller font.
\usepackage{fancyvrb}
\fvset{fontsize=\normalsize}

% Small sections of multiple columns
\usepackage{multicol}

% Provides paragraphs of dummy text
\usepackage{lipsum}

% These commands are used to pretty-print LaTeX commands
\newcommand{\doccmd}[1]{\texttt{\textbackslash#1}}% command name -- adds backslash automatically
\newcommand{\docopt}[1]{\ensuremath{\langle}\textrm{\textit{#1}}\ensuremath{\rangle}}% optional command argument
\newcommand{\docarg}[1]{\textrm{\textit{#1}}}% (required) command argument
\newenvironment{docspec}{\begin{quote}\noindent}{\end{quote}}% command specification environment
\newcommand{\docenv}[1]{\textsf{#1}}% environment name
\newcommand{\docpkg}[1]{\texttt{#1}}% package name
\newcommand{\doccls}[1]{\texttt{#1}}% document class name
\newcommand{\docclsopt}[1]{\texttt{#1}}% document class option name

\theoremstyle{definition}
\newtheorem{definition}{Definition}
\theoremstyle{example}
\newtheorem{example}{Example}
\theoremstyle{theorem}
\newtheorem{theorem}{Theorem}
\begin{document}

\maketitle% this prints the handout title, author, and date

\begin{abstract}
\noindent Understanding asymptotic behavior of a series or function is useful.
\end{abstract}

%\printclassoptions

\section{introduction}\label{sec:introduction}
A key classifier in algorithm design is the order of operations required to implement it.  For example, the bubble sort's $O(n^2)$ vs merge sort's $O(n \log n)$ asymptotic behavior categorizes merge sort as a fundamentally better algorithm.

\begin{definition}{Big $O$}.  This is a specific meaning of "less than or about the same size as" for functions.

$O(g(n))$ is a set of functions that, for large enough $n$, eventually are smaller in magnitude than some constant multiple of $|g(n)|$.  That is $\tilde{g}(n) \in O(g(n))$ if, and only if, there exists some $c>0$ and some $n_0$ so that $|\tilde{g}(n)| \leq c |g(n)|$ for all $n \geq n_0$.
\end{definition}

In an expression, writing $O(g(n))$ means, "some specific function in $O(g(n))$.  You can also write $f(n)=O(g(n))$ as $f(n) \lessapprox g(n)$.

\begin{definition}{Little $o$}.  This is a specific meaning of "much less than" for functions.

$o(g(n))$ is a set of functions that, for large enough $n$, eventually are smaller in magnitude than {\em any}  constant multiple of $|g(n)|$.  That is $\tilde{g}(n) \in o(g(n))$ if, and only if, for any $c > 0$ there is some $n_0$ so that $|\tilde{g}(n)| \leq c |g(n)|$ for all $n \geq n_0$.
\end{definition}

In an expression, writing $o(g(n))$ means, "plus some specific function in $o(g(n))$. You can also write $f(n)=o(g(n))$ as $f(n) \ll g(n)$.

\begin{definition}{Big $\Omega$}. This is a specific meaning of "more than or about the same size as" for functions.

$\Omega(g(n))$ is a set of functions that, for large enough $n$, eventually are larger in magnitude than some constant multiple of $|g(n)|$.  That is $\tilde{g}(n) \in \Omega(g(n))$ if, and only if, there exists some $c>0$ and some $n_0$ so that $|\tilde{g}(n)| \geq c |g(n)|$ for all $n \geq n_0$.
\end{definition}

In an expression, writing $\Omega(g(n))$ means, "some specific function in $\Omega(g(n))$.  You can also write $f(n)=\Omega(g(n))$ as $f(n) \gtrapprox g(n)$.

\begin{definition}{Little $\omega$}. This is a specific meaning of "much more than" for functions.

$\omega(g(n))$ is a set of functions that, for large enough $n$, eventually are larger in magnitude than any constant multiple of $|g(n)|$.  That is $\tilde{g}(n) \in \omega(g(n))$ if, and only if, for any $c>0$ there is some $n_0$ so that $|\tilde{g}(n)| \geq c |g(n)|$ for all $n \geq n_0$.
\end{definition}

In an expression, writing $\omega(g(n))$ means, "some specific function in $\omega(g(n))$.  You can also write $f(n)=\omega(g(n))$ as $f(n) \gg g(n)$.

\begin{tabular}{|c|c|c|c|}
\hline
set & relation & constant & for all $n \geq n_0$\ldots \\
\hline
    $O(g(n))$  &  $\tilde{g}(n) \lessapprox g(n)$ & some $c>0$ & $|\tilde{g}(n)| \leq c |g(n)|$ \\
    $o(g(n))$  &  $\tilde{g}(n) \ll g(n)$ & any $c>0$ & $|\tilde{g}(n)| \leq c |g(n)|$ \\
    $\Omega(g(n))$  &  $\tilde{g}(n) \gtrapprox g(n)$ & some $c>0$ & $|\tilde{g}(n)| \geq c |g(n)|$ \\
    $\omega(g(n))$  &  $\tilde{g}(n) \gg g(n)$ & any $c>0$ & $|\tilde{g}(n)| \geq c |g(n)|$ \\
    \hline
\end{tabular}

\section{$O$ categories}

$O(1)$ means "bounded" - $f(n) \in O(1)$ means $|f(n)| \leq c$ for some $c$ and every $n > n_0$.  Any algorithm that takes some maximum number of steps to complete {\em independent} of the number of elements it is working with would be constant complexity.  Indexing into an array or computing a hash are $O(1)$ operations.

$O(\log n)$.  Logarithms grow very slowly, and so "almost constant".  An algorithm that can work with $n=2^{128}$ items, more than can conceivably ever be stored on a planet sized computer, would only take at most 128 times longer than working with $2$ items.  A binary search in a sorted array or balanced tree are $O(\log n)$ operations.

$O(n)$. Linear.  Any algorithm that typically goes through some fixed fraction of all the elements it contains to complete would be linear in complexity. Indexing into a linked list or searching for an element in an unsorted array are $O(n)$ operations.

$O(n \log n)$ Log linear.  An algorithm that must do an $O(\log n)$ step on each of it's elements would have this kind of complexity.  Since inserting an element is $O(\log n)$ for a balanced tree, creating a balanced tree from $n$ items is an $O(n \log n)$ step.  Sorts based on comparison and swapping are, at best, $O(n \log n)$.

$O(n^p)$  Polynomial.  Nested linear loops where the sub-loops go though a significant fraction of the entire set tend to be polynomial with $p$ the number of nested loops.  Bubble sort is $O(n^2)$ while a traditional matrix multiply is $O(n^3)$.

$O(b^n)$ Exponential.  Algorithms that have $b$ branches to explore at every level of an $n$ depth tree are $b^n$ complex.

$O(n!)$ Factorial.  This is faster than any exponential.  Trying every permutation is an example of factorial complexity\footnote{Stirling's approximation is $n! \approx n^n e^{-n} \sqrt{2\pi n}$, or the slightly better Gosper's approximation $n! \approx n^n e^{-n} \sqrt{(2n+1/3)\pi}$.}

Note $a^n n^b (\log n)^c \ll A^n n^B (\log n)^C$ whenever $a$ and $A$ are positive and $(a,b,c)$ is lexicographically less than $(A,B,C)$: ($a < A$) or ($a = A$ and $b < B$) or ($a=A$ and $b=B$ and $c < C$).

\section{$O$ manipulations}

\begin{theorem}{$f(n) \lessapprox g(n) \iff g(n) \gtrapprox f(n)$}

Suppose $f \in O(g)$.  So there is a $c > 0$ and $n_0$ so that $|f(n)| \leq c |g(n)|$ when $n \geq n_0$.  This can be re-written as $|g(n)| \geq \frac{1}{c} |f(n)|$.  Using $\tilde{c}=1/c$, and the same $n_0$, this is the required criteria for $g(n) \in \Omega(f(n))$. Going backwards is similar.
\end{theorem}

\begin{theorem}{$f(n) \ll g(n) \iff g(n) \gg f(n)$}

Suppose $f \in o(g)$.  So for any $c > 0$ there is an $n_0(c)$ so that $|f(n)| \leq c |g(n)|$ when $n \geq n_0$.  This can be re-written as $|g(n)| \geq \frac{1}{c} |f(n)|$.  So for any $\tilde{c}$ in the $\omega$ criteria, choosing $c=1/\tilde{c}$ gives the required $\tilde{n}_0(\tilde{c})=n_0(1/\tilde{c})$. Going backwards is similar.
\end{theorem}

Other useful facts:
\begin{itemize}
    \item Adding a finite number of small terms to a bounded term is bounded: $O(g(n)) + o(g(n)) = O(g(n))$.
    \item Adding a finite number of small terms to a small term is small: $o(g(n)) + o(g(n)) = o(g(n))$.
    \item if $f(n) \ll g(n)$, then $O(f(n))$ and $o(f(n))$ are small compared to $g(n)$.
    \item Adding a finite number of bounded terms to a bounded term is bounded: $O(g(n)) + O(g(n)) = O(g(n))$.
    \item Nonzero constants don't matter: $O(\alpha g(n))=O(g(n))$ and $o(\alpha g(n))=o(g(n))$, so long as $\alpha \neq 0$.
\end{itemize}

\end{document}


% !TEX root = as_grf_sopt.tex

%\newcommand{\cH}{\mathcal{H}}
\newcommand{\hgamma}{\hat{\gamma}}
We present an UCB-style analysis for GP-SOPT.TT and GP-SOPT.TOPK.
% and an analysis based on \cite{contal2014gaussian} for GP-SOPT.
We combine
several results on GP optimization \citep{srinivas2012information,vanchinathanadaptively}
and the spectral bandit analysis \citep{valko2014spectral}.
As in these results, our regret bounds depend on the mutual information between $f$ and the
observed values $\by_S$ at a set $S$ of nodes:
\begin{equation}
	\mathcal{I}(\by_S ; f) := H(\by_S) - H(\by_S \mid f),
\end{equation}
where $H(\cdot)$ denotes the entropy. If $f$ is drawn from a GP with observation noise distributed independently as $\mathcal{N}(0,\sigma_n)$,
the mutual information has the following analytical form:
\begin{equation}
	\mathcal{I}(\by_S; f) \;=\; \mathcal{I}(\by_S; f_S) \;=\; \frac{1}{2} \log |I + \sigma_n^{-2} \bC_{\bv_S\bv_S}|.
\end{equation}
Let
\begin{equation}
	\gamma_T := \max_{S \in V, |S| = T} \frac{1}{2} \log |I + \sigma_n^{-2} \bC_{\bv_S\bv_S}|,
\end{equation}
i.e., the maximum information about $f$ gained by observing $T$ function evaluations.
The regrets of our algorithms depend on the growth rate of $\gamma_T$, which can be linear in $T$ for arbitrary graphs.
However, real-world graphs often possess rich structures, such as clusters or communities, and
practical measures of relevance are often highly correlated with these structures, resulting in
slowly-growing $\gamma_T$. To formalize this intuition, we follow
\cite{valko2014spectral} to consider the \textit{effective dimension}:
\begin{equation}
	d^*_T := \max \left\{i \mid \lambda_i \leq \frac{\sigma_n^{-2}T}{(i-1)\log(1 + \frac{T}{\sigma_n^2 \omega_0})} \right\},
\end{equation}
where $\lambda_i$ is the $i$th smallest eigenvalue of $\widetilde{\cLap}_0$ and $\lambda_1 = \omega_0$.
The effective dimension is small when the first few $\lambda_i$'s are small and the rest increase rapidly,
as is often the case for graphs with community or cluster structures. On the contrary, if all the eigenvalues are close to $\omega_0$, then
$d^*_T$ may be linear in $T$. The following lemma bounds $\gamma_T$ in terms of $d^*_T$:
\begin{lemma}
	\label{lemma:gamma_T}
Let $T$ be the total number of rounds. Then
\begin{equation*}
	\gamma_T \leq 2 d^*_T \log \left( 1 + \frac{T}{ \sigma_n^2 \omega_0}\right).
\end{equation*}
\end{lemma}
\begin{proof}
	By Lemma 7.6 of \cite{srinivas2012information} and the fact that $\lambda_i^{-1}$ is the $i$th largest eigenvalue of the kernel $\bC_0 = \widetilde{\cLap}_0^{-1}$, we have
	\begin{equation}
		\gamma_T \leq \max_{\substack{\{m_i\}_{i=1}^T, m_i \geq 0, \\ \sum_{i=1}^T m_i = T}} \sum_{i=1}^T \log\left( 1 + \frac{m_i}{\sigma_n^2 \lambda_i} \right).
		\label{eq:gamma_bound}
	\end{equation}
	Then by applying the same argument that proves Lemma 6 of \cite{valko2014spectral}, we obtain the desired result.
	%Let the maximum be attained at $\{m^*_i\}_{i=1}^T$.
	%We then use $d^*_T$ to further bound the r.h.s. of \eqref{eq:gamma_bound}:
	%\begin{eqnarray}
	%\gamma_T &\leq& d^*_T \log \left( 1 + \frac{T}{\sigma^2 \omega_0}\right) + \sum_{i = d^*_T + 1}^T \log\left( 1 + \frac{m^*_i}{\sigma^2 \lambda_i}\right) \nonumber \\
	%         &\leq& d^*_T \log \left( 1 + \frac{T}{\sigma^2 \omega_0}\right) + \sum_{i = d^*_T + 1}^T \frac{m^*_i}{\sigma^2 \lambda_i}\\
  	%         &\leq& d^*_T \log \left( 1 + \frac{T}{\sigma^2 \omega_0}\right) + \frac{T}{\sigma^2 \lambda_{d^*_T+1}}\\
	%	 &\leq& 2 d^*_T \log \left( 1 + \frac{T}{\sigma^2 \omega_0}\right).
	%\end{eqnarray}
\end{proof}
%In the next two subsections
We will then derive regret bounds in terms of $\gamma_T$.

% \subsubsection{Active Search Regret}
%Let $\{v^*_i\}_{i=1}^n$ denote the nodes sorted decreasingly based on their function values, with ties broken arbitrarily.
Recall the cumulative regret of an active search algorithm is defined as
$ %$\begin{equation}
	R_T := \sum_{t=1}^T f(v^*_t) - f(v_t),
$ %$	\label{eq:search_regret}
% \end{equation}
where $\{v_t\}_{t=1}^T$ is the sequence of unique nodes selected by the algorithm.
For the two proposed UCB-style algorithms, GP-SOPT.TT \eqref{eq:sopt.tt} and GP-SOPT.TOPK \eqref{eq:sopt.topk}, we give the following
%For the proposed UCB-style algorithm GP-SOPT.TT, we give the following
bounds on their cumulative regrets.
\begin{theorem}
\label{thm:as_regret}
Pick $\delta \in (0,1)$.
Assume the vector of true node values, $\bff$, has bounded quadratic norm, $\|\bff\|_{\widetilde{\cLap}_0} = \sqrt{\bff^\top \widetilde{\cLap}_0 \bff}\leq B$,\footnote{This is similar to a bounded RKHS norm with kernel $C_0$ in \cite{srinivas2012information}.}
% Assume the true function $f$ lies in the RKHS characterized by the kernel $K := (L + \omega_0 I)^{-1}$ and its RKHS norm is upper-bounded by $B$.
and the observation noise $\epsilon_t$ is zero-mean conditioned on the past and is bounded by $\sigma_n$ almost surely.
If \textsc{gp-sopt.tt} and \textsc{gp-sopt.topk}
use \textsc{grf} prior \eqref{eq:generative} with zero-mean and graph Laplacian $\widetilde{\cLap}_0$,
% GP prior with zero mean and covariance $K$,
the observation noise model $\mathcal{N}(0,\sigma_n^2)$, and
$\alpha_t := \sqrt{2 B + 300 \gamma_t \log^3(t / \delta)}$, then their cumulative regrets will satisfy
%Its cumulative regret satisfies
\begin{equation*}
	\mbox{Pr}(\{R_T \leq k \sqrt{c_1 T \alpha_T \gamma_T}\;\; \forall T \geq 1\}) \geq 1 - \delta,
\end{equation*}
where the randomness is over the observation noise and $c_1 := \frac{8/\omega_0}{\log(1 + \sigma_n^{-2})}$. This implies that with high probability,
\begin{equation*}
R_T = O(k\sqrt{T}(B \sqrt{d^*_T} + d^*_T)).
\end{equation*}
\end{theorem}
This result is easily derived from the regret analysis of the GP-SELECT algorithm proposed by \cite{vanchinathanadaptively}
because
the exploration terms used by GP-SOPT.TT and GP-SOPT.TOPK both satisfy $\sigma_t(v) \leq s_t(v) \leq k \sigma_t(v)$,
%the exploration term used by GP-SOPT.TT satisfies $\sigma_t(v) \leq s_t(v) \leq k \sigma_t(v)$,
thereby maintaining the UCB property.
Although our regret bound is $k$ times worse than the GP-SELECT bound, the actual regret
tends to behave more favorably as we observe in our experiments that after a few tens of rounds, $s_t(v)$ becomes smaller than
$k \sigma_t(v)$ for almost all unqueried nodes, and the two proposed algorithm usually outperforms GP-SELECT.
We give the proof in Appendix \ref{appendix:proof_as_regret} for completeness.%
\footnote{An earlier version of this paper follows on to discuss bounds on vanilla GP-SOPT. These proofs used strategies from \cite{contal2014gaussian} which were found to be incorrect. Therefore, they have been removed in the current version of the paper.}

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

%\subsubsection{Optimization Regret}

%Following conventions in \cite{contal2014gaussian}, define $\mu_t(v), \sigma_t(v), \rho_t(v,v')$ to be the posterior mean, standard deviation, and correlation of nodes, respectively. Let $f(v)$ to be the true value on node $v$. Define the filtration\footnote{In original paper they defined it to be $\mathbf{Y}_t$} $\{\cH_t\}_{t=1}^T$ to be the history of pulls and outcomes, which forms a martingale. Let
%\begin{align*}
%	Y_t
%	&= ((f(v^\ast) - f(v_t)) - (\mu_t(v^*) - \mu_t(v_t)),
%	\\
%	M_T
%	&= \sum_{t=1}^T Y_t
%	\\
%	\ell_t^2
%	&= \sigma_t^2(v_t) + \sigma_t^2(v^*) - \rho_t(v_t,v^*)\sigma_t(v_t)\sigma_t(v^*),
%	\\
%	\langle M \rangle_T
%	&= \sum_{t=1}^T \ell_t^2
%\end{align*}
%
%Here we analyze the GP-SOPT algorithm, whose exploration term is exactly
%the risk reduction criterion in $\Sigma$-optimality without any modification.
%As shown earlier, that criterion may not give rise to an upper-confidence bound and we thus resort
%to a different type of analysis proposed recently by \cite{contal2014gaussian},
%who studied sequential global optimization with Gaussian processes.
%Using their key result concerning a general GP-based sequential global optimization algorithm,
%we obtain a bound on the \textit{optimization regret}:
%\begin{equation}
%	R^{o}_T := \sum_{t=1}^T f(v^*) - f(v_t),
%\end{equation}
%where $v^* \in \arg \max_{v \in V} f(v)$ and $\{v_t\}_{t=1}^T$ is
%the sequence of nodes picked by GP-SOPT \textit{with replacement}.\footnote{Notice its subscript difference with \eqref{eq:search_regret}.}
%%In addition to the maximum information gain $\gamma_T$, our bound also depends on
%Our bound depends on the maximum
%total risk reduction in $\Sigma$-optimality:
%\begin{equation}
%	\Delta_T := \max_{\bv_T} \; \bone^\top (\bC_0  - \bC_{T\mid \bv_T}) \bone,
%\end{equation}
%where $\bv_T$ denotes a sequence of $T$ nodes and $\bC_{T\mid \bv_T}$ denotes the posterior covariance conditioned on $\bv_T$.
%\begin{theorem}
%	\label{thm:opt_regret}
%Pick $\delta \in (0,1)$. Assume the true function $f$ is drawn from a \textsc{gp} with zero mean and covariance $\bC_0 = (\cLap+\omega_0\bI)^{-1}$, and
%the observation noise is distributed independently as $\mathcal{N}(0,\sigma^2)$. Let $T$ denote the total number of rounds
% and $\sigma_{\max}^2 := 1 / \omega_0 + \sigma_n^2$.
%The optimization regret of \textsc{gp-sopt}, \textsc{gp-sopt.tt}, and \textsc{gp-sopt.topk} using $\alpha_t = \frac{\sqrt{2\log(\nicefrac{2}{\delta})}\sigma_{\max}}{\sqrt[4]{T \Delta_T}}$ all  satisfy that for all $T > 1$,
%\begin{equation}
%\mbox{Pr}\left(R^o_T \leq
%	2\sqrt{2\log(\nicefrac{2}{\delta})\sigma_{\max}}\sqrt[4]{T\Delta_T}
%\right)
%%\sqrt{\log(\nicefrac{2}{\delta})}\left( \frac{\sigma_{\max}}{2}\sqrt{\frac{T \Delta_T}{c_1 \gamma_T + 1}} + 4 \sqrt{c_1 \gamma_T + 1}\right)
%\geq 1  - \delta.
%\end{equation}
%\end{theorem}
%This optimization regret bound is always smaller than $O(\sqrt{\frac{1}{\omega_0}T})$, which appeared in \cite{valko2014spectral}. Indeed, the sum of greedy $\Sigma$-optimality, \eqref{eq:sopt.orig} implies that $\Delta_T$ is %from \eqref{eq:var_update}, $\Delta_T$ is,
%\begin{equation*}
%	\sum_{t=1}^T \frac{\be_{v_t}^\top \bC_{t-1}^2 \be_{v_t}}{\be_{v_t}^\top \bC_{t-1} \be_{v_t}+\sigma_n^2}
%	% \leq \sum_{t=1}^T \frac{\sum_r Q_{t-1}(v_t,r)^2\lambda_r^4}{\sum_{r} Q_{t-1}(v_t,r)^2(\lambda_r^2+\sigma_n^2)}
%	\leq \sum_{t=1}^T\frac{\lambda_{\max}^2(\bC_{t-1}^2)}{\lambda_{\max}^2(\bC_{t-1})+\sigma_n^2}
%	\leq \frac{T/\omega_0^2}{\sigma_{\max}^2}.
%\end{equation*}
%Further, for graphs that contain large clusters, $\Delta_T$ may introduce a significant improvement. Since one may obtain good surveying results after sampling a few cluster centers, $\Delta_T$ usually grows much slower after a few iterations.

%Also, similar proof

%For the graphs in our experiments we observe that $\Delta_T$ usually grows slower than $\gamma_T$.
%In this situation, Theorem \ref{thm:opt_regret} and Lemma \ref{lemma:gamma_T} imply that
%with high probability, $R^o_T$ of GP-SOPT scales as $O(\sqrt[4]{T\tr(\bC_0)})$.
%The proof is in Appendix \ref{appendix:proof_opt_regret}.

%
%
%For Lemma 3 in \cite{contal2014gaussian}, they used the pulling rule,
%\begin{align}
%	&\mu_t(x^*) - \mu_t(x_t)
%	\leq
%	\phi_t(x_t) - \phi_t(x^*),
%	\\
%	\Rightarrow\quad
%	&
%	R_T \leq M_T + \sum_{t=1}^T (\phi_t(x_t) - \phi_t(x^*)).
%\end{align}


\documentclass[12pt]{cdblatex}
\usepackage{bssn-eqtns}

\begin{document}

\section*{PhysRevD.62.044034 equation (12)}

\begin{cadabra}
   from shared import *
   import cdblib

   jsonfile = 'bssn-eqtns-12.json'
   cdblib.create (jsonfile)

   # --------------------------------------------------------------------------

   DABarDt := \partial_{t}{ABar_{i j}}.          # cdb(eq12.00,DABarDt)
   DABarDt := N (trK ABar_{i j} - 2 ABar_{i a} ABar^{a}_{j})
              + \exp(-4\phi) (N R_{i j} - D_{i j}{N}
                              - (1/3) g_{i j} (N R_{a b} - D_{a b}{N}) g^{a b}).

                                                 # cdb(eq12.01,DABarDt)

   # --------------------------------------------------------------------------

   substitute (DABarDt, defD2)                   # cdb(eq12.02,DABarDt)
   substitute (DABarDt, defGamma2GammaBar)       # cdb(eq12.03,DABarDt)

   foo := g_{a b} -> \exp(4\phi) gBar_{a b}.
   bah := g^{a b} -> \exp(-4\phi) gBar^{a b}.

   substitute (DABarDt, foo)                     # cdb(eq12.04,DABarDt)
   substitute (DABarDt, bah)                     # cdb(eq12.05,DABarDt)
   distribute (DABarDt)                          # cdb(eq12.06,DABarDt)
   eliminate_kronecker (DABarDt)                 # cdb(eq12.07,DABarDt)
   substitute (DABarDt,defGBarSq)                # cdb(eq12.08,DABarDt)

   DABarDt = product_sort (DABarDt)              # cdb(eq12.09,DABarDt)

   rename_dummies (DABarDt)                      # cdb(eq12.10,DABarDt)
   canonicalise   (DABarDt)                      # cdb(eq12.11,DABarDt)

   map_sympy  (DABarDt, "simplify")              # cdb(eq12.12,DABarDt)
   factor_out (DABarDt,$\exp(-4\phi)$)           # cdb(eq12.13,DABarDt)

   foo := ABar^{a}_{b} -> gBar^{a c} ABar_{c b}.

   substitute (DABarDt, foo)

   DABarDt = product_sort (DABarDt)              # cdb(eq12.14,DABarDt)

   substitute (DABarDt,defGammaBarU)             # cdb(eq12.15,DABarDt)
   distribute (DABarDt)

   DABarDt = product_sort (DABarDt)              # cdb(eq12.16,DABarDt)

   canonicalise (DABarDt)                        # cdb(eq12.17,DABarDt)

   foo := gBar^{b c} \partial_{a}{gBar_{b c}} -> 0.   # follows from det(g) = 1
   bah := gBar^{e b} gBar^{f c} \partial_{a}{gBar_{b c}} -> - \partial_{a}{gBar^{e f}}.

   substitute (DABarDt,foo)                      # cdb(eq12.18,DABarDt)
   substitute (DABarDt,bah)                      # cdb(eq12.19,DABarDt)

   DABarDt = product_sort (DABarDt)

   canonicalise (DABarDt)                        # cdb(eq12.20,DABarDt)
   factor_out   (DABarDt, $\exp(-4\phi)$)        # cdb(eq12.21,DABarDt)

                                                 # cdb(eq12.99,DABarDt)

   cdblib.put ('DABarDt',DABarDt,jsonfile)
\end{cadabra}

\clearpage

\begin{dgroup*}
   \begin{dmath*}
      \cdb{eq12.00} = \Cdb*{eq12.01}
                    = \Cdb*{eq12.02}
                    = \Cdb*{eq12.03}
                    = \Cdb*{eq12.04}
                    = \Cdb*{eq12.05}
                    = \Cdb*{eq12.06}
                    = \Cdb*{eq12.07}
   \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*}
      \cdb{eq12.00} = \Cdb*{eq12.08}
                    = \Cdb*{eq12.09}
                    = \Cdb*{eq12.10}
                    = \Cdb*{eq12.11}
                    = \Cdb*{eq12.12}
                    = \Cdb*[\hskip2cm\hfill]{eq12.13}
   \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*}
      \cdb{eq12.00} = \Cdb*[\hskip2cm\hfill]{eq12.14}
                    = \Cdb*{eq12.15}
                    = \Cdb*[\hskip2cm\hfill]{eq12.16}
                    = \Cdb*{eq12.17}
                    = \Cdb*{eq12.18}
   \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*}
      \cdb{eq12.00} = \Cdb*{eq12.19}
                    = \Cdb*{eq12.20}
                    = \Cdb*{eq12.21}
   \end{dmath*}
\end{dgroup*}

\end{document}


\documentclass[a4paper]{article}

\title{Protein HMM}
\author{Danilo Horta}
\date{August 2019}

\usepackage{natbib}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage[margin=0.5in]{geometry}
\usepackage{rotating}
\usepackage{subcaption}
\usepackage[T1]{fontenc}

\theoremstyle{definition}
\newtheorem{example}{Example}[section]

\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

\theoremstyle{definition}
\newtheorem{corollary}{Corollary}[section]

\newcommand{\prob}[1]{p (#1)}
\newcommand{\cprob}[2]{p\left(#1\;\middle|\; #2\right)}
\newcommand{\eps}{\epsilon}
\newcommand{\s}{\texttt{\char`_}}
\newcommand{\gv}{\;|\;}
\newcommand*{\field}[1]{\mathbb{#1}}%

\begin{document}

\maketitle

\section{Model}

\begin{definition}\label{def:hmm}
Let $\mathcal A$ be a finite set of symbols.
Let $Q_1, Q_2, \dots$ be a Markov process and let $S_1, S_2, \dots$ be a stochastic process for which
$p(S_t\in\mathcal A\gv Q_1=q_1, Q_2=q_2, \dots, Q_t=q_t) = p(S_t\in\mathcal A\gv Q_t=q_t)$.
The pair $(Q_t, S_t)$ is a hidden Markov model (HMM) with alphabet $\mathcal A$.
\end{definition}

Let $(Q_t, S_t)$ be a HMM with the amino acid alphabet $\mathcal A$.
We want to replace it with a HMM that generates sequences of symbols from the alphabet
$\mathcal B = \{\mathrm A, \mathrm C, \mathrm G, \mathrm T\}$ of DNA bases and is able to account
for frame-shifting.
Let $\mathrm M_j$ be the so-called match state of an amino acid HMM and let $Q_t=\mathrm M_j$.
From the amino acid emission probabilities and any other relevant source of information
(codon usage bias, for instance), one can define the probability $\cprob{X_1=x_1, X_2=x_2, X_3=x_3}{Q_t=\mathrm M_j}$
of $\mathrm M_j$ emitting the codon $(x_1, x_2, x_3) \in \mathcal B^3$
--- one can also write $\cprob{X=x_1x_2x_3}{Q_t=\mathrm M_j}$, for short.
Since measurement errors occur and nature is not perfect, we will replace the
codon emission process by one that instead produces base sequences of different
lengths to account for base insertions and deletions (indels).

Node $\mathrm M_j$ in Fig.~\ref{fig:codon-hmm-tree} represents the modified match state.
The generated codon will go through four transitions, each one representing one of three possibilities: (i) delete a base; (ii) insert a base; or (iii) do nothing.
The deletion can happen in any of the three codon positions with equal probability.
If a deletion has already happened, the next deletion can happen in any of the remaining two positions with equal probability.
The insertion can happen between any two bases, before the first base or after the last base with equal probability.

The codon emitted at node $\mathrm M_j$ can go under $m\in\{0, 1, 2, 3, 4\}$ base indels during
the state transitions that end at some leaf-node state.
The probability of it undergoing $m$ indels is given by
\begin{align*}
    p(M=m) = \binom{4}{4-m} (1 - \eps)^{4-m} \eps^m,
\end{align*}
where coefficient $\binom{4}{m}$ counts the number of paths corresponding to $m$ base indels.
Fig.~\ref{fig:indel-dist} shows the base indel distributions over different values of $\eps$.
Let $F$ be a random variable representing the final sequence length generated by the model in
Fig.~\ref{fig:codon-hmm-tree}.
We have the probabilities
\begin{align*}
    p(F=1) = p(F=5) &= \eps^2(1-\eps)^2, \\
    p(F=2) = p(F=4) &= 2\eps^3(1-\eps) + 2\eps(1-\eps)^3,~\text{and} \\
    p(F=3)          &= \eps^4 + 4\eps^2(1-\eps)^2 + (1-\eps)^4
\end{align*}
illustrated in Fig.~\ref{fig:len-dist} over different values of $\eps$.

\begin{figure}[htbp]
\centering
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.7\linewidth]{indel-prob}
  \caption{Base indel distribution.}%
  \label{fig:indel-dist}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.7\linewidth]{seq-len-prob}
  \caption{Sequence length distribution.}%
  \label{fig:len-dist}
\end{subfigure}
\caption{
    Distribution of base indels and sequence length over the transition probability $\eps$.
    It is recommended to choose a value for $\eps$ that is smaller than $1/5$ such that
    $p(M=m)<p(M=m+1)$, as per Fig.~\ref{fig:indel-dist}.
}
\label{fig:dist}
\end{figure}

A sequence $\mathbf z=z_1 z_2\dots$ of finite but variable length will emerge at the end of the
process represented in Fig.~\ref{fig:codon-hmm-tree}.
Let $\mathcal Q_f$ be the set of hidden paths, starting with $Q_t=\mathrm M_j$ and ending at some leaf-node state,
that generate sequences of length $f$.
Let $Z^f=(Z^f_1, \dots, Z^f_f)$ be a $f$-tuple of random variables that generates such sequences of length $f$.
We have
\begin{align*}
    p(Z^f=z_1\dots z_f,F=f) &= \sum_{\mathbf q \in \mathcal Q_f}
    \cprob{Z^f=z_1\dots z_f}{Q_{t..t+4}=\mathbf q} p(Q_{t..t+4}=\mathbf q).
\end{align*}

\section{Final sequence distribution}

We will write $p(X=x_1x_2x_3) = p(X=x_1x_2x_3 \gv Q_t = \mathrm M_j)$ for brevity.
Underscore $\s$ denotes a summation over the corresponding random variables.
For example, $p(X=x_1\s\s)=\sum_{x_2,x_3}p(X=x_1x_2x_3)$.

\subsection{Sequences of length 1}

\begin{align*}
    p(Z^1=z_1,F=1)
        &= \eps^2(1-\eps)^2(p(X=z_1\s\s) + p(X=\s z_1\s) + p(X=\s\s z_1)) / 3
\end{align*}

\subsection{Sequences of length 2}

\begin{align*}
    p(Z^2=z_1z_2,F=2)
        &= 2\eps(1-\eps)^3(p(X=\s z_1z_2) + p(X=z_1\s z_2) + p(X=z_1z_2\s))/3\\
        &+ \eps^3(1-\eps)(p(X=z_1\s\s) + p(X=\s z_1\s) + p(X=\s\s z_1))p(z_2)/3\\
        &+ \eps^3(1-\eps)(p(X=z_2\s\s) + p(X=\s z_2\s) + p(X=\s\s z_2))p(z_1)/3
\end{align*}

\subsection{Sequences of length 3}

\begin{align*}
    p(Z^3=z_1z_2z_3,F=3) &= (1-\eps)^4 p(X=z_1z_2z_3)\\
        &+ 4\eps^2(1-\eps)^2 (p(X=\s z_2 z_3) + p(X=z_2\s z_3) + p(X=z_2 z_3\s))p(z_1)/9\\
        &+ 4\eps^2(1-\eps)^2 (p(X=\s z_1 z_3) + p(X=z_1\s z_3) + p(X=z_1 z_3\s))p(z_2)/9\\
        &+ 4\eps^2(1-\eps)^2 (p(X=\s z_1 z_2) + p(X=z_1\s z_2) + p(X=z_1 z_2\s))p(z_3)/9\\
        &+ \eps^4 (p(X=z_3\s\s) + p(X=\s z_3\s) + p(X=\s\s z_3))p(z_1)p(z_2)/9\\
        &+ \eps^4 (p(X=z_2\s\s) + p(X=\s z_2\s) + p(X=\s\s z_2))p(z_1)p(z_3)/9\\
        &+ \eps^4 (p(X=z_1\s\s) + p(X=\s z_1\s) + p(X=\s\s z_1))p(z_2)p(z_3)/9
\end{align*}

\subsection{Sequences of length 4}

\begin{align*}
    p(Z^4=z_1z_2z_3z_4,F=4) &= \eps(1-\eps)^3 (p(X=z_2z_3z_4)p(z_1)+p(X=z_1z_3z_4)p(z_2)\\
        &+p(X=z_1z_2z_4)p(z_3)+p(X=z_1z_2z_3)p(z_4))/2\\
        &+\eps^3(1-\eps)(\\
        &+ p(X=\s z_3z_4)p(z_1)p(z_2) + p(X=\s z_2z_4)p(z_1)p(z_3)\\
        &+ p(X=\s z_2z_3)p(z_1)p(z_4) + p(X=\s z_1z_4)p(z_2)p(z_3)\\
        &+ p(X=\s z_1z_3)p(z_2)p(z_4) + p(X=\s z_1z_2)p(z_3)p(z_4)\\
        &+ p(X=z_3\s z_4)p(z_1)p(z_2) + p(X=z_2\s z_4)p(z_1)p(z_3)\\
        &+ p(X=z_2\s z_3)p(z_1)p(z_4) + p(X=z_1\s z_4)p(z_2)p(z_3)\\
        &+ p(X=z_1\s z_3)p(z_2)p(z_4) + p(X=z_1\s z_2)p(z_3)p(z_4)\\
        &+ p(X=z_3z_4\s)p(z_1)p(z_2) + p(X=z_2z_4\s)p(z_1)p(z_3)\\
        &+ p(X=z_2z_3\s)p(z_1)p(z_4) + p(X=z_1z_4\s)p(z_2)p(z_3)\\
        &+ p(X=z_1z_3\s)p(z_2)p(z_4) + p(X=z_1z_2\s)p(z_3)p(z_4))/9
\end{align*}

\subsection{Sequences of length 5}

\begin{align*}
    p(Z^5=z_1z_2z_3z_4z_5,F=5)
        &= \eps^2(1-\eps)^2(\\
        &+p(z_1)p(z_2)p(X=z_3z_4z_5)+p(z_1)p(z_3)p(X=z_2z_4z_5)\\
        &+p(z_1)p(z_4)p(X=z_2z_3z_5)+p(z_1)p(z_5)p(X=z_2z_3z_4)\\
        &+p(z_2)p(z_3)p(X=z_1z_4z_5)+p(z_2)p(z_4)p(X=z_1z_3z_5)\\
        &+p(z_2)p(z_5)p(X=z_1z_3z_4)+p(z_3)p(z_4)p(X=z_1z_2z_5)\\
        &+p(z_3)p(z_5)p(X=z_1z_2z_4)+p(z_4)p(z_5)p(X=z_1z_2z_3))/10
\end{align*}

\section{Model generalisation}

The standard HMM description (Def.~\ref{def:hmm}) is usually extended to account for states that do not emit symbols.
Those states are referred to as silent states and are useful to describe a missing alignment position, for example.
This section goes a step further by defining a more general hidden Markov model that accounts for states that instead
emit sequence of symbols of variable length.

\begin{definition}
Let $\mathcal A$ be a finite set of symbols.
Let $Q_0, Q_1, \dots$ be a Markov process with initial state $q_0$, $p(q_0) = 1$, and $F_0, F_1, \dots$ be a stochastic process for which
\begin{equation*}
    p(F_t\in\field{N}\gv Q_0=q_0, Q_1=q_1, \dots, Q_t=q_t) = p(F_t\in\field{N}\gv Q_t=q_t)
\end{equation*}
and $p(F_0=0\gv Q_0=q_0) = 1$.
Let $V_0, V_1, \dots$ be a stochastic process for which
\begin{equation*}
    p(V_t\in\mathcal A^{f_t}\gv F_0=f_0, F_1=f_1, \dots, F_t=f_t, Q_0=q_0, Q_1=q_1, \dots, Q_t=q_t)
        = p(V_t\in\mathcal A^{f_t}\gv F_t=f_t, Q_t=q_t),
\end{equation*}
$p(V_0=\emptyset\gv F_0=f_0, Q_0=q_0) = 1$, and $f_0=0$.
The triplet $(Q_t, F_t, V_t)$ is an invisible Markov model (IMM) with alphabet $\mathcal A$.
\end{definition}

\begin{definition}
Let $\mathcal A$ be a finite set of symbols.
Let $Q_0, Q_1, \dots$ be a Markov process with initial state $q_0$.
Let $F_0, F_1, \dots$ and $V_0, V_1$ be two stochastic processes for which
\begin{equation*}
    p(F_t\in\field{N}, V_t\in\mathcal A^{f_t} \gv Q_0=q_0, Q_1=q_1, \dots, Q_t=q_t)
    = p(F_t\in\field{N}, V_t\in\mathcal A^{f_t} \gv Q_t=q_t)
\end{equation*}
and $p(F_0=0, V_t=\emptyset \gv Q_0=q_0) = 1$.
% Let $V_0, V_1, \dots$ be a stochastic process for which
% \begin{equation*}
%     p(V_t\in\mathcal A^{f_t}\gv F_0=f_0, F_1=f_1, \dots, F_t=f_t, Q_0=q_0, Q_1=q_1, \dots, Q_t=q_t)
%         = p(V_t\in\mathcal A^{f_t}\gv F_t=f_t, Q_t=q_t),
% \end{equation*}
% $p(V_0=\emptyset\gv F_0=f_0, Q_0=q_0) = 1$, and $f_0=0$.
The triplet $(Q_t, F_t, V_t)$ is an invisible Markov model (IMM) with alphabet $\mathcal A$.
\end{definition}

Fig.~\ref{fig:imm} illustrates a probabilistic graphical representation of the IMM.
States are not directly observable as well as sequence lenghts.
Therefore, given a final sequence $\mathbf z$, it not immediate clear which random variable $V_i$ emitted
which subsequence from $\mathbf z$.
We need some definitions in order to clarify this point.

\begin{figure}[htbp]
\centering
\includegraphics[width=.45\linewidth]{imm}
\caption{Invisible Markov model.}%
\label{fig:imm}
\end{figure}

\begin{definition}
    An IMM cycle is any probable sequence of states that starts and ends with the same state.
    A quiet state is a state that has a non-zero probability of emitting an empty sequence.
    A \textbf{quiet cycle} is any cycle having only quiet states.
\end{definition}

IMMs with no quiet cycles will simplify some calculations as we will see shortly.

\begin{corollary}
Let $M$ be the number of states of the IMM.
If it has no quiet cycles, any sequence of $M$ states will have emitted at least one symbol.
\end{corollary}

The marginal likelihood of $\mathbf z=z_1 .. z_L$ is given by
\begin{align}\label{eq:ml}
    \mathrm{ML}(\mathbf z) = p(V_1=\mathbf z) + p(V_1||V_2=\mathbf z) + \dots,
\end{align}
where $||$ denotes tuple concatenation.
The summation on the right-hand side of the above equation is unbouded if IMM is allowed to have
quiet cycles.
On the other hand, if IMM has no quiet cycles, the marginal likelihood of $\mathbf z=z_1 .. z_L$
can be given by
\begin{align*}
    \mathrm{ML}(\mathbf z) =
    p(V_1=\mathbf z) + p(V_1||V_2=\mathbf z) + \dots + p(V_1||V_2||\dots||V_{L\cdot M}=\mathbf z).
\end{align*}

Let $l_n=f_0+f_1+\dots+f_{n-1}$.
Observe that the outcomes of the random variables $F_1, F_2, \dots$ are enough to assign the subsequences
of $\mathbf z$ to the random variables $V_1, V_2, \dots$ in the following sense:
\begin{alignat*}{3}
    p&(V_1=z_1 .. z_{f_1}, V_2=z_{l_2+1} .. z_{l_2+f_2}, \dots, V_n=z_{l_n+1} .. z_{l_n+f_n}&&) =\\
    p&(V_1=z_1 .. z_{f_1}, V_2=z_{l_2+1} .. z_{l_2+f_2}, \dots, V_n=z_{l_n+1} .. z_{l_n+f_n}&&,
        F_1=f_1, F_2=f_2, \dots, F_n=f_n).
\end{alignat*}
We will therefore use the shorter notation
\begin{align*}
    p(V_{1..n}=\mathbf z, F_1=f_1, F_2=f_2, \dots, F_n=f_n)
\end{align*}
instead.
Also note that, if the association between subsequences of $\mathbf z$ with the random variables $V_1, V_2, \dots$ is
not specified, we still need to sum out the possible combinations:
\begin{align*}
    p(V_{1..n}=\mathbf z) = \sum_{f_1,\dots,f_n} p(V_{1..n}=
    \mathbf z, F_1=f_1, F_2=f_2, \dots, F_n=f_n).
\end{align*}

Lets consider the first term of the right-hand side of Eq. \eqref{eq:ml}.
We have
\begin{align*}
    p(V_1=\mathbf z)
        &= \sum_{q_1} p(V_1=\mathbf z, F_1=L \gv Q_1=q_1) p(Q_1=q_1 \gv Q_0=q_0).
\end{align*}
Lets now consider the second term of the right-hand side of Eq. \eqref{eq:ml}.
\begin{align*}
    p(V_{1..2}=\mathbf z)
        &= \sum_{f_1,f_2} p(V_{1..2}=\mathbf z, f_1, f_2)
        = \sum_{f_1,f_2,q_1,q_2} p(V_{1..2}=\mathbf z, f_1, f_2 \gv q_1, q_2) p(q_1, q_2) \\
        &= \sum_{f_1,f_2,q_2} p(V_2=\mathbf z, f_1, f_2 \gv q_2) \sum_{q_1} p(V_1=\mathbf z, f_1 \gv q_1) p(q_2 \gv q_1) p(q_1 \gv q_0)
\end{align*}

\newpage
\newpage

\section{Old model generalisation}

Let $L_t=F_0+F_1+\dots + F_{t-1}$ be the random variable describing the number of emitted symbols right
before the sequence emission by $Q_t$.
Let $S_1, S_2, \dots$ a stochastic process for symbol emission such that $S_t\in\mathcal A$
and
\begin{align*}
    p(s_{l_t+1} .. s_{l_t+f_t}, L_t=l_t, F_t=f_t, V_t=\mathbf v_t)
        = p(s_{l_t+1} .. s_{l_t+f_t}\gv L_t=l_t, F_t=f_t, V_t=\mathbf v_t).
\end{align*}

Let us define an additional stochastic process  associated with a given IMM
(random variables are omitted for didactic reasons whenever appropriate):
\begin{align*}
    p(S_0=\emptyset\gv Q_0=q_0)
        &=1\\
    p(s_1 .. s_{f_1},f_1,q_1)
        &= p(s_1 .. s_{f_1}\gv f_1,q_1)p(f_1,q_1) = p(s_1 .. s_{f_1}\gv f_1,q_1)p(f_1\gv q_1)p(q_1)\\
    p(s_1 .. s_{f_1+f_2},f_1,f_2,q_1,q_2)
        &= p(s_{f_1+1} .. s_{f_1+f_2}\gv f_1, f_2, q_2)p(s_1 .. s_{f_1}, f_1, f_2, q_1, q_2)\\
        &= p(s_{f_1+1} .. s_{f_1+f_2}\gv f_1, f_2, q_2)p(s_1 .. s_{f_1}\gv f_1, q_1) p(f_1, f_2, q_1, q_2)\\
        &= p(s_{f_1+1} .. s_{f_1+f_2}\gv f_1, f_2, q_2)p(s_1 .. s_{f_1}\gv f_1, q_1) p(f_1\gv q_1) p(f_2\gv q_2)p(q_2\gv q_1)p(q_1)
\end{align*}

\begin{figure}[htbp]
\centering
\includegraphics[width=.6\linewidth]{imm-s}
\caption{Invisible Markov model with symbol emission stochastic process.}%
\label{fig:imm-s}
\end{figure}

Let $L_t=F_0+F_1+\dots + F_{t-1}$, be the random variable describing the number of emitted symbols right
before the sequence emission by $Q_t$.
We define
\begin{align*}
    p(S_{l_t+1}=s_{l_t+1}, \dots, S_{l_t+f_t}=s_{l_t+f_t} \gv L_t=l_t, F_t=f_t, Q_t=q_t) =
                                p(V_t=(s_{l_t+1}, \dots, s_{l_t+f_t}) \gv F_t=f_t, Q_t=q_t).
\end{align*}
Given an IMM, we define the marginal likelihood of a sequence $\mathbf z = z_1z_2\dots z_L$
as being
\begin{align*}
    p(S_1=z_1, \dots, S_L=z_L) = \sum\limits_{\substack{q_1..q_N \\ f_1..f_N}}
        p(S_1=z_1, \dots, S_L=z_L, Q_1=q_1, F_1=f_1, \dots, Q_N=q_N, F_N=f_N),
\end{align*}
subject to $L=l_N+f_N$.\footnote{It might be a good moment to talk about degenerate IMM: when there is silent states cycle and/or
there are states with unbounded sequence lengths.}

Silent and non-silent HMM states are particular cases of IMM states that emit sequences of length zero and one,
respectively.

% \begin{align*}
%     p(S_{i_t}=s_{i_t}, S_{i_t+1}=s_{i_t+1}, \dots, S_{i_t+f_t-1}=s_{i_t+f_t-1} &| I_t=i_t, F_t=f_t, Q_t=q_t) =\\
%                                             &p(V_t=(s_{i_t}, s_{i_t+1}, \dots, s_{i_t+f_t-1}) | F_t=f_t, Q_t=q_t).
% \end{align*}

% \section{Old model generalisation}

% The standard HMM description (Def.~\ref{def:hmm}) is usually extended to account for states that do not emit symbols.
% Those states are referred to as silent states and are useful to describe a missing alignment position, for example.
% This section goes a step further by defining an alternative Markov model that accounts for states that instead
% emit sequence of symbols of variable length.

% \begin{definition}
% Let $\mathcal A$ be a finite set of symbols.
% Let $Q_1, Q_2, \dots$ be a Markov process and $F_1, F_2, \dots$ be a stochastic process for which
% \begin{equation*}
%     p(F_t\in\field{N}\gv Q_1=q_1, Q_2=q_2, \dots, Q_t=q_t) = p(F_t\in\field{N}\gv Q_t=q_t).
% \end{equation*}
% Let $V_1, V_2, \dots$ be a stochastic process for which
% \begin{equation*}
%     p(V_t\in\mathcal A^{f_t}\gv Q_1=q_1, F_1=f_1, Q_2=q_2, F_2=f_2, \dots, Q_t=q_t, F_t=f_t)
%         = p(V_t\in\mathcal A^{f_t}\gv Q_t=q_t, F_t=f_t).
% \end{equation*}
% The triplet $(Q_t, F_t, V_t)$ is an invisible Markov model (IMM) with alphabet $\mathcal A$.
% \end{definition}

% Silent and non-silent states are particular cases of IMM states that emit sequences of length zero and one,
% respectively.
% IMM reduces to the standard HMM if $p(F_t=1\gv Q_t=q_t)$ for every $t$.
% Fig.~\ref{fig:imm} illustrates a probabilistic graphical model for IMM.

% Let us define an additional stochastic process $S_1, S_2, \dots$ associated with a given IMM as follows.
% Let $L_t=F_1+\dots + F_{t-1}$, for which $L_1 = 0$, be the random variable describing the number of emitted symbols right
% before the sequence emission by $Q_t$.
% We define
% \begin{align*}
%     p(S_{l_t+1}=s_{l_t+1}, \dots, S_{l_t+f_t}=s_{l_t+f_t} \gv L_t=l_t, F_t=f_t, Q_t=q_t) =
%                                 p(V_t=(s_{l_t+1}, \dots, s_{l_t+f_t}) \gv F_t=f_t, Q_t=q_t).
% \end{align*}
% Given an IMM, we define the marginal likelihood of a sequence $\mathbf z = z_1z_2\dots z_L$
% as being
% \begin{align*}
%     p(S_1=z_1, \dots, S_L=z_L) = \sum\limits_{\substack{q_1..q_N \\ f_1..f_N}}
%         p(S_1=z_1, \dots, S_L=z_L, Q_1=q_1, F_1=f_1, \dots, Q_N=q_N, F_N=f_N),
% \end{align*}
% subject to $L=l_N+f_N$.\footnote{It might be a good moment to talk about degenerate IMM: when there is silent states cycle and/or
% there are states with unbounded sequence lengths.}

\begin{sidewaysfigure}[ht]
    \centering
    \includegraphics[scale=0.9]{codon-hmm-tree}
    \caption{Matched codon HMM tree.
        The $\eps$-transitions occur infrequently and exist to account for sequence errors.
        The most probably path ends at the first leaf-node from left to right.}\label{fig:codon-hmm-tree}
\end{sidewaysfigure}

\end{document}


%!TEX root = head-full.tex

\section{Partition Function Estimation} \label{sec:rbm}

\subsection{Restricted Bolztmann Machine}
Co-invented and enhanced largely\cite{hinton2006reducing} by Geoff Hinton, a Restricted Bolzmann Machine(RBM)\cite{mcclelland1987parallel} is a model which brings the idea of a physics concept to the field of computer science.

\begin{figure*}[tb]
% \vspace{-0.5in}
  	\centering
  	\includegraphics[width=1\textwidth]{figure/rbm.png}
% \vspace{-0.2in}
	\caption{A Restricted Boltzmann Machine}
	\label{fig:rbm}
\end{figure*}

\subsubsection{Introduction}
An RBM is a two-layer undirected model(Figure~\ref{fig:rbm}). The first layer of the RBM is called visible layer, and the second is called the hidden layer. In the model, every visible units are connected to all hidden units and vice versa. For every given value of visible layer $\mathbf v$ \& hidden layer $\mathbf h$, we can define an energy of this state.
\begin{equation}
E(\mathbf v,\mathbf h;\theta)=-\mathbf v^T\mathbf W\mathbf h-\mathbf b^T\mathbf v-\mathbf a^T\mathbf h
\end{equation}
where $\theta =\{W,\mathbf b,\mathbf a\}$ are the model configurations. $W_{ij}$ represents the weight between visible unit $v_{i}$ and hidden unit $h_{j}$. $\mathbf b$ \& $\mathbf a$ are biases for visible and hidden layer, respectively.

\subsubsection{Training an RBM}
On training an RBM, we want our RBM model to have a lowest scale of energy. By doing so, we have to calculate the joint distribution over the visible and hidden units, which is defined by:
\begin{equation}
	p(\mathbf v,\mathbf h;\theta)=\frac{e^{-E(\mathbf v,\mathbf h;\theta)}}{Z(\theta)}
\end{equation}
where
\begin{equation}
	Z(\theta)=\sum_{\mathbf v} \sum_{\mathbf h} e^{-E(\mathbf v,\mathbf h;\theta)}
\end{equation}
is the partition function.

However, calculating partition functions has always been an intractable work since we have to traverse all the possible state of $\mathbf v$ \& $\mathbf h$.
When the model grows large, this process will be very time \& rescouces consuming and thus become unrealistic for the real practice.

So, we have to introduce methods to estimate the partition functions instead of just calculating it in brute force. Although some deviation may include in the estimation, but the efficiency along with them make them preferable. In fact, studies have shown that only few deviation is included that we could just ignore it since it does petty influence on our training.

In the next subsection, we will discuss about three methods available, which each have their pros and cons in doing this complex estimation.

\subsection{Algorithms}

\input{TAP}
\input{AIS}
\input{RTS}

\subsubsection{Other methods}
There are many other methods which can also estimate the partition functions. Such as Self-adjusted mixture sampling(SAMS)\cite{tan2015optimally} proposed a method to estimate multiple partition functions together to improve the efficiency. As the length \& time limit, we only implement 3 methods here in this paper.

\input{numresults}

\input{theoretical}


\section{Recommendations for experimenters}
\label{sec:recommend}

We still recommend using a band-pass filter for online SWR detection -- as long as the experimenter is fine with only detecting events with a strong ripple oscillation, and not necessarily any sharp-wave.

From \cref{ch:BPF} though, it is clear that the type of band-pass filter ought to be carefully chosen. The short duration of SWR's makes it is easy to design a filter that introduces a relatively high delay (see e.g. the default ripple filter in the closed-loop neuroscience software \emph{Falcon}; \cref{fig:BPF-performance}). We find that low group-delay is a more important design consideration than sharp passband edges when designing a band-pass filter for online SWR detection. A concrete digital filter that has been shown to work well (at least at a sampling frequency of $f_s = 1000$ Hz), is a combination of an 8th order Butterworth high-pass filter, and a 2nd order Butterworth low-pass filter.


\section{Results \& Outlook}
\label{sec:outro}

The project's goals of interactively creating bifurcation diagrams using Galerkin's method and continuation methods could be met.
There are some further points of interest for similar or following projects of this type.

On a practical level, one of the things an implementation of the sort of this project might benefit from are Broyden updates.
In its basic form, the method allows to update the Jacobian of the system of equations obtained from the Galerkin operator.
Though calculating the Jacobian is a time-consuming task, this is of minor interest, as the effort is negligible compared to the effort for inverting the Jacobian, which is needed for each computation of the tangent.

One of the main sources of complications are orbits which change their direction too fast.
As is the case in the Rössler system for high values of $c$ and in the Lorenz System for low values of $\rho$. %pics
In these regions the optimization procedure converges slowly and the predictor-corrector method's step-size adaption suggests very small steps (as seen from the bifurcation view).
This is likely caused by choosing a truncated Fourier series as a model for the solution candidates.
Ringing effects as in the Gibbs phenomenon support this thesis.
This kind of model is, though natural for periodic functions, not a natural choice for sharp turning functions.
No attempts were made to investigate the definite reason for this behavior, however, choosing a model which is better adapted to these challenges might allow for more accurate results in these areas.
Furthermore, solution branches could be traced further, as these effects are a cause of stopping the tracing of solutions in the Rössler, as well as in the Lorenz system. %ref
In the case of the Rössler system this is less of a problem, as the solutions for high $c$ did not appear to reveal anything of immediate interest.
However, in the Lorenz system the behavior prohibited tracing the solutions in the $\rho < 20$ area.
It is this area, where there is a huge amount of interaction between the branches of solutions.

Modeling the trajectories as linear combinations of non-equidistant B-splines instead of complex oscillations might yield interesting results. %cite
\begin{itemize}
	\item The periodicity requirement can be enforced by choosing the basis vectors appropriately.
	\item Through adaption of the knots, the degree of smoothness can be varied to the point being $C^0$ only.
		This can be done by changing \emph{multiplicities} of knots, that is, by having several knots be equal.
		An interesting point is that this change in continuity can occur dynamically through optimizing the knot vector.
	\item Spline curves can easily be differentiated.
	\item Adding and removing control-points is possible.
		This might allow for dynamic adaption of a solution candidate, if necessary.
\end{itemize}
Chances are good, that candidate solutions modeled this way can be fit into a framework similar to the one above while at the same time gaining the ability to do non-differentiable turns.

%\begin{figure}[!h]
	%\centering
	%\makebox[0pt]{
		%\includegraphics[scale=.5]{img/1.png}
		%\includegraphics[scale=.5]{img/2.png}
		%\includegraphics[scale=.5]{img/3.png}
	%}
	%\caption{A periodic orbit in the Rössler modeled by a decreasing number of coefficients, illustrating the ringing effect.}
	%\label{fig:end}
%\end{figure}