\documentclass{amsart}[12pt]
\usepackage{amsmath, amsfonts, tikz, natbib, array}
\oddsidemargin=0in \evensidemargin=0in
\textwidth=6.6in \textheight=8.7in

\title{Differentiable mappings from Euclidean to spherical polygons}
\author{B R S Recht}
\date{May 2019}

\begin{document}

\maketitle

-map projections
-geodesic domes
-dymaxion map
-square-circle maps

Yadda yadda\cite{kahn}

In the geodesic dome world, geometry is usually synthetic rather than
analytic. That is, geometric constructions are usually expressed in terms of
step-by-step geometric constructions rather than in equations and numeric
values. See, for instance, \cite{kenner}. Implementing a synthetic geometric
construction on a computer can be a pain; analytic specifications are more
amenable to programming idioms.

\section{Definitions}
Let $x,y$ be coordinates in $\mathbb{R}^2$ (equivalently, $z = x + i y$ in
$\mathbb{C}$), and $u,v,w$ be coordinates in $\mathbb{R}^3$.
If a point in $\mathbb{R}^3$ is on the unit sphere,
then its coordinates satisfy $u^2 + v^2 + w^2 = 1$.

Unless otherwise specified, the vertices of any given polygon are ordered in
countclockwise order.

\subsection{Spherical geometry}
There are a number of ways to numerically specify points on a sphere. By far
the most common is by latitude and longitude, which appear on every modern map
of the Earth and some other planets. Latitude and longitude are
familiar and convenient, but performing extended geometry calculations using
latitude and longitude is often complicated.

Doing spherical geometry using a 3-component unit vector is more convenient
in a number of ways: the equations are often simpler, and there are no
singularities at the poles. We'll also find that calculations using vectors
often make clear symmetries that would be hidden by other forms. A unit sphere
can be defined as the set of all unit
vectors in 3-space; i.e., vectors $\mathbf v = [v_x, v_y, v_z]$ such that the
vector norm $\|\mathbf v \|=1$. Unit vectors are often denoted using a hat:
$\hat{\mathbf v}$. We'll often find ourselves normalizing vectors,
so we may supress the denominator with an ellipsis like so:
\begin{equation}
  \hat{\mathbf v} = \frac{\mathbf{some+really+long+statement}}{\|\dots\|}
\end{equation}
If a vector is an intermediate step to a normalized vector,
we may call it pre-normalized and denote it ${\mathbf v}^*$,
such that $\hat{\mathbf v} = \frac{{\mathbf v}^*}{ \|{\mathbf v}^*\|}$

The shortest distance between two points in Euclidean space is a straight line.
On the sphere, the shortest distance is an arc of the great circle between those
points. The great circle is the intersection of the sphere and a plane passing
through the origin. A plane through the origin can be specified as
$\hat{\mathbf n} \cdot \mathbf v = 0$, where $\hat{\mathbf n}$ is a unit vector
normal to the plane; this vector $\hat{\mathbf n}$ can be used to specify a
great circle. Given two points $\mathbf{\hat{v}_1, \hat{v}_2}$ on the sphere,
the $\hat{\mathbf n}$ of the great circle between those two points is (up to
normalization) their cross product:
\begin{equation}
  \mathbf{\hat{n}} =
\frac{\mathbf{\hat{v}}_1 \times \mathbf{\hat{v}}_2}{\|\dots\|}
\end{equation}

Small circles are the intersection of the sphere with a plane not through
the origin. All planes may be specified in Hessian normal form as
$\mathbf{\hat{n}} \cdot \mathbf v = r$, where $r$ is the minimum distance
between the plane and the origin. The intersection of the plane with the sphere
is determined by $r$ as so:

\begin{itemize}
  \item $r = 0$: Great circle
  \item $r \in (0,1)$: Small circle
  \item $r = 1$: Point
  \item $r > 1$: None
\end{itemize}

The following subsections give some formulas for measurements and constructions
in Euclidean space and on the sphere. Since a sphere is locally Euclidean, the
spherical formulas approach the Euclidean formulas when the measures are small.
Note that some spherical formulas require normalized vectors,
denoted by the hat $\mathbf{\hat{v}}$.

\subsubsection{Distance}
In Euclidean space, the distance between two vertices $\mathbf v_1$ and
$\mathbf v_2$ is given by the usual metric. On the sphere, distance is the
central angle $\theta$, which is given by many equivalent forms: the most
numerically stable one is the one using $\arctan$ given below.
\begin{equation}\begin{split}
\eta & = \|\mathbf v_1-\mathbf v_2\| \\
\theta & = \arctan\left(
  \frac{\|\mathbf{\hat{v}}_1 \times \mathbf{\hat{v}}_2\|}
  {\mathbf{\hat{v}}_1 \cdot \mathbf{\hat{v}}_2}\right)
\end{split}\end{equation}

\subsubsection{Angle}
The angle on a surface at the vertex $v_1$ between $v_2$ and $v_3$ is a
standard expression for Euclidean space. For spheres, it is the dihedral angle
between the planes defined from $v_1$ to $v_2$ and from $v_1$ to $v_3$.
\begin{equation}
  \cos\phi_1 = \mathbf{\hat{c}}_{12} \cdot \mathbf{\hat{c}}_{13}
\end{equation}
where $\mathbf{\hat{c}}_{ij} = \frac{\mathbf{v}_i - \mathbf{v}_j}{\|\dots\|}$
for Euclidean space and $\mathbf{\hat{c}}_{ij} = \frac{\mathbf{\hat{v}}_i
\times \mathbf{\hat{v}}_j}{\|\dots\|}$ for spheres. (This formula also has
equivalent forms using $\sin$ and $\tan$.)

\subsubsection{Area}
The area of an arbitrary polygon with vertices $v_i$ is given by the shoelace
formula. $n$ is the number of vertices in the polygon and
$i = 0 \dots n-1$ is an index for each vertex. $i$ should be treated as if it's
mod $n$, so that it loops around. This formula will give a result for skew
polygons, but the areas of skew polygons are not well-defined.
\begin{equation}
A = \frac{1}{2} \| \sum \mathbf v_i\times \mathbf v_{i+1} \|
\end{equation}
The area of a spherical triangle is the solid angle $\Omega$,
and given by a more elaborate formula. \cite{oosterom}\cite{eriksson}
\begin{equation}
\tan(\Omega/2) = \frac{|\mathbf{\hat{v}_1} \cdot
       \mathbf{\hat{v}}_2 \times \mathbf{\hat{v}}_3|}
       {1+\mathbf{\hat{v}}_1\cdot \mathbf{\hat{v}}_2+\mathbf{\hat{v}}_2
       \cdot \mathbf{\hat{v}}_3+\mathbf{\hat{v}}_3\cdot \mathbf{\hat{v}}_1}
\end{equation}

\subsubsection{Means}
When $n=2$ this formula gives the midpoint between $\mathbf v_1$ and
$\mathbf v_2$. When $n=3$ it gives the centroid of the triangle with
vertices $\mathbf v_1, \mathbf v_2$ and $\mathbf v_3$.
\begin{equation}\begin{split}
\mathbf v_\mu & = \frac{\sum\mathbf v_i}{n} \\
\mathbf{\hat{v}}_\mu & = \frac{\sum\mathbf{\hat{v}}_i}{\|\dots\|}
\end{split}\end{equation}
\subsubsection{Interpolation}
Interpolation in Euclidean space is standard linear interpolation. On the
sphere, interpolation is given by spherical linear interpolation, or slerp.
\begin{equation}
\mathrm{Lerp}(\mathbf{v_1}, \mathbf{v_2}; t) =
       (1-t) \mathbf{v_1} + t \mathbf{v_2}
\end{equation}
\begin{equation}
\mathrm{Slerp}(\mathbf{\hat{v}_1}, \mathbf{\hat{v}_2}; t) =
\begin{cases}\mathbf{\hat{v}_1}
  & \text{if } \mathbf{\hat{v}_1} = \mathbf{\hat{v}_2}\\
        \frac{\sin ((1-t)w)}{\sin (w)} \mathbf{\hat{v}_1} +
       \frac{\sin (tw)}{\sin (w)} \mathbf{\hat{v}_2}
  &\text{otherwise}
      \end{cases}
\end{equation}
where $w = \arccos \mathbf{\hat{v}_1} \cdot \mathbf{\hat{v}_2}$.

\subsubsection{Face normal}
For the purposes of this text, we define the normal to a (Euclidean) polygon as
so, where $n$ is the number of vertices in the polygon and
$i = 0 \dots n-1$ is an index for each vertex:
\begin{equation}
  \hat{\mathbf{n}} =
  \frac{\sum^{n-1}_i \mathbf{v}_i \times \mathbf{v}_{i+1}}{\|\dots\|}
\end{equation}
$i$ should be treated as if it's mod $n$, so that it loops around.
(Note the similarity to the shoelace formula.)
This definition allows for a somewhat sensible extension to skew polygons:
the normal points in a generally reasonable direction for skew polygons.
The normal will be outward-facing if the points are ordered counterclockwise,
and inward-facing if the points are ordered clockwise.

\subsubsection{Skewness}
There's no standard measure of polygon skewness, so this text uses an ad-hoc
measure that seems to work well. This program measures the skewness of a polygon
with 4 or more vertices by this method: Let $\mathbf x_i = \mathbf{v}_i -
\bar{\mathbf{v}}$, where $\bar{\mathbf{v}}$ is the (Euclidean) average of the
points. Calculate the SVD decomposition of the matrix that has $\mathbf x_i$
as rows (or columns). We only need the singular values: since we're in 3d
space, there will be 3 singular values. The \textit{skewness} is the smallest
singular value divided by the sum of the  other two singular values.
If the polygon is flat, the skewness is 0.

\subsection{Triangle and quadrilateral coordinates}

\begin{figure}%[!htbp]
\begin{tikzpicture}
  \draw (0, 0) -- (1.7,3) -- (3.4, 0) -- (0, 0) ;
  \draw[fill] (1.7, 3) circle [radius=0.05] node[anchor=west] {\tiny 1};
  \draw[fill] (0, 0) circle [radius=0.05] node[anchor=south] {\tiny 2};
  \draw[fill] (3.4, 0) circle [radius=0.05] node[anchor=south] {\tiny 3};
  \draw[fill] (2, 1) circle [radius=0.05];
  \draw[dotted] (0,0) -- (2,1) -- (1.7,3);
  \draw[dotted] (3.4, 0) -- (2,1);

  \draw (4, 0) -- (5.7,3) -- (7.4, 0) -- (4, 0) ;
  \draw[fill] (5.7, 3) circle [radius=0.05] node[anchor=west] {\tiny 1};
  \draw[fill] (4, 0) circle [radius=0.05] node[anchor=south] {\tiny 2};
  \draw[fill] (7.4, 0) circle [radius=0.05] node[anchor=south] {\tiny 3};
  \draw[fill] (6, 1) circle [radius=0.05];

  \draw[dotted] (4.6, 1) node[anchor=east] {\tiny 1,2}
  -- (6.85,1) node[anchor=west] {\tiny 1,3};
  \draw[dotted] (5.43, 0) node[anchor=north] {\tiny 3,2}
  -- (6.425, 1.75) node[anchor=west] {\tiny 3,1};
  \draw[dotted] (6.56, 0) node[anchor=north] {\tiny 2,3}
  -- (5.3, 2.2) node[anchor=east] {\tiny 2,1};

\end{tikzpicture}
\caption{Barycentric coordinates. Left: Area opposite of each vertex.
Right: Intersection of lines parallel with triangle edges.}
\label{fig:bary}
\end{figure}

This text will use barycentric coordinates to express Euclidean triangles.
Barycentric coordinates are real numbers $\beta_1, \beta_2, \beta_3$ such that
$\sum^3_{i=1} \beta_i = 1$. Given a triangle with vertices $\mathbf v_1,
\mathbf v_2, \mathbf v_3$, the corresponding vertex is given by $\mathbf v =
\sum^3_{i=1} \beta_i \mathbf v_i$. Given $\mathbf v$ and $\mathbf v_i$,
$\beta_i$ can be found by e.g. solving the linear system of
$\beta_1 + \beta_2 + \beta_3 = 1$ and $\mathbf v = \sum^3_{i=1} \beta_i \mathbf
v_i$. $\beta_i$ are all positive on the interior of the triangle. If a point
lies on an edge opposite vertex $i$, then $\beta_i$ is zero.
(If it lies beyond the edge, then $\beta_i < 0$.)

There are two geometric interpretations of barycentric coordinates that will be
useful, as depicted in Figure \ref{fig:bary}. One is that $\beta_i$ is the area
of the smaller triangle opposite $\mathbf v_i$ divided by the area of the large
triangle.
The other is that if a line is placed passing through $\mathbf v$ parallel to
the edge opposite vertex $i$, it will be at $\beta_i$ of the distance between
the edge and its opposite vertex, with $\beta_i = 0$ being on the edge itself.
Let $\mathbf v_{i,j}$ be the point where the line for $i$ meets the line between
vertices $i$ and $j$: then the vertex lies $\frac{\beta_{j}}{1-\beta{i}}$
of the distance from $\mathbf v_{i,j}$ to $\mathbf v_{i,j+1}$. Symbolically,
$\mathbf v_{i,j} = \mathrm{Lerp}(\mathbf v_{j},\mathbf v_i;\beta_{i})$, and
$\mathbf v = \mathrm{Lerp}(\mathrm{Lerp}(\mathbf v_{i-1}, \mathbf v_i;
\beta_{i}), \mathrm{Lerp}(\mathbf v_{i+1}, \mathbf v_i; \beta_{i});
\frac{\beta_{i-1}}{1-\beta_{i}})$ for all $i$.

Generalized barycentric coordinates are defined similarly, but the requirement
that $\sum^3_{i=1} \beta_i = 1$ is dropped. For instance, generalized
barycentric coordinates on the unit sphere replace it with a requirement that
$\| \sum^3_{i=1} \beta_i \mathbf v_i \| = 1$. $\sum^3_{i=1} \beta_i$ would be
$>1$ on the interior of the triangle, $=1$ on the edges,
and $<1$ on the exterior.

Quadrilaterals are instead specified by \textit{$xy$ coordinates} where
$x$ and $y$ are $\in [-1, 1]$. Given a quadrilateral with vertices
$\mathbf v_1, \mathbf v_2, \mathbf v_3, \mathbf v_4$, the transformation is:
\begin{equation}\begin{split}
\mathbf v & = \frac{(1-x)(1-y)}{4} \mathbf v_1 +
\frac{(1+x)(1-y)}{4} \mathbf v_2 +
\frac{(1+x)(1+y)}{4} \mathbf v_3 +
\frac{(1-x)(1+y)}{4} \mathbf v_4 \\
&= \frac{1}{4} (\mathbf v_1 +\mathbf v_2 +\mathbf v_3 + \mathbf v_4)
+\frac{x}{4}  (-\mathbf v_1 +\mathbf v_2 +\mathbf v_3 - \mathbf v_4)
+\frac{y}{4}  (-\mathbf v_1 -\mathbf v_2 +\mathbf v_3 + \mathbf v_4)
+\frac{x y}{4} (\mathbf v_1 -\mathbf v_2 +\mathbf v_3 - \mathbf v_4)
\end{split}\end{equation}
Unlike triangles, quadrilaterals may have points that do not share a common
plane: they may be skew quadrilaterals. If the quadrilateral is a skew
quadrilateral, $x$ and $y$ smoothly parameterize a surface over that skew
quadrilateral. Like barycentric coordinates, these $xy$ coordinates can be
expressed in terms of nested linear interpolation:
\begin{equation}\begin{split}
\mathbf v
& = \mathrm{Lerp}(\mathrm{Lerp}(\mathbf v_1,\mathbf v_2;\frac{x+1}{2}),
\mathrm{Lerp}(\mathbf v_4,\mathbf v_3;u);\frac{y+1}{2}) \\
& = \mathrm{Lerp}(\mathrm{Lerp}(\mathbf v_1,\mathbf v_4;\frac{y+1}{2}),
\mathrm{Lerp}(\mathbf v_2,\mathbf v_3;v);\frac{x+1}{2})
\end{split}\end{equation}

\begin{figure}%[!htbp]
\begin{tikzpicture}
  \draw (0, 0) -- (4, 0) -- (4, 3) -- (1, 4) -- (0, 0);
  \draw[fill] (0, 0) circle [radius=0.05] node[anchor=east] {\tiny 1};
  \draw[fill] (4, 0) circle [radius=0.05] node[anchor=west] {\tiny 2};
  \draw[fill] (4, 3) circle [radius=0.05] node[anchor=west] {\tiny 3};
  \draw[fill] (1, 4) circle [radius=0.05] node[anchor=east] {\tiny 4};
  \draw[dotted] (2, 0) -- (2.5, 3.5);
  \draw[dotted] (0.5, 2) -- (4, 1.5);
  \draw[fill] (2.25, 1.75) circle [radius=0.05];
\end{tikzpicture}
\caption{$uv$ coordinates on quadrilateral, showing intersection of lines.}
\label{fig:uv}
\end{figure}

$xy$ coordinates are not amenable to a generalization in exactly the way that
generalized barycentric coordinates are, but some formulas can be expressed like
\begin{equation}
  \mathbf v = \sum^4_{i=1} \alpha_i \mathbf v_i
\end{equation}
where $\alpha_i$ are not necessarily unique.

\subsection{Mappings between the hemisphere and the disk}

For simplicity, we'll use azimuthal maps\cite{snyder}

\subsubsection{Azimuthal equal-area}
Preserves areas
\begin{equation}\begin{split}
  \left<x, y\right> &= \left<u, v\right> \sqrt{\frac{2}{1-w}} \\
  \left<u, v, w\right> &= \left<\sqrt{1- \frac{x^2+y^2}{4}}x,
    \sqrt{1- \frac{x^2+y^2}{4}}y, \frac{x^2+y^2}{2}-1\right>
\end{split}\end{equation}

\subsubsection{Stereographic}
This and the following projections are perspective projections: they can be
understood as the view of a sphere from a defined point in space.
Conformal
\begin{equation}\begin{split}
  \left<x, y\right> &= \frac{\left<u, v\right>}{1-w} \\
  \left<u, v, w\right> &= \frac{\left<2x, 2y, x^2+y^2-1\right>}{1+x^2+y^2}
\end{split}\end{equation}

\subsubsection{Gnomonic}
In general, the gnomonic projection is defined as:
\begin{itemize}
\item To sphere: $\hat{\mathbf v} = \frac{\mathbf p}{\|\mathbf p\|}$
\item From sphere: $\mathbf p = \frac{r}
  {\hat{\mathbf n} \cdot \hat{\mathbf v}}\hat{\mathbf v}$
\end{itemize}
where $\mathbf p$ is a point on a plane given in Hessian normal
form by $\hat{\mathbf n} \cdot \mathbf p = r$. Projection from Euclidean
space to the sphere is literally just normalizing the vector.

\subsubsection{Orthographic}
\begin{equation}\begin{split}
  \left<x, y\right> &= \left<u, v\right> \\
  \left<u, v, w\right> &= \left<x, y, \sqrt{1-x^2-y^2}\right>
\end{split}\end{equation}

\subsection{Qualities of a mapping}

Desireable qualities in a mapping include:
\begin{itemize}
\item Homeomorphism: The forward map and inverse map are both continuous.
\item Diffeomorphism: The forward map and inverse map are both differentiable.
In terms of appearance, smooth lines stay smooth.
\item Equal-Area: Relative areas are preserved.
  Can be measured with the Jacobian determinant.
\item Conformal: Small circles are mapped to small circles
(rather than ellipses or something else). Can be measured with the Jacobian matrix.
\item Equidistant: Mappings which preserve (proportional) distances. This isn't
possible for the entire domain, but can be for certain cases, e.g. along the
edges of the polygon/disk, or along lines between the vertices and the center.
\item Closed-form: Can be expressed in terms of a finite number of defined
functions and operations.
This of course depends on which functions are acceptable.
\item Simple: How simple or complicated is the formula? This is,
of course, somewhat subjective.
\end{itemize}

The Jacobian matrix of a mapping $f(x,y) = \left<f_x(x,y), f_y(x,y)\right>$
between two subsets of $\mathbb{R}^2 = \mathbb{C}$ is a 2x2 matrix of
derivatives:
\begin{equation}
\mathbf{J}_f =
\begin{bmatrix}
    \dfrac{\partial f_x}{\partial x} & \dfrac{\partial f_x}{\partial y}\\
    \dfrac{\partial f_y}{\partial x} & \dfrac{\partial f_y}{\partial y}
\end{bmatrix}.
\end{equation}

The Jacobian of the inverse map is just the inverse of the Jacobian matrix of the
forward map, evaluated at the corresponding point: $\mathbf{J}_{f^{-1}} (z)
=\mathbf{J}_{f}^{-1} \left(f^{-1}(z)\right)$. The inverse must exist,
or else the mapping wouldn't be a homeomorphism.

If this matrix is of the form $\begin{bmatrix} a & -b\\ b & a \end{bmatrix}$
for all arguments, then the mapping is conformal. To measure deviations from
conformality, define a quantity $\chi$, the "unconformality", as
\begin{equation}
\chi = \sqrt{\left(\dfrac{\partial f_x}{\partial x} -
\dfrac{\partial f_y}{\partial y}\right)^2 +
\left(\dfrac{\partial f_x}{\partial y} +
\dfrac{\partial f_y}{\partial x}\right)^2}
\end{equation}
If this quantity is zero, the mapping is conformal at that point.

If the determinant of the Jacobian matrix (the Jacobian determinant) is constant,
the map is area-preserving, and it is equal to the ratio of the areas of the
domain and the codomain. In fact, the integral of the determinant over the whole
domain is equal to that ratio.

For mappings from $\mathbb{R}^2$ to the unit sphere $S^2$, use the fact that
the composition of conformal mappings is a conformal mapping, and the
composition of equal-area maps is an equal-area mapping. So to measure the
conformality of a map $\mathbb{R}^2 \to S^2$, we instead measure the composition
of that map with the stereographic projection from $S^2 \to \mathbb{R}^2$.
Similarly, for equal-area, measure the compisition of the map with the azimuthal
equal-area projection. Take care to avoid any singularities or boundaries of the
projection. (There are more sophisticated differential-geometric methods that
could be used here, but this suffices and is easier to understand.)

\section{Mappings between Euclidean and general spherical polygons}
\subsection{Conformal}
Conformal mapping has deep connections to the theory of complex functions.
The Schwarz triangle maps conformally transform the upper half-plane to a
triangle whose edges are circular arcs. It it given by:
\begin{equation}
   \varphi(z) = z^{1-c} \frac{_2 F_1(a',b';c',z)}{_2 F_1(a,b;c,z)}
\end{equation}
where $_2 F_1(a,b;c,z)$ is the hypergeometric function and
\begin{equation}\begin{split}
   a & = \frac{1 - \alpha + \beta - \gamma}{2}\\
   b & = \frac{1 - \alpha - \beta - \gamma}{2}\\
   c & = 1 - \alpha\\
   a' &= \frac{1 + \alpha + \beta - \gamma}{2} = 1 + a - c\\
   b' &= \frac{1 + \alpha - \beta - \gamma}{2} = 1 + b - c\\
   c' &= 1 + \alpha
\end{split}\end{equation}
and the angles at each vertex of the triangle are $\pi \alpha, \pi \beta,
\pi \gamma$. If $\alpha + \beta + \gamma < 1$, then the triangle is hyperbolic;
if $=1$ it is Euclidean, and if $>1$ it is spherical. \cite{nehari} Hyperbolic
triangles seem to be the most investigated cases in the literature, but here the
other two cases are of interest.

The Schwarz triangle map maps the boundary of the half-plane (i.e. $\mathbb{R}$)
to the boundary of the triangle. The vertices are the points $z=0$, $1$, and
$\infty$ on that line. The map takes $z=0$ to $0$, $z=1$ to $\phi(1) =
\frac{\Gamma(c-a) \Gamma(c-b) \Gamma(2-c)}{\Gamma(1-a) \Gamma(1-b) \Gamma(c)}$,
and $z=\infty$ to $\phi(\infty) = \exp\left(i \pi \alpha \right)
\frac{\Gamma(b) \Gamma(c-a) \Gamma(2-c)}{\Gamma(c) \Gamma(b-c+1) \Gamma(1-a)}$
unless $b=0$ (the planar case), then $\phi(\infty) = \exp\left(i \pi \alpha \right)
\frac{\Gamma(a) \Gamma(2-c)}{\Gamma(a-c+1)}$

Denote the stereographic map from the plane to the sphere as $S(z)$. Then a
conformal mapping between the upper half-plane and a spherical triangle is
given by $S\left(\phi(z)\frac{h}{\phi(1)}\right)$, where $h$ is a scaling factor
given by
\begin{equation}
  h = \sqrt{ -\frac{\cos \left(\pi (\alpha+\beta)\right)
                    \cos\left(\pi\gamma\right)}
                   {\cos \left(\pi (\alpha-\beta)\right)
                    \cos\left(\pi\gamma\right)}}
\end{equation}
The derivation of $h$ can be performed using the spherical law of cosines.

What remains is to find a conformal mapping between a Euclidean triangle and the
half-plane. This is also expressed with $\phi(z)$.
\begin{equation}
  S\left(\phi_{\alpha,\beta,\gamma}
  \left(\phi_{\alpha^*,\beta^*,\gamma^*}^{-1}(z)\right)
  \frac{h_{\alpha,\beta,\gamma}}{\phi(1)_{\alpha,\beta,\gamma}}\right)
\end{equation}
where $\alpha,\beta,\gamma$ denotes the angles of the spherical triangle (over
$\pi$), and $\alpha^*, \beta^*, \gamma^*$ denotes the angles of the Euclidean
triangle. (One choice to relate the two sets of angles is $\alpha^* =
\frac{\alpha}{\alpha+\beta+\gamma}$ etc.) The spherical triangle can be
rotated to the desired position on the sphere with an appropriate Mobius
transformation or rotation matrix. (Numerically, it may be helpful to use
both to avoid the point at infinity.)

No closed-form inverse $\phi^{-1}(z)$ is known to the author, even though in the
Euclidean case $b=0$ and the denominator of $\phi(z)$ is 1. The function has
branch cuts on $(-\infty,0]$ and $[1, \infty)$, and points are transformed to
arbitrarily large values, so care must be taken performing the numerical
inversion. A Mobius transformation can be used to estimate initial conditions,
replacing the triangle with an appropriate disk.

\subsection{Gnomonic}
The gnomonic projection was known to the ancient Greeks, and is the simplest
of the transformations listed here. It has the nice property that all lines in
Euclidean space are transformed into great circles on the sphere: that is,
geodesics stay geodesics, and polygons stay polygons. This is in fact the
motivation for the name ``geodesic dome'': Fuller used this projection to project
triangles on the sphere. This is referred to as Method 1 in geodesic dome
terminology. The main downside is that the transformation causes shapes
near the corners to appear bunched up;
this is particularly bad for larger faces e.g. on the tetrahedron.

Projection from Euclidean
space to the sphere is literally just normalizing the vector. For triangles:
\begin{equation}
   \mathbf v^* =
   \beta_1 \mathbf v_1 + \beta_2 \mathbf v_2 + \beta_3 \mathbf v_3
\end{equation}
For quadrilaterals:
\begin{equation}
   \mathbf v^* = (1-x)(1-y) \mathbf v_1 +
   (1+x)(1-y) \mathbf v_2 +
   (1+x)(1+y) \mathbf v_3 +
   (1-x)(1+y) \mathbf v_4
 \end{equation}
where $\beta_i$ are (planar) barycentric coordinates and $x,y$ are
$xy$ coordinates. The factor of $1/4$ is omitted for the quadrilateral
form because the vector is going to be normalized anyways.

The triangular case can be thought of in terms of generalized
barycentric coordinates. If the generalized coordinates are
$\beta^\prime_i$, then $\beta^\prime_i = \frac{\beta_1}
{\|\beta_1 \mathbf v_1 + \beta_2 \mathbf v_2 + \beta_3 \mathbf v_3\|}$.

\subsection{Spherical areal}
This method applies to triangles only. Instead we look to the relation between
barycentric coordinates and area; we treat $\beta_i$ as the proportion of
spherical area in the triangle that is opposite the vertex $\hat{\mathbf v}_i$.
Let $\Omega$ be the spherical area (solid angle) of the spherical triangle and
$\Omega_i = \beta_i\Omega$ be the area of the smaller triangle opposite vertex
$\hat{\mathbf v}_i$.

The formula to find $\hat{\mathbf v}$ given $\beta_i$ more complicated,
although it's also derived from the formula for solid angle given earlier.
\begin{equation}
\label{eq:sphareal}
  \begin{split}
  \mathbf G & \hat{\mathbf v} = \mathbf h \\
   \mathbf G & = \begin{bmatrix}
   \mathbf g_1 & \mathbf g_2 & \mathbf g_3 \end{bmatrix} \\
   \mathbf h & = \begin{bmatrix} h_1  & h_2 & h_3  \end{bmatrix}^T \\
   \mathbf g_{i} & = \left(1+\cos \Omega_{i}\right) \mathbf v_{i-1} \times
   \mathbf v_{i+1} - \sin\Omega_{i}\left(\mathbf v_{i-1} +
   \mathbf v_{i+1}\right)\\
   h_i &= \sin\Omega_i\left(1+\mathbf v_{i-1}\cdot\mathbf v_{i+1}\right)
\end{split}\end{equation}
The subscripts loop around: 0 should be interpreted as 3, and 4 should be
interpreted as 1. To clarify, $\mathbf G$ is the 3x3 matrix where the $i$th
column is $\mathbf g_i$, and $\mathbf h$ is the column vector where the
$i$th element is $h_i$. The vector $\hat{\mathbf v}$
can be solved for using standard matrix methods.

\subsection{Great Circle}
\begin{figure}%[!htbp]
\begin{tikzpicture}
  \draw (2,2) circle [radius=2];

  \draw (0.6, 1) to [out=-25, in=205]
  (3.4, 1) to [out=90, in=-35]
  (2, 3.5) to [out=215, in=90]
  (0.6, 1);
  \draw[fill] (2, 3.5) circle [radius=0.05] node[anchor=west] {\tiny 1};
  \draw[fill] (0.6, 1) circle [radius=0.05] node[anchor=north] {\tiny 2};
  \draw[fill] (3.4, 1) circle [radius=0.05] node[anchor=north] {\tiny 3};
  \draw[dotted] (0.65, 1.5)  node[anchor=east] {\tiny 1,2}
  to [out=-15, in=195] (3.35, 1.5) node[anchor=west] {\tiny 1,3};

  \draw[dotted] (1.8, 0.65) node[anchor=north] {\tiny 3,2}
  to [out=45, in=265] (2.9, 2.7) node[anchor=west] {\tiny 3,1};
  \draw[dotted] (1.6, 3.1) node[anchor=east] {\tiny 2,1}
  to [out=-45, in=105] (2.9, 0.8) node[anchor=north] {\tiny 2,3};
\end{tikzpicture}
\caption{Intersection of great circle arcs inside a spherical triangle,
and the small spherical triangle formed by the arcs. Exaggerated so that the
small triangle is visible; not to scale.}
\label{fig:intlines}
\end{figure}
This is Method 2 in geodesic dome terminology. Recall in our earlier discussion
of barycentric coordinates that on a plane triangle, we can draw a line
corresponding to each $\beta_i$, and those three lines meet at a point. On the
sphere, if we make the same construction, the lines do not meet at a point
(except on the edges), but instead intersect to form a small spherical
triangle. Take a point within that triangle as $\mathbf v$.
Typically the centroid is used, as it's easy to calculate,
although we'll discuss another variation.

(If there were any ambiguities, we used the program \texttt{geodesic}
from Antiprism\cite{antiprism} as a reference implementation.)

In analytic terms, use Slerp to determine the points on each triangle edge.
Take the cross product of the opposing pairs of points to determine the normal
to the intersecting plane corresponding to each line. Take the cross product of
each pair of normals to find a vector proportional to the point of
intersection. (As the cross product is antisymmetric, be careful about order
here.) Then normalize each vector and take their centroid.

In terms of equations, Method 2 or the Great Circle Intersection
method on a triangle is:
\begin{equation}\begin{split}%??? does this reduce to slerp on the edges?
\mathbf v^* & = \sum^3_{i=1} \frac{\mathbf h_i \times \mathbf h_{i+1}}
{\|\mathbf h_i \times \mathbf h_{i+1}\|} \\
\mathbf h_i & =
\mathrm{Slerp}(\mathbf v_{i-1}, \mathbf v_i; \beta_{i})
\times
\mathrm{Slerp}(\mathbf v_{i+1}, \mathbf v_i; \beta_{i})
\end{split}\end{equation}

The above equation can be tweaked slightly by removing the step of normalizing
the vectors at the points of intersection. This still produces a point within
the triangle. This formula is a little more computationally efficient and
easier to treat algebraically. Where $\mathbf h_i$ is as before:
\begin{equation}\label{eq:gct}%??? does this reduce to slerp on the edges?
\mathbf v^* = \sum^3_{i=1} \mathbf h_i \times \mathbf h_{i+1} \\
\end{equation}

This method can be extended to the Quadrilateral. Use Slerp to find points on
opposing sides of the quadrilateral, use the cross product to find their
normal, and then use the cross product to find the point of intersection. Since
we draw two intersecting lines, there is only one point of intersection within
the quadrilateral. The formula is:
\begin{equation}\label{eq:gcq}%??? does this reduce to slerp on the edges?
\mathbf v^* =
(\mathrm{Slerp}(\mathbf v_1, \mathbf v_2; \frac{x+1}{2})
\times
\mathrm{Slerp}(\mathbf v_4, \mathbf v_3; \frac{y+1}{2}))
\times
(\mathrm{Slerp}(\mathbf v_1, \mathbf v_4; \frac{y+1}{2})
\times
\mathrm{Slerp}(\mathbf v_2, \mathbf v_3; \frac{x+1}{2}))
\end{equation}

\subsection{Nested Slerp}
This is similar to the Great Circle method, except instead of using the great
circles to calculate the intersections of the lines, we use another spherical
linear interpolation to get a point near the intersection. We effectively use
the Lerp formulas from the section on coordinates, substituting Slerp for Lerp.
Unlike Lerp, Slerp does not commute, so we take the different permutations of
the arguments and combine the different points that result.

Triangular:
\begin{equation}\label{eq:nst}
\mathbf v^* = \sum^3_{i=3} \mathrm{Slerp}(
\mathrm{Slerp}(\mathbf v_{i-1}, \mathbf v_i; \beta_{i}),
\mathrm{Slerp}(\mathbf v_{i+1}, \mathbf v_i; \beta_{i});
\frac{\beta_{i-1}}{1-\beta{i}})
\end{equation}
Quadrilateral:%??? not symmetric?
\begin{equation}\label{eq:nsq}
  \begin{split}
\mathbf v^* =& \mathrm{Slerp}(
\mathrm{Slerp}(\mathbf v_1, \mathbf v_2; \frac{x+1}{2}),
\mathrm{Slerp}(\mathbf v_4, \mathbf v_3; \frac{x+1}{2}); \frac{y+1}{2})\\
&+ \mathrm{Slerp}(
\mathrm{Slerp}(\mathbf v_1, \mathbf v_4; \frac{y+1}{2}),
\mathrm{Slerp}(\mathbf v_2, \mathbf v_3; \frac{y+1}{2}); \frac{x+1}{2})
\end{split}
\end{equation}

\subsection{Naive Slerp}
The previously mentioned mappings are all somewhat complicated. Expansion of the
formulas results in very lengthy equations. Applying a simplifying restriction
allows us to produce a formula that is nearly as simple as the gnomonic mapping.
The restriction is that the polygons are equilateral. This may seem very
restrictive, but many of the applications of these mappings involve a regular
polyhedron, e.g. the cube or the icosahedron, with equilateral faces.

The Naive Slerp method resembles a naive extension of spherical linear
interpolation (Slerp) to barycentric or $uv$ coordinates, thus the
name. Let $\cos(w) = \mathbf v_i \cdot \mathbf v_{i+1}$ for all $i$. (As
usual, the subscripts loop around.) For triangles:
\begin{equation}
   \mathbf v^* = \sum_{i=1}^3\frac{\sin(w\beta_i)}{\sin(w)}  \mathbf v_i
\end{equation}
For quadrilaterals:
\begin{equation}\begin{split}
     \mathbf v^* & = \sum_{i=1}^4\frac{\sin(w\gamma_i)}{\sin(w)} \mathbf v_i \\
\gamma_1 & = \frac{(1-x)(1-y)}{4} \\
\gamma_2 & = \frac{(1+x)(1-y)}{4} \\
\gamma_3 & = \frac{(1+x)(1+y)}{4} \\
\gamma_4 & = \frac{(1-x)(1+y)}{4}
\end{split}\end{equation}
or
\begin{equation}\begin{split}
   \mathbf v^* & = \sum_{i=1}^4\frac{s_i}{\sin^2(w)}  \mathbf v_i \\
s_1 & = \sin \left(w\frac{1-x}{2}\right)\sin \left(w\frac{1-y}{2}\right) \\
s_2 & = \sin \left(w\frac{1+x}{2}\right)\sin \left(w\frac{1-y}{2}\right) \\
s_3 & = \sin \left(w\frac{1+x}{2}\right)\sin \left(w\frac{1+y}{2}\right) \\
s_4 & = \sin \left(w\frac{1-x}{2}\right)\sin \left(w\frac{1+y}{2}\right)
\end{split}\end{equation}

\subsection{Projection of $\mathbf v^*$}
The nested slerp and naive slerp methods produce values that are normalized
along the edges. Because the projected edges already lie on the sphere, we have
freedom in how to adjust $\mathbf v^*$ to lie on the sphere. The easiest is
just to centrally project the vertices, that is, to normalize $\mathbf v^*$
like we have been. Another option is to perform a parallel projection along the
face normal, as defined earlier. We need the parallel distance $p$ from the
vertex to the sphere surface in the direction of the face normal
$\hat{\mathbf n}$, such that $\hat{\mathbf v} =
\mathbf v^* + p\hat{\mathbf n}$. $p$ is given by:
\begin{equation}
   p = -\mathbf v^* \cdot \hat{\mathbf n} +
   \sqrt{1+\mathbf v^* \cdot \hat{\mathbf n}-\mathbf v^* \cdot \mathbf v^*}
\end{equation}
$p$ can also be approximated as $\widetilde{p} = 1 - \|\mathbf v^*\|
\leq p$, which is fewer operations and doesn't require
calculation of the face normal. Technically, you can project in almost any
direction, not just that of the face normal, but most other choices don't
produce a symmetric result.

Sometimes the best mapping comes from a compromise of the central and
parallel projections. Choose a constant $k$, typically between 0 and 1, then:
\begin{equation}
  \hat{\mathbf v} = \frac{\mathbf v^* + kp\mathbf c}{\|\dots\|}
\end{equation}
$p$ may be replaced by $\widetilde{p}$. If our goal is to optimize a
measurement of the mapping, we can do a 1-variable optimization on $k$.

\section{Mappings between Euclidean and particular spherical rectangles}

\subsection{Nowell's cube mapping}
One mapping between the filled cube $[-1,1]^3$ and the filled sphere
$\mathbf{v} \le 1$ is given by
\cite{nowellcu}
\begin{equation}\begin{split}
u &= x \sqrt{1 - \frac{y^2}{2}-\frac{z^2}{2}+\frac{y^2 z^2}{3}} \\
v &= y \sqrt{1 - \frac{z^2}{2}-\frac{x^2}{2}+\frac{z^2 x^2}{3}} \\
w &= z \sqrt{1 - \frac{x^2}{2}-\frac{y^2}{2}+\frac{x^2 y^2}{3}}
\end{split}\end{equation}
This can be considered a map between a square face of the cube and a spherical
square of area $\frac{2 \pi}{3}$ if one of the $x,y,z$ coordinates is held
constant at $\pm 1$.

\subsection{Naive Slerp to a spherical rectangle}
Let the target rectangle be defined by the points $(-a,-b,c), (a,-b,c), (a,b,c),
(-a,b,c)$ where $a, b, c$ are in $[0,1]$ and $a^2 + b^2 + c^2 = 1$. The
spherical center of this rectangle, and the face normal, is $(0,0,1)$. The naive
slerp method from the standard square to this rectangle is expressible as so:
\begin{equation}
  u^* &= \frac{\sin(\frac{w_x}{2}x) \cos(\frac{w_y}{2}y) }
    {\sqrt{1-b^2}}\\
  v^* &= \frac{\cos(\frac{w_x}{2}x) \sin(\frac{w_y}{2}y) }
    {\sqrt{1-a^2}}\\
  w^* &=c \frac{\cos(\frac{w_x}{2}x) \cos(\frac{w_y}{2}y) }
    {\sqrt{1-a^2}\sqrt{1-b^2}}
\end{equation}
where $cos(w_x) = 1 - 2 a^2$ and $cos(w_y) = 1 - 2 b^2$.

In the case when $c=0$,
and the spherical rectangle takes up an entire hemisphere, the formula further
reduces to:
\begin{equation}
  u^* &= \frac{\sin(\frac{w_x}{2}x) \cos(\frac{w_y}{2}y) }
    {a}\\
  v^* &= \frac{\cos(\frac{w_x}{2}x) \sin(\frac{w_y}{2}y) }
    {b}\\
  w^* &=0
\end{equation}

In the limit where $c=0$ and $b = 0$,
\begin{equation}
  u^* &= \sin(\frac{\pi}{2}x) \\
  v^* &= y \cos(\frac{\pi}{2}x) \\
  w^* &= 0
\end{equation}

\subsection{Elliptical mapping to a spherical rectangle}
$\sin(k x)$ may be approximated as $\sin(k)x$, where the two expressions are
equal at $x=-1,0,1$. Similarly, $\cos(k x)$ may be approximated as
$\sqrt{1 - \sin^2(k) x^2}$. This approximation was applied in \cite{reynolds} to
produce an approximate equal-area mapping, as it maintains the boundary of the
shape where $x=\pm1$ or $y=\pm1$. Applying this approximation to the equation
for naive slerp on a spherical rectangle yields:

\begin{equation}
  u^* &= ax \frac{\sqrt{1-b^2 y^2} }
    {\sqrt{1-b^2}}\\
  v^* &= by \frac{\sqrt{1-a^2 x^2} }
    {\sqrt{1-a^2}}\\
  w^* &=c \frac{\sqrt{1-a^2 x^2}\sqrt{1-b^2 y^2} }
    {\sqrt{1-a^2}\sqrt{1-b^2}}
\end{equation}

In the case when $c=0$, and the spherical rectangle takes up an entire
hemisphere, the formula reduces to:
\begin{equation}
  u^* &= x \sqrt{1-b^2 y^2} \\
  v^* &= y \sqrt{1-a^2 x^2} \\
  w^* &=0
\end{equation}

When $a=b=\frac{1}{\sqrt{2}}$, this is the elliptical mapping from the square
to the disk.\cite{nowellsq}\cite{fong17} Furthermore, when $c=b=0$,
\begin{equation}
  u^* &= x  \\
  v^* &= y \sqrt{1 - x^2} \\
  w^* &=0
\end{equation}
which is the squelch mapping from the square to the disk in \cite{fong17}.

\section{Qualities of mappings}
Jacobians, etc.
Tissot indicatrices?

\section{Applications}
\subsection{Cartographic use}

\subsection{Optimization of geodesic polyhedra}

\bibliographystyle{plain}
\bibliography{references}

\end{document}


\chapter{Summary}

Recent advances in machine learning, neural network software frameworks, and \ac{GPU} computing capacity have made it possible to design and teach very deep neural networks. \acfp{CNN} have been long used for image processing, and lately, it has been shown that they can be adapted to human face detection and extraction of relevant low-dimensional facial data. An extension of a \ac{CNN}, the \acf{FCNN}, has been recently shown to be capable of doing dense pixel-to-pixel mappings. This mapping has been used, for example, to do dense semantic segmentations of images. To train \acp{FCNN} in a supervised way, a large number of annotated input/output image pairs are needed. Nowadays, because of abundant processing and storage capacity in computing clusters, it is feasible to generate these kinds of input/output image pairs synthetically using rendering software. Also, data augmentation has been shown to expand the effective size of even small training datasets successfully.

Because the \ac{FCNN} is an extension to the \ac{CNN}, it is possible to train the former to do dense mapping of human faces. The downscaling part of the \ac{FCNN} first detects the relevant features of the face and compresses them down to a lower dimensional presentation. The upscaling part of the \ac{FCNN} then uses the representation to generate a segmentation and a dense mapping of the human face. One problem is to find a dense mapping that would represent the geometry of the face and that could be taught to a neural network. Another problem is to find training data of real-world images with the aforementioned mapping. Creating the mappings by hand would be very time-consuming as at least tens of thousands of training samples would be needed. On the contrary, generating a training dataset like this by rendering would be easy, as access to exact underlying geometry is available.

The main research goal of the thesis was to explore whether it is possible to train an \ac{FCNN} using non-realistic synthetic data to do dense facial geometry tracking of real-world human faces. Subgoals included designing a method to generate the training data, making the network inpaint geometry under occlusions, making the network temporally stable when applied to video, and designing visualization methods for the generated mappings to ease the evaluation of the results.

To generate the synthetic training dataset, we used Blender to render 100 000 training samples of a randomized head mesh. One sample included an input image, a UV image, and a mask image. The input image had realistic backgrounds but non-realistic face materials. We decided to use the underlying UV mapping of the head model to render the UV image, which then represented the geometry mapping in our method. The mask image was used to segment the frontal face area out of the input image.

We based the design of our \ac{FCNN} on the U-net network topology. Seven levels were used and skip connections were added between all corresponding down and upsampling parts. Convolution feature map sizes, convolution filter sizes, and activation functions were slightly adjusted to optimize results. In the end, as a loss function, we used a simple sum of L1 losses between UV, UV gradient and mask images. UV image gradients were used to speed converge and enforce the smoothness of the resulting UV mapping.

Data augmentation was implemented by applying the following to the input image: rotations, color channels shuffles, exposure and gamma changes, Gaussian noise, and texture based occlusions. Augmentation generated one additional mask image, the occluded mask, which was used in the loss function to aid occlusion detection.

To visualize the generated geometry mappings, we implemented four different visualizations: texture projection, inverse texture projection, grid lines projection, and grid points projection. These projections were used to assess the accuracy and stability of the geometry mapping, both in static images and in videos. In addition, we created a custom browser-based results evaluation page that used these visualization images and other illustrations to help assess the performance of the network.

When given real-world human faces, our final \ac{FCNN} was successful in doing the segmentation and geometry mapping, even though it had been trained on non-realistic synthetic data. The segmenting was, in most cases, good with sharp edges and geometry mapping worked well with non-extreme input images. Our data augmentation strategy successfully expanded the training dataset and prevented the network from overfitting. The occlusion augmentation method also enabled the network to inpaint geometry under obstructions that had not been in the training material, e.g., sunglasses or facial hair. When applied to a video, the temporal stability of the generated geometry was not bad but could be improved. Inpainted geometry was, most of the time, somewhat distorted and not temporally stable.

Future work could include 3D mesh generation from the UV mapping using, for example, morphable models and synthesis-by-analysis. Instead of doing a 2D-to-2D mapping and then 3D mesh reconstruction, it should be possible to train an \ac{FCNN} to do straight 2D-to-3D volumetric mapping. The temporal stability of the generated geometry was not perfect, especially under occlusions, and could be improved.


\section{Conclusion}
DeepProbLog is relatively easier to scale compared to a normal CNN. The CNN took longer to reach an accuracy of 100\%, especially when the model gets more complex it  takes a substantial amount of time. Integrating probabilistic logic programming makes the network train faster. Since the rules are defined in a separate model, these can be easily extended while their corresponding neural networks barely have to change to cope with an increase in complexity in the problem. Giving additional information to the model with these predicates we can increase performance: 100\% accuracy is achieved faster. Incorporating logic programming looks promising and is worth exploring. We have shown that DeepProbLog can be used to optimise the performance of a CNN model when rules about the game or problem can be clearly defined.


\section{Recurrent Neural Networks}
\label{sec:rnn}
Recurrent Neural Networks (RNNs) are one of the most commonly used typology of neural networks~\cite{lecun2015deep}. In recent years, thanks to advancements in their architecture~\cite{hochreiter1997long,chung2014empirical} and in computational power, they have become the standard to effectively model sequential data. They have been used successfully for tasks such as sentiment analysis~\cite{tang2015document}, speech recognition~\cite{graves2013speech}, image captioning~\cite{karpathy2015deep}, predicting tourist paths~\cite{palumbo2017predicting} and neural language models~\cite{mikolov2010recurrent}. One of the typical applications of RNNs is language modeling, i.e. the task of learning a probabilistic model of text in order to generate new text by recursively predicting the next word in a sentence~\cite{sutskever2011generating}. We use RNNs, more specifically Long-Short Term Memory (LSTM) cells~\cite{hochreiter1997long}, in a similar vein to the language modeling problem, i.e. training the network to predict the next track in a playlist and sampling tracks from the learned probability model to generate predictions. In practice, rather than using only the track as input, we use a richer representation that also exploits the artist, the album, the title and, possibly, lyrics features (Figure~\ref{fig:global_architecture}).

In the following sections, we describe in detail the input features as well as the generation strategy.

\begin{figure*}
    \centering
    \includegraphics[width=0.7\textwidth, height=0.35\textwidth]{figures/rnn.pdf}
    \caption{RNN architecture for playlist completion. The input vectors include word2vec embeddings for the track, the album, and the artist, a fastText embedding for the playlist title and numerous features extracted from the lyrics.}
    \label{fig:global_architecture}
\end{figure*}

\subsection{Input Vectors}

\subsubsection{Track, Album and Artist Embeddings}
\label{sec:track_embs}
In order to leverage the information in the dataset concerning tracks, artists and albums, we opt for an approach based on word2vec~\cite{mikolov2013distributed} embeddings. More precisely, we train the word2vec model separately on sequences of tracks, albums and artists in the order of appearance in the playlist, obtaining three separated word2vec models encoding co-occurrence patterns of tracks, albums and artists respectively. Each word2vec model is based on the Skip-gram model with negative sampling using default hyper-parameters of the Gensim implementation~\cite{rehurek_lrec}: embedding vector dimension is $d=100$, learning rate $\alpha = 0.025$ linearly decaying up to $min_{\alpha} = 0.0001$, window size $c = 5$, number of epochs is $\eta = 5$.

We concatenate the three representations of the tracks, albums and artists, obtaining an input vector $x_{w2v}$ whose dimensionality is $|x_{w2v}| = 300$.

\subsubsection{Titles Embeddings}
\label{sec:title_embs}
The title of a playlist can potentially contain interesting information about the intention and the purpose of its creator. The title can suggest that the tracks in certain playlist are intended to suit a certain goal (e.g. \textit{party}, \textit{workout}), a mood (\textit{sad songs}, \textit{relaxing}), a genre (\textit{country}, \textit{reggae}), or a topic (\textit{90's}, \textit{Christmas}). Our intuition, supported by the experiments described later in this section, is that playlists with similar titles may contain similar tracks.
The title similarity could rely on pre-trained models and thesauri. However, we opted for computing a model that is specific for the playlist continuation task, using the sole data of the MPD.

A playlist embedding $p_{w2v}$ is computed as the mean of the embeddings of the tracks composing the playlist, already generated in Section \ref{sec:track_embs}. The playlist embeddings are then grouped in $n$ clusters, applying the K-means algorithm.

We empirically observed that, apart from very general clusters, we also created clusters containing specialized playlists, obtaining as a consequence groups of titles that belong to the same semantic area. For example, a cluster contains playlists like \textit{Christmas feels}, \textit{December} or with titles including the emoji of Santa Claus, while another group encompasses playlists like \textit{country} and \textit{Alabama}.

Each cluster $c$ expresses a composed label, which is the concatenation of the titles of all the playlist $p \in c$ separated by a blank space. These labels can be seen as a corpus of $n$ documents (one for each cluster) that is used as input for the fastText algorithm~\cite{joulin2016fasttext}. Because this algorithm is able to represent textual information at the level of n-grams from 3 to 6 character, the Title2Rec model in output computes the embeddings of any playlist title, being this already seen in the dataset or totally unknown. Figure~\ref{fig:t2r_pipeline} illustrates the process of the Title2Rec model generation.

% source: https://docs.google.com/presentation/d/1KV4eFuYvFxS1Z25ZwOqu5TJ2zuBbeRAZAkR2Hbf8h_A/edit#slide=id.g3d7920112c_0_0
\begin{figure*}
    \centering
    \includegraphics[width=0.85\textwidth]{figures/t2r.pdf}
    \caption{Pipeline for generating the title embedding model used in Title2Rec. The embeddings are computed through a fastText model trained on a corpus of concatenated titles of similar playlists.}
    \label{fig:t2r_pipeline}
\end{figure*}

\subsubsection{Lyrics Embeddings}
\label{sec:lyrics}
Since playlists contain tracks that share semantic properties (such as the genre) and acoustic properties (such as the mood), we hypothesize their lyrics share features as well. To this end, we extract numerous features from the lyrics for a large set of tracks used in the MPD dataset ($v \in \mathbb{R}^{n}$) that describe different stylistic and linguistic dimensions of a song text:
\begin{itemize}
  \item \textit{vocabulary} ($v \in \mathbb{R}$): as a measure of the vocabulary richness, we compute the type-token ratio of a song text.
  \item \textit{style} ($v \in \mathbb{R}^{27}$): to estimate the linguistic style of a song text, we measure the line lengths (in characters and in tokens) and the frequencies of all major part-of-speech tags. We further count rhyme occurrences and \qu{echoisms} (sung words like \qu{laaalala} and \qu{yeeeeeeeaaaaaaah}).
  \item \textit{semantics} ($v \in \mathbb{R}^{60}$): we build a topic model with 60 topics on the song text bag of words using Latent Dirichlet Allocation~\cite{LDA}. Each song text is then represented by its association to these topics.
  \item \textit{orientation} ($v \in \mathbb{R}^{3}$): this dimension models how the song narrative (entities, events) is oriented with respect to the world. We encode a temporal dimension, i.e. whether the song mainly recounts past experiences or present/future ones, by representing the fraction of past tense verb forms to all verb forms as a feature.
  \item \textit{emotion} ($v \in \mathbb{R}^{6}$): we model the subjectivity (subjective vs. objective) as well as the polarity (positive vs. negative) of the song text. Furthermore, the emotions conveyed are modelled in a common two-dimensional model that accounts for degrees of arousal and valence.
  \item \textit{song structure} ($v \in \mathbb{R}^{4}$): as a proxy of the structure of the lyrics, we use the line lengths as well as the lengths of paragraphs in the song text.
\end{itemize}

For experimental purposes, we grouped the previous features in two additional categories:
\begin{itemize}
    \item \textit{deterministic} ($v \in \mathbb{R}^{23}$): it encompasses all features generated in a deterministic way such as features related to the structure, the vocabulary, and the style of the lyrics. We excluded from this group the frequencies of part-of-speech tags, as they depend on the tagger used.
    \item \textit{fuzzy} ($v \in \mathbb{R}^{18}$): it includes the features generated in a non-deterministic fashion such as orientation, emotion, and the frequencies of part-of-speech tags.
\end{itemize}

All features are scaled using a custom feature scaler that combines two elements: i) account for outliers by scaling the data non-linearly based on the percentile of the feature value distribution they belong to; ii) scale the data linearly to the same $[-1,1]$ interval that non-lyrics features live in.

Retrieving lyrics for the MPD dataset is achieved by linking it to the WASABI corpus~\cite{meseguerbrocal:hal-01589250}.\footnote{\url{https://wasabi.i3s.unice.fr}} The WASABI corpus is an ongoing resource that contains 2.1M song texts (of 77k artists), and for each song it provides the following information: the lyrics extracted from \url{http://lyrics.wikia.com}, the synchronized lyrics (when available) from \url{http://usdb.animux.de}, DBpedia abstracts and categories the song belongs to, genre, label, writer, release date, awards, producers, artist and/or band members, the stereo audio track from Deezer (when available), the unmixed audio tracks of the song, its ISRC, BPM, and duration. In total, we linked 416k tracks in MPD (out of 2.2M unique tracks) to WASABI tracks that contain the lyrics. While the linked tracks proportion with $\sim$20\% seems small, the linked tracks cover 53\% of all 66M track occurrences in MPD because of the typical fat-tailed distribution, where some songs are extremely common while most titles occur only rarely in a playlist. Linking the lyrics was done in three levels of accuracy: direct Spotify URI matching gave us 155k links, exact artist and title matching provided 334k matches, and finally lower casing and deleting bracketed content (in song titles only) led to 51k matches. As the results overlap we ended up with 416k matched tracks in total. Some of our lyrics features are language-specific, so we decided to compute lyrics features exclusively on English song texts. This finally resulted in 367k English song texts we computed lyrical features on. Language detection is done with the \textit{langdetect} package\footnote{\url{https://github.com/Mimino666/langdetect}} and datasets of MPD and WASABI are merged along the axes of their Spotify URIs, artist names, song title names, respectively.

\subsection{Learning Model}
As mentioned earlier, we address the problem of playlist continuation as a language modeling problem. More specifically, we train the RNN to predict the next track in a playlist, defining the targets $Y$ to be the inputs $X$ shifted in time, i.e. $X = \{(\hat{T{^j}}_0, \hat{T{^j}}_1, \dots, \hat{T^{j}}_{N_j -1})\}$ and $Y = \{(T{^j}_1, T{^j}_2, \dots, T^{j}_{N_j})\}$ where $\hat{T}$ represents a track and its metadata (artist, album, playlist title, lyrics features), $T$ represents a track id in a playlist, $j = 1, \dots, M$ is a playlist index and $N_j$ is the length of the j-\textit{th} playlist. In this way, we train the model to learn a probability distribution of the next track $P (T_N | \hat{T}_{N-1}, \hat{T}_{N-2}, \dots, \hat{T}_{0})$ given the previous ones, which is parametrized by the network outputs that are converted into probabilities by the final softmax layer (Figure~\ref{fig:global_architecture}). The training algorithm attempts to minimize the cross-entropy loss function $L$, that measures the disagreement between the learned probability model and the observed probability model of the targets $Y$. The perplexity metric that is reported in the experiments (Section~\ref{sec:rnn-opt}) corresponds to $ppl = 2^{L}$. In practice, rather than using probabilities, we use the `logits' $p_i$ where $i$ is a track index, un-normalized scores that are proportional to the probabilities. Different optimization algorithms to minimize the loss are empirically compared (Section~\ref{sec:rnn-opt}).

\subsection{Generating predictions}
\label{sec:generation}
We experiment three different strategies to generate track predictions from the RNN. Given an input seed and the hidden state, the trained model outputs the logits $p_i$, i.e. un-normalized scores that are proportional to the probability that a given track appears after the sequence of seeds $s$. In details, we considered the following approaches, as depicted in Figure~\ref{fig:predictions}.
\begin{description}
    \item[do\_sample] It samples the track with the highest logit $p_i$, where $\hat{i} = arg\ max ({p_i})$, given the set of seeds $s$. It adds the sampled track $\hat{i}$ to the seeds $s$, then it repeats the previous operations until 500 tracks are sampled.
    \item[do\_rank] It ranks the tracks according to their logit value $p_i$, given all the seeds $s$, then it selects the top-500 tracks with the highest logit.
    \item[do\_summed\_rank] It computes the logits $p_i$ for every seed. It averages all the logits in the sequence obtaining $\hat{p_i}$ and then it ranks the tracks according to the values of $\hat{p_i}$.
\end{description}

\begin{figure}
	\centering
	\begin{subfigure}{0.4\textwidth}
		\includegraphics[width=\textwidth]{figures/sample.pdf}
		\caption{do\_sample}
	\end{subfigure}
	\begin{subfigure}{0.4\textwidth}
		\includegraphics[width=\textwidth]{figures/rank.pdf}
		\caption{do\_rank}
	\end{subfigure}
	\begin{subfigure}{0.4\textwidth}
		\includegraphics[width=\textwidth]{figures/summed.pdf}
		\caption{do\_summed\_rank}
	\end{subfigure}
	\caption{Three strategies for generating track predictions.}
	\label{fig:predictions}
\end{figure}


% !TEX root = ./Basilisk-sunSafePoint-20180427.tex

\section{Module Functions}
\begin{itemize}
	\item \textbf{Compute the attitude tracking error}: Determines the shortest rotation to align $\bm s$ and $\hat{\bm s}_{c}$, and computes the corresponding three-dimensional attitude difference
	\item \textbf{Control spacecraft rotation}: The reference frame is assumed to be non-accelerating and either zero (default) or a constant spin about the sun heading axis.

	\item \textbf{Robust to no sun heading information}: If the sun heading vector is not available, then the attitude feedback is turned off by zeroing $\bm\sigma_{B/R}$.  Instead of driving the body rates to zero, the body rates are driven to a prescribed $\bm\omega_{R/N}$ vector.  This allow the spacecraft to search for the sun and covers the case if some sun sensors are offline.

	\item \textbf{Robust to collinear observation vector}:  The module must handle the cases where the commanded body relative vector and the sun direction vectors are nearly collinear.
\end{itemize}

\section{Module Assumptions and Limitations}
The module input vector $\bm s$ can be a vector of any length except for a zero-length vector.  The commanded body-relative unit direction vector ${\bm s}_{c}$ is assumed to be fixed relative to the body.


% !TEX root=../report.tex

\section{Overview}

\statefultrue

\subsection{Language}

\begin{grammar}
  Expressions
    & e    &::= & \lambda x:\tau.\ e   & – abstraction \\
    &      &\mid& e_1\ e_2             & – application \\
    &      &\mid& x                    & – variable \\
    &      &\mid& c                    & – constant \\
    &      &\mid& l                    & – location \\
  \addlinespace
    &      &\mid& e_1 \star e_2        & – operate \\
    &      &\mid& \If{e_1}{e_2}{e_3}   & – branch \\
    &      &\mid& \tuple{e_1, e_2}     & – pair \\
    &      &\mid& \unit                & – unit \\
  \addlinespace
    &      &\mid& \Ref e               & – reference \\
    &      &\mid& !e                   & – dereference \\
    &      &\mid& e_1 := e_2           & – assign \\
    &      &\mid& e_1; e_2             & – sequence \\
  \addlinespace
    &      &\mid& p                    & – pretask \\
  \addlinespace
  Constants
    & c    &::= & B                    & – boolean \\
    &      &\mid& I                    & – integer \\
    &      &\mid& S                    & – string \\
  \addlinespace
  Pretasks
    & p    &::= & \Edit e              & – valued editor \\
    &      &\mid& \Enter \beta         & – unvalued editor \\
    &      &\mid& \Update e            & – stored editor \\
  \addlinespace
    &      &\mid& \Fail                & – fail task \\
  \addlinespace
    &      &\mid& e_1 \Then e_2        & – step \\
    &      &\mid& e_1 \Next e_2        & – user step \\
  \addlinespace
    &      &\mid& e_1 \And e_2         & – composition \\
  \addlinespace
    &      &\mid& e_1 \Or e_2          & – choice \\
    &      &\mid& e_1 \Xor e_2         & – user choice \\
\end{grammar}

\newpage
\subsection{Typing}

\begin{grammar}
  Types
    & \tau &::= & \tau_1 \to \tau_2    & – function type \\
    &      &\mid& \tau_1 \times \tau_2 & – product type \\
    &      &\mid& \Unit                & – unit type \\
    &      &\mid& \Reference \tau      & – reference type \\
    &      &\mid& \Task \tau           & – task type \\
    &      &\mid& \beta                & – basic type \\
    &      &\mid& \alpha               & – universal type \\
  Basic types
    &\beta &::= & \Bool                & – boolean type \\
    &      &\mid& \Int                 & – integer type \\
    &      &\mid& \String              & – string type \\
\end{grammar}

\begin{equation*}
  \boxed{\RelationT}
\end{equation*}

\begin{mathpar}
  \userule{T-Abs}\\
  \userule{T-If}\\
  \userule{T-App}\\
  \userule{T-Edit} \qquad \userule{T-Enter} \qquad \userule{T-Update} \\
  \userule{T-Fail} \\
  \userule{T-Then} \\
  \userule{T-Next} \\
  \userule{T-And} \\
  \userule{T-Or} \\
  \userule{T-Xor}
\end{mathpar}

\subsection{Evaluating}

\begin{grammar}
  Values
    & v    &::= & \lambda x:\tau.\ e        & – abstraction \\
    &      &\mid& \tuple{v_1, v_2}     & – pair value \\
    &      &\mid& \unit                & – unit \\
    &      &\mid& c                    & – constant \\
    &      &\mid& l                    & – location \\
    &      &\mid& t                    & – task \\
  Tasks
    & t    &::= & \Edit v              & – valued editor \\
    &      &\mid& \Enter \beta         & – unvalued editor \\
    &      &\mid& \Update l            & – stored editor \\
    &      &\mid& \Fail                & – fail task \\
    &      &\mid& t_1 \Then e_2        & – step \\
    &      &\mid& t_1 \Next e_2        & – user step \\
    &      &\mid& t_1 \And t_2         & – composition \\
    &      &\mid& t_1 \Or t_2          & – choice \\
    &      &\mid& t_1 \Xor t_2         & – user choice \\
\end{grammar}

Notes:
\begin{itemize}
  \item $\Then$ and $\Next$ are strict in their first argument, lazy in their second.
    It doesn't matter what the continuation is.
  \item $\And$ and $\Or$ is strict in both arguments.
    \todo{Explain why?}
  \item $\Xor$ is lazy in both arguments.
    Evaluating one or both options of $e_1 \Xor e_2$ before the user makes a choice will result in untimely reference updates.
  % \item Although internal steps should be evaluated without user interaction,
  %   $t \Then e$ \emph{is} a task value, iff $\Value(t) = \nothing$.
  %   Take for example $t = \Enter \Int$.
\end{itemize}

\begin{equation*}
  \boxed{\RelationV}
\end{equation*}

\begin{mathpar}
  \userule{E-Edit} \qquad \userule{E-Enter} \qquad \userule{E-Update} \\
  \userule{E-Fail} \\
  \userule{E-Then} \qquad \userule{E-Next} \\
  \userule{E-And} \\
  \userule{E-Or} \qquad \userule{E-Xor}
\end{mathpar}
(Standard constructs as defined by \textcite{books/Pierce02TAPL})

\subsection{Observing}

\begin{flalign*}
  \begin{array}{lcl}
    \multicolumn{3}{l}{\Value : \mathrm{Tasks} \rightharpoonup \mathrm{Values}} \\
    \Value(\Edit v)       &=& v \\
    \Value(\Enter \tau)   &=& \bot \\
    \Value(\Update l, s)  &=& s(l) \\
    \Value(\Fail)         &=& \bot \\
    \Value(t_1 \Then e_2) &=& \bot \\
    \Value(t_1 \Next e_2) &=& \bot \\
    \Value(t_1 \And t_2)  &=& \left\{
      \begin{array}{ll}
        \tuple{v_1, v_2}  & \when\ \Value(t_1) = v_1 \land \Value(t_2) = v_2 \\
        \bot              & \otherwise
      \end{array}
    \right. \\
    \Value(t_1 \Or t_2)   &=& \left\{
      \begin{array}{ll}
        v_1               & \when\ \Value(t_1) = v_1 \\
        v_2               & \when\ \Value(t_1) = \bot \lor \Value(t_2) = v_2 \\
        \bot              & \otherwise
      \end{array}
    \right. \\
    \Value(t_1 \Xor t_2)  &=& \bot
  \end{array} & &&
\end{flalign*}

\begin{flalign*}
  \begin{array}{lcl}
    \multicolumn{3}{l}{\Value_{\stride} : \mathrm{Tasks} \rightharpoonup \mathrm{Boolean}} \\
    \Value_{\stride}(\Edit e)       &=& \True \\
    \Value_{\stride}(\Enter \tau)   &=& \True \\
    \Value_{\stride}(\Fail)         &=& \True \\
    \Value_{\stride}(e_1 \Then e_2) &=& \neg\Value(e_1)\wedge\Value_{\stride}(e_1) \\
    \Value_{\stride}(e_1 \Next e_2) &=& \Value(e_1)\vee\Value_{\stride}(e_1)\\
    \Value_{\stride}(e_1 \And e_2)  &=& \Value_{\stride}(e_1)\wedge \Value_{\stride}(e_2) \\
    \Value_{\stride}(t_1 \Or t_2)   &=& \neg(\Value(e_1)\vee\Value(e_2))\wedge\Value_{\stride}(e_1)\wedge\Value_{\stride}(e_2) \\
    \Value_{\stride}(t_1 \Xor t_2)  &=& \True
  \end{array} & &&
\end{flalign*}

\begin{flalign*}
  \begin{array}{lcl}
    \multicolumn{3}{l}{\Failing : \mathrm{Tasks} \to \mathrm{Booleans}} \\
    \Failing(\Edit v)       &=& \False \\
    \Failing(\Enter \tau)   &=& \False \\
    \Failing(\Update l)     &=& \False \\
    \Failing(\Fail)         &=& \True \\
    \Failing(t_1 \Then e_2) &=& \Failing(t_1) \\
    \Failing(t_1 \Next e_2) &=& \Failing(t_1) \\
    \Failing(t_1 \And t_2)  &=& \Failing(t_1) \wedge \Failing(t_2) \\
    \Failing(t_1 \Or t_2)   &=& \Failing(t_1) \wedge \Failing(t_2) \\
    \Failing(t_1 \Xor t_2)  &=& \False
  \end{array} & &&
\end{flalign*}

\todo{Is $\Failing$ preserved by $\stride$?}

\begin{flalign*}
  \begin{array}{lcl}
    \multicolumn{3}{l}{\Inputs : \mathrm{Tasks} \to \powerset(\mathrm{Inputs})} \\
    \Inputs(\Edit v:\Task\tau)       &=& \set{v':\tau, \Empty} \\
    \Inputs(\Enter \tau)   &=& \set{v':\tau} \\
    \Inputs(\Update l:\Task\tau)     &=& \set{v':\tau} \\
    \Inputs(\Fail)         &=& \set{} \\
    \Inputs(t_1 \Then e_2) &=& \Inputs(t_1) \\
    \Inputs(t_1 \Next e_2) &=& \Inputs(t_1) \cup \set{\Continue\mid \Value{(t_1)}\neq \bot \wedge \neg\Failing{(e_2 \Value{(t_1)}\stride)}} \\
    \Inputs(t_1 \And t_2)  &=& \set{\First\ i \mid i \in \Inputs(t_1)} \cup \set{\Second\ i \mid i \in \Inputs(t_2)} \\
    \Inputs(t_1 \Or t_2)   &=& \set{\First\ i \mid i \in \Inputs(t_1)} \cup \set{\Second\ i \mid i \in \Inputs(t_2)} \\
    \Inputs(e_1 \Xor e_2)  &=& \set{\Pick \Left, \Pick \Right}
  \end{array} & &&
\end{flalign*}

\newpage
\subsection{Normalising}

\begin{equation*}
  \boxed{\RelationN}
\end{equation*}

\paragraph{Step}
\begin{mathpar}
  \userule{S-ThenStay} \\
  \userule{S-ThenFail} \\
  \userule{S-ThenCont}
\end{mathpar}

\paragraph{Choose}
\begin{mathpar}
  \userule{S-OrLeft} \\
  \userule{S-OrRight} \\
  \userule{S-OrNone}
\end{mathpar}

\paragraph{Congruence}
\begin{mathpar}
  \userule{S-Next} \\
  \userule{S-And}
\end{mathpar}

\paragraph{Ready}
\begin{mathpar}
  \userule{S-Edit} \qquad \userule{S-Fill} \qquad \userule{S-Update} \\
  \userule{S-Fail} \qquad \userule{S-Xor}
\end{mathpar}

\paragraph{Driving}
\begin{mathpar}
  \userule{S-Eval}
\end{mathpar}

\todo{Do we need to normalise \refrule{S-And} further to a pair for nice equality properties or can we just use $\Value(t)$ to check if we have a pair?}

\subsection{Handling}

\begin{grammar}
  Inputs
    & i    & ::=& a                    & – action \\
    &      &\mid& \First i             & – pass to first \\
    &      &\mid& \Second i            & – pass to second \\
  Actions
    & a    & ::=& v                    & – change editor to value \\
    &      &\mid& \Empty               & – empty an editor \\
    &      &\mid& \Continue            & – continue with next task \\
    &      &\mid& \Pick r              & – pick route \\
  Routes
    & r    & ::=& \Left r              & – go left \\
    &      &\mid& \Right r             & – go right \\
    &      &\mid& \Here                & – stay here \\
\end{grammar}

\begin{equation*}
  \boxed{\RelationH}
\end{equation*}

\paragraph{Editing}
\begin{mathpar}
  \userule{H-Change} \qquad \userule{H-Empty} \qquad \userule{H-Fill} \\
  \userule{H-Update}
\end{mathpar}

\todo{
  Should $\Fail$ be a black hole or just go stuck?
  Probably it should go stuck, than $\Inputs(\Fail)$ is empty!
}

\paragraph{Continuing}
\begin{mathpar}
  \userule{H-PickLeft} \qquad \userule{H-PickRight} \\
  \userule{H-PickHere} \qquad \userule{H-Next}
\end{mathpar}

\todo{
  There is a problem with routes and picking $\Here$(ere):
  It is an input you can always send, so it fucks up $\Inputs$\ldots
  Should we only allow to pick $\Left$ or $\Right$ for the semantics?
}

\paragraph{Passing}
\begin{mathpar}
  \userule{H-PassThen} \qquad \userule{H-PassNext} \\
  \userule{H-FirstAnd} \qquad \userule{H-SecondAnd} \\
  \userule{H-FirstOr}  \qquad \userule{H-SecondOr}
\end{mathpar}

\subsection{Driving}

\begin{equation*}
  \boxed{\RelationD}
\end{equation*}

\begin{mathpar}
  \userule{D-Handle}
\end{mathpar}


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

\section{The standard electroweak model}

\subsection{Gauge theories}

\marginpar{Tuesday\\ 2021-12-7}

Yesterday we wrote the equation for a free fermion:
%
\begin{align}
\xi_{R, L} ' = \exp(- i \vec{\omega} \cdot \frac{\vec{\sigma}}{2} \pm \vec{u} \cdot \frac{\vec{\sigma}}{2}) \xi _{R, L}
\,.
\end{align}

The Dirac equation tells us that these are coupled:
%
\begin{align}
\left[\begin{array}{cc}
-m & E + \vec{p} \cdot \vec{\sigma} \\
E - \vec{p} \cdot \vec{\sigma} & m
\end{array}\right]
\left[\begin{array}{c}
\xi _R \\
\xi _L
\end{array}\right]
= 0
\,.
\end{align}

For nonzero mass these components are coupled, while in the zero-mass case they are decoupled and helicity is equal to chirality.

Helicity is the eigenvalue under \(\hat{p} \cdot \vec{\sigma}\), chirality is the eigenvalue under \(\gamma^{5}\).

\todo[inline]{What is the meaning of \(\gamma^{5}\) in position space? Is it a parity transformation?}

The coupling of a fermion to an external EM field can be represented with \(\partial_{\mu } \to \partial_{\mu } + iq A_\mu \).

The SM Lagrangian can be written on a mug as
%
\begin{align}
\mathscr{L} = - \frac{1}{4} F^{\mu \nu } F_{\mu \nu }
+ i \overline{\psi} \slashed{D} \psi + \text{h.c.}
+ i \psi_i y_{ij} \psi_j \phi  + \text{h.c.}
+ \abs{\slashed{D} \phi }^2 - V(\phi )
\,.
\end{align}

We have scalars \(\phi \), fermions \(\psi \) and spin-1 gauge fields \(A_\mu \).

From a Lagrangian \(L (q, \dot{q})\) we get Lagrange equations
%
\begin{align}
\dv{}{t} \pdv{L}{\dot{q}} - \pdv{L}{q} = 0
\,.
\end{align}

If the Lagrangian is, say, \(L = m \dot{q}^2 / 2 - V(q)\) we get Newton's law \(m \ddot{q} = - \vec{\nabla} V = F\).

This is classical; in field theory we have Lagrangians in the form
%
\begin{align}
\partial_{\mu } \pdv{\mathscr{L}(\phi , \partial \phi )}{ \partial_{\mu } \phi _i} - \pdv{\mathscr{L}}{\phi _i} = 0
\,.
\end{align}

We will write the Yukawa Lagrangian with terms like \(\psi \phi \), and the QED Lagrangian with terms like \(\psi A_\mu \).

The equation of motion for a scalar field is the Klein-Gordon equation: \((\partial_{\mu } \partial^{\mu } + m^2) \phi = 0\).
The Lagrangian giving rise to this is
%
\begin{align}
L = \frac{1}{2} \partial_{\mu } \phi \partial^{\mu } \phi - \frac{1}{2} m \phi^2
\,.
\end{align}

We have written the EOM for a free fermion, the Dirac equation \(\left(i \gamma^{\mu } \partial_{\mu } - m\right) \psi = 0\); the Lagrangian giving it is the Dirac Lagrangian
%
\begin{align}
\mathscr{L} = \overline{\psi} \left(i \gamma^{\mu } \partial_{\mu } - m\right) \psi
\,.
\end{align}

Again, we have a mass-like term and a kinetic-like term.

The term \(m \overline{\psi} \psi\) can be expanded into left and right components:
%
\begin{align}
m \overline{\psi} \psi = m \left( \overline{\psi}_R \psi _L + \overline{\psi}_L \psi _R\right)
\,.
\end{align}

What about the EM field? \(A_\mu \) is gauge-dependent, but
%
\begin{align}
F_{\mu \nu } = 2 \partial_{[\mu  } A_{\nu ]}
\,
\end{align}
%
is not. The Lagrangian giving Maxwell's equations in a vacuum (so, \(\square A^{\mu } = 0\) in the appropriate gauge) is
%
\begin{align}
\mathscr{L} = - \frac{1}{4} F_{\mu \nu } F^{\mu \nu }
\,.
\end{align}

The absence of a mass term means that the photon is massless.

What about interactions?
We start from the Yukawa interaction between a fermion and a scalar.
The Lagrangian, for starters, must contain the free terms for both:
%
\begin{align}
\mathscr{L} = \underbrace{\overline{\psi} \left(i \gamma^{\mu } \partial_{\mu } - m_\psi \right) \psi + \frac{1}{2} \left( \partial_{\mu } \phi \partial^{\mu } \phi -  m_\phi  \phi^2 \right) }_{\text{free terms}} - \underbrace{g \overline{\psi} \psi \phi}_{\text{interaction}}
\,.
\end{align}

The pictorial way to represent this is to draw quadratic terms for fermions like straight lines with an arrow, scalar fields as dashed lines, and cubic interaction terms like vertices.

What do fermion-photon interactions look like?
%
\begin{align}
\mathscr{L} _{\text{QED}} = \overline{\psi} \left(i \gamma^{\mu } \partial_{\mu } - m_\psi \right) \psi - \frac{1}{4} F^{\mu \nu } F_{\mu \nu } - q \overline{\psi} \gamma^{\mu } \psi A_\mu
\,.
\end{align}

The EOM for the electromagnetic field are  Maxwell's equations with an external current \(j^{\mu } = q \overline{\psi} \gamma^{\mu } \psi \).

This is the same Lagrangian we get if we do a minimal coupling substitution \(\partial \to \partial + iqA\).
It is invariant under gauge transformations.

These diagrams can be used to compute scattering amplitudes perturbatively.

The way to get a cross-section is to multiply the square modulus of the amplitude by the phase space term.
The idea to get decay rates is similar.

The guiding principle to describe EW interactions is gauge invariance.
The Yukawa Lagrangian has global phase invariance; what happens if we try to make a transformation \(\psi \to e^{- i q \alpha (a)} \psi \)?
The term \(q\) is only introduced here for later convenience.

The timezone analogy for local gauge invariance!
If we have the freedom to choose a phase locally, we must have carriers of information moving at the maximum possible speed, otherwise processes would be disrupted.

We start with \(U(1)\) gauge invariance, as written above, but we will also need \(SU(2)\) invariance, written as
%
\begin{align}
\exp(- ig \vec{\theta} \cdot \vec{T})
\,,
\end{align}
%
where \(\vec{T} = \vec{\sigma} / 2\), but we write them differently to not confuse them with spacetime rotations.

Introducing gauge invariance for a term \(\overline{\psi} \left(i \slashed{\partial} - m \right) \psi \) will take us to the QED Lagrangian.

The mass term is already invariant, the problem is the kinetic one.
The trick is to introduce a covariant derivative
%
\begin{align}
\text{D}_\mu = \partial_{\mu } + iq A_\mu
\,.
\end{align}

If \(\psi \to e^{-iq \alpha (x)} \psi \), also \(\text{D}_\mu \psi \to e^{-iq \alpha (x)} \text{D}_\mu \psi \), as long as \(A_\mu \) also transforms like \(A_\mu \to A_\mu + \partial_{\mu } \alpha \).

Then, the Lagrangian
%
\begin{align}
\mathscr{L} = \overline{\psi} \left( i \slashed{\text{D}} - m \right) \psi  - \frac{1}{4} F^{\mu \nu } F_{\mu \nu }
\,.
\end{align}

A term like \(m^2 A_{\mu } A^{\mu }\) would violate gauge invariance, so this principle also gives an explanation as to why the photon is massless if we accept the gauge invariance principle.

Protons and neutrons were thought to be part of a doublet under isospin SU(2) transformations.

But, we have interactions like protons and neutrons interacting with electrons and neutrinos.
So, one might think that electrons + neutrinos have isospin-like SU(2) symmetry as well.

We want to make the doublet \(\psi_1 , \psi_2 \) invariant under SU(2) transformations as written above: how do we do it?
Again, we redefine the derivative:
%
\begin{align}
\partial_{\mu } \to \text{D}_\mu - ig \vec{T} \cdot \vec{A}_\mu
\,,
\end{align}
%
so we need to introduce three fields \(\vec{A}_\mu \). These are the gauge bosons related to SU(2) gauge invariance.

These now transform like
%
\begin{align}
\vec{A}_\mu \to \vec{A}_\mu - \partial_{\mu } \vec{\theta}(x) + g \vec{\theta} \times \vec{A}_\mu
\,.
\end{align}

The presence of this coupling means that the field is charged.

The field tensor here is
%
\begin{align}
\vec{F}_{\mu \nu } = 2 \partial_{[\mu } A_{\nu ]} + g \vec{A}_\mu \times \vec{A}_\nu
\,.
\end{align}

We then get a Lagrangian like
%
\begin{align}
\mathscr{L} = \overline{\psi} \left( i \gamma^{\mu } \text{D}_\mu -m\right) \psi - \frac{1}{4} \vec{F}^{\mu \nu } \cdot \vec{F}_{\mu \nu }
\,.
\end{align}

In the \(\psi \) term we have \(\psi \psi \) terms, as well as \(\psi \psi A\) interactions.
In this \(F^2\) term we have quadratic, trilinear and quadrilinear terms in \(A\)!

The actual group for the EW theory is \(SU(2)_L \otimes U(1)_Y\).
The simplest EW world contains
\begin{enumerate}
    \item 1 massive electron, with both right- and left-handed components;
    \item 1 massless \(\nu _e\), with only the left-handed component;
    \item EM interactions (we want to have a diagram describing how the electron interacts with a massless photon);
    \item weak chiral interactions like \(\nu _L e_L W^{\pm}\), where \(W^{\pm}\) is massive.
\end{enumerate}

The Higgs mechanism accomplishes this, and it also gives mass to fermions.
If neutrinos have Majorana masses, the Higgs mechanism cannot give them mass.

Let us define a doublet \(L=(e_L, \nu _{e, L})\), and a singlet \(R = e_R\).
The theory must then be invariant if we redefine
%
\begin{align}
L &\to L' = \exp(-i g \vec{\theta}(x) \cdot \vec{T}) L  \\
R &\to R' = R
\,.
\end{align}

The doublet \(L\) corresponds to the \(T_3 = \pm 1/2\) quantum numbers, while \(T_3 = 0\) for the singlet.

Could the three bosons be some combinations  of the photon and the two \(W^{\pm}\) bosons? We know that the charge operator \(Q\) has eigenvalues \(0\), \(-1\)  for the doublet, but \(\Tr Q \neq 0\) while \(\Tr T_i = 0\) for all \(T_i\).

Why would \(Q\) need to be able to be written as a function of the \(T_i\)?
The proper answer lies in Nöther's theorem.

We therefore introduce a further hypercharge symmmetry:
%
\begin{align}
L' &= \exp(- i g' \beta (x) \frac{Y}{2}) L \\
R' &= \exp(- i g' \beta (x) \frac{Y}{2}) R
\,,
\end{align}
%
so that this generator commutes with the \(T_i\), and indeed \([T_i, Y] = 0\). The only way to have this is \(Y \propto Q - T_3\), and indeed \(Y = 2 (Q - T_3)\).

In the end, the Lagrangian must be chargeless.

The full transformation is therefore
%
\begin{align}
L' = \exp(-i g \vec{\theta}(x) \cdot \vec{T} - ig' \beta (x) \frac{Y}{2}) L \\
R' = \exp( - ig' \beta (x) \frac{Y}{2}) R
\,.
\end{align}

The procedure is then like before: we need to redefine the derivative, as
%
\begin{align}
\text{D}_\mu L =\left(  \partial_{\mu } + i g \vec{T} \cdot \vec{A}_\mu - i g' \frac{Y}{2} B_\mu  \right) L
\,,
\end{align}
%
so we have four fields, the three \(\vec{A}_\mu \) with their \(\vec{F}_{\mu \nu }\) and \(B_\mu \) with its \(G_{\mu \nu }\).

The Lagrangian will then read
%
\begin{align}
\mathscr{L} =
\overline{L} i \gamma^{\mu } \text{D}_\mu L
+
\overline{R} i \gamma^{\mu } \text{D}_\mu R + \text{kinetic}
\,,
\end{align}
%
but we cannot write mass terms like \(m \overline{\psi} \psi \), which would be \(\overline{L} R\) or \(L \overline{R}\): the matrix dimensions don't match up!

So, everything's massless: the Higgs mechanism comes to the rescue.
It gives masses to all the bosons except the photon, as well as giving mass to the leptons.

Suppose we have a \(U(1) \otimes U(1)\) symmetry, spontaneously broken to \(U(1)\). The thing we think of is a pencil about to fall on a table.

\end{document}


\section{Conclusion}

We proposed a method that builds on top of existing approaches for homography estimation that utilize existing point correspondences. The method is a systematic ranking of a set of homography matrices while exploiting the proposed score function to establish the order. Each homography in such a set belongs to a specific marker.

We consistently demonstrated that the proposed solution is robust in presence of noise in the point correspondences. These correspondences can be either algorithmically found using feature-matching algorithms or annotated manually, but one has to keep in mind that even human annotations are often inaccurate. We also showed the robustness of our method to a varying number of markers and a change in shape.

Generally speaking, all the improvements at individual ranking positions steadily decreased, reaching $0$\% improvement at around $\nicefrac{2}{3}~m$, where $m$ is the number of markers. A practically applicable statement would be the following: ``the first half of ranked homographies yields a better reprojection compared to the baseline on average.''. The baseline performance was given by an average \opencv{}~\cite{bradski2008learning} reprojection error under the assumption of no prior preference of specific markers, hence the random marker selection.

An advantage of our algorithm is that it is invariant to the underlying homography estimation method. It can serve as an extension to all existing or future approaches that handle point correspondences, either as part of run time or a post-processing stage. Moreover, it is computationally efficient, as it scales well with a quadratic complexity $\func{\Theta}{m^2}$ in the number of markers, which is usually a single-digit number.

The proposed homography ranking found a real-world application within our solution for the university-related \interreg{} project where we tackled the problem of tracking vehicles for the purpose of speed and dimension estimation. However, we did not continue with this branch of research due to the lack of available datasets that we would require for a deep learning-based object tracking solution involving perspective projections.


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

% \marginpar{Thursday\\ 2019-11-21, \\ compiled \\ \today}
% \section*{Thu Nov 21 2019}

% We exponentiate the equation from before:
% we get
We can approximate this as
%
\begin{align}
  X_d \approx X_n (1 - X_n)
  \exp(-29.33 + \frac{25.82}{T_9  } - \frac{3}{2} \log T_9 + \log ( \Omega_{0b} h^2 ))
\,,
\end{align}
%
where \(T_9  =  T / \SI{e9}{K}\).
The factor \(\Omega_{0b} h^2\) comes from the scaling of the baryon-to-photon ratio \(\eta\) (equation \eqref{eq:baryon-to-photon-ratio}).

\todo[inline]{\textcite[]{paccianiAppuntiCorsoPhysical2018} says we use the exponential decay of the neutron population to find this formula: how does it come in, though?}

% \todo[inline]{What is going on? What is \(T_{\rho }\)? }

% We want to understand why there is so much He-4 in the universe, since it is destroyed in stars!
Almost all the deuterium which is formed then turns into \ce{^{4}He}, so since those nuclei are as heavy as four neutrons, and two neutrons are needed to make each we can estimate that the helium mass fraction will be given by \(Y \approx 2 X_n \approx \num{.25}\).
The calculation is quite rough, in order to do it properly we should use the Boltzmann equation.

\todo[inline]{Very rough calculation\dots the corrective factor of \num{.8} is kind of thrown in there, also I think using \(\exp(-1.5)\) instead of \(\exp(-1.3)\) helps nudging the number and hides just how rough this is}

% \todo[inline]{This is indirect evidence for dark energy: why?}

This provides an experimental bound for many parameters: the lifetime of the neutron, for example, cannot be much shorter since otherwise too many would have decayed before forming deuterium.

The reaction rate \(\Gamma \) for weak interactions, as we have discussed earlier, is given by \(\Gamma \sim G_F^2 T^5 \approx T^{5} / \tau _n\), where the Fermi coupling constant \(G_F\) is connected to the lifetime of the neutron \(\tau_n\) since that is also a weak-interaction process.

Then, the moment of decoupling \(\Gamma \sim H\) also constrains \(\tau _n\), since it happens at a temperature \(T_{d \nu } \sim G_F^{-2/3} m_P^{-1/3} \approx \tau_n^{4/3} m_P^{-1/3}\).\footnote{One might think that the lifetime of the neutron would be a well-established result in Earthly particle physics, but in fact there is a conflict between two different kinds of measurements \cite[]{wolchoverNeutronLifetimePuzzle}, so while the value is roughly known the error bars of these measurements do not overlap: this is the ``neutron lifetime puzzle''.}
% Let us suppose we increase the lifetime of neutrons, \(\tau_{1/2}\).
% This changes the moment at which we reach equation \(\Gamma \sim H\).

Increasing the lifetime of neutrons decreases the amount of He-4 in the universe.

We know that the Hubble parameter is given by
%
\begin{align}
  H^2 = \frac{8 \pi G}{3} \underbrace{\frac{\pi^2}{30} g_{*}(T) T^4}_{\rho = \rho _r}
\,,
\end{align}
%
so \(H(T) \sim \sqrt{g_* (T)}\): this means that if we add more particles to our model which are coupled in the \(\sim \SI{}{MeV}\) range, thus increasing \(g_*\) at that temperature, we also increase \(H\), which means that the moment at which \(\Gamma < H\) comes about earlier, meaning that we get more Helium.
This is very useful constraint on our models; for instance, any dark matter particle we hypothesize needs to not ``break baryogenesis''.

% If we fix the temperature, and change \(g_{*}\) (by adding degrees of freedom), then we get more He-4.

% This gives us observational constraints on the additions of exotic particles to our theory, since that would change \(g_{*}\).
% This bounds the number of neutrino families by \num{3.} something, so there cannot be more than \num{3} families of light neutrinos.

% If gravitons are thermal, then they also contribute to radiation.

Decreasing the baryon fraction \(\Omega_b\) inhibits the production of deuterium, since then there are more photons to disassociate them.
We find that the model fits observation as long as \(\num{.011} h^{-2}\leq \Omega_{0b} \leq \num{.25} h^{-2}\); most people agree that we are near the upper bound of this range.

There is also another parameter, \(m_P \sim G^{-1/2}\): modified gravity theories often predict variations of the gravitational constant with time, but since this appears in our calculations we can constrain its value at that stage in the early universe.

\section{Dark Matter dynamics}

We have described how dark matter came to be accepted as a necessary component of the matter content of the universe, now we wish to understand what are its basic properties.

Observationally, dark matter has no relevant electromagnetic interactions: in the low-redshift universe it only interacts gravitationally (it is \emph{decoupled}), and is able to cluster.

This allows us to distinguish it from dark energy, which instead is uniformly distributed.

Models of dark matter can be classified into \textbf{Hot and Cold dark matter}: HDM and CDM.
We can also have \emph{Warm} dark matter, which has intermediate properties.

In \textbf{HDM}, particles decoupled while they were ultrarelativistic, so they have very high thermal motion.
They move fast, and tend to destroy gravitational potential wells in which they might settle by moving out of them, and thus decreasing the quantity of matter there.
Neutrinos were thought to be Dark Matter, and would have been classified as HDM.

They do this on scales comparable to the maximum distance travelled by them: this is calculated as \(vt\), where \(v\) is their average thermal velocity, and \(t\) is the age of the universe.

This means that the structures formed in the presence of HDM are larger than \(\num{e15} M_{\odot}\); however this seems to conflict with observation, since we also see smaller structures!
The hypothesis is then that they were formed later, by fragmentation: this is known as the \emph{top-down approach}.

The top-down approach, however, is falsified by the observation of high-redshift quasars combined with the scale of the anisotropies of the CMB: in order to account fo high-redshift small-scale structures (we have seen stars at \(z \sim 20\)!) we would have to increase the amplitude of the anisotropies to a scale which is not compatible to the anisotropies we see in the CMB.
This does not mean that HDM cannot exist, but it cannot make up most of the observed DM density.

\textbf{CDM}, on the other hand, is dark matter which decoupled at a time when it was already nonrelativistic.
A \emph{bottom-up} approach to structure formation is compatible with the existence of CDM.
This is the kind of dark matter which appears in the currently-accepted \(\Lambda\)CDM model of cosmology.

Although it is the best model to date, there are also issues with CDM, which are current research topics.
Dark matter is distributed in \emph{halos}, gravitationally-bound regions which contain dark matter and are currently decoupled from cosmic expansion.

One issue is that simulations predict small-scale halos in the larger ones, which are however not observed.
Also, the density profiles from simulations do not seem to match what is observed: they have a cusp in the center of the halo, while observations suggest that density profiles are flat in the center.

There are many proposed solutions to these problems: for example, dark matter could self-interact in ways other than gravitational, or it could be warm.

% We also have a bottom-up approach, which is compatible with CDM.

% Now, neutrinos are not useful for cosmology.

% We have \(\Gamma \sim T^{5}\), and \(\Gamma = H\):
% \(T^{5} / \tau_{1/2} \sim T^2\) implies that \(\tau_{1/2} \sim T^{3}\).

% The decouplig temperature for HDM is larger than the temperature at which they become nonrelativistic, which is of the order of the mass.

% For CDM, instead, the decoupling temperature is \emph{smaller} than the temperature at which they become relativistic.

\subsection{The Boltzmann equation and decoupling}

In order to understand how Dark Matter evolves, let us introduce the main equation used to analyze non-equilibrium phenomena: the \textbf{Boltzmann equation}. It describes the evolution of the phase space distribution of particles, \(f\). Its compact form is:
%
\begin{align}
  \mathbb{L} [f] = \mathbb{C} [f]
\,,
\end{align}
%
where \(\mathbb{L}\) is the \emph{Liouville operator}, which is a total derivative of the phase space density with respect to changes in time, position as well as momentum; while \(\mathbb{C}\) is the \emph{collision operator}, which describes the effect (in terms of variation per unit time) on the phase space distribution of collisions between particles --- it is written in terms of scattering matrices.
% where all the scattering operators live on the RHS.
In general, we should consider the phase space distribution of all the particle species, writing an equation for each of theses \(f_i\); now we will treat a single particle species for simplicity.

This basic form is quite general: it can be used both for a simple Newtonian calculation and to include general-relativistic and quantum-mechanical effects.

We start with the Newtonian description: the phase space has position, momentum and time as coordinates, and a density function \(f(\vec{q}, \vec{p}, t)\) is defined on it.

% The Einstein equations are blind to the momentum distribution, since \(T_{\mu \nu }\) does not depend on the momentum.
% We can say that all of the momentum has been marginalized.

The classical form of the Liouville operator is the \emph{convective derivative},
%
\begin{subequations}
\begin{align}
  \mathbb{L} = \frac{D}{Dt} &= \pdv{}{t} + \dv{\vec{x}}{t} \cdot \nabla_x + \dv{\vec{p}}{t} \cdot \nabla_p   \\
  &= \pdv{}{t} + \vec{v} \cdot \nabla_x + \frac{\vec{F}}{m} \cdot \nabla_p
\,.
\end{align}
\end{subequations}

% Applying this to a classical fluid yields the Navier-Stokes equations, as long as we distinguish the force term \(\vec{F}\) into forces proportional to volume and forces proportional to area.
This equation describes motion in much more detail than, say, the Navier-Stokes equations, since it allows for arbitrary momentum \emph{at each point} in space.
We can recover the N-S equations, as well as the energy and mass conservation equations, by taking \emph{moments} of the Boltzmann equation: we multiply it by \(m \vec{v}\), or \(m v^2 / 2\), or \(m\), and integrate in \(\dd[3]{p}\).

In the Newtonian case, the force term \(\vec{F}\) includes gravity, which in GR instead is ``geometrized'', meaning that it is included in the inertial motion of the particles.
The relativistic version of the Liouville operator is written in terms of position \(x^{\alpha }\) and momentum \(p^{\alpha } = \dv*{x^{\alpha }}{\lambda }\)
%
\begin{align}
\mathbb{L}
&= \dv{x^{\alpha }}{\lambda } \pdv{}{x^{\alpha }}
+ \dv{p^{\alpha }}{\lambda } \pdv{}{p^{\alpha }} \\
&= p^{\alpha } \partial_{\alpha } - \Gamma^{\alpha }_{\beta \gamma } p^{\beta } p^{\gamma } \pdv{}{p^{\alpha }}
\,.
\end{align}

\todo[inline]{Is the momentum supposed to be dimensionless or not? Setting \(\dv*{x^{\alpha }}{\lambda } = p^{\alpha }\) as well as \(p^2= m^2\) seems contradictory\dots}

This is because, since any particle must move along geodesics, \(p^{\alpha }\) must satisfy the geodesic equation:
%
\begin{align}
\frac{Dp^{\alpha }}{Dt } =
\dv{p^{\alpha }}{\lambda } + \Gamma^{\alpha }_{\beta \gamma } p^{\beta } p^{\gamma }=0
\,.
\end{align}

% We can then write down the Christoffel bit of the geodesic equation instead of the derivative \(\dv*{p^{\alpha }}{\lambda }\).
We require that the particles are \emph{on shell}:
%
\begin{align}
  g^{\alpha \beta } p_{\alpha } p_{\beta } = m^2
\,,
\end{align}
%
meaning that we are neglecting the uncertainty principle and our discussion is relativistic but classical (not fully quantum-mechanical).

% We want to describe the \emph{abundance} of dark matter, in phase space: the number of DM particle per EM-interacting particle.

Let us make this explicit, using the Christoffel symbols of the FLRW metric and assuming isotropy and homogeneity (which together imply that the phase space density \(f\) only depends on \(t\) and \(p^{0} = E\)): many terms vanish, and we are left with
% Acting on \(f\), we get
%
\begin{align}
\mathbb{L}[f]
= p^{0} \partial_{t}f - \Gamma^{0}_{ij} p^{i} p^{j} \pdv{f}{E}
= E \partial_t f - \frac{\dot{a}}{a} \abs{\vec{p}}^2 \pdv{f}{E}
\,,
\end{align}
%
% which we will not prove.
% The derivative with respect to the momentum must be \(\partial_{p^{0}}\),
% \todo[inline]{because of isotropy?}
since the relevant Christoffel symbols (in Cartesian coordinates) are
%
\begin{align}
  \Gamma^{0}_{ij } = \frac{\dot{a}}{a} \delta_{ij }
\,.
\end{align}

So, we can write the Boltzmann equation as
%
\begin{align}
\pdv{f}{t} - \frac{\dot{a}}{a} \frac{p^2}{E} \pdv{f}{E} = \frac{\mathbb{C} [f]}{E}
\,.
\end{align}

% so in the end the equation becomes:
% %
% \begin{align}
%   \hat{\mathbb{L}} = \dot{n} + 3 \frac{\dot{a}}{a} n
% \,.
% \end{align}
% %

% % Conventionally we divide by \(p^{0}\): we get for the Boltzmann equation:
% %
% \begin{align}
%   \pdv{f}{t} - \frac{\dot{a}}{a } \frac{p^2}{E} \pdv{f}{E} = \frac{1}{E} \hat{\mathbb{C}} [f]
% \,.
% \end{align}

Let us now do what is also done in the classical case and integrate in \(\dd[3]{\vec{p}}\): we will lose detail in the description but gain in computability.
First, recall the definition of the number density from the phase space distribution:
%
\begin{align}
  n(t) = \frac{g}{(2\pi )^3} \int  \dd[3]{\vec{p}} f(\abs{\vec{p}}, t)
\,,
\end{align}
%
which appears in the first term if we integrate the Boltzmann equation (also multiplying by \(g / (2 \pi )^3\)):
%
\begin{align}
  \pdv{n}{t} - \frac{g}{(2 \pi )^3} \frac{\dot{a}}{a } \int  \dd[3]{\vec{p}} \frac{p^2}{E} \dv{f}{E} = \frac{g }{(2\pi )^3} \int  \dd[3]{p} \frac{1}{E} \mathbb{C} [f]
\,.
\end{align}
%
% More properly, we are doing \(\mathbb{L} \expval{f}\).

The number density actually also appears in the second term: we can manipulate it as
%
\begin{subequations}
\begin{align}
  \int \dd[3]{p} \frac{p^2}{E} \pdv{f}{E}
  &= 2 \int \dd[3]{p} p^2 \pdv{f}{(E^2)}
  = 2 \int \dd[3]{p} p^2 \pdv{f}{(p^2)}  \marginnote{\(\dd{(E^2)} = 2 E \dd{E}\) and similarly for \(\dd{(p^2)}\).}\\
  &= \int \dd[3]{p} p \pdv[]{f}{p}
  = 4 \pi \int_{0}^{ \infty } \dd{p} p^3 \pdv{f}{p}  \\
  &= \eval{4 \pi p^3 f}_{0}^{\infty } - 4 \pi \int_{0}^{\infty } \dd{p} 3 p^2 f
  = -3 \int \dd[3]{p} f = -3n \frac{(2 \pi )^3}{g}
\,.
\end{align}
\end{subequations}

The boundary term vanishes since at \(0\) we have \(p=0\), and at (momentum) infinity we have \(f=0\) (since otherwise the energy would diverge). We are also moving back and forth between integrals in \(\dd[3]{p}\) and in \(\dd{p}\) times \(4 \pi \), which we can do because of isotropy.

So, we can see that the left-hand side is equal to \(\dot{n} + 3 \dot{a}n/a \), and we have the \textbf{cosmological Boltzmann equation}
%
\begin{align}
  \dot{n} + 3 \frac{\dot{a}}{a} n = \frac{g}{(2 \pi )^3} \int \dd[3]{p} \frac{1}{E} \hat{\mathbb{C}} [f]
\,.
\end{align}

% This is the cosmological version of the Boltzmann equation.

Right away we can see that this makes sense in the decoupling limit: if there are no collisions the right-hand side must vanish, so we are left with
%
\begin{align}
\dot{n} + 3 \frac{\dot{a}}{a} n = \dv{}{t} \qty(n a^3) = 0
\,,
\end{align}
%
meaning that \(n \propto a^{-3}\): this is the usual scaling of the number density, so our approach is working.

Now we need to understand what the right-hand side looks if particle species are coupled. This is difficult in general, we will give an expression using ``bulk'' parameters:
%
\begin{align}
  \frac{g}{(2 \pi )^3} \int \frac{ \dd[3]{p}}{E} \hat{\mathbb{C}}[f]
  = \Psi - \Gamma_A n
  = \Psi - \expval{\sigma v } n^2
\,,
\end{align}
%
where \(\Psi \) is the rate of creation of particles per unit volume, while \(\Gamma_A\) is the rate of annihilation. Note that \(\Psi \) has the dimensions \SI{}{s^{-1} m^{-3}}, while \(\Gamma _A\) has the dimensions \SI{}{s^{-1}}, so it needs to be multiplied by \(n\) in order to be dimensionally consistent.
Physically speaking, the reason the term has that form is that the rate of annihilation must be proportional to the number density of particles there are at the moment.

The annihilation rate is found in terms of the cross section of the process, which we must average over all the momentum distribution of the particles: this is the reason for the appearance of \(\expval{\sigma v}\).

% where we have \(\Gamma_A = \expval{\sigma v} n\) times \(n\), where \(\Gamma \) is the rate of annihilation.

At equilibrium, the left-hand side is equal to zero. The number density will be given by some equilibrium value, \(n _{\text{eq}}\): inserting this in the right-hand side, which must also vanish, we find \(\Psi = \expval{\sigma v} n^2 _{\text{eq}}\).
This result can then be used in general: the right-hand side is written as \(\expval{\sigma v} \qty(n^2 _{\text{eq}} - n^2)\).

\end{document}


\section{Subrings}