\documentclass[a4paper]{article}
\usepackage[a4paper, total={6.5in, 10in}]{geometry}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{floatrow}
\restylefloat{table}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{float}
\title{Vector-Valued Image Regularization with PDEs}

\author{Meet Kathiriya, Shreyas Pimpalgaonkar, Saiteja Talluri \\ 160050001,160050024,160050098}

\date{\today}

\begin{document}
\maketitle

\begin{abstract}

We focussed on techiniques for vector-valued image regularization, based on variational methods and PDEs. We performed denoising, image reconstruction, inpainting, magnification and flow visualization on color images using these techinques and presented our results and conclusions.
\end{abstract}

\section{Theory}
\label{sec:theory}
\hspace{5mm}The problem of image regularisation can be solved by three interconnected models of functional \\ minimisation, divergence expressions and oriented laplacians.

The structure tensor is used here, and it's eigen vectors represent directions of maximum variation. Therefore, the problem can be formulated as minimising the generalised functional representing the variation in the image using the eigen vectors as follows
$$\min_{I:\Omega\to\mathcal{R}^{n}} E(I) = \int_{\Omega} \psi(\lambda_{+},\lambda_{-})\,d\Omega$$

 The above equation can be converted to the divergence of a diffusion matrix with gradient of the Image channel by using Euler-Lagrange theorem, heat equations, orthogonality of eigen vectors and simple partial differential equation chain rules as done in the appendix 1 of the original paper.
        $$\frac{\partial I_i}{\partial t} = div ( D \nabla I )          \qquad  (i = 1..n) $$
        $$ \textbf{D} = \frac{\partial \psi}{\partial \lambda_+} \theta_+ \theta_+^T  +  \frac{\partial \psi}{\partial \lambda_-} \theta_- \theta_-^T$$
    where $n$ is the number of channels and $\theta_+,\theta_-$ are the eigen vectors of the structure tensor. If a $\psi$ exists, eigenvalues of the divergence tensor D can be seen it's gradient and obtaining $I_i$ is easy for every channel.

The oriented laplacian equation can be written as the following PDE
$$\frac { \partial I _ { i } } { \partial t } = c _ { 1 } I _ { i \epsilon \varepsilon } + c _ { 2 } I _ { i m } = \operatorname { trace } \left( \mathbf { T } H _ { i } \right)$$
 $$ I _ { i ( t ) } = I _ { i _ { ( t = 0 ) } } * G ^ { ( \mathbf { T } , t ) }$$
where $*$ stands for the convolution with the oriented Gaussian kernel
$$G ^ { ( \mathbf { T } , t ) } ( \mathbf { x } ) = \frac { 1 } { 4 \pi t } \exp \left( - \frac { \mathbf { x } ^ { T } \mathbf { T } ^ { - 1 } \mathbf { x } } { 4 t } \right) \quad \text { with } \quad \mathbf { x } = ( x \quad y ) ^ { T }$$

$$\frac { \partial I _ { i } } { \partial t } = \operatorname { trace } \left( \mathbf { T } \mathbf { H } _ { i } \right) \quad ( i = 1 . . n )$$

where $\textbf{T}$ is the tensor field defined pointwise as

$$\mathbf { T } = f _ { - } \left( \sqrt { \lambda _ { + } ^ { * } + \lambda _ { - } ^ { * } } \right) \theta _ { - } ^ { * } \theta _ { - } ^ { * T } + f _ { + } \left( \sqrt { \lambda _ { + } ^ { * } + \lambda _ { - } ^ { * } } \right) \theta _ { + } ^ { * } \theta _ { + } ^ { * } T$$

where $\lambda_{\pm}^*$ and $\theta_{\pm}^*$ are defined to be the spectral elements of $G_\sigma = G * G_{\sigma'}$ , a Gaussian smoothed version of the structure tensor G, allowing us to retrieve a more coherent vector geometry giving a better approximation of the vector discontinuity directions.

For our experiments we choose, $f _ { + } ( s ) = \frac { 1 } { 1 + s ^ { 2 } } .\text { and } f _ { - } ( s ) = \frac { 1 } { \sqrt { 1 + s ^ { 2 } } }$ \newline

Finally, a high level overview of the algorithm is to convolve the image with a gaussian that solves the PDE of Oriented Laplacians with $\textbf{T}$ and $f$ as in the above section. This is equivalent to using the trace formula in section 2.3 and also is proved in the original paper.

\pagebreak
\section{Results and Inferences}

\subsection{Image Inpainting}

\begin{figure}[h]
\centering
\includegraphics[width=1\textwidth]{glasses.png}
\caption{\label{fig:data} Inpainting with 21x21 neighbourhood, t=5 and 10 iterations}
\end{figure}

\begin{figure}[h]
\centering
\includegraphics[width=1\textwidth]{parrot1.png}
\caption{\label{fig:data} Inpainting with 10x10 neighbourhood, t=2 and 20 iterations}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[width=1\textwidth]{redparrot.png}
\caption{\label{fig:data} Inpainting with 20x20 neighbourhood, t=3 and 20 iterations Also the black prints at boundaries and some darker regions in image is due to the fact that the mask we are using is imperfect as it contains more white region at some locations than the cage obstacle in real image.}
\end{figure}

\pagebreak
\subsection{Image Denoising}

\begin{figure}[h]
\centering
\includegraphics[width=1\textwidth]{baby.png}
\caption{\label{fig:data} From L to R : Noisy image, image filtered with gaussian smoothing with 5x5 kernel, image filtered with PDE regularisation with t=3, 3x3 neighbourhood and 5 iterations - better performance and lower noise especially on left and top parts of the image }
\end{figure}

\begin{figure}[h]
\centering
\includegraphics[width=0.8\textwidth,height=0.4\textwidth]{face.png}
\caption{\label{fig:data} From L to R : Noisy image, image filtered with PDE with t=3, 3x3 neighbourhood and 5 iterations }
\end{figure}

\subsection{Image Magnification}

\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{jerry.png}
\caption{\label{fig:data}
    From L to R : Original Image. This image was downsampled by 4 to serve as input for the two algorithms. Magnified image using bi-linear interpolation, magnified image using PDE regularisation with t=3, 3x3 neighbourhood and 10 iterations.
}

\end{figure}

\pagebreak

\subsection{Flow Visualisation}

\begin{table}[H]
\caption{Input images, flow vectors and output images, with dt = 0.01, 100 iterations and sobel gradient vectors for Hessian Matrix. Paralallised code, runs much faster compared to others}
\begin{tabular}{c c c}
\includegraphics[width=0.33\textwidth,height=0.4\textwidth]{1} & \includegraphics[width=0.33\textwidth,height=0.4\textwidth]{5} &
\includegraphics[width=0.33\textwidth,height=0.4\textwidth]{2}\\
\includegraphics[width=0.33\textwidth,height=0.4\textwidth]{4} & \includegraphics[width=0.33\textwidth,height=0.4\textwidth]{6} &
\includegraphics[width=0.33\textwidth,height=0.4\textwidth]{3}
\end{tabular}
\end{table}

\subsection{Image Restoration}

\begin{figure}[H]
\centering
\includegraphics[width=1\textwidth]{obama.png}
\caption{\label{fig:data}
    From L to R : Input Image, image with 50 \% pixels removed in 2x2 granularity, output image with SSIM of 0.995, better than results with median filter. Also, median filter will become less accurate on increasing the box sizes. }

\end{figure}

\begin{figure}[H] \label{frow}
 \begin{floatrow}
 {\includegraphics[width=0.5\textwidth]{l1}}
 {\includegraphics[width=0.5\textwidth]{l2}}
 \end{floatrow}
 \caption{\label{fig:data} from L to R : image with 50 \% pixels removed and SSIM = 0.23, restored image with t=4, 10 iterations with 3x3 neighbourhood, SSIM = 0.966 with original image}
\end{figure}

\section{Experimental Observations and Conclusions}

\begin{enumerate}
    \item This technique is hard to parallelise in MATLAB as we have to calculate the eigen vectors and eigen values of the  structure tensor at each pixel (The matrix $\textbf{T}$). The MATLAB eig function doesn't provide this functionality. We tried to do this using parfor but it takes too much time to setup the threads and ultimately is slower.

    \item Image Inpainting fails drastically as the size of the width of continuous portion of mask increases. Inpainting by this framework is only suitable for removing shapes like cylinders/spheres with small radii. On increasing the width, the lost information is harder to recover due to the high variability in diffusion. Some techniques that specialise in hole filling on the basis of similar patterns like used in Mean Shift Segmentation can be used to give better results. Also, machine learning models can be trained to predict the missing parts, rather than regularisation.

    \item This technique performs almost similar to bilateral filtering in denoising images, with a lot more computation overhead.

    \item Algorithm follows three main parameters neighbourhood,number of iterations and time. From our experimentation we observed that neighbourhood size highly affects the regularization and it determines amount of smoothing (directly proportional) and edge preservation (indirectly proportional), number of iteration also determines above mentioned image characteristics but they characteristic change start to converge as the number of iteration increases. the time parameter we observed to be least affecting on result as in a very large t worked as a mean filter and very small t there was no significant regularization on image.

    \item While using PDE for image magnification we didn't obtain desired results when the down sampling ratio is high. The possible reason for this could be that we are applying PDE on image magnified with bi-linear interpolation which doesn't retain global features like edges for high down sampling ratios.

    \item Flow visualization with PDEs doesn't require calculation of Tensor field at each point unlike denoising and inpainting so with vector manipulations in MATLAB we could very efficiently compute it if the Field vector is not dependent on local variations at each pixel.

\end{enumerate}

\begin{thebibliography}{9}
D. Tschumperle ́ and R. Deriche, “Vector-valued image regularization with PDE’s: A common framework for different applications,” IEEE Trans. PAMI, vol. 27, no. 4, pp. 506–517, 2005.
\end{thebibliography}
\end{document}


\chapter{Acknowledgements}
\label{ch:Acknowledgements}
\sloppy

We wish to acknowledge the use of and heritage of some of the source code that we have used to help develop the Ginan.

\subsection{Eclipse Routine}
\noindent The routines to calculate the eclipsing times for GPS satellites were based off the original routines written by Jan Kouba, they have since been heavily modified.

\subsection{JPL Planetary Ephemerides}
\noindent We are using the Jet Propulison (JPL) Planetary and Lunar Ephemerides processing program (\url{ftp://ssd.jpl.nasa.gov/pub/eph/planets/fortran/}), in particular the routines:
\texttt{CONST.f, FSIZER3.f, INTERP.f, PLEPH.f, SPLIT.f}
We have modified the following subroutines:
\texttt{asc2eph.f90, STATE.f90}
so that there is no longer a dependency on a binary file produced in the original JPL form.

\subsection{Standards of Fundamental Astronomy (SOFA) routines}
\noindent We have used a number of routines obtained from SOFA, \url{http://www.iausofa.org/}:
\texttt{anp.for, bi00.for, bpn2xy.for, bpn2xy.for, c2ixys.for, c2tcio.for, cal2jd.for, cp.for, cr.for, era00.for, fad03.for, fae03.for, faf03.for, faju03.for, fal03.for, falp03.for, fama03.for, fame03.for, fane03.for, faom03.for, fapa03.for, fasa03.for, faur03.for, fave03.for, gmst00.for, gmst06.for, gmst\_iers.f03, ir.for, jd2cal.for, jdcalf.for, numat.for, nut00a.for, obl80.for, pn00a.for, pn00.for, pnm00a.for, pnm06a.for, pom00.for, pr00.for, rx.for, rxr.for, ry.for, rz.for, s00.for, s06.for, sp00.for, taiutc.for, tide\_pole\_oc.f90, tide\_pole\_se.f90, time\_GPS.f90, time\_TAI.f90, time\_TT.f90, time\_TT\_sec.f90, time\_UTC.f90, tr.for, xy06.for, xys00a.for, xys06a.for
}

\subsection{International Earth Rotation Service (IERS) routines}
\noindent The following routines we originally sourced from the IERS:
\texttt{interp\_iers.f, CNMTX.F, FUNDARG.F, LAGINT.f, ORTHO\_EOP.F, PMSDNUT2.F, RG\_ZONT2.F, UTLIBR.F, IERS\_CMP\_2015.F}


\section{Introduction}
This assignment involves employing genetic programming and incorporating modularization using automatically defined functions (ADFs) to produce a classifier for postoperative patient diagnosis. In addition, the results of this approach are compared to those produced by a previous genetic programming approach that did not incorporate modularization - see \url{https://github.com/marcus-bornman/cos_710_assignment_2}.

The toolset provided by ECJ \cite{luke2006ecj} - a java-based evolutionary computation research system - was used to construct the genetic programming approach to evolve a population of arrays of trees. The first tree in each array represents the main decision-tree for classifying postoperative patient diagnosis for the patients in the Post-Operative Patient Data Set (available from the UCI Machine Learning repository \cite{Dua:2019}). The rest of the trees in each array represent ADFs.

The aforementioned data set consist of 90 records. The data set was randomly divided into a training set of 70 records and an evaluation set of 20 records. Each record consists of 9 attributes, which can be described as follows:

\begin{itemize}
    \item L-CORE (patient's internal temperature in C):
              high ($>$ 37), mid ($\geq$ 36 and $\leq$ 37), low ($<$ 36)
    \item L-SURF (patient's surface temperature in C):
              high ($>$ 36.5), mid ($\geq$ 36.5 and $\leq$ 35), low ($<$ 35)
    \item L-O2 (oxygen saturation in %):
              excellent ($\geq$ 98), good ($\geq$ 90 and $<$ 98),
              fair ($\geq$ 80 and $<$ 90), poor ($<$ 80)
    \item L-BP (last measurement of blood pressure):
              high ($>$ 130/90), mid ($\leq$ 130/90 and $\geq$ 90/70), low ($<$ 90/70)
    \item SURF-STBL (stability of patient's surface temperature):
              stable, moderate, unstable
    \item CORE-STBL (stability of patient's core temperature)
              stable, moderate, unstable
    \item BP-STBL (stability of patient's blood pressure)
              stable, moderate, unstable
    \item COMFORT (patient's perceived comfort at discharge, measured as
              an integer between 0 and 20)
    \item ADM-DECS (discharge decision):
              I (patient sent to Intensive Care Unit),
              S (patient prepared to go home),
              A (patient sent to general hospital floor)
\end{itemize}

The classification task of this data set is to determine where patients in a postoperative recovery area should be sent to next (the discharge decision). For this assignment, the \emph{COMFORT} attribute is not considered for the classification problem as it contains missing values. So, the classifier will use 7 patient attributes to classify patient's into one of three discharge decisions.

All of the code that was used to employ the genetic algorithm and the information necessary to reproduce the results can be found on github at \url{https://github.com/marcus-bornman/cos_710_assignment_3}.


\documentclass[10pt, a4paper, twocolumn, oneside]{article}

\usepackage[mono]{codebookpkg}

\team{NCTU\_a}{National Chiao Tung University}
\codetheme{default}

\begin{document}

\fontsize{7.2pt}{9pt}\selectfont

\tableofcontents
\newpage

\section{Misc}
    \subsection{Contest}
        \subsubsection{Debug List}
            \inputminted{md}{content/misc/debug-list.txt}
        \subsubsection{Makefile}
            \inputminted{makefile}{content/misc/makefile}
        \subsubsection{Default Code}
            \cppfile{content/misc/default.cpp}
        \subsubsection{acceleration yes}
            \cppfile{content/misc/pragmas.cpp}
        \subsubsection{C++17 constexpr}
            \cppfile{content/misc/constexpr.cpp}
        \subsubsection{Changing Stack Size}
            \cppfile{content/misc/stack-size.cpp}
    \subsection{Utils}
        \subsubsection{SplitMix64}
            \cppfile{content/misc/splitmix64.cpp}
        \subsubsection{Random}
            \cppfile{content/misc/random.cpp}
        \subsubsection{Bit Twiddling}
            \cppfile{content/misc/bit-hacks.cpp}
        \subsubsection{Floating Point Comparison}
            \cppfile{content/misc/epsilon.cpp}
        \subsubsection{Floating Point Binary Search}
            \cppfile{content/misc/float-binary-search.cpp}
    \subsection{Misc Algorithms}
        \subsubsection{Mo's Algorithm on Tree}
            \cppfile{content/misc/mo-tree.cpp}
        \subsubsection{Longest Increasing Subsequence}
            \cppfile{content/misc/lis.cpp}
        \subsubsection{Aliens Trick}
            \cppfile{content/misc/aliens.cpp}

\section{Data Structures}
    \subsection{GNU PBDS}
        \cppfile{content/ds/pbds.cpp}
    \subsection{Segment Tree}
        \cppfile{content/ds/segtree.cpp}
    \subsection{Line Container}
        \cppfile{content/ds/line-container.cpp}
    \subsection{Heavy-Light Decomposition}
        \cppfile{content/ds/hld.cpp}
    \subsection{Link-cut Tree}
        \cppfile{content/ds/lct.cpp}

\section{Math}
    \subsection{Number Theory}
        \subsubsection{Modular}
            \cppfile{content/math/number-theory/modular.cpp}
        \subsubsection{Extended GCD}
            \cppfile{content/math/number-theory/extgcd.cpp}
        \subsubsection{Chinese Remainder}
            \cppfile{content/math/number-theory/crt.cpp}
        \subsubsection{Sieve}
            \cppfile{content/math/number-theory/sieve.cpp}
        \subsubsection{Miller-Rabin}
            \cppfile{content/math/number-theory/miller-rabin.cpp}
        \subsubsection{Pollard's Rho}
            \cppfile{content/math/number-theory/pollard-rho.cpp}
        \subsubsection{Tonelli-Shanks}
            \cppfile{content/math/number-theory/tonelli-shanks.cpp}
        \subsubsection{Baby-Step Giant-Step}
            \cppfile{content/math/number-theory/bsgs.cpp}
        \subsubsection{Multiplicative Function Sum}
            \cppfile{content/math/number-theory/djs.cpp}
    \subsection{Combinatorics}
        \subsubsection{De Brujin Sequence}
            \cppfile{content/math/combinatorics/de-brujin.cpp}
        \subsubsection{Multinomial}
            \cppfile{content/math/combinatorics/multinomial.cpp}
        \subsubsection{Not Burnside's Lemma}
            \input{content/math/combinatorics/burnside.tex}
        \subsubsection{Matroid Intersection}
            \input{content/math/combinatorics/matroid.tex}
    \subsection{Theorems}
        \input{content/math/theorem.tex}

\section{Numeric}
    \subsection{long long Multiplication}
        \cppfile{content/numeric/ll-mul.cpp}
    \subsection{Barrett Reduction}
        \cppfile{content/numeric/barrett-reduction.cpp}
    \subsection{Polynomial Interpolation}
        \cppfile{content/numeric/interpolation.cpp}
    \subsection{Fast Fourier Transform}
        \cppfile{content/numeric/fft.cpp}
    \subsection{Fast Walsh-Hadamard Transform}
        \cppfile{content/numeric/fwht.cpp}
    \subsection{FFT Convolution}
        \cppfile{content/numeric/fftc.cpp}
    \subsection{Linear Recurrence}
        \subsubsection{Calculation}
            \cppfile{content/numeric/linear-recurrence.cpp}
        \subsubsection{Berlekamp-Massey}
            \cppfile{content/numeric/berlekamp-massey.cpp}
        \subsubsection{Composite Modulus Recurrence}
            \cppfile{content/numeric/min25-rec.cpp}
    \subsection{Matrix Determinant}
        \cppfile{content/numeric/det.cpp}
    \subsection{Matrix Inverse}
        \cppfile{content/numeric/inverse.cpp}
    \subsection{Linear Equations}
        \cppfile{content/numeric/linear-eq.cpp}
    \subsection{Simplex}
        \cppfile{content/numeric/simplex.cpp}

\section{Graph}
    \subsection{Modeling}
        \input{content/graph/model.tex}
    \subsection{Flow}
        \subsubsection{Dinic}
            \cppfile{content/graph/flow/dinic.cpp}
        \subsubsection{Gomory-Hu Tree}
            \cppfile{content/graph/flow/gomory-hu.cpp}
        \subsubsection{Global Minimum Cut}
            \cppfile{content/graph/flow/sw.cpp}
        \subsubsection{Min Cost Max Flow}
            \cppfile{content/graph/flow/mcmf.cpp}
    \subsection{Matching}
        \subsubsection{Kuhn-Munkres}
            \cppfile{content/graph/matching/km.cpp}
        \subsubsection{Bipartite Minimum Vertex Cover}
            \cppfile{content/graph/matching/min-bi-cover.cpp}
        \subsubsection{Maximum General Matching}
            \cppfile{content/graph/matching/edmonds.cpp}
        \subsubsection{Min Weight Perfect Matching}
            \cppfile{content/graph/matching/min-weight-general.cpp}
        \subsubsection{Stable Marriage}
            \cppfile{content/graph/matching/marriage.cpp}
    \subsection{Centroid Decomposition}
        \cppfile{content/graph/centroid-decomposition.cpp}
    \subsection{Minimum Mean Cycle}
        \cppfile{content/graph/min-mean-cycle.cpp}
    \subsection{Bellman-Ford}
        \cppfile{content/graph/bellman-ford.cpp}
    \subsection{Directed Minimum Spanning Tree}
        \cppfile{content/graph/dmst.cpp}
    \subsection{Maximum Clique}
        \cppfile{content/graph/clique.cpp}
    \subsection{Tarjan}
        \subsubsection{Strongly Connected Components}
            \cppfile{content/graph/tarjan-scc.cpp}
        \subsubsection{Articulation Point}
            \cppfile{content/graph/tarjan-ap.cpp}
        \subsubsection{Bridge}
            \cppfile{content/graph/tarjan-b.cpp}
    \subsection{2-SAT}
        \cppfile{content/graph/2sat.cpp}
    \subsection{Dominator Tree}
        \cppfile{content/graph/dominator-tree.cpp}
    \subsection{Biconnected Components}
        \cppfile{content/graph/bcc.cpp}
    \subsection{Edge BCC}
        \cppfile{content/graph/edge-bcc.cpp}
    \subsection{Manhattan MST}
        \cppfile{content/graph/manhattan-mst.cpp}
    \subsection{Notes}
        \inputminted{text}{content/graph/notes.txt}

\section{Geometry}
    \subsection{Basic 2D}
        \cppfile{content/geometry/basic-2d.cpp}
    \subsection{Angular Sort}
        \cppfile{content/geometry/angular-sort.cpp}
    \subsection{Convex Hull}
        \cppfile{content/geometry/convex-hull.cpp}
    \subsection{Convex Polygon Point Inclusion}
        \cppfile{content/geometry/convex-inclusion.cpp}
    \subsection{Convex Polygon Minkowski Sum}
        \cppfile{content/geometry/minkowski-sum.cpp}
    \subsection{Closest Pair}
        \cppfile{content/geometry/closest-pair.cpp}
    \subsection{Minimum Enclosing Circle}
        \cppfile{content/geometry/min-circle.cpp}
    \subsection{Half Plane Intersection}
        \cppfile{content/geometry/half-plane.cpp}
    \subsection{Delaunay Triangulation}
        \cppfile{content/geometry/delaunay.cpp}
    \subsection{Spherical Coordinates}
        \cppfile{content/geometry/spherical.cpp}
    \subsection{Quaternion}
        \cppfile{content/geometry/quaternion.cpp}
    \subsection{3D Convex Hull}
        \cppfile{content/geometry/3d-hull.cpp}

\section{Strings}
    \subsection{Z-value}
        \cppfile{content/strings/z-value.cpp}
    \subsection{Manacher}
        \cppfile{content/strings/manacher.cpp}
    \subsection{Minimum Rotation}
        \cppfile{content/strings/min-rotation.cpp}
    \subsection{Aho-Corasick}
        \cppfile{content/strings/ahocorasick.cpp}
    \subsection{Suffix Array}
        \cppfile{content/strings/suffix-array.cpp}
    \subsection{Suffix Tree}
        \cppfile{content/strings/suffix-tree.cpp}

\end{document}


\section{Results}
\label{sec:results}

Statistical significance was achieved between our test case and our baseline regardless of whether we used random selection or parameter means. Between these two methods, taking the mean showed better accuracy, though not significantly so. Results varied between workflow runs but we observed differences in effect that increased the ending loss by as much as 5\% compared to the control and that decreased the ending loss as much as 20\%.
There is little improvement after merging the networks following a short amount of time, however, there is significant improvement (including a quicker convergence) following a merge of two well-trained networks.
Though overall results were significant, we have observed bias in our testing towards partially trained models with similar parameter values. This aligns with our initial thoughts regarding the structure and shape of the parameter search space. Namely, for two local optima, it is not unlikely that another local optimum exists in a location between the two prior values.
\begin{figure}[h!]
\includegraphics[width=\linewidth]{figures/loss.png}
\caption{Mean loss across 5 trial runs comparing the use of cross-over.}
\label{fig:results}
\end{figure}


\documentclass{article} % For LaTeX2e
\usepackage{times}
\usepackage{hyperref}
\usepackage{url}

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}

\usepackage[T1]{fontenc}

\title{Efficient Calculation of Polynomial Features on Sparse Matrices}

%\author{Andrew Nystrom \\
%Savvysherpa Inc.\\
%6200 Shingle Creek Pkwy \\
%Suite 400 \\
%Minneapolis, MN 55430, USA \\
%\texttt{awnystrom@gmail.com} \\
%\And
%John F. Hughes \\
%Department of Computer Science \\
%Brown University \\
%Providence, RI \\
%\texttt{jfh@cs.brown.edu} \\
%}

\author{
  Nystrom, Andrew\\
  \texttt{awnystrom@gmail.com}
  \and
  Hughes, John\\
  \texttt{jfh@cs.brown.edu}
}

% The \author macro works with any number of authors. There are two commands
% used to separate the names and addresses of multiple authors: \And and \AND.
%
% Using \And between authors leaves it to \LaTeX{} to determine where to break
% the lines. Using \AND forces a linebreak at that point. So, if \LaTeX{}
% puts 3 of 4 authors names on the first line, and the last on the second
% line, try using \AND instead of \And before the third author name.

%\newcommand{\fix}{\marginpar{FIX}}
%\newcommand{\new}{\marginpar{NEW}}

\begin{document}

\maketitle

\begin{abstract}
We provide an algorithm for polynomial feature expansion that operates directly on a sparse matrix.
For a vector of dimension $D$ and density $d$, the algorithm has time and space complexity $O(d^kD^k)$ where $k$ is the polynomial order.
\end{abstract}

% this is a test-change for Spike to see whether Git seems to work for him. Ignore.

\section{Introduction}

Polynomial feature expansion has long been used in statistics to approximate nonlinear functions~\cite{gergonne1974application, smith1918standard}.
Despite this, we are unaware of any efforts to optimize calculating them.
Here we provide an algorithm for calculating polynomial features for a vector of dimension $D$ and density $d$ with time and space complexity $O(d^kD^k)$ where $k$ is the polynomial order, and $0 \le d \le 1$ is the fraction of elements that are nonzero.
The standard algorithm has time and space complexity $O(D^k)$, so the added factor of $d^k$ represents a significant complexity reduction.
The algorithm avoids densification of the vector, i.e. the vector remains in compressed sparse row form, so the space complexity is also $O(d^kD^k)$ as opposed to $O(D^k)$.

\section{Algorithm}
In the naive computation of polynomial features for a vector $\vec{x}$, we create a new feature for each product (with repetition) of $k$ features in $\vec{x}$ (or without repetition, for ``interaction features'').
This ignores data sparsity and will yield a product of zero any time one of the features involved in the product is zero.
In a sparse matrix, such zero-products are common.
%If $\vec{x}$ has density $d$, the fraction of nonzero elements of the $k$-order expansion will be $\frac{\left(\binom{dD+k-1}{k}\right)}{\left(\binom{D+k-1}{k}\right)} = \frac{[(dD+k-1)(dD+k-2) \dots (dD+k)](D-1)!}{(dD-1)!} = $
If we store vectors in a sparse matrix format, these zero-products need not be computed or stored.

The main idea behind our algorithm is to leverage sparsity by only computing products that do not involve zeros.
In a compressed sparse row matrix, the columns containing nonzero data are the only columns that are stored.
We can therefore iterate over products of combinations with repetition of order $k$ of \emph{only these columns} for each row to calculate $k$-degree polynomial features.

While the idea is straightforward, there is yet an unaddressed challenge:
Given a multiset of column indices whose corresponding nonzero components were multiplied to produce a polynomial feature, where in the augmented polynomial vector does the result of the product belong?
To address this, we give a bijective mapping from the set of possible column index combinations-with-repetition of order $k$ onto the column index space of the polynomial feature matrix. Thus the map has the form

\begin{equation}
(i_0, i_1, \dots, i_{k-1}) \rightarrowtail \hspace{-1.9ex} \twoheadrightarrow p_{i_0i_1 \dots i_{k-1}} \in \{0,1,\dots,\binom{D}{k}\}
\end{equation}
such that $ 0 \le i_0 \le i_1 \le \dots \le i_{k-1} < D$
where $(i_0, i_1, \dots, i_{k-1})$ are column indicies of a row vector $\vec{x}$ of an $N \times D$ input matrix, and $p_{i_0i_1 \dots i_{k-1}}$ is a column index into the polynomial expansion vector for $\vec{x}$ where the product of elements corresponding to indices $i_0, i_1, \dots, i_{k-1}$ will be stored.
%and $\left(\binom{D}{k}\right)$ is the number of combinations with repetition of size $k$ drawn from $D$ objects.
%In general, $\left(\binom{n}{k}\right) = \binom{n+k-1}{n-1} = \binom{n+k-1}{k}$, as given by \cite{stanley1986enumerative}.

\subsection{Construction of Mappings}

For the second degree case, we seek a map from matrix indices $(i, j)$ (with $0 \le i < j < D$ ) to numbers $f(i, j)$ with $0 \le f(i, j) < \frac{D(D-1)}{2}$, one that follows the pattern indicated by
\begin{align}
\begin{bmatrix}
x & 0 & 1 & 3 \\
x & x & 2 & 4 \\
x & x & x & 5 \\
x & x & x & x
\end{bmatrix}
\label{eq:4x4mat}
\end{align}
where the entry in row $i$, column $j$, displays the value $f(i, j)$. We let $T_2(n) = \frac{1}{2} n(n+1)$
be the $n$th triangular number; then in Equation~\ref{eq:4x4mat}, column $j$ (for $j > 0$) contains entries with
$T_2(j-1) \le e < T_2(j)$; the entry in the $i$th row is just $i + T_2(j-1)$. Thus we have
$
f(i, j)
= i + T_2(j-1) =  \frac{1}{2}(2i + j^2-j).$
For instance, in column $j = 2$ in our example (the \emph{third} column), the entry in row $i = 1$ is
$i + T_2(j-1) = 1 + 1 = 2$.

With one-based indexing in both the domain and codomain, the formula above becomes
$f_1(i, j)  = \frac{1}{2}(2i + j^2 - 3j + 2).$

For \emph{polynomial} features, we seek a similar map $g$, one that also handles the case $i = j$. In this case, a similar analysis yields
$ g(i, j) = i + T_2(j) = \frac{1}{2} (2i + j^2 + j + 1).$

To handle \emph{three-way interactions}, we need to map triples of indices in a 3-index array to a flat list, and similarly for higher-order interactions. For this, we'll need the tetrahedral numbers $T_3(n) = \sum_{i=1}^n T_{2}(n) =
\frac{1}{6}(n^3 + 3n^2 + 2n)$.

For three indices, $i,j,k$, with $0 \le i < j < k < D$, we have a similar recurrence. Calling the mapping $h$, we have
\begin{align}
h(i,j,k) = i + T_2(j-1) + T_3(k-2);
\end{align}
if we define $T_1(i) = i$, then this has the very regular form
\begin{align}
h(i,j,k) =  T_1(i) + T_2(j-1) + T_3(k-2);
\end{align}
and from this the generalization to higher dimensions is straightforward. The formulas for ``higher triangular numbers'', i.e., those defined by
\begin{align}
T_k(n) &= \sum_{i=1}^n T_{k-1}(n)
\end{align}
for $k > 1$ can be determined inductively.

The explicit formula for 3-way interactions, with zero-based indexing, is
\begin{align}
h(i, j, k) &= 1 + (i-1) + \frac{(j-1)j}{2} + \\
& \frac{(k-2)^3 + 3(k-2)^2 + 2(k-2)}{6}.
\end{align}

\section{Complexity Analysis}
%\subsection{Analytical}

Calculating $k$-degree polynomial features via our method for a vector of dimensionality $D$ and density $d$ requires $\binom{dD}{k}$ (with repetition) products.
The complexity of the algorithm, for fixed $k \ll dD$, is therefore
\begin{align}
O\left(\binom{dD+k-1}{k}\right) & = O\left(\frac{(dD+k-1)!}{k!(dD-1)!}\right)\\
& = O\left(\frac{(dD+k-1)(dD+k-2) \dots (dD)}{k!}\right)\\
& = O\left((dD+k-1)(dD+k-2) \dots (dD)\right) \mbox{ for } k \ll dD\\
& = O\left(d^kD^k\right)
\end{align}

%\subsection{Empirical}
%\section{Conclusion}

\bibliography{sparse_poly}
\bibliographystyle{iclr2016_workshop}

\end{document}


\documentclass[parskip=half]{scrartcl}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[citestyle=authoryear-icomp,bibstyle=authoryear]{biblatex}
\usepackage{booktabs}
\usepackage[style=british]{csquotes}
\usepackage{fontspec}
\usepackage{siunitx}

\setmainfont[Numbers=Lowercase]{TeX Gyre Pagella}
\newfontfamily\dispfamily{TeX Gyre Pagella}
\addtokomafont{disposition}{\dispfamily}

\MakeAutoQuote{«}{»}
\DeclareMathOperator{\Res}{Res}

\addbibresource{cable.bib}

\title{Analytic solution to passive cable model}
\author{Sam Yates}
\date{October 20, 2016}

\begin{document}

\maketitle

\section{Background}

The Rallpack suite \parencite{bhalla1992} is a set of three tests for cable-based neuronal
simulators, for validation and benchmarking. Validation data is provided with the
distribution of the suite, which at the time of writing can now be found within the
\textsc{Genesis} simulator simulator distribution.\footnote{see \url{http://genesis-sim.org}.}

The first two of the tests are based on passive cable models which admit analytic
solutions, and the Rallpack suite includes code that can generate the reference curves
for these models. The reference code, however, requires hand-tuning of the iterations;
the authors state in the internal documentation that
«the use of 10 terms gives at least six figure accuracy», but this is for the
fixed time increments used in their dataset and is not validated within the code
or by the supplied material.

For flexibility of testing and cross-checking of the Rallpack reference data,
it would be useful to have at hand a robust calculator of the passive cable
potential solution.

\section{The Rallpack 1 model}

The model comprises a cylindrical cable segment with the physical and electrical
properties as described in Table~\ref{tbl:rallpack1}. A current of \SI{0.1}{\nA}
is injected at the left end of the cable from $t=0$, and the initial potential
is the reversal potential.

\begin{table}[ht]
    \centering
    \begin{tabular}{lSl}
        \toprule
        Term & {Value} & Property\\
        \midrule
        $d$    & \SI{1.0}{\um}                 & cable diameter \\
        $L$    & \SI{1.0}{\mm}                 & cable length \\
        $R_A$  & \SI{1.0}{\ohm\m}              & bulk axial resistivity \\
        $R_M$  & \SI{4.0}{\ohm\m\squared}      & areal membrane resistivity \\
        $C_M$  & \SI{0.01}{\F\per\m\squared}   & areal membrane capacitance \\
        $E_M$  & \SI{-65.0}{\mV}               & membrane reversal potential \\
        \bottomrule
    \end{tabular}
    \caption{Cable properties for the Rallpack 1 model.}
    \label{tbl:rallpack1}
\end{table}

The potential on a constant-radius passive cable is governed by the PDE
\begin{equation}
    \lambda^2 \frac{\partial^2 v}{\partial x^2} =
    \tau\frac{\partial v}{\partial t} + v - E,
\end{equation}
where $E$ is the membrane reversal potential, and $\lambda$ and $\tau$ are the
electrotonic length and time constants for the cable. It is convenient
to consider the electrical properties of the cable per unit-length, in terms
of the linear axial resistivity $r$, the linear membrane capacitance $r$,
and the linear membrane capacitance $c$. These determine $\lambda$ and $\tau$ by
\begin{gather*}
    \lambda = \frac{1}{r\cdot g},\\
    \tau = r\cdot c.
\end{gather*}

With the model boundary conditions,
\begin{subequations}
    \begin{align}
        v(x, 0) &= E, \\
        \left.\frac{\partial v}{\partial x}\right\vert_{x=0} & = -Ir, \\
         \left.\frac{\partial v}{\partial x}\right\vert_{x=L} & = 0,
    \end{align}
\end{subequations}
where $I$ is the injected current and $L$ is the cable length.

The solution $v(x, t)$ can be expressed in terms of the solution $g(x, t; L)$
to a normalized version of the cable equation,
\begin{subequations}
    \begin{align}
        \label{eq:normcable}
        \frac{\partial^2 g}{\partial x^2} & =
        \frac{\partial g}{\partial t} + g,
        \\
        \label{eq:normcableinitial}
        g(x, 0) &= 0,
        \\
        \label{eq:normcableleft}
        \left.\frac{\partial g}{\partial x}\right\vert_{x=0} & = 1,
        \\
        \label{eq:normcableright}
        \left.\frac{\partial g}{\partial x}\right\vert_{x=L} & = 0
    \end{align}
\end{subequations}
by
\begin{equation}
    v(x, t)= E - Ir\lambda \cdot g(\frac{x}{\lambda}, \frac{t}{\tau};  \frac{L}{\lambda}).
\end{equation}

\section{Solution to the normalized cable equation}

Let $G(x, s)$ be the Laplace transform of $g(x, t)$ with respect to $t$.
If the inverse transform of $G$ exists, it must agree with $g$ almost everywhere
for $t>0$, or for all $t>0$ given the continuity of $g$.

From
\eqref{eq:normcable} and \eqref{eq:normcableinitial},
\begin{equation}
    \label{eq:lap}
    \frac{\partial^2 G}{\partial x^2} = sG + G.
\end{equation}
The boundary conditions \eqref{eq:normcableleft} and \eqref{eq:normcableright} give
\begin{align}
    \label{eq:lapleft}
    \frac{\partial G}{\partial x}(0, s) & = \frac{1}{s}
    \\
    \label{eq:lapright}
    \frac{\partial G}{\partial x}(L, s) & = 0.
\end{align}

Solutions to \eqref{eq:lap} must be of the form
\begin{equation}
    G(x, s) = A(s) e^{mx} +B(s) e^{-mx}
\end{equation}
where $m=\sqrt{1+s}$. From \eqref{eq:lapleft} and \eqref{eq:lapright},
\begin{align*}
    mA(s) - mB(s) & = \frac{1}{s}
    \\
    mA(s)e^{mL} -mB(s)e^{-mL} & = 0
\end{align*}
and thus
\begin{align*}
    A(s) & = \frac{1}{sm (1-e^{2mL})}
    \\
    B(s) & = \frac{e^{2mL}}{sm (1-e^{2mL})}.
\end{align*}

Consequently,
\begin{equation}
    \begin{aligned}
        G(x, s) &= \frac{1}{ms}\cdot\frac{e^{mx}+e^{2mL-mx}}{1-e^{2mL}}\\
                &= - \frac{1}{ms}\cdot\frac{\cosh m(L-x)}{\sinh mL}.
    \end{aligned}
\end{equation}

\subsection*{Inversion}

Sufficient conditions for the inverse transform of $G(x,s)$ to exist
and be representable in series form are as follows
\parencite[][Theorem 4]{churchill1937}:
\begin{enumerate}
\item
    $G(x, s)$ is analytic in some right half-plane $H$,
\item
    the singularities of $G(x, s)$ are all poles, and
\item for some $k>1$, $|s^k G(x, s)|$ is bounded in $H$ and
    on the circles $|s|=\rho_i$, where $\rho_i$ is an unbounded monotonically
    increasing sequence.
\end{enumerate}
If in addition all the poles $\sigma_j$ of $G$ are simple, then
the series expansion of the inverse transform is given by
\begin{equation}
    g(x,t) = \sum_j e^{\sigma_j t}\, \Res(G;\sigma_j),\quad t>0.
\end{equation}

$G(x,s)$ has poles when $s=0$, $m=0$, or $\sinh mL=0$.
In the following, let
\begin{gather*}
    a_k = k\pi /L\\
    m_k = a_k i\\
    s_k = m_k^2 -1 = -k^2\pi^2/L^2-1.
\end{gather*}
for $k\in\mathbb{Z}$.
The poles are then $0$, $-1$, and $s_k$ for $k\geq 1$.

There are no branch points
arising from $m=\sqrt{1+s}$, as letting $m=-\sqrt{1+s}$ leaves $G$ unchanged.

For $|s+1|>\epsilon$,
\begin{equation}
    \begin{aligned}
        |s^{3/2}G(x,s)|^2
            & \leq (1+\epsilon)^{-1} \left| \frac{\cosh m(L-x)}{\sinh mL} \right|^2
        \\
            & \leq (1+\epsilon)^{-1} (1+|\coth mL|)^2
    \label{eq:gbounds}
    \end{aligned}
\end{equation}
which is bounded in the half-plane $\Re(s) \geq  -1+\epsilon$.
As $\coth u+iv$ is periodic in $v$, \eqref{eq:gbounds} is also bounded outside
the regions $\{s: m\in D_k\}$, where $D_k$ are non-overlapping $\delta$-neighborhoods of $m_k$
for some fixed small $\delta>0$. These are contained within disks of radius
$2k\pi\delta/L+\delta^2$ about $s_k$ for $k\geq 1$, which then are separated by
circles $|s|=\rho_k$ about the origin for some $\rho_k$ in $(|s_k|, |s_k+1|)$.

\textbf{Pole at $s=0$}.\\
Recalling $m=\sqrt{1+s}$, $m$ and $\sinh mL$ are non-zero in
a neighbourhood of $s=0$, and so the pole is simple and
\begin{equation}
    \begin{aligned}
        \Res(G; 0) & = - \frac{1}{m}\cdot\left.\frac{\cosh m(L-x)}{\sinh mL}\right|_{s=0}\\
                   & = - \frac{\cosh (L-x)}{\sinh L}.
    \end{aligned}
\end{equation}

\textbf{Pole at $s=-1$}.\\
Let $G(x,s)=f(x,s)/h(s)$, where
\begin{equation}
    \begin{aligned}
        f(x, s) &= -\frac{1}{s}\cosh m(L-x)\\
        h(s) &= m\sinh mL.
    \end{aligned}
    \label{eq:hf}
\end{equation}
Noting that $dm/ds = \frac{1}{2}m^{-1}$,
\begin{equation}
    \begin{aligned}
        h'(s) &= \frac{1}{2}m^{-1}\sinh mL + \frac{1}{2}L\cosh mL \\
              &= \frac{1}{2}L + \frac{1}{2}L + O(m^2) \quad(m\to 0) \\
              &= L + O(s+1) \quad(s\to -1).
    \label{eq:hprime}
    \end{aligned}
\end{equation}
The pole is therefore simple, and
\begin{equation}
    \Res(G; -1) = f(x, -1)/h'(-1) = -\frac{1}{L}.
\end{equation}

\textbf{Pole at $s=s_k$, $k \geq 1$}.\\
Taking $h$ and $f$ as above \eqref{eq:hf},
$m_k$ is non-zero for $k\geq 1$ and
\[
    h'(s_k) = \frac{1}{2}L\cosh m_kL.
\]
Consequently the pole is simple and
\begin{equation}
    \begin{aligned}
        \Res(G; s_k)
            & = f(x, s_k)/h'(s_k)\\
            & =  -\frac{2}{s_k L}\frac{\cosh m_k(L-x)}{\cosh m_kL} \\
            & =  -\frac{2}{s_k L}\frac{\cosh m_kL\cosh m_kx-\sinh m_kL\sinh m_kL}{\cosh m_kL} \\
            & =  -\frac{2}{s_k L}\cosh m_k x,
    \end{aligned}
\end{equation}
as $\sinh m_k=0$.

In terms of $a_k$,
\begin{equation}
    \Res(G; s_k) = \frac{2}{L}\cdot\frac{1}{1+a_k^2}\cdot\cos a_kx.
\end{equation}

The series exapnsion for $g(x, t)$ therefore is
\begin{equation}
    g(x, t) = -\frac{\cosh(L-x)}{\sinh L} + \frac{1}{L}e^{-t}\left\{
        1+2\sum_{k=1}^\infty \frac{e^{-ta_k^2}}{1+a_k^2}\cos a_k x\right\}.
    \label{eq:theg}
\end{equation}

\section{Computation of series}

As $t$ approaches zero, the series \eqref{eq:theg} converges increasingly slowly.
For computational purposes, an estimate on the series residual allows the determination
of stopping criteria for a given tolerance.

Let $g_n$ be the partial sum
\begin{equation}
    g_n(x, t) = -\frac{\cosh(L-x)}{\sinh L} + \frac{1}{L}e^{-t}\left\{
        1+2\sum_{k=1}^n \frac{e^{-ta_k^2}}{1+a_k^2}\cos a_k x\right\}.
\end{equation}
so that $g(x, t) =\lim_{n\to\infty} g_n(x,t)$. Let $\bar{g}_n = |g-g_n|$ be the
residual. The $a_k$ form an increasing sequence, so
\begin{equation}
    \begin{aligned}
        \bar{g}_n(x,t)
            & \leq \frac{2}{L}e^{-t}\sum_{n+1}^\infty\frac{e^{-ta_k^2}}{1+a_k^2}\\
            & \leq \frac{2}{L}e^{-t}\int_{a_n}^\infty \frac{e^{-tu^2}}{1+u^2}\,du\\
            & < \frac{2}{L}e^{-t}\int_{a_n}^\infty \frac{e^{-tu^2}}{u^2}\,du.
    \end{aligned}
    \label{eq:gbar}
\end{equation}
Substituting $u=\sqrt{v/t}$ gives the identity
\begin{equation}
    \int_{a}^\infty \frac{e^{-tu^2}}{u^2}\,du
    = \frac{1}{2}\sqrt{t}\int_{a^2t}^\infty e^{-tv} v^{\frac{-3}{2}}\,dv
    = \frac{1}{2}\sqrt{t}\,\Gamma(-\frac{1}{2},a^2 t),
\end{equation}
where $\Gamma(\alpha, z)$ is the upper incomplete gamma function.

For real $\alpha<1$ and $z>0$, \textcite[][Theorem 2.3]{borwein2009} give the upper bound
\[
    \Gamma(\alpha, z) \leq z^{\alpha-1} e^{-z}.
\]
Substituting into \eqref{eq:gbar} gives
\begin{equation}
    \begin{aligned}
        \bar{g}_n(x,t)
            & < \frac{1}{L}e^{-t}\sqrt{t}\,\Gamma(-\frac{1}{2},a_n^2 t) \\
            & \leq \frac{1}{L}e^{-t}\sqrt{t}\,(a_n^2 t)^{-\frac{3}{2}}e^{-a_n^2t} \\
            & = \frac{e^{-t(1+a_n^2)}}{L t a_n^3}.
    \end{aligned}
\end{equation}

\printbibliography
\end{document}


\subsection{Experiments}

\subsubsection{MNIST}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%MNIST%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%MNIST%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{2x, Five Layer, adagrad, hessian uniform}
%\input{mnist_five_2_adg_heu.tex}
\noindent This section provides comprehensive study on the choice of mini batch size, its relationship with number of classes in classification task.
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_FiveLayer_20B_0E_adagrad_he_u.csv}\dnwtwoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_FiveLayer_40B_0E_adagrad_he_u.csv}\dnwfooptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_FiveLayer_60B_0E_adagrad_he_u.csv}\dnwsxoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_FiveLayer_80B_0E_adagrad_he_u.csv}\dnwegoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_FiveLayer_100B_0E_adagrad_he_u.csv}\dnwhnoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_FiveLayer_120B_0E_adagrad_he_u.csv}\dnwhntwoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_FiveLayer_140B_0E_adagrad_he_u.csv}\dnwhnfooptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_FiveLayer_160B_0E_adagrad_he_u.csv}\dnwhnsxoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_FiveLayer_180B_0E_adagrad_he_u.csv}\dnwhnegoptinit

\providecommand{\initerr}{Error for initial epochs}
\providecommand{\initacc}{Accuracy for initial epcohs}
\providecommand{\lateerr}{Error for later epochs}
\providecommand{\lateacc}{Accuracy for later epochs}
\providecommand{\boxerr}{Error variation}
\providecommand{\boxacc}{Accuracy variation}

\providecommand{\initfigtitle}{Different batch results for starting 15 epochs }
\providecommand{\initcaption}{The initial epochs seen shows that 2x batch size(2x batch size=2*number of classes) started with the lowest error(a) as well as best accuracy(b), surprisingly 8x batch size started quite well inspite of less network updates in an epoch.
	Then till 15 epochs it is mixed results and no batch size cannot be singled out as a best performer.}

\providecommand{\latefigtitle}{Different batch results for later epochs}
\providecommand{\latecaption}{8x started well but in late epochs it could not sustain the start, Another good perfromance is shown by 10x which has reached quite good accuracy but its error become high and entered overfitting regime, 2x performance in error as well as accuracy side remain quite robust.}

\providecommand{\boxerraccfigtitle}{accuracy and error plot for full training epochs}
\providecommand{\boxerracccaption}{4x perform quite well as error remain with in small range, but on high side, 16x and 18x have low error regime as their minimum error but their variance range is on higher side, 10x shows quite good accuracy and has its maximum value is maximum among all other batch sizes, while its error had high variance than 2x. 2x is consistent in both low error with less vairance as well as accuracy. Low error makes 2x a robust classifier.}

\providecommand{\trtscaption}{2x shows quite good performance}
\providecommand	{\ymaxlim}{0.99}

\input{batch_init_epochs.tex}
\input{batch_box_plots.tex}
\input{batch_late_epochs.tex}
\input{batch_train_test_plots.tex}

\pgfplotstableclear{\dnwtwoptinit}
\pgfplotstableclear{\dnwfooptinit}
\pgfplotstableclear{\dnwsxoptinit}
\pgfplotstableclear{\dnwegoptinit}
\pgfplotstableclear{\dnwhnoptinit}
\pgfplotstableclear{\dnwhntwoptinit}
\pgfplotstableclear{\dnwhnfooptinit}
\pgfplotstableclear{\dnwhnsxoptinit}
\pgfplotstableclear{\dnwhnegoptinit}

\paragraph{2x, Three Layer, adagrad, hessian uniform}
results for three layer

\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_ThreeLayer_20B_0E_adagrad_he_u.csv}\dnwtwoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_ThreeLayer_40B_0E_adagrad_he_u.csv}\dnwfooptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_ThreeLayer_60B_0E_adagrad_he_u.csv}\dnwsxoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_ThreeLayer_80B_0E_adagrad_he_u.csv}\dnwegoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_ThreeLayer_100B_0E_adagrad_he_u.csv}\dnwhnoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_ThreeLayer_120B_0E_adagrad_he_u.csv}\dnwhntwoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_ThreeLayer_140B_0E_adagrad_he_u.csv}\dnwhnfooptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_ThreeLayer_160B_0E_adagrad_he_u.csv}\dnwhnsxoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_ThreeLayer_180B_0E_adagrad_he_u.csv}\dnwhnegoptinit

\renewcommand{\initerr}{Error for initial epochs-revisited}
\renewcommand{\initacc}{Accuracy for initial epcohs}
\renewcommand{\lateerr}{Error for later epochs}
\renewcommand{\lateacc}{Accuracy for later epochs}
\renewcommand{\boxerr}{Error variation}
\renewcommand{\boxacc}{Accuracy variation}

\providecommand{\initfigtitle}{Different batch results for starting 15 epochs }
\providecommand{\initcaption}{The initial epochs seen shows that 2x batch size(2x batch size=2*number of classes) started with the lowest error(a) as well as best accuracy(b), surprisingly 8x batch size started quite well inspite of less network updates in an epoch.
	Then till 15 epochs it is mixed results and no batch size cannot be singled out as a best performer.}

\providecommand{\latefigtitle}{Different batch results for later epochs}
\providecommand{\latecaption}{8x started well but in late epochs it could not sustain the start, Another good perfromance is shown by 10x which has reached quite good accuracy but its error become high and entered overfitting regime, 2x performance in error as well as accuracy side remain quite robust.}

\providecommand{\boxerraccfigtitle}{accuracy and error plot for full training epochs}
\providecommand{\boxerracccaption}{4x perform quite well as error remain with in small range, but on high side, 16x and 18x have low error regime as their minimum error but their variance range is on higher side, 10x shows quite good accuracy and has its maximum value is maximum among all other batch sizes, while its error had high variance than 2x. 2x is consistent in both low error with less vairance as well as accuracy. Low error makes 2x a robust classifier.}

\renewcommand{\trtscaption}{2x shows quite good performance}

\renewcommand{\initerr}{Error for initial epochs-revisited}
\renewcommand{\ymaxlim}{0.98}

\input{batch_init_epochs.tex}
\input{batch_box_plots.tex}
\input{batch_late_epochs.tex}
%\input{batch_train_test_plots.tex}

\pgfplotstableclear{\dnwtwoptinit}
\pgfplotstableclear{\dnwfooptinit}
\pgfplotstableclear{\dnwsxoptinit}
\pgfplotstableclear{\dnwegoptinit}
\pgfplotstableclear{\dnwhnoptinit}
\pgfplotstableclear{\dnwhntwoptinit}
\pgfplotstableclear{\dnwhnfooptinit}
\pgfplotstableclear{\dnwhnsxoptinit}
\pgfplotstableclear{\dnwhnegoptinit}

\paragraph{Two Layer, adagrad, hessian uniform}

results for two layer

\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_TwoLayer_20B_0E_adagrad_he_u.csv}\dnwtwoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_TwoLayer_40B_0E_adagrad_he_u.csv}\dnwfooptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_TwoLayer_60B_0E_adagrad_he_u.csv}\dnwsxoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_TwoLayer_80B_0E_adagrad_he_u.csv}\dnwegoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_TwoLayer_100B_0E_adagrad_he_u.csv}\dnwhnoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_TwoLayer_120B_0E_adagrad_he_u.csv}\dnwhntwoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_TwoLayer_140B_0E_adagrad_he_u.csv}\dnwhnfooptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_TwoLayer_160B_0E_adagrad_he_u.csv}\dnwhnsxoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/mnist_TwoLayer_180B_0E_adagrad_he_u.csv}\dnwhnegoptinit

\renewcommand{\initerr}{Error for initial epochs-revisited}
\renewcommand{\initacc}{Accuracy for initial epcohs}
\renewcommand{\lateerr}{Error for later epochs}
\renewcommand{\lateacc}{Accuracy for later epochs}
\renewcommand{\boxerr}{Error variation}
\renewcommand{\boxacc}{Accuracy variation}

\providecommand{\initfigtitle}{Different batch results for starting 15 epochs }
\providecommand{\initcaption}{The initial epochs seen shows that 2x batch size(2x batch size=2*number of classes) started with the lowest error(a) as well as best accuracy(b), surprisingly 8x batch size started quite well inspite of less network updates in an epoch.
	Then till 15 epochs it is mixed results and no batch size cannot be singled out as a best performer.}

\providecommand{\latefigtitle}{Different batch results for later epochs}
\providecommand{\latecaption}{8x started well but in late epochs it could not sustain the start, Another good perfromance is shown by 10x which has reached quite good accuracy but its error become high and entered overfitting regime, 2x performance in error as well as accuracy side remain quite robust.}

\providecommand{\boxerraccfigtitle}{accuracy and error plot for full training epochs}
\providecommand{\boxerracccaption}{4x perform quite well as error remain with in small range, but on high side, 16x and 18x have low error regime as their minimum error but their variance range is on higher side, 10x shows quite good accuracy and has its maximum value is maximum among all other batch sizes, while its error had high variance than 2x. 2x is consistent in both low error with less vairance as well as accuracy. Low error makes 2x a robust classifier.}

\renewcommand{\trtscaption}{2x shows quite good performance}

\renewcommand{\initerr}{Error for initial epochs-2}
\renewcommand{\ymaxlim}{0.99}

\input{batch_init_epochs.tex}
\input{batch_box_plots.tex}
\input{batch_late_epochs.tex}
%\input{batch_train_test_plots.tex}

\pgfplotstableclear{\dnwtwoptinit}
\pgfplotstableclear{\dnwfooptinit}
\pgfplotstableclear{\dnwsxoptinit}
\pgfplotstableclear{\dnwegoptinit}
\pgfplotstableclear{\dnwhnoptinit}
\pgfplotstableclear{\dnwhntwoptinit}
\pgfplotstableclear{\dnwhnfooptinit}
\pgfplotstableclear{\dnwhnsxoptinit}
\pgfplotstableclear{\dnwhnegoptinit}
\relax

\subsubsection{CIFAR100}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CIFAR100%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CIFAR100%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pgfplotstableread[col sep = comma]{ResultsNormal/cifar100_TwoLayer_200B_0E_adagrad_he_u.csv}\dnwtwoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar100_TwoLayer_400B_0E_adagrad_he_u.csv}\dnwfooptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar100_TwoLayer_600B_0E_adagrad_he_u.csv}\dnwsxoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar100_TwoLayer_800B_0E_adagrad_he_u.csv}\dnwegoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar100_TwoLayer_1000B_0E_adagrad_he_u.csv}\dnwhnoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar100_TwoLayer_1200B_0E_adagrad_he_u.csv}\dnwhntwoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar100_TwoLayer_1400B_0E_adagrad_he_u.csv}\dnwhnfooptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar100_TwoLayer_1600B_0E_adagrad_he_u.csv}\dnwhnsxoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar100_TwoLayer_1800B_0E_adagrad_he_u.csv}\dnwhnegoptinit

\renewcommand{\initerr}{Error for initial epochs-revisited}
\renewcommand{\initacc}{Accuracy for initial epcohs}
\renewcommand{\lateerr}{Error for later epochs}
\renewcommand{\lateacc}{Accuracy for later epochs}
\renewcommand{\boxerr}{Error variation}
\renewcommand{\boxacc}{Accuracy variation}

\providecommand{\initfigtitle}{Different batch results for starting 15 epochs-cifar10 }
\providecommand{\initcaption}{The initial epochs seen shows that 2x batch size(2x batch size=2*number of classes) started with the lowest error(a) as well as best accuracy(b), surprisingly 8x batch size started quite well inspite of less network updates in an epoch.
	Then till 15 epochs it is mixed results and no batch size cannot be singled out as a best performer.}

\providecommand{\latefigtitle}{Different batch results for later epochs}
\providecommand{\latecaption}{8x started well but in late epochs it could not sustain the start, Another good perfromance is shown by 10x which has reached quite good accuracy but its error become high and entered overfitting regime, 2x performance in error as well as accuracy side remain quite robust.}

\providecommand{\boxerraccfigtitle}{accuracy and error plot for full training epochs}
\providecommand{\boxerracccaption}{4x perform quite well as error remain with in small range, but on high side, 16x and 18x have low error regime as their minimum error but their variance range is on higher side, 10x shows quite good accuracy and has its maximum value is maximum among all other batch sizes, while its error had high variance than 2x. 2x is consistent in both low error with less vairance as well as accuracy. Low error makes 2x a robust classifier.}

\renewcommand{\trtscaption}{2x shows quite good performance}

\renewcommand{\initerr}{Error for initial epochs-2}
\renewcommand{\ymaxlim}{0.20}

\input{batch_init_epochs.tex}
\input{batch_box_plots.tex}
\input{batch_late_epochs.tex}
%\input{batch_train_test_plots.tex}

\subsubsection{CIFAR10}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CIFAR100%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CIFAR100%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pgfplotstableread[col sep = comma]{ResultsNormal/cifar10_TwoLayer_20B_0E_adagrad_he_u.csv}\dnwtwoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar10_TwoLayer_40B_0E_adagrad_he_u.csv}\dnwfooptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar10_TwoLayer_60B_0E_adagrad_he_u.csv}\dnwsxoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar10_TwoLayer_80B_0E_adagrad_he_u.csv}\dnwegoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar10_TwoLayer_100B_0E_adagrad_he_u.csv}\dnwhnoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar10_TwoLayer_120B_0E_adagrad_he_u.csv}\dnwhntwoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar10_TwoLayer_140B_0E_adagrad_he_u.csv}\dnwhnfooptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar10_TwoLayer_160B_0E_adagrad_he_u.csv}\dnwhnsxoptinit
\pgfplotstableread[col sep = comma]{ResultsNormal/cifar10_TwoLayer_180B_0E_adagrad_he_u.csv}\dnwhnegoptinit

\renewcommand{\initerr}{Error for initial epochs-revisited}
\renewcommand{\initacc}{Accuracy for initial epcohs}
\renewcommand{\lateerr}{Error for later epochs}
\renewcommand{\lateacc}{Accuracy for later epochs}
\renewcommand{\boxerr}{Error variation}
\renewcommand{\boxacc}{Accuracy variation}

\renewcommand{\initcaption}{The initial epochs seen for TWO that 2x batch size(2x batch size=2*number of classes) started with the lowest error(a) as well as best accuracy(b), surprisingly 8x batch size started quite well inspite of less network updates in an epoch.
	Then till 15 epochs it is mixed results and no batch size cannot be singled out as a best performer.}

\renewcommand{\latecaption}{8x started well but in late epochs it could not sustain the start, Another good perfromance is shown by 10x which has reached quite good accuracy but its error become high and entered overfitting regime, 2x performance in error as well as accuracy side remain quite robust.}

\renewcommand{\boxerracccaption}{4x perform quite well as error remain with in small range, but on high side, 16x and 18x have low error regime as their minimum error but their variance range is on higher side, 10x shows quite good accuracy and has its maximum value is maximum among all other batch sizes, while its error had high variance than 2x. 2x is consistent in both low error with less vairance as well as accuracy. Low error makes 2x a robust classifier.}

\renewcommand{\trtscaption}{2x shows quite good performance}

\renewcommand{\initerr}{Error for initial epochs-2}
\renewcommand{\ymaxlim}{0.65}

\input{batch_init_epochs.tex}
\input{batch_box_plots.tex}
\input{batch_late_epochs.tex}
%\input{batch_train_test_plots.tex}


\documentclass{beamer}

\mode<presentation> {
  \usetheme{Madison}
%    \usetheme[left,hideallsubsections,width=1cm]{UWThemeB}
  \usefonttheme[onlymath]{serif}
}

% % % % to make navigation two lines
\usepackage{ragged2e}

\makeatletter
\setbeamertemplate{section in head/foot}{%
    \parbox[c][0.33cm][t]{\dimexpr(\textwidth-1.3cm)/\beamer@sectionmax\relax}{%
        \RaggedRight\fontsize{4}{4}\selectfont\insertsectionhead}}
\setbeamertemplate{footline}[frame number]
\makeatother
% % % %
\usepackage{booktabs, calc, rotating}
\usepackage{scalefnt}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{times}
%\usepackage[T1]{fontenc}
\usepackage{alltt}

  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{blocks}[rounded][shadow=true]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  CHANGE THE TITLE AND INPUT FILE ACCORDING TO THE CHAPTER THAT YOU WISH TO COMPILE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title[Severity]{Severity Distributions}

\date[Fall 2017]{Fall 2017}
%Personal definitions - Bayes Regression
\def\bsb{\boldsymbol \beta}
\def\bsa{\boldsymbol \alpha}
\def\bsm{\boldsymbol \mu}
\def\bsS{\boldsymbol \Sigma}
\def\bsx{\boldsymbol \xi}

\begin{document}

\frame{\titlepage}

\begin{frame}
  \frametitle{Outline}
    %\tableofcontents[part=1,pausesections]
     \tableofcontents[part=1]
\end{frame}

\part<presentation>{Main Talk}

\section[Foundations]{Severity Distributions Foundation}

\begin{frame}[shrink=2]
\frametitle{Important Severity Distributions}

Three important loss severity distributions: \vspace{2mm}
\begin{itemize}
\item \textbf{Gamma}
\begin{itemize}
\item Fits medium tail lines like physical damage auto and homeowners well
\item Member of the ``exponential family of distributions''. This means that it is easy to incorporate rating variables into the distribution via generalized linear modeling
(GLMs) \vspace{2mm}
\end{itemize}
\item \textbf{Pareto}
\begin{itemize}
\item Fits longer tail lines like injury liability in auto and workers' compensation well
\item Simple to work with analytically (hence can provide intuition as we develop theory and explain the theory to
others) \vspace{2mm}
\end{itemize}
\item \textbf{GB2 - Generalized Beta of the Second Kind}
\begin{itemize}
\item A four parameter distribution family, complex
\item Yet, many severity distributions can be expressed as a special case of this distribution (good for programming)
\item Some applications have been fit well by the GB2 where others do not seem to
work \vspace{2mm}
\end{itemize}
\end{itemize}
\end{frame}

\begin{frame}%[shrink=2]
\frametitle{Gamma Distribution}

\begin{itemize}\scalefont{0.9}
\item The gamma distribution has two parameters,  $\alpha$ and $\theta$ %\vspace{2mm}

\item The probability density function is 0 for $x \le 0$ and for $x>0$
\begin{eqnarray*}
f(x) &=& \frac{(\frac{x}{\theta})^{\alpha} e^{-x/\theta}}{x\Gamma(\alpha)} = \frac{1}{\theta^{\alpha} \Gamma(\alpha)} x^{\alpha - 1} e^{-x/\theta}
\end{eqnarray*} %\vspace{2mm}

\item If $\alpha=1$, the gamma reduces to the familiar \textit{exponential} distribution
%\vspace{2mm}
\item The function $\Gamma(\cdot)$ is known as the \textit{gamma function}, defined as
\begin{equation*}
\Gamma(\alpha) =  \int_0^{\infty} x^{\alpha-1} e^{-x} ~dx
\end{equation*} %\vspace{2mm}
\item Some important facts about the gamma function: %\vspace{2mm}

\begin{itemize}\scalefont{0.9}
\item For a positive integer $n$, $\Gamma(n) = (n-1)!$ %\vspace{2mm}

\item For more general arguments, one needs to rely on numerical integration to evaluate $\Gamma(\cdot)$. The two main exceptions are:
\begin{itemize}\scalefont{0.9}
\item For any $\alpha>0$, $\Gamma(\alpha+1)=\alpha\Gamma(\alpha)$
\item $\Gamma(0.5)=\sqrt{\pi}$
\end{itemize}\end{itemize}
Thus, for example, $\Gamma(2.5)=1.5 \Gamma(1.5) = 1.5 (0.5)
\Gamma(0.5) = \frac{3}{4} \sqrt{\pi} $
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Exercise} \emph{Example.} Suppose that $X \sim
gamma(\alpha=2, \theta=100)$, that is, the random variable $X$ has a
gamma distribution with parameters $\alpha=2$ and  $\theta=100$
\vspace{2mm}

Determine $\Pr(X \le 60)$

\end{frame}

%\begin{frame}[shrink=2]
%\frametitle{Incomplete Gamma Function}
%\begin{itemize}
%   \item More generally, we define the \textit{incomplete gamma function}
%\begin{equation*}
%\Gamma(\alpha;x) =  \int_0^x t^{\alpha-1} e^{-t} ~dt
%\end{equation*} \vspace{2mm}

%\item With this, we may express the gamma distribution function as
%\begin{equation*}
%F(x) = \Gamma(\alpha; \frac{x}{\theta}),
%\end{equation*}
%so that computing the gamma distribution function is evaluating the
%incomplete gamma function at a rescaled value of $x$ \vspace{2mm}

%\begin{itemize}\item In general, this is done via numerical integration
%\item However, when $\alpha$ is a positive integer, one can use integration by parts as in the preceding example to get:
%\begin{equation*}
%\Gamma(\alpha; x) = 1 - \sum_{j=0}^{\alpha-1} ~ \frac{x^j
%e^{-x}}{j!}
%\end{equation*}
%In their book, KPW have this as Theorem A.1 \vspace{2mm}
%\end{itemize}
%\item \emph{Example - Continued.} Suppose that $X \sim gamma(\alpha=2, \theta=100)$. Determine $\Pr(X \le 60)$.
%\end{itemize}
%\end{frame}

\begin{frame}[shrink=2]
\frametitle{Gamma Moments} Use the gamma function to calculate
moments of a gamma distribution \vspace{2mm}
\begin{itemize}
\item Define the $k$th \textit{raw moment} to be
\begin{eqnarray*}
\mu_k^{\prime} &=& \mathrm{E~} X^k = \int_0^{\infty} x^k f(x) dx
\end{eqnarray*} \vspace{2mm}

\item Using a change of variable, $t=x/\theta$, we have
\begin{eqnarray*}
\mu_k^{\prime}
&=& \frac{1}{\theta^{\alpha} \Gamma(\alpha)} \int_0^{\infty} x^{\alpha+k-1} \exp(-x/\theta) ~dx \\
&=& \frac{\theta^{\alpha+k}}{\theta^{\alpha} \Gamma(\alpha)} \int_0^{\infty} t^{\alpha+k-1} \exp(-t) dt \\
&=& \frac{\theta^k }{\Gamma(\alpha)} \Gamma(\alpha+k).
\end{eqnarray*} \vspace{2mm}
\item With $k=1$, we have $\mu = \mu_1^{\prime}
= \theta \frac{\Gamma(\alpha+1)}{\Gamma(\alpha)} = \alpha \theta$
\vspace{2mm}
\item Check that:
\begin{itemize}
\item $ \mu_2^{\prime} = \theta^2 \alpha (\alpha+1), $ \hspace{0.2in} $ \mathrm{Var}(X)  =\theta^2
\alpha,
$ \hspace{0.2in} $\mu_k^{\prime} = \theta^k(\alpha+k-1) \cdots
\alpha$
\end{itemize}\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Gamma Moment Generating Function}
\begin{itemize}
\item The gamma moment generating function (mgf) is
\begin{eqnarray*}
M(t) = \mathrm{E~} e^{tX} &=& \frac{1}{\theta^{\alpha}\Gamma(\alpha)}\int_0 ^{\infty} x^{\alpha-1} e^{tx} e^{-x/\theta} dx\\
&=& \frac{1}{\theta^{\alpha}\Gamma(\alpha)}\int_0 ^{\infty} x^{\alpha-1} \exp\left\{-x\left(\frac{1-\theta t}{\theta}\right)\right\} dx\\
&=& \frac{1}{\theta^{\alpha}\Gamma(\alpha)} \left(\frac{\theta}{1-\theta t}\right)^{\alpha} \Gamma(\alpha)\\
&=& (1 - \theta t)^{-\alpha} .
\end{eqnarray*}
\item To check this result, first note that $M(0) = (1 - \theta 0)^{-\alpha} = 1$, as anticipated. Next, taking derivatives, we have
\begin{eqnarray*}
M^{\prime}(t) = \frac{\partial}{\partial t} M(t) &=& -\alpha (1 - \theta t)^{-\alpha - 1}(-\theta) = \alpha \theta (1 - \theta t)^{-\alpha - 1}
\end{eqnarray*}
\item Evaluating this at 0 yields $M^{\prime}(0) = \alpha \theta =\mu$, as anticipated
\end{itemize}
\end{frame}

\begin{frame}%[shrink=2]
\frametitle{Pareto Distribution}
\begin{itemize}\scalefont{0.9}
\item The Pareto with parameters $\alpha$ and $\theta$ has probability density function:
\begin{eqnarray*}
\mathrm{f}(x) = \frac{\alpha \theta^{\alpha}}{(x+\theta)^{\alpha+1}}
\end{eqnarray*} %\vspace{2mm}
and moments
\begin{eqnarray*}
\mu_k^{\prime}= \frac{\theta^k k!}{(\alpha-1) \cdots (\alpha-k)}
\end{eqnarray*} %\vspace{2mm}
\item Because moments are not finite when $k \ge \alpha$, the moment generating function is not well-defined %\vspace{2mm}
\item Unlike the gamma, there is a simple expression for the distribution function
\begin{eqnarray*}
\mathrm{F}(x) &=& \int^x_0 \mathrm{f}(y) dy = 1 -
\left(\frac{\theta}{x+\theta}\right)^{\alpha}
\end{eqnarray*} %\vspace{2mm}
\item This means that it is easy to compute quantiles
\begin{itemize}\scalefont{0.9}
\item For example, find $x$ so that 0.95 = F(x) (the 95th percentile) %\vspace{2mm}
\item Easy calculations show that this is $\theta \left[(0.05)^{-1/\alpha} - 1\right]$ %\vspace{2mm}
\item In general, the $p$th percentile/quantile is $\theta \left[(1-p)^{-1/\alpha} - 1\right]$
\end{itemize}\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{GB2 - Generalized Beta of the Second Kind}
\begin{itemize}
\item In KPW, the GB2 is known as a \textit{transformed beta
distribution} \vspace{2mm}

\item The pdf (KPW, Appendix A2.1.1) is
\begin{eqnarray*}
f(x) &=& \frac{\Gamma(\alpha + \tau)}{\Gamma(\alpha)\Gamma(\tau)}
   \frac{\gamma (x/\theta)^{\gamma \tau}}
   {x\left[1+(x/\theta)^{\gamma}\right]^{\alpha + \tau}}
\end{eqnarray*} \vspace{2mm}

with moments
\begin{eqnarray*}
\mathrm{E~}X^k &=& \theta^k \frac{\Gamma(\tau + \frac{k}{\gamma})\Gamma(\alpha-\frac{k}{\gamma})}{\Gamma(\alpha)\Gamma(\tau)} .
\end{eqnarray*} \vspace{2mm}

\item In the text by Frees on Regression, the GB2 distribution is cited but with the parameters
$\alpha_1  = \alpha$, $\alpha_2  =\tau$, $\gamma = 1/\sigma$,
$\theta = e^\mu$
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{GB2 Special Cases} The GB2 a four parameter family of
distributions that captures many other distributions, either as
special cases or as limiting results: \vspace{2mm}

\begin{itemize}
\item \textit{Special Case: Burr Distribution}. Use the GB2 distribution with $\tau =
1$ \vspace{2mm}

\item \textit{Special Case: Pareto Distribution}. Use the GB2 distribution with $\gamma=\tau =
1$ \vspace{2mm}

\item \textit{Limiting Case: Generalized Gamma Distribution} \vspace{2mm}

Replace $\theta$ by $\theta \tau^{1/\gamma}$ \vspace{2mm}

Then, one can show that
\begin{eqnarray*}
\lim_{\tau \to \infty} f_{GB2}(x; \theta \tau^{1/\gamma}, \alpha, \tau, \gamma) = f(x),
\end{eqnarray*}
the pdf of a \textit{generalized gamma}. In KPW, Appendix A.3.1,
p.673, the generalized gamma is called a \emph{transformed gamma}
\end{itemize}
\end{frame}

\section{Creating Distributions Using Transformations}

\begin{frame}[shrink=2]
\frametitle{Creating Distributions Using Transformations} There are
many distributions available to the analyst \vspace{2mm}

\begin{itemize}
\item In this section, we consider distributions that are created by transforming the random variable of a distribution.
Specifically: \vspace{2mm}

\begin{itemize}
\item  Multiplication by a constant ($Y = cX$) \\
\item Raising to a power ($Y = X^\tau$)\\
\item Exponentiation $(Y = e^X)$\\
\end{itemize}\vspace{2mm}

\item In the next section, we consider ways of combining distributions to form a distribution of interest. Specifically: \vspace{2mm}

\begin{itemize}
\item Mixing
\item Splicing
\end{itemize}\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Multiplication by a Constant}
\begin{itemize}
\item Multiplying a random variable by a positive constant is a simple type of
transformation \vspace{2mm}

\item It is also easy to interpret: \vspace{2mm}

\begin{itemize}
\item Think of $X$ as this year's losses and assume that we have an 8\% inflation rate. Then, we can model next year's losses as $Y =
1.08X$ \vspace{2mm}

\item We also want to readily go from dollars to thousands of dollars ($c=1/1000$) or from dollars to Euros (or swapping any set of
currencies) \vspace{2mm}

\end{itemize}
\item More generally, let $Y=cX$ and use
\begin{eqnarray*}
F_Y (y) &=& \Pr( Y \le y) = \Pr \left(X \le \frac{y}{c}\right)= F_X \left(\frac{y}{c}\right)\\
f_Y (y) &=& \frac{1}{c}~f_X\left(\frac{y}{c}\right)
\end{eqnarray*}
\end{itemize}
\end{frame}

\begin{frame}%[shrink=2]
\frametitle{Scale Distributions}
\begin{itemize}\scalefont{0.9}
\item In a location-scale distribution, the transformed variable $Y = c(X-a)$ has a distribution from the same family as the random variable $X$ %\vspace{2mm}
\begin{itemize}\scalefont{0.9}
\item Here, $a$ and $c>0$ are constants
\item The normal distribution is the usual example %\vspace{2mm}
\end{itemize}
\item In a scale distribution,  the transformed variable $Y = c X$ has a distribution from the same family as the random variable $X$ %\vspace{2mm}
\begin{itemize}\scalefont{0.9}
\item Many loss distributions are scale distributions
\item Typically, one uses $\theta$ as the scale parameter. If $X$ comes from a distribution with parameter $\theta$, then $Y = c X$ has the same distribution with scale parameter $\theta^{\ast} = c \theta$ %\vspace{2mm}
\end{itemize}
\item \textit{Example: Special Case - Gamma Distribution}. Suppose that $X$ has a gamma distribution with $\alpha = 4$ and $\theta = 10,000$ %\vspace{2mm}
\begin{itemize}\scalefont{0.9}
\item The mean is $\alpha \theta = 40,000$ and the standard deviation is $\theta \sqrt{\alpha} = 20,000$ %\vspace{2mm}
\item Suppose that $Y = X/1000$
\begin{itemize}\scalefont{0.9}
\item This has mean 40 and standard deviation 20
\item Further $Y$ has a gamma distribution with parameters $\alpha = 4$ and $\theta^{\ast} = \theta/1000 = 10$\end{itemize}
\end{itemize}\end{itemize}
\end{frame}

\begin{frame}%[shrink=.5]
\frametitle{Raising to a Power}
\begin{itemize}\scalefont{0.9}
\item Another type of transformation involves raising the random variable to a power, say, $\tau$ %\vspace{2mm}
\item Consider the transformed random variable $Y = X^{\tau}$. We examine three cases: %\vspace{2mm}
\scalefont{0.9}
\begin{eqnarray*}
&\tau>0&  \text{transformed}\\
&\tau=-1 &  \text{inverse}\\
&\tau<0 & \text{inverse transformed}
\end{eqnarray*}\scalefont{1.1111} %\vspace{2mm}
\item \textit{Special Case: Exponential Distribution}. Suppose that $X$ has an exponential distribution with parameter $\theta^{\ast}$ and consider $Y=1/X$ %\vspace{2mm}
\begin{itemize}\scalefont{0.9}
\item The distribution function of $Y$ is
\begin{eqnarray*}
\Pr(Y \le y) &=& \Pr(\frac{1}{X} \le y) = \Pr(\frac{1}{y} \le X) = \exp\left(-\frac{1}{y \theta^\ast}\right) .
\end{eqnarray*}
\item Now, define a new parameter $\theta = \frac{1}{\theta^{\ast}}$. With this notation,
\begin{eqnarray*}
\Pr(Y \le y) &=& \exp\left(-\frac{\theta}{y}\right).
\end{eqnarray*}
\item This distribution is known as an \textit{inverse exponential distribution} with parameter $\theta$. See the appendix of KPW
\end{itemize}
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Exponential to get a Weibull}
\textit{Example: Transforming an Exponential to get a Weibull}.
\begin{itemize}
\item Start with $X \sim $ exponential distribution with parameter 1. Define the transformed random
variable:
\begin{eqnarray*}
Y = \theta X^{1/\tau}
\end{eqnarray*} \vspace{2mm}

\item This has distribution
\begin{eqnarray*}
F_Y(y) &=& \Pr(Y \le y)\\
&=& \Pr(X^{1/\tau} \le \frac{y}{\theta}) = \Pr(X \le (\frac{y}{\theta})^{\tau})\\
&=& 1 - \exp\left(-(\frac{y}{\theta})^\tau\right) ,
\end{eqnarray*}
known as a \textit{Weibull distribution} \vspace{2mm}

\item This result will be handy if you want to \emph{simulate} outcomes from a Weibull distribution in Excel (exponential simulation is easy, Weibull is not available)
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Transforming the Pareto Distribution} This is from KPW
Exercise 5.3. We assume that $X \sim$  Pareto with parameters
$(\alpha, \theta)$ and consider the transformed variable $Y =
X^{1/\tau}$. We wish to determine the df of $Y$ when $\tau$ is
positive, equal to -1, and negative

\bigskip

\textit{Solution.} Begin by recalling the df of the Pareto
\begin{eqnarray*}
\mathrm{F}_X (x) &=& 1 - \left(\frac{\theta}{x+\theta}\right)^{\alpha} .
\end{eqnarray*}

\textit{Case} \textcircled{1}. Assume $\tau > 0$. Then,
\begin{eqnarray*}
\mathrm{F}_Y (y) &=& \Pr (X^{1/\tau} \le y ) = \Pr (X \le y^\tau ) \\
& =& \mathrm{F}_X (y^\tau)\\
&=& 1 - \left(\frac{\theta}{y^\tau+\theta}\right)^{\alpha} .
\end{eqnarray*}
Now, define the new parameter $\theta^{\ast} = \theta^{1/\tau} $ so that $\theta^{\ast \tau} = \theta$. With this notation, we have
\begin{eqnarray*}
\mathrm{F}_Y (y) &=& 1 - \left(\frac{\theta^{\ast \tau}}{y^{\tau}+\theta^{\ast \tau}}\right)^{\alpha} .
\end{eqnarray*}
This is known as a \emph{Burr distribution} with parameters $
(\alpha, \theta^{\ast}, \tau = \gamma)$
\end{frame}

\begin{frame}%[shrink=2]
\frametitle{Exponentiation}
\begin{itemize}\scalefont{0.9}
\item Another type of transformation involves exponentiating a random variable so that $Y=\exp(X)$ %\vspace{2mm}
\item The main example of this is the normal distribution. If $X \sim$ normal, then $Y=e^{X} \sim $ a \textit{lognormal
distribution} %\vspace{2mm}
\item We can develop the distribution of the new random variable through the relation with the df
\begin{eqnarray*}
F_Y (y) = \Pr ( \exp(X) \le y) = \Pr( X \le \ln y) = F_X (\ln y)
 \end{eqnarray*} %\vspace{2mm}
and the pdf
\begin{eqnarray*}
f_Y (y) = \frac{1}{y} f_X (\ln y) .
 \end{eqnarray*} %\vspace{2mm}
\item Remark. This provides a way to simulate a Pareto distribution, by first simulating an exponential random variable and then transforming it
\end{itemize}

\end{frame}

\section{Creating Distributions by Mixing}

\subsection{Motivation}

\begin{frame}[shrink=2]
\frametitle{Motivation for Mixing}
\begin{itemize}
\item In a mixture distribution,  the outcome (random variable) can be thought of as a random draw from a population of
outcomes \vspace{2mm}

\item \textit{Example: Pareto Distribution}. Consider the Pareto distribution with survival function
\begin{eqnarray*}
S(x) = \left(\frac{\theta}{x+\theta}\right)^\alpha,
\end{eqnarray*}
and mean $ \mathrm{E~}X = \frac{\theta}{\alpha-1}$. Let us think
about two types of populations: \vspace{2mm}

$X_1 \sim \text{Pareto} (\alpha_1, \theta_1)$ "Good Driver"

$X_2 \sim \text{Pareto} (\alpha_2, \theta_2)$ "Bad Driver"
\vspace{2mm}

\item Suppose that with probability $a$ we draw the loss from a good driver, $X_1$, and with probability $1-a$ we draw the loss from a bad driver,
$X_2$:
\begin{eqnarray*}
Y =
\begin{cases}
X_1 & \text{with probability~} a\\
X_2 &  \text{with probability~} 1-a
\end{cases}
\end{eqnarray*} \vspace{2mm}

Our interest is in the distribution of $Y$
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Mixing Moments}
\begin{itemize}
\item To begin, focus on the mean. Using the law of total
expectations: \vspace{2mm}

\begin{eqnarray*}
\mathrm{E~}Y = a\mathrm{E~}X_1 + (1-a)\mathrm{E~}X_2 = a \frac{\theta_1}{\alpha_1-1} +  (1-a) \frac{\theta_2}{\alpha_2-1} .
\end{eqnarray*} \vspace{2mm}

We can also write \vspace{2mm}

\begin{eqnarray*}
\hspace{-0.8in}Y^2 =
\begin{cases}
X_{1}^2 & \text{with probability~} a\\
X_{2}^2 &  \text{with probability~} 1-a
\end{cases}
\end{eqnarray*} \vspace{2mm}

Thus, we have \vspace{2mm}

\begin{eqnarray*}
\mathrm{E~}Y^2 = a\mathrm{E~}X_{1}^2 + (1-a)\mathrm{E~}X_{2}^2 .
\end{eqnarray*} \vspace{2mm}

The same argument holds for any moment
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Mixing Distribution Function}
\begin{itemize}
\item For the distribution function, we have \vspace{2mm}
\begin{eqnarray*}
\Pr(Y \le y) &=& \Pr(Y \le y, \text{Good Driver}) + \Pr(Y \le y, \text{Bad Driver})\\
&=& \Pr(X_1 \le y, \text{Good Driver}) + \Pr(X_2 \le y, \text{Bad Driver})\\
&=& \Pr(X_1 \le y)\Pr(\text{Good Driver}) + \Pr(X_2 \le y)\Pr(\text{Bad Driver})\\
&=& a F_{X_1}(y) + (1-a) F_{X_2}(y)
\end{eqnarray*}
\end{itemize} \vspace{4mm}

\textit{Example from Exam M Spring 05 \#34}. Suppose that $a$ = 0.8,
and $X_1 \sim \text{Pareto}(\alpha = 2, \theta = 100), X_2 \sim
\text{Pareto}(\alpha = 4, \theta = 3000)$ \vspace{2mm}

Determine $\Pr(Y \le 200)$
\end{frame}

\subsection{Finite Mixture Distributions}

\begin{frame}%[shrink=2]
\frametitle{Finite Mixture Distributions}
\begin{itemize}\scalefont{0.9}
\item \emph{Definition.} Let $X_1, \ldots, X_k$ be random variables and define
\begin{eqnarray*}
Y =\left\{
\begin{array}{cc}
X_1 & with~probability~a_1 \\
\vdots & \vdots \\
X_k & with~probability~a_k \\
\end{array}
\right.
\end{eqnarray*}
Here, $a_{j}>0$ and $ a_1+ \cdots + a_k = 1.$ Then, $Y$ is a $k$-point mixture random variable. The df is
\begin{eqnarray*}
F_Y(y) = a_1 F_{X_1}(y)+ \cdots +a_k F_{X_k}(y)
\end{eqnarray*}
with mean
\begin{eqnarray*}
\mathrm{E~}Y = a_1 \mathrm{E~}X_1 + \cdots + a_k \mathrm{E~}X_k.
\end{eqnarray*}
\item If $k$ is unknown (but not random), then this a \emph{variable component mixture
distribution} %\vspace{2mm}
\item We can always select one or more of the underlying $X_j$ variables to be degenerate (that is, equal to a number with probability one). In this way, we can use the finite mixture framework to create discrete and mixed distributions
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Exponential Example}
\textit{Example}. Suppose, for a fixed parameter $\theta$, that
$X|\theta \sim$ exponential with parameter $\theta$. Thus,
\begin{equation*}
\Pr(X \le x | \theta) = 1 - e^{-x/\theta}.
\end{equation*} \vspace{2mm}

Now, think of two populations, each having an exponential
distribution, but with different parameter values. For concreteness,
assume
\begin{equation*}
 \Theta =
\begin{cases}
10 &  \text{with prob~}\alpha\\
200 & \text{with prob~}(1-\alpha)\\
\end{cases}
\end{equation*} \vspace{2mm}

As with the $x$'s, we use an upper case $\Theta$ for a random
variable and a lower case $\theta$ for a realization of the random
variable
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Exponential Example II}
\begin{itemize}
\item Using the discrete mixing framework, we may write the df of $X$ as
\begin{equation*}
\Pr(X \le x) = \alpha(1 - e^{-x/10}) + (1-\alpha)(1-e^{-x/200}) .
\end{equation*} \vspace{2mm}

\item More generally, we can consider $k$ populations, each with the same
form of the distribution function $\mathrm{F}(\cdot|\theta)$ and
allow $\theta$ to vary as
\[
\Theta=\left\{
\begin{array}{ll}
\theta_1  & \text{prob~} \alpha_1  \\
\theta_2  & \text{prob~} \alpha_2  \\
\vdots & \vdots \\
\theta_K & \text{prob~} \alpha_K \\
\end{array}
\right.
\] \vspace{2mm}

This is our \textit{finite mixture} distribution
\end{itemize}
\end{frame}

\subsection{Continuous Mixtures}

\begin{frame}[shrink=2]
\frametitle{Continuous Mixtures}
\begin{itemize}
\item Extend this idea by thinking about an infinite number of
populations, each with a conditional distribution function that has
the same structure $\mathrm{F}(\cdot|\theta)$ (e.g., exponential)
but with a parameter $\theta$ that accounts for population
differences \vspace{2mm}

\item Assume that the random variable $\Theta$ has pdf $f_\Theta
(\theta)$ \vspace{2mm}

\item Then, the df is:
\begin{eqnarray*}
\mathrm{F}_X(x) = \Pr(X \le x) &=& E_{\Theta} \Pr(X \le x|\Theta)\\
&=& \int \Pr(X \le x|\theta)f_{\Theta}(\theta) d\theta =\int
\mathrm{F}(x|\theta)f_{\Theta}(\theta) d\theta
\end{eqnarray*} \vspace{2mm}

\item The pdf is:
\begin{eqnarray*}
f_X (x) &=& \int f_{x | \theta}(x) f_{\Theta}(\theta) d\theta
\end{eqnarray*}
\end{itemize}
\end{frame}

\begin{frame}%[shrink=2]
\frametitle{Special Case: Gamma Mixtures of Exponentials}
\begin{itemize}\scalefont{0.9}
\item \textit{Special case: Gamma Mixtures of Exponentials}. Suppose that each population has an exponential distribution with parameter $1/\theta$, that is, $X|\theta \sim \text{exponential}(\frac{1}{\theta})$:
\begin{eqnarray*}
f_{X|\theta}(x) &=& \theta e^{-\theta x}
\end{eqnarray*} %\vspace{2mm}
\item Suppose that the distribution of population parameters is governed by a gamma distribution such that $\Theta \sim \text{gamma}(\alpha, \beta)$ %\vspace{2mm}
\begin{eqnarray*}
f_{\theta}(\theta) &=&
\frac{1}{\Gamma(\alpha)\beta^{\alpha}}\theta^{\alpha-1}e^{-\theta/\beta}
\end{eqnarray*} %\vspace{2mm}

\item The pdf of $X$ is
\begin{eqnarray*}
f_X (x) &=&\int f_{x | \theta}(x) f_{\Theta}(\theta) d\theta \\
&=& \frac{1}{\Gamma(\alpha)\beta^{\alpha}}\int_0 ^{\infty}
\theta^{\alpha} e^{{-\theta}(x+1/\beta)}d\theta = \frac{\alpha
\beta}{(1+x\beta)^{\alpha+1}}
\end{eqnarray*} %\vspace{2mm}
\item We recognize this as a Pareto distribution with parameters $\alpha$ and $\theta=1/\beta $
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Mixture Expectations}
\begin{itemize}
\item For some mixtures such as the above example, we can compute the
mixture distribution in closed-form \vspace{2mm}

\item However, it is often helpful to
just consider the moments. For the mean function, using the
\textit{law of iterated expectations}, we have
\begin{eqnarray*}
\mathrm{E~}X &=& \mathrm{E}_{\Theta}[\mathrm{E}(X|\Theta)]
\end{eqnarray*} \vspace{2mm}

\item This is easily extended to the $k$th moment
\begin{eqnarray*}
\mathrm{E~}X^k &=& \mathrm{E}_{\Theta}[\mathrm{E}(X^k|\Theta)]
\end{eqnarray*}
\end{itemize}
\end{frame}

\bigskip
\begin{frame}[shrink=2]
\frametitle{Mixture Expectations Example}
\textit{Example. Gamma Mixtures of Exponentials}.
\begin{itemize}
\item Assume that $X|\theta \sim$ exponential with parameter $(\frac{1}{\theta})$. Thus, the mean is $\mathrm{E}(X|\theta) =
1/\theta$, the second raw moment is $\mathrm{E}(X^2|\theta) =
2/\theta^2$, and the variance is $\mathrm{Var}(X|\theta) = 1/
\theta^2$ \vspace{2mm}

\item For the parameter distribution, we have $\theta \sim \text{gamma}(\alpha,
\beta)$ \vspace{2mm}

\item One can check that
\begin{eqnarray*}
\mathrm{E~}X = \frac{1}{\beta(\alpha-1)}
\end{eqnarray*}
and
\begin{eqnarray*}
\mathrm{Var~}X = \frac{\alpha}{\beta^2(\alpha-1)^2(\alpha-2)}
\end{eqnarray*} \vspace{2mm}

\item This is consistent with a Pareto distribution with parameters $\alpha$ and $\theta=1/\beta $ (good practice to check)
\end{itemize}
\end{frame}

\subsection{Splicing}

\begin{frame}[shrink=2]
\frametitle{Splicing}
\begin{itemize}
\item Join (splice) together different probability density functions to form a pdf over the support of a random
variable \vspace{2mm}
\[
f_X (x)=\left\{
\begin{array}{ll}
\alpha_1 f_1 (x) & c_0  < x < c_1  \\
\alpha_2 f_2 (x) & c_1  < x < c_2  \\
\vdots & \vdots \\
\alpha_{k}f_{k}(x) & c_{k-1} < x < c_{k}  \\%
\end{array}%
\right.
\]% \vspace{2mm}

$\alpha_1  + \alpha_2  \cdots + \alpha_{k} = 1$\\ \vspace{2mm}

Each $f_j$ is a pdf, so that $\int_{c_{j-1}}^{c_{j}}f_{j}(x)dx =
1$\\ \vspace{2mm}

$c_{j}$'s are typically known\\ \vspace{2mm}

\item \textit{Example: Life Contingencies}.
\begin{itemize}\item It is common to use an exponential distribution in the early ages, e.g., from $x=5$ to $x=40$. The exponential has a constant hazard rate and is well suited to model mortality from
accidents \vspace{2mm}

\item Beginning at age $x=40$, one use another mortality law, e.g., Gompertz, that reflects mortality that increases with age $x$
\end{itemize}\end{itemize}
\end{frame}

\section{Risk Retention -- Deductibles and Limits}

\begin{frame}[shrink=2]
\frametitle{Risk Retention Framework}
\begin{itemize}
\item Now consider the following framework: \vspace{2mm}

\begin{itemize}
\item The policyholder or insured suffers a loss in the amount $X$ \vspace{2mm}

\item Under the insurance contract, the insurer is obligated to covered a portion of this
amount \vspace{2mm}

\item The insurer may have entered into a separate contract with a reinsurer that relieves the insurer of a portion of its
obligations \vspace{2mm}
\end{itemize}

\item This section introduces standard mechanisms that insurers use to reduce, or mitigate, their risk, including deductibles and policy
limits \vspace{2mm}

\item Further, we examine how the distribution of the insurers obligations depends on these mechanisms
\end{itemize}
\end{frame}

\begin{frame}%[shrink=2]
\frametitle{Risk Retention Function}
\begin{itemize}\scalefont{0.8}
\item Recall that $X$ represents the amount of an insurable loss and use $Y$ to represent the insurer's
obligation %\vspace{2mm}
\item There is a known function $g(\cdot)$ that maps the amount insured to the amount retained by the insurer, that is, $Y=g(X)$ %\vspace{2mm}
\item \textbf{Special Case 1. Deductible (d)} %\vspace{2mm}
\begin{equation*}
g(x) = (x-d)_+ =
\begin{cases}
0 & x \le d\\
x - d & x > d .
\end{cases}
\end{equation*}
The notation ``$(\cdot)_+$'' means ``take the positive part of.''
$Y=g(X)$ as the loss in excess of the deductible $d$ \vspace{2mm}
\item \textbf{Special Case 2. Limit (u)} %\vspace{2mm}
\begin{equation*}
g(x) = x \wedge u =
\begin{cases}
x & x \le u\\
u & x > u .
\end{cases}
\end{equation*}
The notation ``$\wedge$'' means ``take the minimum of.'' In this case, the insurance only pays up to a specified limit $u$. The random variable $Y= X \wedge u = \min(X,u)$ is the claim paid %\vspace{2mm}
\item \textbf{Special Case 3. Coinsurance}. Define $Y = c X$. Typically, $0<c<1$, and so represents the proportion of claims retained by the insurer
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Risk Retention Function II}
\begin{itemize}
\item One handy way of combining the three special cases is through the expression
\begin{equation*}
g(x) =
\begin{cases}
0      & x \le d\\
c(x-d) & d \le x < u \\
c(u-d) & x \ge u .
\end{cases}
\end{equation*} \vspace{2mm}

\item Think about these as parameters in a contract between a policyholder and an insurer and so represent ``modifications'' of the underlying
contract \vspace{2mm}

\item Also interpret the risk retention function as the result from a reinsurance
contract \vspace{2mm}

\begin{itemize}
\item For example, it is common in such a contract for an insurer to retain 50\% of each risk and ``cede'' 50\% to the reinsurer
\end{itemize}
\end{itemize}
\end{frame}

\begin{frame}%[shrink=2]
\frametitle{Information Set for Deductibles}
\begin{itemize}\scalefont{0.9}
\item Specify what type of information, sometimes known as the ``information set,'' that is available to the
insurer %\vspace{2mm}
\item \textbf{Special Case 4. Policyholder Deductible}. Define:
\begin{equation*}
g_P(x) =
\begin{cases}
\text{undefined/not observed} & x \le d\\
x - d & x > d
\end{cases}
\end{equation*} %\vspace{2mm}
\item The insurance only pays amounts in excess of the deductible $d$. If the loss is less than the deductible, then the insurer does not observe the loss. The random variable $Y^P = g(X)$ is the claim that an insurer
observes %\vspace{2mm}
\item We have placed a ``$P$'' subscript to remind ourselves that the retained loss is on what is sometimes known as a ``per payment'' basis %\vspace{2mm}
\item In statistical terms, this retained loss is \emph{truncated} in the sense that values of $X$ below $d$ are not
observed %\vspace{2mm}
 \item To distinguish this from the other case where a zero is observed for losses $X<d$, the terminology \textbf{per loss} is used.  Some sources use the notation $Y^L = (X-d)_+$ for the loss amount on a \textbf{per loss} basis
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Distributions of Retained Risks - Deductible}
\begin{itemize}
\item Consider two types of \textit{ordinary deductible}: \vspace{2mm}

\begin{enumerate}
\item Cost (amount of payment) per loss event
  \begin{eqnarray*}
Y^L=(X-d)_+&=&
\left \{
\begin{array}{cc}
0 & X<d\\
X-d & X\ge d\\
\end{array}
\right.\text{(a censored rv)}
  \end{eqnarray*} \vspace{2mm}

\item Cost (amount of payment) per payment event
  \begin{eqnarray*}
Y^P &=&
\left \{
\begin{array}{cc}
undefined & X<d\\
X-d & x\ge d\\
\end{array}
\right. \text{(a truncated rv)}
  \end{eqnarray*}
\end{enumerate}
\end{itemize} \vspace{2mm}

\textit{Example. Exponential Distribution.} Suppose that the loss
$X$ has distribution function $F(x) = 1-\exp{(-x/1000)}$. Compute
the distribution function and pdf for $Y^L$ and $Y^P$ with $d=250$
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Pareto Per Payment Deductible}
\begin{itemize}
\item Assume a deductible $d = 1,000$ \vspace{2mm}

Then, the claim amount on a per payment basis is
\begin{equation*}
Y^{P} =
\begin{cases}
\text{undefined/not observed} & X < 1000\\
1000 & X \ge 1000
\end{cases}
\end{equation*} \vspace{2mm}

\item Identify the distribution of $Y^P$
\end{itemize}
\end{frame}

\subsection{Expectations of Retained Risks}

\begin{frame}[shrink=2]
\frametitle{Limited Expected Value}
\begin{itemize}
\item Use a generic ``$u$'' for the upper limit. To compute the expected value of the limited loss variable $\min(X, u)$, we have
\begin{eqnarray*}
\mathrm{E~}\min(X, u) = \int_0^u \left(1-F(x)\right) dx =  \int_0^u S(x)dx .
\end{eqnarray*}

\textit{Pareto Policy Limit}. Recall
\begin{equation*}
1-F(x)=  S(x) = \Pr(X > x) = \left(\frac{\theta}{x + \theta}\right)^{\alpha}
\end{equation*}
with mean $\mathrm{E~}(X) = \frac{\theta}{\alpha - 1}$. Thus, the limited expected value is
\begin{eqnarray*}
\mathrm{E~}\min(X, u)  &=& \theta^{\alpha}\int_0^u (x + \theta)^{-\alpha} dx =\theta^{\alpha} \left.\frac{(x + \theta)^{-\alpha+1}}{-\alpha + 1}\right|_0^u\\
&=& \theta^{\alpha}\left(\frac{\theta^{-\alpha+1} - (u+\theta)^{-\alpha+1}}{\alpha - 1}\right)\\
&=& \frac{\theta}{\alpha-1}\left\{1 - \left(\frac{\theta}{u + \theta}\right)^{\alpha-1} \right\}.
\end{eqnarray*}
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Pareto Deductible}
\begin{itemize}
\item The claim amount on a ``per loss'' basis is $Y^L = (X-d)_+$ for a deductible
$d$ \vspace{2mm}

\item To calculate $\mathrm{E~} (X-d)_+$, we can use the relation, $X \wedge d + (X - d)_{+} =
X$ \vspace{2mm}

\item For the Pareto distribution, recall $\mathrm{E~}X = \frac{\theta}{\alpha - 1}$ and
\begin{eqnarray*}
\mathrm{E~}\min(X, d)  &=&  \frac{\theta}{\alpha-1}\left\{1 - \left(\frac{\theta}{d + \theta}\right)^{\alpha-1} \right\}.
\end{eqnarray*} \vspace{2mm}

Thus,
\begin{eqnarray*}
\mathrm{E~}(X-d)_+ &=& \mathrm{E~} X -
\mathrm{E~}\min(X, d)  =  \frac{\theta}{\alpha-1} -\frac{\theta}{\alpha-1}\left\{1 - \left(\frac{\theta}{d + \theta}\right)^{\alpha-1} \right\} \\
&=& \frac{\theta}{\alpha-1} \left\{\left(\frac{\theta}{d + \theta}\right)^{\alpha-1} \right\} .
\end{eqnarray*}
\end{itemize}
\end{frame}

\begin{frame}%[shrink=2]
\frametitle{Mean Residual Life}
\begin{itemize}\scalefont{0.9}
\item For the ``per payment'' random variable associated with the policyholder deductible case,
\begin{equation*}
g_P(x) =
\begin{cases}
\text{undefined/not observed} & x \le d\\
x - d & x > d
\end{cases}
\end{equation*}
we can calculate the expectation as
\begin{eqnarray*}
e_X(d) &=& e(d) = \mathrm{E~}(X - d|X > d)
\end{eqnarray*} %\vspace{2mm}
\item Here, $e_X(d)$ is known as the \textit{mean residual life} %\vspace{2mm}
\item We can write this as
\begin{eqnarray*}
e(d) &=&  \mathrm{E~}(X - d|X > d)\\
&=& \frac{\int_d^{\infty} (x-d) f(x)dx}{S(d)} = \frac{\mathrm{E~}(X - d)_+}{S(d)}
\end{eqnarray*} %\vspace{2mm}
Thus,
\begin{eqnarray*}
e(d) &=& \frac{\int_d^{\infty} S(x)dx}{S(d)}
\end{eqnarray*}
\end{itemize}
\end{frame}

\begin{frame}[shrink=2]
\frametitle{Example} \textit{Example. Exam M Fall 2005, Exercise
26.} For an insurance:

\begin{enumerate}
\item Losses have density function
\begin{eqnarray*}
f_X(x)&=& \left \{
\begin{array}{cc}
0.02x & 0<x<10\\
0 & \text{elsewhere}\\
\end{array}
\right.
\end{eqnarray*} \vspace{2mm}

\item The insurance has an ordinary deductible of $4$ per loss \vspace{2mm}

\item $Y^P$ is the claim payment per payment random variable \vspace{2mm}

\end{enumerate}
Calculate $\mathrm{E~}[Y^P]$\\
\end{frame}

\begin{frame}%[shrink=2]
\frametitle{Summary of Limited Loss Variables}
\scalefont{0.8}
\[
\begin{tabular}{ll}
\hline
\textbf{Random Variable} & \textbf{Expectation} \\ \hline
\emph{Excess loss random variable} & $e_{X}(d)=\mathrm{E}~Y=\mathrm{E}%
(X-d|X>d)$ \\
$Y=X-d$ if $X>d$ & mean excess loss function \\
left \emph{truncated} & mean residual life function \\
& complete expectation of life \\
& $e_{X}^{k}(d)=\mathrm{E}\left[ \left( X-d\right) ^{k}|X>d\right] $ \\
\hline
$\left( X-d\right) _{+}=\left\{
\begin{array}{ll}
0 & X<d \\
X-d & X\geq d
\end{array}
\right. $ & $\mathrm{E~}\left( X-d\right) _{+}=e(d)S(d)$ \\
left-\emph{censored} and shifted variable & $\mathrm{E~}\left(
X-d\right) _{+}^{k}=e^{k}(d)S(d)$ \\ \hline
$\mathrm{min}(X,d)=X\wedge d=\left\{
\begin{array}{ll}
X & X<d \\
d & X\geq d
\end{array}
\right. $ \  & $\mathrm{E}\left( X\wedge d\right) -$ limited expected value
\\ \emph{limited loss variable} - right \emph{censored} &
\\ \hline
\end{tabular}
\]

Note that $\left( X-d\right) _{+}+\left( X\wedge d\right) =X.$ \
Thus, $ \mathrm{E~}\left( X-d\right) _{+}+\mathrm{E}\left( X\wedge
d\right) =\mathrm{E}~X$ %\vspace{2mm}

For nonnegative, continuous random variables,
\begin{equation*}
\mathrm{E}\left( X \wedge d\right) =\int_{0}^{d} S\left( x\right)
dx\text{ \ \ and \ \ \ }\mathrm{E}( X-d) _{+} = \int_{d}^{\infty
}S\left( x \right) dx
\end{equation*}
\end{frame}

\subsection{Loss Elimination Ratio (LER)}

\begin{frame}[shrink=2]
\frametitle{Loss Elimination Ratio (LER)}
\begin{itemize}
\item Consider an ordinary deductible, cost (amount of payment) per loss event
\begin{eqnarray*}
LER&=&\frac{\mathrm{E~}X - (\mathrm{E~}X-\mathrm{E~}(X\wedge
d))}{\mathrm{E~}X}
=\frac{\mathrm{E~}(X\wedge d)}{\mathrm{E~}X}\\
&=&\frac{\text{limited exp value}}{\text{exp value}}
\end{eqnarray*}
What fraction of losses have been eliminated by introducing the deductible?\\
\end{itemize}

\textit{Example.} Losses have a lognormal distribution with $\mu=6$
and $\sigma=2$. There is a deductible of 2,000, and 10 losses are
expected each year \vspace{2mm}

Determine the loss elimination ratio

\end{frame}

\end{document}

\begin{frame}[shrink=2]
\frametitle{Instructor Notes}
\begin{itemize}
\item
\end{itemize}
\end{frame}

\textcolor{blue}{temp}