\section{Limits and Continuity}
If we want to differentiate, we need to make sense of a limit, so here goes.
\subsection{Limit of a function}
\begin{definition}
    Suppose $a\in\mathbb C$ and $f:\mathbb C\setminus\{a\}\to\mathbb C$.
    We say $\lim_{z\to a}f(z)=c\in\mathbb C$ if
    $$\forall\epsilon>0,\exists\delta>0,|z-a|<\delta\implies |f(z)-c|<\epsilon$$
    Sometimes we write $f(z)\to c$ as $z\to a$.
\end{definition}
We say $\lim_{z\to a}f(z)$ is undefined if there is no $c$ with $\lim_{z\to a}f(z)=c$.
\begin{proposition}
    If $\lim_{z\to a}f(z)=c$ and $\lim_{z\to a}f(z)=d$, then $c=d$.
\end{proposition}
\begin{proof}
    Trivial.
\end{proof}
\begin{example}
    1. If $f\equiv c$, then $\lim_{z\to a}f(z)=c$ for any $a$, just take for example $\delta=1$.\\
    2. If $f(z)=z$, then $\lim_{z\to a}f(z)=a$, as we can take $\delta=\epsilon$.\\
    3. If $f(z)=1_{\mathbb C\setminus\{0\}}$, then $\lim_{z\to 0}f(z)=1$, taking for example $\delta=1$.\\
    4. If
    $$f(z)=\begin{cases}
        1\text{, if $\operatorname{Re}(z)>0$}\\
        0\text{, if $\operatorname{Re}(z)=0$}\\
        -1\text{, if $\operatorname{Re}(z)<0$}
    \end{cases}$$
    then $\lim_{z\to 0}f(z)$ does not exist.\\
    5. If $f(z)=z^2$, then $\lim_{z\to a}f(z)=a^2=f(a)$ by choosing $\delta=\min\{\epsilon/(2|a|+1),1\}$.
\end{example}
\begin{proposition}
    $\lim_{z\to a}f(z)=c$ if and only if $\forall (z_n)\in\mathbb C$ with $z_n\to a$, we have $f(z_n)\to c$
\end{proposition}
\begin{proof}
    If the limit of the function is $c$, given $\epsilon>0$, we can find $\delta$ such that $|z-a|<\delta\implies |f(z)-c|<\epsilon$.
    Given a sequence $z_n\to a$, we can find $N\in\mathbb N$ such that $\forall n>N,|z_n-a|<\delta$, so using this $N$, $\forall n>N,|z_n-a|<\delta\implies |f(z_n)-c|<\epsilon$, so $f(z_n)\to c$.\\
    Conversely, if $c$ is not the limit of that function, then $\exists\epsilon>0,\forall\delta>0,\exists z\in\mathbb C,|z-a|<\delta,|f(z)-c|>\epsilon$.
    So we choose such $z_n$ for $\delta=1/n$, then $z_n\to a$ but $|f(z_n)-c|>\epsilon$ for any $n$, hence $f(z_n)$ does not tend to $c$.
\end{proof}
\begin{proposition}
    Let $f,g:\mathbb C\setminus\{a\}\to\mathbb C$, if $\lim_{z\to a}f(z)=c$ and $\lim_{z\to a}f(z)=d$, then\\
    1. $\lim_{z\to a}(f(z)+g(z))=c+d$.\\
    2. $\lim_{z\to a}f(z)g(z)=cd$.\\
    3. If $c\neq 0$, then $\lim_{z\to a}1/f(z)=1/c$.
\end{proposition}
\begin{proof}
    Using the preceding proposition and laws of limits for sequences.
\end{proof}
\begin{proposition}
    Suppose $f,g:\mathbb C\setminus\{a\}\to\mathbb R$ such that
    $$\lim_{z\to a}f(z)=c,\lim_{z\to a}g(z)=d$$
    then,\\
    1. If $\forall z,f(z)\ge g(z)$, then $c\ge d$.\\
    2. (Squeeze Rule) Let $h:\mathbb C\setminus\{a\}$ be such that $f\ge h\ge g$.
    Then if $c=d$, we have $\lim_{z\to a}h(z)=c$.
\end{proposition}
\begin{proof}
    Immediate.
\end{proof}
What if $f:A\to\mathbb C$ where $A$ is a subset of $\mathbb C$?
Does it still makes sense?
Does it change the limit?
The answer to the second question if obviously no.
But we can make sense of the limit.
\begin{definition}
    Suppose $A$ is a subset of $\mathbb C$.
    We say $a\in\mathbb C$ is a limit point of $A$, if $\forall\delta>0,\exists z\in A,0<|z-a|<\delta$.
\end{definition}
\begin{example}
    Any $a\in [0,\infty)$ is a limit point of $(0,\infty)$, and $\mathbb Z$ has no limit point.
\end{example}
\begin{definition}
    If $f:A\to\mathbb C$ and $a\in\mathbb C$ is a limit point of $A$, we say $\lim_{z\to a}f(z)=c$ if $\forall\epsilon>0,\exists\delta>0,z\in A,0<|z-a|<\delta\implies |f(z)-c|<\epsilon$.
\end{definition}
Equivalently, $f(z_n)\to c$ for any sequence $(z_n)\in A$ such that $z_n\to a$.
Also, it is also easy to show that the limit is unique.
\begin{definition}
    For $f:\mathbb R\to\mathbb R$, we define
    $$\lim_{x\to a^+}f(x)=\lim_{x\to a}f|_{(a,\infty)}(x),\lim_{x\to a^-}f(x)=\lim_{x\to a}f|_{(-\infty,a)}(x)$$
\end{definition}
\subsection{Continuity}
\begin{definition}
    Suppose $A\subset\mathbb C$, and $f:A\to\mathbb C$.
    We say $f$ is continuous at $a\in A$ if
    $$\forall\epsilon>0,\exists\delta>0,z\in A,|z-a|<\delta\implies |f(z)-f(a)|<\epsilon$$
\end{definition}
\begin{remark}
    $|f(a)-f(a)|=0<\epsilon$, so this condition is equivalent to say $|f(z)-f(z)|<\epsilon$ whenever $0<|z-a|<\delta$.
\end{remark}
\begin{proposition}
    Suppose $f:A\to\mathbb C$ and $a\in A$, then the following conditions are equivalent:\\
    1. $f$ is continuous at $a$.\\
    2. Either $a$ is not a limit point of $A$ or $\lim_{z\to a}f(z)=f(a)$.\\
    3. $f(z_n)\to f(a)$ whenever $z_n\to a$ is a sequence in $A$.
\end{proposition}
\begin{proof}
    Verify from definition.
\end{proof}
\begin{example}
    1. Constant functions are continuous at every point.
\end{example}
\begin{definition}
    We say $f:A\to\mathbb C$ is continuous if $f$ is continuous at every $a\in A$.
\end{definition}
\begin{definition}
    2. The identity function is continous.\\
    3. (non-example) $f:\mathbb R\to\mathbb R$ by $f=1_{\mathbb Q}$. is not continuous at any point.\\
    4. Consider $f:\mathbb R\to\mathbb R$ by
    $$f(x)=\begin{cases}
        1/q\text{, if $x$ is rational and $q=\min\{q\in\mathbb N:\exists p\in\mathbb Z,x=p/q\}$}\\
        0\text{, otherwise}
    \end{cases}$$
    Then $f$ is not continuous at any $x\in\mathbb Q\setminus\{0\}$ but it is continuous at $a\notin\mathbb Q$.\\
    5. $f:\mathbb R_{\ge 0}\to\mathbb R_{\ge 0}$ by $x\mapsto \sqrt{x}$ is continuous.
\end{definition}
\begin{proposition}
    Suppose $f,g:A\to\mathbb C$ for some $A\subset\mathbb C$ and they are both continuous at $a\in A$.
    Then $f+g,fg$ are continuous at $a$.
    And if $f(a)\neq 0$, then $1/f$ is continuous at $a$.
\end{proposition}
\begin{proof}
    Trivial.
\end{proof}
\begin{example}
    Everywhere in $\mathbb C$ we have any constant function is continous, the identity is continuous, hence any linear function is continuous, therefore any polynomial is continuous.
    Also any rational function is continuous at anywhere it is defined.
\end{example}
The function $\exp$ is continuous, but we will not prove it now.
\begin{proposition}
    Let $A,B,C\subset\mathbb C$ and $f:A\to B,g:B\to C$ such that $f$ is continuous at $a$ and $g$ continuous at $f(a)$, then $g\circ f$ is continuous at $a$.
\end{proposition}
\begin{proof}
    Straightforward.
\end{proof}
\begin{example}
    $g:(0,\infty)\to (0,\infty),g(x)=\sqrt{x}$ and $f:(0,\infty)\to(0,\infty),f(x)=x^2+1$, so $x\mapsto (g\circ f)(x)=\sqrt{x^2+1}$ is continuous.
\end{example}
\begin{lemma}
    Suppose $(x_n)$ is a sequence in $[a,b]$ and $x_n\to x\in\mathbb R$, then $x\in [a,b]$.
\end{lemma}
Note that this is false if we replace $[a,b]$ by $(a,b)$.
\begin{proof}
    Obvious.
\end{proof}
\begin{theorem}[Intermediate Value Theorem]
    If $f:[a,b]\to\mathbb R$ is continuous, and $f(a)\le0,f(b)\ge0$, then there is some $c\in [a,b]$ such that $f(c)=0$.
\end{theorem}
This is false for $\mathbb Q$.
\begin{remark}
    Note that it does not matter if it is $f(a)\le0,f(b)\ge0$ or $f(b)\le0,f(a)\ge0$.
    Also it suffices to show the case where the inequalities are both strict, so we will assume that in the proof.
\end{remark}
\begin{proof}
    For $n\in\mathbb N$, we define $Q_n=\{a+k(b-a)/n:0\le k\le n\}$ and $P_n\subset Q_n$ such that $\forall x\in P_n,f(x)\le 0$, so $P_n$ is never empty.
    Define $x_n=\max P_n$, then $a\le x_n\le b-(b-a)/n$ and $f(x_n)\le 0$.
    We let $y_n=x_n+(b-a)/n=\min Q_n\setminus P_n\subset [a,b]$, then by maximality of $x_n$ we have $f(y_n)>0$.
    By Bolzano-Weierstrass Theorem, there is a subsequence $x_{n_k}$ that converges to some $c\in [a,b]$ by the preceding lemma, so by continuity of $f$, $f(c)=\lim_{n\to\infty}f(x_n)\le 0$.
    Therefore $y_{n_k}\to c$ as well since $(b-a)/n_k\to 0$, but then $f(c)=\lim_{n\to\infty}f(y_n)\ge 0$.
    So $f(c)=0$.
\end{proof}
\begin{corollary}
    An odd degree polynomial has a root in $\mathbb R$.
\end{corollary}
\begin{proof}
    Immediate.
\end{proof}
\begin{corollary}
    If $f:[a,b]\to\mathbb R$ is continuous, and $f(a)=x,f(b)=y$, then for all $z$ in between $x,y$ there is some $c\in [a,b]$ such that $f(c)=z$.
\end{corollary}
\begin{proof}
    $g:x\mapsto x-z$ is continuous.
    Then apply the preceding theorem.
\end{proof}
\begin{theorem}
    Continuous function on bounded closed interval is bounded and attains its bounds.
\end{theorem}
Again it is not true in general for open intervals.
\begin{proof}
    Suffice to show this for upper bounds.
    Let $f:[a,b]\to\mathbb R$ be continuous.
    Let $A=f([a,b])$.
    Suppose $A$ is not bounded above, then $\forall n\in\mathbb N,\exists x_n\in[a,b],f(x_n)>n$.
    Then choose a convergent subsequence $(x_{n_k})$ of $(x_n)$, then $x_{n_k}\to x\in [a,b]$, but by continuity $f(x)=\lim_{k\to\infty}f(x_k)\ge\lim_{k\to\infty}n_k\to\infty$, contradiction.\\
    Now that $A$ is bounded above, we choose $M=\sup A$, then $\forall n\in\mathbb N$, we can choose $x_n\in [a,b]$ such that $M-1/n<x_n\le M$.
    Choose a convergent subsequence $x_{n_k}\to x\in [a,b]$, then continuity tells us that $f(x)=\lim_{k\to\infty}f(x_{n_k})$ which is bounded by $M-1/n_k,M$, hence $f(x)=M$ by Squeeze rule.
\end{proof}


\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{url}
\title{Smooth Autonomous Paths on Tank Drive using Splines}
\date{Spring 2018}
\author{Lyra Solomon, Citrus Circuits}
\begin{document}
\maketitle

\section{Why Splines?}
Getting from point to point efficiently is key to writing an effective autonomous routine.
Before using splines, we designed our paths by sequencing semicircles. This has two primary
issues. Most visibly, where each drive action ends up depends on where it started, so a
change near the beginning of a routine means the entire rest of the routine has to be retuned.
Less visibly, the transition between semicircles is imperfect because angular velocity is
not continuous. This year, we began using splines, or two-dimensional polynomials, to define
smooth curves between arbitrary states. This allowed us to do more in autonomous by getting
around more efficiently and tuning faster.

\section{Notation Used in this Paper}
\paragraph{$a_{\bot b}$} The rejection of $a$ onto $b$, $a-a_{\parallel b}$.
\paragraph{$a_{\parallel b}$} The projection of $a$ onto $b$, $(a \cdot \hat{b}) \hat{b}$.
\paragraph{$\hat{a}$} The unit vector in the direction of $a$, $\frac{a}{\lvert a \rvert}$.
\paragraph{$a^\bot$} The perpendicular of $a$, $\begin{bmatrix} -a_1 \\ a_0 \end{bmatrix}$.
\paragraph{$A^+$} The pseudoinverse of A.
\paragraph{$\mathrm{cap}$} A function to ensure a value is in a given range,
$\mathrm{cap}(x, min, max) = \mathrm{min}(max, \mathrm{max}(min, x))$.

\section{Definitions of Symbols}
\paragraph{$d_0, d_f: \mathbb{R}$} The additional mostly straight initial and final distances,
specified by the user to avoid obstacles or better handle nonzero $\omega_0$ and $\omega_f$.
\paragraph{$k: \mathbb{R}_+$} The approximate curvature of the path.
\paragraph{$k_r: \mathbb{R}_+$} The radius of the wheel base, half the distance between left and right wheels.
\paragraph{$r(s): [0,1] \rightarrow \mathbb{R}^2$} A curve which defines the shape of the path.
$s$ is an arbitrary variable that doesn't correspond exactly to time.
\paragraph{$\Delta r: \mathbb{R}^2$} The total displacement $r(1)-r(0)$.
\paragraph{$v_0, v_f: \mathbb{R}$} The initial and final velocity of the robot.
\paragraph{$\omega_0, \omega_f: \mathbb{R}$} The initial and final angular velocity of the robot.
\paragraph{$u_{cap}: \mathbb{R}_+$} The maximum voltage for feedforward control.
Should be less than the battery voltage to allow feedback corrections.
\paragraph{$a_{cap}: \mathbb{R}_+$} The maximum acceleration. This is limited since
reversing direction at full power would result in the robot tipping or skidding.

\section{Paths}
The path the robot must follow is defined by six constraints - the initial and final position,
tangent (which closely corresponds to velocity), and normal (which closely corresponds to acceleration).
Therefore, the path must be a fifth-degree polynomial since that is the minimum degree with six coefficients.
Since $r(s)=a_0+a_1s+a_2s^2+a_3s^3+a_4s^4+a_5s^5$, the constraints are
$r(0)=a_0$, $r'(0)=a_1$, $r''(0)=2a_2$, $r(1)=a_0+a_1+a_2+a_3+a_4+a_5$,
$r'(1)=a_1+2a_2+3a_3+4a_4+5a_5$, and $r''(1)=2a_2+6a_3+12a_4+20a_5$. Solving for the coefficients in
terms of the constraints yields the following equation for $r(s)$:
\begin{align}
\notag r(s)=&r(0)+\\
\notag      &r'(0) \cdot s+\\
\notag      &\frac{1}{2}r''(0) \cdot s^2+\\
\notag      &(-10r(0)-6r'(0)-\frac{3}{2}r''(0)+\frac{1}{2}r''(1)-4r'(1)+10r(1)) \cdot s^3+\\
\notag      &(15r(0)+8r'(0)+\frac{3}{2}r''(0)-r''(1)+7r'(1)-15r(1)) \cdot s^4+\\
            &(-6r(0)-3r'(0)-\frac{1}{2}r''(0)+\frac{1}{2}r''(1)-3r'(1)+6r(1)) \cdot s^5
\end{align}

The positions $r(0)$ and $r(1)$ are two-dimensional vectors representing the initial and final position of the robot, respectively.

The tangents $r'(0)$ and $r'(1)$ are used primarily to define the shape of the curve.
They are two-dimensional vectors with direction defined by the robot's heading. Usually, their magnitude
is set to the endpoint-to-endpoint length of the curve. This has the advantage of being very predictable,
since scaling the endpoints simply scales the curve, and being very quick to drive if the robot starts and
ends from rest. However, if the robot has a high enough initial or final velocity, the path will curve too
quickly for the robot to follow. To fix this, we add an estimate of the extra stopping distance, $\frac{1}{2}v^2k^2$,
where $k$ is the estimated curvature.
\begin{equation}
k = \frac{2 \cdot \lvert \Delta r_{\bot r'(0)} \rvert - \Delta r_{\bot r'(0)} \widehat{\cdot r'(1)}}{\lvert \Delta r \rvert}
\end{equation}
This estimates the curvature by taking twice the sideways distance minus the amount of sideways distance accounted for
by ending at a different angle, as a proportion of the total distance. An additional value is added by the
user if necessary to extend one end of the curve to avoid an obstacle. Experimentally, it was found that to
drive mostly straight for an additional distance $d$, approximately $5d$ should be added to the tangent.
The complete equation for $r'(0)$ is as follows ($r'(1)$ works the same way):
\begin{equation}
r'(0)=(\lvert \Delta r \rvert + \frac{1}{2}v_0^2k^2 + 5d_0) \cdot \widehat{r'(0)}
\end{equation}

The normals $r''(0)$ and $r''(1)$ are used to ensure that the angular angular velocity at the endpoints is correct.
The equations $a=v^2/r$ and $r=v/\omega$ give the following equation for $r''(0)$ ($r''(1)$ works the same way):
\begin{equation}
r''(0)=r'(0)^\bot \cdot \lvert r'(0) \rvert \cdot \frac{\omega_0}{v_0}
\end{equation}

\section{Reparameterization}
For the robot to follow the path, it must be given position and velocity as a function of time. First,
the polynomial is broken into a finite list of samples containing x, y, and heading at $s=0,\frac{1}{n},\hdots,\frac{n-1}{n}$.
From this, the drivetrain state is calculated at each sample using the following equations:
\begin{align}
\Delta x_{l,i} &= \Delta r_i \cdot T_i - k_r \Delta \theta_i \\
\Delta x_{r,i} &= \Delta r_i \cdot T_i + k_r \Delta \theta_i
\end{align}
where $T$ is the unit tangent vector at the first sample and $k_r$ is the radius of the wheel base.

Two passes are needed to find the point in time at which each sample occurs - one which steps
forwards using the maximum acceleration, and one which steps backwards using the maximum
deceleration.

The robot is assumed to follow the state-space equation $\dot{x}=Ax+Bu$. On each pass,
the holding voltage $V_{holding}=-B^+Ax$ is calculated at each sample. On the forwards
pass, this is subtracted from the minimum and maximum voltage to give the amount of voltage
available for acceleration. On the backwards pass, it is added instead, since the output
state occurs before the input state.

\begin{align}
u_{max} &= \begin{bmatrix}  u_{cap} \\  u_{cap} \end{bmatrix} - B^+Ax * \mathrm{time direction} \\
u_{min} &= \begin{bmatrix} -u_{cap} \\ -u_{cap} \end{bmatrix} - B^+Ax * \mathrm{time direction}
\end{align}

For each side of the drivetrain, the maximum acceleration is calculated. In most cases,
the segment can be approximated as an arc, in which the acceleration on each side is
proportional to the segment length. However, this approximation fails when one side needs
to travel much further than the other. In that case, when computing the acceleration
for the shorter side, treat the other side as being shorter than it is. A reasonable cutoff
is to cap the opposite side at three times the length. From the acceleration ratio, the
voltage ratio is calculated to find the maximum.

\begin{equation}
u_{accel} = B^+ \begin{bmatrix} a_{same} \\ a_{opposite} \end{bmatrix}k
\end{equation}
$u_{accel,max}:$ select largest $k$ such that no component of $u_{accel}$ is greater than its matching component in $u_{max}$. \\
$u_{accel,min}:$ select smallest $k$ such that no component of $u_{accel}$ is less than its matching component in $u_{max}$.

When the distance is forwards, select the maximum acceleration, when the distance is backwards,
select the minimum acceleration. In either of these cases,
$a = \mathrm{cap}(Bu_{accel}, -a_{cap}, a_{cap})$, and
$v_f = \sqrt{v_0^2+2ad}$, but with the sign set to that of the $d$.

In the case that the direction changes, take the next distance as well and assume the samples
are evenly spaced in time, forming a quadratic equation where $x(0)=0$, $x(1)=d_1$, and $x(2)=d_1+d_2$,
$x(s)=\frac{d_2-d_1}{2}s^2+ks$.
If the total time from $s=0$ to $s=2$ is $T$,
$x(t)=2\frac{d_2-d_1}{T^2}t^2+kt$ and $a=4\frac{d_2-d_1}{T^2}$.
Selecting $a=a_{cap}$ and solving gives $T=2\sqrt{\frac{d_2-d_1}{a}}$,
and $v_f=v(\frac{T}{2})=\frac{d_2+d_1}{T}$.

Due to approximations and capping, the two velocities may not agree. The time each
side of the drivetrain requires is calculated as $t=\frac{2d}{v_0+v_f}$. The time
required for the segment is $\mathrm{max}(t_l, t_r)$, unless one side crosses $v=0$
during that segment, in which case the time from the other side is used to prevent
possible floating point precision issues. The final velocity for each side is
multiplied by $\frac{t_{side}}{t}$ so both sides are balanced. The balancing is done
on the final velocity instead of the average velocity to prevent errors from passed
on to the next segment.

\section{Interpolation}
The times that the robot needs to know the goal state are not the same as the sample times.
Because of this, the goal state must be calculated from the nearest samples. We maintain the
index of the segment the robot is currently following, and the time elapsed since the robot began
that segment. When the time elapsed exceeds the segment time, the time elapsed is decreased
by that amount and the index is incremented. The path is considered complete when the segment
index is equal to the number of segments.

The goal position and velocity follow the equations $x=x_i+v_it+\frac{1}{2}a^2$ and $v=v_i+at$,
where $x_i$ and $v_i$ come from the sample at the start of the segment, $t$ is the time elapsed
in the current segment, and $a=\frac{v_{i+1}-v_i}{t_i}$, where $v_{i+1}$ comes from the sample
at the end of the segment and $t_i$ is the segment time.

The goal angle $\theta=\omega t$, where $\omega=\frac{\theta_{i+1}-\theta_i}{t_i}$.

The goal Cartesian position has $p_x=p_{x,i}+d\frac{cos{\theta}+cos{\theta_i}}{2}$
and $p_y=p_{y,i}+d\frac{sin{\theta}+sin{\theta_i}}{2}$, where the distance traveled this segment
$d=\frac{x_l+x_r-x_{l,i}-x_{r,i}}{2}$.

\section{Implementation}
Our implementation of splines is in the directory \path{/third_party/frc971/control_loops/paths/}
of our robot code repository. The files \path{path.*} contain the implementation of the paths
section, and the files \path{trajectory.*} contain the implementation of the reparameterization
and interpolation sections.

When implementing or modifying spline code, important edge cases to test are driving backwards
and turns sharp enough that one side needs to reverse direction.
\end{document}


\chapter{Quadrilateral Quality Metrics}

All the metrics in this section are defined on a quadrilateral element with vertices
shown in Figure~\ref{f:quad}. Furthermore, we define the following edge vectors for
convenience. Note that each edge has two versions, one defined by its endpoints and
another indexed by sequential integers:
\begin{equation*}
\begin{array}{lcl}
\vec L_0 &=& \vec P_1 - \vec P_0\\
\vec L_1 &=& \vec P_2 - \vec P_1\\
\vec L_2 &=& \vec P_3 - \vec P_2\\
\vec L_3 &=& \vec P_0 - \vec P_3
\end{array}\rule{10em}{0pt}
\begin{array}{lcl}
\vec L_{01} &=& \vec P_1 - \vec P_0\\
\vec L_{12} &=& \vec P_2 - \vec P_1\\
\vec L_{23} &=& \vec P_3 - \vec P_2\\
\vec L_{30} &=& \vec P_0 - \vec P_3.
\end{array}
\end{equation*}

The quadrangle edge lengths are denoted as follows:
\[
L_0 = \normvec{L_0}\quad
L_1 = \normvec{L_1}\quad
L_2 = \normvec{L_2}\quad
L_3 = \normvec{L_3}
\]
and the largest and smallest edge lenghts are, respectively,
\[
L_{\min} = \min\left(L_0, L_1, L_2, L_3\right)
  \rule{2em}{0pt}
L_{\max} = \max\left(L_0, L_1, L_2, L_3\right)
\]

The diagonals of a quadrilateral are denoted
\begin{equation*}
\begin{array}{lcl}
\vec D_0 &=& \vec P_2 - \vec P_0
\end{array}\rule{10em}{0pt}
\begin{array}{lcl}
\vec D_1 &=& \vec P_3 - \vec P_1
\end{array}
\end{equation*}
and the longest diagonal has length
\[
D_{\max} = \max\left\{ \normvec{D_0}, \normvec{D_1} \right\}.
\]

\begin{figure}[htb]
  \centering
  \subfigure[Vertices of a quadrilateral.]{\includegraphics[width=2in]{quad}}
  \subfigure[Principal axis vectors.]{\includegraphics[width=2in]{quad-axes}}
  \caption{A quadrilateral showing notation used in metric definitions.%
                                                                  \label{f:quad}}
\end{figure}

The principal axes are
\begin{equation*}
\begin{array}{lcl}
\vec X_1 &=& \left(\vec P_1 - \vec P_0\right) + \left(\vec P_2 - \vec P_3\right)\\
\vec X_2 &=& \left(\vec P_2 - \vec P_1\right) + \left(\vec P_3 - \vec P_0\right)
\end{array}
\end{equation*}
and the cross derivatives of the map from parametric to world space are oriented along
\begin{equation*}
\begin{array}{lcl}
\vec X_{12} &=& \left(\vec P_0 - \vec P_1\right) + \left(\vec P_2 - \vec P_3\right) =\\
\vec X_{21} &=& \left(\vec P_0 - \vec P_3\right) + \left(\vec P_2 - \vec P_1\right).
\end{array}
\end{equation*}

Each corner has a normal vector associated with it
\begin{equation*}
\begin{array}{lcl}
\vec N_0 &=& \vec L_3 \times \vec L_0\\
\vec N_1 &=& \vec L_0 \times \vec L_1
\end{array}
\rule{10em}{0pt}
\begin{array}{lcl}
\vec N_2 &=& \vec L_1 \times \vec L_2\\
\vec N_3 &=& \vec L_2 \times \vec L_3
\end{array}
\end{equation*}
and these vectors can be normalized to unit length:
\begin{equation*}
\begin{array}{lcl}
\hat n_0 &=& \dfrac{\vec N_0}{\normvec{ N_0}}\\
\hat n_1 &=& \dfrac{\vec N_1}{\normvec{ N_1}}
\end{array}
\rule{10em}{0pt}
\begin{array}{lcl}
\hat n_2 = \dfrac{\vec N_2}{\normvec{ N_2}}\\
\hat n_3 = \dfrac{\vec N_3}{\normvec{ N_3}}.
\end{array}
\end{equation*}

In addition to corner normals, we can define a ``center'' normal
\begin{equation*}
\vec N_{c} = \vec X_1 \times \vec X_2
\end{equation*}
and its unit-length companion
\begin{equation*}
\hat n_{c} = \frac{\vec N_{c}}{\normvec{ N_{c}}}
\end{equation*}
In the event that the vertices of the quadrilateral are all
contained in the same plane, all the unit normals will be
equivalent (i.e., $\hat n_0 = \hat n_1 = \hat n_2 = \hat n_3 = \hat n_c$).

\begin{figure}[htb]
  \centering
  \includegraphics[width=2in]{quad-vertex-areas}
  \caption{Areas associated with each quadrilateral vertex.%
                                                    \label{f:quad-vertex-areas}}
\end{figure}

It is often useful to partition the quadrilateral into four areas, one
associated with each vertex. These areas are denoted
\begin{equation*}
\alpha_k = \hat n_c \cdot \vec N_k\rule{10em}{0pt}\forall k\in\{0,1,2,3\}
\end{equation*}
and are shown in Figure~\ref{f:quad-vertex-areas}.
If $\vec N_c = \vec 0$, then the signed corner areas are undefined,
and all the metrics which depend on $\alpha_k$ are undefined.
In this case, we set $\alpha_k = 0$ for $k=0,1,2,3$.
When $\alpha_k \leq 0$ for any one or more $k$, the quadrilateral
is degenerate.
This occurs when
an element is so small its edge length approach the machine epsilon or
when its vertices are collinear or
when its vertices define a concave quadrilateral.

% -------------------Metric Table-------------------
\newcommand{\quadmetrictable}[8]{%
  \begin{center}
  \begin{tabular}{ll}
    \multicolumn{2}{r}{\textbf{\sffamily\Large quadrilateral #1}}\\\hline
    Dimension:             & #2\\
    Acceptable Range:      & #3\\
    Normal Range:          & #4\\
    Full Range:            & #5\\
    $q$ for unit square:   & #6\\
    Reference:             & #7\\
    \verd\ function:       & \texttt{#8}\\ \hline
  \end{tabular}
  \end{center}
}

\newpage \input{QuadArea}
\newpage \input{QuadAspectRatio}
\newpage \input{QuadCondition}
\newpage \input{QuadDistortion}
\newpage \input{QuadEdgeRatio}
\newpage \input{QuadJacobian}
\newpage \input{QuadMaxAspectFrobenius}
\newpage \input{QuadMaximumAngle}
\newpage \input{QuadMaximumEdgeRatio}
\newpage \input{QuadMedAspectFrobenius}
\newpage \input{QuadMinimumAngle}
\newpage \input{QuadOddy}
\newpage \input{QuadRadiusRatio}
\newpage \input{QuadRelativeSizeSquared}
\newpage \input{QuadScaledJacobian}
\newpage \input{QuadShape}
\newpage \input{QuadShapeAndSize}
\newpage \input{QuadShear}
\newpage \input{QuadShearAndSize}
\newpage \input{QuadSkew}
\newpage \input{QuadStretch}
\newpage \input{QuadTaper}
\newpage \input{QuadWarpage}


\section{Linear Spectral Clustering Superpixel}

\begin{flushleft}
    \author{
    Jiansheng Chen,
    \emph{Member, IEEE},
    Zhengqin Li,
    \emph{Student Member, IEEE},
    Bo Huang
}
\end{flushleft}

\begin{center}
    \emph{IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 26, NO. 7, JULY 2017}
\end{center}

\subsection{INTRODUCTION}
The introduced technique is called SUPERPIXEL. Widely used in image
processing for particular tasks such as image segmentation, image analysis,
image classification, target tracking, 3D reconstruction, surface retrieval and
object proposal. The purpose of this technique is to be able to group the
pixels into groups that delimit the edges of an object in order to be able
to extract its content. Compared to other methods already existing in the
state of the art, characteristics such as size, number of superpixels and shape
are not considered. The purpose of the elaborate story is to reduce the
computational complexity. The three targets that must be satisfied by each
superpixel algorithm are:
\begin{enumerate}
    \item Adhere well to the edges without forming overlaps on objects;
    \item Have a pre-processing technique useful to improve efficiency;
    \item Consider global information.
\end{enumerate}
The proposed system, called Linear Spectral Clustering (LSC), manages to
satisfy all the previous points with a high memory efficiency. In LSC, each
pixel is mapped to a point within a ten-dimensional space of characteristics
in which the weighted K-means is applied for segmentation.

\subsection{LSC SUPERPIXEL}
The study focuses on the relationships between the results returned by the
optimization functions, and those returned by two other equations. If the results
are equivalent, then weighted k-means clustering can replace the highly
complex eigen based method.

\subsubsection{Mathematical Backgrounds}
The task of LSC is to discover the relationships that exist between the objective
functions ($ F_{N_{cuts}} $) (\ref{FNcuts}), of the normalized cuts, and the objective functions
of the weighted K-means ($ F_{km}$) (\ref{Fkm}).
\begin{equation} \label{Fkm}
    F_{km} = \sum_{k=1}^K\sum_{p\in\pi_k}\omega(p)= || \phi(p)-m_k ||^2
\end{equation}
\begin{equation} \label{Centroid}
    m_k = \frac{\sum_{q\in\pi_k}\omega(q)\phi(q)}{\sum_{q\in\pi_k}\omega(q)}
\end{equation}
\begin{equation} \label{FNcuts}
    F_{N_{cuts}} = \frac{1}{K}\sum_{k=1}^K\frac{\sum_{p\in\pi_k}\sum_{q\in\pi_k}W(p,q)}{\sum_{p\in\pi_k}\sum_{q\in{V}}W(p,q)}
\end{equation}
Where $ m_k $ (\ref{Centroid}) represent the average point, or centroid, of each cluster. Within
the formulation of normalized cuts, each data Point corresponds to a node
within a graph \emph{G = (V, E, W)} where \emph{V} is the set of all nodes, \emph{E} represents
the set of all edges connected and \emph{W} represents the result returned by a
similarity function between nodes. The criterion of normalized cuts is based
on maximizing the $ F_{N_{cuts}} $ function. The minimization or maximization problems
are called \emph{optimization problems} which can be solved by using a positive kernel of
a matrix. To see the relationship between the two functions, the Dhillon's concept \cite{0781426526} is extended, to obtain {\bfseries Corollary \ref{Corollary1}}:

\begin{corollary} \label{Corollary1}
    Optimizations of the objective functions of the weighted K-means
    and the normalized cuts are mathematically equivalent if (\ref{eq4}) and (\ref{eq5})
    hold simultaneously. The symbol $ \cdot $ stands for inner product.
\end{corollary}

\begin{equation} \label{eq4}
    \omega(p)\phi(p) \cdot \omega(q)\phi(q) = W(p,q), \forall p,q \in V
\end{equation}

\begin{equation} \label{eq5}
    w(p) = \sum_{q \in V} W(p,q), \forall p \in V
\end{equation}

After making various derivative calculations, $ F_{km} $ can be seen as:
\begin{equation}
    F_{km} = C - K * F_{N_{cuts}}
\end{equation}

From the above definition it is possible to note that the minimization of
$ F_{km} $ is equivalent to the maximization of $ F_{N_{cuts}} $. Specifically, both $ F_{km} $ and
$ F_{km} $ perform an identical partitioning of the n-dimensional space defined by
the function $ \phi $.

\subsubsection{LSC Algorithm}
The purpose of LSC is to find the correct positive function W (p, q) in order
to satisfy {\emph{Corollary \ref{Corollary1}}}. To achieve this, the Euclidean distance calculation
was used as an index of similarity between two pixels. Each pixel \emph{p} is represented
by five dimensional vectors \emph{(l, a, b, x, y)} in the CIELAB color space, where \emph{l}
epresents brightness, \emph{a} and \emph{b} represent opposite colors and \emph{x} and \emph{y} represent
the coordinates of the plane. The similarity function, in order to satisfy
the positivity condition required by (\ref{eq4}), is extended as a convergent Fourier series:
\begin{eqnarray}
    W(p,q) & = & C_s^2(\cos \frac{\pi}{2}(x_p-x_q)+\cos\frac{\pi}{2}(y_p-y_q)) \nonumber \\
           &   &  + C_c^2(\cos \frac{\pi}{2}(l_p-l_q)+\cos\frac{\pi}{2}(\alpha_p-\alpha_q) \nonumber \\
           &   &  + \cos\frac{\pi}{2}(\beta_p-\beta_q)x2.55^2)
\end{eqnarray}

Where $ C_s $ and $ C_c $ are used to control the relative significance of
color and spatial information. The mapping function that maps a point in a ten-dimensional
space is as follows:
\begin{equation}
    \begin{split}
        \phi(p) = \frac{1}{\omega(p)}[C_c\cos\frac{\pi}{2}l_p, C_c\sin\frac{\pi}{2}l_p, 2.55C_c\cos\frac{\pi}{2}\alpha_p \\
        x 2.55C_c\sin\frac{\pi}{2}\alpha_p, 2.55C_c\cos\frac{\pi}{2}\beta_p, 2.55C_c\sin\frac{\pi}{2}\alpha_p, \\
        x C_s\cos\frac{\pi}{2}x_p, C_s\sin\frac{\pi}{2}x_p, C_s\cos\frac{\pi}{2}y_p, C_s\sin\frac{\pi}{2}x_p]
    \end{split}
\end{equation}
In the defined space, the weighted K-mean clustering as well as being
equivalent to the Fncuts optimization function, creates the optimal context to
optimize it. The LCS algorithm takes two parameters as input; The image
to be segmented and the preferred K number of superpixels that the
algorithm will have to produce. Each \emph{K} pixel represents the central search point
and its vector will be used as the weighted initial vector of the corresponding
cluster. Each pixel is assigned to te cluster for which the weightedd mean
is closet to the picel's vector in the ten-dimensional feature space. At each
assignment, the weighted average and the central point will be updated until
the system convergence. Each cluster will form a superpixel and each of
these, if considered spatially small, can be joined to other clusters to form
a larger cluster. The total complexity achieved by LSC is \emph{O(kN + nZ)}, where
\emph{k} represents the number of iterations, \emph{N} the number of pixels, \emph{n} the average
number of adjacent neighbors and \emph{z} represents the number of small
isolated superpixels to be joined. This complexity, when compared with that
achieved by other superpixel systems, is the lowest.

\subsection{COMPARATIVE EXPERIMENTS}
In order to evaluate the quantitative goodness of the proposed algorithm,
three comparison metrics are used: under segmentation error (\emph{UE}) \cite{0781426514}, boundary
recall (\emph{BR}) and achievable segmentation accuracy (\emph{ASA}). The
goal is to have a low UE value, while it is preferable to have high values in BR
and ASA. A low percentage of UE indicates that the detected boundary is made
up of a small amount of pixels not belonging to the object to be delimited.
A segmentation is correct when at least two boundary pixel fall from at least
one superpixel boundary point. A high BR index indicates that the better
segmentation is obtained. On the other hand, the ASA metric indicates the
level of accurancy achieved in the segmentation pashe of contour, obtained
thanks to the various labels (ground-truth) placed on each superpixel. A
high ASA value indicates that superpixel adapt well to objects. The experiments
were conducted on a set of 300 images belonging to the Barkeley
Segmentation Database \cite{0781426515}.

\subsubsection{Parameter Selection}
When the ratio $ r = C_s / C_c $ is high, then the neighboring pixels tend to be
aggregated into a single cluster, forming superpixels with a regular shape
and therefore potentially incorrect. On the other hand, when \emph{r} is small,
then it means that the pixels tend to have similar colors, therefore both
will be grouped into a single cluster, forming irregular superpixels. In order to
choose an optimal r value, it is necessary to introduce a metric that calculates
the average  values of shape regularity. The average value of shape regularity
is measured with a metric called superpixel compactness \emph{(CP)} \cite{0781426533} which is
inversely proportional to the BR index. So as CP increases, the likelihood
of regular shapes being created is greater and at the same time worse segmentation
will be generated as BR decreases. The r value will be chosen
when the value resulting from $ (1-BR / CP) $ is the lowest. Therefore \emph{r} can be
used as a correction parameter. In order to control the search range of the
K-means cluster algorithm, a $ \tau $ parameter is used which is equal to at least
0.5. This value will be multiplied by the spatial components, vertical ($ v_x $)
and horizontal ($ v_y $), of the vector belonging to each point in space. Clearly,
as this parameter increases, the size of each superpixel generated and the
general $ O(N) $ complexity will increase. In the experiments conducted, $ \tau $ is
set to 1.

\subsubsection{Comparison With State-of-the-Art}
The proposed system is compared with other existing superpixels algorithms
in the state of the art. A comparison, in terms of boundary adherence and
speed in segmentation (Table \ref{table superpixels}), when the number of superpixels \emph{K} generated
is 400. With a relatively high \emph{K} number, LSC achieves the best
performance.

\begin{table}[h!]
    \centering
    \begin{adjustbox}{max width=\textwidth}
    \begin{tabular}{*{9}{|c}|}%%{|c|c|c|c|c|c|c|c|c|}
        \hline
        & EneOpt0 & SEEDS & ERS & Lattices & NCuts & SLIC & Turbo & LSC \\
        \hline
        \bfseries{ADERENCE TO BOUNDARY} & & & & & & & & \\
        \emph{Under segmentation error} & 0.230 & 0.197 & 0.198 & 0.303 & 0.220 & 0.213 & 0.277 & \bfseries{0.190}\\
        \emph{Boundary recall} & 0.765 & 0.918 & 0.920 & 0.811 & 0.789 & 0.837 & 0.739 & \bfseries{0.926}\\
        \emph{Achievable segmentation accuracy} & 0.950 & 0.960 & 0.959 & 0.933 & 0.956 & 0.956 & 0.943 & \bfseries{0.962}\\
        \hline
        \bfseries{SEGMENTATION SPEED} & & & & & & & & \\
        \emph{Computational complexity} & $ O(N^3/K^2) $ & $ O(N) $ & $ O(N^2 \lg{N}) $ & $ O(N^{\frac{3}{2}} \lg{N}) $ & $ O(N^{\frac{3}{2}}) $ & $ O(N) $ & $ O(N) $ & $ O(N) $\\
        \emph{Average time per image} & 3.35s & \bfseries{0.0935}s & 0.969s & 0.284s & 93.4s & 0.125s & 6.61s & 0.334s\\
        \hline
    \end{tabular}
    \end{adjustbox}
    \caption{Performance metrics superpixel segmentation algorithms at K=400}
    \label{table superpixels}
\end{table}
As we can see from the results, the worst algorithm, in terms of time,
is \emph{NCuts}, while a good algorithm, which ranks second before \emph{LSC}, is \emph{SLIC}.
Unlike the algorithm studied, SLIC uses an iterative K-means clustering
performed inside different feature spaces, based only on local characteristics.
On the other hand, LSC is able to use local and global features thanks to the
$ \phi $  mapping function, all to have a better segmentation. However, when
K = 400, the CP value of the \emph{ERS} \cite{0781426508} and \emph{SEEDS} \cite{0781426509} algorithms are 0.151
and 0.280 respectively, while the CP value of LSC is 0.366. Looking at the data
in the table, this makes us understand how LSC is able to have a better BR
value despite having a higher CP value than the previous algorithms, this
represents the strength of this algorithm.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 1 \linewidth]{images/paper2/superpixelsComparison.png}
    \centering
    \caption{Superpixel results from different algorithms. (a) SEEDS. (b) NCuts. (c) SLIC. (d) ERS. (e) LSC.}
    \label{fig: superpixelsComparison}
\end{figure}

\subsection{APPLICATIONS}
\subsubsection{Class Segmentation}
An SVM-based multi-class object classifier trained on the histograms of the generated
superpixels was used. In order for similar superpixels to have the same
label, a conditional random field (CRF) is used to refine the segmentation.
Thanks to this model, the prediction made by the classifier will also
take into account the neighbors superpixels to the one to be labeled. The
method used is that proposed in \cite{0781426534} where the main unit of measurement is
that of the superpixel. In \cite{0781426534} the quick shift (\emph{QS}) algorithm is used for the
generation of superpixels. The experiments were conducted on the \emph{Graz-02}
database \cite{0781426535} containing already labeled objects. The accuracy achieved by
the QS, ERS, SLIC and LSC algorithms is that shown in the Table \ref{table accuracy}, while
the various segmentations, obtained from each of these, are visible in the
figure \ref{fig: superpixelSegmentation}. As you can see, LSC performs a better segmentation than the other
methods, this happens because the information obtained from the histograms
belonging to the SIFT of different superpixel generated are used. In this way
there is a better adherence to the boundary of each object in addition the
superpixels take on a highly irregular shape for objects in the foreground and
more regular for the background.
\begin{table}[h!]
    \centering
    \begin{adjustbox}{max width=\textwidth}
    \begin{tabular}{*{5}{|c}|}%%{|c|c|c|c|c|}
        \hline
        & QS & ERS & SLIC & LSC\\
        \hline
        bike & 72.2 & 74.2 & 76.3 & \bfseries{76.9}\\
        cars & 72.2 & 74.7 & 72.5 & \bfseries{76.8}\\
        person & 66.3 & 66.5 & 66.7 & \bfseries{67.0}\\
        \hline
    \end{tabular}
    \end{adjustbox}
    \caption{Accuracy using different superpixels algorithms.}
    \label{table accuracy}
\end{table}

\begin{figure}[htbp]
    \centering
    \includegraphics[width = 1 \linewidth]{images/paper2/superpixelAlgo.png}
    \centering
    \caption{Segmentation using different superpixels algorithms. (a) Original Image. (b) QS. (c) ERS. (d) SLIC. (e) LSC. (f)Ground Truth.}
    \label{fig: superpixelSegmentation}
\end{figure}

\subsubsection{Weakly Supervised Semantic Segmentation}
\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.6 \linewidth]{images/paper2/semanticSegmentation.png}
    \centering
    \caption{Weakly supervised semantic segmentation. (a) A training image with bounding boxes. (b) Output of soft-max layer of $ FCN_c $. (c) Coarse semantic segmentation result. (d) Superpixels with higher probability of foreground. (e) Fore-/Background segmentation result after iterative optimization. (f) Refined semantic segmentation result.}
    \label{fig: flowchartSemanticSegmentation}
\end{figure}
As the title suggests, the LSC algorithm is able to improve semantic segmentation
with a weakly supervised method. The images of the PASCAL
VOC2012 database \cite{0781426538} are used as tests, in which there are 1449 images
containing labeled objects and the remaining 10582 images containing only
bounding boxes used for training and validation. The flow chart of the proposed
method can be seen in figure (\ref{fig: flowchartSemanticSegmentation}). The steps are as follows: coarse
semantic segmentation, fore-/background segmentation and refined semantic
segmentation. In the first step there is a completely convolutional network,
called $ FCN_c $, trained with images containing only the bounding boxes which
will be restricted in order to eliminate the border pixels that seem to be
irrelevant. These new squares are used as positive examples, while the cut
parts are used as negative examples. For each superpixel \emph{p} generated within
each bounding box $ i_{th} $, we set $ c_p^i $ as the average value of the colors of each
pixel within the superpixel and then we set $ l_p^i $ as the label to be estimated (0
backgroud, 1 foreground). The separation of the background from the
foreground is seen as an optimization problem
\begin{equation}
    \begin{split}
        \argmax\limits_{l} \sum_i\sum_p(E_a(l_p^i,c_p^i) + \lambda_1E_c(l_p^i, FCN_c)\\
        + \lambda_2\sum_{q\in N(p)}E_s(l_p^i,c_p^i,l_q^i,c_q^i))
    \end{split}
\end{equation}
Where $ E_s $ is useful for capturing the smoothness prior produced by a covariance
matrix, $ E_c $ represents the probability that the superpixel belongs
to the foreground, while $ E_a $, also called the appearance model, represents
the probability that a superpixel belongs to the background or foreground.
After several iterations, which have the purpose of updating the foreground
and background labels of the superpixels, a correct segmentation will be
obtained. The segmentation obtained will be used to train a convolutional
network called $ FCN_r $ which is combined with a dense CRF model useful for
formulating the final semantic segmentation model. This system is also
called $ Joint_{sp} $. The model is compared with other supervivided methods \cite{0781426541},
a strong one, called \emph{Strong}, and a weak one called \emph{Bbox-seg}, the results of
which can be seen in figure \ref{fig: semanticSegmentation}. While the accuracy, measured with the intersection
over-union (\emph{IOU}), achieved by the systems mentioned is visible in the
table \ref{table accuracy semantic segmentation}.

\begin{figure}[htbp]
    \centering
    \includegraphics[width = 0.7 \linewidth]{images/paper2/segmentationAlgo.png}
    \centering
    \caption{Semantic segmentation. (a) Input image. (b) Strong. (c) Bbox-seg. (d) $ Joint_{sp} $ (LSC) }
    \label{fig: semanticSegmentation}
\end{figure}

\begin{table}[h!]
    \centering
    \begin{adjustbox}{max width=\textwidth}
    \begin{tabular}{*{3}{|c}|}%%{|c|c|c|}
        \hline
        Strong & Bbox-seg & $ Joint_{sp} $ \\
        \hline
        62.5 & 60.6 & \bfseries{64.0} \\
        \hline
    \end{tabular}
    \end{adjustbox}
    \caption{Semantic segmentation accuracy in terms of Mean IOU (\%)}
    \label{table accuracy semantic segmentation}
\end{table}

\subsection{CONCLUSIONS}
Like all superpixel algorithms, there are still two problems that need to be
solved. The first concerns the number K of superpixels to be generated. Unfortunately,
this parameter still has to be entered manually and today there
is no stable method that can establish a specific K number of superpixels on
each type of image. The second, on the other hand, concerns the study of
new similarity techniques, instead of the one already used in this article
($ W(p,q) $), useful for improving the performance, in terms of segmentation,
of LSC.


\subsection{Local Winner Takes All (LWTA) layer}

The output for all nodes in a layer is \(0\) unless it is the greatest.


\documentclass[12pt]{hitec}

\usepackage{fancyvrb}
%%\usepackage{hyperref}

\title{Problem set 2}
\author{Joe Armstrong}
\date{}

\begin{document}

\maketitle

\tableofcontents

\section{Problems}

Implement the functions described below. Choose suitable module names
for your functions. Add unit tests and documentation to the modules.

For v\"{a}lgodk\"{a}nd you should solve the sections mark advanced and
your programs should be of production quality. This means, not only
should the code be totally correct, it should also be well documented
with no spelling errors and have good test coverage.

\subsection*{On ambiguities in the questions}

These questions might appear to you to be unclear or to have multiple
interpretations.

If you think the question is unclear and has several interpretations,
then choose one of the interpretations and and answer the question
with the chosen interpretation.

Include in your answer a description of why you thought the question
was unclear and which of the possible interpretations you have
chosen. You might get extra credits for this.

If you think the question is crazy and cannot be answered then write a
description of why you cannot answer it.

When you get a job at the end of your courses and start programming
you will find that specifications are almost always unclear -- this is very
common -- in these circumstances there is often nobody to ask so have
to choose an interpretation of the specification, write down your
assumptions and solve the problem subject to your interpretation.

\subsection{is\_prime(N)}

Write a function \verb+is_prime(N)+ which returns \verb+true+ if
\verb+N+ is a prime number otherwise \verb+false+. Assume that
\verb+N+ $<=$ 10,000.

\subsection{seq(N)}
Write a function \verb+seq(N)+ which returns a list of integers from
$1$ to $N$

\subsection{filter(F, L)}

Write a function \verb+filter(F, L)+ which returns all elements $X$ in
the list $L$ for which $F(X)$ is \verb+true+.

\subsection {all\_primes(N)}

Write a function \verb+all_primes(N)+ which returns
all primes $<= N$ using the functions \verb+seq/1+,
\verb+is_prime/1+ and \verb+filter/2+ that you have written earlier.

\subsection{rotate(N, L)}

\verb+rotate(1, L)+ rotates the list \verb+N+ by one place.
For example a one place rotation of the list \verb+[a,b,c,d,e,f]+ is the list
\verb+[b,c,d,e,f,a]+. The element at the head of the list \verb+a+ is moved
to the end of the list.

\verb+rotate(N, L)+ for positive \verb+N+ performs a one place rotation \verb+N+ times.

\verb+rotate(-1,L)+ rotates the list in the opposite direction and moves the
last element of the list to the beginning
so  \verb+rotate(-1, [a,b,c,d,e,f])+ is the list
\verb+[f,a,b,c,d,e]+.

\verb+rotate(N, L)+ for negative \verb+N+ performs \verb+rotate(-1, L)+ \verb+N+ times.

Implement the function \verb+rotate(N, L)+ write unit test cases for the
function. Write some test cases extremely large values
of \verb+N+ (greater than $10^{20}$).

\section{Arithmetic evaluator}

Assume that the parse trees of
arithmetic expressions are represented as follows:

\begin{itemize}
\item \verb=A + B= is represented as the tuple \verb+{plus,A,B}+
\item \verb=A - B= is represented as the tuple \verb+{minus,A,B}+
\item \verb=A * B= is represented as the tuple \verb+{times,A,B}+
\item \verb=A / B= is represented as the tuple \verb+{divide,A,B}+
\item \verb+N+ is represented by itself if \verb+N+ is an integer or float.
\end{itemize}

Write an expression evaluator \verb+eval(E)+ that returns the value of a arithmetic
expression represented as a parse tree \verb+E+. \verb+{divide,A,B}+ should
perform floating point division.

For example:
\verb+eval({plus,3,4})+ should return \verb+7+ and
\\
\verb+eval({times,{plus,2,3},{minus,3,4}})+ should return \verb+-5+.
\\
\verb+eval({divide,12,3})+ should return \verb+4.0+ and not \verb+4+.

\section{Advanced}
Write a function \verb+safe_eval(X)+ which returns \verb+{ok, Val}+
if \verb+X+ is an arithmetic expression whose value is \verb+Val+ according
to the rules in the previous section, and whose value is \verb+{error,Why}+
is the \verb+X+ does not represent a valid expression and \verb+Why+
is a term describing the error.

A non valid expression is one where the parse tree is incorrect, or
might trigger a divide by zero exception. So for, example
\verb+{plus,12,monday}+ is an invalid expression (according to the rules
above) and
\\
\verb+{plus,12,{divide,12,0}}+ is an invalid expression
since it would cause a divide by zero exception when evaluated.

Write a process which is sent messages containing parsed arithmetic expressions and returns
messages containing the result of the evaluation.

Make sure your process does not crash if it is sent invalid messages.

\end{document}


\section{Spatial Discretization}\label{se:SpatialDiscretization}

We discretize the two-moment model with a simple first-order finite volume method to illustrate how the closure affects the realizability-preserving property of the method.
By assuming that the moments at time level $t^{n}$ ($\bcM^{n}$) satisfy the bounds in Eq.~\eqref{eq:MomentsBounds}, our goal is to identify sufficient conditions such that the moments at time level $t^{n+1}$ ($\bcM^{n+1}$) also satisfy the bounds.
To simplify, we limit the discussion to one spatial dimension and employ a uniform Cartesian mesh.
(The extension to multiple spatial dimensions and high-order discretization using the discontinuous Galerkin method is given in~\cite{chu_etal_2018}.)

We divide the spatial domain $D$ into $N$ uniform cells and denote the $i$-th cell by $\bK_{i}$, with $i = 1,\ldots,N$; i.e.,
\begin{equation*}
  D = \cup_{i = 1}^{N} \bK_{i} \quad \text{with} \quad
  \bK_{i}=\{\,x : x\in(x_{i-1/2}, x_{i+1/2})\},
\end{equation*}
and cell width $\dx = D/N$.
The cell-average of the moments is defined as
\begin{equation}
  \bcM_{i} = \dfrac{1}{\dx} \int_{\bK_i}\bcM dx.
\end{equation}
Integrating Eq.~\eqref{eq:momentEquations} over each cell $\bK_{i}$ gives
\begin{equation}
  \dfrac{d \bcM_{i}}{d t} = - \dfrac{1}{\dx} \left( \widehat{\bcF}(\bcM_{i},\bcM_{i+1}) -  \widehat{\bcF}(\bcM_{i-1},\bcM_{i})\right) + \f{1}{\tau}\,\cC(\bcM_{i}),
  \label{eq:SemiDiscretizatedMomentEquation}
\end{equation}
where $\widehat{\bcF}(\vect{\cM}_{a},\vect{\cM}_{b})$ is the numerical flux and $\f{1}{\tau}\,\cC(\bcM_{i})$ is the collision term evaluated with $\bcM_{i}$.
In this paper we use the global Lax-Friedrichs flux (setting the largest absolute eigenvalue of the flux Jacobian to one):
\begin{equation}
  \widehat{\bcF}_{\LF}(\vect{\cM}_{a},\vect{\cM}_{b})
  =\f{1}{2}\,\big(\,\bcF(\vect{\cM}_{a})+\bcF(\vect{\cM}_{b})-(\,\vect{\cM}_{b}-\vect{\cM}_{a}\,)\,\big).
  \label{eq:Lax-Friedrichs flux}
\end{equation}
By treating the transport term explicitly with forward Euler and the collision term implicitly with backward Euler, we have
\begin{align}
  \bcM_{i}^{n+1} = \widetilde{\bcM}^{n}_{i} + \f{\dt}{\tau}\,\cC(\bcM^{n+1}_{i}),
  \label{eq:MomentIMEX}
\end{align}
where we have defined
\begin{align}
  \widetilde{\bcM}^{n}_{i}
  & = \bcM_{i}^{n} - \frac{\dt}{\dx} \left( \widehat{\bcF}_{\LF}(\bcM^{n}_{i},\bcM^{n}_{i+1}) -  \widehat{\bcF}_{\LF}(\bcM^{n}_{i-1},\bcM^{n}_{i})\right)\nonumber \\
  & = (1-\beta)\bcM_{i}^{n} + \beta\left[ \f{1}{2}\left( \bcM^{n}_{i+1}-\bcF(\bcM^{n}_{i+1})\right)  + \f{1}{2}\left( \bcM^{n}_{i-1}+\bcF(\bcM^{n}_{i-1})\right)\right],
  \quad\beta = \frac{\dt}{\dx}.
\label{eq:widetildeM}
\end{align}

Considering Eqs.~\eqref{eq:MomentIMEX} and \eqref{eq:widetildeM} and assuming that $\bcM_{i}^{n}$ is realizable for all $i$, it can be shown (Lemma~3 in~\cite{chu_etal_2018}) that $\bcM^{n+1}_{i}$ is realizable provided $\f{\dt}{\tau} > 0$.
%and $\widetilde{\bcM}^{n}_{i}$ is realizable.
In Eq.~\eqref{eq:widetildeM}, if $\beta \in [0,1]$, $\widetilde{\bcM}^{n}_{i}$ is expressed as a convex combination of $\bcM_{i}^{n}$ and the expression in the square brackets on the right-hand side of Eq.~\eqref{eq:widetildeM}.
It follows that $\widetilde{\bcM}^{n}_{i}$ is realizable if the expression inside the square brackets is realizable.
It can be shown (Lemma~2 in~\cite{chu_etal_2018}) that the expression in square brackets is realizable for a distribution satisfying $f\in[0,1]$.
For the two-moment model considered here, realizability depends on the algebraic closure.
Specifically, if $\bcM_{i}^{n}$ is realizable and the Eddington factor satisfies the bounds in Eq.~\eqref{eq:eddingtonFactorBounds}, then $\bcM^{n+1}_{i}$ is realizable provided $\beta \in [0,1]$.
Thus, realizability of $\bcM^{n+1}_{i}$ requires both a closure based on Fermi-Dirac statistics and a Courant-Friedrichs-Lewy (CFL) condition $\dt\le\dx$.


\chapter{Cumulative distribution function of the Durbin-Watson statistic}

Let us consider the linear regression model \[ y_i = \beta_0 +
\beta_1x_{i1} + \ldots + \beta_kx_{ik} + \xi_i, \] $i = 1, \ldots, n$,
$k \geq 1$, $n > k + 1$, where $\xi_i$ are independent identically
distributed normal variables with zero mean, or $y = X\beta + \xi$. The
least squares estimate of $\beta$ is $b = (X^TX)^{-1}X^Ty$ and the
vector of residuals from the regression is $e = y - Xb$. The
Durbin-Watson $d$ statistic is defined by \[ d = \frac{\sum_{i = 2}^n
  (e_i - e_{i - 1})^2}{\sum_{i = 1}^n e_i^2} \] It is shown in
\cite[p.~426]{durbin-watson-1950} that $d_L \leq d \leq d_U$, where \[
d_L = \frac{\sum_{i = 1}^{n - k - 1} \lambda_i \zeta_i^2} {\sum_{i =
    1}^{n - k - 1} \zeta_i^2}, \] \[ d_U = \frac{\sum_{i = 1}^{n - k -
    1} \lambda_{i + k} \zeta_i^2} {\sum_{i = 1}^{n - k - 1}
  \zeta_i^2}, \] \[ \lambda_i = 2\left(1 - \cos \frac{\pi i}{n}\right),
\quad i = 1, \ldots, n - 1, \] and $\zeta_1, \ldots, \zeta_{n - 1}$ are
independent standard normal variables. The cumulative distribution
functions of $d_L$ and $d_U$ are
\begin{align} \label{eq:dwcdfdL}
  \Pr(d_L < x) &= \Pr\left(\sum_{i = 1}^{n - k - 1} (x - \lambda_i)
  \zeta_i^2 > 0 \right), \\
  \label{eq:dwcdfdU}
  \Pr(d_U < x) &= \Pr\left(\sum_{i = 1}^{n - k - 1} (x - \lambda_{i + k})
  \zeta_i^2 > 0 \right).
\end{align}

In both cases, the probabilities~(\ref{eq:dwcdfdL})
and~(\ref{eq:dwcdfdU}) are of the form \[ \Pr\left(\sum_{i = 1}^m w_i
\zeta_i^2 > 0 \right), \] where $w_i$, $i = 1, \ldots, m$, $m > 0$, are
those $x - \lambda_i$ or $x - \lambda_{i + k}$ which are not equal to 0.
They can be calculated by the formula (3.2) of
\cite[p.~422]{imhof-1961}, which states that if $w_i \neq 0$, $i = 1,
\ldots, m$, then \[ \Pr\left(\sum_{i = 1}^m w_i \zeta_i^2 > 0 \right) =
\frac{1}{2} + \frac{1}{\pi} \int_0^{+\infty} f(u) du, \] where
\begin{align*}
  f(u) &= \frac{\sin \theta(u)}{u \rho(u)}, \\
  \theta(u) &= \frac{1}{2} \sum_{i = 1}^m \arctan(w_iu), \\
  \rho(u) &= \prod_{i = 1}^m (1 + w_i^2u^2)^{1 / 4}.
\end{align*}
It is shown in (3.3) of \cite[p.~423]{imhof-1961} that
\begin{align}
  \nonumber
  \lim_{u \rightarrow 0} f(u) &= \frac{1}{2} \sum_{i = 1}^m w_i, \\
  \nonumber
  \lim_{u \rightarrow \infty} \theta(u) &= \frac{\pi}{4}
  \sum_{i = 1}^m \sgn w_i, \\
  \label{eq:dwcdftail}
  |\frac{1}{\pi} \int_u^{+\infty} f(u) du| & \leq
  \frac{1}{\pi} \frac{2}{m} u^{-m / 2} \prod_{i = 1}^m |w_i|^{-1 / 2}.
\end{align}

To achieve the result $\mathit{prob}$ and the accuracy $\mathit{eps}$
such that
\begin{equation} \label{eq:dwcdfprob}
  \mathit{prob} - \mathit{eps} \leq \Pr \left( \sum_{i = 1}^m w_i
  \zeta_i^2 > 0 \right) < \mathit{prob} + \mathit{eps}
\end{equation}
we put
\begin{equation} \label{eq:dwcdfupperlimit}
  u \geq (\frac{1}{\pi} \frac{2}{m} (\prod_{i = 1}^m |w_i|^{-1 / 2}) /
  (\mathit{eps} / 2))^{2 / m}
\end{equation}
so that by~(\ref{eq:dwcdftail}) we have \[ |\frac{1}{\pi}
\int_u^{+\infty} f(u) du| \leq \mathit{eps} / 2 \] and then calculate
\begin{equation} \label{eq:dwcdfintegral}
  \frac{1}{\pi} \int_0^u f(u) du
\end{equation}
by the Simpson method until two consecutive approximations differ no
more than $\mathit{eps} / 2$. To have four significant digits after the
comma, we put $\mathit{eps} = 0.000049$.

The function should not be used for low values of $n - k - 1$, say 1, 2,
3, as integration~(\ref{eq:dwcdfintegral}) fails. For $n - k - 1 = 1$ we
have
\begin{align*}
  \Pr(d_L < x) = 0 & \quad \mathrm{for} \quad x \leq \lambda_1, \\
  \Pr(d_L < x) = 1 & \quad \mathrm{for} \quad x > \lambda_1, \\
  \Pr(d_U < x) = 0 & \quad \mathrm{for} \quad x \leq \lambda_{1 + k}, \\
  \Pr(d_U < x) = 1 & \quad \mathrm{for} \quad x > \lambda_{1 + k}.
\end{align*}
For possible solution to this problem, see~\cite{farebrother-1984}. See
also~\cite{savin-white-1977}.


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

\section{Sheet 6}

\subsection{Sphere pole Riemann coordinates}

Recall from section \ref{sec:spherical-surface-curvature} the spherical surface metric in the coordinates \((\theta,  \varphi )\):
%
\begin{subequations}
\begin{align}
  g_{\mu \nu } = \left[\begin{array}{cc}
  R^2 & 0 \\
  0 & R^2 \sin^2 \theta
  \end{array}\right]
\,,
\end{align}
\end{subequations}
%
and the Christoffel symbols, which are all zero except for \(\Gamma^{0}_{11}= - \sin \theta \cos \theta \) and \(\Gamma^{1}_{01} = \Gamma^{1}_{10} = 1/ \tan \theta \).

We can plug these into the geodesic equation \(u^{\mu } \nabla_{\mu } u^{\nu }\), which comes out to be
%
\begin{subequations}
\begin{align}
  \ddot{\theta } &= + \dot{\varphi }^2 \sin \theta \cos \theta  \\
  \ddot{\varphi } &= - 2 \frac{\dot{\varphi } \dot{\theta } }{\tan(\theta )}
\,,
\end{align}
\end{subequations}
%
for a trajectory \((\theta (s), \varphi (s))\) with velocity \((\dot{\theta }, \dot{\varphi })\): dots denote derivatives with respect to \(s\).

Now, we want to check whether parallels and meridians are geodesics. First of all, we want to choose a parameter such that the velocity is of constant norm \(1\): the equation to satisfy is
%
\begin{subequations}
\begin{align}
  R^2 \left[\begin{array}{cc}
  \dot{\theta} & \dot{\varphi}
  \end{array}\right]
  \left[\begin{array}{cc}
  1 & 0 \\
  0 & \sin^2 \theta
  \end{array}\right]
  \left[\begin{array}{c}
  \dot{\theta} \\
  \dot{\varphi}
  \end{array}\right]
  \equiv 1
\,,
\end{align}
\end{subequations}
%
or \(\dot{\theta}^2 + \dot{\varphi}^2 \sin^2 \theta = R^{-2}\).
Meridians have constant \(\varphi \): for them, then, \(\dot{\theta}^2 = R^{-2} \), so an appropriate parametrization is \((\theta(s), \varphi(s)) = (s/R, \varphi_0 )\).
Parallels have constant \(\theta \): by an analogous line of reasoning, we parametrize them as \((\theta (s), \varphi (s) )= (\theta_0, s / R \sin\theta  )\).

One can readily check that for meridians both of the geodesic equations are identities, while for parallels the second one is an identity but the first reads \(0= \cos \theta  / \sin \theta \): it can only be satisfied if \(\theta = \pi /2\).
This makes sense: geodesics on a sphere are great circles, and the only parallel which is a great circle is the equator.

\subsubsection{Riemann coordinates}

The coordinates we wish to use are
%
\begin{subequations}
\begin{align}
  x &= R \theta \cos \varphi   \\
  y &= R \theta \sin \varphi
\,.
\end{align}
\end{subequations}
%
% whose tangent vectors at the north pole (i.e. \(\theta = 0\)) are:
% %
% \begin{subequations}
% \begin{align}
%   \dv[]{}{x} &= R \cos \varphi \dv[]{}{\theta }
%   - R \theta \sin \varphi \dv[]{}{\varphi }
%   = R \cos \varphi \dv[]{}{\theta } \\
%   \dv[]{}{y} &= R \sin \varphi \dv[]{}{\theta }
%   + R \theta \cos \varphi \dv[]{}{\varphi }
% \,,
% \end{align}
% \end{subequations}
% %

They are in the form \(x^{\alpha } = \theta n^{\alpha }\), for vectors \(n^{\alpha } = R (\cos \varphi, \sin \varphi )\).
An orthonormal basis for these vectors can be found by selecting \(\varphi = 0, \pi /2\).

As we have shown before, the coordinates \(x^{\alpha }\) describe geodesics if we consider them for fixed \(\varphi \) and with parameter \(\theta \), since they are meridians.

\subsubsection{Metric computation}

The metric transforms as
%
\begin{align}
  g_{\mu \nu }^{\prime }
  = \pdv{x^{\alpha }}{x^{\prime \mu }}
  \pdv{x^{\beta }}{x^{\prime  \nu }}
  g_{\alpha \beta }
\,,
\end{align}
%
so we need the inverse Jacobian, which is expressed in terms of the new coordinates \(x^{\prime \mu } = (x, y)\) and the old ones \(x^{\mu } = (\theta , \varphi )\):
%
\begin{subequations}
\begin{align}
  \pdv{x^{\alpha }}{x^{\prime \mu }}
  = \left[\begin{array}{cc}
  \frac{1}{R} \frac{x}{\sqrt{x^2 + y^2}} &
  \frac{1}{R} \frac{y}{\sqrt{x^2 + y^2}} \\
  \frac{-y / x^2}{1 + (y/x)^2} &
  \frac{1/x}{1 + (y/x)^2}
  \end{array}\right]
\,,
\end{align}
\end{subequations}
%
so we get, using the expansion \(\sin^2\theta \sim \theta^2 - \theta^{4} /3 + O (\theta^{6})\) and the identification \(R^2\theta^2 = x^2+y^2\):
%
\begin{subequations}
\begin{align}
  g_{00}^{\prime } &= R^2 \qty(\pdv{x^{0}}{x^{\prime 0}})^2
  + R^2 \sin^2 \theta \qty(\pdv{x^{1}}{x^{\prime 0}})^2  \\
  &= \frac{x^2}{x^2+y^2} + R^2 \sin^2 \theta \frac{y^2}{x^{4} \qty(1 + (y/x)^2)^2}  \\
  &=\frac{1}{x^2+y^2} \qty(x^2 + \frac{R^2 \sin^2\theta y^2}{x^2+y^2})  \\
  &= 1 - \frac{y^2}{3R^2} + O((x^2+y^2)y^2)
\,,
\end{align}
\end{subequations}
%
while for the off-diagonal elements \(g_{01}^{\prime } = g_{10}^{\prime }\):
%
\begin{subequations}
\begin{align}
  g_{01}^{\prime } &= R^2 \pdv{x^{0}}{x^{\prime 0}} \pdv{x^{0}}{x^{\prime 1}}
  + R^2 \sin^2 \theta \pdv{x^{1}}{x^{\prime 0}} \pdv{x^{1}}{x^{\prime 1}}  \\
  &= \frac{xy}{x^2+y^2} + R^2 \sin^2\theta \qty(- \frac{xy}{(x^2+y^2)^2})  \\
  &= \frac{xy}{x^2+y^2} \qty(1 - \frac{R^2 \sin^2\theta }{x^2+y^2})  \\
  &= \frac{xy}{x^2+y^2} \qty(\frac{(x^2+y^2)^2}{3R^2 (x^2+y^2)}) + O(x^2+y^2) \\
  &= \frac{xy}{3R^2} + O(x^2+y^2)
\,,
\end{align}
\end{subequations}
%
and lastly for the element \(g_{11}^{\prime }\):
%
\begin{subequations}
\begin{align}
  g_{11}^{\prime } &=  R^2 \qty(\pdv{x^{0}}{x^{\prime 1}})^2
  + R^2 \sin^2 \theta \qty(\pdv{x^{1}}{x^{\prime 1}})^2  \\
  &= \frac{y^2}{x^2+y^2} + R^2 \sin^2 \theta \frac{1}{x^{2} \qty(1 + (y/x)^2)^2}  \\
  &= \frac{1}{x^2+y^2} \qty(y^2 +  R^2 \sin^2\theta \frac{x^2}{x^2+y^2})  \\
  &= 1 - \frac{x^2}{3R^2} + O ((x^2+y^2) x^2)
  \,.
\end{align}
\end{subequations}

At the north pole \(x=y=0\), so there \(g^{\prime }_{\mu \nu }= \delta_{\mu \nu }\), and all the first derivatives calculated there vanish since there are no first order terms.

\subsubsection{Scalar curvature calculation}

The expression we have for the scalar curvature in a LIF is given in equation \eqref{eq:ricci-scalar-LIF}.

We can evaluate it for \(g_{\mu \nu }^{\prime }\). Do note  that the non-differentiated metric can be identified with the identity, and derivatives with upper and lower indices are the same. So, we get:
%
\begin{align}
  R _{\text{Ric}} = \tensor{g}{_{\alpha \nu , }^{\alpha \nu }} - \delta^{\mu \nu } \square g_{\mu \nu }
\,,
\end{align}
%
where the only nonvanishing terms are:
%
\begin{align}
  \tensor{g}{_{\alpha \nu,}^{\alpha \nu }} = 2 \pdv[2]{}{x}{y} \qty(\frac{xy}{3R^2}) = \frac{2}{3R^2}
\,
\end{align}
%
and what was denoted as the Dalambertian before is just the Laplacian: \(\square = \delta^{\mu \nu }\partial_{\mu } \partial_{\nu }= \partial^2_{xx} + \partial^2_{yy}\):
%
\begin{align}
  \delta^{\mu \nu } \square g_{\mu \nu }
  = \partial_{xx}^2 g_{11} + \partial_{yy}^2 g_{00}
  = - 2 \frac{2}{3R^2}
\,,
\end{align}
%
so in the end we get
%
\begin{align}
  R _{\text{Ric}} = \frac{2}{3R^2} + \frac{4}{3R^2} = \frac{2}{R^2}
\,,
\end{align}
%
which means that the curvature decreases as the radius increases, as we might expect.

\subsection{Schwarzschild metric curvature}

\subsubsection{Christoffel symbols}

The computation is tedious and not particularly enlightening: we start from the metric
\footnote{There is a typo in the homework assignment: the coefficients are written as functions of time.}
%
\begin{align}
  \dd{s^2} = - A(r) \dd{t^2}
  + B(r) \dd{r^2}
  + r^2 \qty(\dd{\theta^2} + \sin^2\theta \dd{\varphi^2})
\,,
\end{align}
%
and compute the Christoffel symbols with the usual formula:
%
\begin{align}
  \Gamma^{\mu }_{\nu \rho } =
  \frac{1}{2} g^{\mu \alpha }\qty(g_{\alpha \nu , \rho }
  + g_{\alpha \rho, \nu } - g_{\nu \rho , \alpha })
\,,
\end{align}
%
where fortunately, since the metric is diagonal, we only need to compute one term in the sum (that is, \(\mu \equiv \alpha \) always), and the two indices in the metric must be equal in order for the term to not vanish.

The metric only depends on \(\theta \) and \(r\), so any derivatives with respect to \(t\) and \(\varphi \) are to be discarded.

With this out of the way, we start computing the \(40\) independent symbols and find that the nonzero ones are (denoting differentiation with respect to \(r\) with a prime):
%
\begin{subequations} \label{eq:schwarzschild-christoffel}
\begin{align}
  \Gamma^{t}_{rt} &= \frac{A^{\prime }}{2A}  &
  \Gamma^{r}_{rr} &= \frac{B^{\prime }}{2B}  \\
  \Gamma^{r}_{tt} &= \frac{A^{\prime }}{2B}  &
  \Gamma^{\theta }_{r \theta } &= \frac{1}{r}  \\
  \Gamma^{r}_{\theta \theta } &= -\frac{r}{B}  &
  \Gamma^{\varphi }_{r \varphi } &= \frac{1}{r}  \\
  \Gamma^{r}_{\varphi \varphi } &= - \frac{r}{B} \sin^2 \theta  &
  \Gamma^{\theta }_{\varphi \varphi } &= - \sin \theta \cos \theta  \\
  \Gamma^{\varphi }_{\theta \varphi } &= \frac{\cos \theta }{\sin \theta }
\,.
\end{align}
\end{subequations}

\subsubsection{Ricci component}

We want to compute \(R^{\mu }_{t \mu t }\), and in order to do so we must find the three components \(R^{i}_{tit}\) with varying \(i\) and sum them (here \(i = r, \theta,\varphi \)), since \(R^{t}_{ttt}\) vanishes by antisymmetry.

In general we have:
%
\begin{subequations}
\begin{align}
  R^{i}_{tit} &= 2 \qty( \Gamma^{i}_{[t| t, |i]}  + \Gamma^{\alpha }_{t[t} \Gamma^{i}_{i] \alpha })  \\
  &= \Gamma^{i}_{tt, i} - \cancelto{}{\Gamma^{i}_{it,t}}
  + \Gamma^{\alpha }_{tt} \Gamma^{i}_{i\alpha }
  - \Gamma^{\alpha }_{ti} \Gamma^{i}_{t\alpha }
\,.
\end{align}
\end{subequations}

Note that the index \(i\) is consider not to be summed here, we are writing a formula for the components of the Riemann tensor; although the expression holds when summing over \(i\) as well.

So, we can compute this for the specific values of \(i\): for \(i=r\) we have
%
\begin{subequations}
\begin{align}
  R^{r}_{trt} &= \Gamma^{r}_{tt, r} + \Gamma^{\alpha}_{tt}
  \Gamma^{r}_{r \alpha } - \Gamma^{\alpha }_{tr} \Gamma^{r}_{t \alpha }  \\
  &= \qty(\frac{A^{\prime }}{2B})^{\prime } + \frac{A^{\prime }}{2B} \frac{B^{\prime }}{2B} - \frac{A^{\prime }}{2A} \frac{A^{\prime }}{2B}  \\
  &= \frac{A^{\prime \prime}}{2B} - \frac{A^{\prime }}{2B^2} B^{\prime } + \frac{A^{\prime }}{4B} \qty(\frac{B^{\prime }}{B} - \frac{A^{\prime}}{A}) \\
  &= \frac{A^{\prime \prime}}{2B} - \frac{A^{\prime }}{4B} \qty(\frac{A^{\prime}}{A} + \frac{B^{\prime }}{B})
  \,,
\end{align}
\end{subequations}
%
for \(i= \theta \) instead
%
\begin{subequations}
\begin{align}
  R^{\theta }_{t \theta  t} &= \cancelto{}{\Gamma^{\theta}_{tt, \theta}} + \Gamma^{\alpha}_{tt}
  \Gamma^{\theta}_{\theta \alpha } - \cancelto{}{\Gamma^{\alpha }_{t\theta} \Gamma^{i}_{t \alpha }}  \\
  &= \frac{A^{\prime }}{2B} \frac{1}{r}
  \,,
\end{align}
\end{subequations}
%
and for \(i = \varphi \):
%
\begin{subequations}
  \begin{align}
    R^{\varphi }_{t \varphi t} &= \cancelto{}{\Gamma^{\varphi}_{tt, \varphi}} + \Gamma^{\alpha}_{tt}
    \Gamma^{\varphi}_{\varphi \alpha } - \cancelto{}{\Gamma^{\alpha }_{t\varphi} \Gamma^{i}_{t \alpha }}  \\
    &= \frac{A^{\prime }}{2B} \frac{1}{r}
    \,,
  \end{align}
\end{subequations}
%
so our final solution is
%
\begin{subequations}
\begin{align}
  R_{00} = \sum_i R^{i}_{0i0} &= \frac{A^{\prime \prime}}{2B}
  - \frac{A^{\prime }}{4B} \frac{(AB)^{\prime }}{AB} + \frac{A^{\prime }}{Br}  \\
  &= \frac{A''}{2B} - \frac{A^{\prime 2} }{4AB} - \frac{A' B' }{4B^2} + \frac{A'}{Br}
\,.
\end{align}
\end{subequations}
%

\subsection{Schwarzschild geometry orbits}

The derivation up to the equation for the perturbed orbit equation is documented in the lecture notes, I might copy it here later, but for now one can find it there.

During the lecture we got up to the first order equation for the perturbation \(w\) for the orbit \(u\), written in the form \(u(\varphi ) = u_{c} \qty(1+w(\varphi ))\):
%
\begin{align}
    \dv[2]{w}{\varphi }  = (6GMu_c-1) w
\,,
\end{align}
%
which is in the form \(\ddot{w} + \omega^2 w = 0\), for \(\omega^2 = 1- 6GMu_c\). Now, we know that the first order equation must be complemented by the zeroth order one:
%
\begin{align}
    u_c = \frac{GM}{l^2} + 3GM u_c^{2}
\,,
\end{align}
%
which can be solved for \(u_c\) to yield:
%
\begin{align}
  u_c = \frac{1 \pm \sqrt{1 - 3 \times 4 \frac{G^2 M^2}{l^2}}}{6GM}
\,,
\end{align}
%
therefore the square angular velocity of the perturbation's evolution is:
%
\begin{align}
  \omega^2 = 1 - \cancelto{}{6GM} \qty(\frac{1 \pm \sqrt{1 - 12 \frac{G^2 M^2}{l^2}}}{ \cancelto{}{6GM}})
  = \pm \sqrt{1 - 12 \frac{G^2 M^2}{l^2}}
\,.
\end{align}

The solution with the minus sign has no meaning for us, since the solution we want to consider must be stable, with positive \(\omega^2\). So, the angular velocity is
%
\begin{align}
  \omega = \qty(1 - 12 \frac{G^2M^2}{l^2})^{1/4}
\,,
\end{align}
%
and we know that angular velocity and period are related by \(T = 2 \pi / \omega \): therefore we get
%
\begin{align}
  T = 2 \pi \qty(1 - 12 \frac{G^2M^2}{l^2})^{-1/4}
\,,
\end{align}
%
which we can Taylor expand: at \(x=0\) we have
%
\begin{align}
    (1-12x)^{-1/4} = 1 - \frac{1}{4} (1-12 \times 0)^{-5/4} (-12x) + O(x^2) = 1 + 3x + O(x^2 )
\,.
\end{align}
%

Therefore:
%
\begin{align}
  T = 2 \pi \qty(1 + 3 \qty(\frac{GM}{l})^2) + O\qty(\qty(\frac{GM}{l})^{4})
\,,
\end{align}
%
which is approximately \(2 \pi \) as we should expect: the Newtonian approximation is \(l \gg GM\), and Newtonian orbits have a period of exactly \(2 \pi \). Then we can read off the first-order correction directly from the first term in the expansion: it is
%
\begin{align}
  \delta \varphi = 6 \pi \qty(\frac{GM}{l})^2
\,.
\end{align}
%

The \(M\) here is the mass of the central object, while \(l\) is the angular momentum of the orbit.

\end{document}


%%
%% Hyperbolic Trig Identities
%%
%% Author: William Gao
%% 09/04/2019
%%

\documentclass[12pt]{article}
\setlength{\parindent}{0pt}                  % disable indent globally

\RequirePackage[
    letterpaper,
    left=0.8in,
    right=0.8in,
    top=0.70in,
    bottom=0.55in,
    nohead
]{geometry}

% Packages
\usepackage{amssymb}
\usepackage[fleqn]{amsmath}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    urlcolor=blue
}

\newcommand{\hzline}{\noindent\makebox[\linewidth]{\rule{0.8\paperwidth}{0.4pt}}}

\title{Hyperbolic Trig Identities}
%\author{math2.org}
\author{Version 1.1}
\date{September 4, 2019}

\begin{document}

\maketitle

\section{Introduction}
A compiled list of the most commonly used hyperbolic trig identities. Enjoy. \\

All credits goes to \href{http://math2.org/math/trig/hyperbolics.htm}{math2.org}. If you have comments, corrections, or clarifications, please submit an issue or pull request on \href{https://github.com/chemclub/calculus}{GitHub}.

\large
\section{Hyperbolic Definitions}

\begin{align*}
& \sinh x = \frac{e^x-e^{-x}}{2} \\
& \operatorname{csch}x = \frac{1}{\sinh x} = \frac{2}{e^x-e^{-x}}
\end{align*}

\begin{align*}
& \cosh x = \frac{e^x+e^{-x}}{2} \\
& \operatorname{sech}x = \frac{1}{\cosh x} = \frac{2}{e^x+e^{-x}}
\end{align*}

\begin{align*}
& \tanh x = \frac{\sinh x}{\cosh x} = \frac{e^x-e^{-x}}{e^x+e^{-x}} \\
& \operatorname{coth}x = \frac{1}{\tanh x} = \frac{e^x+e^{-x}}{e^x-e^{-x}}
\end{align*}

\begin{align*}
& \cosh^2x-\sinh^2x = 1 \\
& \tanh^2x+\operatorname{sech}^2x = 1 \\
& \coth^2x-\operatorname{csch}^2x = 1
\end{align*}

\section{Inverse Hyperbolic Definitions}

\begin{align*}
& \operatorname{arcsinh}z=\ln\left(z+\sqrt{z^2+1}\right) \\
& \operatorname{arccosh}z=\ln\left(z\pm\sqrt{z^2-1}\right) \\
& \operatorname{arctanh}z=\frac{1}{2}\ln\left(\frac{1+z}{1-z}\right)
\end{align*}

\begin{align*}
& \operatorname{arccsch}z=\ln\left(\frac{1+\sqrt{1+z^2}}{z}\right) \\
& \operatorname{arcsech}z=\ln\left(\frac{1+\sqrt{1-z^2}}{z}\right) \\
& \operatorname{arccoth}z=\frac{1}{2}\ln\left(\frac{z+1}{z-1}\right)
\end{align*}

\section{Relations to Trigonometric Functions}

\begin{align*}
& \sinh z=-i\sin\left(iz\right) \\
& \operatorname{csch}z=i\csc\left(iz\right)
\end{align*}

\begin{align*}
& \cosh z=\cos\left(iz\right) \\
& \operatorname{sech}z=\sec\left(iz\right)
\end{align*}

\begin{align*}
& \tanh z=-i\tan\left(iz\right) \\
& \coth z=i\cot\left(iz\right)
\end{align*}

\end{document}


\documentclass{article}

\usepackage{geometry}
\usepackage{amsmath}
\usepackage{amssymb}

\newcommand{\n}{^{\mathrm{min}}}
\newcommand{\x}{^{\mathrm{max}}}

\begin{document}

\section{Timers}

These host-ticks timers are a bit weird.  In fact, originally I had
them \emph{wrong}.

Let $i\n$ be the minimum interval, $i\x$ the maximum.  $t_j$ is a
ticker value, $r_j$ is a remainder, $d_j$ is a duration of time
passage, $\delta_j$ is the amount by which the ticker advances.

Consider
\[
\mathrm{Ticker}(t_0,r_0)\xrightarrow{d_1}
\mathrm{Ticker}(t_1,r_1)\xrightarrow{d_2}
\mathrm{Ticker}(t_2,r_2)
\]
where $t_1 = t_0+\delta_1$, $t_2=t_1+\delta_2 =
t_0+\delta_1+\delta_2$.

The original rule was:
\[
\exists i_j.\;
i\n\leq i_j \wedge i_j\leq i\x \wedge
\delta_j = \left\lfloor \frac{r_{j-1}+d_j}{i_j} \right\rfloor \wedge
r_j = r_{j-1}+d_j - \delta_j i_j
\]

A crucial property is the following (roughly \textbf{S1} and
\textbf{S2} in Lynch and Vaandrager 1996), which I shall call
additivity:
\[
\mathrm{Ticker}(t_0,r_0)\xrightarrow{d_1}
\mathrm{Ticker}(t_1,r_1)\xrightarrow{d_2}
\mathrm{Ticker}(t_2,r_2)
\Leftrightarrow
\mathrm{Ticker}(t_0,r_0)\xrightarrow{d_1+d_2}
\mathrm{Ticker}(t_2,r_2)
\]

This does not hold for the original rule!  If $d_1 > d_2$, and we
choose $i_1=i\n$ and $i_2=i\x$, it can happen that even though $r_2 <
i_2$, it is the case that $r_2 > i\x_{12}$, where $i\x_{12}$ is the
greatest interval consistent with $t_2$, i.e., $i\x_{12} =
\frac{r_0+d_1+d_2-r_2}{\delta_1+\delta_2}$.  This means that no
$i_{12}$ satisfying the condition of the rule exists.

For example: let $r_0 = 14$, $d_1=364$, $d_2=141$, $i_1=56$,
$i_2=112$.  Then $\delta_1=6$, $r_1=42$, $\delta_2=1$, $r_2=71$.  But
to achieve $r_{12}=71/56$ we must have
$\delta_{12}i_{12}=r_0+d_{12}-r_{12}=448$; and since $\delta_{12}=7$,
we must have $i_{12}=64$.  But $\delta_{12}=\left\lfloor \frac{519}{64}
\right\rfloor = 8 \neq 7$, which is a CONTRADICTION.

A new possible rule is as follows:
\[
\begin{array}{r@{}c@{}l}
\exists \delta\n_j \delta\x_j.\;\\
\delta\n_j &=& \left\lfloor \frac{r_{j-1}+d_j}{i\x} \right\rfloor \wedge\\[1ex]
\delta\x_j &=& \left\lfloor \frac{r_{j-1}+d_j}{i\n} \right\rfloor \wedge\\
\delta\n_j &{}\leq \delta_j\leq{}&\delta\x_j \wedge\\
r_{j-1}+d_j-\delta_j i\x &{}\leq r_j \leq {}&r_{j-1}+d_j-\delta_j i\n \wedge\\
0 &{}\leq r_j <{}& i\x
\end{array}
\]
where the $\delta\n_j, \delta\x_j$ are now naturals as well as
$\delta_j$ (note the strict inequality on $r_j < i\x$ is still
necessary for the model).

Does this have the desired properties?

Argh, I'm an idiot!  The reason I was having trouble proving the
properties was that the above rule is overconstrained.  It is
sufficient to require:
\[
\begin{array}{r@{}c@{}l}
r_{j-1}+d_j-\delta_j i\x &{}\leq r_j \leq {}&r_{j-1}+d_j-\delta_j i\n \wedge\\
0 &{}\leq r_j <{}& i\x
\end{array}
\]
The following results follow:
\begin{itemize}
\item $\delta_j$ lies in the range $[\left\lfloor
\frac{r_{j-1}+d_j}{i\x} \right\rfloor,\left\lfloor
\frac{r_{j-1}+d_j}{i\n} \right\rfloor]$.
\item $r_j$ can then be determined
from the inequations above---it is usually free in $[0,i\x]$, but when
$\delta_j$ is chosen at or near the boundaries, it is restricted by
the other inequation.
\item The additivity property holds (this is trivial to verify: add
the first inequations for $j=1$ and $j=2$, and subtract $r_1$
through).
\end{itemize}

\end{document}


\section{Learning spectral clustering}
\label{ch:jordan04}

\textit{Learning spectral clustering} by Francis R. Bach and Michael I. Jordan. \\
Cited by 313. \textit{Advances in Neural Information Processing Systems 16 (2004)}.
\newline

\textbf{Main point} is that the author derived \begin{inparaenum}[\itshape a\upshape)]
\item a cost function for spectral clustering that minimize the error between a given partition and the minimum normalized cut
\item with respect to two algorithms one for spectral clustering and one for learning the similarity matrix.
\end{inparaenum}.

\subsection{Objective way of similarity measure}
A general framework is provided for learning the similarity matrix for spectral clustering. New cost function $J(W,e)$ that characterizes how close the eigen structure of a similarity matrix $W$ is to a partition $e$.
%
%\subsection{Spectral clustering}
%Given a dataset $I$ of $P$ points in space $X$ and a $P \times P$ similarity matrix $W$ that measures the similarity between the $P$ points.

\subsection{Learning the similarity matrix}

\begin{figure}[ht]
\begin{mdframed}
\begin{description}
\item[Assumption] \hfill \\
given $N$ datasets $D_n, n \in \{ 1, \cdots, N \}$ of points in $R^F$ where $D_n$ is composed of $P_n$ points $x_{np}, p \in \{ 1, \cdots, P_n \}$.
\item[Step 1] \hfill \\
for each $n$ we know the partition $e_n$, so that target matrix $ \Pi (e_n, \alpha)$ can be computed from each dataset.
\item[Step 2] \hfill \\
for each $n$, we have a similarity matrix $W_n (\alpha)$
\item[Step 3] \hfill \\
The cost function $H(\alpha) = \frac{1}{N} \sum_n F( W_n(\alpha), \Pi_0 (e_n, \alpha)) + C || \alpha ||_1$.
\item[Step 4] \hfill \\
The learning algorithm is the minimization of $H(\alpha)$ with respect to $\alpha \in R_{+}^F$ using the method of conjugate gradient with line search.
\end{description}
\end{mdframed}
\caption{Learning similarity matrix}
\end{figure}


% !TEX root = as_grf_sopt.tex

\subsection{DISCUSSIONS}

Our approach and two other popular criteria, information gain from \cite{srinivas2012information} and V-optimality of \cite{mingji}, can also be connected by functions of the eigenvalues of the covariance matrix at each iteration.
% Particularly, we are interested in primitives of monotone functions as described in \cite{spectral_submod}.

% From the rank-one update rule, \eqref{eq:var_update}, the posterior covariance matrices at different iterations can be ordered using convex cone of postive semi-definite matrix (Loewner order) as
% $\bC_0\succ\bC_1\succ\dotsc\succ\bC_T\succ\mathbf{0}$. With this ordering, we can define monotone spectral operators, $h(\bC_t)$, that maps Hermitian matrices to real values, such that
% \begin{equation*}
% h(\bC_t)>h(\bC_{t'}) \Leftrightarrow \bC_t\succ\bC_{t'}
% \quad(\Leftrightarrow t<t').
% \end{equation*}

% Many exploration heuristics can be written as a function of the spectral difference between the current model and one-step look-ahead posterior model.
To see this connection, assume the updated covariance matrix at iteration $(t+1)$ has eigen-decomposition $\bC_t = \sum_{j=1}^n \lambda_{t,(j)}\bq_{t,(j)} \bq_{t,(j)}^\top$, where $\blambda_t=(\lambda_{t,(1)}, \dotsc,\lambda_{t,(n)})^\top$ represents the eigenvalues and  $\{\bq_{t,(j)}:j=1,\dotsc,n\}$ is the set of corresponding eigenvectors. Assume the eigenvalues are sorted by $\lambda_{t,(1)}\geq\dotsc\geq\lambda_{t,(n)}\geq0$.
We hope to connect $s_t(v)$ to the following spectral difference,
 % at the one-step difference of a spectral function $h(\blambda_t):\mathbb{R}^n\to\mathbb{R}$, as
%\begin{align}
%	\rho(\bC_t) &= \sum_{j=1}^n h(\lambda_{t,(j)}),
%	\quad {\rm s.t.} \;
%	h'(s)>0, \forall s>0.
%\end{align}
%Correspondingly, assuming an observation of $v$, the exploration heuristic is then,
\begin{equation}
	\Delta h_t(v) =
	h\bigl(\blambda_{t}\bigr)
	-
	h\bigl(\blambda_{t+1\mid v}\bigr)
	% \\
	% &{\rm s.t. } \;
	% h'(s)>0, \forall s>0
\end{equation}
where $h(\blambda):\mathbb{R}^n\to\mathbb{R}$ is a multivariate function defined on the eigenvalues.
Further, by the one-step update rule of \eqref{eq:var_update}, $\bC_t$ has Loewner order as
$\bC_0\succ\bC_1\succ\dotsc\succ\bC_T\succ\mathbf{0}$.
% for any monotone increasing function $h:\mathbb{R}^n\to\mathbb{R}$.
It is thus often desirable to require $h(\cdot)$ to be monotone with respect to this ordering, i.e. $\bC_t\succ\bC_{t'} \Rightarrow h(\blambda_t)\geq h(\blambda_{t'})$.
% Notice that $\bC_t$ is positive semi-definite and $\lambda_{t,(j)}$ is monotone decreasing as $t$ increases,
% by applying Weyl's inequality to rank-one updates at each iteration.

% where the difference inside $h^{-1}(\cdot)$ is nonnegative, because we can prove using induction and definition of eigen-vectors, for example with $j=1$
% and
% $\bq_{t+1,(1)}$ being the eigen-vector corresponding to $\lambda_{t+1,(1)}$ in the posterior model,
% $
	% \lambda_{t,(j)}^2 - \lambda_{t+1,(1)}^2
	% \geq
	% \nicefrac{\langle \bq_{t+1,(1)}, \bc_{t+1}(v)\rangle^2}{(\sigma_n^2 - \sigma_{t+1}^2(v))}\geq0$.

%For example, some reasonable choices of $s_t(v)$ are,
%\begin{numcases}{\hspace{-2em}}
%	\sqrt{ 1+\nicefrac{\sigma_t^2(v)}{\sigma_n^2}}
%	 & $h_{ig}(s) = -log(s)$
%	   \label{eq:s-ig}
%	\\
%	 \sqrt{\tr(\bC_{t}) - \tr(\bC_{t+1})},
%	   & $h_2(s) = s^2$
%	   \label{eq:s-variance}
%	\\
%	 \lambda_{\max}(\bC_{t}) - \lambda_{\max}(\bC_{t+1}),
%	 \hspace{-1em}
%	 & $h_\infty(s) = s^p, p\to\infty$
%	   \label{eq:s-spectral}
%\end{numcases}

\textbf{Case 1}. $
	h(\blambda) = \sum_j \log(\lambda_{(j)}).$
	% the differential entropy of $\mathcal{N}(\bmu_t,\bC_t)$.
	Then,
$	\Delta h_t(v)
	= 2\mathcal{I}_t(\bff; y(v)) = \log(1+\frac{\sigma_t^2(v)}{\sigma_n^2}),
	% = \sqrt{ 1+\nicefrac{\sigma_t^2(v)}{\sigma_n^2}}.
$ twice the information gain from $\bff\sim\mathcal{N}(\bmu_t, \bC_t)$ to $\mathcal{N}(\bmu_{t+1\mid v}, \bC_{t+1\mid v})$.
This metric is important to \textbf{GP-UCB} \citep{srinivas2012information}, which set $s_t(v)=\sigma_t(v)$ and used the inequality, $\log(1+\frac{\sigma_m^2}{\sigma_n^2})  \frac{\sigma_t^2(v)}{\sigma_m^2}\leq\log(1+\frac{\sigma_t^2(v)}{\sigma_n^2}),$ where $\sigma_m=\max_{v,t}\sigma_t(v)$, in its proofs.

% This heuristic adds biases to maximize the differential information gain of the joint distribution of node values, turns out to pay too much attention to the graph periphery, which actually prevents information gathering in the true problem against intuition. Precisely, differential entropy is sensitive to tails of the distribution, which happens to be the place of the biggest model mismatch of our \textsc{grf} models.

\textbf{Case 2}. $
	h(\blambda) = \sum_j \lambda_{(j)} $
	gives
	$
	\Delta h_t(v) = \tr(\bC_{t}) - \tr(\bC_{t+1\mid v}) =  \nicefrac{ \| \bc_t(v) \|_2^2 }{(\sigma_t^2(v) + \sigma_n^2)}.
$ For $\sigma_n= 0$, $\Delta h_t(v)$ is used as the greedy \textbf{V-optimal} criterion for design of experiments by \cite{mingji}.
%, which though alleviates the situation by adding independence assumptions on the nodes and measuring the sum of the marginal variances, cannot completely address the selection bias at graph peripheries, because the self-variance term usually dominates the sum of squares of $\|\bc_t(v)\|_2^2$.

\textbf{Case 3}. $
	h(\blambda) = \lambda_{(1)}$ connects to the greedy design for \textbf{E-optimality} \citep{pukelsheim1993optimal}. To some extent, it is also related to greedy \textbf{$\Sigma$-Optimality}. First,
	approximate $\Delta h_t(v)$ by $\partial\lambda_{(j)} = \bq_{(j)}^\top \partial(\bC) \bq_{(j)}$ around $\bC=\bC_t$, as
\vspace{-.5em}
\begin{equation*}
	\Delta h_t(v)
	% &
	\approx
	\bq_{t,(1)}^\top (\bC_t-\bC_{t+1|v}) \bq_{t,(1)}
	=
	 \bigg(
		\frac{|\bc_t(v)^\top \bq_{t,(1)}|}
	{\sqrt{\sigma_t(v)^2 + \sigma_n^2}}
	 \bigg)^2
	%  \\
	%  &=
	%  \bigg(
	% 	\frac{\lambda_{(1)} \cdot |q_{t(1)}(v)|}
	% {\sqrt{\sigma_t(v)^2 + \sigma_n^2}}
	%  \bigg)^2
	\end{equation*}
The above resembles \eqref{eq:sopt} if $\bq_{t,(1)}\propto \bone$, which holds true for $t=0$ and $\omega_0=0$ and approximately so for small $t$s.

In all these cases, exploration is measured by how much the objective, $h(\blambda_T)$, is eventually decreased after $T$ iterations.
Each definition of $h(\blambda_t)$ aggregates the eigenvalues of the posterior covariance matrices in a different way, which
affects the relative importance of large and small eigenvalues. In \textbf{Case 1}, since $\frac{\partial \log(\lambda)}{\partial \lambda}=\frac{1}{\lambda}$, the same change introduced to a smaller $\lambda$ will have a relatively larger impact on the objective.
 % than a larger $\lambda$.
Such an effect is not evident in the other two cases.
Particularly in \textbf{Case 3}, changes to small eigenvalues are ignored unless they become the largest eigenvalue.

Establishing biases to penalize larger eigenvalues more has the benefit of improving global robustness because the posterior marginal variance of every node is upper-bounded by $\lambda_{t,(1)}$.
Compared with \textbf{Cases 2} and \textbf{3}, \textbf{Case 1} is more sensitive to changes in small eigenvalues, which may be another explanation
of \textbf{GP-UCB}'s strong tendency to select peripheral nodes, as seen in Figure 4 of \cite{MIG} or Figure 1(d) of \cite{gotovos2013active}.

Although Algorithm~\ref{alg:main} is not built around the concept of functions on eigenvalues, it still establishes strong biases to penalize large eigenvalues in its initial explorations, per analysis in \textbf{Case 3}.
Note that \textbf{$\Sigma$-optimality} achieves a more complex goal than \textbf{E-optimality}; exact execution of \textbf{E-optimality} may over-simplify the model and select nodes between clusters for separation rather than inside them.

% First, assuming that the principal eigen-vector of $\bC_t$ is $\bq_t$, then
% $
% 	\lambda_{\max}^2(\bC_{t+1} \mid v) \approx \lambda_{\max}^2(\bC_t) -
% 	\frac{\langle \bq_t,  \bc_t(v)\rangle^2}
% 	{ (\sigma_t^2(v) + \sigma_n^2) }
% $ and, compounding the square-root operator,
% $
% 	s_t(v) \approx \frac{1}{2\lambda_{\max}(\bC_t)}
% 	\frac{\bc_t(v)^\top \bq_t}
% 	{\sqrt{\sigma_t(v)^2 + \sigma_n^2}}.
% $

% This approximation works for the very first selections. Note that $\bC_0^{-1}=\bD-\bA+\omega_0\bI$ has its smallest eigen-vector (with respect to $\omega_0$) very close to $\frac{1}{n}\mathbf{1}$, that same vector carries to be $\bq_0$ for the largest eigen-value of $\bC_0$. At this point, $s_t(v)$ is our Sigma-optimality up to a selection-independent constant.

% In fact, this approximation can be valid for larger $t$'s. Further break the graph down to different (relatively isolated) connected components, where each individual component is relatively unexplored, and therefore contains a principal eigen-vector,  relative to the component, which will approximate
% $\bq_{t,(c)}\approx\mathbf{1}_\cC$, where $c$ is the rank of this eigen-vector and $\cC$ the subset of nodes of this connected component. The more under-explored the component is, the more likely that $\bq_{t,(c)}$ becomes the principal eigen-vector, $\bq_t$ and also $\bq_{t,(c)}$ gets close to $\mathbf{1}_\cC$.

% In the meantime, every column on the current covariance matrix $\bc_t(v)$ will also reflect independence between these (relatively isolated) components. Thus, the inner product can be roughly approximated as,
% $ %\begin{equation}
% 	\bq_t^\top \bc_t(v) \approx \mathbf{1}_\cC^\top \bc_t(v)  + \mathbf{1}_{\bar{\cC}}^\top \mathbf{0} = \mathbf{1}^\top \bc_t(v),
% $ %\end{equation}
% where $\bar{\cC}$ is the complement of $\cC$.
% Again, Sigma-optimality approximates the difference of the spectral norm between prior and one-step look-ahead covariance matrices.


\chapter{Experimental}

\section{Further development of the maximum proof}
Starting point is:
\[
v_{n+2}=\frac{2}{\left(2-\prod_{i=1}^{n}\beta_i\right)\cdot2^{\alpha_{n+1}}}
\]

\par\medskip
In order to show that $v_{n+2}<1$ we consider the worst case that maximizes $v_{n+2}$ by using the inserting the Engel expansion into the product:
\[
\prod_{i=1}^{n}\beta_i=\prod_{i=1}^{n}\left(1+\frac{1}{3v_i}\right)=\prod_{i=1}^{n}\left(1+\frac{1}{3v_i}\right)=\prod_{i=1}^{n}\left(1+\frac{1}{3\frac{3^{i-1}(v_1+1)-2^{i-1}}{2^{i-1}}}\right)
=\prod_{i=1}^{n}\frac{3^i(v_1+1)-2^i}{3^i(v_1+1)-3*2^{i-1}}
=\frac{1}{v_1}-\frac{1}{v_1}\left(\frac{2}{3}\right)^n+1
\]

\par\medskip
This leads to:
\[
v_{n+2}=\frac{2}{\left(2-\left(\frac{1}{v_1}-\frac{1}{v_1}\left(\frac{2}{3}\right)^n+1\right)\right)\cdot2^{\alpha_{n+1}}}
\]

\par\medskip
Multiplying leads to
\[
2^{\alpha_{n+1}}v_1v_{n+2}-2^{\alpha_{n+1}}v_{n+2}+2^{\alpha_{n+1}}v_{n+2}\left(\frac{2}{3}\right)^n-2v_1=0
\]

\par\medskip
Now we remove the variable $v_1$, because we know the relatonship between $v_1$ and $v_{n+2}$ in an Engel expansion (see \ref{eq:asc_continued_fraction}):
\[
v_1=\frac{(v_{n+2}+1)2^{n+1}}{3^{n+1}}-1
\]

\par\medskip
Now we substitute the term above into our equation:
\[
2^{\alpha_{n+1}}\left(\frac{(v_{n+2}+1)2^{n+1}}{3^{n+1}}-1\right)v_{n+2}-2^{\alpha_{n+1}}v_{n+2}+2^{\alpha_{n+1}}v_{n+2}\left(\frac{2}{3}\right)^n-2\left(\frac{(v_{n+2}+1)2^{n+1}}{3^{n+1}}-1\right)=0
\]

\par\medskip
We know that in an Engel expansion $\alpha_{n+1}=1$ (we make onla one division by two between vertices). Via substitution $v_{n+2}=y$ we obtain a simple equation, which has for $y\ge1$ only complex solutions having an imaginary part:
\[
\left(\frac{(y+1)2^{n+1}}{3^{n+1}}-1\right)y-y+y\left(\frac{2}{3}\right)^n-\left(\frac{(y+1)2^{n+1}}{3^{n+1}}-1\right)=0
\]

Let us now substitute $\left(\frac{2}{3}\right)^n$ with $z$:
\[
\left((y+1)\frac{2}{3}z-1\right)y-y+yz-\left((y+1)\frac{2}{3}z-1\right)=0
\]

Hence $y=v_{n+2}$ must be smaller than 1.