%!TEX root = ../main.tex

%===============================================================================
%
%    Chapter: vectors
%
%===============================================================================

\chapter{Vectors}
\label{chapter:vectors}

In this chapter we'll learn how to manipulate multi-dimensional objects called vectors.						\index{vector|textbf}
Vectors are the precise way to describe directions in space.
We need vectors in order to describe physical quantities like forces, velocities, and accelerations.

Vectors are built from ordinary numbers,
which form the \emph{components} of the vector.
You can think of a vector as a list of numbers,
and \emph{vector algebra} as operations
performed on the numbers in the list.
Vectors can also be manipulated as geometric objects,
represented by arrows in space.
For instance, the arrow that corresponds to the vector $\vec{v}=(v_x,v_y)$ starts at the origin $(0,0)$
and ends at the point $(v_x,v_y)$.
The word vector comes from the Latin \emph{vehere},
which means \emph{to carry}.
Indeed, the vector $\vec{v}$ takes the point $(0,0)$ and carries it to the point $(v_x,v_y)$.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.4\textwidth]{figures/vectors/vector_components.pdf}
	\vspace{-2mm}
	\caption{	The vector $\vec{v}=(3,2)$ is an arrow in the Cartesian plane.
			The horizontal component of $\vec{v}$ is $v_x=3$
			and the vertical component  is $v_y=2$.}
	\label{fig:vector_components}
\end{figure}

%!TEX root = ../main.tex

%=======================================================================  vectors
\section{Vectors}
\label{sec:vectors}

	Vectors are extremely useful in all areas of life.
	In physics, for example, we use a vector to describe the velocity of an object.
	It is not sufficient to say that the speed of a tennis ball is 200 kilometres per hour:
	we must also specify the direction in which the ball is moving.
	Both of the two velocities
	\[
	 \vec{v}_1 = (200,0)
	 \qquad \textrm{and}
	 \qquad \vec{v}_2=(0,200)
	\]
	describe motion at the speed of $200$ kilometres per hour;
	but since one velocity points along the $x$-axis, and the other points along the $y$-axis,
	they are \emph{completely} different velocities.
	The velocity vector contains information about the object's speed \emph{and} its direction.
	The direction makes a big difference.
	If it turns out the tennis ball is hurtling toward you, you'd better get out of the way!

	The main idea in this chapter is that \textbf{vectors are not the same as numbers}.
	We'll start by defining what vectors are.
	Then we'll describe all the mathematical operations we can perform with vectors,
	which include
		vector addition $\vec{u}+\vec{v}$,
		vector subtraction $\vec{u}-\vec{v}$,
		vector scaling $\alpha\vec{v}$,
		and other operations.

	\subsection{Definitions}
	\label{vectors:definitions}

		A two-dimensional vector $\vec{v}$ corresponds to a \emph{pair of numbers}:
		\[
			\vec{v} = (v_x, v_y),
		\]
		where $v_x$ is the \emph{$x$-component} of the vector and $v_y$ is its \emph{$y$-component}.					\index{components}
		We denote the set of two-dimensional vectors as $\mathbb{R}^2$,
		since the components of a two-dimensional vector are specified by two real numbers.
		We'll use the mathematical shorthand $\vec{v} \in \mathbb{R}^2$ to define a two-dimensional vector $\vec{v}$.
		Vectors in $\mathbb{R}^2$ can be represented as arrows in the Cartesian plane.
		See the vector $\vec{v}=(3,2)$ illustrated in Figure~\ref{fig:vector_components}.

		We can also define three-dimensional vectors like the vector $\vec{v} = (v_x, v_y, v_z) \in \mathbb{R}^3$,
		which has three components.
		A three-dimensional coordinate system is similar to the Cartesian coordinate system you're familiar with,
		and includes the additional $z$-axis that measures the height above the plane.
		In fact,
		there's no limit to the number of dimensions for vectors.
		We can define vectors in an $n$-dimensional space:								\index{dimension}
		$\vec{v} = (v_1, v_2, \ldots, v_n) \in \mathbb{R}^n$.
		For the sake of simplicity,
		we'll define all the vector operation formulas using two-dimensional vectors.
		Unless otherwise indicated in the text,
		all the formulas we give for two-dimensional vectors $\vec{v} \in \mathbb{R}^2$
		also apply to $n$-dimensional vectors $\vec{v} \in \mathbb{R}^n$.

		\subsubsection{Vector operations}

			Consider two vectors,
			$\vec{u}=(u_x,u_y) $ and $\vec{v}=(v_x,v_y)$,
			and assume that $\alpha \in \mathbb{R}$ is an arbitrary constant.
			The following operations are defined for these vectors:
			\begin{itemize}
				\item 	\textbf{Addition:}	$\vec{u} + \vec{v} = (u_x+v_x,\, u_y+v_y)$
				\item 	\textbf{Subtraction:}	$\vec{u} - \vec{v} = (u_x-v_x,\, u_y-v_y)$
				\item 	\textbf{Scaling:}		$\alpha \vec{u} = (\alpha u_x,\, \alpha u_y)$
				\item 	\textbf{Dot product:}	$\vec{u} \cdot \vec{v}  = u_xv_x+u_yv_y$								\index{dot product}
				\item 	\textbf{Length:}		$\|\vec{u}\| = \sqrt{\vec{u}\cdot\vec{u}} = \sqrt{u_x^2+u_y^2}$.
						The vector's length is also called the \emph{norm} of the vector.
						We sometimes use the letter $u$ to denote the length of the vector $\vec{u}$.
			\end{itemize}

			\noindent
			Note there is no vector division operation.

			For vectors in a three-dimensional space $\vec{u}=(u_x,u_y,u_z) \in \mathbb{R}^3$
			and $\vec{v}=(v_x,v_y,v_z) \in \mathbb{R}^3$,
			we can also define the \textbf{cross product} operation												\index{cross product}
			$\vec{u} \times \vec{v} = (u_yv_z-u_zv_y,\; u_zv_x-u_xv_z,\; u_xv_y-u_yv_x)$.
			The dot product and the cross product are new operations that you probably haven't seen before.

		\subsubsection{Vector representations}

			We'll use three equivalent ways to denote vectors in two dimensions:
			\begin{itemize}
			    \item   	$\vec{v} =(v_x, v_y)$: component notation.
					The vector is written as a pair of numbers called the \emph{components} or \emph{coordinates} of the vector.	\index{coordinates}
			    \item 	$\vec{v} =v_x\hat{\imath}+ v_y\hat{\jmath}$: unit vector notation.
					The vector is expressed as a combination of the unit vectors
					$\hat{\imath} = (1,0)$ and $ \hat{\jmath} = (0,1)$.
			    \item   	$\vec{v}=\|\vec{v}\|\angle \theta$: length-and-direction notation (polar coordinates).
					The vector is expressed in terms of its \emph{length} $\|\vec{v}\|$
					and the angle $\theta$ that the vector makes with the $x$-axis.
			\end{itemize}

			\begin{figure}[htb]
				\centering
				\includegraphics[width=0.6\textwidth]{figures/vectors/vector_components_annotated.pdf}
				\vspace{-2mm}
				\caption{The vector $\vec{v}=(v_x,v_y) = v_x\hat{\imath}+ v_y\hat{\jmath} = \|\vec{v}\|\angle \theta$.}
				\label{fig:vector_components_annotated}
			\end{figure}

			\noindent
			We use the component notation for doing vector algebra calculations since it is most compact.
			The unit vector notation shows explicitly that the vector $\vec{v}$ corresponds to the sum of
			$v_x\hat{\imath}$ (a displacement of $v_x$ steps in the direction of the $x$-axis)
			and $v_y\hat{\jmath}$ (a displacement of $v_y$ steps in the direction of the $y$-axis).
			The length-and-direction notation describes the vector $\vec{v}$
			as a displacement of $\|\vec{v}\|$ steps in the direction of the angle $\theta$.
			We'll use all three ways of denoting vectors throughout the rest of the book,
			and we'll learn how to convert between them.

	\subsection{Exercises}
	\label{basis:exercises}

		\input{problems/chapter3_exercises_vectors.tex}

%!TEX root = ../main.tex

\section{Vectors problems}
\label{sec:vec_problems}

\vspace{-2mm}

You learned a bunch of vector formulas and you saw some vector diagrams,
but did you really learn how to solve problems with vectors?
There is only one way to find out: test yourself by solving problems.

I've said it before and I don't want to repeat myself too much,
but it's worth saying again: the more problems you solve, the better you'll understand the material.
It's now time for you to try the following vector problems to make sure you're on top of things.

\medskip

{ \small

\begin{problems}{ch3}

	\begin{problem}
		Given the vectors $\vec{u}=(1,1,1)$, $\vec{v} = (2,3,1)$, and $\vec{w}=(-1,-1,2)$,
		compute the following products:

		\threecol
			\textbf{a)}~$\vec{u} \cdot \vec{v}$

			\textbf{b)}~$\vec{u} \cdot \vec{w}$

			\textbf{c)}~$\vec{v} \cdot \vec{w}$
		\endthreecol

		\threecol
			\textbf{d)}~$\vec{u} \times \vec{v}$

			\textbf{e)}~$\vec{u} \times \vec{w}$

			\textbf{f)}~$\vec{v} \times \vec{w}$
		\endthreecol

		\begin{answer}\textbf{a)}~$6$.
					\textbf{b)}~$0$.
					\textbf{c)}~$-3$.
					\textbf{d)}~$(-2, 1, 1)$.
					\textbf{e)}~$(3, -3, 0)$.
					\textbf{f)}~$(7, -5, 1)$.\end{answer}
	\end{problem}

	\begin{problem}
		Given the vectors $\vec{p} =(1,1,0,3,3)$ and $\vec{q}=(1,2,3,4,5)$, calculate the following expressions:
		\threecol
			\textbf{a)}~$\vec{p}+\vec{q}$

			\textbf{b)}~$\vec{p}-\vec{q}$

			\textbf{c)}~$\vec{p} \cdot \vec{q}$
		\endthreecol

		\begin{answer}\textbf{a)}~$(2,3,3,7,8)$.
					\textbf{b)}~$(0,-1,-3,-1,-2)$.
					\textbf{c)}~$30$.\end{answer}
	\end{problem}

	\begin{problem}
		Find a unit vector that is perpendicular to both  $\vec{u}=(1, 0, 1)$ and $\vec{v} =(1, 2, 0)$.
		\begin{hint}
			Use the cross product.
		\end{hint}
		\begin{answer}$(-\frac{2}{3}, \frac{1}{3}, \frac{2}{3})$ or $(\frac{2}{3}, -\frac{1}{3}, -\frac{2}{3})$.\end{answer}
		\begin{solution}See \href{http://bit.ly/1cOa8yo}{\texttt{bit.ly/1cOa8yo}} for calculations.
		\end{solution}
	\end{problem}

	\begin{problem}
		Find a vector that is orthogonal to both $\vec{u}_1 = (1, 0, 1)$ and $\vec{u}_2 =(1, 3, 0)$,
		 and whose dot product with the vector  $\vec{v}= (1, 1, 0)$ is equal to $8$.
		%	\begin{hint}
		%	\end{hint}
		\begin{answer}$(12, -4, -12)$.\end{answer}
		\begin{solution}
			Any multiple of the vector $\vec{u}_1 \times \vec{u}_2 = (-3,1,3)$
			is perpendicular to both $\vec{u}_1$ and 	$\vec{u}_2$.
			We must find a multiplier $t \in \mathbb{R}$ such that
			$t(-3,1,3) \cdot (1, 1, 0) = 8$.
			Computing the dot product we find $-3t + t = 8$, so $t=-4$.
			The vector we're looking for is $(12, -4, -12)$.
			See \href{http://bit.ly/1nmYH8T}{\texttt{bit.ly/1nmYH8T}} for calculations.
		\end{solution}
	\end{problem}

\end{problems}

} % /small


%`
%\nonstopmode
\hbadness=100000
\documentclass[a4paper, 12pt]{article}
\usepackage{amsmath,amsfonts,caption,float,geometry,graphicx,mathtools,pythonhighlight,textcomp,url,verbatim,subcaption,tabularx, longtable, ulem, hyperref, tikz} %,parskip
\geometry{ a4paper, total={170mm,257mm}, left=20mm, top=20mm}
\newcommand{\matr}[1]{\underline{\underline{\textbf{#1}}}}
\newcommand{\ve}[1]{\boldsymbol{#1}}
\newcommand{\pythoncode}[2]{
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}
\begin{adjustwidth}{-1.3cm}{-1.3cm}
\texttt{#1}
\inputpython{#2}{1}{1500}
\end{adjustwidth}
}
\usepackage[toc, page]{appendix}
% \usepackage[dvipsnames]{xcolor}
% \definecolor{subr}{rgb}{0.8, 0.33, 0.0}
% \definecolor{func}{rgb}{0.76, 0.6, 0.42}

\begin{document}
% \includegraphics[width=8cm]{CoverPage/UoBlogo.pdf}
% \hrule
% \bigbreak
% \textbf{F}usion Neutron \textbf{Acti}vation Spectra \textbf{U}nfolding by \textbf{N}eural \textbf{N}etworks \\
% (FACTIUNN)                                      \\
% \hrule
% \bigbreak
% \begin{minipage}[b]{0.4\textwidth}
%     \includegraphics[height=2cm]{CoverPage/CCFElogo.jpeg}
%   \end{minipage}
%   \hfill
%   \begin{minipage}[b]{0.4\textwidth}
%     \includegraphics[height=3cm]{CoverPage/UKAEAlogo.jpeg}
% \end{minipage}

\begin{table}[!h]
\centering
\begin{tabular}{rl}
author:&Ocean Wong          \\
       &(Hoi Yeung Wong)    \\
date:  &May 2020       \\
Organization:&Culham Centre for Fusion Energy\\
            & Sheffield Hallam University\\
Reivewed by:&Bashir Mitchell\\
Motivated by:&Boredom of quarantine
\end{tabular}
\end{table}
\hrule
\begin{abstract}
This document explores the intuition for exponentiation of complex numbers
\end{abstract}
% \hline
% \twocolumn
\begin{center}
\chapter{}
\end{center}
\section{Introduction}
To most physics students and graduates, two of the three basic arithmetic operations of complex numbers $z \in \mathbb{C}$ has been made intuitive:
\begin{longtable}{ccc}
\hline
operation& representation & intuition\\
\hline
addition & $z_1+z_2$ & translation of the $z_1$ plane by the vector $z_2$\\
multiplication & $(z_1)(z_2)$ & dilation of the complex plane by a factor $|z_2|$\\ && and rotation by a factor $arg(|z_2|)$. \\
\hline
\end{longtable}

However, the third commonly used arithmetic operation, exponentiation ${z_1}^{z_2}$, is not made obvious/intuitive as part of their physics training.

This text aims to provide intuition for that.

\section{Set up and calculation}
In the previous two operations we have visualized $z_1$ as a member on the infinitely extending complex plane, while $z_2$ describes an operation on this plane\footnote{This asymmetric nature of $z_1$ and $z_2$ makes the communtativity of complex multiplication unintuitive. But that's a story for another time}. We will use the same approach in the following set up:

Let $z_1= e^{x} e^{iy}$. And for convenience, let's denote the $z_2 = a+ib$.

Then an operation $z_1^{z_2}$ will give

\begin{align}
z_3 = z_1^{z_2}  & = e^{ax} e^{iay} \cdot e^{ibx} e^{-by}\\
                & = e^{ax - by} e^{iay + bx} \\
                & = e^{(ax-by) +i (ay+bx)} \label{initial algebra}
\end{align}

\section{Trick}
The trick here is then to recognize the matrix-algebra nature of equation \ref{initial algebra}.

It the real part of the exponent looks like the dot product $ (a, -b) \cdot (x, y)$, while
the imaginary part of the exponent looks like the dot product $(b, a) \cdot (x, y)$.

Thus we can re-write the the real and imaginary part of the resulting $z_3$ into a 2D-vector, given by the transformation
\begin{equation}
\begin{pmatrix}
a & -b\\
b & a
\end{pmatrix}
\begin{pmatrix}
x\\
y
\end{pmatrix}\label{transformation equation}
\end{equation}

\section{Intuition}\label{Intuition}
Therefore the intuition of raising $z_1$ to the power of $z_2$ can be broken down into four steps
\begin{enumerate}
    \item Decompose $z_1$ into $x=ln(|z|), y=arg(z)$. This will turn the polar coordinates lines on the argand diagram \ref{polar} into a cartesian coordinate with $-\infty < x < \infty$,$ -\pi\le y\le \pi$ (figure \ref{cartesian}). The point ($-\infty$, $-\pi < y\ge\pi$) in figure \ref{cartesian} corresponds to the origin in figure \ref{polar}.
    \item Contruct a matrix:
    $\matr{M}=\begin{pmatrix}
    a & -b\\
    b & a
    \end{pmatrix}$ by decomposing $z_2$ into $z_2=a+ib$.
    \item Apply this matrix transformation $\matr{M}$ (equation \ref{transformation equation}) on figure \ref{cartesian}.
    \item Now exponentiate the transformed figure \ref{cartesian} (inverse transformation of what we've done in step 1).
\end{enumerate}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.4\textwidth]{polar.png}
    \captionof{figure}{Input complex plane with polar coordinate lines overlaid. Exponentiating figure \ref{cartesian} will return this figure.
    The origin in figure \ref{cartesian} corresponds to the point $(1,0)$ in this figure.
    }\label{polar}
\end{figure}
\begin{figure}[H]
    \centering
    \includegraphics[width=0.4\textwidth]{cartesian.png}
    \captionof{figure}{The output complex plane with cartesian coordinates overlaid. Each point on the cartesian coordinate lines corresponds to a point on the polar coordinate lines in figure \ref{polar}. This can be obtained by taking the logarithm of figure \ref{polar} to give $x=ln(|z|), y=arg(z)$.}\label{cartesian}
\end{figure}
The lines in the figures have corresponding colours: the deep purple line gets mapped to the deep purple line after transformation, etc.

\section{Correspondence to our expectation in special cases}
When $a=n, b=0$,
$\begin{pmatrix}
a & -b\\
b & a
\end{pmatrix}$ becomes a simple scaling matrix with no skewing component, agreeing with our expectation that ${z_1}^{n}$ simply multiplies itself by n times.

If both the real and imaginary parts are zero, then the transformation in step 3 will squash everything down to the origin; and step four will transform the origin back to the number $1+0i$, confirming our expectation that $z_1^0 = 1$.

\section{Example: $i^i$}
For the case of raising any complex number $z_1$ to the power of $i$,
\begin{align}
    z_2 &= 0 + 1i
\end{align}
Therefore, using the checklist laid out in section \ref{Intuition}:

\begin{enumerate}
    \item Step 1 is as described in section \ref{Intuition}. At this point $z_1 = i = (0,1)$ will be transformed to $ln(z_1) = 0+arg(i) i = (0, arg(i)) = (0, \frac{\pi}{2})$
    \item Step 2 will give us a rotation matrix
$\matr{M} = \begin{pmatrix}
0 & -1\\
1 & 0
\end{pmatrix}$ which is a rotation matrix that rotates everything anti-clockwise by $90 ^\circ$.
    \item Applying this on $z_1$ will give us a rotated figure \ref{cartesian}, rotated to the left by $90^\circ$. If we consider only the point $z_1 = i$, it will now be mapped from $(0, \frac{\pi}{2})$ (step 1) to the point $(-\frac{\pi}{2}, 0)$
    \item Exponentiating this result will give us the solution $z_3$. In this case we will exponentiate $-\frac{\pi}{2} + 0i$ into $e^{-\frac{\pi}{2}} \approx 0.20788$
\end{enumerate}

\section{Interesting results}
In fact when $z_2$ is purely imaginary, the unit circle of $z_1$ (whose exponent has real part=0) will be mapped to the real number line in the output $z_3$. This is because when $a=0$, the matrix transformation becomes a 90-degrees rotation plus a scaling operation, swapping the real and the imaginary part of the exponent.
\section{Multiple solutions}
Of course, the point $(x,y)$ and the point $(x, y + 2n\pi)$ on figure \ref{cartesian} both maps to the same point on figure \ref{polar}. But these two points may be transformed differently by step 3. Therefore one get multiple answers of $z_3$ depending on which represenation of $z_1$ they have chosen for themselves on figure \ref{cartesian} to represent $z_2$.

An example of this is that $i^i$ actually has mutliple solutions,
\begin{align}
    i^i = e^{-\frac{\pi}{2}} e^{2n\pi} = 0.20788 (e^{2n\pi})
    & & \forall n \in \mathbb{Z}
\end{align}
% \begin{figure}[H]
% \centering
% \includegraphics[width=1\textwidth]{path/to/file.png} %Stupid latex doesn't allow two dots in the filename.
% \caption{Short description} \label{somethingcatchy}
% \end{figure}

\end{document}
%`


\lab{Stochastic Differential Equations}{Stochastic Differential Equations}
\label{lab:sde}
\objective{Stochastic differential equations are used to model stochastic processes.
In this lab we will explore Brownian motion and then derive the Euler-Maruyama numerical method for SDEs.
We will build an Euler-Maruyama numerical solver and use this solver to predict future stock prices.}

Stochastic differential equations combine the concepts of Brownian motion and differential equations in order to model stochastic processes.
A stochastic process is a mathematical object made from a family of random variables.
These processes model events that occur with random changes over time, such as bacterial population growth, movement of gas molecules, and fluctuating stock prices.
To understand stochastic processes, it is imperative to understand Brownian motion.

\section*{Brownian Motion}

Brownian motion is random movement described by the Wiener process.
The Wiener process is a stochastic process $W(t)\sim\mathscr{N}(0,t)$ which satisfies the following conditions:

\begin{enumerate}
\item $W(0)=0$,\\
\item $W(t-s)=W(t) - W(s)$,\\
\item $W(t)$ is independent for all $t$.
\end{enumerate}

For example, imagine a point at zero on a number line.
The point can only move one number away and must move left or right.
The probability of moving left and right is equal and can be modeled by a coin flip.
Let's say that landing on heads moves the point right and tails moves the point left.
On our first flip, we get heads and the point moves from 0 to 1.
Now we flip the coin again.
This coin flip does not depend on the previous coin flip and determines whether the point moves back to 0 or moves to 2.
On the second flip, we get tails and the point moves back to 0.
Continuing this process shows the random movement of the point on the number line.

\begin{figure}
\captionsetup[subfigure]{justification=justified}
\begin{center}
\begin{subfigure}{\textwidth}
\centering
\begin{tikzpicture}
\draw(-2,0)--(-1,0)--(0,0)--(1,0)--(2,0);
\draw[fill] (-2,0) circle [radius=0.1];
\draw[fill] (-1,0) circle [radius=0.1];
\draw[fill, blue] (0,0) circle [radius=0.1];
\draw[fill] (1,0) circle [radius=0.1];
\draw[fill] (2,0) circle [radius=0.1];
\node at (-2,-.5) {-2};
\node at (-1,-.5) {-1};
\node at (0,-.5) {0};
\node at (1,.-.5) {1};
\node at (2,-.5) {2};
\end{tikzpicture}
\caption{Initial position}
\vspace{.3cm}
\end{subfigure}
\begin{subfigure}{\textwidth}
\centering
\begin{tikzpicture}
\draw(-2,0)--(-1,0)--(0,0)--(1,0)--(2,0);
\
\draw[fill] (-2,0) circle [radius=0.1];
\draw[fill] (-1,0) circle [radius=0.1];
\draw[fill] (0,0) circle [radius=0.1];
\draw[fill, blue] (1,0) circle [radius=0.1];
\draw[fill] (2,0) circle [radius=0.1];
\node at (-2,-.5) {-2};
\node at (-1,-.5) {-1};
\node at (0,-.5) {0};
\node at (1,.-.5) {1};
\node at (2,-.5) {2};
\end{tikzpicture}
\caption{Heads is flipped and point moves right.}
\vspace{.3cm}
\end{subfigure}
\begin{subfigure}{\textwidth}
\centering
\begin{tikzpicture}
\draw(-2,0)--(-1,0)--(0,0)--(1,0)--(2,0);
\draw[fill] (-2,0) circle [radius=0.1];
\draw[fill] (-1,0) circle [radius=0.1];
\draw[fill, blue] (0,0) circle [radius=0.1];
\draw[fill] (1,0) circle [radius=0.1];
\draw[fill] (2,0) circle [radius=0.1];
\node at (-2,-.5) {-2};
\node at (-1,-.5) {-1};
\node at (0,-.5) {0};
\node at (1,.-.5) {1};
\node at (2,-.5) {2};
\end{tikzpicture}
\caption{Tails is flipped and point moves left.}
\vspace{.3cm}
\end{subfigure}
\begin{subfigure}{\textwidth}
\centering
\begin{tikzpicture}
\draw(-2,0)--(-1,0)--(0,0)--(1,0)--(2,0);
\draw[fill] (-2,0) circle [radius=0.1];
\draw[fill, blue] (-1,0) circle [radius=0.1];
\draw[fill] (0,0) circle [radius=0.1];
\draw[fill] (1,0) circle [radius=0.1];
\draw[fill] (2,0) circle [radius=0.1];
\node at (-2,-.5) {-2};
\node at (-1,-.5) {-1};
\node at (0,-.5) {0};
\node at (1,.-.5) {1};
\node at (2,-.5) {2};
\end{tikzpicture}
\caption{Tails is flipped and point moves left.}
\vspace{.3cm}
\end{subfigure}
\caption{Example of Brownian motion. The blue dot travels left or right with equal probability. It is modeled by a coin flip. When heads, the dot moves right. When tails, the dot moves left.}
\end{center}
\end{figure}

As we flip the coin $t$ times, the distribution of the point's position is approximately normally distributed with mean 0 and variance $t$.
Note that $dW\sim\mathscr{N}(0,\Delta t)$ is also approximately normally distributed because $W(t-s)=W(t)-W(s)$ and $W(t-s)\sim\mathscr{N}(0,t-s)$.
Using $dW$, we can show the movement of a point with the differential equation
\begin{equation}
\frac{dS_t}{S_t}=g(t,S_t)dW.
\label{eqn:brownian-motion}
\end{equation}
where $g(t,S_t)$ is a scalar function and $S_t$ is the position of the point at time $t$.
We can manipulate Equation \ref{eqn:brownian-motion} to model the position of the point numerically:

\begin{align*}
dS_t&\approx g(t,S_t)S_tdW\\
S_{t+1}-S_t&\approx g(t,S_t)S_tdW\\
S_{t+1}&\approx S_t+g(t,S_t)S_tdW
\end{align*}
where $dW\sim\mathscr{N}(0,1)$.
This model is itself a stochastic differential equation that is based completely on brownian motion.

\begin{problem}
Write a function \li{brownian_motion()} that accepts a scalar function \li{g}, initial condition \li{y0}, and an array of time points \li{t}.
The function should return an array of the solution to Equation \ref{eqn:brownian-motion} evaluated at $t$.

Animate this function for $g(t,S_t)=1$, $y_0=(1,1)$ and $t\in[0,100)$.
The animation should show a particle moving with a tail indicating it's previous position.

(Hint: Because $y_0\in\mathbb{R}^2$, $dW\in\mathbb{R}^2\times\mathbb{R}^2$ so that each dimension of $y_0$ moves independently. Thus, $dW=\begin{pmatrix}d_{w_1}&0\\0&d_{w_2}\end{pmatrix}$ where $d_{w_i}\sim\mathscr{N}(0,1)$).
\label{prob:brownian-motion}
\end{problem}

\section*{Euler-Maruyama Method}

A stochastic differential equation (SDE) is a differential equation that involves at least one stochastic component.
Equation \ref{eqn:brownian-motion} is an example of a SDE, as its only component is stochastic.
However, most SDEs are not made of just one stochastic component.
A commonly used stochastic differential equation which contains a non-stochastic component is
\begin{equation}
\frac{dS_t}{S_t}=f(t,S_t)dt + g(t,S_t)dW
\label{eqn:general-model}
\end{equation}
where $f(t,S_t)$ and $g(t,S_t)$ are scalar functions and $dW\sim\mathscr{N}(0,\Delta t)$.
In this equation, the first term is a standard differential equation while the second term represents brownian motion.
The combination allows for more accurate models of stochastic processes.
To solve Equation \ref{eqn:general-model}, we apply the Euler-Maruyama method.
This method combines the Euler method for ODEs with an additional stochastic component.
Note that Problem \ref{prob:brownian-motion} is the Euler-Maruyama method where $f(t,S_t)=0$.
We solve for $S_{t+1}$ as follows:

\begin{align*}
dS_t&\approx f(t,S_t)S_tdt + g(t,S_t)S_tdW\\
S_{t+1}-S_t&\approx f(t,S_t)S_tdt + g(t,S_t)S_tdW\\
S_{t+1}&\approx S_t+f(t,S_t)S_tdt + g(t,S_t)S_tdW.
\end{align*}

\begin{problem}
Write a function \li{euler_maruyama()} which accepts a scalar function \li{f}, a scalar function \li{g}, initial condition \li{y0}s, and an array of time points \li{t}.
The function should return an array of the solution to \ref{eqn:general-model}.

To test your function, set $f(t,S_t)=1-(S_t)^2$, $g(t,S_t)=0.1$, $y_0=1$ and $t\in[0,10)$.
Your function should result in a plot which randomly oscillates with $y$ generally in the interval $[0,2]$.
An example is shown in Figure \ref{fig:prob2}.
% try doing histogram instead
\label{prob:euler-maruyama}
\end{problem}

\begin{figure}
\includegraphics[width=\textwidth]{figures/problem2.pdf}
\caption{Possible solution for $f(t,S_t)=1-(S_t)^2$, $g(t,S_t)=0.1$, $y_0=1$ and $t\in[0,10)$.}
\label{fig:prob2}
\end{figure}

\section*{Drift and Volatility}

SDEs are often used in mathematical finance models.
Particularly, the Geometric Brownian Motion (GBM) model is useful in predicting future stock prices.
The GBM is defined as follows:
\begin{equation}
dS_t=\mu S_tdt+\sigma S_tdW,
\label{eqn:gbm}
\end{equation}
where $\mu$ is the drift of the stock and $\sigma$ is the volatility.
The drift $\mu$ of a stock is the average change in return of historic stock data.
The volatility of a stock is the standard deviation of the change in return of historic stock data.
It is expected that $\mu$ and $\sigma$ will remain the same for future stock data.

To find $\mu$ and $\sigma$, let $\theta=(\mu,\sigma)$.
We want to find $\theta_{MAP}$ (maximum a posteriori) which maximizes the probability that $\mu$ and $\sigma$ fit the historical data.
We can calculate $\theta_{MAP}$ using Bayes Theorem:
\begin{equation}
\theta_{MAP}\Bigg(\frac{dS}{S}\Bigg)=\text{argmax}_\theta P\Bigg(\theta|\frac{dS}{S}\Bigg)=\text{argmax}_\theta\frac{P\Big(\frac{dS}{S}|\theta\Big)P(\theta)}{\int_\Theta P\Big(\frac{dS}{S}|\vartheta\Big)P(\vartheta)d\vartheta}=\text{argmax}_\theta P\Big(\frac{dS}{S}|\theta\Big)P(\theta),
\label{eqn:map}
\end{equation}
where $\Theta$ is the collection of all possible $\theta$.
Since no information is known about $P(\theta)$, we choose $P(\theta)$ to be equal over all $\theta$.
This avoids giving bias to one value of $\theta$ over another.
To ease calculations, we choose our improper prior to be uniformly 1, $P(\theta)=1$.
This implies $\theta_{MAP}=\text{argmax}_\theta P(\frac{dS}{S}|\theta)=\theta_{MLE}$.

Now it is necessary to determine the probability distribution of $P(\frac{dS}{S}|\theta)$.
Plotting the change in stock price results in the following histogram:
\begin{figure}
\includegraphics[width=\textwidth]{figures/distribution.pdf}
\caption{Distribution of change in stock price.}
\label{fig:distribution}
\end{figure}
The change in stock price is approximately normally distributed and thus we consider $P(\frac{dS}{S})\sim\mathscr{N}(\mu,\sigma^2)$.
Now we can calculate $\theta_{MAP}$ as follows:

\begin{equation}
\begin{split}
\theta_{MAP}&=\text{argmax}_\theta P(\frac{dS}{S}|\theta)\\
&=\text{argmax}_{\theta}\prod_{i=1}^N\frac{1}{\sqrt{2\pi \sigma^2}}\text{exp}(-\frac{((\frac{dS}{S})_i-\mu)^2}{2\sigma^2})\\
&=\text{argmax}_{\theta}\log(\prod_{i=1}^N\frac{1}{\sqrt{2\pi \sigma^2}}\text{exp}(-\frac{((\frac{dS}{S})_i-\mu)^2}{2\sigma^2}))\\
&=\text{argmax}_{\theta}\sum_{i=1}^N\log(\frac{1}{\sqrt{2\pi \sigma^2}}\text{exp}(-\frac{((\frac{dS}{S})_i-\mu)^2}{2\sigma^2}))\\
&=\text{argmax}_\theta\sum_{i=1}^N\log(\frac{1}{\sqrt{2\pi\sigma^2}})-\frac{((\frac{dS}{S})_i-\mu)^2}{2\sigma^2}\\
&=\text{argmax}_\theta N\log(\frac{1}{\sqrt{2\pi\sigma^2}})-\sum_{i=1}^N\frac{((\frac{dS}{S})_i-\mu)^2}{2\sigma^2}\\
&=\text{argmin}_\theta N\log(\sqrt{2\pi\sigma^2})+\sum_{i=1}^N\frac{((\frac{dS}{S})_i-\mu)^2}{2\sigma^2}\\
&=\text{argmin}_\theta N\log(\sqrt{2\pi\sigma^2})+\frac{1}{2\sigma^2}\sum_{i=1}^N((\frac{dS}{S})_i-\mu)^2
\end{split}
\label{eqn:calculation}
\end{equation}
The end result of Equation \ref{eqn:calculation} gives an equation that can be optimized using \li{scipy.optimize.minimize} to find $\theta$.

\begin{problem}
Write a function \li{theta()} which takes in an array of historical data.
Use \li{scipy.optimize.minimize} and Equation \ref{eqn:calculation} to calculate the optimal $\mu$ and $\sigma$.
Return $\mu$ and $\sigma$.
For the closing stock prices of \li{google_stock.csv}, $\mu\approx1129.4321$ and $\sigma\approx1.8548$.

(Hint: Use the sample mean and sample variance as an initial guess for \li{scipy.optimize.minimize}. Also use \li{method='Nelder-Mead'}.)
\label{prob:theta}
\end{problem}

\begin{problem}
Use \li{euler_maruyama()} to predict the future closing stock prices of Google stock for $t\in[377,427)$.
Plot the original data and the average predicted stock prices.
Return an array of the average future stock prices.
Your plot should look similar to Figure \ref{fig:stock}.

(Hint: Let $f(t,S_t)=\mu$ and $g(t,S_t)=\sigma$. Each $t$ represents one day, so there should be 50 predicted values.)
\label{stock}
\end{problem}

\begin{figure}
\includegraphics[width=\textwidth]{figures/future_stock.pdf}
\caption{Possible plot of future Google stock prices.}
\label{fig:stock}
\end{figure}

\section*{Convergence of Euler-Maruyama}

The Euler-Maruyama method has strong convergence as $\Delta t\rightarrow\infty$.
This can be seen heuristically by looking at the expected value of the error of the numerical method.
Note equation \ref{eqn:gbm} can be solved analytically to get the solution
\begin{equation}
S(t)=s_0e^{\bigl(\mu-\frac{\sigma^2}{2}\bigr)t+\sigma W(t)}
\label{eqn:analytic}
\end{equation}
where $s_0=S(0)$.
Let $A_{\Delta t}(t)$ be the approximation of $S(t)$ with step size $\Delta t$.
Because we are working with SDEs, we take the expected value of the max error over all $t$ and define the error as

\begin{equation}
E(A_{\Delta t})=\sup_t\mathbb{E}\Bigl(|S(t)-A_{\Delta t}(t)|\Bigr)\approx C(\Delta t)^\gamma.
\end{equation}
where $\gamma$ is the order of convergence and $C$ is some constant.
Taking the log of both sides, we get
\begin{equation}
\log(E(A_{\Delta t}))=\log(C)+\gamma\log(\Delta t).
\end{equation}

To find the order of convergence $\gamma$, we can plot $\Delta t\times E(A_{\Delta t}(t))$ as $\Delta t\rightarrow\infty$ with log axes.
This should result is a straight line with slope $\gamma$, giving us the convergence rate.
For Euler-Maruyama, $\gamma=\frac{1}{2}$.

% Compare to Euler which has convergence of order 1
\begin{problem}
Write a function \li{convergence()} that calculates the convergence of Euler-Maruyama.
Calculate the drift and volatility of the closing prices in \li{google_stock.csv} and use Euler-Maruyama to predict stock values for $t\in[0,50)$.
Calculate the difference between the analytical solution \ref{eqn:analytic} and predicted data from Euler-Maruyama.
Plot the difference for $dt=2^i$ for $i\in[0,1,2,3,4,5]$ on a log-log plot.
Your plot should be a straight line with slope $\frac{1}{2}$.

(Hint: Try using \li{np.arange}).
\end{problem}


\subsection{Functions}
This section decribes all the functions in the file ``ptwXY\_functions.c''.

\subsubsection{ptwXY\_pow}
\setargumentNameLengths{ptwXY}
This function applies the math operation $y_i = y_i^{p}$ to the y-values of \highlight{ptwXY}.
\CallingC{fnu\_status ptwXY\_pow(}{statusMessageReporting *smr,
    \addArgument{ptwXYPoints *ptwXY,}
    \addArgument{double p );}}
    \argumentBox{smr}{The \highlight{statusMessageReporting} instance to record errors.}
    \argumentBox{ptwXY}{A pointer to the \highlight{ptwXYPoints} object.}
    \argumentBox{p}{The exponent.}
    \vskip 0.05 in \noindent
This function infills to maintain the initial accuracy.

\subsubsection{ptwXY\_exp}
\setargumentNameLengths{ptwXY}
This function applies the math operation $y_i = \exp( a \, y_i )$ to the y-values of \highlight{ptwXY}.
\CallingC{fnu\_status ptwXY\_exp(}{statusMessageReporting *smr,
    \addArgument{ptwXYPoints *ptwXY,}
    \addArgument{double a );}}
    \argumentBox{smr}{The \highlight{statusMessageReporting} instance to record errors.}
    \argumentBox{ptwXY}{A pointer to the \highlight{ptwXYPoints} object.}
    \argumentBox{a}{The exponent coefficient.}
    \vskip 0.05 in \noindent
This function infills to maintain the initial accuracy.

\subsubsection{ptwXY\_convolution}
This function returns the convolution of \highlight{ptwXY1} and \highlight{ptwXY2}.
\setargumentNameLengths{ptwXY1}
\CallingC{ptwXYPoints *ptwXY\_convolution(}{statusMessageReporting *smr,
    \addArgument{ptwXYPoints *ptwXY1,}
    \addArgument{ptwXYPoints *ptwXY2,}
    \addArgument{int mode );}}
    \argumentBox{smr}{The \highlight{statusMessageReporting} instance to record errors.}
    \argumentBox{ptwXY1}{A pointer to a \highlight{ptwXYPoints} object.}
    \argumentBox{ptwXY2}{A pointer to a \highlight{ptwXYPoints} object.}
    \argumentBox{mode}{Flag to determine the initial x-values for calculating the convolutions.}
    \vskip 0.05 in \noindent
User should set \highlight{mode} to 0.

\subsubsection{ptwXY\_inverse}
This function returns a new instance of \highlight{ptwXYPoints} that is the inverse of \highlight{ptwXY1}.
That is, the returned points are $(y_{\rm i},x_{\rm i})$ where $(x_{\rm i},y_{\rm i})$ are the points of \highlight{ptwXY1}.
All y-values of \highlight{ptwXY1} must be descending or increasing. If the y-values of \highlight{ptwXY1} are descending,
the returned points are reversed to insure that in the returned instance $X_{\rm i} < X_{\rm i+1}$ where $X_{\rm i}$ is a
x-value of new returned instance.
\setargumentNameLengths{ptwXY1}
\CallingC{ptwXYPoints *ptwXY\_inverse(}{statusMessageReporting *smr,
    \addArgument{ptwXYPoints *ptwXY1 );}}
    \argumentBox{smr}{The \highlight{statusMessageReporting} instance to record errors.}
    \argumentBox{ptwXY1}{A pointer to a \highlight{ptwXYPoints} object.}
    \argumentBox{ptwXY2}{A pointer to a \highlight{ptwXYPoints} object.}
    \argumentBox{mode}{Flag to determine the initial x-values for calculating the convolutions.}
    \vskip 0.05 in \noindent
If an error occurs, NULL is returned.


\section{Introduction}
\label{sec:intro}

The use of Machine Learning in attempts to find new physics by probing High Energy Particle interactions has been ubiquitous, but unsupervised techiques are yet to find their place in this landscape. With vast volumes of data available from experiments like the Large Hadron Collider (LHC), it becomes increasingly desirable and ever more plausible that Unsupervised and Model-Free learning take a leading role in the hunt for new Physics.

Jet substructure is the analysis of radiation patterns and particle distributions within the collimated sprays of particles (jets) emerging from high-energy collisions. \cite{energyflow_poly}.
It has found a central importance in many of the searches for new physics at the Large Hadron Collider (LHC) and otherwise, some of them being:
\begin{itemize}
    \item Standard Model measurements
    \item Identification of boosted heavyparticles
    \item Discrimination of quark- from gluon- initiated jets
    \item Search of Beyond Standard Model particles
\end{itemize}

\subsection{Energy Flow Polynomials (EFPs)}

We have had several methods to represent jets as inputs to computational models, from a list of 4-vectors of constituent particles, to images of the jet itself amongst others, but either they are extremely sparse representations of the jets (as in the images) making is hard to ML models to learn something meaningful, or they have had an ordering (as in lists) not providing permutation invariance.

\begin{figure}
    \centering
    \begin{subfigure}[b]{0.49\textwidth}
        \includegraphics[width=\textwidth]{img/efp-qcd-particlenetdata.png}
        \caption{Histograms for QCD Jets}
    \end{subfigure}
    \begin{subfigure}[b]{0.49\textwidth}
        \includegraphics[width=\textwidth]{img/efp-top-particlenetdata.png}
        \caption{Histograms for Top Jets}
    \end{subfigure}
    \caption{EFP Polynomials on Top Tagging data}
    \label{fig:efp-histogram}
\end{figure}

\paragraph{EFPs as a method of jet representation} are both dense representations which inherently have permutation, as well as translational and rotational invariance. For any given jet, it's EFPs are Polynomials of the following form ~\cite{energyflow_poly}:
\begin{equation}
    \text{EFP}_{G} = \sum_{i_1 = 1}^{M} \dots \sum_{i_N = 1}^{M} z_{i_1} \dots z_{i_N} \prod_{k,l \in G} \theta_{i_k i_l}
\end{equation}
In addition, linear models trained on these polynomials perform nearly as well as the best Neural Networks on jet tagging tasks while having over an order magnitude fewer parameters. Owing to the fact that very simple supervised models can perform well using EFPs as the input representation, it seems natural that the same would apply to unsupervised techiniques.

\subsection{Latent Dirichet Allocation}

\textcolor{red}{Add details on what LDA does and any it's general issues, low accuracy, etc.}


In order to give a better sense of the approach to reliability analysis and
optimization presented in \sref{chaos-reliability-analysis} and
\sref{chaos-optimization}, we consider a concrete application, meaning that we
specify the uncertain parameters and discuss the accompanying computations. This
application is also utilized for the quantitative evaluation of our technique
presented in the next section, \sref{chaos-optimization-results}.

\subsection{\problemtitle}

Assume that the structure of the reliability model $R(\cdot | \vg)$ of the
system at hand is the one given in \eref{reliability-model} where each
individual reliability function $R_i(\cdot | \vg_i)$ is the one shown in
\eref{weibull-reliability} with its own parameters $\scale_i$ and $\shape_i$.

During each iteration, the temperature of processing element~$i$ exhibits \nk{i}
cycles. Each cycle generally has different characteristics and hence causes a
different amount of damage to the processing element. This aspect is accounted
for by adjusting $\scale_i$ as shown in \eref{thermal-cycling-scale}. The shape
parameter $\shape_i$ is known to be indifferent to temperature \cite{chang2006}.
For simplicity, assume that $\shape_i$ does not depend on process parameters
either, and that $\shape_i = \shape$ for $i = \range{1}{\np}$.

Under the above assumptions, \rref{weibull-homogeneity} applies, and the
lifetime $\life: \Omega \to \real$ of the system has a Weibull distribution as
follows:
\[
  \life | (\scale, \shape) \sim \mathrm{Weibull}(\scale, \shape)
\]
where $\scale$ is the one given in \rref{weibull-homogeneity} combined with
\eref{thermal-cycling-scale}. Even though the reliability model has two
parameters, only one of them is uncertain to the designer, namely $\scale$.
Therefore, we treat the model as if it was parameterized only by $\scale$. The
shape parameter $\shape$ is assumed to be implicitly given.

In the case of reliability analysis under process variation without any
accompanying exploration of the design space, one can proceed to constructing a
\ac{PC} expansion of $\scale$. Having obtained this lightweight surrogate, the
reliability of the system can be studied from various perspectives. In the
current scenario, however, the quantity of interest \g is the one given in
\eref{chaos-optimization-quantity}, since it allows for evaluating the objective
function and constraints defined in \eref{chaos-optimization-objective} and
\eref{chaos-optimization-constraints}, respectively. In
\eref{chaos-optimization-quantity}, the component denoted by \life stands for
the parameterization of the reliability model; consequently, it is $\scale$ in
the illustrative application developed in this section.

Let us now turn our attention to the uncertain parameters \vu of the problem
being addressed. We focus on two crucial process parameters: the effective
channel length and gate oxide thickness. Each processing element is then
assigned two random variables corresponding to the two process parameters, which
means that $\nu = 2 \np$ in the current example; see also \sref{chaos-problem}.

\begin{remark}
The variability in a process parameter at a spatial location can be modeled as a
composition of several parts---such as inter-lot, inter-wafer, inter-die, and
intra-die variations---which is demonstrated in
\sref{chaos-transient-application}. In this section, we illustrate a different
approach. From a mathematical perspective, it is sufficient to consider only one
random variable per location with an adequate distribution and correlations with
respect to the other locations.
\end{remark}

Based on \sref{chaos-formulation}, the parameters \vu are assumed to be given as
a set of marginal distributions and a correlation matrix denoted by
$\set{F_i}_{i = 1}^\nu$ and $\correlation{\vu}$, respectively. Note that the
number of distinct marginals is only two, since \np components of \vu correspond
to the same process parameter.

Both process parameters, the effective channel length and gate oxide thickness,
correspond to Euclidean distances; they take values on bounded intervals of the
positive half of the real line. Consequently, similarly to
\sref{chaos-transient-application}, we model the two process parameters using
the four-parameter family of beta distributions shown in
\eref{beta-distribution}. Without loss of generality, the parameters are assumed
to be independent of each other, and the correlations between those elements of
\vu that correspond to the same process parameter are assumed to be given by the
correlation function shown in \eref{bayes-correlation}.

The process parameters manifest themselves in the calculations associated with
the power model shown in \eref{chaos-power-model-bulk} through static power.
Analogously to \sref{chaos-transient-application}, the modeling here is based on
\up{SPICE} simulations of a series of \up{CMOS} invertors. The invertors are
taken from the 45-nm open cell library by NanGate \cite{nangate} and configured
according to the 45-nm \up{PTM} \up{HP} model \cite{ptm}. The simulations are
performed on a fine-grained and sufficiently broad three-dimensional grid
comprising the effective channel length, gate oxide thickness, and temperature;
the results are tabulated. An interpolation algorithm is subsequently employed
whenever static power is to be evaluated at a particular point within the range
of the grid. The output of this model is scaled up to account for about 40\% of
the total power consumption \cite{liu2007}. Regarding temperature, the thermal
\up{RC} circuit utilized for dynamic steady-state analysis is constructed by
virtue of HotSpot \cite{skadron2003} as described in \sref{temperature-model}.

At this point, the two outputs of Stage~1 are now specified.

\subsection{Probability Transformation}

At Stage~2 in \fref{chaos-overview}, the uncertain parameters \vu are
transformed into a vector of independent random variables \vz via a suitable
transformation $\transform$. Specifically, we use the one given in
\eref{probability-transformation}, which also includes model order reduction.
Unlike \sref{chaos-transient-application}, in this section, we let \vz obey the
standard Gaussian distribution and, therefore, tailor $\transform$ accordingly;
see \xref{probability-transformation}.

\subsection{Surrogate Construction}

Since the auxiliary variables $\vz = (\z_i)_{i = 1}^\nz$ are Gaussian, the
polynomial basis considered at Stage~3 is to be composed of Hermite polynomials,
which is the exact scenario described in \xref{polynomial-chaos}. The variables
also tell us how to approach numerical integration needed for evaluation of the
coefficients of \ac{PC} expansions: since we are interested in integrals with
respect to the standard Gaussian measure, Gauss--Hermite quadratures
\cite{maitre2010} are worth considering. These quadratures are especially
efficient, since they belong to the class of Gaussian quadratures and thus
inherit their properties; see \xref{numerical-integration}.

Lastly, let us illustrate the Hermite basis. In the case of working with only
one standard Gaussian variable ($\nz = 1$), a second-level \ac{PC} expansion
($\lc = 2$) of a three-dimensional quantity of interest \vg is as follows:
\[
  \chaos{1}{2}{\vg}
  = \hat{\vg}_{(0)} \psi_{(0)}
  + \hat{\vg}_{(1)} \psi_{(1)}
  + \hat{\vg}_{(2)} \psi_{(2)}
\]
where $\set{\hat{\vg}_{\vi}} \subset \real^3$,
\begin{align*}
  & \psi_{(0)}(\vz) = 1, \\
  & \psi_{(1)}(\vz) = \z_1, \text{ and} \\
  & \psi_{(2)}(\vz) = \z_1^2 - 1.
\end{align*}
At Stage~4, the expansion is post-processed as described in
\sref{chaos-optimization}.


\chapter{Experimental Tests in the Solar System}
How can we test relativistic effects in our solar system?
\begin{itemize}
  \item The sum of the mass of all planets is much smaller than the solar mass
  $M_{\astrosun}\approx \unit[2\cdot 10^{30}]{kg}$. The heaviest planet is
  Jupiter with a mass of $M\textsubscript{Jup}\approx \unit[2\cdot
  10^{27}]{kg}$, therefore we can assume the planets to be testparticles.
  \item The sun is in good approximation a spherically symmetric object. We can
  therefore use the Schwarzschild metric.
\end{itemize}
% Consider the variation of the energy functional
% \begin{equation}
% \int\tensor{g}{_\mu_\nu}\tensor{\dot{x}}{^\mu}\tensor{\dot{x}}{^\nu}\dif\lambda\,.
% \end{equation}
We define
$K:=-\tensor{g}{_\mu_\nu}\tensor{\dot{x}}{^\mu}\tensor{\dot{x}}{^\nu}$, which is
conserved along geodesics and it holds true that
\begin{equation}
K=\begin{cases}
-1& \mathrm{\ timelike\ geodesics}\\
\phantom{-}0& \mathrm{\ lightlike\ geodesics}
\end{cases}\,.
\end{equation}
Using the Schwarzschild metric, we can explicitly write
\begin{equation}
K=-e^{2a(r)}\dot{t}^2+e^{2b(r)}\dot{r}^2+r^2\left(\dot{\vartheta}+\sin^2\vartheta
\dot{\phi}\right)
\end{equation}
A Killing-vector $\tensor{\xi}{^\mu}$ satisfies
\begin{equation}
\tensor{\xi}{_\mu}\tensor{\dot{x}}{^\mu}=\mathrm{\ const.}
\end{equation}
For the Schwarzschild metric, there are four independent Killing-vectors,
corresponding to 3 rotations, and staticity (time independence).
Conservation of angular momentum leads to a motion in a plane, w.l.o.g.\ we can
chose a coordinate system in which $\vartheta=\nicefrac{\pi}{2}$.
The Killing-Vectors are given by
\begin{align}
\tensor*{\xi}{_{(\varphi)}^\mu}&=(\partial_\varphi)^\mu=\tensor*{\delta}{_\varphi^\mu}\,,\\
\tensor*{\xi}{_{(t)}^\mu}&=(\partial_t)^\mu=\tensor*{\delta}{_t^\mu}\,.
\end{align}
The associated conserved quantities are
\begin{align}
E&:=\tensor*{\xi}{_{(\varphi)}^\mu}\tensor{g}{_\mu_\nu}\tensor{\dot{x}}{^\nu}
=\tensor{g}{_t_t}\dot{t}
=e^{2a}\dot{t}
=\left(1-\frac{2M}{r}\right)\dot{t}
\\
L&:=\tensor*{\xi}{_{(t)}^\mu}\tensor{g}{_\mu_\nu}\tensor{\dot{x}}{^\nu}
=\tensor{g}{_\varphi_\varphi}\dot{\varphi}
=r^2\dot{\varphi}\,.
\end{align}
For massless
%TODO stimmt das?
particles, we can think of $E$ and $L$ as conserved energy and angular momentum.
It follows
\begin{equation}
K=-\left(1-\frac{2M}{r}\right)\dot{t}^2+\left(1-\frac{2M}{r}\right)^{-1}\dot{r}^2+r^2\varphi^2
\end{equation}
If we insert the conserved quantities $L,E$ and multiply by
$\frac{1}{2}\left(1-\frac{2M}{r}\right)$, we get
\begin{equation}
\frac{E^2}{2}=\frac{\dot{r}^2}{2}
+\left(1-\frac{2M}{r}\right)\left(\frac{L^2}{2r}-\frac{K}{2}\right)\,.
\end{equation}
This expression can be rearranged to the Form
\begin{equation}
\frac{\dot{r}^2}{2}+V\textsubscript{eff}(r)
=\varepsilon\,,
\end{equation}
with the convenient definitions
\begin{equation}
V\textsubscript{eff}(r):=\frac{MK}{r}+\frac{L^2}{2r^2}-\frac{ML^2}{r^3}\,,\quad
\varepsilon:=\frac{E^2+K}{2}\,.
\end{equation}
\begin{figure}[hbtp!]
\centering
 \includegraphics{plot2.pdf}
\caption{Effective Potential in Newtonian physics.}
%TODO unit of a!
\end{figure}
\begin{figure}[hbtp!]
\centering
 \includegraphics{plot1.pdf}
\caption{Effective Potential in GR for various
$a=L/(mr\textsubscript{S})$.}
%TODO unit of a!
\end{figure}
\begin{figure}[hbtp!]
\centering
 \includegraphics{plot3.pdf}
\caption{Effective Potential for a photon.}
%TODO unit of a!
\end{figure}

\section{Perihelion Shift of Mercury}
% \begin{figure}[b]
% \centering
% \begin{tikzpicture}[auto,node distance=3cm,thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries}]
% \draw [black,thick,dashed] (0,0) circle (1/1.6);
% \draw [black,thick,dashed] (0,0) circle (1/0.4);
% \draw [thick, color=red, domain=0:6*pi, samples=200, smooth]
%   plot (xy polar cs:angle=\x r, radius={1/(1-0.6*cos(\x r+0.2*\x r))});
% \node [fill=white] at (0,1) {Perihelion};s
% \node at (0,0) {\Huge\textbullet};
% \node (1) at (40:1/1.6) {\textbullet};
% \node (2) at (90:1/1.6) {\textbullet};
% \node (3) at (140:1/1.6) {\textbullet};
% \end{tikzpicture}
% \caption{Perhelion shift of mercury (exaggerated)}
% \end{figure}
It has been known for a long time that the perihelion of the mercury moves by
roughly $5061''\footnote{Where an arcsec $''$ denotes the 3600 part of
an degree.}/\textrm{century}$, if on subtracts other effects such a
fraction of $43''/\textrm{century}$.
\begin{figure}[hbtp!]
\centering
 \includegraphics{perishift.pdf}
\caption{Perihelion shift of mercury. (exaggerated)}
\end{figure}

There where several proposed explanations for this including
\begin{itemize}
  \item a new planet called Vulcan between mercury and the sun,
  \item a change to newtons $1/r^2$-law,
  \item effects due the suns quadrupole moment.
\end{itemize}
We will now look at what is predicted by GR.
The trajectories of planets ($K=-1$) are given by
\begin{equation}
\dot{r}^2-\frac{2M}{r}+\frac{L^2}{r^2}-\frac{2ML^2}{r^3}=E^2-1\label{eq:planeteq}\,.
\end{equation}
If we think of the radius as a function of the angle, we can write
\begin{equation}
\dot{r}=\od{r}{\lambda}=\od{r}{\phi}\od{\phi}{\lambda}\,.
\end{equation}
Multiplying \eqref{eq:planeteq} with
%TODO choose between varphi and phi
$\left(\od{\phi}{\lambda}\right)^{-2}=\frac{1}{\dot{\phi}}=\frac{r^4}{L^2}$
yields
\begin{equation}
\left(\dod{r}{\phi}\right)^2-\frac{2Mr^3}{L^2}+r^2-2Mr
=\left(E^2-1\right)\frac{r^4}{L^2}\,.\label{eq:orbitrphi}
\end{equation}
Similar to the treatment of the Keppler problem in classical mechanics, we
define
\begin{equation}
u(\phi):=\frac{L^2}{Mr(\phi)}\,.
\end{equation}
This implies
\begin{equation}
\dif r=-\frac{L^2}{Mu^2}\dif u\,,\quad
\left(\dod{r}{\phi}\right)^2=\frac{L^4}{M^2u^4}\left(\dod{u}{\phi}\right)^2\,.
\end{equation}
In terms of the new variables \eqref{eq:orbitrphi} reads
\begin{equation}
\left(\dod{u}{\phi}\right)^2-2u+u^2-\frac{2M^2}{L^2}u^3=(E^2-1)\frac{L^2}{M^2}\,.
\end{equation}
We differentiate with respect to $\phi$ and get
\footnote{primes denote $\phi$
derivatives}
\begin{equation}
2u^\prime u^{\prime\prime}-2u^\prime+2u
u^{\prime}-\frac{6M^2}{L^2}u^2u^\prime=0\,.
\end{equation}
Dividing by $2u^\prime$ yields
\begin{equation}
u^{\prime\prime}-1+u=\frac{3M^2}{L^2}u^2\,,
\end{equation}
which is an equation similar to the Keppler problem. The difference is in the
right hand side, which is equal zero in the classical case.
We may calculate an approximation by pertubative corrections
\footnote{The quantity relevant for the error of a given order is
$\frac{3M^2}{L^2}$.}
\begin{equation}
u=u_0+u_1+u_2+\dots\,.
\end{equation}
At zeroth order, we neglect the quadratic term, so that we are left with
\begin{equation}
u_0^{\prime\prime}-1+u_0=0\,,
\end{equation}
which is equal to the Newtonian problem, with exact solution
\begin{equation}
u_0(\phi)=1+\varepsilon\cos\phi\,.
\end{equation}
\begin{figure}[hbtp!]
\centering
 \includegraphics{ellipsegeo.pdf}
\caption{An ellipse is the solution to the classical unperturbed Kepler
problem.}
\end{figure}

At first order we have
\begin{equation}
\begin{split}
u_1^{\prime\prime}-1+u_1&=\frac{3M^2}{L^2}u_0^2\\
&=\frac{3M^2}{L^2}\left(1+\varepsilon\cos\phi\right)^2\\\
&=\frac{3M^2}{L^2}\left(1+\frac{\varepsilon^2}{2}+2\varepsilon\cos\phi+\frac{1}{2}\varepsilon^2\cos
2\phi\right)\,,
\end{split}
\end{equation}
Where we made use of trigonometric identities in the last step.
The first order solution reads
\begin{equation}
u_1(\phi)=1+\varepsilon\cos\phi+\frac{3M^2}{L^2}\phi\sin\phi\,.
\end{equation}
which can be checked by using
\begin{align}
\dod[2]{}{\phi}(\phi\sin\phi)+\phi\sin\phi&=2\cos\phi\,,\\
\dod[2]{}{\phi}(\cos 2\phi)+\cos 2\phi&=-3\cos 2\phi\,.
\end{align}
Assuming that we still have approximately a movement along an ellipse and Taylor
expansion yields
\begin{equation}
u(\phi)=1+\varepsilon\cos[(1-\delta)\phi]
\simeq
1+\varepsilon\cos\phi
+\varepsilon\delta\phi\sin\phi+\landauO(\delta^2)\,.
\end{equation}
Comparing this to the expression for $u_1$ we find
\begin{equation}
\delta=\frac{3M^2}{L^2}
\end{equation}
and the error is of order $\delta^2$.
%\begin{equation}
% r(\phi)=\frac{p}{1+\varepsilon\cos\phi}
% =\frac{a\left(1-\varepsilon^2\right)}{1+\varepsilon\cos\phi}
% \end{equation}
If we assume that there was a perihelion at $\phi_p$, the next one will occure
at $\phi+\Delta\Phi$ with
\begin{equation}
\Delta\phi=2\pi\delta=\frac{6\pi M^2}{L^2}
\end{equation}
The zeroth order solution gives
\begin{equation}
r_0(\phi)=\frac{L^2}{M(1+\varepsilon\cos\phi)}\stackrel{!}{=}
\frac{a(1-\varepsilon^2)}{1+\varepsilon\cos\phi}\,.
\end{equation}
So $L^2\approx M(1-\varepsilon^2)a$ with an error of order $\delta$, that can
be neglected.
With this approximation and restoring factors of $c$ and $G$ we arrive at the following
expression for the perihelion shift:
\begin{equation}
\Delta\phi=\frac{6\pi G M_{\astrosun}}{c^2 (1-\varepsilon^2)a}\,.
\end{equation}
As expected the effect scalses with $1/a$ and thus the planet nearest to the sun
recives the strongest effect. For mercury we have
\begin{equation}
\frac{GM_{\astrosun}}{c^2}=\unit[1.48]{km}\,,\quad a =\unit[5.79\cdot
10^7]{km}\,,\quad\varepsilon=0.2056\,,
\end{equation}
Which results in an perihelionshift
\begin{equation}
\Delta\phi\textsubscript{mer}
=\unitfrac[5.03\cdot 10^{-7}]{rad}{orbit}
=\unitfrac[43]{{}^{\prime\prime}}{century}\,,
\end{equation}
which fits the observation in the error margin.


\documentclass[paper=a4, fontsize=11pt]{scrartcl} % A4 paper and 11pt font size
\usepackage{physics}
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage{fourier} % Use the Adobe Utopia font for the document - comment this line to return to the LaTeX default
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amsthm} % Math packages
\usepackage{braket}
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{sectsty} % Allows customizing section commands
\allsectionsfont{\centering \normalfont\scshape} % Make all sections centered, the default font and small caps
\usepackage[mathscr]{euscript}
\usepackage{bm}
\newcommand{\uvec}[1]{\boldsymbol{\hat{\textbf{#1}}}}
\usepackage[thinlines]{easytable}
\usepackage{fancyhdr} % Custom headers and footers
\pagestyle{fancyplain} % Makes all pages in the document conform to the custom headers and footers
\fancyhead{} % No page header - if you want one, create it in the same way as the footers below

\usepackage{multicol}
\fancyfoot[L]{} % Empty left footer
\fancyfoot[C]{} % Empty center footer
\fancyfoot[R]{\thepage} % Page numbering for right footer
\renewcommand{\headrulewidth}{0pt} % Remove header underlines
\renewcommand{\footrulewidth}{0pt} % Remove footer underlines
\setlength{\headheight}{13.6pt} % Customize the height of the header
\usepackage{float}
\numberwithin{equation}{section} % Number equations within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
\numberwithin{figure}{section} % Number figures within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
\numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)

\setlength\parindent{0pt} % Removes all indentation from paragraphs - comment this line for an assignment with lots of text

%----------------------------------------------------------------------------------------
%	TITLE SECTION
%----------------------------------------------------------------------------------------

\newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height

\title{
\normalfont \normalsize
\textsc{California State University San Marcos \\ Dr. De Leone, Physics 323} \\ [25pt] % Your university, school and/or department name(s)
\horrule{0.5pt} \\[0.4cm] % Thin top horizontal rule
\huge H.W. 3 \\ % The assignment title
\horrule{2pt} \\[0.5cm] % Thick bottom horizontal rule
}

\author{Josh Lucas} % Your name

\date{\normalsize\today} % Today's date or a custom date

\begin{document}

\maketitle % Print the title

%----------------------------------------------------------------------------------------
%	PROBLEM 1
%----------------------------------------------------------------------------------------

\section{State Vectors}
Consider the following state vectors:
\begin{equation*}
\ket{\psi_1} = 2\ket{+} + 3\ket{-};\quad \ket{\psi_2} = -3i\ket{+} + 2\ket{-};\quad \ket{\psi_3} = \ket{+} + e^{i\frac{ \pi}{4}}\ket{-};
\end{equation*}
\textbf{a) Calculate the inner product of $\bra{\psi_2}\ with\ \ket{\psi_1}$}\\
\begin{align*}
\braket{\psi_2 |\psi_1} & = -3i(2) \braket{+|+} +2(3)\braket{-|-}\\
   & =  -6i + 6\\
   \braket{\psi_2 | \psi_2} &= 6-6i
\end{align*}
\textbf{b) Normalize each state vector}\\
 \begin{align*}
1 & = \braket{\psi_1 | \psi_1} \\
 & = C^* \big \{\ 2\bra{+} +3\bra{-}\ \big\}\ C\big \{\ 2\ket{+}+3\ket{-} \big \} \\
& = C^*C \big \{ 2^2 \braket{+|+} + 2(3)\braket{+|-} + 3(2)\braket{-|+} + 3^2 \braket{-|-} \big \}  \\
 1 & = 13|C|^2 \\
 |C_{\psi_1}| & = \frac{1}{\sqrt{13}} \\
 \ket{\psi_1} & = \frac{1}{\sqrt{13}} \big ( 2\ket{+} + 3\ket{-} \big )
\end{align*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{align*}
1 & = \braket{\psi_2 | \psi_2} \\
 & = C^* \big \{\ 3i\bra{+} +2\bra{-}\ \big\}\ C\big \{\ -3i\ket{+}+2\ket{-} \big \} \\
& = C^*C \big \{ -9(i)^2 \braket{+|+} +3i(2)\braket{+|-} + 2(-3i)\braket{-|+} + 2^2 \braket{-|-} \big \}  \\
& = C^*C \big \{ 9 + 4 \big \} \\
 1 & = 13|C|^2 \\
 |C_{\psi_2}| & = \frac{1}{\sqrt{13}} \\
 \ket{\psi_2} & = \frac{1}{\sqrt{13}} \big ( -3i\ket{+} + 2\ket{-} \big )
\end{align*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{align*}
1 & = \braket{\psi_3 | \psi_3} \\
  & = C^* \big \{  \bra{+} + e^{-i\tfrac{\pi}{4}} \bra{-} \big \} C \big \{ \ket{+} + e^{i\tfrac{\pi}{4}} \ket{-} \big \} \\
  & = C^*C \big \{ \braket{+|+} + e^{i\tfrac{\pi}{4} - i\tfrac{\pi}{4}} \braket{-|-} \big \} \\
  & = C^* C \big \{ 1+ 1 \big \} \\
  1 & = 2|C|^2 \\
  |C_{\psi_3}| & = \frac{1}{\sqrt{2}} \\
  \ket{\psi_3} & = \frac{1}{\sqrt{2}} \big ( \ket{+} +   e^{i\tfrac{\pi}{4}} \ket{- }\big )
\end{align*}
 \textbf{c) For each normalized state vector, use Postulate 4 to calculate the probability that the spin-component is up or down along the z-axis. }
 \begin{multicols}{2}
 \noindent
\begin{align*}
 \mathscr{P_+} & = |\braket{+|\psi_1 }|^2 \\
 & = |\bra{+} \big[ \tfrac{2}{\sqrt{13}}\ket{+} + \tfrac{3}{\sqrt{13}} \ket{-} \big] |^2 \\
 & = |\tfrac{2}{\sqrt{13}} \braket{+|+} + \tfrac{3}{\sqrt{13}} \braket{+|-}|^2 \\
 & = \bigg | \tfrac{2}{\sqrt{13}} \bigg |^2 \\
\mathscr{P_+} & = \frac{4}{13}
  \end{align*}
   \begin{align*}
 \mathscr{P_-} & = |\braket{-|\psi_1 }|^2 \\
 & = |\bra{-} \big[ \tfrac{2}{\sqrt{13}}\ket{+} + \tfrac{3}{\sqrt{13}} \ket{-} \big] |^2 \\
 & = |\tfrac{2}{\sqrt{13}} \braket{-|+} + \tfrac{3}{\sqrt{13}} \braket{-|-}|^2 \\
 & = \bigg | \tfrac{3}{\sqrt{13}} \bigg |^2 \\
\mathscr{P_-} & = \frac{9}{13}
  \end{align*}
  \end{multicols}
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \begin{multicols}{2}
  \noindent
  \begin{align*}
 \mathscr{P_+} & = |\braket{+|\psi_2 }|^2 \\
 & = |\bra{+} \big[ \tfrac{-3i}{\sqrt{13}}\ket{+} + \tfrac{2}{\sqrt{13}} \ket{-} \big] |^2 \\
 & = |\tfrac{-3i}{\sqrt{13}} \braket{+|+} + \tfrac{2}{\sqrt{13}} \braket{+|-}|^2 \\
 & = \bigg | \tfrac{-3i}{\sqrt{13}} \bigg |^2 \\
\mathscr{P_+} & = \frac{9}{13}
  \end{align*}
   \begin{align*}
 \mathscr{P_-} & = |\braket{-|\psi_2 }|^2 \\
 & = |\bra{-} \big[ \tfrac{-3i}{\sqrt{13}}\ket{+} + \tfrac{2}{\sqrt{13}} \ket{-} \big] |^2 \\
 & = |\tfrac{-3i}{\sqrt{13}} \braket{-|+} + \tfrac{2}{\sqrt{13}} \braket{-|-}|^2 \\
 & = \bigg | \tfrac{2}{\sqrt{13}} \bigg |^2 \\
\mathscr{P_-} & = \frac{4}{13}
  \end{align*}
  \end{multicols}
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \begin{multicols}{2}
  \noindent
  \begin{align*}
  \mathscr{P_+} & = |\braket{+ | \psi_3}|^2 \\
  & = |\bra{+} \big [ \tfrac{1}{\sqrt{2}} \ket{+} + \tfrac{ e^{i\tfrac{\pi}{4}}}{\sqrt{2}} \ket{-} \big ]|^2 \\
  & = |\tfrac{1}{\sqrt{2}} \braket{+|+} + \tfrac{ e^{i\tfrac{\pi}{4}}}{\sqrt{2}} \braket{+|-}  |^2 \\
  & = \bigg | \frac{1}{\sqrt{2}} \bigg |^2 \\
  \mathscr{P_+} & = \frac{1}{2}
\end{align*}
\begin{align*}
  \mathscr{P_-} & = |\braket{- | \psi_3}|^2 \\
  & = |\bra{-} \big [ \tfrac{1}{\sqrt{2}} \ket{+} + \tfrac{ e^{i\tfrac{\pi}{4}}}{\sqrt{2}} \ket{-} \big ]|^2 \\
  & = |\tfrac{1}{\sqrt{2}} \braket{-|+} + \tfrac{ e^{i\tfrac{\pi}{4}}}{\sqrt{2}} \braket{-|-}  |^2 \\
  & = \bigg |  \tfrac{ e^{i\tfrac{\pi}{4}}}{\sqrt{2}} \bigg |^2 \\
  \mathscr{P_-} & = \frac{1}{2}
\end{align*}
\end{multicols}
 \textbf{d) Would you expect to find the same probabilities for the measured spin-components along the x- and y- axes?}\\
 \\
 We would not expect to find the same probabilities for the other axes. The probabilities in the orthogonal directions are independent of each other.
 \section{Phase of quantum state vector}
\textbf{Show that a change in the overall phase of a quantum state vector does not change the probability of obtaining a particular result in a measurement. }\\
\\
The phase of the quantum state vector is not physically measurable only the difference in the phases. The complex conjugate will ensure the magnitude is the same.
\begin{align*}
\mathscr{P_\pm} & = |\braket{\pm|\psi}|^2 \\
\mathscr{P_{\psi_\alpha}}& = |\braket{\pm | e^{i\alpha}\psi}|^2 \\
& = |e^{i\alpha} \braket{\pm | \psi}|^2 \\
& = (e^{i\alpha} \braket{\pm | \psi})(e^{-i\alpha} \braket{\pm | \psi}) \\
& = |(1)\braket{\pm | \psi}|^2 \\
\mathscr{P_\pm} & = \mathscr{\psi_\alpha} \\
|\braket{\pm | \psi}|^2 & = |\braket{\pm | \psi}|^2
\end{align*}
%----------------------------------------------------------------------------------------

\end{document}

H.W. 3 Due Monday 9-10-2018/Phys323 H.W.3.tex


%\lipsum[1-20]

Chapter~\ref{chp:bgm} has provided a framework for modeling the self-assembly of a polyhedron using a Markov process. When using a transition rate matrix of the form
\begin{align}
  \label{eq:Qdef_rep}
  Q_{jk} =
  \begin{cases}
   S_{jk}e^{-\beta\left(E_{jk} - E_{j}\right)} & \text{if } [x^j] \leftrightarrow [x^k]  \\
   -z_j       & \text{if } j = k \\
   0 & \text{else}
  \end{cases}
\end{align}
the intermediate energies $E_j$ and transition barrier energies $E_{jk}$ must be specified. Using minus the number of closed edges in an intermediate has a nice, physically motivated interpretation. The choice of barrier heights, however, has not yet been addressed. Using information of an intermediate's geometric configuration space that can be gathered using our manifold reflected Brownian motion scheme, we derive energy barrier heights and thus the rate matrix $Q$. This combination of combinatorial and geometric structure provides a unique insight into the various themes of self-assembly.

\section{Deriving Rates}

Consider the process of adding a face to an intermediate. In the combinatorial configurations space this is a transition from one node of the graph to another. However, for this transition to occur in a more physical setting, the geometry of the intermediate plays a large role. One can imagine that there are geometric configurations are contorted in a way as to prevent a face from being added at a particular location. For instance consider the linkage of two triangles as an intermediate of the tetrahedron. Since the combinatorial configuration space is rather trivial, adding a face will results in the rigid linkage of three triangles all sharing a vertex. Since the equilateral triangle has angles of $\frac{\pi}{3}$, the angle between the two edges of the two triangle linkage that the third face attaches to must be close to $\frac{\pi}{3}$ for it to attach easily. We extend and formalize this idea for face attachment on a Building Game intermediate to obtain the rates we desire.

%Since we assume that each polyhedron is composed solely of triangles, each attachable face will have three vertices. For each of these vertices, there is either $0, 1,$ or $2$ vertices on the existing intermediate that they will attach to. If there are zero vertices on the intermediate that the vertex on the new face combines with, it means that the attachment occurs

If there are three vertices $v_a, v_b, v_c$ in the intermediate that each combine with one of the three vertices on the added triangle, and $(v_a, v_b)$ and $(v_b, v_c)$ are edges in one of the intermediate's existing triangles, the rate of attachment for the face is given by the proportion of time the configuration--undergoing manifold reflected Brownian motion--has $\frac{\pi}{3} - \epsilon < \angle( v_a, v_b, v_c) < \frac{\pi}{3} + \epsilon$. Here $\epsilon$ is a parameter reflecting how close to the ideal angle the configuration must be in order to allow attachment. If there are no such triplets $v_a, v_b, v_c$ where a face is being attached, the attachment occurs at a unit rate. If there are more than one triplet $v_a, v_b, v_c$, the attachment rate is averaged across each such triplet. Taking this empirical rate and summing over the other faces corresponding to the degeneracies of the transition of interest, the empirical forward transitions rates $\hat{Q}_{jk}$ are derived. By comparing these computed rates with the analytic form for our transition rate matrix, we can derive the barrier heights $E_{jk}$ for each transitions. Since the barriers are symmetric, this information also gives the reverse transition rates $Q_{kj}$.
\begin{align}
\hat{Q}_{jk} &= Q^0_{jk} \\
	&= S_{jk}e^{\beta_0(E_{jk} - E_j)} \\
E_{jk} &= E_j-\frac{1}{\beta_0}\log\left(\hat{Q}_{jk}/S_{jk}\right)
\end{align}
Here $\beta_0$ is the inverse temperature used to derive the barriers from the empirical computations. Since
\begin{align}
Q_{jk} 	&= S_{jk}e^{\beta(E_{jk} - E_j)} \\
 &= S_{jk} e^{-\beta\left(E_j-\frac{1}{\beta_0}\log\left(\hat{Q}_{jk}/S_{jk}\right) - E_j\right)} \\
 &= S_{jk}\left(\hat{Q}_{jk}/S_{jk}\right)^{\frac{\beta}{\beta_0}},
\end{align}
the choice of $\beta_0$ effectively specifies the units of $\beta$. Typically, we choose $\beta_0 = 1$.

To derive the empirical rates, each intermediate was simulated for $10,000,000$ steps with a stepsize of $h = 0.05$. By storing each of the relevant angles either step by step, or in a histogram, the rates can be computed for each choice of $\epsilon$ at a later time as needed.

\section{Self-Assembly Statistics}

After we have computed the rate matrix $Q$ for the octahedron as a function of $\epsilon$ and $\beta$, we are now able to compute the different statistics derived in section~\ref{sec:StochMod}.
\begin{figure}[ht]
\centering
  \includegraphics[scale=0.6]{images/octahedron_pi.eps}
\caption{Octahedron stationary distributions as a function of $\beta$.}
\label{fig:OctaPi}
\end{figure}
For instance, the stationary distribution of each octahedron intermediate is plotted as a function of $\beta$ in figure~\ref{fig:OctaPi}.
\begin{figure}[ht]
\centering
  \includegraphics[scale=0.6]{images/octahedron_log_pi.eps}
\caption{Natural log of the octahedron stationary distributions as a function of $\beta$.}
\label{fig:OctaLogPi}
\end{figure}
To better view how these probabilities decay as the temperature decreases, figure~\ref{fig:OctaLogPi} presents the natural logarithm of these stationary probabilities.

With the rate matrix, we can also look at how the occupation probabilities change over time.
\begin{figure}[ht]
\centering
  \includegraphics[scale=0.6]{images/octahedron_finite_dist.eps}
\caption{Occupation probabilities for Octahedron intermediates as a function of time.}
\label{fig:OctaFinDist}
\end{figure}
If the process begins with a single face, the probabilities diffuse through the graph according to $e^{Qt}e_1$ and eventually converge of the stationary distribution $\pi$ as $t \to \infty$. Figure~\ref{fig:OctaFinDist} shows how these occupation probabilities change over time.

Another way to visualize the dynamic behaviors of our Markov process is to look at individual transitions and the rates with which they occur.
\begin{figure}[ht]
\centering
  \includegraphics[scale=0.5]{images/octahedron_ccs.eps}
\caption{Combinatorial Configuration space for the Octahedron.}
\label{fig:OctaCCS}
\end{figure}
Figure~\ref{fig:OctaCCS} shows the octahedron combinatorial configuration space with the edges labeled with the joint transition rate $\pi_j Q_{jk} = \pi_k Q_{kj}$ for the choices $\beta = 0.8$ and $\epsilon = 0.5$.

Since our model uses the two parameters $\epsilon$ and $\beta$, it is of particular interest to examine how the choice of these parameters affects the behaviors of the Markov process.
\begin{figure}[ht]
\centering
  \includegraphics[scale=0.22]{images/octahedron_pi_Q_grid.eps}
\caption{The Affect of $\beta$ and $\epsilon$ on the transitions rates and stationary distribution of the Octahedron combinatorial configuration space.}
\label{fig:OctaPiGrid}
\end{figure}
Figure~\ref{fig:OctaPiGrid} shows how the stationary distributions (node size) and the transition rates (edge thickness) change for three choices of $\epsilon$ and three choices of $\beta$. These plots provide and effective way of visualizing which edges and pathways are more probable for different parameter choices.

One of the most interesting Markov process statistics is the expected formation time $E[\tau]$.
\begin{figure}[ht]
\centering
  \includegraphics[scale=0.6]{images/octahedron_tau.eps}
\caption{Expected formation times for the octahedron as a function of $\epsilon$ and $\beta$.}
\label{fig:OctaTau}
\end{figure}
Figure~\ref{fig:OctaTau} shows the relation between $\beta$ and the expected formation time for several choices of $\epsilon$. At $\beta = 0$, the Markov process is essentially a random walk on the graph, weighted only by the degeneracy of each transition and unaffected by the choice of $\epsilon$. On the other end, as $\beta$ gets higher and higher, each transition occurs with an increasingly small rate. This leads to a sharp increase in formations times. Interestingly, there is an intermediary range of $beta$s where a minimum of the formation time function occurs.


\section{Data Structures}
\subsection{Binary-Indexed Tree}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Data Structures/fenwick/BIT.cpp"}
\hrulefill
\subsection{2D Binary-Indexed Tree}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Data Structures/fenwick/2D_BIT.cpp"}
\hrulefill
\subsection{Range BIT}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Data Structures/fenwick/BIT_range.cpp"}
\hrulefill
\subsection{RMQ}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Data Structures/static rmq/max_index.cpp"}
\hrulefill
\subsection{Segment Tree}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Data Structures/segment tree/classic_segt.cpp"}
\hrulefill
\subsection{KD-Tree}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Data Structures/kd_tree.cpp"}
\hrulefill
\subsection{Wavelet Tree}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Data Structures/wavelet_tree.cpp"}
\hrulefill
\subsection{Lazy Treap}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Data Structures/BST/lazy_treap.cpp"}
\hrulefill
\subsection{Range LEQ query}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Data Structures/range_leq.cpp"}
\hrulefill
\subsection{Persistent Segment Tree}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Data Structures/segment tree/persistent_segtree.cpp"}
\hrulefill

\section{Flow and Matching}
\subsection{Max Flow}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Flow & Matching/dinic.cpp"}
\hrulefill
\subsection{Bipartite Matching}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Flow & Matching/hopcroft_karp.cpp"}
\hrulefill
\subsection{Min-cost Flow}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Flow & Matching/min_cost_flow.cpp"}
\hrulefill
\subsection{LP Solver}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Flow & Matching/simplex.cpp"}
\hrulefill
\subsection{Stable Marriage}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Flow & Matching/stable_marriage.cpp"}
\hrulefill

\section{Geometry}
\subsection{2D Floating-point Geometry}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Geometry/base_ld.cpp"}
\hrulefill
\subsection{3D Geometry}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Geometry/3d.cpp"}
\hrulefill
\subsection{2D Convex Hull}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Geometry/convex_hull.cpp"}
\hrulefill
\subsection{Pair of Closest Points}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Geometry/closest_points.cpp"}
\hrulefill
\subsection{Triangulation}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Geometry/triangulation.cpp"}
\hrulefill
\subsection{Delaunay Triangulation}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Geometry/delaunay.cpp"}
\hrulefill
\subsection{3D Convex Hull}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Geometry/3dcnv.cpp"}
\hrulefill

\section{Graphs}
\subsection{Bridge Edges}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Graphs/bridge.cpp"}
\hrulefill
\subsection{Dijkstra's}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Graphs/dijkstra.cpp"}
\hrulefill
\subsection{Euler Path}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Graphs/eulerpath.cpp"}
\hrulefill
\subsection{Kruskal's Algorithm}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Graphs/kruskal.cpp"}
\hrulefill
\subsection{Strongly-connected Components}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Graphs/scc.cpp"}
\hrulefill
\subsection{Topological Sorting}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Graphs/top_sort.cpp"}
\hrulefill

\section{Math}
\subsection{Floating-Point Matrix}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Math/matrix_fp.cpp"}
\hrulefill
\subsection{Finite Field Matrix}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Math/matrix_ll.cpp"}
\hrulefill
\subsection{Primes}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Math/primes.cpp"}
\hrulefill
\subsection{Formulas}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Math/formulas.cpp"}
\hrulefill

\section{Miscellaneous}
\subsection{2-SAT}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Miscellaneous/2sat.cpp"}
\hrulefill
\subsection{Convex Hull Trick}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Miscellaneous/convex_hull_trick.cpp"}
\hrulefill
\subsection{Divide and Conquer Optimization}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Miscellaneous/divide_conquer_optimization.cpp"}
\hrulefill
\subsection{Fast C++ Input}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Miscellaneous/fast_input.cpp"}
\hrulefill
\subsection{Longest Increasing Subsequence}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Miscellaneous/longest_incr_subseq.cpp"}
\hrulefill
\subsection{Java}
\raggedbottom\lstinputlisting[style=java]{"/home/jack/comp/Competitive-Programming/Miscellaneous/Main.java"}
\hrulefill
\subsection{Other}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Miscellaneous/random.cpp"}
\hrulefill

\section{Strings}
\subsection{Suffix Array}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Strings/suffix_array.cpp"}
\hrulefill
\subsection{KMP Algorithm}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Strings/kmp.cpp"}
\hrulefill
\subsection{String Hashing}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Strings/range_hash.cpp"}
\hrulefill
\subsection{Z-Algorithm}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Strings/Z_algo.cpp"}
\hrulefill

\section{Transforms}
\subsection{FFT}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Transforms/fft1.cpp"}
\hrulefill
\subsection{NTT}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Transforms/ntt.cpp"}
\hrulefill
\subsection{FHWT and Similar}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Transforms/fwht.cpp"}
\hrulefill

\section{Trees}
\subsection{Centroid Decomposition}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Trees/centroid_decomposition.cpp"}
\hrulefill
\subsection{Heavy-Light Decomposition}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Trees/hld.cpp"}
\hrulefill
\subsection{LCA}
\raggedbottom\lstinputlisting[style=cpp]{"/home/jack/comp/Competitive-Programming/Trees/lca.cpp"}
\hrulefill


\section{\toolname}\label{sec:Toolname}

Similar to few-shot learning, positive-unlabeled (PU)~learning must overcome limited labeled data.  In fact, PU~learning could be viewed as an instance of zero-shot learning since labeled negative instances are non-existent!  Given this overlap, it may be reasonably expected that ideas originally proposed for Siamese networks may also be applicable to PU~learning.

Shown in Figure~\ref{fig:Toolname}, our deep positive-unlabeled learning architecture, \textit{\toolname}, relies on a bifurcated autoencoder.  Each input ${\xBase\in\xDomain}$ is mapped by encoder~$g_e$ to (concatenated) latent space ${\zBase\in\mathbb{R}^{\abs{\zP}+\abs{\zS}+\abs{\zN}}}$. Unlike Siamese networks which map instances to~$\mathbb{R}^m$, \toolname\ is a function ${\fPU:\xDomain\mapsto\xDomain\times\xDomain}$.  Each instance in the generated tuple corresponds to an output of one of two decoders.  As described in the next section, decoder~$\fPUp$ is trained to accurately reconstruct specifically positive instances while decoder~$\fPUn$ is trained to correctly reconstruct negative instances.

Observe that the positive and negative decoder inputs --- ${\lbrack \zS~\zP \rbrack}$ and ${\lbrack \zS~\zN \rbrack}$ respectively --- are not identical.  The shared latent vector component,~$\zS$, contains the mutual information needed to reconstruct \textit{both} positive and negative instances while $\zP$ and~$\zN$ contain class-specific reconstruction information --- i.e.,~for positive and negative respectively.

\begin{figure}[t]
  \centering
  \input{tikz/deep_pu.tex}
  \caption{\toolname\ network architecture}\label{fig:Toolname}
\end{figure}

\subsection{Learning}

This subsection outlines our novel ideas for training \toolname\@.

\paragraph{Loss Function} Just as Siamese network training requires the unique triplet loss, \toolname\ similarly uses a novel loss function we call the \textit{\attLossLow}.

Let $\xBase\in\xDomain$ be a training example with label~${y\in\{\negLabel,\posLabel\}}$. Consider first the more straightforward case where ${\xBase\in\Pos}$ necessitating that ${y=\posLabel}$.  As explained above, \toolname's positive decoder output,~$\xHatP$, should be a more accurate reconstruction of~$\xBase$ than the negative decoder output,~$\xHatN$. If $\xBase$ is considered the ``anchor,'' $\xHatP$ and $\xHatN$ can serve as the triplet loss' $\exP$ and~$\exN$ respectively. The fundamental intuition outlined in Section~\ref{sec:Siamese} still applies.  Our positive \attLossLow\ is shown in Eq.~\eqref{eq:Loss:AttP}.  As with the triplet loss, $\alpha$ is a hyperparameter, and distance metric~$\distSym$'s selection application-specific with mean-squared error often adequate.

\begin{equation}\label{eq:Loss:AttP}
  \lPosAtt = \max\Big\{ \puDistDiff + \alpha, 0 \Big\}
\end{equation}

Consider next the alternative case where ${\xBase\in\Unlabel}$. $y$~is unknown so the triplet loss cannot be directly used, but it helps guide the intuition.

When ${y=\posLabel}$, then during training the distance between~$\xBase$ and~$\exP$ should decrease while the distance between~$\xBase$ and~$\exN$ should increase.  If ${y=\negLabel}$, the direction of changes of these distances is reversed.  $\xBase$~can be thought of as being \textit{attracted} to the decoder associated with its label~$y$. The unlabeled \attLossLow\ in Eq.~\ref{eq:Loss:AttU} modifies the triplet loss to incorporate this attraction.  The basic intuition behind this loss function, put colloquially, is that each ${\xBase\in\Unlabel}$ is driven to ``pick a side'' --- either the positive or negative class.

\begin{equation}\label{eq:Loss:AttU}
  \lUAtt = \max\Big\{ - \big\lvert\puDistDiff\big\rvert + \alpha, 0 \Big\}
\end{equation}

When ${\puDist{\xBase}{\xHatP} < \puDist{\xBase}{\xHatN}}$ --- i.e.,~$\xBase$ appears ``more positive'' --- Eq.~\eqref{eq:Loss:AttU} is equivalent to Eq.~\eqref{eq:Loss:AttP}, and the triplet loss' intuition applies. In the opposite case, where $\xBase$ appears ``more negative'' --- ${\puDist{\xBase}{\xHatN} < \puDist{\xBase}{\xHatP}}$ --- the absolute value inverts the intuition, meaning the loss is minimized when the distance between $\xBase$ and~$\xHatN$ is reduced and the distance between $\xBase$ and~$\xHatP$ increased.

The \attLossLow\ can introduce instability during training since an obvious minimum is to attract all unlabeled instances to one decoder and produce a maximally poor reconstruction on the other decoder.  To ensure minimum reconstruction quality, a reconstruction error term is added to both the positive and unlabeled attractive losses as shown in Eq.~\eqref{eq:Loss:PuP} and Eq.~\eqref{eq:Loss:PuU} respectively. ${\lambda\in\mathbb{R}_{{>}0}}$ is a hyperparameter.

\begin{align}
  \lPuP &= \lPosAtt + \lambda\puDist{\xBase}{\xHatP} \label{eq:Loss:PuP}\\
  \lPuU &= \lUAtt + \underbrace{\lambda\min\Big\{\puDist{\xBase}{\xHatP}, \puDist{\xBase}{\xHatN}\Big\}}_{\text{Reconstruction Quality}}\label{eq:Loss:PuU}
\end{align}

\begin{algorithm}[t]
  \caption{\toolname\ training algorithm}\label{alg:Complete}
  \input{alg/complete_alg.tex}
\end{algorithm}

\paragraph{Training Algorithm} Training is divided into three disjoint phases.  In the first phase, the encoder and negative decoder are fit to minimize the reconstruction error on~$\Unlabel$ similar to a standard, stacked autoencoder; the positive decoder is untouched during this stage.  Once $\Unlabel$'s reconstruction error has adequately converged, training stops, and all weights in the encoder are frozen except those associated exclusively with $\zP$.  This ensures that during the next training phase, the performance of the negative decoder is not degraded.

Stage~2 trains the encoder and positive decoder on~$\Pos$ similar again to a standard autoencoder.  We allow the positive encoder to train for twice as many epochs as the negative decoder.  This increases the likelihood that the positive decoder can reconstruct positive examples more accurately than the negative decoder.  Similarly, since the positive decoder has, until this point, never seen a negative training example, its reconstruction performance on negative instances should be poor.

Before starting the final phase, all networks weights are unfrozen. The encoder and both decoders are then trained on interleaved batches from $\Pos$ and~$\Unlabel$ using the loss functions in Eq.~\eqref{eq:Loss:PuP} and~\eqref{eq:Loss:PuU}.  If hyperparameter $\alpha$ is initially set too high, attraction of unlabeled examples to the positive decoder can be unstable and result in unpredictable network behavior. We address this by setting the initial $\alpha$ close to zero and linearly increasing its value after each epoch.  The previously mentioned batch interleaving also promotes stability be ensuring the performance of both decoders remains in sync.

% \begin{algorithm}[t]
%   \caption{Joint training of the positive and unlabeled decoders}\label{alg:JointTraining}
%   \input{alg/attractive_training.tex}
% \end{algorithm}

\subsection{Inference}

For unlabeled example~${\xBase\in\Unlabel}$, if $g_{p}$ yields a superior reconstruction than $g_{n}$, it can be reasonably concluded that $\xBase$ is positive labeled; otherwise, $\xBase$ is more likely negative labeled.  This intuition is the basis for \toolname's inference function shown in Eq.~\eqref{eq:PU:ClassificationFunc}.

  \begin{equation}\label{eq:PU:ClassificationFunc}
    \hat{y} = -\sign{\puDistDiff}
  \end{equation}

\noindent
In rare cases where ${\puDist{\xBase}{\xHatP}=\puDist{\xBase}{\xHatN}}$, $\xBase$ is equally likely to be either negative or positive labeled.  For simplicity, such examples are assigned a positive label.


\documentclass[twoside]{MATH77}
\usepackage[\graphtype]{mfpic}
\usepackage{multicol}
\usepackage[fleqn,reqno,centertags]{amsmath}
\begin{document}
\opengraphsfile{pl02-17}
\begmath 2.17 Fresnel Integrals

\silentfootnote{$^\copyright$1997 Calif. Inst. of Technology, \thisyear \ Math \`a la Carte, Inc.}

\subsection{Purpose}

The subprograms described in this chapter compute the Fresnel Integrals%
\begin{equation*}
\hspace{-13pt}C(x)=\int_0^x\!\!\cos \left( \frac \pi 2t^2\right) dt\quad
\text{and}\quad S(x)=\int_0^x\!\!\sin \left( \frac \pi 2t^2\right) dt,
\end{equation*}
and the associated functions%
\begin{align*}
\hspace{-13pt}f(x)&=\left[ \frac 12-S(x)\right] \cos \left(
\frac \pi 2x^2\right) -\left[\frac 12-C(x)\right] \sin \left(
\frac \pi 2x^2\right)\\
\hspace{-13pt}g(x)&=\left[ \frac 12-C(x)\right] \cos \left(
\frac \pi 2x^2\right) +\left[\frac 12-S(x)\right] \sin \left(
\frac \pi 2x^2\right)
\end{align*}
as defined by Equations 7.3.1,~7.3.2, 7.3.5 and~7.3.6 in \cite{ams55}.

\subsection{Usage}

\subsubsection{Program Prototype, Single Precision}

To compute $C(x)$ use

{\bf REAL \ SFRENC, X, Y}
$$
\fbox{{\bf Y = SFRENC(X)}}
$$
To compute $S(x)$ use

{\bf REAL \ SFRENS, X, Y}
$$
\fbox{{\bf Y = SFRENS(X)}}
$$
To compute $f(x)$ use

{\bf REAL \ SFRENF, X, Y}
$$
\fbox{{\bf Y = SFRENF(X)}}
$$
To compute $g(x)$ use

{\bf REAL \ SFRENG, X, Y}
$$
\fbox{{\bf Y = SFRENG(X)}}
$$

\subsubsection{Argument Definitions}

\begin{description}
\item[X]  \ [in] The value at which the function is to be evaluated.
\end{description}

\subsubsection{Modifications for Double Precision}

Change the REAL type statements to double precision, and change the initial
letter of the subprogram names from S to D. It is important that the
subprogram names be explicitly typed.
\vspace{10pt}

\hspace{5pt}\mbox{\input pl02-17 }

\subsection{Examples and Remarks}

See DRSFRENL and ODSFRENL for an example of the usage of this subprogram.

There are no restrictions on the range of applicability of these functions.
The accuracy of the trigonometric functions decreases, however, for large $%
|x|$. Thus evaluation of $C(x)$, $S(x)$, $f(-|x|)$ or $g(-|x|)$ for large $%
|x|$ will be less accurate than evaluation of $f(|x|)$ and $g(|x|)$ for the
same value of $x$. When formulating an application, one should when possible
use $C(x)$ and $S(x)$ when $|x|\leq 1.6$ (to achieve maximum efficiency). To
achieve maximum accuracy and efficiency use $f(x)$ and $g(x)$ when $x>1.6$,
and avoid using $x<-1.6.$

\subsection{Functional Description}

\begin{table*}
\begin{center}
\begin{tabular}{cl*{6}{r}}
& \multicolumn{1}{c}{\bf Argument} & \multicolumn{1}{c}{\bf Mean} &
\multicolumn{1}{c}{\bf Max} & \multicolumn{1}{c}{\bf Mean} &
\multicolumn{1}{c}{\bf Max} & \multicolumn{1}{c}{\bf Mean} &
\multicolumn{1}{c}{\bf Max}\\
{\bf Function} & \multicolumn{1}{c}{\bf Interval} &
\multicolumn{1}{c}{\bf ULP} & \multicolumn{1}{c}{\bf ULP} &
\multicolumn{1}{c}{\bf REL} & \multicolumn{1}{c}{\bf REL} &
\multicolumn{1}{c}{\bf ABS} & \multicolumn{1}{c}{\bf ABS}\\
$C(x)$ & [0..1.2] & 0.57 $\rho $ & 2.18 $\rho $ & 0.40 $\rho $ &
1.29 $\rho $ & 0.19 $\rho $ & 0.83 $\rho $\\
& (1.2..1.6] & 0.70 $\rho $ & 2.52 $\rho $ & 0.48 $\rho $ &
1.55 $\rho $ & 0.19 $\rho $ & 0.63 $\rho $\\
S($x)$ & [0..1.2] & 0.74 $\rho $ & 2.42 $\rho $ & 0.52 $\rho $ &
1.39 $\rho $ & 0.09 $\rho $ & 0.65 $\rho $\\
& (1.2..1.6] & 0.75 $\rho $ & 2.20 $\rho $ & 0.55 $\rho $ &
1.55 $\rho $ & 0.38 $\rho $ & 1.10 $\rho $\\
$f(x)$ & (1.6..1.9] & 0.51 $\rho $ & 1.50 $\rho $ & 0.36 $\rho $ &
1.10 $\rho $ & 0.06 $\rho $ & 0.19 $\rho $\\
& (1.9..2.4] & 0.30 $\rho $ & 0.96 $\rho $ & 0.26 $\rho $ &
0.77 $\rho $ & 0.04 $\rho $ & 0.12 $\rho $\\
& (2.4..6.0] & 0.43 $\rho $ & 1.15 $\rho $ & 0.29 $\rho $ &
0.80 $\rho $ & 0.02 $\rho $ & 0.07 $\rho $\\
& (6.0..50.0] & 0.45 $\rho $ & 1.05 $\rho $ & 0.31 $\rho $ &
0.71 $\rho $ & 0.00 $\rho $ & 0.03 $\rho $\\
& (50..1000] & 0.39 $\rho $ & 1.02 $\rho $ & 0.27 $\rho $ &
0.72 $\rho $ & 0.00 $\rho $ & 4E$-$3 $\rho $\\
$g(x)$ & (1.6..1.9] & 0.53 $\rho $ & 1.92 $\rho $ & 0.38 $\rho $ &
1.11 $\rho $ & 0.01 $\rho $ & 0.02 $\rho $\\
& (1.9..2.4] & 1.06 $\rho $ & 3.43 $\rho $ & 0.75 $\rho $ &
1.93 $\rho $ & 0.01 $\rho $ & 0.02 $\rho $\\
& (2.4..6.0] & 1.51 $\rho $ & 4.04 $\rho $ & 1.01 $\rho $ &
2.61 $\rho $ & 0.00 $\rho $ & 0.01 $\rho $\\
& (6.0..50.0] & 1.40 $\rho $ & 3.62 $\rho $ & 0.97 $\rho $ &
2.11 $\rho $ & 0.00 $\rho $ & 3E$-$4 $\rho $\\
& (50..1000] & 1.09 $\rho $ & 2.40 $\rho $ & 0.75 $\rho $ &
1.50 $\rho $ & 0.00 $\rho $ & 2E$-$7 $\rho $
\end{tabular}
\end{center}
\end{table*}

The computer approximations for these functions use Chebyshev rational
approximations developed by W. J. Cody, described in \cite{Cody:1968:CAF}. Cody
provides approximations for $C(x)$ and $S(x)$ for $|x| \leq 1.6$, and for $%
f(x)$ and $g(x)$ for $x > 1.6$. The approximations for $f(x)$ and $g(x)$ for
$x > 2.4$ have the same asymptotic form as the functions. We compute $f(x)$
and $g(x)$ from $S(x)$ and $C(x)$ when $|x| \leq 1.6$, and vice versa for $x
> 1.6$. For $x < 0$ we use $C(-x) = -C(x)$, $S(-x) = -S(x)$, $g(-x) = \cos
(\pi /2\ x^2) + \sin (\pi /2\ x^2) - g(x)$ and $f(-x) = \cos (\pi /2\ x^2) -
\sin (\pi /2\ x^2) - f(x)$.

The approximations and programming were checked by comparing the double
precision functions to an extended precision computation of $w(z)$, the
Fadeeva function described in Chapter~2.16. Testing consisted of dividing
several regions of the argument range into~200 equal-sized intervals, and
selecting a point randomly in each interval. To test $f(x)$ and $g(x)$ when $%
50 < x < 1000$ we divided the range $10^{-3} < 1/x < .02$ into~200 equal
subranges. In each interval we report the error in units of the last
position of the test value in the column headed ULP, the error relative to
the true value in the column headed REL, and the absolute error in the
column headed ABS. The quantity $\rho $ is the round off level, that is, the
difference between~1.0 and the next representable number, which is provided
by D1MACH(4) (Chapter~19.1). For IEEE arithmetic, $\rho \approx 2.22$E$-$16 in
double precision. The results are summarized above.

Cody's testing of the approximations, as described in \cite{Cody:1968:CAF},
indicates a relative accuracy in the approximations of~15 to~18 digits, so
one should not expect to achieve more accuracy simply by carrying out the
calculations using more precision, as, for example, by using double
precision on a Cray computer.

The errors in $f(x)$ and $g(x)$ decrease as $x$ increases in the range $6 <
x \leq 1000$. The approximations for $f(x)$ and $g(x)$ have the same
asymptotic form as the functions when $x > 2.4$, and therefore they become
more accurate as $x$ increases. For IEEE format double precision arithmetic,
the approximation for $f(x)$ is identical to the asymptotic expansion when $%
x > 29$, and the approximation for $g(x)$ is identical to the asymptotic
expansion when $x > 14.$

We verified correct programming of $f(x)$ and $g(x)$ for $|x| \leq 1.6$, and
for $C(x)$ and $S(x)$ for $x > 1.6$, by comparing results to values in table
7.7 in \cite{ams55}. Extensive accuracy testing would simply have validated
the trigonometric function routines.

\bibliography{math77}
\bibliographystyle{math77}

\subsection{Error Procedures and Restrictions}

There are no restrictions on the argument range for these functions; they do
not announce any errors.

\subsection{Supporting Information}

The source language is ANSI Fortran~77.

\begin{tabular}{@{\bf}l@{\hspace{5pt}}c}
\bf Entry & \hspace{.27in} {\bf Required Files}\vspace{2pt} \\
DFRENC & \hspace{.2in} AMACH, DFRENL\\
DFRENF & \hspace{.2in} AMACH, DFRENL\\
DFRENG & \hspace{.2in} AMACH, DFRENL\\
DFRENS & \hspace{.2in} AMACH, DFRENL\\
SFRENC & \hspace{.2in} AMACH, SFRENL\\
SFRENF & \hspace{.2in} AMACH, SFRENL\\
SFRENG & \hspace{.2in} AMACH, SFRENL\\
SFRENS & \hspace{.2in} AMACH, SFRENL\\
\end{tabular}

Subprograms designed and developed by W. V. Snyder, JPL, 1992.

\begcodenp

\enlargethispage*{10pt}
\lstset{language=[77]Fortran,showstringspaces=false}
\lstset{xleftmargin=.8in}
\centerline{\bf \large DRSFRENL}\vspace{-5pt}
\lstinputlisting{\codeloc{sfrenl}}

\vspace{0pt}\centerline{\bf \large ODSFRENL}\vspace{2pt}
\lstset{language={}}
\lstinputlisting{\outputloc{sfrenl}}

\closegraphsfile
\end{document}


\documentclass{article}
\begin{document}
\author{Ross Brown}
\title{Proposed Implementations/Changes}
\maketitle
\section{Evaluating}
\subsection{Current Issue}
The algorithms are running on 3 datasets at the moment for an arbitrary number of runs. They are then adjusted/modified manually to visually improve these results which is of little value.
\subsection{Solution}
Using a set of datasets (currently about 2000 datasets), $X$, portioned into training, validating, and testing subsets ($X_\mathrm{train}$, $X_\mathrm{test}$), more robust results can be produced. The idea for these subsets arises from the equivalent idea seen in machine learning.

$X_\mathrm{train}$ will be used to fit parameters in the algorithm and the $X_\mathrm{test}$ will have the fitted algorithm applied and the scoring reported. An $X_\mathrm{valid}$ is not deemed necessary at the moment.
\section{Scoring}
\subsection{Current Issues}
Simply taking the mse of the results does not fit in with the biological aspect: finding highly active compounds. The scoring thus needs to fulfil the following criteria:
\begin{itemize}
    \item Weighting to higher pXa
\end{itemize}
And would preferably meet the following:
\begin{itemize}
    \item Lightweight - would rather have computational power used on the active learning than the scoring.
    \item Independent of dataset size and distribution.
\end{itemize}
\subsection{Solutions}
\begin{itemize}
    \item Weighted mse:
          $$\sigma{}=\sum_i{w(y_i-\bar{y})^2}$$
          Where $w$ may be:
          $$w_i=y_i^\alpha$$
          It is unknown what $\alpha{}$ would be (so probably 1 according to Occam's razor).
    \item Number of `top' results to contain $a$ of the top $b$ true top values.
    \item Number of iterations needed to get either of the above below a predefined value.
\end{itemize}
Likely to choose the first solution as simple to implement with a target of 5 iterations. A validation could be used to determine the number of iterations (i.e. look at the rate of improvement and stop at a certain rate).
\end{document}