% NB: use pdflatex to compile NOT pdftex.  Also make sure youngtab is
% there...

% converting eps graphics to pdf with ps2pdf generates way too much
% whitespace in the resulting pdf, so crop with pdfcrop
% cf. http://www.cora.nwra.com/~stockwel/rgspages/pdftips/pdftips.shtml

\documentclass[10pt,aspectratio=169,dvipsnames]{beamer}

\usetheme[color/block=transparent]{metropolis}

\usepackage[absolute,overlay]{textpos}
\usepackage{booktabs}
\usepackage[utf8]{inputenc}

\usepackage[scale=2]{ccicons}

\usepackage[official]{eurosym}

%use this to add space between rows
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}

\setbeamerfont{alerted text}{series=\bfseries}
\setbeamercolor{alerted text}{fg=Mahogany}
\setbeamercolor{background canvas}{bg=white}

\newcommand{\R}{\mathbb{R}}

\def\l{\lambda}
\def\m{\mu}
\def\d{\partial}
\def\cL{\mathcal{L}}
\def\co2{CO${}_2$}

\def\bra#1{\left\langle #1\right|}
\def\ket#1{\left| #1\right\rangle}
\newcommand{\braket}[2]{\langle #1 | #2 \rangle}
\newcommand{\norm}[1]{\left\| #1 \right\|}
\def\corr#1{\Big\langle #1 \Big\rangle}
\def\corrs#1{\langle #1 \rangle}

% for sources http://tex.stackexchange.com/questions/48473/best-way-to-give-sources-of-images-used-in-a-beamer-presentation

\setbeamercolor{framesource}{fg=gray}
\setbeamerfont{framesource}{size=\tiny}

\newcommand{\source}[1]{\begin{textblock*}{5cm}(10.5cm,8.35cm)
    \begin{beamercolorbox}[ht=0.5cm,right]{framesource}
        \usebeamerfont{framesource}\usebeamercolor[fg]{framesource} Source: {#1}
    \end{beamercolorbox}
\end{textblock*}}

\usepackage{hyperref}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\usepackage[europeanresistors,americaninductors]{circuitikz}

%\usepackage[pdftex]{graphicx}

\graphicspath{{graphics/}}

\DeclareGraphicsExtensions{.pdf,.jpeg,.png,.jpg,.gif}

\def\goat#1{{\scriptsize\color{green}{[#1]}}}

\let\olditem\item
\renewcommand{\item}{%
\olditem\vspace{5pt}}

\title{Energy System Modelling\\ Summer Semester 2020, Lecture 4}
%\subtitle{---}
\author{
  {\bf Dr. Tom Brown}, \href{mailto:tom.brown@kit.edu}{tom.brown@kit.edu}, \url{https://nworbmot.org/}\\
  \emph{Karlsruhe Institute of Technology (KIT), Institute for Automation and Applied Informatics (IAI)}
}

\date{}

\titlegraphic{
  \vspace{0cm}
  \hspace{10cm}
    \includegraphics[trim=0 0cm 0 0cm,height=1.8cm,clip=true]{kit.png}

\vspace{5.1cm}

  {\footnotesize

  Unless otherwise stated, graphics and text are Copyright \copyright Tom Brown, 2020.
  Graphics and text for which no other attribution are given are licensed under a
  \href{https://creativecommons.org/licenses/by/4.0/}{Creative Commons
  Attribution 4.0 International Licence}. \ccby}
}

\begin{document}

\maketitle

\begin{frame}

  \frametitle{Table of Contents}
  \setbeamertemplate{section in toc}[sections numbered]
  \tableofcontents[hideallsubsections]
\end{frame}

\section{3-node example from last time}

\begin{frame}
  \frametitle{Solving 3-node example}

  Last time we looked at an example where energy conservation at each
  vertex (Kirchhoff's Current Law, KCL) was not enough information to
  solve the power flow, since there are multiple paths in the network.
  Assume equal reactances $x_\ell = x$ on each edge.

  \vspace{.3cm}

  \begin{columns}
    \column[c]{.5\textwidth}

    \centering

  %https://tex.stackexchange.com/questions/270543/draw-a-graph-in-latex-with-tikz
  \begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw,fill=yellow}]
      \node (1) at (0,3) {$+6$};
      \node (2) at (3,3) {$0$};
      \node (3) at (1.5,0) {$-6$};
    \end{scope}

    \begin{scope}[>={Stealth[black]},
        every node/.style={fill=white,circle},
        every edge/.style={draw=red,very thick}]
      \path [->] (1) edge node {$?$} (2);
      \path [->] (2) edge node {$?$} (3);
      \path [->] (3) edge node {$?$} (1);
    \end{scope}
  \end{tikzpicture}

      \column[c]{.5\textwidth}

      Formalise by labelling the nodes and edges:

      \vspace{.5cm}

\begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw,fill=cyan}]%text=white}]
      \node (1) at (0,2.5) {1};
      \node (2) at (2.5,2.5) {2};
      \node (3) at (1.25,.3) {3};
    \end{scope}

    \begin{scope}[>={Stealth[black]},
        every node/.style={fill=white,circle},
        every edge/.style={draw=black,very thick}]
      \path [->] (1) edge node {1} (2);
      \path [->] (2) edge node {2} (3);
      \path [->] (3) edge node {3} (1);
    \end{scope}
  \end{tikzpicture}

      \vspace{.5cm}

We have $p_i = (6,0,-6)$. (Check $\sum_i p_i = 0$.)

Goal is to find $f_\ell$ for $\ell = 1,2,3$.

  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{Solving 3-node example: Kirchhoff's Current Law (KCL)}
  \begin{columns}

      \column[c]{.5\textwidth}

      \vspace{.2cm}

\begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw,fill=cyan}]%text=white}]
      \node (1) at (0,2.5) {1};
      \node (2) at (2.5,2.5) {2};
      \node (3) at (1.25,.3) {3};
    \end{scope}

    \begin{scope}[>={Stealth[black]},
        every node/.style={fill=white,circle},
        every edge/.style={draw=black,very thick}]
      \path [->] (1) edge node {1} (2);
      \path [->] (2) edge node {2} (3);
      \path [->] (3) edge node {3} (1);
    \end{scope}
  \end{tikzpicture}

      \vspace{.3cm}

      Kirchhoff's Current Law gives us:
  \begin{equation*}
    p_i = \sum_\ell K_{i\ell} f_\ell \hspace{2cm} \forall i
  \end{equation*}

  The incidence matrix $K$ is given by:
        \begin{equation*}
\mathbf{K}_{i \ell}=\left(\begin{matrix}
 1 & 0 & -1\\
 -1 & 1 & 0\\
 0 & -1 & 1
\end{matrix}\right)
\end{equation*}
      \column[c]{.5\textwidth}
        So we get:
        \begin{align*}
          p_1 & = 6 = f_1 - f_3 \\
          p_2 & = 0 = f_2 - f_1 \\
          p_3 & = -6 = f_3 - f_2
        \end{align*}
        Sum of KCL equations is always zero, so
        reduce to $N-1 = 2$ independent equations:
        \begin{align*}
          6 & = f_1 - f_3 \\
          0 & = f_2 - f_1
        \end{align*}
        Not enough information to solve!

        Need more information from KVL and reactances.

  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{Solving 3-node example: Kirchhoff's Voltage Law (KVL)}
  \begin{columns}

      \column[c]{.5\textwidth}

      \vspace{.2cm}

\begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw,fill=cyan}]%text=white}]
      \node (1) at (0,2.5) {1};
      \node (2) at (2.5,2.5) {2};
      \node (3) at (1.25,.3) {3};
    \end{scope}

    \begin{scope}[>={Stealth[black]},
        every node/.style={fill=white,circle},
        every edge/.style={draw=black,very thick}]
      \path [->] (1) edge node {1} (2);
      \path [->] (2) edge node {2} (3);
      \path [->] (3) edge node {3} (1);
    \end{scope}
  \end{tikzpicture}

      \vspace{.1cm}

      One formulation of Kirchhoff's Voltage Law gives us $L-N+1$ equations for cycles:
  \begin{equation*}
    \sum_\ell C_{\ell c} x_\ell f_\ell = 0 \hspace{2cm} \forall c
  \end{equation*}
  The cycle matrix $C$ is given by:
        \begin{equation*}
\mathbf{C}_{\ell c}=\left(\begin{matrix}
 1 \\
 1\\
 1
\end{matrix}\right)
\end{equation*}
      \column[c]{.5\textwidth}
        For equal reactances $x_\ell = x$ we get:
        \begin{align*}
          \sum_\ell C_{\ell 1} x_\ell f_\ell = x(f_1 + f_2 + f_3) = 0
        \end{align*}
        Together with KCL equations we now have 3 independent equations for 3 unknowns. Solve:
        \begin{align*}
          f_1 & = 2 \\
          f_2 & = 2 \\
          f_3 & = -4
        \end{align*}

  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{Solving 3-node example: Solution}

  \vspace{.3cm}

  \begin{columns}

      \column[c]{.5\textwidth}

  Solution:
  \vspace{.3cm}

    \centering
  %https://tex.stackexchange.com/questions/270543/draw-a-graph-in-latex-with-tikz
  \begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw,fill=yellow}]
      \node (1) at (0,3) {$+6$};
      \node (2) at (3,3) {$0$};
      \node (3) at (1.5,0) {$-6$};
    \end{scope}

    \begin{scope}[>={Stealth[black]},
        every node/.style={fill=white,circle},
        every edge/.style={draw=red,very thick}]
      \path [->] (1) edge node {$2$} (2);
      \path [->] (2) edge node {$2$} (3);
      \path [->] (3) edge node {$-4$} (1);
    \end{scope}
  \end{tikzpicture}

  \raggedright

      \column[c]{.5\textwidth}

      Along 2-edge path reactance is double the 1-edge path, so half as much power flows along the 2-edge path as the 1-edge path.

      \vspace{.5cm}
  NB: For directed graph, sign determines direction of flow.

  \end{columns}
\end{frame}

\section{Full power flow equations}

\begin{frame}
  \frametitle{Goal: Understand the physical origin of these equations}

  Last time we said we can (in the linear approximation) express the
  flow $f_\ell$ on each line in terms of the voltage angles $\theta_i$
  at the nodes for a line $\ell$ with
  reactance $x_\ell$ as
  \begin{equation*}
    f_\ell = \frac{\theta_i - \theta_j}{x_\ell} = \frac{1}{x_\ell}\sum_{i} K_{i\ell} \theta_i
  \end{equation*}
   This is a relative of Ohm's Law in DC circuits, $I = \frac{V_1 - V_2}{R}$.

  Now we explain the physics of where this comes from, and the linear approximation
  that leads to it.

  This is also useful when we consider the synchronisation of
  oscillators later.
\end{frame}

\begin{frame}
  \frametitle{Alternating Current}

  The majority of electrical power, including what you get out of a
  wall plug, is transmitted as \alert{Alternating Current (AC)},
  i.e. both the voltage and current are sinusoidal waves.

  \begin{center}
  \includegraphics[width=8cm]{738px-Types_of_current}
  \end{center}

  [Some power is transmitted as \alert{Direct Current (DC)} under bodies of water and
    indeed many electronic devices require DC (must convert AC to DC).]
  \source{Wikipedia}
\end{frame}

\begin{frame}
  \frametitle{Why alternating current?}

  Battle of currents! Edison versus Westinghouse/Tesla in late 1880s, early 1890s, etc.

  \url{https://en.wikipedia.org/wiki/War_of_Currents}

  AC won, because it's easy to transform AC to a higher voltage, so
  you can transmit a given power $P = VI$ with a lower current and thus avoid
  the $I^2R$ resistive losses in power lines.

  Reason: $\frac{d}{dt}$ in $\mathcal{E} = \frac{d\Phi}{dt}$; use a
  solenoid to induce a \alert{fluctuating} magnetic field in another
  solenoid with a different number of turns, giving different
  potential difference.

  Frequency of 50~Hz is uniform across Europe (except for
  train-electricity, e.g. in Germany 16.7~Hz). 60~Hz in USA, western half of
  Japan, etc.
\end{frame}

\begin{frame}[fragile]
  \frametitle{Frankfurt: Home of Long-Distance AC Transmission}

  First long-distance high-voltage alternating-current transmission in 1891 from hydroelectric
  plant in Lauffen to Frankfurt for the Elektrotechnische Ausstellung (176~km, 15~kV).

  \begin{columns}[T]
\begin{column}{3.5cm}
  \includegraphics[trim=0 0cm 0 0cm,width=3.7cm,clip=true]{IEAFrankfurt1891c.jpg}
\end{column}
\begin{column}{2.5cm}
  \includegraphics[trim=0 0cm 0 0cm,width=2.8cm,clip=true]{Drehstromuebertragung_Lauffen-Frankfurt.png}
\end{column}
\begin{column}{5cm}
  \vspace{1cm}
        \includegraphics[trim=0 0cm 0 0cm,width=5cm,clip=true]{Lauffen-Frankfurt1891-1991.jpg}
\end{column}
  \end{columns}

  \source{Wikipedia}

\end{frame}

\begin{frame}
  \frametitle{Sinuisoidal waves}

  The voltage is usually written in terms of the \alert{angular frequency} $\omega =
  2\pi f$ (radians per second) rather than frequency $f$ (Hertz) and the \alert{Root-Mean-Squared (RMS)} voltage magnitude $V_{\textrm{rms}}$
  \begin{equation*}
    V(t) = V_{\textrm{peak}} \sin(\omega t) = \sqrt{2} V_{\textrm{rms}} \sin(\omega t)
  \end{equation*}
  Similarly for the current we have
  \begin{equation*}
    I(t) = I_{\textrm{peak}} \sin(\omega t - \varphi) = \sqrt{2} I_{\textrm{rms}} \sin(\omega t - \varphi)
  \end{equation*}
  Note that they are not necessarily in phase, $\varphi \neq 0$.

  The RMS values are useful because then for the \alert{average power} with $\varphi = 0$ we can forget factors of 2
  \begin{equation*}
    \langle P(t) \rangle = \langle V(t)I(t) \rangle = 2 V_{\textrm{rms}} I_{\textrm{rms}} \langle\sin^2(\omega t)\rangle = V_{\textrm{rms}} I_{\textrm{rms}}
  \end{equation*}

\end{frame}

\begin{frame}
  \frametitle{Resistive loads}

  For purely \alert{resistive loads}, e.g. a kettle or an electric heater, we have
  \begin{equation*}
    V(t) = R I(t)
  \end{equation*}
  and thus for a voltage of $V(t) = \sqrt{2} V_{\textrm{rms}}
  e^{j\omega t}$ (NB: for engineers $j = \sqrt{-1}$ to avoid confusion
  with the current $i$) we have
  \begin{equation*}
    I(t) = \sqrt{2} \frac{V_{\textrm{rms}}}{R} e^{j\omega t} = \frac{1}{R} V(t)
  \end{equation*}
  or in terms of the RMS value and phase shift
  \begin{align*}
    I_{\textrm{rms}} & = \frac{1}{R} V_{\textrm{rms}} \\
    \varphi & = 0
  \end{align*}

\end{frame}

\begin{frame}
  \frametitle{Resistive loads}

  In terms of the waveforms, the current has no phase shift from the voltage.

  \centering
  \includegraphics[width=11cm]{vi-r.pdf}

\end{frame}

\begin{frame}
  \frametitle{Capacitive loads}

  For purely \alert{capacitive loads} we have
  \begin{equation*}
       I(t) = C  \frac{dV(t)}{dt}
  \end{equation*}
  and thus for a voltage of $V(t) = \sqrt{2} V_{\textrm{rms}}
  e^{j\omega t}$ we get
  \begin{equation*}
    I(t) = \sqrt{2} j\omega C V_{\textrm{rms}} e^{j\omega t} = j\omega C V(t)
  \end{equation*}
  or in terms of the RMS value and phase shift
  \begin{align*}
    I_{\textrm{rms}} & = \omega C V_{\textrm{rms}} \\
    \varphi & = -\frac{\pi}{2}
  \end{align*}
  We write $X_{C} = \frac{1}{\omega C}$ for the \alert{capacitive reactance}.

\end{frame}

\begin{frame}
  \frametitle{Capacitive loads}

  Current peaks before the voltage (it \alert{leads} the voltage),
  since first charge must accumulate on the plates; once the charge is
  on the plates, the current drops to zero and the voltage peaks.

  \begin{columns}
    \column[c]{.7\textwidth}
  \includegraphics[width=10cm]{vi-c.pdf}
    \column[c]{.3\textwidth}
  \includegraphics[width=4cm]{capacitor.png}
  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{Inductive loads}

  For purely \alert{inductive loads}, e.g. a motor during start-up
  \begin{equation*}
    V(t) = L \frac{d I(t)}{dt}
  \end{equation*}
  and thus for a voltage of $V(t) = \sqrt{2} V_{\textrm{rms}}
  e^{j\omega t}$ we get
  \begin{equation*}
    I(t) = \sqrt{2} \frac{V_{\textrm{rms}}}{j\omega L} e^{j\omega t} = \frac{1}{j\omega L}V(t)
  \end{equation*}
  or in terms of the RMS value and phase shift
  \begin{align*}
    I_{\textrm{rms}} & = \frac{1}{\omega L} V_{\textrm{rms}} \\
    \varphi & = \frac{\pi}{2}
  \end{align*}
  We write $X_{L} = \omega L$ for the \alert{inductive reactance}, in analogy to the resistance.

\end{frame}

\begin{frame}
  \frametitle{Inductive loads}

  Now current peaks after the voltage (it \alert{lags} the voltage),
  since the flow of current in the solenoid resists the changing voltage.

  \begin{columns}
    \column[c]{.7\textwidth}
  \includegraphics[width=10cm]{vi-l.pdf}
    \column[c]{.3\textwidth}
  \includegraphics[width=4cm]{600px-Solenoid_and_Ampere_Law_-_2.png}
  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{General loads}

  General loads will have a combination of resistive, capacitive and
  inductive parts. For an RLC circuit in series the voltage across the
  components is additive
  \begin{equation*}
    V(t) = R I(t) + L\frac{dI(t)}{dt} + \frac{1}{C} \int_{-infty}^t I(\tau) d\tau
  \end{equation*}
  and therefore for a sinuisoidal voltage with angular frequency $\omega$ we get
  \begin{equation*}
    V(t) = \left[ R + j\omega L + \frac{1}{j\omega C} \right] I(t)
  \end{equation*}
  which leads us to define a general complex notion of resistance called \alert{impedance}
  \begin{equation*}
    Z =  R + j\omega L + \frac{1}{j\omega C} = R + j(X_L - X_C) = R + jX
  \end{equation*}
  where $X$ is the reactance $X = X_L - X_C$.
\end{frame}

\begin{frame}
  \frametitle{Impedances and admittances}

  Thus for a regular sinuisodal setup we have
  \begin{equation*}
    V(t) = ZI(t)
  \end{equation*}
  where the complex \alert{impedance} takes care both of the relation
  of the RMS values of the current and the voltage, and their phase
  difference. We can decompose $Z$ into real resistance $R$ and real reactance $X$
  \begin{equation*}
    Z = R + jX
  \end{equation*}

  The inverse impedance, called the \alert{admittance} is given by
  \begin{equation*}
    Y = \frac{1}{Z}
  \end{equation*}
  so that
  \begin{equation*}
    I(t) = Y V(t)
  \end{equation*}
  We can also decompose this into real conductance $G$ and real susceptance $B$
  \begin{equation*}
    Y = G + jB
  \end{equation*}

\end{frame}

\begin{frame}
  \frametitle{Simple transmission line}

  A simple model for a transmission line $\ell$ between nodes $i$ and
  $j$ is a resistance $R$ in series with an (inductive) reactance $X$.

  [Typical values are for a 380~kV overhead transmission line e.g. $R = 0.03$~Ohm/km and $X = 0.3$~Ohm/km.]

  The voltage at each node (compared to ground) is given by $V_i(t) = \sqrt{2}
  V_ie^{j(\omega t + \theta_i)}$ where $\theta_i$ is the phase offset
  for each node and $V_i$ is the RMS voltage magnitude.

  Now the current in the transmission line is given by
  \begin{equation*}
    I(t) = \frac{1}{R + jX} \left[ V_j(t) - V_i(t) \right] =  \frac{1}{R + jX}\sqrt{2} V_i e^{j(\omega t + \theta_i)} \left[\frac{V_j}{V_i} e^{j(\theta_j - \theta_i)} - 1\right]
  \end{equation*}

\end{frame}

\begin{frame}
  \frametitle{Active versus reactive power}

  Now let's consider the power injection at the first node. This is
  simply the voltage there multiplied by the current in the
  transmission line.

  It's convenient to eliminate the time-dependent part $e^{j\omega t}$
  by multiplying the voltage with the complex conjugate of the current
  \begin{equation*}
    S = P + jQ = \frac{1}{2} V(t)I^*(t)
  \end{equation*}

  For a resistive load with $V(t) = R I(t)$ this reproduces the
  \alert{active power} $P$.

  For loads where the $I(t)$ is not in phase with the voltage, we get
  a flow of \alert{reactive power} $Q$.

  $S = P + j Q$ is called the \alert{apparent power}.

\end{frame}

\begin{frame}
  \frametitle{Linearisation: Assumption 1/3}

  Now if we consider the power injected at the first node we get
  \begin{equation*}
    P_i + jQ_i =  \frac{1}{R + jX} V_i^2\left[\frac{V_j}{V_i} e^{j(\theta_i - \theta_j)} - 1\right]
  \end{equation*}

  This is the full non-linear equation for the power flow. Now let's
  linearise by making some simplifying assumptions.

  1. Assume the voltage magnitudes are the same everywhere in the network $V_i = V_j$
  \begin{equation*}
    P_i + jQ_i =  \frac{1}{R + jX} V_i^2\left[e^{j(\theta_i - \theta_j)} - 1\right]
  \end{equation*}
  This means \alert{power flows primarily according to angle differences} in this approximation.

\end{frame}

\begin{frame}
  \frametitle{Linearisation: Assumption 2/3}

  2. Now assume that the voltage angle differences across the transmission line are small enough that $\sin(\theta_i - \theta_j) \sim (\theta_i - \theta_j)$
  \begin{align*}
    P_i + jQ_i & =  \frac{1}{R + jX} V_i^2\left[e^{j(\theta_i - \theta_j)} - 1\right] \\
    & \sim  \frac{1}{R + jX} V_i^2\left[j(\theta_i - \theta_j)\right]
  \end{align*}

  This assumption is usually valid, since for stability reasons, we usually have in the transmission network
  $(\theta_i - \theta_j) \leq \frac{\pi}{6}$ (30 degrees).
\end{frame}

\begin{frame}
  \frametitle{Linearisation: Assumption 3/3}

  3. Finally we assume $R << X$ so that we can ignore the resistance $R$
  \begin{align*}
    P_i + jQ_i
    & =  \frac{1}{R + jX} V_i^2\left[j(\theta_i - \theta_j)\right] \\
    & \sim  \frac{1}{jX} V_i^2\left[j(\theta_i - \theta_j)\right]\\
    & =  \frac{V_i^2}{X}(\theta_i - \theta_j)
  \end{align*}

  Note that ignoring $R$ means that we ignore resistive losses in the transmission lines and also since $Q_i \sim 0$, we ignore the flow of reactive power. Finally we absorb the voltage into the definition of the \alert{per unit} reactance $x_\ell = \frac{X}{V_i^2}$ to get
  \begin{equation*}
    f_\ell = P_i = -P_j = \frac{\theta_i - \theta_j}{x_\ell}
  \end{equation*}

\end{frame}

\begin{frame}
  \frametitle{Three-phase power}

  Electricity is generally generated simultaneously in
    3 separate circuits separate by 120 degrees or $\frac{2\pi}{3}$
  \begin{center}
  \includegraphics[width=7cm]{3_phase_AC_waveform}
  \end{center}

  In your plug, you only see one phase, but your oven may use all
  three phases.

  \source{Wikipedia}
\end{frame}

\begin{frame}
  \frametitle{Three-phase power}

  Why three phases? This was settled in the late 1880s.

  1. The total power delivery is constant
  \begin{equation*}
    \frac{d}{dt} P(t) =     \frac{d}{dt} \left[P_a(t) + P_b(t) + P_c(t) \right] = 0
  \end{equation*}
  This reduces mechanical stress on generators and motors.

  2. The sum of voltages and currents is zero, so no return path
  required! Saving on materials.

  Both facts follow from
  \begin{equation*}
    \sum_{k=0}^{N-1} e^{j\frac{2\pi k}{N}} = 0
  \end{equation*}
  for $N > 1$.

  3. Why $N=3$ rather than $N=2$? Allows directional rotating fields for induction motors (thanks Tesla!).
\end{frame}

\begin{frame}
  \frametitle{Roots of unity for $N=3$}

  For $N=3$, check they add up to zero:

  \centering
  \includegraphics[width=8cm]{f8UGvjRAqV-3rd-roots-of-unity.png}

  \source{\href{https://brilliant.org/wiki/roots-of-unity/}{brilliant.org}}
\end{frame}

\begin{frame}
  \frametitle{Rotating field in a three-phase induction motor}

  A brilliant insight (credited to Tesla, but the history is
  \href{https://en.wikipedia.org/wiki/Induction\_motor\#History}{complicated})
  was that with three-phase power, you can place your wires spaced at
  $2\pi/3$ to create a \alert{rotating} magnetic field

  \url{https://www.youtube.com/watch?v=LtJoJBUSe28}

  which can then induce a current in a rotor cage, which then
  experiences a torque thanks to the magnetic field: this is the
  principle of the \alert{induction motor}.

  It would not be possible to create such a rotating field with a
  single-phase or two-phase system.

\end{frame}

\begin{frame}
  \frametitle{Three-phase power}
  \begin{center}
  \includegraphics[width=9cm]{circuit}
  \end{center}

  \source{\href{https://en.wikipedia.org/wiki/Three-phase_electric_power}{Wikipedia}}

\end{frame}

\section{Computing the Linear Power Flow}

\begin{frame}
  \frametitle{The goal of power flow analysis}

  \begin{columns}
    \column[c]{.55\textwidth}

  The goal of a power/load flow analysis is to find the flows in the
  lines of a network given a power injection pattern at the nodes.

    I.e. given power injection at the nodes
\begin{equation*}
\mathbf{P}_{i}=\left(\begin{matrix}
50 \\
50 \\
0 \\
-100
\end{matrix}\right)
\end{equation*}
what are the flows in lines 1-4?

\vspace{.1cm}

To find the flows, it is sufficient to know the \alert{reactances} of
the lines $x_\ell$ and the \alert{voltages angles} $\theta_i$ at each node.

\column[c]{.45\textwidth}

\begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw,fill=cyan}]%text=white}]
      \node (4) at (0,2.5) {4};
      \node (2) at (2.5,2.5) {2};
      \node (3) at (1.25,.3) {3};
      \node (1) at (4.2,4.2) {1};
    \end{scope}

    \begin{scope}[>={Stealth[black]},
        every node/.style={fill=white,circle},
        every edge/.style={draw=black,very thick}]
      \path [->] (1) edge node {1} (2);
      \path [->] (2) edge node {2} (3);
      \path [->] (3) edge node {4} (4);
      \path [->] (2) edge node {3} (4);
    \end{scope}
  \end{tikzpicture}
\end{columns}

\end{frame}

\begin{frame}
  \frametitle{Framing the load flow problem}

  Suppose we have $N$ nodes labelled by $i$, and $L$ edges labelled by
  $\ell$ forming a directed graph $G$.

  Suppose at each node we have a \alert{power imbalance} $p_i$ ($p_i >
  0$ means its generating more than it consumes and $p_i < 0$ means it
  is consuming more than it).

  Since we cannot create or destroy energy (and we're ignoring losses):
  \begin{equation*}
    \sum_i p_i = 0
  \end{equation*}

  \alert{Question}: How do the flows $f_\ell$ in the network relate to the nodal power
  imbalances?

  \alert{Answer}: According to the reactances (generalisation of
  resistance for oscillating voltage/current) and the corresponding
  voltages.

\end{frame}

\begin{frame}
  \frametitle{Kirchhoff's Current Law (KCL)}

  KCL says (in this linear setting) that the nodal power imbalance at
  node $i$ is equal to the sum of direct flows arriving at the
  node. This can be expressed compactly with the incidence matrix

  \begin{equation*}
    p_i = \sum_\ell K_{i\ell} f_\ell \hspace{2cm} \forall i
  \end{equation*}

  Only $N-1$ of these equations are independent for a connected network, since $\sum_i K_{i\ell} = 0$.
\end{frame}

\begin{frame}
  \frametitle{Kirchhoff's Voltage Law (KVL)}

  KVL says that the sum of voltage differences across edges for any
  closed cycle must add up to zero.

  If the voltage angle at any node is given by $\theta_i$ then the voltage difference across edge $\ell$ is
  \begin{equation*}
    \sum_i K_{i\ell} \theta_i
  \end{equation*}

  And Kirchhoff's law can be expressed using the cycle matrix encoding of independent cycles
  \begin{equation*}
    \sum_\ell C_{\ell c} \sum_i K_{i\ell} \theta_i = 0 \hspace{2cm} \forall c
  \end{equation*}

  [Automatic, since we already said KC = 0.]

\end{frame}

\begin{frame}
  \frametitle{Kirchhoff's Voltage Law (KVL)}

  Physics gives us the expression of the flow $f_\ell$ on each line $\ell$ with reactance $x_\ell$ in terms of the voltage angles at the nodes $\theta_i$  (a
  relative of $V = IR$)
  \begin{equation}
    f_\ell = \frac{\theta_i - \theta_j}{x_\ell} = \frac{1}{x_\ell}\sum_{i} K_{i\ell} \theta_i \label{eq:1}
  \end{equation}
      [NB: This restricts the $L$ variables $f_\ell$ to depend only on the $N$ voltage angles $\theta_i$. Since the flow doesn't change under a constant shift $\theta_i \to \theta_i + c$, we can choose   a \alert{slack} or \alert{reference node} such that  $\theta_1 = 0$, so there are only $N-1$ independent variables.]

      \vspace{.5cm}

  KVL now becomes $L-N+1$ binding constraints on the line flows $f_\ell$
  \begin{equation}
    \sum_\ell C_{\ell c} x_\ell f_\ell = 0 \hspace{2cm} \forall c  \label{eq:2}
  \end{equation}
  [NB: Equations \eqref{eq:1} and  \eqref{eq:2} are equivalent and both restrict our $L$ variables $f_\ell$ to an $N-1$ dimensional subspace.]

\end{frame}

\begin{frame}
  \frametitle{Solving the equations via the line flows}

  Now we have $N-1$ equations for the flows $f_\ell$ from KCL:
  \begin{equation*}
    p_i = \sum_\ell K_{i\ell} f_\ell \hspace{2cm}\forall i \in \{ 1, \dots N-1 \}
  \end{equation*}
  and $L-N+1$ equations from KVL:
  \begin{equation*}
    \sum_\ell C_{\ell c} x_\ell f_\ell = 0 \hspace{2cm}\forall c \in \{ 1, \dots L-N+1 \}
  \end{equation*}

  So $L$ independent linear equations for $L$ variables $f_\ell$.

  Can solve with e.g. LU decomposition using specialised sparse solvers, with polynomial complexity in $L$. (For dense matrices complexity $O(L^a)$ where $2 < a < 3$.)

  This formulation is useful for the optimisation later, but we can solve a smaller dimensional linear system with $N-1$ variables using the voltage angles.
\end{frame}

\begin{frame}
  \frametitle{Solving the equations via the voltage angles}

  If we combine
    \begin{equation}
    f_\ell  = \frac{1}{x_\ell}\sum_{i} K_{i\ell} \theta_i \label{eq:3}
  \end{equation}
    with Kirchhoff's Current Law we get
    \begin{equation*}
    p_i = \sum_{\ell} K_{i\ell}f_\ell =   \sum_{\ell} K_{i\ell} \frac{1}{x_\ell}\sum_{j} K_{j\ell} \theta_j
    \end{equation*}
    This is a \alert{weighted Laplacian}. If we write $B_{k\ell}$ for the diagonal matrix with $B_{\ell\ell} = \frac{1}{x_\ell}$ then
    \begin{equation*}
      L = KBK^t
    \end{equation*}
    and we get a \alert{discrete Poisson equation} for the $\theta_i$ sourced by the $p_i$
    \begin{equation*}
      p_i = \sum_{j} L_{ij} \theta_j
    \end{equation*}
    This is a set of $N-1$ sparse linear equations for the $\theta_j$ ($N-1$ since $\sum_i L_{ij} = 0$).
    We can solve this for the $\theta_i$ and then find the flows using equation \eqref{eq:3}. Polynomial complexity in $N$.

\end{frame}

\begin{frame}
  \frametitle{Solving the equations via the PTDF}

  If we are repeating the calculation for a fixed network multiple times with different power injections, it can make sense to do the full matrix inversion.

  Given $p_i$ at every node, we want to find the flows $f_\ell$. We
  have the equations
    \begin{align*}
      p_i & = \sum_{j} L_{ij} \theta_j \\
     f_\ell  & = \frac{1}{x_\ell}\sum_{i} K_{i\ell} \theta_i
    \end{align*}

    Basic idea: invert $L$ to get $\theta_i$ in terms of $p_i$
    \begin{equation*}
      \theta_i  = \sum_{k} (L^{-1})_{ik} p_k
    \end{equation*}
    then insert to get the flows as a linear function of the power injections $p_i$
    \begin{equation*}
    f_\ell   = \frac{1}{x_\ell}\sum_{i,k} K_{i\ell}  (L^{-1})_{ik} p_k = \sum_k \textrm{PTDF}_{\ell k} p_k
    \end{equation*}
    called the \alert{Power Transfer Distribution Factors} (PTDF).

\end{frame}

\begin{frame}
  \frametitle{Inverting Laplacian $L$}

  There is one small catch: $L$ is \alert{not invertible} since we saw last
  time it has (for a connected network) one zero eigenvalue, with
  eigenvector $(1,1, \dots 1)$, since by construction $\sum_j L_{ij} =
  0$.

  This is related to a gauge freedom to add a constant to all voltage angles
  \begin{equation*}
    \theta_i \to \theta_i + c
  \end{equation*}
  which does not affect physical quantities:
    \begin{align*}
      p_i & = \sum_{j} L_{ij} (\theta_j+ c) = \sum_{j} L_{ij} (\theta_j)  \\
     f_\ell  & = \frac{1}{x_\ell}\sum_{i} K_{i\ell}( \theta_i  + c) = \frac{1}{x_\ell}\sum_{i} K_{i\ell}( \theta_i )
    \end{align*}

    Typically choose a \alert{slack} or \alert{reference node} such that  $\theta_1 = 0$.

\end{frame}

\begin{frame}
  \frametitle{Inverting Laplacian $L$}

  Two solutions:

  1. Since $\theta_1 = 0$ and $p_1$ is not independent of the other
  power injections ($\sum_{i=1}^N p_i = 0$ implies $p_1 = -
  \sum_{i=2}^N p_i$), we can ignore these elements and invert
  the lower-right $(N-1) \times (N-1)$ part of $L$ (which doesn't have zero eigenvalues) to find the
  remaining $\{\theta_i\}_{i=2,\dots N}$ in terms of the
  $\{p_i\}_{i=2,\dots N}$.

  2. Use the Moore-Penrose pseudo-inverse.

  Write $L$ in terms of its basis of orthonormal eigenvectors $e^n_i$ ($\sum_j L_{ij} e^n_j = \l_n e^n_i$, $\sum_i e^n_i e^n_i = 1$ and  $\sum_i e^n_i e^m_i = 0$ if $n \neq m$):
  \begin{equation*}
    L_{ij} = \sum_n \l_n e^n_i e^n_j
  \end{equation*}
  then the Moore-Penrose pseudo-inverse is:
  \begin{equation*}
    L^\dagger_{ij} = \sum_{n | \l_n \neq 0} \frac{1}{\l_n} e^n_i e^n_j
  \end{equation*}

\end{frame}

\begin{frame}
  \frametitle{Check the Moore-Penrose pseudo-inverse}

  Let's check the Moore-Penrose pseudo-inverse really gives us an inverse:
  \begin{align*}
    \sum_{j} L_{ij}L^\dagger_{jk} &= \sum_j \sum_n \l_n e^n_i e^n_j  \sum_{m | \l_m \neq 0} \frac{1}{\l_m} e^m_j e^m_k \\
&= \sum_n \l_n e^n_i  \sum_{m | \l_m \neq 0} \frac{1}{\l_m} e^m_k \sum_j   e^n_j e^m_j \\
    & =   \sum_{m | \l_m \neq 0} \frac{\l_m}{\l_m} e^m_i e^m_k\\
    & =   \sum_{m | \l_m \neq 0}  e^m_i e^m_k
  \end{align*}
  From line 2 to 3 we use the orthogonality of the eigenvectors.

  This is almost the identity. It has eigenvalues 1 for each eigenvector $e^n_k$ except for zero eigenvectors of $L$ with $\l_n = 0$, which it annihilates.

\end{frame}

\begin{frame}
  \frametitle{4-node example}

  \begin{columns}
\column[c]{.5\textwidth}
\begin{equation*}
\mathbf{K}_{i \ell}=\left(\begin{matrix}
1 & 0 & 0 & 0\\
-1 & 1 & 1 & 0\\
0 & -1 & 0 & 1\\
0 & 0 & -1 & -1
\end{matrix}\right)
\end{equation*}
\begin{equation*}
\mathbf{L}_{ij}=\left(\begin{matrix}
1 & -1 & 0 & 0\\
-1 & 3 & -1 & -1\\
0 & -1 & 2 & -1\\
0 & -1 & -1 & 2
\end{matrix}\right)
\end{equation*}
\begin{equation*}
\mathbf{PTDF}_{\ell i}=\left(\begin{matrix}
0 & -1 & -1 & -1\\
0 & 0 & -2/3 & -1/3\\
0 & 0 & -1/3 & -2/3\\
0 & 0 & 1/3 & -1/3
\end{matrix}\right)
\end{equation*}

\column[c]{.5\textwidth}

\begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw,fill=cyan}]%text=white}]
      \node (4) at (0,2.5) {4};
      \node (2) at (2.5,2.5) {2};
      \node (3) at (1.25,.3) {3};
      \node (1) at (4.2,4.2) {1};
    \end{scope}

    \begin{scope}[>={Stealth[black]},
        every node/.style={fill=white,circle},
        every edge/.style={draw=black,very thick}]
      \path [->] (1) edge node {1} (2);
      \path [->] (2) edge node {2} (3);
      \path [->] (3) edge node {4} (4);
      \path [->] (2) edge node {3} (4);
    \end{scope}
  \end{tikzpicture}
\end{columns}

\end{frame}

\begin{frame}
  \frametitle{4-node example}

  \begin{columns}
\column[c]{.65\textwidth}
\begin{align*}
\sum_i \mathbf{PTDF}_{\ell i}p_i & =\left(\begin{matrix}
0 & -1 & -1 & -1\\
0 & 0 & -2/3 & -1/3\\
0 & 0 & -1/3 & -2/3\\
0 & 0 & 1/3 & -1/3
\end{matrix}\right)\left(\begin{matrix}
50\\
50 \\
0\\
-100
\end{matrix}\right) \\
& =\left(\begin{matrix}
50\\
33.3 \\
66.7 \\
33.3
\end{matrix}\right)
\end{align*}

\column[c]{.35\textwidth}

\begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw,fill=yellow}]
      \node (4) at (0,2.5) {-100};
      \node (2) at (2.5,2.5) {+50};
      \node (3) at (1.25,.3) {0};
      \node (1) at (4.2,4.2) {+50};
    \end{scope}

    \begin{scope}[>={Stealth[black]},
                every node/.style={fill=white,circle},
        every edge/.style={draw=red,very thick}]
      \path [->] (1) edge node {50} (2);
      \path [->] (2) edge node {33.3} (3);
      \path [->] (3) edge node {33.3} (4);
      \path [->] (2) edge node {66.7} (4);
    \end{scope}
  \end{tikzpicture}
\end{columns}

\end{frame}

\begin{frame}
  \frametitle{PTDF as sensitivity}

  Can also `experimentally' determine the Power Transfer Distribution
  Factors (PTDF) by choosing a slack node (in this case node 1).

  Each column (labelled by $i$) is then the resulting line flows if we have
  a simple power transfer from node $i$ to the slack $p_i = 1$ and $p_1
  = -1$.

  \begin{columns}
\column[c]{.5\textwidth}
\begin{equation*}
\mathbf{PTDF}_{\ell i}=\left(\begin{matrix}
0 & -1 & -1 & -1\\
0 & 0 & -2/3 & -1/3\\
0 & 0 & -1/3 & -2/3\\
0 & 0 & 1/3 & -1/3
\end{matrix}\right)
\end{equation*}

\column[c]{.5\textwidth}
\begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw,fill=cyan}]%text=white}]
      \node (4) at (0,2.5) {4};
      \node (2) at (2.5,2.5) {2};
      \node (3) at (1.25,.3) {3};
      \node (1) at (4.2,4.2) {1};
    \end{scope}

    \begin{scope}[>={Stealth[black]},
        every node/.style={fill=white,circle},
        every edge/.style={draw=black,very thick}]
      \path [->] (1) edge node {1} (2);
      \path [->] (2) edge node {2} (3);
      \path [->] (3) edge node {4} (4);
      \path [->] (2) edge node {3} (4);
    \end{scope}
  \end{tikzpicture}

\end{columns}

\end{frame}

\begin{frame}
  \frametitle{PTDF as sensitivity: example of 3rd column for node 3}
  \begin{columns}
    \column[c]{.5\textwidth}
    Focus on 3rd column of PTDF and look at power flow with $p_3 = +1$ and slack $p_1 = -1$. Coefficients determined by resulting flow:
\begin{equation*}
\mathbf{PTDF}_{\ell 3}=\left(\begin{matrix}
 &  & -1 &\\
 &  & -2/3 & \\
 &  & -1/3 & \\
 &  & 1/3 &
\end{matrix}\right)
\end{equation*}

\column[c]{.5\textwidth}

\begin{tikzpicture}
    \begin{scope}[every node/.style={circle,thick,draw,fill=yellow}]
      \node (4) at (0,2.5) {0};
      \node (2) at (2.5,2.5) {0};
      \node (3) at (1.25,.3) {+1};
      \node (1) at (4.2,4.2) {-1};
    \end{scope}

    \begin{scope}[>={Stealth[black]},
                every node/.style={fill=white,circle},
        every edge/.style={draw=red,very thick}]
      \path [->] (1) edge node {-1} (2);
      \path [->] (2) edge node {-2/3} (3);
      \path [->] (3) edge node {1/3} (4);
      \path [->] (2) edge node {-1/3} (4);
    \end{scope}
  \end{tikzpicture}
\end{columns}

\end{frame}

\section{Consequences of limiting power transfers}

\begin{frame}
  \frametitle{Line loading limits}

  You cannot pass infinite current through a transmission line.

  As it warms, it sags, then it will become damaged and/or hit a
  building/tree and cause a short-circuit. For this reasons there are
  always \alert{thermal limits} on current transfer. There may also be
  limits on the amount of power or current based on concerns about
  \alert{voltage stability} or \alert{general stability}.

  Typically each line has a well-defined \alert{line loading limit} on the
  amount of current or power that can flow through it:
  \begin{equation*}
    | f_{\ell } | \leq F_\ell
  \end{equation*}
  where here $F_\ell$ is the maximum power capacity of the transmission line.

  These limits prevent the transfer of renewable energy or other power sources.

\end{frame}

\begin{frame}
  \frametitle{Adjusting generator dispatch to avoid overloading}

  To avoid overloading the power lines, we must adjust our generator
  output (or the demand) so that the power imbalances do not overload
  the network.

  We will now generalise and adjust our notation.

  From lecture 3 we had for a single node:
  \begin{equation*}
    - p_t = m_t -b_t + c_t = d_t - Ww_t - Ss_t -b_t + c_t = 0
  \end{equation*}
  where $p_t$ was the nodal power balance, $m_t$ was the mismatch
  (load $d_t$ minus wind $Ww_t$ and solar $Ss_t$), $b_t$ was the
  backup power and $c_t$ was curtailment.

  We generalised this to multiple nodes labelled by $i$
  \begin{equation*}
    - p_{i,t} = m_{i,t} -b_{i,t} + c_{i,t} = d_{i,t} - W_iw_{i,t} - S_is_{i,t} -b_{i,t} + c_{i,t}
  \end{equation*}
  where now we don't enforce $p_{i,t} = 0$ but $\sum_{i} p_{i,t} = 0$ for
  all $t$.

\end{frame}

\begin{frame}
  \frametitle{Adjusting generator dispatch to avoid overloading} Now
  we write the dispatch of all generators at node $i$ (wind, solar,
  backup) labelled by technology $s$ as $g_{i,s,t}$ ($i$ labels node, $s$ technology and $t$ time) so that we have a relation between load $d_{i,t}$, generation $g_{i,s,t}$ and network flows $f_{\ell,t}$
  \begin{equation*}
    p_{i,t} = \sum_{s} g_{i,s,t} - d_{i,t} = \sum_{\ell} K_{i\ell} f_{\ell,t}
  \end{equation*}
  Where $s$ runs over the wind, solar and backup capacity generators
  (e.g. hydro or natural gas) at the node.

  A dispatchable generator's $g_{i,s,t}$ output can be controlled
  within the limits of its power capacity $G_{i,s}$
  \begin{equation*}
      0 \leq g_{i,s,t} \leq  G_{i,s}
  \end{equation*}
\end{frame}

\begin{frame}
  \frametitle{Variable generation constraints}

  For a renewable generator we have time series of availability $0\leq G_{i,s,t}\leq 1$ (the $s_t$ and $w_t$ before; $W$ and $S$ are the capacity $G_{i,s}$):
    \begin{equation*}
      0 \leq g_{i,s,t} \leq G_{i,s,t} G_{i,s} \leq  G_{i,s}
    \end{equation*}
    Curtailment corresponds to the case where $g_{i,s,t} < G_{i,s,t} G_{i,s}$:

     \centering
  \begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=10cm]{scigrid-curtailment}};
\draw (3,2.75) node{$g_{i,s,t}$};
\draw (3,3.4) node{$G_{i,s,t}G_{i,s}$};
\draw (3,4.7) node{$G_{i,s}$};
  \end{tikzpicture}

\end{frame}

\begin{frame}
  \frametitle{Germany curtailment example}

  See \url{https://pypsa.org/examples/scigrid-lopf-then-pf.html}.

\end{frame}

\begin{frame}
  \frametitle{European transmission versus backup energy}

  Consider backup energy in a simplified European grid:

  \centering
  \includegraphics[trim=0 4cm 0 4cm,width=9cm,clip=true]{europe_map}

\end{frame}

\begin{frame}
  \frametitle{DE versus EU backup energy from last time}

  Germany needed backup generation for 31\% of total load:

  \centering
  \includegraphics[width=6.3cm]{mismatch-duration-DE}

  \raggedright
  Europe needed Backup generation for only 24\% of the total load:

  \centering
  \includegraphics[width=6.3cm]{mismatch-duration-EU}

\end{frame}

\begin{frame}
  \frametitle{European transmission versus backup energy}

  \href{http://www.sciencedirect.com/science/article/pii/S0960148113005351}{Transmission needs across a fully renewable European power system} by Rodriguez, Becker, Andresen, Heide, Greiner, Renewable Energy, 2014

  \centering
  \includegraphics[width=6cm]{sarah_balancing.png}

\end{frame}

\end{document}


\chapter{Introduction to Time Series Analysis}
A {\sl time series} is a collection of observations made
sequentially in time. Examples are daily mortality counts,
particulate air pollution measurements, and temperature data.
Figure 1 shows these for the city of Chicago from 1987 to 1994.
The public health question is whether daily mortality is
associated with particle levels, controlling for temperature.

\centerline{\epsfig{figure=Plots/plot-10-01.ps,angle=270,width=\textwidth}}

We represent time series measurements with $Y_1, \dots, Y_T$
where $T$ is the total number of measurements. In order to analyze
a time series, it is useful to set down a statistical model in the
form of a {\sl stochastic process}. A stochastic process can be
described as a statistical phenomenon
that evolves in time. While most statistical problems are
concerned with estimating properties of a population from a
sample, in time series analysis there is a different situation.
Although it might be possible to vary the length of the observed
sample, it is usually impossible to make multiple observations at
any single time (for example, one can't observe today's mortality
count more than once). This makes the conventional statistical
procedures, based on large sample estimates, inappropriate.
Stationarity is a convenient assumption that permits us to
describe the statistical properties of a time series.

\input{section-10-01}
\input{section-10-02}


\documentclass{memoir}
\usepackage{notestemplate}

%\logo{~/School-Work/Auxiliary-Files/resources/png/logo.png}
%\institute{Rice University}
%\faculty{Faculty of Whatever Sciences}
%\department{Department of Mathematics}
%\title{Class Notes}
%\subtitle{Based on MATH xxx}
%\author{\textit{Author}\\Gabriel \textsc{Gress}}
%\supervisor{Linus \textsc{Torvalds}}
%\context{Well, I was bored...}
%\date{\today}

\begin{document}

% \maketitle

% Notes taken on 05-10-21

\section{Techniques in Characteristic p > 0}
\label{sec:techniques_in_characteristic_p_0}

\begin{prop}
	Let \(F\) be a field of characteristic \(p>0\). Then for all \(a,b \in F\), we get that
	\begin{align*}
		(a+b)^{p} = a^{p} + b^{p}\\
		(ab)^{p} = a^{p}b^{p}
	\end{align*}
\end{prop}
This is the "Freshman's Dream".

\begin{defn}[Frobenius Endomorphism]
	For a field \(F\) of characteristic \(p>0\), the function
	\begin{align*}
		\varphi :F\to F\\
		a\mapsto a^{p}
	\end{align*}
	is the \textbf{Frobenius endomorphism} of \(F\).
\end{defn}
\begin{cor}
	The Frobenius endomorphism of \(F\) is an injective field homomorphism. When \(F\) is finite, it is also surjective.
\end{cor}

Now we will go back to some propositions about finite fields using these ideas.
\begin{prop}
	Every irreducible polynomial over a finite field \(F\) is separable. Moreover, \(f(x) \in F[x]\) is separable if and only if it is the product of distinct irreducible polynomials in \(F[x]\).
\end{prop}
This follows by contradiction. One can express the irreducible polynomial as a polynomial of the form \(g(x^{p})\), but this polynomial can be shown to be reducible, and so cannot occur.

\begin{defn}[Perfect]
	A field \(K\) of characteristic \(p>0\) is called \textbf{perfect} if every element of \(K\) is a \(p\)-th power in \(K\)-- that is, \(K = K^{p}\).
\end{defn}
By convention any field of characteristic zero is also called perfect.\\

We have just shown that every irreducible polynomial over a perfect field is separable, and hence finite extensions of perfect fields are separable.

\begin{hw}
	Prove that there exists a non-perfect infinite field \(F\), i.e. find \(f(x) \in F[x]\) so that \(f\) is irreducible and not separable.
\end{hw}

These concepts can be used to prove that the \(n\)-th cyclotomic polynomial \(\Phi_n(x) \in \Z[x]\) is irreducible.

\end{document}

Abstract Algebra - Introductory/Algebra II/Notes/source/Lecture23 - Polynomial_Fields_Over_Fp.tex


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

\begin{document}

This code verifies that successive $\ny{n}^{a}$ introduce a new leading power of $\eps$ while leaving the lower
order terms unchanged. That is
\begin{align}
   \ny{n+1}^a - \ny{n}^a = \BigO{\eps^{n+1}}
\end{align}

\clearpage

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

   \nabla{#}::Derivative.

   g_{a b}::Metric.
   g^{a b}::InverseMetric.
   g_{a}^{b}::KroneckerDelta.
   g^{a}_{b}::KroneckerDelta.
   \delta^{a}_{b}::KroneckerDelta.
   \delta_{a}^{b}::KroneckerDelta.

   R_{a b c d}::RiemannTensor.
   R^{a}_{b c d}::RiemannTensor.

   R_{a b c d}::Depends(\nabla{#}).
   R^{a}_{b c d}::Depends(\nabla{#}).

   # Dx{#}::LaTeXForm{"{\Dx}"}.  # LCB: currently causes a bug, it kills ::KeepWeight for Dx

\end{cadabra}

\clearpage

\begin{cadabra}
   # note: keeping numbering as is (out of order) to ensure R appears before \nabla R etc.
   def product_sort (obj):
       substitute (obj,$ A^{a}                            -> A001^{a}               $)
       substitute (obj,$ x^{a}                            -> A002^{a}               $)
       substitute (obj,$ g^{a b}                          -> A003^{a b}             $)
       substitute (obj,$ \nabla_{e f g h}{R_{a b c d}}    -> A008_{a b c d e f g h} $)
       substitute (obj,$ \nabla_{e f g}{R_{a b c d}}      -> A007_{a b c d e f g}   $)
       substitute (obj,$ \nabla_{e f}{R_{a b c d}}        -> A006_{a b c d e f}     $)
       substitute (obj,$ \nabla_{e}{R_{a b c d}}          -> A005_{a b c d e}       $)
       substitute (obj,$ R_{a b c d}                      -> A004_{a b c d}         $)
       sort_product   (obj)
       rename_dummies (obj)
       substitute (obj,$ A001^{a}                  -> A^{a}                         $)
       substitute (obj,$ A002^{a}                  -> x^{a}                         $)
       substitute (obj,$ A003^{a b}                -> g^{a b}                       $)
       substitute (obj,$ A004_{a b c d}            -> R_{a b c d}                   $)
       substitute (obj,$ A005_{a b c d e}          -> \nabla_{e}{R_{a b c d}}       $)
       substitute (obj,$ A006_{a b c d e f}        -> \nabla_{e f}{R_{a b c d}}     $)
       substitute (obj,$ A007_{a b c d e f g}      -> \nabla_{e f g}{R_{a b c d}}   $)
       substitute (obj,$ A008_{a b c d e f g h}    -> \nabla_{e f g h}{R_{a b c d}} $)

       return obj

   # now check that y(n+1) - y(n) = Order \eps^{n+1}

   import cdblib

   y2 = cdblib.get ('y2','../geodesic-bvp.json')
   y3 = cdblib.get ('y3','../geodesic-bvp.json')
   y4 = cdblib.get ('y4','../geodesic-bvp.json')
   y5 = cdblib.get ('y5','../geodesic-bvp.json')

   diff32 := @(y3) - @(y2).
   diff43 := @(y4) - @(y3).
   diff54 := @(y5) - @(y4).

   diff32 = product_sort (diff32)
   rename_dummies        (diff32)
   canonicalise          (diff32)         # cdb (diff32.001,diff32)

   diff43 = product_sort (diff43)
   rename_dummies        (diff43)
   canonicalise          (diff43)         # cdb (diff43.001,diff43)

   diff54 = product_sort (diff54)
   rename_dummies        (diff54)
   canonicalise          (diff54)         # cdb (diff54.001,diff54)

   def truncateR (obj,n):

   # I would like to assign different weights to \nabla_{a}, \nabla_{a b}, \nabla_{a b c} etc. but no matter
   # what I do it appears that Cadabra assigns the same weight to all of these regardless of the number of subscripts.
   # It seems that the weight is assigned to the symbol \nabla alone. So I'm forced to use the following substitution trick.

       Q_{a b c d}::Weight(label=numR,value=2).
       Q_{a b c d e}::Weight(label=numR,value=3).
       Q_{a b c d e f}::Weight(label=numR,value=4).
       Q_{a b c d e f g}::Weight(label=numR,value=5).

       tmp := @(obj).

       substitute (tmp, $\nabla_{e f g}{R_{a b c d}} -> Q_{a b c d e f g}$)
       substitute (tmp, $\nabla_{e f}{R_{a b c d}} -> Q_{a b c d e f}$)
       substitute (tmp, $\nabla_{e}{R_{a b c d}} -> Q_{a b c d e}$)
       substitute (tmp, $R_{a b c d} -> Q_{a b c d}$)

       ans = Ex(0)

       for i in range (0,n+1):
          foo := @(tmp).
          bah = Ex("numR = " + str(i))
          keep_weight (foo, bah)
          ans = ans + foo

       substitute (ans, $Q_{a b c d e f g} -> \nabla_{e f g}{R_{a b c d}}$)
       substitute (ans, $Q_{a b c d e f} -> \nabla_{e f}{R_{a b c d}}$)
       substitute (ans, $Q_{a b c d e} -> \nabla_{e}{R_{a b c d}}$)
       substitute (ans, $Q_{a b c d} -> R_{a b c d}$)

       return ans

   diff32 = truncateR (diff32,2)        # cdb (diff32.002,diff32)
   diff43 = truncateR (diff43,3)        # cdb (diff43.002,diff43)
   diff54 = truncateR (diff54,4)        # cdb (diff54.002,diff54)

\end{cadabra}

\clearpage

% =================================================================================================
\section*{Verify order of $\ny{n}^{a}$}

If things have gone to plan then we should see that $\ny{n+1}^a - \ny{n}^a = \BigO{\eps^{n+1}}$. And we do. Good show.

\begin{dgroup*}
   \begin{dmath*} \ny{3}^{a} - \ny{2}^{a} = \cdb{diff32.001} \end{dmath*}
   \begin{dmath*} \ny{4}^{a} - \ny{3}^{a} = \cdb{diff43.001} \end{dmath*}
   % \begin{dmath*} \ny{5}^{a} - \ny{4}^{a} = \cdb{diff54.001} \end{dmath*}  % too long
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \nT{2}\left(\ny{3}^{a} - \ny{2}^{a}\right) = \cdb{diff32.002} \end{dmath*}
   \begin{dmath*} \nT{3}\left(\ny{4}^{a} - \ny{3}^{a}\right) = \cdb{diff43.002} \end{dmath*}
   \begin{dmath*} \nT{4}\left(\ny{5}^{a} - \ny{4}^{a}\right) = \cdb{diff54.002} \end{dmath*}
\end{dgroup*}

\end{document}


\section{BL test case I}

In this section test case 1 is solved (1D incompressible
BL equations with gas injection along a bore hole).
The gas is injected at a velocity of $u_g \phi =1$ and
a saturation of one $S_g=1$. On the outlet boundary the
pressure level is set to zero. All boundary conditions are
applied naturally.

A converged time step of $1\times 10^{-3}$ is used for all simulations
and applications with the continuous and discontinuous between
element formulations are presented. All simulations
use the overlapping mixed finite element method with a
piecewise linear variation of the velocity within each
element and quadatric pressure. Saturation is collocated at
the pressure nodes. Although saturation is cacluated using
a control volume formulation a FEM interpolation is
used to form the high order fluxes and these are also
used in this section for most of the graphs.

\subsubsection{Continuous formulation}

{\it Upwind solution}

In figure \ref{bl-exact-meth-upwind}  the
control volume (CV) saturation of gas (with horizontal and vertical lines) and
the quadratic finite element interpolation of these are
presented.
As can be seen the solution converges with increased resolution.
Notice that the corners of the control volumes pass
very closely
to the converged solution. This is because upwinding of
the velocities is used (or equivalently the relative permeabilities)
and it is at these corners that the equations reach the
balance necessary to match closely the analytical solution.

{\it Optimal upwinding}

If one uses 80$\%$ upwinding and 20$\%$ downwinding then
one gets a closer match with the converged solution,
see figure \ref{bl-exact-meth-cv-0-8-ele50} where we see the
control volume solution and figure \ref{bl-optimal-upwind}
and where these solutions with upwinding as well as
the optimal quantity of upwinding (as described in section \ref{opt-up})
are compared.
One should note that 80$\%$ upwinding matches quite closely with the
optimal upwind parameter results and these results converge rapidly
with increase resolution. When applying optimal upwinding
the quantity of upwinding (upwind fraction) varies from
1 (full upwinding) which is typically applied near shocks
and $\frac{1}{2}$ which is central differencing. See
the upwind fractions in figure \ref{bl-upwind-frac} for the
different grid resolutions and each of the two phases.
The upwind fraction is chosen so as to increase the accuracy
of the formulation. However, even though downwinding of the
velocity may increase this accuracy we limit ourselves to
central difference. If however, one chooses to use
upwinding and downwinding then one obtains the solution
shown in figure \ref{bl-upwind-v-up-and-down}. Including
the downwind components may not be consistent with the characteristics
of the differential equation and thus may detract from
its accurate solution. The optimal solution for a number
of different resolutions ranging from 3 elements to 50 elements
is shown in figure \ref{bl-3-10-20-50}. Notice that
the solution converges rapidly. There are no oscillations in
the corresponding control volume solutions, but here we are
looking at the finite element interpolation (using a Galerkin
project) of the control volume solution which does oscillate
near the shock.

% cty:

%fig1: bl-exact-meth-upwind.xmgr

%fig2: bl-exact-meth-cv-0-8-ele50.xmgr

%fig3: bl-optimal-upwind.xmgr

%fig4: bl-upwind-frac.xmgr

%fig5: bl-upwind-v-up-and-down.xmgr

%fig6: bl-3-10-20-50.xmgr

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-exact-meth-upwind}
\end{center}
\vspace{0.cm}}
\caption{The continuous upwind method applied to the BL test
case 1 for different mesh resolutions.}
\label{bl-exact-meth-upwind}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-exact-meth-cv-0-8-ele50}
\end{center}
\vspace{0.cm}}
\caption{Comparison of the control volume solutions using 80$\%$ upwinding
and with optimal upwinding and using 50 continuous quadatric elements. }
\label{bl-exact-meth-cv-0-8-ele50}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-optimal-upwind}
\end{center}
\vspace{0.cm}}
\caption{Comparison of upwind, 80$\%$ upwind and optimal upwind solutions
at various resolutions.  }
\label{bl-optimal-upwind}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-upwind-v-up-and-down}
\end{center}
\vspace{0.cm}}
\caption{A comparison of the optimal upwind formulation when using
downwind as well as upwinding and upwinding only. The finite element interpolation
of the gas saturation is shown at different mesh resolutions.
Downwinding seems to detract from the accuracy of the solution. }
\label{bl-upwind-v-up-and-down}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-upwind-frac}
\end{center}
\vspace{0.cm}}
\caption{The fraction of upwinding used in the optimal upwinding approach at the control volume boundaries at the final time step and for three different mesh resolutions. Notice that the upwind fraction is at its largest near the shocks and is relatively small
where the solution is smooth. The magnitude of the upwind fraction also reduces
with increased mesh resolution. Also shown is the finite element interpolation
of the gas saturation at the 3 mesh resolutions.  }
\label{bl-upwind-frac}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-3-10-20-50}
\end{center}
\vspace{0.cm}}
\caption{The finite element interpolation of the gas volume fraction, for the optimal upwind scheme and for different mesh resolutions. }
\label{bl-3-10-20-50}
\end{figure}

\subsubsection{Discontinuous formulation}

Here results for the discontinuous between elements
of saturation and pressure are presented.
Having the discontinuity between elements potentially allows one
to use a course mesh to represent abruptly changing fields.
For example, using two discontinuous elements only one
obtains a result, for the BL test case, which is qualatively
similar to the converged solution, see \ref{bl-dg-2eles}.
This solution was obtained with upwinding within and
between the elements, as described in section \ref{opt-up}.
This upwind scheme issued in all results presented here
with the acception of solutions obtained using a central scheme
as shown in figure \ref{bl-dg-cent-4-10-20} for different
resolutions. The corresponding upwind solutions at the
same mesh resolutions are shown in figure \ref{bl-dg-4-10-20}.
In order to get a feel for how the discontinuous solutions
compare, in terms of accuracy, with the continuous
solutions of the previous subsection they are compared
in figure \ref{bl-dg-4-10-vers-cty}. At the courser resolution
they do seem more accurate despite the outstanding accuracy
of the continuous formulation. We also show
the accuracy of the formulation for linear fem-saturation/pressure and various mesh resolutions in figure \ref{bl-dg-p1-2-4-5-10-20-40}.
Near the shock front there is little benefit in using high order elements
so linear elements perform well here compared to quadratic elements.

% dg:

%fig7: bl-dg-2eles.xmgr

%fig8: bl-dg-cent-4-10-20.xmgr

%fig9: bl-dg-4-10-20.xmgr

%fig10: bl-dg-4-10-vers-cty.xmgr

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-dg-2eles}
\end{center}
\vspace{0.cm}}
\caption{Two element solution using the discontinuous formulation. Both the
control volume gas saturation and the finite element interpolation
of this saturation are shown.  }
\label{bl-dg-2eles}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-dg-cent-4-10-20}
\end{center}
\vspace{0.cm}}
\caption{Gas saturations from the discontinuous formulation with no upwinding and for
different mesh resolutions. Notice that there are substantial oscillations.  }
\label{bl-dg-cent-4-10-20}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-dg-4-10-20}
\end{center}
\vspace{0.cm}}
\caption{Gas saturations from the discontinuous formulation with upwinding and for
different mesh resolutions.
Notice that oscillations are suppressed compared to the central scheme.  }
\label{bl-dg-4-10-20}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-dg-4-10-vers-cty}
\end{center}
\vspace{0.cm}}
\caption{Gas saturations shown comparing the accuracy of the discontinuous between elements and continuous
formulation. The 50 element continuous solution may be viewed as a converged
result.     }
\label{bl-dg-4-10-vers-cty}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-dg-p1-2-4-5-10-20-40}
\end{center}
\vspace{0.cm}}
\caption{Gas saturations for p1(linear) pressure/(fem-interpolation of saturation)
for changing mesh resolution.   }
\label{bl-dg-p1-2-4-5-10-20-40}
\end{figure}

%\pagebreak

\subsubsection{BL test case with positive and negative gravity}

In this section we apply the the formulations to the test
case of the previous section but with gravity defined
in both the negative (figure \ref{bl-sou-neg}) and
positive (figure \ref{bl-sou-pos}) x-directions.
These solutions converge to the analytical solutions
shown in the appendix.
Notice that for the negative gravity source the less dense gas region
is compressed (compared to the case without gravity shown in
the previous section) by the weight of the more dense liquid and
the opposite happens for the positive gravity result.

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-sou-pos}
\end{center}
\vspace{0.cm}}
\caption{Gas saturations for p2(quadratic) pressure/(fem-interpolation of saturation)
for changing mesh resolution and for the test case with gravity acting in
the +ve x-direction. }
\label{bl-sou-pos}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/bl-sou-neg}
\end{center}
\vspace{0.cm}}
\caption{Gas saturations for p2(quadratic) pressure/(fem-interpolation of saturation)
for changing mesh resolution and for the test case with gravity acting in
the -ve x-direction. }
\label{bl-sou-neg}
\end{figure}

\subsubsection{Pressure/density wave propogation}

In this section we solve a single phase flow problem
with an compressible with a simple EoS given by
$\rho=1+0.01 p_{CV}$ and the fluid initially as rest.
The inlet velocity is accelerated within
one time step (the time step sizes are $\Delta t=1\times 10^{-4}$)
to a unit velocity and is sustained for 0.005 seconds.
The inlet velocity is then decreased to zero.
The rest is a density/pressure wave which
propagates across the domain with a characteristic
velocity of $c=10$. The results at $t=0.25$ seconds
into the simulation are shown. The outlet pressure is zero
and initial density unity.

An intermediate density using a quadratic DG pressure
and cubic DG velocity are shown in figure \ref{compres-imp-nonlin}.
The final solution is shown for this scheme as well
as a quadratic continuous pressure and quadratic DG velocity
scheme. In addition, we use the same two scheme's but
switching off the non-linear terms in the momentum
equations (retaining the time term only) to
produce the results shown in figure \ref{compres-imp-no-nonlin}. We have
also shown the results using the overlapping finite
element method. For the continuous scheme this results
in an exact representation of the momentum equation.
For the DG pressure formulation this is no longer
true but is close in some sense.

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/compres-imp-nonlin}
\end{center}
\vspace{0.cm}}
\caption{Density wave propogation from left to right across the domain
with DG and continuous pressure formulations. The fem-interpolation of
density is shown. }
\label{compres-imp-nonlin}
\end{figure}

\begin{figure}[H]
\vbox{
\begin{center}
\includegraphics[width=17.5cm,height=12.5cm]{./doc_figures/compres-imp-no-nonlin}
\end{center}
\vspace{0.cm}}
\caption{Density wave propogation from left to right across the domain
with DG, continuous pressure and overlapping velocity formulations.
The non-linear terms in the momentum equations are switched off
in these simulations. The fem-interpolation of
density is shown.  }
\label{compres-imp-no-nonlin}
\end{figure}


\chapter{CONCLUSIONS AND FUTURE WORK} \label{ch:conclusion}% Must have a blank line after every section label

This work analyzes a method of detecting hierarchical and communities in complex networks. This method is capable of detecting the absence of significant community structure as an early stopping criterion, and it performs competitively against other community detection methods. It has been shown to be stable to perturbations in the graph structure, unlike competing methods. Additionally, it can detect ties.

We have shown that the leximin method (and the related MCF cut algorithm) can identify ties, while eight popular methods cannot. These ties are a superposition of two dendrogram behaviors, and perturbing edge capacities gives a smooth transition away from the tie behavior.

Gridlock is a fragmentation of the network structure that occurs when the network lacks any clear mesoscopic, community structure. All edges are saturated with flow at the same time, without any bottlenecks. For a given expected density of edges, larger graphs produce gridlock more frequently. Every gridlock graph with rational capacities is related to a multigraph with unit capacities. On these multigraphs, flow is passed between all pairs along edge-disjoint paths.

The leximin method is competitive with other methods for low mixing parameter. It tends to break off singletons and small structures between or at fringes of communities. Breaking off singletons suggests worthiness for evaluations involving overlapping communities. Additionally, in graphs with real-world properties but lacking strong community structure, gridlock is extremely likely to occur.

Normalized mutual information (NMI) is deficient for evaluating community detection as a ground truth because it exaggerates accuracy of a random assignment to clusters. Argued in favor of adjusted mutual information (AMI), which addresses this deficiency. Most algorithms' scores do not change significantly under AMI; the trends are the same. It does, however, assess the leximin method in a way that agrees with intuition.

Due to the complexity of the leximin method, other methods for identifying community structure may be more desirable when the ability to recognize ties is not important or concerns about stability are not paramount. Additionally, in networks with weak community structure, other methods demonstrably outperform the AMI of the leximin method, so they should be preferred.

\section{Future Work}

Often, the disagreement between LFR-given clusters and those identified by the leximin method is \emph{not} because nodes are assigned to the \emph{wrong} communities. Instead, nodes are splintered off into \emph{their own} communities. This especially happens when equally strong connections tie the node to two different communities. This suggests an overlapping structure with some nodes serving as hubs or middlemen. Consequently, it would be beneficial to test the method on Lancichinetti and Fortunato's benchmark for overlapping communities~\cite{lancichinetti2009benchmarks}.

Additionally, the leading eigenvector method is another that displays early stopping behavior. Work to contrast their criteria for lack of mesoscopic structure in random graphs is warranted.

Further, because the leximin method operates in such a high-order polynomial time, it would be beneficial to compare the accuracy of community detection performed by approximation methods that exist~\cite{shahrokhi1989approximation}~\cite{madry2010faster}.

Finally, work to tighten the bound of the conjecture from \autoref{ch:random} would be beneficial to the traffic theory problems which surround the MCFP.


% Document Type: LaTeX

\chapter{The \resquan\ Library}

The \resquan\ library provides some basic facilities for working with
restricted quantifications. It consists of a single theory \verb|res_quan.th|,
which contains a number of theorems about the properties of some
restricted quantifiers, and a set of ML functions for dealing with
these quantifiers. It also contains some conditional
rewriting tools which can be loaded as a separate library part.

The description in this chapter begins with a brief introduction to
the syntax for restricted quantification. This is followed by an
overview of the ML functions available in the library and a
description of the theory \verb|res_quan.th|. A complete reference
manual for all ML functions appears in Chapter~2. The last chapter
lists all theorems in the \verb|res_quan.th|.

\section{Syntax for restricted quantification}

Since Version 2.0, \HOL\ provides parser and pretty printer support
for restricted quantification. This notation allows terms of the form
\[
\con{Q}\,x ::P.\, t[x],
\]
where \con{Q} is a quantifier and
if $x:\alpha$ then $P$ can be any term of type $\alpha\fun\bool$; this
denotes the quantification of $x$ over those values satisfying $P$.
The qualifier {\small\verb|::|} can be used with {\small\verb|\|} and any
binder, including user defined ones. The appropriate meanings are
predefined for {\small\verb|\|} and the built-in binders
{\small\verb|!|}, {\small\verb|?|} and {\small\verb|@|}.
This syntax automatically translates as follows:

\begin{hol}
{\small\verb%   \%}$v${\small\verb%::%}$P${\small\verb%.%}$tm${\small\verb%    <---->   %}\con{RES\_ABSTRACT}\ $P${\small\verb% (\%}$v${\small\verb%.%}$tm${\small\verb%)%}\\
{\small\verb%   !%}$v${\small\verb%::%}$P${\small\verb%.%}$tm${\small\verb%    <---->   %}\con{RES\_FORALL}\ \ \ $P${\small\verb% (\%}$v${\small\verb%.%}$tm${\small\verb%)%}\\
{\small\verb%   ?%}$v${\small\verb%::%}$P${\small\verb%.%}$tm${\small\verb%    <---->   %}\con{RES\_EXISTS}\ \ \ $P${\small\verb% (\%}$v${\small\verb%.%}$tm${\small\verb%)%}\\
{\small\verb%   @%}$v${\small\verb%::%}$P${\small\verb%.%}$tm${\small\verb%    <---->   %}\con{RES\_SELECT}\ \ \ $P${\small\verb% (\%}$v${\small\verb%.%}$tm${\small\verb%)%}
\end{hol}

The constants \con{RES\_ABSTRACT}, \con{RES\_FORALL}, \con{RES\_EXISTS} and
\con{RES\_SELECT} are defined in the theory \ml{bool} to provide
semantics for these restricted quantifiers as follows:

\begin{hol}\begin{verbatim}
   RES_ABSTRACT P tm  =  \x:*. (P x => tm x | ARB:**)

   RES_FORALL   P tm  =  !x:*. P x ==> tm x

   RES_EXISTS   P tm  =  ?x:*. P x /\ tm x

   RES_SELECT   P tm  =  @x:*. P x /\ tm x
\end{verbatim}\end{hol}

\noindent where the constant \con{ARB} is defined in the theory \ml{bool} by:

\begin{hol}\begin{verbatim}
   ARB  =  @x:*. T
\end{verbatim}\end{hol}

User-defined binders can also have restricted forms, which are set up
with the function:

\begin{holboxed}\index{associate_restriction@\ml{associate\_restriction}}
\begin{verbatim}
   associate_restriction : (string # string) -> *
\end{verbatim}\end{holboxed}

\noindent If \m{B} is the name
of a binder and \ml{RES\_}$B$ is the name of a suitable constant (which
must be explicitly defined), then executing:

\begin{hol}
{\small\verb%   associate_restriction(`%}\m{B}{\small\verb%`, `RES_%}\m{B}{\small\verb%`)%}
\end{hol}

\noindent will cause the parser and pretty-printer to support:

\begin{hol}
{\small\verb%   %}$B$ $v${\small\verb%::%}$P${\small\verb%. %}$tm${\small\verb%    <---->   RES_%}$B$ $P${\small\verb% (\%}$v${\small\verb%. %}$tm${\small\verb%)%}
\end{hol}

\noindent Note that associations between user defined binders and their
restrictions are not stored in theory files, so they have to be set up
for each \HOL\ session (e.g. with a {\small\verb%hol-init.ml%} initialization file).

The flag \ml{print\_restrict} has default \ml{true}, but if set to
\ml{false} will
disable the pretty printing. This is useful for seeing what the
semantics of particular restricted abstractions are.
Here is an example session:

\setcounter{sessioncount}{1}
\begin{session}\begin{verbatim}
#"!x y::P. x<y";;
"!x y :: P. x < y" : term

#set_flag(`print_restrict`, false);;
true : bool

#"!x y::P. x<y";;
"RES_FORALL P(\x. RES_FORALL P(\y. x < y))" : term

#"?(x,y) p::(\(m,n).m<n). p=(x,y)";;
"RES_EXISTS
 (\(m,n). m < n)
 (\(x,y). RES_EXISTS(\(m,n). m < n)(\p. p = x,y))"
: term

#"\x y z::P.[0;x;y;z]";;
"RES_ABSTRACT P(\x. RES_ABSTRACT P(\y. RES_ABSTRACT P(\z. [0;x;y;z])))"
: term
\end{verbatim}\end{session}

The syntax for restricted quantification provides a method of
simulating subtypes and dependent types; the qualifying predicate $P$ can be
an arbitrary term containing parameters. For example:
{\small\verb|!|}$w${\small\verb|::|}$\con{Word}(n)${\small\verb|. |}$t[w]$,
for a suitable constant \con{Word}, simulates a quantification over the
`type' of $n$-bit words.\footnote{This approach is used in the library
{\tt word} to model bit vectors.}

\section{The theory {\tt res\_quan.{}th}}

This theory contains a small number of theorems about the restricted
universal quantifier and restricted existential quantifier.
The following four theorems state the distributivity property of these
quantifiers across conjunction and disjunction.
\begin{verbatim}
 RESQ_FORALL_CONJ_DIST
  |- !P Q R.
     (!(i:*) :: P. (Q i /\ R i)) = (!i :: P. Q i) /\ (!i :: P. R i)

 RESQ_FORALL_DISJ_DIST
  |- !P Q R.
     (!(i:*) :: \i. P i \/ Q i. R i) = (!i :: P. R i) /\ (!i :: Q. R i)

 RESQ_EXISTS_DISJ_DIST
  |- !P Q R.
     (?(i:*) :: P. (Q i \/ R i)) = (?i :: P. Q i) \/ (?i :: P. R i)

 RESQ_DISJ_EXISTS_DIST
  |- !P Q R.
     (?(i:*) :: \i. P i \/ Q i. R i) = (?i :: P. R i) \/ (?i :: Q. R i)
\end{verbatim}

The theorems \ml{RESQ\_FORALL\_REORDER} and \ml{RESQ\_EXISTS\_REORDER}
state the reordering property of these quantifiers.
\begin{verbatim}
 RESQ_FORALL_REORDER
  |- !(P:*->bool) (Q:**->bool) (R:*->**->bool).
      (!i :: P. !j :: Q. R i j) = (!j :: Q. !i :: P. R i j)

 RESQ_EXISTS_REORDER
  |- !(P:*->bool) (Q:**->bool) (R:*->**->bool).
      (?i :: P. ?j :: Q. R i j) = (?j :: Q. ?i :: P. R i j)
\end{verbatim}
The theorem \ml{RESQ\_FORALL\_FORALL} states the reordering property of
the restricted universal quantifier and the ordinary universal
quantifier.
\begin{verbatim}
 RESQ_FORALL_FORALL
  |- !(P:*->bool) (R:*->**->bool) x.
      (!x. !i :: P. R i x) = (!i :: P. !x. R i x)
\end{verbatim}

\section{ML functions}

The ML functions available when this library is loaded can be divided
into six groups: conditional rewriting tools, syntax functions,
derived rules, conversions, tactics, and constant definitions. They
will be described in separate subsections.

\subsection{Conditional rewriting tools}

The conditional rewriting tools are not specific for restricted
quantifiers. They are available as a separate part of the library
which can be loaded into \HOL\ without loading other functions in this
library. This is done by the command
\begin{verbatim}
 load_library `res_quan:cond_rewrite`;;
\end{verbatim}

The conditional rewriting tools consists of a simple tactic which is
for use in goal-directed proof and a simple conversion which is
usually used in forward proof.

\subsubsection{Conditional theorems}

Both the conditional rewriting tactic and conversion require a theorem
to do the rewriting. This theorem should be an implication whose
consequence is an equation, i.e., it should be of the following form:
\begin{equation}
   A \vdash \forall\,x_1 \ldots x_n\DOT P_1 \IMP \ldots P_m \IMP
 (Q[x_1,\ldots,x_n] = R[x_1,\ldots,x_n]) \label{eq-cond-thm}
\end{equation}
where $x_1, \ldots, x_n$ are the only variables that occur free in the
left-hand side of the conclusion of the theorem but do not occur free
in the assumptions. Futhermore, none of the antecedents
$P_1,\ldots,P_n$ should be
conjunctions. The idea of  conditional rewriting is that the
antecedents of this input theorem are treated as conditions which have
to be satisfied before the equation $Q[x_1,\ldots,x_n] = R[x_1,\ldots,x_n]$
can be used to rewrite a term.

The ML function \ml{COND\_REWR\_CANON} transforms a theorem
into the canonical form in~\ref{eq-cond-thm}. The antecedents of the
input theorem to \ml{COND\_REWR\_CANON} may contain conjunctions and
quantification. For example, suppose that {\tt th} is the theorem
\begin{equation}
   A \vdash \forall\,x\DOT P_1\,x \IMP  \forall y\,z.(P_2\,y \AND P_3\,z) \IMP
 (\forall t. Q[x,y,z,t] = R[x,y,z,t]) \label{eq-cond-thm2}
\end{equation}
then \verb|COND_REWR_CANON th| returns the theorem
\[
   A \vdash \forall\,x\,y\,z\,t\DOT P_1\,x \IMP P_2\,y \IMP P_3\,z \IMP
 (Q[x,y,z,t] = R[x,y,z,t])
\]
That is all universal quantifications are moved to the outer most level
and conjunctions in the antecedents are converted to implication.

\subsubsection{Conditional rewriting tactic}

The basic conditional rewriting tactic is
\begin{holboxed}
\begin{verbatim}
   COND_REWRITE1_TAC : thm_tactic
\end{verbatim}
\end{holboxed}
Suppose {\tt th} is the theorem in~\ref{eq-cond-thm2},
the effects of applying the tactic $\ml{COND\_REWRITE1\_TAC}\;th$ to the
goal $(asm,gl)$ is that
\begin{itemize}
\item  all instances of $Q$ in the goal $gl$ are
	replaced by corresponding instances of $R$, and
\item the instances of the antecedents $P_i$ which do not appear in
	the assumption $asm$ become new subgoals.
\end{itemize}

This tactic is implemented using a lower level tactic \ml{COND\_REWR\_TAC}.
The theorem $th$ supplied to \ml{COND\_REWRITE1\_TAC} is processed by
\ml{COND\_REWR\_CANON} first. The resulting theorem is passed to the low
level conditional rewriting tactic \ml{COND\_REWR\_TAC} together with a
search function \ml{search\_top\_down}. This function determines how to
find the instantiations. By calling \ml{COND\_REWR\_TAC} with different
search function, other conditional rewriting strategy can be
implemented. The details of the tactics and search functions can be
found in the reference entries in Chapter~2.
Note that the {\tt 1} in the name of the tactic indicates that it
takes only a single theorem as its argument.

\subsubsection{Conditional rewriting conversion}

The basic conditional rewriting conversion is
\begin{holboxed}
\begin{verbatim}
   COND_REWRITE1_CONV : (thm list -> thm -> conv)
\end{verbatim}
\end{holboxed}
which performs conversion in a way similar to the conditional
rewriting tactics. The difference is that the instances of the
antecedents are added to the list of assumptions of the resulting theorem. The
extra argument to this conversion is a list of theorems which are
used to eliminate instances of the antecedents from the assumptions.

\subsection{Syntax functions}

There are term constructors, term destructors and term testers for the
four built-in restricted quantifiers. There are also iterative
constructors and destructors for the restricted universal and
existential quantifiers. Their names and types are:
\begin{holboxed}
\begin{verbatim}
mk_resq_forall = - : ((term # term # term) -> term)
mk_resq_exists = - : ((term # term # term) -> term)
mk_resq_select = - : ((term # term # term) -> term)
mk_resq_abstract = - : ((term # term # term) -> term)
list_mk_resq_forall = - : (((term # term) list # term) -> term)
list_mk_resq_exists = - : (((term # term) list # term) -> term)

dest_resq_forall = - : (term -> (term # term # term))
dest_resq_exists = - : (term -> (term # term # term))
dest_resq_select = - : (term -> (term # term # term))
dest_resq_abstract = - : (term -> (term # term # term))
strip_resq_forall = - : (term -> ((term # term) list # term))
strip_resq_exists = - : (term -> ((term # term) list # term))

is_resq_forall = - : (term -> bool)
is_resq_exists = - : (term -> bool)
is_resq_select = - : (term -> bool)
is_resq_abstract = - : (term -> bool)
\end{verbatim}
\end{holboxed}

\subsection{Derived rules}

The introduction and elimination rules for the restricted universal
quantifier are \ml{RESQ\_SPEC} and \ml{RESQ\_GEN} which are in analogy
to the rules for the universal quantifier. The specification of these
rules are:
\[
\frac{\Gamma \THM \forall x :: P. t[x]}{\Gamma,P\,x'\THM t[x'/x]}
\quad\mbox{{\tt RESQ\_SPEC "x'"}}
\]
\[
\frac{\Gamma,P\,x\THM t[x]}{\Gamma \THM \forall x :: P. t[x]}
\quad\mbox{{\tt RESQ\_GEN "x" "P"}}
\]
There is an extra rule \ml{RESQ\_HALF\_SPEC} which transform a
restricted universal quantification into its underlying semantic
representation, namely an implication.
\[
\frac{\Gamma \THM \forall x :: P. t[x]}{\Gamma \THM\forall x. P\,x\IMP t[x]}
\quad\mbox{{\tt RESQ\_HALF\_SPEC}}
\]

There are iterative versions of the introduction and elimination rules:
\begin{holboxed}
\begin{verbatim}
RESQ_SPECL = - : (term list -> thm -> thm)
RESQ_SPEC_ALL = - : (thm -> thm)

RESQ_GENL = - : (term list -> thm -> thm)
RESQ_GEN_ALL = - : (thm -> thm)
\end{verbatim}
\end{holboxed}

Since instantiation of a theorem is a very common operation, for
convenience, the following ML functions are provided to instantiate a
theorem with a mixture of ordinary and restricted universal quantifiers:
\begin{holboxed}
\begin{verbatim}
GQSPEC = - : tm -> thm -> thm
GQSPECL : term list -> thm -> thm
GQSPEC_ALL : thm -> thm
\end{verbatim}
\end{holboxed}

The rule for eliminating restricted existential quantification is
\ml{RESQ\_HALF\_EXISTS} whose specification is:
\[
\frac{\Gamma \THM \exists x:: P. t[x]}{\Gamma \THM \exists x. P\,x
\AND t[x]}\quad\mbox{{\tt RESQ\_HALF\_EXISTS}}
\]
This function only transforms the restricted existential quantifier to
an ordinary existential quantifier.

The function \ml{RESQ\_MATCH\_MP} eliminates a restricted universal
quantifier using an instance of the condition. Its specification is:
\[
\frac{\Gamma_1 \THM \forall x::P. t[x]\qquad\Gamma_2\THM P\,x'}
{\Gamma_1 \cup \Gamma_2 \THM t[x'/x]}\quad\mbox{{\tt RESQ\_MATCH\_MP}}
\]

\subsection{Conversions}

There are a number of conversions for manipulating restricted
universal quantification. The conversion \ml{RESQ\_FORALL\_CONV}
converts a restricted universal quantification to its underlying
semantic representation, namely an implication. For example,
evaluating the ML expression
\verb|RESQ_FORALL_CONV "!x :: P. t[x]"| returns the following theorem:
\[
\THM \forall x :: P. t[x] = \forall x. P x \IMP t[x]
\]
The ML function
\ml{IMP\_RESQ\_FORALL\_CONV} performs the reverse conversion. The ML
function \ml{LIST\_RESQ\_FORALL\_CONV} is an iterative version of
\ml{RESQ\_FORALL\_CONV} which converts a term having multiple
restricted universal quantifiers at the outer level.

The conversions \ml{RESQ\_FORALL\_AND\_CONV} and
\ml{AND\_RESQ\_FORALL\_CONV} move the restricted universal
quantification in and out of a conjunction, respectively.
The conversion \linebreak\ml{RESQ\_FORALL\_SWAP\_CONV} changes the order of two
restricted universal quantifications. For instance, evaluating the
following ML expression
\begin{verbatim}
   RESQ_FORALL_SWAP_CONV "!i :: P. !j :: Q. R"
\end{verbatim}
returns the theorem:
\[
\THM (\forall i :: P. \forall j :: Q. R) = (\forall j :: Q. \forall i :: P. R)
\]
providing that $i$ does not occur free in $Q$ and $j$ does not occur
free in $P$.

The conversion \ml{RESQ\_EXISTS\_CONV} transforms a restricted
existential quantification to its underlying semantic representation.
For instance, \verb|RESQ_EXISTS_CONV "?x::P. t"| returns the theorem
\[
\THM \exists x::P. t = \exists x. P x \AND t[x]
\]

A rewriting conversion \ml{RESQ\_REWRITE1\_CONV} uses a restricted
universal quantified equation to rewrite a term. For instance, if {\tt
th} is a theorem of the following form:
\[
\THM \forall x::P. u[x] = v[x]
\]
and {\tt tm} is a term containing some instances of $u$,
then \verb|RESQ_REWRITE1_CONV ths th tm| will return the theorem
\[
\Gamma \THM tm = tm'
\]
where $tm'$ is obtained by replacing all instances of $u$ by
corresponding instances of $v$ and $\Gamma$ contains instances of $P$
which cannot be eliminated by the theorems in the list {\tt ths}. This
conversion is implemented using the conditional rewriting conversion
\ml{COND\_REWRITE1\_CONV}.

\subsection{Tactics}

The simple tactics \ml{RESQ\_GEN\_TAC} and \ml{RESQ\_EXISTS\_TAC} are
provided for stripping of a restricted universal or existential
quantifier, respectively. They reduce a restricted quantified goal to
a goal in the underlying semantic representation. They are in analogy
to \ml{GEN\_TAC} and \ml{EXISTS\_TAC}.

The resolution tactics and tactical listed below are in analogy to
\ml{RES\_TAC}, \ml{IMP\_RES\_TAC}, \ml{RES\_THEN} and
\ml{IMP\_RES\_THEN}.
\begin{holboxed}
\begin{verbatim}
RESQ_RES_THEN : (thm_tactic -> tactic)
RESQ_IMP_RES_THEN : thm_tactical
RESQ_RES_TAC : tactic
RESQ_IMP_RES_TAC : thm_tactic
\end{verbatim}
\end{holboxed}
The theorem-tactic \ml{RESQ\_IMP\_RES\_TAC} uses a restricted universally
quantified theorem as if it is an implication to perform resolution.
Similarly, the tactic \ml{RESQ\_RES\_TAC} uses a restricted universally
quantified assumption as if it is an implication to
perform resolution against other assumptions.

The theorem-tactic \ml{RESQ\_REWRITE1\_TAC} uses a restricted universally
quantified theorem to perform conditional rewriting.
For instance, if {\tt th} is the following theorem
\[
\THM \forall x::P. u[x] = v[x]
\]
then applying the tactic \verb|RESQ_REWRITE1_TAC th| to a goal {\tt
gl} will reduce it to one or more subgoals {\tt gl0}, \ldots, {\tt
gln}. The main subgoal {\tt gl0} is obtained by replacing instances of
$u$ in {\tt gl} with corresponding instances of $v$. The new subgoals
are the instances of $P$ which do not occur in the assumption of $gl$.

\subsection{Constant definitions}

This library provides support for defining constants whose arguments
can be restricted quantified variables. For example, one can defined a constant
\con{C} by the following equation:
\begin{eqnarray*}
\lefteqn{\forall x_1::P_1. \ldots \forall x_n::P_n.} \\
 & &  \mbox{{\sf C}}\, y\, x_1 \ldots x_n\, z = t[y,x_1,\ldots,x_n,z]
\end{eqnarray*}
The constant \con{C} may be an ordinary constant, or it may have
either `infix' or `binder' status. The ML functions for defining
restricted quantified constants are:
\begin{holboxed}
\begin{verbatim}
new_resq_definition        : (string # term) -> thm
new_infix_resq_definition  : (string # term) -> thm
new_binder_resq_definition : (string # term) -> thm
\end{verbatim}
\end{holboxed}
Suppose {\tt tm} is the term shown above, evaluating the ML expression
\begin{verbatim}
   new_resq_definition(`C_DEF`,tm)
\end{verbatim}
will store the definition under
the name \verb|C_DEF| in the current theory. The definition is
returned as the value of the expression.


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage[margin=0.75in]{geometry}

\setlength{\parskip}{0.7em}
\setlength{\parindent}{0em}

\begin{document}
	\begin{center}

		% MAKE SURE YOU TAKE OUT THE SQUARE BRACKETS
		\LARGE{\textbf{CSE 6730, Group Proposal}} \\
		\vspace{1em}
		\Large{Project 2: Complex Simulation} \\

	\end{center}
	\begin{normalsize}

		\section{Project Title}

		Simulation of Predator-Prey Population Dynamics

		\section{Team Members}

		\begin{enumerate}
			\item D. Aaron Hillegass (GTID 901988533)
			\item Siawpeng Er (GTID 903413430)
			\item Xiaotong Mu (GTID 903529807)
		\end{enumerate}

		\section{Problem Description and Purpose}
		The predator and prey relationship is an important ecological system. Their populations rise and fall over time as they interact and impact one another. These interactions are the prime movers of energy through food chains. Both prey and predators are affecting each other. In simplest interaction, predators depend on the prey as the food source. However, any abuse of the food source may result in decease in population of the prey, and subsequently decrease the number of the predators due to lack of food. Because of such interaction, the population of the predators and the prey may oscillate, and inversely proportional to each others.  \\

		Predator prey releationship is important for us to understand the impact of the relationship on the ecological system in one area. Such relationship is always complicated. Without predators, prey (normally herbivors) will cause detrimental impact on the plants in that area. However, overkill by the predators may also impact the balance of the nature. Besides, there are effects from human intervention on such relationship (eg: hunting and destroy of the habitat). Furthermore, predator-prey model can be used to describe many fundamental characteristics of ecological systems and can even be extended to other ideas like military response \cite{derrik}.\\

		One of the mathematical models that simulates predator and prey interactions is the Lotka-Volterra model proposed by Alfred Lotka and Vito Volterra. Lotka helped develop the logistic equation to explain autocatalytic chemical reactions. Volterra interconnected the logistic equation to two separate populations in competition to explain predator and prey relationships. We hope to use this intuitive model in our complex system simulation,  so that we could gain more understanding on the relationship, as well as the impact of our activities on such relationship.

		\section{Data Source}
		For this project, we plan to obtain some data from the National Park. However, it is also possible from literature review we could obtained some of the data source used by the their simulation and use it as our data source.

		\section{Methodology}
		Our simulation will first simulate predators and prey entering and exiting a predefined area. Then through interactions, their population may affecting each others.

		Traditionally, there is the nonlinear Lotka-Volterra Model of the predator-prey dynamic system \cite{inproceedings, 1102729}. LVM approach is a simplified model and suitable for detailed stability analysis. However, it is also very limited model and lack of flexibility for complex interaction. Hence, we also hope to incorporate the Agent-Based Model \cite{Hodzic} in this project to increase the completeness of our analysis.

		In our project, some of the ideas that we wish to investigate include:
		\begin{enumerate}
			\item Long-term population interaction among predators and prey.
			\item Introduction of the uncertainties like diseases.
			\item Introduction of the third parties interaction: human activity, natural disasters etc.
		\end{enumerate}

		\section{Development Platform}
		The programming language is Python 3. We will provide a Jupyter notebook for user interaction.
		In the Jupyter notebook, we will allow the user to change some of the probability and the simulation parameters to see different result of the simulation.

		\section{Division of Labor}
		As we move forward on our project, we plan to work concurrently. The timeline is as below:

		\begin{center}
			\begin{tabular}{ |c|c|c| }
				\hline
				Task & Duration  \\
				\hline
				Data collection & 2 weeks \\
				Modeling design and implementaion & 4 weeks \\
				Modeling revised & 4 weeks \\
				\hline
			\end{tabular}
		\end{center}

		\bibliographystyle{plain}
		\bibliography{reference}
	\end{normalsize}

\end{document}


\section{Deep Learning}
\label{sec:deep_learning}

\subsection{Why Machine Learning}

Machine learning methods try to model either the joint or the marginal distribution of some covariates and some target. In statistics a model is usually explicitly formulated. A typical example could be linear regression. The covariates is decided on, and transformed such that they fit the desired model. The linear regression will yield a parameter vector which can then be interpreted. This interpretation is usually the focus; parameter inference. Example: Does an increase in the minimum salary have a negative effect on BNP per capita. Machine Learning focuses on prediction. That is, the objective is to predict some target conditional on some covariates. The specific model is not necessarily important, instead the focus is on Out-Of-Sample error. These predictive methods lend themselves well where causal inference is not needed. Example: What is the expected consumption on a monthly basis by person with a given set of characteristics. When formulating a traditional econometric method, e.g., OLS, there are standard ways to infer if the model is well specified. In general machine learning does not have the same asymptotic results regarding regularization of a model. Usually sample splitting will be used instead. Take a data set, split the data into two partitions a test set and a training set. First the hyper parameters of the machine learning algorithm is tuned, usually by finding which set of hyper parameters that yield the best performance on the training data. Cross validation is the go-to procedure to optimize the hyper parameters. The final algorithm is only used on the test data set once yielding the out-of-sample performance. Machine learning methods, as mentioned before usually has associated hyper parameters. These are parameters of the model, which is not fitted by training on the data, rather these are specifications of the algorithm before training the model. Much of machine learning is about finding the right hyper parameters and regularizing the model in an intelligent way \parencite{friedman_elements_2001}. Now why is this paper concerned with ML methods? This is due to the fact, that when estimating the value function, or the policy function, one cannot be sure that this follows a linear function. In fact value functions and policy functions might be highly non-linear, which is where machine learning methods shine. Considering that the value function is a conditional expectation: $ \E[Y \mid X=x]$, where $Y$ is the expected cumulative discounted rewards and $X$ is the state implies, that machine learning methods is the appropriate choice for value function approximation. Also, in this case, causal interpretation of the influence of a specific state on the value function is not of interest, rather it's the accuracy of the expected value function\footnote{Obviously, intelligent agents usually do causal inference on their actions. They might not do a certain action exactly because they have some causal notion of how the environment will evolve conditional on their action.}. Deep neural networks has been the standard way to implement reinforcement algorithms, however other machine learning methods can also be used. The reason for deep Learning methods being the standard implementation is the convenient property of online updating of the networks weights. In other words, as more data comes in, the neural network can be incrementally fitted to the new data.

\subsection{Deep Neural Networks}

Deep learning (feed forward networks), which is used in this paper, is in fact just layered non-linear functions. Figure \ref{fig:feedforwardnetwork} illustrates the architecture of a deep neural network\footnote{Figure found at \url{https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/MultiLayerNeuralNetworkBigger_english.png/381px-MultiLayerNeuralNetworkBigger_english.png}}.

\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.6]{figures/feedforwardnetworkillustration.png}
    \caption{Illustration of Feed Forward Neural Network}
    \label{fig:feedforwardnetwork}
\end{figure}

The network can be described as having an \textit{input layer}, that takes the covariates, $\textbf{x}$. The \textit{hidden layer} makes a transformation of the previous layer. This also implies that a hidden layer, can be followed by an arbitrary number of other hidden layers. Lastly an \textit{output layer} maps the representation of the last hidden layer into the desired output. For classification that could be a one-hot encoding of the classes, and for regression a single real valued scalar.

As illustrated in figure \ref{fig:feedforwardnetwork}, each layer is broken down into smaller cells. The number of cells in each layer corresponds to the width of the layer. The wider the layer the more flexible representation the given layer is capable of doing. The hidden cells work as mentioned by creating a non-linear transformation of the input from last layer:

\begin{equation}
    z_i^{+} = g(\textbf{z}; \theta) = g(\textbf{w}^T \cdot \textbf{z} + b)
\end{equation}

The output of cell \textit{i} is the real valued scalar $z_i^+$. $g$ is the activation function that maps the input into the output. $\textbf{w}$ is the weights of dot product, $\textbf{z}$ is a vector of the outputs from the last layer, and $b$ is bias or the constant in the activation. In that sense the activation looks like a linear regression squashed through an activation function $g$. Multiple different activation functions has been proposed. Originally the logistic function was preferred, but in later years the rectified linear unit activation function has been popular \parencite{goodfellow_deep_2016}:

\begin{equation}
    \textbf{Rectified Linear Unit: }  \max \lcp 0, \textbf{w}^T \cdot \textbf{z} + b \rcp
\end{equation}

The neural network can in other words be considered a function $f$, that takes an input $\textbf{x}$ and maps it to some output $y$, parameterized by $\theta$, which is a collection of all the weights and biases associated with each individual cell.

\subsection{Stochastic Gradient Descent and Optimization}

The neural network is estimated (or trained) by using stochastic gradient descent. This is possible due to the fact, that a neural network can be represented as a set of nested functions, such that the chain rule can be applied. The loss function can in other words be differentiated with respect to the parameter vector $\theta$ as shown below:

\begin{equation}\label{eq:loss_function}
    \frac{\partial}{\partial\theta} \Loss (\textbf{X}, \textbf{Y}, \theta) = \frac{\partial}{\partial\theta} \lp \sum \ell_i \rp = \frac{\partial}{\partial\theta} \lp \sum \lp \hat{Y}_i  - Y_i \rp^2 \rp = \frac{\partial}{\partial\theta} \lp \sum \lp f^{\theta}(X_i)  - Y_i \rp^2 \rp
\end{equation}

In equation \eqref{eq:loss_function} the loss function $\Loss$ is assumed be a mean squared error loss function, in other words a regression problem. The optimization works by minimizing the loss with respect to the parameters $\theta$. In modern neural network architectures it is not unusual to see neural networks have in the excess of a million parameters. The objective function of the optimization cannot be assumed to be convex due to the non-linearity of the activation functions. For this reason deep neural networks is not solved analytically. Instead, gradient descent is used for estimating the parameters of the network. The update rule of the parameters can be described as \parencite{goodfellow_deep_2016}:

\begin{equation}
    \theta \la \theta - \alpha \nabla_{\theta} \Loss(\textbf{X}, \textbf{Y}, \theta)
\end{equation}

So for each step in the algorithm the derivative of the loss function with respect to the parameters can be calculated, and the parameters can be updated by taking a small step in parameter space of size $\alpha$ in the direction that reduces the loss. Stochastic gradient is a response to the fact that it can be computationally expensive to calculate the gradient for the entire data set in each update step. This is important for deep neural networks, since the training period of a large network, even on optimized hardware, can take a very long time, so any speed up for the training is important. In practice this implies that the training data is split into mini batches usually of size 32 to 128. The optimization is then performed on each of the small batches, taking a small step of size $\alpha$ for each step.