text:
%-------------------------------------------------------------------------------
% This file provides template SUSY group object descriptions and cuts.
% \pdfinclusioncopyfonts=1
% This command may be needed in order to get \ell in PDF plots to appear. Found in
% https://tex.stackexchange.com/questions/322010/pdflatex-glyph-undefined-symbols-disappear-from-included-pdf
%-------------------------------------------------------------------------------
% Specify where ATLAS LaTeX style files can be found.
\newcommand*{\ATLASLATEXPATH}{../../latex/}
% Use this variant if the files are in a central location, e.g. $HOME/texmf.
% \newcommand*{\ATLASLATEXPATH}{}
%-------------------------------------------------------------------------------
\documentclass[NOTE, atlasdraft=true, texlive=2016, USenglish]{\ATLASLATEXPATH atlasdoc}
% The language of the document must be set: usually UKenglish or USenglish.
% british and american also work!
% Commonly used options:
%  atlasdraft=true|false This document is an ATLAS draft.
%  texlive=YYYY          Specify TeX Live version (2016 is default).
%  txfonts=true|false    Use txfonts rather than the default newtx
%  paper=a4|letter       Set paper size to A4 (default) or letter.

%-------------------------------------------------------------------------------
% Extra packages:
\usepackage{\ATLASLATEXPATH atlaspackage}
% Commonly used options:
%  subfigure|subfig|subcaption  to use one of these packages for figures in figures.
%-------------------------------------------------------------------------------
\usepackage{multirow}

% Useful macros
\usepackage[jetetmiss]{\ATLASLATEXPATH atlasphysics}
% See doc/atlas_physics.pdf for a list of the defined symbols.
% Default options are:
%   true:  journal, misc, particle, unit, xref
%   false: BSM, heppparticle, hepprocess, hion, jetetmiss, math, process,
%          other, snippets, texmf
% See the package for details on the options.

% Package for creating list of authors and contributors to the analysis.
\usepackage{\ATLASLATEXPATH atlascontribute}

% Add you own definitions here (file atlas-document-defs.sty).
% \usepackage{atlas-document-defs}

% Paths for figures - do not forget the / at the end of the directory name.
\graphicspath{{\ATLASLATEXPATH ../logos/}{figures/}}

%-------------------------------------------------------------------------------
% Generic document information
%-------------------------------------------------------------------------------

\AtlasTitle{SUSY group text snippets for INT notes}
\AtlasVersion{0.1}
\author{ATLAS SUSY Group}
\AtlasRefCode{SUSY-2018-XX}
\AtlasAbstract{%
  This note contains text snippets and tables that should be included in supporting notes
  from the SUSY group.

  The templates are in American English.
  If wanted, some adaption to British English could be made.

  This document was generated using version \ATPackageVersion\ of the ATLAS \LaTeX\ package.

  \emph{2019-02-04: This file is a work in progress (WIP) and will probably be updated.
  Backwards incompatible changes may be made as the examples develop.}
}
% Author and title for the PDF file
\hypersetup{pdftitle={ATLAS SUSY supporting note},pdfauthor={ATLAS SUSY group}}

%-------------------------------------------------------------------------------
% Main document
%-------------------------------------------------------------------------------
\begin{document}

\maketitle

\tableofcontents

%-------------------------------------------------------------------------------
% The executive summary template is provided by the group
\include{executive_summary}
%-------------------------------------------------------------------------------

Please feel free to also include a change log with major updates either before or after the executive summary.

%-------------------------------------------------------------------------------
% The executive summary template is provided by the group
\section{Introduction}
\label{sec:introduction}
%-------------------------------------------------------------------------------

Place a short introduction here.  It is useful to introduce your analysis target signals, place them in context,
and describe any previous analyses that this analysis follows on (particularly if significant pieces are in common).

Please note that in an internal note there is no need for a description of the ATLAS detector,
unless the search uses some unusual or less well-known features of the detector of which reviewers will need a reminder.

%-------------------------------------------------------------------------------
\section{Signal Models}
\label{sec:signals}
%-------------------------------------------------------------------------------

Place the description of your target signal models here, potentially including a description of the ``signal grids'' that you will ultimately use for interpretataion.

%-------------------------------------------------------------------------------
\section{Data and Simulated Event Samples}
\label{sec:samples}
%-------------------------------------------------------------------------------

Place the description of your dataset (including GRL) and Monte Carlo simulated samples here.
Please place any long tables (e.g. lists of used datasets) into appendices.

%-------------------------------------------------------------------------------
\section{Object definition}
\label{sec:objects}
%-------------------------------------------------------------------------------

Please describe your object definition here.
% Object definition recommendations are here: https://twiki.cern.ch/twiki/bin/view/AtlasProtected/SusyObjectDefinitionsr2113TeV

%-------------------------------------------------------------------------------
\section{Event selection}
\label{sec:selection}
%-------------------------------------------------------------------------------

Place the description of your event selection here.  This can include signal region optimization, control region selection, and pre-selection.

%-------------------------------------------------------------------------------
\section{Background Estimation}
\label{sec:backgrounds}
%-------------------------------------------------------------------------------

Place the description of your background estimation here.

%-------------------------------------------------------------------------------
\section{Systematic Uncertainties}
\label{sec:systematics}
%-------------------------------------------------------------------------------

Place the description of your systematic uncertainties here.
% Useful recommendations are maintained by the SUSY group: https://twiki.cern.ch/twiki/bin/view/AtlasProtected/SUSYSpecificRecommendations
% and by the PMG: https://twiki.cern.ch/twiki/bin/view/AtlasProtected/PhysicsModellingGroup#Systematic_uncertainties_and_rew

%-------------------------------------------------------------------------------
\section{Results}
\label{sec:result}
%-------------------------------------------------------------------------------

Place your results here.

% The required information is available here: https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/SUSYResultsPresentation
% All figures and tables should appear before the summary and conclusion.
% The package placeins provides the macro \FloatBarrier to achieve this.
% \FloatBarrier

%-------------------------------------------------------------------------------
\section{Conclusion}
\label{sec:conclusion}
%-------------------------------------------------------------------------------

Place your conclusion here.

%-------------------------------------------------------------------------------
% If you use biblatex and either biber or bibtex to process the bibliography
% just say \printbibliography here
\printbibliography
% If you want to use the traditional BibTeX you need to use the syntax below.
% \bibliographystyle{obsolete/bst/atlasBibStyleWithTitle}
% \bibliography{atlas-document,bib/ATLAS,bib/CMS,bib/ConfNotes,bib/PubNotes}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
% Print the list of contributors to the analysis
% The argument gives the fraction of the text width used for the names
%-------------------------------------------------------------------------------
\clearpage
The supporting notes for the analysis should also contain a list of contributors.
This information should usually be included in \texttt{mydocument-metadata.tex}.
The list should be printed either here or before the Table of Contents.
\PrintAtlasContribute{0.30}

%-------------------------------------------------------------------------------
\clearpage
\appendix
\part*{Appendices}
\addcontentsline{toc}{part}{Appendices}
%-------------------------------------------------------------------------------

In an ATLAS note, use the appendices to include all the technical details of your work
that are relevant for the ATLAS Collaboration only (e.g.\ dataset details, software release used).
This information should be printed after the Bibliography.

\end{document}


text:
\subsubsection{Normality}\label{subsubsec:ldassumptionsnormality}

In this case, we get better results for normality compared to those obtained in
the high density scenario: also the QQ-plot for the total number of messages
sent looks more linear with \(R^2\!=\!0.9322\).

Also in this case normality is not verified for the percentage of covered users.
Since we do not study this index, we do not need to get it verified.

ext: tex

max_stars_repo_name: SpeedJack/pecsn

max_issues_repo_name: SpeedJack/pecsn

max_forks_repo_name: SpeedJack/pecsn


text:
\documentclass[]{spie}
%\documentclass[a4paper]{spie}  %>>> use this instead for A4 paper
%\documentclass[nocompress]{spie}  %>>> to avoid compression of citations

\renewcommand{\baselinestretch}{1.0} % Change to 1.65 for double spacing

\usepackage{amsmath,amsfonts,amssymb}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{multicol}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{longtable}
\usepackage[english,iso]{isodate}

% lsstdoc documentation: https://lsst-texmf.lsst.io/lsstdoc.html
\input{meta}

% Package imports go here.

% Local commands go here.

\date{\today}

\input{authors}

\title{Faro: A framework for measuring the scientific performance of petascale Rubin Observatory data products}

\newcommand{\docRef}{DMTN-211}
\newcommand{\docUpstreamLocation}{\url{https://github.com/lsst-dm/dmtn-211}}

% Option to view page numbers
\pagestyle{empty} % change to \pagestyle{plain} for page numbers
\setcounter{page}{1} % Set start page numbering at e.g. 301

\begin{document}
\maketitle
%\hypersetup{pdftitle={\@title}, pdfauthor={\@author}, pdfkeywords={\@keywords}}

\input{abstract}

% Include a list of keywords after the abstract
\keywords{Rubin Observatory, LSST, performance characterization, verification}
\input{body}

\appendix
% Remove this when you start your paper
%\input{appendix}
% Include all the relevant bib files.
% https://lsst-texmf.lsst.io/lsstdoc.html#bibliographies
\section{References} \label{sec:bib}
\bibliographystyle{spiebib}
\bibliography{local,lsst,lsst-dm}

% Make sure lsst-texmf/bin/generateAcronyms.py is in your path
\section{Acronyms} \label{sec:acronyms}
\input{acronyms.tex}

\end{document}


text:
\section{Our technique}

We suggest a \clos{}-based \emph{protocol} defining the set of
operations on a first-class environment.  This protocol contains
around $40$ generic functions.  The details of the proposed protocol
can be found in the appendix of this paper.  The protocol has been
implemented as part of the \sicl{} project.%
\footnote{See https://github.com/robert-strandh/SICL.}

Mainly, the protocol contains versions of \commonlisp{} environment
functions such as \texttt{fboundp}, \texttt{find-class}, etc. that
take an additional required \texttt{environment} argument.

For a simple example, consider the \sicl{} implementation of the
standard \commonlisp{} function \texttt{fboundp}:

{\small\begin{verbatim}
(defun fboundp (name)
  (sicl-genv:fboundp
    name
    (load-time-value (sicl-genv:global-environment))))
\end{verbatim}}

In this example \texttt{sicl-genv} is the nickname for the package
named \texttt{sicl-global-environment} which contains the symbols of
the protocol defined in this paper.  In each global environment, the
function \texttt{global-environment} in that package returns
the value of the environment itself.  When the definition in the
example above is \emph{loaded}, either as source or from a previously
compiled file, the value of the \texttt{load-time-value} form will
therefore be the global environment in which the definition is loaded,
thereby permanently \emph{linking} this definition to that global
environment.

In addition to these functions, the protocol contains a set of
functions for accessing \emph{cells} that in most implementations
would be stored elsewhere.  Thus, a binding of a function name to a
function object contains an indirection in the form of a
\emph{function cell}.  The same holds for the binding of a variable
name (a symbol) to its \emph{global value}.  In our implementation,
these cells are ordinary \texttt{cons} cells with the \texttt{car}
containing the value of the binding, and the \texttt{cdr} containing
\texttt{nil}.  The reason for using ordinary \texttt{cons} cells is
that they are already supported in any \commonlisp{} implementation.
The only possible reason for choosing a different representation for
cells would be to save one word in each cell, since the \texttt{cdr}
slot in each of our \texttt{cons} cells is wasted.  However, the saved
space would probably be more than consumed by the space occupied by
specialized inspector functionality for dealing with custom cell
representations.

These cells are created as needed.  The first time a reference to a
function is made, the corresponding cell is created.  Compiled code
that refers to a global function will have the corresponding cell in
its run-time environment.  The cost of accessing a function at
run-time is therefore no greater in our implementation than in an
implementation that accesses the function through the symbol naming
it, hence our claim that there is no performance penalty for accessing
this information at run-time.

The \sicl{} compiler translates a reference to a global function (say
\texttt{foo}) into something similar to this code:

{\small\begin{verbatim}
(car
  (load-time-value
    (sicl-genv:function-cell
      'foo
      (sicl-genv:global-environment+))))
\end{verbatim}}

except that what is shown as \texttt{car} is not the full
\commonlisp{} function, because the argument is known to be a
\texttt{cons} cell.  When the code containing this reference is
loaded, the resulting machine code will refer to a local variable
containing the \texttt{cons} cell of the current global environment
that is permanently assigned to holding the function definition of
\texttt{foo}.

Our technique does, however, incur a performance penalty for functions
such as \texttt{fdefinition} and \texttt{symbol-value} with an
argument that is computed at run-time%
\footnote{When the argument is a constant, a suitable
  \emph{compiler-macro} can turn the form into an access of the
  corresponding cell.}
compared to an implementation in which each symbol contains slots for
these objects.  However, even in a high-performance implementation such
as \sbcl{}, these values are \emph{not} contained in symbol slots.

The performance penalty incurred on these functions depends on the
exact representation of the environment.  The representation of the
environment is outside the scope of this paper, however.  Here, we
only consider the \emph{protocol} for accessing it.  However, it is
not hard to devise a reasonable implementation.  In SICL, we use a
hash table for each namespace with the keys being the corresponding
\emph{names}%
\footnote{Functions are named by symbols and lists; variables are
  named by symbols; packages are named by strings; classes are named
  by symbols; etc.}
of the entities in that namespace.

While it is \emph{possible} for the application programmer to create
new global environments, it would not be a common thing to do, at
least not for the applications of first-class global environments that
we have considered so far.  For that reason, we have not streamlined
any particular technique for doing so.  The difficulty is not in
\emph{creating} the environment per se, but rather in filling it with
useful objects.  For the purpose of bootstrapping, we currently fill
environments by loading code into it from files.

max_stars_repo_name: gwerbin/SICL

max_issues_repo_name: gwerbin/SICL

max_forks_repo_name: gwerbin/SICL


text:
\documentclass[11pt, a4]{article}
\usepackage{geometry}
\geometry{margin=1.25in}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{graphicx}
\graphicspath{ {./figures/} }
\usepackage{placeins}
\usepackage{booktabs}
\usepackage{listings}

\title{Credible or not Credible Clients - Default of Credit Card
	Supervised Machine Learning: Classification - Course Project}
\author{Caio Mescouto Terra de Souza}
\date{\today}

\begin{document}

\maketitle

\section*{Introduction and Main Objective}

From a bank's perspective, one of the most important piece of information about clients is how willing are they to default? In possession of this banks can set credit limits as well as interest rates that clients must bear. In addition, it's fundamental piece to calculate contingent liabilities on the balance sheet.

The dataset \cite{credit} I worked on contains customers attributes and a binary variable of default credit card payment. The main objective of this analysis is to build a model capable of predicting whether a client is likely to default or not. Even if interpretation is intended, we would like to avoid underfitting by simplicity and, of course, overfitting by high complexity. Finally, precision is a key in this analysis as a very conservative model reduce the number of potential clients and a very risky one increases the risk the bank will bear.

\section*{Data Set Description}

As presented before, the data set contains 23 numerical attributes, a binary variable as target and and 30,000 instances. The table below summarises the attributes (Table  \ref{table:1}).

\begin{table}[h!]
\centering
\begin{tabular}{l c c}
\toprule
\textbf{Columns} & \textbf{Dtype} & \textbf{Unit} \\
\midrule
1. Credit limit & int64 & USD\\
2. Gender & int64 & 1(male); 2(female)\\
3. Education & int64 & 1(graduate); 2(university); 3(high school); 4(others)\\
4. Marital status & int64 & 1(married); 2(single); 3(others) \\
5. Age & int64 & years \\
6-11. History of past payment & int64  & Binary each variable one month\\
12-17. Amount of monthly bill & int64 & USD\\
18-23. Amount of previous payment & int64 & USD \\
24. Default Payment & int64 & 0(No); 1(Yes)\\
\bottomrule
\end{tabular}
\caption{Data Set Attributes}
\label{table:1}
\end{table}

\section*{Exploratory Data Analysis (EDA)}

Considering the main objective, the data exploration had 5 steps. First, data cleaning; second, to split the data into train and test data; third, to understand the distribution of the numerical variables; fourth, to analyse the correlation between than and fifth, to understand the importance of the attributes to predict clients defaults.

\subsection*{Data Cleaning}

The data set is almost clean, no null, no outliers, no mismatching. The only point is that scales are very different, so depending on the estimator it should be scaled and centered before being fitted to the model.

\subsection*{Data Stratified Sampling}

To avoid hacking the model it is important to split the data between train and test data as early as possible. Just after the first view, the data was split using a stratified split. The stratification followed the distribution of the target variable (\textit{Default Payment}) and the test set was set in $30\%$ of the data. Below the \textit{Scikit-Learn} implementation applied. Strafication is justified because the dataset is unbalanced on the target variable.

\begin{table}[h!]
\centering
\begin{tabular}{l c }
\toprule
\textbf{Column} & \textbf{Count} \\
\midrule
No & 23364\\
Yes& 6636\\
\bottomrule
\end{tabular}
\caption{Default payment next month?}
\label{table:2}
\end{table}

\begin{lstlisting}
StratifiedShuffleSplit(n_splits=1, test_size=0.3, random_state=42)
\end{lstlisting}

\subsection*{Numerical Variables}

This subsection covers two steps of the EDA plan (third and forth). First the histograms of all numerical variables were plotted and two problems that can interfere in modeling were spotted. First, some variables are far away from normal distributions, second the scale is also different between them. Two approaches were followed. (1) fitting Tree-based models as there is no effect related to scale or distributions (2) Feature engineering before fitting sensitive models. Bellow is presented the skewness of the variables.

\begin{table}[h!]
\centering
\begin{tabular}{l c c}
\toprule
\textbf{Column} & \textbf{Skewness} \\
\midrule
LIMIT_BAL    & 0.999384\\
SEX          & -0.423501\\
EDUCATION    & 0.994205\\
MARRIAGE     &-0.027035\\
AGE          & 0.733548\\
PAY_0         & 0.728328\\
PAY_2       &  0.803700\\
PAY_3        & 0.808713\\
PAY_4        & 0.905861\\
PAY_5        & 0.906568\\
PAY_6         &0.864933\\
BILL_AMT1     &2.665551\\
BILL_AMT2    & 2.733801\\
BILL_AMT3    & 2.738895\\
BILL_AMT4    & 2.831088\\
BILL_AMT5    & 2.930481\\
BILL_AMT6    & 2.898127\\
PAY_AMT1    & 15.829797\\
PAY_AMT2    & 21.766774\\
PAY_AMT3    & 19.104434\\
PAY_AMT4    & 12.485983\\
PAY_AMT5    & 10.925696\\
PAY_AMT6    & 10.054438\\
\bottomrule
\end{tabular}
\caption{Data Skewness}
\label{table:3}
\end{table}

Variables that are highly correlated with each other should be avoided due to collinearity issues. As we can observe in the heatmap below (Figure \ref{fig:heatmap}).

\begin{figure}
\includegraphics[]{heatmap}
\centering
\caption{Heatmap of correlations}
\label{fig:heatmap}
\end{figure}

\section*{Better understand the features - Setting a baseline score}

At this point the data were directly fitted into a model that required neither feature scaling nor center distribution. The motivation for doing this are, (1)it could be possible to fit a good model with almost no cost of data preparation, (2) to set a baseline score, and most important (3) The models applied are good to understand feature importance.

\subsection*{Score}

The F1 score was set to evaluate the model for two reasons: (1) It is a well-balanced score that assesses accuracy and memory equally, and since we are interested in a well-balanced model, it is naturally a good indicator. (2) Since the dataset is unbalanced, accuracy is no longer a good measure of adequacy.

\subsection*{Models}

Bellow \ref{table:4} is presented the code snippet for the model definition. Cross-validation was applied in combination with GridSearch to set the best model possible and avoid overfitting.

\begin{lstlisting}
rndf_clf = RandomForestClassifier(random_state=42, n_jobs=-1)
extt_clf = ExtraTreesClassifier(random_state=42, n_jobs=-1)

params = {
    'n_estimators': [200, 300, 400, 500],
    'max_features': ['auto', 'sqrt', 'log2', None],
    'max_leaf_nodes': [10, 15, None]
}

estimators = {}
for estimator in [rndf_clf, extt_clf]:
    estimators[estimator.__class__.__name__] =
     RandomizedSearchCV(estimator=estimator,
     param_distributions=params,
     n_jobs=-1, n_iter=15, cv=5, return_train_score=True,
     random_state=42, scoring='f1').fit(X_train, np.ravel(y_train))

\end{lstlisting}

\begin{table}[h!]
\centering
\begin{tabular}{l c }
\toprule
\textbf{Estimator} & \textbf{F1} \\
\midrule
RandomForestClassifier & 0.4779\\
ExtraTreesClassifier & 0.4859\\
\bottomrule
\end{tabular}
\caption{F1}
\label{table:4}
\end{table}

\subsection*{Feature Importance}

Both models suggested that the two most important feature was \textit{History of payment in the previous month}. Besides that, \textit{Credit Limit} and \textit{Age}, are also important. Finally, Features with high correlation between than has a stable scale of importance.

\section*{Data preparation and Feature Engineering}

The scaling was tackled during the data preparation process that precedes the modeling process. After analyzing the skewness of all numerical variables (Table \ref{table:3}) A log transformation was applied in \textit{Credit Limit}. Finally,
some simulation to reduce colinearity and improve correlations was tried between All variables of history of past payments and between all varibles of Amount of monthly bill, but as no improvement was reached.

\section*{Model Selection}

Three simple models were selected and a list o paramers were defined. Finally the \textit{GridSearchCV} was used to tune the best estimator for each model selected before. But the result achived was worse than the ensemble methods previous presented. Bellow \ref{table:5} the F1 score for each model:

\begin{table}[h!]
\centering
\begin{tabular}{l c }
\toprule
\textbf{Estimator} & \textbf{F1} \\
\midrule
LinearSVC & 0.3815\\
LogisticRegression & 0.3701\\
KNeighborsClassifier & 0.4256\\
\bottomrule
\end{tabular}
\caption{F1}
\label{table:5}
\end{table}

These selection was also thought because they are very different models and I could use them ensemble. To do so, a \textit{VotingClassifier} was built as follow. However, the ensemble achieve a mean score of 0.3941 and was also rejected.

\begin{lstlisting}
voting_clf = VotingClassifier(estimators=[
                             ('svm', svm_clf),
                             ('log', log_clf),
                             ('knn', knn_clf)], voting='hard')
\end{lstlisting}

\section*{Model Interpretation and Key Findings}

It's clear that the models selected were not able to produce a powerfull model, however, the results are important and have predictive power as well. A hypothetical model that reject all clients would be a very strict model and the F1 of this model would be 0.3623. Therefore, all models trained were better off.

Finally, after six models were tested and different feature engineering were performed, the best fit was:

\begin{lstlisting}
ExtraTreesClassifier(random_state=42, n_jobs=-1,
					 max_features= None,
					 max_leaf_nodes= 15,
					 n_estimators= 300)
\end{lstlisting}
\subsection*{Key Findings}

\begin{itemize}
\item Default in the previous month is the most important feature in explaning clients default, Limit credit also has predictive power, but the direction is negative;
\item Education, gender and marriage are less important in explaning default than the history of payments and the credit limit;

\end{itemize}

\subsection*{Test set}

The last phase before presenting the conclusion is that the model were tested against the test dataset and the result is presented below (Table \ref{fig:Confusion Matrix}).

\begin{figure}
\includegraphics[]{confusion}
\centering
\caption{Confusion Matrix}
\label{fig:Confusion Matrix}
\end{figure}

\section*{Next steps and Improvements}

First of all, there is a field of improvement concerning the dataset analyzed. Definitely more data is required and a robustness can be achieve applying deep learning \cite{Yeh}. Finally, as presented above, credit limit data has explanatory power on credit card defaults, which means that more information related to wealth and employment can improve our predictive power.

\FloatBarrier

\begin{thebibliography}{9}

\bibitem{credit}
default of credit card clients Data Set,
\\\texttt{https://archive.ics.uci.edu/ml/datasets/default+of+credit+card+clients#}

\bibitem{Yeh}
\\\texttt{Yeh, I. C., & Lien, C. H. (2009). The comparisons of data mining techniques for the predictive accuracy of probability of default of credit card clients. Expert Systems with Applications, 36(2), 2473-2480.}

\end{document}


text:
% Changing book to article will make the footers match on each page,
% rather than alternate every other.
%
% Note that the article class does not have chapters.
\documentclass[letterpaper,10pt,twoside,twocolumn,openany]{book}

% Use babel or polyglossia to automatically redefine macros for terms
% Armor Class, Level, etc...
% Default output is in English; captions are located in lib/dndstring-captions.sty.
% If no captions exist for a language, English will be used.
%1. To load a language with babel:
%	\usepackage[<lang>]{babel}
%2. To load a language with polyglossia:
%	\usepackage{polyglossia}
%	\setdefaultlanguage{<lang>}
\usepackage[english]{babel}
%usepackage[italian]{babel}
% For further options (multilanguage documents, hypenations, language environments...)
% please refer to babel/polyglossia's documentation.

\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{listings}

% dnd package options
% bg-full   : Default option. Use paper background and fancy footer.
% bg-print  : Use fancy footer but not background.
% bg-none   : No paper background and plain footer.
% justified : Use full justification for text layout instead of ragged right.
\usepackage[bg-print]{dnd}

\lstset{%
  basicstyle=\ttfamily,
  language=[LaTeX]{TeX},
}

% Start document
\begin{document}

% Your content goes here

% Comment this out if you're using the article class.
%\chapter{Chapter 1: The Dark \LaTeX}

\section{Stelmaria's Friends}

What follows are stat blocks for Stelmaria's pacted allies.
Each such ally is an independent fey spirit with their own values and objectives.
So long as Stelmaria adheres to the terms of their pact, the ally will heed Stelmaria's call.

\begin{quotebox}
	Beware angering your allies! Most consider themselves your equal or even your better.
\end{quotebox}

%-------------------------------------------------------------------------
% AVARR
%-------------------------------------------------------------------------

\subsection{Avarr}

% You can optionally not include the background by saying
% begin{monsterboxnobg}
\begin{monsterbox}{Avarr}
	\textit{Large fey tiger, lawful neutral}\\
	\hline%
	\basics[%
	armorclass = 13,
	hitpoints  = \dice{7d12 + 18},
	speed      = {50 ft, climb 40 ft, swim 30 ft}
	]
	\hline%
	\stats[
    STR = \stat{20}, % This stat command will autocomplete the modifier for you
    DEX = \stat{15},
    CON = \stat{17},
    WIS = \stat{14},
    CHA = \stat{9}
	]
	\hline%
	\details[%
	% If you want to use commas in these sections, enclose the
	% description in braces.
	% I'm so sorry.
	skills = {Perception +5, Stealth +8},
	senses = {darkvision 60 ft, pp 15},
	languages = {Giant Tiger, understands Common and Sylvan but cannot speak},
	challenge = 2
	]
	\hline \\[1mm]
	\begin{monsteraction}[Keen Smell]
		Avarr has advantage on Wisdom (Perception) checks that rely on smell.
	\end{monsteraction}

	\begin{monsteraction}[Pounce]
		If Avarr moves at least 20 feet straight toward a creature and then hits it with a claw attack on the same turn,
		that target must succeed on a DC 15 Strength saving throw or be knocked prone.
		If the target is prone, Avarr can make one bite attack against it as a bonus action.
	\end{monsteraction}

	\monstersection{Actions}
	\begin{monsteraction}[Bite]
		\emph{Melee Weapon Attack}: +8 to hit, reach 5 ft., one target. \emph{Hit}: \dice{2d6 + 5} piercing damage.
	\end{monsteraction}

	\begin{monsteraction}[Claw]
		\emph{Melee Weapon Attack}: +8 to hit, reach 5 ft., one target. \emph{Hit}: \dice{1d10 + 5} slashing damage.
	\end{monsteraction}

	\begin{monsteraction}[Mighty Leap]
		(1 / summoning) Avarr leaps 150 ft. If Avarr lands adjacent to a creature, he can make a claw attack as a part of this action.
	\end{monsteraction}
\end{monsterbox}

\subsubsection{Pact}
You freed Avarr from Shymstani bondage.
He came to respect you following your daring rescue of Bellevoja.
Avarr has agreed to help you, so long as his homeland (the interior of Kharazan) remains wild and free.

\subsubsection{Personality}
Avarr is proud, and considers himself the apex of being.

\subsubsection{Opinion of You}
Avarr is intrigued by your inversion of roles - he clearly considers you a prey animal.
You seem to have his respect for now.

%-------------------------------------------------------------------------
% SNAAK
%-------------------------------------------------------------------------

\subsection{Snaak}

% You can optionally not include the background by saying
% begin{monsterboxnobg}
\begin{monsterbox}{Snaak}
	\textit{Large fey saltwater crocodile, true neutral}\\
	\hline%
	\basics[%
	armorclass = 14 (natural armor),
	hitpoints  = \dice{6d12 + 15},
	speed      = {25 ft, swim 40 ft}
	]
	\hline%
	\stats[
    STR = \stat{21}, % This stat command will autocomplete the modifier for you
    DEX = \stat{9},
    CON = \stat{17},
    INT = \stat{7},
    WIS = \stat{10},
    CHA = \stat{5}
	]
	\hline%
	\details[%
	% If you want to use commas in these sections, enclose the
	% description in braces.
	% I'm so sorry.
	skills = {Stealth +9 (when underwater)},
	senses = {pp 10},
	languages = {Crocodile, understands Common and Sylvan but cannot speak},
	challenge = 2
	]
	\hline \\[1mm]
	\begin{monsteraction}[Hold Breath]
		Snaak can hold his breath for 30 minutes.
	\end{monsteraction}

	\begin{monsteraction}[Ambush]
		Once per turn, Snaak deals an extra 5d6 damage against the target if he is submerged in water and hidden.
	\end{monsteraction}
	\monstersection{Actions}
	\begin{monsteraction}[Multiattack]
		Snaak makes two attacks: one with its bite and one with its tail.
	\end{monsteraction}

	\begin{monsteraction}[Bite]
		\emph{Melee Weapon Attack}: +8 to hit, reach 5 ft., one target. \emph{Hit}: \dice{2d10 + 5} piercing damage, and the target is Grappled (escape DC 16). Until this grapple ends, the target is Restrained, and the Crocodile can't bite another target.
	\end{monsteraction}

	\begin{monsteraction}[Tail]
		\emph{Melee Weapon Attack}: +8 to hit, reach 5 ft., one target not grappled by Snaak. \emph{Hit}: \dice{2d8 + 5} bludgeoning damage. The target must succeed on a DC 16 Strength saving throw or be knocked prone.
	\end{monsteraction}

	\begin{monsteraction}[Drown]
		When Snaak is grappling an enemy in water, he can drag them to a watery grave.
		The target must succeed a DC 16 Strength save or take \dice{4d10+5} bludgeoning damage.
		A target that succeeds the save takes half damage.
	\end{monsteraction}
\end{monsterbox}

\subsubsection{Pact}
Snaak agreed to aid you so long as you assist him in reclaiming his home (presumably a saltwater rivermouth) from the invaders that drove him off.

\subsubsection{Personality}
Snaak is a creature of simple pleasures.
Kill and eat.
Bask in the sun.
Repeat.

\subsubsection{Opinion of You}
Snaak doesn't seem like he has much going on upstairs.

%-------------------------------------------------------------------------
% SNAAK
%-------------------------------------------------------------------------

\subsection{ Pleath}

% You can optionally not include the background by saying
% begin{monsterboxnobg}
\begin{monsterbox}{ Pleath}
	\textit{Giant fey longneck, lawful neutral}\\
	\hline%
	\basics[%
	armorclass = 13 (natural armor),
	hitpoints  = \dice{8d10 + 24},
	speed      = {10 ft., swim 40 ft.}
	]
	\hline%
	\stats[
    STR = \stat{18}, % This stat command will autocomplete the modifier for you
    DEX = \stat{15},
    CON = \stat{16},
    INT = \stat{9},
    WIS = \stat{12},
    CHA = \stat{5}
	]
	\hline%
	\details[%
	% If you want to use commas in these sections, enclose the
	% description in braces.
	% I'm so sorry.
	skills = {Perception + 3, Stealth +5 (when underwater)},
	senses = {pp 13},
	languages = {Longneck, understands Common and Sylvan but cannot speak},
	challenge = 2
	]
	\hline \\[1mm]
	\begin{monsteraction}[Hold Breath]
		Pleath can hold her breath for 2 hours.
	\end{monsteraction}

	\monstersection{Actions}
	\begin{monsteraction}[Bite]
		\emph{Melee Weapon Attack}: +7 to hit, reach 10 ft., one target. \emph{Hit}: \dice{3d6 + 4} piercing damage.
	\end{monsteraction}

	\begin{monsteraction}[Release the Storm]
		\emph{Concentration (1 min)}: While submerged in water, Pleath whips up a local storm and gains control over the wind and water in a 60 ft diameter cylinder centered on her. The cylinder counts as difficult terrain, and creatures (other than Pleath and Stelmaria) that begin their turn in the cylinder must make a DC 14 strength save or be slid 10 ft and knocked prone.
	\end{monsteraction}

\end{monsterbox}

\subsubsection{Pact}
You destroyed Lobi Thic, releasing the storm trapped within her and fulfilling your pact with Pleath.

\subsubsection{Personality}
She seems single-minded in her mission to release the storm, and apparently turned on Thic without provocation.

\subsubsection{Opinion of You}
Pleath holds you in high regard since you fulfilled your bargain.

\subsection{ Nakal}

% You can optionally not include the background by saying
% begin{monsterboxnobg}
\begin{monsterbox}{ Nakal}
	\textit{Large fey monitor lizard, true neutral}\\
	\hline%
	\basics[%
	armorclass = 12 (natural armor),
	hitpoints  = \dice{6d8 + 12},
	speed      = {35 ft.}
	]
	\hline%
	\stats[
    STR = \stat{17}, % This stat command will autocomplete the modifier for you
    DEX = \stat{11},
    CON = \stat{16},
    INT = \stat{5},
    WIS = \stat{13},
    CHA = \stat{5}
	]
	\hline%
	\details[%
	% If you want to use commas in these sections, enclose the
	% description in braces.
	% I'm so sorry.
	skills = {Athletics + 3},
	senses = {pp 11},
	languages = {Monitor Lizard, understands Common and Sylvan but cannot speak},
	challenge = 1
	]
	\hline \\[1mm]
	\begin{monsteraction}[Charge]
		If Nakal moves at least 20 ft. in a straight line towards a target and then hits it with a bite attack on the same turn, the target takes an extra \dice{3d6} piercing damage.
		If the target is a creature, it must succeed a DC 13 Strength saving throw or be knocked prone.
	\end{monsteraction}

	\monstersection{Actions}
	\begin{monsteraction}[Bite]
		\emph{Melee Weapon Attack}: +6 to hit, reach 5 ft., one target. \emph{Hit}: 14 (1d8 + 3) piercing damage.
		If the target is a crature, it must succeed a DC 13 Constitution saving throw against diseased or become poisoned until the disease is cured.
		Every hour that elapsed, the creature must repeat the saving throw, reducing its hit point maximum by \dice{1d10} on a failure.
		This reduction lasts until the disease is cured.
		The creature dies if the disease reduces its hit point maximum to 0.
	\end{monsteraction}

\end{monsterbox}

\subsubsection{Pact}
Nakal agreed to aid you on the condition that she is allowed to participate in a hunt.

\subsubsection{Personality}
Nakal is a creature of simple pleasures, although she seems unfulfilled by her life of manual labor and easy food.

\subsubsection{Opinion of You}
Nakal seems excited by the prospect of adventuring with you.

\subsection{ Chippah}

\textbf{Special}: must be summoned with a 5th level spell slot

% You can optionally not include the background by saying
% begin{monsterboxnobg}
\begin{monsterbox}{ Chippah}
	\textit{Gargantuan fey dragon turtle, true neutral}\\
	\hline%
	\basics[%
	armorclass = 17 (natural armor),
	hitpoints  = \dice{8d20 + 35},
	speed      = {20 ft., swim 40 ft.}
	]
	\hline%
	\stats[
    STR = \stat{20}, % This stat command will autocomplete the modifier for you
    DEX = \stat{8},
    CON = \stat{20},
    INT = \stat{7},
    WIS = \stat{12},
    CHA = \stat{8}
	]
	\hline%
	\details[%
	% If you want to use commas in these sections, enclose the
	% description in braces.
	% I'm so sorry.
	skills = {Athletics + 10},
	senses = {darkvision 120 ft., pp 11},
	languages = {Dragon Turtle, understands Common, Draconic, and Sylvan but cannot speak},
	challenge = 4
	]
	\hline \\[1mm]
	\begin{monsteraction}[Amphibious]
		Chippah can breath both air and water.
	\end{monsteraction}

	\monstersection{Actions}
	\begin{monsteraction}[Multiattack]
		Chippah makes two attacks: one with its bite and one with its claws.
	\end{monsteraction}

	\begin{monsteraction}[Bite]
		\emph{Melee Weapon Attack}: +9 to hit, reach 10 ft., one target. \emph{Hit}: \dice{2d10 + 6} piercing damage
	\end{monsteraction}

	\begin{monsteraction}[Claw]
		\emph{Melee Weapon Attack}: +9 to hit, reach 10 ft., one target. \emph{Hit}: \dice{2d6 + 6} slashing damage
	\end{monsteraction}

	\begin{monsteraction}[Tail]
		\emph{Melee Weapon Attack}: +9 to hit, reach 15 ft., one target. \emph{Hit}: \dice{3d8 + 6} bludgeoning damage.
		If the target is a creature, it must succeed on a DC 18 Strength saving throw or be pushed up to 10 ft. away and knocked prone.
	\end{monsteraction}

	\begin{monsteraction}[Steam Breath]
		(1 / summoning): Chippah exhales scalding steam in a 60 foot cone. Each creature in that area must make a DC 15 Constitution saving throw, taking \dice{8d6} fire damage on a failed save or half as much damage on a successful one.
		Being underwater does not grant resistance against this damage.
	\end{monsteraction}

\end{monsterbox}

\subsubsection{Pact}
You have fulfilled your promise to take Chippah to the sea.

\subsubsection{Personality}
Chippah is old, sheltered, and tired, but not ready die yet.

\subsubsection{Opinion of You}
Chippah seems grateful for your help.

% End document
\end{document}

max_stars_repo_name: bwpriest/dnd-homebrew

max_issues_repo_name: bwpriest/dnd-homebrew

max_forks_repo_name: bwpriest/dnd-homebrew


text:
\subsection{Cross-Validation Weights}
We start this section by listing relevant assumptions needed for our results. Suppose the following holds:
\begin{assumption}\label{asump:1}
	\begin{enumerate}
		\item The true data generating process satisfies the linear process $y_t = x_t'\beta_t + e_t$, $t=1,...,T,\beta_t \in \mathbb{R}^k$, where $\beta_t = \beta + T^{-1/2}\eta(t/T)\delta\sigma_t$. $\eta(\bullet)$ is a $\mathbb{R}^k$ valued Riemann integrable function on $[0,1]$ and $\delta \in \mathbb{R}\backslash\{0\}$ is a scalar indexing the magnitude of parameter variation, $\sigma_{t}$ is the standard deviation of the error term at period $t$.
		\item $\{(x_t',e_t)\}$ is $\alpha$-mixing of size $-r/(r-2),r > 2$ or $\phi$-mixing of size $-r/(2r-2),r \geq 2$.
	    \item $E(x_t e_t) = 0, \forall t$, and the process $\{x_t e_t\}$ is uniformly $L_r$-bounded, i.e., $||x_t e_t||_{r} < B$, where $B$ is a constant and $B < \infty$.
	    \item $T^{-1/2}\sum_{t=1}^{[\pi T]} x_t e_t \Rightarrow W(\pi)$ where $W(\pi)$ is a $k \times 1$ Wiener process with symmetric, positive definite long-run covariance matrix $\Sigma \equiv \lim\limits_{T\to \infty}\mathrm{VAR}(T^{-1/2}\sum_{t=1}^{[\pi T]} x_t e_t)$, for $0 \leq \pi \leq 1$. ` $\Rightarrow$' denotes the weak convergence of the underlying probability measure as $T \to \infty$.
		\item $T^{-1}\sum_{t=1}^{[\pi T]}x_t x_t'$ converges uniformly to $\pi Q$ for all $\pi \in [0,1]$, $Q = E(x_t x_t')$ and all eigenvalues of $Q$ are uniformly bounded away from zero. $[\pi T]$ denotes the integer part of the product $\pi T$.
		\item $E(e_t|x_t) = 0$ ;$E(e_t^{2}|x_t) = \sigma_t^{2}$.
	\end{enumerate}
\end{assumption}
Assumption 1.1 says that the true data generating process for $y_t$ takes a general parameter variation form and structural break occurs in all parameters. In each period, the change of the true parameter value is of small magnitude so that the asymptotic distributions are asymptotically continuous. Additionally, the parameter variation is proportional to the unconditional standard deviation of the error term, so the impact of parameter instability will not be dominated by that of the volatility. This type of data generating process is quite general, as it includes several commonly used models, for example, the single break model with the absolute change of parameter values positive in one period while zero in others.

In practice, if there is no clear guidance or information on which subset of parameters are unstable \emph{a priori}, it is natural to assume that all parameters are subject to break. This full-break in the conditional mean assumption is less restrictive, so empirically it is adopted in applications of detecting and dating breaks, see Rapach and Wohar \cite{rapach_wohar_JFE2006} and Paye and Timmermann \cite{paye_timmermann_JEF2006}.

Notice that our predictive model outlined earlier only allows for one possible break in the conditional mean, so it is highly possible that the forecasting model, either the pre-test model or the averaged model, is misspecified. We make this assumption allowing for the gap between the true data generating process and the forecasting model primarily for two reasons. First, in practice the true data generating process is almost always unknown to researchers, as it may be a complicated process possibly involving past values of infinite order. In addition, the true dynamics and parameter stability are very difficult to capture by models based on limited information. Second, for the prediction problem, the goal is not to come up with a highly complex model to fit the training data as closely as possible measured in terms of the learning error rate. Instead, forecasters pay more attention to the test error rate. By reducing the complexity of the predictive model, we hope our model to be more adaptive to environment change in the future.

Assumption 1.2 -- 1.5 ensure that we can apply all relevant mixing laws of large numbers, functional central limit theorem or Donsker's invariance principle when proving our results. See Davidson \cite{davidson_textbook} for more details on advanced asymptotic theory. Assumption 1.6 says that the error term is conditionally heteroscedastic which is less restrictive.

To obtain model weights, first, we need to show what the cross-validation criterion looks like under the above assumptions. We know that the information criterion usually consists of two parts, one measuring in-sample fit while the other penalizing overfitting. For model averaging, the penalty term is crucial in determining the optimal weights. The proofs of all theoretical results are provided in the appendix.

\begin{proposition} \label{thm:1}
If assumption~\ref{asump:1} holds but $E(e_t^{2}|x_t) = \sigma^{2}$, the leave-one-out cross--validation criterion is asymptotically equivalent to Mallows' criterion, that is, $E(CV(T)) \stackrel{p}{\rightarrow} E(Cp(T))$.
\end{proposition}

The intuition for this result is that since the cross-validation criterion is robust to heteroscedasticity compared with Mallows' criterion, so when conditional heteroscedasticity is absent, we would not expect any significant difference between CV and Cp. With this result in hand, we can obtain the feasible sample optimal weight for the break model:

\begin{corollary} \label{corollary:1}
The feasible sample CV weight for the break model is:
    \begin{equation}
    \hat{w} = \frac{(T - 2k)(\sum_{t=1}^{T}\tilde{e}_{t}^{2} - \sum_{t=1}^{T}\hat{e}_{t}^{2}) - \bar{p}\sum_{t=1}^{T}\hat{e}_{t}^{2}}{(T - 2k)(\sum_{t=1}^{T}\tilde{e}_{t}^{2} - \sum_{t=1}^{T}\hat{e}_{t}^{2})}
    \end{equation}
where $T$ is the sample size, $k$ is the number of regressors, $\hat{e}_t$s are the ordinary least squares residuals from the break model, $\tilde{e}_t$s are residuals from the stable model, $\bar{p}$ is the penalty coefficient whose value depends on the asymptotic distribution of the SupW test statistic.
\end{corollary}

By proposition~\ref{thm:1}, Hansen's weights \cite{hansen2009averaging} still apply in this case. Following Hansen, the population penalty term in the cross-validation criterion involves a distribution which is a function of the true data generating process. To obtain the feasible sample optimal weights, the sample CV penalty term is approximated by averaging two extreme cases \footnote{One is that the break size is extremely large while in the other case the break size is $0$.}, so that is how Hansen's $\bar{p}$ value enters the formula for the break model weight.

It is widely known in the model selection literature that the CV criterion is superior to Mallows' and other information criteria because of its robustness to heteroscedasticity \cite{andrews_JE1991}, our next proposition establishes the asymptotic distribution of the CV penalty term in the presence of conditional heteroscedasticity.
\begin{proposition} \label{thm:2}
If Assumption~\ref{asump:1} holds, then the penalty term in the cross-validation criterion converges in distribution to a weighted sum of independent $\chi^2$ distribution with degree of freedom one, plus a term whose distribution is a function of the Brownian bridge,
    \begin{equation} \label{eq:4}
    	e'P(\hat{k})e \stackrel{d}{\rightarrow} \sum_{j=1}^{k} \lambda_j \chi^2(1) + J_0(\xi_{\delta})
    \end{equation}
where $\lambda_j$s are the eigenvalues of the matrix $Q^{-1}\Sigma$, $\Sigma$ is the long-run variance of $\rn\jian X_t e_t$, $Q = E(x_t x_t')$ and $J_0(\xi_{\delta})$ is the asymptotic distribution of the Sup-Wald type statistic under the true data generating process.
\end{proposition}

Comparing this result with Hansen's, we can see that the distribution under conditional homoscedasticity is just a special case of what is shown in proposition~\ref{thm:2}. That is, the weights for the $\chi^2$ random variables are identical and they take the value of one, which results in a $\chi^2$ distribution with degrees of freedom equal to the total number of regressors. In our results, $\lambda_j$s can take different values which capture the impact brought to the weight by allowing for conditional heteroscedasticity. Intuitively, the first term on the right-hand-side of equation~\ref{eq:4} reflexes the impact of conditional heteroscedasticity while the second term deals with structural break.

The expectation of $\sum_{j=1}^{k} \lambda_j \chi^2(1)$ is simply $\sum_{j=1}^{k} \lambda_j$ which is the trace of the matrix $Q^{-1} \Sigma$, where $\Sigma$ is the long-run variance of $\rn\jian X_t e_t$ and $Q = E(x_t x_t')$. Empirically, $\Sigma$ can be estimated by HAC estimators and $Q$ can be consistently estimated by its sample analogue $\frac{1}{T}\sum_{t=1}^{T}x_t x_t'$. The feasible sample optimal weight for the break model in this case is:

\begin{corollary} \label{corollary:2}
The feasible sample optimal weight for the break model in the presence of conditional heteroscedasticity takes the form:
    \begin{equation} \label{eq:5}
    	\hat{w} = 1 - \frac{\mathrm{tr}\left(\hat{Q}^{-1}\hat{\Sigma}\right) + 2\bar{p} - k}{2\left(\sum_{t=1}^{T}\hat{e}_t^2 - \sum_{t=1}^{T}\tilde{e}_t^2\right)}
    \end{equation}
where $\hat{e}_t$s are the OLS residuals from the break model and $\tilde{e}_t$s are residuals from the stable model, $\mathrm{tr}(\hat{Q}^{-1}\hat{\Sigma})$ is the trace of the matrix $\hat{Q}^{-1}\hat{\Sigma}$
\end{corollary}

Again, $\bar{p}$ comes from averaging two extreme cases approximating the infeasible expectation of the population penalty term.

In the next section, through several designs we are going to assess the sample performance of CV weights comparing with Cp wieghts and other related methods in controlled simulations.

max_stars_repo_path: Tex/new theory.tex

max_stars_repo_name: anwenyin/ooscombo

max_issues_repo_path: Tex/new theory.tex

max_issues_repo_name: anwenyin/ooscombo

max_forks_repo_path: Tex/new theory.tex

max_forks_repo_name: anwenyin/ooscombo


text:
%File: model.tex
%Date: Fri Jan 03 21:06:49 2014 +0800
%Author: Yuxin Wu <ppwwyyxxc@gmail.com>

\subsection{GMM}
\textbf{Gaussian Mixture Model} is commonly used in acoustic learning task such as speech/speaker recognition,
since it describes the varied distribution of all the feature vector.\cite{GMM}
GMM assumes that the probability of a feature vector $x$ belonging to the model is the following:
\begin{equation}
p(x | w_i, \mu_i, \Sigma_i) = \sum_{i=1}^{K}{w_i \mathcal{N}(x | \mathbf{\mu}_i, \Sigma_i)}
\label{eqn:gmm}
\end{equation}

where
\[\mathcal{N}(x | \mathbf{\mu}_i, \Sigma_i) = \dfrac{1}{(2\pi)^{\frac{d}{2}}\sqrt{|\Sigma_i|}}
\exp \left({-\dfrac{1}{2}(x-\mu_i)^T\Sigma_i^{-1}(x-\mu_i)}\right)\]
subject to
\[\sum_{i=1}^{K} w_i = 1\]

  Therefore, GMM is merely a weighted combination of multivariate Gaussian distribution which
  assumes feature vectors are independent.
  (Actually we use diagonal covariances since the dimensions of the feature vector is independent to each other).
  GMM can describe the distribution of feature vector with several clusters, as shown in \figref{gmm-fig}
\begin{figure}[H]
  \centering
  \includegraphics[width=0.8\textwidth]{img/gmm.png}
  \caption{A Two-Dimensional GMM with Two Components\label{fig:gmm-fig}}
\end{figure}

The training of GMM is the process to find the best parameters for $ \mu_i, \Sigma_i, w_i$,
so that the model fits all the training data with maximized likelihood.
More specifically, Expectation-Maximization(EM)
Algorithm\cite{bilmes1998gentle} is used to maximize the likelihood.
The two steps of one iteration of the algorithm in GMM training case here are
\begin{itemize}
	\item \textbf{E-Step} For each data point(feature vector), estimate the probatility that
		each Gaussian generated it\footnote{Actually, for an arbitrary point in
			space, its measure is zero, therefore its ``probability'' is
			actually zero. Therefore, here by ``probability of $x$'' we mean
			``the value of probability distribution function at $x$'' }.
			This is done by direct computation using \eqnref{gmm}.
	\item \textbf{M-Step} Modify the parameters of GMM such that maximize the
		likelihood of data. Here, hidden variable $z_{ij}$ is introduced
		to indicate where $i$-th data point is generate by Gaussian $j$.
		It can be shown that, instead of maximizing the
		likelihood of data, we can maximize the expectation of log likehood
		of data with respect to $Z$.

		let $\theta = \{w, \theta, \Sigma\}$, the log likehood function is
		\[Q(\theta', \theta) = \mathbb{E}_{Z} [\log p(X, Z) | \theta]\]
		where $\theta$ is current parameters, and $\theta'$ is the parameters
		we are to estimate. Incorporating the constraint $\sum_{i=1}^{K} w_i = 1$ using
		Lagrange multiplier gives
		\[J(\theta', \theta) = Q(\theta', \theta) - \lambda\left(\sum_{i=1}^{K} w_i - 1 \right)\]
		Set derivatives to zero, we can get the update equation
		\[Pr(i| x_j) = \dfrac{w_i \mathcal{N}(x_j | \mu_i', \Sigma_i')}{
			\sum_{k=1}^{K} w_k \mathcal{N}(x_j | \mu_k' \Sigma_k')}\]
		\[n_i = \sum_{j=1}^N Pr(i| x_j)\]
		\[\mu_i = \dfrac{1}{n_i} \sum_{t=1}^{T} Pr(i |x_j) x_j\]
		\[\Sigma_i = \left(\dfrac{1}{n_i} \sum_{t=1}^{T} Pr(i |x_j) diag(x_j x_j^T)\right) -
		diag(\mu_i' \mu_i'^T)\]
		\[w_i = \dfrac{n_i}{N}\]

\end{itemize}

After training, the model can give the score of fitness for every input feature vector,
measuring the probability that the vector belongs to this model.

Therefore, in the task of speaker recognition, we can train a GMM for every speaker.
Then for a input signal, we extract lists of feature vectors for it, and calculate the
overall likelihood that the vectors belong to each model.
The speaker whose model fits the input best will be choosen as the answer.

Moreover, an enhancement have been done to the original GMM method.
The training of GMM first requires a random initialization of the means of
all the components. However, we can first use K-Means algorithm\cite{kmeans} to perform a clustering
to all the vectors, then use the clustered centers to initialize the training of GMM.
This enhancement can speed up the training, also gives a better training result.

On the calculation of K-Means, an algorithm call K-MeansII\cite{bahmani2012scalable},
which is an improved version of K-Means++\cite{arthur2007k} can be used for better accuracy.

%\begin{itemize}
  %\item Performance: \\ We investigate the effect of initialization of GMM during
    %training. We implemented GMM with
    %K-meansII\cite{bahmani2012scalable}, which is an improved
    %version of K-means++\cite{arthur2007k} to initialize the
    %mean vector of GMM. Results shows improvements compared
    %to GMM provided by \textbf{scikit-learn\cite{scikit-learn}}.
  %\item Efficiency:
    %\begin{itemize}
      %\item We provide a parallel version of GMM, especially
        %optimized to train large Universal Background Model(UBM).
      %\item We further improve efficiency by utilizing
        %SSE instruction in computing exponential function
        %using polynomial approximation. This can speed up
        %the training procedure by a factor of two.
    %\end{itemize}
%\end{itemize}

\subsection{UBM}

\textbf{Universal Background Model} is a GMM trained on giant number of speakers.
It therefore describes common acoustic features of human voices.\cite{UBM}

As we are providing continuous speech close-set diarization function in
GUI, we adopt \textbf{Universal Background Model} as imposter model using equation
given in \cite{reynolds2000speaker}
and use likelihood ratio test to make reject decisions as proposed in\cite{reynolds2000speaker}.

Further more, by hints mentioned in paper, we only update mean vectors.

When using conversation mode in GUI (will be present later),
GMM model of each user is adapted from a pre-trained UBM
using method described in \cite{reynolds2000speaker}.

\subsection{CRBM}

\textbf{Restricted Boltzmann Machine} is generative stochastic
two-layer neural network that can learn a probability distribution
over its set of binary inputs\cite{rbm_wiki}.  \textbf{Continuous
restricted Boltzmann Machine(CRBM)}\cite{chen2003continuous} extends
its ability to real-valued inputs.  RBM has a ability to, given an
input(visible layer), reconstruct a hidden layer that is similar
to the input.  The neurons
in hidden layer controls the model complexity and the performance of
the network. The Gibbs sampling of hidden layer can be seen as a
representation of the original data. Therefore RBMs can be used
as an auto feature-extractor.
\figref{crbm} illustrate original MFCC data and the
sampled output of reconstructed data from CRBM.

Both RBM and CRBM can be trained using Contrastive Divergence learning,
with subtle difference in update equation.

As details about CRBM are too verbose to be covered here, for interested,
we recommend reading original papers.

Previous works using neural network largely focused on speech
recognition, such as \cite{deep},\cite{mohamed2011deep}.

\begin{figure}[H]
  \begin{minipage}{0.48\linewidth}
    \centering
    \includegraphics[width=\linewidth]{img/rbm-original.png}
    \caption*{The first three dimension of a woman's MFCC feature}
  \end{minipage}
  \hfill
  \begin{minipage}{0.48\linewidth}
    \centering
    \includegraphics[width=\linewidth]{img/rbm-reconstruct.png}
    \caption*{The first three dimension of the same woman's MFCC feature
      recontructed by a CRBM with 50-neuron hidden layer. We can
      see that, the density of these two distributions are alike}
  \end{minipage}
  \caption{\label{fig:crbm}}
\end{figure}

To use CRBM as a substitution of GMM, rather than
an feature extractor, we train a CRBM per speaker,
and estimate reconstruction error without sampling (which is stable).
The person whose corresponding CRBM has lowest reconstruction error is chosen as

recognition result.

\subsection{JFA}

\textbf{Factor Analysis} is a typical method which behave
very well in classification problems, due to its ability to
account for different types of variability in training data.
Within all the factor analysis methods,
Joint Factor Analysis (JFA)\cite{jfa2,jfa-se} was proved to outperform other method
in the task of Speaker Recognition.

JFA models the user by ``supervector'' , i.e. a $C\times F $ dimension vector, where $C$ is
the number of components in the Universal Background Model, trained by GMM on all the training data,
and $ F$ is the dimension of the acoustic feature vector. The supervector of an utterance is obtained by concatenate
all the $C $ means vectors in the trained GMM model. The basic assumption of JFA on describing a supervector is:

\[ \vec{M} = \vec{ m } + vy + dz + ux, \]

where $m$ is a supervector usually selected to be the one trained from UBM, $v$ is a $ CF \times R_s$ dimension matrix,
$ u$ is a $ CF \times R_c$ dimension matrix, and $d$ is a diagonal matrix.
This four variables are considered independent of all kinds of variabilities and remain constant after training, and
$x, y, z $ are matrixes computed for each utterance sample.
In this formulation, $ m + vy + dz$ is commonly believed to account for the ``Inter-Speaker Variability'', and $ux $ accounts
for the ``Inter-Channel Variability''.
The parameter $ R_s $ and $ R_c$, also referred to as ``Speaker Rank'' and ``Channel Rank'', are two emprical constant selected as first.
The training of JFA is to calculate the best $ u, v, d$ to fit all the training data.


text:
\documentclass{article}
\begin{document}
	\section{Science Discoveries}
	Some of the \textbf{greatest}
	discoveries in $\underline{science}$
	were made by
	\textbf{\textit{accident}}.

	\paragraph{}
	Some of the greatest discoveries in science were made by \emph{accident}.

\end{document}

max_stars_repo_path: ARIYIBI iSEOLUWA/practice 5.tex

max_issues_repo_path: ARIYIBI iSEOLUWA/practice 5.tex

max_forks_repo_path: ARIYIBI iSEOLUWA/practice 5.tex


text:
% Appedix
\appendix

\begingroup

\chapter{Source Code}
\label{app:code}

\section{JPEG CODEC Code in Python}
\label{app:sec:python}

\subsection{Python-MATLAN Interface \texttt{matlab.py}}
\lstinputlisting[caption={Code of Python-MATLAN Interface \texttt{matlab.py}.},captionpos=t,language=Python]{Code/matlab.py}

\endgroup


text:
\documentstyle[a4]{article}
\pagestyle{myheadings}
\markboth{Author:kk}{Doc.No. AID/newsletter/2}
\setlength{\textheight}{9in}
\setlength{\topmargin}{0in}
\setlength{\headheight}{.3in}
\setlength{\headsep}{.5in}
\parindent=0pt
\parskip= .35\baselineskip plus .0833333\baselineskip minus .0833333\baselineskip
\begin{document}
Artificial Intelligence for Development\\
Document No: AID/newsletter/2\\
Last Modified and by whom: 1/3/91 kk \\
Distributed on:  1/3/91\\
\LARGE
\begin{center} Artificial Intelligence for Development\\
Newsletter Number 2\\March 1991\\
\end{center}
\normalsize

This newsletter is being sent by both electronic and paper mail. If
you no longer wish to receive it, or have any contributions or
comments on its content, please contact KK by any of the normal
methods. Contributions will be particularly well received!
We seem to be having a problem getting through to some folk by email. If you
receive a paper copy of this and not an electronic one, but think you
{\em should} be receiving an electronic one, make yourself known.

\section{ LUPES - knowledge-based land use allocation.}
For those of you who didn't make it to the last meeting, {\bf Robert
Muetzelfeldt} here outlines the elements of the project he spoke on and
demonstrated. If you would like to see or use LUPES, contact RM.

LUPES is a program designed to allocate a land use to each of a number of
patches of land ("zones").   The aim is to mimic the reasoning methods of the
human land use planner to the extent possible.
The major constraint that LUPES applies is that you must represent an area in
terms of a number of discrete zones.   Each zone is assumed to be internally
uniform (homogenous), and can have only one land use applied to it.
Each zone has a number of boundaries (which can be shared between a
neighbouring zone; each boundary has a set of co-ordinates.   The co-ordinate
information is used for display purposes only: the landuse allocation part
could operate without this co-ordinate information.

It is entirely up to the user to specify zone attributes: these should be
attributes that influence landuse allocation decisions.   They can include
obvious things like soil, altitude, and current land use, as well as more
subtle things like which zones are next to it, distances from roads or points,
etc.   The full power of Prolog is available to enable this information to be
asserted as facts or inferred from other information: for example, land
capability can be inferred from soil, altitude, etc; contiguity can be
inferred from the sharing of boundaries; distances can be inferred fromthe
co-ordinate information.

Allocation of landuse to a zone is controlled by two types of rule. The
'compatible-with' rule specifies which landuse is compatible with which zone.
This draws on zone attributes, but can also draw on the attributes of any
other zones in the area, including those which are known to be contiguous.
Most importantly, the 'compatible-with' rules can also draw on knowledge about
the allocations that have been made so far in the allocation process: for
example, there may be a requirement that all allocations of a certain type of
landuse are contiguous, which is expressed as 'landuse U is compatible-with
zone Z if Z is next to Z1 and Z1 has already been allocated U' (but in Prolog,
of course).   So, these rules offer great expressiveness: you could check for
things like preferred ratios between different landuses, for example. The
challenge is to see if there are things you would like to express that can NOT
be captured with these rules.

The second type of allocation rule is 'requirement-failure': it checks at the
end of the allocation process for things that can only be sensibly checked at
that stage: e.g. that at least one of the zones has forestry, or that there is
a minimum area of maize; or that the total revenue exceeds a certain amount.
So, the user can supply information specific to a particular area; and, at a
higher level, rules about allocation (which presumably will apply to many
areas of the same type).   At a still higher level, the user can specify how
the allocation process is actually to proceed.   In particular, LUPES needs to
know which zone to try to allocate next.   I could have built in one
particular strategy (e.g. take the next one off a list of all the zones), but
it is important for me that LUPES should mimic to the extent possible the way
that human landuse planners go about there task. Therefore, the user can
specify (in Prolog) 'any' arbitrary strategy for choosing the next zone to try
- e.g. choose the most constrained zone; the one with the largest area; a zone
that is next to one that has already  \ been allocated a landuse; or whatever.
There are various ramifications here, but this should give you a feel of the
way in which I'm trying to give the user as much control as possible.

There's currently a demo version of LUPES running on a Mac II using LPA
MacProlog in colour.   It provides extra facilities for user interaction - the
user can directly allocate a landuse to a zone (provided its compatible); find
out all the zones that can have a certain landuse applied to them; etc.
However, I stress that what I have now is essentially a rather crude
prototype, and is not in a form that I'd be prepared to release. However, it
is being used in a current M.Sc. dissertation, and is the basis for a Ph.D. on
farm forestry in Scotland that has just started.

\section{News from around the world}
Contributions to this section are particularly welcome. Personal
experience from living and working in a country, or even having
visited for a short time, is always interesting, and this is also a
good forum to pass on informal knowledge gleaned from other sources.

\subsection{Computing Facilities in South America}
{\bf Ehud Reiter} tells us what he did on his holidays:

I spent November - January in South America, mostly on holiday but I did
visit some university computer science departments.  The quality was quite
variable.  The best place I visited was the University of the Andes
(Venezuela), where there were rooms full of Sparcstations and the
faculty published regularly
in international journals.  The worst was the Central University of Quito
(Ecuador), which had lots of tear gas (gassings at least once a week), but
very few computers (20 PC's and two old 16-bit Data General minis for 70,000
students).  The quality of the graduates reflected the availability of
resources: University of the Andes computer students seemed to usually know
what they were doing, while Central University of Quito students typically
had to be retrained from scratch after graduation if they got a computer job.
I suspect, unfortunately, that most South American universities are a lot
closer to the Central University of Quito than the University of the Andes.

It did seem to me that there was a substantial amount of demand for computers
and computer skilled people, mostly for standard business applications
(spreadsheets, word processing, accounts, etc) on PC's or large IBM machines.
I did not run across any AI applications.  Among the biggest problems faced
by potential computer users was high prices (higher than in the UK) and
the lack of manuals or how-to books in Spanish.

\subsection{ Mail connections to Africa}
The following correspondence took place the net newsgroup
soc.culture.african, and is of varying ages and veracity.  I thought
some of you might be interested in this aspect of computing in
developing countries.

{\bf John Pearce}, of Silma, Inc. Cupertino CA originally asked the
following:\\
``I will be leaving for Zimbabwe on a Fulbright in January
to teach Computer Science at the University in Harare.
Naturally, the University suffers from lack of equipment,
expertise, and ability to import equipment due to currency
controls. I would like to remedy this situation somewhat by
trying to set up a simple network of PCs with a file server
and possibly an Internet connection. I would appreciate
hearing suggestions from anyone about

1. computer networks or hosts anywhere in Southern Africa \\
2. corporations that might be interested in donating equipment\\
3. computer companies that do business in the region''

{\bf Philip Machanick} of the Computer Science Department, Stanford
University replied:\\
``It is possible to reach South African universities via fidonet.
A better setup is being worked on. At the moment, you may find
political obstacles to dealing with SA universities from Zimbabwe,
but this could change while you are there. If you are interested,
e-mail me and I'll suppply you with addresses/phone numbers of people
who'll be interested in your work in Zimbabwe.
I heard a rumour at one point that Apple was thinking of the
possibility of donations of used (but not yet obsolete) computers
to the third world. Just a rumour - it won't hurt to ask.
Here's one contact: Pan Africa Computer Services, the Apple
distributor for Southern Africa. Philip Noyce can be reached at
(508) 256-6887.
You may also want to look out for a copy of Computers in Africa,
published by Africa File, 21 Mill Lane, London, NW 6 1NT, UK (phone
London 794-5308). Subscriptions were 32 pounds a year when I last checked.
I don't have the most recent issue with me, but they have a fair number
of ads, which gives you an idea of who sells in Zimbabwe.
I would check to see if you can bring the equipment with you, rather than
getting it there. I have an idea that a scholarship like Fulbright entitles
you to bring in equipment duty free (?). Prices in Zimbabwe were extrememly
inflated when I last investigated this issue, owing to restrictions on foreign
currency.''

{\bf F.F. Jacot Guillarmod} of Rhodes University, Grahamstown RSA responded:\\
``I would like to point out that the newsgroup 'soc.culture.african' is
being received and distributed to the following academic sites in
South Africa: Rhodes University Grahamstown, University of Cape Town,
University of Natal Durban.
As soon as a dedicated TCP/IP data line is in place, the University of
Fort Hare in Alice will also be receiving netnews.  More distant is a
dialup uucp link to the University of Zimbabwe in Harare (early 1991),
and a dial up uucp link to the University of Namibia in Windhoek.''

\subsection{Editor's comment}
The note
about dialup links to Zimbabwe is of interest as in the latest
`African Technology Forum' Anuradha Vedantham writes that ``Since the
government outlaws modems as a national security measure, no
electronic mail contact is possible from Zimbabwe''. I understood that
the University of Zimbabwe at one point had a modem link in its
medical library, to access overseas library databases, but that this
was discontinued bbecause of cost. Maybe someone in the know can
enlighten us as to the truth of the matter. It would be
interesting to have further information as to the extent of the
electronic mail network around the globe, especially to developing
countries. Opening channels of quick and effective communications is
one of the most successful ways of initiating technology transfer.

\section{Next meeting:}
Please send suggestions for future meetings to KK. Unfortunately we
have no finances to pay for visiting speakers, but if you know of
anyone interesting who'll be in town (or within the sort of vicinity
that it wouldn't bankrupt us to get them here) and would like to speak
to the group at some point, please get in touch. Perhaps {\em you}
would like to give a short talk...

Dan Walker's talk on March 7th has been postponed. The next meeting
will be:

On {\bf Thursday May 2nd}
at 5.30 pm in Room F10, AI Dept, 80 South Bridge,
Teresa Anderson will speak on {\em ``AI for Rural Electrification in Nepal:
Experiences with laptops 14000 feet up in the Annapurnas''}  and give
a software demonstration.

\section{Journals and Literature Additions}
 Another journal that might be of interest to readers is:
 {\bf  VITA (Voulunteers in technical Assistance) News}, although
 rumour (ER) has it that his has been electronicised. Does anyone have
 further information?

The following new items have come into our
possession. Contact ER if you'd like to look at them.
\begin{enumerate}
\item African Technology Forum, volume 3 number 3 containing a short
article about the AI for Development Group, December 1990.
\item `The Development of Information Systems in the Third World', MSc
Thesis by R. A. Felts from LSE Systems Research Group, 1986/7.
\item `Health Informatics in Developing Countries', PhD thesis by Dayo
Forster from LSE Department of Information Systems, 1990.
\item `AI Research in China: a review', by Xinsong, J.
and Guoning, S. and Yu, C, from Proceedings of IJCAI 1983
\end{enumerate}
\section{Contact Personnel}
\begin{tabular}{l|l}
{\bf Software library:} & {\bf Newsletter, overall co-ordination,
meetings:}\\
Howard Beck &  Kathleen King\\
Artificial Intelligence Applications Institute &  Department of
Artificial Intelligence \\
University of Edinburgh & University of Edinburgh\\
80 South Bridge & 80 South Bridge\\
Edinburgh EH1 1HN & Edinburgh EH1 1HN\\
031-225-7774 x208 & 031 225 7774 x236\\
hab@uk.ac.ed.aiai & kk@uk.ac.ed.aipna\\
\hline
{\bf Addresses and contacts, funding:} & {\bf Distribution of
information, newsgroup etc:}\\
Robert Muetzelfeldt & Olly Morgan\\
Department of Forestry and Natural Resources &  School of Agriculture\\
University of Edinburgh & University of Edinburgh\\
Kings Buildings & Kings Buildings\\
 Mayfield Road &  West Mains Road\\
Edinburgh   EH9 3JU & Edinburgh   EH9 3JU\\
 031 667 1081 & 031 667 1081\\
 R.Muetzelfeldt@uk.ac.edinburgh &  O.Morgan@uk.ac.ed\\
\hline
{\bf Literature resource and bibliography:} &\\
 Ehud Reiter &\\
 Department of Artificial Intelligence &\\
 University of Edinburgh &\\
 80 South Bridge &\\
 Edinburgh EH1 1HN &\\
 031 225 7774 x294 &\\
reiter@uk.ac.ed.aipna &

\end{tabular}

\end{document}

max_stars_repo_name: ashok-khanna/cmu-ai-repository

max_issues_repo_name: ashok-khanna/cmu-ai-repository

max_forks_repo_name: ashok-khanna/cmu-ai-repository


text:
\section{Data Sets}
\label{sec:data-sets}

max_stars_repo_name: gmarciani/research

max_issues_repo_name: gmarciani/research

max_forks_repo_name: gmarciani/research


text:
\section{White box and black box methods}
Generally there are two types of methods for interpretability: Black box and white box. White box methods need access to the neural network parameters (weights, biases etc.) and/or the individual activations of neurons inside the networks when an image is processed by it. Some white box methods only work with the network parameters itself, others explain the network output for specific sample inputs.

Black box methods only work with the input (e.g. images) and the output (e.g. classes) of a neural network and can be used on arbitrary network architectures and even non-deep learning technologies like decision trees. Black box methods only work with specific sample inputs and cannot analyze the network in a general way.


text:
\section{Shapley Feature Importance}

\begin{frame}[c]
\Huge{\centerline{Shapley Feature Importance}}
\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Overview of SHAP: SHapley Additive exPlanations}

	\begin{itemize}
		\item \textbf{What:} SHAP values provide feature importance for a complex model, through numeric values that are easy for humans to understand.
		\bigskip
		\item \textbf{Why:} SHAP is a unified framework that reveals the relationship between other published interpretability techniques [citations needed], as well as solutions to these techniques that are easier to interpret and satisfy the SHAP properties.
		\bigskip
		\item\textbf{Examples:}  Interpretability methods that fall under the SHAP framework. \textit{Shapley Feature Importances} explicitly apply SHAP framework and satisfy its constraints, while \textit{LOCO} and \textit{Feature Importance} fall under the SHAP framework but are not designed to satisfy the SHAP Properties.
	\end{itemize}
\end{frame}
%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{SHAP: SHapley Additive exPlanations (Cont.)}

The following slides summarize and explain the work found in [\cite{shapley}].

\end{frame}
%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Explanation Models}

	\begin{itemize}
	\item \textbf{Explanation models:} a form of surrogate models, explanation models $h$ are designed to provide an interpretable approximation of a complex model.
	\bigskip
	\item  \textbf{Simplified inputs:} a binary vector $\mathbf{x'}$, of interpretable values, that maps to a given training observation $\mathbf{x}$, through a mapping function $M_\mathbf{x}$ specific to $\mathbf{x}$, such that $\mathbf{x} = M_\mathbf{x}(\mathbf{x'})$.
	\bigskip
	\item  \textbf{Local methods:} are techniques to explain a model's prediction for a specific observation, as oppose to observations in general.  When a local method works well, $h(\mathbf{z'}) \approx g(M_\mathbf{x}(\mathbf{z'}))$ whenever $\mathbf{z'} \approx \mathbf{x'}$.
	\end{itemize}

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Additive Feature Attribution Methods}
Additive feature attribution methods sum up the feature attributions of an observation  $\mathbf{x}$ to approximate and thereby explain the prediction $g(\mathbf{x})$ corresponding to that observation.
	\bigskip
	\begin{itemize}
	\item  \textbf{Definition 1}  additive feature attribution methods use an explanation model that is a linear function of binary variables:
	\end{itemize}

	\begin{equation}
	\begin{aligned}
		h(\mathbf{z'})= \phi_0 + \sum_{j=1}^P \phi_j z'_j,
	\end{aligned}
	\end{equation}

	$\phi_j$: each feature's attributed impact, where $\phi_j \in \mathbb{R}$.\\
	$P$: the number of predictors. \\
	$\mathbf{z'}$: the binary vector where $\mathbf{z'} \in \{0,1\}^P$.

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Review of Cooperative Game Theory's Shapley Number}
\begin{itemize}
	\item \textbf{Cooperative Games:} a game in which players benefit from teaming up rather than playing independently.
	\bigskip
	\item \textbf{The Shapley Number:} a numeric value that determines how much a player should gain or lose, given the number of players and the value attributed to each if they were to play independently. 	\begin{itemize}
		\bigskip
		\item the Shapley Number is easy to calculate when there only a few players: it's the average value of all possible combinations for each player.
	\end{itemize}
\end{itemize}
\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Shapley Number Axioms}
The Shapley Number calculation is based on the following three axioms:
\begin{itemize}
	\bigskip
	\item \textbf{Efficiency}: the sum of the amounts attributed to each player must equal the total amount attributed to the players when they play together.
	\bigskip
	\item \textbf{Symmetry}: changing the names of players doesn't affect the attributed importance of each player.
	\bigskip
	\item \textbf{Monotonicity:} If the total value of a game increases the value attributed to each player will not decrease. This axiom includes the linearity axiom - the sum of players playing individually has to equal the sum of them playing together - and the null effect axiom - players that don't participate don't contribute to the game.
\end{itemize}

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Game Theory Axiom Applied to Machine Learning}
The previous Shapley Number axioms can be applied as constraints to solve a SHAP explanation model. Below are the SHAP properties and their mapping to the Shapley axioms.
	\bigskip
\begin{itemize}
	\item Local Accuracy $\sim$ Efficiency Axiom
	\bigskip
	\item Missingness $\sim$ Null Effect Axiom - adapted to handle missing data
	\bigskip
	\item Consistency  $\sim$ Monotonicity Axiom

\end{itemize}

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Local Accuracy Property}
To satisfy the local accuracy property, an explanation model $h$ should return the same prediction as the complex model $g$, given a simplified input $\mathbf{x'}$ that maps back to $\mathbf{x}$ via the mapping function $M_\mathbf{x}$. Specifically,

	\begin{equation}
	\begin{aligned}
		&\text{if } \mathbf{x} = M_\mathbf{x}(\mathbf{x'}), \phi_0 = g(M_\mathbf{x}(\mathbf{0})),\\
		&\text{and } h(\mathbf{x'})= \phi_0 + \sum_{j=1}^P \phi_j x'_j,\\
		&\text{then } g(\mathbf{x}) = g(M_\mathbf{x}(\mathbf{x'})) = h(\mathbf{x'}).
	\end{aligned}
	\end{equation}

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Missingness Property}
If a feature value is missing during training, that implies it shouldn't have an attributed effect value. Remember that $x_j' = 0$ means the original input value $x_j$ is not present.

	\begin{equation}
	\begin{aligned}
		x_j' = 0 \implies \phi_j = 0
	\end{aligned}
	\end{equation}

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Consistency Property}
If a model changes and the change causes a feature to have a larger impact on the model's predicted value for a simplified input (or keep it the same), the feature's new attributed value cannot decrease.\\
\vspace{\baselineskip}
Let $g_\mathbf{x}(\mathbf{z'}) = g(M_\mathbf{x}(\mathbf{z'}))$, and $\mathbf{z'} \: \backslash \: j$ denote setting $z_j' = 0$.\\
\vspace{\baselineskip}
Let  $g$ and $g'$ be any two models, if\\
	\begin{equation}
	\begin{aligned}
		g_\mathbf{x}'(\mathbf{z'}) - g_\mathbf{x}'(\mathbf{z'} \: \backslash \: j) \geq g_\mathbf{x}(\mathbf{z'}) - g_\mathbf{x}(\mathbf{z'} \: \backslash \: j), \: \forall \: \mathbf{z'} \in \{0,1\}^P,\\
	\end{aligned}
	\end{equation}
then
	\begin{equation}
	\begin{aligned}
		\phi_j(g', \mathbf{x}) \geq  \phi_j(g, \mathbf{x})
	\end{aligned}
	\end{equation}

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Inconsistency}

Several of the other attributed feature importance calculations (gain, permutation, etc) assign inconsistent attribution values, under different models:
	\begin{equation}
	\begin{aligned}
		g_\mathbf{x}'(\mathbf{z'}) - g_\mathbf{x}'(\mathbf{z'} \: \backslash \: j) \geq g_\mathbf{x}(\mathbf{z'}) - g_\mathbf{x}(\mathbf{z'} \: \backslash \: j), \: \forall \: \mathbf{z'} \in \{0,1\}^P,\\
	\end{aligned}
	\end{equation}
and
	\begin{equation}
	\begin{aligned}
		\phi_j(g', \mathbf{x}) <  \phi_j(g, \mathbf{x})
	\end{aligned}
	\end{equation}

Even though the presence of $z_j' $ shows a larger difference for $g'$ then $g$, its attributed effect for the original input $\phi_j(g', \mathbf{x})$, is less.

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{SHAP Theorem 1}
\textbf{SHAP Theorem 1}: only one possible explanation model $h$ follows from SHAP Definition 1 and satisfied Properties 1-3:

	\begin{equation}
	\begin{aligned}
		\phi_j(g,\mathbf{x}) = \sum_{\mathbf{z'} \subseteq \mathbf{x'} } \frac{\left\vert{\mathbf{z'}}\right\vert!(P-\left\vert{\mathbf{z'}}\right\vert-1)!}{P!} \left[g_\mathbf{x}(\mathbf{z'}) - g_\mathbf{x}(\mathbf{z'} \: \backslash \: j) \right]
	\end{aligned}
	\end{equation}

$\left\vert{\mathbf{z'}}\right\vert$: the number of non-zero entries in $\mathbf{z'}$\\
$\mathbf{z'} \subseteq \mathbf{x'}$: represents all $\mathbf{z'}$ vectors where the non-zero entries are a subset of the non-zero entries in $\mathbf{x'}$.
\bigskip
\begin{itemize}
	\item This theorem implies that methods which fall under the explanation model but are not solved in consideration of the Shapley values likely break the local accuracy and/or consistency properties.
\end{itemize}

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{SHAP Values Overview}

As stated in [\cite{shapley}]: "SHAP values are the Shapley values of the complex model's conditional expectation function. This means that SHAP values attribute to each feature the change in the expected model prediction when conditioning on that feature."\\

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{SHAP Approximations}
SHAP values makes the following simplifications and approximations:\\
\bigskip
\begin{itemize}
\item Defined simplified input mapping:
	\begin{equation}
	\begin{aligned}
		g(M_\mathbf{x}(\mathbf{z'})) = \mathbb{E}\left[ g(\mathbf{z})\right | \mathbf{z}_s ] =  \mathbb{E}_{\mathbf{z}_{\bar{s}} | \mathbf{z}_s }\left[ g(\mathbf{z})\right]
	\end{aligned}
	\end{equation}

\item Assumptions of feature independence:
	\begin{equation}
	\begin{aligned}
		g(M_\mathbf{x}(\mathbf{z'})) \approx  \mathbb{E}_{\mathbf{z}_{\bar{s}}}\left[ g(\mathbf{z})\right]
	\end{aligned}
	\end{equation}
\item Assumptions of model linearity:
	\begin{equation}
	\begin{aligned}
		g(M_\mathbf{x}(\mathbf{z'})) \approx  g(\left[ \mathbf{z}_s, \mathbb{E} \left[\mathbf{z}_{\bar{s}}\right] \right])
	\end{aligned}
	\end{equation}
\end{itemize}
Where $M_\mathbf{x}(\mathbf{z'}) = \mathbf{z_s}$, $S$ is the set of non-zero indexes in $\mathbf{z'}$, and $\bar{S}$ is the set of features not in $S$.

\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{SHAP Values For Tree Ensemble Feature Attributions}

Given
	\begin{equation}
		\begin{aligned}
		g_\mathbf{x}(S) = g(M_{\mathbf{x}}(\mathbf{z'}))= \mathbb{E}\left[ g(\mathbf{x})\right | \mathbf{x}_s ]
		\end{aligned}
	\end{equation}

where $S$ is the set of non-zero indexes in $\mathbf{z'}$ and $ \mathbb{E}\left[ g(\mathbf{x})\right | \mathbf{x}_s ]$ is the expected value of the function conditioned on a subset of $S$ input features. We can calculate the attribute value $\phi_j$ of each feature:

\begin{equation}
	\begin{aligned}
\phi_j(g,\mathbf{x}) = \sum_{S \subseteq P \: \backslash \: \{j\}} \frac{\left\vert{S}\right\vert!(P-\left\vert{S}\right\vert-1)!}{P!} \left[ g_\mathbf{x}(S \cup \{j\}) - g_\mathbf{x}(S) \right]
	\end{aligned}
	\end{equation}

again, $P$ is the set of all features, so $P \: \backslash \: \{j\}$ removes the $jth$ feature from the set.
\end{frame}

%----------------------------------------------------------------------------------------

\begin{frame}\frametitle{Some techniques that fall under Additive Feature Attribution Methods}
Each of the following interpretability techniques, are specific implementations of the SHAP explanation model.
	\begin{itemize}
		\item LOCO
		\item Tree-Interpreter
		\item LIME
		\item DeepLIFT
		\item Layer-Wise Relevance Propagation
		\item Shapley Regression Values
		\item Shapley Sampling Values
		\item Quantitative Input Influence
	\end{itemize}
\end{frame}


text:
\documentclass[a4paper]{article}

% Set up page size
\usepackage[margin=1.5cm, includefoot, footskip=30pt]{geometry}

% Nice way to display code
\usepackage{minted}

% Import images
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{multicol}

\title{The Monty Hall problem and the effect of goats}
\author{Vince Knight}
\date{}

\begin{document}
\maketitle

\section{Introduction: The Monty Hall Problem}

The Monty hall problem is a probabilistic problem based on a game
show~\cite{rosenhouse2009monty}. In this show a contestant was presented with
three doors. Behind one of the doors was a car and behind the others was a
goat. The contestant would choose a door (which would thus either be hiding a
goat or a car) and the host would then open a door showing the location of the
goat. At this stage the contestant had a strategic choice:

\begin{itemize}
    \item Stick: if their original choice had the car they won!
    \item Switch: take whatever was behind the remaining door.
\end{itemize}

This puzzled many mathematicians for years as it might seem that the contestant
is given a false choice and the probability of winning is in fact the same
whether or not they switch. This is however not true: if the contestant
switched they doubled their probability of winning!

In this work, we will hopefully clarify this by considering what happens if we
modify the game: let us have \(n\) goats behind \(n\) doors. Everything else
remains the same: the host still opens one of the doors behind which is a goat.

In Section~\ref{sec:simulation} Python will be used to simulate both strategies
and find the probability of winning. Then in
Section~\ref{sec:analytical_formulae} a mathematical formula for the probability
of winning will be obtained and verified.

\section{Simulating more goats}\label{sec:simulation}

Here are two python functions that simulate sticking or switching with a given
number of goats:

\begin{minted}{python}
import random

def stick(number_goats=2):
    """A function to simulate a play of the game when we stick"""
    doors = ['Car'] + number_goats * ['Goat']

    initial_choice = random.choice(doors)  # make a choice
    return initial_choice == 'Car'

def switch(number_goats=2):
    """A function to simulate a play of the game when we swap"""
    doors = ['Car'] + number_goats * ['Goat']

    initial_choice = random.choice(doors)  # make a choice

    doors.remove(initial_choice)  # Switching: remove initial choice
    doors.remove('Goat')  # The game show host shows us a goat

    new_choice = random.choice(doors)   # We choose our one remaining option

    return new_choice == 'Car'
\end{minted}

Using this we can simulate the probabilities for the case of 2 goats (the
original TV show!):

\begin{minted}{python}
>>> repetitions = 10000
>>> random.seed(0)
>>> prob_win_stick = sum([stick() for rep in range(repetitions)]) / repetitions
>>> prob_win_switch = sum([switch() for rep in range(repetitions)]) / repetitions
>>> prob_win_stick, prob_win_switch
(0.3346, 0.6636)
\end{minted}

This indeed looks like the contestant is twice as likely to win if they switch.

\section{Analytic formulae}\label{sec:analytical_formulae}

We can compute the probability \(p_n\) of winning when switching when there are
\(n\) goats. In order to win when switching:

\begin{itemize}
    \item The initial choice must not be the car. If there are \(n\) goats,
        there are a total of \(n + 1\) doors. Thus, the probability of finding
        the car is \(\frac{1}{n + 1}\). Thus, the probability of \textbf{not}
        finding the car is \(1 - \frac{1}{n + 1}\).
    \item Switching implies choosing the car from the remaining doors. There
        have however been 2 doors removed (the original choice and the one that
        the host opens). Thus the probability of choosing the car is
        \(\frac{1}{n - 1}\).
\end{itemize}

Thus:

\begin{multicols}{2}

    \begin{align}
        p_n &= \left(1 - \frac{1}{n + 1}\right)\left(\frac{1}{n - 1}\right)\\
        p_n &= \left(\frac{n + 1 - 1}{n + 1}\right)\left(\frac{1}{n - 1}\right)\\
        p_n &= \frac{n}{(n + 1)(n - 1)}\\
        p_n &= \frac{n}{(n^2 - 1)}
    \end{align}

    \columnbreak

Using Python to verify the algebra:

    \begin{minted}{python}
    >>> import sympy as sym
    >>> n = sym.symbols('n')
    >>> p_n = (1 - 1 / (n + 1)) * (1 / (n - 1))
    >>> p_n.simplify()
    n/(n**2 - 1)
    \end{minted}

\end{multicols}

The ratio of how much better it is to switch is thus given by:

\[
    \alpha_n = \frac{p_n}{1 / (n + 1)} = \frac{n}{n - 1}
\]

Finally, let us compare this formulae to simulated values.

\begin{minted}{python}
def ratio(repetitions=50000, number_goats=2):
    """Obtain the ratio of win probabilities"""
    prob_win_stick = sum([stick(number_goats=number_goats)
                          for rep in range(repetitions)]) / repetitions
    prob_win_switch = sum([switch(number_goats=number_goats)
                           for rep in range(repetitions)]) / repetitions
    return prob_win_switch / prob_win_stick
\end{minted}

\begin{minted}{python}
\end{minted}

Here is some Python code that plots this ratio (both simulated and using the
formulae) shown in
Figure~\ref{fig:simulated_v_expected_ratio_of_win_probability}.

\begin{minted}{python}
>>> random.seed(0)
>>> goats = range(2, 25 + 1)
>>> ratios = [ratio(number_goats=n) for n in goats]
>>> theoretic_ratio = [(n / (n - 1)) for n in goats]
>>> plt.figure()
>>> plt.scatter(goats, ratios, label="simulated")
>>> plt.plot(goats, theoretic_ratio, color="C1", label="theoretic")
>>> plt.xlabel("Number of goats")
>>> plt.ylabel("Ratio")
>>> plt.legend()
>>> plt.savefig("simulated_v_expected_ratio_of_win_probability.pdf");
\end{minted}

\begin{figure}[!htbp]
    \begin{center}
        \includegraphics[width=.6\textwidth]{./simulated_v_expected_ratio_of_win_probability.pdf}
    \end{center}
    \caption{The simulated and expected effect of goats on the win probability}
    \label{fig:simulated_v_expected_ratio_of_win_probability}
\end{figure}

Finally let us confirm that as the number of goats grows the effect of switching
gets smaller and smaller:

\begin{multicols}{2}

    \begin{align}
        \lim_{n\to\infty}\alpha_n & = \lim_{n\to\infty}\frac{n}{n - 1}\\
        \lim_{n\to\infty}\alpha_n & = \lim_{n\to\infty}\frac{1}{1 - 1 / n}\\
        \lim_{n\to\infty}\alpha_n & = 1
    \end{align}

    \columnbreak

Using Python to verify this calculation:

    \begin{minted}{python}
    >>> import sympy as sym
    >>> alpha_n = p_n / (1 / (n + 1))
    >>> sym.limit(alpha_n, n, sym.oo)
    1
    \end{minted}

\end{multicols}

\section{Conclusion}

This report has used mathematics and Python to shed some light on the Monty hall
problem. The modified version of the problem considers the effect of having a
given number of goats in the game.

An analytical formula is obtained for the probability of winning if the player
switches.

As the number of goats increases the beneficial effect of switching is reduced:
this makes intuitive sense as the increase of goats implies that the host makes
very little change to the problem by showing a door with a goat.

Other avenues for investigation could include seeing the effect of adding more
cars and also what happens when the host opens more doors with goats.

\bibliographystyle{plain}
\bibliography{bibliography.bib}

\end{document}

max_stars_repo_name: geraintpalmer/cfm

max_issues_repo_name: geraintpalmer/cfm

max_forks_repo_name: geraintpalmer/cfm


text:
\documentclass{article}

\usepackage{a4}

\usepackage[square,numbers,comma,sort&compress]{natbib}
\usepackage{hyperref}
\title{Heap-points-to analysis}

\begin{document}

\section{Introduction}

\subsection{why heap-points-to}

simplification, eval, apply, transformations, inline, specialise

\subsection{how does it look}

store, heap, eval, apply, environment, flow insensitive, call insensitive,
whole program, closed world, unique identifiers, abstract interpretation

- show example of an analysis result. (sum [1..10])

\section{results}

save results, keep results up to date, transformations

\section{Implementation}

retrieving equations, fixpoint

- show example equations

\subsection{Deriving equations}

- show equation derivation

select equations, case statement, artificial identifiers, result variable,
formals, actuals, unknown function application, caf variable

retrieving equations, store, eval, tag to function map, apply, function to tag
map, tag to tag map,

\subsection{fixpoint}

- the actual fixpoint implementation

dependencies, destructive updates, arrays, work list, change sets

\bibliographystyle{abbrvnat}

\bibliography{../papers}

\end{document}

max_stars_repo_name: atzedijkstra/uhc-doc

max_issues_repo_name: atzedijkstra/uhc-doc

max_forks_repo_name: atzedijkstra/uhc-doc