\documentclass[main.tex]{subfiles}
\begin{document}

\marginpar{Wednesday\\ 2020-10-14, \\ compiled \\ \today}

We were talking about Spontaneous Symmetry Breaking: how does it work in a cosmological context?
Specifically, we ask about its effect on cosmological phase transitions at high temperatures in the early universe.

We start out with a scalar field \(\varphi \) with Lagrangian\footnote{We can write it with partial derivatives instead of covariant ones since for a scalar \(\varphi \) they are equal: \(\nabla_{\mu } \varphi = \partial_{\mu} \varphi \).}
%
\begin{align}
\mathscr{L}_\varphi =
- \frac{1}{2} g^{\mu \nu } \partial_{\mu } \varphi \partial_{\nu } \varphi
- V(\varphi )
\,,
\end{align}
%
where we choose a potential
%
\begin{align}
V(\varphi ) = \frac{\lambda }{4} \qty(\varphi^2 - \sigma^2)^2
\,.
\end{align}

This is the typical example of a potential which exhibits SSB. Its vacuum (minimum) is a pair of points at \(\abs{\varphi} = \sigma \).

The Lagrangian is invariant under \(\varphi \to - \varphi \); either of the vacuum states is not.

We need to consider finite-temperature effects on the propagator of the scalar field.
The temperature corrections to this potentials yields a temperature-dependent mass term, which looks like
%
\begin{align}
m^2_T = \alpha \lambda T^2
\,,
\end{align}
%
where \(\lambda \) is the coupling of the field, while \(\alpha \) is a dimensionless order-1 number.

Then, the potential reads
%
\begin{align}
V_T (\varphi ) = V_{T=0}(\varphi ) + \frac{1}{2} \alpha \lambda \varphi^2 T^2
\,.
\end{align}

If the temperature is sufficiently high, the potential will have only one vacuum again.
This means that if we go far enough back in time the symmetry is restored.

The moment at which the potential goes from one minimum to two is the one at which we have a \textbf{phase transition}. At which temperature does it happen? We can find out by considering the sign of the second derivative of the potential at \(\varphi = 0\):
%
\begin{align}
\eval{\dv[2]{V}{\varphi }}_{\varphi =0}  = - \lambda \sigma^2 + \lambda \alpha T^2
\,,
\end{align}
%
so we have a critical temperature \(T \approx \sigma / \sqrt{\alpha }\) at which the symmetry is broken.

\subsection{Topological defects}

The defects are quite similar to the defects we find in regular phase transitions we know at our scales, like water to ice: the crystal which forms is not perfect.

The minima \(\varphi = \pm \sigma \) are the \emph{true vacuum} of the system, while \(\varphi = 0\) is the \emph{false vacuum}.

There will be regions in the universe in which the scalar field goes to \(+ \sigma \), and other regions in which it goes into \(- \sigma \).
This is because the two minima are equivalent: there are even odds for the field at any point to fall into either. In causally connected regions it will go into the same minimum.
There will then be boundaries between the regions in which the field goes into \(+ \sigma \) and \(- \sigma \).

In a mostly-plus metric signature, the equation of motion reads
%
\begin{align}
\square \varphi = \pdv{V}{\varphi }
\,,
\end{align}
%
so if we neglect the curvature and consider static solutions we will have
%
\begin{align}
\nabla^2 \varphi = \pdv{V}{\varphi }
\,.
\end{align}

%% GOT HERE

Further, we consider an infinite \textbf{domain wall} in the \(xy\) plane, assuming that for \(z \to \pm \infty \) we have \(\varphi = \pm \sigma \). Also, we assume that the whole field has no \(x\) or \(y\) dependence.
Let us then substitute into the equation:
%
\begin{align}
- \pdv[2]{\varphi }{z} = - \pdv{V}{\varphi } = - \lambda \varphi (\varphi^2 - \sigma^2)
\,.
\end{align}

Solving this yields
%
\begin{align}
\varphi (z) = \sigma \tanh \qty( \frac{z}{\Delta })
\,,
\end{align}
%
where \(\Delta \) is the \emph{thickness} of the wall, which we can estimate through energetic configurations: the surface energy will have contributions through the gradient of the field: \( \Delta (\partial_{z} \varphi)^2 \sim \Delta \sigma^2 / \Delta^2 = \sigma^2 / \Delta  \); and a potential term \(V(\varphi ) \sim \Delta V(\varphi =0) \sim \Delta \lambda \sigma^{4} / 4\).

This is because the total Hamiltonian for a unit-area region of this stationary configuration will also look like
%
\begin{align}
H &= \int \qty[\frac{1}{2} g^{\mu \nu } \partial_{\mu } \varphi \partial_{\nu } \varphi + V(\varphi ) ] \dd{z}  \\
&= \int \frac{1}{2} \qty(\partial_{z} \varphi )^2 + V(\varphi ) \dd{z}  \\
&\approx \frac{\Delta}{2} \eval{\qty(\partial_{z} \varphi)^2}_{z=0} + \frac{\lambda}{4} \sigma^4 \Delta  \underbrace{\int \qty(\tanh^2 z - 1)^2 \dd{z}}_{\order{1}}   \\
&\approx \Delta \frac{\sigma^2}{\Delta^2} + \frac{\lambda}{4} \sigma^4 \Delta
\,.
\end{align}

% \todo[inline]{Add clarification of the estimates. Gradient of the field is the kinetic term?}

The two contributions scale oppositely with \(\Delta \): the kinetic energy decreases for a wide wall, the potential energy decreases for a narrow wall.
Then, we can find an optimum at \(\Delta \sim 1 / (\sigma \sqrt{\lambda })\).

This domain wall is not removable, the configuration is topologically stable.

Now we discuss the \textbf{Kibble mechanism}, which demonstrates how phase transitions always generate domain walls.
Let us denote as \(\xi \) the typical linear size of the domains: it is called the \emph{correlation length} of \(\varphi \).

We know that in the radiation-dominated epoch there is a finite particle horizon \(d_H(t) \approx 2 t\), so we must have \(\xi \lesssim d_H (t)\), since regions which were further apart could not have communicated yet at that time.

Then, we find a lower bound on the number density of the domain walls, \(n_X \sim \xi^{-3} \gtrsim d_H^{-3}(t) = (2t)^{-3}\).

Recall from regular HBB cosmology that
%
\begin{align}
H^2(t) = \frac{8 \pi G}{3} \rho _r = \frac{8 \pi G}{3} \frac{\pi^2}{30} g_* T^{4}
\,,
\end{align}
%
so
%
\begin{align}
t = \frac{1}{2 H} \approx \num{.3} \frac{1}{\sqrt{g_*}} \frac{M _{\text{Pl}}}{T^2}
\,,
\end{align}
%
therefore
%
\begin{align}
n_X \gtrsim \qty(\frac{\sqrt{g_*}}{\num{.6}} \frac{T}{M _{\text{Pl}}})^3 T^3 \sim \qty(\frac{\sqrt{g_*}}{\num{.6}} \frac{T}{ M _{\text{Pl}}})^3 n_\gamma (T)
\,,
\end{align}
%
since the number density of photons scales like \(n_\gamma (T) \sim T^3\).

Let us evaluate this number density, for \(T \sim T _{\text{GUT}} \sim \SI{e15}{GeV}\).
Here, \(g_* \sim 100\), meaning that we get
%
\begin{align}
n_X (T _{\text{GUT}}) > \num{e-9} \divisionsymbol \num{e-10} n_\gamma (T _{\text{GUT}})
\,.
\end{align}

Therefore, we have the ratio
%
\begin{align}
\frac{n_X (T _{\text{GUT}})}{n_\gamma (T _{\text{GUT}})} > \num{e-9} \divisionsymbol \num{e-10}
\,.
\end{align}

If we assume that after production these objects are stable, there are no processes which can modify their number. Then, for lower temperatures we keep the same ratio, both number densities will scale like \(n_\gamma \sim T^3 \sim a^{-3}\).

This is a very similar number to the ratio of baryons to photons, \(\eta = n_b / n_\gamma \)!
This means that
%
\begin{align}
\Omega_{0x} = \frac{m_x \eta _x(t_0 )}{\rho _{\text{crit}}}
\gtrsim \frac{m_x \eta_{0b}}{\rho _{\text{crit}}} = \frac{m_x}{m_p}  \Omega_{0b}
\,,
\end{align}
%
which means that, since \(m_x \sim T _{\text{GUT}} \sim \SI{e15}{GeV}\), we must have \(\Omega_{0x} \gtrsim \num{e14}\)! This definitely \textbf{over-closes} the universe.

How does inflation solve this problem? These objects are produced in these early stages, but their number density is very \textbf{diluted}.
Each \(\pm \sigma \) region is inflated to the size of the observable universe.

Now we will give some arguments as to why a scalar field makes sense, a characterization of different inflationary models, and discuss the generation of the first primordial density perturbations.

A De Sitter phase is one with a cosmological constant \(\Lambda \):
%
\begin{align}
H^2= \frac{8 \pi G}{3} \rho _\Lambda - \frac{k}{a^2}
\,.
\end{align}

Here \(P_\Lambda = - \rho _\Lambda \).
Then, \(a(t) \propto \exp(Ht)\), with \(H = \const\). This \(\rho _\Lambda\) is constant as the universe expands.

A cosmological constant term can be written in terms of a vacuum energy density of the quantum system. It appears in the EFE as
%
\begin{align}
R_{\mu \nu } - \frac{1}{2} g_{\mu \nu } R = 8 \pi G T_{\mu \nu } - \Lambda g_{\mu \nu }
\,.
\end{align}

This can be calculated as \(\bra{0} T_{\mu \nu } \ket{0} \propto
 - \bra{0} \varphi \ket{0} g_{\mu \nu }= - \expval{\rho } g_{\mu \nu }\).

Plugging this into the EFE we find
%
\begin{align}
\Lambda = - 8 \pi G \expval{\rho }
\,.
\end{align}

We cannot get rid of the vacuum energy density of the system, since energy gravitates.

Let us come back to the Lagrangian
%
\begin{align}
\mathscr{L}_{\varphi } = - \frac{1}{2} g^{\mu \nu } \partial_{\mu } \varphi \partial_{\nu } \varphi - V(\varphi )
\,,
\end{align}
%
whose energy momentum tensor is
%
\begin{align}
T^{\varphi }_{\mu \nu } = \partial_{\mu } \varphi \partial_{\nu } \varphi + \mathscr{L}_{\varphi } g_{\mu \nu }
\,.
\end{align}

Let us look at the Vacuum Expectation Value of the field: \(\expval{\varphi } = \bra{0} \varphi \ket{0}\). If this is a constant, it should correspond to the minimum of the classical potential: the ground state.
This behaves like a cosmological constant.
Since \(\varphi \) is a constant, we have
%
\begin{align}
\expval{T_{\mu \nu }} = g_{\mu \nu } V(\expval{\phi })
\,,
\end{align}
%
since the derivatives of a constant vanish.
This is an effective \(\Lambda \).

A phase transition can move us away from this Vacuum Energy Value (VEV).

The VEV of \(\varphi \) can be a function of time.

Are there other options beyond a scalar field? Say, a vector field, or a spinor?
The first reason we do not choose this is because it breaks isotropy.

\end{document}


\chapter{Stopped martingales (TO DO)}
\section{How to make money almost surely}
We now take our newfound knowledge of measure theory to a casino.

Here's the most classical example that shows up:
a casino lets us play a game where we can bet any amount of
on a fair coin flip, but with bad odds:
we win $\$n$ if the coin is heads,
but lose $\$2n$ if the coin is tails,
for a value of $n$ of our choice.
This seems like a game that no one in their right mind would want to play.

Well, if we have unbounded time and money,
we actually can almost surely make a profit.
\begin{example}
	[Being even greedier than 18th century France]
	In the game above, we start by betting $\$1$.
	\begin{itemize}
		\ii If we win, we leave having made $\$1$.
		\ii If we lose, we then bet $\$10$ instead, and
		\begin{itemize}
			\ii If we win, then we leave having made $\$10-\$2=\$8$, and
			\ii If we lose then we bet $\$100$ instead, and
			\begin{itemize}
				\ii If we win, we leave having made $\$1000-\$20-\$2=\$978$, and
				\ii If we lose then we bet $\$1000$ instead, and so on\dots
			\end{itemize}
		\end{itemize}
	\end{itemize}
	Since the coin will almost surely show heads eventually,
	we make money whenever that happens.
	In fact, the expected amount of time until a coin shows heads
	is only $2$ flips! What could go wrong?
\end{example}
This chapter will show that under sane conditions
such as ``finite time'' or ``finite money'',
one cannot actually make money in this way --- the \emph{optional stopping theorem}.
This will give us an excuse to define conditional probabilities,
and then talk about martingales (which generalize the fair casino).

Once we realize that trying to extract money from Las Vegas is a lost cause,
we will stop gambling and then return to solving math problems,
by showing some tricky surprises,
where problems that look like they have nothing to do with gambling
can be solved by considering a suitable martingale.

In everything that follows, $\Omega = (\Omega, \SA, \mu)$ is a probability space.

\section{Sub-$\sigma$-algebras and filtrations}
\prototype{$\sigma$-algebra generated by a random variable, and coin flip filtration.}
We considered our $\Omega$ as a space of worlds,
equipped with a $\sigma$-algebra $\SA$ that lets us integrate over $\Omega$.
However, it is a sad fact of life that at any given time,
you only know partial information about the world.
For example, at the time of writing,
we know that the world did not end in 2012
(see \url{https://en.wikipedia.org/wiki/2012_phenomenon}),
but the fate of humanity in future years remains at slightly uncertain.

Let's write this measure-theoretically: we could consider
\begin{align*}
	\Omega &= A \sqcup B \\
	A &= \left\{ \omega \text{ for which world ends in $2012$} \right\} \\
	B &= \left\{ \omega \text{ for which world does not end in $2012$} \right\}.
\end{align*}
We will assume that $A$ and $B$ are measurable sets,
that is, $A,B \in \SA$.
That means we could have good fun arguing about what the values
of $\mu(A)$ and $\mu(B)$ should be
(``a priori probability that the world ends in $2012$''),
but let's move on to a different silly example.

We will now introduce a new notion that
we will need when we define conditional probabilities later.
\begin{definition}
	Let $\Omega = (\Omega, \SA, \mu)$ be a probability space.
	A \vocab{sub-$\sigma$-algebra} $\SF$
	on $\Omega$ is exactly what it sounds like:
	a $\sigma$-algebra $\SF$ on the set $\Omega$
	such that each $A \in \SF$ is measurable
	(i.e.,\ $\SF \subseteq \SA$).
\end{definition}

The motivation is that $\SF$ is the $\sigma$-algebra of sets
which let us ask questions about some piece of information.
For example, in the 2012 example we gave above,
we might take $\SF = \{\varnothing, A, B, \Omega\}$,
which are the sets we care about if we are thinking only about 2012.

Here are some more serious examples.
\begin{example}
	[Examples of sub-$\sigma$-algebras]
	\listhack
	\begin{enumerate}[(a)]
		\ii Let $X \colon \Omega \to \{0,1,2\}$ be a random
		variable taking on one of three values.
		If we're interested in $X$ then we could define
		\begin{align*}
			A &= \{\omega \colon X(\omega) = 1\} \\
			B &= \{\omega \colon X(\omega) = 2\} \\
			C &= \{\omega \colon X(\omega) = 3\}
		\end{align*}
		then we could write
		\[ \SF = \left\{ \varnothing, \; A, \; B, \; C, \;
				A \cup B, \; B \cup C, \; C \cup A, \; \Omega \right\}. \]
		This is a sub-$\sigma$-algebra on $\SF$
		that lets us ask questions about $X$
		like ``what is the probability $X \ne 3$'', say.

		\ii Now suppose $Y \colon \Omega \to [0,1]$ is another random variable.
		If we are interested in $Y$,
		the $\SF$ that captures our curiosity is
		\[ \SF = \left\{ Y\pre(B) \mid B \subseteq [0,1]
			\text{ is measurable } \right\}. \]
	\end{enumerate}
\end{example}

You might notice a trend here which we formalize now:
\begin{definition}
	Let $X \colon \Omega \to \RR$ be a random variable.
	The \vocab{sub-$\sigma$-algebra generated by $X$} is defined by
	\[ \sigma(X) \defeq \left\{ X\pre(B) \mid B \subseteq \RR
		\text{ is measurable } \right\}. \]
	If $X_1$, \dots is a sequence (finite or infinite) of random variables,
	the sub-$\sigma$-algebra generated by them
	is the smallest $\sigma$-algebra which contains $\sigma(X_i)$ for each $i$.
\end{definition}

Finally, we can put a lot of these together ---
since we're talking about time, we learn more as we grow older,
and this can be formalized.
\begin{definition}
	A \vocab{filtration} on $\Omega = (\Omega, \SA, \mu)$
	is a nested sequence\footnote{For convenience,
		we will restrict ourselves to $\ZZ_{\ge0}$-indexed
		filtrations, though really any index set is okay.}
	\[ \SF_0 \subseteq \SF_1 \subseteq \SF_2 \subseteq \dots \]
	of sub-$\sigma$-algebras on $\Omega$.
\end{definition}

\begin{example}
	[Filtration]
	Suppose you're bored in an infinitely long class
	and start flipping a fair coin to pass the time.
	(Accordingly, we could let $\Omega = \{H,T\}^\infty$
	consist of infinite sequences of heads $H$ and tails $T$.)
	We could let $\SF_n$ denote the sub-$\sigma$-algebra
	generated by the values of the first $n$ coin flips.
	So:
	\begin{itemize}
		\ii $\SF_0 = \{\varnothing, \Omega\}$,
		\ii $\SF_1 = \{\varnothing, \text{first flip $H$}, \text{first flip $T$}, \Omega\}$,
		\ii $\SF_2 = \{\varnothing, \text{first flips $HH$}, \text{second flip $T$}, \Omega, \text{first flip and second flip differ}, \dots\}$.
		\ii and so on, with $\SF_n$ being the measurable sets
		``determined'' only by the first $n$ coin flips.
	\end{itemize}
\end{example}

\begin{exercise}
	In the previous example, compute the cardinality $|\SF_n|$ for each integer $n$.
\end{exercise}

\section{Conditional expectation}
\prototype{$\EE(X \mid X+Y)$ for $X$ and $Y$ distributed over $[0,1]$.}

We'll need the definition of conditional probability to define a martingale,
but this turns out to be surprisingly tricky.
Let's consider the following simple example to see why.
\begin{example}
	[Why high-school methods aren't enough here]
	Suppose we have two independent random variables $X$, $Y$ distributed
	uniformly over $[0,1]$ (so we may as well take $\Omega = [0,1]^2$).
	We might try to ask the question:
	\begin{quote}
		\itshape
		``what is the expected value of $X$
		given that $X+Y = 0.6$''?
	\end{quote}
	Intuitively, we know the answer has to be $0.3$.
	However, if we try to write down a definition, we quickly run into trouble.
	Ideally we want to say something like
	\[ \EE[X \text{ given } X+Y=0.6]
		= \frac{\int_{S} X}{\int_{S} 1}
		\text{ where }
		S = \left\{ \omega \in \Omega \mid X(\omega)+Y(\omega)=0.6 \right\}.  \]
	The problem is that $S$ is a set of measure zero,
	so we quickly run into $\frac 00$, meaning a definition
	of this shape will not work out.
\end{example}

The way that this is typically handled in measure theory
is to use the notion of sub-$\sigma$-algebra that we defined.
Let $\SF$ be a sub-$\sigma$-algebra which captures the information
This means we create a function assigning the
``conditional expectation'' to \emph{every} point $\omega \in \Omega$,
which is measurable with respect to $\SF$.
\todo{give the example}

\begin{proposition}
	[Conditional expectation definition]
	\label{prop:conditional_exp}
	Let $X \colon \Omega \to \RR$ be an \emph{absolutely integrable}
	random variable (meaning $\EE[|X|] < \infty$)
	over a probability space $\Omega$,
	and let $\SF$ be a sub-$\sigma$-algebra on it.

	Then there exists a function $\eta \colon \Omega \to \RR$
	satisfying the following two properties:
	\begin{itemize}
		\ii $\eta$ is $\SF$-measurable (that is,
			measurable as a function $(\Omega, \SF, \mu) \to \RR$); and
		\ii for any set $A \in \SF$ we have
		$\EE[\eta \cdot \mathbf{1}_A] = \EE[X \cdot \mathbf{1}_A]$.
	\end{itemize}
	Moreover, this random variable is unique up to almost sureness.
\end{proposition}
\begin{proof}
	Omitted, but relevant buzzword used is ``Radon-Nikodym derivative''.
\end{proof}

\begin{definition}
	Let $\eta$ be as in the previous proposition.
	\begin{itemize}
		\ii We denote $\eta$ by $\EE(X \mid \SF)$
		and call it the \vocab{conditional expectation} of $X$ with respect to $\SF$.
		\ii If $Y$ is a random variable then
		$\EE(X \mid Y)$ denotes $\EE(X \mid \sigma(Y))$,
		i.e.\ the conditional expectation of $X$
		with respect to the $\sigma$-algebra generated by $Y$.
	\end{itemize}
\end{definition}

More fine print:
\begin{remark}
	[This notation is terrible]
	The notation $\EE(X \mid \SF)$ is admittedly confusing,
	since it is actually an entire function $\Omega \to \RR$,
	rather than just a real number like $\EE[X]$.
	For this reason I try to be careful to remember
	to use parentheses rather than square brackets
	for conditional expectations; not everyone does this.
\end{remark}

\begin{abuse}
	In addition, when we write $Y = \EE(X \mid \SF)$,
	there is some abuse of notation happening here
	since $\EE(X \mid \SF)$ is defined only up to some reasonable uniqueness
	(i.e.\ up to measure zero changes).
	So this really means that
	``$Y$ satisfies the hypothesis of \Cref{prop:conditional_exp}'',
	but this is so pedantic that no one bothers.
\end{abuse}

\todo{properties}

\section{Supermartingales}
\prototype{Visiting a casino is a supermartingale, assuming house odds.}

\begin{definition}
	Let $X_0$, $X_1$, \dots be a sequence of random variables
	on a probability space $\Omega$,
	and let $\SF_0 \subseteq \SF_1 \subseteq \cdots$ be a filtration.

	Then $(X_n)_{n \ge 0}$ is a \vocab{supermartingale}
	with respect to $(\SF_n)_{n \ge 0}$ if the following conditions hold:
	\begin{itemize}
		\ii $X_n$ is absolutely integrable for every $n$;
		\ii $X_n$ is measurable with respect to $\SF_n$; and
		\ii for each $n = 1, 2, \dots$ the inequality
		\[ \EE(X_n \mid \SF_{n-1}) \le X_{n-1} \]
		holds for all $\omega \in \Omega$.
	\end{itemize}

	In a \vocab{submartingale} the inequality $\le$ is replaced with $\ge$,
	and in a \vocab{martingale} it is replaced by $=$.
\end{definition}

\begin{abuse}
	[No one uses that filtration thing anyways]
	We will always take $\SF_n$ to be the $\sigma$-algebra
	generated by the previous variables $X_0$, $X_1$, \dots, $X_{n-1}$,
	and do so without further comment.
	Nonetheless, all the results that follow hold in the more general setting
	of a supermartingale with respect to some filtration.
\end{abuse}

We will prove all our theorems for supermartingales;
the analogous versions for submartingales can be obtained
by replacing $\le$ with $\ge$ everywhere
(since $X_n$ is a martingale iff $-X_n$ is a supermartingale)
and for martingales by replacing $\le$ with $=$ everywhere
(since $X_n$ is a martingale iff it is both a supermartingale
and a submartingale).

Let's give examples.
\begin{example}
	[Supermartingales]
	\listhack
	\begin{enumerate}[(a)]
		\ii \textbf{Random walks}:
		an ant starts at the position $0$ on the number line.
		Every minute, it flips a fair coin and either
		walks one step left or one step right.
		If $X_t$ is the position at the $t$th time,
		then $X_t$ is a martingale, because
		\[ \EE(X_t \mid X_0, \dots, X_{t-1})
			= \frac{(X_{t-1}+1) + (X_{t-1}-1)}{2} = X_{t-1}. \]

		\ii \textbf{Casino game}:
		Consider a gambler using the strategy described
		at the beginning of the chapter.
		This is a martingale, since every bet the gambler makes
		has expected value $0$.

		\ii \textbf{Multiplying independent variables}:
		Let $X_1$, $X_2$, \dots, be independent (not necessarily
		identically distributed) integrable random variables with mean $1$.
		Then the sequence $Y_1$, $Y_2$ \dots defined by
		\[ Y_n \defeq X_1 X_2 \dots X_n \]
		is a martingale; as
		$\EE(Y_n \mid Y_1, \dots, Y_{n-1}) = \EE[Y_n] \cdot Y_{n-1} = Y_{n-1}$.

		\ii \textbf{Iterated blackjack}:
		Suppose one shows up to a casino and plays
		infinitely many games of blackjack.
		If $X_t$ is their wealth at time $t$, then $X_t$ is a supermartingale.
		This is because each game has negative expected value (house edge).
	\end{enumerate}
\end{example}

\begin{example}
	[Frivolous/inflamamtory example --- real life is a supermartingale]

	Let $X_t$ be your happiness on day $t$ of your life.
	Life has its ups and downs,
	so it is not the case that $X_t \le X_{t-1}$ for every $t$.
	For example, you might win the lottery one day.

	However, on any given day, many things can go wrong (e.g.\ zombie apocalypse),
	and by Murphy's Law this is more likely than things going well.
	Also, as you get older, you have an increasing number of responsibilities
	and your health gradually begins to deteriorate.

	Thus it seems that
	\[ \EE(X_t \mid X_0, \dots, X_{t-1}) \le X_{t-1} \]
	is a reasonable description of the future ---
	\emph{in expectation}, each successive day is
	slightly worse than the previous one.
	(In particular, if we set $X_t = -\infty$ on death,
	then as long as you have a positive probability of dying,
	the displayed inequality is obviously true.)
\end{example}

Before going on, we will state without proof one useful result:
if a martingale is bounded, then it will almost certainly converge.

\begin{theorem}
	[Doob's martingale convergence theorem]
	\label{thm:doob_martingale_converge}
	Let $X_0$, \dots be a supermartingale on a
	probability space $\Omega$ such that
	\[ \sup_{n \in \ZZ_{\ge 0}}
		\EE \left[ \left\lvert X_n \right\rvert \right] < \infty. \]
	Then, there exists a random variable $X_\infty \colon \Omega \to \RR$
	such that
	\[ X_n \asto X_\infty. \]
\end{theorem}

\section{Optional stopping}
\prototype{Las Vegas.}

In the first section we described how to make money almost surely.
The key advantage the gambler had was the ability to quit whenever he wanted
(equivalently, an ability to control the size of the bets;
betting \$0 forever is the same as quitting.)
Let's formalize a notion of stopping time.

The idea is we want to define a function
$\tau \colon \Omega \to \{0, 1, \dots, \infty\}$ such that
\begin{itemize}
	\ii $\tau(\omega)$ specifies the index
	after which we \emph{stop} the martingale.
	Note that the decisions to stop after time $n$
	must be made with only the information available at that time ---
	i.e., with respect to $\SF_n$ of the filtration.

	\ii $X_{\tau \wedge n}$ is the random value representing the
	value at time $n$ of the stopped martingale,
	where if $n$ is \emph{after} the stopping time,
	we just take it to be the our currently value after we leave.

	So for example in a world $\omega$ where we stopped at time $3$, then
	$X_{\tau \wedge 0}(\omega) = X_0(\omega)$,
	$X_{\tau \wedge 1}(\omega) = X_1(\omega)$,
	$X_{\tau \wedge 2}(\omega) = X_2(\omega)$,
	$X_{\tau \wedge 3}(\omega) = X_3(\omega)$, but then
	\[ X_3(\omega)
		= X_{\tau \wedge 4}(\omega)
		= X_{\tau \wedge 5}(\omega)
		= X_{\tau \wedge 6}(\omega)
		= \dots
	\]
	since we have stopped --- the value stops changing.

	\ii $X_{\tau}$ denotes the eventual value after we stop
	(or the limit $X_\infty$ if we never stop).
\end{itemize}

Here's the compiled machine code.
\begin{definition}
	Let $\SF_0 \subseteq \SF_1 \subseteq \cdots$ be a filtration
	on a probability space $\Omega$.
	\begin{itemize}
		\ii A \vocab{stopping time} is a function
		\[ \tau \colon \Omega \to \{0, 1, 2, \dots\} \cup \{\infty\} \]
		with the property that for each integer $n$, the set
		\[ \left\{ \omega \in \Omega \mid \tau(\omega) = n \right\} \]
		is $\SF_n$-measurable (i.e., is in $\SF_n$).

		\ii For each $n \ge 0$ we define
		$X_{\tau \wedge n} \colon \Omega \to \RR$ by
		\[ X_{\tau \wedge n}(\omega)
		= X_{\min \left\{ \tau(\omega), n \right\}}(\omega) \]

		\ii Finally, we let the eventual outcome be denoted by
		\[ X_\tau(\omega)
			= \begin{cases}
				X_{\tau(\omega)}(\omega) & \tau(\omega) \ne \infty \\
				\lim_{n \to \infty} X_n(\omega) & \tau(\omega) = \infty
				\text{ and } \lim_{n \to \infty} X_n(\omega) \text{ exists } \\
				\text{undefined} & \text{otherwise}.
			\end{cases}
		\]
		We require that the ``undefined'' case occurs
		only for a set of measure zero
		(for example, if \Cref{thm:doob_martingale_converge} applies).
		Otherwise we don't allow $X_\tau$ to be defined.
	\end{itemize}
\end{definition}

\begin{proposition}
	[Stopped supermartingales are still supermartingales]
	Let $X_0$, $X_1$, \dots be a supermartingale.
	Then the sequence
	\[ X_{\tau \wedge 0}, \; X_{\tau \wedge 1}, \; \dots \]
	is itself a supermartingale.
\end{proposition}
\begin{proof}
	We have almost everywhere the inequalities
	\begin{align*}
		\EE\left( X_{\tau \wedge n} \mid \SF_{n-1} \right)
		&= \EE \left( X_{n-1} + \mathbf 1_{\tau(\omega) = n-1} (X_n - X_{n-1}) \mid \SF_{n-1} \right) \\
		&= \EE \left( X_{n-1} \mid \SF_{n-1} \right)
		+ \EE \left( \mathbf 1_{\tau(\omega) = n-1} \cdot (X_n - X_{n-1}) \mid \SF_{n-1} \right) \\
		&= X_{n-1} + \mathbf 1_{\tau(\omega) = n-1}
			\cdot\EE \left(  X_n - X_{n-1} \mid \SF_{n-1} \right)
		\le X_{n-1}
	\end{align*}
	as functions from $\Omega \to \RR$.
\end{proof}

\begin{theorem}
	[Doob's optional stopping theorem]
	Let $X_0$, $X_1$, \dots be a supermartingale on a probability space $\Omega$,
	with respect to a filtration $\SF_0 \subseteq \SF_1 \subseteq \cdots$.
	Let $\tau$ be a stopping time with respect to this filtration.
	Suppose that \emph{any} of the following hypotheses are true,
	for some constant $C$:
	\begin{enumerate}[(a)]
		\ii \textbf{Finite time}: $\tau(\omega) \le C$ for almost all $\omega$.
		\ii \textbf{Finite money}: for each $n \ge 1$,
		$\left\lvert X_{\tau \wedge n}(\omega) \right\rvert \le C$
		for almost all $\omega$.
		\ii \textbf{Finite bets}: we have $\mathbb E[\tau] < \infty$,
		and for each $n \ge 1$, the conditional expectation
		\[ \EE\left( \left\lvert X_n-X_{n-1} \right\rvert
			\mid \SF_n \right) \]
		takes on values at most $C$ for almost all $\omega \in \Omega$
		satisfying $\tau(\omega) \ge n$.
	\end{enumerate}
	Then $X_\tau$ is well-defined almost everywhere,
	and more importantly, \[ \EE[X_\tau] \le \EE[X_0]. \]
\end{theorem}
The last equation can be cheekily expressed as
``the only winning move is not to play''.

\begin{proof}
	\todo{do later tonight}
\end{proof}

\begin{exercise}
	Conclude that going to Las Vegas with the strategy
	described in the first section is a really bad idea.
	What goes wrong?
\end{exercise}

\section{Fun applications of optional stopping (TO DO)}
%% for 18.A34 we can do the random walk example
We now give three problems which showcase some of the power of
the results we have developed so far.

\subsection{The ballot problem}
Suppose Alice and Bob are racing in an election;
Alice received $a$ votes total while Bob received $b$ votes total, and $a > b$.
If the votes are chosen in random order,
one could ask: what is the probability that Alice never falls behind
Bob in the election?

\missingfigure{path}

\begin{proposition}
	[Ballot problem]
	This occurs with probability $\frac{a-b}{a+b}$.
\end{proposition}

\subsection{ABRACADABRA}

\subsection{USA TST 2018}

\section{\problemhead}

\begin{problem}
	[Examples of martingales]
	We give some more examples of martingales.
	\begin{enumerate}[(a)]
		\ii \textbf{(Simple random walk)}
		Let $X_1$, $X_2$, \dots be i.i.d.\ random variables
		which equal $+1$ with probability $1/2$,
		and $-1$ with probability $1/2$.
		Prove that
		\[ Y_n = \left( X_1 + \dots + X_n \right)^2 - n \]
		is a martingale.

		\ii \textbf{(de Moivre's martingale)}
		Fix real numbers $p$ and $q$ such that $p,q > 0$ and $p+q=1$.
		Let $X_1$, $X_2$, \dots be i.i.d.\ random variables
		which equal $+1$ with probability $p$,
		and $-1$ with probability $q$.
		Show that
		\[ Y_n = \left(qp^{-1}\right)^{X_1 + X_2 + \dots + X_n} \]
		is a martingale.

		\ii \textbf{(P\'{o}lya's urn)}
		An urn contains one red and one blue marble initially.
		Every minute, a marble is randomly removed from the urn,
		and two more marbles of the same color are added to the urn.
		Thus after $n$ minutes, the urn will have $n+2$ marbles.

		Let $r_n$ denote the fraction of marbles which are red.
		Show that $r_n$ is a martingale.
	\end{enumerate}
\end{problem}

\begin{problem}
	A deck has $52$ cards; of them $26$ are red and $26$ are black.
	The cards are drawn and revealed one at a time.
	At any point, if there is at least one card remaining in the deck,
	you may stop the dealer;
	you win if (and only if) the next card in the deck is red.
	If all cards are dealt, then you lose.
	Across all possible strategies,
	determine the maximal probability of winning.
	\begin{hint}
		There is a cute elementary solution.
		For the martingale-based solution,
		show that the fraction of red cards in the deck is a martingale
		at time $n$ is a martingale.
	\end{hint}
\end{problem}

\begin{problem}
	[Wald's identity]
	Let $\mu$ be a real number.
	Let $X_1$, $X_2$, \dots be independent random variables
	on a probability space $\Omega$ with mean $\mu$.
	Finally let $\tau \colon \Omega \to \{1, 2, \dots\}$
	be a stopping time such that $\mathbb E[\tau] < \infty$,
	such that the event $\tau = n$ depends only on $X_1$, \dots, $X_n$.

	Prove that
	\[ \EE[X_1 + X_2 + \dots + X_\tau] = \mu \EE[\tau]. \]
\end{problem}

\begin{problem}
	[Unbiased drunkard's walk]
	An ant starts at $0$ on a number line,
	and walks left or right one unit with probability $1/2$.
	It stops once it reaches either $-17$ or $+8$.
	\begin{enumerate}[(a)]
		\ii Find the probability it reaches $+8$ before $-17$.

		\ii Find the expected value of the amount of time
		it takes to reach either endpoint.
	\end{enumerate}
\end{problem}

\begin{problem}
	[Biased drunkard's walk]
	Let $0 < p < 1$ be a real number.
	An ant starts at $0$ on a number line,
	and walks left or right one unit with probability $p$.
	It stops once it reaches either $-17$ or $+8$.
	Find the probability it reaches $+8$ first.
\end{problem}

\begin{problem}
	The number $1$ is written on a blackboard.
	Every minute, if the number $a$ is written on the board,
	it's erased and replaced by a real number
	in the interval $[0, 2.01a]$ selected uniformly at random.
	What is the probability that the resulting sequence of numbers approaches $0$?
	\begin{hint}
		It occurs with probability $1$.
		If $X_n$ is the number on the board at step $n$,
		and $\mu = \frac{1}{2.01} \int_0^{2.01} \log t \; dt$,
		show that $\log(X_n) - n \mu$ is a martingale.
		(Incidentally, using the law of large numbers could work too.)
	\end{hint}
\end{problem}


\subsection{Free groups}\label{subsec:free_groups}

\begin{definition}\label{def:free_monoid}
  Let \( S \) be an arbitrary set. We associate with \( S \) its \term{free monoid} \( F(S) \coloneqq (S^{\ast}, \cdot) \), where \( S^{\ast} \) is the \hyperref[def:formal_language/kleene_star]{Kleene star} and \( \cdot \) is \hyperref[def:formal_language/concatenation]{concatenation}.
\end{definition}
\begin{proof}
  It is a monoid due to \fullref{thm:kleene_star_is_monoid}.
\end{proof}

\begin{proposition}\label{thm:free_monoid_universal_property}
  For every set \( A \), denote by \( \iota_A: A \to F(A) \) the canonical inclusion function, which sends every member of \( A \) into the corresponding single-symbol word in the \hyperref[def:free_monoid]{free monoid} \( F(A) \).

  As a consequence of \fullref{thm:free_monoid_universal_property}, \( F(A) \) is the unique up to an isomorphism monoid that satisfies the following \hyperref[rem:universal_mapping_property]{universal mapping property}:
  \begin{displayquote}
    For every monoid \( \mscrM \) and every function \( f: A \to \mscrM \), there exists a unique monoid homomorphism \( \widetilde{f}: F(A) \to \mscrM \) such that the following diagram commutes:
    \begin{equation}\label{eq:def:free_monoid/diagram}
      \begin{aligned}
        \includegraphics[page=1]{output/def__free_monoid.pdf}
      \end{aligned}
    \end{equation}
  \end{displayquote}
\end{proposition}
\begin{proof}
  For every function \( f: A \to \mscrM \), we have the monoid homomorphism
  \begin{equation*}
    \begin{aligned}
      &\widetilde{f}: F(A) \to \mscrM, \\
      &\widetilde{f}(x_1 x_2 \ldots x_n) \coloneqq f(x_1) \cdot f(x_2) \cdot \ldots \cdot f(x_n)
    \end{aligned}
  \end{equation*}
  obtained by applying the monoid operation \( \cdot \) recursively to the pointwise image
  \begin{equation*}
    f(x_1) f(x_2) \ldots f(x_n)
  \end{equation*}
  of the word
  \begin{equation*}
    x_1 x_2 \ldots x_n.
  \end{equation*}

  The homomorphism \( \widetilde{f} \) is uniquely determined by the action of \( f \) on single-symbol words.
\end{proof}

\begin{corollary}\label{thm:free_monoid_functor}
  Consider the functor \( F: \cat{Set} \to \cat{Mon} \) defined for objects pointwise in \fullref{def:free_monoid}. For every function \( f: A \to B \), define the \hyperref[def:unital_magma/homomorphism]{monoid homomorphism}
  \begin{equation*}
    \begin{aligned}
      &F(f): F(A) \to F(B) \\
      &F(f)(x_1 \cdots x_n) \coloneqq f(x_1) \cdots f(x_n).
    \end{aligned}
  \end{equation*}

  This functor is \hyperref[def:category_adjunction]{left adjoint} to the \hyperref[def:concrete_category]{forgetful functor} \( U: \cat{Mon} \to \cat{Set} \).
\end{corollary}
\begin{proof}
  Follows from \fullref{thm:free_monoid_universal_property} via \fullref{rem:universal_mapping_property}.
\end{proof}

\begin{definition}\label{def:free_group}
  Let \( S \) be an arbitrary set. We will now construct the \term{free group} \( F(S) \) of \( S \). The construction is similar to that of \hyperref[def:free_monoid]{free monoids}, but it is much more complicated because of special reduction rules for \hyperref[def:unital_magma_inverse_element]{inverse elements}. Refer to \cite{code:free_group_grammar_verification} for a software implementation of the construction.

  Let \( \star \) be a \hyperref[def:formal_language/symbol]{symbol} not in \( S \). Our goal is, for each \( a \in S \), to make the word \( a{\star} \) behave like the inverse of \( a \) in a group. Rather than considering the \hyperref[def:formal_language/kleene_star]{Kleene star} \( (S \cup \{ \star \})^* \) and removing elements via \enquote{reductions} as in \cite{code:free_group_reduction_verification} and \cite[306]{Knapp2016BasicAlgebra}, we directly build a language of \term{reduced words} using the mutually recursive \hyperref[def:formal_grammar]{grammar}
  \begin{alignedeq}\label{eq:def:free_group/grammar}
    &I \to \varepsilon,           &&                        && \text{\( I \) is the initial state} \\
    &I \to S_a \mid D_a,             && a \in S              && \\
    &S_a \to a \mid a S_a,           && a \in S              && S_a \text{ does not produce words beginning with } a\star \\
    &S_a \to a D_b,               && a, b \in S, a \neq b && \\
    &D_a \to a\star S_b,          && a, b \in S, a \neq b && D_a \text{ does not produce words beginning with } a \\
    &D_a \to a\star \mid a\star D_a, && a \in S              && \\
  \end{alignedeq}

  The \term{free group} \( F(S) \) is defined to be the language of \eqref{eq:def:free_group/grammar} equipped with the inductively defined operation
  \begin{equation}\label{eq:def:free_group/operation}
    w_1 \odot w_2 \coloneqq \begin{cases}
     p \odot s, &w_1 = p a \T{and} w_2 = a\star s \text{ for some } a \in S, \\
     p \odot s, &w_1 = p a\star \T{and} w_2 = as \T{and} s \neq \star t \text{ for some } a \in S, \\
     ps,        &\text{otherwise}.
   \end{cases}
  \end{equation}

  The inverse of the word \( w = a_1 \ldots a_n \) is \( w^{-1} \coloneqq b_1 \ldots b_n \), where
   \begin{equation}\label{eq:def:free_group/inverse}
     b_{n-k+1} \coloneqq \begin{cases}
       \varnothing, &a_k = {\star} \\
       a_k{\star},  &a_k \neq {\star} \T{and} k = n \\
       a_k{\star},  &a_k \neq {\star} \T{and} a_{k+1} \neq {\star} \\
       a_k,         &a_k \neq {\star} \T{and} k \neq n \T{and} a_{k+1} = {\star} \\
     \end{cases}
   \end{equation}
   for \( k = 1, \ldots, n \).

  The group \( (F(S), \odot) \) is called the \term{free group} generated by \( S \).
\end{definition}
\begin{proof}
  The proof of the well-definedness of the group structure of \( F(S) \) is a straightforward (but tedious) application of induction.
\end{proof}

\begin{proposition}\label{thm:free_group_is_free_functor}
  The functor \( F: \cat{Set} \to \cat{Grp} \), defined pointwise in \fullref{def:free_group}, is \hyperref[def:category_adjunction]{free}.
\end{proposition}
\begin{proof}
  The outline of the proof is similar to the proof of \fullref{thm:free_monoid_universal_property}.
\end{proof}

\begin{definition}\label{def:group_presentation}\mcite[314]{Knapp2016BasicAlgebra}
  Let \( S \) be a set, \( F(S) \) be the \hyperref[def:free_group]{free group} and \( \mscrR \subseteq F(S) \) be a subset. Denote by \( \mscrN(\mscrR) \) the smallest normal subgroup of \( F(S) \) that includes \( \mscrR \) as a subset.

  We define the group
  \begin{equation}\label{eq:def:group_presentation/presentation}
    \mscrG = \braket{ S \mid \mscrR} \coloneqq F(S) / \mscrN(\mscrR)
  \end{equation}
  called the group with \term{generators} \( S \) and \term{relators} \( \mscrR \). The expression \eqref{eq:def:group_presentation/presentation} is called a \term{presentation} of \( \mscrG \).

  If there exists a presentation for \( \mscrG \) such that \( S \) is finite, it is called a \term{finitely generated} group. If there exists a presentation such that both \( S \) and \( \mscrR \) are finite, it is called \term{finitely presented}.

  If \( \mscrR = \varnothing \), there are no restrictions and we use the notation
  \begin{equation}\label{eq:def:group_presentation/free}
    \mscrG = \braket{ S } \coloneqq F(S)
  \end{equation}
  for the free group.
\end{definition}

\begin{theorem}\label{thm:every_group_is_representable}\mcite[prop. 7.7]{Knapp2016BasicAlgebra}
  Every group \( \mscrG \) has at least one \hyperref[def:group_presentation]{presentation}.
\end{theorem}
\begin{proof}
  Let \( \mscrG \) be an arbitrary group and let \( S \coloneqq U(\mscrG) \) be the underlying set. Let \( F(S) \) be the corresponding free group with \( \iota: S \to F(S) \) sending elements of \( S \) to singleton words in \( F(S) \). By \fullref{thm:free_group_is_free_functor}, there exists a unique homomorphism \( \varphi: F(S) \to \mscrG \) such that
  \begin{equation*}
    \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
      beginfig(1);
      input metapost/graphs;

      v1 := thelabel("$S$", origin);
      v2 := thelabel("$U(F(S))$", (-1, -1) scaled u);
      v3 := thelabel("$U(G)$", (1, -1) scaled u);

      a1 := straight_arc(v1, v2);
      a2 := straight_arc(v1, v3);

      d1 := straight_arc(v2, v3);

      draw_vertices(v);
      draw_arcs(a);

      drawarrow d1 dotted;

      label.ulft("$\iota$", straight_arc_midpoint of a1);
      label.urt("$\id$", straight_arc_midpoint of a2);
      label.top("$U(\varphi)$", straight_arc_midpoint of d1);
      endfig;
    \end{mplibcode}\fi
  \end{equation*}
  that is, \( U(\varphi) \circ \iota = \id \). Thus, \( G = S \subseteq \ker \varphi \). Define \( \mscrR \coloneqq \ker \varphi \). By \fullref{def:normal_subgroup}, \( \mscrR \) is a normal subgroup of \( F(S) \), thus
  \begin{equation*}
    G = \varphi(F(S)) \cong F(S) / \ker \varphi = \braket{ S \mid \mscrR }.
  \end{equation*}
\end{proof}

\begin{definition}\label{def:cyclic_group}
  For a singleton alphabet \( \set{ a } \), we define the \term{infinite cyclic group}
  \begin{equation*}
    C \coloneqq \braket{a}
  \end{equation*}
  and, for positive integers \( n \), the \term{finite cyclic group} of \term{order} \( n \) as
  \begin{equation*}
    C_n \coloneqq \braket{a \given a^n}.
  \end{equation*}

  We use the same notation independent of \( a \) because all cyclic groups of the same order are obviously \hyperref[def:group/homomorphism]{isomorphic}.

  See \fullref{thm:cyclic_group_isomorphic_to_integers_modulo_n}.
\end{definition}

\begin{definition}\label{def:group_free_product}\mcite[323]{Knapp2016BasicAlgebra}
  The \term{free product} of a nonempty family of groups \( \seq{ \mscrX_k }_{k \in \mscrK} \) with presentations \( \braket{S_k \mid \mscrR_k}, k \in \mscrK \) is the group
  \begin{equation*}
    \Ast_{k \in \mscrK} \mscrX_k \coloneqq \braket*{ \coprod_{k \in \mscrK} S_k \given* \coprod_{k \in \mscrK} \mscrR_k },
  \end{equation*}
  where \( \coprod \) is the \hyperref[def:disjoint_union]{disjoint union}.
\end{definition}

\begin{definition}\label{def:free_abelian_group}
  A \term{free abelian group} is a \hyperref[def:free_left_module]{free} \hyperref[thm:abelian_group_iff_z_module]{\( \BbbZ \)-module}. This definition of a free abelian group is different from the definition of a \hyperref[def:free_group]{free group}.
\end{definition}

\begin{proposition}\label{thm:product_of_cyclic_groups}
  The \hyperref[def:group_direct_product]{direct product} \( C_n \times C_m \) of two \hyperref[def:cyclic_group]{cyclic groups} is cyclic if and only if \( n \) and \( m \) are \hyperref[def:coprime_numbers]{coprime}.
\end{proposition}
\begin{proof}
  Take \( (a^i, a^j) \in C_n \times C_m \).
\end{proof}

\begin{definition}\label{def:group_direct_product}
  The \term{direct product} of a nonempty family of groups \( \{ \mscrX_k \}_{k \in \mscrK} \) is their \hyperref[def:cartesian_product]{Cartesian product} \( \prod_{k \in \mscrK} \mscrX_k \) with the componentwise group operation
  \begin{equation*}
    \{ x_k \}_{k \in \mscrK} \cdot \{ y_k \}_{k \in \mscrK}
    \coloneqq
    \{ x_k \cdot y_k \}_{k \in \mscrK}.
  \end{equation*}
\end{definition}

\begin{definition}\label{def:group_direct_sum}
  The \term{direct sum} \( \bigoplus_{k \in \mscrK} \mscrX_k \) of a nonempty family of groups \( \{ \mscrX_k \}_{k \in \mscrK} \) is a subgroup of their \hyperref[def:group_direct_sum]{direct product} where, for any group element \( \{ x_k \}_{k \in \mscrK} \), only finitely many components are different from zero.

  \begin{thmenum}
    \thmitem{def:group_direct_sum/internal}\mcite[126]{Knapp2016BasicAlgebra}If all \( \{ \mscrX_k \}_{k \in \mscrK} \) are subgroups of a group \( \mscrX \), we say that \( \mscrX \) is their \term{internal direct sum} if the homomorphism
    \begin{align*}
       &\varphi: \bigoplus_{k \in \mscrK} \mscrX_k \to X \\
       &\varphi(\{ x_k \}_{k \in \mscrK}) \coloneqq \cdot_{k \in \mscrK} x_k
    \end{align*}
    is an isomorphism.

    The sum is well-defined since, by definition, there are only finitely many non-identity summands.

    \thmitem{def:group_direct_sum/external} To distinguish \( \bigoplus_{k \in \mscrK} \mscrX_k \) from \( X \), we sometimes call it the \term{external direct product}.
  \end{thmenum}
\end{definition}

\begin{proposition}\label{thm:group_categorical_limits}
  We are interested in \hyperref[def:category_of_cones/limit]{categorical limits} and \hyperref[def:category_of_cones/colimit]{colimits} in \( \cat{Grp} \). Fix an indexed family  \( \{ \mscrX_k \}_{k \in \mscrK} \) of groups.

  \begin{thmenum}
    \thmitem{thm:group_categorical_limits/product} Their \hyperref[def:discrete_category_limits]{categorical product} is their \hyperref[def:group_direct_product]{direct product} \( \prod_{k \in \mscrK} \mscrX_k \), the projection morphisms being inherited from \fullref{thm:discrete_category_limits_in_set}.

    \thmitem{thm:group_categorical_limits/coproduct} Their \hyperref[def:discrete_category_limits]{categorical coproduct} is their \hyperref[def:group_free_product]{free product} \( \Ast_{k \in \mscrK} \mscrX_k \), the embedding morphisms being
    \begin{balign*}
       &\iota_m: \mscrX_m \to \Ast_{k \in \mscrK} \mscrX_k \\
       &\iota_m(x_m) \coloneqq x_m.
    \end{balign*}
  \end{thmenum}
\end{proposition}


\chapter{Classification of Spectra}
\label{ch:spectra_classification}

Let’s open the collagen data set again and see how well can logistic regression predict its four classes. Straightforward, right?

\begin{figure}[h]
    \includegraphics[width=0.95\textwidth]{sp_classification-fig1.png}
    \label{fig:spectra_classification-fig1}
    \caption{In \widget{Preprocess Spectra} we also did some spectral processing: we decided to only keep columns for wavenumbers between 1500\wn and 1800\wn.}
\end{figure}

\noindent Connect \widget{Datasets}, \widget{Logistic Regression}, \widget{Predictions}, \widget{Confusion Matrix} and that's it.

\begin{figure*}
  \newcommand{\spectra}{\includegraphics[scale=0.35]{sp_classification-fig2b.png}}
  \newcommand{\confusion}{\includegraphics[scale=0.45]{sp_classification-fig2a_.png}}
  \hspace{3.5cm} \stackinset{l}{-4cm}{t}{-1cm}
  {\confusion}
  {\spectra}
  \caption{In the \widget{Confusion Matrix} we selected wrong predictions for the actual class DNA. The connected \widget{Spectra} widget displays them.}
  \vspace{-0.5cm}
  \label{fig:spectra_classification-fig2}
\end{figure*}

\noindent Let’s not forget that it is pointless to predict for the same data as we used for learning. We could either  use a \widget{Data Sampler} and connect its Sample output to \widget{Preprocess Spectra} and Remaining output to \widget{Predictions}, or obtain predictions from the \widget{Test and Score} widget.
\widget{Confusion Matrix} now shows the mistakes of the model (scored with cross-validation). We can select them and inspect them further in a \widget{Spectra} widget. Here we colored them by the predicted class (see the Menu).

\begin{wrapfigure}{o}{1.1\textwidth}
  \centering
  \includegraphics[width=1.1\textwidth]{sp_classification-fig3.png}%
  \label{fig:spectra_classification-fig3}
\end{wrapfigure}

But how does the model make its decisions? We already inspected a different model, classification tree, where each node represents a decision on a value of a column.  \widget{Logistic regression} works differently. On the training data it computes weights for all columns (wavelengths), which are then used for prediction, where values are multiplied with weights. To see the weights, connect \widget{Logistic Regression} to a \widget{Data Table}.

\begin{wrapfigure}{o}{\textwidth}
%  \centering
  \vspace{-0.7cm}
  \includegraphics[width=0.9\textwidth]{sp_classification-fig4.png}
  \label{fig:spectra_classification-fig4}
\end{wrapfigure}
We get a table that is hard to understand. What if we visualize it? First, \widget{Transpose} the data. Then, use \widget{Select Columns} to make the visualization prettier: in the widget remove the intercept.

Now, open \widget{Logistic Regression} and try changing its parameters. Observe the effect on the weights.

\begin{figure}[h]
\hspace{-1cm}\stackinset{r}{0\linewidth}{t}{-0.12\linewidth}
  {\includegraphics[scale=0.35]{sp_classification-fig5a.png}}
  {\includegraphics[scale=0.35]{sp_classification-fig5b.png}}
  \label{fig:spectra_classification-fig5}
\end{figure}


\newpage
\subsection{Observations of the size of hidden layers}

An interesting phenomenon is that if we increase the size of the hidden layer, the two-layer linear NN descend faster from the beginning than single-layer linear NN. We use 0 and 1 in MNIST dataset to observe if this phenomenon also occurs in MNIST dataset.

\begin{figure}[H]
	\centering
	\includegraphics[width=2.5in]{MNIST_hidden1000_step50.png}
	\caption{MNIST: $d_1 = 1000, lr = 0.1$}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=2in]{MNIST_hidden8000_step1000.png}
	\includegraphics[width=2in]{MNIST_hidden8000_step30.png}
	\caption{MNIST: WideNet($d_1 = 8000$) vs NarrowNet($d_1 = 100$)}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=2in]{MNIST_hidden64000_1.png}
	\includegraphics[width=2in]{MNIST_hidden64000_2.png}
	\caption{MNIST: $d_1 = 2000,4000,8000,16000$}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=2in]{MNIST_hidden64000_3.png}
	\includegraphics[width=2in]{MNIST_hidden64000_4.png}
	\caption{MNIST: $d_1 = 16000, 32000, 64000$}
\end{figure}

\begin{itemize}
	\item When $d_1 = 1000$, Net1 descend slower than single-layer linear NN from the beginning, but catch up and surpass Net0
	\item When $d_1 > 2000$, Net1 descend faster than Net0 from the beginning. And the speed goes faster as we increase the size of hidden-layer $d_1$.
	\item If we put Net0(Single-layer), NarrowNet1(2-layer with $d_1 = 100$), WideNet1(2-layer with $d_1 = 8000$) together, we can observe that Net0 descend faster at the beginning than NarrowNet1, but NarrowNet1 catches up and surpass Net0 soon. WideNet1 is much more faster than the other two at the beginning and remain the fastest all the time.
\end{itemize}

\subsection{Observation of initializations}

But if we look at how Pytorch do initialization, we can see that their initialization method is related to the size of hidden layer. For example, for some layer in linear NN, if input size is $d_{in}$, output size is $d_{out}$, then Pytorch use the following initialization:
\begin{equation}
	W,b \sim U(-\frac{1}{\sqrt{d_{in}}},\frac{1}{\sqrt{d_{in}}}),
\end{equation}
 which means each single parameter in $W$ and $b$ is uniformly sampled from interval $(-\frac{1}{\sqrt{d_{in}}},\frac{1}{\sqrt{d_{in}}})$.\\

 We know that in our experiments, there are mainly three things that determine the training process: (1) the size of hidden layer, (2) Initialization, (3) learning rate(step size). But if we use a default initialization, we are hard to draw a conclusion because we don't know if this kind of initializaiton is the best in different hidden-size settings. So we do a simple experiment to test this. \\
 \indent We only consider a 2-layer linear NN where the fisrt layer is unbiased. So we need to initialize the parameters $W_1,W_2,b$. We set
 \begin{equation}
 	W_1,W_2,b \sim U(-\beta,\beta),
 \end{equation}
 and change the value of $\beta$, to see if it will influence the descent of loss.

  \begin{figure}[H]
 	\centering
 	\includegraphics[width=1.5in]{MNIST_hidden10_uniform1.png}
 	\includegraphics[width=1.5in]{MNIST_hidden10_uniform2.png}
 	\includegraphics[width=1.5in]{MNIST_hidden10_uniform3.png}
 	\caption{MNIST: $d_1 = 10$, $W_1,W_2,b \sim U(-\beta,\beta)$}
 \end{figure}

 \begin{figure}[H]
 	\centering
 	\includegraphics[width=1.5in]{MNIST_hidden100_uniform1.png}
 	\includegraphics[width=1.5in]{MNIST_hidden100_uniform2.png}
 	\includegraphics[width=1.5in]{MNIST_hidden100_uniform3.png}
 	\caption{MNIST: $d_1 = 100$, $W_1,W_2,b \sim U(-\beta,\beta)$}
 \end{figure}

 \begin{figure}[H]
	\centering
	\includegraphics[width=1.5in]{MNIST_hidden500_uniform1.png}
	\includegraphics[width=1.5in]{MNIST_hidden500_uniform2.png}
	\includegraphics[width=1.5in]{MNIST_hidden500_uniform3.png}
	\caption{MNIST: $d_1 = 500$, $W_1,W_2,b \sim U(-\beta,\beta)$}
\end{figure}

 \begin{figure}[H]
	\centering
	\includegraphics[width=1.5in]{MNIST_hidden1000_uniform1.png}
	\includegraphics[width=1.5in]{MNIST_hidden1000_uniform2.png}
	\includegraphics[width=1.5in]{MNIST_hidden1000_uniform3.png}
	\caption{MNIST: $d_1 = 1000$, $W_1,W_2,b \sim U(-\beta,\beta)$}
\end{figure}

  \begin{figure}[H]
 	\centering
 	\includegraphics[width=1.5in]{MNIST_hidden5000_uniform1.png}
 	\includegraphics[width=1.5in]{MNIST_hidden5000_uniform2.png}
 	\includegraphics[width=1.5in]{MNIST_hidden5000_uniform3.png}
 	\caption{MNIST: $d_1 = 5000$, $W_1,W_2,b \sim U(-\beta,\beta)$}
 \end{figure}

   \begin{figure}[H]
 	\centering
 	\includegraphics[width=1.5in]{MNIST_hidden10000_uniform1.png}
 	\includegraphics[width=1.5in]{MNIST_hidden10000_uniform2.png}
 	\includegraphics[width=1.5in]{MNIST_hidden10000_uniform3.png}
 	\caption{MNIST: $d_1 = 10000$, $W_1,W_2,b \sim U(-\beta,\beta)$}
 \end{figure}

   \begin{figure}[H]
	\centering
	\includegraphics[width=1.5in]{MNIST_1hidden_step50_uniform1.png}
	\includegraphics[width=1.5in]{MNIST_1hidden_step50_uniform2.png}
	\includegraphics[width=1.5in]{MNIST_1hidden_step50_uniform3.png}
	\caption{MNIST: $d_1 = 10,100,500,1000,5000,10000$, $W_1,W_2,b \sim U(-\beta,\beta)$}
\end{figure}

    \begin{figure}[H]
 	\centering
 	\includegraphics[width=1.5in]{MNIST_1hidden_step10_uniform1.png}
 	\includegraphics[width=1.5in]{MNIST_1hidden_step10_uniform2.png}
 	\includegraphics[width=1.5in]{MNIST_1hidden_step10_uniform3.png}
 	\caption{MNIST: $d_1 = 10,100,500,1000,5000,10000$, $W_1,W_2,b \sim U(-\beta,\beta)$}
 \end{figure}


\section{closed channel transfer matrix folding}

Now that we have a matrix of size $(N+N_c)x(N+N_c)$ it would be convenient to be able to represent it as a matrix of size $NxN$.  We will call this reduction "folding" as we are folding the closed channels into a smaller matrix. There is conservation of information in this matrix of reduced rank as the elements are messier.  The folding operation occurs one closed channel at a time, but it is shown by a recursion relation that the operation can be done by induction for an infinite number of closed channels.

Bagwell does the operation but gives an incorrect recursion relation. See~\cite{1990_Bagwell} page 358, equation 25.

dealing with a 4x4 matrix (2 open and 2 closed channels), solve for $t_{24}$ in the fourth equation:
\begin{equation}
t_{24} = -\frac{\Gamma_{41}}{\Gamma_{44}+2\kappa_4} t_{21} +
         -\frac{\Gamma_{42}}{\Gamma_{44}+2\kappa_4} t_{22} +
         -\frac{\Gamma_{43}}{\Gamma_{44}+2\kappa_4} t_{23}
\end{equation}
then plug that into the three remaining equations. Group like terms
\begin{equation}
0 = ((\Gamma_{11}-\frac{\Gamma_{14}\Gamma_{41}}{\Gamma_{44}+2 \kappa_4}) - 2 i k_1)t_{21} +
     (\Gamma_{12}-\frac{\Gamma_{14}\Gamma_{42}}{\Gamma_{44}+2 \kappa_4})t_{22} +
     (\Gamma_{13}-\frac{\Gamma_{14}\Gamma_{43}}{\Gamma_{44}+2 \kappa_4})t_{23}
\end{equation}
Now we can write a 3x3 matrix
\begin{equation}
 \left( \begin{array}{c}
0 \\
-2 i k_2 \\
0 \end{array} \right) =
 \left( \begin{array}{cccc}
(\Gamma_{11}-\frac{\Gamma_{14}\Gamma_{41}}{\Gamma_{44}+2 \kappa_4})-2 i k_1 &
(\Gamma_{12}-\frac{\Gamma_{14}\Gamma_{42}}{\Gamma_{44}+2 \kappa_4})           &
(\Gamma_{13}-\frac{\Gamma_{14}\Gamma_{43}}{\Gamma_{44}+2 \kappa_4})            \\
(\Gamma_{21}-\frac{\Gamma_{24}\Gamma_{41}}{\Gamma_{44}+2 \kappa_4})         &
(\Gamma_{22}-\frac{\Gamma_{24}\Gamma_{42}}{\Gamma_{44}+2 \kappa_4})-2 i k_2 &
(\Gamma_{23}-\frac{\Gamma_{24}\Gamma_{43}}{\Gamma_{44}+2 \kappa_4})              \\
(\Gamma_{31}-\frac{\Gamma_{34}\Gamma_{41}}{\Gamma_{44}+2 \kappa_4})         &
(\Gamma_{32}-\frac{\Gamma_{34}\Gamma_{42}}{\Gamma_{44}+2 \kappa_4})         &
(\Gamma_{33}-\frac{\Gamma_{34}\Gamma_{43}}{\Gamma_{44}+2 \kappa_4})+2 i \kappa_3 \end{array} \right)
 \left( \begin{array}{c}
t_21 \\
t_22 \\
t_23 \end{array} \right)
\label{singlescattererfirstfold}
\end{equation}
observe the recursion relation
\begin{equation}
\Gamma_{ij,4} = \Gamma_{ij} - \frac{\Gamma_{i4}\Gamma_{4j}}{\Gamma_{44}+2 \kappa_4}
\end{equation}
which generalizes to a recursion relation
\begin{equation}
\Gamma_{ij}^{(n)} = \Gamma_{ij}^{(n+1)} - \frac{\Gamma_{i(n+1)}^{(n+1)}
\Gamma_{(n+1)j}^{(n+1)}}{\Gamma_{(n+1)(n+1)}^{(n+1)}+2 \kappa_{(n+1)}}
\end{equation}
Things to keep in mind: multiplying folded matrices is not equivalent to multiplying large matrices and then folding.  This recursion relation demonstrates that an infinite number of closed channels can be accounted for (with the proper normalization).
% see Ben's notes, 20080618
Now we'll repeat the process of folding for the general one scatterer matrix for N open channels and $N_c$ closed channels.
\begin{equation}
\left(
\left( \begin{array}{ccc}
\hat{\Gamma}_{pp} & | & \hat{\Gamma}_{pq} \\
--- & + & --- \\
\hat{\Gamma}_{qp} & | &  \hat{\Gamma}_{qq} \end{array}
\right) - 2 i
\left( \begin{array}{cccc}
k_1 &     &        & 0         \\
    & k_2 &        &           \\
    &     & \ddots &           \\
  0 &     &        & k_{N+N_c} \end{array}
\right)
\right)
\left( \begin{array}{c}
\vec{t}_p \\
\vec{t}_q\end{array}
\right) = free terms from input
\end{equation}
where if $n>N$ then $k=i\kappa$.

Do the bottom half (closed channels only) of the matrix multiplication,
\begin{equation}
\hat{\Gamma}_{qp} \vec{t}_p + (\hat{\Gamma}_{qq} + 2 \hat{\kappa}_q)\vec{t}_q =
\left( \begin{array}{c}
	0 \\
	\vdots \\
	0 \end{array}
\right)_q
\end{equation}
Zeros on the left since the evanescent modes can not have inputs. No $k$ dependence since there are no diagonal elements.

Solve for $\vec{t}_q$,
\begin{equation}
(\Gamma_{qq}+2 \vec{\kappa}_q) \vec{t}_q = - \hat{\Gamma}_qp \vec{t}_p
\end{equation}

\begin{equation}
\vec{t}_q = -(\hat{\Gamma}_{qq} + 2 \hat{\kappa}_q)^{-1} (\hat{\Gamma}_{qp} \vec{t}_p)
\end{equation}

Now it's time for the upper set (open channels)
\begin{equation}
free terms = (\hat{\Gamma}_{pp}-2 i \hat{k}_p)\vec{t}_p + \hat{\Gamma}_{pq} \vec{t}_q
\end{equation}
plug into $\vec{t}_q$
\begin{equation}
free terms = (\hat{\Gamma}_{pp}-2 i \hat{k}_p)\vec{t}_p - \hat{\Gamma}_{pq}
((\hat{\Gamma}_{qq}+2 \vec{\kappa}_q)^{-1})(\hat{\Gamma}_{qp} \vec{t}_p)
\end{equation}
factor out $\vec{t}_p$
\begin{equation}
free terms = ((\hat{\Gamma}_{pp}-2 i \hat{k}_p)\vec{t}_p - \hat{\Gamma}_{pq}
((\hat{\Gamma}_{qq}+2 \vec{\kappa}_q)^{-1})\hat{\Gamma}_{qp}) \vec{t}_p
\end{equation}
which compared to equation B8 in \cite{2007_Froufe-Perez_PRE}

\begin{equation}
\hat{\tilde{U}}_{pp} = \hat{U}_{pp} - \hat{U}_{pq}
\frac{1}{\sqrt{2 \vec{\kappa}_Q}}\frac{1}{I+
\frac{1}{\sqrt{2 \kappa_Q}}\hat{U}_{QQ}\frac{1}{\sqrt{2 \kappa_Q}} }
\frac{1}{\sqrt{2 \kappa_Q}}\hat{U}_{QP}
\end{equation}

\begin{equation}
\hat{\tilde{U}}_{pp} = \hat{U}_{pp} - \hat{U}_{pq}
\frac{1}{I 2 \vec{\kappa}_Q + 2 \vec{\kappa}_Q \hat{U}_{QQ}}\hat{U}_{QP}
\end{equation}

\begin{equation}
\hat{\tilde{U}}_{pp} = \hat{U}_{pp} - \hat{U}_{pq} (2 \kappa_Q + U_{QQ})^{-1} U_{QP}
\end{equation}

They match!


%outlines the background behind the sequential probability ratio test.

\note{This section assumes that the reader has a basic familiarity with the terminology and techniques of hypothesis testing in statistics.}

A statistical test is a mechanism for making quantitative decisions about a process, by determining how well the data stand in agreement with given predicted probabilities \cite{cowan1998statistical}. Statistical tests are usually used to draw conclusions about a \textit{statistical hypothesis}, which is a testable hypothesis based on observations of a process that is modelled using random variables. There are many texts that outline the statistical tests that can be used to make a decision between accepting and rejecting the null hypothesis, $H_0$, for example \cite{IntroductionToMathematicalStatistics}. The usual context in which this occurs is one in which the data has been collected in advance and the sample size is fixed and known. The standard procedure for testing a simple hypothesis involves using a Uniformly Most Powerful (UMP) Test for a fixed value of the probability of making a Type \Romannum{1} error, $\alpha$ \cite[p.~253]{IntroductionToMathematicalStatistics}. The subsequent sections discuss how this can be extended to a sequential paradigm, where the sample size is not fixed.\note{An example might be of value here} \par

There exists a branch of statistical hypothesis testing called \textit{sequential hypothesis testing}, which is used when the sample size is not fixed in advance \cite[p.~375]{IntroductionToMathematicalStatistics}. Given a hypothesis to test, $H_0$, this means the decision process goes beyond deciding whether to accept or reject the null hypothesis, but to either
\begin{enumerate}
    \item Accept the hypothesis being tested, $H_0$.
    \item Reject the hypothesis being tested, $H_0$
    \item Continue the experiment by making a further observation.
\end{enumerate}

It is clear that samples are gathered as long as 1). or 2). above are not chosen, which intuitively corresponds to the notion of making an informed decision, where it is desirable to ensure that enough data has been gathered to draw a meaningful conclusion. In the sequential testing paradigm, two kinds of error may be committed, as with the non-sequential case: we may reject the null hypothesis when it is true (commit a Type \Romannum{1} error) or we may accept the null hypothesis when some alternative hypothesis is true (commit a Type \Romannum{2} error).

The Sequential Probability Ratio Test (SPRT), which was devised by \citeauthor{Wald1945SequentialHypotheses}, proposes a statistical test for simple hypotheses with specified fixed values, which ensures that the probability of Type \Romannum{1} and Type \Romannum{2} errors do not exceed $\alpha$ and $\beta$ respectively \cite{Wald1945SequentialHypotheses}. \citeauthor{Wald1948OptimumTest} proved that the SPRT is optimal, in the sense that of all tests with the same power, the SPRT requires on average the fewest number of observations to reach a decision \cite{Wald1948OptimumTest}. A strong advantage of the test is that it can be carried out without determining any probability distributions whatsoever \cite{Wald1945SequentialHypotheses}. The SPRT can be thought of as a stopping rule for sampling in a stochastic process. For the sake of brevity, we omit the full derivation of the rule and the proof of optimality, but instead refer the reader to \cite{Wald1945SequentialHypotheses}, \cite{Wald1950BayesProblems} and \cite{Wald1948OptimumTest}. The SPRT can be carried out following the procedure shown in Algorithm \ref{alg:SPRT}.

%\begin{enumerate}
%    \item The null and alternative hypotheses are stated, $H_0$ and $H_1$.
%    \item The desired type \Romannum{1} and type \Romannum{2} error rates are specified as $\alpha$ and $\beta$.
%    \item Calculate the values $A = \frac{1-\beta}{\alpha}$ and $B = \frac{\beta}{1-\alpha}$
%    \item
%\end{enumerate}

\begin{algorithm}{}
\caption{The Sequential Probability Ratio Test Algorithm}
\label{alg:SPRT}

\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
%Input
\REQUIRE $\newline \alpha \text{: \quad The upper limit in probability for making a Type \Romannum{1} error.}$
\newline $\beta \text{: \quad The upper limit in probability for making a Type \Romannum{2} error.}$
\newline $H_0 \text{: \quad The null hypothesis.}$
\newline $H_1 \text{: \quad The alternative hypothesis.}$
\newline $(x_1, ..., x_m) \text{: \quad The m observations made so far.}$
%Output
\ENSURE  $\newline$ A decision to accept $H_0$, accept $H_1$ or make another observation.\\
\hfill\pagebreak

\STATE Calculate $p_{0m}=p_{0m}(x_1, ..., x_m)$, the probability of observing the data under the assumption $H_0$ is true.

\STATE Calculate $p_{1m}=p_{1m}(x_1, ..., x_m)$, the probability of observing the data under the assumption $H_1$ is true.

\STATE Calculate the values $A = \frac{1-\beta}{\alpha}$ and $B = \frac{\beta}{1-\alpha}$

\STATE Accept $H_1$ if $\frac{p_{1m}}{p_0m} \geq A$

\STATE Accept $H_0$ if $\frac{p_{1m}}{p_0m} \leq B$

\STATE Make an additional observation if $B < \frac{p_{1m}}{p_0m} < A$

\end{algorithmic}
\end{algorithm}

The main idea, as is the case with simple non-sequential hypothesis tests, is based on the idea that if the likelihood ratio ($\frac{p_{1m}}{p_{0m}}$) lies in some \textit{critical region}, $C$, then we may reject the null hypothesis \cite{IntroductionToMathematicalStatistics}. The SPRT extends this by partitioning the m-dimensional sample space $M_m$ into three mutually exclusive regions, $R_m^0$, $R_m^1$ and $R_m$. After the $i_{th}$ observation $(x_i)$ has been drawn, $H_0$ is accepted if $(x_1, ..., x_i)$ lies in $R_m^0$, $H_1$ will be accepted if $(x_1, ..., x_i)$ lies in $R_m^1$ or a $i+1_{th}$ observation will be drawn if $(x_1, ..., x_i)$ lies in $R_m$ \cite{Wald1945SequentialHypotheses}. The process of how to choose $R_m^0$, $R_m^1$ and $R_m$ is outlined in Section 3 of \cite{Wald1945SequentialHypotheses}, which goes beyond the scope of this thesis. The derivation essentially shows that $(x_1, ..., x_i) \in R_m^0$ is equivalent to $\frac{p_{1m}}{p_0m} \leq B$, $(x_1, ..., x_i) \in R_m^1$ is equivalent to $\frac{p_{1m}}{p_0m} \geq A$, and $(x_1, ..., x_i) \in R_m$ is equivalent to $B < \frac{p_{1m}}{p_0m} < A$.

\subsubsection{Summary}
The SPRT is a sequential hypothesis test that formulates a stopping rule in order to draw conclusions based on statistical data. It has frequently been in quality control studies, where samples can be expensive to gather, but it can be applied in other scenarios where sampling can be expensive \cite{Ou2010AnMean}. We use it in Section \ref{subsubsec:SeachTerminationMethodology}


\documentclass[notitlepage]{problem-solving}

\title{The Mystery of $1^\pi$\\ Wrestling with Complex Exponentiation}
\author{Matt McCarthy}
\date{June 2016}

\addbibresource{complex-logs.bib}

\nocite{*}

\begin{document}

\maketitle

\begin{problem*}
	Find what step is wrong in the following statements.
	\begin{align*}
		1 &= 1^\pi\\
		&= \paren{e^{2i\pi}}^\pi\\
		&=e^{2i\pi^2}\\
		&=\cos 2\pi^2 + i\sin 2\pi^2\\
		&\approx 0.6296 +0.7768 i
	\end{align*}
\end{problem*}

\section{Background}

\subsection{Complex Logarithms}

In $\RR$ we can define logarithms in various ways such as the inverse of the exponential or as
\[
	\ln x = \int \frac{1}{x} dx.
\]
However, in $\CC$ the original definition (inverse of the exponential) fails since
\[
	e^{i\theta} = e^{i\theta + 2ki\pi}
\]
where $k\in\ZZ$.
Essentially, the exponential is a bijection between $\RR$ and $(0,\infty)$ and is thus invertible.
When we move to $\CC$, the exponential function loses its injectivity since multiple domain elements get mapped to a single element in the range.
However, defining logarithms as the antiderivative of $1/x$ still works.
\begin{definition}
	Let $z\in\CC$.
	Then $\log z$ is defined as
	\[
		\log z := \ln |z| +i\arg z.
	\]
	If $\arg z\in(-\pi,\pi]$ we say it is the \textit{principal logarithm} of $z$.
\end{definition}
\begin{corollary}
	\[
		\frac{d}{dz} \log z = \frac{1}{z}
	\]
\end{corollary}
As we can see by the definition, the complex logarithm is \textit{multivalued}, thus if we want it to be well-defined we need to restrict the argument of the input to an open interval of length $2\pi$.

\subsection{Exponentiation with a Complex Base}

Because of these problems with the logarithm, exponentiation becomes less straightforward.
In the complex world, exponentiation is defined as follows.
\begin{definition}
	Let $z,w\in\CC$ with $w\neq 0$.
	Then
	\[
		w^z = e^{z\log w}.
	\]
\end{definition}
However, this definition is equivalent to
\[
	w^z = e^{z(\ln|w| + i\arg w)}.
\]
Thus, due to the properties of the complex logarithm, exponentiation in the complex plane is also multivalued.

When exponentiating, the following are true.
\begin{enumerate}
	\item $z^w$ is single-valued iff $w\in\ZZ$.
	\item $z^{m/n}$ has $n$ distinct values for $m,n\in\ZZ$ with $n>0$ and $\gcd(m,n)=1$.
	\item $z^x$ has infinitely many values if $x$ is irrational.
\end{enumerate}

\section{Solution}

\begin{problem*}
	Find what step is wrong in the following statements.
	\begin{align*}
		1 &= 1^\pi\\
		&= \paren{e^{2i\pi}}^\pi\\
		&=e^{2i\pi^2}\\
		&=\cos 2\pi^2 + i\sin 2\pi^2\\
		&\approx 0.6296 +0.7768 i
	\end{align*}
\end{problem*}

The problem is
\[
	1^\pi = 1.
\]
By definition of complex exponentiation we have
\[
	1^\pi = e^{\pi\log 1}.
\]
However
\[
	\log 1 = \ln |1| + i\arg 1 = 0 + 2ki\pi
\]
for $k\in\ZZ$.
Thus,
\[
	1^{\pi} = e^{2ki\pi^2}.
\]
Since $\pi$ is irrational, there are infinitely many values that $1^\pi$ can take.
The only value of $k$ that yields an answer of 1 is $k=0$.

\printbibliography

\end{document}


\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[T1]{fontenc}
\usepackage{pagecolor}
\usepackage{amssymb}
\usepackage{lmodern}
\usepackage{mathtools, nccmath}
\usepackage{courier}
\usepackage[overload]{empheq}
\usepackage[inline, shortlabels]{enumitem}
\usepackage{amsmath}
\usepackage{mathtools}
\definecolor{myyellow}{RGB}{225,225,100}
\definecolor{myred}{RGB}{220,100,100}
\definecolor{mygreen}{RGB}{120,225,120}
\definecolor{myblue}{RGB}{100,200,255}
\definecolor{mypurple}{RGB}{200,140,255}
\definecolor{myorange}{RGB}{255,150,50}
\color{white}
\pagecolor{black}
\title{Solution to Linear algebra \#1}
\author{@all.about.mathematics}
\date{}

\begin{document}
\maketitle
\large
\section{Problem}
Let $A$ be a square matrix. Then reflect its entries along the diagonal other than the diagonal and let the new matrix be $B$. Prove that $\det(A)=\det(B)$.

\medskip
\noindent
For example, if
$$
A=
\begin{bmatrix}
1 & 4 & 7 \\
2 & 5 & 8 \\
3 & 6 & 9 \\
\end{bmatrix}
\implies
B=
\begin{bmatrix}
9 & 8 & 7 \\
6 & 5 & 4 \\
3 & 2 & 1 \\
\end{bmatrix}
$$
\newpage
\section{Solution}
Let's use the example provided in the last page. First, let's take the transpose of A, which does not change its determinant.
$$A=
\begin{bmatrix}
1 & 4 & 7 \\
2 & 5 & 8 \\
3 & 6 & 9 \\
\end{bmatrix}
\implies
A^T=
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{bmatrix}$$
We can see that $\mathbf{r_1}\longleftrightarrow \mathbf{r_3}$ and $\mathbf{c_1} \longleftrightarrow \mathbf{c_3} $ turns $A^T$ into $B$.
\medskip

\noindent{Similarly, we can deduce that for a $n\times n$ matrix $A$, the following EROs and ECOs can turn $A^T$ into it's corresponding $B$:}
$$\{\mathbf{r_1}\longleftrightarrow\mathbf{r_n}\:,\: \mathbf{r_2}\longleftrightarrow\mathbf{r_{n-1}}\cdots \mathbf{r_{\left \lfloor{n/2}\right \rfloor}}\longleftrightarrow \mathbf{r_{\left \lceil{n/2}\right \rceil}}\} $$
$$\{\mathbf{c_1}\longleftrightarrow\mathbf{c_n}\:,\: \mathbf{c_2}\longleftrightarrow\mathbf{c_{n-1}}\cdots \mathbf{c_{\left \lfloor{n/2}\right \rfloor}}\longleftrightarrow \mathbf{c_{\left \lceil{n/2}\right \rceil}}\}$$
It's trivial that both sets have the same number of operations. Let that number be $m$. Since these Type I operations multiply the determinant by $-1$, $\det(B)$ can be calculated like this.
$$\det(B)=\det(A^T)(-1)^m(-1)^m= \det(A)(-1)^{2m}= \det(A)$$
Therefore our claim is proved.

\end{document}

Algebra/all.about.mathematics' questions/Linear algebra question 1.tex


%%% Local Variables:
%%% mode: latex
%%% TeX-master: "program-analysis"
%%% End:

\chapter{Semantics}

\section{Simple Imperative Language}
\label{sec:simple-language}

\begin{figure}[h]
  \begin{math}
    \begin{array}{lcll}
      n & \in & \mathbb{V} & \text{Scalar values}\\
      x & \in & \mathbb{X} & \text{Program variables}\\
      \odot & = & + | - | * | \dots & \text{Binary operators}\\
      \oslash & = & < | \leq | == | \dots & \text{Comparison operators}\\
      E & = & & \text{Scalar expressions}\\
        & | & n & \text{Scalar constant}\\
        & | & x & \text{Variable}\\
        & | & E \odot E & \text{Binary operation}\\
      B & = & & \text{Boolean expressions}\\
        & | & x \oslash n & \text{Comparison of a variable with a constant}\\
      C & = & & \text{Commands (or Statements)}\\
        & | &\mathbf{skip} & \text{No-Op}\\
        & | & C; C & \text{Sequence}\\
        & | & x := E & \text{Assignment}\\
        & | & \mathbf{input}(x) & \text{Reading a value from input}\\
        & | & \mathbf{if}(B)\{C\} \mathbf{else} \{C\} & \text{Conditional statement}\\
        & | & \mathbf{while}(B)\{C\} & \text{Loop statement}\\
      P & = & C & \text{Program}\\
    \end{array}
  \end{math}

  \caption{Syntax of a simple imperative language}
  \label{fig:syntax}
\end{figure}


\chapter{PRINCIPLES OF DIFFERENTIAL PRIVACY}

During this chapter we are going to introduce the term of D.P., and its definition, alongside with the principles that need to be followed while applying it.

\section{Promise of Differential Privacy}

\par Differential Privacy is actually a promise made by the data handlers, to the participants of a study: "You will not be affected, adversely or otherwise, by allowing your data to be used in any study or analysis, no matter what other studies/ datasets/ info resources are available".
\par The goal is to make the data widely available for analysis, while protecting the users. However, is it possible to learn nothing about an individual, while gathering useful information about a population? This is actually what D.P. is trying to achieve.

\section{Definition of Differential Privacy}
Before defining D.P., we must analyze some of the basic components of its definition.

\subsection{Randomized Response}
Randomized response is one of the earliest privacy mechanisms, that is used to conduct surveys where taboo behaviour is studied. The participants in those surveys are asked to answer truthfully, while they do not want to be stigmatized. There is a micro-world of what we are trying to achieve, thus we are going to give the algorithm of the randomized response in order to answer a binary (yes/no) question.

\begin{itemize}
    \item Flip a coin.
    \item If it lands on heads, answer truthfully
    \item If it lands on tails, flip another one
    \item If it lands on heads, answer no, else, answer yes
\end{itemize}

We are going to analyze this algorithm and its success in later chapters, but for now, it is enough to know that there exists a simple mechanism that adds noise, and is rather accurate for large samples.

Before giving the definition of D.P., we must define its components.

\begin{itemize}
    \item \textbf{Probability Simplex}, given a discrete set $B$, is denoted as $\Delta(B)$ and is defined to be:
    \begin{align*}
        \Delta(B) = \{ x\in R^{|B|}: x_i \geq 0 \text { } \forall i \text{ and } \sum_{i=1}^{|B|} x_i = 1\}
    \end{align*}
    \item A \textbf {Randomized algorithm} $M$ with domain $A$ and discrete range of results $B$, is associated with the mapping $M: A\rightarrow\Delta(B)$.
    \item \textbf{Distance between Databases:} The $l_1$ norm of a database x is denoted $||x||_1$ and it is defined to be: $||x||_1 = \sum_{i = 1}^{|x|} |x_i|$. Thus, the $l_1$ distance between 2 databases $x$ and $y$, is $||x-y||_1$, and the size of a database $x$ os $||x||_1$.

\end{itemize}

\subsection{Definition}
Differential Privacy is defined as following:
\\
\\
A randomized algorithm $M$ with domain $N^{|x|}$ is (ε,δ)-differentially private, if for all $S \in Range(n)$ and for all $x,y \in N^{|x|}$ s.t. $||x - y||_1 \leq 1$
$$ Pr[M(x) \in S] \leq e^\epsilon Pr[M(y) \in S] + \delta$$

where the probability space is over the coin flips of the mechanisms $M$. If $\delta = 0$, we say that $M$ is ε-differentially private.

\\
It should be noted that D.P. is rather a definition than a strict algorithm. While relying on the definition of D.P., we can create different algorithms, which will all ensure that the result will be deferentially private. This allows us to create different forms of D.P., that will be analyzed later on this thesis.

The whole point of Differential Privacy, is that the output of a D.P. mechanism, should by \emph{independent} of whether or not an individual is present in the domain $N$. The "ability" of the adversary to recognise the existence of a column in the dataset, is regularized by epsilon.

\section{The meaning of epsilon}
It is made clear from the above definition, that if we have a computational task, we might find different algorithms for applying D.P., but the result will always be of the same form: each user of the dataset, will get ε-D.P.. But what does the epsilon parameter actually mean?

By reading the mathematical equation, we observe that the higher the value of epsilon, the bigger the difference between the two probabilities (minimum and maximum). Thus, we extract the following statement about the value of epsilon during the application of Differential Privacy:

\begin{itemize}
    \item The \emph{lower the epsilon} value, the \emph{higher the privacy} guarantees for the users of the dataset.
    \item The \emph{higher the epsilon} value, the \emph{more accurate the results} produced.
\end{itemize}

In practice, epsilon values vary in the range $(0,5]$, as lower values are prohibited, and higher values are considered extreme cases. However, as mentioned in [1],  when epsilon is small, failing to be (ε,0)-differentially private is not necessarily alarming, if our algorithm is linearly increasing with ε (ex (2ε,0)-D.P). This happens because of the nature of the epsilon parameter, which guarantees very strict boundaries between databases. However, when ε increases by a lot, users' privacy suffers.

In \textbf{Figure 2.1}, we can see in general terms, the function between the epsilon and the accuracy error, as well as the protection guaranteed. We will discuss in later sections the details on how these graphs are created, but now is a good time to get an overall picture of the accuracy error produced when applying D.P.
\bigskip
\bigskip\bigskip

\begin{figure}[!htb]\centering
      \includegraphics[width=0.6\textwidth]{images/epsilon_intro_graph.png}
  \caption{Accuracy Error as a function of epsilon}
\end{figure}

\section{Different forms of Differential Privacy}

As mentioned during the definition, due to the room that is left for its interpretation, there can be many forms of Differential Privacy. There are two major fields recognized, the \emph{Global D.P.} and the \emph{Local D.P.}.

Their major difference is the curator of the data. In the Global model, the curator must be trusted, as he collects the non-private data and has to pass them through a D.P. algorithm.

On the other hand, in the Local model, the curator may as well be untrusted, since the users perturb their data on their own, using a specific protocol. The key differences of the two forms are shown in the \emph{Figure 2.2} below.

An other difference between the two models, is the amount of noise added. With the absence of a trusted curator, the users themselves must add a significant amount of noise into their data, in order to preserve their privacy. This of course results into a need of many users (several thousands), in order for the L.D.P. protocols to function correctly and accurately.

\begin{figure}[!htb]\centering
      \includegraphics[width=0.3\textwidth]{images/local_vs_global.png}
  \caption{Differences between LDP and GDP}
\end{figure}

In this thesis, we are going to examine both models, by quoting their definitions, observing already-existing algorithms, and creating our own L.D.P. protocol.

\section{Existing Problems of D.P.}

As every new step in Computer Science, Differential Privacy has some issues that are yet to be solved, and some others not covered by its definition.

One major problem is the behaviour of the protocols \emph{when the number of users is limited}. The definition of D.P. is based on the alteration of the data in order not to reveal sensitive information. Thus, if a small amount of users are involved in those protocols, the accuracy of the results might be way off the standards that we set, in order to satisfy the epsilon requirements of the user.

Another (unsolvable) issue, that mainly lies on the basis of surveys, is  \emph{the possibility that conclusions drawn from a survey may reflect statistical information about an individual}.

For example, if a survey about the correlation of smoking and dental problems is conducted, someone that has specific dental problems might be deemed as a smoker, despite keeping his privacy about the fact that he is smoking, during the survey. That is something that D.P. does not promise: unconditional freedom from distinguishing. This is not however a violation of the definition of D.P., as the survey teaches us that specific private attributes correlate with public observable attributes, since this correlation would be observed independent of the presence or absence of the individual in the survey.

There are several more issues as the ones covered above, however we are not going to focus on those, rather on the advantages of D.P.