% @Author: UnsignedByte
% @Date:   11:12:32, 08-Dec-2020
% @Last Modified by:   UnsignedByte
% @Last Modified time: 2021-05-21 22:45:03

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{asymptote}
\graphicspath{ {./images/} }
\usepackage[%
    colorlinks=true,
    pdfborder={0 0 0},
    linkcolor=black
]{hyperref}
\title{Generalized Derivation for the Motion of an n-Pendulum System}
\author{Edmund Lam \and Nicolas Wieczorek}
\begin{document}
\begin{titlepage}
	\maketitle
	\thispagestyle{empty}
\end{titlepage}
\newpage
  \tableofcontents
\newpage

\begin{asydef}
import astylib;
\end{asydef}

\section{Introduction}
All source code for this project is public on \href{https://github.com/UnsignedByte/n-pendulums}{Github}.

A single pendulum, is defined by a point of mass suspended by a rigid rod allowed to rotate freely on a joint at the other end of the rod. The mechanics of such a pendulum is simple to calculate, even with Newtonian mechanics. When attaching a second pendulum to the mass of the first pendulum, we get a system widely known as the "double pendulum." The double pendulum system is widely known to be a chaotic system, meaning a small difference in initial conditions results in widely different motion after a period of time. Figure \ref{fig:1} is an example of such a system. This method can be continued, adding more and more pendulums, creating a "pendulum chain"--an N pendulum system.

To simplify the problem, we define our system while leaving a number of things constant. Our pendulums will have massless rods of constant length $l$, with a mass $m$ at the end of each rod, or at the "joint" between two pendulums. Each pendulum will be defined by a single angle $\theta_i$, the angle of the pendulum rod from the vertical.

\begin{figure}[h]
	\caption{Example double pendulum system with labeled components.}
	\label{fig:1}
	\begin{center}
		\begin{asy}
		pair R,A,B,AY,BY;
		real TA,TB,L;
		L = 100; // length
		astyscale = 15;

		R = (0,0);
		TA = 45;
		A = R+dir(270+TA)*L;
		AY = (R.x, A.y);
		TB = -30;
		B = A+dir(270+TB)*L;
		BY = (A.x, B.y);

		pen guide = linetype(new real[] {0,5});

		draw(R--A--B);
		draw(astyangle(AY, R, A));
		draw(astyangle(B, A, BY));
		draw(astycomponents(R, A), guide);
		draw(astycomponents(A, B), guide);

		label("$R$", R, -dir(270+TA));
		label("$A$", A, E);
		label("$B$", B, dir(270+TB));
		label("$l$", R--A, dir(TA));
		label("$l$", A--B, -dir(TB));
		label("$y_1$", (R.x, A.y)--R, W);
		label("$x_1$", (R.x, A.y)--A, S);
		label("$y_2$", (A.x, B.y)--A, E);
		label("$x_2$", (A.x, B.y)--B, S);
		label("$\theta_1$", R+dir(270+TA/2)*astyscale, dir(270+TA/2));
		label("$\theta_2$", A+dir(270+TB/2)*astyscale, dir(270+TB/2));
		\end{asy}
	\end{center}
\end{figure}

\section{Lagrangian Approach}
In contrast to the limitations of the Newtonian Free Body Diagram approach to calculating propogated forces amongst an $n$-pendulum system, the use of Lagrangian Mechanics does not require an analysis of forces. Instead, the total potential and kinetic energy in the system is used to determine equations of motion for each pendulum in the system.
\subsection{Derivation of Equations of Motion for Finite \texorpdfstring{$n$}{n}}
The use of the lagrangian method requires on two main parts: defining constraints and variables, and using them to create equations of motion.
\subsubsection{Deriving the Lagrangian \texorpdfstring{$L=T-V$}{L=T-V}}
We begin by defining the kinematic constraints of our problem.
\begin{align*}
	x_i &= x_{i-1} + l\sin{\theta_i}\\
	&= l\sum_{k=1}^i\sin{\theta_k}\\
	y_i &= y_{i-1} - l\cos{\theta_i}\\
	&= -l\sum_{k=1}^i\cos{\theta_k}
\end{align*}
Note that $y_i$ is negative, because $\theta_i$ is to the negative vertical. Next we derive the velocities. These can be calculated simply by taking the derivative of the positions.
\begin{align*}
	\dot x_i &= \dot x_{i-1} + \dot\theta_i \cdot l\cos{\theta_i}\\
	&= l\sum_{k=1}^i\dot\theta_k\cos{\theta_k}\\
	\dot y_i &= \dot y_{i-1} + \dot\theta_i \cdot l\sin{\theta_i}\\
	&= l\sum_{k=1}^i\dot\theta_k\sin{\theta_k}
\end{align*}
Plugging these in, we can calculate the total potential energy $V=mgh$ and the total kinetic energy $T=\frac{1}{2}mv^2$. First, we solve for $V$ and simplify:
\begin{align*}
	V &= mg\sum_{i=1}^n y_i \\
	&=-mgl\sum_{i=1}^n\sum_{k=1}^i\cos\theta_k
	&\text{(Substitute in $y_i$)}\\
	&=-mgl\sum_{i=1}^n (n-i+1)\cos\theta_i
	&\text{(Each element $\cos\theta_i$ appears $(n-i+1)$ times)}\\
\end{align*}
And we can do the same with $T$, substituting in $v^2=\sum_{i=1}^n\left(\dot{x}_i^2+\dot{y}_i^2\right)$.
\begin{align*}
	T &= \frac{m}{2}\sum_{i=1}^n \left(\dot{x}_i^2+\dot{y}_i^2\right)\\
	&= \frac{ml^2}{2}\sum_{i=1}^n \left(\left(\sum_{k=1}^i\dot\theta_k\cos{\theta_k}\right)^2+\left(\sum_{k=1}^i\dot\theta_k\sin{\theta_k}\right)^2\right)
	&\text{(Substitute in $\dot x_i$ and $\dot y_i$)}\\
	&= \frac{ml^2}{2}\sum_{i=1}^n \sum_{j=1}^i\sum_{k=1}^i\dot\theta_j\dot\theta_k\left(\cos{\theta_j}\cos{\theta_k}+\sin{\theta_j}\sin{\theta_k}\right)
	&\text{(Expand squared sums)}\\
	&= \frac{ml^2}{2}\sum_{i=1}^n \sum_{j=1}^i\sum_{k=1}^i\dot\theta_j\dot\theta_k\cos(\theta_j-\theta_k)
	&\text{(Simplify using $\cos$ addition formula)}\\
	&= \frac{ml^2}{2} \sum_{j=1}^n\sum_{k=1}^n(n-\max(j,k)+1)\dot\theta_j\dot\theta_k\cos(\theta_j-\theta_k)
	&\text{(Simplify out first sum)}\\
\end{align*}
Next, we can plug $T$ and $V$ into the lagrangian, giving us the following:
\begin{align*}
	L &= T-V \\
	&=  \frac{ml^2}{2} \sum_{j=1}^n\sum_{k=1}^n(n-\max(j,k)+1)\dot\theta_j\dot\theta_k\cos(\theta_j-\theta_k) + mgl\sum_{i=1}^n (n-i+1)\cos\theta_i\\
\end{align*}
\subsubsection{Utilizing the Euler-Lagrange Equation}
Now that we have our $L$ expression, we can use this to solve for the angular acceleration of each pendulum using the Euler-Lagrange Equation. We start with the equation $0 = \frac{d}{dt}\left(\frac{\partial L}{\partial \dot \theta_i}\right) - \frac{\partial L}{\partial \theta_i}$, and we will use this equation to solve for all $\ddot\theta_i.$

First, we try to solve for $\frac{\partial L}{\partial \dot \theta_i}$ by taking a derivative of $L$ with respect to $\dot\theta_i$. We first make an important observation: all terms in multiple sums of $L$ that do not contain $\dot\theta_i$ can be treated as a constant, and will be removed. We immediately can remove $V,$ which leaves us with the $T$ term. Because $\dot\theta_i$ appears if and only if $j=i$ or $k=i$, we can simplify our equation much further. We can arbitrarily plug in $j=i$ or $k=i$ into our equation. Before this, however, we must separate our sum due to the special case $i=i$. Firstly, the term simplifies to $\dot\theta_i^2$ when $i=i,$ which cannot be differentiated while treating one of the $\dot\theta_i$ as a constant. It is also the only term that would be double counted if we had kept the simple single sum and doubled it. This gives us 3 cases, one for $i=i,$ one for $1\leq k\le i$ and finally for $i+1\leq k \leq n$. The latter two are counted twice, once as $\dot\theta_i\dot\theta_k$ and once as $\dot\theta_k\dot\theta_i,$ thus we need a factor of two before both sums. This gives us the following, which we can further simplify:
\begin{align*}
&\frac{ml^2}{2}\frac{\partial L}{\partial \dot \theta_i}\left((n-i+1)\dot\theta_i^2 + 2\sum_{k=1}^{i-1}(n-i+1)\dot\theta_i\dot\theta_k\cos(\theta_i-\theta_k)\right.\\
&\qquad\qquad+ \left.2\sum_{k=i+1}^n(n-k+1)\dot\theta_i\dot\theta_k\cos(\theta_i-\theta_k)\right)\\
&= ml^2\left((n-i+1)\dot\theta_i + (n-i+1)\sum_{k=1}^{i-1}\dot\theta_k\cos(\theta_i-\theta_k)\right.\\
&\qquad\qquad+ \left.\sum_{k=i+1}^n(n-k+1)\dot\theta_k\cos(\theta_i-\theta_k)\right)
\end{align*}
Next we take the derivative with respect to time:
\begin{align*}
&= ml^2\frac{d}{dt}\left((n-i+1)\dot\theta_i + (n-i+1)\sum_{k=1}^{i-1}\dot\theta_k\cos(\theta_i-\theta_k)\right.\\
&\qquad\qquad+ \left.\sum_{k=i+1}^n(n-k+1)\dot\theta_k\cos(\theta_i-\theta_k)\right)\\
&= ml^2\left((n-i+1)\ddot\theta_i + (n-i+1)\sum_{k=1}^{i-1}\left(\ddot\theta_k\cos(\theta_i-\theta_k)-\dot\theta_k(\dot\theta_i-\dot\theta_k)\sin(\theta_i-\theta_k)\right)\right.\\
&\qquad\qquad+ \left.\sum_{k=i+1}^n(n-k+1)\left(\ddot\theta_k\cos(\theta_i-\theta_k)-\dot\theta_k(\dot\theta_i-\dot\theta_k)\sin(\theta_i-\theta_k)\right)\right)\\
\end{align*}
Because $\cos(\theta_i-\theta_i)=1$ and $\sin(\theta_i-\theta_i)=0$, we can combine these sums back into one, reducing our expression back to
$$ml^2\sum_{k=1}^n(n-\max(i,k)+1)\left(\ddot\theta_k\cos(\theta_i-\theta_k)-\dot\theta_k(\dot\theta_i-\dot\theta_k)\sin(\theta_i-\theta_k)\right).$$
Note that the derivative could not be taken from the outset, as that would ignore the special case altogether, as well as the double counting occuring in the other cases.

Now that we have the $\frac{d}{dt}\left(\frac{\partial L}{\partial \dot\theta_i}\right)$ term, we want to get $\frac{\partial L}{\partial \theta_i}$ in order to finish our Euler-Lagrange Equation. We approach this with the same method: simplifying our equation for $L$ with only the terms consisting of $\theta_i$. For $T$, we have the same situation: a term only contains $\theta_i$ when $j=i$ or $k=i$. This gives us a similar equation, but one where $\dot\theta_i^2$ can be removed. This time, however, we must also consider $V$. $V$ is easy to simplify: the only term with $\theta_i$ is simply the $ith$ term of the sum. This gives us the following equation:
\begin{align*}
&\frac{ml^2}{2}\frac{\partial L}{\partial \theta_i}\left(2\sum_{k=1}^{i-1}(n-i+1)\dot\theta_i\dot\theta_k\cos(\theta_i-\theta_k)\right.\\
&\qquad\qquad+ \left.2\sum_{k=i+1}^n(n-k+1)\dot\theta_i\dot\theta_k\cos(\theta_i-\theta_k)\right)\\
&\qquad\qquad+ \frac{\partial L}{\partial \theta_i}\left(mgl(n-i+1)\cos\theta_i\right)\\
&=-ml^2\left(\sum_{k=1}^{i-1}(n-i+1)\dot\theta_i\dot\theta_k\sin(\theta_i-\theta_k)\right.\\
&\qquad\qquad+ \left.\sum_{k=i+1}^n(n-k+1)\dot\theta_i\dot\theta_k\sin(\theta_i-\theta_k)\right)\\
&\qquad\qquad- mgl(n-i+1)\sin\theta_i\\
\end{align*}
Using the same reduction as before ($\sin(0)=0$), we can combine the sums again to get a final equation of
$$-ml^2\sum_{k=1}^n\left((n-\max(i,k)+1)\dot\theta_i\dot\theta_k\sin(\theta_i-\theta_k)\right) - mgl(n-i+1)\sin\theta_i.$$

Plugging all of this into the Euler-Lagrange equations and simplifying, we get our final equation.
\begin{align*}
0&=ml^2\sum_{k=1}^n(n-\max(i,k)+1)\left(\ddot\theta_k\cos(\theta_i-\theta_k)-\dot\theta_k(\dot\theta_i-\dot\theta_k)\sin(\theta_i-\theta_k)\right)\\
&\qquad\qquad+ ml^2\sum_{k=1}^n\left((n-\max(i,k)+1)\dot\theta_i\dot\theta_k\sin(\theta_i-\theta_k)\right) + mgl(n-i+1)\sin\theta_i\\
&=ml^2\sum_{k=1}^n(n-\max(i,k)+1)\left(\ddot\theta_k\cos(\theta_i-\theta_k)-\dot\theta_k(\dot\theta_i-\dot\theta_k)\sin(\theta_i-\theta_k)+\dot\theta_i\dot\theta_k\sin(\theta_i-\theta_k)\right)\\
&\qquad\qquad+ mgl(n-i+1)\sin\theta_i\\
&=ml^2\sum_{k=1}^n(n-\max(i,k)+1)\left(\ddot\theta_k\cos(\theta_i-\theta_k)+\dot\theta_k^2\sin(\theta_i-\theta_k)\right)\\
&\qquad\qquad+ mgl(n-i+1)\sin\theta_i\\
\end{align*}
Because we can substitute into this equation with all $1\leq i\leq n$, we end up with a system of equations with $n$ variables and $n$ equations, which we can solve to calculate the acceleration of each.
\subsection{Generalization to an Infinite Rope}
Now that we have our derivation with a finite rope, we generalize this to an infinite rope, with a constant finite mass and density. We define our mass-density of the total rope with $\frac{M}{L}$, such that $M$ is the total mass of the rope, $L$ is the total length of the rope, and $\frac{dm}{dl} = \frac{M}{L}$. Otherwise, we also need to define the function $\theta_l=\theta(l),$ which gives us the angle $\theta$ given a length $l$ along the rope. While the final Euler-Lagrange equation can be simply converted from the one derived in the finite set, the very similar infinite derivation is also included below.
\subsubsection{Deriving the Lagrangian \texorpdfstring{$L=T-V$}{L=T-V}}
Once again, we start with the kinematic constraints.
\begin{align*}
	x_i &= L\int_0^i\sin\theta_ldl\\
	y_i &= -L\int_0^i\cos\theta_ldl
\end{align*}
Next, we calculate the velocities simply by taking the derivative of their position.
\begin{align*}
	\dot x_i &= L\int_0^i\dot\theta_l\cos\theta_ldl\\
	\dot y_i &= L\int_0^i\dot\theta_l\sin\theta_ldl
\end{align*}
With these new equations, calculating the $T$ and $V$ terms becomes much simpler. Once again, we use the same starting equations, and simplify.
\begin{align*}
	V &= mg\int_0^L y_idi \\
	&=-mgL\int_0^L\int_0^i\cos{\theta_l}dldi
	&\text{(Substitute in $y_l$)}\\
	&=-mgL\int_0^L(L-l)\cos{\theta_l}dl
	&\text{(Reduce away inner integral)}
\end{align*}
We can do the same with $T$ as well.
\begin{align*}
	T &= \frac{m}{2}\int_0^L\left(\dot{x}_i^2+\dot{y}_i^2\right)di\\
	&= \frac{mL^2}{2}\int_0^L\left(\left(\int_0^i\dot\theta_l\cos\theta_ldl\right)^2+\left(\int_0^i\dot\theta_l\sin\theta_ldl\right)^2\right)di
	&\text{(Plug in values for sum)}\\
	&= \frac{mL^2}{2}\int_0^L\int_0^i\int_0^i\dot\theta_j\dot\theta_k\left(\cos\theta_j\cos\theta_k+\sin\theta_j\sin\theta_k\right)djdkdi
	&\text{(Simplify integrals)}\\
	&= \frac{mL^2}{2}\int_0^L\int_0^i\int_0^i\dot\theta_j\dot\theta_k\cos(\theta_j-\theta_k)djdkdi
	&\text{(Combine integrals)}\\
	&= \frac{mL^2}{2}\int_0^L\int_0^L(L-\max(j,k))\dot\theta_j\dot\theta_k\cos(\theta_j-\theta_k)djdk
	&\text{(Reduce outer integral)}\\
\end{align*}
Combining the two, we get our new $L$ value.
\begin{align*}
	L &= T-V \\
	&= \frac{mL^2}{2}\int_0^L\int_0^L(L-\max(j,k))\dot\theta_j\dot\theta_k\cos(\theta_j-\theta_k)djdk + mgL\int_0^L(L-l)\cos\theta_ldl\\
\end{align*}
\subsubsection{Utilizing Lagrange's Equations of Motion}
With our new $L$ value, we once again use this to solve Lagrange's equations of motion. This time we can ignore $i$, giving us $0 = \frac{d}{dt}\left(\frac{\partial L}{\partial \dot \theta}\right) - \frac{\partial L}{\partial \theta}$, and we will use this to find the function $\ddot\theta$.

Once again, we start by solving for $\frac{\partial L}{\partial \dot \theta}$ by taking a derivative of $L$ with respect to $\dot\theta$. We can use the same tricks as before, but this time the $i=i$ case does not need to be specially considered, as the integral is continuous and a single individual value makes an insignificant change to the whole.
\begin{align*}
&mL^2\frac{\partial L}{\partial \dot \theta_i}\left(\int_0^L(L-\max(i,k))\dot\theta_i\dot\theta_k\cos(\theta_i-\theta_k)dk\right)\\
&= mL^2\int_0^L(L-\max(i,k))\dot\theta_k\cos(\theta_i-\theta_k)dk
\end{align*}
Again, we take the derivative with respect to time:
\begin{align*}
&= mL^2\frac{d}{dt}\int_0^L(L-\max(i,k))\dot\theta_k\cos(\theta_i-\theta_k)dk\\
&= mL^2\int_0^L(L-\max(i,k))\left(\ddot\theta_k\cos(\theta_i-\theta_k)-\dot\theta_k(\dot\theta_i-\dot\theta_k)\sin(\theta_i-\theta_k)\right)dk
\end{align*}
With $\frac{d}{dt}\left(\frac{\partial L}{\partial \dot\theta_i}\right)$ finished, we once again calculate the remaining term $\frac{\partial L}{\partial \theta_i}$.
\begin{align*}
&mL^2\frac{\partial L}{\partial \theta_i}\left(\int_0^L(L-\max(i,k))\dot\theta_i\dot\theta_k\cos(\theta_i-\theta_k)dk\right) + \frac{\partial L}{\partial \theta_i}mgL(L-i)\cos\theta_i\\
&= mL^2\int_0^L(L-\max(i,k))\dot\theta_i\dot\theta_k\sin(\theta_i-\theta_k)dk - mgL(L-i)\sin\theta_i\\
\end{align*}
Now, we combine this back into the Euler-Lagrange equation, and simplify.
\begin{align*}
0&=mL^2\int_0^L(L-\max(i,k))\left(\ddot\theta_k\cos(\theta_i-\theta_k)-\dot\theta_k(\dot\theta_i-\dot\theta_k)\sin(\theta_i-\theta_k)\right)dk\\
&\qquad\qquad+ mL^2\int_0^L(L-\max(i,k))\dot\theta_i\dot\theta_k\sin(\theta_i-\theta_k)dk + mgL(L-i)\sin\theta_i\\
&=mL^2\int_0^L(L-\max(i,k))\left(\ddot\theta_k\cos(\theta_i-\theta_k)-\dot\theta_k(\dot\theta_i-\dot\theta_k)\sin(\theta_i-\theta_k) + \dot\theta_i\dot\theta_k\sin(\theta_i-\theta_k)\right)dk\\
&\qquad\qquad+ mgL(L-i)\sin\theta_i\\
&=mL^2\int_0^L(L-\max(i,k))\left(\ddot\theta_k\cos(\theta_i-\theta_k)+\dot\theta_k^2\sin(\theta_i-\theta_k)\right)dk+ mgL(L-i)\sin\theta_i\\
\end{align*}
We have our equation
$$0=mL^2\int_0^L(L-\max(i,k))\left(\ddot\theta_k\cos(\theta_i-\theta_k)+\dot\theta_k^2\sin(\theta_i-\theta_k)\right)dk+ mgL(L-i)\sin\theta_i$$
for all $i \in [0,L]$, which we next need to evaluate for all $\ddot\theta_i$.
\end{document}


\documentclass[handout]{beamer}
\usetheme{focus}
\usepackage{graphicx}
\usepackage{svg}
\usepackage{amssymb,amsmath}
\usepackage{dsfont}
\usepackage{caption}
\usepackage{subcaption}

\title{Graph eigenvectors estimation by random walk and diffusion}
\subtitle{A study of robustness}
\author{Hoang NT}
\titlegraphic{\includegraphics[scale=0.12]{imgs/spectrahedron.png}}
\institute{Murata Laboratory \\ Tokyo Tech \vspace{4em}}
\date{2018/10/24}

\begin{document}
    \begin{frame}
        \maketitle
    \end{frame}

    \begin{frame}{Overview}
        \tableofcontents
    \end{frame}

    \section{Stability problem}

    \subsection{Observation}

    \begin{frame}{Eigen-mass shift}
        Consider a "basically expander" graph G, except that it has two poorly connected components:
        \begin{figure}
            \centering
            \includegraphics[scale=0.5]{imgs/ex1_graph_unstable.png}
            \caption{Almost expander graph.}
            \label{fig:ex1_G_unstable}
        \end{figure}
        \pause
        The problem with this kind of graph is: It is easy to change the edge weights of the central part to make the "mass" of the leading non-trivial eigenvector on the first small component or the second component. \pause \textbf{Stability of eigendirection} is clearly an issue.

    \end{frame}
    \begin{frame}{Example}
        Graph $G$ having 13 nodes, by removing edge (0,1) we get $G'$:
        \begin{figure}
        \centering
        \begin{subfigure}{.5\textwidth}
          \centering
          \includegraphics[width=.45\linewidth]{imgs/ex2_graph_13_full.pdf}
          \caption{Original graph ($G$)}
          \label{fig:ex2_graph_full}
        \end{subfigure}%
        \begin{subfigure}{.5\textwidth}
          \centering
          \includegraphics[width=.45\linewidth]{imgs/ex2_graph_13.pdf}
          \caption{Perturbed graph ($G'$)}
          \label{fig:ex2_graph_pert}
        \end{subfigure}
        \caption{Almost expander graphs.}
        \label{fig:ex2}
        \end{figure}
        The two first non-trivial eigenvectors of these graphs are:
        \tiny
        \begin{align*}
        v^G_1 &=
             \begin{bmatrix}
                -0.208 & -0.286 & -0.275 & -0.275 & -0.275 & -0.212 & -0.275 & 0.225 & 0.394 & 0.395 & 0.126 &  0.221 &  0.221 & 0.221
             \end{bmatrix} \\
        v^{G'}_1 &=
             \begin{bmatrix}
                0.194 & 0.307 & 0.275 & 0.275 & 0.275 & 0.208 & 0.275 & -0.224 & -0.387 & -0.387 & -0.131 & -0.226 & -0.226 & -0.226
             \end{bmatrix} \\
        \end{align*}
    \end{frame}

    \begin{frame}{Similar problem in Linear Program}
        Consider an optimization problem:
        $$ \min_{x \in \mathcal{S}} f(x) $$
        \pause
        This problem might not be "well-posed", so we add a \textit{regularization} term $\lambda g(x)$:
        $$ \min_{x \in \mathcal{S}} f(x) + \lambda g(x) $$
        \pause
        If we choose $g(x)$ to be strongly convex ($\sigma$-strongly convex), we can obtain: increased stability; \pause decreased sensitivity to noise; \pause and avoid overfitting.
    \end{frame}

    \subsection{Effectiveness of approximation methods}
    \begin{frame}{Practical approximation methods}
    In theory, eigenvectors provide a nice way for graph analysis. \pause However, spectral clustering methods are usually worse than heuristic/approximation-based methods \cite{perozzi2014deepwalk,leskovec2008statistical}.\linebreak
    \\
    \pause
    \noindent
    Hence, there must be some form of \textbf{implicit} regularization for each of these heuristic algorithms.
        \begin{block}{Research question}
            To what extent can one formaliza the idea that performing an approximate computation can implicitly lead to more regular solutions? \cite{mahoney2010implementing}. \vspace{0.5em}
        \end{block}
    \end{frame}

    \section{Implicit regularizations}

    \subsection{Problem definition}

    \begin{frame}{Aim}
        The aim of paper \cite{mahoney2010implementing} is to connect the solution of a regularized SDP problem to three diffrent commonly used random walk heuristics:
        \begin{description}
        \item[Heat Kernel]
        An operator describing the diffusive spreading of heat on the graph.
        $$ H_t = \exp{(-tL)} = \sum_{k=0}^{\inf} \frac{(-t)^k}{k!}L^k $$
        \pause
        \item[PageRank]
        The PageRank vector is given by:
        $$ \pi(\gamma, s) = \gamma s + (1-\gamma)M\pi(\gamma,s) $$
        \pause
        \item[TLRW]
        $M = AD^{-1}$ is the natural random walk transition matrix, the Truncated $\alpha$-Lazy Random Walk matrix is given by:
        $$ W_\alpha = \alpha I + (1-\alpha)M $$
        \end{description}
    \end{frame}

    \begin{frame}{SPECTRAL problem}
        \pause
        Consider the standard SPECTRAL problem:
        \begin{equation*}
            \begin{array}{ll@{}ll}
            \text{min} & x^TLx \\
            \text{s.t.}& x^Tx = 1\\
                       & x^TD^{1/2}1 = 0
            \end{array}
        \end{equation*}
        \pause
        This problem is \textit{equivalent} to a SDP:
        \begin{equation*}
            \begin{array}{ll@{}ll}
            \text{min} & L \cdot X \\
            \text{s.t.}& Tr(X) = I \cdot X = 1\\
                       & X \succeq 0
            \end{array}
        \end{equation*}
        \pause
    The exact solution for SDP is when $X$ is rank-1, i.e. $X=xx^T$. However, when the solution is not rank-1, a simple way to construct a vector $x$ from $X$ is to sample $\xi \backsim N(0,1/n)$ and build $x = X^{1/2} \xi$.
    \end{frame}

    \begin{frame}{Regularized SDP}
        Consider the form:
        \begin{equation*}
            \begin{array}{ll@{}ll}
            (F,\eta) - SDP & \text{min} & L \cdot X + \frac{1}{\eta} F(X) \\
                           & \text{s.t.}& I \cdot X = 1\\
                           &            & X \succeq 0
            \end{array}
        \end{equation*}

        The authors of \cite{mahoney2010implementing} connects the regularization term $F(X)$ and approximation heuristic as follow:
        \pause
        \begin{itemize}
        \item When $F(X)$ is \textbf{von Neumann entropy}, the solution $X^{\ast}$ can be obtained by the \textbf{heat kernel}.
        \pause
        \item When $F(X)$ is \textbf{log-determinant}, the solution $X^{\ast}$ can be obtained by \textbf{PageRank}.
        \pause
        \item When $F(X)$ is \textbf{matrix p-norm}, the solution $X^{\ast}$ can be obtained by \textbf{truncated lazy random walk}.
        \end{itemize}
    \end{frame}

    \subsection{Solution to the regularized SPD}

    \begin{frame}{Solution to the regularized SPD}
        \begin{block}{Theorem 1 \cite{mahoney2010implementing}\vspace{0.5em}}
        Let $G$ be a connected, weighted, undirected graph, with normalized Laplacian $L$. Then, the following conditions are sufficient for $X^\ast$ to be an optimal solution to $(F,\eta) - SDP$.
        \begin{enumerate}
            \item $X^\ast = (\nabla F)^{-1}(\eta(\lambda^\ast I - L)), \text{for } \lambda^\ast \in \mathds{R}$,
            \item $I \cdot X^\ast = 1$,
            \item $X^\ast \succeq 0$.
        \end{enumerate}
        \vspace{0.5em}
        \end{block}
    \end{frame}

    \begin{frame}{Proof of theorem 1}
        \pause
        The proof is pretty straight-forward. Write the Lagrangian $\mathcal{L}$ as:        $$\mathcal{L} = L \cdot X + \frac{1}{\eta} \cdot F(X) - \lambda \cdot (I \cdot X - 1) - U \cdot X$$
        \pause
        Set the gradient of the Lagrangian w.r.t. X to 0:
        $$\nabla \mathcal{L} = L + \frac{1}{\eta}(\nabla F)X-\lambda I - U = 0 $$
        \pause
        The dual objective function is minimized when:
        $$X = (\nabla F)^{-1} (\eta (-L + \lambda^\ast I + U))$$
        \pause
        We choose $\lambda^\ast$ to satisfy the second condition. By Weak Duality ( primal problem solution is always greater than or equal to an associated dual problem solution), $X^\ast$ ($X$ with appropriate $\lambda^\ast$) is an optimal solution to $(F,\eta) - SDP$.
    \end{frame}

    \subsection{Plug the regularizer in!}

    \begin{frame}{Generalized Entropy and the Heat Kernel}
        \pause
        The generalized entropy function (also von Neumann entropy):
        $$F_H(X) = Tr(X \log{X}) - Tr(X) $$
        \pause
        for which:
        \begin{align*}
        (\nabla F_H)(X) &= \log{X}\\
        (\nabla F_H)^{-1}(Y) &= \exp{Y}.
        \end{align*}
        \pause
        Hence, the solution to $(F_H,\eta) - SDP$ is:
        $$X^\ast_H = \exp{(\eta (\lambda I - L)}$$
        \pause
        By setting $\lambda = -1/\eta \log{(Tr(exp(-\eta L)))}$, we have:
        $$X*\ast_H = \frac{H_\eta}{Tr(H_\eta)}$$.
    \end{frame}

    \begin{frame}{Log-determinant and PageRank}
        The log-determinant function is given by:
        $$F_D(X) = -\log{\det{X}}$$
        Similar to the previous manipulation, lemma 2 of \cite{mahoney2010implementing} showed that:
        $$X^\ast_D = \frac{D^{-1/2} R_\gamma D^{-1/2}}{Tr(R_\gamma)}$$
    \end{frame}

    \begin{frame}{p-norm and Truncated Lazy Random Walk}
        The p-norm function is given by:
        $$F_p(X) = \frac{1}{p} \parallel X \parallel^p_p = \frac{1}{p} Tr(X^p)$$
        Lemma 3 of \cite{mahoney2010implementing} showed that:
        $$X^\ast_p = \frac{D^{\frac{-(q-1)}{2}W_\alpha^{q-1}D^{\frac{q-1}{2}}}}{Tr(W_\alpha^{q-1})}$$
        Thus connecting the p-norm and the heuristic algorithms on TLRW matrix.
    \end{frame}

    \section{Conclusion}

    \subsection{Summary}
    \begin{frame}{Summary}
        \begin{figure}
            \centering
            \includegraphics[scale=0.7]{imgs/sum.png}
            \caption{Graphical summary.}
            \label{fig:sum}
        \end{figure}
    \end{frame}

    \subsection{Discussion}
    \begin{frame}{Discussion}
        The random-walk-based (also difussion-based) view provided several benefits:        \begin{itemize}
        \item Robustness and stability in computation
        \item Insight on how heuristic algorithms worked better than spectral methods.
        \end{itemize}
    \end{frame}

    \appendix
    \begin{frame}{References}
        \nocite{*}
        \bibliography{main}
        \bibliographystyle{plain}
    \end{frame}
\end{document}


% The ICIP2016 paper according to the given template
%          spconf.sty  - ICASSP/ICIP LaTeX style file, and
%          IEEEbib.bst - IEEE bibliography style file.
% --------------------------------------------------------------------------
\documentclass{article}
\usepackage{spconf,amsmath,graphicx}
\usepackage{enumitem}
\usepackage{verbatim}

% Definitions.
% --------------------
\def\B{{\mathbf B}}
\def\M{{\mathbf M}}
\def\I{{\mathbf I}}
\def\mcT{{\mathcal{T}}}
\def\mcD{{\mathcal{D}}}
\def\mcA{{\mathcal{A}}}
\def\mcL{{\mathcal{L}}}
\def\mcV{{\mathcal{V}}}
\def\p{{\mathbf p}}
\def\q{{\mathbf q}}
\def\r{{\mathbf r}}
\def\s{{\mathbf s}}
\def\S{{\mathbf S}}
\def\mcN{{\mathcal{N}}}
\DeclareMathOperator*{\argmax}{arg\,max}
% Title.
% ------
\title{A Data-driven Region Detector for Structured Image Scenes}
%
% Single address.
% ---------------
\name{Elena Ranguelova}
\address{Netherlands eScience Center\\ Amsterdam, The Netherlands}
%\\ e-mail: E.Ranguelova@esciencecenter.nl}

\begin{document}

\maketitle
\begin{abstract}

\end{abstract}

\section{Introduction}
\label{sec:intro}

\section{Data-driven Morphology Salient Regions Detection}
\label{sec:DMSR}

MSER and MSSR decompose a gray-scale image into binary cross-sections and evaluate the stability of the connected components (CCs) or accumulate saliency masks. DMSR starts with a data-driven binarization, producing one binary image and thus transforming the problem into a binary saliency.

\subsection{Binary Salient Regions Detection}
\label{ssec:binary}
We claim that the perceptual saliency in a binary image of a structured scene
 $\B: \mcD \subset \mathcal{Z}^2 \rightarrow \{0,1\}$ (1-white, 0-black)
is only due to the spatial layout of the image regions \cite{RangHumpb06}.
We have defined four types of salient regions called {\em holes, islands, indentations} and {\em protrusions}. The two types of {\em inner salient structures (ISS)} are {\em holes} -- set of connected black pixels entirely surrounded by white pixels, and {\em islands} -- set of connected white pixels surrounded by black ones, i.e.~inverse of holes. A significant connected component ${\cal B}^1$ is defined as a CC with area proportional to the image area by $\Lambda$. The radius of the morphological structuring element is $r$ and  the area opening parameter for  noise filtering is $\lambda$. In addition, the two {\em boundary salient structures (BSS)} are {\em protrusions}-- set of white pixels on the border of a significant CC, which if pinched off from the CC, will increase its boundary with no more than $2\pi r$, and the {\em indentations}-- inverse protrusions.

These four types are also valid for the MSSR detector. The regions are obtained from the binary image $\B$ by morphological operations: hole filling, top hat and area opening, for details see \cite{RangMSSR06, RangHumpb06}. The ISS are similar to the definition of the MSER+ and MSER- regions \cite{Matas2002BMVC}. In this paper, detectors using only ISS, i.e., directly comparable to MSER, are denoted by DMSR/MSSR, while DMSRA/MSSRA are detectors using all region types. These definitions are summarized in Table~\ref{table:binary_sal} and the exact shaped regions from a synthetic $100 \times 100$ binary image with parameters $\Lambda=100$, $r=5$ and $\lambda = 10$ are shown on Fig.~\ref{fig:binary_sal}.

%----------------------------------------------------------------------
\begin{table}[hbt]
\begin{minipage}[b]{0.99\linewidth}\begin{tabular}{|l l|}
\hline
{\bf ISS} & A CC $S^i_{fb} = \{\p \in \mcD, \forall \p=foreground,$\\&$\forall \q \in \partial S^i_{fb}, \q=background, \q \notin \partial \B $ \},\\
$2$ types & $S^i_{10}$ (islands), $S^i_{01}$  (holes); $\S^i = S_{01}^i \cup S_{10}^i$\\
{\bf BSS} &  $S_{fb}^b: \{\p \in S_{fb}^b \subset{\cal B}^f, \forall \p = foreground,$\\&$ \q \in \partial S_{fb}^b \subset {\partial \cal B}^f,\forall \q = background \}$, \\
& $|\partial {\cal B}^f| - |\partial ({\cal B}^f \backslash S_{fb}^b)| < 2 \pi r$\\
$2$ types & $S^b_{10}$ (protr.), $S^b_{01}$ (indent.); $\S^b = S_{01}^b \cup S_{10}^b$\\
{\bf Regions} &  $\S = \S^i$ (DMSR); $\S = \S^i \cup \S^b$ (DMSRA)  \\
\hline
\end{tabular}
\hfill
\centering
\caption{Binary saliency definitions used in Section \ref{ssec:binary}.}\label{table:binary_sal}
\end{minipage}
\vspace*{-0.4cm}
\end{table}
%----------------------------------------------------------------------
\begin{figure}[htb]
%\vspace{-0.5cm}
\begin{minipage}[b]{.49\linewidth}
  \centering
  \centerline{\includegraphics[width=5cm]{./Figs/binary_marks}}

\end{minipage}
%\hfill
\begin{minipage}[b]{0.49\linewidth}
  \centering
  \centerline{\includegraphics[width=5cm]{./Figs/binary_marks_clean_color_coded}}

\end{minipage}
\vspace{-0.5cm}
\caption{Binary salient regions detection.
Color coding: holes-blue, islands- yellow,
indentations - green, protrusions- red. }
\label{fig:binary_sal}
\end{figure}
%----------------------------------------------------------------------

\subsection{Data-driven binarization}
\label{ssec:binarize}
Any gray-scale image  $\I:~\mcD~\subset~\mathcal{Z}^2~\rightarrow ~\mcT $, where $\mcT=\{0,1,\ldots, t_{max}\}$ and $t_{max}~=~2^n-1~=~255$ is the maximum gray value encoded by $n~=~8$ bits, can be decomposed into cross-sections at
every possible level $t$:  $\I = \sum_{t \in \mcT}CS_t(\I)$. Obtaining a section at level $t$ is equivalent to thresholding the image at threshold $t$: $CS_t(\I)= 1.(\I>t) + 0.(\I<t)$ is a binary image.
Three sets of connected components in $CS_t(\I)$ are defined: $\mcA_t$- {\em all}, $\mcL_t$- the {\em large} and $\mcV_t$- the {\em very large} CCs.  The size of each CC category is defined by$\Lambda_{\mcL}$ and $\Lambda_{\mcV}$ fraction of the image area $A_{\I}$. Let us denote the normalized number of elements in a set ($|\cdot|$) by $\Vert \cdot \Vert = |\cdot| / \max_{t \in \mcT}|\cdot|$.
Finding the optimal threshold $t_{opt}$ is then defined as:
\begin{equation*}
\vspace{-0.05cm}
t_{opt} = \argmax_{t \in \mcT}( w^{\mcA} \Vert \mcA_t \Vert + w^{\mcL} \Vert \mcL_t \Vert + w^{\mcV} \Vert \mcV_t \Vert ),
\vspace{-0.05cm}
\end{equation*}
where $w^{\cdot}$ are the weights per set of CCs.

The standard Otsu thresholding does not select a single stable $CS$, while choosing $t_{opt}$ ensures stable number of regions across transformations (see Figs.~\ref{fig:binary_hist} and \ref{fig:leuven_bin} for lighting).
%------------------------------------------------------------------------
%\vspace{-0.8cm}
\begin{figure}[htb]

\begin{minipage}[b]{0.49\linewidth}
  \centering
  \centerline{\includegraphics[width=4.65cm]{./Figs/hist_otsu_leuven_1_4}}
  \centerline{(a) Otsu}\medskip
\end{minipage}
\hfill
%\vspace{-0.5cm}
\begin{minipage}[b]{0.49\linewidth}
  \centering
  \centerline{\includegraphics[width=4.8cm]{./Figs/hist_numcc_leuven_1_4}}
\centerline{(b) Max number CC}\medskip
\end{minipage}
\hfill
\vspace{-0.5cm}
\caption{Finding the optimal threshold for two images from the 'Leuven' sequence
(Oxford dataset, lighting): the base image- solid black line, the forth image - dotted blue line.}
\label{fig:binary_hist}
%
\end{figure}
%------------------------------------------------------------------------
%\vspace{-0.5cm}

\begin{figure}[htb]

\begin{minipage}[b]{.3\linewidth}
  \centering
  \centerline{\includegraphics[width=2.8cm]{./Figs/leuven1}}
%  \vspace{1.5cm}
%   \centerline{(a)}\medskip
\end{minipage}
\hfill
\begin{minipage}[b]{0.3\linewidth}
  \centering
  \centerline{\includegraphics[width=2.7cm]{./Figs/leuven1_otsu}}
%  \vspace{1.5cm}
  % \centerline{(b)}\medskip
\end{minipage}
\hfill
\begin{minipage}[b]{0.3\linewidth}
  \centering
  \centerline{\includegraphics[width=2.7cm]{./Figs/leuven1_numcc}}
%  \vspace{1.5cm}
  % \centerline{(c)}\medskip
\end{minipage}

\begin{minipage}[b]{.3\linewidth}
  \centering
  \centerline{\includegraphics[width=2.7cm]{./Figs/leuven4}}
%  \vspace{1.5cm}
   \centerline{(a)}\medskip
\end{minipage}
\hfill
\begin{minipage}[b]{0.3\linewidth}
  \centering
  \centerline{\includegraphics[width=2.7cm]{./Figs/leuven4_otsu}}
%  \vspace{1.5cm}
   \centerline{(b)}\medskip
\end{minipage}
\hfill
\begin{minipage}[b]{0.3\linewidth}
  \centering
  \centerline{\includegraphics[width=2.7cm]{./Figs/leuven4_numcc}}
%  \vspace{1.5cm}
   \centerline{(c)}\medskip
\end{minipage}

 \vspace{-0.5cm}
\caption{Binarization of two images of the 'Leuven' sequence (lighting). Top row- base image, bottom row- forth image;   (a) gray scale; (b) Otsu binarization, (c) proposed binarization.}
\label{fig:leuven_bin}
%
\end{figure}
%------------------------------------------------------------------------

After the data-driven binarization, the DMSR detector finds the set of affine-covariant regions $\S$ from the single binary image $CS_{t_{opt}}$ as was described in Section \ref{ssec:binary} and \cite{RangMSSR06, RangHumpb06}. DMSR produces fewer non-overlapping and perceptually salient regions (visualized by their equivalent ellipses, not exact shapes) compared to MSER (see Figures~\ref{fig:det_graffiti} and \ref{fig:wood}).

\section{Performance  Evaluation}
\label{sec:perf}
{\em performance evaluation here...}
%------------------------------------------------------------------------
\begin{figure}[htb]

\begin{minipage}[b]{.49\linewidth}
  \centering
  \centerline{\includegraphics[width=4.0cm]{./Figs/mserGraffiti1}}
 % \vspace{0.2cm}
 % \centerline{(a) MSER}\medskip
\end{minipage}
\hfill
\begin{minipage}[b]{0.49\linewidth}
  \centering
  \centerline{\includegraphics[width=4.0cm]{./Figs/dmsrGraffiti1}}
 % \vspace{0.2cm}
 % \centerline{(b) DMSR}\medskip
\end{minipage}
\vspace{-0.25cm}
\caption{Region detectors on the base image of the 'Graffiti' sequence, Oxford dataset. Left: MSER, right: DMSR}
\label{fig:det_graffiti}
%
\end{figure}
%------------------------------------------------------------------------
\begin{figure}[htb]

\begin{minipage}[b]{.49\linewidth}
  \centering
  \centerline{\includegraphics[width=4.0cm]{./Figs/mserWood}}
 % \vspace{0.2cm}
 % \centerline{(a) MSER}\medskip
\end{minipage}
\hfill
\begin{minipage}[b]{0.49\linewidth}
  \centering
  \centerline{\includegraphics[width=4.0cm]{./Figs/dmsrWood}}
 % \vspace{0.2cm}
 % \centerline{(b) DMSR}\medskip
\end{minipage}
%\vspace{-0.25cm}
\caption{Salient region detectors on microscopy wood images. Left: MSER (every second region is shown), right: DMSR}
\label{fig:wood}
%
\end{figure}
%\vspace{-0.5cm}

% To start a new column (but not a new page) and help balance the last-page
% column length use \vfill\pagebreak.
% -------------------------------------------------------------------------
%\vfill
%\pagebreak

%\section{REFERENCES}
%\label{sec:ref}

% References should be produced using the bibtex program from suitable
% BiBTeX files (here: strings, refs, manuals). The IEEEbib.bst bibliography
% style file from IEEE produces unsorted bibliography list.
% -------------------------------------------------------------------------
\bibliographystyle{IEEEbib}
\bibliography{icip2016}

\end{document}


\section{Getting Radiation Right in our Climate Model! 3D Motion Here We Come} \label{sec:stream8}
The time has come to finally fix 3D motion. For this to work, we need to use a radiation scheme, which Simon \sout{shamelessly stole} got inspired by the Isca project \cite{isca}. So he followed
the references and found a paper which he is going to use in our model \cite{greyRad}. Great, so let's get into it shall we.

\subsection{Grey Radiation Scheme}
A radiation scheme is a model for how energy is redistributed using light in a system. Such a model is a Grey radiation scheme if you split it into two parts, short and long wavelength radiation.
So you have two redistribution systems, one for short wavelength light and one for long wavelength light. Another assumption we make when using the Grey radiation scheme, is that the atmosphere
is transparent to short wavelength radiation, meaning it lets through light with short wavelengths. Additionally we use a two stream approximation, which means that we have a stream of radiation
going up, and another stream of radiation going down. Note that these two streams are both long wavelength radiation, because we said earlier we assume the atmosphere completely ignores short
wavelength radiation.

The two long wavelength radiation streams are described in \autoref{eq:upward radiation} and \autoref{eq:downward radiation} \cite{greyRad}. In those equations, the symbols are:

\begin{itemize}
    \item $U$: Upward flux.
    \item $D$: Downward flux.
    \item $B$: The Stefan-Boltzmann equation (see \autoref{eq:stefan-boltzmann}).
    \item $\tau$: Optical depth.
\end{itemize}

\begin{subequations}
    \begin{equation}
        \frac{dU}{d\tau} = U - B
        \label{eq:upward radiation}
    \end{equation}
    \begin{equation}
        \frac{dD}{d\tau} = B - D
        \label{eq:downward radiation}
    \end{equation}
\end{subequations}

With \autoref{eq:upward radiation} and \autoref{eq:downward radiation} written down, we can discuss how they work. These equations need a boundary condition to work, a starting point if you like.
For those equations the boundary conditions are that $U$ is at the surface equal to $B$ and that $D$ at the top of the atmosphere is equal to $0$. Meaning that in the beginning the top of the
atmosphere has no downward flux as there is no heat there, and that the bottom of the atmosphere has a lot of upward flux as most if not all of the heat is located there. Then after the spin up
time this should stabilise. We are interested in the change of the fluxes, so $dU$ and $dD$, to get those we need to multiply the right hand side by $d\tau$. Then we have the flow of radiation
that we need. However we cannot solely use these two equations to calculate the heat of a given layer. For that we need a few more components. These are described in \autoref{eq:heat layer}.
Here $Q_R$ is the amount of heat in a layer, $c_p$ is the specific heat capacity of dry air (our atmosphere), $\rho$ is the density of the air in that layer and $\delta z$ is the change in height.
$\delta U - D$ are the change in net radiation, meaning the amount of radiation that is left over after you transferred the upward and downward flux. See it as incoming and outgoing energy for a
given layer, the net change (either cooling down or heating up) is what remains after you have subtracted the incoming energy from the outgoing energy. While this explanation is not entirely true
(as flux is not entirely equivalent to energy), it explains the concept the best.

\begin{equation}
    Q_R = \frac{1}{c_p\rho}\frac{\delta(U - D)}{\delta z}
    \label{eq:heat layer}
\end{equation}

Now only one question remains: what is optical depth? Optical depth is the amount of work a photon has had to do to get to a certain point. This might sound really vague, but bear with me.
Optical depth describes how much stuff a certain photon has had to go through to get to a point. As you'd expect this is $0$ at the top of the atmosphere as space is a big vacuum so no stuff to
move through, so no work. Then the further the photon moves into the atmosphere, the more work the photon has had to do to get there. This is because it now needs to move through gases, like air,
water vapour and other gases. Hence the closer the photon gets to the surface of the planet, the larger the optical depth is because the photon has had to work more to get there. This phenomenon
is described in \autoref{eq:optical depth}. The symbols in the equation mean:

\begin{itemize}
    \item $\tau_0$: Optical depth at the surface.
    \item $p$: Atmospheric pressure ($Pa$).
    \item $p_s$: Atmospheric pressure at the surface ($Pa$).
    \item $f_l$: The linear optical depth parameter, with a value of 0.1.
\end{itemize}

\begin{equation}
    \tau = \tau_0[f_l(\frac{p}{p_s}) + (1 - f_l)(\frac{p}{p_s})^4]
    \label{eq:optical depth}
\end{equation}

As one can see, \autoref{eq:optical depth} has two parts, a linear part and a quatric part (to the power $4$). The quatric term approximates the structure of water vapour in the atmosphere, which
roughly scales with $\frac{1}{4}$ with respect to the height. The linear term is present to fix numerical behaviour because this is an approximation which will not be completely correct (that's
why it is an approximation) so we add this term to make it roughly right. The same thing holds for $f_l$ which can be manually tuned to fix weird numerical behaviour.

\subsection{Getting the equations to code}
With these equations in our mind, let's get coding. First we add the pressure profile, the pressure of all atmospheric layers at a lat lon point. We need this to accurately represent the optical
depth per atmospheric layer. Then we need to use the pressure profile with regards to \autoref{eq:optical depth}. The resulting code can be found in \autoref{alg:optical depth}. This algorithm
replaces the temperature calculations we have done in \autoref{alg:temperature layer}, as this is basically a better version of the calculations done in that algorithm. $f_l$ has a value of $0.1$
and is located near all the other constants in the code, henceforth we will refer to this section in the code as the control panel, since most if not all of the constants can be tweaked here.
$\tau_0$ is a function that gives the surface optical depth for a given latitude. The corresponding equation can be found in \autoref{eq:optical depth surface} \cite{simon}. Translating this
into code is left as an exercise to the reader. $U[0]$ is the boundary condition discussed before (being the same as \autoref{eq:stefan-boltzmann}), just as $D[nlevels]$ is the boundary condition.
$S_z$ represents the call to \autoref{alg:gradient z layer}. \texttt{solar} represents the call to \autoref{alg:solar}.

\begin{algorithm}
    \For{$lat \in [-nlat, nlat]$}{
        \For{$lon \in [0, nlon]$}{
            $pressureProfile \leftarrow p[i,j,:]$ \;
            $\tau = \tau_0(lat)f_l\frac{pressureProfile}{pressureProfile[0]} + (1 - f_l)(\frac{pressureProfile}{pressureProfile[0]})^4)$ \;
            $U[0] \leftarrow \sigma T_p[lat, lon]^4$ \;

            \For{$level \in [1, nlevels]$}{
                $U[level] \leftarrow U[level - 1] - \frac{(\tau[level] - \tau[level - 1])(\sigma \cdot (mean(T_a[:, :, level]))^4)}{1 + (\tau[level - 1] - \tau[level])}$ \;
            }

            $D[nlevels - 1] \leftarrow 0$ \;

            \For{$level \in [nlevels - 1, 0]$}{
                $D[level] \leftarrow D[level + 1] - \frac{(\tau[level + 1] - \tau[level])(\sigma \cdot (mean(T_a[:, :, level]))^4)}{1 + (\tau[level] - \tau[level + 1])}$ \;
            }

            \For{$level \in [0, nlevels]$}{
                $Q[level] \leftarrow - \frac{S_z(U - D, 0, 0, level)}{10^3 \cdot densityProfile[level]}$ \;
            }

            $T_a[lat, lon, :] \leftarrow T_a[lat, lon, :] + Q$ \;

            $S \leftarrow \texttt{solar}(I, lat, lon, t)$ \;

            $T_p[lat, lon] \leftarrow T_p[lat, lon] \frac{\delta t((1 - a[lat, lon]) S + S_z(D, 0, 0, 0) - \sigma T_p[lat, lon]^4)}{C_p[lat ,lon]}$ \;
        }
    }
    \caption{Adding in radiation}
    \label{alg:optical depth}
\end{algorithm}

\begin{equation}
    \tau_0 = 3.75 + \cos(lat \frac{\pi}{90})\frac{4.5}{2}
    \label{eq:optical depth surface}
\end{equation}

%Note that in this form, it did not work on stream yet. This may be due to a coding error or to a missing equation, constant or something similar. If it turns out to be a simple fix, then it will
%be fixed in this section. If a lot of other things change in order for the fix to work, then it will probably be a seperate section with a reference to that section here.


\documentclass[12pt]{article}
\usepackage[noanswer]{exercise}
\usepackage[]{amsthm}
\usepackage[]{amsmath}
\usepackage[]{hyperref}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{proposition}{Proposition}
\newtheorem{corollary}{Corollary}

\theoremstyle{definition}
\newtheorem{definition}{Definition}

% I don't like how the "exercise" package normally lays things out.
% Feel free to copy this if you agree.
\renewcommand{\ExerciseHeader}{\noindent\textbf{\ExerciseName\ \ExerciseHeaderNB}\ \ExerciseHeaderTitle\ \ExerciseHeaderOrigin\smallskip}
\renewcommand{\ExerciseHeaderOrigin}{(\ExerciseOrigin)}
\renewcommand{\AnswerHeader}{\bigskip\noindent\textbf{Solution \ExerciseHeaderNB}\newline}

\title{Recitation Notes}
\author{Robert Dougherty-Bliss}
\date{20 January 2021}

\begin{document}

\maketitle

Welcome to real analysis!

Today marks the first step of your journey through one of the principle pillars
of mathematics: \emph{analysis}. The field is so vast that I could not possibly
summarize it in a few words. But if I had to, I would say that analysis is the
rigorous study of \emph{change} and \emph{estimates}.

% Adding the * gets rid of the section numbering.
\section*{Logistics}%
\label{sec:logistics}

\begin{enumerate}
    \item I am Robert Dougherty-Bliss, your TA for this semester. For Professor
        Coley, I run \emph{workshops} every week. For now, this is 15-30
        minutes of me going over material, and then an hour or so of answering
        your questions.

        For Professor Klatt, my rough plan is to record the weekly workshops I
        do with the other section and post them online for you to watch. Maybe
        this will change.

    \item We have a Canvas page. The syllabus is on the Canvas page.

    \item Textbook: \url{https://elliespathtostatistics.files.wordpress.com/2018/03/abbott-second-edition.pdf}

    \item Office hour survey: \url{https://www.when2meet.com/?10713170-4UARI}

    \item Join the Rutgers Math Discord! \url{https://discord.gg/rutgersmath}

        I usually hang out there and answer questions.
\end{enumerate}

\section*{New stuff}%
\label{sec:new_stuff}

Like you should for any journey, we will begin today by preparing our
equipment. In this case, our equipment consists of \emph{methods of proof}. I
cannot say, ``in order to prove X, do Y,'' but I can lay out some rough logical
tools. These tools are:

\begin{enumerate}
    \item Direct proof.
    \item Proof by contrapositive.
    \item Proof by contradiction.
    \item Proof by induction.
\end{enumerate}

In theory you've seen these before, but I'm sure that you're rusty. Let's see
some examples.

\subsection*{Direct proof}

The first and most ``obvious'' way to prove something is to do it directly. You
take the assumptions given to you and move them around until the conclusion
falls out.

\begin{definition}
    An integer $n$ is \emph{even} provided that $n = 2k$ for some integer $k$.
    On the other hand, $n$ is \emph{odd} provided that $n = 2m + 1$ for some
    integer $m$.
\end{definition}

\begin{proposition}
    The sum of two even integers is even. (If $x$ and $y$ are even integers,
    then $x + y$ is even.)
\end{proposition}

\begin{proof}
    Let $x$ and $y$ be even integers. That is, $x = 2n$ and $y = 2m$ for some
    integers $n$ and $m$. Then
    \begin{equation*}
        x + y = 2(n + m),
    \end{equation*}
    and since $n + m$ is an integer, it follows that $x + y$ is even.
\end{proof}

\begin{proposition}
    The product of two odd integers is odd. (If $x$ and $y$ are odd integers,
    then $xy$ is odd.)
\end{proposition}

\begin{proof}
    Let $x = 2n + 1$ and $y = 2m + 1$ for integers $n$ and $m$. Then
    \begin{equation*}
        xy = (2n + 1)(2m + 1) = 2(2nm + n + m) + 1,
    \end{equation*}
    so $xy$ is odd.
\end{proof}

\begin{Exercise}
    Prove that the sum of two odd integers is even.
\end{Exercise}

\subsection*{Contrapositive}%

The statement ``if $P$, then $Q$'' is \emph{logically equivalent} to ``if not
$Q$, then not $P$.'' The latter statement is called the \emph{contrapositive}
of the former, and proving either proves the other. In some cases the
contrapositive is much easier to prove than the original statement. Other times
there isn't much of a difference.

\begin{proposition}
    If $n^2$ is even, then $n$ is even.
\end{proposition}

Writing $n^2 = 2k$ does not seem very helpful. Instead, we'll try the
contrapositive.

\begin{proof}
    Suppose that $n$ is odd, so that $n = 2m + 1$ for some integer $m$. Then
    $n^2 = 2(2m^2+ 2m) + 1$ is odd, so our original claim is true.
\end{proof}

Note that the contrapositive is \emph{not} the same as the \emph{converse}. The
converse of ``if $P$, then $Q$'' is ``if $Q$, then $P$.'' In general these are
completely different statements. If both happen to be true, then we say ``$P$
if and only if $Q$,'' sometimes shortened ``$P$ iff $Q$.''

\begin{Exercise}
    Is the following true?
    \begin{quote}
        If $x$ and $y$ are integers, then $x + y$ is even iff $x$ and $y$ are
        both even.
    \end{quote}
\end{Exercise}

\begin{Exercise}
    Show that $n^2$ is odd iff $n$ is odd. (Hint: Do one half directly, and one
    half with the contrapositive.)
\end{Exercise}

\subsection*{Contradiction}%

If a statement cannot be false, then it must be true. (This is controversial.)
So, to prove that something is true, start by assuming that it is \emph{false},
and try to show that this is impossible.

Before I give you an example, I should say that not many things \emph{require}
a proof by contradiction. In fact, most proofs by contradiction are actually
proofs by contrapositive in disguise! I will yell at you if you make this
mistake.

Now for the most famous example where contradiction is really necessary.

\begin{proposition}
    $\sqrt{2}$ is irrational.
\end{proposition}

\begin{proof}
    Suppose, to the contrary, that $\sqrt{2} = a / b$ for coprime integers $a$
    and $b$, i.e., $a$ and $b$ do not share a common factor other than $1$.
    Then
    \begin{equation*}
        2 = \frac{a^2}{b^2},
    \end{equation*}
    or $2 b^2 = a^2$. It follows that $a^2$ is even, and so $a$ is as well,
    meaning that $a = 2a'$ for some integer $a'$. Our equation becomes
    \begin{equation*}
        2 b^2 = (2a')^2 = 4a'^2,
    \end{equation*}
    so $b^2 = 2a'^2$. From this we see that $b^2$ is even, and therefore $b$ is
    as well. But now $2$ divides both $a$ and $b$, which contradicts that they
    share no common divisors but $1$. Therefore $\sqrt{2}$ \emph{cannot} be
    rational.
\end{proof}

\begin{Exercise}
    Mimic the above proof to show that $2^{1/3}$ is irrational. (Hint: If $2$
    divides $xy$, then it divides either $x$ or $y$.) Now show that $2^{1/n}$
    is irrational for all $n \geq 2$.
\end{Exercise}

\subsection*{Induction}

Induction is a tool for when you want to prove something about all positive
integers, and somehow each integer with the property implies that the next
integer has it too.

The general setup is this: Suppose that $P(n)$ is some statement about the
integer $n$, maybe $P(n) = n^2 \geq n$. If $P(1)$ is true, and $P(n)$ implies
$P(n + 1)$ for every $n \geq 1$, then $P(n)$ is true for all $n \geq 1$. (You
can replace $1$ with any integer.)

\begin{proposition}
    For all $n \geq 4$,
    \begin{equation*}
        n! \geq 2^n.
    \end{equation*}
\end{proposition}

\begin{proof}
    Suppose that $n! \geq 2^n$ for some $n \geq 4$. Then,
    \begin{equation*}
        \frac{(n + 1)!}{2^{n + 1}} = \frac{n + 1}{2} \frac{n!}{2^n} \geq \frac{n + 1}{2}.
    \end{equation*}
    Since $n \geq 4$ we get $(n + 1) / 2 \geq 1$, which implies
    \begin{equation*}
        \frac{(n + 1)!}{2^n} \geq 1.
    \end{equation*}
    At $n = 4$, we have
    \begin{equation*}
        4! = 24 \geq 16 = 2^4.
    \end{equation*}
    Thus, by induction, $n! \geq 2^n$ for all $n \geq 4$.
\end{proof}

Here's a statement with a true induction step, but is false for all nonnegative
integers: $n! = 0$ for all $n \geq 0$.

\begin{Exercise}
    The \emph{Fibonacci} numbers are defined recursively as follows:
    \begin{align*}
        F_0 &= 0 \\
        F_1 &= 1 \\
        F_{n + 2} &= F_{n + 1} + F_n.
    \end{align*}
    Prove via induction that
    \begin{equation*}
        \sum_{k = 0}^n F_k = F_{n + 2} - 1
    \end{equation*}
    for all integers $n \geq 0$.

    (Hint: $\sum_{k = 0}^{n + 1} F_k = \sum_{k = 0}^n F_k + F_{n + 1}$.)
\end{Exercise}

\begin{Answer}
    For $n = 0$, the identity reads
    \begin{equation*}
        0 = \sum_{k = 0}^n F_k = F_2 - 1 = 0,
    \end{equation*}
    which is true. Now, suppose that
    \begin{equation*}
        \sum_{k = 0}^n F_k = F_{n + 2} - 1
    \end{equation*}
    for some $n \geq 0$. Then,
    \begin{align*}
        \sum_{k = 0}^{n + 1} F_k &= \sum_{k = 0}^n F_k + F_{n + 1} \\
                                 &= F_{n + 2} + F_{n + 1} - 1 \\
                                 &= F_{n + 3} - 1 \\
                                 &= F_{(n + 1) + 2} - 1.
    \end{align*}
    Therefore, by induction, the identity holds for all $n \geq 0$.

    (Method two, which you are not allowed to use: Check it with a computer for
    $n \leq 100$.)
\end{Answer}

\section*{A note on style}%

Style and taste is important in all writing, even in mathematics. I'm not going
to explain all of the finer points, but I will point you to this document,
written in part by mathematical wiz and computer science guru Donald Knuth:

\url{https://jmlr.csail.mit.edu/reviewing-papers/knuth_mathematical_writing.pdf}

Read the first chapter when you have time! You'll be glad that you did.

\section*{A note on \LaTeX}%

LaTeX, styled \LaTeX, is a ``typesetting'' system widly used in mathematics.
\LaTeX\ turns formatted plaintext documents (created using a text editor such
as Notepad++) into nicely rendered PDF files. It has \emph{very} good support
for mathematical symbols and a number of other niche topics. Virtually all
mathematicians use \LaTeX\ to write papers, prepare lecture notes, and so on.
In fact, I'm using it to write these notes right now.

It is encouraged---but \emph{not} required---that you write up your homework,
midterm projects, etc.~in \LaTeX. This makes it easier to read and will make
you feel fancy.

Some of you have seen \LaTeX\ and some of you have not. There are a number of
resources online that will teach you how to prepare and ``compile'' a \LaTeX
document. To give you examples of good \LaTeX\ documents, I will occasionally
prepare my workshop notes in \LaTeX\ and post them online somewhere every week.
(I can't promise I will do this all the time. It takes more time!)

\end{document}