\chapter{Theoretical Background}
As seen in the related work section, many sophisticated ideas have already been proposed stating how the task of motion segmentation on RGB-D videos can be addressed. In this thesis, we aim to approach this issue by incorporating optical flow fields to track motion trajectories and then group them by running a spectral clustering. However, there exist many possibilities how to implement a spectral clustering on trajectories. \\ \\
In this chapter we give an introduction about various mathematical concepts which form the fundament to understand the implementation of our motion segmentation pipeline and how its results were computed. In particular, we will discuss the concepts of optical flow and spectral clustering, since they are essential concepts used throughout this thesis. \\ \\
We start by defining a general motion segmentation pipeline and elaborate on its stages, which later will be used as a blue print for our later pipeline implementation. Next we give a brief introduction in optical flow fields by offering the reader a basic definition, some insights about the pioneering motion estimation work of Horn and Schunck and summarize four modern flow methods. We will see that optical flow fields are particularly useful for tracking point trajectories. Since we determine motion by grouping trajectories, the quality of the optical flow affects the final outcome of the motion segmentation. \\ \\
Finally, since our pipeline implements segmentation methods that are all based on spectral clustering variants, we wrote a dedicated section about clustering data points, in which we explain the idea behind clustering methods and how they can be implemented. Moreover, we state some important definitions about similarity graphs and their properties, how to form the Laplacian matrix from a similarity graphs and the differences between k-means and spectral clustering. We conclude this section by stating that optimizing for the minimum cut on a similarity graph is an equivalent to the problem of computing the spectral clustering on its Laplacian matrix.

\section{General Motion Segmentation Pipeline}
In this section, we conceptually describe how the task of motion segmentation can be approached. As mentioned earlier, motion segmentation is the task of decomposing a video sequence into its moving objects and into its background. The idea is to separate image regions that undergo different motion patterns. Therefore, we want to consider motion not independently for each frame but rather the whole history of a point to make a grouping decision. The history of a point can be represented by point trajectories which are the result of a point tracker. The point tracking is based on optical flow fields. \\ \\
Since point trajectories have a temporal- (via the frames the capture) as well as a spatial (via image location in captured frames via the tracked points) component, they are an ideal intermediate representation for the motion of object parts.
\begin{figure}[H]
\begin{center}
\includegraphics[width=1\linewidth] {background/general_pipeline}
\end{center}
\caption[General Motion Segmentation Pipeline]{A sketch of a motion segmentation pipeline$\footnotemark$ consists of the two stages: track motion trajectories and group trajectories on their similarities. For a given RGB-D video sequence we first have to track motion trajectories on reliable features. By comparing the resulting trajectories according to a certain measure we can perform a grouping. Every group consists of similar trajectories. The final motion segmentation is directly represented by the grouped trajectories.}
\label{fig:general_moseg_pipeline}
\end{figure}
\footnotetext{To create Figure $\ref{fig:general_moseg_pipeline}$ I used a frame of the Bonn Chairs dataset from: \url{http://www.ais.uni-bonn.de/download/rigidmultibody/}}
In recent Computer Vision literature, various contributions have already successfully demonstrated that motion segmentations can be cast as the problem of clustering point trajectories from an image sequence with respect to their motion. For instance in $\cite{OB14b}$, T.Brox et al implemented a motion segmentation based on a spectral clustering on motion trajectories. In particular, they described a certain similarity measure that can be used to form such a similarity matrix. In $\cite{KB15b}$ the authors followed a similar approach but formed a similarity graph. The segmentation was generated by running a multi min-cut. \\ \\
In this thesis we want to follow a similar approach as described in those two contribution. For this purpose we compared their segmentation pipelines and derived a general motion segmentation pipeline as sketched in Figure $\ref{fig:general_moseg_pipeline}$. In summary, a motion segmentation pipeline implements the following main stages:
\begin{enumerate}
	\item Compute optical flow fields on the video sequence.
	\item Extract meaningful motion feature locations in the video frames.
	\item Track motion trajectories on feature locations using the flow fields.
	\item Compute affinities between these trajectories and form a similarity matrix.
	\item Group the trajectories via a spectral clustering on the affinity matrix.
\end{enumerate}
However, keep in mind that this motion segmentation technique also suffers from some issues: Trajectories usually start and end in different frames due to occlusion and disocclusion. Therefore, it is crucial to know where points get occluded. Furthermore, there are various metrics that can be used to compute distances between trajectories, such as their spatial-, color- or motion-distance. Moreover, there are many mathematical variants to solve the problem of spectral clustering. Lastly, the used optical flow estimation method should be carefully chosen since it affects the quality of the final segmentation. \\ \\
In next chapter we describe how we implemented such a motion segmentation pipeline by following these main stages. In particular, we will address all issues described above and provide robust solutions.

\section{Optical Flow}
\label{sec:optical_flow}
In this section we, explain the principles and the idea behind optical flow. We motivate this concept by discussing an intuitive example, followed by stating a mathematical definition. Furthermore, we explain how such a flow field could be visually represented. Lastly, we summarize and elaborate on the pioneering formulation of Horn and Schnunck, which can be used to estimate flow fields.

\subsection{Motivation}
The optical flow ($\textbf{OF}$) is a vector field that defines a point-to-point correspondence between two successive frames. Each vector acts as the displacement of a point in the first frame to match its corresponding point in the second frame. In other words, the OF represents the pixel motion field as observed in images and thus answers the question which pixel went where in its successor frame. Ideally, the optical flow is the projection of the three dimensional motion on an image. \\ \\
Figure $\ref{fig:optical_flow_math_def_eg}$ illustrates the idea of the point-to-point correspondence using optical flow fields.
\begin{figure}[H]
\begin{center}
\includegraphics[width=1\linewidth] {background/of/rubiks_cube_frames}
\end{center}
\caption[Spinning Rubik's Cube]{An illustration$\footnotemark$ of two frames of a spinning Rubik's Cube. The point-to-point correspondence of a sample point (the orange point) is given by the optical flow, depicted as a red arrow.}
\label{fig:optical_flow_math_def_eg}
\end{figure}
\footnotetext{The unprocessed image shown in this figure has been taken from: \\ \url{http://robotics.eecs.berkeley.edu/~sastry/ee20/vision3/node2.html}}
In this figure two frames of a spinning Rubik's cube at different times are shown. The orange point $p = (x,y)$ at time $t$ is tracked to the position $(x+u, y+v)$ at time $t+dt$ by adding the optical flow $(u,v)$ (visualized by a red arrow) to $p$. This matter of a fact can mathematically be modelled via the brightness consistency assumption, stated in Equation $\ref{eq:of_brightness_const}$.
\begin{equation}
	I_{t} \left( x,y \right) = I_{t+dt} \left( x+u, y+v \right)
\label{eq:of_brightness_const}
\end{equation}
Where $I_t$ depicts the brightness at frame $t$.

\subsection{Visualization of Flow Fields}
For visualizing flow fields we use the Middlebury$\cite{Baker2011}$ flow color encoding$\footnote{The corresponding visualizer script can be found at \url{http://vision.middlebury.edu/flow/submit/}}$ shown in Subfigure $\ref{fig:color_encoding_flows_a}$. The shown color plate provides color values for the normalized$\footnote{One way to normalize a set of vectors is the following: Divide each vector by the maximal length of these vectors.}$ flow vectors. The angle in the circle corresponds to the flow direction and the distance to the center corresponds to the flow velocity. Moreover, Figure $\ref{fig:color_encoding_flows}$ also contains an example of a flow visualization using these color codes. As we can see the cars are moving to the bottom-right direction at a intermediate velocity.
\begin{figure}[H]
\begin{center}
\subfigure[Flow Color Codes]{
   \includegraphics[width=0.40\linewidth] {background/of/flowfield_color_encoding}
   \label{fig:color_encoding_flows_a}
}
~
\subfigure[Example flow visualization]{
   \includegraphics[width=0.535\linewidth] {background/of/cars_fwf_1}
   \label{fig:color_encoding_flows_b}
}
\end{center}
\caption[Visual Color Encoding of Flow Fields]{On the left a visualization of the color plate used to draw flow fields and on the right flow field visualized by this color scheme.}
\label{fig:color_encoding_flows}
\end{figure}

\subsection{Original Flow Estimation Method of H.S.}
\label{sec:hs_formulation}
In the pioneering work of $\cite{Hs81}$, B. Horn and B. Schnunck describe a technique to estimate the optical flow. Their method assumes smoothness in the flow over the whole image. Their flow estimation is formulated as a global energy functional and can numerically be solved via the Jocobi method$\footnote{The Jacobi method is an iterative method used to solve linear systems.}$. The advantage of their method is that it produces flow fields where the inner parts of homogeneous objects is filled in from the motion boundaries. However, its downside is that is very sensitive to noise. \\ \\
Back then they defined the optical flow as \textit{the distribution of apparent velocities of movement of brightness patterns in an image}. \\ \\
Moreover, they already understood the potential of the optical flow and stated the following properties: It can arise from relative motion between objects and the viewer, provides information about the spatial arrangement of the viewed objects and the rate of change in that arrangement. Moreover, they mentioned that discontinuities in the optical flow can help to perform segmentation tasks. \\ \\
Sticking to their flow definition they derived an equation that relates the change in the image brightness at a point to the motion of the brightness. \\ \\
Their formulation is based on the following assumptions:
\begin{itemize}
  \item The surface is assumed to be flat. This avoids brightness variations due to shading effects.
  \item The incident illumination is uniform across the surface. Then, the brightness at a point in the image is proportional to the reflectance of the surface at the corresponding point on the object.
  \item The Reflectance varies smoothly and has no spatial discontinuities. Having no discontinuities assures that the image brightness is differentiable.
  \item Situations where objects occlude one another are excluded.
\end{itemize}
These assumptions allow to conclude, that in their model the brightness of a particular point in the pattern is constant. \\ \\
Let the image brightness at a point $(x,y)$ in the image plane at time $t$ be denoted by $E(x,y,t)$. Since the brightness of any point is constant, the total derivative $\frac{d E}{dt}$ is zero. Using the chain rule for differentiation, they derived the expression in Equation $\ref{eq:flow_eq}$.
\begin{equation}
\begin{aligned}
0 &= \frac{d E}{dt} \\
&= \frac{\partial E}{\partial x} \frac{x}{dt} + \frac{\partial E}{\partial y} \frac{y}{dt} + \frac{\partial E}{\partial t} \\
&= E_{x} u + E_{y} v + E_{t}
\end{aligned}
\label{eq:flow_eq}
\end{equation}
where we the following substitutions were used to derive the last identity of Equation $\ref{eq:flow_eq}$:
\begin{equation}
\begin{aligned}
	u = \frac{dx}{dt} \text{ and } v = \frac{dy}{dt}
\end{aligned}
\end{equation}
By re-ordering the terms of Equation $\ref{eq:flow_eq}$ the same way like it has been done in Equation $\ref{eq:reordered_flow_eq}$:
\begin{equation}
\begin{aligned}
	(E_x, E_y) \cdot (u, v) &= -E_t \\
	\underbrace{-\frac{1}{E_t}\left( E_x, E_y \right)}_\text{known} \cdot \underbrace{(u, v)}_\text{unknown} &= 1
\end{aligned}
\label{eq:reordered_flow_eq}
\end{equation}
Hence, they could show that the change in image brightness can be formulated by a single linear equations with two unknowns $u$ and $v$, the so called $\textit{flow velocity}$. As a consequence, such a flow velocity cannot be computed locally without introducing additional constraints. \\ \\
In their formulation they express their additional constraint by stating that the square of the magnitude of the gradient of the optical flow velocity, as defined in Equation $\ref{eq:smoothness_constraints}$
\begin{equation}
	\left( \frac{\partial u}{\partial x} \right)^2 + \left( \frac{\partial u}{\partial y} \right)^2 \text{ and } \left( \frac{\partial v}{\partial x} \right)^2 + \left( \frac{\partial v}{\partial y} \right)^2,
\label{eq:smoothness_constraints}
\end{equation}
should be minimal. The remaining problem is then to minimize the sum of the energies modelling the rate of image brightness change as stated in Equation $\ref{eq:energy_brightness}$
\begin{equation}
	E_b = E_x u + E_y v + E_t
\label{eq:energy_brightness}
\end{equation}
and the measure of the departure from smoothness in the velocity flow, as formulated in Equation $\ref{eq:energy_constraint}$.
\begin{equation}
	E_c^2 = \norm{\nabla u}^2 + \norm{\nabla v}^2
\label{eq:energy_constraint}
\end{equation}
The total error to be minimized is therefore equal to the energy term formulated in Equation $\ref{eq:final_hs_energy_term}$.
\begin{equation}
	E = \int \int \left( E_b^2 + \alpha^2 E_c^2 \right) dx dy
\label{eq:final_hs_energy_term}
\end{equation}
This flow estimation formulation assumes smoothness in the flow over the whole image. Hence, minimzing this energy results in a minimization of distortions in the flow and thus prefers solutions which exhibit more smoothness. The scalar $\alpha$ acts as a regularization constant, that weights the influence of the smoothness term. Hence, larger values for $\alpha$ lead to soother flow estimations. \\ \\
This minimization can analytically be solved by formulating its multi-dimensional Euler-Lagrange equations as formulated in Equation $\ref{eq:multi_dim_euler_lagrange}$.
\begin{equation}
\begin{aligned}
 \frac{\partial L}{\partial u} - \frac{\partial}{\partial x} \frac{\partial L}{\partial u_x} - \frac{\partial}{\partial y}\frac{\partial L}{\partial u_y} &= 0 \\
\frac{\partial L}{\partial v} - \frac{\partial}{\partial x} \frac{\partial L}{\partial v_x} - \frac{\partial}{\partial y}\frac{\partial L}{\partial v_y} &= 0
\end{aligned}
\label{eq:multi_dim_euler_lagrange}
\end{equation}
where L denotes the integrand of the energy expression, given by Equation $\ref{eq:def_l_euler_lag}$:
\begin{equation}
\begin{aligned}
E_x E_b - \alpha^2 \Delta u &= 0 \\
E_y E_b - \alpha^2 \Delta v &= 0 \\
\end{aligned}
\label{eq:def_l_euler_lag}
\end{equation}
Where $\Delta$ denotes the Laplace$\footnote{Definition of the Laplace operator in the two dimensional case: $\Delta = \frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2}$}$ operator. When using a finite differences scheme for approximating the Laplacian equation
as defined in Equation $\ref{eq:finite_difference_laplacian}$
\begin{equation}
	\Delta u(x,y) = \bar{u} (x,y) - u(x,y)
\label{eq:finite_difference_laplacian}
\end{equation}
where $\bar{u} (x,y)$ denotes the weighted average of u computed by visiting the neighborhood around the pixel at location $(x,y)$, Equation $\ref{eq:def_l_euler_lag}$ can be simplified to
\begin{equation}
\begin{aligned}
(E_x^2 + \alpha^2) u + E_x E_y v &= \alpha^2 \bar{u} - E_x E_t \\
(E_x^2 + \alpha^2) v + E_x E_y u &= \alpha^2 \bar{v} - E_y E_t
\end{aligned}
\label{eq:def_l_euler_lag_simplified}
\end{equation}
The equations from above (Eq. $\ref{eq:def_l_euler_lag_simplified}$) became linear in $u$ and $v$. This allows to solve this minimization problem for each pixel in the image. However, keep in mind that the solution depends on the neighboring values of the flow field. Hence, the system must be solved iteratively. The following update rule can therefore be used:
\begin{equation}
\begin{aligned}
 u_{k+1} &= \bar{u}_k - \frac{E_x (E_x \bar{u}_k + E_y \bar{v}_k + E_t)}{\alpha^2 + E_x^2 + E_y^2} \\
  v_{k+1} &= \bar{v}_k - \frac{E_y (E_x \bar{u}_k + E_y \bar{v}_k + E_t)}{\alpha^2 + E_x^2 + E_y^2}
\end{aligned}
\label{eq:hs_iteration}
\end{equation}

\subsection{Modern Flow Methods}
\label{sec:impl_optical_flow}
In this section we briefly introduce four modern flow methods by summarizing their corresponding papers and some main points stated in $\cite{Sun2014}$. In particular, we state the main properties and drawbacks of these flow methods. Discussing those methods particularly makes sense since we use these flow estimation techniques later in our pipeline to generate flow fields (Sec. $\ref{sec:generate_of}$).

\subsubsection{Enhanced H.S. Optical Flow Fields}
\label{sec:hs_flows}
In $\cite{Deq10}$ Dequing Sun et al studied various flow methods and models and determined the most important factors that increase the quality of produced flow fields. They incorporated their findings in Horn and Schunck's original formulation and contributed a efficient implementation of their method. Additional information about their formulations can be found in Section $\ref{sec:hs_formulation}$ on page $\pageref{sec:hs_formulation}$. When using the abbreviation HS we strictly refer to their implementation. \\ \\
The original HS formulation combines a data term that assumes constancy of some image property with a spatial term that models how the flow is expected to vary across the image. The HS model relies on brightness constancy and spatial smoothness assumptions. Unfortunately it is not very robust to outliers. Therefore, the following main improvements were implemented in their methods:
\begin{itemize}
  \item The quadratic penalty function is replaced by the Charbonnier penalty $p\left( x \right) = \sqrt{x^2 + \epsilon^2}$. This penalty is supposed to be less error-prone to outliers.
  \item An incremental multi-resolution technique is applied to estimate flow fields with large displacements. The optical flow estimated at a coarse level is used to warp the second image toward the first at the next finer level and a flow increment is calculated between the first image and the warped second image. Each level is recursively downsampled by applying a Gaussian filter from its nearest lower level.
  \item An enhanced objective function is used, which includes a non-local term that robustly integrates flow estimates over large spatial neighborhoods. This is achieved by applying a median filtering to denoise the flow after every warping step to increase the accuracy.
\end{itemize}

\subsubsection{Large Displacement Optical Flows}
\label{sec:ldof_flows}
Before the work in $\cite{Bro11a}$, there was no accurate method present to estimate fast motions of small objects, i.e. large motions. Most flow methods are based on a combination of HS flow formulation and the concept of coarse-to-fine image warping. However, both approaches have been extended by robust statistics to fight outliers and at the same time retain smoothness assumptions. \\ \\
Two fundamental ideas exist to address the issue of large motions. On one hand there are coarse-to-fine techniques. Such techniques, however, require a downsampling. Unfortunately, this also removes details that may be important for the flow accuracy. Consequently, the method cannot refine the flow of structures that are smaller than their displacement, because the structure is smoothed away. Flow Fields produced this way are often close to the motion of the larger scale structures. On the other hand descriptor matching techniques are well suited to match large displacements. However, their resulting correspondences are very sparse, have a limited accuracy and exhibit many outliers due to missing regularity constraints and lastly, there is only a pixel-level accuracy guaranteed. \\ \\
In their paper they propose a method how to combine both strategies. They direct a variational technique using correspondences from sparse descriptor matching. The correspondences determined by the descriptors are directly integrated into the variational approach. This allows to make use of all image information at every level and smoothly scales down the influence of descriptor keypoints as the grid gets finer.

\subsubsection{Semi Rigid Scene Flows}
\label{sec:srsf_flows}
In their paper $\cite{Bro14}$, Quiroga et al. proposed an approach to estimate the scene flow$\footnote{The term scene flow denotes a motion field in the 3D space, which can be computed from a single view when using RGB-D sensor data.}$ by exploiting the properties of motion in real world scenes. For that purpose they implemented an over-parameterized framework that estimates scene flows from RGBD images. \\ \\
This allows for piecewise smooth solutions using a total variation (TV) regularization$\footnote{An image denoising technique, which is also known as \textit{total variation denoising}.}$ on the parameterization. Most real world scenes can be modelled as locally or piecewise rigid. This means that the scene is composed of 3D independently rigid components. Moreover, their formulation offers a general formulation to solve for the local and global motion by jointly using intensity and depth data. \\ \\
They model the scene flow as a 3D vector field consisting of a global rigid motion plus a non-rigid residual. this is particularly useful, when estimating the motion of deformable objects in conjunction with a moving camera. A piecewise smooth solution is estimated using a total variation on the parameterization.\\ \\
In the following some details according to their implementation:
\begin{itemize}
  \item They represent motions as a 3D vector field of twists, which encourages piecewise-smooth solutions of rigid body motions.
  \item Instead of representing the flow vectors in the 3D space, they represent the scene structure in the image domain. Then, color and depth data can be coupled using a projective function. this way depth influences the motion in the image domain and consistency constraints can be formulated jointly over the color and depth images.
  \item However, scene flow estimation using intensity and depth is an ill-posed problem and regularization is needed. In their work they use an over-parameterization of the scene flow. Each scene point is allowed to follow a rigid body motion. this way, the regularization can be done on a field of rigid motion.
  \item Usually, the 3D motion vector of each point is solved to minimize color and intensity constraints in a data term and the whole 3D motion field is regularized to get spatially smooth solutions while preserving discontinuities. Since depth data is available a weighted regularization can be used to preserve motion discontinuities along depth edges.
  \item In order to formulate an efficient 3D motion exploration they use a parameterization provided by RGB-D sensors to formulate an efficient 3D motion exploration. Hence, they define a warping function to couple the twist motion and the optical flow. They use a warping function to locally constrain the rigid motion field in the image domain and define a depth consistency constraint to exploit the sensor data.
\end{itemize}

\subsubsection{Layered RGB-D Flow Fields}
\label{sec:lrgbd_flows}
In $\cite{Deq10}$ Dequing Sun et al present a layered RGBD scene flow estimation  method. They make use of the fact that depth information allows to recover 3D motion from a single view. However, in that case, depth boundaries are not well aligned with RGB images. Especially in occluded regions methods produce large errors. As a remedy, they therefore, use the depth fields for occlusion reasoning and formulate a layered RGBD scene flow method that jointly solves for the scene segmentation and the motion. In their formulation, the depth fields are used to estimate the per-layer 3D rigid motion to constraint the motion of each layer. \\ \\
The implementation of their method is freely available on the authors website, written in Matlab. In the following we use the abbreviation LRGBD for flow fields produced by their implementation.

\section{On Data Clustering}
\label{sec:on_data_clustering}
Clustering is a technique for exploratory data analysis and allows to identify groups of similar behaviour. This is achieved by separating data points according to their similarities. \\ \\
Generally, clustering is a hard problem and yet no perfect method exists. As we show in our evaluation section, the choice of the segmentation method has a big influence on the quality of our motion segmentation pipeline. \\ \\
In this section we offer the reader definitions of various such techniques. For writing the content of this section we partially relied on the work of $\cite{vonLuxburg2007}$. \\ \\
In the following we start by describing the k-means clustering which is a clustering method applied on point clouds and which is popular because of its speed, relative simplicity and robustness. However, a drawback of k-means is that it only works for relatively low-dimensional datasets. \\ \\
In this thesis, we are mainly working with datasets consisting of point trajectories. This kind of data is not easily embeddable in an Euclidean space. Therefore, we present a more general clustering framework targeting at segmenting graphs. Regardless of the dimensionality of the input data, these method are general enough to work with any kind of data as long as it is possible to compute a distance between data point pairs

\subsection{K-Means Clustering}
\label{sec:k_means}
The idea of the k-means clustering algorithm is to partition $n$ observations into $k$ clusters in which each observation belongs to the cluster with the nearest mean. \\ \\
Given a set of observations $(\textbf{x}_1, \dots, \textbf{x}_n)$, where any $\textbf{x}_k \in \mathbb{R}^d$. k-means clustering tries to partition the $n$ observations into $k$ sets $\textbf{S} = \{ S_1, \dots, S_k\}$ to minimize the sum of distance functions of each point in the cluster to the $k$ centers. Mathematically, this can formulated as follows:
\begin{equation}
	\argmin_{\textbf{S}} \sum_{i=1}^k \sum_{\textbf{x} \in S_i} \norm{\textbf{x} - {\boldsymbol {\mu }}_{i}}^2
\label{eq:k_means_minimzation_formulation}
\end{equation}
where ${\boldsymbol {\mu }}_{i}$ is the mean of points in $S_i$, the so called centroid. An example of the k-means algorithm is given in Figure $\ref{fig:k_means_example}$.
\begin{figure}[H]
\begin{center}
\includegraphics[width=0.8\linewidth] {background/clustering/k_means_steps}
\end{center}
\caption[K-Means Example]{An example$\footnotemark$ of the k-means algorithm. Training examples are shown as dots, and cluster centroids are shown as crosses. (a) Original dataset. (b) Random initial cluster centroids. (c-f) Illustration of running two iterations of k-means. In each iteration, we assign each training example to the closest cluster centroid (shown by "painting" the training examples the same color as the cluster centroid to which is assigned); then we move each cluster centroid to the mean of the points assigned to it. Images courtesy of Michael Jordan.}
\label{fig:k_means_example}
\end{figure}
\footnotetext{The caption and the images in Figure $\ref{fig:k_means_example}$ were taken from: \\ \url{http://stanford.edu/~cpiech/cs221/handouts/kmeans.html}}
The k-means clustering equations (Eq. $\ref{eq:k_means_minimzation_formulation}$) can be iteratively minimized, but without the guarantee of finding a global minimum. Given an initial set of $k$ means $m_1^{(1)}, \dots, m_k^{(1)}$, the algorithm proceeds by alternating between two steps:
\begin{itemize}
\item \textbf{Assignment step}: Assign each observation to the cluster whose mean yields the least sum of distance functions of each point in the cluster. Since the sum of squares is the squared Euclidean distance, this is intuitively the \enquote{nearest} mean.
\begin{equation}
  	S_i^{(t)} = \left\{ x_p \mid \forall j: 1 \leq j \leq k: \norm{x_p - m_i^{(t)}}^2 \leq \norm{x_p - m_j^{(t)}}^2 \right\}
\label{eq:k_means_step_1}
\end{equation}
where each $x_p$ is assigned to exactly one $S^{(t)}$.
\item \textbf{Update step}: Calculate the new means to be the centroids of the observations in the new clusters.
\begin{equation}
	m_i^{(t+1)} = \frac{1}{\left| S_i^{(t)} \right| } \sum_{x_j \in S_i^{(t)}} x_j
\label{eq:k_means_step_2}
\end{equation}
\end{itemize}
These two steps (Eq. $\ref{eq:k_means_step_1}$ and Eq. $\ref{eq:k_means_step_2}$) are repeated until the assignments $\{S_1, \dots, S_m \}$ no longer change. \\ \\
The k-means algorithm is guaranteed to converge to a local minimum because there are a finite number of possible data partitionings, and its objective function$\footnote{The objective function of the k-means algorithm is to assign each observation to the cluster whose mean yields the least within-cluster sum of squares.}$ must decrease in every step. A corresponding proof of this convergence statement can be found in the paper $\cite{Bottou95convergenceproperties}$. However, there is no guarantee that the global optimum is found using this algorithm.\\ \\
Commonly, clusters are either initialized by using the \textit{Random}$\cite{1697556}$ or the \textit{Forgy}$\cite{Hamerly:2002:AKA:584792.584890}$ method. The Random method assigns each object a random cluster and then computes the initial centroid of each cluster. The Forgy method chooses k observations randomly from the data set and uses these as the initial means. The appropriate way of initializing the clusters depends on the given problem statement, which the k-means attempts to address. In general, the Random method places the clusters close to the center of the data points, whereas the Forgy method tends to spread the initial means out. However, different local minima are found depending on the chosen initialization of the cluster centers. One way to address this problem is to simply run this algorithm several times, using different initialization. Then, the minima with the lowest error is considered as the optimum.
\subsection{Graph Definitions}
In the following we offer the reader some basic graph definitions which are broadly used in this thesis. \\ \\
Let $G = (V, E)$ denote an undirected graph, where $V$ is the set of vertices and $E$ the set of edges. In this work we work with weighted graphs. This means that each edge between two vertices $v_i$ and $v_j$ has a non-negative weight $w_{ij}$. \\ \\
The $\textbf{weighted adjacency matrix}$ of the graph is the matrix
\begin{equation}
W = \left( w_{ij} \right)_{i,j=1,\dots, n}
\label{eq:def_adjacency_matrix}
\end{equation}
If $w_{ij} = 0$ then the vertices $v_i$ and $v_j$ are \textbf{not connected} by an edges. \\ \\
Since $G$ is assumed to be an \textbf{undirected graph}, we require
\begin{equation}
	\forall i,j : w_{ij} = w_{ji}
\end{equation}
The \textbf{degree} of a vertex $v_i \in V$ is defined as
\begin{equation}
	d_i = \sum_{j=1}^n w_{ij}
\label{eq:vertex_degree}
\end{equation}
In fact the sum accumulates only weights of edges adjacent to $v_i$, since all other vertices have a weight equals zero. \\ \\
The \textbf{degree matrix} $D$ is defined as the diagonal matrix with the degrees $d_1,\dots, d_n$ on the diagonal. \\ \\
For a given subset of vertices $A \subset V$, its \textbf{complement} is defined as
\begin{equation}
	\bar{A} = V \setminus A
\label{eq:set_complement}
\end{equation}
The \textbf{indicator function} is defined as
\begin{equation}
\begin{aligned}
& \mathbbm{1}_A = \left( f_1, \dots, f_n \right)^{T} \in \mathbb{R}^n \\
& \text{where } \forall i: f_i=
\begin{cases}
    1,& \text{if } v_i\in A\\
    0,              & \text{otherwise}
\end{cases}
\end{aligned}
\end{equation}
For the set of indices $\{ i : v_i \in A \}$ we use the shorthand notation $i \in A$. For two subsets $A, B \subset V$, which are not necessarily disjoint, we define their \textbf{set sum} as
\begin{equation}
	W(A,B) = \sum_{i \in A, j \in B} w_{ij}
\label{eq:set_sum}
\end{equation}
For measuring the size of a subset $A \subset V$, we either can \textbf{count} the number of vertices in $A$, which is denoted by $\left| A \right|$ or measure the \textbf{volume} of $A$ defined as
\begin{equation}
	\text{vol}(A) = \sum_{i \in A} d_i
\label{eq:set_volume}
\end{equation}
The volume is the sum of weights of all edges attached to vertices in $A$.

\subsection{Similarity Graph}
\label{sec:similarity_graphs}
Given a set of data points $x_1, \dots, x_n$ and some notion of similarity $s_{ij} \geq 0$ between all pairs of data points $x_i$ and $x_j$. Then, our goal is to divide the data points into several groups such that points in the same group are similar and points in different groups are dissimilar to each other. To address this task we represent our data by a similarity graph $G = (V, E)$. \\ \\
Each vertex $v_i$ in this graph represents a data point $x_i$. Two vertices are connected if the similarity $s_{ij}$ between the corresponding data point $x_i$ and $x_j$ is positive or larger than a certain threshold and the edge is weighted by $s_{ij}$. The data clustering reduces to the graph partitioning problem. The goal is then to find a partition of the graph such that the edges between different groups have very low weights$\footnote{This means that points in different clusters are dissimilar from each other.}$ and edges within a group have high weights$\footnote{which means that points within the same cluster are similar to each other}$. \\ \\
There are several constructions to transform a given set of data points with pairwise similarities $s_{ij}$ or pairwise distances $d_{ij}$ on the graph. The common goal of such a construction is to model the local neighborhood relationships between the data points. In the following several a list of different construction types.
\begin{itemize}
	\item The \textbf{$\epsilon$-neighborhood graph}: All points whose pairwise distances are smaller than a given $\epsilon$ are connected. In that case the distances between connected vertices is at the same scale (at most equals $\epsilon$). Hence, the edge weights do not incorporate additional information about the data on the graph and thus, such a graph is usually considered as an unweighted graph.
	\item The \textbf{k-nearest neighbor graph}: Vertex $v_i$ is connected with $v_j$ if $v_j$ is among the k-nearest neighbors of $v_i$. This definition usually leads to a directed graph, since this neighborhood relationship is not symmetric. When interested in constructing a undirected graph, we can either ignore the induced edge directions (corresponds to an OR relationship) or connect the vertices if and only if both are nearest neighbors of each other (corresponds to an AND relationship).
	\item The \textbf{fully connected graph}: All points that exhibit a positive similarity are connected with each other. The edge weight corresponds to their similarity value.
\end{itemize}
For measuring the distances between data points any kind of metric$\footnote{For example one could use the Euclidean distance or other kind of norms}$ can be used.

\subsection{Graph Laplacians}
In spectral clustering we are working with the so called graph Laplacian matrices, which can be defined based on the previously discussed adjacency matrix formulation. In this section, we therefore define different graph Laplacians and state some of their properties. \\ \\
In the following we assume that $G$ is an undirected, weighted graph with the positive weight matrix $W$ and $D$ denotes the degree matrix. \\ \\
When discussing some properties of the eigenvectors of the Laplacian matrix, keep in mind that they do not necessarily have to be normalized. By conventions, we assume the eigenvectors being ordered increasingly. Additionally, when referring to the first $k$ eigenvectors, we mean the eigenvectors that correspond to the $k$ smallest eigenvectors.

\paragraph{Unnormalized Graph Laplacian}
The unnormalized graph Laplacian matrix $L$ of the graph $G$ is defined as
\begin{equation}
	L = D - W
\label{eq:unnormalized_graph_laplacian}
\end{equation}
It has the following properties:
\begin{itemize}
\item \begin{equation}
	\forall v \in \mathbb{R}^n: v^T L v = \frac{1}{2	} \sum_{i,j=1}^n w_{ij} (v_i - v_j)^2
\end{equation}
\item L is symmetric and positive semi-defnite$\footnote{A $n \times n$ matrix $M$ is called positive semi-definite if and only if $\forall x \in \mathbb{R}^n : x^T M x \geq 0$ holds true.}$.
\item The smallest eigenvalue of L is equal to zero and the corresponding eigenvector is the constant one vector.
\end{itemize}
The unnormalized graph Laplacian does not depend on the diagonal elements of the matrix W. Each adjacency matrix which coincides with W on all off diagonal positions lead to the same Laplacian L. Moreover, the multiplicity of the eigenvalue zero of $L$ is equal the number of connected components in the graph. A proof of this property can be found in $\cite{Lux07}$.

\paragraph{Normalied Graph Laplacian}
The symmetric, normalized graph Laplacian matrix $L^{\text{sym}}$ of the graph $G$ is defined as
\begin{equation}
	L^{\text{sym}} = D^{-\frac{1}{2}} L D^{-\frac{1}{2}}
\label{eq:normalized_graph_laplacian}
\end{equation}
which has the following properties:
\begin{itemize}
\item \begin{equation}
	\forall v \in \mathbb{R}^n: v^T L^{\text{sym}} v = \frac{1}{2	} \sum_{i,j=1}^n w_{ij} \left( \frac{v_i}{\sqrt{d_i}} - \frac{v_j}{\sqrt{d_j}} \right)^2
\end{equation}
\item Zero is an eigenvalue of $L^{\text{sym}}$ with the eigenvector $D^{\frac{1}{2}} \mathbbm{1}$
\item $L^{\text{sym}}$ is positive semi-definite and has $n$ non-negative real-valued eigenvectors.
\end{itemize}
Please notice that the definition of Equation $\ref{eq:normalized_graph_laplacian}$ relies on the definition of the unnormalized graph Laplacian, stated in Equation $\ref{eq:unnormalized_graph_laplacian}$. Moreover, the multiplicity of the eigenvalue zero of L is equal the number of connected components $A_1, \dots, A_k$ in the graph G. The Eigenspace of $L^{\text{sym}}$ is spanned by the vectors $D^{\frac{1}{2}} \mathbbm{1}_{A_i}$

\subsection{Spectral Clustering}
\label{sec:spectral_clustering_bg}
In this section we describe a clustering technique for grouping data points by using the spectrum of the points' similarity matrix. More precisely, this method performs a dimensionality reduction and then separates the transformed data representation via k-means. \\ \\
Given $n$ data points $x_1, \dots, x_n$ with their pairwise similarities $s_{ij}$ measured by some similarity function which is symmetric and non-negaitve. Then, the corresponding similarity matrix $S$ is defined as $S = (s_{ij})_{i,j=1,\dots,n}$. \\ \\
The rationale of the spectral clustering algorithm is to change the abstract representation of the data points $x_i$ to points $y_i \in \mathbb{R}^k$, which are easy to cluster using k-means. Algorithm $\ref{alg:spectral_clustering_algorithm}$ lists the actual step that have to performed to run the spectral clustering algorithm.
\begin{algorithm}[H]
\caption{Spectral Clustering Algorithm}
\begin{table}[H]
  \begin{tabular}{@{}lll@{}}
    \textbf{Input:} & Similarity matrix $S \in \mathbb{R}^{n \times n}$ \\
		& Number $k$ of clusters to construct \\
    \textbf{Output:} & Clusters $A_1, \dots, A_k$ with $A_i = \{ j : y_j \in C_i\}$ \\
  \end{tabular}
\end{table}
\setlength{\fboxrule}{0pt}
\begin{boxedminipage}{1.0\textwidth}
  \begin{algorithmic}[1]
  	  \State $\text{Construct a similarity graph as described in Section }\ref{sec:similarity_graphs}$
  	  \State $\text{Let } W \text{ denote the corresponding weighted adjacency matrix}.$
  	  \State $\text{Compute the normalized graph Laplacian } L^{\text{sym}} \text{ as defined in Equation } \ref{eq:normalized_graph_laplacian}$
  	  \State $\text{Compute the first k eigenvectors } u_1,\dots,u_k \text{ of } L^{\text{sym}}$
  	  \State $\text{Let } U \in \mathbb{R}^{n \times k} \text{ be the matrix containing the vectors } u_1,\dots,u_k \text{ as columns}$
  	  \State $\text{Form a matrix } T \in \mathbb{R}^{n \times k} \text{ from U by normalizing the rows}$
  	  \State $\forall i \in \left[ 1, n \right]: \text{ Let } y_i \in \mathbb{R}^k \text{ be the vector corresponding to the t-th row of T.}$
  	  \State $\text{Cluster the points } (y_i)_{i=1,\dots,n} \text{ via k-means as described in Section } \ref{sec:k_means} \text{ into clusters } C_1, \dots, C_k$
  \end{algorithmic}
  \end{boxedminipage}
  \vskip1.5pt
\label{alg:spectral_clustering_algorithm}
\end{algorithm}
The actual choice of similarity graph we want to construct depends on the underlying problem statement. A simple spectral clustering example is shown in Figure $\ref{fig:spectral_clustering_example}$.
\begin{figure}[H]
\begin{center}
\includegraphics[width=0.8\linewidth] {background/clustering/spectral_clustering_example}
\end{center}
\caption[Spectral Clustering Example]{A simple spectral clustering example: We want to partition a similarity graph (as shown on the left), which consists of two disconnected subgraphs, into two clusters by running the spectral clustering algorithm (Algorithm $\ref{alg:spectral_clustering_algorithm}$). The corresponding Laplacian matrix L that graph is a block diagonal matrix with each block defining a cluster (as shown in the center). The two smallest$\footnotemark$ eigenvectors $u_1$ and $u_2$ directly represent the connected components of the two subgraphs (as shown on the right). The resulting clusters $A_1$ and $A_2$ are shown on the left.}
\label{fig:spectral_clustering_example}
\end{figure}
\footnotetext{By \textit{smallest eigenvectors} we are referring to those eigenvectors that belong to the smallest eigenvalues $\lambda$.}

\subsection{Graph Cut}
\label{sec:graph_cut}
In this section we relate the problem of clustering to graph partitioning problems. \\ \\
For a similarity graph, the problem of clustering can be reformulated to the task of finding a partition on the graph such that edges between different groups have low weights and edges within the same group have high weights. \\ \\
Let $G = (V, E)$ denote a similarity graph and $W$ its corresponding adjacency matrix. Then, one way to obtain a partition of $G$ is to solve the mincut problem. For a given number $k$ of subsets, the mincut tries to find an optimal partition $A_1, \dots, A_k$ of $G$ which minimizes
\begin{equation}
\text{cut} \left( A_1, \dots, A_k \right) := \frac{1}{2} \sum_{i=1}^k W \left( A_i, \bar{A_i} \right)
\label{eq:simple_mincut}
\end{equation}
where $\bar{A}$ denotes the complement of $A$ as defined in Equation $\ref{eq:set_complement}$ and $W(A,B)$ is the set sum of the subsets $A$, $B$ as defined in Equation $\ref{eq:set_sum}$. \\ \\
The minimum cut problem from Equation $\ref{eq:simple_mincut}$ can be efficiently solved according to the method described in $\cite{Stoer:1997:SMA:263867.263872}$. The idea is to reduce the graph by merging the vertices of an edge determined similar as in iteration of Prim's minimum spanning tree algorithm, until the graph only contains two combined vertex sets. After each shrinking, the weight of the merged cut would be stored in a list. Finally, the minimum weight cut in the list will be the minimum of the graph. \\ \\
In practice, the resulting graph partitions are not satisfactory. In many situations, the solution of such a mincut simply separates one individual vertex from the rest of the graph. However, we expect clusters to from reasonable large groups and hence, partitions into individual vertices are not what we want. The remedy of this issue is to introduce an additional constraint, that models the notion of cluster size. We explicitly request that the resulting partitions should be large enough.
The two common objective functions to encode the notion of size is the ratio cut \textit{Rcut} $\cite{Hagen:2006:NSM:2298571.2301769}$ and the normalized cut \textit{Ncut} $\cite{Shi:2000:NCI:351581.351611}$. They are defined as
\begin{equation}
\begin{aligned}
&\text{Rcut} = \frac{1}{2} \sum_{i=1}^k \frac{W(A_i, \bar{A_i})}{\left| A_i\right|} = \sum_{i=1}^k \frac{\text{cut}(A_i, \bar{A_i})}{\left| A_i\right|} \\
&\text{Ncut} = \frac{1}{2} \sum_{i=1}^k \frac{W(A_i, \bar{A_i})}{\text{vol}(A_i)} = \sum_{i=1}^k \frac{\text{cut}(A_i, \bar{A_i})}{\text{vol}(A_i)}
\end{aligned}
\end{equation}
Both objective functions try to achieve that the clusters are balanced in terms of either the number of vertices (Rcut) or edges (Ncut). The downside of this is that introducing balancing conditions make the previous simple mincut become NP hard, as discussed in $\cite{Jeg09}$. Spectral clustering is a way to solve a relaxed version of those balanced mincut problems. In particular, in the paper $\cite{vonLuxburg2007}$ the authors demonstrated that relaxing Ncut leads to the spectral clustering algorithm we mention in Section $\ref{sec:spectral_clustering_bg}$. \\ \\
In literature, many sophisticated methods exist to optimize relaxed versions of this NP hard problem. Examples are the graph partition heuristic in $\cite{Ker70}$, or by solving the multi-label CRF problem via max-flow as presented in $\cite{Fulkerson2009}$.


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

\marginpar{Monday\\ 2020-3-30, \\ compiled \\ \today}

% Last time we discussed: how can we distinguish what is a GW and what is not?

% We do this by separating them by frequency.
% We cannot really measure the nature of tensor perturbation of GWs, since we are only measuring integrated effects.

% We can precisely map the effect of the GW in time, by sampling with a frequency which is much higher than the one of the GW.

So, let us do this formally: we consider \(g = \overline{g} + h\) where \(\overline{g}\) only contains low frequency components while \(h\) contains high frequency ones, we expand the Ricci tensor in powers of \(h_{\mu \nu }\) up to second order and rewrite the Einstein equations as
%
\begin{align}
\frac{8 \pi G}{c^{4}} \qty(T_{\mu \nu } - \frac{1}{2} g_{\mu \nu }T)
= \overline{R}_{\mu \nu }
+ R^{(1)}_{\mu \nu }
+ R^{(2)}_{\mu \nu }
\,,
\end{align}
%
where the second order in \(h_{\mu \nu }\) term, \(R^{(2)}_{\mu \nu }\), has both high and low frequency components, while the term \(\overline{R}_{\mu \nu }\) is exclusively low frequency and \(R_{\mu \nu }^{(1)}\) is exclusively high frequency.

Let us give a heuristic argument for this statement: the gravitational waves contained in \(h_{\mu \nu } \) will have several high frequencies; let us call two of them \(\omega_1  \) and \(\omega_2 \), so as we compute a term which is quadratic in \(h\) we will get
%
\begin{align}
\qty(\sin(\omega_{1} t) + \sin(\omega_2 t))^2
= \\ =
\frac{1}{2} \left(-\cos \left(2 t \omega _1\right)-\cos \left(2 t \omega _2\right)-2 \cos \left(t \omega _1+t \omega _2\right)+2 \cos \left(t \omega _1-t \omega _2\right)+2\right)
\,,
\end{align}
%
where we used the prostapheresis formulas: we get terms oscillating with \(\omega_1 + \omega_2 \) as well as \(\omega_1 - \omega_2 \), one of which is high frequency while the other is low frequency, since we are considering a high-frequency wavepacket.

So, what we want to do is to separate the field equation into its low and high frequency parts:
%
\begin{align} \label{eq:low-frequency-ricci-tensor-contribution}
\overline{R}_{\mu \nu } &= - \qty(R_{\mu \nu }^{(2)})^{\text{low}} + \frac{8 \pi G}{c^{4}} \qty(T_{\mu \nu } - \frac{1}{2} g_{\mu \nu } T)^{\text{low}} \\
R_{\mu \nu }^{(1)} &= - \qty(R_{\mu \nu }^{(2)})^{\text{high}} + \frac{8 \pi G}{c^{4}} \qty(T_{\mu \nu } - \frac{1}{2} g_{\mu \nu } T)^{\text{high}}
\,.
\end{align}

How might we define these formally?
Recall, we expand in two parameters: \(h\) and \(\lambda / L_B \sim  f_B / f\). Then, in terms of orders of magnitude we have\footnote{The fact that the derivatives correspond to divisions by lengths is justified since we are looking at harmonic expansions, the metric will be a sum of sinusoids around a characteristic frequency.}
%
\begin{align}
\overline{R}_{\mu \nu } \sim \partial^2 \overline{g}_{\mu \nu } \sim \frac{1}{L_B^2}
\,,
\end{align}
%
while
%
\begin{align}
\qty[R^{(2)}_{\mu \nu }]^{\text{low}} \sim \qty(\partial h)^2
 \sim \qty(\frac{h}{\lambda })^2
\,.
\end{align}

See Maggiore \cite[pag.\ 31]{maggioreGravitationalWavesVolume2007} for more details.
So, inserting these order-of-magnitude estimates inside equation \eqref{eq:low-frequency-ricci-tensor-contribution} we get
%
\begin{align}
\frac{1}{L_B^2} \sim \frac{h^2}{\lambda^2} + \qty(T_{\mu \nu } \text{ contribution})
\,.
\end{align}

If we are in a vacuum (\(T_{\mu \nu }=0\)) then
%
\begin{align}
\frac{1}{L_B^2} \sim \qty(\frac{h}{\lambda })^2
\implies h \sim \frac{\lambda }{L_B}
\,,
\end{align}
%
while if the stress-energy tensor is nonvanishing we get
%
\begin{align}
\frac{1}{L_B^2} \sim \qty(\frac{h}{\lambda })^2 + (T_{\mu \nu } \text{ contribution}) \gg \qty(\frac{h}{\lambda })^2
\,,
\end{align}
%
which means \(h \ll \lambda / L_B\). This shows that \textbf{the linearized expansion cannot be extended beyond linear order} starting from a flat background: if we start from a flat metric then \(1/L_B = 0\), so any \(h > 0\) violates the condition \(h \lesssim \lambda / L_B\).
We can also see that the notion of a gravitational wave only makes sense as long as \(h\) is small: if \(h\) were close to 1, then we would have \(\lambda \sim L_B\), but our only way to distinguish GW from background is through their wavelength!

\todo[inline]{Unclear what the problem is: we cannot use the flat metric, but the real world's metric is not flat anyways! Why can we not go to second order with a curved background?}

The solution to this problem is to take averages on a scale \(\ell\) such that \(\lambda_{GW} \ll \ell \ll L_B\), so that the gravitational wave is fully averaged out, while the background metric is approximately constant across the integration volume.
This low-frequency projection reads:
%
\begin{align}
\overline{R}_{\mu \nu } =
- \expval{R^{(2)}_{\mu \nu }} + \frac{8 \pi G}{c^{4}} \expval{T_{\mu \nu } - \frac{1}{2} g_{\mu \nu } T}
\,.
\end{align}

After some math (see Maggiore \cite[eqs.\ 1.122-1.123]{maggioreGravitationalWavesVolume2007}) we can define a stress tensor of the GW, which looks like
%
\begin{align}
t_{\mu \nu } = - \frac{c^{4}}{8 \pi G} \expval{R^{(2)}_{\mu \nu } - \frac{1}{2} \overline{g}_{\mu \nu } R^{(2)}}
\,,
\end{align}
%
where the Ricci scalar is computed using the smoothed metric: \(R^{(2)} = \overline{g}^{\mu \nu } R_{\mu \nu }^{(2)}\).
Also, we define a  ``smoothed out'' stress-energy tensor of matter:
%
\begin{align}
\expval{T_{\mu \nu } - \frac{1}{2} g_{\mu \nu } T}
\overset{\text{def}}{=}
\overline{T}_{\mu \nu } - \frac{1}{2} \overline{g}_{\mu \nu } \overline{T}
\,,
\end{align}
%
so the equation which will hold is the equivalence of the smoothed Einstein tensor with the sum of the smoothed and GW stress-energy tensors:
%
\boxalign{
\begin{align}
\overline{R}_{\mu \nu } - \frac{1}{2} \overline{g}_{\mu \nu } \overline{R} =
\frac{8 \pi G}{c^{4}} \qty(\overline{T}_{\mu \nu } + t_{\mu \nu })
\,.
\end{align}}

Do note that if we work with these, the stress-energy tensor which is conserved is \(\overline{T}_{\mu \nu } + t_{\mu \nu }\): if we take the divergence of the equation we get, by the Bianchi identities,
%
\begin{align}
\nabla^{\mu } \qty(\overline{R}_{\mu \nu } - \frac{1}{2} \overline{g}_{\mu \nu }\overline{R}) = 0 = \nabla^{\mu } \qty(\overline{T}_{\mu \nu } + t_{\mu \nu })
\,.
\end{align}

This means that gravitational waves and matter can exchange energy and momentum. If the stress-energy tensor is slowly-varying enough, as often happens practically, we can just use \(\overline{T}^{\mu \nu } \approx T^{\mu \nu }\).

How does this look like far from the source?
There, we can approximate \(\overline{g} \approx \eta_{\mu \nu }\) and \(\nabla_{\mu } \approx \partial_{\mu }\).
This \(t_{\mu \nu }\) only has 2 physical degrees of freedom (those of the gravitational wave): we need to gauge the others away.

The Lorentz gauge plus \(h=0\) eliminates \(5\) degrees of freedom.

When we have terms like \(h \partial \partial h\), we can integrate by parts on a sufficiently large volume to turn them into \(\partial(h \partial ) - \partial h \partial h\).
Using the facts \(\partial^{\mu }h_{\mu \nu } = h = \square h_{\mu \nu } = 0\) we can also simplify several terms: in the end we get
%
\boxalign{
\begin{align}
t_{\mu \nu } = \frac{c^{4}}{32 \pi G} \expval{\partial_{\mu } h_{\alpha \beta } \partial_{\nu } h^{\alpha \beta }}
\,.
\end{align}}

This is invariant under the residual gauge transformations, and coordinate independent: we can compute it in any frame we like.

\subsubsection{Explicit TT-gauge expression}

Let us compute this in the simplest case: a gravitational wave travelling along the \(z\) axis, described in the TT-gauge.
The 00 component will read:
%
\begin{align}
t^{00 } = \frac{c^{4}}{32 \pi G} \expval{\partial^{0} h_{\alpha \beta } \partial^{0} h^{\alpha \beta }} = \frac{c^2}{16 \pi G} \expval{\dot{h}^2_{+} + \dot{h}^2_{ \times }}
\,,
\end{align}
%
since:
%
\begin{align}
\partial^{0} h_{\alpha \beta } \partial^{0} h^{\alpha \beta } =
\frac{\dot{h}^{TT}_{ij}}{c} \frac{\dot{h}^{TT}_{ij}}{c}
= \frac{1}{c^2}\sum _{i, j =1}^{2} \qty(\dot{h}_{ij}^{TT})^2
= \frac{2}{c^2} \qty(\dot{h}_{+}^2 + \dot{h}_{ \times }^2)
\,.
\end{align}

As for the other components, we will have \(t^{01} = t^{02} =0 \) by symmetry (they would represent momentum transfer in a direction orthogonal to the propagation, also formally \(\partial_{1,2} h_{ij}^{TT} = 0\) since it only depends on \(t\) and \(z\)), and also \(t^{03}= t^{00}\), since the perturbation is a function of \((t - z/c)\): so, we have
%
\begin{align}
\partial_{3} h_{ij}^{TT} = - \partial_{0} h_{ij}^{TT} = + \partial^{0} h_{ij}^{TT}
\,.
\end{align}

\subsection{Energy and momentum flux far from the source}

If we are far enough away from the source, we can compute the energy crossing a surface \(\dd{A}\) in a time \(\dd{t}\) as the spacetime density contained in a volume \(\dd{A} c \dd{t}\): if we are considering a specific direction (say, the flux coming the way of the Earth) then we can say that the wave's propagation is aligned with the \(z\) axis and so we can write
%
\begin{align}
\dd{E} &= \dd{A} c \dd{t} \frac{c^2}{32 \pi G} \expval{\dot{h}^{TT}_{ij}\dot{h}^{TT}_{ij}} \\
\frac{ \dd{E}}{ \dd{t} \dd{A}} &= \frac{c^3}{16 \pi G} \expval{\dot{h}^2_{+} + \dot{h}^2_{ \times }}
\,.
\end{align}

In order to get the total power \(\dv*{E}{t}\) which is emitted by the source we can integrate this expression in \(R^2 \dd{\Omega }\); however we will need to use the general expression \(\expval{\dot{h}^{TT}_{ij}\dot{h}^{TT}_{ij}}\) since we cannot have alignment with the \(z\) axis across the whole sphere.

To get the momentum density the reasoning is similar: we start from \(\dd{P^{k}} = \dd{A} c \dd{t} t^{0k}/c\) to get
%
\begin{align}
\frac{ \dd{P^{k}}}{ \dd{A} \dd{t}} = \frac{c^{4}}{32 \pi G} \expval{ \partial^{0} h_{\alpha \beta } \partial^{ k} h^{\alpha \beta }}
= - \frac{c^3}{32 \pi G} \expval{\dot{h}^{TT}_{ij} \partial^{k} h_{ij}^{TT}}
\,,
\end{align}
%
where we used the fact that \(\partial^{0} = -\partial_0  =-  \pdv*{}{(ct)}\).

So, the general expressions for the energy and momentum density emitted at a distance will be
%
\begin{align}
\dv{E}{t} = \frac{c^3}{32 \pi G} r^2 \int
\expval{\dot{h}^{TT}_{ij}\dot{h}^{TT}_{ij}} \dd{\Omega }
\qquad \text{and} \qquad
\dv{P^{k}}{t} = - \frac{c^3}{32 \pi G} r^2
\int \expval{\dot{h}^{TT}_{ij} \partial^{k} h_{ij}^{TT}} \dd{\Omega }
\,.
\end{align}

We want to express this explicitly in terms of the quadrupole moment. We start from the expression of the TT-gauge amplitude in terms of the quadrupole \eqref{eq:traceless-transverse-amplitude-from-quadrupole}: its derivative reads
%
\begin{align}
\dot{h}_{ij}^{TT} (t, \vec{x}) = \frac{1}{r} \frac{2G}{c^{4}} \Lambda_{ij, kl} \dot{\ddot{Q}}^{kl} (t - r/c)
\,.
\end{align}

Inserting this into the expression we get
%
\begin{subequations}
\begin{align}
\dv{E}{t} &= \frac{r^2c^{3}}{32 \pi G} \int \dd{\Omega }
\expval{
\frac{1}{r} \frac{2G}{c^{4}} \Lambda_{ij,kl} \dot{\ddot{Q}}^{kl}
\frac{1}{r} \frac{2G}{c^{4}} \Lambda_{ij,mn} \dot{\ddot{Q}}^{mn}
}  \\
&=\frac{G}{8 \pi c^{5}} \int \dd{\Omega }
\Lambda_{ij, kl} \expval{\dot{\ddot{Q}}^{ij} \dot{\ddot{Q}}^{kl}}
\marginnote{\(\Lambda \) is idempotent and symmetric under swaps of index pairs: so \(\Lambda_{ij, kl} \Lambda_{ij, mn} = \Lambda_{kl, mn}\).}
\,,
\end{align}
\end{subequations}
%
where the only expression depending on the angle is \(\Lambda_{ij, kl} \), since the quadrupole only depends on the source, not on an observer's position.

\begin{claim}
The explicit expression for the projection tensor \(\Lambda_{ij,kl}(\hat{n})\) in terms of the unit vector \(\hat{n}\) is:
%
\begin{align}
\Lambda_{ij, kl} (\hat{n}) = \delta_{ik} \delta_{jl} - \frac{1}{2} \delta_{ij} \delta_{kl} - n_j n_l \delta_{ik} - n_i n_k \delta_{jl}
+ \frac{1}{2} n_k n_l \delta_{ij}
+ \frac{1}{2} n_i n_j \delta_{kl}
+ \frac{1}{2} n_i n_j n_k n_l
\,,
\end{align}
%
and its integral in \(\dd{\Omega }\) is given by
%
\begin{align}
\int \dd{\Omega } \Lambda_{ij, kl} = \frac{4 \pi }{30}
\qty(11 \delta_{ik} \delta_{jl} - 4 \delta_{ij} \delta_{kl} + \delta_{il} \delta_{jk} )
\,.
\end{align}
\end{claim}

With this result, we can write
%
\begin{align}
\dv{E}{t} &= \frac{G}{8 \pi c^{5}} \frac{2\pi}{15} \qty(11 \delta_{ik} \delta_{jl} - 4 \delta_{ij} \delta_{kl} + \delta_{il} \delta_{jk} )
\expval{\dot{\ddot{Q}}^{ij} \dot{\ddot{Q}}^{kl}}
\,,
\end{align}
%
but since the quadrupole moment derivatives \(\dot{\ddot{Q}}^{ij}\) are both traceless and symmetric the first and third delta combinations are equal (so the factor multiplying them will be 12), while the second combination will vanish. So, we will get
%
\boxalign{
\begin{align}
\label{eq:radiated-power-GW}
\dv{E}{t} = \frac{G}{8 \pi c^{5}} \frac{2 \pi }{15} 12
\expval{\dot{\ddot{Q}}^{ij} \dot{\ddot{Q}}^{ij}}
= \frac{G }{5 c^{5}}
\expval{\dot{\ddot{Q}}^{ij} \dot{\ddot{Q}}^{ij}}
= \frac{G}{5 c^{5}}
\expval{\dot{\ddot{M}}_{ij} \dot{\ddot{M}}_{ij} - \frac{1}{3} \dot{\ddot{M}}_{kk}^{2} }
\,.
\end{align}}
%

When we do the same from the \textbf{momentum loss}, we get an integral in the form
%
\begin{align}
\dv{P^{k}}{t} \propto \int \dd{\Omega } \dot{\ddot{Q}}^{TT}_{ij} \partial^{k} \ddot{Q}^{TT}_{ij}
\,,
\end{align}
%
which is odd under spatial inversion because of the spatial derivative, so there is no contribution!

This is not true if we go beyond the quadrupole approximation: full GR calculations/simulations show that there can be kicks at the merger.

In linearized gravity, we can calculate the power loss by energy conservation:
%
\begin{align}
\dv{E _{\text{source}}}{t} = - \dv{E _{\text{far-field}}}{t} = - \frac{G}{5c^{5}} \expval{\dot{\ddot{Q}}^{ij} \dot{\ddot{Q}}^{ij}}
\,,
\end{align}
%
although this is not exact moment-by-moment in full GR, since there some of the emission can be delayed.
In our approximation, the two sides of the equation should be calculated at the same retarded time: the power loss by the source at \(t - r/c\) will be the power detected a distance \(r\) away at a time \(t\).

\subsection{Angular momentum loss from GW}

\subsubsection{Effective back-action force}

% We can calculate the angular distribution in a relatively simple way, since it is easy to go to TT gauge at a point.

We can model the back-action from GW as a force applied on the source \cite[sec.\ 3.3.4]{maggioreGravitationalWavesVolume2007}, whose power is the average of \(\vec{F} \cdot \vec{v}\) as in classical mechanics; since we consider a continuous medium we have:
%
\begin{align}
- \frac{G}{5 c^{5}} \expval{\dv[3]{Q_{ij}}{t} \dv[3]{Q_{ij}}{t}}
= \dv{E _{\text{source}}}{t} =
\expval{\int  \dd[3]{x} \dv{F_i}{V} \dot{x}_{i}}
\,.
\end{align}

We can integrate by parts twice to write the two third derivatives as
%
\begin{align}
\expval{\dv[3]{Q_{ij}}{t} \dv[3]{Q_{ij}}{t}}
= \expval{\dv{Q_{ij}}{t} \dv[5]{Q_{ij}}{t}}
\,.
\end{align}

Also, the 0th component of the conservation of the stress-energy tensor \(\partial_{\mu } T^{0 \mu }\) for a classical source reads \(\partial_{t} \rho + \partial_{i} \qty(\rho v_i) = 0 \). Using this fact, we can rewrite the first derivative of \(Q_{ij}\) as
%
\begin{align}
\dv{Q_{ij}}{t} &= \dv{}{t} \int  \dd[3]{x}
\rho \bigg( x_{i} x_{j} - \underbrace{\frac{1}{3} r^2 \delta_{ij}}_{\mathclap{\text{contracted with traceless \(\dot{\ddot{\ddot{Q}}}_{ij}\)}}}\bigg)
= - \int \dd[3]{x} \partial_{k} \qty(\rho v_k)
 x_{i} x_{j}  \\
&= + \int \dd[3]{x} \rho v_k \partial_{k} \qty(x_i x_j) =
2 \int \dd[3]{x} \rho v_{(i } x_{j)}
\,.
\end{align}
%
\todo[inline]{Missing symmetrization in the slides! Although it is implicit when contracting with \(Q\)\dots}

Then our equation reads:
%
\begin{align}
\expval{\int \dd[3]{x} \dv{F_i}{V} \dot{x}_{i}} = - \frac{2G}{5c^{5}}\expval{\int \dd[3]{x} \dv[5]{Q_{ij}}{t} \rho \dot{x}_{i} x_{j}}
\,,
\end{align}
%
so we can identify the terms to get
%
\begin{align}
\dv{F_{i}}{V} = - \frac{2G}{5c^{5}} \dv[5]{Q_{ij}}{t} \rho (t, \vec{x}) x_{j}
\,,
\end{align}
%
so finally, since the only position-dependent terms on the right-hand side are the density and the position we get that the effective force is:
%
\boxalign{
\begin{align}
F_{i} = - \frac{2G}{5c^{5}} \dv[5]{Q_{ij}}{t} m \overline{x}_{j}
\,,
\end{align}}
%
where \(\overline{x}_{j} \) is the center-of-mass coordinate.

\subsubsection{Angular momentum}

With this effective force we can calculate the torque explicitly: in general it is given by \(T_i = \epsilon_{ijk} x_j F_k\), which we can make into a local relation by substituting \(T_i\) and \(F_k\) with their densities. With this we can write
%
\begin{align}
\dv{T_i}{V} = \epsilon_{ijk} x_j  \dv{F_k}{V} = -
\epsilon_{ijk} x_j  \frac{2G}{5 c^{5}} \dv[5]{Q_{kl}}{t} \rho (t, \vec{x}) x_l
\,,
\end{align}
%
so the total torque is given by
%
\begin{align}
T_{i} &= - \frac{2G}{5 c^{5}} \epsilon_{ijk} \dv[5]{Q_{kl}}{t}
\int \dd[3]{x} \rho (t, \vec{x}) x_l x_j \underbrace{- \frac{1}{3} r^2 \delta_{lj}}_{\mathclap{\text{does not contribute, since \(Q\) is traceless}}} \\
&= - \frac{2G}{5 c^{5}} \epsilon_{ijk} \dv[5]{Q_{kl}}{t} Q_{lj}
\,,
\end{align}
%
so if we take the average, substituting the derivative of the angular momentum for the torque and integrating by parts twice to get a second and a third derivative, we find:
%
\begin{align}
\expval{\dv{L_{i}}{t}} = -\frac{2G}{5c^{5}} \epsilon_{ijk}
\expval{\ddot{Q}_{jl} \dot{\ddot{Q}}_{kl}}
\,.
\end{align}

\section{Back-reaction and the evolution of binary systems}

\subsection{Compact circular inspiral}

We use the reduced mass formalism for a two-body problem: we define the total mass \(M = m_1 +m_2 \), the reduced mass \(\mu = m_1 m_2 / M\), the relative coordinate \(\vec{x} = \vec{x}_1 - \vec{x}_2\) whose modulus is \(R = \abs{\vec{x}}\).
The angular velocity of the circular motion is \(\omega_{s}\), satisfying Kepler's law \(\omega_{s}^2 R^3 = GM\).

As we saw, the amplitude of the emitted gravitational waves is given by
%
\begin{align}
A = \frac{4 G^{5/3} \omega_{s}^{2/3} \mu M^{2/3}}{r c^{4}}
\,,
\end{align}
%
and the amplitudes of the two polarizations in time are given in terms of \(A\) by
%
\begin{subequations}
\begin{align}
h_{+} &= A \frac{1 - \cos^2\theta   }{2} \cos(2 \omega_{s} t _{\text{ret}} + 2 \varphi ) \\
h_{\times } &= A \cos \theta  \sin(2 \omega_{s} t _{\text{ret}} + 2 \varphi )
\,.
\end{align}
\end{subequations}

In order to make these expressions easier to interpret, we define the chirp mass:
%
\begin{align}
M_c = \mu ^{3/5} M^{2/5} = \frac{\qty(m_1 m_2 )^{3/5}}{(m_1 + m_2 )^{1/5}}
\,.
\end{align}

Also, since the frequency of the emitted GW is double that of the binary we define \(f_{GW} = 2 f_s = 2 \omega_{s} / (2 \pi )\), and \(\omega_{GW} = 2 \pi f_{GW}\).
The reduced wavelength corresponding to this frequency is \(\lambdabar = c / \omega_{GW}\); also we can define a Schwarzschild radius corresponding to the chirp mass: \(R_C = 2GM_c / c^2\).

With these definitions we can rewrite \(A\) as:
%
\begin{align}
A = \frac{4}{r} \qty( \frac{G M_C}{c^2})^{5/3} \qty( \frac{\pi f_{GW}}{c})^{2/3}
= \frac{1}{\sqrt[3]{2}} \frac{R_C}{r} \qty( \frac{R_C}{\lambdabar})^{2/3}
\,,
\end{align}

As we have shown, in the quadrupole approximation the radiated power is:
%
\begin{align}
\dv{E}{t} = \frac{G}{5 c^{5}} \expval{\dot{\ddot{M}}_{ij} \dot{\ddot{M}}_{ij} - \frac{1}{3} \qty(\dot{\ddot{M}}_{kk})^2}
\,,
\end{align}
%
which we can calculate explicitly for our binary.
We have already derived expressions for the second time derivatives of the second mass moment, \(\ddot{M}_{ij}\) for motion in the \(xy\) plane \eqref{eq:second-mass-moment-xy-components}; taking their derivative we get
%
\begin{align}
\dot{\ddot{M}}_{11} = - \dot{\ddot{M}}_{22} =
- 4 \mu R^2 \omega_{s}^3 \sin(2 \omega_{s}t )
\qquad \text{and} \qquad
\dot{\ddot{M}}_{12} = 4 \mu R^2 \omega_{s}^3 \cos(\omega_{s}t)
\,,
\end{align}
%
so the term \(\qty(\dot{\ddot{M}}_{ij})^2\) vanishes (\(\dot{\ddot{M}}_{ij}\) is traceless) and \(\dot{\ddot{M}}_{11}^2 = \dot{\ddot{M}}_{22}^2\), so the contribution we get is
%
\begin{align}
\dv{E}{t} &= \frac{G}{5 c^{5}} \expval{2 \dot{\ddot{M}}_{11}^2 + 2 \dot{\ddot{M}}_{12}^2 }  \\
&= \frac{G}{5 c^{5}} 2 \qty(4 \mu R^2 \omega_{s}^3)^2 \underbrace{\qty(\expval{\sin^2(2 \omega_{s}t)} + \expval{\cos^2(2\omega_{s}t)})}_{= 1/2 + 1/2 = 1}
\,,
\end{align}
%
since the average of the squared sine or cosine is \(1/2\).
Now, we can simplify this expression by using \(R^3 = GM / \omega_{s}^2\) and substituting in the GW angular velocity:
%
\begin{align}
\dv{E_{GW}}{t} &= \frac{32G}{5c^{5}} \mu^2 R^{4} \omega_{s}^{6}  \\
&= \frac{32G}{5c^{5}} \mu^2 \qty( \frac{GM}{\omega_{s}})^{4/3} \omega_{s}^{6}  \\
&= \frac{32}{5c^{5}} \mu^2 G^{7/3} M^{4/3} \omega_{s}^{10/3} \\
&= \frac{32}{5} \frac{c^{5}}{G} \qty( \frac{G M_c \omega_{GW}}{2 c^{3}})^{10/3} \label{eq:gravitational-wave-total-power-emitted}
\,.
\end{align}

We can apply a similar reasoning for the angular momentum loss (here \(L = \abs{\vec{L}}\)):
%
\begin{align}
\dv{L}{t} =
\frac{32}{5} \frac{c^{5}}{G} \qty( \frac{G M_c \omega_{GW}}{2 c^{3}})^{10/3} \frac{2}{\omega_{GW}}
= \frac{32}{5} \frac{c^{5}}{G} \qty(\frac{G M_c}{c^{3}})^{10/3} \qty(\frac{\omega_{GW}}{2})^{7/3}
\,.
\end{align}

If we have masses in circular orbit, then by the virial theorem their total energy is given by half of the potential energy:
%
\begin{align}
E = - \frac{1}{2} \frac{G m_1 m_2  }{R}
\,,
\end{align}
%
which we can differentiate with respect to time to get \(\dot{E} = G m_1 m_2 / (2 R^2) \dot{R}\); this can be also written as
%
\begin{align} \label{eq:radius-evolution-binary}
\dot{R} = - \frac{2R^2}{G m_1 m_2 } \dot{E}_{GW}
\,,
\end{align}
%
as long as the orbital energy is only lost through gravitational wave emission.

This means that, as the GW carry away energy, the radius shrinks; this corresponds to an increase in frequency, and a corresponding increase in gravitational wave emission.

In all our calculations we assumed the orbits to be circular!
This is fine, as long as they are almost-circular: the condition to require is that the variation of the radius across a single orbit is very small:
%
\begin{align}
\abs{\frac{\dot{R} T}{R}} \ll 1
\,,
\end{align}
%
where \(T\) is the period.
In order to express this conditions in terms of the orbital angular velocity \(\omega_{s}\) we use Kepler's law: if we differentiate \(R = \qty(GM / \omega_{s}^2)^{1/3}\) we get
%
\begin{align} \label{eq:derivative-radius-evolution-binary}
\dot{R} = - \frac{2}{3} \omega_{s}^{-5/3} \qty(GM)^{1/3} \dot{\omega}_{s}
= - \frac{2}{3} \frac{R}{\omega_{s}} \dot{\omega}_{s}
\,.
\end{align}

This equality can also be written in terms of logarithmic derivatives as
%
\begin{align} \label{eq:log-derivatives-radius-angular-velocity-binary}
\frac{\dot{R}}{R} + \frac{2}{3} \frac{\dot{\omega}_{s}}{\omega_{s}} = 0
\,.
\end{align}

Starting from this, and using \(T = 2 \pi / \omega_{s}\) we can write
%
\begin{align}
\abs{\frac{\dot{R}T}{R}} = \frac{2}{3} \frac{R}{\omega_{s}} \dot{\omega}_{s} \frac{2\pi}{\omega_{s}} \frac{1}{R} = \frac{4 \pi }{3} \frac{\dot{\omega}_{s}}{\omega_{s}^2}
\,,
\end{align}
%
which means that we need to require \(\dot{\omega}_{s} \ll \omega_{s}^2\).

In practice, this condition is quite well satisfied for most of the inspiral, right up until the merger phase.
Motion satisfying this condition is called \textbf{quasi-circular}.

\end{document}


\subsection{Rate Distortion Analysis}
%rate distortion analysis

Rate distortion is a critical metric to assess the overall compression quality. As for rate-distortion, \emph{rate} is also known as \emph{bit-rate}, refering to the number of bits used to represent a data point on average after the compression (the smaller the better). \emph{Distortion} is assessed using \emph{peak signal-to-noise ratio} (PSNR), which is a common criterion to assess the overall compression error (the higher the better).

The rate distortion results are presented in Figure \ref{fig:rate-distortion_psnr}.

%plot rate distortion


\chapter{Exploring The Hopfield Model}
% This is where we describe our experiments. We insert plots, images, ....

We started out the analysis by experimenting with converge of patterns. We shall present two experiments, that provide some interesting insight for the reader into the Hopfield Model.

\section{Facial Recognition for Police criminal records}

This experiment describes how the Hopfield network might be used by a Police Office, in order to identify criminals. Since the police has a big database that contains facial images of criminals, the network can perform identify, given an image, which criminal is depicted.

Before being sent to the Hopfield model, the image suffers a few normalising transformations:
\begin{enumerate}
 \item the background is completely removed
 \item the image is scaled to 25x25 pixels.
 \item conversion first to grayscale, and then to only black or white pixels takes place
\end{enumerate}

In figure \ref{fig:criminal}, we present the convergence series for the input image of a criminal. The network used for this experiment had 400 neurons, running on images of 20x20 pixels. It clearly illustrates the how efficient the networks can be in these scenarios. However, the network might also convert to to spurious patterns, which might create problems in certain situations. See section \ref{spurious_patterns} for a more detailed description.

\begin{figure}[h]
  \centering
\includegraphics[scale=2]{images/convergence/all.png}
\caption{Convergence sequence for a criminal in the police database}
\label{fig:criminal}
\end{figure}

Furthermore, we have developed a GUI, powered by the underlying recognition core, to provide a friendly user experience, in addition to providing interactive facilities (figure \ref{fig:gui}). An overview of our the recognition system can be found in figure ~\ref{fig:system}.

\begin{figure}[h]
  \centering
\includegraphics[scale=0.3]{screenshots-small/gui1.jpg}
\caption{GUI for a criminal record recognition system.}
\label{fig:gui}
\end{figure}

\begin{figure}[h]
  \centering
\includegraphics[scale=0.3]{recognition.jpg}
\caption{Outline of the Recognition System demonstrating how the various system components interact}
\label{fig:system}
\end{figure}

\section{Further analysis}

Our initial aim was to explore various properties of the attractors in a Hopfield Network. We are interested in studying, testing or challenging several ideas about the neural network:
\begin{itemize}
 \item Clusters of attractors: We are interested to see how the Hopfield network behaves when learning similarly correlated patterns. This implies training the network with a cluster of attractors, which will lower the capacity of the network. We believe that basin sizes will get smaller as the patterns get closer to each other.
 \item Super-Attractors: Find out what happens if the network is trained several times with the same pattern. We believe this super-attractor will have a larger basin size compared to the other attractors.
 \item Convergence: We plan to train the network with different types of attractors and find out to which ones patterns tend to converge.
\end{itemize}

\section{Basins of Attraction}
%I think we should move the measurements for the basins of attraction in here.
A basin of attraction for a particular attractor \(\alpha\) is defined as the set of all states that will eventually converge to \(\alpha\), under repeated update. Here, we are particularly interested in finding a way to measure the size of such a basin of attraction. A large basin size would provide stability for the attractor, since the states in the neighbourhood would converge to it. A small basin size for an attractor would mean that the network might never recall the pattern corresponding to that attractor.

\subsection{Measuring the Basin Size using the Storkey-Valabregue technique}
\label{storkey_basin_size}

 A large part of our experiments were thus dedicated to measuring basin sizes of different attractors, clusters of attractors and a newly introduced concept of \emph{Super-Attractors}, in section ~\ref{super_attractors}.

 A recognised scientific method for calculating the basin size is the Storkey-Valabregue measurement. This can be computed as follows:

 \begin{enumerate}
  \item Initially n = 1
  \item Choose an initial fixed point corresponding to a stored pattern \(\mu\)
  \item \label{itm:choose radius} Choose some initial normalised Hamming radius \(r=r_{0}\)
  \item Let the set A be all the states Hamming-distant \( nr \) from the fixed point
  \item Sample 100 states from A
  \item Calculate how many of these states are attracted to the fixed point. Denote this number \( t_{\mu}(r) \)
  \item If \( t_{\mu}(r) \) is smaller than 90, stop and return \(nr\)
  \item Increment \(n\) by a suitable amount and repeat from (\ref{itm:choose radius})
  \item Repeat for each attractor.
 \end{enumerate}

% TODO: This algorithm is implemented in the Haskell function ...

\section{Generating Clusters of Attractors}

There are various ways of generating clusters of attractors (i.e. attractors that have a low Hamming distance between each other). We shall present two different methodologies that can be used to generate them.

One way is to start with a root pattern and then reverse each bit with a probability p. The new patterns can be interpreted as noisy versions of the root pattern. We shall denote this procedure T1.

\subsection{Generating Gaussian-Distributed Clusters}

Another objective of this work was to analyse patterns that are extracted according to a Gaussian distribution with a specific mean and variance.

Since the state space is \( 2^N \) for a network of N neurons, the Gaussian Distribution will have to be defined over a huge set of states. This is highly non-trivial, since we are dealing with binary patterns, that cannot be ordered in an easy way.

In this case, we will use Mancinelli's method for sampling Gaussian distributed patterns \cite[p.~33]{federico}. We tackle this issue using the simplest possible approach: to draw numbers from a Normal Distribution and then translate them into patterns that will preserve the distance between them. Formally, if \(x\) and \(y\) were drawn and \( |x-y|=\delta\), then the Hamming distance between the encoded patterns \(x'\) and \(y'\) would also be \( d(x',y')=\delta\).

\subsubsection{Encoding of the patterns}

In order to encode a number into a binary pattern, we first round the number to the nearest integer. Let k be the integer obtained as such. Now, from left to right, we set to 1 all the bits in locations 1..k of our pattern. The remaining bits are set to -1.

For example, if the pattern size is 7 and the integer obtained is 4, we get the following pattern: [1,1,1,1,-1,-1,-1].

\subsubsection{Limitations of the encoding}

Although the method has a big advantage for simplicity, we can only obtain N different patterns out of all \( 2^N\) patterns available in the state space. However, we can regain capacity if we start flipping bits, while at the same time keeping constant the hamming distance to some certain mean pattern \(\mu\).

Another idea would be to extend our distribution to a multi-variate distribution. In this case, the capacity of the network would increase from \(N\) to \(\frac{n}{k}^k\), where k is the number of dimensions.

Unfortunately, we did not have enough time to implement these ideas, so we only experimented with the naive encoding of patterns described above.

\section{First experiments with basin sizes}
\label{sec:fexp}

In this section we shall introduce the experiments that we used to analyse various properties of the Hopfield Network. We remind the reader about the two methods that we are going to use for generating clusters of attractors:
\begin{itemize}
 \item T1: We start with a root pattern \(\mu\), and generate patterns by flipping each bit from \(\mu\) with probability \(p\).
 \item T2: This method is generating Gaussian-distributed patterns. We sample several numbers from a normal distribution with a certain mean and variance, and then encode each number into patterns of the form [1,1,1,-1,-1].
\end{itemize}

\subsection{Basin Size for One Cluster using T1}

Our first experiment is showing us the basin sizes for increasing values of p, the probability of flipping a bit. Method T1 is used, for a Hopfield Network of N neurons.

\begin{easylist}[enumerate]
\ListProperties(Style2*=,Numbers=a,Numbers1=R,FinalMark=.)
& We generate a random pattern \(\mu\)

& For all values of probability p from 0 to 0.5

    && Starting from \(\mu\) we generate P patterns using T1, and give them to the Hopfield network in order to be learned according to Hebb or Storkey rule.

    && We measure the basin size for all the patterns learned using the Storkey-Valabregue measurement and take their mean.
\end{easylist}

\begin{figure}[h]
  \centering
  \input{plot-T1-onecluster-100}
\caption{Average Basin size of patterns belonging to one cluster generated using T1}
\label{fig:plot-T1-onecluster}
\end{figure}

\subsubsection{Comments}

The results are displayed in figure \ref{fig:plot-T1-onecluster}. This initial experiment is confirming not only what Mancinelli obtained \cite{federico}, but also what we already know from theory: A Hopfield network that is trained with similar patterns loses capacity. Although we are not measuring capacity here, the basin size is strongly correlated to that.

Initially, when p is zero, we observe a huge value of 24 for the basin size. This is easily explained, since all the patterns generated are the the same as the root pattern. Subsequently, the network is trained with the same patterns that have the effect of creating a super-attractor with a huge basin size.

When p is between 0 and a critical value of 0.35, the basin size is 0, since the patterns are too close to each other and don't have enough space to fit basins of attraction between them. As soon as p goes over 0.35, the basins start to increase until a maximum size of 11.

\subsubsection{Further explanation of the results}

The results can also be easily understood and visualised in figure \ref{fig:basins}. For small p values, the attractors formed in the network are too close to each other to allow room for any basins of attraction (apart from the attractors lying at the edge of the cluster). When the p-value is high, the attractors become more disperse, leaving room for larger basins. It is also worth mentioning that the basin shapes are not necessarily hyper-spherical.

\begin{figure}[h]
  \centering
\includegraphics[scale=0.25]{images/basins_of_attraction.png}
\caption{Illustration of clusters of attractors generated using T1, with different p-values. }
\label{fig:basins}
\end{figure}

\subsection{Basin Size for Two Clusters using T1}

This experiment is similar to the previous one, however it contains two clusters this time. The value \(p_{1}\) for one cluster will stay the same (fixed at 0.45), while \( p_{2}\), corresponding to the second cluster, will vary in the range [0-0.5]. Method T1 is used, for a Hopfield Network of N neurons. The procedure is given below:
\newline
\begin{easylist}[enumerate]
\ListProperties(Style2*=,Numbers=a,Numbers1=R,FinalMark=.)
& We generate 2 random patterns \(\mu_{1}\) and \(\mu_{2}\), corresponding to clusters \( C_{1} \) and \( C_{2} \).

& We generate P patterns for \( C_{1} \), using T1 with associated probability \( p_{1}=0.45\).

& For all values of probability \( p_{2} \) from 0 to 0.5

    && Starting from \(\mu_{2}\) we generate P patterns using T1 with associated probability \( p_{2} \), and give them to the Hopfield network in order to be learned according to Hebb or Storkey rule.

    && For both sets of patterns, we measure the mean basin size using the Storkey-Valabregue measurement and plot the values on the graph.
\end{easylist}

We will be interested to observe how can the probability p influences the basin sizes. For this reason, we have run two experiments, in which we are outputting the basin sizes for cluster 1, in which p varies. The

\subsubsection{Comments}

\begin{figure}[h]
  \centering
  \input{plot-T1-twocluster-100}
\caption{Average Basin size of patterns belonging to Cluster 2, generated using T1}
\label{fig:plot-T1-twocluster}
\end{figure}

This latter experiment seems to suggest that the probability $p$ of flipping bits in the pattern doesn't actually influence the basin sizes of attractors in Cluster 1. The same behaviour has been observed in the previous graph, and this is the case especially when the root images, that are randomly generated, are far away from each other.

\subsubsection{Link to attachment theory}
A network having been trained with two clusters of patterns can be interpreted, in attachment theory, with an infant that has been exposed to two different caregivers. The patterns can be for example, visual or auditory memories describing the 2 caregivers.

\section{Experiments with Gaussian-distributed patterns}

In this section we are testing clusters of patterns that have been generated using a normal distribution. We are expecting to get similar results to the T1 method, since by the Central Limit Theorem, the Binomial distribution ~ B(N, p) is nicely approximated by a Gaussian distribution with mean N(Np, Np(1-p)). Since in the previous experiments, we used to increase the probability p of flipping a bit, this now translates to increasing the standard deviation of the normal distribution.

\subsubsection{Comments}

\begin{figure}[h]
  \centering
  \input{plot-T2-onecluster-100}
\caption{Average basin sizes of one cluster generated using T2}
\label{fig:plot-T2-onecluster}
\end{figure}

The results here are quite surprising. The experiment with Gaussian-distributed patterns shows us that the basin sizes decrease exponentially as standard deviation increases. This might be the case because at low standard deviation, the patterns would repeat themselves and create small super-attractors that have big basin sizes.
This is in contradiction with what we obtained previously, when using method T1, and further details and possible explanations are given in section \ref{inconsistencies}.

\subsection{Basin Size for Two Clusters using T2}

\subsubsection{Comments}

\begin{figure}[h]
  \centering
  \input{plot-T2-twocluster-100}
\caption{Average basin size for two clusters generated using T2}
\label{fig:plot-T2-twocluster}
\end{figure}

This experiment has been run on a network of 100 nodes, with 2 clusters of patterns:C1, with fixed standard deviation $\sigma_{1}$, and C2, with varying standard deviation $\sigma_{2}$. We have run two different trials, with $\sigma_{1}$ = 5 or 10.

As it can be easily noticed in the graph, the standard deviation does not have any effect on the basin size of the clusters. This seems to suggest that a more disperse cluster will not be affected by neighbouring attractors.

\section{Super Attractors}
\label{super_attractors}
In the context of learning models such as the Hopfield model, we define a super attractor as an attractor resulting from training a model with multiple occurrences or instances of some stored pattern. The degree of a super attractor denotes the number of occurrences of its corresponding pattern in the training set.

In the context of modelling Attachment theory, a super attractor may represent repeated interactions with the primary care giver. Clearly, it is of interest to investigate the properties of such an attractor; in particular establishing the existence and, if existent, the type of relationship between the degree of the super attractor and the extent of its dominance, or stability, over the space of patterns.

\subsection{Single super attractor}

% Define variables
\newcommand{\psuper}{$p_{super}$}
\newcommand{\prandom}{$\overrightarrow{p}_{random}$}

\begin{enumerate}

\item Fix N, the number of neurons.

\item \label{itm:choose pattern} Choose a random pattern \psuper, which signifies the primary care giver.

\item Choose a number of random patterns \prandom, such that the Hamming distance between \psuper and each of \prandom is between 25\% and 75\%.

The range forms a ball centred at 50\% Hamming distance\footnote{The percentage Hamming distance is simply the Hamming distance divided by the number of bits N} with an arbitrary radius, chosen such that the probability of a \prandom falling into \psuper's basin of attraction is small. This is done to avoid forming clusters of attractors, which we deal with separately in Recall that the Hopfield network is sign blind, and as a result the inverse of \psuper, $p_{super}^{-1}$, forms a symmetric super attractor. It is for this reason that a symmetric range about 50\% is chosen.

\item Choose a degree $d$ for \psuper and train a Hopfield network using $\overrightarrow{p}^d_{super}$ ($d$ instances of \psuper) and \prandom.

\item Measure the basin of attraction of \psuper using the Storkey-Valabregue method.

\item Repeat from (\ref{itm:choose pattern}) for various values of degree $d$.

\end{enumerate}

In our experiment 100 neurons are used, and the network is trained with 16 random patterns in addition to the super attractor. It is run with degree values {[}1, 2, 4, 8, 16, 32{]}. The entire procedure is repeated 800 times for various randomly chosen \psuper and \prandom. The average results obtained are summarised in ~\ref{fig:one super plot}.

This experiment can be replicated by running \texttt{Experiment.hs}.

\begin{figure}[h]
  \centering
\input{plot-one-super}
\caption{Average basin of attraction for a super attractor with varying degrees.}
\label{fig:one super plot}
\end{figure}

The results show that as the super attractor's degree is increased, its basin of attraction also increases. Also note that this increase appears to approach the singularity at 50\% Hamming distance, which is consistent with our knowledge of \psuper's symmetrical counterpart. The very fast initial growth also indicates that super attractors in general very stable and demonstrate strong dominance over the space of patterns.

Linking back to the Attachment theory model, this may be interpreted as depicting the strong influence of repeated and consistent interaction with the child, represented by a super attractor of increasing degree. In particular, it exhibits its dominance over distantly scattered, unrelated influences, which are represented by the random patterns.

\subsection{Two super attractors}

% Define variables
\newcommand{\poriginsuper}{$p_{origin}$}
\newcommand{\pnewsuper}{$p_{new}$}
\newcommand{\dorigin}{$d_{origin}$}
\newcommand{\dnew}{$d_{new}$}

\begin{enumerate}

\item Fix N, the number of neurons.

\item Fix a degree \dorigin, for all chosen \poriginsuper from (\ref{itm:choose two super}).

\item \label{itm:choose two super} Choose a random pattern \poriginsuper, which signifies the primary care giver.

\item Choose a random pattern \pnewsuper, such that the Hamming distance between \poriginsuper and each of \pnewsuper is between 25\% and 75\%. This could symbolise the training due to either an alternate and influential care giver, or that resulting from a retraining period.

\item Choose a number of random patterns \prandom, such that the Hamming distance between \poriginsuper and each of \prandom is between 25\% and 75\%.

Note that while this allows for the possibility of forming a cluster in the vicinity of \pnewsuper, in practice the probability of this occurring is negligible.

\item Choose a degree \dnew for \pnewsuper and train a Hopfield network using \prandom, \dorigin instances of \poriginsuper, and \dnew instances of \pnewsuper

\item Measure the basins of attraction for each of \poriginsuper and \pnewsuper using the Storkey-Valabregue method.

\item Repeat from (\ref{itm:choose two super}) for different value of degree \dnew.

\end{enumerate}

In our experiment 100 neurons are used, and the network was trained with 8 random patterns in addition to the original and new super attractors, \poriginsuper and \pnewsuper, respectively. \poriginsuper is given a fixed degree, \dorigin, of 8. This value was chosen as being the smallest point of stability from the previous experiment ~\ref{fig:one super plot}, beyond which increasing the degree further does not greatly impact the basin of attraction. It is run with \dnew degree values {[}1, 2, 4, 8, 16, 32{]}. The entire procedure is repeated 634 times for various randomly chosen \poriginsuper, \pnewsuper and \prandom. The average results obtained are summarised in ~\ref{fig:two super plot}.

This experiment can be replicated by running \texttt{Experiment2SuperAttractors.hs}.

\begin{figure}[h]
  \centering
\input{plot-two-super}
\caption{Average basin of attraction for the two super attractors, \poriginsuper having a fixed degree, \dorigin, of 8, and varying the degree, \dnew, of \pnewsuper.}
\label{fig:two super plot}
\end{figure}

The results clearly reveal that increasing the degree of the new pattern increases its own basin of attraction, and decreases that of the original pattern. This relationship is symmetrical, as can be observed by the shape of the graph, in addition to the intersection point, which occurs (roughly) near the point (8 , 8) where both patterns have the same degree of 8. By random choice of original pattern, and random choice of new pattern (subject to a Hamming distance of 25\% to 75\% from the original pattern), we can claim that the basin of attraction depends solely on the relative degrees of the two patterns, and is independent of the actual patterns themselves. This is also consistent with the symmetry observed.

This also fits in nicely nicely with in the Attachment theory interpretation. The original pattern as before represents the consistent interactions with a primary care giver. The new pattern may represent the consistent, yet significantly different, interactions with an alternate and influential care giver, perhaps the other parent of the child or a relative with whom they have developed a close relationship. Intuitively, the care giver which has more interactions would exert a stronger influence, undermining the dominance of the other care giver, and indeed the impact of any other interactions.

In relation to retraining, the new pattern may also be taken to represent the influences arising due to the undertaken retraining phase. We find that, similar to the above, increasing the number of interactions due to retraining further ingrains its dominance, and dilutes that of the previous interactions due to the primary care giver or otherwise.

% undefined variables
\let\psuper\undefined
\let\poriginsuper\undefined
\let\pnewsuper\undefined
\let\dorigin\undefined
\let\dnew\undefined
\let\prandom\undefined