%begin-include

\section{Additional results in formal logic}

\begin{lemma}
Let $A$ and $B$ be any propositional forms. The formulas
\begin{statements}
\item \label{pcl1} $\lnot A \limplies (A \limplies B)$,
\item \label{pcl2} $A \limplies \lnot\lnot A$,
\item \label{pcl3} $A \limplies (\lnot B \limplies \lnot (A\limplies B))$,
\item \label{pcl4} $(A\limplies B) \limplies ( (\lnot A \limplies B) \limplies B)$,
\end{statements}
are theorems of the formal system $\mathsf{P}$ of propositional logic.
\label{pcl}
\end{lemma}

\begin{proof}
What follows are some tedious, long and boring mechanical proofs.
It is hard to say that you will gain anything from carefully reading them other than convincing yourself that this lemma is true.
You have been advised. Proceed at your own discretion.
\begin{parlist}
\item It is immediate that $A, (A \limplies B), (B \limplies C) \vdash C$, so a simple application of the deduction theorem \ref[fund]{dedthmprop} reveals that
\[(A\limplies B), (B\limplies C) \vdash (A \limplies C).\]
This is known as the \emph{hypothetical syllogism rule} (HS).

With HS in our toolbox, we can perform the following proof in the formal system $\mathsf{P}$.
\begin{deduction}{notaaimpb}
\dstep[1]{\ref[fund]{axp1}}{\lnot A \limplies (\lnot B \limplies \lnot A),}
\dstep[2]{\ref[fund]{axp3}}{(\lnot B \limplies \lnot A) \limplies (A \limplies B),}
\dstep{HS on \dref{1} and \dref{2}}{\lnot A \limplies (A \limplies B).}
\end{deduction}

\item No fancy artefacts are required for this proof. We just need some patience.

\begin{deduction}{browerdisapproves}
\dstep[1]{\ref{pcl1}}{\lnot\lnot A \limplies (\lnot A \limplies \lnot\lnot\lnot A),}
\dstep[2]{\ref[fund]{axp3}}{(\lnot A \limplies \lnot\lnot\lnot A) \limplies (\lnot\lnot A \limplies A),}
\dstep[3]{HS on \dref{1}, \dref{2}}{\lnot\lnot A \limplies (\lnot \lnot A \limplies A),}
\dstep[4]{\ref[fund]{axp2}}{(\lnot\lnot A \limplies (\lnot\lnot A \limplies A)) \limplies ( (\lnot \lnot A \limplies \lnot \lnot A) \limplies (\lnot\lnot A \limplies A)),}
\dstep[5]{MP on \dref{3}, \dref{4}}{(\lnot \lnot A \limplies \lnot \lnot A) \limplies (\lnot\lnot A \limplies A),}
\dstep[6]{\ref[fund]{dedaa}}{\lnot\lnot A \limplies \lnot\lnot A,}
\dstep[7]{MP on \dref{5}, \dref{6}}{\lnot\lnot A \limplies A,}
\dstep[8]{Instance of \dref{7}}{\lnot\lnot\lnot A \limplies \lnot A,}
\dstep[9]{\ref[fund]{axp3}}{(\lnot\lnot\lnot A \limplies \lnot A) \limplies (A \limplies \lnot\lnot A),}
\dstep{MP on \dref{8}, \dref{9}}{A \limplies \lnot\lnot A.}
\end{deduction}

\item For this proof, we need some background results.
Firstly,we should notice that, for any formulas $A$ and $B$, we have $\lnot\lnot A, (A\limplies B) \vdash \lnot\lnot B$.
This follows from some simple applications of modus ponens taking into consideration that, as we showed in the previous deduction, $\lnot\lnot A \limplies A$ and $B \limplies \lnot\lnot B$ are both theorems of $\mathsf{P}$.
In addition, the application of the deduction theorem on this result yields the existence of a proof for
\begin{equation}
(A\limplies B) \limplies (\lnot\lnot A \limplies B).
\tag{$1*$}
\label{prelp31}
\end{equation}
Furthermore, some other applications of the deduction of theorem and the modus ponens rule on $A,(A\limplies B) \vdash B$ reveal that
\begin{equation}
A \limplies ( (A \limplies B) \limplies B)
\tag{$2*$}
\label{prelp32}
\end{equation}
is another theorem of $\mathsf{P}$.

With these preliminaries out of the way, we can now safely proceed to our proof.
\begin{deduction}{compleximplication}
\dstep[1]{\eqref{prelp31}}{(A \limplies B) \limplies (\lnot\lnot A \limplies \lnot\lnot B),}
\dstep[2]{\ref[fund]{axp3}}{(\lnot\lnot A \limplies \lnot\lnot B) \limplies (\lnot B \limplies \lnot A),}
\dstep[3]{MP on \dref{1}, \dref{2}}{(A\limplies B) \limplies (\lnot B \limplies \lnot A),}
\dstep[4]{Instance of \dref{3}}{( (A\limplies B) \limplies B) \limplies (\lnot B \limplies \lnot(A\limplies B)),}
\dstep[5]{\eqref{prelp32}}{A \limplies ( (A\limplies B) \limplies B),}
\dstep{HS on \dref{4}, \dref{5}}{A \limplies (\lnot B \limplies\lnot(A\limplies B)).}
\end{deduction}
By the way, observe that we have also shown
\begin{equation}
(A \limplies B) \limplies (\lnot B \limplies \lnot A)
\tag{$3*$}
\label{axp3vv}
\end{equation}
to be a theorem of $\mathsf{P}$.

\item As an auxiliary result, we need to prove that, given any formula $A\in L_P$,  the propositional form
\begin{equation}
(\lnot A \limplies A) \limplies A
\tag{$1\star$}
\label{prelp41}
\end{equation}
is a theorem in the formal system $\mathsf{P}$. If we consider an arbitrary $B \in L_P$, this can be through from the following deduction.
\begin{deduction}{auxresult3}
\dstep[1]{\ref{pcl1}}{\lnot A \limplies (A \limplies \lnot B),}
\dstep[2]{\ref[fund]{axp2}}{(\lnot A \limplies (A \limplies \lnot B)) \limplies ( (\lnot A \limplies A) \limplies (\lnot A \limplies \lnot B)),}
\dstep[3]{MP on \dref{1}, \dref{2}}{ (\lnot A \limplies A) \limplies (\lnot A \limplies \lnot B),}
\dstep[4]{\ref[fund]{axp3}}{(\lnot A \limplies \lnot B) \limplies (B \limplies A),}
\dstep[5]{HS on \dref{3}, \dref{4}}{ (\lnot A \limplies A) \limplies (B \limplies A),}
\dstep[6]{Instance of \dref{5}}{(\lnot A \limplies A) \limplies ( (\lnot A \limplies A) \limplies A),}
\dstep[7]{\ref[fund]{axp2}}{( (\lnot A \limplies A) \limplies ( ( \lnot A \limplies A) \limplies A ) ) \limplies ( ( ( \lnot A \limplies A) \limplies (\lnot A \limplies A)) \limplies ( (\lnot A \limplies A) \limplies A)),}
\dstep[8]{MP on \dref{6}, \dref{7}}{( (\lnot A \limplies A) \limplies (\lnot A\limplies A)) \limplies ( (\lnot A \limplies A) \limplies A),}
\dstep[9]{\ref[fund]{dedaa}}{(\lnot A \limplies A) \limplies (\lnot A \limplies A),}
\dstep{MP on \dref{8}, \dref{9}}{(\lnot A \limplies A) \limplies A.}
\end{deduction}

In addition, it is immediate that $\lnot B, (\lnot B \limplies \lnot A), (\lnot A \limplies B) \vdash B$, which, after some applications of the deduction theorem, shows that
\begin{equation}
(\lnot B \limplies \lnot A) \limplies ( (\lnot A \limplies B) \limplies (\lnot B \limplies B)).
\tag{$2\star$}
\label{prelp42}
\end{equation}
is another theorem of propositional logic.

We will now proceed to deduce $B$ from $(A\limplies B)$ and $(\lnot A \limplies B)$. This will, through some applications of the deduction theorem, yield the result we wanted to prove.
\begin{deduction}{auxresult4}
\dstep[1]{Hypothesis}{A \limplies B,}
\dstep[2]{\ref{pcl3}\eqref{axp3vv}}{(A\limplies B)\limplies (\lnot B \limplies \lnot A),}
\dstep[3]{MP on \dref{1}, \dref{2}}{\lnot B \limplies \lnot A,}
\dstep[4]{\eqref{prelp42}}{(\lnot B \limplies \lnot A) \limplies ( (\lnot A \limplies B) \limplies (\lnot B \limplies B),}
\dstep[5]{MP on \dref{3}, \dref{4}}{(\lnot A \limplies B) \limplies (\lnot B \limplies B),}
\dstep[6]{Hypothesis}{\lnot A \limplies B,}
\dstep[7]{MP on \dref{5}, \dref{6}}{ \lnot B \limplies B,}
\dstep[8]{\eqref{prelp41}}{(\lnot B \limplies B) \limplies B,}
\dstep{MP on \dref{7}, \dref{8}}{B.}
\end{deduction}
Having shown that $(A \limplies B), (\lnot A \limplies B) \vdash B$, the deduction theorem leads us to $\vdash (A\limplies B) \limplies ( (\lnot A \limplies B) \limplies B)$. This concludes the proof.
\end{parlist}
\end{proof}

\begin{lemma}
Let $A\in L_P$ be any propositional and let $i$ be any interpretation of propositional logic together with its induced valuation function $v_i$.
Without loss of generality, let $x_1,\ldots,x_k$ be the only distinct propositional variables appearing in $A$.

For every propositional form $\phi \in L_{P}$, we define $\phi^i$ as $\phi$ if $v_i(\phi) = 1$ and $\phi^i$ as $\lnot \phi$ if, otherwise, $v_i(\phi) = 0$.
Under these conditions,
\[ x_1^i,\ldots,x_k^i \vdash A^i.\]
\label{<+label+>}
\end{lemma}

\begin{proof}
We will prove this by induction on the number of connectives in $A$.
If $A$ has no connectives, then it will simply be the variable $x_1$ and, clearly, $x_1^i \vdash x_1^i$, so the base case is obvious.

Let us assume the result to hold for any formulas with $n$ or less connectives and show it for an arbitrary formula $A$ with $n+1$.
Necessarily, $A$ will be of the form $\lnot X$ or $X \limplies Y$ for $X,Y \in F_P$.
In either case, the result will hold, by hypothesis, for the subformulas $X$ and $Y$.

If $A$ is of the form $\lnot X$, we may have $v_i(X) = 0$ or $v_i(X) = 1$. If $v_i(X) = 0$, then $X^i$ will be $\lnot X$, so, by the inductive hypothesis, $x_1^i, \ldots, x_k^i \vdash \lnot X$.
Moreover, $v_i(X) = 0$ implies that $v_i(A) = v_i(\lnot X) = 1$, so $A^i$ will be $\lnot X$ and, therefore, we can conclude that $x_1^i,\ldots,x_k^i \vdash A^i$.

If $v_i(X) = 1$, then $X^i$ will be $X$ and we will have $v_i(A) = v_i(\lnot X) = 0$, so $A^i$ will be $\lnot\lnot X$.
In addition, by the inductive hypothesis, we know that $x_1^i,\ldots,x_k^i\vdash X$.
In conjunction with \ref{pcl}\ref{pcl2}, this shows that $x_1^i,\ldots,x_k^i \vdash \lnot\lnot X$ which translates into our desired $x_1^i,\ldots,x_k^i\vdash A^i$.

Let us now assume $A$ to be of the form $X \limplies Y$. We will consider three different subcases: one for $v_i(X) = 0$, one for $v_i(Y) = 1$ and one for $v_i(X) = 1$ and $v_i(Y) = 0$.

If $v_i(X) = 0$, then $X^i$ will be $\lnot X$ and we will obviously have $v_i(A) = v_i(X \limplies Y) = 1$, so $A^i$ will be $A$.
According to our inductive hypothesis, we know that $x_1^i,\ldots,x_k^i\vdash \lnot X$. Taking \ref{pcl}\ref{pcl1} into consideration, it follows that $x_1^i, \ldots,x_k^i \vdash (X\limplies Y)$, hence $x_1^i, \ldots,x_k^i \vdash A$ as we wanted to show.

If $v_i(Y) = 1$, $Y^i$ will be $Y$ and we will also have $v_i(A) = v_i(X\limplies Y) = 1$. In this scenario, our hypothesis states that $x_1^i, \ldots,x_k^i \vdash Y$, which, using \ref[fund]{axp1}, leads us to $x_1^i,\ldots,x_k^i \vdash X \limplies Y$.

Lastly, if $v_i(X) = 1$ and $v_i(Y) = 0$, we will have $v_i(A) = 0$, so $A^i$ will be $\lnot(X \limplies Y)$. By the inductive hypothesis,
\[ x_1^i,\ldots,x_k^i \vdash X,\qquad x_1^i,\ldots,x_k^i \vdash \lnot Y,\]
which, together with \ref{pcl}\ref{pcl3}, leads to $x_1^i,\ldots,x_k^i \vdash \lnot(X\limplies Y)$ and completes our proof.
\end{proof}

\begin{theorem}
The formal system $\mathsf{P}$ of propositional logic is semantically complete.
\label{psemcom}
\end{theorem}

\begin{proof}
Let $A$ be any tautology. We aim to prove that it is a theorem in $\mathsf{P}$.

According to our previous lemma, letting $x_1,\ldots,x_k$ be the only distinct propositional variables appearing in $A$, if we fix any interpretation $i$, we will have $x_1^i,\ldots,x_k^i \vdash A^i$. Nonetheless, as $A$ is a tautology, it will be true under any interpretation $i$ and, therefore, $A^i$ will be $A$.

We can pick any two interpretations $i$ and $j$ that make $x_k$ true and false respectively and that are equal in all the remaining variables, this is, that satisfy $v_i(x_k) = 1$, $v_j(x_j) = 0$ and $v_i(x_l) = v_j(x_l)$ if $k \neq l$.
According to our previous lemma, we will have
\[ x_1^i,\ldots,x_{k-1}^i,x_k \vdash A,\qquad
x_1^i,\ldots,x_{k-1}^i, \lnot x_k \vdash A,\]
where we have used the fact that $x_l^i$ is the same as $x_l^j$ if $l \neq k$.
Applying the deduction theorem, we are thus led to
\[ x_1^i,\ldots,x_{k-1}^i \vdash (x_k \limplies A),\qquad
x_1^i,\ldots,x_{k-1}^i \vdash (\lnot x_k \limplies A).\]
If we now consider \ref{pcl}\ref{pcl4}, it is immediate that
\[ x_1^i,\ldots,x_{k-1}^i \vdash A.\]
A recursive application of this reasoning eventually leads to $\vdash A$.
\end{proof}

\begin{lemma}
Let $\mathsf{H}$ be a consistent first-order system defined on a certain first-order language.
There exists a consistent extension of the set of non-logical axioms of $\mathsf{H}$ (also known as an extension of $\mathsf{H}$) that makes $\mathsf{H}$ syntactically complete.
\label{fol-scext}
\end{lemma}

\begin{proof}
Let us consider an infinite enumeration $A_1,\ldots,A_n,\ldots$ of all the formulas in the first-order language under consideration.
Such an enumeration can indeed be constructed and I will leave the details for you.
We define a sequence of extensions of $\mathsf{H}$ as follows. Firstly, the formal system $\mathsf{H}_0$ will be $\mathsf{H}$ itself. Then, for every natural $n$, we will define $\mathsf{H}_n$ to be the extension of $\mathsf{H}_{n-1}$ including $\lnot A_n$ as an axiom if $A_{n}$ is not a theorem in $\mathsf{H}_{n-1}$. If it is a theorem, we define $\mathsf{H}_n$ to be $\mathsf{H}_{n-1}$.

By \ref[fund]{notacons}, we know that each of this extensions will be consistent. Thus, if we consider the extension $\mathsf{H}_{\infty}$ including as axioms all the axioms of all the $\mathsf{H}_n$ for every $n\in\mathbb{N}$, it is immediate that it will be consistent too.
In addition, it can be easily seen that $\mathsf{H}_\infty$ will be a syntactically complete extension. Just assume that there is a sentence $A$ such that neither $A$ or $\lnot A$ are theorems in $\mathsf{H}_\infty$. Shouldn't one of them have been added as an axiom in a certain  $\mathsf{H}_n$?
\end{proof}

\begin{theorem}
Any consistent first-order formal system $\mathsf{H}$ has a (countable!) model.
\label{foconmodel}
\end{theorem}

\begin{proof}
Let us consider the formal system $\mathsf{H}_0$ obtained by adding an infinite sequence of symbols $b_0,\ldots,b_n,\ldots$ to the particular language it uses.

It is easy to see that the addition of these symbols has no effect in the consistency of the system.
It suffices to show how a proof in the new formal system of any statement $A$ can be transformed into one, in the old system, of the formula $A'$ obtained by replacing every constant $b_1,\ldots,b_n,\ldots$ in $A$ by a new variable not occurring in $A$.
Thus, should the new system be able to prove both $A$ and $\lnot A$, the old one would prove $A'$ and $\lnot A'$, but that would be impossible for we have assumed $\mathsf{H}$ to be consistent.

We can now consider an enumeration $A_1,\ldots,A_n,\ldots$ of all the formulas in the language of $\mathsf{H}_0$ with a single free variable --- which we will denote, for each $A_n$, as $y_n$.
From this point, we define a sequence of extensions of $\mathsf{H}_0$ as follows.
The first element of this sequence will obviously be $\mathsf{H}_0$.
Then, for every natural $n$, we will take $\mathsf{H}_n$ to be the extension of $\mathsf{H}_{n-1}$ incorporating the additional axiom $S_n$ given by
\[ A_n(y_n\Vert c_n) \limplies (\forall y_n) A_n,\]
where $c_n$ is the first element in $b_1,\ldots,b_n,\ldots$ that does not appear in $A$ and that does not belong to $\{c_1,\ldots,c_{n-1}\}$.

Let us show that all these extensions will be consistent. Given any natural $n$, we will assume that $\mathsf{H}_n$ is not consistent and, therefore, that it can prove, for a certain formula $A$, both $A$ and $\lnot A$.
According to the principle of explosion, this means that we will be able to prove $\vdash_{\mathsf{H}_n} \lnot S_n$. Proofs in $\mathsf{H}_n$ are deductions from $S_n$ in $\mathsf{H}_{n-1}$. Considering this fact together with the deduction theorem yields
\[ \vdash_{\mathsf{H}_{n-1}} S_n \limplies \lnot S_n.\]
Since $(A \limplies \lnot A) \limplies \lnot A$ is a tautology, we can then deduce that $\lnot S_n$ will be a theorem in $\mathsf{H}_{n-1}$, so we will have
\[ \vdash_{\mathsf{H}_{n-1}} \lnot \left( A_n(y_n\Vert c_n) \limplies (\forall y_n) A \right).\]
As both $\lnot(A\limplies B) \limplies A$ and $\lnot(A \limplies B) \limplies \lnot B$ are tautologies, this means that
\[ \vdash_{\mathsf{H}_{n-1}} A_n(y_n\Vert c_n),\qquad
\vdash_{\mathsf{H}_{n-1}} \lnot (\forall y_n) A_n.\]
As $c_n$ does not appear in the axioms of $\mathsf{H}_{n-1}$, we can safely replace each occurrence of $c_n$ in the proof of $A_n(y_n\Vert c_n)$ by a variable not appearing in the proof.
Then, an application of the generalisation rule reveals that $\vdash_{\mathsf{H}_{n-1}} (\forall y_n) A_n$, which would mean that $\mathsf{H}_{n-1}$ would not be consistent, thus contradicting our hypothesis and showing the consistency of all the extensions in the sequence.

As all these extensions are consistent, the formal system $\mathsf{H}_\infty$ defined as the extension of $\mathsf{H}_0$ containing all the axioms $A_n$ will be consistent too.
We can now consider the (consistent) extension $\mathsf{H}^*$ of $\mathsf{H}_\infty$ obtained from a direct application of lemma \ref{fol-scext}.

We will now show that every element in the domain of any model of $\mathsf{H}^*$ can be referenced directly from the language.
Formally, this means showing that, given any formula $A_n$ with a single free variable $y_n$, if --- for every \emph{closed term} $t$ (term with no free variables) --- $A(y_n\Vert t)$ is a theorem, then so is $(\forall y_n) A$.

This is fairly easy to do. If we assume $A_n(y_n\Vert t)$ to be a theorem for every closed term $t$, then, in particular, $A(y_n\Vert c_n)$ will be a theorem. Thus, applying modus ponens on $S_n$, one can prove $\vdash_{\mathsf{H}_\infty} (\forall y_n) A$.

We will now define an interpretation of $\mathsf{H}^*$ that will be a model for it and, therefore, will also define a model for $\mathsf{H}$. This interpretation will have as domain of discourse the set of closed terms of the language of $\mathsf{H}^*$ (recall that it is the extension of the language of $\mathsf{H}$ with the additional constants $b_i$).
The interpretation of each constant $b_i$ will be itself and the functions will behave in the obvious way.
The interpretation of each $n$-ary predicate symbol $P$ will be the predicate that, for any closed terms $t_1,\ldots,t_n$ is true if and only if $P(t_1,\ldots,t_n)$ is a theorem in $\mathsf{H}^*$.

We can then prove by induction on the number of connectives that any closed formula is a theorem in $\mathsf{H}^*$ if and only if it is true in the interpretation we have defined.
Taking the generalisation rule into consideration, this can be trivially extended to non-closed formulas, which implies that our interpretation is, indeed, a model of $\mathsf{H}^*$.
From the existence of a model of $\mathsf{H}^*$, the existence of a model for $\mathsf{H}$ can be trivially inferred.

Proving, by induction on the number of connectives, that closed formulas in $\mathsf{H}^*$ are theorems if and only if they are true is fairly straightforward and somewhat entertaining if you have a good understanding of the material. I will leave it to you.
Keep in mind that --- at least for the purpose of convincing yourself this result is true --- you don't need to write a fully-fledged formal proof.
A few diagrams and notes and a good dose of thinking will probably suffice.
\end{proof}


\documentclass{article}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[section]{placeins}
\renewcommand{\thesubsection}{\thesection.\alph{subsection}}
\usepackage{listings}
\usepackage{amssymb}

\title{\bf{CSE397: Assignment \#2}}
\author{Nicholas Malaya \\ Department of Mechanical Engineering \\
Institute for Computational Engineering and Sciences \\ University of
Texas at Austin} \date{}

\begin{document}
\maketitle

\newpage
\section{Problem 1}

\subsection{Find and classify all stationary points}

\begin{figure}[!htb]
  \includegraphics[scale=.5]{figs/1_3d.pdf}
  \label{fig:3d}
  \caption{The topology of -cos(x)cos(y/10) in the domain.}
\end{figure}

Figure one shows a clear stationary point at (0,0). In addition, we are
seeking all points where $\nabla f = 0$.  The gradient of $\nabla f =
(\text{sin}(x)\text{cos}(y/10),\frac{\text{cos}(x)}{10}\text{sin}(y/10))$. Solving
$\text{sin}(x)\text{cos}(y/10) = 0$  and
$\frac{\text{cos}(x)}{10}\text{sin}(y/10) = 0$ shows that while the
directional derivative of x is zero at $y \pm \frac{10 \pi}{2}$ and the
y-derivative is zero at $x \pm \frac{\pi}{2}$, the entire gradient is
only zero at (0,0). Thus, this is the only fixed point in the region we
are considering.

\subsection{Find the region where the Hessian Matrix of f(x,y) is positive definite.}

\begin{equation*}
H = \left(
  \begin{array}{ c c }
     \frac{\partial^2 f}{\partial x^2} & \frac{\partial^2 f}{\partial x
      \partial y} \\
     \frac{\partial^2 f}{\partial x
      \partial y} & \frac{\partial^2 f}{\partial y^2}
  \end{array} \right)
=
\left(
  \begin{array}{ c c }
     \text{cos}(x)\text{cos}(y/10) & -\frac{\text{sin}(x)}{10}\text{sin}(y/10) \\
     -\frac{\text{sin}(x)}{10}\text{sin}(y/10) & \frac{\text{cos}(x)}{100}\text{cos}(y/10)
  \end{array} \right)
\end{equation*}

Then setting the determinant of the matrix ($H - \lambda = 0$) to zero yields:
\begin{equation*}
		\lambda^2 - \frac{101}{100}\cos(x)\cos(\frac{y}{10})\lambda + \frac{1}{100}(\cos^2(x)\cos^2(\frac{y}{10}) - \sin^2(x)\sin^2(\frac{y}{10})) = 0
\end{equation*}
The eigenvalues are therefore,
\begin{equation*}
		\lambda = \frac{1}{200}\left[101\cos(x)\cos(\frac{y}{10}) \pm \sqrt{9801\cos^2(x)\cos^2(\frac{y}{10}) + 400\sin^2(x)\sin^2(\frac{y}{10})}\right]
\end{equation*}
The first eigenvalue is always positive. The second is positive when the
terms in the square root are positive, e.g.
\begin{equation*}
 \cos^2(x)\cos^2(\frac{y}{10}) - \sin^2(x)\sin^2(\frac{y}{10}) > 0
\end{equation*}
In other words,
\begin{equation*}
 \cos^2(x)\cos^2(\frac{y}{10}) > \sin^2(x)\sin^2(\frac{y}{10})
\end{equation*}

\begin{figure}[!htb]
  \includegraphics[scale=.5]{figs/eigen.pdf}
  \caption{The Contours of the Eigenvalues. The red line at the top is
 the region where the Hessian is positive definite. }
\end{figure}
The bounds of this region are plotted in figure 2.

\newpage
\subsection{Derive expressions for the search directions}

The search direction for steepest descent is the negative gradient,
e.g.
\begin{equation*}
g = -\nabla f =\left(
  \begin{array}{ c }
     - \text{sin}(x)\text{cos}(y/10)\\
     - \frac{\text{cos}(x)}{10}\text{sin}(y/10)
  \end{array} \right)
\end{equation*}
For newton, the step direction is $H_k p_k = g_k$ or,
\begin{equation*}
\left(
  \begin{array}{ c c }
     \text{cos}(x)\text{cos}(y/10) & -\frac{\text{sin}(x)}{10}\text{sin}(y/10) \\
     -\frac{\text{sin}(x)}{10}\text{sin}(y/10) & \frac{\text{cos}(x)}{100}\text{cos}(y/10)
  \end{array} \right)
  p_k
  =
\left(
 \begin{array}{ c }
  - \text{sin}(x)\text{cos}(y/10)\\
  - \frac{\text{cos}(x)}{10}\text{sin}(y/10)
   \end{array} \right)
\end{equation*}
Which is,
\begin{equation*}
 p_k =
\left(
\begin{array}{c}
 \frac{\sin (2 x) \left(\cos \left(\frac{y}{5}\right)-\sin
   \left(\frac{y}{5}\right)-1\right)}{2 \left(\cos (2 x)+\cos
   \left(\frac{y}{5}\right)\right)} \\
 -\frac{20 \sin \left(\frac{y}{10}\right) \left(\cos
   \left(\frac{y}{10}\right) \cos ^2(x)+\sin ^2(x) \sin
   \left(\frac{y}{10}\right)\right)}{\cos (2 x)+\cos
   \left(\frac{y}{5}\right)}
\end{array}
\right)
\end{equation*}

\subsection{Write a program that performs both steepest descent and a
  Newton Iteration}

\begin{figure}[!htb]
  \includegraphics[scale=.5]{figs/P1SDNLSwin.jpg}
  \caption{Steepest Descent from within the region of stability,
 converging to the solution at (0,0).}
\end{figure}

\begin{figure}[!htb]
  \includegraphics[scale=.5]{figs/P1SDNLSFail.jpg}
  \caption{Steepest Descent from outside the region of stability, yet
 still converging to the solution at (0,0).}
\end{figure}

\begin{figure}[!htb]
  \includegraphics[scale=.5]{figs/P1NMWLSwin.jpg}
  \caption{Newton's Method with line search inside the region of
 stability, converging correctly.}
\end{figure}

\begin{figure}[!htb]
  \includegraphics[scale=.5]{figs/P1NMWLSFail.jpg}
  \caption{Newton's Method with line search outside the region of
 stability, diverging. Hint: look at the bottom right.}
\end{figure}

\begin{figure}[!htb]
  \includegraphics[scale=.5]{figs/P1NMNLSwin.jpg}
  \caption{Newton's Method without line search inside the region of
 stability, converging correctly.}
\end{figure}

\begin{figure}[!htb]
  \includegraphics[scale=.5]{figs/P1NMNLSFailinside.jpg}
  \caption{Newton's Method without line search inside the region of
 stability, yet not converging correctly.}
\end{figure}

\subsection{What do you observe about convergence rates in these cases?}

The number of iterations required to converge were nearly what I
expected. Steepest descent always converges, but is the slowest. A line
search improves it by dialing back the otherwise overly greedy step
sizes, but still significantly underperforms Newton's method.
Newton's method is fastest without a line search, but only within the
region where the function is very nearly quadratic. Outside of this
region, it fails.
\newline
\begin{tabular}{| l | c |}
 \hline
 Method & Number of iterations \\
 \hline
  Steepest Descent without line search & 212 \\
  Steepest Descent with line search & 81     \\
  Newton's Method with Line Search & 33      \\
  Newton's Method without Line Search & 3    \\
 \hline
\end{tabular}

\section{Problem 2}

\subsection{Show that the two problems have the same minimizers}

We can see that the problems must have the same minimizers
(e.g. $x^\star$) because $\beta$ is just a scale factor, and our solution
should be invariant to homogeneous linear mappings.

Intuitively, if we multiply our function at each point by 10x, then
the lowest point should remain in the same place (and likewise, for the
max).

More formally speaking, our first order necessary conditions for a local
minimizer, $x^\star$, require that if $x^\star$ is a local minimizer of
$f_2(x)$, then $g_2(x^\star) = 0 $ at the local minimizer.

However, $f_2(x) = \beta f_1(x)$. Therefore,  $f_2(x^\star) = \beta
f_1(x^\star)$, and $g_1(x^\star) = g_2(x^\star) = 0 $. Therefore, the
gradient is also zero at $x^\star$ for $f_1$.

\subsection{Compare Steepest Descent and Newton Directions at $x_0 \in \mathbb{R}$}

\begin{align*}
 p_k&=-g_k = -\nabla f_k\\
 p_{k,1}&=-g_{k,1}\\
 p_{k,2}&=-g_{k,2} = -\beta g_{k,1}
\end{align*}

Thus,
\begin{equation}
p_{k,2} \ne p_{k,1}
\end{equation}
for steepest descent: the search directions
vary by a scale factor. However, using Newton's method, the first search
direction is,
\begin{align*}
 H_k p_k&=-g_k \\
 H_{k,1} p_{k,1}&=-g_{k,1}\\
\end{align*}
And the second is,
\begin{align*}
 H_{k,2} p_{k,2}&=-g_{k,2}\\
 \beta H_{k,1} p_{k,2}&=- \beta g_{k,1}\\
 H_{k,1} p_{k,2}&=-g_{k,1}
\end{align*}
And therefore,
\begin{equation}
p_{k,2} = p_{k,1}
\end{equation}
Thus, Newton's method is insensitive to the scale of the underlying
problem. Steepest decent on the other hand, does depent on the scale of
the underlying problem, and therefore it is not possible to make a good
initial step length, $\alpha$.

\subsection{Multidimensional expansion}

The result from the previous section is generalizable to
multi-dimensions. Now, instead of $\beta$ we have B, a matrix of
positive elements that scale the function f(x) that we are trying to
minimize. Note that B is invertible, has full rank and is independent of
x.

\begin{equation}
 Bg(x) = 0
\end{equation}
As before, our Newton step is insensitive to the scale of the system we
are solving,
\begin{align*}
 H_{k} p_{k}&=-g_{k}\\
 B H_{k} p_{k}&=- B g_{k}\\
 (B^{-1}B)H_{k} p_{k}&=-(B^{-1}B)g_{k} \\
 H_{k} p_{k}&=-g_{k}
\end{align*}
This is because the same scale factor will ``push-through'' the Hessian
Matrix, e.g.
\begin{equation}
H(x) = \nabla\nabla B f(x) = B \nabla\nabla f(x)
\end{equation}
Thus, Newton's method is affine invariant, e.g. independent of linear
changes of coordinates.

\section{Problem 3}

Write a program to minimize a quartic form -- a homogeneous polynomial
of degree four.
\newpage
\subsection{Compare the performance between Newton and Steepest Descent}

% mu = 0 sigma = 10
\begin{figure}[!htb]
        \centering
        \begin{subfigure}[bh]{0.45\textwidth}
                \includegraphics[width=\textwidth]{figs/P3SDmu0sig1.jpg}
        \end{subfigure}%
        \begin{subfigure}[bh]{0.45\textwidth}
                \includegraphics[width=\textwidth]{figs/P3NCGmu0sig1eta1.jpg}
        \end{subfigure}
        \centering
        \begin{subfigure}[bh]{0.45\textwidth}
                \includegraphics[width=\textwidth]{figs/P3NCGmu0sig1eta2.jpg}
        \end{subfigure}%
        \begin{subfigure}[bh]{0.45\textwidth}
                \includegraphics[width=\textwidth]{figs/P3NCGmu0sig1eta3.jpg}
        \end{subfigure}
        \caption{Comparison between steepest descent and Newton CG at
 varying $\eta$, for $\mu=0$, $\sigma=1$.}
\end{figure}

In figure 9, we can see that roughly all of the plots are converging
non-linearly. This is surprising, because I did not expect the steepest
descent to converge at this rate. It is possible that gradient descent
is converging super-linearly because of the function. I would conjecture
that
this is related to the $mu=0$, and that by killing the lower order term
in the function, we are making it easier for our gradient vector to
point in the correct direction ``downhill''.

% mu = 10, sigma = 1
\begin{figure}[!htb]
        \centering
        \begin{subfigure}[bh]{0.45\textwidth}
                \includegraphics[width=\textwidth]{figs/P3SDmu10sig1.jpg}
        \end{subfigure}%
        \begin{subfigure}[bh]{0.45\textwidth}
                \includegraphics[width=\textwidth]{figs/P3NCGmu10sig1eta1.jpg}
        \end{subfigure}
        \centering
        \begin{subfigure}[bh]{0.45\textwidth}
                \includegraphics[width=\textwidth]{figs/P3NCGmu10sig1eta2.jpg}
        \end{subfigure}%
        \begin{subfigure}[bh]{0.45\textwidth}
                \includegraphics[width=\textwidth]{figs/P3NCGmu10sig1eta3.jpg}
        \end{subfigure}
        \caption{Comparison between steepest descent and Newton CG at
 varying $\eta$, for $\mu=10$, $\sigma=1$.}
\end{figure}
In figure 10, steepest descent only converges linearly. We can see that
when $eta$ is fixed at one half, the convergence is only linear for
newton as well, as expected. Both of the other methods for selecting
$eta$ give superior convergence rates (super-linear), as expected.

Therefore, aside from the $\mu=0$ case, the theoretical convergence
rates for these different choices are what we expected.

\end{document}


%!TEX root =  ../main.tex

\mychapters{Functions}{functions}{\chapdir/pics/Mountain-type_Woodland_Caribou}

Functions are the central objects of investigation in many subdivision of mathematics today, and
are very effective means of representing real-life phenomena. For example, in any given year,
there is one population of
deer in a certain forest.  Would it make sense for a forest ranger to answer you two numbers when
you ask how many \textit{Rangifer tarandus} (caribou) exist in a given range, at a certain time?

\begin{figure}[h]
\centering
\begin{tikzpicture}
    \begin{axis}%
    [
        %grid=major,
        xmin=0,
        xmax=12,
        axis x line=bottom,
        ytick={0,10,...,100},
        ymax=110
       % axis y line=middle,
    ]
        \addplot%
        [
            blue,%
            mark=none,
            samples=100,
            domain=0:12,
        ]
        (x,{1+100/(1+exp(-x+5))});
    \end{axis}
\end{tikzpicture}
\caption{Population of caribou over time}
\end{figure}

How do we model phenomena in the world?  Is it reasonable to expect
caribou population to follow a curve such as the above figure?  How can we
extract information from a graph like this?  If actual measurements diverge some
from the expectation established by the curve, are they \emph{wrong}?  Are functions
better tools than relations?  What else could there be?

\newpage
\chapterminitoc

This chapter is entitled functions.  You have been studying functions for several years now,
and should be familiar with function notation.  It is also possible to present functions
graphically, or in a table.  Lastly, we may write or speak a verbal description of a function,
but this requires technical jargon, with which you are just starting to become familiar.

Hopefully, your time in algebra classes until now has helped you achieve a basic familiarity
with certain elementary or parent functions.  You will need to recognize them in each
of the four ways.  These prototypical versions can be moved or stretched as needed.  They
can also be mirrored or reflected.  This should naturally lead to the observation that some
graphs are unchanged under certain types of reflection.

Lastly, we will introduce the rich and vast field of taking numerical data and generating
an algebraic equation, called regression.

%								1 - 1
\newpage
\invisiblesection{Representations}
\marginlessinput{\chapdir/0101p}
\newpage
\input{\chapdir/0101}
\newpage
\subsection{Exercises}
\marginlesspdf{\chapdir/0101xA.pdf}
\marginlesspdf{\chapdir/0101xB.pdf}
\marginlesspdf{\chapdir/0101xC.pdf}

%								1 -2
\newpage
\invisiblesection{Types}
\subsection{Pick x, Find y}
\marginlesspdf{ch01/0102p.pdf}
\newpage
\input{ch01/0102}
\newpage
\subsection{Exercises}
in Kuta
~\vfill

%								1 - 3
\newpage
\invisiblesection{Translations and Dilations}
\subsection{Multiplying and Adding Functions}
\marginlesspdf{ch01/0103pA.pdf}
%\newpage
\marginlesspdf{ch01/0103pB.pdf}
\newpage
\input{ch01/0103}
\newpage
\subsection{Exercises}
in Kuta
~\vfill

%								1 - 4
\newpage
\invisiblesection{Reflections and Symmetries}%
\marginlessinput{ch01/0104p}
\newpage
\input{ch01/0104}
\newpage
\subsection{Exercises}
in Kuta

%								1 - 5
\newpage
\invisiblesection{Regressions}
\subsection{Graphical Patterns}
\marginlesspdf{ch01/0105pA.pdf}
\newpage
\marginlesspdf{ch01/0105pB.pdf}
\input{ch01/0105}
\newpage
\input{\chapdir/0105x}

%								1 - 6
\newpage
\section{Review}
\input{ch01/0106}


\documentclass[12pt]{cdblatex}
\usepackage{exercises}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% --------------------------------------------------------------------------------------------
\section*{Exercise 3.4 More symmetries of Riemann}

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).

   \partial{#}::PartialDerivative.

   g_{a b}::Symmetric.
   g^{a b}::Symmetric.

   \Gamma^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2}).
   \Gamma_{a b c}::TableauSymmetry(shape={2}, indices={1,2}).

   GammaU := \Gamma^{a}_{b c} ->  1/2 g^{a d} (   \partial_{b}{g_{d c}}
                                                + \partial_{c}{g_{b d}}
                                                - \partial_{d}{g_{b c}}). # cdb(Gamma.000,GammaU)

   GammaD := \Gamma_{a b c} ->  1/2 (   \partial_{b}{g_{a c}}
                                      + \partial_{c}{g_{b a}}
                                      - \partial_{a}{g_{b c}}).           # cdb(Gamma.010,GammaD)

   Rabcd := R_{a b c d} ->   \partial_{c}{\Gamma_{a b d}}
                           - \partial_{d}{\Gamma_{a b c}}
                           + \Gamma_{e a d} \Gamma^{e}_{b c}
                           - \Gamma_{e a c} \Gamma^{e}_{b d}.             # cdb(Rabcd.000,Rabcd)

\end{cadabra}

\clearpage

% --------------------------------------------------------------------------------------------
\section*{Exercise 3.4 Antisymmetry on first pair of indices}

\begin{cadabra}
   expr := R_{a b c d} + R_{b a c d}.   # cdb(ex-0304.101,expr)

   substitute     (expr, Rabcd)         # cdb(ex-0304.102,expr)
   substitute     (expr, GammaU)        # cdb(ex-0304.103,expr)
   substitute     (expr, GammaD)        # cdb(ex-0304.104,expr)
   distribute     (expr)                # cdb(ex-0304.105,expr)
   product_rule   (expr)                # cdb(ex-0304.106,expr)
   sort_product   (expr)                # cdb(ex-0304.107,expr)
   rename_dummies (expr)                # cdb(ex-0304.108,expr)
   canonicalise   (expr)                # cdb(ex-0304.109,expr)
\end{cadabra}

\clearpage

\begin{dgroup*}[spread={3pt}]
   \Dmath*{\cdb{ex-0304.101} = \Cdb*{ex-0304.102}
                             = \Cdb*{ex-0304.103}
                             = \Cdb*[\hskip3.0cm\hfill]{ex-0304.104}
                             = \Cdb*{ex-0304.105}}
\end{dgroup*}

\clearpage

\begin{dgroup*}[spread={3pt}]
   \Dmath*{\cdb{ex-0304.101} = \Cdb*{ex-0304.106}
                             = \Cdb*{ex-0304.107}}
\end{dgroup*}

\clearpage

\begin{dgroup*}[spread={3pt}]
   \Dmath*{\cdb{ex-0304.101} = \Cdb*{ex-0304.108}
                             = \Cdb*{ex-0304.109}}
\end{dgroup*}

\clearpage

% --------------------------------------------------------------------------------------------
\section*{Exercise 3.4 Symmetric on swapping first and second pair of indices}

\begin{cadabra}
   expr := R_{a b c d} - R_{c d a b}.   # cdb(ex-0304.201,expr)

   substitute     (expr, Rabcd)         # cdb(ex-0304.202,expr)
   substitute     (expr, GammaU)        # cdb(ex-0304.203,expr)
   substitute     (expr, GammaD)        # cdb(ex-0304.204,expr)
   distribute     (expr)                # cdb(ex-0304.205,expr)
   product_rule   (expr)                # cdb(ex-0304.206,expr)
   sort_product   (expr)                # cdb(ex-0304.207,expr)
   rename_dummies (expr)                # cdb(ex-0304.208,expr)
   canonicalise   (expr)                # cdb(ex-0304.209,expr)
\end{cadabra}

\clearpage

\begin{dgroup*}[spread={3pt}]
   \Dmath*{\cdb{ex-0304.201} = \Cdb*{ex-0304.202}
                             = \Cdb*{ex-0304.203}
                             = \Cdb*[\hskip3.0cm\hfill]{ex-0304.204}
                             = \Cdb*[\hskip2.5cm\hfill]{ex-0304.205}}
\end{dgroup*}

\clearpage

\begin{dgroup*}[spread={3pt}]
   \Dmath*{\cdb{ex-0304.201} = \Cdb*[\hskip2.5cm\hfill]{ex-0304.206}
                             = \Cdb*[\hskip2.5cm\hfill]{ex-0304.207}}
\end{dgroup*}

\clearpage

\begin{dgroup*}[spread={3pt}]
   \Dmath*{\cdb{ex-0304.201} = \Cdb*[\hskip2.5cm\hfill]{ex-0304.208}
                             = \Cdb*{ex-0304.209}}
\end{dgroup*}

\end{document}


\documentclass[]{BasiliskReportMemo}

\newcommand{\submiterInstitute}{Autonomous Vehicle Simulation (AVS) Laboratory,\\ University of Colorado}

\newcommand{\ModuleName}{MRP\_Feedback}
\newcommand{\subject}{MRP Feedback ADCS Control Module}
\newcommand{\status}{Initial Documentation Draft}
\newcommand{\preparer}{H. Schaub}
\newcommand{\summary}{This module provides a general MRP feedback control law, applying to using $N$ reaction wheels with general orientation.     }

\begin{document}

\makeCover

%
%	enter the revision documentation here
%	to add more lines, copy the table entry and the \hline, and paste after the current entry.
%
\pagestyle{empty}
{\renewcommand{\arraystretch}{2}
\noindent
\begin{longtable}{|p{0.5in}|p{4.5in}|p{1.14in}|}
\hline
{\bfseries Rev}: & {\bfseries Change Description} & {\bfseries By} \\
\hline
Draft & Initial Draft document & H. Schaub \\
\hline

\end{longtable}
}

\newpage
\setcounter{page}{1}
\pagestyle{fancy}

\tableofcontents
~\\ \hrule ~\\

\section{Initialization}
Simply call the module reset function prior to using this control module.  This will reset the prior function call time variable, and reset the attitude error integral measure.  The control update period $\Delta t$ is evaluated automatically.

\section{Algorithm}
		 This module employed the MRP feedback algorithm of Example 8.16 of Reference\citenum{schaub}.  This  nonlinear attitude tracking control includes an integral measure of the attitude error.  Further, we seek to avoid quadratic $\bm\omega$ terms to reduce the likelihood of control saturation during a detumbling phase.  Let the new nonlinear feedback control be expressed as
		\begin{multline}
			\label{eq:GusRW}
			[G_{s}]\bm u_{s} = K \bm\sigma + [P] \delta\bm\omega + [P][K_{I}] \bm z - [I_{\text{RW}}](\dot{\bm\omega}_{r} - [\tilde{\bm\omega}]\bm\omega_{r}) + \bm L
			\\
			- ([\tilde{\bm \omega}_{r}] + [\widetilde{K_{I}\bm z}])
			\left([I_{\text{RW}}]\bm\omega + [G_{s}]\bm h_{s} \right)
		\end{multline}
		The integral attitude error measure $\bm z$ is defined through
		\begin{equation*}
			\bm z = K \int_{t_{0}}^{t} \bm\sigma \text{d}t + [I_{\text{RW}}](\delta\bm\omega - \delta\bm\omega_{0})
		\end{equation*}

		The integral measure $\bm z$ must be computed to determine $[P][K_{I}] \bm z$, and the expression $[\widetilde{K_{I}\bm z}]$ is added to $[\widetilde{\bm\omega_{r}}]$ term.

		To analyze the stability of this control, the following Lyapunov candidate function is used:
		\begin{equation*}
			V(\delta\bm\omega, \bm\sigma, \bm z) = \frac{1}{2} \delta\bm\omega^{T} [I_{\text{RW}}] \delta\bm\omega
			+ 2 K \ln ( 1 + \bm\sigma^{T} \bm\sigma) + \frac{1}{2} \bm z ^{T} [K_{I}]\bm z
		\end{equation*}
		provides a convenient positive definite attitude error function.  The attitude feedback gain $K$ is positive, while the integral feedback gain $[K_{I}]$ is a symmetric positive definite matrix.
		The resulting Lyapunov rate expression, solved in Eq.~(8.101), is given by
		\begin{equation*}
			\dot V =  (\delta\bm\omega + [K_{I}]\bm z)^{T} \left ( [I_{\text{RW}}] \frac{{}^{\mathcal{B \!}}\text{d}}{\text{d}t} (\delta\bm\omega) + K \bm \sigma \right )
		\end{equation*}
		Substituting the equations of motion of a spacecraft with $N$ reaction wheels (see Eq.~(8.160) in Reference~\citenum{schaub}), results in
		\begin{equation*}
			\dot V =  (\delta\bm\omega + [K_{I}]\bm z )^{T} \left (
			 - [\tilde{\bm\omega}] ([I_{\text{RW}}] \bm\omega +[G_{s}]\bm h_{s}) - [G_{s}] \bm u_{s} + \bm L
			 - [I_{\text{RW}}] ( \dot{\bm \omega}_{r} - [\tilde{\bm\omega}]\bm\omega_{r}) + K \bm\sigma
			\right)
		\end{equation*}
		Substituting the control expression in Eq.~\eqref{eq:GusRW} and making use of $\bm \alpha = \bm\omega_{r} - [K_{I}]\bm z$ leads  to
		\begin{align*}
			\begin{split}
			\dot V &=  (\delta\bm\omega + [K_{I}]\bm z )^{T} \Big (
			- ([\tilde{\bm\omega}] - [\tilde{\bm\omega}_{r}] + [\widetilde{K_{I}\bm z}]) ([I_{\text{RW}}] \bm\omega + [G_{s}]\bm h_{s})
			+( K \bm\sigma - K \bm\sigma)
			\\
			& \quad - [P]\delta\bm\omega - [P][K_{I}]\bm z + [I_{\text{RW}}](\dot{\bm\omega}_{r} - [\tilde{\bm\omega}]\bm\omega_{r}) - [I_{\text{RW}}](\dot{\bm\omega}_{r} - [\tilde{\bm\omega}]\bm\omega_{r})
			+ ( \bm L - \bm L)
			\Big)
			\end{split}
			\\
			&=  (\delta\bm\omega + [K_{I}]\bm z )^{T} \Big (
			 - ([\widetilde{\delta\bm\omega}] + [\widetilde{K_{I}\bm z}] )  ([I_{\text{RW}}] \bm\omega + [G_{s}]\bm h_{s})
			 - [P] (\delta\bm\omega + [K_{I}]\bm z)
			\Big )
		\end{align*}
		Because $(\delta\bm\omega + [K_{I}]\bm z )^{T}  ([\widetilde{\delta\bm\omega}] + [\widetilde{K_{I}\bm z}] ) = 0$, the Lyapunov rate reduces the negative semi-definite expression
		\begin{equation*}
			\dot V = -  (\delta\bm\omega + [K_{I}]\bm z )^{T} [P]  (\delta\bm\omega + [K_{I}]\bm z )
		\end{equation*}
		This proves the new control is globally stabilizing.  Asymptotic stability is shown following the same steps as for the  nonlinear integral feedback control in Eq. (8.104) in Reference~\citenum{schaub}.

		One of the goals set forth at the beginning of the example was avoiding quadratic $\bm\omega$ feedback terms to reduce the odds of control saturation during periods with large $\bm\omega$ values.  However, the control in Eq.~\eqref{eq:GusRW} contains a product of $\bm z$ and $\bm\omega$.  Let us study this term in more detail.  The $\bm\omega$ expression with this product terms is found to be
		\begin{equation*}
			[\widetilde{K_{I}\bm z}] ([I_{\text{RW}}]\bm \omega)
			 \quad \Rightarrow \quad
			-  (
			[\widetilde{I_{\text{RW}} \bm \omega}]
			 ) ([K_{I}] [I_{\text{RW}}] \bm \omega + \cdots )
		\end{equation*}
		If the integral feedback gain is a scalar $K_{I}$, rather than a symmetric positive definite matrix $[K_{I}]$, the quadratic $\bm\omega$ term vanishes.  If the full $3\times 3$ gain matrix is employed, then quadratic rate feedback terms are retained.

\bibliographystyle{unsrt}   % Number the references.
\bibliography{references}   % Use references.bib to resolve the labels.

\end{document}


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

\title{MAT257 Notes}
\author{Jad Elkhaleq Ghalayini}
\date{November 23 2018}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{cancel}

\usepackage[margin=1in]{geometry}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{definition}{Definition}
\newtheorem*{corollary}{Corollary}
\newtheorem{exercise}{Exercise}
\newtheorem{claim}{Claim}

\DeclareMathOperator{\Int}{Int}
\DeclareMathOperator{\grad}{grad}
\DeclareMathOperator{\Ker}{Ker}
\DeclareMathOperator{\Ima}{Im}

\newcommand{\reals}[0]{\mathbb{R}}
\newcommand{\nats}[0]{\mathbb{N}}
\newcommand{\ints}[0]{\mathbb{Z}}
\newcommand{\rationals}[0]{\mathbb{Q}}
\newcommand{\brac}[1]{\left(#1\right)}
\newcommand{\sbrac}[1]{\left[#1\right]}
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\eval}[3]{\left.#3\right|_{#1}^{#2}}
\newcommand{\ip}[2]{\left\langle#1,#2\right\rangle}
\newcommand{\prt}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\mb}[1]{\mathbf{#1}}
\newcommand{\hlfspc}[0]{\mathbb{H}}

\begin{document}

\maketitle

\section{Manifolds with boundary}

Recall the following definitions:
\begin{definition}
  A half space \(\hlfspc^k \subset \reals^k\) is given by
  \[\{x = (x_1,...,x_k) : x_k \geq 0\}\]
\end{definition}
\begin{definition}
  A subset \(M \subseteq \reals^n\) is a \(k\)-dimensional \(\mc{C}^r\) \underline{manifold with boundary} if for every \(a \in M\), there is an open neighborhood \(U\) of \(a\) in \(\reals^n\), an open subset \(V\) of \(\reals^n\) and a \(\mc{C}^r\) diffeomorphism \(h: U \to V\) such that either
  \begin{enumerate}[label=(\arabic*)]

    \item The usual condition for a manifold,
    \[h(M \cap U) = V \cap (\reals^k \times \{\mb{0} \in \reals^{n - k}\})\]
    \label{mnfcnd}

    \item The manifold looks like a half space around \(a\), i.e.
    \[h(M \cap U) = V \cap (\hlfspc^k \times \{\mb{0} \in \reals^{n - k}\}) = \{y = (y_1,...,y_n) : y_1,...,y_k \geq 0 \land y_{k + 1} = ... = y_n = 0\}\] \label{bndcnd}

  \end{enumerate}
  \label{mwb}
\end{definition}
One thing you could ask is whether both conditions \ref{mnfcnd}, \ref{bndcnd} could be satisfied by the same point \(a\). The answer is no. To show why, suppose \(h_1: U_1 \to V_1\) satisfies \ref{mnfcnd} and \(h_2: U_2 \to V_2\) satisfies \ref{bndcnd} for some \(a\). How can we get a contradiction? If we take
\[h_2 \circ h_1^{-1}: V_1 \to V_2\]
we get a \(\mc{C}^r\) diffeomorphism in an open set containing \(a\) taking an open subset of \(\reals^k\) onto an open subset of \(\hlfspc^k\) which is \textit{not} open in \(\reals^k\). What we're contradicting here is the inverse function theorem, which says there would be open neighborhoods \(h_1(a)\) and \(h_2(a)\) which are mapped together with an inverse. Alternatively, we could use the topological arguments that diffeomorphisms, which are homeomorphisms, are open maps.

Once we've established this result, we can really distinguish these two kinds of points. That means, precisely, that we can make the following definitions
\begin{definition}
  The \underline{boundary} of \(M\), written \(\partial M\), is the set of points satisfying condition \ref{bndcnd} in definition \ref{mwb}
\end{definition}

We're going to be interested in manifolds because they generalize the idea of intervals with endpoints in the real line. In fact, an interval with endpoints is a one dimensional manifold with boundary.

\end{document}


 \documentclass [12pt]{article}

\usepackage {amsmath}
\usepackage {amsthm}
\usepackage {amssymb}
\usepackage {graphicx}
\usepackage {float}
\usepackage {multirow}
\usepackage {xcolor}
\usepackage {algorithmic}
\usepackage [ruled,vlined,commentsnumbered,titlenotnumbered]{algorithm2e} \usepackage {array}
\usepackage {booktabs}
\usepackage {url}
\usepackage {parskip}
\usepackage [margin=1in]{geometry}
\usepackage [T1]{fontenc}
\usepackage {cmbright}
\usepackage [many]{tcolorbox}
\usepackage [colorlinks = true,
            linkcolor = blue,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = blue]{hyperref}
\usepackage {enumitem}
\usepackage {xparse}
\usepackage {verbatim}
\usepackage{listings}
\usepackage{xcolor}
\lstset { %
    language=C++,
    backgroundcolor=\color{black!5}, % set backgroundcolor
    basicstyle=\footnotesize,% basic font setting
}
\newtheorem{theorem}{Theorem}
\newtheorem{remark}{Remark}
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newtheorem{claim}{Claim}

\DeclareTColorBox {Solution}{}{breakable, title={Solution}} \DeclareTColorBox {Solution*}{}{breakable, title={Solution (provided)}} \DeclareTColorBox {Instruction}{}{boxrule=0pt, boxsep=0pt, left=0.5em, right=0.5em, top=0.5em, bottom=0.5em, arc=0pt, toprule=1pt, bottomrule=1pt} \DeclareDocumentCommand {\Expecting }{+m}{\textbf {[We are expecting:} #1\textbf {]}} \DeclareDocumentCommand {\Points }{m}{\textbf {(#1 pt.)}}

\begin {document}

\vspace {1em}
\begin {Instruction}
Adapted From Virginia Williams' lecture notes.
\end {Instruction}

{\LARGE \textbf {COMP 285 (NC A\&T, Spr `22)}\hfill \textbf {Lecture 24} }

\begin{centering}
\section*{Dynamic Programming II: Bellman-Ford}
\end{centering}

\section{More on the Bellman-Ford Algorithm}

We didn't quite make it to the Bellman-Ford algorithm in the last lecture, so we'll re-hash some of that again today. In the notes for the previous lecture, we introduced Bellman-Ford in the context of Dijkstra's algorithm. We'll see it in this lecture in a different way, so as to naturally introduce \textit{dynamic programming}. The Bellman-Ford algorithm is a dynamic programming algorithm, and dynamic programming is a basic paradigm in algorithm design used to solve problems by relying on intermediate solutions to smaller subproblems. The main step for solving a dynamic programming problem is to analyze the problem's \textbf{optimal substructure} and \textbf{overlapping subproblems}.

The Bellman-Ford algorithm is pretty simple to state:

\begin{algorithm}
\caption{Bellman-Ford Algorithm(G,s)}
\label{alg:bellman-ford}
\begin{algorithmic}
\STATE $d^{(0)}[v] \gets \infty, \forall v \in V$
\STATE $d^{(0)}[s] \gets 0$
\STATE $d^{(k)}[v] = \texttt{None}, \forall v \in V, \forall k > 0$
\FOR{$i$ from $1 \to n - 1$}
  \STATE $d^{(k)}[v] \gets d^{(k-1)}[v]$ for all $v$
  \FOR{$(u,v) \in E$}
    \STATE $d^{(k)}[v] \gets \min\{d^{(k)}[v], d^{(k-1)}[u] + w(u,v) \}$
  \ENDFOR
  \STATE \texttt{// Here we release the memory for } $d^{(k-1)}$ \texttt{, we'll never need it again}
\ENDFOR
\RETURN $d^{(n-1)}[v], \forall v \in V$
\end{algorithmic}
\end{algorithm}

What's going on here? The value $d^{(k)}[v]$ is the cost of the shortest path from $s$ to $v$ with at most $k$ edges in it. Once we realize this, a proof by induction falls right out, with the inductive hypothesis that ``$d^{(k)}[v]$ is the cost of the shortest path from $s$ to $v$ with at most $k$ edges in it.''

\textbf{Runtime and Storage} The runtime of the Bellman-Ford algorithm is $O(mn)$; for $n$ iterations, we loop through all the edges. This is slower than Dijkstra's algorithm. However, it is simpler to implement, and further as we saw in Lecture Notes 23, it can handle negative edge weights. For storage, in the pseudocode above, we keep n different arrays $d^{(k)}$ of length $n$. This isn't necessary: we only need to store two of them at a time. This is noted in the
comment in the pseudocode.

\subsection{What's really going on here?}

The thing that makes that Bellman-Ford algorithm work is that that the shortest paths of length at most $k$ can be computed by leveraging the shortest paths of length at most $k - 1$. More specifically, we relied on the following recurrence relation between the intermediate solutions:

$$
d^{(k)} [v ] = \min_{u \in V}\{ d^{(k-1)}[u] + w(u, v ) \}
$$

where $d^{k}[v ]$ is the length of the shortest path from source $s$ to node $v$ using at most $k$ edges, and $w(u, v )$ is the weight of edge $(u, v )$. (Above, we are assuming $w(v, v ) = 0$).

This idea of using the intermediate solutions is similar to the divide-and-conquer paradigm. However, a divide-and-conquer algorithm recursively computes intermediate solutions once for each subproblem, but a dynamic programming algorithm solves the subproblems exactly once and uses these results multiple times.

\section{Dynamic Programming}

The idea of dynamic programming is to have a table of solutions of subproblems and fill it out in a particular order (e.g. left to right and top to bottom) so that the contents of any particular table cell only depends on the contents of cells before it. For example, in the Bellman-Ford algorithm, we filled out $d^{(k-1)}$ before we filled out $d^{(k)}$ ; and in order to fill out $d^{(k)}$ , we just had to look back at $d^{(k-1)}$, rather than compute anything new.

In this lecture, we will discuss dynamic programming more.

\subsection{Dynamic Programming Algorithm Recipe}
Here, we give a general recipe for solving problems (usually optimization problems) by dynamic programming. Dynamic programming is a good candidate paradigm to use for problems with the following properties:

\begin{itemize}
  \item Optimal substructure gives a recursive formulation; and
  \item Overlapping subproblems give a small table, that is, we can store the precomputed
answers such that it doesn't actually take too long when evaluating a recursive function multiple times.
\end{itemize}

What exactly do these things mean? We'll discuss them a bit more below, with the BellmanFord algorithm in mind as a reference.

\subsubsection{Optimal Substructure}

By this property, we mean that the optimal solution to the problem is composed of optimal solutions to smaller independent subproblems. For example, the shortest path from $s$ to $t$ consists of a shortest path $P$ from $s$ to $k$ (for node $k$ on $P$) and a shortest path from $k$ to $t$. This allows us to write down an expression for the distance between $s$ and $t$ with respect to the lengths of sub-paths:
$$
d(s, t) = d(s, k) + d(k, t), \text{for all } k \text{ on a shortest } s - t \text{ path}
$$

We used this in the Bellman-Ford algorithm when we wrote
$$
d^{(k)} [u] = \min_{v\in V} \{d^{(k-1)}[v ] + w(u, v )\}
$$

\subsubsection{Overlapping subproblems}

The goal of dynamic programming is to construct a table of entries, where early entries in the table can be used to compute later entries. Ideally, the optimal solutions of subproblems can be reused multiple times to compute the optimal solutions of larger problems.

For our shortest paths example, $d(s, k)$ can used to compute $d(s, t)$ for any $t$ where the shortest $s - t$ path contains $k$. To save time, we can compute $d(s, k)$ once and just look it up each time, instead of recomputing it.

More concretely in the Bellman-Ford example, suppose that $(v, u)$ and $(v, u' )$ are both in $E$. When we go to compute $d^{(k)}[u]$, we'll need $d^{(k-1)}[v ]$. Then when we go to compute $d^{(k)}[u ' ]$, we'll need $d^{k-1}[v ]$ again. If we just set this up as a divide-and-conquer algorithm, this would be extremely wasteful, and we'd be re-doing lots of work. By storing this value in a table and looking it up when we need it, we are taking advantage of the fact that these subproblems overlap.

\subsubsection{Implementations}

The above two properties lead to two different ways to implement dynamic programming algorithms. In each, we will store a table $T$ with optimal solutions to subproblems; the two variants differ in how we decide to fill up the table:

\begin{enumerate}
  \item Bottom-up: Here, we will fill in the table starting with the smallest subproblems. Then, assuming that we have computed the optimal solution to small subproblems, we can compute the answers for larger subproblems using our recursive optimal substructure.
  \item Top-down: In this approach, we will compute the optimal solution to the entire problem recursively. At each recursive call, we will end up looking up the answer or filling in the table if the entry has not been computed yet.
\end{enumerate}
In fact, these two methods are completely equivalent. Any dynamic programming algorithm can be formulated as an iterative table-filling algorithm or a recursive algorithm with look-ups.

\section{Why is it called dynamic programming?}

The name doesn't immediately make a lot of sense. ``Dynamic programming'' sounds like the type of coding that action heroes do in late-90's hacker movies. However, ``progamming'' here refers to a program, like a plan (for example, the path you are trying to optimize), not to programming a computer. ``Dynamic'' refers to the fact that we update the table over time: this is a dynamic process. But the fact that it makes you (or at least me) think about action movies isn't an accident. As Richard Bellman, who coined the term, writes in his autobiography:

\begin{quote}

An interesting question is, ``Where did the name, dynamic programming, come from?'' The 1950s were not good years for mathematical research. We had a very interesting gentleman in Washington named Wilson. He was Secretary of Defense, and he actually had a pathological fear and hatred of the word, research. Im not using the term lightly; Im using it precisely. His face would suffuse, he would turn red, and he would get violent if people used the term, research, in his presence. You can imagine how he felt, then, about the term, mathematical. The RAND Corporation was employed by the Air Force, and the Air Force had Wilson as its boss, essentially. Hence, I felt I had to do something to shield Wilson and the Air Force from the fact that I was really doing mathematics inside the RAND Corporation. What title, what name, could I choose? In the first place, I was interested in planning, in decision-making, in thinking. But planning, is not a good word for various reasons. I decided therefore to use the word, ``programming``. I wanted to get across the idea that this was dynamic, this was multistage, this was time-varying- I thought, let’s kill two birds with one stone. Let’s take a word which has an absolutely precise meaning, namely dynamic, in the classical physical sense. It also has a very interesting property as an adjective, and that is it’s impossible to use the word, dynamic, in the pejorative sense. Try thinking of some combination which will possibly give it a pejorative meaning. It’s impossible. Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it as an umbrella for my activities.
\end{quote}

\end{document}


\documentclass[12pt, letterpaper]{report}
\usepackage[margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{float}
\usepackage{subfig}
\graphicspath{ {./img/} }
\setlength\parindent{0pt}
\renewcommand\thesection{\Roman{section}.}
\renewcommand{\thesubsection}{\alph{subsection}.}

\title{CS1675 - Assignment 4}
\author{Zachary M. Mattis}

\begin{document}

\maketitle

\section{Problem 1 - Data Analysis}

% A
\subsection{Binary Attributes}

There is only 1 binary attribute, \#4 CHAS. It is a Charles River dummy variable indicating if the housing tract bounds the river.

% B
\subsection{Correlations}

The attribute that demonstrated the highest positive correlation was \#6, RN, with a value of 0.6954. The attribute that demonstrated the highest negative correlation was \#13, LSAT, with a value of -0.7377.

\begin{table}[H]
	\centering
	\begin{tabular}{ |l|r| }
		\hline
		Attribute & Correlation \\
		\hline
		CRIM & -0.3883 \\
		\hline
		ZN & 0.3604 \\
		\hline
		INDUS & -0.4837 \\
		\hline
		CHAS & 0.1753 \\
		\hline
		NOX & -0.4273 \\
		\hline
		RM & 0.6954 \\
		\hline
		AGE & -0.3770 \\
		\hline
		DIS & 0.2499 \\
		\hline
		RAD & -0.3816 \\
		\hline
		TAX & -0.4685 \\
		\hline
		PTRATIO & -0.5078 \\
		\hline
		B & 0.3335 \\
		\hline
		LSTAT & -0.7377 \\
		\hline
	\end{tabular}
	\caption{Correlations}
\end{table}

% C
\subsection{Linear / Non-Linear}

The most correlated non-linear graph appears to be attribute 13, LSTAT. The data points are very closely packed, while the shape is not necessarily linear. The shape appears to be a quadratic function. It also has the highest negative correlation coefficient.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\columnwidth]{p1c13.png}
	\caption{Non-Linear}
\end{figure}

The most correlated linear graph appears to be attribute 6, RM.  In this case, there are a few outliers, but many points are located very close to a line of best fit. It also has the highest positive correlation coefficient.

\begin{figure}[H]
\centering
\includegraphics[width=0.7\columnwidth]{p1c6.png}
\caption{Linear}
\end{figure}

% D
\subsection{Mutual Correlation}

Attribute \#9, RAD, and attribute \#10, TAX, have the highest mutual correlation with a coefficient of 0.910228.

\section{Problem 2 - Linear Regression}

% A
\subsection{Solve}

\begin{verbatim}
function [ w ] = LR_solve( X, y )
    w = X\y;
end
\end{verbatim}

% B
\subsection{Predict}

\begin{verbatim}
function [ y ] = LR_predict( X, w )
    y = X*w;
end
\end{verbatim}

% C
\subsection{Training / Testing Data}

\[ MSE = \frac{1}{N} \sum (f_i -y_i)^2 \]

% D
\subsection{Weight / Mean Squared Error}

\begin{table}[H]
	\centering
	\begin{tabular}{ |l|r| }
		\hline
		Attribute & Weight \\
		\hline
		CRIM & -0.0979 \\
		\hline
		ZN & 0.0490 \\
		\hline
		INDUS & -0.0254 \\
		\hline
		CHAS & 3.4509 \\
		\hline
		NOX & -0.3555 \\
		\hline
		RM & 5.8165 \\
		\hline
		AGE & -0.0033 \\
		\hline
		DIS & -1.0205 \\
		\hline
		RAD & 0.2266 \\
		\hline
		TAX & -0.0122 \\
		\hline
		PTRATIO & -0.3880 \\
		\hline
		B & 0.0170 \\
		\hline
		LSTAT & -0.4850 \\
		\hline
	\end{tabular}
	\caption{LR Weights}
\end{table}

The mean squared error of the training data was 24.4759, while the MSE of the testing data was 24.2922. Because the MSE of the testing data was lower, this appears to be the better set, although they are both very close.

\section{Problem 3 - Online Gradient Descent}

% A
\subsection{Regression Coefficients}

\begin{verbatim}
online_gradient_descent.m
\end{verbatim}

% B
\subsection{Gradient Procedure}

The mean squared error of the training data was 34.2648, while the MSE of the testing data was 68.2374. In this particular case, the end result was worse than be solving the problem exactly.

\begin{table}[H]
	\centering
	\begin{tabular}{ |l|r| }
		\hline
		Attribute & Weight \\
		\hline
		CRIM & 0.2343 \\
		\hline
		ZN & 2.0068 \\
		\hline
		INDUS & 0.4363 \\
		\hline
		CHAS & -0.3487 \\
		\hline
		NOX & 8.5354 \\
		\hline
		RM & 1.358 \\
		\hline
		AGE & -5.4657 \\
		\hline
		DIS & 1.0777 \\
		\hline
		RAD & -4.7237 \\
		\hline
		TAX & 0.4721 \\
		\hline
		PTRATIO & 2.4667 \\
		\hline
		B & 2.6942 \\
		\hline
		LSTAT & -0.3014 \\
		\hline
	\end{tabular}
	\caption{OGD Weights}
\end{table}

% C
\subsection{No Normalization}

With un-normalized data, the weights approached infinity instantly.  Therefore, the weights and errors were not valid.

% D
\subsection{Data Observation}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\columnwidth]{p3d.png}
	\caption{MSE}
\end{figure}

% E
\subsection{Trials}

\begin{table}[H]
	\centering
	\begin{tabular}{ |l|r|r|r|r|r|r|r|r| }
		\hline
		Steps & 1000 & 1000 & 1000 & 1000 & 1000 & 1000 & 10000 & 100000 \\
		\hline
		Learning Rate & 0.01 & 0.05 & $1/\sqrt{t}$ & $2/t^{2}$ & $2/t^{3}$ & 2/t & 2/t & 2/t \\
		\hline
		MSE Train & 0.2895 & 0.9875 & 3.66E+55 & 0.8247 & 0.5577 & 34.2648 & 5.3167 & 1.5551 \\
		\hline
		MSE Test & 0.1909 & 0.8354 & 4.27E+55 & 0.9502 & 0.5534 & 68.2374 & 8.4973 & 2.1502 \\
		\hline
		CRIM & -0.0639 & 0.4199 & -6.4E+27 & -0.1014 & -0.0684 & 0.2343 & 0.3515 & 0.1312 \\
		\hline
		ZN & 0.0383 & -0.1958 & 9.07E+26 & -0.1454 & -0.0823 & 2.0068 & 0.2848 & 0.0628 \\
		\hline
		INDUS & 0.0038 & 0.2318 & -5.8E+25 & 0.2605 & 0.0154 & 0.4363 & -0.6689 & -0.6397 \\
		\hline
		NOX & 0.2284 & 0.2222 & 1.34E+27 & 1.0100 & 0.5398 & 1.3580 & 1.1946 & 0.7857 \\
		\hline
		RM & -0.0005 & 0.2016 & -1.4E+27 & 0.1962 & -0.1313 & -5.4657 & -0.1862 & -0.7714\\
		\hline
		AGE & -0.1767 & -0.2337 & 6.56E+26 & -0.1858 & 0.0170 & 1.0777 & 0.5802 & 0.2096 \\
		\hline
		DIS & 0.1175 & 0.0543 & 1.58E+27 & -0.3084 & -0.1616 & -4.7237 & -2.6102 & -1.6003 \\
		\hline
		TAX & -00507 & -0.2419 & 4.12E+26 & -0.2002 & -0.1405 & 0.4721 & 0.9293 & 0.9607 \\
		\hline
		PTRATIO & -0.1213 & -0.0677 & -1.4E+26 & -0.2226 & -0.1121 & 2.4667 & 1.3450 & 0.5477 \\
		\hline
		B & 0.0385 & 0.0768 & -5.9E+25 & 0.0840 & 0.0449 & 2.6942 & 0.5061 & 0.2595 \\
		\hline
		LSTAT & -0.4389 & -0.3127 & 7.67E+26 & -0.2942 & -0.3686 & -0.3014 & -0.2189 & -0.2919 \\
		\hline
	\end{tabular}
	\caption{Trial Analysis}
\end{table}

Keeping the steps constant while changing the learning rate affects error the most.  The smaller the learning rate, the lower the error becomes.  It is likely that there is a threshold where a lower rate will have worse error (since the regression never approaches the optimum) if the number of steps are not enough.  If the learning rate is stalled, then the change becomes less noticeable as the function becomes “smaller and smaller” (such as $2/t^{2} => 2/t^{3}$).  Now, if the learning function remains the same while the steps increase, the errors go down with diminishing returns.

\end{document}


\documentclass[12pt]{article}
\input{physics1}
\begin{document}

\section*{NYU Physics I---dimensional analysis of orbits}

Here we exercise dimensional analysis to derive some properties of
gravitational orbits, including one of Kepler's laws.
For context, the Earth ($m= 6\times 10^{24}\,\kg$) orbits the Sun ($M= 2\times
10^{30}\,\kg$) at a distance of $R= 1.5\times 10^{11}\,\m$.

\paragraph{\theproblem}\refstepcounter{problem}%
What is the orbital period $T$ of the Earth in units of $\s$?

\paragraph{\theproblem}\refstepcounter{problem}%
What combination of $M$, $R$, and $T$ has dimensions of acceleration?
What has dimensions of force?  What has dimensions of momentum?

\paragraph{\theproblem}\refstepcounter{problem}%
The force on the Earth from the Sun that keeps it in orbit is
gravitational.  What is the magnitude of the gravitational force, in
terms of $G$, $m$, $M$, and $R$? What about acceleration?

\paragraph{\theproblem}\refstepcounter{problem}%
If you assume that the gravitational force provides the
dimensional-analysis force you derived above, how much longer would
the year be if the Earth's orbit were four times larger in radius than
it is?  The general answer is one of Kepler's laws!

\paragraph{\theproblem}\refstepcounter{problem}%
Now solve the problem and find speed $v$ in terms of $G$, $m$, $M$,
and $R$ for a circular orbit. Do the same for period $T$. By what
factor were your dimensional-analysis answers wrong?

\paragraph{\theproblem}\refstepcounter{problem}%
You got Kepler's law correct even though your dimensional-analysis result
was off by a constant factor.  Why?

\paragraph{\theproblem}\refstepcounter{problem}%
If the Earth were four times less massive than it is, but were still on
a circular orbit at its current radius, how much longer or shorter
would the year be?

\paragraph{\theproblem}\refstepcounter{problem}%
If the Sun were four times less massive than it is, but the Earth were
still on a circular orbit at its current radius, how much longer or
shorter would the year be?

\paragraph{\theproblem}\refstepcounter{problem}%
The Sun orbits the Milky Way on a close-to-circular orbit at a speed
of $2\times 10^5\,\mps$ and a distance of $R= 3\times 10^{20}\,\m$.
What is the orbital time of the Sun around the Milky Way?

\paragraph{\theproblem}\refstepcounter{problem}%
What, therefore, is the mass of the Milky Way, approximately, in units
of the mass of the Sun?

\end{document}


\documentclass[twocolumn]{article}

\title{The Dynamic Binary search tree}
\author{}

\begin{document}

\maketitle

\section{Introduction}

Binary trees are an important data organization in which searching for
an element is performed in $O(\log{n})$ steps. Dynamic trees were new
elements can be added and removed may become unbalanced and thus more
sophisticated binary tree implementations have been suggested to keep
the tree in $O(\log{n})$ limits.

Our goal is controlling the height of a tree to small values. A balanced
tree fulfills this goal but a tree need not necessarily be balanced to have
its height controlled.

The algorithm for an efficient implementation of dynamic tree is described,
along with comparisons with existing dynamic tree implementations.

\section{Description of the tree}

The basic idea is using a simple binary search tree and setting a limit on
it's height. Let us use for the rest of this study the number 32 as height
limit. This restricts the total number of nodes to no more than $2^{32}$ as
long as duplicate elements are not allowed.
We should notice that due to the logarithmic nature of complexity,
in real-life applications a balanced tree will never reach such values for
it's height.

Supposing we can efficiently fulfill this condition, locating an element in
the tree will be performed in no more than 32 steps. Typically
$O(32)<O(\log{n})$. Actually it may result in a few more steps.
In practice it is an unimportant
difference and therefore it is as fast as any balanced tree.

Removing an element from the tree can be easily done without the necessity
of a balancing operation as long as by removing an element the
height of the tree is not increased. This condition can be implemented.

If the node to be removed has two child nodes then the procedure is to find
the biggest element from the smaller ones or the smallest from the bigger
ones and replace the node to be removed with this element. A sample code is
illustrated in \ref{app:rmv}

Adding a new element to the tree is the most important operation. While
inserting the element the number of comparisons performed is counted. The
simple rule, when this number reaches 32 the tree must be rebalanced, is
very efficient.

Balancing the tree is accomplished in $n$ steps. However, the frequency at
which the tree needs to be balanced again is a function of $\frac{1}{2^n}$.
As a result adding a new element is in the great majority of the cases done
in less than 32 steps; but rebalancing is more rare as the number of nodes
increases
\footnote{A wosre-case behavior were a lot of elements have to be inserted
in an empty tree and they arrive sorted is solved in \ref{init}}.

\subsection{Balancing the tree}

The binary tree can be entirely reconstructed in $n$ steps using a simple
algorithm. First, an array of $n$ pointers is allocated an all the elements
of the tree are placed in this array in sorted order. Let us remember than an
always-balanced tree implementation requires extra memory for the node
structures and therefore the extra allocation of the array is yet efficient;
furthermore, in modern multithreaded database systems an operation which
alters part of the data is given full control of the hardware and the memory
usage burst will in this case be safely performed.

The next step is to reset the root of the tree and start inserting elements
in the order at which they will result in a perfectly balanced tree. This is
done by first inserting the middle element $N/2$ of the array, then
elements $N/4$ and $3 N / 4$, then $N/8$, $3 N / 8$, $5 N / 8 \ldots$
and so on.

By this procedure $2^k - 1$ where $k$ the integer for which
$2^k \leq N < 2^{k + 1}$ nodes can be inserted. For the remaining $N-(2^k -1)$
nodes, if any, various algorithms of $O(n)$ steps can be applied. One way
that is used in the sample code is to proceed normally as if there were
$2^{k+1}$ nodes and exclude the elements $i$ for which the modulo of the
division $i * 2^k / N$ is greater or equal to $N-(2^k -1)$ or zero; in other
words excluding those numbers $a$ for which there is a number $b$ so that
\begin{equation}
\left\lfloor \frac{a N}{2^{k+1}} \right\rfloor =
\left\lfloor \frac{b N}{2^k} \right\rfloor
\: , \;\; 0 < b < 2^k
\end{equation}

The complexity of the above algorithm will be linear if when inserting nodes
in the new tree redundant comparisons are avoided.

A sample implementation is provided at \ref{code:balance}.

\section{Characteristics of the tree}

The main feature of the this tree is that after is has been balanced, the
more nodes it contains, the more new elements be distributed in external
nodes and thus it will be much more unlikely to become ``unbalanced''.

\begin{itemize}
\item
   Memory requirements for this tree are minimal. The standard memory needed
   is as much as any simple binary tree and the same as a double linked
   list. Memory usage bursts occur when
   balancing is performed but this is generally a rare and very fast action.
   Memory due to recursion is not trivial since tree height is limited
   to 32.
\item
   Locating elements will happen in less than 32 steps. Generally after
   balancing has been performed locating elements is a matter of $\log{n}$.
\item
   Removing elements is also a matter of less than 32 steps.
   However, there are no rotations performed and therefore removing an
   element is possibly performed faster than in an always-balanced tree.
\item
   Adding elements in most of the cases is a matter of less than 32 very
   fast steps.
   Balancing is rare and becomes even more rare as the tree grows and it
   requires $n$ simple steps.

   In long term performance, for a growing tree the number of nodes $n$
   divided with the number of steps spent for balancing, tends to be
   independent of $n$.
\end{itemize}

Tests have shown that the tree will need to balance 2 times for
1,000,000 elements arriving in random order, once after 20,000 elements
and once again at about 400,000.

\section{Database initialization}
\label{init}

One case were the suggested tree would prove inefficient is inserting a lot
of elements in sorted order in an \emph{empty} tree.
If the tree is not empty and has been balanced before then the arriving
elements will be distributed on the external nodes.

This is a case which would occur when initially loading the data from
storage devices. The workaround to this problem is similar to the way the
tree is balanced. The -sorted- elements will have to be inserted in the tree
in the order that they will make a balanced tree, first the middle element,
$N/4$, $3*N/4$ and so on.

Once a perfectly balance tree is constructed there should be no worry for
this worse-case occurring unless most of the elements are removed.

Generally, in cases were a long sequence of elements is to be inserted
in the tree, if the tree has few nodes it may be preferable to sort the
sequence of elements and then insert the right elements first.
This procedure is worth the tradeoff if the arriving elements are almost
sorted, and in this case special sorting algorithms can be applied.

Another solution is to make the elements really random, by using a random
tree. In a \emph{random tree}, the comparison of elements is heads or tails.
After the sequence of elements has been inserted in a random tree (which
will never be unbalanced), they can be read in-order and sent to the dbs
tree.

\section{Conclusions}

The tree structure with the characteristics that have been presented is
efficient for specific database requirements.

When the database is idle or the specific tree is not used, is consumes the
least memory compared to other balanced tree structures.
That is the primary reason for the design of this structure.

When the tree is just accessed for locating an element this is as fast as
any balanced tree.

Theoretically, balanced tree implementations which perform rotations after
a node is inserted or removed from the tree are better. In practice, and
more specificly in a database environment limiting the height of the tree to
a `small' number is more than adequate.
Except from memory efficiency, the suggested tree structure may possibly
behave faster as well; the worse case scenario will either occur at the
initialization of the database or else is can be easilly prevented.

\onecolumn
\section{Sample code}

A sample implementation in C of the presented tree is provided.
For the sample code the simple definition of a node with a pointer to
data is used. The function {\tt compare ()} is the application-specific
function which compares the data of two nodes.

\begin{verbatim}
#define MAX_HEIGHT 32
typedef struct tnode node;
struct tnode {
   char *data;
   node *less, *more;
};
node *root;
\end{verbatim}

\subsection{Removing a node}
\label{app:rmv}

When removing an element which has two children,
both the smallest from the bigger elements and the
biggest from the smaller elements are located. By convention the deepest one
is selected to replace the node to be removed.

\begin{verbatim}
void remove (node *n)
{
    node *np, *nl, *nr, *nlp, *nrp;
    int isroot;

    if (!(isroot = (np = root) == n))
        for (;;)
            if (compare (np->data, n->data) > 0)
                if (np->less == n) break;
                else np = np->less;
            else
                if (np->more == n) break;
                else np = np->more;

    if (!(n->less && n->more))
    {
        if (isroot) root = (n->less) ? n->less : n->more;
        else
            if (np->less == n) np->less = (n->less) ? n->less : n->more;
            else np->more = (n->less) ? n->less : n->more;
        return;
    }
    for (i = 0, nlp = NULL, nl = n->less; nl->more; i++)
        nlp = nl, nl = nl->more;
    for (j = 0, nrp = NULL, nr = n->more; nr->less; j++)
        nrp = nr, nr = nr->less;
    if (i >= j)
    {
        if (isroot) root = nl;
        else
            if (np->less == n) np->less = nl;
            else               np->more = nl;
        if (nlp)
        {
             nlp->more = nl->less
             nl->less = n->less;
        }
        nl->more = n->more;
    } else {
        if (isroot) root = nr;
        else
            if (np->less == n) np->less = nr;
            else               np->more = nr;
        if (nrp)
        {
            nrp->less = nr->more
            nr->more = n->more;
        }
        nr->less = n->less;
    }
}
\end{verbatim}

\subsection{Balancing}
\label{code:balance}

The algorithm for reconstructing a balanced tree.
{\tt alloca} is a stack allocation mechanism.

Special care should be taken that the variables {\tt i, j, D, k} in
{\tt balance()} are 64 bit integers. If not then the algorithm will fail for
trees with more than about 65000 nodes.

\begin{verbatim}
unsigned int suint;
node **snpp;

void count_nodes (node *n)
{
    ++suint;
    if (n->less) count_nodes (n->less);
    if (n->more) count_nodes (n->more);
}
void tree_to_array (node *n)
{
    if (!n) return;
    tree_to_array (n->less);
    *snpp++ = n;
    tree_to_array (n->more);
}
void balance ()
{
    node **npp;
    long int i, j, D, k, k2, k3;

    /** Generate a sorted array **/
    suint = 0;
    count_nodes (root);
    npp = snpp = (node**) alloca (sizeof (node*) * suint);
    tree_to_array (root);
    /** Insert the top 2^k -1 nodes **/
    root = npp [suint / 2];
    for (i = 4; i <= suint + 1; i *= 2)
        for (j = 2; j < i; j += 4)
        {
            k2 = suint * j / i;
            npp [k2]->less = npp [suint * (j - 1) / i];
            npp [k2]->more = npp [suint * (j + 1) / i];
        }
    /** Test whether there are nodes left **/
    if ((k = suint + 1 - i / 2)) == 0)
    {
        for (i /= 2, j = 1; j < i; j += 2)
            k2 = suint * j / i,
            npp [k2]->less = npp [k2]->more = NULL;
        return;
    }
    /** Proceed normally but for specific nodes **/
    for (j = 2; j < i; j += 4)
    {
        k3 = suint * j / i;
        D = (k2 = suint * (j - 1) / i) * (i / 2) % suint;
        if (D >= k || D == 0)    /* k2 Excluded */
            npp [k3]->less = NULL;
        else {                   /* k2 Inserted */
            npp [k3]->less = npp [k2];
            npp [k2]->less = npp [k2]->more = NULL;
        }
        D = (k2 = suint * (j + 1) / i) * (i / 2) % suint;
        if (D >= k || D == 0)
            npp [k3]->more = NULL;
        else {
            npp [k3]->more = npp [k2];
            npp [k2]->less = npp [k2]->more = NULL;
        }
    }
    insert (npp [0]);
}
\end{verbatim}

\subsection{Inserting a node}

The procedure is similar to that of a simple binary search tree.

\begin{verbatim}
int insert (node *n)
{
    node *np;
    int h;

    n->less = n->more = NULL;
    if (!(np = root))
    {
        root = n;
        return 0;
    }
    for (h = 0;; h++)
        if (compare (np->data, n->data) > 0)
            if (!np->less) { np->less = n; break; }
            else np = np->less;
        else
            if (!np->more) { np->more = n; break; }
            else np = np->more;
     if (h == MAX_HEIGHT)
     {
         balance ();
         return 0;
     } else if (h > MAX_HEIGHT) {
         // If that ever happens please send me a mail and I'll send
         // you 10.000$ for having a tree with 4bill nodes
         // or make MAX_HEIGHT 34 and go to 16bills
         printf ("Tree full. Reached 2^%i nodes\n", MAX_HEIGHT);
         return -1;
     }
     return h;
}
\end{verbatim}

\end{document}


\section{Concatenation}

\frame{\tableofcontents[currentsection]}

\begin{frame}
    \frametitle{Problem Statement}
    \begin{center} \ttfamily
         [1,2,3,4,5] ++ [6,7,8,9,10,11,12,13]\\[4mm]
         $\downarrow$ \\[4mm]
         [1,2,3,4,5,6,7,8,9,10,11,12,13]
    \end{center}
\end{frame}

\begin{frame}
    \frametitle{Updating an Array}
    \begin{center}
        \begin{tikzpicture}
            \draw[thick] (0,0) grid[step=0.5cm] ++(3,0.5);
            \draw[thick,xshift=4cm] (0,0) grid[step=0.5cm] ++(4,0.5);
            \draw[thick,xshift=0.5cm] (0,-2) grid[step=0.5cm] ++(7,0.5);

            \foreach \i in {0,0.5,...,2.5} {
                \draw[-latex] (\i+0.25,0.25) -- (\i+0.75,-1.75);
            }

            \foreach \i in {0,0.5,...,3.5} {
                \draw[-latex] (\i+4.25,0.25) -- (\i+3.75,-1.75);
            }
        \end{tikzpicture}
    \end{center}
    \vskip4mm
    \structure{Algorithm}
    \begin{itemize}
        \item Requires both arries to be copied
        \item $O(n_1 + n_2)$
    \end{itemize}
\end{frame}

\begin{frame}
    \frametitle{Updating a Linked List}
    \begin{center}
        \begin{tikzpicture}[link/.style={thick,-latex}]
            \foreach[count=\i] \x in {0,...,4} {
                \coordinate (p\i) at (\x,0);
                \llnode[position=p\i,size=0.25cm]
            }

            \foreach[evaluate={\i+1} as \j] \i in {1,...,4} {
                \draw[-latex] ($ (p\i) + (0.375,0.125) $) -- ($ (p\j) + (0,0.125) $);
            }

            \foreach[count=\i] \x in {0,...,8} {
                \coordinate (q\i) at (\x,-0.5);
                \llnode[position=q\i,size=0.25cm]
            }

            \foreach[evaluate={\i+1} as \j] \i in {1,...,8} {
                \draw[-latex] ($ (q\i) + (0.375,0.125) $) -- ($ (q\j) + (0,0.125) $);
            }

            \foreach[count=\i] \x in {0,...,4} {
                \coordinate (r\i) at (\x,-2);
                \llnode[position=r\i,size=0.25cm]
            }

            \foreach[evaluate={\i+1} as \j] \i in {1,...,4} {
                \draw[-latex] ($ (r\i) + (0.375,0.125) $) -- ($ (r\j) + (0,0.125) $);
            }
            \draw[-latex] ($ (r5) + (0.375,0.125) $) -- ($ (q1) + (0.25,0) $);
        \end{tikzpicture}
    \end{center}
    \vskip4mm
    \structure{Algorithm}
    \begin{itemize}
        \item Only first list needs to be copied
        \item Second list can be safely reused
        \item Copy's last node points to second list's first node
        \item $O(n_1)$
    \end{itemize}
\end{frame}


\chapter{The full Halide simplifier reduction order}
\label{a:sreductionorder}

\begin{equation}
s >_{\mathcal{V}ar} t \textrm{ iff } \exists x . |s|_{x} > |t|_{x} \wedge \forall c \in \Sigma^0 . \lnot \exists \sigma . \sigma(x) = c
\end{equation}

The order $>_{\mathcal{V}ar}$ holds if there is one variable with strictly fewer occurrences in $s$ than in $t$, and if that variable cannot be a ground term.

\begin{equation}
s >_{vec} t \textrm{ iff } |s|_{vec} > |t|_{vec} \wedge \forall x \in \mathcal{V}ar . |s|_x \geq |t|_x
\end{equation}

The order $>_{vec}$ holds if there are strictly more vector operations in $s$ than in $t$.

\begin{equation}
s >_{\textrm{dmm}} t \textrm{ iff } |s|_{\textrm{dmm}} > |t|_{\textrm{dmm}} \wedge \forall x \in V, |s|_x \geq |t|_x
\end{equation}

The order $>_{\textrm{dmm}}$ holds if the total count of division, modulus, and multiplication operations is strictly greater in $s$ than in $t$.

\begin{equation}
s >_{\textrm{leaf}} t \textrm{ iff } |s|_{\textrm{leaf}} > |t|_{\textrm{leaf}} \wedge \forall x \in V, |s|_x \geq |t|_x
\end{equation}

We define the measure function $|s|_{\textrm{leaf}}$ as the number of leaves or terminals in the term $s$ represented as an abstract syntax tree. Thus $>_{\textrm{leaf}}$ holds if $s$ has more leaves than $t$.

\begin{equation}
s >_{\textrm{op}} t \textrm{ iff } \sum_{f \in \Sigma} |s|_f > \sum_{f \in \Sigma} |t|_f \wedge \forall x \in V, |s|_x \geq |t|_x
\end{equation}

The order $>_{\textrm{op}}$ holds if the count of all operations (all symbols in $\Sigma$ that are not zero-arity) in term $s$ is strictly greater that of $t$.

\begin{equation}
\begin{split}
s >_{0/1} t \textrm{ iff } & |s|_{leaf} - |s|_0 + |s|_1 > |t|_{leaf} - |t|_0 - |t|_1 \\
&  \wedge |s|_{leaf} = |t|_{leaf} \\
& \wedge \forall x \in \mathcal{V}ar(s_1) . |s_1|_x \geq |s_2|_x \\
& \wedge \forall x \in \mathcal{V}ar(s) . \lnot \exists \sigma . (\sigma(x) \neq 0 \wedge \sigma(x) \neq 1)
\end{split}
\end{equation}

The order $>_{0/1}$ holds if there are strictly more occurrences of the constants 0 and 1 in $t$ than in $s$ and if for all variables in $s$, there is no substitution such that $x$ can be substituted with the constants 0 or 1.

\begin{equation}
s >_{f} t \textrm{ iff } |s|_{f} > |t|_{f} \wedge \forall x \in \mathcal{V}ar . |s|_x \geq |t|_x
\end{equation}

This order represents a composition of orders over each operation in the Halide expression grammar. The operations are checked in this order:

\begin{enumerate}
  \item \texttt{ramp}
  \item \texttt{broadcast}
  \item \texttt{select}
  \item division
  \item multiply
  \item modulus
  \item subtraction
  \item addition
  \item \texttt{min}, \texttt{max}
  \item or
  \item and
  \item $\geq$
  \item $>$
  \item $\leq$
  \item $<$
  \item $\neq$
  \item $=$
  \item not
\end{enumerate}

\begin{equation}
s >_{lpo} t
\end{equation}
The order $>_{lpo}$ is a lexicographic path order induced by an order defined over the Halide operations. We further refine the Halide operations by distinguishing addition, multiplication, select, min, and max where both arguments must not be ground terms from their counterparts whose arguments may be a ground term. We also separate subtraction where the left operand is the constant 0 from substractions where the left operand cannot be the constant 0.

\begin{itemize}
  \item add by constant $<$
  \item multiply by constant $<$
  \item \{subtract from 0, select from constant \} $<$
  \item max with constant $<$
  \item \{min with constant, max, min, add, mul, subtract \} $<$
  \item all other operators
\end{itemize}

\begin{equation}
s >_{str} t \textrm{ iff } \phi_{str}(s) < \phi_{str}(t) \wedge \forall x \in V, |s|_x \geq |t|_x
\end{equation}

The order $>_{str}$ is checked by calculating the function $\phi_{str}$, which traverses the input term depth-first and replaces each constant with "b" and each variable with "a". The resulting strings are then compared lexicographically.

\begin{equation}
s >_{negc} t \textrm{ iff } |s|_{negc} > |t|_{negc}  \wedge \forall x \in V, |s|_x \geq |t|_x
\end{equation}

The order $>_{negc}$ holds when $s$ contains strictly more negative constants than $t$.

\begin{equation}
s >_{nmodc} t \textrm{ iff } |s|_{nmodc} > |t|_{nmodc}  \wedge \forall x \in V, |s|_x \geq |t|_x
\end{equation}

The order $>_{nmodc}$ holds when $s$ contains strictly more constants that are not within the range $0 \leq c < |c_m|$, for some constant $c_m$.

\begin{equation}
s >_{uniq} t \textrm{ iff } |s|_{uniq} > |t|_{uniq}  \wedge \forall x \in V, |s|_x \geq |t|_x
\end{equation}

The order $>_{uniq}$ holds when $s$ contains strictly more unique subtrees than $t$.

Finally, these two rules are well-ordered because they associate min and max to the left.

\begin{equation}
\tag{max106}
\texttt{max}(\texttt{max}(x,y), \texttt{max}(z,w)) \rightarrow_R \texttt{max}(\texttt{max}(\texttt{max}(x,y),z),w)
\end{equation}

\begin{equation}
\tag{min106}
\texttt{min}(\texttt{min}(x,y), \texttt{min}(z,w)) \rightarrow_R \texttt{min}(\texttt{min}(\texttt{min}(x,y),z),w)
\end{equation}


\chapter{Reconstruction of physical properties using machine learning}
\label{ch:ml}
Using the image parameters for each event, the particle type, origin and energy of the primary particle can be reconstructed.
In this work, supervised machine learning is used for the reconstruction.
The algorithms are trained on a set of Monte Carlo simulations which are preprocessed using two different versions of \texttt{lstchain}
and the results are compared in \autoref{ch:results}.
The set includes a simulation of diffuse gamma-rays, diffuse protons and a simulation of gamma-rays emitted by a point-like source.
The simulations were done using the programs \texttt{CORSIKA} and \texttt{sim\_telarray} \cite{simulations}.

In supervised machine learning, a generic estimator $f$ is trained on a dataset for which all information is known.
Training means that the parameters of $f$ are fitted in order to minimize a loss-function for certain target features.
This trained estimator, or model, can then be used to estimate the target features of datasets where this information is missing.

Two common types of problems that can be solved this way are binary classification and regression.
For binary classification problems, the estimator $f$ has to guess which of two classes any given sample is a part of.
This is used for background separation and during the origin reconstruction.
To solve a regression problem a countinuous quantity has to be estimated which is used for energy estimation and again during origin reconstruction.

It is important to validate the trained models before using them to estimate unknown features.
This is done by applying them to a different dataset than the dataset the model was trained on, but for which all information is known as well.
This allows for a comparison between the estimated values and the true values for the target features.
In this work, a $\num{5}$-fold cross validation is used which means that the training dataset is split into $\num{5}$ parts and training happens
with $\num{4}$ of those parts while the remaining part is used for validation.
The training is done on all possible combinations of the $\num{4}$ parts resulting in $\num{5}$ training sets.

\section{Decision Trees and Random Forests}
The basis for the random forest algorithm is the decision tree algorithm \cite{breiman1984classification} or more specifically binary trees.
A binary tree splits a dataset into two subsets at each step, called node.
For each split a threshold $t_j$ for a certain feature $j$ is chosen that minimizes the given loss-function.
This is repeated recursively until a stopping criterion is met like e.g. a total number of nodes (\enquote{depth} of the tree).
The final subsets are called leafs and for binary classification the partition between the two classes within each leaf is returned as a continuous score $p \in [0,\, 1]$.
For a regression task the average value of the regression target feature within each leaf is returned.
One common loss-function for binary classification is the cross-entropy
\begin{align}
    \text{Cross-entropy} = - q\, \log(q) - (1 - q) \log(1 - q)
\end{align}
with $q$ being the proportion of one of the two classes.
For the regression problem the mean squared error is often used as loss function which is evaluated for all $j$ features in every node \cite{hastie2009elements}.
\begin{align}
    \text{mse} = \sum_{X_{i,j} \in\, R_1} (y_i - c_1)^2\, + \sum_{X_{i,j} \in\, R_2} (y_i - c_2)^2,
\end{align}
Cross-entropy and the mean squared error are also used as loss functions in this work.

As decision trees have some weaknesses like an inherent instability, Leo Breimann introduced the random forest algorithm \cite{breiman2001random}.
This algorithm trains multiple decision trees on slightly different datasets which are created from the initial training dataset by sampling with replacement.
This process is called bagging \cite{breiman1996bagging}.
To add even more randomness to the training only a random subsample off all given features is considered in each node.
The results from these trees are then averaged.

\section{Quality Metrics}
\label{sec:quality_metrics}
To quantify the performance of a model there are a number of quality metrics for binary classification which are based on the confusion matrix.
\begin{align}
    \begin{pmatrix}
        tp & fp \\
        fn & tn
    \end{pmatrix}
\end{align}
$tp$ means true positive and $tn$ means true negatives.
These two values describe the proportion of correctly classified members of the two classes (positive and negative).
On the other hand, $fp$ (false positives) and $fn$ (false negatives) describe the amount of falsely classified members of the two classes respectively.
In this work, the accuracy of a binary classifier is used which measures the overall percentage of correctly reconstructed samples.
\begin{align}
    \text{accuracy} = \frac{tp\, +\, tn}{tp\, +\, tn\, +\, fp\, +\, fn}
\end{align}
Because a binary classifier returns a continuous score $p \in [0,\, 1]$ for each sample, in order to ultimately classify a sample,
a prediction threshold $t_p \in [0,\, 1]$ has to be chosen and if $p > t_p$, the sample is classified as positive.
However, it is also of interest to examine the classifier performance independent of this prediction threshold $t_p$.
A common metric for this is the area under the Receiver Operating Characteristic (ROC) curve.
In the ROC curve the $tp$ rate is plotted against the $fp$ rate for every possible threshold $t_p$.
A perfect classifier would achieve an area under the curve (AUC) of $\num{1.0}$ and random guessing is equivalent to an AUC of $\num{0.5}$.
For regression models the coefficient of determination or $r^2$-score is often used as quality metric.
\begin{align}
    r^2 = 1 - \frac{\sum_{i = 0}^N (y_i - \hat{y}_i)^2}{\sum_{i = 0}^N (y_i - \bar{y})^2}
\end{align}
$\hat{y}_i$ is the estimated value for the true value $y_i$ and $\bar{y}$ is the arithmetic mean of all $y_i$.
A perfect regressor would always achieve $y_i - \hat{y}_i = 0$ which would result in an $r^2$-score of $\num{1}$.
A $r^2$-score of $\num{0}$ means that the regressor always estimates $\bar{y}$ and a negative $r^2$-score thus means the regressor is doing even worse.

\section{The aict-tools}
For the training and appliction of such models in the context of data analysis for IACTs, the command line tools from the \texttt{aict-tools} package is used \cite{aict-tools}.
For the implementation of the machine learning algorithms, the \texttt{aict-tools} use the \texttt{scikit-learn} module \cite{scikit-learn}.
The configuration of models is done using a single \text{yaml}-file and the configuration used in this work can be found in \autoref{sec:config}.

Initially the \texttt{aict-tools} were developed for the FACT-experiment, which uses a different coordinate system and data-structure than CTA.
Therefore, at the start of this work, some conversion of the LST-1 data had to be done before the \texttt{aict-tools} could be applied
(\texttt{aict-tools} version \texttt{v0.21.0}).
Due to the continued development of the \texttt{aict-tools}, different coordinate systems are now supported and the necessary conversions became largely obsolete.
By the time of writing, merely the data-structure of the LST-1 data has to be adjusted before the \texttt{aict-tools} can be applied
(\texttt{aict-tools} version \texttt{v0.25.0} \cite{aict-tools}).

Another utility provided by the \texttt{aict-tools} is the generation of additional custom image features based on existing ones.
This is utilized in this work and the features that are generated can be seen in \autoref{sec:config}.
The calculation of the quality metrics presented in \autoref{sec:quality_metrics} is also done using their implementation in the \texttt{aict-tools}.

\section{The disp method}
The estimation of the origin within the detector plane is a two dimensional regression task ($x$ and $y$).
The \texttt{aict-tools} use the disp method instead which simplifies this task into a one dimensional regression task and a binary classification \cite{max}.

This is done by assuming the main shower axis is correctly reconstructed so that the origin of the primary particle lies somewhere along this line.
Based on this, the regression task aims to determine the absolute distance of the origin from the center of gravity of the shower image called \texttt{|disp|}.
As the regression results in two possible origin positions along the main shower axis, the objective of the binary classification is to decide which
of those two is the correct origin position.
This is called \texttt{sign} of disp.


    \filetitle{bpass}{Band-pass filter}{tseries/bpass}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
[X,T] = bpass(X,Band,Range,...)
\end{verbatim}

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

\begin{itemize}
\item
  \texttt{X} {[} tseries {]} - Band-pass filtered tseries object.
\item
  \texttt{T} {[} tseries {]} - Estimated trend tseries object.
\end{itemize}

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

\begin{itemize}
\item
  \texttt{X} {[} tseries {]} - Input tseries object that will be
  filtered.
\item
  \texttt{Range} {[} numeric \textbar{} Inf {]} Date range on which the
  data will be filtered.
\item
  \texttt{Band} {[} numeric {]} - Band of periodicities to be retained
  in the output data, \texttt{Band = {[}LOW,HIGH{]}}.
\end{itemize}

\paragraph{Options}\label{options}

\begin{itemize}
\item
  \texttt{'addTrend='} {[} \emph{\texttt{true}} \textbar{}
  \texttt{false} {]} - Add the estimated linear time trend back to
  filtered output series if \texttt{band} includes Inf.
\item
  \texttt{'detrend='} {[} \emph{\texttt{true}} \textbar{} \texttt{false}
  {]} - Remove an estimated time trend from the data before filtering.
\item
  \texttt{'log='} {[} \texttt{true} \textbar{} \emph{\texttt{false}} {]}
  - Logarithmise the data before filtering, de-logarithmise afterwards.
\item
  \texttt{'method='} {[} \emph{\texttt{'cf'}} \textbar{}
  \texttt{'hwfsf'} {]} - Type of band-pass filter:
  Christiano-Fitzgerald, or h-windowed frequency-selective filter.
\item
  \texttt{'unitRoot='} {[} \emph{\texttt{true}} \textbar{}
  \texttt{false} {]} - Assume unit root in the input data.
\end{itemize}

See help on \href{tseries/trend}{\texttt{tseries/trend}} for other
options available when \texttt{'detrend='} is set to true.

\paragraph{Description}\label{description}

Christiano, L.J. and T.J.Fitzgerald (2003). The Band Pass Filter.
International Economic Review, 44(2), 435--465.

Iacobucci, A. \& A. Noullez (2005). A Frequency Selective Filter for
Short-Length Time Series. Computational Economics, 25, 75--102.

\paragraph{Example}\label{example}