 %% Private

  %% Old: Once the ordered set of constraints is defined, we discuss the idea of introducing an additional constraint to the set. The introduction of an additional constraint is problematic because it can hide or render irrelevant constraints that already exist in the set. However, by restricting the analysis to the \textit{relevant} set of constraints, we are able to

  %% Old: We now move on to the sources of consumption concavity. In our setting, there are two sources of consumption concavity: risk and constraints. The properties of consumption under risk have already been derived in \citet{carroll&kimball:concavity}. We therefore restrict our attention to showing how liquidity constraints make the consumption function concave. Once the relationship between liquidity constraints and consumption concavity is established, we use the results on consumption concavity and prudence to show under which conditions liquidity constraints heighten prudence.

  \subsection{Liquidity Constraints and Kink Points}\label{sec:LCandKinks}
  Recall that we are working with a consumer whose horizon goes from $0$ to $T$. We define a liquidity constraint dated $t$ as a constraint that requires savings at the \textit{end of period} $t \in (0, T]$ to be non-negative (the assumption of non-negativity is without loss of generality as shown in Theorem \ref{thm:lcip2}).

  We first define what we mean by a kink point which is induced by a constraint. To have a distinct terminology for the effects of current-period and future-period constraints, we will use the word `binds' to refer to the potential effects of a constraint in the period in which it applies and will use the term `impinges' to describe the effect of a future constraint on current consumption.
  \begin{defn}(Kink Point.) \\
    We define a kink point, $\wAlt_{t,n}$ as the level of market resources at which constraint $n$ stops binding or impinging on time $t$ consumption.
  \end{defn}
  \noindent A kink point corresponds to a transition from a level of market resources where a current constraint binds or a future constraint impinges, to a level of market resources where that constraint no longer binds or impinges.

  The timing of a constraint relative to other existing constraints matters for the effects of the constraint. We therefore define an ordered set to keep track of the existing constraints.
  \begin{defn} (An Ordered Set of Relevant Constraints.) \\
    We define $\mathcal{T}$ as an ordered set of dates at which a relevant constraint exists. We define $\mathcal{T}[1]$ as the last period in which a constraint exists, $\mathcal{T}[2]$ as the date of the last period before $\mathcal{T}[1]$ in which a constraint exists, and so on.
  \end{defn}
  \noindent $\mathcal{T}$ is the set of relevant constraints, ordered from the last to the first constraint. We order them from last to first because a constraint in period $t$ only affects behavior prior to period $t$ (and $t$ itself). The set of constraints from period $t$ to $T$ summarizes all relevant information in period $t$. Further, and as discussed below, the effect of imposing the next constraint in $\mathcal{T}$ on consumption is unambiguous only if one imposes constraints chronologically from last to first (and all constraints are of the no-borrowing type).

  For any $t \in [0, T)$, we define $c_{t,n}$ as the optimal consumption function in period $t$ assuming that the first $n$ constraints in $\mathcal{T}$ have been imposed. For example, $c_{t,0}({m})$ is the consumption function in period $t$ when no constraint has been imposed, $c_{t,1}({m})$ is the consumption function in period $t$ after the chronologically last constraint has been imposed, and so on. $\Omega_{t,n}, V_{t,n}$, and other functions are defined correspondingly.

  \subsection{A Fixed Set of Constraints}\label{subsec:Piecewise}

  We first consider an initial situation in which a consumer is solving a perfect foresight optimization problem with a finite horizon that begins in period $t$ and ends in period $T$. The consumer begins with market resources ${m}_{t}$ and earns constant income ${y}$ in each period. Lemma \ref{lem:LcAndCc} shows how this consumer's behavior in period $t$ changes from an initial situation with $n\geq 0$ constraints to a situation in which $n+1$ liquidity constraints has been imposed.

  \begin{lemma}\label{lem:LcAndCc}(Liquidity Constraints Cause Counterclockwise Concavification.) \\
    Consider an agent who has a utility function with $u'> 0 $ and $u'' < 0$, faces constant income ${y}$, and is impatient ($\beta R < 1$). Assume that the agent faces a set $\mathcal{T}$ of $N$ relevant constraints. Then $c_{t,n+1}({m})$ is a counterclockwise concavification of $c_{t,n}({m})$ around $\wAlt_{t,n+1}$ for $n \leq N-1$.
  \end{lemma}

  \noindent See Appendix \ref{app:pfclc} for the proof. When we have an ordered set of constraints, $\mathcal{T}$, the introduction of the next constraint generates a counterclockwise concavification of the consumption function.

  \subsection{Additional Constraints}
  \label{subsec:IncreaseNumConstr}

  Lemma \ref{lem:LcAndCc} analyzes the case where there is a preordained set of constraints $\mathcal{T}$ which were applied sequentially in reverse chronological order. We now examine how behavior will be modified if we add a new date $\hat{\tau}$ to the set of dates at which the consumer is constrained.

  Call the new set of dates $\hat{\mathcal{T}}$ with $N+1$ constraints (one more constraint than before), and call the consumption rules corresponding to the new set of dates
  $\hat{c}_{t,1}$ through $\hat{c}_{t,N+1}$. Now call $m$ the
  number of constraints in $\mathcal{T}$ at dates strictly
  greater than $\hat{\tau}$.  Then note that that $\hat{c}_{\hat{\tau},m} =
  c_{\hat{\tau},m}$, because at dates after the date at which the new constraint (number $m+1$) is
  imposed, consumption is the same as in the absence of the new constraint.
  Now recall that imposition of the constraint at $\hat{\tau}$ causes a counterclockwise concavification of the consumption function around a new kink point, $\wAlt_{\hat{\tau},m+1}$. That is, $\hat{c}_{\hat{\tau},m+1}$ is a counterclockwise concavification of $\hat{c}_{\hat{\tau},m} = c_{\hat{\tau},m}$.

  The most interesting observation, however, is that behavior under constraints $\hat{\mathcal{T}}$ in periods strictly before $\hat{\tau}$ \textit{cannot} be described as a counterclockwise concavification of behavior under $\mathcal{T}$.  The reason is that the values of wealth at which the earlier constraints caused kink points in the consumption functions before period $\hat{\tau}$ will not generally correspond to kink points once the extra constraint has been added.

  \hypertarget{CurrConstrHidesFutKink}{}

  \begin{figure}[ht]
    {\centering \includegraphics[width=.95\textwidth]{\FigDir/CurrConstrHidesFutKink}}
    \caption{How a future constraint can move a current kink}
    \footnotesize {\emph{Notes:} $c_{t,1}$ is the original consumption function with one constraint that induces a kink point at $\omega_{t,1}$. $\hat{c}_{t,2}$ is the modified consumption function in where we have introduced one new constraint. The two constraints affect $\hat{c}_{t,2}$ through two kink points: $\hat{\omega}_{t,1}$ and $\hat{\omega}_{t,2}$. Since we introduced the new constraint at a later point in time than the current existing constraint, the future constraint affects the position of the kink induced by the current constraint and the modified consumption function $\hat{c}_{t,2}$ is not a counterclockwise concavification of ${c}_{t,1}$.}
    \label{fig:LCtHidesLCtpn}
  \end{figure}

  Figure~\ref{fig:LCtHidesLCtpn} presents an example. The original $\mathcal{T}$ contains only a single constraint, at the end of period $t+1$, inducing a kink point at $\wAlt_{t,1}$ in the consumption rule $c_{t,1}$. The expanded set of constraints $\hat{\mathcal{T}}$ adds one constraint at period $t+2$. $\hat{\mathcal{T}}$ induces two kink points in the updated consumption rule $\hat{c}_{t,2}$, at $\hat{\wAlt}_{t,1}$ and $\hat{\wAlt}_{t,2}$.  It is true that imposition of the new constraint causes consumption to be lower than before at every level of wealth below $\hat{\wAlt}_{t,1}$.  However, this does not imply higher prudence of the value function at every ${m} <\hat{\wAlt}_{t,1}$.  In particular, the original consumption function is strictly concave at $\wAlt_{t,1}$, while the new consumption function is linear at $\wAlt_{t,1}$, so prudence is greater before than after imposition of the new constraint at $\wAlt_{t,1}$.

  The intuition is straightforward. At levels of initial wealth below $\hat{\wAlt}_{t,1}$, the consumer had been planning to end period $t+2$ with negative wealth. With the new constraint, the old plan of ending up with negative wealth is no longer feasible and the consumer will save more for any given level of current wealth below $\hat{\wAlt}_{t,1}$, including $\wAlt_{t,1}$. But the reason $\wAlt_{t,1}$ was a kink point in the initial situation was that it was the level of wealth where consumption would have been equal to market resources in period $t+1$. Now, because of the extra savings induced by the constraint in $t+2$, the period $t+1$ constraint will no longer bind for a consumer who begins period $t$ with wealth $\wAlt_{t,1}$. In other words, at wealth $\wAlt_{t,1}$ the extra savings induced by the new constraint prevents the original constraint from being relevant at $\wAlt_{t,1}$.

  Notice, however, that all constraints that existed in $\mathcal{T}$ will remain relevant at \textit{some} $m$ under $\hat{\mathcal{T}}$ even after the new constraint is imposed - they just induce kink points at different levels of market resources than before (in Figure \ref{fig:LCtHidesLCtpn}, the first constraint causes a kink at $\hat{\wAlt}_{t,2}$ rather than $\wAlt_{t,1}$).

  \subsection{A More General Analysis}
  \label{subsubsec:MoreGenConstr}
  The preceding analyses required income to be constant, the liquidity constraints to be of the no-borrowing type, and consumers to be impatient ($\beta R < 1$).  We now relax these requirements.
  %% Old: We now want to allow time variation in the level of income ${y}_{t}$ and in the location of the liquidity constraint .  We also drop the restriction that $\beta R < 1$, allowing the consumer to desire consumption growth over time.

  Under these more general circumstances, a constraint imposed in a given period can render constraints in either earlier or later periods irrelevant.  For example, consider a consumer with CRRA utility and $\beta R=1$ who earns income of 1 in each period, but who is required to arrive at the end of period $T-2$ with savings of 5.  Then a constraint that requires savings to be greater than zero at the end of period $T-3$ will have no effect because the consumer is required by the constraint in period $T-2$ to end period $T-3$ with savings greater than 4.

  Formally, consider now imposing the first constraint, which applies in period $\tau < T$.  The simplest case, analyzed before, was a constraint that requires the minimum level of end-of-period wealth to be ${a}_{\tau} \geq 0$.  Here we generalize this to ${a}_{\tau} \geq \sConst_{\tau,1}$ where in principle we can allow borrowing by choosing $\sConst_{\tau,1}$ to be a negative number. Now for constraint $1$ calculate the kink points for prior periods from
  \begin{eqnarray}
    u'(c_{\tau,1}^{\#}) & = & R\beta u'(c_{\tau+1,0}(R\sConst_{\tau,1}+{y}_{\tau + 1}))
    \\ \wAlt_{\tau,1} & = & (V_{\tau,1}')^{-1}(u'(c_{\tau,1}^{\#})).
  \end{eqnarray}
  In addition, for constraint $2$ recursively calculate
  \begin{eqnarray}
    \underline{\sConst}_{\tau-1,1} & = & (\sConst_{\tau,1}-{y}_{\tau,2}+\underline{c})/R  \label{eq:cgt0}
  \end{eqnarray}
  where $\underline{\sConst}_{\tau-1,1}$ is the level of wealth that constraint $1$ requires the agent to end period $\tau-1$ with and $\underline{c}$ is the lower bound for the value of consumption permitted by the model (independent of constraints).\footnote{For example, CRRA utility is well defined only on the positive real numbers, so for a CRRA utility consumer $\underline{c}=0$.  In other cases, for example with exponential or quadratic cases, there is nothing to prevent consumption of $-\infty$, so for those models $\underline{c}=-\infty$, unless there is a desire to restrict the model to positive values of consumption, in which case the $c\geq 0$ constraint will be implemented through the use of \eqref{eq:cgt0}.}

  Now assume that the first $n$ constraints in $\mathcal{T}$ have been imposed, and consider imposing constraint number $n+1$, which we assume applies at the end of period $\tau$.  The first thing to check is whether constraint number $n+1$ is relevant given the already-imposed set of constraints. This is simple: A constraint that requires ${a}_{\tau} \geq \sConst_{\tau,n+1}$ will be irrelevant if $\max_{i \in [1,n]} [\underline{\sConst}_{\tau,i}] \geq \sConst_{\tau,n+1}$, i.e.\ if one of the existing constraints already implies that savings must be greater or equal to value required by the new constraint.  If the constraint is irrelevant then the analysis proceeds simply by dropping this constraint and renumbering the constraints in $\mathcal{T}$ so that the former constraint $n+2$ becomes constraint $n+1$, $n+3$ becomes $n+2$, and so on.

  Now consider the other possible problem: That constraint number $n+1$ imposed in period $\tau$ will render irrelevant some of the constraints that have already been imposed.  This too is simple to check: It will be true if the proposed $\sConst_{\tau,n+1} \geq \sConst_{\tau,i}$ for any $i \leq n$ and for all ${m}$.\footnote{If a constraint is irrelevant for the lowest ${m}$ that t could enter period $\tau$ with, then it is irrelevant for all ${m}$.} The fix is again simple: Counting down from $i=n$, find the smallest value of $i$ for which $\sConst_{\tau,n+1} \geq \sConst_{\tau,i}$.  Then we know that constraint $n+1$ has rendered constraints $i$ through $n$ irrelevant. The solution is to drop these constraints from $\mathcal{T}$ and start the analysis over again with the modified $\mathcal{T}$.

  If this set of procedures is followed until the chronologically earliest relevant constraint has been imposed, the result will be a $\mathcal{T}$ that contains a set of constraints that can be analyzed as in the simpler case. In particular, proceeding from the final $\mathcal{T}[1]$ through $\mathcal{T}[N]$, the imposition of each successive constraint in $\mathcal{T}$ now causes a counterclockwise concavification of the consumption function around successively lower values of wealth as progressively earlier constraints are applied and the result is again a piecewise linear and strictly concave consumption function with the number of kink points equal to the number of constraints that are relevant at any feasible level of wealth in period $t$.

  The preceding discussion establishes the following result:

  \begin{theorem}\label{thm:lcip2} (Liquidity Constraints Cause Counterclockwise Concavification.) \\
    Consider an agent in period $t$ who has a utility function with $u' > 0$, $u'' < 0$, $u''' \geq 0$, and non-increasing absolute prudence ($-u'''/u''$). Assume that the agent faces a set $\mathcal{T}$ of $N$ relevant constraints.  Then $c_{t,n+1}({m})$ is a counterclockwise concavification of $c_{t,n}({m})$ around $\wAlt_{t,n+1}$.
    %	When $n \leq N-1$ constraints have been imposed, the imposition of constraint $n+1$ strictly increases absolute prudence of the agent's value function if the utility function satisfies $u''' > 0$ and ${m}_{t} < \wAlt_{t,n+1}$ or if $u''' = 0$ and $\frac{c'_{t,n+1}}{c'_{t,n}}$ strictly declines at ${m}$.
  \end{theorem}

  %% Old: \begin{theorem}\label{thm:lcip2} (Liquidity Constraints Increase Prudence.) \\
  %%   Old:   Consider an agent in period $t$ who has a utility function with $u' > 0$, $u'' < 0$, $u''' \geq 0$, and non-increasing absolute prudence ($-u'''/u''$). Assume that the agent faces a set $\mathcal{T}$ of $N$ relevant constraints. When $n \leq N-1$ constraints have been imposed, the imposition of constraint $n+1$ strictly increases absolute prudence of the agent's value function if the utility function satisfies $u''' > 0$ and ${m}_{t} < \wAlt_{t,n+1}$ or if $u''' = 0$ and $\frac{c'_{t,n+1}}{c'_{t,n}}$ strictly declines at ${m}$.
  %%   Old: \end{theorem}

  \noindent Theorem \ref{thm:lcip2} is a generalization of Lemma \ref{lem:LcAndCc}. Even if we relax the assumptions that income is constant and the agent is impatient, the imposition of an extra (more general) constraint increases absolute prudence of the value function as long as we are careful when we select the set $\mathcal{T}$ of relevant constraints.

  For an agent that only faces liquidity constraints, but no risk, the shape of the consumption function is piecewise linear.
  %% Old: \begin{corollary}(Piecewise Linear Consumption Function.) \\
  %%   Old:   Consider an agent who has a utility function with $u'> 0$ and $u'' < 0$, faces constant income ${y}$, and is impatient. Assume that the agent faces a set $\mathcal{T}$ of $N$  constraints. When $n \leq N$ constraints have been imposed, $c_{t,n}({m})$ is a piecewise linear increasing concave function with kink points at successively larger values of wealth at which future constraints stop impinging on current consumption.
  %%   Old: \end{corollary}
  Since the consumption function is piecewise linear, the new consumption function, $c_{t,n+1}({m})$ is not necessarily strictly more concave than $c_{t,n}({m})$ for all ${m}$. This is where the concept of counterclockwise concavification is useful. Even though $c_{t,n+1}({m})$ is not strictly more concave than $c_{t,n}({m})$ everywhere, it is a counterclockwise concavification and we can apply Lemma \ref{lem:CCToPrud} and \ref{lem:ccandstrictprud} to show that the introduction of the next liquidity constraint increases absolute prudence of the value function.

  \begin{corollary}\label{cor:lcip} (Liquidity Constraints Increase Prudence.) \\
    Consider an agent in period $t$ who has a utility function with $u' > 0$, $u'' < 0$, $u''' \geq 0$, and non-increasing absolute prudence ($-u'''/u''$). Assume that the agent faces a set $\mathcal{T}$ of $N$ relevant constraints. When $n \leq N-1$ constraints have been imposed, the imposition of constraint $n+1$ strictly increases absolute prudence of the agent's value function if the utility function satisfies $u''' > 0$ and ${m}_{t} < \wAlt_{t,n+1}$ or if $u''' = 0$ and $\frac{c'_{t,n+1}}{c'_{t,n}}$ strictly declines at ${m}$.
  \end{corollary}
  \begin{proof}
    By Theorem \ref{thm:lcip2}, the imposition of constraint $n+1$ constitutes a counterclockwise concavification of $c_{t,n}({m})$. By Lemma \ref{lem:CCToPrud} and \ref{lem:ccandstrictprud}, such a concavification (strictly) increases absolute prudence of the value function.
  \end{proof}
  \noindent %In the subsequent discussions, we consider cases where we relax the assumptions underlying Corollary \ref{cor:lcip}. We first consider the case where we add an extra constraint to the set of constraints. Next, we consider the cases with time-varying deterministic income, general constraints, and no assumption on time discounting.

  %% Old: Finally, consider adding a new constraint to the problem and call the new set of constraints $\hat{\mathcal{T}}$.  Suppose the new constraint applies in period $\hat{\tau}$.  Then the analysis of the new situation will be like the analysis of an added constraint in the simpler case in section \ref{subsec:IncreaseNumConstr} if the new constraint is relevant given the constraints that apply after period $\hat{\tau}$ and the new constraint does not render any of those later constraints irrelevant. If the new constraint fails either of these tests, the analysis of $\hat{\mathcal{T}}$ can proceed from the ground up as described above.

  \newpage


\chapter[PhotoElectric effect]{PhotoElectric effect}
\section{Cross section and Mean free path}

\subsection{binding energy of the shells}
The binding energy of the inner shells have been parameterised as:
\[
   B_i (Z) = Z^2 (a_i + b_i Z + c_i Z^2 + d_i Z^3 )
\]
where $ i = K, L_1, L_2 $, and the constants $a_i, b_i, c_i,d_i$
are tabulated inside dedicated functions.

\subsection{Cross section per atom}
Lets $E_{\gamma} =$ incident gamma energy, and $\epsilon = E_{\gamma}/m_{e}c^2 $ \\
The photoelectric total cross-section per atom has been parameterised as:
\[
   \sigma(Z,\epsilon)=\frac{Z^{\alpha}} {\epsilon^{\beta}} F(Z,\epsilon)
\]
\\
where $\alpha$ and $\beta$ are results of a fit, and $F(Z,\epsilon)$ is:
\[
  \begin{array}{lll}
  \mbox{for\quad} E_{\gamma} > B_K: & F=  p_{1K }/Z  + p_{2K }/\epsilon  + p_{3K }
                           & + p_{4K }Z + p_{5K }\epsilon +p_{6K } Z^2 \\
                       & & + p_{7K }Z\epsilon + p_{8K }\epsilon^2 + p_{9K }Z^3 \\
       & & + p_{10K} Z^2\epsilon + p_{11K} Z/\epsilon^2 + p_{12K}\epsilon^3 \\
  \mbox{for\quad} E_{\gamma} \in ]B_{L1}, B_K]: &
                                   F= p_{1L1}/Z + p_{2L1}/\epsilon + p_{3L1} \\
  \mbox{for\quad} E_{\gamma} \in ]B_{L2}, B_{L1}]: &
                                   F= p_{1L2}/Z + p_{2L2}/\epsilon + p_{3L2} \\
  \mbox{for\quad} E_{\gamma} \leq B_{L2}: & F= p_{1M}
  \end{array}
\]
\\
The fit was made over 301 data points chosen between:
\[5 \leq Z \leq 100\quad \mbox{and} \quad 10 \; keV \leq E \leq 50\; MeV \]
The values of the parameters are defined within the method which computes the
cross section per atom. \\
The accuracy of the fit is estimated to be:
\begin{displaymath}
 \frac{\Delta \sigma}{\sigma} \leq
    \left\{
        \begin{array}{ll} 25\% & \mbox{near to the peaks} \\
                          10\% & \mbox{elsewhere.}
         \end{array}
    \right.
\end{displaymath}

\subsection{Mean free path}

\begin{itemize}
\item[*]
         In a simple material the number of atoms per volume is:
         \[n  = \frac{\mathcal{N}\rho}{A}\]
         where:
         \begin{eqnarray*}
          \mathcal{N} &  & \mbox{Avogadro's number} \\
          \rho        &  & \mbox{density of the medium} \\
          A           &  & \mbox{mass of mole}
         \end{eqnarray*}
\item[*]
         In a compound material the number of atoms of Element elm per volume is:
         \[n_{elm}  = \frac{\mathcal{N}\rho w_{elm}}{A_{elm}}\]
         where:
         \begin{eqnarray*}
          \mathcal{N} &  & \mbox{Avogadro's number} \\
          \rho        &  & \mbox{density of the medium} \\
          w_{elm}     &  & \mbox{proportion by mass of the Element elm}\\
          A_{elm}     &  & \mbox{mass of mole of the Element elm}
         \end{eqnarray*}
\item[*]
         The mean free path, $\lambda$, for a photon to interact via photo electric
         effect is given by
         \[
           \lambda(E_{\gamma}) \equiv \frac{1}{\Sigma (E_{\gamma})}
             = \frac{1}{\sum_{elm}{\lbrack n_{elm} \sigma(Z_{elm},E_{\gamma})\rbrack}}
         \]
         where $\sum_{elm}$ runs over all Elements the material is made of.
\end{itemize}

\section{final state}
\subsection{choose an Element}
The binding energy of the shells depend of the atomic number $Z_{elm}$. \\
In a compound material one choose randomly an Element on the basis of the
probability:
\[
  Prob(Z_{elm},E_{\gamma}) =
                      \frac{n_{elm} \sigma(Z_{elm},E_{\gamma})}{\Sigma (E_{\gamma})}
\]
\subsection{final state}
The simulation is presently rather crude.             \\
A quanta can be absorbed if $E_{\gamma} > B_{shell}$.
The photoelectron is emitted with kinetic energy:
\[T_{photoelectron} = E_{\gamma}-B_{shell}(Z_{elm})\]
\\
The electron has the same direction as the incident gamma.
\section{Status of this document}
 9.10.98  created by M.Maire.


\documentclass[12pt,letterpaper]{article}
\usepackage{fullpage}
\usepackage[top=2cm, bottom=4.5cm, left=2.5cm, right=2.5cm]{geometry}
\usepackage{amsmath,amsthm,amsfonts,amssymb,amscd}
\usepackage{lastpage}
% \usepackage{hyperref}
\usepackage{enumerate}
\usepackage{fancyhdr}
\usepackage{mathrsfs}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{listings}
%\usepackage{mcode}
%\usepackage{hyperref}
\usepackage{movie15}
\usepackage{float}

\usepackage[colorlinks = true,
            linkcolor = blue,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = blue]{hyperref}

% load package with ``framed'' and ``numbered'' option.
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}

% \hypersetup{%
%   colorlinks=true,
%   linkcolor=blue,
%   linkbordercolor={0 0 1}
% }

% \renewcommand\lstlistingname{Algorithm}
% \renewcommand\lstlistlistingname{Algorithms}
% \def\lstlistingautorefname{Alg.}

% \lstdefinestyle{Python}{
%     language        = Python,
%     frame           = lines,
%     basicstyle      = \footnotesize,
%     keywordstyle    = \color{blue},
%     stringstyle     = \color{green},
%     commentstyle    = \color{red}\ttfamily
% }

\setlength{\parindent}{0.0in}
\setlength{\parskip}{0.05in}

% Edit these as appropriate
\newcommand\course{Digital Signal Processing}
\newcommand\hwnumber{2}                  % <-- homework number
\newcommand\NetIDa{Mehdi Raza Khorasani}           % <-- NetID of person #1
\newcommand\NetIDb{}           % <-- NetID of person #2 (Comment this line out for problem sets)

\pagestyle{fancyplain}
\headheight 35pt
\lhead{\NetIDa}
\lhead{\NetIDa\\\NetIDb}                 % <-- Comment this line out for problem sets (make sure you are person #1)
\chead{\textbf{\Large Homework \hwnumber}}
\rhead{\course \\ \today}
\lfoot{}
\cfoot{}
\rfoot{\small\thepage}
\headsep 1.5em

\begin{document}

\section*{Question 1}
\subsection*{Part (a)}
From the definition of Z-Transform:
\[
    X(z)= \sum_{n=-\infty}^{\infty} x(n)z^{-n}
\]
So we get:
\[
    X(z) = (3)z^{-3} + (0)z^{-2} + (0)z^{-1} + (6)z^{0} + (1)z^{1} + (-4)z^{2}
\]
\[
\boxed{
X(z) = 3z^{-3} +  6 + z  -4z^{2}
}
\]

\subsection*{Part (b)}
\begin{figure}[h]
    \centering
    \includegraphics[scale=0.5]{figures/q1task2.eps}
    \caption{PZ plot for Q1}
    \label{PZq1}
\end{figure}
\subsubsection*{Proof 1}
We know that if system is FIR, then it is non-recursively and defined as follows:
\[
    y(n)=\sum^{\infty}_{k=-\infty} b_k x(n-k)
\]
Taking Z-transform, we get:
\[
    Y(z) = \sum^{\infty}_{k=-\infty} b_k X(z)z^{-k}
\]
From above equation, we can observe the following constraint for FIR system:
\begin{enumerate}
    \item It can contain any number of zeros.
    \item It does not contain any poles.
    \item Its ROC will be the whole z plane (due to absense of poles).
\end{enumerate}
Since the given system violates the condition 2 and 3, it is not FIR. So it  can be safely termed \textbf{IIR}.
\subsubsection*{Proof 2}
We have:
\[
    H(z) = G z^{N-M} \dfrac{\prod_{k=1}^{M} (z-z_k)}{\prod_{k=1}^N (z-p_k)}
\]
where $G = \dfrac{b_o}{a_o}$.\\
In our case:
\[
    N=M=1
\]
Then:
\[
    H(z) = G z^0 \dfrac{z}{z-0.5}
\]
\[
    H(z) = G \dfrac{z}{z-0.5}
\]
We know that:
\[
    H(z) = \dfrac{Y(z)}{X(z)}
\]
So the system function can be written as:
\[
    \dfrac{Y(z)}{X(z)} = \dfrac{b_o}{a_o} (\dfrac{z}{z-0.5})
\]
Multiply and divide by $z^{-1}$:
\[
    \dfrac{Y(z)}{X(z)} = \dfrac{b_o}{a_o} (\dfrac{1}{1-0.5z^{-1}})
\]
Re-arranging:
\[
    a_o Y(z) - 0.5a_oY(z)z^{-1} = b_o X(z)
\]
Converting to LCCDE form:
\[
    a_o y(n) - 0.5 a_o y(n-1) = b_o x(n-1)
\]
\[
\boxed{
    a_o y(n) = 0.5 a_o y(n-1) + b_o x(n-1)
}
\]
The given LCCDE is recursively defined hence the system is indeed IIR. Verified!
\pagebreak
\section*{Question 2}
Given:
\[
    y(n) = 0.8 y(n-1)-0.6y(n-2) + x(n)+ 2x(n-1)
\]
\subsection*{Part (a)}
Taking Z-Transform on both sides:
\[
    Y(z) = 0.8 z^{-1}Y(z) -0.6Y(z) z^{-2} + X(z) + 2X(z) z^{-1}
\]
\[
    Y(z)(1+0.6z^{-2} - 0.8z^{-1}) =  X(z)(1+2z^{-1})
\]
\[
    \dfrac{Y(z)}{X(z)} = \dfrac{1+2z^{-1}}{1-0.8z^{-1} + 0.6z^{-2}}
\]
\[
    = \dfrac{z^2 + 2z}{z^2-0.8z + 0.6}
\]
\[
    H(z) = \dfrac{z(z + 2)}{z^2-0.8z + 0.6}
\]

\subsection*{Part (b)}
\subsubsection*{Zeros}
Zeros are as follows:
\[
    z = 0
\]
\[
    z=-2
\]
\subsubsection*{Poles}
Calculating roots of the equation below:
\[
    z^2-0.8z+0.6 = 0
\]
Poles are as follows:
\[
    p = 0.4 + 0.6633j
\]
\[
    p = 0.4 - 0.6633j
\]
\begin{figure}[h]
    \centering
    \includegraphics[scale=0.5]{figures/q2task3.eps}
    \caption{PZ plot}
    \label{PZq2}
\end{figure}
\subsection*{Part (c)}
The outer most pole is located at:
\[
    r = \sqrt{0.4^2 +0.6633^2} = 0.7746
\]
Since system is causal, the ROC consists of $r>0.7746$. This implies that the ROC will include the unit circle (we may also observe this from the PZ plot). So system is stable.
\pagebreak
\section*{Question 3}
Given:

\[
    H(z) = \dfrac{z^2+z}{z^2+z-0.75}
\]
\subsection*{Part (a)}
\begin{figure}[!h]
    \centering
    \includegraphics[scale=0.5]{figures/q3task1.eps}
    \caption{PZ plot for Q3}
    \label{PZq3}
\end{figure}
\subsubsection*{Zeros}
Zeros are calculated as follows:
\[
    z(z+1) = 0
\]
Then,
\[
\boxed{
z = 0
}
\]
\[
    \boxed{
    z = -1
    }
\]
\subsubsection*{Poles}

Poles are calculated as follows:
\[
    z^2+z-0.75 = 0
\]
\[
\boxed{
p = -1.5
}
\]
\[
\boxed{
p = 0.5
}
\]

\subsection*{Part (b)}
The outer most pole lies at:
\[
    r = 1.5
\]
With the system obeying causality, its ROC will be $r>1.5$. So ROC doesn't includes the unit circle. So system is \textbf{unstable}

\subsection*{Part (c)}
The system function can be written as:
\[
    \dfrac{Y(z)}{X(z)} = \dfrac{z^2+z}{z^2+z-0.75}
\]
Multiply and divide by $z^{-2}$
\[
    \dfrac{Y(z)}{X(z)} = \dfrac{1+z^{-1}}{1+z^{-1} - 0.75z^{-2}}
\]

\[
 Y(z) + Y(z)z^{-1} -0.75Y(z)z^{-2} = X(z) + X(z)z^{-1}
\]
Above equation can now be converted into LCCDE form:
\[
    y(n) + y(n-1) -0.75y(n-2) = x(n) + x(n-1)
\]
\[
\boxed{
    y(n) = -y(n-1) +0.75y(n-2) + x(n) + x(n-1)
}
\]
\pagebreak
\section*{Question 4}
Given:
\[
    X(z) = \dfrac{z}{z^2+z-0.75}
\]
\[
    \dfrac{X(z)}{z} = \dfrac{1}{z^2+z-0.75}
\]
Creating partial fractions:
\[
  \dfrac{1}{(z+1.5)(z-0.5)} = \dfrac{A_1}{(z+1.5)}  +\dfrac{A_2}{(z-0.5)}
\]
\[
 1 = A_1(z-0.5)+A_2(z+1.5)
\]
\subsection*{For $A_1$}
Put $z=-1.5$
\[
     1 = -2A_1  +0
\]
\[
\boxed{
A_1 = -0.5
}
\]
\subsection*{For $A_2$}
Put $z=0.5$
\[
     0.5 = 2A_2  +0
\]
\[
\boxed{
A_2 = 0.25
}
\]
Then Partial fraction expansion becomes:
\[
\boxed{
  \dfrac{X(z)}{z} = \dfrac{-0.5}{(z+1.5)}  +\dfrac{0.25}{(z-0.5)}
}
\]
\[
    X(z) = \dfrac{-0.5z}{(z+1.5)}  +\dfrac{0.25z}{(z-0.5)}
\]
Multiply and divide by $z^{-1}$:
\[
    X(z) =  \dfrac{-0.5}{(1+1.5z^{-1})}  +\dfrac{0.25}{(1-0.5z^{-1})}
\]
From the lookup table, the inverse transform is given as:
\[
\boxed{
    x(n) = [-0.5(-1.5)^n + 0.25( 0.5)^n] u(n)
}
\]
\pagebreak
\section*{Question 5}

\subsection*{Part (a)}
Since the fiter is high pass, we may place pole at $\omega = \pi$ and zero at $\omega = 0$. One possible arrangement is shown in the PZ plot:
\begin{figure}[h]
    \centering
    \includegraphics[scale=0.5]{figures/q5task1.eps}
    \caption{PZ plot for Q5}
    \label{PZq5}
\end{figure}
\subsection*{Part (b)}
\begin{enumerate}
    \item This is a band-pass filter for frequencies near $\omega=\pm \pi/ 2$. It is so because we see poles at frequency $\pm \pi/ 2$  (Poles are placed near frequencies to be emphasized). Similarly, we see zeros at $\omega = \pi $ and $\omega = 0$ (zeros are placed near frequencies to be de-emphasized). Hence this filter will block low and high frequencies ($\omega = 0 $ and $\omega = \pi$) and pass frequencies around $\omega = \pm \pi/ 2$.
    \item
    At $\omega =0$, the response is:
    \[
     |H(\omega)| = b_o \dfrac{\textit{product of length of vector: zero to unit circle}}{\textit{product of length of vector: pole to unit circle}}
    \]
    Hence the response in this case will be (Assuming poles at $r = 0.9$):
    \[
    |H(\omega)| = b_o \dfrac{1\times 1}{0.9 \times 0.9}
    \]
    \[
    |H(\omega)| =  1.234b_o
    \]
\end{enumerate}
\section*{Index}
The complete source code can be found at: \href{https://github.com/mehhdiii/Z-Transform-Basics}{GitHub/mehhdiii/}
\end{document}


\section{Use of Higher Order Functions}

\begin{lstlisting}[language=Haskell]
module ProgExercises.FS_2019_ProgExer05Prob_V01 where

-- Develop some functions to work with order lists.
-- Make use of higher-order functions and/or recursion.

toBeImplemented = undefined

type ArtName = String   -- name of article
type Number = Int       -- number of ordered articles
type Order = (ArtName, Number)

type Price = Int   -- price of an article in Rappen
type Pricing = (ArtName, Price)
type PricedOrder = (ArtName, Number, Price)

-- Note: Order and Pricing are exactly the SAME type.
-- However, we distinguish them on the software engineering level,
-- but we must be careful.

ol01 :: [Order]
ol01 =
  [("Schraube M4", 100),
   ("Mutter M4", 100),
   ("Unterlegscheibe M4", 200)]

pl01 :: [Pricing]
pl01 =
  [("Schraube M4", 5),
   ("Unterlegscheibe M4", 2),
   ("Mutter M4", 5),
   ("Zahnrad 36Z", 1300)]

-- Given a name and a list of name item pairs, myLookup returns the first
-- item in the list that matches the given name.
-- If the list does not contain the given name, myLookup fails.
-- Later we will write a better function that returns a value indicating
-- whether an item has been found or not.
exa_myLookup =
  myLookup 39 [(5, 'a'), (39, 'b'), (7, 'c'), (39, 'd')] == 'b'

myLookup :: Eq a => a -> [(a, b)] -> b
myLookup x ((x', y) : xs)
  | x == x' = y
  | otherwise = myLookup x xs

-- Given an order list and a pricing list, addPrices adds the prices
-- according to the pricing list to the order list.
-- Precondition:
--   All article names in the order list occur in the pricing list.
exa_addPrices =
  addPrices ol01 pl01 ==
    [("Schraube M4",100,500),
     ("Mutter M4",100,500),
     ("Unterlegscheibe M4",200,400)]

addPrices :: [Order] -> [Pricing] -> [PricedOrder]
addPrices ol pl = map (\(name, num) -> (name, num, myLookup name pl * num)) ol

-- totalPrice determines the total price of an order list.
exa_totalPrice =
  totalPrice (addPrices ol01 pl01) == 1400

totalPrice :: [PricedOrder] -> Price
totalPrice pol = sum (map (\(_, _, price) -> price) pol)

-- totalNumPrice determines the total number of items and the total price
-- of an order list.
totalNumPrice :: [PricedOrder] -> (Number, Price)
totalNumPrice pol = (sum nums, sum prices)
  where (_, nums, prices) = unzip3 pol

-- Returns items that (for the number ordered) cost more than a given maxPrice.
exa_tooExpensive =
  tooExpensive 450 (addPrices ol01 pl01) ==
    [("Schraube M4",100,500),
     ("Mutter M4",100,500)]

tooExpensive :: Price -> [PricedOrder] -> [PricedOrder]
tooExpensive maxPrice pol = filter (\(_, _, price) -> price > maxPrice) pol

-- Adds an order to an order list.
-- If the article name added already occurs in the order list,
-- the number is accordingly incremented.
exa_add =
  addOrder ("Mutter M4", 250) ol01 ==
    [("Schraube M4", 100),
     ("Mutter M4", 350),
     ("Unterlegscheibe M4", 200)]

addOrder :: Order -> [Order] -> [Order]
addOrder (name, num) ((name', num') : ol)
  | name == name' = (name, num + num') : ol
  | otherwise = (name', num') : addOrder (name, num) ol
addOrder nameNum [] = [nameNum]

-- addOrderList adds all orders of a new order list to an old order list.
exa_addOrderList =
  addOrderList (tail ol01) ol01 ==
    [("Schraube M4", 100),
     ("Mutter M4", 200),
     ("Unterlegscheibe M4", 400)]

addOrderList :: [Order] -> [Order] -> [Order]
addOrderList olNew olOld = foldr addOrder olOld olNew

-- Removes an order with a given article name from a given order list.
exa_removeOrder =
  removeOrder "Schraube M4" ol01 ==
    [("Mutter M4", 100),
     ("Unterlegscheibe M4", 200)]

removeOrder :: ArtName -> [Order] -> [Order]
removeOrder name ol = filter (\(name', _) -> name' /= name) ol
\end{lstlisting}

\clearpage


% !TEX root = ../main.tex
% chktex-file 21
\section{Hyperparameter optimization}%
\label{sec:hyperparams}

As described in the introduction, the goal of hyperparameter optimization is to find a global minimum of \(l\).
Since \(l\) is generally unknown, analytical methods or gradient descent cannot usually be applied.
The only way the get information about \(l\) is to evaluate it on individual configurations \(\lambda\) which is costly.
There are multiple ways to reduce the total cost of those evaluations:
\begin{enumerate}
	\item \textbf{Number \(T\) of evaluations of \(l\):}
		During optimization multiple hyperparameter configurations \(\lambda_1, \dots, \lambda_T\) will be evaluated using \(l\).
		\(T\) is usually fixed when using a grid search or a random search.
		After evaluating \(T\) configurations, the best one is chosen.
		Those na{\"\i}ve approaches assume that \(l(\lambda)\) is independent of \(l(\lambda')\) for all pairs \(\lambda \neq \lambda'\).
		We will see that this strong assumption of independence is not necessarily true which in turn allows us to reduce \(T\).
	\item \textbf{Training dataset size \(S\):}
		The performance of a given configuration \(l(\lambda)\) is computed by training the learner on \(\Dtrain\) which is expensive for big datasets.
		By training on \(S\) instead of \(|\Dtrain|\) datapoints the evaluation can be sped up.
	\item \textbf{Number of training iterations \(E\):}
		Depending on the learner, training often is an iterative process, e.~g.\@ gradient descent.
		To speed up hyperparameter optimization training could be terminated before convergence.
\end{enumerate}

\subsection{FABOLAS}%
\label{sec:hyperparams:fabolas}

The first approach we will discuss is called Fabolas (Fast Bayesian Optimization of Machine Learning Hyperparameters on Large Datasets)~\cite{Klein2017}.
It can be applied to any learner \(L\) and is based upon two main ideas:
\begin{enumerate}
	\item The validation loss \(l\) is modeled as a \textit{Gaussian process} (GP) \(f\) based on the assumption that two configurations \(\lambda\) and \(\lambda'\) will perform similar if they are similar according to some kernel \(k(\lambda, \lambda')\).
		The Gaussian process \(f\) is used as a surrogate to estimate the expected value and variance of \(l\) given \(\lambda\).
		Using \textit{Bayesian optimization} \(l\) will be probed at promising positions to iteratively improve \(f\).
		Hyperparameter configurations that are expected to perform worse than the current optimum will not be probed.
		This effectively reduces \(T\).
	\item The training dataset size \(S\) is modeled as an additional hyperparameter of \(f\) giving the optimizer an additional degree of freedom.
		This allows extrapolating the value of \(l\) when trained on the complete dataset while only probing smaller subsets
		which effectively reduces \(S\).
\end{enumerate}
We will now describe how those two ideas can be applied.

\subsubsection{Gaussian processes}%
\label{sec:hyperparams:fabolas:gaussian}

A Gaussian process is a family of \textit{random variables} (RVs) \({(X_\theta)}_{\theta \in \Theta}\), s.~t.\@ every finite subset of them follows a multivariate normal distribution.
More intuitively it can be understood as a probability distribution over functions \(f: \Theta \to \mathbb{R}\) where \(X_\theta \mathrel{\widehat{=}} f(\theta)\).
Prior knowledge about the likelihood of each \(f\) is described by a prior mean function \(\mu_0(\theta) = \mathbb{E}[f(\theta)]\) and a positive-definite kernel \(k(\theta, \theta') = \mathrm{Cov}(f(\theta), f(\theta'))\).
The covariance kernel models how informative it is to know \(f(\theta)\) to determine \(f(\theta')\).

Let \(\mathcal{D}_n = {\{(\bm{\theta}_i, \bm{y}_i)\}}_{i = 1}^{n}\) denote a set of observations.
Those observations can be used to update the means and variances of the RVs via GP regression.
This collapses the space of possible functions \(f\) to those functions that align with \(\mathcal{D}_n\) (see fig.~\ref{fig:fabolas:matern}):
\begin{align}
	\bm{m} :=&\ {(\mu_0(\bm{\theta}_1), \dots, \mu_0(\bm{\theta}_n))}^T \nonumber \\
	\bm{k}(\theta) :=&\ {(k(\bm{\theta}_1, \theta), \dots, k(\bm{\theta}_n, \theta))}^T \nonumber \\
	\bm{K} \in&\ \mathbb{R}^{n \times n}, \bm{K}_{ij} := k(\bm{\theta}_i, \bm{\theta}_j) \nonumber \\
	\mathbb{E}[f(\theta)\, |\, \mathcal{D}_n] :=&\ \mu_n(\theta) = \mu_0(\theta) + \bm{k}{(\theta)}^T \bm{K}^{-1} (\bm{y} - \bm{m}) \\
	\mathrm{Cov}(f(\theta), f(\theta')\, |\, \mathcal{D}_n) :=&\ k(\theta, \theta') - \bm{k}{(\theta)}^T \bm{K}^{-1} \bm{k}(\theta')
\end{align}
\begin{figure}
	\centering
	\includegraphics[width=0.8\linewidth]{gfx/fabolas/matern.pdf}
	\caption{
		(Left) Comparison between different covariance kernels.
		(Middle) Randomly sampled functions \(f\) using those kernels.
		(Right) Random samples after two \(f\) values were observed and incorporated into the model via GP regression.
		\source{Shahriari2016}
	}\label{fig:fabolas:matern}
\end{figure}

Fabolas works by modeling the loss function \(l\) as a Gaussian process \(f \sim \mathcal{GP}(m, k)\) with parameter set \(\Theta := \Lambda \times [0, 1]\) where \(\mu_0(\lambda, s) = \mathbb{E}[f(\lambda, s)] = \mathbb{E}[l(\lambda)\, |\, \text{training size}\ s]\).
To model the covariances between different combinations of hyperparameters and training set sizes, the following product kernel is used:
\begin{align}
	k((\lambda, s), (\lambda', s')) :=&\ k_{\textsc{Matérn5}}(d_M(\lambda, \lambda')) \cdot k_{\mathrm{lin}}(s, s')
\end{align}
Here \(k_{\textsc{Matérn5}}\) denotes the stationary Matérn kernel (\(\nu = \nicefrac{5}{2}\)) with \(d_M\) being the Mahalanobis distance between the two compared hyperparameter configurations.
\(k_{\mathrm{lin}}\) essentially is a simple linear kernel modeling the assumption that \(l\) monotonically decreases when \(s\) is increased.
We will now give an intuition for this choice of kernel and refer to~\citet{Klein2017} for the details.

The Mahalanobis distance \(d_M\) is used instead of the Euclidean distance because the hyperparameters in a configuration typically use very different scales and are in some cases also correlated.
Figure~\ref{fig:fabolas:mahalanobis} gives an intuition for this.
\begin{figure}[t]
	\centering
	\includegraphics[width=0.7\linewidth]{gfx/fabolas/mahalanobisDistance.pdf}
	\caption{
		Intuition for the Mahalanobis distance.
		Using the Euclidean distance the red points would be equally far away from the blue one.
		The Mahalanobis distance fixes this by first normalizing the hyperparameters and removing correlations.
	}\label{fig:fabolas:mahalanobis}
\end{figure}

Based on the Mahalanobis distance between two configurations \(\lambda, \lambda'\) the \textsc{Matérn5} kernel is used to compute a covariance.
The class of Matérn kernels interpolates between the Gaussian (\textsc{Sq-Exp}) and the exponential (\textsc{Matérn1}) kernel (see fig.~\ref{fig:fabolas:matern}).
Because the exponential kernel drops off quickly, configurations quickly become uncorrelated which causes noisy samples.
The Gaussian kernel drops off less quickly causing smoother samples.
Fabolas uses \textsc{Matérn5} as it empirically fits the smoothness of typical loss functions \(l\) quite well.
Please refer to \citet{Schoen2017} for an explanation of why this is the case.

\subsubsection{Bayesian optimization}%
\label{sec:hyperparams:fabolas:bayesian}

To find \(\arg\min_\lambda l(\lambda)\) the bias and variance of \(f\) has to be reduced by probing \(l\) at promising positions.
This is called Bayesian optimization.
The estimated minimum after \(n\) probes is described by \(\arg\min_\lambda \mu_n(\lambda, s = 1)\), i.~e.\@ the configuration with the smallest predicted error on the full test dataset.
To reduce the number of probes required until this minimum converges, an \textit{acquisition function} is used.
Its role is to trade-off exploration vs.\@ exploitation of \(l\) by describing the expected utility of probing \((\lambda_{n+1}, s_{n+1})\) given a set of previous probes \(\mathcal{D}_n\).
Fabolas uses an aquisition function that rates configurations by their \textit{information gain} per computation time:
\begin{align}
	a_F(\lambda, s) :=&\ \frac{1}{c(\lambda, s)} \mathbb{E}_y\left[ p(y\, |\, \lambda, s, \mathcal{D}_n)\ \cdot \mathrm{KL}_{\hat{\lambda}}(p_{\min}(\hat{\lambda}\, |\, \mathcal{D}_n \cup \{(\lambda, s, y)\})\, \|\, u(\hat{\lambda}))\right] \\
	p_{\min}(\lambda\, |\, \mathcal{D}) :=&\ p(\lambda \in \arg\min_{\lambda'}{f(\lambda', s = 1)}\, |\, \mathcal{D}) \nonumber
\end{align}
It measures the expected amount of available information about the optimal configuration if a given configuration were probed, i.~e.\@ the Kullback-Leibler divergence between the density \(p_{\min}(\lambda)\) of \(\lambda\) being optimal after a probe and the uniform density \(u(\lambda)\).
This information gain of a probe is compared to its expected associated computation time \(c\).
\(c\) is estimated using a separate Gaussian process that is maintained alongside \(f\).
Fabolas considers the cost of a probe because it tries to minimize the total optimization time not the total number of probes.

Since it is infeasible to compute \(a_F\) numerically, its maximum is estimated using \textit{Markov-Chain Monte Carlo} (MCMC).
The estimated most promising configuration will be probed.
The resulting loss value and runtime are then used to update the loss model \(f\) and cost model \(c\) via GP regression.

\subsubsection{Evaluation}%
\label{sec:hyperparams:fabolas:eval}
Fabolas was evaluated in \textit{support vector machine} (SVM) and \textit{convolutional neural network} (CNN) optimization tasks on the MNIST and CIFAR-10 dataset respectively\footnote{A reference implementation can be found at \url{https://github.com/automl/RoBO}}.
Figure~\ref{fig:fabolas:eval} compares Fabolas to the following other hyperparameter optimization approaches:
\begin{itemize}
	\item \textbf{Random Search:}
		Simple random hyperparameter search.
		Each configuration is evaluated on the full dataset.
	\item \textbf{Entropy Search \& Expected Improvement:}
		Bayesian optimization methods that always evaluate on the full dataset.
		Expected Improvement uses an aquisition function that simply probes at the current expected optimum.
		Entropy Search uses an aquisition function similar to the one used by Fabolas but without the cost model.
	\item \textbf{MTBO-\(N\) (Multi-Task Bayesian Optimization~\cite{Swersky2013}):}
		Like Fabolas but restricts probes to two sizes \(s \in \{\nicefrac{1}{N}, 1\}\), i.~e.\@ either a small subsample or the entire dataset is used.
		Multiple values for \(N\) are evaluated: 4, 32 and 512.
\end{itemize}
\begin{figure}
	\begin{subfigure}[b]{0.32\textwidth}
		\centering
		\includegraphics[width=\linewidth]{gfx/fabolas/time1.png}
	\end{subfigure}
	\begin{subfigure}[b]{0.32\textwidth}
		\centering
		\includegraphics[width=\linewidth]{gfx/fabolas/time2.png}
	\end{subfigure}
	\begin{subfigure}[b]{0.34\textwidth}
		\centering
		\includegraphics[width=\linewidth]{gfx/fabolas/size.png}
	\end{subfigure}
	\caption{
		SVM optimization on the MNIST dataset.\
		\sourceinline{Klein2017}
		(Left) Comparison of the test performance over time of different optimzers.
		(Middle) Comparison of Fabolas with different MTBO subsample sizes.
		(Right) Comparison of the subsample sizes \(s\) that MTBO and Fabolas choose for their probes.
		The average over 10 runs is depicted.
	}\label{fig:fabolas:eval}
\end{figure}
All Bayesian optimization approaches are at least one order of magnitude faster than random search.
By allowing two probing sizes, MTBO is one additional order of magnitude faster.
Depending on the choice of \(N\) MTBO sometimes improves faster than Fabolas initially.
Once Fabolas starts improving, it does however find a good configuration about one order of magnitude faster than MTBO.\
The optimal configuration is found at roughly the same time by both Fabolas and MTBO.\
Overall Fabolas finds a good configuration between 100 and 1000 times faster than random search does.
Similar results are obtained when optimizing CNNs on CIFAR-10.

\subsection{Learning Curve Extrapolation}%
\label{sec:hyperparams:earlyterm}

The second approach for speeding up hyperparameter optimization focuses on reducing the number of training iterations \(E\).
It can in principle be applied to any gradient descent based learner and can be integrated into any hyperparameter optimizer.
The idea is to monitor the learning curve of a learner during training with a hyperparameter configuration \(\lambda\).
If it is unlikely that a good accuracy will be reached with \(\lambda\), training will be terminated before convergence.

The method was first described by \citet{Domhan2015} in the context of hyperparameter optimization for \textit{deep neural networks} (DNNs) that are trained using \textit{stochastic gradient descent} (SGD).
Since no strong assumptions specific to DNNs are made, it can however also be used for other learners.
DNNs were used because their gradient descent steps are comparatively expensive.

\subsubsection{Extrapolation Method}%
\label{sec:hyperparams:earlyterm:method}

Let \(y_{1:n}\) denote the observed learning curve of SGD after \(n\) iterations, i~e.\@ the sequence of training accuracies \(y_i \in [0, 1]\).
Normally SGD iterations would be run for each hyperparameter configuration \(\lambda\) until convergence or until a maximum number of iterations \(E\) has been reached.
The learning curve extrapolation optimization works by predicting \(y_E\) every \(p\) iterations:
\begin{algorithmic}[1]
\State{\(\hat{y} \gets -\infty\)}
\For{\(\lambda \gets\) next hyperparameter configuration to evaluate}
	\State{\(n \gets 0\)}
	\Repeat\
		\State{Run \(p\) SGD iterations using \(\lambda\) with resulting accuracies \(y_{(n + 1):(n + p)}\).}
		\State{\(n \gets n + p\)}
		\State{Estimate \(P(y_E < \hat{y}\, |\, y_{1:n})\).}\label{line:earlyterm:estimate}
	\Until{\(\text{SGD converged} \lor n \geq E \lor P(y_E < \hat{y}\, |\, y_{1:n}) > \delta\)}
	\State{\algorithmicif\ \(y_n > \hat{y}\) \algorithmicthen\ \(\hat{y} \gets y_n\) \algorithmicend\ \algorithmicif}
\EndFor\
\end{algorithmic}
The prediction step (line~\ref{line:earlyterm:estimate}) uses a probabilistic model.
Similar to Fabolas, a distribution over candidate functions is fit to the observations \(y_{1:n}\).
Unlike Fabolas however, which uses a flexible non-parametric GP model, we use prior knowledge about the shape of learning curves to restrict the model to parameterized, increasing, saturating functions.
More specifically, the learning curve \(y_{1:n}\) is modeled as a linear combination \(f_{\mathit{comb}}\) of a family of given functions.
\begin{align}
	f_{\mathit{comb}}(t\, |\, \xi) :=&\ \sum_{k = 1}^{K} w_k f_k(t\, |\, \theta_k),\
	\xi = (w_1, \dots, w_k, \theta_1, \dots, \theta_k, \sigma^2) \\
	y_t \sim&\ \mathcal{N}(f_{\mathit{comb}}(t\, |\, \xi), \sigma^2)
\end{align}
\citet{Domhan2015} use \(K = 11\) types of functions \(\{f_1, \dots, f_K\}\) that are each parameterized by \(\{\theta_1, \dots, \theta_K\}\).
The assumption is that every function type captures certain aspects of learning curves.
By allowing linear combinations a more powerful model can be obtained.
Figure~\ref{fig:earlyterm:models} illustrates this idea.
\begin{figure}
	\centering
	\includegraphics[width=0.75\linewidth]{gfx/earlyterm/models.png}
	\caption{
		Comparison of an observed learning curve (black) with the 11 types of learning curve models and a linear combination of them.
		Each type is parameterized to fit the first 50 observations \(y_{1:50}\).
		As can be seen in the legend on the left, the linear combination has the smallest deviation \(\Delta y\) from the observed data after 300 iterations.
	}\label{fig:earlyterm:models}
\end{figure}
To estimate the probability \(P(y_E < \hat{y}\, |\, y_{1:n})\) MCMC is used to sample \(S\) learning curves \(\{\xi_1, \dots, \xi_S\}\) from the posterior
\begin{align}
	P(\xi\, |\, y_{1:n}) \propto&\ P(y_{1:n}\, |\, \xi) P(\xi) \\
	P(y_{1:n}\, |\, \xi) =&\ \prod_{t = 1}^{n} \mathcal{N}(y_t; f_{\mathit{comb}}(t\, |\, \xi), \sigma^2) \\
	P(\xi) \propto&\ \mathbbm{1}[f_{\mathit{comb}}(1\, |\, \xi) < f_{\mathit{comb}}(E\, |\, \xi) \land \forall k: w_k > 0]
\end{align}
The prior \(P(\xi)\) is used to model the fact that learning curves do not typically decrease over time.
Given the learning curve samples, we can now estimate
\begin{align}
	P(y_E < \hat{y}\, |\, y_{1:n}) =&\ \int P(\xi\, |\, y_{1:n}) P(y_E < \hat{y}\, |\, \xi)\, \mathrm{d}\xi \\
	\approx&\ \frac{1}{S} \sum_{s = 1}^S \Phi(\hat{y}; f_{\mathit{comb}}(E\, |\, \xi_s), \sigma^2) \nonumber
\end{align}

\subsubsection{Evaluation}%
\label{sec:hyperparams:earlyterm:eval}

\begin{figure}[t]
	\begin{subfigure}{0.4\textwidth}
		\centering
		\includegraphics[width=0.9\linewidth]{gfx/earlyterm/samples.png}
	\end{subfigure}
	\begin{subfigure}{0.6\textwidth}
		\centering
		\includegraphics[width=0.8\linewidth]{gfx/earlyterm/time.png}
	\end{subfigure}
	\caption{
		Evaluation of early termination on the CIFAR-10 dataset.
		The left graph shows the learning curves of all hyperparameter configurations that were evaluated.
		The right graph shows the average validation error over time.
		\source{Domhan2015}
	}\label{fig:earlyterm:eval}
\end{figure}
The early termination method we just described was evaluated on the CIFAR-10, CIFAR-100 and MNIST dataset.
Figure~\ref{fig:earlyterm:eval} shows the behavior of early termination and the obtained speedup on CIFAR-10.
As expected, configurations with learning curves that tend to approach low accuracies are terminated early.
Configurations with high accuracies are evaluated until convergence.
This approach consistently speeds up the hyperparameter optimization by a factor of two across the tested datasets while reaching the same quality.


% !TEX root = ./appendix.tex

\section{CMRA constructions}

% We will use the notation $\mcarp{M} \eqdef |M| \setminus \{\mzero_M\}$ for the carrier of monoid $M$ without zero. When we define a carrier, a zero element is always implicitly added (we do not explicitly give it), and all cases of multiplication that are not defined (including those involving a zero element) go to that element.

% To disambiguate which monoid an element is part of, we use the notation $a : M$ to denote an $a$ s.t.\ $a \in |M|$.

% When defining a monoid, we will show some \emph{frame-preserving updates} $\melt \mupd \meltsB$ that it supports.
% Remember that
% \[
% 	\melt \mupd \meltsB \eqdef \always\All \melt_f. \melt \sep \melt_f \Ra \Exists \meltB \in \meltsB. \meltB \sep \melt_f.
% \]
% The rule \ruleref{FpUpd} (and, later, \ruleref{GhostUpd}) allows us to use such updates in Hoare proofs.
% The following principles generally hold for frame-preserving updates.
% \begin{mathpar}
% 	\infer{
% 		\melt \mupd \meltsB
% 	}{
% 		\melt \mupd \meltsB \cup \meltsB'
% 	}
% 	\and
% 	\infer{
% 		\melt \mupd \meltsB
% 	}{
% 		\melt \mtimes \melt_f \mupd \{ \meltB \mtimes \melt_f \mid \meltB \in \meltsB \}
% 	}
% \end{mathpar}

\subsection{Agreement}

\ralf{Copy some stuff from the paper, at least in case we find that there are things which are too long for the paper.}

% \subsection{Exclusive monoid}

% Given a set $X$, we define a monoid such that at most one $x \in X$ can be owned.
% Let $\exm{X}$ be the monoid with carrier $X \uplus \{ \munit \}$ and multiplication
% \[
% \melt \cdot \meltB \;\eqdef\;
% \begin{cases}
%   \melt & \mbox{if } \meltB = \munit \\
%   \meltB & \mbox{if } \melt = \munit
% \end{cases}
% \]

% The frame-preserving update
% \begin{mathpar}
% \inferH{ExUpd}
%   {x \in X}
%   {x \mupd \melt}
% \end{mathpar}
% is easily shown, as the only possible frame for $x$ is $\munit$.

% Exclusive monoids are cancellative.
% \begin{proof}[Proof of cancellativity]
% If $\melt_f = \munit$, then the statement is trivial.
% If $\melt_f \neq \munit$, then we must have $\melt = \meltB = \munit$, as otherwise one of the two products would be $\mzero$.
% \end{proof}

% \subsection{Agreement monoid}

% Given a set $X$, we define a monoid such that everybody agrees on which $x \in X$ has been chosen.
% Let $\agm{X}$ be the monoid with carrier $X \uplus \{ \munit \}$ and multiplication
% \[
% \melt \cdot \meltB \;\eqdef\;
% \begin{cases}
% \melt & \mbox{if } \meltB = \munit \lor \melt = \meltB \\
% \meltB & \mbox{if } \melt = \munit
% \end{cases}
% \]

% Agreement monoids are cancellative.
% \begin{proof}[Proof of cancellativity]
% 	If $\melt_f = \munit$, then the statement is trivial.
% 	If $\melt_f \neq \munit$, then if $\melt = \munit$, we must have $\meltB = \munit$ and we are done.
% 	Similar so for $\meltB = \munit$.
% 	So let $\melt \neq \munit \neq \meltB$ and $\melt_f \mtimes \melt = \melt_f \mtimes \meltB \neq \mzero$.
% 	It follows immediately that $\melt = \melt_f = \meltB$.
% \end{proof}

% \subsection{Finite Powerset Monoid}

% Given an infinite set $X$, we define a monoid $\textmon{PowFin}$ with carrier $\mathcal{P}^{\textrm{fin}}(X)$ as follows:
% \[
% \melt \cdot \meltB \;\eqdef\; \melt \cup \meltB \quad \mbox{if } \melt \cap \meltB = \emptyset
% \]

% We obtain:
% \begin{mathpar}
% 	\inferH{PowFinUpd}{}
% 		{\emptyset \mupd \{ \{x\} \mid x \in X  \}}
% \end{mathpar}

% \begin{proof}[Proof of \ruleref{PowFinUpd}]
% 	Assume some frame $\melt_f \sep \emptyset$. Since $\melt_f$ is finite and $X$ is infinite, there exists an $x \notin \melt_f$.
% 	Pick that for the result.
% \end{proof}

% The powerset monoids is cancellative.
% \begin{proof}[Proof of cancellativity]
% 	Let $\melt_f \mtimes \melt = \melt_f \mtimes \meltB \neq \mzero$.
% 	So we have $\melt_f \sep \melt$ and $\melt_f \sep \meltB$, and we have to show $\melt = \meltB$.
% 	Assume $x \in \melt$. Hence $x \in \melt_f \mtimes \melt$ and thus $x \in \melt_f \mtimes \meltB$.
% 	By disjointness, $x \notin \melt_f$ and hence $x \in meltB$.
% 	The other direction works the same way.
% \end{proof}

% \subsection{Product monoid}
% \label{sec:prodm}

% Given a family $(M_i)_{i \in I}$ of monoids ($I$ countable), we construct a product monoid.
% Let $\prod_{i \in I} M_i$ be the monoid with carrier $\prod_{i \in I} \mcarp{M_i}$ and point-wise multiplication, non-zero when \emph{all} individual multiplications are non-zero.
% For $f \in \prod_{i \in I} \mcarp{M_i}$, we write $f[i \mapsto a]$ for the disjoint union $f \uplus [i \mapsto a]$.

% Frame-preserving updates on the $M_i$ lift to the product:
% \begin{mathpar}
%   \inferH{ProdUpd}
%   {a \mupd_{M_i} B}
%   {f[i \mapsto a] \mupd \{ f[i \mapsto b] \mid b \in B\}}
% \end{mathpar}
% \begin{proof}[Proof of \ruleref{ProdUpd}]
% Assume some frame $g$ and let $c \eqdef g(i)$.
% Since $f[i \mapsto a] \sep g$, we get $f \sep g$ and $a \sep_{M_i} c$.
% Thus there exists $b \in B$ such that $b \sep_{M_i} c$.
% It suffices to show $f[i \mapsto b] \sep g$.
% Since multiplication is defined pointwise, this is the case if all components are compatible.
% For $i$, we know this from $b \sep_{M_i} c$.
% For all the other components, from $f \sep g$.
% \end{proof}

% If every $M_i$ is cancellative, then so is $\prod_{i \in I} M_i$.
% \begin{proof}[Proof of cancellativity]
% Let $\melt, \meltB, \melt_f \in \prod_{i \in I} \mcarp{M_i}$, and assume $\melt_f \mtimes \melt = \melt_f \mtimes \meltB \neq \mzero$.
% By the definition of multiplication, this means that for all $i \in I$ we have $\melt_f(i) \mtimes \melt(i) = \melt_f(i) \mtimes \meltB(i) \neq \mzero_{M_i}$.
% As all base monoids are cancellative, we obtain $\forall i \in I.\; \melt(i) = \meltB(i)$ from which we immediately get $\melt = \meltB$.
% \end{proof}

% \subsection{Fractional monoid}
% \label{sec:fracm}

% Given a monoid $M$, we define a monoid representing fractional ownership of some piece $\melt \in M$.
% The idea is to preserve all the frame-preserving update that $M$ could have, while additionally being able to do \emph{any} update if we own the full state (as determined by the fraction being $1$).
% Let $\fracm{M}$ be the monoid with carrier $(((0, 1] \cap \mathbb{Q}) \times M) \uplus \{\munit\}$ and multiplication
% \begin{align*}
%  (q, a) \mtimes (q', a') &\eqdef (q + q', a \mtimes a') \qquad \mbox{if $q+q'\le 1$} \\
%  (q, a) \mtimes \munit &\eqdef (q,a) \\
%  \munit \mtimes (q,a) &\eqdef (q,a).
% \end{align*}

% We get the following frame-preserving update.
% \begin{mathpar}
% 	\inferH{FracUpdFull}
% 		{a, b \in M}
% 		{(1, a) \mupd (1, b)}
%   \and\inferH{FracUpdLocal}
% 	  {a \mupd_M B}
% 	  {(q, a) \mupd \{q\} \times B}
% \end{mathpar}

% \begin{proof}[Proof of \ruleref{FracUpdFull}]
% Assume some $f \sep (1, a)$. This can only be $f = \munit$, so showing $f \sep (1, b)$ is trivial.
% \end{proof}

% \begin{proof}[Proof of \ruleref{FracUpdLocal}]
% 	Assume some $f \sep (q, a)$. If $f = \munit$, then $f \sep (q, b)$ is trivial for any $b \in B$. Just pick the one we obtain by choosing $\munit_M$ as the frame for $a$.

% 	In the interesting case, we have $f = (q_f, a_f)$.
% 	Obtain $b$ such that $b \in B \land b \sep a_f$.
% 	Then $(q, b) \sep f$, and we are done.
% \end{proof}

% $\fracm{M}$ is cancellative if $M$ is cancellative.
% \begin{proof}[Proof of cancellativitiy]
% If $\melt_f = \munit$, we are trivially done.
% So let $\melt_f = (q_f, \melt_f')$.
% If $\melt = \munit$, then $\meltB = \munit$ as otherwise the fractions could not match up.
% Again, we are trivially done.
% Similar so for $\meltB = \munit$.
% So let $\melt = (q_a, \melt')$ and $\meltB = (q_b, \meltB')$.
% We have $(q_f + q_a, \melt_f' \mtimes \melt') = (q_f + q_b, \melt_f' \mtimes \meltB')$.
% We have to show $q_a = q_b$ and $\melt' = \meltB'$.
% The first is trivial, the second follows from cancellativitiy of $M$.
% \end{proof}

% \subsection{Finite partial function monoid}
% \label{sec:fpfunm}

% Given a countable set $X$ and a monoid $M$, we construct a monoid representing finite partial functions from $X$ to (non-unit, non-zero elements of) $M$.
% \ralf{all outdated}
% Let ${X} \fpfn {M}$ be the product monoid $\prod_{x \in X} M$, as defined in \secref{sec:prodm} but restricting the carrier to functions $f$ where the set $\dom(f) \eqdef \{ x \mid f(x) \neq \munit_M \}$ is finite.
% This is well-defined as the set of these $f$ contains the unit and is closed under multiplication.
% (We identify finite partial functions from $X$ to $\mcarp{M}\setminus\{\munit_M\}$ and total functions from $X$ to $\mcarp{M}$ with finite $\munit_M$-support.)

% We use two frame-preserving updates:
% \begin{mathpar}
%   \inferH{FpFunAlloc}
%   {a \in \mcarp{M}}
%   {f \mupd \{ f[x \mapsto a] \mid x \notin \dom(f) \}}
%   \and
%   \inferH{FpFunUpd}
%   {a \mupd_M B}
%   {f[i \mapsto a] \mupd \{ f[i \mapsto b] \mid b \in B\}}
% \end{mathpar}
% Rule \ruleref{FpFunUpd} simply restates \ruleref{ProdUpd}.

% \begin{proof}[Proof of \ruleref{FpFunAlloc}]
%   Assume some $g \sep f$. Since $\dom(f \mtimes g)$ is finite, there will be some undefined element $x \notin \dom(f \mtimes g)$. Let $f' \eqdef f[x \mapsto a]$. This is compatible with $g$, so we are done.
% \end{proof}

% We write $[x \mapsto a]$ for the function mapping $x$ to $a$ and everything else in $X$ to $\munit$.

% %\subsection{Disposable monoid}
% %
% %Given a monoid $M$, we construct a monoid where, having full ownership of an element $\melt$ of $M$, one can throw it away, transitioning to a dead element.
% %Let \dispm{M} be the monoid with carrier $\mcarp{M} \uplus \{ \disposed \}$ and multiplication
% %% The previous unit must remain the unit of the new monoid, as is is always duplicable and hence we could not transition to \disposed if it were not composable with \disposed
% %\begin{align*}
% %  \melt \mtimes \meltB &\eqdef \melt \mtimes_M \meltB & \IF \melt \sep[M] \meltB \\
% %  \disposed \mtimes \disposed &\eqdef \disposed \\
% %  \munit_M \mtimes \disposed &\eqdef \disposed \mtimes \munit_M \eqdef \disposed
% %\end{align*}
% %The unit is the same as in $M$.
% %
% %The frame-preserving updates are
% %\begin{mathpar}
% % \inferH{DispUpd}
% %   {a \in \mcarp{M} \setminus \{\munit_M\} \and a \mupd_M B}
% %   {a \mupd B}
% % \and
% % \inferH{Dispose}
% %  {a \in \mcarp{M} \setminus \{\munit_M\} \and \All b \in \mcarp{M}. a \sep b \Ra b = \munit_M}
% %  {a \mupd \disposed}
% %\end{mathpar}
% %
% %\begin{proof}[Proof of \ruleref{DispUpd}]
% %Assume a frame $f$. If $f = \disposed$, then $a = \munit_M$, which is a contradiction.
% %Thus $f \in \mcarp{M}$ and we can use $a \mupd_M B$.
% %\end{proof}
% %
% %\begin{proof}[Proof of \ruleref{Dispose}]
% %The second premiss says that $a$ has no non-trivial frame in $M$. To show the update, assume a frame $f$ in $\dispm{M}$. Like above, we get $f \in \mcarp{M}$, and thus $f = \munit_M$. But $\disposed \sep \munit_M$ is trivial, so we are done.
% %\end{proof}

% \subsection{Authoritative monoid}\label{sec:auth}

% Given a monoid $M$, we construct a monoid modeling someone owning an \emph{authoritative} element $x$ of $M$, and others potentially owning fragments $\melt \le_M x$ of $x$.
% (If $M$ is an exclusive monoid, the construction is very similar to a half-ownership monoid with two asymmetric halves.)
% Let $\auth{M}$ be the monoid with carrier
% \[
% 	\setComp{ (x, \melt) }{ x \in \mcarp{\exm{\mcarp{M}}} \land \melt \in \mcarp{M} \land (x = \munit_{\exm{\mcarp{M}}} \lor \melt \leq_M x) }
% \]
% and multiplication
% \[
% (x, \melt) \mtimes (y, \meltB) \eqdef
%      (x \mtimes y, \melt \mtimes \meltB) \quad \mbox{if } x \sep y \land \melt \sep \meltB \land (x \mtimes y = \munit_{\exm{\mcarp{M}}} \lor \melt \mtimes \meltB \leq_M x \mtimes y)
% \]
% Note that $(\munit_{\exm{\mcarp{M}}}, \munit_M)$ is the unit and asserts no ownership whatsoever, but $(\munit_{M}, \munit_M)$ asserts that the authoritative element is $\munit_M$.

% Let $x, \melt \in \mcarp M$.
% We write $\authfull x$ for full ownership $(x, \munit_M):\auth{M}$ and $\authfrag \melt$ for fragmental ownership $(\munit_{\exm{\mcarp{M}}}, \melt)$ and $\authfull x , \authfrag \melt$ for combined ownership $(x, \melt)$.
% If $x$ or $a$ is $\mzero_{M}$, then the sugar denotes $\mzero_{\auth{M}}$.

% \ralf{This needs syncing with the Coq development.}
% The frame-preserving update involves a rather unwieldy side-condition:
% \begin{mathpar}
% 	\inferH{AuthUpd}{
% 		\All\melt_f\in\mcar{\monoid}. \melt\sep\meltB \land \melt\mtimes\melt_f \le \meltB\mtimes\melt_f \Ra \melt'\mtimes\melt_f \le \melt'\mtimes\meltB \and
% 		\melt' \sep \meltB
% 	}{
% 		\authfull \melt \mtimes \meltB, \authfrag \melt \mupd \authfull \melt' \mtimes \meltB, \authfrag \melt'
% 	}
% \end{mathpar}
% We therefore derive two special cases.

% \paragraph{Local frame-preserving updates.}

% \newcommand\authupd{f}%
% Following~\cite{scsl}, we say that $\authupd: \mcar{M} \ra \mcar{M}$ is \emph{local} if
% \[
% 	\All a, b \in \mcar{M}. a \sep b \land \authupd(a) \neq \mzero \Ra \authupd(a \mtimes b) = \authupd(a) \mtimes b
% \]
% Then,
% \begin{mathpar}
% 	\inferH{AuthUpdLocal}
% 	{\text{$\authupd$ local} \and \authupd(\melt)\sep\meltB}
% 	{\authfull \melt \mtimes \meltB, \authfrag \melt \mupd \authfull \authupd(\melt) \mtimes \meltB, \authfrag \authupd(\melt)}
% \end{mathpar}

% \paragraph{Frame-preserving updates on cancellative monoids.}

% Frame-preserving updates are also possible if we assume $M$ cancellative:
% \begin{mathpar}
%  \inferH{AuthUpdCancel}
%   {\text{$M$ cancellative} \and \melt'\sep\meltB}
%   {\authfull \melt \mtimes \meltB, \authfrag \melt \mupd \authfull \melt' \mtimes \meltB, \authfrag \melt'}
% \end{mathpar}

% \subsection{Fractional heap monoid}
% \label{sec:fheapm}

% By combining the fractional, finite partial function, and authoritative monoids, we construct two flavors of heaps with fractional permissions and mention their important frame-preserving updates.
% Hereinafter, we assume the set $\textdom{Val}$ of values is countable.

% Given a set $Y$, define $\FHeap(Y) \eqdef \textdom{Val} \fpfn \fracm(Y)$ representing a fractional heap with codomain $Y$.
% From \S\S\ref{sec:fracm} and~\ref{sec:fpfunm} we obtain the following frame-preserving updates as well as the fact that $\FHeap(Y)$ is cancellative.
% \begin{mathpar}
% 	\axiomH{FHeapUpd}{h[x \mapsto (1, y)] \mupd h[x \mapsto (1, y')]} \and
% 	\axiomH{FHeapAlloc}{h \mupd \{\, h[x \mapsto (1, y)] \mid x \in \textdom{Val} \,\}}
% \end{mathpar}
% We will write $qh$ with $h : \textsort{Val} \fpfn Y$ for the function in $\FHeap(Y)$ mapping every $x \in \dom(h)$ to $(q, h(x))$, and everything else to $\munit$.

% Define $\AFHeap(Y) \eqdef \auth{\FHeap(Y)}$ representing an authoritative fractional heap with codomain $Y$.
% We easily obtain the following frame-preserving updates.
% \begin{mathpar}
% 	\axiomH{AFHeapUpd}{
% 		(\authfull h[x \mapsto (1, y)], \authfrag [x \mapsto (1, y)]) \mupd (\authfull h[x \mapsto (1, y')], \authfrag [x \mapsto (1, y')])
% 	}
% 	\and
% 	\inferH{AFHeapAdd}{
% 		x \notin \dom(h)
% 	}{
% 		\authfull h \mupd (\authfull h[x \mapsto (q, y)], \authfrag [x \mapsto (q, y)])
% 	}
% 	\and
% 	\axiomH{AFHeapRemove}{
% 		(\authfull h[x \mapsto (q, y)], \authfrag [x \mapsto (q, y)]) \mupd \authfull h
% 	}
% \end{mathpar}

% \subsection{STS with tokens monoid}
% \label{sec:stsmon}

% \ralf{This needs syncing with the Coq development.}

% Given a state-transition system~(STS) $(\STSS, \ra)$, a set of tokens $\STSS$, and a labeling $\STSL: \STSS \ra \mathcal{P}(\STST)$ of \emph{protocol-owned} tokens for each state, we construct a monoid modeling an authoritative current state and permitting transitions given a \emph{bound} on the current state and a set of \emph{locally-owned} tokens.

% The construction follows the idea of STSs as described in CaReSL \cite{caresl}.
% We first lift the transition relation to $\STSS \times \mathcal{P}(\STST)$ (implementing a \emph{law of token conservation}) and define upwards closure:
% \begin{align*}
%  (s, T) \ra (s', T') \eqdef&\, s \ra s' \land \STSL(s) \uplus T = \STSL(s') \uplus T' \\
%  \textsf{frame}(s, T) \eqdef&\, (s, \STST \setminus (\STSL(s) \uplus T)) \\
%  \upclose(S, T) \eqdef&\, \setComp{ s' \in \STSS}{\exists s \in S.\; \textsf{frame}(s, T) \ststrans \textsf{frame}(s', T) }
% \end{align*}

% \noindent
% We have
% \begin{quote}
% 	If $(s, T) \ra (s', T')$\\
% 	and $T_f \sep (T \uplus \STSL(s))$,\\
% 	then $\textsf{frame}(s, T_f) \ra \textsf{frame}(s', T_f)$.
% \end{quote}
% \begin{proof}
% This follows directly by framing the tokens in $\STST \setminus (T_f \uplus T \uplus \STSL(s))$ around the given transition, which yields $(s, \STST \setminus (T_f \uplus \STSL{T}(s))) \ra (s', T' \uplus (\STST \setminus (T_f \uplus T \uplus \STSL{T}(s))))$.
% This is exactly what we have to show, since we know $\STSL(s) \uplus T = \STSL(s') \uplus T'$.
% \end{proof}

% Let $\STSMon{\STSS}$ be the monoid with carrier
% \[
% 	\setComp{ (s, S, T) \in \exm{\STSS} \times \mathcal{P}(\STSS) \times \mathcal{P}(\STST) }{ \begin{aligned} &(s = \munit \lor s \in S) \land \upclose(S, T) = S   \land{} \\& S \neq \emptyset \land \All s \in S. \STSL(s) \sep T  \end{aligned} }
% \]
% and multiplication
% \[
% 	(s, S, T) \mtimes (s', S', T') \eqdef (s'' \eqdef s \mtimes_{\exm{\STSS}} s', S'' \eqdef S \cap S', T'' \eqdef T \cup T') \quad \text{if }\begin{aligned}[t] &(s = \munit \lor s' = \munit) \land T \sep T' \land{} \\& S'' \neq \emptyset \land (s'' \neq \munit \Ra s'' \in S'') \end{aligned}
% \]

% Some sugar makes it more convenient to assert being at least in a certain state and owning some tokens: $(s, T) : \STSMon{\STSS} \eqdef (\munit, \upclose(\{s\}, T), T) : \STSMon{\STSS}$, and
% $s : \STSMon{\STSS} \eqdef (s, \emptyset) : \STSMon{\STSS}$.

% We will need the following frame-preserving update.
% \begin{mathpar}
% 	\inferH{StsStep}{(s, T) \ststrans (s', T')}
% 	 {(s, S, T) \mupd (s', \upclose(\{s'\}, T'), T')}
% \end{mathpar}
% \begin{proof}[Proof of \ruleref{StsStep}]
% Assume some upwards-closed $S_f, T_f$ (the frame cannot be authoritative) s.t.\ $s \in S_f$ and $T_f \sep (T \uplus \STSL(s))$. We have to show that this frame combines with our final monoid element, which is the case if $s' \in S_f$ and $T_f \sep T'$.
% By upward-closedness, it suffices to show $\textsf{frame}(s, T_f) \ststrans \textsf{frame}(s', T_f)$.
% This follows by induction on the path $(s, T) \ststrans (s', T')$, and using the lemma proven above for each step.
% \end{proof}

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


\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\title{Modeling Corruption in America using the Bush and Obama Administration}
\author{Joshua Wollenweber}

\begin{document}
\maketitle

	\begin{abstract}
	This paper intends to model corruption in the United States of America through a variation of the universal model of interraction (Lotka-Volterra). The model uses logistic decay of corruption and assumes that the new presidential administration interacts with the policies and achievements of the old administration. Data from the Obama and Bush presidential administrations were used as they directly follow each other chronologically. This interraction is assumed to affect the corruption level of the nation. Solution curves were created using a global and local carrying capacity, but yielded no significant difference. The model was determined to be ineffective at forecasting corruption levels in the United States.
	\end{abstract}

	\newpage
	\section{Introduction}
	\paragraph{}
	The goal of this project was to find a suitable model for forecasting corruption in the United States of America. To measure corruption, the Corruption Perception Index (CPI) was used from Transparency.org.
	\paragraph{}
	Transparency.org attempts to measure the perception of corruption in the public sector by consolidating and normalizing data from surveys by several big data businesses, which give their own measure of corruption. CPI has been measured in a rapidly increasing number of countries around the world since 1995. The CPI in the US has been measured from 1995 until their most recent report for 2018.
	\paragraph{}
	Corruption can also be understood as the abuse of power, and presidential administrations demonstrate their abuse of power through their actions during term. Many of these actions may be self-serving (corrupt) and conflict (compete) with the policies and achievements of the administration preceding them. Therefore, the universal model of interaction will be used in attempts to model corruption within the US.

	\section{Methods}
		\subsection{Determining the Model}
		The CPI data for the US is shown with a trend-fitting curve in Figure \ref{USA CPI}. It is important to note the oscillitory nature of its change throughout the years.
		\begin{figure}[h]
		\centering
		\includegraphics[width=1\textwidth]{USA_CPI}
		\caption{Shows the CPI score of the US from 1995 to 2018 with a lower bound of 7 and an upper bound of 8}
		\label{USA CPI}
		\end{figure}

		\paragraph{}
		Because of the oscillations in CPI throughout the years, it is important to fit the data to a growth/decay model. The nature of change in CPI must be indentified in order to determine the best model to use for this project. Logistic growth was tested, and Figure \ref{Logistic Fit} shows the data to fit logistic decay.
		\begin{figure}[h]
		\centering
		\includegraphics[width=1\textwidth]{logistic_fit}
		\caption{Shows the fit of US CPI data to a logistic decay model of growth. Noting the y-intercept identifies the global carrying capacity K to be 7.4194.}
		\label{Logistic Fit}
		\end{figure}

		\subsection{Model}
		\paragraph{}
		With this information, the following model was produced using four assumptions.
		\begin{enumerate}
		\item The change in CPI of the current (new) presidential administration is affected by the CPI of the previous (old) presidential administration.
		\item There is logistic decay in the change in CPI for any administration in the US.
		\item The CPI will go through logistic growth if the administration is corrupt, and will go through logistic decay if the administration is non-corrupt (coefficients a and m).
		\item The CPI will decrease if the new administration takes measures to deface or remove achievements/policies created by the old administration (coefficients b and n).
		\end{enumerate}
		\paragraph{}
		The universal model of interaction was used, which is a variation of the Lotka-Volterra equation. The Obama administration (2009-2016) is identified as the new administration, x, and the Bush administration (2001-2008) is identified as the old administration, y.
		\begin{equation}
		x'=x(-a(1-\frac{x}{K})-by)
		\end{equation}
		\begin{equation}
		y'=y(-m(1-\frac{y}{K})-nx)
		\end{equation}

		\subsection{Coefficients}
		\paragraph{}
		Coefficients were determined using the initial conditions for each administration. MatLab code was used to calculate these values, and the following equations were used.
		\begin{equation}
		C_{x} = \ln{\frac{x_{0}}{x_{0}-K}}
		\end{equation}
		\begin{equation}
		C_{y} = \ln{\frac{y_{0}}{y_{0}-K}}
		\end{equation}
		\begin{equation}
		a = -\ln{\frac{K+x_{1}}{x_{1}}+C}
		\end{equation}
		\begin{equation}
		m = -\ln{\frac{K+y_{1}}{y_{1}}+C}
		\end{equation}
		\begin{equation}
		b = \frac{-x'-x(a(1-\frac{x}{K})}{x*y}
		\end{equation}
		\begin{equation}
		n = \frac{-y'-y(m(1-\frac{y}{K})}{x*y}
		\end{equation}
		\paragraph{}
		While the global carrying capacity, K, was used in the initial test of the model, local carrying capacities for each administration were calculated. The following equations were used for their calculation.
		\begin{equation}
		K_{x} = x_{1} * \frac{2*x_{0}*x_{2}-x_{0}*x_{1}-x_{1}*x_{2}}{x_{0}*x_{2}-x_{1}*x_{1}}
		\end{equation}
		\begin{equation}
		K_{y} = y_{1} * \frac{2*y_{0}*y_{2}-y_{0}*y_{1}-y_{1}*y_{2}}{y_{0}*y_{2}-y_{1}*y_{1}}
		\end{equation}

	\section{Results}
	\paragraph{}
	The nullclines for x' and y' were determined to gain an expectation for the results. This is shown in Figure \ref{Phase Portrait}.
	\begin{figure}[h]
	\centering
	\includegraphics[width=1\textwidth]{phase_portrait}
	\caption{Shows the phase portrait of the model equations. L1 denotes the nullcline for the Obama administration. L2 denotes the nullcline for the Bush administration. Trajectories are shown in mahogany.}
	\label{Phase Portrait}
	\end{figure}

	\paragraph{}
	The phase portrait and solution curves are shown in Figure \ref{Solution1}. The solution curves show slight oscillation around their equillibrium points. These curves predict the CPI up to 10 years after the initial year. This graph uses the universal carrying capacity value of 7.4194. The Obama administration reaches an equillibrium at a CPI of 7, and the Bush administration reaches an equillibrium at a CPI of 7.5.
	\begin{figure}[!]
	\centering
	\includegraphics[width=1\textwidth]{solution_universal_k}
	\caption{The top graphics shows the phase portait as it oscillates around (7, 7.45). The bottom graphic shows the solutions of x (blue) and y (red)}
	\label{Solution1}
	\end{figure}

	\paragraph{}
	Another test using local carrying capacites from equations (9) and (10) is shown in Figure \ref{Solution2}. This shows no significant difference from Figure \ref{Solution1}, but there is slightly more oscillation about the equillibrium point (7, 7.45).
	\begin{figure}[!]
	\centering
	\includegraphics[width=1\textwidth]{solution_local_k}
	\caption{The top graphics shows the phase portait as it oscillates around (7, 7.45). The bottom graphic shows the solutions of x (blue) and y (red)}
	\label{Solution2}
	\end{figure}

	\paragraph{}
	Other approaches not displayed include: changing the initial conditions to the second and third year of a president's administration, experimenting with the values of a,n and b,m. It was determined that a and n must be negative for the solution curves to converge to a CPI value, that the initial conditions have an extremely varying effect on the equillibrium point on the solution curves, and positive b and m will yield an increasing solution curve that reaches an equillibrium while a negative b and m will yield a decreasing solution curve that reaches an equillibrium. The slight oscillation in the solution curves shown in Figures \ref{Solution1} and \ref{Solution2} was the most oscillation seen in any trials.

	\section{Conclusions}
	\paragraph{}
	It is clear that neither solution curves match with the actual trend shown in Figure \ref{USA CPI}. It is therefore clear that this model fails to accurately forecast the CPI in the US for any years after its initial condition. In order to improve the accuracy and effectiveness of the model, several steps can be taken.
	\begin{enumerate}
	\item Find a fit better than logistic decay. Figure \ref{Logistic Fit} demonstrates that the data does fit logistic decay, but it also clearly shows that the fit is poor, and may be coincidental.
	\item Improve interaction term with coefficients b and m. This term is likely too simple to model the complexity of this problem, and should model the real-world impact of postive-negative interaction between administrations more accurately.
	\end{enumerate}
	It is not clear yet to say that the universal model of interaction is a poor skeleton to use for this problem. This model's assumptions seem to correctly interpret the trend CPI would have given competitive vs cooperative administrations. The model's terms have not accurately portraited the complexity of the problem, and additions to the current assumptions should be made.

\end{document}