% this file is called up by thesis.tex
% content in this file will be fed into the main document

\chapter{Compression model}
\label{ch:exprlang}

% ----------------------- paths to graphics ------------------------

\graphicspath{{4_expression_language/images/}}

% ----------------------- contents from here ------------------------
%

\textit{Whitebox compression} is a compression model for columnar database systems. Its purpose is to represent data more compactly through elementary operator expressions. These operators---chained together into expression trees---form the expression language used for data representation. This chapter describes the \textit{whitebox compression} model, its expression language and operators, the structure of expression trees and their evaluation.

\section{Expression language}
\label{sec:exprlang:exprlang}

The \textit{whitebox} compression model represents logical columns as composite functions of physical columns. We refer to these functions as \textit{operators}. With respect to databases, logical columns are columns as seen by the database user, containing the data in its original format. Physical columns contain the physical representation of the data as it is stored on disk, in a different format.

Formally, we define an operator as a function \(o\) that takes as input zero or more columns and optional metadata information and outputs a column:
\begin{equation}
\label{eq:exprlang:exprlang:operator}
    o \colon [C \times C \times ...] \times [M] \to C
\end{equation}

The domain of \(o\) is composed of columns and metadata and the codomain is columns. A column is defined by its datatype \(d\) and the values that it contains \(V\). The metadata is structured information of any type.

We defined our expression language based on a set of elementary column representation types, each having an associated operator. They are listed in Table~\ref{tab:exprlang:exprlang_1}.

\input{4_expression_language/expression_language-table_1.tex}

The concatenation of two string columns \(c_a\) and \(c_b\) is the concatenation of each pair of values \(v_a\) and \(v_b\). E.g. \(\verb|"123abc"| = \mathit{concat}(\verb|"123"|, \verb|"abc"|)\), where \(v_a = \verb|"123"|\) and \(v_b = \verb|"abc"|\). The representation of a string column \(c_a\) as a formatted non-string column \(c_b\) consists of the individual values \(v_b\) formatted as strings based on the format string metadata \(m_{\mathit{format}}\). This can be seen as datatype change. E.g.
\(\verb|"-12000"| = \mathit{format}(\verb|-12000|, \verb|"%d"|)\), where \(v_b = \verb|-12000|\)
and
\(m_{\mathit{format}} = \verb|"%d"|\)
. The direct mapping representation of a column \(c_a\) as a column \(c_b\) through the mapping \(m_{map}\) is a key-value lookup in a dictionary-like data structure. E.g. \(\verb|"valueoncolumnA"| = dict[\verb|"valueoncolumnB"|]\), where \verb|valueoncolumnB| is the key and \verb|"valueoncolumnA"| is the value in the dictionary \verb|dict|. The constant representation of a column indicates that all its values are equal to the constant value \(m_{\mathit{const}}\). The \(\mathit{const}\) operator just returns \(m_{\mathit{const}}\).

These operators and transformations can be composed, resulting in operator expressions. For example, the logical columns \(A\) and \(B\) in Table~\ref{tab:exprlang:exprlang_2}, can be represented as composite functions of the physical columns in Table~\ref{tab:exprlang:exprlang_2}, through the following expressions:
\begin{equation}
\label{eq:exprlang:exprlang:example}
\begin{array}{ll}
    A &= \mathit{concat}(\mathit{map}(P, {dict_{AP}}), \mathit{const}(\verb|"_"|), \mathit{format}(Q, \verb|"%d"|))\\
    B &= \mathit{map}(P, {dict_{BP}})
\end{array}
\end{equation}

\input{4_expression_language/expression_language-table_2_3.tex}

We observe that column \(A\) has the following structure: a dictionary compressible prefix and a numeric suffix, separated by a the '\verb|_|' character. If we store these logical parts separated into 3 columns \(C_{\mathit{prefix}}\), \(C_{\mathit{delim}}\), \(C_{\mathit{suffix}}\), we can represent column \(A\) as their concatenation. Since \(C_{\mathit{prefix}}\) has repeated values, we can represent it more compactly as the mapping of column \(P\)---containing dictionary keys---and the dictionary \(dict_{AP}\)---presented in Table~\ref{tab:exprlang:exprlang_3}. We can represent \(C_{\mathit{delim}}\) through the \textit{const} operator since all its values are equal to '\verb|_|'. \(C_{\mathit{suffix}}\) contains numbers stored in strings. We can store these values more compactly as numbers, by changing the column datatype. Therefore, we represent \(C_{\mathit(suffix)}\) based on the numeric column \(Q\), through the \(format\) operator, with the format string \verb|"%d"|. We move our attention to column \(B\) and observe that it is correlated with column \(C_{\mathit{prefix}}\)---and implicitly also to column \(P\). We can therefore represent \(B\) as the mapping of column \(P\) and the dictionary \(dict_{BP}\)---presented in Table~\ref{tab:exprlang:exprlang_3}. In the end, we store only the physical columns \(P\) and \(Q\) and the metadata: \(dict_{AP}\), \(dict_{BP}\) and the constant string \verb|"_"|. The original values on the logical columns \(A\) and \(B\) can be reconstructed by evaluating the expressions in Equation~\ref{eq:exprlang:exprlang:example}.

So far, we described 4 column representation types and their associated operators: \(concat\), \(format\), \(map\) and \(const\). The \textit{whitebox compression} model does not limit itself to these representation types. It is a generic model and supports any type of column operators (e.g. mathematical operators like addition or multiplication). A practical example is the \textit{whitebox} version of the Frame of Reference compression method: \(const(\mathit{reference}) + C_{\mathit{diff}}\), where \(+\) is the numeric addition/sum operator, \(\mathit{reference}\) is the reference value and \(C_{\mathit{diff}}\) is the physical column containing the differences between the original values and \(\mathit{reference}\).

The purpose of \textit{whitebox compression} is to represent data more compactly through elementary operator expressions similar to the ones presented above. However, there are a multitude of different possible representations of the same logical columns, each one giving a different result. We will describe the optimization problem of finding the best representation for a set of columns in \ref{subsec:learningprocess:optimizationproblem}~\nameref{subsec:learningprocess:optimizationproblem}.

These operator expressions create more compact representations of logical columns, exploiting the underlying compression opportunities in the data. We showed how we can remove redundancy from data by representing columns as functions of other columns through the \(map\) operator and how we can store numeric values in more suitable datatypes through the \(format\) operator. We are able to decompose string columns into subcolumns with values from different distributions, thus enabling independent representations. Finally, the key factor of the \textit{whitebox} model is that it allows recursive representation of columns, ultimately leading to improved compression ratios.

\section{Expression tree}
\label{sec:exprlang:exprtree}

The operators presented so far are useful for describing the data representation and for transforming the physical data into its original logical format. We call this process \textit{decompression}. In practice, we need to transform the logical data into its physical format first---\textit{compression}. The compression process requires a different expression, one that represents the physical columns as functions of the logical columns, through the inverse operators of the ones presented until now. Table~\ref{tab:exprlang:exprlang_4} presents the compression operators types.

\input{4_expression_language/expression_language-table_4.tex}

All these operator types and their practical implementations will be discussed in detail in \ref{sec:pd}~\nameref{sec:pd}. For now, we are interested in their definition. We notice how the formal definition of the compression operator is different from the one of the compression operators:
\begin{equation}
\label{eq:exprlang:exprtree:operator:comp}
    o \colon C \times [M] \to [C \times C \times ...]
\end{equation}

The compression operators take as input a single column and compression metadata information and output 0 or more columns. Because of the multiple column output, representing physical columns as composite functions of logical columns is not straightforward. Therefore, we introduce the concept of \textit{expression trees}, as an alternative representation instead of the nested operator expressions.

\textit{Expression trees} are tree-like structures with 2 types of nodes: \textit{column nodes} and \textit{operator nodes}. We also use the term \textit{expression node} to refer to the \textit{operator nodes}---they are interchangeable. An \textit{expression tree} is composed of alternating levels of \textit{column} and \textit{operator} nodes. Root nodes are always \textit{column nodes}. Leaf nodes can be either \textit{column nodes} or \textit{operator nodes}---in the case of operators that do not output any column. An \textit{operator node} in an \textit{expression tree} is the equivalent of and operator in an operator expression: it has input columns---connected through incoming edges---and output columns---connected through outgoing edges. \textit{Expression trees} are used in the compression and decompression processes as more practical alternatives to the operator expressions. To better understand the similarities between the two, we created the equivalent \textit{expression tree} of the operator expressions for columns \(A\) and \(B\) in Equation~\ref{eq:exprlang:exprlang:example}. Recall the expressions: \(A = \mathit{concat}(\mathit{map}(P, {dict_{AP}}), \mathit{const}(\verb|"_"|), \mathit{format}(Q, \verb|"%d"|))\) and \(B = \mathit{map}(P, {dict_{BP}})\). The equivalent \textit{expression tree} is presented in Figure~\ref{fig:exprlang:exprtree:tree_1}.

\begin{figure}[h]
  \centering
  \includegraphics[width={0.9\linewidth}]{expression_language-tree_1_1.pdf}
  \caption{Expression tree representation}
  \label{fig:exprlang:exprtree:tree_1}
\end{figure}

The first thing to notice is that the \textit{expression tree} is not actually a tree, but a directed acyclic graph (DAG) with 2 root nodes. However, we chose to stick to the term \textit{expression tree} instead of graph, since it is more intuitive. In this case the graph is connected, but in other cases it can have multiple connected components. For example, imagine that in our example we had an additional logical column \(C\) that is represented as a function of a physical column \(S\), without any connection with the columns or operators used to represent columns \(A\) and \(B\). Then, our graph will have 2 connected components.

Besides the graph-like structure, the \textit{expression tree} is an equivalent representation of the operator expressions. We notice the similarities between the operator nodes and the operators in the nested expressions and the alternating levels of columns and operators. A noticeable difference is the additional columns \(A_{\mathit{prefix}}\), \(A_{\mathit{delim}}\) and \(A_{\mathit{suffix}}\). These are non-materialized internal columns that make the recursive representation possible. In terms of representation type, this is a \textit{decompression tree}, since the root nodes are the physical columns \(P\) and \(Q\) and the expression nodes are decompression operators. The \textit{compression tree} will have the same structure, only that the root nodes will be the logical columns \(A\) and \(B\) and the expression nodes will be compression operators---the inverse functions of the decompression operators. The metadata will also differ. The \textit{compression tree} can be derived from the \textit{decompression tree} and vice versa, by using the inverse operators and transforming the metadata where it is necessary.

There is the case that different subsets of the values on a column come from different distributions and cannot be represented through the same expression. E.g. a string column where odd rows contain the same constant value and even rows are numbers. These situations are common in real data, as we have seen in the Public BI benchmark, where there are not many columns for which a single representation perfectly fits all the values. One option to accommodate these cases is to allow a single column to have multiple representations. The representation of the column is then the union of its multiple representations. In terms of \textit{decompression trees}, the column will have multiple incoming edges, each one from a different operator. These multi-representation structures need to be explicitly handled in the \textit{expression tree} evaluation process (described in \ref{sec:exprlang:compdecomp}~\nameref{sec:exprlang:compdecomp}). The second option of handling these cases is through recursive representation of \textit{exception columns}, which is discussed in \ref{sec:exprlang:exceptions}~\nameref{sec:exprlang:exceptions}.

\section{Exception handling}
\label{sec:exprlang:exceptions}

While analyzing the Public BI benchmark in search for patterns and \textit{whitebox compression} opportunities we noticed that columns where all values perfectly fit the same pattern/representation are not very common. Instead there is a smaller or larger subset of values that do not fit the dominant pattern of the column. Let us take for example the data in Table~\ref{tab:exprlang:exprlang_2}. Image that a few values on column \(A\) did not have the \verb|prefix-delim-suffix| structure and instead they were just arbitrary strings. Then, the representation in Figure~\ref{fig:exprlang:exprtree:tree_1} could not be applied on the entire column. We call these values that do not match the representation: \textit{exceptions}. In the \textit{whitebox compression} model \textit{exceptions} are stored on separate \textit{exception columns}. These are nullable columns that contain \verb|null| on positions where the value was not an exception and the original values otherwise. Conversely, the non-exception columns are also nullable and contain null on the positions of exceptions.

We defined 2 ways of handling \textit{exceptions}: 1) through the multi-representation approach mentioned in \ref{sec:exprlang:exprlang}~\nameref{sec:exprlang:exprlang}; 2) through recursive representation of \textit{exception columns}. The first option implies having an operator expression for each subset of values that requires a separate representation. The second option implies choosing a single representation, storing \textit{exceptions} on a separate \textit{exception column} and then recursively applying the same process on the \textit{exceptions}. The two options are equivalent from the physical data perspective. Only the shape of the tree differs: flat and wide trees in the first case and deeper trees in the second case. An additional difference between the two options is the number of \textit{exception columns}: the first option requires at most one \textit{exception column} for every logical column (to store values that do not fit any pattern), while the second option implies having a separate \textit{exception column} for each operator node in the expression tree. The two approaches are illustrated in Figure~\ref{fig:exprlang:exceptions}.

\begin{figure}[h]
\centering
\makebox[\textwidth][c]{
\begin{subfigure}[t]{0.49\linewidth}
  \centering
  \includegraphics[width={1.0\linewidth}]{4_expression_language/images/expression_language-exceptions_1_option_1.pdf}
  \caption{Multi-representation}
  \label{fig:exprlang:exceptions:option1}
\end{subfigure}
\hspace{3em}
\begin{subfigure}[t]{0.31\linewidth}
  \centering
  \includegraphics[width={1.0\linewidth}]{4_expression_language/images/expression_language-exceptions_1_option_2.pdf}
  \caption{Recursive exception representation}
  \label{fig:exprlang:exceptions:option2}
\end{subfigure}
}
\caption{Representation options \& exception handling}
\label{fig:exprlang:exceptions}
\end{figure}

Figure~\ref{fig:exprlang:exceptions} shows the 2 equivalent representations of a string column \(A\), which has 2 major subsets of values: one containing numeric values and the other one a constant value. The figure on the left shows the multi-representation approach: the 2 operators are on the same level of the tree and the exceptions---i.e. the values that do not fit any of the 2 representations---are stored separately in the \(A_{\mathit{exception}}\) column. \(A_{\mathit{numeric}}\) and \(A_{\mathit{exception}}\) are both physical columns. The figure on the right shows the recursive exception representation: the subset of numeric values are represented through the \(format\) operator and the rest are rejected to the \textit{exception column} \(X_{\mathit{format}}\). \(X_{\mathit{format}}\) now contains the subset of constant values, and is represented through the \(const\) operator. The remaining values which are not constant are stored in the \(X_{\mathit{const}}\) \textit{exception column}. The physical columns in this case are \(A_{\mathit{numeric}}\) and \(X_{\mathit{const}}\), while \(A_{\mathit{format}}\) is just an intermediate non-materialized \textit{exception column}. The 2 representations are equivalent in terms of the physical data structure: the numeric values are stored in \(A_{\mathit{numeric}}\) and the exceptions---values that are neither numeric nor constant---are stored in the \(A_{\mathit{exception}}\) respectively \(X_{\mathit{const}}\) column.

In our implementation we used a combination of the 2 approaches: select the dominant patterns in the data and represent each column through multi-representation expressions and then store the rest of the values---which do not fit the representations---in \textit{exception columns}. If there are more opportunities left in the exceptions, recursive representation of the \textit{exception columns} is implicitly performed by the compression learning algorithm, since they are treated as normal columns.

\iffalse
- exceptions can also contain patterns; can be recursively compressed with other methods
- 2 options: 1) a single exception column per logical column (unable to recursively compress exceptions, thus we need multi-representation structures in the tree); 2) an exception column for each operator: allowing recursive compression of exceptions and implicitly used multiple representations for the same column
\fi

\section{Compression and decompression}
\label{sec:exprlang:compdecomp}

The evaluation of a \textit{compression tree} on a set of logical columns---i.e. \textit{compression}---means applying the operators on the logical values in order to generate the physical values that will be stored in the physical columns. Conversely, the evaluation of a \textit{decompression tree} on a set of physical columns---i.e. \textit{decompression}---is the process of applying the operators on the physical values to obtain the original data. The 2 process are similar and we will further discuss only \textit{decompression}.

Given a table with multiple logical columns, its expression tree (graph) will have 1 or more connected components. Each component can be evaluated independently from the other components. The decompression process starts from the root nodes and evaluates the operators on the path to the target logical/physical column, in topological order. In the case of \textit{decompression}, exceptions are handled by checking for \verb|null| values on the \textit{exception column}. If the value at a given position on the \textit{exception column} is not \verb|null| then it was an exception, otherwise the operator needs to be evaluated. A special case is when a logical data value is \verb|null| and also an exception. For this case we use a bitmap indicating which values were \verb|null| in the first place. In the case of \textit{compression}, the operators are responsible for deciding which values are exceptions and which are not: if an operator throws an exception then the value is stored on the \textit{exception column}. The \textit{compression} and \textit{decompression} processes are similar for the multi-representation structures defined in the previous sections. For \textit{compression}, the decision upon which representation fits a given value is determined by the (first) operator that does not raise an exception. If all operators raise an exception then the value is stored on the \textit{exception column}. For \textit{decompression}, the physical columns that do not contain \verb|null| values indicate the representation of each value. This process is similar to the SQL \verb|COALESCE| function \cite{sqlcoalesce}, which returns the first non-null value in a list of expressions.

The process of evaluating \textit{expression trees} in topological order is suitable for vectorized execution \cite{kersten2018everything} and SIMD instructions since the elementary operators can be evaluated in the same order for blocks of data, generating intermediate results which fit in the cache. Alternatively, JIT compilation \cite{kersten2018everything} can be used to generate compiled code for each component of the expression tree during compression time, which is then executed for each query. However, the scope of this thesis does not cover fast evaluation of expression trees. We leave this topic for future work.

% \section{Representation example}
% \label{sec:exprlang:repexamples}

% TODO-1: give example from PBIB with compression ratio and compressed execution opportunity (the one in the presentation)

% \iffalse
% - expression tree examples & compression ratio calculation + compressed execution potential; also mention thesis focus (not compressed execution)
% \fi

% ---------------------------------------------------------------------------
% ----------------------- end of thesis sub-document ------------------------
% ---------------------------------------------------------------------------

\iffalse
where:
\begin{itemize}
    \item[] \(n\) = total number of expression nodes
    \item[] \(c_{in}\) = number of input columns
    \item[] \(p\) = number of pattern detectors
    \item[] \(n_{p}\) = number of expression nodes returned by a pattern detector
    \item[] \(b\) = branching factor of the compression tree
    \item[] \(h\) = height of the compression tree
    \item[] \(c_{out}\) = number of output columns of an expression node
\end{itemize}
\fi


\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{color}
\usepackage{commath}
\usepackage{enumerate}
\usepackage{algpseudocode}

\bibliographystyle{plainnat}  % use the plainnat instead of plain

\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator*{\minimize}{minimize}
\DeclareMathOperator*{\prox}{prox}
\DeclareMathOperator*{\loss}{loss}
\DeclareMathOperator*{\reg}{reg}
\def\RR{{\mathbb R}}
\newcommand{\blue}{\color{blue}}

\newtheorem{example}{Example}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{axiom}[theorem]{Axiom}

\newcommand{\SAGA}{\textsc{Saga}}
\newcommand{\SAG}{\textsc{Sag}}
\newcommand{\LASSO}{\textsc{Lasso}}

\title{Large-scale optimization with the \textsc{SAGA} algorithm}
\author{Fabian Pedregosa \qquad Arnaud Rachez \qquad Mathieu Blondel \\\\
   % \emph{Chaire Havas-Dauphine  \'Economie des Nouvelles Donn\'ees} \\
   % \emph{Universit\'e Paris-Dauphine, PSL Research University} \\
   %  \emph{INRIA - Sierra project-team}
}
\date{\today} % {November 2015}

\begin{document}

\maketitle

\begin{abstract}
In this technical report we describe the implementation of the \SAGA\ algorithm in the lightning\footnote{\url{http://www.mblondel.org/lightning/}} python library. We discuss implementation details such as the use of lazy or lagged updates for squared $\ell_2$ and $\ell_1$ regularization.
\end{abstract}

\section{Introduction}

A large class of optimization problems in machine learning can be expressed as the minimization of a finite sum of the form
$$
\argmin_{x \in \RR^p} \left\{ \sum_{i=1}^n f_i(x) + \lambda \norm{x}^2 + \mu \Omega(x)\right\} \quad,
$$
where $\mu, \lambda$ are real constants, each $f_i: \RR^p \to \RR$ is convex and has Lipschitz continuous derivatives with constant $L$. $\Omega: \RR^p \to \RR$ is also assumed to be convex but potentially non-differentiable. We will further assume that we have acces to its proximal operator, denoted $\text{Prox}_{\mu}$.

These problems arise often in machine learning, where the cost function is a misfit over a large number of data points. The \SAGA\ algorithm~\citep{defazio2014saga} is a recently proposed algorithm to solve optimization problems of this type. As other iterative methods, this algorithm creates a sequence of iterates $w_1, w_2, \ldots$ that converge towards the desired solution $x^*$. The updates of \SAGA\ take the form
\begin{equation} \label{eq:update_rule}
x_{k+1} = \text{Prox}_{\gamma \mu}((1 - \gamma \lambda)x_k - \gamma (\nabla f_i(x_k) - {\alpha}_i + \bar{\alpha})) \quad,
\end{equation}
where $\bar{\alpha} = \sum_{i=1}^n \alpha_i$ and $\alpha_i$ is a table (memory) of historical gradients, $\gamma$ is the step size and $i$ is an index selected uniformly at random. The update rule for the historical gradients is $\alpha_i = f_i(x)$ for the selected $i$. The corrections will be used the next time the same index $i$ gets sampled. The \SAGA\ algorithm is further described in~\citep{defazio2014saga,hofmann2015variance}.

We will focus in the case in which the smooth term is linearly-parametrized, that is, $f_i(x)$ is of the form $g(a_i^T x)$ for all $i$. In this setting $\nabla f_i(x) = a_i g'(a_i^T x)$, so since each $a_i$ is constant we only need to store the scalar $g'(a_i^T x)$. This reduces the storage cost from $\mathcal{O}(n p)$ down to $\mathcal{O}(n)$.

The values of $\Omega$ that we will examine are the cases of $\ell_1$-regularization and $\ell_1/\ell_2$-regularization. $\ell_1$ regularization, known as \LASSO\ when the smooth term is a least squares loss, is a popular penalty that is commonly used to promote sparsity within the vector of coefficients. It is denoted $\norm{\cdot}_1$ and defined as the absolute sum of its components,
$
\norm{x}_1 = \sum_{i=1}^p |x_i|
$. Its proximal operator is the \emph{soft-thresholding} operator, and is defined component-wise as
\begin{equation}\label{eq:soft_thresholding}
\left[\text{Prox}_{\mu \norm{\cdot}_1}(x)\right]_j = \left(1 - \frac{\mu}{|x_j|}\right)_+ x_j =
\begin{cases}
x_j - \mu \text{ if } \mu \leq x_j \\
0 \text{ if } -\mu \leq x_j \leq \mu \\
\mu - x_j \text{ if }  x_j \leq - \mu \\
\end{cases}
\end{equation}

A practical implementation of \SAGA\ relies on a number of non-trivial techniques that need to be used. In this technical report we detail the techniques that we found where essential to obtain a practical implementation of this algorithm. These are:
\begin{itemize}
% \item {\bf Adaptive step size}. The SAGA algorithm relies on a particular choice of the step size $\gamma$. While in theory this step size can be estimated from the data, we found that much faster convergence can be achieved by choosing an \emph{adaptive} step size. We will detail this choice in Section~\ref{scs:step_size}.
\item {\bf Lagged updates}. Even if the gradients $\nabla f_i(x)$ are sparse, the vector $\bar{\alpha}$ is typically dense and so update rule~\eqref{eq:update_rule} involves dense vector operations. However, a technique known as implicit updates, lagged updates~\citep{defazio2014saga} or just-in-time updates~\citep{schmidt2013minimizing} can be used in order to reduce the vector update to sparse operations.
We extend this technique to the case of an $\ell_1$ penalty term.
\item {\bf Step size}. The theory of \SAGA\ is developed for a step-size that is sub-optimal. In particular,
\end{itemize}

\section{Impicit updates}

When the vectors $a_i$ are sparse (recall that we assume $f_i$ is of the form $f_i(x) = g(a_i^T x)$, an individual gradient $\nabla f_i$ will inherit the sparsity pattern of the corresponding $a_i$. However, the update rule~\eqref{eq:update_rule} appears unappealing since in general $\bar{\alpha}$ will be dense. Nevertheless, we can use the following technique to obtain iterations with a cost that is proportional to the number of non-zeros in $a_i$.

This technique consists in not explicitly storing the full vector $x_k$ after each iteration. Instead, on each iteration we only compute the elements corresponding to non-zero elements of $a_i$ and at the same time storing a record of when was the last time that a given feature or coordinate was updated. We denote the vector that keeps track of this $m$, such that $m_i$ returns the last iteration in which $x_i$ was updated.

We will first present the technique in its general form and then see how this simplifies for some common choice of the regularizers such as $\ell_2$ or $\ell_1$. The technique can be defined recursively as follows (assumes the prox is computed element-wise):

\begin{enumerate}[(i)]
\item In the first iteration, perform the update rule only on the support of $a_1$, which we denote $J$, and we updated the vector $m$.
$$
\begin{aligned}
(x^1)_J &\leftarrow \text{Prox}_{\gamma \mu}((1 - \gamma^k \lambda)x_k - \gamma^k (\nabla f_i(x_k) - {\alpha}_i + \bar{\alpha}))_J \\
m_J &\leftarrow 1
\end{aligned}
$$
\item At iteration $k$, we update the vector of coefficients $x_k$ to ensure that it is up-to-date on the support of $a_k$. That is, for all indices $j$ in the support of $a_i$:
\begin{algorithmic}
\For{$j \text{ in the support of }a_i$}
\For{$l \gets m_j,k$ }
\State $x_j \gets \text{Prox}_{\gamma^k \mu}((1 - \gamma^k \lambda)x_j - \gamma^k \bar{\alpha}_j)$
\EndFor
\State $m_j \gets k$ \Comment{ Mark the $j$-th variable as updated }
\EndFor
\end{algorithmic}
\item Perform the $k$-th update on the support of $a_i$:
\begin{algorithmic}
\For{$j \in \text{ support of }a_i$}
\State $(x_k)_j \gets \text{Prox}_{\gamma^k \mu}((1 - \gamma^k \lambda)x_k - \gamma^k (\nabla f_i(x_k) - {\alpha}_i + \bar{\alpha}))_j$
\EndFor
\end{algorithmic}
% $$
% \begin{aligned}
% (x_k)_j &\leftarrow \text{Prox}_{\gamma \mu}((1 - \gamma \lambda)x_k - \gamma (\nabla f_i(x_k) - {\alpha}_i + \bar{\alpha}))_j \\
% \alpha_i &\leftarrow \nabla f_i(x_k) (XXX)
% \end{aligned}
% $$
\end{enumerate}

The technique of implicit (or lagged) updates consists in finding a shortcut for the update in step $(ii)$. As we will see, this can be done for the case of $\ell_2$ regularization and (to a certain extend) for the case of $\ell_1$ regularization. For simplicity we define the following function $P$ which represents the update of a single coordinate. Given arbitrary real numbers $s, t$ this is defined as follows:
$$
U_t(s) = \text{{Prox}}_{\gamma \mu}((1 - \gamma \lambda)s - \gamma t) \quad,
$$
The update in step $(ii)$ can be written in this notation as $x \leftarrow U_{\bar{\alpha_j}}(x_j)$. The for loop in this step can be interpreted as the composition of $U$ with itself. Hence, the efficiency of the lagged update will depend on how fast we are able to compute $U^m$, where the exponent denotes composition with itself.

\subsection{Implicit updates with $\ell_2$ regularization}

We start with the simple case in which there is no non-smooth penalty term, i.e. $\Omega$ is zero. This setting is described in~\citep{defazio2014saga} and in ~\citep{schmidt2013minimizing} (in this case of the \SAG\ algorithm instead of \SAGA).

In this case, the updates in step (ii) take a simple form. Supposing $k-m_j = 1$ then the update for coordinate $j$ is simply
$$
x^+_j \gets (1 - \gamma \lambda)x_j - \gamma \bar{\alpha}_j \quad.
$$
If $k-m_j=2$ then the update becomes
$$
\begin{aligned}
x^+_j &\gets (1 - \gamma^{k} \lambda)((1 - \gamma^{k-1} \lambda)x_j - \gamma^{k-1} \bar{\alpha}_j) - \gamma^k \bar{\alpha}_j \quad. \\
&= (1 - \gamma^{k} \lambda)(1 - \gamma^{k-1} \lambda) x_j - \gamma^k \bar{\alpha} (1 + (1 - \gamma^{k-1} \lambda))
\end{aligned}
$$

From this it is easy to generalize to an arbitrary value of $k-m_j$. The full update in this case becomes:
\begin{algorithmic}
\For{$j \in \text{ support of }a_i$}
\State $x_j \gets \left(\prod_{i=1}^{k-m_j} (1 - \gamma^{k-i+1} \lambda )\right) x_j + \gamma^k \bar{\alpha} \left(1 + \sum_{i=1}^{k-m_j} \prod_{j=1}^i (1 - \gamma^{k-j} \lambda) \right)$
\State $m_j \gets k$
\EndFor
\end{algorithmic}

That this is indeed equivalent to the update rule in in (ii) can be easily proven by induction on $k - m_j$.

\subsection{Implicit updates for $\ell_2 + \ell_1$ regularization}

Through this section $\text{Prox}$ denotes the proximal operator for the $\ell_1$ norm, defined in Eq.~\eqref{eq:soft_thresholding}. Our update scheme is based upon the following lemma.

\begin{lemma}\label{lemma:update_l1}
Let $s, t$ be arbitrary real numbers and $P$ be a function defined as follows:
where $j$ is an arbitrary index. Let $P^m$ denote the composition of $P$ with itself $m$ times. Then, if $|\bar{\alpha}_j| \leq \mu$ or if $\bar{\alpha}_j x_j \leq 0$, then it is verified that
$$
P^m(s, t) =
\text{\emph{Prox}}_{m \gamma \mu}\left((1 - \gamma \lambda)^{m} x_j + \gamma \bar{\alpha}_j \sum_{i=1}^{m} (1 - \gamma \lambda)^{i-1}\right)
$$
\end{lemma}
\begin{proof}
% Take first the case of $k - m_j = 1$. The update in (ii) takes the following form
% $$
% x_j \gets \text{Prox}_{\gamma \mu}((1 - \gamma \lambda)x_j - \gamma \bar{\alpha}_j)
% $$
We first consider the case in which $\abs{\bar{\alpha}_j} \leq \mu$. Make make the following distinction of cases:
\begin{itemize}
\item $x_j = 0$. In this case $P(x_j) = \text{{Prox}}_{\gamma \mu}(- \gamma \bar{\alpha}_j)$ and the assumption $\abs{\bar{\alpha}_j} \leq \mu$ implies that $T(x_j) = \text{{Prox}}_{\gamma \mu}(- \gamma \bar{\alpha}_j) = 0$.
\end{itemize}
% and $(1 - \gamma \lambda)x_j - \gamma \bar{\alpha}_j \geq \gamma \mu$
. Then by the definition of soft-thresholding we have the update
$$
T(x) =
$$
XXX
$$
x_j^+ \gets (1 - \gamma \lambda)x_j - \gamma \bar{\alpha}_j - \gamma \mu
$$
\end{proof}

This proximal function also features a homogeneous property, namely that if $x = \tau w$, then
$$
\text{Prox}_\lambda(x) = \tau \text{Prox}_{\lambda /\tau}(w_k) \quad.
$$

This, together with Lemma~\ref{lemma:update_l1}, yield the following lagged update rule for the $\ell_1$ regularization.

% \section{Adaptive step size} \label{scs:step_size}

% Following~\citep{schmidt2013minimizing,schmidt2015non}, we take the step size to be $\gamma = 1 / L$, where $L$ is an approximation to the maximum Lipschitz constant of the gradients. This is the smallest number such that
% $$
% \norm{\nabla f_i(w) - \nabla f_i(v)} \leq L \norm{w - v}\quad,
% $$
% for all $i, w$ and $v$. A classical result on quadratic upper bounds for $L$-smooth functions (see e.g.~\citep[Lemma 1.2.3]{nesterov2004introductory}) states that the following inequality is verified:
% \begin{equation*}
% f_{i}(x_k - \frac{1}{L}\nabla f_{i}(x_k)) \leq f_{i}(x_k) - \frac{1}{2 L} \norm{\nabla f_{i}(x_k)}^2
% \end{equation*}
% The adaptive step size strategy is the following: at the current iterate, compute the above inequality for the current value of $i$ and $k$. If the inequality is satisfied, use the step size $1 / L$. Otherwise, double the value of $L$ until the inequality is verified.

\subsection{Experiments}

Some convergence plots.

\section{Choice of step size}

\section{Feedback}

\bibliography{biblio}{}
\end{document}


\documentclass[12pt]{cdblatex}
\usepackage{exercises}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% --------------------------------------------------------------------------------------------
\section*{Exercise 4.3 Polynomial products}

\begin{cadabra}

   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).

   def get_term (poly,n):

       x^{a}::Weight(label=xnum).     # assign weights to x^{a}

       foo := @(poly).                # make a copy of poly
       bah  = Ex("xnum = " + str(n))  # choose a target
       keep_weight (foo,bah)          # extract the target

       return foo

   def poly_product (p,q,n):

       pq = Ex("0")

       for i in range (0,n+1):
          for j in range (0,i+1):
             termA = get_term (p,j)
             termB = get_term (q,i-j)
             termAB := @(termA) @(termB).
             pq = pq + termAB

       sort_product   (pq)
       rename_dummies (pq)
       factor_out     (pq,$x^{a?}$)

       return pq

   # ---------------------------------------------------------------

   # two polynomials

   polyA := c^{a}
          + c^{a}_{b} x^b
          + c^{a}_{b c} x^b x^c
          + c^{a}_{b c d} x^b x^c x^d
          + c^{a}_{b c d e} x^b x^c x^d x^e.    # cdb(ex-0403.100,polyA)

   polyB := d^{f}
          + d^{f}_{b} x^b
          + d^{f}_{b c} x^b x^c
          + d^{f}_{b c d} x^b x^c x^d
          + d^{f}_{b c d e} x^b x^c x^d x^e.    # cdb(ex-0403.101,polyB)

   # multiply polynomials and truncate

   polyAB = poly_product (polyA,polyB,3)        # cdb(ex-0403.102,polyAB)

\end{cadabra}

\begin{dgroup*}
   \Dmath*{  p = \Cdb*{ex-0403.100} }
   \Dmath*{  q = \Cdb*{ex-0403.101} }
   \Dmath*{ pq = \Cdb*[\hskip1cm\hfill]{ex-0403.102} }
\end{dgroup*}

\end{document}


\chapter{Introduction}

\section{Knowledge Discovery in Database, KDD}

The overall process of non-trivial extraction of implicit, previously unknown and potentially useful knowledge from large amounts of data

\begin{align*}
    Database &\xrightarrow{Data\ Cleaning} Data Warehouse \\
    &\xrightarrow{Selection\ Transformation} Task relevant\ Data \\
    &\xrightarrow{Data\ Mining} Pattern \\
    &\xrightarrow{Pattern\ Evaluation\ and\ Visualisation} Knowledge
\end{align*}

\section{Data Mining}

\begin{description}
  \item[Prediction\ Methods] Classification, Outlier Detection, Regression
  \item[Description Methods] Clustering, Association Rule, Sequence Pattern
\end{description}


\input{../tex/headerfile}
\input{../tex/mathdefs}
\setcounter{MaxMatrixCols}{20}
\usepackage{enumerate}
\usepackage{Sweave}
\begin{document}
\input{basic-matrix-math-key-concordance}

\chapter*{Solutions Chapter \ref{chap:basicmat}}
\addcontentsline{toc}{chapter}{Solutions Chapter \ref{chap:basicmat}}

%######################################
%# Basic Matrix Math
%# Homework Questions
%######################################

\begin{enumerate}
\item
\begin{Schunk}
\begin{Sinput}
 A=matrix(1:4,4,3)
\end{Sinput}
\end{Schunk}
\item
\begin{Schunk}
\begin{Sinput}
 A[1:2,1:2]
\end{Sinput}
\end{Schunk}
\item
\begin{Schunk}
\begin{Sinput}
 A=matrix(1:12,4,3, byrow=TRUE)
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 #end up with a vector
 A[3,]
 #end up with a matrix
 A[3,,drop=FALSE]
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 B=matrix(1,4,3)
 B[2,3]=2
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 t(B)
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 diag(1:4)
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 B=diag(1,5)
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 diag(B)=2
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 diag(1,4)+1
 #or
 B=matrix(1,4,4)
 diag(B)=2
 B
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 solve(B)
 #or this but only works because B is symmetric
 chol2inv(chol(B))
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 B=matrix(letters[1:9],3,3)
 B
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 diag(B)="cat"
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 A=matrix(1,4,3)
 B=matrix(2,3,4)
 A%*%B
 #or
 B%*%A
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 # A%*%A #throws an error
 A%*%t(A) #works
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 #this is an example where you use B to select values in A
 A=matrix(1:9,3,3)
 B=matrix(0,3,3)
 B[1,1]=1
 B[2,3]=1
 B[3,2]=1
 C=A%*%B
 diag(C)
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 #this shows one of the uses of diagonal matrices
 B=diag(2,3)
 C=A%*%B
 C
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 #this shows how to use a column vector (matrix with 1 col)
 #to compute row sums
 B=matrix(1,3,1)
 C=A%*%B
 C
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 #this shows how to use a row vector (matrix with one row)
 #to compute column sums
 B=matrix(1,1,3)
 C=B%*%A
 C
\end{Sinput}
\end{Schunk}

\item
\begin{Schunk}
\begin{Sinput}
 A=diag(1,3)+1
 C=matrix(3,3,1)
 #AB=C
 #B=inv(A)%*%C
 B=solve(A)%*%C
 B
\end{Sinput}
\end{Schunk}

\end{enumerate}

\bibliography{../tex/Fish507}

\end{document}

docs/Labs/Week 0 basic matrix/basic-matrix-math-key.tex


\documentclass[12pt]{article}
\input{physics1}
\begin{document}

\noindent
Name: \rule[-1ex]{0.55\textwidth}{0.1pt}
NetID: \rule[-1ex]{0.2\textwidth}{0.1pt}

\section*{NYU Physics I---Term Exam 2}

\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from Lecture on 2018-09-27)
A roller-coaster cart is at the top of a loop-the-loop (and therefore
upside-down). The trajectory of the center of mass of the cart has a
radius of curvature $R=5\,\m$. How fast does the roller-coaster have
to be moving in $\mps$ to stay on it's proper path (that is, on the
tracks)?  Assume the mass is $M=1000\,\kg$ and the acceleration due to
gravity is $g=10\,\mpss$.

\vfill

\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from Lecture on 2018-09-25)
In \emph{16 words or fewer} tell me why the mass flying off the
(not a) aki jump didn't fly
all the way back up to the release height. Put a box around your answer,
so I can count the words!

\vfill

\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from Problem Set 3)
If a runner, starting at rest, accelerates at $5\,\mpss$ for $2\,\s$
and then continues at constant speed for $19\,s$ more, how far will
she have run at the end of that $21\,\s$?

\vfill
~

\clearpage
\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from Problem Set 4)
What is your kinetic energy when you are walking along the street?
State your assumptions, and make sure they are \emph{reasonable.}

\vfill

\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from the blocks-and-pulleys worksheet)
A massless pulley hangs from the ceiling from a string which is at
tension $T_1$. Over this pulley is another string at tension $T_2$, on
the ends of which are massive blocks attached. What is the
relationship between $T_1$ and $T_2$? If you have to assume additional
things to solve this problem, state them.

\vfill

\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from the friction worksheet)
You have a block of mass $m$ on an inclined plane, inclined at an
angle $\theta=15\,\deg$ to the horizontal. The coefficient of friction
is $\mu=0.9$. What is the magnitude of the frictional force on the
block? The acceleration due to gravity is $g$.
You can leave your answer in terms of $\mu$, $m$, $g$, $\theta$, or
whatever you need to deliver a correct answer.
Once again, state any assumptions you need to make.

\vfill
~
\end{document}


\documentclass[12pt]{article}
\usepackage[a4paper, bindingoffset=0.2in, %
							left=0.5in,right=0.5in,top=0.5in,bottom=0.5in,%
							footskip=.25in]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{physics}
\usepackage{hyperref}

\title{Midterm Report}
\author{Ali Abolhassanzadeh Mahani\\ 97110863}

\begin{document}
	\maketitle
	\section{Problem 1 (3D Site Percolation)}
	\subsection{Part a}
	I made a class \texttt{PercMatrix} that takes the length $L$ as the size of the arrays, and $p$, the probability with which I fill the cells with zero and on.
	Then, I go on and generate random binary numbers, and store shared poiters to them in the cells. I use smart pointers (\texttt{std::shared\_ptr<int>}) to make the clustering process faster.
	\subsection{Part b}
	First I make a $L\times L$ matrix called \texttt{frontier} that stores the color codes through out the clustering and coloring process. Then, I add a surface matrix called \texttt{init} to the beginning of the
	cube that contains pointers to the cells in \texttt{frontier}. Then, I go through the cube cells and check if they are adjacent. If so, I form clusters, If more than one neighbors is on, I merge the cluster to the one with the lowest color code, since that cluster was made first.\\
	In the end, I check the ending surface of cube to see if any of the color code are between $1, L\times L +1$. If so, Percolation has occured. Otherwise, no percolation.
	In order to find the gyro radius, first, I find the color code of the biggest non-percolating cluster. Then, I
	find the geometric center of that cluster and then, I can calculate the gyro radius.

	\section{Problem 2 (Erdos Renyi Graph)}
	\subsection{Part a (clustering)}
	I made the graph using \texttt{nx.erdos\_renyi\_graph(n, p)}. Here $p$ is the probablity of an edge to exist which is $\frac{<k>}{n}$ with $n$ being the number of nodes.\\
	I used the \texttt{nx.clustering(G)} module to calculate the clustering of each edge and then
	used a trick to store them in a \texttt{numpy array}. Then I plotted them using \texttt{plt.hist()}. (Fig\ref{fig:clust})
	\begin{figure}[h]
		\centering
		\includegraphics[width=.4\linewidth]{../p2/clust1.jpg}
		\includegraphics[width=.4\linewidth]{../p2/clust8.jpg}
		\includegraphics[width=.4\linewidth]{../p2/clust64.jpg}
		\includegraphics[width=.4\linewidth]{../p2/clust512.jpg}
		\label{fig:clust}
		\caption{clustering distribution for mean degrees of $\{1, 8, 64, 512\}$}
	\end{figure}
	\subsection{Part b (poisson dist. of degrees)}
	First I plot the histogram of degrees using \texttt{plt.hist()}, which gives me \texttt{counts}
	and \texttt{bins}, then I make a function that returns the probability using the poisson distribution. (basically made that function). Then, I found the poisson distribution of the \texttt{bins} and compared them to the actual \texttt{counts}. \\
	Then \texttt{np.sum} over them to find the cultivated error. The error is of order $\mathcal{O}(10^{-5})$ for $<k> = 64$

	This means that the poisson distribution function fits the degree distribution fairly well.
	\section{Problem 3 (Random Generation)}
	\subsection{Part a (generating function)}
	The function that generates this distribution is the inverse of $g(x)$. It is as follows:
	\begin{equation}
		g^{-1}(x) = \left(\frac{\alpha x_m^\alpha}{x}\right)^{\frac{1}{\alpha + 1}}
	\end{equation}
	In order to generate from $x_m$ to $\infty$, we need the input to be a uniform distribution
	from $0$ to $g^{-1}(x_m)$.\\
	I created this function and called it \texttt{target\_dist()}; then I made a random set of size
	$100000$ and plotted the histogram as seen below.(Fig\ref{fig:reverse})
	\begin{figure}[h]
		\centering
		\includegraphics[width=.4\linewidth]{../p3/reverse.jpg}
		\includegraphics[width=.4\linewidth]{../p3/reverseplot.jpg}
		\label{fig:reverse}
		\caption{Distribution of $g(x)$ by 1000 samples and by ideal plot}
	\end{figure}

	\subsection{Part b (metropolis algorithm)}
	In the metropolis algorithm, first, I defined the function $g(x)$ to return it's value as states in the previous
	subsection, and to return $0$ if $x \le 1$. Then, I made a function \texttt{gen\_dist(step, size)} which takes
	in the \texttt{step} and \texttt{size} and returns an array of random numbers as expected.
	Inside the function, I used two counters, one to count acceptances and one to count the whole process.
	Using the first, I can get the acceptance rate. I also stored all the numbers generated (whether or not they
	were same)and using the second counter, I hand-picked the random samples.

	Then, I made a function \texttt{corr\_len()} that takes in all the numbers, calculates the auto correlation
	for values of $j = \{0, 10, 20, 30, \dots, 5000\}$. Then, I look to see at which point, the auto correlation becomes less than $e^{-1}$. That value of $j$ is our correlation (gyro) length.
	The results are in Table\ref{tab:gyro}
	\begin{table}[h]
		\centering
		\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
			\hline
step size& $0.2$& $0.49$ & $0.9$ & $1.5$ & $2.45$ & $4$ & $6.4$ & $13.5$ & $33$ \\
 \hline
acceptance rate & $0.9$ & $0.8$ & $0.7$ & $0.6$ & $0.5$ & $0.4$ & $0.3$ & $0.2$ & $0.1$ \\
 \hline
correlation length & $5000$ & $1190$ & $3530$ & $430$ & $440$ & $290$ & $110$ & $1310$ & $90$ \\
 \hline
		\end{tabular}
	\label{tab:gyro}
	\caption{step size, and gyro length for different values of acceptance rate. The error for gyro length is 10.
	The first with gyro length 5000 suggests that the gyro is actually more for that acceptance rate since 5000
	is the maximum value in my calculations.}
	\end{table}

	\section{Problem 4 (simulation)}
	\textbf{List of group members:} \emph{Ali Abolhassanzadeh Mahani}, \emph{Abbas Shojakani}, \emph{Mohadeseh Asgari}
	\subsection{Stating the Problem}
	A blind /drunk person wants to cross a street using nothing but random process.\\
	We want to find his/her success rate relative to the degree of which how crowded the street is.\\
	We also want to find his/her mean lifetime for the times that he/she does not succeed and dies in a crash.
	\subsection{Simulation}
	The man is on the left side of the street at first, but then, It starts moving randomly with time.
	The boundary conditions are walls on the sides of the street. Meaning that if the man staeps to the left of the street, it stays there. If he reaches the right side, he succeeds.

	We took a mean of the car speeds and decided for it to be twice the speed of the blind/drunk person.
	The width of the street is fixed to size $L$ and the number of cars that are randomly generated and put on
	the street is our independent variable. The length of the cars is 1 unit area and the
	cars move from bottom up. If in a time step, the position of the
	random walker and a car are interfered, the person is rendered dead, and is reset to be on the left side again. This cycle continues for the rest of the ensemble.\\
	We have also omitted the will of the drivers to hit the brake before hitting the person. So we have kind of assumed that the drivers are drunk too, which is a bit absurd or that the drivers' response time is not low enough to avoid a crash, which can be more reasonable.

	A better approximation of to set a condition to lower the speed if the driver sees the drunk person or that it
	shift the car to a new lane. Implementing these conditions can yield better, more accurate results. (We don't have time for that ;-) )
	\subsection{The Simulation Code}
	I made a random walker in 1 Dimension that randomly crosses the street. And every time it makes a choice, its lifetime is incremented by 1 unit time. This method \texttt{next()} that contains the decision making,
	returns 0 if the person is still in the street and returns 1 if the person has reached the right side (success).\\
	\emph{Mohadeseh} made the street and the cars that are randomly generated at the bottom of the street and move upwards with speed 40 unit length.\\
	\emph{Abbas} simulated using our code and got the statistics. The conditions of death and taking the mean are of his work. The precedence of time step evolution is with the random walker. Meaning first, the
	random walker takes a step, then the cars move with their speed. If the cars hit the man in their evolution
	process, the man dies, else, the loop continues until either the man reaches the other side of the street,
	or he dies in a crash.\\
	I also added a some code to get the mean life span for the times that the drunk person dies.
	Afterwards, I spent time refining the code, commenting it and making it pretty :)
	The results are below.

	In our work, the evolution of the cars up the street is a cellular automata and the person crossing the
	street is obviously a random walk simulation.
	\subsection{Results}
	 We simulated for the car speed $v = 40$ and the man's speed $V_p = 2$ and the street width $L = 10$.
	 Then, we plotted the success rate vs. the number of cars and the mean life span vs. the number of cars.
	 Fig\ref{fig:drunk}
	 \begin{figure}[h]
	 	\centering
		\includegraphics[width=.4\linewidth]{../p4/success.jpg}
		\includegraphics[width=.4\linewidth]{../p4/meanlife.jpg}
		\label{fig:drunk}
		\caption{On the left we have the success rate vs. the number of cars, and on the right we have
		the mean life time vs. the number of cars}
	 \end{figure}
 	As one can observe, the \emph{success rate} decays fast with \emph{number of cars}, the mean life time
 	also decays fast but a bit smoother than the success rate. The moral lesson here is that one shall not try crossing a street while drunk.

 	The results show that for example, for a mean degree of crowd about 1 car per 100 unit area, the success rate is about $0.20$ and the mean lifetime for the unsuccessful times, it roughly 8 time steps.
 	for 10 cars per 100 unit area, those numbers decay to about $0$ and $1.5$ respectively.
 	In the ladder case, the drunk person dies after taking about $1.5$ steps in the street.\\
 	This threshold of $10$ can be due to the fact that the width of our street is 10 and since the \texttt{death\_check}'s conditions are perdiodic, for a velocity of 40 unit length per unit time, the entire street becomes full and the drunk person gets hit in just 1 or steps.
\end{document}


\section{MAC network and our proposed simplification}

\begin{wrapfigure}{r}[5pt]{0.4\textwidth}
	\vspace{-15pt}
	\centering
	\includegraphics[width=\textwidth]{../img/mac_cell.pdf}
	\caption{The MAC cell, reproduced on the basis of~\cite{hudson2018compositional}.}
	\label{fig:mac_cell}
	\vspace{-5pt}
\end{wrapfigure}

The MAC network~\cite{hudson2018compositional} is a recurrent model that performs sequential reasoning, where each step involves analyzing a part of the question followed by shifting the attention over the image.
The core of the model is the MAC cell, supported with an input unit that processes the question and image pair, and output unit which produces the answer.
The input unit  uses an LSTM~\cite{hochreiter1997long} to process the question in a word-by-word manner producing a sequence of \emph{contextual words} and a final \emph{question representation}.
Additionally, the input unit uses a pre-trained ResNet~\cite{he2016resnet} followed by two CNN layers to extract a feature map (referred to as \emph{knowledge base}) from the image.

The MAC cell consists of a control unit, a read unit and a write unit (\Fig{fig:mac_cell}).
The control unit is updating the control state $c_i$ and drives the attention over the list of \emph{contextual words} $\cw$ taking into account the \emph{question representation} $q$.
Guided by $c_i$,  the read unit extracts information from the \emph{knowledge base} $\kb$ and combines it with the previous memory state $m_{i-1}$  to produce the \emph{read vector} $r_i$.
Finally, the write unit integrates $r_i$ and $m_{i-1}$ to update the memory state. Detailed equations are described in the next section.

%\begin{figure}[htbp]
%	\centering
%	\includegraphics[width=0.4\textwidth]{img/mac_cell.pdf}
%	\caption{The MAC cell~\cite{hudsonManning18}}
%	\label{fig:mac_cell}
%\end{figure}


\input{mmd-article-header}
\def\mytitle{MultiMarkdown Math Example}
\input{mmd-article-begin-doc}

\part{Math}
\label{math}

An example of math within a paragraph --- ${e}^{i\pi }+1=0$ --- easy
enough.

And an equation on it's own:

\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \]

That's it.

\chapter{``DollarMath''}
\label{dollarmath}

An example of math within a paragraph --- ${e}^{i\pi }+1=0$ --- easy
enough.

An example of math within a paragraph, ${e}^{i\pi }+1=0$, easy
enough.

And an equation on it's own:

$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$

\chapter{Not Math}
\label{notmath}

An example of math within a paragraph --- \$ \{e\}\textsuperscript{{i}\textbackslash{}pi \}+1=0\$ --- easy
enough.

And an equation on it's own:

\$\$ \{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\textsuperscript{{2}}--4ac\}\}\{2a\}\$\$

An example of math within a paragraph --- \$\{e\}\textsuperscript{{i}\textbackslash{}pi \}+1=0 \$ --- easy
enough.

And an equation on it's own:

\$\$\{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\textsuperscript{{2}}--4ac\}\}\{2a\} \$\$

An example of math within a paragraph --- a\$\{e\}\textsuperscript{{i}\textbackslash{}pi \}+1=0\$ --- easy
enough.

And an equation on it's own:

a\$\$\{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\textsuperscript{{2}}--4ac\}\}\{2a\}\$\$

An example of math within a paragraph --- \$\{e\}\textsuperscript{{i}\textbackslash{}pi \}+1=0\$b --- easy
enough.

And an equation on it's own:

\$\$\{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\textsuperscript{{2}}--4ac\}\}\{2a\}\$\$b

\input{mmd-memoir-footer}

\end{document}


% !TeX root = ../phd-1st-year-presentation.tex
% !TeX encoding = UTF-8
% !TeX spellcheck = en_GB

\section{A hybrid technique for MRP transient analysis}
  \begin{frame}{A hybrid technique for MRP transient analysis}
    Transient analysis of Markov Regenerative Processes (MRP)\\
    employing different techniques for different regenerative epochs

    \vspace{1em}
    The basics:
    \begin{itemize}
      \item Exact techniques require specific conditions to be met
      \begin{itemize}
        \item different techniques require different conditions
      \end{itemize}
      \item Kernel rows of different epochs can be evaluated independently
    \end{itemize}

    \vspace{1em}
    The idea:
    \begin{itemize}
      \item Evaluate each kernel row with a different technique
      \begin{itemize}
        \item corresponding to the condition enabled in that epoch
        \item eventually with an approximate technique, if no conditions are met
      \end{itemize}
      \item Compute transient probabilities with Markov Renewal Equations
    \end{itemize}
  \end{frame}

  \subsection{Techniques for MRP transient analysis}
    \begin{frame}{Techniques for MRP transient analysis}
      \begin{minipage}{0.6\textwidth}
        \textbf{Analysis under enabling restriction}\footnotemark
        \begin{itemize}
          \item at most one GEN enabled in each state
        \end{itemize}
      \end{minipage}
      \begin{minipage}{0.35\textwidth}
        \begin{center}\scalebox{0.45}{\input{img/pn_enabling_restriction}}\end{center}
      \end{minipage}

      \begin{minipage}{0.6\textwidth}
        \textbf{Analysis with stochastic state classes}\footnotemark
        \begin{itemize}
          \item a regeneration is always reached\\
            within a bounded number of events
          \begin{itemize}
            \item i.e. no cycles without regenerations
          \end{itemize}
          \item a.k.a. bounded regeneration
        \end{itemize}
      \end{minipage}
      \begin{minipage}{0.35\textwidth}
        \begin{center}\scalebox{0.45}{\input{img/pn_bounded_regeneration}}\end{center}
      \end{minipage}

      \begin{minipage}{0.6\textwidth}
        \textbf{Approximate analysis}
        \begin{itemize}
          \item usable when no conditions are met
        \end{itemize}
      \end{minipage}
      \begin{minipage}{0.35\textwidth}
        \begin{center}\scalebox{0.45}{\input{img/pn_no_restriction}}\end{center}
      \end{minipage}

      \addtocounter{footnote}{-1}
      \footnotetext{German, R., Logothetis, D., \& Trivedi, K. S. (1995, October). Transient analysis of Markov regenerative stochastic Petri nets: A comparison of approaches. In Petri Nets and Performance Models, 1995., Proceedings of the Sixth International Workshop on (pp. 103-112). IEEE.}
      \stepcounter{footnote}
      \footnotetext{Horváth, A., Paolieri, M., Ridi, L., \& Vicario, E. (2012). Transient analysis of non-Markovian models using stochastic state classes. Performance Evaluation, 69(7), 315-335.}
    \end{frame}

  \subsection{Classification of epochs}
    \begin{frame}{Classification of epochs}
      Through \textbf{non-deterministic analysis}
      \begin{itemize}
        \item State Class Graphs (SCG) are built
        \item for each regenerative epoch
      \end{itemize}

      \vspace{2em}
      By visiting each SCG, epochs are classified
      \begin{itemize}
        \item enabling restriction
        \begin{itemize}
          \item if at most one GEN is enabled in any state
        \end{itemize}
        \item bounded regeneration
        \begin{itemize}
          \item if no cycle is present
        \end{itemize}
      \end{itemize}
    \end{frame}

  \subsection{Iterative approximate technique}
    \begin{frame}{Iterative approximate technique}
      Based on analysis with stochastic state classes
      \begin{itemize}
        \item truncated after enough precision is met
      \end{itemize}

      \vspace{2em}
      Improvement with heuristics
      \begin{enumerate}
        \item expand at most $\nu_{start}$ nodes for non restricted epochs
        \item identify the truncated node $\Phi$ with highest reaching probability
        \begin{itemize}
          \item based on steady-state analysis of the embedded DTMC
        \end{itemize}
        \item expand at most $\nu_{iter}$ nodes from $\Phi$
        \item if at least $\nu_{max}$ nodes expanded, stop
        \begin{itemize}
          \item otherwise, return to step 2
        \end{itemize}
      \end{enumerate}
    \end{frame}


\documentclass[10pt]{beamer}
\usetheme{metropolis}
% all imports
\input{all_imports}

\AtBeginEnvironment{quote}{\singlespacing}

% new commands
\input{all_new_commands}

% definitions
\input{definitions/colors}
\input{definitions/styles}

\input{header}

\begin{document}

\maketitle

\begin{frame}{Research problem}
\begin{itemize}
\item Create a set of tasks that incorporate logic reasoning to boost performance of the current dialog agents.
\item Perform a stress test in the existing \textit{neural network based end-to-end dialog systems}.
\item Integrate linguistic reasoning with visual references to create a new set of visual question answering (VQA) tasks.
\item Define new models to achieve better results in the tasks proposed above.
\end{itemize}
\end{frame}

\section{Background}

\begin{frame}{Neural network based language model}
We call \alert{language model} a probability distribution over sequences of tokens in a natural language.
\begin{equation}
P(x_1,x_2,x_3,x_4) = p
\end{equation}

Since \cite{Mikolov11}, we use a \alert{Recurrent Neural Network (RNN)} to estimate the probability distribution   \\

\begin{equation}
P(x_{n} = \text{word}_{j^{*}} | x_{1}, \dots ,x_{n-1})
\end{equation}

for any $(n-1)$-sequence of words $x_{1}, \dots ,x_{n-1}$.
\end{frame}

\begin{frame}{Neural network based language model}
\input{tikzfiles/LanguageModelUnfolded}
\end{frame}

\begin{frame}{GRU: Gated Recurrent Units}
\begin{equation}
\vect{\widetilde{h}}^{(t)} = tahn(\vect{W} (\vect{h}^{(t-1)} \odot  \vect{r}^{(t)}) + \vect{U} \vect{x}^{(t)} + \vect{b})
\end{equation}

\begin{equation}
\vect{r}^{(t)} = \sigma(\vect{W}_{r} \vect{h}^{(t-1)} + \vect{U}_{r} \vect{x}^{(t)} + \vect{b}_{r})
\end{equation}

\begin{equation}
\vect{u}^{(t)} = \sigma(\vect{W}_{u} \vect{h}^{(t-1)} + \vect{U}_{u} \vect{x}^{(t)} + \vect{b}_{u})
\end{equation}

\begin{equation}
\vect{h}^{(t)} = \vect{u}^{(t)} \odot \vect{\widetilde{h}}^{(t)} + (1 - \vect{u}^{(t)}) \odot \vect{h}^{(t-1)}
\end{equation}

\end{frame}

\begin{frame}{LSTM: Long Short Term Memory}
\begin{equation}
\vect{f}^{(t)} = \sigma(\vect{W}_{f} \vect{h}^{(t-1)} + \vect{U}_{f} \vect{x}^{(t)} + \vect{b}_{f})
\end{equation}

\begin{equation}
\vect{i}^{(t)} = \sigma(\vect{W}_{i} \vect{h}^{(t-1)} + \vect{U}_{i} \vect{x}^{(t)} + \vect{b}_{i})
\end{equation}

\begin{equation}
\vect{o}^{(t)} = \sigma(\vect{W}_{o} \vect{h}^{(t-1)} + \vect{U}_{o} \vect{x}^{(t)} + \vect{b}_{o})
\end{equation}

\begin{equation}
\tilde{\vect{c}}^{(t)} = tahn(\vect{W} \vect{h}^{(t-1)} + \vect{U} \vect{x}^{(t)} + \vect{b})
\end{equation}

\begin{equation}
\vect{c}^{(t)} = \vect{f}^{(t)} \odot \vect{c}^{(t-1)} + \vect{i}^{(t)} \odot \tilde{\vect{c}}^{(t)}
\end{equation}

\begin{equation}
\vect{h}^{(t)} = \vect{o}^{(t)} \odot tanh(\vect{c}^{(t)})
\end{equation}

\end{frame}

\begin{frame}{Sequence-to-sequence}
\begin{itemize}
\item $\vect{x}^{(1)}, \dots, \vect{x}^{(n)}$, source sentence
\item $\vect{y}^{(1)}, \dots, \vect{y}^{(m)}$, target sentence
\item $f_{enc}$ (the \textit{encoder}), a RNN
\item $f_{dec}$ (the \textit{encoder}), a language model
\end{itemize}

\begin{equation}
\vect{s} = f_{enc}(\vect{x}^{(n)}, \vect{h}^{(n-1)})
\end{equation}

\begin{equation}
\vect{\tilde{h}}^{(t)} = f_{dec}(\vect{y}^{(t)}, \vect{\tilde{h}}^{(t-1)})
\end{equation}

\begin{equation}
p(y_t | y_1, \dots, y_{t-1}, x_1, \dots, x_{n}) = softmax(\vect{W}_{s}  \vect{\tilde{h}}^{(t)} + \vect{b}_s)
\end{equation}

\end{frame}

\begin{frame}{Attention}

\begin{equation}
\vect{a}_{ts} = \frac{exp(score(\vect{\tilde{h}}^{(t)},\vect{h}^{(s)}))}{\sum_j exp(score(\vect{\tilde{h}}^{(t)},\vect{h}^{(j)}))}
\end{equation}

\begin{equation}
score(\vect{\tilde{h}}^{(t)},\vect{h}^{(s)}) = \begin{cases}
{\vect{\tilde{h}}^{(t)}} .^{\top} \vect{h}^{(s)}\\
\vect{\tilde{h}}^{(t)} .^{\top}\vect{W}_a \vect{h}^{(s)}\\
\vect{v}_a ^{\top}tahn(\vect{W}_a[\vect{\tilde{h}}^{(t)};\vect{h}^{(s)}])\\
\end{cases}
\end{equation}

\begin{equation}
\vect{c}^{(t)} = \sum_{s} \vect{a}_{ts}\vect{h}^{(s)}
\end{equation}

\begin{equation}
\vect{\tilde{h}}^{(t)}_{out} = tahn(\vect{W}_c[\vect{c}^{(t)};\vect{h}^{(t)}])
\end{equation}

\begin{equation}
p(y_t | y_1, \dots, y_{t-1}, x_1, \dots, x_{n}) = softmax(\vect{W}_{s}  \vect{\tilde{h}}^{(t)}_{out} + \vect{b}_s)
\end{equation}

\end{frame}

\begin{frame}{Attention general formulation}

\begin{equation}
f(\vect{Q},\vect{K}_i) = \begin{cases}
\vect{Q} .^{\top} \vect{K}_i\;\;\;\; \text{dot}\\
\vect{Q} .^{\top}\vect{W}_{a} \vect{K}_i\;\;\;\; \text{general}\\
\vect{W}_{a}[\vect{Q};\vect{K}_i] \;\;\;\; \text{concat}\\
\vect{v}_{a}.^{\top} tahn(\vect{W}_{a}\vect{Q} + \vect{U}_{a}\vect{K}_i)\;\;\;\; \text{perceptron}\\
\end{cases}
\end{equation}

% softmax figure
\begin{figure}[ht!]
\centering
\scalebox{1.1}{
\begin{tikzpicture}[auto]
\node[textonly] (logits) {$\begin{bmatrix}f(\vect{Q},\vect{K}_1)\\f(\vect{Q},\vect{K}_2)\\\vdots\\f(\vect{Q},\vect{K}_n)\end{bmatrix}$};
\node[textonly, right=60pt of logits] (softmax) {$\begin{bmatrix}a_1\\a_2\\\vdots\\a_n\end{bmatrix}$};
\path[tedge] (logits) edge node[above=1pt] {{\Large softmax}} (softmax);
\end{tikzpicture}
}
\end{figure}

\begin{equation}
Attention(\vect{Q},\vect{K}, \vect{V})= \sum_{i} \vect{a}_{i}\vect{V}_i
\end{equation}

\end{frame}

\section{Neural network based dialog systems}

\begin{frame}{Seq2seq applied to translation}
\input{tikzfiles/Translation}
\end{frame}

\begin{frame}{Seq2seq applied to dialog \cite{DBLP:journals/corr/VinyalsL15}}
\input{tikzfiles/seq2seq_dialog}
\end{frame}

\begin{frame}{MemNN}
\begin{itemize}
\item $U_1, \dots, U_n$ context
\item $q$ question
\item $a$ answer
\end{itemize}

We have $k = 1, \dots, K$ memory layers:

\begin{itemize}
\item $\{ {\vect{m}^{(k)}}_i\}$, memory vectors
\item $\vect{u}^{(k)}$, input vector
\item $\vect{p}^{(k)}$,  match between $\vect{u}^{(k)}$ and each $\vect{m}^{(k)}_i$
\item $\{ {\vect{c}^{(k)}}_i\}$, another representation of the context $U_1, ..., U_n$
\item $\vect{o}^{(k)}$, output.
\item $\vect{\hat{a}}= softmax(\vect{W}(\vect{o}^{K}))$, candidate answer
\end{itemize}
\end{frame}

\section{How to evaluate dialogs?}

\begin{frame}{Human evaluation  \cite{Lowe:2016}}
\begin{center}
\includegraphics[scale=0.2]{images/exemploEval1.png}
\end{center}

\begin{enumerate}
\item \alert{Adequacy}: the meaning equivalence between the generated and control sentence.
\item \alert{Fluency}: the syntactic correctness of the generated sequence.
\item \alert{Readability}: efficacy of the generated sentence in a particular context.
\end{enumerate}

\end{frame}

\begin{frame}{BLEU (bilingual evaluation understudy)}
\begin{equation}
P_n = \frac{\text{number of } n\text{-grams in both } \hat{y} \text{ and } y}{\text{number of } n\text{-grams appearing in } \hat{y}}
\end{equation}
\vspace{0.2cm}

\begin{equation}
BP=
\begin{cases}
1 & \text{if } len(\hat{y}) > len(y) \\
\exp\left( 1 - \frac{len(y)}{len(\hat{y})} \right) & \text{otherwise}
\end{cases}
\end{equation}
\vspace{0.2cm}

\begin{equation}
BLEU = BP \; \exp \left(\frac{1}{N}  \sum_{n=1}^{N} \log P_n \right)
\end{equation}
\end{frame}

\begin{frame}{METEOR (Metric for Evaluation of Translation with Explicit ORdering)}
\begin{equation}
P = \frac{\text{number of } \text{unigrams in both } \hat{y} \text{ and } y}{\text{number of } \text{unigrams appearing in } \hat{y}}
\end{equation}

\begin{equation}
R = \frac{\text{number of } \text{unigrams in both } \hat{y} \text{ and } y}{\text{number of } \text{unigrams appearing in } y}
\end{equation}

\begin{equation}
F_{mean} = \frac{10 P R}{R + 9P}
\end{equation}

\begin{equation}
METEOR = F_{mean} (1 - penalty)
\end{equation}
\end{frame}

\begin{frame}{ROUGE (Recall Oriented Understudy for Gisting Evaluation)}
\begin{equation}
P_{lcs} = \frac{lcs(\hat{y}, y)}{len(\hat{y})}
\end{equation}

\begin{equation}
R_{lcs} = \frac{lcs(\hat{y}, y)}{len(y)}
\end{equation}

\begin{equation}
ROUGE_L = \frac{(1 + \beta^2) P_{lcs} R_{lcs}}{R_{lcs} + \beta^{2}P_{lcs}}
\end{equation}

where $\beta$ is usually set to favour recal ($\beta = 1.2$).
\end{frame}

\begin{frame}{Problems \cite{LiuLSNCP16}}

\begin{table}[h]
\centering
\label{hownottable}
\begin{tabular}{|c|c|c|c|c|}
\hline
\cellcolor{blue!50} metric & \cellcolor{blue!50} Spearman & \cellcolor{blue!50} $p$-value & \cellcolor{blue!50} Pearson &  \cellcolor{blue!50} $p$-value \\ \hline
BLEU   & $0.34$   & $< 0.01$  & $0.14$  & $0.17$ \\ \hline
METEOR & $0.19$   & $0.06$    & $0.19$  & $0.05$ \\ \hline
ROUGE  & $0.12$   & $0.22$    & $0.1$   & $0.34$ \\ \hline
\end{tabular}
\caption{Correlation between automatic metrics and human judgments based on dialog generated on Twitter}
\end{table}

\begin{table}[h]
\centering
\label{hownottable}
\begin{tabular}{|c|c|c|c|c|}
\hline
\cellcolor{blue!50} metric & \cellcolor{blue!50} Spearman & \cellcolor{blue!50} $p$-value & \cellcolor{blue!50} Pearson &  \cellcolor{blue!50} $p$-value \\ \hline
BLEU & $0.12$   & $0.23$    & $0.11$  & $0.26$    \\ \hline
METEOR & $0.06$   & $0.53$    & $0.14$  & $0.16$     \\ \hline
ROUGE & $0.05$   & $0.59$    & $0.06$  & $0.53$    \\ \hline
\end{tabular}
\caption{Correlation between automatic metrics and human judgments based on dialog generated on Ubuntu}
\end{table}
\end{frame}

\section{Creating simplified tasks as tests}

\begin{frame}{bAbI \cite{WestonBCM15}}
One solution is to create a set of QA synthetic tasks to test different capabilities of a dialog agent.

\begin{center}
\includegraphics[scale=0.25]{images/babi.png}
\end{center}
\end{frame}

\begin{frame}{ParlAI \\ \url{https://github.com/facebookresearch/ParlAI}}

\begin{center}
\includegraphics[scale=0.84]{images/parlai.png}
\end{center}

"ParlAI (pronounced 'par-lay') is a framework for dialog AI research, implemented in Python.

Its goal is to provide researchers:

\begin{itemize}
\item a unified framework for sharing, training and testing dialog models
\item many popular datasets available all in one place, with the ability to multi-task over them
\item seamless integration of Amazon Mechanical Turk for data collection and human evaluation"
\end{itemize}

\end{frame}

\begin{frame}{Sanity check experiments}
\begin{center}
\includegraphics[scale=0.34]{images/comparative_results_babi1.png}
\end{center}
\end{frame}

\begin{frame}{Sanity check experiments}
\begin{center}
\includegraphics[scale=0.34]{images/comparative_results_babi2.png}
\end{center}
\end{frame}

\section{Entailment-QA}

\begin{frame}{bAbI: task 15}

\alert{Basic Deduction}

\begin{center}
\includegraphics[scale=0.28]{images/babi15.png}
\end{center}
\begin{quote}
\centering
$P^{1}$ are afraid of $Q^{1}$\\
$P^{2}$ are afraid of $Q^{2}$\\
$P^{3}$ are afraid of $Q^{3}$\\
$P^{4}$ are afraid of $Q^{4}$\\
$c^{1}$ is a $P^{1}$\\
$c^{2}$ is a $P^{2}$\\
$c^{3}$ is a $P^{3}$\\
$c^{4}$ is a $P^{4}$\\
What is $c^j$ afraid of? \alert{A: $Q^j$}\\
\end{quote}

\end{frame}

\begin{frame}{bAbI: task 16}

\alert{Basic Induction}

\begin{center}
\includegraphics[scale=0.28]{images/babi16.png}
\end{center}
\begin{quote}
\centering
$c^{1}$ is a $P^{1}$\\
$c^{1}$ is $C^{1}$\\
$c^{2}$ is a $P^{2}$\\
$c^{2}$ is $C^{2}$\\
$c^{3}$ is a $P^{3}$\\
$c^{3}$ is $C^{3}$\\
$c^{4}$ is a $P^{4}$\\
$c^{4}$ is $C^{4}$\\
$c$ is a $P^{j}$\\
What color is $c$? \alert{A: $C^j$}\\
\end{quote}

\end{frame}

\begin{frame}{Entailment-QA}

\begin{enumerate}
\item \textbf{Boolean Connectives}
\item[]
\item \textbf{First-Order Quantifiers}
\item[]
\item \textbf{Synonymy}
\item[]
\item \textbf{Antinomy}
\item[]
\item \textbf{Hypernymy}
\item[]
\item \textbf{Active/Passive voice}
\end{enumerate}
\end{frame}

\begin{frame}{Entailment-QA: task 1}
\begin{itemize}
\item \alert{Entailment} ($s_1$ implies $s_2$)
\begin{itemize}
\item $\underbrace{P^{1}a^1 \land \dots \land P^{n}a^n}_{s_1}, \underbrace{P^{j}a^j}_{s_2}$
\item $\underbrace{P^{j}a^j}_{s_1}, \underbrace{P^{1}a^1 \lor \dots \lor P^{n}a^n}_{s_2}$
\item $\underbrace{Pa}_{s_1}, \underbrace{\lnot \lnot Pa}_{s_2}$
\end{itemize}

\vspace{0.4cm}
\item \alert{Not entailment} ($s_1$ does not imply $s_2$)
\begin{itemize}
\item $\underbrace{P^{j}a^j}_{s_1}, \underbrace{P^{1}a^1 \land \dots \land P^{n}a^n}_{s_2}$
\item $\underbrace{P^{1}a^1 \lor \dots \lor P^{n}a^n}_{s_1}, \underbrace{P^{j}a^j}_{s_2}$
\item $\underbrace{Pa}_{s_1}, \underbrace{\lnot Pa}_{s_2}$
\end{itemize}
\end{itemize}
\end{frame}

\begin{frame}{Entailment-QA: task 1}
\begin{itemize}
\item[] Ashley is fit
\item[] Ashley is not fit
\item[] The first sentence implies the second sentence? \alert{A: no}
\end{itemize}

\vspace{0.3cm}

\begin{itemize}
\item[]Avery is nice and Avery is obedient
\item[]Avery is nice
\item[]The first sentence implies the second sentence? \alert{A: yes}
\end{itemize}

\vspace{0.3cm}

\begin{itemize}
\item[]Elbert is handsome or Elbert is long
\item[]Elbert is handsome
\item[]The first sentence implies the second sentence? \alert{A: no}
\end{itemize}
\end{frame}

\begin{frame}{Entailment-QA: task 2}

\begin{itemize}
\item \alert{Entailment}
\begin{itemize}
\item $\forall x Px, Pa$
\item $Pa, \exists x Px$
\end{itemize}
\item []
\item \alert{Contradiction}
\begin{itemize}
\item $\forall x Px, \lnot Pa$
\item $\forall x Px, \exists x \lnot Px$
\end{itemize}
\item []
\item \alert{Neutral}
\begin{itemize}
\item $Pa,Qa$
\item $\forall x Px, \lnot Qa$
\end{itemize}
\end{itemize}
\end{frame}

\begin{frame}{Entailment-QA: task 2}

\begin{itemize}
\item[] Every person is lively
\item[] Belden is lively
\item[] What is the semantic relation? \alert{A: entailment}
\end{itemize}

\begin{itemize}
\item[] Every person is short
\item[] There is one person that is not short
\item[] What is the semantic relation?  \alert{A: contradiction}
\end{itemize}

\begin{itemize}
\item[] Every person is beautiful
\item[] Abilene is not blue
\item[] What is the semantic relation? \alert{A: neutral}
\end{itemize}
\end{frame}

\begin{frame}{Entailment-QA: task proxy}

SICK (Sentences Involving Compositional Knowledge) \cite{Marelli14}

\begin{center}
\includegraphics[scale=0.25]{images/sick.png}
\end{center}

\end{frame}

\begin{frame}{Entailment-QA: task proxy}

\begin{itemize}
\item[] There is no dog leaping in the air
\item[] A dog is leaping high in the air and another is watching
\item[] What is the semantic relation? \alert{A: contradiction}
\end{itemize}

\begin{itemize}
\item[] A man is exercising
\item[] A baby is laughing
\item[] What is the semantic relation? \alert{A: neutral}
\end{itemize}

\begin{itemize}
\item[] Some dogs are playing in a river
\item[] Some dogs are playing in a stream
\item[] What is the semantic relation? \alert{A: entailment}
\end{itemize}
\end{frame}

\begin{frame}{Preliminary Results}
\begin{center}
\includegraphics[scale=0.42]{images/comparative_results.png}
\end{center}
\end{frame}

\begin{frame}{Preliminary Results}
\begin{center}
\includegraphics[scale=0.28]{images/training_acc_EntailQA_mem.png}
\end{center}
\end{frame}

\begin{frame}{Preliminary Results}
\begin{center}
\includegraphics[scale=0.42]{images/cm_mem_EntailQA2.png}
\end{center}
\end{frame}

\begin{frame}{Future Steps}
\begin{itemize}
\item Try to overcome the reported overfitting problem.
\item Finish the Entailment-QA corpus.
\item Explore new models not mentioned here, like \alert{Dynamic Memory Networks} \cite{KumarISBEPOGS15} and  \alert{Memory Attention and Composition (MAC) cell} \cite{Manning18}.
\item Create a visual version of the Entailment-QA to test logical inference with images.
\item Check the reinforcement learning on dialog.
\item Review the literature on the theory of comparing models \cite{BenavoliCDZ17}.
\end{itemize}
\end{frame}

\begin{frame}{Schedule}
\begin{center}
\includegraphics[scale=0.24]{images/workplan.png}
\end{center}
\end{frame}

\begin{frame}[allowframebreaks]{References}

  \bibliography{my_references}
  \bibliographystyle{abbrv}

\end{frame}

\end{document}

\end{document}


\documentclass{article}
\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{February 19, 2014}
\maketitle

\section*{leftover}
sine integral transform (evaluating integrals explicitly)

find:
\begin{align*}
  I&=\int_0^\infty{\frac{\sin(x\omega }{\omega }e^{-\alpha ^2t\omega ^2}\,\mathrm{d}\omega },& &&x&>0\\
  \intertext{convert to}
  I=I(\beta )&=\int_0^\infty{\frac{\sin(\beta s}{s}e^{-s^2}\,\mathrm{d}s}&&&\text{write }\beta =\frac{x}{\alpha \sqrt{t}}&>0\\
  \intertext{note}
  I(\beta )&=\int_0^\infty{\frac{\sin(s)}{s}e^{-s^2/\beta ^2}\,\mathrm{d}s}
  &\to&& 0 \text{ as }\beta &\to 0\\
  &&\to&&\frac{\pi }{2}\text{ as }\beta &\to+\infty\\
  \intertext{end note}
  I'(\beta )&=\frac{\mathrm{d}}{\mathrm{d}\beta }\int_0^\infty{\cos(\beta s)e^{-s^2}\,\mathrm{d}s}&u&=e^{-s^2}&\mathrm{d}v&=\cos(\beta s)\mathrm{d}s\\
  &&\mathrm{d}u&=-2se^{-s^2}\mathrm{d}s&v&=\frac{1}{\beta }\sin(\beta s)\\
  I'(\beta )&=\left.e^{-s^2}\frac{1}{\beta }\sin(\beta s)\right\rvert_0^\infty-\int_0^\infty{\frac{\sin(\beta s)}{\beta }(-2se^{-s^2})\,\mathrm{d}s}\\
  &=+\frac{2}{\beta }\int_0^\infty{\sin(\beta s)se^{-s^2}\,\mathrm{d}s}\\
  &=\frac{2}{\beta }\left(-I''(\beta )\right)\\
  I''(\beta )&=\int_0^\infty{\sin(\beta s)se^{-s^2}\,\mathrm{d}s}=-\frac{\beta }{2}I'(\beta )\\
  I'(\beta )&=c_1e^{-\beta^2 /4}\\
  I(\beta )&=c_2-c_1\int_\beta^\infty{e^{t^2/4}\,\mathrm{d}t}\text{ note the integration starting at }\beta \\
  &=c_2-0\\
  &=\frac{\pi }{2}-c_1\int_\beta^\infty{e^{-t^2/4}\,\mathrm{d}t}\\
  I(0)&=\frac{\pi }{2}-c_1\int_0^\infty{e^{-t^2/4}\,\mathrm{d}t}\\
  \intertext{fact $\int_0^\infty{e^{-x^2}\,\mathrm{d}x}=\frac{\sqrt{\pi }}{2}$}
  \frac{1}{2}\int_0^\infty{e^{-t^4}\,\mathrm{d}t}&=\frac{\sqrt{\pi }}{2}\\
  I(\beta )&=\frac{\pi }{2}-\frac{\sqrt{\pi }}{2}\int_x^\infty{e^{-x^2/4}\,\mathrm{d}x}\\
  \intertext{note error function (erf)}
  \text{erf}(x)&=\frac{2}{\sqrt{\pi }}\int_0^\infty{e^{-t^2}\,\mathrm{d}t}\to1 \text{ as }x\to\infty\\
  \text{erfc}(x)&=1-\text{erf}(x)=\frac{2}{\sqrt{\pi }}\int_x^\infty{e^{-t^2}\,\mathrm{d}t}\\
  \intertext{graph on page 79}
  \intertext{end note}
  x&=2t&\mathrm{d}x&=2\mathrm{d}t\\
  0&=\frac{\pi }{2}-c_2\sqrt{\pi }&\frac{\sqrt{\pi }}{2}&=c_1\\
  I(\beta )&=\frac{\pi }{2}-\frac{\sqrt{\pi} }{2}\int_{t/2\cdot2t?}^\infty{2e^{-t^2}\,\mathrm{d}t}\\
  &=\frac{\pi }{2}-\frac{\sqrt{\pi }}{2}\cdot2\cdot\frac{\sqrt{\pi }}{2}\left(\frac{2}{\sqrt{\pi }}\int_{2t}^\infty{e^{-u^2}\,\mathrm{d}u}\right)\\
  &=\frac{\pi }{2}-\frac{\pi }{2}\text{erfc}\left(\frac{\beta }{2}\right)\\
  \intertext{solution on p79}
  u(x,t)&=A\text{erfc}\left(\frac{x}{2\alpha \sqrt{t}}\right)
\end{align*}
\section*{last homework problem (hw09)}
we can do this without paying attention to formula's at all because the idea is so simple.
\begin{align*}
  u_x(0,t)&=0=f(t)\\
  u_x(1,t)+hu(1,t)&=1=g(t)
\end{align*}
introduce $u(x,t)=\omega (x,t)+\text{adjustment}$. This adjustment is chosen to obtain hetorgeneous boundary conditions ($f(t)=g(t)=0$). Take adjustment to be $+a(t)+bt)x$ because original boundary values (0 and 1) lie on a line.
\begin{align*}
  u&=\omega +a(t)+b(t)x\\
  \omega_x(0,t)+b(t)+0&=f(t)\\
  (\omega_x(1,t)+b(t))+h(\omega (1,t)+a(t)+b(t)\cdot1)&=g(t)
\end{align*}
\end{document}