%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Paul McKee
% Rensselaer Polytechnic Institute
% 1/31/18
% Master's Thesis
% with Dr. Kurt Anderson
% LaTeX Template: Project Titlepage Modified (v 0.1) by rcx
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[12pt]{article}

%\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\usepackage{blindtext}
\usepackage[utf8]{inputenc}

\usepackage{graphicx, wrapfig, subcaption, setspace, booktabs}
\usepackage{sectsty}
\usepackage{url, lipsum}
\usepackage{makecell}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}

\usepackage[table,xcdraw]{xcolor}

\usepackage[margin=.75in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{color}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{graphicx}

\usepackage{cite}%AddedbyChris
\usepackage{graphicx}%AddedbyChris
\usepackage{array}%Added by Chris
\usepackage{caption}
\usepackage{amsmath}%Added by Chri
\pagestyle{fancy}
\fancyhf{}
%\fancyhead[L]{Independant Study}
%\fancyhead[C]{\rightmark}
\fancyhead[C]{}

\fancyhead[L]{\nouppercase{\leftmark}}
\fancyhead[R]{Philip Hoddinott}

\rfoot{Page \thepage \hspace{1pt} of \pageref{LastPage}}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}

\newenvironment{theorem}[2][Theorem]{\begin{trivlist}
		\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{lemma}[2][Lemma]{\begin{trivlist}
		\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{exercise}[2][Exercise]{\begin{trivlist}
		\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{problem}[2][Problem]{\begin{trivlist}
		\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{question}[2][Question]{\begin{trivlist}
		\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{corollary}[2][Corollary]{\begin{trivlist}
		\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

\newenvironment{solution}{\begin{proof}[Solution]}{\end{proof}}
\usepackage{multicol}
\newcommand{\mysize}{0.5}
\usepackage{subcaption}
\usepackage{float}
\usepackage{listings}
\usepackage{color}
\newcolumntype{L}{>{\centering\arraybackslash}m{3cm}}
\usepackage{setspace}
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}

\newlength\longest

% %---------------------------------------------------------------
% % HEADER & FOOTER
% %---------------------------------------------------------------

%\fancyhf{}
%\pagestyle{fancy}
%\renewcommand{\headrulewidth}{0pt}
%\setlength\headheight{0pt}
%\fancyhead[L]{ Paul McKee }
%\fancyhead[R]{Rensselaer Polytechnic Institute}
%\cfoot{ \thepage\ }

%--------------------------------------------------------------
% TITLE PAGE
%--------------------------------------------------------------
\iffalse
\begin{titlepage}
	\title{
		\LARGE \textbf{\uppercase{Put Title Here}} \\
		\vspace{0.25cm}
		\LARGE \textbf{Philip Hoddinott}
	}
	\author{\small{Submitted in Partial Fulfillment of the Requirements} \\ \small{for the Degree of} \\
		\uppercase{Master of Science} \\ \\
		Approved by:
		\\ Kurt Anderson, Chair \\ John Christian \\ Matthew Oehlschlaeger \\ \\ %% from paul's template
		\includegraphics[width=2.5cm]{rensselaer_seal.png} \\
		\small{\textit{Department of Mechanical, Aerospace, and Nuclear Engineering}} \\
		\small{Rensselaer Polytechnic Institute} \\
		\small{Troy, New York} \\
		\small{November 2018}
	}
\end{titlepage}
\fi

\begin{document}
		\title{A comparison of the Gibbs and Herrick-Gibbs Methods subject to noise for low eccentric orbits}
	\author{Philip Hoddinott}

	\maketitle
	\pagenumbering{roman}
	\thispagestyle{empty}
	\clearpage

	\thispagestyle{empty}
	\null\vfill

	\begin{figure}[!t]
		\begin{center}
			\settowidth\longest{\huge\itshape But, Captain, I cannot change;}
			\parbox{\longest}{%
				\raggedright{\huge\itshape%
					But, Captain, I cannot change the laws of physics\par\bigskip
				}
				\raggedleft\Large{-Lt. Commander Montgomery ``Scotty" Scott}\par
				\raggedleft\Large{USS}\textit{ Enterprise}\par%

			}
		\end{center}
	\end{figure}

	\null\vfill

	\newpage
	%\setcounter{page}{1}
	\tableofcontents

	\newpage

	%\thispagestyle{fancy}

	%\addcontentsline{toc}{section}{\uppercase{Table of Contents}}
	%\listoftables
	%\addcontentsline{toc}{section}{\uppercase{List of Tables}}
	\listoffigures
	%\addcontentsline{toc}{section}{\uppercase{List of Figures}}
	% -----------------------------

	% ------------------------------------------------------------
	% Acknowledgement
	% ------------------------------------------------------------
	\newpage
	\pagenumbering{arabic}
		\doublespacing

	% ------------------------------------------------------------
	% Abstract
	% ------------------------------------------------------------

	\newpage
	\section*{Abstract}
	The purpose of this report is to perform an analysis of the Gibbs and Herrick-Gibbs methods of orbital determination when subject to noise. The methods are explained and their derivations given. They are then computed for a sample orbit at various eccentricities. The Root Mean Square Error of both methods is obtained and the accuracy of the methods compared. \par
	The author would like to express his gratitude to Professor John Christian for his suggestion of this project and his assistance with the methods of orbital determination through out the semester.\par

	%\textcolor{red}{ Do More}
	% ------------------------------------------------------------
	% Introduction
	% ------------------------------------------------------------
	\newpage
	 % this should start the normal numberinbg

	\section{Introduction}
	\subsection{Background}
	Watching the skys at night, the ancient Greeks noticed that some stars seemed to move in fixed path across then night sky. They called these stars \textit{planetes}, meaning wanderers. The Greeks were not the first civilization to take notice of the planets, Babylonian astronomers were already recording the motion of the planets for five hundred years. But they were the first to develop methods of predicting the planet's motion. These methods were so advanced, that they would remain in use for over a thousand years until they were eclipsed the works of Copernicus\cite{lectureOnGreekAstro}. %, Kepler, Newton, and Euler\cite{lectureOnGreekAstro}.

	%\textcolor{red}{Segway hre}
	Today the prediction of planet's orbits falls under what we would call orbital determination. Orbital determination is the estimation of an object's orbital elements from certain measurements of the object (position, velocity, angle), often taken from some ground station. Modern orbital determination employs various methods such as Lambert's method, Gauss' method, Gibbs' method, Herrick-Gibbs method. Some methods such as Gibb's and Herrick-Gibbs' require only three position measurements. Lambert's method requires two position and velocity measurements, and Gauss's method uses measurements of an object's right ascension and declination. A method of orbital determination is considered a preliminary orbit determination method if it just uses the equations of two body motion, and neglects other effects on the orbit.\par

		%\textcolor{red}{Put a bit more on the other methods}
		\subsection{Problem Statement}
		Of the mentioned methods of preliminary orbit determination, Gibbs and Herrick-Gibbs are two commonly used ones. Gibbs method uses three position measurements that are spaced relatively far apart to solve for the orbital elements. Herrick-Gibbs uses three position measurements that are close together and a Taylor series to solve for the orbital elements. Herrick-Gibbs is recommended for position measurements that are less than 5 degrees apart, and Gibbs should be used for measurements more than 5 degrees apart\cite{vallado2007fundamentals}. However this suggestion does factor in error in the position measurements. Some work has been done on these three position measurement methods \cite{Kaushick}, in this paper we seek to expand on it and add in the effects of orbital eccentricity.
		\subsection{Transition Line}
		Kaushick \cite{Kaushick} in his comparison of the Gibbs and Herrick-Gibbs methods discusses the idea of a transition point, the place where on a plot of error vs the separation of position measurements that the Gibbs method becomes more accurate than the Herrick-Gibbs method.\par
		In this paper the idea of a transition line will be used. The transition line is the three dimensional representation of the transition point. The transition line marks where on a range of noise and measurement separations the Gibbs method becomes better than the Herrick-Gibbs method.

	%\subsection{Orbit Determination}
	%
	%\newpage
	\section{Gibbs method}
	Gibbs method was developed by Josiah Willard Gibbs\cite{gibbsBio}, who was famous for his application of vectorized math to thermodynamics. Gibbs method works off having three measurements of the distance to an object at three different times. Thus, assume we have the following position vectors:
	\begin{equation}
	\boldsymbol{r_1}, 	\boldsymbol{r_2},	\boldsymbol{r_3}
	\end{equation}
	which were observed at times $t_1, t_2, \text{ and  } t_3$. Each of these position vectors has a corresponding velocity vector $\boldsymbol{v_1}, 	\boldsymbol{v_2},	\text{ and  } \boldsymbol{v_3}$. To obtain the orbital elements from one of the position vectors, the corresponding velocity vector is needed. Thus the focus of Gibbs method is searching for a velocity vector. This velocity vector may be found in just four equations:
	\begin{equation}
	\mathbf { N } = r _ { 1 } \left( \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right) + r _ { 2 } \left( \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 } \right) + r _ { 3 } \left( \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } \right)
	\end{equation}
	\begin{equation}
	\mathbf { D } = \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } + \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } + \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 }
	\end{equation}
	\begin{equation}
	\mathbf { S } = \mathbf { r } _ { 1 } \left( r _ { 2 } - r _ { 3 } \right) + \mathbf { r } _ { 2 } \left( r _ { 3 } - r _ { 1 } \right) + \mathbf { r } _ { 3 } \left( r _ { 1 } - r _ { 2 } \right)
	\end{equation}
	\begin{equation}
	\mathbf { v } = \sqrt { \frac { \mu } { N D } } \left( \frac { \mathbf { D } \times \mathbf { r } } { r } + \mathbf { S } \right)
	\end{equation}

	This algorithm works well for a code to obtain orbital elements, and a MATLAB code for it is provided in the appendix.

	\subsection{Derivation of Gibbs Method}
	The algorithm above will now be expanded on, to explain how the steps were obtained. We will use the notation from Howard Curtis's Orbital Mechanics for Engineering Students \cite{curtis2013_gibbs}.

	Gibbs method beings with the conservation of momentum, which means that all the position vectors of an orbiting object must all be co planer. Or the unit vector normal to the plane of any two position vectors must be perpendicular to the unit vector of the third measurement. This may be expressed as:

	\begin{eqnarray}
	\hat { { u } } _ { r 1 } = \mathbf { r } _ { 1 } / r _ { 1 }& \hat { \mathrm { C } } _ { 23 } = \left( \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right) / \left\| \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right\|\\
	\hat {{ u } } _ { r 2 } = \mathbf { r } _ { 2 } / r _ { 2 }&\hat { \mathrm { C } } _ { 31 } = \left( \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1} \right) / \left\| \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 } \right\|\\
	\hat {{ u } } _ { r 3 } = \mathbf { r } _ { 3 } / r _ { 3} & \hat { \mathrm { C } } _ { 12 } = \left( \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } \right) / \left\| \mathbf { r } _ { 1} \times \mathbf { r } _ { 2 } \right\|
	\end{eqnarray}
	%\textcolor{red}{toDO, make these normal fractions, i like those better}

	To check that all the vectors are co planer as they should be, the dot product of

	\begin{equation}
	\hat {  { u } } _ { r 1 } \cdot \hat {  { C } } _ { 23 } = 0
	\end{equation}

	Additionally because the vectors are co planer, there must be scalar factors $(c)$ that can be applied to two of the vectors to make their sum equal to the third vector:

	\begin{equation}
	\mathbf{r}_2 = c_1 \mathbf{ r }_1 + c_3 \mathbf{r}_3
	\label{eqn:cs}
	\end{equation}
	We should note that convention has Gibbs method solve for the velocity vector associated with the second position vector. Gibbs method can be used to solve for the other vectors, the order of the position vectors must simply be rotated.

	If these vectors are all co planer, we may define unit vector $\hat{\mathbf{w}}$ as a unit vector normal to the orbital plane, unit vector $\hat{\mathbf{p}}$ as being in the direction of the eccentricity vector, and $\hat{\mathbf{q}}$ as the unit vector that is normal to $\hat{\mathbf{w}}$ and $\hat{\mathbf{p}}$, such that:
	\begin{equation}
	\hat{\mathbf{q}}=\hat{\mathbf{w}}\times\hat{\mathbf{p}}
	\label{eqn:cross_wpq}
	\end{equation}
	The eccentricity and angular moment vectors may be written as
	\begin{eqnarray}
	\mathbf{h}=h\hat{\mathbf{w}}\\
	\mathbf{e}=e\hat{\mathbf{p}}
	\end{eqnarray}

	\begin{equation}
	\mathbf { v } \times \mathbf { h } = \mu \left( \frac { \mathbf { r } } { r } + \mathbf { e } \right)
	\label{eqn:Og_h}
	\end{equation}

	The relationship between position, velocity, momentum, and eccentricity may be expressed as equation \ref{eqn:Og_h}. We rewrite equation \ref{eqn:Og_h} to solve for velocity as equation \ref{eqn:new_h}

	\begin{equation}
	\mathbf { v } = \frac { \mu } { h ^ { 2 } } \left( \frac { \mathbf { h } \times \mathbf { r } } { r } + \mathbf { h } \times \mathbf { e } \right)
	\label{eqn:new_h}
	\end{equation}

		and using equation \ref{eqn:cross_wpq}, equation \ref{eqn:new_h} may be rewritten as
	 \begin{equation}
	 \mathbf { v } = \frac { \mu } { h } \left( \frac { \hat { \mathbf { w } } \times \mathbf { r } } { r } + e \hat { \mathbf { q } } \right)
	 \label{eqn:almostDone}
	 \end{equation}

	 The relationship between eccentricity, angular momentum, and position vector may be written as
	 \begin{equation}
	 \mathbf { r } \cdot \mathbf { e } = \frac { h ^ { 2 } } { \mu } - r
	 \label{eqn:eampo}
	 \end{equation}
	 Equation \ref{eqn:eampo} has a relation of position, eccentricity, and momentum. To eliminat eccentricity, we first dot equation \ref{eqn:cs} with the eccentricity vector to get equation \ref{eqn:edot} and then insert equation \ref{eqn:eampo} into equation \ref{eqn:edot}.

	 \begin{equation}
	 \left(\mathbf{r}_2 \right)\cdot\mathbf{ e }= \left(c_1 \mathbf{ r }_1 + c_3 \mathbf{r}_3\right)\cdot\mathbf{ e }=c_1 \mathbf{ r }_1\cdot\mathbf{ e } + c_3 \mathbf{r}_3\cdot\mathbf{ e }
	 \label{eqn:edot}
	 \end{equation}

	 \begin{equation}
	 \left(\frac { h ^ { 2 } } { \mu } - r_2\right) =c_1 \left(\frac { h ^ { 2 } } { \mu } - r_1\right)  + c_3\left(\frac { h ^ { 2 } } { \mu } - r _3\right)
	 \label{eqn:edot2}
	 \end{equation}

	 Now we have a relationship between the coefficients from earlier, position, and momentum. If the coefficients $c_1$ and $c_2$ may be solved for, the angular momentum may be found.

	 Removing the coefficients gives the following equation
	 \begin{equation}
	 \frac { h ^ { 2 } } { \mu } \underbrace{\left( \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } + \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } + \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 } \right)}_{D} = \underbrace{r _ { 1 } \left( \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right) + r _ { 2 } \left( \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 } \right) + r _ { 3 } \left( \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } \right)}_{N}
	 \label{eqn:longone}
	 \end{equation}
	 For simplicity we create the vectors N and D, which are:
	 \begin{eqnarray}
	 	 \mathbf { N } = r _ { 1 } \left( \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right) + r _ { 2 } \left( \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 } \right) + r _ { 3 } \left( \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } \right)\\
	 	 \mathbf { D } = \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } + \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } + \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 }\\
	 	 N=\norm{\mathbf{N}}\\
	 	 D=\norm{\mathbf{D}}
	 \end{eqnarray}
 	Now using this notation equation \ref{eqn:longone} may be rewritten as
	\begin{equation}
	\mathbf { N } = \frac { h ^ { 2 } } { \mu } \mathbf { D }
	\end{equation}
	Replacing the vectors with their norms and rearranging:
	\begin{eqnarray}
	N = \frac { h ^ { 2 } } { \mu } D\\
	h = \sqrt { \mu \frac { N } { D } }
	\label{eqn:gotH}
	\end{eqnarray}
	From equation \ref{eqn:gotH} the angular momentum may be found from just the position vectors.

	Because $\hat{ \mathbf { w } }$ was defined as being a unit vector normal to the orbital plane, and $\mathbf{ N }$ and $\mathbf{ D }$ are made up of vectors in the orbital plane then
	\begin{equation}
	\hat{ \mathbf { w } }=\frac{\mathbf{ N }}{N}=\frac{\mathbf{ D }}{D}
	\end{equation}

	Equation \ref{eqn:cross_wpq} may then be written as
	\begin{equation}
	\hat { \mathbf { q } } = \frac { ( \mathbf { D } \times \mathbf { e } ) } { D e }
	\label{eqn:p1}
	\end{equation}
	Fully writing out the numerator:

	\begin{equation}
	\hat { \mathbf { q } } = \frac { \left[ \left( \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } \right) \times \mathbf { e } + \left( \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right) \times \mathbf { e } + \left( \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 } \right) \times \mathbf { e } \right] } { D e }
	\end{equation}

	Using the bac-cab vector identity, the following equations are obtained
	\begin{equation}
	( \mathbf { A } \times \mathbf { B } ) \times \mathbf { C }  = \mathbf { B } ( \mathbf { A } \cdot \mathbf { C } ) - \mathbf { A } ( \mathbf { B } \cdot \mathbf { C } )
	\end{equation}
	\begin{eqnarray}
	{ \left( \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right) \times \mathbf { e } = \mathbf { r } _ { 3 } \left( \mathbf { r } _ { 2 } \cdot \mathbf { e } \right) - \mathbf { r } _ { 2 } \left( \mathbf { r } _ { 3 } \cdot \mathbf { e } \right) } \\ { \left( \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 } \right) \times \mathbf { e } = \mathbf { r } _ { 1 } \left( \mathbf { r } _ { 3 } \cdot \mathbf { e } \right) - \mathbf { r } _ { 3 } \left( \mathbf { r } _ { 1 } \cdot \mathbf { e } \right) } \\ { \left( \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } \right) \times \mathbf { e } = \mathbf { r } _ { 2 } \left( \mathbf { r } _ { 1 } \cdot \mathbf { e } \right) - \mathbf { r } _ { 1 } \left( \mathbf { r } _ { 2 } \cdot \mathbf { e } \right) }
	\label{eqn:usedVectId}
	\end{eqnarray}
	Inserting equation \ref{eqn:eampo} into equation \ref{eqn:usedVectId}

	\begin{eqnarray}
	\left( \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right) \times \mathbf { e } = \mathbf { r } _ { 3 } \left( \frac { h ^ { 2 } } { \mu } - r _ { 2 } \right) - \mathbf { r } _ { 2 } \left( \frac { h ^ { 2 } } { \mu } - r _ { 3 } \right) = \frac { h ^ { 2 } } { \mu } \left( \mathbf { r } _ { 3 } - \mathbf { r } _ { 2 } \right) + r _ { 3 } \mathbf { r } _ { 2 } - r _ { 2 } \mathbf { r } _ { 3 }\\
	\left( \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 } \right) \times \mathbf { e } = \mathbf { r } _ { 1 } \left( \frac { h ^ { 2 } } { \mu } - r _ { 3 } \right) - \mathbf { r } _ { 3 } \left( \frac { h ^ { 2 } } { \mu } - r _ { 1 } \right) = \frac { h ^ { 2 } } { \mu } \left( \mathbf { r } _ { 1 } - \mathbf { r } _ { 3 } \right) + r _ { 1 } \mathbf { r } _ { 3 } - r _ { 3 } \mathbf { r } _ { 1 }\\
	\left( \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } \right) \times \mathbf { e } = \mathbf { r } _ { 2 } \left( \frac { h ^ { 2 } } { \mu } - r _ { 1 } \right) - \mathbf { r } _ { 1 } \left( \frac { h ^ { 2 } } { \mu } - r _ { 2 } \right) = \frac { h ^ { 2 } } { \mu } \left( \mathbf { r } _ { 2 } - \mathbf { r } _ { 1 } \right) + r _ { 2 } \mathbf { r } _ { 1 } - r _ { 1 } \mathbf { r } _ { 2 }
	\end{eqnarray}

%\textcolor{red}{	NOte take out the midle part}

The we write the sum of these equations as

	\begin{equation}
	\mathbf { S } = \mathbf { r } _ { 1 } \left( r _ { 2 } - r _ { 3 } \right) + \mathbf { r } _ { 2 } \left( r _ { 3 } - r _ { 1 } \right) + \mathbf { r } _ { 3 } \left( r _ { 1 } - r _ { 2 } \right)
	\end{equation}
	And equation \ref{eqn:p1} can now be written as
	\begin{equation}
	\hat { \mathbf { q } } = \frac { 1 } { D e } \mathbf { S }
	\label{eqn:ad2}
	\end{equation}
	Inserting equation \ref{eqn:ad2}into equation \ref{eqn:almostDone} yields equation \ref{eqn:FinalP}.

	\begin{equation}
	\mathbf { v } = \frac { \mu } { h } \left( \frac { \hat { \mathbf { w } } \times \mathbf { r } } { r } + e \hat { \mathbf { q } } \right)=\frac { \mu } { \sqrt { \mu \frac { N } { D } } } \left[ \frac { \frac { D } { D } \times \mathbf { r } } { r } + e \left( \frac { 1 } { D e } \mathbf { S } \right) \right]
	\label{eqn:FinalP}
	\end{equation}

	Equation \ref{eqn:FinalP} may be simplified to \ref{eqn:f21}

	\begin{equation}
	\mathbf { v } = \sqrt { \frac { \mu } { N D } } \left( \frac { \mathbf { D } \times \mathbf { r } } { r } + \mathbf { S } \right)
	\label{eqn:f21}
	\end{equation}
	 Now from this equation the velocity vector may be computed. From the velocity and position vector, the orbital elements may be computed.
	\iffalse
	\subsubsection{Gibbs method Algorithm}
	These steps follow the derication og gibbs method from Orbital Mechanics for Engineering Students \cite{curtis2013_gibbs}. A more detailed derivation may be found in the appendix

	\begin{equation}
	\mathbf { N } = r _ { 1 } \left( \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right) + r _ { 2 } \left( \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 } \right) + r _ { 3 } \left( \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } \right)
	\end{equation}

	and
	\begin{equation}
	\mathbf { D } = \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } + \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } + \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 }
	\end{equation}

	\begin{equation}
	\mathbf { S } = \mathbf { r } _ { 1 } \left( r _ { 2 } - r _ { 3 } \right) + \mathbf { r } _ { 2 } \left( r _ { 3 } - r _ { 1 } \right) + \mathbf { r } _ { 3 } \left( r _ { 1 } - r _ { 2 } \right)
	\end{equation}
	From these
	\begin{equation}
	\mathbf { v } = \sqrt { \frac { \mu } { N D } } \left( \frac { \mathbf { D } \times \mathbf { r } } { r } + \mathbf { S } \right)
	\end{equation}

	From this velocity, the oribtal elements may be found

	Write up
	Page or two on orbit degetrimantion
	Angle only mtheod: gauss, ;laplace
	Velotto textbook on Orbit deterimantion
	3 pos vect, 3 beartin time
	Thrre velc , IOD two
	(no eqn)
	Section on gibbs
	Frame problem
	Derive gibbs
	Show how you go through problem set up to the end
	Talk about now, assses how well gibbs does for ODE, diff ecc, diff noise level
	Talk about results
	Derivation of gibbs should be a page to two pages (plus figures)
	Harrit gibbs method (try to take a look at this) (it’s a taylor series expansion of orbit around)
	Nice plots
	Get a pdf of report by last day of class
	Mean  anonly, not true for circ

	\subsection{Derivation of Gibbs Method}
	\begin{eqnarray}
	\hat { { u } } _ { r 1 } = \mathbf { r } _ { 1 } / r _ { 1 }& \hat { \mathrm { C } } _ { 23 } = \left( \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right) / \left\| \mathbf { r } _ { 2 } \times \mathbf { r } _ { 3 } \right\|\\
	\hat {{ u } } _ { r 2 } = \mathbf { r } _ { 2 } / r _ { 2 }&\hat { \mathrm { C } } _ { 31 } = \left( \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1} \right) / \left\| \mathbf { r } _ { 3 } \times \mathbf { r } _ { 1 } \right\|\\
		\hat {{ u } } _ { r 3 } = \mathbf { r } _ { 3 } / r _ { 3} & \hat { \mathrm { C } } _ { 12 } = \left( \mathbf { r } _ { 1 } \times \mathbf { r } _ { 2 } \right) / \left\| \mathbf { r } _ { 1} \times \mathbf { r } _ { 2 } \right\|
	\end{eqnarray}
	NOTE make these normal fractions
	\fi
	\section{Herrick-Gibbs Method}
	The obvious problem with Gibbs method is what if the measured vectors are close to each other, for example in a single pass over a ground station. Herrick Gibbs is one such solution to this problem, it is a method of orbital determination that requires three position measurements, and their respective times. It then uses a Taylor series expansion. Because it is a Taylor series, it is not as robust as Gibbs method. According to Vallado, it is best for under 5 degrees of separation between position vectors \cite{vallado2007fundamentals}.

	\subsection{Herrick-Gibbs Method Algorithm}
	The derivation of Herrick-Gibbs method is a lengthy one, and readers searching for a more in depth derivation of Herrick-Gibbs should read Vallado's Fundamentals of Astrodynamics and Applications \cite{vallado2007fundamentals}. This paper will present the relevant algorithm for Herrick Gibbs method. The algorithm of the Herrick-Gibbs method in this section is based off of Kaushick's derivation\cite{Kaushick}, but the notation has been changed to be consistent with the notation used thus far in this paper. Herrick Gibbs begins by using the Taylor series to expand the position and the velocity vectors out by
	\begin{equation}
	\begin{array} { l } { \mathbf { r } = \mathbf { a } _ { 0 } + t \mathbf { a } _ { 1 } + t ^ { 2 } \mathbf { a } _ { 2 } + t ^ { 3 } \mathbf { a } _ { 3 } + t ^ { 4 } \mathbf { a } _ { 4 } + t ^ { 5 } \mathbf { a } _ { 5 } } \\ { \mathbf { v } = \mathbf { a } _ { 1 } + 2 t \mathbf { a } _ { 2 } + 3 t ^ { 2 } \mathbf { a } _ { 3 } + 4 t ^ { 3 } \mathbf { a } _ { 4 } + 5 t ^ { 4 } \mathbf { a } _ { 5 } } \end{array}
	\end{equation}
	Where the $a_n$ terms are unknowns from the power series. The equation for acceleration in a two body system then becomes
	\begin{equation}
	- \frac { \mu } { r ^ { 3 } } \mathbf { r } = 2 \mathbf { a } _ { 2 } + 6 t \mathbf { a } _ { 3 } + 12 t ^ { 2 } \mathbf { a } _ { 4 } + 20 t ^ { 3 } \mathbf { a } _ { 5 }
	\end{equation}
	The time between the observations is defined as
	\begin{equation}
	\begin{array} { l } { \Delta t _ { 32 } = t _ { 3 } - t _ { 2 } } \\ { \Delta t _ { 31 } = t _ { 3 } - t _ { 1 } } \\ { \Delta t _ { 21 } = t _ { 2 } - t _ { 1 } } \end{array}
	\end{equation}
	The position vectors may be now written as
	\begin{equation}
	\begin{array} { l }
	{ \mathbf { r } _ { 2 } = \mathbf { a } _ { 0 } } \\
	 { \mathbf { r } _ { 1 } = \mathbf { r } _ { 2 } - \Delta t _ { 21 } \mathbf { a } _ { 1 } + \Delta t _ { 21 } ^ { 2 } \mathbf { a } _ { 2 } - \Delta t _ { 21 } ^ { 3 } \mathbf { a } _ { 3 } + \Delta t _ { 12 } ^ { 4 } \mathbf { a } _ { 4 } - \Delta t _ { 21 } ^ { 5 } \mathbf { a } _ { 5 } } \\

	{ \mathbf { r } _ { 3 } = \mathbf { r } _ { 2 } - \Delta t _ { 32 } \mathbf { a } _ { 1 } + \Delta t _ { 32 } ^ { 2 } \mathbf { a } _ { 2 } - \Delta t _ { 32 } ^ { 3 } \mathbf { a } _ { 3 } + \Delta t _ { 32 } ^ { 4 } \mathbf { a } _ { 1 } - \Delta t _ { 32 } ^ { 5 } \mathbf { a } _ { 5 } } \\
	\end{array}
	\end{equation}
	The velocity and acceleration vectors may be now written as
	 \begin{equation}
	 \begin{aligned} \mathbf { v } _ { 2 } & = \mathbf { a } _ { 1 } \\ - \frac { \mu } { r _ { 1 } ^ { 3 } } \mathbf { r } _ { 1 } & = 2 \mathbf { a } _ { 2 } - 6 \Delta t _ { 21 } \mathbf { a } _ { 3 } + 12 \Delta t _ { 21 } ^ { 2 } \mathbf { a } _ { 4 } - 20 \Delta t _ { 21 } ^ { 3 } \mathbf { a } _ { 5 } \\ - \frac { \mu } { r _ { 2 } ^ { 3 } } \mathbf { r } _ { 2 } & = 2 \mathbf { a } _ { 2 } \\ - \frac { \mu } { r _ { 3 } ^ { 3 } } \mathbf { r } _ { 3 } & = 2 \mathbf { a } _ { 2 } + 6 \Delta t _ { 32 } \mathbf { a } _ { 3 } + 12 \Delta t _ { 32 } ^ { 2 } \mathbf { a } _ { 4 } + 20 \Delta t _ { 32 } ^ { 3 } \mathbf { a } _ { 5 } \end{aligned}
	 \end{equation}

	Solving for the $a_n$ terms gives the following equation

	\begin{equation}
	\begin{aligned} \mathbf { v } _ { 2 } = - \Delta t _ { 32 } \left[ \frac { 1 } { \Delta t _ { 21 } \Delta t _ { 31 } } + \frac { \mu } { 12 r _ { 1 } ^ { 3 } } \right] \mathbf { r } _ { 1 } + \left( \Delta t _ { 32 } - \Delta t _ { 21 } \right) & \left[ \frac { 1 } { \Delta t _ { 21 } \Delta t _ { 32 } } + \frac { \mu } { 12 r _ { 2 } ^ { 3 } } \right] \mathbf { r } _ { 2 } \\ + \Delta t _ { 21 } & \left[\frac { 1 } { \Delta t _ { 32 } \Delta t _ { 31 } } + \frac { \mu } { 12 r _ { 3 } ^ { 3 } } \right] \mathbf { r } _ { 3 } \end{aligned}
	\label{eqn:HGREF}
	\end{equation}

		%\begin{equation}
	%\mathbf { v } _ { 2 } = - \Delta t _ { 32 } \left[ \frac { 1 } { \Delta t _ { 21 } \Delta t _ { 31 } } + \frac { \mu } { 12 r _ { 1 } ^ { 3 } } \right] \mathbf { r } _ { 1 } + \left( \Delta t _ { 32 } - \Delta t _ { 21 } \right)  \left[ \frac { 1 } { \Delta t _ { 21 } \Delta t _ { 32 } } + \frac { \mu } { 12 r _ { 2 } ^ { 3 } } \right] \mathbf { r } _ { 2 } \\ + \Delta t _ { 21 }  \left[\frac { 1 } { \Delta t _ { 32 } \Delta t _ { 31 } } + \frac { \mu } { 12 r _ { 3 } ^ { 3 } } \right] \mathbf { r } _ { 3 }
	%\end{equation}

	\iffalse

	%\textcolor{red}{To do, expand on this derivation, reverance Vallado}

	The derivation of the Herrick-Gibbs method in this section is based off of Vallado's derivation \cite{vallado2007fundamentals}, but the notation has been changed to be consistent with the notation used thus far in this paper.

		Herrick Gibbs begins by using the Taylor series to expand the position vector out by
		\begin{equation}
		\mathbf{r(t)}=\mathbf{r_2}+\mathbf{\dot{r}_2} (t-t_2) + \mathbf{\ddot{r}_2} \frac{(t-t_2)^2}{2!}+ \mathbf{\dddot{r}_2} \frac{(t-t_2)^3}{3!}+ \mathbf{{r_2}}^{(iv)} \frac{(t-t_2)^4}{4!}+\dots
		\end{equation}

		The time between the observations is defined as
		\begin{equation}
		\begin{array} { l } { \Delta t _ { 23 } = t _ { 2 } - t _ { 3 } } \\ { \Delta t _ { 13 } = t _ { 1 } - t _ { 3 } } \\ { \Delta t _ { 12 } = t _ { 1 } - t _ { 12 } } \end{array}
		\end{equation}
		The position vectors may be now written as

		\begin{equation}\begin{aligned}
		\mathbf{r_1}=\mathbf{r_2}+\mathbf{\dot{r}_2} (\Delta t _ { 12 } ) + \mathbf{\ddot{r}_2} \frac{(\Delta t _ { 12 })^2}{2!}+ \mathbf{\dddot{r}_2} \frac{(\Delta t _ { 12 })^3}{3!}+ \mathbf{{r_2}}^{(iv)} \frac{(\Delta t _ { 12 })^4}{4!}+\dots\\
		\mathbf{r_3}=\mathbf{r_2}+\mathbf{\dot{r}_2} (\Delta t _ { 32 } ) + \mathbf{\ddot{r}_2} \frac{(\Delta t _ { 32 })^2}{2!}+ \mathbf{\dddot{r}_2} \frac{(\Delta t _ { 32 })^3}{3!}+ \mathbf{{r_2}}^{(iv)} \frac{(\Delta t _ { 32 })^4}{4!}+\dots\end{aligned}
		\end{equation}
		Using the relations in \ref{eqn:timer} and multiplying the equations together yields
		\begin{equation}
		\begin{array} { l } { \Delta t _ { 12 } ^ { 2 } \Delta t _ { 32 } - \Delta t _ { 32 } ^ { 2 } \Delta t _ { 12 } = \Delta t _ { 12 } \Delta t _ { 32 } \Delta t _ { 13 } } \\ { \Delta t _ { 12 } ^ { 2 } \Delta t _ { 32 } ^ { 3 } - \Delta t _ { 32 } ^ { 2 } \Delta t _ { 12 } ^ { 3 } = \Delta t _ { 12 } ^ { 2 } \Delta t _ { 32 } ^ { 2 } \Delta t _ { 31 } } \\ { \Delta t _ { 12 } ^ { 2 } \Delta t _ { 32 } ^ { 4 } - \Delta t _ { 32 } ^ { 2 } \Delta t _ { 12 } ^ { 4 } = \Delta t _ { 12 } ^ { 2 } \Delta _ { 32 } ^ { 2 } \Delta t _ { 31 } \left\( \Delta t _ { 32 } + \Delta t _ { 12 } \right\) } \end{array}\label{eqn:timer}
		\end{equation}

		\begin{equation}
		\begin{aligned}
		\mathbf{\dot{r}_2} \left(\Delta t_{12}\Delta t_{32}\Delta t_{31}\right)=\mathbf{r_1}\Delta t_{32}^2 + \mathbf{r_2}\left(-\Delta t_{32}^2 +\Delta t_{12}^2 \right)-\mathbf{r_3}\Delta t_{12}^2\\
		+ \frac { \mathbf{\dot { r_2 }} } { 6 } \left( \Delta t _ { 12 } ^ { 2 } \Delta t _ { 32 } ^ { 2 } \Delta t _ { 31 } \right) + \frac { \mathbf{\dot { r } _ { 2 }} } { 24 } \left( \Delta t _ { 12 } ^ { 2 } \Delta t _ { 32 } ^ { 2 } \Delta t _ { 31 } \left\{ \Delta t _ { 32 } + \Delta t _ { 12 } \right\} \right)
		\end{aligned}
		\end{equation}

	Herrick Gibbs begins by using the Taylor series to expand the position and the velocity vectors out by
	\begin{equation}
	\begin{array} { l } { \mathbf { r } = \mathbf { a } _ { 0 } + t \mathbf { a } _ { 1 } + t ^ { 2 } \mathbf { a } _ { 2 } + t ^ { 3 } \mathbf { a } _ { 3 } + t ^ { 4 } \mathbf { a } _ { 4 } + t ^ { 5 } \mathbf { a } _ { 5 } } \\ { \mathbf { v } = \mathbf { a } _ { 1 } + 2 t \mathbf { a } _ { 2 } + 3 t ^ { 2 } \mathbf { a } _ { 3 } + 4 t ^ { 3 } \mathbf { a } _ { 4 } + 5 t ^ { 4 } \mathbf { a } _ { 5 } } \end{array}
	\end{equation}

%\iffalse

	difference in time for the
	\fi
	\section{Analysis of Methods}
	\subsection{Analysis Process}
	%\textcolor{red}{To Do: Put in Orbital Parameters for the orbit I am using}
	The orbits that were analyzed came from the following orbital elements:
	\begin{itemize}\singlespacing
		\item Inclination (i) of 30 degrees.
		\item Longitude of the ascending node $(\Omega)$ of 40 degrees.
		\item Argument of periapsis $(\omega)$ of 70 degrees.
		\item A periapsis of 7178.1 km.
		\item An eccentricity that was varied.
		\item A true anomaly that was varied.
	\end{itemize}\doublespacing
	From these elements the semi major axis and the angular momentum was calculated to get the full set of orbital elements.

	The first parameter investigated was the separation of position measurements.  Vallado\cite{vallado2007fundamentals} states that Herrick-Gibbs is only accurate for measurements taken within 5 degrees of the mean anomaly of eachother, however that seems dependent on other factors. The other parameter was the noise, how accurate the position measurements were. Cases for a range of eccentricity were run. The processes for each test goes as follows:
	\begin{enumerate}
		\item The eccentricity is set and the orbital parameters calculated.
		\item The distance between measurements measured in degrees is selected from a range. The exact position vectors are calculated.
		\begin{enumerate}
			\item The noise level is selected from a range.
			\begin{enumerate}
				\item A large number of position vectors are generated from the exact position vector, and the noise level.
				\item The code uses a method of orbital determination to compute the semi major axis corresponding to each ``noisy" position vector.
				\item The Root Mean Square error for the computed semi major axis vs the real semi major axis is calculated.

			\end{enumerate}
				\item The next noise level is selected and the code repeats.
		\end{enumerate}
		\item The next distance between position measurements is selected, and the code repeats.
	\end{enumerate}

	The accuracy of two methods is compared by the Root Mean Square Error of their semi major axis. The Root Mean Square Error is computed by equation \ref{eqn:rmse}
	\begin{equation}
	RMSE(\hat{y})=\sqrt{E\left(\left(\hat{y}-y\right)^2\right)}
	\label{eqn:rmse}
	\end{equation}
	Where E is the expected value or the mean, $\hat{y}-y$ is the difference between the expected value and the measured value.
	Figure \ref{fig:RMS_MATLAB} shows how this is implemented in MATLAB.
		\begin{figure}[H]
		%\singlespacing
		\begin{lstlisting}
		RMSE = sqrt(mean((yhat - y).^2));
		\end{lstlisting}
		\caption{Root Mean Square Error Implemented in MATLAB}
		\label{fig:RMS_MATLAB}
		%\doublespacing
	\end{figure}

	The code that was used to to compare the methods and generate the plots may be seen in the appendix. As hundreds of orbits were compared not all plots can be reasonably fit into this report. Thus only the most relevant figures have been included. The additional plots and their data may be downloaded at the author's website: \url{rpi.edu\~hoddip}.
	\subsection{Analysis of a circular orbit}
	The first orbit that was analyzed was a circular orbit using the orbital elements previously listed. The RMS error for Gibbs methods may be seen in figure \ref{fig:circulargibbs}.
	\begin{figure}[H]
		\centering
		\includegraphics[width=0.7\linewidth]{circularGibbs}
		\caption{RMS error for the semi major axis via Gibbs method for an eccentricity of zero.}
		\label{fig:circulargibbs}
	\end{figure}
		It should be noted that the figure has been cropped to have a Z axis limit of $10^5$ kilometers. This is done so that the color mapping shows the change in the method more clearly. From this figure it can be seen that Gibbs method is incredibly inaccurate for position vectors taken within 10 degrees of each other. This is likely due to the noise attached with the position measurements. Gibbs method is already not intended to work with close position vectors. Thus the error that causes a small problem when the potions vectors are 30 degrees apart causes a much larger problem when the vectors are only one 5 degrees apart. The RMS error with Herrick-Gibbs methods is seen in figure \ref{fig:circularherrickgibbs}.

	%	\section{NOTE TO PHILIP2}
	\begin{figure}[H]
		\centering
		\includegraphics[width=0.7\linewidth]{circularHerrickGibbs}
		\caption{RMS error for the semi major axis via Herrick-Gibbs method for an eccentricity of zero.}
		\label{fig:circularherrickgibbs}
	\end{figure}

	Unlike Gibbs, Herrick Gibbs excels in the very close range, as it is designed to do. It dips to it's lowest error at a separation of 10 degrees, twice the range Vallado  \cite{vallado2007fundamentals} said it could be used for. Figure \ref{fig:bestmethodscirc} compares both methods.

%\section{NOTE TO PHILIP}
%\textcolor{red}{GIBBS is so bad here because the vectors might be close enough that they are within the noise level!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{bestMethodsCirc}
	\caption{The best possible RMS error for the semi major axis. The red transition line indicates where Gibbs method becomes better than the Herrick Gibbs Method}
	\label{fig:bestmethodscirc}
\end{figure}
	Figure \ref{fig:bestmethodscirc} shows the lowest error of the two methods. It starts by showing the error of Herrick-Gibbs, then at the red line it transitions over to Gibbs method. From this figure Gibbs method is seen to overtake Herrick-Gibbs at a separation of 15 degrees for low noise levels,while at high noise levels it takes up to 35 degrees of separation for Gibbs method to overtake Herrick-Gibbs. From here the error associated with both methods over a range of eccentricity will be analyzed.\par

	\iffalse

	For this orbit both methods were run given a range of measurement separation and noise.  over a range of degrees . They were subject to noise

	The purpose of this report is to perform an analysis of the Gibbs and Herrick-Gibbs methods of orbital determination when subject to noise. The methods are explained and their derivations given. They are then computed for a sample orbit at various eccentricities. The Root Mean Square Error of both methods is obtained and the accuracy of the methods compared.   and sample sizes.

	Going to do a statistical analysis with various eccentricities
	This should be before gibbs
	Then Compare Herrick-Gibbs
	The semi Major will be used
	Or I could use the v2
	I think I should just cut down the size untill I don't have to deal with the asymtote anymore
	Look at what the fund book says for when they are good or no

	\section{Results}
	Explain I have a staring orbit
	I go through it for diffrent mean anamolys
	With a a noise
	Then do this for diffrent eccentricities
	Plotting the best of both
	Use the v2 norm, or the a norm?
	Then Look at the change in which method is the most accurate

	Purpose of this si not so much the mean anamoly change, but the amount of noise and samples?
	\fi

	\subsection{Analysis of Gibbs Method at various eccentricities}
	The following plots come from Gibb's method at an eccentricity of $e=0.05,0.1,0.15$
	\begin{figure}[H]
		\centering
		\includegraphics[width=0.7\linewidth]{gibbs_e_05}
		\caption{Gibbs method for an eccentricity of 0.05 vs noise and distance between measurements.}
		\label{fig:gibbse05}
	\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{gibbs_e_05_side}
	\caption{Section view of figure \ref{fig:gibbse05} for specified noise levels.}
	\label{fig:Sidegibbse05}
\end{figure}

	\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{gibbs_e_1}
	\caption{Gibbs method for an eccentricity of 0.1 vs noise and distance between measurements.}
	\label{fig:gibbse1}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{gibbs_e_1_side}
	\caption{Section view of figure \ref{fig:gibbse1} for specified noise levels.}
	\label{fig:Sidegibbse1}
\end{figure}

	\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{gibbs_e_15}
	\caption{Gibbs method for an eccentricity of 0.15 vs noise and distance between measurements.}
	\label{fig:gibbse15}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{gibbs_e_15_side}
	\caption{Section view of figure \ref{fig:gibbse15} for specified noise levels.}
	\label{fig:Sidegibbse15}
\end{figure}

	From these plots it can be seen that Gibbs method is sensitive to both noise and position vector separation. The results are what would be expected, as the distance between position vectors increases the resulting error decreases. Gibbs is also sensitive noise (as expected), where the increase in noise increases the error. \par

	Figures \ref{fig:Sidegibbse05}, \ref{fig:Sidegibbse1}, and \ref{fig:Sidegibbse15} show the RMS vs the separation at specified noise levels. From these figures it is seen that changing the eccentricity has very little effect on Gibbs method.

	%\newpage
	\subsection{Analysis of Herrick-Gibbs Method at various eccentricities}
		The following plots come from Herrick-Gibb's method at an eccentricity of $e=0.05,0.1,0.15$
		\begin{figure}[H]
		\centering
		\includegraphics[width=0.7\linewidth]{herrickgibbs_e_05}
		\caption{Herrick-Gibbs method for an eccentricity of 0.05 vs noise and distance between measurements.}
		\label{fig:herrickgibbse05}
	\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{heck_gibbs_e_05_side}
	\caption{Section view of figure \ref{fig:herrickgibbse05} for specified noise levels.}
	\label{fig:heckgibbse05side}
\end{figure}

	\begin{figure}[H]
		\centering
		\includegraphics[width=0.7\linewidth]{herrickgibbs_e_1}
		\caption{Herrick-Gibbs method for an eccentricity of 0.1 vs noise and distance between measurements.}
		\label{fig:herrickgibbse1}
	\end{figure}
	\begin{figure}[H]
		\centering
		\includegraphics[width=0.7\linewidth]{heck_gibbs_e_1_side}
		\caption{Section view of figure \ref{fig:herrickgibbse1} for specified noise levels.}
		\label{fig:heckgibbse1side}
	\end{figure}
	\begin{figure}[H]
		\centering
		\includegraphics[width=0.7\linewidth]{herrickgibbs_e_15}
		\caption{Herrick-Gibbs method for an eccentricity of 0.15 vs noise and distance between measurements.}
		\label{fig:herrickgibbse15}
	\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{heck_gibbs_e_15_side}
	\caption{Section view of figure \ref{fig:herrickgibbse15} for specified noise levels.}
	\label{fig:heckgibbse15side}
\end{figure}

	From these plots it can be seen that just like Gibbs method, Herrick-Gibbs is sensitive to both noise and position vector separation. The results are what would be expected, as the distance between position vectors increases Herrick-Gibbs gets better up to a point, then resulting error begins to increase. Again, like Gibbs, Herrick-Gibbs is also sensitive to noise as the increase in noise increases the error. \par

Unlike Gibbs, Herrick-Gibbs is sensitive to changes in eccentricity. Figures \ref{fig:heckgibbse05side}, \ref{fig:heckgibbse1side}, and \ref{fig:heckgibbse15side} show the RMS vs the separation at specified noise levels at three different eccentricities. From these figures it is seen that increasing the eccentricity causes the RMS error to increase faster once it has passed it's minimum point.\par

	\subsection{Comparison of methods}

	From the previous sections it can be seen  that Gibbs method improves as the distance between observations increases and Herrick-Gibbs method improves up to a point, then decreases in accuracy. It has also been seen that changing the eccentricity has little effect on Gibbs, but a strong effect on Herrick-Gibbs. These methods are now compared against each other in the following figures.
	\iffalse
	\begin{figure}[H]
		\centering
		\includegraphics[width=0.7\linewidth]{bothMethods_e_05}
		\caption{Both Gibbs and Herrick-Gibbs at an eccentricity of 0.05}
		\label{fig:bothmethodse05}
	\end{figure}
	\begin{figure}[H]
		\centering
		\includegraphics[width=0.7\linewidth]{bestMethods_e_05}
		\caption{The best possible measurement from either method at an eccentricity of 0.05}
		\label{fig:bestmethodse05}
	\end{figure}
\fi
%\iffalse
\begin{figure}[H]
	\centering
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=1.1\textwidth]{bothMethods_e_05}
		\caption{Both Gibbs and Herrick-Gibbs at an eccentricity of 0.05}
		\label{fig:sub1}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=1.1\linewidth]{bestMethods_e_05}
		\caption{Best possible measurement from either method at an eccentricity of 0.05}
		\label{fig:sub2}
	\end{subfigure}
	\caption{Comparison of methods at an eccentricity of 0.05}
	\label{fig:test}
\end{figure}

\begin{figure}[H]
	\centering
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=1.1\textwidth]{bothMethods_e_1}
		\caption{Both Gibbs and Herrick-Gibbs at an eccentricity of 0.1}
		\label{fig:e1}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=1.1\linewidth]{bestMethods_e_1}
		\caption{Best possible measurement from either method at an eccentricity of 0.1}
		\label{fig:e12}
	\end{subfigure}
	\caption{Comparison of methods at an eccentricity of 0.1}
	\label{fig:test2}
\end{figure}

\begin{figure}[H]
	\centering
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=1.1\textwidth]{bothMethods_e_15}
		\caption{Both Gibbs and Herrick-Gibbs at an eccentricity of 0.15}
		\label{fig:e151}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=1.1\linewidth]{bestMethods_e_15}
		\caption{Best possible measurement from either method at an eccentricity of 0.15}
		\label{fig:e152}
	\end{subfigure}
	\caption{Comparison of methods at an eccentricity of 0.15}
	\label{fig:test3}
\end{figure}
%\fi
\iffalse
	\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{bothMethods_e_1}
	\caption{Both Gibbs and Herrick-Gibbs at an eccentricity of 0.1}
	\label{fig:bothmethodse1}
\end{figure}
\begin{figure}
	\centering
	\includegraphics[width=0.7\linewidth]{bestMethods_e_1}
	\caption{The best possible measurement from either method at an eccentricity of 0.1}
	\label{fig:bestmethodse1}
\end{figure}
	\begin{figure}
	\centering
	\includegraphics[width=0.7\linewidth]{bothMethods_e_15}
	\caption{Both Gibbs and Herrick-Gibbs at an eccentricity of 0.15}
	\label{fig:bothmethodse15}
\end{figure}
\begin{figure}
	\centering
	\includegraphics[width=0.7\linewidth]{bestMethods_e_15}
	\caption{The best possible measurement from either method at an eccentricity of 0.15}
	\label{fig:bestmethodse15}
\end{figure}
\fi

It becomes clear that Gibbs method remains robust as eccentricity increases, while Herrick-Gibbs does not handle the changes in eccentricity as well. While a circular orbit had Herrick-Gibbs beat Gibbs method for up to 35 degrees between measurements, the results are now approaching Vallado's measurement of 5 degrees separation as the change point.\par

Figure \ref{fig:eccecomp} plots the line where Gibbs method becomes better than Herrick-Gibbs. This provides a more clear demonstration of how as the eccentricity increases, the area where Herrick-Gibbs is the best method decreases.
\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{ecceComp_3}
	\caption{Comparison of transition lines against a plot of the error for a circular Gibb's method for reference.}
	\label{fig:eccecomp}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\linewidth]{topDownEcce_Comp_3}
	\caption{Top down view of figure \ref{fig:eccecomp}.}
	\label{fig:topdowneccecomp3}
\end{figure}

	\section{Conclusion}
	Both Gibbs and Herrick-Gibbs method are affected by measurement noise. This should be considered when performing preliminary orbit determination. However it should also be noted that real orbital determination methods take multiple position measurements, obtaining the mean, and lowering the noise level. \par

	Vallado states that \cite{vallado2007fundamentals} the separation point should be five degrees. However this paper has shown that for measurements subject to measurement error, Herrick-Gibbs performs better than Gibbs over a larger range. Additionally the larger the measurement error, the longer that Herrick-Gibbs is the more accurate method. These findings are backed up Kaushick \cite{Kaushick}'s findings.\par
	However unlike Kashick's findings  this paper shown a relation between eccentricity and the range where Herrick-Gibbs performs better than Gibbs method. From figure \ref{fig:topdowneccecomp3} it is clear that the transition line is highly dependent on the orbit's eccentricity. An eccentric orbit will transition in a region twice the size of  Vallado's suggested region, but a nearly circular orbit will transition much further along.

	The relation between the eccentricity and the accuracy of Herrick=Gibbs was not expected. Recalling equation \ref{eqn:HGREF}, the middle term of the equation for the $\mathbf{ v_2 }$ was:
	\begin{equation}
	\left( \Delta t _ { 32 } - \Delta t _ { 21 } \right) \left[ \frac { 1 } { \Delta t _ { 21 } \Delta t _ { 32 } } + \frac { \mu } { 12 r _ { 2 } ^ { 3 } } \right] \mathbf { r } _ { 2 }
	\end{equation}

	When $ \Delta t _ { 21 }$ was very close to $ \Delta t _ { 32 } $ the effect of the $\mathbf{r_2}$ term would cancel out. For a nearly circular orbit $ \Delta t _ { 21 }$ would be very close to $ \Delta t _ { 32 } $. It was expected that removing this term would increase error, however it has had the opposite effect and decreased error. In fact for very nearly circular orbits, a gouging effect occurs, where the accuracy of Herrick-Gibbs method will dip below Gibbs a second time further down the position measurement distance. The author plans to explore these effects further in later papers.

	\iffalse

	 seen a relation

	Both Gibbs and Herrick-Gibbs method are quite robust to measurement noise. It should be noted that real orbital determination methods take multiple position measurements, obtaining the mean, and lowering the noise level. \par

	What is interesting is the effect of Herrick-Gibbs on noisy measurements of nearly circular orbits. At low eccentricities the Herrick-Gibbs performs better than the Gibbs method subject to noise.

	At very low levels of position vector separation Gibbs method has an incredibly high level of error. This is

	IMPOARTANTE

	We have verified that the 5 degres works for low nosie.
	Unlike Tthat other guy we have seen that the eccentricitg of an orbit does have an effect on the range where herrick is better than gibbs

	\textcolor{red}{ToDo: Finish Conclusions, Upload plots when computer is finished running ,finsh derivation HeckGibb}
		\fi
		%--------------------------------------
		% References
		% -------------------------------------

		\bibliographystyle{unsrt}
		\bibliography{ref}

		%-----------------------------------------------------------
		% Appendix
		%-----------------------------------------------------------
		\newpage
		\singlespacing
%		\section*{Appendix 1 -derivation of gibbs}
		\section*{Appendix 1 - MATLAB code}
		\addcontentsline{toc}{section}{Appendix}

		\lstset{language=Matlab,%
			%basicstyle=\color{red},
			breaklines=true,%
			morekeywords={matlab2tikz},
			keywordstyle=\color{blue},%
			morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
			identifierstyle=\color{black},%
			stringstyle=\color{mylilas},
			commentstyle=\color{mygreen},%
			showstringspaces=false,%without this there will be a symbol in the places where there is a space
			numbers=left,%
			numberstyle={\tiny \color{black}},% size of the numbers
			numbersep=9pt, % this defines how far the numbers are from the text
			emph=[1]{for,end,break},emphstyle=[1]\color{red}, %some words to emphasise
			%emph=[2]{word1,word2}, emphstyle=[2]{style},
		}
	%\lstinputlisting{C:/Users/Philip/Documents/GitHub/Thesis/Master_TLE.m}
	\lstinputlisting{C:/Users/Philip/Documents/GitHub/independent_study_fall_2018/Independat-Study-Fall-2018/Gibbs_Heck_master_loop_Latex.m}

	%\subsection{Code}
	%\subsection{Master\_TLE.m}
	%\lstinputlisting{C:/Users/Philip/Documents/GitHub/Thesis/Master_TLE.m}
	%\subsection{get\_SATCAT.m}
	%	\lstinputlisting{C:/Users/Philip/Documents/GitHub/Thesis/get_SATCAT.m}
	%	\subsection{get\_TLE\_from\_ID\_Manager.m}
	%\lstinputlisting{C:/Users/Philip/Documents/GitHub/Thesis/get_TLE_from_ID_Manager.m}

	%\subsection{get\_TLE\_from\_NorID.m}
	%\lstinputlisting{C:/Users/Philip/Documents/GitHub/Thesis/get_TLE_from_NorID.m}
	%\lstinputlisting{get_SATCAT.m}

	%Thanks for Paul McKee who started this template. It seems to have good matlab code viwing

	\end{document}


\documentclass[12pt,a4paper]{article}
\input{latexmacros.tex}

\title{Sudoku Solving in Haskell}
\author{Robin Martinot, 10589155}
\date{\today}
\hypersetup{pdfauthor={Robin}, pdftitle={SudokuSolving}}

\begin{document}

\maketitle

\begin{abstract}
The goal of this project was to adapt and extend existing code for solving Sudoku
puzzles in Haskell to code that solves and generates various different types of Sudokus. Additionally, the difficulty of solving these types of Sudokus was measured
by implementing a counter in a recursive function of the code. It seems that with the
current measure of complexity it is hard to conclude exactly how `difficult' Haskell finds
the Sudoku, although the new types of Sudokus seemed harder to solve than the regular Sudoku.
Nevertheless, the results were rather variable and additional research is required in order
to draw any reliable conclusions.
\end{abstract}

\section{Introduction}
Implementation of numeric puzzles, in particular Sudokus, can be
carried out in many programming languages. Haskell, too, has been used to generate and solve
the logic-based number-placement Sudoku puzzle (for existing code, see https://homepages.cwi.nl/~jve/courses/16/fsa/lab/FSAlab3.html).
Briefly, the objective of the Sudoku is to fill a $9 \times 9$ grid with digits so that each column, each row, and each
of the nine $3 \times 3$ subgrids that compose the grid contain all of the digits
from 1 to 9. Translating this to code, this entails that there has to
be a surjective and injective function $f: \{1, ..., 9 \} \rightarrow R$ where $R$ is
one of the rows, one of the columns or one of the subgrids.\\\\
It is unclear whether code adapted to variations of this puzzle changes
the complexity of finding a solution such that it is detectable in Haskell. We might expect that adding
extra requirements to the puzzle forces Haskell to check for consistency more often, so that
it is less easy to find suitable values. Alternatively, additional requirements might limit the possibilities
for new values in open positions, so that it is in fact easier for Haskell to extend the Sudoku with new values.\\\\
To test these hypotheses, code was generated in the current project for two different types of Sudokus besides the regular one.
A `diagonal' Sudoku required both diagonals to contain all of the values $1$ up to $9$. Additionally,
a Sudoku type was implemented with four additional $3 \times 3$ blocks with left-top corners
$(2,2)$, $(2,6)$, $(6,2)$, and $(6,6)$ (coordinates denoting positions by (row, column)).
An attempt at comparing the complexity of the different types of Sudokus was made.

\section{Methods}
(The complete code can be found at the bottom of this report). First, the code for regular Sudokus was adapted to `diagonal' Sudokus and Sudokus
with additional subgrids. This entailed adding a definition of the required additional blocks, and
adding a `Restriction' type which specifies the elements of both diagonals and the additional blocks
(besides row, column and subgrid).
Instead of writing code for each restriction separately, the Restriction type was added as input
argument to functions like `injectiveFor', `consistent' and `freeAtPos', so that these only needed one instance.
For example, the latter function, which computes which values are available at a certain position in the grid, now looks like this:
\begin{code}
freeAtPos :: [Restriction] -> Sudoku -> (Row,Column) -> [Value]
freeAtPos x s (r,c) = foldr1 intersect [ freeInSeq (allValues res s (r,c)) | res <- x ]
\end{code}
The following lists of restrictions were defined, which describe all of the requirements
that each type of Sudoku should adhere to:
\begin{code}
normal :: [Restriction]
normal = [row, column, subGrid]

diagonal :: [Restriction]
diagonal = [row, column, subGrid, diagonalUp, diagonalDown]

addGrid :: [Restriction]
addGrid = [row, column, subGrid, addsubGrid]
\end{code}
In particular, the solveAndShow function now works by taking into account the type of Sudoku:
\begin{code}
solveAndShow :: Grid -> [Restriction] -> IO ()
solveAndShow gr x = solveShowNs x (initNode gr x)
\end{code}

Second, the random Sudoku generator was adapted so that it generates each type of
Sudoku. For this, an additional input argument for the list of restrictions that
decides the type of Sudoku was added to the existing functions. This way,
the code generates a filled Sudoku of the right type and subsequently removes values
until no value can be removed without the Sudoku becoming unsolvable.\\
The generated problem Sudoku is then fed back into the Sudoku solver. For this, the function
`genAndSolve' was defined:
\begin{code}
genAndSolve :: [Restriction] -> IO ()
genAndSolve x = do (_,s) <- sudGen x
                   showSudoku s
                   solveAndShow (sud2grid s) x
\end{code}\\\\
Third, to gain more insight into the search process, a counter was added to the recursive function `search'.
This way, the number of tries Haskell needs to find a solution was kept track of.
The function `solveAndShow' returns the number of counted steps along
with the solved Sudoku.\\\\
\begin{code}
search :: Int -> (node -> [node])
        -> (node -> Bool) -> [node] -> ([node], Int)
search w _ _ [] = ([],w)
search w children goal (x:xs)
  | goal x    = (x : fst (search w children goal xs), w)
  | otherwise = search (w+1) children goal (children x ++ xs)
\end{code}
Finally, the `genAndSolve' function was run 20 times for each type of Sudoku.
\begin{code}
genAndSolve :: [Restriction] -> IO ()
genAndSolve x = do (_,s) <- sudGen x
                  showSudoku s
                  solveAndShow (sud2grid s) x
\end{code}

\section{Results}
The results are displayed in Table 1, 2 and 3 below. Each column shows the results of
running genAndSolve ten times. The average number of steps per column can be found in bold at the bottom,
below which the overall average is shown.
\begin{center}
 \begin{tabular}{|c | c |}
 \hline
 \multicolumn{2}{|c|}{\textbf{Number of steps regular Sudoku}} \\[0.5ex]
 \hline\hline
 62 & 248  \\
 \hline
 133 & 76 \\
 \hline
 59 & 594 \\
 \hline
 248 & 290 \\
 \hline
 232 & 75 \\
 \hline
 319 & 473 \\
 \hline
 55 & 57 \\
 \hline
 59 & 60 \\
 \hline
 60 & 96 \\
 \hline
 419 & 976 \\
 \hline\hline
 \textbf{164.6} & \textbf{294.5} \\
 \hline
 \multicolumn{2}{|c|}{229.55} \\
 \hline
\end{tabular}
\end{center}
\noindent { \small $\it{Table {}1}$. This shows the number of steps Haskell
needed to solve the regular Sudoku 20 times.}

\begin{center}
 \begin{tabular}{|c | c |}
 \hline
 \multicolumn{2}{|c|}{\textbf{Number of steps addGrid Sudoku}} \\[0.5ex]
 \hline\hline
 238 & 30343  \\
 \hline
 1598 & 355681 \\
 \hline
 839 & 3279 \\
 \hline
 1544 & 770 \\
 \hline
 1548 & 13369 \\
 \hline
 938 & 17853 \\
 \hline
 496 & 9234 \\
 \hline
 1247 & 7838 \\
 \hline
 23577 & 1452 \\
 \hline
 1604 & 7444 \\
 \hline\hline
 \textbf{3362.9} & \textbf{44726.3} \\
 \hline
 \multicolumn{2}{|c|}{24044.6} \\
 \hline
\end{tabular}
\end{center}
\noindent { \small $\it{Table {}2}$. This shows the number of steps Haskell
needed to solve the Sudoku with additional grids 20 times.}

\begin{center}
 \begin{tabular}{|c | c |}
 \hline
 \multicolumn{2}{|c|}{\textbf{Number of steps diagonal Sudoku}} \\[0.5ex]
 \hline\hline
 290 & 264  \\
 \hline
 4376 & 146 \\
 \hline
 343 & 1053 \\
 \hline
 1311 & 1105 \\
 \hline
 9870 & 26144 \\
 \hline
 548 & 1926 \\
 \hline
 977 & 1455 \\
 \hline
 182 & 220 \\
 \hline
 385 & 4136 \\
 \hline
 2295 & 928 \\
 \hline\hline
 \textbf{2057.7} & \textbf{3737.7} \\
 \hline
 \multicolumn{2}{|c|}{2897.7} \\
 \hline
\end{tabular}
\end{center}
\noindent { \small $\it{Table {}3}$. This shows the number of steps Haskell
needed to solve the diagonal Sudoku 20 times.}

We see that the regular Sudoku on average requires the least number of steps (229.55 steps). Next
in line is the diagonal Sudoku with 2897.7 steps on average. The Sudoku with four
additional subgrids required most steps on average (24044.6 steps). However, there was
one extreme result for this type of Sudoku (355681 steps) which considerably affected this
average. Without this particular result, the average for this type of Sudoku is 6590.053 steps instead of
24044.6. Even though the new average is still higher than that of the diagonal Sudoku,
this shows that the results are subject to this type of fluctuations.

\section{Discussion \& conclusion}
In short, it appears that the results are relatively inconsistent, although a pattern
can be detected. The regular Sudoku seems to require the least number of steps that
Haskell needs, followed by the diagonal Sudoku. The Sudoku with four additional blocks
requires by far most steps. In line with these results, the approximate computation time
for Haskell for diagonal Sudokus and Sudokus with additional blocks exceeded that of the regular
Sudokus.\\\\
The results might be explained by the fact that normal Sudokus require less checking
for Haskell, as they have the least number of requirements that need to be fulfilled.
Furthermore, checking for additional subgrids each overlapped with four normal types of grids,
perhaps causing the computation to become more complex. The diagonals, although seemingly similar to additional rows
or columns, overlap with three normal subgrids and also need to fulfill $r + c == 10$ and $r == c$ for each of
their elements. Apparently adding these constraints makes a difference in complexity when solving the Sudoku. Thus, a preliminary conclusion
is that diagonal Sudokus and Sudokus with additional grids are indeed harder to solve
for Haskell.\\\\
In the current project it was assumed that every randomly generated Sudoku was
approximately of the same difficulty. This is not straightforward, however: the random Sudoku generator sometimes may have happened to generate
a rather easily solvable Sudoku, and other times a hard one. The number of Sudokus that
was currently run (20 of each type) is not enough to take away possible effects caused by this (e.g. if it happened to generate easier Sudokus
for the normal type in this experiment). In fact, as mentioned
in the results section this seems to have been of influence on the averages. Thus, the
results cannot yet be taken as reliable.\\\\
It should also be kept in mind that there is no obvious and official way to measure the
complexity of a Sudoku. The current method was only one way of analyzing the differences
between the solving of different types of Sudokus. To give a more complete view of
how Haskell solves different Sudokus, measures of other functions, computation time measurements and
visualization of intermediate steps in the solving process can be taken into account.
To be more precise it is necessary for there to be specific rules for what we define an easy or hard
Sudoku problem.\\\\
Something I did not have time to complete in the current project is to compare the
results to binary puzzles. These are Sudoku-like puzzles that only work with values
$0,1$ and require slightly different rules. Additionally, there are many other types
of Sudokus that can still be investigated in Haskell, as well as the mentioned different measures
of complexity.\\\\
Below, the entire code of the project is displayed, with comments explaining what
changes to the existing code were made.

\clearpage

% We include one file for each section. The ones containing code should
% be called something.lhs and also mentioned in the .cabal file.

\input{AllSudokusNew.lhs}

\addcontentsline{toc}{section}{Bibliography}
\bibliographystyle{alpha}
\bibliography{references.bib}
Code for regular Sudokus provided by Jan van Eijck, https://homepages.cwi.nl/~jve/courses/16/fsa/lab/FSAlab3.html

\end{document}


\section{How to evaluate the Results}

We will generate a table with the result of the experiments in the format below. Graphics are going to be created on demand as we analyze the results. Such results will provide all the information required to see how each method behaves, how different instances impact on each method, how big is the instance they can handle.

\begin{table}[ht!]
    \centering
    \begin{tabular}{|c|c|c|c|c|c|c|}
        \hline
        \multirow{2}{*}{Instance} &
            \multicolumn{2}{c|}{ILP} &
            \multicolumn{2}{c|}{greedy} &
            \multicolumn{2}{c|}{metaheuristic} \\
            & no. items & time & no. items & time & no. items & time\\
        \hline\hline
        X & 10 & 100 & 8 & 14 & 9 & 36 \\
        \hline
    \end{tabular}
    \caption{Results of the methods of solution. The time is given in seconds.}
\end{table}


\section{Introduction}

The paper \supercite{tonolini2019variational} proposes an improvement over the Variational Auto-Encoder (VAE) architecture  \supercite{Rezende2014, Kingma2013} by explicitly modelling sparsity in the latent space with a Spike and Slab prior distribution and drawing ideas from sparse coding theory. The main motivation behind their work lies in the ability to infer truly sparse representations from generally intractable non-linear probabilistic models, simultaneously addressing the problem of lack of interpretability of latent features. Moreover, the proposed model improves the classification accuracy using the low-dimensional representations obtained, and significantly adds robustness while varying the dimensionality of latent space. \\

The authors of the paper derive an analytic expression for the evidence lower bound (ELBO) of the VAE model by choosing the sparsity-inducing Spike and Slab prior distribution for the latent variables, which is later optimized using standard gradient methods to recover the encoding and decoding mappings. After training on well-known datasets, the Variational Sparse Coding (VSC) model is able to recover sparse, informative and interpretable representations given a fixed number of latent dimensions, which authors claim to be advantageous over standard VAE representations for classification tasks. \\

In this reproducibility report we study in detail the VSC model to implement the architectures described in the paper, run the  experiments (detailed in Section \ref{experiments}),  provide insights and suggestions for replicating results, and analyze the results obtained in comparison with the ones reported by the authors of the paper (Section \ref{insights}). Furthermore, we add modifications to improve the model performance and propose some possible future work directions (Section \ref{conclusions}).

\section{Related Work}

Variational Auto-Encoders have been extensively studied \supercite{Doersch2016} and widely modified in the recent years in order to encourage certain behavior of the latent space variables \supercite{Nalisnick2016, rolfe2016discrete, casale2018gaussian} or to be further applied for particular tasks \supercite{chen2016variational,walker2016uncertain, kusner2017grammar, jin2018junction}. Regarding the sparsity of the latent space for VAEs, previous work in the literature has focused on either explicitly incorporating a regularization term to benefit sparsity \supercite{louizos2017learning}, or fixing a prior distribution, such as Rectified Gaussians by \supercite{salimans2016structured},  discrete distributions by \supercite{van2017neural}, student-t distribution for Variational Information Bottleneck by \supercite{Chalk2016} and Stick Breaking Processes by \supercite{Nalisnick2016}. \\

Nonetheless, previous works have not allowed to explicitly model sparsity by incorporating linear sparse coding to non-linear probabilistic generative models.  The paper we aim to reproduce offers a connection between both areas through the  Spike-and-Slab distribution, chosen as a prior distribution for the latent variables. Although this distribution has been commonly used for modeling sparsity \supercite{Goodfellow2012}, it has rarely been applied to generative models. Moreover, since sparse coding imposes efficient data representations \supercite{ishwaran2005spike, titsias2011spike, bengio2013representation}, the authors demonstrate qualitatively how the sparse learned representations can capture subjectively understandable sources of variation. \\

Following the line of latent features interpretability, we can observe that the authors' idea is closely related to the Epitomic VAE by \supercite{yeung2016epitomic}, which learns the latent dimensions the recognition function should exploit. Many recent approaches, mostly related to disentangled representations, such as  $\beta$-VAE  \supercite{higgins2016beta, Burgess2018} or Factor-VAE by \supercite{Kim2018}, focus on learning interpretable factorized representations of the independent data generative factors via generative models. However, these approaches although explicitly induce interpretation of the latent features, do not directly produce sparse representations in contrast with the VSC model. Hence, the authors' aim is to develop a model that directly induces sparsity in a continuous latent space, which in addition, results into a higher expectation of interpretability in large latent spaces. \\

Our work, as part of the reproducibility challenge, will contribute in clarifying the implementation details of the VSC model, corroborate the results, and assess a few concerns of the reviewers by adding small modifications to the model and experiments based on the insights obtained during the reproducibility challenge.

\section{Target Questions}

In order to assess the reproducibility of the paper and validate its conclusions, the main questions we will focus our efforts on answering are:
\begin{itemize}
    \item \textsc{Can we actually validate the reported results? }
    \item \textsc{Is it possible to interpret the latent features learned by the VSC model?}
    \item \textsc{How the proposed model can be further improved? }
\end{itemize}

\section{Experimental Methodology}
\label{experiments}

Within the experiments described in the paper, we focus on replicating the precise settings for:
\begin{itemize}
    \item \textit{ELBO evaluation}: to observe ELBO drop while optimizing the model loss.
    \item \textit{Classification Performance}: to use the learned presentations for classification tasks.
    \item \textit{Interpretation of sparse codes}: to visually inspect the role of learned latent features.
    \item \textit{Visualization / Traversal of Latent Space}: to qualitatively evaluate the reconstructed images.
\end{itemize}

We found that the paper was well written and moderately amenable for reproduction. Although the authors did not make the code available, writing the code from scratch was not as challenging as we anticipated. Thus, in this section, we describe in detail how our implementation of the model was carried out, clarify the adjustments considered and display the results obtained.

\subsection{Datasets}

We test the VSC model in two commonly used image datasets: MNIST \supercite{lecun1998gradient} and Fashion-MNIST \supercite{xiao2017fashion}, both composed of $28 \times 28$ grey scale images of handwritten digits and pieces of clothing respectively. Following the paper description, we run most of the experiments with these datasets. In addition to this, CelebA faces \supercite{liu2015deep} dataset was used to showcase qualitative results. We include in our repository routines to download and preprocess the datasets.

\subsubsection{Observations}

\begin{itemize}
    \item For the CelebA dataset, we used a subset of 100K samples for training and 20K samples for testing, which were center cropped and downsampled to a size of $32 \times 32$ using all $3$ RGB channels, as described in the paper.
    \item We applied a 0-1 Min-Max scaling to all the datasets. We observed that normalizing vectors to unitary norm, as the paper suggests, produced lower quality image reconstruction.
\end{itemize}

\subsection{Implementation Details}

We decided to replicate the architecture described in the paper using PyTorch \supercite{paszke2017automatic}. Our repository includes a few instructions on how to install and set up all the required libraries needed for running our implementation.  We organize the code on scripts for each model architecture, as well as Jupyter Notebooks for preprocessing, running experiments and visualization. \\

In order to establish a valid benchmark, we implemented the VAE architecture from \supercite{Kingma2013}, which, in the same way as the Variational Sparse Coding (VSC) model, was implemented by an encoder and a decoder function, both parametrized as fully connected neural networks. The architecture, implemented from scratch, allows to explicitly define the hyperparameters of the model (e.g., hidden layer dimension, latent space dimension, learning rate, epochs, batch size, etc.) and is highly modular, to encourage future modifications. \\

For the loss function, the authors used a continuous relaxation for the discrete binary component in the reconstruction term of the ELBO and applied the reparametrization trick \supercite{NIPS2015_5666} for the Spike and Slab distribution to obtain a differentiable expression which can be optimized. Implementing this code was straightforward, our implementation forces the parameter $c$ to increase by $0.001$ per iteration to benefit convergence stability. \\

We stored all the checkpoints for the trained models, for reproducibility purposes, together with the training logs which can be visualized using TensorBoard.

\subsubsection{Observations}
\begin{itemize}
    \item One of the missing details in the paper was the batch size. We assumed it to be $32$ samples per batch, due to our memory restrictions.
    \item The original paper suggests using $20,000$ iterations for model training using the ADAM optimizer \supercite{kingma2014adam} with learning rate ranging between $0.001$ and $0.01$. In particular, we implemented the VSC model in a way that the number of epochs is one hyperparameter. Thus, we fixed the number of epochs to be equivalent the number of iterations given by the paper; i.e., for MNIST and Fashion-MNIST we trained the VSC model for $11$ epochs with a batch size of $32$. We fixed a learning rate of $0.001$.
    \item A minor downside of the paper is that the weights initialization method was not specified. We initialized the weights with uniform random variables using the Kaiming initialization method \supercite{Kaiming2015} for all the layers, which is also the default method for linear layers in PyTorch.
    \item For the recognition function, in order to avoid numerical instability, we suggest to either use $\textit{clamp}$ or Sigmoid activation function to avoid spike values of zero (thus ensuring $\gamma_i < 1$).
\end{itemize}

\subsection{Reproducibility cost}

Given that there was no mention in the paper about computational resources required, we describe the computational cost required for running the experiments. Since MNIST and Fashion-MNIST are relatively small datasets, the training procedure run on CPU took around $1$ minute per epoch and $8$ seconds per epoch on a Titan Xp GPU, using a latent size of $200$ units and a single hidden layer of 400 units for both the encoder and decoder, as described in the paper. On the other hand, the VSC model training time for the CelebA dataset was around $30$ seconds per epoch on a Titan Xp GPU, using a latent size of $800$ units and two hidden layers of $2000$ units also for the encoder and decoder. Regarding memory requirements on GPU, the network trained on MNIST and Fashion-MNIST consumed around $529$MB, which scaled up to $850$MB during training, while the network trained on CelebA consumed around $637$MB, which scaled up to $1322$MB during training. In conclusion, the computational cost for running the experiments is not high, which facilitated the reproduction of the results.

\section{Results}

\subsection{ELBO Evaluation}
We evaluated how the Variational Lower Bound (VLB) varies while changing the latent space dimension of the models: VSC - $\alpha = 0.2$, VSC - $\alpha = 0.5$ and VAE (Figure \ref{fig:vlb}). We observed that in general the ELBO decreases until reaching an optimal latent dimension and then they slowly increase as we add more latent dimensions.

\begin{figure}[h]
    \centering
    \captionsetup{justification=centering,margin=1cm}
    \begin{tabular}{ccc}
    \includegraphics[width=.45\textwidth]{figures/mnist_vlb} &
    \includegraphics[width=.45\textwidth]{figures/mnist_fashion_vlb} \\
    \textbf{(a)}  & \textbf{(b)}   \\[6pt]
\end{tabular}
    \centering
    \caption{Evaluation of ELBO on the test set for the VSC trained model at varying number of latent dimensions.}
    \label{fig:vlb}
\end{figure}

\subsection{Classification Performance}
We studied the classification accuracy obtained by using the latent representations as input (Figure \ref{fig:classification}), in order to validate the authors' conclusion that the Variational Sparse Coding learned representations improve the classification results and significantly increase robustness with respect to the latent number of dimensions. We can observe that for both MNIST and Fashion-MNIST, after surpassing the optimal latent dimension of the VAE, the representations learned by the VSC are significantly more informative as the latent dimension increases.

\begin{figure}[h]
    \centering
    \captionsetup{justification=centering,margin=1.3cm}
    \begin{tabular}{ccc}
    \includegraphics[width=.45\textwidth]{figures/mnist_class} &
    \includegraphics[width=.45\textwidth]{figures/mnist_fashion_class} \\
    \textbf{(a)}  & \textbf{(b)}   \\[6pt]
\end{tabular}
    \centering
    \caption{Classifications results on the test set (for MNIST (a) and Fashion-MNIST (b)) by varying the latent space dimensions using the model VSC - $\alpha = 0.01$ and a 2-layer fully connected neural network as base classifier. }
    \label{fig:classification}
\end{figure}

\subsection{Intepretation of sparse codes}
Authors claim the interpretability of the sparse learned representations. We qualitatively examined the interpretation of the non-zero elements in the sparse codes recovered with the VSC model by running interpolations in the sparse space varying the dimension with the highest absolute value (Figure \ref{fig:reconstruction}). In addition, we observe the effect of the latent dimensionality at capturing the image content (Figure \ref{fig:latent_dim}).

\begin{figure}[!h]
    \centering
    \captionsetup{justification=centering,margin=1cm}
    \begin{tabular}{ccc}
    \includegraphics[width=.45\textwidth]{figures/latent200_alpha001_ex2} &
    \includegraphics[width=.45\textwidth]{figures/latent200_alpha001_ex4} \\
    \textbf{(a)}  & \textbf{(b)}   \\[6pt]
\end{tabular}
    \centering
    \caption{Reconstruction results by modifying encoding in 200-dimensional latent space for MNIST (a) and Fashion-MNIST (b) for the model VSC - $\alpha = 0.01$.}
    \label{fig:reconstruction}
\end{figure}

\begin{figure}[!h]
    \centering
    \begin{tabular}{ccc}
    \includegraphics[width=.45\textwidth]{figures/latent_mnist_example} &
    \includegraphics[width=.45\textwidth]{figures/latent_fashion_example} \\
    \textbf{(a)}  & \textbf{(b)}   \\[6pt]
\end{tabular}
    \centering
    \caption{Encoding and reconstruction of samples using the VSC - $\alpha = 0.01$ model from MNIST (a) and Fashion-MNIST (b) datasets with varying latent dimensions of $8$, $96$ and $200$. }
    \label{fig:latent_dim}
\end{figure}

\subsection{Visualization / Traversing Latent Space}
We explored how sampling from the latent space distribution can allow us to obtain interpretable variations in the generated images (Figure \ref{fig:traversals}), and also how conditional sampling produces arguably realistic new samples from the same conceptual entity (Figure \ref{fig:conditional}). The traversal of the latent space is performed varying the latent codes with a high absolute value for a given image, one at a time. We can observe that these latent codes indeed represent interpretable features of the datasets, such as the digits shape in MNIST, the color and shape of the clothes in Fashion-MNIST and the orientation, background color, skin color and hair color in the CelebA results.

\begin{figure}[!h]
    \captionsetup{justification=centering,margin=0.3cm}
    \centering
    \begin{tabular}{ccc}
        \includegraphics[width=.47\textwidth]{figures/Mnist-traversal} &
        \includegraphics[width=.47\textwidth]{figures/Fashion-traversal} \\
        \textbf{(a)} & \textbf{(b)} \\ [6pt]
     \end{tabular}

     \centering
     \begin{tabular}{cccc}
          \includegraphics[width=.60\textwidth]{figures/CelebA_Traversal} \\
          \textbf{(c)} \\ [6pt]
     \end{tabular}

    \centering
    \caption{Traversing the latent space of the VSC - $\alpha = 0.01$ model trained for $11$ epochs on MNIST (a) and Fashion-MNIST (b) datasets, and $90$ epochs on CelebA (c) dataset.}
    \label{fig:traversals}
\end{figure}

\begin{figure}[!h]
    \captionsetup{justification=centering,margin=2cm}
    \centering
    \begin{tabular}{ccc}
    \includegraphics[width=.45\textwidth]{figures/mnist_conditional} &
    \includegraphics[width=.45\textwidth]{figures/mnist_fashion_conditional} \\
    \textbf{(a)}  & \textbf{(b)}   \\[6pt]
\end{tabular}
    \centering
    \caption{Conditional sampling from VSC - $\alpha = 0.01$ model trained for $11$ epochs on MNIST (a) and Fashion-MNIST (b) datasets.}
    \label{fig:conditional}
\end{figure}

\section{Analysis and discussion of findings}
\label{insights}

We should note that the paper we reproduced was clearly written and overall, despite a few implementation details unspecified (batch size, number of epochs for the CelebA training and weights initialization procedure), it is possible to replicate the results reported. Moreover, we are able to validate the authors hypothesis that the VSC models generate sparse, informative and interpretable representations. \\

Minor discrepancies in the results can be explained by the restricted number of training epochs. In particular, in Figure \ref{fig:vlb}, we observe a similar trend that the one shown in the paper; however, the gap between the curves can be decreased by training the model for larger number of iterations. Furthermore, in the log optimization files, we can easily notice that by using only $20K$ iterations the model has not reached a local optimum yet.  This situation is also present during training on the CelebA dataset: we noticed that at least $50$ epochs are needed to be close to a local optimum, as it is shown in Figure \ref{fig:CelebALoss}. We believe that authors must provide more specifications on the optimization hyperparameters to facilitate the reproducibility task.

\begin{figure}[h]
    \centering
    \captionsetup{justification=centering,margin=1.3cm}
    \includegraphics[width=.55\textwidth]{figures/CelebA_Loss}
    \centering
    \caption{Evaluation of training and test loss of the VSC model on the CelebA dataset}
    \label{fig:CelebALoss}
\end{figure}

Similarly, for the classification task (Figure \ref{fig:classification}) although we were able to obtain more informative representations using the VSC model with respect to VAE, the classification accuracy can still be improved by using a higher capacity classification model, instead of the simple classifier used in the original paper. \\

Many of the reviewers addressed the issue of how we can interpret the  learned latent features by the VSC-model. Although authors affirm that the model does not explicitly induce intepretation, it certainly results into a higher expectation of interpretability in large latent spaces, provided that the sources of variations in the observed data can be considered sparse. \\

To account for the blurriness of generated images (Figures \ref{fig:reconstruction} and \ref{fig:traversals}), we must understand that the model capacity is limited and perhaps convolutional architecture could drastically improve the quality of results.

\section{Conclusions}
\label{conclusions}

% Can we actually validate the results reported?
Overall the paper describes in enough detail the VSC model implementation and we must applaud the authors in their ability to convey such a complex topic in an approachable and replicable manner. The hypothesis of using Variational Sparse Coding to obtain sparse, informative and interpretable representations was confirmed by reproducing the experiments. \\

% Is it possible to interpret the latent features learned by the VSC model?
Further development on testing the model and comparing it against other sparse models on well known benchmarks is critical. In order to assess how \textit{interpretable} the learned latent features are, we could draw ideas from disentangled representations, to measure the effect of sparsity in the disentanglement metric, against benchmark models such as $\beta$-VAE or Factor-VAE. \\

% How the proposed model can be further improved?
To conclude our reproducibility report we propose the following directions for future research and improvement of current results:
\begin{itemize}
    \item  Increase the number of iterations suggested for training the models and re-run the experiments using the notebooks in our repository.
    \item  In order to improve the quality of generated images, we suggest to expand the model capacity by either stacking more layers or trying convolutional architectures for the encoder and decoder.
    \item Apply the model to the Disentanglement testing Sprites dataset, to measure the effect of sparsity on a disentanglement metric.
\end{itemize}

\subsubsection*{Acknowledgments}

We would like to thank to Emilien Dupont for clarifying distinct aspects on variational autoencoders' implementation, and Lukas Mosser for his suggestions on training generative models.

% Three years, we launched ReScience, a new scientific journal aimed at publishing the
% replication of existing computational research. Since ReScience published its first
% article\supercite{Topalidou:2015}, things have been
% going steadily. We are still alive, independent and without a budget. In the
% meantime, we have published around 24 articles (mostly in computational
% neuroscience \& computational ecology) and the initial
% \href{https://rescience-c.github.io/board/}{editorial board} has grown from
% around 10 to roughly 100 members (editors and reviewers), we have advertised
% ReScience at several conferences worldwide, gave some
% interviews\supercite{Science:2018}, and published an article introducing
% ReScience in PeerJ~CS\supercite{Rougier:2017}. Based on our
% experience\supercite{Rougier:2018} at managing the journal during these three
% years, we think that time is ripe for some changes.

% \subsubsection{ReScience C \& ReScience X}

% The biggest and most visible change we would like to propose is to change the
% name of the journal ``ReScience'' in favor of ``ReScience C'' where the C
% stands for (c)omputational. This change would be necessary to have consistent
% naming with the upcoming creation of the ``ReScience X'' journal that will be
% dedicated to e(x)perimental replications and co-directed by E.Roesch
% (University of Reading) and N.Rougier (University of Bordeaux). The name
% ``ReScience'' would then be used for the name of a non-profit organization
% (that is yet to be created) for the two journals as well as future journals
% (such as the utopian CoScience\supercite{Rougier:2017} or a future and
% tentative ``ReScience T'' for theoretical science).

% \subsubsection{A new submission process}

% The current submission process requires authors to fork, clone and branch the
% submission repository in order to write their article and to place code and
% data at the relevant places in the forked repository. Once done, authors have
% to push their changes and to make a pull request that is considered as a
% submission. This process is cumbersome for authors and has induced many
% troubles for editors as well once the article is accepted and ready to be
% published, mostly because of the complexity of the editing procedure. In order
% to make life easier for everyone, we greatly simplified the submission process
% for ReScience C and X. Authors are now responsible for getting a DOI for their
% code \& data and only have to submit a PDF and a metadata file in a GitHub
% issue.
% We also provide Python programs that largely automate the subsequent editing
% process. We will still archive the submission on Zenodo but this archive will
% be made for the final PDF only. However, both the PDF and the Zenodo entry will
% contain all associated DOIs (data and code).

% \subsubsection{A simplified publishing process}

% In ReScience, we have have been using a combination of
% \href{https://daringfireball.net/projects/markdown/syntax}{markdown} and
% \href{http://pandoc.org/}{pandoc} for producing both the draft and the final
% version of all the published articles. This had worked reasonably well until it
% started to cause all kind of problems for both authors and editors, especially
% with the reference and citation plugins. Consequently, articles will be now
% submitted directly in PDF with accompanying metadata in a separate file using
% the \href{https://en.wikipedia.org/wiki/YAML}{YAML} format (they were
% previously embedded in the markdown file). Once an article has been accepted,
% authors will be responsible for updating the metadata and for rebuilding the PDF if
% necessary. We could also consider using the
% \href{https://github.com/openjournals/whedon}{Whedon} API that helps with automating
% most of the editorial tasks for \href{http://joss.theoj.org/}{JOSS} and
% \href{http://jose.theoj.org/}{JOSE}. This will most probably require some
% tweaking because our publishing pipeline is a bit different.

% \subsubsection{A new design}

% The combination of markdown and pandoc has also severely limited the layout and
% style possibilities for the article template and since we are switching to
% \LaTeX, this is the opportunity to propose a new design based on a more elegant
% style, using a new font stack\supercite{SourceSerifPro:2014, Roboto:2011,
%   SourceCodePro:2012} (you are currently reading it). The goal is to have a
% subtle but strong identity with enhanced readability. Considering that articles
% will be mostly read on screen (as opposed to printed), we can benefit from a
% more ethereal style. Once this design will have stabilized, an
% \href{https://www.overleaf.com/}{overleaf} template will be made available for
% those without a \TeX~installation. If a \TeX~expert is ready to help review
% the template (and possibly rewrite it as a class), their help would be much
% welcome and appreciated. The same holds for LibreOffice, Word or Pages, any
% template is welcome, just contact us beforehand such that we can coordinate
% efforts.

% \subsubsection{Editorials, letters and special issues}

% ReScience C remains dedicated to the publication of computational replications
% but we (i.e., the editorial team) would like to have the opportunity to
% publish \emph{editorials} when deemed necessary and to give anyone the
% opportunity to write \emph{letters} to the community on a specific topic
% related to reproducibility. Both editorials and letters are expected to be 1 or
% 2 pages long (but no hard limit will be enforced), will be (quickly) peer reviewed,
% and will be assigned a DOI. Furthermore, with the advent of reproducibility
% hackatons worldwide, we will host {\em special issues} with guest editors (such
% as, for example, the organizers of a hackaton) in order to publish the results
% and to enhance their discoverability. Each entry will have to go through the
% regular open peer-reviewed pipeline.\\

% We hope that most readers will agree on the proposed changes such that we can
% commit to them in the next few weeks. The review for this editorial is open (as
% usual) and anyone can comment on and/or oppose any of the proposed changes. New
% ideas are also welcome.