\documentclass[11pt]{article}
\usepackage{amsmath,amsfonts,amssymb,algorithm,algpseudocode}
\usepackage{graphicx,tikz,setspace}
\usepackage[hidelinks]{hyperref}
\usepackage[mathscr]{euscript}
\usepackage[top=1in, left=1.5in, right=1.5in, bottom=1in]{geometry}

\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
\setstretch{1.5}

\title{Practicum in Artificial Intelligence:\\ Optical Character Recognition via Neural Networks}
\date{December 12, 2012}
\author{Bryan Cuccioli (\texttt{blc72@cornell.edu}), Mathematics \& Computer Science, 2014\\
\and
Renato Amez (\texttt{ra374@cornell.edu}), Electrical \& Computer Engineering, 2014}

\usetikzlibrary{calc,positioning,arrows,chains,decorations.pathreplacing,matrix}

\tikzset{
>=stealth',
  punktchain/.style={
    rectangle,
    rounded corners,
    fill=black!5,
    draw=black, very thick,
    text width=9em,
    minimum height=3em,
    text centered,
    on chain},
  line/.style={draw, thick, <-},
  element/.style={tape, text centered, on chain},
  every join/.style={->, thick,shorten >=1pt},
  decoration={brace},
  tuborg/.style={decorate},
  tubnode/.style={midway, right=2pt},
}

\begin{document}

\maketitle
\tableofcontents
\pagebreak

\section{Abstract}

\emph{
We propose to design and train a feed-forward, multilayer neural network with back-propagation to perform optical character recognition. We give a formal definition of the problem of optical character recognition, and then exhibit the design and topology of such a neural network. We present experimental results relating several construction parameters, such as number of hidden layers, response threshold, and learning rate, independently to the output of our neural network.
}

\section{Introduction}
Optical character recognition (OCR) is an important problem in computer vision, with applications ranging from efficiently scanning books to recognizing cheques in an ATM. We aim to give a simple solution to the problem of OCR via training a neural network. In particular, we approximately model the human brain as a weighted directed graph and use training samples to tune the weights, enabling the network to compute the character corresponding to the representation in an image. This gives a relatively simple version of a general purpose \emph{linear classifier}, more sophisticated versions of which are used in industry to perform OCR.

We exhibit the design and structure of such a network, and experimentally determine parameters of its construction that give optimal results.

\subsection{Formal Description}

We will now give a more precise definition of the problem of optical character recognition. Each image in our input set is of size $N\times N$, consisting of pixel values in $\{0,\dots,M\}$, and represents a digit between 0 and 9. That is, each image is a vector in the $N\times N$-dimensional vector space $\mathscr{V}$ taken over the Galois field $\mathbf{F}=\mathrm{GF}(M+1)$. We aim to construct a function
\begin{equation}\varphi:\mathscr{V}\xrightarrow{\ \ \ } \{0,1,\dots,9\}\end{equation}
that assigns to each image $v\in\mathscr{V}$ an output $n\in \{0,1,\dots,9\}$, such that the output corresponds to the digit represented in the image.

\section{Method}

Our method for solving this problem is to create a multi-layer feed-forward neural network trained with back-propagation. A \emph{neural network} is a directed weighted graph $G=(V,E)$ such that the set of \emph{neurons} $V$ is partitioned into a set of \emph{layers} $\{L_1,\dots,L_n\}$, with $n\geq 2$. The layer $L_1$ is called the \emph{input layer}, and $L_n$ the \emph{output layer}; the remaining layers are \emph{hidden layers}, and all have the same cardinality. For each $i=1,\dots,n-1$, we form the edge set between layers
\[E_i=\{(u,v) : u\in L_i\mathrm{\ and\ } v\in L_{i+1}\}\]
so that our neural network has edges
\begin{equation}E=\bigcup_{i=1}^{n-1} E_i.\end{equation}
We also add to each layer a \emph{bias node}, and create an edge from this node to every neuron in the layer.

For example, Figure \ref{nn} shows a simple neural network with two hidden layers, each containing five neurons, an input layer containing four neurons, and an output layer containing three neurons, with no bias node.

\def\layersep{2.5cm}

\vspace{1cm}
\begin{figure}[h]
\centering
\begin{tikzpicture}[shorten >=1pt,->,draw=black!50, node distance=\layersep]
    \tikzstyle{every pin edge}=[<-,shorten <=1pt]
    \tikzstyle{neuron}=[circle,fill=black,minimum size=6pt,inner sep=0pt]
    \tikzstyle{input neuron}=[neuron];
    \tikzstyle{output neuron}=[neuron];
    \tikzstyle{hidden neuron}=[neuron];
    \tikzstyle{annot} = [text width=4em, text centered]

    % Draw the input layer nodes
    \foreach \name / \y in {1,...,4}
        \node[input neuron, pin=left:Input \#\y] (I-\name) at (0,-\y) {};

    % Draw the hidden layer nodes
    \foreach \name / \y in {1,...,5}
        \path[yshift=.5cm]
            node[hidden neuron] (H1-\name) at (\layersep,-\y cm) {};
    \foreach \name / \y in {1,...,5}
        \path[yshift=.5cm]
            node[hidden neuron] (H2-\name) at (5cm,-\y cm) {};

    % Draw the output layer nodes
    \node[output neuron,pin={[pin edge={->}]right:Output}, right of=H2-2] (O1) {};
    \node[output neuron,pin={[pin edge={->}]right:Output}, right of=H2-3] (O2) {};
    \node[output neuron,pin={[pin edge={->}]right:Output}, right of=H2-4] (O3) {};

    % Connect every node in the input layer with every node in the
    % hidden layer.
    \foreach \source in {1,...,4}
        \foreach \dest in {1,...,5}
            \path (I-\source) edge (H1-\dest);

    % Connect every node between the hidden layers
    \foreach \source in {1,...,5}
        \foreach \dest in {1,...,5}
            \path (H1-\source) edge (H2-\dest);

    % Connect every node in the hidden layer with the output layer
    \foreach \dest in {1,...,3}
        \foreach \source in {1,...,5}
            \path (H2-\source) edge (O\dest);

    % Annotate the layers
    \node[annot,above of=H1-1, node distance=1cm] (hl) {Hidden layer};
    \node[annot,above of=H2-1, node distance=1cm] (hl2) {Hidden layer};
    \node[annot,left of=hl] {Input layer};
    \node[annot,right of=hl2] {Output layer};
\end{tikzpicture}
\caption{Topology of a simple neural network} \label{nn}
\end{figure}
\vspace{1cm}

We begin by initializing each edge weight to a random value in the interval $[-10,10]$. We then \emph{feed forward} each input in the neural network to compute the output. This is done by computing for each neuron the weighted sum of its inputs, and then passing to the \emph{sigmoid function} $\sigma:\mathbb{R}\xrightarrow{\ \ \ \ } \mathbb{R}_{\geq 0}$ given by
\begin{equation}\sigma(x) = \frac{1}{1+e^{-x/a}},\end{equation}
where $a$ is the \emph{activation threshold}. The function $\sigma$ approximates an activation threshold to the perceptron, and has the advantage of being differentiable, which is necessary for the back-propagation step.

For each $i=2,\dots,n$ in sequence, we compute for each neuron $j$
\begin{equation}b_j = \sum_{k=1}^m w_{k,j} a_k, \mathrm{\ \ \ } a_j=\sigma(b_j),\end{equation}
where $m$ is the number of neurons in each hidden layer, $w_{k,j}$ is the weight of the edge $(k,j)$, and the $a_k$ are initialized in the input layer to the values of the inputs. This is exhibited fully in Algorithm 1.

\begin{algorithm}
\caption{Feed forward}
\begin{algorithmic}[1]
\Function{FeedForward}{input $(x_1,x_2,\dots,x_r)$}
\For{node $i$ in the input layer}
  \State $a_i \gets x_i$
\EndFor
\For{$\ell=2,...,n$}
  \For{node $j$ in layer $\ell$}
    \State $b_j\gets \sum_i w_{i,j} a_i$
    \State $a_j \gets \sigma(b_j)$
  \EndFor
\EndFor
\State \Return set of neurons in $L_n$
\EndFunction
\end{algorithmic}
\end{algorithm}

To facilitate learning in the neural network, it is necessary to update the edge weights after computing the output based on whether the output was correct. The process by which this is accomplished is called \emph{back-propagation}. At a high level, the idea behind the back-propagation algorithm is that we can update the weights in the edges of $E_{n-1}$ in order to minimize the \emph{loss}, a heuristic designed to measure the distance between the output and the desired output. This gives the desired activation values for the neurons of layer $L_{n-1}$, so we update the weights of edges in $E_{n-2}$ similarly, and recurse until the input layer is reached.

We will derive and analyze a method for computing the updated weights. Suppose that $\mathbf{a}=(a_1,\dots,a_s)$ is the input vector, and $\mathbf{y}=(y_1,\dots,y_r)$ is the desired output. Let $f$ be the function that implements the neural network, i.e. the function that takes in the input vector and weight vector $\mathbf{w}$ consisting of all of the weights in the network, and returns the output layer $f(\mathbf{a},\mathbf{w})$. Define the ``loss function'' $\mathscr{L}$ as
\begin{align}\mathscr{L}(\mathbf{a})&=\sum_{i=1}^r (y_i - f(a_i,\mathbf{w}))^2\notag\\
&=\sum_{i=1}^r \mathscr{L}_i(\mathbf{a}).\end{align}

We implement back-propagation as a form of hill-climbing search, following the gradient of the loss function in order to arrive at a local minimum. We begin by defining for each node $j$ in the output layer
\begin{equation}\Delta_j = \sigma'(b_j) \cdot (y_j-a_j).\end{equation}
Then observe that at the output layer, we can compute the gradient of $\mathscr{L}_k$ as
\begin{align}\pd{\mathscr{L}_k}{w_{j,k}} &= -2(y_k-a_k)\pd{a_k}{w_{j,k}}\notag\\
&=-2(y_k-a_k)\pd{\sigma(b_k)}{w_{j,k}}\notag\\
&=-2(y_k-a_k)\sigma'(b_k)\pd{b_k}{w_{j,k}}\notag\\
&=-2(y_k-a_k)\sigma'(b_k)\pd{}{w_{j,k}} \left(\sum_{j} w_{j,k} a_j\right)\notag\\
&=-2(y_k-a_k)\sigma'(b_k)a_j\notag\\&=-a_j \Delta_k.\end{align}
The gradients with respect to the weights in layers upstream from the output layer can now be computed. For each $i=n-1,\dots,1$, we define for each neuron $j\in L_i$,
\begin{equation}\Delta_j = \sigma'(a_j) \sum_{k\in L_{i+1}} w_{j,k} \Delta_k,\end{equation}
so that
\begin{align}\pd{\mathscr{L}_k}{w_{i,j}} &= -2(y_k-a_k)\pd{a_k}{w_{i,j}}\notag\\
&=-2(y_k-a_k)\pd{\sigma(b_k)}{w_{i,j}}\notag\\
&=-2(y_k-a_k)\sigma'(b_k)\pd{b_k}{w_{i,j}}\notag\\
&=-2\Delta_k \pd{}{w_{i,j}} \left(\sum_j w_{j,k} a_j\right)\notag\\
&=-2\Delta_k w_{j,k} \pd{a_j}{w_{i,j}}\notag\\
&=-2\Delta_k w_{j,k} \sigma'(b_j) \pd{b_j}{w_{i,j}}\notag\\
&=-2\Delta_k w_{j,k} \sigma'(b_j) \pd{}{w_{i,j}}\left(\sum_i w_{i,j} a_i\right)\notag\\
&=-2\Delta_k w_{j,k} \sigma'(b_j) a_i\notag\\
&=-a_i \Delta_j.\end{align}
Hence it remains to update each edge weight by adding the gradient of the loss function at that weight, multiplied by some pre-defined \emph{learning rate} $\lambda$. The full back-propagation algorithm is shown in Algorithm 2.

\begin{algorithm}
\caption{Back-propagate}
\begin{algorithmic}[1]
\Function{BackPropagate}{output $\mathbf{a}$, correct output $\mathbf{y}$}
\For{node $j$ in the output layer}
  \State $\Delta_j \gets \sigma'(b_j)\cdot (y_j-a_j)$
\EndFor
\For{$\ell=n-1,\dots,1$}
  \For{node $i$ in layer $\ell$}
    \State $\Delta_i\gets \sigma'(b_i) \sum_{j\in L_{\ell+1}} w_{i,j}\Delta_j$
  \EndFor
\EndFor
\For{weight $w_{i,j}$ in network}
  \State $w_{i,j}\gets w_{i,j} + \lambda\times a_i\times \Delta_j$
\EndFor
\EndFunction
\end{algorithmic}
\end{algorithm}

At the top level, we use $t$ training examples per digit, computing the output through the neural network in each and then back-propagating in turn to update the weights. Each image is first resized from $28\times 28$ to $6\times 6$, and is then converted from grayscale to black and white using Otsu thresholding. This serves to reduce the dimensionality of the input, so that the input set can be fit more accurately to the weights. We construct a neural network with $6\times 6$ neurons in the input layer, each corresponding to a pixel in the image, and 10 neurons in the output layer, each corresponding to a possible output $0,1,\dots,9$, with activation values $a_i$ representing the network's confidence that $i$ is the correct output.

We then execute the training algorithm shown in Algorithm 3.

\begin{algorithm}
\caption{Train}
\begin{algorithmic}[1]
\Function{Train}{training set $S$}
\For{weight $w_{i,j}$ in $\mathbf{w}$}
  \State $w_{i,j} \gets \mathrm{\ small\ random\ value}$
\EndFor
\For{image $s\in S$}
  \State $s\gets \mathrm{resize}(s)$
  \State $f(\mathbf{s},\mathbf{w})\gets \mathrm{FeedForward}(\mathbf{s})$
  \State BackPropagate($f(\mathbf{s},\mathbf{w})$, desired output)
\EndFor
\EndFunction
\end{algorithmic}
\end{algorithm}

The \emph{success} of the neural network is measured by running the above algorithm on some distinct set of $T$ images without the BackPropagate stage and counting for how many images the correct value was output.

\section{System Architecture}

The implementation of the system is divided among four main classes. Although an approach not based on object-oriented programming using only a three-dimensional array to store weights and activation values is possible, the structure of a neural network and modularization of the project lend themselves well to a class-based approach.

\begin{enumerate}
\item \texttt{ImageData}: This class is responsible for reading in images from the data set, resizing them, and thresholding them from grayscale to black and white. Image processing is done via the OpenCV \footnote{\url{http://opencv.org}} library.

\item \texttt{Neuron}: This class represents a single neuron in the network. Each neuron stores its activation value and the weights of its incoming edges. It handles the logic for randomly assigning values to these weights upon initialization as well as for computing the linear combination of its inputs.

\item \texttt{Layer}: This class represents a layer of the neural network. It stores an array of neurons belonging to this layer, and handles the logic for initializing each neuron.

\item \texttt{NeuralNet}: This class represents the neural network at the top level. It handles the logic for initializing each layer and implements the FeedForward and BackPropagate algorithms.
\end{enumerate}

\vspace{.5cm}
\begin{figure}[h]
\centering
\begin{tabular}{ccc}
\begin{tikzpicture}
  [node distance=.8cm, start chain=going above,]
  \node[punktchain, join] (neuron) {\texttt{Neuron}};
  \node[punktchain, join] (layer) {\texttt{Layer}};
  \node[punktchain, join] (neuralnet) {\texttt{NeuralNet}};
\end{tikzpicture}
& \hspace{.75cm} &
\begin{tikzpicture}
  [node distance=.8cm, start chain=going above,]
  \node[punktchain] (imagedata) {\texttt{ImageData}};
\end{tikzpicture}
\end{tabular}
\caption{Class structure} \label{classes}
\end{figure}
\vspace{.5cm}

Training and testing is done using Google's MNIST database \footnote{\url{http://yann.lecun.com/exdb/mnist/}}. As part of pre-processing, a simple C\# script\footnote{\url{https://gist.github.com/4056614}} was used to convert the glob of pixel values to 10,000 JPEG images suitable for processing.

\section{Experimental Evaluation}

\subsection{Methodology}

The interface to the program supports specifying several variables that we test in relation to the success of the network, including

\begin{itemize}
\item $t$: the number of training samples per digit;
\item $\ell$: the number of hidden layers in the network;
\item $h$: the number of neurons per hidden layer;
\item $b$: the weight of the bias;
\item $\lambda$: the learning rate of the network, as defined above;
\item $r$: the response threshold for the sigmoid function.
\end{itemize}
We vary each of these parameters independently over several discrete values, holding fixed the size of the test sample set $T=100$. Training and test data samples are taken from the MNIST database, a collection of 10,000 handwritten digits. Recognizing digits simplifies the problem of learning optical character recognition without loss of generality; it can easiy be extended to learning to recognize all handwritten characters.

\subsection{Results}

The hypothesis established before beginning the experimental trials was that increasing every one of the above parameters separately would increase the success rate of the neural network roughly linearly. Experimental trials show that each of the parameters affects the output in this way between some lower and upper bound.

We found that the learning rate $\lambda$ is one such parameters which increases the success up to some upper bound. We fix $\ell=1$, $h=45$, $t=800$, $r=55$, and $b=60$. With $\lambda=1$, we get $\mu=10.3\% \pm 1.1\%$. With $\lambda=10$, we get $\mu=27.0\% \pm 1.3\%$. With $\lambda=40$, we get $\mu=34.4\% \pm 1.4\%$. However, with $\lambda=50$, we get $\mu=27.2\% \pm 1.2\%$, and the results similarly decrease from there, indicating that the optimal value for $\lambda$ is approximately 40.

We found that having one hidden layer is optimal for our neural network. With $\lambda=40$ and the other parameters fixed as above, we find that with $\ell=0$, we get $\mu=12.3\% \pm 1.3\%$. With $\ell=1$, we get $\mu=34.4\% \pm 1.4\%$, as above. With $\ell=2$, we get $\mu=23.8\% \pm 1.6\%$, and with $\ell=3$, we get $\mu=12.7\% \pm 0.8\%$. This makes intuitive sense: having too few nodes available should make it hard for the network to generalize to the entire dataset, while having too many subjects the network to \emph{overfitting}.

By the same reasoning, we intuit that there will be some middle value for $h$ that is optimal. Experimental results confirm this: with $h=25$ we get $\mu=15.7\% \pm 0.7\%$; with $h=45$ we get $\mu=30.4\% \pm 1.2\%$; with $h=55$, we get $\mu=35.1\% \pm 1.4\%$, and the outputs stay approximately constant up through at least $h=100$ (fixing the optimal values above for the other parameters).

We found that the response threshold $r$ greatly influences the success of the neural network. Fix the other parameters as above, with $h=45$. With $r=25$, we get $\mu=15.2\% \pm 2.2\%$; with $r=35$, we get $\mu=23.8\%\pm 2.0\%$; with $r=55$ we get $\mu=31.8\% \pm 1.6\%$; with $r=65$ however we get $\mu=20.0\% \pm 1.9\%$. Intuitively, it makes sense that having a value for $r$ that is slightly too large or too low can drastically affect the outcome, as it skews the already steep slope of the sigmoid curve.

The bias element also has a weak effect on the outcome. Having a bias $b=0$ gives an output $\mu=27.6\% \pm 1.6\%$; having a bias $b=20$ gives an output $\mu=28\%\pm 1.4\%$; we see that optimally the bias $b=60$ gives an output of $\mu=32.1\% \pm 2.0\%$; however, having a bias $b=70$ causes the output to drop to $\mu=21.3\% \pm 1.7\%$.

Finally, we observe that the number of training examples $t$ used has a strong effect on the success of the network, with diminishing returns. Fixing the other parameters with the above-determined values, with $t=200$ gives output $\mu=17.1\% \pm 1.8\%$; using $t=400$ gives output $\mu=29.2\%\pm 1.9\%$; with $t=600$ we have $\mu=31.2\%\pm 2.3\%$; with $t=900$ we have output $\mu=29.8\% \pm 2.2\%$, approximately the same result as with $t=600$. It is expected that the success of the neural network should level off as $t\to\infty$, since many of the training examples are very similar and eventually the weights are changing by very small amounts.

\section{Future Work}

The major shortcoming with using a neural network is that it does not achieve a high rate of recognition. While recognition rates in the neighborhood of 35\% indicate that the model is at least somewhat successful, it is unable to adapt the weights to the resolution required for 90\% or greater recognition. It appears that the neural network model is not general or adaptable enough to perform OCR effectively.

There are a number of methods from computer vision that can be used to increase the efficacy of OCR. For example, many commercial OCR solutions use feature detection mechanisms such as computing the Laplacian of a Gaussian convolved with the image and then compare local features using e.g. scale-invariant feature transform (SIFT) to measure similarity between images$^3$. These methods could be incorporated into future versions of the project.

The neural network can also be adapted to a more robust detection mechanism. In particular, one could train a network to recognize for each $i\in \{0,\dots,9\}$ whether an input simply represents $i$ or not, and then apply all 10 neural networks to determine the digit in the image.

\section{Conclusion}

By constructing a multilayer feed-forward neural network and training it using back-propagation, we are able to implement a simple classifier that recognizes handwritten digits with a non-trivial success rate of approximately 35\%. Via experimentation, we determined that our neural network optimally has one hidden layer containing $h=45$ neurons, uses approximately $t=600$ training examples per digit, has a response threshold of $r=55$, a bias of $b=60$, and a learning rate of $\lambda=40$. These results make intuitive sense, as they achieve an optimal balance between under- and over-fitting the data.

While the neural network alone was able to achieve a success rate indicating that it is learning, it was not able to achieve a practically-applicable success rate alone. We posit that a neural network in combination with feature detection and extraction algorithms will perform significantly better.

\section{References}

\begin{enumerate}
\item \emph{``OpenCV''}. Visited December 12, 2012. $<$\url{http://opencv.org}$>$.

\item Cortes, LeCun. \emph{``The MNIST Database of Handwritten Digits''}.\\
Visited December 12, 2012. $<$\url{http://yann.lecun.com/exdb/mnist/}$>$.

\item Szeliski, Richard. \emph{Computer Vision: Algorithms and Applications.}\\ New York: SpringerLink, 2011.

\end{enumerate}

\section{Appendix: Code Tree}

\begin{itemize}
\item \texttt{main.cpp}: The main driver program, implements the top-level algorithm.

\item \texttt{Neuron.h}: Defines the \texttt{Neuron} class, contains logic for initializing a neuron and computing its activation.

\item \texttt{Layer.h}: Defines the \texttt{Layer} class, contains logic for initializing a layer of neurons.

\item \texttt{NeuralNet.h}: Defines an interface for the variables and methods of the \texttt{NeuralNet} class.

\item \texttt{NeuralNet.cpp}: Implements forward-feeding and back-propagation for the \texttt{NeuralNet} class.

\item \texttt{ImageData.h}: Defines an interface for the \texttt{ImageData} class, which handles processing of JPEG images into suitable pixel arrays.

\item \texttt{ImageData.cpp}: Implements the methods of the \texttt{ImageData} class.

\item \texttt{Makefile}: Build system used for compiling the project.
\end{itemize}

\end{document}


\documentclass[a4paper,10pt]{article}
\usepackage{amssymb, amsmath}
\DeclareMathOperator{\arcsinh}{arcsinh}
\DeclareMathOperator{\arccosh}{arccosh}
\DeclareMathOperator{\arctanh}{arctanh}
\usepackage[utf8]{inputenc} % this is needed for umlauts
\usepackage[ngerman]{babel} % this is needed for umlauts
\usepackage[T1]{fontenc}    % this is needed for correct output of umlauts in pdf
%layout
\usepackage[margin=2.5cm]{geometry}
\usepackage{parskip}
\usepackage{xcolor}
\usepackage{hyperref}

\pdfinfo{
   /Author (StackExchange and GitHub authors)
   /Title  (TikZ Cheat Sheet)
   /CreationDate (D:20120221095400)
   /Subject (TikZ)
   /Keywords (TikZ)
}

\newcommand{\myCode}[1]{\colorbox{gray!30}{#1}}

\begin{document}

\title{TikZ cheat sheet}
\author{StackExchange and GitHub authors}
\date{\today}

\section*{Command Templates}
\begin{itemize}
    \item Basic path: \myCode{\textbackslash drawing-command [options] path-specification;}
    \item Path specification: \myCode{(coordinate) path-component (coordinate);}
    \item Path Reusage  \myCode{postaction=\{<basic drawing commands> or <decorate>\}} When this option is given to any basic drawing commands below, the path is not immediately discarded and reused after the initial drawing command is finished. \\
            \myCode{preaction=\{<basic drawing commands> or <decorate>\}} When this option is given to any basic drawing commands below, the path is used once before the initial drawing command is executed.
\end{itemize}

\section*{Basic Drawing Commands}
\begin{itemize}
    \item \myCode{\textbackslash path}: constructs a path
\end{itemize}

All following commands are in fact short forms for \myCode{\textbackslash path} with one option or two:
\begin{itemize}
    \item \myCode{\textbackslash draw}: constructs and draws ("strokes") a path
    \item \myCode{\textbackslash fill}: constructs and fills a path
    \item \myCode{\textbackslash filldraw}: constructs, fills, and draws a path (in that order)
    \item \myCode{\textbackslash shade}: constructs and shades a path
    \item \myCode{\textbackslash shadedraw}: constructs, shades, and draws a path (in that order)
    \item \myCode{\textbackslash coordinate}: label a coordinate
    \item \myCode{\textbackslash node}: constructs a node
\end{itemize}

\section*{Coordinate Specifications}
\begin{itemize}
    \item \myCode{(<x>,<y>)}: specifies the coordinate as a multiple of the current x- and y-vector (default: 1cm right and 1cm upwards)
    \item \myCode{(<$\theta$>:<r>)} specifies a coordinate in polar form with \myCode{r} being the vector length and \myCode{$\theta$} being the angle in degrees
    \item \myCode{+<coordinate specification>}: specifies a coordinate relative to the previous position but does not save the current position
    \item \myCode{++<coordinate specification>}: specifies a coordinate relative to the previous position
\end{itemize}

\subsection*{Notes}
\begin{enumerate}
    \item Lengths can be with or without unit.  If with a unit they are taken literally, if without they are multiples of the current `x` or `y` vector (as appropriate).
    \item Relative coordinates are with respect to the last *saved* position.  Unless specified otherwise, the above all save their resultant position as the last saved position.
    \item When a relative coordinate is used in a bezier curve specification the behaviour is slightly different.  The second control point is taken relative to the final position of the curve, and the final point is taken relative to the initial one (or last saved position).
\end{enumerate}

\section*{Path Specifications}
\begin{itemize}
    \item \myCode{(coordinate) (coordinate)}: moves the "current point" from the first coordinate to the second
    \item \myCode{(coordinate) -- (coordinate)}: draws a line from the first coordinate to the second
    \item \myCode{(coordinate) .. controls (control) and (control) .. (coordinate)}: draws a cubic bezier from the first coordinate to the second with the specified control points
    \item \myCode{(coordinate) to[options] (coordinate)}: draws a `to path` from the first coordinate to the second; \myCode{to path}s can be extremely complicated
    \item \myCode{(coordinate) rectangle (coordinate)}: draws a rectangle with the coordinates as opposite corners
    \item \myCode{(coordinate) circle[options]}: draws a circle centred at the coordinate
    \item \myCode{(coordinate) arc[options]}: draws an arc starting at the coordinate
    \item \myCode{(coordinate) node[options] \{text\}}: adds a node at the coordinate
    \item \myCode{(coordinate) coordinate}: adds a coordinate label at the given coordinate
\end{itemize}

\section*{Basic Options}
\begin{itemize}
    \item \myCode{draw[=<colour specification>]}1: draw the current path (with the given colour)
    \item \myCode{fill[=<colour specification>]}1: fill the current path (with the given colour)
    \item \myCode{<colour specification>}: set the colour for draw, fill, text (without explicitly enforcing those actions)
    \item \myCode{line width=<dimen>}: sets the line width
    \item \myCode{thin, thick, ultra thick} \href{http://martin-thoma.com/sizes-in-latex/}{etc}: presets for the line width
\end{itemize}

[1] The brackets indicate an optional part and must not be type in the code. I.e. use \myCode{draw=red} and not \myCode{draw[=red]}.
\end{document}


\documentclass[11pt]{article}

\pagestyle{empty}                         %%%% No page Numbering

% Mathews packages....
\usepackage{amsbsy,amsmath,amssymb,psfig}
\usepackage{times,mathpi,mathptm}
\usepackage{graphicx,psfrag,rotating,subfigure}

\begin{document}
\section{Calculation of the sparsity pattern for Mixed formulation}

In the mesh migration problem, it is useful to use a first order
element-element adjancy matrix when a mixed formulation is being used
by the solver. To see why, consider
Figure~\ref{fig:mixedgraph}. Normally the yellow elements define the
mesh overlap, or halo, between two domains. In the case of a mixed
formulation, some field values are stored and solved on a more sparce
matrix pattern. For the mixed formulation considered here, all
elements adjacent to yellow elements, are also required on the
neighbouring domain. The elements of interest are coloured blue in
Figure~\ref{mixedgrapg}.

Define $\pmb{E}$ as the element-element adjancy matrix over all the
domains where
\begin{displaymath}
E_{ij} = \left\{ \begin{array}{ll}
1 & \textrm{if element $i$ shares nodes with element $j$ and $i \ne j$,}\\
0 & \textrm{otherwise}
\end{array} \right.
\end{displaymath}

\begin{figure}[h]\label{fig:mixedgraph}
\centering
\includegraphics[width=80mm]{images/mixed}
\caption{Yellow indicates elements in the halo between two domains
divided by the dashed line. The blue elements indicates the additional
elements that need to be communicated to the neighbouring domains in
the mixed formulation}
\end{figure}

Next we define $\pmb{D}_s$ is the element distribution across the domains
\begin{displaymath}
D_{s_i} = \left\{ \begin{array}{ll}
1 & \textrm{if element $i$ has nodes assigned to domain $s$,}\\
0 & \textrm{otherwise}
\end{array} \right.
\end{displaymath}
Thus, the yellow halo elements between domains $s$ and $r$ can be
defined by $pmb{H}_{sr} = \pmb{D}_s \otimes \pmb{D}_r$.

Finally, let us define $\pmb{B}_{sr}$ as the non-halo elements in
domain $s$, which have to be sent with some specific field values to
domain $r$;
\begin{equation}
B_{sr_i} = S( (H_{sr_i}\pmb{E}_i ).D_s )
\end{equation}

where the function $S$ is defined by
\begin{displaymath}
S(x) = \left\{ \begin{array}{ll}
1 & \textrm{for $x \ne 0$,}\\
0 & \textrm{otherwise}
\end{array} \right.
\end{displaymath}

\end{document}


\section{Surface Integral Flowchart}

\begin{figure}[H]
	\centering
	\hspace*{-1.5in}
	\includegraphics[width=\paperwidth]{Images/additionalMaterials/Surface_Integral_Flowchart}
\end{figure}

\pagebreak


\documentclass[11pt]{article}
\newcommand\tab[1][1cm]{\hspace*{#1}}
\usepackage{graphicx}
\graphicspath{ {C:/Users/yedkk/Desktop/CS465/hw4} }
\begin{document}
\section{Homework 4}
Name: Kangdong Yuan

\subsection{problem1}
a).I did not work in a group.
\\b).I did not consult without anyone my group members
\\c).I did not consult any non-class materials.

\subsection{problem2}
First we need to count the number of vertices $|V|$ in this graph G. We count the number of edge in this graph by dfs or bfs. if the count of edges exceed $|V|-1$, return yes. If there are only $|V|-1$ edges in graph G, we return no.  \\
The time to count vertices is $|V|$, and the time to count $|V|$ edges is $O(|V|)$. So, the time complexity of this algorithm is $2|V|=O(|V|)$

\subsection{problem3}
a). the minimum spanning tree will not change\\
\\the reason behind it: if graph has n vertices, then any spanning tree of G has $n-1$ edges. We define the cost of each spanning tree are $x_1,x_2,x_3,...x_j$. If each edge's weight decrease by 1, the cost of every spanning tree will decrease  by a constant $n-1$. So, the new cost of each spanning tree are $x_1-(n-1),x_2-(n-1),x_3-(n-1),...x_j-(n-1)$. Thus, the order of cost of spanning trees will not change, so the mst will still be the mst in new graph after weight changing.   \\
\\
b).but the shortest path may change\\
for example, this is the original graph, the shortest path from vertex 1 to vertex 2 is edge(1,2)\\
\includegraphics[scale=0.2]{og1}\\
This is the new graph that all edge weights minus 1, the shortest path from vertex 1 to vertex 2 is edge (1,3), (3,2)\\
\includegraphics[scale=0.2]{ng1}\\
so the shortest path may change after edge weights changed\\
\subsection{problem4}
we prove by the contradiction.\\
Suppose this claim not hold, which is $T\cap U \notin T_H$. Then there is an edge $e\in T \cap H$ across some cut $(S|V-S)$ of H such that another edge across the cut, where the weight $e'$ is less. However, H is a subgraph of G, so $e'$ is lighter edge than e across the cut $(S|V-S)$ of G. This new edge $e$ should replace the edge in minimum spanning tree in G because it provide less cost, contradicting that T is an MST.

\end{document}


\section{Graphs}

\subsection{Weighted matroid intersection}
\inputminted{cpp}{code/weighted_matroid_intersection.cpp}


%
% @author   Shmish  "shmish90@gmail.com"
% @legal    MIT     "(c) Christopher Schmitt"
%

\documentclass{article}

%
% Document Imports
%

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{color}
\usepackage{tikz}

%
% Document Configuation
%

\newcommand{\hwAuthor}{Christopher Schmitt}
\newcommand{\hwSubject}{Math 218}
\newcommand{\hwSection}{Section 81}
\newcommand{\hwSemester}{Summer 2019}
\newcommand{\hwAssignment}{Assignment 4}

%
% Document Enviornments
%

\setlength{\headheight}{65pt}
\pagestyle{fancy}
\lhead{\hwAuthor}
\rhead{
  \hwSubject \\
  \hwSection \\
  \hwSemester \\
  \hwAssignment
}

\newenvironment{problem}[1]{
  \nobreak\section*{Problem #1}
}{}

%
% Document Start
%

\begin{document}
  \begin{problem}{1}
    Let $\preceq$ be the relation on the set $A = \{2, 3, 5, 8, 25, 30, 300\}$ defined by:
    \begin{center}
      $a \preceq b$ iff $a$ is a divisor of $b$
    \end{center}
    $\preceq$ is a partial order on $A$ (you do not need to prove this).  Answer each of the following.

    \begin{flushleft}
      \textbf{(a)} Draw the hasse diagram for this partially ordered set.
    \end{flushleft}

    \begin{center}
      \begin{tikzpicture}[scale=1.5]
        \node (300) at (1, 0) {$300$};
        \node (8) at (0, -1) {$8$};
        \node (30) at (1, -1) {$30$};
        \node (25) at (2, -1) {$25$};
        \node (2) at (0, -2) {$2$};
        \node (3) at (1, -2) {$3$};
        \node (5) at (2, -2) {$5$};
        \draw (30) -- (300) -- (25) -- (5) -- (30) -- (3) -- (30) -- (2) -- (8);
      \end{tikzpicture}
    \end{center}

    \begin{enumerate}
      \item[\textbf{(b)}] What are the maximal elements for this poset? $\{8, 300\}$
      \item[\textbf{(c)}] What are the maximum elements for this poset? None
      \item[\textbf{(d)}] What are the minimal elements for this poset? $\{2, 3, 5\}$
      \item[\textbf{(e)}] What are the minimum elements for this poset? None
      \item[\textbf{(f)}] Find $2 \vee 3$. $30$
      \item[\textbf{(g)}] Find $8 \vee 25$. Does not exist
      \item[\textbf{(h)}] Find $8 \wedge 300$. $2$
      \item[\textbf{(i)}] Find $8 \wedge 25$. Does not exist
    \end{enumerate}
  \end{problem}

  \begin{problem}{2}
    Prove that the function $f : Q \rightarrow Q$ defined by $f(x) = 3x + 7$ is injective.
    \begin{proof}
      Let $a, b \in Q$, Suppose $f(a) = f(b)$
      \begin{equation*}
        \begin{split}
          3(a) + 7 & = 3(b) + 7\\
          3(a) & = 3(b)\\
          a & = b\\
        \end{split}
      \end{equation*}
    \end{proof}
  \end{problem}

  \begin{problem}{3}
    Prove that the function $f : R \rightarrow R$ defined by $f(x) = x^{2} - 3x + 5$ is not injective.
    \begin{proof}
      \begin{equation*}
        f(0) = f(3)
      \end{equation*}
    \end{proof}
  \end{problem}

  \begin{problem}{4}
    Prove that the function $f : Z \times Z \rightarrow Z$ defined by $f(n, m) = 3n - 2m - 1$ is onto.
    \begin{proof}
      Let $k \in Z$
      \begin{equation*}
        \begin{split}
          f(n, m) & = 3(n) - 2(m) - 1\\
          f(2, 2) & = 3(2) - 2(2) - 1 = 1\\
          f(2k, 2k) & = 3(2k) - 2(2k) - 1\\
          f(2k, 2k) & = k(1) = k
        \end{split}
      \end{equation*}
    \end{proof}
  \end{problem}

  \begin{problem}{5}
    Prove that the function $f : Z \rightarrow Z$ defined by $f(n) = 3n + 2$ is not onto.
    \begin{proof}
      \begin{equation*}
        \begin{split}
          1 & \in Z\\
          1 & = 3n + 2\\
          -1 & = 3n\\
          \frac{-1}{3} & = n\\
          \frac{-1}{3} & \notin Z
        \end{split}
      \end{equation*}
      So $f : Z \rightarrow Z$ cannot produce the value $1$, and therefore cannot be onto.
    \end{proof}
  \end{problem}

  \begin{problem}{6}
    Let $f : R \setminus \{4\} \rightarrow R$ be the function defined by $f(x) = \frac{2x + 7}{x - 4}$
    \begin{flushleft}
      \textbf{(a)} Prove that this function is injective.
    \end{flushleft}
    \begin{proof}
      Let $a, b \in R \setminus \{4\}$ Suppose $f(a) = f(b)$
      \begin{equation*}
        \begin{split}
          \frac{2(a) + 7}{a - 4} & = \frac{2(b) + 7}{b - 4}\\
          (2(a) + 7)(b - 4) & = (2(b) + 7)(a - 4)\\
          2ab - 8a + 7b - 28 & = 2ab - 8b + 7a - 28\\
          -8a + 7b & = -8b + 7a\\
          15b & = 15a\\
          b & = a\\
        \end{split}
      \end{equation*}
    \end{proof}

    \begin{flushleft}
      \textbf{(b)} This function is not onto. Determine which element should be removed from the codomain to make it onto. Prove that $f$ is onto when this element is removed from the codomain, and find the inverse $f^{-1}$.
    \end{flushleft}

    \begin{center}
      $f : R \setminus \{4\} \rightarrow R \setminus \{2\}$
    \end{center}

    \begin{proof}
      Let $r \in R \setminus \{2\}$
      \begin{equation*}
        \begin{split}
          r & = \frac{2x + 7}{x - 4}\\
          r(x - 4) & = 2x + 7\\
          rx - 4r & = 2x + 7\\
          rx - 4r - 2x + 8 & = 15\\
          (r - 2)(x - 4) & = 15\\
          x - 4 & = \frac{15}{r - 2}\\
          x & = \frac{15}{r - 2} + 4\\
          x & = \frac{15 + 4(r - 2)}{r - 2}\\
          x & = \frac{7 + 4r}{r - 2}\\
          f(\frac{7 + 4r}{r - 2}) & = r \text{, where $r \neq 2$}
        \end{split}
      \end{equation*}
    \end{proof}

    \begin{center}
      $f^{-1} : R \setminus \{2\} \rightarrow R \setminus \{4\}$\\
    \end{center}

    \begin{center}
      $f^{-1}(x) = \frac{7 + 4r}{r - 2}$
    \end{center}
  \end{problem}
\end{document}


% !TEX root = ../main.tex

\section{Context}
\begin{frame}{\insertsec}
  \begin{itemize}
    \item Work based on predicting Princess Margaret Cancer Center Dataset's patients survival
    \item Nowadays Machine Learning is widely used
    \item Medical images can be obtained using MRI, PET or CT scans but are underused
    \item Different methods have appeared to analyze these data for image classification,
    object detection, segmentation... usually using deep learning.
    \item Hand-crafted radiomic features can be extracted from medical images
  \end{itemize}
\end{frame}

\subsection{Survival Analysis}
\begin{frame}{\insertsubsec}
  Survival analysis models usually have:
  \begin{itemize}
    \item Baseline data \( x \)
    \item Event \( E \in \{0, 1\} \)
    \item Time \( T \)
    \item Censoring
  \end{itemize}

  \begin{block}{Survival function}
    \[
      S(t) = \Pr(T \ge t)
    \]
  \end{block}

  \begin{block}{Hazard function}
  \[
    \lambda(t) = \lim_{\Delta t \rightarrow 0}
    \frac{\Pr(t \le T < t + \Delta t | T \ge t)}{\Delta t}
  \]
  \end{block}

  \begin{block}{Cox Proportional Hazards model}
    \[
      \lambda(t | \bm{x}) = \exp(\bm{x}\bm{\beta}) \cdot \lambda_0 (t)
    \]
  \end{block}
\end{frame}

\begin{frame}

  Casting the survival problem as a ranking is a way of dealing with censored data.
  Conditions:
  \begin{itemize}
    \item Both of them are uncensored (\( \bm{E}_i = \bm{E}_j = 1\))
    \item The uncensored time of one is smaller than the censored survival time of the other
    (\( \bm{T}_i < \bm{T}_j | \bm{E}_i = 1; \bm{E}_j = 0 \))
  \end{itemize}

  \begin{columns}
    \begin{column}{.5\textwidth}
      \begin{figure}
        \centering
        \scalebox{.8}{\input{drawings/graph_no_censored.tikz.tex}}
        \caption{Uncensored data}
      \end{figure}
    \end{column}
    \begin{column}{.5\textwidth}
      \begin{figure}
        \centering
        \scalebox{.8}{\input{drawings/graph_censored.tikz.tex}}
        \caption{Censored data}
      \end{figure}
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}
  \begin{block}{Good prediction}
    \[
      T_i > T_j \land \hat{T}_i > \hat{T}_j
    \]
  \end{block}

  \begin{block}{Bad prediction}
    \[
      T_i > T_j \land \hat{T}_i < \hat{T}_j
    \]
  \end{block}

  \begin{block}{Concordance Index}
    \[
      CI = \frac{\text{Good predictions}}{\text{Total predictions}} \in [0, 1]
    \]
  \end{block}
\end{frame}

\subsection{Dataset}
\begin{frame}{\insertsubsec}
  \begin{itemize}
    \item Dataset with 671 patients diagnosed of Oropharyngeal Squamous Cell Carcinoma
    \item CT scan of \( 512 \times 512 \) with 100-200 slices
    \item Tumour annotated in provided mask
    \item Clinical information compressed of:
    \begin{itemize}
      \item Subject characteristics
      \item Tumour characteristics
      \item Treatment data
      \item Outcome data
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \begin{figure}
    \centering
    \begin{subfigure}[t]{.32\textwidth}
      \centering
      \includegraphics[width=\textwidth]{images/IMG0138_example.png}
      \caption{Original image}
    \end{subfigure}
    \hfill
    \begin{subfigure}[t]{.32\textwidth}
      \centering
      \includegraphics[width=\textwidth]{images/IMG0138_MASS_example.png}
      \caption{Image mask}
    \end{subfigure}
    \hfill
    \begin{subfigure}[t]{.32\textwidth}
      \centering
      \includegraphics[width=\textwidth]{images/IMG0138_merge_example.png}
      \caption{Mask applied to original}
    \end{subfigure}

    \caption[Images from the dataset]{
      Example of images from the dataset
    }
  \end{figure}
\end{frame}

\subsection{Neural Networks}
\begin{frame}{\insertsubsec}
  \begin{figure}
    \centering
    \input{drawings/neural_network.tikz.tex}
    \caption[Neural network graph]{
      Neural Network graph drawing.
    }
  \end{figure}
\end{frame}

\begin{frame}
  \begin{block}{Hidden Layers}
    \begin{equation*}
      \begin{aligned}
        z_i^{[l]} &= \sum_{j = 1}^{n^{[l]}} w_{ij}^{[l]} \cdot a_j^{[l - 1]} + w_{i0}^{[l]} \\
        a_i^{[l]} &= g^{[l]}(z_i^{[l]})
      \end{aligned}
      \quad
      \xrightarrow{\text{becomes}}
      \quad
      \begin{aligned}
        \bm{z}^{[l]} &= \bm{W}^{[l]} \cdot \bm{a}^{[l - 1]} + \bm{b}^{[l]} \\
        \bm{a}^{[l]} &= g^{[l]}(\bm{z}^{[l]})
      \end{aligned}
    \end{equation*}

  \end{block}
  \begin{figure}
    \centering
    \input{drawings/activation_functions.tikz.tex}

    \caption[Activation functions]{
      Activation functions
    }
  \end{figure}
\end{frame}

\begin{frame}
  \begin{block}{Output layers}
    \[
      g_k^{[L]}(\bm{a}^{[L - 1]}) = \frac{e^{a_k^{[L - 1]}}}{\sum_{i = 1}^K e^{a_i^{[L - 1]}}}
    \]
  \end{block}

  \begin{block}{Cost function}
    \begin{align*}
      \hat{\bm{y}} &:= g^{[L]}(\bm{a^{[L - 1]}}) \\
      C(\bm{y}, \hat{\bm{y}}) &:= \frac{1}{N} \sum_{i = 1}^N (y_i - \hat{y}_i)^2
    \end{align*}
  \end{block}
\end{frame}

\subsection{Convolutional Neural Networks}

\begin{frame}{\insertsubsec}
  \centering
  \begin{figure}
    \hspace{-7cm}
    \adjustbox{max width=1.35\pagewidth}{\input{drawings/convolution_operation.tikz.tex}}

    \caption{Convolution operation}
  \end{figure}

  \begin{block}{Output size}
    \begin{align*}
      n_{\text{next}} = \left\lfloor\frac{n_{\text{prev}} + p - f}{s}\right\rfloor + 1
    \end{align*}
  \end{block}
\end{frame}

\begin{frame}
  \begin{figure}
    \centering
    \scalebox{.7}{\input{drawings/convolutional_layer.tikz.tex}}
    \caption{Convolutional layer}
  \end{figure}

  \begin{align*}
    \bm{z}^{[l]} &= \bm{W}^{[l]} \cdot \bm{a}^{[l - 1]} + \bm{b}^{[l - 1]} \\
    &\downarrow \text{becomes} \\
    \bm{\mathsf{Z}}^{[l]} &= \bm{\mathsf{A}}^{[l - 1]} * \bm{\mathsf{W}}^{[l]} +
    \bm{\mathsf{B}}^{[l - 1]}
  \end{align*}
\end{frame}


\input{docs/preamble}
\title{Optical Pumping}
\author{Max Bigras and David Frawley}

\begin{document}

\maketitle

\begin{abstract}
We performed optical pumping to trap $^{85}$Rb and  $^{87}$Rb atoms. We measured the strength of an applied magnetic field and the intensity of light passing through the Rb vapor. We determined the Lande g-factor, $g_{\mathrm{f}}$, for each of the isotopes and were able to determine the ratio $g^{\mathrm{exp}}_{87}$/$g^{\mathrm{exp}}_{85}$ = $1.5 \pm 0.1$ which agrees with the accepted value $g_{87}$/$g_{85}$ = 1.5. We also observed our applied magnetic field cancel the Earth's magnetic field.
\end{abstract}

\section{Introduction}
Optical pumping is an important experimental technique that takes precise advantage of quantum selection rules to trap and manipulate atoms. We used a technique developed in the 1950s by Alfred Kastler who later won the Nobel Prize in 1966 \cite{wiki}. By careful constructing a magnetic field from pairs of Helmholtz coils, one can adjust the Zeeman energy gap and pump atoms into a trapped state. Once trapped the atoms can be manipulated in interesting and precise ways to measure quantities like the size of the Zeeman energy gap, the atom's g-factors, or the strength of an external magnetic field.

\section{Theory}
\subsection{Zeeman splitting}
When an atomic system is placed in a magnetic field it's energy levels undergo Zeeman splitting. Our atomic system consists of the two stable isotopes $^{85}$Rb and  $^{87}$Rb. A schematic for $^{85}$Rb can be seen in Figure \ref{energy_levels}. In the Rb atoms there are three magnetic moments caused by orbiting electrons, electron spin, and nuclear spin. Taking into account these moments the equation for the energy gap between adjacent levels is

\begin{equation}
E_{\mathrm{Zeeman}}= g_{\mathrm{f}} \mu_{\mathrm{B}} B
\label{zeeman}
\end{equation}
where $g_{\mathrm{f}}$ is the Lande g-factor, $\mu_{\mathrm{B}}$ is the Bohr magneton, and $B$ is the strength of the total magnetic field felt by the atom.
\begin{figure}[H]
  \includegraphics[totalheight=0.65\textwidth]{figs/energy_levels}
  \caption{Structure of the $^{85}$Rb isotope (not to scale) image from \cite{manual}}
  \label{energy_levels}
\end{figure}

\subsection{Optical pumping}

A visual description for optical pumping can be seen in Figure \ref{pumping}. Initially all the atomic states are equally populated. At this point an atom in one of the lower states can absorb  a photon and excite, following the selection rule $\Delta m_{\mathrm{F}} = +1$. To de-excite the atom emits a photon and follows the selection rule $\Delta m_{\mathrm{F}} = -1, 0, +1$. So there is some probability that $\Delta m_{\mathrm{F}}$ will be 0 or $+1$ on the way down, causing a net ``ratcheting up'' of the atoms. Now when the Rb atom falls into the $m_{\mathrm{F}} = 3$ state it can no longer excite while following the selection rules, so it is trapped. Interestingly once all the atoms are trapped they can no longer absorb photons and become transparent, shown in  Figure \ref{pumping}g.
\begin{figure}[H]
  \includegraphics{figs/pumping}
  \caption{Optical pumping of Rb atoms with 795 nm light}
  \label{pumping}
\end{figure}

A visual description for de-pumping and zero-fielding can be seen in Figure \ref{rfing}. Now, all the Rb atoms have been trapped. What could cause a Rb atom to   absorb a photon again? There are two ways, the first is place the atoms in a zero-field situation so there is no more Zeeman splitting and they can absorb photons as usual. The second is de-pump the atoms into a lower state, now they can obey the selection rules and absorb photons.

How is a zero field situation created? Even if there is no magnetic field created in the lab Zeeman splitting will  occur because of the presence of the Earth's magnetic field. If one adjusts the magnetic field in a precise way the Earth's magnetic field can be canceled, thus creating a zero-field situation, shown in Figure \ref{rfing}b.

How are atoms de-pumped? If the magnetic field is increased further then the Zeeman gap is also increased. What if the atoms are exposed to a second set of photons at the same time? The energy of these photons is
\begin{equation}
E = hf
\end{equation}
If the Zeeman energy gap is matched with the energy of the second set of photons then stimulated emission will occur, de-pumping a Rb atom so it is again able to absorb the higher energy exciting photons while obeying the selection rules, Figure \ref{rfing}d-\ref{rfing}e.
\begin{figure}[H]
  \includegraphics{figs/rfing}
  \caption{Zero-fielding and De-pumping Rb atoms with RF photons}
  \label{rfing}
\end{figure}

\section{Apparatus}
A schematic for our apparatus can be seen in Figure \ref{schematic}. We generate 795 nm light from a Rubidium lamp. The light is then manipulated and filtered so we get 795 nm circularly polarized light which is used to pump Rb atoms. After the light passes through the chamber we measured it's intensity with a detector.

Optical pumping and manipulation depend on a carefully controlled magnetic field. We generated the vertical and horizontal components of the lab's magnetic field with a pair of Helmholtz coils. Now we have trapped atoms, to de-pump them we require a second set of lower energy photons. We used Helmholtz coils to generate radio frequency photons shown in red, Figure \ref{schematic}g.

% magnetic field vs current
\begin{figure}[H]
  \includegraphics[totalheight=0.5\textwidth]{figs/apparatus}
  \caption{Experimental setup. \newline
a) Rubidium lamp \newline
b) lens, $f$ = 50 mm \newline
c) Interference filter \newline
d) Polarizer \newline
e) Quarter wave plate \newline
f) 795 nm right circularly polarized light \newline
g) Helmholtz coils, with rubidium chamber \newline
h) lens, $f$ = 50 mm \newline
i) Amplified photo-detector}
  \label{schematic}
\end{figure}

\section{Analysis}
What kind of behavior will a system of trapped atoms that is suddenly freed exhibit? It will absorb light, which is to say go from transparent to not transparent. We can measure and detect when this happens because the intensity of the light passing through the chamber will suddenly decrease. By sweeping through an increasing range of magnetic fields we can see when the magnetic field is just right to cause: a cancellation of Earth's magnetic field, stimulated emission of  $^{87}$Rb and stimulated emission of $^{85}$Rb, shown in Figure \ref{depumping}. What will happen if the radio frequency is increased? Now the Zeeman energy gap must be larger for stimulated emission to occur so we would see the two humps slide to the right.
% MATLAB by itself EPS
\begin{figure}[H]
  \includegraphics[totalheight=0.6\textwidth]{figs/depumping_final}
  \caption{Drop in light intensity caused by canceling Earth's magnetic field and de-pumping $^{85}$Rb and $^{87}$Rb}
  \label{depumping}
\end{figure}

Because we can measure the current through the Helmholtz coils and we know the required physical parameters of the coils we can measure the magnetic field. Because we know the energy of the RF photons we can measure the Zeeman energy gap. A plot and fit of the energy gap vs. magnetic field can be seen in Figures \ref{rb85line} and \ref{rb87line}. We determined the slope of the line and by applying Equation \ref{zeeman} we determined the Lande g-factors. Our results can be seen in Table \ref{result}. Taking the ratio we obtain $g^{\mathrm{exp}}_{87}$/$g^{\mathrm{exp}}_{85}$ = $1.5 \pm 0.1$ which agrees with the accepted value $g_{87}$/$g_{85}$ = 1.5, shown in Table \ref{result2}.
% MATLAB by itself EPS
\begin{figure}[H]
  \includegraphics[totalheight=0.6\textwidth]{figs/rb85}
  \caption{Determining the slope of  $\Delta E$ vs. $B$  for  $^{85}$Rb}
  \label{rb85line}
\end{figure}

% MATLAB by itself EPS
\begin{figure}[H]
  \includegraphics[totalheight=0.6\textwidth]{figs/rb87}
  \caption{Determining the slope of $\Delta E$ vs. $B$  for  $^{87}$Rb}
  \label{rb87line}
\end{figure}

\begin{table}[H]
\caption{Experimental g-factors }
\begin{tabular}{c@{\hskip 1cm} c}
\hline\noalign{\smallskip}
Isotope & $g_{\mathrm{f}_{\mathrm{exp}}}$ \\
\hline\noalign{\smallskip}
$^{85}$Rb & $0.34 \pm 0.02$\\
$^{87}$Rb & $0.52 \pm 0.03$\\
\hline\noalign{\smallskip}
\end{tabular}
\label{result}
\end{table}

\begin{table}[H]
\caption{Experimental and Accepted g-factor ratio from \cite{mit} }
\begin{tabular}{c@{\hskip 1cm} c@{\hskip 1cm} c}
\hline\noalign{\smallskip}
Quantity & Experimental Value & Accepted Value \\
\hline\noalign{\smallskip}
$g_{87}$/$g_{85}$ & $1.5 \pm 0.1$ & 1.5 \\
\hline\noalign{\smallskip}
\end{tabular}
\label{result2}
\end{table}

\section{Conclusion}
We performed optical pumping to trap $^{85}$Rb and  $^{87}$Rb atoms. We measured the strength of an applied magnetic field and the intensity of light passing through the Rb vapor. We determined the Lande g-factors for each of the isotopes which agree with accepted values. We also observed our applied magnetic field cancel the Earth's magnetic field.

\begin{thebibliography}{99}

\bibitem{manual} Physics Dept., ``Optical Pumping'', Quantum Lab,
  California Polytechnic University, (2013).

\bibitem{wiki} ``Optical pumping'', Wikipedia: The Free Encyclopedia. Wikimedia Foundation, Inc., 05 December 2013. Web. wikipedia.org/wiki/Opticalpumping.

\bibitem{mit} A. Speranza, ``Optical Pumping of Rubidium Vapor'', MIT Physics Dept.,MIT University, (2013).

\end{thebibliography}

\end{document}


% !TEX root = main.tex

\chapter{Hypothesis Testing}\label{chap:hyptest}

\input{09A_nhst}
\input{09B_examples}
\input{09C_slrt}
\input{09D_most_powerful_tests}


\subsection{\acrshort{nrpa} playout}%
\label{sub:nrpa_playout}

A \gls{nrpa} playout is used to generate and evaluate a sequence of actions.
So a sequence \(S={a1, a2, a3, \dots}\) is a list of actions that lead from the root state to a terminal one.
To \(S\), we can attach a score equal to the sum of rewards obtained by applying it to the root state.
As the problem is not stochastic, therefore, \(S\) can be apply any number of time and will always give the same resuls.

The algorithm in charge of the rollout is given in algorithm~\ref{alg:nrpa_playout}.
The algorithm first initialize the sequence it's going to create (line 2).
Then if it reaches a terminal state, it returns the sequence alongside the score obtained.
Otherwise, it repeats the following.
It sums the exponential of the weights attached to each legal actions for the current state (line 8-10).
Then it samples a move among the legal ones according to the exponential of the weight divided by the sum it just computed.
This basically means that, a move attached to a big weight will more likely be picked.
It then plays the chosen action and update the sequence by adding the move at the end.

\begin{figure}[htpb]
    \centering
    \begin{minipage}{.7\linewidth}
        \subimport{../../../algorithms/nrpa/}{playout.tex}
    \end{minipage}
\end{figure}


\documentclass[11pt]{article}
\usepackage[english]{babel}
\usepackage{a4}
\usepackage{latexsym}
\usepackage[
	colorlinks,
	pdftitle={Towers of Hanoi in Lambda Calculus},
	pdfsubject={Towers of Hanoi in Lambda Calculus},
	pdfauthor={Martijn Vermaat}
]{hyperref}

\title{Towers of Hanoi in Lambda Calculus}
\author{
	Martijn Vermaat\footnote{E-mail: mvermaat@cs.vu.nl, homepage: http://www.cs.vu.nl/\~{}mvermaat/}
}
\date{29th February 2004}

\begin{document}
\maketitle

\begin{abstract}
In this document we will see how a solution to the Towers of Hanoi problem can be constructed in pure, untyped Lambda Calculus.
\end{abstract}

\tableofcontents

\section{The problem of the Towers of Hanoi}

The problem definition below is taken from Wikipedia\footnote{Tower of Hanoi, http://en.wikipedia.org/wiki/Tower\_{}of\_{}Hanoi}.

\begin{quote}
The Tower of Hanoi (also called Towers of Hanoi) is a mathematical game or puzzle. It consists of three pegs, and a number of discs of different sizes which can slot onto any peg. The puzzle starts with the discs neatly stacked in order of size on one peg, smallest at the top, thus making a conical shape.

The object of the game is to move the entire stack to another peg, obeying the following rules:
\begin{itemize}
\item
only one disc may be moved at a time
\item
a disc can only be placed onto a larger disc (it doesn't have to be the adjacent size, though: the smallest disc may sit directly on the largest disc)
\end{itemize}
\end{quote}

This problem is often used in programming courses to illustrate the use of recursion. Solutions have been programmed in allmost every language known to human kind. Having taken a introductory course on Lambda Calculus, I searched for a solution for the Towers of Hanoi problem in Lambda Calculus. Much to my suprise, I wasn't able to find one.

\section{A solution in untyped Lambda Calculus}

\subsection{The simple solution in Haskell}

The solution is basically a translation to Lambda Calculus of the following obvious solution in Haskell:

\begin{verbatim}
hanoi (0, _, _, _)         = []
hanoi (n, from, to, using) = hanoi(n-1, from, using, to) ++
                               (from, to) :
                               hanoi(n-1, using, to, from)
\end{verbatim}

That is, to move \verb|n| discs from \verb|from| to \verb|to| (using \verb|using|), all we have to do is move \verb|n-1| discs to \verb|using|, then move the last disc to \verb|to|, and finaly move the \verb|n-1| discs from \verb|using| to \verb|to|. The trivial case here is moving 0 discs--just don't do anything (return the empty list of pairs). Calling \verb|hanoi| as follows will return a list of pairs, where each pair denotes a move:

\begin{verbatim}
> hanoi (3, 1, 3, 2)
[(1,3),(1,2),(3,2),(1,3),(2,1),(2,3),(1,3)]
\end{verbatim}

In Lambda Calculus, we can try to do the same thing, using notations for pairs, lists, and natural numbers. Because we are talking about untyped Lambda Calculus, the result will be complicated to read (but nevertheless it can well be a correct solution).

\subsection{Translating to Lambda Calculus}

To denote numbers, we will use the common notation known as Church Numerals. The most important part of the translation is what we can do in Haskelly with simple pattern matching: to distinguish in the number 0 and all numbers above.

By realising what happend if we apply two arguments on a Church Numeral, we find the following body for our Hanoi function:

\begin{displaymath}
\lambda n.n \quad (\lambda x.A) \quad B
\end{displaymath}

where $A$ is some Lambda term not containing $x$ and $B$ an arbitrary Lambda term. This function expects one argument, a Church numeral, and will reduce to $A$ on applications on numbers greater than zero, and $B$ on application on zero.

Now, moving on, we can fill in the $B$ part. The resulting term for zero has to be the empty list. We do have to make sure though, to discard the three arguments $from$, $to$, and $using$. So, using $empty$ as the empty list constructor, we have our new Hanoi function:

\begin{displaymath}
\lambda n.n \quad (\lambda x.A) \quad (\lambda f \; t \; u.empty)
\end{displaymath}

The $A$ part is a bit more complicated, but can nevertheless be translated from the Haskell solution fairly straightforward by making use of some predefined functions:

\begin{displaymath}
\begin{array}{ll}
\lambda f \; t \; u\;. \quad append & (hanoi\;(pre\;n)\;f\;u\;t) \\
& (cons \; (pair\;f\;t) \; (hanoi\;(pre\;n)\;u\;t\;f))
\end{array}
\end{displaymath}

where:

\begin{itemize}
\item $append$ is the append operator for lists
\item $pre$ is the predecessor function
\item $cons$ is the list constructor function
\item $pair$ is the pairing constructor function
\item $hanoi$ is a recursive call to the Hanoi function itself
\end{itemize}

Combining these results, we then have a complete Hanoi function:

\begin{displaymath}
\begin{array}{llll}
hanoi \to & \lambda n.n & ( \lambda f \; t \; u\;. \; append & (hanoi\;(pre\;n)\;f\;u\;t) \\
& & & (cons \; (pair\;f\;t) \; (hanoi\;(pre\;n)\;u\;t\;f)) ) \\
& & (\lambda f \; t \; u.empty) &
\end{array}
\end{displaymath}

\subsubsection{Recursion in Lambda Calculus}

The problem is that we now have a definition in terms of it self. We say we now how $hanoi$ goed, but only if we know $hanoi$. We can transform this recursive definition in a non-recursive one using a little trick and the fixed-point combinator $Y$\footnote{For a short explanation of the fixed-point combinator, see for example http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?fixed+point+combinator on FOLDOC}.

We can rewrite the term we just had to the following (taking the $hanoi$ references outside the term):

\begin{displaymath}
\begin{array}{llll}
hanoi \to & (\lambda h \; n.n & ( \lambda f \; t \; u\;. \; append & (h\;(pre\;n)\;f\;u\;t) \\
& & & (cons \; (pair\;f\;t) \; (h\;(pre\;n)\;u\;t\;f)) ) \\
& & (\lambda f \; t \; u.empty)) & \\
& hanoi & &
\end{array}
\end{displaymath}

The resulting definition is still recursive, but if we look closely, we can see that $hanoi$ seems to be a fixed-point of the function consisting of the complex inner term (everything between the two $hanoi$'s).

That observation makes it possible to write $hanoi$ using the fixed-point combinator $Y$, as follows:

\begin{displaymath}
\begin{array}{llll}
hanoi \to & Y \quad \lambda h \; n.n & ( \lambda f \; t \; u\;. \; append & (h\;(pre\;n)\;f\;u\;t) \\
& & & (cons \; (pair\;f\;t) \; (h\;(pre\;n)\;u\;t\;f)) ) \\
& & (\lambda f \; t \; u.empty) &
\end{array}
\end{displaymath}

And there we have our final definition of a solution for the Towers of Hanoi problem in untyped Lambda Calculus. Please don't try to prove its correctness by reducing

\begin{displaymath}
hanoi \; 4 \; left \; right \; middle
\end{displaymath}

by hand. Let's instead just assume it's correct enough.

\appendix

\section{Function definitions}

Below are the definitions of the functions used in the construction of our solution. These definitions are widely used and are certainly not `invented' by me. Because there we have smart people for.

\subsection*{General combinators}

\begin{displaymath}
\begin{array}{rll}
I & \to & \lambda x.x \\
Y & \to & \lambda f. \; (\lambda x.f(x \; x)) \; (\lambda x.f(x \; x))
\end{array}
\end{displaymath}

\subsection*{Church numerals}

\begin{displaymath}
\begin{array}{rll}
zero & \to & \lambda s \; z.z \\
suc & \to & \lambda x \; s \; z.s \; (x \; s \; z) \\
pre & \to & \lambda c.c \; (\lambda z. \; (z \; I (suc \; z))) \; (\lambda a. \; (\lambda x.zero))
\end{array}
\end{displaymath}

\subsection*{Pairing constructor}

\begin{displaymath}
\begin{array}{rll}
pair & \to & \lambda l \; r \; z.z \; l \; r
\end{array}
\end{displaymath}

\subsection*{Lists}

\begin{displaymath}
\begin{array}{rll}
empty & \to & \lambda x \; y.y \\
cons & \to & \lambda h \; t \; z.z \; h \; t \\
append & \to & Y \quad (\lambda a \; l \; r.l \; (\lambda h \; t \; z.cons \; h \; (a \; t \; r)) \; r)
\end{array}
\end{displaymath}

\end{document}


\chapter{IDL Routines}
\label{ch_idl}
%\chapterhead{IDL Routines}
\markright{IDL Routines}

\section{Introduction}
A set of routines has been developed in IDL. Starting IDL using
the script program {\em mre} allows the user to get the multiresolution
environment, and all routines
described in the following can be called. An online help facility
is also available by
invoking the {\em mrh} program under IDL.

\section{IDL Tools}
\subsection{del\_pattern}
\label{pat}
Suppress a pattern in an image. A pattern is considered as a peak in
Fourier space. So it can be iteratively eliminated.
{\bf
\begin{center}
     USAGE: output = del\_pattern(Image, n\_iter=n\_iter, pattern=pattern, disp=disp, NSigma=NSigma, NbrScale=NbrScale)
\end{center}}
where
\begin{itemize}
\item {\em Image} is an IDL 2D array.
\item {\em n\_iter} is the number of iterations. Default is 3.
\item if {\em disp} set, then results are displayed during the iterations.
\item {\em output} is an IDL 2D array. It contains the input image, without
the pattern.
\item {\em pattern} is an IDL 2D array. It is equal to the difference between
{\em Image} and {\em output}.
\item {\em NSigma} is a real value (default is 3.0).
\item {\em NbrScale} is the number of scales used in the wavelet transform.
\end{itemize}

\subsection{block\_trans}
This routine separates the image into blocks of size {\em BlockSize}
$\times$ {\em BlockSize}
and computes inside each block the mean and the variance. The
variance versus mean plot gives information about the type of noise in
the data.

{\bf
\begin{center}
     USAGE: block\_trans, Image, TabVar=TabVar, TabMean=TabMean,  Plot=Plot, BlockSize=BlockSize
\end{center}}
where
\begin{itemize}
\item {\em Image} is an IDL 2D array.
\item {\em TabVar} is an output keyword and is the array of variances.
\item {\em TabMean} is an output keyword and is the array of means.
\item {\em Plot} is an input keyword. If set, the curve variance versus
mean is plotted.
\item {\em BlockSize} is the size of the blocks. Default is 8.
\end{itemize}

\subsection{delete}
Suppress a file in working directory.
{\bf
\begin{center}
     USAGE: delete, filename
\end{center}}

\subsection{im\_smooth}
Smooth an image, taking into account the border.
{\bf
\begin{center}
     USAGE:  im\_smooth, Im\_in, Im\_out, method=method, Step\_Trou=Step\_Trou, Border=Border, WinSize=WinSize
\end{center}}
where
\begin{itemize}
\item {\em Im\_in} is the input 2D IDL array.
\item {\em Im\_out} is the output 2D IDL smoothed array.
\item {\em method}: keyword specifying the method for smoothing.
Available methods are ``linear'', ``bspline'', or ``median''. Default is
``median''.
\item {\em Step\_Trou}: $2^{Step\_Trou}$ is the  distance between
two adjacent
pixels (default is 0).
\item {\em Border} defines the way  the borders of the image must be managed.
Available methods are: ``cont'' ($Im_{in}(-i,-j) = Im_{in}(0,0)$), ``mirror''
($Im_{in}(-i,-j) = Im_{in}(i,j)$), ``zero'' ($Im_{in}(-i,-j) = 0$), ``nobord'' (the
borders of the image are not
smoothed).
\item {\em WinSize} is the window size (only used if method =
``median''). Default is 3.
\end{itemize}

\subsection{Tikhonov}
 Deconvolve  an image using Tikhonov regularization.
 This program does not shift the maximum of the PSF to the center.
 The minimized functional is:
\begin{eqnarray}
  J(O) = \parallel I - P*O  \parallel + \alpha  \parallel H*O  \parallel
 \end{eqnarray}
where $O$ is the unknown object, $P$ the point spread function (PSF), $I$
the data and $H$ a high pass filter (the Laplacian).
{\bf
\begin{center}
  USAGE: Result = TIKHONOV(Imag, Psf, residu=residu, niter=niter,
                         CvgParam=CvgParam, RegulParam=RegulParam,
                         NoRegul=NoRegul)
 \end{center}}
 where
\begin{itemize}
\item {\em Imag} is an input 2D IDL  array, i.e.\ the image to deconvolve.
\item {\em Psf}  is an input 2D IDL  array, i.e.\ point spread function.
\item {\em niter} is the input number of iterations. Default is 10.
\item {\em CvgParam} is the convergence parameter. Default is 0.1.
\item {\em RegulParam} is the regularization parameter (i.e.\ $\alpha$).
\item {\em NoRegul} if set, no regularization is performed.
\item {\em Residu} is an output 2D IDL array containing the residual:
residual = Imag -- Psf*Result.
\end{itemize}

If the keyword NoRegul is set, then no regularization is done,
and the algorithm becomes a simple one step gradient method.
\subsubsection*{Examples:}
\begin{itemize}
\item Result = TIKHONOV(Imag, Psf) \\
Deconvolve an image with all default options.
\item  Result = TIKHONOV(Imag, Psf) \\
 Same example, but impose the number of iterations to be 30.
\item   Result = TIKHONOV (Imag, Psf, niter=30) \\
 Deconvolution by the one step gradient method, without
 any regularization, with 30 iterations.
\item  Result = TIKHONOV (Imag, Psf, niter=30, /NoRegul)
\end{itemize}

\section{Noise Related Routines}
\subsection{poisson\_image}
Create an image with Poisson-distributed values around the mean values
IMAGE, using Knuth's ``Algorithm Q"  (D.E. Knuth, The Art of
Computer Programming, Volume 2, ``Seminumerical Algorithms",
Addison-Wesley, 1969, p.\ 117). This routine has been written by James Hamill
(Siemens Medical Systems, 2501 N. Barrington Rd., Hoffman Estates, IL
60195-7372), and has been inserted in the \proj package.
{\bf
\begin{center}
     USAGE: output = poisson\_image ( image[, seed] )
\end{center}}
where {\em image} is a  numeric array (byte, integer, long, or float) of arbitrary dimensionality.
This is the array of values around which values in the
result will be Poisson-distributed. {\em seed} is a  longword seed for the random number generator.  If this is not
supplied, the value --123456789L is used for generating the first random
value.

\subsection{poisson\_to\_gauss}
Transforms the data with Poisson noise into a new set of data
 with Gaussian noise using the generalized Anscombe transform.
\begin{eqnarray}
T(x) = \frac{2}{gain} \sqrt{gain*x + \frac{3}{8}*gain^2 + \sigma^2 - gain * mean}
\end{eqnarray}
where
\begin{itemize}
\item {\em gain} = gain of the CCD
\item $\sigma$ = standard deviation of the readout noise
\item {\em mean} = mean of the read out noise
\end{itemize}
For pure Poisson noise, {\em gain}=1, {\em mean}=0, and $\sigma$=0.
If the {\em inv} keyword is set, then the inverse transform is applied:
\begin{eqnarray}
 T(x) = \frac{x^2}{4.} * \textrm{\em gain} - \frac{\frac{3}{8}*\textrm{\em gain}^2 + \sigma^2 - gain * mean}{gain}
\end{eqnarray}

{\bf
\begin{center}
     USAGE: output = poisson\_to\_gauss (Data, poisson=poisson, inv=inv)
\end{center}}
\begin{itemize}
\item {\em Data}: IDL array: data
\item {\em poisson}: float array (poisson(0) = gain, poisson(1)= $\sigma$, and
poisson(2) = mean). By default, poisson=[1.,0.,0.].
\item {\em inv}: If set, the inverse transform is applied.
\end{itemize}

\subsection{sigma\_clip}
Returns the noise standard deviation obtained by k-sigma.
{\bf
\begin{center}
     USAGE: output = sigma\_clip(Data, sigma\_clip=sigma\_clip, mean=mean)
\end{center}}
where
\begin{itemize}
\item {\em output}: standard deviation estimated by k-sigma clipping.
\item {\em Data}: IDL array (input data).
\item {\em sigma\_clip}: number of iterations.  Default value is 3.
\item {\em mean}: If mean is set, the mean of the data (taking into
account outliers) is returned.
\end{itemize}

\subsection{get\_noise}
Find the standard deviation of white Gaussian noise in the data.
{\bf
\begin{center}
     USAGE: SigmaNoise = get\_noise(Data, Niter=Niter)
\end{center}}
{\em Data} is an IDL array (1D, 2D, or 3D), and ({\em Niter}) is a keyword
which fixes the number of iterations used by the sigma clipping. Default
value is 3.

\section{Display}
\subsection{tvlut}
Display an image with a zoom factor, and the LUT is displayed
The zoom factor is calculated automatically in order to visualize
the image in a window of size 320 $\times$ 320 (for an image 32 $\times$
32, the
zoom factor is 320/32 = 10). An offset is automatically calculated
(or is set by keywords) in order to center the image in the IDL window.
{\bf
\begin{center}
     USAGE: tvlut, Data, Depx=Depx, Depy=Depy
\end{center}}
where
\begin{itemize}
\item {\em Data}: 2D IDL array (input data) to visualize.
\item {\em Depx}: offset in x (default is 50).
\item {\em Depy}: offset in y (default is 80).
\end{itemize}

\subsection{xdisp}
XDISP is a widget program for image analysis. Several operations
can be carried out by using the mouse and pressing buttons:
\begin{itemize}
\baselineskip=0.4truecm
\item QUIT: quit the application
\item LOAD: load a FITS image.
\item LUT: modify the LUT.
\item PROFILE: examine rows or columns.
\item CURSOR: examine pixel values. If the image format is FITS and if
the header contains astrometric position, then the pixel
position in the sky is given (right ascension and declination).
\item HISTO: plot the histogram.
\item CONTOURS: Contours of the image (isophotes).
\item 3D VISU: three-dimensional representation of the image.
\item INFO: print the min, max, mean, sigma of the image.
\item FFT: compute the Fourier transform and display either the power
spectrum, the phase, the real part or the imaginary part.
\item PAN: make a zoom. Zoom factors are 2,4,8,1/2,1/4,1/8
\end{itemize}
{\bf
\begin{center}
     USAGE: xdisp, Data [, FitsHeader]
\end{center}}
{\em Data} is a two-dimensional IDL array, and {\em FitsHeader} (string array)
is an optional parameter for astrometric information (in FITS format).

\subsection{x3d}
X3D is a widget program for cube analysis. Several operations
can be carried out by using the mouse and buttons:
\begin{itemize}
\baselineskip=0.4truecm
\item  QUIT: quit the application
\item Temporal Cut: A temporal cut is displayed.
\item Horizontal Cut: A horizontal cut is displayed.
\item Vertical Cut: A vertical cut is displayed.
\item Frame Number: When the user enters a value V followed by carriage return
the image Cube(*,*,V) is displayed.
\item Window Size: Define the number of elements plotted.
\item Slider Frame Number: When the user moves the slider,
the corresponding frame is displayed.
\end{itemize}

{\bf
\begin{center}
     USAGE: x3d, Data, from=from, to=to
\end{center}}
{\em Data} is an IDL 3D array. The keywords {\em from} and {\em to} allow
the user
to define a subcube, which can analysed separately with x3d.
\subsubsection*{Example:}
\begin{verbatim}
IDL> HELP,MY_CUBE
       MY_CUBE         INT       = Array(32, 32, 100)
IDL>  X3D, my_cube,from=[0,21,50],to=[20,49,99]
\end{verbatim}

\subsection{xdump}
Save the selected window in a Postscript file. The file
name is ``idl.ps''.
{\bf
\begin{center}
     USAGE: xdump, FILENAME=filename, WIN=win, LANDSCAPE=landscape,
              SCALE=scale, TITLE=title, GIF=gif
\end{center}}
where keywords are
\begin{itemize}
\item {\em filename}: filename of output Postscript file (default is ``idl.ps")
\item {\em win}: identifier of IDL window (default is active window)
\item {\em landscape}: set landscape orientation
\item {\em title}: add the title at the upper left corner of window
\item {\em scale}: specify a scale to be applied to the entire graph
\item {\em gif}: store the data in GIF format instead of PS format.
 Default title in this case ``idl.gif".
\end{itemize}

\section{Multiresolution Routines (1D)}
\subsection{mr1d\_atrou}
Computes a multiresolution transform of a 1D Signal by the
\`a trous algorithm.
{\bf
\begin{center}
     USAGE: mr1d\_atrou, Signal, WaveTrans, Nscale, mirror=mirror, linear=linear
\end{center}}
where
\begin{itemize}
\item {\em Signal}: input one-dimensional IDL array.
\item {\em WaveTrans}: output two-dimensional array (wavelet transform).
\item {\em Nscale}: number of scales (input parameter).
\item {\em mirror}: if set, then mirroring is used at the border.
\item {\em linear}: if set, then a linear wavelet function is used.
If not set, then a B-spline wavelet function is used.
\end{itemize}

\subsection{mr1d\_pavemed}
Computes a multiresolution transform of a 1D Signal by the
multiresolution median algorithm.
{\bf
\begin{center}
     USAGE: mr1d\_pavemed, Signal, MedTrans, Nscale, cont=cont
\end{center}}
where
\begin{itemize}
\item {\em Signal}: input one-dimensional IDL array.
\item {\em MedTrans}: output two-dimensional array (multiresolution transform).
\item {\em Nscale}: number of scales (input parameter).
\item {\em cont}: if set, consider the data as constant beyond
the borders.
\end{itemize}

\subsection{mr1d\_minmax}
Computes a multiresolution transform of a 1D Signal by the
min-max algorithm.
{\bf
\begin{center}
     USAGE: mr1d\_minmax, Signal, MinMaxTrans, Nscale
\end{center}}
where
\begin{itemize}
\item {\em Signal}: input one-dimensional IDL array.
\item {\em MinMaxTrans}: output two-dimensional array
(multiresolution transform).
\item {\em Nscale}: number of scales (input parameter).
\end{itemize}

\subsection{mr1d\_pyrmed}
Computes a multiresolution transform of a 1D Signal by the
pyramidal median algorithm.
{\bf
\begin{center}
     USAGE: mr1d\_pyrmed, Signal, MedTrans, Nscale, TabNp=TabNp, interp=interp, cont=cont
\end{center}}
where
\begin{itemize}
\item {\em Signal}: input one-dimensional IDL array.
\item {\em MedTrans}: output two-dimensional array (multiresolution transform).
\item {\em Nscale}: number of scales (input parameter).
\item {\em TabNp}: Number of pixels at each scale of the multiresolution
transform (MedTrans(0:TabNp(j)-1) are the multiresolution coefficients
of the scale j).
\item {\em interp}: if set, each scale is interpolated to the size of the
input signal.
\item {\em cont}: if set, consider the data as constant outside
the borders.
\end{itemize}

\subsection{mr1d\_paverec}
Reconstruct a signal from its multiresolution transform (\`a trous algorithm
or multiresolution median transform).
{\bf
\begin{center}
     USAGE: mr1d\_paverec, MR\_Trans, Rec\_Signal, Adjoint=Adjoint,
mirror=mirror, nosmooth=nosmooth
\end{center}}
where
\begin{itemize}
\item {\em MR\_Trans}: input two-dimensional
IDL array (multiresolution transform).
\item {\em Rec\_Signal}: output one-dimensional
IDL array. This is the reconstructed signal.
\item {\em Adjoint}: if set, the adjoint operator is used for the
reconstruction.
\item {\em nosmooth}: if set, the last scale is not used.
\item {\em interp}:  if set, and if adjoint is set,
then mirroring is used beyond the borders.
\end{itemize}

\subsection{mr1d\_pyrrec}
Reconstruct a signal from its pyramidal multiresolution transform.
{\bf
\begin{center}
     USAGE: mr1d\_pyrrec, MR\_Trans, Rec\_Signal
\end{center}}
where
\begin{itemize}
\item {\em MR\_Trans}: input two-dimensional IDL array (multiresolution transform).
\item {\em Rec\_Signal}: output one-dimensional IDL array. This
is the reconstructed signal.
\end{itemize}

\subsection{mr1d\_pyrinterp}
Interpolate each scale of a 1D pyramidal multiresolution transform to the size
of the original signal.
{\bf
\begin{center}
     USAGE: mr1d\_pyrinterp, MR\_Trans
\end{center}}
where {\em MR\_Trans} is a pyramidal multiresolution transform.

\subsection{mr1d\_tabcoef}
Return the pre-computed table for noise behavior in the multiresolution
transform.
{\bf
\begin{center}
     USAGE: output =  mr1d\_tabcoef(TypeTransform)
\end{center}}
where {\em TypeTransform} is the type of multiresolution transform. Available
types are ``atrou", ``pyrmed" or ``pavemed". The output is a float array which
gives the standard deviation of the noise at each scale, when we apply
a multiresolution transform to a signal following a Gaussian distribution
with a standard deviation equal to 1.

\subsection{mr1d\_trans}
One-dimensional wavelet transform. 19 transforms are available
 (see \ref{sect_mr1dtrans}), which are grouped in 5 classes:
\bi
\item Class 1: no decimation (transform 1 to 7 and 11 to 14).
\item Class 2: pyramidal transform (transform 8 to 10).
\item Class 3: orthogonal transform (15 and 16).
\item Class 4: Wavelet packets (17 and 18).
\item Class 5: Wavelet packets from the \`a trous algorithm  (19).
\ei
Depending on the class, the transform does not contain the
same number of pixels, and the data representation differs.
{\bf
\begin{center}
     USAGE: MR1D\_Trans, Signal, Result, OPT=OPT, BAND=BAND, NODEL=NODEL
\end{center}}
where
\begin{itemize}
\item {\em Signal}: input one-dimensional IDL array.
\item {\em Result}: output IDL structure.
\item {\em Opt}: string which contains the different options
(see the {\em mr1d\_trans} C++  program).
\item {\em Band}: if set, a tag per band is created in the output structure.
\item {\em Nodel}: if set, the two created file are not deleted: \\
xx\_result.fits: wavelet coefficients file  \\
xx\_info.fits: information about the transform
\end{itemize}
{\em Result} is IDL structure which contains the wavelet transform.
The structure contains the following tags:
{\small
\bi
\item N\_BAND: float; number of bands in the transfrom
\item INFO: 2D float array (Array[2, NbrBand+3])
\begin{verbatim}
                       info[0,0] = transform number
                       info[1,0] = number of scales
                       info[0,1] = transform class number (5 classes)
                       info[1,1] = number of bands
                                 it is not equal to the number of scales
                                 for wavelet packets transform.
                       info[0,2] = number of pixels
                       info[1,2] = lifting scheme type
                       info[0,3] = type of filter
                       info[1,3] = type of normalization
                       for i=4 to Number_of_bands + 3
                       info[0,i] = number of pixels in the band i
                       info[1,i] = position number of the pixel of the band
		       If a user filter file is given (i.e. -T 6,filename),
                       with a filename of $L$ characters, $L$ lines are added
                       to the array:
                       info[1,Number_of_bands + 4] = number of characters of
                                                    the filter file name
                        for i=Number_of_bands+4 to  Number_of_bands+4+L-1
                             info[0,i] = ascii number of the ith character.
\end{verbatim}
If a user filter file is given (i.e. -T 6,filename), with a filename
of $L$ characters, $L$ lines are added to the array:
\begin{verbatim}
        info[1,Number_of_bands + 4] = number of characters of the filter file name
        for i=Number_of_bands+4 to  Number_of_bands+4+L-1
	info[0,i] = ascii number of the ith character.
\end{verbatim}
\item FROM: 1D array (NbrBand); position of the first pixel
\item TO: 1D array (NbrBand); position of the last pixel
\item COEF: 1D or 2D FLOAT array; wavelet coefficients
     for non-redundant transform (15,16,17), it is a 1D array \\
     for other transform, it is 2D array \\
     class 1 and 5: coeff[*,i] = band i (i in [0..NbrBand-1]) \\
     class 2: coeff[0:to[i],i] = band i \\
     class 3 and 4: coeff[from[i]:to[i]] = band i \\
\item Bandi: if BAND keyword is set, the array coef is also split
into bands:
\begin{verbatim}
            BAND1   : band 1
            BAND2   : band 2
                      ...
            BANDi   : band i
\end{verbatim}
\ei
}

\subsection{mr1d\_recons}
Reconstruct a one-dimensional signal from its wavelet transform.
{\bf
\begin{center}
     USAGE:  MR1D\_RECONS, WT\_Struct, result
\end{center}}
where
\begin{itemize}
\item {\em WT\_Struct}: input  IDL structure (obtained using IDL MR1D\_TRANS program)..
\item {\em Result}: output one-dimensional IDL array.
\end{itemize}

\subsection{mr1d\_filter}
Filter a 1D signal:
\begin{center}
     USAGE: mr1d\_filter, Signal, Result, Opt=Opt
\end{center}
where
\begin{itemize}
\item {\em Signal}: input  one-dimensional IDL array.
\item {\em Result}: output one-dimensional IDL array (filtered signal).
\item {\em Opt}:  string which contains the different options
(see the {\em mr1d\_filter} C++  program).
\end{itemize}

\section{Spectral Analysis}

\subsection{mr1d\_continuum}
Estimate the continuum of a 1D signal.
{\bf
\begin{center}
     USAGE: output = mr1d\_continuum(Signal, Nscale,Sigma=Sigma,median=median,mirror=mirror)
\end{center}}
where
\begin{itemize}
\item {\em Signal}: 1D IDL array. Input spectrum.
\item {\em Output}: 1D IDL array. Estimated continuum.
\item {\em Nscale}: number of scales.
\item {\em median}: if set  use multiresolution median transform
\item {\em mirror}: if set, use mirroring at borders.
\item {\em niter}: number of iterations. Default is 5.
\item {\em Sigma}: noise estimation (output keyword).
\end{itemize}

\subsection{mr1d\_optical\_depth}
Estimate the optical depth of a spectrum.
{\bf
\begin{center}
     USAGE: output = mr1d\_optical\_depth(Signal, Nscale, Sigma=Sigma)
\end{center}}
where
\begin{itemize}
\item {\em Signal}: 1D IDL array. Input spectrum.
\item {\em Output}: 1D IDL array. Estimated optical depth.
\item {\em Nscale}: number of scales.
\item {\em Sigma}: noise estimation (output keyword).
\end{itemize}

\subsection{mr1d\_detect}
{\bf
\begin{center}
     USAGE: mr1d\_detect, Signal, result, OPT=OPT, print=print, tabobj=tabobj,
    NbrObj=NbrObj, nodel=nodel, tabw=tabw
\end{center}}
where
\begin{itemize}
\item {\em Signal}: input signal.
\item {\em result}: output signal (sum of all detected objects).
\item {\em OPT}: string which contains the different options
(see the {\em mr1d\_detect} C++  program).
\item {\em print}: if set, information about each detected object is printed.
\item {\em tabobj}: IDL structure which contains the information about
the objects. For each object, we have
\begin{itemize}
\item NumObj: Object number
\item Pos: Position in the signal (in wavelength units).
\item Sigma: standard deviation of the band (in wavelength units).
\item Fwhm:  Full-width at half-maximum (in wavelength units).
\item PosPix: Position in the signal (in pixel units).
\item SigmaPix: standard deviation of the band (in pixel units).
\item Flux:  integrated flux of the band.
\end{itemize}
\item {\em NbrObj}: number of detected objects
\item {\em nodel}: if set, the created files
(by the {\em mr1d\_detect} C++ program)
are not deleted.
\item {\em tabw}:  wavelength array
\end{itemize}

\section{Multiresolution Routines (2D)}

\subsection{mr\_transform}
Computes a multiresolution transform of an image. If the
keyword {\em MR\_File\_Name} is set, a file is created
which contains the multiresolution transform. A multiresolution file
has a ``.mr" extension, and if the parameter file name does not
specify this, then
the extension is added to the file name. Result is stored in the {\em
DataTransf}.
Depending on the options, DataTransf can be a cube, an
image, or an IDL structure. This routine calls
the C++ executable {mr\_transform}.
The keyword ``OPT" allows to pass to the executable all
options described in section~\ref{sect_trans}.

{\bf
\begin{center}
  USAGE: mr\_transform, Data, DataTransf, MR\_File\_Name=MR\_File\_Name, OPT=Opt
\end{center}}
\subsubsection*{Examples:}
\begin{itemize}
\item mr\_transform, I, Output, MR\_File\_Name='result.mr' \\
Compute the multiresolution of the image {\em I} with default options
(i.e.\ \`a trous algorithm with 4 scales). The result is stored in
the file ``result.mr".
\item mr\_transform, I, Output, MR\_File\_Name='result\_pyr\_med',
OPT='-t 10 -n 5' \\
Compute the multiresolution of {\em I}  by using the pyramidal median
algorithm with 5 scales. The result is stored in the file
``result\_pyr\_med.mr".
\end{itemize}

\subsection{xmr\_transform}
Computes a multiresolution transform of an image. Parameters are
chosen through a widget interface. Creates a file which contains
the multiresolution transform of the image. The transform is made
by calling the routine mr\_transform. If there is an image parameter
the user doesn't need to load an image with the interface.
{\bf
\begin{center}
   USAGE: xmr\_transform, TransfData, input=input
\end{center}}
{\em TransfData} is the output transform, and {\em input} is the input
image.

\subsection{mr\_info}
Calculate statistical information about the wavelet transform
of an image. This routine calls
the C++ executable {mr\_info}.
The keyword ``OPT" allows to pass to the executable all
options described in section~\ref{sect_trans}.
The output is the 2D IDL array $T(*,0:4)$ with the following
syntax:
\begin{itemize}
\item  T(j,0) = standard deviation of the jth band
\item T(j,1) = skewness of the jth band
\item T(j,2) = kurtosis of the jth band
\item T(j,3) = minimum of the jth band
\item T(j,4) = maximum of the jth band
\end{itemize}

{\bf
\begin{center}
  USAGE: mr\_info, Data, TabStat, OPT=Opt, nodel=nodel, NameRes=NameRes
\end{center}}
\subsubsection*{Example:}
\begin{itemize}
\item mr\_info, I, Stat \\
Compute the multiresolution of the image {\em I} with default options
(i.e.\ \`a trous algorithm with 4 scales) and calculate statistical
information about each band.
\end{itemize}

\subsection{mr\_extract}
Extract a scale from a multiresolution transform. This routine
calls the C++ executable {mr\_extract}. The keyword ``OPT"
allows
all options described in
section~\ref{sect_extr}
to be passed to the executable.
{\bf
\begin{center}
   USAGE: mr\_extract, Multiresolution\_File\_Name, ScaleImage, OPT=Opt
\end{center}}
where {\em Multiresolution\_File\_Name} is a string which contain the
name of multiresolution file (``.mr"), and {\em ScaleImage} is the output
image (IDL 2D array).

\subsection{mr\_read}
Read a multiresolution file (extension ``.mr"). If the multiresolution
transform is a cube, the output is a three-dimensional array.
If it is an image the output is a two-dimensional IDL array.
If it is a pyramidal transform or a half-pyramidal transform,
we have 3 different outputs:
\begin{enumerate}
\item an image containing several subimages (flag raw set)
\item a cube of interpolated or rebinned images (flag interpol set)
\item a structure containing several subimages  (default)
\end{enumerate}
{\bf
\begin{center}
     USAGE: output = mr\_read(filename, interpol=interpol, raw=raw, debug=debug)
\end{center}}
where
\begin{itemize}
\item {\em filename}: string which contains the file name of
the multiresolution transform (extension ``.mr").
\item {\em interpol}: integer (for pyramidal transform only) \\
0: the output will not be interpolated \\
1: the output will be rebinned \\
2: the output will be interpolated \\
\item {\em raw}: if set the output overwrites the
input FITS file (for pyramidal transform only).
\item {\em debug}: if set, the routine is verbose
\end{itemize}

\subsection{mr\_compare}
Comparison between a reference image and an image or a sequence of images.
The comparison is carried out on the multiresolution scales.
If {\em Ima\_Or\_Cube} is a cube,
the processing is repeated on each image of the
cube (*,*,i).
For each image {ima\_i} of the cube {\em Ima\_Or\_Cube}
\begin{itemize}
\item  we compute the wavelet transform {\em WaveRef} of {\em ImaRef}
\item  we compute the wavelet transform {\em WaveIma} of {\em  ima\_i}
\item  we calculate the  correlation at each scale s: \\
if TabCorrel[s,i] = 1 then WaveRef[*,*,s] = WaveIma[*,*,s] are identical \\
else TabCorrel[s,i] is less than 1, and some differences exist.
\item  we calculate the  RMS at each scale:    \\
  TabRMS[s,i] = sigma( WaveRef[*,*,s] - WaveIma[*,*,s]])
\item  we calculate the normalized SNR at each scale (in dB): \\
  TabSNR[s,i] = 10 alog10 ( mean(WaveRef[*,*,s]\^2) \/ TabRMS[s,i]\^2)
\end{itemize}
This routine  calls the C++
executable {mr\_transform} described in section~\ref{sect_trans}.

{\bf
\begin{center}
     USAGE:  mr\_compare, ImaRef, Ima\_Or\_Cube, TabCorrel, TabRMS, TabSNR, Nscale=Nscale, plot=plot, title=title
\end{center}}
where
\begin{itemize}
\item {\em ImaRef}: IDL 2D array. Reference image.
\item {\em Ima\_Or\_Cube}:  IDL 2D or 3D array.  Image or sequence of images
to be compared.
\item {\em Nscale}: number of scales for the comparison
\item {\em plot}: if set, then plot the results
\item {\em title}:  is set, add the title to the plots
\item {\em TabCorrel}:  1D or 2D IDL array: output correlation table
\item {\em TabRMS}:  1D or 2D IDL array: output RMS table
\item {\em TabSNR}:  1D or 2D IDL array: output SNR table (in dB)
\end{itemize}
\subsubsection*{Example}
mr\_compare, imaref, ima1, tc, tr, ts, /plot, title='Comparison ImaRef-Ima1'\\
Comparison of the images {\em imaref} and {\em ima1}.

\subsection{mr\_background}
Estimate the background of an image.
{\bf
\begin{center}
     USAGE:  output=mr\_background(Image, nscale=nscale, border=border)
\end{center}}
If {\rm border} is set, the background is estimated from the border of
the image. If not, the pyramidal median transform is used with {\em nscale}
scales (default is 3) by calling the C++ executable {mr\_background} described in section~\ref{sect_bgr}.

\subsection{mr\_filter}
Filter  an image by using a multiresolution transform.
This routine is calling the C++ executable {mr\_filter}. The keyword
``OPT" allows
all options described in section~\ref{sect_filter}
to be passed to the executable.

{\bf
\begin{center}
     USAGE: mr\_filter, Data, FilterData, opt=opt
\end{center}}
{\em Data} is an image (2D IDL array), and {\em FilterData} is the result
of the filtering.

\subsection{im\_deconv}
Deconvolve an image by standard methods. This routine calls
the C++ executable {im\_deconv}. The keyword ``OPT"
allows
all options described in section~\ref{sect_deconv} to be passed
to the executable.

{\bf
\begin{center}
     USAGE: im\_deconv, Data, PSF, DeconvData, opt=opt
\end{center}}
\subsubsection*{Examples:}
\begin{itemize}
\item im\_deconv, Imag, Psf, Result \\
deconvolve an image with all default options (gradient method).
\item  im\_deconv, Imag, Psf, Result, OPT='-i 30 -e 0' \\
same example, but impose the number of iterations to be 30.
\item  im\_deconv, Imag, Psf, Result, OPT='-d 4 -i 30' \\
deconvolution by the one step gradient method, without
any regularization, with 30 iterations.
\end{itemize}

\subsection{mr\_deconv}
Deconvolve an image by using the multiresolution support. This routine calls
the C++ executable {mr\_deconv}. The keyword ``OPT"
allows
all options described in section~\ref{sect_deconv} to be passed
to the executable.

{\bf
\begin{center}
     USAGE: mr\_deconv, Data, PSF, DeconvData, opt=opt
\end{center}}
\subsubsection*{Examples:}
\begin{itemize}
\item mr\_deconv, Imag, Psf, Result \\
deconvolve an image with all default options (Richardson-Lucy method +
regularization in  wavelet space by using the \`a trous
algorithm, etc.).
\item  mr\_deconv, Imag, Psf, Result, OPT='-i 30 -e 0'  \\
same example, but impose the number of iterations to be 30.
\item  mr\_deconv, Imag, Psf, Result, OPT='-d 2 -i 30' \\
deconvolution by the one step gradient method, without
any regularization, with 30 iterations.
\end{itemize}

\subsection{mr\_detect}
Detect the sources in  an image by using a multiresolution transform.
This routine calls the C++ executable {mr\_detect}. The keyword ``OPT"
allows all options described in section~\ref{sect_detect}
to be passed to the executable.

{\bf
\begin{center}
     USAGE: mr\_detect, imag, result, OPT=OPT, print=print, tabobj=tabobj,
    NbrObj=NbrObj, nodel=nodel, RMS=RMS
\end{center}}
where
\begin{itemize}
\baselineskip=0.4truecm
\item {\em imag}: input image.
\item {\em result}: output image (sum of all detected objects).
\item {\em OPT}: option keyword.
\item {\em print}: if set, information about each detected object is printed.
\item {\em tabobj}: IDL structure which contains the information about
the objects. For each object, we have
\begin{itemize}
\baselineskip=0.4truecm
\item ScaleObj: scale where the object is detected.
\item NumObj: object number
\item PosX: X coordinate in the image.
\item PosY: Y coordinate in the image.
\item SigmaX: standard deviation on first main axis of the object.
\item SigmaY: standard deviation on second main axis of the object.
\item Angle: angle between the main axis and x-axis.
\item ValPixMax: value of the maximum of the object.
\item Flux: integrated flux of the object.
\item Magnitude: magnitude of the object.
\item ErrorFlux: flux error.
\item SNR\_ValMaxCoef: signal to noise ratio of the maximum of the wavelet
coefficient.
\item SNR\_Obj: signal to noise ratio of the object.
\item PosCoefMaxX: X coordinate  of the maximum wavelet coefficient
\item PosCoefMaxY: Y coordinate  of the maximum wavelet coefficient
\end{itemize}
\item {\em NbrObj}: number of detected objects
\item {\em nodel}: if set, the files created (by the program mr\_detect)
are not deleted.
\item {\em RMS}: RMS image related to the input image.
\end{itemize}
\subsubsection*{Examples:}
mr\_detect, imag, result, tabobj=tabobj, NbrObj=NbrObj \\
detects all sources with default options in the image {\em imag}. \\
print, NbrObj \\
print the number of objects. \\
print, tabobj(0).PosX, tabobj(0).PosY \\
print the coordinates of the first object. \\

\subsection{xlive}
XLIVE is a widget program for large image analysis. The large image
has to be compressed  by mr\_comp or mr\_lcomp before being
analyzed. Then the XLIVE data format is the MRC format.
When an MRC file is read, an image at very low resolution is displayed
and the user can improve the resolution of the image, or of a part
the image, using the RESOLUP button. When RESOLUP is called,
XLIVE reads from the MRC file the  wavelet coefficient needed for improving
the resolution.
If the large image has been compressed by block (-C option), only
the blocks needed are decompressed, and the image in memory has always
a size compatible with the window size.
The Dat parameter (if given) contains the last displayed image.
If it is not given, the user can however get it using the global
variable XIMA.

Several operations can be carried out by using the mouse and pressing buttons:
\begin{itemize}
\baselineskip=0.4truecm
\item QUIT: quit the application.
\item LOAD: load a FITS image.
\item LUT: modify the LUT.
\item PROFILE: examine rows or columns.
\item CURSOR: examine pixel values. If the image format is FITS and if
the header contains astrometric position, then the pixel
position in the sky is given (right ascension and declination).
\item HISTO: plot the histogram.
\item CONTOURS: contours of the image (isophotes).
\item 3D VISU: three-dimensional representation of the image.
\item INFO: print the min, max, mean, sigma of the image.
\item FFT: compute the Fourier transform and display either the power
spectrum, the phase, the real part or the imaginary part.
\item PAN: make a zoom. Zoom factors are 2,4,8,1/2,1/4,1/8
\item RESOLUP: Improve the image resolution. If the new image size is
greater than the window size, the user must click in the area
he/she wishes to see, and only this part of the image will be
decompressed.
\item RESOLDOWN: decrease the resolution.
\item RESOL: goto a given resolution.\end{itemize}
{\bf
\begin{center}
     USAGE: xlive, [Dat,], FILEName=FileName, WindowSize=WindowSize
\end{center}}
{\em Dat} is an output two-dimensional IDL array,
and {\em FileName} (string array)
is an optional parameter containing the MRC filename to be read.