\subsubsection{BasicStatistics}
\label{BasicStatistics}
The \textbf{BasicStatistics} post-processor is the container of the algorithms
to compute many of the most important statistical quantities. It is important to notice that this
post-processor can accept as input both \textit{\textbf{PointSet}} and \textit{\textbf{HistorySet}}
data objects, depending on the type of statistics the user wants to compute:
\begin{itemize}
  \item \textit{\textbf{PointSet}}: Static Statistics;
  \item \textit{\textbf{HistorySet}}: Dynamic Statistics. Depending on a ``pivot parameter'' (e.g. time)
  the post-processor is going to compute the statistics for each value of it (e.g. for each time step).
  In case an \textbf{HistorySet} is provided as Input, the Histories needs to be synchronized (use
    \textit{\textbf{Interfaced}} post-processor of type  \textbf{HistorySetSync}).
\end{itemize}
%
\ppType{BasicStatistics post-processor}{BasicStatistics}
\begin{itemize}
  \item \xmlNode{"metric"}, \xmlDesc{comma separated string or node list, required field},
    specifications for the metric to be calculated.  The name of each node is the requested metric.  There are
    two forms for specifying the requested parameters of the metric.  For scalar values such as
    \xmlNode{expectedValue} and \xmlNode{variance}, the text of the node is a comma-separated list of the
    parameters for which the metric should be calculated.  For matrix values such as \xmlNode{sensitivty} and
    \xmlNode{covariance}, the matrix node requires two sub-nodes, \xmlNode{targets} and \xmlNode{features},
    each of which is a comma-separated list of the targets for which the metric should be calculated, and the
    features for which the metric should be calculated for that target.  See the example below.

    \nb When defining the metrics to use, it is possible to have multiple nodes with the same name.  For
    example, if a problem has inputs $W$, $X$, $Y$, and $Z$, and the responses are $A$, $B$, and $C$, it is possible that
    the desired metrics are the \xmlNode{sensitivity} of $A$ and $B$ to $X$ and $Y$, as well as the
    \xmlNode{sensitivity} of $C$ to $W$ and $Z$, but not the sensitivity of $A$ to $W$.   In this event, two
    copies of the \xmlNode{sensitivity} node are added to the input.  The first has targets $A,B$ and features
    $X,Y$, while the second node has target $C$ and features $W,Z$.  This could reduce some computation effort
    in problems with many responses or inputs.  An example of this is shown below.
  %
  \\ Currently the scalar quantities available for request are:
  \begin{itemize}
    \item \textbf{expectedValue}: expected value or mean
    \item \textbf{minimum}: The minimum value of the samples.
    \item \textbf{maximum}: The maximum value of the samples.
    \item \textbf{median}:  The weighted median of the samples ( $50\%$ weighted percentile). If probability weights are not assigned, uniform distribution will be assigned. The median $x_k$ satisfying:
    \begin{equation}
      \sum_{i = 1}^{k - 1} w_i \le 1/2  and \sum_{i = k + 1}^{n} w_i \le 1/2
    \end{equation}
    The user can specify the parameter \textit{interpolation='X'} for the interpolation method used to calculate the median when it falls between data points. \textit{X} can be \textit{'linear'} (default) or \textit{'midpoint'}
    where \textit{'linear'} uses linear interpolation between points and \textit{'midpoint'} uses the midpoint or average.
    \item \textbf{variance}: variance
    \item \textbf{sigma}: standard deviation
    \item \textbf{percentile}: the percentile. If this quantity is inputted as \textit{percentile} the $5\%$ and $95\%$ percentile(s) are going to be computed.
                               Otherwise the user can specify this quantity with a parameter \textit{percent='X'}, where the \textit{X} represents the requested
                               percentile (a floating point value between 0.0 and 100.0). The user can also specify the parameter \textit{interpolation='X'} for
                               the interpolation method used to calculate the percentile when it falls between data points. \textit{X} can be \textit{'linear'}
                               (default) or \textit{'midpoint'} where \textit{'linear'} uses linear interpolation between points and \textit{'midpoint'} uses the
                               midpoint or average.
    \item \textbf{variationCoefficient}: coefficient of variation, i.e. \textbf{sigma}/\textbf{expectedValue}. \nb If the \textbf{expectedValue} is zero,
    the \textbf{variationCoefficient} will be \textbf{INF}.
    \item \textbf{skewness}: skewness
    \item \textbf{kurtosis}: excess kurtosis (also known as Fisher's kurtosis)
    \item \textbf{samples}: the number of samples in the data set used to determine the statistics.
  \end{itemize}
  The matrix quantities available for request are:
  \begin{itemize}
    \item \textbf{sensitivity}: matrix of sensitivity coefficients, computed via linear regression method. (\nb The condition number is computed every time this quantity is requsted. If it results
    to be greater then $30$, a multicollinearity problem exists and the sensitivity coefficients
    might be incorrect and a Warning is spooned by the code)
    \item \textbf{covariance}: covariance matrix
    \item \textbf{pearson}: matrix of correlation coefficients
    \item \textbf{spearman}: matrix of spearman ranking coefficients. This matrix is computed in its
    weighted form (see RAVEN theory manual at \cite{RAVENtheoryManual}):
    \begin{equation}
\boldsymbol{\mathrm{P}}(\boldsymbol{X},\boldsymbol{Y}) = \frac{\boldsymbol{\Sigma}(\boldsymbol{R(X)},\boldsymbol{R(Y)})}{\sigma_{R(x)} \sigma_{R(y)}}
\end{equation}
    \item \textbf{NormalizedSensitivity}: matrix of normalized sensitivity
    coefficients. \nb{It is the matrix of normalized VarianceDependentSensitivity}
    \item \textbf{VarianceDependentSensitivity}: matrix of sensitivity coefficients dependent on the variance of the variables
  \end{itemize}
  This XML node needs to contain the attribute:
  \begin{itemize}
    \itemsep0em
    \item \xmlAttr{prefix}, \xmlDesc{required string attribute}, user-defined prefix for the given \textbf{metric}.
      For scalar quantifies, RAVEN will define a variable with name defined as:  ``prefix'' + ``\_'' + ``parameter name''.
      For example, if we define ``mean'' as the prefix for \textbf{expectedValue}, and parameter ``x'', then variable
      ``mean\_x'' will be defined by RAVEN. For \textbf{percentile}, RAVEN will define a variable with name defined as:
      ``prefix'' + ``\_'' + ``percent'' + ``\_'' + ``parameter name''. For example, if we define ``perc'' as the prefix
      for \textbf{percentile}, percent as ``10'', and parameter ``x'', then variable ``perc\_10\_x'' will
      be defined by RAVEN.
      For matrix quantities, RAVEN will define a variable with name defined as: ``prefix'' + ``\_'' + ``target parameter name'' + ``\_'' + ``feature parameter name''.
      For example, if we define ``sen'' as the prefix for \textbf{sensitivity}, target ``y'' and feature ``x'', then
      variable ``sen\_y\_x'' will be defined by RAVEN.
      \nb These variable will be used by RAVEN for the internal calculations. It is also accessible by the user through
      \textbf{DataObjects} and \textbf{OutStreams}.
  \end{itemize}
   %
  \nb If the weights are present in the system then weighted quantities are calculated automatically. In addition, if a matrix quantity is requested (e.g. Covariance matrix, etc.), only the weights in the output space are going to be used for both input and output space (the computation of the joint probability between input and output spaces is not implemented yet).
  \\
  \nb Certain ROMs provide their own statistical information (e.g., those using
  the sparse grid collocation sampler such as: \xmlString{GaussPolynomialRom}
  and \xmlString{HDMRRom}) which can be obtained by printing the ROM to file
  (xml). For these ROMs, computing the basic statistics on data generated from
  one of these sampler/ROM combinations may not provide the information that the
  user expects.
  \\
  \nb Determining the percentile requires many samples, especially if the requested percentile is in
  the tail of the distribution. The standard error of the percentile requires a large number of
  samples for accuracy due to the asymptotic variance method used.
  \\
  In addition, RAVEN will automatically calculate the standard errors on the following scalar quantities:
  \begin{itemize}
    \item \textbf{expectedValue}
    \item \textbf{median}
    \item \textbf{variance}
    \item \textbf{sigma}
    \item \textbf{skewness}
    \item \textbf{kurtosis}
    \item \textbf{percentile}
  \end{itemize}
  RAVEN will define a variable with name defined as: ``prefix for given \textbf{metric}'' + ``\_ste\_'' + ``parameter name'' to
  store standard error of given \textbf{metric} with respect to given parameter. This information will be stored in the DataObjects,
  i.e. \textbf{PointSet} and \textbf{HistorySet}, and by default will be printed out in the ``CSV'' output files by the
  \textbf{OutStreams}. Option node \xmlNode{what} can be used in the \textbf{OutStreams} to select the information that
  the users want to print.
  In the case when the users want to store all the calculations results in general \textbf{DataSets}, RAVEN will employ a variable
  with name defined as: ``\textbf{metric}'' + ``\_ste'' to store standard error with respect to all target parameters. An additional
  index ``target'' will added in the \textbf{DataSets} with respect to these variables. All these quantities will be automatically
  computed and stored in the given \textbf{DataSet}, and the users do not need to specify these quantities in their RAVEN input files.
  %
   \item \xmlNode{pivotParameter}, \xmlDesc{string, optional field}, name of the parameter that needs
   to be used for the computation of the Dynamic BasicStatistics (e.g. time). This node needs to
   be inputted just in case an \textbf{HistorySet} is used as Input. It represents the reference
   monotonic variable based on which the statistics is going to be computed (e.g. time-dependent
   statistical moments).
    \default{None}
  %
  \item \xmlNode{biased}, \xmlDesc{string (boolean), optional field}, if \textit{True} biased
  quantities are going to be calculated, if \textit{False} unbiased.
  \default{False}
  %
  \item \xmlNode{dataset}, \xmlDesc{boolean, optional field}, if \textit{True} \xmlString{DataSet}
    will be used to store the calculation results, if \textit{False} \xmlString{PointSet} or \xmlString{HistorySet}
    will be used to store the calculation results.
    \nb The optional \xmlString{DataSet} is added only to this PostProcessor, one can still use the \xmlString{OutStreams}
    to print the variables available in the \textit{DataSet}. The \xmlString{"metric"} names are used as the
    variable names, i.e. variable names listed in \xmlNode{Input} or \xmlNode{Output} in the defined \xmlString{DataSet}.
    In addition, the extra node \xmlNode{Index} is required, and the value for \xmlAttr{var} can be found in the following:
    \begin{itemize}
      \item scalar metrics, such as \xmlNode{expectedValue} and \xmlNode{variance},
        are requested, the index variable \xmlString{targets} will be required.
      \item vector metrics, such as \xmlNode{covariance} and \xmlNode{sensitivity}, are requested, the index variables
        \xmlString{targets} and \xmlString{features} will be required.
      \item If \xmlNode{percentile} is requested, an additional index variable \xmlString{percent} should be added.
      \item when dynamic BasicStatistics (e.g. time) is requested, the index variable \xmlString{time}  will be required.
    \end{itemize}
  \default{False}
  %
\item \xmlNode{multipleFeatures}, \xmlDesc(boolean, optional field), if \textbf{False}, this node can be used when
    the users want to compute sensitivities based on one target variable with respect to one feature variable,
    i.e. the sensitivity calculations are directly computed using the \textbf{Linear Regression} or
    \textbf{Best Linear Predictor} method with single feature. This method can be useful when the input features
    depend on each other. The default value is \textbf{True}, which means the sensitivity calculations are performed
    using \textbf{Linear Regression} or \textbf{Best Linear Predictor} method with multiple features. If the input
    features are not fully correlated, the default value for \xmlNode{multipleFeatures} is always recommended.
    \nb this node only affects the calculations of metrics such as \xmlNode{sensitivity},
    \xmlNode{VarianceDependentSensitivity} and \xmlNode{NormalizedSensitivity}.
  \default{True}
\end{itemize}
\textbf{Example (Static Statistics):}  This example demonstrates how to request the expected value of
\xmlString{x01} and \xmlString{x02}, along with the sensitivity of both \xmlString{x01} and \xmlString{x02} to
\xmlString{a} and \xmlString{b}.
\begin{lstlisting}[style=XML,morekeywords={name,subType,debug}]
<Simulation>
  ...
  <Models>
    ...
    <PostProcessor name='aUserDefinedName' subType='BasicStatistics' verbosity='debug'>
      <expectedValue prefix='mean'>x01,x02</expectedValue>
      <sensitivity prefix='sen'>
        <targets>x01,x02</targets>
        <features>a,b</features>
      </sensitivity>
    </PostProcessor>
    ...
  </Models>
  ...
</Simulation>
\end{lstlisting}

In this case, the RAVEN variables ``mean\_x01, mean\_x02, sen\_x01\_a, sen\_x02\_a, sen\_x01\_b, sen\_x02\_b''
will be created and accessible for the RAVEN entities \textbf{DataObjects} and \textbf{OutStreams}.

\textbf{Example (Static, multiple matrix nodes):} This example shows how multiple nodes can specify
particular metrics multiple times to include different target/feature combinations.  This PostProcessor
calculates the expected value of $A$, $B$, and $C$, as well as the sensitivity of both $A$ and $B$ to $X$ and
$Y$ as well as the sensitivity of $C$ to $W$ and $Z$.
\begin{lstlisting}[style=XML,morekeywords={name,subType,debug}]
<Simulation>
  ...
  <Models>
    ...
    <PostProcessor name='aUserDefinedName' subType='BasicStatistics' verbosity='debug'>
      <expectedValue prefix='mean'>A,B,C</expectedValue>
      <sensitivity prefix='sen1'>
        <targets>A,B</targets>
        <features>x,y</features>
      </sensitivity>
      <sensitivity prefix='sen2'>
        <targets>C</targets>
        <features>w,z</features>
      </sensitivity>
    </PostProcessor>
    ...
  </Models>
  ...
</Simulation>
\end{lstlisting}
\textbf{Example (Dynamic Statistics):}
\begin{lstlisting}[style=XML,morekeywords={name,subType,debug}]
<Simulation>
  ...
  <Models>
    ...
    <PostProcessor name='aUserDefinedNameForDynamicPP' subType='BasicStatistics' verbosity='debug'>
      <expectedValue prefix='mean'>x01,x02</expectedValue>
      <sensitivity prefix='sen'>
        <targets>x01,x02</targets>
        <features>a,b</features>
      </sensitivity>
      <pivotParameter>time</pivotParameter>
    </PostProcessor>
    ...
  </Models>
  ...
  <HistorySet name='basicStatHistorySet'>
    <Output>
      mean_x01,mean_x02,
      sen_x01_a, sen_x01_b,
      sen_x02_a, sen_x02_b
    </Output>
    <options>
      <pivotParameter>time</pivotParameter>
    </options>
  </HistorySet>
</Simulation>
\end{lstlisting}

\textbf{Example (Dumping the results into DataSet):}
\begin{lstlisting}[style=XML,morekeywords={name,subType,debug}]
<Simulation>
  ...
  <Models>
    ...
    <PostProcessor name='aUserDefinedNameForDynamicPP' subType='BasicStatistics' verbosity='debug'>
      <dataset>True</dataset>
      <expectedValue prefix='mean'>x01,x02</expectedValue>
      <sensitivity prefix='sen'>
        <targets>x01,x02</targets>
        <features>a,b</features>
      </sensitivity>
      <pivotParameter>time</pivotParameter>
    </PostProcessor>
    ...
  </Models>
  ...
  <DataObjects>
    <DataSet name='basicStatDataSet'>
      <Output>expectedValue,sensitivity</Output>
      <Index var='time'>expectedValue,sensitivity</Index>
      <Index var='targets'>expectedValue,sensitivity</Index>
      <Index var='features'>sensitivity</Index>
    </DataSet>
  </DataObjects>
</Simulation>
\end{lstlisting}


%!TEX root =  ../main.tex

\mychapters{Matrices}{matrix}{\chapdir/pics/primes} % Chapter heading image

Numbers in boxes
\newpage
\chapterminitoc

%									BB - 1
\newpage
\section{Transformations}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{chBB/BB01p.pdf}}
\subsection{Shifts}
\subsection{Reflections}
\subsection{Rotations}
\subsection{Derivatives}
\subsection{Exercises}

%									BB - 2
\newpage
\section{Walks}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{chBB/BB02p.pdf}}
\subsection{Adjacency Maps}
\subsection{Unidirectional Lines}
\subsection{Exercises}

%									BB - 3
\newpage
\section{Vector-Spaces}
\subsection{Null Space}
\subsection{Dependent Systems}
\subsection{Exercises}

%									BB - 4
\newpage
\section{Determinants}
\subsection{Eigenvalues}
\subsection{Eigenvectors}
\subsection{Exercises}

%									BB - 5
\newpage
\section{Fractals}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{chBB/BB05p.pdf}}
\newpage
\subsection{Text}
Nature is fractals, not smooth (locally linear)
\newpage
\subsection{Exercises}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{chBB/BB05x.pdf}}

%									BB - 6
\newpage
\section{Review}
\subsection{Chapter Review}
\subsection{Chapter Test}


\section{Exercise 03}
\subsection{}

\begin{frame}
\frametitleTC{Direct synthesis for disturbance rejection}
\framesubtitleTC{In fact, slightly more than a remark}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item The loop  and the closed-loop transfer functions are tied to one another: since
       \begin{displaymath}
        G_{yw}(z) = \frac{L(z)}{1+L(z)}, \qquad
        G_{yd}(z) = \frac{1}{1+L(z)},
       \end{displaymath}
 \item we have
       \begin{displaymath}
         L(z) = \frac{G_{yw}(z)}{1-G_{yw}(z)}, \quad
         L(z) = \frac{1-G_{yd}(z)}{G_{yd}(z)}, \quad
         G_{yw}(z)+G_{yd}(z) = 1.
       \end{displaymath}
 \item As a consequence,
       \begin{displaymath}
        G_{yw}(z) = \frac{1-\alpha}{z-\alpha} \quad \Rightarrow \quad
        G_{yd}(z) = 1-\frac{1-\alpha}{z-\alpha}
                  = \frac{z-1}{z-\alpha}
       \end{displaymath}
       and we are just back to the tracking problem.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Direct synthesis for disturbance rejection}
\framesubtitleTC{In fact, slightly more than a remark}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item We can revisit the previous exercise focusing on the disturbance response.
 \item In doing so, it is interesting to also look at the behaviour of the \TC{control signal}\\
       (in our Modelica diagram, \texttt{C.y}).
 \item Observe how a faster rejection -- like a faster tracking -- requires a larger peak\\
       in that signal (which is quite intuitive).
 \item As we shall see, this may lead to require something that the system -- or more\\
       precisely, the \TC{actuator} -- cannot do (e.g., allocate more cores than those\\
       aboard the machine).
 \item Incidentally, this means that \TC{architectures need sizing for fast enough\\
       reaction to TIME-VARYING \emph{stimuli}, not just for a worst-case\\
       CONSTANT load} --- hence one has to know about dynamics.
 \item \vfill Enough on this for the moment, please experiment at home \& report.
 \end{itemize}
\end{frame}


\documentclass{segabs}
\usepackage{mathrsfs,amsmath}

% An example of defining macros
\newcommand{\rs}[1]{\mathstrut\mbox{\scriptsize\rm #1}}
\newcommand{\rr}[1]{\mbox{\rm #1}}

\begin{document}

\title{Moving between Dimensions in electromagnetic inversions}

\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\author{Seogi Kang\footnotemark[1], Rowan, Cockett, Lindsey Heagy and Douglas W. Oldenburg, Geophysical Inversion Facility, University of British Columbia}

\footer{Example}
\lefthead{Kang et al.}
\righthead{Moving dimensions in EM inversions}

\maketitle
\begin{abstract}
Electromagnetic (EM) methods are used to characterize the electrical conductivity distribution of the earth. Since EM methods consider time-varying fields, we typically treat EM in either the frequency domain (FD) or the time domain (TD). Recently, due in part to computational advances, EM geophysical surveys are increasingly being simulated and inverted in 3D. However, the availability of computational resources does not invalidate the use of lower dimensional formulations and methods, which can be useful depending on the geological complexity as well as the survey geometry. For example, we can treat the measured EM data either in TD or FD, and a progressive procedure can be used to invert these data, starting with 1D inversions, then moving to multi-dimensional inversions. As such, we require a set of tools that allow a geophysicists to easily move between dimensions and formulations of the EM problem. This is the motivation behind the open source software package SimPEG-EM which is part of a software ecosystem for Simulation and Parameter Estimation in Geophysics (SimPEG). In this presentation, we will share examples as well as our experience from creating a range of simulation and inversion tools for EM methods that span dimensions (1D, 2.5D and 3D) and apply analytic, FD and TD formulations in a consistent framework. The flexibility and consistency in our EM package allows us to be methodical so that we have the capacity to tackle a spectrum of problems in EM geophysics.
\end{abstract}
\renewcommand{\figdir}{Fig} % figure directory
\section{Introduction}

\section*{Methodology}
\subsection*{Linearization of EM responses}
An often-used representation for complex conductivity in the frequency domain is the Cole-Cole model \cite[]{COLE}
\begin{eqnarray}
  \sigma(\omega) = \sigma_{\infty} - \sigma_{\infty}\frac{\eta}{1+(1-\eta)(\imath\omega\tau)^c}.
\end{eqnarray}
where $\sigma_{\infty}$ is the conductivity at infinite frequency, $\eta$ is the chareability, $\tau$ is the time constant and $c$ is the frequency dependency. By applying inverse Fourier transform with time dependency, $e^{\imath\omega t}$, we have
\begin{eqnarray}
  \sigma(t) = \mathscr{F}^{-1}[\sigma(\omega)] = \sigma_{\infty}\delta(t) + \triangle\sigma(t)u(t)
\end{eqnarray}
where $\delta(t)$ is Dirac delta function, $u(t)$ is Heaviside step function and $\mathscr{F}^{-1}[\cdot]$ is inverse Fourier transform operator.

Modified from \cite{routh2001}, we define our IP datum as
\begin{eqnarray}
  d^{IP}(t)  = F^{EM}[\sigma_{\infty}\delta(t)+\triangle\sigma(t)u(t)] - F^{EM}[\sigma_{\infty}],
  \label{eq6}
\end{eqnarray}
where $F^{EM}[\cdot]$ is the forward modeling operator for the time domain EM problem. Note that this subtraction process has the additional benefit of removing EM coupling effects. This fact alone, allows us to better see regions of potential IP signal.

By linearizing the first term in right-hand side of equation (\ref{eq6}) with the assumption that $\Delta \sigma \ll \sigma_{\infty}$ we obtain
\begin{eqnarray}
  d^{IP}(t)  \approx \frac{\partial F^{EM}}{\partial \sigma_{\infty}}\Big|_{t = t^{*}}\sigma_{\infty}\bar{\eta}(t)
  =  \frac{\partial F^{EM}}{\partial log(\sigma_{\infty})}\Big|_{t = t^{*}}\bar{\eta}(t),
  \label{eq7}
\end{eqnarray}
where $\frac{\partial F^{EM}}{\partial \sigma_{\infty}}\Big|_{t = t^{*}}$ is the sensitivity of $F^{EM}[\cdot]$ $w.r.t$ $\sigma_{\infty}$ at arbitrary time and $\bar{\eta}(t)$ is the pseudo chargeability
\begin{eqnarray}
  \tilde{\eta}(t) = \eta\mathscr{F}^{-1}[\frac{1}{1+(1-\eta)(\imath\omega\tau)^c}]\otimes I(t)
\end{eqnarray}

Equation (\ref{eq7}) represents a linear system of equations relating the time domain IP data to pseudo-chargeability.

Clearly much of the success of the above strategy rests upon the ability to have a good estimate of the background conductivity $\sigma_{\infty}$ This is needed to generate the data and also the sensitivity function in the linear system. We have capability to efficiently carry out 3D time domain EM inversion of ATEM data (\cite{yang20143}). Before carrying out this inversion, data that are obviously contaminated with IP signal, (eg time channels with negative values) may first be winnowed. Irrespective of how well this is carried out, there may be some residual error left in the data. In synthetic cases where our background conductivity is scaled up or down by a factor, this error manifests itself as a DC shift in the $d^{IP}$ data. If the value of the shift can be estimated from the $d^{IP}$ data then the effect of the incorrect background can be removed. This motivates us to work with the $d^{IP}$ data and estimate smoothly varying background fields, which when subtracted from the $d^{IP}$ data, yield data for inversion. This procedure will work only if the scale of the perturbation from the incorrect background model is larger than the length scale of the IP signal, that is, the two signals must be separable. Our scenario is thus analagous to common works in potential fields where a background gravitational or magnetic field must be removed to reveal the anomalous field to be inverted.  Thus, in practice, we can redefine our IP datum as
\begin{eqnarray}
  d^{IP}_{corr}(t)  = d^{obs}(t) - F^{EM}[\sigma_{est}] - R(t) \nonumber \\
  = d^{IP}(t) - R(t),
  \label{eq8}
\end{eqnarray}
where $d^{IP}_{corr}(t)$ is corrected $d^{IP}(t)$ data, $d^{obs}(t)$ is the observed ATEM data, $\sigma_{est}$ is the estimated conductivity model from 3D ATEM inversion and $R(t)$ is the regional field due to incorrect background conductivity model.

% The detailed flow of our ATEM-IP inversion is shown in Figure~\ref{fig:flowchart}.

% \plot{flowchart}{width=\columnwidth}
% {The flow chart of ATEM-IP inversion.}

\subsection{Linear inversion with bound constraint}
To set up an linear inverse problem, we rewrite equation (\ref{eq7}) as
\begin{eqnarray}
  Am=d,
  \label{eq9}
\end{eqnarray}
where $d=d^{IP}_{i}$, $m = \bar{\eta}_i$, and $A=\frac{\partial F^{EM}}{\partial log(\sigma_{\infty})}\bigg|_{t=t^*}$.
Our inversion methodology is based upon that described in \cite{doug1994}. The solution to the inverse problem is the model $m$ that solves the optimization problem
\begin{eqnarray}
  minimize \ \phi =  \phi_d(m) + \phi_m(m)\nonumber \\
  s.t. \ 0 \le m,
  \label{eq10}
\end{eqnarray}
where $\phi_d$ is a measure of data misfit, $\phi_m$ is a user defined model objective function and $\beta$ is regularization or trade-off parameter. We use the sum of the squares to measure data misfit
\begin{eqnarray}
  \phi_d = \| W_d(Am-d^{obs}|)\|^2_2 =
  \sum^N_{j=1}(\frac{d^{pred}_j-d^{obs}_j}{\epsilon_j}),
  \label{eq11}
\end{eqnarray}
where $N$ is the number of the observed data and $W_d$ is a diagonal data weighting matrix which contains the reciprocal of the esitmated uncertainty of each datum (
$\epsilon_i$) on the main diagonal,  $d^{obs}$ is a vector containing the observed data, $d^{pred}$ is a vector containing calculated data from a linear equation given in equation (\ref{eq9}).
The model objective function, $\phi_m$ is a measure of amount structure in the model and, upon minimization, will generate a smooth model this is cloe to a reference model, $m_{ref}$. We define $\phi_m$ as
\begin{eqnarray}
  \phi_m = \alpha_s\| W_s(m-m_{ref})\|^2_2+
       \alpha_x\| W_x(m-m_{ref})\|^2_2+ \nonumber \\
       \alpha_y\| W_y(m-m_{ref})\|^2_2+
       \alpha_z\| W_z(m-m_{ref})\|^2_2,
  \label{eq12}
\end{eqnarray}
where $W_s$ is a diagonal matrix, and $W_s$, $W_s$ and $W_s$ are discrete approximations of the first derivative operator in $x$, $y$ and $z$ directions, respectively. The $\alpha$'s are weighting parameters that balance the relative importance of producing small or smooth models.

\section{ATEM-IP Examples}
\subsection{Synthetic Example: Conductive and chargeable body}
As a test example we use a conductive and chargeable body in the half-space as shown in Figure~\ref{fig:model}. The top panel of Figure~\ref{fig:model}, shows the survey geometry; there are 31 soundings in each 7 lines so that we have 217 soundings. We use a coincdent-loop system located 30 m above the surface. A step-off transmitter waveform is used and the range of the observed time channels is $10^{-2}$-$10^2$ $ms$. For the dicretization of the 3D earth, $20\times20\times20$ m core cells are used and the number of cells in the domain is $69\times69\times50 = 238050$. The size of the IP body is $80\times80\times80$ m and the top is $60$ m below the surface. In order to generate synthetic ATEM-IP data, we use the EMTDIP code developed by \cite[]{Marchant2012a}. By assuming we know the  true background conductivity model, we generated $\frac{db_z}{dt}$ responses of $EMIP$ and $EM$ data at the sounding locations. These are presented in Figure~\ref{fig:resp_ch1,resp_ch2}. Here $EMIP$ and $EM$ indicates $F^{EM}[\sigma_{\infty}\delta(t)+\triangle\sigma(t)u(t)]$ and $F^{EM}[\sigma_{\infty}]$, respectively. At the top-left panels of Figure~\ref{fig:resp_ch1,resp_ch2}a and b, we present time decaying curves for both simulations at sounding location $East=0$ and $North=0$ m. Black and blue lines indicate $EMIP$ and $EM$, respectively. In addition, we present all of synthetic responses with given survey geometry in the bottom panels of Figure~\ref{fig:resp_ch1,resp_ch2}(a) and (b), and the profile at center line in top-right panels of Figure~\ref{fig:resp_ch1,resp_ch2}a and b. After we generate these two responses, we subtract $EM$ from $EMIP$ to better recognize IP responses and set this IP datum as $d^{IP}$ (red lines). Thus, we simply have
\begin{equation}
  d^{IP} = EMIP - EM.
  \label{eq14}
\end{equation}
We observe that the $EMIP$ and $EM$ responses are almost identical in early time channels where EM effects are dominant.  As a result, in early time channels, it is quite hard to recognize IP effects. However, by applying the EM decoupling process shown in equation (\ref{eq14}), we can clearly identify the IP responses even in early time channels.

In practice, however, we might not know the exact background conductivity model. To investigate this we  generated $d^{IP}$ using incorrect background conductivity models, $2\sigma_{\infty}$ and $0.5\sigma_{\infty}$ and show the resultant $d^{IP}$ responses in Figure ~\ref{fig:syn_regional}. Compared to $d^{IP}$ from the correct conductivity model (blue line), data from incorrect conductivity models (red and gree lines) are biased as shown in Figure ~\ref{fig:syn_regional}(b). This example shows the potential need of estimating a regional  field ($R(t)$) and subtracting it from the EM decoupled data.

\plot{model}{width=0.75\columnwidth, height=0.22\textheight}
{Planal and sectional views of 3D complex conductivity model based on Cole-Cole representation. Dashed line in contours the boundary of the conductive IP body.}

\multiplot{2}{resp_ch1,resp_ch2}{width=0.5\textwidth, height=0.18\textheight}
{Responses of $EMIP$ (black line), $EM$ (blue line) at $t=6$ (a) and $t=24$ $ms$ (b). Top-left panels of (a) and (b) show time decay curves at center sounding location and dashed circles here show that corresponding time for other figures. Bottom pannels of (a) and (b) show that responses from all the sounding in the survey geometry at specific time channel and solid circles here indicate sounding locations. Red dashed line indicates the profile lines, which are shown at top-right panels of (a) and (b).}

\plot{syn_regional}{width=\columnwidth}
{$d^{IP}$ responses with correct and incorrect background conductivity models from all sounding locations (a) and the center East-West line (b) at $t = 12$ $ms$. }

\subsection{Field Example: Mt. Milligan VTEM data}
In 2007 a  VTEM survey was flown over the Mt. Millgian deposit as part of QUEST project intiated by Geoscience of BC. A location map as well as soundings along a profile are shown in Figure ~\ref{fig:field_back}. Note the strong negative transients near 800 $m$ distance. The data were inverted in 3D by \cite{yang20143} and the recovered conductivity model is shown in 3D (Figure ~\ref{fig:field_back}c). The conductivity inversion omitted some stations/time channels where the measured responses showed strong negative transients.  By using this 3D conductivity model, which is $\sigma_{est}$, we computed $d^{IP}$ data using equation (\ref{eq14}). In Figure ~\ref{fig:field_ch2}, we present observed data ($EMIP$), predicted data ($EM$) from 3D ATEM inversion and $d^{IP}$ data. Here we put white and black dashed circles to emphasize five $d^{IP}$ anomalies (A1-A5); white and black colors of those differentiate between locations where negative transients were observed in the raw data (A1-A3), and where transients are noted after EM coupling removal (A4 and A5). Observed data at $t$ = 4.7 $ms$ show that we cannot see any negative transients at the locations near A1-A3 anomalies (left panel of Figure~\ref{fig:field_ch2}(a)), whereas those at $t$ = 7.2 $ms$ (left panel of Figure~\ref{fig:field_ch2}(b)) show negative transients near these locations. However, by subtracting $EM$ responses predicted by 3D ATEM inversion, we can clearly recognize A1-A3 anomalies even at $t$  = 4.7 $ms$ as shown in right panel of Figure~\ref{fig:field_ch2}. Furthermore, we can identfiy A4 and A5 anomalies,which we could not identify even in a relatively late time channel ($t$ = 7.2 $ms$) of the observed data.

The next step is to account for inexact knowledge about the background conductivity. For each time channel we estimated a regional by fitting the observed data with a low order polynomial and then subtracted this regional from $d^{IP}$. This is made easier by the observation that the IP response for the coincident loop system should be negative.  The $d^{IP}$ data, the estimated regional, and the corrected data at $t = 7.2$ $ms$ are shown in Figure ~\ref{fig:field_regional}.

The final step is to carry out the inversion. At the top of the horizontal slice in Figure ~\ref{fig:field_inv}, we present corrected $d^{IP}$ responses at  $t = 7.2$ $ms$ and below that we present recovered pseudo-chargeability ($\bar{\eta}$) section at three different depth estimated from our linear inversion. In this figure, we can recognize that anomalous $d^{IP}$ responses are reasonably mapped in the 3D space and we also observe the changes of anomalous $\bar{\eta}$ bodies in depth.
Five anomalies are identified. Anomalies at A2 and A3 exhibited negative values at mid to late times and hence would have been identified as locations of chargeable material. Anomalies at A4 and A5 were not associated with negatives and are observed only because of the decoupling process. We also notice a difference in the inverted IP bodies. Bodies near A1 and A5 anomalies appears to be shallow and dies out quickly with depth. Anomalous body near A3 and A4 increases in strength and then decays with depth.

\plot{field_back}{width=0.8\columnwidth}
{Geographic location of Mt. Millgan (a). Profile of negative transients observed in a VTEM survey at the Mt. Milligan deposit in British Columbia (b). Estimated background conductivity model ($\sigma_{est}$) from 3D ATEM inversion \cite[]{yang20143} (c)}

\plot{field_ch2}{width=1.0\columnwidth}
{Observed (left panel), predicted (middle panel), $d^{IP}$ (right panel) data from 3D ATEM inversion of Mt. Milligan VTEM data at $t=4.7$ (a) and $t=7.2$ $ms$ (b). Solid dots indicate sounding and dashed circles contour five $d^{IP}$ anomalies (A1-A5). Black and white colors of dashed circles differentiate two different types of $d^{IP}$ anomalies.}

\plot{field_regional}{width=0.9\columnwidth}
{(a) $d^{IP}$ responses computed by the subtraction of predicted ATEM responses3D ATEM inversion of Mt. Milligan VTEM data at $t=7.2$ $ms$ from observed responses. Estimated regional (b) and corrected $d^{IP}_{corr}$ (b)responses based on equation (\ref{eq8}).}

\section{Conclusions}
In this study we have developed a procedure to extract IP information from ATEM data. The processing involves estimating a background conductivity, removal of EM coupling, estimating a possible residual field caused by incorrect knowledge of the conducitivity and carrying out a linearized inversion to recover a pseudo-chargeability. The inversion can be done at each time channel and the results further analysed to extract intrinsic estimates of the Cole-Cole parameters. We recognize that there are significant assumptions that have gone into generating our algorithm, principally the need to evaluate the background conductivity and the assumption that we can generate a residual field that can be removed from the data. These are issues for further research. Nevertheless, the success we have had in applying the technique to the Mt. Milligan data is encouraging.

\plot{field_inv}{width=0.45\textwidth, height=0.36\textheight}
{Corrected $d^{IP}$ by regional removal at $t=4.7$ $ms$ and horizontal slices for the distribution of recovered pseudo chargeability model at depths -20, -40 and -60 m.}

% \section{Acknowledgement}
% ...

\twocolumn
\onecolumn
% \append{The source of the bibliography}
% \verbatiminput{example.bib}
\bibliographystyle{seg}  % style file is seg.bst
\bibliography{example}

\end{document}


% !TEX root = ../thesis.tex

\chapter{Methods}
% \label{cha:dmd_methods}
In this chapter, I am first going to describe the optical setup that was built to work on the DMD independently from the running experiment. To use a camera for image correction with the DMD, a pixel to pixel mapping is needed. For this, I will start with the algorithm to calibrate the camera and then explain how this calibration is used to map a camera image to DMD pixel coordinates. Finally, I will introduce the actual error correction algorithms.

\section{Testing Setup}
% \label{sec:dmd_testing_setup}
\Cref{fig:dmd_test_setup} shows the test setup that was built for the development of the correction algorithms. We use a \SI{770}{nm} laser\footnote{Toptica DL Pro} as illumination for the DMD\footnote{Vialux DLP7000}. The beam is guided onto the table with an optical fibre and then collimated by a lens with a long focal length. The large diameter beam is then reflected onto the DMD with a mirror mounted on a rotation mount. The angle of this mirror is adjusted such that the \emph{ON}-direction of the DMD is level with the breadboard while the \emph{OFF}-direction is shined onto a beam dump. The projection is then imaged onto a CCD camera\footnote{Thorlabs DDC1545M, monochrome sensor, $1280\times 1024$ pixels} with a telescope.
\begin{figure}[htbp]
    \centering
    \input{TexContents/Figures/DMD/TestSetup/setup.tikz}
    \caption[Test setup for the DMD]{The laser beam from the optical fibre (A) is collimated by a lens (B) and then mirrored onto the DMD (C). A beam dump (D) captures the excess light in the \emph{OFF}-direction. The light reflected in the \emph{ON}-direction is imaged onto the CCD camera (F) using a telescope (E).}
    \label{fig:dmd_test_setup}
\end{figure}

\section{Camera Calibration}
% \label{sec:dmd_camera_calibration}
As mentioned earlier, a good camera calibration is required for usable correction results. The better we know which camera pixels are related to which DMD pixels, the more accurate we can make the correction algorithm. A very simple idea would be to take the positions of the DMD corners on the camera and then apply a rectangular transformation to get the mapped coordinates. But due to nonlinear imaging aberrations, the DMD edges could appear slightly curved on the camera. This makes a simple rectangular transformation generally impractical. While the setup in this work could indeed function with only a rectangular transformation between camera and DMD, the algorithms developed here are supposed to function in a general scenario.

So instead, we project a pattern of small dots which can be detected on the camera. An example of a grid like this is given in \cref{fig:point_matrix_example}. If the distance between these dots is small enough, the edges they form can be approximated as straight lines, even if the line between two corners of the image is curved. The quadrilaterals formed by four dots can be mapped to the corresponding square on the DMD using an algorithm that conserves the ratio between two lengths (see \cref{sec:dmd_mapping}). We further require the number of dots in both directions to be odd so the centre of the DMD has a dot in all cases.

\vfill
\begin{figure}[htbp]
    \centering
    % \pdfpxdimen=\dimexpr 1 in/96\relax
    % \includegraphics[scale=1.4,trim=220px 194px 186px 140px,clip]{DMD/grid-unmapped}
    \includegraphics{DMD/gridWithInset}
    \caption[Camera image of a grid with 165 equally spaced points]{The original image is $640\times 512$ pixels large, the image shown here has been cropped to the region $(220,140)$--$(454,318)$. The inset shows the comparatively dark points with a false colour scale.}
    \label{fig:point_matrix_example}
\end{figure}
\vfill
\pagebreak

\subsection{Point Detection}
% \label{sec:dmd_point_detection}
\Cref{fig:point_matrix_example} shows the camera image of a grid of points with equal spacing. Although the edges of the pattern projected from the DMD are dark, the camera captures a lot of reflected light from the edges of the DMD chip. For calibration, we can easily circumvent this by taking another picture where all pixels are set to \emph{OFF} and subtracting this from the image with the points.

The detection algorithm for the points works as follows:
\begin{enumerate}
    \item Iterate over all the pixels from top to bottom and left to right.
    \item If the intensity at one pixel reaches a previously fixed threshold, search the region \SI{5}{px} in all directions for the pixel $(x_\text{max},y_\text{max})$ with the highest intensity.
    \item The coordinates of the gridpoint are determined as an intensity-weighted average over the region \SI{5}{px} around $(x_\text{max},y_\text{max})$: \[\begin{pmatrix}
        x \\ y
    \end{pmatrix} = \frac{\sum\limits_{j = -5}^5 \sum\limits_{i = -5}^5 \begin{pmatrix}
        x_\text{max} + i \\ y_\text{max} + j
    \end{pmatrix}\times I(x_\text{max} + i, y_\text{max} + j)}{\sum\limits_{j = -5}^5 \sum\limits_{i = -5}^5 I(x_\text{max} + i, y_\text{max} + j)} \]
    \item The region that has been searched in step 2 and the region over which the average is taken in step 3 are marked as processed. This ensures that the same gridpoint is not \enquote{detected} twice.
\end{enumerate}
% To detect the points on the camera image, the pixels are traversed from top to bottom and from left to right  and if a pixel reaches a certain intensity, the region around this pixel is searched for the brightest spot. The location of the point is then decided by intensity-weighted averaging over a region aroung the brightest pixel (\cref{alg:dmd_point_detection}).
%
All gridpoints that have been detected are added to a common list. Unfortunately, this list is not necessarily sorted, meaning it is not yet possible to assign a point from the original grid to one corresponding point in the list of detected points.

\subsection{Point Sorting}
% \label{sec:dmd_point_sorting}
We sort the detected points using the pattern sketched in \cref{fig:sorting_tikz} and as follows:
\begin{enumerate}
    \item Find the basis vectors from the central gridpoint up ($\hat{y}$) and to the right ($\hat{x}$) by projecting two more images with only the centre and one neighbouring spot in the vertical and horizontal direction lit up, respectively.
    \item Use $\hat{y}$ and $-\hat{y}$ to find the nearest points up and down from the centre. \textbf{(a)}
    \item Continue up and down, using the difference between the last two points to define new local basis vectors $\hat{y}_\uparrow$ and $\hat{y}_\downarrow$. \textbf{(b)}
    \item Stop at the gridpoints closest to the edges.
    \item Expand to the columns to the right and left from the centre, using $\hat{x}$ and $-\hat{x}$ to locate the nearest gridpoints left and right. \textbf{(c)}
    \item To find the next points up and down, use the difference between the already found gridpoints one column inwards to get an estimate. \textbf{(d)}
    \item Continue up and down as in step 3 and 4, defining now four different local basis vectors $\hat{y}_{\uparrow,l}$, $\hat{y}_{\uparrow,r}$, $\hat{y}_{\downarrow,l}$, $\hat{y}_{\downarrow,r}$. \textbf{(e)}
    \item Missing gridpoints are replaced by the respective guess \textbf{(e)}, \textbf{(h)}; See below for detail.
    \item Repeat steps 5--7 until all the gridpoints except the outermost edges have been sorted. \textbf{(f)}--\textbf{(h)}
    \item If possible, improve the estimated position of missing points \textbf{(i)}; See below for detail.
\end{enumerate}
\begin{figure}[tbp]
    \centering
    \input{TexContents/Figures/DMD/PointSorting/sort.tikz}
    \vspace*{-5mm}
    \caption[Sketch of the point sorting algorithm]{The central column is handled first and then the rows are expanded outwards. All detected grid points are black, already sorted ones green and currently searched ones blue. The black arrows are pointing to the estimated location of the next gridpoint and the grey arrows show the local basis vectors. Missing gridpoints are indicated by a cross.}
    \label{fig:sorting_tikz}
\end{figure}
In each step, the actual coordinates of the gridpoint are found from the estimated position $P_\text{guess}$ by searching the detected list for the closest match $\tilde{P}$. Until now, the underlying assumption has been that all gridpoints have actually been detected in the previous stage. However, if that is not the case, the point $\tilde{P}$ might be a neighbouring gridpoint. To account for this, the distance between $P_\text{guess}$ and $\tilde{P}$ must not exceed half the distance between the last two known gridpoints. Otherwise, the point is marked as \enquote{missing} and replaced by $P_\text{guess}$ for the time being, just to be able to continue with the sorting \textbf{(e)}, \textbf{(h)}. At the end, missing gridpoints can be replaced by averaging the coordinates of the gridpoints to the left, right, top and bottom, but only if those have not been marked as missing themselves \textbf{(i)}.
If too many points are missing, the entire list is rejected and the calibration fails.

Finally, we have to address the gridpoints at the outer edges. Due to the leakage light as seen in \cref{fig:point_matrix_example}, points at the edges can never be detected and have to be extrapolated at the end of the sorting algorithm. This extrapolation can lead to errors in the mapping, which are very apparent in the example in \cref{fig:mapping_example_mapped}.

% The vertical basis vector is used to find the next point up- and downwards from the centre. Now the next points are found using the difference between the last two points as a guess:
% \begin{equation}
%     P_{n+1,\text{guess}} = 2P_n - P_{n-1} \nonumber
% \end{equation}
% Once a column has been completely sorted, the horizontal basis vector is used to find the starting points of the next column (step 3) etc.\ until all points are sorted.

% To get the actual coordinates of a grid point from the guess, the list of detected points is searched for the point with the smallest distance to $P_{n+1,\text{guess}}$. If this distance too high, it is likely that a neighbouring point was selected and the target point had not been detected at all. If this happens, the guess is used instead. The grid positions of these points is stored in a separate list. When all grid points are sorted, either by finding the correct point in the list of detected points or by guessing, we can try to improve all the guesses. If the surrounding four points (left, right, top and bottom) of a guessed point have been detected correctly, the guessed one is updated as the average of these four surrounding points. If the number of remaining guesses is too high after this, the complete list is rejected. Because the edges of the DMD appear very bright on the camera, the outermost points are all guesses. This is of course not ideal and results in errors which can be seen in \cref{fig:mapping_example_mapped}.

Of course, the need for a sorting method like this could be avoided entirely if every single gridpoint was projected by itself. However, this can take very long and if the calibration works reliably while needing far fewer images, then the added complication is worth it.

\section{Camera Mapping}
\label{sec:dmd_mapping}
At this point we know the coordinates of the camera pixels that correspond to the gridpoints on the DMD. Now we need to find an expression for all the pixels in between. We can reduce this problem to a singular square of gridpoints on the DMD. We know the coordinates of the four pixels on the camera that mark the corners of this square, therefore we can map the space in between them using the scheme shown in \cref{fig:dmd_mapping_scheme}.

To find the coordinates of a point on an irregular quadrilateral $P'$ that corresponds to a point $P$ on a unit square, we take the $x$ and $y$ coordinates on the unit square and apply them as length ratios to the sides of the quadrilateral, $\overline{A'B'}$ and $\overline{C'D'}$ for the $x$ direction and $\overline{A'C'}$ and $\overline{B'D'}$ for the $y$ direction, giving us the points $U$, $V$, $W$, $Z$. The point $P'$ is found where the lines $\overline{UW}$ and $\overline{ZV}$ cross (refer to \cref{fig:dmd_mapping_scheme} for definitions):
\begin{align*}
    \vec{P'} = \begin{pmatrix} x' \\ y'\end{pmatrix} &= \left\{ \vec{U} + r\cdot \left(\vec{W} - \vec{U}\right),\ r\in \mathbb{R} \right\} \cap \left\{ \vec{Z} + s\cdot \left(\vec{V} - \vec{Z}\right),\ s\in \mathbb{R} \right\} \\
    &= \begin{pmatrix} U_x \\ U_y\end{pmatrix} + r \cdot \begin{pmatrix} W_x - U_x \\ W_y - U_y\end{pmatrix},\ r = \frac{Z_y - U_y - (Z_x - U_x)\frac{V_x - Z_x}{V_x - Z_x}}{W_y - U_y - (W_x - U_x)\frac{V_y - Z_y}{V_x - Z_x}}
\end{align*}
where
\begin{align*}
    \vec{U} &= \left(\vec{A'} + x\cdot\left(\vec{B'} - \vec{A'}\right)\right), \quad \vec{V} = \left(\vec{B'} + y\cdot\left(\vec{D'} - \vec{B'}\right)\right),  \\
    \vec{W} &= \left(\vec{C'} + x\cdot\left(\vec{D'} - \vec{C'}\right)\right), \quad \vec{Z} = \left(\vec{A'} + y\cdot\left(\vec{C'} - \vec{A'}\right)\right).
\end{align*}
% The coordinates $(x'|y')$ of the point $P'$ are then found as
% \begin{equation*}
%     \begin{pmatrix}
%         x' \\ y'
%     \end{pmatrix} = \vec{U} + r \cdot \left(\vec{W} - \vec{U}\right) \quad \text{with}\ r = \frac{Z_y - U_y - (Z_x - U_x)\frac{V_x - Z_x}{V_x - Z_x}}{W_y - U_y - (W_x - U_x)\frac{V_y - Z_y}{V_x - Z_x}}.
% \end{equation*}
\vfill
\begin{figure}[hbp]
    \centering
    \input{TexContents/Figures/DMD/quadrilateraltransformation.tikz}
    \caption[Mapping a unit square onto an irregular quadrilateral]{The points $U$, $W$ ($V$, $Z$) divide the sides $\overline{A'B'}$, $\overline{C'D'}$ ($\overline{B'D'}$, $\overline{A'C'}$) by the ratio $x$ ($y$).}
    \label{fig:dmd_mapping_scheme}
\end{figure}
\vfill

\noindent
Applying this to the DMD, we get the following algorithm for mapping each individual pixel $P$:
\begin{enumerate}
    \item Find the closest four gridpoints and their corresponding camera counterparts.
    \item Use the scheme explained before to find the floating point coordinates $(x' | y')$ of this pixel on the camera $P'$.
    \item The mapped pixel value is then found by averaging the four pixels surrounding $P'$, with weights given by the reciprocal distance to $P'$: \[I_\text{mapped} = \frac{\sum\limits_{j=0}^1 \sum\limits_{i=0}^1 \frac{I_\text{camera}(\floor{\tilde{x}} + i,\floor{\tilde{y}} + j)}{\sqrt{\left(\floor{\tilde{x}} - \tilde{x} + i\right)^2 + \left(\floor{\tilde{y}} - \tilde{y} + j\right)^2}}}{\sum\limits_{j=0}^1 \sum\limits_{i=0}^1 \frac{1}{\sqrt{\left(\floor{\tilde{x}} - \tilde{x} + i\right)^2 + \left(\floor{\tilde{y}} - \tilde{y} + j\right)^2}}} \]
    % Here, $\floor{}$ is the floor function.
\end{enumerate}
\Cref{fig:mapping_example} shows an example of the applied mapping algorithm.
% \textbf{Note:} Because the mapped coordinates of $P'$ are floating point values, the intensity on the mapped image is calculated from the average of the four pixels surrounding $P'$, weighted by the distance of the pixel to the floating point coordinates of $P'$. An example of the mapped camera image can be seen in \cref{fig:mapping_example}

\vspace*{7mm}
\begin{figure}[hbp]
    \centering
    \begin{subfigure}[c]{0.45\textwidth}
        \pdfpxdimen=\dimexpr 1 in/96\relax
        \includegraphics[clip, trim=220px 194px 186px 140px,width=\textwidth]{DMD/Mapping/camlogo2-unmapped-uncropped}
        \caption{Unmapped camera image}
    \end{subfigure}\\[\baselineskip]
    \begin{subfigure}[c]{0.49\textwidth}
        \centering
        \frame{\includegraphics[width=0.825\linewidth]{DMD/Mapping/camlogo2-target}}
        \caption{Target pattern on the DMD}
        \label{fig:mapping_example_target}
    \end{subfigure}
    \begin{subfigure}[c]{0.49\textwidth}
        \centering
        \includegraphics[width=0.825\linewidth]{DMD/Mapping/camlogo2-mapped}
        \caption{Resulting mapped image}
        \label{fig:mapping_example_mapped}
    \end{subfigure}
    \caption[Example images for the camera-to-DMD mapping]{The unmapped camera capture (cropped) is shown in (a). (b) and (c) show the comparison between the projected pattern and the mapped image. Note that the rotation of the camera image was corrected automatically.}
    \label{fig:mapping_example}
\end{figure}

\section{Error Correction}
% \label{sec:dmd_error_correction_theory}
The previous works mentioned in \cref{sec:pastworks} were mainly concerned with the creation of flat-top beams. For this purpose, the entire dynamic range of the DMD was usable. However, if there is stray light in a portion where the DMD pixels are already off, it is not possible to reduce the light level in that area as a correction. This situation will be the main focus of the correction algorithms here.

The generation of an error signal is very straightforward. A camera image is taken and mapped. We can then subtract the target intensities from the pattern projected on the DMD\footnote{If the target was a greyscale image, the DMD pattern will have to be blurred by a small amount to reverse the dithering.} from this to get the intensity deviation. \Cref{fig:imaging_error_example} shows an example of this. At the edges of the shapes, large errors are detected. These result from subpixel mapping errors and from the surrounding light. Because they would otherwise lead to strong overcorrections, these edge effects should be handled separately by the correction algorithm.
\begin{figure}[p]
    \centering
    \begin{subfigure}[t]{0.49\textwidth}
        \centering
        \frame{\includegraphics[width=0.825\linewidth]{DMD/Mapping/twoshapes-target}}
        \caption{DMD target pattern}
        \label{fig:imaging_error_target}
    \end{subfigure}
    \begin{subfigure}[t]{0.49\textwidth}
        \centering
        \includegraphics[width=0.825\linewidth]{DMD/Mapping/twoshapes-mapped}
        \caption{Resulting mapped camera image}
    \end{subfigure} \\[\baselineskip]
    \begin{subfigure}[T]{.49\textwidth}
        \centering
        \includegraphics[clip, trim=0 0 52px 0]{DMD/Mapping/twoshapes-error}
        \caption{Difference between (b) and (a)}
    \end{subfigure}
    \hspace{-0.7em}
    \begin{subfigure}[T]{.06\textwidth}
        \centering
        \includegraphics[clip, trim=228px 0 25px 0]{DMD/Mapping/twoshapes-error}
    \end{subfigure}
    \hspace{-1.1em}
    \begin{subfigure}[T]{.065\textwidth}
        \centering
        \includegraphics[clip, trim=251px 0 0 0.9px]{DMD/Mapping/twoshapes-error}
    \end{subfigure}
    \caption[Example of DMD imaging error]{At the edges of the shapes, large deviations are detected. This is partly due to sub-pixel imperfections in the mapping from (a) to (b).}
    \label{fig:imaging_error_example}
\end{figure}

\subsection{Edge Detection}
To perform this edge detection, we can use a simple contrast-based model. We define an edge as a region where the difference of the intensity of neighbouring pixels exceeds a certain threshold value. The discontinuity $D$ in the vertical and horizontal direction at position $(x,y)$ is calculated as
\begin{align*}
    D_\text{vertical}(x,y,r) &= \frac{\sum_{j=-r}^{r} \sum_{i=-r}^{r} \left| I_{x+i,y+j} - I_{x+i,y-j} \right|}{\sum_{j=-r}^{r} \sum_{i=-r}^{r} \chi (x+i,y+j,x+i,y-j)}, \\
    D_\text{horizontal}(x,y,r) &= \frac{\sum_{j=-r}^{r} \sum_{i=-r}^{r} \left| I_{x+i,y+j} - I_{x-i,y+j} \right|}{\sum_{j=-r}^{r} \sum_{i=-r}^{r} \chi (x+i,y+j,x-i,y+j)}.
\end{align*}
% \begin{equation*}
%     D_\text{vertical} > D_\text{threshold} \lor D_\text{horizontal} > D_\text{threshold}
% \end{equation*}
Here, $2r+1$ is the side length of the square area around $(x,y)$ that is sampled over, $I_{i,j}$ is the intensity at pixel $(i,j)$ and $\chi(x_1,y_1,x_2,y_2)$ is defined as 1 if both points are within the image area and 0 otherwise. There is an edge at $(x,y)$ if either $D_\text{vertical}$ or $D_\text{horizontal}$ surpasses a pre-defined threshold $D_\text{threshold}$. This algorithm has been adapted from \cite{wu:2015}.

$D_\text{threshold}$ and $r$ are user-specified parameters. In this work, $D_\text{threshold}$ is always fixed to a value of 35. A lower value results in the detection of far more pixels as edges and a higher value does not guarantee the detection of all edges. How the parameter $r$ has to be chosen depends on how well the DMD surface is resolved on the camera. This influence is studied in detail in \cref{sec:results_edgedetection}.
\Cref{fig:edge_detection_example} shows the detected edges with a setting of $r=\SI{4}{px}$ in the patterns from \cref{fig:imaging_error_target,fig:mapping_example_target}.
\begin{figure}[htbp]
    \centering
    \begin{subfigure}[t]{0.49\textwidth}
        \centering
        \frame{\includegraphics[width=0.825\linewidth]{DMD/EdgeDetection/camlogo-edges-1pxblur}}
        \caption{Edges in \cref{fig:mapping_example_target}}
    \end{subfigure}
    \begin{subfigure}[t]{0.49\textwidth}
        \centering
        \frame{\includegraphics[width=0.825\linewidth]{DMD/EdgeDetection/twoshapes-edges-noblur}}
        \caption{Edges in \cref{fig:imaging_error_target}}
    \end{subfigure}
    \caption[Examplary results of the edge detection algorithm]{Before the edge detection was applied to \cref{fig:mapping_example_target}, the dithering was reversed using a Gaussian blur filter with a \SI{1}{px} radius.}
    \label{fig:edge_detection_example}
\end{figure}

\subsection{Linear Feedback}
The correction we are aiming for is directed both at the parts that are too dark and the parts that are too bright. If the target intensity in an area is zero but there is actually light in that area, we obviously cannot reduce this light level using the DMD. Instead, we have to raise the overall light level so the deviation is evened out. Parts of the image that are too dark need to receive more light. If this is not possible because the DMD already reflects \SI{100}{\percent} of the incident light, then we have to lower the overall light level. These changes reduce the contrast of the trap which in turn decreases the lifetime of the atomic cloud due to increased scattering of light in the centre. \Cref{fig:linear_feedback_scheme} shows how this intensity correction works in the case of a box that is generated from a non-flat beam where additional inhomogeneities disturb the dark centre.

For the actual implementation, the linear feedback is divided into two parts. In the first iteration it is decided by how much the maximum intensity needs to be lowered and how much of an offset needs to be introduced to the dark parts. The following iterations only serve to improve on the results of the first correction.
%
\begin{enumerate}
    \item Blur both the target pattern and the camera capture with a Gaussian filter of \SI{1}{px} radius. The target needs to be blurred in this way because of the dithering that had been applied before. The mapped camera image is blurred to remove very fine noise that could not be corrected anyway as the mapping is not completely perfect on the scale of a single pixel.
    \item Convert greyscale levels from the range $[0,255]$ to $[0,1]$.
    \item Apply the edge detection on the target image and store the results as Boolean values.
    \item Calculate the difference between camera and target brightness \[\Delta_{ij} = I_\text{Camera}[i,j] - I_\text{DMD}[i,j].\] For pixels that are at an edge, ignore the difference for now and set it to 0.
    \item Find the extrema of $\Delta_{ij}$. The positive maximum $\Delta^+$ is the amount by which the picture needs to be brightened and vice versa for the negative maximum $\Delta^-$.
    \item Calculate the difference at the edges again. This time, do not ignore it but use the extrema found before as limits.
    \item Calculate the updated pattern as \[I_\text{DMD}'[i,j] = I_\text{DMD}[i,j]\times \underbrace{(1- | \Delta^- | - \Delta^+)}_{\text{Rescaling}} + \underbrace{\Delta^+}_{\text{Offset}} - \Delta_{ij}. \] The rescaling and offset are applied to account for the reduced overall dynamic range. The updated image then has minimum and maximum values of $\Delta^+$ and $1 - |\Delta^-|$.
    \item Apply dithering and upload to the DMD.
    \item Capture a new camera image and blur it as before (\SI{1}{px} Gaussian).
    \item Calculate the difference to the target. Ignore values that are out of bounds.
    \item Update the target pattern, apply dithering and upload the new pattern to the DMD.
    \item Repeat steps 9--11 until the relative reduction of the RMS deviation of two subsequent images is less than \SI{2}{\percent}.
\end{enumerate}
\begin{figure}[tbp]
    \centering
    % \begin{subfigure}[c]{0.52\textwidth}
    %     \centering
    %     \includegraphics[]{DMD/LinearFeedbackSketch/sketch}
    %     \caption{Uncorrected}
    % \end{subfigure}
    % \begin{subfigure}[c]{0.47\textwidth}
    %     \centering
    %     \includegraphics[]{DMD/LinearFeedbackSketch/sketch1_correct}
    %     \caption{Corrected}
    % \end{subfigure}
    \begin{subfigure}[T]{0.06\textwidth}
        \begin{tikzpicture}
            \draw[-latex,thick] (0,0) -- (0,3.8) node[midway,left=25pt, rotate=90, anchor=north] {\small Intensity (arb.\ units)};
        \end{tikzpicture}
    \end{subfigure}
    \begin{subfigure}[T]{0.42\textwidth}
        \centering
        \includegraphics[width=.98\textwidth]{DMD/LinearFeedbackSketch/sketch}
        \caption{Uncorrected}
    \end{subfigure}
    \begin{subfigure}[T]{0.42\textwidth}
        \centering
        \includegraphics[width=.98\textwidth]{DMD/LinearFeedbackSketch/sketch1_correct}
        \caption{Corrected}
    \end{subfigure}
    \caption[Basic example of linear feedback]{(a) The box pattern on the DMD (dash-dotted) results in a camera image (solid) with deviations (blue~$=$~too dark, green~$=$~too bright). Assuming a linear relationship between the DMD's reflectivity and the intensity recorded on the camera, the corrected pattern in (b) would result in a box with lower contrast but correct shape.}
    \label{fig:linear_feedback_scheme}
\end{figure}

\subsection{Maxima/Minima Suppression}
The second correction algorithm also uses the difference between camera and target image as feedback, but it includes the binary nature of the DMD. Rather than calculating a new pattern of greyscale values and dithering that again, it switches certain pixels on or off depending on the brightness values on the camera image. This method was originally developed by Liang et al.\ \cite{liang:2010}.
\begin{enumerate}
    \item Calculate the difference between camera and target. During this procedure edges are ignored completely.
    \item Find the pixel with the maximum deviation (both positive and negative).
    \item Search the surrounding area for the nearest pixel that is neither too bright nor too dark. The search is performed on the edges of a square with side length $2r+1$, where $r$ starts at 1 and increases until a pixel with a deviation of the opposite sign of the original pixel is found.
    \item Sum up the target and actual intensities $I_\text{target}$ and $I_\text{actual}$ of all the pixels in this area.
    \item Count the number of pixels on the DMD in this area that are already on $N_\text{\textit{ON}}$.
    \item The number of pixels that have to be switched is then given by \[N_\text{switch} = \left| \frac{I_\text{target}}{I_\text{actual}} - 1 \right|\times N_\text{\textit{ON}}. \]
    \item Switch on/off $N_\text{switch}$ pixels in this area. For this, draw pixel coordinates from a Gaussian distribution centred around the pixel with maximum difference and with a standard deviation of $r$. If the pixel at the drawn coordinates does not need to be switched, draw new coordinates.
    \item Mark the area as \enquote{processed} by setting the difference to 0.
    \item Repeat steps 1--7 until the whole image has been processed.
    \item Project the new pattern.
    \item Repeat until the RMS error of two subsequent images has shrunk by less than \SI{1.5}{\percent}.
\end{enumerate}
Unfortunately, because many pixels are surrounded by only a few pixels where the sign of the difference stays the same, this adjustment process is very slow. We decided that it would be best to set additional breakoff conditions; one iteration is stopped if the number of pixels that has been switched on or off reaches a threshold value. This means that noise on the smallest scale is effectively ignored. Another breakoff condition is derived from the variance of the difference. Whenever the difference is set to 0 for a certain area (see above, step 8), this is also reflected in a theoretical change in the total variance. Once the square root of the variance (the RMS error) falls below a threshold, the search for new maxima and minima is stopped. Overall, we also impose a limit on how often new maxima/minima are searched in the difference image. This last breakoff is mainly due to time constraints. All conditions are outlined in \cref{tab:suppression_breakoffs}.
\begin{table}[bp]
    \centering
    \caption{Breakoff conditions for the maxima/minima suppression algorithm.}
    \begin{tabular}{rS[table-format=5]S[table-format=1.2]S[table-format=5]}
        \toprule
        \multicolumn{1}{c}{Iteration} & \multicolumn{1}{c}{max.\ on/off switches} & \multicolumn{1}{c}{min.\ RMS error / \si{\percent}} & \multicolumn{1}{c}{\shortstack[c]{max.\ no.\ of maxima/\\ minima processed}}  \\
        \midrule
        1     & 20000 & 1 & 20000 \\
        2     & 10000 & .2 & 10000 \\
        $\geq 3$  & 10000 & .01 & 40000 \\
        \bottomrule
    \end{tabular}
    \label{tab:suppression_breakoffs}
\end{table}

It is important to point out that the RMS error is not the actual RMS error of the resulting image, just a helping variable used in the algorithm that tracks the remaining error when the differences are set to 0 to indicate that an area has been processed.\\[\baselineskip]
\noindent
In this work, the linear feedback is applied first and the maxima/minima suppression then reduces remaining noise.


\documentclass[a4paper,twocolumn]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsbsy}

\usepackage[cm]{fullpage}
\usepackage[small]{titlesec}
% patch titlesec bug of not showing (sub)title numbering http://tex.stackexchange.com/a/300259
\usepackage{etoolbox}
\makeatletter
\patchcmd{\ttlh@hang}{\parindent\z@}{\parindent\z@\leavevmode}{}{}
\patchcmd{\ttlh@hang}{\noindent}{}{}{}
\makeatother

\let\originalleft\left
\let\originalright\right
\renewcommand{\left}{\mathopen{}\mathclose\bgroup\originalleft}
\renewcommand{\right}{\aftergroup\egroup\originalright}

\usepackage{amssymb}
\renewcommand{\H}{\mathcal{H}}
\newcommand{\N}{\mathcal{N}}
\renewcommand{\L}{\mathcal{L}}
\renewcommand{\O}{\mathcal{O}}
\newcommand{\Lhybrid}{\L_{\mathtt{hybrid}}}
\newcommand{\Ldisc}{\L_{\mathtt{disc}}}
\newcommand{\Lgen}{\L_{\mathtt{gen}}}

\let\originalnu\nu
\renewcommand{\nu}{\boldsymbol{\originalnu}}

\title{Online Incremental Feature Learning with Denoising Autoencoders$-$ summary}
\author{Matěj Nikl}

\begin{document}
\maketitle
\noindent
Determining the optimal model complexity, i.e. the number of features for DAE is a nontrivial problem. Moreover, in large-scale and online datasets the cross-validation method enabling the hyper-parameter search is even more challenging.

This adaptive feature learning algorithm tries to address the given issue by:
\begin{enumerate}
    \item adding and training new features to minimize the residual of the objective function
    \item merging similar features to avoid redundant feature representations
\end{enumerate}
Having a variable number of features gives the model the ability to make itself more/less complex according to the (even changing) dataset needs.

\section{Denoising Autoencoder}
The standard Denoising Autoencoder is used as a building block for incremental feature learning, it consists of four components:
\begin{itemize}
    \item a conditional distribution $q(\mathbf{\widetilde{x}|x})$, that corrupts $\mathbf{x}$ into $\mathbf{\widetilde{x}}$
    \item an encoding function $f(\mathbf{\widetilde{x}}) = \sigma(\mathbf{W\widetilde{x} + b}) \equiv \mathbf{h} \in \mathbb{R}^N$, which gives a representation of input data $\mathbf{x}$
    \item an decoding function $g(\mathbf{h}) = \sigma(\mathbf{W}^T\mathbf{h + c}) \equiv \mathbf{\widehat{x}} \in \mathbb{R}^D$, which recovers the data from the representation $\mathbf{h}$
    \item a differentiable (cross-entropy) cost function $\L(\mathbf{x}) = \H(\mathbf{x}, \mathbf{\widehat{x}}) \in \mathbb{R}$, which computes the dissimilarity between input and reconstruction
\end{itemize}

\section{Incremental Feature Learning}
The incremental feature learning algorithm needs to address the following problems:
\begin{enumerate}
    \item \textbf{when} to add and merge features
    \item \textbf{how} to add and merge features
\end{enumerate}
In order to deal with these problems, the authors have chosen the following procedure:
\begin{enumerate}
    \item form a set $B$ of hard training examples: $B \leftarrow B \cup \{\textbf{x}\}$ if $\L(\textbf{x}) > \mu$, which is used to greedily train the new features
    \item merge similar + add new features when there are enough examples in $B$: $|B| > \tau$
\end{enumerate}
I.e. when there is enough \textit{hard} examples, $2\Delta M$ old features are merged into $\Delta M$ new features, $\Delta N$ new features are simply added, and these new features are greedily trained on the set $B$ of hard training examples. After convergence, set $B = \emptyset$ and continue standard training of all features.

In this paper $\mu$ was set as average of the objective function for recent $10000$ examples, $\tau$ was also set as 10000.

\paragraph{Notations.} $D$ denotes input dimension, $N$ the number of (existing) features, and K the number of class labels. The parameters for generative training are defined as the (tied) weight matrix $\mathbf{W} \in \mathbb{R}^{N \times D}$, the hidden bias $\mathbf{b} \in \mathbb{R}^N$, and the input bias $\mathbf{c} \in \mathbb{R}^D$. Similarly, the parameters for discriminative training are composed of the weight matrix $\mathbf{\Gamma} \in \mathbb{R}^{K \times N}$ between hidden and output units, the output bias $\nu \in \mathbb{R}^K$, as well as the weight matrix $\mathbf{W}$ and the hidden bias $\mathbf{b}$. $\N$ is used to denote \textit{new} features and $\O$ to denote existing or \textit{old} features, thus $\theta_\O = \{\mathbf{W_\O, b_\O, c, \Gamma_\O, \nu}\}$, and $\theta_\N = \{\mathbf{W_\N, b_\N, c, \Gamma_\N, \nu}\}$.

\begin{figure*}[t]
    \centering
    \includegraphics[width=0.9\textwidth]{graph.png}
    \caption{(a,d) Test (online) reconstruction error and classification error of incremental (IncMDAE) and non-incremental DAE. (b,e) The number of features for incremental learning with generative and hybrid criteria. (c,f) Test reconstruction error and classification error at convergence. The numbers in parentheses refer to the initial number of features.}
    \label{fig:graph}
\end{figure*}

\subsection{Adding Features} \label{ssec:adding}
New features are being added and trained upon, whenever there is enough examples in the \textit{hard set} $B$.
The basic idea for efficient training is that only the new features $\theta_\N$ are trained to minimize the objective function while keeping $\theta_\O$ fixed.

\subsubsection{Generative Objective Function}
Measures reconstruction error between the input $\mathbf{x}$ and the reconstruction $\mathbf{\widehat{x}}$:
\begin{equation}
    \Lgen(\mathbf{x}) = \H(\mathbf{x}, \mathbf{\widehat{x}})
\end{equation}
The encoding and decoding functions for the new features can be written as:
\begin{align}
    \mathbf{h}_\N &= sigm(\mathbf{W_\N \widetilde{x}} + \mathbf{b_\N}) \\
 \label{equ:dec}
    \mathbf{\widehat{x}} &= sigm(\mathbf{W}_\N^T\mathbf{h}_\N + \mathbf{W}_\O^T\mathbf{h}_\O + \mathbf{c})
\end{align}
Moreover, since $\theta_\O$ is fixed, equation \eqref{equ:dec} can be rewritten to:
\begin{equation}
    \mathbf{\widehat{x}} = sigm(\mathbf{W}_\N^T\mathbf{h}_\N + c_d(\mathbf{h}_\O))
\end{equation}
where $c_d(\mathbf{h}_\O) \equiv \mathbf{W}_\O^T\mathbf{h}_\O + \mathbf{c}$ is viewed as a \textit{dynamic} decoding bias.
This allows for a efficient way of training new features, because $c_d(\mathbf{h}_\O)$ can be computed for each training example only once and then recalled without additional computational cost.

\subsubsection{Discriminative Objective Function}
Computes a classification loss between the actual label $\mathbf{y}$ and the predicted label $\mathbf{\widehat{y}}$:
\begin{gather}
    \Ldisc(\mathbf{x}, \mathbf{y}) = \H(\mathbf{y}, \mathbf{\widehat{y}}(\mathbf{x})) \\
    \mathbf{\widehat{y}} = \mathrm{softmax}(\mathbf{\Gamma_\N}f_\N(\mathbf{\widetilde{x}}) + \mathbf{\Gamma_\O}f_\O(\mathbf{\widetilde{x}}) + \nu)
\end{gather}
A similar interpretation for $\mathbf{\Gamma_\O}f_\O(\mathbf{\widetilde{x}}) + \nu$, as in the generative training is possible, and therefore, the new parameters $\{\mathbf{W_\N, b_\N, \Gamma_\N}\}$ can be trained efficiently as well.

\subsubsection{Hybrid Objective Function}
The proposed objective function for training new features is a linear combination of a generative and a discriminative objective function, called a \textit{hybrid} objective function:
\begin{equation}
    \Lhybrid = \Ldisc(\mathbf{x}, \mathbf{y}) + \lambda\Lgen(\mathbf{x})
\end{equation}
The values $\lambda \in [0.1, 0.4]$ gave roughly the best performance.

\subsection{Merging Features} \label{ssec:merging}
As a counterpart to the feature adding is the process of \textit{merging} the features, because only adding would lead to redundant features and overfitting.
Feature merging is done in two steps:
\begin{itemize}
    \item select a pair of candidate features to be merged, $\mathcal{M} = \{m_1, m_2\} \subset \O$, whose cosine distance $d(\textbf{W}_{m_1}, \textbf{W}_{m_2})$ is minimal, and replace $f_\O$ by $f_\O \setminus \mathcal{M}$
    \item add a new feature mapping $f_\N$ that \textit{replaces} the merged features, while initializing it as a weighted average of the selected two for faster convergence:
\end{itemize}
\begin{equation}
    \theta_\N = \frac{\sum_{\mathbf{x} \in B} P(h_{m_1}|\mathbf{x};\theta_{m_1})\theta_{m_1} + P(h_{m_1}|\mathbf{x};\theta_{m_2})\theta_{m_2}}
    {\sum_{\mathbf{x} \in B} P(h_{m_1}|\mathbf{x};\theta_{m_1}) + P(h_{m_1}|\mathbf{x};\theta_{m_2})}
\end{equation}

\subsection{Selecting $\Delta N$ and $\Delta M$}
Some kind of metric must be used to control the number of features being merged ($2\Delta M$) and added ($\Delta N$). A combination of AIC and BIC was used by authors, however the performance was fairly robust to the choice of update rule for $\Delta N$ and $\Delta M$.

\section{Principles of modularization}
Individual hidden units are treated as modules $-$ they are being manipulated (added and merged), however this does not allow for any kind of modular-like design for multi-task setting.

\section{Principles of growing}
This kind of architecture is well capable of growing (and shrinking), as explained in \ref{ssec:adding} and \ref{ssec:merging}, however it only increases or decreases the model's complexity (and allows to adapt faster to e.g. changing distribution of the dataset during online training).

\end{document}


\section{MCSImporter}
\label{MCSimporterPP}

The \textbf{MCSImporter} post-processor has been designed to import Minimal Cut Sets (MCSs) into RAVEN.
This post-processor reads a csv file which contain the list of MCSs and it save this list as a DataObject
(i.e.,  a PointSet).
The csv file is composed by three columns; the first contains the ID number of the MCS, the second one contains
the MCS probability value, the third one lists all the Basic Events contained in the MCS.
An example of csv file is shown in Table~\ref{MCScsv}.

\begin{table}[h]
    \centering
    \caption{Example of csv file which contains four MCSs.}
    \label{MCScsv}
	\begin{tabular}{c  c  c}
		\hline
		ID, & Prob, & MCS, \\
		\hline
		1.,  &  1.8E-2, &  D  \\
		2.,  &  4.0E-3, &  B \\
		3.,  &  3.0E-4, &  A,C  \\
		4.,  &  2.1E-5, &  E,C \\
		\hline
	\end{tabular}
\end{table}

The PointSet is structured to include all Basic Event, the MCS ID, the MCS probability, and the outcome of such MCS
(always set to 1).
MCS ID and MCS probability are copied directly from the csv file.
For each MCS, the Basic Events can have two possible values:
  \begin{itemize}
    \item  0: Basic Event is not included in the MCS
    \item  1: Basic Event is included in the MCS
  \end{itemize}
The PointSet generated from the csv file of Table~\ref{MCScsv} is shown in Table~\ref{PointSetMCSExpandFalse}.
\begin{table}[h]
    \centering
    \caption{PointSet generated by RAVEN for the list of MCSs shown in Table~\ref{MCScsv}.}
    \label{PointSetMCSExpandFalse}
	\begin{tabular}{c | c | c | c | c | c | c | c }
		\hline
		A & B & C & D & E & MCS\_ID & probability & out \\
		\hline
		0 & 0 & 0 & 1 & 0 & 1 & 1.8E-2 & 1 \\
		0 & 1 & 0 & 0 & 0 & 2 & 4.0E-3 & 1 \\
		1 & 0 & 1 & 0 & 0 & 3 & 3.0E-4 & 1 \\
		0 & 0 & 1 & 0 & 1 & 4 & 4.0E-3 & 1 \\
		\hline
	\end{tabular}
\end{table}

%
\ppType{MCSImporter}{MCSImporter}
%
\begin{itemize}
  \item  \xmlNode{expand},\xmlDesc{bool, required parameter}, expand the set of Basic Events by including all PRA Basic Events
  and not only the once listed in the MCSs
  \item  \xmlNode{BElistColumn},\xmlDesc{string, optional parameter}, if expand is set to True, then this node contains the
  column of the csv file which contains all the PRA Basic Events
\end{itemize}

\textbf{Example:}
\begin{lstlisting}[style=XML,morekeywords={anAttribute},caption=MCS Importer input example (no expand)., label=lst:MCS_PP_InputExample]
  <Files>
    <Input name="MCSlistFile" type="MCSlist">MCSlist.csv</Input>
  </Files>

  <Models>
    <PostProcessor name="MCSImporter" subType="SR2ML.MCSImporter">
      <expand>False</expand>
    </PostProcessor>
  </Models>

  <Steps>
    <PostProcess name="import">
      <Input   class="Files"        type="MCSlist"         >MCSlistFile</Input>
      <Model   class="Models"       type="PostProcessor"   >MCSImporter</Model>
      <Output  class="DataObjects"  type="PointSet"        >MCS_PS</Output>
    </PostProcess>
  </Steps>

  <DataObjects>
    <PointSet name="MCS_PS">
      <Input>A,B,C,D,E</Input>
      <Output>MCS_ID,probability,out</Output>
    </PointSet>
  </DataObjects>
\end{lstlisting}

\textbf{Example:}
\begin{lstlisting}[style=XML,morekeywords={anAttribute},caption=MCS Importer input example (expanded)., label=lst:MCS_PP_InputExample]
  <Files>
    <Input name="MCSlistFile" type="MCSlist">MCSlist.csv</Input>
    <Input name="BElistFile"  type="BElist" >BElist.csv</Input>
  </Files>

  <Models>
    <PostProcessor name="MCSImporter" subType="SR2ML.MCSImporter">
      <expand>False</expand>
    </PostProcessor>
  </Models>

  <Steps>
    <PostProcess name="import">
      <Input   class="Files"        type="MCSlist"         >MCSlistFile</Input>
      <Input   class="Files"        type="BElist"          >BElistFile</Input>
      <Model   class="Models"       type="PostProcessor"   >MCSimporter</Model>
      <Output  class="DataObjects"  type="PointSet"        >MCS_PS</Output>
    </PostProcess>
  </Steps>

  <DataObjects>
    <PointSet name="MCS_PS">
      <Input>A,B,C,D,E,F,G</Input>
      <Output>MCS_ID,probability,out</Output>
    </PointSet>
  </DataObjects>
\end{lstlisting}


\subsection{LOWESS}


\documentclass[Physics.tex]{subfiles}
\begin{document}
\chapter{Motion in a Circle}
\sldef{Angular displacement} is the angle in radians through which a body is rotated about an axis. \begin{equation}\mathbf{\theta} = \frac{s}{r}\end{equation} One \sldef{radian} is the angle subtended at the centre of a circle by an arc that is equal in length to the radius of the circle.

\sldef{Angular velocity} is the rate of change of angular displacement w.r.t. time. \begin{equation}\mathbf{\omega} = \sldd{\mathbf{\theta}}{t}\end{equation}

The \sldef{period} of an object in circular motion is the time taken for the object to make one complete revolution, and the frequency of an object in circular motion is the number of complete revolutions made by the object per unit time. \begin{align}T &= f^{-1} = \frac{2\pi}{\omega}\\f &= T^{-1} = \frac{\omega}{2\pi}\end{align}

The \sldef{linear velocity} of an object moving in a non-linear path is tangential to the object's path. \begin{equation}\mathbf{v} = \mathbf{r} \times \mathbf{\omega}\end{equation}

An object in \sldef{uniform circular motion} has constant angular velocity and a constant linear speed.

The \sldef{centripetal acceleration} (acceleration in the direction of the centre of motion) is \begin{equation}\mathbf{a}_c = \frac{\mathbf{v}^2}{\mathbf{r}} = \mathbf{r\omega}^2\end{equation} For the centripetal acceleration to exist, the net force must be in that direction. A net force in the direction of the centre of motion is known as a centripetal force. \begin{equation}\mathbf{F}_c = m\frac{\mathbf{v}^2}{\mathbf{r}} = m\mathbf{r\omega}^2\end{equation} In some cases, friction can be the force providing for the centripetal force.
\end{document}


\section{Conclusion}

Our implementation demonstrates how HMMs can be parallelized in a graph-parallel framework.  We view this project is a success, because it provides a strong foundational implementation for others to parallelize this nontrivial machine learning algorithm---in a framework that's gaining traction fast.   We intend to share our work with Dato, for example, since they already provide GraphLab users with a host of other machine learning algorithms and preprocessing routines, but not HMM representation / training.  Even though our graph-parallel approach is slower than
our serial approach, we show that it achieves better scaling than the serial
approach in limited certain cases. We conjecture that the difference in runtime relates to GraphLab's communication cost.  We also believe that GraphLab's immutable graph data structure, $\tt{SGraph}$ may be slow to manipulate and may be copied often.  Finally, we  believe that on some $\tt{triple\_apply}$ calls, the core code may be unnecessarily locking the vertex data, since the locking is performed even when vertex data is not mutated, but simply read.   We have suggested this optimization to the Dato team and they have endorsed this suggestion as an area for future improvement in their product, encouraging us to submit a pull request to their open source core code.  All put together, we are very optimistic about the work we have done and enjoyed getting our feet wet with a framework that we were previously less-than-comfortable with.
\section*{Acknowledgement}

The authors like to thank the teaching staff of CS 205, as well as Jay Gu and
Srikrishna Sridhar from Dato, for their tips and helpful advice.


\section{Type checking and other semantic analyses}
\subsection*{Type checking}
Assigning a type t to a variable x is, in essence, an invariant. Because languages are turing complete undecidable. Conservative if static, applies inference rules to deduce types of expression (without caring about reachability). We can use implicit casting if we have expressions of the type 4 + 1.0. The hierarchy is saved in memory.\\
\textbf{Typechecker:} Verify the validity of the expression given the types of the descendants. Derive the type of parent expressions (propagation). Via bottom-up traversal of the AST using the symbol table. Statements have no type, so they start the recursive traversal of their
\subsection*{General reachability}
Undecidable, halting problem. Conservative approach. Focus list of statements, reachable and terminate normally, ie control flow "falls through".\\
\textbf{Algorithm:} Consider a statement list S = s 1 , . . . , s n ;
1. If S is reachable then s 1 is reachable. 2. If s n terminates abnormally then so does S. 3. If S is the body of a function or procedure then S is reachable. 4. Local variable declarations, assignments, function calls, memory allocation, increment, decrement instructions all terminate normally. 5. A null statement or statement list does not generate error messages if it is not reachable. However, they propagate their non-reachability status to their successors. 6. If a statement has a predecessor then it is reachable if its predecessor terminates normally. For reachability analysis we assume the conditioncan be both true and false. \textit{while loop} If it evaluates constant true -> the while-statement is marked as abnormally terminating — since it is an infinite loop. false -> unreachable; If body contains break then normal terminating (when was abnormal). If body terminates normally, then the while statement terminates normally (unless infite with no break).


\section{Range Maximum Query}

\subsection{Range Maximum Query}
\begin{frame}
    \frametitle{Range Maximum Query}
    \begin{itemize}
    	\setlength\itemsep{1em}
    	\item
    		The suffix maximum query is a special case of the range
			maximum query.
		\item
			In this section, we will describe our approach to address
			the challenges in the {\em second} stage of
			Algorithm~\ref{alg:parallel-VGLCS}.
    \end{itemize}
\end{frame}

\subsection{Blocked Range Maximum Query}
\begin{frame}
    \frametitle{Blocked Range Maximum Query}
	%We improve the efficiency of our parallel VGLCS algorithm with a
	%{\em blocked} sparse table proposed by Fischer.
	Fischer proposed {\em blocked} sparse table as follows:
	\begin{enumerate}
		\setlength\itemsep{1em}
		\item
			Partitions the data into blocks of size $s$, then
		\item
			Computes the maximum of each block, then
		\item
			Compute a sparse table $T_s$ for these maximums.
	\end{enumerate}
	\vspace{1em}
	It answers a range maximum query as two types of queries
	\begin{itemize}
		\setlength\itemsep{1em}
		\item
			{\em super block} query
		\item
			{\em in-block} query.
	\end{itemize}
\end{frame}

\begin{withoutheadline}
\begin{frame}
    \frametitle{An Super Block Query Example}
	\begin{figure}[!thb]
		\centering \subfigure[Array] {
	    	\includegraphics[width=0.85\linewidth]{\GraphicPath/fig-interval-decomposition.pdf}
	  	} \subfigure[Blocked sparse table] {
	    	\includegraphics[width=0.4\linewidth]{\GraphicPath/fig-sparse-table.pdf}
	  	}
	  	\caption{A Sparse Table}
	  	\label{fig:block-interval-decomposition}
	\end{figure}
\end{frame}
\end{withoutheadline}

\begin{frame}
	\frametitle{Answer In-Block Query with Least Common Ancestor}
	\begin{itemize}
		\setlength\itemsep{1em}
		\item
			Fischer's algorithm scans through the data within a block
			and places them into a {\em Cartesian tree}.
		\item
			Cartesian tree as a {\em heap} where the data are in heap
			order, and the indexes of the data are in {\em sorted binary
			search tree order}.
		\item
			As a result, the answer to an in-block range maximum query
			from the $i$-th to the $j$-th element of a block is located
			at their {\em least common ancestor} in the Cartesian tree.
	\end{itemize}
\end{frame}

\begin{withoutheadline}
\begin{frame}
	\frametitle{An In-Block Query Example}
	\begin{figure}[htbp]
	  \centering
	  \includegraphics[width=\linewidth]{\GraphicPath/fig-interval-cartesian.pdf}
	  \caption{Least common ancestor tables}
	  \label{fig:ancesstor-cartesian}
	\end{figure}
\end{frame}
\end{withoutheadline}

\begin{frame}
	\frametitle{Fischer's Build Least Common Ancestor Table}
	Fischer's algorithm chooses block size $s=\frac{\log n}{4}$.
	\begin{itemize}
		\setlength\itemsep{1em}
		\item
			Catalan number ${\cal C}_s$ is the number of different Cartesian
			trees, and also is the number of different binary trees of
			$s$ nodes.
		\item
			Space requirement is
			$O(s^2{\cal C}_s)=O(s^2\frac{1}{s+1}\binom{2s}{s})=O(n)$
		\item
			Construct LCA tables for blocks {\em on-demand}.
	\end{itemize}
\end{frame}

\begin{withoutheadline}
\begin{frame}
	\frametitle{Illustration for Constructing On-demand}
	\begin{figure}[htbp]
	  \centering
	  \includegraphics[width=0.9\linewidth]{\GraphicPath/fig-fischer-ondemand.pdf}
	  \caption{Construct LCA table for blocks on-demand}
	\end{figure}
\end{frame}
\end{withoutheadline}

\begin{frame}
	\frametitle{The Least Common Ancestor Table in Parallel VGLCS}
	There are two performance issues:
	\begin{itemize}
		\setlength\itemsep{1em}
		\item
			Building process repeats for as many times as the number of
			blocks, and may cause serious cache misses.
		\item
			The LCA table will be cached and this may {\em evict} other
			LCA tables from cache.
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{The Static Least Common Ancestor Table}
	Demaine's algorithm does not check if an LCA table is in memory --
	instead it builds LCA table for {\em every possible} block.
	\begin{itemize}
		\setlength\itemsep{1em}
		\item
			Use a binary string of length $2s$ to identify a block and
			its Cartesian tree.
		\item
			The binary string is encoded in such a way that one can
			answer an in-block query by examining this binary string.
	\end{itemize}
\end{frame}

\begin{frame}
	There are two issues on examining this binary string:
	\begin{itemize}
		\setlength\itemsep{1em}
		\item
			This requires counting the number of 1's {\em between} the
			last two 0's, which is {\em hard} to implement efficiently
			in a modern computer.
		\item
			Converting binary string to LCA table must be processed
			sequentially, and also is the overhead of RMQ.
	\end{itemize}
\end{frame}

\subsection{Rightmost-pops Encoding}
\begin{frame}
    \frametitle{Rightmost-pops Encoding}
    We propose a new encoding for blocks, called {\em rightmost-pops},
	instead of the binary string by Demaine, in order to improve the
	performance of range maximum query.
	\\~\\
	When we add the $i$-th data $a_i$ into the Cartesian tree,
	\begin{itemize}
		\setlength\itemsep{1em}
		\item
			Keep popping data until the top of stack is no less than
			$a_i$.
		\item
			$t_i$ be the number of nodes that need to be popped.
		\item
			$0 \le t_i < s$, where $s$ is the block size.
	\end{itemize}

\end{frame}

\begin{withoutheadline}
\begin{frame}
	\frametitle{A Rightmost-pops Encoding Example}
	\begin{figure}[!thb]
	  \centering
	  \includegraphics[width=\linewidth]{\GraphicPath/fig-cartesian-encoding-stack.pdf}
	  \caption{Rightmost path in stack}
	  \label{fig:interval-cartesian}
	\end{figure}
\end{frame}
\end{withoutheadline}

\begin{frame}
	\frametitle{Implementation of Rightmost-pops Encoding}
	We choose the block size $s = {{\frac{\log n}{4}}} = 16$.

	\begin{itemize}
		\setlength\itemsep{1em}
		\item
			All $t_i$'s are small than 16.
		\item
			Represent each of $t_i$ as a 4-bit integer.
		\item
			Concatenate sixteen of these 4-bit integers into a 64-bit
			integer to present a Cartesian tree for a block.
	\end{itemize}
	\vspace{1em}
	It can answer range maximum query for up to $n = 2^{64}$ data.  The
	time complexity of our parallel VGLCS algorithm becomes $O(n^2
	\log{n} / p + n \log n)$.
\end{frame}

\begin{frame}
	\frametitle{Pseudocode for Rightmost-pops Encoding}
	\begin{center}
		\scalebox{1} { \begin{minipage}{1\textwidth}
			\input{\AlgoPath/alg-cartesian64bits-query-2e}
			\end{minipage}
		}
	\end{center}
\end{frame}


% !Mode:: "TeX:UTF-8"

\chapter{Efficient determination of disparity map from
stereo images with modified Sum of Absolute
Differences (SAD) algorithm}

\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Dang Khanh Hoa, Le Dung, Nguyen Tien Dzung

\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .\\

This paper proposes modification of the
conventional Sum of Absolute Differences (SAD) for performance
improvement in depth-map estimation from stereo images
captured by a camera in a stereo system. The conventional SAD
is commonly search in whole stereo images to find out the
difference in pixels between the left and right captured images,
and then obtains the corresponding disparity map and this may
lead to high elapsing time. In order to reduce the number of
searching pixels, the proposed modified SAD tries to estimate the
difference only from edge pixels which are referred as pixels-ofinterest
and bring significant information about depth map. The
number of pixels being searched is reduced to about 17\% on the
total pixels, hence the total elapsing time is saved up to around
89\% compared to that of the conventional SAD. This results is
promising for implementation of a real-time vision system.

Stereo matching is a problem to find correspondences
between two input images,. It is one of fundamental
computer vision problems with a wide range of applications,
and hence it has been extensively studied in the computer
vision field for many recent years . Stereo matching consists to
find for each point in the left image, its corresponding in the
right one. The difference between horizontal distances of these
points is the disparity. A disparity map consists of all the
possible disparity values in an image. Such a map is basically
a representation of the depth of the perceived scene. Therefore,
the disparity maps have been used to address efficiently
problems such as 3D reconstruction, positioning, mobile robot
navigation, obstacle avoidance and many other domains.

There are three broad classes of techniques, which have
been used for stereo matching: area-based, featurebased, and phase-based. SAD-based implementations
are the most favorable area-based techniques in real-time
stereo vision, since they can be straightforwardly implemented
in hardware. The calculations required in terms of design units
are simple, since only summations and absolute values are
performed. Parallel design units can be utilized in order to
handle various disparity ranges, in order to reduce the
computational time required. SAD correlation algorithm
can be applied to solve the problem automatically detect mold
applications in robot control and mapping. The research
results show that the SAD correlation algorithm can be a
potential replacement for SIFT method proposed by Lowe in the landmark selection problem. The purpose of the
SIFT method is quoted as a full-featured constant rate,
rotate, move but criticized the selection of stable
characteristics proved more effective when reproducing 3D or
service of navigation.

Typically, the disparity is computed as a shift to the left of
an image feature when it is viewed in the right image, it is
calculated by determining a measure of the SAD, that is used
to calculate disparities at each pixel in the right image.
After this SAD “match strength” has been computed for all
valid disparities, the disparity that yields the lowest SAD is
determined to be the disparity at that location in the right
image. Hence, the computation of a disparity map is
performed on all pixels of stereo images so this approach may
be influenced by an object's position and large elapsing time to
determine the corresponding points between the two images,
especially for huge size of captured images or frames.
In this paper, the proposed SAD algorithm tries to modify
the way of disparity determination by utilization of edge
information extracted from the captured stereo images. Since
edges operators used in the proposed method require fewer
computational load, the disparity map can be represented with
low elapsing time while maintaining reasonable quality of the
map reconfiguration.

The rest of this paper is organized as follows: Section 2
describes modifications in the proposed SAD method to
determine a disparity map. In Section 3, experimental results
obtained on real images are presented and discussed. Finally,
Section 4 concludes the paper with some remarks and future
works.