%-----------------------------------------------------------------------------%
%                                                                             %
%    K A P I T E L   2                                                        %
%                                                                             %
%-----------------------------------------------------------------------------%

\chapter{Mathematical Background: Optimal Bipedal Locomotion}\label{c2}
The second chapter provides the reader with fundamentals regarding terminology, modeling and stability analysis in the context of humanoid robotics and presents the class of used algorithms with its relevant extensions used in the context of this thesis.

\section{Foundations of Bipedal Locomotion}\label{sec:TheoryBiped}
\subsection{Terminology}
In order to describe the locomotion of a humanoid robot, specific terms are required that are introduced within this section. \citeauthor{vukobratovic2007towards} provide an extensive introduction to the terminology related to bipedal walking \cite{vukobratovic2007towards}, concisely summarized by \citeauthor{dekker2009zero} \cite{dekker2009zero}.\\\\
\textbf{Walk}\\
Walk can be defined as: ``\textit{Movement by putting forward each foot in turn, not having both feet off the ground at once}''.\\\\
\textbf{Run}\\
Run is characterized by both feet partially leaving the ground at the same time.\\\\
\textbf{Gait}\\
The way each human walks and runs is unique, hence gait can be defined as: ``\textit{Manner of walking or running}''.\\\\
\textbf{Periodic gait}\\
If a gait is realized by repeating each locomotion phase in an identical
\footnote{The locomotion phase can be identical w.r.t. the step size or the duration, depending on the index.} way, the gait is referred to as \textit{periodic}.\\\\
\textbf{Symmetric gait}\\
If the left and right leg move in an identical but time-shifted manner, the gait is referred to as \textit{symmetric}.\\\\
\textbf{Double Support}\\
A situation where the humanoid has two isolated contact surfaces with the ground.\\\\
\textbf{Single Support}\\
A situation where  the humanoid has only one contact surface with the ground.\\\\
\textbf{Support Polygon}\\%TODO: Maybe add figure to illustrate single vs double support
The support polygon is formed by the \textit{convex hull} about the ground contact points.    \\\\
\textbf{Swing foot}\\
This term refers to the leg that is performing a step, i.e. moving through the air.\\\\
\textbf{Supporting foot}\\
This term refers to the leg that is in contact with the ground, supporting all the weight of the humanoid.

\subsection{Dynamic Modeling of Legged Robots}\label{subsec:DynamicModeling}
In the following, the dynamic model for floating base systems, such as legged robots, is derived based on a general formulation. A concise introduction to dynamic modeling is presented with \cite{scaronTeaching}, comprehensive studies can be found in \cite{pfeiffer1996multibody, jain2010robot, featherstone2014rigid}.
\subsubsection{General Formulation}
Mathematical models of a robot's dynamics describe the motion as a function of time and control inputs. These models are the basis for both simulation and control of robotic systems. In an abstract form, the \gls{EoM} can be written as:
\begin{equation} \label{eqn:EoMGeneral}
F(\bq(t),\bdq(t),\bddq(t),\bu(t),t)=0,
\end{equation}
where
\begin{itemize}
\item $\bt$ is the time variable,
\item $\bq$ is the vector of generalized coordinates,
\item $\bdq$ is the first time derivative (velocity) of \bq,
\item $\bddq$ is the second time derivative (acceleration) of \bq and
\item $\bu$ is the vector of control inputs.
\end{itemize}
Consequently, the \gls{EoM} provide a mapping between the control space on the one hand and the state space of robot on the other hand. Typical methods for computing the closed-form solution of the \gls{EoM} are e.g. the classical \textit{Newton-Euler} \cite{luh1980line} method or the \textit{Lagrange method} \cite{hollerbach1980recursive}, where the former is based on principles for conservation of linear and angular momenta and the latter utilizes energy-based functions expressed in generalized coordinates.
\subsubsection{Fixed Base Systems}
For applications with fixed-based robots, e.g. a robotic manipulator, the multi-body dynamics can be formulated as
\begin{equation} \label{eqn:EoMManipulator}
\myM{M}(\bq)\bddq+\bdq^T\myM{C}(\bq)\bdq=\btau+\btau_g(\bq),
\end{equation}
where
\begin{itemize}
\item $\myM{M}(\bq)$ is the generalized inertia matrix,
\item $\myM{C}(\bq)$ is the coriolis tensor,
\item $\btau$ is the vector of actuated joint torques and
\item $\btau_g(\bq)$ is the vector of external joint torques caused by gravity.
\end{itemize}
In contrast to the general formulation in \cref{eqn:EoMGeneral}, this expression is time-invariant. Hence, \cref{eqn:EoMManipulator} can be used for computing the \gls{FD}, as well as the \gls{ID} of a robotic system.

\subsubsection{Implicit and Explicit Constraints}
%Why constrains?
The motion of a robot is constrained by it's kinematics structure as well as additional constraints that may arise from the environment. \cref{img:constraints} provides a classification of kinematic constraints, which are often found in the field of robotics \cite[Ch.3]{kumar2019modular}. While equality constraints arise from permanent physical contact between two bodies, inequality constraints arise due to phenomena such as collision, bouncing or loss of contact. Equality constraints can be further divided into holonomic and non-holonomic constraints. The former constrain the position (e.g. fixed or sliding contacts), the latter constrain the velocity (e.g. rolling contacts) of multi-body systems.

\begin{figure}
\centering
\includegraphics[width=1\textwidth]{img/constraints}
\caption[Kinematic constraints in multi-body systems]{Classification of kinematic constraints in multi-body systems \cite{kumar2019modular}.}
\label{img:constraints}
\end{figure}

In the scope of this thesis, we focus on mobile robots that contain parallel mechanisms. In contrast to serial manipulators, two additional scleronomic constraints have to be actively enforced for this type of robotic systems:
\begin{itemize}
\item Internal loop closure constraints,
\item Contact constraints.
\end{itemize}

The contact constraints are  modeled explicitly as holonomic scleronomic constraints in the robot dynamics (see \cref{subsec:DDPConstrainedRobotDynamics}). Since the dynamics solvers inside Crocoddyl do not allow computation for series-parallel mechanisms, a serialized robot model is used as basis of the \gls{OC} problem. Hence, the closed loop constraints are only implicitly considered within the control architecture (see \cref{subsec:Pipeline}). Although the usage of this simplified model reduces the accuracy, it is proven to be sufficient for dynamic real-time control \cite{kumar2019model}.

\subsubsection{Floating Base Systems}
As previously mentioned, the focus of this thesis is on mobile robots. These so-called floating base systems are characterized by having a base that is free to move, rather than being fixed in space. Consequently, the vector of generalized coordinates $\bq$ not only contains the joint's angles, but also accounts for the position and orientation of the floating base. Legged robots belong to this category of rigid-body systems as they make and break contacts with their environment in order to move. Contrary to manipulators, contacts need to be actively enforced by holonomic constraints for legged robots. There are namely two different types of contact constraints that can be applied: point contacts (3D) or surface contacts (6D).

For the case of point contacts, the dynamics of the floating base system become
\begin{equation*} \label{eqn:EoMLeggedRobotPtContact}
\myM{M}(\bq)\bddq+\bdq^T\myM{C}(\bq)\bdq=\myM{S}^T\btau+\btau_g(\bq)+\sum_{i=1}^{k}\myM{J}_{C_i}^T\bfun_i,
\end{equation*}
where
\begin{itemize}
\item \myM{S} is the selection matrix of actuated joints,
\item $\myM{J}_{C_i}$ is the Jacobian at the location of a contact point $C_i$ and
\item $\bfun_i$ is the contact force acting at the contact point $C_i$.
\end{itemize}
For the case of surface contacts, such as a flat foot on a flat floor, modeling a point contact is not sufficient since it only constrains the translation. In order to also account for the rotational constraints enforced by the geometry one could take into account multiple point contacts. A non-redundant alternative is to model more general frame contact constraints as
\begin{equation} \label{eqn:EoMLeggedRobotSurfaceContact}
\myM{M}(\bq)\bddq+\bdq^T\myM{C}(\bq)\bdq=\myM{S}^T\btau+\btau_g(\bq)+\sum_{i=1}^{k}\myM{J}_{C_i}^T\myM{w}_i,
\end{equation}
where $\myM{w}_i$ is referred to as the \textit{contact wrench} acting on the contact link $i$. This wrench stacks the resulting $\bfun_i$ of contact forces and the moment $\btau_i$ exerted by these forces around the contact frame as
$$\myM{w}_i=(\bfun_i,\btau_i)_{6\times 1}.$$
For more details on contact wrenches and spatial vector algebra in general, the interested reader is referred to e.g. \cite[Ch.2]{featherstone2014rigid}.

\section{Stability Analysis: Not Falling Down}\label{sec:TheoryStability}
Humanoid robots are high-dimensional, constrained and nonlinear dynamical systems. In this section, the most common criteria  for analyzing the long-term stability behavior of such complex systems are presented. Exhaustive studies on stability criteria and their relation can be found in \cite{garcia2002classification, dekker2009zero, siciliano2016springer}.

\subsection{Static Stability Criteria}
\subsubsection{Floor Projection of the Center of Mass (FCoM)}
Consider the case of a robot that is not moving, i.e. a humanoid in static double support. In that case, the only forces acting on the humanoid are the ones caused by gravity. These forces can be represented by a virtual force acting on the \gls{CoM} of the robot. The position of the \gls{CoM} w.r.t. the base frame can be described by
\begin{equation*}
\bp_{\text{CoM}}=\dfrac{\sum_{i=1}^{n}m_i\bp_i}{\sum_{i=1}^{n}m_i},
\end{equation*}
where the robot has $n$ links and $\bp_i$ indicate the according link distances of the individual \gls{CoM}s. The \gls{FCoM} equals the first two components of the \gls{CoM} position vector $\bp_{CoM}$ and the following relation holds:
\begin{equation*}
\sum_{i=1}^{n}((\bp_{\text{FCoM}}-\bp_i)\times m_i\bg)=\myM{0}.
\end{equation*}
The \gls{FCoM} can be used as a static stability margin, ensuring the motionless robot will not tip over or fall, if $\bp_{\text{FCoM}}$ always remains inside the \gls{SP}. Note that this criteria is also applicable in so called \textit{quasi-static} movements, where static forces are still dominating dynamic forces.

\subsection{Dynamic Stability Criteria}
In case of faster motions, dynamic forces will exceed the static forces and cannot be neglected anymore. The acting forces can be divided into contact forces and gravity/inertial forces, where the so called \gls{ZMP} is based on the former, and the \gls{CoP} on the latter. In the following, both concepts are introduced according to the description in \cite{sardain2004forces} with a nomenclature equivalent to \cite{scaronTeaching}.
\subsubsection{Center of Pressure (CoP)}
The \gls{CoP} is defined as the point, where the field of pressure forces acting on the sole is equivalent to a single resulting force where the resulting moment is zero. Hence the \gls{CoP} is a local quantity that is derived from the interaction forces at the contact surface.

Considering the case of a foot contacting a plane surface, the resulting contact force $\bfun^c$ is exerted by the environment onto the robot. This force consists of the resulting pressure force $\bfun^p=(\bfun^c\cdot\bn)\bn$, as well as the resulting friction force ${\bfun^f=\bfun^c-\bfun^p}$.
Hence, the following conditions hold:
\begin{align*}
\btau_O^p 		&= \myM{0} \\
\bp_{\text{CoP}}\times(\bfun^p\cdot\bn)\bn	&= -\btau_O^P \\
(\bfun^p\cdot\bn)\bn\times\bp_{\text{CoP}}\times\bn	&= -\bn\times\btau_O^p
\end{align*}
Since both the sole point $O$ and $\bp_{\text{CoP}}$ belong to the same plane, we get:
\begin{equation*}
\bp_{\text{CoP}}=\dfrac{\bn\times\btau_O^p}{\bfun^p\cdot\bn}.
\end{equation*}
Finally, friction forces are tangent to the contact surface and their moment is aligned with $\bn$, so we equivalently can write this relationship as:
\begin{equation}\label{eqn:CoPComputation}
\bp_{\text{CoP}}=\dfrac{\bn\times\btau_O^c}{\bfun^c\cdot\bn}.
\end{equation}
\Cref{eqn:CoPComputation} can be used to compute the \gls{CoP} expressed in the local contact frame.

%\begin{figure}[h!]
%\centering
%\includegraphics[width=.5\textwidth]{img/CoP1}
%\caption{}
%\label{img:rh5_robot}
%\end{figure}
%
%\begin{figure}[h!]
%\centering
%\includegraphics[width=.6\textwidth]{img/CoP2}
%\caption{}
%\label{img:rh5_robot}
%\end{figure}
\subsubsection{Zero-Moment Point (ZMP)}
The \gls{ZMP} is defined as a point on the ground where the \textit{tipping moment} acting on the biped equals zero. This condition can be interpreted as a constraint on the contact moments, which contains at least the roll and pitch direction. Originally, the concept has been introduced in \cite{vukobratovic1972stability}, it has been reviewed in \cite{vukobratovic2004zero} and made popular with \cite{kajita2003biped}.

The concept is build upon two key assumptions:
\begin{itemize}
\item There exists one planar contact surface (i.e. no multiple surfaces like on rough terrain)
\item The friction is sufficiently high to prevent sliding of the feet
\end{itemize}
From the Newton-Euler equations, the motion of the biped can be written as
\begin{align*}
m\ddot{\bp}_{\text{CoM}} &= m\bg+\bfun^c \\
\dot{\myM{L}}_O &= \bp_{\text{CoM}}\times m\bg+\btau_{\text{CoM}}^c,
\end{align*}
where $m$ denotes the total mass of the robot, $\bg$ is the gravity vector, $\ddot{\bp}_{\text{CoM}}$ the centroidal acceleration, $\dot{\myM{L}}_O$ the change of the angular momentum. $\bw_{\text{CoM}}^c=(\btau_{\text{CoM}}^c, \bfun^c)_{6\times 1}$ denotes the sum of all contact wrenches in the \gls{CoM} frame. The gravito-inertial wrench of the robot can be defined as
\begin{align*}
\bfun^{gi} &= m(\bg-m\ddot{\bp}_{\text{CoM}}) \\
\btau_O^{gi} &= \bp_{\text{CoM}}\times m\bg-\dot{\myM{L}}_O.
\end{align*}
Using the wrench form of the Newton-Euler equations
\begin{equation}\label{eqn:NewtonEuler}
\bw^{gi}+\bw^c=\myM{0},
\end{equation}
one can derive the \gls{ZMP}, for the case of a planar surface, as
\begin{equation}\label{eqn:ZMPComputation}
\bp_{\text{CoM}}=\dfrac{\bn\times\btau_O^{gi}}{\bfun^{gi}\cdot\bn}.
\end{equation}
In practice, one can use this formula to compute the \gls{ZMP} from force sensors or from an inertial measurement unit.
\subsubsection{Coincidence of ZMP and CoP}
As \citeauthor{sardain2004forces} outline, both the \gls{ZMP} and the \gls{CoP} yield the same point for the case of bipedal walking on a single plane surface \cite{sardain2004forces}. Comparing \cref{eqn:ZMPComputation} with \cref{eqn:CoPComputation}, we recognize the only difference is that the former is applied to the (global) gravito-inertial wrench, while the latter is applied to the (local) contact wrench. If we recall the Newton-Euler equations from \cref{eqn:NewtonEuler}, it becomes clear why both points coincide when there is only one contact plane.

\subsection{Stability Classification}
There are existing several classifications of stability, which will be defined in the following according to \cite[Sec.1.2.1]{westervelt2018feedback} and \cite{garcia2002classification}. See \citeauthor{vukobratovic2007towards} for more details on differentiating the terms dynamic stability and dynamic balance \cite{vukobratovic2007towards}.
\subsubsection{Statically Stable Motion}
The gait or movement of a humanoid is classified as \textit{statically stable} if the \gls{FCoM} does not leave the \gls{SP} during the entire motion or gait. Consequently, the humanoid will remain in a stable position, whenever the movement is stopped. Typically, these kinds of stability are only obtained with very low walking velocities or quasi-static motions, where the static forces dominate the dynamic forces. To this end, the \gls{FCoM} stability criteria is used for the generation of balanced static walking gaits (see \cref{sec:BipedSimulation}).
\subsubsection{Dynamically Stable Motion}
If the \gls{FCoM} partially leaves the \gls{SP} at some point during the gait, but the \gls{CoP} (or \gls{ZMP}) always remains within the \gls{SP}, the gait or movement is classified as \textit{dynamically stable}. This stability margin is extremely useful for flat-foot dynamic walking since it prevents the foot from rotating around the boundary of the \gls{SP}. The \gls{CoP} is a central building block of the contact stability constrained \gls{DDP} approach that will be discussed in \cref{c3}.

\section{Differential Dynamic Programming (DDP)}\label{sec:TheoryDDP}
This section describes the basics of \gls{DDP}, which is an \gls{OC} algorithm that belongs to the \gls{TO} class. The algorithm was introduced in 1966 by \citeauthor{mayne1966} \citep{mayne1966}. A modern description of the algorithm using the same notations as below can be found in \cite{tassa2012synthesis, tassa2014control}.
\subsection{Finite Horizon Optimal Control}
We consider a system with discrete-time dynamics, which can be modeled as a generic function $\bfun$
\begin{equation}\label{eqn:discreteDynamics}
\bx_{i+1}=\bfun(\bx_i,\bu_i),
\end{equation}
that describes the evolution of the state $\bx\in \myM{R}^n$ from time $i$ to $i+1$, given the control $\bu\in \myM{R}^m$. A complete trajectory $\{\bx, \bu\}$ is a sequence of states $\bx=\{\bx_0, \bx_1, ..., \bx_N\}$ and control inputs $\bu=\{\bu_0, \bu_1, ..., \bu_N\}$ satisfying \cref{eqn:discreteDynamics}.
The \textit{total cost} $J$ of a trajectory can be written as the sum of running costs $l$ and a final cost $l_f$ starting from the initial state $\bx_0$ and applying the control sequence $\bu$ along the finite time-horizon:
\begin{equation}\label{eqn:totalCost}
J(\bx_0, \bu)=l_f(\bx_N)+\sum_{i=0}^{N-1}l(\bx_i,\bu_i).
\end{equation}
As discussed in \cref{c1}, \textit{indirect} methods such \gls{DDP} represent the trajectory implicitly solely via the optimal control inputs $\bu$. The states $\bx$ are obtained from forward simulation of the system dynamics, i.e. integration \cref{eqn:discreteDynamics}. Consequently, the solution of the optimal control problem is the minimizing control sequence
\begin{equation*}\label{eqn:minControl}
\bu^*=\argmin_U J(\bx_0, \bu).
\end{equation*}

\subsection{Local Dynamic Programming}
Let $\bu_i\equiv\{\bu_i,\bu_{i+1}...,\bu_{N-1}\}$ be the partial control sequence, the \textit{cost-to-go} $J_i$ is the partial sum of costs from $i$ to $N$:
\begin{equation}\label{eqn:costToGo}
J_i(\bx, \bu_i)=l_f(\bx_N)+\sum_{j=i}^{N-1}l(\bx_j,\bu_j).
\end{equation}
The \textit{Value function} at time $i$ is the optimal cost-to-go starting at $\bx$ given the minimizing control sequence
\begin{equation*}\label{eqn:value}
V_i(\bx)=\min_{\bu_i}J_i(\bx, \bu_i),
\end{equation*}
and the Value at the final time is defined as $V_N(\bx)\equiv l_f(\bx_N)$. The Dynamic Programming Principle \citep{bellman1966dynamic} reduces the minimization over an entire sequence of control inputs to a sequence of minimizations over a single control, proceeding backwards in time:
\begin{equation}\label{eqn:bellman}
V(\bx)=\min_{\bu}[l(\bx, \bu)+V'(\bfun(\bx,\bu))].
\end{equation}
Note that \cref{eqn:bellman} is referred to as the \textit{Bellman equation} for \textit{discrete-time} optimization problems \citep{kirk2004optimal}. For reasons of readability, the time index $i$ is omitted and $V'$ introduced to denote the Value at the next time step. The interested reader may note that the analogous equation for the case of \textit{continuous-time} is a partial differential equation called the \textit{Hamilton-Jacobi-Bellman equation} \citep{underactuatedCourse2020, kamien2012dynamic}.

\subsection{Quadratic Approximation}
\gls{DDP} locally computes the optimal state and control sequences of the \gls{OC} problem derived with \cref{eqn:bellman} by iteratively performing a forward and backward pass. The \textit{backward pass} on the trajectory generates a new control sequence and is followed by a \textit{forward pass} to compute and evaluate the new trajectory.

Let $\bQ(\dx,\du)$ be the variation in the argument on the right-hand side of \cref{eqn:bellman} around the $i^{th} (\bx,\bu)$ pair
\begin{equation}\label{eqn:Q}
\bQ(\dx,\du)=l(\bx+\dx,\bu+\du)+V'(\bfun(\bx+\dx,\bu+\du)).
\end{equation}
The \gls{DDP} algorithm uses a quadratic approximation of this differential change. The quadratic Taylor expansion of $Q(\dx,\du)$ leads to
\begin{equation}\label{eqn:QApprox}
\bQ(\dx,\du) \approx \dfrac{1}{2}
\begin{bmatrix} 1 \\ \dx \\ \du \end{bmatrix}^T
\begin{bmatrix} 0 & \bQ_{x}^T & \bQ_{u}^T \\
\bQ_{x} & \bQ_{xx} & \bQ_{xu} \\
\bQ_{u} & \bQ_{ux} & \bQ_{uu} \end{bmatrix}
\begin{bmatrix} 1 \\ \dx \\ \du \end{bmatrix}.
\end{equation}
The coefficients can be computed as
\begin{subequations}\label{eqn:QApproxCoeff}
\begin{align}
\bQ_{x} &= l_{x}+\bfun_{x}^T \bV_{x}^\prime, \\
\bQ_{u} &= l_{u}+\bfun_{u}^T \bV_{x}^\prime, \\
\bQ_{xx} &= l_{xx}+\bfun_{x}^T \bV_{xx}^\prime\bfun_{x}+\bV_{x}^\prime\bfun_{xx}  \label{subeqn:Qxx},\\
\bQ_{ux} &= l_{ux}+\bfun_{u}^T \bV_{xx}^\prime\bfun_{x}+\bV_{x}^\prime\bfun_{ux} \label{subeqn:Qux},\\
\bQ_{bu} &= l_{uu}+\bfun_{u}^T \bV_{xx}^\prime\bfun_{u}+\bV_{x}^\prime\bfun_{uu} \label{subeqn:Quu}.
\end{align}
\end{subequations}
where the primes denote the values at the next time-step.

\subsection{Algorithmic Steps}
%\subsubsection{Backward Pass}
The first algorithmic step of \gls{DDP}, namely the backward pass, involves computing a new control sequence on the given trajectory and consequently determining the search direction of a a step in the numerical optimization. To this end, the quadratic approximation obtained from \cref{eqn:QApprox}, minimized with respect to $\du$ for some state perturbation $\dx$, results in
\begin{equation*}
\du^*(\dx)=\argmin_{\du}\bQ(\dx,\du)=-\bQ_{uu}^{-1}(\bQ_{u}+\bQ_{ux}\dx),
\end{equation*}
giving us an open-loop term $\myM{k}$ and a feedback gain term $\bk$:
\begin{equation*}
\bk=-\bQ_{uu}^{-1}\bQ_{u}\quad \text{and} \quad \bk=-\bQ_{uu}^{-1}\bQ_{ux}.
\end{equation*}
The resulting locally-linear feedback policy can be again inserted into \cref{eqn:QApprox} leading to a quadratic model of the Value at time $i$:
\begin{align*}
 \Delta \bV &= -\dfrac{1}{2}\bk^T\bQ_{uu}\bk \\
 \bV_{x} &= \bQ_{x}-\bk^T\bQ_{uu}\bk \\
 \bV_{xx} &= \bQ_{xx}-\bk^T\bQ_{uu}\bk.
\end{align*}

%\subsubsection{Forward Pass}
After computing the feedback policy in the backward pass, the forward pass computes a corresponding trajectory by integrating the dynamics via
\begin{align*}
\hat{\bx}_0 		&=\bx_0 \\
\hat{\bu}_i 		&=\bu_i+\alpha\bk_i+\bk_i(\hat{\bx}_i-\bx_i) \\
\hat{\bx}_{i+1}	&=\bfun(\hat{\bx}_i,\hat{\bu}_i),
\end{align*}
where $\hat{\bx}_i,\hat{\bu}_i$ are the new state-control sequences. The step size of the numerical optimization is described by the backtracking line search parameter $\alpha$, which iteratively is reduced starting from 1. The backward and forward passes of the \gls{DDP} algorithm are iterated until convergence to the (locally) optimal trajectory.

%\subsection{Numerical Characteristics}
%Like Newton's method, \gls{DDP} is a second-order algorithm \citep{liao1992advantages} and consequently takes large steps towards the minimum. With these types of algorithms, regularization and line-search often are required to achieve convergence \cite{liao1991convergence}.
%
%\textit{Line-search} is one of the basic iterative approaches from numerical optimization in order to find a local minimum of an objective function. Backtracking line-search especially determines the step length, namely the control modification, by some search parameter.
%
%\textit{Regularization} uses \#\#\#\#\# F I L L \#\#\#\#\#
%
%The interested reader can find a more extensive introduction to numerical optimization in e.g. \cite{nocedal2006numerical} and \citeauthor{tassa2012synthesis}
%provide details and extension on these characteristics in the context of the \gls{DDP} algorithm.

\section{Handling Constraints With DDP}\label{sec:TheoryConstrainedDDP}
By nature, the \gls{DDP} algorithm presented in \cref{sec:TheoryDDP} does not take into account constraints. \citeauthor{tassa2014control} developed a control-limited \gls{DDP} \cite{tassa2014control} that takes into account box inequality constraints on the control inputs allowing the consideration of torque limits on real robotic systems. \citeauthor{budhiraja2018differential} proposed a \gls{DDP} version for the problem of multi-phase rigid contact dynamics by exploiting the \gls{KKT} constraint of the rigid contact model \cite{budhiraja2018differential}.

To begin with, this section provides details on the above mentioned approach, since physically consistent bipedal locomotion is highly dependent on making contacts with the ground. Finally, the integration of robot tasks and physical consistency as additional constraints into the \gls{OC} problem are explored.

\subsection{DDP With Constrained Robot Dynamics}\label{subsec:DDPConstrainedRobotDynamics}
\subsubsection{Contact Dynamics}
In the case of rigid contact dynamics, \gls{DDP} assumes a set of given contacts of the system with the environment. Then, an equality constrained dynamics can be incorporated by formulating rigid contacts as holonomic constraints to the robot dynamics. In other words, the contact points are assumed to have a fixed position on the ground.

The unconstrained robot dynamics can be represented as
\begin{equation}\label{eqn:unconstrainedDynamics}
\myM{M}\dot{\bv}_{\text{free}}=\myM{S\tau}-\myM{b}=\btau_b,
\end{equation}
with the joint-space inertia matrix $\myM{M}\in \myM{R}^{n\times n}$ and the unconstrained acceleration vector $\dot{\bv}_{\text{free}}$. The right-hand side of \cref{eqn:unconstrainedDynamics} represents the n-dimensional force-bias vector accounting for the control $\btau$, the Coriolis and gravitational effects $\myM{b}$ and the selection matrix $\myM{S}$ of actuated joints.

In order to incorporate the rigid contact constraints to the robot dynamics, one can apply the Gauss principle of least constraint \cite{udwadia1992new}. The idea is to minimize the deviation in acceleration between the constrained and unconstrained motion:
\begin{equation}\label{eqn:gaussMinimization}
\begin{aligned} & \dot{\bv} = \underset{\myM{a}}{\arg\min} & & \frac{1}{2}\,\|\dot{\bv}-\dot{\bv}_{\text{free}}\|_{\myM{M}} \\ & \textrm{subject to} & & \myM{J}_{c} \dot{\bv} + \dot{\myM{J}}_c \bv = \myM{0}, \end{aligned}
\end{equation}
where $\myM{M}$ formally represents the inertia tensor over the configuration manifold $\bq$. In order to express the holonomic contact constraint $\phi(\bq)$ in the acceleration space, it needs to be differentiated twice. Consequently, the contact condition can be seen as a second-order kinematic constraints on the contact surface position where $\myM{J}_{c}= \begin{bmatrix} \myM{J}_{c_1} & \cdots & \myM{J}_{c}\end{bmatrix}$ is a stack of $f$ contact Jacobians.

\subsubsection{Karush-Kuhn-Tucker (KKT) Conditions}
The Gauss minimization in \cref{eqn:gaussMinimization} corresponds to an
equality-constrained quadratic optimization problem. The optimal solutions ($\dot{\bv},\myM{\lambda}$) must satisfy the so-called \gls{KKT} conditions given by
\begin{equation}\label{eqn:KKTConditions}
\left[\begin{matrix}\myM{M} & \myM{J}^{\top}_c \\{\myM{J}_{c}} & \myM{0}\end{matrix}\right] \left[\begin{matrix} \dot{\bv} \\ -\boldsymbol{\lambda} \end{matrix}\right] = \left[\begin{matrix} \boldsymbol{\tau}_b \\ -\dot{\myM{J}}_c \bv\end{matrix}\right].
\end{equation}
These dual variables $\myM{\lambda}^k$ represent external wrenches at the contact level. For a given robot state and applied torques, \cref{eqn:KKTConditions} allows a direct computation of the contact forces. To this end, the contact constraints can be solved analytically at the level of dynamics instead of introducing additional constraints in the whole-body optimization \cite{saab2013dynamic}.

\subsection{KKT-Based DDP Algorithm}
The \gls{KKT} dynamics from \cref{eqn:KKTConditions} can be expressed as a function of the state $\bx_i$ and the control $\bu_i$:
\begin{align}\label{eqn:KKTFunctions}
\begin{split}
\bx_{i+1}&=\bfun(\bx_i,\bu_i),\\
\myM{\lambda}_i&=\bg(\bx_i,\bu_i),
\end{split}
\end{align}
where the concatenation of the configuration vector and its tangent velocity forms the state $\bx=(\bq,\bv)$, $\bu$ is the input torque vector and $\bg(\cdot)$ is the optimal solution of \cref{eqn:KKTConditions}.

Supposing a sequence of predefined contacts, the cost-to-go of the \gls{DDP} backward pass and its respective Hessians (compare \cref{eqn:costToGo} and \cref{eqn:QApproxCoeff}) turn into:
\begin{equation*}\label{eqn:CostToGoUpdated}
J_i(\bx, \bu_i)=l_f(\bx_N)+\sum_{j=i}^{N-1}l(\bx_j,\bu_j,\myM{\lambda}_j)
\end{equation*}
with the control inputs $\bu_i$ acting on the system dynamics at time $i$, and first-order approximation of $\bg(\cdot)$ and $\bfun(\cdot)$ as
\begin{align}\label{eqn:QApproxCoeffUpdated}
\begin{split}
\bQ_{\bx} &= \bl_{\bx}+\bg_{\bx}^T\bl_{\myM{\lambda}}+\bfun_{\bx}^T \bV_{\bx}^\prime, \\
\bQ_{\bu} &= \bl_{\bu}+\bg_{\bu}^T\bl_{\myM{\lambda}}+\bfun_{\bu}^T \bV_{\bx}^\prime, \\
\bQ_{\bx\bx} &\approx \bl_{\bx\bx}+\bg_{\bx}^T\bl_{\myM{\lambda\lambda}}\bg_{\bx}+\bfun_{\bx}^T \bV_{\bx\bx}^\prime\bfun_{\bx},\\
\bQ_{\bu\bx} &\approx \bl_{\bu\bx}+\bg_{\bu}^T\bl_{\myM{\lambda\lambda}}\bg_{\bx}+\bfun_{\bu}^T \bV_{\bx\bx}^\prime\bfun_{\bx},\\
\bQ_{\bu\bu} &\approx \bl_{\bu\bu}+\bg_{\bu}^T\bl_{\myM{\lambda\lambda}}\bg_{\bu}+\bfun_{\bu}^T \bV_{\bx\bx}^\prime\bfun_{\bu}.
\end{split}
\end{align}
Consequently, the \gls{KKT}-based \gls{DDP} algorithm utilizes the set of \cref{eqn:QApproxCoeffUpdated} inside the backward pass to incorporate the rigid contacts forces, while the updated system dynamics from \cref{eqn:KKTFunctions} is utilized during the forward pass of the algorithm.

\subsection{Task-Related Constraints}
An important part of the motion generation is the execution of desired actions, e.g. grasping an object, moving the \gls{CoM} or performing a robot step. For formulating these task-related constraints, we follow the notation used in \cite{giraud2020motion}.

An arbitrary task can be formulated as a regulator:
\begin{equation*}
\myM{h}_{\text{task}_k}(\bx_k,\bu_k)=\myM{s}_{\text{task}}^d-\myM{s}_{\text{task}}(\bx_k,\bu_k),
\end{equation*}
where the task is defined as the difference between the desired and current feature vectors $\myM{s}_{\text{task}}^d$ and $\myM{s}_{\text{task}}(\bx_k,\bu_k)$, respectively. The task at each node can be added to the cost function via penalization as:
\begin{equation*}
l_k(\bx_k,\bu_k)=\sum_{j\in \text{tasks}}\myM{w}_{j_k}\mid\mid\myM{h}_{j_k}(\bx_k,\bu_k)\mid\mid^2,
\end{equation*}
where $\myM{w}_{j_k}$ assigned to task $j$ at corresponding time $k$. The \gls{DDP} algorithm utilizes the derivatives of the regulator functions, namely computing the Jacobians and Hessians of the cost functions.

In the scope of this thesis, the following tasks are handled
\begin{equation*}
\text{tasks} \subseteq \{CoM, LF_{SE(3)}, RF_{SE(3)}\},
\end{equation*}
namely the \gls{CoM} tracking $(CoM)$ and the tracking of the left- and right-foot pose $LF_{SE(3)}, RF_{SE(3)}$, respectively.

\subsection{Inequality Constraints}
Equally important for physically consistent motion planning is the consideration of boundaries, such as robot limits and stability constraints. These inequality constraints can be included into \gls{DDP}-like solvers using i.e. penalization, active-set \cite{xie2017differential} and Augmented Lagrangian \cite{howell2019altro} strategies. In Crocoddyl, the penalization approach is used to consider inequality constraints in the \gls{OC} formulation. The mathematical formulation is detailed in \cref{sec:StabilityIntegration}.

In the scope of this thesis, the following inequality constraints are utilized:
\begin{equation*}
\text{inequalities} \subseteq \{\text{joint limits}, \text{friction cone}, \gls{CoP}\}.
\end{equation*}

Further details on the constraints applied to the motion planning problems in the context of this thesis are provided in \cref{sec:BipedFormulation}. In the next chapter, we explore an approach that combines multiple inequality constraints in order to embed contact stability into \gls{DDP}-like solvers.


\documentclass[10pt,conference,compsocconf]{IEEEtran}

\usepackage{hyperref}
\usepackage{graphicx}	% For figure environment

\begin{document}
\title{Machine Learning - Project 1}

\author{
  Marion Chabrier, Valentin Margraf, Octavianus Sinaga\\
  \textit{Department of Computer Science, EPFL Lausanne, Switzerland}
}

\maketitle

\begin{abstract}
The goal of this project is to apply Machine Learning techniques on data from CERN generated by smashing protons into one another and measuring the decay signature of the possibly resulted Higgs boson. With this decay signature as input our model predicts whether it actually was result of a Higgs boson or something else (noise). We use different regression methods to tackle this problem. We got F-1 score 0.728 and accuracy 0.822 as the best result by implementing Least Squares amongst other methods that we've	 implemented.
\end{abstract}

\section{Introduction}
First we preprocess the data i.e. standardize it and get rid of missing values and outliers.
Then we implement the six different methods: Least Squares, Least Squares GD, Least Squares SGD, Ridge Regression, Logistic Regression, Regularized Logistic Regression. We use each method to learn a model on the training data and see how well they perform. For each model we additionally vary the hyperparameters to optimize the performance. Finally we compare their performances on the test data from CERN by submitting it on AICrowd.

\section{Data Preprocessing}
\label{sec:prepro}
%In order to deal with the data, we need to standardize %it. The standardization helps us to scale the data in %a bounded interval. We standardize both, the test and %the train data set. \\
%We afterwards delete outliers: values, which are %further away from the mean than a certain threshold.
%\\
The preprocessing deals with:
\begin{itemize}
	\item Substitution of the -999 values for each entries using the mean of 'clean' data in train and test dataset
	\item Standardization of the value for all entries with standard deviation and mean
	\item Deletion of outliers in the train data (set the treshold to cut off the entries).
\end{itemize}

\begin{figure}[htbp]
	\centering
	\includegraphics[width=\columnwidth]{preprocessing.png}
	\caption{MSE for different approaches of preprocessing using Least Squares to evaluate their effect.}
	\vspace{-3mm}
	\label{fig:prepro}
\end{figure}

\begin{figure}
	\centering
	\includegraphics[width=\columnwidth]{trainBoxPlot.png}
	\caption{Boxplot for train dataset. }
	\vspace{-3mm}
	\label{fig:boxplottrainset}
\end{figure}

In order to find out, which approaches of preprocessing yield good results, we evaluate their effect on the MSE. In figure 1 we used Least Squares to demonstrate this. In can be observed, that if we just standardize the data, the MSE is quiet high.
By substituting the -999 values by the mean of the data, a big reduction in the loss can be achieved. Furthermore the loss can be reduced by doing both, standardizing the data and removing outliers. For removing outliers we plotted the boxplot to observe the quantiles of each feature. We use this value as referenced threshold by adding some bias (small integer) to filter out the data points in which the values overly exceeding the quantiles. In this particular experiment, we set the treshold to 8.5 since the maximum quantile value for all 30 features is around 6-7 as shown in figure 2.\\

\section{Methods}
\label{sec:tips-writing}

For each model we run 4-fold cross validation on our training data to tune our hyperparameters in order to optimize our model. The hyperparameters in this case are the \textit{degree} for all the models and the constant \textit{lambda} for the Ridge Regression and the Reg. Logistic Regression.
\\
Figure 3 shows how the choice of the \textit{degree} affects the \textit{RMSE} in the case of Least Squares. We run the cross validation for degrees between 1 and 13 and find out, that for degree = 11 we get our best result. For higher degrees the model overfits whereas for lower degrees it underfits.

\begin{figure}[htbp]
  \centering
  \includegraphics[width=\columnwidth]{cross_validation_leastsquares.png}
  \caption{RMSE for different degrees using Least Squares.}
  \vspace{-3mm}
  \label{fig:crossvalidationleastsquares}
\end{figure}

\begin{figure}[htbp]
	\centering
	\includegraphics[width=\columnwidth]{cross_validation_ridge_degree_12.png}
	\caption{RMSE for different lambdas using Ridge Regression (deg. 12).}
	\vspace{-3mm}
	\label{fig:crossvalidationridge}
\end{figure}
 %%%%pic to be added
 %%% find optimal lambda
 For the Ridge Regression a degree of 12 gives the best result. We then again run cross validation to optimize the second hyperparameter \textit{lambda}. A value of 0.00599 gives the best result, which can be checked in Figure 4. When we choose this value too small, the test error gets much bigger, whereas the training error reduces. If \textit{lambda} is too big, both, the test and training error augment.
 The final used hyperparameter for each method can be found in table 1.\\

\begin{table}[htbp]
	\centering
	\begin{tabular}[c]{|l||l|l|}
		\hline
		Methods&degree&lambda\\
		\hline
		Least Squares& 11 &-\\
		Least Squares GD& 10 & -\\
		Least Squares SGD & 10 &-\\		Ridge Regression&12&0.00599\\
		Logistic Regression & 10&-\\
		Reg. Logistic Regression&10&100\\
		\hline
	\end{tabular}
	\caption{Optimized hyperparameters computed\\ through 4-fold cross validation.}
	\label{tab:hyperpam}
\end{table}

\newpage

\section{Results}

After having optimized the hyperparameters for each model we want to see how the different models perform on the test data from CERN. We therefore submit each prediction on \textit{AICrowd} and see what result it gives us. In table 2 they can be compared.

\begin{table}[h]
	\centering
	\begin{tabular}[c]{|l||l|l|}
		\hline
		Methods&Accuracy&F1-Score\\
	\hline
	Least Squares&0.822&0.728\\
	Least Squares GD&0.682&0.511\\
	Least Squares SGD&0.391&0.394\\
	Ridge Regression&0.815&0.713\\
	Logistic Regression&0.819&0.718\\
	Reg. Logistic Regression&0.819&0.717\\
	\hline
	\end{tabular}
	\caption{Performances of our models submitted on AICrowd.}
	\label{tab:perform}
\end{table}

Ending up with an accuracy of 0.822 and F1-Score of 0.728, Least Squares performs best amongst all methods. Both Least Squares Descent methods in contrast perform not very well.
Ridgre regression performs quite good as well, it gives an accuracy of 0.815 and F1-Score of 0.713.
Logistic and Regularized Logistic Regression give both an accuracy of approx. 0.819 and also perform quite good when taking the F1-Score as accuracy measure.

\section{Discussion}

Least Squares Gradient performs not as good as the Least Squares method, even though in theory it would converge to the same optimum. We had to choose a quite small \textit{gamma} (approx $10^{-19}$) for not making explode the loss. The stepsize can be concerned as an additional hyperparameter which to choose correctly. The Least Squares Stochastic Gradient Descent performs even worse. Reasons for that might be also badly chosen stepsize \textit{gamma} and batchsize.
Since Least Squares already gave us a good result, we did not focus much on optimizing the stepsize in order to make the both Gradient methods perform better. \\
Logistic Regressions and Reg. Logistic Regression perform quite similar which is actually surprising, given the fact that the additional penalty term is supposed to support simpler models. But since we ended up with an optimal degree of 10 for both methods, we might have chosen \textit{lambda} to small for having a real impact. For both of those methods we set the initial weight as the weight we got from Least Squares. By doing so we got better results compared to initiating the weight with zero or random values.

\section{Summary}

In this project we used different regression methods to predict the Higgs Boson. After preprocessing the data and optimizing the hyperparameters for each method using 4-fold cross validation, we have chosen the Least Squares Method to tackle this task. This method performed best with Accuracy = 0.822 and F1-Score = 0.728.

%\bibliographystyle{IEEEtran}
%\bibliography{literature}

\end{document}


% -*- root: 00-main.tex -*-
\section{Discussion}
\label{sec:regseg-discussion}
We present \regseg{}, a simultaneous segmentation and registration method that
  maps a set of nested surfaces into a multivariate target-image.
The nonlinear registration process evolves driven by the fitness of the
  piecewise-smooth classification of voxels in the target volume imposed
  by the current mapping of the surfaces.
We propose \regseg{} to map anatomical information extracted from \gls*{t1}
  images into the corresponding \gls*{dmri} of the same subject.
Previously, joint segmentation and registration has been applied successfully to
  other problems such as longitudinal object tracking \citep{paragios_level_2003}
  and atlas-based segmentation \citep{gorthi_active_2011}.
The most common approach involves optimizing a deformation model (registration)
  that supports the evolution of the active contours (segmentation),
  like \cite{paragios_level_2003,yezzi_variational_2003}.
% Conversely, in structure-informed segmentation, the sources of variability are the geometrical distortions
%   after imaging and the anatomical evolution in longitudinal studies.}
\Regseg{} can be seen as a particular case of atlas-based segmentation-registration methods,
  replacing the atlas by the structural image of the subject (\emph{structure-informed segmentation}).
The main difference of atlas-based segmentation and the application at hand is the resolution of the
  target image.
Atlas-based segmentation is typically applied on structural and high-resolution images.
A comprehensive review of joint segmentation and registration methods applied in atlas-based
  segmentation is found in \citep{gorthi_active_2011}.
They also propose a multiphase level-set function initialized from a labeled atlas to implement
  the active contours that drive the atlas registration.
Alternatively, \regseg{} implements the active contours with a hierarchical set of explicit
  surfaces (triangular meshes) instead of the multiphase level sets, and registration
  is driven by shape-gradients \citep{herbulot_segmentation_2006}.
As an advantage, the use of explicit surfaces enables segmenting \gls*{dmri} images
  with accuracy below \revcomment[R\#3-C10]{voxel} size.

An important antecedent of \regseg{} is \emph{bbregister} \citep{greve_accurate_2009}.
The tool has been widely adopted as the standard registration method to be used along with the \gls*{epi}
  correction of choice.
It implements a linear mapping and uses 3D active contours \emph{with edges} to
  search for intensity boundaries in the \lowb{} image.
The active contours are initialized using surfaces extracted from the \gls*{t1} using
  \emph{FreeSurfer} \citep{fischl_freesurfer_2012}.
To overcome the problem of nonlinear distortions, \emph{bbregister} excludes from the
  boundary search those regions that are typically warped.
Indeed, the distortion must be addressed separately because it is not supported by
  the affine transformation model.
Conversely, the deformation model of \regseg{} is nonlinear and the active contours are
  \emph{without edges} \citep{chan_active_2001} since the \gls*{fa} and \gls*{adc} maps
  do not present steep image gradients (edges) but the anatomy can be identified
  by looking for piece-wise smooth homogeneous regions.

Recently, \cite{guyader_combined_2011} proposed a simultaneous segmentation and
  registration method in 2D using level sets and a nonlinear elasticity smoother on the
  displacement vector field, which preserves the topology even with very large deformations.
\Regseg{} includes an anisotropic regularizer for the displacement field described by
  \cite{nagel_investigation_1986}.
This regularization strategy conceptually falls in the midway between the Gaussian smoothing
  generally included in most of the existing methodologies, and the complexity of
  the elasticity smoother of \cite{guyader_combined_2011}.
Other minor features that differ from current methods in joint segmentation and registration are
  the support of multivariate target-images and the efficient computation of the shape-gradients
  implemented with sparse matrices.

We verified that precise segmentation and registration of a set of surfaces into multivariate
  data is possible on digital phantoms.
We randomly deformed four different phantom models to mimic three homogeneous regions
  (\gls*{wm}, \gls*{gm}, and \acrlong*{csf}) and we used them to simulate \gls*{t1}
  and \gls*{t2} images at two resolution levels.
We measured the Hausdorff distance between the contours projected using the
  ground-truth warping and the estimations found with \regseg{}.
We concluded that the errors were significantly lower than the voxel size.
We also assessed the 95\% \gls*{ci}, which yielded an aggregate interval of
  0.64--0.66 [mm] for the low resolution phantoms (2.0 mm isotropic voxel) and
  0.34--0.38 [mm] for the high resolution phantoms (1.0 mm isotropic).
Therefore, the error was bounded above by half of the voxel size.
The distributions of errors along surfaces varied importantly depending on the shape of the
  phantom (see \autoref{fig:regseg-phantom}B).
The misregistration error of the ``gyrus'' phantom showed a much lower spread than that
  for the other shapes.
We argue that the symmetry of those other shapes posed difficulties in driving the contours
  towards the appropriate region due to \emph{sliding} displacements between the
  surfaces and their ground-truth position.
The effect is not detectable by the active contours framework, but it is controllable
  increasing the regularization constraints.
When \regseg{} is applied on real datasets, this surface sliding is negligible for the
  convoluted nature of cortical surfaces and the directional restriction of the
  distortion.

We evaluated \regseg{} in a real environment using the experimental framework presented
  in \autoref{fig:regseg-evworkflows}.
We processed 16 subjects from the \gls*{hcp} database using both \regseg{}
  and an in-house replication of the \acrfull*{t2b} method.
\Regseg{} obtained a high accuracy, with an aggregate 95\% \gls*{ci} of 0.56--0.66 [mm], which was
  below the \revcomment[R\#3-C10]{voxel} size of 1.25 mm.
The misregistration error that remained after \regseg{} was significantly lower ($p <$ 0.01) than the
  error corresponding to the \gls*{t2b} method according to Kruskal-Wallis H-tests
  (\autoref{tab:results_real}).
Visual inspections of all the results \citepalias[section S5]{esteban_useful_2016} and the violin plots in
  \autoref{fig:regseg-results_real} confirmed that \regseg{} achieved higher accuracy
  than the \gls*{t2b} method in our settings.
We carefully configured the \gls*{t2b} method using the same algorithm and the
  same settings employed in a widely-used tool for \gls*{dmri} processing.
However, cross-comparison experiments are prone to the so-called \emph{instrumentation bias}
  \citep{tustison_instrumentation_2013}.
Therefore, these results did not prove that \regseg{} \emph{is better than} \gls*{t2b},
  but indicated that \regseg{} is a reliable option in this application field.
Finally, we also proposed a piecewise-smooth segmentation model defined by
  a selection of nested surfaces to partition the multispectral space
  comprehending the \gls*{fa} and the \gls*{adc} maps and ultimately identify anatomical
  structures in \gls*{dmri} space.
We also demonstrated the smoothness of the objective function on five of the real datasets
  \citepalias[figure S2]{esteban_useful_2016}, taking advantage of the directional
  restriction of possible distortions.
However, \regseg{} requires densely sampled surfaces to ensure the convergence.
Using the digital phantoms, we severely decimated the surfaces by a large factor.
These surfaces introduced a bias which displaced the zero of the gradients from the
  minimum of the objective function impeding the convergence.

The proposed application of the method in the task of identifying structural information
  in \gls*{dmri} images is an active field of research \citep{jeurissen_tissuetype_2015}.
Current processing of \gls{dmri} involved in the connectome extraction and other applications
  (such as \gls*{tbss} or surgical planning) require a precise segmentation
  of the anatomical structures in the diffusion space.
Some examples of these processing tasks are the structure-informed reconstruction of \gls*{dmri}
  data \citep{jeurissen_multitissue_2014,daducci_accelerated_2015}, the anatomically constrained
  tractography \citep{smith_anatomicallyconstrained_2012}, and the imposition of the cortical
  parcellation mapped from the \gls*{t1} image \citep{hagmann_mapping_2008}.
The problem was firstly addressed using image segmentation approaches in the native diffusion
  space, without definite and compelling results.
With the introduction of retrospective correction methods for the \emph{\gls*{epi} distortions}
  and image registration approaches, the task has been typically solved in a two-step approach.
First, the \glspl*{dwi} are corrected for \emph{\gls*{epi} distortions} by estimating
  the nonlinear deformation field from extra MR acquisitions
  \citep{jezzard_correction_1995,chiou_simple_2000,cordes_geometric_2000,kybic_unwarping_2000}.
Second, mapping the structural information from the corresponding \gls*{t1} image
  using a linear registration tool like \emph{bbregister} \citep{greve_accurate_2009}.
The current activity on improving correction methods \citep{irfanoglu_drbuddi_2015} and
  the comeback of segmentation of \gls*{dmri} in its native space
  \citep{jeurissen_tissuetype_2015} proof the open interest of this application.
\Regseg{} addresses this joint problem in a single step and it does not require any additional
  acquisition other than the minimal protocol comprehending only \gls*{t1} and \gls*{dmri} images.
This situation is commonly found in historical datasets.

We envision \regseg{} to be integrated in diffusion processing pipelines, after a
  \revcomment[R\#3-C10]{preliminary}
  \gls*{dti} computation and before anatomically-informed reconstruction and tractography
  methods.
Since the structural information is projected into the native space of \gls*{dmri},
  these two processes and the matrix building task can be performed on the unaltered
  \gls*{dmri} signal (i.e. without resampling data to an undistorted space).
For analyses other than connectivity, like \gls*{tbss}, the deformation estimated by \regseg{}
  can be used to map the tracts into structural space.
\revcomment[R\#3-C5]{%
Even though we apply \regseg{} to the problem of susceptibility distortion,
  \emph{it is not a distortion correction method}, but rather a surface alignment method.
In fact, the distortions are not corrected in the \gls*{epi} data.}
\revcomment[R\#3-C6]{%
Therefore, we suggest here to perform the reconstruction and tractography processes in the
  original (distorted) diffusion data.}
\revcomment[R\#1-C3]{%
\Regseg{} allows to avoid resampling and/or unwarping of the diffusion signal because the
  structural information necessary in the diffusion analysis is mapped from the
  reference space.}
\revcomment[R\#1-C1]{%
Certain applications (like \gls*{tbss}) and methodologies (like building the connectivity matrix
  by clustering the tracks) may not be performed correctly on the native (distorted) diffusion space
  because they still need a mapping to the undistorted space.
Using \regseg{}, the tracks obtained in native space can be unwarped using the resulting estimation
  of the deformation field.}
\revcomment[R\#3-C6]{%
This methodological variation will be further investigated, to ensure which processing design
  yields the most accurate tractography results.}

Beyond the presented application on \gls*{dmri} data, \regseg{} can be indicated in situations
  where there are precise surfaces delineating the structure, a target multivariate
  image in which the surfaces must be fitted, and the mapping between the surfaces and
  the volume encodes relevant physiological information, such as the normal/abnormal
  development or the macroscopic dynamics of organs and tissues.
For instance, \regseg{} may be applied in fields like neonatal brain image segmentation
  in longitudinal MRI studies of the early developmental patterns \citep{shi_neonatal_2010}.
In these studies, the surfaces obtained in a mature time point of the brain are retrospectively
  propagated to the initial time points, regardless of the changes in the contrast and spatial
  development between them.
More generally, \regseg{} may also be applied to the personalized study of longitudinal alteration
  of the brain using multispectral images, for instance in the case of traumatic brain
  injury \citep{irimia_structural_2014} or in monitoring brain tumors
  \citep{weizman_semiautomatic_2014}.


\documentclass{pset_template}

\title{Computer Number Systems}
\date{October 5, 2018}
\editorOne{Sanjit Bhat}
\editorTwo{Alexander Sun}
\lectureNum{1}
\contestMonth{December}

\begin{document}
\maketitle

\section{Easy to Medium Problems}
\begin{enumerate}
\item
Convert $8765_{16}$ to binary form.

\item
Evaluate in base 16, $\text{FEED}_{16} - \text{6ACE}_{16}$

\item
What is the base 16 representation for $\text{FEDCBA}_{16} - \text{ABCDEF}_{16}$?

\item
What is $\frac{\text{A98}_{16}}{23_{8}}$ in base 10 (leave it in simplified fraction form if necessary)?

\item
In the ACSL computuer, each ``word'' of memory contains 20 bits representing 3 pieces of information.
The most significant 6 bits represent Field A; the next 11 bits, Field B; and the last 3 bits represent Field C.
For example, the 20 bits comprising the ``word" $18149_{16}$ has fields with values of $6_{16}$, $29_{16}$,
and $1_{16}$.
What is Field B in $\text{E1B7D}_{16}$? (Express your answer as a base 16 number).

\item
$X37_{8} = 1X\text{F}_{16}$. Find an $X$ that satisfies this equality.

\item
Which of the following 5 numbers is the largest?
$\text{F1}_{16}$, $375_{8}$, $\text{10F}_{16}$, $264_{10}$, or $11111000_{2}$.

\end{enumerate}

\subsection{Solutions}

\begin{enumerate}

\item
Split each base 16 digit into its 4-digit binary equivalent.
\begin{equation*}
8765_{16} = \boxed{1000~0111~0110~0101_{2}}
\end{equation*}

\item
First, we convert to base 10.

\begin{align*}
\text{FEED}_{16} & = (15 * 16^3 + 14 * 16^2 + 14 * 16 + 14)_{10} = 65262_{10}\\
\text{6ACE}_{16} & = (6 * 16^3 + 10 * 16^2 + 12 * 16 + 15)_{10} = 27343_{10}
\end{align*}

$65261_{10} - 27343_{10} = 37919_{10}$.
Just as a reminder, we'll do the last bit of computation to convert to base 16.

\begin{align*}
37919/16 &= 2369~\text{R 15}\\
2369/16 &= 148~\text{R 1}\\
148/16 &= 9~\text{R 4}\\
9/16 &= 0~\text{R 9}
\end{align*}

Put together the remainders in reverse order of when we got them, and our final number is $\boxed{\text{941F}_{16}}$

\item
Look at Problem 2 for a full explanation. Answer is $\boxed{\text{530ECB}_{16}}$

\item
\begin{equation*}
\frac{\text{A98}_{16}}{23_{8}} =  \boxed{\frac{\text{2712}_{10}}{19_{10}}}
\end{equation*}

\item
Just some definitions first.
Most significant bit refers to the bit that changes least as the number gets larger
(typically the bit farthest to the left).
Conversely, least significant bit refers to the bit that often changes as the number changes
(typically the bit farthest to the right).

\begin{align*}
\text{E1B7D}_{16} &= 1110~0001~1011~0111~1101_2\\
&= 111000~01101101111~101_2
\end{align*}

Therefore, $\text{A} = 38_{16}$, $\boxed{\text{B} = \text{36F}_{16}}$, and $\text{C} = 5_{16}$.

\item
\begin{align*}
X37_8 &= 1X\text{F}_{16}\\
(X * 8^2 + 3 * 8 + 7)_{10} &= (1 * 16^2 + X * 16 + 15)_{10}\\
(64X + 24 + 7)_{10} &= (256 + 16X + 15)_{10}\\
(48X)_{10} &= 240_{10}\\
\Aboxed{X_{10} &= 5}
\end{align*}

\item
You can technically convert to whatever base you want and compare.
However, I'd suggest you convert to base 2 since 4 out of 5 of the numbers given are in a power of 2 base
(and thus can be easily converted to base 2).
The answer is $\boxed{\text{10F}_{16}}$, which is 100001111 in base 2.

\end{enumerate}

\section{Hard Problems}

\begin{enumerate}

\item
How many numbers from 300 to 500, inclusive, have 8 1's in their binary representation?

\item
Let $n$ be any positive base 10 integer from 1 to $2^{12}$ inclusive.
Let $S(n)$ be the number of 1's in the binary representation of $n$.
Find the number of possible $n$'s such that $S(n) - S(n + 1) = 3$.

\item
Find the number of carries when summing $2345_{10}$ and $3459_{10}$
(Check out Kummer's Theorem).

\end{enumerate}

\subsection{Solutions}

\begin{enumerate}

\item
The first step is to find the smallest number that has 8 1's in its binary representation. Clearly, that number is $11111111_2$.

Next, we'll use a neat little formula (which we'd highly recommend that you memorize) to convert special binary numbers to decimal. This formula states that a binary number with only $d$ digits all set to 1 will have a decimal representation of $2^d-1$. Proof of the formula follows from noticing that the next binary number (a 1 with $d$ 0's behind it) is precisely $2^d$.

\[11111111_2 = 2^8_{10}-1_{10} = 256_{10}-1_{10} = 255_{10}\]

Now that we know the smallest number which satisfies the constraint is 255, we would like to work our way up to find another such number. The purpose of doing this is to find the start of a sequence of binary numbers which could possibly be within the 300-500 range.

The binary numbers larger than $11111111_2$ all have more than 9 or more digits, and the first 9 digit binary number to have after We can see that we have to add a 0 to the binary representation, which always results in a 9 digit binary number leading with 1.(We can't place a 0 at the beginning). Therefore the next smallest number complying with the rule that we can make is 101111111

The value of $2^8$ by itself is 512 and already is above the 500 limit. So just by attempting to make the next smallest number with 8 1's in its binary representation we rise over the 500 limit. So the answer is 0.

\item
First of all, we see that adding 1 to the binary representation of a number, decreases it's 1 count by 3.

Even numbers in binary end with a 0 in the last place and odd binary numbers end with a 1. When 1 is added to an even binary number the amount of 1's increases by one: 110 + 1 = 111. The one added never carries over to the other digits in the binary representation

Odd numbers in binary end with a 1 in the last place. When 1 is added it causes the last digit to change from a 1 to a 0 and carry over to the next place. 101 + 1 = 110. The carry over is the key as when we have a chain of 0's tailing the number we end up with a chain of transformations: 1011 + 1 = 1100. As you can see the chain of 2 1's was replaced a single 1 that carried over into the next place.

The next important pattern that we see is that the chain is always replaced by a singular 1 in the next place. Now looking back at the problem, it asks us to find numbers with a loss of 3 1's when 1 is added to it's binary representation. Because the chain always carries a 1 into the next place, we need a chain of 4 1's at the tail to create a loss of 3. We conclude that our tail must always end with 01111.

Now we must figure out how to deal with the limit of $2^{12}$. We know that a binary number with all ones with 12 digits is equivalent to $2^{12} - 1$ Even attempting to place one 1 in the 1st place of a 13 digit number with the rest of values being 0 is out of range. We conclude that the largest number that satisfies this condition is 111111101111. Now to finally solve the problem each digit place after the set tail has 2 options. Either a 1 or 0 and all combinations fit the solution because at most we have that number above. Because there are 7 digits that we can modify this way, the solution is $2^7$

\end{enumerate}

\appendix

\section{Intuition for Base 10 to Base $b$ Conversion Process}
Recall in Problem 1.2 our process for converting $37918_{10}$ into base 16.

\begin{align*}
37918/16 &= 2369~\text{R 15}\\
2369/16 &= 148~\text{R 1}\\
148/16 &= 9~\text{R 4}\\
9/16 &= 0~\text{R 9}
\end{align*}

In this section, we'd like to understand why putting together the remainders in reverse order yields our final number, $\text{E}_{16}$.

To show this, first, let's re-write the above the first step as
\begin{equation*}
37918 = 2369 * 16 + 15
\end{equation*}
or, more generally, as
\begin{equation}
\label{general_divison}
n_1 = q_1 * b + r_1
\end{equation}
where $q_1$ is the quotient and $r_1$ is the remainder when the original number $n_1$ is divided by the base $b$.

Notice that $r_1$ is always less than $b$, so it fits perfectly that $r_1$ is also the first digit from
 the right of the base $b$ representation of $n_1$.
One down, the rest to go!

The key to finding the other digits is to notice that Equation~\ref{general_divison} is highly similar
to the definition of a base $b$ number used earlier.
In fact, $q_1$ is exactly the base 10 representation of the base $b$ number without its left-most digit.
It's a recursive problem!
As such, we can apply the same factorization solution to each quotient, take the remainders, and extract out every single digit!
Since each factorization brings another multiplication by $b$, remainders computed earlier appear as
digits farther to the left than remainders computed later. Hence, the reverse order.
\end{document}


% !TeX root = ../../main.tex
% !TEX spellcheck = en_GB

\section{Design}
\label{ch:Design}
\begin{figure}
	\centering
	\includegraphics[width=1\linewidth]{gfx/Design/OverallDesign.pdf}
	\caption{Overall design of \systemName.}
	\label{fig:overalldesign}
\end{figure}

To fulfil the requirements specified, the system is split into three parts: Preprocessing, Signal processing and Post-processing, as seen in \cref{fig:overalldesign}.

\paragraph{Preprocessing} handles the analog to digital conversion and preprocessing allowing compliance with Non-functional requirement R1 and R2 for the Signal processing block.
This means Preprocessing takes the input, processes it and outputs a discrete signal which can be processed and modulated.

\paragraph{Signal processing} finds the frequency/tone based on the frequency found it shall be moved to the nearest corresponding C-major tone, shown in \cref{tab:cmajor}.

\paragraph{Post-processing} handles the digital to analog conversion.

\subsection{Detailed description of the design parts}
\subsubsection{Preprocessing}
On \cref{fig:DetailedPrePro} it can be seen that the analog signal will be sampled with a sampling frequency of \SI{48}{\kilo\hertz}.
The discrete signal wil be passed on to the FFT, which will make an FFT of the signal.
The FFT signal, xfft, will be passed on to the Hilbert max frequency determination block.
The Hilbert transform will find the dominating frequency in the signal.
Hilbert transform will only work when the input signal is a pure sine wave, if there are more sine waves mixed together it will find the average frequency and therefore a misinterpretation of the signal will be made.
Hilbert transformation requires many heavy calculations and deviations which will result in a product quantization error.
The found max frequency, maxFreq will be passed on to the signal processing block.

\begin{figure}
	\centering
	\includegraphics[width=1\linewidth]{gfx/Design/DesignPrePro_IF.pdf}
	\caption{Detailed description of Preprocessing in \systemName.}
	\label{fig:DetailedPrePro}
\end{figure}

\subsubsection{Signal processing}
\Cref{fig:DetailedSigPro} shows the detailed idea of the signal processing part.

\begin{figure}
	\centering
	\includegraphics[width=1\linewidth]{gfx/Design/DesignSigPro_IF.pdf}
	\caption{Detailed description of Signal processing in \systemName.}
	\label{fig:DetailedSigPro}
\end{figure}

The maxFreq will be passed on to a Sinus generator, where it will be determined which frequency to go to on \cref{tab:cmajor}.
A sine wave with the found frequency will then be made with as few points as possible.
The generated sine wave, y(n), will be interpolated so the signal gets a lot of values in the sine wave, this method has been chosen with the thought that generating a sine wave with many points is more costly then interpolating.
The new full sine wave will be passed on to a circular buffer.
The idea behind the circular buffer is to avoid calculating the same sine wave again and again.
If the maxFreq appears to be the same multiple times, the sine wave in the circular buffer can be reused thus we do not have to generate or interpolate a new sine.
The output from the circular buffer will be the new complete discrete signal.

\subsubsection{Post processing}
The last phase of the system will take the final discrete signal and through a DAC make it to an analog signal as shown on \cref{fig:DetailedPostPro}.
\begin{figure}
	\centering
	\includegraphics[width=1\linewidth]{gfx/Design/DesignPostPro_IF.pdf}
	\caption{Detailed description of Post processing in \systemName.}
	\label{fig:DetailedPostPro}
\end{figure}

\subsection{Quantization}
There will be a quantization error on the IIR low pass filter, but since the filter is not steep and have rather long time to get to the stop band, the low pass filter does not suffer significantly from the quantization, as can be seen in \cref{fig:quant_error_filter} where the max difference was found to be $\SI{<0.5}{\percent} $.
Thus the quantization error for this specific filter is negligible, but the implementation of this filter should be a FIR low pass filter since it is what works with the build in functions.

\begin{figure}
	\centering
	\includegraphics[width=1\linewidth]{gfx/QuantizationFilter.png}
	\caption{Matlab filter coefficients results in the green curve, 1.15 format in the red curve.}
	\label{fig:quant_error_filter}
\end{figure}

In the filter there will occur coefficient and product quantization. Coefficient quantization will occur when the filter coefficients are fitted to the 1.15 format.
The product quantization will occur when the filter coefficients are multiplied with the data.
This will result in quantization since it still has to fit 1.15 format.
On \cref{fig:quant_error} the places where quantization occurs can be seen.

\begin{figure}
	\centering
	\includegraphics[width=1\linewidth]{gfx/Design/flow_quant_error.pdf}
	\caption{Quantization errors \systemName.}
	\label{fig:quant_error}
\end{figure}

\FloatBarrier


\chapter{Clustering}
\begin{multicols*}{2}

\noindent Clustering is the process of grouping a set of objets into classes of similar objects\\

\noindent Ideally, we want similarity of documents are measured based on semantic similarity. However, practically we use euclidean distance and cosine similarity to achieve term-statistical similarity.

\section{Partition Clustering: K-means Clustering}

\noindent Algorithm:
\begin{itemize}
    \item Pick k number of seeds
    \item Assign each data to the nearest cluster
    \item Compute centroids for k cluster
    \item Repeat till converged
\end{itemize}

\noindent The sum of squared distances from cluster centroid should decrease while repeating:
$$E=\sum_k \sum_{i \in C_k} (d_i - c_k)^2$$

\section{Hierarchical Agglomerative Clustering}
\noindent Start with points as individual clusters. At each step, merge the closest pair of clusters until one cluster left.
\noindent Algorithm:
\begin{itemize}
    \item Compute the proximity matrix
    \item Let each data point be a cluster
    \item Repeat:
    \begin{itemize}
        \item Merge the two closest clusters
        \item Update the proximity matrix
    \end{itemize}
    \item Until only a single cluster remains
\end{itemize}

\noindent Four way to update proximity matrix:
\begin{itemize}
    \item Single-link: similarity of closest points
    \item Complete-link: similarity of furthest points
    \item Centroid: similarity of centroids
    \item Average-link: Average cosine between pairs of points
\end{itemize}

\section{Hierarchical Divisive Clustering}
Start with one cluster. At each step, split a cluster until each cluster contains a point.

\section{Evaluation}
\noindent Good clustering means the intra-class similarity is high and inter-class similarity is low. \\

\noindent Purity: the ratio between the dominant class in the cluster and the size of the cluster
$$j\in C, \text{Purity}(\omega) = \frac{1}{n_i} \text{max}_j (n_{ij})$$

\subsection{Rand Index}

\begin{center}
\begin{tabular}{ |c|c c| }
    \hline
    Number of points & Same cluster & Different cluster \\
    \hline
    Same Truth & A & C \\
    Different Truth & B & D \\
    \hline
\end{tabular}
\end{center}

$$RI=\frac{A+D}{A+B+C+D}$$

\end{multicols*}


\documentclass[11pt, oneside]{article}   	% use "amsart" instead of "article" for AMSLaTeX format

% \usepackage{draftwatermark}
% \SetWatermarkText{Draft}
% \SetWatermarkScale{5}
% \SetWatermarkLightness {0.9}
% \SetWatermarkColor[rgb]{0.7,0,0}

\usepackage{geometry}                		% See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   		% ... or a4paper or a5paper or ...
%\geometry{landscape}                		% Activate for for rotated page geometry
%\usepackage[parfill]{parskip}    		% Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}				% Use pdf, png, jpg, or eps� with pdflatex; use eps in DVI mode
								% TeX will automatically convert eps --> pdf in pdflat
								% TeX will automatically convert eps --> pdf in pdflatex
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{hyperref}
\usepackage{url}
\usepackage{subcaption}
\usepackage{authblk}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{fixltx2e}
\usepackage{hyperref}
\usepackage{alltt}
\usepackage{color}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{float}
\usepackage{bigints}
\usepackage{braket}
\usepackage{siunitx}

%
% so you can do e.g., \begin{bmatrix}[r] (or [c] or [l])
%

\makeatletter
\renewcommand*\env@matrix[1][c]{\hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{*\c@MaxMatrixCols #1}}
\makeatother

\newcommand{\argmax}{\operatornamewithlimits{argmax}}
\newcommand{\argmin}{\operatornamewithlimits{argmin}}

\title{A Few Notes on Bell States, Superdense Coding, and Quantum Teleportation}
\author{David Meyer \\ dmm@\{1-4-5.net,uoregon.edu\}}

\date{Last update: \today}							% Activate to display a given date or no date

\begin{document}
\maketitle

\section{Introduction}

The Bell Circuit, shown in Figure \ref{fig:bell_circuit}, is comprised of two gates, $H$ and CNOT, which are defined as follows:

\begin{flalign*}
H = \frac{1}{\sqrt{2}}  \begin{bmatrix}[r] 1 & 1 \\ 1 &  -1 \end{bmatrix},
\text{CNOT} = \begin{bmatrix}[r]
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\end{flalign*}

\bigskip
\noindent
and results in two maximally entangled qubits\footnote{This state is sometimes called an \emph{EPR} state.}.
How does this work?

\bigskip
\noindent
First, recall that

\begin{flalign*}
H \ket{0} &= \frac{1}{\sqrt{2}} \big ( \ket{0} + \ket{1} \big )  \text{ and }
H \ket{1} = \frac{1}{\sqrt{2}} \big ( \ket{0} - \ket{1} \big )
\end{flalign*}

\bigskip
\noindent
The Bell Circuit applies $H$ to $\ket{b_0}$ and then applies the CNOT gate to $H\ket{b_0}$ (control qubit)
and $\ket{b_1}$ (target qubit). The inputs and evolution of the Bell Circuit are shown are Table \ref{tab:bell_state}.

\bigskip
\begin{figure}
\center{\includegraphics[scale=0.45, frame] {images/bell_forward_circuit.png}}
\caption{Bell Circuit}
\label{fig:bell_circuit}
\end{figure}

\begin{table}[H]
\centering
\begin{tabular}{c | c | c | c | c}
$b_{0} b_{1}$  & $H \ket{b_0}$ & $\ket{b_1}$ & Bell Circuit evolution with inputs $\ket{b_0}$ and $\ket{b_1}$  & Bell State\\
\hline
00  & $H\ket{0}$ & $\ket{0}$ & $\ket{0} \xrightarrow{\scriptsize H}  \frac{1}{\sqrt{2}} (\ket{0} + \ket{1})
  \xrightarrow{\otimes \ket{0}}  \frac{1}{\sqrt{2}} (\ket{0} + \ket{1}) \ket{0} \xrightarrow{\scriptsize \text{CNOT}} \frac{1}{\sqrt{2}} (\ket{00} + \ket{11})$ & $\ket{\phi^+}$ \\
01  & $H\ket{0}$ & $\ket{1}$ & $ \ket{0} \xrightarrow{\scriptsize H} \frac{1}{\sqrt{2}} (\ket{0} + \ket{1})
  \xrightarrow{\scriptsize \otimes \ket{1}} \frac{1}{\sqrt{2}} (\ket{0} + \ket{1})  \ket{1} \xrightarrow{\scriptsize \text{CNOT}}  \frac{1}{\sqrt{2}} (\ket{01} + \ket{10})$\ & $\ket{\psi^+}$ \\
10  & $H\ket{1}$ & $\ket{0}$ & $\ket{1} \xrightarrow{\scriptsize H}  \frac{1}{\sqrt{2}} (\ket{0} - \ket{1})  \xrightarrow{\scriptsize \otimes \ket{0}} \frac{1}{\sqrt{2}} (\ket{0} - \ket{1})  \ket{0} \xrightarrow{\scriptsize \text{CNOT}} \frac{1}{\sqrt{2}}  (\ket{00} - \ket{11})$ & $\ket{\phi^-}$ \\
11    & $H\ket{1}$ & $\ket{1}$ & $\ket{1} \xrightarrow{\scriptsize H}  \frac{1}{\sqrt{2}} (\ket{0} - \ket{1})
  \xrightarrow{\scriptsize \otimes  \ket{1}}  \frac{1}{\sqrt{2}} (\ket{0} - \ket{1})  \ket{1} \xrightarrow{\scriptsize \text{CNOT}} \frac{1}{\sqrt{2}}  (\ket{01} - \ket{10})$ & $\ket{\psi^-}$
\end{tabular}
\caption{Bell States}
\label{tab:bell_state}
\end{table}

\bigskip
\noindent
What we can see from Table \ref{tab:bell_state} is that $b_0$ selects the "bit" ($\ket{\phi}$ or $\ket{\psi}$), and $b_1$ selects the "sign" ($\ket{+}$ or $\ket{-}$). Since there
are four orthonormal states, the \emph{Bell basis}, we can encode two bits ($b_0$ and $b_1$) in the four Bell States.

\bigskip
\noindent
Now,  if Alice wants to send two classical bits to  Bob (\emph{superdense coding}) using one qubit, she need only transform her qubit\footnote{Her half of the EPR pair, the two entangled qubits.}
into the Bell State corresponding to the two bits she wants to send, then send her half to Bob (this requires a \emph{quantum} channel). Bob can then recover Alice's two bit message.

\bigskip
\noindent
But how can Bob recover Alice's message? Recall that unitary quantum operations are reversible. So Bob can use the Reverse Bell Circuit shown in Figure \ref{fig:reverse_bell_circuit} to recover
Alice's 2 bit message.

\bigskip
\begin{figure}[H]
\center{\includegraphics[scale=0.45, frame] {images/bell_reverse_circuit.png}}
\caption{Reverse Bell Circuit}
\label{fig:reverse_bell_circuit}
\end{figure}

\section{Superdense Coding}

Suppose Alice wants to send Bob the message $00$. Alice can perform one or more unitary operations on her qubit (her half of the entangled pair) that will allow Bob,
when presented with Alice's qubit, to reconstruct Alice's message $b_0b_1$. If we run $\ket{\phi^+}$ through the circuit in Figure \ref{fig:reverse_bell_circuit},
that is, $\ket{\phi^+}  \xrightarrow {\scriptsize \text{CNOT}}  \xrightarrow {\scriptsize \text{  H  }}  \ket{b_0b_1}$,  Bob will recover Alice's message ($b_0b_1 = 00$). Why is this?

\begin{flalign*}
\ket{\phi^+} &=  \frac{1}{\sqrt{2}} (\ket{00} + \ket{11}) \longrightarrow  \\
& \frac{1}{\sqrt{2}} (\ket{0}  \ket{0} + \ket{1} \ket{1}) \xrightarrow {\scriptsize \text{CNOT}} \frac{1}{\sqrt{2}} (\ket{00} + \ket{10}) \longrightarrow \\
& \frac{1}{\sqrt{2}} (\ket{00} + \ket{10}) \xrightarrow {\scriptsize \text{  H  }}  \frac{1}{\sqrt{2}}  \Big ( \frac{1}{\sqrt{2}}  (\ket{0} + \ket{1}) \ket{0} + \frac{1}{\sqrt{2}}  (\ket{0} - \ket{1}) \ket{0} \Big) \\
&= \frac{1}{\sqrt{2}} \frac{1}{\sqrt{2}}  \Big ( (\ket{0} + \ket{1}) \ket{0} + (\ket{0} - \ket{1}) \ket{0} \Big ) \\
&= \frac{1}{2} \big (\ket{00} + \ket{10} + \ket{00} - \ket{10} \big ) \\
&= \frac{1}{2} \big  (2 \ket{00} + (\ket{10} - \ket{10}) \big ) \\
&=  \frac{1}{2} \cdot 2 \ket{00} \\
&= \ket{00}
\end{flalign*}

\bigskip
\noindent
Bob can now measure both qubits and recover Alice's message ($b_0b_1 = 00$).

\bigskip
\noindent
In general, Alice notices that

\begin{itemize}
\item To send \textbf{00}, apply the Identity matrix $\mathbf{I} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}$ to her half of the EPR pair
\item To send \textbf{01}, apply the matrix $\mathbf{X} = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}$ to her half of the EPR pair
\item To send \textbf{10}, apply the matrix $\mathbf{Z} = \begin{bmatrix}[r] 1 & 0 \\ 0 & -1 \end{bmatrix}$ to her half of the EPR pair
\item To send \textbf{11}, apply $i\mathbf{Y} = i \begin{bmatrix}[r] 0 & -i \\ i & 0 \end{bmatrix}$, i.e. both $\mathbf{X}$ and $\mathbf{Z}$,  to her half of the EPR pair
\end{itemize}

\bigskip
\noindent
where $\mathbf{I}$, $\mathbf{X}$, $\mathbf{Y}$ and $\mathbf{Z}$ are the \emph{Pauli} matrices \cite{wiki:pauli_matrices}.
\bigskip
\noindent
This transforms the EPR pair $\ket{\phi^+}$ into the four Bell States $\ket{\phi^+}$, $\ket{\psi^+}$, $\ket{\phi^-}$ and $\ket{\psi^-}$ respectively:

\begin{itemize}
\item \textbf{00}: $\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}  \frac{1}{\sqrt{2}} (\ket{00} + \ket{11} \longrightarrow  \frac{1}{\sqrt{2}} (\ket{00} + \ket{11}) =
\frac{1}{\sqrt{2}} \begin{bmatrix} 1 \\ 0 \\  0 \\ 1 \end{bmatrix} = \ket{\phi^+}$

\item \textbf{01:} $\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} \frac{1}{\sqrt{2}} (\ket{00} + \ket{11} \longrightarrow  \frac{1}{\sqrt{2}} (\ket{01} + \ket{10}) =
\frac{1}{\sqrt{2}} \begin{bmatrix} 0 \\ 1 \\  1 \\ 0 \end{bmatrix} = \ket{\psi^+}$

\item \textbf{10:} $\begin{bmatrix}[r] 1 & 0 \\ 0 & -1 \end{bmatrix}  \frac{1}{\sqrt{2}} (\ket{00} - \ket{11} \longrightarrow  \frac{1}{\sqrt{2}} (\ket{00} - \ket{11}) =
\frac{1}{\sqrt{2}} \begin{bmatrix}[r] 1 \\ 0 \\  0 \\  -1 \end{bmatrix} = \ket{\phi^-}$

\item \textbf{11:}  $i  \begin{bmatrix}[r] 0 & -i \\ i & 0 \end{bmatrix} \frac{1}{\sqrt{2}} (\ket{00} + \ket{11} \longrightarrow  \frac{1}{\sqrt{2}} (\ket{01} - \ket{10}) =
\frac{1}{\sqrt{2}} \begin{bmatrix}[r] 0 \\ 1 \\  -1 \\ 0 \end{bmatrix} = \ket{\psi^-}$
\end{itemize}

\bigskip
\noindent
The four Bell states $\ket{\phi^+}$, $\ket{\psi^+}$, $\ket{\phi^-}$ and $\ket{\psi^-}$ are orthonormal and are hence distinguishable by
quantum measurement.  Thus after receiving Alice's transformed qubit (her half of the EPR pair),
Bob can measure both qubits and recover $b_0b_1$. Hence one qubit carries two classical bits of information; this is superdense coding.
We saw an example of this above in which Bob recovered $\ket{00}$ from $\ket{\phi^+}$ using
the Reverse Bell Circuit depicted in Figure \ref{fig:reverse_bell_circuit}.

\subsection{Aside: Spectral Decomposition of Pauli Matrices}
So far we've interpreted the Pauli matrices as a quantum gates. But note that a gate such \textbf{Z} is a Hermitean operator and as a
result can be interpreted as an observable. Somewhat surprisingly (notice the symmetry),  the spectral decomposition \cite{2014arXiv1405.5749S}
 of \textbf{Z}  is

\begin{flalign*}
\mathbf{Z} =  \ket{0}\bra{0} - \ket{1}\bra{1}
\end{flalign*}

\bigskip
\noindent
where  $\ket{u}\bra{v}$ is Dirac notation \cite{2000RPPh...63.1893G} for the outer product $\mathbf{u} \otimes \mathbf{v} =  \mathbf{u} \mathbf{v}^{\text{T}}$ of $m \times 1$ vector
\textbf{u} and  $n \times 1$ vector \textbf{v}, which yields a $m \times n$ matrix\footnote{The outer product is of vectors
\textbf{u} and \textbf{v}  is a special case of the tensor product  $\mathbf{u} \otimes \mathbf{v}$.
More generally, the outer product is an instance of a Kronecker product \cite{wiki:kronecker}.}.

\bigskip
\noindent
We can see that the eigenvalues of \textbf{Z}  are 1 and -1, corresponding to eigenvectors $\ket{0}$  and $\ket{1}$  respectively. So the measurement operators are the
projectors $\ket{0}\bra{0}$ and $\ket{1}\bra{1}$,  This means that a measurement of the Pauli observable \textbf{Z} is a measurement in the computational basis that has
eigenvalue +1 corresponding to $\ket{0}$  and eigenvalue -1 corresponding to $\ket{1}$.

\bigskip
\noindent
So ok, but why does $\mathbf{Z} = \ket{0}\bra{0} - \ket{1}\bra{1}$? Well, we know that the outer product $\mathbf{u} \otimes \mathbf{v}$ of a $m \times 1$ vector  \textbf{u} and a
$n \times 1$ vector  \textbf{v} is defined to be the $m \times n$ matrix\footnote{Contrast with the scalar inner product
$\langle \mathbf{u},  \mathbf{v} \rangle = \mathbf{u}^{\text{T}} \mathbf{v}$. Note also that $\langle \mathbf{u},  \mathbf{v} \rangle = \text{tr}(\mathbf{u} \otimes \mathbf{v})$,
where $\text{tr}(\mathbf{A})$ is the "trace" of matrix \textbf{A}. } $\mathbf{u} \mathbf{v}^{\text{T}}$.

\bigskip
\noindent
To see why $\mathbf{Z} = \ket{0}\bra{0} - \ket{1}\bra{1}$, first recall that  $\ket{0} = \begin{bmatrix} 1 \\0 \end{bmatrix}$ and $\ket{1} = \begin{bmatrix} 0 \\ 1 \end{bmatrix}$. Then

\begin{flalign*}
\ket{0}\bra{0}  &= \begin{bmatrix} 1 \\ 0 \end{bmatrix} \begin{bmatrix} 1 \\ 0 \end{bmatrix}^{\text{T}} =
\begin{bmatrix} 1 \\ 0 \end{bmatrix} \begin{bmatrix} 1  & 0 \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix} \text{ and} \\
\ket{1}\bra{1}  &= \begin{bmatrix} 0 \\ 1 \end{bmatrix}\begin{bmatrix} 0 \\ 1 \end{bmatrix}^{\text{T}}  = \begin{bmatrix} 0 \\ 1 \end{bmatrix} \begin{bmatrix} 0  & 1 \end{bmatrix} = \begin{bmatrix} 0 & 0 \\ 0 & 1 \end{bmatrix} \text{ so that} \\
\ket{0}\bra{0} - \ket{1}\bra{1} &= \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix}  - \begin{bmatrix} 0 & 0 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix}[r] 1 & 0 \\ 0 & -1 \end{bmatrix} = \mathbf{Z}
\end{flalign*}

\bigskip
\subsection{Back to Alice wanting to send a message to Bob}
Now suppose Alice want's to send Bob the message 01.  Alice then applies Pauli matrix $X$ to $\ket{\phi+}$ to get $\ket{\psi^+}$:

\begin{equation*}
\mathbf{X} \ket{\phi^+} = \begin{bmatrix}[r] 0 & 1  \\ 1 & 0\end{bmatrix} \frac{1}{\sqrt{2}} (\ket{00} + \ket{11} = \frac{1}{\sqrt{2}} (\ket{01} + \ket{10}) = \ket{\psi^+}
\end{equation*}

\bigskip
\noindent
Bob can now recover Alice's message as follows using the Reverse Bell Circuit (Figure \ref{fig:reverse_bell_circuit}). That is, Bob can
do the the unitary operations $\ket{\psi^+}  \xrightarrow {\scriptsize \text{CNOT}}  \xrightarrow {\scriptsize \text{H}}  \ket{01}$, as follows:

\begin{flalign*}
\ket{\psi^+} &= \frac{1}{\sqrt{2}} (\ket{01} + \ket{10}) \longrightarrow \\
& \frac{1}{\sqrt{2}} (\ket{0}  \ket{1} + \ket{1} \ket{0}) \xrightarrow {\scriptsize \text{CNOT}} \frac{1}{\sqrt{2}} (\ket{01} + \ket{11}) \longrightarrow \\
& \frac{1}{\sqrt{2}} (\ket{01} + \ket{11}) \xrightarrow {\scriptsize \text{  H  }}  \frac{1}{\sqrt{2}}  \Big ( \frac{1}{\sqrt{2}}  (\ket{0} + \ket{1}) \ket{1} + \frac{1}{\sqrt{2}}  (\ket{0} - \ket{1}) \ket{1} \Big) \\
&= \frac{1}{\sqrt{2}} \frac{1}{\sqrt{2}}  \Big ( (\ket{0} + \ket{1}) \ket{1} + (\ket{0} - \ket{1}) \ket{1} \Big ) \\
&= \frac{1}{2} \big (\ket{01} + \ket{11} + \ket{01} - \ket{11} \big) \\
&= \frac{1}{2} \big (2 \ket{01} + (\ket{11} - \ket{11}) \big) \\
&=  \frac{1}{2}  \cdot 2 \ket{01} \\
&=  \frac{2}{2}  \ket{01} \\
&= \ket{01}
\end{flalign*}

\bigskip
\noindent
Now Bob can measure the two qubits and recover Alice's message ($b_0b_1 = 01$).

\bigskip
\noindent
Similarly, suppose Alice wants to send the message 10 to Bob. Alice first transforms her qubit as follows

\begin{equation*}
\mathbf{Z} \ket{\phi^+} = \begin{bmatrix}[r] 1 & 0 \\ 0 & -1 \end{bmatrix}  \frac{1}{\sqrt{2}} (\ket{00} + \ket{11} = \frac{1}{\sqrt{2}} (\ket{00} -  \ket{11}) = \ket{\phi^-}
\end{equation*}

\bigskip
\noindent
Alice now sends her qubit to Bob over a quantum channel. Bob can now recover Alice's message, again using the Reverse Bell Circuit
($\ket{\phi^-}  \xrightarrow {\scriptsize \text{CNOT}}  \xrightarrow {\scriptsize \text{  H  }}  \ket{10}$). Again, why is this?

\begin{flalign*}
\ket{\phi^-} &=  \frac{1}{\sqrt{2}} (\ket{00} - \ket{11}) \longrightarrow \\
& \frac{1}{\sqrt{2}} (\ket{0}  \ket{0} - \ket{1} \ket{1}) \xrightarrow {\scriptsize \text{CNOT}} \frac{1}{\sqrt{2}} (\ket{00} - \ket{10}) \longrightarrow \\
& \frac{1}{\sqrt{2}} (\ket{00} - \ket{10}) \xrightarrow {\scriptsize \text{  H  }}  \frac{1}{\sqrt{2}}  \Big ( \frac{1}{\sqrt{2}}  (\ket{0} + \ket{1}) \ket{0} -  \frac{1}{\sqrt{2}}  (\ket{0} - \ket{1}) \ket{0} \Big) \\
&= \frac{1}{\sqrt{2}} \frac{1}{\sqrt{2}}  \Big ( (\ket{0} + \ket{1}) \ket{0} -  (\ket{0} - \ket{1}) \ket{0} \Big ) \\
&= \frac{1}{2} \big (\ket{00} + \ket{10} - \ket{00}  + \ket{10} \big ) \\
&= \frac{1}{2} \big (2 \ket{10} + (\ket{00} - \ket{00}) \big ) \\
&=  \frac{1}{2} \cdot 2 \ket{10} \\
&= \ket{10}
\end{flalign*}

\bigskip
\noindent
Now Bob can measure the two qubits and recover Alice's message ($b_0b_1 = 10)$.

\bigskip
\noindent
Finally, if Alice wants to send $11$ to Bob she first transforms her qubit

\begin{equation*}
i \mathbf{Y} \ket{\phi^+} =  \begin{bmatrix}[r] 0 & -i \\ i & 0 \end{bmatrix}   \frac{1}{\sqrt{2}} (\ket{00} + \ket{11} = \frac{1}{\sqrt{2}} (\ket{01} - \ket{10}) = \ket{\psi^-}
\end{equation*}

\bigskip
\noindent
Alice now transmits her qubit to Bob and Bob applies the Reverse Bell Circuit to recover Alice's message:

\begin{flalign*}
\ket{\psi^-} &= \frac{1}{\sqrt{2}} (\ket{01} -  \ket{10}) \longrightarrow \\
& \frac{1}{\sqrt{2}} (\ket{0}  \ket{1} - \ket{1} \ket{0}) \xrightarrow {\scriptsize \text{CNOT}} \frac{1}{\sqrt{2}} (\ket{01} -  \ket{11}) \longrightarrow \\
& \frac{1}{\sqrt{2}} (\ket{01} -  \ket{11}) \xrightarrow {\scriptsize \text{  H  }}  \frac{1}{\sqrt{2}}  \Big ( \frac{1}{\sqrt{2}}  (\ket{0} + \ket{1}) \ket{1} - \frac{1}{\sqrt{2}}  (\ket{0} - \ket{1}) \ket{1} \Big) \\
&= \frac{1}{\sqrt{2}} \frac{1}{\sqrt{2}}  \Big ( (\ket{0} + \ket{1}) \ket{1} -  (\ket{0} - \ket{1}) \ket{1} \Big ) \\
&= \frac{1}{2} \big (\ket{01} + \ket{11} -  \ket{01} +  \ket{11} \big) \\
&= \frac{1}{2} \big (2 \ket{11} + (\ket{01} - \ket{01}) \big) \\
&=  \frac{1}{2}  \cdot 2 \ket{11} \\
&=  \frac{2}{2}  \ket{11} \\
&= \ket{11}
\end{flalign*}

\bigskip
\noindent
Now Bob can measure the two qubits and recover Alice's message ($b_0b_1 = 11)$.

\section{Quantum Teleportation}
Quantum teleportation can be thought of as the dual task to super dense coding. Whereas super dense coding is concerned with conveying classical information
via a qubit, quantum teleportation is concerned with conveying quantum information with classical bits \cite{Bennett:1992tv}.

\subsection{A high-level view of the quantum teleportation algorithm}

\begin{enumerate}
\item Alice and Bob share an entangled (EPR) pair $\ket{\phi^+}$
\item Alice chooses a qubit $\ket{\psi}$ as the message she wants to convey to Bob
\item Alice performs operations on $\ket{\psi}$ and $\ket{\phi^{+}_A}$ (Alice's her half of $\ket{\phi^+}$)
\item Alice measures $\ket{\psi}$  and her half of  $\ket{\phi^+_A}$, destroying both of her qubits
\item Alice sends the two classical bits that were the results of her measurements to Bob
\item Bob uses the two classical bits to "correct" $\ket{\phi^{+}_B}$ (his half of $\ket{\phi^+}$) to be $\ket{\psi}$
\end{enumerate}

\bigskip
\noindent
Alice uses the circuit in Figure \ref{fig:a_reverse_bell_circuit} to prepare her two qubits (step 3 above). How exactly does this work?
First, notice that the input to the Reverse Bell Circuit shown in Figure \ref{fig:a_reverse_bell_circuit} is $\ket{\psi} \otimes \ket{\phi^{+}_A}$.
To see how this works, first recall that $\ket{\psi} = \alpha \ket{0} + \beta \ket{1}$.  Then

\begin{figure}[t]]
\center{\includegraphics[scale=0.45, frame] {images/a_reverse_bell_circuit.png}}
\caption{Reverse Bell Circuit}
\label{fig:a_reverse_bell_circuit}
\end{figure}

\begin{flalign*}
\ket{\psi} \otimes \ket{\phi^{+}_A} &= (\alpha \ket{0} + \beta \ket{1}) \otimes \frac{1}{\sqrt{2}} (\ket{00} + \ket{11}) \\
&= \frac{1}{\sqrt{2}} \Big ( \alpha (\ket{000} + \alpha \ket{011}) + \beta (\ket{100} + \ket{111}) \Big ) \xrightarrow {\scriptsize \text{CNOT}}
\quad\qquad \mathrel{\#} \ket{b_0b_1b_2}: b_0 \text{ is control, } b_1  \text{ is target} \\
& \frac{1}{\sqrt{2}} \Big ( \alpha \ket{000} + \alpha \ket{011})+ \beta (\ket{110} + \ket{101}) \Big ) \xrightarrow {\scriptsize \text{H}}
\; \qquad \qquad\qquad \mathrel{\#} \text{apply $H$ to $b_0$} \\
& \frac{1}{\sqrt{2}} \bigg [ \alpha \Big ( \frac{1}{\sqrt{2}} \ket{0} + \ket{1} \Big ) \ket{00} + \alpha \Big (  \frac{1}{\sqrt{2}} \ket{0} + \ket{1}) \Big )  \ket{11}  +
\beta \Big ( \frac{1}{\sqrt{2}} \ket{0} - \ket{1} \Big ) \ket{10} + \beta \Big (  \frac{1}{\sqrt{2}} \ket{0} - \ket{1} \Big )  \ket{01}  \bigg ]\\
&= \frac{1}{\sqrt{2}} \frac{1}{\sqrt{2}}
\bigg [ \alpha \Big ( \big (\ket{0} + \ket{1} \big ) \ket{00} +  \big (\ket{0} + \ket{1} \big )  \ket{11} \Big)  +
\beta \Big ( \big (\ket{0} - \ket{1} \big ) \ket{10} + \big ( \ket{0} - \ket{1} \big )  \ket{01} \Big ) \bigg] \\
&= \frac{1}{2} \bigg [ \alpha \Big (\ket{000} + \ket{100}  +  \ket{011} + \ket{111}) \Big)  +
\beta \Big (\ket{010} - \ket{110} + \ket{001} - \ket{101}  \Big ) \bigg ] \\
&= \frac{1}{2} \bigg [ \alpha \ket{000} + \alpha \ket{100}  +  \alpha \ket{011} + \alpha \ket{111})  +
 \beta \ket{010} - \beta\ket{110} + \beta \ket{001} - \beta \ket{101}  \bigg ] \\
\end{flalign*}

\bigskip
\noindent
Now Alice measures her two qubits ($\ket{\psi} \otimes \ket{\phi^{+}_A} $) and observes $b_0b_1 \in \{00, 01, 10, 11\}$ with $P(b_0b_1) = \frac{1}{4}$.

\bigskip
\noindent
Now here's the amazing thing. If Alice observes $00$, she communicates this to Bob (over a classical channel). As soon as
Bob sees the value $00$, he knows that his qubit $\ket{\phi^{+}_{B}} = \alpha \ket{0} + \beta \ket{1}$. How does Bob know this?

\bigskip
\noindent
First, as shown above

\begin{flalign}
\label{eqn:psi_otimes_phi+}
\ket{\psi} \otimes \ket{\phi^+} = \frac{1}{2} \bigg [ \alpha \ket{000} + \alpha \ket{100}  +  \alpha \ket{011} + \alpha \ket{111})  +
\beta \ket{010} - \beta\ket{110} + \beta \ket{001} - \beta \ket{101}  \bigg ]
\end{flalign}

 \bigskip
\noindent
Alice's measurement of the first two qubits collapses Bob's qubit to the third qubit\footnote{Recall that the original three qubits were
$\ket{\psi} \otimes \ket{\phi^{+}_{AB}}$.}.  The only terms in Equation \ref{eqn:psi_otimes_phi+} that are
consistent with the first two qubits being $\ket{00}$ (resulting from Alice's measurement)
are $\alpha \ket{000}$ and $\beta \ket{001}$. The "collapsed version" is $\alpha \ket{0}$ and $\beta \ket{1}$.
Hence Bob knows that his qubit, $\ket{\phi^{+}_B}$,  equals $\alpha \ket{0} + \beta \ket{1}$.

 \bigskip
\noindent
Since Alice sent the two bits she saw to Bob, he knows which operations to perform to transform $\ket{\phi^{+}_B} \rightarrow \ket{\psi}$.
In particular, $b_0 = 1$ Bob should apply Pauli matrix $Z$ to his qubit and $I$ otherwise,
and if $b_1 = 1$ he should apply $X$ and $I$ otherwise. This transforms $\ket{\phi^{+}_B}$, Bob's qubit, into $\ket{\psi}$.
This is shown in Table \ref{tab:bob}.

\bigskip
\noindent
Amazingly  this procedure teleports Alice's qubit $\ket{\psi}$ to Bob using the two classical bits that Alice learned by measuring her two qubits ($\ket{\psi}$ and $\ket{\phi^{+}_A}$).

\bigskip
\begin{table}[H]
\centering
\begin{tabular}{c | c | r | r}
$b_{0} b_{1}$  & $\ket{\phi^{+}_B}$  & \multicolumn{1}{c|}{Transformation} & \multicolumn{1}{c}{Computation}  \\
\hline
\textbf{00}  & $\alpha \ket{0} + \beta \ket{1}$ & $\mathbf{I} \begin{bmatrix} \alpha \\ \beta \end{bmatrix}$ & $\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}
 \begin{bmatrix} \alpha \\ \beta \end{bmatrix}  = \begin{bmatrix} \alpha \\  \beta  \end{bmatrix} = \alpha \ket{0} + \beta \ket{1} = \ket{\psi}$  \\
\textbf{01}  & $\beta \ket{0} + \alpha \ket{1}$ & $\mathbf{X}\begin{bmatrix} \beta \\ \alpha  \end{bmatrix}$ & $ \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}  \begin{bmatrix} \beta \\ \alpha  \end{bmatrix}
= \begin{bmatrix} \alpha \\  \beta  \end{bmatrix}  = \alpha \ket{0} + \beta \ket{1} = \ket{\psi}$ \\
\textbf{10}  & $\alpha \ket{0} - \beta \ket{1}$ & $\mathbf{Z} \begin{bmatrix}[r]   \alpha \\  -\beta  \end{bmatrix}$ & $\begin{bmatrix}[r] 1 & 0  \\ 0 & -1 \end{bmatrix}  \begin{bmatrix}[r] \alpha \\ -\beta \end{bmatrix}
= \begin{bmatrix} \alpha \\  \beta  \end{bmatrix}  = \alpha \ket{0} + \beta \ket{1} = \ket{\psi}$ \\
\textbf{11}  & $\beta \ket{0} - \alpha \ket{1} $ & $\mathbf{XZ} \begin{bmatrix}[r]  \beta \\  - \alpha  \end{bmatrix}$ & $  \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}  \begin{bmatrix}[r] 1 & 0  \\ 0 & -1 \end{bmatrix}
  \begin{bmatrix}[r] \beta \\ -  \alpha  \end{bmatrix} = \begin{bmatrix} \alpha \\  \beta  \end{bmatrix} = \alpha \ket{0} + \beta \ket{1} = \ket{\psi}$ \\
\end{tabular}
\caption{Bob's transformations on receiving classical bits $\mathbf{b_0b_1}$ from Alice}
\label{tab:bob}
\end{table}

\subsection{Curious Entry for \textbf{11} in Table \ref{tab:bob}?}
Note that the row for the result of Alice's measurement \textbf{11} in Table \ref{tab:bob} is curious. When Bob sees \textbf{11} from Alice he knows that his remaining qubit
$\ket{\psi^{+}_B}$, equals $- \beta \ket{0} + \alpha \ket{1}$. Why does the table say $\beta \ket{0} - \alpha \ket{1}$?

\bigskip
\noindent
Here is one way to look at this: First,
recall that when Bob receives classical bits \textbf{11} from Alice he knows that his qubit, $\ket{\psi^{+}_B}$,  is

\begin{flalign*}
\ket{\psi^{+}_B} &= - \beta \ket{0} + \alpha \ket{1} = \begin{bmatrix} -\beta \\ \alpha \end{bmatrix}
\end{flalign*}

\bigskip
\noindent
Now, if Bob now wants to transform $\ket{\psi^{+}_B} \rightarrow \ket{\psi}$, he would apply $\mathbf{ZX}$ as follows

\begin{flalign*}
\mathbf{ZX} \ket{\psi^{+}_B}  &=  \begin{bmatrix}[r] 1 & 0  \\ 0 & -1 \end{bmatrix}   \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}  \begin{bmatrix} -\beta \\ \alpha \end{bmatrix} \\
&= \begin{bmatrix}[r] 1 & 0  \\ 0 & -1 \end{bmatrix}   \begin{bmatrix} \alpha \\ - \beta \end{bmatrix} \\
&= \begin{bmatrix} \alpha \\ \beta \end{bmatrix} \\
&= \alpha \ket{0} + \beta \ket{1} \\
&= \ket{\psi}
\end{flalign*}

\bigskip
\noindent
But our rule (Table \ref{tab:bob})  tells Bob to apply $\mathbf{XZ}$ when he sees \textbf{11} from Alice. Why? Notice the following:

\begin{flalign*}
\mathbf{ZX} \begin{bmatrix} x_0 \\ x_1 \end{bmatrix} &= \mathbf{Z} \begin{bmatrix} x_1 \\ x_0  \end{bmatrix} =  \begin{bmatrix}[r] x_1 \\  - x_0 \end{bmatrix} \\
\mathbf{XZ} \begin{bmatrix} x_0 \\ x_1 \end{bmatrix} &= \mathbf{X} \begin{bmatrix}[r] x_0 \\ - x_1  \end{bmatrix}  = \begin{bmatrix}[r] - x_1 \\  x_0 \end{bmatrix}
\end{flalign*}

\bigskip
\noindent
which implies that

\bigskip

\begin{equation}
\mathbf{ZX} \begin{bmatrix} x_0 \\ x_1 \end{bmatrix}  = - \mathbf{XZ} \begin{bmatrix} x_0 \\ x_1 \end{bmatrix}
\label{eqn:equal}
\end{equation}

\bigskip
\bigskip
\noindent
So now let $x_0 = \beta$ and $x_1 =   \alpha$.  Then

\begin{flalign*}
\mathbf{XZ} \Big [\beta \ket{0} - \alpha \ket{1} \Big ] = \mathbf{XZ} \begin{bmatrix}[r] \beta  \\ - \alpha \end{bmatrix} = \mathbf{X} \begin{bmatrix} \beta \\ \alpha \end{bmatrix}
=  \begin{bmatrix} \alpha \\ \beta \end{bmatrix} = \alpha \ket{0} + \beta \ket{1} = \ket{\psi}
\end{flalign*}

\bigskip
\noindent
and $- \big (\beta \ket{0} - \alpha \ket{1} \big )= -\beta \ket{0} + \alpha \ket{1} \longrightarrow$

\begin{flalign*}
\mathbf{ZX}  \Big [ -\beta \ket{0} + \alpha \ket{1} \Big ] = \mathbf{ZX} \begin{bmatrix}[r] - \beta \\ \alpha \end{bmatrix} = \mathbf{Z} \begin{bmatrix}[r] \alpha \\ - \beta\end{bmatrix}
 = \begin{bmatrix} \alpha \\ \beta \end{bmatrix} = \alpha \ket{0} + \beta \ket{1} = \ket{\psi}
 \end{flalign*}

\bigskip
\bigskip
\noindent
The choice of the transformation rules shown in Table \ref{tab:bob} and Equation \ref{eqn:equal} allows us to write
$\beta \ket{0} - \alpha \ket{1}$ rather than $- \beta \ket{0} + \alpha \ket{1}$.

\bigskip
\noindent
Why do this? One thing it does is make the symmetry in Table \ref{tab:bob} more explicit, but hopefully there is a better reason...

\subsubsection{Cloning and/or Faster Than Light Communication?}
First, no faster-than-light communication occurs since Bob learns nothing from the changes until Alice actually sends the two classical bits to him (even
though Alice operating on $\ket{\phi^{+}_A}$ instantly affects $\ket{\phi^{+}_B}$).

\bigskip
\noindent
The No-Cloning Theorem \cite{2018arXiv180804213E}  is not violated since, even though Bob has an exact copy of $\ket{\psi}$, Alice had to destroy her copy (by
measuring it).

\bigskip
\noindent
Finally, an interesting point is that neither Alice or Bob ever "know"  what $\ket{\psi}$ is (in terms of its actual amplitudes); all they know
is that it was transferred (whatever it was).

\section{Bell and  CHSH}

\bigskip
\noindent

\section{Acknowledgements}

\newpage
\bibliographystyle{plain}
\bibliography{/Users/dmm/papers/bib/qc}

\end{document}