\documentclass[12pt]{article}
\usepackage{design_ASC}
\usepackage{url}
\usepackage{float}
\setlength\parindent{0pt} %% Do not touch this

%% -----------------------------
%% CTA200H Assignment 2
%% -----------------------------
\title{CTA200H Assignment \#2} %% Assignment Title

\author{Nikki Frazer\\ %% Student name
\textsc{SURP Student}
}

\date{\today} %% Change "\today" by another date manually
%% -----------------------------
%% -----------------------------

%% %%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\setlength{\droptitle}{-5em}
%% %%%%%%%%%%%%%%%%%%%%%%%%%
\maketitle

% --------------------------
% Start here
% --------------------------

% %%%%%%%%%%%%%%%%%%%
\section*{Question 1}
% %%%%%%%%%%%%%%%%%%%

For each point in the complex plane $c = x + iy$, with $-2 < x < 2$ and $-2 < y < 2$, set $z_0 = 0$ and iterate the equation $z_{i + 1} = z_i^2 + c$.
Note what happens to the $z_i$'s: some points will remain bounded in absolute value $|z|^2 = \Re(z)^2 + \Im(z)^2$, while others will run off to infinity.
Make an image  in which your points $c$ that diverge are given one color and those that stay bounded are given another.
(Once you have done this, you can try coloring the points that diverge using a colorscale that indicates the iteration number at which the given point diverged.)
Try zooming in on a portion of the image and trying again.

% %%%%%%%%%%%%%%%%%%%
\subsection*{Method}
% %%%%%%%%%%%%%%%%%%%
\begin{figure}[H]
    \centering
    \includegraphics{mandel.png}
    \caption{Mandelbrot Plot: Early Attempt }
\end{figure}
\begin{figure}[H]
    \centering
    \includegraphics{mandel.1.png}
    \caption{Mandelbrot Plot:Diverging vs Converging Points }
\end{figure}
\begin{figure}[H]
    \centering
    \includegraphics{mandel.2.png}
    \caption{Mandelbrot Plot: Diverging points colourscaled }
\end{figure}
\begin{figure}[H]
    \centering
    \includegraphics{zoom.png}
    \caption{Mandelbrot Plot: Zoomed In }
\end{figure}
I began by drawing out the complex plane and computing iterations of Z by hand when given a point c. Then, I created a function that will determine whether a point diverges or converges after a certain number of iterations of Z, or, which points are actually in the Mandelbrot set. I computed some tests, and noticed that by splitting Z into its real and imaginary parts that by 50 iterations, points with real values over 2 will diverge, or become close to infinity. This function then creates a list of zeroes and ones depending on if a point converges or diverges. In order for the code to execute, it was important to include code that recorded the exact iteration when a point started to diverge. Next, I created another function which will plot the Mandelbrot set. I used meshgrid() from the numpy library to create the coordinates in the grid, and then plotted the imaginary axis, the real axis, and the colour code of zeros and ones together to create the Mandelbrot shape. For the colourscale plot, I adapted my first function to count how many iterations a point goes through before it diverges, and then used that data to map colour onto the plot.

% %%%%%%%%%%%%%%%%%%%
\subsection*{Analysis}
% %%%%%%%%%%%%%%%%%%%
My first few attempts at creating a plot showed me the general outline of the Mandelbrot plot, which helped me to refine the image by creating a density variable. The Mandelbrot set plot shows a distinct ink splotch pattern, which remarkably has been coloured according to which points diverge or converge according to the iterations of Z. The colourscale plot shows the pattern of the diverging points, and creates a striking visual. Zooming in on the plot shows the distinct swirls in different colours. It”s amazing that a short python script created such a complex plot!
% %%%%%%%%%%%%%%%%%%%
\section*{Question 2}
% %%%%%%%%%%%%%%%%%%%

The SIR model is a simple mathematical model of disease spread in a population.
The model divides a fixed population of size $N$ into three groups, which vary as a function of time, $t$:

\begin{itemize}
    \item $S(t)$ is those that are susceptible but not yet infected
    \item $I(t)$ is the number of infected individuals
    \item $R(t)$ is those individuals that have recovered and are now immune
\end{itemize}

The model can be described by a set of 3 first order differential equations for each of the variables as

\begin{align}
    \frac{dS}{dt} &= -\frac{\beta S I}{N},\\
    \frac{dI}{dt} &= \frac{\beta S I}{N} - \gamma I,\\
    \frac{dR}{dt} &= \gamma I
\end{align}

Using the ODE integrator of your choice (must be callable in Python, we recommend using Scipy as will be covered in lecture on Friday), integrate the equations with $N=1000$ from $t=0$ to $t=200$ for various values of $\gamma$ and $\beta$ (at least 3-4 values, justify your choices physically).

Use the initial condition $I(0) = 1, S(0)=999, R(0) = 0$ (you can also experiment with other initial conditions if you wish).
Plot the curves for $S, I, R$ on the same figure with a legend. make separate plots for each choice of the parameters.

Bonus: Add a 4th parameter $D$ for deaths and justify the addition of a 4th differential equation as well as any RHS terms that must be changed on the initial 3 equations. Integrate the new set of equations for some choice of parameters and comment on the results compared to the SIR model. \ldots

% %%%%%%%%%%%%%%%%%%%
\subsection*{Method}
% %%%%%%%%%%%%%%%%%%%
For question 2, I began by reviewing that a solution to such a system of ordinary differential equations would be geometrical, and that I should use a numerical integration method that could solve the system and plot its solution. From the SciPy Integrate library, solve ivp requires equations, an interval, initial values, and the number of points in the interval. I started by setting initial values for the model and then I defined a function that would return the right hand sides of the equations. I experimented with different gamma and beta values, and figured out what the variables meant. Beta is the contract rate for the virus, and gamma is the recovery rate. Then, I called solve ivp to create the data sets for the three groups of the population. I then plotted the data against the time axis, with four different sets of beta and gamma.
\begin{figure}[H]
    \centering
    \includegraphics{SIR.1.png}
    \caption{SIR Model Plots}
\end{figure}
\begin{figure}[H]
    \centering
    \includegraphics{SIR.2.png}
    \caption{SIR Model Plots}
\end{figure}
\begin{figure}[H]
    \centering
    \includegraphics{SIR.3.png}
    \caption{SIR Model Plots}
\end{figure}
\begin{figure}[H]
    \centering
    \includegraphics{SIR.4.png}
    \caption{SIR Model Plots}
\end{figure}
% %%%%%%%%%%%%%%%%%%%
\subsection*{Analysis}
% %%%%%%%%%%%%%%%%%%%
The four plots show interesting results. I picked beta and gamma values to model distinct situations. Plot 1 models a situation where a large portion of the population becomes infected within the first 25 days, but the recovery rate also increases rapidly, flattening the number of people susceptible to the disease close to zero quickly. Plot 2 models a situation where a minority of the population becomes infected after 50 days of the disease spreading, but while the recovery rate is still steep, the number of susceptible people does not drop to zero. Plot 3 models a situation where a minority of the population becomes infected rapidly, but recovers quickly. However, again, the number of susceptible people does not reach zero. Plot 4 models a situation where almost all of the population becomes infected before the first 25 days, but the rapid recovery rate shows that the number of infected and susceptible people drops to zero before 50 days. Each situation models a unique disease, and while the SIR model simplifies pandemic situations, it also offers a unique perspective into how variables such as beta and gamma can drastically change how a disease spreads throughout a population. The SIR model has been used to roughly model the COVID-19 global pandemic in different regions, and while it oversimplifies the situation, it does offer a way to show people how a disease can spread without preventative measures in place.

\end{document}


\documentclass[letterpaper]{article}

\usepackage[utf8]{inputenc}
\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{January 28, 2015}
\maketitle
last quiz answers:
?

\section*{on board}
$f$ bounded on $[a,b]$

$D_f=\{x:f\text{ is not continuous at } x\}$

\subsection*{theorem}
$f$ is Riemann integrable iff $m*(D_f)=0$

\subsection*{definition}
if $T\subseteq [a,b]$ oscillation of $f$ on $T$

\[\Omega_f(T)=\sup\{f(x)-f(y):x,y\in T\}\]

\subsubsection*{for example}
$f(x)=x^2, T=[0,5]$ then oscillation is $\Omega_f=25$

$f(x)=x^2, T=\mathbb{Q}^C\cap [0,5]$ then oscillation is $25$ but this time $5\not\in T$ and $0\not\in T$ and so we need the supremum

we are interested in how much the oscillation happens as we approach $x$

\subsection*{def}
$\omega_f(x)=\lim\limits_{h\to0^+}\Omega_f(B(x,h)\cap[a,b])$

\subsection*{facts}
\begin{enumerate}
\item
$\omega_f(x)=0$ iff $f$ is continuous at $x$

\subsection*{theorem}
let $\varepsilon>0$ be given. if $\omega_f(x)<\varepsilon$ for all $x\in [a,b]$ then $\exists\delta>0$ so that when $\Omega_f(T)<\varepsilon$ for any closed interval $T\subseteq[a,b]$ with $m*(T)<\delta$

\end{enumerate}

for every $x\in[a,b]$ there is $B(x,\delta_x)$ such that $\Omega_f(B(x,\delta_x)\cap[a,b])<\varepsilon$. $\{B(x,\delta_x)\}_{x\in[a,b]}$ is an open cover for $[a,b]$ there is $x_1,\dots,x_n\in [a,b]$ with $[a,b]\subseteq\bigcup_{i=1}^nB(x_i,\frac{\delta_{x_i}}{2})$. $\delta=\min\{\frac{\delta_{x_i}}{2}\}$

if $m*(T)<\delta$ then any two points are are within $\delta$ of $x_i$. $T\cap B(x_i,\frac{\delta_{x_i}}{2})\ne \emptyset$ so $T\subseteq B(x_i,\delta_{x_i})$ and so $\Omega_f(T)<\varepsilon$

\subsubsection*{lemma}
let $J_{\varepsilon}=\{x\in[a,b]:\omega_f(x)\ge \varepsilon\}$ then
$J_\varepsilon$ is closed and $D_f=\bigcap\limits_{n=1}^\infty J_{\frac{1}{n}}$

second part is just lemma? continuous=measure 0

first part $y\in J_{\varepsilon}^C$ then $\omega_f(y)<\varepsilon$ there is $\delta$ such that $\Omega_f(B(y,\delta)\cap[a,b]<\varepsilon$, $B(y,\delta)\subseteq J_{\varepsilon}^C$

if $z\in B(y,\delta)$ consider $bB(z,\delta)$ where $\delta'$ is chosen so that $B(z,\delta')\subseteq B(y,\delta)$. notice that $\omega_f(z)\ge \Omega_f(B(z,\delta')\cap[a,b])\le\Omega_f(B(y,\delta)\cap[a,b]<\varepsilon$ so $z\not\in J_{\varepsilon}$.

\subsubsection*{now for proof of thrm}
we want to show that $f$ is reimann integrable iff $m*(D_f)=0$.

assume $m*(D_f)>0$. $D=\bigcup_{r=1}^\infty J_{\frac{1}{r}}$ with $J_{\frac{1}{r}}=\{x:\omega_f(x)\ge\frac{1}{r}\}$

these are closed sets, closed sets are measurable, and this is countable union so the whole thing (D) is measurable. and since $m*(D_f)>0$ there is $N>0$ such that $m*(J_{\frac{1}{n}})>0$

if $J_N\subseteq\bigcup_{i=1}^\infty(a_i,b_i)$ then $\sum\limits{b_i-a_i}> \varepsilon$ for some $\varepsilon>0$.

now let $P$ be a partition.

$U(P,f)-L(P,f)$ (upper-lower) $=\sum\limits_{k=1}^n{M_k-m_k}\delta_k$
check page 114ish

$=\left[\sum\limits_{s_1}{(M_k-m_k)\\delta_k}\right]+\left[\sum\limits_{s_2}{M_k-m_k\\delta_k}\right]$

$s_1=J_{1/N}\cap(x_{k-1},x_k)\ne\emptyset$

$s_2=J_{1/N}\cap(x_{k-1}$

\begin{enumerate}
\item
$D\subseteq \bigcup_{k\in S_1}(x_{k-1},x_k)$

$M_k(f)-m_k(f)\ge \frac{1}{N}$ for all $k\in S$

$\sum\limits_{k\in S_1}{\delta_k}>\varepsilon$

$U(f_iP)-L(f,P)\ge \sum\limits_{s_1}{M_k-m_k)\delta_k}\ge \frac{1}{N}\sum\limits_{s_1}{\delta_k}=\frac{1}{N}\varepsilon$ so f not integrable
\end{enumerate}
\end{document}


\documentclass{standalone}
\begin{document}
	\subsection{Number of Clusters}

	The designed algorithm for the centroids estimation is the k-means clustering that requires prior knowledge about the number of clusters to use. This is very important since a bad choice will badly affect the whole segmentation results. In order to choose the proper number of clusters, I've considered two different sources of information: the anatomical knowledge about the lung and the internal variability of the lung.

	From anatomical knowledge about the lung, we can derive 5 clusters, corresponding to:
	\begin{itemize}
		\item Lung;

		\item  Edges;

		\item Vessel surrounding bronchial structures;

		\item Bronchi.

		\item  Ground Glass Opacities and Consolidation;
	\end{itemize}

	Notice that the background of the image is not considered as a cluster since it is removed from the segmentation for the reasons explained before.
	In order to verify that this number of clusters is the best one, I have considered the internal cluster variability.

	Clustering techniques try to group the data into different clusters in order to maximize the difference between points in different clusters and to maximize the similarity within each cluster. If the number of centroids is less then the clusters one, the similarity within each cluster is low. Increasing the number of centroids will reduce the internal variability until $0$ (if the number of clusters is equal to the number of points).
	This means that after a certain point the diminishing of the internal variability is no more significant, since do not correspond to the good number of clusters but only to the increasing of their number.

	To found the correct number of clusters, we seek to for a number of clusters which still provides a small amount of internal variability.

	To achieve this purpose, the clustering was repeated several times increasing the number of clusters and for each iteration, the internal variability was measured by the sum of squares estimate error (SSE) :

	\begin{equation}\label{eq:SumOfSquare}
		SSE = \sum (x_i - c_j)^2
	\end{equation}

	Once this task is completed, the results was printed in \figurename\,\ref{fig:ElbowCurve}.

	\begin{figure}[h!]
		\centering
		\includegraphics[scale=.3]{ElbowCurve.png}
		\caption{Intra-cluster variance vs the number fo clusters(blue); right joining first and last point(orange). We can see the elbow shape of the graph; the elbow location in the one which maximizes the distance between the right joining line and the elbow curve.}\label{fig:ElbowCurve}
	\end{figure}

	The optimal number of clusters is the one that corresponds to the elbow of the curve. It is difficult to find this feature from visually, I took the numerical value of the elbow considering the point which maximizes the distance between the right joining the first and the last point.
	From this analysis, I have found that the optimal number of clusters is $5$, which corresponds to the same that I have found considering lung anatomy.
\end{document}


\documentclass[]{latexie-article}

\usepackage[]{latexie}
\usepackage{lipsum}

\title{latexie Example Document}
\author{Yuki Koyama}
\date{\today}

\begin{document}

\maketitle

\begin{abstract}
  \lipsum[1-2]
\end{abstract}

\tableofcontents

\section{Introduction}

This is a citation test \cite{Koyama:SIGGRAPH:17, Koyama:SIGGRAPH:20, Koyama:CHI:18}.
\todo{This is a test of the ``todo'' command.}
\note{This is a test of the ``note'' command.}
\spot{This is a test of the ``spot'' command.}
This is a test of displaying a very long URL including hyphens: \url{https://koyama.xyz/Lorem-ipsum-dolor-sit-amet-consectetuer-adipiscing-elit-Ut-purus-elit-vestibulum-ut-placerat-ac-adipiscing-vitae-felis} (line breaks should be appropriately inserted at hyphens).

\lipsum[1-5]

\section{Equations}

Minimization problem:
\begin{align}
  \bfx^{*} = \argmin_{\bfx \in \calX} f(\bfx).
\end{align}

Conditional probability:
\begin{align}
  \cprob{\theta}{x} \propto \cprob{x}{\theta}\prob{\theta}
\end{align}

Gaussian distribution:
\begin{align}
  \calN(\bfx; \bfmu, \bfSigma)
  =
  \frac{1}{(2 \pi)^{\frac{n}{2}} \det(\bfSigma)^{\frac{1}{2}}}
  \exp \left\{
    - \frac{1}{2} (\bfx - \bfmu)^\T \bfSigma^\inv (\bfx - \bfmu)
  \right\}.
\end{align}

\bibliographystyle{plainnat}
\bibliography{example}

\end{document}


%%% exercise 06 %%%
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath, amssymb, amsfonts, enumitem, fancyhdr, tikz}
% get rid of paragraph indent
\setlength{\parindent}{0 pt}
% allow section.equation numbering
\numberwithin{equation}{section}
% allows you to copy-paste code segments. requires pygments to be installed
% natively, i.e. not just in a Python venv! for example, on WSL Ubuntu you
% need to sudo apt-get install python3-pygments (unfortunately, the version
% will be a bit dated) and cannot rely on your venv Pygments version.
\usepackage{minted}
% makes clickable links to sections
\usepackage{hyperref}
% make the link colors blue, as well as cite colors. urls are magenta
\hypersetup{
    colorlinks, linkcolor = blue, citecolor = blue, urlcolor = magenta
}
% fancy pagestyle so we can use fancyhdr for fancy headers/footers
\pagestyle{fancy}
% add logo in right of header. note that you will have to adjust logo path!
\fancyhead[R]{\includegraphics[scale = 0.15]{../bac_logo1.png}}
% don't show anything in the left and center header
\fancyhead[L, C]{}
% give enough space for logo by reducing top margin height, head separator,
% increasing headerheight. see Figure 1 in the fancyhdr documentation. if
% \topmargin + \headheight + \headsep = 0, original text margins unchanged.
\setlength{\topmargin}{-60 pt}
\setlength{\headheight}{50 pt}
\setlength{\headsep}{10 pt}
% remove decorative line in the fancy header
\renewcommand{\headrulewidth}{0 pt}

% title, author + thanks, date
\title{Exercise 6}
\author{Derek Huang\thanks{NYU Stern 2021, BAC Advanced Team.}}
% the extra thanks is also useful for making notes about previous versions.
% you can remove this thanks if there are no version revisions.
\date{April 19, 2021\thanks{Original version released on April 8, 2021.}}

\begin{document}

\maketitle
% need to include this after making title to undo the automatic
% \thispagestyle{plain} command that is issued.
\thispagestyle{fancy}

% remove some space between title and first section to keep text on one page.
% comment this line out or adjust the space reduction as needed. generally,
% try to remove as little space as possible if you are trying to keep content
% on one page, else comment this line out if content spans multiple pages.
%\vspace{-20 pt}

\section{Convexity}

\subsection{The convex hull}

Let $ C \subseteq \mathbb{R}^n $ be a set. Prove that $ C =
\operatorname{conv} C \Leftrightarrow C $ convex.

\medskip

\textit{Hint.} Note that given $ \mathbf{x}_1, \mathbf{x}_2, \mathbf{x}_3
\in C $, $ \alpha_1, \alpha_2 \in [0, 1] $, that
$ \alpha_2(\alpha_1\mathbf{x}_1 + (1 - \alpha_1)\mathbf{x}_2) +
(1 - \alpha_2)\mathbf{x}_3 \in C $.

\subsection{Positive definite matrices}

Let $ \mathbb{S}_{\succ\mathbf{0}}^n \triangleq \{\mathbf{A} \in
\mathbb{R}^{n \times n} : \mathbf{A} \succ \mathbf{0}\} $ be the set of
$ n \times n $ positive definite matrices. Prove
$ \mathbb{S}_{\succ\mathbf{0}}^n $ is convex.

\medskip

\textit{Hint.} Note that $ \mathbb{S}_{\succ\mathbf{0}}^n $ is closed under
addition and multiplication by positive scalars.

\subsection{Norms}

Prove that any norm $ \Vert\cdot\Vert $ on a real or complex vector space
$ V $ is convex.

\medskip

\textit{Hint.} Use the triangle inequality and absolute homogeneity properties
of norms.

\subsection{Scalar composition}

Let $ f : \mathbb{R} \rightarrow \mathbb{R} $ be convex and nondecreasing and
let $ g : \mathbb{R}^n \rightarrow \mathbb{R} $ be convex. Prove that
$ f \circ g $ is convex.

\section{Optimization}

\subsection{Underdetermined linear systems}

Suppose we have the underdetermined linear system $ \mathbf{Ax} = \mathbf{b} $,
where $ \mathbf{A} \in \mathbb{R}^{q \times n} $,
$ \operatorname{rk}(\mathbf{A}) = q $,
$ \mathbf{x} \in \mathbb{R}^n $, $ \mathbf{b} \in \mathbb{R}^q $, and
$ q < n $. The minimum $ \ell^2 $-norm solution $ \mathbf{x}^* $ to
$ \mathbf{Ax} = \mathbf{b} $ solves
\begin{equation*}
    \begin{array}{ll}
        \displaystyle\min_\mathbf{x} & \Vert\mathbf{x}\Vert_2^2 \\
        \text{s.t.} & \mathbf{Ax} = \mathbf{b}
    \end{array}
\end{equation*}

Derive an analytical solution for $ \mathbf{x}^* $.

\medskip

\textit{Hint.} $ \mathbf{A} $ full rank means $ \mathbf{AA}^\top $ is
invertible. Strong duality holds as well. Use the Lagrangian to compute the
primal optimal $ \mathbf{x}^* $ in terms of the dual optimal
$ \nu^* \in \mathbb{R}^q $ and solve the resulting dual problem to get an
analytical expression for $ \nu^* $ that can be substituted back into the
expression for $ \mathbf{x}^* $.

\subsection{Markowitz portfolios}

Suppose we have $ n $ investable risky assets with covariance matrix
$ \mathbf{C} \succ \mathbf{0} \in \mathbb{R}^{n \times n} $. Let
$ \mathbf{w} \in \mathbb{R}^n $ be a portfolio, i.e. a vector indicating how
much dollar wealth is invested long or short in each asset. A portfolio
$ \mathbf{w}^* $ with minimium expected variance and \$1 total outlay,
assuming no borrowing cost, solves
\begin{equation*}
    \begin{array}{ll}
        \displaystyle\min_{\mathbf{w}} & \mathbf{w}^\top\mathbf{Cw} \\
        \text{s.t.} & \mathbf{1}^\top\mathbf{w} = 1
    \end{array}
\end{equation*}

Find an analytical expression for $ \mathbf{w}^* $.

\medskip

\textit{Hint.} Strong duality holds here so the Karush-Kuhn-Tucker conditions
are satisfied for primal optimal $ \mathbf{w}^* $ and dual optimal
$ \nu^* \in \mathbb{R} $. Use stationarity of the Lagrangian at
$ \mathbf{w}^*, \nu^* $ to compute $ \mathbf{w}^* $ as a function of
$ \nu^* $ and use the equality constraint to get analytical expressions for
both $ \nu^* $ and $ \mathbf{w}^* $.

\subsection{Highly constrained portfolios}

Suppose we want to form a minimum variance long-only portfolio
$ \mathbf{w}^* \in \mathbb{R}^n $ with positive total outlay capped at \$1
where at least $ \kappa \in [0, 1) $ of the portfolio is invested in cash,
i.e. not invested in any assets. Furthermore, no more than
$ \gamma \in (0, 1) $, $ \gamma > \kappa $, of the total wealth may be
invested in any one asset. $ \mathbf{w}^* $ solves
\begin{equation*}
    \begin{array}{ll}
        \displaystyle\min_\mathbf{w} & \mathbf{w}^\top\mathbf{Cw} \\
        \text{s.t} & 0 \le \mathbf{1}^\top\mathbf{w} \le 1 - \kappa \\
        & \mathbf{0} \preceq \mathbf{w} \preceq \gamma\mathbf{1}
    \end{array}
\end{equation*}

Derive the dual problem corresponding to the primal problem above.

\medskip

\textit{Hint.} First, rewrite the problem in standard form and note that
the Lagrange multipliers $ \lambda \in \mathbb{R}^{2n + 2} $. Use the
convexity of $ \mathcal{L}_f : \mathbb{R}^n \times \mathbb{R}^{2n + 2}
\rightarrow \mathbb{R} $, the Lagrangian, to write $ \mathbf{w}^* $ in terms
of $ \lambda $ and derive an expression for $ f_d : \mathbb{R}^{2n + 2}
\rightarrow \mathbb{R} $, the dual of the objective, which will be a quadratic
function of $ \lambda $.

\end{document}


\documentclass[../PHYS306Notes.tex]{subfiles}

\begin{document}
\section{Lecture 26}
\subsection{Lecture Notes - Liouville's Theorem, Path to QM (Canonical Quantization)}
\subsubsection{Review - Liouville's Theorem}
\begin{itemize}
    \item The volume $V$ of a region of phase space does not change in time.
    \item The phase space density $N/V$ moving with the slow lines remains constant.
    \item The phase space density moves like an incompressible fluid.
    \item $V_t = \int d\v{z}_t = \int\abs{\dpd{\v{z}_t}{\v{z}_0}}d\v{z}_0 = V_0$, $abs{\dpd{\v{z}_t}{\v{z}_0}} = 1$
\end{itemize}

\subsubsection{Liouville's Theorem from Gauss's (Divergence) Theorem}
Recall the divergence theorem; for a vector field $\v{v}$, it holds that:
\[\int_V \div{\v{v}} dV = \int_S \v{v} \cdot \v{n} dA\]
Now we consider the divergence of the phase space velocity, $\v{v}$:
\[\v{v} = \m{\dot{\v{q}} \\ \dot{\v{p}}} = \m{\dpd{\HH}{\v{p}} \\ -\dpd{\HH}{\v{q}}}\]
The divergence is given by:
\[\div{\v{v}} = \dpd{\dot{\v{q}}}{\v{q}} + \dpd{\dot{\v{p}}}{\v{p}} = \dpd{}{\v{q}}\left(\dpd{\HH}{\v{p}}\right) - \dpd{}{\v{p}}\left(\dpd{\HH}{\v{q}}\right) = 0\]
Where we use Hamilton's equations and the equality of mixed partials. How do we interpret this? Consider a surface in phase space that moves out with time. As the surface expands there will be a change in volume covered by this propogating surface.
\begin{center}
    \includegraphics[scale=0.7]{Lecture-26/l26-img1.png}
\end{center}
Giving this a surface normal $\v{n}$, calculating the change in volume w.r.t. time we have $\delta V = \v{n}\cdot \v{v}\delta t dA$ and if we integrate over the entire surface, we get teh total change. This yields $\Delta V = \int_S \v{n} \cdot \v{v}\Delta t dA$. And hence:
\[\dod{V}{t} = \int_S \v{n}\cdot \v{v}dA = 0\]
Where the RHS we set to zero by the divergece theorem. This concludes the proof, and is another way of proving the theorem.

\subsubsection{Poisson Brackets Revisited \& The path to QM}
Recall we could write:
\[\dod{F}{t} = [F, \HH] + \dpd{F}{t}\]
where $F$ is some function on phase space. By definition, we had:
\[[F, G] = \sum_i \dpd{F}{q_i}\dpd{G}{p_i} - \dpd{F}{p_i}\dpd{G}{q_i}\]
The fundamental poisson brackets of position and momentum were given by:
\[[q_i, q_j] = [p_i, p_j] = 0, \quad [q_i, p_j] = \delta_{ij}\]
We now connect this to QM, one of the defining theories of the 20th century.

\noindent Recall that in QM, measurements are operations. We perturb systems by measuring/observing them (e.g. measure position of ball by shining light on it, but light carries momentum, so it will interact with the ball in doing so.). Also recall that in qm, $pq$ and $qm$ are different, that is that operators do not (in general) commute.

\subsubsection{Non-Commutative Structure of Phase Space}
Phase space functions become non-commutative operators (matrices).
\noindent Consider four phase space functions, $F_1, F_2, G_1, G_2$. Now, consider the object $[F_1F_2, G_1G_2]$. We pull this apart using the Leibniz product rule:
\[[F_1F_2, G_1G_2] = [F_1, G_1G_2]F_2 + F_1[F_2, G_1G_2] \]
we can also apply it on the second argument:
\[[F_1F_2, G_1G_2] = [F_1F_2, G_1]G_2 + G_1[F_1F_2, G_2]\]
Hence, we get the following expression if we apply hte product rule again:
\[[F_1F_2, G_1G_2] = [F_1, G_1](F_2G_2 - G_2F_2) = (F_1G_1 - G_1F_1)[F_2, G_2]\]
If we have classical observables, the $F, G$s are just numbers, they commute and the relation is obviously satisfied (both sides are just zero!). But in QM, we want to consider arbitrary, non-commuting operators. Hence, the condition for the above equation to be satified for arbitrary non-commuting operators is that:
\[[F_1, G_1] = F_1G_1 - G_1F_1\]
That is, we want the Poisson bracket to be a commutator. Furthermore, we will embellish this with an imaginary unit $i$:
\[i[F_1, G_1] = F_1G_1 - G_1F_1\]
Which is there to ensure that the bracket of two Hermitian operators is again Hermitian. Recall that a Hermitian operator $O$ satisfies $O^\dagger = O$. Finally, we put a number $\hbar$ in front of the commutator as well:
\[i\hbar[F_1, G_1] = F_1G_1 - G_1F_1\]
This now gives the quantum mechanics we know. This process is known as \textbf{canonical quantization}.

\subsubsection{Canonical Quantization}
There are two steps of going from classical mechanics to quantum mechanics:
\begin{enumerate}
    \item Phase space functions (numbers) turn into operators (non-commuting in general).
    \item $[F, G]_P \mapsto \frac{1}{i \hbar}[F, G]$, that is, we embellish the poisson bracket with a factor of $i\hbar$ and turn it into a commutator.
\end{enumerate}
We can check the canonical commutation relations of quantum mechanics:
\[[q_i, q_j] = [p_i, p_j] = 0\]
\[[p_i, p_j] = i\hbar\delta_{ij}\]
From these relations, we can derive many fundamental results of quantum mechanics, such as the Heisenberg uncertainty principle, that is, $(\Delta q)(\Delta p) \geq \frac{\hbar}{2}$. By making the Poisson bracket the commutator, we get this quantized theory with uncertainty built into it. We may also look at the time evolution of operators. The classical evolution equation is:
\[\dod{F}{t} = [F, H]_P + \dpd{F}{t}\]
the quantum version of this replaces the poisson bracket with a commutator; for a quantum mechanical operator $O$, the time evolution of it is given by:
\[\boxed{\dod{O}{t} = -\frac{i}{\hbar}[O, H] + \dpd{O}{t}}\]
Which is known as the Heisenberg equation of motion. This is the Heisenberg picture of QM, where you move the idea of time-evolution from the states (the Schrodinger picture) to the operators. The canonical quantization process takes us into the Heisenberg picture. Note that one can also do this on fields and get Quantum Field Theory, but that is a story for another course.
\end{document}


\subsection{Type-III - Reversed Weibull distribution}


\subsection{Cauchy's integral theorem}


% \VignetteIndexEntry{gdxrrw Tutorial}
% \VignetteDepends{gdxrrw}
% \VignettePackage{gdxrrw}
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage[pdftex]{graphicx}
\usepackage{color}
% \usepackage{xspace}
% \usepackage{fancyvrb}
% \usepackage{fancyhdr}
\usepackage[colorlinks=true,
            linkcolor=blue,
            citecolor=blue,
            urlcolor=blue]{hyperref}
\usepackage{lscape}
\usepackage{Sweave}

\newcommand{\rrw}{\texttt{gdxrrw}}

\title{A Tutorial for the {\tt gdxrrw} Package}
\author{Steve Dirkse \\ GAMS Development Corporation}

\begin{document}

\maketitle

\thispagestyle{empty}
\section{Introduction}

In this tutorial introduction to \rrw{} we carry out a small modeling
exercise.  We consider a common use case in which one starts with a
self-contained, fully-functional GAMS model that reads from and writes
to GDX.  The GAMS source for the model is not R-specific; it works
equally well with or independently of R.  Without changing the model
source, we can control the model behavior by passing it flags that
control the GDX data input and output used.

It's worth noting that this tutorial assumes the user is familar with
GAMS and to a lesser extent with R.

\section{First steps}

Here we execute the basic steps: transferring data between GAMS and R,
and running GAMS.

Before you can use any R package, you must load
it.  The \rrw{} package also depends on the GDX shared libraries found
in the GAMS system directory.  The \texttt{igdx} command is useful for
setting and querying this linkage between \rrw{} and GAMS.  For
example, the usage below checks for the GAMS system directory in the
environment variable \texttt{R\_GAMS\_SYSDIR}.
<<loadPackage>>=
library(gdxrrw)
igdx('')
if (! igdx(silent=T)) stop ('Could not load GDX API')
@

Our starting point is a basic transport model where all of the data
inputs and outputs are done via GDX.  Running this model is easy once
we figure out how to get it from the \texttt{doc} subdirectory of the
package:
<<genData>>=
gms <- system.file('doc','transport.gms',package='gdxrrw', mustWork=T)
isWindows <- ("mingw32" == R.Version()$os)
if (isWindows) gms <- gsub("/","\\",gms,fixed=TRUE)
ingdx <- system.file('doc','inputs.gdx',package='gdxrrw', mustWork=T)
if (isWindows) ingdx <- gsub("/","\\",ingdx,fixed=TRUE)
rc <- gams(paste0(gms, " --INPUT=", ingdx))
if (0 != rc) stop ('GAMS run failed: rc = ',rc)
@

For reference, we have included the GDX file \texttt{outputs.gdx}
produced by the run above in the \texttt{doc} directory.
<<inCase>>=
if (! file.exists('outputs.gdx')) {
  ogdx <- system.file('doc','outputs.gdx',package='gdxrrw', mustWork=T)
  file.copy(ogdx,'outputs.gdx')
}
@

The model \texttt{transport} dumps all of its data (including its
inputs) to GDX before it quits.  There are 5 inputs: 2 sets and 3
parameters.
<<origData>>=
outgdx <- 'outputs.gdx'
if (! file.exists(outgdx)) stop (paste('File not found:',outgdx))
I <- rgdx.set(outgdx,'I')
J <- rgdx.set(outgdx,'J')
a <- rgdx.param(outgdx,'a')
b <- rgdx.param(outgdx,'b')
c <- rgdx.param(outgdx,'c')
@

As an exercise, we first generate a GDX file whose data is identical
to the original inputs, and verify that the solution with this data is unchanged:
<<identData>>=
wgdx.lst('intest',list(I,J,a,b,c))
rc <- system2('gdxdiff', paste('intest.gdx', ingdx), stdout=F)
if (0 != rc) stop ('gdxdiff says intest.gdx and inputs.gdx differ: rc = ',rc)
rc <- gams(paste(gms, '--INPUT intest.gdx --OUTPUT outtest.gdx'))
if (0 != rc) stop ('gams failed: rc = ',rc)
# system2('gams', 'transport.gms --INPUT intest.gdx --OUTPUT outtest.gdx')
zlst <- rgdx('outputs.gdx',list(name='z'))
z <- zlst$val
# we don't need to use the intermediate zlst variable to get the val
zz <- rgdx('outtest.gdx',list(name='z'))$val
if (0.0 != round(z-zz,6)) stop (paste("different objectives!! ", z, zz))
@

If we double all transportation costs, we can expect to double the objective.
<<doubleData>>=
c2 <- c
c2[[3]] <- c[[3]] * 2
wgdx.lst('in2',list(I,J,a,b,c2))
gams(paste(gms,'--INPUT in2.gdx --OUTPUT out2.gdx'))
z2 <- rgdx('out2.gdx',list(name='z'))$val
print(paste('original=', z,'  double=',z2))
@

\section{Using New Data}

We can define a new problem by changing the sets I and J.
For example, we can use the state data in R to create a set of source
and destination nodes.  The state data includes populations that we
can use to scale demands, and we can base transportation costs on the
lat/long data for the state centers.
<<statesData>>=
data(state)
src <- c('California','Washington','New York','Maryland')
dst <- setdiff(state.name,src)
supTotal <- 1001
demTotal <- 1000
srcPop <- state.x77[src,'Population']
srcPopTot <- sum(srcPop)
dstPop <- state.x77[dst,'Population']
dstPopTot <- sum(dstPop)
sup <- (srcPop / srcPopTot) * supTotal
dem <- (dstPop / dstPopTot) * demTotal
x <- state.center$x
names(x) <- state.name
y <- state.center$x
names(y) <- state.name
cost <- matrix(0,nrow=length(src),ncol=length(dst),dimnames=list(src,dst))
for (s in src) {
  for (d in dst) {
    cost[s,d] <- sqrt((x[s]-x[d])^2 + (y[s]-y[d])^2)
  }
}
@

Now that we've created the raw data for our transportation problem, we
need to put it in proper form for writing out the GDX.  In this example,
we use a list for each symbol to write, although we could use data
frames too.
<<statesGDX>>=
ilst <- list(name='I',uels=list(src),ts='supply states')
jlst <- list(name='J',uels=list(dst),ts='demand states')
suplst <- list(name='a',val=as.array(sup),uels=list(src),
               dim=1,form='full',type='parameter',ts='supply limits')
demlst <- list(name='b',val=as.array(dem),uels=list(dst),
               dim=1,form='full',type='parameter',ts='demand quantities')
clst <- list(name='c',val=cost,uels=list(src,dst),
             dim=2,form='full',type='parameter',
             ts='transportation costs')
wgdx.lst('inStates',list(ilst,jlst,suplst,demlst,clst))
@

Once the data is written to GDX we can call gams, as before.  A model
status of 1 (Optimal) indicates an optimal solution was found.
<<statesSolve>>=
gams(paste(gms,'--INPUT inStates.gdx --OUTPUT outStates.gdx'))
ms <- rgdx.scalar('outStates.gdx','modelStat')
print(paste('Model status:',ms))
@

\section{Abnormal Results}

Things often fail to go as planned.  In many cases, this is indicated
by a nonzero return code from a GAMS run.  For example, we could point
to a non-existent GDX input:
<<missingGDX>>=
rc <- gams('transport --INPUT notHere')
if (0 == rc) print ("SHOULD NOT GET HERE") else print ("abnormal gams return as expected")
@

Another case to consider is an infeasible model.  This is not an
error: infeasible models are sometimes expected.  The model status
(one of many values available after a solve) can indicate an infeasible
model, among other things.  If we reduce the supply available from
Seattle, we make the model infeasible.
<<infeas>>=
a2 <- a
rows <- a2$i == 'seattle'
a2[rows,2] <- a2[rows,2] - 100
wgdx.lst('inInf',list(I,J,a2,b,c))
gams(paste(gms,'--INPUT inInf.gdx --OUTPUT outInf.gdx'))
ms <- rgdx.scalar('outInf.gdx','modelStat')
if (4 == ms) print ("Reduced supply makes model infeasible")
@

\end{document}


\subsection{Dataset}
We have conducted experiments on the following datasets(Mainly For Phase 1):
\begin{center}
\begin{tabular}{| l | c |}
  \hline
  Dataset Name & Advogato  \\ \hline
  Largest conn compo & 5054  \\ \hline
  Size & 6551 vertices  \\ \hline
  Volume & 51332 edges \\ \hline
\end{tabular}
\end{center}

In out final experiment suit, a more large and diverse datasets from different domains will be explored. The tentative source of experiment dataset are listed below:
\begin{description}
	\item{{\bf SNAP:}}{It has abundant data about social network, we plan to conduct triangle counting, pagerank, radius computing experiment which will reveal the underlying feature of large graphs and spot strange graphs.}
	\item{{\bf Konect:}}{Konect has more diverse datasets compared to SNAP, like citation network. It's a good target to analyze features of non-social networks, we will examine whether such networks follow power law by generating degree distribution, etc.}
\end{description}

We also calculated statistics about the weakly connected components in table \ref{table:wcc}.We compute radius for every node in Advogato dataset, the result is in table \ref{table:radius}:

\input{t1_exp}

\input{t2_exp}

\input{t3_exp}

\input{t4_exp}

\input{t5_exp}

\input{t6_exp}

\input{t7_exp}

\input{sp}

\input{mst}


\section{Introduction}

 The purpose of this chapter is to align the $k$-species PDMP given in Chapter 3 with a mean-field model of grain coarsening.  We will assume many of the mean field assumptions from the Fradkov model, given in Section \ref{fradkov}.  In fact, the only significant point of departure is in the selection of the flipping parameter $\beta$.  After defining the appropriate parameters, we will proceed to show some basic properties of the fluid limit, such as conservation of polyhedral defect and area, that are present in instances of  the finite particle model.   Finally, we will examine simulations of grain PDMP.

\section{Side redistribution at singular events }

We now take a closer look at particular singular events of grain and edge deletion. Flow through a singular point in a grain network is highly nonunique (see \cite{evans1991motion} for some illuminating examples).  For the grain coarsening problem, we are interested in what happens when a face or side in a grain network shrinks to a point. In this case, we look for grain networks that solve the continuation problem outlined in Section \ref{introduct}  with initial conditions of $G$ that satisfy the    \textbf{$k$-ray  condition}.  This is defined by a  finite planar graph $G,$ with smooth edges $\alpha_i(x),$ that is trivalent at all vertices except for one vertex, which is of degree $k$.
 To rule out possible pathologies, we'll make the following
assumptions of evolving networks $G(t)\subset \mathbb R^2$, for $t\in(0,\varepsilon)$ under curvature flow which  enforce topological changes to take place at vertices:

 \textbf{Continuation assumptions}: Suppose $G$ consists of $n$ smooth boundaries  $\alpha_{i}(x):(0,1) \rightarrow \mathbb{R}^2$, $i = 1, \dots, n$. Then   there exist evolving boundaries $\alpha_i(x,s):(0,1)\times (0,\varepsilon)\rightarrow \mathbb R^2$ and neighborhoods $U_v(s), s\in (0,\epsilon)  $ for each vertex  $v \in V$ where
\begin{enumerate}
\item $U_v(s) \rightarrow \{v\}$ in the Hausdorff distance.
\item $G(s) \setminus \bigcup_{v\in V} U_v(s)= \bigcup_{i = 1}^n \alpha_i((c_i^1(s),c_i^2(s)),s)$, where $c_i^1(s) \rightarrow 0$ and $c_i^2(s) \rightarrow 1$ as $s\rightarrow 0$.
\item
$\lim_{t\rightarrow 0^+} \alpha(x,t) = \alpha(x), \quad x \in (0,1)$.
\item
  $U_v(s)\cap G(s)$ is connected for $s \in (0, \varepsilon)$, $v\in V$.

\end{enumerate}
Assumptions 1-3 forbid topological changes  at points in $G$ that are not vertices. The connectedness assumption is a reasonable one when we consider the underlying physical motivation of the problem, where each grain is understood as having a different material property.  Solutions that disconnect at a degree $k$ vertex without the connectedness assumption have have several different grains of positive area immediately merge regions.

It may seem permissible, however, for new edges to arise from vertices in $G$. The following theorem shows with the continuation assumptions imposed on $G$, face creation is impossible, and that there are a limited number of topologies for $G(t)$.

\begin{theorem} Suppose $G$ has $k$-ray conditions. For a grain network $G(s)$ with initial conditions $G$ satisfying the continuation assumptions, there are at most $5$ possible topologies of $G(s)$ when $k = 5$, $2$ topologies when $k= 4$, and 1 topology when $k = 3$ or $2$. All solutions in a sufficiently small neighborhood of the initial degree $k$ vertex are trees. \end{theorem}
\begin{proof}

Let $G$ be a network with $k$-ray conditions, with a  degree $k$ vertex at $\tilde v$, and boundaries $\alpha_i(x), x \in (0,1)$ emanating from $v$, for $i = 1, \dots, l$. For some $\varepsilon >0$, suppose $G(s), s \in (0,\varepsilon)$ is a grain network satisfying the continuation assumptions, with corresponding evolving boundaries $\alpha_{i}(x,s)$ and neighborhoods $U_v$ for $v \in V$.

 We now fix a time $s\in (0,\varepsilon)$ and focus on $U:=U_{\tilde v}$.  For a network with $V$ vertices, $E$ edges, and $F$ faces,  the Euler characteristic $\chi(G_{U}(s))= V-E+F$  is $1-k$. This characteristic includes the edges $\alpha_i$ that cross $\partial U$, but neither the vertices of these edges that lie outside of $U$, nor faces that intersect the compliment of $U$. This can be seen by explicitly calculating the Euler characteristic for simple examples of subnetworks ($k$ edges meeting at a point in $U$, for instance), and recalling from Euler's theorem that  $\chi$ is invariant for any  planar graph contained in $U$ with $k$ edges that intersect $\partial U$.

We claim that no grains in $G_U(s)$ can have less than 7 sides.  First note that no topological changes occur in $G_U(t)$ during time $t \in (0,\varepsilon)$. However, by the $n-6$ rule, this means that any grain  with $n<7$ sides and area $a> 0$ at time $s\in (t,t+\epsilon]$ would have area $a+(s-t)(n-6)>0$ at time $t$, which is a contradiction to the initial configuration of edges.

The main claim, then, is that no network  $G_U(s)$ can exist which contains only faces of more than 6 sides. The first step is an identity relating the number of edges and vertices.  Since $G_U(s)$ is trivalent, we can count edges by double counting. For every $v \in G_U(s)$, there are three edges. We sum over the vertices to obtain the edge count, noting that every edge, except those which intersect $\partial U$, is counted twice.  This gives us
\begin{equation} \label{vertest}
E = \frac{3V+k}{2} \Rightarrow V = \frac{2E-k}{3}.
\end{equation}

We can also estimate $E$ with relation to $F$.  Supposing each face of $F$ has at least 7 sides, the number of edges is at least $7F/2$, since in the  worst case every edge is shared between two faces.  We also have an extra $k$ edges (those intersecting $\partial U$) which are not part of any face in $G_U(s)$. This gives us
\begin{equation}\label{faceest}
E\ge\frac{7F}{2}+k.
\end{equation}
This estimate is sufficient for the $2$ and $3$ ray cases.  To see this, we use (\ref{faceest}), (\ref{vertest}), and the Euler formula to give us
\begin{eqnarray}
V-E+F= 1-k \\
\Rightarrow \frac{2E-k}{3} -E+F = 1-k\nonumber\\
\Rightarrow F =1+\frac{E}3-\frac{2k}3 \nonumber\\
\ge1+\frac {7F}{6}+\frac k3-\frac {2k}3 \nonumber\\
\Rightarrow F\le 2(k-3)\nonumber
\end{eqnarray}

For the case of 4 and 5 rays, however, we need a slightly stronger estimate. Toward this end,  we can assume, without loss of generality, that $U$ is a circle, and $G(s)\cap \partial U$ consists of $k$ points $p_1, \dots, p_k$ that are ordered clockwise. If any edges corresponding to $p_i$ meet at a vertex, then we can draw a new neighborhood $U'$ with $k-1$ points where $G_{U'}(s)$ is a subnetwork.  This process may possibly be continued until we are left with three or less points in $\partial U\cap G(s)$, in which case we are done. Otherwise, for $k > 3$, between any two points $p_k$ and $p_{k+1}$ with vertices $v_k,v_{k+1} \in G_U(s)$, mod $k$, there exists edges $E_1^k, \dots, E_{l_k}^k$ that connect $p_k$ and $p_{k+1}$, and are also edges of a face $F^k$ in the complement of $G_U(s)$. The sequence of edges $E_1^1,\dots, E_{l_1}^1, \dots, E_1^k, E_{l_k}^k$ forms a circuit whose edges do not cross that connects the vertices $v_i, i = 1, \dots k$.  Thus each edge $E_j^i$, $i = 1, \dots, k$, $j = 1, \dots, l_i$ occurs in only one face of $G_U(s)$.  This implies that we have undercounted (\ref{faceest}) by at least $k/2$ edges, which gives us the new estimate
\begin{equation}\label{strongfaceest}
E \ge \frac{7F+3k}{2} .
\end{equation}

\begin{figure}
\begin{centering}
\includegraphics{graintrees.png}
\caption {\textbf{Continuation through a $k$-degree vertex. }\label{crittypes}Possible topologies of  curvature flow with $k$-ray initial conditions, with $k= 3, 4,$ and $5$. These correspond to planar rooted  trivalent tree, with the rooted vertex in each figure denoted by a dot.   }
\end{centering}
\end{figure}

We now combine (\ref{vertest}), (\ref{strongfaceest}), and the Euler characteristic formula to obtain
\begin{eqnarray}
V-E+F = 1-k \\
\Rightarrow F =1+\frac{E}3-\frac{2k}3\nonumber\\
\ge1+\frac{7F+3k}{6}-\frac{2k}3 \nonumber\\
\Rightarrow F\le k-6 \nonumber.
\end{eqnarray}
 We therefore search for solutions containing no faces.  Such networks are precisely trees.  Specifically, we seek trivalent trees with $k$ leaves corresponding to  edges containing $p_i$, $i = 1, \dots k$.  Since the endpoints of the leaves are fixed, the number $M_n$ of such trees is equal to the planar trivalent rooted trees of $n$ leaves, which is equal to the ${n-1}^{st}$ Catalan number $C_{n-1}$ \cite{hungerbuhler1995isomorphism}. Specifically, $M_2 = 1,M_3 = 1, M_4 = 2$, and $M_5 = 5$.
\end{proof}
The explicit graph types are shown in Fig. \ref{crittypes}. However, regardless of topological type, flowing through a  four and five sided grain deletions gives the same topological transitions, as shown in Fig. \ref{distrules}.

\section{PDMPs and grain coarsening}\label{applygrain}
We now demonstrate that a mean-field model of grain coarsening is a specific example of the $k$-species PDMP explored in \cite{klob2013pdmp1} .  The one parameter constants are as follows, where we index our species $i = 2, \dots, M+1$ according to the $n-gons$ (grains with $n$-sides) they describe:

 \begin{centering}
 \begin{tabular}{|c|c|}\hline
General Variable & Value for grain coarsening \\\hline
$M$ & $M>6$ (free parameter)\\\hline
$M_-$ & 4 \\\hline
$\beta$ & $\beta>0$ (free parameter) \\\hline
$v_i$&$i-6 $  \\\hline
$K^{(l)}$&$K^{2}=2, K^{(3)} = 3, K^{(4)}= 2, K^{(5)}= 3, K^{int} = 4$ \\\hline
\end{tabular}

\end{centering}
\vspace{10 pt}
Describing our parameters in more detail:
\begin{itemize}
\item A particle of size $a$ of species $L_n = \mathbb{R}^+, n = 2 ,\dots, M$, corresponds to an $n$-gon with area $a$.
\item By the $n-6$ rule, the velocity $v_n(a)$ of an $n$-gon is the constant $v_n(a) \equiv n-6$. Thus, $M_- = 4$.
\item Constants $K^{(i)},K^{int}$ correspond to the number of side redistributions for each type of grain  and side deletion, e.g.  five sided grain deletions affect three grains, $K^{(5)} = 3$.
\end{itemize}

For $n$-gon probability weights, we impose the mean-field assumption that  $n$-gon selection is proportional to $n$.  To obtain a closed system, we forbid two-sided grains to lose sides, three-sided grains to lose two sides, and $M-$sided grains to gain a side. We will not consider one-sided grains, as they are relatively rare in actual metal networks (about .1\%, see \cite{fradkov1985experimental}).

We now give the explicit weights for $n$-gon selection in grain coarsening.  These are based on the Fradkov assumption that grains are selected based only on their side number. The weights are then
\begin{equation}
w_j^{(2)}= \begin{cases}j, & j \in \{4,\dots, M\},   \ \\
0, & j \in \{2,3\},  \ \\
\end{cases}
\end{equation}
\begin{equation}
w_j^{(3)}= \begin{cases}j, & j \in \{3,\dots, M\},   \ \\
0, & j =2,  \ \\
\end{cases}
\end{equation}
\begin{equation}
w_j^{(4)}= \begin{cases}j, & j \in \{3,\dots, M\},   \ \\
0, & j =2,  \ \\
\end{cases}
\end{equation}
\begin{equation}
w_j^{(5)}= \begin{cases}j, & j \in \{3,\dots, M-1\},   \ \\
0, & j \in\{2,M\},  \ \\
\end{cases}
\end{equation}
\begin{equation}
w_j^{int}= \begin{cases}j, & j \in \{3,\dots, M-1\},   \ \\
0, & j \in\{2,M\}.  \ \\
\end{cases}
\end{equation}

Reassignments are in accordance with  side redistribution under grain and side deletion. Recall the upper index $l= 1, \dots M_-$  in $R_{kj}^{(l)}$ refers to the side number of the deleted grain, $k= 2,\dots, M$ refers to the side number of a neighboring grain before undergoing side reassignment, and $j= 1\dots, K^{(l)}$ refers to the specific reassignment of the $j^th$ grain that is reassigned sides. Refer to Fig. \ref{distrules} for a pictorial description distribution of sides before and after grain and side deletions. Note that we disallow reassignments that create 1 and $M+1$ sided  grains.
The explicit reassignments are then\begin{equation}
R_{kj}^{(2)}= \begin{cases}k-2, & k \in \{4,\dots, M\},j\in \{1,2\},         \\
0, & k \in \{2,3\} ,  \ \\
\end{cases}
\end{equation}
\begin{equation}
R_{kj}^{(3)}= \begin{cases}k-1, & k \in \{3,\dots ,M\},j\in \{1,2,3\}, \\
0, & k =2,  \ \\
\end{cases}
\end{equation}
\begin{equation}
R_{kj}^{(4)}= \begin{cases}k-1, & k \in \{3,\dots ,M\},j\in \{1,2\}, \\
0, & k =2,  \ \\
\end{cases}
\end{equation}
\begin{equation}
R_{kj}^{(5)}= \begin{cases}k-1, & k\in \{3, \dots,M-1\}, j \in \{1,2\},    \\
k+1, & k\in \{3 ,\dots,M-1\},j=3,\\
0, & k\in \{2 ,M\},\\
\end{cases}
\end{equation}
\begin{equation}
R_{kj}^{int}= \begin{cases}k-1, & k\in \{3, \dots,M-1\}, j \in \{1,2\},    \\
k+1, & k\in \{3 ,\dots,M-1\},j\in\{3,4\},\\
0, & k\in \{2 ,M\}.\\
\end{cases}
\end{equation}

\begin{figure}
\begin{centering}
\includegraphics{grainpic.png}
\caption{\textbf{Reassignments of sides before and after deletions.  }\label{distrules} Numbers in grains refer to side numbers.}
\end{centering}
\end{figure}
We now give an explicit form to the limiting kinetic equations of \cite{klob2013pdmp1} for grain coarsening. Assuming a continuous density of grain areas $u_k(x,t)$, we  can write a system of kinetic equations  for grains with $k$ sides:\begin{equation}\label{grainpde}
\partial_tu_{k}(x,t)+(k-6)\partial_xu_{k}(x,t) = h^{k+}_{grain}(u,t)-h_{grain}^{k-}(u,t)+h^{k+}_{side}(u,t)-h_{side}^{k-}(u,t).
\end{equation}

The four source terms of the right hand side of (\ref{grainpde}) describe, in order, addition and deletion of grains from $L_k$ due to grain deletions, and addition and deletion from $L_k$ due to side deletions.
Explicitly, they are, for $k = 2, \dots, M$,
\begin{eqnarray}
h_{grain}^{k,+}(u,t)= 8u_2(0,t)W_{k+2}^{(2)}(t)u_{k+2}(x,t)+9u_{3}(0,t)W_{k+1}^{(3)}u_{k+1}(x,t)\\+4u_{4}(0,t)W_{k+1}^{(4)}(t)u_{k+1}(x,t)+ 2u_{5}(0,t)W_{k+1}^{(5)}(t)u_{k+1}(x,t)\nonumber\\+u_{5}(0,t)W_{k-1}^{(5)}(t)u_{k-1}(x,t), \nonumber
\end{eqnarray}
\begin{eqnarray}
h_{grain}^{k,-}(u,t) = u_k(x,t)[8u_2(0,t)W_{k}^{(2)}(t)+9u_{3}(0,t)W_{k}^{(3)}(t)\\+4u_{4}(0,t)W_{k}^{(4)}(t)+3u_{5}(0,t)W_{k}^{(5)}(t)],
\nonumber
\end{eqnarray}
\begin{equation}
h_{side}^{k,-}(u,t)= \frac{2\beta G(t)}{G_{int}(t)}[w_{k-1}^{int}u_{k-1}(x,t)+w_{k+1}^{int}u_{k+1}(x,t)],
\end{equation}
\begin{equation}
h_{side}^{k,+}(u,t)= \frac{4\beta G(t)}{G_{int}(t)}w_k^{int}u_k(x,t),
\end{equation}
for tier weights $w_i^{(l)},w_i^{int}$, total numbers $G(t),G_{int}(t)$, and species selection weight fraction $W_i^{(l)},W_i^{int}$ defined in (\ref{limeq}).
Our main result of the previous chapter is the convergence of empirical PDMPs to the weak form of (\ref{grainpde}) for absolutely continuous measures $\mu_k(t) \in \mathcal{M}(\mathbb{R}^+)$, obtained by pairing solutions $\mu_k$ with a test function $\phi \in \mathcal C$ and integrating along $\mathbb{R}^+$. The weak form of (\ref{grainpde}) is then, for  $k = 2, \dots, M$,
 \begin{eqnarray}\label{weakgrainpde}
\langle C_k(t), \phi\rangle -  \langle C_k(0), \phi\rangle+(k-6)\int_0^t \langle C_k(s), \phi' \rangle\\= H^{k+}_{grain}(u,t)-H_{grain}^{k-}(u,t)+H^{k+}_{side}(u,t)-H_{side}^{k-}(u,t) ,\nonumber
\end{eqnarray}
with
\begin{eqnarray}
H^{k+}_{grain}(u,t)=2\int_0^tW^{(2)}_{k+2}(s)\langle C_{k+2}(s), \phi \rangle dF_{2}(s)+\\3\int_0^tW^{(3)}_{k+1}(s)\langle C_{k+1}(s), \phi \rangle dF_{3}(s)+2\int_0^tW^{(4)}_{k+1}(s)\langle C_{k+1}(s), \phi \rangle dF_{4}(s)+ \\2\int_0^\infty W^{(5)}_{k+1}(s)\langle C_{k+1}(s), \phi \rangle+W^{(5)}_{k-1}(s)\langle C_{k-1}(s), \phi \rangle dF_5(s), \nonumber
\end{eqnarray}
\begin{eqnarray}
H_{grain}^{k,-}(u,t) =2 \int_0^t\langle C_{k}(s), \phi \rangle W^{(2)}_{k}(s)dF_2(s)\\+3\int_0^t\langle C_{k}(s), \phi \rangle W^{(3)}_{k}(s)dF_3(s)+2\int_0^t\langle C_{k}(s), \phi \rangle W^{(4)}_{k}(s)dF_4(s)\nonumber\\+3\int_0^t\langle C_{k}(s), \phi \rangle W^{(5)}_{k}(s)dF_{5}(s), \nonumber
\end{eqnarray}
\begin{equation}
H_{side}^{k,-}(u,t)= \int_0^t\frac{2\beta N(s)}{N_o(s)}[w_{k-1}^{int}\langle C_{k-1}(s), \phi \rangle+w_{k+1}^{int}\langle C_{k+1}(s), \phi \rangle]ds,
\end{equation}
\begin{equation}
H_{side}^{k,+}(u,t)= \int_0^t\frac{4\beta N(s)}{N_o(s)}w_{k}^{int}\langle C_{k}(s), \phi \rangle ds.
\end{equation}
A point of departure from the Fradkov model is the choice of side deletion parameter $\beta$.  For the PDMP model, each grain is equipped with a Poisson clock that activates with average time $\beta$.  When such a clock is activated, four grains are selected to change side number in accordance with rules for side flipping.  This differs from Fradkov's model, which assumes side deletion over grain deletion occurs at a constant ratio $\beta$.  Graphs depicting the ratio of side to grain deletions are depicted in Fig. \ref{fradrat1}-\ref{fradrat3}. .

From the previous chapter, we have seen that there exists limiting subsequence that converges to a solution of (\ref{weakgrainpde}).  We now show that the solution retains several properties from the pre-limit PDMP.

\section{Properties of grain coarsening}

One advantage to the stochastic method of proving existence  of solutions to (\ref{weakgrainpde}) is that we can use properties from the finite particle PDMP model to prove, with little difficulty, that the same properties hold for the hydrodynamic limit.  Our main tool is the observation that since $\langle \mu_k^N(t),\phi\rangle \xrightarrow {l.u.} \langle \mu_k(t),\phi\rangle$ for all $\phi \in C_b(\mathbb{R}^+)$, we can choose $\phi \equiv 1$ to obtain the convergence of total numbers $g^N_k(t)\xrightarrow{l.u.} g_k(t)$.

\begin{theorem}  The following properties hold for the limiting distributions $\mu_k(t)$
\begin{enumerate}
\item (\textbf{Conservation of Polyhedral Defect}). If the initial average side number for grains is 6, it remains so:
\begin{equation}
\sum_{k = 2}^M(k-6)g_{k}^0= 0 \quad \Rightarrow \quad P(t):=\sum_{k = 2}^M(k-6)g_k(t)= 0.
\end{equation}
\item (\textbf{No runoff at infinity}).  All loss of total number occurs from boundary events, or
\begin{equation}
N(t) := \sum_{k =2}^M g_k(t) =  \sum_{k = 2}^M g_{k}^0-\sum_{i = 2}^5 F_i(t).
\end{equation}
\item (\textbf{Decreasing densities}).  The total number is decreasing in time:
\begin{equation}
N(t)\le N(s) \quad \hbox{ for } t\ge s.
\end{equation}
\end{enumerate}
\end{theorem}
\begin{proof}
Suppose we have a limiting initial measure $\mu_k^0$ with zero polyhedral defect. For $i \in \mathbb N$, let $\mu_k^{N_i,0}\in \mathcal M(\mathbb R^+)$  be a sequence of initial empirical distributions of particles with zero polyhedral defect, satisfying $\mu_k^{N_i,0} \rightarrow \mu_k^0 $ in $\mathcal M(\mathbb{R}^+)$. Constructing such a sequence is always possible. To see this, choose integers $N_i \rightarrow \infty$  ,where $N_i= N_i^2+\dots+N_i^M$ , $\sum_{k = 2}^M (k-6)N_i^k = 0 $, and $N_i^k/\sum_j N_i^j \rightarrow g_{i,0}$. For each $n$-gon in $L_n$, randomly select $N_i^k$ particles with respect to the distribution $\mu_k^0$.  By the Glivenko-Cantelli theorem, with probability one the empirical distributions  $\mu_k^{N_i,0}$ will converge  to $\mu_k^0$ in $\mathcal M(\mathbb{R}^+)$.

For the empirical measures $\mu^{N_i,0}(t)$, it is straightforward to see conservation of polyhedral defect.  This is because transport of grains does not change a grain's side number, and one can check that any critical event has a net zero change in polyhedral defect. Thus
\begin{equation}
P^{N_i}(t) :=\sum_{k = 2}^M(k-6)g_k^{N_i}(t)= 0.
\end{equation}
Since $g_k$ is the local uniform limit of $g_k^{N_i}(t)$, we obtain property (1).

For property (2), we again choose a sequence of empirical initial measures $\mu_k^{N_,0} \rightarrow \mu_k^0 $ in $\mathcal M(\mathbb{R}^+)$, this time with no further qualifications. For the empirical densities, we have
\begin{equation}\label{totalmass}
\sum_{k =2}^M g_k^N(t) =  \sum_{k = 2}^M g_{k,0}^{N}-\sum_{i = 2}^5 F_i^N(t). \end{equation}
In the previous chapter we've shown that $F_i^N(t) \xrightarrow{l.u.} F_i(t)$, so taking the local uniform limit proves (2).  Statement (3) then follows immediately from (\ref{totalmass}), as the cumulative distributions $F_i$ are increasing.
\end{proof}

Our next task is to show that our system conserves area, which is a consequence of conservation of polyhedral defect.  In this case, we'll  use the weak form of the limiting equations.  Here, we denote the identity function $id: x \mapsto x$.
\begin{theorem}(\textbf{Conservation of area}).  For initial distributions which satisfy
\begin{equation}
\sum_{k = 2}^M\langle \mu_k^0,id\rangle< \infty, \quad P(0) = 0,
\end{equation}
we have
\begin{equation}
\sum_{k = 2}^M\langle \mu_k(t),id\rangle = \sum_{k = 2}^M\langle \mu_k^0,id\rangle
\end{equation}
\end{theorem}
\begin{proof}  For $r,j>0$, we use functions $\phi^{r,j}:\mathbb{R}^+ \rightarrow \mathbb{R}^+$ defined by
\begin{equation}
\phi^{r,j}(x) = \begin{cases}x & x<r \\
\psi^{j}(x-r)+r & x \in [r,r+\frac 1j] \\
r  \ & x > r+\frac 1j,
\end{cases}
\end{equation}
where $\psi^j:[0,\frac 1j]\rightarrow \mathbb{R}^+$ is a $C^1(\mathbb{R}^+)$ function with $\psi'(0) = 1$ and $\psi'(\frac1j) = 0$, so that $\phi^{r,j}\in \mathcal C$.  If we sum (\ref{grainpde})  over grain classes, a simple  (though lengthy) calculation shows that
\begin{equation}
\sum_{k = 2}^MH^{k+}_{grain}(u,t)-H_{grain}^{k-}(u,t)+H^{k+}_{side}(u,t)-H_{side}^{k-}(u,t)= 0.
\end{equation}
Intuitively, this identity simply states that critical events change side numbers of grains, but not their areas.  We are left with the relation
\begin{equation}\label{finitearea}
\sum_{k = 2}^M\langle \mu_k(t), \phi^{r,j}\rangle =  \sum_{k = 2}^M\langle \mu_k(0), \phi^{r,j}\rangle-\sum_{k = 2}^M(k-6)\int_0^t \langle \mu_k(s), (\phi^{r,j})' \rangle.
\end{equation}
Notice, however, that
\begin{equation}
\langle \mu_k(s), (\phi^{r,j})' \rangle= \mu_k(s)([0,r))+\int_0^{\frac 1j}\psi^j d\mu_k(s) \rightarrow g_k(s) \hbox{ as } r,j\rightarrow \infty.
\end{equation}
This implies that taking the limit as $j,r\rightarrow \infty$ in (\ref{finitearea}) gives
\begin{equation}
 \sum_{k = 2}^M\langle \mu_k(t), id\rangle =  \sum_{k = 2}^M\langle \mu_k(0), id\rangle-\int_0^t P(s)ds.
\end{equation}
Our theorem then follows from conservation of polyhedral defect.
\end{proof}

\section{Computations}\label{computations}
Simulations for PDMP grain coarsening were performed in Matlab. Grains over several different initial configurations and $\beta$ parameters were tested. Illustrations, unless otherwise noted, are with $N= 9\times 10^4$ initial grains with a maximum of 20 sides. \textbf{Uniform initial distributions} have $10^4$ $n$-gons, for $n=2, \dots, 10$, distributed uniformly in $[0,1]$.   At time  $t= 5$ the number of grains drops an order of magnitude (see figure \ref{grainnumber}).  We observe the following:
\subsection*{Mean area growth}
Simulations of grain networks which directly approximate mean curvature flow suggest that the average grain area grows linearly.   (see, \cite{elsey2009diffusion,anderson1984computer,wakai2000three}, for instance). In our simulations, the plot the average area $\langle A_\beta(t)\rangle$ at time $t$ for the grain coarsening PDMP with varying Poisson parameters $\beta$. For small values of $\beta$,   $\langle A_\beta(t)\rangle$ is approximately linear (see Fig. \ref{av1},\ref{av2}).  The same behavior holds for average area of grains with $k$ sides, $k = 1, \dots, M$. For larger values of $\beta$, coarsening becomes convex (Fig. \ref{av3}).

\subsection*{Distribution of $n$-gons} For low values of $\beta$, the distribution of $n$-gons is approximately stationary (see Fig. \ref{sidedist1}) .  However, as $\beta$ increases, distributions of  $n$-gons $n= 3, \dots, 9$ become more uniform  as time increases (Fig. \ref{sidedist3}). This is similar to the numerical experiments of Fradkov \cite{fra881}.   Plots of $n$-gon densities for $\beta = 0$ and the Kinderlehrer model described in \cite{kin06} for stationary densities (time $t= 5$ for both models) shows a similarity of  statistics (see Fig. \ref{kindcompare}).

 \subsection*{Grain densities and diffusion} In Fig. \ref{tierdens1}-\ref{tierdens9}, we plot histograms for grain densities of 4, 6, and 8 sides under $\beta$ values of .01, .1, and 1.  Each bar represent a bin of 40 grains. From grain deletions, the number of bars decreases, corresponding to a decrease in number for increasing time.  The densities for all $n$-gons drift to the right with time (see Fig. \ref{averagewhole}).  The parameter $\beta$ appears to play a diffusing role, as larger $\beta$ also correspond to increased variance.

\subsection*{Side to grain deletion ratio} As observed in Section \ref{applygrain}, the PDMP model differs from the Fradkov model in its choice of parameter $\beta$. Thus, we will denote $\gamma_{\beta}(t)$ as the (time dependent) ratio of side deletions to grain deletions. For a uniform initial distribution,  under differing $\beta$,  $\gamma_{\beta}(t)$ exhibits similar concave profiles   (see Fig. \ref{fradrat1}-\ref{fradrat3}).

\section{Remarks}

A major advantage to viewing grain growth statistics as approximations of a hydrodynamic limit  is the relative ease of implementing simulations.  As we have seen, we can immediately raise several conjectures about grain behavior.  For example, for $\beta = 0$, does there exist a stable attractor for the distribution of $n$-gon densities?  Several details of the limiting densities make this question difficult.  First, individual $n$-gon densities do not have stable attractors.  Also, we still have yet to establish existence for an infinite time, which would be central in an asymptotic analysis.  Such long time existence was established for the Fradkov system in \cite{henseler2008kinetic}, but the existence of universal attractors in this model remains unanswered.

   The role of the flipping parameter $\beta$ plays an interesting role in altering grain statistics. The general trend noted in simulations is that $\beta$ tends to act as a diffusion agent between $n$-gons. The rule for side flipping is similar to the particle transfer rule in the following model, as described in \cite{bruus2008theoretical}.  Here, we are approximating the dispersal of a fluid plug with initial density $u_{0}(x,y)$ in a carrier fluid. If the fluid has a vertical velocity profile of $V(y)$, the governing equations for the evolving density $u(x,y,t)$ have the form
\begin{eqnarray}
u_t-V(y)u_{x} = \frac{\alpha}2 u_{yy}\\
u(x,y,0) = u_0(x,y). \nonumber
\end{eqnarray}
The factor $\alpha$ is the diffusivity factor for the plug.  Taken as a $k$-species PDMP, we can approximate the domain carrier fluid by a large number of horizontal tiers, and then approximately the fluid plug as particles traveling on these tiers with velocity $V(y^*)$ for a tier located at $y = y^*$.  This model has no particle deletions (the fluid is conserved), but each particle is equipped with a Poisson clock of parameter $\alpha$, that when set, transfers a particle  to the next highest species with probability 1/2, and to the next lowest species with probability 1/2.  This, rule, however, is roughly the same as side flipping. In both models, for $n$ particles that are selected in an intermediate species, roughly $n/2$ will transfer upwards by one species, and $n/2$ will lower by a species. Thus, it is reasonable to expect the $\beta$ parameter in grain coarsening to act in a similar manner as the diffusion parameter $\alpha$ for the fluid plug. This is, of course, not precise, as we have not actually shown the right scaling of vertical species interspacing for the fluid plug, nor have we considered how grain deletions may interact with  diffusion due to side deletion.
\begin{figure}
\hspace{130pt}\includegraphics[width=.3\textwidth]{fluidpic.png}
\caption{\textbf{Dispersal of a fluid plug.}  A carrier fluid   is approximated by horizontal tiers, and a fluid plug (the inner region of the figure) is approximated by particles (denoted by dots) which travel horizontally on tiers corresponding to the vertical velocity profile $V(y)$.}
\end{figure}

\clearpage{}

\begin{figure}
   \begin{centering}
\includegraphics[width=.5\textwidth]{grainnumber.jpg}
        \caption{\textbf{Grain number} $N(t)$.}\label{grainnumber}
        \end{centering}
  \end{figure}

 \begin{figure}
 \begin{centering}
  \includegraphics[width=.5\textwidth]{meanregareazero.jpg}
\caption{\textbf{Mean area of grains with $\beta = .01$} Mean area is plotted with line of best fit $y_1 = .2806+.9214x$  (the lines are indistinguishable). The correlation between average area and $y_1$ is $r^2= .9998$. }\label{av1}
\end{centering}
\end{figure}

\begin{figure}
  \begin{centering}
\includegraphics[width=.5\textwidth]{meanregareatenth.jpg}
\caption{\textbf{Mean area of grains with $\beta = .1$} Mean area is plotted with line of best fit $y_1 = .1909+1.0347x$   (the lines are almost indistinguishable). The correlation between average area and $y_1$ is $r^2= .9979$. }\label{av2}
\end{centering}
\end{figure}

\begin{figure}
  \begin{centering}
\includegraphics[width=.5\textwidth]{meanregareaone.jpg}
\caption{\textbf{Mean area of grains with $\beta = 1.$} Mean area is plotted with line of best fit $y_1 = -.2796+1.6624x$   (mean area is convex). The correlation between average area and $y_1$ is $r^2= .9881$. }\label{av3}
\end{centering}
\end{figure}

\begin{figure}
\begin{centering}
\includegraphics[width=.5\textwidth]{kindocompare.jpg}
\caption{Comparison of side number frequency between grain coarsening PDMP (dots) at $\beta= 1$ and the Kinderlehrer model (crosses) at $t= 5$.}\label{kindcompare}
\end{centering}
\end{figure}

\begin{figure}
        \begin{centering}
        \includegraphics[width=.5\textwidth]{classdistzero.jpg}
        \caption{Frequency of side number for $\beta= .01$ for various times.}\label{sidedist1}
\end{centering}
\end{figure}

\begin{figure}
        \begin{centering}
        \includegraphics[width=.5\textwidth]{classdisttenth.jpg}
        \caption{Frequency of side number for $\beta= .1$ for various times.}
\end{centering}
\end{figure}

\begin{figure}
        \begin{centering}
        \includegraphics[width=.5\textwidth]{classdistone.jpg}
        \caption{Frequency of side number for $\beta= 1$ for various times.}\label{sidedist3}
\end{centering}
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth]{histbetazerotier4.pdf}
\vspace{-130pt}
\caption{Histograms of four-sided grain densities at $\beta = .01$.}\label{tierdens1}
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth]{histbetatenthtier4.pdf}
\vspace{-130pt}
\caption{Histograms of four-sided grain densities at $\beta = .1$.}
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth]{histbetaonetier4.pdf}
\vspace{-130pt}
\caption{Histograms of four-sided grain densities at $\beta = 1$.}
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth]{histbetazerotier6.pdf}
\vspace{-130pt}
\caption{Histograms of six-sided grain densities at $\beta = .01.$}
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth]{histbetatenthtier6.pdf}
\vspace{-130pt}
\caption{Histograms of six-sided grain densities at $\beta = .1$.}
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth]{histbetaonetier6.pdf}
\vspace{-130pt}
\caption{Histograms of six-sided grain densities at $\beta = 1$.}
\end{figure}

\clearpage{}

\begin{figure}
\includegraphics[width=\textwidth]{histbetazerotier8.pdf}
\vspace{-130pt}
\caption{Histograms of eight-sided grain densities at $\beta = .01$.}
\end{figure}

\clearpage{}
\begin{figure}
\includegraphics[width=\textwidth]{histbetatenthtier8.pdf}
\vspace{-130pt}
\caption{Histograms of eight-sided grain densities at $\beta = .1$.}
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth]{histbetaonetier8.pdf}
\vspace{-130pt}
\caption{Histograms of eight-sided grain densities at $\beta = 1$.}\label{tierdens9}
\end{figure}

\begin{figure}
\begin{centering}
\includegraphics[width=.5\textwidth]{averageareas.jpg}
\caption{Average areas of grains with sides 2-10 at $\beta= 0$.  Note how for each collection of $n$-gons,for $n= 2, \dots, M$, average area increases linearly.  Similar behavior holds for $\beta= .1$ and $\beta= 1.$}\label{averagewhole}
\end{centering}
\end{figure}

\begin{figure}
\centering
        \includegraphics[width=.5\textwidth]{coarseratiobetazero.jpg}
        \caption{Side to grain deletion ratio $\gamma_\beta(t)$ at $\beta=.01$.}\label{fradrat1}
 \end{figure}

 \begin{figure}
        \centering
        \includegraphics[width=.5\textwidth]{coarseratiobetatenth.jpg}
        \caption{Side to grain deletion ratio $\gamma_\beta(t)$ at $\beta=.1$.}
 \end{figure}

        \begin{figure}
        \centering
        \includegraphics[width=.5\textwidth]{coarseratiobetaone.jpg}
        \caption{Side to grain deletion ratio $\gamma_\beta(t)$ at $\beta=1$.}\label{fradrat3}
       \end{figure}

\clearpage{}


\epigraph{``It's known in theory that log(log(n)) approaches infinity, but no one has ever observed it in practice."}{Grant Sanderson}

To prove the hypothesis that `it is possible to create open source software implementation to simulating atmospheric dynamics, with a recurrent neural network and ensemble prediction system being used in combination with a physical model, that such a software implementation has a reasonable execution time to forecast length ratio, and to determine if such an implementation has a statistically significant accuracy improvement over a traditional deterministic physical model', it is necessary to carry out a series of appropriate benchmarks.

It was determined that it was necessary to carry out a series of appropriate benchmarking within the areas of performance, and accuracy. The performance benchmark would demonstrate whether or not the software has a reasonable execution time to forecast length ratio, and the accuracy benchmark would highlight whether or not the forecasts produced by the software had a reasonable level of accuracy. Considering there is no open source software to which one can compare the software, it was determined that the software would be compared against a proprietary implementation. For this purpose, OpenWeatherAPI was selected as the most appropriate option as it provides accurate data for slightly longer time ranges than other similar application programming interfaces\cite{owa}.

Please note that all of the benchmarking code is available on the AMSIMP repository, which can be accessed using the following url: \url{https://github.com/amsimp/initial-conditions}

\section{Performance Benchmark}
One of the most important factors to consider when benchmarking a piece of software is the execution time of said software. A piece of software can be as precise and accurate as it wants, however, it isn't of much practical use if it takes the length of time until the heat death of the universe to finish executing. For example, attempting to brute force a 12 character alphanumeric password might work, however, it would take approximately two centuries based on the current capabilities of computers. Considering simulating atmospheric dynamics requires a significant amount of computational resources, it was deemed necessary to run the software on a virtual machine. Using a virtual machine also allows for easier replication and duplication of results, especially considering the wide variety of computer hardware available today. Google's Compute Engine was ultimately chosen as it provided the most flexibility, with the amount of promotional credit being significantly greater than the competition. Without the promotional credit, the benchmarking process would have been an extremely expensive affair to complete (the hardware specification below would have cost approximately one dollar an hour). It was also deemed the only feasible option available due to the restrictions imposed by the COVID-19 pandemic.

\subsection{Hardware Specifications}\label{specs}
\begin{center}
\begin{tabular}{|c|c|}
 \hline
  & Compute Engine n1-custom-configuration \\
 \hline
 \textbf{vCPUs} & 8 \\
 \hline
 \textbf{Memory} & 128 GB \\
 \hline
 \textbf{Operating System} & Ubuntu 20.04 LTS \\
 \hline
\end{tabular}\par
\bigskip
Table 5.3.: Compute Engine Hardware Specifications
\end{center}

\subsection{Benchmarking Method}
\begin{definition}
Algorithm is a set of mathematical instructions or rules that, especially if given to a computer, will help to calculate an answer to a problem.
\end{definition}

The aspect of the performance that is being benchmarked is the length of time it takes to generate a forecast of a fixed length, and after which, determining in order to determine the ratio between the execution time and the length of the forecast. For this particular experiment, a forecast length of five days was specified. The reason for utilising such a ratio is that it provides a rough estimate of the usability time of a forecast. For example, it would be highly undesirable for the simulation to take several days if the forecast was only a day in length. A small ratio would increase the amount of time a forecast is usable for, and vice versa, for a high ratio. The following algorithm on the next page was created for this purpose.

\begin{algorithm}[H]
    \caption{Performance Algorithm}
    \begin{algorithmic}[1]
        \State $ start \gets $ The time at the start of the experiment (UNIX time).
        \State $ output = scheme(\texttt{scheme-name}) \gets $ Generate a forecast using the selected scheme.
        \State $ end \gets $ The time at the end of the experiment (UNIX time).
        \State $ runtime = end - start \gets $ The difference between the start and end variables is the runtime of the selected scheme.
        \State $ forecast\_length \gets $ The fixed length of the generated forecast.
        \State $ratio = \frac{runtime}{forecast\_length}$
    \end{algorithmic}
\end{algorithm}

\section{Accuracy Benchmark}
Accuracy is probably the most important metric when considering the validity of a given forecasting scheme, therefore, extensive benchmarking was carried out in this particular area. The accuracy benchmarks can be broken down into three distinct categories: comparing against a nave forecasting model, comparing the different forecasting schemes found in the software, and comparing the accuracy of the best forecasting scheme in the software with a proprietary forecasting implementation. The fixed length of the forecast was chosen to be five days, as it was deemed to be a good comprise between short and long term forecasting.

\subsection{Mean Absolute Scaled Error}
The first and most important benchmark to consider is the comparison against a naive forecasting model. A naive forecasting model is one that assumes that the given parameter will not change during the duration of the forecast, the given parameter is constant with respect to time. This is done through the utilisation of the mean absolute scaled error.

\begin{definition}
The mean absolute scaled error is a measure of the accuracy of forecasts. It is the mean absolute error of the forecast values, divided by the mean absolute error of the in-sample one-step naive forecast.
\end{definition}

The mean absolute scaled error has the following desirable properties:

\begin{itemize}
    \item The mean absolute scaled error penalises positive and negative forecast errors equally, and penalises errors in large forecasts and small forecasts equally. In contrast, the mean absolute percentage error and median absolute percentage error fail both of these criteria, while the "symmetric" sMAPE and sMdAPE fail the second criteria.
    \item The mean absolute scaled error can be easily interpreted, as values greater than one indicate that in-sample one-step forecasts from the naive method perform better than the forecast values under consideration.
\end{itemize}

The following algorithm was developed with the intention to calculate the mean absolute scaled error of a given forecasting scheme, and for the comparison of said forecasting scheme with the naive forecasting model:

\begin{algorithm}[H]
    \caption{Comparison against the Naive Forecasting Model Algorithm}
    \begin{algorithmic}[1]
        \State $ forecast \gets $ The forecasted atmospheric conditions for the next five days.
        \State $ actual \gets $ The actual atmospheric conditions for the forecast period.
        \State $ naive \gets $ The naive forecasting prediction (it is constant).
        \Function{benchmark}{$forecast, actual, naive$}
            \State $MAE_{forecast} = abs(actual - forecast)$
            \State $MAE_{naive} = abs(actual - naive)$
            \State $MASE = \frac{MAE_{forecast}}{MAE_{naive}}$
        \EndFunction
    \end{algorithmic}
\end{algorithm}

\subsection{Comparison of Schemes}
The second benchmark involves the comparison of the various forecasting schemes available within the software. The available schemes that will be benchmarked are listed as follows: the physical model, the physical with the recurrent neural network enabled, the physical model with the ensemble forecasting system enabled. In the case of the ensemble forecasting system, the mean of the ensemble forecasting system will be utilised rather than any particular ensemble member. The ensemble mean normally verifies better than the control forecast by most standard verification scores because it smooths out unpredictable detail and simply presents the more predictable elements of the forecast\cite{intro_efs}. The comparison metric will be the mean squared error.

For this benchmark, what will be determined is whether the null hypothesis can be rejected or accepted. The null hypothesis $H_0$ is that there is not a significantly significant difference between two given forecasting schemes, while the alternate hypothesis $H_A$ is that there is a significantly significant difference between two given forecasting schemes. This will be determined using a two-sample independent t-test. This can be represented mathematically as the following:

\begin{equation}
    H_0 : \mu_1 = \mu_2
\end{equation}

\begin{equation}
    H_A : \mu_1 \neq \mu_2
\end{equation}

\begin{definition}
The independent t-test is an inferential statistical test that determines whether there is a statistically significant difference between the means in two groups.
\end{definition}

To do this, a significance level needs to be set that allows us to either reject or accept the alternative hypothesis. For the purposes of this project, this significance level will be 0.1. The algorithm for this benchmark is pretty similar to algorithm 2, and is as follows:

\begin{algorithm}[H]
    \caption{Comparison of Schemes Algorithm}
    \begin{algorithmic}[1]
        \State $ forecast_{1} \gets $ The forecasted atmospheric conditions for the next five days for a given scheme.
        \State $ actual_{1} \gets $ The actual atmospheric conditions for the forecast period for a given scheme.
        \State $ forecast_{2} \gets $ The forecasted atmospheric conditions for the next five days for the comparison scheme.
        \State $ actual_{2} \gets $ The actual atmospheric conditions for the forecast period for the comparison scheme.
        \State $MSE_{1} = (actual_{1} - forecast_{1})^2 \gets$ The mean squared error for the first scheme.
        \State $MSE_{2} = (actual_{2} - forecast_{2})^2 \gets$ The mean squared error for the second scheme.
        \State $p = ttest\_ind(MSE_{1}, MSE_{2}) \gets $ Determines the significance level.
    \end{algorithmic}
\end{algorithm}

\subsection{Comparison against OpenWeatherAPI}
The final benchmark will involve the comparison of the software's most accurate scheme against a proprietary implementation. The proprietary implementation ultimately chosen was OpenWeatherAPI, due to the fact that, as previously mentioned, it provides accurate data for slightly longer time ranges than other similar application programming interfaces\cite{owa}. The algorithm is the exact same as algorithm, just slightly edited to incorporate data from OpenWeatherAPI.

\begin{algorithm}[H]
    \caption{Comparison against OpenWeatherAPI Algorithm}
    \begin{algorithmic}[1]
        \State $ forecast_{1} \gets $ The forecasted atmospheric conditions for the next five days for the software's most accurate scheme.
        \State $ actual_{1} \gets $ The actual atmospheric conditions for the forecast period for for the software's most accurate scheme.
        \State $ forecast_{2} \gets $ The forecasted atmospheric conditions for the next five days for OpenWeatherAPI.
        \State $ actual_{2} \gets $ The actual atmospheric conditions for the forecast period for the OpenWeatherAPI.
        \State $MSE_{1} = (actual_{1} - forecast_{1})^2 \gets$ The mean squared error for the software's forecast.
        \State $MSE_{2} = (actual_{2} - forecast_{2})^2 \gets$ The mean squared error for OpenWeatherAPI's forecast.
        \State $p = ttest\_ind(MSE_{1}, MSE_{2}) \gets $ Determines the significance level.
    \end{algorithmic}
\end{algorithm}


\documentclass[12pt]{cdblatex}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% ============================================================================================
\section*{Example 3 The Riemann curvature tensor}

\CdbSetup{action=hide}

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u#}::Indices(position=independent).

   \partial{#}::PartialDerivative.

   ;::Symbol;

   def check (objA,objB):

       tmp := @(objA) - @(objB).

       distribute     (tmp)
       sort_product   (tmp)
       rename_dummies (tmp)
       canonicalise   (tmp)

       return tmp

   import cdblib

   # ---------------------------------------------
   check000A = cdblib.get ('check000','expected/example-03.json')
   check001A = cdblib.get ('check001','expected/example-03.json')
   check002A = cdblib.get ('check002','expected/example-03.json')

   # ---------------------------------------------
   check000B = cdblib.get ('check000','output/example-03.json')
   check001B = cdblib.get ('check001','output/example-03.json')
   check002B = cdblib.get ('check002','output/example-03.json')

   # ---------------------------------------------
   diff000 = check (check000A,check000B)   # cdb (ex-03.diff000,diff000)
   diff001 = check (check001A,check001B)   # cdb (ex-03.diff001,diff001)
   diff002 = check (check002A,check002B)   # cdb (ex-03.diff002,diff002)

\end{cadabra}

% \clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-03.diff000}}
   \Dmath*{\cdb*{ex-03.diff001}}
   \Dmath*{\cdb*{ex-03.diff002}}
\end{dgroup*}

\end{document}