%------------------------------------------------
% FILENAME: assignment_0_revised.tex
%  PROJECT: mathbootcamp
%   AUTHOR:Joe Patten
%    EMAIL: joe.patten@wsu.edu
%  WEBSITE: http://joepatten.github.io
%------------------------------------------------
\documentclass[a4paper, 11pt]{article}
\usepackage{assignment_0_style}

\title{ Mathematics Bootcamp Assignment 0 }

\begin{document}
\maketitle

There are 43 problems in this assignment.
Take a deep breath.
That is a lot, but many are quite quick if you have taken courses in calculus. The questions are not meant to be exhaustive of all important topics in univariate calculus.
Instead, they are intended to \emph{nudge} you to remember things you likely once learned, but forgot.
For example, the rules of limits, l'Hopital's rule, continuity, the product rule, the chain rule, the fundamental theorem of calculus, taylor series, integration, the intermediate value theorem, the mean value theorem, inverse functions, implicit differentiation, etc.

\section{Calculus}

\paragraph{Problem 1} Compute
\begin{align}
    \lim_{x\rightarrow 3} \frac{5x^2 - 8x -13}{x^2-5}  \nonumber
\end{align}

\paragraph{Problem 2} Compute
\begin{align}
    \lim_{x\rightarrow 3} \frac{x^4 - 81}{2x^2-5x-3}  \nonumber
\end{align}

\paragraph{Problem 3}
Compute
\begin{align}
    \lim_{x\rightarrow 4} \frac{3-\sqrt{x+5}}{x-4}  \nonumber
\end{align}

\paragraph{Problem 4}
Consider the values of constants $a$ and $b$ so that $\lim_{x \rightarrow 2} f(x)$ exists and is equal to $f(2)$ where $f(x)$ is defined as below.
\begin{align}
    f(x) = \begin{cases}
    			a + bx & \text{ if } x > 2 \\
    			3 & \text{ if } x=2 \\
    			b-ax^2 & \text{ if } x < 2
    	   \end{cases}  \nonumber
\end{align}

\paragraph{Problem 5}
Compute the following limit.
\begin{align}
    \lim_{x\rightarrow \infty} \frac{100}{x^2 + 5}  \nonumber
\end{align}

\paragraph{Problem 6}
Compute
\begin{align}
    \lim_{x\rightarrow \infty} (3x^3 - 1000x^2)  \nonumber
\end{align}

\paragraph{Problem 7}
Compute
\begin{align}
    \lim_{x\rightarrow \infty} \frac{7x^2 + x - 100}{2x^2 - 5x}  \nonumber
\end{align}

\paragraph{Problem 8}
Compute
\begin{align}
    \lim_{x\rightarrow \infty} \left( 3^x + 3^{2x} \right)^{\frac{1}{x}}  \nonumber
\end{align}

\paragraph{Problem 9}
Compute $\lim_{x\rightarrow 0^+} \; x \cdot \ln x$.

\paragraph{Problem 10}
Compute $\lim_{x \rightarrow 0^+} x \cdot \left( \ln x \right)^2$.

\paragraph{Problem 11}
Compute $\lim_{x \rightarrow 0 } (1-x)^{1/x}$.

\paragraph{Problem 12}
Consider the following functions for $w \geq 0$ and $0 < \sigma < 1$.
\begin{align}
    u(w) &= \frac{w^{1-\sigma}-1}{1-\sigma}  \nonumber \\
    u(w) &= \ln(w) \nonumber \nonumber \\
    u(w) &= \sqrt{w} \nonumber
\end{align}
For each function above, find the following limits (if they exist) where $u'(\cdot)$ and $u''(\cdot)$ represent the first and second derivatives respectively.
\begin{enumerate}[(i)]
	\item $\lim_{w\rightarrow 0} \; -u''(w)/u'(w)$.
	\item $\lim_{w\rightarrow \infty} \; -u''(w)/u'(w)$.
	\item $\lim_{w\rightarrow 0} \; (-u''(w)\cdot w)/u'(w)$.
	\item $\lim_{w\rightarrow \infty} \; (-u''(w)\cdot w)/u'(w)$.
\end{enumerate}

\paragraph{Problem 13} Differentiate $y = x^x$ (with respect to $x$).

\paragraph{Problem 14} Differentiate $y = x^{e^x}$ (with respect to $x$).

\paragraph{Problem 15} Compute the following limits associated with the functions $f(x) = |x|$.
\begin{align}
    &\lim_{h\rightarrow 0} \frac{f(-2 + h) - f(-2)}{h}  \nonumber \\
    &\lim_{h\rightarrow 0} \frac{f(0 + h) - f(0)}{h} \nonumber \\
    &\lim_{h\rightarrow 0} \frac{f(3 + h) + f(3)}{h} \nonumber
\end{align}

\paragraph{Problem 16}
Define the intervals (if any) over which the following function is continuous.
\[
	f(x) = \frac{7x^5 + x - 2}{x^2-4}
\]

\paragraph{Problem 17}
Show that there is a root of the equation $3x^7 - 2x^5 + x -1 = 0$ between $0$ and $1$.

\paragraph{Problem 18}
Compute the following limit associated with $f(x) = x^2 - 8x + 9$.
\[
	\lim_{x\rightarrow a} \; \frac{(x^2-8x+9)-(a^2-8a+9)}{x-a}
\]

\paragraph{Problem 19}
If the function $f(x)$ is differentiable in the interval $(a,b)$ and $|f'(x)| \leq B < \infty$ for all $x$ in the interval $(a,b)$ then is the maximum change in the function over any sub interval $(c,d) \subseteq (a,b)$ finite or infinite? Prove it.

\paragraph{Problem 20}
If the function $f(x)$ is differentiable on $(a,b)$, but not continuously differentiable, then is $f$ continuous everywhere on $(a,b)$? Prove it. (Hint: use a theorem)

\paragraph{Problem 21}
Can you differentiate the expression $2x = 1$? If so what is the derivative?  If not, why not?

\paragraph{Problem 22} Find the derivative of the function
\[
	f(x) = \frac{\sqrt[4]{x}}{x^{-1} \sqrt{x^5}}
\]

\paragraph{Problem 23} Differentiate the function
\[
	f(x) = \frac{3x^2 - 5\sqrt{x} }{ 6x^4 }
\]

\paragraph{Problem 24}
Find the linearization of the function $f(x) = \sqrt[3]{1+x}$ at $a=0$ and use it to approximate the numbers $f(-0.05)$ and $f(0.1)$.
Are these approximations overestimates or underestimates?

\paragraph{Problem 25}
Let $f(x) = (3x-5)/(4-2x)$ and find $f^{-1}(x)$.  Then compare $f'(x)$ and $\frac{d}{dx} f^{-1}(x)$ and describe the relationship (if any).

\paragraph{Problem 26}
Compute the derivative of the following function, $H(p)$, with respect to $p$ and use it to show the answer to the following questions.
\begin{align}
    H(p) &= p \log_2 \left(\frac{1}{p} \right) + (1-p)\log_2 \left(\frac{1}{1-p} \right)  \nonumber
\end{align}
\begin{enumerate}[(i)]
	\item Is there a global maximum and minimum over the interval $[0,1]$, if so, what is it?
	\item If so, over what subset of $[0,1]$, if any, is the function increasing?
	\item If so, over what subset of $[0,1]$, if any, is the function decreasing?
\end{enumerate}

\paragraph{Problem 27}
Consider the function $f(x) = x^4 e^x$ with domain all real numbers.
\begin{enumerate}[(i)]
	\item Find the $x$-value(s) of all roots ($x$-intercepts) of $f$.
	\item Find the $x$- and $y$-value(s) of all critical points and identify each as a local max, local min, or neither.
	\item Find the $x$- and $y$-value(s) of all global extrema and identify each as a global max or global min.
	\item Find the $x$-value(s) of all inflection points.
\end{enumerate}

\paragraph{Problem 28}
Use the Intermediate Value Theorem to show that $f(x) = x^3 - 2x - 1$ has a root on $[1,2]$.

\paragraph{Problem 29}
Does the Extreme Value Theorem say anything about the function $f(x) = x^2$ on each of the following intervals? If so what does it say?  In either case, explain why.
\begin{enumerate}[(i)]
	\item $[1,4]$
	\item $(1,4)$
\end{enumerate}

\paragraph{Problem 30}
Find the value of the constant $c$ that the Mean Value Theorem specifies for $f(x)=x^3 + x$ on the interval $[0,3]$.

\paragraph{Problem 31}
For the equation $x^3 + y^3 = \ln(xy) - 1$ use implicit differentiation to find $\dd y/ \dd x$.

\paragraph{Problem 32}
Consider the function
\[
	f(x) = \begin{cases}
				b-x^2 & \text{ if } x < 3 \\
				ax & \text{ if } x \geq 3
	 	   \end{cases}
\]
\begin{enumerate}[(i)]
	\item What condition(s) must be placed on the constants $a$ and $b$ in order for $f$ to be continuous on $(-\infty, \infty)$?
	\item For what values of the constants $a$ and $b$ will $f$ be differentiable on $(-\infty, \infty)$?
\end{enumerate}

\paragraph{Problem 33}
Consider the function $f(x) = \ln(x^2)$.
Find the fourth-order Taylor polynomial for $f(x)$ centered at $x_0=1$.

\paragraph{Problem 34}
Let $X$ be a random variable with a probability density function (PDF) $f(x)$
\[
	f(x) = \begin{cases}
 				ce^{-x/3} & \text{ for } x > 0 \\
 				0 & \text{ otherwise }
 		   \end{cases}
\]
Remember that a PDF has the property that $\int_{\infty}^{\infty} f(x)\dd x = 1$.
\begin{enumerate}[(i)]
	\item Find the value of the constant $c$ that makes $f(x)$ a valid PDF.
	\item Find the probability that $X \leq 1/4$.
\end{enumerate}

\paragraph{Problem 35}
Find the derivative of the following function
\[
	G(x) = \int_{1}^{\sin{x}} t \dd t
\]

\paragraph{Problem 36}
Find the derivative of the following function
\[
	G(x) = \int_{72}^{\ln(x)} t \dd t
\]

\paragraph{Problem 37}
Suppose that $\sum_{n=1}^{\infty} a_n$ represents a convergent series and that no term of the series equals zero, i.e., $a_n \neq 0$ for all $n=1,2, \dots$.
Prove that $\sum_{n=1}^{\infty} 1/a_n$ is a divergent series.

\paragraph{Problem 38}
Determine whether the given sequence is increasing, decreasing, or not monotonic.
Is the sequence bounded?  On the basis of what you find, does the series converge, diverge or can't be determined?
\[
	a_n = \frac{1}{5^n}
\]

\paragraph{Problem 39}
Differentiate the function $y = 3(x^2-1)^3 (x^2 + 1)^5$.

\paragraph{Problem 40}
Consider a continuously differentiable utility function $u(\cdot)$ such that $u'>0$ and $u'' < 0$.
Utility comes from income $I$ which takes on two different values $I_H(x)$ and $I_L(x)$ and that the probability of that $I=I_H$ is given by $p(x)$ where $x\geq 0$ and $p'(x)>0$.
Differentiate the expected utility with respect to $x$.
\[
	E[u] = p(x)u[I_H(x)] + (1-p(x))u[I_L(x)]
\]

\paragraph{Problem 41}
Consider a twice continuously differentiable utility function $U(\cdot)$ such that $U'>0$ and $U''< 0$.
Utility comes from wealth $W$ and a person takes a gamble $h$ that represents a gain or loss to the a person's wealth and $h=0$ on average ($E(h)=0$).
Let $p$ represent the size of an insurance premium paid to avoid taking the gamble and makes the person exactly indifferent between the gamble $h$ and paying $p$ with certainty.
Let $E$ represent the expectation operator.
Use the identity below to answer the questions.
\[
	E[U(W + h)] \equiv U(W-p)
\]
\begin{enumerate}[(i)]
	\item Derive a linear (first order) Taylor approximation of the right-hand side of the identity (with respect to $W$).
	\item Derive a quadratic (second order) Taylor approximation of the left-hand side of the identity (with respect to $W$).
	\item Let $r(W) = -U''(W)/U'(W)$ (this is the Arrow-Pratt measure of risk-aversion) use the previous approximations and the identity relationship to sign the derivative $\dd P / \dd r(W)$.  What is the sign and what relationship does this imply about the level of risk aversion and the amount of insurance premium an individual is willing to pay?
\end{enumerate}

\paragraph{Problem 42}
A new machine has a rental rate $v(s)$ at any time $s$ and depreciates at rate $d$.
With interest rate $r$ the present discounted value of this machine is
\[
	PDV(t) = \int_{t}^{\infty} e^{(r+d)t} v(s) e^{-(r+d)s} \dd s
\]
Let $p(t)$ be the purchase price of the machine at time $t$.
In equilibrium the purchase price at time $t$, $p(t)$ will equal the present discounted value and hence we have
\[
	p(t) = \int_{t}^{\infty} e^{(r+d)t} v(s)e^{-(r+d)s} \dd s
\]
\begin{enumerate}[(i)]
	\item Using the last expression for $p(t)$, find $\frac{dp(t)}{dt}$.
	\item Using your expression for $\frac{dp(t)}{dt}$ solve for $v(t)$ in terms of $p(t)$ to show the relationship between a new machines rental rate at time $t$ and the machine's purchase price at time $t$.
\end{enumerate}

\paragraph{Problem 43}
A forester must decide when to cut down a growing tree.
The value at any time $t$ is given by $f(t)$ where $f' > 0$ and $f'' < 0$ and there was an initial investment of $L$.
The continuous interest rate is $r$.
The forester must choose $t$ (the time of harvest) to maximize the present discounted value of her profits.
\[
	PDV(t) = e^{-rt}f(t) - L
\]
\begin{enumerate}[(i)]
	\item Differentiate $PDV(t)$ with respect to $t$.
	\item Use the derivative as a first order condition to characterize the relationship between the $t$ that maximizes the forester's present discounted value of profit and the interest rate $r$.
\end{enumerate}

\end{document}


\section{Security Analysis}
We look into attacks against the fundamental property:
$READ(Q_1,x) = READ(Q_2,x)$ for $\forall Q_1, Q_2 \in QS$, which is
known as equivocation.  The best that attackers can do is divide a
clique into two sets ($\mathcal{H}_1$ and $\mathcal{H}_2$) and ask
each set to sign $\langle x,t,v \rangle$ and $\langle x,t,v' \rangle$
separately. Then do the {\sf write} protocol for the target nodes with
collected signature sets $S$ and $S'$. Honest servers will refuse the
request because it does not satisfy the basic $b$-masking quorum
condition: $|S| \geq b+1$. But with $b+1$ colluding nodes
($\mathcal{F}$), the attack will succeed.

\ifdefined\ABSTRACT
\else
\newcommand{\slice}[4]{
  \pgfmathparse{0.5*#1+0.5*#2}
  \let\midangle\pgfmathresult

  % slice
  \draw[thick,fill=black!10] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;

  % outer label
  \node[label=\midangle:#4] at (\midangle:1) {};

  % inner label
  \pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
  \let\temp\pgfmathresult
  \pgfmathparse{max(\temp,-0.5) + 0.8}
  \let\innerpos\pgfmathresult
  \node at (\midangle:\innerpos) {#3};
}

\begin{tikzpicture}[scale=1.5]

\newcounter{a}
\newcounter{b}
\foreach \p/\t/\l in {25//,40/$\mathcal{H}_1$/Honest nodes,
20/$\mathcal{F}$/Faulty nodes, 40/$\mathcal{H}_2$/Honest nodes}
  {
    \setcounter{a}{\value{b}}
    \addtocounter{b}{\p}
    \slice{\thea/100*360}
          {\theb/100*360}
          {\t}{\l}
  }

\end{tikzpicture}
\fi

The maximum number of signatures dishonest clients can get is
$b+(n-b)/2$. Therefore, to overcome the attack we need:
\[ n-b > b+(n-b)/2 \Rightarrow n > 3b. \]

\subsubsection*{Detecting equivocation on {\sf read}}
Even if the number of faulty nodes exceeds the above threshold, the
system can detect malicious actions with the following probability:
\begin{align*}
  D_p &= Pr[Q \cap \mathcal{H}_1 \neq \emptyset \wedge Q \cap
        \mathcal{H}_2 \neq \emptyset] \\
      & = 1 - Pr[Q \subseteq \mathcal{F} \cup \mathcal{H}_1] \\
      & = 1 - ((n + f) / 2n)^{|Q|}
\end{align*}
when $f > b$ and $|Q| < (f + n)/2$, where $f = |\mathcal{F}|$ is the
number of the faulty nodes, assuming the sizes of $\mathcal{H}_1$ and
$\mathcal{H}_2$ are the same.

In the case of $f \le b$ malicious messages will never go through
therefore it does not make sense to talk about the detection rate on
{\sf read}, however, it is possible to detect malicious messages on
{\sf write} if such actions are taken by clients.
When the number of faulty nodes exceeds the threshold, i.e., $f > b$,
it will be possible that the (honest) client cannot detect all
malicious actions. Since the minimum quorum size is $(n-1)/3$ it does
not need to consider the case where $|Q| < n/3$. Also, if the size
exceeds $(f+n)/2$ any quorum always includes at least one node from
each $\mathcal{H}_i$ which makes the detection rate 100\%.

\ifdefined\ABSTRACT
\else
\begin{tikzpicture}[xscale=6,yscale=6]
  \draw [<->] (0,0.9) -- (0,0) -- (1.0,0);
  \node [below right] at (1,0) {$|Q|$};
  \node [left] at (0,{1-pow(17/300,0.7)}) {$1$};
  \node [left] at (0,0) {$0$};
  \node [below] at (0.3,0) {$n/3$};
  \node [below] at (0.7,0) {$(f+n)/2$};
  \draw[dashed, domain=0:0.3] plot (\x, {1-pow(17/300,\x)});
  \draw[thick, domain=0.3:0.7] plot (\x, {1-pow(17/300,\x)});
  \draw[dashed, domain=0.7:1.0] plot (\x, {1-pow(17/300,0.7)});
\end{tikzpicture}
\fi

For example, assuming we choose a quorum $|Q| = 3b+1$ out of $n = 4b+1$,
which is the default setup of the kv quorum system, the detection rate
is 100\% up to $f = 2b$ failure nodes.

\ifdefined\ABSTRACT
\else
\begin{tikzpicture}[xscale=6,yscale=6]
  \draw [<->] (0,1.05) -- (0,0) -- (1.05,0);
  \node [left] at (0,1) {$1$};
  \node [left] at (0,0) {$0$};
  \node [below] at (0.3,0) {$n/3$};
  \node [below] at (0.7,0) {$2n/3$};
  \node [below] at (1,0) {$n$};
  \node [right] at (1.05,0) {$f$};
  \draw[thick, smooth] (0,1) to (0.6,1) to [out=0,in=90] (1,0);
\end{tikzpicture}
\fi


\documentclass[10pt,handout]{beamer}
\setbeamertemplate{navigation symbols}{}
\usefonttheme{serif}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{cite}
\usepackage{color}
\usepackage{setspace}
\usepackage{hyperref}

\newcommand{\xx}{{\bf{x}}}
\begin{document}
\title{Machine Learning I Lecture IV:\\ Bayesics of Inference}
\author{Jakob H Macke\\ Max Planck Institute for Biological Cybernetics\\ Bernstein Center for Computational Neuroscience}
\date{XY.XY.2012}

\frame{\titlepage}

\frame{\frametitle{Plan for today}\tableofcontents}

\section{Bayesian Inference}
\frame{\frametitle{'Bayesian Inference' refers to computation of the posterior distribution over parameters given the data.}
\begin{itemize}
\item Data $\mathcal{D}=\{t_1, t_2, \ldots, t_N\}$ \pause
\item Supervised learning: $\mathcal{D}=\{(x_1,t_1), (x_2,t_2), \ldots, (x_N,t_N)\}$ \pause
\item Likelihood function $P(t|w)$ \hspace{1cm}(parameterized by $w$)\pause
\item $P(D|w)= \prod_{n=1}^N P(t_n|w)$\pause
\item Prior distribution $\pi(w)$\pause
\item Bayes rule: $\mbox{Posterior} \propto \mbox{Likelihood}  \times \mbox{Prior}$
\begin{align}
P(w | D) =\frac{1}{Z} P(D|w) P(w)
\end{align}\pause
\item Probabilities must normalize to $1$:
\begin{align}
Z= P(D)= \int P(D|w) P(w) dw
\end{align}
\end{itemize}

}

%\subsection{Subsection no.1.1  }
%\frame{
%Without title somethink is missing.
%}
\frame[shrink=5]{\frametitle{We can use the posterior distribution to make predictions, decisions or scientific statements.}
\begin{itemize}
\item Predictions: \alert{Predictive distribution}
\begin{align}
P(t^*|x^*, D)= \int_w P(t^*| x^*, w) P(w| D)   dw
\end{align}
\pause
\item Making decisions: Suppose we have calculated $P(t^*|x^*, D)$, and someone asks us to give a guess $\hat t$ of $t^*$. While we could just take the \emph{most likely value} of $t^*$, it really depends on the cost function. Are mistakes in one direction as costly as mistakes in the other direction? For example, what is the cost of a false positive or false negative? Given a \alert{cost function} $C(\hat t, t)$, one can calculate the 'Bayes-optimal' decision from the posterior distribution.
\item \pause Scientific statements: e.g. 'After observing 100 data points, we were 90\% sure that the parameter $\theta$ is between -.1 and .3. Now that we have observed another 200, we are 97\% sure.'

\end{itemize}

}
\frame{\frametitle{In most cases, the posterior distribution can not be calculated exactly, and approximations have to be used.}
\begin{itemize}
\item Ignore prior, maximize likelihood $P(D|w)$: \alert{Maximum likelihood learning}  \pause
\item Only search for mode of posterior (\alert{Maximum a posteriori, MAP}), i.e. $\mbox{argmax}_w P(w |D) $. In practice, maximize log-posterior.\\
\pause
\textcolor{gray}{Q: Why is finding the mode of the posterior so much easier than finding the full posterior?}\\
\pause
\textcolor{gray}{Q: When is MAP a really bad idea?}
\item \pause Use simplified model to approximate posterior: Find parameters of model $q(w,\Phi)$ such that
$q(w) \approx P(w|D)$. \\
\pause
\begin{itemize}
\item Examples: Varational Inference, Expectation Propagation, Laplace Approximation
\item Very often, a Normal approximation is used: $q(w) \approx \mathcal{N}(w|\mu,\Sigma)$.
\end{itemize}
\pause
\item Use MCMC sampling to generate samples from posterior distribution
\end{itemize}

}

\section{Example: Bayesian coin toss}
\frame{\frametitle{Example: Bayesian coin toss}
\begin{itemize}
\item Suppose we have $N$ throws of a coin, $D=\{t_1, t_2, \ldots, t_N\}$
\item We write $T_n= 1$ if the n-th throw was head, and $t_n=0$ if it was tail.
\item \pause One parameter:  $q\in [0, 1]$, the probability of obtaining heads
\item \pause Likelihood of one throw:
\begin{align}
 P(T_n=1|q)&= q\\
 P(T_n=0|q)&= (1-q)
\end{align}
\item Likelihood of data $D$: [on board]
\end{itemize}

}

\frame{\frametitle{We will use a beta distribution as a prior for $q$.}
The shape of the distribution is determined by two parameters.
\centering
\includegraphics[width=10cm]{BetaZoo}
}

\frame{\frametitle{We will use a beta distribution as a prior for $q$.}
\begin{itemize}
\item
Beta distribution:
\begin{align}
\pi(q| \alpha, \alpha_{2})= \frac{1}{Z}q^{\alpha_1-1} (1-q)^{\alpha_{2}-1}
\end{align}
\item \pause Normalizing constant: the 'beta function'
\begin{align}
Z= \int_0^1 q^{\alpha_1-1} (1-q)^{\alpha_{2}-1} dq=: B(\alpha_1, \alpha_{2})
\end{align}
\item \pause Mean and Variance:
\begin{align}
\mbox{E}(q|\alpha_1,\alpha_{2})&= \frac{\alpha_1}{\alpha_1+\alpha_{2}}\\
\mbox{Var}(q|\alpha_1,\alpha_{2})&= \frac{\alpha_1\alpha_{2}}{(\alpha_1+\alpha_{2})^2(\alpha_1+\alpha_{2}+1)}
\end{align}
\item \pause Symmetric case and heuristics:  [on board]
\end{itemize}

}
\frame{\frametitle{Illustration: The posterior gets more peaked as more data is coming in. }

\centering
Data: $D=\{1     1     0     1     1     1     1     1     0\}$

\includegraphics[width=10cm]{BetaPosterior}
}

\frame{\frametitle{The posterior distribution can be calculated in closed form.}

We use $S_n$ to denote the number of heads on the first $n$ trials.
\vspace{.5cm}

 \pause Maximum likelihood estimation:

\vspace{.5cm}

[on board]

\vspace{.5cm}

 \pause Posterior distribution:

\vspace{.5cm}

[on board]

\vspace{.5cm}

\pause We can either take all the data and calculate the posterior at once, or do it sequentially as new data comes in:

\vspace{.5cm}

[on board]
}

\frame[shrink=10]{\frametitle{We can use the posterior distribution for predictions ... }
\vspace{.5cm}
After observing $N$ coin-flips, what is our prediction for the next coin flip?
\begin{align}
P(T^*=1| D)&= \int_0^1 P(T^*=1|q) P(q|D) dq\\
& = \int_0^1 q P(q|D) dq\\
&= \mbox{E}(q|D) \\
&=\frac{\alpha_1+S_N}{(\alpha_1+ S_N)+(\alpha_{2}+N-S_N)}\\
&=\frac{\alpha_1+S_N}{(\alpha_1+\alpha_2+N)}
\end{align}

\pause
\vspace{.5cm}
In our example, $\mbox{E}(q|D)=0.69$, and $\mbox{MLE}=0.78$.

\pause
\vspace{.5cm}
Q: What happens if $N$ gets very large?

\pause
\vspace{.5cm}
Note: This is a bit of a special case-- in general, the predictive distribution is not simply the likelihood evaluated at the mean!!!
}

\frame{\frametitle{... for statistical reasoning .... }
\includegraphics[width=10cm]{BetaPosteriorConfidence}
}

\frame{\frametitle{... and for making decisions. }
Someone offers you the bet that you get 1 euros if you predict the next coin toss correctly, but you have to pay 2 euros if if you are wrong.

Should you take the bet? What should you predict?

\begin{align}
C(t^*,\hat t)=
\begin{cases}
-1 &\mbox{if~} t^*= \hat t\\
2 &\mbox{if~} t^*\neq \hat t\\
\end{cases}
\end{align}

Expected cost:
\begin{align}
E(C)=\sum_{t^*=0}^1 C(t^*,\hat t) P(t^*| D)
\end{align}

\pause
If we predict tail ($t^*=0$):
\begin{align}
E(C)&= P(t^*=1|D) C(0,1)+P(t^*=0|D) C(0,0)  \\
&=0.69 (2)  + 0.31 (-1)= 1.07
\end{align}

\pause
If we predict head ($t^*=1$):
\begin{align}
E(C)=0.69 (-1)  + 0.31 (2)= -0.07;
\end{align}

}

\section{Conjugate priors and the exponential family}

\frame{\frametitle{Why was inference so easy here?}
\begin{itemize}
\item Posterior distribution had a closed form solution. \pause
\item In fact, the posterior had the same functional form as the prior, just different parameters. \pause
\item Parameters of posterior could be calculated by simply adding observations to prior parameters. \pause
\item We used a likelihood from the \alert{exponential family} and its \alert{conjugate prior}. In this case,  Bayesian inference is always easy. \pause
\item For this reason, exponential families and conjugate priors are used extensively in Bayesian modelling, often as 'building blocks' of more complicated models.
\end{itemize}

}

\frame{\frametitle{Inference is easy whenever the likelihood is in the exponential family and the prior is its conjugate.}
\begin{itemize}
\item Exponential family distributions  have the form
\begin{align}
P(\xx|\theta)&= g(\theta) f(\xx) \exp\left(\phi(\theta)^\top S(\xx)\right)
\end{align}

\item \pause The conjugate prior is
\begin{align}
\pi(\theta)&= F(\tau,\nu) g(\theta)^\nu \exp(\phi(\theta)^\top \tau)
\end{align}
\item \pause  Calculating the posterior:
\begin{align}
 [\mbox{on board}]
\end{align}
\end{itemize}

}

\frame{\frametitle{Inference is easy whenever the likelihood is in the exponential family and the prior is its conjugate.}
The posterior given an exponential family likelihood and conjugate prior is
\begin{align}
P(\theta|D)= F(\tau+ \sum_i S(x_i), \nu+N) g(\theta)^{\nu+N} \exp\left(\phi(\theta)^\top(\tau +\sum_i S(x_i)    )\right)
\end{align}
\pause
\begin{itemize}
\item $\phi(\theta)$ is the vector of \alert{natural parameters}
\item $\sum_i S(x_i)$ is the vector of \alert{sufficient statistics}
\item $\tau$ are \alert{pseudo-observations}
\item $\nu$ is the scale of the prior\\
\end{itemize}

\pause
The exponential family includes most common distributions, including the Normal, Exponential, Gamma, Chi-square, Beta, Dirichlet, Bernoulli, Poisson, Wishart and the Inverse Wishart.
}

  \frame{\frametitle{How can we put our coin-example into this framework?}
  [on board]
  }

%\subsection{Lists I}
%\begin{itemize}
%\item Introduction to  \LaTeX
%\item Course 2
%\item Termpapers and presentations with \LaTeX
%\item Beamer class
%\end{itemize}

%\frame{\frametitle{lists with pause}
%\begin{itemize}
%\item Introduction to  \LaTeX \pause
%\item Course 2 \pause
%\item Termpapers and presentations with \LaTeX \pause
%\item Beamer class
%\end{itemize}
%}

%\subsection{Lists II}
%\frame{\frametitle{numbered lists}
%\begin{enumerate}
%\item Introduction to  \LaTeX
%\item Course 2
%\item Termpapers and presentations with \LaTeX
%\item Beamer class
%\end{enumerate}
%}
%\frame{\frametitle{numbered lists with pause}
%\begin{enumerate}
%\item Introduction to  \LaTeX \pause
%\item Course 2 \pause
%\item Termpapers and presentations with \LaTeX \pause
%\item Beamer class
%\end{enumerate}
%}

%\section{The Normal distribution}
%\subsection{Tables}
%\frame{\frametitle{Next week}

%Gaussians

%\vspace{1cm}
%Gaussians

%\vspace{1cm}
%Linear Regression

%}

%\frame{\frametitle{The multivariate Gaussian}
%}
%\begin{tabular}{|c|c|c|}
%\hline
%\textbf{Date} & \textbf{Instructor} & \textbf{Title} \\
%\hline
%WS 04/05 & Sascha Frank & First steps with  \LaTeX  \\
%\hline
%SS 05 & Sascha Frank & \LaTeX \ Course serial \\
%\hline
%\end{tabular}}
%}

%\frame{\frametitle{Tables}
%}
%\frame{\frametitle{Tables with pause}
%\begin{tabular}{c c c}
%A & B & C \\
%\pause
%1 & 2 & 3 \\
%\pause
%A & B & C \\
%\end{tabular} }

%\section{Section no. 4}
%\subsection{blocs}
%\frame{\frametitle{blocs}

%\begin{block}{title of the bloc}
%bloc text
%\end{block}

%\begin{exampleblock}{title of the bloc}
%bloc text
%\end{exampleblock}

%\begin{alertblock}{title of the bloc}
%bloc text
%\end{alertblock}
%}
\end{document}


\section*{Problem 1: Logarithmic Regret of UCB}

We will consider the multi-armed bandit setting discussed in class, where the
actions $a \in \{1,\cdots,K\}$, $\mu_a$ is the mean reward provided by arm $a$,
and $X_t$ is reward observed at time $t$ if we pull arm $a$. As in class, we
assume that the observed rewards are bounded a $0 \leq X_t \leq 1$ almost
surely.

Recall $\mu_* = \max_a\mu_a$, and let $a_*$ be the index of an optimal
arm. Define $\Delta_a$ as:
\begin{equation}
  \Delta_a = \mu_* - \mu_a
\end{equation}
and define:
\begin{equation}
  \Delta_{\min} = \min_{a \neq a_*} \Delta_a.
  \label{eqn:1_delta_min}
\end{equation}

In this problem, we seek to prove the following theorem:

\begin{theorem}
  The UCB algorithm (with an appropriate setting of the parameters) has a regret
  bound that is:
  \begin{equation}
    T\mu_* - \mathbb{E}\left[
      \sum_{t \leq T} X_t
    \right] \leq c \frac{K\log T}{\Delta_{\min}},
    \label{eqn:1_result}
  \end{equation}
  where $c$ is a universal constant.
\end{theorem}

\subsection*{Let's prove this!}

Let $N_{a,t}$ be the number of times we pulled arm $a$ up to time $t$. Recall
from class that by Hoeffding's bound (and the union bound), we can provide a
confidence bound for an arbitrary algogrithm as follows: with probability
greater than $1 - \delta$, we have that fo all arms and for all time steps $K
\leq t \leq T$:
\begin{equation}
  \mathbb{P}\left(\forall t, a, \left\lvert
      \hat{\mu}_{a,t} - \mu_a
    \right\rvert
    \leq  c_2 \sqrt{\frac{\log\left(T/\delta\right)}{N_{a,t}}}
  \right) \geq 1 - \delta,
  \label{eqn:1_confidence_interval}
\end{equation}
where $c_2$ is some universal constant. Note that the algorithm starts the first
$K$ steps by sampling each arm once, so we can assume $t \geq K$.

\begin{enumerate}
\item Now consider the UCB algorithm using this confidence interval. Argue that
  with probability greater thatn $1 - \delta$, the total number of times that an
  sub-optimal arm $a$ will be pulled up to time $T$ will be bounded as follows:
  \begin{equation}
    N_{a,T} \leq c_3 \frac{\log\left(T/\delta\right)}{\Delta_a^2}
    \label{eqn:1_N_at_bound}
  \end{equation}
  for some constant $c_3$.

  \subsubsection*{Solution}

  \begin{proof}
    This bound follows from Equation \ref{eqn:1_confidence_interval}. Then, for
    any $a$ and $t \in [K, T]$ with probability greater than $1 - \delta$, we
    have that
    \begin{align*}
      \left\lvert \hat{\mu}_{a,t} - \mu_a \right\rvert
      &\leq  c_2 \sqrt{\frac{\log\left(T/\delta\right)}{N_{a,t}}} \\
      \sqrt{N_{a,t}}
      &\leq c_2\frac{
        \sqrt{\log\left(T/\delta\right)}
        }{\left\lvert \hat{\mu}_{a,t} - \mu_a \right\rvert} \\
      N_{a,t}
      &\leq c_2^2 \frac{\log\left(T/\delta\right)}{
        \left(\hat{\mu}_{a,t} - \mu_a \right)^2}.
    \end{align*}
    If we let $c_3 = c_2^2$, substitute
    $\Delta_a^2 = \left(\hat{\mu}_{a,t} - \mu_a \right)^2$, and fix $t = T$, we
    have Equation \ref{eqn:1_N_at_bound} with probability greater than
    $1 - \delta$ as desired.
  \end{proof}
\item Argue that the observed regret of UCB is bounded as follows: with
  probability greater than $1 - \delta$, we have that:
  \begin{equation}
    T\mu_* - \sum_{t \leq T} \mu_{at} \leq c_3 \sum_{a \neq a_*}\frac{\log\left(T/\delta\right)}{\Delta_a},
    \label{eqn:1_2_result}
  \end{equation}
  where $a_t$ is the arm chosen by the algorithm at time $t$.

  \subsubsection*{Solution}

  \begin{proof}
    Equation \ref{eqn:1_2_result} follows from Equation \ref{eqn:1_N_at_bound},
    noting that $\sum_{a = 1}^K N_{a,T} = T$, and seeing that
    $\Delta_{a_*} = \mu_* - \mu_{a_*} = 0$

    We have that
    \begin{align*}
      T\mu_* - \sum_{t \leq T} \mu_{a_t}
      &= \sum_{a = 1}^K N_{a,T}\left(\mu_* - \mu_a\right)
p      \\
      &= \sum_{a = 1}^K \Delta_{a}N_{a,T} \\
      &= \sum_{a \neq a_*} \Delta_{a}N_{a,T} \\
      &\leq \sum_{a \neq a_*} \Delta_{a}\left(c_3\frac{\log\left(T/\delta\right)}{\Delta_{a}^2}\right) \\
      &= \sum_{a \neq a_*} c_3\frac{\log\left(T/\delta\right)}{\Delta_{a}},
    \end{align*}
    which gives Equation \ref{eqn:1_2_result} with probability $1 - \delta$ as
    desired.
  \end{proof}
\item Now show that the expected regret of UCB is bounded as:
  \begin{equation}
    T\mu_* - \mathbb{E}\left[\sum_{t \leq T} X_t\right] \leq
    c_4 \sum_{a \neq a_*} \frac{\log\left(T\right)}{\Delta_a}.
    \label{eqn:1_3_result}
  \end{equation}
  \subsubsection*{Solution}
  \begin{proof}
    Fix $\delta = 1/T^2$ as in the proof of Lemma 3.1 from the lecture notes.

    We have that
    \begin{align*}
      \mathbb{E}\left[\sum_{t \leq T} \left(\mu_* - X_t\right)\right]
      &=
        T\mu_* - \mathbb{E}\left[\sum_{t \leq T} X_t\right]
        = T\mu_* - \sum_{t \leq T} \mu_{a_t} \\
      &\leq \left(1 - \delta\right)c_3\sum_{a \neq a_*}\frac{\log\left(T/\delta\right)}{\Delta_{a}}
        + \delta T \\
      &= \left(1 - \frac{1}{T^2}\right)c_3\sum_{a \neq a_*}\frac{\log\left(T\right) + 2\log\left(T\right)}{\Delta_{a}}
        + \frac{1}{T} \\
      &= 3c_3 \sum_{a \neq a_*} \frac{\log\left(T\right)}{\Delta_{a}} - \frac{3c_3}{T^2} \sum_{a \neq a_*} \frac{\log\left(T\right)}{\Delta_{a}} + \frac{1}{T} \\
      &= O\left(\sum_{a \neq a_*} \frac{\log\left(T\right)}{\Delta_{a}}\right)
    \end{align*}
    asymptotically since the other terms decay with $T$. Thus, it follows that
    there exists some $c_4$ such that
    \begin{equation*}
      T\mu_* - \mathbb{E}\left[\sum_{t \leq T} X_t\right]
      \leq c_4\sum_{a \neq a_*} \frac{\log\left(T\right)}{\Delta_{a}}.
    \end{equation*}
  \end{proof}
\item Now argue that the theorem follows and specify what the UCB algorithm is
  (with parameters set appropriately).
  \subsubsection*{Solution}
  \begin{proof}
    Applying Equation \ref{eqn:1_delta_min} to Equation \ref{eqn:1_3_result}, we have that
    \begin{align*}
      T\mu_* - \mathbb{E}\left[\sum_{t \leq T} X_t\right]
      &\leq
        c_4 \sum_{a \neq a_*} \frac{\log\left(T\right)}{\Delta_a} \\
      &\leq
        c_4 \sum_{a \neq a_*} \frac{\log\left(T\right)}{\Delta_{\min}} \\
      &\leq c_4 K\frac{\log\left(T\right)}{\Delta_{\min}},
    \end{align*}
    which gives us Equation \ref{eqn:1_result} if we define $c = c_4$.
  \end{proof}

  Thus, we have the following UCB algorithm.
  \begin{enumerate}[label=(\arabic*)]
  \item Try each of the $K$ arms once.
  \item Fix $t$. Calculate \begin{equation} U_{a,t} = \hat{\mu}_{a,t} +
      c_2\sqrt{3\frac{\log{T}}{N_{a,t}}}
      \label{eqn:1_4_upper_bound}
    \end{equation}
    for all $a = 1,2,\ldots,K$. Pull arm $a_{*}^{(t)} = \argmax_a U_{a,t}$.
    \label{alg:1_4_explore}
  \item Repeat Step \ref{alg:1_4_explore} $T$ times.
  \end{enumerate}
\end{enumerate}


\subsubsection{One Dimensional Permeable Porous Medium Radionuclide Mass Balance
Model}\label{sec:one_dim_ppm}

The advection dispersion equation is at the core of contaminant transport. A
description of advection and dispersion appears in the following section on
mass transfer. For now, it is sufficient to note that various solutions to the advection dispersion equation
\eqref{unidirflow} have been published for both the first and third types of
boundary conditions. The third, Cauchy type, is more mass conservative, and is
the primary kind of boundary condition used at the source for the model
implementation in \Cyder.
Abstraction results informed modifications to the implementation of an
analytic solution to the one dimensional advection-dispersion equation with
a finite domain and Cauchy and Neumann boundary conditions at the inner and outer
boundaries, respectively.

The conceptual model in Figure \ref{fig:1dinf} represents solute transport in
one dimension with unidirectional flow upward and a
finite boundary condition in the positive flow direction.
Notably, unidirectional vertical flow upward in the far field simplifies a
3-dimensional problem into one dimenstion. The vertical direction was chosen to
be conservative, since the shortest path to the biosphere is the vertical, $z$, direction.
In \Cyclus, radioactive decay is handled external to the components, so there is
no need to include production or decay.  An approximate solution for these conditions
made by Brenner \cite{brenner_diffusion_1962} is described below as
it is given in van Genuchten et. al, \cite{van_genuchten_analytical_1982},

\FloatBarrier
\vspace{4mm}

\begin{figure}[h!]
  \begin{center}
    \def\svgwidth{0.7\columnwidth}
    \input{./nuclide_models/mass_balance/one_dim_ppm/1dfin.eps_tex}
  \end{center}
  \caption[1D finite advection dispersion solution.]{A one-dimensional,
        finite, unidirectional flow solution with Cauchy $(z=0)$ and Neumann
        $(z=L)$ boundary
        conditions.}
  \label{fig:1dinf}
\end{figure}

For the Cauchy boundary condition,
\begin{align}
  -D \frac{\partial C}{\partial z}\big|_{z=0} + v_zc &= \begin{cases}
    v_zC_0  &  \left( 0<t<t_0 \right)\\
    0  &  \left( t>t_0 \right)\\
  \end{cases}
\intertext{where}
      D &= \mbox{ Effective Dispersion Coefficient }[m^2/s]\\
      v &= \mbox{ Fluid Velocity in the medium }[m/s]
\intertext{the Neumann boundary condition,}
  \frac{\partial C}{\partial z}\big|_{z=L} &= 0
  \intertext{and the initial condition,}
  C(z,0) &= C_i,
  \label{1dinfBC}
\end{align}
\begin{align}
  \intertext{the solution is given as }
  C(z,t) &= \begin{cases}
  C_i + \left(C_0 - C_i\right)A\left(z,t\right) & 0<t\le t_0\\
  C_i + \left(C_0 - C_i\right)A\left(z,t\right) - C_0A(z,t-t_0) & t\ge t_0.
  \end{cases}
\end{align}

For the vertical flow coordinate system, $A$ is defined as
\begin{align}
A(z,t) =& \left(\frac{1}{2}\right)\erfc{\left[\frac{Rz-vt}{2\sqrt{DRt}}\right]} \nonumber\\
&+ \left(\frac{v^2t}{\pi RD}\right)^{1/2}\exp{\left[-\frac{(Rz-vt)^2}{4DRt}\right]}\nonumber\\
&- \frac{1}{2} \left(1+\frac{vz}{D} + \frac{v^2t}{DR}\right) \exp{\left[\frac{vz}{D}\right]}\erfc{\left[\frac{Rz+vt}{2\sqrt{DRt}}\right]}\nonumber\\
&+ \left(\frac{4v^2t}{\pi RD}\right)^{1/2}\left[1+\frac{v}{4D}\left(2L-z+\frac{vt}{R}\right)\right]\exp{\left[\frac{vL}{D} - \frac{R}{4Dt}\left(2L-z+\frac{vt}{R}\right)^2\right]}\nonumber\\
&- \frac{v}{D}\left[2L - z + \frac{3vt}{2R} + \frac{v}{4D}\left(2L - z + \frac{vt}{R}\right)^2\right]\exp{\left[\frac{vL}{D}\right]}\erfc{\left[\frac{R(2L-z) + vt}{2\sqrt{DRt}}\right]}
\label{simple_genuchten}
\intertext{where}
L =& \mbox{Extent of the solution domain }[m]\nonumber\\
R =& \mbox{Retardation factor }[-].\nonumber
\end{align}


\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage[margin=0.75in]{geometry}
\usepackage[numbers]{natbib}
\usepackage{physics}
\usepackage{xcolor}
\usepackage{cancel}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{Creative Destruction Lab}
\lhead{Week 2: Optimization problems \& Rydberg atom arrays}
\rfoot{Page \thepage}

\usepackage{graphicx}

\usepackage[hidelinks]{hyperref}

\renewcommand{\phi}{\varphi}

\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}

\title{Week 2: Optimization problems \& Rydberg atom arrays}
\author{}
\date{}

\begin{document}

\maketitle

\thispagestyle{empty}

\section*{Introduction}

Last week, you were able to simulate elements of the seminal work produced from Google's Sycamore quantum computer on your own (classical) laptops.
However, given that you are in the CDL stream, you are probably wondering how one might be able to demonstrate a quantum advantage in a ``real-world'' setting, such as optimization problems, instead of the simulatability of an ``unusual'' probability distribution (the Porter-Thomas distribution).

Superconducting-qubit (Sycamore) and trapped-ion devices are considered top contenders for scalable quantum computers, due to their long coherence times and
high gate fidelities.  However, recently neutral-atom quantum computers are also proving to be competitive due to the ease of control of a large number of programmable
qubits~\cite{serret_solving_2020,bernien_probing_2017,ebadi_quantum_2020,henriet_quantum_2020,Browaeys2020}.
%Logically, if we have access to larger quantum computers, we can foreseeably demonstrate a quantum advantage for this very reason.
Given the immense scaling solutions required for today's largest data-driven problems (e.g. supply chain management), it seems
likely that neutral-atom quantum computers could be close close to demonstrating a quantum advantage for today's real problems.

The foundation of today's neutral-atom quantum computers is comprised of Rydberg atoms~\cite{Browaeys2020}.
Briefly, Rydberg atoms are highly-excited atoms (e.g. rubidium) that interact with each other on the scale of a few micrometres.
A controlled laser pulse can excite an atom into a quantum state with a large principal quantum number (i.e. a Rydberg state) that is quasi-stable.
The binary nature of a Rydberg atom's ground and excited states is analogous to the state of a qubit.
Besides ease of control and scalability, the value of Rydberg atoms in the context of solving real-world problems is in the way that Rydberg atoms interact with each other.
Their interactions map trivially to a well-known mathematical problem called the Unit-Disk Maximum Independent Set (UD-MIS) problem, which is NP-hard\footnote{Problems that are NP-hard are not solvable in polynomial time, but trial solutions can be verified to be correct or not in polynomial time.}.

A host of today's real-world problems are classified as NP-hard, and it turns out that NP-hard problems can be translated into other NP-hard problems with some negligible overhead.
So, we can map a lot of real-world problems to the building blocks of quantum computers!
This is precisely what you will be investigating this week: exploring the UD-MIS problem as it pertains to Rydberg atoms, and mapping it to a real-life NP-hard problem.
First, let's look at some of the relevant math so that you can do your tasks!

\subsection*{Modelling Rydberg atoms}

Rydberg atoms need to be placed at a physical location.
We will strictly look at Rydberg atoms on a {\it graph} $G$ with vertices (physical Rydberg atom locations) and edges $V$ and $E$, respectively.
With this, we will look at a Rydberg Hamiltonian of the form
\begin{equation} \label{eq:rydberg_hamiltonian_Omega=0}
	\hat{H} = -\sum_{i \in V} \hat{n}_i + \sum_{ i < j } \left( \frac{R_b}{r_{ij}} \right)^6 \hat{n}_i \hat{n}_j,
\end{equation}
where $\hat{n}_i = 1/2 \left( I - \hat{\sigma}_i^z \right) = \ketbra{1}{1}_i$ is called an {\it occupation operator}, $R_b$ is a parameter called the {\it blockade radius}, and $r_{ij}$ is the distance between Rydberg atoms located at vertices $i$ and $j$.
The computational basis we will be working in is the occupation basis: the eigenstates of $\hat{n}_i$,
\begin{subequations} \label{eq:occupation_basis}
    \begin{align}
        \hat{n}_i \ket{0}_j =& 0 \qquad (\text{$\forall$ $i,j$}), \\
        \intertext{and}
        \hat{n}_i \ket{1}_j =& \delta_{i,j}\ket{1}_j,
    \end{align}
\end{subequations}
where the state $\ket{0}$ ($\ket{1}$) represents the ground (excited) state of a Rydberg atom.

On observing the form of the Hamiltonian in Eq.~\ref{eq:rydberg_hamiltonian_Omega=0}, we can see that the first term (sum over $V$) favours all sites being occupied, while the interaction term penalizes occupied pairs.
It is precisely this dichotomy that leads us to our next section.

\subsection*{Rydberg atoms and the UD-MIS problem}

The MIS problem\footnote{Not UD-MIS!} is defined as follows \cite{serret_solving_2020}: \\

\begin{changemargin}{1.5cm}{1.5cm}
	\noindent Let $G = (V,E)$ be a graph with a set of vertices $V$ and edges $E$, $N = |V|$, and $S = (n_1, \dotsb, n_N)$ be an $N$-bit string (i.e. $n_i \in 0,1$) with Hamming weight $|S| = \sum_{i = 1}^N n_i$.
	The MIS problem is defined as finding
	\begin{align*}
		\max_{S \in \mathcal{B}} & |S|,
	\end{align*}
	subject to the constraint that $S$ is an independent set.
	Here, $\mathcal{B}$ is the set of all possible $N$-bit strings, and an independent set is defined as a set with mutually non-connected vertices: $n_i = n_j = 1 \Rightarrow (i,j) \cancel{\in} E$. \\
\end{changemargin}

Solving this problem consists of finding the largest possible independent set and returning an instance of it.
With the additional unit-disk constraint, all vertices of the given graph share an edge except those that are separated by a distance greater than 1.
An example of an independent set on a unit-disk graph is shown in Fig.~\ref{fig:udmis_example}.

\begin{figure}
    \begin{center}
        \includegraphics[width=0.4\linewidth]{images/udmis_example.png}
    \end{center}
    \caption{An example of a unit-disk graph $G$ with an instance of the corresponding solution to its UD-MIS problem. Here, blue lines indicate graph edges $E$, and dots represent vertices $V$ wherein the shaded regions represent unit-radii disks. The red dots correspond to a maximum independent set.} \label{fig:udmis_example}
\end{figure}

The ground state of the Hamiltonian
\begin{equation} \label{eq:UDMIS_hamiltonian}
	\hat{H} = -\sum_{i \in V} \hat{n}_i + u \sum_{i,j \in E} \hat{n}_i \hat{n}_j
\end{equation}
is precisely the solution to the UD-MIS problem on a graph $G$\footnote{So long as $u > 1$ \cite{serret_solving_2020}. You will use $u = 1.35$ for all of your tasks.}.
This is eerily similar to Eq.~\ref{eq:rydberg_hamiltonian_Omega=0}, with the difference being in the coefficients in front of the interaction terms.
However, to a very good approximation, it's ``similar enough''.
So, essentially, finding the ground state of a bunch of Rydberg atoms on the same graph $G$ will (approximately) solve the UD-MIS problem.

In all of your tasks, we will be modelling Eq.~\ref{eq:UDMIS_hamiltonian} for simplicity.
However, let's just take a moment to appreciate how having a physical neutral-atom quantum computer makes solving the UD-MIS problem so simple.
We could just place the Rydberg atoms at the desired vertex locations, and measure their Rydberg occupation! Pretty easy\footnote{Obviously, a lot more goes into it. These experiments are highly non-trivial affairs... No free lunch!}!

\subsection*{Task 1: Simulated Classical Annealing}

Let's first try and solve the UD-MIS problem classically.
You'll notice that the Hamiltonian in Eq.~\ref{eq:UDMIS_hamiltonian} is diagonal in the Rydberg occupation basis (Eq.~\ref{eq:occupation_basis}).
So, we can use classical Monte Carlo methods (namely the Metropolis-Hastings algorithm) to simulate this Hamiltonian at finite temperatures.
But, we're interested in the {\it ground} state, not some high-temperature state.
That being said, so long as we can simulate the Hamiltonian at a low enough temperature, it should be fine.

In this directory, you will find a Jupyter notebook titled \texttt{Task1.ipynb}.
Here, there's all the code you will need to solve the UD-MIS problem via classical {\it simulated annealing}: performing Monte Carlo simulations at lower and lower temperatures to hopefully simulate the ground (zero-temperature) state.
The {\it annealing schedule} is the manner in which the temperature is decreased.
We've provided an annealing schedule for you, but {\bf try other annealing schedules to see if you can get a solution to the UD-MIS problem faster (less steps)}.

\subsection*{Task 2: Quantum Annealing}

Let's now try solving the UD-MIS problem quantum-ly.
We will employ a quantum annealing (QA)-based approach.
Briefly, the goal of QA is to start in an easily-preparable ground state of a Hamiltonian and time evolve this state with a time-dependent Hamiltonian.
At the end of the time evolution process, the Hamiltonian should be such that its ground state is what we are after.
Consider the time-dependent Hamiltonian
\begin{equation} \label{eq:time_dep_hamiltonian}
	\hat{H}(t) = \Omega(t) \sum_{i \in V} \hat{\sigma}_i^x - \delta(t) \sum_{i \in V} \hat{n}_i + u \sum_{i,j \in E} \hat{n}_i \hat{n}_j.
\end{equation}
Notice that if $\Omega(t = 0) = \delta(t = 0) = 0$, the ground state of this Hamiltonian is every Rydberg atom in its ground state: $\ket{0}^{\bigotimes N}$.
If $\Omega(t = t_{\text{final}}) = 0$ and $\delta(t = t_{\text{final}}) = 1$, we have Eq.~\ref{eq:UDMIS_hamiltonian}.
Time-evolving the initial state $\ket{0}^{\bigotimes N}$ with the Hamiltonian in Eq.~\ref{eq:time_dep_hamiltonian} by manually choosing how to vary $\Omega(t)$ and $\delta(t)$ will hopefully give us the ground state of the UD-MIS Hamiltonian (Eq.~\ref{eq:UDMIS_hamiltonian}).
In a nutshell, this is the QA process as it pertains to our problem.

Mathematically and algorithmically, QA looks like the following
\begin{align*}
	\ket{\psi(t)} =& U(t) U(t - \delta t) \cdots U(t_0 + \delta t) U(t_0) \ket{\psi (t = t_0)},
\end{align*}
where $U(t)$ is the time-evolution operator
\begin{align*}
	U(t) =& \exp(-\frac{i}{\hbar} \delta t \hat{H}(t)),
\end{align*}
$\hat{H}(t)$ is given in Eq.~\ref{eq:time_dep_hamiltonian}, and $\delta t$ is a user-defined increment of time that defines the number of subdivisions in the time interval $t \in [t_0, t_f]$.
We will implement this on a quantum circuit simulator package in the \texttt{Julia} programming language called \texttt{Yao.jl} \cite{luo_yaojl_2020}\footnote{Created by our very own Roger Luo!}.
Everything you need is in \texttt{run\_quantum\_annealing.jl}.
We have taken inspiration from Ref.~\cite{serret_solving_2020} for the annealing schedule (see Fig. 2 in this work).
The very last line in \texttt{run\_quantum\_annealing.jl} draws samples from the resulting wavefunction $\ket{\psi(t)}$ that has been time-evolved.
{\bf Plot the samples on the graph coordinates given in the code and verify that indeed the UD-MIS problem has been solved.}

The resulting time-evolved wavefunction may not \textit{perfectly} be the ground state (i.e. when you sample it, you might get configurations that aren't the solution we desire).
Sample the resulting wavefunction several thousand times, and look for the most common bit string.
Use this as your solution\footnote{You might need to run the code a few different times!}.

\subsection*{Task 3: A Real Problem}

The City of Gotham is looking at putting in new cell phone towers.
The possible locations of the cell phone towers are given in Fig.~\ref{fig:gotham}.
The billionaire Bruce Wayne is funding the project and he loves his money.
Therefore, Gotham should only purchase the required number of cell phone towers such that 1) the cell phone tower signal ranges do not overlap\footnote{Yes, this means some areas of Gotham City won't have cell phone service... ``Too bad,'' said Bruce.}, and 2) as much of Gotham City can be within cell signal range.

The possible Gotham City cell phone tower locations are\footnote{All coordinates are normalized to the cell phone tower signal range.}:
\begin{enumerate}
	\item (1.19, 4.25)
	\item (2.71, 3.48)
	\item (1.19, 3.51)
	\item (2, 3.38)
	\item (1.12, 2.86)
	\item (1.70, 2.42)
	\item (2.36, 2.54)
	\item (1.52, 1.48)
	\item (2.15, 1.54)
	\item (2.14, 1.87)
	\item (1.72, 0.86)
	\item (2.29, 0.87)
\end{enumerate}

\begin{enumerate}
	\item {\bf Explain why this is a problem that can be easily mapped to the UD-MIS problem.} A few sentences is all that is needed.
	\item {\bf Solve Gotham City's problem.} Using the methods provided in Tasks 1 and 2 \textbf{Are there multiple solutions}?
	\item {\bf Should Bruce pay for a few more cell phone towers to make sure that more of Gotham City has cell phone service?}
\end{enumerate}

\begin{figure}
    \begin{center}
        \includegraphics[width=0.4\linewidth]{images/gothamcity.png}
    \end{center}
    \caption{Possible cell phone tower locations in Gotham City.} \label{fig:gotham}
\end{figure}

\section*{Additional Challenges}

\begin{itemize}
	\item Compare / benchmark the methods outlined in the Task 1 and 2 codes.You will probably want to make larger graphs to push both of these algorithms to the test. Which method is better (i.e. faster, more efficient)?
	\item Benchmark other classical and quantum optimization methods to solve your UD-MIS problems.
	\item Solve another real-world problem that can be mapped to the UD-MIS problem.
	\item Perform any of the tasks with real quantum hardware.

\end{itemize}

\bibliography{refs}
\bibliographystyle{unsrturl}

\end{document}


\chapter{Reliability Analysis}
\chaptermark{Reliability}

We will define reliability analysis to be the analysis of the \emph{time} to \emph{failure}.
We will also assume that ``time'' and ``failure'' are well defined and agreed upon.

We intuitively understand ``more reliable'' to mean ``lasts longer''.
We should also consider, however, the case of a product that is designed to fail after some time, thus forcing the consumer to buy a new one.
Some may say that a major hi-tech company named after a fruit employs this practice, which is known as \emph{planned obsolescence}\footnote{\url{https://en.wikipedia.org/wiki/Planned_obsolescence}.}
Be it true or not, I hope we can agree that good knowledge of your product's life expectancy is a desirable.

By ``product'' we clearly imply a production problem, but our methods equally apply to other problems where we analyse the distribution of times-to-events.
\begin{description}
	\item[Services] The analysis of time-to-service in service queues.
	\item[Marketing] The analysis of time-to-adoption/abandon in marketing.
	\item[Sotware reliability] The analysis of time-to-bug in software reliability.
	\item[Actuary] The analysis of time-to-death in actuary sciences (insurance).
	\item[Pharmaceutics] The analysis of time-to-effect in pharmaceutics.
	\item[Epidemiology] The analysis of time-to-infection/recovery in epidemiology and biostatistics.
\end{description}

Reliability analysis involves the study of a probabilistic property of our product- its \emph{survival}.
Any probabilistic model will require calibration to reality via data.
This chapter thus introduces both the probability calculus typically used for reliability analysis, and then some statistical considerations involved when calibrating these models.

\section{Probabilistic Analysis}

\subsection{A Static View}

Let $\x_j \in \set{0,1}, j=1,\dots,p$ denote the state of the $j$'th component of a system, and $x=(x_1,\dots,x_p)$.

\begin{definition}[Structure Function]
The \emph{structure function}, $\struct=\struct(x):x \mapsto \set{0,1}$, is an indicator function of the state of the system. A failure indicated by $0$.
\end{definition}

\begin{remark}[$\Phi$]
We apologize to the reader for using $\Phi$ to denote both the $\gauss{0,1}$ CDF, and the structure function.
We do so to stay in accordance with reliability literature, and since no collisions are created in this chapter by doing so.
\end{remark}

\begin{definition}[Series System]
A \emph{series system}, or \emph{serial system}, is one where all components need to function for the system to function: $$\struct(x)=\prod_{j=1}^{p}x_j.$$
\end{definition}
A reliability diagram of a series system is given in Figure~\ref{fig:series_system}.
\begin{figure}[ht]
\centering
\includegraphics[width=0.5\linewidth]{art/series_system}
\caption{Series system.}
\label{fig:series_system}
\end{figure}

\begin{definition}[Parallel System]
A \emph{parallel system} is one where all components need to fail for the system to fail:
$$\struct(x)=1-\prod_{j=1}^{p} (1-x_j)= \coprod_{j=1}^p x_j.$$
\end{definition}
A reliability diagram of a parallel system is given in Figure~\ref{fig:parallel_system}.
\begin{figure}[ht]
\centering
\includegraphics[width=0.5\linewidth]{art/parallel_system}
\caption{Parallel system.}
\label{fig:parallel_system}
\end{figure}

\begin{definition}[k-out-of-p System]
A \emph{k-out-of-p} system is one where at least $k$ components need to function for the system to function:
$$\struct(x)=\indicator{\sum_{j=1}^{p} x_j \geq k}.$$
\end{definition}

\begin{think}
	A reliability diagram of a k-out-of-p system is not provided, since it is not very friendly. Try thinking of a 2-out-of-3 system to see why.
\end{think}

\begin{definition}[Monotone System]
A system is said to be \emph{monotone} if $\struct(x_1,\dots,x_p)$ is non decreasing in all components.
\end{definition}
The definition of monotonicity captures the idea that you cannot improve a system's state by breaking components.
This seems rather natural (I am still looking for a counter example).

\begin{think}
	Think how the structure function of a non monotone system would look.
\end{think}

\begin{definition}[Reliability]
We define the \emph{reliabity of component $j$} to be $$p_j:= P(\x_j=1),$$
and  the \emph{reliability of the system}
$$ S_\struct = S_{\struct(x)}:=P(\struct(x)=1).$$
\end{definition}

\begin{example}[Reliability of a series system]
For $\Phi(x)$ a series system, assuming independent components, we have
$$ S_\struct= \prod_{j=1}^{p} p_j.$$
\end{example}

\begin{example}[Reliability of a parallel system]
For $\Phi(x)$ a parallel system, assuming independent components, we have
$$ S_\struct= 1-\prod_{j=1}^{p} (1-p_j)= \coprod_{j=1}^p p_j. $$
\end{example}

\begin{example}[Reliability of a k-out-of-p system]
For $\Phi(x)$ a k-out-of-p system, assuming independent components with equal reliability ($p_i=p_0$), we have
$$ S_\struct= \sum_{i=k}^{p} \binom{p}{i} p_0^i (1-p_0)^{p-i} .$$
\end{example}

\subsubsection{State enumeration method}
To compute the reliability of more complex structures, the brute-force approach is the \emph{state enumeration method}.
This method simply relies on summation of the probabilities of the states for which the system functions.
$$ S_\struct= \sum_{x} \Phi(x) P(\x=x).$$

\subsubsection{Factoring method}
The \emph{factoring method}, \aka \emph{pivot-decomposition method}, relies on two ingredients:
(a) conditioning on the state of some components greatly simplifies the structure, and
(b) the total probability argument.
Combining the two we have:
$$ S_\struct= p_j  S_{\struct|x_j=1} + (1-p_j) S_{\struct|x_j=0}   ,$$
where $S_{\struct|x_j=1}$ denotes the reliability of the structure $\Phi$ conditional on $x_j=1$.
The following example demonstrates the power of the factoring method.

\begin{example}[Bridge Structure]
\label{eg:bridge}
Consider structure in Figure~\ref{fig:bridge}.
To compute the reliability, we will call upon the factoring method while conditioning on the state of component $3$:
$$ S_\struct= p_3  S_{\struct|x_3=1} + (1-p_3) S_{\struct|x_3=0}   .$$
Now note that when $x_3=1$ then we have a series structure of parallel structures, while when $x_3=0$ we have a parallel structure of series structures.:
\begin{align*}
	S_{\struct|x_3=1} &= (p_1 \coprod p_2) (p_4 \coprod p_5),\\
	S_{\struct|x_3=0} &=  p_1 p_4 \coprod p_2 p_5,
\end{align*}
so that
$$
	S_\struct = p_3  (p_1 \coprod p_2) (p_4 \coprod p_5) + (1-p_3) (p_1 p_4 \coprod p_2 p_5).
$$
\begin{figure}[ht]
\centering
\includegraphics[width=0.5\linewidth]{art/bridge}
\caption[Bridge Structure]{Structure of a bridge system. Source: \cite[Fig.2.5]{aven_stochastic_1999}}
\label{fig:bridge}
\end{figure}
\end{example}
Example~\ref{eg:bridge} demonstrates a single application of the factoring method. Clearly, it can be applied recursively for more complicated systems.

The example also demonstrates a more general principle. Namely, that redundancy is preferable at the component level, and not at the system's level.
Put differently- when designing a backup, and the resources allow a fill copy of the original system, we are better of by designing a component-wise backup, than a single backup system.
Put formally:
\begin{theorem}[Component-wise redundancy]
For a monotone structure $\Phi$,
\begin{align}
	S_{\struct(x \coprod y)} \geq S_{\struct(x)} \coprod S_{\struct(y)}
\end{align}
where $x \coprod y$ denotes a component-wise backup: $(x_1 \coprod y_1,\dots,x_p \coprod y_p)$.
\end{theorem}

\begin{extra}[Reliability analysis of complex systems]
Except for simple systems, of the type we presented, the computation of the reliability of a complex system may be a formidable task.
For complicated real-life systems, \emph{min-cut--max-flow} algorithms, or \emph{inclusion-exclusion} type algorithms are employed.
For more details, see \cite{aven_stochastic_1999}.
\end{extra}

\subsubsection{Reliability Importance Measures}
\begin{quotation}
The Strength Of The Chain Is In The Weakest Link.
\end{quotation}
This is obviously a profound observation in reliability analysis.
In order to identify the weakest link we require some measure of reliability importance.

\begin{definition}[Improvement potential]
The \emph{improvement potential} is defined as the change in a system's reliability, if we could force a component to function indefinitely.
Formally, we denote $\Phi^{(j)}$ to be a system where component $j$ cannot fail: $\Phi^{(j)}:=\Phi_{(p_j=1)}$.
We then define the improvement potential with respect to component $j$ to be
\begin{align}
	I_j :=S_{\Phi^{(j)}}-S_{\Phi}.
\end{align}
\end{definition}

\begin{definition}[Birenbaum's measure]
\emph{Birenbaum's measure} is defined as the change in a system's reliability, if we infinitesimally improve the reliability of component $j$.
Formally
\begin{align}
	I_j: =\frac{\partial}{\partial p_j} S_{\Phi}.
\end{align}
\end{definition}

Clearly any such importance measure, once computed, may serve to decide which component should be treated to improve reliability.

\subsection{A Time Dynamic View}
The reliability of each component ($p_j$), typically changes in time, and so does the reliability of the whole system.
In the following, $\T$ will typically stand for the time to malfunction. It is thus assumed to be \textbf{continuous} and \textbf{non-negative}.

\begin{definition}[CDF]
The cumulative distribution function (CDF) of a random variable $\T$ at a point $t$  is given by
\begin{align}
	\cdf{\T}{t}:= P(\T<t).
\end{align}
\end{definition}

\begin{definition}[PDF]
The probability density function (PDF) of a continuous random variable $\T$ at a point $t$ is given by
\begin{align}
	\pdf{\T}{t}:= \frac{\partial}{\partial t}\cdf{\T}{t}.
\end{align}
\end{definition}

\begin{definition}[Survival Function]
The survival function of a random variable $\T$ at a point $t$ is given by
\begin{align}
	\survive{\T}{t}:= P(\T>t)=1-\cdf{\T}{t}.
\end{align}
\end{definition}
By definition, it follows that if $\T_j$ is the time to failure of component $j$, then $$p_j(t)=\survive{\T_j}{t}.$$
If $\T_\struct$ is the time to failure of a system $\Phi$, then we may write $S_\struct(t)=\survive{\T_\struct}{t}$.

\begin{example}[Survival of a series system]
For a series system $\struct$, the reliability of the system at time $t$ is given by $$\survive{\Phi}{t}=\prod_{j=1}^{p} p_j(t).$$
\end{example}

\begin{example}[Survival of a parallel system]
For a parallel system $\struct$, the reliability of the system at time $t$ is given by $$\survive{\Phi}{t}=1- \prod_{j=1}^{p} (1-p_j(t))= \coprod_{j=1}^p p_j(t).$$
\end{example}

Another way to present a distribution, no less informative than the previous ones, is by the \emph{hazard function}, which is the ``probability of surviving just another instant''.
\begin{definition}[Hazard Function]
The \emph{hazard function}, or \emph{failure rate} of a random variable $\T$ at a point $t$ is given by \marginnote{Hazard Function}
\begin{align}
	\hazard{\T}{t} &:= \lim_{dt\to 0}\frac{P( \T \in [t,t+dt)|\T \geq t )}{dt} \label{eq:hazard}\\
	&= \frac{\pdf{\T}{t}}{\survive{\T}{t}} \\
	&= - \frac{\partial}{\partial t}\log \survive{\T}{t} . \label{eq:survival_to_hazard}
\end{align}
\end{definition}
The hazard function can be thought of as the expected number of events per unit of time, thus the name failure-rate.
If the unit of time is days, and the $\hazard{\T}{t}=2$, then we can expect two failure events in day $t$.
This also means that the total number of events expected since $t=0$, is the integral of the hazard, known as the \emph{cummulative risk}.
\begin{definition}[Cumulative Risk]
The \emph{cumulative hazard}, \aka the \emph{cumulative risk}, of a random variable $\T$ at a point $t$ is given by \marginnote{Cumulative Hazrd}
\begin{align}
	\cuhazard{\T}{t} &:= \int_{0}^{t}\hazard{\T}{s} \dif s \\
	\Rightarrow \survive{\T}{t} &= \exp(-\cuhazard{\T}{t}). \label{eq:cumhazrd}
\end{align}
\end{definition}
Eq.(\ref{eq:cumhazrd}) readily shows that a distribution is well defined by its hazards.

\begin{theorem}[Failure rate of a series system]
\label{thm:ifr_closure}
The failure rate of a series system of independent components $\Phi$ is given by the sum of the failure rates of its components
\begin{align}
	\hazard{\Phi}{t}= \sum_{j=1}^{p} \hazard{\T_j}{t}
\end{align}
\end{theorem}
The proof is immediate using the cumulative risk.
The failure rate of a parallel system, does not admit such a nice closed form as we will soon see in Example~\ref{eg:failure_parallel}.

\begin{example}[Exponential Hazard]
The simplest distribution when discussing hazards is the exponential.
Recalling the for non-negative $t$:
\begin{align}
	\pdf{\T}{t}= \lambda e^{-\lambda t}, \\
	\cdf{\T}{t}= 1-e^{-\lambda t},
\end{align}
so that
\begin{align}
	\survive{\T}{t} &= e^{-\lambda t}, \\
	\hazard{\T}{t} &= \lambda.
\end{align}
\end{example}
The exponential is the only distribution with constant hazard which makes it very easy to analyze.
The constant hazard is due to the \emph{memoryless} property. Look at Eq.(\ref{eq:hazard}) and think why.

% [HW: prove that memory less is sufficient]

\begin{example}[Failure rate of a series of exponential components]
The failure rate of a series system $\Phi$, of $p$ independent components each with exponentially distributed failure times, is simply
\begin{align}
	\hazard{\Phi}{t}= \sum_{j=1}^{p} \lambda_j, \forall t \geq 0
\end{align}
where $\lambda_j=\lambda_j(t)$ is the rate of each component.
\end{example}
This is obviously the simplest system possible for reliability analysis, which stems from the fact that a minimum of exponentials is exponential with the sum of rates.

The following example, seemingly very simple, provides tremendous insight into the complexities of reliability analysis.
\begin{example}[Failure rate of a two exponential-component parallel-system]
\label{eg:failure_parallel}
Consider a system of two independent, parallel, exponential components, with failure times $\T_j\sim \exp(\lambda_j); j=1,2$.
The failure rate is given by
\begin{align}
	\hazard{\Phi}{t}=
	\frac
	{\exppdf{\lambda_1}{t} + \exppdf{\lambda_2}{t}  - \exppdf{(\lambda_1+ \lambda_2)}{t}}
	{\expcdf{\lambda_1}{t} + \expcdf{\lambda_2}{t} - \expcdf{(\lambda_1+ \lambda_2)}{t}}
\end{align}
\end{example}
Why is Example~\ref{eg:failure_parallel} so important?
Because it demonstrates that even in a simple system, with the simplest components, the reliability is not so simple to compute (as a function of the components' reliability).
Indeed, even though the component-wise hazards are fixed in time, the system's hazard is not fixed, and not even monotone in time (Figure~\ref{fig:hazard_non_monotone}).

\begin{figure}[ht]
\centering
\includegraphics[width=0.5\linewidth]{art/hazard}
\caption{Failure rate of the parallel exponential component system.}
\label{fig:hazard_non_monotone}
\end{figure}

\begin{example}[Weibull Hazard]
The Weibull distribution is very common in reliability analysis since it is tractable generalization of the exponential distribution with many nice properties.
It can be constructed by
$\T := \lambda \U^{1/k}$, where $\U \sim \exp(1)$.
This implies that for non negative $t$:
\begin{align}
	\pdf{\T}{t} &= \frac{k}{\lambda}\left(\frac{t}{\lambda} \right)^{k-1} e^{-(t/\lambda)^k}, \\
	\cdf{\T}{t} &= 1 - e^{-(t/\lambda)^k},
\end{align}
so that
\begin{align}
	\survive{\T}{t} &= e^ {-(t/\lambda )^k}, \\
	\hazard{\T}{t} &= \frac{k}{\lambda} \left(\frac{t}{\lambda} \right)^{k-1} .
\end{align}
\end{example}
Elementary analysis shows that the hazard function of the Weibull may be increasing or decreasing in time ($\T$), depending on $k$, but it is always monotone.

\begin{example}[Gompertz Hazard]
	The Gompertz distribution\footnote{Not to be confused with it's generalization, the \emph{Gompertz-Makeham} distribution.} is another common distribution in reliability analysis.
	\begin{align}
%	\pdf{\T}{t} &= \\
	\cdf{\T}{t} &= 1- e^\frac{-\lambda (\varphi^t-1)}{\log \varphi},
	\end{align}
	so that
	\begin{align}
	\survive{\T}{t} &= e^\frac{-\lambda (\varphi^t-1)}{\log \varphi}, \\
	\hazard{\T}{t} &= \lambda \varphi^t .
	\end{align}
\end{example}
Elementary analysis shows that the hazard function of the Gompertz may be increasing or decreasing in time ($\T$), depending on $\varphi$, but it is always monotone.

\begin{example}[Empirical risk rates]
	\label{ex:bathtub}
When examining empirical risk rates of true devices, we almost always notice a \emph{bathtub} structure, such as in Figure~\ref{fig:bathtub}.\marginnote{Bathtub}
This shape captures the idea that products tend to fail more when they are brand new, or as they are very old, while their failure rates are fairly stable in the ``mid-life''.
In this text, we will not be providing a particular distribution which has this property.
We refer the reader to \cite{nadarajah_bathtub-shaped_2008} for examples of distributions which have the bathtub property.
\end{example}

\begin{figure}[ht]
\centering
\includegraphics[width=0.5\linewidth]{art/bathtub_curve}
\caption[Bathtub empirical hazard curve]{Bathtub curve of empirical failure rates. \newline
\url{http://support.minitab.com/en-us/minitab/17/topic-library/modeling-statistics/reliability/distributions-in-reliability-analysis/hazard-functions/}}
\label{fig:bathtub}
\end{figure}

\subsubsection{Aging}
The idea of \emph{aging} is that failure rate may vary over time. It is an important concept in reliability, as demonstrated by the empirical bathtub failure rate (Figure~\ref{fig:bathtub}).
Instead of checking if a particular textbook distribution has some ageing property, we instead analyze classes of distributions with the desired notion of ageing.
Our goal will ultimately be to understand the ageing of a whole system, as a function of the ageing of its components.

\begin{definition}[IFR]
We call a failure time distribution to be in the \emph{increasing failure rate} (IFR) ageing class, if it has a non decreasing failure rate.
\end{definition}

\begin{definition}[IFRA]
We call a failure time distribution to be in the \emph{increasing failure rate average} (IFRA) ageing class, if the average risk is non decreasing in $t$.
Formally: $\cuhazard{\T}{t}/t=\int_0^t \hazard{\T}{s}\dif s/t$ is non decreasing in $t$.
\end{definition}
The intuition underlying IFRA relies on understanding $\cuhazard{\T}{t}/t$, which can be seen as the average risk from ignition to time $t$.
IFRA thus means that even if the risk decreases at some point in time, the average risk still increases.

\begin{definition}[NBU]
We call a failure time distribution to be in the \emph{new better then used} (NBU) ageing class, if
$\survive{\T}{t_1+t_2} \leq \survive{\T}{t_2} \survive{\T}{t_1}$.
\end{definition}

\begin{definition}[NBUE]
Define the \emph{expected residual life}, $\mu(t)$, to be
$$\mu(t):= \expect{\T-t|\T>t}.$$
\marginnote{Expected Residual Life}
We call a failure time distribution to be in the \emph{new better then used in expectation} (NBUE) ageing class, if
$\mu(t) \leq \mu(0)$.
\end{definition}
NBUE can be easily understood, since it means that a component's expected life is maximal when it is brand new.

\begin{theorem}
$IFR \Rightarrow IFRA \Rightarrow NBU \Rightarrow NBUE. $
\end{theorem}

The following theorem states a relation between the ageing properties of particular components, and that of the whole system. In particular it states that for the (very wide) class of monotone systems, then the IFRA property is conserved.
This should be contrasted with the IFR property, which is not conserved, as demonstrated by the parallel system in  Example~\ref{eg:failure_parallel}.
\begin{theorem}[IFRA closure theorem]
\label{thm:ifra_closure}
If the independent components of a monotone system are IFRA, then so is the whole system.
\end{theorem}

Series systems are a extremely small and particular subset of monotone systems.
It does provide, however, an example of systems where not only IFRA is preserved, but also the stronger IFR.
The following corollary follows immediately from Theorem~\ref{thm:ifr_closure} and the fact that a sum of monotone functions is monotone.
\begin{cor}[IFR closure for series systems]
\label{cor:ifr_series}
A series system of independent IFR components is IFR.
\end{cor}

Now consider a two-component system, where one component kicks-in when the first fails.
We will call this an \emph{offline backup}.\marginnote{Offline Backup}
The survival times of the components in an offline backup system are clearly dependent.
It turns out that for such a system of IFR components, does conserve the IFR property, as seen in the following theorem.
\begin{theorem}[Convolution of IFR]
\label{thm:ifr_convolution}
For two independent random variables, $\x$ and $\y$, both in the IFR ageing class, then so is $\x+\y$.
\end{theorem}
The theorem is called the convolution theorem, because the distribution of a sum of independent random variables, is the convolution of their distributions.

\begin{extra}[IFR and log-concave]
The IFR requirement, is essentially the same as log-concavity of the density function.
This immediately implies many properties of the class, including the convolution theorem above.
See \cite{bagnoli_log-concave_2005}.
\end{extra}

\begin{example}[IFR of Gamma]
The Gamma (and thus the Erlang) distribution is in the IFR aging class, since it is the sum of exponentials, each IFR.
\end{example}

\begin{example}[Series system of offline backups]
What can we say about the ageing class of a series systems of offline backup systems?
It turns out that if the components are IFR, then so will the whole system.
This is immediate from Corollary~\ref{cor:ifr_series} and Theorem~\ref{thm:ifr_convolution}.
\end{example}

\section{Statistical Analysis}
%TODO: update using Venables and Ripley (2002)

The probabilistic analysis of the previous section is great fun and all, but like any probabilistic problem, is has to be calibrated to real life.
This is where data, and statistics come in.

The statistical analysis of time-to-event data is very important to many disciplines.
It possibly started in the $17$'th century with the \emph{Life Tables} of John Graunt and
William Petty, used by actuaries to compute life expectancies.
These were later reinvented and augmented to the full statistical framework known as \emph{failure-time} analysis in engineering, \emph{survival} analysis in epidemiology and biostatistics, and \emph{event-history} analysis in sociology. \marginnote{Failure-time analysis}

\begin{remark}[Reliability analysis versus failure-time analysis]
	In this text we use the term \emph{reliability analysis} for the probabilistic analysis above, and \emph{failure-time analysis} for the statistical problem.
	We do so to respect the original literature where these originate.
\end{remark}

The statistical analysis of failure data, is typically concerned with the estimation of the \textbf{hazard} function, or the \textbf{survival} function.
To do so, we face the following statistical challenges:
\begin{description}
\item [Failure Distribution] like any statistical model, we will need to assume something about distributions of failure times.

\item [Identifiability] It is typically hard, if not impossible, to estimate the reliability of particular components, from the reliability of the whole system.

\item [Censoring] A major concern with reliability data, is that in any finite length experiment, some events will just not have happened yet; their failure time will thus be \emph{censored}. Ironically- the more reliable a component, the less data we will have to estimate its reliability.

\item [Lab versus real-life conditions] Reliable components take very long time to fail. We will thus extrapolate from harsh lab conditions to real-life operating conditions. This requires the introduction of covariates.

\end{description}

\subsection{Failure distribution}
Assuming the distribution of the failure time is no different than the problem of assuming the sampling distribution in elementary statistical problems (e.g., in a t-test).
Luckily, there is one very popular estimator of the hazard function, which is \emph{non-parametric}, meaning that it is free of any distribution assumption.
\begin{definition}[Kaplan-Meier Estimator]
	The Kaplan-Meier estimator of the survival function $\survive{\T}{t}$ is defined as
	\begin{align}
		\surviven{\T}{t}:=\prod_{t_i \leq t} \frac{n_i-d_i}{n_i},
	\end{align}
	where $t_i$ is the period between the $i-1$'th event and the $i$'th event,
	$n_i$ is the number of units that did not fail until the end of $t_i$,
	$d_i$ is the number of units that fail in period $t_i$ (typically $1$, except for ties).
\end{definition}
The rational of the estimator is obvious once we realize that $\frac{n_i-d_i}{n_i}$ estimates the probability of \textbf{not} failing during period $t_i$, and that surviving all the way to time $t$ means not failing for all previous periods.

Given a covariate, $x$, that splits into sub populations, one may estimate and compare the survival separately for each value of the covariate: $\surviven{\T|x}{t}$.

\subsection{Identifiability}

\begin{example}[Likelihood estimation of a series system]
\label{eg:likelihood_of_failures}
Assume a series system $\Phi$ with $p$ independent, exponential components with rates $(\lambda_1,\dots,\lambda_p)$.
We have $n$ observations on the failure times of the system $t_1,\dots,t_n$.
How can we estimate the failure rates?
To use a likelihood approach, we need the data's sampling distribution.
Denoting the failure time of the $j$'th component of the $i$th device with $\T_{i,j}$, we have that $\T_{i,j}\sim \exp(\lambda_j)$ by assumption.
Since the system is serial, then $\T_i=\min_j(\T_{i,1},\dots,\T_{i,p})$.
By the properties of the exponential distribution $\T_i \sim \exp(\lambda)$, where $\lambda:=\sum_{j=1}^{p} \lambda_j$, as we have already seen with the failure rate. It follows that
$\pdf{\T_i}{t}=\lambda \exp(-\lambda t)$.
We may then write the likelihood function, maximize it with respect to $\lambda$ and discover, as we already know, that $$\hat{\lambda}=\frac{n}{\sum_{i=1}^{n} t_i}.$$
We are now left with the problem of recovering $(\lambda_1,\dots,\lambda_p)$ from $\lambda$.
Can we do it? On the face of it- no. Which should not surprise us, since the mere knowledge of a device failure, is not very informative on the particular component that failed, which we would need to estimate $(\lambda_1,\dots,\lambda_p)$.
\end{example}

Example~\ref{eg:likelihood_of_failures} teaches us that unless further assumptions are introduced, the estimation of the component-wise failure rates requires information on the component-wise failure times.

\subsection{Censored Events}
Consider several components being analyze for their reliability.
Ironically, we actually want them to fail. If they do not, they do not convey information on their reliability.
In the event that a component has not failed, we clearly cannot register its failure time.
Omitting this component from the sample will upward bias the estimated reliability.
These events are called \emph{censored} observations.

Decomposing the likelihood function, $\lik$, to the contributions of each independent event, $\lik=\prod_{i=1}^n \lik_i$, then the likelihood of non-censored events is given by
\begin{align}
	\lik_i=\density_\T(t_i)= \survive{\T}{t_i} \hazard{\T}{t_i},
\end{align}
and the likelihood of a censored event, under the \emph{non-informative} assumption, is given by
\begin{align}
	\lik_i=\survive{\T}{t_i} .
\end{align}
Unifying the two cases assuming independent observations, using an indicator for non-censoring, $c_i$, and taking logs we have
\begin{align}
	\loglik &:=\log \lik\\
	&= \log \left[\prod_{i=1}^{n} \survive{\T}{t_i} \hazard{\T}{t_i}^{c_i}\right] \\
	&= \sum_{i=1}^{n} [c_i \log \hazard{\T}{t_i} - \cuhazard{\T}{t_i}]. \label{eq:censored_likelihood}
\end{align}

\begin{example}[Censored exponential lifetimes]
\label{ex:censoring}
Recalling that the failure rates of exponential lifetimes are fixed, we have that the likelihood of censored exponential lifetimes is given by
$$
	\sum_{i=1}^{n} [c_i \log \lambda - \lambda t_i].
$$
The maximum likelihood estimator of $\lambda$ is thus
\begin{align}
	\estim{\lambda}= \frac{\sum c_i}{\sum t_i}. \label{eq:censored_ml}
\end{align}
Eq.(\ref{eq:censored_ml}) lends itself to a nice interpretation.
The numerator is the total number of failures.
The denominator is the total \emph{exposure time}.
The estimated failure rate is thus the number of failures per unit of exposure time.
\end{example}

The example also demonstrates that overly reliable components is a problem.
If no component fails, i.e., all observations are censored, then $\sum c_i=0$, so that $\estim{\lambda}=0$.
This is both mathematically true, and absolutely not interesting; we need events to occur for us to learn from them!
This motivates the use of covariates such as temperature, pressure, humidity, etc. to force failure events.
The problem will then be how to convert failure rates in extreme conditions, to failure rates in regular conditions?
Sometime we have a physical theory that tells us what is the effects of various factors.
For instance, the \emph{Arrhenius model}, and the \emph{Eyring model} are physically motivated models that capture the effect of temperature.
For models for stress, voltage, humidity, and other life accelerating covariates, see for instance \cite[Sec.8.1.5]{natrella_nist/sematech_2010}
In the next section we introduce two very simple models to demonstrate how we deal with covariates.

\begin{extra}
The results in Example~\ref{ex:censoring} is trivial if you consider failures as events which come as a Poisson process, which is implied from the exponential times assumption.
The process is run for $\sum t_i$ time, and the total event count is $\sum c_i$.
The trivial estimator for the rate of the process, is $\sum c_i/\sum t_i$.
\end{extra}

\subsection{From lab to reality: ``Accelerating Life''.}

\subsubsection{Accelerated Life model}
An \emph{accelerate life} model assumes that covariates rescale \emph{time}.
For instance, the lab may produce conditions where time advances ten times faster than in real-life operating conditions.

The model is best understood as a \emph{log-linear} model, i.e., the effects of the various factors, $x$, are linear in log-of-time scale:
\begin{align}
\label{eq:estimating_accelerated_life}
	\log \T_i = x_i'\beta + \varepsilon_i,
\end{align}
for some error term $\varepsilon_i$.

The definition of accelerated life models via Eq.(\ref{eq:estimating_accelerated_life}) is very convenient for practical purposes.
It means that after taking the log of failure times, effects ($\beta$'s) can be estimated using any software that can solve a linear model.

The accelerated life model, like any other log-linear model, implies that our factors have multiplicative effects.
To see this, compare the distribution of failure times at some condition $x_0$ versus some other condition $x_1$.
Taking the exponent of both sides of Eq.(\ref{eq:estimating_accelerated_life}) we have
\begin{align}
	\T_{x_1} = \T_{x_0} e^{\beta'(x_1-x_0)},
\end{align}
so we see that a change in the conditions from $x_0$ to $x_1$ multiplies failure times.
This also explains why the models are called \emph{accelerated time}: this is because we can make time ``move'' multiplicatively faster or slower, by changing the operating conditions.

\begin{think}
	Think of a single two-state factor, $x_i \in\set{0,1}$ to get some intuition to the meaning of the parameter $\beta$.
\end{think}

\begin{example}[Accelerated life with Gaussian noise]
\label{eg:accelerated_gaussian}
The maximum likelihood estimation of $\beta$ when assuming that $\varepsilon_i \sim \gauss{0,\sigma^2}$, collapses to a simple linear regression when the dependent variable is simply $\log t_i$.
\end{example}

\begin{extra}[Tobit regression]
Assuming $\varepsilon_i \sim \gauss{0,\sigma^2}$, as in the previous example, implies that failure times are \emph{log normal} distributed.
This approach is known as \emph{Tobit} regression.
\end{extra}

\subsubsection{Proportional Hazard Models}
The \emph{proportional hazard}, or \emph{proportional risk} class of models, assumes that covariates multiply not time, but rather failure rates.
Put differently, accelerated rescales time linearly, thus hazards are rescaled non-linearly. Proportional hazards rescale hazards linearly, thus time is rescaled non-linearly.
Qualitatively, they are the same.
Quantitatively, the exact amount of acceleration (deceleration) may differ.
The choice between these models typically depends on the underlying physical theory, and on the ease of computation and interpretation.

A proportional hazard model assumes that the risk function when operating under some conditions $x_0$ is related to the risk under conditions $x_1$ via:
\begin{align}
\label{eq:proportional_hazard}
	\hazard{\T|x_1}{t}:=\hazard{\T|x_0}{t} e^{\beta'(x_1-x_0)}  ,
\end{align}

\begin{think}
	Think of a single two-state factor, $x_i \in\set{0,1}$ to get some intuition to the meaning of the parameter $\beta$.
\end{think}

The linear rescaling of the risk in the proportional hazard model, implies the following relation between survival functions
\begin{align}
\label{eq:survival_proportional_hazard}
	\survive{\T|x_1}{t}=\survive{\T|x_0}{t}^{\exp((x_1-x_0)'\beta)}.
\end{align}
To see this recall Eq.(\ref{eq:survival_to_hazard}):
\begin{align*}
\hazard{\T|x_1}{t}
&=  - \frac{\partial}{\partial t} \log \survive{\T|x_1}{t}  \\
&= - \frac{\partial}{\partial t} \log \survive{\T|x_0}{t}^{\exp((x_1-x_0)'\beta)} \\
&= e^{(x_1-x_0)'\beta} - \frac{\partial}{\partial t}  \log \survive{\T|x_0}{t} \\
&=  \hazard{\T|x_0}{t} e^{(x_1-x_0)'\beta}
\end{align*}
as required.

\begin{example}[Closure of the exponential failure times]
The exponential failure times have a nice property:
if the failure times are exponential under \textbf{some} condition, $x_0$, then they are exponential for \textbf{all} conditions.
This holds if we assume that factors have an accelerated-time effect, or a proportional-hazard effect.
Put differently: for the exponential distribution (only), a linear rescaling of time is equivalent to a linear rescaling of hazards.
Put more differently: if we assume exponential failure times, the proportional-hazard model and the accelerated-life model are the same. \\
\textbf{Proof:}
The proportional-hazard case:
$\T_{x_0}\sim \exp(\lambda)$ by the exponential assumption, so that
$\hazard{\T_{x_0}}{t}=\lambda$.
Now $\hazard{\T_{x_1}}{t}=\hazard{\T_{x_0}}{t} e^{\beta(x_1-x_0)}$ by the proportional hazard assumption, so that $\forall x_1: \hazard{\T_{x_1}}{t}= const$, which completes the proof that failure times are exponential under \textbf{all} conditions. \\
The accelerated-life case:
$\T_{x_0}\sim \exp(\lambda)$ by the exponential assumption, so that
$e^{\varepsilon_i}$ is exponential.
Denoting $\gamma:=e^{\beta'(x_1-x_0)}$, then $\T_{x_1} = \gamma \T_{x_0} $ by the accelerated time assumption, so that $\forall x_1: \T_{x_1} \sim \exp(\lambda/\gamma)$, which completes the proof that failure times are exponential under \textbf{all} conditions.
\end{example}

\subsection{Choosing the Base Failure Rate}
\label{sec:based-failure-rate}
In all the above models, we are free to choose the base failure rate:
$\survive{\T_0}{t}$ in Eq.(\ref{eq:accelerated_life}), or
$\varepsilon$ in Eq.(\ref{eq:estimating_accelerated_life}), or
$\hazard{\T|x_0}{t}$ in Eq.(\ref{eq:proportional_hazard}).
Three possible approaches include:
\begin{enumerate}
\item Assume a \textbf{parametric} model, such as exponential times, Weibull times, etc.
\item Assume a \textbf{semi-parametric} model, which can be simply seen as a flexible class of distributions, that has no particular parametric representation. In failure-time analysis, the \emph{piece-wise constant} hazard is a popular choice.
\item Do not assume anything on the distribution, known as a \textbf{non-parametric} approach.
\end{enumerate}
If we assume a particular parametric model, then we may gather failure time data, write the likelihood function, and return failure rate estimates, and covariate effects.
We now focus on the more flexible framework of semi-parametric modelling.

\subsection{The Parametric Case}
A parametric model fitting to failure data, is simply a maximum likelihood problem.
Examples \ref{eg:likelihood_of_failures}, \ref{eg:accelerated_gaussian}, and \ref{eg:accelerated_exponential} demonstrate this.

\subsection{The Semi Parametric Case}
We now relax the explicit failure time distribution assumption, and adopt a more flexible semi-parametric distribution class, known as the \emph{piecewise exponential class}.\marginnote{Piecewise Exponenitial}
Consider the proportional hazard model:
\begin{align}
	\hazard{\T|x_1}{t}:=\hazard{\T|x_0}{t} \times \exp((x_1-x_0)'\beta).
\end{align}
The model clearly requires some baseline failure rate $\hazard{\T|x_0}{t}$.
A flexible, yet not too flexible assumptions, is that the failure rate is constant in some time intervals:
\begin{align}
	\hazard{0}{t}=h_j \quad \text{if} \quad t\in [\tau_{j-1},\tau_j)
\end{align}
This class of distributions has $J(J-1)$ parameters: $(\tau_1,\dots,\tau_{J-1},h_1,\dots,h_J)$.
We are free to choose $J$.
Large $J$ are very flexible classes, but will require a lot of failure data to estimate.
Small $J$ are less flexible, but require less data to estimate.
At the limits, when $J=1$, we are back to exponential failure times.
At the other limit, where $J \to \infty$, we have an absurdly flexible distribution class, which requires impossibly large amounts of data to estimate.

Since the failure rate is piece-wise constant, the distribution class is known as \emph{piece-wise exponential}.\marginnote{Piecewise Exponential}
It is a rather flexible class of distributions. Figure~\ref{fig:piecewise_exponential} depicts the approximation of the Weibull survival function, using a piece-wise constant hazard function, with $J=3$ and appropriate selected parameters.
\begin{figure}[ht]
\centering
\includegraphics[height=0.2\textheight]{art/piecewise_exponential}
\caption{Piecewise Exponential aproximation of the Weibull distribution.}
\label{fig:piecewise_exponential}
\end{figure}

The piecewise-constant hazard model is very convenient to analyze under the proportional hazard assumption:
\begin{align}
	\hazard{x}{t} = \hazard{x_0}{t} e^{(x-x_0)'\beta} = h_j e^{(x-x_0)'\beta}.
\end{align}
There are $p+2J$ parameters to estimate.
This can be done directly using maximum likelihood, or by casting the problem as several separate Poisson regression problem.
This has the benefit that the problem may be immediately solved with any statistical software suite, with existing numerical solvers.
We will currently not pursue this avenue, and refer the reader to the bibliographic notes.

\section{Collecting the pieces}
In this chapter we have seen the probabilistic reliability analysis, where we assumed components' reliabilities are known.
We then proceeded to the statistical problem of estimating reliabilities from failure data.
We now glue collect these pieces to sketch a realistic analysis workflow, which would look roughly as follows:
\begin{enumerate}
\item Estimate reliability parameters by collecting component-wise failure data. Data is collected in a lab so that you may accelerate time and rescale to realistic operating conditions.
\item Perform the probabilistic analysis of the whole system using the estimated parameters.
\end{enumerate}

\begin{remark}[Interplay between probability and statistics]
There is obviously an interplay between the above stages:
In the statistical analysis, we want the least possible set of assumptions;
For the probabilistic analysis, the more we can assume, the more we can say about the system as a whole.
\end{remark}

\begin{remark}[What is a component?]
The notion of a ``system'' and a ``component'' is not well defined.
Indeed, for some purposes you may consider a system, as a component in a larger system.
For the statistical problem, a component is probably the smallest unit you can collect data on. At times, the smallest unit, may be the system as a whole.
\end{remark}

\section{Repairable systems}
In this section we return the a probabilistic analysis.
Unlike the previous sections, we now study systems which may be repaired after they fail.
We will thus want to study the state of the system at time $t$.
This state may depend on the number of failures and repairs performed on the system up to $t$.

We start with the introduction of some quantities of interest.
\begin{definition}[Point availability]
The point availability at time $t$, denoted $A(t)$ is defined as
\begin{align}
	A(t):= \expect{\Phi_t}=P(\Phi_t=1) .
\end{align}
\end{definition}

\begin{definition}[Interval reliability]
When considering the availability in some time interval $J$, and denoting by $N_J$ the number of system failures in the interval, we may study
\begin{align}
	P(N_j\leq k) &\\
	M(J) &:= \expect{N_j} \\
	A(J) &:= P(\Phi_t=1), \forall t \in J.
\end{align}
\end{definition}

\begin{definition}[Interval downtime]
Denoting by $Y_J=\int_J (1-\Phi_t) dt$ the downtime during interval $J$, we may study
\begin{align}
	P(Y_j \leq y) &	\\
	A^D(J) := \frac{\expect{Y_J}}{|J|}
\end{align}
\end{definition}

\paragraph{Limiting measures} The particular time $t$, or interval $J$ are usually not of real importance in the sense that all times and intervals are equally important.
We will thus typically be interested in the above performance measures for in some \emph{steady state} of the systems, so that the measure is representative of all $t$ (or $J$), and thus no longer depends on $t$ (or $J$).
The typical approach for this is to study the limit of the performance measure, which implies the system has reached it's steady state. Formally, this means studying $\lim_{t \to \infty}$ of the above measures.

We now start with the analysis of a \emph{single component} system, which we later complicate into \emph{multiple component systems}.
The required theory is that of stochastic processes, in particular \emph{counting processes}.
The reader is referred to the bibliographic notes for rigorous proofs and details.

\subsection{Single component systems}
For a single component, $\Phi_t=\x(t)$.
If the component fails, it is replaced or repaired.
We denote by $T_k$ and $R_k$ and the (random) time of the $k$'th run, and repair, respectively.
We assume $T_k \sim F$ and $R_k \sim G$, independent.

\begin{definition}[MTTF]
We denote by $\mu_F=\expect{T_k}$, the \emph{mean time to failure} (MTTF).
\end{definition}

\begin{definition}[MTTR]
We denote by $\mu_G=\expect{R_k}$, the \emph{mean time to repair} (MTTR).
\end{definition}

Obviously, MTTR and MTTF are important characteristics of the single-component system.

\begin{theorem}[Stable point availability]
As $t \to \infty$
\begin{align}
	A(t) \to \frac{\mu_F}{\mu_F+\mu_G}.
\end{align}
\end{theorem}

\begin{theorem}[Stable failures per unit of time]

As $t \to \infty$, then with probability one
\begin{align}
	\frac{N_t}{t} \to \frac{1}{\mu_F+\mu_g}
\end{align}
\end{theorem}

\begin{theorem}[Stable unavailability]
As $t \to \infty$, then with probability one
\begin{align}
	A^D([0,t])=\frac{Y_t}{t} \to \frac{\mu_G}{\mu_F+\mu_G}
\end{align}

\end{theorem}

\subsection{Multiple component systems}
We will now want to study the availability of a system of multiple repairable components.
The performance of the single-component system still apply, but the analysis now has to account for the fact that the state of the systems depends on the state of $n$ repairable components, assumingly independent.
By indexing the components with $i$, we denote $T_{i,k}, R_{i,k}$ for the uptime and repair time of the $k$'th failure of the $i$'th component. Their distributions are $F_i$ and $G_i$ respectively.
The system failures up to time $t$ is still $N(t)$, but not we also allow for component-wise processes $N_i(t)$, with expectations $M(t)$, and $M_i(t)$.

Denoting $A_i(t)$ the availability of component $i$ at time $t$, $A(t)$ the n-vector of reliabilities, and $A_\Phi(t)$ the whole system's reliability.

[TODO:Complete from  \cite[Sec.4.3]{aven_stochastic_1999}]

\section{Bibliographic Notes}
An light introductory discussion, may be found in \cite{nahmias_production_2015}.
The probabilistic analysis in this text is adapted from \cite{aven_stochastic_1999}.
The seminal reference probably being \cite{barlow_mathematical_1965}.
The statistical analysis is adapted from German Rodriguez's Generalized-Linear-Models class notes\footnote{\url{http://data.princeton.edu/wws509/notes/c7.pdf}.} and \cite[Ch.8]{natrella_nist/sematech_2010}.
For more on the statistical analysis, see Chapter 13 of the excellent \citet{venables_modern_2002} and references therein.

%