\documentclass{beamer}

\mode<presentation>
{
  \usetheme{Hawke}
  \setbeamercovered{transparent}
}

\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{multimedia}
\usepackage{mathtools}

\title[Lecture 1]{Lecture 1 - Introduction}

\author[I. Hawke]{I.~Hawke}

\institute[University of Southampton]
{
  School of Mathematics, \\
  University of Southampton, UK
}

\date[Semester 1]{MATH3018/6141, Semester 1}

\subject{Numerical methods}

\pgfdeclareimage[height=0.5cm]{university-logo}{mathematics_7469}
\logo{\pgfuseimage{university-logo}}

\AtBeginSection[]
{
  \begin{frame}<beamer>
    \frametitle{Outline}
    \tableofcontents[currentsection]
  \end{frame}
}

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\section{Numerical methods - introduction}

\subsection{What are numerical methods?}

\begin{frame}
  \frametitle{Examples}

  \begin{overlayarea}{\textwidth}{0.8\textheight}
    \only<1|handout:1>
    {
      \begin{center}

        \vspace{2ex}
        \includegraphics[width=0.95\textwidth]{figures/Kenji_Glue_Crop3}
        \vspace{3ex}

        Computing air flow past complex shapes {\tiny [MSc Race Car
          Aerodynamics students, School of Engineering Sciences]}.
      \end{center}
    }
    \only<2|handout:2>
    {
      \begin{center}
        \includegraphics[width=0.6\textwidth]{figures/0mT_zeeman_Fangohr_Ferromagnetic_Sphere}

        Complex magnetic field structures \href{http://www.soton.ac.uk/~rpb/thesis.pdf}{\tiny [Boardman \& Fangohr]}.
      \end{center}
    }
    \only<3|handout:3>
    {
      \begin{center}
        \includegraphics[width=0.8\textwidth]{figures/3d_landscape_samples_NieldDunes}

        Geographical modelling {\tiny
          \href{http://dx.doi.org/10.1016/j.gloplacha.2008.10.002}{[Nield \&
            Baas, Global and Planetary Change 64 (2008)]}}.
      \end{center}
    }
    \only<4|handout:4>
    {
      \begin{center}
        \includegraphics[width=0.67\textwidth]{figures/collapse6}

        Computing gravitational waves emitted in neutron star collapse
        to black hole
        \href{http://dx.doi.org/10.1088/0264-9381/24/12/S13}{{\tiny
            [Baiotti, Hawke, Rezzolla, Schnetter; K{\"a}hler]}}.
      \end{center}
    }
    \only<5|handout:5>
    {
      \begin{center}
        \includegraphics[width=0.95\textwidth]{figures/QuadPic1}

        Suggesting and testing purely mathematical results.
      \end{center}
    }
  \end{overlayarea}

\end{frame}

\begin{frame}
  \frametitle{What are numerical methods?}

  \begin{quotation}
    Numerical methods are algorithms that give quantitative answers in
    a finite number of steps.
  \end{quotation}
  \pause
  \begin{itemize}
  \item Problem \emph{continuous} (eg
    differential equation) implies answer is  approximate.\pause
  \item Usefulness of algorithm is practically defined by the
    number of steps to find answer at given accuracy.\pause
  \item In particular: \emph{useless}
    algorithms exist - more steps need not improve accuracy.
  \end{itemize}

\end{frame}

\begin{frame}
  \frametitle{Where do numerical methods fit?}

  \begin{center}
    \includegraphics[width=0.9\textwidth]{figures/ModelMethodReality}
  \end{center}

\end{frame}

\subsection{What is this course?}

\begin{frame}
  \frametitle{What is this course?}

  This course aims to introduce three areas of numerical methods.\pause

  \begin{enumerate}
  \item<2-> How are specific algorithms implemented?
    \begin{itemize}
    \item ``Engineering'' aspect.
    \item Practical implementation using Python.
    \item Class test (10\%) and coursework (30\%).
    \end{itemize}
  \item<3-> How efficient are the algorithms and how can they be
    implemented efficiently?
    \begin{itemize}
    \item ``Computer science'' aspect.
    \item Mixture of analytic and practical, Python work.
    \item Mainly coursework (30\%).
    \end{itemize}
  \item<4> How do we derive algorithms and prove that they work?
    \begin{itemize}
    \item ``Mathematics'' aspect.
    \item Analytic, but feeds into practical work.
    \item Closed book exam (60\%).
    \end{itemize}
  \end{enumerate}

\end{frame}

\begin{frame}
  \frametitle{How to think}

  \begin{itemize}
  \item Course will \emph{not} introduce cutting edge
    numerical methods.
  \item Shows how numerical methods are derived and
    analyzed. \pause
  \item Course notes contain the formal material that
    might be examined.
  \item Lectures illustrate by example how the algorithms are understood,
    implemented and used. \pause
  \item Computer labs  introduce Python needed to
    illustrate and implement the algorithms.
  \end{itemize}

\end{frame}

\section{Approximation pitfalls}

\subsection{Finite precision}

\begin{frame}
  \frametitle{Finite precision and approximation}

  Most numerical algorithms involve real numbers. Computer
  representations in \emph{floating point} notation are
  approximations:
  \begin{equation*}
    \pi \rightarrow 0.\underbracket{314159265358979}_{\text{precision}} \times 10^{\overbracket{1}^{\text{\clap{exponent}}}}.
  \end{equation*}
  Precision of representation -- number of significant
  digits -- controls accuracy: can never be perfect.

\end{frame}

\begin{frame}
  \frametitle{$1 + 1 = \dots$}

  Imagine a computer with 1 digit of precision. It
  represents $1$ and $0.1$ exactly. It also represents
  \begin{equation*}
    1 + 1 = 2
  \end{equation*}
  precisely. \pause

  Computer cannot represent sum of $1$ and $0.1$:
  \begin{align*}
    1 + 0.1 & = 1.1 \\
            & = 0.11 \times 10^1 \\
            & \rightarrow 0.1 \times 10^1 \\
            & = 1
  \end{align*}

\end{frame}

\begin{frame}
  \frametitle{$1 + 1 = 2$?}

  On a computer with a single digit of precision,
  \begin{align*}
    1 + \sum_1^{10} 0.1 & = (1 + 0.1) + 0.1 + \dots 0.1 \\
                        & = \dots \\
                        & = 1
  \end{align*} \pause
  \emph{or}
  \begin{align*}
    1 + \sum_1^{10} 0.1 & = 1 + (0.1 + \dots 0.1) \\
                        & = 1 + 1 \\
                        & = 2.
  \end{align*}

\end{frame}

\begin{frame}
  \frametitle{Matrix problems}

  Many numerical methods depend on solving linear systems. Consider
  \begin{equation*}
    \begin{pmatrix}
      4 & 5 \\ 2 & 3
    \end{pmatrix} {\bf x} = {\bf b}.
  \end{equation*}
  This is a sensible matrix equation. \pause

  Problem has solution if (and only if) matrix is
  non-singular:
  \begin{equation*}
    \det (A) = 4 \times 3 - 5 \times 2 = 2 \neq 0,
  \end{equation*}
  so problem has a solution. \pause
%
  \emph{However}, with only one digit of precision
  \begin{align*}
    \det (A) & = 4 \times 3 - 5 \times 2 && = (12) - (10) \\
             &&& \rightarrow (10) - (10)  = 0.
  \end{align*} \pause
  Finite precision makes matrix singular; no solution can be
  found!

\end{frame}

\subsection{Summary}

\begin{frame}
  \frametitle{Summary}

  \begin{itemize}
  \item Numerical methods are about computing quantitative answers
    using a finite number of steps.
  \item The finite accuracy of numerical methods leads to inherent
    approximations.
  \item These approximations can lead to fundamental mathematical
    difficulties.
  \end{itemize}

\end{frame}

\end{document}


\documentclass{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[hidelinks]{hyperref}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{float}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=blue,
    pdfpagemode=FullScreen,
    }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{Preliminaries}
\large
First, download the figures from the web by right clicking and selecting "Save Link As...".
\bigskip

\url{https://raw.github.com/rjp0i/latex-intro/master/en/gerbil.jpg}

\url{https://raw.github.com/rjp0i/latex-intro/master/en/lithium.png}

\medskip

Then upload the images into this Overleaf Project. You will then need to recompile this project in Overleaf, so that the images are added to this PDF (check the next page to see if an image appears).
\bigskip

\bigskip

The PDF for this entire workshop can be found here:

 \url{https://raw.github.com/rjp0i/latex-intro/master/en/latex-fig-tab.pdf}

\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{First Figure}

Here is a figure, with no caption
\medskip

{\bf Your Turn: Try changing the width of the figure}

\begin{figure}
\centering   %centers the figure (horizontally) on the page
\includegraphics[width=1.5in]{lithium.png} %sets the figure width to 1.5in
\end{figure}
\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Captioning a Figure}
Here is a figure, with a caption

\begin{figure}
\centering
\includegraphics[scale=0.5]{lithium.png} %scales the figure down to 50% of the original size
\caption{\label{fig:lithium}This is Lithium (${}^{6}$Li)}
\end{figure}
\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Labeling a Figure}
Figure \ref{fig:gerbil} shows the automatic numbering of figures (both in the caption, as well as here, in the text of the document itself.

{\bf Your turn: }
\begin{figure}
\centering
\includegraphics[
  width=0.5\textwidth]{gerbil}
\caption{\label{fig:gerbil}Aww\ldots}
\end{figure}
\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Placing a Figure}
Figure \ref{fig:gerbil2}, shown below, shows how one can position a figure on a page.

{\bf Your Turn: Try changing the placement of the figure, using the options h, t, b, p, !, and H}
\begin{figure}[h]
\centering
\includegraphics[width=0.70\textwidth]{gerbil}
\caption{\label{fig:gerbil2}Aww\ldots.}
\end{figure}
\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Simple Tables}

A very basic table
\bigskip

\begin{tabular}{lrr}\hline\hline
Item   & Qty & Unit \$ \\ \hline
Widget & 1   & 199.99  \\
Gadget & 2   & 399.99  \\
Cable  &3    &  19.99   \\
\hline
\end{tabular}
\bigskip

{\bf Your Turn:}
Try changing the alignment of the columns.

{\bf Your Turn again (after next slide):}
Try adding horizontal and vertical lines to the table.

\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Lining up using @-expressions}

\begin{tabular}{r@{.}l} \hline
  3   & 14159 \\
  16  & 2     \\
  123 & 456   \\  \hline
\end{tabular}
\bigskip

{\bf Your turn:}
\begin{enumerate}
\item What happens if you change the alignment for the two columns from right, left to left, right?
\item Try changing the content of the @-expression from a decimal point to something else
\end{enumerate}
\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \section{multicolumn  and multirow}

\begin{tabular}{|l|l|r|} \hline
  \multicolumn{2}{|c|}{Item} & \multirow{2}{*}{Price (\$)}\\ \cline{1-2}
  Animal & Description &  \\ \hline
  Gnat  & per gram & 13.65 \\
        & each     &  0.01 \\
  Gnu   & stuffed  & 92.50 \\
  Emu   & stuffed  & 33.33 \\
  Armadillo & frozen & 8.99 \\ \hline
 \end{tabular}

 \bigskip

{\bf Your turn:}
\begin{enumerate}
\item What happens if you change Gnat to ${\backslash}$multirow\{2\}\{*\}\{Gnat\}?
 % \multirow{2}{*}{Gnat}
\item What happens if you replace the ${\backslash}$cline\{1-2\} command with an ${\backslash}$hline command?
\end{enumerate}
\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Positioning, Captioning, and Labeling a Table}

\begin{table}[H]
\centering
\begin{tabular}{|l|l|r|} \hline
  \multicolumn{2}{|c|}{Item} & \multirow{2}{*}{Price (\$)}\\ \cline{1-2}
  Animal & Description &  \\ \hline
  Gnat  & per gram & 13.65 \\
        & each     &  0.01 \\
  Gnu   & stuffed  & 92.50 \\
  Emu   & stuffed  & 33.33 \\
  Armadillo & frozen & 8.99 \\ \hline
 \end{tabular}
 \caption{\label{tab:prices}Wholesale Prices}
 \end{table}
 %\input{prices.tex}
 \bigskip

{\bf Your turn:}
\begin{enumerate}
\item Refer to the Table \ref{tab:prices} in the text
\item Move the location of the table with the positioning parameter
\end{enumerate}
\clearpage
\end{document}


%%
%% Automatically generated file from DocOnce source
%% (https://github.com/hplgit/doconce/)
%%
%%

%-------------------- begin preamble ----------------------

\documentclass[%
oneside,                 % oneside: electronic viewing, twoside: printing
final,                   % draft: marks overfull hboxes, figures with paths
10pt]{article}

\listfiles               %  print all files needed to compile this document

\usepackage{relsize,makeidx,color,setspace,amsmath,amsfonts,amssymb}
\usepackage[table]{xcolor}
\usepackage{bm,ltablex,microtype}

\usepackage[pdftex]{graphicx}

\usepackage[T1]{fontenc}
%\usepackage[latin1]{inputenc}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}

\usepackage{lmodern}         % Latin Modern fonts derived from Computer Modern

% Hyperlinks in PDF:
\definecolor{linkcolor}{rgb}{0,0,0.4}
\usepackage{hyperref}
\hypersetup{
    breaklinks=true,
    colorlinks=true,
    linkcolor=linkcolor,
    urlcolor=linkcolor,
    citecolor=black,
    filecolor=black,
    %filecolor=blue,
    pdfmenubar=true,
    pdftoolbar=true,
    bookmarksdepth=3   % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC
    }
%\hyperbaseurl{}   % hyperlinks are relative to this root

\setcounter{tocdepth}{2}  % levels in table of contents

% prevent orhpans and widows
\clubpenalty = 10000
\widowpenalty = 10000

% --- end of standard preamble for documents ---

% insert custom LaTeX commands...

\raggedbottom
\makeindex
\usepackage[totoc]{idxlayout}   % for index in the toc
\usepackage[nottoc]{tocbibind}  % for references/bibliography in the toc

%-------------------- end preamble ----------------------

\begin{document}

% matching end for #ifdef PREAMBLE

\newcommand{\exercisesection}[1]{\subsection*{#1}}

% ------------------- main content ----------------------

% ----------------- title -------------------------

\thispagestyle{empty}

\begin{center}
{\LARGE\bf
\begin{spacing}{1.25}
Project 5, deadline  December 15, 2019
\end{spacing}
}
\end{center}

% ----------------- author(s) -------------------------

\begin{center}
{\bf Disease Modeling${}^{}$} \\ [0mm]
\end{center}

\begin{center}
% List of all institutions:
\end{center}

% ----------------- end author(s) -------------------------

% --- begin date ---
\begin{center}
Fall semester 2019
\end{center}
% --- end date ---

\vspace{1cm}

\subsection*{Theoretical background and description of the system}

The goal of this project is to develop a Monte Carlo simulation of
the spread of an infectious disease. We will use the classical SIRS model of
to develop the necessary transition
probabilities for the simulation. Interpreting the simulation requires
a thorough understanding of the SIRS model, so a deterministic
approach is used in conjunction with Monte Carlo methods.

The main purpose of creating such a simulation is to investigate how a
disease spreads throughout a given population over time. Then we can
make predictions about whether or not a certain disease has the
capacity to establish itself within the population, i.e.~a fraction of
the population remains infected after the system reaches
equilibrium.

The \href{{https://en.wikipedia.org/wiki/Compartmental_models_in_epidemiology}}{SIRS model} considers an isolated population of $N$ people which are divided into three separate groups:

\begin{itemize}
  \item Susceptible (S): those without immunity to the disease,

  \item Infected (I): those who are currently infected with the disease,

  \item Recovered (R): those who have been infected in the past and have developed an immunity to the disease.
\end{itemize}

\noindent
A person can move from one group to another only in the cyclic order
suggested by the name of the model
$S\rightarrow I \rightarrow R\rightarrow S$.
The rate of transmission $a$, the rate of recovery $b$
and the rate of immunity loss $c$ help describe the flow of people
moving between the three groups. The population is assumed to mix
homogeneously and total population is assumed to remain constant so
that

\begin{equation}
N = S(t)+I(t)+R(t).
\end{equation}

For the simple case, we will assume that the dynamics of the epidemic
occur during a time scale much smaller than the average person's
lifetime. Hence the effect of the birth and death rate of the
population is ignored.

From these assumptions, a set of coupled differential equations can be constructed to form the classical SIRS model:

\begin{equation}
\begin{split}
S'&=cR-\frac{aSI}{N}\\
I'&=\frac{aSI}{N}-bI\\
R'&=bI-cR\\
\end{split}
\end{equation}

Note that for small populations, one may choose to write $aSI$ instead
of $\frac{aSI}{N}$ since the number of susceptibles which become
infected depend more on the absolute number of infected people rather
than the infected fraction of the population.

Though this set does not have analytic solutions like the
closely-related SIR model, the equilibrium solutions are simple to
obtain. The constraint in (1) reduces this three dimensional system
into a two dimensional one so that the equation for $R'$ can just be
omitted:

\begin{equation}
\begin{split}
S'&=c(N-S-I)-\frac{aSI}{N}\\
I'&=\frac{aSI}{N}-bI\\
\end{split}
\end{equation}

The steady state is found by setting both equations in (3) equal to
zero. Let $s$, $i$, and $r$ denote the fractions of people in $S$,
$I$, and $R$, respectively. Then the fractions of people in each group
at equilibrium are:

\begin{equation}
\begin{split}
s^* &= \frac{b}{a},\\
i^* &= \frac{1-\frac{b}{a}}{1+\frac{b}{c}},\\
r^* &= \frac{b}{c}\frac{1-\frac{b}{a}}{1+\frac{b}{c}}.
\end{split}
\end{equation}

Here, the asterisk ($^*$) signifies that these fractions are at
equilibrium. Notice that each fraction must be a number between 0 and
1, and that the three fractions must add up to 1. Thus the equations
in (4) suggest that the rate of recovery $b$ must be less than the
rate of transmission $a$ for the number of infected people at
equilibrium to be greater than zero. In other words, the disease
establishes itself in the population only if $b<a$.

\textbf{For this project you can collaborate with fellow students and you can  hand in a common report.}
This project (together with projects 3 and 4) counts 1/3 of the final mark.

\paragraph{Part a) setting up the differential equations.}
We will create four different populations to investigate the effect of
increasing the rate of recovery $b$ and crossing the "threshold". Each
population consists of 400 people, 100 of which were initially
infected and 300 of which were initially susceptible. We fix the  rate of
transmission $a$ and the rate of immunity loss $c$
between populations, but let the rate of recovery $b$ be varied because
it is the one parameter which can be reasonably controlled by the
actions of human society (access to health care, development of new
medicines, etc). Note that the rates have units of inverse time.
The table here lists a possible set of parameters for the four different populations.

\begin{quote}
\begin{tabular}{ccccc}
\hline
\multicolumn{1}{c}{ \textbf{Rate} } & \multicolumn{1}{c}{ \textbf{A} } & \multicolumn{1}{c}{ \textbf{B} } & \multicolumn{1}{c}{ \textbf{C} } & \multicolumn{1}{c}{ \textbf{D} } \\
\hline
a             & 4          & 4          & 4          & 4          \\
b             & 1          & 2          & 3          & 4          \\
c             & 0.5        & 0.5        & 0.5        & 0.5        \\
\hline
\end{tabular}
\end{quote}

\noindent
The rates of transmission are given by the parameter $a$, recovery by $b$, and immunity loss $c$ for populations $A$, $B$, $C$, and $D$.

We treat the population as a continuous variable. Develop a Runge-Kutta fourth order code
to solve the above equations.

Discuss your results and present your interpreations.

\paragraph{Part b), moving to a Monte Carlo simulation.}
The set of differential equations in (2) inherently assume that $S$,
$I$, and $R$ are continuous variables, when they are discrete in
reality. We can use the idea of randomness to remedy this issue by
defining a set of transition probabilities for the possible moves a
person can take from one state to another: $S\rightarrow I$, $I
\rightarrow R$, and $R \rightarrow S$. To obtain the specific values
for each probability, we first notice from (2) that in a small time
step $\Delta t$, the number of people moving from $S$ to $I$ is
approximately $\frac{aSI}{N}\Delta t$. Likewise, about $bI\Delta t$
move from $I$ to $R$ and $cR\Delta t$ move from $R$ to $S$.

Now we let $\Delta t$ be small enough so that \emph{at most} one person moves from a given group to another. Since

\begin{equation}
\begin{split}
&\max \Big\{ \frac{aSI}{N}\Delta t \Big\} = \frac{a}{N}\left(\frac{N}{2}\right)^2\Delta t=\frac{aN}{4}\Delta t,\\
&\max \Big\{ bI\Delta t \Big\} = bN\Delta t,\\
&\max \Big\{ cR\Delta t \Big\} = cN\Delta t,\\
\end{split}
\end{equation}
the time step is then given by

\begin{equation}
\Delta t = \min \Big\{ \frac{4}{aN}, \frac{1}{bN}, \frac{1}{cN} \Big\}.
\end{equation}
This construction allows us to reinterpret the values $\frac{aSI}{N}\Delta t$, $bI\Delta t$, and $cR\Delta t$ as transition probabilties:

\begin{equation}
\begin{split}
P(S\rightarrow I) &= \frac{aSI}{N}\Delta t,\\
P(I \rightarrow R) &= bI\Delta t,\\
P(R \rightarrow S) &= cR\Delta t.\\
\end{split}
\end{equation}
For each possible move, a random number between 0 and 1 is generated. If the number is less than the probability for the move, the move is taken.

Develop now a Monte Carlo algorithm which implements the last
equations using the same parameters $N$, $a$, $b$, and $c$ for each
population. Compare your results to those obtained with the
deterministic differential equation solver and discuss your findings.

You will need to find the
fraction of people when the system has been equilibrated.  You will
need to find the equlibrium expectation values and corresonding
standard deviations.

\paragraph{Part c) Improvements, vital dynamics.}
The same principles used in this simple model can be extended to
include more details about the population and disease.

For instance, vital dynamics can be easily added to the system so that
the model can describe the spread of diseases which occur over longer
stretches of time. If $e$ is the birth rate, $d$ is the death rate,
and $d_I$ is the death rate of infected people due to the disease,
then the modified differential equations are given by:

\begin{equation}
\begin{split}
S'&=cR-\frac{aSI}{N}-dS+eN\\
I'&=\frac{aSI}{N}-bI-dI-d_I I\\
R'&=bI-cR-dR\\
\end{split}
\end{equation}
Here, we have assumed that all the babies born into the population are initially susceptible.

Add now these additions to your ODE solver and Monte Carlo solver and discuss the results.

\paragraph{Part d) Seasonal Variation.}
For diseases such as influenza, the rate of transmission depends
largely on the time of year. During the colder months, individuals are
more likely to spend time in closer proximity to one another,
resulting in a rate of transmission which oscillates. So we can let
$a$ be given by

\begin{equation}
a(t)=Acos(\omega t) + a_0,
\end{equation}

where $a_0$ is the average transmission rate, $A$ is the maximum
deviation from $a_0$, and $\omega$ is the frequency of oscillation.
Study the the effect of seasonal variations as well, with both the ODE
and Monte Carlo solver. Try different values of the above new
parameters and discuss your results.

\paragraph{Part e) Vaccination.}
Diseases with available vaccinations allow people to move directly
from $S$ to $R$, breaking the cyclic structure of the SIRS model. We
assume that a susceptible individual's choice to become vaccinated
does not depend on how many other susceptibles are vaccinated. We may,
however, assume that the rate of vaccination $f$ can depend on the
time, since this rate may oscillate during the course of a year and/or
increase as awareness and medical research increases. Then the system
of differential equations become

\begin{equation}
\begin{split}
S'&=cR-\frac{aSI}{N}-f\\
I'&=\frac{aSI}{N}-bI\\
R'&=bI-cR+f\\
\end{split}
\end{equation}

Add now the effect of vaccination via the parameter $f$ and discuss
again your results.  Play around with different values of the
parameter $f$.

\subsection*{Introduction to numerical projects}

Here follows a brief recipe and recommendation on how to write a report for each
project.

\begin{itemize}
  \item Give a short description of the nature of the problem and the eventual  numerical methods you have used.

  \item Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.

  \item Include the source code of your program. Comment your program properly.

  \item If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.

  \item Include your results either in figure form or in a table. Remember to        label your results. All tables and figures should have relevant captions        and labels on the axes.

  \item Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.

  \item Try to give an interpretation of you results in your answers to  the problems.

  \item Critique: if possible include your comments and reflections about the  exercise, whether you felt you learnt something, ideas for improvements and  other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.

  \item Try to establish a practice where you log your work at the  computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember  what a previous test version  of your program did. Here you could also record  the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.
\end{itemize}

\noindent
\subsection*{Format for electronic delivery of report and programs}

The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file.  As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:

\begin{itemize}
  \item Use Devilry to hand in your projects, log in  at  \href{{http://devilry.ifi.uio.no}}{\nolinkurl{http://devilry.ifi.uio.no}} with your normal UiO username and password and choose either 'fys3150' or 'fys4150'. There you can load up the files within the deadline.

  \item Upload \textbf{only} the report file!  For the source code file(s) you have developed please provide us with your link to your github domain.  The report file should include all of your discussions and a list of the codes you have developed.  Do not include library files which are available at the course homepage, unless you have made specific changes to them.

  \item In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parametxers.

  \item In this and all later projects, you should include tests (for example unit tests) of your code(s).

  \item Comments  from us on your projects, approval or not, corrections to be made  etc can be found under your Devilry domain and are only visible to you and the teachers of the course.
\end{itemize}

\noindent
Finally,
we encourage you to work two and two together. Optimal working groups consist of
2-3 students. For this specific report you can  hand in a common report.

% ------------------- end of main content ---------------

\end{document}


\section{Script and Output}
\subsection{Figures}

\begin{figure}[!hbtp]
    \centering
    \includegraphics[width=\textwidth]{../src/lab_10_figure_1.pdf}
    \caption{Mesh Plots}
    \label{fig:my_label}
\end{figure}

\begin{figure}[!hbtp]
    \centering
    \includegraphics[width=\textwidth]{../src/lab_10_figure_2.pdf}
    \caption{Surf Plots}
    \label{fig:my_label}
\end{figure}

\newpage
\subsection{Script file: \lstinline[style=Plain]{lab_10_script.m}}
\lstinputlisting[style=MATLAB]{../src/lab_10_script.m}


% Copyright 2020 by Junwei Wang <i.junwei.wang@gmail.com>
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt

\documentclass[compress]{beamer}

\usepackage[document]{ragged2e}

\usepackage[english]{babel}
\usepackage{metalogo}
\usepackage{listings}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{pgfplots}

\usetheme{Nord}
% \usetheme[style=light]{Nord}

\setmainfont{Yanone Kaffeesatz}
\setsansfont{Andika New Basic}
\setmonofont{DejaVu Sans Mono}

\AtBeginSection[]
{
  \begin{frame}[c,noframenumbering,plain]
    \tableofcontents[sectionstyle=show/hide,subsectionstyle=show/show/hide]
  \end{frame}
}

\AtBeginSubsection[]
{
  \begin{frame}[c,noframenumbering,plain]
    \tableofcontents[sectionstyle=show/hide,subsectionstyle=show/shaded/hide]
  \end{frame}
}

\title{Beamer Theme ``Nord''}
\subtitle{A simple beamer theme that uses ``Nord'' color scheme}
\author{Junwei Wang}
\institute{CryptoExperts}
\date{\today}

\begin{document}

\begin{frame}[plain,noframenumbering]

\begin{itemize}

\item \color{NordOrange} Accuracy \color{NordWhite}

\begin{equation*}
\text{Accuracy} = \displaystyle\frac{\color{NordOrange}\text{TN}\color{NordWhite}+\color{NordOrange}\text{TP}\color{NordWhite}}{\color{NordOrange}\text{TN}\color{NordWhite}+\color{NordOrange}\text{TP}\color{NordWhite}+\color{NordCyan}\text{FN}\color{NordWhite}+\color{NordCyan}\text{FP}\color{NordWhite}}
\end{equation*}

\vspace{10pt}

\begin{center}
\begin{tikzpicture}[scale=2] %font=\scriptsize
    % Draw Basic Box
    \draw[thick] (0,0) -- (2.2,0);
    \draw[thick] (0,0) -- (0, 2.2);
    \draw[thick] (2.2,2.2) -- (2.2, 0);
    \draw[thick] (2.2,2.2) -- (0, 2.2);

    % Draw Box Ticks
    \draw[thick] (0, 1.1) -- (2.2, 1.1);
    \draw[thick] (1.1, 0) -- (1.1, 2.2);

    % Box Labels
    % -- left side
    \coordinate[label=left:$0$] (p1) at (-0.1,1.65);
    \coordinate[label=left:$1$] (p2) at (-0.1,0.55);

    % -- bottom side
    \coordinate[label=below:$0$] (p3) at (0.55, -0.1);
    \coordinate[label=below:$1$] (p4) at (1.65, -0.1);

    % -- overall headers
    \coordinate[label=below:Predicted] (p5) at (1.1, -0.4);
    \coordinate[label=left:\rotatebox{90}{Actual}] (p6) at (-0.4, 1.1);

    % Category Values
    \coordinate[label={\Large \color{NordOrange}TN}] (TP) at (0.55, 1.50);
    \coordinate[label={\Large \color{NordCyan}FN}] (FP) at (1.65, 1.50);
    \coordinate[label={\Large \color{NordCyan}FP}] (FN) at (0.55, 0.40);
    \coordinate[label={\Large \color{NordOrange}TP}] (TN) at (1.65, 0.40);
\end{tikzpicture}
\end{center}

\end{itemize}

\end{frame}

\begin{frame}[plain,noframenumbering]

\begin{itemize}

\item \color{NordOrange} True Positive Rate \color{NordWhite}(TPR), \color{NordOrange} Recall\color{NordWhite}, or \color{NordOrange} Sensitivity \color{NordWhite}

\begin{equation*}
\text{TPR} = \displaystyle\frac{\text{TP}}{\text{TP}+\color{NordCyan}\text{FN}\color{NordWhite}}
\end{equation*}

\item \color{NordOrange} Precision \color{NordWhite}

\begin{equation*}
\text{Precision} = \displaystyle\frac{\text{TP}}{\text{TP}+\color{NordCyan}\text{FP}\color{NordWhite}}
\end{equation*}

\item \color{NordOrange} F1 Score \color{NordWhite}

\begin{equation*}
\text{F1} = \displaystyle\frac{\text{TP}}{\text{TP} + \color{NordCyan}\frac{1}{2}\left(\text{FP} + \text{FN}\right)\color{NordWhite}}
\end{equation*}

\item \color{NordOrange} Accuracy \color{NordWhite}

\begin{equation*}
\text{Accuracy} = \displaystyle\frac{\text{TN}+\text{TP}}{\text{TN}+\text{TP}+\color{NordCyan}\text{FN}\color{NordWhite}+\color{NordCyan}\text{FP}\color{NordWhite}}
\end{equation*}

\end{itemize}

\end{frame}

% \section{Appearance}

% \begin{frame}[fragile]
%   \frametitle{Usage}
%   Simply include the following code in your preamble:

%   \begin{lstlisting}[basicstyle = \ttfamily\small]
% \usetheme{Nord}
%   \end{lstlisting}

%   \bigskip

%   By default, the appearance is in dark theme, however you can actively choose a either a light or a
%   dark theme.

%   \begin{lstlisting}[basicstyle = \ttfamily\small]
% \usetheme[style=light]{Nord}
% \usetheme[style=dark]{Nord}
%   \end{lstlisting}

% \end{frame}

% \subsection{Colors}

% \begin{frame}{Defined Colors}{This is a subtitle}
%   \begin{description}[Snow Storm]
%   \item[Polar Night]
%     \textcolor{NordDarkBlack}{NordDarkBlack} \quad \textcolor{NordBlack}{NordBlack}\\
%     \textcolor{NordMediumBlack}{NordMediumBlack} \quad \textcolor{NordBrightBlack}{NordBrightBlack}
%   \item[Snow Storm]
%     \textcolor{NordWhite}{NordWhite} \quad \textcolor{NordBrighterWhite}{NordBrightestWhite}\\
%     \textcolor{NordBrightestWhite}{NordBrightestWhite}
%   \item[Forest]
%     \textcolor{NordCyan}{NordCyan} \quad \textcolor{NordBrightCyan}{NordBrightCyan}\\
%     \textcolor{NordBlue}{NordBlue} \quad \textcolor{NordBrightBlue}{NordBrightBlue}
%   \item[Aurora]
%     \textcolor{NordRed}{NordRed} \quad \textcolor{NordOrange}{NordOrange} \\
%     \textcolor{NordYellow}{NordYellow} \quad \textcolor{NordGreen}{NordGreen} \\
%     \textcolor{NordMagenta}{NordMagenta}
%   \end{description}
% \end{frame}

% \subsection{Fonts}

% \begin{frame}[fragile]{Recommended Free Fonts}
%   \begin{description}[Selected Fonts]
%   \item[Selected Fonts] recommended for this theme\\
%     \begin{lstlisting}[basicstyle = \ttfamily\small]
% \setmainfont{Yanone Kaffeesatz}
% \setsansfont{Andika New Basic}
% \setmonofont{DejaVu Sans Mono}
%     \end{lstlisting}
%   \item[Download] {\small \url{https://www.fontsquirrel.com/}}
%   \item[Install Fonts] {\small \url{https://www.google.com/get/noto/help/install/}}
%   \item[Compilation] compile with \XeLaTeX~to use system-wide fonts
%   \end{description}

% \end{frame}

% \subsection{Blocks}

% \begin{frame}
%   \frametitle{Blocks}
%   \begin{block}{This is a Block}
%     \[
%       a^2 + b^2 = c^2
%     \]
%   \end{block}
%   \begin{exampleblock}{This is an Example Block}
%     \[
%       E = m \cdot c^{2}
%     \]
%   \end{exampleblock}
%   \begin{alertblock}{This is an Alert Block}
%     \[
%       e^{i\pi} + 1 = 0
%     \]
%   \end{alertblock}

%   \centering
%   \begin{minipage}{1.0\linewidth}
%     \begin{block}{Horizontally-Aligned Block}
%       \[
%         \log xy = \log x + \log y
%       \]
%     \end{block}
%   \end{minipage}
% \end{frame}

% \subsection{Items}

% \begin{frame}{Items}
%   Itemize
%   \begin{itemize}
%     \item item 1
%     \item item 2
%   \end{itemize}

%   \bigskip

%   Enumerate
%   \begin{enumerate}
%     \item item 1
%     \item item 2
%   \end{enumerate}
% \end{frame}

% \subsection{Figures}

% \begin{frame}{Figures}
%   \begin{figure}
%     \centering
%     \begin{tikzpicture}
%       \draw [help lines,NordMagenta,very thick] (0,0) grid (5,4);
%     \end{tikzpicture}
%     \caption{Credits to Ti\textit{k}Z}
%   \end{figure}
% \end{frame}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% TeX-engine: xetex
%%% End:


\RequirePackage[l2tabu, orthodox]{nag}	% tells out-of-date packages
\documentclass[10pt, letterpaper]{scrartcl}

\usepackage{amssymb,amsfonts}
\usepackage{amsthm} % if using theorems and proofs
\usepackage[cmex10]{amsmath}
\usepackage[usenames,dvipsnames,svgnames]{xcolor} % use like \textcolor{red}{..} or {\color{red} ...}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}% can also add 'nohead', or leave blank

%\usepackage{url}

\usepackage{cancel} % for canceling terms

\usepackage{booktabs}

\usepackage{pdfpages} % for including pdfs

\usepackage{algpseudocode}  %algorithmicx
\usepackage{wrapfig}

%\usepackage{listings}
\usepackage[numbered,framed]{matlab-prettifier}
\lstdefinestyle{mat}{
    frame=single,
    language=matlab,
    showstringspaces=false,
    %  keywordstyle=\bfseries\color{blue},
    %  commentstyle=\color{green},
    %  stringstyle=\color{magenta},
}
\lstset{
    style              = Matlab-editor,
    basicstyle         = \mlttfamily,
    escapechar         = ",
    mlshowsectionrules = true,
}
%% use withL: \lstinputlisting{myODEfunction.m}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} % important!

\usepackage{hyperref}
\hypersetup{pdfauthor={Stephen Becker},
    pdftitle={},
    colorlinks=true,
    citecolor=MidnightBlue,
    urlcolor=Bittersweet,
}
% -- Input macros and such --
\IfFileExists{custom_headers.tex}{
\input{custom_headers}}{
\input{../custom_headers}}{
}
\let\oldenumerate\enumerate
\renewcommand{\enumerate}{
  \oldenumerate
  \setlength{\itemsep}{1em}
  \setlength{\parskip}{1em}
  \setlength{\parsep}{0pt}
}
\usepackage{enumitem}
%\setlist{noitemsep}
% See http://mirrors.fe.up.pt/pub/CTAN/macros/latex/contrib/enumitem/enumitem.pdf
% and now, set par indent to zero
\newlength{\savedparindent}
\setlength{\savedparindent}{\parindent}
\setlist[enumerate]{listparindent=\savedparindent}
%\setlength{\parindent}{0pt} % Jan 2017, HW 3/4, comment this out.

\usepackage{xspace}
%\newcommand{\collaboration}{\textbf{Collaboration Allowed}\xspace}
%\newcommand{\nocollaboration}{\textbf{No Collaboration}\xspace}

\renewcommand{\T}{\mathbb{T}}
\newcommand{\fn}{\widehat{f}_n} % Fourier coefficients
\newcommand{\spi}{\frac{1}{\sqrt{2\pi}}}
\renewcommand{\H}{\mathcal{H}}
\renewcommand{\phi}{\varphi}
\DeclareMathOperator{\ran}{ran} % ker already defined, and with lower case

\newcommand*\Laplace{\mathop{}\!\mathbin\bigtriangleup}
\renewcommand{\SS}{\mathcal{S}} % Schwartz space

% My solution environment
%%\newenvironment{solution}{\setlength{\parindent}{\savedparindent}{\bfseries Solution}:}{}
\makeatletter
\newcommand\solParagraph{\@startsection{paragraph}{4}{\z@}%
%    {-3.25ex \@plus -1ex \@minus -0.2ex}%
    {-.55ex \@plus -1ex \@minus -0.2ex}%
    {0.01pt}%
    {\raggedsection\normalfont\sectfont\nobreak\size@paragraph}%
}
\makeatother
\newenvironment{solution}{\setlength{\parindent}{\savedparindent}\solParagraph{Solution:}}{}

%\newenvironment{solution}{\emph{Solution}:}{}
\newenvironment{instructions}{}{}
\newenvironment{SolnComment}{}{}
\usepackage{comment}

%\def\solutions{1}  % define solutions  % !!! COMMENT or UNCOMMENT THIS LINE

% NOTE: \begin{solution} should have NO SPACES BEFORE OR AFTER IT,
% 	Can give very weird errors, hiding text, etc. See http://tex.stackexchange.com/a/91431/4603
\ifdefined\solutions
    \newcommand{\solTitle}[1]{#1}
    \excludecomment{instructions}
\else
   \excludecomment{solution}% uncomment this line to hide solution
   \newcommand{\solTitle}[1]{}
   \excludecomment{SolnComment}
\fi

\title{Homework 5 \solTitle{Selected Solutions} \\APPM 4720/5720 Spring 2019 \\ Randomized Algorithms}
%\author{Stephen Becker}
\date{}
\begin{document}
\maketitle
\vspace{-6em}
\textbf{Due date}: Friday, Feb 15 2019

Theme: Sketches   \hfill Instructor: Stephen Becker %Dr.\ Becker
%\vspace{1em}

\begin{instructions}
\paragraph{Instructions}
Collaboration with your fellow students is allowed and in fact recommended, although direct copying is not allowed.  Please write down the names of the students that you worked with. The internet is allowed for basic tasks only, not for directly looking for solutions.

An arbitrary subset of these questions will be graded.

\end{instructions}

\begin{enumerate}[align=left, leftmargin=*, label=\sffamily\bfseries Problem \arabic*:]

    \item \ [READING and MATH] Read exercise 4.1.4 and Lemma 4.1.5 about approximate identities, from Vershynin's 2018 ``High-dimensional probability'' book.

    \textbf{Deliverable}:
    Do exercise 4.1.6: if $A\in \R^{m \times n}$ and all the singular values of $A$ are in the set $[1-\delta,1+\delta]$ for some $\delta>0$,
    then $\|A^TA - I_n \| \le 3 \max \left( \delta,\delta^2\right)$.
    Note: you may assume $m\ge n$, otherwise the hypothesis cannot be true unless $\delta \ge 1$ (why?) and the result is not interesting.

    \item \ [PROGRAMMING] Try various sketches, do they converge to the identity  as number of repeated trials $N$ increases to $\infty$?
    Each draw of a sketch $S_i$ is $m \times n$, but unlike the above exercise, here $m < n$, and instead of looking at $S_i^TS_i \approx I_n$, we ask about
    \begin{equation}\label{eq:err}
    \left\| \frac{1}{N}\sum_{i=1}^N S_i^TS_i  - I_n \right\|
    \end{equation}
    as $N\rightarrow \infty$ (in either spectral or Frobenius norm).

    Also consider a histogram of outcomes of sketching (1) $x\in \R^n$ where $x$ is very sparse, and (2) $x \in \R^n$ where all the entries of $x$ are similar in value. Look at $\|Sx\|^2/\|x\|^2$.

    Generate $S$ in all of the following manners:
    \begin{enumerate}
        \item Gaussian
        \item Haar (cf.\ HW 2)
        \item Fast Johnson-Lindenstrauss, $S=RHD$ where $R$ samples $m$ of $n$ rows uniformly at random, $H$ is the discrete cosine transform, and $D$ is diagonal with Rademacher random variables on the diagonal.
        \item Simple sampling of $m$ of $n$ rows (e.g., $S=R$ in the above notation)
        \item \emph{at least one} of the following variants
            \begin{enumerate}
                \item the approach from ``How to Fake Multiply by a Gaussian Matrix'' (Kapralov, Potluru, Woodruff, ICML 2016, \url{https://arxiv.org/abs/1606.05732})
                \item the FJLT approach from the original FJLT paper, where $R$ is not simple sub-sampling but rather the matrix $R$ is such that each entry is $0$ with a certain probability, otherwise drawn from an appropriately scaled Gaussian (see ``Approximate nearest neighbors and the fast Johnson-Lindenstrauss transform'', Ailon and Chazelle, 2006, STOC, \url{https://dl.acm.org/citation.cfm?id=1132597})
                \item The low-density parity check (LDPC) codes used for the $R$ term in the FJLT, from ``Low Rank Approximation using Error Correcting Coding Matrices'' (Ubaru, Mazumdar, Saad, ICML 205,
\url{http://proceedings.mlr.press/v37/ubaru15.html}).
                \item CountSketch (``Simple and deterministic matrix sketching'', Edo Liberty, KDD 2013, \url{https://arxiv.org/abs/1206.0594}; or Clarkson and Woodruff, \url{https://doi.org/10.1145/3019134})
                \item the approach from ``Very Sparse Random Projections'' (Li, Hastie, Church, KDD 2006, \url{https://dl.acm.org/citation.cfm?id=1150436}),
                where each entry $S_{ij}$ is iid with value $\sqrt{3}$ with probability $1/6$, value $-\sqrt{3}$ with probability $1/6$, and value $0$ with probability $2/3$.
                \item the $S=\text{const}\cdot  THG\Pi H B$ approach in eq.\ (7) from
                ``Fastfood -- Approximating Kernel Expansions in Loglinear Time'' (Le, Sarl\'os, Smola, ICML 2013, \url{https://arxiv.org/abs/1408.3060})
                \item Fast Johnson-Lindenstrauss, where $H$ is now a Hadamard transform instead of the DCT
                \item Anything else you can find in the literature, e.g., see Fig.~\ref{fig:1}
            \end{enumerate}
        \end{enumerate}

    For each of the (at least 5) methods for $S$, plot the quantity in Eq.~\eqref{eq:err} as a function of $N$, and check that it behaves as you think it should.

    Try with several choices of $n$ and $m$ to make sure your scaling is correct; most of the sketch matrices need a $\sqrt{n/m}$ or $\sqrt{1/m}$ scaling.

    \textbf{Deliverables}: A plot of the quantity in Eq.~\eqref{eq:err} as a function of $N$ for each type of sketch, and histograms of $\|Sx\|_2^2/\|x\|_2^2$ for the different types of sketches and the two types of $x$ mentioned above. Include at least code snippets for how you generated each type of matrix.

    Are these good metrics to look at? Can you think of other metrics to look at?

\begin{figure}
    \centering
    \includegraphics[width=.75\textwidth]{Figs/TypesOfSketches.pdf}
    \caption{Types of sketches as listed in
        ``Weighted SGD for $\ell_p$ Regression with Randomized Preconditioning'' by Yang, Chow, R\'e and Mahoney, SODA 2016, \url{https://arxiv.org/abs/1502.03571}}.
\label{fig:1}
\end{figure}

\begin{solution}
TBD
     % Matlab prettifier package
     % see https://mirror.hmc.edu/ctan/macros/latex/contrib/matlab-prettifier/matlab-prettifier.pdf
%\lstinputlisting{Figs/loadBigFile.m}
%\begin{lstlisting}
%% Code TBD
%\end{lstlisting}

\end{solution}

\end{enumerate}
\end{document}


\section{Conclusion}

We did not get a full CUDA-implementation to work but only a partly CUDA-translated version with the most important part non-parallelized, namely the \texttt{rollback} loop.

We have in this report attempted to explain both abstractly and concretely via code examples the work process and goals of parallelizing the given system.

This includes flattening the implementation, loop distributing, creating coalesced memory accesses and loop interchanging along with transposing of matrices and moving sequential loops to the outer most, as was the goal of the project.

The benchmarks are incomplete, as the CUDA-version is incomplete. This makes the benchmarks perform considerably worse than the CPU parallel versions. We do not expect this to be the case, had the CUDA-version been fully implemented, and especially not if we had time to optimize it also, e.g. the \texttt{TRIDAG\_SOLVER}.

% In this report we explain the ideas behind parallelizing the given system. This was done by first flattening the vectors/arrays of the system. To increase the degree of parallelism, array expansion and privatization of simple non-array variables, which are later transformed into inlined scalar variables, was applied. To further increase the degree of parallelism over the whole system, loop distribution was applied throughout the system from the main loop. To keep memory access coalesced, loops where interchanged where possible and/or matrices where transposed.

% The system has one inherently sequential loop, in between parallel loops, which was distributed to be the outer loop via array expansions (making the inner arrays a dimension higher) and loop distribution.

% Unfortunately we were unable to complete the programming part. We misused a lot of time on the convertion from the flat sequential program to CUDA kernels, whereby we created a PrivGlob structure completely on CUDA (to omit having to copy arrays to and from the kernels). This however made debugging hell, and after tens of hours debugging without valid results we had to revert back to the flat sequential solution and create kernels one at a time, with the PrivGlobs placed completely in hos memory. We should have had realized this sooner, but alas we where stubborn thinking a valid solutions was right around the next logical error.

% Due to this, we ran out of time before parallelizing the rollback part, which performance wise is also the most essential part. This also means that we have not optimized the given tridag kernel. However, this report should still give the ideas behind parallelizing the system.