This section first describes the greedy algorithms used to build filters setting for querying large data graphs in order to retrieve relevant UI elements that are of interest to the users.  Following this, we describe an optimization-based approach based on Mixed Integer Linear Programming (MILP) to benchmark the performance of the proposed greedy algorithms on moderate-sized problems.

\subsection{Greedy search}

% Should discuss greedy algorithm generically as having a metric and at each step
% a choice of k restrictions, which are each scored against the metric with the
% highest score chosen at each step.  Then each individual filter only has to
% specify what the choices are and how the choice restricts the set of emails
% selected.  What is a good succinct notation for this?

As is discussed previously, three types of sub-filters are used to select a subset of relevant information in a data visualization interface: keywords sub-filter, time sub-filter, and space (location) sub-filter.  A global filter that is generated by \emph{conjoining} these three sub-filters, is used to select the subset $RS$ of relevant UI elements. While considering a greedy top-down approach for building these filter settings, we describe in the following how we propose to build each of these sub-filters individually, and then how we propose to combine them in order to select a global filter.

\subsubsection{Keywords greedy algorithm}
The idea behind the keywords-based greedy top-down algorithm is the following: given a set of elements and an evaluation measure, the algorithm aims to select a set of keywords to form a negation query in order to exclude a subset of elements containing these keywords for the purpose of maximizing the evaluation measure.

Formally, given a keyword query representation $Q_k$, the algorithm aims to select an
optimal subset of $k$ terms $T_{k}^{*}\subset E$ (where $|T_{k}^{*}|=k$ and $E$ is the initial set of elements) to build a negation keyword query $Q_k$, i.e. $Q_k=\{\neg t_{1}^{*},\dots \neg t_{k}^{*}\}$, in order to optimize a given evaluation measure, e.g. expected precision, expected recall, expected F1-score. This is achieved by
building $T_{k}^{*}$ in a greedy manner by choosing the next optimal
term $t_{k}^{*}$ given the previous set of optimal term selections
$T_{k-1}^{*}=\{t_{1}^{*},\ldots,t_{k-1}^{*}\}$ (assuming $T_{0}^{*}=\emptyset$)
using the following selection criterion:
\begin{equation}
t_{k}^{*}=\argmax_{t_{k}\notin T_{k-1}^{*}}\hspace{-0.3mm}[EF1(E^{*} \textrm{ that satisfies } Q_k=\{\neg t_{1}^{*},\dots \neg t_{k}^{*}\})]
\end{equation}
assuming we use expected F1-score to assess  $E^{*}$, which is a subset of the initial element set $E$ that satisfy the negation keyword query $Q_k$. In order to reduce the keyword search space, we propose to use the top 100 terms ranked using mutual information. Note that the best indexing strategy to use here is obviously the inverted index data structure \cite{Zobel2006}.

\subsubsection{Time greedy algorithm}
The idea behind the time-based greedy top-down algorithm is as simple as finding a query time window range $Q_t=[t_{start},t_{end}]$, which allows to select a subset of elements $E^{*}\subseteq E$ falling in that time window, with $E^{*}$ having a higher evaluation metric value.

Formally, given an evaluation measure (say EF1) and a list of elements $E=\{j_{t_1}\leq \dots \leq j_{t_n}\}$, where "$\leq$" specifies the timestamp order, we propose the following two time greedy algorithms:

\subfour{Naive greedy algorithm:} First, at each iteration of this algorithm, an early ranked element $j_{t_i}$ is removed, and then, the remaining set is assessed using expected F1-Score. If the remaining set has a lower expected F1-score value than the set of the previous iteration, the algorithm assigns $t_i$ to the lower time bound of the time query, i.e., $t_{start}=t_i$.
Next, the algorithm does the same set of operations, by removing at each iteration a lastly ranked element  $j_{t_i}$, and by stopping once the removal of  $j_{t_i}$ causes a decrease in the expected F1-Score value. Then, the algorithm assigns $t_i$ to the upper time bound of the time query, i.e., $t_{end}=t_i$.
Lastly, the algorithm returns the  time query $Q_t=[t_{start},t_{end}]$, with obviously $EF1(E^{*} \textrm{ that satisfies } Q_t=[t_{start},t_{end}]) \geq EF1(E)$.

\subfour{Dichotomy-based greedy algorithm:} Having a large dataset with a low number of positive data (e.g., 0.5\% of alerts in a security graph) will cause the previous algorithm to take a large number of iterations to terminate since it greedily adjusts filter settings in a minimal way at each step.  A way to address this problem is to use binary partitioning search, which we call Dichotomy search.  Hence, instead of removing a single element $j$ at each iteration, this algorithm operates by selecting between two distinct alternatives (dichotomies) at each iteration.

\begin{algorithm}[t]
%\scriptsize
\caption{Dichotomy Algorithm}
\SetAlgoLined
\SetKwData{Left}{left}\SetKwData{This}{this}\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}\SetKwFunction{FindCompress}{FindCompress}
\SetKwInOut{Input}{input}\SetKwInOut{Output}{output}
\Input{A set of ordered elements $E=\{j_{v_1} \dots j_{v_n}\}$ }
\Output{A timestamp $t$;}
\BlankLine
\label{alg:Dichotomy}

$v_{min}=v_1$; $v_{max}=v_n$;  $v_{mid}=\tfrac{v_1+v_n}{2}$;

\While {$v_{min}!=v_{mid}!=v_{max}$}{

\eIf{$[EF1(\{j_{v_{min}} \dots  j_{v_n}\}) \geq EF1(\{j_{v_{mid}} \dots  j_{v_n}\})]$}{
$v_{max}=v_{mid}$;
$v_{mid}=\tfrac{v_{min}+v_{mid}}{2}$;
}{
$v_{min}=v_{mid}$;
$v_{mid}=\tfrac{v_{min}+v_{max}}{2}$;
}
}
\Return  $v_{mid}$;

\label{alg:return}
\end{algorithm}

%Therefore, the algorithm first sets the values $t_{min}=t_1$, $t_{max}=t_n$,  and $t_{mid}=\tfrac{t_1+t_n}{2}$. Then, for each iteration, if $[EF1(\{d_{t_{min}}\leq \dots \leq d_{t_n}\}) \geq EF1(\{d_{t_{mid}}\leq \dots \leq d_{t_n}\})]$, the algorithm sets $t_{max}=t_{mid}$, $t_{mid}=\tfrac{t_{min}+t_{mid}}{2}$ and makes a new iteration, else, the algorithm sets $t_{min}=t_{mid}$,  $t_{mid}=\tfrac{t_{min}+t_{max}}{2}$  and makes a new iteration. The algorithm keeps iterating until $t_{min}=t_{mid}=t_{max}$, where it assigns $t_{mid}$ to the lower time bound of the time query, i.e., $t_{start}=t_{mid}$.

As an example of the Dichotomy approach for the time sub-filter, the algorithm first sorts $E$ in increasing order of time stamp. Then, it applies the procedure described by Algorithm \ref{alg:Dichotomy}. This procedure will return  the lower time bound of the time query, i.e., $t_{start}=t_{mid}$.
Next, the algorithm sorts $E$ in decreasing order of time stamp, and then, it applies again the procedure described by Algorithm \ref{alg:Dichotomy} to get the upper time bound of the time query, i.e., $t_{end}=t_i$. Lastly, the algorithm returns the  time query $Q_t=[t_{start},t_{end}]$, such that $EF1(E^{*} \textrm{ that satisfies } Q_t=[t_{start},t_{end}]) \geq EF1(E)$. Note that this algorithm proceeds in a total of $log(n)$ iterations in the best case, and $2\times log(n)$ iterations in the worst case.

For both the naive and time-based greedy algorithms, we use the red-black tree as the indexing data structure \cite{Guibas1978}.

\subsubsection{Position greedy algorithm} The aim of this algorithm is to return a query $Q_p=[(x_{min},y_{min}),(x_{max},y_{max})]$, which expresses the best set (assessed using one of the expected metrics described) of elements falling in the bounding box represented by the  lower and upper bound coordinates -- respectively $(x_{min},y_{min})$ and $(x_{max},y_{max})$. This two dimensional problem is similar to the previous one dimensional problem of finding the best time window. Therefore, the two greedy algorithms described above can be adapted for this problem by first applying each algorithm on the x-axis to determine $(x_{min},x_{max})$, then on the y-axis to determine $(y_{min},y_{max})$.  We omit the description of these two algorithms for lack of space, but a detailed description can be found in \cite{Bouadjenek2018}.

We use the R-tree as a data structure for indexing multi-dimensional continuous data~\cite{Guttman1984}.

\subsubsection{Multi-filter algorithm} To get a global query combining all filters, we propose a greedy algorithm, which basically at each iteration selects the best filter to apply, then checks if that filter improves the evaluation metric used. If so, the algorithm makes another iteration using the sub-set obtained in the previous iteration, otherwise, it stops. Note that here, we use  $k=1$ for the keywords greedy algorithm. The algorithm will then determine a sequence of filters to apply on the initial set, and the final query is then built by combining these filters by types.

 %such as: $\{Keyword \to Time -> Position \to Time \to Keyword\} $

For example, let's suppose the algorithm determines the following filter sequence: $\{Q_{k_1}=\{ \neg natural\} \to Q_{t_1}=[50,2030] \to Q_{p_1}=[(10,60), (50,100)] \to Q_{t_2}=[60,1230] \to Q_{k_2}=\{ \neg fictive\}  \to  Q_{p_2}=[(10,60), (30,85)] \to  Q_{t_3}=[60,800] \}$.
The final query is built by combining these filters by types as follows: $Q_k=Q_{k_1} \cup Q_{k_2}=\{\neg natural,\neg fictive\}$, $Q_t =Q_{t_1} \cap Q_{t_2} \cap Q_{t_3}=[60,800]$, and  $ Q_p=Q_{p_1}  \cap Q_{p_2}=[(10,60),$ $(30,85)]$, which gives $Q=[Q_k=\{\neg natural,\neg fictive\}\wedge Q_t=[60,800]\wedge Q_p = [(10,60),$ $(30,85)]]$.

Finally, note that this algorithm can use the keywords greedy algorithm with the time and position naive greedy algorithms to which we refer as Greedy Algorithm, or the keywords greedy algorithm with the time and position dichotomy-based algorithms to which we refer as Dichotomy Algorithm.

\subsection{Optimal Solutions for Benchmarking}

Next we propose an optimization-based algorithm to maximize EF1 and provide a benchmark for evaluation of the previous Greedy algorithms.  Given the trivial solution of optimizing the expected precision (singleton) and expected recall (the whole collection), we consider in the following only the optimization of EF1.

\subsubsection{Original intuitive formulation} \hfill \\
Let's first reformulate the objective EF1 to prepare further optimization step. Note that the global sum of scores of all information elements is a constant $C$ given the current system.
\begin{equation}
\begin{aligned}
    \emph{$EF1$} &= \dfrac{2\times \sum_{j=1}^m S(j)I(j)}{\sum_{j=1}^m I(j) + \sum_{j=1}^m S(j)} = \dfrac{2 \times \sum_{j=1}^m S(j)I(j)}{\sum_{j=1}^m I(j) + C}
\end{aligned}
\end{equation}

In order to obtain the optimal element set, we intend to directly optimize the EF1 metric in terms of decision indication variables $\emph{I\textsubscript{filter}} \in \left[0, 1\right]$ for filter setting as follows:
% Don't use I(i)... confusing!
%\begin{align}
%\max_{\textit{filter vars}} \;\;
%& \dfrac{\sum_{j=1}^m S(i)I(j)}{\sum_{j=1}^m I(j) + C} \nonumber \\
%& \textrm{subject to constraints between {\it filter vars} and $I(j)$}
%\end{align}
\begin{equation}
\begin{aligned}
& \underset{I_{\mathit{filter}}(j)}{\text{maximize}}
& & \dfrac{\sum_{j=1}^m S(j)I(j)}{\sum_{j=1}^m I(j) + C} \\
& s.t
& & I(j) = \bigwedge I_{\mathit{filter}}(j) \\
\end{aligned}
\end{equation}

Note that our goal is to optimize the element set in terms of \emph{filters settings}. This means elements in the interface sharing the same property needs to be simultaneously added to the selected set. This is a unique property of our filter-based UI problem, which is different from the independent retrieval of each document in standard IR system.

\subsubsection{Transformation to a MILP} \hfill \\
In order to transform the above fractional optimization problem into a Mixed-integer Linear Programming (MILP) form (for which we have optimal solvers), we use the Charnes-Cooper method \cite{Charnes1962} and Glover linearization method \cite{Glover1975} with big-M constraints, where auxiliary variables \emph{w(j)} and \emph{u} must be  introduced\footnote{https://optimization.mccormick.northwestern.edu/index.php/Mixed-integer\_linear\_fractional\_programming\_(MILFP)}. Here, $w(j)$ is defined as $w(j)=I(j)\times u$ with $u$ defined as follows:
\begin{equation}
u = \dfrac{1}{\sum_{j=1}^m I(j) + C}
\end{equation}

Then, the EF1 optimization problem is able to be transformed into the following MILP problem:
\begin{equation}
\begin{aligned}
& \underset{w,u}{\text{maximize}}
& & \sum_{j=1}^m S(j)w(j) \\
& s.t
& & \sum_{j=1}^m w(j) + uC = 1 \\
& & & w(j) \leqslant u, \quad w(j) \leqslant M\times I(j)  \\
& & & w(j) \geqslant u - M\times [1-I(j)] \\
& & & u > 0,  \quad I(j) \in \{0, 1\}, \quad w(j) \geqslant 0
\end{aligned}
\end{equation}

\subsubsection{Constraints} \hfill \\
As our goal is to select elements through three sub-filters, we add three constraints to the above optimization.
\begin{enumerate}
\item Time: a two-element tuple ($t_{start}$, $t_{end}$) indicating respectively the start and the end of the time window.

\begin{equation}
\begin{aligned}
  I_{\mathit{time}}(j) &=
   \begin{cases}
     1, & \text{if $(t_{start} \leqslant t(j)) \land (t(j) \leqslant t_{end})$}  \\
     0, & \text{otherwise}
  \end{cases}
\end{aligned}
\end{equation}

\item Position: a four-element tuple ($x_{min}$, $y_{min}$, $x_{max}$, $y_{max}$) to create a bounding box filter in visualization interface.

\begin{equation}
\begin{aligned}
I_{\mathit{pos}}(j) & =\begin{cases}
1, & \text{if \ensuremath{(x_{min}\leqslant x(j))\land(x(j)\leqslant x_{max})\land}}\\
 & (y_{min}\leqslant y(j))\land(y(j)\leqslant y_{max})\\
0, & \text{otherwise}
\end{cases}
\end{aligned}
\end{equation}

\item Keyword: a boolean vector of terms $t^*_k$ with size $m$ - the size of the dictionary of the global collection.

\begin{equation}
  I_{\mathit{term}}(j) = \bigwedge_{t^*_k \in j} t^*_k \qquad \textnormal{for s = 1, 2, $\cdots$, m}
\end{equation}
All terms with $I_{\mathit{term}}=0$ are included in the negation query.

\item Multiple Filter: if an element $j$ is simultaneously selected via the three sub-filters, all filter constraints have to be satisfied in this element. In others words, an AND operator is required between all the sub-filter constraints.

%{\bf TODO: mention how to apply to all filters... need to say an email j is selected if \emph{all} filters say it is selected, so an AND constraint.  \textcolor{red}{[PLEASE COMPLETE YIHAO]}.
%}

\begin{equation}
  I(j) = I_{\mathit{time}}(j) \land I_{\mathit{pos}}(j) \land I_{\mathit{keyword}}(j)
\end{equation}

\end{enumerate}

\subsection{Multiple Filter Selection Wrapper}

In practice a single filter chosen by the previously described algorithms will narrow the user in on a single \textquotedblleft event\textquotedblright{}. However, there will likely be multiple anomalous events and so the user should have a choice of multiple filters.  In this work, we provide an initial greedy approach for providing a ranked list of multiple filters (that is a wrapper approach working with any of the previously defined filtering algorithms); we leave it to future work to develop improved filtering and ranking methods for multiple filters.

The algorithm itself is quite simple.  After the first filter is produced, all selected elements by the filter have their scores zeroed out.  The filtering algorithm is then run again, where it will inherently focus on a different content set.  This procedure is repeated until the desired number of filters is reached, or a metric / coverage score for high scoring content is reached.  The user should then be able to choose among the multiple filters.


\section{Introduction}
\label{sec:introduction}

A proof assistant is a piece of software that can assist a human user in writing a particular type of proofs, one that can be verified by a machine. Proofs following this format are desirable because it suffices to show that the verification procedure is sound to automatically and irrefutably judge any of them. Computer-assisted theorem proving can also leverage the computational capabilities offered by machines, one of the most famous example being the proof of the \textit{four-color conjecture} \cite{Appel1989}. However, the greatest strength of proof assistants might also be their greatest weakness: they are often complex systems, whose correctness is difficult to demonstrate and therefore are prone to bugs in their implementation. They also suffer from a lack of understandability, both in terms of the underlying theories used and of the proofs produced, which results in a low adoption rate by mathematicians \cite{Ayers2021}.

In this thesis we describe the design process of a front-end for the modern proof assistant LISA. Our main focus is to preserve the same soundness standards as the existing framework while making it more expressive and interactive. The supporting source code for this project is published at the following address:
\begin{center}
\href{http://github.com/FlorianCassayre/master-project}{\textbf{github.com/FlorianCassayre/master-project}}\footnote{The current release is identified by commit number: \code{868c750de37171e524612673bbed6058dadaa8bb}}
\end{center}

\subsection{LISA}

LISA\footnote{\textbf{L}ISA \textbf{I}s \textbf{S}ets \textbf{A}utomated} is an ongoing project conducted at the Lab for Automated Reasoning and Analysis (LARA), EPFL. It is a library built on top of sequent calculus and set theory that enables the formalization of mathematical proofs \cite{Guilloud2022-2}.

\begin{figure}[H]
  $$
  \begin{prooftree}
  \hypo{}
  \infer1[Hypo.]{{?a} \vdash {?a}, {?b}}
  \infer1[Left $\neg$]{\neg{?a}, {?a} \vdash {?b}}
  \hypo{}
  \infer1[Hypo.]{{?a}, {?b} \vdash {?b}}
  \infer2[Left $\lor$]{\neg{?a} \lor {?b}, {?a} \vdash {?b}}
  \infer1[Right $\Rightarrow$]{\neg{?a} \lor {?b} \vdash {?a} \Rightarrow {?b}}
  \infer1[Right $\Rightarrow$]{\vdash \neg{?a} \lor {?b} \Rightarrow {?a} \Rightarrow {?b}}
  %
  \hypo{}
  \infer1[Hypo.]{{?a} \vdash {?a}, {?b}}
  \infer1[Right $\neg$]{\vdash \neg{?a}, {?a}, {?b}}
  \hypo{}
  \infer1[Hypo.]{{?b} \vdash \neg{?a}, {?b}}
  \infer2[Left $\Rightarrow$]{{?a} \Rightarrow {?b} \vdash \neg{?a}, {?b}}
  \infer1[Right $\lor$]{{?a} \Rightarrow {?b} \vdash \neg{?a} \lor {?b}}
  \infer1[Right $\Rightarrow$]{\vdash ({?a} \Rightarrow {?b}) \Rightarrow \neg{?a} \lor {?b}}
  %
  \infer2[Right $\Leftrightarrow$]{\vdash \neg{?a} \lor {?b} \Leftrightarrow {?a} \Rightarrow {?b}}
  \end{prooftree}
  $$
  \caption[Proof tree (1)]{An example of a proof in sequent calculus. This proof demonstrates the tautology $\neg{?a}\lor{?b}\Leftrightarrow{?a}\Rightarrow{?b}$. The question mark indicates a schema, namely a variable that can later be instantiated. The inference rule used at every step is indicated on the right.}
  \label{fig:simple-lisa-proof-graph}
\end{figure}

\begin{figure}[H]
  \centering
  \input{figures/proof-mini.lisa}
  \caption[Proof in LISA]{A representation of the proof of \autoref{fig:simple-lisa-proof-graph} in LISA. Each step is assigned an index, and import are represented with negative indices. Scoping within the proof is possible and determined by the indentation level: subproofs are indented further down. The second column states what rule is used, along with the premises it uses. The third column is the conclusion of that step. The last column contains parameters to disambiguate the application of the rule.}
  \label{fig:simple-lisa-proof}
\end{figure}

A proof in this system is a directed acyclic graph of proof steps. Each such step corresponds to the application of an inference rule, and is characterized by its conclusion expressed as a sequent, and some premises. A sequent is a pair of sets of formulas, noted $\phi_1, \phi_2, ..., \phi_n \vdash \psi_1, \psi_2, ..., \psi_m$ or $\Gamma \vdash \Delta$, and can be interpreted in conventional logic as a conjunction of premises implying a disjunction of conclusions. That said, the actual semantic is controlled by the inference rules provided by the system. Proofs can optionally have ``imports'': sequents that are used as premises but do not come from any step. Proofs may also be nested for organization purposes. Figures \ref{fig:simple-lisa-proof-graph} and \ref{fig:simple-lisa-proof} showcase a formal proof in LISA. Notice that a directed acyclic graph can always be represented in a linear fashion, but not necessarily as a tree (unless we duplicate forward edges).

Currently LISA only exists as a Scala library, therefore the proofs are described using Scala code. For further technical details about LISA, we refer the reader to the official manual \cite{Guilloud2022-2}.


\vsssub
\subsubsection{~$S_{mud}$: Dissipation by viscous mud (D\&L)} \label{sec:BT8}
\vsssub

\opthead{BT8}{NRL/SWAN}{M. Orzech and E. Rogers}

\noindent
Two formulations for wave damping by viscous fluid mud have been implemented
in \ws\, based on earlier implementations in a SWAN code at NRL.  As with wave
damping by ice (Sect. \ref{sec:ICE1}), both rely on the concept of complex
wave number (Eq. (\ref{eq:waveno})). Both treat the mud layer as a viscous
fluid, and both assume that the mud depth is comparable to its Stokes'
boundary layer thickness. The first formulation (\cite{art:DL78}; hereafter
D\&L) is a numerical solution.  The second formulation (\cite{art:Ng00};
hereafter Ng) is an analytical, asymptotic solution, so calculations tend to
be much faster than with D\&L. For the range of mud characteristics used by
\cite{art:RH09}, which are based on field measurements (and estimates),
the methods produce very similar results.

In each case, the mud-induced dissipation is added to contributions from other
source/sink terms in Eq.~(\ref{eq:bal_plane}).

\begin{equation}\label{eq:dmud1}
  {S_{mud}} = 2  k_i {C_{g,mud}},
\end{equation}

\noindent
where $k_i=imag({k_{mud}})$ and ${C_{g,mud}}$ is the mud-modified wave group
velocity.

The above follows from exponential decay of a single wave train with initial
amplitude $a_0$:
\begin{equation}\label{eq:dmud2}
 a=a_0e^{-k_ix}.
\end{equation}

\noindent
Both methods operate by solving for a modified dispersion relation, where the
wavenumber being solved for, ${k_{mud}}$, is a complex number. The D\&L method
uses an iterative procedure for this dispersion relation. For details, see
Section 2 and Appendix B of \cite{art:DL78}. Descriptions specific to {\code
BT9} (Ng) are given in the following section.

To activate viscous mud effects with the (D\&L) routines, the user specifies
{\code BT8} in the switch parameter file.

In the case where any of the new ice and mud source functions are activated
with the switches {\code IC1}, {\code IC2}, {\code IC3}, {\code BT8}, or
{\code BT9}, {\file ww3\_shel} will anticipate instructions for 8 new fields
(5 for ice, then 3 for mud). These are given prior to the ``water levels''
information. The new fields can also be specified as homogeneous field using
{\file ww3\_shel.inp}. The mud parameters are mud density (kg/m$^3$), mud
thickness (m), and mud viscosity (m$^2$/s), in that order.

The user is referred to the regression tests {\file ww3\_tbt1.1} {\file
ww3\_tbt2.1} for examples of how to use the new mud source functions.

\textrm{\textit{\underline{Limitations of the code}}}: In the case of {\file ww3\_multi},
the interface for the necessary mud and ice forcing fields has only been implemented when using
the namelist type of input file.  In the case of mud, though the ${k_r}$ is calculated, its effect is
not passed back to the main program. The only effect is via ${k_i}$
(dissipation). Full implementation of ${k_r}$, already possible with IC3, and
will be available in a future version of the model.

\textrm{\textit{\underline{Limitations of the physics}}}: 1) Both models
({\code BT8}, {\code BT9}) neglect elasticity in the mud layer. 2)
Non-Newtonian response of the mud (e.g. as a thixotropic fluid) is not
available. 3) Mud thickness should be interpreted not as the total mud
thickness, but rather as the thickness of the fluidized mud layer. This value
is notoriously difficult to determine in practice
(\cite{art:RH09}). Fortunately, since \ws\ supports nonstationary and
non-uniform input for the mud parameters, it is possible to address items (2)
and (3) via coupling with a numerical model of the mud layer: no additional
changes to the \ws\ code are required for this.


\subsection{Discrete states as vectors}

\subsection{Observables as linear operators}

\subsection{Orthonormal basis}


\chapter{RANDOMNESS AND GRIDLOCK} \label{ch:random}

\epigraph{Everything we care about lies somewhere in the middle, where pattern and randomness interlace.}{James Gleick, \emph{The Information: A History, a Theory, a Flood}}

In this chapter, I define and examine the \emph{gridlock} behavior of the leximin method. In the case of random graphs, I show a reliable tendency that for some edge creation probability $p$, as the network size grows, the occurrence of gridlock becomes more frequent. I show that for any gridlock graph with rational capacities, there exists a constant $k$ such that when the capacities of all edges are $k$, integer flows can be assigned along each path. For diameter-2 random graphs, I conjecture that this value $k$ is $M / [N (N-1) - M]$.

\section{Introduction}

If a community detection method splits a global community into all individuals, and the method has some justification as realistic, then this behavior says that the input is indistinguishable from what random associations would give. Only two levels of structure exist: the macroscopic level of the entire graph and the microscopic level of single nodes. There is no mesoscopic, community structure.

The leximin method for community detection has a tendency to produce the microscopic structure as the only partition in its hierarchy under certain conditions. We call this phenomenon \emph{gridlock}. When it occurs, we affirm that a particular example is \emph{practically} equivalent to random associations. This may suggest that methods which generate hierarchies on these networks lack the causality to do so; instead, they overzealously force communities to be generated in the given example. Obtaining a hierarchy inexplicable by causality is at best problematic and effectively accidental.

\subsection{Gridlock}

The only replicable partition, irrespective of a random edge creation process, is immediate separation into individual singleton parts. The leximin method can identify such a partition into communities as the only extant one, because every edge is saturated simultaneously. This is \emph{gridlock}. Only the macro- and microscopic structure exist, without a mesoscopic structure. A graph with these properties is called a \emph{gridlock graph}.

What differentiates gridlock from a tie is the width of the stable ranges. In a tie, the stable ranges are tight because ties straddle the boundaries of two behaviors, creating a superposition of dendrogram states. By contrast, gridlock is a stable behavior. The width of the stable range along any axis is not infinitesimally small. Gridlock need not occur at the first level of the hierarchy, but in this work, we specify when gridlock is not immediate. In general, we use the term to refer to immediate gridlock.

A useful lemma about gridlock and modularity can be proven based on a lemma given by Brandes et al.~\cite{brandes2007finding}:
\begin{lemma}
\label{lemma:modularity}

A clustering with maximum modularity has no cluster that consists of a single node with degree 1.
\end{lemma}

Gridlock is a clustering with very low modularity, according to Lemma \autoref{lemma:modularity}. In fact, the modularity of singleton clustering is the minimum possible~\cite{brandes2008modularity}. This suggests a corresponding Lemma:

\begin{lemma}
\label{lemma:grids}

If the modularity-maximizing flat clustering produced by the leximin method is into singletons, then gridlock has occurred.
\end{lemma}

\begin{proof}
According to Lemma \autoref{lemma:grids}, the singletons of gridlock produce the worst possible modularity. If they are the highest-modularity clustering found, then there exist no other clusterings in the dendrogram.
\end{proof}

A final observation is that when immediate gridlock occurs, there is only one level in the hierarchy, so the leximin and maximin solutions are the same. Since only one level is solved, rather than up to $N - 1$, a lack of community structure causes the method to \say{fail fast}.

\subsection{Random graphs}

A helpful model to examine this structure of random connections is the binomial graph model. It produces a graph~$G(N, p)$, specifying the number of nodes~$N$ and the probability of an edge between each pair of nodes~$p$. The model was introduced by Gilbert~\cite{gilbert1959random} and analyzed by Erd\H{o}s and R\'enyi~\cite{erdos1960evolution}.

Much attention has been given to the problem of a dense community \emph{planted} in an otherwise random graph~\cite{hajek2015computational, arias2013community}. Less attention has been given to the \emph{existential} problem of communities in random graphs---of structure inherent in randomness. An exception to this is what has been called \say{one of the most surprising results in the theory of random graphs}: the identification of a reliable largest clique size for a given $p$~\cite{matula1976largest, palmer1985graphical}. Although the largest clique size is replicable across instances of the random graph with given parameters, the particular set of members is almost certainly not replicable. The issue of determining a well-defined cluster of members that should recur is not affected by this observation. Additional work has been done to identify communities in random graphs by consensus using nondeterministic methods~\cite{campigotto2013power} and to relate community size in random graphs to component size~\cite{lipowski2014generic}.

To assess whether there exists a community structure in random graphs, we use the leximin method. For a sufficiently homogeneous graph, the leximin method exhibits gridlock. As the first and only possible partition, it separates the graph into singletons. This dissection suggests a lack of mesoscopic, community structure in the graph. Computational results presented below support this conclusion.

\section{Experimental Evidence} \label{sec:random_experiment}

\begin{figure}
\centering
\begin{subfigure}[c]{0.48\textwidth}
\centering
\includegraphics[height=0.225\textheight]{fig/gridlock_big}
\caption{Group 1: 10 trials each}
\end{subfigure}
\quad
\begin{subfigure}[c]{0.48\textwidth}
\centering
\includegraphics[height=0.225\textheight]{fig/gridlock_small}
\caption{Group 2: 100 trials each}
\end{subfigure}
\caption{Rate of gridlock for each combination of $N$ and $p$}
\label{fig:gridlock}
\end{figure}

To examine the community structure of random graphs, two groups of test graphs were created:
\begin{description}
\item[Group 1.] 10 graphs each at $N = 20, 40, \ldots, 160$ and $p = \frac{1}{10}, \frac{2}{10}, \ldots, \frac{9}{10}$
\item[Group 2.] 100 graphs each at $N = 20, 24, \ldots, 80$ and $p = \frac{1}{25}, \frac{2}{25}, \ldots, \frac{24}{25}$
\end{description}
For each of these parameter combinations, we computed the fraction which display immediate gridlock. From the empirical results shown in \autoref{fig:gridlock}, we see a tendency that for a given $p$, increasing $N$ reliably increases the rate of immediate gridlock.

It is important to note that middle values of the edge probability~$p$ are capable of producing gridlock at lower sizes~$N$, compared to high or low values. For lower values, the reason is that so few edges naturally impart a structure; after all, there is a threshold $p = 1/n$ for the graph to be connected at all~\cite{frieze2015introduction, janson2011random}. On the higher end, gridlock is less common because removing edges from a complete graph (i.e.\ one with $p=1$) produces nodes of minimum degree less than $N - 1$. The resulting asymmetry of node degree generally yields more than one level in the leximin hierarchy. This investigation of the number of levels and the causes is worthy of more investigation.

\section{Discussion}

We can show a result for maximum concurrent flow similar to Menger's theorem for maximum flow~\cite{menger1927allgemeinen}: that a multigraph of the gridlocked graph exists where all edges can be partitioned into edge-disjoint paths with the same number of paths between each node pair.

\begin{theorem}{Edge-disjoint paths in gridlock graphs.} \label{thm:edge}

A multigraph of the gridlocked graph exists where all edges can be partitioned into edge-disjoint paths with the same number of paths between each node pair.
\end{theorem}
\begin{proof}
In a gridlock graph, the demand between all pairs is equal, and the utilized capacity of each edge is equal. The flow may be diverted between various intermediate nodes before reaching its destination, possibly taking multiple paths.

Linear programs with integer coefficients (like the HMCFP) produce rational results~\cite{adler1992polynomial}, so the flow assigned to each path will be rational: a value $p/q$ where $q \ne 0$. Let $k$ be the least common multiple (LCM) of all the denominators of the flows on each path. Assigning this value as the capacity of each edge creates integer-valued flow along all paths, indicating the number of copies of each path. This also means that the capacity of an edge is split into integral flows, from each path that uses that edge.

Each capacitated (weighted) edge with capacity $C$ can be replaced with $C$ unweighted edges, producing the desired multigraph. A path that requires $c < C$ units of flow can utilize $c$ of the $C$ edges. All paths will do this, resulting in edge-disjoint paths on the multigraph.
\end{proof}

An example application of this theorem is the smallest nontrivial graph with gridlock: $K_{3,2}$. Its throughput is $z = M/[N (N -1) - M] = 6/14 = 3/7$. The flow allocations on each path have denominators of 7 or 14. When scaling up all flows by the LCM of these values, we get 14 unweighted paths between each pair. \autoref{fig:k32_integer} shows the unweighted multigraph's edge-disjoint paths.

\begin{figure}
\centering
\begin{subfigure}[c]{0.48\textwidth}
\centering
\includegraphics[height=0.225\textheight]{fig/diameter_big}
\caption{Group 1: 10 trials each}
\end{subfigure}
\quad
\begin{subfigure}[c]{0.48\textwidth}
\centering
\includegraphics[height=0.225\textheight]{fig/diameter_small}
\caption{Group 2: 100 trials each}
\end{subfigure}
\caption{Average diameter for each combination of $N$ and $p$}
\label{fig:diameter}
\end{figure}

\begin{figure}
\centering
\includegraphics[height=0.25\textheight]{fig/k32_integer}
\caption{The gridlock graph $K_{3,2}$ represented as a multigraph. A single color corresponds to a single route. There are $[N (N-1) - M] = 14$ edges between each node, and 6 are used for demand between each pair of nodes. 2 units between the end nodes 1 and 5 are routed through each middle node 2, 3, and 4. 3 units between each pair of middle nodes are routed through each end node.}
\label{fig:k32_integer}
\end{figure}

\subsection{Gridlock Graphs with Diameter 2}

In the experiment from \autoref{sec:random_experiment}, most graphs that gridlock have diameter 2 (see \autoref{fig:diameter}). This is not a requirement; we see from the $(N=160, p=0.3)$ case that gridlock is possible on a diameter-3 graph (see \autoref{fig:diameter}).

In the case that the diameter is 2, the maximum throughput is easily computable. There exist $|D| = {N \choose 2}$ demand pairs, of which $M$ are at distance 1. Thus, the sum of all shortest path lengths is $M + 2(|D| - M) = 2|D| - M$. These shortest paths must carry all flow, or else we waste capacity by taking longer paths~\cite{mann2008extensions}. Additionally, because we assume unit capacity on each edge, the total capacity is $M$. The throughput is then $z = M / [N (N-1) - M]$. This is the \emph{gridlock bound}, first identified by Biswas and Matula~\cite{biswas1986two}.

Since throughput is the amount of flow between each pair, we can get an integral flow of $M$ units when we scale up the capacity of each edge by the denominator $[N(N-1)-M]$.

We can consider specific cases of diameter-2 gridlock graphs with low $p$, with scaled-up edge capacity. These tend to produce several paths at integral flow $M$, as well as some paths with either integral or  fractional values that sum to $M$. We know these values are fractional, rather than irrational, because linear programs with integer coefficients produce rational results~\cite{adler1992polynomial}. The question emerges whether there exists an assignment of flow that is not only rational, but also integral.

\begin{description}
\item[Conjecture.] \emph{In a random graph of diameter 2 and $p<0.5$ that exhibits gridlock, there exists an integer assignment of flows to paths when the capacity of edges is equal to $[N ( N - 1 ) - M ]$.}
\end{description}

As a justification for this conjecture, consider the fact that there exists a multiple of $[N ( N - 1 ) - M ]$ where all paths have integer flow. This comes from Theorem \autoref{thm:edge}. Additionally, the case of $K_{3,2}$ did evenly split its flow along integer paths, as shown in \autoref{fig:k32_integer}. What remains is to show that this multiple is in fact exactly $[N ( N - 1 ) - M ]$ in all such cases.

More work is needed here to prove the conjecture provided above, or to otherwise determine how big the edge multiplicity must be, such that it prescribes a partition into paths with the same number of paths between each node pair. A major hindrance is that while a unique set of critical edges exists, there is not necessarily a unique assignment of flow along paths. To guarantee an integer solution (if it exists) is possible using integer linear programming (ILP), which is NP-hard.


\chapter{Coupling Discrete Dislocation Dynamics to Finite Element Methods}
\label{c:ddd_fem}
\section{Superposition Scheme}
\label{s:sup_sch}
Coupling discrete dislocation dynamics to a finite element method \cite{analytic_tractions} is important to properly simulate micromechanical tests because discrete dislocation dynamics provides us with a more precise set of inputs and greater granularity for solving the finite element problem. This can be achieved by using a so-called superposition scheme \cref{f:fem_ddd} that enables the independent solution of both problems, whilst feeding information from one to the other in a continuous feedback loop.
\begin{figure}
	\centering
	\includegraphics[width=\linewidth]{fem_ddd.eps}
	\caption[Coupling Discrete Dislocation Dynamics to Finite Element Methods.]{The dislocation ensemble in a volume $ V $ is bounded by surface $ S $. First, the traction field $ \sum_{\textrm{d}} \tns{\tilde{\sigma}}_{\textrm{d}} $ due to the dislocation ensemble is evaluated at the surface. Then, a traditional finite element method or boundary element method calculates the image traction field $ \tns{\hat{\sigma}} \times \vec{n} $. Which is then fed back to the discrete dislocation dynamics problem to evolve the dislocation positions and repeat the cycle. Image edited from \cite{analytic_tractions}.}
	\label{f:fem_ddd}
\end{figure}
\section{Extracting Surface Nodes}
The finite element method coupler arranges the nodes starting on the $ xz $-plane where $ y \in \{0 \to n~\mathrm{d}y\}$ and $n\in \mathbb{N} $. However in order to couple discrete dislocation dynamics to finite element method we only require the surface nodes where displacements are not calculated. Because we're working with rectangular prisms, we can easily pick out the surface nodes using a search algorithm with a logical mask. MATLAB and Fortran provide vector intrinsics that allow one to do so. \Cref{f:fem_surf_nodes} illustrates only the surface nodes according to our implementation's node arrangement---which is the $ xz $-plane whose domain is $[y_{\text{min}},~ y_{\text{max}}]$.
\begin{figure}
	\centering
	\begin{subfigure}[b]{0.45\linewidth}
		\centering
		\includegraphics[width=\linewidth]{fem_surf_nodes.pdf}
		\caption[Surface nodes of our finite element model.]{Arrangement of the surface nodes of our finite element model. finite element nodes are arranged in chunks of $ \Delta x \Delta z $ nodes in our implementation, but we only want the surface nodes.}
		\label{f:fem_surf_nodes}
	\end{subfigure}
	~
	\begin{subfigure}[b]{0.45\linewidth}
		\centering
		\includegraphics[width=\linewidth]{fe_numbering.pdf}
		\caption[Single finite element node numbering.]{Single finite element node numbering. It is necessary to know which finite element plane corresponds to which node labels. This lets us design the auxiliary matrix that selects nodes according to the planes we want to extract.}
		\label{f:fe_numbering}
	\end{subfigure}
	\caption[Finite Element node arrangement for coupling to Discrete Dislocation Dynamics.]{finite element node arrangement for coupling to discrete dislocation dynamics.}
	\label{f:fem_node_arr}
\end{figure}
However, due to the nature of the analytical solutions in \cref{c:lin_rect}, we need all the surface nodes of the rectangular faces for which there are no displacements. This means that edge nodes are shared between 2 adjacent faces and corner nodes between 3 adjacent faces. In order to properly apply the logical mask to find \emph{only} the surface nodes need to know that each finite element's nodes are numbered according to \cref{f:fe_numbering}.

Using \cref{f:fem_node_arr} one can work out which nodes are of interest to whichever surface is being extracted. The ordering of the nodes in the final array will depend on the definition of the problems in \cref{c:lin_rect}.

Node selection remains an expensive operation and minimising array indexing is of the utmost importance for the best perfomance. Selecting nodes in the traditional sense, i.e. with code branching such as \texttt{if statements} or \texttt{case selection} is unmantainable, verbose and very prone to mistakes. The issue was solved by introducing an auxiliary matrix which defines various parameters that aid node selection and greatly reduces code size, improves readability, and eliminates the need for code branching. The matrix can be constructed utilising \cref{f:fem_node_arr} in order to know which nodes correspond to which finite element planes. The $ p\textsuperscript{th} $ column of the matrix\footnote{MATLAB uses column-major ordering, so this gives us the best performance for vectorised code.} corresponds to the $ p\textsuperscript{th} $ plane (according to an arbitrary plane numbering) and is defined as,
\begin{align}\label{eq:surf_node_util_vec}
	\vec{V_{p}}^{\mathsf{T}} =
	\begin{bmatrix}
		L_{1p} & L_{2p} & \cdots & L_{Np} & A_{p} & C_{p}
	\end{bmatrix}\,,
\end{align}
where $ L_{np} $ is the numeric label for node $ n $ as given by \cref{f:fem_node_arr}, $ A_{p} $ is the area of the plane, and $ C_{p} $ is the numeric label of the orthogonal coordinate to the plane $ C_{p} = 1, ~2, ~3 $ for the $ x, ~y, ~z $ coordinates respectively. $ A_{p} $ lets us segment our output and transitional arrays so that the only data being modified is that which corresponds to the correct plane and $ C_{p} $ lets us know which coordinate we must use in our selection criteria. Using our particular node labelling scheme (with dimensions $ \Delta x,~ \Delta y,~ \Delta z $ respectively in the $ x,~ y,~ z $ directions), the matrix is defined as,
\begin{align}\label{eq:surf_node_util}
	\mtx{V} =
	\begin{bmatrix}
		5                 & 2                 & 6                 & 1                 & 5                 & 4                 \\
		1                 & 6                 & 5                 & 2                 & 6                 & 3                 \\
		8                 & 3                 & 7                 & 4                 & 1                 & 8                 \\
		4                 & 7                 & 8                 & 3                 & 2                 & 7                 \\
		\Delta y \Delta z & \Delta y \Delta z & \Delta x \Delta z & \Delta x \Delta z & \Delta x \Delta y & \Delta x \Delta y \\
		1                 & 1                 & 2                 & 2                 & 3                 & 3
	\end{bmatrix}\,.
\end{align}
The information codified in \cref{eq:surf_node_util} lets us index and process only the necessary columns to extract the surface nodes we're interested in. The advantage of this setup over a naïve implementation is that it can be relatively easily expanded, maintained, and is general enough that it lends itself to a variety of selection criteria. The columns from left to right (1 to 6) represent:
\begin{enumerate}[{face} 1 $ \equiv $]
	\item $ \min(x),~ yz $-plane;
	\item $ \max(x),~ yz $-plane;
	\item $ \min(y),~ xz $-plane;
	\item $ \max(y),~ xz $-plane;
	\item $ \min(z),~ xy $-plane;
	\item $ \max(z),~ xy $-plane.
\end{enumerate}

It is important to make sure the nodes are extracted in a self consistent manner because the problem definitions in \cref{c:lin_rect} assume a specific node ordering. In particular, the labelling chirality must remain the same. This is due to the fact that the problems in \cref{c:lin_rect} utilise internal coordinates derived from a set of basis vectors, and scalar projections onto them. If the relationship between the vectors is kept, but the chirality is different (opposite) the calculated quantities will have the wrong sign. If however the relationship between the vectors is different to the problem formulation, the program will crash due to division by 0. Self-consistency was achieved by placing an imaginary observer inside the finite element model facing the $ \min(x),~ yz $-plane (face 1) and rotating it to view all 6 planes according to \cref{f:surf_node_plane}.
\begin{figure}
	\centering
	\includegraphics[width=0.75\linewidth]{surf_node_plane.pdf}
	\caption[Self-consistent, chirality preserving surface planes.]{Self-consistent, chirality preserving surface planes. Plane and node numbering according to the columns of \cref{eq:surf_node_util} and \cref{f:fem_node_arr}.}
	\label{f:surf_node_plane}
\end{figure}
\section{Mapping Forces}
\begin{algorithm}
	\caption{If $ \vec{\hat{F}} $'s columns are arranged the same way as $ \vec{\gamma_{t}} $.}
	\begin{algorithmic}[1]
		\State\Comment{Loop through the array containing the node labels of the relevant surface nodes.}
		\For{$ i = 0;\, i < \rvar{length}(\vec{\gamma_{t}});\, i++$}
		\State\Comment{Save the global node label for the current iteration.}
		\State $ n \gets \vec{\gamma_{t}}[i] $
		\State\Comment{Use the node label to find a vector with the linearised index of all surface nodes whose labels correspond to the node whose forces we want to pass on to the finite element method coupler.}
		\State $ \vec{L} \gets \rvar{find}(\mtx{N_{L}} == n) $
		\State\Comment{Loop over coordinates.}
		\For{$ k = 0;\, k < 3;\, k++ $}
		\State\Comment{Use global node label vector to index the force array from the analytical force calculation due to dislocations on surface nodes. Multiplied by 3 because there are three coordinates per node. We sum the forces from the analytical calculation because the same global node can be part of multiple surface elements. We add $ k $ because the $ x,~y,~z $ coordinates are consecutively stored in $ \mtx{F_{n}} $.}
		\State $ \mtx{\hat{F}}[3\times \vec{L} + k] \gets \mtx{\hat{F}}[3\times \vec{L} + k] + \sum\mtx{F_{n}}[3\times \vec{L} + k]  $
		\EndFor
		\EndFor
	\end{algorithmic}
\end{algorithm}

%	\begin{algorithm}
%		\begin{algorithmic}[1]
%			content...
%		\end{algorithmic}
%	\end{algorithm}
\begin{figure}
	\centering
	\includegraphics[width=\linewidth]{lrse_thread_map.pdf}
	\caption[Finite element nodes shared by multiple surface elements.]{finite element nodes shared by multiple surface elements.}
	\label{f:fe_node_share}
\end{figure}

$ \vec{\hat{F}} $ only cares about the global node numbers, of which there are $ M $. The columns of $ \mtx{N_{L}},~ \mtx{F_{N}} $ represent the 4 nodes of a surface element, the rows represent the surface element they are part of. The column vector $ \vec{x} $ represents the $ x,~y,~z$-coordinates of the node-element or global node corresponding to their subscript. The column vector $ \vec{\gamma_{t}} $ is the list of global nodes for which the forces induced by dislocations must be calculated.
\begin{align}
	\vec{x_{e,n}}^{\mathsf{T}} & \equiv	\begin{bmatrix}
		x_{en} & y_{en} & z_{en}
	\end{bmatrix}, \quad
	\vec{\hat{x}_{n}}^{\mathsf{T}} \equiv	\begin{bmatrix}
		x_{n} & y_{n} & z_{n}
	\end{bmatrix}      \\
	\begin{split}
		\mtx{N_{L}} &=	\begin{bmatrix}
			l_{1,1} & l_{1,2} & l_{1,4} & l_{1,5} \\
			l_{2,2} & l_{2,3} & l_{2,5} & l_{2,6} \\
			l_{3,5} & l_{3,6} & l_{3,8} & l_{3,9} \\
			l_{4,4} & l_{4,5} & l_{4,7} & l_{4,8} \\
		\end{bmatrix}
	\end{split}
	, \quad
	\vec{\gamma} =   \begin{bmatrix}
		l_1    \\
		l_2    \\
		\vdots \\
		l_9
	\end{bmatrix}                          \\
	\begin{split}
		\mtx{F_{e}} &=	\begin{bmatrix}
			\vec{x_{1,1}} & \vec{x_{1,2}} & \vec{x_{1,3}} & \vec{x_{1,4}} \\
			\vec{x_{2,1}} & \vec{x_{2,2}} & \vec{x_{2,3}} & \vec{x_{2,4}} \\
			\vec{x_{3,1}} & \vec{x_{3,2}} & \vec{x_{3,3}} & \vec{x_{3,4}} \\
			\vec{x_{4,1}} & \vec{x_{4,2}} & \vec{x_{4,3}} & \vec{x_{4,4}} \\
		\end{bmatrix}
	\end{split}
	,\quad
	\vec{\hat{F}} = 	\begin{bmatrix}
		\vec{\hat{x}_{1}} \\
		\vec{\hat{x}_{2}} \\
		\vec{\hat{x}_{3}} \\
		\vec{\hat{x}_{4}}
	\end{bmatrix}\,.\label{eq:force_imp}
\end{align}


\documentclass[t, 11pt]{beamer}
\pdfmapfile{+sansmathaccent.map}
%%% Работа с русским языком
\usepackage{cmap}
\usepackage{mathtext}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian, english]{babel}

\usetheme{Montpellier}
\usecolortheme{beaver} % Цветовая схема

%%% Работа с картинками
\usepackage{graphicx}

\usepackage{csquotes}

\hypersetup{
	colorlinks=true,
	linkcolor=blue,
	citecolor=black,
	filecolor=magenta,
	urlcolor=red
}
%% табличка
\usepackage{booktabs, caption, makecell}
\usepackage{threeparttable}

%% график нормального распределения
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}

%% доп символы
\usepackage{newunicodechar}

\newcommand\Warning{%
	\makebox[1.4em][c]{%
		\makebox[0pt][c]{\raisebox{.1em}{\small!}}%
		\makebox[0pt][c]{\color{red}\Large$\bigtriangleup$}}}%

\newunicodechar{⚠}{\Warning}

\title {Key statistical concepts}
\subtitle{}
\author{Chuvakin Sergey}
\date{\today}
\institute[<<Anthropology>>]{<<School of Advanced Studies>>}

\begin{document}

	\frame[plain]{\titlepage}

	\section{Outline}

		\begin{frame}
			\frametitle{\insertsection}
			\begin{itemize}
				\item Random variable
				\item Distribution
				\item Distribution types
				\item Central measures
				\item Dispersion
				\item Standart deviation
				\item Types of variables
				\item Population
				\item Sample
				\item law of large numbers (maybe)
				\item central limit theorem (maybe)
			\end{itemize}
		\end{frame}

	\section{Random Variable}
		\subsection{Definition}

	\begin{frame}
		\frametitle{\insertsection}
		\framesubtitle{\insertsubsection}
	Variable - \textbf{\emph{varying}} values.

	\textbf{RV} - aka  random quantity, aleatory variable, or stochastic variable - is a variable whose value is unknown or a function that assigns values to each of an experiment's outcomes.

	\vspace{1cm}

	\emph{Examples:} - tips for waiter, number of people in a line, number of insects under a bed and a lot of other examples. The idea that it's unlimited number. Everything potetntilaly could be a random variable.
	\end{frame}

	\section{Distribution}
	\subsection{Definition}
		\begin{frame}
		\frametitle{\insertsection}
		\framesubtitle{\insertsubsection}
		In statistics, a probability distribution is a mathematical description of a random variable in terms of the probabilities of it's particular possible values.

		\vspace{1cm}

		 Put it simpler - distribution - possible values of random variable.

		 \vspace{1cm}

		NB: It's a function, therefore there are input and output.
	\end{frame}

	\subsection{Types}
	\begin{frame}
		\frametitle{\insertsection}
		\framesubtitle{\insertsubsection}

		\href{https://seeing-theory.brown.edu/probability-distributions}{Tap here!} - interactive types of various distributions!

		\vspace{1cm}

		Let us see it together!

		What worth noticing:
		\begin{enumerate}
		\item it can be descrite and continious
		\item each has extra parameters
		\item shape varies
		\item some combinations of parameters of different distributions looks alike!
	 \end{enumerate}
	\end{frame}

	\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}

	Exercise - try to guess the following!

	\begin{enumerate}
		\item meaning of (at least some of) parameters
		\item difference between descrete and continious
		\item what is probability mass (density) function (PDF) $f(x)$
		\item what if cumulative distribution function (CDF) $F(x)$
	\end{enumerate}

	\vspace{1cm}

	Do not be upset if not all of above is clear!  The more important is to grasp intuition...

\end{frame}

	\pgfmathdeclarefunction{gauss}{2}{\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}}

	\section{Normal distribution}
	\subsection{Plot}
	\begin{frame}
		\frametitle{\insertsection}
		\framesubtitle{\insertsubsection}
		\begin{center}
		\begin{tikzpicture}

			\begin{axis}[no markers, domain=0:10, samples=100,
				axis lines*=left, xlabel=$X$, ylabel=axis $y$,
				height=6cm, width=10cm,
				xticklabels={Test A,$99\%$,$95\%$,$68\%$, $\mu$, $\sigma$,$2\sigma$,$3\sigma$}, ytick=\empty,
				enlargelimits=false, clip=false, axis on top,
				grid = major]
				\addplot [fill=cyan!20, draw=none, domain=-3:3] {gauss(0,1)} \closedcycle;
				\addplot [fill=orange!20, draw=none, domain=-3:-2] {gauss(0,1)} \closedcycle;
				\addplot [fill=orange!20, draw=none, domain=2:3] {gauss(0,1)} \closedcycle;
				\addplot [fill=blue!20, draw=none, domain=-2:-1] {gauss(0,1)} \closedcycle;
				\addplot [fill=blue!20, draw=none, domain=1:2] {gauss(0,1)} \closedcycle;
			\end{axis}
		\end{tikzpicture}

	\end{center}

	\end{frame}

	\subsection{Fomula}
	\begin{frame}
		\frametitle{\insertsection}
		\framesubtitle{\insertsubsection}
		$$P(x) = \frac{1}{{\sigma \sqrt {2\pi } }}e^{{{ - \left( {x - \mu } \right)^2 } \mathord{\left/ {\vphantom {{ - \left( {x - \mu } \right)^2 } {2\sigma ^2 }}} \right. \kern-\nulldelimiterspace} {2\sigma ^2 }}}$$
		\begin{itemize}
			\item $P(x)$ aka $y$
			\item $\sigma$ - standart deviation
			\item $\mu$ - mean aka Expected value $E(x)$
			\item $e$ - e number (2.7\texttildelow)
			\item $\pi$ Pi number (3.14\texttildelow)
			\item $x$ - value from random variable
			\end{itemize}

	\vspace{0.5cm}

	\emph{Intuition behind - probability of $x$ assumed it distributed normally.}
	\end{frame}

	\section{Back to variables}
	\subsection{Examples in sociology and anthropology}
	\begin{frame}
		\frametitle{\insertsection}
		\framesubtitle{\insertsubsection}
	RV - frequently used as quality (or feature) of person or some phenomena.

	Examples of pseudo normal distribution:

	\begin{itemize}
		\item Age
		\item Heigh
		\item Salary
		\item Number of robberies in a country
		\item Number of votes  during elections
		\item Number of cigarettes smoked
		%item Favorite color
		%\item Gender
		%\item Race
	\end{itemize}

	\end{frame}

\section{Formal Statistics}
\subsection{central tendency}
\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}

	\begin{itemize}
		\item Mean
		\item Mode
		\item Median
	\end{itemize}

%U+2757
\Warning  In trully normal distrubution Mean  $\simeq$  Mode $\simeq$  Median

\end{frame}

\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}
	The mean of a distribution is the arithmetic mean, or the <<average>>

	$${\displaystyle A={\frac {1}{n}}\sum _{i=1}^{n}a_{i}={\frac {a_{1}+a_{2}+\cdots +a_{n}}{n}}}$$

	$$\mu(X) = \frac{\sum_{i=1}^{n}x^{i}}{n}$$

\end{frame}

\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}

	The median is the value separating the higher half of sample,a population, or a probability distribution, from the lower half.
	\begin{enumerate}
	\item The median is the “middle” value of a [ordered] data set.
	\item Let there be a variable v1: 20,7,23,17,21,5,19,3,11
	\item To compute the median of v1, sort the variable into ascending order: 3,5,7,11,17,19,20,21,23
	\item Pick one in center (17)
	\end{enumerate}

	\end{frame}

\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}

	The mode is the value that appears most often in a set of data
	\begin{enumerate}
	\item Consider data 2,5,7,6,7,9,2,0,5,3,3,7,7,8.
	\item The mode is 7
	\item What about 3,7,4,2,3,1,0,7,9,6,3,7,4,11?
	\item The mode of a continuous probability distribution is the value x at which its probability density function has its maximum value
	\item The mode is at the peak of the distribution
	\end{enumerate}

\end{frame}

\pgfmathdeclarefunction{gauss1}{3}{\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}}

\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}
	\begin{center}
\begin{tikzpicture}

	\begin{axis}[
		no markers
		, domain=-7.5:25.5
		, samples=100
		, ymin=0
		, axis lines*=left
		, xlabel=
		, every axis y label/.style={at=(current axis.above origin),anchor=south}
		, every axis x label/.style={at=(current axis.right of origin),anchor=west}
		, height=5cm
		, width=13cm
		, xtick=\empty
		, ytick=\empty
		, enlargelimits=false
		, clip=false
		, axis on top
		, grid = major
		, hide y axis
		, hide x axis
		]

		%\draw [help lines] (axis cs:-3.5, -0.4) grid (axis cs:3.5, 0.5);

		% Normal Distribution 1
		\addplot[blue, ultra thick,restrict x to domain=-6:6] {gauss1(x, 0, 1.75)};
		\pgfmathsetmacro\valueA{gauss1(0, 0, 1.75)}
		\draw [dashed, thick, blue] (axis cs:0, 0) -- (axis cs:0, \valueA);
		\node[below] at (axis cs:0, -0.02)  {\Large \textcolor{blue}{$\mu_{1}$}};
		\draw[thick, blue] (axis cs:-0.0, -0.01) -- (axis cs:0.0, 0.01);

		% Normal Distribution 2
		\addplot[green, ultra thick,restrict x to domain=3:15] {gauss1(x, 9, 1.75)};
		\draw [dashed, thick, green] (axis cs:9, 0) -- (axis cs:9, \valueA);
		\node[below] at (axis cs:9, -0.02)  {\Large \textcolor{green}{$\mu_{2}$}};
		\draw[thick, green] (axis cs:9, -0.01) -- (axis cs:9, 0.01);

		% Normal Distribution 3
		\addplot[red, ultra thick,restrict x to domain=12:24] {gauss1(x, 18, 1.75)};
		\draw [dashed, thick, red] (axis cs:18, 0) -- (axis cs:18, \valueA);
		\node[below] at (axis cs:18, -0.02)  {\Large \textcolor{red}{$\mu_{3}$}};
		\draw[thick, red] (axis cs:18, -0.01) -- (axis cs:18, 0.01);

	\end{axis}

\end{tikzpicture}
	\end{center}
\end{frame}

\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}

\Warning 1 Guess why median is more representative one?

\vspace{1cm}

\Warning 2 What is the synonym for representative?

\end{frame}

\section{Dispersion and std}
\subsection{Formula}
\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}
Range is the difference between the smallest and the largest observation in the sample.

\begin{itemize}
	\item Variance is the average of all squared deviations from the mean:
	$$\sigma^2 = \frac{\sum^{n}_{i=1} (x_i - \mu(X))^2}{n}$$
 	\item The larger this value, the greater the dispersion of the observations around the mean value, the more heterogeneous sample (the less informative mean).
 	\item The standard deviation (denoted as $\sigma$ or $s$) is the square root of the variance
\end{itemize}
\end{frame}

\section{Variable types}
\subsection{list}

\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}

	\begin{enumerate}
		\item \tikz\draw[red,fill=red] (0,0) circle (.5ex); continious $(-\infty:+\infty)$
		\item \tikz\draw[blue,fill=blue] (0,0) circle (.5ex); nominal (colors)
		\item \tikz\draw[green,fill=green] (0,0) circle (.5ex); ordered (ranks in the army)
	\end{enumerate}

\end{frame}

\subsection{ Examples}

\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}

	\tikz\draw[red,fill=red] (0,0) circle (.5ex); Continious:
	\begin{enumerate}
		\item Age of person
		\item Salaries in a company
	\end{enumerate}
	\tikz\draw[blue,fill=blue] (0,0) circle (.5ex); Nominal:
	\begin{enumerate}
		\item Religion of person
		\item Prefered candidate at elections
		\item Gender
	\end{enumerate}

	\tikz\draw[green,fill=green] (0,0) circle (.5ex); Ordered:
	\begin{enumerate}
		\item Number of smoked sigaretes
		\item Number of children in a family
	\end{enumerate}

\end{frame}

\subsection{Notions}

\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}

	\tikz\draw[red,fill=red] (0,0) circle (.5ex); Continious - takes any real number - it can be normally distributed or somehow else.

	\vspace{1cm}

	\tikz\draw[blue,fill=blue] (0,0) circle (.5ex); Nominal - always descrete. The only thing can be done upon this - count unique values.  The values \emph{can not be} compared!

	\vspace{1cm}

	\tikz\draw[green,fill=green] (0,0) circle (.5ex); Ordered - unlike nominal scal it can be compared, but we do not know the granularity of difference. Descrete as well!

\end{frame}

\section{Population and  Sample}
\subsection{Formula}
\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}
\textbf{Popuation} - theoretical measure of your object of research.

\vspace{1cm}

\textbf{Sample} - Real number of observations

\vspace{1cm}

\textbf{Representetivness} - How sample reflects quality of population

\end{frame}

\section{Important Laws}

\subsection{Law of large numbers}
\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}

	The law of large numbers, in probability and statistics, states that as a sample size grows, its mean gets closer to the average of the whole population

\end{frame}

\subsection{Central Limit Theorem}
\begin{frame}
	\frametitle{\insertsection}
	\framesubtitle{\insertsubsection}

	The central limit theorem states that if you have a population with mean $\mu$ and standard deviation $\sigma$and take sufficiently large random samples from the population with replacement, then the distribution of the sample means will be approximately normally distribute

\end{frame}

%TODO: sample, population, types of variables

\end{document}


\documentclass[11pt]{article}
\usepackage{geometry}
\geometry{a4paper,top=2cm,bottom=2cm,left=2cm,right=2cm}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{lineno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage {tikz}
\usepackage{tikz-cd}
\usetikzlibrary {positioning}
\usepackage {xcolor}
\usepackage{titlesec}
\usepackage{varwidth}

\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother

\title{\textbf{Algorithm Design - Homework 2} \\ \bigskip \large \textbf{Sapienza University of Rome}}
\date{\textbf{\today}}
\author{\textbf{Marco Costa, 1691388}}
\pagestyle{fancy}
\fancyhead[L]{Marco Costa, 1691388}
\fancyhead[R]{Algorithm Design - Homework 2}

%section, subsection: space - left, before, after
\titlespacing{\section}{0em}{0em}{0em}
\titlespacing{\subsection}{0em}{0.5em}{0em}
\titlespacing{\subsubsection}{0em}{0.5em}{0em}
\setlength\parindent{0pt}

\begin{document}
\maketitle
\newpage

\section*{Exercise 1}
\subsection*{First Problem}
We need to model Michele's problem as a integer linear problem, and relax this to a corresponding LP.
\subsubsection*{Solution}
The problem can be modeled as an \textit{ILP} as follow: \\
\(\left \{ \begin{array}{l}
minimize \quad \sum\limits_{i \in F} \sum\limits_{j \in O}x_{ij}w(i,j)\\
s.t. \qquad \qquad \sum\limits_{j \in O}x_{ij} = 1 , \forall{i \in F}\\
\qquad \qquad \qquad \sum\limits_{i \in F}x_{ij} \leq 1 , \forall{j \in O}\\
\qquad \qquad \qquad x_{ij} \in{\{0,1\}}
\end{array}
\right. \)\\
For the relaxation of this problem to a LP problem, we need simply to change the last condition in $x_{ij} \in [0, 1]$ ($0 \leq x_{ij} \leq 1$).
\subsection*{Second Problem}
Give a polynomial-time algorithm that, from any
given optimal LP-solution, computes an optimal integer assignment, knowing that there is no \textit{integrality gap} and for every fractional LP-solution, there exists an integral
feasible solution with the same cost.
\subsubsection*{Solution}
Let's assume that $\hat{x}$ is an optimal solution for the LP. If, for each $x_{ij} \in \hat{x}$, we have that $x_{ij} \in \{0,1\}$, then $\hat{x}$ is also an optimal solution for the ILP. \\
 But, if $\exists \; x_{ij} \in [0,1]$ then $\hat{x}$ is fractional so it is not an optimal solution
for the ILP problem. \\
 Now, consider the subgraph $H \in G$ (where $G$ is the graph composed by the matching of the two sets $F$
and $O$) comprising all the fractional values $x_{ij} \in \hat{x}$ (so $H$ will be a graph whose edges are the ones with fractional weights deriving from $\hat{x}$). \\
Now, either $H$ is a cycle or it is a path whose source and sink vertices have all incident edges
$e_{ij} \in G.edges$ with $x_{ij} = 0$ except for one that has weight less then 1. In order to prove this, each edge that belongs to
$H$ has a fractional weight by definition. Let $(v_1, v_2) \in H$ be the first edge of a path, obviously we have $ 0 < x_{ij} < 1$.
All the other incident edges of $v_1$ that are not in $H$ cannot have $x_{ij} = 1$ (otherwise the constraints will be violated) or
$0 < x_{ij} < 1$ (otherwise they will be in H), so for all this edges we will have $x_{ij} = 0$. Now, consider a graph $H$ defined as before. We can define the following value at the beginning of each step of the algorithm:
\begin{equation}
\epsilon = \min_{\{i,j\} \in H} (x_{ij}, 1-x_{ij})
\end{equation}
At each step of the algorithm, for each $x_ij \in \bar{x}$ we compute the two following updates:
\begin{equation}
x_{ij}^{'} = \begin{cases}
x_{ij} - \epsilon, & \mbox{if } e_{ij} \mbox{ has odd idx in G.edges} \land e_{ij} \in H.edges \\
x_{ij} + \epsilon, & \mbox{if } e_{ij} \mbox{ has even idx in G.edges} \land e_{ij} \in H.edges\\
x_{ij} , &\mbox {if } e_{ij} \notin H.\mbox{edges}\end{cases}
\end{equation}
\begin{equation}
x_{ij}^{''} = \begin{cases}
x_{ij} - \epsilon, & \mbox{if } e_{ij} \mbox{ has odd idx in G.edges} \land e_{ij} \in H.edges \\
x_{ij} + \epsilon, & \mbox{if } e_{ij} \mbox{ has even idx in G.edges} \land e_{ij} \in H.edges\\
x_{ij} , &\mbox {if } e_{ij} \notin H.\mbox{edges}\end{cases}
\end{equation}
We define $x'$ as the solution whose elements are $x_{ij}^{'}$ and $x''$ the solution whose elements are $x_{ij}^{''}$. At each step we perform the two updates over the solution with the highest number of integer values. The number of steps required to obtain an integral solution is $O(n)$ where $n$ is the number of fractional solutions in the initial optimal solution $\hat{x}$ of the LP. The most important thing is that, for every intermediate solution computed (so $x'$ and $x''$) the value of the objective function doesn't change, so also at the end of the algorithm it will be the same as the beginning.

\newpage

\section*{Exercise 2}
\subsection*{First Problem}
We need to show that $\mathop{\mathbb{E}}[|B'|] \le 2|OPT|$.
\subsubsection*{Solution}
Let's define two variables $X_i$ a d $Y_i$, the first is set to 1 if the algorithm adds a vertex belonging to OPT and to 0 otherwise, while the second is set to 1 if the algorithm adds a vertex not belonging to OPT and to 0 otherwise. Let's define also $X = \sum\limits_{i}X_i$ and $Y = \sum\limits_{i}Y_i$. \\
In this way we have that $|B'| = X + Y$ and $X \le |OPT|$. \\
Now let's consider this: if an edge $e$ is already covered, we have $X_i = Y_i = 0$, if both vertices of $e$ belong to OPT, then $X_i = 1$ and $Y_i = 0$, and $Pr[X_i] = Pr[Y_i] = \frac{1}{2}$ otherwise. \\
So we can see that $Pr[Y_i] \le Pr[X_i]$, and it means that $\mathop{\mathbb{E}}[|Y|] \le \mathop{\mathbb{E}}[|X|]$. \\
Finally we have $\mathop{\mathbb{E}}[|B'|] = \mathop{\mathbb{E}}[|X + Y|] = \mathop{\mathbb{E}}[|X|] + \mathop{\mathbb{E}}[|Y|] \le 2\mathop{\mathbb{E}}[|X|] \le 2|OPT|$, so $\mathop{\mathbb{E}}[|B'|] \le 2|OPT|$.

\subsection*{Second Problem}
We need to show that for every constant $c \ge 1$, the algorithm might produce a $B'$ with $|B'| \ge c|OP T|$.
\subsubsection*{Solution}
Given a star graph of $c + 1$ vertices we have that the optimal solution is to choose the center ($|OPT| = 1$). Now suppose that for each edge the algorithm chooses the other vertex (that is not the center). In this way the algorithm chooses $c$ different vertices, so $|B'| = c|OPT|$. \\
Since it is the worst case, we have that $|B'| \le c|OPT|$.

\subsection*{Third Problem}
We need to say why there is not much hope of deriving an efficient, deterministic
version using the method of conditional expectation.
\subsubsection*{Solution}
In order to apply the condition expectation to have a deterministic algorithm, we can do as follow: \\
When the edge $e$ is not covered and we need to add one of its endpoints, we can analyze how each of the two endpoints impacts the expectation value of the solution $E[|B'|]$. I define a variable $Y=(v_1,v_2,...)$ for each chosen edge $e$: it's equal to the vertex chosen.\\
Let's suppose that $i$ edges are already covered and $j$ vertices already added in $B'$. Now we have an edge $e=(u,v)$ to cover and we want to add what minimizes the expected $|B'| = S$:
\begin{center}
	$E[|B'||y_1=v_1,...,y_i=v_j]=\frac{1}{2}E[|B'||y_1=v_1,...,y_i=v_j\land Y_{i+1}=u]+\frac{1}{2}E[|B'||y_1=v_1,...,y_i=v_j\land Y_{i+1}=v]$
\end{center}
Now we can compute $E[|B'||y_1=v_1,...,y_i=v_j\land Y_{i+1}=v_{j+1}]$ as $j + 1$ + all the vertices needed to cover the remaining edges. To compute the number of these uncovered edges, we can consider the already covered edges, the new added vertex and all his outgoing edges not covered:\\
$E-\{e_1,...,e_i\}-\{e$ | $e$ is outgoing vertex of $v_{j+1}\land y_e=0\}$\\
The issue, that makes not efficient deterministic problem, is the difficulty and hard computation to find number of vertices needed to cover the uncovered edges.

\newpage

\section*{Exercise 3}
\subsection*{Problem}
Given $\alpha \ge 0$ calculate Philip’s payoff at some mixed Nash equilibrium, for $\alpha < 1$ and $\alpha \ge 1$.
\subsubsection*{Solution for $\mathbf{\alpha < 1}$}
Let's define as $q_r$ the probability that the opponent plays R, $q_p$ the probability that the opponent plays P and $q_s = 1 - q_r - q_p$ the probability that the opponent plays S. Now we compute Philip's expected payoffs:
\begin{itemize}
	\item Philip's expected payoff playing R: $\alpha \cdot q_r + (\alpha - 1) \cdot q_p + (\alpha + 1) \cdot (1 - q_r - q_p)$
	\item Philip's expected payoff playing P: $1 \cdot q_r + 0 \cdot q_p -1 \cdot (1 - q_r - q_p) = 2q_r + q_p - 1$
	\item Philip's expected payoff playing S: $-1 \cdot q_r + 1 \cdot q_p + 0 \cdot (1 - q_r - q_p) = -q_r + q_p$
\end{itemize}
Since the strategy must be best responses, the payoffs must be equal, and we obtain: \\
\begin{minipage}[t]{0.63\textwidth}
\(\left \{ \begin{array}{l}
\alpha \cdot q_r + (\alpha - 1) \cdot q_p + (\alpha + 1) \cdot (1 - q_r - q_p) = 2q_r + q_p - 1\\
\alpha \cdot q_r + (\alpha - 1) \cdot q_p + (\alpha + 1) \cdot (1 - q_r - q_p) = -q_r + q_p\\
2q_r + q_p - 1 = -q_r + q_p
\end{array}
\right. \)
\end{minipage}
\begin{minipage}[t]{0.07\textwidth}
	\raisebox{-.5\height}{\scalebox{2}{$\Rightarrow$}}
\end{minipage}
\begin{minipage}[t]{0.3\textwidth}
	\(\left \{ \begin{array}{l}
		q_r = \frac{1}{3} \\
		q_p = \frac{\alpha + 1}{3} \\
		q_s = 1 - q_r - q_p = \frac{1 - \alpha}{3}
	\end{array}
	\right. \)
\end{minipage} \\
Since Philip is mixing in a Nash Equilibrium, the opponent must mix with weights \(\left(\frac{1}{3},\frac{\alpha + 1}{3},\frac{1 - \alpha}{3}\right) \).\\
Now let's do the same for opponent's expected payoffs, defining as $q'_r$, $q'_p$ and $q'_s = 1 - q'_r - q'_p$ the probability that Philip plays R, P or S respectively:
\begin{itemize}
	\item Opponent expected payoff playing R: $0 \cdot q'_r - 1 \cdot q'_p + 1 \cdot (1 - q'_r - q'_p) = -2q'_p - q'_r + 1$
	\item Opponent expected payoff playing S: $1 \cdot q'_r + 0 \cdot q'_p - 1 \cdot (1 - q'_r - q'_p) = 2q'_r + q'_p - 1$
	\item Opponent expected payoff playing P: $-1 \cdot q'_r + 1 \cdot q'_p + 0 \cdot (1 - q'_r - q'_p) = -q'_r + q'_p$
\end{itemize}
Since the strategy must be best responses, the payoffs must be equal, and we obtain: \\
\begin{minipage}[t]{0.4\textwidth}
	\(\left \{ \begin{array}{l}
	-2q'_p - q'_r + 1 = 2q'_r + q'_p - 1 \\
	-2q'_p - q'_r + 1 = -q'_r + q'_p \\
	-2q'_r + q'_p - 1 = -q'_r + q'_p
	\end{array}
	\right. \)
\end{minipage}
\begin{minipage}[t]{0.07\textwidth}
\raisebox{-.5\height}{\scalebox{2}{$\Rightarrow$}}
\end{minipage}
\begin{minipage}[t]{0.3\textwidth}
\(\left \{ \begin{array}{l}
q'_r = \frac{1}{3} \\
q'_p = \frac{1}{3} \\
q'_s = 1 - q_r - q_p = \frac{1}{3}
\end{array}
\right. \)
\end{minipage} \\
Since the opponent is mixing in a Nash Equilibrium, Philip must mix with weights \(\left(\frac{1}{3},\frac{1}{3},\frac{1}{3}\right) \).\\
So the MNE is:
\(\left[\left(\frac{1}{3},\frac{1}{3},\frac{1}{3}\right),\left(\frac{1}{3},\frac{\alpha + 1}{3},\frac{1 - \alpha}{3}\right) \right] \).\\
Finally we can calculate Philip's payoff as follow: \\
$\alpha \cdot q_r \cdot q'_r + (\alpha - 1) \cdot q_p \cdot q'_r + (\alpha + 1) \cdot q_s \cdot q'_r + 1 \cdot q_r \cdot q'_p + 0 \cdot q_p \cdot q'_p + (-1) \cdot q_s \cdot q'_p + (-1) \cdot q_r \cdot q'_s + 1 \cdot q_p \cdot q'_s + 0 \cdot q_s \cdot q'_s = \frac{\alpha}{3}$

\subsubsection*{Solution for $\mathbf{\alpha \ge 1}$}
\begin{minipage}[c]{10cm}
	In this case, looking at the table it's possible to see that simplifications can be made: for Philip, P is dominated by R because of $\alpha \ge 1$, so we can delete the relative row. After that, for the opponent S is dominated by R, so we can delete the relative column. \\
\end{minipage}
\begin{tabular}{ |c|c|c|c| }
\hline
Ph/Op & R & P & S \\
\hline
R &  $\alpha$, 0  &  $(\alpha-1)$, 1 &  $(\alpha+1)$, -1 \\
\hline
P &  1, -1  &  0 , 0 &  -1 , 1 \\
\hline
S &  -1, 1  &  1 , -1 &  0 , 0 \\
\hline
\end{tabular}
Let's define as $q_r$ and $q_p = 1 - q_r$ the probability that the opponent plays R or P respectively, while as $q'_r$ and $q'_s = 1 - q'_r$ the probability that Philip plays R or S respectively. \\
We have the following payoffs:
\begin{tabular}{ |c|c|c| }
	\hline
	 & Philip & Opponent \\
	\hline
	R &  $\alpha \cdot q_r + (\alpha - 1) \cdot (1 - q_r) = q_r + \alpha - 1$  &  $0 \cdot q'_r + 1 \cdot (1 - q'_r) = 1 - q'_r$  \\
	\hline
	P &  none  & $1 \cdot q'_r -1 \cdot (1 - q'_r) = 2q'_r - 1$ \\
	\hline
	S &  $-1 \cdot q_r + 1 \cdot (1 - q_r) = -2q_r + 1$  &  none  \\
	\hline
\end{tabular}
Since the strategy must be best responses, the payoffs of each player must be equal, and we obtain:  $q_r = \frac{2-\alpha}{3}$, $q_p = \frac{\alpha + 1}{3}$, $q'_r = \frac{2}{3}$ and $q'_s = \frac{1}{3}$. \\
So the MNE is:
\(\left[\left(\frac{2}{3},\frac{1}{3}\right),\left(\frac{2-\alpha}{3},\frac{\alpha + 1}{3}\right) \right] \).\\
Finally we can calculate Philip's payoff as follow: \\
$\alpha \cdot q_r \cdot q'_r + (\alpha - 1) \cdot q_p \cdot q'_r + (-1) \cdot q_r \cdot q'_s + 1 \cdot q_p q'_s = \frac{2\alpha-1}{3}$.

\newpage

\section*{Exercise 4}
\subsection*{Problem}
Given $n$, the number of students, and assuming that each student $a_i$ and $b_i$
is
uniformly distributed in $[0, 1]$, show that there are $\mathbf{O}(\log n)$ students worthy of an award, with
high probability.
\subsubsection*{Solution}
We can order the students according to $a_i$ in descending order. \\
The first student will get the award for sure, since he has the highest $a_i$. \\
The other students will get the award if and only if $b_i > b_1$. \\
Now let's define with $X_i \in {0, 1}$ the variable that describes if the student i gets the award, and with $X = \sum\limits_{i = 1}^n X_i$ the number of student that have a reward. \\
We have that $\mathop{\mathbb{E}}[X_i] = Pr[X_i] = \frac{1}{i}$. \\
So $\mathop{\mathbb{E}}[X] = \sum\limits_{i = 1}^n \frac{1}{i} = \ln n + \mathbf{O}(1)$. \\
Now let's apply Chernoff Bound: \\
$Pr[X > (1 + \delta)\mathop{\mathbb{E}}[X]] < e^{-\delta^2 \cdot \frac{\mu}{3}}$. \\
Choosing $\mu = \ln n$ and $\delta = \frac{1}{2}$, we have: \\
$Pr[X > (1 + \delta)\ln n] < e^{-\frac{1}{4} \cdot \frac{\mu}{3}} = \frac{1}{\sqrt[12]{e^{\ln(n)}}} = \frac{1}{\sqrt[12]{n}}$. \\
Finally, for high values of $n$ this values tents to 0, so there are $\mathbf{O}(log n)$ students that will get an award with high probability.

\newpage

\section*{Exercise 5}
\subsection*{First Problem}
We need to show that $|T1| + 2|T2| + 3|T3| = |E|(|V | − 2)$.
\subsubsection*{Solution}
Given an edge $e = (u, v)$ of the graph $G = (V, E)$, we need to build a triple choosing any vertex in the set $V \setminus \{u, v\}$
For every edge $e \in E$ there could be three cases:
\begin{itemize}
	\item $(e, w) = (u, v, w) \in T1$: count it one time;
	\item $(e, w) = (u, v, w) \in T2$: count it two times, since one time we have this triple as $(e, w) = (u, v, w)$, and another time when we have the edge $(v, w)$ and the vertex $u$ (or the edge $(u, w)$ and the vertex $v$);
	\item $(e, w) = (u, v, w) \in T3$: count it three times, for the same reason as before.
\end{itemize}
Since the number of triple generated by the algorithm is $|E|(|V|-2)$ because for every edge we test all possible $|V| - 2$ vertices, the triple in $T1$ are generated one time, in $T2$ two times and in $T3$ three times, we have that $|T1| + 2|T2| + 3|T3| = |E|(|V | − 2)$.

\subsection*{Second Problem}
We need to show that $\frac{1}{s}\sum\limits_{i = 1}^s x_i\frac{|E|(|V|-2)}{3}$ is an estimator of T3.
\subsubsection*{Solution}
The expected value of the output value $x$ of the algorithm is $\mathop{\mathbb{E}}[x] = \frac{3|T3|}{|T1| + 2|T2| + 3|T3|} = \frac{3|T3|}{|E|(|V| - 2)}$. \\
So we have $|T3| = \mathop{\mathbb{E}}[x] \cdot \frac{|E|(|V| - 2)}{3|T3|}$. \\
Now let's use $(\frac{1}{s}\sum\limits_{i = 1}^s x_i)$ as an estimator for $\mathop{\mathbb{E}}[x]$.
Finally we have that $\tilde{T3} = \frac{1}{s}\sum\limits_{i = 1}^s x_i\frac{|E|(|V|-2)}{3}$ is an estimator for $T3$.

\subsection*{Third Problem}
We need to find a nontrivial number $s$ of executions of the algorithm which are sufficient in order
obtain an $(1 + \epsilon)$ and an $(1 - \epsilon)$ approximation of T3 with probability at least $1 - \delta$.
\subsubsection*{Solution}
In other words, we need to show that we have $(1 - \epsilon)|T3| < \tilde{T3} < (1 + \epsilon)|T3|$ with probability $(1 - \delta)$. \\
Using Chernoff Bound we have: \\
\begin{itemize}
	\item \textbf{Lower tail}: $\mathbf{Pr}[\frac{1}{s}\sum\limits_{i = 1}^s x_i \le (1 - \epsilon)\mathop{\mathbb{E}}[x]] \le e^{-\frac{\mathop{\mathbb{E}}[x] \cdot \epsilon^2}{2}}$
	\item \textbf{Upper tail}: $\mathbf{Pr}[\frac{1}{s}\sum\limits_{i = 1}^s x_i \ge (1 + \epsilon)\mathop{\mathbb{E}}[x]] \le e^{-\frac{\mathop{\mathbb{E}}[x] \cdot \epsilon^2}{3}}$
\end{itemize}
For $s \ge \frac{3}{\epsilon^2} \cdot \frac{|T1| + 2|T2| + 3|T3|}{|T3|} \cdot \ln(\frac{2}{\delta})$ the sum of both probabilities is bounded by $\delta$.

\end{document}


\documentclass[../psets.tex]{subfiles}

\pagestyle{main}
\renewcommand{\leftmark}{Problem Set \thesection}
\setcounter{section}{3}

\begin{document}

\section{Interference and Diffraction}
\begin{enumerate}[label={\arabic*)}]
    \item \marginnote{8/19:}\textcite{bib:YoungFreedman}: Problem 35.9.\par
    Two slits spaced $\SI{0.450}{\milli\meter}$ apart are place $\SI{75.0}{\centi\meter}$ from a screen. What is the distance between the second and third dark lines of the interference pattern on the screen when the slits are illuminated with coherent light with a wavelength of $\SI{500}{\nano\meter}$?
    \item \textcite{bib:YoungFreedman}: Problem 35.20.\par
    Two slits spaced $\SI{0.0720}{\milli\meter}$ apart are $\SI{0.800}{\meter}$ from a screen. Coherent light of wavelength $\lambda$ passes through the two slits. In their interference pattern on the screen, the distance from the center of the central maximum to the first minimum is $\SI{3.00}{\milli\meter}$. If the intensity at the peak of the central maximum is $\SI{0.0600}{\watt\per\square\meter}$, what is the intensity at points on the screen that are
    \begin{enumerate}
        \item $\SI{2.00}{\milli\meter}$ from the center of the central maximum;
        \item $\SI{1.50}{\milli\meter}$ from the center of the central maximum?
    \end{enumerate}
    \item \textcite{bib:YoungFreedman}: Problem 35.39.\par
    Suppose you illuminate two thin slits by monochromatic coherent light in air and find that they produce their first interference \emph{minima} at $\pm\ang{35.20}$ on either side of the central bright spot. You then immerse these slits in a transparent liquid and illuminate them with the same light. Now you find that the first minima occur at $\pm\ang{19.46}$ instead. What is the index of refraction of this liquid?
    \item \textcite{bib:YoungFreedman}: Problem 35.41.\par
    Two radio antennae radiating in phase are located at points $A$ and $B$, $\SI{200}{\meter}$ apart (see the following figure). The radio waves have a frequency of $\SI{5.80}{\mega\hertz}$. A radio receiver is moved out from point $B$ along a line perpendicular to the line connecting $A$ and $B$ (line $BC$ shown in the following figure). At what distances from $B$ will there be \emph{destructive} interference? (Note: The distance of the receiver from the sources is not large in comparison to the separation of the sources.)
    \begin{center}
        \begin{tikzpicture}
            \footnotesize
            \draw (-1,0) -- (3,0) node[right]{$C$};
            \draw (0,-1) -- (0,2);

            \node [circle,fill=ory,draw,label={above left:$A$}] at (0,1.2) {};
            \node [circle,fill=ory,draw,label={below left:$B$}] at (0,0) {};

            \draw [very thin,<-|,shorten <=1pt] (-0.45,0) -- node[fill=white,inner sep=1.5pt]{$\SI{200}{\meter}$} ++(0,1.2);
        \end{tikzpicture}
    \end{center}
    \item \textcite{bib:YoungFreedman}: Problem 35.45.\par
    White light reflects at normal incidence from the top and bottom surfaces of a glass plate ($n=1.52$). There is air above and below the plate. Constructive interference is observed for light whose wavelength in air is $\SI{477.0}{\nano\meter}$. What is the thickness of the plate if the next longer wavelength for which there is constructive interference is $\SI{540.6}{\nano\meter}$?
    \item \textcite{bib:YoungFreedman}: Problem 36.1.\par
    Monochromatic light from a distant source is incident on a slit $\SI{0.750}{\milli\meter}$ wide. On a screen $\SI{2.00}{\meter}$ away, the distance from the central maximum of the diffraction pattern to the first minimum is measured to be $\SI{1.35}{\milli\meter}$. Calculate the wavelength of the light.
    \pagebreak
    \item \textcite{bib:YoungFreedman}: Problem 36.14.\par
    Monochromatic light of wavelength $\lambda=\SI{620}{\nano\meter}$ from a distant source passes through a slit $\SI{0.450}{\milli\meter}$ wide. The diffraction pattern is observed on a screen $\SI{3.00}{\meter}$ from the slit. In terms of the intensity $I_0$ at the peak of the central maximum, what is the intensity of the light at the screen the following distances from the center of the central maximum:
    \begin{enumerate}
        \item $\SI{1.00}{\milli\meter}$.
        \item $\SI{3.00}{\milli\meter}$.
        \item $\SI{5.00}{\milli\meter}$.
    \end{enumerate}
    \item \textcite{bib:YoungFreedman}: Problem 36.26.\par
    Monochromatic light is at normal incidence on a plane transmission grating. The first-order maximum in the interference pattern is at an angle of $\ang{11.3}$. What is the angular position of the fourth-order maximum?
    \item In an experiment, light of wavelength $\lambda$ falls on three slits evenly spaced a distance $d$ apart, and an interference pattern is observed on a distant screen. If the intensity at $\ang{0}$ with two adjacent slits open (and the third slit covered) is $I_2$, what is the intensity at $\ang{0}$ when all three slits are open, $I_3$?
\end{enumerate}

\end{document}