% Manual_MILP_BH_cyclic_ec_vector_en.txt
% ver1: Jan 12, 2021

\documentclass[11pt, titlepage, dvipdfmx, twoside]{article}
\linespread{1.1}

\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\usepackage{enumitem}
\usepackage{geometry}
\geometry{left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm}

\usepackage{mathtools}
\usepackage{comment}
\usepackage[dvipdfmx]{graphicx}
\usepackage{float}
\usepackage{framed}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{listings}
\usepackage{color}
\usepackage{url}

\definecolor{codegreen}{rgb}{0, 0.6, 0}
\definecolor{codegray}{rgb}{0.5, 0.5, 0.5}
\definecolor{codepurple}{rgb}{0.58, 0, 0.82}
\definecolor{backcolour}{rgb}{0.95, 0.95, 0.92}

\newcommand{\tname}{6Hc}
%%  target name used for the example

\newcommand{\dist}{\mathrm{dist}}

\title{\Huge{Module 3: Inferring a 2-Lean Cyclic Chemical Graph with Bounded Branch-Height
			  from a Trained ANN Using MILP}}

\begin{document}

% The following makeatletter must be after begin{document}
\makeatletter
\let\c@lstlisting\c@figure
\makeatother

\date{\today}

\maketitle

% \cleardoublepage

\thispagestyle{empty}
\tableofcontents
\clearpage

\pagenumbering{arabic}

\section{Outline}
\label{sec:Intro}

This note explains how to use an implementation of a mixed-integer
linear programming (MILP) formulation that can infer
a vector of graph descriptors given a target value and the
weights and bias values of a trained artificial neural network (ANN).

The MILP is implemented in Python,
using the PuLP modeling module of the
COIN-OR package~\cite{PuLP1,PuLP2,PuLP3,PuLP4}.

To begin with, we give a list of the files that accompany this note.

\begin{itemize}

\item Folder {\tt source\_code}\\
A folder containing four Python scripts that implement
an MILP formulation for inferring feature vectors
of cyclic chemical graphs from a trained ANN,
and files containing minimum and maximum values
of each descriptor
in the MILP formulation.

\begin{itemize}

\item {\tt ann\_inverter.py}\\
An implementation of an MILP formulation
for the Inverse problem on  ANNs~\cite{AN19}.

\item {\tt cyclic\_graphs\_MILP\_ec\_id\_vector.py}\\
A Python script that contains functions to initialize the variables and prepare
the constraints for an MILP
formulation for inferring cyclic chemical graphs with
a prescribed topological structure~\cite{cyclic_BH_arxiv}.

\item {\tt infer\_cyclic\_graphs\_ec\_id\_vector.py}\\
A Python script that prepares the data and executes
the MILP formulation for given input data.
Further details on the use of this script
are given in Section~\ref{sec:Exp}.

\item {\tt read\_instance\_BH\_cyclic\_v05.py}\\
A Python script that contains necessary functions
to read the topological specification from a given textual file.

\item Folder {\tt topological\_description}\\
A folder containing six textual files each giving a chemical specification as detailed
in~\cite{cyclic_BH_arxiv}.
%
\begin{itemize}
 \item {\tt instance\_a.txt}
 \item {\tt instance\_b1.txt}
 \item {\tt instance\_b2.txt}
 \item {\tt instance\_b3.txt}
 \item {\tt instance\_b4.txt}
 \item {\tt instance\_c.txt}
 \item {\tt instance\_d.txt}
\end{itemize}

\item Folder {\tt ANN}\\
A folder containing information on trained artificial neural networks (ANNs) for three target properties:
Flash point (closed cup) (Fp), Lipophilicity (Lp), and Solubility (Sl).
For each of the above three properties, ${\tt property} \in \{{\tt FP, LP, SL}\}$ three files are provided:
%
\begin{itemize}
\item {\tt property\_desc.csv}\\
A comma-separated value file containing descriptors
used in the training of the ANN.

\item {\tt property\_biases.txt}\\
A file containing the values of the biases of a trained ANN.

\item {\tt property\_weights.txt}\\
A file containing the values of the weights of a trained ANN.
\end{itemize}
%
For each of the files, the data format is explained in Section~\ref{sec:InOut},
and an actual example is given in Section~\ref{sec:Exp}.

\item {\tt fv4\_cyclic\_stdout.cpp}\\
A C++ program that calculates the feature vector of
a chemical graph stored in SDF format.
The input and output of this program are customized to work with
the Python script {\tt infer\_cyclic\_graphs\_ec\_id\_vector.py}
in order to verify the descriptor values
of the graph inferred as a solution to the MILP (if one exists).
This source file should be compiled into an executable file
with the name {\tt fv}.

\item {\tt fv}\\
An executable binary file of the above C++ program.
This executable has been compiled
by {\tt gcc} version 5.4.0
on a PC running the Linux Mint 18.3 operating system.
%
\end{itemize}
\end{itemize}

The remaining of this note is organized as follows.
Section~\ref{sec:Pre} gives an explanation
of the used terms and notation.
%
Section~\ref{sec:InOut} explains the
input and output data of the program,
and Section~\ref{sec:Exp} gives a concrete
example of input data and the results form the computation.

% \newpage

\section{Terms and Notation}
\label{sec:Pre}
%
This section explains the terms and notation used in this note.

\begin{itemize}

\item {\bf Feature vector}\\
%
A {\em feature vector} stores numerical values of certain parameters,
called {\em descriptors}.
In this work, we choose graph-theoretical descriptors, such as number of
non-hydrogen atoms, number of vertices of certain degree, etc.

\item {\bf Artificial neural network - ANN}\\
%
Artificial neural networks are one of the methods in machine learning.
They provide a means to construct a correlation function between
pairs of feature vectors as input and target data as output.

\item {\bf Input, hidden, and output layer}\\
%
We deal with the multilayer perceptron model
of feed-forward neural networks.
These neural networks are constructed of several {\em layers}.
First comes the \emph{input layer}, where each neuron takes as input
one value of the feature vector.
Next come the \emph{hidden layers}, where the
values from the input layer are propagated in a feed-forward manner,
such that each node in one layer is connected to all the nodes of the next layer.
Finally, the output is delivered at the \emph{output layer}.
We deal with predicting the value of a single target,
and hence we assume that the output layer comprises a single node.

\item {\bf Weights}\\
%
Each edge connecting two nodes in an ANN is assigned a real value,
called a \emph{weight}.
Part of the \emph{learning} process of ANNs is to determine values for each of the weights
based on known pairs of feature vectors and target values.

\item {\bf Biases}\\
Each node of an ANN except for the nodes in the input layer
is assigned a real value, called a {\em bias},
which, just like the edge weights, is determined through the learning process.

\item {\bf Activation function}\\
%
In an ANN, each node produces an output as a function, called the \emph{activation function},
of its input.
We assume that each node has the Rectified Linear-Unit (ReLU) function
as its activation function,
which can be expressed exactly in the MILP formulation
for the inverse problem on ANNs~\cite{AN19}.
%https://scikit-learn.org/stable/modules/generated/sklearn.neural\_network.MLPRegressor.html

\item {\bf Mixed-Integer Linear Programming (MILP)}\\
%
A type of a mathematical programming problem
where all the constraints are given as linear expressions, and
some of the decision variables are required to take
only integer values.
For more details, see any standard reference, e. g.~\cite{LP}.

\item {\bf Graph} \\
An abstract combinatorial construction comprising
a finite set of {\em vertices}, and a finite set of {\em edges},
where each edge is a pair of vertices.
We treat {\em undirected} graphs,
i. e., graphs where edges are unordered pairs of vertices.
For more information, see e. g.~\cite{graph}.

\end{itemize}

% \newpage

\section{The Program's Input and Output}
\label{sec:InOut}

This section explains the format of the input and the output of the program.
Section~\ref{sec:section3_1} illustrates an example of the program's input format,
and Section~\ref{sec:section3_2} gives a concrete computational example.
Following, Section~\ref{sec:section3_3} illustrates an example of the program's output format,
and Section~\ref{sec:section3_4} gives a concrete computational example.

\subsection{Program Input}
\label{sec:section3_1}

This section gives an explanation of the input to the program.

First
the input requires three textual files containing \\
~~~~- the descriptor names, in csv format \\
~~~~- the weights and biases of a trained ANN in textual format.\\
For a common prefix {\tt TT} which the program accepts as a command-line parameter,
these files must be saved with file names {\tt TT\_desc.csv},
{\tt TT\_weights.txt} and {\tt TT\_biases.txt} for the files containing
the descriptor names, the weights, and the biases of a trained ANN, respectively.
%
Next, comes the target value for which we wish to infer
a chemical graph based on the trained ANN given above.
Following is a chemical specification given in a textual file,
as described in~\cite{cyclic_BH_arxiv},
as well as a filename prefix for the output files,  which are described in Section~\ref{sec:section3_4}.

Finally, comes a choice of MILP solver program to be used.
We can choose \\
~~~~- 1: CPLEX, a commercial MILP solver~\cite{cplex}. \\
(Note, in this case the parameter {\tt CPLEX\_PATH} in the file {\tt infer\_cyclic\_graphs\_ec\_id\_vector.py}
must be set to the correct path of the CPLEX program executable file.) \\
~~~~- 2: CBC, a free and open-source MILP solver. It comes together with the PuLP package for Python~\cite{PuLP1}.

\subsection{Input Data Format}
\label{sec:section3_2}

This section presents an actual example of an input instance of the program.
In particular, we give a concrete example of the three input files
mentioned in Section~\ref{sec:section3_1}.

The purpose of this program is to calculate a feature vector that will produce a desired output from a
given trained ANN.
Figure~\ref{fig:sample} gives an example of a trained ANN.

\begin{figure}[H]
  \centering
  \includegraphics[width=0.5\textwidth]{./fig/ANN_sample_en}
  \caption{An example of a trained ANN.
		      The ANN's weights are given in red numbers, and
		      its biases in blue.
		    }
  \label{fig:sample}
\end{figure}

The information on the trained ANN is written in two text files, containing the information
on the ANN's weights and biases, respectively.
First, we give the structure of the file that contains the information on the ANN's weights.
The first line of this text file contains the information on the ANN's architecture, i. e.,
the number of nodes in each of its layers.
From the second row and onward
follows the information on the
weights in the ANN.
Each row contains the weights of the edges that are incident to one node of the ANN,
first of the nodes in the input layer, and then for the nodes of the hidden layers.
Following is a textual example for the ANN given in Fig.~\ref{fig:sample}.

\bigskip

\begin{oframed}
{\bf Organization of the text file containing weight data}\\\\
%\bigskip\bigskip
3 2 1\\
1.1 2.3\\
-0.4 0.8\\
1.8 3.1\\
2.6\\
1.5\\
\end{oframed}

\bigskip

Next, comes the text file with the information on the ANN's biases.
The bias values from Fig.~\ref{fig:sample} are given below.

\bigskip

\begin{oframed}
{\bf Bias values}\\\\
%\bigskip\bigskip
0.7\\
-1.2\\
2.1\\
\end{oframed}

\bigskip

Last comes a text file containing data on the feature vector.
The first line of this file contains the names of the descriptors used in the feature vectors.
Following form the second row onward, are the numerical values of the descriptors for each chemical graph
in the training dataset, one row per chemical graph.
For an example, please check one of the files  {\tt TT\_desc.csv},  in the folder {\tt ANN},
where ${\tt property} \in \{{\tt FP, LP, SL}\}$.

\subsection{Program Output}
\label{sec:section3_3}

This section gives an explanation of the output of the program.
If there exists an acyclic chemical graph with a feature vector that
would result with the given target value as a prediction of
the given trained ANN, the program will output the feature vector.
In case such a chemical graph does not exist, the program will report this.
The next section gives an explanation of the output of the program.

\subsection{Output Data Format}
\label{sec:section3_4}

This section describes the output data of the program as
obtained on a personal computer.

Once invoked, the program will print some messages to the standard error
stream, which appear on the terminal.
Once the MILP solver completes the computation,
the status of the computation is printed on the terminal.

\bigskip

\begin{oframed}
{\bf Text output on the terminal}\\\\
%\bigskip\bigskip
\begin{tabular}{l l}
 Initializing Time: 0.809                &         \# Written to {\tt stderr} \\
Start Solving Using CPLEX...      &       \# Written to {\tt stderr} \\
Status: Feasible 				&       \# Solution status \\
MILP y*: 197.922 				&      \# Calculated target value in the MILP  \\
ANN propagated y*: 197.922     &      \# Target value calculated by the trained ANN  \\
All descriptors match    		&      \# Descriptor values due to the MILP and the inferred  graph \\
Solving Time: 16.711                     &      \# Time taken by the MILP solver \\
\end{tabular}

\end{oframed}

Finally, if there exists a feasible solution the program writes to disk two text files.
Recall that as a part of the input the program requires a filename
used for the output files.
Assume that the supplied parameter is {\tt filename}.
Then, the resulting two text files are named \\
- {\tt filename.sdf} \\
- {\tt filename\_partition.sdf}.

\noindent
The file {\tt filename.sdf} contains information
on the inferred chemical graph in the SDF (Structure Data File)
format.
For more information see the official documentation (in English) \\
\url{http://help.accelrysonline.com/ulm/onelab/1.0/content/ulm_pdfs/direct/reference/}\\
\phantom{\url{http://}} \url{ctfileformats2016.pdf} \\
for detail.

\noindent
The file {\tt filename\_partition.sdf} contains a
decomposition of the cyclic graph from the
file {\tt filename.sdf} into acyclic subgraphs,
as described in~\cite{cyclic_BH_arxiv}.

\section{Invoking the Program and a Computational Example}
\label{sec:Exp}

This section explains how to invoke the program
and explains a concrete computational example.
Following is an example of invoking the
program {\tt infer\_cyclic\_graphs\_ec\_id\_vector.py}.

\subsection{Executing the Program}
\label{sec:Exp_1}

First make sure that the terminal is
correctly directed to the location
of the {\tt source\_code} folder, as described in Section~\ref{sec:Intro}. \\

\noindent
{\tt
 python  infer\_cyclic\_graphs\_ec\_id\_vector.py
trained\_ann\_filename\_prefix
target\_value \\
 \phantom{python }
 chemical\_specification
output\_file\_name
solver\_type
 }\\

As an example we use the target property Flash Point (closed cup),
that is, the files from the trained ANN with filename prefix {\tt FP},
target value 200,
the file {\tt instance\_a.txt} for a chemical specification,
and CPLEX~\cite{cplex} as an MILP solver (parameter value 1).

{\tt
 python infer\_cyclic\_graphs\_ec\_id\_vector.py
ANN/FP
200 \\
 \phantom{python }
chemical\_specification/instance\_a.txt
result
1
 }\\

By executing the above command, the following text should appear on the terminal prompt.

\bigskip

\begin{oframed}
{\bf Text output on the terminal}\\\\
%\bigskip\bigskip
 Initializing Time: 0.809  \\
Start Solving Using CPLEX...\\
Status: Feasible 		\\
MILP y*: 197.922 		\\
ANN propagated y*: 197.922 \\
All descriptors match    	\\
Solving Time: 16.711
\end{oframed}

The contents of the output files {\tt result.sdf} and
{\tt result\_partition.txt} are as follows.

\bigskip

\begin{oframed}
{\bf File {\tt result.sdf}}\\\\
\begin{verbatim}
 1
MILP_cyclic
ec_id_vector
 43 46  0  0  0  0  0  0  0  0999 V2000
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  2  0  0  0  0
  1 24  1  0  0  0  0
  2 25  1  0  0  0  0
  2 41  1  0  0  0  0
  3  4  1  0  0  0  0
  3 23  2  0  0  0  0
  3 38  1  0  0  0  0
  4  5  2  0  0  0  0
  4 33  1  0  0  0  0
  5 24  1  0  0  0  0
  6 12  1  0  0  0  0
  6 18  1  0  0  0  0
  7  9  1  0  0  0  0
  7 11  2  0  0  0  0
  7 28  1  0  0  0  0
  8  9  1  0  0  0  0
  8 10  1  0  0  0  0
 10 11  1  0  0  0  0
 11 12  1  0  0  0  0
 12 17  1  0  0  0  0
 13 14  1  0  0  0  0
 13 17  1  0  0  0  0
 13 19  1  0  0  0  0
 14 15  1  0  0  0  0
 14 16  1  0  0  0  0
 17 18  2  0  0  0  0
 18 22  1  0  0  0  0
 19 20  1  0  0  0  0
 19 21  1  0  0  0  0
 19 23  1  0  0  0  0
 22 23  1  0  0  0  0
 24 25  1  0  0  0  0
 25 26  1  0  0  0  0
 25 27  1  0  0  0  0
 28 29  1  0  0  0  0
 28 30  1  0  0  0  0
 30 31  1  0  0  0  0
 30 32  1  0  0  0  0
 33 34  1  0  0  0  0
 34 35  1  0  0  0  0
 35 36  1  0  0  0  0
 35 37  1  0  0  0  0
 38 39  1  0  0  0  0
 39 40  3  0  0  0  0
 41 42  1  0  0  0  0
 42 43  3  0  0  0  0
M  END
$$$$
\end{verbatim}
\end{oframed}

\bigskip

\begin{oframed}
{\bf File {\tt result\_partition.txt}}\\\\
\begin{verbatim}
12
9
0 1
10
0 0
11
0 0
12
0 0
13
1 3
17
0 0
18
0 1
19
0 1
22
0 0
23
0 1
24
0 2
25
0 4
15
9 7 11
1 3
9 8 10
0 3
10 11
0 0
11 12
0 0
12 6 18
0 1
12 17
0 0
13 17
0 0
13 19
0 0
17 18
0 0
18 22
0 0
19 23
0 0
22 23
0 0
23 3 4 5 24
4 6
24 1 2 25
3 5
24 25
0 2
\end{verbatim}
\end{oframed}

\begin{thebibliography}{99}
  \bibitem{AN19}
    T.~Akutsu and H.~Nagamochi.
    A Mixed Integer Linear Programming Formulation to Artificial Neural Networks,
    in Proceedings of the 2019 2nd International Conference on Information Science and Systems,
    pp.~215--220, https://doi.org/10.1145/3322645.3322683.

  \bibitem{cyclic_BH_arxiv}
	  T.~Akutsu and H.~Nagamochi.
	  A Novel Method for Inference of Chemical Compounds with Prescribed Topological Substructures Based on Integer Programming.
	  Arxiv preprint, arXiv:2010.09203

%   \bibitem{graph} 茨木俊秀，永持仁，石井利昌．グラフ理論ー連結構造とその応用ー．朝倉書店，2010．
%
%   \bibitem{LP} 福島雅夫．数理計画入門．朝倉書店，2012．
  \bibitem{LP} J.~Matousek and B.~G\"{a}rtner.
			      Understanding and Using Linear Programming. Springer, 2007.

  \bibitem{graph} M.~S.~Rahman.
			      Basic Graph Theory. Springer, 2017.

  \bibitem{PuLP1} A Python Linear Programming API, \url{https://github.com/coin-or/pulp}.

  \bibitem{PuLP2} Optimization with PuLP, \url{http://coin-or.github.io/pulp/}.

  \bibitem{PuLP3} The Python Papers Monograph, \url{https://ojs.pythonpapers.org/index.php/tppm/article/view/111}.

  \bibitem{PuLP4} Optimization with PuLP, \url{https://pythonhosted.org/PuLP/}.

  \bibitem{cplex}
{IBM ILOG CPLEX Optimization Studio~12.8 User Manual}.
\newblock
  \url|https://www.ibm.com/support/knowledgecenter/SSSA5P_12.8.0/ilog.odms.studio.help/pdf/usrcplex.pdf|.

\end{thebibliography}

\end{document}


\documentclass[]{article}
\usepackage{amsmath}

%opening
\title{Engineering Statistics Lectures XVII}
\author{Notes by Jonathan Bender}
\date{November 14, 2019}

\begin{document}

	\maketitle

	\begin{abstract}
		Opportunity \#1 given November 26, 2019 and due November 27, 2019 at 6:00 PM.
		Final opportunity given sometime during the week of December 10, 2019.
		LCCC community dinner on November 27, 2019 from 5:00 PM to 7:00 PM, room AT134.

		Opportunity \#1 Questions due Sunday November 24, 2019 by 8:00 PM by email. Questions can range from any section, focusing on material from Lecture 16 onward (Chapter 5).
	\end{abstract}

	\section{Hypergeometric Functions?}

		3 conditions:
		\begin{enumerate}
			\item Population is a finite set of some size N.
			\item Members of the population are either a success or failure; there are a fixed number of successes K in the population.
			\item Take a sample of size n from the population -- Each sample of size n is equally "likely". Let X be the number of successes in this sample set.
			\item X is bounded: $max(0,\ n-[N-k]) \leq X \leq min(n,\ k)$ such that "n-[N-k]" is the minimum number of possible failures among the sample set.
			\item $\mu_X = \dfrac{k}{N}(n)$
			\item Finite population correction factor = $\dfrac{N-n}{N-1}$
			\item $\sigma_X^2 = \dfrac{n * k}{N} * (1-\dfrac{k}{N}) * (\dfrac{N-n}{N-1}) = \mu_X * P(Fail) * (Finite\ population\ correction\ factor)$
		\end{enumerate}

		Suppose that N = 16, k = 4, n = 7: The bounds are $max(0,7-[16-4]),min(4,7)$, which simplifies to [0, 4].

	\pagebreak
	\section{Noah has raccoons?}

		Spoz Noah wants to yell at North Ridgeville metropolis about his raccoon problem. Suppose there are 30 raccoons near his house. Noah captures and tags 11 raccoons, then he sets them free. Later, Noah captures a sample set of size 6. Let's define a success as one of the previously-tagged raccoons being currently captured.

		\subsection{A. Mean?}
			$\mu_X = \dfrac{11}{30}*6 = \dfrac{22}{10} = 2.2$ successes on average.

		\subsection{B. Bounds?}
			Minimum bound is the maximum of 0 and the number of failures, or 0 and 6-19. So, 0. Maximum bound is the minimum of the sample size and the number of successes, which is the sample size. So, [0,6].

		\subsection{C. P(more than two, no more than four) being tagged?}

			P($2<X\leq 4$) = P($X=3 \cap X=4$) = $P(X=3) \cup P(X=4)$

			P(3) = $\dfrac{\binom{11}{3} * \binom{19}{3}}{\binom{30}{6}}$

			P(4) = $\dfrac{\binom{11}{4} * \binom{19}{2}}{\binom{30}{6}}$

			Result is left as an exercise in arithmetic: $\dfrac{545}{1496}$

		\subsection{D. Variance?}
			$\sigma_X^2 = \mu_X * P(Fail) * (Finite\ population\ correction\ factor)$
			$ = \dfrac{22}{10} * (\dfrac{19}{30}) * (\dfrac{30-6}{30-1})$

	\section{Ian has skunks?!}
		Spoz we have N skunks; Ian captures and tags 5. He then captures 10 at another time. Because the number of untagged skunks is 8, we know that there are at least 13 skunks in circulation, but this is ultimately an inconclusive way of estimating the value. Still -- valuable for the future.

		We assume that, if $\mu_X = 2 = (\dfrac{k}{N})n = (\dfrac{5}{N})10$, then $N = \dfrac{50}{2} = 25$. This can be used for estimating animal populations.

\end{document}


\section{Prob 2. d)}

Results of the rejection sampling are shown in Fig. \ref{fig:fig4}.

\lstinputlisting{sampling.py}

\begin{figure}[ht!]
  \centering
  \includegraphics[width=0.9\linewidth]{./plots/rejection_sampling.png}
  \caption{Rejection sampling of $n(x)$.}
  \label{fig:fig4}
\end{figure}

Output of $r$, $\phi$ and $\theta$ for 100 satellites.

\lstinputlisting{positions.txt}


% Created 2019-10-17 jue 19:04
\documentclass[presentation,aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{khpreamble}
\usepackage{amssymb}
\DeclareMathOperator{\shift}{q}
\DeclareMathOperator{\diff}{p}
\usetheme{default}
\author{Kjartan Halvorsen}
\date{\today}
\title{Computerized Control - Polynomial design}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs 25.3.50.2 (Org mode 8.2.10)}}
\begin{document}

\maketitle

\section{Intro}
\label{sec-1}

\section{2-dof controller}
\label{sec-2}

\begin{frame}[label=sec-2-1]{Two-degree-of-freedom controller}
\begin{center}
\includegraphics[width=0.8\linewidth]{../../figures/2dof-block-explicit-no-delay}
\end{center}
\end{frame}

\section{Problem 5.3}
\label{sec-3}
\begin{frame}[label=sec-3-1]{Åström \& Wittenmark problem 5.3}
Consider the system given by the pulse-transfer function
\[ H(z) = \frac{z+0.7}{z^2 -1.8z + 0.81} \]
Use polynomial design (RST) to determine a controller such that the closed-loop system from command input to output has the characteristic polynomial
\[ A_c(z) = z^2 - 1.5z + 0.7. \]
Let the observer polynomial have as low order as possible, and place all observer poles in the origin (deadbeat observer). Consider three cases
\begin{description}
\item[{(a)}] Positional control with cancellation of the process zero
\item[{(b)}] Positional control with no cancellation of the zero
\item[{(c)}] Incremental controller with  no cancellation of the zero
\end{description}
\end{frame}

\begin{frame}[label=sec-3-2]{Why cancel the process zero?}
Bode plots of closed-loop systems (from reference signal to output) with and without cancellation of the process zero:

\begin{center}
\includegraphics[width=0.6\linewidth]{../../figures/aw5_3_bode}
\end{center}
\end{frame}

\begin{frame}[label=sec-3-3]{Preliminary exercise}
Which of the closed-loop responses below  corresponds to (I) Positional control with zero cancellation (II), Positional control without zero cancellation, (III) Incremental control without zero cancellation.
\begin{center}
\includegraphics[width=0.45\linewidth]{../../figures/aw5_3_refstep}
\includegraphics[width=0.45\linewidth]{../../figures/aw5_3_diststep}
\end{center}
\end{frame}
% Emacs 25.3.50.2 (Org mode 8.2.10)
\end{document}


% JuliaCon proceedings template
\documentclass{juliacon}
\setcounter{page}{1}
\usepackage{verbatim}
\usepackage{svg}
\usepackage{amsmath}

\begin{document}

\input{header}

\maketitle

\begin{abstract}

Data from various fields have their suitable structure. Nowadays, applicable data in
artificial intelligence are images, text and speech. These data can be represented as vector
or matrix structure. However, some data are not suitable for matrix structure or it can be
sparse to fit in matrix structure. For example, social network in social science, biological
network in biology and traffic network represent their data in graph or network structure.
Usually, measurement of these data lies in non-Euclidean space. To utilize network
representation as input for deep learning model, geometric deep learning, or its subfield
called graph neural network, learns topological information provided by network structure
and latent information from input features simultaneously. A geometric deep learning
framework in Julia is proposed, GeometricFlux.jl. GeometricFlux.jl is a Julia package for
geometric deep learning on graph. It extends Flux.jl, a well-known machine learning
framework in Julia, to accept network structure as model input. Some well-known and key
graph convolutional layers are implemented in GeometricFlux.jl. It relies on Zygote.jl for
automatic differentiation engine. ScatterNNlib.jl acted as independent package contains
essential scatter/gather operations and their gradient for GeometricFlux.jl. To leverage
existing JuliaGraphs ecosystem, GeometricFlux.jl accepts graph data structure constructed
from JuliaGraphs. Layers implemented in GeometricFlux.jl are compatible with Flux.jl layers.
Thus, dropout, batch normalization and dense layers are applicable when using Flux and
GeometricFlux.jl together. GPU computation is necessary and is supported by CUDA.jl as well.
Static and variable graphs are supported for efficiency and various network structure input,
respectively. Message-passing scheme \cite{gilmer2017} and graph network block \cite{battaglia2018}
are implemented as flexible and integrated framework. The performance of scatter operations
are benchmarked and it outperforms pytorch-scatter on cuda. I propose a novel and competitive
geometric deep learning library in Julia.

\end{abstract}

\section{Introduction}

Geometric deep learning emerges as a subfield of deep learning. It learns with irregular
structured data and features. Topological information from graph is embedded with features
through the whole neural network. Graph neural network provides a generic approach \cite{gilmer2017,battaglia2018}
for learning topological information together with features to get precisely prediction.
However, integration of scientific computing, software architecture, graph representation
and dataset preparation is challenging. GPU computation on irregular data struture is not
commonly supported. A well-defined graph neural network framework is needed for researchers
to operate with. I proposed GeometricFlux, a geometric deep learning extension of a deep learning
library, Flux, in Julia. Graph convolutional layers are organized in the design of message
passing scheme. Graph network block is implemented as a generic version of message passing
scheme. Leveraging Julia ecosystem, operations on CPU and GPU are optimized with SIMD and
CUDA.jl, respectively. Graph representations are supported with general array or graphs from
JuliaGraph ecosystem.
A github repository is available in https://github.com/yuehhua/GeometricFlux.jl.

\begin{figure*}[t]
\resizebox{180mm}{!}{\input{figures/scatter_add.pdf_tex}}
\caption{Benchmark for scatter add on CPU and GPU.}
\label{fig:scatter_add}
\end{figure*}

\begin{figure*}[ht]
\resizebox{180mm}{!}{\input{figures/scatter_mean.pdf_tex}}
\caption{Benchmark for scatter mean on CPU and GPU.}
\label{fig:scatter_mean}
\end{figure*}

\begin{figure*}[ht]
\resizebox{180mm}{!}{\input{figures/scatter_max.pdf_tex}}
\caption{Benchmark for scatter max on CPU and GPU.}
\label{fig:scatter_max}
\end{figure*}

\section{Extending Framework}

An extending framework is designed to integrate message-passing scheme and graph network (GN)
block in GeometricFlux. Message-passing scheme is defined in two functions: message function
and update function. Message function passes states on node itself and its neighbors or edges
and give messages. Aggregate function is used to aggregate messages into single outcome.
Update function takes node state and aggregated message, and then update the result as new
node state. Precisely, message-passing scheme can be described as follow:

\[
    \begin{aligned}
    m_i^{(t+1)} &= agg_{j \in \mathcal{N}(i)}(M(x_i^{(t)}, x_j^{(t)}, e_{ij})) \\
    x_i^{(t+1)} &= U(x_i^{(t)}, m_i^{(t+1)})
    \end{aligned}
\]

Message function $M$ and update function $U$ are predefined by a network layer or users.
A message for node $i$ is calculated for $t+1$-th layer, which is denoted as $m_i^{(t+1)}$,
and aggregated in elementwise manner by operation $agg$ with neighbors of $i$. A new node $i$
state $x_i^{(t+1)}$ is computed for $t+1$-th layer as an outcome from update function.

GN block defines a more general operations on graph. It updates edge, node and global states
individually. Aggregate functions are applied after updating states and merge states from edges
to nodes, from edges to global and from nodes to global. GN is implemented as an abstract
type in Julia and coupled with a series of update functions and aggregate functions as API
for overriding. As a special case of GN, message-passing network is defined as subtype of GN.
Update functions are defined as follow:

\[
    \begin{aligned}
    e_k' &= \phi^e (e_k, v_i, v_j, g) \\
    v_i' &= \phi^v (\bar{e}_i', v_i, g) \\
    g' &= \phi^g (\bar{e}', \bar{v}', g)
    \end{aligned}
\]

and aggregate functions are

\[
    \begin{aligned}
    \bar{e}_i' &= \rho^{e \rightarrow v} (\{e_k', i, j\}_{j \in \mathcal{N}(i),k = (i, j)}) \\
    \bar{e}' &= \rho^{e \rightarrow g} (\{e_k\}_{k \in E}) \\
    \bar{v}' &= \rho^{v \rightarrow g} (\{v_i\}_{i \in V})
    \end{aligned}
\].

New states for edges, nodes and global graph are updated by $\phi^e$, $\phi^v$ and $\phi^g$,
respectively. $\phi^e$ takes edge state $e_k$, corresponding node state $v_i$, $v_j$ and
global state $g$, and then outputs a new edge state $e_k'$ for edge $k$.
$\rho^{e \rightarrow v}$ aggregates states of edge incident to node $i$.
$\rho^{e \rightarrow g}$ and $\rho^{v \rightarrow g}$ functions aggregate all edge states and
node states into a global state, respectively. It is designed as a whole in single layer
such that a GN block can be use as an unit of a neural network.

\section{Static and Variable Graph Support}

In graph neural network, static graph structure is required for computation efficiency;
while variable graph carried by input features is used to train neural network on various
graph topology. Static graph should be given during constructing GNN layers; while variable
graph is packed within FeaturedGraph data structure as input of GNN layer. Static graphs are
processed for efficiency in prior during constructing GNN layer and variable graphs are
processed during network training time. In this framework, graph network block is designed as
fundamental layers. Each layer accepts input of node features, edge features, global features
and graph. Graph structures from Graphs.jl, SimpleWeightedGraphs.jl and MetaGraphs.jl
are accepted. FeaturedGraph is designed as generic data structure for containing different
kinds of features and graph structure.

\section{Compatible with Flux Layers}

In general, the layer design of graph neural network is different from regular layer of
neural network. The layer of graph neural network accepts at least features and graph as input.
In our architecture, we accept node features, edge features, global features and graph as input.
To make layer design compatible with regular neural network needs complicated design in
each GNN layer. GNN layers are designed with two version, one for FeaturedGraph input and
the other for normal feature input. GNN layers are designed to be consistent with input type
and output type. Output of regular feature will be the input of regular Flux layer.
Conclusively, layers implemented in GeometricFlux are compatible with regular Flux layers.

\section{Integration with JuliaGraphs}

JuliaGraphs already forms a whole ecosystem for graph operations, graph visualization and
solving problems in graph theory. Graphs.jl and SimpleWeightedGraphs.jl provides the
graph construction and representation in unweighted and weighted graphs.
MetaGraphs.jl provides user the chance to assign properties on nodes, edges or global graph.
Integration with JuliaGraphs ecosystem provides more ways to assign graph to model and
reduce the effort of transformation between data types. Graph representation constructed
from Graphs.jl, SimpleWeightedGraphs.jl and MetaGraphs.jl are accepted in construction
of geometric deep learning model in GeometricFlux. Under construction of graph convolutional
layer, a static graph is accepted as one of arguments of neural network layer during
configuring model. In the context of using variable graph, FeaturedGraph also accepts graph
representation constructed from Graphs.jl, SimpleWeightedGraphs.jl and MetaGraphs.jl
and can be fed as sample directly to model. This feature accepts graph representations
from JuliaGraphs ecosystem to geometric deep learning model.

\section{Performance Evaluation}

Julia community is always interested to performance issues of all kinds of computation.
Scatter functions are benchmarked to show the fundamental operations in graph neural network
model. Matrix addition and multiplication is to convolutional neural network as scatter
operations is to graph neural network. I compared time consumption on scatter add function
between pytorch geometric and GeometricFlux. The functionality of scatter operations are
separated as independent packages of pytorch scatter and ScatterNNlib for pytorch geometric
and GeometricFlux, respectively. Benchmark are performed on Intel i7-8700K machine with a
Nvidia Titan XP and Ubuntu 20.04 64-bit. Software of ScatterNNlib.jl v0.1.1 and CUDA.jl v1.2.1
with Cuda version of 10.1 is used. For pytorch, Pytorch v 1.6.0 and Pytorch-scatter v 2.0.5
are tested. I benchmarked on both CPU and GPU with scatter add (\autoref{fig:scatter_add}), mean (\autoref{fig:scatter_mean})
and max (\autoref{fig:scatter_max}).

\section{Datasets Preparation}

Datasets are preprocessed and prepared by GraphMLDatasets.jl. Currently, the citation graphs
Cora, CiteSeer, PubMed and Cora-Full datasets \cite{sen2008,bojchevski2018deep} are
provided. Scientific datasets such as molecule datasets QM7b \cite{montavon2013} and
protein-protein interaction graphs \cite{hamilton2017} are also provided.

\section{Conclusion}

I introduced GeometricFlux for deep learning on graph. An extending framework is designed
to be the core of GeometricFlux and it also supports of static and variable graph.
JuliaGraph ecosystem is also integrated to provide more graph representations.
Effective scatter operations are implemented to accelerate model training and inference.
These make GeometricFlux as a prototype of playground for geometric deep learning in Julia.
Finally, I will keep working to implement more network layers on graph and more prepared
datasets.

\section{Acknowledgments}

I personally thank Ching-Wen Cheng for suggestions on scatter operation implementation.

\input{bib.tex}

\end{document}

% Inspired by the International Journal of Computer Applications template


\subsection{Example: A simple activated sludge model: }
 creation of a simple activated sludge model for BOD removal using GIFMod is demonstrated. Figure \ref{fig:21} shows the schematic of the activated sludge system. A two component model with substrate identified by $S$ and biomass identified by $X$ will be created. The parameters of the model are listed in table \ref{table:ASM}.

\begin{figure}[!ht]\label{fig:21}
\begin{center}
\includegraphics[width=8cm]{Images/Figure21.png} \\
\caption{Activated Sludge System schematic}
\end{center}
\end{figure}

\begin{table}
\caption{Parameters of the activated sludge model example}
\begin{tabular}{l l}\label{table:ASM}
parameter & value \\
\hline
Volume of aeration tank & 8468$m^3$ \\
Volume of the clarifier & 60$m^3$ \\
maximum growth rate ($\mu_{max}$) & 6$day^{-1}$ \\
Substrate half saturation constant ($k_s$) & 20mg-COD/L \\
Biomass decay rate ($k_d$) & 0.12$day^{-1}$ \\
Yield coefficient for heterotrophic growth ($Y$) & 0.4  mgVSS/mgCOD. \\
Inflow flow rate ($Q_{in})$ & 22464$m^3/day$ \\
Inflow substrate concentration ($S_{in}$) & 224$mgCOD/L$ \\
Wasting flow rate ($Q_{WAS}$) & 300 $m^3/day$ \\
Return flow rate ($Q_{RAS}$) & 13478 $m^3/day$ \\
Area of the clarifier & 3000$m^2$ \\
Depth of the clarifier & 2m \\
Settling velocity of biomass & 100$m/day$ \\
 \end{tabular}\\
\end{table}

Steps to create the simple activated sludge model:
\begin{itemize}
\item \textbf{Start GIFMod}
\item \textbf{Setting the duration of the simulation: } We want the simulation to run for 20 days so a
steady-state solution is achieved. In order to do so go to \textbf{Project Explorer}$\rightarrow$\textbf{Project Setting} and from the \textbf{Properties} window set the simulation end date to January 20, 1900. This result in a period of simulation from 0 to 20days.
\item \textbf{Add Aeration Tank: } We will use the \textbf{Pond} block to create the components of the model including the aeration tank, the clarifier and the reservoirs to hold the effluent and waste flow. Other blocks types could also be used as we will use the \textbf{quasi steady-state} method to calculate flows. \\
- Add a pond to represent the aeration pond. \\
- Set the following properties:
- \textbf{Name: } \textit{Aeration Tank} \\
- \textbf{Bottom area: }\textit{8468$m^2$} \\
- \textbf{Initial water depth: }\textit{1m} \\
\textbf{Note: } As long as a depth and area result in the required volume of 8468$m^3$, the depth and bottom area will not influence the results. If aeration was to be considered, then the area could determine the rate of dissolved oxygen flux into the pond depending on the external flux model (See section \ref{sssec:ExtFlux}).\\
\item \textbf{Adding other ponds: } The clarifier will be modeled using two vertically connected ponds and two additional ponds will be used to retain waste and effluent flow. A larger number of layers could be used to represent the clarifier but to keep this example simple, it is limited to two ponds. \\
Add the following pond blocks:\\\\
\textbf{Clarifier top: }\\
- \textbf{Name: } \textit{Clarifier top} \\
- \textbf{Bottom area: }\textit{30$m^2$} \\
- \textbf{Initial water depth: }\textit{1m} \\\\
\textbf{Clarifier Bottom: }\\
- \textbf{Name: } \textit{Clarifier bottom} \\
- \textbf{Bottom area: }\textit{3000$m^2$} \\
- \textbf{Initial water depth: }\textit{1m} \\
- \textbf{Bottom elevation: }\textit{-1m}\\
\textbf{Note: } The bottom elevation of the lower compartment of the clarifier need to be below the bottom elevation of the top compartment for the settling of biomass to be appropriately calculated in the clarifier.\\\\
\textbf{Waste Storage: }\\
- \textbf{Name: } \textit{Waste Storage} \\
- \textbf{Bottom area: }\textit{3000$m^2$} \\
- \textbf{Initial water depth: }\textit{0} \\\\
\textbf{Effluent Storage: }\\
- \textbf{Name: } \textit{Effluent Storage} \\
- \textbf{Bottom area: }\textit{3000$m^2$} \\
- \textbf{Initial water depth: }\textit{0} \\
\item \textbf{Adding Connections: } Connect the following pond blocks together: \\
- \textbf{Aeration Tank} to \textbf{Clarifier top}\\
- \textbf{Clarifier Top} to \textbf{Clarifier bottom}\\
- \textbf{Clarifier Top} to \textbf{Effluent Storage}\\
- \textbf{Clarifier Bottom} to \textbf{Waste Storage}\\
- \textbf{Clarifier Bottom} to \textbf{Aeration Tank}\\
- Enter a length of 1 for all the connectors.

\textbf{Note: } The length that is entered for the connectors is not actually used in calculations of flow because the quasi-steady state approach will be used. But GIFMod does not allow connectors with zero lengths so the value must be entered. After adding the connectors the model configuration should look like figure \ref{fig:22}.
- Select the connector from \textbf{Clarifier top} to \textbf{Clarifier bottom} and set the \textbf{Settling} property to \textbf{Yes}. This forces the model to consider settling advective transport in this connector.

\begin{figure}
\begin{center}
\includegraphics[width=10cm]{Images/Figure22.png} \\
\caption{Activated sludge model configuration in GIFMod}\label{fig:22}
\end{center}
\end{figure}
\item \textbf{Adding constituents: } Two constituents  including substrate (S) and biomass (X) will be considered in the model.
- Add two constituents by right-clicking on \textbf{Project Explorer}$\rightarrow$\textbf{Water Quality}$\rightarrow$\textbf{Constituents} and then choose \textbf{Add Constituents} from the drop-down menu. Change the name of the first constituent to \textbf{S} and the second one to \textbf{X}.
- Change the settling velocity of the \textbf{X} constituent to 100m/day.
\item \textbf{Inflow rate and characteristics: } The inflow characteristics input file looks like figure \ref{fig:23}. Create this file or upload it from the example folder and save it in a folder on your hard drive as inflow.csv or any other names you desire.
//- Click on the aeration tank and from the \textbf{Inflow time-series} property in the properties window select the file containing the inflow time series. Note that only to time-point are needed because the flow rate and characteristics are assumed to be constant throughout the simulation.
\begin{figure}
\begin{center}
\includegraphics[width=5cm]{Images/Figure23.png} \\
\caption{Inflow input file for the activated sludge example}\label{fig:23}
\end{center}
\end{figure}
The quasi steady state hydraulics mode solve the flow rates in each connector by assuming that the summation of inflows and outflows are equal. At this point if we consider a quasi-steady state flow there are 5 connectors while the inflow=outflow condition can only be applied to the three blocks that have more than one connectors connected to them (i.e. Aeration tank, Clarifier top, and Clarifier bottom) and so there is only three equations for five unknowns. However, in activated sludge systems typically the waste and return flows are controlled. We impose the flow rates in the RAS and WAS connectors using prescribed flow. The input prescribed flow files for the two connectors are shown in figure \ref{fig:24}. Create the files and save them respectively as return.csv and waste.csv.
\begin{figure}
\begin{center}
\begin{tabular}{c c}
a) \includegraphics[width=5cm]{Images/Figure24.png} & b) \includegraphics[width=5cm]{Images/Figure24b.png}\\
\end{tabular}

\caption{a) return and b) waste flow input file for the activated sludge example}\label{fig:24}
\end{center}
\end{figure}
Note that the heading line for the prescribed flow input files are not necessary, so deleting the first line in the files will not affect the output. \\\\
- Click on connector connecting \textbf{Clarifier bottom} to the \textbf{Aeration tank} (i.e. return activated sludge connector). \\\\
- From the properties window, set \textbf{Use prescribed flow} to \textbf{Yes} and choose return.csv as the \textbf{Prescribed flow time series}. \\\\
- Do the same for the connector from \textbf{Clarifier bottom} to {Waste Storage} and pick waste.csv as the \textbf{Prescribed flow time series}. \\
\item \textbf{Biomass Settling in the clarifier: } In order to force the biomass in the clarifier the settling property of the connector connecting the top clarifier compartment to the lower clarifier compartment should be set to \textbf{Yes}. Click on the connector connecting \textbf{Clarifier top} to \textbf{Clarifier bottom} and from the properties window look for the \textbf{Settling} option and set it to \textbf{Yes}.
\item \textbf{Biomass initial condition: } The should be some biomass in the clarifier initially for the biomass growth to be possible. We will start from a small (1$mg/L$) concentration of biomass. Click on the aeration tank and click on the box in front of \textbf{Constituent Initial Concentration}. From the window that will pop up, select X as the constituent and enter the value 1 under the value column and then close the window (Figure \ref{fig:26}).
\begin{figure}
\begin{center}
\includegraphics[width=8cm]{Images/Figure26.png} \\
\caption{Setting initial biomass concentration in the simple activated sludge model}\label{fig:26}
\end{center}
\end{figure}

\item \textbf{Entering reaction parameters: }\\
- Right-click on \textbf{Project Explorer}$\rightarrow$\textbf{Water Quality}$\rightarrow$\textbf{Reactions}$\rightarrow$\textbf{Reaction parameters} and click on \textbf{Add reaction parameter} item from the drop-down menu. \\
- Type "$\sim mu\_max$" in the name field and enter a value of 6.
- Similarly add the other reaction parameters including $k_d$, $Y$ and $K_s$ with values of respectively 0.12, 0.4, and 20.
\item \textbf{Setting up reactions: }\\
- Right-click on \textbf{Project Explorer}$\rightarrow$\textbf{Water Quality}$\rightarrow$\textbf{Reactions}$\rightarrow$\textbf{Reaction network} and click on \textbf{Open Reaction Network Window}. \\
- Enter the processes names, rate expressions and stoichiometric constants as see in figure \ref{fig:27}.
\begin{figure}
\begin{center}
\includegraphics[width=8cm]{Images/Figure27.png} \\
\caption{Reaction network for the simple activated sludge model}\label{fig:27}
\end{center}
\end{figure}
\item \textbf{Turning off reactions in clarifier and waste and effluent storage blocks}: In most activated sludge models the reactions in claifier is neglected. Also in order to use the waste storage and effluent storage to gain information about the characteristics of effluent and storage it may be desirable to preserve the mass balance in these two blocks by turning off reactions in them. \\
- Turn off reactions in \textbf{Clarifier top}, \textbf{Clarifier bottom}, \textbf{Waste Storage}, and \textbf{Effluent Storage} blocks by clicking on them and switching the value of \textbf{Conduct reactions} to \textbf{No}. \\
\item \textbf{Running the simulation} Now the model is ready. Click on the \textbf{forward run} icon icon \includegraphics[width=0.5cm]{Icons/run_icon.png} on the tool bar on the left side of the screen and wait for the simulation to end.
\textbf{Inspecting the results: } Right-click on the \textbf{aeration tank} and click \textbf{Water quality results}$\rightarrow$\textbf{S} to see the variation of substrate in the aeration tank. Do the same thing for \textbf{X}. Similar to the previous example you can copy the two graphs unto each other (Figure \ref{fig:32}).
\begin{figure}
\begin{center}
\includegraphics[width=8cm]{Images/Figure32.png} \\
\caption{S and X variation in the simple ASM model}\label{fig:32}
\end{center}
\end{figure}

\end{itemize}


\documentclass[a4paper,11pt]{article}

\usepackage[francais]{babel}
\usepackage[utf8]{inputenc}
\usepackage[official]{eurosym}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{float}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{algorithmic, algorithm}

\begin{document}
\hskip-2.7cm
  \begin{minipage}[c]{17cm}
  \vskip-2cm
    \begin{minipage}[c]{2cm}
      \includegraphics[width=2cm]{img/logo-telecom-paristech.png}
    \end{minipage}
    \begin{center}
      \vspace*{2cm}

      {\LARGE Project Report}

      {\LARGE \textbf{Turing's Morphogenesis}}

      \vspace*{1cm}

      {\large \textbf{Olivier Le Floch},} code written with Thomas Deniau,
      March 20, 2009
    \end{center}
  \end{minipage}

\section{Introduction}

The phenotypes of multicellular living organisms such as mammals exhibit many
specific and complex shapes and textures. Since they have a rather limited
number of genes -- about 20.000 for humans \cite{human_genome} -- the
mechanics that generate these shapes must be very simple. In particular, this
means that they very probably use a limited number of chemicals that interact
together in a chaotic manner to form emergent complex patterns. In 1952,
Turing \cite{turing} proposed a simple diffusion-reaction model to try to
account for the observed genesis of planar patterns with only two chemicals :
$A$ is a pigmented catalytic molecule, and $B$ destroys $A$. The creation of
$B$ and $A$ is catalyzed by $A$. Additionally, both $A$ and $B$ follow a
standard diffusion differential equation. Our program solved the following
differential equation system based on Turk's \cite{turk} work on texture
generation :

\begin{eqnarray}
  A(t) &=& F(A, B) + D_A \nabla^2 A \\
  B(t) &=& G(A, B) + D_B \nabla^2 B
\end{eqnarray}

where $F(A, B) = D_s (16 - A B)$ and $G(A, B) = A B - B - \beta$. $D_A$ and
$D_B$ are diffusion speeds for both chemicals, $D_S$ is the reaction speed,
and $\beta$ is the decay rate of $B$.

\section{Technical solutions and challenges}

As can be seen in the \verb|README| file for \verb|PyMoprhogenesis|, we
implemented this solution in a graphical application based on Qt and OpenGL
using python bindings. The application can also be launched from the command
line in order to be able to easily specify parameters for automated batch
runs.

We encountered two problems in implementing this project : poor performance
for mathematical calculations in python, and sensitivity of the output to
small changes in the input parameters ($D_A$, $D_B$, $D_s$, $\beta$).

To improve performance, we used Blitz++ \cite{weave} \cite{performancepython}.
This allowed us to manipulate NumPy arrays in python when speed wasn't an
issue, i.e. for glue code : passing the image to OpenGL as a texture was coded
purely in python, for instance. On the other hand, when performance was
required, for instance for the diffusion calculations, we were able to
seamlessly manipulate the same arrays in C++ code directly embedded in our
python code, and compiled and cached at run-time so as to have no explicit
compilation phase and near-native performance. We didn't do any rigourous
benchmarks, but the performance improvement was by several orders of
magnitude, going from more than a second per iteration to less than a
hundredth of a second.

To find adequate values for the parameters, we added an option to
automatically run the program from a set of given parameter values, and coded
a script that outputted 80 images obtained from these values at iteration
1000. We then compared the images, and be exploring values around the most
interesting image outputs, obtained some results summed up in section
\ref{sec:results}.

\section{Results} % (fold)
\label{sec:results}

Our goal was to produce textures that were as close as possible to real world
animal skin patterns. As we were using only one pigmented chemical, and since
the parameter space is very large, the results we obtained were not perfect.
We did however obtain the following series of pictures, with accompanying
parameter ranges.

\subsection{Stripes} % (fold)
\label{sub:stripes}

We obtained stripes with $D_a > 10 * D_b$. The width of the stripes decreases when $D_s$ increases.

\begin{figure}[!ht]
  \centering
  \includegraphics[width=5cm]{img/stripes.png}
\end{figure}

% subsection stripes (end)

\subsection{Dots} % (fold)
\label{sub:dots}

We obtained dots with $5 * D_b > D_a > 3 * D_b$. The contrast of the dots
relative to the background decreases when $D_s$ increases.

\begin{figure}[!ht]
  \centering
  \includegraphics[width=5cm]{img/dots.png}
\end{figure}

% subsection dots (end)

\subsection{Spots} % (fold)
\label{sub:spots}

We obtained relatively large spots with $D_a >> D_b$. The spots' intensity decreases when $D_s$ increases.

\begin{figure}[!ht]
  \centering
  \includegraphics[width=5cm]{img/spots.png}
\end{figure}

% subsection dots (end)

% section results (end)

\section{Future work}

This work can be improved in the future by using machine learning algorithm
trained on local shape and texture features, extracted using wavelet
approaches for instance, to search more efficiently for interesting values of
the input parameters.

Additionally, as not all textures seem to be reachable through this model when
starting with a purely random, white-noise, isotropic initial distribution for
both chemicals, we may need to add an anisotropic initialisation to allow us
to generate more zebra like, strongly anisotropic textures.

\section{Conclusion}

In conclusion, we produced a python program reproducing results that show that
very simple chemical reactions can account for the creation of shape in living
beings. Our program also provides an interesting technological overview of
simple to deploy technologies to quickly develop applications in python with
performance sufficient for time-consuming numerical calculations.

\begin{thebibliography}{99} % (fold)

\bibitem{turing}
  Alan Turing,
  The Chemical Basis of Morphogenesis,
  \emph{Transactions of the Royal Society B}, Vol. 237, pp. 37-72 (August 14, 1952).

\bibitem{turk}
  Greg Turk,
  Generating Textures on Arbitrary Surfaces Using Reaction-Diffusion,
  \emph{Computer Graphics}, Vol. 25, No. 4, (SIGGRAPH 91), pp. 289-298, July 1991.

\bibitem{human_genome}
  International Human Genome Sequencing Consortium,
  Finishing the euchromatic sequence of the human genome.
  \emph{Nature}, 431 (7011): 931-45, 2004.

\bibitem{lawlor}
  Orion Sky Lawlor,
  Reaction-Diffusion Textures, \\
  \url{http://charm.cs.uiuc.edu/users/olawlor/projects/2003/rd/}

\bibitem{jennings}
  Christopher G. Jennings, \\
  Turing's Reaction-Diffusion Model of Morphogenesis, \\
  \url{http://www.sfu.ca/~cjenning/toybox/turingmorph/}

\bibitem{performancepython}
	Prabhu Ramachandran et al.,
  A comparison of weave with NumPy, Pyrex, Psyco, Fortran and C++ for solving Laplace's equation, \\
	\url{http://www.scipy.org/PerformancePython}

\bibitem{weave}
	Weave, a python package allowing the inclusion of C/C++ code within python code,
	\url{http://www.scipy.org/Weave}

\end{thebibliography}% (end)

\end{document}


\chapter{Objectives} \label{ch-2}

\section{Problem Statement}

The overarching research objective can be expressed with the following statement:

\begin{statement*}
The primary research subject of this thesis will be to study algorithms for operations on non-commutative algebraic structures. In particular, the following problems will be considered:

\begin{itemize}
    \item Computing the minimal polynomial of Drinfeld modules of rank $r > 2$.
    \item Multiplication algorithms for Ore polynomials where $\delta \neq 0$.
    \item Algorithms for linear algebra over coefficient rings consisting of skew polynomials.
\end{itemize}

\end{statement*}

There are three major outcomes of this thesis that we anticipate:

\begin{enumerate}
    \item Provide sharper complexity bounds for existing algorithms.

    \item Develop new algorithms related to non-commutative structures on finite fields that are competitive with the current theory.

    \item Develop concrete implementations of both new and existing algorithms to provide empirical verification of the theoretically derived complexities.
\end{enumerate}

With regards to point 1, algebraic complexity is the more widely used model for performing complexity analysis of algorithms over finite fields. This is related to another issue, namely that computing the action of a map on an element of a finite field is often assigned $O(1)$ complexity regardless of the cost of computing the map for the first time. To provide a more consistent framework within which to analyze algorithms, we aim to convert a number of these bounds to a bit-complexity model.


\chapter{Introduction}

This document is part of package
{\tt ffr-ElectronicStructure.jl} using plane wave basis set.

{\color{red} WARNING: This document is under heavy construction}

\section{Outline}

First, I will describe the top level description about what
the a typical electronic structure calculation based on density functional
theory is carried out. After that, I will break it apart into
smaller pieces which are hopefully easier to implement and be understood.

In a typical DFT calculation we are trying to solve the so-called Kohn-Sham
equations:
\begin{equation}
H_{KS} \psi_{KS} = e_{KS} \psi_{KS}
\end{equation}

Tasks:
\begin{itemize}
\item Setting up data structure for PW basis set
\item Solving Poisson equation using FFT
\item Solving Schrodinger equation: diagonalization, energy minimization
\item Solving KS equation: SCF and energy minimzation
\end{itemize}


\section{Attribute selection}
\subsection{Impact}

\begin{frame}
 \frametitle{Attribute selection}
 \begin{center}
  \alert{Which attribute to select ?}
 \end{center}
 For each project, sort metrics by \emph{Information Gain}:\\
 \vspace{0.2cm}
 \begin{tabular}{ll}
  $InfoGain(A_i)$ = & the number of bits of information obtained\\
   & by knowing the value of attribute $A_i$
 \end{tabular}
 \\
 \vspace{0.4cm}
 Then, in a decreasing order of $InfoGain(A_i)$, compute PD, PF and Bal with the NB+log classifier.
\end{frame}
%discarding a redundant metric could improve performance

\begin{frame}
 \frametitle{Impact of attribute selection}
 \framesubtitle{Linux}
 \begin{center}
  \includegraphics[width=\textwidth]{figures/attributesLinux.png}
 \end{center}
\end{frame}

\begin{frame}
 \frametitle{Impact of attribute selection}
 \framesubtitle{MySQL}
 \begin{center}
  \includegraphics[width=\textwidth]{figures/attributesMysql.png}
 \end{center}
\end{frame}

\begin{frame}
 \frametitle{Impact of attribute selection}
 \framesubtitle{CARDAMOM}
 \begin{center}
  \includegraphics[width=\textwidth]{figures/attributesCardamom.png}
 \end{center}
\end{frame}

\begin{frame}
 \frametitle{Impact of attribute selection}
 \begin{itemize}
  \item Top metrics not the same
  \item Need about 5 top metrics
  \item With all metrics, nearly the same results than with 5
 \end{itemize}
 \vspace{0.5cm}
 \begin{center}
  $\Longrightarrow$ \alert{We keep the full set of metrics.}
 \end{center}
\end{frame}


\chapter{Lists}

A list\index{List} is an object consisting of a sequence of other objects
(including lists themselves), separated by commas and surrounded by
braces.  Examples of lists are:
\begin{verbatim}
        {a,b,c}

        {1,a-b,c=d}

        {{a},{{b,c},d},e}.
\end{verbatim}
The empty list is represented as
\begin{verbatim}
	{}.
\end{verbatim}

\section{Operations on Lists}\index{List operation}

Several operators in the system return their results as lists, and a user
can create new lists using braces and commas.  Alternatively, one can use
the operator LIST to construct a list.  An important class of operations
on lists are MAP and SELECT operations.  For details, please refer to the
chapters on MAP, SELECT and the FOR command.  See also the documentation
on the ASSIST package.

To facilitate the use of
lists, a number of operators are also available for manipulating
them. {\tt PART(<list>,n)}\ttindex{PART} for example will return the
$n^{th}$ element of a list. {\tt LENGTH}\ttindex{LENGTH} will return the
length of a list.  Several operators are also defined uniquely for lists.
For those familiar with them, these operators in fact mirror the
operations defined for Lisp lists.  These operators are as follows:

\subsection{LIST}

The operator LIST is an alternative to the usage of curly brackets. LIST
accepts an arbitrary number of arguments and returns a list
of its arguments. This operator is useful in cases where operators
have to be passed as arguments. E.g.,
\begin{verbatim}
list(a,list(list(b,c),d),e);       ->  {{a},{{b,c},d},e}
\end{verbatim}

\subsection{FIRST}

This operator\ttindex{FIRST} returns the first member of a list.  An error
occurs if the argument is not a list, or the list is empty.

\subsection{SECOND}

{\tt SECOND}\ttindex{SECOND} returns the second member of a list.  An error
occurs if the argument is not a list or has no second element.

\subsection{THIRD}

This operator\ttindex{THIRD} returns the third member of a list.  An error
occurs if the argument is not a list or has no third element.

\subsection{REST}

{\tt REST}\ttindex{REST} returns its argument with the first element
removed.  An error occurs if the argument is not a list, or is empty.

\subsection{$.$ (Cons) Operator}

This operator\ttindex{. (CONS)} adds (``conses'') an expression to the
front of a list.  For example:
\begin{verbatim}
        a . {b,c}     ->   {a,b,c}.
\end{verbatim}

\subsection{APPEND}

This operator\ttindex{APPEND} appends its first argument to its second to
form a new list.
{\it Examples:}
\begin{verbatim}
        append({a,b},{c,d})     ->     {a,b,c,d}
        append({{a,b}},{c,d})   ->     {{a,b},c,d}.
\end{verbatim}

\subsection{REVERSE}

The operator {\tt REVERSE}\ttindex{REVERSE} returns its argument with the
elements in the reverse order.  It only applies to the top level list, not
any lower level lists that may occur.  Examples are:\index{List operation}
\begin{verbatim}
        reverse({a,b,c})        ->     {c,b,a}
        reverse({{a,b,c},d})    ->     {d,{a,b,c}}.
\end{verbatim}

\subsection{List Arguments of Other Operators}

If an operator other than those specifically defined for lists is given a
single argument that is a list, then the result of this operation will be
a list in which that operator is applied to each element of the list.  For
example, the result of evaluating {\tt log\{a,b,c\}} is the expression
{\tt \{LOG(A),LOG(B),LOG(C)\}}.

There are two ways to inhibit this operator distribution.  Firstly, the
switch {\tt LISTARGS},\ttindex{LISTARGS} if on, will globally inhibit
such distribution.  Secondly, one can inhibit this distribution for a
specific operator by the declaration {\tt LISTARGP}.\ttindex{LISTARGP} For
example, with the declaration {\tt listargp log}, {\tt log\{a,b,c\}} would
evaluate to {\tt LOG(\{A,B,C\})}.

If an operator has more than one argument, no such distribution occurs.

\subsection{Caveats and Examples}

Some of the natural list operations such as {\it member} or {\it delete}
are available only after loading the package {\it ASSIST}.

Please note that a non-list as second argument to CONS
(a "dotted pair" in LISP terms) is not allowed
and causes an "invalid as list" error.
\begin{verbatim}
 a := 17 . 4;

***** 17 4 invalid as list
\end{verbatim}
Also, the initialization of a scalar variable is not the empty list --
one has to set list type variables explicitly, as in the following
example:
\begin{verbatim}
 load_package assist;

 procedure lotto (n,m);
  begin scalar list_1_n, luckies, hit;
     list_1_n := {};
     luckies := {};
     for k:=1:n do list_1_n := k . list_1_n;
     for k:=1:m do
       << hit := part(list_1_n,random(n-k+1) + 1);
          list_1_n := delete(hit,list_1_n);
          luckies := hit . luckies >>;
     return luckies;
  end;                             % In Germany, try lotto (49,6);
\end{verbatim}

{\it Another example:} Find all coefficients of a multivariate
polynomial with respect to a list of variables:

\begin{verbatim}
procedure allcoeffs(q,lis); % q : polynomial, lis: list of vars
   allcoeffs1 (list q,lis);

procedure allcoeffs1(q,lis);
  if lis={} then q else
    allcoeffs1(foreach qq in q join coeff(qq,first lis),rest lis);

\end{verbatim}


\chapter*{Abstract}
Different algorithms have been trained by the ATLAS collaboration to separate true hadronically decaying taus from QCD jets. The efficiency of these algorithms is compared in simulation and data and correction factors are derived to account for the differences that may arise from the simulation limitations. Our study makes use of $Z\to\tauh l$ events highly boosted in the transverse plane, where $l=e,\mu$,  to evaluate the performance of the tau-ID algorithms for high-$\pt$ taus. The scale factors are defined as
\begin{equation}
	C_{\text{ID}}=\frac{\mathcal{E}_{\text{MC}}}{\mathcal{E}_{\text{Data}}},\nonumber
\end{equation}
where $\mathcal{E}$ is the efficiency of the algorithms measured in the data and the simulation. In this report we present the value obtained for the scale factors for the classifier \textit{tight-ID} working point. The values are $C_{\text{Tight-ID}}=0.989\pm 0.012\text{(stat)}\pm 0.024\text{(lumi)}\pm 0.028\text{(sys)}$ for the muon-tau final state and $C_{\text{Tight-ID}}=0.974\pm 0.014\text{(stat)}\pm 0.023\text{(lumi)}\pm 0.029\text{(sys)}$ for the electron-tau final state.


\section{Trajectory Optimization Framework}\label{sec:framework}
In addition to providing standardized multi-sensor data, we have created a framework for developing and testing algorithms that aid navigation, where ``navigation'' is defined as continuous self-localization relative to a local or global frame. This framework supports our own data sets as well as user-supplied data. It serves two major purposes: i) To facilitate the development of new trajectory optimization algorithms with a focus on alternative sensors other than GPS; and ii) To assist system integrators who must test a variety of sensors and algorithms on a level playing field and combine them to achieve desired accuracy. Our approach is to define the broad structure of the navigation problem while leaving the details to be implemented differently for each application.

The framework consists of four interfaces (abstract classes) that divide the navigation problem into manageable components, as illustrated in Figure \ref{fig:components}. A \texttt{\small{DynamicModel}} is an algorithm that relates a set of generic parameters to the rigid-body trajectory of a physical system such as a car or airplane. It also generates ``costs'', which are discussed later in this section. Sensor data comes into the system through a customizable hardware abstraction class labeled \texttt{\small{DataContainer}}. Each \texttt{\small{Measure}} relates sensor data to a trajectory hypothesis and generates additional costs. Finally, at the core of the framework is the \texttt{\small{Optimizer}}, which is an algorithm that minimizes a combination of costs by intelligently generating and modifying the parameters of one or more \texttt{\small{DynamicModel}} instances and passing them through zero or more \texttt{\small{Measure}} instances.

\begin{figure}[!htp]
  \begin{center}
  \includegraphics[width=0.97\linewidth]{SimpleBlockDiagram.png}
  \caption{\label{fig:components}Block diagram of framework components.}
  \end{center}
  \vspace{-15pt}
\end{figure}

A user interacts with the framework by specifying a set of components that derive from the framework classes. These components represent the physical system and define ``optimal'' for a specific application. The framework then sets up a scalar objective function to be evaluated and optimized. Further details of this approach are provided below, and framework code is available in both MATLAB and C++ online \cite{functionalnavigation}.

\subsection{Dynamic Model}\label{sec:dynamics}
Consider the following canonical state transition models for continuous and discrete nonlinear systems:

\begin{equation}
\underbrace {{\mathbf{\dot x}}_t  = {\mathbf{f}}\left( {{\mathbf{x}}_t ,{\mathbf{u}}_t ,{\mathbf{v}}_t } \right)}_{{\text{continuous}}}\quad \quad \underbrace {{\mathbf{x}}_{n + 1}  = {\mathbf{f}}\left( {{\mathbf{x}}_n ,{\mathbf{u}}_n ,{\mathbf{v}}_n } \right)}_{{\text{discrete}}}.
\end{equation}

These equations have been established to model the dynamics of numerous physical systems, from Brownian particles to holonomic ground vehicles, fighter jets, and even animals. They are typically placed in an integration loop, such that the state $\mathbf{x}$ is computed incrementally at increasing time instants $t$, given an initial condition. The symbols $\mathbf{x}$, $\mathbf{u}$, and $\mathbf{v}$ all represent vector-valued functions indexed by time. The input $\mathbf{u}$ represents data that is known, and the input $\mathbf{v}$ represents parameters whose probability distributions are known. If an interpolation method is specified, then both the continuous and discrete models can be written in \emph{functional} form as follows:

\begin{equation}
{\mathbf{x}} = {\mathbf{F}}\left( {{\mathbf{v}};{\mathbf{u}}} \right).
\end{equation}

Our \texttt{\small{DynamicModel}} class standardizes the interface to $\mathbf{F}$. It requires that $\mathbf{x}$ contain a $C^1$ continuous $6$-DOF rigid-body trajectory relative to an Earth-Centered Earth-Fixed (ECEF) frame. It accesses the data $\mathbf{u}$ implicitly, a detail that we notate using a semicolon ($;$) in the argument list. It requires that each parameter vector $\mathbf{v}_n$ consist of logical and/or integer parameters. And, it defines an indexing system that allows the domain of $\mathbf{x}$ to grow with the domain of $\mathbf{v}$ in a consistent manner as time moves forward. Finally, assuming that each parameter vector $\mathbf{v}_n$ is independently distributed, the \texttt{\small{DynamicModel}} associates a cost function $r$ with the negative log likelihood of the normalized probability density of $\mathbf{v}_n$ as follows

\begin{equation}
c_n = r\left(\mathbf{v}_n\right) = -\operatorname{ln}\left(\frac{\operatorname{pdf}\left(\mathbf{v}_n\right)}{\left\| {\operatorname{pdf}\left( { \mathbf{v}_n } \right)} \right\|_\infty}\right).
\end{equation}

\subsection{Measure}\label{sec:measures}
Many sensors can be modeled by the canonical form

\begin{equation}
\mathbf{y}_n  = {\mathbf{g}}\left( {\mathbf{x}_n ,\mathbf{u}_n ,\mathbf{w}_n } \right)
\label{eqn:function_measurement}
\end{equation}

\noindent where each measurement $\mathbf{y}_n$ arises from the instantaneous state $\mathbf{x}_n$, the known data $\mathbf{u}_n$, and the stochastic vector-valued function $\mathbf{w}_n$. However, some measurements of interest cannot be accurately modeled in this form, because they are not inherently instantaneous. A prime example is a feature match between two images that were acquired at different times. Regardless of whether one uses Optical Flow \cite{Lucas1981}, SIFT \cite{SIFT}, normalized cross-correlation \cite{Lewis1995}, or another technique, the computed feature displacement will depend on the position and orientation of the sensor at each time. Another sensor example is a gyroscope, which can be modeled as if it measures instantaneous rotation rates, but is most accurately modeled as measuring changes in orientation over discrete time periods.

One approach to dealing with sensors of the type described above is to create a combining function $\mathbf{\psi}_{ab} = \mathbf{\gamma}\left(\mathbf{y}_a,\mathbf{y}_b\right)$, where the pair of indices labeled $ab$ indicate a measurement arising from two times, $n=a$ and $n=b$, sorted such that $a \leq b$. This implies an indexing system that has a graph structure instead of a simple linear index. Each discrete time is associated with a node (or vertex), and each node pair forms an edge. In general, not all of the nodes are connected, making it an incomplete graph. This idea can be incorporated into Equation \ref{eqn:function_measurement} by rewriting it in \emph{functional} form

\begin{equation}
\mathbf{y}_{ab}  = {\mathbf{g}}\left( {\mathbf{x},ab,\mathbf{u},\mathbf{w}} \right)
\label{eqn:functional_measurement}
\end{equation}

\noindent where the sensor accesses its arguments as functions. The functional $\mathbf{g}$ can evaluate the body trajectory at any time in its domain, which we assume includes the span $t\in\left[t_a,t_b\right]$. Likewise, it can evaluate its other arguments within their valid domains. As a generalization of Equation \ref{eqn:function_measurement}, it can also be used to simulate measurements. However, for the purpose of trajectory optimization, simulated measurements may not be necessary, as long as there is a function that can test a hypothetical trajectory against a set of sensor data. Therefore, we define a cost \emph{functional} $s$ associated with data from each algorithm or sensor $m$ as follows:

\begin{equation}
c_{m,ab} = s_m\left(\mathbf{x},ab;\mathbf{u}\right) = -\operatorname{ln}\left(\frac{\operatorname{pdf}_m\left(\mathbf{u}|\mathbf{x},ab\right)}{\left\|{\operatorname{pdf}_m\left( \mathbf{u} |\mathbf{x},ab\right)}\right\|_\infty}\right).
\end{equation}

Our \texttt{\small{Measure}} class standardizes the interface to each $s_m$ without requiring explicit computation of $\mathbf{y}$ or $\mathbf{w}$. This not only has the potential to reduce processor burden, but it also makes it possible to wrap a wide variety of sensors and algorithms with a uniform interface. For example, suppose $s_1$ represents a ``smart camera'' running a sparse feature tracker, and $s_2$ represents a GPS unit. Since they both posess the same interface, they can be tested and their performance can be compared objectively, a property that is especially helpful to system integrators.

\subsection{Optimizer}\label{sec:optimizer}
Once cost functions have been defined, putting together the overall objective is straightforward. All costs are additive by definition, which implies the assumption of independent distributions for each parameter vector in the \texttt{\small{DynamicModel}} and for each edge contributed by each \texttt{\small{Measure}}. Therefore, the optimization problem boils down to the composition

\begin{align}\label{eqn:objective}
{\mathbf{v}}^ * &= \mathop {\operatorname{argmin} }\limits_{\mathbf{v}} \left\lbrace \sum\limits_n {c_n }  + \sum\limits_m {\sum\limits_{ab} {c_{m,ab} } } \right\rbrace \\
 \nonumber &= \mathop { \operatorname{argmin} }\limits_{\mathbf{v}} \left\lbrace \sum\limits_n {r\left( {{\mathbf{v}}_n } \right)}  + \sum\limits_m {\sum\limits_{ab} {s_m \left( {{\mathbf{F}}\left( {{\mathbf{v}};{\mathbf{u}}} \right),ab;{\mathbf{u}}} \right)} } \right\rbrace
\end{align}

\noindent where the solution ${\mathbf{v}}^{*}$ is an optimal parameter hypothesis. To find the optimal trajectory ${\mathbf{x}}^{*}$, this needs to be inserted back through the dynamic model as follows:

\begin{equation}
{\mathbf{x}}^{*} = {\mathbf{F}}\left( {{\mathbf{v}}^{*};{\mathbf{u}}} \right).
\end{equation}

Our \texttt{\small{Optimizer}} class wraps algorithms that query $r$ and $s$ in order to search for global minima in Equation \ref{eqn:objective}. In general, neither convexity nor uniqueness of solution are guaranteed; however, specific sets of components can be designed to offer these guarantees. To facilitate efficient optimization, the costs can be computed individually before the summation takes place. This formulation suggests automated learning of the relationship between time indexed parameters and time indexed graphs of costs, a subject beyond the scope of this paper. In future work, we plan to demonstrate that our framework generalizes a wide range of trajectory optimization techniques including EKF, UKF, gradient descent, genetic algorithm, simplex, and the pose graph method \cite{OlsonGraph2006}.