% !TEX root=talk.tex
\section{Special Material}

\begin{frame}[fragile]
\frametitle{Mathematics}

\begin{center}\begin{minipage}{.7\textwidth}\rmfamily
\eqref{eq:gratio} relates the golden ratio and the Fibonacci series.  Recall that the golden ratio, $\varphi = \frac{1}{2} (1 + \sqrt{5})$.

\begin{equation}\label{eq:gratio}
\varphi = 1 + \sum^{\infty}_{n=1}
                \frac{ (-1)^{n+1} }{ F_n F_{n+1} }
\end{equation}
\end{minipage}
\end{center}

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[escapechar=|,basicstyle=\ttfamily\small,moretexcs=eqref,emph={equation}]
\eqref{eq:gratio} relates the golden ratio and the Fibonacci series.
Recall that the golden ratio, |\textcolor{red}{\large\ttfamily\$}|\phi = \frac{1}{2} (1 + \sqrt{5})|\textcolor{red}{\large\ttfamily\$}|.

\begin{equation}\label{eq:gratio}
\phi = 1 + \sum^{\infty} _{n=1}
                \frac{ (-1)^{n+1} }{ F_n F_{n+1} }
\end{equation}
\end{lstlisting}
\vspace*{-1em}
\end{beamerboxesrounded}
\end{frame}

\begin{frame}[fragile]
\frametitle{Chemical Equations and Molecules}

\begin{center}\rmfamily\small
\ce{Zn^2+ <=>[\ce{+ 2OH-}][\ce{+ 2H+}]
$\underset{\text{amphoteres Hydroxid}}{\ce{Zn(OH)2 v}}$
<=>C[+2OH-][{+ 2H+}]
$\underset{\text{Hydroxozikat}}{\cf{[Zn(OH)4]^2-}}$
}
\hfil
\chemfig{H-C(-[2]H)(-[6]H)-C(-[7]H)=[1]O}
\end{center}

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[basicstyle=\ttfamily\small,moretexcs={ce,chemfig,underset,text,cf},
emph={mhchem,chemfig}]
\usepackage[version=3]{mhchem}   % sufficient for chemical equations
\usepackage{chemfig}   % for 2-D molecule drawings
...
\ce{Zn^2+ <=>[\ce{+ 2OH-}][\ce{+ 2H+}]
$\underset{\text{amphoteres Hydroxid}}{\ce{Zn(OH)2 v}}$
<=> C[+2OH-][{+ 2H+}]
$\underset{\text{Hydroxozikat}}{\cf{[Zn(OH)4]^2-}}$ }

\chemfig{H-C(-[2]H)(-[6]H)-C(-[7]H)=[1]O}
\end{lstlisting}
\vspace*{-1em}
\end{beamerboxesrounded}

\end{frame}

\begin{frame}[fragile]
\frametitle{Linguistics}

\begin{columns}[T]
\begin{column}{.54\textwidth}\small\rmfamily
\ex
\begingl
\gla \%*Wen liebt seine Mutter?//
\glb Whom loves his mother//
\glc `Who does his mother love?'//
\endgl
\xe

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[moretexcs={ex,xe,gla,glb,glc},basicstyle=\ttfamily\footnotesize\lsstyle,
emph={expex},
lineskip=-2pt,commentstyle={}]
\usepackage{linguex,qtree}
...
\ex
\begingl
\gla \%*Wen liebt seine Mutter?//
\glb Whom loves his mother//
\glc `Who does his mother love?'//
\endgl
\xe
\end{lstlisting}
\vskip-1em
\end{beamerboxesrounded}
\end{column}
\begin{column}{.45\textwidth}\footnotesize\rmfamily
\Tree [ .S [.NP [.Pron He ] ] [.VP [.V kicked ] [.NP [.Det the ] [.N ball ] ] ] ]

\medskip

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[moretexcs={ex,xe,gla,glb,glcTree},basicstyle=\ttfamily\footnotesize\lsstyle,
emph={expex,qtree},
lineskip=-2pt,commentstyle={}]
\usepackage{qtree}
...
\Tree [ .S [.NP [.Pron He ] ] [.VP [.V kicked ] [.NP [.Det the ] [.N ball ] ] ] ]
\end{lstlisting}
\vspace*{-1em}
\end{beamerboxesrounded}

\end{column}
\end{columns}

\end{frame}

\begin{frame}[fragile]
\frametitle{Program Listings}

\begin{columns}
\begin{column}{.5\textwidth}
\begin{beamerboxesrounded}{}
\vspace{-1em}
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize,
emph={listings,lstlisting},moretexcs={color}]
\usepackage{listings,xcolor}
...
\begin{lstlisting}
[language=C,columns=fullflexible,
basicstyle=\ttfamily,
keywordstyle=\bfseries\color{red},
commentstyle=\sffamily\color{green},
stringstyle=\rmfamily\color{orange}]
#include <stdio.h>
/*
 | Prints "hello world"
 */
int main(void)
{
    printf("hello, world\n");
    return 0;
}
:\bfseries\color{Maroon}\textbackslash end:{lstlisting}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}
\end{column}
\hfill\begin{column}{.46\textwidth}
\begin{lstlisting}[language=C,escapechar=~,lineskip=-2pt,
basicstyle=\ttfamily,
commentstyle=\upshape\sffamily\small\color{SeaGreen4},keepspaces=true,
keywordstyle=\bfseries\color{Maroon},stringstyle=\rmfamily\color{Sienna2}]
#include <stdio.h>

/*
 | Prints "hello world"
 */
int main(void)
{
    printf("hello, world\n");
    return 0;
}
\end{lstlisting}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[fragile]
\frametitle{Network Protocols}
\begin{columns}
\begin{column}{.505\textwidth}
\begin{beamerboxesrounded}{}
\vspace{-1em}
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize,
moretexcs={bitheader,wordgroupr,bitbox,endwordgroupr,wordbox},
emph={bytefield,rightwordgroup}]
\usepackage{bytefield}
...
\begin{bytefield}{16}
\bitheader{0,7,8,15} \\
\begin{rightwordgroup}{Header}
\bitbox{4}{Tag} & \bitbox{12}{Mask} \\
\bitbox{8}{Source} &
\bitbox{8}{Destination}
\end{rightwordgroup} \\
\wordbox{3}{Data}
\end{bytefield}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}
\end{column}
\begin{column}{.49\textwidth}\rmfamily\small
\hfill\begin{bytefield}[bitwidth=.75em]{16}
\bitheader{0,7,8,15} \\
\begin{rightwordgroup}{Header}
\bitbox{4}{Tag} & \bitbox{12}{Mask} \\
\bitbox{8}{Source} & \bitbox{8}{Destination}
\end{rightwordgroup}\\
\wordbox{3}{Data}
\end{bytefield}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[fragile]
\frametitle{Life Sciences}

\begin{texshade}{examples/AQPpro.MSF.txt}
\shadingmode{similar}
\threshold[80]{50}
\setends{1}{80..112}
\hideconsensus
\feature{top}{1}{93..93}{fill:$\downarrow$}{first case (see text)}
\feature{bottom}{1}{98..98}{fill:$\uparrow$}{second case (see text)}
\end{texshade}
\vskip-1em
\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[
moretexcs={setends,shadingmode,threshold,hideconsensus,feature,downarrow,uparrow},
emph={texshade},
basicstyle=\ttfamily\small,lineskip=-2pt,escapechar=|]
\usepackage{texshade}  % for nucleotide and peptide alignments
...
\begin{texshade}{AQPpro.MSF.txt}
\shadingmode{similar}
\threshold[80]{50}
\setends{1}{80..112}
\hideconsensus
\feature{top}{1}{93..93}{fill:$\downarrow$}{first case (see text)}
\feature{bottom}{1}{98..98}{fill:$\uparrow$}{second case (see text)}
\end{texshade}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}
\end{frame}

\begin{frame}[fragile]
\frametitle{Circuits and SI Units}
\begin{columns}
\begin{column}{.49\textwidth}\rmfamily
\begin{circuitikz}[transform shape,scale=.9]
\draw (0,0) node[anchor=east] {B}  to[short, o-*] (1,0)    to[R=20<\ohm>, *-*] (1,2)
  to[R=10<\ohm>, v=$v_x$] (3,2) -- (4,2)
  to[ cI=$\frac{\si{\siemens}}{5} v_x$, *-*] (4,0) -- (3,0)  to[R=5<\ohm>, *-*] (3,2)
  (3,0) -- (1,0)   (1,2) to[short, -o] (0,2) node[anchor=east]{A}
;\end{circuitikz}
\end{column}
\begin{column}{.49\textwidth}
\begin{itemize}\rmfamily
\item \SI{3.45d4}{\square\volt\cubic\lumen\per\farad}
\item \SIlist[per-mode=symbol]{40;85;103}{\kilo\metre\per\hour}
\end{itemize}
\end{column}
\end{columns}

\medskip

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize,lineskip=-2pt,
moretexcs={draw,si,siemens,ohm,SI,SIlist,square,volt,cubic,lumen,per,farad,kilo,metre,hour},
emph={siunitx,circuitikz},emph={[2]{draw,node,to}}
]
\usepackage{siunitx}
\usepackage[siunitx]{circuitikz}
...
\begin{circuitikz}
\draw (0,0) node[anchor=east] {B}
  to[short, o-*] (1,0)    to[R=20<\ohm>, *-*] (1,2)
  to[R=10<\ohm>, v=$v_x$] (3,2) -- (4,2)
  to[ cI=$\frac{\si{\siemens}}{5} v_x$, *-*] (4,0) -- (3,0)
  to[R=5<\ohm>, *-*] (3,2)
  (3,0) -- (1,0)   (1,2) to[short, -o] (0,2) node[anchor=east]{A}
;\end{circuitikz}

\SI{3.45d4}{\square\volt\cubic\lumen\per\farad}
\SIlist[per-mode=symbol]{40;85;103}{\kilo\metre\per\hour}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}
\end{frame}

\begin{frame}[fragile]
\frametitle{Meh, What Good is That? Can't Use it Anywhere Else.}
Actually, you can.

\bigskip

\pause
\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[moretexcs={PreviewEnvironment,texshade},basicstyle=\ttfamily,emph={preview}]
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{texshade}
...
\begin{texshade}
...
\end{texshade}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}

\begin{itemize}
\item Run \texttt{pdflatex} $\rightarrow$ cropped \textsmaller{PDF} containing \emph{only} contents of \texttt{texshade}
\pause
\item ImageMagick: \verb|convert -depth 150 texshade.pdf texshade.png|
\pause
\item Multiple environments $\rightarrow$ multi-page \textsmaller{PDF} and multiple \textsmaller{PNG}s
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitle{Bar Codes}
%%% CAUTION!!! This takes a LOOONG time to compile if you're using pdflatex.
% I'm just going to load the already generated PDFs instead.

% \begin{pspicture}
% \psbarcode{MECARD:N:Malaysia Open Source Conference 2011;TEL:+60196085482;URL:http://www.mosc.my/;EMAIL:secretariat@mosc.my;ADR:Bayview Beach Resort, Baru Ferringgi Penang;NOTE:Malaysia Open Source Conference 2011 (MOSC2011);;}{eclevel=L width=0.75 height=0.75}{qrcode}
% \end{pspicture}\;
\includegraphics[page=1]{talk-pics}\;
% \begin{pspicture}
% \psbarcode[scalex=0.7,scaley=0.7]{9781860742712}{ includetext guardwhitespace }{ean13}
% \end{pspicture}\;
\includegraphics[page=2]{talk-pics}\;
% \begin{pspicture}
% \psbarcode[scalex=0.7,scaley=0.7]{978-3-86541-114}{includetext guardwhitespace}{isbn}
% \end{pspicture}\;\;
\includegraphics[page=3]{talk-pics}\;
% \begin{pspicture}
% \psbarcode[scalex=0.7,scaley=0.7]{^453^178^121^239}{ columns=2 rows=10}{pdf417}
% \end{pspicture}%
\includegraphics[page=4]{talk-pics}
\llap{\raisebox{0.45in}{\includegraphics[page=5]{talk-pics}%
% \begin{pspicture}
% \psbarcode[scalex=0.6,scaley=0.6]{LE28HS9Z}{includetext}{royalmail}
% \end{pspicture}
}}

\bigskip

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[moretexcs={psbarcode},escapechar=|,basicstyle=\ttfamily\footnotesize,
emph={pst-barcode},emph={[2]{qrcode,ean13,isbn,pdf417,royalmail,}},
alsoletter={1347-}
]
\usepackage{auto-pst-pdf}  % Needed if running pdflatex; must use option -shell-escape
\usepackage{pstricks,pst-barcode}
...
|\color{Maroon}\bfseries\textbackslash begin|{pspicture}
\psbarcode{MECARD:N:Malaysia Open Source Conference...}{eclevel=L}{qrcode}
\psbarcode{9781860742712}{includetext guardwhitespace}{ean13}
\psbarcode{978-3-86541-114}{includetext guardwhitespace}{isbn}
\psbarcode{LE28HS9Z}{includetext}{royalmail}
\psbarcode{^453^178^121^239}{columns=2 rows=10}{pdf417}
|\color{Maroon}\bfseries\textbackslash end|{pspicture}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}
\end{frame}

\begin{frame}[fragile]
\frametitle{Graph Plots}

{\centering
\pgfplotsset{height=.75\textheight,width=.9\textwidth}
\begin{tikzpicture}[transform shape,scale=.7]
\begin{loglogaxis}[xlabel=Dof]
\addplot table[x=dof,y=L2] {examples/datafile.dat}; \addlegendentry{$L_2$};
\addplot table[x=dof,y=Lmax] {examples/datafile.dat}; \addlegendentry{$L_\text{max}$};
\end{loglogaxis}
\end{tikzpicture}
\par}

\medskip

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize,
emph={pgfplots,tikzpicture,loglogaxis},
moretexcs={addplot, table, addlegendentry,text},lineskip=-2pt]
\usepackage{pgfplots}
...
\begin{tikzpicture}
\begin{loglogaxis}[xlabel=Dof]
\addplot table[x=dof,y=L2]{datafile.dat}; \addlegendentry{$L_2$};
\addplot table[x=dof,y=Lmax]{datafile.dat};  \addlegendentry{$L_\text{max}$};
\end{loglogaxis}
\end{tikzpicture}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}

\end{frame}

\begin{frame}[fragile]
\frametitle{Spreadsheets}
\framesubtitle{(Seriously, use a proper spreadsheet application for complex stuff.)}
\begin{center}\rmfamily\STautoround*{2}
\begin{spreadtab}{{tabular}{l rrr}}
@ Year ending Mar 31 & @2009 & @2008 & @2007\\\midrule
@ Revenue & 14580.2 & 11900.4 & 8290.3\\
@ Cost of sales & 6740.2 & 5650.1 & 4524.2\\\cmidrule{2-4}
@\emph{Gross profit} & \STcopy{>}{b2-b3} & &\\\cmidrule[\lightrulewidth]{2-4}
\end{spreadtab}
\end{center}

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[basicstyle=\ttfamily\small,moretexcs={STcopy,STautoround*},
alsoletter={23->}, emph={spreadtab},
emph={[2]{b2-b3,>}}]
\STautoround*{2}
\begin{spreadtab}{{tabular}{l rrr}}
@Year ending Mar 31 & @2009 & @2008 & @2007\\ \hline
@Revenue & 14580.2 & 11900.4 & 8290.3\\
@Cost of sales & 6740.2 & 5650.1 & 4524.2\\ \cline{2-4}
@\emph{Gross profit} & \STcopy{>}{b2-b3} & &\\ \cline{2-4}
\end{spreadtab}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}

\end{frame}

\begin{frame}[fragile]
\frametitle{Gantt Charts}

\scalebox{.85}{\rmfamily
\begin{ganttchart}%
[y unit title=0.4cm,
y unit chart=0.5cm,
vgrid=true,
title/.style={draw=none, fill=RoyalBlue!50!black},
title label font=\sffamily\bfseries\color{white}, title label anchor/.style={below=-1.6ex},
title left shift=.05,
title right shift=-.05,
title height=1,
bar/.style={draw=none, fill=OliveGreen!75},
bar height=.6,
bar label font=\normalsize\color{black!50},
group right shift=0,
group top shift=.6,
group height=.3, group peaks height=.2,
bar incomplete/.style={fill=Maroon}]{1}{16}
\gantttitle{2010}{4} \gantttitle{2011}{12} \\
\ganttbar%
[progress=100, bar progress label font=\small\color{OliveGreen!75}, progress label anchor/.style={right=4pt},
bar label font=\normalsize\color{OliveGreen},
name=pp]%
  {Preliminary Project}{1}{4} \\
\ganttset{progress label text={}, link/.style={black, -to}}
\ganttgroup{Objective 1}{5}{16} \\
\ganttbar[progress=4, name=T1A]{Task A}{5}{10} \\
\ganttlinkedbar[progress=0]{Task B}{11}{16} \\
\ganttgroup{Objective 2}{5}{16} \\
\ganttbar[progress=15, name=T2A]{Task A}{5}{13} \\
\ganttlinkedbar[progress=0]{Task B}{14}{16}
\end{ganttchart}
}

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize,lineskip=-2pt,
moretexcs={gantttitle,ganttbar,ganttlink,ganttgroup,ganttlinkedbar},
emph={pgfgantt,tikzpicture,ganttchart}]
\usepackage{pgfgantt}
...
\begin{ganttchart}[...settings...]{1}{16}
\gantttitle{2010}{4} \gantttitle{2011}{12} \\
\ganttbar[progress=100]{Preliminary Project}{1}{4} \\
\ganttgroup{Objective 1}{5}{16} \\
\ganttbar[progress=4, name=T1A]{Task A}{5}{10} \\
\ganttlinkedbar[progress=0]{Task B}{11}{16} \\
...
\end{ganttchart}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}

\end{frame}

\begin{frame}[fragile]
\frametitle{`Smart Diagrams'}
\begin{columns}[T]

\begin{column}{.49\textwidth}
\resizebox{\linewidth}{!}{\smartdiagram[bubble diagram]{Planning Cycle,Assess,Plan,Implement,Renew}}

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize,lineskip=-2pt]
\usepackage{smartdiagram}
\smartdiagram[bubble diagram]{
  Planning Cycle,Assess,Plan,
  Implement,Renew}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}
\end{column}

\begin{column}{.49\textwidth}
\resizebox{\linewidth}{!}{\smartdiagram[priority descriptive diagram]{Assess,Plan,Implement,Renew}}

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[basicstyle=\ttfamily\footnotesize,lineskip=-2pt]
\usepackage{smartdiagram}
\smartdiagram
  [priority descriptive diagram]{
  Assess,Plan,Implement,Renew}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}
\end{column}

\end{columns}

% \resizebox{\linewidth}{\smartdiagram[priority descriptive diagram]{Planning Cycle,Assess,Plan,Implement,Renew}}
\end{frame}

\begin{frame}[fragile]
\frametitle{Chess games}

\begin{columns}
\begin{column}{.51\textwidth}

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[basicstyle=\ttfamily\small,
moretexcs={newgame,mainline,chessboard},
emph={skak,chessboard}]
\usepackage[skaknew]%
{skak,chessboard}
...
\newgame
\mainline{1. e4 e5 2. Nf3 Nc6 3. Bb5 a6}
\chessboard[smallboard]
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}
\end{column}

\begin{column}{.47\textwidth}
\rmfamily
\newgame\mainline{1. e4 e5 2. Nf3 Nc6 3. Bb5 a6}

\chessboard[smallboard]

\end{column}
\end{columns}
\end{frame}

\begin{frame}[fragile]
\frametitle{Crossword Puzzles}
\begin{columns}
\begin{column}{.3\textwidth}\rmfamily
\begin{Puzzle}{5}{3}
|* |* |[1]E|X |* |.
|[2]A|[3]S|T |* |[4]T|.
|* |[5]P|A |R |T |.
\end{Puzzle}
\end{column}
\begin{column}{.65\textwidth}\rmfamily
\begin{PuzzleClues}{
\textbf{Across:} }
  \Clue{1}{EX}{unit of measure}
  \Clue{2}{AST}{\(\ast\)}
  \Clue{5}{PART}{sectioning unit}
\end{PuzzleClues}
\begin{PuzzleClues}{
\textbf{Down:} }
  \Clue{1}{ETA}{\(\eta\)}
  \Clue{3}{SP}{unit of measure}
  \Clue{4}{TT}{nonproportional font}
\end{PuzzleClues}
\end{column}
\end{columns}

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{multicols}{2}
\begin{lstlisting}[escapechar=?,basicstyle=\ttfamily\footnotesize,
moretexcs={Clue},emph={cwpuzzle,Puzzle,PuzzleClues}]
\usepackage{cwpuzzle}
...
\begin{Puzzle}{5}{3}
|* |* |[1]E|X |* |.
|[2]A|[3]S|T |* |[4]T|.
|* |[5]P|A |R |T |.
\end{Puzzle}
\begin{PuzzleClues}{
\textbf{Across:} }
  \Clue{1}{EX}{unit of measure}
  \Clue{2}{AST}{\(\ast\)}
  \Clue{5}{PART}{sectioning unit}
\end{PuzzleClues}
\begin{PuzzleClues}{
\textbf{Down:} }
  \Clue{1}{ETA}{\(\eta\)}
  \Clue{3}{SP}{unit of measure}
  \Clue{4}{TT}{nonproportional font}
\end{PuzzleClues}
\end{lstlisting}
\end{multicols}
\vspace{-.5em}
\end{beamerboxesrounded}
\end{frame}

\begin{frame}[fragile]
\frametitle{Song Books with Guitar Tabs}
\vskip-.55\textheight
\begin{guitar}
\rmfamily\smallchords\def\chordsize{.5em}
\renewcommand\yoff{2}
\renewcommand\xoff{0}
\renewcommand\namefont{\footnotesize\sffamily}
\renewcommand\normalsiz{1.1}
\renewcommand\topfretsiz{1.2pt}
\newcommand{\CMaj}{\chord{t}{n,p3,p2,n,p1,n}{C}}
\newcommand{\Amin}{\chord{t}{n,n,p2,p2,p1,n}{Am}}
\newcommand{\FMaj}{\chord{t}{n,n,p3,p2,p1,p1}{F}}
\newcommand{\GMaj}{\chord{t}{p3,p2,n,n,n,p3}{G}}
Country [\CMaj]road, take me [\GMaj]home, to the [\Amin]place I be[\FMaj]long.
West Vir[\CMaj]ginia, mountain [\GMaj]momma, take me [\FMaj]home, country [\CMaj]road.
\end{guitar}

\begin{beamerboxesrounded}{}
\vskip-1em
\begin{lstlisting}[moretexcs={chord,CMaj,Amin,FMaj,GMaj},
emph={gchords,guitar},
basicstyle=\ttfamily\small]
\usepackage{gchords,guitar}
...
\begin{guitar}
\newcommand{\CMaj}{\chord{t}{n,p3,p2,n,p1,n}{C}}
\newcommand{\Amin}...
Country [\CMaj]road, take me [\GMaj]home, ...
\end{guitar}
\end{lstlisting}
\vspace{-1em}
\end{beamerboxesrounded}
\end{frame}


% Created 2018-03-06 mar 16:38
\documentclass[letterpaper,fleqn]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{khpreamble}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\geometry{top=20mm, bottom=20mm, left=24mm, right=18mm}
\author{Kjartan Halvorsen}
\date{}
\title{State feedback exercise}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs 24.5.1 (Org mode 8.2.10)}}
\begin{document}

\maketitle

\section*{Input signal design}
\label{sec-1}
Consider the sampled double-integrator on state-space form
\begin{equation}
\begin{aligned}
x(kh+h) &= \underbrace{\bbm 1 & h\\ 0 & 1\ebm}_{\Phi(h)} x(kh) + \underbrace{\bbm \frac{h^2}{2}\\h\ebm}_{\Gamma(h)} u(kh)\\
y(kh) &= \bbm 1 & 0 \ebm x(kh)
\end{aligned}
\label{eq:ss}
\end{equation}
We want to find the input sequence $u(0)$, $u(h)$ that takes the system from the origin of the state space $x(0) = \bbm 0 & 0 \ebm\transp$ to the point $x(2h) = \bbm a & 0 \ebm\transp$ in two time steps.

\subsection*{Iterate the state space model}
\label{sec-1-1}
\ldots{} in order to find an expression for $x(2h)$ in terms of the unknown input signals
\begin{align*}
x(h) &= \Phi x(0) + \Gamma u(0) \\
x(2h) &= \Phi x(h) + \Gamma u(h) = \Phi\left(\Phi x(0) + \Gamma u(0)\right) + \Gamma u(h)\\
          &= \Phi^2x(0) + \Phi\Gamma u(0) + \Gamma u(h)
          = \Phi^2x(0) + \underbrace{\bbm & & & & \ebm}_{W_c} \bbm u(h)\\u(0) \ebm
\end{align*}

\subsection*{Set up system of equations}
\label{sec-1-2}
With \(u = \bbm u(h) & u(0) \ebm\transp\) we get the linear system of equations \(W_c u = x(2)-\Phi^2x(0)\). In the particular case we are considering here this gives
\[ \bbm & & & & &\\ & & & & &\\ & & & & & \ebm \bbm u(h)\\u(0)\ebm = \bbm & &  \\ && \\ &&\ebm.\]

\newpage

\section*{Verify the result}
\label{sec-2}

\subsection*{Calculate the state sequence}
\label{sec-2-1}
\begin{align*}
x(h) &= \\
x(2h) &=
\end{align*}

\subsection*{Plot the results}
\label{sec-2-2}
\begin{center}
\includegraphics[width=0.6\linewidth]{../figures/empty-input-state-sequences}
\end{center}

\section*{The deadbeat control law}
\label{sec-3}
We are looking for the linear control law \(u(kh) = l_0y_{ref}(kh) - Lx(kh) = l_0y_{ref}(kh) - l_1x_1(kh) -l_2x_2(kh)\) that produced the result above.
\subsection*{Set up the equations}
\label{sec-3-1}
\begin{description}
\item[{\(k=0\):}] \(u(0) = \)
\item[{\(k=1\):}] \(u(h) = \)
\item[{\(k=2\):}] \(u(2h) = \)
\end{description}

\subsection*{Solve the system of equations}
\label{sec-3-2}
Write the system of equations

\[ \bbm & & & & & & & &\\ & & & & & & & &\\ & & & & & & & & \\ & & & & & & & &  \ebm \bbm l_0\\l_1\\l_2\ebm = \bbm && &  \\ &&& \\ &&& \\ && &\ebm.\]

\newpage

\subsection*{The poles of the closed-loop system}
\label{sec-3-3}

Inserting the control law \(u(kh) = l_0y_{ref}(kh) - Lx(kh)\) into the state-space system \eqref{eq:ss} gives the closed-loop system
\begin{equation*}
\begin{aligned}
 x(kh+h) &= \Phi x(kh) + \Gamma u(kh) = \Phi x(kh) - \Gamma L x(kh) + \Gamma l_0y_{ref}(kh)\\
    &= \\
\end{aligned}
\end{equation*}

Determine the poles of the closed-loop system.
% Emacs 24.5.1 (Org mode 8.2.10)
\end{document}


\documentclass[12pt]{article}

\usepackage[margin=1in]{geometry}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{hyperref}

\usepackage{mathpazo}

\newcommand{\nup}{{(\nu)}}
\newcommand{\evm}{{(-)}}
\newcommand{\evz}{{(0)}}
\newcommand{\evp}{{(+)}}

\begin{document}

\begin{center}
{\Large Treatment of gas pressure interface state in Castro + radiation}
\end{center}

\subsection*{Background}

The interface states for radiation work in the primitive variable
system, $q = (\rho, u, p, (\rho e)_g, E_r)^\intercal$, where $p$ is
the gas pressure only, and $(\rho e)_g$ is the gas energy density.

Written in the form:
\begin{equation}
q_t + A(q) q_x = 0
\end{equation}
The matrix $A$ takes the form:
\begin{equation}
A = \left (
\begin{matrix}
u & \rho & 0 & 0 & 0\\
0 & u & {1}/{\rho} & 0 & \lambda_f/{\rho}\\
0 & c_{g}^{2} \rho & u & 0 & 0\\
0 & h_{g} \rho & 0 & u & 0\\
0 & E_{r} \left(\lambda_f + 1\right) & 0 & 0 & u
\end{matrix}\right )
\end{equation}
here, $c_g$ is the gas sound speed and $h_g = e_g + p/\rho$ is the
gas specific enthalpy.
A has eigenvalues, $\lambda^\evm = u - c$, $\lambda^\evz = u$,
$\lambda^\evp = u + c$, where the total sound speed, $c$ is related
to the gas sound speed, $c_g$, as:
\begin{equation}
c^2 = c_g^2 + (\lambda_f + 1)\frac{\lambda_f E_r}{\rho}
\end{equation}
In constructing the interface states, start with a reference state,
$q_\mathrm{ref}$ and define the jumps carried by each wave as the
integral under the parabolic profile with respect to this reference
state:
\begin{equation}
\Delta q^\nup \equiv q_\mathrm{ref} - \mathcal{I}^\nup(q)
\end{equation}
and then the interface states are:
\begin{equation}
q_\mathrm{int} = q_\mathrm{ref} - \sum_\nu (l^\nup \cdot \Delta q^\nup) r^\nup
\end{equation}
Defining:
\begin{align}
\beta^\evm = ( l^\evm \cdot \Delta q^\evm ) &= \frac{1}{2 c^{2}} \left(
    \Delta E_r^\evm \lambda_f + \Delta p^\evm - \Delta u^\evm c \rho\right)\\
&= \frac{1}{2 c^{2}} \left(
    \Delta p_\mathrm{tot}^\evm - \Delta u^\evm c \rho\right)
\end{align}
where we recognized that $p_\mathrm{tot} = p + \lambda_f E_r$.
Similarly, we have:
\begin{align}
\beta^\evp = ( l^\evp \cdot \Delta q^\evp ) &= \frac{1}{2 c^{2}} \left(
    \Delta E_r^\evp \lambda_f + \Delta p^\evp + \Delta u^\evp c \rho\right)\\
           &= \frac{1}{2 c^{2}} \left(
    \Delta p_\mathrm{tot}^\evp + \Delta u^\evp c \rho\right)
\end{align}
and for the 0-wave, we have three degenerate eigenvalues and
eigenvectors.  We label these with the subscripts $\rho$, $\rho e_g$,
and $E_r$, indicating which of the corresponding components in our
primitive variable vector, $q$, is non-zero in the right eigenvector,
$r^\nup$.  Then we have:
\begin{align}
\beta^\evz_\rho &=
    \Delta\rho^\evz  - \frac{\Delta p^\evz_\mathrm{tot}}{c^2} \\
%
\beta^\evz_{{\rho e}_g} &= \Delta(\rho e)^\evz_g - \frac{\Delta p_\mathrm{tot}^\evz}{c^2} h_g \\
%
\beta^\evz_{E_r} &= \Delta E_r^\evz - \frac{\Delta p_\mathrm{tot}^\evz}{c^2} h_r
\end{align}
where $h_r = (\lambda_f + 1)E_r/\rho$.  Note, these match the derivation
done in the Jupyter/SymPy notebook:\newline
{\footnotesize \url{https://github.com/zingale/hydro_examples/blob/master/compressible/euler-generaleos.ipynb}}

The gas pressure update in these terms is:
\begin{equation}
p_\mathrm{int} = p_\mathrm{ref} - (\beta^\evp + \beta^\evm) c_g^2 + \lambda_f \beta^\evz_{E_r}
\end{equation}
This matches the expression in Castro.  Notice that this expression is
unusual for pressure, since it jumps across the $\evz$-wave, whereas
the total pressure would not.

Castro computes the edge state of the radiation energy density as:
\begin{equation}
{E_r}_\mathrm{int} = {E_r}_\mathrm{ref} - (\beta^\evp + \beta^\evm) h_r - \beta^\evz_{E_r}
\end{equation}
and we see that the total pressure can be constructued as
${p_\mathrm{tot}}_\mathrm{int} = p_\mathrm{int} + \lambda_f
{E_r}_\mathrm{int}$, giving:
\begin{equation}
{p_\mathrm{tot}}_\mathrm{int} = {p_\mathrm{tot}}_\mathrm{ref} -
   (\beta^\evp + \beta^\evm) c^2
\end{equation}
This looks, as it should, analogous to the pure hydrodynamics case.

\subsection*{The Interface States}

What is the interface state? for this we need to choose a reference
state.  The choice of reference state should not matter if we counted
the contributions of all waves, then:
\begin{equation}
q_\mathrm{int} = q_\mathrm{ref} - \sum_\nu [ l^\nup \cdot (q_\mathrm{ref} - \mathcal{I}^\nup(q)) ] r^\nup
\end{equation}
and $q_\mathrm{ref}$ cancels out.  However, when we do characteristic
tracing, this is not guaranteed.

In Castro, the quantity $\Delta p^\evz_\mathrm{tot}$ is defined as:
\begin{equation}
\Delta p^\evz_\mathrm{tot} =
  p_\mathrm{tot,ref} - \mathcal{I}^\evz(p_\mathrm{tot})
\end{equation}
and we adopt the common strategy of picking the reference state to be
the $\mathcal{I}$ corresponding to the fastest wave moving toward the
interface.

Consider a zone, $i$, and tracing to the right edge of the zone to
form the interface state, $i+1/2,L$, where $L$ indicates that it is
immediately to the left of the $i+1/2$ interface.  The fastest wave
that can potentially move toward that interface is the $\evp$ wave,
so we pick:
\begin{equation}
q_\mathrm{ref} = \left (
   \begin{array}{c}
     \mathcal{I}^\evp(\rho) \\
     \mathcal{I}^\evp(u) \\
     \mathcal{I}^\evp(p_\mathrm{tot}) \\
     \mathcal{I}^\evp((\rho e)_g) \\
     \mathcal{I}^\evp(E_r)
   \end{array}
\right )
\end{equation}
Looking at the gas pressure interface state, we have:
\begin{equation}
p_\mathrm{int} = p_\mathrm{ref} - \frac{1}{2} \frac{c_g^2}{c^2} \left \{
   \left [ \Delta p_\mathrm{tot}^\evp + \Delta u^\evp c\rho \right ]
 + \left [ \Delta p_\mathrm{tot}^\evm - \Delta u^\evm c\rho \right ] \right \}
 + \lambda_f \left [ \Delta E_r^\evz - \frac{h_r}{c^2} \Delta p^\evz_\mathrm{tot} \right ]
\end{equation}
Substituting in our choice of reference state, we have:
\begin{align}
p_\mathrm{int} = \mathcal{I}^\evp(p) &- \underbrace{\frac{1}{2} \frac{c_g^2}{c^2} \left \{
 \left [ \mathcal{I}^\evp(p_\mathrm{tot}) - \mathcal{I}^\evm(p_\mathrm{tot}) \right ]
   - \rho c \left [ \mathcal{I}^\evp(u) - \mathcal{I}^\evm(u) \right ] \right \}}_{\mbox{\footnotesize carried by the $\evm$ wave}} \\
 &+ \underbrace{\lambda_f \left \{ \left [ \mathcal{I}^\evp(E_r) - \mathcal{I}^\evz(E_r) \right ]
   - \frac{h_r}{c^2} \left [ \mathcal{I}^\evp(p_\mathrm{tot}) - \mathcal{I}^\evz(p_\mathrm{tot}) \right ] \right \}}_{\mbox{\footnotesize carried by the $\evz$ wave}}
\end{align}
We see that the expression for
$p_\mathrm{int}$ starts with the gas pressure.  In the
event that no other waves are moving toward the interface, then we find:
\begin{equation}
p_\mathrm{int} \rightarrow \mathcal{I}^\evp(p)
\end{equation}
(since in our algorithms, we set the $\beta$'s to $0$ if those waves
are not moving toward the interface.

\subsection*{Alternative?}

A, perhaps more consistent, way to handle this is to predict $p_\mathrm{tot}$
and $E_r$ to the interfaces.  This is consistent with our choice of
reference state, and using $p_\mathrm{tot}$ is more analogous to the
pure hydrodynamics case.  We then algebraically construct the
gas-pressure interface state as:
\begin{equation}
p_\mathrm{int} = {p_\mathrm{tot}}_\mathrm{int} - \lambda_f {E_r}_\mathrm{int}
\end{equation}

Note that this extends naturally to multigroup radiation as well, simply by
summing up the independent $E_r$.

\subsection*{$\gamma_e$ system}

The alternate approach that Castro takes to incorporate auxiliary
thermodynamic information into the system is to evolve an equation for
$\gamma_e$.  We use the primitive variable system, $q = (\tau, u, p,
\gamma_e, E_r)^\intercal$, where $\tau = 1/\rho$.  The matrix $A$ now
takes the form:
\begin{equation}
A = \left (
   \begin{matrix}
   u & - \tau & 0 & 0 & 0\\
   0 & u & \tau & 0 & \lambda_f \tau\\
   0 & \frac{c_{g}^{2}}{\tau} & u & 0 & 0\\
   0 & - \alpha & 0 & u & 0\\
   0 & E_{r} \left(\lambda_f + 1\right) & 0 & 0 & u
\end{matrix}\right)
\end{equation}
The eigenvalues are unchanged and the eigenvectors are derived in the
same Jupyter notebook as with the previous system.
Here, $\alpha = (\gamma_e - 1)(\gamma_e - \Gamma_1)$.
Now we have
\begin{align}
\beta^\evp = ( l^\evp \cdot \Delta q^\evp ) &= -\frac{1}{2C}
   \left ( \Delta u^\evp + \frac{\Delta p_\mathrm{tot}^\evp}{C} \right ) \\
\beta^\evz_\tau = ( l^\evz_\tau \cdot \Delta q^\evz ) &=
   \Delta \tau^\evz + \frac{\Delta p_\mathrm{tot}^\evz}{C^2} \\
\beta^\evz_{\gamma_e} = ( l^\evz_{\gamma_e} \cdot \Delta q^\evz ) &=
   \Delta \gamma_E^\evz + \alpha \frac{\Delta p_\mathrm{tot}^\evz}{\tau C^2} \\
\beta^\evz_{E_r} = ( l^\evz_{E_r} \cdot \Delta q^\evz ) &=
   \Delta E_r^\evz - \frac{h_r}{c^2} \Delta p_\mathrm{tot}^\evz \\
\beta^\evm = ( l^\evm \cdot \Delta q^\evm ) &= \frac{1}{2C}
   \left ( \Delta u^\evm - \frac{\Delta p_\mathrm{tot}^\evm}{C} \right )
\end{align}
Here we use the Lagrangian sound speed, $C = \rho c = c/\tau$.

The interface states are then:
\begin{align}
\tau_\mathrm{int} &= \tau_\mathrm{ref} - \beta^\evp - \beta^\evm - \beta_\tau^\evz \\
u_\mathrm{int} &= u_\mathrm{ref} + C (\beta^\evp - \beta^\evm) \\
p_\mathrm{int} &= p_\mathrm{ref} + \frac{c_g^2}{\tau^2} ( \beta^\evp + \beta^\evm) + \beta_{E_r} \lambda_f \\
{\gamma_e}_\mathrm{int} &= {\gamma_e}_\mathrm{ref} - \beta_{\gamma_e}^\evz
   - \frac{\alpha}{\tau} (\beta^\evp + \beta^\evm) \\
{E_r}_\mathrm{int} &= {E_r}_\mathrm{ref} + \frac{h_r}{\tau^2} (\beta^\evp + \beta^\evm) - \beta^\evz_{E_r}
\end{align}
Again, we can also construct the total pressure on the interface:
\begin{align}
{p_\mathrm{tot}}_\mathrm{int} &= p_\mathrm{int} + \lambda_f {E_r}_\mathrm{int}\\
    &= p_\mathrm{ref} + \lambda {E_r}_\mathrm{ref} + \frac{h_r \lambda_f + c_g^2}{\tau^2} (\beta^\evp + \beta^\evm) \\
    &= {p_\mathrm{tot}}_\mathrm{ref} + C^2 (\beta^\evp + \beta^\evm)
\end{align}

\end{document}


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\allowdisplaybreaks

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

\begin{document}
\title{Notes}
\date{November 21, 2014}
\maketitle
\section*{\#8}
find irreducible factors of $x^4-5x^2+6$ over $\mathbb{Q}, \mathbb{Q}(\sqrt{2}),\mathbb{R}$

$\mathbb{Q}(\sqrt{2})$ is $(x-\sqrt{2})(x+\sqrt{2})(x^2-3)$
\section*{\#14}
if $m|n$ then $mk=n$ and $x^m\equiv 1\mod x^m-1$ and $x^{mk}\equiv 1\mod x^m-1$ and $x^n-1\equiv 0\mod x^m-1$

can pull out factors too

assume that $x^m-1|x^n-1$ then $x^n-1\equiv 0\mod x^m-1$ and $x^n=0\mod x^m-1$ and $n=mq+r$ and $x^n\equiv x^r\mod x^m-1$ and so $(x^r-1)|(x^m-1)$ but $r<m$ and so $r=0$

\section*{commutative rings}
what is a ring? a set (often denoted with $R$) with two {\bf binary} operations (indicating closure) similar to fields. ``addition'' operation is abelian group, and ``multiplication'' is associative (and commutative when the ring is commutative) and has an identity. distribution holds. every field is a ring. rings don't require inverse for ``multiplication''.

\subsection*{examples of commutative rings}
$\mathbb{Z},\mathbb{Z}_n,$ if $K$ is a field then $K[x]$ is a commutative ring.

if $R$ is a commutative ring, then $R[x]$ is a commutative ring.

\subsection*{definition}
if $R$ is a comm ring, then we say that $S\subseteq R$ is a subring if $S$ is a comm ring on the same operations as $R$ and has the same identity element.

\subsubsection*{example}
$R\subseteq R[x]$
\section*{proposition}
if $S\subseteq R$ then $S$ is a subring iff
\begin{enumerate}
\item
$S$ is closed under it's operations
\item
if $a\in S$ then $-a\in S$
\item
$1_R\in S$ (identity in $R$ is in $S$)
\end{enumerate}

\subsubsection*{examples}
complex integers: $\mathbb{Z}[i]=\{a+bi:a,b\in\mathbb{Z}\}\subseteq \mathbb{C}$

\subsection*{definition}
we say the $a\in R$ is invertible if $b\in R$ such that $ab=1_R$. another term for this is saying $a$ is a unit, but some books call the identity a unit, so just call it invertible.

\subsubsection*{example}
if $R=\{0\}$ then $1_R=0$.

$\pm 1\in \mathbb{Z}$ are only invertible elements in $\mathbb{Z}$

\subsection*{notation}
$R^{\times}=\{x:x\in R,x \text{ is invertible}\}$

$R=\mathbb{Z}_n\to R^\times=\{[k]:\gcd(k,n)=1\}$

\subsection*{proposition}
if $R$ is a commutative ring, then $(R^\times,\cdot)$ is an abelian group.

\subsection*{definition}
an element $a$ is called a zero divisor if there exists some $ab=0$ where $b\ne 0$.

in $\mathbb{Z}_4$ $[2][2]=[0]$.

\subsection*{definition}
given $R$ a commutative ring, then we say that $R$ is an integral domain (emphasis on integrity and domain) if $1_R\ne 0_R$ and $ab=0$ only when $a=0$ or $b=0$ (that is $0_R$ is the only zero divisor).

\subsubsection*{example}
every field is an integral domain. not that if $ab=0$  then $a^{-1}\in F$ and $ab=a^{-1}ab=a^{-1}0=b=0$ and so we have a contraction if we assume $b\ne 0$.

$\mathbb{R}[x]/\langle x^2-1\rangle$ is not a field because $x^-1$ is reducible but it is a commutative ring.
\end{document}


\documentclass{article}
%\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{color}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{mathrsfs}
\usepackage{enumerate}
\usepackage[margin=1in]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Final 01}
\rhead{Jon Allen}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\degree}{\ensuremath{^\circ}}

\begin{document}
\subsubsection*{PDE A.}
\begin{align*}
  \text{PDE.}&&\frac{\partial u}{\partial t}&=\frac{\partial^2u}{\partial x^2}&&\text{for}&0&<x<1,&0&<t<\infty\\
  \text{BC.}&&u_x(0,t)&=0=u_x(1,t)&&\text{for}&&&0&<t<\infty\\
  \text{IC.}&&u(x,0)&=f(x)&&\text{for}&0&<x<1
\end{align*}

For PDE A, apply separation of variables and, for separated solutions $u=T(t)X(x)$, analyze the associateed eigenvalue problem $X''(x)=\lambda X(x)$ and determine the eigenfunctions (or their nonexistence) for the cases:
\begin{align*}
  u&=T(t)X(x)\\
  \frac{\partial u}{\partial t}&=T'(t)X(x)\\
  \frac{\partial u}{\partial x}&=X'(x)T(t)\\
  \frac{\partial^2 u}{\partial x^2}&=X''(x)T(t)\\
  T'(t)X(x)&=X''(x)T(t)\\
  \intertext{$t$, and $x$ are independant of eachother, therefore:}
  \frac{T'(t)}{T(t)}&=\frac{X''(x)}{X(x)}=\lambda\\
  T'(t)-\lambda T(t)&=0\\
  \omega(t)&=e^{\int{-\lambda\,\mathrm{d}t}}\\
  \omega(t)T(t)&=\int{0\,\mathrm{d}t}=c_3\\
  T(t)&=c_3e^{\lambda t}\\
  X''(x)-\lambda X(x)&=0\\
  X''-\lambda X=0\\
  r^2+0r-\lambda&=0\\
  r&=\frac{{-0}\pm\sqrt{0^2-4(-\lambda)}}{2}\\\
  &=\pm\sqrt{\lambda}
\end{align*}
\begin{enumerate}[(a)]
\item
$\lambda=+\mu^2>0$
\begin{align*}
  r&=\pm\mu\\
  X(x)&=c_1e^{\mu x}+c_2e^{-\mu x}\\
  u_x&=X'(x)T(t)=\left(c_1\mu e^{\mu x}-c_2\mu e^{-\mu x}\right)T(t)\\
  u_x(0,t)&=0=u_x(1,t)\\
  \left(c_1\mu-c_2\mu\right)T(t)&=0=\left(c_1\mu e^\mu-c_2\mu e^{-\mu}\right)T(t)
  \intertext{note that if $T(t)=0$ then we are dealing with the trivial case $u(x,t)=0$ which is not what we are looking for, so we say that $T(t)\ne0$}
  c_1\mu-c_2\mu&=0=c_1\mu e^{\mu}-c_2\mu e^{-\mu}&\mu\ne0\\
  c_1-c_2&=0&c_1=c_2\\
  c_1e^{\mu}-c_1e^{-\mu}&=0\\
  e^\mu&=e^{-\mu}\\
  e^{2\mu}&=1\\
  \ln(e^{2\mu})&=\ln(1)=2\mu=0\\
  \mu&=0
\end{align*}
But we have defined $\mu^2>0$ so we have no solutions.
\item
$\lambda=0$
\begin{align*}
  r&=\pm\sqrt{0}=0\\
  X(x)&=(c_1+c_2x)e^{0x}=c_1+c_2x\\
  u_x(0,t)&=0=u_x(1,t)\\
  c_2T(t)&=0=c_2T(t)\\
  \intertext{Again we take $T(t)\ne0$}
  c_2&=0\\
  X(x)&=c_1&T(t)&=c_3e^{0t}=c_3\\
  u(x,t)&=c_1\cdot c_3=c_4
\end{align*}
So we have one eigenfunction, $u(x,t)=c_0$
\item
$\lambda=-\mu^2<0$
\begin{align*}
  r&=\pm\sqrt{-\mu^2}=\pm\mu i\\
  X(x)&=c_1\cos(\mu x)+c_2\sin(\mu x)\\
  X'(x)&=-c_1\mu\sin(\mu x)+c_2\mu\cos(\mu x)\\
  u_x(0,t)&=0=u_x(1,t)\\
  [c_2\mu\cos(0)-c_1\mu\sin(0)]T(t)&=0=[c_2\mu\cos(\mu)-c_1\mu\sin(\mu)]T(t)\\
  \intertext{Taking $T(t)\ne0$}
  c_2\mu&=0=c_2\mu\cos(\mu)-c_1\mu\sin(\mu)&\mu>0&\to c_2=0\\
  -c_1\mu\sin(\mu)&=0\\
  \intertext{Avoiding the trivial solution requires $\sin(\mu)=0$}
  \mu&=n\pi&n&=1,2,3,\dots\\
  T(t)&=c_3e^{-\mu^2t}=c_3e^{-n^2\pi^2t}\\
  u_n(x,t)&=c_ne^{-n^2\pi^2t}\cos(n\pi x)
\end{align*}
\end{enumerate}
\end{document}


\chapter{Hypothesis testing} % Casella berger, S373
\section{Introduction}
This chapter explains hypothesis testing and p-values. A hypothesis is defined as below.
\begin{defn}
A hypothesis is a statement about a population parameter.
\end{defn}
Furthermore one tests two hypotheses against each other. A definiton of this is as follows.
\begin{defn}
The two complementary hypotheses in a hypothesis testing problem are called the null hypothesis and the alternative hypothesis. They are denoted by $H_0$ and $H_1$, respectivly.
\end{defn}
To do a hypothesis test one need to calculate a test statistic from data. For a one sided test one can assume that the data is outside the null model for large values of the test statistic. In the case of a two sided test the data can be outside the null hypothesis for small values of the test statistic too. This leads to calculation of p-values
\section{P-values} % s397
A p-value can give the result of a hypothesis test. The following defintion and theorem can be found in \cite{casella2002statistical}. First we are going to define a valid p-value.
\begin{defn}
\label{def:valpval}
A p-value $p(\boldsymbol{X})$ is a test statistic satisfying $0 \leq p(\boldsymbol{x}) \leq 1$ for every sample point $\boldsymbol{x}$. Small values of $p(\boldsymbol{X})$ give evidence that $H_1$ is true. A p-value is valid if, for every $\theta \in \Theta_0$ and every $0 \leq \alpha \leq 1$,
\begin{equation}
P_\theta (p(\boldsymbol{X}\leq \alpha)) \leq \alpha.
\end{equation}
\label{defn:validpvalue}
\end{defn}
Then a p-value is as follows.
\begin{theorem}
\label{th:pvalue}
Let $W(\boldsymbol{X})$ be a test statistic such that large values of $W$ give evidence that $H_1$ is true. For each sample point $\boldsymbol{x}$, define
\begin{equation*}
p(\boldsymbol{x}) = \sup_{\theta \in \Theta_0} P_\theta (W(\boldsymbol{X}) \geq W(\boldsymbol{x})).
\end{equation*}
Then, $p(\boldsymbol{X})$ is a valid p-value.
\end{theorem}
The $\Theta_0$ is the subset of the parameter space for the null model.
P-values can also be defined by using sufficient statistics. A p-value is then defined as
\begin{equation}
p(\boldsymbol{x}) = P(W(\boldsymbol{X}) \geq W(\boldsymbol{x}) | S(\boldsymbol{X}) = S(\boldsymbol{x})),
\label{eq:pvalue}
\end{equation}
where $S(\boldsymbol{x})$ is a sufficient statistic under the null hypothesis.
By this definition the p-value given a sufficient statistic is valid as shown below
\begin{equation*}
P_\theta(p(\boldsymbol{X}) \leq \alpha ) = \sum_x P(p(\boldsymbol{X}) \leq \alpha | S(\boldsymbol{X}) =s) P_\theta (S(\boldsymbol{X})=s) \leq \sum_s \alpha P_\theta (S(\boldsymbol{X})=s) = \alpha.
\end{equation*}
This result is for discrete $S(\boldsymbol{X})$. However for the continuous case the one can replace the sums with integrals.
\\
\\
For a two-sided hypothesis test the p-value is found by the equation below,
\begin{equation*}
p(\boldsymbol{x}) = 2(\min(P(W(\boldsymbol{X}) \geq W(\boldsymbol{x})), P(W(\boldsymbol{X}) \leq W(\boldsymbol{x})))).
\end{equation*}
\\ % http://www.math.ntnu.no/~bo/Fordypning/2015/Marius/NHPP-Iran-paper.pdf
\section{Test statistics}
\label{sec:teststat}
As mentioned earlier to calculate the p-value one need a test statistic. A test statistic is often a function which takes a sample as input and gives out a meassure of an certain attribute. For our data we will use several types of test statistics. For the test statistics used, the transformed times are applied. This is has also been done in \cite{lindqvist2011monte}. The transformed times have an uniform distribution between 0 and 1. This is because if the times $t_1,...,t_n$ is from a NHPP then $\Lambda(t_1),...,\Lambda(t_n)$ is a homogenous Poisson distribution with intensity 1. The tranformed times are defined as below.
\begin{equation}
V_j = \frac{\Lambda(t_j)}{\Lambda(\tau)}.
\label{eq:transtimes}
\end{equation}
How to find the transformed times for our NHPP is discussed in section \ref{sec:teststatpvalue}.
The different test statistics used will be introduced below. Here $\hat{V}_j$ are the estimated versions of $V_j$ obtained by using estimated parameters in $\Lambda(\cdot)$.
\subsection{Greenwood statistic}
The Greenwood statistic is a two sided statistic where values are rejected for small and large values.
\begin{equation*}
G = \sum_{j=1}^{n+1} (\hat{V_j} - \hat{V}_{j-1})^2
\end{equation*}
\subsection{Laplace statistic}
This one is also a two sided statistic and are rejected for small and large values.
\begin{equation*}
L = \sqrt{\frac{12}{n}} \sum_{j=1}^{n+1} \left( \hat{V_j} - \frac{1}{2} \right)
\end{equation*}
\subsection{Modified Cramer von Mises statistic}
\begin{equation*}
W^2 = \sum_{j=1}^{n} \left[ \hat{V}_j - \frac{(2j-1)}{2n} \right]^2 + \frac{1}{12n}
\end{equation*}
\subsection{Modified Kolmogorov-Smirnov statistic}
\begin{equation*}
D = max[D^+ , D^-]
\end{equation*}
\begin{equation*}
D^+ = \max_{1 \leq j \leq n} \left( \frac{j}{n} - \hat{V}_j \right)
\end{equation*}
\begin{equation*}
D^- = \max_{1 \leq j \leq n} \left( \hat{V}_j - \frac{(j-1)}{n} \right)
\end{equation*}
\\
\\
Both the Modified Cramer von Mises statistic and Modified Kolmogorov-Smirnov statistic reject the null hypothesis for large values of the statistic.

\section{Test statistics and p-values in NHPP}
\label{sec:teststatpvalue}
To be able to use the test statistics in section \ref{sec:teststat} we need to find the tranformed times as defined in equation \ref{eq:transtimes}. To do this the parameters for the rate function need be estimated. These estimates can be found by using maximum likelihood estimators as defined in chapter \ref{chap:like}. From equation \ref{eq:loglike} we see that finding the maximum likelihood might not be trivial because of the term $\Lambda(\tau)$. However the maximum likelihood can be found numerically in R programming language by using the built in function Optim. Furthermore the integral in equation \ref{eq:largelambda} can also be solved numerically. Hence the tranformed times and test statistics can be calculated.
\\
\\
To calculate the p-value in equation \ref{eq:pvalue} we refer to \cite{iranNHPP}. From this paper we have that the p-value can be estimated by
\begin{equation*}
\hat{p} = \#\{W^* \geq W_{obs}\}/M,
\end{equation*}
where $W^*$ is a test statistic for a sample, $W_{obs}$ is the observed test statistic from original data and $M$ is the number of samples.


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[super,square]{natbib}
\usepackage{tabularx}
\usepackage{parskip}
\usepackage[margin=1.4in]{geometry}
\usepackage{csquotes}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}

\newcommand{\comment}[1]{}

\title{\vspace{-3cm} Ergodic Theory}
\author{}
\date{}

\comment{
TODO:
- add section on statisitcal learning
}

\begin{document}
\maketitle
\vspace{-1.5cm}
\section{Dynamical Systems}
A \textbf{dynamical system}, usually written as the tuple $(T, X)$, is described by a transformation that maps a phase space onto itself, $T: X \to X$. The set of points attained from repeated applications of the transformation from some starting point is known as its \textbf{forward orbit} or trajectory,
\[
\mathcal{O}(x, T) = \{ T^i(x) : i \in \mathbb Z^+ \}.
\]

If the trajectory repeats itself, the point is considered \textbf{periodic}, $T^n(x) = T^m(x), n \neq m $.

\section{Measure}
A measure is an extension of the concepts of length, area, or volume in Euclidean geometry. In a generic space, a measure is a way of assigning a value or weight to different parts of the space.

Let $X$ be a set. A collection $\mathcal{F}$ of subsets of $X$ is called a \textbf{$\sigma$-algebra} if:
\begin{enumerate}
    \item $X$ is in $\mathcal{F}$
    \item If $A$ is in $\mathcal{F}$, then so is the complement of $A$
    \item  if $A_n$ is a countable sequence of sets in $\mathcal{F}$ then their union is in $\mathcal{F}$, i.e. $ \displaystyle \bigcup_{n=1}^{\infty} A_n \in \mathcal{F}$
\end{enumerate}
This definition provides us with sets that can be considered \emph{events} in a probability space, while elements not in $\mathcal{F}$ have no defined probability measure. $\sigma$-algebras allow us to avoid certain undefined behaviour which arises from non-measurable sets.

A function $\mu: \mathcal{F} \mapsto \mathbb{R}^+ \cup \{\infty\}$ is called a \textbf{measure} if:
\begin{enumerate}
    \item $\mu(\emptyset)=0$
    \item if $A_n$ is a countable collection of pairwise disjoint sets in $\mathcal{F}$ (i.e. $A_n \cap A_m = \emptyset$ for $n \neq m$) then
    \[
        \mu \Big(  \bigcup_{n=1}^{\infty} A_n \Big) = \sum_{n=1}^{\infty}\mu(A_n).
    \]
\end{enumerate}

We call $(X, \mathcal{F}, \mu)$ a measure space. If $\mu(X) = 1$ then we consider $\mu$ a probability measure similar to $ 0 \leq Pr(X) \leq 1$ and may refer to $(X, \mathcal{F}, \mu)$ as a probability space.

We say that $T$ is a measure-preserving transformation
or, equivalently, $\mu$ is said to be a $T$-invariant measure if the measure of a set is always the same as the measure of the set of points which map to it, i.e. $\mu(T^{-1}(A))=\mu(A)$ for any measurable set $A \in \mathcal{F}$.

\section{Ergodicity}

Let $(X, \mathcal{F}, \mu)$ be a probability space and let \ $T : X \mapsto X$ be a measure-preserving transformation. We say that $T$ is an \textbf{ergodic transformation}, or that $\mu$ is an \textbf{ergodic measure}, if whenever $A \in \mathcal{F}$ satisfies $T ^{-1}(A) = A$, then $\mu(A) = 0$ or $1$.

Ergodicity can be understood as a measure theoretic version of irreducibility, similar to the inability to split up markov chains into smaller sub-chains. Ergodicity can be viewed as an indecomposability condition and is concerned with how a typical orbit of a dynamical system is distributed throughout the phase space while ergodic theory studies the qualitative distributional properties of typical orbits of a dynamical system with these properties being expressed in terms of measure theory. An ergodic dynamical system is one in which, with respect to some probability distribution, all invariant sets either have measure 0 or 1.

\section{Birkhoff’s Ergodic Theorem}
\begin{quote}
    \begin{enumerate}
        \item
        Let $(X, \mathcal B, \mu, T)$ be a measure-preserving system on a $\sigma$-finite measure space ($\mu(X)< \infty$), and let $f$ be any integrable function.

        \item
        We consider $\hat f$ the time-average of $f$,
        \[
            \hat f(x) = \frac{1}{n}\sum_{i=0}^{n-1} f(T^{i}(x)).
        \]
        $\hat f(x)$ converges for almost every $x \in X$, and is integrable i.e. $\hat f$ is in $L^1(\mu)$. Moreover, $\hat f$ is $T$-invariant, i.e., $ \hat f \circ T = \hat f$.

        \item
        We consider $\bar f$ the space-average of $f$,
        \[
            \bar f = \frac{1}{\mu(x)} \int_{X} f d\mu.
        \]
        For a probability space, $\mu (X)=1$.

        \item
        If $T$ is ergodic, then $\hat f$ is constant in $\mu$ almost everywhere, so we have $\hat f = \bar f$, i.e.
        \begin{align*}
            \displaystyle \lim_{n\to \infty} \frac{1}{n}\sum_{i=0}^{n-1}f(T^{i}(x)) &= \frac{1}{\mu(x)} \int_{X} f d \mu
        \end{align*}
    \end{enumerate}

\end{quote}

If a mapping is ergodic, as the number of finite averages taken along any of its orbit increases to infinity (the time-average), this value will converge to the continuous integral (the space average). That is, a finite average sampling of points of any orbit will be be as accurate as a continuous average integral over the entire state space.

\section{Statistical Mechanics and the Law of Large Numbers}
The term \emph{ergodic} was originally introduced by Ludwig Boltzman, the founder of statistical mechanics, to describe a stronger but related property: starting from a random point in state space, orbits will typically pass through every point in state space. To understand this relation in terms of a mathematical space, consider the \textbf{indicator function} of A, $\mathbb{I_A} :X \to \{0,1\}$ defined by,
\[
	\mathbb I_A(x) = \begin{cases}
		1 &\text{ if $x\in A$}\\ 0 &\text{ otherwise}
	\end{cases}.
\]

The time-average of $\mathbb I_A$ is the fraction of time that the orbit spends in $A$ while the space-average of $I_A$ is the probability that a randomly picked point is in $A$. In an ergodic system, the two averages are almost always equal, meaning almost all trajectories end up covering the state space in the same way. The classical ergodic model is a version of the \textbf{law of large numbers} --- the average of the results obtained from a large number of trials should be close to the expected value and will tend to become closer to the expected value as more trials are performed.

\section{Ergodic Hierarchy}
Ergodicity is at the bottom level of the ergodic hierarchy, where the higher a system is categorized the more random its behaviour. This unpredictability occurs as a result of a decay of correlations between the systems’ past and present states.
\[
\text{Bernoulli} \subset \text{Kolmogorov} \subset \text{Strong Mixing} \subset \text{Weak Mixing} \subset \text{Ergodic}.
\]
We can gain an intuition for a mixing transformation, $T$, through a comparison with stirring two parts $(A, B)$ of a fluid together, meaning that $T^n(A)$ is the region or $n$-orbit of the first part of fluid after $n$ time units of mixing. If the volume of the entire fluid $V$ is equal to $C$, then we consider the fluid to be thoroughly mixed if the concentration of the first part of fluid equals $\mu(A)/\mu(C)$ in both the whole volume of fluid and also in sub-region in the volume. That is, the fluid is thoroughly mixed at time $n$ if
\[
    \frac{\mu(T^n A \cap V)}{\mu(V)}=\frac{\mu(A)}{\mu(C)}
\]
for any volume $V$ (of non-zero measure). We assume that the volume of the combined liquid is one unit, i.e. $\mu(C)=1$, then for all subsets $A$ and $B$ of $X$ a system is \textbf{strong mixing} (S-M) if,
\[
    \displaystyle \lim_{n\to\infty} \mu(T^n B \cap A) = \mu(B) \mu(A).
\]
A system is \textbf{weak mixing} (W-M) if,
\[
    \displaystyle \lim_{n\to \infty} \frac{1}{n}
        \sum_{k=0}^{n-1} | \mu(T^k B \cap A) - \mu(B)\mu(A)|=0.
\]

A system is \textbf{K-mixing} (K-M) if for any subsets $A_0,A_1,...,A_r$ of $X$, where $r$ is an arbitrary natural number, the following condition holds:
\[
    \lim_{n\to\infty}
        \sup_{B \in \sigma(n,r)}
        |\mu(T^n B \cap A) - \mu(B)\mu(A)| = 0
\]

A partition of $X$ is a division of $X$ into different mutually exclusive parts or atoms that jointly cover $X$. A system is a \textbf{Bernoulli system} if if there exists a partition $\alpha$ of $X$ so that the images of $\alpha$ under its transformation $T$ at different instants of time are independent, i.e.
\[
    \mu(\delta \in \beta) = \mu(\delta_i) \mu(\beta_j)
\]
for all atoms $\delta_i$ of $T^k\alpha$ and all atoms $\beta_j$ of $T^l\alpha$ for all $k \neq l$.

\begin{thebibliography}{}
\bibitem{}
https://personalpages.manchester.ac.uk/staff/charles.walkden/magic/

\bibitem{}
https://plato.stanford.edu/entries/ergodic-hierarchy/

\bibitem{}
http://bactra.org/notebooks/ergodic-theory.html

\bibitem{}
https://terrytao.files.wordpress.com/2011/01/measure-book1.pdf

\end{thebibliography}
\end{document}


\section{Conclusion}
All in all, we successfully implemented a deep reinforcement learning architecture using convolutional neural networks, trained with Deep Q-Learning, whose input is raw pixel values, varying between \( \{0, 1, \dots, 255\} \), of a grayscale version of the image of the current state, and output is the most suitable action from the action space. As we demonstrated in our final presentation demo, our trained agent outperforms the random agent with less than an hour of training. As demonstrated, our own group members also played the game using the keyboard agent, although none of the group members can perform more than \(20\) in any of the trials. In this context, the trained agent outperforms every group member with the score of \(28\). Therefore, the answer to our initial question is yes! The trained agent with the specified model can outperform both random and human agents.

Throughout the project, we learned the basic approaches of reinforcement learning. We learned that by using CNNs and DQNs, it is possible to learn control policies directly from high-dimensional sensory input using reinforcement learning. The resultant agent is satisfactory to respond our question with ``yes''. In addition to basic theoretical approach, we also had the chance to interact with a practical issue that we were not expecting to face. While we were trying to adjust the exploration versus exploitation hyperparameter, \(\varepsilon \), we faced with an issue that we later learned it is called the credit assignment problem. The credit assignment problem means that it can happen that we choose an action, and we only win or lose hundreds of actions later, leaving us with no idea of as to which of our actions led to this win or lose, thus, making it difficult to learn from our actions~\autocite{mnih2013playing}. We learned that solely increasing the training duration does increase the performance of the agent. We learned that in order to overcome this credit assignment pitfall, using random restarts actually increases the performance of the agent, by adjusting the exploration versus exploitation problem in the direction of exploration.

As the future work of the project, performance of the agent can be increased by changing the deep neural network architecture and increasing the training duration. During our project, we have encountered with more complex approaches like double DQNs, Never Give-Up (NGU), etc. Experimentation on these approaches can be expressed as potential future work. Furthermore, these approaches can be generalized as \textit{DeepMind}'s \texttt{Agent57} to provide trained agents for \(57\) atari games~\autocite{agent57}.


In this chapter, we give some hints on the automatic computation of the number of index sets, the number of derivatives in the {\tt Interaction} and the levelMin and LevelMax.

\section{Why is the  relative degree not relevant ?}
In this section, we give a very brief overview of the notion of relative degree.

\subsection{First order Linear complementary systems}

 A  Linear Complementarity System (LCS) is defined by
\begin{equation}
  \label{eq:LCS-bis}
  \begin{cases}
    \dot x = A x +B \lambda \\
     y = C x + D \lambda\\
    0 \leq  y \perp \lambda \geq 0 \\
  \end{cases}
\end{equation}
 \begin{definition}[Relative degree in the SISO case]
      Let us consider a linear system in state representation given by the quadruplet $(A,B,C,D) \in \RR^{n\times n}\times\RR^{n \times m}\times \RR^{m\times n}\times\RR^{m\times m} $:
      \begin{equation}
        \label{eq:LS}
        \begin{cases}
          \dot x = A x +B \lambda \\
          y = C x + D \lambda
        \end{cases}
      \end{equation}
      \begin{itemize}
      \item In the Single Input/ Single Output (SISO) case ($m=1$), the relative
        degree is defined by the first non zero Markov parameters :
        \begin{equation}
          \label{eq:Markov-Parameter}
          D, CB, CAB, CA^2B, \ldots, CA^{r-1}B, \ldots
        \end{equation}
      \item In the multiple input/multiple output (MIMO) case ($m>1$), an \textit{uniform} relative degree is defined as follows.
        If $D$ is non singular, the relative degree is equal to $0$. Otherwise, it is assumed to be the first positive integer $r$ such that
        \begin{equation}
          \label{eq:mimo-r}
          CA^{i}B =0, \quad i=0\ldots q-2
        \end{equation}
        while
        \begin{equation}
          \label{eq:mimo-r2}
          CA^{r-1}B \text{ is non singular}.
        \end{equation}
      \end{itemize}
    \end{definition}
    The Markov parameters arise naturally when we derive with respect
    to time the output $y$,
    \begin{eqnarray*}
      \label{eq:y-derive}
      y &=& C x + D \lambda \\
      \dot y &=& CA x + CB \lambda, \text{ if } D= 0  \\
      \ddot y &=& CA^2 x + CAB \lambda, \text{ if }  D=0, CB=0\\
      &\ldots& \\
      y^{(r)} &=& CA^{r} x + CA^{r-1}B \lambda, \text{ if } D=0, CB=0, CA^{r-2}B=0, r=1\ldots r-2 \\
      &\ldots&
    \end{eqnarray*}
    and the first non zero Markov parameter allows us to define the
    output $y$ directly in terms of the input $\lambda$.

In continuous time, the nature of solutions depends strongly on the relative degree. When we want to perform the time--integration of such systems, we need also to reduce the relative degree or to known it to correctly operate.

We can observe that the relative degree $0$ is well defined only by the relation ($D$ nonsingular) and by the nonsmooth law. Indeed, let us imagine that the nonsmooth law is defined by $0\leq\dot y \perp \lambda \geq 0 $. We can easily see that the relative degree is reduced.

In the MIMO, the computation of non uniform relative degree is hard task. This is also the case for nonlinear systems.

\subsection{Second order Lagrangian systems}

Let us consider a second order linear and time-invariant Lagrangian dynamical system (see \S~\ref{Sec:LagrangianLineatTIDS})
\begin{equation}
  \label{eq:rd1}
  \begin{cases}
    M \dot v + C v + K q = F_{Ext}(t) + p \\
    \dot q = v
  \end{cases}
\end{equation}
together with a Lagrangian linear relation
\begin{equation}
  y= Cq + e + D \lambda + Fz,
  \label{eq:rd2}
\end{equation}
\begin{equation}
  p = C^t \lambda
\label{eq:rd3}
\end{equation}
and a simple nonsmooth law,
\begin{equation}
  0\leq y \perp \lambda \geq 0
\label{eq:rd4}
\end{equation}

If $D>0$, the relative degree is uniformly zero and the system can be solved without deriving the output~(\ref{eq:rd2}). Indeed, we known that the solution of the LCP
\begin{equation}
  0\leq Cq + e + D \lambda + Fz, \perp \lambda \geq 0
\label{eq:rd5}
\end{equation}
is unique and Lipschitz with respect to $q$. It can be denoted as $\lambda(q) = \mbox{SOL}(D,Cq + e +Fz)$. Therefore, the differential equation~(\ref{eq:rd1}) reduces to a standard ODE with a Lipschitz RHS
 \begin{equation}
  \label{eq:rd6}
  \begin{cases}
    M \dot v + C v + K q = F_{Ext}(t) + C^t \lambda(q)  \\
    \dot q = v
  \end{cases}
\end{equation}

In the case that we deal with unilateral contact, we usually have $D=0$ and the relative degree of the system is $2$. In this case, the output has to be differentiated as
\begin{equation}
  \label{eq:rd7}
   \dot y= C \dot q,
\end{equation}
and an impact law has to added, for instance the newton's impact law
\begin{equation}
  \label{eq:rd8}
  \text{ if } y=0, \text{ when } \dot y^+= -e y^-
\end{equation}
In the same vein, the equations of motion (\ref{eq:rd1}) is not sufficient since the velocity may encounter jumps. The dynamics is usually replaced by a measure differential equation of the form
\begin{equation}
  \label{eq:rd10}
  \begin{cases}
    M dv + C v^+(t) dt + K q(t) dt = F_{Ext}(t)dt + di \\
    \dot q = v
  \end{cases}
\end{equation}
where $di$ is the measure that can be related to $p$ thanks to
\begin{equation}
  \label{eq:rd11}
  di = p dt + \sigma \delta _{t^*}
\end{equation}
is only one jump is expected at ${t^*}$.

\subsection{Conclusion for the implementation}
From the continuous time mathematical analysis, the relative degree is very important to know if we have to compute the derivatives of the output $y^{(n)}$ and to consider various levels for the input $p , \sigma, ....$

However in the numerical practice,  the time --discretization makes an assumption on the relative degree and treats the nonsmooth law at different levels. The resulting time discretized system posseses more or less variables.

Consider for instance  (\ref{eq:rd1}) in the case of the Moreau scheme
\begin{subnumcases}{\label{eq:MoreauTS}}
  M(v_{k+1}-v_k)  + h  (K q_{k+\theta}+ C v_{k+\theta}) = p_{k+1} = G(q_{k+1}) \lambda_{k+1},\quad\,\\[1mm]
  q_{k+1} = q_{k} + h v_{k+\theta}, \quad \\[1mm]
  \dot y_{k+1} = G^\top(q_{k+1})\, v_{k+1} \\[1mm]
  \begin{array}{l}
    \text{if }\quad\bar y^\alpha_{k+1} \leq 0 \text{ then } 0 \leq \dot y^\alpha_{k+1} + e  \dot y^\alpha_{k} \perp \lambda^\alpha_{k+1}  \geq 0, \\[1mm]
    \text{otherwise  } \lambda^\alpha_{k+1}  =0.\label{eq:MoreauTSd}
  \end{array}, \alpha \in \mathcal I
\end{subnumcases}
and the Schatzman--Paoli  scheme
\begin{subnumcases}{}
  M(q_{k+1}-2q_{k}+q_{k-1})  + h^2 (K q_{k+\theta}+ C v_{k+\theta})  =  p_{k+1},\quad\,\\ \notag\\
  v_{k+1}=\Frac{q_{k+1}-q_{k-1}}{2h}, \\ \notag \\
  y_{k+1} = h\left(\Frac{q_{k+1}+e q_{k-1}}{1+e}\right) \\
  p_{k+1}= G\left(\Frac{q_{k+1}+e q_{k-1}}{1+e}\right) \lambda_{k+1} \\
  0 \leq y_{k+1}  \perp\lambda_{k+1} \geq 0 .
\end{subnumcases}

We can see easily that the number of derivatives (or levels) that we store for $y$ and $\lambda$ is independent on the relative degree but is chosen by the {\tt OneStepIntegrator} with respect to the type of systems.

\section{How to define and compute the various levels and the number of indexSets }

\subsection{$y$ related variables}

The size of the vector {\tt y} in the {\tt Interaction} depends on
\begin{itemize}
\item the {\tt  OneStepIntegrator} type.
  \begin{itemize}
  \item see the difference between the Moreau and Schatzman Paoli
    scheme,
  \item plan the time--discontinuous Galerkin scheme
  \item plan the Higher Order Moreau sweeping process (HOSP)
  \end{itemize}
\item the {\tt  Simulation} type.
  \begin{itemize}
  \item In {\tt Timestepping} or {\tt Event-driven} we do not need the same number of stored $y$
  \end{itemize}

\item the {\tt NonSmoothLaw} type.
  \begin{itemize}
  \item If we consider some cases with or without friction in {\tt
      Timestepping} or {\tt Event-driven}, we need to adapt the number
    of stored $y$
  \end{itemize}

\end{itemize}

Since the various levels of  {\tt y} are used to build the index sets we will need from $0$ to a computed size that depends on the previous criteria. Only a part will be used in the {\tt OneStepNSProblem}.

\subsection{$\lambda$ related variables}

The size of the vector {\tt lambda} in the {\tt Interaction} depends on the same criteria than in the previous section.  Only, the number of lambda is not the same as {\tt y} since a multiplier {\tt lambda[i]} is not necessarily related to {\tt y[i]}

\section{Rules for implementation}

We can define new members in {\tt Interaction}:
\begin{itemize}
\item {\tt \_lowerlevelForOutput}, this value is to $0$ by default
\item {\tt \_upperlevelForOutput},  this value must be computed at initialization with respect to the previous criteria
\item {\tt \_lowerlevelForInput},  this value must be computed at initialization with respect to the previous criteria
\item {\tt \_upperlevelForInput},  this value must be computed at initialization with respect to the previous criteria
\end{itemize}

This level are computed in {\tt Simulation::ComputeLevelsForInputAndOutput}. A visitor is used for the {\tt OneStepIntegrator}. Furthermore, four global levels are computed
\begin{itemize}
\item {\_levelMinForOutput} this value is the minimum level for the output {\tt Interaction::\_lowerlevelForOutput}  for all the interactions
\item {\_levelMaxForOutput} this value is the maximum level for the output {\tt Interaction::\_upperlevelForOutput}  for all the interactions
\item {\_levelMinForInput} this value is the minimum level for the output {\tt Interaction::\_lowerlevelForInput}  for all the interactions
\item {\_levelMaxForInput} this value is the maximum level for the output {\tt Interaction::\_upperlevelForInput}  for all the interactions
\end{itemize}

\begin{itemize}
\item the values {\tt y[i]} must be initialized from {\tt \_lowerlevelForOutput} to {\tt \_upperlevelForOutput}.
\item the values {\tt lamdba[i]} must be initialized from {\tt \_lowerlevelForInput} to  {\tt \_upperlevelForInput}.
\item the values {\tt y[i]} in {\tt Interaction} must be used in priority to store the i-th derivative of $y$. When it is needed, higher index $i$ can be used for other triggering variables. For instance, for an Event--Driven scheme with a Lagrangian systems with friction, sliding velocity must be stored.
\item the values of {\tt lamdba[i]} must stored the various multiplier for the nonsmooth law. We affect the same index $i$ as for the level of {\tt y[i]} present in the corresponding nonsmooth law.
\item The number of {\tt IndexSets} should follows {\tt \_levelMaxForY}.
\end{itemize}

For the dynamical systems :
\begin{itemize}
\item The number of levels for {\tt \_r} and {\tt \_p} in the DS should follow {\tt \_lowerlevelForInput} and {\tt \_upperlevelForOutput} of the associated interactions. This is done in {\tt Interaction::initialize}.
\item A new variable should be added in the LagrangianDS to store the multiplier at the position level ({\tt \_tau} ?) to avoid the use of {\tt \_p[0]}. Indeed, we will continue to assume that {\tt \_p} is the input in the equation of motion. For {\tt lambda} we can  use {\tt lambda[0]}
\end{itemize}

TODO LIST AND QUESTIONS
\begin{itemize}
\item What about the case of multiples interactions on a DS with various {\tt \_lowerlevelForInput} and {\tt \_upperlevelForOutput} ? Normally, all the levels should be correctly initialized thanks to the proposed implementation (r2821)
\item {\tt DynamicalSystem::\_r} should be a VectorOfVectors
\item {\tt DynamicalSystem::\_r} is split in {\tt LagrangianDS}. a first part is {\tt LagrangianDS::\_p}. The other is not implemented !! {\tt LagrangianDS::\_tau} ?
\end{itemize}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "DevNotes"
%%% End:


\section{Results}
\label{sec:Results}
In this section we describe the results of our methodologies on the observational and treatment data. We investigate the relations between features and symptoms of the real data provided in the files\footnote{See GitHub} and determine answers to our questions from the data.

\subsection{Observational Data: Task $1_a$}
\label{subsec:1_a_real}
\graphicspath{{pictures/task1a/}}
In this subsection we use the real data provided in the \textit{Observation-feature.csv} file.

%Methodology 1, observational data
Applying methodology\textsubscript{1} to the observational data, we obtain the following correlations between features and $Death$ shown in Figure \textbf{Figure \ref{fig:1a1r}}. We firstly observe that vaccines have relevant negative correlations, while for positive correlations $CovidPositive$ is the major influencer of $Death$.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{1a1r.png}
  \caption{Correlations between Death and other features for Observational Data.}
    \label{fig:1a1r}
\end{figure}

\begin{figure}[H]
  \includegraphics[width=\linewidth]{1a2r.png}
  \caption{Auto-correlations among features for Observational Data.}
  \label{fig:1a2r}
\end{figure}

The auto-correlation matrix in \textbf{Figure \ref{fig:1a2r}} shows high values of correlation between $CovidPositive$ and some symptoms: such as $No\_Taste/Smell$, $Pneumonia$ and $Blood\_Clots$. Hence, similarly to the synthetic data we found that it is necessary to work in a subset of the data containing only the $CovidPositive$ individuals to eliminate the dependence of symptoms on it. As our experiments with synthetic showed, this should allow us to determine the features which are actually predictive of death.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{1a3r.png}
  \caption{Correlations between Death and selected features for Observational Data.}
    \label{fig:1a3r}
\end{figure}
Then we obtain the following correlations, where we can observe that vaccines are much more strongly predictive of survival. Perhaps even more notably, the features most predictive of death are no longer dominated solely by symptoms, but now show several genes which are especially predictive of death, namely $Gene_{16}$, $Gene_{27}$, $Gene_{63}$, $Gene_{77}$ in the top 5 features. The only symptom remaining among the top 5 predictive features was $Pneumonia$.

%Methodology 2, observational data 1a
Following from the useful indications from methodology\textsubscript{1}, we then use methodology\textsubscript{2}, yielding the conditional probability of death given explanatory features.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{1a7r.png}
  \caption{Conditional Probability of Death given $Feature = 0$.}
    \label{fig:1a7r}
\end{figure}

\begin{figure}[H]
  \includegraphics[width=\linewidth]{1a8r.png}
  \caption{Conditional Probability of Death given $Feature = 1$.}
    \label{fig:1a8r}
\end{figure}

\textbf{Figures \ref{fig:1a7r}} and \textbf{\ref{fig:1a8r}} show the conditional probability of death given the features from the dataset. We see in the plots that the probability of death increased by the greatest amount when conditioned on $Pneumonia$, from a mean of approximately $0.013$ to $0.025$. We also see a small increase in the probability of death when conditioned on the gene features, however the range of values when the genes are present versus not present overlap quite heavily. In this regard, we are not able to deduce that these genes affect the probability of death from methodology\textsubscript{2}.

%Methodology 3, observational data 1a

We then apply our final methodology to the observational data to determine our final conclusions with respect to the effect of genes and symptoms on death in the observational data.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{1a9r.png}
  \caption{Coefficient Values of Logistic Regression observational data, after randomized grid-search 500-fold CV.}
    \label{fig:1a9r}
\end{figure}

\begin{figure}[H]
  \includegraphics[width=\linewidth]{1a10r.png}
  \caption{95\%  Confidence  Interval  for  Logistic  Regression Coefficient Values.}
    \label{fig:1a10r}
\end{figure}

Following our procedure, the $Logistic$ $regression$ models were trained on the top 10 negatively correlated and top 10 positively correlated features from observational data. When trained with all features, including $CovidPositive$, the logistic regression models were unable to predict $Death$ at any better than $0.5$ (i.e. random guess). When the models were trained on a subset containing only the $CovidPositive$ population without feature selection, the best model had an accuracy of $0.71$. Finally, when using the 10 most negatively and 10 most positively correlated features, the best scoring model had an accuracy of $0.87$. This approach therefore remains the same in our subsequent tasks and models trained for methodology\textsubscript{3}.

The resulting coefficient values are as shown in \ref{fig:1a9r}, with $95\%$ confidence intervals for the logistic regression shown in \textbf{Figure \ref{fig:1a10r}}. This is to say that we are $95\%$ confident that the true value of the coefficient will be within the intervals shown in the figure. From this, we can conclude that if a feature has a lower range of possible values, then it is less predictive of death (or more predictive of death if the range is higher than other features).

Based on these results along with the previous methodologies, we return to our first set of questions:

\begin{itemize}
    \item \textit{Can we predict death rate given age, gender, income, genes and comorbidities?}
The logistic regression coefficients and accuracy show that it is possible to train a model which is able to accurately predict death.

    \item Our second question (\textit{Which explanatory features are best to predict death?})
is answered by these results as well, showing that the symptoms and comorbidities which are most effective in predicting death are $Gene_{16}$, $Gene_{63}$ and $Gene_{27}$. $Pneumonia$ did not arise in methodology\textsubscript{3} as a top predictor of death, and $Gene_7$ does not appear from methodologies $1$ and $2$, so we conclude that these features are most likely comparatively less important predictors of death (though likely still risk factors).
\end{itemize}

\subsection{Observational Data: Task $1_b, 1_c$}
In this section we apply our methodologies for estimating the efficacy of vaccines and investigate their possible side-effects. The results of methodology 1 are the same as from Subsection \ref{subsec:1_a_real}, but in this case we focus on the fact that each of the vaccines are highly negatively correlated to death (\textbf{Figure \ref{fig:1a3r}}), indicating that they are possibly effective in preventing it.

%Methodology 2, observational 1bc

On the other hand, methodology\textsubscript{2} differs from our previous analysis, as in this case we are modelling the conditional probability of side-effects (including death) from vaccines.
\graphicspath{{pictures/task1b/}}
\begin{figure}[H]
  \includegraphics[width=\linewidth]{1b5r.png}
  \caption{Conditional  Probability  of  Death  given $Feature = 0$.}
    \label{fig:1b5r}
\end{figure}

\begin{figure}[H]
  \includegraphics[width=\linewidth]{1b6r.png}
  \caption{Conditional  Probability  of  Death  given $Feature = 1$.}
    \label{fig:1b6r}
\end{figure}

\textbf{Figures \ref{fig:1b5r}} and \textbf{\ref{fig:1b6r}} show the conditional probabilities of side-effects where the patient is unvaccinated and vaccinated, respectively. The figures show that the probability of $Death$ is greatly reduced when conditioned on all of the vaccines, with $Vaccine1$ being the most effective (specifically, reducing the probability of death the most). In this case we also observe that the quantiles for the probability of death given vaccines are greatly below the probability of death without vaccines. Interestingly, while both this methodology and methodology\textsubscript{1} show $Vaccine1$ to have the greatest effect on reducing the probability of death, they differ on which of $Vaccine2$ or $Vaccine3$ is the second most effective in preventing death.

An additional aspect of our analysis with methodology\textsubscript{2} is the estimation of side effects from vaccines. With this methodology we are also able to calculate the conditional probability of symptoms given vaccines. \textbf{Figures \ref{fig:1c3r}} and \textbf{\ref{fig:1c4r}} show that the probability of $Fever$ and $Headache$ symptoms was greatly increased when conditioned on the vaccines. Without vaccines the mean probability of $Headache$ was $0.03$ and $Fever$ was $0.05$. $0.05$ for headache, $0.085$ for Fever. We did not find a similar association with any other side-effects.

The mean probability of $Headache$ symptom increased from approximately $0.03$ to $0.05$ when conditioned on each of the vaccines (all resulted in similar mean values), while the mean probability of $Fever$ increased from $0.05$ to $0.085$. For the probability of $Fever$ and $Headache$ conditioned on each of the vaccines, the quantiles of the probability estimate did not overlap with the probability estimate conditioned on not receiving the vaccine. For this reason we conclude that this is a reasonable indication that the vaccines are associated with $Fever$ and $Headache$ as side effects.

\graphicspath{{pictures/task1c/}}
\begin{figure}[H]
  \includegraphics[width=\linewidth]{1c3r.png}
  \caption{Conditional  Probability  of  Symptoms  given $Vaccines = 0$.}
    \label{fig:1c3r}
\end{figure}

\begin{figure}[H]
  \includegraphics[width=\linewidth]{1c4r.png}
  \caption{Conditional  Probability  of  Symptoms  given $Vaccines = 1$.}
    \label{fig:1c4r}
\end{figure}

%Methodology 3, observational 1bc

Next, turning to methodology\textsubscript{3}, we train $Logistic$ $regression$ models predicting symptoms including death. As with methodology\textsubscript{1}, we refer to the same models described in \ref{subsec:1_a_real} to determine the answer to our second set of questions (Tasks 1b and 1c). The top 3 negative features in the logistic regression model are the three vaccines (\textbf{Figure} \ref{fig:1a9r}), indicating that they are the most predictive of survival. The order of greatest effectiveness can be loosely observed as $Vaccine1$, $Vaccine2$, $Vaccine3$. This  Nonetheless, the confidence intervals on the effectiveness of each vaccine (as measured with the coefficient values) broadly overlap (\textbf{Figure \ref{fig:1a10r}}) and all three can be considered "effective" under this measure (and there may be no reason for a patient to, for instance, prefer $Vaccine1$ to $Vaccine3$ in practice).

%Side effects here

In conclusion with this, we answer the questions posed for Tasks 1b and 1c.
\begin{itemize}
\item \textit{Can we predict death rate (efficacy) of a vaccine?}
Yes, our methodologies indicate that all three vaccines are very effective in reducing the chance of death in the Covid-Positive population.

\item \textit{Which vaccine is most effective?}
Our analysis indicates that $Vaccine1$ is the most effective of the three. However, we cannot definitively say whether $Vaccine2$ or $Vaccine3$ is superior, as the results of our methodologies differ on which is more predictive of survival.

\item \textit{Can we predict a specific symptom(s) (side-effect(s)) of a vaccine?}
Through analyzing the conditional probability estimates obtained in methodology\textsubscript{2}, we predict that all three of the vaccines in the data are associated with side-effects of $Headache$ and $Fever$. In the case of features such as blood clots, the conditional probability estimates do not differ sufficiently from the conditional probability of death without the vaccines to conclude that the vaccines may cause them as side effects. Blood clots may be associated with $Vaccine2$ as shown in \ref{fig:1c4r}, but the overlap between this estimate and the baseline is too great to rule out the possibility of this being merely random chance.

\item \textit{Which side-effect(s) each vaccine produce?}
From our analysis it appears that all three vaccines produce $Fever$ and $Headache$ as side-effects, with the unconfirmed possibility of blood clots from $Vaccine3$, as noted above.
\end{itemize}
\subsection{Treatment Data: Task $2$}
\graphicspath{{pictures/task2/}}
In the final subsection we use the real data contained in the files 'treatment\_features.csv', 'treatment\_action.csv' and 'treatment\_outcome.csv' regarding the treatments.

%Methodology 1, treatment data (Task 2)
We again perform methodology\textsubscript{1} in order to obtain the correlations of features in the data. The results shown in \textbf{Figure \ref{fig:2_1r}} are similar to those in the observational data, with the new addition of $Treatment2$ as a variable which is highly negatively correlated with death. Notably, we do not observe $Treatment1$ in the top 10 negatively correlated variables.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{2_1r.png}
  \caption{Correlations between Death and selected features for Observational Data.}
    \label{fig:2_1r}
\end{figure}

% Methodology 2, treatment data (Task 2)

We then proceed with analyzing \textbf{Figures \ref{fig:2_5r_top}} and \textbf{Figures \ref{fig:2_6r_top}} using methodology\textsubscript{2}. The results show that the probability of $Death$ conditioned on $Treatment2$ appears to be lowered, but there is some overlap in the estimates from this method. For this reason, these results may not be as indicative in establishing that $Treatment2$ is effective in preventing $Death$.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{2_5r_top.png}
  \caption{Conditional Probability of $Death$ given selected $Features = 0$.}
    \label{fig:2_5r_top}
\end{figure}
\begin{figure}[H]
  \includegraphics[width=\linewidth]{2_6r_top.png}
  \caption{Conditional Probability of $Death$ given selected $Features = 1$.}
    \label{fig:2_6r_top}
\end{figure}

We also observe in \textbf{Figures \ref{fig:2_5r_after}} and \textbf{\ref{fig:2_6r_after}} that the probability of symptoms when conditioned on treatments are very similar to the probability when conditioned on the absence of treatment. The one notable feature of these charts is that the probability of $Blood\_clots$ conditioned on $Treatment 1$ is $0$. This is however a very marginal result and so we can not establish any evidence of side-effects from treatments using this method. We note that the amount of total samples in the data was very small, particularly with respect to certain symptoms. This may be a reason that this methodology does not reach a clear conclusion and estimates several probabilities precisely at $0$.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{2_5r_after.png}
  \caption{Conditional Probability of Symptoms given $Treatments = 0$.}
    \label{fig:2_5r_after}
\end{figure}
\begin{figure}[H]
  \includegraphics[width=\linewidth]{2_6r_after.png}
  \caption{Conditional Probability of Symptoms given $Treatments = 1$.}
    \label{fig:2_6r_after}
\end{figure}

%Methodology 3, treatment data (Task 2)

Our last analysis of the treatment data is performed with methodology\textsubscript{3}. In this case, due to the scarcity of data points, we train the $Logistic$ $regression$ model using bootstrapping to re-sample the data, in order to balance the outcomes for the training process. The resulting best model accuracy is $0.98$ with confidence intervals as in \textbf{Figure \ref{fig:2_12r}}. We observe once again in \textbf{Figure \ref{fig:2_11r}} that the the coefficient for $Treatment1$ is not in the top selected features. On the other hand, $Treatment2$ is once again among the most negatively associated variables with $Death$. Combined with our observation from methodology\textsubscript{1}, this indicates that $Treatment2$ is effective at preventing $Death$, and very likely more effective than $Treatment1$.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{2_11r.png}
  \caption{Coefficient Values of Logistic Regression, after randomized grid-search 500-fold CV.}
    \label{fig:2_11r}
\end{figure}

\begin{figure}[H]
  \includegraphics[width=\linewidth]{2_12r.png}
  \caption{95\%  Confidence  Intervals  for  Logistic  Regression Coefficient Values.}
    \label{fig:2_12r}
\end{figure}

We are then able to answer the questions we posed for Task 2.

\begin{itemize}
\item \textit{Can we predict death rate given a specific treatment?}
Yes, we are able to train a logistic regression model which is able to predict death among the $CovidPositive$ population with an cross-validated accuracy of $0.98$.
\item \textit{Which treatment is the most effective?}
We estimate that the probability of death for a patient given $Treatment2$ is lower than without treatment, as well as lower than when given $Treatment1$. While $Treatment1$ may still be effective in preventing death (we do not establish that it is not), our analysis indicates that $Treatment2$ is more effective.
\item \textit{Can  we  predict  a  precise  symptom(s)(side-effect(s))  given  a  specific  treatment?}
We were not able to establish that any side-effects were more likely given either of the treatments. We speculate that this may be due to the low number of samples for each symptom, such that our calculation of conditional probabilities was not able to make an precise estimate approximating the actual outcomes.
\item \textit{Which side-effect(s) does each treatment produce?}
As noted in the previous answer, we cannot establish any side-effects from the treatments, and conversely we also do not establish that the treatments do \textbf{not} cause side effects.
\end{itemize}


\RequirePackage[l2tabu, orthodox]{nag}
\documentclass[a4paper]{article}
\usepackage[a4paper]{geometry}
\usepackage[colorlinks=false, pdfborder={0 0 0}]{hyperref}
\usepackage{array,multirow,amsmath,amssymb,esint,bm,siunitx,cleveref}
\renewcommand{\arraystretch}{2.5}
\title{Green's Function}
\author{Naitree Zhu}
\date{Last modified: \today}
\begin{document}
\maketitle
In mathematics, a Green's function\footnote{More information:\url{http://en.wikipedia.org/wiki/Green\%27s_function}} is the impulse response of an inhomogeneous differential equation defined on a domain, with specified initial conditions or boundary conditions. Via the superposition principle, the convolution of a Green's function with an arbitrary function $f(x)$ on that domain is the solution to the inhomogenous differential equation for $f(x)$.

Green's functions are named after the British mathematician George Green, who first developed the concept in the 1830s. In the modern study of linear partial differential equations, Green's functions are studied largely from the point of view of fundamental solutions instead.

Under many-body theory, the term is also used in physics, specifically in quantum field theory, aerodynamics, aeroacoustics, electrodynamics and statistical field theory, to refer to various types of correlation functions, even those that do not fit the mathematical definition.
\part{Definition and Use}
A Green's function, $G(x,s)$, of a linear differential operator$L=L(x)$ acting on distributions over a subset of the Euclidean space $R^{n}$, at a point s, is any solution of
\begin{equation}
L^{*}\,G(x,s)=\delta(x-s)
\end{equation}
where $\delta$ is the Dirac delta function and $L^{*}$ is the adjoint $L$. In the case of a self-adjoint operator, the equation can be written as
\begin{equation}
L\,G(x,s)=\delta(x-s)
\end{equation}
If the kernel of L is non-trivial, then the Green's function is not unique. However, in practice, some combination of symmetry, boundary conditions and/or other externally imposed criteria will give a unique Green's function. Also, Green's functions in general are distributions, not necessarily proper functions.

Green's functions are also useful tools in solving wave equations and diffusion equations. In quantum mechanics, the Green's function of the Hamiltonian is a key concept with important links to the concept of density of states. As a side note, the Green's function as used in physics is usually defined with the opposite sign; that is,
\begin{equation}
L\,G(x,s)=-\delta(x-s)
\end{equation}
This definition does not significantly change any of the properties of the Green's function.
\part{Motivation}
Loosely speaking, if such a function $G$ can be found for the operator $L$, then if we multiply the equation (2) for the Green's function by $f(s)$, and then perform an integration in the $s$ variable, we obtain:
\begin{align*}
\int L\,G(x,s)\,f(s)\,\mathrm{d}s&=\int \delta(x-s)\,f(s)\,\mathrm{d}s\\&=f(x)\\&=L\,u(x)
\end{align*}
i.e.
\[
L\,u(x)=\int L\,G(x,s)\,f(s)\,\mathrm{d}s
\]
Because the operator $L = L(x)$ is linear and acts on the variable $x$ alone, we can take the operator $L$ outside of the integration on the right-hand side (Note it's definitive integral over the region that the operator $L$ is acting on), obtaining
\[
L\,u(x)=L\left(\int G(x,s)\,f(s)\,\mathrm{d}s\right)
\]
Provided operator $L$ is arbitrary, so it suggests
\begin{equation}
u(x)=\int G(x,s)\,f(s)\,\mathrm{d}s
\end{equation}
Thus, we can obtain the function $u(x)$ through knowledge of the Green's function in equation (2) and the source term on the right-hand side in equation (3). This process relies upon the linearity of the operator $L$. The problem now lies in finding the Green's function $G$ that satisfies equation (2). For this reason, the Green's function is also sometimes called the fundamental solution associated to the operator $L$.

Not every operator $L$ admits a Green's function. A Green's function can also be thought of as a right inverse of $L$. Aside from the difficulties of finding a Green's function for a particular operator, the integral in equation (4), may be quite difficult to evaluate. However the method gives a theoretically exact result.
\part{Finding Green's functions}
\section{Eigenvalue expansions}
If a differential operator $L$ admits a set of eigenvectors $\Psi_{n}(x)$ (i.e., a set of functions $\Psi_{n}$ and scalars $\lambda_{n}$ satisfying $L\Psi_{n}=\lambda_{n}\Psi_{n}$) that is complete, then it is possible to construct a Green's function from these eigenvectors and eigenvalues.
``Complete'' means that the set of functions $\lbrace\Psi_{n}\rbrace$ satisfies the following completeness relation:
\begin{equation}
\delta(x-x')=\sum_{n=0}^\infty\Psi_n^\dag(x)\Psi_{n}(x')
\end{equation}
Then the following holds:
\begin{equation}
G(x,x')=\sum_{n=0}^\infty\frac{\Psi_{n}^\dag(x)\,\Psi_{n}(x')}{\lambda_{n}}
\end{equation}
where \dag represents complex conjugation.

Applying the operator $L$ to each side of this equation results in the completeness relation, which was assumed true.

The general study of the Green's function written in the above form, and its relationship to the function spaces formed by the eigenvectors, is known as Fredholm theory.
\section{Table of Green's functions}
The following table gives an overview of Green's functions of frequently appearing differential operators, where $\theta(t)$ is the Heaviside step function,$r=\sqrt{x^2+y^2+z^2}$ and $\rho=\sqrt{x^2+y^2}$.
\begin{table}[h]
\centering
\caption{Green's functions of some common operators}
\begin{tabular}{|>{$}c<{$}|>{$}c<{$}|>{$}m{4.85cm}<{$}|}
\hline
\text{Differential Operator}\,L & \text{Green's Function}\,G & \text{Example of application}\\
\hline
\displaystyle \partial_t+\gamma &\displaystyle \theta(t)e^{-\gamma t}&\\
\hline
\displaystyle \left(\partial_t +\gamma\right)^2&\displaystyle \theta(t)te^{-\gamma t}&\\
\hline
\multirow{2}{*}{$\displaystyle \partial_t^2 + 2\gamma\partial_{t}+\omega_0^2$} & \displaystyle \theta(t)e^{-\gamma t}\frac{1}
{\omega}sin(\omega t) & \text{one-dimensional damped harmo-}\\ &\text{with }\omega=\sqrt{\omega_0^2
-\gamma^2}&\text{nic oscillator}\\
\hline
\displaystyle \Delta_{2D}=\partial_x^2 +\partial_y^2 & \displaystyle \frac{1}{2\pi}\ln \rho &\\
\hline
\displaystyle \Delta=\partial_x^2 +\partial_y^2+\partial_z^2 &\displaystyle \frac{-1}{4\pi r}& \text{Poisson equation}\\
\hline
\text{Helmholtz operator}\,\displaystyle \Delta +k^2&\displaystyle \frac{-e^{-ikr}}{4\pi r}&\text{stationary Schr\"{o}dinger equation}\\
\hline
\text{D'Alembert operator}\, \displaystyle \square=\frac{1}{c^2}\partial_t^2-\Delta &\displaystyle \frac{\delta(t-\frac{r}{c})}{4\pi r}&\text{wave equation}\\
\hline
\displaystyle \partial_t-D\Delta &\displaystyle \theta(t)\left(\frac{1}{4\pi Dt}\right)^{\frac{3}{2}}e^{\frac{r^2}{4Dt}}&\text{diffusion}\\
\hline
\end{tabular}
\end{table}
\part{Green's functions for the Laplacian}
Green's functions for linear differential operators involving the Laplacian may be readily put to use using the second of Green's identities:
\begin{equation}
\int_V \left(\varphi\nabla^{2}\psi-\psi\nabla^{2}\varphi\right)\mathrm{d}V=\oint_S\left(\varphi\frac{\partial\psi}{\partial n}-\psi\frac{\partial \varphi}{\partial n}\right)\mathrm{d}S
\end{equation}
Suppose that the linear differential operator $L$ is the Laplacian $\nabla^2$, and that there is a  Green's function $G$ for the Laplacian.

According to the defining property of the Green's function,
\begin{equation}
L\,G(x,x')=\nabla^2 G(x,x')=\delta(x-x')
\end{equation}
Let $\psi=G$ in Green's second identity.Then:
\begin{equation}
\int_V \left(\varphi\delta(x-x')-G(x,x')\nabla'^2\varphi\right)\mathrm{d}V'=\oint_S\left(\varphi\frac{\partial G(x,x')}{\partial n'}-G(x,x')\frac{\partial \varphi}{\partial n'}\right)\mathrm{d}S'
\end{equation}
Using this expression, it is possible to solve Laplace's equation $\nabla^2\varphi=0$ or Poisson's equation $\nabla^2\varphi(x)=-\rho(x)$, subject to either Dirichlet or Neumann boundary conditions. In other words, we can solve for $\varphi(x)$ everywhere inside a volume where one of the following conditions are satisfied:
\begin{enumerate}
\item the value of $\varphi(x)$ is specified on the bounding surface of the volume.
\item the normal derivative of $\varphi(x)$ is specified on the bounding surface.
\end{enumerate}
This is specified followingly.

Suppose the problem is to solve for $\varphi(x)$ inside the region. Then according to the defining property of the Dirac delta function, we have：
\begin{equation}
\varphi(x)=\int_V G(x,x')\rho(x')\mathrm{d}V'+\oint_S\left(\varphi\frac{\partial G(x,x')}{\partial n'}-G(x,x')\frac{\partial \varphi}{\partial n'}\right)\mathrm{d}S'
\end{equation}
\begin{enumerate}
\item If the problem is to solve a Dirichlet boundary value problem, the Green's function should be chosen such that $G(x,x')$ vanishes when either $x$ or $x'$ is on the bounding surface. Thus only the first of the two terms in the surface integral remains.
\item If the problem is to solve a Neumann boundary value problem, the Green's function is chosen such that its normal derivative vanishes on the bounding surface, as it would seem to be the most logical choice. However, this is not possible. Intuitively, Green's function suggests that a source of field exists in the region. So the integral of field at the boundary,i.e. flux outward the region must be nonzero. And mathematically,
\begin{equation}
\oint_S \frac{\partial G(x,x')}{\partial n'}\mathrm{d}S'=\int_V \nabla'^2 G(x,x')\mathrm{d}V'=\int_V \delta(x-x')\mathrm{d}V'=1
\end{equation}
so $\frac{\partial G(x,x')}{\partial n'}$ can not be 0 at the boundary, otherwise the first integral equals to zero and divergence theorem is violated. Thus, the simplest form the normal derivative can take is that of a constant, namely letting $\frac{\partial G(x,x')}{\partial n'}=\frac{1}{S}$, where $S$ is the surface area of the surface. The first surface term in eq.~(10) becomes
\begin{equation}
\oint_S \frac{\partial G(x,x')}{\partial n'}\mathrm{d}S'=\left<\varphi\right>_S
\end{equation}
where $\left<\varphi\right>_S$ is the average value of the potential on the surface. This number is not known in general, but is often unimportant, as the goal is often to obtain the electric field given by the gradient of the potential, rather than the potential itself.
\end{enumerate}

Supposing the boundary goes out to infinity and $G=0$ at infinity (Dirichlet problem), the corresponding Green's function is
\begin{equation}
G(x,x')=\frac{1}{\lvert x-x' \rvert}
\end{equation}
Applying this to eq.~(10) gives familiar expression for electric potential:
\begin{equation}
\varphi(x)=\int_V \frac{\rho(x')}{\lvert x-x' \rvert}\mathrm{d}V'
\end{equation}
Notice that because of the defining property eq.~(8) of Green's function for Laplacian and infinity boundary condition stated above, the corresponding Green's function eq.~(13) is exactly what a point charge would behave under the same boundary condition.
\end{document}