\chapter{The Role of Algorithms in Computing}

\section{Algorithms}

\begin{enumerate}

\item[1.1{-}1] Give a real-world example that requires sorting or
  a real-world example that requires computing a convex hull.

\begin{framed}
Sorting. In a dictionary, it is essential to use sorting so that one
can easily find the desired word.

Convex hull. After conducting a voting intention survey, it may be
interesting to know its coverage area. One can calculate the aproximate area by
projecting the covered cities to a two dimensional plane, obtain the convex hull
of the projected cities, and then compute the approximate area of the convex
hull.
\end{framed}

\item[1.1{-}2] Other than speed, what other measures of efficiency might
  one use in a real-world setting?

\begin{framed}
For algorithms in general, we can also optimize for low memory usage or low
power consumption. In machine learning algorithms, accuracy (hit rate) is also
considered a measure of efficiency.
\end{framed}

\item[1.1{-}3] Select a data structure that you have seen previously,
  and discuss its strengths and limitations.

\begin{framed}
Linked List is a basic data structure. Some of its strengths are:

\begin{itemize}
\item Given a pointer to an element in the list, we can insert an element after
  or before it in constant time.
\item Given a pointer to an element in the list, we can delete it in constant
  time.
\end{itemize}

Some of its limitations are:

\begin{itemize}
\item The pointers requires extra memory.
\item Since it only has pointers to the next element, it takes linear time to
  retrieve the i-th element.
\end{itemize}
\end{framed}

\item[1.1{-}4] How are the shortest-path and traveling-salesman problems
  given above similar? How are they different?

\begin{framed}
They are similar because both of them aims at minimizing the distance between
A and B, given a set of possible valid paths. However, the traveling-salesman
problem has an additional constraint: for a path to be valid, besides starting
in A and ending in B, it also needs to pass through a set of other points C, D,
\ldots, E before reaching B.
\end{framed}

\item[1.1{-}5] Come up with a real-world problem in which only the best
  solution will do. Then come up with one in which a solution that is
  ``approximately'' the best is good enough.

\begin{framed}
In a competition, each candidate received a score for her/his performance. To
obtain the ranking list of the candidates, only the best sorting solution is
accepted. Approximated sorting algorithms are not feasible in this situation.

Recently, Facebook computed the approximate degree of separation between every
two people in the world. Since Facebook has billion of users, it would take too
long to compute the solution that takes into account all the connections between
all the users. Also, an approximate result is very feasible in this case. They
then used an approximate to get the result of 3.57.
\end{framed}

\end{enumerate}

\pagebreak

\section{Algorithms as a technology}

\begin{enumerate}

\item[1.2{-}1] Give an example of an application that requires
  algorithmic content at the application level, and discuss the function of the
  algorithms involved.

\begin{framed}
The search engines we have today involves a lot of complex algorithms to work.
It needs a ranking algorithm to sort the search results appropriately. It is
also important to use a crawler that systematically browses and indexes the web
content. During searching, this indexed content is gathered and filtered from
the database using sophisticated algorithms.
\end{framed}

\item[1.2{-}2] Suppose we are comparing implementations of insertion
  sort and merge sort on the same machine. For inputs of size $n$, insertion sort
  runs in $8 n^2$ steps, while merge sort runs in $64 n \lg n$ steps. For which
  values of $n$ does insertion sort beat merge sort?

\begin{framed}
For input values less than or equal to 43, insertion sort beats merge sort. We
can ignore the case where $n = 1$, since a single element is already sorted by
definition.
\end{framed}

\item[1.2{-}3] What is the smallest value of $n$ such that an algorithm
  whose running time is $100 n^2$ runs faster than an algorithm whose running
  time is $2^n$ on the same machine?

\begin{framed}
The smallest value of $n$ is 15.
\end{framed}

\end{enumerate}

\pagebreak

\section*{Problems}
\addcontentsline{toc}{section}{\protect\numberline{}Problems}%

\begin{enumerate}

\item[1{-}1] Comparison of running times. For each function $f(n)$ and
  time $t$ in the following table, determine the largest size $n$ of a problem
  that can be solved in time $t$, assuming that the algorithm to solve the problem
  takes $f(n)$ microseconds.

\begin{framed}
\centering
\footnotesize
\begin{tabular}{cccccccc}
  \toprule
  \multirow{2}{*}{$f(n)$} & \textbf{1} & \textbf{1} & \textbf{1} & \textbf{1} &
  \textbf{1} & \textbf{1} & \textbf{1}\\
  & \textbf{second} & \textbf{minute} & \textbf{hour} & \textbf{day} &
    \textbf{month} & \textbf{year} & \textbf{century}\\

  \midrule

  $\lg n$ & $2^{10^6}$ & $2^{10^7 \times 6}$ & $2^{10^8 \times 36}$ &
  $2^{10^8 \times 864}$ & $2^{10^9 \times 2592}$ &
  $2^{10^9 \times 31536}$ & $2^{10^{11} \times 31536}$ \\

  $\sqrt{n}$ & $10^{12}$ & $10^{14} \times 36$ & $10^{16} \times 1296$ &
  $10^{16} \times 746496$ & $10^{18} \times 6718264$ &
  $10^{18} \times 994519296$ & $10^{22} \times 994519296$ \\

  $n$ & $10^6$ & $10^7 \times 6$ & $10^8 \times 36$ &
  $10^8 \times 864$ & $10^9 \times 2592$ &
  $10^9 \times 31536$ & $10^{11} \times 31536$ \\

  $n \lg n$ & 62746 & 2801418 & 133378059 & 2755147513 & 71870856404 &
  797633893349 & 68610956750570 \\

  $n^2$ & $10^3$ & $7745$ & $10^4 \times 6$ & 293938 & 1609968 & 5615692 &
  561569229 \\

  $n^3$ & $10^2$ & 391 & 1532 & 4420 & 13736 & 31593 & 146645\\

  $2^n$ & 9 & 25 & 31 & 36 & 41 & 44 & 51\\

  $n!$ & 9 & 11 & 12 & 13 & 15 & 16 & 17\\

  \bottomrule
\end{tabular}
\end{framed}

\end{enumerate}


         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
         % Information sheet for the Matlab lab - Maths 6111 %
         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[10pt]{article}
\input ma_no_html_header

\usepackage{color}
\usepackage{hyperref}
\hypersetup{breaklinks=true,colorlinks=true}
%\input ma_header
\setlength{\parindent}{0pt}
\pagestyle{myheadings}
% \markright{
% \protect {\protect \epsfxsize=0.2 true cm \protect \epsffile {dolph.line.eps}}
% \it Maths 3018/6111 - Numerical methods \hfill}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\thispagestyle{empty}
\begin{center}
\textbf{\Large Maths 3018/6111 - Numerical Methods \\*[8mm]
Worksheet 2 - Solutions}\\*[.8cm]
\end{center}

\section*{Theory}

\begin{enumerate}
\item Perform the $LU$ decomposition of
  \begin{equation*}
    A =
    \begin{pmatrix}
      1 & 3 \\ 4 & 16
    \end{pmatrix}.
  \end{equation*}
  Use both standard factorisation methods.
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
  Remember the general algorithm from Table 2.1 in the notes.

  We first assume the Doolittle factorization ($\ell_{kk} = 1$). We
  immediately get that
  \begin{align*}
    u_{11} & = \left( a_{11} - \sum_{s=1}^{0} \ell_{1s} u_{s1} \right) /
    \ell_{11} \qquad \text{(using $k=1$)} \\
    & = 1.
  \end{align*}
  We then build the first row of $U$ to get
  \begin{align*}
    u_{12} & = \left( a_{12} - \sum_{s=1}^{0} \ell_{1s} u_{s2} \right) /
    \ell_{11} \qquad \text{(using $k=1$)} \\
    & = 3.
  \end{align*}
  We then build the first column of $L$ to get
  \begin{align*}
    \ell_{21} & = \left( a_{21} - \sum_{s=1}^{0} \ell_{2s} u_{s1} \right) /
    \ell_{11} \qquad \text{(using $k=1$)} \\
    & = 4.
  \end{align*}
  Given the factorization we have that $\ell_{22} = 1$ and hence that
  \begin{align*}
    u_{22} & = \left( a_{22} - \sum_{s=1}^{1} \ell_{2s} u_{s2} \right) /
    \ell_{22} \qquad \text{(using $k=2$)} \\
    & = (16 - 4 \times 3) \\
    & = 4.
  \end{align*}
  Hence we have
  \begin{equation*}
    L =
    \begin{pmatrix}
      1 & 0 \\ 4 & 1
    \end{pmatrix}, \qquad U =
    \begin{pmatrix}
      1 & 3 \\ 0 & 4
    \end{pmatrix}.
  \end{equation*}
  Quickly check that
  \begin{align*}
    L U & = \begin{pmatrix}
      1 & 0 \\ 4 & 1
    \end{pmatrix}
    \begin{pmatrix}
      1 & 3 \\ 0 & 4
    \end{pmatrix} \\
    & = \begin{pmatrix}
      1 & 3 \\ 4 & 16
    \end{pmatrix} \\
    & = A.
  \end{align*}

  With the Crout factorization ($u_{kk} = 1$), we immediately get
  that
  \begin{align*}
    \ell_{11} & = \left( a_{11} - \sum_{s=1}^{0} \ell_{1s} u_{s1} \right) /
    u_{11} \qquad \text{(using $k=1$)} \\
    & = 1.
  \end{align*}
  We then build the first row of $U$ to get
  \begin{align*}
    u_{12} & = \left( a_{12} - \sum_{s=1}^{0} \ell_{1s} u_{s2} \right) /
    \ell_{11} \qquad \text{(using $k=1$)} \\
    & = 3.
  \end{align*}
  We then build the first column of $L$ to get
  \begin{align*}
    \ell_{21} & = \left( a_{21} - \sum_{s=1}^{0} \ell_{2s} u_{s1} \right) /
    \ell_{11} \qquad \text{(using $k=1$)} \\
    & = 4.
  \end{align*}
  Given the factorization we have that $u_{22} = 1$ and hence that
  \begin{align*}
    \ell_{22} & = \left( a_{22} - \sum_{s=1}^{1} \ell_{2s} u_{s2} \right) /
    u_{22} \qquad \text{(using $k=2$)} \\
    & = (16 - 4 \times 3) \\
    & = 4.
  \end{align*}
  Hence we have
  \begin{equation*}
    L =
    \begin{pmatrix}
      1 & 0 \\ 4 & 4
    \end{pmatrix}, \qquad U =
    \begin{pmatrix}
      1 & 3 \\ 0 & 1
    \end{pmatrix}.
  \end{equation*}
  Quickly check that
  \begin{align*}
    L U & = \begin{pmatrix}
      1 & 0 \\ 4 & 4
    \end{pmatrix}
    \begin{pmatrix}
      1 & 3 \\ 0 & 1
    \end{pmatrix} \\
    & = \begin{pmatrix}
      1 & 3 \\ 4 & 16
    \end{pmatrix} \\
    & = A.
  \end{align*}

  Note that in this case only one entry has changed; in general the
  different factorizations will give totally different answers.
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
\item{} [Additional] Write out the Thomas algorithm for a tridiagonal
  system.
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
  We assume that the tridiagonal matrix $A$ has diagonal entries $b_i,
  i = 1, \dots, N$, sub-diagonal entries $a_j, j = 1, \dots, N-1$, and
  super-diagonal entries $c_j, j = 1, \dots, N-1$. We assume that we
  are trying to solve the problem
  \begin{equation*}
    A {\bf x} = {\bf f},
  \end{equation*}
  which has size $N$.

  The Thomas algorithm is essentially Gaussian elimination; forward
  elimination is used to get an upper triangular problem, and then
  back substitution used to find the answer. The tridiagonal nature of
  the problem means that it is sufficiently simple to write it out
  explicitly.

  The first step is the forward elimination process. This yields the
  system
  \begin{equation*}
    B {\bf x} = {\bf y},
  \end{equation*}
  where $B$ has entries only on the diagonal, and these entries are
  all 1, and on the super-diagonal, which are written as $c_j / d_j, j
  = 1, \dots, N-1$. The vectors ${\bf d}, {\bf y}$ are given by the
  procedure
  \begin{enumerate}
    %
  \item At the first step $d_1=b_1$ and $y_1=f_1/d_1$;
    %
  \item At the $k$-th step $d_k=b_k-a_{k-1}c_{k-1}/d_{k-1}$ and
    $y_k=(f_k-y_{k-1} a_{k-1})/d_k$.
  \end{enumerate}
  We can then solve this simplified system using back substitution to find
  \begin{enumerate}
  \item At the first step $x_N = y_N$;
  \item In reverse order, $k = N-1, \dots, 1$ we have
    $x_{k}=y_{k}-x_{k+1} c_{k}/d_{k}$.
  \end{enumerate}
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
\item Write down the general framework for iterative methods for
  linear systems. Give the convergence matrix. If the linear system
  uses the matrix $A$ above, will an iterative method converge? [Hint:
  remember what to do with the diagonal entries]
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
  The system to be solved is
  \begin{equation*}
    A {\bf x} = {\bf b},
  \end{equation*}
  with $\det(A) \ne 0$. \emph{We first scale the problem such that all
    diagonal entries of $A$ are 1}. We split the coefficient matrix
  $A$ into the matrices $N, P$, such that
  \begin{equation*}
    A = N - P
  \end{equation*}
  where $\det(N) \ne 0$. We therefore have that
  \begin{equation*}
    N {\bf x} = P {\bf x} + {\bf b}
  \end{equation*}
  and we use this to write an iteration scheme as
  \begin{equation*}
    N {\bf x}^{(n)} = P {\bf x}^{(n-1)} + {\bf b}, \qquad n = 1, 2, 3,
    \dots
  \end{equation*}
  where we start from some arbitrary initial guess ${\bf x}^{(0)}$.

  The convergence matrix $M$ is given by $M = N^{-1} P$. Convergence
  is guaranteed if the spectral radius of $M$ is less than one. For
  the matrix given in the first part we have the \emph{rescaled} $A$
  is
  \begin{equation*}
    A =
    \begin{pmatrix}
      1 & 3 \\ 1/4 & 1
    \end{pmatrix}.
  \end{equation*}
  Clearly to talk about convergence we need to first decide how to
  split $A$ into $N, P$ matrices. For simplicity we consider Jacobi's
  method for which $N = I$ and hence we have
  \begin{align*}
    N & =
    \begin{pmatrix}
      1 & 0 \\ 0 & 1
    \end{pmatrix}, \\
    P & =
    \begin{pmatrix}
      0 & -3 \\ -1/4 & 0
    \end{pmatrix}, \\
    M & = N^{-1} P \\
      & = P \\
      & =
    \begin{pmatrix}
      0 & -3 \\ -1/4 & 0
    \end{pmatrix}, \\
    \Rightarrow \qquad \rho(M) & = \max_i | \lambda_i | \\
    & = \max \left\{ \pm \sqrt{-3/4} \right\} \\
    & = \sqrt{3/4} \\
    & < 1.
  \end{align*}
  Therefore Jacobi will converge for this matrix.
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
\item Check which of the matrices on this sheet are diagonally
  dominant.
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
  For (strict) diagonal dominance we need the absolute value of the
  diagonal coefficient to be (strictly) greater than the sum of the
  absolute values of all other coefficients in the row.

  For $A$ this is not true; for the first row we have $1 \ngtr 3$,
  although dominance holds for the second row.

  For $B$ it is not true; for the second row we have $28 \ngtr 24 +
  53$, although dominance holds for the other rows.

  For $C$ it is not true; for the first row it fails, although
  dominance holds for the other rows.
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
\item Briefly explain what is meant by quadrature methods based on
  polynomial interpolation.
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
  {\it Standard exam question; see, e.g., 07/08}.

  The function $f(x)$ to be integrated is replaced by an interpolating
  function, in this case a polynomial of degree $n$, that interpolates
  it at $n+1$ \emph{nodes} $x_j$, $j=0,1,\ldots,n$. In general, when
  constructing a compound quadrature formula, we may split the
  interval into subintervals, each subinterval containing $n+1$ nodes,
  and use a polynomial interpolating function on each subinterval. The
  integral of the function is approximated by the integral of the
  (piecewise polynomial) interpolating function.
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
\item{} [3018 only] Write down the contraction mapping theorem. Check
  that $g(x) = \cos(x)$ is contracting on the unit interval.
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
  The contraction mapping theorem is
  \begin{quote}
    If $g(x)$ is a contraction mapping in an interval $I=[a,b]$ then
    there exists one and only one fixed point of the map in $[a,b]$.
  \end{quote}
  In order to state we need the definition of a contraction mapping,
  which is
  \begin{quotation}
    \textbf{Definition} - A continuous map $g(x)$ from an interval
    $I=[a,b] \subseteq \bR$ into $\bR$ is \textit{contracting} (or a
    \emph{contraction mapping}) if
    %
    \begin{enumerate}
      %
    \item the image of $I$ is contained in $I$:
      %
      \begin{align*}
        g(I) & \subseteq I \\
        \Leftrightarrow \quad g(x) & \in I \, \forall x \in I .
      \end{align*}
      %
    \item the function $g(x)$ is Lipschitz continuous in $I$ with
      Lipschitz constant $L < 1$:
      %
      \begin{equation*}
        | g(x) - g(y) | \le L | x - y | \quad \forall x,y \in I .
      \end{equation*}
    \end{enumerate}
  \end{quotation}

  Given this we want to check $g(x) = \cos(x)$ on $I = [0, 1]$. We
  have that $g$ is continuous and differentiable, so it must be
  Lipschitz continuous. We know that $L < \max_{x \in I} |g'(x)|$ so
  we look at $g' = -\sin(x)$. We note that the extrema of $g'$ occur
  when $g'' = - \cos(x) = 0$ which is at $x = (n+1/2)\pi$, of which
  none occur in the interval $[0, 1]$. We also note that $g'$ is
  monotonic on the interval. Therefore the extreme values of $g'$ are
  taken at the ends of the interval and are $[0, -\sin(1)]$, which are
  both less than 1 in absolute value. So $L<1$.

  We also need to check that $g(I) \subseteq I$. Again we note that
  $g$ is monotonic on the interval. Hence we only need to check that
  $g(0) = 1 \in I$ and $g(1) = \cos(1) \in I$, both of which
  hold. Therefore the map is contracting.
  %
  \begin{center}
    \rule{0.9\textwidth}{.1pt}
  \end{center}
  %
\end{enumerate}

\end{document}


\section{Attributes and Vitals}
Each and every character has a number of assigned variables we call \textbf{attributes and vitals}. \textbf{Attributes} are, for the most part fixed for a character \textit{(though some events can alter them)}, but very often modified by status effects \textemdash they tend to range between 0 and 20 for playable characters, with 10 being an average value. \textbf{Vitals} on the other hand are constantly changing, and are measured against certain set maximums and minimums.\newline
\textbf{Attributes} include:
\begin{itemize}
\item \textbf{Strength:} Governs the damage of bow-type ranged weapons \textit{(strength below a certain number of certain bows results in range penalty or inability to even use the bow)} and the damage of blunt weapons. Strength also governs the efficency of unarmed combat. Outside of a combat context, strength will also govern the character's ability to lift heavy objects, affencting carrying capacity among other things. Having high strength comes with the drawback of increasing a character's need for protein, unless the character is undead.
\item \textbf{Endurance:} Governs the maximum number of hitpoints per body part, as well as the character's maximum stamina. High endurance also increases a character's resistance to diseases and poisons. Having high endurance comes with the drawback of increasing a character's need for fat, unless the character is undead.
\item \textbf{Dexterity:} Governs damage of piercing weapons like spears and bladed weapons such as swords, accuracy of ranged weapons, evasion chance, stealth, lockpicking, etc. Having high dexterity comes with the drawback of increasing a character's need for protein, unless the character is undead.
\item \textbf{Intelligence:} Governs the character's maximum \textit{mana/spellpoints} count, if the character is using Arcane Magic. Whether the character is a spellcaster or not, intelligence aids the character at detecting things that seem unusual \Parentheses{rolls for intelligence}. Having high intelligence also comes with the drawback of increasing a character's need for carbohydrates, unless the character is undead.
\item \textbf{Willpower:} Governs magic resistance for all character, as well as the maximum \textit{mana/spellpoints} for characters that use Clerical Magic. While it increases the character's magic resistance as a whole, it especially increases resistance to mind control. NPCs with high willpower also tend to be resistant to bribery and seduction attempts. Unlike strength, endurance or dexterity, willpower does not come with the drawback of increasing the character's nutritional needs.
\item \textbf{Charisma:} Governs a character's ability to lead, convince, explain, seduce, and various other social interactions. Highly charismatic characters can talk monsters to death, while characters with low charisma will be forced to rely on favors, money or brute strength to get what they want. Unlike strength, endurance or dexterity, charisma does not come with the drawback of increasing the character's nutritional needs, but a disproportionate number of negative status effects reduce charisma.
\end{itemize}
\textbf{Vitals} include:
\begin{itemize}
\item \textbf{Hitpoints:} Represents how much damage the character can still sustain, unlike all the other vitals, hitpoints are counted separately for each body part of the character. Reaching zero hitpoints on vital body parts means death.
\item \textbf{Mana:} Relevant only to spellcasting character, it determines how much magical power they have left and can use to cast spells. Running out of mana means not being able to cast spells until they recover their mana via either resting or drinking mana potions. For character who use Arcane Magic, maximum mana is $2.5*Intelligence$ - for characters who rely on Clerical Magic instead, it is  $2.5*Willpower$.
\item \textbf{Stamina:} Represents how un-tired the character is. All physically intensive actions - such as swinging one's weapon - cost stamina. Stamina is recovered during lack of activity, and completely depleting it causes the character to collapse and become temporarily incapaciated. A character's maximum stamina is $10*Endurance$.
\item \textbf{Energy:} Effectively how un-sleepy the character is, on a scale of 0 to 100. This one is active even for undead characters, since all sentient beings need rest \textemdash if not physical, then mental. It slowly and gradually depletes over time \textit{(but depletes faster when the character is doing physically or mentally demanding work)}, and is regenerates very fast by sleeping \textit{(eight hours is enough to recover 100\% of a character's energy, no matter how depleted it was)} and also by consuming certain potions or beverages  \textit{(such as black tea)}. When it is depleted, the character spontaneously faints and falls asleep. When it is near depletion, the character is supposed to feel very drowsy and even experience episodes of microsleep and general confusion.
\item \textbf{Protein:} The amount of protein in the character's system, expressed in grams. The character's daily need for protein is governed by their race, sex and strength - normally, it is $11*Strength$. Having under 50\% of their protein need causes the character's strength and dexterity to degrade linearly. \textbf{This vital is inactive for undead characters.}
\item \textbf{Carbohydrate:} The amount of carbohydrates in the character's system, expressed in grams. The character's daily need for carbohydrates is governed by their race, sex and intelligence - normally, it is $28*Intelligence$. Having under 50\% of their carbohydrate need causes the character's intelligence to degrade linearly. \textbf{This vital is inactive for undead characters.}
\item \textbf{Fat:} The amount of fat in the character's system, expressed in grams. The character's daily need for fat is governed by their race, sex and endurance - normally, it is $8*Endurance$. Having under 50\% of their fat need causes the character's endurance to degrade linearly. \textbf{This vital is inactive for undead characters.}
\item \textbf{Calories:} Total calories in the character's system. Effectively $other+(4*protein)+(4*carbohydrate)+(9*fat)$, since each gram of protein is 4 calories, each gram of carbohydrates is 4 calories, and each gram of fat is 9 calories. Other calories can include every other sources of calory, but among them is chiefly alcohol, with each gram of alcohol being 7 calories. \textbf{This vital is inactive for undead characters} \textemdash otherwise, a character that reaches zero calory count starves to death. Overeating has negative consequences, like temporarily reducing dexterity and charisma.
\item \textbf{Alcohol:} The amount of alcohol in the character's system, expressed in blood alcohol content \textit{(a percentage of ethanol in the blood in units of mass of alcohol per volume of blood)}, primarily to determine the character's level of intoxication. \textbf{This vital is inactive for undead characters} \textemdash otherwise, blood alcohol content above 0.500 is lethal \textit{(death by alcohol poisoning)}, blood alcohol content between 0.500 and 0.029 equates to varying levels of drunkenness, and blood alcohol content below 0.029 has no symptoms \textit{(the character is for all intents and purposes sober)}.
\item \textbf{Water:} The hydration level of your character \textemdash unlike other counters, it is more like a timer that gets reset to 100 when the character is hydrated. \textbf{This vital is inactive for undead characters} \textemdash otherwise characters die of dehydration when their water level reaches zero, which normally happens under the course of three days. or 72 hours.
\item \textbf{Blood:} The amount of foreign blood in the character's system. For vampires and theriantropes, the need for blood replaces the need for nutrients like protein, carbohydrates, fat, calories and water \textemdash as such \textbf{this vital is only active for vampires and theriantropes.} A vampire or theriantrope character needs a 100 units of blood per day - unless hybernating - but their body can store up to 6000 units of blood at maximum.
\end{itemize}


\section{Roadmap}

\begin{itemize}
	\item May, 2017
	      \begin{itemize}
	      	\item Design of representative benchmarks models:
	      	      \begin{itemize}
	      	      	\item A template for binned models that is parametrized in terms of number of events, number of bins, number of channels, number of signal/background components, and number of parameters of interest and nuisance parameters.
	      	      	\item Establish a precise mathematical formulation that is implementation-independent.
	      	      	      This will be based on the \code{HistFactory} schema.
	      	      	\item Document the template model.
	      	      \end{itemize}
	      	\item Implementation of this template for the benchmark models with a \code{HistFactory} script (probably in \code{Python}).
	      	      This will provide the \code{RooFit} benchmark.
	      	\item Study of data flow graph frameworks (e.g., \code{TensorFlow}, \code{Theano}, \code{MXNet}) or of probabilistic programming frameworks (e.g., \code{Edward}, \code{tensorprob}).
	      \end{itemize}
	\item June, 2017
	      \begin{itemize}
	      	\item Implementation of the benchmark models in one of the studied frameworks.
	      	\item Benchmarks evaluating their data and model parallelism.
	      \end{itemize}
	\item July, 2017
	      \begin{itemize}
	      	\item Technical report and recommendations for particle physics use cases.
	      	\item Upstream software contributions to address the identified limitations (if any).
	      	\item Development of/Contribution to a probabilistic framework (if time permits).
	      \end{itemize}
\end{itemize}


\section{Goblin Shaman}

Goblins live in bands of between 3 and 20, making their nests in caves and attacking livestock and humans alike.

\begin{minipage}[H]{1\textwidth}
	\centering
	\rowcolors{2}{lightgray}{white}
	\begin{tabular}[c]{|c | c | c | c | c | c | c|}
		\hline
		Strength & Vitality & Dexterity & Agility & Intellect & Perception & Empathy\\
		\hline
		6 & 5 & 7 & 6 & 9 & 7 & 6\\
		\hline
	\end{tabular}
\end{minipage}
\bigbreak
\begin{minipage}[H]{1\textwidth}
	\centering
	\rowcolors{2}{lightgray}{white}
	\begin{tabular}[c]{|c | c | c|}
		\hline
		Combat & Adventuring & Social\\
		\hline
		2 & 2 & 2\\
		\hline
	\end{tabular}
\end{minipage}
\bigbreak
\begin{minipage}[H]{1\textwidth}
	\centering
	\rowcolors{2}{lightgray}{white}
	\begin{tabular}[c]{|c | c | c|}
		\hline
		Health & Stamina & Mana\\
		\hline
		20 + 2d6 & 10 + 4d6 & 25 + 2d6\\
		27 & 24 & 32\\
		\hline
	\end{tabular}
\end{minipage}
\noindent
Health Pool II\\
Stamina Pool II\\
Mana Pool IV\\
Spell Attack Training I\\
Earth Rune I\\
Lightning Rune I\\
Stealth I\\
\\
Actions:\\
Hearl Rock (5 AP, 3 Mana): +9, \passus{6}: 1d12 blunt\\
\\
Lightning Bolt (4 AP, 5 Mana): +9, \passus{9}: 3d4 lightning, 2 AP damage\\
\\
\begin{minipage}[H]{1\textwidth}
	\centering
	\rowcolors{2}{lightgray}{white}
	\begin{tabular}[c]{|c | c | c|}
		\hline
		Dodge & Notice & Willpower\\
		\hline
		18 & 19 & 18\\
		\hline
	\end{tabular}
\end{minipage}
Loot:\\
Check: Perception\\
Tool: -\\
\\
\begin{minipage}{0.8\textwidth}
	\rowcolors{2}{lightgray}{white}
	\begin{tabular}{|l | l|}
		\hline
		Check & Cost\\
		\hline
		8 & 1x Lightning Runestone (Tiny), 1x Earth Runestone (Tiny)\\
		12 & 1x Tattered Robes (Small, Cloth Material I), 3d4+2 Gold\\
		16 & 3d4+2 Gold\\
		\hline
	\end{tabular}
\end{minipage}
\\
Check: Dexterity (Alchemy)\\
Tool: Knife\\
\\
\begin{minipage}{0.8\textwidth}
	\rowcolors{2}{lightgray}{white}
	\begin{tabular}{|l | l|}
		\hline
		Check & Cost\\
		\hline
		15 & 1x Goblin Tooth (Agility Essence I)\\
		20 & 1d4 Goblin Tooth (Agility Essence I)\\
		\hline
	\end{tabular}
\end{minipage}
\pagebreak


 \documentclass [12pt]{article}

\usepackage {amsmath}
\usepackage {amsthm}
\usepackage {amssymb}
\usepackage {graphicx}
\usepackage {float}
\usepackage {multirow}
\usepackage {xcolor}
\usepackage [ruled,vlined,commentsnumbered,titlenotnumbered]{algorithm2e} \usepackage {array}
\usepackage {booktabs}
\usepackage {url}
\usepackage {parskip}
\usepackage [margin=1in]{geometry}
\usepackage [T1]{fontenc}
\usepackage {cmbright}
\usepackage [many]{tcolorbox}
\usepackage [colorlinks = true,
            linkcolor = blue,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = blue]{hyperref}
\usepackage {enumitem}
\usepackage {xparse}
\usepackage {verbatim}
\usepackage{algpseudocode}
\usepackage{listings}
\usepackage{xcolor}
\lstset { %
    language=C++,
    backgroundcolor=\color{black!5}, % set backgroundcolor
    basicstyle=\footnotesize,% basic font setting
}
\newtheorem{theorem}{Theorem}
\newtheorem{remark}{Remark}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newtheorem{claim}{Claim}
\newtheorem{proposition}{Proposition}

\DeclareTColorBox {Solution}{}{breakable, title={Solution}} \DeclareTColorBox {Solution*}{}{breakable, title={Solution (provided)}} \DeclareTColorBox {Instruction}{}{boxrule=0pt, boxsep=0pt, left=0.5em, right=0.5em, top=0.5em, bottom=0.5em, arc=0pt, toprule=1pt, bottomrule=1pt} \DeclareDocumentCommand {\Expecting }{+m}{\textbf {[We are expecting:} #1\textbf {]}} \DeclareDocumentCommand {\Points }{m}{\textbf {(#1 pt.)}}

\begin {document}

\vspace {1em}
\begin {Instruction}
Adapted From Virginia Williams'lecture notes.
\end {Instruction}

{\LARGE \textbf {COMP 285 (NC A\&T, Spr `22)}\hfill \textbf {Lecture 33} }

\begin{centering}
\section*{Max Flows and Mininum Cuts}
\end{centering}

\section{Formulation of the Maximum Flow Problem}

You are given an input graph $G = (V, E)$, where the edges are directed. There is a function $c : E \to R\geq 0$ that defines the capacity of each edge. We also label two nodes in $G$, $s$ and $t$, as the source and destination, respectively. The task is to output a flow of maximum value. We will shortly define what a flow is and what a flow of maximum value means.

A flow $f$ is a function $f : E \to R\geq 0$ such that
\begin{enumerate}
    \item Capacity constraints are satisfied:
    $$
        \forall (u, v ) \in E : 0 \leq f (u, v ) \leq c(u, v )
    $$.
    \item Flow conservation constraints are satisfied:
    $$
    \forall v \in V \setminus \{s, t\} : \sum_{x \in N_{\text{in}}(v)} f (x, v ) = \sum_{y\ in N_{\text{out}}(v)} f (v, y )
    $$
    Here $N_{\text{in}}(v )$ denotes the set of nodes with an edge that points to $v$ and $N_{\text{out}}(v )$ denotes the set of nodes that $v$ points to.
\end{enumerate}

\begin{figure}[h!]
    \centering
    \includegraphics[scale=0.6]{max_flow_ex.png}
    \caption{(Left) Graph $G$ with edge capacities (Right) Graph $G$ with a sample flow.}
    \label{fig:max_flow_ex}
\end{figure}

Suppose that there are no edges going into $s$ and no edges coming out of $t$. From the above, you can verify yourself that $\sum_{x \in N_{\text{out}}(s)} f (s, x) = \sum_{y \in N_{\text{in}}(t)} f (y, t)$. We define the value $x \in N_{\text{out}}(s) f (s, x)$ to be the value of the flow $f$ . We usually denote the value of a flow $f$ as $|f |$. If there are edges going into $s$ and out of $t$, then the value of $f$ is $$
|f | = \sum_{x \in N_{\text{out}}(s)} f (s, x) - \sum_{ y \in N_{\text{in}}(s)} f (y, s)
$$.

The max flow problem is to find some flow f such that $|f |$ is maximized. Remark 1. In the analysis below we consider graphs with a single source s and a single sink t. However, if we need to work with a graph with multiple sources, we can do so by adding a new source node, and then adding edges with capacity infinity from it to each of the multiple sources. Similarly, if we want to have multiple sinks, we add a new sink node and add edges from the multiple sinks to that sink with capacity infinity.

\section{Example}

In Fig. \ref{fig:max_flow_ex}, we have a graph $G$ and a sample flow $f$ . Observe that the two constraints for a flow are satisfied. There can be multiple other flows possible that can satisfy the constraints. For our given flow, $|f | = 16$. The max flow for this graph is actually $18$, as we will see shortly.

\section{Formulation of the Minimum Cut Problem}

Now, we give a formulation of the min cut problem defined for directed graphs with source and destination nodes $s$ and $t$. Note that there is also a version of the min cut problem without a source and sink node, though we won't discuss that now. An s-t cut is a partition $V = S \cup T$ where $S$ and $T$ are disjoint and $s \in S, t \in T$, and the size/cost of an s-t cut is $c(S, T) := \sum_{x\in S, y\in T} c(x, y )$.

For our graph $G$ shown above, if we set$ S = \{s, a, c\}$ and $T = \{b, t\}$, then the cost of the cut is $c(a, b) + c(c, b) + c(c, t) = 5 + 3 + 10 = 18$. If we take another cut $S
' = \{s, c\}, T' = \{a, b, t\}$, then $c(S', T') = c(s, a) + c(c, b) + c(c, t) = 10 + 3 + 10 = 23$. Note that we do
not consider the edge $\{a, c\}$ as it is in the wrong direction (we only consider edges from $S'$ to $ T'$).

\section{The Max-Flow Min-Cut Theorem}

\begin{lemma}
For any flow $f$ and any s-t cut $(S, T)$ of $G$, we have $|f | \leq c(S, T)$. In particular,the value of the max flow is at most the value of the min cut.
\end{lemma}

\begin{proof}

\begin{align*}
|f| &= \sum_{x \in N_{\text{out}}(s)} f(s,x) - \sum_{y \in N_{\text{in}}(s)} f(y,s) \\
&=\sum_{v \in S} \left(\sum_{x \in N_{\text{out}}(v)} f(v,x) - \sum_{y \in N_{in}(v)} f(y,v) \right) \tag{by flow conservation constraing for $v \neq s$} \\
&=\sum_{v \in S} \left(\sum_{x \in N_{\text{out}}(v) \cap S} f(v,x) - \sum_{y \in N_{in}(v) \cap S} f(y,v) \right) + \sum_{v \in S} \left(\sum_{x \in N_{\text{out} \cap T}(v)} f(v,x) - \sum_{y \in N_{in}(v) \cap T} f(y,v) \right) \\
&=\sum_{v \in S} \left(\sum_{x \in N_{\text{out} \cap T}(v)} f(v,x) - \sum_{y \in N_{in}(v) \cap T} f(y,v) \right) \tag{first term sums to $0$} \\
&\leq \sum_{v \in S, x \in T, x \in N_{\text{out}}(v)} f(v,x) \\
&=\leq \sum_{v \in S, x \in T, x \in N_{\text{out}}(v)} c(v,x) \\
&= c(S,T)
\end{align*}

In the proof, $\sum_{v \in S} \left(\sum_{x\in N_{\text{out}}(v)} f(v,x) - \sum_{y\in N_{\text{int}}(v)} f(y,v)\right) = 0$ since we add and subtract the flow $f (u, v )$ for every $u, v \in S$ such that $(u, v ) \in E$.
\end{proof}

We get the following consequence.

\begin{corollary}
If we can find $f$ and $(S,T)$ such that $|f| = c(S,T)$ then $f$ is a max-flow and $(S,T)$ is a min s-t cut.
\end{corollary}

It turns out we can always find such an $f$ and $(S,T)$ for any graph.

\begin{theorem}{Max-Flow Min-cut Theorem}
For any graph $G$, source $s$ and destination $t$, the value of the max flow is equal to the cost of the min cut
\end{theorem}

We will show this by coming up with an algorithm. The algorithm will take the graph $G$ and some flow $f$ that has already been constructed, and create a new graph that is called the residual graph. In this new graph, the algorithm will try to find a path from s to t. If no such path exists, we will show that the value of the flow we started with is the value of the maximum flow. If not, we show how to increase the value of our flow by pushing some flow
on that path.

\begin{figure}[h!]
\centering
\includegraphics[scale=0.6]{max_flow_res.png}
\caption{The Residue network given the flow presented in Figure \ref{fig:max_flow_ex}}
\label{fig:max_flow_res}
\end{figure}

\section{The Ford-Fulkerson Max-Flow Algorithm}

We will make an assumption on our graph. The assumption can be removed, but it will make our lives easier. We will assume that for all $u, v \in V$ , $G$ does not have both edges $(u, v )$ and $(v, u)$ in $E$. We can make this condition hold by modifying the original graph in the following way. If $(u, v ), (v, u) \in E$, we split the edge $(u, v )$ to two edges $(u, x)$ and $(x, v )$, where $x$ is a new node we introduce into the graph. This makes the number of nodes at most $m + n$.

Now, let $f$ be a flow given to us. We will try to see if we can improve this flow. We will define the residual capacity $c_f : V \times V \to R_{\geq 0}$ as follows.

$$
c_f (u, v ) = \begin{cases}
    c(u, v ) - f (u, v ) & \text{if }(u, v ) \in E \\
    f (v, u) & \text{if }(v, u) \in E \\
    0 & \text{ otherwise. }
\end{cases}
$$

Basically, what this does is that, if there is any flow through the edge, you remove the flow from the capacity and add an edge in the opposite direction with the value of the flow. The reason we do this is because the flow we picked thus far might not be the correct flow, and this formulation allows us to undo changes that we have done through ``adding flow'' in the revere direction. The residual capacity $c_f (u, v )$ represents how much flow we can send from $u$ to $v$ in addition to the flow $f$.

We define $G_f$ to be a residual network defined with respect to $f$ , where $V (G_f ) = V (G)$ and $(u, v ) \in E(G_f )$ if $c_f (u, v ) > 0$. Figure \ref{fig:max_flow_res} shows $G$ with the residual edges. We will show that, if there is a path from $s$ to $t$ in $G_f$ , then $f$ is not a max flow. If no such path exists, that $f$ is a max flow.

\begin{lemma}
If $t$ is not reachable from $s$ is $G_f$ , then $f$ is a maximum flow.
\end{lemma}
\begin{proof}
Let $S$ be the set of nodes reachable from $s$ in $G_f$ and $T = V \setminus S$. There are no edges in $G_f$ from $S$ to $T$ since the nodes in $T$ are not reachable from $s$. Note that $(S, T)$ defines an $s-t$ cut. Now consider any $v \in S, w \in T$. We have $c_f (v, w) = 0$ since $(v, w)$ is not an edge in $G_f$ . There are three cases:
\begin{enumerate}
    \item If $(v, w) \in E$, then by definition $c_f (v, w) = c(v, w) - f (v, w) = 0 \implies c(v, w) = f (v, w)$\item If $(w, v ) \in E$, then $c_f (v, w) = f (w, v ) = 0$.
    \item If $(v, w) \notin E and (w, v ) \notin E$, we can disregard $(v, w)$ and $(w, v )$ since they do not appear in any flow or cut.
\end{enumerate}

 Using this, and the proof in Lemma 2, we have
 \begin{align*}
 |f | &= \sum_{v\in S} \left( \sum_{x\in N_{\text{out}(v)} \cap T} f (v, x) - \sum_{y\in N_{\text{in}}(v) \cap T} f (y, v ) \right) \\
 &= \sum_{v\in S} \sum_{x\in N_{\text{out}(v)} \cap T} f (v, x) \tag{from case 2 the second term is 0} \\
 &= \sum_{v\in S} \sum_{x\in N_{\text{out}(v)} \cap T} c(v, x) \tag{from case 1}\\
 &= c(S, T)
 \end{align*}

 Thus, we show that the flow is equal to the cut. From Corollary 3 we know that $f$ is a maximum flow, and $(S, T)$ is a min cut.
\end{proof}

\begin{lemma}
If $G_f$ has a path from $s$ to $t$, we can modify $f$ to $f'$ such that $|f | < |f'|$.
\end{lemma}
\begin{proof}

Pick a path $P$ from $s$ to $t$ in $G_f$ , and consider the edge of minimum capacity on the path. Let that capacity be $F$ . Then we can increase our flow by $F$ . For each edge in $P$, if $c_f (v, w)$ is the right direction (i.e., there is an edge $(v, w) \in E(G)$), then we can increase our flow on this edge by $F$ . If $c_f (v, w)$ is in the opposite direction (i.e., $(w, v ) \in E(G)$), then we can decrease the flow on this edge by $F$ . In effect, we are ``undoing'' the flow on this edge. By doing so, we have increased our flow by $F$.

As an example, consider Fig. \ref{fig:max_flow_res} again. The path $s \to a \to c \to b \to t$ is a path with minimum capacity $2$. Therefore, we can update our flow and push additional $2$ units of flow, resulting in a flow of $18$.

Formally, Let $s = x_0 \to x_1 \to ... \to x_k = t$ be a simple path $P$ in $G_f$ , and let $F = \min_i c_f (x_i , x_{i+1})$. Define a new flow $f'$ where
$$
f' (u, v ) = \begin{cases}
    f (u, v ) + F & \text{ if }(u, v ) \in P\\
    f (u, v ) - F & \text{ if }(v, u) \in P \\
    f (u, v ) & \text{ otherwise }.
    \end{cases}
$$

We now need to show that $f'$ is a flow. The capacity constraints are satisfied because for every $(u, v ) \in E$,
\begin{enumerate}
    \item If $(u, v ) \in P$, then $0 \leq f (u, v ) + F \leq f (u, v ) +c_f (u, v ) = f (u, v ) +c(u, v )-f (u, v ) = c(u, v )$.
    \item If $(v, u) \in P$, then $f (u, v ) - F \leq f (u, v ) \leq c(u, v )$ and $f (u, v ) - F \geq f (u, v ) - c_f (v, u) = 0$.
    \item Otherwise, $f (u, v )$ is from the original flow $f$ .
\end{enumerate}

The conservation constraints are also satisfied: Recall that $P$ is a simple path. Thus, for every $v \in V \setminus \{s, t\}$, $P$ uses $0$ or two edges incident on $v$ . If $P$ uses $0$ edges on $v$, then flow values of the edges incident on $v$ have not changed when going from $f$ to $f'$ . Thus, suppose that $P$ uses two edges $(x, v )$ and $(v, y )$ incident on $v$. Because in $G_f$ some edges appear in the opposite direction compared to $G$, we need to consider a few cases.

\begin{enumerate}
    \item $(x, v )$ and $(v, y )$ are both in the same direction (an edge into $v$ and an edge out of $v$ ); the flow into $v$ increases by $F$ and the flow out of it also increases by $F$ .
    \item $(x, v )$ and $(v, y )$ are both in the opposite direction $((v, x), (y, v ) \in E$); the flow into $v$ decreases by $F$ and the flow out of it also decreases by $F$ .
    \item $(x, v )$ is in the correct direction and $(v, y )$ is in the opposite direction. Then the flow into $v$ changes by $F - F = 0$.
    \item $(x, v )$ is in the opposite direction and $(v, y )$ is in the correct direction. Then the flow out of $v$ changes by $F - F = 0$.
\end{enumerate}

Finally, note that we increase our flow by $F$ . Consider the edge $(s, x_1)$ in $P$. If $(s, x_1) \in E$, the flow out of $s$ increases by $F$ . If $(x_1, s) \in E$, the flow into s decreases by $F$ . By our definition of $G_f$ , it must be that $F > 0$, and we get that $|f'| > |f |$.
\end{proof}

From this, we can construct an algorithm to find the maximum flow. Starting with some arbitrary flow of the graph, construct the residual network, and check if there is a path from $s$ to $t$. If there is a path, update the flow, construct the new residual graph and repeat. Otherwise, we have found the max flow.

A path from $s$ to $t$ in the residual graph is called an augmenting path, and pushing flow through it to modify the current flow is referred to as augmenting along the path.

The run time of this algorithm is bounded by the number of times we update our flow. If the edge capacities are all integers, we can increase the flow by at least 1 each time we update our flow. Therefore, the runtime is $O(|f |m)$ where $|f |$ is the value of the max flow. If we have rational edge capacities, then we can multiply all edge capacities by a factor to make them all integers. However, the runtime blows up by that factor as well. If we have irrational edge capacities, then the algorithm is no longer guaranteed to terminate. So we have a problem.

\begin{algorithm}
\caption{maxflow($G,s, t$)}
\label{alg:maxflow_algorithm}
\begin{algorithmic}
\State $f \gets$ all zeros flow
\State $G_f \gets G$
\State \While{$t$ is reachable from $s$ in $G_f$ (check using DFS/BFS)}{
    \State $P \gets$ path in $G_f$ from $s$ to $t$
    \State $F \gets$ min capacity on $P$
    \State $f \gets f'$ as defined in Lemma 5 above.
    \State Update $G_f$ to the corresponding new flow.
}
\State \Return $f$
\end{algorithmic}
\end{algorithm}

We will save the day in the next sections. Algorithm \ref{alg:maxflow_algorithm} is called the Ford-Fulkerson method.

It is actually part of a family of algorithms that depend on how the path $P$ between $s$ and $t$ in $G_f$ is selected. One can obtain $P$ via DFS, BFS, or any other method for selecting paths. It turns out that two methods work particularly well: the shortest path method and the fattest path method. The shortest path method is known as the Edmonds-Karp algorithm or Dinic's algorithm.

\textbf{The fattest path method.} This method finds a path between $s$ and $t$ that maximizes $\min_{e \in P} c_f (e)$ among all $s-t$ paths $P$. Finding such a path can be done in $O(m + n)$ time by a clever mix of linear time median-finding and $DFS$.

\textbf{The shortest path method (the Edmonds-Karp algorithm/Dinic's algorithm)}. This method picks the path between $s$ and $t$ using BFS, thus picking a path that minimizes the number of edges. Finding such a path also runs in $O(m)$ time: BFS takes $O(m + n)$ to explore the whole graph, but since we only care about the vertices reachable from $s$ this is $O(m)$ time.

Since both methods of selecting a path run in linear time, the main question becomes, how many iterations does Ford-Fulkerson perform? We will answer these questions below in the next section.

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% ICML 2013 EXAMPLE LATEX SUBMISSION FILE %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Use the following line _only_ if you're still using LaTeX 2.09.
%\documentstyle[icml2013,epsf,natbib]{article}
% If you rely on Latex2e packages, like most moden people use this:
\documentclass{article}

% For figures
\usepackage{graphicx} % more modern
%\usepackage{epsfig} % less modern
\usepackage{subfigure}

% For citations
\usepackage{natbib}

% For algorithms
\usepackage{algorithm}
\usepackage{algorithmic}

% As of 2011, we use the hyperref package to produce hyperlinks in the
% resulting PDF.  If this breaks your system, please commend out the
% following usepackage line and replace \usepackage{icml2013} with
% \usepackage[nohyperref]{icml2013} above.
\usepackage{hyperref}

% Packages hyperref and algorithmic misbehave sometimes.  We can fix
% this with the following command.
\newcommand{\theHalgorithm}{\arabic{algorithm}}

% Employ the following version of the ``usepackage'' statement for
% submitting the draft version of the paper for review.  This will set
% the note in the first column to ``Under review.  Do not distribute.''
\usepackage{icml2013}
% Employ this version of the ``usepackage'' statement after the paper has
% been accepted, when creating the final version.  This will set the
% note in the first column to ``Proceedings of the...''
% \usepackage[accepted]{icml2013}

% The \icmltitle you define below is probably too long as a header.
% Therefore, a short form for the running title is supplied here:
\icmltitlerunning{Building Multi-Class Models with the Iris Dataset}

\begin{document}

\twocolumn[
\icmltitle{Building Multi-Class Models with the Iris Dataset}

% It is OKAY to include author information, even for blind
% submissions: the style file will automatically remove it for you
% unless you've provided the [accepted] option to the icml2013
% package.
\icmlauthor{Carl Cortright}{carl.cortright@colorado.edu}
\icmladdress{University of Colorado Boudler}
\icmlauthor{Your CoAuthor's Name}{email@coauthordomain.edu}

% You may provide any keywords that you
% find helpful for describing your paper; these are used to populate
% the "keywords" metadata in the PDF but will not be shown in the document
\icmlkeywords{boring formatting information, machine learning, ICML}

\vskip 0.3in
]

\section{Introduction}

One of the classic example data sets in machine learning is the Iris dataset. This dataset contains three different species of iris, each entry with a measurement of sepal length and width and pedal length and width. For this project, I split the Iris dataset in to two, one for testing and one for training. Then, I trained two different models, one using a custom naive bayes algorithm and the other using vowpal wabbit. Later we compare the two models for accuracy and explain some flaws in our experiment.

\section{Naive Bayes Analysis}

\subsection{Experimental Setup}

For this experiment, I used a python script to train a model on various sized datasets. Then, using the rest of the iris model, I tested for accuracy. I also used basic "Add 1" smoothing to account for features that weren't seen in training.  The naive bayes algorithm used, uses log space multiplication to simplify the expression\\

$P(C) \prod_{i=0}^n P(X_i | C) = log(P(C)) + log(P(X_0|C)) + ... + log(P(X_n|C)$

\subsection{Results}

Shuffling the dataset between runs, I computed the accuracy based on different ratios of training:test data. With ratios ranging from 1:1 to 15:1 , I ran 5000 tests on each ratio to calculate the average accuracy, producing figure 1.

\begin{figure}[!ht]

\caption{The blue line represents best fit, and the ratio is the number on the x-axis:1 (training:test)}
\includegraphics[width=\columnwidth]{figure_1.png}

\end{figure}

As expected, the larger the training set, the more accurate the model. As we approach the full size of the dataset, the accuracy appears to approach somewhere around 91 percent, a decent result for naive bayes. With a larger dataset, the accuracy could likely be increased.

\section{Vowpal Wabbit Analysis}

\subsection{Experimental Setup}

To set up VW, I shuffled the iris dataset and put it in two separate files, one for training and one for testing. Then, I used the scripts given to us to train and test the dataset using vowpal wabbit. Afterwards, I used a custom python script to calculate the accuracy of the model.

\subsection{Results}

After training my model with VW, I was able to get an accuracy of 100 percent using a similar ratio to that used in the naive bayes model. This makes sense, a model like vowpal wabbit that uses logistic regression rather than naive bayes normally performs better.

\section{Conclusion}

For this project, I used the iris dataset to create two different multi-class models to predict flower type. Based on the experiments I ran, I determined that vowpal wabbit is a superior method to naive bayes for predicting class using this dataset. Overall, our predictions weren't very accurate. We did show that the more training examples, the better the model that resulted. In order to create a more robust system with either method, we would likely need a larger dataset to train on.

\section{Software and Data}

Vowpal Wabbit\\ https://github.com/JohnLangford/vowpal_wabbit\\
Iris Dataset\\ https://archive.ics.uci.edu/ml/datasets/Iris\\

% In the unusual situation where you want a paper to appear in the
% references without citing it in the main text, use \nocite
\nocite{langley00}

\end{document}

% This document was modified from the file originally made available by
% Pat Langley and Andrea Danyluk for ICML-2K. This version was
% created by Lise Getoor and Tobias Scheffer, it was slightly modified
% from the 2010 version by Thorsten Joachims & Johannes Fuernkranz,
% slightly modified from the 2009 version by Kiri Wagstaff and
% Sam Roweis's 2008 version, which is slightly modified from
% Prasad Tadepalli's 2007 version which is a lightly
% changed version of the previous year's version by Andrew Moore,
% which was in turn edited from those of Kristian Kersting and
% Codrina Lauth. Alex Smola contributed to the algorithmic style files.


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage{amssymb}
\usepackage{graphicx}

\title{Proiect SDA}
\author{Dragos-Gabriel Danciulescu}
\date{May 2022}

\begin{document}

\maketitle

\section*{Example Exercise}

Use the baby-step giant-step method to find x such that   $$ 5^{x} \equiv 107 \bmod{179} $$. Pick m = $\lfloor\sqrt{89}\rfloor$.Copy, extend and fill the
appropriate tables.\\
\begin{enumerate}[a.]
    \item
We will create the Baby steps table in which $g=5$ for $i$ up to $9$:\\
\begin{tabular}{ |c|c|c|c|c|c|c|c|c|c|c| }
 \hline
 i & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\
 \hline
 $5^i \bmod 179$ & 1 & 5 & 25 & 125 & 88 & 82 & 52 & 81 & 47 &  56\\
 \hline

\end{tabular}
\\
Next, we note that:\\
$g^{-\sqrt{89}}=5^{-9}=56^{-1}=16 \bmod 179$\\
So, $h \cdot g^{-mj} = 107 \cdot 16^j$\\
Now,we will create the Giant steps table. Note that in the algorithm, these values are not stored in memory like the ones in the first table.\\
\begin{tabular}{ |c|c|c|c| }
 \hline
 j & 0 & 1 & 2\\
 \hline
 $107 \cdot 16^j \bmod 179$ & 107 & 101 & 5\\
 \hline

\end{tabular}
We can now observe that we've found a match, for $i=1$ and $j=2$.\\
So,following the theory:\\
$g^{i+m \cdot j}=h$\\
$5^{1+9 \cdot 2}=107$\\
$5^{19} \bmod 179 = 107$\\
We've also checked the value with Wolfram Alpha, it is correct, so:\\
$x=19$\\

\end{enumerate}

\section*{Notebook Examples and Theory}
\begin{figure}
  \includegraphics[width=\textwidth]{GCD.png}
  \caption{Extended Euclidean algorithm notebook example}
  \label{fig:D_P}
 \end{figure}

\begin{figure}
  \includegraphics[width=\textwidth]{BSGS.png}
  \caption{Baby-Step Giant-Step notebook example}
  \label{fig:D_P}
\end{figure}

\begin{figure}
  \includegraphics[width=\linewidth]{theory_gcd.png}
  \caption{Greatest Common divisor}
  \label{fig:D_P}
\end{figure}

\begin{figure}
  \includegraphics[width=\linewidth]{euclidean.png}
  \caption{Euclidean algorithm}
  \label{fig:D_P}
\end{figure}

\begin{figure}
  \includegraphics[width=\linewidth]{EEA.png}
  \caption{Extended euclidean algorithm}
  \label{fig:D_P}
\end{figure}

\begin{figure}
  \includegraphics[width=\linewidth]{Invertibility.png}
  \caption{Computing inverse using Euclid's algorithm}
  \label{fig:D_P}
\end{figure}

\begin{figure}
  \includegraphics[width=\linewidth]{DiscreteLog.png}
  \caption{The discrete log problem in cryptography}
  \label{fig:D_P}
\end{figure}

\begin{figure}
  \includegraphics[width=\linewidth]{TheoryBSGS.png}
  \caption{Explanation of Baby-Step Giant-Step algorithm}
  \label{fig:D_P}
\end{figure}

\begin{figure}
  \includegraphics[width=\linewidth]{Discussion.png}
  \caption{A discussion about BSGS}
  \label{fig:D_P}
\end{figure}

\end{document}


\setlength{\parindent}{0pt}
\clearpage

\section{Liveness DFA example}
(Prepared by Jai Arora)
\vspace{0.3cm}

Consider the following example:

\begin{figure}[H]
        \centering
        \includegraphics[height=6cm]{images/Module83_1.png}
\end{figure}

The solution for this program using the Liveness DFA rules discussed is follows:
\begin{figure}[H]
        \centering
        \includegraphics[height=6cm]{images/Module83_2.png}
\end{figure}

The working of this example can be found in \href{https://www.youtube.com/watch?v=dTVq4gnbUYg&list=PLf3ZkSCyj1tf3rPAkOKY5hUzDrDoekAc7&index=83}{this video}.\\

\subsection{Liveness DFA Observations}
\begin{itemize}
    \item Every $L()$ in this analysis can change only once (${\tt false} \rightarrow {\tt true}$). Now this fact guarantees the convergence of the fixed point algorithm.
    \item Worst Case execution time: For a particular variable, all the $L()$ can change only once, and as the number of such values is $2 \times \#$statements, so the worst case execution time is $O(2 \times \#$statements).
    \item Once this analysis is finished, we can use it to identify dead code.
    \item Notice that information flowed in the forward direction (in the direction of the program execution) for constant propagation but flowed in the reverse direction (against the direction of the program execution) for liveness analysis.
    The former types of analyses are called forward dataflow analyses. The latter types of analyses are called backward dataflow analyses
\end{itemize}


\(\today\)

\section{In the morning}\label{in-the-morning}

\begin{itemize}
\tightlist
\item
  Eat eggs
\item
  Drink coffee
\item
  inf:
\item
  \(\infty\)
\item
  today:
\item
  \(\today\)
\end{itemize}

\(\today\)

\section{In the evening}\label{in-the-evening}

\begin{itemize}
\tightlist
\item
  Eat spaghetti
\item
  Drink wine
\end{itemize}

\section{Conclusion}\label{conclusion}

\begin{itemize}
\tightlist
\item
  And the answer is\ldots{}
\item
  \(f(x)=\sum_{n=0}^\infty\frac{f^{(n)}(a)}{n!}(x-a)^n\)
\end{itemize}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Part of EBESS and MESS Presentation: Learn to LaTeX 2019
% Prepared by JT
% March 2019
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[]{article}
\usepackage{amsmath}
\begin{document}

\section{Introduction}
\label{sec:intro}

% this is how we use equation referencing
In Section \ref{sec:method}, we \ldots

\section{Test section}

\section{Method}
\label{sec:method}

\begin{equation}
    \label{eq:euler}
    e^{i\pi} + 1 = 0
\end{equation}

By \eqref{eq:euler}, we have \ldots
\end{document}


\documentclass{article}
\usepackage{graphicx}
\usepackage{marvosym}
\usepackage{dingbat}

\title{Prefix Scan}
\date{}

\begin{document}
\maketitle

\section{Sequential and parallel Prefix Scan}

Prefix Scan is an operation that computes all the partial sums of a
vector of values. Given an array, the result of this operation is an
array where each element is the sum of the preceding elements in the
original vector up to the corresponding position. There are two
versions of prefix scan: inclusive and exclusive. For an inclusive
scan, the result is the sum of all preceding values, as well as the
value of the element in the position under consideration. Therefore,
the value of coefficient $i$ in the result vector is equal to the sum
of all the values $1,2,...,i$ in the original vector. The exclusive
version does not include the value of the vector element at the
position of interest. Therefore, the value of coefficient $i$ in the
result vector is equal to the sum of all the values $1,2,...,i-1$ in
the original vector. Here is an example of these two variants:

\vspace{0.3cm}

\noindent\includegraphics[width=\textwidth]{prefscan_seq}

\vspace{0.3cm}

Both variants are commonly implemented {\it in-place} which mean that
the result is stored in the input array. {\bf The objective of this
exercise is to implement a parallel version of the inclusive prefix
scan using OpenMP}.

The sequential version of the inclusive prefix scan is extremely
simple and consists of the following lines of code
\begin{verbatim}
  for(i=1; i<l; i++)
    pref[i] = pref[i]+pref[i-1];
\end{verbatim}

As you can see, the above loop cannot be parallelized with a simple
\texttt{\#pragma omp parallel for} directive because of a loop-carried
dependency (iteration \texttt{i} uses the result of iteration
\texttt{i-1}). For this reason a more complicated algorithm has to be
used; this methods consists of the following 5 steps:
\begin{enumerate}
\item the initial vector is split into four chunks (parts) of roughly
  the same size and each chunk is assigned to one thread;
\item each thread computes the inclusive prefix scan of the chunk it
  was assigned;
\item each thread copies the last element of its local result into the
  corresponding location of a temporary array \texttt{loc\_last}
  (i.e., thread number 0 will copy the value in \texttt{loc\_last[0]},
  thread number 1 in \texttt{loc\_last[1]} etc.);
\item {\bf one} thread (it can be the master as well as any other
  thread, but only one) computes the {\bf exclusive} prefix scan of
  the \texttt{loc\_last} array;
\item each thread sums the corresponding element of the resulting
  \texttt{loc\_last} array into its own chunk.
\end{enumerate}

Here is an example of how this algorithm is applied to the vector in
the previous figure when the number of threads is equal to 4:

\vspace{0.3cm}

\noindent\includegraphics[width=\textwidth]{prefscan_par}

\section{Package content}

The \texttt{PrefixScan} directory contains a single file named
\texttt{prefixscan.c}.
This file contains:
\begin{itemize}
\item a sequential inclusive prefix scan routine
  \texttt{prefix\_inc\_seq} that takes two arguments:
  \begin{enumerate}
  \item an integer \texttt{l} containing the length of the array whose
    prefix scan has to be computed;
  \item a reference \texttt{*pref} of the array whose
    prefix scan has to be computed;
  \end{enumerate}
\item a sequential exclusive prefix scan routine
  \texttt{prefix\_exc\_seq} with the same
  interface as the inclusive routine;
\item the declaration of the parallel inclusive prefix scan routine
  \texttt{prefix\_inc\_par} (at the beginning the routine is empty and
  the objective of the exercise is to write it);
\item a main program that creates a vector, fills it with random
  numbers, computes the inclusive prefix scan with both the sequential
  and the parallel version and finally checks that the result of the
  parallel version is the same as that of the sequential one.
\end{itemize}

The code can be compiled with the \texttt{make} command: simply type
\texttt{make} int the \texttt{PrefixScan} directory. This will
generate an executable \texttt{main} file that can be run like this
\begin{verbatim}
$ ./main l
\end{verbatim}
where l is the length of the array whose prefix scan has to be
computed. Obviously, at the beginning the execution of the main
program will report an error because the parallel version is not
implemented.

\section{Assignment}
\begin{itemize}
\item {\huge \Keyboard} Implement the parallel inclusive prefix scan
  algorithm described above using OpenMP inside. Compile and run the code
  with 1, 2 and 4 threads to check the correctness of your parallel
  implementation.
\item \smallpencil Did you observe any speedup (reduction of the
  execution time) when using 2 or 4 threads instead of 1? If not, how can
  you explain this? report your comments in the \texttt{responses.txt}
  file.
\end{itemize}

\paragraph{Advice.}
\begin{itemize}
\item Note that inside the empty initial version of the parallel
  routine, the \texttt{loc\_last} array is already declared of size
  \texttt{MAXTHREADS} (equal to 16). Clearly you only have to use the
  first \texttt{nth} elements where \texttt{nth} is the number of
  threads in your parallel region.
\item Pay attention to the synchronization between threads.
\item Note that the original vector is only logically partitioned into
  chunks: this means threads don't have to allocate memory for storing
  the local chunks but that each thread simply has to identify the
  first element and the length of its own local chunk.
\item Use the \texttt{prefix\_inc\_seq} sequential routine to compute
  the inclusive prefix scan on the local chunks as described in step 2
  of the parallel algorithm. Use the \texttt{prefix\_exc\_seq} routine
  to compute the exclusive prefix scan of the \texttt{loc\_last} array
  as described in step 4 of the parallel algorithm.
\item Compile with \texttt{make main\_dbg} to get some messages useful
  for debugging.
\end{itemize}

\end{document}

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


\documentclass[epsfig,10pt,fullpage]{article}

\newcommand{\LabNum}{6}
\newcommand{\CommonDocsPath}{../../../common/docs}
\input{\CommonDocsPath/preamble.tex}

\begin{document}

\centerline{\huge Digital Logic}
~\\
\centerline{\huge Laboratory Exercise \LabNum}
~\\
\centerline{\large Adders, Subtractors, and Multipliers}
~\\

The purpose of this exercise is to examine arithmetic circuits that add, subtract,
and multiply numbers. Each circuit will be described in Verilog and implemented on an
Intel\textsuperscript{\textregistered} FPGA DE10-Lite, DE0-CV, DE1-SoC, or DE2-115 board.

\section*{Part I}
\addcontentsline{toc}{1}{Part I}
Consider again the four-bit ripple-carry adder circuit used in lab exercise 2; its diagram
is reproduced in Figure~\ref{fig:ripple_carry}.

\begin{figure}[H]
\centerline{
\includegraphics{figures/ripple_carry}}
\caption{A four-bit ripple carry adder.}
\label{fig:ripple_carry}
\end{figure}

This circuit can be implemented using a '+' sign in Verilog. For example, the following code
fragment adds {\it n}-bit numbers $A$ and $B$ to produce outputs $sum$ and $carry$:

\begin{center}
\begin{minipage}[t]{12.5 cm}
\begin{tabbing}
ZZ\=ZZ\=ZZ\=ZZ\=ZZ\=ZZ\=ZZ\=ZZ\=ZZ\=ZZ\=ZZ\kill
\>{\bf wire} [n-1:0] sum;\\
\>{\bf wire} carry;\\
\>\ldots \\
\>{\bf assign} \{carry, sum\} = A + B;\\
\end{tabbing}
\end{minipage}
\end{center}

Use this construct to implement a circuit shown in Figure~\ref{fig:accumulator}. This
circuit, which is often called an {\it accumulator}, is used to add the value of an input
$A$ to itself repeatedly. The circuit includes a carry out from the adder, as well as an
{\it overflow} output signal. If the input $A$ is considered as a 2's-complement number,
then {\it overflow} should be set to~1
in the case where the output {\it sum} produced does not represent a correct
2's-complement result.

~\\
Perform the following steps:
\begin{enumerate}
\item Create a new Quartus\textsuperscript{\textregistered} project. Write Verilog code that describes the
circuit in Figure~\ref{fig:accumulator}.
\item Connect input $A$ to switches {\it SW}$_{7-0}$, use {\it KEY}$_0$ as an
active-low asynchronous reset, and use {\it KEY}$_1$ as a manual clock input. The sum
from the adder should be displayed on the red lights {\it LEDR}$_{7-0}$, the registered
carry signal should be displayed on {\it LEDR}$_{8}$, and the registered {\it overflow}
signal should be displayed on {\it LEDR}$_{9}$. Show the registered values of {\it A}
and {\it S} as hexadecimal numbers on the 7-segment displays HEX$3-2$ and HEX$1-0$.
\item Make the necessary pin assignments needed to implement the circuit on your
DE-series board, and compile the circuit.
\item Use timing simulation to verify the correct operation of the
circuit. Once the simulation works properly, download the circuit onto your DE-series board
and test it by using different values of~$A$. Be sure to check that the {\it overflow}
output works correctly.
\end{enumerate}

\begin{figure}[H]
\centerline{
\includegraphics{figures/accumulator}}
\caption{An eight-bit accumulator circuit.}
\label{fig:accumulator}
\end{figure}

\section*{Part II}
\addcontentsline{toc}{2}{Part II}
Extend the circuit from Part I to be able to both add and subtract numbers. To do so,
introduce an {\it add\_sub} input to your circuit. When {\it add\_sub} is 1, your circuit should
subtract $A$ from $S$, and when {\it add\_sub} is 0 your circuit should add
$A$ to $S$ as in Part I.

\section*{Part III}
\addcontentsline{toc}{3}{Part III}
Figure~\ref{fig:binary_multiplication}$a$ gives an example of paper-and-pencil multiplication $P = A \times B$, where $A = 11$ and $B = 12$.

\begin{figure}[H]
	\begin{center}
		\includegraphics{figures/figure3.pdf}
	\end{center}
	\caption{Multiplication of binary numbers.}
	\label{fig:binary_multiplication}
\end{figure}

We compute $P = A \times B$ as an addition of summands. The first summand is equal to $A$ times the ones digit of $B$.
The second summand is $A$ times the tens digit of $B$, shifted one position to the left. We add the two summands to form the product $P = 132$.

~\\
Part $b$ of the figure shows the same example using four-bit binary numbers.
To compute $P = A \times B$, we first form summands by multiplying $A$ by each digit of $B$. Since each digit of
$B$ is either 1 or 0, the summands are either shifted versions of $A$ or 0000. Figure ~\ref{fig:binary_multiplication}$c$
shows how each summand can be formed by using the Boolean AND operation of $A$ with the appropriate bit of $B$.

~\\
A four-bit circuit that implements $P = A \times B$ is illustrated in Figure~\ref{fig:array_mult}. Because of its
regular structure, this type of multiplier circuit is called an {\it array multiplier}. The shaded areas correspond to the shaded columns in Figure~\ref{fig:binary_multiplication}$c$. In each row of the multiplier AND gates are used to produce the summands,
and full adder modules are used to generate the required sums.

\begin{figure}[htb]
	\begin{center}
		\includegraphics[]{figures/figure4.pdf}
	\end{center}
	\caption{An array multiplier circuit.}
	\label{fig:array_mult}
\end{figure}

Perform the following steps to implement the array multiplier circuit:

\begin{enumerate}
\item Create a new Quartus project.
\item Generate the required Verilog file. Use switches {\it SW}$_{7-4}$ to represent the
number $A$ and switches {\it SW}$_{3-0}$ to represent $B$. The hexadecimal values of~$A$
and $B$ are to be displayed on the 7-segment displays {\it HEX}2 and {\it HEX}0, respectively.
The result ~$P = A \times B$~ is to be displayed on {\it HEX}$5-4$.
\item Make the necessary pin assignments needed to implement the circuit on your
DE-series board, and compile the circuit.
\item Use simulation to verify your design.
\item Download your circuit onto your DE-series board and test its functionality.
\end{enumerate}

\section*{Part IV}
\addcontentsline{toc}{4}{Part IV}
In Part III, an array multiplier was implemented using full adder modules. At a higher level, a row of full adders functions as an $n$-bit adder and the array multiplier circuit can be represented as shown in Figure~\ref{fig:array_mult_adders}.

\begin{figure}[H]
\centerline{
\includegraphics{figures/array_mult_adders}}
\caption{An array multiplier implemented using $n$-bit adders.}
\label{fig:array_mult_adders}
\end{figure}

Each $n$-bit adder adds a shifted version of $A$ for a given row and the {\it partial
product} of the row above. Abstracting the multiplier circuit as a sequence of additions
allows us to build larger multipliers. The multiplier should consist of n-bit adders
arranged in a structure shown in Figure~\ref{fig:array_mult_adders}. Use this approach to
implement an 8 {\sf x} 8 multiplier circuit with registered
inputs and outputs, as shown in Figure~\ref{fig:registered_mult}.

\begin{figure}[H]
\centerline{
\includegraphics{figures/registered_mult}}
\caption{A registered multiplier circuit.}
\label{fig:registered_mult}
\end{figure}

Perform the following steps:
\begin{enumerate}
\item Create a new Quartus project and write the required Verilog file.
\item Use switches {\it SW}$_{7-0}$ to provide the data inputs to the circuit. Use
{\it SW}$_9$ as the enable signal {\it EA} for register {\it A}, and use {\it SW}$_8$
as the enable for register {\it B}.  When {\it SW}$_9 = 1$ display the contents of
register A on the red lights LEDR, and display the contents of register B on these lights
when {\it SW}$_8 = 1$. Use {\it KEY}$_0$ as a synchronous reset input, and use
{\it KEY}$_1$ as a manual clock signal.  Show the product~$P = A \times B$~ as a
hexadecimal number on the 7-segment displays {\it HEX3-0}.
\item Make the necessary pin assignments needed to implement the circuit on your
DE-series board, and compile the circuit.
\item Test the functionality of your design by inputting various data values and observing
the generated products.
\end{enumerate}

\section*{Part V}
\addcontentsline{toc}{5}{Part V}
Part IV showed how to implement multiplication $A \times B$ as a sequence of additions,
by accumulating the shifted versions of $A$ one row at a time. Another way to implement
this circuit is to perform addition using an adder tree.

An adder tree is a method of adding several numbers together in a parallel fashion. This
idea is illustrated in Figure~\ref{fig:adder_tree}. In the figure, numbers
$A$, $B$, $C$, $D$, $E$, $F$, $G$, and $H$ are added together in parallel.
The addition $A + B$ happens simultaneously with $C + D$, $E + F$ and $G + H$. The
result of these operations are then added in parallel
again, until the final sum $P$ is computed.

\begin{figure}[H]
\centerline{
\includegraphics{figures/adder_tree}}
\caption{An example of adding 8 numbers using an adder tree.}
\label{fig:adder_tree}
\end{figure}

In this part you are to implement an 8 {\sf x} 8 multiplier circuit by using the adder-tree
approach. Inputs $A$ and $B$, as well as the output $P$ should be registered as in Part IV.

\input{\CommonDocsPath/copyright.tex}
\end{document}


\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{microtype}      % microtypography
\usepackage{array}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{amsthm}

%% Header
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[C]{COMP 136 - 2020s - HW2 Submission}
\fancyfoot[C]{\thepage} % page number
\renewcommand\headrulewidth{0pt}
\pagestyle{fancy}

%% Hyperlinks always blue, no weird boxes
\usepackage[hyphens]{url}
\usepackage[colorlinks=true,allcolors=black,pdfborder={0 0 0}]{hyperref}

%%% Doc layout
\usepackage{parskip}
\usepackage{times}

%%% Write out problem statements in blue, solutions in black
\usepackage{color}
\newcommand{\officialdirections}[1]{{\color{blue} #1}}

%%% Avoid automatic section numbers (we'll provide our own)
\setcounter{secnumdepth}{0}

\begin{document}
~~\\ %% add vert space

{\Large{\bf Student Name: TODO}}

{\Large{\bf Collaboration Statement:}}

Turning in this assignment indicates you have abided by the course Collaboration Policy:

\url{www.cs.tufts.edu/comp/136/2020s/index.html#collaboration-policy}

Total hours spent: TODO

I consulted the following resources:
\begin{itemize}
\item TODO
\item TODO
\item $\ldots$
\end{itemize}

FYI Official instructions for all problems can be found at:

\url{www.cs.tufts.edu/comp/136/2020s/hw2.html}

\tableofcontents

\newpage
\officialdirections{
\subsection*{1a: Problem Statement}

Consider the estimator $\hat{\sigma}^2$:
\begin{align}
\hat{\sigma}^2(x_1, \ldots x_N) = \frac{1}{N} \sum_{n=1}^N (x_n - \mu_{\text{true}})^2
\end{align}
Compute the expected value of this estimator under the sampling distribution of the observations $x$. You should assume each $x_n$ are drawn i.i.d from $x_n \sim \mathcal{N}( \mu_{\text{true}}, \sigma^2_{\text{true}})$.
}

\subsection{1a: Solution}

\newpage
\officialdirections{
\subsection*{1b: Problem Statement}
Given your result above, describe if the estimator is biased or unbiased.
}

\subsection{1b: Solution}

TODO

\officialdirections{
\subsection*{1c: Problem Statement}
How does your answer about bias in 1b compare to what we learned about whether the maximum likelihood estimator for the variance is biased? Provide some justification.
}

\subsection{1c: Solution}
TODO

\newpage
\officialdirections{
\subsection*{2a: Problem Statement}

Show that the SGD estimator is an *unbiased* estimator of the whole dataset gradient. That is, show:
\begin{align}
\mathbb{E}_{i \sim U}[ \hat{G}(\theta, x_i) ] = G(\theta, x)
\end{align}
}

\subsection{2a: Solution}

\newpage
\officialdirections{
\subsection*{2b: Problem Statement}
How will the $\theta$ value estimated by whole dataset gradient descent (which has no randomness) typically compare to resulting $\theta$ from SGD? Why is it important that the SGD estimator is unbiased?
}

\subsection{2b: Solution}

\newpage
\officialdirections{
\subsection*{3a: Problem Statement}
Given the log PDF below, show that $x$ has a univariate Gaussian distribution.
\begin{align}
\log p(x) = \text{const} - \frac{1}{2} a x^2 + bx
\end{align}
where $a > 0$ and $b$ is any number.
}

\subsection{3a: Solution}

\newpage
\officialdirections{
\subsection*{3b: Problem Statement}
Given the log PDF below, show that vector $x$ has a multivariate Gaussian distribution.
\begin{align}
\log p(x) = \text{const} - \frac{1}{2} x^T A x + b^T x
\end{align}
where $A$ symmetric and positive definite, and $b$ any vector.
}

\subsection{3b: Solution}

\newpage
\officialdirections{
\subsection*{4a: Problem Statement}
For the case $M=1$, show that we can write $S_{N+1}^{-1} = S_N^{-1} + v^2$ for some scalar value $v$.
}

\subsection{4a: Solution}

\newpage
\officialdirections{
\subsection*{4b: Problem Statement}
For the case $M=1$, write an expression for $\sigma^2_{N+1} - \sigma^2_{N}$, simplifying as much as possible.
}

\subsection{4b: Solution}

\newpage
\officialdirections{
\subsection*{4c: Problem Statement}
By studying the terms of your expression from **4b**, prove the following statement:

$$
\sigma_{N+1}^2(x_*) \leq \sigma_N^2(x_*)
$$
}

\subsection{4c: Solution}

\newpage
\officialdirections{
\subsection*{5a: Problem Statement}
Show that we can write $S_{N+1}^{-1} = S_N^{-1} + vv^T$ for some vector $v$.
}

\subsection{5a: Solution}

\newpage
\officialdirections{
\subsection*{5b: Problem Statement}
\begin{align}
(A + vv^T)^{-1} &= A^{-1} - \frac{ (A^{-1}v)(v^T A^{-1})}{ 1 + v^T A^{-1} v}
\end{align}

Substitute $A = S_N^{-1}$ and $v$ from 5a, then simplify to write an expression for $S_{N+1}$ in terms of $S_{N}$.
}

\subsection{5b: Solution}

\officialdirections{
\subsection*{5c: Problem Statement}
Show that $\sigma^2_{N+1}(x_*) - \sigma^2_{N}(x_*) = \phi(x_*)^T \left[ S_{N+1} - S_{N} \right] \phi(x_*)$

}

\subsection{5c: Solution}

\newpage
\officialdirections{
\subsection*{5d: Problem Statement}
Finally, plug your result from 5c into 5d, plus the fact that $S_N$ must be positive definite, to show that:
\begin{align}
\sigma_{N+1}^2(x_*) \leq \sigma_N^2(x_*), \quad \text{or equivalently} \quad \sigma_{N+1}^2(x_*) - \sigma_N^2(x_*) \leq 0
\end{align}
}

\subsection{5d: Solution}

\end{document}


\documentclass[12pt]{article}

\usepackage{eurosym}
\include{preamble}

\title{Math 241 Fall 2016 \\ Final Examination}
\author{Professor Adam Kapelner}

\date{December 15, 2016}

\begin{document}
\maketitle

\noindent Full Name \line(1,0){270} ~~~ Section (A or B)~ \line(1,0){30}

\thispagestyle{empty}

\section*{Code of Academic Integrity}

\footnotesize
Since the college is an academic community, its fundamental purpose is the pursuit of knowledge. Essential to the success of this educational mission is a commitment to the principles of academic integrity. Every member of the college community is responsible for upholding the highest standards of honesty at all times. Students, as members of the community, are also responsible for adhering to the principles and spirit of the following Code of Academic Integrity.

Activities that have the effect or intention of interfering with education, pursuit of knowledge, or fair evaluation of a student's performance are prohibited. Examples of such activities include but are not limited to the following definitions:

\paragraph{Cheating} Using or attempting to use unauthorized assistance, material, or study aids in examinations or other academic work or preventing, or attempting to prevent, another from using authorized assistance, material, or study aids. Example: using a cheat sheet in a quiz or exam, altering a graded exam and resubmitting it for a better grade, etc.
\\

\noindent I acknowledge and agree to uphold this Code of Academic Integrity. \\

\begin{center}
\line(1,0){250} ~~~ \line(1,0){100}\\
~~~~~~~~~~~~~~~~~~~~~signature~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ date
\end{center}

\normalsize

\section*{Instructions}

This exam is 120 minutes and closed-book. You are allowed three pages (front and back) of a \qu{cheat sheet.} You may use a graphing calculator of your choice but \emph{no cell phones}. Please read the questions carefully. If the question reads \qu{compute,} this means the solution will be a number otherwise you can leave the answer in choose, permutation, factorial, summation or any other notation which could be resolved to a number with a computer. I advise you to skip problems marked \qu{[Extra Credit]} until you have finished the other questions on the exam, then loop back and plug in all the holes. I also advise you to use pencil. The exam is 100 points total plus extra credit. Partial credit will be granted for incomplete answers on most of the questions. \fbox{Box} in your final answers. Good luck!

\pagebreak

\problem You are the biostatician for a drug company that is trying to develop a drug to treat skin cancer which has spread to lymph nodes (we will call this the \qu{disease}). There are no drugs currently available for the disease so the company is developing a drug and wants to run a trial in the future.

\begin{center}
\includegraphics[width=2in]{pills.png}
\end{center}

\noindent The recovery rate right now for patients with the disease is 63\%. Assume this is the truth known with certainty.

\benum
\subquestionwithpoints{2} Bob who has the disease wants to be part of the drug trial. Model Bob's recovery as of now as 1 if he recovers and 0 if he does not recover as a r.v. below. Be sure to indicate parameter value(s). \spc{1}

\subquestionwithpoints{3} 100 people just like Bob with the disease want to be part of the trial. Model the total number of people of those 100 who will recover as of now below as the r.v. $X$. Be sure to indicate parameter value(s). \spc{1}

\subquestionwithpoints{4} What two assumptions did you make about the 100 people in order to build the model in part (b)? Explain each in this context.

\begin{table}[h]
\centering
\begin{tabular}{l|l}
Assumption Name: \hspace{2.0in} & Assumption Name: \hspace{2.0in} \\ \hline
Discussion: & Discussion: \\
& \\
& \\
& \\
& \\
& \\
& \\
& \\
\end{tabular}
\end{table}

\subquestionwithpoints{2} Calculate the expected number of people of the 100 who will recover.  \spc{1}

\subquestionwithpoints{3} Compute explicitly the percentage that exactly 63 people will recover. Round to two decimal places. \spc{3}

%\subquestionwithpoints{3} Why is your answer to (f) so low? Discuss. \spc{3}

\subquestionwithpoints{5} For those 100 people just like Bob with the disease, model the \textit{proportion} of people who will recover below as the r.v. $\Phat$ and provide its \textit{approximate} distribution. Be sure to indicate parameter values.\spc{5}

\subquestionwithpoints{2} What theorem did you use to answer (h)? No need to discuss. \spc{1}

\subquestionwithpoints{2} Find $\prob{\Phat = 0.63}$ below assuming the approximate distribution (and not the distribution of the r.v. in part b). \spc{0.1}

\subquestionwithpoints{2} We will now start testing our drug. Denote the proportion of people who truly recover as the population parameter $p$. We are unsure if the drug works and want to be scientifically honest. Thus our null hypothesis will be that the proportion of people who recover when taking the drug will be \textit{at most} the same as the population overall. Write this in our notation we used in class below. \spc{1}

\subquestionwithpoints{2} Write the alternative hypothesis using the notation we learned in class. \spc{0.1}

\subquestionwithpoints{1} What is the official name of this statistical test? \spc{1}

\subquestionwithpoints{2} We will set $\alpha = 2.5\%$ since the scientific community is very conservative when it comes to new drugs. What is the probability of a Type I error?\spc{2}

\subquestionwithpoints{3} Explain what a Type I error would be in this context.\spc{1}

\subquestionwithpoints{3} Explain what a Type II error would be in this context.\spc{1}

\subquestionwithpoints{3} Discuss what you believe the cost of a type II error would be in this case. \spc{2}

\subquestionwithpoints{5} For the case where we have $n=100$ people who take the drug, find the retainment region for $H_0$ in this hypothesis test. Round to three digits. \spc{8}

\subquestionwithpoints{5} Imagine 72 people of the 100 in the drug trial recovered. Run the hypothesis test, state the conclusion and then write a sentence which explains your conclusion in the context of drug trial. \spc{4}

\subquestionwithpoints{1} Regardless of the conclusion of the hypothesis test, you \emph{feel} deep down inside that the drug is effective in increasing the recovery rate of the disease. What type of error do you \emph{feel} you made here? No explanation necessary. \spc{1}

\subquestionwithpoints{3} If you were to design another experiment to prove that the drug is effective, what would you do differently and why? Hint: increasing $\alpha$ is \textit{not} the answer. \spc{3}

\subquestionwithpoints{2} Regardless of the conclusion of the hypothesis test, we will pretend that the point estimate you computed, i.e. $\phat = 0.72$, represents the real probability of recovery under the drug. Denote $R$ as the event of recovery and $D$ as the event that the drug was taken. Thus $R^C$ denotes the person did not recover and $D^C$ denotes the person did not take the drug. What is $\cprob{R}{D}$? \spc{1}

\subquestionwithpoints{1} Find $\cprob{R^C}{D}$.\spc{2}

\subquestionwithpoints{6} Let's say the drug is on the market and you estimate 20\% of the people who have the disease take the drug. You see someone who recovers, what is the probability they took the drug? \spc{7}

\eenum

\problem You are part of a call center for a very large company.

\begin{center}
\includegraphics[width=4in]{call.png}
\end{center}

\noindent You have millions of clients but the probability each of them call in at any moment is very small. If there are 3,000,0000 clients and the probability any of them call in any second is 1 in 1,000,000 then you can say $\lambda = 3$ and model time in seconds until the next call as an \emph{exponential} distribution.

\benum
\subquestionwithpoints{2} Based on the description above, denote the time until the next call as r.v. $X$. Notate its distribution below as $X \sim$ something.\spc{5}

\subquestionwithpoints{4} Provide a rough illustration of $f(x)$. Label the axes and label one point on the y-axis that is not 0. Do not worry about scale. \spc{6}

\subquestionwithpoints{4} Provide a rough illustration of $F(x)$. Label the axes and label one point on the y-axis that is not 0. Do not worry about scale.  \spc{5}

\subquestionwithpoints{4} What is the probability we will wait more than 5 seconds for the next call that comes in? No need to compute explicitly. \spc{3}

\subquestionwithpoints{4} 4 seconds just elapsed. Given this information, what is the probability we will wait more than 5 seconds for the next call that comes in? No need to compute explicitly. \spc{3}

\eenum

\problem Some theoretical exercises are below.

\benum
\subquestionwithpoints{3} On the homework you were introduced to the r.v. $X \sim \poisson{\lambda}$. The PMF is $p(x) = \lambda^x e^{-\lambda} / x!$. If $\support{X} = \naturals \cup \braces{0}$, write an expression for $\expe{X}$ but \textit{do not solve}.\spc{2}

\subquestionwithpoints{5} On the homework you were given that if $X \sim \poisson{\lambda}$ then $M_X(t) = e^{\lambda(e^t - 1)}$. Find $\expe{X}$ by any way you believe to be best.\spc{5}

\subquestionwithpoints{3} Calculate

\beqn
\int_2^\infty \oneoversqrt{2\pi} e^{-\half\squared{x-2}}dx = \quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad
\eeqn\spc{3}

\subquestionwithpoints{2} Let $X \sim \uniform{0}{1}$. Compute $\se{X}$ to two decimal places.\spc{3}

\subquestionwithpoints{2} Assume $\prob{A} > 0$. Compute $\cprob{A}{A}$. \spc{2}

\subquestionwithpoints{5} You are riding the F train from Roosevelt Ave Jackson Heights to Forest Hills 71Av/Continental.

\begin{center}
\includegraphics[width=5in]{f_train.png}
\end{center}

\noindent That means you are traveling for 6 stops. The traveling time of each stop can be modeled as a r.v. with distribution $\normnot{1}{0.2042^2}$ minutes and we will assume independent travel time for each stop. Find the probability it takes you more than 7 minutes to get from Roosevelt Ave Jackson Heights to Forest Hills 71Av/Continental.\spc{10}

\subquestionwithpoints{5} [Extra credit] Prove or disprove: $X \sim \uniform{a}{b}$ has the memorylessness property. \spc{7}

\subquestionwithpoints{5} [Extra credit] If $X \sim \poisson{\lambda}$, find $\var{X}$. \spc{7}

\subquestionwithpoints{5} [Extra credit] Find the skewness of the standard normal.

\eenum

\end{document}

\problem Imagine a bag with 171 marbles each unique.

\begin{center}
\includegraphics[width=2in]{marbles.jpg}
\end{center}
\benum

\subquestionwithpoints{3} Imagine you select 19 balls with replacement. How many ways are there to select balls if their order matters and selection order matters? \spc{1}

\subquestionwithpoints{3} Imagine you select 19 balls with replacement. How many ways are there to select balls if their order does not matter? \spc{1}

\subquestionwithpoints{3} Imagine you select 19 balls without replacement. How many ways are there to select balls if their order matters? \spc{1}

\subquestionwithpoints{3} Imagine you select 19 balls without replacement. How many ways are there to select balls if their order does not matter? \spc{1}

%\subquestionwithpoints{2} Although they're all different, 13 of them are red and the red ones are special. If you pull out 10 marbles, how many red ones are you able to get? \spc{1}

%\subquestionwithpoints{3} Although they're all different, 29 of them are red and the red ones are special. If you pull out 150 marbles without replacement, how many red ones are you able to get? \spc{1}

%\subquestionwithpoints{2} What is the probability of getting 11 red ones on a draw of 150 without replacement? No need to compute explicitly. \spc{1}

%\subquestionwithpoints{3} 23 of them are red and the red ones are special. Imagine you have already drawn 10 red marbles on a draw of 10 without replacement. What is the chance you now get another 10 marbles in a draw of 140 without replacement? No need to compute explicitly. \spc{3}

%\subquestionwithpoints{2} Imagine you have already drawn 10 red marbles on a draw of 10 without replacement. What is the chance you now get another 10 marbles in a remaining draw of 140 \textit{with} replacement? No need to compute explicitly. \spc{1}

\eenum

\problem Some theoretical exercises are below.

\benum

\subquestionwithpoints{2} Consider the following r.v.,

\beqn
X \sim \begin{cases}
2 \withprob 1/7 \\
4 \withprob 4/7 \\
-3 \withprob 2/7 \\
\end{cases}
\eeqn

Provide a set $\Omega$ for the domain of this r.v. \spc{1}

\subquestionwithpoints{3} For the r.v. above, describe or illustrate (any way you can) of a physical device that will create the r.v. Be sure to use $\Omega$ in your illustration from (a).\spc{5}

\subquestionwithpoints{2} Could it be possible that $\abss{\support{X}} < \abss{\Omega}$? Write \qu{yes} or \qu{no} only. \spc{1}

\eenum

\problem Some more theoretical exercises are below.

\benum

\subquestionwithpoints{4} Consider $X \sim \uniformdiscrete{a_1, a_2, a_3, a_4}$ i.e. $\abss{\support{X}} = 4$. Find the MGF of $X$ denoted by $M_X(t)$. \spc{2}

\subquestionwithpoints{7} Consider a large number of $X_1, \ldots, X_n \iid \uniformdiscrete{a_1, a_2, a_3, a_4}$. Consider $X_1 + \ldots + X_n$. What is its approximate distribution? Answer in as much detail as you can provide (partial credit will be given). Use sum notation for compactness.  \spc{6}

\subquestionwithpoints{7} Consider $Y_1$ being distributed as 5 or 10 with equal probability and $Y_2 \sim \bernoulli{\half}$ where $Y_1$ and $Y_2$ are independent. Show that $Y_1 + Y_2$ is a uniform discrete r.v. with $\abss{\support{X}} = 4$ using MGF's. \spc{8}

\subquestionwithpoints{3} [E.C.] Give examples of $a_1, a_2, a_3, a_4$ above which would most likely break the approximation from part (d) for a modest size $n$. \spc{2}

\subquestionwithpoints{3} [E.C.] Find $\expe{\tothepow{\frac{X-\mu}{\sigma}}{13}}$ where $\mu$ and $\sigma$ are the mean and standard error of $X$ respectively. \spc{1}

\eenum

\problem We will investigate more about aliens and UFOs by looking at data from the \href{http://www.nuforc.org/webreports/ndxevent.html}{National UFO Reportion Center Online Database}.

\begin{figure}[htp]
\centering
\includegraphics[width=2in]{ufo.jpg}
\end{figure}

Below is the number of events in each month in 2014 and represents the number of \qu{UFO sightings} across America, a country with 319 million people. Assume that each sighting is unique --- that is each person either makes a sighting for a given or does not and there are no duplicates. That is, a person cannot make more than one sighting per 12-month period.

\begin{table}[htp]
\small
\centering
\begin{tabular}{c|c}
Month & Number \\ \hline
12/2014 &	521 \\
11/2014	&543 \\
10/2014	&786 \\
09/2014	&829 \\
08/2014	&922 \\
07/2014	&1096 \\
06/2014	&776 \\
05/2014	&652 \\
04/2014	&666 \\
03/2014	&517 \\
02/2014	&554 \\
01/2014	&715 \\
\end{tabular}
\end{table}

\benum

\subquestionwithpoints{2} We are interested in the true proportion of people who sight a UFO per year (not per month). Provide an estimate of this proportion below. Round to the nearest two digits. \spc{0.5}

\subquestionwithpoints{6} Provide a 99.7\% confidence interval for the true proportion of people worldwide who see a UFO yearly. \spc{5}

\subquestionwithpoints{3} Give two possible concerns as to why the confidence interval you produced in (b) may not be valid.

\begin{enumerate}
\item [1.] ~\\~\\
\item [2.]
\end{enumerate}

\subquestionwithpoints{4} Regardless of the issues in (c), provide four possibe interpretations of the CI from (b).

\begin{enumerate}
\item [1.] ~\\~\\~\\
\item [2.]~\\~\\~\\
\item [3.]~\\~\\~\\
\item [4.]~\\~\\~\\
\end{enumerate}

\subquestionwithpoints{3} Let's assume the point estimate of (a) is equal to the real population proportion (assume $p = \phat$ for the remainder of the problem). Assume 2015 is the same as 2014 with regards to UFO sightings (and the population of America remained the same to the nearest million people). What is the probability of less than 100,000 sightings in 2015? No need to compute exactly. Sum notation allowed.\spc{2}

\subquestionwithpoints{2} It is possible some states have more UFO sightings than other states. Hawaii had 67 sightings in 2014 for a population of 1.42 million people. Here are some examples:

\begin{table}[htp]
\centering
\footnotesize
\begin{tabular}{lllll}
Timestamp & City & Shape & Duration & Description \\ \hline
1/15/14 03:30&	Paia	HI&	Sphere	&2 min	&  I Saw a golden sphere \\
&&&&shaped object hovering over the water \\
&&&&on the North Shore at 3:30am.	 \\
1/15/14&	Kealia	HI	&Fireball	&20 min&	Fireball w- chinese laturns and parade \\
&&&& of triangles.	 \\
1/14/14 20:50&	Waimanalo	HI	&Fireball&	5 sec&	I saw an orange fireball with flames \\
&&&& trailing as it shot diagonally across \\
&&&& the sky and disappeared behind the\\
&&&& nearby mountain range.	 \\
%1/10/14 22:58&	Kaneohe	HI&	Fireball&	90 sec&	A silent red ball of light traveled \\
%&&&&off the pacific ocean from the east \\
%&&&&to the south below the clouds for \\
%&&&&about 90 seconds.	 \\
\end{tabular}
\end{table}

Find the sample proportion for seeing a UFO sighting in a year in Hawaii. Round to two digits. \spc{2}

\subquestionwithpoints{7} Test whether this proportion is different than the proportion in America overall.

\begin{enumerate}
\item [$H_0$:] ~\\
\item [$H_a$:] ~\\
\item [$\alpha =$] ~~~~~~~~ $\Rightarrow z_{\alpha/2} = $
\end{enumerate}~ \spc{2.5}

\subquestionwithpoints{2} Based on your result in (g), is the event of being in Hawaii and the event of seeing a UFO over the course of a year independent or dependent? Explain using the definition of dependence and independence. \spc{2}

\eenum

\problem We return to our discussion of Chevalier de Mere and his compulsive dice gambiling.

\begin{figure}[htp]
\centering
\includegraphics[width=1.31in]{chevalier.jpg}~\includegraphics[width=2in]{dice.jpg}
\end{figure}

\benum

\subquestionwithpoints{3} Recall the dice game he played: you win if you get at least one 6-6 in 24 rolls of two dice. What is the probability of winning? Compute to four decimal places. \spc{3}

\subquestionwithpoints{6} Chevalier de Mere most likely thought the probability of winning was 0.5 (not your answer from the previous question). Assuming Chevalier de Mere went easy on the wine and cigarettes and kept perfect records of wins and losses of everyone playing this game, how many games (denoted $n$) did he have to watch to be sure (at the 5\% level) that the probability of winning was less than 50\%. You can leave as an algebraic equation of $n$; you do not need to solve.\spc{7}

\eenum

\problem We learn about a bank alert system here for detecting fraudulent charges on a credit card.
\begin{figure}[htp]
\centering
\includegraphics[width=3in]{credit.jpg}
\end{figure}

\benum

\subquestionwithpoints{2} Assume each charge is legitimate from the start. What are the null and alternative hypotheses for this situation with credit card charges? No credit given for the general definition. Answer in English. \spc{1.5}

%\subquestionwithpoints{2} Describe a Type I error for this situation with credit card charges. No credit given for the general definition. \spc{2}

\subquestionwithpoints{3} Describe a Type II error for this situation with credit card charges. No credit given for the general definition. Answer in English. \spc{2}

\subquestionwithpoints{3} Assume the Type I error rate is $\alpha$ with cost $C_I \sim \normnot{\$100}{\$50^2}$ and the Type II error rate is $\beta$ with cost $C_{II} \sim \normnot{\$500}{\$38^2}$. What is the expected cost to the bank for a single credit card transaction? \spc{3}

%\subquestionwithpoints{3} Assuming the bank cannot change the two costs ($C_I$ and $C_{II}$). Give a strategy for the bank to minimize the expected cost in (d) without any chance of inadvertently increasing it. \spc{1}

\eenum

\problem Some questions about continuous r.v.'s

\benum

\subquestionwithpoints{2} The chi-squared distribution (denoted $\chi^2_k$) has a PDF given by

\beqn
\chi^2_k := f(x) = \frac{1}{2^{\frac{k}{2}}\Gamma\left(\frac{k}{2}\right)}\; x^{\frac{k}{2}-1} e^{-\frac{x}{2}}
\eeqn

and its support is all non-negative numbers. Note that the gamma function (denoted $\Gamma$) is evaluated to a number using a computer.  \\

What are the parameter(s) of the $\chi^2_k$ model?\spc{2}

\subquestionwithpoints{4} Write an integral expression for $\expe{X}$ where $X \sim  \chi^2_k$. \spc{4}

\subquestionwithpoints{4} Write an integral expression for $F(x)$ where $X \sim  \chi^2_k$. \spc{4}

\subquestionwithpoints{3} Consider $T \sim \exponential{\lambda}$ which represents the time spent waiting for the Q64 in minutes. What is the probability of waiting more than 10 minutes? \spc{3}

\subquestionwithpoints{4} A stopwatch beeps every minute. After each beep, which r.v. models the waiting time in minutes for the Q64? Assume of course the bus hasn't come by the beep.  \spc{2}

%\subquestionwithpoints{2} A stopwatch beeps every 1$\mu$s (that's one-millionth of a second). After each beep, which r.v. models the waiting time in minutes for the Q64? Assume of course the bus hasn't come by the beep.  \spc{2}

\eenum

\problem Some theoretical questions below

\end{document}