% Chapter 2

\chapter{Convolutional Neural Networks} % Main chapter title

\label{Chapter2}

%-------------------------------------------------------------------------------
%-------------------------------------------------------------------------------

\section{CNNs: Layer by Layer}

Convolutional neural networks have been very successful in computer vision as their key ingredient convolution filters preserve 2D structure and are able to pull features from images. Back propogation and stochastic gradient descent are used to optimize these filters in order to produce. Here I will cover some of the most common layers used in CNNs.

\subsection{Convolution Layer}

The first and foremost layer is the convolution layer. A convolution layer contains a set of filters which are \textit{convolved} across feature maps in order to get the feature map. Let's take a concrete look at what this means. Imagine we are working with images that are of the shape 28x28x3 pixels. We then decide we want to use a convolution filter of size 2x2x5 which will result in a 28x28x5 feature map. Each kernel in this filter will be of size 2x2x3 since the depth in our original image is 3 and there will be five kernels. We then take the dot product of each slice in our 2x2x3 matrix against the original image at pixel 0x0 giving us 3 scalar values which are summed to get the first value in the first feature map of the output. We then slide these filters across the entire feature map in x and y thereby creating a new feature map.  See ~\ref{fig:Convolution} for an example of convolving two 3x3x3 kernels on a 7x7 image.  A few things to consider when sliding the feature maps are image padding. For pixel 0,0 in our example part of the filter would be off the image. To keep the convolution consistent people will often times pad the edges of the image with 0 or 0.5. Additionally a stride length can be set which determines how far we move the filter at each step. A stride length of 2 would skip every other pixel when sliding.

\begin{figure}[ht]
\includegraphics[width=0.9\textwidth]{Figures/Convolution.png}
\caption{An example of performing a 3x3 convolution with a depth of two on an 7x7x3 image with 1 pixel of padding from Andrej Karpathy's Stanford CNN Course \cite{StanfordConv}}
\label{fig:Convolution}
\end{figure}

\subsection{Activation Layer}

Its common after each of the convolutional layers to apply a non-linear activation function. A few examples of activation include: \\

\[ \sigma(x) = \frac{1}{1+e^{-x}} \]
\[ \tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}} \]

\[ ReLu(x) = \begin{cases}
      0 & x < 0 \\
      x & x \geq 0
   \end{cases}
\]

ReLu or rectified linear unit has been a popular choice for cnns as it is computation efficient without sacrificing accuracy.

\subsection{Pooling Layer}

Pooling layers are used to downsample feature maps from layer to layer. Two common flavors of pooling layers are max pooling and average pooling. Max pooling simply looks at a window and returns only the maximum value. Average pooling as it names suggests averages all the values in the window and returns that value. Lets take for example a 2x2 max pooling layer with an feature map of size of 128x128x32. After applying the pooling layer we would have 64x64x32 as an output. A common intuition behind max pooling is that it provides spatial invariance, i.e. if an object shifts by a few pixels we will still have a high response. An alternative to max pooling is using strided convolutions. The argument for this is that a good amount of information is lost in pooling layers.

\subsection{Fully Connected Layer}

Fully connected layers are what we traditional think of as the multi-layer perceptron model. They are commonly used in the final layer of CNNs to distill feature maps from a multi-dimensional matrix into a vector that can be then used for classification or regression. As a simple example are classification networks that will use two fully connected layers where the output is a vector of the same length as number of classes they want to predict from. SoftMax is applied to the vector to normalize the sum of the vector to one and then each scalar in the vector is interpreted as a likelihood of that image being of that particular class.

\subsection{Transfer Learning}

Transfer learning is the process of taking a neural network trained for a certain task and refining it for another. A common example of this is retraining a classification network to predict a different set of classes than what it was originally trained for or changed from a classifier to a regression network. The common intuition for this is that the early layers in the network have learned basic features like, curves, corners, or other simple patterns that are universal in all types of objects. The top layers which carry the strong semantic information are closer to the end and therefore receive more gradient during back propagation. Some methods even freeze the weights for lower levels as fixed feature extractors and only allow the the final layers to change during training. As a bonus, transfer learning reduces the total time to train a network as the lower levels of a network take longer to train that the deeper layers.

When exploring new architectures it is common procedure to simply download a set of weights for a popular network backbone and just apply transfer learning from there. In these next sections I will cover some of the popular network backbones.

\subsection{VGG16}

VGG16 was one of the first major networks after AlexNet which went for simplicity and depth \cite{VGG16}. The first contribution was its simplicity. CNNs before VGG used very large filter sizes, for example AlexNet used 11x11, which led to large parameter sizes. The authors of VGG16 instead used series of two back to back convolution/ReLu layers with 3x3 filters before doing max pooling. VGG16 at the time was considered a very deep network with 13 convolution layers and 3 fully connected layers. It showed that very deep networks were extremely important in learning the hierarchical features necessary for good classification. VGG16 scored $7.3\%$ error rate on ImageNet dataset.

\subsection{ResNet}

In 2015 Microsoft Research came out with \textit{Deep Residual Learning for Image Recognition} \cite{ResNet} which had 152 layers and new type of of block called the residual block. It scored $3.6\%$ on the ImageNet challenge in 2015. A residual block is a normal feed forward neural network that adds in \textit{shortcut} connections where the input to a layer is both fed through a layer but also routed around the layer and added to the output of the next layer. See ~\ref{fig:ResBlock} for a visual description. They hypothesized that a residual mapping induced by this block would be easier to learn than the original feed-forward network. ResNets come in several popular forms now such as ResNet18, ResNet32, ResNet50, ResNet101, and ResNet152, where the choice of depth is based on computational resources and dataset. Most popular deep learning frameworks have pretrained ResNet models available for download.

Another intuition behind ResNets success is that the \textit{shortcut} connections allow gradients to move more easily through the network which helps alleviate a problem known as the vanishing gradient. Vanishing gradients is the problem where the loss at the end of the network has very little impact on changing the weights on the earlier layers and was one of the main reasons preventing networks from going as deep as ResNet. In the next network the use of skip connection is taken even further.

\begin{figure}[ht]
\includegraphics[width=0.9\textwidth]{Figures/ResBlock.png}
\caption{Diagram of Residual Block from \cite{ResNet}}
\label{fig:ResBlock}
\end{figure}

\subsection{DenseNet}

In 2016 Densely Connected Convolutional Networks (DenseNets) were proposed and shown to match and beat the residual network architecture on many datasets while using much fewer parameters and therefore computation. With DenseNets the authors connect all feature maps of same size together through concatenation so that the lth layer will have (l-1) feature maps. This is different then the ResNet model which uses summation in its shortcut connections. In order to concatenate feature maps across max pooling layers DenseNet introduce transition layers. These transition layers pass the prior feature maps through batch normalization, convolution, and finally average pooling before concatenating them to layers further down.

\begin{figure}[ht]
\includegraphics[width=0.9\textwidth]{Figures/DenseNet.png}
\caption{Diagram of Residual Block from \cite{DenseNet}}
\label{fig:DenseNet}
\end{figure}

%-------------------------------------------------------------------------------
%-------------------------------------------------------------------------------
\section{Object Detection Networks}

Object detection networks deal with the problem of first localizing an object with an image frame as well as classifying that object and is generally considered a harder problem then pure classification tasks. The two popular datasets for benchmarking results are \textit{Common Objects in Context} (COCO) \cite{COCO} and \textit{The PASCAL Visual Object Classes} (PASCAL VOC) \cite{VOC}. At the time this work began the two most popular object detection networks were Faster-RCNN and YOLOv2 which I will cover in depth in the next two sections. Since then the state of the art has progressed considerably. Future work might include exploring this architectures.

\subsection{Faster-RCNN}

Faster-RCNN \cite{FASTER-RCNN}, where the R stands for region, is one of the most popular object detection networks at the moment and is an advancement on the authors previous two networks RCNN and Fast RCNN. The authors show results for both VGG16 and ZF network backbones, but many open source implementations of Faster-RCNN have replaced these backbones with various ResNet and DenseNets backbones.

The main contribution of Faster-RCNN is the Region Proposal Network (RPN) which replaces Fast-RCNNs slower, more complicated region proposal mechanism. It works by sliding a window across the final convolution feature map in a network and simultaneously predicting class probability and objectness. Objectness in this context is the probability that there is an object present in the bounding box. The RPN is implemented as a single NxN conv layer that maps into a lower dimension followed by two 1x1 conv layers for class probability and objectness. Furthermore they make use anchor boxes or priors on bounding boxes to make the task of the box regressor easier. At each position in the sliding window there are 9 anchor boxes which the regressor predicts bounding boxes with respect to.

The training scheme for this network is a multi-step process which involves training the RPN and Fast-RCNN networks separately and then later fixing the conv layers of Fast-RCNN and just fine-tuning the RPN.

\subsubsection{Loss}
The loss for Faster-RCNN is split into two parts as shown below.

\begin{align}
    \Loss = \Loss_{cls} +\Loss_{reg}
\end{align}

Given $p_i$ is the predicted confidence that the ith anchor box is an object and $p_i^*$ is a binary indicator that the anchor box has an IoU greater than 0.7 with a ground truth we can define the loss as:

\begin{align}
    \Loss_{cls}(p_i,p_i^*) = \frac{1}{N_{cls}} \sum_{i=1}^{A} [p_i\log(p_i) + (p_i^*-p_i)\log(1-p_i)]
\end{align}

We then parameterize the anchor box and bounding box truth as the following where $_a$ indicates a parameter from the anchor box and $*$ from the ground truth.

\begin{align}
    t_x = \frac{(x - x_a)}{w_a} \\
    t_y = \frac{(y - y_a)}{h_a} \\
    t_w = \log(\frac{w}{w_a}) \\
    t_h = \log(\frac{h}{h_a}) \\
    t_x^* = \frac{(x^* - x_a)}{w_a} \\
    t_y^* = \frac{(y^* - y_a)}{h_a} \\
    t_w^* = \log(\frac{w^*}{w_a}) \\
    t_h^* = \log(\frac{h^*}{h_a}) \\
\end{align}

Next we define the regression loss where again we use $p_i^*$ as an indicator whether this anchor box has an IoU above 0.7 with the ground truth.

\begin{multline}
    \Loss_{reg}(p_i^*, t, t^*) = p_i^*(Smooth_{L1}(t_x-t_x^*) + Smooth_{L1}(t_y-t_y*) \\ + Smooth_{L1}(t_w-t_w*) + SL1(t_h-t_h*)) \\
\end{multline}

\begin{align}
    Smooth_{L1}(d) = \begin{cases}
      0.5d^2 & if |d| \leq 0 \\
      |d| - 0.5 & otherwise
   \end{cases}
\end{align}

\subsection{YOLOv2}

YOLOv2, You Only Look Once, is another successful object detector released in 2016 \cite{YOLOv2}. It's key contribution is a unified network that simultaneously predicts object class and location with out the use of a secondary Region Proposal Network. While maintaining comparable accuracy to Faster-RCNN it runs at a much higher frame rate.

The backbone is of the authors design that uses only 3x3 and 1x1 convolutions, max pooling layers, and batch normalization. The network contains 23 convolution layers, 5 max pooling layers, and one short cut layer that concatenates features from lower levels to the final layer. Since the model contains no fully connected layers the network input size is unconstrained. The 5 max pooling layers of stride 2 mean that the final feature map will have a width and height that is the original width and height divided by $2^5$. As such the the original network input is usually selected to be a multiple of 32 i.e. 320, 416, 608, etc... An example of the network architecture is shown in table~\ref{table:YOLOV2}

\begin{center}
\begin{table}[h]\footnotesize
    \caption{YOLOv2 Network Architecture layer by layer for an input resolution of 608 x 608}\label{table:YOLOV2}
    \begin{tabular}{| l | l | l | l | l |}
    \hline
    layer  & filters & size & input & output \\ \hline \hline

    \rowcolor{LightCyan}
    0 conv & 32 & 3 x 3 / 1 & 608 x 608 x 3 & 608 x 608 x 32 \\ \hline

    \rowcolor{Salmon}
    1 max  & N/A & 2 x 2 / 2 & 608 x 608 x  32   &  304 x 304 x  32 \\ \hline \hline

    \rowcolor{LightCyan}
    2 conv &       64  & 3 x 3 / 1   & 304 x 304 x  32   & 304 x 304 x  64 \\ \hline

    \rowcolor{Salmon}
    3 max &     N/A     & 2 x 2 / 2   & 304 x 304 x  64   &   152 x 152 x  64 \\ \hline \hline

    \rowcolor{LightCyan}
    4 conv &    128  & 3 x 3 / 1   & 152 x 152 x  64   &   152 x 152 x 128 \\ \hline

    \rowcolor{LightCyan}
    5 conv &     64  & 1 x 1 / 1   & 152 x 152 x 128   &   152 x 152 x  64 \\ \hline

    \rowcolor{LightCyan}
    6 conv &    128  & 3 x 3 / 1   & 152 x 152 x  64   &   152 x 152 x 128 \\ \hline

    \rowcolor{Salmon}
    7 max &     N/A     & 2 x 2 / 2   & 152 x 152 x 128   &    76 x  76 x 128 \\ \hline \hline

    \rowcolor{LightCyan}
    8 conv &    256  & 3 x 3 / 1   &  76 x  76 x 128   &    76 x  76 x 256 \\ \hline

    \rowcolor{LightCyan}
    9 conv &    128  & 1 x 1 / 1   &  76 x  76 x 256   &    76 x  76 x 128 \\ \hline

    \rowcolor{LightCyan}
   10 conv &    256  & 3 x 3 / 1   &  76 x  76 x 128   &    76 x  76 x 256 \\ \hline

    \rowcolor{Salmon}
   11 max &     N/A     & 2 x 2 / 2   &  76 x  76 x 256   &    38 x  38 x 256 \\ \hline \hline

    \rowcolor{LightCyan}
   12 conv &    512  & 3 x 3 / 1   &  38 x  38 x 256   &    38 x  38 x 512 \\ \hline

    \rowcolor{LightCyan}
   13 conv &    256  & 1 x 1 / 1   &  38 x  38 x 512   &    38 x  38 x 256 \\ \hline

    \rowcolor{LightCyan}
   14 conv &    512  & 3 x 3 / 1   &  38 x  38 x 256   &    38 x  38 x 512 \\ \hline

    \rowcolor{LightCyan}
   15 conv &    256  & 1 x 1 / 1   &  38 x  38 x 512   &    38 x  38 x 256 \\ \hline

    \rowcolor{LightCyan}
   16 conv &    512  & 3 x 3 / 1   &  38 x  38 x 256   &    38 x  38 x 512 \\ \hline

   \rowcolor{Salmon}
   17 max &     N/A     & 2 x 2 / 2   &  38 x  38 x 512   &    19 x  19 x 512 \\ \hline \hline

    \rowcolor{LightCyan}
   18 conv &   1024  & 3 x 3 / 1   &  19 x  19 x 512   &    19 x  19 x1024 \\ \hline

    \rowcolor{LightCyan}
   19 conv &    512  & 1 x 1 / 1   &  19 x  19 x1024   &    19 x  19 x 512 \\ \hline

    \rowcolor{LightCyan}
   20 conv &   1024  & 3 x 3 / 1   &  19 x  19 x 512   &    19 x  19 x1024 \\ \hline

    \rowcolor{LightCyan}
   21 conv &    512  & 1 x 1 / 1   &  19 x  19 x1024   &    19 x  19 x 512 \\ \hline

    \rowcolor{LightCyan}
   22 conv &   1024  & 3 x 3 / 1   &  19 x  19 x 512   &    19 x  19 x1024 \\ \hline

    \rowcolor{LightCyan}
   23 conv &   1024  & 3 x 3 / 1   &  19 x  19 x1024   &    19 x  19 x1024 \\ \hline

    \rowcolor{LightCyan}
   24 conv &   1024  & 3 x 3 / 1   &  19 x  19 x1024   &    19 x  19 x1024 \\ \hline \hline

   \rowcolor{LightGreen}
   25 route  & 16 & N/A & N/A & N/A \\ \hline

   \rowcolor{Tan}
   26 reorg & N/A &            / 2      & 38 x  38 x 512    &    19 x  19 x2048 \\ \hline

   \rowcolor{LightGreen}
   27 route & 26 & 24 & N/A & N/A \\ \hline \hline

    \rowcolor{LightCyan}
   28 conv &   1024  & 3 x 3 / 1   & 19 x  19 x3072    &    19 x  19 x1024 \\ \hline

    \rowcolor{LightCyan}
   29 conv &     35  & 1 x 1 / 1   & 19 x  19 x1024    &    19 x  19 x  35 \\ \hline

    \hline
    \end{tabular}
\end{table}
\end{center}

YOLOv2 takes a simple approach to bounding box regression and class prediction. To understand how it works lets view the final feature map as a grid. At each location in this grid we want to predict bounding boxes and give a confidence metric for how likely there is to be an object there. We want to predict 5 numbers at each location in the grid plus a confidence for each class as show below:

\begin{align}\label{eq:bbox_regressed}
    t_x,t_y,t_w,t_h,t_o,P(C_1),...,P(C_N)
\end{align}

The parameters $t_x,t_y,t_w,t_h$ are regressed with relation to the feature map x,y location which we call $f_x$ and $f_y$. Further $t_x,t_y$ are constrained to be between [0,1] by the logistic function. We also define $p_w,p_h$ as the prior width and height for the anchor boxes.

\begin{align}
    b_x &= \sigma(t_x) + f_x \\
    b_y &= \sigma(t_y) + f_y \\
    b_w &= p_w * exp(t_w) \\
    b_h &= p_h * exp(t_h)
\end{align}

Like Faster-RCNN the author uses anchor boxes as priors for predicting bounding boxes at each locations. The author determined that 5 prior anchor boxes was a good trade-off between accuracy and efficiency. For each prior bounding box we need to predict the parameters shown in equation~\ref{eq:bbox_regressed}.

Lets take a concrete look at this with an example. Say that our input resolution is 416 x 416, we have 3 classes, and are using 5 prior anchor boxes. Dividing our input resolution by 32 we obtain our final feature map width and height equal to 13. Now at each location in this 13 x 13 map we need to regress 3 classes and 5 bounding box parameters for 5 anchor boxes.

\begin{align}
    (5 * (5 + 3)) * 13^2) = 6760
\end{align}

Instead of using a several fully connected layer to regress these numbers the author simply uses a 1x1 conv in the prior layer and sets the number of filters equal to the number of anchors multiplied by the 5 parameters plus the number of classes. In table~\ref{table:YOLOV2} there are 5 anchors and 2 classes meaning there are 35 filters going into the final feature map. Which can be seen on layer 29.

This setup allows the user to have the freedom to change the input resolution on the fly without having to modify the final layer. The only information we need a prior is the number of classes.

\subsubsection{Loss}

The loss function for YOLOv2 consists of 4 separate parts

\begin{align}
    \Loss_{YOLOv2} = \Loss_{coord} + \Loss_{obj} + \Loss_{noobj} + \Loss_{class} \\
\end{align}

The first part $\Loss_{coord}$ deals with bounding box regression.

\begin{multline}
    \Loss_{coord} = \lambda_{cood} \sum_{i=1}^{f_x*f_y} \sum_{j=i}^{Anchors}
    \indicator_{obj}^{i,j} [
        (\sigma(t_x^{(i,j)}) - \sigma(\hat{t}_x^{(i,j)}))^2 +
        (\sigma(t_y^{(i,j)}) - \sigma(\hat{t}_y^{(i,j)}))^2 + \\
        (\sigma(t_w^{(i,j)}) - \sigma(\hat{t}_w^{(i,j)}))^2 +
        (\sigma(t_h^{(i,j)}) - \sigma(\hat{t}_h^{(i,j)}))^2] \\
\end{multline}

The next part deal with the loss associated with predicting the objectness of the bounding box. Ideally we would like the objectness to predict the IoU of the predicted bounding box with the true bounding box. This is a little unintuitive as during inference we do not have access to the truth. The $\Loss_{noobj}$ is there to punish false positives.

\begin{align}
    \Loss_{obj} = \lambda_{obj} \sum_{i=1}^{f_x*f_y} \sum_{j=i}^{Anchors} \indicator_{obj}^{i,j} (IoU_{truth}^{pred} - \sigma(\hat{t}_o^{(i,j)}))^2 \\
    \Loss_{noobj} = \lambda_{noobj} \sum_{i=1}^{f_x*f_y} \sum_{j=i}^{Anchors} \indicator_{noobj}^{i,j} (-\sigma(\hat{t}_o^{(i,j)}))^2 \\
\end{align}

The final piece weights the error associated with predicting the class of the bounding box. It's simply the sum of squared error of the true class probability distribution (which is 1 at the true class and 0 everywhere else) and the predicted class probability. This is different that much formulations which is the cross entropy loss function like Faster-RCNN.

\begin{align}
    \Loss_{class} = \lambda_{class}\sum_{i=1}^{f_x*f_y} \sum_{j=i}^{Anchors} \sum_{c=1}^{N} \indicator_{obj}^{i,j} (\indicator_{c=true class}-P(c)^{(i,j)})^2
\end{align}

As an aside the naive loss function with regard to class probability has serious issues with regards to class imbalance. Our work demonstrates YOLOv2s inability to work well over in these situations as well be explained further in the results section.

\subsection{Selecting a Network}

Preliminary results using both networks showed results heavily in favor of YOLOv2. The largest reason being the input size to YOLOv2 could easily be scaled up and had pretrained models for higher resolution networks. This could potentially have been replicated on with Faster-RCNN; however, it would have taken extensive architecture changes and weeks training networks from scratch.

Additionally the Darknet framework that YOLOv2 runs on was more approachable for the author allowing for easy modifications where necessary.


\section{Supplementary material}

\paragraph{Simplicial distance and the localizing property of the Laplacian.}
Suppose that $\sigma$ and $\tau$ are $p$-simplices for which $(\nu_0, \nu_1, \dotsc, \nu_d)$ is the shortest sequence of $p$-simplices with the property that $\nu_0=\sigma$, $\nu_d=\tau$, and each $\nu_i$ shares a face or a coface with $\nu_{i-1}$, and a face or a coface with $\nu_{i+1}$. We say that $d$ is the \emph{simplicial distance} between $\sigma$ and $\tau$. Then for all $N<d$, the entry of $L_p^N$ corresponding to $\sigma$ and $\tau$ is $0$, and so the filter does not cause interaction between $c(\sigma)$ and $c(\tau)$. This is analogous to a size-$d$ ordinary CNN layer not distributing information between pixels that are more than $d$ pixels apart. We will refer to $N$ as the \emph{degree} of the convolutional layer, but one may well wish to keep in mind the notion of \emph{size} from traditional CNNs.

\paragraph{Simplicial complexes as the projections of bipartite graphs.}
Given a bipartite graph $X$-$Y$, the simplicial projection on $Y$ is the simplicial complex whose $(k-1)$-simplices are the sets of $k$ vertices in $Y$ that have at least one common neighbor in $X$.
Cochains on the simplicial projection are naturally given by weights on $X$: Given any $(k-1)$-simplex $[y_1,\dots,y_k]$ and its neighboring vertices $\{x_1,\dots,x_j\}\subseteq X$, one can define a $(k-1)$-cochain as $\phi(\{x_1,\dots,x_j\})$, for any function $\phi: \mathcal{P}(X)\to\RR$.
In our coauthorship application, $\phi$ is the sum and the weight of a paper is the number of times it is cited.
See Figure~\ref{fig:bipartite}.

\begin{figure}[htpb]
%\begin{table*}[!t]
\savebox{\tempbox}{

  \begin{tikzpicture}[font=\scriptsize]
    \coordinate (I) at (0,0);
    \coordinate (II) at (0,-0.5);
    \coordinate (III) at (0,-1);
    \coordinate (IV) at (0,-1.5);

    \coordinate (A) at ($ (I) + (2,0) $);
    \coordinate (B) at ($ (II) + (2,0) $);
    \coordinate (C) at ($ (III) + (2,0) $);
    \coordinate (D) at ($ (IV) + (2,0) $);

    \fill[color=black] (I) circle (2pt);
    \fill[color=black] (II) circle (2pt);
    \fill[color=black] (III) circle (2pt);
    \fill[color=black] (IV) circle (2pt);
    \fill[color=black] (A) circle (2pt);
    \fill[color=black] (B) circle (2pt);
    \fill[color=black] (C) circle (2pt);
    \fill[color=black] (D) circle (2pt);

    \node[anchor=east] at (I) {Paper \MakeUppercase{\romannumeral 1}, $100$ citations};
    \node[anchor=east] at (II) {Paper \MakeUppercase{\romannumeral 2}, $50$ citations};
    \node[anchor=east] at (III) {Paper \MakeUppercase{\romannumeral 3}, $10$ citations};
    \node[anchor=east] at (IV) {Paper \MakeUppercase{\romannumeral 4}, $4$ citations};

    \node[anchor=west] at (A) {Author $A$};
    \node[anchor=west] at (B) {Author $B$};
    \node[anchor=west] at (C) {Author $C$};
    \node[anchor=west] at (D) {Author $D$};

    \draw (I) -- (A);
    \draw (I) -- (B);
    \draw (I) -- (C);

    \draw (II) -- (A);
    \draw (II) -- (B);

    \draw (III) -- (A);
    \draw (III) -- (D);

    \draw (IV) -- (C);
    \draw (IV) -- (D);
  \end{tikzpicture}

}%
\settowidth{\tempwidth}{\usebox{\tempbox}}%
\hfil\begin{minipage}[b]{\tempwidth}%
\raisebox{-\height}{\usebox{\tempbox}}%
%\vspace{-7pt}
\scriptsize{\caption*{(a)}}%
\end{minipage}%
\savebox{\tempbox}{

  \begin{tikzpicture}[font=\scriptsize]
    \coordinate (A) at (0,0);
    \coordinate (B) at (2,0);

    \coordinate (C) at ($ (A) + (300:1) $);
    \node[anchor=north] at (C) {$100$};

    \coordinate (D) at ($ (B) + (240:1) $);
    \node[anchor=north] at (D) {$50$};

    \draw[dashed] (A) -- (C) -- (B);
    \draw[dashed] (A) -- (D) -- (B);

    \coordinate (AA) at ($ (A) + (0, -1.5) $);
    \coordinate (BB) at ($ (B) + (0, -1.5) $);

    \fill[color=black] (A) circle (2pt);
    \fill[color=black] (B) circle (2pt);
    \fill[color=black] (AA) circle (2pt);
    \fill[color=black] (BB) circle (2pt);

    \draw (A) -- (B);
    \draw (AA) -- node[below, align=center] {$1$-cochain\\ $150=100+50$} (BB);

    \node[anchor=east] at (A) {$A$};
    \node[anchor=west] at (B) {$B$};
    \node[anchor=east] at (AA) {$A$};
    \node[anchor=west] at (BB) {$B$};

  \end{tikzpicture}
}%
\settowidth{\tempwidth}{\usebox{\tempbox}}%
\hfil\begin{minipage}[b]{\tempwidth}%
\raisebox{-\height}{\usebox{\tempbox}}%
\scriptsize{\captionof*{figure}{(b)}}%
\end{minipage}%
\vspace{5pt}
%\end{table*}
\savebox{\tempbox}{
\input{figures/coauthorship_complex.tex}
}%%
\settowidth{\tempwidth}{\usebox{\tempbox}}%
\hfil\begin{minipage}[b]{\tempwidth}%
\raisebox{-\height}{\usebox{\tempbox}}%
\scriptsize{\captionof*{figure}{(c)}}%
\end{minipage}%
%\end{table*}
\caption{%
    Constructing a simplicial complex and its cochain from a bipartite graph.
    (a)~Paper-author bipartite graph (same data as in Figure~\ref{fig:data2complex}).
    (b)~The $1$-simplex $[A,B]$ is included in the coauthorship complex since authors $A$ and $B$ collaborated on papers I and II.
    The 1-cochain on $[A,B]$ is given by the sum of their common papers' citations.
    (c)~Resulting coauthorship complex with cochains.
}\label{fig:bipartite}
\end{figure}

\begin{table}[htbp]
  \centering
  \scriptsize{
  \begin{tabular}{lrrrrrrrrrrr}
    \toprule
    Dimension   & 0     & 1  & 2     & 3 & 4     & 5 & 6    & 7 & 8   & 9 & 10\\
    \midrule
    CC1 & 352  & 1474  & 3285  & 5019  & 5559  & 4547  & 2732  & 1175  & 343 & 61 & 5\\
    CC2 & 1126 & 5059 & 11840 & 18822 & 21472 & 17896  & 10847 & 4673 & 1357 & 238 & 19\\
    \bottomrule
  \end{tabular}}
  \vspace{2pt}
  \caption{%
  Number of simplices of the two coauthorship complexes sampled from Semantic Scholar.
  } \label{table:Simplices-coauthor}
\end{table}

\paragraph{Sampling papers.}
From the Semantic Scholar Open Research Corpus~\cite{ammar18NAACL}, we excluded papers with fewer than $5$ citations or more than $10$ authors.
To sample a CC, we sampled $80$ papers (corresponding to maximal simplices in the CC) by performing a random walk (of length $80$, from a randomly chosen starting paper) on the graph whose vertices represent papers and edges connect papers sharing at least one author.

\paragraph{Mean accuracy and absolute error.}
A missing value is considered to be correctly imputed if the imputed value differs by at most $10\%$ from the true value.
The \emph{accuracy} is the percentage of missing values that has been correctly imputed and the \emph{absolute error} is the magnitude of the difference between the imputed and true value.
For each rate of missing values, we compute the \emph{mean accuracy} $\pm$ standard deviation over 5 samples with randomly damaged portions.


\section{Lens distortion and point discretization}
\label{sec:model-lens-distortion}
In Section \ref{subsec:lenses} we have introduced lenses, highlighting their advantages over the pinhole. We also introduced the differences between the thin lens model and the thick lens one, observing how, in both cases, curvature radii could introduce aberrations on the acquired image.

As we said in Section \ref{sec:teo-calibration}, all the calibration algorithms try to solve this problem, but most of them, like Tsai and Zhang, are limited to considering radial distortions. In fact it can be shown that tangential contributions are typically negligible, while radial ones increase when focal length decreases. Fortunately, in literature there are some studies about lenses and thin prism distortions, such as \cite{brown},\cite{DBLP:journals/corr/cs-CV-0308003} and \cite{Heikkila}, which offer some solutions to extend the analysis beyond this limit. \\

As a first thing, we focused on \cite{TsaiTvLenses}. Accordingly with it, the commonly used polynomial for radial distortion model, is given by the series
  \begin{equation}
    \label{eq:radial-tot}
    r_d = r + \delta_r = r + \sum_{j=1}^\infty k_jr^{(2j)}
  \end{equation}
where $r$ is the lens radius and $k_j$ is the radial coefficient of degree $j$. As we will discuss later, the used calibration algorithm are limited to the second order, so Equation \ref{eq:radial-tot} can be reduced as:
  \begin{equation}
    \label{eq:radial-2}
    r_d = r + k_1r^2 + k_2r^4
  \end{equation}

Applying Equation \ref{eq:radial-2} to distorted points, we found a simple relation, similar to that in \cite{TsaiTvLenses}:
  \begin{equation}
    \label{eq:dist-coords}
    x_{p_i} = x_{p_i}^{d} \left( 1 + k_1r^2 \right) \qquad
    y_{p_i} = y_{p_i}^{d} \left( 1 + k_1r^2 \right)
  \end{equation}
where $\left( x_{p_i}^{d}, y_{p_i}^{d} \right)$ are the distorted coordinates in the parallel to sensor image plane. In this way, we can determine the projection of a 3D point in a plane parallel to the sensor and distortion free. Note that, given a specific point, it does not make sense to consider the whole radius $r$ of the lens, so it is preferable to consider its distance from the point to the optical center (that ideally is locate in the center of the lens). \\
As we have done in previous sections, the error is propagated as follows
  \begin{equation}
    \label{eq:sigma-dist}
    \begin{matrix}
      \sigma_{x_{p_i}} = \sqrt{
        \left( \frac{\partial x_{p_i}}{\partial x_{p_i}^d} \right)^2 \sigma_{x_{p_i}^d}^2
        + \left( \frac{\partial x_{p_i}}{\partial k_1} \right)^2 \sigma_{k_1}^2
      }
      \\~\\
      \sigma_{y_{p_i}} = \sqrt{
        \left( \frac{\partial y_{p_i}}{\partial y_{p_i}^d} \right)^2 \sigma_{y_{p_i}^d}^2
        + \left( \frac{\partial y_{p_i}}{\partial k_1} \right)^2 \sigma_{k_1}^2
      }
    \end{matrix}
  \end{equation}
Note that this transformation is the same for both $x$ and $y$, thanks to lens radial distortion symmetry. \\

At this point we have noticed that it is very easy to spread the solution to the tangential distortions. Accordingly with \cite{Heikkila} we observed that Equations \ref{eq:radial-2} could be extended easily:
  \begin{equation*}
    \mathcal{F}\left( r, \bar{k}, \bar{p} \right) =
    \begin{bmatrix}
      x_{p_i}\left( \sum_{j=1}^\infty k_jr^{2j} \right) + \left( 2 p_1 x_{p_i} y_{p_i} + p_2 \left( r^2 + 2 x_{p_i}^2  \right) \right) \left( 1 + p_3 r^2 + \ldots  \right)
      \\
      y_{p_i}\left( \sum_{j=1}^\infty k_jr^{2j} \right) + \left(  p_1 \left( r^2 + 2 y_{p_i}^2  \right) + 2 p_2 x_{p_i} y_{p_i} \right) \left( 1 + p_3 r^2 + \ldots \right)
    \end{bmatrix}
  \end{equation*}
As we can see, to consider tangential distortion some additive factors are needed. The analysis for error propagation is the same as that for the Equation \ref{eq:sigma-dist}, but we have to pay attention to include the partial derivatives of the tangential coefficients. \\
To complete the analysis, we have done some test using nominal lens parameters given by the manufacturer, and we observed that the error improvement was negligible. \\

In the last two cases we could ignore the components depending by distortion coefficients, that we can consider correct thanks to calibration processes. \\

Looking around, we have found another model that we considered of interest. Accordingly with \cite{DBLP:journals/corr/cs-CV-0308003}, radial distortions could be formulated as a rational distribution like:
  \begin{equation*}
    \mathcal{F}\left( r, \bar{k}, \bar{p} \right) = \frac{1 + k_1r + k_2r^2}{1 + k_3r + k_4r^2 + k_5r^3}
  \end{equation*}
It is easy to derive many other formulas from the general one, and the most interesting are shown in Table \ref{tab:dist-funcs}.
  \input{./src/chapters/ch4-Model/tab-functions.tex}
All these functions enjoy some properties,. in fact they are:
  \begin{itemize}
    \item radially symmetric around the center of distortion;
    \item expressed in terms of the radius $r$ only;
    \item continuous and $r_d = 0$ iff $r = 0$;
    \item the approximation of $x_d$ is an odd function of $x$.
  \end{itemize}
The above three properties act as the criteria to be good candidates as radial distribution functions. Despite that, we can see that Equation \#4 is very closed to the Equation \ref{eq:radial-2}. Furthermore, the calibration algorithms we have used are limited to second degree, and in this conditions many of these equations can be traced back to \#4. At the end, it can be shown that the performances of the remaining functions are comparable with \#4. \\
For all these reasons, we focused only on Equations \ref{eq:dist-coords}, but as we have shown in this section, it is easy to extends it to tangential distortion or to increase its degree.

\bigskip
Once we have determined the distorted point in the image plane, the last step is the point discretization. In this phase we are interested in projecting the undistorted point in the distorted sensor plane. Accordingly with \cite{TsaiTvLenses}, this projection can be performed by centering the coordinate reference system in the optical center estimated during calibration processes, and by normalizing the point value in the sensor pixel range. At the end we can write:
  \begin{equation*}
    x_{p_i}^d = d_x'(x_{c_i} - c_x) \qquad \qquad y_{p_i}^d = d_y'(y_{c_i} - c_y)
    % \label{eq:discrete-coords}
  \end{equation*} \\
where $(c_x, c_y)$ is the optical center, and $(d_x', d_y')$ the normalized pixel center to center distance, along $x$ and $y$ axis, respectively. Consistent with what we have done so far, we can conclude with error propagation:
  \begin{equation}
    \begin{matrix}
    %
    \sigma_{x_{p_i}^d} = \sqrt{
      \left( \frac{\partial x_{p_i}^d}{\partial x_{c_i}} \right)^2 \sigma_{x_{c_i}}^2
      + \left( \frac{\partial x_{p_i}^d}{\partial c_x} \right)^2 \sigma_{c_x}^2
    }
  %\end{equation*}
  \\
  %\begin{equation*}
    \sigma_{y_{p_i}^d} = \sqrt{
      \left( \frac{\partial y_{p_i}^d}{\partial y_{c_i}} \right)^2 \sigma_{y_{c_i}}^2
      + \left( \frac{\partial y_{p_i}^d}{\partial c_y} \right)^2 \sigma_{c_y}^2
    }
    %
    \end{matrix}
    \label{eq:model:err:disc}
  \end{equation} \\

\bigskip
Before concluding this section, we want to emphasize a possible source of ambiguity in understanding this model. The explanation started from the end of the chain and follows until the beginning. This choice was taken to better identify, for each step, the elements to analyse, and from which each relation depends. In this way the error determination was easy. However, we have to notice that we want to determine the error committed evaluating the point in the world, starting from pixel detection in the image, then formulas have to interpret in this sense, from pixel to world.


% !TEX root =main.tex

\subsection{More Efficient Proof of Storage-Time}\label{More-Efficient-Proof-of-Storage-Time}

In the following, we show how C-TLP can be used in the PoSt protocols that were proposed in  \cite{Storage-Time} to improve their costs. As stated previously,  two protocols: basic PoSt and compact PoSt, supporting proof of storage-time (in the random oracle) are proposed in \cite{Storage-Time}, where  basic PoSt uses VDF and is publicly verifiable while compact PoSt  utilises a trapdoor delay function (TDF) and is privately verifiable. Also, recall that VDF/TDF is used to allow the server to derive multiple challenges at different points over a certain time period $T$. Note, both types of delay function (VDF and TDF) impose the same computation cost to the server, i.e. $3Tz$ modular exponentiations and $Tz$ modular multiplication if the fastest delay function is used \cite{Wesolowski19}.

Now we show how to replace the delay function in these schemes with C-TLP, in the random oracle.  As in the PoSt protocols, the client at the setup precomputes random challenges (and their PoR tags). But, it encodes all challenges for $z-1$ PoR proofs (excluding first one)  into puzzles using C-TLP. It sends to the server all puzzles, encoded file and plaintext challenges for the first PoR proof. As before, the server generates the first PoR proof using the challenges sent to it in the plaintext. Nevertheless, to find $j\text{\small{-th}}$ challenge to generate  $j\text{\small{-th}}$ PoR proof, the server solves the related puzzle, where $j>1$. It sends to the client all PoR proofs (or a combination of them) after period $T$. Also, if the basic PoSt  is used,  the server sends C-TLP proofs that can be efficiently verified by anyone. On the other hand, if the compact PoSt is used, then the server does not need to send the C-TLP's proofs, as the client already knows the random challenges. The adjustments considerably improve the PoSt protocols' costs. In particular,  the server's computation cost would be $\frac{1}{3}$ of the costs imposed by either of the original PoSt protocols. Also,  there will be $3z$ further reduction in the number of exponentiations:  (a) at the verifier side, in the basic PoSt, as it does not need to perform any exponentiation to check the correctness of C-TLP's output,  (b) at the client-side, in the compact PoSt,  as the client does not need to evaluate TDF at the setup to precompute the challenges which in total involves $3z$ modular exponentiations over $\phi(N)$. Moreover, the proof size would be reduced by a factor of $6.5$.

\begin{remark}
Although the use of C-TLP in the PoSt protocols can reduce the computation and communication costs, (a) the server-side I/O cost in these schemes (i.e. $O(\log n)$ in the basic PoSt and $O(n)$ in the compact one), and (b) PoR's proof size complexity in the basic PoSt, will remain the same. Because these costs stem from the underlying PoR schemes, used as a black box, by the two PoSt protocols.
\end{remark}


\documentclass[11pt,twoside]{fncextra}

\pagestyle{myheadings}
\markboth{}{Asteroids}

\begin{document}

\begin{center}
  \bf Asteroids (pew pew)
\end{center}

In 1609 Johannes Kepler proposed that celestial bodies in the solar system follow elliptical orbits with the sun at one focus. This so-called First Kepler Law laid the groundwork for sophisticated mathematical description of orbits, and indeed spurred and justified the early development of calculus, as Kepler's geometric laws were worked out into formulas that were used to explain gravitational force.

There are multiple parameters used to characterize these orbits. If we consider only the motion within the plane of the orbit, these can all be derived from two readily observed ones: $\tau$, the period of the orbit, and $\epsilon$, the eccentricity of the ellipse. (Larger values mean greater deviation from circularity, with a circle at $\epsilon=0$ and a degenerate line at $\epsilon=1$. )

Perhaps the geometrically easiest parameters to understand are the \emph{true anomaly} $\nu$, which is the angle between the body and its \emph{perihelion}, or its closest approach to the sun; and the distance $r$ from the body to the sun. These parameters are related by the equations \begin{align}
  \tan \frac{\nu}{2} &= \sqrt{\frac{1+\epsilon}{1-\epsilon}}\,
    \tan \frac{\psi}{2}, \label{eq:Asteroids1} \\
  M &= \psi - \epsilon \sin \psi, \label{eq:Asteroids2} \\
  r &=  \frac{a(1-\epsilon^2)}{1+\epsilon \cos \nu} \\
  a^3 &= \mu \left(\frac{\tau}{2\pi}\right)^2.
\end{align}
Here, $M$ is known as the \emph{mean anomaly}; it is proportional to time and varies from 0 to $2\pi$ over one complete orbit traversal. In addition, $\psi$ is known as the \emph{eccentric anomaly}, $a$ is half of the (maximum) diameter of the ellipse, and $\mu$ is a gravitational parameter that for the Sun is $39.47524$ $\text{AU}^3/\text{yr}^2$. (An AU is roughly the Earth--Sun distance.)

Equation~\eqref{eq:Asteroids2} implicitly defines $\psi$ as a function of $M$ (and therefore time), but it cannot be solved in closed form. Instead, given a value of $M$, rootfinding must be used to find $\psi$. The rest of the parameters in the equations can be calculated explicitly from $\psi$.

\subsection*{Preparation}

Read Section~4.1.

\subsection*{Goals}

You will apply \texttt{fzero} in MATLAB to compute the eccentric anomaly given the orbital period and eccentricity of an asteroid. From this you can compute other quantities of interest.

%\end{document}

\subsection*{Procedure}

\begin{enumerate}
\item Let \texttt{M} be a vector of 800 evenly spaced values from $0$ to $2\pi$. Set $\epsilon=0.1$ and solve~\eqref{eq:Asteroids2} using \texttt{fzero} to compute a value of $\psi$ for each entry of $M$. Make a labeled plot of $\psi(M)$.  \item Add to the plot of step 1 by stepping through $\epsilon=0.2,0.3,\ldots,0.9$, and plotting the resulting $\psi(M)$ each time.  \item The asteroid 324 Bamberga is both one of the largest and one of the most eccentric in the asteroid belt. It has $\epsilon = 0.338$ and $\tau = 4.40$ yr. Plot $\nu(M)$ over $0\le M \le 2\pi$ for this asteroid. (You will probably find that $\nu$ jumps suddenly from $\pi$ to $-\pi$. It's not incorrect, but if this offends you, use \texttt{unwrap(nu)} to get a smooth equivalent in $[0,2\pi]$.)
\item Plot $r(M)$ as a function of $M$ for 324 Bamberga.
\item Halley's Comet has $\epsilon=0.967$ and $\tau = 75.3$ yr. Plot $r(M)$ for this comet. What are its maximum (aphelion) and minimum (perihelion) values? (You can check these figures against ones you find on the internet.)
\end{enumerate}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:


\chapter{RESULTS AND DISCUSSIONS}
\label{ch:results}

\section{Background of Study}

Suppose that we have a line with equation $y = 2x + 3$. This line cuts the $y$-axis at $y = 3$. We can find the gradient of the line using \eqref{eq:gradient}. Equation~\eqref{eq:tada}, $\ldots$.

\begin{equation} \label{eq:gradient}
    m = \frac{y_2 - y_1}{x_2 - x_1}
\end{equation}

\begin{equation} \label{eq:tada}
e^{\pi i} + 1 = 0
\end{equation}

\subsection{Comparison of Method A with Other Studies}

\begin{table}[ht]
    \caption{Length Units}
    %\begin{tabular}{cc}
    \begin{tabular}{>{\centering\arraybackslash}p{.47\textwidth} >{\centering\arraybackslash}p{.47\textwidth}}
        \toprule %header
        Millimeters & Centimeters\\
        mm          &   cm\\
        \midrule
        1           &   0.1\\
        10          &   1\\
        100         &   10\\
        1000        &   100\\
        10000       &   1000\\
        \bottomrule
    \end{tabular}
    \par\raggedright Note: This table is useful for $\ldots$.
    \label{table:lengthunits}
\end{table}

\subsubsection{Method A Improved}

Figure~\ref{fig:logouitm} is $\dots$. \lipsum[1-2]

\begin{figure}[ht]
    \centering
    \fbox{ % add box arounf image
        \includegraphics[width=.9\linewidth]{logouitm} % scale=.5 <- 50% of original size
    }
    \caption[Short version for LoF]{Logo UiTM Logo UiTM Logo UiTM Logo UiTM Logo UiTM Logo UiTM Logo UiTM Logo UiTM}
    \label{fig:logouitm}

    \par\raggedright
    Notes/Sources: Phasellus in dui mi. Suspendisse placerat nisl et elit tristique, non congue elit bibendum. Donec mauris libero, vehicula in feugiat vitae.
\end{figure}

\lipsum[2-3]


%Abstract

\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}

%The structures and energies of different types of clusters are studied
%computationally. For this, a combination of graph theoretical methods,
%approximate interaction potentials and accurate quantum chemical calculations is
%used to investigate gold clusters, Lennard-Jones (LJ) clusters and clusters
%bound by the sticky-hard-sphere (SHS) interaction potential.

The structures and stabilities of hollow gold clusters are investigated by means
of density functional theory (DFT) as topological duals of carbon fullerenes.
Fullerenes can be constructed by taking a graphene sheet and wrapping it around
a sphere, which requires the introduction of exactly 12 pentagons. In the dual
case, a (111) face-centred cubic (fcc) gold sheet can be deformed in the same
way, introducing 12 vertices of degree five, to create hollow gold nano-cages.
This one-to-one relationship follows trivially from Euler's polyhedral formula
and there are as many golden dual fullerene isomers as there are carbon
fullerenes. Photoelectron spectra of the clusters are simulated and
compared to experimental results to investigate the possibility of detecting
other dual fullerene isomers. The stability of the hollow gold cages is compared
to compact structures and a clear energy convergence towards the (111) fcc sheet
of gold is observed.

The relationship between the Lennard-Jones (LJ) and sticky-hard-sphere (SHS)
potential is investigated by means of geometry optimisations starting from the
SHS clusters. It is shown that the number of non-isomorphic structures resulting
from this procedure depends strongly on the exponents of the LJ potential. Not
all LJ minima, that have been discovered in previous work, can be retrieved this
way and the mapping from the SHS to the LJ structures is therefore non-injective
and non-surjective. The number of missing structures is small and they
correspond to energetically unfavourable minima on the energy landscape. The
optimisations are also carried out for an extended Lennard-Jones potential
derived from coupled-cluster calculations for the xenon dimer, and, although the
shape of the potential is not too different from a regular (6,12)-LJ potential,
the number of minima increases substantially.

Gregory-Newton clusters, which are clusters where 12 spheres surround and touch
a central sphere, are obtained from the complete set of SHS clusters. All 737
structures result in an icosahedron, when optimised with a (6,12)-LJ potential.
Furthermore, the contact graphs, consisting only of atoms from the outer shell
of the clusters, are all edge-induced sub-graphs of the icosahedral graph. For
higher LJ exponents the symmetry of the potential energy surface breaks away
from the icosahedral motif towards the SHS landscape, which does not support a
perfect icosahedron for energetic reasons. This symmetry breaking is mainly
governed by the shape of the potential in the repulsive region, with the
long-range attractive region having little influence.


\subsection{Analytic geometry in the plane}\label{subsec:analytic_geometry_in_the_plane}

\begin{remark}\label{rem:analytic_geometry}
  Analytic geometry is a XVII-century branch of mathematics that studies geometric figures using coordinate \hyperref[rem:coordinate_systems]{systems}. The term \enquote{analytic geometry} may refer to a modern subbranch of algebraic geometry, however we refrain from using \enquote{analytic geometry} in that sense. Historically, most of these definitions were given either for the Euclidean \hyperref[def:euclidean_plane]{plane} or for the three-dimensional Euclidean space.

  Most of the definitions from \fullref{subsec:vector_space_geometry} are generalizations of concepts from analytic geometry. We will state definitions in the language of linear algebra and refrain from using synthetic (axiomatic) geometry. When working in the plane (resp. three-dimensional space), we will assume that we have fixed an \hyperref[def:orthonormal_system]{orthonormal} coordinate \hyperref[def:euclidean_plane_coordinate_system]{system} \( Oxy \) (resp. \( Oxyz \)), which allows us to visualize geometric figures.
\end{remark}

\begin{definition}\label{def:plane_line_equations}
  \hyperref[def:geometric_line]{Lines} in \( \BbbR^2 \) are, so ubiquitous that they can be represented by a lot of standard \hyperref[ex:equations]{equations}.

  \begin{thmenum}
    \thmitem{def:plane_line_equations/vector_parametric} When regarding a line as a parametric curve as in \fullref{def:geometric_line/parametric}, the \hyperref[def:first_order_syntax/formula]{formula}
    \begin{equation}\label{def:plane_line_equations/parametric_equation}
      l(t) = tx + a
    \end{equation}
    is called a \term{vector parametric equation}.

    \thmitem{def:plane_line_equations/scalar_parametric} Given \fullref{def:plane_line_equations/parametric_equation}, the \term{scalar parametric equations} of the line are
    \begin{equation}\label{def:plane_line_equations/scalar_parametric_equations}
      \begin{cases}
         & l_1(t) = t x_1 + a_1  \\
         & l_2(t) = t x_2 + a_2.
      \end{cases}
    \end{equation}

    \thmitem{def:plane_line_equations/general} When regarding a line as an algebraic curve as in \fullref{def:geometric_line/algebraic}, the equation
    \begin{equation}\label{def:plane_line_equations/general_equation}
      p(x, y) \coloneqq Ax + By + C = 0
    \end{equation}
    is called the \term{general equation} or simply \term{equation} of a line in a plane. Either \( A \) or \( B \) must be nonzero, so that \( \deg(p) = 1 \).

    Note that multiple general equations can have the same locus (e.g. the entire polynomial ideal \( \braket{p} \)).

    \thmitem{def:plane_line_equations/normal} If \( A^2 + B^2 = 1 \), we call \fullref{def:plane_line_equations/general_equation} a \term{normal equation}. This leaves us with only two representatives of \( \braket{p} \).

    \thmitem{def:plane_line_equations/cartesian} Given \( k, m \in \BbbR \) and  \( k \neq 0 \), we define the \term{Cartesian equation} of a line:
    \begin{equation}\label{def:plane_line_equations/cartesian_equation}
      y = kx + m.
    \end{equation}

    We call \( k \) the \term{slope} of the line.

    This is a special case of \fullref{def:plane_line_equations/general} with \( A = -k \), \( B = -1 \) and \( C = m \). Unlike the general equation, the Cartesian equation of a line is unique.

    Conversely, if \( B \neq 0 \) in \fullref{def:plane_line_equations/general_equation}, we can define \( k = -\tfrac A B \) and \( m = -\tfrac C B \) to form a Cartesian equation.

    \thmitem{def:plane_line_equations/intercept} Given nonzero \( a, b \in \BbbR \), we define the \term{intercept equation} of a line:
    \begin{equation}\label{def:plane_line_equations/intercept_equation}
      \frac x a + \frac y b = 1,
    \end{equation}

    This is a special case of \fullref{def:plane_line_equations/general} with \( A = \frac 1 a \), \( B = \frac 1 b \) and \( C = -1 \). The intercept equation of a line is also unique.

    If \( A, B, C \neq 0 \) in \fullref{def:plane_line_equations/general}, we can define an \term{intercept equation} as \( a = -\tfrac C A \) and \( b = -\tfrac C B \)).
  \end{thmenum}
\end{definition}

\begin{figure}
  \begin{minipage}[b]{0.40\textwidth}
    \centering
    \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
      input metapost/plotting;

      u := 1.5cm;

      beginfig(1);
      path l, x_axis, y_axis;

      x_axis = (-1, 0) scaled u -- (1, 0) scaled u;
      y_axis = (0, -1) scaled u -- (0, 1) scaled u;
      l = (-1 / 2, -1) * u -- (1, 3 / 4) * u;

      drawarrow x_axis;
      label.bot("$x$", point 0.9 of x_axis);
      drawarrow y_axis;
      label.lft("$y$", point 0.9 of y_axis);
      draw l;
      label.bot("$y = kx + m$", startpoint of l);
      endfig;
    \end{mplibcode}\fi
    \caption{A \hyperref[def:geometric_line]{line} in \( \BbbR^2 \) defined using its \hyperref[def:plane_line_equations/cartesian]{Cartesian equation}.}\label{def:plane_line_equations/cartesian_equation_drawing}
  \end{minipage}
  \hspace{0.05\textwidth}
  \begin{minipage}[b]{0.40\textwidth}
    \centering
    \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
      input metapost/plotting;
      u := 1.5cm;

      beginfig(1)
      drawarrow (-1 / 2, 0) scaled u -- (2, 0) scaled u;
      drawarrow (0, -1 / 2) scaled u -- (0, 2) scaled u;

      z0 = (1 / 2, 1 / 6) scaled u;
      z1 = (2, 11 / 12) scaled u;
      z2 = (1, 13 / 6) scaled u;

      draw z0 -- (x0, max(y1, y2)) dashed withdots;

      drawarrow z0 -- z1;
      draw (x0, y1) -- z1 dashed evenly;
      label.top("$x_1$", midpoint of ((x0, y1) -- z1));

      drawarrow z0 -- z2;
      draw (x0, y2) -- z2 dashed evenly;
      label.bot("$x_2$", midpoint of ((x0, y2) -- z2));
      endfig;
    \end{mplibcode}\fi
    \caption{An \hyperref[def:angle/acute]{acute angle} with its measurement segments dashed.}\label{def:angle/figure}
  \end{minipage}
\end{figure}

\begin{definition}\label{def:angle}
  A \term{directed angle} is a tuple of two closed \hyperref[def:geometric_ray]{rays} with a common vertex. It is a closed cone. Given two rays \( r_1, r_2 \) with a common vertex, we denote their corresponding directed angle by \( \sphericalangle(r_1, r_2) \).

  Suppose that \( r_1 \) and \( r_2 \) have scalar parametric equations
  \begin{equation*}
    r_i: t \mapsto
    \begin{cases}
      tx_i + a_i \\
      ty_i + b_i,
    \end{cases}
    i = 1, 2.
  \end{equation*}

  We write

  The condition of the rays having a common vertex is equivalent to \( a_1 = a_2 \) and \( b_1 = b_2 \). If not specified otherwise, we assume that \( a_1 = a_2 = b_1 = b_2 = 0 \).

  The \term{measure in radians} of a directed angle, often called the angle itself, is defined as the number (see \fullref{def:geometric_trigonometric_functions})
  \begin{equation*}
    \alpha \coloneqq \rem(\arctantwo(y_2, x_2) - \arctantwo(y_1, x_1), 2\pi).
  \end{equation*}

  We can classify angles based on their measure as
  \begin{thmenum}
    \thmitem{def:angle/zero} \term{zero} if \( \alpha = 0 \),
    \thmitem{def:angle/acute} \term{acute} if \( \alpha \in (0, \tfrac \pi 2) \),
    \thmitem{def:angle/right} \term{right} if \( \alpha = \tfrac \pi 2 \),
    \thmitem{def:angle/obtuse} \term{obtuse} if \( \alpha \in (\tfrac \pi 2, \pi) \),
    \thmitem{def:angle/straight} \term{straight} if \( \alpha = \pi \), in which case the angle is actually a line,
    \thmitem{def:angle/reflex} \term{reflex} if \( \alpha > \pi \).
  \end{thmenum}

  We often do not care about the order of the two rays and speak of an \term{undirected angle}. In this case, the measure of the undirected angle is the smaller of the measures of the two oriented angles. Thus, we cannot speak of straight and reflex undirected angles.
\end{definition}

\begin{definition}\label{def:triangle}
  \begin{figure}
    \centering
    \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
      input metapost/plotting;

      beginfig(1)
      pair A, B, C;
      path alpha, beta, gamma;

      A := origin;
      B := (3, 0) scaled u;
      C := (2, 2) scaled u;

      draw A -- B -- C -- cycle;

      alpha = fullcircle scaled (u / 2) shifted A cutbefore (A -- B) cutafter (A -- C);
      draw alpha;
      label.urt("$\alpha$", point 0.4 of alpha);

      beta = fullcircle scaled (u / 2) shifted B cutbefore (B -- C) cutafter (B -- A);
      draw beta;
      label.ulft("$\beta$", point 1.4 of beta);

      gamma = fullcircle scaled (u / 4) shifted C cutbefore (A -- C) cutafter (B -- C);
      draw gamma;
      label.bot("$\gamma$", point 0.6 of gamma);

      fill dot shifted A;
      fill dot shifted B;
      fill dot shifted C;

      label.llft("$A$", A);
      label.lrt("$B$", B);
      label.top("$C$", C);

      label.rt("$a$", midpoint of (B -- C));
      label.ulft("$b$", midpoint of (A -- C));
      label.bot("$c$", midpoint of (A -- B));
      endfig;
    \end{mplibcode}\fi
    \caption{An \hyperref[def:triangle/acute]{acute triangle}.}\label{def:triangle/figure}
  \end{figure}

  A \term{triangle} is a triple \( (A, B, C) \) of \hyperref[def:point]{points}, no two of which are \hyperref[def:collinear_complanar]{collinear} (see \fullref{def:simplex/triangle} for a more general definition). The three points are called the \term{vertices} of the triangle.

  Define the associated \hyperref[def:convex_set/line_segment]{line segments}, called the \term{sides} of the triangle, and its (undirected) \hyperref[def:angle]{angles} as
  \begin{balign*}
    a \coloneqq [B, C], &  & \alpha \coloneqq \sphericalangle(b, c), \\
    b \coloneqq [A, C], &  & \beta \coloneqq \sphericalangle(a, c),  \\
    c \coloneqq [A, B], &  & \gamma \coloneqq \sphericalangle(a, b).
  \end{balign*}

  Note that we defined the angles using segments rather than rays, but this is immaterial because each to each segment \( [p, q] \) there corresponds exactly one closed ray \( t \mapsto p + t q \).

  We can classify triangles based on their sides as
  \begin{thmenum}
    \thmitem{def:triangle/isosceles} \term{isosceles} if at least two of its sides have equal length
    \thmitem{def:triangle/equilateral} \term{equilateral} if all of its sides have equal length
  \end{thmenum}
  or based on their angles as
  \begin{thmenum}
    \thmitem{def:triangle/acute} \term{acute} if all of its angles are \hyperref[def:angle/acute]{acute}.
    \thmitem{def:triangle/right} \term{right} if at least one of the angles is \hyperref[def:angle/straight]{straight}.
    \thmitem{def:triangle/obtuse} \term{obtuse} if at least one of its angles is \hyperref[def:angle/obtuse]{obtuse}.
  \end{thmenum}
\end{definition}

\begin{definition}\label{def:quadratic_plane_curve}
  The \term{quadratic plane curves} are algebraic \hyperref[def:hypersurface/algebraic]{curves} given by a bivariate polynomial of degree \( 2 \). The \term{general equation} of a quadratic plane curve is
  \begin{equation}\label{def:quadratic_plane_curve/general_equation}
    c(x, y) \coloneqq A x^2 + B xy + C y^2 + Dx + Ey + F = 0.
  \end{equation}

  Multiple equation can correspond to the same curve. Not all general equations, however, define algebraic curves. We will not concern ourselves with the details. See \fullref{ex:affine_varieties} for a proof that the unit circle is an algebraic curve. It turns out that the algebraic curves given \fullref{def:quadratic_plane_curve/general_equation} are precisely the ones listed here, collectively known as \term{conic sections}. We give only canonical forms of the equations; any linear transformation of the corresponding loci is described by another general equation.

  \begin{figure}
    \begin{minipage}{0.3\textwidth}
      \centering
      \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
        input metapost/plotting;

        u := 1.25cm;

        vardef scaled_sin(expr x) =
        5 / 6 * sin(x)
        enddef;

        beginfig(1)
        fill dot shifted (u, 0);

        drawarrow (-pi / 2, 0) scaled u -- (pi / 2, 0) scaled u;
        drawarrow (0, -pi / 2) scaled u -- (0, pi / 2) scaled u;

        drawarrow path_of_curve(cos, scaled_sin, -1 / 4 * pi, 3 / 4 * pi, 0.01, u);
        drawarrow path_of_curve(cos, scaled_sin, 3 / 4 * pi, 7 / 4 * pi, 0.01, u);
        endfig;
      \end{mplibcode}\fi
    \end{minipage}
    \hspace{0.02\textwidth}
    \begin{minipage}{0.3\textwidth}
      \centering
      \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
        input metapost/plotting;

        u := 1.25cm;

        vardef minus_cosh(expr x) =
        -cosh(x)
        enddef;

        beginfig(1)
        drawarrow (-pi / 2, 0) scaled u -- (pi / 2, 0) scaled u;
        drawarrow (0, -pi / 2) scaled u -- (0, pi / 2) scaled u;

        drawarrow path_of_curve(cosh, sinh, -pi / 3, 0, 0.01, u);
        drawarrow path_of_curve(cosh, sinh, 0, pi / 3, 0.01, u);

        drawarrow path_of_curve(minus_cosh, sinh, -pi / 3, 0, 0.01, u);
        drawarrow path_of_curve(minus_cosh, sinh, 0, pi / 3, 0.01, u);
        endfig;
      \end{mplibcode}\fi
    \end{minipage}
    \hspace{0.02\textwidth}
    \begin{minipage}{0.3\textwidth}
      \centering
      \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
        input metapost/plotting;

        u := 1.25cm;

        beginfig(1)
        fill dot;

        drawarrow (-pi / 2, 0) scaled u -- (pi / 2, 0) scaled u;
        drawarrow (0, -pi / 2) scaled u -- (0, pi / 2) scaled u;

        vardef y_upper(expr x) =
        sqrt(x)
        enddef;

        vardef y_lower(expr x) =
        -sqrt(x)
        enddef;

        drawarrow path_of_plot(y_upper, 0, pi / 3, 0.01, u);
        drawarrow path_of_plot(y_lower, 0, pi / 3, 0.01, u);
        endfig;
      \end{mplibcode}\fi
    \end{minipage}
    \caption{An \hyperref[def:quadratic_plane_curve/ellipse]{ellipse}, \hyperref[def:quadratic_plane_curve/hyperbola]{hyperbola} and \hyperref[def:quadratic_plane_curve/parabola]{parabola} defined via their parametric equations. The starting point is highlighted and the direction of the parametric curves is shown.}\label{def:quadratic_plane_curve/figure}
  \end{figure}

  \begin{thmenum}
    \thmitem{def:quadratic_plane_curve/ellipse} An \term{ellipse} is a quadratic curve whose canonical equation has the form
    \begin{equation}\label{def:quadratic_plane_curve/ellipse/canonical_equation}
      c(x, y) \coloneqq \frac {x^2} {a^2} + \frac {y^2} {b^2} - 1 = 0,
    \end{equation}
    where \( a, b > 0 \).

    If \( a = b \), we say that the ellipse is a \term{circle} and we call \( a \) the circle's \term{radius}. The \term{unit circle} is defined by \( a = b = 1 \). Circles generalize to \hyperref[def:metric_space/sphere]{spheres} in metric spaces.

    \Fullref{def:pi} and \fullref{def:geometric_trigonometric_functions} logically belong here, but are extracted separately for brevity.

    We are often interested in defining ellipses via \term{scalar parametric equations} using \hyperref[def:trigonometric_functions]{trigonometric functions} as follows:
    \begin{equation}\label{def:quadratic_plane_curve/ellipse/parametric_equations}
      \begin{cases}
        x = a \cos(t) \\
        y = b \sin(t),
      \end{cases}
    \end{equation}
    where \( t \in [0, 2\pi) \).

    We will now demonstrate that \fullref{def:quadratic_plane_curve/ellipse/canonical_equation} and \fullref{def:quadratic_plane_curve/ellipse/parametric_equations} describe the same curve. First, suppose that the pair \( (x_0, y_0) \) satisfies \fullref{def:quadratic_plane_curve/ellipse/canonical_equation}. It follows from \fullref{thm:arctantwo} that \( t_0 \coloneqq \arctantwo\left(\tfrac {y_0} b, \tfrac {x_0} a \right) \) is a, solution to the \hyperref[def:quadratic_plane_curve/ellipse/parametric_equations]{parametric equations}. Conversely, if \( x_0 = a \cos(t_0) \) and \( y_0 = b \sin(t_0) \) for some \( t_0 \in [0, 2\pi) \), by \fullref{thm:trigonometric_identities/pythagorean_identity} it follows that the pair \( (x_0, y_0) \) is a root of \fullref{def:quadratic_plane_curve/ellipse/canonical_equation} and, by \fullref{thm:arctantwo}, \( t_0 \) can be restored given \( \cos(t_0) \) and \( \sin(t_0) \).

    Therefore, every point of the parametric equation \fullref{def:quadratic_plane_curve/ellipse/parametric_equations} corresponds uniquely to a, solution of the canonical equation \fullref{def:quadratic_plane_curve/ellipse/canonical_equation} and vice versa, which makes the two approaches to defining ellipses equivalent.

    \thmitem{def:quadratic_plane_curve/hyperbola} A \term{hyperbola} is a quadratic curve whose canonical equation has the form
    \begin{equation}\label{def:quadratic_plane_curve/hyperbola/canonical_equation}
      c(x, y) \coloneqq \frac {x^2} {a^2} - \frac {y^2} {b^2} - 1 = 0,
    \end{equation}
    where \( a, b > 0 \).

    Similarly to ellipses, we are can define hyperbolas via \term{scalar parametric equations} using \hyperref[def:hyperbolic_trigonometric_functions]{hyperbolic trigonometric functions} as follows:
    \begin{equation}\label{def:quadratic_plane_curve/hyperbola/parametric_equations}
      \begin{cases}
        x = a \cosh(t) \\
        y = b \sinh(t),
      \end{cases}
    \end{equation}
    where \( t \in \BbbR \). This only defines the \term{right part} of the hyperbola. The left part is defined by replacing \( a \) with \( -a \).

    \thmitem{def:quadratic_plane_curve/parabola} A \term{parabola} is a quadratic curve whose canonical equation has the form
    \begin{equation}\label{def:quadratic_plane_curve/parabola/canonical_equation}
      c(x, y) \coloneqq y^2 - 2px = 0,
    \end{equation}
    where \( p \neq 0 \).

    Unlike ellipses and hyperbolas, we do not define parametric equations. Instead, we define \( y \) as a function of \( x \) separately for the lower half-plane and upper half-plane:
    \begin{equation}\label{def:quadratic_plane_curve/parabola/cartesian_equation}
      y(x) = \pm \sqrt{2px}.
    \end{equation}
  \end{thmenum}

  Ellipses, hyperbolas and parabolas are collectively called \term{conic sections}.
\end{definition}

\begin{definition}\label{def:pi}
  \begin{figure}
    \centering
    \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
      input metapost/plotting;

      beginfig(1)
      drawarrow (-pi / 2, 0) scaled u -- (pi / 2, 0) scaled u;
      drawarrow (0, -1 / 2) scaled u -- (0, pi / 2) scaled u;

      vardef y(expr x) =
      sqrt(1 - x ** 2)
      enddef;

      drawarrow path_of_plot(y, -1, 1, 0.01, u);
      endfig;
    \end{mplibcode}\fi
    \caption{\( \gph(y^+) \) as a parametric curve in \fullref{def:pi}.}\label{fig:def:pi/upper_half_circle}
  \end{figure}

  The definition of a circle of unit radius as the zero-locus of the polynomial \( x^2 + y^2 - 1 \) allows us to, solve a chicken-and-egg problem regarding the definitions of the number \( \pi \). It is conventional to define it as the ratio of a circle's circumference to its diameter. For a unit circle, this diameter is \( 2 \). It will be simpler for us, however, to define \( \pi \) as the radius of a half-circle's circumference since we can represent \( y \) as a function of \( x \) in the upper \hyperref[def:half_space]{half-plane} (see \ref{fig:def:pi/upper_half_circle}). Define the parametric curve
  \begin{balign*}
     & y^+: [-1, 1] \to [0, 1]          \\
     & y^+(x) \coloneqq \sqrt{1 - x^2}.
  \end{balign*}

  We use \fullref{thm:length_of_function_graph} to find the length of the graph \( \gph(y^+(x)) \). The derivative of \( y^+(x) \) is
  \begin{equation*}
    D_x[y^+(x)] = \frac{-2x}{2 \sqrt{1 - x^2}} = - \frac x {\sqrt{1 - x^2}} dx.
  \end{equation*}

  The length of the curve \( \gph(y^+) \) is thus
  \begin{equation*}
    \len(\gph(y^+)) = \int_{-1}^1 \sqrt{1 + \frac{x^2}{1 - x^2}} dx = \int_{-1}^1 \frac 1 {\sqrt{1 - x^2}} dx.
  \end{equation*}

  This justifies the definition
  \begin{equation}\label{def:pi/weierstrass_integral}
    \pi \coloneqq \int_{-1}^1 \frac 1 {\sqrt{1 - x^2}} dx.
  \end{equation}

  See \fullref{thm:trigonometric_function_basic_roots} for a proof of how this relates to the trigonometric functions and \fullref{thm:def:exponential_function/properties/eulers_identity} as a consequence.
\end{definition}

\begin{definition}\label{def:geometric_trigonometric_functions}
  After defining the \hyperref[def:trigonometric_functions]{trigonometric functions} \( \cos(z) \) and \( \sin(z) \) analytically via power series, we will define their geometric counterparts \( \cos_G(z) \) and \( \sin_G(z) \) and show the connection between them. The actual geometric definition relies on formalisms that are far beyond our interest (see the notes in \fullref{def:euclidean_plane}).

  Fix a point \( (x_0, y_0) \) on the unit circle (that is, \( x_0^2 + y_0^2 = 1 \)) and define the points
  \begin{equation}\label{def:geometric_trigonometric_functions/vertices}
    \begin{array}{l}
      A \coloneqq (x_0, y_0), \\
      B \coloneqq (0, 0),     \\
      C \coloneqq (x_0, 0).
    \end{array}
  \end{equation}

  Consider the \hyperref[def:triangle]{triangle} formed by these vertices. \Cref{fig:def:geometric_trigonometric_functions/triangle} illustrates the situation.
  \begin{figure}
    \begin{minipage}[b]{0.4\textwidth}
      \centering
      \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
        input metapost/plotting;

        u := 3.5cm;

        beginfig(1)
        pair A, B, C;
        path alpha, beta;

        t := 1;
        A := origin;
        B := (cos(t), sin(t)) scaled u;
        C := (cos(t), 0) scaled u;

        draw A -- B -- C -- cycle;

        alpha = fullcircle scaled (u / 4) shifted A cutbefore (A -- C) cutafter (A -- B);
        draw alpha;
        label.urt("$\alpha$", midpoint of alpha);
        label.lft("$\begin{rcases} \sin_G(\alpha) = \tfrac {\len b} {\len c} \\ \cos_G(\alpha) = \tfrac {\len a} {\len c} \end{rcases}$", A);

        beta = fullcircle scaled (u / 4) shifted B cutbefore (B -- A) cutafter (B -- C);
        draw beta;
        label.llft("$\beta$", point 0.7 of beta);
        label.lft("$\begin{rcases} \sin_G(\beta) = \tfrac {\len a} {\len c} \\ \cos_G(\beta) = \tfrac {\len b} {\len c} \end{rcases}$", B - (0.05, 0) * u);

        fill dot shifted A;
        fill dot shifted B;
        fill dot shifted C;

        label.bot("$A$", A);
        label.top("$B$", B);
        label.lrt("$C$", C);

        label.rt("$a$", midpoint of (B -- C));
        label.bot("$b$", midpoint of (A -- C));
        label.ulft("$c$", midpoint of (A -- B));
        endfig;
      \end{mplibcode}\fi
    \end{minipage}
    \hspace{0.05\textwidth}
    \begin{minipage}[b]{0.4\textwidth}
      \centering
      \text{\todo{Add diagram}}\iffalse\begin{mplibcode}
        input metapost/plotting;

        u := 3.5cm;

        beginfig(1)
        pair A, B, C;
        path alpha, beta;

        t := 1;
        A := origin;
        B := (cos(t), sin(t)) scaled u;
        C := (cos(t), 0) scaled u;

        drawarrow (-sin(pi/16), 0) scaled u -- (5/4, 0) scaled u;
        drawarrow (0, -sin(pi/16)) scaled u -- (0, 5/4) scaled u;

        draw path_of_curve(cos, sin, -pi/16, 9/16 * pi, 0.01, u);
        draw A -- B -- C -- cycle;

        alpha = fullcircle scaled (u / 4) shifted A cutbefore (A -- C) cutafter (A -- B);
        draw alpha;
        label.urt("$\alpha$", midpoint of alpha);

        beta = fullcircle scaled (u / 4) shifted B cutbefore (B -- A) cutafter (B -- C);
        draw beta;
        label.llft("$\beta$", point 0.7 of beta);

        fill dot shifted A;
        fill dot shifted B;
        fill dot shifted C;

        label.llft("$(0, 0)$", A);
        label.urt("$(x_0, y_0)$", B);
        label.lrt("$(x_0, 0)$", C);

        label.rt("$a$", midpoint of (B -- C));
        label.bot("$b$", midpoint of (A -- C));
        label.ulft("$c$", midpoint of (A -- B));
        endfig;
      \end{mplibcode}\fi
    \end{minipage}
    \caption{An \enquote{abstract} right triangle in the \hyperref[def:euclidean_plane]{Euclidean plane} with legends for geometric sines and cosines and the same triangle in \( \BbbR^2 \) connecting the origin to a point \( (x_0, y_0) \) on the unit circle.}\label{fig:def:geometric_trigonometric_functions/triangle}
  \end{figure}

  The original \enquote{geometric definition} of \( \sin_G \) and \( \cos_G \) regards them as functions of an angle rather than numeric functions. \( \sin_G \) and \( \cos_G \) are only defined for two of the angles in a right triangle. The geometric definition is
  \begin{balign*}
    \sin_G(\alpha) \coloneqq \frac{\len(b)} {\len(c)}, &  & \cos_G(\alpha) \coloneqq \frac{\len(a)} {\len(c)},
    \\
    \sin_G(\beta) \coloneqq \frac{\len(b)} {\len(c)},  &  & \cos_G(\beta) \coloneqq \frac{\len(a)} {\len(c)}.
  \end{balign*}

  In our case, \( \len(a) = y_0 \), \( \len(b) = x_0 \) and \( \len(c) = 1 \). Furthermore, \( \sin_G(\beta) \) nor \( \cos_G(
  \beta) \) are immaterial to our subsequent arguments and we only introduced them for the sake of having a full definition.

  Therefore, we conclude that
  \begin{balign*}
    \sin_G(\alpha) = x_0,
     &  &
    \cos_G(\alpha) = y_0.
  \end{balign*}

  To see that \( \sin_G \) and \( \cos_G \) are somewhat analogous to \( \sin \) and \( \cos \), notice that by \fullref{thm:arctantwo}, there exists a unique \( t_0 \coloneqq \arctantwo(y_0, x_0) \) such that
  \begin{balign*}
    \sin(t_0) = x_0,
     &  &
    \cos(t_0) = y_0.
  \end{balign*}

  Therefore, our \hyperref[def:trigonometric_functions]{analytic definition} of the trigonometric functions as numeric functions correspond to the classical geometric definition in the special case where we consider the angle near the origin in the triangle formed by the vertices \fullref{def:geometric_trigonometric_functions/vertices}. This motivates \enquote{measuring} angles using the obtained correspondence. This unit of measurement is called a \term{radian}. We say that the angle \( \alpha \) is \( t_0 \) \term{radians}. Outside of mathematics, it is more conventional to use \term{degrees}, which are obtained from radians by scaling with \( \tfrac {180} {\pi} \). That is, \( \alpha \) is \( \tfrac {180} {\pi} t_0 \) degrees.
\end{definition}


\mychapter{2}{Lesson 2} %180928

\section{Authentic communication}

The most common scenario exposing the problem of authentication is depicted in figure \ref{fig:authentication}. This time, the parties Alice and Bob want to ensure that they are effectively communicating to each other; in other words, nobody else is \emph{impersonating} either party. The objects used here are:
\begin{itemize}
    \item The data to be shared, or \emph{message} $m$;
    \item Some additional secret information, shared by the two parties, that is used to \emph{sign} the message: the \emph{authentication key} or just \emph{key} $k$;
    \item The result of signing a message $m$ using the key $k$: the \emph{signature} or \emph{tag} $t$.
\end{itemize}

\begin{figure}[ht]
    \centering
    \begin{tikzpicture}
        \draw
            (0, 0) node (a) [box, fill = white] {Alice}
            (5, 0) node (b) [box, fill = white] {Bob}
            (2.5, -1) node (e) [box, fill = white] {Eve}
        ;

        \draw[-Stealth] (a) -- node [midway, above] {$(m, t)$} (b);
        \draw[-Stealth] (0, -1) node [below] {$k$} -- (a);
        \draw[-Stealth] (5, -1) node [below] {$k$} -- (b);
        \draw[-Stealth] (-1, 0) node [left] {$m$} -- (a);
        \draw[-Stealth] (b) -- (6, 0) node [right] {$1$};
        \draw[-Stealth] (2, -0.1) -- (3, -0.1) (2.5, -0.1) -- (e);

    \end{tikzpicture}

    \caption{A depiction of the problem of authentic communication}
    \label{fig:authentication}
\end{figure}

The mechanism employed by both parties to enforce authentication is called a \emph{cryptographic authentication scheme}, or just \emph{authentication scheme}, typically taking the form $\Phi = (\Tag, \Ver)$, where:
\begin{itemize}
    \item $\Tag \in \K \times \M \to \T$ is the machine that, given a message $m$ in $\M$ and a key $k$ in $\K$ generates the signature $t$
    \item $\Ver \in \K \times \M \times \T \to \binary$ is the machine that decides whether $t$ is the correct signature for the message $m$ using the key $k$.
\end{itemize}

It is worth observing that, under the assumption that such machines still behave as mathematical functions, a straightforward verifier with inputs $(k, m, t)$ consists in:
\begin{enumerate}
    \item Invoking the tagging function: $u = \Tag(k, m)$;
    \item Comparing $u$ and $t$ for equality.
\end{enumerate}

Given such definitions, an authentication scheme works as intended if and only if:
\[
    \forall m \in \M, \forall k \in \K \implies \Ver(k, m, \Tag(k, m)) = 1
\]

A security problem then arises when someone, having a signed message $(m_1, t_1)$ where the key $k$ used for tagging is unknown, is able to efficiently sign a different message $(m_2, t_2)$ such that verification under the same key yields a success. This acion is called a \emph{forgery}; and by looking at the original setting in figure \ref{fig:authentication}, if Eve is effectively able to forge vaild signatures, she can indeed impersonate either Alice or Bob at will. The desired property of an authentication scheme thus becomes to be resistant, if not immune, to such attacks; in one word, the scheme is \emph{unforgeable}.

\begin{definition}[$\varepsilon$-statistical one-time unforgeability]
    let $\Phi$ be an authentication scheme, and let $m_1$ and $m_2$ be two distinct messages, and $t_1 = \Tag(K, m_1)$ be the signature of $m_1$ under $\Phi$, with the key $K$ picked uniformly at random. $\Phi$ is deemed \emph{$\varepsilon$-statistical one-time unforgeable} iff knowing $m_1$ and $t_1$ does not give any advantage in finding a signature $t_2$ that is actually the signature of $m_2$ under the same scheme and the same key of $m_1$, without knowing such key:
    \[
        \forall m_1 \neq m_2 \in \M \, \forall t_1, t_2 \in \T \quad \Pr[\Tag(K, m_2) = t_2 \knowing \Tag(K, m_1) = t_1] \leq \varepsilon
    \]
\end{definition}

\subsection{An introduction to hashing}

A great deal of authentication has been, and is still done by means of \emph{hashing}, which consists of feeding the message to a special machine that produces a scrambled, unique signature for it; such machines are then known as \emph{hash functions}.

For starters recall that, given a set $A \to B$ that collects all possible functions from $A$ to $B$, a \emph{function family} is a subset of such class that share some specific properties. Having said that:

\begin{definition}
    A family of \emph{hash functions} $H$ is defined as a function family that is mapped 1-to-1 by an indexing set $\mathcal{S}$, where the indices are called \emph{seeds}:\footnote{This kind of notation consisting in putting an argument as a subscript to a generic, typically of higher-order function, is also called ``currying''.}
    \[
        H \in \mathcal{S} \to (\M \to \T) : s \mapsto h_s
    \]
    Furthermore, given a uniformly random seed $S$, the family as a whole distributes the tags uniformly:
    \[
        \forall m \in \M \, \forall t \in \T \qquad \Pr[h_S(m) = t] = \oneover{\T}
    \]
\end{definition}

Having formalized what a hash function family is, the notion of unforgeability can be modeled by the property of \emph{pairwise-independency}:

\begin{definition}
    Let $H$ be a family of hash functions, and $S$ be a uniformly random seed; the hash functions are deemed \emph{pairwise-independent} iff, for any two distinct messages $m_1$ and $m_2$, the pair $(h_S(m_1), h_S(m_2))$ distributes uniformly in $\T^2$:
    \[
        \forall m_1 \neq m_2 \in \M \, \forall t_1, t_2 \in \T \qquad \Pr[h_S(m_1) = t_1 \wedge h_S(m_2) = t_2] = \oneover{|\T|^2}
    \]
\end{definition}

As an example of such a family, consider the additive group of integers modulo $p$: $(\integer_p, +)$, where $p$ is a prime integer. Let the seed space $\mathcal{S}$ be the set of pairs $\integer_p^2$, and define the function family:
\[
    H \in \integer_p^2 \to (\integer_p \to \integer_p) : (a, b) \mapsto (x \mapsto \textrm{\textup{mod}}_p(ax + b))
\]

\begin{proposition}
    The functions in the family $H$ are pairwise-independent.
\end{proposition}

\begin{proof}
    Let $S = (A, B)$ be a uniformly random seed for $H$. For any distinct messages $m_1$ and $m_2$, and for any tags $t_1$ and $t_2$:
    \begin{align*}
        &\ \Pr[h_S(m_1) = t_1 \wedge h_S(m_2) = t_2]        & \\
        =&\ \Pr[A m_1 + B = t_1 \wedge A m_2 + B = t_2]     & \text{($H$ definition)}\\
        =&\ \Pr\left[ \begin{pmatrix} m_1 & 1 \\ m_2 & 1 \end{pmatrix} \cdot \begin{pmatrix} A \\ B \end{pmatrix} = \begin{pmatrix} t_1 \\ t_2 \end{pmatrix} \right]                                        & \text{(Matrix form)} \\
        =&\ \Pr\left[ \begin{pmatrix} A \\ B \end{pmatrix} = \begin{pmatrix} m_1 & 1 \\ m_2 & 1 \end{pmatrix}^{-1} \cdot \begin{pmatrix} t_1 \\ t_2 \end{pmatrix} \right]                                           & \\
        =&\ \oneover{|\integer_p^2|} & \text{($(A, B)$ is uniform)}
    \end{align*}
    which satisfies the definition of pairwise-independency.
\end{proof}

% TODO: Consider making an example in Zp, if possible
It is very important to avoid confusing \emph{pairwise} independency with \emph{mutual} independency: while the former enforces independency only on pairs, the latter extends it to all possible subsets; the two notions are not necessarily equivalent.

The property of pairwise-independency of hash function families can be directly exploited to provide an unforgeable authentication scheme:

\begin{theorem}
    Define an authentication scheme $\Phi = (\Tag, \Ver)$ to be such that its tagging machine is a hash function family $H$:
    \[
        \Tag(k, m) = h_k(m)
    \]
    and let it be pairwise-independent. Then $\Phi$ is $\oneover{|\T|}$-statistical one-time unforgeable.
\end{theorem}

\begin{proof}
    Let $K$ be a uniformly random key. For any distinct messages $m_1$ and $m_2$, and for any tags $t_1$ and $t_2$:
    \begin{align*}
         &\ \Pr[\Tag(K, m_2) = t_2 \knowing \Tag(K, m_1) = t_1]                     & \\
        =&\ \Pr[h_K(m_2) = t_2 \knowing h_K(m_1) = t_1]                             & \text{($\Tag$ definition)} \\
        =&\ \frac{\Pr[h_K(m_2) = t_2 \wedge h_K(m_1) = t_1]}{\Pr[h_K(m_1) = t_1]}   & \text{(Conditional prob. def.)} \\
        =&\ |\T| \cdot \Pr[h_K(m_2) = t_2 \wedge h_K(m_1) = t_1]                    & \text{($H$ is a hash function)} \\
        =&\ \frac{|\T|}{|\T|^2} = \oneover{|\T|}                                    & \text{($H$ is pairwise-independent)}
    \end{align*}

    which satisfies the definition of $\oneover{|\T|}$-statistical one-time unforgeability.
\end{proof}

\todo{Need to link statistical unforgeability with key size beforehand}

\begin{theorem}
    For any positive $\lambda$, a $(2^{-\lambda})$-statistical $t$-time unforgeable authentication scheme has a key of size $(t + 1) \lambda$.
\end{theorem}

\begin{proof}
    Idea: For each ``time'', use one ``subkey''
\end{proof}


\documentclass[11pt]{article}

\usepackage{latexsym}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{pseudocode}
\usepackage{url}
\usepackage[backref, colorlinks=true, citecolor=red, urlcolor=blue, pdfauthor={Jyh-Ming Lien}]{hyperref}

\newcommand{\handout}[5]{
  \noindent
  \begin{center}
  \framebox{
    \vbox{
      \hbox to 5.78in { {\bf Advanced Algorithms} \hfill #2 }
      \vspace{4mm}
      \hbox to 5.78in { {\Large \hfill #5  \hfill} }
      \vspace{2mm}
      \hbox to 5.78in { {\em #3 \hfill #4} }
    }
  }
  \end{center}
  \vspace*{4mm}
}

\newcommand{\lecture}[4]{\handout{#1}{#2}{#3}{}{#1}}

\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{assumption}[theorem]{Assumption}

% 1-inch margins, from fullpage.sty by H.Partl, Version 2, Dec. 15, 1988.
\topmargin 0pt
\advance \topmargin by -\headheight
\advance \topmargin by -\headsep
\textheight 8.9in
\oddsidemargin 0pt
\evensidemargin \oddsidemargin
\marginparwidth 0.5in
\textwidth 6.5in

\parindent 0in
\parskip 1.5ex
%\renewcommand{\baselinestretch}{1.25}

\begin{document}

\lecture{Voronoi Stippling}{Fall 2015}{Prof.\ Jyh-Ming Lien}{---}

The goal of this assignment is to deepen your understanding on various implementations of 2-d Voronoi Diagram.
In this exam, you are given two implementations of 2-d Voronoi Diagram: the Fortune's algorithm and
an algorithm using well-known image-based wave propagation method. You task is to (1) understand the implementations, (2)  compare the results from these two implementations, and (3) finally improve the image-based method.

\textbf{What to submit}: You  need to turn in a report in \LaTeX\ (see the template in report folder).  Your report should include three sections: a summary of what the code does (for both implementations),
your discovery of the differences in output, and your improvement. In the second and third sections, you should include
all the example outputs (visual and/or statistical results). In the last section you should report known bugs, and known limitations.

\textbf{How to submit}:
You should use \href{https://github.com/}{github} to maintain your code and the report. Email me your github clone command to my email address \href{mailto:jmlien@cs.gmu.edu}{\it jmlien@cs.gmu.edu}
before the deadline.

\textbf{Due: Nov 26, 2017. At 11:59 pm.}
\section{Part 1: Understand the implementations (30 pts)}

\subsection{What should  you do?}

Your goal is to get a full grasp of what the code does in both implementations: hedcuter and voronoi.
Your summary should provide algorithms for computing Voronoi diagram, Centroidal Voronoi tessellation (CVT),
and stippling methods from  both implementations.
%Your summary should provide a discussion on what parameters are used to control their outputs.

{\sc Hint 1}: Both methods are based on the paper by Secord, Adrian. ``Weighted voronoi stippling." Proceedings of the 2nd international symposium on Non-photorealistic animation and rendering. ACM, 2002. It is highly recommend that you read the paper first.

{\sc Hint 2}: To compile hedcuter code, please use the solution file in folder {\em hedcuter/code/vc\_files}.
 This code requires OpenCV. By default, it requires 64 bits installation of OpenCV on Windows.
The solution file also uses two environment variables called ``OPENCV\_INCLUDEDIR'' and ``OPENCVX64\_LIBRARYDIR'' the point to
the include and library folders on the system. Therefore, make sure that you have those variable defined before you compile. You can  consult OpenCV documents
(\href{docs.opencv.org}{\it docs.opencv.org}) if you encounter problems.

{\sc Hint 3}: To compile the second code, you will need boost (\href{www.boost.org}{\it www.boost.org}) and define two boost related environment variables:
BOOST\_INCLUDEDIR and BOOST\_LIBRARYDIR before you compile. Each of these variables should have the full paths to the include and library folders on the system.
This implementation is obtained from  \href{http://www.saliences.com/projects/npr/stippling}{\it http://www.saliences.com/projects/npr/stippling}.
Some details of the code can be found there.

\section{Part 2: Compare the Outputs  (30 pts)}

\subsection{What should  you do?}

Your goal is to compare the output of these two implementations.
Use the images in folder hedcuter/images or use images of your own, please show the differences visually (e.g. circle the areas of difference)
and also in writing.
%You can find more of these images from\href{http://philip.greenspun.com/stock/}{\it http://philip.greenspun.com/stock/}.
You should also provide some discussion of where these differences are from.  Here are some questions for you to consider.
You are free to explore beyond these questions.

\begin{enumerate}
\item Do you get the same results by running the same program on the same image multiple times?
\item If you vary the number of the disks in the output images,  do these implementations produce the same distribution in the final image? If not, why?
\item If you vary the number of the disks in the output images,  is a method faster than the other?
\item Does the size (number of pixels), image brightness or contrast of image increase or decrease their difference?
\item Does the type of image (human vs. machine,  natural vs. urban landscapes, photo vs. painting, etc) increase or decrease their difference?
\item Are the outputs of these stippling methods different  the hedcut images created by artists (e.g. those from the \href{http://www.wsj.com/articles/SB10001424052748704207504575129961786135180}{Wall Street Journal})?
\end{enumerate}

\section{Part 3: Improve  ``hedcuter'' code (40 pts)}

\subsection{What should  you do?}

Provide at least two improvements (each will worth 20 points) to the hedcuter code. Below are some possible improvements that
you can do. In your report, you should show the improvement either visually or/and statistically for timing/performance results
using images of your own, i.e. do not use the images in hedcuter/images.
Extra bonus of 20 points will be given for an additional improvement.
\begin{enumerate}

\item Improve the distribution of the disks to avoid unnatural clustering of the disks. One idea is to use higher
image resolution (using subpixels) for computing the centroids of Voronoi cells.

\item Improve the computation efficiency. One way of doing this is via GPU. You can try the method by Hoff III, Kenneth E., et al. ``Fast computation of generalized Voronoi diagrams using graphics hardware." Proceedings of the 26th annual conference on Computer graphics and interactive techniques, 1999. The implementation should be pretty simple if you know OpenGL.

\item Add functionality to generate colorful disks. For example, you can implement functions that are not available in hedcuter code but provided in the voronoi code.
\end{enumerate}

\bibliographystyle{plain}
\bibliography{shape-assignment}

\end{document}


\section*{Exercises}

\begin{ex}
  Consider the vectors $\vect{u}$ and $\vect{v}$ drawn below.
  \begin{center}
    \begin{tikzpicture}[scale=2]
      \draw[->, thick, blue] (0,0)--(2,1);
      \draw[->, thick, red] (4,1)--(5,0.5);
      \node[below] at (1,1.25){$\vect{u}$};
      \node[above right] at (4.5, 0.75){$\vect{v}$};
    \end{tikzpicture}
  \end{center}
  Draw  $-\vect{u}$, $2\vect{v}$, and $-\frac{1}{2}\vect{v}$.

  \begin{sol}
    ~
    \begin{center}
      \begin{tikzpicture}[scale=2]
        \draw[->, thick, blue] (0,0)--(2,1);
        \draw[->, thick, blue] (3,1)--(1,0);
        \draw[->, thick, red] (5,1)--(6,0.5);
        \draw[->, thick, red] (6.5,0.75)--(6,1);
        \draw[->, thick, red] (4,1)--(6,0);
        \node[above] at (1,1){$\vect{u}$};
        \node[below] at (2,0.5){$-\vect{u}$};
        \node[below] at (5.5, 0.75){$\vect{v}$};
        \node[above right] at (6.25, 0.75){$-\frac{1}{2}\vect{v}$};
        \node[below] at (5, 0.4){$2\vect{v}$};
      \end{tikzpicture}
    \end{center}
  \end{sol}
\end{ex}

\begin{ex}
  Find $-3\begin{mymatrix}{r}
    5 \\
    -1 \\
    2 \\
    -3
  \end{mymatrix}
  + 5\begin{mymatrix}{r}
    -8 \\
    2 \\
    -3 \\
    6
  \end{mymatrix}$.
  \begin{sol}
    $\begin{mymatrix}{r}
      -55 \\
      13 \\
      -21 \\
      39
    \end{mymatrix}$.
  \end{sol}
\end{ex}

\begin{ex}
  Use the properties of scalar multiplication from
  Proposition~\ref{prop:vector-scalar-multiplication} and the
  properties of vector addition from
  Proposition~\ref{prop:properties-vector-addition} to prove the
  following equalities. Justify every step.
  \begin{enumerate}
  \item $(k+\ell)(\vect{u}+\vect{v}) = k\vect{u} + k\vect{v} +
    \ell\vect{u} + \ell\vect{v}$.
  \item $0\vect{u} = \vect{0}$.
  \item $(-1)\vect{u} = -\vect{u}$.
  \item $-(k\vect{u}) = k(-\vect{u}) = (-k)\vect{u}$.
  \end{enumerate}
  \begin{sol}
    \begin{enumerate}
    \item
      $(k+\ell)(\vect{u}+\vect{v}) = (k+\ell)\vect{u} +
      (k+\ell)\vect{v} = k\vect{u} + k\vect{v} + \ell\vect{u} +
      \ell\vect{v}$. Here we used the distributive law over vector
      addition in the first step, and the distributive law over scalar
      addition in the second step.
    \item We have $0\vect{u} = (0+0)\vect{u} = 0\vect{u} + 0\vect{u}$
      by properties of scalars and by the distributive law,
      respectively. Adding $-(0\vect{u})$ to both sides of the
      equation, and using the additive unit law and associativity, we
      have $\vect{0} = 0\vect{u}$.
    \item We have $(-1)\vect{u} = (-1)\vect{u} + \vect{0} =
      (-1)\vect{u} + (\vect{u} + (-\vect{u})) = ((-1)\vect{u} +
      \vect{u}) + (-\vect{u}) = ((-1)\vect{u} + 1\vect{u}) +
      (-\vect{u}) = ((-1)+1)\vect{u} + (-\vect{u}) = 0\vect{u} +
      (-\vect{u}) = \vect{0} + (-\vect{u}) = -\vect{u}$. Here, we have
      used the additive unit law, the additive inverse law, the
      associative law, the rule for multiplication by 1, the
      distributive law, properties of scalars, the property of part
      (b), and the additive unit law, respectively.
    \end{enumerate}
  \end{sol}
\end{ex}


\section{What's wrong with monocular camera?}
\label{mono_prob}

As the name suggests a monocular camera is a camera with a single imaging sensor. In section~\ref{imageFormation} we say that given a perfectly calibrated camera ie. with the intrinsic and extrinsic parameters known, we can measure size of objects in the real world. This however is not true for a single image taken from a monocular camera. When 3D objects are projected onto the image plane (2D), the depth information stored in the z-axis is lost. This can be seen in the example below.

% For one-column wide figures use
\begin{figure}
% Use the relevant command to insert your figure file.
% For example, with the graphicx package use
  \includegraphics[width=\textwidth]{./figures/1.png}
% figure caption is below the figure
\caption{Monocular camera scale problem}
\label{fig:mono1}       % Give a unique label
\end{figure}

As seen in the Fig~\ref{fig:mono1}, irrespective of the location of the object in the real world, the size of the object in the image plane remains the same. Mathematically, this can be shown as

\begin{equation}
\frac{y}{f}=\frac{y_1}{z_1+f}=\frac{y_2}{z_2+f}
\end{equation}

Where $f$ is the focal length of the camera. The title of the paper mentions scale estimation. In the context of SLAM which will be covered in the next section, scale is a term used to denote the factor by which the computed trajectory by a SLAM algorithm needs to be multiplied/scaled to make it equal to the ground truth. For example, if the measured distance is 2m, whereas the ground truth is 4m, the scale value would be 2. This is an area of active research and the research community has come up with different techniques to solve this problem. As the title suggests, we would be talking about the fusion of IMU and Vision for solving this challenge.


\subsection{Numerical Approximation and Analysis}\label{sec:set-algorithm}
We present a non-intrusive algorithm based on Monte Carlo sampling\---initially introduced in \cite{BET+14} and further analyzed in \cite{BET+14-arxiv}\---that is structured in four stages (written as four independent for-loops), that are linked to the stages in Fig.~\ref{fig:scheme}.
We direct the interested reader to \cite{BET+14-arxiv} for more detailed information and analysis of this algorithm, e.g., on the requirement of a sampler being ``$\pborel$-consistent'' to ensure convergence.

\begin{algorithm}[hbtp]
\DontPrintSemicolon
Choose a discretization partition $\set{D_\idisc}_{\idisc=1}^{\ndiscs}$ of $\dspace$.\\
	\For{$\idisc = 1, \hdots, \ndiscs$}{
			Compute $p_{\dspace, \idisc} = \dataP(D_\idisc)$.
	}
 	Choose samples $\set{\param^{(\iparam)}}_{\iparam=1}^{\nsamps} \subset \pspace$, which implicitly defines a Voronoi-cell partition $\set{\VV_\iparam}_{\iparam=1}^{\nsamps}$ of $\pspace$.\\
	\For{$\iparam = 1, \hdots, \nsamps$}{
	Compute $\qoi_\iparam = \qoi(\param^{(\iparam)})$.\\
	Let $\OO_\idisc = \set{\iparam: \qoi_\iparam \in D_\idisc}$.\\
	Compute approximations $V_\iparam \approx \pmeas (\VV_\iparam)$.
	}
	\For{$\idisc = 1, \hdots, \ndiscs$}{
	Compute $\CC_\idisc = \set{\iparam:Q_\iparam \in D_\idisc}$.
	}
	\For{$\iparam = 1, \hdots, \nsamps$}{
	Compute $p_{\pspace, \iparam} = \left ( V_\iparam / \sum_{j\in \CC_{\OO_\iparam} } V_j \right ) p_{\dspace, \OO_\iparam}$.
	}
	For any $A\in \pborel$, compute
	\begin{equation}
	\PP_{\pspace, \ndiscs, \nsamps} (A) = \sum_{\iparam=1}^\nsamps p_{\pspace, \iparam} \Chi_{\VV_\iparam} (A)
	\end{equation}
 \caption{Numerical Approximation of the Inverse Density}
 \label{alg:inv_density}
\end{algorithm}

The first two stages correspond to formulating the discretized version of the SIP given in step (S1) in Fig.~\ref{fig:scheme}.
We first discretize the probability space $\Ospace$.
Then, we simultaneously discretize the measure space $(\pspace, \pborel, \pmeas)$ and construct a simple-function approximation to the map $\qoi$.
These stages introduce the primary sources of error, and the third and fourth stages may be thought of as solving the discretized SIP exactly.
The samples that are used to describe $\pspace$ implicitly define a set of Voronoi cells $\set{\VV_\iparam}_{\iparam=1}^{\nsamps}$, which can be seen in Figure~\ref{fig:voronoi_cells}.
Each sample set defines a fundamentally different geometry.

\begin{figure}[ht]
\centering
	\begin{minipage}{.475\textwidth}
		\includegraphics[width=\linewidth]{./images/voronoi_diagrams/voronoi_diagram_N25_r0}
	\end{minipage}
\caption{
Voronoi-cell discretization (partition) induced by $\nsamps = 25 $ uniform i.i.d.~random samples in $\pspace = [0,1]^2$.
}
\label{fig:voronoi_cells}
\end{figure}

The third stage then identifies the collection of Voronoi cells in $\pspace$ that approximate the contour events in $\cborel$ defined by $\qoi^{-1}(D_\idisc)$ for $\idisc=1,\hdots,\ndiscs$. This allows us to formulate the consistent solution to the discretized SIP on $(\pspace, \cborel, \contourP)$ as illustrated in step (S2) of Fig.~\ref{fig:scheme}.
The fourth stage, associated with step (S3) in Fig.~\ref{fig:scheme}, uses a discrete version of the ansatz to approximate the probability of $\VV_\iparam$ for $\iparam=1,\dots,\nsamps$.
This results in an approximate probability measure, denoted by $\updatedPxNM$, which produces the same probability estimates for events $A$ and $A\setminus \set{ \param^{(\iparam)} }_{\iparam=1}^\nsamps$, which are identical almost everywhere with respect to $\pmeas$.

Note that Algorithm~\ref{alg:inv_density} makes no mention of the method by which the samples $\set{ \param^{(\iparam)} }_{\iparam=1}^{\nsamps}$ were generated or sets in $\set{D_\idisc}_{\idisc=1}^{\ndiscs}$ are chosen.
$\set{ \param^{(\iparam)} }_{\iparam=1}^{\nsamps}$ may be generated using uniform random sampling, Latin-hypercube sampling, or even regular grids.
A thorough discussion of the choices involved in making such decisions is beyond the scope of this work, though we touch briefly on the discretization of $\dspace$ in the following section.


\section{Addition and subtraction}
\begin{center}
    \begin{longtable}{lcr}
        $a_1 + a_2\ \cdots\ + a_n = n \cdot a$
        &
        $a + (-b) = a - b$
        &
        $a - (-b) = a + b$
    \end{longtable}
\end{center}