\documentclass[a4paper,man,natbib]{apa6}
\usepackage[english]{babel}

\usepackage[cache=false]{minted}
\usemintedstyle{vs}
\usepackage{xcolor}
\definecolor{bg}{rgb}{.95,.95,.95}

\graphicspath{ {./images/} }
\usepackage{graphicx}
\usepackage{caption}

\usepackage{setspace}
\usepackage{amsmath}

\title{Advanced Statistical Methods Homework 8 \\ Support Vector Machine}
\shorttitle{DAT 530 HW7}
\author{Brandon Hosley}
\date{\today}
\affiliation{University of Illinois - Springfield}
%\abstract{}

\begin{document}
\maketitle
\singlespacing

\section{Intro to the Algorithm}

Support Vector Machines are a type of classification algorithm that is most commonly used for binary classification problems. Classification is performed by calculating a boundary to act as a decision line. Typically the boundary is optimized by calculating it to be as far from the sample points as possible.

\subsection{Intuition}

The boundary can be thought of as a hyperplane of one dimension less than the number of factors being used. A dataset with two factors may be represented as a two-dimensional graph, the classifier will be a one-dimensional hyperplane (a line) dividing the data, and the classifier will optimized to be a far from each cluster as possible.

The maximum margin can be achieved by plotting the hyperplane in a way such that at least three of the closest points to the line are equidistant; with at least one point coming from each class. In the case of overlapping classes or classes too close and too dense the hyperplane is calculated such that a fixed margin will contain the fewest possible points.

\begin{center}
	\includegraphics[width=0.5\linewidth]{Margins}
\end{center}

In the case of a linear classifier of the classic $y=wx + b$ notation we get the following equation. $\lambda$ will represent the size of the margin.

\vspace{1em}
$ \left[ \frac{1}{n} \sum_{n}^{i=1} \text{max} (0,1-y_i(w \cdot x_i-b)) \right] + \lambda \|w\|^2 $
\vspace{1em}

\subsection{e1071}

The library used for this project will be e1071, which includes an SVM module. The type of SVM trained by e1071 is one in which the final model is a voting ensemble of $k(k-1)/2$ binary classifiers rather than a $k-1$ dimensional hyperplane. The ensemble method likely generalizes better as a library and is likely more robust under a large variety of user abilities and knowledge levels.

\clearpage

\section{Applying the Algorithm to Boston}
\subsection{Description of the Problem}

The \textcolor{red}{Boston} data set has been a staple of this course. As we have gained a significant familiarity with the dataset it seems like a good option for exercising SVM use. A primary consideration when choosing a dataset for demonstrating SVMs is the limitation of input and output data. Input data should be quantitative and may be either continuous or discrete. The output is binary.

A common use of the \textcolor{red}{Boston} dataset, and what we will use it for in this assignment is using other attributes to predict crime in certain districts of the city. The data provided in \textcolor{red}{Boston} is Quantitative with the exception of 'chas' which is a binary variable representing whether or not the district borders the Charles River. It is provided as a dummy variable; for this exercise we will not be using it.

\subsection{Summary of the Dataset and Preliminaries}

Boston contains data gathered from a Census of the city of Boston Massachusetts taken in 1978. First we will load it into memory, load the e1071 library, and set a seed for repeatability.

\begin{minted}[bgcolor=bg]{r}
library(MASS)
library(e1071)
set.seed(1234)
\end{minted}

\subsection{Training an SVM Model}

To begin we will make a copy of our data for preparation, remove the 'chas' variable, and normalize the data such that all variables will have a mean equal to zero and a standard deviation of one.

\begin{minted}[bgcolor=bg]{r}
b = Boston
# Remove Chas variable
b <- subset(b,select=-c(chas))
# Normalize the Data (mean=0, SD = 1)
b <- as.data.frame(scale(b))
\end{minted}

Next we will need to change the Crime statistic to be a factor, in this case we will only be predicting whether an area will be 'High Crime' or 'Low Crime' which specifically means whether the district will be in the upper 50\% of crime or in the lower.

\begin{minted}[bgcolor=bg]{r}
# Crim as a Factor(High = 1, Low = 0)
b$crim <- ifelse(b$crim > 0, 1, 0)
b$crim <- as.factor(b$crim)
\end{minted}

Now we will separate the data into a training set and a test set.

\begin{minted}[bgcolor=bg]{r}
# Separate a Training and Testing Set
ind = sort(sample(nrow(b), nrow(b)*0.8))
b_train <- b[ind,]
b_test <- b[-ind,]
\end{minted}

For the sake of exploring options we will train both a linear SVM and a polynomial SVM.

\begin{minted}[bgcolor=bg]{r}
# Training both a Linear and Polynomial Model
svm_lin=svm(crim~., data=b_train, kernel ="linear", cost=1, scale=FALSE)
svm_poly=svm(crim~., data=b_train, kernel ="polynomial", cost=1,
				scale=FALSE)
\end{minted}

Let us take a look at the summaries of the models trained above.

\begin{minted}[bgcolor=bg]{r}
summary(svm_lin)
\end{minted}

\vspace{-0.5em}

\begin{minted}{bash}
Call:
svm(formula = crim ~ ., data = b_train, kernel = "linear",
              cost = 1, scale = FALSE)

Parameters:
    SVM-Type:  C-classification
  SVM-Kernel:  linear
        cost:  1
       gamma:  0.08333333

Number of Support Vectors:  16
( 9 7 )

Number of Classes:  2
Levels:
0 1
\end{minted}

\begin{minted}[bgcolor=bg]{r}
summary(svm_poly)
\end{minted}

\vspace{-0.5em}

\begin{minted}{bash}
Call:
svm(formula = crim ~ ., data = b_train, kernel = "polynomial",
              cost = 1, scale = FALSE)

Parameters:
    SVM-Type:  C-classification
  SVM-Kernel:  polynomial
        cost:  1
      degree:  3
       gamma:  0.08333333
      coef.0:  0

Number of Support Vectors:  38
( 24 14 )

Number of Classes:  2
Levels:
0 1
\end{minted}

\subsection{Summary of the Results}

The models both appear to have a reasonable number of support vectors.
Now we will need some predictions to test how effective the models are.

\begin{minted}[bgcolor=bg]{r}
# Calculate Predictions
pred_lin = predict(svm_lin, b_test)
pred_poly = predict(svm_poly, b_test)
\end{minted}

We can then compare these predictions to the ground truth of the test set.

\begin{minted}[bgcolor=bg]{r}
table(predict=pred_lin, truth=b_test$crim)
\end{minted}

\begin{minted}{bash}
       truth
predict  0  1
      0 77  0
      1  1 24
\end{minted}

\begin{minted}[bgcolor=bg]{r}
table(predict=pred_poly, truth=b_test$crim)
\end{minted}

\begin{minted}{bash}
       truth
predict  0  1
      0 77  0
      1  1 24
\end{minted}

The models performance is identical. In this case with all other hyper-parameters being equal the linear kernel SVM is a better choice. Linear models are simpler than Polynomials; in this case the linear model requires less than half as many support vectors; and in the end, the linear model and the polynomial model make the same mistake.

\end{document}

\begin{minted}[bgcolor=bg]{r}
\end{minted}

2020-Fall Advanced Statistical Methods/HW 08/HW 08.2_Hosley.tex


\documentclass[12pt, titlepage]{article}

\usepackage{amsmath, mathtools}

\usepackage[round]{natbib}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{colortbl}
\usepackage{xr}
\usepackage{hyperref}
\usepackage{longtable}
\usepackage{xfrac}
\usepackage{tabularx}
\usepackage{float}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage[section]{placeins}
\usepackage{caption}
\usepackage{fullpage}
\usepackage[nottoc, numbib]{tocbibind}

\hypersetup{
bookmarks=true,     % show bookmarks bar?
colorlinks=true,       % false: boxed links; true: colored links
linkcolor=red,          % color of internal links (change box color with linkbordercolor)
citecolor=blue,      % color of links to bibliography
filecolor=magenta,  % color of file links
urlcolor=cyan          % color of external links
}

\usepackage{array}

%% Comments
\newif\ifcomments\commentstrue

\ifcomments
\newcommand{\authornote}[3]{\textcolor{#1}{[#3 ---#2]}}
\newcommand{\todo}[1]{\textcolor{orange}{[TODO: #1]}}
\else
\newcommand{\authornote}[3]{}
\newcommand{\todo}[1]{}
\fi

\newcommand{\wss}[1]{\authornote{blue}{SS}{#1}}
\newcommand{\bmac}[1]{\authornote{red}{BM}{#1}}
\newcommand{\sam}[1]{\authornote{magenta}{SC}{#1}}

\newcommand{\progname}{Projectile}

\begin{document}

\title{Module Interface Specification for Projectile}

\author{Samuel J. Crawford}

\date{\today}

\maketitle

\pagenumbering{roman}

\newpage

\tableofcontents

\newpage

\section{Symbols, Abbreviations and Acronyms}

See SRS Documentation at \url{https://jacquescarette.github.io/Drasil/examples/Projectile/srs/Projectile_SRS.pdf}

\pagenumbering{arabic}

\section{Introduction}

The following document details the Module Interface Specifications for the
implemented modules in a program simulating projectile motion. It is intended to
ease navigation through the program for design and maintenance purposes.

Complementary documents include the System Requirement Specifications
and Module Guide.
%The full documentation and implementation can be
%found at \sam{No manual version of Projectile? Should this link be removed or
%should there be a link?}.

% The specification is given in terms of functions, rather than sequences.  For
% instance, the predicted temperature of the water is given as a function of time
% ($\mathbb{R} \rightarrow \mathbb{R})$, not as a sequence ($\mathbb{R}^n$). This
% approach is more straightforward for the specification, but in the
% implementation stage, it will likely be necessary to introduce a
% sequence, assuming that a numerical solver is used for the system of ODEs.

\section{Notation}

The structure of the MIS for modules comes from \citet{HoffmanAndStrooper1995},
with the addition that template modules have been adapted from
\cite{GhezziEtAl2003}.  The mathematical notation comes from Chapter 3 of
\citet{HoffmanAndStrooper1995}.  For instance, the symbol := is used for a
multiple assignment statement and conditional rules follow the form $(c_1
\Rightarrow r_1 | c_2 \Rightarrow r_2 | ... | c_n \Rightarrow r_n )$.

\progname\ uses strings and real numbers. For information on these data types
(and others), see \cite{GhezziEtAl2003}, \cite{GriesAndSchneider1993}, and
\cite{HoffmanAndStrooper1995}. In addition, \progname\ uses functions, which are
defined by the data types of their inputs and outputs. Local functions are
described by giving their type signature followed by their specification.

\newpage
\section{Module Decomposition}

The following table is taken directly from the Module Guide document for this project.

\begin{table}[h!]
\centering
\begin{tabular}{p{0.3\textwidth} p{0.6\textwidth}}
\toprule
\textbf{Level 1} & \textbf{Level 2}\\
\midrule

{Hardware-Hiding} & ~ \\
\midrule

\multirow{5}{0.3\textwidth}{Behaviour-Hiding} & Input Parameters\\
& Calculations\\
& Output Format\\
% & Output Verification\\
& Control Module\\
& Specification Parameters Module\\
\midrule

\multirow{1}{0.3\textwidth}{Software Decision} & Sequence Data Structure\\
% & Plotting\\
\bottomrule

\end{tabular}
\caption{Module Hierarchy}
\label{TblMH}
\end{table}

\newpage

\section{MIS of Control Module} \label{Main}

\subsection{Module}

main

\subsection{Uses}

Param (Section~\ref{Parameters}), Calculations (Section~\ref{Calc}),
% verify\_output (Section~\ref{VerifyOutput}), plot(Section~\ref{Plot}),
Output (Section~\ref{Output})

\subsection{Syntax}

\subsubsection{Exported Access Programs}

\begin{center}
\begin{tabular}{p{2cm} p{4cm} p{4cm} p{2cm}}
\hline
\textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\
\hline
main & - & - & - \\
\hline
\end{tabular}
\end{center}

\subsection{Semantics}

\subsubsection{State Variables}

None

\subsubsection{Access Routine Semantics}

\noindent main():
\begin{itemize}
\item transition: Modify the state of Param module and the environment variables
  for the Output module by following these steps\\
\end{itemize}

\noindent Get (filenameIn: string) from user.\\
\noindent get\_input(filenameIn, Param)\\
\noindent $p_{\text{land}}$ := func\_p\_land(Param)\\
\noindent $d_{\text{offset}}$ := func\_d\_offset(Param, $p_{\text{land}}$)\\
\noindent $s$ := func\_s(Param, $d_{\text{offset}}$)\\
\noindent \#\textit{Output calculated values to a file.}\\
% \noindent verify\_output($T_w$, $T_p$, $E_w$, $E_p$, $t_\text{final}$)\\
% \noindent plot($T_w$, $T_p$, $E_w$, $E_p$, $t_\text{final}$)\\
\noindent write\_output($s$, $d_{\text{offset}}$)\\

\newpage

\section{MIS of Input Parameters Module} \label{Parameters}

The secrets of this module are the data structure for input parameters and how
the values are input and verified.

\subsection{Module}

Param

\subsection{Uses}

SpecParam (Section~\ref{SpecParam})

\subsection{Syntax}

\begin{tabular}{p{3cm} p{2.5cm} p{1cm} >{\raggedright\arraybackslash}p{7.5cm}}
\toprule
\textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\
\midrule
get\_input & string, Param & - &  FileError \\
input\_constraints & Param & - & badSpeed, badAngle, badTargetPosition\\
$v_{\text{launch}}$ & - & $\mathbb{R}$ & -\\
$\theta$ & - & $\mathbb{R}$ & -\\
$p_{\text{target}}$ & - & $\mathbb{R}$ & -\\
\bottomrule
\end{tabular}

\subsection{Semantics}

\subsubsection{Environment Variables}

inputFile: sequence of string \#\textit{f[i] is the ith string in the text file f}

\subsubsection{State Variables}

\# To Support IM1 and IM2 \\
$v_{\text{launch}}$: $\mathbb{R}$\\
$\theta$: $\mathbb{R}$\\
\# To Support IM3 and IM4 \\
$p_{\text{target}}$: $\mathbb{R}$\\

\subsubsection{Assumptions}

\begin{itemize}

\item get\_input will be called before the values of any state variables will
be accessed or verified.

\item The file contains the string equivalents of the numeric values for
each input parameter in order, each on a new line. Any comments in the input file
should be denoted with a `\#' symbol.

\end{itemize}

\subsubsection{Access Routine Semantics}

\noindent get\_input(filename, Param):
\begin{itemize}
\item transition: The file name ``filename" is first associated with the file $f$.
The following procedural specification is followed:
\begin{enumerate}
\item Read data sequentially from $f$ to populate the state variables from
FR1 ($v_{\text{launch}}$, $\theta$, and $p_{\text{target}}$) in Param.
\item input\_constraints()
\end{enumerate}

\item exception: exc := a file name ``filename" cannot be found OR the format of
inputFile is incorrect $\Rightarrow$  FileError
\end{itemize}

\noindent input\_constraints():
\begin{itemize}
\item output: \textit{out} := none
\item exception: exc := ( \\
$\neg (0 < v_{\text{launch}}) \Rightarrow$ badSpeed $|$\\
$\neg (0 < \theta < \frac{\pi}{2}) \Rightarrow$ badAngle $|$\\
$\neg (0 < p_{\text{target}}) \Rightarrow$ badTargetPosition)
\end{itemize}

\noindent Param.$v_{\text{launch}}$:
\begin{itemize}
\item output: \textit{out} := $v_{\text{launch}}$
\item exception: none
\end{itemize}

\noindent Param.$\theta$:
\begin{itemize}
\item output: \textit{out} := $\theta$
\item exception: none
\end{itemize}

\noindent Param.$p_{\text{target}}$:
\begin{itemize}
\item output: \textit{out} := $p_{\text{target}}$
\item exception: none
\end{itemize}

\subsection{Considerations}

The value of each state variable can be accessed through its name (getter).  An
access program is available for each state variable.  There are no setters for
the state variables, since the values will be set by get\_input and
not changed for the life of the program.

See Appendix (Section~\ref{Appendix}) for the complete list of exceptions and
 associated error messages.

\newpage

\section{MIS of Calculations Module} \label{Calc}

The secret of this module is how the required values are calculated.

\subsection{Module}

Calculations

\subsection{Uses}

Param (Section~\ref{Parameters}), SpecParam (Section~\ref{SpecParam})

\subsection{Syntax}

\subsubsection{Exported Access Programs}

\begin{center}
 \begin{tabular}{p{3cm} p{3cm} p{1cm} p{8cm}}
 \hline
 \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\
 \hline
 func\_p\_land & Param & $\mathbb{R}$ & None \\
 \hline
 func\_d\_offset & Param, $\mathbb{R}$ & $\mathbb{R}$ & None \\
 \hline
 func\_s & Param, $\mathbb{R}$ & String & None \\
 \hline
 \end{tabular}
 \end{center}

\subsection{Semantics}

\subsubsection{Assumptions}

All of the fields Param have been assigned values before any of the access
 routines for this module are called.

\subsubsection{Access Routine Semantics}

func\_p\_land(Param):
 \begin{itemize}
 \item out: $\textit{out} := \frac{2 * v_{\text{launch}}^2 * sin(\theta) * cos(\theta)}{g}$
 \item exception: exc := none
 \end{itemize}

func\_d\_offset(Param, $p_{\text{land}}$):
 \begin{itemize}
 \item out: $\textit{out} := p_{\text{land}} - p_{\text{target}}$
 \item exception: exc := none
 \end{itemize}

func\_s(Param, $d_{\text{offset}}$):
 \begin{itemize}
 \item out: $\textit{out} := $ ( \\
$|\frac{d_{\text{offset}}}{p_{\text{target}}}| < \epsilon \Rightarrow$ ``The target was hit." $|$\\
$d_{\text{offset}} < 0 \Rightarrow$ ``The projectile fell short."$|$\\
$\text{True} \Rightarrow$ ``The projectile went long.")
 \item exception: exc := none
 \end{itemize}

%\newpage
%\section{MIS of Output Verification Module} \label{VerifyOutput}
%
%\subsection{Module}
%
%verify\_output
%
%\subsection{Uses}
%
%Param (Section~\ref{Parameters})
%
%\subsection{Syntax}
%
%\subsubsection{Exported Constant}
%
%ADMIS\_ER = $1 \times 10^{-6}$
%
%\subsubsection{Exported Access Programs}
%
%\begin{center}
%\begin{tabular}{p{3cm} p{7cm} p{1cm} p{2cm}}
%\hline
%\textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\
%\hline
%verify\_output & $T_W(t):\mathbb{R} \rightarrow \mathbb{R},
%                 T_P(t):\mathbb{R} \rightarrow \mathbb{R},
%                 E_W(t):\mathbb{R} \rightarrow \mathbb{R},
%                 E_P(t):\mathbb{R} \rightarrow \mathbb{R},
%                 t_\text{final}: \mathbb{R}$ & - & EWAT\_NOT\_CONSERVE, EPCM\_NOT\_CONSERVE \\
%\hline
%\end{tabular}
%\end{center}
%
%\subsection{Semantics}
%
%\subsubsection{State Variables}
%
%None
%
%\subsubsection{Assumptions}
%
%All of the fields of the input parameters structure have been assigned a
%value.
%
%\subsubsection{Access Routine Semantics}
%
%\noindent verify\_output($T_W, T_P, E_W, E_P$, $t_\text{final}$):
%\begin{itemize}
%\item exception: exc := (
%\end{itemize}
%
%\noindent $
%(\forall t | 0 \leq t \leq t_\text{final} : \text{relErr}(E_W,
%\int_{0}^{t} h_C A_C (T_C - T_W(t)) dt - \int_{0}^{t} h_P A_P (T_W(t)
%- T_P(t)) dt) < \text{ADMIS\_ER}) \Rightarrow \text{EWAT\_NOT\_CONSERVE}
%$
%
%$|$
%
%\noindent $
%(\forall t | 0 \leq t \leq t_\text{final} : \text{relErr}(E_{P}, \int_{0}^{t}
%h_{P} A_{P} (T_{W}(t) - T_{P}(t)) dt) < \text{ADMIS\_ER}) \Rightarrow
%\text{EPCM\_NOT\_CONSERVE}
%$
%)
%
%\subsubsection{Local Functions}
%
%relErr: $\mathbb{R}$ $\times$ $\mathbb{R}$ $\rightarrow$ $\mathbb{R}$ \\
%$\text{relErr}(t, e) \equiv \frac{|t - e|}{|t|}$ \\
%\newline

%
%\newpage
%\section{MIS of Plotting Module} \label{Plot}
%
%\subsection{Module}
%
%plot
%
%\subsection{Uses}
%
%N/A
%
%\subsection{Syntax}
%
%\subsubsection{Exported Access Programs}
%
%\begin{center}
%\begin{tabular}{p{2cm} p{8cm} p{2cm} p{2cm}}
%\hline
%\textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\
%\hline
%plot & $T_W(t):\mathbb{R} \rightarrow \mathbb{R},
%                 T_P(t):\mathbb{R} \rightarrow \mathbb{R},
%                 E_W(t):\mathbb{R} \rightarrow \mathbb{R},
%       E_P(t):\mathbb{R} \rightarrow \mathbb{R}$, $t_\text{final}: \mathbb{R}$ & - & - \\
%\hline
%\end{tabular}
%\end{center}
%
%\subsection{Semantics}
%
%\subsubsection{State Variables}
%
%None
%
%\subsubsection{Environment Variables}
%
%win: 2D sequence of pixels displayed on the screen\\
%
%\subsubsection{Assumptions}
%
%None
%
%\subsubsection{Access Routine Semantics}
%
%\noindent plot($T_w$, $T_p$, $E_w$, $E_p$, $t_\text{final}$):
%\begin{itemize}
%\item transition: Modify win to display a plot where the vertical axis
%  is time and one horizontal axis is temperature and the other
%  horizontal axis is energy.  The time should run from $0$ to $t_\text{final}$
%\item exception: none
%\end{itemize}

\newpage
\section{MIS of Output Module} \label{Output}

\subsection{Module}

Output

\subsection{Uses}

Param (Section~\ref{Parameters})

\subsection{Syntax}

\subsubsection{Exported Access Program}

\begin{center}
\begin{tabular}{p{3cm} p{7cm} p{2cm} p{2cm}}
\hline
\textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\
\hline
write\_output & String, String, $\mathbb{R}$ & - & - \\
\hline
\end{tabular}
\end{center}

\subsection{Semantics}

\subsubsection{State Variables}

None

\subsubsection{Environment Variables}

file: The file named ``output".

\subsubsection{Access Routine Semantics}

\noindent write\_output($s$, $d_{\text{offset}}$):
\begin{itemize}
\item transition:  Write to environment variable named ``file" the calculated values $s$ and $d_{\text{offset}}$.
\item exception: none
\end{itemize}

\newpage

\section{MIS of Specification Parameters} \label{SpecParam}

The secrets of this module is the value of the specification parameters.

\subsection{Module}

SpecParam

\subsection{Uses}

N/A

\subsection{Syntax}

\subsubsection{Exported Constants}

\renewcommand{\arraystretch}{1.2}
\begin{longtable*}[l]{l}
\# From Table 10 in SRS\\
  $g$ := 9.8\\
  $\epsilon$ := 0.02\\
\end{longtable*}

\subsection{Semantics}

N/A

\newpage

\bibliographystyle {plainnat}
\bibliography {MIS}

\section{Appendix} \label{Appendix}

\renewcommand{\arraystretch}{1.2}

\begin{longtable}{l p{12cm}}
\toprule
\textbf{Message ID} & \textbf{Error Message} \\
\midrule
badSpeed & InputError: Speed must be positive.\\
badAngle & InputError: Angle must be between zero and pi over two radians.\\
badTargetPosition & InputError: Target position must be positive.\\
\bottomrule
\caption{Possible Exceptions} \\
\end{longtable}

\end{document}


\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[margin=2cm]{geometry}
\usepackage{hyperref}
\usepackage{amssymb,mathtools}
\usepackage[extdef]{delimset}
\usepackage{physics}
\usepackage{verbatim}
\usepackage{enumitem}
\setlist{itemsep=1pt,topsep=1pt,parsep=1pt,partopsep=1pt}
\usepackage{cleveref}

% Number of spacetime dimensions
\let\olddim\dim
\renewcommand{\dim}[0]{d}
% Dimensional regularisation parameter
\newcommand{\eps}[0]{\epsilon}
% Colour operators
\newcommand{\colorT}[1]{\mathbf{T}_{#1}}
% Merged particles in intermediate mappings
\newcommand{\mpd}[1]{\widehat{#1}}

\title{Regularisation of real emissions
with distributed soft counterterms}
\author{Simone Lionetti}
\date{\today}

\begin{document}

\maketitle

\section{Process $e^+e^- \to u\bar{u}d\bar{d}$}
\label{sec:uuxddx}

In this \namecref{sec:uuxddx} we consider the process
$e^+e^- \to u_1\bar{u}_2d_3\bar{d}_4$
as a double-real correction to $e^+e^- \to jj+X$,
and we attempt to construct a subtraction procedure
which features a minimal number of reduced kinematic configurations.

The elementary unresolved limits that need to be regulated are
\begin{equation}
\label{eq:ee2uuxddxelem}
	C_{12}, \quad C_{34}, \quad
	C_{134}, \quad C_{234}, \quad C_{123}, \quad C_{124}, \quad
	S_{12}, \quad S_{34}.
\end{equation}
At most three of these limits have a common overlap
and need to be considered simultaneously.
Due to the lack of a tree-level diagram for $e^+e^- \to gg$,
the limit of two collinear pairs $C_{12}C_{34}$ is regular.
The maximal overlaps that we need to consider are therefore
\begin{equation}
	C_{123}S_{12}C_{12}, \quad
	C_{124}S_{12}C_{12}, \quad
	C_{134}S_{34}C_{34}, \quad
	C_{234}S_{34}C_{34}.
\end{equation}
These are all of the same type,
so it will be sufficient to consider the representative $C_{123}S_{12}C_{12}$.

In order to have a minimal number of kinematic configurations per evaluation,
all measurement functions and matrix elements within counterterms
will be evaluated for collinear reduced kinematics,
where a set of particles have been merged into a single on-shell parent
without violating overall momentum conservation.
The momentum mapping that we use to achieve this
is the rescaling mapping of ref.~\cite{Somogyi:2006da}.%
\footnote{
A generalisation of the rescaling mapping
that applies to massive particles was presented in \cite{}.
}
Counterterms that are associated to soft configurations
will be split into multiple contributions
and distributed among collinear reduced kinematics.

In the expression for local currents
we make extensive use of the momentum fractions $z_{A,B}$
and the transverse momenta $k_{A,B}$.
Since these variables which describe unresolved kinematics
are shared by multiple counterterms,
we find it useful to discuss them here.
Given the light-like vector $n$ in the direction of $\vec{p}_{AB}$
(where $p_{AB} = p_A+p_B$)
and an arbitrary reference vector $\bar{n}$,
momentum fractions are defined by
\begin{equation}
	z_{A,B} \equiv \frac{\bar{n}\cdot p_A}{\bar{n}\cdot p_{AB}},
\end{equation}
and transverse momenta are determined via
\begin{equation}
	k_A^\mu \equiv p_A^\mu
	- \frac{\bar{n}\cdot p_A}{\bar{n}\cdot n} n^\mu
	- \frac{n \cdot p_A}{n\cdot\bar{n}} \bar{n}^\mu,
	\qquad
	k_{A,B}^\mu \equiv k_A^\mu - z_{A,B} k_{AB}^\mu.
\end{equation}
We have verified that the regularisation
of the unresolved limits \cref{eq:ee2uuxddxelem}
is not sensitive to the choice of $\bar{n}$ among the following:
\begin{itemize}
	\item an arbitrary, fixed null vector $(1, \hat{z})$;
	\item the fixed, time-like total momentum $Q$ of the $e^+ e^-$ collision;
	\item a light-like vector in the anti-collinear direction,
	which is different for the collinear sets $\set{1,2}$ and $\set{1,2,3}$.
\end{itemize}

\subsection{Counterterm $C_{12}$}

We subtract the limit of a $q\bar{q}$ pair going collinear using the current
\begin{equation}
\label{eq:Pqq}
	C_{12}^{\mu\nu} = \frac{T_R}{s_{12}} \brk[s]*{
		- g^{\mu\nu}
		+ 4 z_{1,2} z_{2,1} \frac{k_{1,2}^\mu k_{1,2}^\nu}{k_{1,2}^2}
	},
\end{equation}
which is associated to $12$-collinear kinematics.

\subsection{Counterterm $C_{123}$}

The triple-collinear counterterm for $q'\bar{q}'q$
is determined using the current \cite{Catani:1999ss}
\begin{equation}
	C_{123} = \frac{C_F T_R}{2 s_{123}^2} \brk[s]*{
		- \frac{t_{12,3}^2}{s_{12}^2}
		+ \frac{s_{123}}{s_{12}} \brk*{
			\frac{4 z_{3,12} + (z_{1,23} - z_{2,13})^2}{z_{12,3}}
			+(1 - 2\eps) z_{12,3}
		}
		- (1 - 2\eps)
	},
\end{equation}
where
\begin{equation}
	t_{12,3}
	\equiv 2 \frac{z_{1,23} s_{23} - z_{2,13} s_{13}}{z_{12,3}}
	+ \frac{z_{1,23} - z_{2,13}}{z_{12,3}} s_{12}.
\end{equation}
Clearly in this case we use $123$-collinear kinematics.

\subsection{Counterterm $S_{12}$}

In order to construct the $q\bar{q}$ soft counterterm,
we start from the form of the current used in \cite{Somogyi:2005xz} which reads
\begin{equation}
	\frac{T_R}{s_{12}^2} \sum_i \sum_j
	\frac{s_{1i}s_{2j} + s_{1j}s_{2i} - s_{12}s_{ij}}{s_{(12)i} s_{(12)j}}
	\colorT{i}\cdot\colorT{j},
\end{equation}
where the sum runs over all coloured partons of the reduced process
and includes the case $i=j$.

Before discussing partial fractioning, we observe
that the global factor $s_{12}^{-2}$ may cause the counterterm to diverge
in limits where neither $s_{12i}$ nor $s_{12j}$ go to zero.
More concretely, the contribution from the terms with $i=j$ reads
\begin{equation}
\label{eq:qqsoftieqj}
	\frac{T_R}{s_{12}^2} \sum_{i}
	\frac{2s_{1i}s_{2i}}{s_{(12)i}^2}
	\colorT{i}^2,
\end{equation}
and \emph{all} terms are divergent in the triple-collinear limit $12j$
for \emph{any} $j$.
Thus, although from \cref{eq:qqsoftieqj} one might be tempted
to assign the $i$-th term to $12i$-collinear kinematics,
every term needs to be distributed among all $12j$-collinear kinematics.
To this end, we use colour conservation to move all terms off the colour diagonal
\begin{equation}
	\sum_{i}
	\frac{2s_{1i}s_{2i}}{s_{(12)i}^2}
	\colorT{i}^2
	= - \sum_i \sum_{j\ne i}
	\frac{2s_{1i}s_{2i}}{s_{(12)i}^2}
	\colorT{i}\cdot\colorT{j}
	= - \sum_i \sum_{j\ne i} \brk[s]*{
	\frac{s_{1i}s_{2i}}{s_{(12)i}^2}
	+ \frac{s_{1j}s_{2j}}{s_{(12)j}^2}
	}
	\colorT{i}\cdot\colorT{j}.
\end{equation}
In this sense, the kinematics that we assign do not follow the divergent structure
of the invariant poles but rather the colour,
in a similar way as proposed for geometric subtraction \cite{Herzog:2018ggi}.

The complete off-diagonal soft current reads
\begin{equation}
\label{eq:qqsoftoffdiag}
	\frac{T_R}{s_{12}^2} \sum_i \sum_{j \ne i}
	\brk[s]*{
		\frac{s_{1i}s_{2j} + s_{1j}s_{2i} - s_{12}s_{ij}}{s_{(12)i} s_{(12)j}}
		- \frac{s_{1i}s_{2i}}{s_{(12)i}^2} - \frac{s_{1j}s_{2j}}{s_{(12)j}^2}
	} \colorT{i}\cdot\colorT{j}.
\end{equation}
At this stage, we observe that we may replace
the invariants $s_{(12)i} = 2p_{12}\cdot p_i$ and $s_{(12)j} = 2p_{12}\cdot p_j$
in the denominator with $s_{12i}$ and $s_{12j}$ at our leisure.
Indeed, this operation modifies the counterterm by terms which are of higher order
in the double-soft limit $S_{12}$, and therefore does not spoil the cancellation
in the counterterm's defining limit.
Using the triple invariant $s_{12i}$ seems convenient
because it makes denominators naturally match the ones of the collinear counterterm
(which cannot be changed because the modification $s_{123}\to s_{(12)3}$
is \emph{not} higher-order in the triple-collinear limit).
We thus use
\begin{equation}
\label{eq:qqsoftoffdiagmod}
	S_{12} = \frac{T_R}{s_{12}^2} \sum_{j \ne i}
	\brk[s]*{
		\frac{s_{1i}s_{2j} + s_{1j}s_{2i} - s_{12}s_{ij}}{s_{12i} s_{(12)j}}
		- \frac{s_{1i}s_{2i}}{s_{12i}^2} - \frac{s_{1j}s_{2j}}{s_{(12)j}^2}
	} \colorT{i}\cdot\colorT{j}.
\end{equation}
Whether the choice of using $s_{(12)j}$ instead of $s_{12j}$
is important elsewhere in the subtraction was not documented
and needs investigation.

It is easy to partial-fraction \cref{eq:qqsoftoffdiagmod}
into collinear kinematics.
In the present implementation we use
\begin{equation}
	1 = \frac{s_{12i}}{s_{12i} + s_{12j}} + \frac{s_{12j}}{s_{12i} + s_{12j}},
\end{equation}
for each term in the dipole sum which leads to
\begin{equation}
\label{eq:qqsoftoffdiagmodpf}
	S_{12}^{(i)} = \frac{T_R}{s_{12}^2} \sum_{j \ne i}
	\frac{s_{12j}}{s_{12i} + s_{12j}}
	\brk[s]*{
		\frac{s_{1i}s_{2j} + s_{1j}s_{2i} - s_{12}s_{ij}}{s_{12i} s_{(12)j}}
		- \frac{s_{1i}s_{2i}}{s_{12i}^2} - \frac{s_{1j}s_{2j}}{s_{(12)j}^2}
	} \colorT{i}\cdot\colorT{j}.
\end{equation}
Possibly in the future we may want to change the partial fractions
to be dependent only on angles and not on energies:
in the case of two collinear pairs with distributed single-soft limits,
this has been noted to be essential for disjoint collinear limits to work
in combination with distributed soft subtraction.

\subsection{Counterterm $C_{123}S_{12}$}

Shifting out of the diagonal the sum over colour dipoles for the $q\bar{q}$ soft limit
turns out to be extremely practical also to take its $C_{123}$ triple-collinear limit.
We start with either \cref{eq:qqsoftoffdiagmod} or \cref{eq:qqsoftoffdiagmodpf}
(the partial fraction makes no difference in the $C_{123}$ limit), and observe that
for a given term to contribute one of $i$ or $j$ needs to be equal to $3$,
and in the collinear limit the ratio of scalar products with another leg
is equal to a ratio of momentum fractions.
After this replacement, colour conservation can be used and we find
\begin{equation}
	C_{123}S_{12} = - \frac{2T_R}{s_{12}^2} \colorT{3}^2
	\brk[s]*{
		\frac{s_{13} z_{2,13} + s_{23} z_{1,23} - s_{12} z_{3,12}}
		{s_{123} z_{12,3}}
		- \frac{s_{13}s_{23}}{s_{123}^2} - \frac{z_{1,23} z_{2,13}}{z_{12,3}^2}
	}.
\end{equation}
Note that, if the contributions on the diagonal have not been reshuffled,
some effort is needed to see that the latter two terms are needed.
We also note that subtracting this sub-limit from $C_{123}$
many terms simplify and we are left with
\begin{equation}
	C_{123} - C_{123}S_{12} = \frac{C_F T_R}{s_{123}^2} \brk[s]*{
		\frac{s_{123}}{s_{12}} \frac{z_{1,23}^2 + z_{2,13}^2}{z_{12,3}} - 1
		+ \eps \brk*{1 + \frac{s_{123}}{s_{12}} z_{12,3} }
	},
\end{equation}
which is what is currently implemented in the code (for $\eps=0$).
This hard triple-collinear counterterm is clearly associated
to $123$-collinear kinematics, and for the simplifications to occur
the momentum fractions have to be computed as in $C_{123}$.

\subsection{Counterterm $C_{123}C_{12}$}

The strong-ordered collinear limit $C_{123}C_{12}$ is the first nested limit
that we encounter whose counterterm we implement in an iterated fashion.
To this end we follow the steps of \cite{Somogyi:2006da}.
Starting from the counterterm $C_{12}$, we take the extra collinear limit
of the parent gluon $\mpd{12}$ of the quark-antiquark pair
going collinear to the mapped, different-species quark $\mpd{3}$.
This involves taking the collinear limit of a spin-correlated matrix element,
which gives the splitting function
\begin{equation}
	C_{\mpd{12}\mpd{3}}^{\alpha\beta,ss'} = \frac{C_F}{s_{\mpd{12}\mpd{3}}}
	\delta_{ss'} \brk[s]*{
		\frac{z_{\mpd{12},\mpd{3}}}{2} d^{\alpha\beta}
		- 2 \frac{z_{\mpd{3},\mpd{12}}}{z_{\mpd{12},\mpd{3}}}
		\frac{k_{\mpd{3},\mpd{12}}^\alpha k_{\mpd{3},\mpd{12}}^\beta}
		{k_{\mpd{3},\mpd{12}}^2}
	}.
\end{equation}
The sum over physical polarisations is given by the transverse tensor
with respect to the light-cone vector in the collinear direction $p$
and a reference null vector $n$,
\begin{equation}
	d^{\alpha\beta}(p, n) \equiv
	-g^{\alpha\beta}
	+ \frac{p^\alpha n^\beta + p^\beta n^\alpha}{p \cdot n}.
\end{equation}
We have indicated with a hat the variables which are computed
after merging particles 1 and 2.
Performing the Lorentz algebra we find
\begin{equation}
\label{eq:iterC123C12qq}
	C_{\mpd{12}\mpd{3}}^{\alpha\beta,ss'} C_{12,\alpha\beta}
	= \frac{C_FT_R}{s_{12}s_{\mpd{12}\mpd{3}}} \delta^{ss'} \brk[s]3{
		\brk3{
			2 \frac{z_{\mpd{3},\mpd{12}}}{z_{\mpd{12},\mpd{3}}}+
			z_{\mpd{12},\mpd{3}} (1 - \eps)
		} - 2 z_{1,2} z_{2,1} \brk3{
			z_{\mpd{12},\mpd{3}} +
			\frac{z_{\mpd{3},\mpd{12}}}{z_{\mpd{12},\mpd{3}}}
			\frac{(2k_{1,2}\cdot k_{\mpd{3},\mpd{12}})^2}
			{k_{1,2}^2 k_{\mpd{3},\mpd{12}}^2}
		}
	}.
\end{equation}
The reduced matrix element is evaluated for momenta that have been obtained
merging particles 1, 2 and 3 with a generalised rescaling mapping.
This is equivalent to merging 1 and 2 into $\mpd{12}$
recoiling against all other legs,
and later merging $\mpd{12}$ with $\mpd{3}$
recoiling against all remaining momenta.

\subsection{Counterterm $S_{12}C_{12}$}

The limit where the $q\bar{q}$ pair is both collinear and soft is over-subtracted
and needs to be added back.
The corresponding counter-counterterm $S_{12}C_{12}$
may also be constructed iteratively as done in \cite{Somogyi:2005xz}.
After the $C_{12}$ limit has been taken the reduced, spin-correlated matrix element
which contains the single parent $\mpd{12}$ in the limit of soft $\mpd{12}$
factorises with the current
\begin{equation}
	S_{\mpd{12}}^{\mu\nu}
	= \sum_{i, j}
	\frac{\mpd{p}_i^\mu \mpd{p}_j^\nu + \mpd{p}_i^\nu \mpd{p}_j^\mu}
	{s_{\mpd{12}\mpd{i}} s_{\mpd{12}\mpd{j}}}
	2\colorT{i}\cdot\colorT{j}.
\end{equation}

Since this current multiplies the splitting function for the 12-collinear limit
which features a factor $s_{12}^{-1}$,
the counterterm is divergent in all triple-collinear configurations
and not just in the $12i$- or $12j$-collinear limits.
Similarly to the case of $S_{12}$, it is thus convenient
to shift away the elements on the colour diagonal using colour conservation,
which gives
\begin{equation}
	S_{\mpd{12}}^{\mu\nu}
	= \sum_{i \ne j} \brk[s]*{
		\frac{\mpd{p}_i^\mu \mpd{p}_j^\nu + \mpd{p}_i^\nu \mpd{p}_j^\mu}
		{s_{\mpd{12}\mpd{i}} s_{\mpd{12}\mpd{j}}}
		- \frac{\mpd{p}_i^\mu \mpd{p}_i^\nu}{s_{\mpd{12}\mpd{i}}^2}
		- \frac{\mpd{p}_j^\mu \mpd{p}_j^\nu}{s_{\mpd{12}\mpd{j}}^2}
	} 2 \colorT{i}\cdot\colorT{j}.
\end{equation}
Contracting this expression with \cref{eq:Pqq},
with the assumption that $\mpd{p}_i$ and $\mpd{p}_j$
be massless, we find
\begin{multline}
\label{eq:S12C12iter}
	S_{12}^{\mu\nu} C_{12,\mu\nu}
	= \frac{T_R}{s_{12}} \sum_{i \ne j} \bigg[
		- \frac{s_{\mpd{i}\mpd{j}}}{s_{\mpd{12}\mpd{i}}s_{\mpd{12}\mpd{j}}}
		+ 2 z_{1,2} z_{2,1}
		\frac{(2k_{1,2}\cdot\mpd{p}_i)(2k_{1,2}\cdot\mpd{p}_j)}
		{s_{\mpd{12}\mpd{i}} s_{\mpd{12}\mpd{j}} k_{1,2}^2}
		\\\times
		\brk3{ 1
		- \frac{1}{2} \frac{s_{\mpd{12}\mpd{j}}}{s_{\mpd{12}\mpd{i}}}
		\frac{2k_{1,2}\cdot\mpd{p}_i}{2k_{1,2}\cdot\mpd{p}_j}
		- \frac{1}{2} \frac{s_{\mpd{12}\mpd{i}}}{s_{\mpd{12}\mpd{j}}}
		\frac{2k_{1,2}\cdot\mpd{p}_j}{2k_{1,2}\cdot\mpd{p}_i}
		}
	\bigg] \colorT{i}\cdot\colorT{j}.
\end{multline}

At this stage, the $S_{12}C_{12}$ counterterm may be partial-fractioned
into triple-collinear sectors following the colour structure.
We choose to perform this operation \emph{after} the limit $C_{12}$
has been taken, as if we were dealing with a single-soft gluon $\mpd{12}$.%
\footnote{
This choice might match better the structure of iterated limits,
such that $S_{12}C_{12}$ regulates the $C_{12}$ integrated counterterm
in the $S_{\mpd{12}}$ single-unresolved limit
within the single-unresolved phase space.
However the specific form of partial fraction employed
may have interplay with other subtraction elements
and deserves further investigation.
}
We thus use the current
\begin{equation}
	S_{12}^{(i),\mu\nu} C_{12,\mu\nu}
	= \frac{s_{\mpd{12}\mpd{j}}}{s_{\mpd{12}\mpd{i}}+s_{\mpd{12}\mpd{j}}}
	S_{12}^{\mu\nu} C_{12,\mu\nu},
\end{equation}
within $12i$ triple-collinear kinematics.

\subsection{Counterterm $S_{12}C_{123}C_{12}$}

The last piece that is missing for the three limits
$S_{12}$, $C_{123}$ and $C_{12}$ to be regulated is the triple overlap,
which has been subtracted three times in the simple counterterms
and added back three times in the double overlaps,
so that it still needs to be subtracted from the original integrand.
The singular current, which is constructed to match \cite{Somogyi:2006da},
can be obtained from \cref{eq:iterC123C12qq} dropping terms
which do not have a $z_{\mpd{12},\mpd{3}}$ denominator%
\footnote{
In performing this step we somewhat arbitrarily decide
to keep the $z_{\mpd{3},\mpd{12}}$ terms at the numerator
which theoretically could or should be set to one.
Very roughly speaking this is equivalent to taking
the $C_{\mpd{12}\mpd{3}}$ limit of the soft counterterm for $S_{\mpd{12}}$,
as it is sometimes useful to do for single-unresolved
nested soft-collinear limits.
}
\begin{equation}
	S_{\mpd{12}} C_{\mpd{12}\mpd{3}} C_{12}
	= \frac{2 C_F T_R}{s_{12}s_{\mpd{12}\mpd{3}}}
	\frac{z_{\mpd{3},\mpd{12}}}{z_{\mpd{12},\mpd{3}}}
	\brk[s]3{
		1 - z_{1,2} z_{2,1}
		\frac{(2k_{1,2}\cdot k_{\mpd{3},\mpd{12}})^2}
		{k_{1,2}^2 k_{\mpd{3},\mpd{12}}^2}
	}.
\end{equation}
This counterterm is associated to $123$-collinear kinematics.

\subsection{Spurious limits and division by jacobian}

Within each counterterm we let the limit operation
act on the phase space volume,
i.e.\ we divide each counterterm by the jacobian $\mathcal{J}$
defined by
\begin{equation}
\label{eq:jaccanonical}
	\dd{\Phi} = \mathcal{J}\times \dd{\tilde{\Phi}}
	\prod_{C} \frac{\dd{s_C}}{2\pi} \dd{\Phi_C},
\end{equation}
where $\Phi$ is the full phase space,
$\tilde{\Phi}$ the reduced one,
and $C$ each merged set of particles.

This, however, is not sufficient to achieve
the desired cancellation pattern.
Indeed, when the counterterm built from the current \labelcref{eq:S12C12iter}
is included with $12k$ collinear kinematics for some $k$,
which clearly reduce to no momentum mapping for soft $p_{12}$,
it does \emph{not} automatically match
the counterterm $C_{12}$ from \cref{eq:Pqq} in the $S_{12}$ limit.
This is due to our choice of dividing by the jacobian factor
of \cref{eq:jaccanonical} which, in the $S_{12}$ limit,
is different between the mappings that merge
the sets $\set{1,2}$ and $\set{1,2,3}$.
To fix this mismatch we have two options.
The first one, which essentially follows \cite{Somogyi:2006da},
is to forfeit \cref{eq:jaccanonical} and divide by jacobians
which are defined by the alternative
canonical factorisation of phase space
\begin{equation}
	\dd{\Phi} = \mathcal{J}\times \dd{\tilde{\Phi}}
	\prod_{C} \frac{\dd{\alpha_C}}{2\pi} \dd{\Phi_C},
\end{equation}
where $\alpha_C$ are the parameters of the rescaling mapping
defined in \cite{Somogyi:2006da}.
Given that $\alpha_C$ is essentially the light-cone component
of the momentum of the collinear set in the anti-collinear direction,
i.e.\ its `minus' component,
this choice amounts to parametrise the virtuality variables
with the anti-collinear components of the collinear momenta.
The second possibility is to reabsorb the mismatch factor
into the definition of the counterterm, replacing for instance
\begin{equation}
	S_{12}^{(i),\mu\nu} C_{12,\mu\nu}
	\to \frac{Q\cdot p_{12}}{Q\cdot p_{\mpd{12}}}
	S_{12}^{(i),\mu\nu} C_{12,\mu\nu}.
\end{equation}
Note that the factor is only defined up to terms
which are higher-order in the $S_{12}$ limit,
with the constraint that it goes to 1
in the $C_{12}$ and $C_{123}$ limits.
At the moment it does not seem clear which option
is the most convenient, but it is relatively easy
to switch between the two.%
\footnote{
Within \texttt{MadNkLO}, the first option can be chosen
by selecting \texttt{alpha\_jacobian} as \texttt{factor}
for the currents, either individually
or globally in \texttt{QCD\_local\_currents.py}
(beware that this might affect other schemes).
The mismatch factor is instead implemented
within the \texttt{ee2qqgg-NNLO-IR-limits} branch
in the \texttt{cataniseymour} NNLO local current
\texttt{QCD\_final\_collinear\_0\_QQxq},
and more precisely in the method \texttt{S12C12\_kernel}
with the variable \texttt{fix}.
}

\begin{comment}
A potential drawback of this choice is that
it makes the subtraction of disjoint collinear limits more complicated.
In fact, within the formula
\begin{equation}
	1
	- C_{12} - C_{34}
	+ C_{\mpd{3}\mpd{4}} C_{12} + C_{\mpd{1}\mpd{2}} C_{34}
	- C_{12;34},
\end{equation}
the last three terms, which all feature the same kinematics
thanks to the commutativity property of the rescaling mapping,
now differ \emph{only} because of jacobian factors.
\end{comment}

\begin{thebibliography}{9}

%\cite{Catani:1999ss}
\bibitem{Catani:1999ss}
  S.~Catani and M.~Grazzini,
  %``Infrared factorization of tree level QCD amplitudes at the next-to-next-to-leading order and beyond,''
  Nucl.\ Phys.\ B {\bf 570}, 287 (2000)
  doi:10.1016/S0550-3213(99)00778-6
  [hep-ph/9908523].
  %%CITATION = doi:10.1016/S0550-3213(99)00778-6;%%
  %227 citations counted in INSPIRE as of 04 Apr 2019

%\cite{Somogyi:2005xz}
\bibitem{Somogyi:2005xz}
  G.~Somogyi, Z.~Trocsanyi and V.~Del Duca,
  %``Matching of singly- and doubly-unresolved limits of tree-level QCD squared matrix elements,''
  JHEP {\bf 0506}, 024 (2005)
  doi:10.1088/1126-6708/2005/06/024
  [hep-ph/0502226].
  %%CITATION = doi:10.1088/1126-6708/2005/06/024;%%
  %111 citations counted in INSPIRE as of 04 Apr 2019

%\cite{Somogyi:2006da}
\bibitem{Somogyi:2006da}
  G.~Somogyi, Z.~Trocsanyi and V.~Del Duca,
  %``A Subtraction scheme for computing QCD jet cross sections at NNLO: Regularization of doubly-real emissions,''
  JHEP {\bf 0701}, 070 (2007)
  doi:10.1088/1126-6708/2007/01/070
  [hep-ph/0609042].
  %%CITATION = doi:10.1088/1126-6708/2007/01/070;%%
  %115 citations counted in INSPIRE as of 04 Apr 2019

\bibitem{Herzog:2018ggi}
	F.~Herzog,
	Geometric subtraction for real radiation at NNLO,
	\url{https://www.ggi.infn.it/talkfiles/slides/slides4304.pdf}

\end{thebibliography}

\end{document}


%In this section, we first define the problem we address and  then the mathematical notation we use.

%In this section, we will define our addressing problem with the notation. Also, the background about this paper will be provided.

%\subsection{Background}

%Standard unsupervised algorithms like $k$-means~\cite{kmeans_original} (and variants) that are commonly used for search results clustering define clusters according to a prototype document centroid in a vector space model, where all search results would be assigned to their closest cluster centroid.  While this approach naturally provides for topical (content) coherence of search results within a cluster, it does not directly guarantee high relevance of clusters.  It also does not directly guarantee coherence of display attributes of clusters such as the spatial and temporal extent of the cluster (i.e., a cluster may have documents spanning a large spatial or temporal range), unless these attributes are incorporated into the distance metric for the vector space model and appropriately traded off with content distance.

\subsection{Problem definition}

In this paper, we take a novel perspective on the definition of a cluster and the optimization process for extracting these clusters. To start, we assume the search results have the following three display attributes that can be used to define coherent clusters in terms of spatial, temporal, and topical (i.e., content) constraints:
%of an AUI to ease the task of monitoring alerts in large-scale displayed networks. The new interface is expected to filter irrelevant information to provide localized context for each event or alert (defined loosely as a relevant related content localized in time, space, and/or keyword usage). \textcolor{red}{Hence, we argue that the problem we are addressing in this paper is an optimization problem of filter selection.  Furthermore, we assume that selection of information elements to display in a visual interface is obtained via settings of three filters that jointly express a global filter. These three sub-filters are:}
%%
%The problem we address in this paper is the proper display of portion in the network for user's easy to investigate large-scale network elements. The new system is expected to filter information to provide localized and relevant element in the interface. This problem is able to be defined as a filter search/recommendation problem, We expect to employ standard IR theory to solve this problem based on our argument about the similarity of AUI and IR system. We assume that display of the elements in the network is obtained via three filters that can jointly express a global filter. These three sub-filters are:
\begin{itemize}[topsep=2pt,leftmargin=*]
\item {\bf Space:} limits cluster content to 2D spatially annotated content (e.g., latitude and longitude) according to four parameters for the upper left and lower right bounding box coordinates.  These cluster constraints define the bounding box that is visually displayed to the user, cf. Figure~\ref{Fig:BPS_FilteredDisplay}.
\item {\bf Time:} limits cluster content to time-stamped results according to two parameters for the lower and upper time bound.  Time can be displayed via cluster labels, and/or through settings of a time slider in the interface.
%expresses a bounding box of a retrieved set. The location can be expressed as longitude/latitude values, or pure coordinates obtained using a given display layout.
\item {\bf Keyword (or Discrete Attribute):} limits cluster content according to included or excluded keywords (or general discrete attributes of an information element).
Explicit included and excluded keywords can be used to label the cluster.
\end{itemize}
Given a query and a probabilistic measure of relevance for each search result w.r.t.\ this query (e.g., from a language model~\cite{Zhai2001}), %the problem we address in this paper is how to efficiently optimize content filtering in a visual information display (VID) for
the problem we study is how to efficiently extract high-relevance clusters defined according to the above constraints.

%In general, we remark that the choice of which clustering parameters to use is up to the interactive search interface designer according to the display and (meta-)data available.
We note that this clustering work is not limited to these three display attributes -- any continuous or discrete cluster attributes that naturally constrain the search results can be accommodated by our framework.  Nonetheless, we believe time, space, and content constitute three of the most common information display attributes in practice and hence are the ones we focus on in this work.
%one or multiple filter selection settings to maximize retrieval of relevant content?
%\textcolor{red}{Even though in practice, not all data have such information associated, we can imagine throw away the sub-filters associated with the missing information, e.g., location information which is certainly not available in all datasets.}
%best set of elements that is assessed using one of the metrics described above, i.e., expected precision, expected recall, or expected F1-score

\subsection{Mathematical Notation}

With the cluster definitions above, we now define  formal mathematical notation used throughout the remainder of the paper:
%portion of our presentation using
%Throughout this paper, we present all algorithms for Greedy and Optimal search using
%the following mathematical notation:

\begin{itemize}[topsep=2pt,leftmargin=*]
\item An information element $j$ (i.e., a search result) may have three types of associated metadata: (i) position coordinates $(x_{j},y_{j})$, (ii) a timestamp $t_j$, which may represent the creation date of $j$, and (iii) textual content, which is composed of a set of unique terms $\{ t_1,\ldots,t_n \}$ of size $n$ (to reduce notational clutter, we assume the element $j$ containing these terms will be clear from context).

\item Three variables $I(j) \in \{0,1\}$, $B(j) \in \{0,1\}$ and $S(j) \in [0,1]$ are associated with each information element $j$: $I(j)$ is an indicator referring to whether an element $j$ is retrieved and displayed ($\textrm{true}\!=\!1$); $B(j)$ is a Boolean random variable indicating the (ground truth) relevance of an element $j$ ($\textrm{relevant}\!=\!1$); $S(j)$ is a relevance score indicating the \emph{probability} relevance of an element $j$. %Note that $I(j)$ is correlated with the UI system. $B(j)$ and $S(j)$ are independent of the system.
%$\emph{I(j), B(j)} \in \{0, 1\}$, $\emph{S(j)} \in \left[0, 1\right]$.
$B(j)$ follows a \emph{Bernoulli} distribution with parameter $S(j)$, and hence, the expectation of $B(j)$ \emph{is} $S(j)$, i.e.,
  $\mathbb{E}[B(j)] = S(j)$.
%which allows to derive the expectation of \emph{B(j)} as follows:
%\begin{equation}
 % \mathbb{E_S}[B(j)] = 0*(1 - S(i))+ 1*S(i) = S(i)
%\end{equation}
\item We label $GC$ as the global set of all information elements $j$ with total size $|GC|=m$. %Two subsets of $GC$ are particularly important in this research: retrieved set $E$ and relevant set $RS$.
\item $E$ is the set of retrieved information elements that match a user query, where $E \subseteq  GC$.  We use $E^*$ to refer to further subsets of elements of clusters, i.e., $E^*\subseteq E$.
%This variable depends on the UI filtering system.
Note that $|E|$ is the count of retrieved $I(j)$ among the global collection $GC$. Therefore, we have $|E| = \sum_{j=1}^m I(j)$.
\item We label the set of ground truth relevant information elements as the relevant set $RS$ consisting of $|RS|$ elements.
%This is independent of the UI-filter system.
Note that $|RS|$ is the count of relevant $B(j)$ among the global collection $GC$. Therefore, we have $|RS| = \sum_{j=1}^m B(j)$. %However, $B(j)$ is not available for our estimation of $RS$ size in practice. We have to use expected $RS$ size $|RS|$, $\mathbb{E_S}|RS|$, to approximate $|RS|$.
%\begin{equation}
  %|RS| \approx \mathbb{E_S}|RS| = \sum_{j=1}^m \mathbb{E_S}[B(j)] = \sum_{j=1}^m S(j)
%\end{equation}

%\item Keyword parameters $Q_k=\{\neg t_{1}^{*},\dots \neg t_{k}^{*}\}$, are composed of a set of query terms excluded from the cluster, i.e., elements in the cluster cannot contain the terms $t_{1}^{*},\dots t_{k}^{*}$.
%\item Time parameters $Q_t=[t_{start},t_{end}]$ express the lower bound $t_{start}$ and upper bound $t_{end}$ time parameters of the cluster.
%\item Position parameters $Q_p=[(x_{min},y_{min}),(x_{max},y_{max})]$ express the upper left $(x_{min},y_{min})$ and lower right $(x_{max},y_{max})$ corners of the spatial parameters of a cluster.%, assuming $(0,0)$ is in the upper left corner of the display window.
%search 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})$.
%\item A cluster $Q$ combines the three selection parameters $Q_k$, $Q_t$, and $Q_p$ in a conjoined set of parameters $Q=[Q_k, Q_t, Q_p]$.
%$Q=[Q_k\wedge Q_t\wedge Q_p]$.

\end{itemize}

%The goal is to explore an algorithm to obtain an optimal filter setting to retrieve a set of elements with maximum score of the specific metric.

%\subsection{Comparison to standard IR search}
%The comparison between information retrieval for web search and information retrieval for filtering in AUIs can be summarized in Table \ref{tbl:Comparaison2IR}. Obviously , there are important differences between web search and filtering for AUIs, especially in the indirect selection of results through filter settings. This unexplored field provides new possibilities and challenges of research in this novel information retrieval setting:
%\begin{itemize}
%\item Evaluation metrics and human factors: Are there new evaluation metrics specific to this AUI filtering setting? What evaluation metrics correlate with AUI user performance?
%\item Optimization and algorithms: How do we optimally select filter settings to maximize evaluation metrics in expectation? How can we interpret simple heuristics like average and cumulative relevance? (Answer: expected precision.) How do MILPs, relaxed LP approximations with guarantees, or greedy approaches compare in terms of time and metric quality? Are there properties of different filters (1D for time, 2D for bounding box, or discrete choices for property selection) that lend themselves to specialized greedy approaches?
%\item Robustness: As the signal-to-noise ratio varied in the quality of the relevance scoring, how do various algorithms perform?
%\item Explanation: Can we provide explanations for filter settings to allow users to understand the reasons for the suggestions?
%\item Personalization and learning: Can we learn from observations of manual adaption of the suggested filter settings to understand how to improve the third-party scoring systems?
%\item Collaborative filtering: Can we generalize learning across multiple
%users in a collaborative filtering approach?
%\item Learning from implicit feedback: How can we leverage implicit user
%feedback such as clicks and dwell time to indirectly measure the relevance
%of filtered content and improve system performance.
%\end{itemize}

%\subsection{Optimization technique definition}

%The \emph{greedy algorithm} is an algorithmic paradigm that aims to obtain a global optimum of a problem in terms of making the locally optimal decision at each step \cite{Black2005}. In a search problem, a greedy algorithm does not in general produce an optimal solution, but it still yields locally optimal solutions that approximate a global optimum in a reasonable time.

%The greedy algorithms described in this paper are coupled with a \emph{Top-down} search strategy, which basically begins with the whole search space, and then partition into several sub-spaces in a lower level for the local optimization search heuristic.

%An \emph{optimization-based} search is the problem of finding the best solution from all feasible solutions. Usually, the standard form of an optimization problem is defined as the minimization/maximization of a given objective function subject to a set of constraints.

%The search problem will be transformed into Mixed integer linear programming (MILP), which involves problems in which only some of the variables, $x_{i}$, are constrained to be integers, while other variables are allowed to be non-integers.

%\subsection{Evaluation metrics}


% !TEX TS-program = xelatex
% !TEX encoding = UTF-8 Unicode
\documentclass[11pt,a4paper]{article}
\usepackage{amsmath,amssymb}
\usepackage{empheq}
\usepackage[semibold]{ebgaramond}
\usepackage[cmintegrals,cmbraces]{newtxmath}
\usepackage{ebgaramond-maths}
\usepackage{bm}
\usepackage[OMLmathrm, OMLmathsfit, rmdefault=mdugm]{isomath}
\usepackage{tocbibind}
\usepackage{graphicx}
\graphicspath{{./pics/}}
\usepackage{wrapfig}

\makeatletter
  \DeclareSymbolFont{ntxletters}{OML}{ntxmi}{m}{it}
  \SetSymbolFont{ntxletters}{bold}{OML}{ntxmi}{b}{it}
  \re@DeclareMathSymbol{\leftharpoonup}{\mathrel}{ntxletters}{"28}
  \re@DeclareMathSymbol{\leftharpoondown}{\mathrel}{ntxletters}{"29}
  \re@DeclareMathSymbol{\rightharpoonup}{\mathrel}{ntxletters}{"2A}
  \re@DeclareMathSymbol{\rightharpoondown}{\mathrel}{ntxletters}{"2B}
  \re@DeclareMathSymbol{\triangleleft}{\mathbin}{ntxletters}{"2F}
  \re@DeclareMathSymbol{\triangleright}{\mathbin}{ntxletters}{"2E}
  \re@DeclareMathSymbol{\partial}{\mathord}{ntxletters}{"40}
  \re@DeclareMathSymbol{\flat}{\mathord}{ntxletters}{"5B}
  \re@DeclareMathSymbol{\natural}{\mathord}{ntxletters}{"5C}
  \re@DeclareMathSymbol{\star}{\mathbin}{ntxletters}{"3F}
  \re@DeclareMathSymbol{\smile}{\mathrel}{ntxletters}{"5E}
  \re@DeclareMathSymbol{\frown}{\mathrel}{ntxletters}{"5F}
  \re@DeclareMathSymbol{\sharp}{\mathord}{ntxletters}{"5D}
  \re@DeclareMathAccent{\vec}{\mathord}{ntxletters}{"7E}
\makeatother

\usepackage{array}
\usepackage{enumitem}
% to produce a comma between multiple footnotes / https://tex.stackexchange.com/questions/40072/incompatibility-between-footmisc-option-multiple-and-hyperref/62091#62091
\let\oldFootnote\footnote
\newcommand\nextToken\relax
\renewcommand\footnote[1]{%
    \oldFootnote{#1}\futurelet\nextToken\isFootnote}
\newcommand\isFootnote{%
    \ifx\footnote\nextToken\textsuperscript{,}\fi}

\defaultfontfeatures{Ligatures=TeX} % makes this a feature for all selected fonts
\usepackage{esint}
\usepackage{polyglossia}
\setmainlanguage{english}
\usepackage[text={18cm,26cm},centering]{geometry} %
\usepackage{natbib}
\usepackage{mdframed}
\usepackage{lipsum}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{hyperref}
\usepackage{url}
\usepackage[export]{adjustbox}

\hypersetup{
  colorlinks,
  citecolor=bleuSU,
  linkcolor=bleuSU
}
\definecolor{bleuSU}{RGB}{26,39,101}

\usepackage[normalem]{ulem}
\makeatletter
\renewcommand*{\uuline}{%
  \bgroup
  \UL@setULdepth
  \markoverwith{%
    \lower\ULdepth\hbox{%
      \kern-.03em%
      \vtop{%
        \hrule width.2em%
        \kern 0.6pt % distance between the two underlines
        \hrule
      }%
      \kern-.03em%
    }%
  }%
  \ULon
}
\makeatother
\setlength{\ULdepth}{-2pt}  % distance from double underline to letter

\usepackage{environ}
\newtoggle{corrige}

\NewEnviron{answer}{%
  \iftoggle{corrige}
    {\begin{mdframed}\textbf{Answer: } \BODY\end{mdframed}}
    {}%
  }

\newcommand{\delS}{\delta S}
\newcommand{\delA}{\delta A}
\newcommand{\delh}{\delta h}
\newcommand{\delt}{\delta t}
\newcommand{\delz}{\delta z}
\newcommand{\delbx}{\delta \matrixsym x}
\newcommand{\lp}{\left(}
\newcommand{\rp}{\right)}
\newcommand{\itA}{\textit A}
\newcommand{\itB}{\textit B}
\newcommand{\dAB}{\mathcal D_{AB}}
\newcommand{\bA}{\matrixsym A}
\newcommand{\bff}{\matrixsym{f}}
\newcommand{\bF}{\matrixsym{F}}
\newcommand{\bj}{\matrixsym{j}}
\newcommand{\bJ}{\matrixsym J}
\newcommand{\bn}{\matrixsym{n}}
\newcommand{\bN}{\matrixsym N}
\newcommand{\bP}{\matrixsym{P}}
\newcommand{\br}{\matrixsym r}
\newcommand{\bt}{\matrixsym t}
\newcommand{\be}{\matrixsym e}
\newcommand{\bu}{\matrixsym u}
\newcommand{\bv}{\matrixsym v}
\newcommand{\bw}{\matrixsym w}
\newcommand{\bx}{\matrixsym x}
\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\D}[2]{\frac{D #1}{D #2}}
\newcommand{\dd}[2]{\frac{\mathrm d #1}{\mathrm d #2}}
\newcommand{\dA}{\mathrm dA}
\newcommand{\dV}{\mathrm dV}
\newcommand{\dS}{\mathrm dS}
\newcommand{\prg}[1]{\paragraph{$\rhd$ #1}}
\newcommand{\alphaijkl}{\alpha_{ijkl}}
\newcommand{\Aijkl}{A_{ijkl}}
\newcommand{\delij}{\delta_{ij}}
\newcommand{\sigij}{\sigma_{ij}}
\newcommand{\sigji}{\sigma_{ji}}
\newcommand{\sigxy}{\sigma_{xy}}
\newcommand{\matL}{\mathcal L}
\newcommand{\matO}{\mathcal O}
\newcommand{\matS}{\mathcal S}
\newcommand{\kij}{k_{ij}}
\newcommand{\tensor}[1]{\smash{\uuline{#1}{}}}
\setlength{\parindent}{0pt} % remove indent

\setlist[enumerate]{topsep=0pt,itemsep=-1ex,partopsep=1ex,parsep=1ex}

\begin{document}
\setlength{\unitlength}{1cm}
\noindent
\parbox{\textwidth}{
\textsc{
Sorbonne Université
\hfill
Year 2021-2022
}
}
\parbox{\textwidth}{
\textsc{
Faculté des Sciences
\hfill
Physics of Fluids \& Nonlinear Physics
}
}

\begin{center}
\Large
\textbf{Hydrodynamics} \\
\textsl{Tutorial 2: boundary conditions, capillarity \& adhesion} \\[1ex]
\end{center}

\section{Impermeable obstacles}
\togglefalse{corrige}

\begin{figure}[ht]
    \centering
    \includegraphics[height=3cm,valign=m]{splash.jpg}
    \hspace{1cm}
    \includegraphics[height=3cm,valign=m]{flow_over_weir.jpg}
    \caption[Caption for LOF]{\textbf{Liquid deflection.} Left: an hydrophobic bead impacts a water pool at $\simeq 5$ m$\cdot$s$^{-1}$ and produces a splash (liquid corolla) on impact \citep{Eggers2007}. Right: a flow over an obstacle in a wave tank givers rise to the \textit{hydraulic jump} phenomenon (Science Education Resource Center at Carleton College\setcounter{footnote}{0}\footnotemark).}
    \label{fig:obstacle}
\end{figure}
\footnotetext{\url{https://serc.carleton.edu/NAGTWorkshops/geomoph/emriver/index.html}}
\prg{Impact.}
A spherical obstacle of radius $R$ impacts a liquid tank at velocity $-U_\text{impact} \be_{z}$. On impact the fluid is violently set into motion by the object.
\begin{enumerate}
\item Supposing that the object preserves its velocity during impact, determine the position $C$ of the sphere centre through time. Consider that at initial time $t=0$, $C$ is located at $(x,y,z)=(0,0,0)$. Deduce the equation of the sphere surface for all time in the laboratory (i.e. fixed) frame.
\item Obtain the expression for the normal vector $\bn$ at each point of the sphere in cartesian ccoordinates.
\item Noting the fluid velocity $\bu=(u,v,w)$, determine the expression for the impermeability condition at the sphere surface.
\begin{answer}
\begin{equation*}
ux+vy+w(z+U_\text{impact}t) = -U_\text{impact}(z+U_\text{impact}t)
\end{equation*}
\end{answer}

\end{enumerate}
\prg{Flow over an obstacle.} We now consider the flow of a river over an obstacle, such as the one illustrated~\ref{fig:obstacle}. For simplification purposes, we take the flow as uniform far upstream, $\bu = U \be_x$, and translation invariant (that is, 2D) in the transverse direction. The vertical direction is given by $\be_y$ and we note the velocity components $\bu=(u,v)$. The bottom height is given by the function $y = f(x)$.
\begin{enumerate}[resume]
\item Determine the vector normal to the river bottom.
\item Express the impermeability condition at the bottom.
\begin{answer}
\begin{equation*}
v = u f'(x)
\end{equation*}
\end{answer}

\item Sketch schematically the vertical velocity near the bottom in the context of the localised obstable (think of a Gaussian hump). Comment.
\end{enumerate}
\section{Flow around a cylinder with suction}
We consider in this exercise the structure of the flow around a cylinder able to exert a suction (or blowing) on the surrounding fluid, as a rudimentary model of a \textit{turbosail} (see lecture).
\begin{figure}[ht]
    \centering
    \includegraphics[height=5cm,valign=m]{aspiration_cylindre.jpg}
    \caption{\textbf{Turbosail model at ONERA.} The suction through the cylinder boundary allows the flow to reattach on the cylinder.}
    \label{fig:turbosail}
\end{figure}

In the remaining, we consider the flow as translation-invariant (2D), incompressible and potential. We note $\bu = (u,v)$ the components of the velocity field and we introduce the streamfunction $\psi$ such that:
\begin{empheq}[left=\empheqlbrace]{alignat=2}
u &\,=\,&\, \pd{\psi}{y} \\
v &\,=\,&\, -\pd{\psi}{x}
\end{empheq}
Depending on the context we will use cartesian coordinates $(x,y)$ or polar ones $(r,\theta)$.
\begin{enumerate}
\item Show that a flow describe with such a streamfunction automatically satisfies mass conservation.
\begin{answer}
If the flow is incompressible then mass conservation reduces to:
\begin{equation*}
\nabla \cdot \bu = 0.
\end{equation*}
For a flow described by a streamfunction the velocity field divergence reads:
\begin{equation*}
\nabla \cdot \bu = \pd{}{x}\lp\pd{\psi}{y}\rp-\pd{}{y}\lp\pd{\psi}{x}\rp = 0
\end{equation*}
by construction, whatever $\psi$.
\end{answer}
\item Show that the potential flow condition implies $\Delta \psi = 0$.
\begin{answer}
A potential flow is such that:
\begin{equation*}
\nabla \times \bu = 0.
\end{equation*}
For a 2D flow this condition reduces to:
\begin{equation*}
\pd{v}{x}-\pd{u}{y} = 0.
\end{equation*}
On using the relation between $(u,v)$ and $\psi$ we get $-\Delta \psi =0$.
\end{answer}
\item Verify that $\psi_\text{unif} = a y$ and $\psi_\text{source} = b\theta$ are elementary solutions of $\Delta \psi = 0$. What are the associated flow patterns?
\begin{answer}
These two streamfunctions are linear in $y$ and $\theta$, and thus verify Laplace equation trivially.

{\centering
      \includegraphics[width=12cm]{uniform_source.pdf}
      \captionof{figure}{Left: the isolines for $\psi_\text{uniform}$ evidence a uniform flow. Right: the isolines for $\psi_\text{source}$ show the purely radial flow typical of a \textit{source}.}
      \par}
\end{answer}
\item What is the streamfunction associated with a uniform flow $\bu = (U,0)$ ?
\begin{answer}
We have directly:
\begin{equation*}
\psi = Uy
\end{equation*}
\end{answer}
\item More complex multipolar solutions can be built from the previous elementary solutions. Compute the expression for the dipolar fields $\psi_{\parallel} = \pd{}{x} \psi_\text{source}$ and $\psi_{\perp} = \pd{}{y} \psi_\text{source}$. Represent the corresponding streamlines with Python.
\begin{answer}
Let's write $\psi_\text{source}$ in cartesian coordinates:
\begin{equation*}
\psi_\text{source} = \arctan\lp\frac{y}{x}\rp.
\end{equation*}
Using $\partial_x\lp\arctan\lp f \rp \rp=\frac{\partial_x f}{1+f^2}$ we have:
\begin{empheq}[left=\empheqlbrace]{alignat=2}
\psi_{\parallel}  \,&=&\, -\frac{y}{r^2}\\
\psi_{\perp} \,&=&\, \frac{x}{r^2}
\end{empheq}
{\centering
      \includegraphics[width=12cm]{psi_dipoles.pdf}
      \captionof{figure}{Left: $\psi_\parallel$. Right: $\psi_\perp$.}
      \par}
\end{answer}
\item Show that it is possible to build the inviscid potential flow around a cylinder of radius $R$ as the superposition of  $\psi_\text{unif}$ and of a dipolar contribution.
\begin{answer}
The impermeability condition on the cylinder reduces to $\psi = \text{cst}$ along its surface, that is on $r = R$. The only way to fulfill this condition with a streamfunction of the form
$$
\psi = \psi_\text{unif}  + a \psi_{\parallel} + b \psi_{\perp} = Uy - a \frac{y}{r^2} + b \frac{x}{r^2}
 $$
is to set $a = U R^2$ and $b = 0$.
\end{answer}
\item Propose a model for the suction effect, which is characterised with a constant suction velocity  $- u_\text{suction} \be_r$ at the wall.
\begin{answer}
The flow associated to $\psi_\text{source}$ is purely radial and can be represented as:
$$
\bu_\text{source} = \frac{x}{r^2} \be_x + \frac{y}{r^2} \be_y.
$$
At the cylinder surface,
$$
\left.\bu_\text{source}\cdot\bn\right|_{r=R} = \frac{1}{R}.
$$
In order to impose a wall velocity $- u_\text{suction} \be_r$ we need to add the following streamfunction
$$
\psi_\text{suction} = - u_\text{suction} R \theta
$$
\end{answer}
\item Represent with Python the streamlines corresponding to $u_\text{suction} / U = 0, 0.1, 1$.
\begin{answer}
We represent the streamlines associated to:
$$
\psi = Uy - U R^2  \frac{y}{r^2} - u_\text{aspi} R \theta
$$
{\centering
      \includegraphics[width=16cm]{aspi.pdf}
      \par}
\end{answer}
\end{enumerate}
\section{Confined diffusion of a chemical species}
We aim to characterise the impact of walls or boundaries on the diffusion of a contaminant. In order to simplify the study we suppose that diffusion acts along a single axis (this may be seen as a case of translation-invariance along two directions, or of diffusion in a tube). We note $c(x,t)$ the studied concentration field.

We show that a solution to the diffusion equation
\begin{equation}
\pd{c}{t} = D \frac{\partial^2 c}{\partial x^2}
\end{equation}
that exhibit the \textit{scale invariance} property is:
\begin{equation}
c(x,t) = \frac{M}{\sqrt{4 \pi D t}} \exp\lp-\frac{x^2}{4 D t}\rp
\end{equation}
\begin{enumerate}
\item Verify that this field is actually a solution to the diffusion equation.
\item Integrate the total concentration field for a given time. What is the meaning of the constant $M$?
\item Plot with Python the evolution of this field for different instants (we'll set $M = 1$ and $D = 1$).
\end{enumerate}
\vspace{2mm}

As the diffusion equation is linear, any weight sum of elementary solutions will also be a solution. In the following we propose to use this property to build fields that comply with the boundary conditions of the problem. This approach is reminiscent of the use of ``image charges'' in electrostatics to model equipotential surfaces (boundary \textit{``metallisation''}).
\paragraph{$\rhd$ Diffusion near an impermeable wall}
A quantity $M$ of passive scalar is deposited at a distance $\ell$ from an impermeable surface located at $x = 0$.
\begin{enumerate}[resume]
\item What is the boundary condition for the concentration field at $x = 0$ ?
\item By placing a fictitious concentration field symmetric with respect to the wall, show how to build a concentration field respecting the impermeability condition. Give the expression for this field and represent it with Python.
\end{enumerate}
\paragraph{$\rhd$ Diffusion near an absorbing wall}
We now coat the previous wall with a reactant that recombines with the concentration field so that the effective absorbing condition $c(0,t) = 0$ is now verified.
\begin{enumerate}[resume]
\item Propose a strategy to find the evolution of the concentration field in these conditions.
\item What is the concentration flux towards the wall?
\end{enumerate}
\paragraph{$\rhd$ Confined diffusion}
We now consider the diffusion of a contaminant when confined between two impermeable walls located at $x=\pm \ell$. The contaminant is initially deposited at $x=0$.
\begin{enumerate}[resume]
\item Is it sufficient to add three elementary solutions to model the influence of the walls? To answer this question it will be helpful to estimate the flux at each wall.
\item To circumvent this issue, we propose to model the field as a superposition of an infinite sum of elementary solutions located at $x = 2 j \ell, \, j\in \mathbb{Z}$.
\item In order to determine the weight of each term, write the zero-flux condition at $x = \ell$.
\item Plot with Python the evolution of the field for different instants.
\item What is the asymptotic value of the concentration in the gap?
\end{enumerate}
\section{Liquid puddles}
 \noindent A liquid laid over a rigid substrate in the gravity field spontaneously adopts a puddle shape, as illustrated in the facing figure. The liquid has a density $\rho$, a surface tension $\gamma$ with the air, and presents a contact angle $\theta$ with the solid. We denote the gravity with $g$.
\begin{wrapfigure}{L}{5cm}
\centering
\includegraphics{flaque.pdf}
\end{wrapfigure}

\noindent We look for the limit thickness $e_c$ of the puddle far from the edges.
\begin{enumerate}
\item Represent graphically the forces acting on the puddle portion illustrated on the figure.
\item Write the equilibrium condition for the puddle, and deduce the thickness $e_c$ as a function of $\rho$, $g$, $\theta$ and $\gamma$.
\item What is the asymptotic value of $e_c$ in the limit where $\theta \ll 1$ ?
\end{enumerate}
~

\section{Capillary adhesion of a sphere}
\begin{figure}[ht]
    \centering
    \includegraphics[valign=m,page=1]{adhesion_sphere.pdf}
    \hspace{1cm}
    \includegraphics[valign=m,page=2]{adhesion_sphere.pdf}
    \caption{\textbf{Capillary adhesion of a sphere.} Left: a sphere of radius $a$ adheres to a plane thanks to a small meniscus of radius~$\delta$. Right: the meniscus exhibits a curvature radius $r$ much smaller than the sphere radius.}
    \label{fig:adhesion}
\end{figure}
\noindent We consider in this problem the capillary adhesion undergone by a solid sphere of radius $a$ contacting a rigid plane. The sphere adhesion is induced by the presence of a small meniscus made of a perfectly wetting liquid (zero contact angle). The meniscus presents a radial extension $\delta$ that will be supposed much smaller than the radius of the sphere (see figure~\ref{fig:adhesion}). We look for a determination of the vertical component of the capillary force exercée by the meniscus on the sphere, and henceforth noted $F_\text{cap}$. We note the density $\rho$ and the surface tension of the liquid with air $\gamma$. The liquid will be considered quiescent throughout the exercise and we will neglect the influence of gravity.

\begin{enumerate}
\item Justify rapidly why the liquid viscosity cannot enter in the determination of $F_\text{cap}$. Then show using dimensional analysis that:
$$
F_\text{cap} = \gamma a \, \mathcal F(\varepsilon),
$$
where $\varepsilon$ is a small nondimensional parameter which will be explicited. In this exercise we are interested in the limit~$\varepsilon \ll~1$.
\item As the contact angle between the liquid and the solids (both the plane and the bead) is zero, the interface is sharply curved, as indicated figure~\ref{fig:adhesion}. We suppose in particular that the curvature radius $r$ represented on the sketch is much smaller than the interface' second curvature radius. As a result we suppose that the meniscus displays a single radius of curvature $r$ in first approximation. Without calculus, give the sign of the pressure difference between the meniscus and the air $\Delta p = p_\text{ménisque} -p_\text{atm}$ ; is the meniscus in a state of higher or lower pressure with respect to the atmosphere? Explain.
\item In order to track the meniscus extension we introduce the angle $\theta$ represented on figure~\ref{fig:adhesion}. We remind that $\delta \ll a$ and therefore $\theta \ll 1$. Give the relation linking $\delta$ to $a$ and $\theta$ in first approximation.
\end{enumerate}
The force exerted by the liquid meniscus on the bead can be decomposed into two contributions: one due to Laplace pressure, and a second corresponding to the contact line action. Let's focus on the first contribution to start with. In the remaining we will not consider the influence of atmospheric pressure\footnote{In fact we can show that atmospheric pressure contribution naturally cancels out: the intensity of the adhesion force does not depend on it.}.
\begin{enumerate}[resume]
\item Noting $\mathcal S_\text{sphere}$ the portion of the sphere wetted by the meniscus, give the formal expression for the pressure force exerted by the meniscus onto the sphere.
\item Show that we can replace this expression with:
$$
\iint_{\mathcal S_\text{disc}} \!\!\!\Delta p \,\boldsymbol e_z \, \mathrm dS,
$$
where $\mathcal S_\text{disc}$ now represents the surface of the plane wetted by the meniscus.
\item On considering that $\ell \simeq 2r$ (see figure~\ref{fig:adhesion}), propose an estimation of the curvature radius $r$ as a function of $a$ and of $\theta$ to first order in  $\theta$ (we remindd that $\cos \theta = 1 - \tfrac{1}{2} \theta^2 + \tfrac{1}{24} \theta^4 + O(\theta^6)$ for $\theta \ll 1$).
\item Deduce the expression of the pressure contribution in the capillary adhesion force to first order.
\item Explain why the contact line contribution is negligible in this problem.
\item Conclude on the value of the adhesion force, and comment on the dependence with the meniscus volume. What is the limit of the function $ \mathcal F(x)$ of question 1 when $x$ tends to 0?
\end{enumerate}
\section{Curvature of a pendent drop}

\begin{wrapfigure}{L}{5cm}
\centering
\includegraphics[width=5cm]{goutte_eau_jussieu.png}
\end{wrapfigure}

In order to develop a device for surface tension measurement, we wish to write a numerical code to compute the shape of an axisymmetric pendent drop.
To do so it is necessary to know the curvature $\kappa(z)$ of the drop, and to link it to the drop profile $r(z)$ (the equation for the interface is then $r = r(z)$).

\begin{enumerate}
\item Explain why working directly with $r(z)$ is not a good strategy. How does this quantity behave near the drop bottom?
\end{enumerate}
We thus work in the following with the variable $q(z) = r^2(z)$.
\begin{enumerate}
\setcounter{enumi}{1}
\item Propose a function $\mathcal S(r,z)$ that vanishes at the free surface and involves $q(z)$.
\item Compute the normalised gradient of this function. What is the meaning of this field restriction at the drop free surface?
\item Show that the drop curvature $\kappa(z)$ can be expressed as:
\begin{equation}
\kappa(z) = \frac{4 q'(z)^2 - 4q(z) (-2 + q''(z))}{(4 q(z)+q'(z)^2)^{3/2}}.
\end{equation}
\end{enumerate}

\section*{Appendix: differential operators in cylindrical coordinates}
\noindent Let $f(r,\theta,z)$ be a scalar function of space and $\boldsymbol{u}(r,\theta,z) = (u_r(r,\theta,z), u_\theta(r,\theta,z), u_z(r,\theta,z))$ a vector field. We define:
\begin{equation*}
\nabla f = \left(
\begin{array}{c}
\displaystyle\frac{\partial f}{\partial r}\\[1em]
\displaystyle\frac{1}{r}\frac{\partial f}{\partial \theta}\\[1em]
\displaystyle\frac{\partial f}{\partial z}
\end{array}
\right),
\quad \nabla \cdot \boldsymbol{u} = \frac{1}{r} \frac{\partial}{\partial r}\bigg( r u_r\bigg) + \frac{1}{r} \frac{\partial u_\theta}{\partial \theta} + \frac{\partial u_z}{\partial z},
\quad \Delta f = \frac{1}{r} \frac{\partial}{\partial r}\bigg( r \frac{\partial f}{\partial r}\bigg) + \frac{1}{r^2} \frac{\partial^2 f}{\partial \theta^2} + \frac{\partial^2 f}{\partial z^2}
\end{equation*}

\bibliographystyle{jfm}
\bibliography{biblio_tuto}
\end{document}


\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=0.3in]{geometry}
\usepackage{hyperref}
%---------------------------------------
\title{Basic EDA}
\author{Pramod Duvvuri}
\date{March 31, 2019}
\begin{document}
	\maketitle
	The below notes are written to accompany the book \textit{Visualizing Data} by William Cleveland and the S670 class notes written by Prof. Dr. Brad Luen. Before learning Exploratory Data Analysis (EDA), one should be familiar with the basics of statistical concepts. One should also be familiar with Regression. The language of choice is \textbf{R} and the IDE is RStudio and we shall be using the \textit{ggplot2} package of the \textit{tidyverse} to plot, analyze and draw conclusions from the data we have. The references section will contain important resources that will aid you in understanding some tricky concepts that you shall encounter. Regarding the data, always pick datasets that have a lot of observations/rows, the minimum should be at least 100 observations.
	\begin{enumerate}
		\item Differences between CDA/EDA
		\item What is EDA ?
		\begin{enumerate}
			\item Graphing
			\item Fitting
		\end{enumerate}
	    \item The need for EDA
		\item \textbf{Univariate Data} Single Measurement of a Quantitative Variable
		\begin{enumerate}
			\item Histogram
			\begin{enumerate}
				\item Number of Bins
				\item Binwidth
			\end{enumerate}
			\item Density Plot (Frequency Polygon)
			\item Boxplot
			\item ECDF
			\item Normal QQ Plot
			\item Tukey Mean difference Plot
			\item Additive Shift
			\item Fitting a linear model
			\item Residual Fitted Spread Plot
			\item Skewness
			\item Monotone Spread
			\item Transformations
			\begin{enumerate}
				\item Log Transform (log2/log10)
				\item Power Transform
			\end{enumerate}
		\item Spread Location Plot
		\end{enumerate}
	\item \textbf{Bivariate Data} - Paired Measurements of Two Quantitative Variables
	\begin{enumerate}
		\item Correlation (Spearman/Kendall/Pearson)
		\item Scatter Plot
		\item loess curve (Parameters)
		\begin{enumerate}
			\item $\alpha$
			\item $\lambda$
		\end{enumerate}
	    \item Curve with Confidence Intervals
	     \item Skewed Data
	     \begin{enumerate}
	       \item Leptokurtic (Less Area in the Tails)
	     \item Platykurtic (More Area in the Tails)
	     \end{enumerate}
        \item Robust Fits
        \item Sliced Distribution Plots
	\end{enumerate}
	\end{enumerate}
\newpage
\subsection*{References}
\begin{enumerate}
	\item \url{http://docs.statwing.com/interpreting-residual-plots-to-improve-your-regression/}
\end{enumerate}
\subsection*{ggplot2 functions}
\begin{verbatim}
 ECDF - stat_ecdf()
 Histogram - geom_histogram()
 Density Plot - geom_density()
 Boxplot - geom_boxplot()
 Quantile Plot - stat_qq()
 Facet Grid - facet_grid()
 Facet Wrap - facet_wrap() \\ m x n display
 Scatter Plot - geom_point()
 Line - geom_abline()
 QQ Plot - qqplot() \\ Base R function
 Flip Axes - coord_flip()
 Picking Colors - color()
 Details in Histogram - scale_x_continuous()/scale_y_continuous()
 To Set Axis Limits - coord_cartesian()
\end{verbatim}
\end{document}