\documentclass[11pt]{article}

\usepackage{pfFormV8}
\usepackage{pfResV6}
\usepackage{pfColor}
\usepackage{pfArticleV3}
\usepackage{pfHyperrefV2}

\titlepf{Code Writing: DBM \texttt{cf()} Guidelines}
\author{Peter Fontana}
\date{\today}

\begin{document}

\maketitle

\tableofcontents

\section{Overview}

	This document describes the use of the Difference Bound Matrix (DBM) within the code and how/when the conversions to its canonical form (\texttt{cf()}) are applied.  The reader is assumed to have some understand of DBMs when reading this document.  This explains the pruned use of \texttt{cf()} for efficiency of performance while still preserving correctness.

	There are two ideologies of converting to canonical form.  They are:
	\begin{descriptionpf}
		\item[Baseline:] This version converts to \texttt{cf()} immediately after a method alters a DBM to make it not in canonical form.  Slight optimizations are made to avoid unnecessary calls to \texttt{cf()} to improve performance without sacrificing correctness.
		\item[On-The-Fly:] This waits to convert to \texttt{cf()} until right before the canonical form is needed.  Optimizations are made, as well as some preemptive conversions when overall performance will be improved without sacrificing correctness.
	\end{descriptionpf}

\section{Operations and their Relations to \texttt{cf()}}

	For any operator not specified, it is likely not used in the code.  Thus, unless you are willing to further investigate, you should assume \textbf{all input DBMs must be in \texttt{cf()} before calling the method and cannot be assumed to be in canonical form \texttt{cf()} when finished}.
	\par Here is a list of some of the operators:

\begin{descriptionpf}
	\item[DBM Successor Zone (\texttt{succ()}):]  Requires input DBMS to be in canonical form.  \\ Returns a DBM in canonical form (without calling \texttt{cf()}).
	\item[DBM Intersection (\texttt{\&}):]  Does not require input DBMS to be in canonical form.  \\ Returns a DBM (likely) not in canonical form.
	\item[DBM Subset Checks ($\mathtt{\leq, \subseteq}$):]  Requires left input DBM to be in canonical form.  The right input DBM is not required to be in canonical form.  \\ Returns a DBM in canonical form (without calling \texttt{cf()}).
	\item[DBM Emptiness Checks (\texttt{isEmpty()}):]  Requires input DBMS to be in canonical form.  \\ Returns a DBM in canonical form (without calling \texttt{cf()}).
	\item[DBM Clock Reset (\texttt{reset(x)}):]  Requires input DBMS to be in canonical form.  \\ Returns a DBM in canonical form (without calling \texttt{cf()}).  The Algorithm performs a bit extra work to preserve canonical form.

	A special note on reset:  Many resets can be performed at once before calling \texttt{cf()} if the parameters are different clocks (such as resetting a sequence of clocks).  If resetting a set of clocks, one can wait until resetting all of the clocks, and then calling \texttt{cf()} at the end.

	\item[DBM Clock Assignments (\texttt{reset(x,y)}):]  Requires input DBMS to be in canonical form.  \\ Returns a DBM (likely) not in canonical form.

	A special note on Assignments:  Many resets can be performed at once before calling \texttt{cf()} if the parameters are different clocks (such as resetting a sequence of clocks).  If resetting a set of clocks, one can wait until resetting all of the clocks, and then calling \texttt{cf()} at the end.
	\item[DBM Normalization (\texttt{bound()}):]  Requires input DBMS to be in canonical form.  \\ Returns a DBM (likely) not in canonical form.
	\item[DBM Internal Proof Method (\texttt{sucCheck()}):]  Requires input DBMS to be in canonical form.  \\ Returns a DBM in canonical form (without calling \texttt{cf()}).  This is because the DBM uses \texttt{cf()} to help choose a minimal (not nec. minimum) of constraints.
\end{descriptionpf}

\section{Current \texttt{cf()} Conventions used in Code}

	Here this discusses some of the implementation.

\subsection{Common to All Versions}

\begin{enumeratepf}
	\item \textbf{Use of 1-bit \texttt{isCf}}.  This 1-bit variable stores whether the DBM is in canonical form or not.  When \texttt{cf()} is called, it first checks this variable and does nothing if it is set to true.  The program (inside the DBM class) sets this bit to false at the end of any method that modifies the DBM so it may not be in canonical form.
	\item \textbf{Use of \texttt{cf()} Outside DBM Methods}.  The code is implemented so that the programmer calling the DBM methods must call \texttt{cf()} and appropriately use it so DBMs are in canonical form when needed.  While \texttt{cf()} can be used solely within the methods and would provide good programming simplicity and abstraction of the code, using the methods outside of the program allows performance to be fine-tuned.

	This includes the methods like \texttt{succCheck()}, \texttt{incorporateDifferences()} as well as the ones involving placeholders.  One must use \texttt{cf()} either before or after the method, respectively.
	\item \textbf{Notes on \texttt{inv\_chk()}}.  Here, \texttt{cf()} is required before the method is invoked but the returned DBM is not in canonical form.
	%This is because the \texttt{inv\_chk()} method performs a series of DBM intersections.
	However, given the structure  of the method, \texttt{cf()} need not be called within the method.
	\item \textbf{Notes on DBMs in Caches}.  For Performance reasons, all DBMs input into a sequent cache are in canonical form.  This prevents us from having to keep calling \texttt{cf()} every time a sequent is examined in the cache.  Thus, for the \texttt{tabled\_sequent()} method, all DBMs are assumed to be in canonical form before calling the method.
\end{enumeratepf}

\subsection{Specific to Base Implementation}

	Here, the common convention is to convert a returned DBM to \texttt{cf()} as soon as it leaves a method that is not in canonical form.  However, there are some deviations from this and some assumptions that are used:

	\begin{enumeratepf}
		\item Due to the nature of DBM Intersect, we only have to convert to \texttt{cf()} after all the intersections are applied.
		\item As a result, \texttt{retPlaceDBM} (output of function) can be assumed to be in canonical form
		\item At the beginning of the method, \texttt{lhs} and \texttt{place} (input parameter(s)) can be assumed to be in canonical form.
	\end{enumeratepf}

\subsection{Specific to ``On-The-Fly'' Implementation}
	The key to the On-The-Fly Savings is by waiting until necessary to convert to canonical form, some DBMs at some stages do not need to be converted to canonical form.  One instance is when they are only used to be intersected with another DBM.  In this case, the new intersected DBM, but not the other DBM may need to be converted to \texttt{cf()} later. \parspc

	Here, the convention is to wait until absolutely necessary to convert to \texttt{cf()} before doing so.  However, there are some exceptions and certain assumptions that are made as  a result of doing this:

	\begin{enumeratepf}
		\item Before calling a copy constructor, \texttt{cf()} is called so that it will only do its work once instead of doing the same conversion twice (once for each DBM after the copy constructor).
		\item As a result, \texttt{retPlaceDBM} cannot be assumed to be in canonical form.
		\item At the beginning of the method, \texttt{lhs} and \texttt{place} (input parameter(s)) cannot be assumed to be in canonical form.
	\end{enumeratepf}

\begin{examppf}[Reasoning for Using \texttt{cf()} before Copy Constructors]

To Illustrate the Copy Constructor methodology, consider the following code:

\parspc
\begin{algorithmic}[1]
\STATEtt{DBM ph(*lhs);}
\STATEtt{ph.pre()}
\IFtt{(lhs->emptiness())}
\STATEtt{\ldots}
\ENDIF
\end{algorithmic}
\parspc

Here, for different reasons, $ph$ and $lhs$ require to be converted into canonical form.  Calling \texttt{cf()} before the copy constructor allows you to convert them both to canonical form at the same time, instead of having to do the same work twice for each copy of the DBM.

\end{examppf}

\end{document}


\providecommand{\main}{..}
\documentclass[\main/main.tex]{subfiles}
\begin{document}
\clearpage
\section{CpGobsExp}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Beta} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/CpGobsExp}
  \caption{Sampling distribution of metric CpGobsExp}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/CpGobsExp}
  \caption{Values of metric CpGobsExp}
\end{figure}

\clearpage
\section{CpGperCpG}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Beta} distribution.
\begin{figure}
  \includegraphics[width=\textwidth]{distributions/CpGperCpG}
  \caption{Sampling distribution of metric CpGperCpG}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/CpGperCpG}
  \caption{Values of metric CpGperCpG}
\end{figure}

\clearpage
\section{CpGperGC}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gaussian} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/CpGperGC}
  \caption{Sampling distribution of metric CpGperGC}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/CpGperGC}
  \caption{Values of metric CpGperGC}
\end{figure}

\clearpage
\section{DGVCount}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gamma} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/DGVCount}
  \caption{Sampling distribution of metric DGVCount}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/DGVCount}
  \caption{Values of metric DGVCount}
\end{figure}

\clearpage
\section{DnaseClusteredHyp}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gamma} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/DnaseClusteredHyp}
  \caption{Sampling distribution of metric DnaseClusteredHyp}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/DnaseClusteredHyp}
  \caption{Values of metric DnaseClusteredHyp}
\end{figure}

\clearpage
\section{DnaseClusteredScore}
\subsection{Metric sample distribution}
The data points seem to follow \textbf{slightly} a \textbf{Beta} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/DnaseClusteredScore}
  \caption{Sampling distribution of metric DnaseClusteredScore}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/DnaseClusteredScore}
  \caption{Values of metric DnaseClusteredScore}
\end{figure}

\clearpage
\section{EncH3K27Ac}
\subsection{Metric sample distribution}
The data points seem to follow a family of \textbf{Gamma} distributions (a speculation for this distribution could be the different groups from which the data are extracted), we will approximate them to one with a linear combination of the parameters.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/EncH3K27Ac}
  \caption{Sampling distribution of metric EncH3K27Ac}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/EncH3K27Ac}
  \caption{Values of metric EncH3K27Ac}
\end{figure}

\clearpage
\section{EncH3K4Me1}
\subsection{Metric sample distribution}
The data points seem to follow a family of \textbf{Gamma} distributions (a speculation for this distribution could be the different groups from which the data are extracted), we will approximate them to one with a linear combination of the parameters.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/EncH3K4Me1}
  \caption{Sampling distribution of metric EncH3K4Me1}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/EncH3K4Me1}
  \caption{Values of metric EncH3K4Me1}
\end{figure}

\clearpage
\section{EncH3K4Me3}
\subsection{Metric sample distribution}
The data points seem to follow a family of \textbf{Gamma} distributions (a speculation for this distribution could be the different groups from which the data are extracted), we will approximate them to one with a linear combination of the parameters.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/EncH3K4Me3}
  \caption{Sampling distribution of metric EncH3K4Me3}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/EncH3K4Me3}
  \caption{Values of metric EncH3K4Me3}
\end{figure}

\clearpage
\section{GCContent}
\subsection{Metric sample distribution}
The data points seem to be a combination of two \textbf{Gaussian} distributions.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/GCContent}
  \caption{Sampling distribution of metric GCContent}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/GCContent}
  \caption{Values of metric GCContent}
\end{figure}

\clearpage
\section{GerpRS}
\subsection{Metric sample distribution}
The data points seem to follow a family of \textbf{Gamma} distributions (a speculation for this distribution could be the different groups from which the data are extracted), we will approximate them to one with a linear combination of the parameters.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/GerpRS}
  \caption{Sampling distribution of metric GerpRS}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/GerpRS}
  \caption{Values of metric GerpRS}
\end{figure}

\clearpage
\section{GerpRSpv}
\subsection{Metric sample distribution}
The data points seem to follow a family of \textbf{Gamma} distributions (a speculation for this distribution could be the different groups from which the data are extracted), we will approximate them to one with a linear combination of the parameters.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/GerpRSpv}
  \caption{Sampling distribution of metric GerpRSpv}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/GerpRSpv}
  \caption{Values of metric GerpRSpv}
\end{figure}

\clearpage
\section{ISCApath}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gamma} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/ISCApath}
  \caption{Sampling distribution of metric ISCApath}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/ISCApath}
  \caption{Values of metric ISCApath}
\end{figure}

\clearpage
\section{commonVar}
\subsection{Metric sample distribution}
The data points seem to follow an \textbf{Exponential Weibull} distribution.
\begin{figure}
  \includegraphics[width=\textwidth]{distributions/commonVar}
  \caption{Sampling distribution of metric commonVar}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/commonVar}
  \caption{Values of metric commonVar}
\end{figure}

\clearpage
\section{dbVARCount}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gamma} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/dbVARCount}
  \caption{Sampling distribution of metric dbVARCount}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/dbVARCount}
  \caption{Values of metric dbVARCount}
\end{figure}

\clearpage
\section{fantom5Perm}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gamma} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/fantom5Perm}
  \caption{Sampling distribution of metric fantom5Perm}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/fantom5Perm}
  \caption{Values of metric fantom5Perm}
\end{figure}

\clearpage
\section{fantom5Robust}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gamma} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/fantom5Robust}
  \caption{Sampling distribution of metric fantom5Robust}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/fantom5Robust}
  \caption{Values of metric fantom5Robust}
\end{figure}

\clearpage
\section{fracRareCommon}
\subsection{Metric sample distribution}
The data points seem to follow an \textbf{Beta} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/fracRareCommon}
  \caption{Sampling distribution of metric fracRareCommon}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/fracRareCommon}
  \caption{Values of metric fracRareCommon}
\end{figure}

\clearpage
\section{mamPhastCons46way}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gamma} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/mamPhastCons46way}
  \caption{Sampling distribution of metric mamPhastCons46way}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/mamPhastCons46way}
  \caption{Values of metric mamPhastCons46way}
\end{figure}

\clearpage
\section{mamPhyloP46way}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gaussian} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/mamPhyloP46way}
  \caption{Sampling distribution of metric mamPhyloP46way}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/mamPhyloP46way}
  \caption{Values of metric mamPhyloP46way}
\end{figure}

\clearpage
\section{numTFBSConserved}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{exponential} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/numTFBSConserved}
  \caption{Sampling distribution of metric numTFBSConserved}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/numTFBSConserved}
  \caption{Values of metric numTFBSConserved}
\end{figure}

\clearpage
\section{priPhastCons46way}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gamma} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/priPhastCons46way}
  \caption{Sampling distribution of metric priPhastCons46way}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/priPhastCons46way}
  \caption{Values of metric priPhastCons46way}
\end{figure}

\clearpage
\section{priPhyloP46way}
\subsection{Metric sample distribution}
The data points seem to follow an \textbf{Beta} distribution.
\begin{figure}
  \includegraphics[width=\textwidth]{distributions/priPhyloP46way}
  \caption{Sampling distribution of metric priPhyloP46way}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/priPhyloP46way}
  \caption{Values of metric priPhyloP46way}
\end{figure}

\clearpage
\section{rareVar}
\subsection{Metric sample distribution}
The data points seem to follow an \textbf{Beta} distribution.
\begin{figure}
  \includegraphics[width=\textwidth]{distributions/rareVar}
  \caption{Sampling distribution of metric rareVar}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/rareVar}
  \caption{Values of metric rareVar}
\end{figure}

\clearpage
\section{verPhastCons46way}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gamma} distribution.

\begin{figure}
  \includegraphics[width=\textwidth]{distributions/verPhastCons46way}
  \caption{Sampling distribution of metric verPhastCons46way}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/verPhastCons46way}
  \caption{Values of metric verPhastCons46way}
\end{figure}

\clearpage
\section{verPhyloP46way}
\subsection{Metric sample distribution}
The data points seem to follow a \textbf{Gaussian} distribution.
\begin{figure}
  \includegraphics[width=\textwidth]{distributions/verPhyloP46way}
  \caption{Sampling distribution of metric verPhyloP46way}
\end{figure}
\subsection{Metric values}
\begin{figure}
  \includegraphics[width=\textwidth]{plot/verPhyloP46way}
  \caption{Values of metric verPhyloP46way}
\end{figure}

\end{document}


\section{Conclusion}\label{sec:conclusion}
The formulas introduced in the beginning of Hacker's Delight
\cite{Warren:2012:HD:2462741}
form a basis for more complex operations in the book
and have many applications in low level programming.
This paper not only explained why they work the way they do,
but moreover provided an approach to create them from scratch.

Readers who are involved with low level coding
should be encouraged to systematically combine the presented operations
in order to form a compact implementation of their desired function
(instead of searching for it through precompiled lists).
From a theoretical standpoint,
the presented formulas have been identified to be part of
the right to left computability class,
where all included functions can be expressed
with a small set of operations.


\section{Updates: 03/16/2020}%
\label{sec:updates_2020_03_16}
\subsection{Reversibility}%
\label{subsec:reversibility}
Previously, the reversibility checks were only being ran every \(\sim 1000\)
steps during inference, and failed to account for the fact that the L2HMC
updates also flip the direction.

This was modified as follows:
%
\begin{enumerate}
  \item Randomly choose the direction \(d\) to create the initial state
    \(\xi = (x, v, d)\).
  \item Run the dynamics and flip the direction:
    \begin{equation}
      \mathbf{FL} \xi = \mathbf{F}\xi^{\prime} = (x^{\prime}, v^{\prime}, - d)
    \end{equation}
  % \item Flip the direction and run the dynamics in the reverse direction:
  \item Run the dynamics and flip the direction again:
    \begin{equation}
      \mathbf{FL} \xi^{\prime} = \mathbf{F} \xi^{\prime\prime} =
      (x^{\prime\prime}, v^{\prime\prime}, d)
    % \mathbf{F}\xi^{\prime} = (x^{\prime}, v^{\prime}, -d) \rightarrow
    % \xi^{\prime\prime} = (x^{\prime\prime}, v^{\prime\prime}, -d)
  \end{equation}
  \item Check the difference:
    \begin{align}
      \delta x &= x - x^{\prime\prime} \\
      \delta v &= v - v^{\prime\prime}
    \end{align}
\end{enumerate}
%
Following this new procedure, we observe reversibility violations which may
indicate a deeper problem with the algorithm.
%
\begin{figure}[htpb!]
  \centering
  \includegraphics[width=\textwidth]{figures/updates_2020_03_16/reverse_traceplot.pdf}
  \caption{Traceplot of the differences \(\delta x, \delta v\) demonstrating
  the reversibility violation.}
\end{figure}
%
% \begin{figure}[htpb!]
%   \centering
%   \includegraphics[width=\textwidth]{figures/updates_2020_03_16/biased_traceplot.pdf}
%   \caption{Traceplots of various observables. The bias in \(\phi_{P}\) can be
%   seen in the \texttt{plaqs\_diffs} traceplot.}
% \end{figure}
%
%
% \subsection{Symplectic}
% In addition to reversibility, we require our sampler to be \emph{symplectic}.
% %
% Th

% \subsection{Enforcing the gauge condition}%
% \label{subsec:gauge_condition}
% In addition to the reversibility violations described above, an additional
% minor bug in the code was also discovered.
% %
% When running the L2HMC algorithm on the \(2D\) \(U(1)\) lattice gauge model, we
% must enforce that the position coordinate \(x\) remains in \(U(1)\).
% %
% Since we are working with the angle \(x = \phi\) directly, this is done by
% taking
% %
% \begin{equation}
%   x = \mod(x, 2\pi).
% \end{equation}
% %
% Previously, this was being enforced following each update step (following the
% accept/reject step) before passing the new configuration back into the network.
% %
%


%%-*-latex-*-

\chapter*{Foreword}
\addcontentsline{toc}{chapter}{Foreword}
\thispagestyle{empty}

This book addresses a priori different audiences whose common interest
is functional programming.

\emph{For undergraduate students}, we offer a very progressive
introduction to functional programming, with long developments about
algorithms on stacks and some kinds of binary trees. We also study
memory allocation through aliasing (dynamic data-sharing), the role of
the control stack and the heap, automatic garbage collection (GC), the
optimisation of tail calls and the total allocated memory. Program
transformation into tail form, higher\hyp{}order functions and
continuation\hyp{}passing style are advanced subjects presented in the
context of the programming language \Erlang. We give a technique for
translating short functional programs to \Java.

\emph{For postgraduate students}, each functional program is
associated with the mathematical analysis of its minimum and maximum
cost (efficiency), but also its average and amortised cost. The
peculiarity of our approach is that we use elementary concepts
(elementary calculus, induction, discrete mathematics) and we
systematically seek explicit bounds in order to draw asymptotic
equivalences. Indeed, too often textbooks only introduce Bachmann
notation \(\mathcal{O}(\cdot)\) for the dominant term of the cost,
which provides little information and may confuse
beginners. Furthermore, we cover in detail proofs of properties like
correctness, termination and equivalence. An introduction to
operational semantics is given in the context of the programming
language \OCaml, with a hint of type inference.

\emph{For the professionals} who do not know functional languages and
who must learn how to program with the language \XSLT, we propose an
introduction which dovetails the part dedicated to undergraduate
students. The reason of this unusual didactic choice lies on the
observation that \XSLT is rarely taught in college, therefore
programmers who have not been exposed to functional programming face
the two challenges of learning a new paradigm and use \XML for
programming: whereas the former puts forth recursion, the latter
obscures it because of the inherent verbosity of \XML. By learning
first an abstract functional language, and then \XML, we hope for a
transfer of skills towards the design and implementation in \XSLT
without mediation.

This book has also been written with the hope of enticing the reader
into theoretical computing, like programming language semantics,
formal logic, lattice path counting and analytic combinatorics.

I thank Nachum Dershowitz, Fran\c{c}ois Pottier, Sri Gopal Mohanty,
Walter B\"ohm, Philippe Flajolet, Francisco Javier Bar\'on L\'opez,
Ham Jun-Wu and Kim Sung~Ho for their technical help. Most of this book
has been written while I was working at Konkuk University (Seoul,
Republic of Korea), and some parts added while I was at E\"otv\"os
Lor\'and University (Budapest, Hungary).

Please inform me at \url{rinderknecht@free.fr} of any error.

\bigskip

\hfill{}Montpellier, France,

%\hfill\today.

\hfill{}14th January \oldstylenums{2015}.

\hfill{}Ch. Rinderknecht


\documentclass[journal,12pt,twocolumn]{IEEEtran}

\usepackage{setspace}
\usepackage{gensymb}

\singlespacing

\usepackage[cmex10]{amsmath}
%\usepackage{amsthm}
%\interdisplaylinepenalty=2500
%\savesymbol{iint}
%\usepackage{txfonts}
%\restoresymbol{TXF}{iint}
%\usepackage{wasysym}
\usepackage{amsthm}

\usepackage{mathrsfs}
\usepackage{txfonts}
\usepackage{stfloats}
\usepackage{bm}
\usepackage{cite}
\usepackage{cases}
\usepackage{subfig}

\usepackage{longtable}
\usepackage{multirow}

\usepackage{enumitem}
\usepackage{mathtools}
\usepackage{steinmetz}
\usepackage{tikz}
\usepackage{circuitikz}
\usepackage{verbatim}
\usepackage{tfrupee}
\usepackage[breaklinks=true]{hyperref}

\usepackage{tkz-euclide} %loads TikZ and tkz-base

\usetikzlibrary{calc,math}
\usepackage{listings}
    \usepackage{color}
    \usepackage{array}
    \usepackage{longtable}
    \usepackage{calc}
    \usepackage{multirow}
    \usepackage{hhline}
    \usepackage{ifthen}
    \usepackage{lscape}
\usepackage{multicol}
\usepackage{chngcntr}

\DeclareMathOperator*{\Res}{Res}

\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}
\renewcommand\thesubsubsection{\thesubsection.\arabic{subsubsection}}

\renewcommand\thesectiondis{\arabic{section}}
\renewcommand\thesubsectiondis{\thesectiondis.\arabic{subsection}}
\renewcommand\thesubsubsectiondis{\thesubsectiondis.\arabic{subsubsection}}

\hyphenation{op-tical net-works semi-conduc-tor}
\def\inputGnumericTable{}                                 %%

\lstset{
%language=C,
frame=single,
breaklines=true,
columns=fullflexible
}

\begin{document}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{problem}{Problem}
\newtheorem{proposition}{Proposition}[section]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{example}{Example}[section]
\newtheorem{definition}[problem]{Definition}

\newcommand{\BEQA}{\begin{eqnarray}}
\newcommand{\EEQA}{\end{eqnarray}}
\newcommand{\define}{\stackrel{\triangle}{=}}
\bibliographystyle{IEEEtran}
\providecommand{\mbf}{\mathbf}
\providecommand{\pr}[1]{\ensuremath{\Pr\left(#1\right)}}
\providecommand{\qfunc}[1]{\ensuremath{Q\left(#1\right)}}
\providecommand{\sbrak}[1]{\ensuremath{{}\left[#1\right]}}
\providecommand{\lsbrak}[1]{\ensuremath{{}\left[#1\right.}}
\providecommand{\rsbrak}[1]{\ensuremath{{}\left.#1\right]}}
\providecommand{\brak}[1]{\ensuremath{\left(#1\right)}}
\providecommand{\lbrak}[1]{\ensuremath{\left(#1\right.}}
\providecommand{\rbrak}[1]{\ensuremath{\left.#1\right)}}
\providecommand{\cbrak}[1]{\ensuremath{\left\{#1\right\}}}
\providecommand{\lcbrak}[1]{\ensuremath{\left\{#1\right.}}
\providecommand{\rcbrak}[1]{\ensuremath{\left.#1\right\}}}
\theoremstyle{remark}
\newtheorem{rem}{Remark}
\newcommand{\sgn}{\mathop{\mathrm{sgn}}}
\providecommand{\abs}[1]{\left\vert#1\right\vert}
\providecommand{\res}[1]{\Res\displaylimits_{#1}}
\providecommand{\norm}[1]{\left\lVert#1\right\rVert}
%\providecommand{\norm}[1]{\lVert#1\rVert}
\providecommand{\mtx}[1]{\mathbf{#1}}
\providecommand{\mean}[1]{E\left[ #1 \right]}
\providecommand{\fourier}{\overset{\mathcal{F}}{ \rightleftharpoons}}
%\providecommand{\hilbert}{\overset{\mathcal{H}}{ \rightleftharpoons}}
\providecommand{\system}{\overset{\mathcal{H}}{ \longleftrightarrow}}
	%\newcommand{\solution}[2]{\textbf{Solution:}{#1}}
\newcommand{\solution}{\noindent \textbf{Solution: }}
\newcommand{\cosec}{\,\text{cosec}\,}
\providecommand{\dec}[2]{\ensuremath{\overset{#1}{\underset{#2}{\gtrless}}}}
\newcommand{\myvec}[1]{\ensuremath{\begin{pmatrix}#1\end{pmatrix}}}
\newcommand{\mydet}[1]{\ensuremath{\begin{vmatrix}#1\end{vmatrix}}}
\numberwithin{equation}{subsection}
\makeatletter
\@addtoreset{figure}{problem}
\makeatother
\let\StandardTheFigure\thefigure
\let\vec\mathbf
\renewcommand{\thefigure}{\theproblem}
\def\putbox#1#2#3{\makebox[0in][l]{\makebox[#1][l]{}\raisebox{\baselineskip}[0in][0in]{\raisebox{#2}[0in][0in]{#3}}}}
     \def\rightbox#1{\makebox[0in][r]{#1}}
     \def\centbox#1{\makebox[0in]{#1}}
     \def\topbox#1{\raisebox{-\baselineskip}[0in][0in]{#1}}
     \def\midbox#1{\raisebox{-0.5\baselineskip}[0in][0in]{#1}}
\vspace{3cm}
\title{Matrix Theory (EE5609) Challenging Problem}
\author{Arkadipta De\\MTech Artificial Intelligence\\AI20MTECH14002}
\maketitle
\newpage
%\tableofcontents
\bigskip
\renewcommand{\thefigure}{\theenumi}
\renewcommand{\thetable}{\theenumi}
\begin{abstract}
This document proves some properties of matrices.
\end{abstract}
Download latex codes from
%
\begin{lstlisting}
https://github.com/Arko98/EE5609/tree/master/Challenge_7
\end{lstlisting}
%
\section{Problem}
Given two $n \times n$ matrices $\vec{A}$ and $\vec{B}$ prove the following using determinant properties,
\begin{itemize}
    \item $\det\vec{(AB)} = \det\vec{(A)}\det\vec{(B)}$
    \item $\det\vec{(A^T)} = \det\vec{(A)}$
    \item If $\vec{A}$ is a matrix with orthonormal columns then $|\det\vec{(A)}| = 1$
\end{itemize}
\section{Proof}
\subsection{Proof 1}
\textbf{Case 1:} If $\vec{A}$ is not invertible, then $\vec{AB}$ is not invertible. Hence,
\begin{align}
\det\vec{(AB)} & = 0 \quad{\text{[$\because \vec{AB}$ is not invertible]}}\\
\det\vec{(A)} & = 0 \quad{\text{[$\because \vec{A}$ is not invertible]}}\\
\intertext{Hence,}
\det\vec{(AB)} &= \det\vec{(A)}\det\vec{(B)} = 0\label{proof1a}
\end{align}
\textbf{Case 2:} If $\vec{A}$ is invertible then, there exists a series of elementary row operations $\vec{E_k},\vec{E_{k-1}},\dots\vec{E_1}$ such that,
\begin{align}
    \vec{A} = \vec{E_k}\vec{E_{k-1}}\dots\vec{E_1}\label{eq2}
\end{align}
Now, the determinant of an elementary matrix $\vec{E}$ is given as follows -
\begin{align}
\intertext{If $\vec{E}$ interchanges two rows}
\det(\vec{E}) &= -1\label{e1}
\intertext{If $\vec{E}$ multiplies a row with nonzero constant $c$}
\det(\vec{E}) &= c\label{e2}
\intertext{If $\vec{E}$ multiplies Row $i$ by nonzero constant $c$ and adds to Row $j$}
\det(\vec{E}) &= 1\label{e3}
\end{align}
Now, if $\vec{A}$ interchanges two rows and $\vec{E}$ is the corresponding elementary matrix then,
\begin{align}
\det(\vec{EA}) &= -\det(\vec{A}) \quad{\text{[By property]}}\\
\implies\det(\vec{EA}) &= \det(\vec{E})\det(\vec{A})\quad{\text{[From \eqref{e1}]}}\label{a}
\end{align}
If we multiply the $i$th row of $\vec{A}$ by nonzero constant $c$ and $\vec{E}$ is the corresponding elementary matrix then,
\begin{align}
\det(\vec{EA}) &= c\det(\vec{A}) \quad{\text{[By property]}}\\
\implies\det(\vec{EA}) &= \det(\vec{E})\det(\vec{A})\quad{\text{[From \eqref{e2}]}}\label{b}
\end{align}
Lastly, if we multiply the $i$th row of $\vec{A}$ by nonzero constant $c$ and add it to $j$th row of $\vec{A}$ and $\vec{E}$ is the corresponding elementary matrix then,
\begin{align}
\det(\vec{EA}) &= \det(\vec{A}) \quad{\text{[By property]}}\\
\implies\det(\vec{EA}) &= \det(\vec{E})\det(\vec{A})\quad{\text{[From \eqref{e3}]}}\label{c}
\end{align}
Hence, from \eqref{a}, \eqref{b} and \eqref{c} we get, if elementary matrix $\vec{E}$ represents an elementary row operation and \vec{A} is a $n \times n$ matrix then,
\begin{align}
    \det(\vec{EA}) = \det(\vec{E})\det(\vec{A}) \label{Theorem}
\end{align}
Hence from \eqref{eq2} and \eqref{Theorem} we can write,
\begin{align}
\det\vec{(AB)} &= \det(\vec{E_{k}}\dots\vec{E_1}\vec{B})\\
&= \det(\vec{E_k})\det(\vec{E_{k-1}}\dots\vec{E_1}\vec{B})\\
&= \det(\vec{E_k})\det(\vec{E_{k-1}})\dots\det(\vec{E_1})\det(\vec{B})\\
&= \det(\vec{E_k}\vec{E_{k-1}}\dots\vec{E_1})\det(\vec{B})\\
&=\det\vec{(A)}\det\vec{(B)}\label{proof1b}
\end{align}
Hence from \eqref{proof1a} and \eqref{proof1b} proved.

\subsection{Proof 2}
\textbf{Case 1:} If $rank(\vec{A})<n$ then \vec{A} is not invertible and $\det(\vec{A}) = 0$. Since the row rank and the
column rank are equal, it follows that $\det(\vec{A^T}) = 0$, hence for Case 1,
\begin{align}
    \det(\vec{A}) = \det(\vec{A^T})\label{proof2a}
\end{align}
\textbf{Case 2:} $\vec{A}$ is invertible. By Gauss elimination $\vec{A}$ can be reduced to the identity matrix, $\vec{I}$ by elementary row operations. Thus $\vec{A}$ is a product of elementary matrices. Hence,
\begin{align}
\vec{A} = \vec{E_1}\vec{E_2}\dots\vec{E_r}\label{eq3}
\end{align}
Now, each elementary matrix is either symmetric or lower-triangular or upper-triangular and by properties of matrices, determinant of a lower-triangular or upper-triangular matrix is product of it's diagonal elements, hence for every elementary matrix $\vec{E_i}$ we have,
\begin{align}
\det(\vec{E_i}) = \det(\vec{E_i^T})
\end{align}
Hence from \eqref{eq3} we can write,
\begin{align}
\det(\vec{A}) &= \prod_{i=1}^{r} \det(\vec{E_i})\\
&= \prod_{i=1}^{r} \det(\vec{E_i^T})\\
&= \prod_{i=1}^{r} \det(\vec{E_{r-i}^T})\\
&= \det(\vec{A)}\label{proof2b}
\end{align}
Hence, from \eqref{proof2a} and \eqref{proof2b}, Proved.
\subsection{Proof 3}
If $\vec{A}$ has orthonormal columns then,
\begin{align}
\vec{A^T}\vec{A} = \vec{I}\label{eq4}
\end{align}
Again from properties of determinant we have,
\begin{align}
    \det(\vec{I}) = 1\label{eqI}
\end{align}
Hence, we can write from \eqref{eq4} and \eqref{eqI},
\begin{align}
\det(\vec{I}) &= 1\\
\implies\det(\vec{\vec{A^T}\vec{A}}) &= 1\\
\implies\det(\vec{\vec{A^T})\det(\vec{A}}) &= 1 \quad{\text{[By Proof 1]}}\\
\implies\det(\vec{\vec{A})\det(\vec{A}}) &= 1 \quad{\text{[By Proof 2]}}\\
\implies|\det(\vec{A})| &= 1\label{proof3}
\end{align}
Hence from \eqref{proof3} Proved.
\end{document}


\subsection{\textcolor{cyan}{Algorithm description}}\label{sec:pseudocode}

In the following we detail the algorithm of the decoder, see Algorithm \ref{algo:ufbb} for the pseudocode. %To highlight the differences with the Union-Find decoder, Note that this pseudocode includes instructions that are shortened versions of the pseudocode of the Union-Find decoder \cite{delfosse2017almost}. This is done for clarity on the modified additions of the Partitioned-Growth data structure and protocols on top of the Union-Find pseudocode.
The algorithm starts by initializing the node, cluster and spanning trees. Then it loops \todo[inline]{Refine description} %(\ref{algo:B1a}-\ref{algo:B1b}). and describes the loop of cluster growth. Block 2 contains lines \ref{algo:B2a}-\ref{algo:grow} and describes the DFS's related to calculating the node parities and delays from all even subroots stored at the root node, and the DFS of the cluster growth. Block 3 contains lines \ref{algo:B3a}-\ref{algo:B3b} and describes the combined merging protocols of the Union-Find and Partitioned-Growth data structures. Note that lines \ref{algo:dfa}-\ref{algo:dfb} contain an extra step that maintains acyclic spanning-trees. The final block in line \ref{algo:B4a} is the peeling decoder \cite{delfosse2017linear}, which now does not have to create the spanning forest of the grown clusters. Similarly to the Union-Find decoder, Weighted Growth is applied such that the smaller cluster is always grown first.

\begin{algorithm}[h!]
  \BlankLine
  \KwData{A graph $G=(V,E)$, and syndrome $\sigma \subseteq V$}
  \KwResult{Correction set $\m{C}$}
  \BlankLine
  Initialize cluster spanning-trees and node-trees.\;\label{algo:B1a}% and table $\Support$
  Create the list $\m{L}$ of odd clusters.\;
  \While(){$\m{L}$ is not empty}{
    Initialize the fusion list $\m{F}$ as an empty list.\;\label{algo:B1b}
    \For(){cluster $\in\m{L}$ \label{algo:B2a}}{
      Grow node-tree $\nset$ of cluster with \Cref{algo:growdelay}. \label{line:grow}
      % \For(){$N \in\m{R}$ at root node $R$ of $\nset$}{
      %   Apply DFS's to calculate node parities and delays (\Cref{eq:pseudodelay,eq:snodeparity,eq:jnodeparity}) from $N$ to all descendant nodes. Keep track of $\min_{X \in \nset}{\tilde{\delta}_X}$ during the delay DFS.\;\label{algo:pdc}
      % }
      % Apply DFS from root $R$ to all descendants. At each node $N$ during the DFS, if $\delta_N=0$ (\Cref{eq:delay}), grow all boundary edges of vertices in the node a half-edge per the Union-Find decoder, such that grown edges are added to $\m{F}$, and apply $\rho_N=\rho_N +\nicefrac{1}{2}$. \;\label{algo:grow}
      %If $\m{s}(n)\neq0$, apply $n_w=n_w+1$ and continue the DFS.
    }
    \For(){edge $(n,m) \in \m{F}$\label{algo:B3a}}{
      \eIf(){$\Find(n)\neq\Find(m)$}{
        Merge cluster-trees by Weighted $\Union$.\;
        \eIf(){$n \in N$ and $m \in M$\label{algo:joina}}{
          % Merge node-trees by Odd-Rooted $\Nodejoin$. If resulting node-tree with root $R$ is odd, add even subroot (either $N$ or $M$) to list $\m{R}$ at $R$.\;
          Merge node-trees with new edge between $N$ and $M$.
        }($n$ or $m$ does not belong to a cluster){
          Add $n$ to $N$ or $m$ to $M$.\;\label{algo:joinb}
        }
      }($n,m$ in same cluster.\label{algo:dfa}){
        %Subtract 1 from $(u,v)$ in $\Support$.\;
        Nothing to keep both $\vset$ and $\nset$ acyclic.\;\label{algo:dfb}
      }
    }
    Update $\m{L}$ with odd clusters\; \label{algo:B3b}
  }
  Apply the peeling decoder \cite{delfosse2017linear}.\label{algo:B4a}
  \caption{Union-Find Partitioned-Growth}\label{algo:ufbb}
\end{algorithm}


    \filetitle{neighbourhood}{Evaluate the local behaviour of the objective function around the estimated parameter values}{model/neighbourhood}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
[D,FigH,AxH,ObjH,LikH,EstH,BH] = neighbourhood(M,PS,Neigh,...)
\end{verbatim}

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

\begin{itemize}
\item
  \texttt{M} {[} model \textbar{} bkwmodel {]} - Model or bkwmodel
  object.
\item
  \texttt{PS} {[} poster {]} - Posterior simulator (poster) object
  returned by the \href{model/estimate}{\texttt{model/estimate}}
  function.
\item
  \texttt{Neigh} {[} numeric {]} - The neighbourhood in which the
  objective function will be evaluated defined as multiples of the
  parameter estimates.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{D} {[} struct {]} - Struct describing the local behaviour of
  the objective function and the data likelihood (minus log likelihood)
  within the specified range around the optimum for each parameter.
\end{itemize}

The following output arguments are non-empty only if you choose
\texttt{'plot='} true:

\begin{itemize}
\item
  \texttt{FigH} {[} numeric {]} - Handles to the figures created.
\item
  \texttt{AxH} {[} numeric {]} - Handles to the axes objects created.
\item
  \texttt{ObjH} {[} numeric {]} - Handles to the objective function
  curves plotted.
\item
  \texttt{LikH} {[} numeric {]} - Handles to the data likelihood curves
  plotted.
\item
  \texttt{EstH} {[} numeric {]} - Handles to the actual estimate marks
  plotted.
\item
  \texttt{BH} {[} numeric {]} - Handles to the bounds plotted.
\end{itemize}

\paragraph{Options}\label{options}

\begin{itemize}
\item
  \texttt{'plot='} {[} \emph{\texttt{true}} \textbar{} \texttt{false}
  {]} - Call the \href{grfun/plotneigh}{\texttt{grfun.plotneigh}}
  function from within \texttt{neighbourhood} to visualise the results.
\item
  \texttt{'neighbourhood='} {[} struct \textbar{} \emph{empty} {]} -
  Struct specifying the neighbourhood points for some of the parameters;
  these points will be used instead of those based on \texttt{Neigh}.
\end{itemize}

\paragraph{Plotting options}\label{plotting-options}

See help on \href{grfun/plotneigh}{\texttt{grfun.plotneigh}} for options
available when you choose \texttt{'plot='} true.

\paragraph{Description}\label{description}

In the output database, \texttt{D}, each parameter is a 1-by-3 cell
array. The first cell is a vector of parameter values at which the local
behaviour was investigated. The second cell is a matrix with two column
vectors: the values of the overall minimised objective function (as set
up in the \href{model/estimate}{\texttt{estimate}} function), and the
values of the data likelihood component. The third cell is a vector of
four numbers: the parameter estimate, the value of the objective
function at optimum, the lower bound and the upper bound.

\paragraph{Example}\label{example}


\documentclass[simplex.tex]{subfiles}
% NO NEED TO INPUT PREAMBLES HERE
% packages are inherited from simplex.tex; you can compile this on its own
\begin{document}
\subsection{ndreg}
%% Jan

We received three new CLARITY image volumes from our colleagues at Stanford University.
Each dataset contained two channels of a single mouse brain hemisphere at a 585 $\mu m$ $\times$ 585 $\mu m$ $\times$ 5000 $\mu m$ resolution.
The images were ingested and propagated to lower resolutions using NeuroData infrastructure.
NeuroData's registration module (ndreg) was then used to register each image to the Allen institute's mouse Reference Atlas (ARA).

First each image was reoriented to the ARA, the background was subtracted and a mask was generated to eliminate bright regions.
After affine alignment, each Stanford image was deformably aligned to the ARA through Large Deformation Diffeomorphic Metric Mapping (LDDMM).
Since the ARA and CLARITY images differed greatly in intensity profile, mutual information matching was adopted during this step.
Alignment was done in a 3-step multi-resolution approach, with registration at coarser scales initializing the alignment at subsequent finer scales.
It was clear from the ARA-CLARITY checkerboard composite images that registration proceeded successfully (Figure~\ref{fig:ndregAiley}).

\begin{figure}[h!]
\begin{cframed}
\centering
\includegraphics[width=0.75\textwidth]{../../figs/ndreg-ailey.png}
\caption{
  Coronal slices from image volumes.
  From left to right: CLARITY before LDDMM, CLARITY after LDDMM, ARA, checkerboard composite of ARA and CLARITY after LDDMM.
}
\label{fig:ndregAiley}
\end{cframed}
\end{figure}

\clearpage

%% Feb
The NeuroData Registration python module, \textit{ndreg}, uses \textit{Large Deformation Diffeomorphic Metric Mapping (LDDMM)} to register a template image $I_0$ to a target image $J_1$.
It does this by finding smooth invertible map $\varphi$ such that the \textit{matching term} $M(I_0 \circ \varphi^{-1}, J_1)$, a function whose value is small when $I_0 \circ \varphi^{-1}$ is aligned with $J_1$, is minimized.
We compared MI-LDDMM, LDDMM with a Mutual Information based matching term, to our previous SSD-LDDMM and Mask-LDDMM techniques.
SSD-LDDMM uses a Sum of Squared Differences matching term.
As it is based on image subtraction, it assumes that bright regions in $I_0$ align with bright regions in $J_1$.
Mask-LDDMM is SSD-LDDMM in which $I_0$ and $J_1$ are replaced with their respective binary brain mask images $M_0$ and $M_1$.
Since the masks only contain information on which voxels are inside the brain, only edge information is used by Mask-LDDMM.
\\
We placed fiducial landmarks in the corpus callosum and midbrain of four CLARITY template image and the \textit{Allen Reference Atlas (ARA)} target.
After registration corresponding CLARITY landmarks should be close to those of the ARA.
If not then the registration was inadequate.
Figure~\ref{fig:comparison} shows that MI-LDDMM registration performed better than the previous methods.

\begin{figure}[!h]
\begin{cframed}
\centering
 \begin{subfigure}{0.25\columnwidth}
  \includegraphics[width=\textwidth]{../../figs/ssdCoronal.png}
  \caption{SSD-LDDMM}
  \label{fig:clarityCoronalSSD}
 \end{subfigure}
 \begin{subfigure}{0.25\columnwidth}
  \includegraphics[width=\textwidth]{../../figs/maskCoronal.png}
  \caption{Mask-LDDMM}
  \label{fig:clarityCoronalMask}
 \end{subfigure}
 \begin{subfigure}{0.25\columnwidth}
  \includegraphics[width=\textwidth]{../../figs/miCoronal.png}
  \caption{MI-LDDMM}
  \label{fig:clarityCoronalMI}
 \end{subfigure}
 \begin{subfigure}{0.2\columnwidth}
  %\captionsetup{justification=centering} % Center caption
  \includegraphics[width=\textwidth]{../../figs/lmkError.png}
  \caption{Landmark Error}
  \label{fig:lmkError}
 \end{subfigure}
 \caption{Comparison of SSD-LDDMM (\subref{fig:clarityCoronalSSD}), Mask-LDDMM (\subref{fig:clarityCoronalMask}) and MI-LDDMM (\subref{fig:clarityCoronalMI}) registration for a CLARITY mouse brain.
  Panes (\subref{fig:clarityCoronalSSD}-\subref{fig:clarityCoronalMI}) have an ARA coronal slice on the left juxtaposed to the corresponding aligned CLARITY slice on the right.
  Green arrows point out that the corpus callosum is misaligned by SSD-LDDMM but aligned correctly by MI matching.
  Red arrows show that SSD-LDDMM distorts bright regions.
  Fiducial landmarks were placed throughout the corpus callosum, and midbrain of the acquired volumes.
  Pane (\subref{fig:lmkError}) compares mean errors between the deformed CLARITY and ARA landmarks after registration.
 }
 \label{fig:comparison}
\end{cframed}
\end{figure}

\clearpage

%% March
We received a rat brain image acquired using iDISCO microscopy from colleagues at the Johns Hopkins School of Medicine.
iDISCO is a technique for clearing tissues that enables interrogatoion by light-sheet microscopy.
Thus like CLARITY, iDISCO cleared brains can be imaged at high spatial resolution without physical slicing.
The iDISCO volume was ingested into the NeuroData store at its full resolution of 5 $\mu$m isotropic.
We also ingested the widely used Waxholm Rat Atlas, a T2 magnetic resonance image with corresponding labels at a 39 $\mu$m isotropic.\\

\textit{Large Deformation Diffeomorphic Metric Mapping (LDDMM)} is a deformable image registration (alignment) algorithm which computes smooth invertible transforms between images.
Using the \textit{NeuroData Registration (ndreg)} python module we were able to perform a iDISCO to T2 MRI alignment by LDDMM under mutual information matching.
Figure~\ref{fig:idisco} shows the Waxholm Rat Atlas labels overlaid on the iDISCO image.

\begin{figure}[!h]
 \begin{cframed}
  \centering
   \includegraphics[width=\textwidth]{../../figs/iDISCO.png}
   \caption{Waxholm rat atlas labels overlaid on sagittal slices of iDISCO rat brain}
  \label{fig:idisco}
 \end{cframed}
\end{figure}

\clearpage
\end{document}


\documentclass[12pt,letterpaper]{article}
\usepackage{amsmath}
\usepackage{gensymb}
\usepackage{textcomp}
\usepackage[margin=0.7in]{geometry}
\setlength{\parindent}{0pt}
\title{Physics Club Handout 2: Newton's Laws}
\setcounter{page}{2}
\setcounter{section}{1}
\begin{document}
\section{Physics Club Handout: Newton's Laws}
For all these problems, assume acceleration due to gravity is 9.81 m\slash s$^2$.

\paragraph{Beginner problems:}
\begin{enumerate}
\item
A 50 kg human in freefall experiences a force from air resistance equal to $\vec{F}_{air} = -\vec{v}^{\,2}*0.3141\frac{\text{kg}}{\text{m}}$, where $\vec{v}$ is the person's instantaneous velocity. Find the human's terminal velocity.

\item
A hawk flies in a horizontal circle of radius 12 m at a constant velocity of 4 m\slash s. Find its centripital acceleration under these conditions.
The hawk then increases its speed at a rate of 1.2 m\slash s$^2$; find its new acceleration (and the direction of its acceleration).

\item
A 40.0-kg child swings in a swing supported by two chains, each 3.00 m long. The tension in each chain at the lowest point is 350 N. Find the child's speed at the lowest point and the maximum height to which the child rises.
\end{enumerate}

\paragraph{Intermediate problems:}
\begin{enumerate}
\setcounter{enumi}{3}
\item
An object moving through a fluid (at sufficiently high velocity such that viscous forces are insignificant) experiences a retarding force of $\vec{F}_{drag} = -\frac{1}{2}\vec{v}^{\,2}*C$, where $\vec{v}$ is the object's instantaneous velocity, and $C$ is some constant based on the fluid's density and the object's shape.

Given that an object of mass $m$ is dropped in air at time $t = 0$, find the velocity of the object at any given time in terms of $m$, $t$, and $C$.

\item
An amusement park ride is set up as a giant swing that starts at an angle of $80\degree$ to the vertical, and allows the swing to fall freely. For legal reasons, the maximum g-force a rider can experience is $5g$'s (where $g$ = 9.81 m\slash s$^2$). Assuming no air resistance, what is the largest they can make the swing and still avoid litigation?

\item
A plumb bob (a weight hanging from a string) usually does not hang perfectly vertically (i.e. along a line directed towards the center of the earth). By how much does a plumb bob deviate from vertical here in Palo Alto (latitude of 37.4\degree\,N), assuming the earth is spherical and has radius 6380 km?
\end{enumerate}

\paragraph{Advanced problems:}
\begin{enumerate}
\setcounter{enumi}{6}
\item
An object moving througha a fluid experiences a force $\vec{F}_{drag} = -(ar\vec{v} + br^2\vec{v}^2)$ exerted on a sphere of radius $r$ moving through a fluid at speed $v$, where $a$ and $b$ are constants based on the shape of the object and the surrounding atmosphere. For spherical objects in air at sea level, $a = 3.10 \times 10^{-4}\,\text{Pa}\cdot \text{s}$ and $b = 0.870$ g\slash L.
Find the velocity of a water droplet of 100 \textmu m freefalling at time $t$, where $t$ is the time elapsed since it was released from rest.

\item
A 1 kg block is sitting on a table -- the coefficient of static friction between the toaster and the table is 0.4. A string is attached to the block. You pull on the string to make the block move; at what angle should you pull the string to minimize the force necessary to move the block, and what is the force?

\item
A time-dependant force $\vec{F} = (8.00\,\hat{i} -4.00\,t\,\hat{j})\,\text{N}$ (where $t$ is in seconds) is exerted on a 2 kg object initially at rest. At what time will it be moving at a speed of 15 m\slash s? What is the total displacement and distance of the object at this time?
\end{enumerate}

\end{document}


\subsection{gammapy.catalog}
\label{ssec:gammapy-catalog}
\todo{Atreyee}
Gamma-ray catalog access

Comprehensive source catalogs are increasingly being provided by many high
energy astrophysics experiments. gammapy.catalog provides a convenient access
to some common gamma-ray catalogs. A global catalog table is provided, along
with source models flux points and light curves (if available) for individual
objects, which are internally created from the supplied FITS tables. This
module works independently from the rest of the package, and the required
catalogs are supplied in GAMMAPY\_DATA. Presently, catalogs from Fermi-LAT
(standard~\citep{3FGL, 4FGL} and high energy~\citep{2FHL, 3FHL}), H.E.S.S.
galactic plane survey~\citep{HGPS}, HAWC~\citep{2HWC, 3HWC} and gamma-cat
~\citep{gamma-cat}; an open source gamma ray catalog combining information from
multiple catalogs) are supported.

\begin{figure}
	\import{code-examples/generated/}{gp_catalogs}
	\caption{Using gammapy.catalogs: Accessing underlying model, flux points and
		lightcurve from the Fermi-LAT 4FGL catalog for the blazar PKS 2155-304}
	\label{codeexample:data} \end{figure}


\subsection{Model results}
\label{sec:model_results}

\paragraph{Training} The strategy has been optimized using a random search in
the hyperparameter space as commented in section \ref{sec:methods_pipeline_training}.
Primary model results are shown in table \ref{table:primary_model_hyperparameters},
and secondary model results are shown in table \ref{table:secondary_model_hyperparameters}.

\begin{table}[H]
  \centering
  \begin{tabular}{|c | c |}
    \hline
    \multicolumn{2}{|c|}{Primary model} \\
    \hline
    Parameter & Value \\
    \hline
    Moving average fast window length & 5 \\
    \hline
    Moving average slow window length & 30 \\
    \hline
    Profit taking band                & 0.06 \\
    \hline
    Stop loss taking band             & 0.02 \\
    \hline
    Triple barrier window length      & 3 \\
    \hline
    Minimum return                    & 0.005 \\
    \hline
    Volatility window length          & 50 \\
    \hline
  \end{tabular}
  \caption{Primary model hyperparameters.}
  \label{table:primary_model_hyperparameters}
\end{table}

\begin{table}[H]
  \centering
  \begin{tabular}{|c | c |}
    \hline
    \multicolumn{2}{|c|}{Secondary model} \\
    \hline
    Parameter & Value \\
    \hline
    Number of estimators                & 720 \\
    \hline
    Maximum features ratio when bagging & 0.2936 \\
    \hline
    Average uniqueness                  & 0.9502 \\
    \hline
    Cross validation splits             & 6 \\
    \hline
    Embargo                             & 1\% \\
    \hline
  \end{tabular}
  \caption{Secondary model hyperparameters.}
  \label{table:secondary_model_hyperparameters}
\end{table}

\paragraph{Labels} The output of the primary model is summarized in table
\ref{table:labels_metalabel} where we also show the labels and metalabels count.
Also, in \ref{table:label_vs_metalabel} a contingency table between
labels and metalabels is shown. We can see that even though labels are balanced,
there is a bias towards negative metalabels (i.e. do not take the bet) based on
the triple barrier parameters.

\begin{table}[H]
  \centering
  \begin{tabular}{| c | c |}
    \hline
    \multicolumn{2}{|c|}{Labels}      \\
    \hline
    Value & Count                     \\
    \hline
    1 (buy signal) & 80               \\
    \hline
    -1 (sell signal) & 79             \\
    \hline
    \multicolumn{2}{|c|}{Metalabels}  \\
    \hline
    Value & Count                     \\
    \hline
    0 (unreliable label)     & 103    \\
    \hline
    1 (reliable label)       & 56     \\
    \hline
  \end{tabular}
  \caption{Primary model labels and metalabels.}
  \label{table:labels_metalabel}
\end{table}

\begin{table}[H]
  \centering
  \begin{tabular}{|c|c|c|}
    \hline
    Label     & \multirow{2}{*}{0} & \multirow{2}{*}{1} \\ \cline{1-1}
    Metalabel &                    &                    \\ \hline
    1         & 51                 & 29                 \\ \hline
    -1        & 52                 & 27                 \\ \hline
  \end{tabular}
  \caption{Contingency table between labels and metalabels.}
  \label{table:label_vs_metalabel}
\end{table}

\paragraph{Feature importance} Table \ref{table:feature_importance_results}
shows the mean loss in performance per feature after applying the method explained in
\ref{sec:methods_pipeline_feature_importance}. Note that only those features
with mean loss in performance above the mean loss are shown. See figure
\ref{fig:feat_importance} for an in detail mean loss of performance and standard
deviation per feature permutation.

It is interesting to point the groups of features that remained in the final model:

\begin{itemize}
  \item Price and volume features with fractional differentiation.
  \item SADF derived indices with different regression models (constant, linear and
        quadratic) and with one, two and three lag periods for the autocorrelation.
  \item Volatility and logarithmic returns.
  \item Market capitalization.
  \item Fees, transfer volume and days till halving. These are features related
        to the bitcoin ecosystem.
\end{itemize}

However, none of the social features seemed to produce a high impact in the final
model.

\begin{table}[H]
  \centering
  \begin{tabular}{| c | c | c |}
    \hline
    \multicolumn{3}{|c|}{Feature importance} \\
    \hline
    Feature                     & Mean perf. loss & Std. dev. of perf. loss\\ \hline
    CloseFFD                    & 0.039714        & 0.026393 \\ \hline
    HighFFD                     & 0.018739        & 0.019605 \\ \hline
    LowFFD                      & 0.002177        & 0.001215 \\ \hline
    OpenFFD                     & 0.006869        & 0.003897 \\ \hline
    Volume\_(BTC)-log            & 0.032430        & 0.015899 \\ \hline
    Volume\_(Currency)-log       & 0.020350        & 0.008696 \\ \hline
    bsadf\_ct\_1                  & 0.002128        & 0.002060 \\ \hline
    bsadf\_ctt\_1                 & 0.003910        & 0.003278 \\ \hline
    bsadf\_ctt\_2                 & 0.004907        & 0.004139 \\ \hline
    bsadf\_ctt\_3                 & 0.003264        & 0.004178 \\ \hline
    bsadf\_nt\_2                  & 0.003447        & 0.004077 \\ \hline
    daysTillHalving             & 0.003387        & 0.003194 \\ \hline
    fees-mean-log               & 0.004142        & 0.002743 \\ \hline
    log\_ret                     & 0.013930        & 0.006140 \\ \hline
    market-cap-log              & 0.002412        & 0.001501 \\ \hline
    transfer-volume-median-log  & 0.006073        & 0.006431 \\ \hline
    trgt                        & 0.003003        & 0.007776 \\ \hline
    vol\_15                      & 0.008678        & 0.003120 \\ \hline
    vol\_5                       & 0.020516        & 0.015831 \\ \hline
  \end{tabular}
  \caption{Feature performance loss of the secondary model. Only selected features are displayed.}
  \label{table:feature_importance_results}
\end{table}

\begin{figure}[H]
    \centering
    \includegraphics[width=1.35\textwidth, height=\textheight, keepaspectratio, angle=90]{results/images/feat_importance.png}
    \caption{Displays the mean feature importance loss in the bars. Each bar shows one feature. From the top to the bottom, there is one bar per feature in table \ref{table:feature_importance_results} and the rest are unimportant features. The standard deviation across cross validation folds is shown as a red line centered in the mean of each feature.}
    \label{fig:feat_importance}
\end{figure}

A new model was retrained using only these features. That model yields the results
in paragraph \emph{Performance metrics}. Also, as commented in
\ref{sec:methods_pipeline_feature_importance} it is important to explain how
these features are able to produce excess returns. It can be seen that price
related features are the ones that generate the higher mean of performance loss
and it means that a lot of market information is in prices already. Secondly, we
interpret that transacted volumes, both in currency and in bitcoins provide a lot
of information about market tendencies. As outlined in section \ref{sec:methods_features_sadf}
SADF related features determine when regime changes in price series occur and even
though that information is in prices, SADF offers a series that provides direct
information about changes towards explosive behavior. It is not surprising that
the day count until halving provides information and that is also connected with
the two volatility series. We have seen that close to halvings when
issuance changes and produces a considerable change in the network and that definitely
affects market volatility. Market capitalization offers an overall high level
market metric which provides an aggregated indicator of the market and similarly
does the transfer volume which accounts for the amount of currency that is flowing.
Making partitions over these features by means of a tree based model as bagging
ensembles are allows to generate complex relationship between them and identify
patterns.

\paragraph{Performance metrics} Table \ref{table:perf_secondary_model}
shows the F1-score and negative log loss of the retrained secondary model.

\begin{table}[H]
  \centering
  \begin{tabular}{|c | c |}
    \hline
    \multicolumn{2}{|c|}{Secondary model performance} \\
    \hline
    Metric & Value \\
    \hline
    F1-score                & 0.1574 \\
    \hline
    Negative log loss       & 0.6031 \\
    \hline
  \end{tabular}
  \caption{Secondary model classification metrics.}
  \label{table:perf_secondary_model}
\end{table}

F1-score evaluates model's accuracy when classifying samples. Negative log-loss
evaluates model's accuracy of the the estimated probabilities. The secondary
model will not be used as a classifier. Instead, predicted probabilities will
determine the bet size.


 %-------------------------------------------------------------------------------
\section{Introduction}
%-------------------------------------------------------------------------------
Consider the motivating models of \cite{Spence.1973} and \cite{Ben-Porath.1967} as discussed in class.

\begin{boenumerate}
\item For both models, provide a brief description of the question they are designed to address and their key ingredients. Provide two examples of important economic features that are missing from the formal analysis?\\

\noindent{Consider the model developed in \cite{Spence.1973} in more detail. Figure \ref{Model parametrization} visualizes the information about the wage schedule and the cost of education in the parametrized model. Please assume throughout that employers belief that individuals with a level of education $y^* \geq \tfrac{5}{4}$ have a high productivity.}

\begin{figure}[h]\centering
\caption{Model parametrization}\label{Model parametrization}
\subfloat[Wage schedule]{\scalebox{0.25}{\includegraphics{fig-introduction-spence-benefit}}}
\subfloat[Cost of education]{\scalebox{0.25}{\includegraphics{fig-introduction-spence-cost}}}
\end{figure}

\item Write down the parametrization of the cost $(c_L, c_H)$ and wage $(w_L, w_H)$ functions for the high and low productivity individuals.

\item Complete Figure \ref{Canvas Surplus} by adding the surplus functions for each of the two groups over the specified range. Also, indicate the optimal level of schooling for each of the two groups.

\begin{figure}[h]\centering
\caption{Surplus of education}\label{Canvas Surplus}
\scalebox{0.35}{\includegraphics{fig-introduction-spence-surplus-canvas}}
\end{figure}

\item Calculate the range of the separating schooling level $y^*$ that confirms the employer's beliefs.\\

\noindent{Now consider the case where individuals do not have the ability to signal their productivity and the share of individuals with low productivity is denoted by $q_L$.\\}

\item What is the wage for each of the two groups in this scenario as a function of $q_L$?

\item  Complete Figure \ref{Canvas Market Structure} by adding the surplus and wage for the two groups under the scenario where individuals are able to signal their ability and when they are not.

\begin{figure}[h]\centering
\caption{Surplus and market structure}\label{Canvas Market Structure}
\scalebox{0.35}{\includegraphics{fig-introduction-spence-market-structure-canvas}}
\end{figure}

\item What scenario do high productivity individuals prefer, what does their assessment depend on, when exactly do they change their mind?

\end{boenumerate}


\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[frenchb]{babel}

\usepackage{a4wide}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\usepackage{hyperref}

\title{Heuristic Optimization: implementation exercise 1}
\author{Samuel Buchet: 000447808}
\date{March 2017}

\begin{document}

\maketitle

\section{Iterative improvement heuristic}

\subsection{Implementation details}

The implementation has been done in c++ from the sample code.
One improvement function has been written for each neighborhood.
The improvement functions take a parameter that decides the pivoting rule (first or best improvement).
For the first improvement rule, after a new improvement, the algorithm doesn't restart the search from the first neighbor, as seen in class. \newline

One of the main difficulty of the implmentation was the computation of the cost of a solution (weighted completion times sum). The easiest way is to compute the entire sum, starting from the first job.
However, it takes a lot of time and it is not always necessary.
For example, if only the last two jobs are modified in the solution, only the last two completion times need to be re-computed.
To recompute only a part of the solution cost, it is necessary to keep the completion times of each job for each machine.
These times are saved in a matrix in the \textit{PfspInstance} class.
Thanks to this matrix, two functions of the class PfspInstance are available to compute the completion time, one that computes the the total weighted sum and modify the matrix, and another that computes the sum without modifying the matrix.\newline

These two functions are used in the iterative improvement procedures.
The iterative improvement functions have been written for each neighborhood.
The procedures iterate over all neighbours.
If the pivoting rule is the best improvement rule, the best neighbor is saved and the change is done at the end of the procedure.
If the pivoting rule is the first improvement rule, each time an improving neighbor is found, the change is done and the search continue with the new solution. \newline

The transpose improvement procedure is the easiest in the sense that there is no nested loop.
In this procedure, all the possible transpose moves are tried on the solution.
As explained below, it is not necessary to recompute the wighted sum from the first job if the transpose move is not done at the begining of the solution.
However, to do so, the matrix of the completion times of the \textit{initial} solution has to be kept.
That's why the procedure used to compute the weighted sum of a neighbor doesn't modify the matrix.
If the pivoting rule is the first improvement rule and the neighbor improve the solution, the cost is re-computed in order to apply the changes on the completion times matrix (with a second procedure which modify the completion times matrix). \newline

The exchange improvement procedure is very similar.
The only difference is the nested loop.
It is then obvious that this neighborhood is longer to compute than the transpose one.
The insert procedure is also similar.
However, the insertion is properly done only once.
For a given element, the procedure insert it in the first position and the other positions are obained with transpose moves, which is equivalent.
However, the procedure tries the original position of the element and nothing has been done to prevent this case. \newline

All these improvement procedures return a boolean that indicates whether an improving solution has been found or not.
This boolean is used in the iterative improvement procedure to stop the algorithm.
The iterative improvement procedure also initialize the solution with the random permutation or the simplified rz heuristic, depending on the parameters of the algorithm.

\subsection{Experiments}

The following table reports the average of the computation times and the average of the percentage deviations from the best known solution for each algorithm.
best. imp means that the pivoting rule is the best improvement rule and first imp. corresponds to the first improvement rule.
random means that the solution is initialized with a random permutation and srz means that the simplified rz heuristic has been used.
The last parameter is the neighborhood used in the algorithm.

\begin{align*}
\begin{tabular} {|c|c|c|} \hline
    algorithm & average computation time & average percentage deviation \\ \hline
    best imp./random/exchange & 919.706 & 4.383 \\ \hline
    best imp./random/insert & 2721.295 & 3.242 \\ \hline
    best imp./random/transpose & 12.753 & 36.135 \\ \hline
    best imp./srz/exchange & 239.501 & 3.157 \\ \hline
    best imp./srz/insert & 872.557 & 2.231 \\ \hline
    best imp./srz/transpose & 7.757 & 4.304 \\ \hline
    first imp./random/exchange & 93.031 & 3.252 \\ \hline
    first imp./random/insert & 292.007 & 2.676 \\ \hline
    first imp./random/transpose & 1.963 & 36.163 \\ \hline
    first imp./srz/exchange & 80.713 & 3.153 \\ \hline
    first imp./srz/insert & 215.415 & 2.185 \\ \hline
    first imp./srz/transpose & 7.216 & 4.306 \\ \hline
\end{tabular}
\end{align*}

We can see that some algorithms seem to be much worst.
Indeed, the average percentage deviation is quite high for the algorithms using random and transpose parameters.
We can also notice that the algorithms using the transpose neighborhood are much faster.
The algorithms with the insert neighborhood are also the slowest.

\subsection{Statistical tests}

The following statistical tests have been done using the software R. The statistical test used is the Wilcoxon test with a significance level equal to $0.05$.

\subsubsection{Initial solution}

The following table shows the result of the test applied to all pairs of algorithms which differ only between the initial solution.

\begin{align*}
\begin{tabular} {|c|c|c|} \hline
    algorithms compared & p-value & null hypothesis \\ \hline
    best imp. ; exchange & 6.173616e-09 & rejected \\ \hline
    best imp. ; insert & 6.35434e-07 & rejected \\ \hline
    best imp. ; transpose & 1.671329e-11 & rejected \\ \hline
    first imp. ; exchange & 0.5339054 & not rejected \\ \hline
    first imp. ; insert & 0.0005783928 & rejected \\ \hline
    first imp. ; transpose & 1.671329e-11 & rejected \\ \hline
\end{tabular}
\end{align*}

For most of the tests, the null hypothesis is rejected, which means that there is a statistically significant difference between the solution quality. Moreover, with the srz heuristic, the average of the percentage deviation is lower for each algorithm. We can then conclude that the simplified rz heuristic gives better results than the random permutation.

\subsubsection{Pivoting rule}

In this section, the test has been applied to all pairs of algorithms which differ only between the pivoting rule.
This first table contains the results of the tests applied to the average of the percentage deviation.

\begin{align*}
\begin{tabular} {|c|c|c|} \hline
    algorithms compared & p-value & null hypothesis \\ \hline
    random ; exchange & 6.147428e-08 & rejected \\ \hline
    random ; insert & 0.001416562 & rejected \\ \hline
    random ; transpose & 0.7100708 & not rejected \\ \hline
    srz ; exchange & 0.6481444 & not rejected \\ \hline
    srz ; insert & 0.463876 & not rejected \\ \hline
    srz ; transpose & 0.9878667 & not rejected \\ \hline
\end{tabular}
\end{align*}

We can see that there is a statistically significant difference only with two algorithms (which don't use the best initial solution).
Moreover, for these two pairs of algorithms, the first improvement rule seems to give better results. \newline

The table below contains the result od the statistical tests applied to the computation times.

\begin{align*}
\begin{tabular} {|c|c|c|} \hline
    algorithms compared & p-value & null hypothesis \\ \hline
    random ; exchange & 1.671329e-11 & rejected \\ \hline
    random ; insert & 1.671329e-11 & rejected \\ \hline
    random ; transpose & 1.671329e-11 & rejected \\ \hline
    srz ; exchange &5.278219e-11  & rejected \\ \hline
    srz ; insert & 1.671329e-11 & rejected \\ \hline
    srz ; transpose & 3.163469e-06 & rejected \\ \hline
\end{tabular}
\end{align*}

For each pair of algorithms, there is a statistically significant difference beteween the compution times.
The average of the computation times is lower for the first improvement algorithm for each pairs.
We can conclude that the first improvement algorithms are faster and there is no big differences between the quality of the solutions.

\subsubsection{Neighborhood}

In this section, the different neighborhoods are compared. Comparisons are done for each pair of neghborhood (transpose/exchange, transpose/insert, exchange/insert). The p-value returned by the tests of the computation times and the solution quality are indicated in the tables below. \newline

Comparison between the transpose neighborhood and the exchange neighborhood:

\begin{align*}
\begin{tabular} {|c|c|c|c|c|} \hline
    algorithms compared & relative percentage deviation & computation time \\ \hline
    first imp. ; random & 1.671329e-11 & 1.671329e-11 \\ \hline
    first imp. ; srz & 5.282725e-11 & 1.671329e-11 \\ \hline
    best imp. ; random & 1.671329e-11 & 1.671329e-11 \\ \hline
    best imp. ; srz & 1.138656e-10 & 1.671329e-11 \\ \hline
\end{tabular}
\end{align*}

Comparison between the transpose neighborhood and the insert neighborhood:

\begin{align*}
\begin{tabular} {|c|c|c|c|c|} \hline
    algorithms compared & relative percentage deviation & computation time \\ \hline
    first imp. ; random & 1.671329e-11 & 1.671329e-11 \\ \hline
    first imp. ; srz & 1.671329e-11 & 1.671329e-11 \\ \hline
    best imp. ; random & 1.671329e-11 & 1.671329e-11 \\ \hline
    best imp. ; srz & 1.671329e-11 & 1.671329e-11 \\ \hline
\end{tabular}
\end{align*}

Comparison between the exchange and the insert neighborhood:

\begin{align*}
\begin{tabular} {|c|c|c|c|c|} \hline
    algorithms compared & relative percentage deviation & computation time \\ \hline
    first imp. ; random & 0.0006803447 & 1.671329e-11 \\ \hline
    first imp. ; srz & 2.115717e-09 & 1.671329e-11 \\ \hline
    best imp. ; random & 1.345635e-06 & 1.671329e-11 \\ \hline
    best imp. ; srz & 7.033074e-10 & 1.671329e-11 \\ \hline
\end{tabular}
\end{align*}

We can see that for each comparison, the null hypothesis is rejected.
There is a statistically significant difference between the neighborhood in terms of quality and computation time. \newline

%transpos/exchange
For each pair of algorithm, we can see on the table in 2.2 that in average the transpose neighborhood is faster but the quality of the solution found by the exchange neighborhood is better. \newline

%transpose/insert
If we compare the transpose and the insert neighborhoods, we can see that once again, the transpose neighborhood is faster but its quality is worst than the insert neighborhood in average. \newline

%exchange/insert
The comparison of average values between the exchange neighborood and the insert neighborhood indicates that the insert neighborhood is slower than the exchange neighborhood but the quality of its solution is better. \newline

To conclude, the insert neighborhood is the one that generates the best solutions in terms of quality.
However, the transpose neighborhood is the fastest neighborhood. The exchange neighbohood is a good tradeoff because it is faster than the insert one and its quality is better than the transpose one.

\section{Variable Neighborhood Descent heuristic}

\subsection{Implementation details}

The implementation of the VND algorithm mainly uses the procedures created for the iterative improvement algorithms.
The algorithm has been implemented in the \textit{VNDHeuristic} procedure.
It first initialize the solution with the chosen initialization algorithm.
Then, it applies successively the different iterative improvement procedures following the chosen order of the neighbohoods.
This step is repeated until there is no improvement in the last neighborhood.

\subsection{Experiments}

The table below contains the average of the computation time, the average of the percentage deviation of the solution, the average of the percentage improvement over the exchange neighborhood and the average of the percentage improvement over the insert neighborhood. The order used for the neighborhood is transpose - exchange - insert and transpose - insert - exchange. ex. first means that the exchange neighbohood use applied before the insert neighborhood.

\begin{align*}
\begin{tabular} {|c|c|c|c|c|} \hline
algorithm & average compution time & avg percentage deviation & avg imp exchange & avg imp. insert \\ \hline
random ; ex. first & 382.526 & 2.634 & 0.006 & 0.0003 \\ \hline
random ; ins. first & 307.123 & 2.091 & 0.011 & 0.006 \\ \hline
srz ; exchange first & 275.016 & 2.129 & 0.010 & 0.0005 \\ \hline
srz ; insert first & 283.463 & 2.161 & 0.010 & 0.0002 \\ \hline
\end{tabular}
\end{align*}

\subsection{Statistical tests}

The table below contains the p-values obtained with a Wilcoxon test on the vnd algorithms for the quality of the solution and the computation time.

\begin{align*}
\begin{tabular}{|c|c|c|} \hline
    algorithm & computation time & percentage deviation \\ \hline
    srz & 0.1720717 & 0.6274306 \\ \hline
    random & 0.000156713 & 0.0001869606 \\ \hline
\end{tabular}
\end{align*}

The tests indicate that there is no statistically significant differences between the solution qualities and the computation times for the srz heuristic.
However, for the random permutation as initial solution, there is a difference.
For the random permutation, the average of the computation time and the average of the percentage deviation are lower with the insert neighborhood before the exchange neighborhood.
We can conclude that this order is better.
However, regarding the comparison between vnd and the iterative improvement algorithms, the improvement of vnd seems to be very low.

\section{Compilation and execution}

To compile the project, make sure you are in the \textit{code} folder and type the \textit{make} command. \newline

To execute the program, type \textit{./flowshopWCT} in the terminal. You need to specify a valid instance.
You can also specify options to choose the neighborhood, the pivoting rule and the initialization of the solution.
For example, the command \textit{./flowshopWCT yourInstance $--$srz $--$first $--$insert} executes an iterative improvement algorithm with the simplified rz heuristic as initial solution, the first improvement as pivoting rule and the insert neighborhood. Here are all the options available: \newline

\begin{itemize}
    \item neighborhood: $--$insert, $--$exchange, $--$tranpose
    \item initial solution: $--$srz, $--$random
    \item pivoting rule: $--$first, $--$best
\end{itemize}

You can also execute a vnd algorithm. To do that, use the $--$vnd option. To choose the order of the neighborhood, you can precise $--$exfirst and $--$insfirst. And you can still indicate which initial solution to use (vnd uses first improvement rule).

\end{document}


\section{Logical Lifting}

\begin{figure}[t!]
\centering
$$
\begin{array}{rrcl}
\emphbf{Program} \quad
  & \prog & ::= & e \spmid \elet{x}{e}{\gtyp}{[L]}{\prog}\\
  & & \spmid & \eletrec{x}{e}{\gtyp}{[L]}{\prog}
\\[0.03in]

\emphbf{Logic Label} \quad
  & \prog & ::= & A \spmid M \spmid I
\end{array}
$$
\end{figure}
\subsubsection{Axioms}
Axioms that are instantiated via function calls.

\newcommand\exacttype[2]{\ensuremath{\mathtt{exact}(#1, #2)}\xspace}
\newcommand\exacttypefun[3]{\ensuremath{\mathtt{exactfun}(#1, #2, #3)}\xspace}
\newcommand\inline[2]{\ensuremath{[#1 := #2]}\xspace}
\begin{align*}
\embed{\eletrecopt{x}{e}{\gtyp}{A}{\prog}}
  &= \eletrecopt{x}{e}{\exacttype{\gtyp}{e}}{}{\embed{\prog}}\\
\embed{\eletrecopt{x}{e}{\gtyp}{\star}{\prog}}
  &= \eletrecopt{x}{e}{\gtyp}{\star}{\embed{\prog}}\\
\embed{e} &= e
\end{align*}

\begin{align*}
\exacttype{\tref{v}{\btyp}{r}}{e} &= \tref{v}{\btyp}{r \land v = e}\\
\exacttype{\tfun{x}{\typ_x}{\typ}}{\efun{y}{}{e}} &=\tfun{x}{\typ_x}{\exacttype{\typ}{e\subst{y}{x}}}
\end{align*}

\subsubsection{Inlines}
Non-recursive logical macros. Can be used only to non-recursive functions.
\NV{We need to explicitly track recursion}

\begin{align*}
\embed{\elet{f}{\efun{\overline{x}}{}{e}}{\gtyp}{I}{\prog}}
  &= \elet{f}{\efun{\overline{x}}{}{e}}{\gtyp}{}{\embed{\prog\inline{f\ \overline{x}}
  {e}}}\\
\embed{\eletrecopt{x}{e}{\gtyp}{\star}{\prog}}
  &= \eletrecopt{x}{e}{\gtyp}{\star}{\embed{\prog}}\\
\embed{e} &= e
\end{align*}

\begin{align*}
{\eletrecopt{x}{e}{\gtyp}{\star}{\prog}}\inline{f\ \overline{x}}{e_f}\\
  = \eletrecopt{x}{e}{\gtyp\inline{f\ \overline{x}}{e_f}}{\star}{\prog\inline{f\ \overline{x}}{e_f}}\\
e\inline{f\ \overline{x}}{e_f} = e
\end{align*}

\begin{align*}
(\tfun{x}{\typ_x}{\typ})\inline{f\ \overline{x}}{e_f}
 = & \tfun{x}{\typ_x\inline{f\ \overline{x}}{e_f}}{\typ\inline{f\ \overline{x}}{e_f}}\\
\tref{v}{\btyp}{e}\inline{f\ \overline{x}}{e_f}
 = & \tref{v}{\btyp}{e\inline{f\ \overline{x}}{e_f}}
\end{align*}

\begin{align*}
(x\ \overline{e})\inline{f\ \overline{x}}{e_f} &= e_f\subst{\overline{x}}{\overline{e}}\\
c\inline{f\ \overline{x}}{e_f} &= c \\
(\efun{x}{\typ}{e})\inline{f\ \overline{x}}{e_f} &=
\efun{x}{\typ}{e\inline{f\ \overline{x}}{e_f}}\\
(D\ \overline{e})\inline{f\ \overline{x}}{e_f} &=
D\ \overline{e\inline{f\ \overline{x}}{e_f}}\\
x\inline{f\ \overline{x}}{e_f} &= x \\
(e_1 \ e_2)\inline{f\ \overline{x}}{e_f} &=  (e_1\inline{f\ \overline{x}}{e_f})\ (e_2\inline{f\ \overline{x}}{e_f})\\
\ecase{x}{e}{C}{\overline{x}}{e}\inline{f\ \overline{x}}{e_f} &=
\ecase{x}{e\inline{f\ \overline{x}}{e_f}}{C}{\overline{x}}{e\inline{f\ \overline{x}}{e_f}}
\end{align*}

\newcommand\updatedcty[2]{\ensuremath{\mathtt{updatedc}(#1, #2)}\xspace}

\subsubsection{Measures}
  Axioms that are automatically instantiated, always.
  \NV{can we encode them using axioms?}
  \NV{not efficient as call invocations}

\begin{align*}
\embed{\eletrecopt{x}{e}{\gtyp}{M}{\prog}}
  &= \eletrecopt{x}{e}{\gtyp}{}{\embed{\prog}}
; \updatedcty{x}{e} \\
\embed{\eletrecopt{x}{e}{\gtyp}{\star}{\prog}}
  &= \eletrecopt{x}{e}{\gtyp}{\star}{\embed{\prog}}\\
\embed{e} &= e
\end{align*}

\begin{align*}
\updatedcty{f}{\efun{x}{\typ}{\ecase{y}{x}{\dc_i}{\overline{z}}{e_i}}}\\
 \defeq
 \constty(\dc_i) := \exacttypefun{f}{\constty(\dc_i)}{\efun{\overline{z}}{}{e_i\subst{x}{v}\subst{y}{v}}}
\end{align*}

\begin{align*}
\exacttypefun{f}{\tref{v}{\btyp}{r}}{e} &= \tref{v}{\btyp}{r \land f\ v = e}\\
\exacttypefun{f}{\tfun{x}{\typ_x}{\typ}}{\efun{y}{}{e}} &=\tfun{x}{\typ_x}{\exacttype{\typ}{e\subst{y}{x}}}
\end{align*}


\par
\section{Data Structure}
\label{section:Graph:dataStructure}
\par
The {\tt Graph} structure has nine fields.
\begin{itemize}
\item {\tt int type} : type of graph \qquad
% \begin{center}
\begin{tabular}{|c|c|c|} \hline
{\tt type} & vertices weighted? & edges weighted? \\ \hline
         0 &  no &  no \\
         1 & yes &  no \\
         2 &  no & yes \\
         3 & yes & yes \\ \hline
\end{tabular}
% \end{center}
\item {\tt int nvtx } : number of internal vertices
\item {\tt int nvbnd } : number of boundary vertices
\item {\tt int nedges } : number of edges
\item {\tt int totvwght } : total vertex weight
\item {\tt int totewght } : total edge weight
\item {\tt IVL *adjIVL} :
pointer to {\tt IVL} object to hold adjacency lists
\item {\tt int *vwghts} : pointer to a vertex to hold vertex weights
non-{\tt NULL} if {\tt type \% 2 == 1}
\item {\tt IVL *ewghtIVL} : pointer to {\tt IVL} object to hold
      edge weight lists, non-{\tt NULL} if {\tt type / 2 == 1}
\end{itemize}