% Created 2021-09-02 Thu 17:27
% Intended LaTeX compiler: pdflatex
\documentclass[presentation,aspectratio=169, usenames, dvipsnames]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{khpreamble}
\usepackage{amssymb}
\usepgfplotslibrary{groupplots}
\newcommand*{\shift}{\operatorname{q}}
\definecolor{ppc}{rgb}{0.1,0.1,0.6}
\definecolor{iic}{rgb}{0.6,0.1,0.1}
\definecolor{ddc}{rgb}{0.1,0.6,0.1}
\usetheme{default}
\author{Kjartan Halvorsen}
\date{\today}
\title{Process Automation Laboratory - PID control}
\hypersetup{
 pdfauthor={Kjartan Halvorsen},
 pdftitle={Process Automation Laboratory - PID control},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 26.3 (Org mode 9.4.6)},
 pdflang={English}}
\begin{document}

\maketitle

\section{Repetition - Second-order model critically damped}
\label{sec:orgd8c85bb}
\begin{frame}[label={sec:org8c495f4}]{Second-order models}
\end{frame}
\begin{frame}[label={sec:org4130cf8}]{Two first-order models in series}
\begin{center}
\begin{tikzpicture}
  \node {\includegraphics[width=0.4\linewidth]{../../figures/tank-with-hole-no-variables}};
  \node at (5.3,-2.05) {\includegraphics[width=0.4\linewidth]{../../figures/tank-with-hole-no-variables}};
\end{tikzpicture}
\end{center}

\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
    \node[block, right of=input, node distance=20mm] (plant1)  {$G_1(s)$};
    \node[block, right of=plant1, node distance=26mm] (plant2)  {$G_2(s)$};
    \node[coordinate, right of=plant2, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$u(t)$} (plant1);
    \draw[->] (plant1) -- node[coordinate, ] (mp) { } (plant2);
    \draw[->] (plant2) -- node[above, near end] {$y(t)$} (output);
    \draw[red] (plant1.south west) ++(-4mm,-10mm) rectangle ++(49mm, 20mm);

    \node[red,below of=mp, node distance=10mm] {$G(s) = G_1(s)G_2(s)$};
  \end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}[label={sec:org51bc4e6}]{Fitting second-order critically-damped model}
\alert{Model with two identical time-constants.}
Assuming model
\[ \textcolor{green!50!black}{Y(s)} = \frac{K}{(s\tau + 1)^2}\textcolor{blue!80!black}{U(s)} \quad \overset{U(s) = \frac{u_f}{s}}{\Longrightarrow} \quad \textcolor{green!50!black}{y(t)} = u_f K\Big( 1 - (1+\frac{t}{\tau}\big)\mathrm{e}^{-\frac{t}{\tau}}\Big)u_H(t)\]
\def\Tcnst{2}
\def\tdelay{0.0}
\def\ggain{2}
\def\uampl{0.8}
\pgfmathsetmacro{\yfinal}{\uampl*\ggain}
\pgfmathsetmacro{\ytwo}{\yfinal*(1-2*exp(-1))}
\pgfmathsetmacro{\ytwofactor}{(1-2*exp(-1))}
\pgfmathsetmacro{\two}{\tdelay + \Tcnst}

\begin{center}
  \begin{tikzpicture}
    \begin{axis}[
    width=14cm,
    height=4.5cm,
    grid = both,
    xtick = {0, \two},
    xticklabels = {0,  $\tau$},
    ytick = {0, \ytwo, \uampl, \yfinal},
    yticklabels = {0, $\ytwofactor y_f$, $u_f$, $y_f$},
    xmin = -0.2,
    clip = false,
    %minor y tick num=9,
    %minor x tick num=9,
    %every major grid/.style={red, opacity=0.5},
    ]
      \addplot [thick, green!50!black, no marks, domain=0:11, samples=100] {\uampl*\ggain*(x>\tdelay)*(1 - (1+x/\Tcnst)*exp(-(x-\tdelay)/\Tcnst)} node [coordinate, pos=0.9, pin=-90:{$y(t)$}] {};
      \addplot [const plot, thick, blue!80!black, no marks, domain=-1:11, samples=100] coordinates {(-1,0) (0,0) (0,\uampl) (11,\uampl)} node [coordinate, pos=0.9, pin=-90:{$u(t)$}] {};
      \node at (axis cs: 11, -0.3) {$t$};
    \end{axis}
  \end{tikzpicture}
\end{center}

\[ y_f = \lim_{t\to\infty} y(t) = u_f K \quad \Rightarrow \quad K = \frac{y_f}{u_f}. \]
\end{frame}

\section{PID parameter intuition}
\label{sec:org9124c70}
\begin{frame}[label={sec:org21ee677}]{Feedback control}
   \begin{center}
   \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]
  {
  \node[coordinate] (input) {};
  \node[sumnode, right of=input] (sum) {\tiny $\sum$};
  \node[block, right of=sum, node distance=2.6cm] (reg) {$F(s)$};
  \node[block, right of=reg, node distance=2.6cm] (plant) {$G(s)$};
  \node[coordinate, right of=plant, node distance=2cm] (output) {};
  \node[coordinate, below of=plant, node distance=12mm] (feedback) {};

  \draw[->] (plant) -- node[coordinate, inner sep=0pt] (meas) {} node[near end, above] {$y(t)$} (output);
  \draw[->] (meas) |- (feedback) -| node[very near end, left] {$-$} (sum);
  \draw[->] (input) -- node[very near start, above] {$r(t)$} (sum);
  \draw[->] (sum) -- node[above] {$e(t)$} (reg);
  \draw[->] (reg) -- node[above] {$u(t)$}(plant);
}
\end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}[label={sec:org2fb2529}]{The PID controller}
\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt},scale=0.8, every node/.style={scale=0.8}]

    \node[coordinate] (input) {};
    \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\Sigma$};
    \node[block, right of=sum, node distance=20mm] (pid)  {$F(s)$};
    \node[coordinate, below of=sum, node distance=12mm] (feedback) {};
    \node[coordinate, right of=pid, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$r(t)$} (sum);
    \draw[->] (sum) -- node[above] {$e(t)$} (pid);
    \draw[->] (pid) -- node[above, near end] {$u(t)$} (output);
    \draw[->] (feedback) -- node[left, near start] {$y(t)$} node[right, pos=0.95] {-} (sum);
  \end{tikzpicture}
\end{center}

\alert{Parallel form (ISA)}
\[   F(s) &= k_c\left( 1 + \frac{1}{\tau_i s} + \tau_d s\right) \]

\alert{Series form}
\[F(s) = K_c \left( \frac{ \tau_I s + 1}{\tau_I s} \right) (\tau_D s + 1)
= \underbrace{\frac{K_c(\tau_I + \tau_D)}{\tau_I}}_{k_c} \left(1 + \frac{1}{\underbrace{(\tau_I + \tau_D)}_{\tau_i} s} + \underbrace{\frac{\tau_I\tau_D}{\tau_I + \tau_D}}_{\tau_d}s \right) \]
\end{frame}

\begin{frame}[label={sec:orgae39394}]{The PID - Parallel form}
\definecolor{ppc}{rgb}{0.1,0.1,0.6}
\definecolor{iic}{rgb}{0.6,0.1,0.1}
\definecolor{ddc}{rgb}{0.1,0.6,0.1}

\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
    \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\Sigma$};
    \node[color=iic,block, right of=sum, node distance=28mm] (ii)  {$\frac{1}{\tau_is}$};
    \node[color=ppc, coordinate, above of=ii, node distance=10mm] (pp)  {};
    \node[color=ddc,block, below of=ii, node distance=10mm] (dd)  {$\tau_ds$};
    \node[sumnode, right of=ii, node distance=20mm] (sum2) {\tiny $\Sigma$};
    \node[block, right of=sum2, node distance=20mm] (gain)  {$k_c$};
    \node[coordinate, below of=sum, node distance=12mm] (feedback) {};
    \node[coordinate, right of=gain, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$r(t)$} (sum);
    \draw[->] (sum) -- node[above, pos=0.2] {$e(t)$} node[coordinate] (mm) {}  (ii);
    \draw[->] (gain) -- node[above, near end] {$u(t)$} (output);
    \draw[->] (feedback) -- node[left, near start] {$y(t)$} node[right, pos=0.95] {-} (sum);
    \draw[->, color=ppc] (mm) |- (pp) -| node[right,] {$u_P(t)$} (sum2);
    \draw[->, color=ddc] (mm) |- (dd) -| node[right,] {$u_D(t)$} (sum2);
    \draw[->, color=iic] (ii)  -- node[above,] {$u_I(t)$} (sum2);
    \draw[->] (sum2) -- node[above, near end] {} (gain);

  \end{tikzpicture}
\end{center}

\begin{align*}
u(t) &= k_c\Big( \textcolor{ppc}{e(t)} + \textcolor{iic}{\frac{1}{\tau_i} \int_0^{t} e(\xi) d\xi} + \textcolor{ddc}{\tau_d \frac{d}{dt} e(t)} \Big)
\end{align*}
\end{frame}

\begin{frame}[label={sec:orga5afc99}]{The PID - Parallel form, modified D-part}
\definecolor{ppc}{rgb}{0.1,0.1,0.6}
\definecolor{iic}{rgb}{0.6,0.1,0.1}
\definecolor{ddc}{rgb}{0.1,0.6,0.1}

\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
    \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\Sigma$};
    \node[color=iic,block, right of=sum, node distance=28mm] (ii)  {$\frac{1}{\tau_is}$};
    \node[color=ppc, coordinate, above of=ii, node distance=10mm] (pp)  {};
    \node[color=ddc,block, below of=ii, node distance=10mm] (dd)  {$\tau_ds$};
    \node[sumnode, right of=ii, node distance=20mm] (sum2) {\tiny $\Sigma$};
    \node[block, right of=sum2, node distance=20mm] (gain)  {$k_c$};
    \node[coordinate, below of=sum, node distance=12mm] (feedback) {};
    \node[coordinate, right of=gain, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$r(t)$} (sum);
    \draw[->] (sum) -- node[above, pos=0.2] {$e(t)$} node[coordinate] (mm) {}  (ii);
    \draw[->] (gain) -- node[above, near end] {$u(t)$} (output);
    \draw[->] (feedback) -- node[left, near start] {$y(t)$} node[right, pos=0.95] {-} (sum);
    \draw[->, color=ppc] (mm) |- (pp) -| node[right,] {$u_P(t)$} (sum2);
    \draw[->, color=ddc] (feedback |- dd) -- node[above, pos=0.95] {-} (dd);
    \draw[->, color=ddc] (dd) -| node[right,] {$u_D(t)$} (sum2)  ;
    \draw[->, color=iic] (ii)  -- node[above,] {$u_I(t)$} (sum2);
    \draw[->] (sum2) -- node[above, near end] {} (gain);

  \end{tikzpicture}
\end{center}

\[    u(t) = k_c\Big( \textcolor{ppc}{e(t)} + \textcolor{iic}{\overbrace{\frac{1}{\tau_i} \int_0^{t} e(\xi) d\xi}^{u_I(t)}} + \textcolor{ddc}{ \underbrace{\tau_d \frac{d}{dt} \big(-y(t)\big)}_{u_D(t)}} \Big) \]
\end{frame}

\begin{frame}[label={sec:org320807c}]{The PID - Parallel form}
\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}, scale=0.6, every node/.style={scale=0.6}]

    \node[coordinate] (input) {};
    \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\Sigma$};
    \node[color=iic,block, right of=sum, node distance=28mm] (ii)  {$\frac{1}{\tau_is}$};
    \node[color=ppc, coordinate, above of=ii, node distance=10mm] (pp)  {};
    \node[color=ddc,block, below of=ii, node distance=10mm] (dd)  {$\tau_ds$};
    \node[sumnode, right of=ii, node distance=20mm] (sum2) {\tiny $\Sigma$};
    \node[block, right of=sum2, node distance=20mm] (gain)  {$k_c$};
    \node[coordinate, below of=sum, node distance=12mm] (feedback) {};
    \node[coordinate, right of=gain, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$r(t)$} (sum);
    \draw[->] (sum) -- node[above, pos=0.2] {$e(t)$} node[coordinate] (mm) {}  (ii);
    \draw[->] (gain) -- node[above, near end] {$u(t)$} (output);
    \draw[->] (feedback) -- node[left, near start] {$y(t)$} node[right, pos=0.95] {-} (sum);
    \draw[->, color=ppc] (mm) |- (pp) -| node[right,] {$u_P(t)$} (sum2);
    \draw[->, color=ddc] (feedback |- dd) -- node[above, pos=0.95] {-} (dd) -| node[right,] {$u_D(t)$}   (sum2);
    \draw[->, color=iic] (ii)  -- node[above,] {$u_I(t)$} (sum2);
    \draw[->] (sum2) -- node[above, near end] {} (gain);

  \end{tikzpicture}
  \small
  \(  u(t) = k_c\Big( \textcolor{ppc}{e(t)} + \textcolor{iic}{\overbrace{\frac{1}{\tau_i} \int_0^{t} e(\xi) d\xi}^{u_I(t)}} + \textcolor{ddc}{ \underbrace{\tau_d \frac{d}{dt} \big(-y(t)\big)}_{u_D(t)}} \Big)\)
\end{center}

   \begin{center}
   \def\TT{1}
   \begin{tikzpicture}
   \begin{axis}[
    clip=false,
    width=14cm,
    height=4.5cm,
    ylabel={},
    xlabel={$t$},
    ymax = 2,
    ymin = -0.5,
    ]
      \addplot[black, no marks, domain=-0.1:8, samples=200] {(x>0)*(1 - (1+x/\TT)*exp(-x/\TT)} node[coordinate, pin=-20:{$y(t)$}, pos=0.4] {};
      \addplot[magenta!70!black, no marks, domain=-0.1:8, samples=200] coordinates {(-0.1, 0) (0,0) (0,1) (8,1)} node[coordinate, pin=90:{$r(t)$}, pos=0.4] {};
    \end{axis}

 \end{tikzpicture}
\end{center}
\alert{Activity} Sketch the error signal \(e(t)\), the derivative signal \(u_D(t)\) and the integral signal \(u_I(t)\) (use \(\tau_i=\tau_d=1\))
\end{frame}

\begin{frame}[label={sec:org0429488}]{The PID - Parallel form, solution}
\end{frame}
\begin{frame}[label={sec:orgb2e7e1a}]{The PID - Parallel form, solution}
\(u(t) = k_c\Big( \textcolor{ppc}{e(t)} + \textcolor{iic}{\overbrace{\frac{1}{\tau_i} \int_0^{t} e(\xi) d\xi}^{u_I(t)}} + \textcolor{ddc}{ \underbrace{\tau_d \frac{d}{dt} \big(-y(t)\big)}_{u_D(t)}} \Big)\)
   \begin{center}
   \def\TT{1}
   \begin{tikzpicture}
   \begin{axis}[
    clip=false,
    width=14cm,
    height=5cm,
    ylabel={},
    xlabel={$t$},
    ymax = 2,
    ]
      \addplot[black, no marks, domain=-0.1:8, samples=200] {(x>0)*(1 - (1+x/\TT)*exp(-x/\TT)} node[coordinate, pin=-20:{$y(t)$}, pos=0.4] {};
      \addplot[magenta!70!black, no marks, domain=-0.1:8, samples=200] coordinates {(-0.1, 0) (0,0) (0,1) (8,1)} node[coordinate, pin=90:{$r(t)$}, pos=0.21] {};
      \addplot[color=ppc, no marks, domain=0:8, samples=200] {(x>=0)*( (1+x/\TT)*exp(-x/\TT)} node[coordinate, pin=20:{$e(t)$}, pos=0.7] {};
      \addplot[color=iic, no marks, domain=-0.1:8, samples=200] {(x>0)*(2*(1-exp(-x/\TT)) - \x/\TT*exp(-x/\TT))} node[coordinate, pin=-20:{$u_I(t)$}, pos=0.6] {};
      \addplot[color=ddc, no marks, domain=-0.1:8, samples=200] {(x>0)*(-\x/\TT*exp(-x/\TT))} node[coordinate, pin=-20:{$u_D(t)$}, pos=0.4] {};
    \end{axis}

 \end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}[label={sec:org586fa5e}]{The PID - practical form}
\definecolor{ppc}{rgb}{0.1,0.1,0.6}
\definecolor{iic}{rgb}{0.6,0.1,0.1}
\definecolor{ddc}{rgb}{0.1,0.5,0.1}

\begin{center}
  \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

    \node[coordinate] (input) {};
    \node[sumnode, right of=input, node distance=16mm] (sum) {\tiny $\Sigma$};
    \node[color=iic,block, right of=sum, node distance=28mm] (ii)  {$\frac{1}{\tau_is}$};
    \node[color=ppc, coordinate, above of=ii, node distance=10mm] (pp)  {};
    \node[color=ddc,block, below of=ii, node distance=13mm] (dd)  {$\frac{\tau_ds}{\frac{\tau_d}{N}s + 1}$};
    \node[sumnode, right of=ii, node distance=20mm] (sum2) {\tiny $\Sigma$};
    \node[block, right of=sum2, node distance=20mm] (gain)  {$k_c$};
    \node[coordinate, below of=sum, node distance=12mm] (feedback) {};
    \node[coordinate, right of=gain, node distance=20mm] (output) {};

    \draw[->] (input) -- node[above, pos=0.3] {$r(t)$} (sum);
    \draw[->] (sum) -- node[above, pos=0.2] {$e(t)$} node[coordinate] (mm) {}  (ii);
    \draw[->] (gain) -- node[above, near end] {$u(t)$} (output);
    \draw[->] (feedback) -- node[left, near start] {$y(t)$} node[right, pos=0.95] {-} (sum);
    \draw[->, color=ppc] (mm) |- (pp) -| node[right,] {$u_P(t)$} (sum2);
    \draw[->, color=ddc] (feedback |- dd) -- node[above, pos=0.95] {-} (dd);
    \draw[->, color=ddc] (dd) -| node[right,] {$u_D(t)$} (sum2)  ;
    \draw[->, color=iic] (ii)  -- node[above,] {$u_I(t)$} (sum2);
    \draw[->] (sum2) -- node[above, near end] {} (gain);

  \end{tikzpicture}
\end{center}

The parameter \(N\) is chosen to limit the influence of noisy measurements. Typically,
\[  3 < N < 10 \]
\end{frame}

\section{PID tuning - (Smith and Corripio) Ziegler Nichols}
\label{sec:orga158d8d}
\begin{frame}[label={sec:orgd1f6a5d}]{PID tuning}
\end{frame}
\begin{frame}[label={sec:org71a4d7d}]{Method by Smith \& Corripio using table by Ziegler-Nichols}
\small

Given process model (fitted to response of the system) \[ G(s) = K \frac{\mathrm{e}^{-s\theta}}{\tau s + 1} \] and PID controller
   \[ F(s) = k_c\left( 1 + \frac{1}{\tau_i s} + \tau_d s\right) \]
   Choose the PID parameters according to the following table (Ziegler-Nichols, 1943)
   \begin{center}
   \setlength{\tabcolsep}{20pt}
   \renewcommand{\arraystretch}{1.5}
   \begin{tabular}{llll}
   Controller & \(k_c\) & \(\tau_i\) & \(\tau_d\)\\
  \hline\hline
  P & \(\frac{\tau}{\theta K}\) &  & \\
  PI & \(\frac{0.9\tau}{\theta K}\) & \(\frac{\theta}{0.3}\) & \\
  PID & \(\frac{1.2\tau}{\theta K}\) & \(2\theta\) & \(\frac{\theta}{2}\)\\
  \hline
\end{tabular}
\end{center}

Gives good control for \[0.1 < \frac{\theta}{\tau} < 0.6.\]
\end{frame}

\section{SIMC}
\label{sec:org627d95f}

\begin{frame}[label={sec:org62fb5a1}]{SIMC-PID tuning rule}
[ SIMC stands for \emph{SIMple Control} or \emph{Skogestad Internal Model Control} ]
   \begin{center}
   \begin{tikzpicture}[node distance=22mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}scale=0.5, every node/.style={scale=0.5}]
  {
  \node[coordinate] (input) {};
  \node[sumnode, right of=input] (sum) {\tiny $\sum$};
  \node[block, right of=sum, node distance=2.6cm] (reg) {$F(s)$};
  \node[block, right of=reg, node distance=2.6cm] (plant) {$G(s)$};
  \node[coordinate, right of=plant, node distance=2cm] (output) {};
  \node[coordinate, below of=plant, node distance=12mm] (feedback) {};

  \draw[->] (plant) -- node[coordinate, inner sep=0pt] (meas) {} node[near end, above] {$y(t)$} (output);
  \draw[->] (meas) |- (feedback) -| node[very near end, left] {$-$} (sum);
  \draw[->] (input) -- node[very near start, above] {$r(t)$} (sum);
  \draw[->] (sum) -- node[above] {$e(t)$} (reg);
  \draw[->] (reg) -- node[above] {$u(t)$}(plant);
}
\end{tikzpicture}
\end{center}

Given model of the process and desired closed-loop system \[G(s) = K \frac{\mathrm{e}^{-s\theta}}{(\tau_1 s + 1)(\tau_2 s + 1)}, \quad \tau_1 \ge \tau_2; \qquad G_c(s) = \frac{\mathrm{e}^{-s\theta}}{\tau_c s + 1} \] Good robustness is obtained with PID controller

\[F(s) = K_c \left( \frac{ \tau_I s + 1}{\tau_I s} \right) (\tau_d s + 1)
= \frac{K_c(\tau_I + \tau_d)}{\tau_I} \left(1 + \frac{1}{(\tau_I + \tau_D) s} + \frac{\tau_I\tau_D}{\tau_I + \tau_D}s \right) \]
with
\[ K_c = \frac{\tau_1}{K(\tau_c + \theta)}, \qquad \tau_I = \min\{\tau_1, 4(\tau_c + \theta)\}, \qquad \tau_d = \tau_2 \]
\end{frame}
\end{document}


\documentclass[12pt]{article}
    \usepackage{mathtools}
    \usepackage[hidelinks]{hyperref}
    \usepackage{color}
    \usepackage{fancyref}
    \usepackage{lastpage}
    \usepackage{fancyhdr}

    \usepackage{pagecolor}
    % \pagecolor{black}
    % \color{white}

    \pagestyle{fancy}
    \fancyhf{}
    \fancyhead[LO]{TMA4140: Homework set 8}
    \fancyhead[RO]{Henry S. Sjøen \& Toralf Tokheim}
    \fancyfoot[CO]{\thepage\ of \pageref{LastPage}}

    \definecolor{darkred}{RGB}{200, 0, 0}

  \author{Henry S. Sjøen \& Toralf Tokheim}
  \title{
  \textbf{TMA4140 - Homework Exercise Set 8}}
\begin{document}
    \maketitle
    \thispagestyle{empty}
    \pagebreak
    \tableofcontents
    \pagebreak

    \section{Section 5.2}
    %  Obligatoriske: 4, 14; Anbefalte: 7, 19, 23
    \subsection{Exercise 4}
    Let $P(n)$ be the statement that a postage of $n$ cents can be formed using just 4-cent stamps and 7-cent stamps. The parts of this exercise outline a strong induction proof that $P(n)$ is $true$ for $n\geq 18$.\\

    \textbf{a)} Show statements $P(18),P(19),P(20)$ and $P(21)$ are $true$, completing the basis step of the proof.

    \begin{equation}
        \begin{split}
            P(n)=4a+7b=n\\
            P(18)=(4\times 1)+(7\times 2)=18\\
            P(19)=(4\times 3)+(7\times 1)=19\\
            P(20)=(4\times 5)+(7\times 0)=20\\
            P(21)=(4\times 0)+(7\times 3)=21\\
        \end{split}
    \end{equation}

    \textbf{b)} What is the inductive hypothesis of the proof?\\
    If for every i in $18 \leq i \leq k $, where $k \leq 21$, there is an "a" and "b" so that $i= 4a+7b$. Then there is an  "c" and "b" so that $k+1 = 4c+7d$ is \textit{true}.\\

    \textbf{c)} What do you need to prove in the inductive step?\\
    In the inductive step, we assume that the inductive hypothesis holds, and use that to prove $k+1$. \\

    \textbf{d)} Complete the inductive step for $k \geq 21$.\\
    For $k = 21$ then $P(k+1)$ should still be \textit{true}.
    \begin{equation}
        \begin{split}
                    P(k)=(4\times 0)+(7\times 3)=21\\
                    P(k+1)=4+(k-3)=(4\times 2)+(7\times 2)=22\\
        \end{split}
    \end{equation}
    \textit{True} for base step $P(21)$ and the first inductive step $P(22)$.\\

    \textbf{e)} Explain why these steps show that this statement is $true$ whenever $n\geq 18$.\\
    Since the base step and the inductive step are true, by the principle of strong induction all amount of postage where $n \geq 18$ can be obtained using only 4- and 7-cent stamps.

    % \subsection{Todo: Exercise 14}
    % Suppose you begin with a pile of $n$ stones and split this pile into $n$ piles of one stone each by successively splitting a pile of stones into two smaller piles.\\
    % Each time you split a pile you multiply the number of stones in each of the two smaller piles you form, so that if these piles have $r$ and $s$ stones in them, respectively, you compute $rs$. Show that no matter how you split the piles, the sum of the products computed at each step equals $n(n-1)/2$.

    \section{Section 5.3}
    %  Obligatoriske: 12, 18; Anbefalte: 13, 14, 15
    \subsection{Exercise 12}
    Prove that $f_1^2 +f_2^2 +\cdots+f_n^2 =f_nf_{n+1}$ when $n$ is a positive integer.
    \begin{equation}
        \begin{split}
                    f_{0} = 0\\
                    f_{1} = 1\\
                    \\
                    f_{2} = f_{1}+f_{0}=1+0=1 \\
                    f_{3} = f_{2}+f_{1}=1+1=2 \\
                    f_{4} = f_{3}+f_{1}=2+1=3 \\
        \end{split}
    \end{equation}

    \textbf{Base step:} \\
    $P(1)$ is true because $f_{1}^2 = f_{1}f_{1}$\\
    $= 1.1$\\
    $= 1$\\
    $= f_1*f_2$\\
    \\

    \textbf{Inductive step:}\\
    Assume that $P(k)$  is true.\\
    Show that $P(k+1)$ is true:
    \begin{equation}
        \begin{split}
              f_{1}^2 + f_{2}^2 + \cdots + f_k^2 + f_{k+1}^2 = f_k * f_{k+1} + f_{k+1}^2\\
            = f_k * f_{k+1} + f_{k+1} * f_{k+1}\\
            = f_{k+1} (f_k+f_{k+1})
            =f_{k+1} * f_{k+2}
        \end{split}
    \end{equation}
    Therefore, $P(k+1)$ is true. \\
    Hence by the principle of strong induction, we conclude that the statement is true. \\
    And therefor $f_1^2 +f_2^2 +\cdots+f_n^2 =f_nf_{n+1}$ is true.

    \subsection{Exercise 18}
    Let
    $ A =
    \begin{bmatrix}
        1 & 1 \\
        1 & 0
    \end{bmatrix}
    $,
    Show that
    $ A^n = \begin{bmatrix}
                    f_{n+1} & f_n\\
                    f_n & f_{n-1}
                    \end{bmatrix}
    $   when $n$ is a positive integer.

    Let $A=\begin{bmatrix}
    1&1\\
    1&0
    \end{bmatrix}$
    Let $P(n)$ be a statement that $A^n=\begin{bmatrix}
        f_{n+1}&f_{n}\\
        f_{1}&f_{1-1}
    \end{bmatrix}$

    \begin{equation}
        A^1= \begin{bmatrix}
            f_{2}&f_{1}\\
            f_{1}&f_{0}
        \end{bmatrix}\\
        =\begin{bmatrix}
            1&1\\
            1&0
        \end{bmatrix}
        = A
    \end{equation}
    A is true.\\
    Inductive step...
    Assume that $P(k)$ is true.
    i.e., $A^k=\begin{bmatrix}
    f_{k+1}&f_k\\
    f_k & f_k-1
    \end{bmatrix}$\\
    We have to prove that $P(k+1)$ is true.
    \begin{equation}
        \begin{split}
            A^{k+1}&=A.A^k\\
            &=\begin{bmatrix}
            1&1\\
            1&0
            \end{bmatrix}
            \begin{bmatrix}
            f_{k+1}& f_k\\
            f_k&f_{k-1}
            \end{bmatrix}\\
            &=\begin{bmatrix}
            1.f_{k+1}+1.f_k &1.f_{k}+1.f_{k-1}\\
            1.f_{k+1}+ 0.f_k & 1.f_k+0.f_{k-1}
            \end{bmatrix}\\
            &=\begin{bmatrix}
            f_{k+1}+f_k & f_{k-1}+f_k\\
            f_{k+1}+0 & f_{k}+0
            \end{bmatrix}\\
            &=\begin{bmatrix}
            f_{k+2} & f_{k+1}\\
            f_{k+1} & f_{k}
            \end{bmatrix}
        \end{split}
    \end{equation}
    Therefore $P(k+1)$ is \textbf{true}.\\
    And from the principle of mathematical induction we can conclude that the given statement is true.

    \section{Section 5.4}
    %  Obligatoriske: 3
    \subsection{Exercise 3}
    Trace Algorithm 3 when it finds $\gcd(8,13)$. That is, show all the steps used by Algorithm 3 to find $\gcd(8,13)$.

            \textbf{Input:} $\gcd(8, 13)$ \\
            \begin{equation}
                \begin{split}
                   since(8 < 13) &\\
                        \gcd(8, 13) &= \gcd(13 \textbf{mod} 8,8)\\
                        \gcd(8, 13) &= \gcd(5, 8) \\
                        \\
                   since(5 < 8) &\\
                        \gcd(5, 8) &= \gcd(8 \textbf{mod} 5,5)\\
                        \gcd(5, 8) &= \gcd(3, 5) \\
                        \\
                   since(3 < 5) &\\
                        \gcd(3, 5) &= \gcd(5 \textbf{mod} 3,3)\\
                        \gcd(3, 5) &= \gcd(2, 3) \\
                        \\
                   since(2 < 3) &\\
                        \gcd(2, 3) &= \gcd(3 \textbf{mod} 2,2)\\
                        \gcd(2, 3) &= \gcd(1, 2) \\
                        \\
                   since(1 < 2) &\\
                        \gcd(1, 2) &= \gcd(2 \textbf{mod} 1,1)\\
                        \gcd(1, 2) &= \gcd(0, 1) \\
                        \\
                   since(a = 0) &\\
                        \gcd(0, 1) &= 1\\
                        \gcd(8, 13) &= \textbf{1}
                \end{split}
            \end{equation}

    \section{Section 9.1}
    %  7, 40a, 40c (4, 28a, 28c); Anbefalte: 4, 25, 32
    \subsection{Exercise 7}
    Determine whether the relation $R$ on the set of all integers is \textit{reflexive}, \textit{symmetric}, \textit{antisymmetric}, and/or \textit{transitive}, where $(x,y) \in R$ if and only if\\
    \textbf{a)} $ x \neq y$.\\
        $R$ is \textbf{Not reflective}. $x \neq x$ can never be true\\
        $R$ is \textbf{symetric}, since if $x, y$ are integers and $ x \neq y$; then $ y \neq x$. \\
        $R$ is \textbf{not antisymetric}, as $1\neq 5$, $5 \neq 1$ while $1$ and $5$ are not the same.
        $R$ is \textbf{not transitive}, as $1\neq 5$, $5 \neq 1$ while $1 = 1$\\
        \\
    \textbf{b)} $ xy \geq 1$.\\
        $R$ is \textbf{not reflexive} \\
        $R$ is \textbf{symetric} \\
        $R$ is \textbf{not antisymetric} \\
        $R$ is \textbf{transitive} \\
        \\
    \textbf{c)} $ x=y + 1$ or $ x=y-1$.\\
        $R$ is \textbf{not reflexive} \\
        $R$ is \textbf{symetric} \\
        $R$ is \textbf{not asymetric} \\
        $R$ is \textbf{not transitive} \\
        \\
    \textbf{d)} $ x \equiv y (mod 7) $.\\
        $R$ is \textbf{reflexive} \\
        $R$ is \textbf{symetric} \\
        $R$ is \textbf{not asymetric} \\
        $R$ is \textbf{transitive} \\
        \\
    \textbf{e)} $ x $ is a multiple of $y$.\\
        $R$ is \textbf{reflective} \\
        $R$ is \textbf{not symmetric} \\
        $R$ is \textbf{not antisymetric} \\
        $R$ is \textbf{transitive} \\
        \\
    \textbf{f)} $ x $ and $y$ are both negative or both nonnegative.\\
        $R$ is \textbf{reflexitive} \\
        $R$ is \textbf{symmetric} \\
        $R$ is \textbf{not asymmetric} \\
        $R$ is \textbf{transitive} \\
        \\
    \textbf{g)} $ x=y^2 $.\\
        $R$ is \textbf{not reflexive} \\
        $R$ is \textbf{not symmetric} \\
        $R$ is \textbf{asymmetric} \\
        $R$ is \textbf{not transitive} \\
        \\
    \textbf{h)} $ x \geq y^2 $.
        $R$ is \textbf{not reflexive} \\
        $R$ is \textbf{not symmetric} \\
        $R$ is \textbf{asymmetric} \\
        $R$ is \textbf{transitive} \\
        \\

    \subsection{Exercise 40}
    Let $R_1$ and $R_2$ be the "divides" and "is a multiple of" relations on the set of all positive integers, respectively.\\
    That is, $R_1 = \{(a,b)|a $ divides $ b\}$ and $R_2=\{(a,b)|a$ is a multiple of $b\}$. Find...

    \subsubsection{Exercise 40.a}
    $R_1 \cup R_2$.\\
    An ordered pair $(a,b)\in R_1\cup R_2 $ if and only if $(a,b)\in R_1$ or $(a,b)\in R_2$.\\
    If $a$ divides $b$ for some integer $k$, $b=ka$.\\
    If $a$ is an multiple of $b$, then for some integer k,
    $b=\frac{1}{k}a $\\
    Therefore, $R_1 \cup R_2=\{(a,b)|b=ka$ or $ b=\frac{1}{k}a$, where $k$ is an integer.$\}$

    \subsubsection{Exercise 40.c}
    $R_1 - R_2$.\\
    An ordered pair $(a,b)\in R_1-R_2$ if and only if $(a,b)\in R_1$ and $(a,b)\notin R_2$.\\
    That is, if and only if \textit{a divides b} and \textit{a} is not a multiple of \textit{b}.\\
    Therefore,
    $R_1-R_2 = \{(a,b) | a$ is a proper divisor of $b \}$.

    \section{Section 9.3}
    %  10, 14a, 14b, 14c (6, 10a, 10b, 10c); Anbefalte: 15
    \subsection{Exercise 10}
    How many nonzero entries does the matrix representing the relation $R$ on $A=\{1,2,3,...,1000\}$ consisting of the first 1000 positive integers have if $R$ is...\\
    \textbf{a)} $\{(a,b) | A \leq b \}$?
    \begin{equation}
        \begin{split}
            \{(a,b) | A \leq b \}&=1000+999+998+\cdots + 2 + 1\\
            &=\frac{(1000)(1000+1)}{2}\\
            &=(500)(1001)\\
            &=500,500
        \end{split}
    \end{equation}

    \textbf{b)} $\{(a,b) | a=b \pm 1 \}$?
    \begin{equation}
        \begin{split}
            \{(a,b) | a=b \pm 1 \}&=1+2(998)+1\\
            &=1+1996+1\\
            &=1998
        \end{split}
    \end{equation}

    \textbf{c)} $\{(a,b) | a+b = 1000 \}$?
    \begin{equation}
        \begin{split}
            \{(a,b) | a+b = 1000 \}&=1+1+1+\cdots + 1(999)\\
            &=999
        \end{split}
    \end{equation}

    \textbf{d)} $\{(a,b) | a+b \leq 1001 \}$?
        \begin{equation}
            \begin{split}
            \{(a,b) | a+b \leq 1001 \} &=1000+999+998+\cdots+2+1\\
            &=\frac{(1000)(1000+1)}{2}\\
            &=(500)(1001)\\
            &=500,500
            \end{split}
        \end{equation}

    \textbf{e)} $\{(a,b) | a \neq 0 \}$?
        \begin{equation}
            \begin{split}
            \{(a,b) | a \neq 0 \}&=1000+1000+1000+\cdots + 1000+1000 (1000 times)\\
            &=(1000)(1000)\\
            &= 1,000,000
            \end{split}
    \end{equation}

    \subsection{Exercise 14}

    Let $R_1$ and $R_2$ be the relations represented by the matrices... \\
    $M_{R_1}=\begin{bmatrix}
        0 & 1 & 0\\
        1 & 1 & 1\\
        1 & 0 & 0
    \end{bmatrix}$ and $M_{R_2} = \begin{bmatrix}
        0 & 1 & 0 \\
        0 & 1 & 1 \\
        1 & 1 & 1
    \end{bmatrix}
    $\\
    Find the matrices that represent...
    \subsubsection{Exercise 14.a}
    $R_1 \cup R_2$
    \begin{equation}
        M_{R_1 \cup R_2} = \begin{bmatrix}
            0 & 1 & 0 \\
            1 & 1 & 1 \\
            1 & 1 & 1
        \end{bmatrix}
    \end{equation}

    \subsubsection{Exercise 14.b}
    $ R_1 \cap R_2 $.
    \begin{equation}
        M_{ R_1 \cap R_2}=
        \begin{bmatrix}
            0 & 1 & 0\\
            0 & 1 & 1\\
            1 & 0 & 0
        \end{bmatrix}
    \end{equation}

    \subsubsection{Exercise 14.c}
    $ R_2 \circ R_1$.
    \begin{equation}
       M_{R_2 \circ R_1}=
        \begin{bmatrix}
        0&1&1\\
        1&1&1\\
        0&1&0
        \end{bmatrix}
    \end{equation}
\end{document}


\subsection{Task 7: Triangle Counting}
According to the algorithms in \cite{tsourakakis2008fast}, we know that the number of triangles in a network is proportional to the sum of eigenvalue of its adjacency matrix, which is $\frac{\sum_{i}\lambda_{i}^{3}}{6}$. Figure \ref{t7:timedata} shows the running time of global triangle counting with regards to the size of graph. We can see that as the size of graph increases, the running time also grows nearly linearly with the size. For the largest graph, which is Roadnet-PA, it runs nearly for an hour to complete. However, the predicted result for Roadnet-PA is unsatisfactory. We conduct both global and local triangle counting, all the data is listed as follows.

\subsubsection{Detailed Plots}
{\bf Proof of Correctness: } In this experiment, we run our algorithm on the dataset, and verify that the predicted number of triangles is a good approximate of the true count. The full result is in Table \ref{t7:globalpredict}. As we can see, most of the result is near to each other. So we are aure about the correctness of the implementation.

Table \ref{t7:timedata} lists run time of global triangle counting. Figure \ref{t7:globaltime} plots the run time of global triangle counting on each dataset.

\begin{table}
\begin{center}
\begin{tabular}{ | c | c | }
    \hline
    graph size & run time(seconds) \\ \hline
    7115 & 45.199s \\ \hline
    36692 & 72.76 \\ \hline
    82168 & 596.046 \\ \hline
    334863 & 1288.703 \\ \hline
    1088092 & 2980.985 \\ \hline
\end{tabular}
\end{center}
\caption{Task 7 run time(global)}
\label{t7:timedata}
\end{table}

\begin{table}
\begin{center}
\begin{tabular} {| c | c | c | c | }
    \hline
    dataset & size & predict & truth \\ \hline
    wiki-Vite & 7115 & 661282 & 608389 \\ \hline
    Enron-email & 36692 & 756757 & 727044 \\ \hline
    slash-dot & 82168 & 635792 & 602592 \\ \hline
    Amazon-com & 334863 & 675778 & 667129 \\ \hline
    Roadnet-PA & 1088092 & 72134 & 67150 \\ \hline
\end{tabular}
\end{center}
\caption{Predicted triangle count(global)}
\label{t7:globalpredict}
\end{table}

% \begin{table}
% \begin{center}
% \begin{tabular} {| c | c | c | c | }
%     \hline
%     dataset & predict & truth \\ \hline
%     wiki-Vote & 661282 & 608389 \\ \hline
%     youtube & 3122234 & 3056386 \\ \hline
%     slashdot0922 & 631667 & 602592\\ \hline
%     com-DBLP & 2451225 & 2224385 \\ \hline
%     wiki-Talk & 9778534 & 9203519\\ \hline
% \end{tabular}
% \end{center}
% \caption{Predicted triangle count(global)}
% \label{t7:globalpredict}
% \end{table}

\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.6\textwidth]{FIG/t7_time.png}
\end{tabular}
\caption{Task 7: Run time VS graph size(global)}
\label{t7:globaltime}
\end{center}
\end{figure}

\subsubsection{Local triangle counting}
We plot the rank-frequency plot of local triangle counting, that x-axis represent the rank of the count of local triangle, y-axis represents the number of local triangles at that rank.

\paragraph{Amazon}
Figure \ref{t7:amazon} plots the rank-frequency of Amazon. We can observe from the figure that it follows {\bf power law}.
\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.4\textwidth]{FIG/t7_amazon.png}
\end{tabular}
\caption{Local triangle counting for Amazon}
\label{t7:amazon}
\end{center}
\end{figure}

\paragraph{Enron mail}
Figure \ref{t7:enron} plots the rank-frequency of Enron Mail. We can observe from the figure that it follows {\bf power law}.
\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.4\textwidth]{FIG/t7_enron.png}
\end{tabular}
\caption{Local triangle counting for Enron mail}
\label{t7:enron}
\end{center}
\end{figure}

\paragraph{Slashdot}
Figure \ref{t7:slashdot} plots the rank-frequency of Slashdot. We can observe from the figure that it follows {\bf power law}.
\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.4\textwidth]{FIG/t7_slashdot.png}
\end{tabular}
\caption{Local triangle counting for Slashdot}
\label{t7:slashdot}
\end{center}
\end{figure}

\paragraph{wiki-Vote}
Figure \ref{t7:wikivote} plots the rank-frequency of wiki-Vote. We can observe from the figure that it follows {\bf power law}.
\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.4\textwidth]{FIG/t7_wikivote.png}
\end{tabular}
\caption{Local triangle counting for wiki-Vote}
\label{t7:wikivote}
\end{center}
\end{figure}

\paragraph{Youtube}
Figure \ref{t7:youtube} plots the rank-frequency of Youtube. We can observe from the figure that it follows {\bf power law}.
\begin{figure}[!htbf]
\begin{center}
\begin{tabular}{c}
     \includegraphics[width=0.4\textwidth]{FIG/t7_youtube.png}
\end{tabular}
\caption{Local triangle counting for youtube}
\label{t7:youtube}
\end{center}
\end{figure}

% \begin{figure}[!htbf]
% \begin{center}
% \begin{tabular}{cc}
%      \includegraphics[width=0.4\textwidth]{FIG/t7_amazon.png} &
%      \includegraphics[width=0.4\textwidth]{FIG/t7_enron.png} \\
%      (a) & (b) \\
%      \includegraphics[width=0.4\textwidth]{FIG/t7_slashdot.png} &
%      \includegraphics[width=0.4\textwidth]{FIG/t7_wikivote.png} \\
%      (c) & (d) \\
%      \includegraphics[width=0.4\textwidth]{FIG/t7_youtube.png} & \\
%      (e)
% \end{tabular}
% \caption{Local triangle counting. (a) Amazon (b) Enron Mail (c) Slashdot (d) Wiki Vote (e) Youtube}
% \label{t7:local}
% \end{center}
% \end{figure}

\subsubsection{Observation}
We can see that the rank-frequency plot of local triangle count also follows {\bf power law}, it just matches our intuition. And we can observe that the run time grows nearly linearly with the graph size.


%!TEX root = ../../common/main.tex

\section{Decay time resolution and acceptance}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance}

In the following sections the parametrisation of the decay time resolution and
the model to describe the decay time acceptance are studied.

% ------------------------------------------------------------------------------
\subsection{Resolution}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance:resolution}

In this section the applicability of the \dtfpv output variable $\obsTimeError$ as
the per-event decay time error resolution estimate is checked and a model to
calibrate the estimate is developed. The model is determined in a two step
procedure. At first, different calibration models are tested using a binned fit
on the decay time resolution determined on data as a function of the resolution
estimate $\obsTimeError$. Then the found resolution model is used in an unbinned
likelihood fit to determine the calibration parameter values.

The study is performed on $\BdToJpsiKS$ candidates passing the pre-scaled
stripping line and the unbiased trigger lines only. The nominal selection is
applied, except the decay time cut at $\obsTime < \SI{0.3}{\pico\second}$, all
remaining candidates are considered irrespective of their tagging information.
Without cuts restricting the reconstructed decay time of the \Bd candidates, the
sample consists mainly of combinatorial background candidates promptly produced
at the \PV. As these candidates quasi decay instantaneously at $t = 0$ their
decay time distribution should give a proper handle on the decay time
resolution. A fit to the $\Jpsi$ candidate's reconstructed mass is applied to
get signal \sweights that are subsequently used in a weighted likelihood fit to
the reconstructed \Bd candidates' decay time distribution.

The $\Jpsi$ mass distribution is described by a \Ipatia \PDF (\cf
\cref{sec:measurement_of_sin2beta:likelihood_fit:pdfs:ipatia}) for the signal
component and an exponential \PDF for the background candidates. The fit is
performed on the reconstructed invariant dimuon mass $m_{\mumu}$ in a range from
$\num{3040}$ to $\SI{3155}{\MeVcc}$. The fitted distribution and the \PDF
projections split into the \catDD and \catLL categories are shown in
\cref{fig:measurement_of_sin2beta:resolution_and_acceptance:resolution:jpsi_mass}.
Although, the pion track types have no influence on the mass distribution of the
$\Jpsi$ candidates, the separation is justified by the different decay time
resolutions expected in these categories.
%
\begin{figure}[h]
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_mass_jpsi_dd.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_mass_jpsi_ll.pdf}
\caption{Invariant $\Jpsi$ candidates' mass distribution in the (left) \catDD
and (right) \catLL subsample. Data are shown in black, the projection of the
total \acs{PDF} as solid black line, the signal component described by a \Ipatia
\acs{PDF} as dashed blue line, and the exponential background component as
dotted green line.}
\label{fig:measurement_of_sin2beta:resolution_and_acceptance:resolution:jpsi_mass}
\end{figure}
%
Using a simultaneous fit in $\num{20}$ equally filled bins of the decay time
error prediction $\obsTimeError$ the width of the prompt peak in the decay time
distribution is fitted. This choice is based on the assumption that the decay
time resolution behaves alike for all candidates combined into one bin. As the
last bin is too wide, this assumption does not hold not any more, thus the last
bin is left out from then on. The fit model consists of two Gaussian \acp{PDF}
sharing a common mean parameter to model the prompt peak and two additional
decay \acp{PDF} as parametrisation of the non-prompt components. The decay \PDF
is convoluted with the same double-Gaussian \PDF used to model the prompt peak.
The two widths---one narrow and one wider---are then both employed in the
calibration.

For both widths a binned $\chisq$-fit of the $\num{19}$ per-bin parameter values
against the per-bin $\obsTimeError$ averages is performed. One linear and two
parabolic calibration models (with and without offset) are tested. For both
widths ($i = \{1,2\}$) as well as for both the \catDD and \catLL candidates the linear model
$\sigma^\prime(\obsTimeError) = c_i + b_i \obsTimeError$ describes the data at
least equally well \wrt the other parametrisations, such that the simpler model
is chosen in case of comparable results.
\Cref{fig:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration}
shows the calibration function for both track types and both Gaussian width
parameters.
%
\begin{figure}[h]
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_calibration_dd_narrow.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_calibration_dd_wide.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_calibration_ll_narrow.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/resolution_calibration_ll_wide.pdf}
\caption{Decay time error estimate calibration for (top) \catDD and (bottom)
\catLL candidates. Different calibration functions are fitted to the (left)
narrow and the (right) wide Gaussian width parameters. In green the linear
function $\sigma^\prime(\obsTimeError) = c_i + b_i \obsTimeError$ is shown, blue
and yellow describe the parabolic function with and without offset.}
\label{fig:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration}
\end{figure}
%
Results of the depicted fits are given in
\cref{tab:app:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration:dd,tab:app:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration:ll}
in \cref{sec:app:measurement_of_sin2beta:resolution_and_acceptance:resolution}.

Using the determined calibration model, the nominal decay time resolution model
is developed. An unbinned maximum likelihood fit to the \Bd decay time is
performed on the same $\Jpsi$ signal \sweighted dataset as described before
using the resolution model
%
\begin{equation}\label{eq:measurement_of_sin2beta:resolution_and_acceptance:resolution}
\begin{split}
  \Resolution{}{}\!\left(\obsTime;\obsTimeError\right)
  &= \sum_{i=1}^{2}{g_i\,\cdot\,\frac{1}{\sqrt{2\pi}(c_i + b_i \cdot \obsTimeError)}\exp\left(-\frac{(\obsTime - \mu_t)^2}{2(c_i + b_i \cdot \obsTimeError)^2}\right)}\\
  &+ f_{\text{PV}} \frac{1}{\sqrt{2\pi} \sigma_{\text{PV}}} \exp\left(-\frac{(\obsTime - \mu_t)^2}{2 \sigma_{\text{PV}}^2}\right) \eqpd
\end{split}
\end{equation}
%
The first two Gaussian components describe the prompt peak resolution, the third
component models the distribution of candidates associated to the wrong \PV.
Different calibration parameters $c_i$ and $b_i$ are chosen for the width of the
narrow ($i=1$) and the wide ($i=2$) Gaussian \PDF. The fractions $g_i$ add up to
unity together with the fraction $f_\text{\acs*{PV}}$ of candidates associated
to the wrong \PV. The offset $\mu_{\obsTime}$ of the Gaussian central value is
shared between all three Gaussian \acp{PDF}. Finally,
$\sigma_{\text{\acs*{PV}}}$ describes the width of the wrong \PV component. The
decay time distribution is modelled using two decay \acp{PDF} that are
convoluted with the resolution model
$\Resolution{}{}\!\left(\obsTime;\obsTimeError\right)$ and with pseudo-lifetimes
$\tau_{1,2}$.
\Cref{tab:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration:results}
lists the results that are used from now on in the decay time resolution model.
It is tested how the choice of the calibration model influences the measurement
using a \ToyMC study
(\cref{sec:measurement_of_sin2beta:systematics:systematics:resolution}).
%
\begin{table}[h]
  \centering
  \caption{Results of the fit of the parameters described in the decay time
  resolution model.}
  \label{tab:measurement_of_sin2beta:resolution_and_acceptance:resolution:calibration:results}
  \sisetup{
    table-number-alignment    = center,
    table-figures-integer     = 1,
    table-figures-decimal     = 5,
    table-figures-uncertainty = 5,
    table-sign-mantissa,
  }
  \begin{tabular}{llSS}
    \toprule
    \multicolumn{2}{c}{Parameter}       &   {\catDD sample}     &   {\catLL sample}   \\
    \midrule
    $\mu_t$             &   (\si{\ps})  &   -0.00291 +- 0.00026 & -0.00169 +- 0.00026 \\
    $b_{1}$             &               &    0.88    +- 0.09    &  1.04    +- 0.14    \\
    $c_{1}$             &   (\si{\ps})  &    0.0077  +- 0.0028  &  0.0045  +- 0.0028  \\
    $b_{2}$             &               &    1.33    +- 0.33    &  1.8     +- 0.4     \\
    $c_{2}$             &   (\si{\ps})  &    0.019   +- 0.008   &  0.007   +- 0.005   \\
    $g_{2}$             &               &    0.251   +- 0.020   &  0.24    +- 0.023   \\
    $\sigma_\text{PV}$  &   (\si{\ps})  &    1.6     +- 0.7     &  1.40    +- 0.14    \\
    $f_\text{PV}$       &               &    0.048   +- 0.004   &  0.0488  +- 0.0024  \\
    \midrule
    $\tau_1$            &   (\si{\ps})  &   0.7      +- 0.5     &  0.29    +- 0.06    \\
    $\tau_2$            &   (\si{\ps})  &   2.1      +- 1.3     &  1.82    +- 0.12    \\
    $f_1$               &               &   0.08     +- 0.10    &  0.046   +- 0.006   \\
    $f_2$               &               &   0.08     +- 0.11    &  0.079   +- 0.009   \\
    \bottomrule
  \end{tabular}
\end{table}

% ------------------------------------------------------------------------------
\subsection{Decay time acceptance}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance:acceptance}

Acceptance effects that alter the distribution of the decay time might result
from selection requirements or inefficiencies in the event reconstruction. This
section summarises acceptance effects stemming from lifetime biasing selection
cuts of trigger requirements (\cf
\cref{sec:measurement_of_sin2beta:data_preparation:trigger}) and reconstruction
inefficiencies mainly caused by the \VELO track reconstruction algorithms (\cf
\cref{sec:lhcb_experiment:tracking}).

% ..............................................................................
\subsubsection{Trigger induced decay time acceptance}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower}

The biased trigger lines (\cf
\cref{sec:measurement_of_sin2beta:data_preparation:trigger}) and the stripping
cut on the reconstructed decay time of the $\Bd$ candidates result in a non-flat
decay time acceptance.

In order to correctly describe these effects, the data sample is split into two
disjoint categories of candidates that show a substantially different behaviour
regarding their decay time acceptance. All candidates passing the \emph{almost
unbiased} (\textbf{\catAU}) trigger requirements show nearly no decay time
acceptance effects, in contrast to the sample of candidates passing the
\emph{exclusively biased} (\textbf{\catEB}) trigger requirements. The addressed
requirements are:
%
\begin{description}
  \item[\catAU] \TriggerReqAU
  \item[\catEB] \TriggerReqEB
\end{description}
%
To construct the acceptance in terms of ratios, a sample of candidates that pass
a set of unbiased trigger requirements is needed:
%
\begin{description}
  \item[Unbiased] \TriggerReqUB
\end{description}
%
The acceptance of the \catAU subsample can be computed using the overlap of
events which pass the biased and the unbiased \HLTTwo di-muon lines. Both
lines are using the same trigger cuts except for an additional cut on the flight
distance significance (see
\cref{tab:measurement_of_sin2beta:data_preparation:trigger:hlt2:cuts}) in the
case of the biased line. The acceptance can then be written as a time-dependent
efficiency $\varepsilon_\text{\catAU}$, with
%
\begin{align}
    \varepsilon_\text{\catAU} &= \frac{\text{\VerbAU\VerbAnd \HLTTwoDiMuonJpsi}}{\text{\VerbUB}}\\
                              &= \frac{\text{\TriggerReqAUEnumerator}}{\text{\TriggerReqUB}}\eqpd \nonumber
\end{align}
%
For the \catEB subsample, there is no corresponding reference sample available,
so strictly speaking only a relative efficiency can be computed. Nonetheless,
the ratio of the \catEB subsample and the unbiased subsample can be computed as
$\varepsilon_\text{\catEB}$.
%
\begin{align}
    \varepsilon_\text{\catEB} &= \frac{\text{\VerbEB}}{\text{\VerbUB}}\\
                              &= \frac{\text{\TriggerReqEB}}{\text{\TriggerReqUB}}\eqpd \nonumber
\end{align}
%
In other words $\varepsilon_\text{\catAU}$ quantifies the efficiency due to the
requirements by the biased \HLTTwo line for events that pass the unbiased
\HLTOne line, whereas $\varepsilon_\text{\catEB}$ effectively quantifies the
relative efficiency introduced by both, the \HLTOne and \HLTTwo, biased trigger
lines.

\subsubsection{Methodology}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower:methodology}

The data set for studying the trigger acceptance effects consists of all events
that are selected by the \StrippingDetached stripping line and pass the
offline selection. As the tagged and untagged candidates are expected to behave
equally concerning the studied effect all available candidates are used.
On the remaining multiple candidates, a random candidate selection is applied.
All candidates are selected by either one of the four considered trigger lines.

The efficiencies are time-dependent and, since the focus lies on the acceptance
of the signal component's decay time distribution, have to be determined through
a fit to separate signal from background. To do so, a simultaneous fit for the
signal yield is performed in ten bins of decay time. The bin boundaries are
chosen in a way that each bin contains the same number of events (before
splitting the data into the different fit categories). The fit is also performed
simultaneously in categories of track type, tagger, and both trigger sets given
by the numerators and the denominator of $\varepsilon_\text{\catAU}$ and
$\varepsilon_\text{\catEB}$. The yields for the different tagger and track type
categories are summed up (including error propagation). Then the efficiency per
time bin is calculated. For $\varepsilon_{\catAU}$ a binomial error is
estimated, while a Gaussian error propagation is used for
$\varepsilon_{\catEB}$.

In the mass fit, the signal peak is described by a \Ipatia \PDF, while a single
exponential is used to describe the combinatorial background.
\Cref{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower:mass_fits}
shows both mass distributions and fit projections for the biased and unbiased
sample, respectively. In both plots the sum over all categories is displayed.
%
\begin{figure}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/mass_trigger_efficiency_biased.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/mass_trigger_efficiency_unbiased.pdf}
\caption{Mass distribution and fit projection summed over all categories for
the (left) biased (\catAU and \catEB) and the (right) unbiased sample.}
\label{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower:mass_fits}
\end{figure}
%
\Cref{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower:splines}
shows the acceptance histograms for the \catAU and the \catEB sample. In the
nominal fit cubic splines \cite{Karbach:2014qba} are used instead of the
histograms themselves. Each bin centre is used as a knot for the splines. The
bin contents determine the shape of the splines. However, the bin contents
aren't fixed but constrained with a Gaussian function where the width is given
by the uncertainty on the bin content. As there is no information about the
acceptance at the decay time limits, the efficiency is assumed to be flat
between the lower decay time limit at \SI{0.3}{\ps} and the first bin
centre/knot and the last bin centre/knot and the upper decay time limit at
\SI{18.3}{\ps}, respectively.
%
\begin{figure}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/trigger_acceptance_spline_AU.pdf}
\includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/trigger_acceptance_spline_EB.pdf}
\caption{Histograms of the trigger acceptance for the (left) almost unbiased and
the (right) exclusively biased sample. The blue curve shows the fitted
acceptance using cubic splines.}
\label{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:lower:splines}
\end{figure}

% ..............................................................................
\subsubsection{Upper decay time acceptance}
\label{sec:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}

Due to a decrease in the \VELO reconstruction efficiency for tracks with a
larger offset to the beam line, a second decay time acceptance effect has to be
modelled. To account for this a correction factor $\beta_\tau$ is included into
the fit model by implementing the modified lifetime
%
\begin{equation}\label{eq:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}
  \widetilde{\tau} = \frac{\tau}{1 + \beta_\tau \tau} \eqpd
\end{equation}
%
The value of $\beta_\tau$ is determined using an unbinned fit to simulated data
while fixing the lifetime $\tau$ to its generation value. Based on the
\BdToJpsiKS signal \MC data set, only candidates passing the
\StrippingPrescaled stripping line and the unbiased trigger lines
\HLTOneDiMuonHighMass and \HLTTwoDiMuonJpsi are chosen to avoid any
additional lifetime bias for events with short decay times. Only candidates
being matched on \MC as true signal events are considered. The nominal offline
selection is applied and from the remaining multiple (\acs{PV},\,\Bd) candidate
pairs, one is chosen randomly. To avoid wrong-\acs{PV} associations of the
reconstructed \BdToJpsiKS candidate the true \MC decay time is used in the fit.
To reduce the statistical uncertainties, and as no deviations of the decay time
distributions are expected, all untagged events are included. The number of
remaining \MC candidates available for this study is roughly \num{60000}. Due to
differences in the reconstruction efficiency the factor $\beta_\tau$ is
determined separately for \catOO/\catOT and \catDD/\catLL events. The results
are collected in
\cref{tab:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}.
%
\begin{table}
  \centering
  \caption{Decay time correction factor $\beta_\tau$ in \si{\per\pico\second}.}
  \label{tab:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}
  \sisetup{
    table-number-alignment    = center,
    table-figures-integer     = 1,
    table-figures-decimal     = 4,
    table-figures-uncertainty = 4,
  }
  \begin{tabular}{cSS}
    \toprule
           & {2011}           & {2012} \\
    \midrule
    \catDD & 0.0036 +- 0.0029 & 0.0084 +- 0.0032 \\
    \catLL & 0.018  +- 0.004  & 0.035  +- 0.005  \\
    \bottomrule
  \end{tabular}
\end{table}

\subsubsection*{Influence of higher order effects}

\cref{eq:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}
expands to
%
\begin{equation}\label{eq:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper:linear}
\begin{split}
  \Prob{}{}\left(t\right) &= \exponential{-\frac{t}{\tau}\left(1+\beta_{\tau}\tau\right)} \\
                          &= \exponential{-\frac{t}{\tau}-\beta_{\tau}t} = \exponential{-\frac{t}{\tau}} \exponential{-\beta_{\tau}t} \\
                          &= \exponential{-\frac{t}{\tau}}\left(1-\beta_{\tau} t+\frac{\beta_{\tau}^2 t^2}{2}+\order{(\beta_{\tau} t)^3}\right).
\end{split}
\end{equation}
%
To check the influence of higher order terms, a quadratic correction function is
tested where the second order term has an own degree of freedom given by
$\gamma_\tau^\prime$,
%
\begin{equation}\label{eq:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper:quadratic}
  \Prob{}{}\left(t\right) = \exponential{-\frac{t}{\tau}}\left(1-\beta_\tau^\prime t+ \gamma_\tau^\prime t^2\right).
\end{equation}
%
Again the parameters $\beta_\tau^\prime$ and $\gamma_\tau^\prime$ are fitted
while fixing the lifetime $\tau$. In \cref{tab:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper:quadratic}
the results are listed for \catOO/\catOT and \catDD/\catLL events. To visualise
the effect, the per-bin ratio of the decay time distributions of signal \MC
events to events generated from \ToyMC is calculated and shown in
\cref{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}.
The \ToyMC decay time distribution follows an exponential function with the same
lifetime as used in the generation of the signal \MC. As the uncertainties on
$\beta_\tau^\prime$ and $\gamma_\tau^\prime$ are large and the parameters are
strongly correlated ($\rho>\SI{90}{\percent}$), the linear model is selected. A
possible bias due to this choice is investigated in
\cref{sec:measurement_of_sin2beta:systematics:systematics:acceptance}.
%
\begin{table}
  \centering
  \caption{Decay time correction factors $\beta_\tau^\prime$ (in
  \si{\per\pico\second}) and $\gamma_\tau^\prime$ (in
  \si{\per\square\pico\second}).}
  \label{tab:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper:quadratic}
  \sisetup{
    table-number-alignment    = center,
    table-figures-integer     = 1,
    table-figures-decimal     = 3,
    table-figures-uncertainty = 3,
    table-sign-mantissa,
  }
  \begin{tabular}{
    c
    S
    S[
    table-figures-decimal     = 4,
    table-figures-uncertainty = 4,
    ]
    S
    S[
    table-figures-decimal     = 4,
    table-figures-uncertainty = 4,
    ]
  }
    \toprule
           & \multicolumn{2}{c}{2011}                          & \multicolumn{2}{c}{2012}                        \\
           & {$\beta_\tau^\prime$}  & {$\gamma_\tau^\prime$}   & {$\beta_\tau^\prime$}  & {$\gamma_\tau^\prime$} \\
    \midrule
    \catDD & -0.016 +- 0.007        & -0.0030 +- 0.0008        & -0.001 +- 0.007        & -0.0014 +- 0.0009      \\
    \catLL & -0.001 +- 0.009        & -0.0028 +- 0.0012        &  0.01  +- 0.06         & -0.0027 +- 0.0008      \\
    \bottomrule
  \end{tabular}
\end{table}
%
\begin{figure}
  \includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/velo_acceptance_11_DD.pdf}\hfill
  \includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/velo_acceptance_11_LL.pdf}
  \includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/velo_acceptance_12_DD.pdf}\hfill
  \includegraphics[width=0.49\textwidth]{private/content/measurement-of-sin2beta/figs/velo_acceptance_12_LL.pdf}
\caption{
Decay time ratio in bins of decay time for (left/right) \catDD/\catLL and
(top/bottom) \catOO/\catOT. The blue (red) curve shows a linear (quadratic) fit
to the data points.}
\label{fig:measurement_of_sin2beta:resolution_and_acceptance:acceptance:upper}
\end{figure}


\section{Exploring Errors}

%Introduction
\begin{frame}{Exploring Errors}
\begin{itemize}
    % \item After building and understanding all three of our models, we began to explore the errors associated with them
    \item Our definition of error:

    \begin{align*}
        \mbox{error} = \frac{||v_{observed} - v_{predicted}||}{||v_{observed}||}
    \end{align*}
    \item While this is not the only metric we used (we also used error square and angular velocity error), this was our primary one
    % \item In the following slides, we will present some of the experiments we conducted to better understand and reduce predictive error from the models

\end{itemize}

\end{frame}

%Experiment 1: Errors and Positions
%\subsection{Experiment 1: Errors and Positions}
\begin{frame}{Experiment 1: Errors and Position}
    \begin{itemize}
        \item Question: Could measurement errors in position and velocity explain the difference between our $v_{predicted}$ and the $v_{observed}$
        \item To this end, we began to iteratively change the measured x and y COM and contact positions of the ellipse by a percentage
    \end{itemize}

    \begin{figure}[!htb]
    \minipage{0.32\textwidth}
      \includegraphics[width=\linewidth]{figures/changeInXPos.jpg}
      \caption{Changing the contact x position in Wang}
      \label{fig:awesome_image1}
    \endminipage\hfill
    \minipage{0.32\textwidth}%
      \includegraphics[width=\linewidth]{figures/errorVsOptMethod.png}
      \caption{Changing the contact x position in IRB}
      \label{fig:awesome_image3}
    \endminipage\hfill
    \minipage{0.32\textwidth}
      \includegraphics[width=\linewidth]{figures/trial900.jpg}
      \caption{Changing the angle of the ellipse in IRB}
      \label{fig:awesome_image2}
    \endminipage
    \end{figure}

\end{frame}

\begin{frame}{Experiment 1: Errors and Position}
Findings: across all three models, changing by a percentage the positions of the ellipse had a big impact on the accuracy of the results \\
\vspace{\baselineskip}
In general, this is what we saw:
    \begin{itemize}
        \item The measured position already gave a small error (few cases)
        \item Changing the measured position by a little bit gave a large drop in error (most cases)
        \item Changing the measured position by a lot to give a noticeable drop in error (few cases)
    \end{itemize}
\vspace{\baselineskip}
Conclusion: the data we were provided is not completely accurate!

\end{frame}

%Experiment 2: Errors and Moments
%\subsection{Experiment 2: Errors and Moments}
\begin{frame}{Experiment 2: Errors and Impact Angle}
At first, we were able to find a relationship between the error and the impact angle.

    \begin{itemize}
%        \item The pre-impact angle is related to both the moment arm and the geometry of the ellipse, which in turn directly affects the torque resulting from the impulse pair
        \item After running our models, we saw a relation between impact angles and the normalized errors (AP and Classic IRB)
        %\item For IRB with torque, the average width (the error offset) was also related to the impact angle.
    \end{itemize}
\vspace{0.5\baselineskip}
Which means that Some impact angles prevented some of the models from accurately predicting the post-impact states.

    \vspace{0.5\baselineskip}
     We will be exploring HOW that link came to be in later slides, but we are still unsure of WHY exactly the models systematically mispredict at certain angles.
\end{frame}

\begin{frame}{Experiment 2: Errors and Impact Angle}

 \begin{figure}
 \centering
        \includegraphics[scale=0.12]{figures/IRBWidthAngle.jpg}
        \caption{IRB With Torque}
        \label{fig:IRBAngle}
\end{figure}
\vspace{-1\baselineskip}

\begin{itemize}
    \item Width can be interpreted as Error
    \item We can see that peaks here occur around -110, -60, 60, 110

\end{itemize}

\end{frame}

\begin{frame}{Experiment 2: Errors and Impact Angle}
\begin{itemize}
    \item Does this trend extend to other models we have looked at?
\end{itemize}

\begin{figure}
    \centering
    \quad
    \begin{subfigure}[b]{0.45\linewidth}
        \includegraphics[scale=0.11]{figures/APAngleVsError.jpg}
        \caption{AP Poisson}
        \label{fig:AP_angle}
    \end{subfigure}
    \quad
    \begin{subfigure}[b]{0.45\linewidth}
        \includegraphics[scale=0.11]{figures/CIRBAngleVsError.jpg}
        \caption{Classical IRB}
        \label{fig:WangAngle}
    \end{subfigure}
\end{figure}
\vspace{-1\baselineskip}

\begin{itemize}
    \item The answer is, kind of!
\end{itemize}

\end{frame}

% \begin{frame}{The Link}

% Overall, this is the link that we have observed between all of our variables
% \vspace{0.5\baselineskip}

% %NEEDS INFO CHECK TO MAKE SURE THIS IS CORRECT

% \begin{itemize}
%     \item  Experiment 3 ($\Delta \dot \theta$ and Impact Angles) - At specific angles, the change in angular velocity is greater than at others. $\Rightarrow$
%     \item Experiment 4 ($\Delta \dot \theta$ and Torque) - There is a smaller change in angular velocity at certain angles because at those angles the resultant torque is smaller. $\Rightarrow$
%     \item Experiment 5 ($\Delta \dot \theta$ and Errors) - The smaller the change in angular velocity, the greater the prediction error. $\Rightarrow$
%     \item  Experiment 6 (Moments and Errors) - The smaller the Torque, the greater the prediction error.
% \end{itemize}

% \vspace{0.25\baselineskip}
% %\begin{itemize}
%         %\item In summary: pre-impact angle is related to both the moment arm and the geometry of the ellipse, which in turn directly affects the torque resulting from the impulse pair
%         In summary: At specific angles, there are smaller resultant torques, and at these smaller resultant torques, the prediction error of the IRB model is greater.
%     %\end{itemize}

% \end{frame}

%Experiment 3: Impact angles and Change in angular velocity
\begin{frame}{Experiment 3: $\Delta \dot \theta$ and Impact Angles}

\begin{itemize}
    \item We expected the ellipse to have a greater change in angular velocity if it didn't fall right on its center of mass.
    \item The greater the moment arm, the greater the change in angular velocity.
\end{itemize}
\begin{figure}
    \centering
    \includegraphics[scale=0.12]{figures/impact angle vs change in angular velocity.jpg}
    \caption{All moments vs Error}
    \label{fig:MomentsError}
\end{figure}
\item At around -110, 60, 110 the change in angular velocity is close to 0.
\end{frame}

%Experiment 4: Change in angular velocity and Torque
\begin{frame}{Experiment 4: $\Delta \dot \theta$ and Torque}
%this kind of ties in to the previous slide/it's already been said that greater change in angular velocity leads is related to greater moment/torque so maybe just delete this one?

\begin{figure}
    \centering
    \includegraphics[scale=0.21]{figures/AngularVvsMoment.jpg}
    \caption{Classic IRB: Change in Angular Velocity vs Total Moment}
    \label{fig:MomentsError}
\end{figure}

\end{frame}

%Experiment 5: Link between angular velocity and error
\begin{frame}{Experiment 5: $\Delta \dot \theta$ and Errors}

\begin{figure}
    \centering
    \includegraphics[scale=0.17]{figures/changeInOmegaEllipse.jpg}
    \caption{Classic IRB: Change in Angular Velocity vs Error}
    \label{fig:AngularVError}
\end{figure}
\end{frame}

%The important part about this slide is the idea of overcompensation. The width isn't just helping adjust for changes in angular velocity that are too large for the IRB to predict and need more torque.... It is allowing for the IRB to change the impulses and create large torques/changes in omega which the width can then cancel out potentially

%Experiment 6: Link between Moments and Error [editttttttt]
\begin{frame}{Experiment 6: Moments and Errors}

% Since a greater angular velocity change led to a smaller error, and the angular velocity change is directly related to the net torque, As a sanity check, we graphed the net torque vs the normalized error hoping to see the same trend.

%\vspace{0.25\baselineskip} [PRESENTATION NOTES]
%The difference between these next 2 plots is the magnitude of the normalized error. IRB torque has a minor error magnitude compared to the classical model, because the compression width applies a moment to "Correct" the angular velocity.

\begin{figure}
    \centering
    \quad
    \begin{subfigure}[b]{0.4\linewidth}
        \includegraphics[scale=0.105]{figures/IRB Classic Net torque vs error.jpg}
        \caption{Net Torque vs Error}
        \label{fig:AP_angle}
    \end{subfigure}
    \quad
    \begin{subfigure}[b]{0.5\linewidth}
        \includegraphics[scale=0.13]{figures/MomentProp2.jpg}
        \caption{IRB Moment vs Torque}
        \label{fig:MomentIRB}
    \end{subfigure}
\end{figure}

\end{frame}

\begin{frame}{The Link}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=2.5cm, minimum height=1.75cm, text centered, text width = 4cm, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{tikzpicture}[node distance=2cm]

\node (exp2) [startstop, xshift = 3.5cm, yshift = 11cm] {\textbf{Experiment 2:} \\ Error is maximized at specific angles};
\node (exp3) [startstop, xshift = 7.25cm, yshift = 8.5 cm] {\textbf{Experiment 3:} \\ $\Delta \dot \theta$ is min at these angles};
\node (exp4) [startstop, xshift = 6.35cm, yshift = 6cm] {\textbf{Experiment 4:} \\  $\Delta \dot \theta$ decreases as the res. torque decreases};
\node (exp5) [startstop, xshift = 0.65cm, yshift = 6cm] {\textbf{Experiment 5:} \\ $\Delta \dot \theta$ decreases as prediction error increases};
\node (exp6) [startstop,xshift = 0.25cm, yshift = 8.5cm] {\textbf{Experiment 6:} \\ Therefore as torque decreases, error increases};

\draw [arrow] (exp3) -- (exp4);
\draw [arrow] (exp4) -- (exp5);
\draw [arrow] (exp5) -- (exp6);
\draw [arrow] (exp6) -- (exp2);
\draw [arrow] (exp2) -- (exp3);

\end{tikzpicture}
\end{frame}


\documentclass{article}
\usepackage{graphicx}
\usepackage{amssymb}
\graphicspath{{figures/}}
\DeclareGraphicsRule{*}{mps}{*}{}

\usepackage{color}
\newcommand{\red}[1]{{\color{red} #1}}

\begin{document}
\section{Increasing numbers}
The graphs are generated by a sequence of numbers $\alpha_i\in\mathbb{Z}$ appearing in random (not sorted) order from left to right.
\[\{\alpha_1,...,\alpha_n\}\]
We set $s=\alpha_1$ and $t=\alpha_n$. Odd numbers are red.
Two numbers $\alpha_i,\alpha_j$ are connected if:
\begin{itemize}
\item $i<j$
\item $\alpha_i<\alpha_j$
\end{itemize}
The edges are directed from the smaller to the larger number.
Some examples:
\begin{figure}[h]
  \centering
\includegraphics{increase_n8_1.0}
  \caption{increase_n8_1, n=8}
\end{figure}
\begin{figure}[h]
  \centering
\includegraphics{increase_n8_2.0}
  \caption{increase_n8_2, n=8}
\end{figure}
\begin{figure}[h]
  \centering
  \includegraphics{increase_n8_3.0}
  \caption{increase_n8_3, n=8}
\end{figure}

\end{document}


\begin{appendix}

\chapter{Algorithm for balancing lookup tables train set}\label{Chapter:results}

Since the dataset for the lookup tables is small -- even if length 2 compositions was created using tables \textit{t1} to \textit{t8}, there could only be 64 compositions which would bijectively map 8 \lq  3 bit inputs to 3 bit outputs\rq{} thereby leading to a total of 512 samples only -- we try to ensure that the compositions present in the training data are uniformly distributed while simultaneously keeping the distribution of the output strings in the training data uniform as well. This ensures that the model doesn't get biased towards any particular composition or an output string. As has been explained in section \ref{lt:splits}, the heldout inputs set is created by randomly taking out 2 inputs for each of the 28 compositions in training. Therefore the resultant training set should have the following properties:
\begin{itemize}
	\item The total number of data points  $= 28*6 = 168$.
	\item There are 8 outputs. The total number of compositions that lead to a particular output $=168/8 = 21$.
\end{itemize}

.
\begin{algorithm}
	\caption{Create training with uniform distribution of both compositions and outputs}
	\begin{algorithmic}
		\STATE We start with 28 compositions with 8 inputs each.
		\STATE Create an empty dataframe of dimension (21,8) with the 8 output strings as it's columns.
		\STATE Create a dictionary Y with compositions as it's keys and values=0.
		\FOR {i in range [0, 21)}
		\FOR {output in dataframe column}
		\STATE Sample composition
		\IF{composition \textbf{not in} row[i] AND composition \textbf{not in} output column AND Y[composition] $<$ 21 }
		\STATE dataframe[i][output] = composition
		\STATE Y[composition] += 1
		\ELSE
		\STATE continue
		\ENDIF
		\ENDFOR
		\ENDFOR
	\end{algorithmic}
\end{algorithm}

\end{appendix}


%
% Complete documentation on the extended LaTeX markup used for Insight
% documentation is available in ``Documenting Insight'', which is part
% of the standard documentation for Insight.  It may be found online
% at:
%
%     http://www.itk.org/

\documentclass{InsightArticle}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  hyperref should be the last package to be loaded.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[dvips,
bookmarks,
bookmarksopen,
backref,
colorlinks,linkcolor={blue},citecolor={blue},urlcolor={blue},
]{hyperref}
% to be able to use options in graphics
\usepackage{graphicx}
% for pseudo code
\usepackage{listings}
% subfigures
\usepackage{subfigure}

%  This is a template for Papers to the Insight Journal.
%  It is comparable to a technical report format.

% The title should be descriptive enough for people to be able to find
% the relevant document.
\title{Parallel algorithms for erosion and dilation of label images.}

\newcommand{\IJhandlerIDnumber}{3399}

% Increment the release number whenever significant changes are made.
% The author and/or editor can define 'significant' however they like.
\release{0.00}

% At minimum, give your name and an email address.  You can include a
% snail-mail address if you like.
\author{Richard Beare{$^1$} {\small and} Paul Jackway{$^2$}}
\authoraddress{Richard.Beare@monash.edu\\Department of Medicine\\Monash University\\Melbourne\\Australia{$^1$}\\CSIRO Mathematics Informatics and Statistics\\Dutton Park\\Queensland\\Australia{$^2$}}

\begin{document}

\IJhandlefooter{\IJhandlerIDnumber}

\maketitle

\ifhtml
\chapter*{Front Matter\label{front}}
\fi

\begin{abstract}
\noindent
It is sometimes useful to be able to apply binary morphological
operations, such as erosions and dilations, to labelled images in a
fashion that preserves the labels. This article introduces a
specialised class implementing parallel methods described in
\cite{beare2011parallel} that provide very fast dilations by circles
and spheres of arbitary size. Comparisons with other implementations
using currently available building blocks are also made.
\end{abstract}
\IJhandlenote{\IJhandlerIDnumber}
\tableofcontents

\section{Introduction}
The link between Euclidean distance transforms and binary
morphological operations is well known - erosions and dilations by
circles and spheres can be performed by thresholding the distance
transform. Efficient and readily parallelizable distance transform
algorithms can, in turn, be based on erosions and dilations by
parabolic structuring elements. The classes outlined in this article
extend the contact point algorithm used for parabolic erosions and
dilations to facilitate operations on label images. A more complete
discussion is available in \cite{beare2011parallel}. The classes
introduced here are able to separate touching labels during erosion
and split touching labels at the midpoint during dilation.

\section{The classes}
The {\em itk::LabelSetDilateImageFilter} and {\em
  itk::LabelSetErodeImageFilter} implement dilation and erosion of
label images. They share a common parent class. The methods controlling class behaviour are:
\begin{itemize}
\item {\em UseImageSpacing}: Defines whether the radius refers to voxels or world dimensions. Default is false, meaning radius is in voxels.
\item {\em Set/GetRadius}: Set the size of the dilation or erosion. There are versions to set the size in all directions to be the same, corresponding to a circular or spherical structuring element, and independently, corresponding to an ellipsoid structuring element (with axes parallel to image axes).
\end{itemize}

Examples of use are available with the package.

Please note that these are specialised classes which cannot use
arbitrary structuring elements.

The code from this contribution is also available at
\url{https://github.com/richardbeare/LabelErodeDilate}.

\subsection{Notes for label erosion}
The class provided for label erosion {\bf will separate} touching
labels. If this is not the desired behaviour, then implement label
erosion via binary erosion and masking.

\section{Alternative approaches to label dilation}
As advised on the ITK mailing list, label dilation can be implemented
via distance transforms and watershed transforms. This algorith is
illustrated in SimpleITK python code below (courtesy of Bradely
Lowekamp):

\lstset{language=Python}
\begin{lstlisting}
def MultilabelDilation(img, radius=1,kernel=sitk.BinaryDilateImageFilter.Ball):
    distImg = sitk.SignedMaurerDistanceMap(img != 0,
                                           insideIsPositive=False,
                                           squaredDistance=False,
                                           useImageSpacing=False)
    dilatImg = sitk.BinaryDilate(img!=0, radius, kernel)
    wsImg = sitk.MorphologicalWatershedFromMarkers(distImg, img)
    return dilatImg*wsImg
\end{lstlisting}

There are a couple of altnernatives to this algorithm implemented in
C++ and provided in {\em multilabelDilation.h}. The first version is a
variant of the code above, which avoids using the binary dilate
operation and thresholds the distance transform instead. This version
is called {\em multilabelDilation}. The second version uses the {\em
DanielssonDistanceMapImageFilter} to produce both a distance map and a
Voronoi tesselation. The distance map is thresholded to produce a
dilation which is then used to mask the Voronoi tesselation. This
version is called {\em multilabelDilationDanielsson}. The Danielsson
filter is slower than the Maurer filter, but this approach avoids the
watershed transform step as the information provided by the Voronoi
map is removes the need for the watershed. Comparisons of performance
are below.

\subsection{Problems with the watershed approach}
It turns out that the distance transform followed by watershed
transform approach to label dilation only works reliably for smaller
dilations, say 10. For larger dilations there is a chance of regions
leaking across borders and becoming incorrect. Leaks of this kind
result from the nature of propagation in the border zone combined with
tied distance values. The test image {\em vCenters10.mha} demonstates
this issue.

\subsection{Dilations via distance maps versus binary dilation}
There are subtle differences between the effective structuring element
produced when thresholding distance maps versus those provided by the
{\em BinaryBallStructuringElement}. The latter is a Bresenham circle
or sphere, which means that any voxel which is partly inside the
specified radius is included in the structuring elements. Distance
maps, on the other hand, typically compute distances to voxel
centres. Thus any voxel whos centre is closer than the specified
radius is included, resulting in a slightly smaller structuring
element.

In addition, the parabolic dilation used in the LabelDilate tool
treats voxels with centres exactly the dilation radius from the seed
as ``outside''. This results from the optimized use of the contact
point algorithm to avoid computation of a complete distance
transform. There may be some fudge factors that can be added to avoid
this behaviour, which will be investigated in the future.

\subsection{Other differences}
There are minor differences in results obtained from the Danielsson
approach and the new approach discussed here. Some of those
differences are along boundaries. My investigations suggest that the
Danielsson approach is wrong in these cases. Explicit calculation of
the distance between the locations of seeds and differences in
labelling indicate that the points are incorrectly labelled by the
Danielsson approach. The {\em reportNonZero} tool and {\em check.R}
functions were used to investigate these problems.

\section{Performance}
The specialised version was developed due to ease of parallel
implementation and performance results show that it is indeed much
faster than versions that can be built using existing tools. It also
scales moderately well with increased execution threads. The execution
times and speedups for a 12 core Intel(R) Xeon(R) CPU X5650 @ 2.67GHz
on a $182 \times 218 \times 182$ brain atlas are shown in Figures
\ref{fig:exec}. None of the methods have a
significant dependence on dilation size, as the structuring element is
not explicit. Speedup at 8 cores for the Maurer method is 1.86
versus 4.71 for the parabolic method. The lack of scalability of the
Maurer method is likely to be largely caused by the watershed step,
which is not parallel. The Danielsson approach is much slower, despite
avoiding the need for an explicit watershed transform. There is some
redundancy in the Maurer approach, as a signed distance transform is
computed by not used. In the single threaded the specialised version
is 7 times faster than the Mauer approach and 180 times faster than
the Danielsson-based method.

\begin{figure}[htbp]
\centering
\includegraphics[scale=0.35]{exectimes}
\includegraphics[scale=0.35]{speedups}
\caption{Execution times and speedups for all methods.\label{fig:exec}}
\end{figure}

\section{Sample results}
Label images occur in many situations. This is an example of a brain
atlas in which different labels represent different anatomical
regions. Examples of 2D processing (operations applied to a single
slice of the atlas) are shown in Figure \ref{fig:2d}. Examples of a 3D
processing are shown in Figures \ref{fig:3dorig} to \ref{fig:3ddil}.

\begin{figure}[htbp]
\centering
\includegraphics[scale=0.75]{axial_color}
\includegraphics[scale=0.75]{laberode2d_color}
\includegraphics[scale=0.75]{labdilate2d_color}
\caption{Original, eroded and dilated atlases - a single slice with a 2d circular structuring element.\label{fig:2d}}
\end{figure}

\begin{figure}[htbp]
\centering
\includegraphics[scale=0.15]{atlas_orig}
\caption{Axial, sagittal and coronal slices through a labelled brain atlas.\label{fig:3dorig}}
\end{figure}

\begin{figure}[htbp]
\centering
\includegraphics[scale=0.15]{atlas_erode_color}
\caption{Atlas in Figure \ref{fig:3dorig} after applying 3d labelled erosion. \label{fig:3dero}}
\end{figure}

\begin{figure}[htbp]
\centering
\includegraphics[scale=0.15]{atlas_dilate_color}
\caption{Atlas in Figure \ref{fig:3dorig} after applying 3d labelled dilation. \label{fig:3ddil}}
\end{figure}

\section{Conclusion}
This article provides two classes for erosions and dilations of label
images using algorithms developed in a previously published
work. These methods use parallel, scan-line base algorithms that offer
very fast operations.
\bibliographystyle{plain}
\bibliography{local,InsightJournal}
\nocite{ITKSoftwareGuide}

\end{document}


\subsubsection{\stid{3.06} PETSc-TAO} \label{subsubsect:petsc}
\paragraph{Overview}

Algebraic solvers (generally nonlinear solvers that use sparse linear solvers) and integrators form the
core computation of many numerical simulations. No scalable ``black box'' sparse solvers or integrators
work for all applications, nor are there single implementations that work well for all problem sizes.
Hence, algebraic solver and integrator packages provide a wide variety of algorithms and implementations
that can be customized for the application and range of problem sizes. PETSc/TAO~\cite{petsc:homepage,petsc-man}
is a widely used numerical library for the scalable solution of linear, nonlinear, and variational systems,
for integration of ODE/DAE systems and computation of their adjoints, and for numerical optimization.
This project focuses on three topics: (1) partially matrix-free scalable solvers to efficiently use
many-core and GPU-based systems; (2) reduced synchronization algorithms that can scale to larger
concurrency than solvers with synchronization points; and (3) performance and data structure
optimizations for all the core data structures to better utilize many-core and GPU-based
systems as well as provide scalability to the exascale systems.

The availability of systems with over 100 times the processing power of today's machines compels the utilization
of these systems not just for a single ``forward solve'' (as discussed above), but rather within a tight loop
of optimization, sensitivity analysis (SA), and uncertain quantification (UQ). This requires the implementation
of a new scalable library for managing a dynamic hierarchical collection of running scalable simulations, where
the simulations directly feed results into the optimization, SA, and UQ solvers.  This library, which we call
libEnsemble, directs the multiple concurrent ``function evaluations'' through the tight coupling and
feedback. This work consist of two parts: (1) the development of libEnsemble; and (2) the development
of application-relevant algorithms to utilize libEnsemble.

\paragraph{Key Challenges}

A key challenge for scaling the PETSc/TAO numerical libraries to Exascale systems is that traditional
``sparse-matrix-based'' techniques for linear, nonlinear, and ODE solvers, as well as optimization
algorithms, are memory-bandwidth limited.  Another difficulty is that any synchronizations
required across all compute units---for example, an inner product or a norm---can
dramatically affect the scaling of the solvers.  Another challenge is the need to
support the variety of accelerators that will be available on the exascale systems
and the programming models that application teams use for performance
portability.

Running an ensemble of simulations requires a coordination layer that handles load balancing and
allows the collection of running simulations to grow and shrink based on feedback. Thus, our
libEnsemble library must be able to dynamically start simulations with different parameters,
resume simulations to obtain more accurate results, prune running simulations that the solvers
determine can no longer provide useful information, monitor the progress of the simulations,
and stop failed or hung simulations, and collect data from the individual simulations both
while they are running and at the end.

\paragraph{Solution Strategy}

To address the scalability of the numerical libraries, we implemented new solvers and data
structures including: pipeline Krylov methods that delay the use of the results of inner
products and norms, allowing overlapping of the reductions and other computation; partially
matrix-free solvers using high-order methods that have high floating-point-to-memory-access
ratios and good potential to use many-core and GPU-based systems; and in-node optimizations
of sparse matrix-matrix products needed by algebraic multigrid to better utilize many-core
systems.

Our strategy for coordinating ensemble computations has been to develop libEnsemble
to satisfy our needs.  This library should not be confused with workflow-based
scripting systems; rather it is a library that, through the tight coupling and
feedback, directs the multiple concurrent ``function evaluations'' needed by
optimization, SA, and UQ solvers.

\paragraph{Recent Progress}

In the past year, we have released PETSc/TAO 3.14 (available at \url{http://www.mcs.anl.gov/petsc}),
which features enhanced GPU support.  The library now supports CUDA-11 and HIP, along with CUDA-aware
MPI, which allows direct communication of data between Summit GPUs, bypassing the previously needed
step of first copying the data to the CPU memory. This enhancement reduces the latency of the
communication and improves bandwidth.  An experimental Kokkos backend for some matrix and
vector operations using KokkosKernels was also provided, as one step in the refactoring
process to support the variety of accelerators needed for exascale systems and the
programming models for performance portability wanted by applications.

\begin{figure}
\centering
\includegraphics[trim = 0in .2in 1.7in .2in, clip, width=0.9\textwidth]{projects/2.3.3-MathLibs/2.3.3.06-PETSc-TAO/petsc_arch}
\caption{The improved PETSc/TAO architecture enables users to utilize a variety of programming
models for GPUs independently of PETSc's internal programming model.}
\label{fig:petsc-tao-fig}
\end{figure}

We have also release libEnsemble 0.7.1 (available at \url{https://github.com/Libensemble/libensemble}).
This release includes new generator functions and examples, changes to become xSDK compatible, and
improved testing across available platforms.

\paragraph{Next Steps}

Our next efforts are:
\begin{enumerate}
  \item \textbf{Performance and application assessment}:
  We will provide updated performance reports of PETSc/TAO on the architectures available to us.
  We will work with our applications to assess the usage of our software technologies and our
  progress toward reaching our impact goals.
  We will add a libEnsemble guide for function writer users to the documentation and survey
  the libEnsemble user community.
  \item \textbf{PETSc/TAO release with full-functionality on available hardware}:
  We will release a version of PETSc/TAO that fully supports the hardware and software on the
  architectures available to us.
  We will begin testing important kernels using different backends and prepare more methods to utilize accelerators.
  \item \textbf{libEnsemble release with enhanced capabilities}:
  We will release a version of libEnsemble that implements a method for Bayesian calibration.
  We will connect libEnsemble to continuous integration tools and demonstrate capabilities.
  \item \textbf{PETSc/TAO release focused on performance on available hardware}:
  We will release a version of PETSc/TAO with performance improvements on the architectures available to us.
  We will continue testing important kernels using different backends and optimize more methods to
  utilize accelerators.
\end{enumerate}