\section{Declaration of Circuits}

The construction of RKQC is designed to be as similar as possible to C++ programs which contain a number of functions. To this end, circuits are specifiable through a main function, as well as through various submodules that are declared exactly as common C++ functions. Exactly one module must be named "int main", however this module, as well as any module, can call any other module at any time.

\section{Signal Types}

There is one major type of signal in RKQC, the \textbf{qint}. This type forms the basis for the five other types of signals that are derived from this main class:

\begin{itemize}
    \item qbit
    \item zero\_to\_garbage ancilla
    \item zero\_to\_zero ancilla
    \item one\_to\_garbage ancilla
    \item one\_to\_one ancilla
\end{itemize}

All of the above signals can be declared and used in the specification of gates and circuit descriptions. The primary differences are that the "\_to\_garbage" ancilla are ancilla signals that are not guaranteed to maintain their original state during computation, while the two other ancilla types do make this guarantee.

As will be explained later on, all of these signals are of a base type \textbf{qint}, which allows for circuit description flexibility when creating and passing parameters to submodules.

\section{Creating and Using Modules}

At the circuit level, both user defined modules as well as built in modules can be instantiated in the same fashion.

In the example circuit "e008\_swap.cpp", the built in function "cnot" is called, creating CNOT gates on the qubits passed in as parameters:

\begin{lstlisting}
    int main( int argc, char ** argv )
    {
        qbit a;
        qbit b;

        cnot(a, b);
        cnot(b, a);
        cnot(a, b);

        return 0;
    }
\end{lstlisting}

In exactly the same fashion, a circuit designer can create a submodule, and instantiate it within the main function, as in file "e009\_swap\_triples.cpp":

\begin{lstlisting}
    void swap_bits( qint x, qint y){
        cnot(x, y);
        cnot(x, y);
        cnot(x, y);
    }

    int main( int argc, char ** argv ){
        qbit a0;
        qbit a1;
        qbit a2;

        qbit b0;
        qbit b1;
        qbit b2;

        swap_bits(a0, b0);
        swap_bits(a1, b1);
        swap_bits(a2, b2);

        return 0;
    }
\end{lstlisting}

\section{Arrays}

RKQC also allows for multi-dimensional arrays of signals to be declared and used in circuits. To demonstrate this, file "e010\_swap\_triples\_2.cpp" replicates the functionality of "e009\_swap\_triples.cpp" with arrays:

\begin{lstlisting}
    void swap_bits( qint x, qint y){
        cnot(x, y);
        cnot(x, y);
        cnot(x, y);
    }

    int main( int argc, char ** argv ){
        qbit a(3);
        qbit b(3);

        swap_bits( a[0], b[0] );
        swap_bits( a[1], b[1] );
        swap_bits( a[2], b[2] );

        return 0;
    }
\end{lstlisting}

\section{Signals and Gates}

Gates are built in modules that can be instantiated in a variety of methods, with a variety of signal types. Specifically,
\begin{itemize}
    \item single qint signals,
    \item qint arrays,
    \item single qbit signals,
    \item qbit arrays,
    \item single ancilla signals, and
    \item ancilla arrays
\end{itemize}
all are capable of being passed through as parameters to built in gates. For an example of this, file "e002\_signals\_and\_gates.cpp" calls all of the intrinsic built in gates with all of the different signal types:
\begin{lstlisting}
    int main( int argc, char ** argv )
    {

        qbit a;
        qbit b;
        qbit c;
        qbit d(10);
    	qbit e(10);
    	qbit f(10);
    /*------------ Gates Called By Qubit --------------*/
        NOT(a);
        cnot(a,b);
        toffoli(a, b, c);
    /*------------ Gates Called By Register Index -----*/
        NOT(d[0]);
        cnot(d[1], d[9]);
        toffoli(d[0], e[0], c[0]);
    /*------------ Gates Called By Mixed Register Index & Qbits -----*/
        cnot(a, d[0]);
        cnot(e[0], b);
    	toffoli(d[0], a, b);
    	toffoli(a, d[0], b);
    	toffoli(a, b, d[0]);
    	toffoli(d[0], e[0], a);
    	toffoli(d[0], a, e[0]);
    	toffoli(a, d[0], e[0]);
    /*------------ Gates Called By Full Qbit Reg ------*/
    	NOT(d);
    	cnot(d, e);
    	toffoli(d, e, f);

        return 0;
    }
\end{lstlisting}

\section{Assign Value}

A commonly used function of assigning value of one signal to another is built into RKQC in the form of a function:
\begin{lstlisting}
    assign_value_of_b_to_a();
\end{lstlisting}

This function can be instantiated a number of different ways, with integer constants or with two \textbf{qint} signals. These instantiation methods are detailed in file "e004\_assign\_value.cpp":
\begin{lstlisting}
    int main( int argc, char ** argv )
    {
        qbit a;
        assign_value_of_b_to_a(a, "0", 1);

        qbit b(8);
        assign_value_of_b_to_a(b, "1", 8);

        qbit c(8);
        assign_value_of_b_to_a(c, b, 8);

        return 0;
    }
\end{lstlisting}

\section{Integer Arithmetic Modules}

RKQC comes with implementations of quantum adders and multipliers developed in recent theoretical work. For instance, the quantum ripple-carry adder implemented in the function:

\begin{lstlisting}
    a_eq_a_plus_b();
\end{lstlisting}

is derived from work by Wang et. al \cite{adder}, and an example of usage is contained in file "e005\_adder.cpp":

\begin{lstlisting}
    int main( int argc, char ** argv )
    {
        qbit a(32);
        qbit b(32);

        a_eq_a_plus_b(a,b,32);

        return 0;
    }
\end{lstlisting}

Alternatively, an implementation of an ancilla-free addition circuit is also contained within RKQC, derived from earlier work by Cuccaro \cite{Cuccaro}.


\subsubsection{Benchmark Default Curve}\label{ss:benchmark_default_curve}

Default curves can be set up as a difference curve of two yield curves as shown in listing
\ref{lst:defaultcurve_benchmark}. A typical use case is to back out a default curve from an all-in discounting curve
fitted to a series of liquid bond prices (the ``source curve'') and a benchmark curve representing a benchmark funding
level. The default curve can then be used in models consuming a benchmark curve and a default curve.

If $P_B(0,t)$ and $P_S(0,t)$ denote the discount factors of the given benchmark
and source curve respectively the resulting default term structures has survival probabilities

\begin{equation}
S(t) = \left( P_S(0,t) / P_B(0,t) \right) ^ { 1/(1-R) }
\end{equation}

on the given pillar times. Her, $R$ is the specified recovery rate. If the recovery rate is zero, which is the usual
case, the formula simplifies to

\begin{equation}
  S(0,t) = P_S(0,t) / P_B(0,t)
\end{equation}

The interpolation is backward flat in the hazard rate. The meaning of each node is as follows:

\begin{itemize}
\item CurveId: The curve id.
\item CurveDescription: The curve description.
\item Currency: The currency of the curve.
\item Type: Must be set to Benchmark.
\item DayCounter: The day counter used to convert dates to times.
\item RecoveryRate [optional]: The recovery rate for the resulting default curve. Defaults to zero. The recovery rate
  can be a market quote as usual or also a fixed numeric value for this curve type.
\item BenchmarkCurve: The benchmark yield curve, typically this is the standard Ibor curve in the currence
  (e.g. EUR-EURIBOR-6M, USD-Libor-3M, ...)
\item SourceCurve: The all-in discounting curve.
\item Pillars: The pillars on which to match the source curve
\item SpotLag: The pillar dates are derived using the spot lag and the tenors as specified in the Pillars node using the
  specified calendar.
\item Calendar: The calendar used to derive the pillar dates.
\item Extrapolation [Optional]: If set to true, the curve is extrapoalted beyond the last pillar. Defaults to true.
\item AllowNegativeRates [Optional]: If set to true, the check for non-negative instantaneous hazard rate in the result
  curve is disabled, i.e. the relation $P_S(0,t) \leq P_B(0,t)$ is not enforced. This flag should be enabled with care,
  i.e.  a model consuming the resulting default curve must be able to handle negative hazard rates appropriately. On the
  other hand in some situations it is natural that the source curve rates are below the benchmark rates. Defaults to
  false.
\end{itemize}

\begin{longlisting}
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
    <DefaultCurve>
      <CurveId>BOND_YIELD_EUR_OVER_OIS</CurveId>
      <CurveDescription>Default curve derived as bond yield curve over Eonia</CurveDescription>
      <Currency>EUR</Currency>
      <Type>Benchmark</Type>
      <DayCounter>A365</DayCounter>
      <RecoveryRate>RECOVERY_RATE/RATE//SNR/USD</RecoveryRate>
      <BenchmarkCurve>Yield/EUR/EUR6M</BenchmarkCurve>
      <SourceCurve>Yield/EUR/BOND_YIELD_EUR</SourceCurve>
      <Pillars>1Y,2Y,3Y,4Y,5Y,7Y,10Y</Pillars>
      <SpotLag>0</SpotLag>
      <Calendar>TARGET</Calendar>
      <Extrapolation>true</Extrapolation>
      <AllowNegativeRates>false</AllowNegativeRates>
    </DefaultCurve>
  </DefaultCurves>
\end{minted}
\caption{Benchmark default curve}
\label{lst:defaultcurve_benchmark}
\end{longlisting}

\subsubsection{Multi-Section Default Curve}\label{ss:multisection_default_curve}

Default curves can be build by stitching together instantaneous hazard rates from multiple source curves for multiple
date ranges as shown in listing \ref{lst:defaultcurve_multisection}.

The hazard rate of the resulting curve is taken from the $i$th input curve ($i=0,1,2,\ldots$) for dates before the $i$th
switch date and (if $i>0$) on or after the $i-1$th switch date. The day counter of all input curves should be equal to
the day counter of the result curve. The interpolation is hardcoded as backward flat in the hazard rate.

If not given, the recovery rate $R$ is assumed to be zero. The result default curve's survival probabiltiies are
computed as

\begin{equation}
  S(t) = \left[ \left(\frac{P_{S,n}(t)}{P_{S,n}(t_{n})}\right)^{(1-R_n)} \Pi_{i=0}^{n-1} \left(\frac{P_{S,i}(t_{i+1})}{P_{S,i}(t_{i})}\right)^{(1-R_i)} \right] ^ { \frac{1}{1-R} }
\end{equation}

where $P_{S,i}$ is the survival probability of the $i$th source curve, $R_i$ is the associated recovery rate for the
$i$th source curve, $n$ is chosen such that $P_{S,n}$ is the relevant source curve for time $t$ according to the given
switch dates and curve $i$ is relevant for times in $[t_i,t_{i+1}]$.

The meaning of each node is as follows:

\begin{itemize}
\item CurveId: The curve id.
\item CurveDescription: The curve description.
\item Currency: The currency of the curve.
\item Type: Must be set to MutliSection.
\item SourceCurves: The list of input default curves.
\item SwitchDates: The list of dates where we switch from one input curve to the next. The number of switch dates must
  be one less than the number of source curves.
\item DayCounter: The day counter used to convert dates to times.
\item RecoveryRate [optional]: The recovery rate for the resulting default curve. Defaults to zero. The recovery rate
  can be a market quote as usual or also a fixed numeric value for this curve type.
\item Extrapolation [Optional]: If set to true, the curve is extrapoalted beyond the last pillar. Defaults to true.
\end{itemize}

\begin{longlisting}
%\hrule\medskip
\begin{minted}[fontsize=\small]{xml}
<DefaultCurve>
   <CurveId>MyMultiSectionDefaultCurve</CurveId>
   <CurveDescription>Default curve with multiple sections</CurveDescription>
   <Currency>USD</Currency>
   <Type>MultiSection</Type>
   <SourceCurves>
     <SourceCurve>Default/USD/Generic_AA_Curve</SourceCurve>
     <SourceCurve>Default/USD/Generic_B_Curve</SourceCurve>
     <SourceCurve>Default/USD/Generic_C_Curve</SourceCurve>
   </SourceCurves>
   <SwitchDates>
     <SwitchDate>2020-10-01</SwitchDate>
     <SwitchDate>2021-12-01</SwitchDate>
   <SwitchDates>
   <Extrapolation>true</Extrapolation>
   <DayCounter>A365</DayCounter>
   <RecoveryRate>RECOVERY_RATE/RATE/NAME/SR/USD</RecoveryRate>
</DefaultCurve>
\end{minted}
\caption{Multi-Section default curve}
\label{lst:defaultcurve_multisection}
\end{longlisting}


% !TeX spellcheck = en_GB
\documentclass[a4paper, 11pt]{article}
\usepackage[english]{babel}
\usepackage{newtxtext,newtxmath}

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{dramatist}
\usepackage{dirtytalk}
\usepackage{multicol}
\usepackage{soul}
\usepackage{xcolor}

\usepackage[round]{natbib}

\usepackage{geometry}
\geometry{
	a4paper,
	total={150mm,257mm},
	top=20mm,
}
\usepackage{adjustbox}

\usepackage{hyperref}
\hypersetup{
	colorlinks=true,
	linkcolor=blue,
	filecolor=blue,
	urlcolor=blue,
	citecolor=blue
}

\setlength\parindent{0pt}

%opening
\title{\textbf{Natural Language Processing}\\Portfolio II}
\author{\textbf{Leon F.A. Wetzel}\\ Information Science \\ Faculty of Arts - University of Groningen\\ \texttt{l.f.a.wetzel@student.rug.nl}}

\begin{document}

\maketitle

\begin{abstract}

	In this document, you can find the results and explanations for the assignments of the second part of the portfolio for the course Natural Language Processing, taught at the University of Groningen. The corresponding Python code can be found at \url{https://github.com/leonwetzel/natural-language-processing}\footnote{All code will be published after the course has been completed}. Note that version control of Jupyter notebooks is done via \texttt{jupytext}, so do not forget to convert the relevant Python scripts to notebooks yourself!

\end{abstract}

\section{Week 5 - Neural Language Models}

\subsection{Neurons}

\noindent\fbox{%
	\parbox{\textwidth}{%
Consider the basic neuron $y$ with a sigmoid activation $\sigma$ ($g$ in the image).

$$y = \sigma(x*w+b) \qquad \sigma = s(z) = \frac{1}{1 + e^{-z}} \qquad y = \sigma(x*w+b) = \frac{1}{1 + e^{-(x*w+b)}}$$

Given the weight and bias values $x = [0.3, 0.9, 0.1]$, $w = [-0.2, 0.8, -0.6]$, $b = 0.4$ compute the value of $y$ and provide intermediate calculations.
	}%
}\\

\begin{equation} \label{eq1}
	\begin{split}
		y & = \frac{1}{1 + e^{-(w*x+b)}} = \frac{1}{1+e^{-(0.3*-0.2 + 0.9*0.8 + 0.1*-0.6 + 0.4)}} \\
		& = \frac{1}{1 + e^{-0.06 + 0.72 + -0.06 + 0.4}} = \frac{1}{1 + e^{-1}} \\
		& = \frac{1}{1 + 0.36787944117} = 0.73105857863
	\end{split}
\end{equation}

\subsection{Relu}

\noindent\fbox{%
	\parbox{\textwidth}{%
Assume the same basic neuron as in 5.1, but now with ReLU activation, where

$$\sigma = \text{relu}(z) = max(z,0)$$

Give the updated formula for computing $y$, as well as the new value of $y$ (with intermediate calculations).
	}%
}\\

$$y = \sigma(x*w+b) \qquad \sigma = \text{relu}(z) = max(z,\theta) \qquad y = \sigma(x*w+b) = max(x*w+b, 0)$$

\begin{equation} \label{eq1}
	\begin{split}
		y & = max(x*w+b, 0) = max(0.3*-0.2 + 0.9*0.8 + 0.1*-0.6 + 0.4, 0) \\
		& = max(-0.06 + 0.72 + -0.06 + 0.4, 0) \\
		& = max(1, 0) = 1
	\end{split}
\end{equation}

\subsection{Model size}

\noindent\fbox{%
	\parbox{\textwidth}{%
The feed-forward neural network below with a vocabulary of 50.000 words represented by one-hot vectors, a context window of 3 words, a projection layer with $d=100$, a hidden layer $d_h=500$, like the one below, has a total of $P = E + W + U$ trainable parameters. Which of the following has a bigger impact on the number of parameters:

\begin{enumerate}
	\item increasing context-size from 3 to 4, or
	\item increasing vocabulary from 50.000 to 51.000 words
\end{enumerate}
Give the calculations of $P$ to motivate your answer.
	}%
}\\

\begin{equation}
	\left.\begin{aligned}
		E &= d*|V| = 100 * 50.000 = 5.000.000\\
		W &= d_h * 3d = 500 * 3 * 100 = 150.000\\
		U &= |V| * d_h = 50.000 * 500 = 25.000.000\\
		P &= E + W + U = 5.000.000 + 150.000 + 25.000.000 = 30.150.000
	\end{aligned}
	\right\}
	\qquad \text{CS = 3}
\end{equation}

\begin{equation}
	\left.\begin{aligned}
		E &= d*|V| = 100 * 50.000 = 5.000.000\\
		W &= d_h * 4d = 500 * 4 * 100 = 200.000\\
		U &= |V| * d_h = 50.000 * 500 = 25.000.000\\
		P &= E + W + U = 5.000.000 + 200.000 + 25.000.000 = 30.200.000
	\end{aligned}
	\right\}
	\qquad \text{CS = 4}
\end{equation}

\begin{equation}
	\left.\begin{aligned}
		E &= d*|V| = 100 * 51.000 = 5.100.000\\
		W &= d_h * 3d = 500 * 3 * 100 = 150.000\\
		U &= |V| * d_h = 51.000 * 500 = 25.500.000\\
		P &= E + W + U = 5.100.000 + 150.000 + 25.500.000 = 30.750.000
	\end{aligned}
	\right\}
	\qquad \text{V = 51.000}
\end{equation}

Increasing the vocabulary size leads to a higher amount of trainable parameters, contrary to increasing the context-size. The size of vocabulary affects both $E$ and $U$ (opposed to only $W$ when changing the context size), which leads to higher values in the summation.
\subsection{Architectures}

\noindent\fbox{%
	\parbox{\textwidth}{%
Provide at least one example of an NLP application for each of the following task formulations. Try to come up with examples that are different from those mentioned in class.
	}%
}\\

\begin{table}[h]
	\centering
	\begin{tabular}{l|l}
	\textbf{Task formulation}	& \textbf{Example(s)} \\ \hline
	One-to-many	& Poem generation \\
	Many-to-one	& Language detection \\
	Many-to-many (seq2seq)	& Document summarization \\
	Many-to-many (sequence labelling) & Semantic tagging
	\end{tabular}
	\caption{Examples per task formulation for RNN's}
	\label{tab:examples_rnn}
\end{table}

\subsection{Probing}

\noindent\fbox{%
	\parbox{\textwidth}{%
Think of a grammatical phenomenon in a language of your choice, and come up with at least 10 example sentences to probe whether the model makes the correct predictions. Think of cases where the context makes it clear that the mask has to be plural or singular, that a verb has to have a particular form (like plural or singular, or participle or infinitive), that a specific (personal, possessive, reflexive) pronoun has to be used, that an adjective or noun has to have a specific inflection (like in German and more generally in languages with a rich case and/or gender marking system). There is a host of literature on this, see for instance Marvin and Linzen (for English) and Sahin et al (for multilingual probes).
	}%
}\\

\begin{enumerate}
	\item De minister-president heeft [MASK] handtekening gezet onder de bepaling.
		\begin{enumerate}
		\item de;
		\item een;
		\item geen;
		\item zijn;
		\item deze;
	\end{enumerate}
	\item De ontwikkelaars onthouden [MASK] van commentaar op hun code.
	\begin{enumerate}
		\item software;
		\item ook;
		\item gebruik;
		\item code;
		\item niet;
	\end{enumerate}
	\item Het ijsje begon met [MASK] toen de zon doorbrak.
		\begin{enumerate}
		\item ij;
		\item ,;
		\item zon;
		\item :;
		\item water;
	\end{enumerate}
	\item De universiteit investeerde [MASK] in onderzoeken naar kunstmatige intelligentie.
	\begin{enumerate}
		\item ook;
		\item verder;
		\item \#\#n;
		\item vooral;
		\item zich;
	\end{enumerate}
	\item Het zwaard van Damocles hing boven [MASK] hoofd.
	\begin{enumerate}
		\item zijn;
		\item het;
		\item de;
		\item haar;
		\item hun;
	\end{enumerate}
	\item De kaas uit Duitsland was niet [MASK] dan de kaas uit Nederland.
	\begin{enumerate}
		\item groter;
		\item meer;
		\item kleiner;
		\item anders;
		\item beter;
	\end{enumerate}
	\item De diplomaten dronken uit [MASK] bekers terwijl het ongeval plaatsvond.
	\begin{enumerate}
		\item de;
		\item in;
		\item het;
		\item uit;
		\item en;
	\end{enumerate}
	\item Het weer was onstuimig, het [MASK] namelijk vrij hard.
		\begin{enumerate}
		\item was;
		\item weer;
		\item is;
		\item kwam;
		\item had;
	\end{enumerate}
	\item De scholen sloten hun deuren [MASK].
		\begin{enumerate}
		\item in;
		\item aan;
		\item op;
		\item ';
		\item .;
	\end{enumerate}
	\item Jan had gisteren [MASK] voet gestoten tegen de tafelpoot.
		\begin{enumerate}
		\item en;
		\item met;
		\item van;
		\item aan;
		\item de;
	\end{enumerate}
\end{enumerate}

\noindent\fbox{%
	\parbox{\textwidth}{%
Give at least ten example sentences with a [MASK] and a list of targets that illustrate a specific grammatical phenomenon in a language of your choice. Describe what the grammatical phenomenon is you are investigating. Use the probe function for testing. Try to include both easy sentences (where the model should do well) as well as hard sentences (where there are words in the context that might lead to confusion, or where the clue words are far away from the mask). For languages other than Dutch or English, make sure to include enough explanation so that examples and tests are clear to a non-native speaker.

Describe how well the model did on your probe sentences. Where there any cases where the model made the wrong decision?
	}%
}\\

Please see the notebook for the sentences that were tested. The model did quite well on the provided probe sentences. There is a noticeable bias present in the model when it comes to gender and pronoun usage; him/his often comes on tops when such cases are masked. Although the model performs well in most cases, it did make a slight error in the sentence \texttt{The dog [MASK] hunting for food in the evenings.}, where \textit{are} apparently has a higher score than \textit{was}.

\section{Week 6 - Dependency Parsing}

\subsection{Evaluation}

We are given the following sentence: \texttt{I hate to put a little pressure on you}\\

Our total amount of nodes ($N$) is 8, so our formulas would look like...

	\begin{equation}
		UAS = \frac{\text{\# of nodes with correct parent}}{8}
	\end{equation}

	\begin{equation}
		LAS = \frac{\text{\# of nodes with correct parent and edge label}}{8}
	\end{equation}

For the example on the upper side, the scores are as follows:

\noindent\begin{minipage}{.5\linewidth}
	\begin{equation}
		UAS = \frac{8}{8} = 1
	\end{equation}
\end{minipage}%
\begin{minipage}{.5\linewidth}
	\begin{equation}
		LAS = \frac{8}{8} = 1
	\end{equation}
\end{minipage}\\

For the example on the lower side, the scores are as follows:

\noindent\begin{minipage}{.5\linewidth}
	\begin{equation}
		UAS = \frac{6}{8} = 0.75
	\end{equation}
\end{minipage}%
\begin{minipage}{.5\linewidth}
	\begin{equation}
		LAS = \frac{3}{8} = 0.375
	\end{equation}
\end{minipage}

\subsection{Transition-based Parsing}

\noindent\fbox{%
	\parbox{\textwidth}{%
Describe the states and actions that a transition-based parser has to go through to produce the gold standard (top) analysis of the sentence
in question 6.1. A state consists of a stack, input buffer, and set of dependency relations. An action is either SHIFT, RIGHTARC, or LEFTARC,
where you can assume that the RIGHTARC and LEFTARC actions also produce the correctly labeled dependency relations.
	}%
}\\

We are given the following sentence: \texttt{I hate to put a little pressure on you}\\

We assume that the upper example from exercise 2.1 is the gold standard.\\

\adjustbox{max width=\columnwidth}{
%\begin{table}[h]
	\begin{tabular}{l|l|l|l|l}
	Step & Stack & Word List & Action & Relation Added \\ \hline
	0	& [root] & [I, hate, to, put, a, little, pressure, on, you] & SHIFT &  \\
	1	& [root, I] & [hate, to, put, a, little, pressure, on, you] & SHIFT &  \\
	2	& [root, I, hate] & [to, put, a, little, pressure, on, you] & LEFTARC & (I $\leftarrow$ hate) \\
	3	& [root, hate] & [to, put, a, little, pressure, on, you] & SHIFT &  \\
	4	& [root, hate, to] & [put, a, little, pressure, on, you] & SHIFT &  \\
	5	& [root, hate, to, put] & [a, little, pressure, on, you] & LEFTARC & (to $\leftarrow$ put) \\
	6	& [root, hate, put] & [a, little, pressure, on, you] & SHIFT &  \\
	7	& [root, hate, put, a] & [little, pressure, on, you] & SHIFT &  \\
	8	& [root, hate, put, a, little] & [pressure, on, you] & SHIFT &  \\
	9	& [root, hate, put, a, little, pressure] & [on, you] & LEFTARC & (little $\leftarrow$ pressure) \\
	10	& [root, hate, put, a, pressure] & [on, you] & LEFTARC & (a $\leftarrow$ pressure) \\
	11	& [root, hate, put, pressure] & [on, you] & RIGHTARC & (put $\rightarrow$ pressure) \\
	12	& [root, hate, put] & [on, you] & SHIFT &  \\
	13	& [root, hate, put, on] & [you] & SHIFT &  \\
	13	& [root, hate, put, on, you] & [] & LEFTARC & (on $\leftarrow$ you) \\
	14	& [root, hate, put, you] & [] & RIGHTARC & (put $\rightarrow$ you) \\
	15	& [root, hate, put] & [] & RIGHTARC & (hate $\rightarrow$ put) \\
	15	& [root, hate] & [] & RIGHTARC & (root $\rightarrow$ hate) \\
	16	& [root] & [] & Done & \\ \hline
	\end{tabular}
\centering
%\caption{Transition-based parsing of the sentence \textit{I hate to put a little pressure on you}.}
%\end{table}
}

\subsection{Crossing arcs}

\noindent\fbox{%
	\parbox{\textwidth}{%
It is not possible to produce the analysis for the sentence below using a transition-based parser. Give the state and input buffer for the point where the problem arises and explain why there is no sequence of actions that leads to a correct parse.
	}%
}\\

We are given the following sentence: \texttt{Who did Kim talk to}\\

	\begin{table}[h]
	\begin{tabular}{l|l|l|l|l}
		Step & Stack & Word List & Action & Relation Added \\ \hline
		0	& [root] & [Who, did, Kim, talk, to] & SHIFT &  \\
		1	& [root, Who] & [did, Kim, talk, to] & SHIFT &  \\
		2	& [root, Who, did] & [Kim, talk, to] & SHIFT &  \\
		3	& [root, Who, did, Kim] & [talk, to] & SHIFT &  \\
		4	& [root, Who, did, Kim, talk] & [to] & LEFTARC & (Kim $\leftarrow$ talk) \\
		5	& [root, Who, did, talk] & [to] & LEFTARC & (did $\leftarrow$ talk) \\
		6	& [root, Who, talk] & [to] & LEFTARC & (Who $\leftarrow$ talk) \\
		\textbf{7}	& \textbf{[root, talk]} &\textbf{ [to]} & \textbf{SHIFT (?)} &  \\
		? & [root] & [] & Done &
	\end{tabular}
	\centering
	%\caption{Transition-based parsing of the sentence \textit{I hate to put a little pressure on you}.}
	\end{table}

As we can see in the table above, the problem arises near step 7. As a result of the previous LEFTARC action, we removed the word \textbf{Who} which would be needed for a later RIGHTARC operation. The remaining word \textbf{talk} cannot be coupled with \textbf{to}, as there is no sensible relation between these words. We cannot couple \textbf{root} and \textbf{talk} at this moment, as \textbf{to} is still part of either the stack or word list.

\subsection{Tiny-dependency parser}

\noindent\fbox{%
	\parbox{\textwidth}{%
Improve the oracle of the dependency parser in the notebook and train and evaluate it on the data. See notebook for details.
	}%
}\\

\section{Week 7 - Word Sense Disambiguation}

See the attached notebook for the results of the various experiments.

\end{document}


\documentclass[accentcolor=tud2c,usenames,dvipsnames,colorbacktitle,inverttitle,landscape,german,presentation,t]{tudbeamer}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{slashed}
\usepackage{color}
\usepackage{physics}
\usepackage{graphicx}
\usepackage{braket}
% \usepackage[utf8]{inputenc}

\begin{document}

  \input{macros.tex}

  \setbeamerfont{footline}{size=\fontsize{1}{1}\selectfont}

  \title{Chiral Green's functions and Ward identities}
  \subtitle{\small{Matthias Heinz}}
  \author{Matthias Heinz}
  \institute[Institut f\"ur Kernphysik, TU Darmstadt]{Institut f\"ur Kernphysik, TU Darmstadt}
  \date{January 30, 2020}

  \setbeamertemplate{section in toc}[ball unnumbered]
  \setbeamertemplate{subsection in toc}[ball unnumbered]

  \nocite{*}

  \begin{titleframe}
    \vskip3em
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        Outline:
          \vskip2em
        \begin{enumerate}
          \item Ward identities in a $\U{1}$ example
          \vskip2em
          \item Chiral Ward identities via the algebra of currents
          \vskip2em
          \item The chiral generating functional
        \end{enumerate}
      \end{column}
    \end{columns}
      % \includegraphics[width=0.75\textwidth]{figures/05/critical_point_illustration}
      % \\\footnotesize{Stephanov 2009}
  \end{titleframe}

  \section{Ward identities in a $\U{1}$ example}

  \begin{frame}
    \frametitle{Scalar $\Phi^4$ theory with a global $\U{1}$ symmetry}
    \begin{equation*}
      \mathcal{L}^0 = \frac{1}{2}(\dmulop{\Phidag}\dmuhip{\Phi})
      - \frac{m^2}{2} \Phidag \Phi - \frac{\lambda}{4} (\Phidag \Phi)^2
    \end{equation*}

    \vskip3em

    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        Global $\U{1}$ symmetry:

        \begin{equation*}
        \begin{array}{cc}
          \Phi \rightarrow (1 + i \epsilon) \Phi, &
          \Phidag \rightarrow (1 - i \epsilon) \Phidag, \\
        \end{array}
        \end{equation*}

        \vskip1em

        Conserved Noether current:

        \begin{equation*}
          \Jmu = i (\dmuhip{\Phidag} \Phi - \Phidag \dmuhip{\Phi})
        \end{equation*}
      \end{column}
    \end{columns}
  \end{frame}

  \begin{frame}
    \frametitle{Scalar $\Phi^4$ theory with a global $\U{1}$ symmetry}

    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        Example Green's function:

        \begin{equation*}
          \Gmu(x,y,z) = \mel*{0}{\timeorder{\Phi(x)\Jmu(y)\Phidag(z)}}{0},
        \end{equation*}

        \vskip1em

        Symmetry constraint:

        \begin{equation*}
          \begin{array}{cc}
            \Jmu \rightarrow \Jmu, &
            \Gmu \rightarrow \Gmu, \\
          \end{array}
        \end{equation*}

        \vskip1em

        Example Ward identity:

        \begin{align*}
          \dmulox{\Gmu(x,y,z)}{y} = & (\delta^4(y-x) - \delta^4(y-z))\mel*{0}{\timeorder{\Phi(x) \Phidag(z)}}{0} \\
                                    & + \mel*{0}{\timeorder{\Phi(x) \dmulopx{\Jmu(y)}{y} \Phidag(z)}}{0},
        \end{align*}
      \end{column}
    \end{columns}
  \end{frame}

  % \begin{frame}
  %   \frametitle{Recap of path integral formalism \\ Maybe just skip and explain on actual generating functional}
  %   \begin{columns}[c]
  %     \begin{column}{0.8\textwidth}
  %       Green's functions via path integral:
  %
  %       \begin{equation*}
  %         \mel{0}{\timeorder{\Phidag(x) \Phi(y)}}{0} =
  %         \int \mathcal{D}\Phistar \mathcal{D}\Phi \Phistar(x) \Phi(y) \exp(i S[\Phi, \Phistar]),
  %       \end{equation*}
  %
  %       Generating functional:
  %
  %       \begin{equation*}
  %       W[j, j^{*}] = \mel*{0}{\timeorder{\exp(i\int d^4x[j(x) \Phidag (x) + j^{*}(x) \Phi(x)])}}{0},
  %       \end{equation*}
  %
  %       Green's functions via functional derivatives:
  %
  %       \begin{equation*}
  %         \mel{0}{\timeorder{\Phidag(x) \Phi(y)}}{0} = \left.\left(-i\frac{\delta}{\delta j(x)} \right) \left(-i\frac{\delta}{\delta j^{*}(y)} \right) W[j, j^{*}] \right\rvert_{j=0,j^{*}=0},
  %       \end{equation*}
  %     \end{column}
  %   \end{columns}
  % \end{frame}

  \begin{frame}
    \frametitle{Generating functional for $\Phi^4$}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        Generating functional:
        \begin{equation*}
          W[j, j^{*}, j_{\mu}] = \mel*{0}{\timeorder{\exp{i\int d^4x[j(x) \Phidag (x) + j^{*}(x) \Phi(x) + j_{\mu}(x) \Jmu(x)]}}}{0},
        \end{equation*}
        Our example Green's function:
        \begin{equation*}
          \Gmu(x,y,z) = \left.(-i)^3 \frac{\delta^3 W[j, j^{*}, j_{\mu}]}{\delta j^{*}(x) \delta j_{\mu}(y) \delta j(z)}\right\rvert_{j=0,j^{*}=0,j_{\mu}=0},
        \end{equation*}
        As path integral:
        \vskip-1em
    \begin{equation*}
      \only<1>{W[j, j^{*}, j_{\mu}] = \int \mathcal{D}\Phistar \mathcal{D}\Phi \exp(i \int d^4x[\mathcal{L}^{0}(x) + \mathcal{L}_{\textrm{ext}}(x)]),}
      \only<2>{W[j, j^{*}, j_{\mu}] = \int \mathcal{D}\Phistar \mathcal{D}\Phi \exp(i S[\Phi, \Phistar, j, j^{*}, j_{\mu}]),}
    \end{equation*}
    \only<1>{
      \begin{equation*}
        \mathcal{L}_{\textrm{ext}}(x) = j(x) \Phi^{*} (x) + j^{*}(x) \Phi(x) + j_{\mu}(x) \Jmu(x),
      \end{equation*}
    }
    \only<2>{Note: Only in the presence of external fields can we demand $\mathcal{L}$ remain invariant under \textit{local} transformations.}
      \end{column}
    \end{columns}

  \end{frame}

  \begin{frame}
    \frametitle{The master equation for $\Phi^4$}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}

    Demanding $S[\Phi, \Phidag, j, j^{*}, j_{\mu}] = S[\Phi^{\prime}, \Phi^{\prime \dagger}, j^{\prime}, j^{\prime*}, j^{\prime}_{\mu}]$ gives:
    \begin{align*}
    j(x) & \rightarrow (1 + i \epsilon(x))j(x), \\
    j^{*}(x) & \rightarrow (1 - i \epsilon(x))j^{*}(x), \\
    j_{\mu}(x) & \rightarrow j_{\mu} - \dmulop{\epsilon(x)},
    \end{align*}
    % \begin{equation*}
    %   \begin{array}{ccc}
    %     j(x) \rightarrow (1 + i \epsilon(x))j(x), &
    %     j^{*}(x) \rightarrow (1 - i \epsilon(x))j^{*}(x), &
    %     j_{\mu}(x) \rightarrow j_{\mu} - \dmulop{\epsilon(x)}, \\
    %   \end{array}
    % \end{equation*}
    We observe that this also means:
    \begin{equation*}
      W[j, j^{*}, j_{\mu}] = W[j^{\prime}, j^{\prime*}, j^{\prime}_{\mu}],
    \end{equation*}
    Master equation:
    \begin{equation*}
      \only<1>{0 = \int d^{4}x \epsilon(x) \left[ i j(x) \frac{\delta}{\delta j(x)} - i j^{*}(x) \frac{\delta}{\delta j^{*}(x)} + \dmulox{\frac{\delta}{\delta j_{\mu}(x)}}{x} \right] W[j, j^{*}, j_{\mu}],}
      \only<2>{0 = \left[ j(x) \frac{\delta}{\delta j(x)} - j^{*}(x) \frac{\delta}{\delta j^{*}(x)} - i \dmulox{\frac{\delta}{\delta j_{\mu}(x)}}{x} \right] W[j, j^{*}, j_{\mu}],}
    \end{equation*}
      \end{column}
    \end{columns}
  \end{frame}

  \begin{frame}
    \frametitle{QCD in the chiral limit}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        \begin{equation*}
\mathcal{L}_{\textrm{QCD}}^{0} = \sum_{l=u,d,s}(\bar{q}_{R,l}i\slashed{D}q_{R,l} + \bar{q}_{L,l}i\slashed{D}q_{L,l})
- \frac{1}{4} \mathcal{G}_{a\mu\nu} \mathcal{G}_{a}^{\mu\nu},
        \end{equation*}

        Symmetry group:
        \begin{equation*}
        \U{3}_{L}\times\U{3}_{R} \xrightarrow[]{\textrm{Quantization}}\suxsuxu
        \end{equation*}
      \end{column}
    \end{columns}

    \vskip3em
    \begin{columns}[t]
      \begin{column}{0.45\textwidth}
        Conserved currents:
        \begin{itemize}
          \item $\vecoct = R_{a}^{\mu} + L_{a}^{\mu} = \vecoctexpl$,
          \item $\axvoct = R_{a}^{\mu} - L_{a}^{\mu} = \axvoctexpl$,
          \item $\vecsing = R^{\mu} + L^{\mu} = \vecsingexpl$,
        \end{itemize}
      \end{column}
      \begin{column}{0.45\textwidth}
        Color-neutral quadratic forms:
        \begin{itemize}
          \item $\scalardensityx{a}{x} = \scalardensityexplx{a}{x}$,
          \item $\pscalardensityx{a}{x} = \pscalardensityexplx{a}{x}$,
        \end{itemize}
        Note: $a=0,...,8$
      \end{column}
    \end{columns}
  \end{frame}

  \begin{frame}
    \frametitle{Chiral Green's functions and Ward identities \\ \small{\textit{An example}}}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
      Green's function:
\begin{equation*}
\Gmu_{APab}(x, y) = \mel*{0}{\timeorder{\axvoct(x)\pscalardensityx{b}{y}}}{0},
\end{equation*}

      Ward identity:
      \end{column}
    \end{columns}
    \vskip1em

\begin{equation*}
\dmulox{\Gmu_{APab}(x,y)}{x} = \delta(x_0 - y_0) \mel*{0}{\commutator{A_{a}^{0}(x)}{P_{b}(y)}}{0}
+ \mel*{0}{\timeorder{\dmulopx{\axvoct(x)}{x}\pscalardensityx{b}{y}}}{0},
\end{equation*}

\vskip1em

    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        Generalization to any $(n+1)$-point functions:
        \begin{align*}
        % \begin{equation*}
        \partial_{\mu}^{x} &\mel*{0}{\timeorder{\Jmu(x)A_1(x_1)\ldots A_n(x_n)}}{0} = \mel*{0}{\timeorder{\dmulopx{\Jmu(x)}{x}A_1(x_1)\ldots A_n(x_n)}}{0} \\
                           & + \delta(x^{0} - x_{1}^{0}) \mel*{0}{\timeorder{[J_{0}(x), A_{1}(x_{1})] A_{2}(x_2)\ldots A_n(x_n)}}{0} \\
                           & + \ldots \\
                           & + \delta(x^{0} - x_{n}^{0}) \mel*{0}{\timeorder{A_{1}(x_1)A_2(x_2) \ldots [J_{0}(x), A_{n}(x_{n})] }}{0},
        % \end{equation*}
        \end{align*}
      \end{column}
    \end{columns}
  \end{frame}

  \begin{frame}
    \frametitle{Algebra of currents}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        \begin{itemize}
          \item We could now evaluate $[J_{0}(x), A_{n}(x_{n})]$ commutators
          \item \textit{But we have to be careful}
          \item QED current example:
          \begin{itemize}
            \item $[J_0(t, \vec{x}), J_{i}(t, \vec{y})] = 0$
            \item from which one can show $\mel*{0}{J_0(t, \vec{x})}{n} = 0$
          \end{itemize}
          \item Fix: Schwinger term in original charge-current commutator
          \item In general, charge-current commutation relations only determined up to a derivative of a delta function
          \item Another problem: used naive time-ordered product rather than \textit{covariant} time-ordered product
          \item Seagull terms from covariant time-ordering cancel with Schwinger terms (Feynman)
        \end{itemize}
      \end{column}
    \end{columns}
  \end{frame}

  \begin{frame}
    \frametitle{Chiral generating functional}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        Extend chiral Lagrangian to include external fields (sources):
\begin{equation*}
\mathcal{L} = \mathcal{L}^{0}_{\textrm{QCD}} + \lext
\end{equation*}

with

\begin{equation*}
  \only<1>{\lext = \sum_{a = 1}^{8} v_a^{\mu} \vecoct + \frac{1}{3} v_{(s)}^{\mu} \vecsing + \sum_{a=1}^{8} a_a^{\mu} \axvoct
  - \sum_{a=0}^{8}s_{a} \scalardensity{a} + \sum_{a=0}^{8}p_{a} \pscalardensity{a},}
  \only<2>{\color{black}\lext = \bar{q} \gamma_{\mu} \left( \color{red}v^{\mu} \color{black}+ \frac{1}{3} \color{red}v_{(s)}^{\mu} \color{black}+ \gamma_5 \color{red}a^{\mu} \color{black}\right) q
  - \bar{q} ( \color{red}s \color{black}- i \gamma_5 \color{red}p\color{black}) q,}
\end{equation*}

\vskip1em

\pause
using definitions

\begin{equation*}
\begin{array}{cc}
  v^{\mu} = \sum_{a=1}^{8} v_{a}^{\mu} \frac{\lambda_a}{2}, &
a^{\mu} = \sum_{a=1}^{8} a_{a}^{\mu} \frac{\lambda_a}{2}, \\
\end{array}
\end{equation*}
\begin{equation*}
\begin{array}{cc}
s = \sum_{a=0}^{8} s_{a} \lambda_a, &
p = \sum_{a=0}^{8} p_{a} \lambda_a, \\
\end{array}
\end{equation*}

      \end{column}
    \end{columns}
  \end{frame}

  \begin{frame}
    \frametitle{Chiral generating functional \\ \small{\textit{Some examples}}}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        Generating functional:

\begin{equation*}
W[v,a,s,p] = \mel*{0}{\timeorder{\exp{i \int d^4x \lext(x)}}}{0}_{0},
\end{equation*}

\only<1>{Chiral limit example:}
\only<2>{Physical example:}

\begin{equation*}
  \only<1>{\bar{u} u = \frac{1}{2} \bar{q} \left(\sqrt{\frac{2}{3}} \lambda_0 + \lambda_3 + \frac{1}{\sqrt{3}} \lambda_8 \right) q,}
\end{equation*}
      \end{column}
    \end{columns}
\begin{equation*}
  \only<1>{\mel*{0}{\bar{u}(x) u(x)}{0}_{0} = \frac{i}{2} \left. \left[ \sqrt{\frac{2}{3}} \frac{\delta}{\delta s_0(x)} + \frac{\delta}{\delta s_3(x)} + \frac{1}{\sqrt{3}} \frac{\delta}{\delta s_8(x)} \right] W[v,a,s,p]\right\rvert_{v=a=s=p=0},}
  \only<2>{\mel*{0}{\timeorder{\axvoct(x)\pscalardensityx{b}{y}}}{0} = (-i)^2 \left. \frac{\delta^2}{\delta a_{a\mu}(x) \delta p_{b}(y)} W[v,a,s,p] \right\rvert_{v=a=p=0,s=\textrm{diag}(m_{u}, m_{d}, m_{s})},}
\end{equation*}

  \end{frame}

  \begin{frame}
    \frametitle{Constraining external fields}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        We demand of $\mathcal{L}$ that it is:
        \begin{itemize}
          \item Hermitian Lorentz scalar
          \item Even under $P$ and $C$
          \item Invariant under local chiral transformations
        \end{itemize}

        \pause

        Parity:
\begin{align*}
v^{\mu} &\xrightarrow[]{P} v_{\mu}, \\
v^{\mu}_{(s)} &\xrightarrow[]{P} v^{(s)}_{\mu}, \\
a^{\mu} &\xrightarrow[]{P} - a_{\mu}, \\
s &\xrightarrow[]{P} s, \\
p &\xrightarrow[]{P} -p,
\end{align*}

      \end{column}
    \end{columns}
  \end{frame}

  \begin{frame}
    \frametitle{Constraining external fields}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        We demand of $\mathcal{L}$ that it is:
        \begin{itemize}
          \item Hermitian Lorentz scalar
          \item Even under $P$ and $C$
          \item Invariant under local chiral transformations
        \end{itemize}

        Charge conjugation:
\begin{align*}
v_{\mu} &\xrightarrow[]{C} -v^{T}_{\mu}, \\
v_{\mu}^{(s)} &\xrightarrow[]{C} -v^{(s)T}_{\mu}, \\
a_{\mu} &\xrightarrow[]{C} a^{T}_{\mu}, \\
s &\xrightarrow[]{C} s^{T}, \\
p &\xrightarrow[]{C} p^{T},
\end{align*}

      \end{column}
    \end{columns}
  \end{frame}

  \begin{frame}
    \frametitle{Constraining external fields}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        Local chiral transformation:

        \begin{equation*}
          \begin{array}{cc}
            q_{R} \rightarrow \exp{-i\frac{\Theta(x)}{3}} V_{R}(x) q_{R}, &
q_{L} \rightarrow \exp{-i\frac{\Theta(x)}{3}} V_{L}(x) q_{L},
          \end{array}
\end{equation*}

        After splitting our external fields into $r_{\mu}=v_{\mu}+a_{\mu}$ and $l_{\mu}=v_{\mu}-a_{\mu}$:
\begin{align*}
  r_{\mu} &\rightarrow V_{R} r_{\mu} V_{R}^{\dagger} + i V_{R} \dmulop{V_{R}^{\dagger}}, \\
  l_{\mu} &\rightarrow V_{L} l_{\mu} V_{L}^{\dagger} + i V_{L} \dmulop{V_{L}^{\dagger}}, \\
  v_{\mu}^{(s)} &\rightarrow v_{\mu}^{(s)} - \dmulop{\Theta}, \\
  s + ip &\rightarrow V_{R} (s + ip) V_{L}^{\dagger}, \\
  s - ip &\rightarrow V_{L} (s - ip) V_{R}^{\dagger},
\end{align*}
      \end{column}
    \end{columns}
  \end{frame}

  \begin{frame}
    \frametitle{Key takeaways}
    \begin{columns}[c]
      \begin{column}{0.8\textwidth}
        $\U{1}$ example:
        \begin{itemize}
          \item Local invariance of generating functional contains all Ward identities of theory
        \end{itemize}

        Chiral Ward identities from algebra of currents:
        \begin{itemize}
          \item Using the algebra of currents, one must tread with caution (Schwinger and seagull terms)
        \end{itemize}

        Generating functional for chiral Green's functions:
        \begin{itemize}
          \item Allows one to compute Green's functions for chiral limit and ``real" world
          \item Can constrain transformation behavior of external fields by invariance of generating functional under local transformations
        \end{itemize}
      \end{column}

    \end{columns}
  \end{frame}

  %yank 7

  % \begin{frame}
  %   \frametitle{Frame template}
  %   \begin{columns}[c]
  %     \begin{column}{0.8\textwidth}
  %     \end{column}
  %   \end{columns}
  % \end{frame}

  \begin{frame}[allowframebreaks]
    \frametitle{References}
    \bibliographystyle{apalike}
    \bibliography{bibfile}
  \end{frame}

\end{document}


\documentclass[main.tex]{subfiles}
\begin{document}

\marginpar{Tuesday\\ 2020-10-6, \\ compiled \\ \today}

As we said earlier, massive stars go type-2 supernova: this corresponds to Core-Collapse.

Compact objects are quite common in the galaxy.

% Non si può preparare un matrimonio con i fichi secchi.

A compact object is one for which the ratio of the gravitational radius \(R_g = GM / c^2\) is comparable to the radius of the true object.
For a white dwarf, the ratio is of the order of \num{e3}.

We then need GR in order to deal with them.
Let us quickly go over exact solutions of the Einstein Field Equations.

\section{The Schwarzschild external solution}

This lecture, we consider the vacuum Schwarzschild solution.
The most general line element which is spherically symmetric (invariant under spatial rotations)
must be made up of elements which are themselves invariant under spatial rotations.
We will use spherical coordinates: \(r, \theta , \varphi , t\).

In flat spacetime, the line element reads
%
\begin{align}
\dd{s^2} = - c^2 \dd{t^2} + \dd{r^2} + r^2 \qty( \dd{\theta^2} + \sin^2 \theta \dd{\varphi^2})
\,,
\end{align}
%
and our Schwarzschild solution will need to reduce to this in some limit.

The spatial line element is given by
%
\begin{align}
\dd{\vec{r}} \cdot \dd{\vec{r}} =  \dd{r^2} + r^2 \qty( \dd{\theta^2} + \sin^2 \theta \dd{\varphi^2}) = g_{ij} \dd{x^{i}} \dd{x^{j}}
\,.
\end{align}

Then, the most general spherically symmetric line element will read
%
\begin{align}
\dd{s^2} =  F(r ,t) \dd{t^2} + M(r, t) \dd{r^2} + G(r, t) \dd{r} \dd{t} + C(r, t) r^2 \qty( \dd{\theta^2} + \sin^2 \theta \dd{\varphi^2})
\,,
\end{align}
%
however, we can redefine the radial coordinate in order to remove the function multiplying the angular term, so we get
%
\begin{align}
\dd{s^2} = F \dd{t^2} + M \dd{r^2}  + G \dd{r} \dd{t}
+ r^2 \qty(\dd{\theta^2} + \sin^2\theta \dd{\varphi^2})
\,.
\end{align}

We can also introduce a new time variable:
%
\begin{align}
\dd{t'} = \dd{t} + \psi (r, t) \dd{r}
\,.
\end{align}

If \(\psi = G / 2F\), then we remove the mixed term, and then we are left with the expression
%
\begin{align}
\dd{s^2} = -B (r, t) \dd{t^2} + A(r, t) \dd{r^2} + r^2 \dd{\Omega^2}
\,.
\end{align}

However, we have not yet determined the two functions, and we have not said anything about the Einstein Field Equations, which are
%
\begin{align}
R_{\mu \nu } - \frac{1}{2} g_{\mu \nu } R = 8 \pi G T_{\mu \nu }
\,.
\end{align}

In vacuo, the stress-energy tensor vanishes.
The curvature scalar must vanish (we can show this by contracting the EFE with the inverse metric), so the equations reduce to \(R_{\mu \nu } = 0\).
We restrict ourselves to the static case.

The linearly independent components of the Ricci tensor read
%
\begin{align}
R_{0}^{0} = \frac{B''}{2AB} - \frac{A' B'}{4 A'' B}
- \frac{B^{\prime 2}}{4AB^2} + \frac{B'}{rAB} &= 0 \\
R_{1}^{1} = \frac{B''}{2AB} - \frac{A' B'}{4 A'' B}
- \frac{B^{\prime 2}}{4AB^2} + \frac{A'}{rA^2} &= 0 \\
R_{2}^{2} = \frac{1}{4rA} \qty(\frac{B'}{B} - \frac{A'}{A})
+ \frac{1}{r^2} \qty( \frac{1}{A} - 1)
\,.
\end{align}

Computing \(R^{0}_{0} - R^{1}_{1} = 0\) we find
%
\begin{align}
\frac{1}{rA} \qty(\frac{B'}{B} + \frac{A'}{A} )&= 0  \\
\dv{\log (AB)}{r} &= 0
\,,
\end{align}
%
so \(AB\) is constant.
Without losing generality we can take \(A = 1/B\), since if this is not the case we can just rescale the radial or temporal coordinate until it is.

Then, we can compute
%
\begin{align}
R^{2}_{2} = \frac{B}{2r} \qty(\frac{B'}{B} + \frac{B'}{B}) + \frac{1}{r^2} (B-1) &= 0  \\
B' + \frac{B}{r} - \frac{1}{r} &= 0  \\
\dv{}{r} \qty(rB) &= 1
\,,
\end{align}
%
so \(r B(r) = r + C\) for some constant \(C\), or equivalently
%
\begin{align}
B (r) = \frac{C}{r} + 1
\,.
\end{align}

After this, we can already substitute into the metric:
%
\begin{align}
\dd{s^2} = - \qty(1 + \frac{C}{r}) \dd{t^2}
+ \frac{1}{1 + C/r} \dd{r^2} + r^2 \dd{\Omega^2}
\,.
\end{align}

For any value of \(C\), \(B \to 1\) as \(r \to \infty \): the metric reduces to the flat one asymptotically.
Right now \(C\) is an arbitrary constant, however in the weak field limit it is known that
%
\begin{align}
g_{00} = - \qty(1 + 2 \frac{\phi }{c^2})
\,,
\end{align}
%
where \(\phi = - GM / r\) is the Newtonian gravitational field.
Equating this expression to the one for \(g_{00} \), we find
%
\begin{align}
g_{00} = - \qty(1 - \frac{2 GM}{rc^2})
\implies C = - \frac{2GM}{c^2}
\,.
\end{align}

The constant \(M\) in the classical case is the mass of the source, however we are computing a vacuum solution. This is the mass we would compute if we were to measure the orbits of objects around the compact object.

% \todo[inline]{This is then surely a \emph{gravitational} mass, is it also an \emph{inertial} mass? Can we show this in GR?}

Then, we can write the Schwarzschild metric:
%
\begin{align}
\dd{s^2} = - \qty(1 - \frac{2GM}{c^2r}) \dd{t^2}
+ \qty(1 - \frac{2GM}{rc^2})^{-1} \dd{r^2} + r^2 \dd{\Omega^2}
\,.
\end{align}

This is derived by assuming time-independence, however the result is the same even in the time-dependent case by the Jebsen-Birkhoff theorem (which we will prove in a moment).
The element \(g_{rr} \) diverges as \(r \to R_g = 2GM/c^2\), however this does not represent any physical divergence: no component of the Riemann tensor \(R_{\mu \nu \rho \sigma }\) diverges there, while the Ricci tensor \(R_{\mu \nu }\) is identically zero by hypothesis.
On the other hand, the origin is a true singularity, since the scalar \(R^{\mu \nu \rho \sigma } R_{\mu \nu \rho \sigma } \propto r^{-6}\) diverges there.

There are coordinates which do not diverge near the horizon: one classical choice employs the ``tortoise'' coordinates, which are the same for \(r\), \(\theta \), \(\varphi \) as the Schwarzschild ones, while the time becomes (setting \(G = c =  1\))
%
\begin{align}
t = t' - 2M \log \qty(1 - \frac{r}{2M})
\,.
\end{align}

\begin{claim}
Substituting this into the metric yields (dropping the primes for clarity):
%
\begin{align}
\dd{s^2} = - \qty(1 - \frac{2M}{r}) \dd{t}^2
+ \frac{4M}{r} \dd{r} \dd{t} + \qty(1 + \frac{2M}{r}) \dd{r^2}
+ r^2 \dd{\Omega^2}
\,.
\end{align}
\end{claim}

\begin{proof}
The new time differential after the change of coordinates reads
%
\begin{align}
\dd{t} &= \pdv{t}{t'} \dd{t'} + \pdv{t}{r} \dd{r}  \\
&= \dd{t'} - 2M \frac{(-1/2M)}{1 - r/2M} \dd{r} = \dd{t}' + \frac{ \dd{r}}{1 - r / 2M}  \\
\dd{t}^2 &= \dd{t}^{\prime 2}
+2 \frac{ \dd{r} \dd{t'}}{1 - r/2M}
+ \frac{ \dd{r^2}}{(1 - r / 2M)^2}
\,,
\end{align}
%
therefore the new metric reads (omitting the angular part for brevity):
%
\begin{align}
\dd{s}^2
&= - \qty(1- \frac{2M}{r}) \dd{t}^2 + \frac{ \dd{r}^2}{1 - 2M / r}  \\
&= - \qty(1- \frac{2M}{r}) \qty(\dd{t}^{\prime 2}
+2 \frac{ \dd{r} \dd{t'}}{1 - r/2M}
+ \frac{ \dd{r^2}}{(1 - r / 2M)^2}) + \frac{ \dd{r}^2}{1 - 2M / r}  \\
&= - \qty(1 - \frac{2M}{r}) \dd{t^{\prime 2}} + \frac{4M}{r} \dd{r} \dd{t'} + \qty(1 + \frac{2M}{r}) \dd{r^2}
\,,
\end{align}
%
where we have used the following manipulations: setting \(x = 2M / r\), the coefficients of the \(\dd{r} \dd{t}'\) and \(\dd{r^2}\) terms are respectively
%
\begin{align}
2\frac{1 - x}{1 - x^{-1}} &= -2x  \\
-\frac{1 -x}{(1- x^{-1})^2} + \frac{1}{1-x} &= \frac{1}{1-x} \qty(-\qty(\frac{1-x}{1- x^{-1}})^2 + 1) =  \frac{1-x^2}{1-x} = 1+x
\,.
\end{align}
\end{proof}

There is no pathology at \(r = 2M\) anymore, so it was not a physical divergence.
The temporal coefficient \(g_{00} \) is the same: it can be shown that it is an invariant under coordinate transformations.

If we take two points which are very close along a particle trajectory, they must be separated by an interval \(\dd{s}^2 < 0\).

If we consider a radial path (not necessarily geodesic) described by \(r(t)\), we can compute the corresponding line element by neglecting the angular part:
%
\begin{align}
\dd{s^2} &= - \qty(1 - \frac{2M}{r}) \dd{t}^2
+ \frac{4M}{r} \dd{r} \dd{t} + \qty(1 + \frac{2M}{r}) \dd{r^2}  \\
\qty( \dv{s}{t})^2 &= - \qty(1- \frac{2M}{r})
+ \frac{4M}{r} \dv{r}{t} + \qty(1 + \frac{2M}{r} ) \qty(\dv{r}{t})^2
\,.
\end{align}

Now, the question we ask is: is it possible for the particle trajectory to be timelike or lightlike (\(\dd{s}^2 \leq 0\)) and outgoing (\(\dv*{r}{t} > 0\)) under these conditions? If this is the case, the signs of the three terms read
%
\begin{align}
\underbrace{\qty(\dv{s}{t})^2}_{< 0 ?}
=
- \qty(1- \frac{2M}{r})
\underbrace{+ \frac{4M}{r} \dv{r}{t}}_{> 0 } \underbrace{+ \qty(1 + \frac{2M}{r} ) \qty(\dv{r}{t})^2}_{> 0}
\,,
\end{align}
%
so we can see that the equality can be satisfied (a positive number cannot equal a negative one!) as long as the first term on the right-hand side is negative, which means \(r > 2M\).
If \(r \leq 2M\), on the other hand, this cannot be the case: a radial trajectory below the horizon \emph{cannot} be outward.

This is what ``horizon'' means: it is a \emph{semi-permeable} membrane, particles can surpass it only in one direction.

\paragraph{Jebsen-Birkhoff}

This theorem states that the Schwarzschild solution also describes the spacetime around an object in the spherically-symmetric but time-\emph{dependent} case. Let us give a sketch of its proof, omitting some tedious calculations.
If we write out the components of the Ricci tensor, we find something in the form
%
\begin{align}
R^{0}_{0} &= \eval{R^{0}_{0}}_{\text{static}} + \dot{A} \qty(\dots)\\
R^{1}_{1} &= \eval{R^{1}_{1}}_{\text{static}} + \dot{A} \qty(\dots)
\,,
\end{align}
%
while \(R^{2}_{2}\) and \(R^{3}_{3}\) are the same. Also, the term \(R^{1}_{0}\) does not vanish unlike the static case, and is equal to
%
\begin{align}
R^{1}_{0} = - \frac{\dot{A}}{r A^2} = 0
\,,
\end{align}
%
so \(\dot{A} = 0\): the equations then are the same as the static case ones!
This, however, is not the end, since now the equation
%
\begin{align}
\frac{A'}{A} + \frac{B'}{B} = 0
\,
\end{align}
%
is not necessarily solved by \(\log A = - \log B\), since a prime denotes a \emph{partial} derivative with respect to \(r\), so in general we will have \(\log A + \log B = f(t)\), some generic function of time.
The metric will then read
%
\begin{align}
\dd{s}^2 = - \qty(1 - \frac{2M}{r}) f(t)\dd{t^2} + \qty(1 - \frac{2M}{r}) \dd{r^2} + r^2 \dd{\Omega}^2
\,,
\end{align}
%
but we can simply rescale the time coordinate to \(t \to \sqrt{f} t\) in order for this to reduce to the usual expression.
This theorem was originally discovered by the Norwegian physicist Jebsen, and only later popularized in a textbook by Birkoff \cite{johansenDiscoveryBirkhoffTheorem2005}.

The source of the geometry can change in time while leaving the outside spacetime unperturbed, however this holds only as long as the variation remains spherically symmetric: collapse, expansion or pulsation.
Any asymmetry can lead to the emission of gravitational radiation.

\end{document}


\startreport{Network Influence Score}
\reportauthor{Ramesh Subramonian}
\section{Introduction}

We define the ``network influence score'' problem as follows. Let us assume that
we know 2 things for every user that we have (a) who referred that user (could
be zero or one user) (b) the revenue generated by that user.

We ``attribute''
the revenue of a user to every referrer along the chain of referrals ending at
that user. For example, if \(a\) referred \(b\) who referred \(c\) and \(c\)
generated \$210 of revenue, then \$140 is attributed to \(b\) and 70 to \(a\).
Note that the distribution of c's revenue depends on the length of the referral
chain ending at \(c\). So, if \(d\) had referred \(a\) in this example, then
\$120 is attributed to \(b\), \$60 to \(a\) and \$30 to \(d\).

Simply stated, the problem is to find the attributed revenue of each user.

\subsection{Selected Q operators}
See Table~\ref{tbl_q_ops}.

\begin{table}[ht]
\centering
\begin{tabular}{|l|l|l|} \hline \hline
{\bf ID} & {\bf operator} & {\bf explanation} \\ \hline \hline
1 & \(y = \mathrm{get\_val\_by\_idx}(f, x)\) & \(y_i \leftarrow x_{f_i}\) \\ \hline
2 & \(y = \mathrm{set\_sclr\_val\_by\_idx}(x, y, s)\) & \(x_i = j \Rightarrow y_j \leftarrow s\) \\ \hline
3 & \(z = \mathrm{add\_vec\_val\_by\_idx}(x, y, z)\) & \(x_i = j \Rightarrow z_j \leftarrow
z_j + y_i\) \\ \hline
4 & \(z = \mathrm{vvmul}(x, y)\) & \(z_i \leftarrow x_i \times y_i\) \\ \hline
5 & \(y = \mathrm{vsleq}(x, s)\) & {\bf if} \(x_i \leq s\) {\bf then} \(y_i \leftarrow 1\) {\bf else} \(y_i \leftarrow 0\)  \\ \hline
6 & \(w = \mathrm{ifxthenyelsez}(x, y,z)\) & {\bf if} \(x_i\) {\bf then} \(w_i \leftarrow y_i\) {\bf else} \(w_i \leftarrow z_i\)  \\ \hline
7 & \(x = \mathrm{const}(s)\) & \(x_i \leftarrow s\) \\ \hline
8 & \(z = \mathrm{where}(x, y)\) & \(z = \{x_i\}\) where \(y_i = 1\) \\ \hline
\hline
\end{tabular}
\caption{Selected Q operators}
\label{tbl_q_ops}
\end{table}

\section{Data Structures}
\subsection{T0}

\(T_0\) has the following columns, where each row refers to a person.
\be
\item \(x\) --- a sequence \(0, 1, \ldots\)
\item \(y\), person who did the referring.
\item id, original ID
\item \(r\), dollar amount spent
\item \(s\), dollar amount attributed, {\em created by algorithm}
\item \(d\), max depth of referral chain ending in this person, {\em created by algorithm}
\ee
Notes:
\bi
\item \(y[i] = j \Rightarrow\) \(i\) was referred by \(j\).
We also say that \(y\) is the 1-parent of \(i\)
\item \(y[j] < 0 \Rightarrow \) nobody referred \(j\)
\item a person can be referred by at most one person
\ei

\subsection{T1}

\(T_1\) is \(T_0\) restricted to persons who were refered. Specifically,
\bi
\item \(v = \mathbf{Q.vsgeq}(T_0.y, 0)\)
\item \(T_1.x = \mathbf{Q.where}(T_0.x, v)\)
\item \(T_1.y = \mathbf{Q.where}(T_0.y, v)\)
%% DELETE \item \(T_1.r = \mathbf{Q.where}(T_0.r, v)\)
%% DELETE \item \(T_1.d = \mathbf{Q.const}(1)\)
%% DELETE --- initial assumption on depth of chain ending in \(x\)
\ei

\subsection{Tk}

Tables \(T_k\) for \(k =  2, \ldots\) have the following columns
\be
\item \(x\), person who was referred
\item \(y\), person who did the referring at a distance of \(k\)
\ee

Note that if \(a\) referred \(b\) and \(b\) referred \(c\), then table \(T_2\)
would have a row of the form \((c, a)\)

\subsection{Sample Data}
An example is in Table~\ref{example_extend}.
\begin{table}[hp]
\centering
\begin{tabular} {|l|l|l|l|l|} \hline \hline
{\bf k} & {\bf x} & {\bf y} & {\bf z} & {\bf w} \\ \hline
0 & 0 & 1  & --- & --- \\ \hline
0 & 1 & 2  & --- & --- \\ \hline
0 & 2 & 3  & --- & --- \\ \hline
0 & 3 & 4  & --- & --- \\ \hline
0 & 4 & -1 & --- & --- \\\hline
0 & 5 & 6  &  --- & --- \\\hline
0 & 6 & 7  &  --- & --- \\\hline
0 & 7 & -1 &  --- & --- \\\hline
0 & 8 & -1 &  --- & --- \\\hline
\hline  \hline
1 & 0 & 1  & 2  & 1 \\ \hline
1 & 1 & 2  & 3  & 1 \\ \hline
1 & 2 & 3  & 4  & 1 \\ \hline
1 & 3 & 4  & -1 & 0 \\ \hline
1 & 5 & 6  & 2  & 1 \\ \hline
1 & 6 & 7  & -1 & 0 \\ \hline
\hline  \hline
2 & 0 & 2 & 3 & 1 \\ \hline
2 & 1 & 3 & 4 & 1 \\ \hline
2 & 2 & 4 & -1 & 0 \\ \hline
2 & 5 & 7 & -1 & 0 \\ \hline
\hline  \hline
3 & 0 & 3 & 4 & 1 \\ \hline
3 & 1 & 4 & -1 & 0 \\ \hline
\hline  \hline
4 & 0 & 4 & -1 & 0 \\ \hline
\end{tabular}
\caption{Sample data}
\label{example_extend}
\end{table}

\section{Algorithm}

The algorithm is presented in Figure~\ref{algo}. Some useful routines in
Section~\ref{aux_algo}
\subsection{Sub-routines}
\label{aux_algo}

\bi
\item The function {\bf Q.extend} is in Figure~\ref{extend}
\item The way the attribution diminishes with distance is in Table~\ref{attenuate}
\ei

\begin{figure}
\centering
\fbox{
\begin{minipage}{12 cm}
\centering
\begin{tabbing}
\hspace*{0.25in} \= \hspace*{0.25in} \= \hspace*{0.25in} \= \kill
Inputs: \+ \\
\(T_k.x\) \\
\(T_k.y\) \\
\(T_0.y\) \- \\
% Operation:  \+ \\
% Let \(T_k.x[i] = x', T_k.y[i] = y'\).  \\
% Let \(f' = T_0.y[y']\).  \\
% If \(z' \geq 0\), add \((x', z')\) to output; else, do nothing \- \\
Implementation in Q:  \+ \\
\(z = \mathbf{Q.get\_val\_by\_idx}(T_k.y, T_0.y)\) \\
\(w = \mathbf{Q.vsgeq}(z, 0)\) \\
\(T_{k+1}.x = \mathbf{Q.where}(T_k.x, w)\) \\
\(T_{k+1}.y = \mathbf{Q.where}(z, w)\) \- \\
\end{tabbing}
\caption{extend}
\label{extend}
\end{minipage}
}
\end{figure}

\begin{table}[hp]
\centering
\begin{tabular}{|l|l|l|l|l|l|l|} \hline \hline
\(d_{max}\) & \(\alpha_1\)  & \(\alpha_2\)  & \(\alpha_3\)  & \(\alpha_4\)
\\ \hline
1 & 1 & --- & --- & --- \\ \hline
2 & 2/3 & 1/3 & --- & --- \\ \hline
3 & 4/7 & 2/7 & 1/7 & --- \\ \hline
4 & 8/15 & 4/15 & 2/15 & 1/15 \\ \hline
\hline
\end{tabular}
\caption{Attenuation Factors for different \(d, d_{max}\)}
\label{attenuate}
\end{table}

\begin{figure}
\centering
\fbox{
\begin{minipage}{12 cm}
\centering
\begin{tabbing}
\hspace*{0.25in} \= \hspace*{0.25in} \= \hspace*{0.25in} \= \kill

\(T_0.d = \mathbf{Q.const}(1)\) --- initialize max depth to 1 \\
\(T_0.s = \mathbf{Q.const}(0)\) --- initialize attributed revenue to 0 \\
\(k = 1\) \\
{\bf repeat } \+ \\
\(T_{k+1} = \mathbf{Q.extend}(T_k.x, T_k.y, T_0.y)\) (Figure~\ref{extend})\\
{\bf if} \(T_{k+1} = \bot\) {\bf then break else} \(k = k+1\) {\bf end}\\
--- Update max depth of referral chain \\
\(\mathbf{Q.set\_sclr\_val\_by\_idx}(T_{k+1}.x, T_0.d, k+1)\) \- \\
{\bf until} --- not possible to extend any further \\
\(d_{max} = k\) \\
Load \(\alpha\) which contains attribution coefficients (Table~\ref{attenuate})\\
{\bf for} \(k = 1, \ldots d_{max}\) {\bf do} \+ \\
% {\bf for} \(k = 1, \ldots k\) {\bf do} \+ \\
  \(T_k.d       = \mathbf{Q.get\_val\_by\_idx}(T_k.x, T_0.d)\)  \\
  \(T_k.r       = \mathbf{Q.get\_val\_by\_idx}(T_k.x, T_0.r)\)  \\
  \(T_k.\alpha  = \mathbf{Q.get\_val\_by\_idx}(T_k.d, \alpha[k])\) \\
  \(s           = \mathbf{Q.vvadd}(T[k].r, T[k].\alpha)\) \\
  \(\mathbf{Q.add\_vec\_val\_by\_idx}(s, T_k.y, T_0.s)\) \- \\
{\bf endfor} \\
\end{tabbing}
\caption{Pseudo-code}
\label{algo}
  \end{minipage}
}
\end{figure}

\newpage

\appendix
Some bogus reference to make bibtex not complain \cite{Hastie2009}.
\bibliographystyle{alpha}
\bibliography{../../../DOC/ref}


\chapter{Anomaly Detection}

\section{Type of Anomaly}
\begin{enumerate}
\item Point Anomalies (Our Focus)
\item Contextual Anomalies
\item Collective Anomalies
\end{enumerate}

\section{Anomaly Detection Techniques}
\noindent General steps
\begin{table}[h!]
\begin{tabular}{r p{12cm}}
\hline
    1: & Build profile of normal behavior \\
    2: & Use the normal profile to detect anomalies \\
\hline
\end{tabular}
\end{table}

\begin{description}
\item[Graphical Approaches] Boxplot, Scatter plot, Spin plot
\item[Statistical Approaches] points are determined to be outliers depending on their relationship with this model
\item[Nearest Neighbor Based Approaches] Distance based methods or density based methods
\item[Classification Based Approaches] Supervised learning techniques
\end{description}
\textit{Evaluation of Anomaly Detection: Use F-measure and ROC curve}


\chapter{Preliminaries and related work}
\label{preliminaries}

In this section we briefly introduce and explain the necessary theoretical background, upon which we build later on.

We first define the concepts of Machine learning (ML) and Deep neural networks (DNNs). We explain, how DNNs can learn patterns from data by using powerful gradient-based stochastic optimization algorithm called Stochastic gradient descent (SGD). Then we talk about a subset of DNNs that perform very well on image data called Convolutional neural networks (CNNs).

Finally, we describe the systemic vulnerability of DNNs and define an adversarial attack. Then we explain related terms like adversarial defenses, adversarial examples, adversarial robustness and different adversarial attack threat models and present current state of the field.

\section{Deep learning basics}

\subsection{Machine learning}
The topic of machine learning has been introduced many times over in other books and papers. \cite{10.5555/2380985}, \cite{10.5555/1162264} and \cite{Goodfellow-et-al-2016} all provide a comprehensive exposition to the field. Because of the abundance of many different kinds of resources, we don't feel the need to reinvent the wheel and come up with yet another machine learning introduction.

To put forward the most accepted definition of machine learning, the \cite{10.5555/2380985} lay it as follows: \\

“A computer program is said to learn from experience $E$ with respect to some class of tasks $T$ and performance measure $P$, if its performance at tasks in $T$, as measured by $P$, improves with experience $E$.”

\subsection{Deep neural networks}
In our case the "computer program learning from experience" will be in most cases a deep neural network (DNN). We will introduce neural networks only very briefly at a high level as more details can be easily found in \cite{Goodfellow-et-al-2016}.

DNN is in its essence a parametrized mapping $y = f(x;\theta)$, where $x$ are the network inputs, $\theta$ are the parameters and $y$ are the outputs of the network. The "network" in its name comes from the fact that the function computation is described as an evaluation of a computational directed acyclic graph (DAG), the structure of which depends on the exact network architecture.

During evaluation, each node in the graph is asociated with a number called "activation", This activation value is computed from the values of other nodes and from the relevant parameters $\theta$. It is then passed through a non-linear activation function $a(x)$. For a long time the $sigmoid(x)$ activation function was very popular. Nowdays $ReLU(x) = \max(0, x)$ (Rectified Linear Unit) is used more often as it is better suited for deeper networks.

The nodes in the DAG are sometimes referred to as "neurons", as there is an analogy to the functioning of biological neurons.

The function $f(x;\theta)$ can be often decomposed into several computational steps: $f(x;\theta) = f_n(f_{n-1}(...f_2(f_1(x; \theta_1);\theta_2)...;\theta_{n-1});\theta_n)$. In this decomposition the individual functions $f_i(x_i; \theta_i)$ are called "layers". When the number of layers is large, the network is said to be deep. The successive computations of $f_1(x_1, \theta_1)$, $f_2(x_2, \theta_2)$ up to $f_n(x_n, \theta_n)$ is called a "forward pass".

\subsection{Network training}
If we have a dataset $D$ consisting of input datapoints $x_i$ and their corresponding $y_i$ values called "labels", we want the neural network function $f(x, \theta)$ to express the relationship between $x_i$ and $y_i$. Depending on the complexity of the network, the parameters $\theta$ can be often set accordingly, such that $f(x_i, \theta) \approx y_i$. This ability to approximate the data well with the right $\theta$ is called "network's capacity". How good is the neural network's approximation is measured by a loss function $\mathcal{L}(D, f(x, \theta))$. Because the network models the relationship between $x_i$ and $y_i$, it is sometimes just called a "model".

The process of training a neural network tries to minimize the training loss by optimizing the parameters. Formally, we search for $\theta$ = $\argmin{\theta}[ \mathcal{L}(D, f(x, \theta))]$.

This optimization is in practice done iteratively using an algorithm called stochastic gradient descent (SGD). It involves computing the gradient of the loss with respect to the parameters $\theta$: $\nabla_{\theta} \mathcal{L}(D, f(x, \theta))$. It then updates the parameters in the opposite direction of the gradient to hopefully lower the loss.

The partial derivates $\frac{\partial \mathcal{L}(D, f(x, \theta))}{\partial \theta_i}$ can be efficiently computed by an algorithm called "backpropagation". It is very similar to a forward pass, but it starts from the loss and proceeds in the opposite direction of the DAG. Detailed explanation can be again found in \cite{Goodfellow-et-al-2016}. It is also icredibly well explained in the \href{https://www.youtube.com/playlist?list=PLZHQObOWTQDNU6R1_67000Dx_ZCJB-3pi}{YouTube video series about neural networks} by 3Blue1Brown (Grant Sanderson)

\subsection{Convolutional neural networks}
Convolutional neural network (CNN) is a network using a special type of layers called "convolutional layers". CNNs were invented more than 20 years ago (\cite{LeCun1998ConvolutionalNF}) and they are powerful feature extractors compressing highly dimensional spatial inputs to a smaller feature vector. They are used mainly when dealling with images, but in general, convolutions are useful for any type of spatial data with translational invarience property. When a network is asked to perform an image classification, it is often desireable for an object in the left part of the image to be detected in the same way as an object on the right side. Convolutional layer achives this by convolving each part of the input image with the same kernel, thus sharing weights and greatly reducing the parameter count. Each convolutional kernel is sometimes referred to as "filter", because the kernel convolution operation resembles a sobol operator used in classical computer vision and image processing. CNNs usually stack multiple convolutional layers on top of each other with each subsequent layer having more filters, but reducing the spatial dimension. The spatial dimension reduction is achived by an average or max pooling layers that follow periodically after each set of convolutional layers. The final convolution outputs are either pooled together to reduce the spatial dimension to 1x1, or they are passed through a one or two densely connected layers to produce the extracted features.

\section{Related Work}
\label{related_work}

\subsection{Definitions}
As it was outlined in chapter \ref{introduction}, adversarial attacks are methods of producing adversarial examples. Given an original input $x$ and a classifier model $y = f(x), y \in C$, an adversarial example $x_{adv} = x + \delta$ is a slightly pertubed version of $x$, such that $f(x_{adv}) \neq y$. By "slightly" we mean $\lVert \delta \rVert < \epsilon$. In this work we focus on image adversarial examples achieving misclasification on image classification models, albeit the concept of adversarial attacks is applicable across different types of neural networks and different types of input data.

One can be also interested in the minimal pertubation $\delta_{min}$ needed to change the model classification:

$$\delta_{min} = \argmin{\delta} \lVert \delta \rVert \quad \text{such that} \quad f(x + \delta) \neq y$$

This brings us to the definition of robustness $r(x, f)$ given an input $x$:
$$r(x, f) = \lVert \delta_{min} \rVert$$

More informative can be the expected robustness across all of our data $D$, the global robustness of a model:

$$\rho (f) = \underset{x \sim \mathcal D}{\mathbb E} r(x, f)$$

Whether we do or do not care about the nature of misclassification distinguishes the targeted and untargeted attacks:

\begin{itemize}
    \item targeted attacks require that $f(x_{adv}) = t, t \in C$
    \item untargeted attacks only aim for unspecified misclasification - $f(x_{adv}) \neq y$
\end{itemize}

The constraint on pertuation size $\lVert \delta \rVert$ makes sure, that the adversarial example $x_{adv}$ looks almost the same as the original $x$. That said, there are many valid choices for the metric $\lVert \cdot \rVert$ that are commonly used:

\begin{itemize}
    \item $l_{0}$ - the number of non-zero components of $\delta$.
    \item $l_{1}$ - $\lVert \delta \rVert = \underset{i}{\sum} \lvert \delta_{i} \rvert$
    \item $l_{2}$ - $\lVert \delta \rVert = \sqrt{\sum \delta_{i}^2}$
    \item $l_{inf}$ - $\lVert \delta \rVert = \underset{i}{\max \delta_{i}}$
\end{itemize}

\subsection{Whitebox attacks}
Whitebox adversarial attacks assume full knowledge of the target model, which allows for efficient computation of the the gradients with respect to the input. This is in contrast with blackbox attacks \ref{blackbox_attack}, where the attacked model is available only as a blackbox and as such the gradients can be only estimated using sampling for example.

\cite{Biggio2013EvasionAA} was the first to point out the inherent vulnerability of machine learning models by attacking SVMs and multi-layer perceptrons.

In the same year \cite{szegedy2014intriguing} used an L-BFGS optimization algorithm that leverages estimates of second order partial derivates information to find minimally distorted adversarial example $x$ by solving the following:
$$\min \lVert x - x_{adv} \rVert_2^2 \quad \text{s.t.} \quad f(x_{adv}) = t \quad \text{and} \quad x_{adv} \in [0, 1]^m$$

In 2014 \cite{goodfellow2015explaining} introduced the Fast gradient sign method (FGSM) which we use in \ref{fgsm_exp}. It involves doing only one backpropagation, so it is very efficient and is often use for an adversarial training. Adversarial training is a method of dynamicaly extending the training dataset by adversarial examples generated on the fly. FGSM is well suited for this, because it's fast.

In 2015 Jacobian-based saliency map attack (JSMA) was proposed by \cite{papernot2015limitations}.

Various methods trying to reduce the susceptibility of neural networks to adversarial examples are being proposed around this time. These methods are called "adversarial defences". One of those is the previously mentioned adversarial training. Few others include for example JPG compression, stochastic augmentations, feature distilation etc.

As an attempt to break a specific "distilation defense", \cite{carlini2017evaluating} propose their C\&W attack. FGSM and L-BFGS aren't strong-enough against the distilation defense, because the gradients are orders of magnitude smaller than in the case of an undefended target.

They reframe the optimization problem as:
$$\min \lVert x - x_{adv} \rVert^2_2 + c \cdot f(x', t) \quad \text{s.t.} \quad x' \in [0, 1]^m \quad \text{where} \quad f(x', t) = (max_{i \neq t} Z(x')_i - Z(x')_t)^+$$

Their reframing allows for adaptive scaling of the objective being optimized and as such doesn't suffer as much from the small gradients. Furthemore, their objective is different from the objectives optimized previously, which also helps the C\&W attack.

For a more comprehensive overview of whitebox attacks and adversarial attacks in general we will point the reader to the review paper \cite{xu2019adversarial}.

\subsection{Transferability}
\label{transferability}
It was demonstrated \cite{tramer2017space} that adversarial examples generated by whitebox attacks have high probability of decieving another neural network. This transferability of adeversarial examples is made more severe when the two models have similar architectures and when the datasets used to train them are the same.

\subsection{Blackbox attacks}
\label{blackbox_attack}
In the blackbox setting the access to the target model is limited and only the final output is available to the attacker.

Nevertheless, the transferability proprety \ref{transferability} can be used to fool the target model without any further knowledge.

A different approach of attacking a blackbox model can be to estimate the gradients by sampling to make up for the inability to backpropage through it. (\cite{Chen2017ZOOZO}, \cite{Ilyas2018BlackboxAA})

There is yet another class of blackbox attacks. These attacks don't rely on the gradient information at all, but instead they use random search to find the adversarial pertubation. SquareAttack \cite{Andriushchenko2020SquareAA}, which we utilize in this work, is one example of such attacks.

In chapter \ref{our_approach} we talk more about the different blackbox attacks and about possible ways of combining different approaches together.

    % - maximizes classification for t and minimizes classification for all other classes
    % - so called **"margin loss"**
    % - there are many different ways to define valid loss function, but margin loss seems to work the best (probably)
%   - only difference in formulation is that L-BFGS  uses **cross-entropy** instead of **margin loss**
    % - this formulation has a nice property, that when $C(x') = t$, then $f(x', t) = 0$, and the algorithm switches to optimizing only the **distance part of the objective**
    % - efficient for finding the minimally distorted adversarial example
% - quite very strong attack, useful for benchmarking