\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bbm}
\usepackage[american]{babel}
\usepackage{verbatim}
\usepackage[pdftex,colorlinks, linkcolor=blue]{hyperref}
\newcommand{\R}{\mathbbm{R}}
\newcommand{\N}{\mathbbm{N}}
\newcommand{\Z}{\mathbbm{Z}}
\newcommand{\B}{\mathbbm{B}}
\newcommand{\Q}{\mathbbm{Q}}
\title{An Introduction to SCIP}
\author{Cornelius Schwarz \\ University of Bayreuth \\ cornelius.schwarz@uni-bayreuth.de}
\date{September 28, 2010}
\begin{document}
\maketitle

\section{Preface}

In this tutorial we give a short introduction to the constraint integer programming framework SCIP
(\underline{s}olving \underline{c}onstraint \underline{i}nteger \underline{p}rograms) which was developed
by Tobias Achterberg \cite{scip} as part of his PhD thesis. SCIP combines constraint programming and mixed
integer programming (MIP) into one framework. We will focus on the mixed integer part here.
We show how to use SCIP as a MIP solver backend using the $n$-queens example.
This introduction is currently adapted to SCIP 2.0 and will probably be extended to the development of
plugins in the future.

SCIP is free for academical use, but you will also need an LP solver. For this purpose you can use SoPlex,
which was developed by Roland Wunderling \cite{soplex} as part of his PhD thesis and is distributed under
the same conditions as SCIP. The easiest way is to download the ZIB Optimization Suite, which contains
SCIP/SoPlex and the mathematical modeling language Zimpl~\cite{zimpl}.

A good starting point for SCIP is to look at the examples bundled with the source code. As a reference you
can use the doxygen documentation, which is available online at \url{http://scip.zib.de/doc/html}.
You should start by looking at ``File List $\rightarrow$ scip.h''. Here you find the most important functions,
sorted by categories like ``Global Problem Methods'', ``Variable Methods'', ``Constraint Methods'' and so on.
Another place to look at is ``File Members $\rightarrow$ All $\rightarrow$ s. Here you also find functions like
\verb+SCIPcreateConsLinear+ which is not defined in ``scip.h'' -- since it is a plugin -- but in
``cons\_linear.h''. The most useful SCIP functions start with the prefix ``SCIP''.

\section{Using SCIP as a MIP solver backend}

In this section we show how to use SCIP as a backend for solving mixed integer programs by developing a solver
for the $n$-queens problem. We first give a brief introduction into the problem and than describe a C++ program
for solving it. The model is based on the one described in the Zimpl documentation.

\subsection{The $n$-queens problem}

The $n$-queens problem asks how to place $n$ queens on an $n \times n$ chess board in a way that no two queens interfere. In detail this means:
\begin{itemize}
\item In each vertical line of the board only one queen is allowed, we will refer to these lines as columns.
\item In each horizontal line of the board only one queen is allowed, these lines will be called rows later on.
\item In each diagonal line only one queen is allowed.
\end{itemize}
This can be modeled as a binary program in the following way: Let $x_{i,j} \in \{0,1\}$ denote whether a queen
is placed on the $i$th row and the $j$th column of the chess board. Since the problem is to find a placement,
the objective function is irrelevant. We add, however, the redundant objective to maximize the number of placed queens:
\[
\max \sum_{i=1}^n \sum_{j=1}^n x_{i,j}
\]
Now we force exactly one queen to be placed in every column and every row:
\begin{eqnarray*}
  \sum_{i=1}^n x_{i,j} & = & 1, \ j=1,\ldots,n \\
  \sum_{j=1}^n x_{i,j} & = & 1, \ i=1,\ldots,n
\end{eqnarray*}
The diagonal rows are a little bit more complicated to write up:
\begin{eqnarray*}
  \sum_{i=1}^{n-j+1} x_{i,j+i-1} & \leq & 1, \ j = 1, \ldots, n \\
  \sum_{j=1}^{n-i+1} x_{i+j-1,j} & \leq & 1, \ i = 1, \ldots, n \\
  \sum_{i=1}^{n-j+1} x_{i,n-j-i+2} & \leq & 1, \ j = 1, \ldots, n\\
  \sum_{j=1}^{n-i+1} x_{i+j-1,n-j+1} & \leq & 1, \ i = 1, \ldots, n\\
\end{eqnarray*}

\subsection{Error handling in SCIP}

Before we transform the $n$-queens IP program into a SCIP program, we first consider a general point when working with
SCIP functions: Most SCIP functions return a value of the type \verb+SCIP_RETCODE+. If this is equal to
\verb+SCIP_OKAY+, then everything went well, otherwise it indicates an error code. Therefore the normal call of a
SCIP function returning a \verb+SCIP_RETCODE+ (we use \verb+SCIPfunction+ as a generic name -- replace it with
whatever function you are calling) is
\begin{verbatim}
SCIP_RETCODE retcode;
retcode = SCIPfunction();
if (retcode != SCIP_OKAY)
{
   // do your error handling here
}
\end{verbatim}
Since this is a lot of code for every function call, SCIP provides two macros namely \verb+SCIP_CALL+ and
\verb+SCIP_CALL_ABORT+. The second one just aborts the execution by calling \verb+abort()+ if an error occured.
The first one calls the SCIP function and, in the error case, returns the retcode. This results in the following code:
\begin{verbatim}
SCIP_RETCODE myfunction(void)
{
   SCIP_CALL(SCIPfunction());
   SCIP_CALL(SCIPotherfunction());
}
int main(int args, char * argv)
{
   SCIP_RETCODE retcode = myfunction();
   if (retcode != SCIP_OKAY)
   {
      // do your error handling here
   }
}
\end{verbatim}
While this is nice for C programs, there is a problem when using \verb+SCIP_CALL+ from C++: A C++ constructor is not
allowed to return a value. The same is true for destructors. Therefore we supply a third method, the
\verb+SCIP_CALL_EXC+ macro. This behaves just like \verb+SCIP_CALL+, but instead of returning the error code it
throws an exception of a new type \verb+SCIPException+. So the example above would now be written as:
\begin{verbatim}
int main(int args, char * argv)
{
   try
   {
      SCIP_CALL_EXC(SCIPfunction());
      SCIP_CALL_EXC(SCIPotherfunction());
   } catch(SCIPException & exec)
   {
      cerr<<exec.what()<<endl;
      exit(exec.getRetcode());
   }
}
\end{verbatim}

\subsection{Include files}

For a SCIP based project there are three main header files to consider. The first and most important one is of course
``scip/scip.h''. It declares the \verb+SCIP+ pointer and all public functions. You may have noticed that SCIP can be
extended by plugins.
In fact most parts of the MIP solver like heuristics, separators, etc.\ are implemented as plugins. To use them, include
``scip/scipdefplugins.h''.

These two header files are C type. In early versions of SCIP it was necessary to wrap them in an \verb+extern "C"+
statement. As of version 1.1 SCIP now detects a C++ compiler and adds \verb+extern "C"+ own its own.

The last header file to consider is ``objscip/objscip.h'' if you want to use the C++ wrapper classes distributed  with
SCIP. For the queens example we do not develop own plugins, so we just use
\begin{verbatim}
#include <scip/scip.h>
#include <scip/scipdefplugins.h>
\end{verbatim}

\subsection{Developing a queens solver}

When you use SCIP you have to do the following steps:
\begin{itemize}
\item initialize the SCIP environment
\item load all desired plugins (including your own, if you like)
\item create a problem
\item add variables and constraints to the problem
\item solve the problem
\item access results
\item free the SCIP environment
\end{itemize}
You can of course cycle through some of these steps like accessing the results, modifying the problem and
solving again. We will now describe these steps in more detail for the queens solver.

\subsubsection{Initializing the SCIP environment}

In this section, we start developing our queens solver. Before you can do anything with SCIP, you have to
create a valid \verb+SCIP+ pointer. For this purpose use the \verb+SCIPcreate+ function:
\begin{verbatim}
SCIP* scip;
SCIP_CALL_EXC(SCIPcreate(& scip));
\end{verbatim}

\subsubsection{Loading all desired plugins}

After we created our \verb+SCIP+ pointer we load the plugins. In SCIP nearly everything is a plugin:
heuristics, separators, constraint handlers, etc. Whenever you want to use one you first have to include
it. This is done by various \verb+SCIPinclude+ functions like \verb+SCIPincludeHeur+ for heuristics
or \verb+SCIPincludeConshdlr+ for constraint handlers. This also activates the default display plugins
which writes various messages to standard output. (If you do not like this you can disable it by a call of
\verb+SCIPsetMessagehdlr(NULL)+.) All together we get:
\begin{verbatim}
SCIP_CALL_EXC(SCIPincludeDefaultPlugins(scip));
// SCIP_CALL_EXC(SCIPsetMessagehdlr(NULL);
// uncomment the above line to disable output
\end{verbatim}

\subsubsection{Creating a problem}

Now we can create the IP model for the queens solver in SCIP. First we create an empty problem with
\verb+SCIPcreateProb+. The first argument is our \verb+SCIP+ pointer and the second is the name
of the problem. You can also supply user specific problem data and call back functions to handle them,
but normally you will not need them and can safely set them to \verb+NULL+:
\begin{verbatim}
SCIP_CALL_EXC(SCIPcreateProb(scip, "queens", NULL, NULL,
                             NULL, NULL, NULL, NULL, NULL));
\end{verbatim}
The default objective sense for SCIP problems is minimizing. Since we have a maximization problem we have to change this:
\begin{verbatim}
SCIP_CALL_EXC(SCIPsetObjsense(scip, SCIP_OBJSENSE_MAXIMIZE));
\end{verbatim}

\subsubsection{Creating variables}

Now it is time to fill the empty problem with information. We start by creating variables, one binary variable for every
field on the chess board. Variables are accessed through the type \verb+SCIP_VAR*+. Associated with each variable is a
type (continuous, integer, or binary), lower and upper bound and a objective. In our case, the type is binary for all
variables, the lower bound is naturally 0, the upper bound 1, and the objective is 1 for all variables:
\begin{verbatim}
SCIP_VAR* var;
SCIP_CALL_EXC(SCIPcreateVar(scip, & var, "x#i#j", 0.0, 1.0, 1.0,
                            SCIP_VARTYPE_BINARY, TRUE, FALSE,
                            NULL, NULL, NULL, NULL, NULL));
\end{verbatim}
Here, you should replace $i$ and $j$ by the actually row and column number of the variable. The fourth argument is the
lower bound, the fifth the upper bound, the sixth the objective, and the seventh the type. After that you specify two
boolean parameters indicating whether this variable is in the initial (root) LP and whether it is allowed to be removed
during aging. Like in \verb+SCIPcreateProb+ you can use the last five parameters to specify user data. We set these
parameters to \verb+NULL+. After creating the \verb+SCIP_VAR+ pointer it is time to add it to the SCIP problem:
\begin{verbatim}
SCIP_CALL_EXC(SCIPaddVar(scip, var));
\end{verbatim}
You should store the \verb+SCIP_VAR+ pointers somewhere, since you will need them to add the variables to constraints and to access their values in the final solution and so on. In our example, you can use a two dimensional STL vector for that purpose.

\subsubsection{Creating constraints}

Creating and adding variables is just half of the battle. To ensure feasibility, we have to add the constraints we described above. To create a constraint in SCIP you first need to specify a constraint handler. The constraint handler is responsible for checking feasibility, tighten variable bounds, adding new rows to the underlying LP problem and so on. The creating method depends on the actual constraint you want to use and is  usually called \verb+SCIPcreateConsName+ -- for instance \verb+SCIPcreateConsLinear+. Although there are many different default constraints like knapsack, logic-OR, etc., it is a safe way to create them as linear constraints. The presolver will automatically transform them to the right constraint type. We will therefore add all our constraints as type linear and describe the handler here.

The linear constraint handler handles constraint of the following type:
\[
lhs \leq a^T x \leq rhs
\]
There are three special cases of these: For equality constraints set $lhs = rhs$, for lesser equal constraints, set $lhs = -$\verb+SCIPinfinity(scip)+ and for greater equal constraints $rhs = $~\verb+SCIPinfinity(scip)+. So the creating of the diagonal constraints looks as follows:
\begin{verbatim}
SCIP_CONS* cons;
SCIP_CALL_EXC(SCIPcreateConsLinear(scip, & cons, "diag",
                                   0, NULL, NULL, 0, 1.0, TRUE,
                                   TRUE, TRUE, TRUE, TRUE, FALSE,
                                   FALSE, FALSE, FALSE, FALSE);
\end{verbatim}
The first is, as usual, the \verb+SCIP+ pointer and the second the \verb+SCIP_CONS+ pointer, which allows to access the constraint later. After that you can specify variables to be added to the constraint. This could be done by specifying the number, an array of \verb+SCIP_VAR+ pointers to variables, and an array of values of the coefficients, stored as doubles. We skip the adding at this point and use the function \verb+SCIPaddCoefLinear+ described later on. The next two entries are $lhs$ and $rhs$. In our cases 0 and 1. Then you specify the following parameters:
\begin{description}
\item[initial] set this to \verb+TRUE+ if you want the constraint to occur in the root problem
\item[separate] set this to \verb+TRUE+ if you would like the handler to separate, e.\,g.\ generate cuts
\item[enforce] set this to \verb+TRUE+ if you would  like the handler to enforce solutions. This means that when the handler declares an LP or pseudo solution as infeasible, it can resolve infeasibility by adding cuts, reducing the domain of a variable, performing a branching, etc.
\item[check] set this to \verb+TRUE+ if the constraint handler should check solutions
\item[propagate] set this to \verb+TRUE+ if you want to propagate solutions, this means tighten variables domains based on constraint information
\item[local] set this to \verb+TRUE+ if the constraint is only locally valid, e.\,g., generated in a branch and bound node
\item[modifiable] set this to \verb+TRUE+ if the constraint may be modified during solution process,  e.\,g.\ new variables may be added (colum generation)
\item[dynamic] set this to \verb+TRUE+ if this constraint is subject to aging, this means it will be removed after being inactive for a while (you should also say \verb+TRUE+ to removable in that  case)
\item[removable] set this to \verb+TRUE+ to allow the deletion of the relaxation of the  constraint from the LP
\item[stickingatnode] set this to \verb+TRUE+ if you want the constraint to be kept at the node it was added
\end{description}

Variables which are not added at the creation time of the constraint can be added by calling:
\begin{verbatim}
SCIP_CALL_EXC(SCIPaddCoefLinear(scip, cons, var, 1.0));
\end{verbatim}
Here ``1.0'' is the matrix coefficient.

\subsubsection{Solving the problem}

When the problem is setup completely we can solve it. This is done by
\begin{verbatim}
SCIP_CALL_EXC(SCIPsolve(scip));
\end{verbatim}
SCIP then starts transforming and preprocessing the problem. After that it enters the solving stage where the root LP is solved, heuristics are run, cuts are generated, and the branching process starts. All plugins you wrote (heuristics, separators,  etc.) will be called by SCIP through call back functions in this stage.

\subsubsection{Accessing results}

Now that the problem is solved, we want to know the solution data. Whether the problem has been solved to optimality, only feasible solutions were found, and so on, can be queried by \verb+SCIPgetStatus+. We ignore this in our queens solver and start with the best solution found so far. This can be accessed by
\begin{verbatim}
SCIP_SOL* sol = SCIPgetBestSol(scip);
\end{verbatim}
If SCIP did not find a solution \verb+sol+ is equal to \verb+0+. Otherwise, you can get the objective value by \verb+SCIPgetSolOrigObj+. In the queens example we want to know whether a queen is placed on a field or not. Therefore we need the value of the variable $x_{i,j}$ which can be accessed by \verb+SCIPgetSolVal+. In the case of an integer or binary variable, care must be taken, because this functions returns double values. So if we want to query a binary variable we use the following:
\begin{verbatim}
if (sol == NULL)
{
   // output error message here and abort
}
if ( SCIPgetSolVal(scip, sol, var) > 0.5 )
{
   // value is one
}
else
{
   // value is zero
}
\end{verbatim}
In this example, we of course use the knowledge that variables have 0/1 values only. There are special SCIP functions for performing numerical comparisons between values that are not known to be integer. For instance, you can use \verb+SCIPisFeasEQ(scip, x, y)+ for comparing whether $x$ is equal to $y$ within the feasibility tolerance of SCIP. This macro return true if $|x - y| < \epsilon$, where $\epsilon$ is the feasibility tolerance of SCIP (by default $\epsilon = 10^{-6}$).

\subsubsection{Freeing the SCIP environment}

Finally, we must free all the memory SCIP used. When we created the variables and constraints, the \verb+SCIPcreateVar+ and \verb+SCIPcreateCons+ captured the corresponding variables and constraints. This means that SCIP knows that we have a pointer to these and will only free the memory if we tell it that we do not need these pointers anymore. This is done by the \verb+SCIPrelease+ functions.  So before we can free the \verb+SCIP+ pointer, we have to call:
\begin{verbatim}
SCIP_CALL_EXC(SCIPreleaseVar(scip, & var);
SCIP_CALL_EXC(SCIPreleaseCons(scip, & cons);
\end{verbatim}
Then we close the SCIP environment:
\begin{verbatim}
SCIP_CALL_EXC(SCIPfree(& scip));
\end{verbatim}

\begin{thebibliography}{99}
\bibitem{scip} Achterberg, Tobias: \emph{Constraint Integer Programming}, PhD thesis, Technische Universit\"at Berlin, 2007
\bibitem{soplex} Wunderling, Roland: \emph{Paralleler und Objektorientierter Simplex-Algorithmus}, PhD thesis, Technische Universit\"at Berlin, 1996
\bibitem{zimpl} Koch, Thorsten: \emph{Rapid Mathematical Programming}, PhD thesis, Technische Universit\"at Berlin, 2004
\end{thebibliography}
\end{document}


\documentclass[10pt,reqno]{beamer}
\usepackage[utf8]{inputenc}
\usetheme{Dresden}
\usecolortheme{beaver}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{stmaryrd}
\usepackage{siunitx}
\usepackage{subcaption}
\usepackage[backend=biber, style=chem-acs]{biblatex}
\setbeamertemplate{navigation symbols}{}
\title{Bond Graph Clinic: Part 3}
\subtitle{Biomolecular Systems}
\author{Peter Cudmore}

\institute{Systems Biology Lab, The University of Melbourne}

\newcommand{\D}[2]{\frac{\mathrm{d} #1}{\mathrm{d} #2}}
\newcommand{\e}{\mathrm{e}}
\newcommand{\I}{\mathrm{i}}
\renewcommand{\mod}[1]{\left|#1\right|}
\newcommand{\DD}[2]{\frac{\mathrm{d}^2 #1}{\mathrm{d} #2^2}}
\newcommand{\bigO}[1]{\text{O}\left(#1\right)}
\renewcommand{\P}[2]{\frac{\partial #1}{\partial #2}}
\renewcommand{\Re}{\operatorname{Re}}
\renewcommand{\Im}{\operatorname{Im}}
\newcommand{\EX}{\mathbb{E}}
\newcommand{\df}[1]{\mspace{2mu}  \mathrm{d}#1}
\newcommand{\reals}{\mathbb{R}}
\newcommand{\complex}{\mathbb{C}}
\newcommand{\conj}[1]{\overline{#1}}
\bibliography{references}

\begin{document}
	\begin{frame}
	\titlepage
	\addtocounter{framenumber}{-1}
\end{frame}
\begin{frame}
\tableofcontents[hideallsubsections]
\end{frame}
\section{Introduction}
\subsection{Previously...}
\begin{frame}
\frametitle{Network models of energetic systems}
\begin{figure}
	\includegraphics{images/bondgraph.pdf}
\end{figure}
Bond Graphs capture:
\begin{itemize}
	\item Energy transferred between $B,C,D$ without loss via bonds.
	\item Power transfer represented by conjugate variables $P_i=e_if_i$.
	\item Subsystem dynamics via constitutive relations $\Phi_B(e,f) = 0$
\end{itemize}
We've also looked at some examples.
\end{frame}
\begin{frame}
\frametitle{A Mathematicians Model of a Chemical System}
A naive description of molecular systems is as follows:
\begin{enumerate}
	\item A set of distinct quanta (molecules, complexes, atoms and free electrons) $A, B, \ldots$ move stochastically through a volume.
	\item When $A, B$ are sufficiently close they may bind to form complex $C$.
	\item After some time $\tau$, $C$ may disassociate into a number of quanta $E, \ldots$.
\end{enumerate}
All basic reaction types (synthesis, decomposition and replacement) can be represented in this way.\\
\vspace*{10pt}
Clearly this is an example of a \emph{reaction-diffusion} process.
\end{frame}
\subsection{Today}
\begin{frame}
\frametitle{This Clinic}
Today we shall consider \emph{reactions}.
\vfill

Next clinic will consider \emph{diffusion}.

\vfill

%For more details to Oster, Perelson and Auslander \cite{Oster:1971aa, Oster:1971ab, Oster:1973aa, Oster:1974aa, Perelson:1974, Auslander:1972aa}
\end{frame}
\begin{frame}
\frametitle{Spatial Assumptions}
Consider chemical reactions inside some vessel of fixed volume.\\
We assume that the chemical solution is well mixed, ie:
\begin{itemize}
	\item The solution is actively stirred or,
	\item the diffusion rate across the volume is orders of magnitude faster than the fastest reaction rate.
\end{itemize}
\vfill
This basically means we can work with average concentration, and ignore spatial effects inside the vessel.
\vfill
Later, we will couple many vessels together to represent diffusion.
\end{frame}
\section{Chemical Reactions}
\subsection{Chemical Reaction Networks}
\begin{frame}
\frametitle{Chemical Reaction Network: Petri Net}
\begin{figure}
	\includegraphics{images/petrinet_abc}
	\caption{Petri net of $A+B \rightleftharpoons C$}
\end{figure}
\end{frame}
\begin{frame}
\frametitle{Chemical Reaction Network: Bond Graph}
\begin{figure}
	\includegraphics{images/bondgraph_abc}
	\caption{Bond Graph of $A+B \rightleftharpoons C$}
\end{figure}
\end{frame}

\begin{frame}
\frametitle{Thermodynamic Assumptions}
Consider chemical reactions inside some vessel of fixed volume.\\
We assume that the solution is \emph{isobaric} and \emph{isothermic}.
These assumptions allow us to define the chemical potential
\[
\mu_A = \mu_A^\varoslash + RT\ln \frac{x_A}{V_m}
\]
\only<1>{
\begin{itemize}
	\item $R=N_Ak_b\approx 8.314$ is the gas constant in \si{\joule\per\kelvin\per\mole}
	\item $T\approx 300$ is temperature (in \si{\kelvin})
	\item $\mu_A^\varoslash$ is the chemical potential of a pure solution of $A$ in \si{\joule}
	\item $x_A$ the amount of species $A$ in \si{\mole}.
	\item $V_m$ is volume of the solution in \si{\mole}
\end{itemize}
This follows from the \emph{Ideal Gas Law} and the \emph{Fundamental Equation of Thermodynamics}.
}
\only<2>{
\begin{align*}
\text{Energy}&=x_A \cdot \mu_A \si{\joule} \\
\text{Power}&=\dot{x}_A\cdot \mu_A\ \si{\joule\per\second}
\end{align*}
\begin{center}
$\mu_A$ is \emph{effort} or force-like \\
\vspace{10pt}
$\dot{x}_A$ is the \emph{flow} or flux-like.
\end{center}
\vfill
}

\only<3>{
Recall $x_A$ is the molar amount of species $A$.\\
\vfill
Question:\\
What happens to $\mu_A$ when $x_A \rightarrow 0$ but $V_m$ is constant?\\
When might this occur and is this physical?
}
\end{frame}
\subsection{Components}
\begin{frame}
\frametitle{Ce Constitutive Relation}
\begin{figure}
	\includegraphics{images/oneport-Ce.pdf}
\end{figure}
Constitutive Relation for a Chemical Species:
\[
\Phi_{Ce}(e,f) = e - \beta \ln kq = 0
\]
\vfill
\only<2>{
This follow from substituting the parameters
\[
k = \exp(\mu_A^\varoslash/RT)/V_m,\qquad \beta = RT
\]
and the state variables $\mu_A = e$, $\dot{x}_A = f$ and $x_A = q  = q_0 + \int_0^t f\df{t} $ into
\[
\mu_A = \mu_A^\varoslash + RT\ln \frac{x_A}{V_m}.
\]}
\only<3>{
\[
\beta = RT, \qquad k = \exp(\mu_A^\varoslash/\beta)/V_m
\]
\vfill
\begin{center}
\emph{It will often be convenient for us to take $\beta =1$}
\end{center}
}
\end{frame}
\begin{frame}
\frametitle{Chemical Kinetics}
Reactions proceed according to the \emph{Marcelin-de Donder} formula
\[
v = \kappa\left(\e^{A^f/RT} - \e^{A^r/RT}\right)
\]
\only<1>{Here:
\begin{itemize}
	\item $v$ is the reaction velocity or molar flow
	\item $A^f, A^r$ are the forward and reverse chemical affinities
	\item $\kappa$ is the reaction rate constant.
	\item $R,T$ is the gas constant and temperature respectively.
\end{itemize}}
\only<2>{

The mass flow in is $v$, hence the mass flow out is $-v$.\\
\vspace{10pt}
So
\[
f_1 = v,\qquad f_2 = -v
\]
are natural \emph{flow} variables.

}
\only<3>{

For a chemical reaction $\nu^f_AA + \nu^f_BB +\ldots \rightleftharpoons \nu^f_AA + \nu^f_BB +\ldots$ with forward and reverse stoichiometric coefficients $\nu^f$ and $\nu^r$.\\
\vfill
The forward (and similarly reverse) affinity is defined as
\[
A^f = \nu^f_A\mu_A + \nu^f_B\mu_B +\ldots
\]
So the natural effort variables are
\[
e_1 =  A^f, \qquad e_2 = A^r.
\]
}
\end{frame}
\begin{frame}
\frametitle{Re Constitutive Relation}
\begin{figure}
	\includegraphics{images/twoport-Re.pdf}
\end{figure}
Constitutive Relation for a reaction component:
\[
\Phi_{Re}(\mathbf{e},\mathbf{f}) = \left(
\begin{matrix}
\kappa[\exp(\e_1/\beta) - \exp(\e_2/\beta)] - f_1\\
f_1 + f_2
\end{matrix}
\right) = 0
\]
\vfill
\only<1>{
Where again $\beta =RT$ is often taken as $\beta =1$.
}
\only<2>{
This follows directly from the Marcelin-de Donder formula.
}
\end{frame}
\begin{frame}
\frametitle{Putting it together}
\begin{figure}
	\includegraphics{images/bondgraph_ab}
\end{figure}
{\scriptsize
The above bond graph describes the reaction $A\rightleftharpoons B$.

\begin{minipage}{0.475\linewidth}
\begin{align}
\Phi_{Ce:A} &= e_1 - \ln k_A\left[q_A(0)  + \int(- f_1)\df{t}\right]\\
\Phi_{Ce:B} &= e_2 - \ln k_B\left[q_B(0)  + \int f_2\df{t}\right]
\end{align}
\end{minipage}\hfill
\begin{minipage}{0.475\linewidth}
\begin{align}
\Phi_{Re}(\mathbf{e},\mathbf{f}) &= \left(
\begin{matrix}
\kappa\left[\e^{e_1} - \e^{e_2}\right] - f_1\\
f_1 +(- f_2)
\end{matrix}
\right)
\end{align}
\end{minipage}
\vspace{11pt}

Recall that $q(t) = q_0 + \int_0^t f(t)\df{t}$. So define
\begin{align*}
\dot{x}_A  = \dot{q_1} &= -f_1 &\implies&& q_1 &= q_A(0) -\int_0^t f_1 \df{t} &\implies &&\e^{e_1} &= k_Aq_1, \\
\dot{x}_B = \dot{q_2} &= f_2 &\implies&& q_2 &= q_B(0) +\int_0^t f_2 \df{t} &\implies &&\e^{e_2} &= k_Bq_2.
\end{align*}

The second line of (3) gives $f_1 = f_2$ which implies $-\dot{q_1} = \dot{q_2}$, and the first gives the result
\[
\dot{q_1} = - \kappa\left(k_Aq_1 - k_Bq_2\right) = k_-q_2 - k_+q_1 \quad \text{where}\quad k_+ = \kappa k_A,\ k_- =\kappa k_B.
\]

}
\end{frame}

\section{Stoichiometry}
\begin{frame}
\frametitle{Complexes}
The reaction $A + B \rightleftharpoons C$ can be though of
\begin{enumerate}
	\item $A$ and $B$ collide forming a complex $AB$.
	\item $AB$ reacts to form $C$.
\end{enumerate}
\vfill

Clearly, the flow of $A$ and the flow of $B$ into this reaction are equal.
\vfill

Hence, we \emph{should} be able to represent the $AB$ complex as a equal flow junction, and allow the reaction to drive what that flow is.
\end{frame}

\begin{frame}
\frametitle{Revisiting the '1' junction}
\begin{figure}
\includegraphics{images/nport-1}
\end{figure}
\only<1>{
In clinic 2 we introduced the '1' junction and argued that it's constitutive relation is given by
\[
\Phi_\text{1} = \left(\begin{matrix}
f_1 -f_2\\
\ldots\\
f_{j-1} - f_j\\
e_1 + e_2 + \ldots + e_j
\end{matrix}\right) = 0
\]}
\only<2-3>{
Alternatively
\[
f_i =f_j \qquad \forall i,j
\]
and \[
\sum_i e_i = 0
\]}
\only<3>{This deviates from the literature and may cause problems\\
(thanks to Peter Gawthrop for pointing this out.).}
\end{frame}
\begin{frame}
\frametitle{Revisiting the '1' junction}
\begin{figure}
	\includegraphics{images/nport-1a}
\end{figure}
\only<1>{
To fix this, we must instead think of the 1 junction as having two ends (call the sets $\iota$ and $\omega$) so that all flows at $\iota$ are equal, all flows at $\omega$ are equal, and any flow at $\omega$ is in the opposite direction to any other at $\iota$.
\vfill
We can then define:
\[
\sigma_k = \begin{cases}
1 &\text{if}\quad  k \in \iota,\\
-1 &\text{if}\quad k \in \omega.
\end{cases}
\]}
\only<2>{
The redefined constitutive relation then becomes
\[
\Phi_\text{1} = \left(\begin{matrix}
\sigma_1f_1 -\sigma_2f_2\\
\ldots\\
\sigma_{j-1}f_{j-1} - \sigma_{j}f_j\\
\sum_{k=1}^j \sigma_ke_k
\end{matrix}\right) = 0,
\qquad
\sigma_k = \begin{cases}
1 &\text{if}\quad  k \in \iota,\\
-1 &\text{if}\quad k \in \omega.
\end{cases}
\]}
\only<3>{
This is equivalent to the following bond graph
\begin{figure}
	\includegraphics[scale=0.5]{images/nport-1b}
\end{figure}
\[
\text{Where} \qquad \Phi_\text{1*} = \left(\begin{matrix}
f_1 -f_2\\
\ldots\\
f_{j-1} - f_j\\
e_1 + e_2 + \ldots + e_j
\end{matrix}\right)\qquad \text{as before.}
\]}
\only<4>{
	The relations can be simplified by associating the direction of a connecting bond with $\sigma$, ie; bond pointing out implies $\sigma = -1$.
	\[
	\Phi_\text{1} = \left(\begin{matrix}
	\sigma_1f_1 -\sigma_2f_2\\
	\ldots\\
	\sigma_{j-1}f_{j-1} - \sigma_{j}f_j\\
	\sum_{k=1}^j \sigma_ke_k
	\end{matrix}\right) = 0,
	\qquad
	\sigma_k = \begin{cases}
	1 &\text{if connecting bond points in},\\
	-1 &\text{if connecting bond points out}.
	\end{cases}
	\]
This is standard practice, but this means that the $1$ component needs to know what it's connected to.
}
\end{frame}

\subsection{Reaction Bond Graphs}
\begin{frame}

\frametitle{$A+B\rightleftharpoons C$}
{\scriptsize
	\begin{figure}
		\includegraphics[scale=0.5]{images/bondgraph_abc_naive}
		\caption{Bond Graph of $A+B \rightleftharpoons C$}
	\end{figure}
	\begin{minipage}{0.475\textwidth}
		\begin{align}
		\Phi_{Ce:A} &= e_1 - \ln k_A(q_1),\\
		\Phi_{Ce:B} &= e_2 - \ln k_B(q_2),\\
		\Phi_{Ce:C} &= e_4 - \ln k_C(q_4)
		\end{align}
	\end{minipage}
	\begin{minipage}{0.475\textwidth}
		\begin{align}\Phi_{Re} &= \left(
		\begin{matrix}
		\kappa\left[\e^{e_3} - \e^{e_4}\right] - f_3\\
		f_3 + (- f_4)
		\end{matrix}
		\right),\\
		\Phi_{1} &= \left(\begin{matrix}
		e_1 +e_1 - e_3 \\
		f_1 - f_3\\
		f_2 - f_3\\
		\end{matrix}\right)
		\end{align}
	\end{minipage}

	\vfill
	Clearly
	\[
	e_3 = e_1 + e_2 \implies \exp(e_3) = \exp(\ln k_A q_1 + \ln k_Bq_2) = k_Ak_B q_1q_2.
	\]
	Since $f_4 = \dot{q_4}$,  it follows from (12) that
	\[
	\dot{q_4} =  \kappa k_Ak_B q_1q_2 - \kappa k_C q_4 = k_+q_1q_2 - k_-q_4.
	\]
	From (12) and (13) we have $\dot{q_4} = f_4 =f_3= f_2 = f_1$.\\
	Combining this with $f_1 = -\dot{q_1} $ and $f_2 = -\dot{q_2}$ completes the picture.
}
\end{frame}

\begin{frame}
\frametitle{Stoichiometric Coefficients}
Transformers can be used to introduce stoichiometry (see \cite{Oster:1973aa} and \cite{Gawthrop:2014aa})
\begin{figure}
	\includegraphics[scale=0.5]{images/stoic_oster}
\end{figure}
Here $n_1$ and $n_2$ represent the stoichiometric coefficients, and the $\circ$ on identifies the transformer primary winding.\\
Hence, the reaction forward affinity is given by
\[
e_o = n_1\mu_1 + n_2 \mu_2
\]
and the flow rates
\[
\nu_1 = n_1f_0,\qquad \nu_2 = n_2f_0
\]
are in terms of the reaction flow $f_0$ as expected.
\end{frame}
\begin{frame}{Complexes}
\begin{center}
	\begin{figure}
		\includegraphics[scale=0.6]{images/stoic_oster_Y}
	\end{figure}
can be replaced by
\end{center}
\begin{figure}
\only<1>{
\includegraphics[scale=0.6]{images/stoic_Ya}}
\only<2>{
	\includegraphics[scale=0.6]{images/stoic_Ya}}
\end{figure}
\only<1>{Here $[c]$ identifies the port associated with the complex. The ports $[n_1]$ and $[n_2]$ capture the stoichiometric coefficients.}
\only<2>{
Instead of defining a port $[c]$, we could require the `complex' port always be pointing `out'; and the rest inwards. We would however still need some way to specify $n_1$ and $n_2$}
\end{frame}
\begin{frame}
\frametitle{Complexes II}
\begin{minipage}{0.58\textwidth}
\begin{figure}
	\includegraphics{images/stoic_Ya}
\end{figure}
\end{minipage}
\begin{minipage}{0.38\textwidth}
Constitutive Relation:
\[
\Phi_{Y} = \left(\begin{matrix}
e_r - \sum n_ie_i \\
f_r + \frac{f_1}{n_1}\\
\vdots
\end{matrix}\right)
\]
\end{minipage}

\vspace{20pt}

$\text{Y}$ is power conserving. Multiplying the top line by $f_r$ gives
\[
0 = e_r f_r - f_r\sum e_i n_i  =e_r f_r - \sum e_i (n_if_r)
\]
Since $n_if_r = -f_i$, the result follows from
\[
0 = e_r f_r - \sum e_i (n_if_r) = e_rf_r + \sum e_if_i.
\]
This is no surprise as $\text{Y}$ is built from conserving components.

\end{frame}
\begin{frame}
\frametitle{$A+B\rightleftharpoons C$: final form!}
\begin{figure}
	\includegraphics[scale=0.75]{images/bondgraph_abc}
	\caption{Bond Graph of $A+B \rightleftharpoons C$}
\end{figure}
In the above figure we have added standard 0 junctions. While this is redundant in this above reaction, it allows us to use the same species for many reactions.
Also, note that $\text{Y:C}$ is the identity (\emph{prove it!}) and may be omitted.
\end{frame}
\section{Conclusion}
\begin{frame}
\frametitle{In Review}
\begin{figure}
	\includegraphics[scale=0.75]{images/bondgraph_abc}
	\caption{Bond Graph of $A+B \rightleftharpoons C$}
\end{figure}
\only<1>{
The $\text{Ce}$ is a one port component representing a store of a particular chemical species and has a constitutive relation that captures the usual definition of \emph{chemical potential energy}.
}
\only<2>{
The zero junctions allow species A B and C to be shared across reactions other than the one modelled in this graph.
}
\only<3>{
The $\text{Y}$ component is a power conserving flow junction, which captures the forward (in the case of $\text{Y:AB}$) and reverse stoichiometry of this reaction.
}
\only<4>{
The $\text{Re}$ component models how the complex $A+B$ transmutes into $C$. The reaction proceeds according to the \emph{Marcelin-de Donder} formula.
}
\end{frame}

\begin{frame}
\frametitle{Try for yourself}
Try drawing bond graphs of these common reactions:
\begin{itemize}
	\item $A+2B \rightleftharpoons 2D+C$
	\item $A+B \rightleftharpoons B+C$
	\item $E + S \rightleftharpoons ES \rightleftharpoons E+P$
\end{itemize}
\vfill
{\scriptsize
	\begin{minipage}{0.475\textwidth}
		\begin{align*}
		\Phi_{Ce}(e,f) &= e - \ln k(q),\\
		\Phi_{Re}(e_f,f_f,e_r,f_r) &= \left(
		\begin{matrix}
		\kappa\left[\e^{e_f} - \e^{e_r}\right] - f_f\\
		f_f +  f_r
		\end{matrix}
		\right)\\
		\Phi_{Y}(e_0,f_0, e_1,f_1,\ldots) &= \left(\begin{matrix}
		e_0 - \sum n_ie_i \\
		f_0 + f_i/n_i\\
		\vdots
		\end{matrix}\right)
		\end{align*}
	\end{minipage}
\begin{minipage}{0.475\textwidth}
	\raggedright
	\begin{figure}
	\includegraphics[width=0.75\linewidth]{images/bondgraph_abc}
	\end{figure}
\end{minipage}}
\end{frame}
\begin{frame}
\frametitle{Points For Future Discussion}
\begin{itemize}
	\item Bond graphic PDEs.
	\item Component/Port centric vs bond centric modelling.
	\item Notation conventions for wider adoption.
	\item Parameters as random variables.
	\item Stochastic bond graphs: Johnson–Nyquist noise and probabilistic reactions.
	\item Bond graph software.
	\item Applications in cardiac physiology, bionics, synthetic biology (particularly metabolic engineering) and neuroscience.
\end{itemize}
Please suggest more!
\end{frame}
\begin{frame}
\frametitle{References}
\printbibliography
\end{frame}

\end{document}


\section{Results of the Extended Model}

I simulate 200.000 households using the optimal $\beta_L = 24.49$. Using the simulations a counter factual analysis of households that do get children, compared to households that do not can be made. Figure \ref{fig:ext_model_working_hours} shows the average number of working hours of the simulations compared to the empirical number of hours worked by women. This extended model fits the data considerably better than the simple model, as shown in figure \ref{fig:dqi_model1_average_path_sim_vs_empirical}. Again the models also differ in the action space, where this extended model do not allow for working more than 37 hours a week. The average number of hours worked is conditional on the supplied number of hours working must be above 0. The figure also shows the average number of hours supplied by women when they get children at their specific age. This is true for age 25, 30 and age 35. These households get one child and only one child, where I do not condition on $H>0$. Looking to these households steep dips in the supplied number of hours are present, at about 5 hours for each of the three age groups. The cohorts of households that get a child at age 30 and 35 year dip to a permanently lower number of supplied hours, whereas the cohort that get a child at age 25, get an initial dip, but readjust after a certain period. For all three cohorts the initial dip, the households experience, has a magnitude of about 5 hours.

\begin{figure}
    \centering
    \includegraphics[scale=0.4]{figures/extended_model_average_hours.png}
    \caption{Extended Model Working Hours - Empirical Vs. Simulated}
    \label{fig:ext_model_working_hours}
\end{figure}

Figure \ref{fig:ext_model_particpation_rates} shows the participation rate over the life cycle. The average participation of all simulations is $81.7 \%$ letting the overall number of women out of the workforce be equal to $18.3 \%$. Comparing to the number used for the estimation of $\beta_L$, which was $15 \%$, the results must be considered a good fit. I have not found good data from Statistics Denmark showing women's average participation rate over the life cycle, implying it is hard to make inference over the participation rate over the life cycle, however, a couple of things can be noted. First and foremost the simulations show a downward sloping trend of participation rates over the life cycle. \textcite{grimm_labour_2001} have investigated female labour participation rate in France over the life cycle. The data  they present suggests this picture is not entirely unrealistic. One thing should be noted about the comparison. Their sample ends in 1998, and looking to that data, the downward sloping trend do seem to be less pronounced comparing to earlier generations. I have shown four different cohorts in the same figure. As before I have focused on families getting 0 children, a cohort of households getting a child at age 25, a cohort of households getting a child at age 30, and lastly a cohort of households getting their first and only child at age 35. The picture is clear, when the child is born, it has a very strong effect on participation rate. Households getting a child at age 25, do seem to have a penalty of 30 percent reduction in participation rate for the next five years. Families getting their child at age 30 experience a reduction in participation rate slightly below 20 percent, and at last the cohort of households getting a child at age 35 experience a reduction in participation rate at around 10 percent.

\begin{figure}
    \centering
    \includegraphics[scale=0.4]{figures/extended_model_participation_rates.png}
    \caption{Participation rates}
    \label{fig:ext_model_particpation_rates}
\end{figure}

Figure \ref{fig:ext_model_impact_earnings_hours} and \ref{fig:ext_model_impact_participation_wage} displays event graphs of households getting a (single) child at different ages. These are compared against the women of households that do not get children. These event graphs compares to the event graphs by \textcite{kleven_children_2019}, however there are a couple of differences. \textcite{kleven_children_2019} considers the husband of the household as benchmark whereas I consider women of households with no children the benchmark. The husband of the household, in this model, is considered to follow a deterministic path, and household heterogeneity only comes from the different choices of the woman of the household, letting this be a more natural comparison for this model. Comparing the results, even though the benchmarks do diverge, does lead to surprisingly similar conclusions. First notice that the earnings do seem to have the largest reduction for households that get children at an early age. The same goes for hours worked, participation rates and wage rates. Secondly the long run penalties do converge to approximately the same levels. Table \ref{tab:extended_results} lists the different long run penalties compared to \textcite{kleven_children_2019}. Comparing the long run penalties, this analysis find 5 percentage points lower long run penalties for earnings, 10 percentage points higher penalty for hours works, 8 percentage points higher penalties for participation rates and 14 percentage points lower penalty for wage rates in this model than the results found by \textcite{kleven_children_2019}.

\begin{figure}[ht]
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{figures/extended_model_event_earnings.png}
  \caption{Earnings}
  \label{fig:ext_model_event_earnings}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{figures/extended_model_event_hours_worked.png}
  \caption{Hours Worked}
  \label{fig:ext_model_event_hours}
\end{subfigure}
    \caption{Impact of Children (Earnings and Worked Hours)}
    \label{fig:ext_model_impact_earnings_hours}
\end{figure}

\begin{figure}[ht]
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{figures/extended_model_event_participation_rates.png}
  \caption{Participation Rates}
  \label{fig:ext_model_event_partipation}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{figures/extended_model_event_wage_rates.png}
  \caption{Wage Rates}
  \label{fig:ext_model_event_wage_rates}
\end{subfigure}
    \caption{Impact of Children (Participation Rates and Wage Rates)}
    \label{fig:ext_model_impact_participation_wage}
\end{figure}

\textcite{kleven_children_2019} writes, that the event graphs they present of wage rates and hours worked is conditional on labour market participation. Figure \ref{fig:ext_model_impact_alt} shows comparable event graphs of the simulations. Here I find the reverse picture, that on average the wage rates and hours worked increase when a child is born. This effect is a consequence of selection effects. In other words, this model primarily finds effects, by letting women select out of the labour market, if they are not on high income trajectories. This clashes with the results found by \textcite{kleven_children_2019}. The RHS column of table \ref{tab:extended_results} shows the long run penalties, conditioning on labour market participation.

\begin{figure}[ht]
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{figures/extended_model_event_earnings_H>0.png}
  \caption{Earnings Conditional on $H > 0$}
  \label{fig:ext_model_event_earnings_alt}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{figures/extended_model_event_wage_rates_H>0.png}
  \caption{Wage Rates Conditional on $H>0$}
  \label{fig:ext_model_event_wage_rates_alt}
\end{subfigure}
    \caption{Impact of Children Conditional on $H>0$}
    \label{fig:ext_model_impact_alt}
\end{figure}

Multiple issues can be attributed to cause these discrepancies between the model presented in this paper and the results found by \textcite{kleven_children_2019}. First, it cannot be rejected that in real Danish registry data, labour market participation is defined in a less naive way, than in this paper. This paper simply assumes, that if a woman supplies zero hours of work $(H=0)$, then said woman is unemployed. Danish registry data have a more intricate way to ascribe unemployment status to individuals, than just looking at the number of hours worked by an individual, implying that some individuals of the sample in \textcite{kleven_children_2019} could be working 0 hours. Secondly this model naively assumes an idiosyncratic wage path following a random walk. This might also contribute to the issues. In general, I believe, that to more accurately find comparable results to \textcite{kleven_children_2019} then the model, should contain more intricate family characteristics, endogenous male labour supply, a more elaborate labour market with multiple sectors and include education in the income process. This would compound to a very complex model, however as shown in this paper, using deep reinforcement learning for solving dynamic models, could make it feasible.

\begin{table}[ht]
    \centering
    \input{tables/model_extended_results_comparison}
    \caption{Long Run Penalties Comparison}
    \label{tab:extended_results}
\end{table}


\chapter{Program MAKPOL}
\index{MAKPOL!description}
Construction of data sets for multiple unit cells is  tedious.  By automating
this process, only the fundamental unit  cell need be specified, the other unit
cells being generated  by translation.  In addition, since the geometry of all
fundamental unit cells in a polymer are identical, symmetry  conditions can be
imposed on each unit cell.  This has two  advantages: first, the calculation
runs significantly faster, and  \index{Periodic boundary conditions} second,
periodic boundary conditions are imposed not only on the  whole cluster, but
also on each fundamental unit cell.

A data set for MAKPOL is similar to a data set for MOPAC.  It consists of one
or more lines of keywords, followed by comments (if needed), then a geometry in
Cartesian or internal coordinates.  The name of the input data set should be of
form `\comp{make~$<\!$filename$\!>$.dat}', in which case the resulting data set
will be `\comp{$<\!$filename$\!>$.dat}'.

MAKPOL uses the unit cell supplied by the user to generate all the unit cells
used in the cluster unit cells. \label{makpol:mers} The number of unit cells in
the cluster is determined by the keyword \comp{MERS($n3$,$n2$,$n1$)}.  If the
system is a layer structure then ``$n3$,'' is omitted. If the system is a
polymer, then ``$n3$,$n2$,'' is omitted. The order in which cells are generated
is as follows:
\begin{sloppypar}
Cell(0,0,0), Cell(0,0,1), Cell(0,0,2), \ldots Cell(0,0,N1-1),
Cell(0,1,0), Cell(0,1,1), \ldots Cell(0,N2-1,N1-1), Cell(1,0,0),
\ldots Cell(N3-1,N2-1,N1-1).
\end{sloppypar}

The geometry of the extended system is first calculated in Cartesian
coordinates. There are two ways the atoms can be arranged.  The default order
is as follows: all atoms in the first unit cell, all atoms in the second unit
cell, etc.  An alternative is to have atom one in all the unit cells then atom
two in all  unit cells, then atom three, etc.  The choice of which order to use
depends on the purpose for which the cluster data set will be used.

The whole system is then converted into internal coordinates, and the
translation vectors added.   If wanted, symmetry conditions can be imposed -
this is useful when the geometry is to be optimized.

\section{Keywords used by MAKPOL}
Any of the keywords used by MOPAC can be used in a MAKPOL data set, but, only a
few keywords will be used by MAKPOL: the rest will be ignored.  Keywords that
are used in  MAKPOL are given below.

\begin{description}
\item[\comp{BCC}]~\\
When \comp{BCC} is added (Body Centered Cubic), all odd unit cells are omitted.
An odd unit cell is one for which the addition of the cell indices results in
an odd number, thus (0,0,0) and (1,1,0) would be allowed, but (1,1,1) and
(2,1,0) would not.  Diamond is an example of a BCC solid.\label{makpol:bcc}

\item[\comp{DEBUG}]~\\
Print diagnostic data on how MAKPOL is working. This is not a particularly
useful keyword---do not use it for routine work.

\item[\comp{LET}]~\\
By default, when \comp{SORT} is {\em not} used, all atoms in the fundamental
unit cell will be placed inside  the boundaries of the unit cell.  Any atoms
that were outside the boundaries will  be translated inside the unit cell.
This is necessary for the band structure calculation (in BZ). If you do not
want the atoms to be moved, add \comp{LET}.

\item[\comp{MERS=($n3$,$n2$,$n1$)}]~\\
The number of unit cells in each  direction is defined by $n3$, $n2$,  and
$n1$.  The total number of unit cells generated will be $n3\times n2\times n1$,
or, if \comp{BCC} is used,  $(n3\times n2\times n1)/2$.

\item[\comp{SORT}]~\\
The default order of atoms in a cluster is as follows: all atoms in the first
unit cell, all atoms in the second unit cell, etc.  An alternative order can be
requested by adding \comp{SORT}.  In this case, the order of occurrence is:
atom one in all the unit cells, atom two in all unit cells, atom three, etc.
The choice of which order to use depends on the purpose for which the cluster
data set will be used.

For geometry optimizations, \comp{SORT} is useful, particularly when used with
\comp{SYMMETRY}.

For band structure calculations, \comp{SORT} should {\em not} be used---these
calculations require the default order of atoms.  To emphasize this point, if
\comp{SORT} is specified, then the keyword \comp{MERS} will be deleted from the
resulting data set.

\item[\comp{SYMMETRY}]~\\
This keyword has two distinct functions.  When \comp{SYMMETRY} is specified,
then any symmetry data present in the input data set will be used.  This is
useful for reducing the number of variables that need to be changed on going
from one system to another (for example, on going from diamond to cubic boron
nitride). If no symmetry data are present, then this function will not be used.

The second function of \comp{SYMMETRY} is to impose symmetry conditions on the
resulting cluster data set.  Only four symmetry conditions are recognized:
bond-lengths that are equal, bond angles that are equal, equal dihedral angles,
and dihedral angles that are the negative of reference dihedrals.

For high symmetry systems, the cluster data set should be edited to increase
the symmetry.  For example, in diamond, all angles and dihedrals are symmetry
defined, so all the optimization flags for these variables should be set to
zero, and all symmetry functions involving angles and dihedrals should be
deleted. In addition, all ``bond lengths'' in diamond are simple multiples of
the fundamental C-C distance, so extra symmetry functions (involving function
19) should be added.  If this is done correctly, then only one geometric
variable will be left.
\end{description}

A test-example of the MAKPOL input-data for diamond is given in
Figure~\ref{makpolc}.
\begin{figure}
\begin{makeimage}
\end{makeimage}
\index{Data!for diamond}
\begin{verbatim}
 bcc mers=(4,4,4)
 Diamond, 64 atoms

 c
 xx  0.785065  1
 c   0.785065  0   180       0     0 0     1
 xx  1.0000000 0    54.73561 0     0 0     1 2 3
 xx  1.0000000 0    54.73561 0   120 0     1 2 4
 xx  1.0000000 0    54.73561 0   240 0     1 2 4
 TV  1.8130299 1     0.0     0     0 0     1 4 2
 TV  1.8130299 1     0.0     0     0 0     1 5 2
 TV  1.8130299 1     0.0     0     0 0     1 6 2
\end{verbatim}
\caption{\label{makpolc} Data set for Diamond for MAKPOL}
\end{figure}


\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath,amsfonts,amssymb,amsthm,epsfig,epstopdf,titling,url,array, tikz,tkz-berge, calrsfs}
\usepackage{tkz-graph}

\title{Matroids And their Graphs}
\author{o.mcdonnell4@nuigalway.ie }
\date{19 January 2018}

\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem*{cor}{Corollary}

\theoremstyle{definition}
\newtheorem{defn}{Definition}[section]
\newtheorem{conj}{Conjecture}[section]
\newtheorem{exmp}{Example}[section]

\theoremstyle{remark}
\newtheorem*{rem}{Remark}
\newtheorem*{note}{Note}

\newenvironment{rcases}
  {\left.\begin{aligned}}
  {\end{aligned}\right\rbrace}

\newcounter{excercise}
\newcounter{solution}
\newcounter{Question}

\newcommand\Excercise{%
  \textbf{Excercise:}~%
  \setcounter{solution}{0}%
}

\newcommand\TheSolution{%
  \textbf{Solution:}\\%
}

\newcommand\Question{%
    \textbf{Question:}~%
    \setcounter{Question}{0}%
}
\newcommand\Notation{%
  \textbf{Notation:}~%
}

\newcommand\Proof{%
    \textbf{Proof:}~%
}

\setlength{\droptitle}{-10em}

\GraphInit[vstyle = none]
\tikzset{
  LabelStyle/.style = { rectangle, rounded corners, draw, minimum height = 2em,
                        minimum width = 2em, fill = white!50,
                        text = red, font = \Large\bfseries },
  VertexStyle/.append style = { inner sep=4pt,
                                font = \itseries},
  EdgeStyle/.append style = { } }
\thispagestyle{empty}

\begin{document}
\maketitle

\subsection{Circuit characterization of a matroid}

\begin{defn} By using (I1)–(I3) , it is not difficult to show that the collection $\mathcal{C}$ of circuits of a matroid M has the following three properties:\\
(C1) The empty set is not in $\mathcal{C}$\\
(C2) No member of $\mathcal{C}$ is a proper subset of another member of $\mathcal{C}$\\
(C3) if $ C_1 $ and $ C_2 $ are distinct members of $ C $ and
$ e \in C_1 \cap C_2 $, then $ (C_1 \cup C_2 ) \setminus \{e\} $ contains a member of $\mathcal{C}$
 \end{defn}

 \vspace{5mm}

 \begin{thm}
 Let M be a matroid and $\mathcal{C}$ be its collection of circuits. Then $\mathcal{C}$ satisfies (C1) - (C3)
  \end{thm}

 \noindent\textbf\Proof \\
 \noindent (C1) is obvious as by $I1$ the empty set must always be an independent set.

 \vspace{2mm}

 \noindent (C2) is also straightforward because any $ C \in \mathcal{C} $ is a minimally independent set by definition. Therefore , if there exists a $ C_1 \in \mathcal{C} $ such that $ C_1 \subset C $ then $ C_1 \in \mathcal{C} $ and $ C $ is not a minimally dependent subset of E.

 \vspace{2mm}

 \noindent (C3) Let $ A, B \in \mathcal{C} $ and suppose that(Seeking a contradiction) $ (A \cup B) \setminus \{e\} $ where $ e $ is $ \in (A \cap B) $ does not contain a circuit.\\
 \noindent Then $ (A \cup B) \setminus \{e\} $ is independent and therefore in $\mathcal{I}$

 \vspace{2mm}

\noindent The set $ A \setminus B $ is non-empty.\\
 Let $ s \in A \setminus B    \implies s \in A$\\
 \noindent as $A$ is in $\mathcal{C}$ it is minimally dependent.
 \noindent $\implies A \setminus \{s\} \in \mathcal{I}$ i.e is independent.

 \vspace{2mm}

\noindent Let $J$ be a maximal independent set of $(A \cup B)$ with the following properties: $S \setminus \{s\} \subset J $ and therefore $ \{s\} \notin J $ but as B is a circuit there must be some element $t \in B$ that is not in $J$. $s$ and $t$ are distinct.

 \vspace{2mm}

\noindent $\implies |J| $ must be at most equal to $|(A \cup B) \setminus \{s,t\}| $\\
 $\implies |J| \leq |(A \cup B) \setminus \{s,t\}| = |(A \cup B)| - 2 < |(A \cup B) \setminus \{e\}|$

 \vspace{2mm}

 \noindent Now by (I3) we can subsitute elements from $|(A \cup B) \setminus \{e\}|$ into $|(A \cup B) \setminus \{s,t\}|$ that are not in $|(A \cup B) \setminus \{s,t\}|$ but the only elements that fits this condition are $\{s,t\}$ and introducing either of these elements breaks the independence of $J$.

\noindent Therefore, $|(A \cup B) \setminus \{e\}|$ must contain a circuit\\
 \qed

\end{document}


% chap3.tex
\input{initializers_variables.tex}
\chapter{Hyper-Parameters}\label{chap:hyperparams}
\noindent This chapter introduces hyper-parameters. They are not directly related to the machine learning algorithm parameters, but responsible for overall algorithm evolution. For example learning rate dictates the update strength per iteration, choice of initializer can lead to slow or fast convergence, choice of optimizers provide way to update learning parameters($\theta$).

\noindent Other than direct algorithm parameters, we will consider everything else as hyper-parameter. Mainly we will consider following hyper-parameters, which we will discuss and explain the experiments performed with different choices of these parameters and their effect in overall convergence.

\begin{enumerate}
	\item \textbf{Initializer}
	\item \textbf{Optimizer}
	\item \textbf{Batch size}
	\item \textbf{Total parameters}
	\item \textbf{Number of Epochs}
\end{enumerate}

\section{Initializer}

\noindent Initial network condition is described as \textit{"At birth the construction of the most important networks is largely random, subject to a minimum number of constraints"} in \cite{Rosenblatt58theperceptron:} suggests that random initializations can be used to initialize network parameters and constraints could be range of these parameters.

\noindent \textbf{Uniform initialization}, assigns initial weights from $U[-r,\; r]$, where $U$ is uniform distribution, Mostly $r$ is used as small value $\sim0.1$. Another random initialization scheme is \textbf{Normal Initialization}, based on sampling initial weights from normal distribution, $N(0,1)$. These are simple methods which are getting used.

\noindent \textbf{Uniform initialization using fan in} \cite{LeCun:1998:EB:645754.668382} suggests, using fan-in to determine standard deviation $\sigma_i$ and sampling initial weights from $N(0,\sigma_l)$. value of $\sigma_l$ is dependent on fan-in, which is number of inputs to a hidden unit. It is suggested to be chosen as per \ref{eq:le_uni}
\begin{equation}\label{eq:le_uni}
	\sigma_l=\textbf{m}^{-1/2}, where, \; \textbf{m} \; is \; the \; fan \; in
\end{equation}

\noindent \textbf{Normalized initialization} \cite{Glorot10understandingthe} suggest to use uniform weight initialization as per \ref{eq:gl_normal}
\begin{equation}\label{eq:gl_normal}
U[-\frac{{\sqrt{6}}}{{\sqrt{n_l+n_{l+1}}}}, \frac{{\sqrt{6}}}{{\sqrt{n_l+n_{l+1}}}}]
\end{equation}
where $n_l$ and $n_{l+1}$ are total number of units in $l^{th}$ and ${(l+1)}^{th}$ hidden layer respectively. This work on paradigm of maintaining activation variances in feed forward direction and back propagated gradient variances in both the directions.

\noindent For very deep models and to support activation ReLU/PReLU \cite{DBLP:journals/corr/HeZR015} suggests to use slight modification in considering the variance from \cite{Glorot10understandingthe} and the \textbf{initialization scheme becomes zero-mean Gaussian with standard deviation as $\sqrt{2/n_l}$}, where $n_l$ is number of hidden units in $l^{th}$ layer.

\noindent \textbf{Orthogonal random initializations} \cite{DBLP:journals/corr/SaxeMG13} suggests simple initialization scheme where in initial weights are chosen from the random orthogonal matrix satisfying $W^TW=I$. This yield depth independent learning times, which means as depth increases learning time remains same as oppose to suggested initializations in \cite{LeCun:1998:EB:645754.668382} \cite{Glorot10understandingthe}

\input{initializers_results.tex}

\section{Optimizers}

\noindent Optimizers are main learning algorithm or routine which is responsible for changes in the network as and when update takes place. The updates are not limited to parameters update alone, even hyperparameters can also get updated as per underlying optimizer routines.

\noindent Here we will discuss different optimizers, mainly gradient/sub gradient methods,their analysis and effect from experimental results. Detailed survey of these methods can be found at \cite{DBLP:journals/corr/Ruder16} and \cite{nadam_}

\noindent \textbf{GD(Gradient descent)} is one of the important and robust optimization algorithm. The gradient of the function  to be optimized is computed with respect to the parameters. In deep learning setting the function to be optimized usually is loss function $\mathcal{L}$ and parameters are $\theta_t$ at $t^{th}$ iteration. The gradient of $\mathcal{L}$ with respect to $\theta$ is denoted as $\nabla_{\theta_{t-1}}\mathcal{L}(\theta_{t-1})$, which gets computed at $(t-1)$ iteration and $\theta_t$ is updated as per \ref{eq:gd_up}
\begin{equation}\label{eq:gd_up}
\theta_{t} = {\theta_{t-1}} -\eta (\nabla_{\theta_{t-1}}\mathcal{L}(\theta_{t-1})),\\ %TBD:to represent this in simple notations form
{\scriptstyle where \; \eta \; is \; known \; as \; learning \; rate}
\end{equation}

\noindent In deep learning due to large training size gradient descent, also known as \textbf{batch learning} is almost impossible. So for large scale learning reduced size is considered and network parameters are updated, this batch will not be used till new repetition of dataset starts. This repetition is known as an \textbf{epoch}. The size of batch used in one single update is known as \textbf{minibatch}.
The minibatch and epochs are considered later in this chapter. We will see batch learning in chapter \ref{chap:training}.

\noindent The strategy to update network parameters after every $minibatch \; size= 1$ is known as \textbf{SGD (Stochastic Gradient Descent)}, which is also known as online learning.
Commonly $minibatch \; size \; \gg \; 1$ is used in deep learning with large datasets. We will use SGD for minibatch or online learning.

\noindent \ref{eq:gd_up} is applicable as it is to SGD also, only difference is computation of loss gradient is restricted to the current minibatch instead of full training dataset. We will discuss its details in chapter \ref{chap:training}.
Another optimizers explained ahead are variants of SGD, which is essentially differs in the way network parameters get adjusted as learning progresses.

\noindent \textbf{Classical Momentum}\cite{POLYAK19641} remembers previous gradient update vector and fraction of it is added to the next parameter update. The momentum term is computed as per \ref{eq:momentum} and update takes place as per \ref{eq:moment_up}.

\begin{equation}\label{eq:momentum}
\begin{aligned}
m_t = \mu m_{t-1}+\nabla_{\theta_{t-1}}\mathcal{L}(\theta_{t-1}),
\end{aligned}
\end{equation}
\begin{equation}\label{eq:moment_up}
\begin{aligned}
\theta_t=\theta_{t-1} - \eta m_t\\
{\scriptstyle where \; \mu \; is \; known \; as \; momentum \; term}
\end{aligned}
\end{equation}

\noindent \textbf{NAG (Nesterov accelerated gradient)} is accelerated gradient descent which converges faster than classical momentum or SGD. The gradient is calculated on possible future update without using gradient and then using it to update network parameter. Acceleration is achieved as it can be seen as looking into future as this can prevent slows gradient update to move uphill and accelerate if it is moving downhill. The updates are calculated as per \ref{eq:nag_up}

\begin{equation}\label{eq:nag_up}
\begin{aligned}
m_t = \mu m_{t-1}+\eta\nabla_{\theta_{t-1}}\mathcal{L}(\theta_{t-1}-\mu m_{t-1}) \\
\theta_t=\theta_{t-1} - m_t
\end{aligned}
\end{equation}

\noindent\textbf{Adagrad (Adaptive subgradient descent)} \cite{Duchi:2011:ASM:1953048.2021068} adapts the learning rate as per the parameters updates. So this optimizer adjusts learning rate hyper parameter and falls under category where it updates parameters as well as hyper parameters. Basic premise of Adagrad is to have larger updates for less frequent parameters and smaller updates for frequent ones.

%This could also be seen as controlling the overfitting to certain patterns which are governed by set of frequent parameters.handle class imbalance problem [WRITE IN RECOMMENDATIONS: TBD]
\noindent The updated learning rate for each parameter thus varies based on their earlier gradient updates individually. The updates take place as per \ref{eq:adagrad}

\begin{equation}\label{eq:adagrad}
\begin{aligned}
n_t=n_{t-1}+(\nabla_{\theta_{t-1}}\mathcal{L}(\theta_{t-1}))^2\\
\theta_t=\theta_{t-1} - \eta \frac{\nabla_{\theta_{t-1}}\mathcal{L}(\theta_{t-1})}{\sqrt{n_t+\epsilon}}
\end{aligned}
\end{equation}

\noindent \textbf{Adadelta}\cite{adadelta} counters the effect of increasing norm $n_t$ of Adagrad as that can reduce learning rate monotonically, which can be easily seen in \ref{eq:adagrad}, where $n_t$ increases as iteration progresses. Adadelta restricts the size of gradients which get accumulated to a sliding window of fixed size. The sum of gradients are maintained as running average $E[g^2]_t$ of previous gradient average squared $E[g^2]_{t-1}$  and current gradient ${g_t}$ squared as per \ref{eq:adadelta_average}

\begin{equation}\label{eq:adadelta_average}
E[g^2]_t=\rho E[g^2]_{t-1}+(1-\rho){g_t}^2, where \; \rho \; is \; a \; decay \; constant
\end{equation}

\noindent Other than maintaining the running average of gradients sqaured, running average $E[\nabla\theta^2]$  of previous parameter updates squared are also maintained and this is compute in similar way of running average gradient computation of \ref{eq:adadelta_average}. It is given in \ref{eq:adadelta_avg_param}

\begin{equation}\label{eq:adadelta_avg_param}
\begin{aligned}
\nabla\theta_{t}=-g_{t}\frac{\sqrt{E[\theta^2]_{t-1}+\epsilon}}{\sqrt{E[g^2]_{t}+\epsilon}}\\
E[\nabla\theta^2]_t=\rho E[\nabla\theta^2]_{t-1}+(1-\rho){\nabla\theta_t}^2,
\end{aligned}
\end{equation}

\noindent Now updates of Adadelta takes place as per \ref{eq:adadelta_up}

\begin{equation}\label{eq:adadelta_up}
\begin{aligned}
\theta_t=\theta_{t-1} - \nabla\theta_t
\end{aligned}
\end{equation}

\noindent if instead of using running average of parameters update, we use $\eta$ in \ref{eq:adadelta_avg_param} to calculate $\nabla\theta_t$ given in \ref{eq:rmsprop_avg_param} and update happens as per \ref{eq:adadelta_up}, then this optimizer is known as \textbf{RMSprop}.value of $\rho$ as proposed by the author is 0.95.

\begin{equation}\label{eq:rmsprop_avg_param}
\begin{aligned}
\nabla\theta_{t}=-g_{t}\frac{\eta}{\sqrt{E[g^2]_{t}+\epsilon}}\\
\end{aligned}
\end{equation}

\noindent \textbf{Adam(Adaptive moment estimation)}\cite{adam} combines momentum and norm based optimizer. It computes first and second moment estimate as per \ref{eq:adam_avgs}. $\hat{m_t}$ and $\hat{v_t}$ are known as first and second moment estimates respectively,

\begin{equation}\label{eq:adam_avgs}
\begin{aligned}
\hat{m_t}=\frac{\beta_1 m_{t-1}+(1-\beta_1)g_t}{(1-{\beta_1}^t)} \\
\hat{v_t}=\frac{\beta_2 v_{t-1}+(1-\beta_2){g_t}^2}{(1-{\beta_2}^t)}\\
\end{aligned}
\end{equation}

\noindent Adam updates then takes place as per \ref{eq:adam_up}
\begin{equation}\label{eq:adam_up}
\begin{aligned}
\theta_t=\theta_{t-1} - \eta\frac{\hat{m_t}}{\sqrt{\hat{v_t}+\epsilon}}
\end{aligned}
\end{equation}

\noindent \textbf{Adamax}\cite{adam} uses same updates as Adam other than it uses $l_{\infty}$ norm instead of $l_2$ norm.
%\input{optimizer_results.tex}

\section{Number of Epochs}

Number of epochs is the parameter which governs how many time full dataset will undergo training progress. As in minibatch learning batch size $\ll$ full training data. To see full data one time several minibatch undergoes update but not used later till full training data is used. One epoch thus sees full data set once and then it starts the process again.

Number of epochs are required to average out noise which is introduced due to stochastic minibatch updates.
We have used this parameters in conjunction with Early stopping, which means set epoch value to a large number and use stopping criterion automatically based on certain performance parameter. In ur experiments we have used validation accuracy as performance parameter to monitor for maximum patience of 50 epochs, which means if there is no improvement from last 50 epochs on validation accuracy, training halts automatically.

\section{Batch Size}

Batch size or minibatch size is the total number of samples chosen from the dataset, which are part of single network update. Often this parameter is chosen arbitarily based on memory availability o the system or capability o underlying mechanism.
There is not much study available on the batch size recommendations.As a general rule \cite{DBLP:journals/corr/abs-1206-5533} suggests to use batch size=32, as values above 10 can take advantage of fast matrix multiplications over vector matrix products.
\cite{Hinton2012} in context of RBM(Restricted Boltzmann Machines) also suggest to use batch size greater than 10 for speed up, but strongly against making the size too big when using stochastic gradient descent.

We can understand this bit more in context of network updates where each mini batch is responsible for a single update, so total number of updates in an epoch depends on the size of mini batch. Bigger the size less number of updates it has in an epoch. So weight updates decreases as batch size increases. \cite{Hinton2012} suggest to use batch size equal to number of classes in case of uniform class data with small number of classes.
Also it suggest to have sample from each class in a batch.
However there is no experimental evidences provided which supports the suggestions for different networks. Also study of mini batch size with respect to classes seems interesting. So our major work here is experiments the relationship of this kind which is largely neglected and provide a recommendations for their choice.

\input{batch_resultsnew.tex}


\documentclass[prb,twocolumn,superscriptaddress]{revtex4-1}

\pdfoutput=1

\usepackage{graphicx}% Include figure files
\usepackage{amsmath,amssymb}

\usepackage{color}
\usepackage{amssymb}
\usepackage{braket}

\usepackage{hyperref}
\hypersetup{colorlinks=true,breaklinks,linkcolor=blue,urlcolor=blue,citecolor=blue}

\def\diff{\mathrm d}
\def\mathi{\mathrm i}
\def\mathe{\mathrm e}

\newcommand{\bx}{\ensuremath{\boldsymbol{\rho}}}
\newcommand{\by}{\ensuremath{\boldsymbol{G}}}
\newcommand{\bS}{\ensuremath{\boldsymbol{S}}}
\newcommand{\bU}{\ensuremath{\boldsymbol{U}}}
\newcommand{\bV}{\ensuremath{\boldsymbol{V}}}
\newcommand{\bA}{\ensuremath{\boldsymbol{A}}}
\newcommand{\bK}{\ensuremath{\boldsymbol{K}}}
\newcommand{\brho}{\ensuremath{\boldsymbol{\rho}}}
\newcommand{\bG}{\ensuremath{\boldsymbol{G}}}

\newcommand{\bu}{\ensuremath{\boldsymbol{u}}}
\newcommand{\bv}{\ensuremath{\boldsymbol{v}}}

\newcommand{\bxp}{\ensuremath{\boldsymbol{x}^\prime}}
\newcommand{\byp}{\ensuremath{\boldsymbol{y}^\prime}}

\newcommand{\np}{\ensuremath{{n^\prime }}}

\newcommand{\tr}[1]{\textcolor{red}{#1}}
\newcommand{\tb}[1]{\textcolor{blue}{#1}}
\newcommand{\tg}[1]{\textcolor{green}{\bf #1}}
\newcommand{\HS}[1]{\textcolor{red}{#1}}
\newcommand{\KY}[1]{\textcolor{blue}{#1}}
\newcommand{\wmax}{\ensuremath{{\omega_\mathrm{max}}}}
\newcommand{\Omegathree}{\ensuremath{\Omega_\mathrm{3pt}}}

\newcommand{\tx}{\ensuremath{\tilde{x}}}
\newcommand{\ty}{\ensuremath{\tilde{y}}}
\newcommand{\tu}{\ensuremath{\tilde{u}}}
\newcommand{\tv}{\ensuremath{\tilde{v}}}
\newcommand{\tK}{\ensuremath{\tilde{K}}}

\newcommand{\Gthree}{\ensuremath{G^\mathrm{3pt}}}
\newcommand{\Gthreenorm}{\ensuremath{G_\mathrm{normal}^\mathrm{3pt}}}
\newcommand{\Gthreesingular}{\ensuremath{G_\mathrm{singular}^\mathrm{3pt}}}
\newcommand{\Gfour}{\ensuremath{G^\mathrm{4pt}}}

\newcommand{\KF}{\ensuremath{K^\mathrm{F}}}
\newcommand{\KB}{\ensuremath{K^\mathrm{B}}}
\newcommand{\UF}{\ensuremath{U^\mathrm{F}}}
\newcommand{\UB}{\ensuremath{U^\mathrm{B}}}
\newcommand{\enhUB}{\ensuremath{U^\mathrm{\overline{B}}}}

\newcommand{\overlineB}{\ensuremath{{\overline{\mathrm{B}}}}}

\begin{document}
\title{Overcomplete compact representation of susceptibility at a finite bosonic frequency}
\author{Hiroshi Shinaoka}
\affiliation{Department of Physics, Saitama University, 338-8570, Japan}

\begin{abstract}
\end{abstract}

\maketitle
\section{The three-point Green's functions}
We consider a three-point Green's function defined by
\begin{align}
  \Gthree(\tau_1, \tau_2, \tau_3) &= \braket{T_\mathrm{\tau} A(\tau_1) B(\tau_2) C(\tau_3)},\label{eq:3point}
\end{align}
where $A$ and $B$ are fermionic operators in the Heisenberg picture and $C$ is a bosonic operator.
Our expansion formula for $\Gthree$ is
\begin{align}
	& \Gthree(\tau_1, \tau_2, \tau_3) \nonumber\\
	& =  \sum_{l_1,l_2=0}^\infty \Big\{G^{(1)}_{l_1l_2}\UF_{l_1}(\tau_{13})\UF_{l_2}(\tau_{23}) \nonumber\\
	& +  G_{l_1 l_2}^{(2)} \enhUB_{l_1}(\tau_{13})\UF_{l_2}(\tau_{21}) +
	G_{l_1 l_2}^{(3)} \UF_{l_1}(\tau_{12})\enhUB_{l_2}(\tau_{23})
	\Big\}.
\end{align}
\begin{align}
	&\Gthree(i\omega_1, i\omega_2)\nonumber\\
	&\equiv \int_0^\beta d\tau_{13} d\tau_{23} e^{i\omega_1 \tau_{13} + i \omega_2 \tau_{23}} \Gthree(\tau_1, \tau_2, \tau_3)
	\nonumber\\
	& =  \sum_{l_1,l_2=0}^\infty \Big\{G^{(1)}_{l_1l_2}\UF_{l_1}(i\omega_1)\UF_{l_2}(i\omega_2) \nonumber\\
	& \quad+  G_{l_1 l_2}^{(2)} \enhUB_{l_1}(i\omega_1 + i \omega_2)\UF_{l_2}(i \omega_2)
	\nonumber\\
	& \quad+
	G_{l_1 l_2}^{(3)} \UF_{l_1}(i\omega_1)\enhUB_{l_2}(i\omega_1 + i \omega_2)
	\Big\}.\label{eq:three-point-exp2}
\end{align}

\section{The four-point Green's functions}

\begin{align}
	&\Gfour(\tau_1, \tau_2, \tau_3, \tau_4)
	\nonumber\\
	& = \sum_{l_1, l_2, l_3=0}^{\infty} \Big\{
	G_{l_1 l_2 l_3}^{(1)}  \UF_{l_1}(\tau_{14}) \UF_{l_2}(\tau_{24}) \UF_{l_3}(\tau_{34})
	\nonumber\\
	&\hspace{4em}+ \cdots \nonumber\\
	&\hspace{4em}+ G_{l_1 l_2 l_3}^{(16)} \UF_{l_1}(\tau_{32}) \enhUB_{l_2}(\tau_{21}) \UF_{l_3}(\tau_{14})
	\Big\}
	\nonumber\\
	& \equiv \sum_{r=1}^{16} \sum_{l_1, l_2, l_3=0}^{\infty} G_{l_1 l_2 l_3}^{(r)} U^{\alpha}_{l_1}(\tau) U^{\alpha'}_{l_2}(\tau') U^{\alpha''}_{l_3}(\tau''),
	\label{eq:ir-four-point}
\end{align}

\begin{align}
	\chi(\tau_{12}, \tau_{34}, i\omega_m) &\equiv \int_0^\beta d \tau_1 \Gfour(\tau_1, \tau_2, \tau_3, 0) e^{i\omega_m \tau_1}
\end{align}

The dependency on two fermionic frequencies at a fixed bosonic frequency is represented as
\begin{align}
	& 	\chi(\tau_{12}, \tau_{34}, i\omega_m) \nonumber\\
	& =  \sum_{s,s^\prime=0,1}\sum_{l_1,l_2=0}^\infty \Big\{G^{(1)}_{s s^\prime l_1l_2}
	\UF_{s l_1}(\tau_{12})\UF_{s^\prime l_2}(\tau_{34}) \nonumber\\
	& +  G_{s s^\prime l_1 l_2}^{(2)}
    \enhUB_{s l_1}(\tau_{12}) \UF_{s^\prime l_2}((-1)^{s^\prime} \tau_{12}+\tau_{34}) \nonumber\\
	& +
	G_{s s^\prime l_1 l_2}^{(3)}
	\enhUB_{s l_1}(\tau_{34})\UF_{s^\prime l_2}( \tau_{12}+(-1)^{s^\prime}\tau_{34})
	\Big\}.\\
	& \hspace{1em}U^\alpha_{s l}(\tau) \equiv e^{is \omega_m \tau} U^\alpha_l(\tau).
\end{align}
In the Matsubara domain, this reads
\begin{align}
	&\chi(i\omega_n, i\omega_\np, i\omega_m)\nonumber\\
	&\equiv \int_0^\beta d\tau_{12} d\tau_{34} e^{i\omega_n \tau_{12} + i\omega_\np \tau_{34}} \chi(\tau_{12}, \tau_{34}, i\omega_m)
	\nonumber\\
	&\equiv \int_0^\beta d\tau_{12} d\tau_{34} d\tau_{14} e^{i\omega_n \tau_{12} + i\omega_\np \tau_{34} + i\omega_\np \tau_{14}} \Gthree(\tau_1, \tau_2, \tau_3, \tau_4)
	\nonumber\\
	& =  \sum_{s,s^\prime=0,1}\sum_{l_1,l_2=0}^\infty \Big\{G^{(1)}_{s s^\prime l_1l_2}
	\UF_{s l_1}(i\omega_n)\UF_{s^\prime l_2}(i\omega_\np) \nonumber\\
	& \quad+  G_{s s^\prime l_1 l_2}^{(2)} \enhUB_{l_1 s}(i\omega_n + (-1)^{s+1} i \omega_\np)\UF_{l_2 s^\prime}(i \omega_\np)
	\nonumber\\
	& \quad+
	G_{s s^\prime l_1 l_2}^{(3)} \enhUB_{l_1 s}(i\omega_\np + (-1)^{s+1} i\omega_n) \UF_{l_2 s^\prime}(i\omega_n)
	\Big\}.\label{eq:three-point-exp2}\\
	& \hspace{2em}U_{s l}^\alpha(i\omega_n) \equiv U_{ l}^\alpha(i\omega_n + s i\omega_m)
\end{align}
%This is motivated by the observation that $\chi(\tau_{12}, \tau_{34}, i\omega_m)$ has discontinuities at $\tau_{12} + \tau_{34} = n \beta$.
%This seems to work very well for $\omega_m = 0$ but not for $\omega_m \neq 0$.

\if0
\begin{table}
	\centering
	\begin{tabular}{c|c|c|c}
		\hline
		$\#r$ & ($i\omega$, $i\omega$', $i\omega$'') & ($\tau$, $\tau'$, $\tau''$) & ($\alpha$, $\alpha'$, $\alpha''$) \\
		\hline
		\hline
		\#1 & ($i\omega_1$, $i\omega_2$, $i\omega_3$) & ($\tau_{14}$, $\tau_{24}$, $\tau_{34}$) &  (F,F,F)  \\
		\#2 & ($i\omega_1$, $i\omega_2$, $i\omega_4$) & ($\tau_{13}$, $\tau_{23}$, $\tau_{43}$) &  (F,F,F)  \\
		\#3 & ($i\omega_1$, $i\omega_3$, $i\omega_4$) & ($\tau_{12}$, $\tau_{32}$, $\tau_{42}$) &  (F,F,F)  \\
		\#4 & ($i\omega_2$, $i\omega_3$, $i\omega_4$) & ($\tau_{21}$, $\tau_{31}$, $\tau_{41}$) &  (F,F,F)  \\ \hline
		\#5 & ($i\omega_1$, $i\omega_1 + i\omega_2$, $-i\omega_4$) & ($\tau_{12}$, $\tau_{23}$, $\tau_{34}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#6 & ($i\omega_1$, $i\omega_1 + i\omega_2$, $-i\omega_3$) & ($\tau_{12}$, $\tau_{24}$, $\tau_{43}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#7 & ($i\omega_1$, $i\omega_1 + i\omega_3$, $-i\omega_4$) & ($\tau_{13}$, $\tau_{32}$, $\tau_{24}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#8 & ($i\omega_1$, $i\omega_1 + i\omega_3$, $-i\omega_2$) & ($\tau_{13}$, $\tau_{34}$, $\tau_{42}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#9 & ($i\omega_1$, $i\omega_1 + i\omega_4$, $-i\omega_3$) & ($\tau_{14}$, $\tau_{42}$, $\tau_{23}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#10 & ($i\omega_1$, $i\omega_1 + i\omega_4$, $-i\omega_2$) & ($\tau_{14}$, $\tau_{43}$, $\tau_{32}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#11 & ($i\omega_2$, $i\omega_2 + i\omega_1$, $-i\omega_4$) & ($\tau_{21}$, $\tau_{13}$, $\tau_{34}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#12 & ($i\omega_2$, $i\omega_2 + i\omega_1$, $-i\omega_3$) & ($\tau_{21}$, $\tau_{14}$, $\tau_{43}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#13 & ($i\omega_2$, $i\omega_2 + i\omega_3$, $-i\omega_4$) & ($\tau_{23}$, $\tau_{31}$, $\tau_{14}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#14 & ($i\omega_2$, $i\omega_2 + i\omega_4$, $-i\omega_3$) & ($\tau_{24}$, $\tau_{41}$, $\tau_{13}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#15 & ($i\omega_3$, $i\omega_3 + i\omega_1$, $-i\omega_4$) & ($\tau_{31}$, $\tau_{12}$, $\tau_{24}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\#16 & ($i\omega_3$, $i\omega_3 + i\omega_2$, $-i\omega_4$) & ($\tau_{32}$, $\tau_{21}$, $\tau_{14}$) &  (F,$\overline{\mathrm{B}}$,F)  \\
		\hline
	\end{tabular}
	\caption{16 different notations of relative times for $\Gfour(\tau_1,\tau_2,\tau_3,\tau_4)$, the corresponding Matsubara frequencies and statistics.}
	\label{table:summary}
\end{table}
\fi

\section{Tensor regression}
We decomposed the particle-hole view of the two-particle Green's function as
\begin{align}
G(r, l_1, l_2) &= \sum_{d=1}^D C(d, r) X_1(d,l_1) X_2(d,l_2),
\end{align}
where $r$ is the index of 12=($3\times 2\times 2$) orthogonal systems.
This is referred to as a CP decomposition [canonical (CANDECOMP) / parallel pactors (PARAFAC)].
We will find useful information in ``Tensor Learning for Regression" written by Weiwei Guo, Irene Kotsia.

The cost function reads
\begin{align}
&& |G(\boldsymbol{n}) - U(\boldsymbol{n}, r, l_1) U(\boldsymbol{n}, r, l_2) G(r, l_1, l_2)|^2_2 \nonumber \\
&& + \alpha \left\{ |C|^2_2 + |X_1|^2_2 + |X_2|^2_2 \right\},
\end{align}
where $\boldsymbol{n} \equiv (n, n^\prime, m)$ runs over sampling points in the Matsubara frequency domain.
This cost function can be minimized using alternative projections since the penalty term is separable with respect to $C$, $X_1$ or $X_2$.
That is, we minimize the cost function with respect to either $C$, $X_1$ or $X_2$ at one time.
This ends up with performing many smaller Ridge regressions.

\begin{figure}
	\centering\includegraphics[width=.4\textwidth,clip]{tensor_regression.pdf}
	\caption{
		Graphical representation of CP decomposition
	}
	\label{fig:CP}
\end{figure}

\end{document}


% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.

      \subsection{pred.m}

\begin{par}
\textbf{Summary:} Compute predictive (marginal) distributions of a trajecory
\end{par} \vspace{1em}
\begin{verbatim}[M S] = pred(policy, plant, dynmodel, m, s, H)\end{verbatim}
\begin{par}
\textbf{Input arguments:}
\end{par} \vspace{1em}
\begin{verbatim}policy             policy structure
plant              plant structure
dynmodel           dynamics model structure
m                  D-by-1 mean of the initial state distribution
s                  D-by-D covariance of the initial state distribution
H                  length of prediction horizon\end{verbatim}
\begin{par}
\textbf{Output arguments:}
\end{par} \vspace{1em}
\begin{verbatim}M                  D-by-(H+1) sequence of predicted mean vectors
S                  D-by-D-(H+1) sequence of predicted covariance
                   matrices\end{verbatim}
\begin{par}
Copyright (C) 2008-2013 by Marc Deisenroth, Andrew McHutchon, Joe Hall, and Carl Edward Rasmussen.
\end{par} \vspace{1em}
\begin{par}
Last modified: 2013-01-23
\end{par} \vspace{1em}

\subsection*{High-Level Steps}

\begin{enumerate}
\setlength{\itemsep}{-1ex}
   \item Predict successor state distribution
\end{enumerate}

\begin{lstlisting}
function [M S] = pred(policy, plant, dynmodel, m, s, H)
\end{lstlisting}

\subsection*{Code}

\begin{lstlisting}
D = length(m); S = zeros(D,D,H+1); M = zeros(D,H+1);
M(:,1) = m; S(:,:,1) = s;
for i = 1:H
  [m s] = plant.prop(m, s, plant, dynmodel, policy);
  M(:,i+1) = m(end-D+1:end);
  S(:,:,i+1) = s(end-D+1:end,end-D+1:end);
end
\end{lstlisting}