\section{Models}
In this section, we describe the models used in this paper: BI-LSTM, CRF, and Bert.
\begin{figure*}[t]
    \begin{center}
        \includegraphics[width=\textwidth]{figures/model_struct.pdf}
    \end{center}
    \caption{Two model in this paper, BiLSTM + CRF \& Bert + CRF}
    \label{fig:model}
\end{figure*}

\subsection{Bi-LSTM}
\label{sec:lstm}

Recurrent neural networks (RNNs) are a family of neural networks that operate on sequential data. They take as input a sequence of vectors $(\mathbf{x}_1, \mathbf{x}_2, \ldots, \mathbf{x}_n)$ and return another sequence $(\mathbf{h}_1, \mathbf{h}_2, \ldots, \mathbf{h}_n)$ that represents some information about the sequence at every step in the input. Although RNNs can, in theory, learn long dependencies, in practice they fail to do so and tend to be biased towards their most recent inputs in the sequence. Long Short-term Memory Networks (LSTMs) have been designed to combat this issue by incorporating a memory-cell and have been shown to capture long-range dependencies. They do so using several gates that control the proportion of the input to give to the memory cell, and the proportion from the previous state to forget.
We use the following implementation:
\\
\begin{align*}
\mathbf{i}_{t} &= \sigma(\mathbf{W}_{xi}\mathbf{x}_{t} + \mathbf{W}_{hi}\mathbf{h}_{t-1} + \mathbf{W}_{ci}\mathbf{c}_{t-1} + \mathbf{b}_{i})\\
\mathbf{c}_{t} &= (1 - \mathbf{i}_{t})\odot\mathbf{c}_{t-1} +\\
&\qquad \mathbf{i}_{t}\odot \tanh(\mathbf{W}_{xc}\mathbf{x}_{t} + \mathbf{W}_{hc}\mathbf{h}_{t-1} + \mathbf{b}_{c})\\
\mathbf{o}_{t} &= \sigma(\mathbf{W}_{xo}\mathbf{x}_{t} + \mathbf{W}_{ho}\mathbf{h}_{t-1} + \mathbf{W}_{co}\mathbf{c}_{t} + \mathbf{b}_{o})\\
\mathbf{h}_{t} &= \mathbf{o}_{t}\odot\tanh(\mathbf{c}_{t}),
\end{align*}
where $\sigma$ is the element-wise sigmoid function, and $\odot$ is the element-wise product.

For a given sentence $(\mathbf{x}_1, \mathbf{x}_2, \ldots, \mathbf{x}_n)$ containing $n$ words, each represented as a $d$-dimensional vector, an LSTM computes a representation $\overrightarrow{\mathbf{h}_t}$ of the left context of the sentence at every word $t$. Naturally, generating a representation of the right context $\overleftarrow{\mathbf{h}_t}$ as well should add useful information. This can be achieved using a second LSTM that reads the same sequence in reverse. We will refer to the former as the forward LSTM and the latter as the backward LSTM. These are two distinct networks with different parameters. This forward and backward LSTM pair is referred to as a bidirectional LSTM.

The representation of a word using this model is obtained by concatenating its left and right context representations, $\mathbf{h}_{t} = [\overrightarrow{\mathbf{h}_{t}} ; \overleftarrow{\mathbf{h}_{t}}]$. These representations effectively include a representation of a word in context, which is useful for numerous tagging applications.

\subsection{CRF Tagging Models}
\label{sec:crf}

\begin{figure*}[t]
    \begin{center}
        \includegraphics[width=\textwidth]{figures/batch.pdf}
    \end{center}
    \caption{Train Set \& Dev Set epoch \& F1 distribute in CWS problem}
    \label{fig:batch}
\end{figure*}

\begin{figure*}[t]
    \begin{center}
        \includegraphics[width=\textwidth]{figures/batch2.pdf}
    \end{center}
    \caption{Train Set \& Dev Set epoch \& F1 distribute in NER problem}
    \label{fig:batch2}
\end{figure*}

A very simple---but surprisingly effective---tagging model is to use the $\mathbf{h}_t$'s as features to make independent tagging decisions for each output $y_t$ ~\cite{ling2015finding}. Despite this model's success in simple problems like POS tagging, its independent classification decisions are limiting when there are strong dependencies across output labels. NER is one such task, since the ``grammar'' that characterizes interpretable sequences of tags imposes several hard constraints (e.g., I-PER cannot follow B-LOC;) that would be impossible to model with independence assumptions.

Therefore, instead of modeling tagging decisions independently, we model them jointly using a conditional random field. For an input sentence
$$\mathbf{X} = (\mathbf{x}_1, \mathbf{x}_2, \ldots, \mathbf{x}_n),$$
we consider $\mathbf{P}$ to be the matrix of scores output by the bidirectional LSTM network. $\mathbf{P}$ is of size $n~\times~k$, where $k$ is the number of distinct tags, and $P_{i, j}$ corresponds to the score of the $j^{th}$ tag of the $i^{th}$ word in a sentence. For a sequence of predictions
$$\mathbf{y} = (y_1, y_2, \ldots, y_n),$$
we define its score to be
$$s(\mathbf{X}, \mathbf{y})=\sum_{i=0}^{n} A_{y_i, y_{i+1}} + \sum_{i=1}^{n} P_{i, y_i}$$
where $\mathbf{A}$ is a matrix of transition scores such that $A_{i, j}$ represents the score of a transition from the tag $i$ to tag $j$. $y_0$ and $y_n$ are the \textit{start} and \textit{end} tags of a sentence, that we add to the set of possible tags. $\mathbf{A}$ is therefore a square matrix of size $k+2$.
\\
\\
A softmax over all possible tag sequences yields a probability for the sequence $\mathbf{y}$:
$$p(\mathbf{y} | \mathbf{X}) = \frac{
	e^{s(\mathbf{X}, \mathbf{y})}
}{
	\sum_{\mathbf{\widetilde{y}} \in \mathbf{Y_X}} e^{s(\mathbf{X}, \mathbf{\widetilde{y}})}
}.$$
During training, we maximize the log-probability of the correct tag sequence:

\subsection{Bert}

\input{figures/corps.tex}
\input{figures/batch_size2.tex}
\input{figures/batchSize.tex}
\input{figures/hyper_param.tex}
\input{figures/bert.tex}
\input{figures/best.tex}

BERT is one of the key innovations in the recent progress of contextualized representation learning \cite{peters2018deep,howard2018universal,devlin2018bert}.
The idea behind the progress is that even though the word embedding layer (in a typical neural network for NLP) is trained from large-scale corpora, training a wide variety of neural architectures that encode contextual representations only from the limited supervised data on end tasks is insufficient.
Unlike ELMo \cite{peters2018deep} and ULMFiT \cite{howard2018universal} that are intended to provide additional features for a particular architecture that bears human's understanding of the end task, BERT adopts a fine-tuning approach that requires almost no specific architecture for each end task. This is desired as an intelligent agent should minimize the use of prior human knowledge in the model design. Instead, it should learn such knowledge from data. BERT has two parameter intensive settings:

\begin{itemize}
    \item {\bf \bertbase}: L=12, H=768, A=12, Total Parameters=110M
    \item {\bf \bertlarge}: L=24, H=1024, A=16, Total Parameters=340M
\end{itemize}


\chapter{Grammatical Evolution}
\section{Introduction}
This chapter introduces the main elements of Grammatical Evolution~\cite{ieee2001}~\cite{ge_book}. It begins by providing an overview of grammars, in particular, focusing on the Backus Naur form used by GE. It also provides brief descriptions of derivation trees and parse trees, two important conceptual tools used to describe the application and structure of a grammar. The basic mechanism of GE is also introduced showing a step-by-step evolution of a solution using a simple grammar. Many of the terms associated with GE and referenced in the following chapters are also introduced here.

\section{Grammars}
\label{grammars}
Grammars provide a means of formally describing a language. Grammars consist of rules, which determine the linguistic structure of sentences in the language, terminals, which are the words or symbols of the language, and non-terminals, which expand into one or more terminals. In a \emph{context free grammar} (CFG) the syntax of a symbol, terminal or non-terminal is the same regardless of what other symbols surround it. Where there is a single non-terminal the grammar can be described as \emph{closed}~\cite{ripple}.

Backus Naur Form (BNF), an example of which is shown in Figure~\ref{simple_grammar}, is a convenient descriptive notation for context free grammars is a notation for expressing the grammar of a language in the form of production rules. BNF consists of \emph{terminals}, which are items that can appear in the language, e.g. + - * etc. and \emph{non-terminals}, which can be expanded into one or more terminals and non-terminals.
A grammar can be represented by the tuple $<N,T,P,S>$ , where N is the set of non-terminals, T the set of terminals, P a set of production rules used to map elements of N to T. S a start symbol is a member of N.

\begin{figure}[tbp]
\begin{tabular}{p{12.8}}
\begin{verbatim}
N = {expr,op}
T = {+,-,/,*,X,(,)}
S = <expr>
P is a set of rules:
<expr>     :: == <var> | <expr><op><expr> | <pre-op>(<expr>)
                 | (<expr>)
<var>      :: == X
<op>       :: == + | - | * | /
<pre-op>   :: == sin | cos | tan | log
\end{verbatim}
\end{tabular}
\caption{\label{simple_grammar}Example Grammar presented in Backus Naur Form.}
\end{figure}

\begin{figure}[tbp]
\centerline{\hbox{
\psfig{file=Chapter2/graphs/derivation_tree.ps,width=3in}}}
\caption{Derivation Tree for the Expression $x + sin(x)$.}
\label{derivation_tree}
\end{figure}

\subsection{Derivation Trees}
A derivation tree is a way of showing graphically  the derivation of a sentence from a grammar. The generation of an expression in GE can be represented in this form. Figure~\ref{derivation_tree} shows a derivation tree for the expression $x + sin(x)$ using the simple grammar shown above. At the top of this tree we see the first derivation step in which the non-terminal $<expr>$ is replaced by $<expr><op><expr>$.

\subsection{Parse Trees}
\label{parse_trees}
A parse tree concerns itself only with terminals. It assists the breakdown of the linguistic structure of the language. The parse tree for the expression $x + sin(x)$ is shown in Figure~\ref{parse_tree}.

\begin{figure}[tpb]
\centerline{\hbox{
\psfig{file=Chapter2/graphs/parse_tree.ps,width=2in}}}
\caption{ Parse Tree for the Expression $x + sin(x)$.}
\label{parse_tree}
\end{figure}

\section{A Description of the Method}
\label{modulo}Grammatical Evolution (GE)~\cite{ieee2001}~\cite{ge_book} is an evolutionary algorithm that can evolve complete programs in an arbitrary language using a variable-length binary string. The binary string is decoded into a genome, which in turn is used to select production rules from a Backus Naur Form (BNF) grammar definition.  The system, illustrated in Figure~\ref{ge_fig1}, can use any search mechanism capable of generating a variable length sequence of integer codons. The codons, typically in the range 0 - 255, are used to select productions from the target grammar using the following function:
\small
\begin{displaymath}
\emph{Rule = (Codon value) MOD(Number of Rules for the current non-terminal)}
\end{displaymath}
\normalsize
A number of different codon values in the range 0 - 255 can cause selection of the same production rule. This occurs because the number of production rules associated with any non-terminal is generally small relative to the 256 expressible by a codon. This \label{sec:degeneracy} \emph{Genetic Code Degeneracy}~\cite{ieee2001} permits \emph{neutral mutation} which allows subtle changes in the search space without necessarily impacting the solution space (see Section~\ref{degeneracy}).

\begin{figure}[tbp]
\centerline{\hbox{
\psfig{file=Chapter2/graphs/ge_fig1.ps,width=3in}}}
\caption[Grammatical Evolution model.]{Grammatical Evolution, any metaheuristic capable of generating a variable length genome can be used with the system.}
\label{ge_fig1}
\end{figure}

Wrapping\label{sec:wrapping} is a technique employed by GE which allows the mapping process re-use codons from the genome. Once all codons in a genome have been used the process simply wraps to the start of the genome and continues the mapping process helping to improve the probability of a complete mapping of individuals onto programs.

The fitness associated with a solution is provided by evaluating the phenotype (i.e.,the program) using an interpreter for the target problem class. This fitness value is available to the generation mechanism to influence the future direction of the search strategy.
The following example illustrates the process of GE for the following simple expression:

\begin{displaymath}
f(x) = sin(x) + x^2 + x
\end{displaymath}

A grammar, which can be used to derive this simple expression, is shown below.

\small
\label{sect:simple_grammar_bnf}\begin{verbatim}

<expr>   :: == <var> | <expr><op><expr> | <pre-op>(<expr>)
                     | (<expr>)
<var>    :: == X
<op>     :: == + | - | * | /
<pre-op> :: == sin | cos | tan | log

\end{verbatim}
\normalsize

We present this grammar in tabular form in Figure~\ref{simple_grammar_table} and show the mapping process that occurs once the search engine has presented a codon to GE.

\begin{table}[h]
\begin{center}
\begin{tabular}{|l|l|l|l|l|l|}
\hline
\multicolumn{2}{|l|}{Non-Terminals}
&\multicolumn{4}{|l|}{Productions} \\
\hline
\multicolumn{2}{|l|}{ }
& 0 & 1 & 2 & 3 \\
\hline
1. & \verb|<expr>| & \verb|<var>| & \verb|<expr><op><expr>| & \verb|<pre-op>(<expr>| & \verb|(<expr>)| \\
2. & \verb|<var>| & X & & & \\
3. & \verb|<op>| & + & - & * & / \\
4. & \verb|<pre-op>| & sin & cos & tan & log \\
\hline
\end{tabular}
\caption{\label{simple_grammar_table}Simple grammar presented in table form.}
\end{center}
\end{table}

GE can use a depth first or a breadth first approach when mapping the codon string to an expression. The example shown in Table~\ref{bf_grammar_table1} and Table~\ref{bf_grammar_table2} illustrates the depth first approach which employs expansion of the left most non-terminal as the expression is created. Detailed commentary has been provided on the first nine derivation steps. The expanding non-terminal is shown in bold type through out Table~\ref{bf_grammar_table1} and Table~\ref{bf_grammar_table2} while the genome string used is shown in Figure~\ref{genome1}. Depth first expansion has been used in all of the trials reported in later sections.

\begin{figure}[!hbp]
\centerline{\hbox{
\psfig{file=Chapter2/graphs/genome1.xfig.ps,width=4in}}}
\caption{\label{genome1}Genome used in example of mapping process.}
\end{figure}

\begin{table}[!hbp]
\begin{center}
\begin{tabular}{|l|l|}
\hline
Step & Expression \\
\hline
0 & $ <expr>$ \\
  &     Start symbol. \\
\hline
1 & $ ( \mathbf{<expr>} )$ \\
  &    11 mod 4 = 3, Production 3 from row 1 was chosen. \\
\hline
2 & $ ( \mathbf{<expr>} <op> <expr> )$ \\
  &    57 mod 4 = 1, Production 1 from row 1 was chosen. \\
\hline
3 & $ (( \mathbf{<expr>}) <op> <expr> )$  \\
  &    91 mod 4 = 3, Production 3 from row 1 was chosen. \\
\hline
4 & $ ((\mathbf{<var>}) <op> <expr> )$ \\
  &   148 mod 4 = 0, Production 0 from row 1 was chosen. \\
\hline
5 & $ (( X ) \mathbf{<op>} <expr> )$  \\
  & There is only one choice for $<var>$ \\
  & so no codon was used for the transition to X. \\
\hline
6 & $ (( X ) * \mathbf{<expr>} )$ \\
  &  22 mod 4 = 2, Production 2 from row 4 was chosen. \\
\hline
7 & $ (( X ) * \mathbf{<expr>} <op> <expr> )$ \\
  &  129 mod 4 = 1, Production 1 from row 1 was chosen. \\
\hline
8 & $ (( X ) * \mathbf{<expr>} <op> <expr> <op> <expr> )$ \\
  & 53 mod 4 = 1, Production 1 from row 1 was chosen. \\
\hline
\hline
\end{tabular}
\caption{\label{bf_grammar_table1}Analysis of Depth First Mapping.}
\end{center}
\end{table}

\begin{table}[!hbp]
\begin{center}
\begin{tabular}{|l|l|}
\hline
Step & Expression \\
\hline
9 &  $ (( X ) * ( \mathbf{<expr>}) <op> <expr> <op> <expr>)$ \\ \hline
10 & $ (( X ) * (( \mathbf{<expr>})) <op> <expr> <op> <expr>)$ \\  \hline
11 & $ (( X ) * (( <var> )) \mathbf{<op>} <expr> <op> <expr>)$  \\ \hline
12 & $ (( X ) * (( X )) \mathbf{<op>} <expr> <op> <expr>)$  \\ \hline
13 & $ (( X ) * (( X )) + \mathbf{<expr>} <op> <expr>)$  \\ \hline
14 & $ (( X ) * (( X )) + \mathbf{<var>} <op> <expr>)$  \\ \hline
15 & $ (( X ) * (( X )) + X \mathbf{<op>} <expr>)$  \\ \hline
16 & $ (( X ) * (( X )) + X + \mathbf{<expr>})$  \\ \hline
17 & $ (( X ) * (( X )) + X + \mathbf{<pre-op>} (<expr>))$ \\ \hline
18 & $ (( X ) * (( X )) + X + Sin (\mathbf{<expr>}))$  \\ \hline
19 & $ (( X ) * (( X )) + X + Sin (\mathbf{<var>}))$  \\ \hline
20 & $ (( X ) * (( X )) + X + Sin (X))$  \\
\hline
\end{tabular}
\caption{\label{bf_grammar_table2}Analysis of Depth First Mapping (continued).}
\end{center}
\end{table}

\section{Expressed and Unexpressed Codons}
A feature of GE is the ability to use only those codons which are required to effect a successful mapping. The genome string presented to GE could, for example, contain 30 codons, if only 15 of these are required to map a successful solution then the remaining 15 remain unexpressed. Though these codons are unexpressed they are not completely redundant, because the polymorphic nature of GE means that these codons could come in to play as that genome evolves through mutation or recombination.

\section{Genetic Code Degeneracy and neutral mutation}
\label{degeneracy} Genetic code degeneracy is a phenomenon that can be observed in the genetic code of biological organisms~\cite{elseth}. It occurs where there is redundancy in the coding required to specify aspects of the DNA. This redundancy can neutralise the effects of mutation in cases where the mutated bits are those that are redundant to the coding. Kimura's neutral theory of evolution  ~\cite{kimura} suggests that it is \emph{neutral mutations} that are responsible for the genetic diversity found in natural populations.

Genetic code degeneracy occurs in GE by virtue of the fact that even though a codon can represent 256 distinct integer values, many of these values represent the same production rule. For example using the \emph{MOD rule} with 4 productions would result in codon values 8, 4, 12 and 16 all selecting the same production 0. It is apparent from this that genomes with differing codon compositions can map to the same solution.
This property of GE, which permits \emph {neutral mutation} on redundant codings, allows subtle changes in the search space without necessarily impacting the solution space.

\section{Summary}
This chapter has introduced Grammatical Evolution, showing in detail how a variable length string of integer values can be used to derive an expression in any language given a suitable grammar. An introduction was provided to the subject of language grammars with particular focus on the Backus Naur Form. The concepts of genetic code degeneracy, neutral mutation, and expressed and unexpressed genes were also introduced.


\documentclass[a4paper,10.5pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{wrapfig}
\usepackage{amssymb}
\usepackage{setspace}
\usepackage{bm}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,decorations.markings}
\usepackage{float}
\usepackage{cite}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage{color}
\renewcommand{\thefootnote}{\alph{footnote}}

\setlength{\textwidth}{16cm}
\setlength{\oddsidemargin}{0cm}
\setlength{\textheight}{23cm}
\setlength{\topmargin}{-1cm}
\setlength\parindent{0pt}
\renewcommand{\baselinestretch}{1.2}
\addtolength{\skip\footins}{7pt}

\pagestyle{fancyplain}
\lhead{}
\rhead{Tom Young 2021}
\cfoot{}
\lfoot{}

\begin{document}

\subsection{Gaussian Process Regression}

A Gaussian process (GP) is a collection of random variables such that any collection obey a multivariate normal distribution (MVN). Generally,
\begin{equation}
	\text{MVN} \sim \mathcal{N}(\boldsymbol{\mu}, \boldsymbol{\Sigma})
\end{equation}
is defined by its mean ($\boldsymbol{\mu} \in \mathbb{R}^d$) and covariance ($\boldsymbol{\Sigma} \in \mathbb{R}^{d \times d}$, positive semi-definite) for a $d$-dimensional distribution.%\footnote{The semi-definite requirement is because the PDF includes $\boldsymbol{\Sigma}^{-1}$.}

\begin{figure}[h!]
	\centering
	\includegraphics[width=\textwidth]{mvn_annotated.pdf}
	\vspace{0.1cm}
	\hrule
	\caption{Various multivariate normal distributions in one and two dimensions.}
\end{figure}

To use a GP for regression the output ($y$) is defined in a linear way,
\begin{equation}
	y = \sum_i w_i \,\phi_i(\boldsymbol{x}) \equiv \boldsymbol{w}^T\tilde{\boldsymbol{x}}
\end{equation}
where $\boldsymbol{w}$ are the weights to be found and $\phi_i$ is a non-linear basis function of the input values ($\boldsymbol{x}$). The distribution of outputs and weights are set to be Gaussians,
\begin{equation}
	\begin{aligned}
		y^* &= \boldsymbol{w}^T\tilde{\boldsymbol{x}} + \varepsilon \qquad : \quad
		\varepsilon \sim \mathcal{N}(0, \sigma^2)\\
		w &\sim \mathcal{N}(0, c\mathbb{I})  \qquad\;\; : \quad c \in \mathbb{R}
	\end{aligned}
\end{equation}
where the asterisk denotes a predicted value, $\boldsymbol{w}^T\tilde{\boldsymbol{x}} := z$ form the GP and $\epsilon$ is a Gaussian error.
\\\\
To do inference requires the posterior (predictive) distribution of $y$, given a set of known values. For the full set of $y$ then,\footnote{As the sum of independent MVNs just sum their means and covariances.}
\begin{equation}
	\begin{aligned}
		\boldsymbol{y}^* &= \boldsymbol{z} + \boldsymbol{\varepsilon} \\
		&\sim \mathcal{N}(\boldsymbol{\mu}, \mathsf{K} + \sigma^2\mathbb{I})
	\end{aligned}
\end{equation}
defining $\mathsf{C} = \mathsf{K} + \sigma\mathbb{I}$ and splitting the vectors and matrices into known (train) and an unknown (${}^*$) components,

\begin{equation}
	\begin{pmatrix}
		y^*\\
		\boldsymbol{y}_\text{train}
	\end{pmatrix}
	\sim \mathcal{N}\left(
		\begin{pmatrix}
			\mu*\\
			\boldsymbol{\mu_\text{train}}
		\end{pmatrix}
	,
	\begin{pmatrix}
		\mathsf{C}^* & \mathsf{C}^*_\text{train} \\
		\mathsf{C}^{* T}_\text{train} & \mathsf{C}_\text{train}
	\end{pmatrix}
	\right)
\end{equation}

then the conditional distribution of $y^*$ is,

\begin{equation}
	(y^* | \boldsymbol{y}_\text{train}) \sim \mathcal{N}(\mu^* +  \mathsf{C}^{* T}_\text{train}\mathsf{C}_\text{train}^{-1}(\boldsymbol{y}_\text{train} - \boldsymbol{\mu}_\text{train})
	, \mathsf{D})
\end{equation}
where $\mathsf{D}$ is the covariance the exact form of which is omitted.
\\\\
{\large\bfseries{References}}

[1] C. E. Rasmussen and C. K. I. Williams, Gaussian Processes for Machine Learning, the MIT Press, 2006,
ISBN 026218253X.

\end{document}


\documentclass[a4paper,UKenglish,cleveref, autoref]{lipics-v2019}
%This is a template for producing LIPIcs articles.
%See lipics-manual.pdf for further information.
%for A4 paper format use option "a4paper", for US-letter use option "letterpaper"
%for british hyphenation rules use option "UKenglish", for american hyphenation rules use option "USenglish"
%for section-numbered lemmas etc., use "numberwithinsect"
%for enabling cleveref support, use "cleveref"
%for enabling cleveref support, use "autoref"

%\graphicspath{{./graphics/}}%helpful if your graphic files are in another directory

\bibliographystyle{plainurl}% the mandatory bibstyle

\title{Integrality of stable matchings polytope} %TODO Please add

% \titlerunning{Dummy short title}%optional, please use if title is longer than one line

\author{Kishlaya Jaiswal}{Chennai Mathematical Institute }{kishlaya@cmi.ac.in}{}{}%TODO mandatory, please use full name; only 1 author per \author macro; first two parameters are mandatory, other parameters can be empty. Please provide at least the name of the affiliation and the country. The full address is optional

\authorrunning{K. Jaiswal}%TODO mandatory. First: Use abbreviated first/middle names. Second (only in severe cases): Use first author plus 'et al.'

\Copyright{Kishlaya Jaiswal}%TODO mandatory, please use full first names. LIPIcs license is "CC-BY";  http://creativecommons.org/licenses/by/3.0/

%\ccsdesc[100]{General and reference~General literature}
%\ccsdesc[100]{General and reference}%TODO mandatory: Please choose ACM 2012 classifications from https://dl.acm.org/ccs/ccs_flat.cfm

%\keywords{Dummy keyword}%TODO mandatory; please add comma-separated list of keywords

%\category{}%optional, e.g. invited paper

%\relatedversion{}%optional, e.g. full version hosted on arXiv, HAL, or other respository/website
%\relatedversion{A full version of the paper is available at \url{...}.}

%\supplement{}%optional, e.g. related research data, source code, ... hosted on a repository like zenodo, figshare, GitHub, ...

%\funding{(Optional) general funding statement \dots}%optional, to capture a funding statement, which applies to all authors. Please enter author specific funding statements as fifth argument of the \author macro.

%\acknowledgements{I want to thank \dots}%optional

\nolinenumbers %uncomment to disable line numbering

\hideLIPIcs  %uncomment to remove references to LIPIcs series (logo, DOI, ...), e.g. when preparing a pre-final version to be uploaded to arXiv or another public repository

%Editor-only macros:: begin (do not touch as author)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\EventEditors{John Q. Open and Joan R. Access}
\EventNoEds{2}
\EventLongTitle{42nd Conference on Very Important Topics (CVIT 2016)}
\EventShortTitle{CVIT 2016}
\EventAcronym{CVIT}
\EventYear{2016}
\EventDate{December 24--27, 2016}
\EventLocation{Little Whinging, United Kingdom}
\EventLogo{}
\SeriesVolume{42}
\ArticleNo{23}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\theoremstyle{definition}
\newtheorem*{lemma*}{Lemma}
\newtheorem*{definition*}{Definition}
\newtheorem*{theorem*}{Theorem}
\begin{document}

\maketitle

%TODO mandatory: add short abstract of the document
\begin{abstract}
Given a complete bipartite graph with edge preferences, we know that Gale-Shapley algorithm confirms the existence of (and outputs) a stable matching. Further, we know that perfect matching polytope is integral. We want to add additional constraints corresponding to stability and see if these new constraints still keeps the polytope integral.

U. Rothblum showed that integrality of polytope remains intact even if the preference lists of men and women are incomplete, in his 1992 paper - \textsl{Characterization of stable matchings as extreme points of a polytope}, which I shall present now.
\end{abstract}

\section{Modelling Perfect Matchings}
\label{sec:typesetting-summary}

Consider the problem of determining a perfect matching for complete bipartite graph $(U,V)$ (with $|U|=|V|$). We know that it can be modeled using a system of linear inequalities as follows:

\begin{align}
    \sum_{j \in V} x_{ij} &= 1 & \forall i \in U \\
    \sum_{i \in U} x_{ij} &= 1 & \forall j \in V \\
    x_{ij} &\geq 0 & \forall (i,j) \in U \times V
\end{align}

We have variables $\{x_{ij}\}$ for each edge $(i,j) \in U \times V$, such that $x_{ij} = 1$ iff $(i,j)$ edge is in the matching, otherwise $x_{ij}=0$.

\begin{remark*}
In convex optimization problems, when the underlying polytope is integral, linear programming can be used to solve integer programming problems for the given system of inequalities, a problem that can otherwise be more difficult.
\end{remark*}

So the first question arises is if this polytope $P$ is integral, after the relaxation of variables $0 \leq x_{ij} \leq 1$?

Here is an interesting observation: the matrix $(x_{ij})_{U \times V}$ is a doubly stochastic matrix iff $\{x_{ij}\}$ is a feasible point for the polytope $P$. And furthermore, each perfect matching corresponds to a permutation matrix.

\textsl{Birkhoff-von Neumann} theorem states that polytope $P$ is the convex hull of $U \times V$ permutation matrices and furthermore that the vertices of the polytope $P$ are precisely the permutation matrices. Therefore, the perfect matchings are the extreme (integer) points of this polytope.

% \section{Stable Perfect Matching}

% Returning back to our stable perfect matching problem, we first ask: can the stability constraint be modeled as a linear inequality? And if so, then does the resulting polytope still has the integrality of extreme points?

% Rothblum addressed this problem in a more general setting, that is when lists are incomplete, strict and singlehood is permitted (some vertices can remain unmatched). This is what we shall discuss now.

\section{Stable Matching with Incomplete Lists}

We begin with sets of men $M$ and women $W$ (not necessarily equal in size). Each man $m$ has preference list $W_m \subseteq W$ along with a strict preference order $>_m$ on it, such that $w_1 >_m w_2$ (where $w_1, w_2 \in W_m$) means $m$ prefers $w_1$ over $w_2$. Similarly we have $(M_w, >_w)$ as the preference list for each woman $w$.
% We will assume that the lists are consistent that is $w \in W_m \iff m \in M_w$.

Now since the lists are incomplete, some people might remain unmatched as well. we need to re-setup linear inequalities to denote a matching between men and women:

% =============================================
%  Make the following equations align properly
% =============================================

\begin{align}
    \sum_{j \in W} x_{ij} \leq 1 && \forall i \in M \\
    \sum_{i \in M} x_{ij} \leq 1 && \forall j \in W \\
    x_{ij} \geq 0 && \forall (i,j) \in M \times W
\end{align}

We additionally also want that if a woman doesn't appears in some man's list then that edge variable should be zero, that is, let $A = \{(m,w) \mid m \in M_w \text{ and } w \in W_m\}$ be the set of possible pairs, then

\begin{align}
    x_{ij} = 0 && \forall (i,j) \not \in A
\end{align}

Now we need the final constraint for stability. For that we redefine blocking pair. Given a matching $N$, $(m,w) \in A$ blocks $N$ if any of the following holds:
\begin{itemize}
    \item $m$ and $w$ both have a partner in $N$ but $w >_m N(m)$ and $m >_w N(w)$
    \item Only $m$ has a partner in $N$ but $w >_m N(m)$
    \item Only $w$ has a partner in $N$ but $m >_w N(w)$
    \item Both $m$ and $w$ don't have partners in $N$
\end{itemize}

Hence the stability constraint should be:

\begin{align}
    \sum_{j >_m w} x_{mj} + \sum_{m >_ w i} x_{iw} + x_{mw} \geq 1 && \forall (m,w) \in A
\end{align}

Indeed if $\sum_{j >_m w} x_{mj} + \sum_{m >_ w i} x_{iw} + x_{mw} < 1 \implies \sum_{j >_m w} x_{mj} = \sum_{m >_ w i} x_{iw} = x_{mw} = 0$ which means that either $m$ has no partner or if he does then $w >_m x(m)$ and similarly either $w$ has no partner or if she does then $m >_w x(w)$.

\begin{remark*}
The same stability constraint works in the case of equal sizes of both sets of men and women and complete lists also.
\end{remark*}

We also note that if $\sum_{j >_m w} x_{mj} + \sum_{m >_ w i} x_{iw} + x_{mw} = 1$ then either $m$ and $w$ are matched together or one of them has a strictly better and other has strictly worse partner.

The only other possibility is $\sum_{j >_m w} x_{mj} + \sum_{m >_ w i} x_{iw} + x_{mw} = 2$ which says that both $m$ and $w$ have strictly better partners.
\newline

Finally, we relax our variables to $0 \leq x_{ij} \leq 1$ and discuss the integrality of the polytope $(4)-(8)$: \textsl{the stable matching polytope}.

% \newpage

We begin by showing that every integer point is an extreme point. Before we proceed I'd like to add a remark here that the author directly concludes this as a consequence of Birkhoff theorem. In my opinion, the result is not so straight-forward as feasible points may not be doubly stochastic. So we shall state (and prove) here a generalization of the Birkhoff theorem from which the result shall follow.

\begin{definition*}
A matrix $Q$ is said to be doubly substochastic if its entries are nonnegative and all its row and column sums are at most one.
\end{definition*}
\begin{definition*}
A matrix P is said to be a partial permutation matrix if it has at most one nonzero entry in each row and column, and these nonzero entries (if any) are all $1$.
\end{definition*}
\begin{theorem*}
Every doubly substochastic matrix is a finite convex combination of partial permutation matrices. Conversely, a finite convex combination of partial permutation matrices is evidently double substochastic.
\end{theorem*}
\begin{proof}
Let $Q$ be a doubly substochastic matrix. Consider the matrix $Q' = \begin{bmatrix} Q & I-D_r\\I-D_c & Q^T\end{bmatrix}$, where $D_r$ and $D_c$ are diagonal matrices with the row and column sums of $Q$ respectively. Notice that $Q'$ is now a doubly stochastic matrix and hence we can now apply Birkhoff theorem to complete the proof.
\end{proof}

Here is a simple observation: Let $P$ be a polytope such that all it's integer points are extreme points, then for any subpolytope $Q \subseteq P$ all it's integer points are extreme points.

We mention this because the equations $(4)-(6)$ form a simple polytope where each feasible point can be identified with a substochastic matrix and integral feasible point with a partial permutation matrix, and vice-versa. Hence we can apply our above theorem and observation to conclude that any integer point is an extreme point for the stable matching polytope.
\newline

Conversely, let $\{x_{ij}\}$ be an extreme point. We want to argue that if it is not integral then it can be written as a convex combination of two other feasible points. For that, we consider two extreme matchings which can be extracted out of any feasible solution. Denote by $S_M(x) = \{m \in M \mid \sum_{j \in W} x_{mj} > 0\}$ (men who weren't left unmatched). For $m \in S_M(x)$ let $W^*(x,m)$ and $W_*(x,m)$ be the most preferred woman and the least preferred woman of $m$ in the list $\{w \mid x_{mw} > 0\}$, respectively. Similarly we can define $S_W(x) = \{w \in W \mid \sum_{i \in M} x_{iw} > 0\}$ and maps $M^*(x,w)$ and $M_*(x,w)$ for all $w \in S_W(x)$.

What we shall do is for every man $m \in S_M(x)$ increment the edge variable $(m, W^*(x,m))$ by $\epsilon$ and decrement $(m, W_*(x,m))$ by $\epsilon$. This shall give us another feasible solution. Similarly, if we exchange the increment/decrement in above process, then we get another feasible solution. And then $x$ is the middle point of these two feasible solutions. To make this idea precise, we define our extreme matchings $x^*$ and $x_*$ as follows:

$$
(x^*)_{mw} =
     \begin{cases}
       1 &\quad m \in S_M(x) \text{ and } w=W^*(x,m) \\
       0 &\quad \text{otherwise.} \\
     \end{cases}
$$

$$
(x_*)_{mw} =
     \begin{cases}
       1 &\quad m \in S_M(x) \text{ and } w=W_*(x,m) \\
       0 &\quad \text{otherwise.} \\
     \end{cases}
$$

Observe that $x$ is a matching (integer point) iff $x^*=x_*$ that is both the most preferred and least preferred partner are same. So we consider $z = x^* - x_*$. To proceed, we state a few properties about $z$, corresponding to our original constraints:

\begin{itemize}
    \item $\sum_{j \in W} z_{ij} = 0, i \in M$ (row sums are zero)
    \item $\sum_{i \in M} z_{ij} = 0, j \in W$ (column sums are zero)
    \item $x_{ij} = 0 \implies z_{ij} = 0, (i,j) \in M \times W$
    \item $z_{ij} = 0, (i,j) \not \in A$
    \item $\left(\sum_{j >_m w} x_{mj} + \sum_{m >_ w i} x_{iw} + x_{mw} = 1 \right) \implies \left(\sum_{j >_m w} z_{mj} + \sum_{m >_ w i} z_{iw} + z_{mw} = 0\right)$
\end{itemize}

Assuming these properties, we can choose a small enough $\epsilon > 0$, such that both $x + \epsilon z$ and $x - \epsilon z$ are feasible solutions. Then we re-write $x = \frac{1}{2}(x + \epsilon z) + \frac{1}{2}(x - \epsilon z)$. Since $x$ was an extreme point, we conclude that $z=0$ and hence the integrality of $x$ follows.

To prove above-mentioned properties we shall build some results (which shall be of independent interest) using our intuition from stable marriage with complete lists problem. An essential result we had was men-optimal matching is women-pessimal and vice-versa. Rothblum establishes a similar result here.

\begin{lemma*}
For $(m,w) \in A$,
\begin{itemize}
    \item $\Big( \big(m \not \in S_M(x)\big)$ or $\big(m \in S_M(x)$ and $w \geq_m W^*(x,m)\big) \Big)$ $\implies$ $\Big(\sum_{i \in M} x_{iw} = 1$ and $m \leq_w M_*(x,w)\Big)$ (Converse is also true provided $\sum_{j >_m w} x_{mj} + \sum_{m >_ w i} x_{iw} + x_{mw} = 1$)
    \item $\big( m \in S_M(x)$ and  $w = W^*(x,m) \big) \iff \big( \sum_{i \in M} x_{iw} = 1$ and $m = M_*(x,w) \big)$
    \item $m \in S_M(x) \iff \sum_{j \in W} x_{mj} = 1$
\end{itemize}
\end{lemma*}

The first two points dictate what we said about optimality vs pessimality, whose proofs follow from a simple manipulation of inequalities. But I, particularly, find the last point of more interest as it tells that the row sums are always either $0$ or $1$, which was apriori not at all expected. The proof technique used for this point is equally interesting and moreover helps in establishing the validity of the matchings $x^*$ and $x_*$.

It is clear that that if $\sum_{j \in W} x_{mj} = 1$ then $m \in S_M(x)$. For the converse, Let us consider the set $F_W(x) = \{w \mid \sum_{i \in M} x_{iw}=1\}$ and the map $W^*(x,.) : S_M(x) \rightarrow F_W(x)$ (definition is valid because of the second point in the lemma). Moreover, injectivity also follows from the second point because if $w=W^*(x,m_1)=W^*(x,m_2)$ then $m_1 = M_*(x,w) = m_2$. Now consider the following inequality:

$$|F_W(x)| = \sum_{j \in F_W(x)} \sum_{i \in M} x_{ij} = \sum_{i \in S_M(x)} \sum_{j \in F_W(x)} x_{ij} \leq \sum_{i \in S_M(x)} 1 = |S_M(x)|$$

Implying that it is surjective also and hence equality is achieved in the above equation, which tells us that for $i \in S_M(x)$ $\sum_{j \in F_W(x)} x_{ij} = 1$, completing the proof.

Similarly, with the roles reversed, we have the analogous lemma:
\begin{lemma*}
For $(m,w) \in A$,
\begin{itemize}
    \item $\Big( \big[w \not \in S_W(x)\big]$ or $\big[w \in S_W(x)$ and $m \geq_w M^*(x,w)\big] \Big)$ $\implies$ $\Big(\sum_{j \in W} x_{mj} = 1$ and $w \leq_m W_*(x,m)\Big)$ (Converse is also true provided $\sum_{j >_m w} x_{mj} + \sum_{m >_ w i} x_{iw} + x_{mw} = 1$)
    \item $\big[ w \in S_W(x)$ and  $m = M^*(x,w) \big] \iff \big[ \sum_{j \in W} x_{mj} = 1$ and $w = W_*(x,m) \big]$
    \item $w \in S_W(x) \iff \sum_{i \in M} x_{iw} = 1$
\end{itemize}
\end{lemma*}

I would like to add that since the row and columns sums are always $1$ (or $0$ in case someone remains unmatched), as established by the above lemmas, the exact same proof goes through in the original stable marriage with complete lists instance.

\section{Conclusion}

It is interesting to note that these lemmas indeed add a lot of structure/restrictions on the feasible points. They can be used to give an easy proof for the \textsl{Decomposition property}, which is: if $x$ and $y$ are two stable matchings, and $(m,w)$ is a pair in the matching $x$, then if one of them prefers the matching $x$ over $y$ then their partner prefers the matching $y$ over $x$ - which seems intuitive from our optimality vs pessimality result.

As a last remark, Rothblum adds that in the case of many-to-one matching, for example: students have to be matched to colleges where several students can be matched to a single college, depending upon the number of available seats; our results can be easily extended by cloning each college as many times as available seats in that college, and uniformly ordering them in each student's list.

\section{Further Work}

Following this course, the next immediate question for me to ask would be: What happens if there are ties in the preference lists?

In such a case, the ordering on the preference lists will not be strict one. We have crucially used that strictness in our stability constraint and in the lemmas. So it is interesting to see where would (if) the above lemmas fail?

We have also seen in class that there are different notions of stability in case of ties. So, I would like to study about the following:
\begin{itemize}
    \item Can we model super-stability, strong-stability and weak-stability respectively as linear inequalities?
    \item Will the resulting polytope be integral with those matchings as their extreme points?
\end{itemize}
\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%		Thesis Settings
%		Custom settings
%
%		2011
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %
% %   Use this file for your own custom packages, command-definitions, etc...
% %
% %
% % Packages for references - cleverref must be last
% \usepackage{nameref}
% \usepackage{hyperref}
% \usepackage{cleveref}
% \usepackage[shortlabels]{enumitem}
% % Reduce spacing in bibliography
% \setlength{\bibsep}{0pt plus 0.3ex}
% % Allow equations to break between pages
% \allowdisplaybreaks
% % Penalty for widow and orphan
% \widowpenalty=9999
% \clubpenalty=9999
% %Penalty for relation and binary operation breaks in equations
% \relpenalty=9999
% \binoppenalty=9999

% \usepackage{amsmath}
\usepackage{amsmath,amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}

% For the nice bold Ex symbol // dosent work
% \DeclareRobustCommand{\bbone}{\text{\usefont{U}{bbold}{m}{n}1}}
% \makeatletter
% \def\thm@space@setup{%
%   \thm@preskip=1cm plus 0cm minus 0cm
%   \thm@postskip=\thm@preskip % or whatever, if you don't want them to be equal
% }
% \makeatother

\newtheoremstyle{thmstyle}
  {.5em plus .1em minus .1em}%   Space above
  {.5em plus .1em minus .1em}%   Space below
  {} % Body font
  {} % Indent amount
  {\bfseries} % Theorem head font
  {.} % Punctuation after theorem head
  {.5em} % Space after theorem head
  {} % Theorem head spec (can be left empty, meaning `normal')

\theoremstyle{thmstyle}
\newtheorem{theorem}{Theorem}

\theoremstyle{thmstyle}
\newtheorem{lemma}{Lemma}

\theoremstyle{thmstyle}
\newtheorem{definition}{Definition}

% \newenvironment{proof}{\paragraph{Proof:}}{\hfill$\square$}
% for indep symbol
\newcommand{\bigCI}{\mathrel{\text{\scalebox{1.07}{$\perp\mkern-10mu\perp$}}}}
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%

% Fix the problem with delimiter size caused by fourier and amsmath packages.
\makeatletter
\def\resetMathstrut@{%
  \setbox\z@\hbox{%
    \mathchardef\@tempa\mathcode`\(\relax
      \def\@tempb##1"##2##3{\the\textfont"##3\char"}%
      \expandafter\@tempb\meaning\@tempa \relax
  }%
  \ht\Mathstrutbox@1.2\ht\z@ \dp\Mathstrutbox@1.2\dp\z@
}
\makeatother

% algo
% \usepackage[noend]{algpseudocode}
% \usepackage{algorithm,algorithmicx}

% \newcommand*\Let[2]{\State #1 $\gets$ #2}
% \algrenewcommand\algorithmicrequire{\textbf{Precondition:}}
% \algrenewcommand\algorithmicensure{\textbf{Postcondition:}}

\usepackage{algorithm,algpseudocode}

\newcounter{algsubstate}
\renewcommand{\thealgsubstate}{\alph{algsubstate}}
\newenvironment{algsubstates}
  {\setcounter{algsubstate}{0}%
   \renewcommand{\State}{%
     \stepcounter{algsubstate}%
     \Statex {\footnotesize\thealgsubstate:}\space}}
  {}

%

\usepackage{dsfont}
\DeclareMathOperator{\E}{\mathds{E}}
\newcommand{\R}{\mathds{R}}
\newcommand{\N}{\mathds{N}}
\newcommand{\Z}{\mathds{Z}}
\newcommand{\Ind}{\mathds{1}}
\newcommand{\Prob}{\mathds{P}}
% Avoid blank page from \mainmatter

\makeatletter
\renewcommand\mainmatter{\clearpage\@mainmattertrue\pagenumbering{arabic}}
\makeatother

% Change font
% \renewcommand{\familydefault}{\sfdefault}

% Nice math cal
\DeclareMathAlphabet{\mathcal}{OMS}{cmsy}{m}{n}

\DeclarePairedDelimiterX{\inp}[2]{\langle}{\rangle}{#1, #2}

% Tikz

\usepackage{pgf}
\usetikzlibrary{arrows, automata}

\newcommand{\Tau}{\mathrm{T}}

\makeatletter
\let\oldabs\abs
\def\abs{\@ifstar{\oldabs}{\oldabs*}}

\DeclarePairedDelimiterX{\infdivx}[2]{(}{)}{%
  #1\;\delimsize\|\;#2%
}
\newcommand{\infdiv}{D_f\infdivx}

\usepackage{pgfplots}

\usepackage{enumitem}

% load the CM symbol font
\DeclareSymbolFont{arrows}{OMS}{cmsy}{m}{n}
% change the arrows to be taken from the CM symbol font
\DeclareMathSymbol{\leftrightarrow}{\mathrel}{arrows}{"24}
\DeclareMathSymbol{\leftarrow}{\mathrel}{arrows}{"20}
   \let\gets=\leftarrow
\DeclareMathSymbol{\rightarrow}{\mathrel}{arrows}{"21}
   \let\to=\rightarrow
\DeclareMathSymbol{\mapstochar}{\mathrel}{arrows}{"37}

\usetikzlibrary{positioning}


\chapter{Appendix: \uclid{} Grammar}

\newcommand{\paratitle}[1]{\textsf{\textbf{#1}}}
\newcommand{\nonterminal}[1]{$\langle \textit{#1} \rangle$}

\setlength{\grammarindent}{12em} % increase separation between LHS/RHS

This appendix describes \uclid{}'s grammar.

\section{Grammar of Modules and Declarations}
\paratitle{A model} consist of a list of modules. Each module consists of a list of declarations followed by an optional control block.
\begin{grammar}
     <Model> ::= <Module>*

     <Module> ::= \keywordbf{module} <Id>~~ `{' <Decl>* <ControlBlock>? `}'
\end{grammar}

\paratitle{Declarations} can be of the following types.
\begin{grammar}
     <Decl> ::= <TypeDecl>
            \alt <InputsDecl>
            \alt <OutputsDecl>
            \alt <VarsDecl>
            \alt <SharedVarsDecl>
            \alt <DefineDecl>
            \alt <ConstsDecl>
            \alt <ConstLitDecl>
            \alt <FuncDecl>
            \alt <ProcedureDecl>
            \alt <InstanceDecl>
            \alt <InitDecl>
            \alt <NextDecl>
            \alt <AxiomDecl>
            \alt <SpecDecl>
\end{grammar}

\paratitle{Type declarations} declare either a type synonym or an uninterpreted type.
\begin{grammar}
     <TypeDecl> ::= \keywordbf{type} <Id> `=' <Type> `;'
              \alt \keywordbf{type} <Id> `;'

\end{grammar}

\paratitle{Variable declarations} can refer to inputs, outputs, state variables, symbolic constants, named constant literals, shared variables, or define declarations.
\begin{grammar}
     <InputsDecl> ::=
       \keywordbf{input} ~ <IdList> `:' <Type> `;'

     <OutputsDecl> ::=
       \keywordbf{output} ~ <IdList> `:' <Type> `;'

     <VarsDecl> ::=
       \keywordbf{var} ~ <IdList> `:' <Type> `;'

     <ConstsDecl> ::=
       \keywordbf{const} ~ <IdList> `:' <Type> `;'

     <ConstLitDecl> ::=
       \keywordbf{const} ~ <Id> ~ `:' <Type> = <Number> `;'

     <SharedVarsDecl> ::=
       \keywordbf{sharedvar} ~ <IdList> `:' <Type> `;'

     <DefineDecl> ::=
       \keywordbf{define} <Id> `(' <IdTypeList> `)' `:' <Type> `=' <Expr>  `;'

\end{grammar}

\paratitle{Function declarations} refer to uninterpreted functions.
\begin{grammar}
     <FuncDecl> ::=
       \keywordbf{function} <Id> `(' <IdTypeList> `)' `:' <Type> `;'

\end{grammar}

\paratitle{Procedure declarations} consist of a formal parameter list, a list of return values and types,
followed by optional pre-/post-conditions and the list of state variables modified by procedure.
\begin{grammar}
     <ProcedureDecl> ::=
       \keywordbf{procedure} <Id> `(' <IdTypeList> ')' <ProcReturnArg>? \\
       <RequireExprs> <EnsureExprs> <ModifiesExprs> \\
       <BlkStmt>

     <ProcReturnArg> ::= \keywordbf{returns} `(' <IdTypeList> `)'

     <RequireExprs> ::= ( \keywordbf{requires} <Expr> `;' )*

     <EnsureExprs> ::= ( \keywordbf{ensures} <Expr> `;' )*

     <ModifiesExprs> ::= ( \keywordbf{modifies} <IdList> `;' )*

\end{grammar}

\paratitle{Instance declarations} allow the instantiation (duh!) of other modules. They consist of the instance name, the name of the module being instantiated and the list of mappings for the instances' inputs, output and shared variables.
\begin{grammar}
     <InstanceDecl> ::= \keywordbf{instance} <Id> `:' <Id> <ArgMapList> `;'

     <ArgMapList>   ::= `(' `)'
                    \alt `(' <ArgMap> `,' <ArgMapList> `)'

     <ArgMap> ::= <Id> `:' `(' `)'
              \alt <Id> `:' `(' <Expr> `)'

\end{grammar}

\paratitle{Axioms} refer to assumptions while a \paratitle{specification declaration} refers to design \keywordbf{invariants}. Note \keywordbf{axiom} and \keywordbf{assume} are synonyms, as are \keywordbf{property} and \keywordbf{invariant}.

\begin{grammar}
     <AxiomDecl> ::= <AxiomKW> <Id> `:' <Expr> `;'
                 \alt <AxiomKW> <Expr> `;'

     <AxiomKW> ::= \keywordbf{axiom} | \keywordbf{assume}

     <SpecDecl> ::= <PropertyKW> <Id> `:' <Expr> `;'
                 \alt <PropertyKW> <Expr> `;'

     <PropertyKW> ::= \keywordbf{property} | \keywordbf{invariant}
\end{grammar}

\paratitle{Init} and \paratitle{next} blocks consist of lists of statements.
\begin{grammar}
     <InitDecl> ::= \keywordbf{init} <BlkStmt>

     <NextDecl> ::= \keywordbf{next} <BlkStmt>

\end{grammar}
Assignment statements in the \keywordbf{next} block declaration must
assign primed variables only, and are concurrently evaluated.

\section{Statement Grammar}
\paratitle{Statements} are the following types, most of which should be familiar. Note the support for simultaneous assignment \`a la Python. The keyword \keywordbf{next} allows for synchronous scheduling of instantiated modules.
\begin{grammar}
     <Statement>
       ::= \keywordbf{skip} `;'
       \alt \keywordbf{assert} <Expr> `;'
       \alt \keywordbf{assume} <Expr> `;'
       \alt \keywordbf{havoc} <Id>  `;'
       \alt <LhsList> `=' <ExprList> `;'
       \alt \keywordbf{call} `(' <LhsList> `)' `=' <Id> <ExprList> `;'
       \alt \keywordbf{call} <Id> `(' <ExprList> `)' `;'
       \alt \keywordbf{next} `(' <Id> `)' `;'
       \alt <IfStmt>
       \alt <CaseStmt>
       \alt <ForLoop>
       \alt <WhileLoop>
       \alt <BlkStmt>
\end{grammar}

\paratitle{Block statements} are a list of variables with local scope, and a list of statements.

\begin{grammar}
    <BlkStmt> ::= `{' <BlockVarDecl>* <Statement>* `}'

    <BlockVarDecl> ::= \keywordbf{var} <IdList> `:' <Type> `;'
\end{grammar}

\paratitle{Assignments} and \paratitle{call} statements refer to the nonterminal \nonterminal{LhsList}. As the name suggests, this is a list of syntactic forms that can appear on the left hand side of an assignment. \nonterminal{Lhs} are of four types: (i) identifiers, bitvector slices within identifiers, (iii) array indices, and (iv) fields within records.
\begin{grammar}
    <LhsList> ::= <Lhs> (`,' <Lhs>)*

    <Lhs> ::= <Id>
	  \alt <Id> `''
          \alt <Id> `[' <Expr> `:' <Expr> `]'
          \alt <Id> `[' <ExprList> `]'
          \alt <Id> (`.' <Id>)+
\end{grammar}

\paratitle{If} statements are as per usual. ``Braceless'' if statements are not permitted.
\begin{grammar}
    <IfStmt> ::=
    \keywordbf{if} `(' <CondExpr> `)'  <BlkStmt> \\ \keywordbf{else} <BlkStmt>
    \alt \keywordbf{if} `(' <CondExpr> `)'  <BlkStmt>

    <IfExpr> ::= <Expr> | *
\end{grammar}

\paratitle{Case} statements are as follows.
\begin{grammar}
    <CaseStmt> ::= \keywordbf{case} <CaseBlock>* \keywordbf{esac}

    <CaseBlock> ::= <Expr> `:' <BlkStmt>
                \alt \keywordbf{default} `:' <BlkStmt>
\end{grammar}

\paratitle{For loops} allow iteration over a statically defined range of values.
\begin{grammar}
    <ForLoop> ::= \keywordbf{for} <Id> \keywordbf{in} \keywordbf{range} `(' <Number> ',' <Number> `)' \\
                  <BlkStmt>
\end{grammar}

\paratitle{While loops} allow unbounded iteration.
\begin{grammar}
    <WhileLoop> ::= \keywordbf{while} `(' <CondExpr> `)' \\
                  <InvariantClause>* \\
                  <BlkStmt>

    <InvariantClause> ::= \keywordbf{invariant} <Expr> `;'
\end{grammar}

\section{Expression Grammar}
Let us turn to \paratitle{expressions}, which may be quantified.
\begin{grammar}
    <Expr> ::= <E1>

    <E1> ::= <E2>
         \alt `(' \keywordbf{forall} `(' <IdTypeList> `)' `::' E1 `)'
         \alt `(' \keywordbf{exists} `(' <IdTypeList> `)' `::' E1 `)'

\end{grammar}

The usual logical and bitwise operators are allowed.
\begin{grammar}
    <E2> ::= <E3> `<==>' <E2> | <E3>

    <E3> ::= <E4> `==>' <E3> | <E4>

    <E4> ::=  <E5> `&&' <E4> | <E5> `||' <E4> |
         \alt <E5> `&' <E4> | <E5> `|' <E4> | <E5> `^' <E4>
         \alt <E5>
\end{grammar}

As are relational operators, bitvector concatentation (++) and arithmetic.

\begin{grammar}
<E5> ::=  <E6> <RelOp> <E6> | <E6>

<RelOp> ::= `>' | `<' | `=' | `!=' | `>=' | `<='

<E6> ::=  <E7> `++' <E6> | <E7>

<E7> ::=  <E8> `+' <E7> | <E8>

<E8> ::=  <E8> `-' <E9> | <E9>

<E9> ::= <E9> `*' <E10> | <E9> `/' <E10> | <E10>
\end{grammar}

The unary operators are arithmetic negation (unary minus), logical negation and bitwise negation of bitvectors.
\begin{grammar}
    <E10> ::= <UnOp> <E11> | <E11>

    <UnOp> ::= `-' | `!' | `~'
\end{grammar}

Array select, update and bitvector select operators are defined as follows.
\begin{grammar}
    <E11> ::= <E12> `[' <Expr> (`,' <Expr>)* `]'
          \alt <E12> `[' <Expr> (`,' <Expr>)* `->' <Expr> `]'
          \alt <E12> `[' <Expr> `:' <Expr> `]'
          \alt <E12>
\end{grammar}

Function invocation, record selection, and access to variables in instantiated modules is as follows.
\begin{grammar}
    <E12> ::=  <E13> `(' <ExprList> `)'
          \alt <E13> (`.' <Id>)+
\end{grammar}

And finally, we have the terminal symbols, identifiers, record field access, tuples and the if-then-else operator.
\begin{grammar}
    <E12> ::= \keywordbf{false} | \keywordbf{true} | <Number> | <String>
          \alt <Id> | <Id> `.' <Id>
          \alt `{' <Expr> (`,' <Expr>)* `}'
          \alt \keywordbf{if} `(' <Expr> `)' \keywordbf{then} <Expr> \keywordbf{else} <Expr>
\end{grammar}

Strings can only be used as arguments to the \texttt{print} command in the control block.

\section{Types}

\begin{grammar}
<Type> ::= <PrimitiveType>
       \alt <EnumType>
       \alt <TupleType> | <RecordType>
       \alt <ArrayType>
       \alt <SynonymType>
       \alt <ExternalType>
%%     }
\end{grammar}

Supported primitive types are Booleans, integers and bit-vectors. Bit-vector types are defined according the regular expression `bv[0-9]+' and the number following `bv' is the width of the bit-vector.

\begin{grammar}
    <PrimitiveType> ::= \keywordbf{boolean} | \keywordbf{integer} | <BitVectorType>
\end{grammar}

Enumerated types are defined using the \keywordbf{enum} keyword.
\begin{grammar}
    <EnumType> ::= \keywordbf{enum} `{' <IdList> `}'
\end{grammar}

Tuple types are declared using curly brace notation.
\begin{grammar}
    <TupleType> ::= `{' <Type>  (`,' <Type>)* `}'
\end{grammar}

Record types use the keyword \keywordbf{record}.
\begin{grammar}
    <Recordtype> ::= \keywordbf{record} `{' <IdTypeList> `}'
\end{grammar}

Array types are defined using square brackets. The list of types within square brackets defined the array's index type.
\begin{grammar}
    <ArrayType> ::= `[' <Type> (`,' <Type>)* `]' <Type>
\end{grammar}

Type synonyms are just identifiers, while external types refer to synonym types defined in a different module.
\begin{grammar}
    <SynonymType> ::= <Id>

    <ExternalType> ::= <Id> `.' <Id>
\end{grammar}

\section{Control Block}
\paratitle{The control block} consists of a list of commands. A command can have an optional result object, an optional argument object, an optional list of command parameters and finally an optional list of argument expressions.
\begin{grammar}
     <ControlBlock> ::= \keywordbf{control}~~ `{' <Cmd>* `}'

     <Cmd> ::= (<Id> `=' )? (<Id> `.')? <CmdName> \\
              (`[' <IdList> `]')? <ExprList>? `;'
\end{grammar}

The following is a list of currently accepted commands.

\begin{grammar}
    <CmdName> ::= `bmc' \alt
                  `bmc_LTL' \alt
                  `bmc_noLTL' \alt
                  `check' \alt
                  `clear\_context' \alt
                  `induction' \alt
                  `print' \alt
                  `print\_cex' \alt
                  `print\_module' \alt
                  `print\_results' \alt
                  `print\_smt2'
                  `synthesize\_invariant' \alt
                  `unroll' \alt
                  `verify'
\end{grammar}

\section{Miscellaneous Nonterminals}

\nonterminal{IdList}, \nonterminal{IdTypeList} and \nonterminal{ExprList} are non-empty, comma-separated list of identifiers, identifier/type tuples and expressions respectively.
\begin{grammar}
     <IdList> ::= <Id> \alt <Id> `,' <IdList>

     <IdTypeList> ::=  <Id> (`,' <Id>)* `:' <Type>
                  \alt <Id> (`,' <Id>)* `:' <Type> `,' <IdTypeList>

     <ExprList> ::=  <Expr>
                \alt <Expr> `,' <ExprList>
\end{grammar}


\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\author{Didrik Jonassen, Imre Kerr}
\title{Project 1B\\ IT3708 --- Subsymbolic methods in AI}
\date{\today}

\begin{document}

\maketitle

\section{Representation and Development}
We chose to represent the chromosome as a binary vector of length $4B$. Every four bits are interpreted as a binary number, meaning that the genome codes for $B$ integers between 0 and 15. These integers are then normalized so they all sum to 1, and the resulting fractions are the troop deployment for each battle.

\section{Strategy Entropy}
Strategy entropy is a measure of how ``spread out'' the troops are for a given strategy. Putting all troops in one battle gives minimum entropy, and spreading them evenly over all battles gives maximum entropy. This is interesting because it characterizes a strategy as a single number, letting you get the gist of the strategy without having to interpret the deployment numbers themselves.

\section{EA Parameters}
\begin{tabular}{|l|l|}
\hline
Parameter & value \\
\hline \hline
Population Size & 20 \\
Mutation Rate & $\frac{1}{40B}$ \\
Crossover Rate & 100\% \\
Selection Mechanism & Fitness Proportionate \\
Selection Protocol & Generational Mixing \\
Litter size & 20 \\
Generations & 400 \\
\hline
\end{tabular}

\section{Base Case Summary}
\begin{tabular}{|c|c|c|l|}
\hline
B & R_{f} & L_{f} & Notes \\
\hline \hline
5 & 0 & 0 & Switches between various strategies putting everything on two battles \\
5 & 0 & 1 & Puts everything on battle 1 \\
5 & 0 & 0.5 & Same as (5,0,0), but weighted towards the first of the two \\
5 & 1 & 0 & Spread out, weighted towards the earlier battles \\
5 & 1 & 1 &  All on battle 1 \\
5 & 1 & 0.5 & All on battle 1 \\
5 & 0.5 & 0 & Switches between various 2-battle strategies \\
5 & 0.5 & 1 & All on battle 1 \\
5 & 0.5 & 0.5 & All on battle 1 \\
20 & 0 & 0 & Converges toward fewer battles, step by step \\
20 & 0 & 1 & Same as B = 5, but slower\\
20 & 0 & 0.5 & Same as B = 5, but slower \\
20 & 1 & 0 & Switches between different strategies involving the 10 first battles \\
20 & 1 & 1 & Same as B = 5, but slower \\
20 & 1 & 0.5 & Same as B = 5, but slower \\
20 & 0.5 & 0 & Switches between different strategies with no clear pattern \\
20 & 0.5 & 1 & Same as B = 5, but slower \\
20 & 0.5 & 0.5 & Same as B = 5, but slower \\
\hline
\end{tabular}
You'll notice that the descriptions for most the B=20 runs were the same. They did however provide us with a clearer look at what was going on, so these runs were not wasted.

\section{Signature Cases}
For each of these cases we give:
\begin{itemize}
\item{an entropy plot showing the average entropy in the population}
\item{a fitness plot showing the best, worst and average (plus/minus std.dev.) fitness in the population}
\item{and a strategy plot, which is a visualization of the winning strategy in each generation. The horizontal axis is generations, and the vertical axis is normalized troop deployment. This plot makes it very easy to see what the dominant strategy looks like at any given point.}
\end{itemize}
\subsection{Case 1: $B=5, R_{f}=0, L_{f}=1$}
\centerline{\includegraphics[width=1.2\textwidth]{case1}}
This case quickly converges towards putting all troops on the first battle. This is not surprising, since having $L_{f}=1$ means that losing the first battle will make the morale zero for all the following battles. This is true for all cases with $L_{f}=1$.

\subsection{Case 2: $B=20, R_{f}=0, L_{f}=0$}
\centerline{\includegraphics[width=1.2\textwidth]{case2}}
\small{(There are two distinct regions that unfortunately both happened to be blue.)}\\
This case gradually converges towards a strategy involving putting everything on two battles, with the trend being one less battle every few generations. We think this can be explained as follows: In order to mutate an n-battle strategy into an (n-1)-battle strategy that beats the original, only one of the battles needs to have a lower weight, and all the other weights will rise as a result. Conversely, if an (n+1)-battle strategy is to beat an n-battle strategy, more than one of the battles needs to get an updated value. Thus it is easier to find winning strategies with lower numbers of battles, so it converges towards lower numbers, with the limit being 2.

\subsection{Case 3: $B=20, R_{f}=1, L_{f}=0$}
\centerline{\includegraphics[width=1.2\textwidth]{case3}}
Here we see a chaotic switching between strategies involving approximately the first half of the battles. Weighting towards earlier battles makes sense due to redeployment, but other than that this one is hard to explain. We made the strategy plot greyscale for this one in order to better see which battles were included in the strategy.

\section{Brief Discussion}
In the cases where there exists an optimal solution, we see that co-evolution finds this solution quite quickly. In the more complex cases, for any given strategy there is a strategy that can beat it, and this will eventually be found. The limiting factor in these cases is how easy it is to get to that strategy by random mutation. This has parallels in biology, where most change we observe is gradual, with quantum leaps being quite rare.

\end{document}


\chapter{Code Structure}\label{structure}

Roughly the code structure is displayed in Fig.\ref{graph}. For more accurate and detailed description, run Doxygen utility and refer the generated documentation.

\begin{figure}[H]
	\begin{center}
		\includegraphics[width=0.8\textwidth]{graph.pdf}
		\caption{\label{graph} Class dependency (crudely)}
	\end{center}
\end{figure}

Each of the the constituent elements are briefly described next.

\section{Code structure}
\subsection{Tensor}
MEANDG has a central datastructure called as `Tensor', which forms all the important arrays, matrices, multidimensional storage lists etc.
Refer `include/Tensor' for details. Tensor class is made of 4 sub-classes.
\begin{verbatim}
TensorO1<dType>, TensorO2<dType>, TensorO3<dType>, Matrix<dType>
\end{verbatim}
From these, $O(1), O(2), O(3)$ tensors can be created of arbitrary dimensions. The tensor objects interact with one another and
have several in-build methods such as $L_1, L_2, L_\infty$ norms etc. All the maths functions accept objects of Tensor library.

Following example code shows usage of tensor class:
\begin{verbatim}
TensorO1<double> A(5);		// creates a O(1) tensor of size 5 with
				// data-members of the type double
TensorO1<double> C(5);

for (int i=0; i<5; i++){
	// generate a random number between 0 and 100
	double valueA = getRandom(0.0,100.0);
	// generate another random number between 0 and 100
	double valueC = getRandom(0.0,100.0);

	// set value at ith index
	A.setValue(i, valueA);
	C.setValue(i, valueC);
};
// now A and C have random values

double dotAnswer = Math::dot(A,C);		// perform math product between two arrays
cout << dotAnswer << endl;			// print the answer

\end{verbatim}

For further details and the available functions, refer the code documentation.

\subsection{Point}
Point is a physical point in $(x,y,z)$ coordiante system. It has a unique id, and description of its location.

\subsection{Cell}
If the domain is indicated by $\Omega$, then the descritization of the domain ($\Omega_h$) is described as,
\begin{equation}
	\Omega_h = \bigcup\limits_{l = 1}^ n S_i
\end{equation}
where $S_i$ are the finite volume cells. These are non-overlapping pieces of the domain.
Each cell has the following important attributes (among others):
\begin{itemize}
	\item Vertices (of the type `Point')
	\item Faces (i.e. boundary of the cell)
	\item Degrees of Freedom (i.e. locations where unkowns are evaluated)
	\item Data (such as the conserved variables)
	\item Volume
	\item Mathematical constructs (Mass matrix, Stiffness matrix etc.)
	\item Mapping onto the standart cell (Jacobian etc.)
\end{itemize}

Thus, each of these parameters (among others) can be accessed using the accessor (get, set) functions of the class `Cell'.
For further details, refer Cell.h and Cell.cpp.

\subsection{Face}
A face is the boundary of a Cell. The face has following important attributes:
\begin{itemize}
	\item Geometrical information (area, normal, vertices etc.)
	\item Neighbour and Owner cells
	\item Data (numerical flux and variables)
	\item Mapping (Jacobian etc.)
\end{itemize}

\subsection{GeometryIO}
This module reads the input file in the OpenFOAM format and fills the data arrays. Refer:
\begin{verbatim}
GeometryIO::fillDataArrays(args)
\end{verbatim}

\subsection{Functional Space}
This module is responsible for everything related to $L^2, H^1$ functional spaces. It contains nodal, modal basis functions and derivatives.
It also computes various matrices used in DG formulation.

\subsection{Math functions}
These are various mathematical functions.

\subsection{Gasdynamics, Riemann solvers etc.}
Depending on the system of equations which one wants to solve, include the physics-specific functions and files. For example, for
Euler's equations of Gasdynamics, we have Gasdyanmics.cpp module and corresponding Riemann solvers.
Apart from these, there are test functions, display functions etc. Refer the code files in `include/' and `src/' folders.

\subsection{DG}
This is the core (central) module of the code. It performs following operations:
\begin{itemize}
	\item Memory management
	\item Cells, faces creation
	\item Calling appropriate functions for computation of cell matrices
	\item Time integration
	\item PDE solving
\end{itemize}

Currently it is configured to solve the hyperbolic system of PDEs of the type:
\begin{equation}
	\frac{\partial {Q}}{\partial{t}} + \nabla .  {\bf F}(Q) = 0
\end{equation}


\subsection{Max Pooling Layer}

After the convolutional layer a pooling layer is placed. This reduces the dimensionality of the data and introduces local non-linearity to the network, enabling it to achieve better function approximation. In our case the layer performs a max operation among a $2 \times 2$ image patch. This means that a 2-by-2 image patch is mapped to 1 output pixel and it's value is equivalent to the maximum value of the input image patch.
Because of the processing of the convolutional layer (see Figure~\ref{fig:hw-conv-operation}) a whole input image input row must be buffered before any processing can happen. Because the pooling layer requires a $2$-by-$2$ input window it is limited by the output of the convolutional layer. To increase throughput the convolutional layer could be parallelized by doing two convolutions at once at the cost of increased area size. Alternatively the pooling operation can be serialized by only operating on half the output channels of the convolutional layer at a time.

\begin{figure}[h]
	\centering
	\includegraphics[width=0.6\textwidth]{img/pool.pdf}
	\caption[Pooling Operation]{Pooling Operation. The pool window (red-dashed-square) applied to current image patch (blue) and shifted over the input data. The first input row needs to be buffered (orange) before processing can happen. Depth channels omitted for illustration purposes.}
	\label{fig:hw-conv-operation}
\end{figure}

% TODO Finish table or dont use it at all
%\begin{table}[hb]
%	\centering
%	\begin{tabular}{lcc}
%		\toprule
%		Parameter & VHDL Datatype & Type \\
%		\midrule
%		 BIT\_WIDTH\_IN & integer & Generic	 	\\
%		 BIT\_WIDTH\_OUT & integer & Generic 	\\
%		 INPUT\_CHANNELS & integer & Generic 	\\
% 	 	 OUTPUT\_CHANNELS & integer & Generic 	\\
% 	 	 \midrule
% 	 	 valid\_i & \stdlogic & input \\
% 	 	 data\_i & \stdlogic[INPUT\_CHANNELS][DATA\_WIDTH] & input \\
% 	 	 \midrule
% 	 	 valid\_o & \stdlogic & output \\
% 	 	 data\_o & \stdlogic[INPUT\_CHANNELS][DATA\_WIDTH] & output \\
%   		\bottomrule
%	\end{tabular}
%	\caption{}
%	\label{tab:hw-pool-layer-parameter}
%\end{table}


\section{Overview}
From earlier calibration versions of data from the autocorrelators
of Odin-SMR we know that calibrated spectra from both high and
low altitudes contain spectral features not caused by the atmospheric
species.
This short report contains a likely explanation
of how these spectral features are induced
and how they affect the spectra.

\clearpage
\newpage

\section{Spectral features in spectra}
\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{odinspectrumpattern.png}\\
\caption{Wave induced pattern in calibrated spectra. The red line represents
a perturbed brightness temperature spectrum of the
hot load (a cosinus wave with eight cycles is added)
The blue line represents a perturbed brightness temperature
spectrum of the cold sky (a cosinus wave with four cycles is added).
The thin red lines represent perfectly calibrated spectra.
The green lines show what features the cosinus waves of the
references induce on calibrated spectra if they are not taken into account.
}
\label{fig:study2ac2a}
\end{figure}

From earlier calibration versions of data from the autocorrelators
of Odin-SMR we know that calibrated spectra from both high and
low altitudes contain spectral features not caused by the atmospheric
species.
The spectral features, which are different at low and and high altitudes,
are instead caused by the instrument itself and not taken into account
in the calibration process.

The calibration process (level1a to level1b) is based on that we have
measurements of the clod sky (\(C_{s}(f)\) at 2.7 K), hot load (\(C_{L}(f)\)
at around 290 K), and the target atmosphere (\(C_{A}(f)\)
at unkown temperature \(T_{A}\)).
The calibration process can be understand as a linear interpolation
of \(C_{A}(f)\)  using \(C_{s}(f)\) and \(C_{L}(f)\) and their temperatures
as references.

The calibration process assumes that both the cold sky and hot load signal
are clean. Figure~\ref{fig:study2ac2a} shows an example of what would happen with
calibrated spectra if these signals are not clean
(but the target signal is clean).
In the example the blue line represents a perturbed brightness temperature
spectrum of the cold sky (a cosinus wave with four cycles is added).
The red line represents a perturbed brightness temperature spectrum of the
hot load (a cosinus wave with eight cycles is added).
The thin red lines can be interpreted as perfectly calibrated spectra.

The green lines show what features the cosinus waves of the
references induce on calibrated spectra if they are not taken into account:

At low brightness temperatures this pattern is caused by the
the wave on the cold sky signal (and 180 degree phase shifted
w.r.t. wave on the cold sky signal).

At high brightness temperatures this pattern is caused by the
the wave on the hot load signal (and 180 degree phase shifted
w.r.t. wave on the hot load signal).

At intermediate brightness temperatures the pattern is a linear
combination of the mentioned pattern,
i.e. (using the equations in the figure)
\begin{equation}
\Delta T=c \cdot cos\left(\frac{f2\pi}{d}+\pi\right) \cdot (1-w(f))
+a \cdot cos \left( \frac{f2\pi}{b}+\pi \right) \cdot w(f)
\end{equation}
where
\begin{equation}
w(f)=\frac{C_{A}(f)-C_{s}(f)}{C_{L}(f)-C_{S}(f)}\approx\frac{T_{A}(f)}{T_{L}(f)}
\end{equation}

\section{Odin data}
\subsection{AC2}
\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac2spechigh.png}\\
\caption{High tangent altitude median spectrum from AC2 (strat 1).}
\label{fig:study2spec1}
\end{figure}

\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac2speclow.png}\\
\caption{Low tangent altitude median spectrum from AC2 (strat 1).}
\label{fig:study2spec2}
\end{figure}

\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac2spec1015.png}\\
\caption{Intermediate tangent altitude median spectrum from AC2 (strat 1).}
\label{fig:study2spec3}
\end{figure}

\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac2spec1520.png}\\
\caption{Intermediate tangent altitude median spectrum from AC2 (strat 1).}
\label{fig:study2spec4}
\end{figure}

\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac2spec3035.png}\\
\caption{Intermediate tangent altitude median spectrum from AC2 (strat 1).}
\label{fig:study2spec5}
\end{figure}

\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac2spec4045.png}\\
\caption{Intermediate tangent altitude median spectrum from AC2 (strat 1).}
\label{fig:study2spec6}
\end{figure}

\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac2spec5560.png}\\
\caption{Intermediate tangent altitude median spectrum from AC2 (strat 1).}
\label{fig:study2spec7}
\end{figure}
\clearpage
\newpage
\subsection{AC1}
\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac1spechigh.png}\\
\caption{High tangent altitude median spectrum from AC1 (strat 2).}
\label{fig:study2spec8}
\end{figure}

\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac1speclow.png}\\
\caption{Low tangent altitude median spectrum from AC1 (strat 2).}
\label{fig:study2spec9}
\end{figure}

\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac1spec4045.png}\\
\caption{Intermediate tangent altitude median spectrum from AC1 (strat 2).}
\label{fig:spec1}
\end{figure}

\begin{figure}[!t]
\centering
\includegraphics[scale=0.7]{ac1spec5560.png}\\
\caption{Intermediate tangent altitude median spectrum from AC1 (strat 2).}
\label{fig:spec1}
\end{figure}


\documentclass{beamer}

\input{../../shared_slides.tex}

\title{Projected Gradient Descent}

\begin{document}
\maketitle
\frame{\tableofcontents}

\section{Introduction}%

\begin{frame}
  \frametitle{Constrained Optimization}

  \begin{minipage}{0.5\textwidth}
    \begin{block}{Constrained optimization problem}
      \begin{equation}
        \begin{aligned}
          \text{minimize } & f(x)\\
          \text{subject to } & x\in C
        \end{aligned}
      \end{equation}
      \textcolor{blue}{How to solve them}
      \begin{itemize}
        \item Project onto $C$
        \item transform to \textit{unconstrained problem}
      \end{itemize}
    \end{block}
  \end{minipage}
  \begin{minipage}{0.45\textwidth}
    \begin{figure}[ht]
      \centering
      \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{constrained_3d}
      % \caption{\label{fig:label} }
    \end{figure}
  \end{minipage}
\end{frame}

\begin{frame}
  \frametitle{Constrained Optimization}

  \begin{minipage}{0.5\textwidth}
    \begin{block}{Constrained optimization problem}
      \begin{equation}
        \begin{aligned}
          \text{minimize } & f(x)\\
          \text{subject to } & x\in C
        \end{aligned}
      \end{equation}
      \end{block}
      \textcolor{blue}{We will focus on:}
      \begin{itemize}
        \item \textbf{Projected Gradient Descent}
      \end{itemize}
  \end{minipage}
  \begin{minipage}{0.45\textwidth}
    \begin{figure}[ht]
      \centering
      \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{constrained_3d}
      % \caption{\label{fig:label} }
    \end{figure}
  \end{minipage}
\end{frame}

\section{Projection}%
\label{sec:}

\begin{frame}
  \frametitle{Projected Gradient Descent}

  \textcolor{blue}{Idea:} After every step project back onto the set: $\Pi_C(x) :=\argmin_{y\in C} \Vert y-x \Vert$.

    \begin{figure}[ht]
      \centering
      \includegraphics[width=\textwidth,height=0.7\textheight,keepaspectratio]{test}
      % \caption{\label{fig:label} }
    \end{figure}

\end{frame}

\begin{frame}
  \frametitle{Projected subgradient method}
  \begin{equation}
    \text{(constrained setting)} \quad \min_{x\in C}\, f(x)
  \end{equation}
  \begin{algorithm}[H]
    \caption{Projected subgradient method}\label{label:}
    \begin{algorithmic}[1]
      \For{$k=0, 1, \dots$}
      \State{Pick $g_k \in \partial f(x_k)$}
      \State{$y_{k+1} =  x_k- \alpha g_k $}
      \State{$x_{k+1} = \Pi_C(y_{k+1})$}
      \EndFor
    \end{algorithmic}
  \end{algorithm}
\end{frame}

\begin{frame}
  \frametitle{Properties of the Projection}
  \begin{block}{Fact}
    Let $C\subseteq \R^d$ be closed and convex, $x\in C$ and $y \in \R^d$.Then
    \begin{itemize}
      \item $\langle x- \Pi_C(y), y - \Pi_C(y)  \rangle \le 0$
      \item $\Vert x - \Pi_C(y) \Vert^2 + \Vert y - \Pi_c(y) \Vert^2 \le \Vert y-x \Vert^2$
    \end{itemize}
  \end{block}
  \begin{figure}[ht]
    \centering
    \includegraphics[height=0.5\textheight,keepaspectratio]{projection_property}
    % \caption{\label{fig:label} }
  \end{figure}

\end{frame}

\begin{frame}
  \frametitle{Properties of the Projection}
  \begin{block}{Fact}
    Let $C\subseteq \R^d$ be closed and convex, $x\in C$ and $y \in \R^d$.Then
    \begin{itemize}
      \item $\langle x- \Pi_C(y), y - \Pi_C(y)  \rangle \le 0$
      \item $\Vert x - \Pi_C(y) \Vert^2 + \Vert y - \Pi_c(y) \Vert^2 \le \Vert y-x \Vert^2$
    \end{itemize}
  \end{block}
  \begin{proof}
    Since $\Pi_C(x)$ is the minimizer of a differentiable convex function $d_x(y) =\frac12 \Vert y-x \Vert^2$ over $C$, by the \textbf{first-order optimality condition}
    \begin{align}
      0 &\le \langle \nabla d_x(\Pi_C(x)), y - \Pi_C(x) \rangle \\
        &= \langle \Pi_C(x) - x, y - \Pi_C(x) \rangle
    \end{align}
  \end{proof}
\end{frame}

\begin{frame}
  \frametitle{Results for projected GD}
  For \textbf{closed}, \textbf{convex} set $C\subset \R^d$ \textcolor{blue}{same} number of gradient steps.
  \begin{itemize}
    \item Lipschitz convex function over $C$: $\mathcal{O}(\epsilon^{-2})$ steps
    \item Smooth convex function over $C$: $\mathcal{O}(\epsilon^{-1})$ steps
    \item Smooth and strongly convex over $C$: $\mathcal{O}(\log(\epsilon^{-1}))$
  \end{itemize}

  But:
  \begin{itemize}
    \item Each step requires a projection onto $C$
    \item May or may not be easy to compute
  \end{itemize}

\end{frame}

\begin{frame}
  \frametitle{The projection step: $\Pi_C(x) := \argmin_{y\in C} \Vert y-x \Vert$}
  Computing $\Pi_C(x)$ is an optimization problem itself.

  Efficient in relevant cases:
  \begin{itemize}
    \item Box constraints: $C= [a_1, b_1] \times \dots \times [a_d, b_d]$
    \item Affine subspace (requires solution of system of linear equations)
          \begin{figure}[ht]
            \centering
            \includegraphics[scale=.12]{projection_onto_affine_space}
          \end{figure}
    \item Projection onto ball with center $c$
          \begin{figure}[ht]
            \centering
            \includegraphics[scale=.2]{projection_onto_ball}
          \end{figure}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Convergence analysis}
  \begin{proof}
    We can deduce the exact same inequality as before
    \begin{equation}
      \begin{aligned}
        \Vert x_{k+1} - x^* \Vert^2 &= \Vert \Pi_C(x_k - \alpha g_k) - \Pi_C(x^*) \Vert^2 \\
        &\le \Vert x_k - \alpha g_k - x^* \Vert^2 \\
        &= \Vert x_k-x^* \Vert^2 + 2 \alpha \langle g_k, x^*-x_k \rangle + \alpha^2 \Vert g_k \Vert^2\\
        &\le \Vert x_k-x^* \Vert^2 + 2 \alpha (f^* - f(x_k))+ \alpha^2 \Vert g_k \Vert^2.
      \end{aligned}
    \end{equation}
    Continue the proof as in the unconstrained setting.
  \end{proof}
\end{frame}

\section{Proximal Gradient}%
\label{sec:}

\begin{frame}
  \frametitle{Composite minimization problem}

  Consider objective function composed as
  \begin{equation}
    f(x) = g(x) + h(x)
  \end{equation}
  where
  \begin{itemize}
    \item $g$ is \textcolor{blue}{nice}
    \item $h$ is \textcolor{blue}{simple}
  \end{itemize}
  typically we mean nice means smooth. Relevant if $h$ is not differentiable.
  Most notably: Lasso

\end{frame}

\begin{frame}
  \frametitle{Idea}
  Classical gradient step for $g$:
  \begin{equation}
    x_{k+1} = \argmin_{x} g(x_k) + \langle \nabla g(x_k), x-x_k \rangle + \frac{1}{2 \alpha} \Vert x-x_k \Vert^2
  \end{equation}
  Now, for $f= g+h$ we keep this for $g$ and add $h$ \textcolor{blue}{unmodified}:
  \begin{align}
    x_{k+1} &= \argmin_{x} g(x_k) + \langle \nabla g(x_k), x-x_k \rangle + \frac{1}{2 \alpha} \Vert x-x_k \Vert^2 \textcolor{red}{+ h(x)} \\
    &= \argmin_x \frac{1}{2 \alpha} \Vert x - (x_k - \alpha \nabla g(x_k)) \Vert^2 + h(x)
  \end{align}
\end{frame}

\begin{frame}
  \frametitle{The proximal gradient algorithm}

  An iteration is defined as
  \begin{block}{}
  \begin{equation}
    x_{k+1} = \prox{\alpha h}{x_k - \alpha \nabla g(x_k)}
  \end{equation}
  \end{block}
  where the \textcolor{blue}{proximal mapping} for a function $h$ and parameter $\alpha$ is defined as
  \begin{equation}
    \prox{\alpha h}{x} = \argmin_{y \in \R^d} \left\{ h(y) + \frac{1}{2 \alpha} \Vert y-x \Vert^2\right\}.
  \end{equation}

\end{frame}

\begin{frame}
  \frametitle{A generalization of (projected) GD}

  \begin{itemize}
    \item $h \equiv 0$ recovers \textcolor{blue}{gradient descent}.
    \item $h = \chi_C$ recovers \textcolor{blue}{projected gradient descent}
          We call $\chi_C$ the \textbf{indicator function} of $C$
          \begin{align}
            \chi_C&: \R^d \to \R \cup +\infty \\
              & x \mapsto \begin{cases}
                0 & \text{if $x \in C$} \\
                +\infty & \text{otherwise.}
              \end{cases}
          \end{align}
          Proximal mapping becomes
          \begin{equation}
            \prox{\alpha h}{x} = \argmin_{y \in \R^d} \left\{ \chi_C(y) + \frac{1}{2 \alpha} \Vert y-x \Vert^2\right\} = \argmin_{y \in C} \{ \Vert y-x \Vert^2\}.
          \end{equation}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Convergence}

  Same complexity as GD or projected GD,

  \textcolor{blue}{if we can compute the proximal mapping!}

\end{frame}

\end{document}


%%% exercise 03 %%%
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath, amssymb, amsfonts, enumitem, fancyvrb, fancyhdr, tikz}
% get rid of paragraph indent
\setlength{\parindent}{0 pt}
% allow section.equation numbering
\numberwithin{equation}{section}
% allows you to copy-paste code segments. requires pygments to be installed
% natively, i.e. not just in a Python venv! for example, on WSL Ubuntu you
% need to sudo apt-get install python3-pygments (unfortunately, the version
% will be a bit dated) and cannot rely on your venv Pygments version.
\usepackage{minted}
% makes clickable links to sections
\usepackage{hyperref}
% make the link colors blue, as well as cite colors. urls are magenta
\hypersetup{
    colorlinks, linkcolor = blue, citecolor = blue, urlcolor = magenta
}
% fancy pagestyle so we can use fancyhdr for fancy headers/footers
\pagestyle{fancy}
% add logo in right of header. note that you will have to adjust logo path!
\fancyhead[R]{\includegraphics[scale = 0.15]{../bac_logo1.png}}
% don't show anything in the left and center header
\fancyhead[L, C]{}
% give enough space for logo by reducing top margin height, head separator,
% increasing headerheight. see Figure 1 in the fancyhdr documentation. if
% \topmargin + \headheight + \headsep = 0, original text margins unchanged.
\setlength{\topmargin}{-60 pt}
\setlength{\headheight}{50 pt}
\setlength{\headsep}{10 pt}
% remove decorative line in the fancy header
\renewcommand{\headrulewidth}{0 pt}

% title, author + thanks, date
\title{Exercise 3}
\author{Derek Huang\thanks{NYU Stern 2021, BAC Advanced Team.}}
\date{March 10, 2021\thanks{Original version released on March 4, 2021.}}

% shortcut links. the % characters strip extra spacing.
\newcommand{\pytest}{%
    \href{https://docs.pytest.org/en/stable/}{pytest}%
}
\newcommand{\lsqr}{%
    \href{%
        https://docs.scipy.org/doc/scipy/reference/generated/%
        scipy.sparse.linalg.lsqr.html%
    }{\texttt{scipy.sparse.linalg.lsqr}}%
}
\newcommand{\skridge}{%
    \href{%
        https://scikit-learn.org/stable/modules/generated/%
        sklearn.linear_model.Ridge.html%
    }{\texttt{sklearn.linear\_model.Ridge}}%
}

\begin{document}

\maketitle
% need to include this after making title to undo the automatic
% \thispagestyle{plain} command that is issued.
\thispagestyle{fancy}

\section{Introduction}

The goal of this exercise is to implement the ridge regression model,
solving the $ \ell^2 $-regularized least-squares objective using both
matrix multiplication and \lsqr, one of the solvers used by the scikit-learn
\skridge{} ridge regression estimator.

\section{Instructions}

\subsection{General}

The \texttt{exercise\_03.py} file contains a skeleton for the
\texttt{RidgeRegression} class, two unit tests, and a \pytest{} test fixture.
Your job is to implement the \texttt{fit}, \texttt{predict}, and
\texttt{score} methods of the \texttt{RidgeRegression} class. Each one of the
three methods contains the comment block

\begin{figure}[h!]
	\centering
	\begin{BVerbatim}
###########################
### your code goes here ###
###########################
	\end{BVerbatim}
	% remove some extra spacing
	\vspace{-5 pt}
\end{figure}

Your code \textbf{must} be written in the areas marked by these blocks. Do
\textbf{not} change any of pre-written code. The exercise is complete
$ \Leftrightarrow $ \texttt{pytest /path/to/exercise\_03.py} executes with
zero test failures. Note that attributes ending with \texttt{\_}, ex.
\texttt{coef\_}, are created \textbf{during} the fitting process.

\subsection{Using \lsqr}

The \lsqr{} solver used by \skridge{} solves
\begin{equation*}
    \min_\mathbf{x}\Vert\mathbf{Ax} - \mathbf{b}\Vert_2^2 +
    d^2\Vert\mathbf{x}\Vert_2^2
\end{equation*}

Here $ \mathbf{A} \in \mathbb{R}^{N \times d} $ is the coefficient matrix,
$ \mathbf{b} \in \mathbb{R}^N $ is the coefficient vector, $ \mathbf{x} \in
\mathbb{R}^d $ is the optimization variable, and $ d \in [0, \infty) $
corresponds to the \texttt{damp} parameter passed to \lsqr.

\medskip

You should use \textbf{only} the \texttt{A}, \texttt{b}, and \texttt{damp}
parameters. See the documentation for usage examples.

\subsection{Tips}

\begin{enumerate}
    \item
    Carefully read the \texttt{RidgeRegression} method docstrings and review
    slides 10 and 12.

    \item
    The \texttt{fit} method should contain a conditional statement to handle
    when \texttt{self.solver == "matmul"} and when
    \texttt{self.solver == "lsqr"}. The unit tests will cover both cases.

    \item
    Use NumPy functions whenever possible for efficiency, brevity of code, and
    to develop good habits.

    \item
    The \textbf{square root} of \texttt{alpha} should be passed to the \lsqr{}
    \texttt{damp} parameter.
\end{enumerate}

\end{document}


\subsection{\smtsolvers}

\begin{frame}[fragile]
  \frametitle{\smtsolvers}

  An \smtsolver is a tool that can parse and solve an SMT-LIB
  benchmark.
  \vfill
  \pause
  There are many such tools available online. In this course
  we will use \yices (developed at SRI, Stanford, closed source), \zthree
  (developed at MSR, Redmond, closed source) and \opensmt (developed here, open source). \pause
  Other available tools are \mathsat, \cvcfour, \boolector, \verit, \stp.
  \vfill
  \pause
  {\scriptsize
  \begin{verbatim}
    roberto@moriarty:examples$ smtlib2yices < test1.smt2
    success
    success
    success
    success
    success
    success
    success
    success
    sat
  \end{verbatim}
  }

\end{frame}

\begin{frame}[fragile]
  \frametitle{SMT-LIB script}

  The SMT-LIB language allows specification of {\bf scripts}. A script
  is a benchmark that may contain many {\tt check-sat} commands. Also,
  it may include {\tt push} and {\tt pop} commands which
  can be used to control the assertion stack

  {\scriptsize
  \begin{verbatim}
    (set-option :print-success false)
    (set-logic QF_LIA)
    (declare-fun x ( ) Int)
    (declare-fun y ( ) Int)
    (assert (<= (+ x y) 0))
    (assert (= x 0))
    (assert (or (= x 1) (>= y 0)))
    (check-sat)
    (push 1)
    (assert (not (= y 0)))
    (check-sat)
    (pop 1)
    (check-sat)
    (exit)
  \end{verbatim}
  }

\end{frame}

\begin{frame}
  \frametitle{Exercizes}

  \begin{enumerate}
    \item Translate the following \Lia formula SMT-LIB, and evaluate it with an \smtsolver
    $$(x - y \leq 0) \wedge (y - z \leq 0) \wedge ((z - x \leq -1) \vee (z - x \leq -2))$$
    \vfill

    \item Translate the following \Lra formula SMT-LIB, and evaluate it with an \smtsolver
    $$(b \vee (x + y \leq 0)) \wedge (\neg b \vee (x + z \leq 10))$$
    \vfill

    \item For the satisfiable \formulae above print out a model
    \vfill

    \item For the satisfiable \formulae above, add constraints such that they become unsatisfiable

  \end{enumerate}

\end{frame}


\hypertarget{meshtools}{%
\section{Meshtools}\label{meshtools}}

The Meshtools package contains a number of functions and classes to
assist with creating and manipulating meshes.

\hypertarget{areamesh}{%
\section{AreaMesh}\label{areamesh}}

This function creates a mesh composed of triangles from a parametric
function. To use it:

\begin{lstlisting}
var m = AreaMesh(function, range1, range2, closed=boolean)
\end{lstlisting}

where

\begin{itemize}

\item
  \texttt{function} is a parametric function that has one parameter. It
  should return a list of coordinates or a column matrix corresponding
  to this parameter.
\item
  \texttt{range1} is the Range to use for the first parameter of the
  parametric function.
\item
  \texttt{range2} is the Range to use for the second parameter of the
  parametric function.
\item
  \texttt{closed} is an optional parameter indicating whether to create
  a closed loop or not. You can supply a list where each element
  indicates whether the relevant parameter is closed or not.
\end{itemize}

To use \texttt{AreaMesh}, import the \texttt{meshtools} module:

\begin{lstlisting}
import meshtools
\end{lstlisting}

Create a square:

\begin{lstlisting}
var m = AreaMesh(fn (u,v) [u, v, 0], 0..1:0.1, 0..1:0.1)
\end{lstlisting}

Create a tube:

\begin{lstlisting}
var m = AreaMesh(fn (u, v) [v, cos(u), sin(u)], -Pi...Pi:Pi/4,
                 -1..1:0.1, closed=[true, false])
\end{lstlisting}

Create a torus:

\begin{lstlisting}
var c=0.5, a=0.2
var m = AreaMesh(fn (u, v) [(c + a*cos(v))*cos(u),
                            (c + a*cos(v))*sin(u),
                            a*sin(v)], 0...2*Pi:Pi/16, 0...2*Pi:Pi/8, closed=true)
\end{lstlisting}

\hypertarget{linemesh}{%
\section{LineMesh}\label{linemesh}}

This function creates a mesh composed of line elements from a parametric
function. To use it:

\begin{lstlisting}
var m = LineMesh(function, range, closed=boolean)
\end{lstlisting}

where

\begin{itemize}

\item
  \texttt{function} is a parametric function that has one parameter. It
  should return a list of coordinates or a column matrix corresponding
  to this parameter.
\item
  \texttt{range} is the Range to use for the parametric function.
\item
  \texttt{closed} is an optional parameter indicating whether to create
  a closed loop or not.
\end{itemize}

To use \texttt{LineMesh}, import the \texttt{meshtools} module:

\begin{lstlisting}
import meshtools
\end{lstlisting}

Create a circle:

\begin{lstlisting}
import constants
var m = LineMesh(fn (t) [sin(t), cos(t), 0], 0...2*Pi:2*Pi/50, closed=true)
\end{lstlisting}

\hypertarget{polyhedronmesh}{%
\section{PolyhedronMesh}\label{polyhedronmesh}}

This function creates a mesh from a polyhedron specification.

\hypertarget{equiangulate}{%
\section{Equiangulate}\label{equiangulate}}

Attempts to equiangulate a mesh.

\hypertarget{meshbuilder}{%
\section{MeshBuilder}\label{meshbuilder}}

The \texttt{MeshBuilder} class simplifies user creation of meshes. To
use this class, begin by creating a \texttt{MeshBuilder} object:

\begin{lstlisting}
var build = MeshBuilder()
\end{lstlisting}

You can then add vertices, edges, etc. one by one using
\texttt{addvertex}, \texttt{addedge} and \texttt{addtriangle}. Each of
these returns an element id:

\begin{lstlisting}
var id1=build.addvertex(Matrix([0,0,0]))
var id2=build.addvertex(Matrix([1,1,1]))
build.addedge([id1, id2])
\end{lstlisting}

Once the mesh is ready, call the \texttt{build} method to construct the
\texttt{Mesh}:

\begin{lstlisting}
var m = build.build()
\end{lstlisting}

\hypertarget{meshrefiner}{%
\section{MeshRefiner}\label{meshrefiner}}

The \texttt{MeshRefiner} class is used to refine meshes, and to correct
associated data structures that depend on the mesh.


\chapter{Conclusion}\label{c5}

A methodology for predicting multiple wind turbine faults in advance by implementing classification algorithms on wind turbine SCADA signals was proposed. 30 months' worth of SCADA data for a wind farm with 25 turbines was processed and labelled using corresponding downtime data containing turbine categories that describe the condition of the turbine. Since the multiple faults are treated as separate labels, multiclass-multilabel classification algorithms, namely DT, RF and kNN, offered in scikit-learn, the machine learning library for Python, were analysed. In order to predict faults in advance, three types of classes were used: `normal' to indicate normal behaviour, `faulty' to indicate a fault, and `X hours before fault' (where X $=$ 6, 12, \dots, 48) to detect faults in advance at varying time scales. This will allow predictive maintenance to be done appropriate to the time scale to prevent catastrophic failure to the turbine. Each of these classifiers have hyperparameters which were tuned for optimal performance on the data using five-fold cross-validation. The effects of balancing training data were also investigated.

The use of multilabel-multiclass algorithms allowed for the classification of each turbine to be done using a single estimator which produces the results of all labels simultaneously and has a shorter training time. Of the three classifiers, RF was found to have the best performance overall. A detailed analysis was done on the results for two labels, namely `electrical system', which had the worst performance, and `gearbox' which had relatively better performance. The performance of the `X hours before fault' classes was found to be relatively poor compared to the other two classes. The performance of these classes was slightly better using balanced training data. This has drawbacks, including using separate estimators for each label, and increased training time and use of resources due to the use of larger training data. After evaluating feature importance, it was concluded that the poor performance of these classes could be attributed to the features used or errors in the data. Further work should be done using additional SCADA fields relevant to each label to verify this. After additional improvements to the model and conducting a cost function analysis, the method could be tested in industry.


\subsection{Bayesian VAR}


\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}

\newtheorem{defi}{Defintion}

\author{moi}
\begin{document}
\section{Introduction}
We shall concentrate our discussion on fixed points and its implication with regard to algebra. We assume the reader confident with basic ring and module theory. In particular, unless stated otherwise we assume each ring $R$ to be commutative and unital (i.e. with one $1_R \in R$.
\subsection{Polynomial example}
Let $R$ be a ring. Firstly, let us discuss the specialisation of fixed points in the polynomial case.
\begin{defi}[Polynomial case]
Fix $f \in R[X]\backslash R$. An element $r_f \in R$ is a fixed point wrt. to $f$, if $f \in \ker \phi_{r_f}$ or equivalently if $r_f \in \ker \rho \circ \psi (f)$, where
$$\begin{array}{rrclcrcl}
ev_r : & R[X] & \longrightarrow & R,&& \sum_i f_i X^i & \longmapsto & \sum_i f_i r^i\\
\rho : &R& \longrightarrow &\mathrm{CRng}(R[X],R),&& r &\longmapsto& ev_r\\% = \left[\sum_i f_i X^i \longmapsto \sum_i f_i r^i\right],\\
\psi :& R[X] &\longrightarrow& R[X],&& f &\longmapsto &f - x,\ \mathrm{and}\\
\phi_r := ev_r \circ \psi :& R[X]& \longrightarrow& R&,& f &\longmapsto& ev_r (f - x).\\
\end{array}$$
\end{defi}
Firstly, we note that $\psi$ is an $R$ module automorphism and $ev_r$ is a ring homomorphism (hence, the notation of the class of ring homs $\mathrm{CRng}(R[X],R)$). The equivalence is obvious. However, the map $\phi_r$ is not a module

\end{document}