\documentclass[a4paper,english,notitlepage,longbibliography,showpacs,preprintnumbers,amsmath,amssymb,aps,prx,nofootinbib,12pt,superscriptaddress]{revtex4-1}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{comment}
\usepackage{hyperref}
\hypersetup{
 bookmarks=true,                % show bookmarks bar?
 unicode=false,                 % non-Latin characters in Acrobat’s bookmarks
 pdftoolbar=true,               % show Acrobat’s toolbar?
 pdfmenubar=true,               % show Acrobat’s menu?
 pdffitwindow=false,            % window fit to page when opened
 pdfstartview={FitH},           % fits the width of the page to the window
 pdftitle={SFR derivations},    % title
 pdfauthor={Szil{\'a}rd Szalay},        % author
 pdfsubject={},       % subject of the document
 pdfcreator={pdflatex},         % creator of the document
 pdfproducer={vim},             % producer of the document
 pdfkeywords={SFR} {BCR}, % list of keywords
 pdfnewwindow=true,             % links in new window
 colorlinks=true,               % false: boxed links; true: colored links
 linktoc=page,                  % defines which part of an entry in the table of contents is made into a link
%%%%%%%%% colored links
 linkcolor=blue,                % color of internal links       (red)
 citecolor=blue,                % color of links to bibliography
 filecolor=magenta,             % color of file links
 urlcolor=blue                  % color of external links
}
%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[inline]{showlabels}
\renewcommand{\showlabelfont}{\footnotesize\ttfamily\color{OliveGreen}}
%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\ceil}[1]{\lceil #1 \rceil}

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{SFR-BCR}

\noindent Binary variables: $x_1,x_2,\dots,x_n\in\{0,1\}$,
and let $X:=\sum_{i=1}^n x_i$, $2\leq k\in\mathbb{N}$, $l = \ceil{\log k}$

\subsection{SFR-BCR-1,2}
\noindent We have the $l+1$ auxiliary variables $y_0,y_1,\dots,y_{l-1},z\in\{0,1\}$.
(In the formulas, summations for $i,i' = 1,2,\dots,n$ and $j,j' = 0,1,\dots,l-1$ are understood.)\\

\noindent We have the function (See Observation 1. from \cite{Boros2018QuadratizationsOS}) %% Would a proper citation be needed
\begin{equation}
\label{eq:Ak}
A_k(X,y,z) = X - (k-2^l)z - (k+1)(1-z) - \sum_{j}2^jy_j.
\end{equation}
After substituting for X, and collecting the terms, the equation for SFR-BCR-1 becomes
\begin{equation}
\label{eq:Ak1}
A_k(X,y,z) = -(1+k) +\sum_i x_i - \sum_{j}2^jy_j + (1+2^l)z.
\end{equation}
Similarly for SFR-BCR-2 we have
\begin{equation}
\label{eq:Ak2}
A_{n-k}({n-X},y,z) = -(1-k) +\sum_i x_i - \sum_{j}2^jy_j + (1+2^l)z.
\end{equation}
For the  two cases
(top/bottom = SFR-BCR-1/SFR-BCR-2),
by recognizing their similarities we can simplify the equation to
\begin{equation}
\label{eq:Ak12}
\left.\begin{aligned}
&A_k(X,y,z) \\
&A_{n-k}({n-X},y,z)
\end{aligned}\right\}
= -(1\pm k) \pm \sum_i x_i - \sum_j 2^jy_j + (1+2^l)z.
\end{equation}
Then the squares are
\begin{equation}
\label{eq:Ak12sq}
\begin{split}
\left.\begin{aligned}
&A_k(X,y,z)^2 \\
&A_{n-k}({n-X},y,z)^2
\end{aligned}\right\}
= (1\pm k)^2 \mp2(1\pm k)\sum_i x_i +2(1\pm k)\sum_j 2^jy_j -2(1\pm k)(1+2^l)z & \\
+ \sum_i\sum_{i'} x_ix_{i'} \mp2\sum_i\sum_j 2^jx_iy_j \pm2 (1+2^l)\sum_i zx_i & \\
+ \sum_j\sum_{j'} 2^{j+j'}y_jy_{j'} - 2(1+2^l)\sum_j z 2^jy_j & \\
+ (1+2^l)^2z^2. &
\end{split}
\end{equation}
Because $z\in\{0,1\}$, we have $z^2=z$, so we can join the two terms,
\begin{equation}
-2(1\pm k)(1+2^l)z + (1+2^l)^2z^2 = (1+2^l)(2^l\mp2k-1)z,
\end{equation}
so we end up with
\begin{equation}
\label{eq:alpha12}
\begin{split}
&\left.\begin{aligned}
&A_k(X,y,z)^2 \\
&A_{n-k}({n-X},y,z)^2
\end{aligned}\right\} = \\
&\underbrace{(1\pm k)^2}_{\alpha}
+ \underbrace{\mp 2(1\pm k)}_{\alpha^{b}} \sum_i x_i
+ \sum_j \underbrace{(1\pm k)2^{j+1}}_{\alpha^{b_{a,1}}}y_j
+ \underbrace{(1+2^l)(2^l\mp2k-1)}_{\alpha^{b_{a,2}}}z \\
&+ \underbrace{1}_{\alpha^{bb}} \sum_{i,i'} x_ix_{i'}
+ \sum_{i,j} \underbrace{\mp2^{j+1}}_{\alpha^{bb_{a,1}}}x_iy_j
+ \underbrace{\pm2(1+2^l)}_{\alpha^{bb_{a,2}}}\sum_i x_iz \\
&+ \sum_{j,j'} \underbrace{2^{j+j'}}_{\alpha^{b_ab_{a,1}}}y_jy_{j'}
+ \sum_j \underbrace{-(1+2^l)2^{j+1}}_{\alpha^{b_ab_{a,2}}} y_j z.
\end{split}
\end{equation}
The coefficients are
\begin{subequations}
\label{eq:BCR12alpha}
\begin{align}
\alpha &= (1\pm k)^2, \\
%
\alpha^{b} &= \mp 2(1\pm k), \\
\alpha^{b_{a,1}} &= (1\pm k)2^{j+1}, \\
\alpha^{b_{a,2}} &= (1+2^l)(2^l\mp2k-1), \\
%
\alpha^{bb} &= 1, \\
\alpha^{bb_{a,1}} &= \mp2^{j+1}, \\
\alpha^{bb_{a,2}} &= \pm2(1+2^l), \\
\alpha^{b_ab_{a,1}} &= 2^{j+j'}, \\
\alpha^{b_ab_{a,2}} &= -(1+2^l)2^{j+1}.
\end{align}
\end{subequations}

Dictionary: \\
$l\mapsto m-1$, ($l+1=m$ auxiliary variables),\\
$x_i\mapsto b_i$, \\
$y_j\mapsto b_{a_j}$ ,
($b_{\text{a},j}$ would be a better choice, $\text{a}$ is a label, $j$ is an index, they should be on the same level.
Also the indexing of the $\alpha^{\dots}$ coefficients could be made more expressive.)\\
$z\mapsto b_{a_m}$, ($b_{\text{a},m}$ would be better)\\
$k\mapsto c$.\\
Note that, in this case, the $j$ indices of the auxiliary bits have to be shifted, since they are ranging from $1$, not $0$.
(This is not the case in the next subsection.)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{SFR-BCR-3,4}
We have now the $l$ auxiliary variables $y_1,y_2,\dots,y_{l-1},z\in\{0,1\}$.
(In the formulas, summations for $i,i' = 1,2,\dots,n$ and $j,j' = 1,2,\dots,l-1$ are understood.)

We have the functions
\begin{equation}
\label{eq:Akp}
A'_k(X,y,z) = X - (k-2^l)z - (k+1)(1-z) - \sum_{j}2^jy_j.
\end{equation}
Note that, compared to \eqref{eq:Ak},
 the difference is only in the range of index $j$ of the sum in the last term.
For the  two cases
(top/bottom = SFR-BCR-3/SFR-BCR-4),
after substituting and collecting the terms,
\begin{equation}
\label{eq:Akp34}
\left.\begin{aligned}
&A'_k(X,y,z) \\
&A'_{n-k}({n-X},y,z)
\end{aligned}\right\}
= -(1\pm k) \pm \sum_i x_i - \sum_j 2^jy_j + (1+2^l)z.
\end{equation}
(Again, although not written out explicitly,
the difference is in the range of $j$ of the summation, c.f., \eqref{eq:Ak12})

We can obtain the $\alpha^{\dots}$ coefficients for BCR-3,4
from those of BCR-1,2.
Instead of taking the squares, $A_k(X,y,z)^2$ and $A_{n-k}(n-X,y,z)^2$,
for BCR-3,4 we have to take
$\frac12 A'_k(X,y,z)\bigl(A'_k(X,y,z)-1\bigr)=\frac12\bigl(A'_k(X,y,z)^2-A'_k(X,y,z)\bigr)$ and
$\frac12 A'_{n-k}(n-X,y,z)\bigl(A'_{n-k}(n-X,y,z)-1\bigr)=\frac12\bigl(A'_{n-k}(n-X,y,z)^2-A'_{n-k}(n-X,y,z)\bigr)$,
so, to get the new $\alpha^{\dots}$ coefficients,
we have to substract the corresponding coefficients of $A'_k(X,y,z)$ and $A'_{n-k}(n-X,y,z)$
(these can be read off from \eqref{eq:Akp34})
from the old ones \eqref{eq:BCR12alpha}, and divide by $2$.
(And not to forget that the summations for $j$ run over a different range.)

\begin{subequations}
\label{eq:BCR34alpha}
\begin{align}
\alpha &=\frac12\Bigl((1\pm k)^2--(1\pm k) \Bigr)= \frac12(k^2\pm3k+2), \\
%
\alpha^{b} &= \frac12\Bigl(\mp 2(1\pm k)-\pm1\Bigr)= -k\mp\frac32, \\
\alpha^{b_{a,1}} &= \frac12\Bigl((1\pm k)2^{j+1}--2^j\Bigr)= (3\pm k)2^{j-1}, \\
\alpha^{b_{a,2}} &= \frac12\Bigl((1+2^l)(2^l\mp2k-1)-(1+2^l)\Bigr)= (1+2^l)(2^{l-1}\mp k-1), \\
%
\alpha^{bb} &= \frac12\bigl(1\bigr)= \frac12, \\
\alpha^{bb_{a,1}} &= \frac12\bigl(\mp2^{j+1}\bigr)= \mp2^j, \\
\alpha^{bb_{a,2}} &= \frac12\bigl(\pm2(1+2^l)\bigr)= \pm(1+2^l), \\
\alpha^{b_ab_{a,1}} &= \frac12\bigl(2^{j+j'}\bigr)= 2^{j+j'-1}, \\
\alpha^{b_ab_{a,2}} &= \frac12\bigl(-(1+2^l)2^{j+1}\bigr)= -(1+2^l)2^{j}.
\end{align}
\end{subequations}

Dictionary: \\
$l\mapsto m$, ($l=m$ auxiliary variables),\\
$x_i\mapsto b_i$, \\
$y_j\mapsto b_{a_j},$
($b_{\text{a},j}$ would be a better choice, $\text{a}$ is a label, $j$ is an index, they should be on the same level.
Also the indexing of the $\alpha^{\dots}$ coefficients could be made more expressive.)\\
$z\mapsto b_{a_m}$, ($b_{\text{a},m}$ would be better)\\
$k\mapsto c$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{SFR-BCR-5}

We begin with the quadratization of f:
\\(Theorem 6, \cite{Boros2018boundsPaper})

\begin{equation}
  \begin{split}
  \left.
  g(x,y,z)
  \right.
  &= \sum_{i=0}^{l-1}\sum_{j=0}^{l-1}r(il+j)y_iz_j
  + 2M\left(1-\sum_{i=0}^{l-1}y_i\right)^2 + 2M\left(1-\sum_{j=0}^{l-1}z_j\right)^2\\
  &+ 2M\left(|x| - \left(l\sum_{i=0}^{l-1}iy_i + \sum_{j=0}^{l-1}jz_j\right)\right)^2
  \end{split}
\end{equation}

After rearranging and substituting $|x| = \sum_ix_i$ we get the equation

\begin{equation}
  \begin{split}
  \left.
  g(x,y,z)
  \right.
  &= \sum_{i,j=1}^{l-1}r((i-1)l+(j-1))y_iz_j
  + 2M\Bigg[\left(1-\sum_{i=0}^{l-1}y_i\right)^2 + \left(1-\sum_{j=0}^{l-1}z_j\right)^2\\
  &+ \left(\sum_ix_i - \left(l\sum_{i=1}^{l-1}(i-1)y_i + \sum_{j=1}^{l-1}(j-1)z_j\right)\right)^2\Bigg]
  \end{split}
\end{equation}

Dictionary: \\
$l\mapsto m + 1$,\\
$x_i\mapsto b_i$, \\
$y_j\mapsto b_{a_j},$\\
$z\mapsto b_{a_{c+i}},$\\
$\lambda\mapsto 2M$\\
$r(x)\mapsto f(x)$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{SFR-BCR-6}

Lets start with the following quadratization of f:
\\(Theorem 10, \cite{Boros2018QuadratizationsOS})

\begin{equation}
  \begin{split}
  \left.
  g(x,y,z)
  \right.
  &= \sum_{i=1}^{l-1}\sum_{j=1}^{l-1}a_{i,j}\cdot y_i\cdot z_j + M
  + M\cdot(X-Y-1)\cdot(X-Y+1)\\
  &+ M\cdot\sum_{i=1}^{l-2}(1-y_i)\cdot y_{i+1} + M\cdot\sum_{j=1}^{l-2}(1-z_j)\cdot z_{j+1}
  \end{split}
\end{equation}

After factoring out M
\begin{equation}
  \begin{split}
  \left.
  g(x,y,z)
  \right.
  &= \sum_{i,j}^{l-1}a_{ij}y_iz_j + M\Big(1 + \Big((X-Y-1)(X-Y+1)\Big)\\
  &+ \sum_{i=1}^{l-2}(1-y_i)y_{i+1} + \sum_{j=1}^{l-2}(1-z_j)z_{j+1}\Big)
  \end{split}
\end{equation}

\noindent \\Substituting for X, Y, and m using $\sum_i w_ix_i$, $l\left(\sum_{j=1}^{l-1}y_j\right) + \sum_{j=1}^{l-1} z_j$, and $l-1$, respectively, we get
\begin{equation}
  \begin{split}
  \left.
  g(x,y,z)
  \right.
  &= \sum_{i,j}^{m}a_{ij}y_iz_j + M\Big[1 + \Big(\sum_i w_ix_i-(m-1)\sum_{j=1}^{m}y_j + \sum_{j=1}^{m} z_j-1\Big)\\
  &\Big(\sum_i w_ix_i-(m-1)\sum_{j=1}^{m}y_j + \sum_{j=1}^{m} z_j+1\Big)
  + \sum_{i=1}^{m-1}(1-y_i)y_{i+1} + \sum_{j=1}^{m-1}(1-z_j)z_{j+1}\Big]
  \end{split}
\end{equation}

Dictionary: \\
$l\mapsto m + 1$,\\
$x_i\mapsto b_i$, \\
$y_j\mapsto b_{a_j},$\\
$z\mapsto b_{a_{c+i}},$\\
$\lambda\mapsto M$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{SFR-ABCG-2}

We begin with the following representation of the parity function.
\\(Theorem 4.6, \cite{Anthony2014})

\begin{equation}
  \prod{(x)} = \sum_{j=1}^n x_j + 2\sum_{i=1}^{n-1}(-1)^{i-1}\left[i - \sum_{j=1}^{n}x_j\right]^-
\end{equation}

\noindent Adding $E(l) = l(l-1) + 2\sum_{i=1}^{n-1}\left[i-l\right]^-$ where $l = \sum_{j=1}^n x_j$, we get the quadratization

\begin{equation}
\begin{split}
  \left.
  g(x,y)
  \right.
  &= 2\sum_{i<j}x_ix_j + \sum_{j=1}^n x_j + 4\sum_{\substack{i = 1:\\ i\:odd}}^{n-1}y_i\Big(i - \sum_{j=1}^n x_j\Big)\\
  &= \sum_{i}x_i + 2\sum_{ij}x_ix_j + 4\sum_{2i-1}^{n-1}y_i\Big(2i - 1 - \sum_{j}x_j\Big)
  \end{split}
\end{equation}

\noindent Dictionary:\\
$x_{i,j}\mapsto b_{i,j}$,\\
$y_{i}\mapsto b_{a_i}$\\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{SFR-ABCG-3}
We begin with the complement of the previous function from SFR-ABCG-2:
\\(Theorem 4.6, \cite{Anthony2014})

\begin{equation}
  \overline{\prod}(x) = 1 - \sum_{j=1}^n x_j + 2\sum_{i=1}^{n-1}(-1)^{i}\left[i - \sum_{j=1}^{n}x_j\right]^-
\end{equation}

\noindent Adding $E(l) = l(l-1) + 2\sum_{i=1}^{n-1}\left[i-l\right]^-$ where $l = \sum_{j=1}^n x_j$, we get the quadratization

\begin{equation}
\begin{split}
  \left.
  g(x,y)'
  \right.
  &= 1 + 2\sum_{i<j}x_ix_j - \sum_{i}^n x_i + 4\sum_{\substack{i = 2:\\ i\:even}}^{n-1}y_i\Big(i - \sum_{j=1}^n x_j\Big)\\
  &= 1 + 2\sum_{ij}x_ix_j - \sum_{i} x_i + 4\sum_{2i}^{n-1}y_i\Big(i - \sum_{j} x_j\Big)
  \end{split}
\end{equation}

\noindent Dictionary:\\
$x_{i,j}\mapsto b_{i,j}$,\\
$y_{i}\mapsto b_{a_i}$\\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{SFR-BCR-7}

Beginning with the quadratization of f:
\\(Theorem 9, \cite{Boros2018boundsPaper})

\begin{equation}
  \begin{split}
  \left.
  g(x,y,z)
  \right.
  &= \sum_{i=0}^{l-1}\sum_{j=0}^{l-1}r(il+j)y_iz_j
  + 2M\left(1-\sum_{i=0}^{l-1}y_i\right)^2 + 2M\left(1-\sum_{j=0}^{l-1}z_j\right)^2\\
  &+ 2M\left(|x| - \left(l\sum_{i=0}^{l-1}iy_i + \sum_{j=0}^{l-1}jz_j\right)\right)^2
  \end{split}
\end{equation}

\noindent Finally, we end with the equation
\begin{equation}
  g(x,y) = 1 + 2\sum_{ij}x_ix_j - \sum_{i} x_i + 4\sum_{2i}^{n-1}y_i\Big(i - \sum_{j} x_j\Big)
\end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{comment}
  \subsection{SFR-BCR-8} THIS WAS JUST SFR-BCR-3/4 FOUND IN THE OTHER PAPER

  Take the quadratization of the exact k-out-of-n function $f_{=k}$:
  \\(Theorem 7, \cite{Boros2018boundsPaper})

  \begin{equation}
  \begin{split}
    \left.
    G_k(x,y,z)
    \right.
    &= \frac{1}{2}A_k(x,y,z)(A_k(x,y,z)-1)\\
    &= \frac{1}{2}\left(A_k(x,y,z)^2-A_k(x,y,z)\right)
  \end{split}
  \end{equation}

  \noindent Where
  \begin{equation}
    A_k(X,y,z) = |x| - (k-2^l)z - (k+1)(1-z) - \sum_{j}^{l-1}2^jy_j.
  \end{equation}

  \noindent We have $A_k(x,y,z)^2$ from \eqref{eq:alpha12} and $A_k(x,y,z)$ from \eqref{eq:Ak1}, thus when we substitute the two equations and collect like terms we end with
  \begin{equation}
  \begin{split}
    \left.
    G_k(x,y,z)
    \right.
    &=\underbrace{\frac{1}{2}(k^2+3k+2)}_{\alpha}
    + \underbrace{-\frac{1}{2}(2k+3)}_{\alpha^{b}} \sum_i x_i
    + \sum_j \underbrace{(k+2)2^{j-1}}_{\alpha^{b_{a,1}}}y_j
    + \underbrace{\frac{1}{2}(1+2^l)(2^l-2k-2)}_{\alpha^{b_{a,2}}}z \\
    &+ \underbrace{\frac{1}{2}}_{\alpha^{bb}} \sum_{i,i'} x_ix_{i'}
    + \sum_{i,j} \underbrace{-2^{j}}_{\alpha^{bb_{a,1}}}x_iy_j
    + \underbrace{(1+2^l)}_{\alpha^{bb_{a,2}}}\sum_i x_iz \\
    &+ \sum_{j,j'} \underbrace{2^{j+j'-1}}_{\alpha^{b_ab_{a,1}}}y_jy_{j'}
    + \sum_j \underbrace{-(1+2^l)2^{j}}_{\alpha^{b_ab_{a,2}}} y_j z
  \end{split}
  \end{equation}

  The coefficients are
  \begin{subequations}
  \begin{align}
  \alpha &= \frac{1}{2}(k^2+3k+2), \\
  %
  \alpha^{b} &= -\frac{1}{2}(2k+3), \\
  \alpha^{b_{a,1}} &= (k+2)2^{j-1}, \\
  \alpha^{b_{a,2}} &= \frac{1}{2}(1+2^l)(2^l-2k-2), \\
  %
  \alpha^{bb} &= \frac{1}{2}, \\
  \alpha^{bb_{a,1}} &= -2^{j}, \\
  \alpha^{bb_{a,2}} &= (1+2^l), \\
  \alpha^{b_ab_{a,1}} &= 2^{j+j'-1}, \\
  \alpha^{b_ab_{a,2}} &= -(1+2^l)2^{j}.
  \end{align}
  \end{subequations}

  Dictionary: \\
  $l\mapsto m$,\\
  $x_i\mapsto b_i$, \\
  $y_j\mapsto b_{a_j}$,\\
  $z\mapsto b_{a_m}$,\\
  $k\mapsto c$.
\end{comment}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{SFR-BCR-8}

Take the quadratization of the at least k-out-of-n function $f_{\geq k}$:
\\(Theorem 8, \cite{Boros2018boundsPaper})

\begin{equation}
  G_k(x,y,z) = \frac{1}{2}A_k(x,y,z)(A_k(x,y,z)-1) + (1-z)
\end{equation}

\noindent With our results from SFR-BCR-8 and adding $(1+z)$ we get\\
\small
\begin{equation}
\begin{split}
  \left.
  G_k(x,y,z)
  \right.
  &=\underbrace{\frac{1}{2}(k^2+3k+4)}_{\alpha}
  + \underbrace{-\frac{1}{2}(2k+3)}_{\alpha^{b}} \sum_i x_i
  + \sum_j \underbrace{(k+2)2^{j-1}}_{\alpha^{b_{a,1}}}y_j
  + \underbrace{\frac{1}{2}((1+2^l)(2^l-2k-2)-2)}_{\alpha^{b_{a,2}}}z \\
  &+ \underbrace{\frac{1}{2}}_{\alpha^{bb}} \sum_{i,i'} x_ix_{i'}
  + \sum_{i,j} \underbrace{-2^{j}}_{\alpha^{bb_{a,1}}}x_iy_j
  + \underbrace{(1+2^l)}_{\alpha^{bb_{a,2}}}\sum_i x_iz \\
  &+ \sum_{j,j'} \underbrace{2^{j+j'-1}}_{\alpha^{b_ab_{a,1}}}y_jy_{j'}
  + \sum_j \underbrace{-(1+2^l)2^{j}}_{\alpha^{b_ab_{a,2}}} y_j z
\end{split}
\end{equation}
\normalsize
The coefficients are
\begin{subequations}
\begin{align}
\alpha &= \frac{1}{2}(k^2+3k+4), \\
%
\alpha^{b} &= -\frac{1}{2}(2k+3), \\
\alpha^{b_{a,1}} &= (k+2)2^{j-1}, \\
\alpha^{b_{a,2}} &= \frac{1}{2}((1+2^l)(2^l-2k-2)-2), \\
%
\alpha^{bb} &= \frac{1}{2}, \\
\alpha^{bb_{a,1}} &= -2^{j}, \\
\alpha^{bb_{a,2}} &= (1+2^l), \\
\alpha^{b_ab_{a,1}} &= 2^{j+j'-1}, \\
\alpha^{b_ab_{a,2}} &= -(1+2^l)2^{j}.
\end{align}
\end{subequations}

Dictionary: \\
$l\mapsto m$,\\
$x_i\mapsto b_i$, \\
$y_j\mapsto b_{a_j}$,\\
$z\mapsto b_{a_m}$,\\
$k\mapsto c$.

\subsection{SFR-BCR-9}

\noindent We begin with the equation for the x-symmetric quadratization of $f_k(x)$
\\(Lemma 2 Eqn 7, \cite{Boros2018QuadratizationsOS})
\begin{equation}
  G(X,y) = \alpha X^2 + X\left(\beta + \sum_{j=1}^m \gamma_jy_j\right) + \left[\sum_{1\leq i < j \leq m} \delta_{ij}y_iy_j + \sum_{j=1}^m \epsilon_jy_j+\phi\right]
\end{equation}

\noindent Using the relationship $X = \sum_i^nx_i$ and rearranging, we get
\begin{equation}
\begin{split}
  \left.
  G(X,y)
  \right.
  &= \alpha\sum_{i,j}^mx_ix_j + \sum_i^mx_i\left(\beta + \sum_{j=1}^m \gamma_jy_j\right) + \left[\sum_{1\leq i < j \leq m} \delta_{ij}y_iy_j + \sum_{j=1}^m \epsilon_jy_j+\phi\right]\\
  &= \alpha\sum_{i,j}^mx_ix_j + \beta\sum_i^mx_i + \sum_{1,j=1}^m \gamma_jx_iy_j + \sum_{ij}^m \delta_{ij}y_iy_j + \sum_{j=1}^m \epsilon_jy_j+\phi
\end{split}
\end{equation}

Dictionary: \\
$x_i\mapsto b_i$, \\
$y_j\mapsto b_{a_j}$\\

\bibliography{SFRBibliography}

\end{document}


\section{Type models and type graphs}
\label{sec:transformation_framework:type_models_and_type_graphs}

In this section, the proposed framework structure is applied to type models and type graphs. First, the general structure and its requirements are discussed. Then the required definitions and theorems are given.

\begin{figure}
    \centering
    \begin{tikzpicture}
    \path
    (-3,4) node[circle,draw,minimum size=10mm,inner sep=0pt](ME) {$T$}
    (-4.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](MA) {$Tm_A$}
    (-1.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](MB) {$Tm_B$}
    (-3,0) node[circle,draw,minimum size=10mm,inner sep=0pt](MAB) {$Tm_{AB}$}

    (3,4) node[circle,draw,minimum size=10mm,inner sep=0pt](GN) {$N$}
    (1.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](GA) {$TG_A$}
    (4.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](GB) {$TG_B$}
    (3,0) node[circle,draw,minimum size=10mm,inner sep=0pt](GAB) {$TG_{AB}$};

    \path[]
    (ME) [-, black, out=240, in=90] edge node[above] {} (MA)
    (ME) [-, black, out=300, in=90] edge node[above] {} (MB)

    (MA) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (MAB)
    (MB) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (MAB)

    (GN) [-, black, out=240, in=90] edge node[above] {} (GA)
    (GN) [-, black, out=300, in=90] edge node[above] {} (GB)

    (GA) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (GAB)
    (GB) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (GAB)

    (ME) [-{Latex[width=5]}, black, out=25, in=155] edge node[above] {$f$} (GN)
    (GN) [-{Latex[width=5]}, black, out=165, in=15] edge node[above] {} (ME)

    (MA) [-{Latex[width=5]}, black, out=35, in=145] edge node[above] {$f_A$} (GA)
    (GA) [-{Latex[width=5]}, black, out=155, in=25] edge node[above] {} (MA)

    (MB) [-{Latex[width=5]}, black, out=35, in=145] edge node[above] {$f_B$} (GB)
    (GB) [-{Latex[width=5]}, black, out=155, in=25] edge node[above] {} (MB)

    (MAB) [-{Latex[width=5]}, black, out=25, in=155] edge node[above] {$f_{A} \sqcup f_{B}$} (GAB)
    (GAB) [-{Latex[width=5]}, black, out=165, in=15] edge node[above] {} (MAB)
    ;
    \end{tikzpicture}
    \caption{Structure for transforming between type models and type graphs}
    \label{fig:transformation_framework:type_models_and_type_graphs:structure_type_models_graphs}
\end{figure}

\cref{fig:transformation_framework:type_models_and_type_graphs:structure_type_models_graphs} shows an alternation of the structure proposed in \cref{sec:transformation_framework:structure} applied to type models and type graphs. As before, type model $Tm_A$ represents the partially build model which corresponds to type graph $TG_A$ under the transformation function $f_A$. Type model $Tm_B$ represents the next building block to add to this model. It corresponds to type graph $TG_B$ under the bijective transformation function $f_B$.

Type models $Tm_A$ and $Tm_B$ are entirely distinct except for a set types $T$, which means $T \subseteq Type_{Tm_A} \land T \subseteq Type_{Tm_B}$. In a similar way, type graphs $TG_A$ and $TG_B$ are entirely distinct except for a set of node types $N$, so $N \subseteq NT_{TG_A} \land N \subseteq NT_{TG_B}$.

Type models $Tm_A$ and $Tm_B$ are combined into type model $Tm_{AB}$ using \cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_models:combine}. In a similar way type graphs $TG_A$ and $TG_B$ are combined into type graph $TG_{AB}$ using \cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:combine}. \cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_models:tmod_combine_merge_correct} and \cref{defin:transformation_framework:type_models_and_type_graphs:combining_type_graphs:tg_combine_merge_correct} respectively show that $Tm_{AB}$ and $TG_{AB}$ are valid. Then \cref{defin:transformation_framework:type_models_and_type_graphs:combining_transformation_functions:combination_transformation_function_type_model_type_graph} and \cref{defin:transformation_framework:type_models_and_type_graphs:combining_transformation_functions:combination_transformation_function_type_graph_type_model} can be used to merge the transformation functions $f_A$ and $f_B$ into $f_{A} \sqcup f_{B}$, where \cref{defin:transformation_framework:type_models_and_type_graphs:combining_transformation_functions:tg_combine_mapping_correct} and \cref{defin:transformation_framework:type_models_and_type_graphs:combining_transformation_functions:tg_combine_mapping_function_correct} show that $f_{A} \sqcup f_{B}$ is again a valid transformation function transforming $Tm_{AB}$ to $TG_{AB}$. Similarly, \cref{defin:transformation_framework:type_models_and_type_graphs:combining_transformation_functions:tmod_combine_mapping_correct} and \cref{defin:transformation_framework:type_models_and_type_graphs:combining_transformation_functions:tmod_combine_mapping_function_correct} show that the inverse function of $f_{A} \sqcup f_{B}$ is again a valid transformation function transforming $TG_{AB}$ to $Tm_{AB}$.

\input{tex/04_transformation_framework/03_type_models_and_type_graphs/01_combining_type_models.tex}
\input{tex/04_transformation_framework/03_type_models_and_type_graphs/02_combining_type_graphs.tex}
\input{tex/04_transformation_framework/03_type_models_and_type_graphs/03_combining_transformation_functions.tex}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    INSTITUTE OF PHYSICS PUBLISHING                                   %
%                                                                      %
%   `Preparing an article for publication in an Institute of Physics   %
%    Publishing journal using LaTeX'                                   %
%                                                                      %
%    LaTeX source code `ioplau2e.tex' used to generate `author         %
%    guidelines', the documentation explaining and demonstrating use   %
%    of the Institute of Physics Publishing LaTeX preprint files       %
%    `iopart.cls, iopart12.clo and iopart10.clo'.                      %
%                                                                      %
%    `ioplau2e.tex' itself uses LaTeX with `iopart.cls'                %
%                                                                      %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
% First we have a character check
%
% ! exclamation mark    " double quote
% # hash                ` opening quote (grave)
% & ampersand           ' closing quote (acute)
% $ dollar              % percent
% ( open parenthesis    ) close paren.
% - hyphen              = equals sign
% | vertical bar        ~ tilde
% @ at sign             _ underscore
% { open curly brace    } close curly
% [ open square         ] close square bracket
% + plus sign           ; semi-colon
% * asterisk            : colon
% < open angle bracket  > close angle
% , comma               . full stop
% ? question mark       / forward slash
% \ backslash           ^ circumflex
%
% ABCDEFGHIJKLMNOPQRSTUVWXYZ
% abcdefghijklmnopqrstuvwxyz
% 1234567890
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\documentclass[12pt]{iopart}
%\newcommand{\gguide}{{\it Preparing graphics for IOP Publishing journals}}
%Uncomment next line if AMS fonts required
%\usepackage{iopams}
\usepackage[thinlines]{easytable}
\begin{document}

\title[Drift velocities in plasmas]{Drift velocities in plasmas}

\author{John "Jack" Brooks}

%\address{}
\ead{jwbrooks0@gmail.com}
\vspace{10pt}
\begin{indented}
\item[]\today
\end{indented}

%\begin{abstract}
%\end{abstract}

%
% Uncomment for keywords
%\vspace{2pc}
%\noindent{\it Keywords}: XXXXXX, YYYYYYYY, ZZZZZZZZZ
%
% Uncomment for Submitted to journal title message
%\submitto{\JPA}
%
% Uncomment if a separate title page is required
%\maketitle
%
% For two-column output uncomment the next line and choose [10pt] rather than [12pt] in the \documentclass declaration
%\ioptwocol
%

\section{Motion in a uniform $\mathbf{B}$ field}

Plasma consists of a collection of positively and negatively charged particles (ions and electrons).  When a uniform magnetic field is applied, $\mathbf{B}$, the plasma is considered magnetized, and the charged particles (plasma) oscillate around the magnetic field lines.  For this work, we define the unit vector associated with the uniform $\mathbf{B}$ to be the parallel, $||$, direction, and everything else as being the cross-field, $\perp$, direction.

The equation of motion of moving charged particles in a magnetic field is
\begin{equation}
\label{eq:eom_simple}
m \dot{\mathbf{v}} = q \mathbf{v} \times \mathbf{B}
\end{equation}
We note that the only non-trivial solution of $\mathbf{v}$ is the cross-field velocity, $\mathbf{v}_\perp$, and therefore we replace $\mathbf{v}$ with $\mathbf{v}_\perp$.

To solve for $\mathbf{v}_\perp$, we take the time derivative of Eq.~\ref{eq:eom_simple} and plug Eq.~\ref{eq:eom_simple} into it.  This provides
\begin{equation*}
\label{eq:eom_simple_2}
\ddot{\mathbf{v}}_\perp = \frac{q^2}{m^2} \left (\mathbf{v}_\perp \times \mathbf{B}  \right) \times \mathbf{B}.
\end{equation*}
Expanding the triple product using BAC-CAB triple product rule provides
\begin{equation*}
\label{eq:eom_simple_3}
\ddot{\mathbf{v}}_\perp = -\frac{q^2}{m^2} \left (B^2 \mathbf{v}_\perp - \left( \mathbf{B} \cdot \mathbf{v}_\perp \right) \mathbf{B} \right).
\end{equation*}
Recognizing that $\mathbf{B} \cdot \mathbf{v}_\perp = 0$, this simplifies to
\begin{equation*}
%\label{eq:eom_simple_3}
\ddot{\mathbf{v}}_\perp = -\left(\frac{qB}{m}\right)^2 \mathbf{v}_\perp
\end{equation*}
and therefore the velocity has the solution
\begin{equation}
\label{eq:velocity_solved}
\mathbf{v}_\perp = v_\perp(0) e^{i \left(qB/m\right) t}.
\end{equation}

Integrating Eq.~\ref{eq:velocity_solved}, we can solve for the position to be

\begin{equation}
%\label{eq:eom_simple_3}
\mathbf{x}_\perp = \frac{v_\perp(0) m}{|q|B} e^{i \left(qB/m\right) t}.
\end{equation}
From this equation, we can identify the gryo-radius (the radius of the circle created by the gyrating particle) to be

\begin{equation}
%\label{eq:gyro-radius}
r_{gyro} = \frac{v_\perp m}{|q|B}
\end{equation}
and the gyro-frequency (the frequency of gyration) to be

\begin{equation}
%\label{eq:gyro-radius}
\omega_{gyro} = \frac{qB}{m}.
\end{equation}
This derivation informs us that the plasma rotates around the magnetic field line and is effectively trapped to the magnetic field without the presence of external forces.

\section{External forces cause a net drift velocity on the plasma}

When an external force is applied to the plasma, it develops an net drift motion (a drift velocity) orthogonal to $\mathbf{B}$ and the external force.  Example forces include gravity, Coulomb force, kinetic pressure, etc.

To calculate the impact of a force on the plasma, we include an unspecified force, $\mathbf{F}$, to our equation of motion (EoM),
\begin{equation*}
%\label{eq:eom_simple}
m \dot{\mathbf{v}} = q \mathbf{v}_\perp \times \mathbf{B} + \mathbf{F}.
\end{equation*}
In addition, we ignore gyromotion and focus on steady-state ``drift'' velocities by time-averaging the EoM over a time much larger than a full gyro-rotation.  The EoM therefore simplifies to
\begin{equation*}
%\label{eq:eom_simple}
0 = q \mathbf{v}_\perp \times \mathbf{B} + \mathbf{F}.
\end{equation*}

We next solve for $\mathbf{v}_\perp (\mathbf{F})$ by multiplying the cross product of $\mathbf{B}$ throughout, performing the BAC-CAB triple product expansion rule, and recognizing that $\mathbf{B} \cdot \mathbf{v}_\perp = 0$.  We finally arrive at
\begin{equation}
\label{eq:drift_velocity_generic}
\mathbf{v}_\perp = \frac{\mathbf{F} \times \mathbf{B}}{q \left | B \right|^2}
\end{equation}

Most drift velocities (perhaps all) can be solved as a special case of the generalized velocity, Eq.~\ref{eq:drift_velocity_generic}, and I personally find it easier to conceptualize each of these drift velocities by considering the force that originally created them.  However, many plasma references prefer a more traditional approach and instead derive them from scratch.

\section{Specific drift velocities}

Now that we have a generic expression for how forces create a net plasma drift velocity (Eq.~\ref{eq:drift_velocity_generic}), the next step is to identify common forces and plug them in.  I've done this for you in Table~\ref{tab:drift_summary} which shows examples of several common forces and their resulting drift velocities.  As an example, the Coulomb force results in the $\mathbf{E} \times \mathbf{B} $ drift that has a net motion that is orthogonal to both $\mathbf{E}$ and $\mathbf{B}$.  Because it has no dependence of charge, $q$, and both ions and electrons therefore move in the same direction when exposed to a net electric field.  The other drift velocities, for example the gravitational drift, are dependent on the plasma charge, $q$, and this means that most forces result in ions and electrons traveling in opposite directions.

\renewcommand{\arraystretch}{1.5} %% Increases row height in the table
\begin{table}[h]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
\multicolumn{2}{|c|}{\textbf{Force}, $\mathbf{F}$}    & \multicolumn{2}{c|}{\textbf{Resulting drift velocity}, $\mathbf{v}_\perp$} \\ \hline
\textbf{Name}       & \textbf{Equation} & \textbf{Name}       & \textbf{Equation}      \\ \hline
Gravity             & $m\mathbf{g}$                &      Gravitational drift               &           $\frac{m \mathbf{g} \times \mathbf{B}}{qB^2}$             \\ \hline
Coulomb force      & $q\mathbf{E}$                &       E ``cross'' B drift              &      $\frac{ \mathbf{E} \times \mathbf{B}}{B^2}$                      \\ \hline
Kinetic pressure    &          $\frac{ - \nabla P}{n}$         &        Diamagnetic drift             &     $-\frac{ \nabla P \times \mathbf{B}}{nqB^2}$                       \\ \hline
Magnetic dipole restoring force     &   $-\frac{mv_\perp^2}{2B} \nabla B$                &     ``Grad'' B drift                &           $\frac{m v_\perp^2}{2qB}\frac{\mathbf{B} \times \nabla B}{B^2}$             \\ \hline
Centripetal force          & $\frac{mv_{||}^2}{\mathbf{r}}$          &         Curvature drift            &       $ m v_{||}^2 \frac{\mathbf{r}\times\mathbf{B}}{qB^2r^2}$              \\ \hline
Oscillating E field & $-\frac{m\mathbf{B}\times\mathbf{\dot{E}}}{B^2}$      &    Polarization drift                 &  $\frac{m \mathbf{\dot{E}}}{qB^2} $                      \\ \hline
\end{tabular}
\caption{\label{tab:drift_summary}List of forces that can act on a plasma and their resulting drift velocity. }
\end{table}

Several of the other forces are somewhat nuanced and require a little more context.  The diamagnetic drift is due to resulting force from kinetic pressure (i.e. collisions between particles) in the plasma.  The $\nabla B$ drift is created charged particle gyro-motion around a  non-uniform $\mathbf{B}$ which results in a restoring magnetic dipole force.  Curvature drift occurs when the magnetic field line is curved and the plasma particle (which is mostly trapped to the field line) is forced to bend along with the field line.

The force responsible for the polarization drift is less straight forward.  In this case, the electric field, $\mathbf{E}$, is changing as a function of time.  The resulting force can be derived from the lorentz Force,

\begin{equation*}
\mathbf{E} = - \mathbf{v} \times \mathbf{B},
\end{equation*}
taking the time derivative and multiplying my the mass,
\begin{equation*}
\mathbf{m\mathbf{\dot{E}}} = - m\mathbf{\dot{v}} \times \mathbf{B} = - \mathbf{F} \times \mathbf{B},
\end{equation*}
crossing both sides with $\mathbf{B}$ and using the BAC-CAB rule to get
\begin{equation}
\mathbf{F} = - \frac{m \mathbf{B} \times \mathbf{\dot{E}}}{B^2}.
\end{equation}

The drift velocities discussed here are merely the motions that are typically covered by plasma physics textbooks, and more complicated motions exist.  These include those from radiation pressure and more complex collision models.  In addition, higher order corrections to the drift velocities discussed here exist when the various forces are not constant in time and space.

\section{Plasma currents}

Because of the $q$ dependence in most of the drift velocities in Table~\ref{tab:drift_summary}, ions and electrons move in opposite directions under these forces.  Therefore, these drift velocities also create electrical current in the plasma.  The exception to this is the $\mathbf{E} \times \mathbf{B}$ drift velocity.

\section*{References}
\begin{thebibliography}{widest entry}
\bibitem{deBlank} de Blank, H.J., ``Guiding Center Motion'', Personal notes: $https://juser.fz-juelich.de/record/283631/files/DeBlank_BT-1-2.pdf$
\end{thebibliography}

\end{document}


\chapter{   Deep Learning}
% CHAPTER SETTINGS
\graphicspath{{./images/computer_vision/}}

\section{Rgularization}

\subsection{Why do we use regularization?}
Regularization helps us control our model capacity, ensuring that our models are better at
making (correct) classifications on data points that they were not trained on, which we call the
ability to generalize. If we don’t apply regularization, our classifiers can easily become too complex
and overfit to our training data, in which case we lose the ability to generalize to our testing data
(and data points outside the testing set as well, such as new images in the wild).
However, too much regularization can be a bad thing. We can run the risk of underfitting, in
which case our model performs poorly on the training data and is not able to model the relationship
between the input data and output class labels (because we limited model capacity too much). For
example, consider the following plot of points, along with various functions that fit to these points.

addfigure starterbundle p.114

What we are doing here is looping over all entries in the matrix and taking the sum of squares.
The sum of squares in the L2 regularization penalty discourages large weights in our matrixW,
preferring smaller ones. Why might we want to discourage large weight values? In short, by
penalizing large weights, we can improve the ability to generalize, and thereby reduce overfitting.
Think of it this way – the larger a weight value is, the more influence it has on the output
prediction. Dimensions with larger weight values can almost singlehandedly control the output
prediction of the classifier (provided the weight value is large enough, of course) which will almost
certainly lead to overfitting.

\section{Activation Functions}

\section{Perceptron}


%!TEX root=../../../template.tex
\subsection{The Lambertian Hypothesis}%
\label{sub:methods_lambertian_hypothesis}

As stated in this chapter's introductory notes, this thesis main body of
work revolves around two base assumptions, our hypothesis. The first
one, about the information capturing by the idealised system, was
addressed in Subsection~\ref{sub:methods_collection}. The second, more
physical in nature, is the subject matter of this section. Our
hypothesis states that the light absorption between points $A$ and $B$
(let's call it $A_{AB}$) should be equal to the difference of the
absorptions in $A$ and $B$. We can write this, in a \emph{Lambertian}
manner as in Equation~\ref{eq:lambertian_hypothesis}.

\begin{equation}
    \label{eq:lambertian_hypothesis}
    I_B = I_A \cdot \exp \bigg[-AB \cdot \sum_i \sigma_{ABi} \cdot
    c_{ABi}\bigg]
\end{equation}

This is to say that the light intensity reaching point $B$ is given by
the intensity reaching $A$, exponentially decreased by the absorbers at
interval $AB$. The intensities at $A$ and $B$ are written as in
Equation~\ref{eq:intensityAtAAndB}.

\begin{equation}
    \begin{aligned}
        \label{eq:intensityAtAAndB}
        I_B = I_0 \cdot \exp \bigg[ -L_B \cdot \sum_i \sigma_{Bi} \cdot
        c_{Bi} \bigg]\\
        I_A = I_0 \cdot \exp \bigg[ -L_A \cdot \sum_i \sigma_{Ai} \cdot
        c_{Ai} \bigg]
    \end{aligned}
\end{equation}

If we join all this information in the same expression, the equation is
transformed into its final form, presented in
Equation~\ref{eq:hypothesis_final_form}.

\begin{equation}
    \small
    \label{eq:hypothesis_final_form}
    I_0 \cdot \exp \bigg[ -L_B \cdot \sum_i \sigma_{Bi} \cdot
            c_{Bi} \bigg] = I_0 \cdot \exp \bigg[ -L_A \cdot \sum_i \sigma_{Ai} \cdot
            c_{Ai} \bigg] \cdot \bigg[-AB \cdot \sum_i \sigma_{ABi} \cdot
            c_{ABi}\bigg]
\end{equation}

Equation~\ref{eq:hypothesis_final_form} can be greatly simplified: we
take the natural logarithm of both sides and we state that $\sum_i
\sigma_{Xi} \cdot c_{Xi} = S_i$. These operations result in the
simplified form of Equation~\ref{eq:final_form_simplified}.

\begin{equation}
    \label{eq:final_form_simplified}
    L_B \cdot S_B = L_A \cdot S_A + L_{AB} \cdot S_{AB}
\end{equation}

Now, $L_X \cdot S_X$ can be thought of as the wavelength dependent light
absorption in path $X$. In this case, the wavelength interval is always
the same. We can therefore conclude that, theoretically, our
hypothesis is valid: light absorption between points $A$ and $B$ can be
expressed in terms of the absorption on both these points and
corresponds to their difference.

Although mathematically this seems clear-cut, in the real world things
can become more problematic, since we have to deal with the
imperfections that characterise a real physical system. Noise,
instrumental limitations, adverse environmental effects, etc.. The
experiment we describe in the next few paragraphs aimed at determining
target trace gas concentration in a set analysis field. This field is
dimension-wise compatible with those that would be employed in the final
working system. This experiment is represented in
Figure~\ref{fig:experiment_map}.

\begin{figure}[htpb]
    \centering
    \includegraphics[width=0.8\linewidth]{img/png/experimentMap.png}
    \caption{Location of observer points for the physical experiment.}
    \label{fig:experiment_map}
\end{figure}

The goal of the experiment was to compare passive and active \gls{DOAS}
measurements performed with a very short time difference between them.
The passive measurement would employ the same acquisition strategy as
the drone is expected to use. This comparison will be used to test our
second hypothesis.

Finding two appropriate experiment sites proved to be the first
difficulty: both telescopes should see sky on the back of the other
telescope. Otherwise, the contribution from the terrain's reflection
would have to be taken into account and the experiment conditions would
be very different from the ones the drone will have. There are not many
site pairs that provide this, and most of the ones that exist are
private and authorisations are not easy to obtain. In the end, we
managed to run the experiment in the facilities of \emph{\gls{iep}} and
the \emph{Cristo-Rei} sanctuary, near our own base.


\startreport{Dense Neural Networks}
\reportauthor{Ramesh Subramonian}

\section{Computational Considerations}
We start by describing the dense neural network (DNN) computation. In
Section~\ref{the_math}, we will discuss the underyling mathematics.
\subsection{Data Structure of DNN}
\label{data_struct}
We start by presenting the data structure of the DNN
\begin{figure}
\centering
% TODO: Following should be auto-generated not hard-coded
\verbatiminput{dnn_types.h}
\end{figure}

We now explain each element of the
\be
\item \(n\) --- {\tt nl}, number of layers. The simplest DNN has 3 layers ---
an input layer, a hidden layer and an output layer.
\item \(p\) -- {\tt npl}, number of neurons per layer. \(p_l\) is number of
neurons in layer \(l\), where \(0 \leq l < n\). The network of
Figure~\ref{sample_network} would have \(n = 3, p = \{3,4,1\}\)
\item \(W\) --- the weights on the edges.
\(W_i\) contains the edges from layer \(i-1\) to layer \(i\).
Hence,
\be
\item \(W_0 = \bot\)
\item \(W_i = \) edges from layer \(i-1\) to layer \(i\). Note that
\(0 < i < n\)
\item \(W_{i,j} = \) edges from neuron \(j\) of layer \(i-1\) to layer \(i\).
Note that \( 0 \leq < p_{i-1}\).
\item \(W_{i,j,k} = \) edge from neuron \(j\) of layer \(i-1\) to
neuron \(k\) of layer \(i\).
Note that \(0 \leq k < p_i\).
\ee
\item \(b\) --- the bias of the neurons.
\(b_i\) contains the bias of neurons in layer \(i\).
Note that \(0 < i < n\).
Hence,
\be
\item \(b_0 = \bot\)
\item \(b_i = \) biases of neurons in layer \(i\)
\item \(b_{i,j} = \) bias of neuron \(j\) of layer \(i\),
where \(0 \leq j < p_i\)
\ee
\item \(z\) --- the intermediate output of a neuron
\(z_i\) contains the intermediate output of neurons in layer \(i\).
Hence,
\be
\item \(z_0 = \bot\)
\item \(z_i = \) intermediate output of neurons in layer \(i\)
Note that \(0 < i < n\).
\item \(z_{i,j} = \) intermediate output of neuron \(j\) of layer \(i-1\)
\ee
\item \(a\) --- the output output of a neuron --- after intermediate output has been
passed through activation function.
\(a_i\) contains the output of neurons in layer \(i\).
Hence,
\be
\item \(a_0 = \bot\)
\item \(a_i = \) output of neurons in layer \(i\)
Note that \(0 < i < n\).
\item \(a_{i,j} = \) output of neuron \(j\) of layer \(i-1\)
\ee
The observant reader would have noticed that the above description indicates
that \(z, a\) are 2-dimensional arrays whereas they have been defined as {\tt
float ***}. This is because the network is evaluated in batches, explained in
Section~\ref{batching}
\ee

\subsection{Batching}
What is batching? Assume that we have \(n\) instances and a batch size of \(m <
n\). Then, it means that an epoch consists of performing the forward pass
for \(m\) instances, then the back propagation, then doing the same for the next
\(m\) instances and so on.

This makes \(z, a\) 3-dimensional arrays such that
\(a_{i,j, k} = \) output of neuron \(j\) of layer \(i-1\) for \(k^{th}\)
instance.

\section{The Math}

\subsection{Dropouts}
Dropouts are explained in \cite{Srivastava14}.

\TBC
\newpage
\bibliographystyle{alpha}
\bibliography{../../../DOC/Q_PAPER/ref}


\section{Summary and Outlook} \label{sec:summary}
By analyzing the SED of a galaxy, we can infer detailed physical properties
such as its stellar mass, star formation rate, metallicity, and dust content.
These properties serve as the building blocks of our understanding of how
galaxies form and evolve.
State-of-the-art SED modeling methods use MCMC sampling to perform Bayesian
statistical inference.
They derive posterior probability distributions of galaxy properties given
observation that accurately estimate uncertainties and parameter degeneracies
to enable more rigorous statistical analyses.
%Posteriors also enable marginalization over any nuisance parameters.
For the dimensionality of current SED models, deriving a posterior requires
${\gtrsim}100,000$ model evaluations and take ${\gtrsim}10-100$ CPU hours per
galaxy.
Upcoming galaxy surveys, however, will observe \emph{billions} of galaxies
using \emph{e.g.} DESI, PFS, Rubin observatory, James Webb Space Telescope, and
the Roman Space Telescope.
Analyzing all of these galaxies with current Bayesian SED models is infeasible
and would require hundreds of billions of CPU hours.
Even with recently proposed emulators, which accelerate model evaluations by
three to four orders to magnitude, the computation cost of SED modeling would
remain a major bottleneck for galaxy studies.

We demonstrate in this work that Amortized Neural Posterior Estimation (ANPE)
provides an alternative \emph{scalable} approach for Bayesian inference in SED
modeling.
ANPE is a simulation-based inference method that formulates Bayesian inference
as a density estimation problem and uses neural density estimators (NDE) to
approximate the posterior over the full space of observations.
The NDE is trained using parameter values drawn from the prior and mock
observations simulated with these parameters.
Once trained, a posterior can be obtained from the NDE by providing the
observations as the conditional variables without any additional model
evaluations.

In this work, we present {\sc SEDflow}, a galaxy SED modeling method using ANPE
and PROVABGS, a flexible SED model that uses a compact non-parameteric SFH and
ZH prescriptions and was recently validated in \cite{hahn2022}.
Furthermore, we apply {\sc SEDflow} to optical photometry from the NASA-Sloan
Atlas as demonstration and validation of our ANPE approach.
We present the following key results from our analysis. \vspace{2mm}
\begin{compactitem}
    \item We train {\sc SEDflow} using a data set of ${\sim}1$ million SED
        model parameters and forward model synthetic SEDs.
        The parameters are drawn from a prior and the forward model is based on
        the PROVABGS and noise models.
        We design the ANPE to estimate $p(\btheta | f_X, \sigma_X, z)$, where
        $f_X$, $\sigma_X$, and $z$ are the photometry, photometric uncertainty,
        and redshift, respectively.
        For its architecture, we use a MAF normalizing flow with 15 MADE blocks
        each with 2 hidden layers and 500 hidden units.
        Training {\sc SEDflow} requires roughly 1 day on a single CPU.
        Once trained, deriving posteriors of galaxy properties for a galaxy
        takes ${\sim}1$ second, $10^5\times$ faster than traditional MCMC sampling.
    \item Posteriors derived using {\sc SEDflow} show excellent agreement with
        posteriors derived from MCMC sampling.
        We further validate the accuracy of the posteriors by applying  {\sc
        SEDflow} to synthetic observations with known true parameter values.
        Based on statistical metrics used in the literature (p-p plot and SBC),
        we find excellent agreement between the {\sc SEDflow} and the true
        posteriors.
    \item Lastly, we demonstrate the advantages of {\sc SEDflow} by applying it
        to the NASA-Sloan Atlas.
        Estimating the posterior of ${\sim}33,000$ galaxies takes $\sim$12 CPU
        hours.
        We make the catalog of posteriors publicly available at
        \url{https://changhoonhahn.github.io/SEDflow/}.
        For each galaxy, the catalog contains posteriors of all 12 PROVABGS
        SED model parameters as well as the galaxy properties: $M_*$,
        average SFR over 1Gyr, mass-weighted metallicity, and mass-weighted
        stellar age. \vspace{2mm}
\end{compactitem}

This work highlights the advantages of using an ANPE approach to Bayesian SED
modeling.
Our approach can easily be extended beyond this application.
For instance, we can include multi-wavelength photometry at ultra-violet or
infrared wavelengths.
We can also modify \sedflow~to infer redshift from photometry.
In \sedflow, we include redshift as a conditional variable, since NSA provides
spectroscopic redshifts.
However, redshift can be included as an inferred variable rather than a
conditional one.
Then, we can apply \sedflow~to infer galaxy properties from photometric data
sets without redshift measurements while marginalizing over the redshift
prior.
If we do not require spectroscopic redshifts, \sedflow~can be extended to much
larger data sets that span fainter and broader galaxy samples.
Conversely, we can use \sedflow~to infer more physically motivated photometric
redshifts, where we marginalize over our understanding of galaxies rather than
using templates.

The ANPE approach to SED modeling can also be extended to galaxy spectra.
Constructing an ANPE for the full data space of spectra would requires
estimating a dramatically higher dimensional probability distribution.
SDSS spectra, for instance, have ${\sim}3,600$ spectral elements.
In our approach we include the uncertainties of observables as conditional
variables, which doubles the curse of dimensionality.
Recent works, however, have demonstrated that galaxy spectra can be represented
in a compact low-dimensional space using autoencoders~\citep[][Melchior \&
Hahn, in prep.]{portillo2020}.
In \cite{portillo2020}, they demonstrate that SDSS galaxy spectra can be
compressed into 7-dimensional latent variable space with little loss of
information.
Such spectral compression dramatically reduces the dimensionality of the
conditional variable space to dimensions that can be tackled by current ANPE
methods.
We will explore SED modeling of galaxy spectrophotometry using ANPE and
spectral compression in a following work.


\documentclass[10pt]{article}
\usepackage{bm}% bold math
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{color}
\DeclareMathOperator{\sgn}{sgn}
\renewcommand{\thefootnote}{\alph{footnote}}

\begin{document}

\subsection{Hessian Diagonalization}

Frequencies and normal modes are obtained from Hessian diagonalization, following the method from {\color{blue} https://tinyurl.com/4a75skfm}, which in turn uses (V. Barone, JCP, 2005, 122, 014108; V. Barone et al. IJQ. Chem., 2012, 112, 2185). Without projection frequencies and normal modes are just (transformed) eigenvalues and eigenvectors of the Hessian,

\begin{equation}
	\mathsf{H} = \begin{pmatrix}
		\frac{\partial^2 E}{\partial x_1^2} & \frac{\partial^2 E}{\partial x_1y_1} &
		\frac{\partial^2 E}{\partial x_1z_1} & \cdots\\
		\frac{\partial^2 E}{\partial y_1x_1} & \frac{\partial^2 E}{\partial y_1^2} &
		\frac{\partial^2 E}{\partial y_1z_1} & \cdots\\
		\vdots & \vdots & \vdots & \ddots
	\end{pmatrix}
\end{equation}
\\
appropriately mass weighted,
\begin{equation}
	\mathsf{H}_\text{w} = \begin{pmatrix}
		\frac{\mathsf{H}_{11}}{\sqrt{m_1 m_1}} & \cdots & \frac{\mathsf{H}_{1,3i}}{\sqrt{m_1 m_i}} & \cdots \\
		\vdots & \vdots & \vdots & \ddots
	\end{pmatrix}
\end{equation}
\\
which is real symmetric so Hermitian ($\mathsf{H} \in \mathbb{R}^{3N\times3N}$ for a system of $N$ atoms). The frequencies are then square roots of the eigenvalues i.e. $\nu_i = \sqrt{\lambda_i}$\footnote{With an appropriate unit conversion.} and the normal modes $\boldsymbol{s}_i$ where,

\begin{equation}
	\mathsf{H}_\text{w} = \mathsf{S D S}^T \quad ; \quad \mathsf{D} = \begin{pmatrix}
		\lambda_1 & 0  & \cdots \\
		0 & \lambda_2 & \cdots \\
		\vdots & \vdots & \ddots
	\end{pmatrix}
	%
	\quad ; \quad
	%
	\mathsf{S} = \begin{pmatrix}
		\uparrow & \uparrow &  \\
		\boldsymbol{s}_1 & \boldsymbol{s}_2 & \cdots \\
		\downarrow & \downarrow &
	\end{pmatrix}
\end{equation}
\\
To project out translational and rotational motion for a non linear molecule requires a transformation of $\mathsf{H}_\text{w}$,

\begin{equation}
	\mathsf{H}_\text{w}' = \mathsf{T}^T \mathsf{H}_\text{w} \mathsf{T} \qquad ; \qquad \mathsf{H}_\text{w}' = \begin{pmatrix}
		\boldsymbol{0} & \boldsymbol{0} \\
		\boldsymbol{0} & \bar{\mathsf{H}}_\text{w}
	\end{pmatrix}
\end{equation}
\\
where
\begin{equation}
	\mathsf{T} = \begin{pmatrix}
		\uparrow & \uparrow  & \\
		\hat{\boldsymbol{t}}_1 & \hat{\boldsymbol{t}}_2 & \cdots \\
		\downarrow & \downarrow &
	\end{pmatrix}
\end{equation}
\\
and the columns of $\mathsf{M}$ are,

\begin{equation}
	\boldsymbol{t}_1 = \begin{bmatrix}
		(\hat{\boldsymbol{e}}_1)_1 \\
		\vdots \\
		(\hat{\boldsymbol{e}}_1)_N \\
	\end{bmatrix}
	%
	\quad ; \quad
	%
	\boldsymbol{t}_2 = \begin{bmatrix}
		(\hat{\boldsymbol{e}}_2)_1 \\
		\vdots \\
		(\hat{\boldsymbol{e}}_2)_N \\
	\end{bmatrix}
	%
	\quad ; \quad
	%
	\boldsymbol{t}_3 = \begin{bmatrix}
		(\hat{\boldsymbol{e}}_3)_1 \\
		\vdots \\
		(\hat{\boldsymbol{e}}_3)_N \\
	\end{bmatrix}
\end{equation}
\\
where $\hat{\boldsymbol{e}}_k$ is a unit vector in 3D (i.e. $\hat{\boldsymbol{e}}_1 = (1, 0, 0)^T$). The rotation vectors are

\begin{equation}
	\boldsymbol{t}_4 = \begin{bmatrix}
		\boldsymbol{e}_1 \times \boldsymbol{r}_1 \\
		\vdots \\
		\boldsymbol{e}_1 \times \boldsymbol{r}_N \\
	\end{bmatrix}
	%
	\quad ; \quad
	%
	\boldsymbol{t}_5 = \begin{bmatrix}
		\boldsymbol{e}_2 \times \boldsymbol{r}_1 \\
		\vdots \\
		\boldsymbol{e}_2 \times \boldsymbol{r}_N \\
	\end{bmatrix}
	%
	\quad ; \quad
	%
	\boldsymbol{t}_6 = \begin{bmatrix}
		\boldsymbol{e}_3 \times \boldsymbol{r}_1 \\
		\vdots \\
		\boldsymbol{e}_3 \times \boldsymbol{r}_N \\
	\end{bmatrix}
\end{equation}
\\
where $\boldsymbol{r}_i$ is the vector from the centre of mass of the system to the atom $i$. The remaining $\boldsymbol{t}_n$ are filled with random vectors that are orthogonal to $\boldsymbol{t}_1\text{--}\boldsymbol{t}_6$, which can be achieved by QR factorisation once the remaining elements of $\mathsf{T}$ have been seeded with random numbers. Normalisation requires,

\begin{equation}
	\hat{\boldsymbol{t}}_i = \frac{\mathsf{M}^{1/2}\boldsymbol{t}_i}{|\mathsf{M}^{1/2}\boldsymbol{t}_i|}
	%
	\qquad ; \qquad
	%
	\mathsf{M} = \begin{pmatrix}
		m_1 & 0 & 0 & 0 &\cdots \\
		0 & m_1 & 0 & 0& \cdots \\
		0 & 0 & m_1 & 0& \cdots \\
		0 & 0 & 0 & m_2 & \cdots \\
		\vdots & \vdots & \vdots & \vdots & \ddots
	\end{pmatrix}
\end{equation}
\\
where $m_i$ is the mass of atom $i$.

\vspace{0.4cm}

Projected frequencies are then obtained from the submatrix of $\mathsf{H}_\text{w}'$,

\begin{equation}
	\bar{\mathsf{H}}_\text{w} = \mathsf{\bar{S} \bar{D}\bar{S}}^T
	%
	\quad ; \quad
	%
	\bar{\mathsf{S}} =
	\begin{pmatrix}
		\uparrow & \\
		\bar{\boldsymbol{s}}_7 & \cdots \\
		\downarrow &
	\end{pmatrix}
	%
	\quad ; \quad
	%
	\bar{\mathsf{D}} =
	\begin{pmatrix}
		\bar{\lambda}_7 &  0& \cdots \\
		0 & \bar{\lambda}_8 & \cdots \\
		\vdots & \vdots & \ddots
	\end{pmatrix}
\end{equation}
with $\bar{\nu}_{0\text{--}6} = 0$ cm${}^{-1}$, while the eigenvectors are,

\begin{equation}
	\boldsymbol{s}_i = \mathsf{T}\boldsymbol{s}_i'
	%
	\quad ; \quad
	%
	\mathsf{S}' = \begin{pmatrix}
		\uparrow & \\
		\boldsymbol{s}_1' & \cdots\\
		\downarrow &
	\end{pmatrix}
    =
	\begin{pmatrix}
		\boldsymbol{0} & \boldsymbol{0} \\
		\boldsymbol{0} & \bar{\mathsf{S}}
	\end{pmatrix}
\end{equation}
\\
which correspond to the normal modes in the original coordinates. For a linear molecule the vibrational frequencies are then the $3N-5$ modes, rather than $3N-6$, with $\mathsf{H}_w'$ contains a different number of non-zero entries.

\end{document}