% MARINA VON STEINKIRCH, SPRING/2013
% http://mysbfiles.stonybrook.edu/~mvonsteinkir/
\documentclass[11pt]{article}

\usepackage{epsfig}
\usepackage{color}
\usepackage{amsmath}    % Package  for subequations
\usepackage{graphicx}   % Package for figures
\usepackage{verbatim}   % Package  for program listings
\usepackage{hyperref}   % Package  for hypertext links, external documents and URLs
\usepackage{amssymb} % For mathematical constructions
\usepackage{latexsym} % Package to generate mathematical symbols
\usepackage{makeidx} % Package to generate an index in the end
\usepackage{float}

\newcommand{\ie}{{\it i.e., }}
\newcommand{\eg}{{\it e.g., }}

\title{CSE 590: Computational Photography\\  Homework \#3: Face Morphism }
\author{ \texttt{ Marina von Steinkirch, steinkirch@gmail.com}\\
	   \texttt{State University of New York at Stony Brook}}
\date{\today}

\begin{document}
\maketitle
\numberwithin{equation}{section}

\section{Introduction}

A {\it morph} is a simultaneous warp of the image shape and a cross-dissolve of the image colors. The warp is controlled by defining a correspondence between two pictures (\eg the map between eyes, mouths, etc.).

\quad

In this work we describe the technique to morph two face images using {\it Delaunay Triangulation} and we apply the method to compute a {\it mean face} for many face images. In addition, we further illustrate this technique on fun examples such as caricatures and the transformation of a face to a zombie.

\newpage

\section{Labeling Points in a Face Image}

To establish the connection between face images we label 43 corresponding points (\ie eye to eyes, month to month, etc) using a frame as a reference (\eg see Fig. \ref{pointslabel}). In MATLAB we can perform this task by two ways: using the function \texttt{cpselect()} or using the function \texttt{ginput()}. Both options return same results and precision (and are include in the  source code).

\quad

\begin{figure} [ht]
\begin{center}
\includegraphics[scale=0.3]{figs/pointlabels.jpg}
\includegraphics[scale=0.3]{figs/efros.jpg}
\includegraphics[scale=0.3]{figs/melabel.png}
\caption{Example of how to label/map points in the face images: the mapping and an example from  \cite{tamara} and how it worked for the image face.}
\label{pointslabel}
\end{center}
\end{figure}

\newpage

\section{Delaunay Triangulation}

With the labeled points from the previous step, we were able to apply the techniques of face morphism to two face images. For this purpose, we chose the triangulation method given by {\it Delaunay triangulation}, which  does not produce overly acute triangles.

\quad

The triangulation was computed to the {\it mean of the two point sets} (the midway shape) since they must be the same throughout the morph. Doing so in this fashion, we reduced the potential triangle deformations. Triangulation results are shown in the Fig. \ref{triang}.

\quad

\begin{figure} [ht]
\begin{center}
\includegraphics[scale=0.1]{figs/triang/1.jpg}
\includegraphics[scale=0.1]{figs/triang/3.jpg}
\includegraphics[scale=0.1]{figs/triang/5.jpg}
\includegraphics[scale=0.1]{figs/triang/6.jpg}
\includegraphics[scale=0.1]{figs/triang/7.jpg}
\includegraphics[scale=0.1]{figs/triang/9.jpg}
\caption{Delaunay triangulation for many of the intermediate steps during the face morphism process.}
\label{triang}
\end{center}
\end{figure}

\newpage

\section{Defining Correspondences and Warping Faces}

For each {\it morphed frame} we:

\begin{enumerate}
\item Interpolate geometry by weighted average of point locations;
\item Warp each image to the interpolated geometry by finding affine warps between triangles and doing affine projections on points;
\item Linearly blend warped images as a weighted average.
\end{enumerate}

\quad

As a result, we generate 60 intermediate frames that smoothly map the original face image to the final face image. The process is shown in the Fig. \ref{frames} and a video with the result can be seen at \cite{video-face}.

\begin{figure}[H]
\begin{center}

\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_01.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_02.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_03.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_04.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_05.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_06.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_07.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_08.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_09.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_10.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_11.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_12.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_13.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_14.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_15.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_16.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_17.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_18.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_19.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_20.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_21.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_22.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_23.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_24.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_25.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_26.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_27.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_28.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_29.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_30.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_31.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_32.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_33.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_34.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_35.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_36.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_37.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_38.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_39.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_40.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_41.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_42.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_43.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_44.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_45.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_46.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_47.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_48.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_49.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_50.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_51.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_52.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_53.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_54.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_55.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_56.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_57.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_58.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_59.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_60.jpg}
\includegraphics[scale=0.06]{figs/frames/morph_steinkirch_tangatur_61.jpg}

\caption{Face morphism: the initial and final images to be morphed and the 58 intermediate frames generate to morph them.}
\label{frames}
\end{center}
\end{figure}

\newpage

\section{Calculating the Mean Face}

Utilizing the previous techniques we calculate the mean face for the whole class. The result can be seen in the Fig. \ref{mean}.

\quad

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.4]{figs/mean.jpg}
\caption{Example of the mean face for many face images (class pictures).}
\label{mean}
\end{center}
\end{figure}

\newpage

\section{Fun Example: Caricatures of a Face Image}

The face morphism techniques can be use to produce fun results. As a first example, we utilize each of the face points mapping from the entire class to create caricatures for a unique face image. The results can be seen in the Fig. \ref{mean-me}.

\quad

Since the map of the other faces is not made as an exact caricature mapping but rather it is just a coincident characterization, some pictures exhibits artifacts (and some does not). The example here showed how to use many different mapping labels to the same picture, however to be able to reproduce specifics caricature features without producing any artifacts, the correct way would be to write a new mapping with coordinates modifications to only  the specific facial parts we want to exaggerate, \eg the nose or the eyes, etc. However this examples illustrate the point well.

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.17]{figs/caricatures/fun_02.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_03.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_04.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_15.jpg}

 \end{center}
\end{figure}
\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.17]{figs/caricatures/fun_05.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_06.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_07.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_08.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_09.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_10.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_11.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_12.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_13.jpg}
\includegraphics[scale=0.17]{figs/caricatures/fun_14.jpg}

\caption{Caricatures as examples of the face morphism techniques.}
\label{mean-me}
\end{center}
\end{figure}

\newpage

\section{Fun Example: Zombie Boyfriend}

Utilizing the above techniques for face morphism, we created a smooth transformation of a human face image to an image of  a monster (zombie). We see some small artifacts due the warping of the background and a way to overcome this problem is apply a final blender transformation. The intermediate results are shown in the Fig. \ref{zombie} and a final video of the result can be seen at \cite{video-zombie}.

\quad

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_01.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_02.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_03.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_04.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_05.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_06.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_07.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_08.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_09.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_10.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_11.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_12.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_13.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_14.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_15.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_16.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_17.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_18.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_19.jpg}
\includegraphics[scale=0.08]{figs/zombie/zombie_bf_20.jpg}
\caption{Face transformation to a monster as an example of the face morphism techniques.}
\label{zombie}
\end{center}
\end{figure}

\newpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%		Ref		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{thebibliography}{}

\bibitem{tamara}{\it Tamara Berg's Class}, {\it http://www.tamaraberg.com/teaching/Spring13/compphotog/3}

\bibitem{video-face} {\it Link to a video with the Face Morphism result}, {\texttt http://www.youtube.com/watch?v=sMtAMN6JLho}, 2013

\bibitem{video-zombie} {\it Link to a video with the Face Morphism example (zombie boyfriend)}, {\texttt http://www.youtube.com/watch?v=O5nBHLGvPs}, 2013

\end{thebibliography}

\end{document}


\chapter{List utilities}
\label{listutilities}

This chapter describes the \defrsixlibrary{lists} library, which
contains various useful procedures that operate on lists.

\begin{entry}{%
\proto{find}{ proc list}{procedure}}

\domain{\var{Proc} should accept one argument
  and return a single value.  \var{Proc} should not mutate \var{list}.}
The {\cf find} procedure applies \var{proc} to the elements of
\var{list} in order.  If \var{proc} returns a true value for an
element, {\cf find} immediately returns that element.  If \var{proc}
returns \schfalse{} for all elements of the list, {\cf find} returns
\schfalse{}.  \var{Proc} is always called in the same dynamic environment
as {\cf find} itself.

\begin{scheme}
(find even? '(3 1 4 1 5 9)) \ev 4
(find even? '(3 1 5 1 5 9)) \ev \schfalse{}
\end{scheme}

\implresp The implementation must check that \var{list} is a chain of
pairs up to the found element, or that it is indeed a list if no
element is found.  It should not check that it is a chain of pairs
beyond the found element.  The implementation must check the restrictions on
\var{proc} to the extent performed by applying it as described.
An
implementation may check whether \var{proc} is an appropriate argument
before applying it.
\end{entry}

\begin{entry}{%
\proto{for-all}{ proc \vari{list} \varii{list} \dotsfoo{} \varn{list}}{procedure}
\proto{exists}{ proc \vari{list} \varii{list} \dotsfoo{} \varn{list}}{procedure}}

\domain{The \var{list}s should all have the same length, and
  \var{proc} should accept $n$ arguments and
  return a single value.
  \var{Proc} should not mutate the \var{list} arguments.}

For natural numbers $i = 0, 1, \ldots$, the {\cf for-all} procedure
successively applies \var{proc} to arguments $x_i^1 \ldots x_i^n$,
where $x_i^j$ is the $i$th element of \varj{list}, until \schfalse{} is
returned.  If \var{proc} returns true values for all but the last
element of \vari{list}, {\cf for-all} performs a tail call of \var{proc}
on the $k$th elements, where $k$ is the length of \vari{list}.  If \var{proc}
returns \schfalse{} on any set of elements, {\cf for-all} returns
\schfalse{} after the first such application of \var{proc}.
If the \var{list}s are all empty, {\cf
  for-all} returns \schtrue.

For natural numbers $i = 0, 1, \ldots$, the {\cf exists} procedure
applies \var{proc} successively to arguments $x_i^1 \ldots x_i^n$,
where $x_i^j$ is the $i$th element of \varj{list}, until a true value is
returned.  If \var{proc} returns \schfalse{} for all but the last
elements of the \var{list}s, {\cf exists} performs a tail call of
\var{proc} on the $k$th elements, where $k$ is the length of
\vari{list}.
If \var{proc} returns a true value on any set of elements, {\cf
  exists} returns that value after the first such application of
\var{proc}.  If the \var{list}s
are all empty, {\cf exists} returns \schfalse.

\var{Proc} is always called in the same dynamic environment
as {\cf for-all} or, respectively, {\cf exists} itself.

\begin{scheme}
(for-all even? '(3 1 4 1 5 9)) \lev \schfalse{}
(for-all even? '(2 4 14)) \ev \schtrue{}
(for-all even? '(2 4 14 . 9)) \lev \exception{\cf\&assertion}
(for-all (lambda (n) (and (even? n) n))
         '(2 4 14)) \lev 14
(for-all < '(1 2 3) '(2 3 4)) \lev \schtrue{}
(for-all < '(1 2 4) '(2 3 4)) \lev \schfalse{}

(exists even? '(3 1 4 1 5 9)) \lev \schtrue{}
(exists even? '(3 1 1 5 9)) \ev \schfalse{}
(exists even? '(3 1 1 5 9 . 2)) \lev \exception{\cf\&assertion}
(exists (lambda (n) (and (even? n) n)) '(2 1 4 14)) \lev 2
(exists < '(1 2 4) '(2 3 4)) \ev \schtrue{}
(exists > '(1 2 3) '(2 3 4)) \ev \schfalse{}
\end{scheme}

\implresp The implementation must check that the \var{list}s are
chains of pairs to the extent necessary to determine the return value.
If this requires traversing the lists entirely, the implementation
should check that the \var{list}s all have the same length.  If not,
it should not check that the \var{list}s are chains of pairs beyond
the traversal.  The implementation must check the restrictions on
\var{proc} to the extent performed by applying it as described.
An
implementation may check whether \var{proc} is an appropriate argument
before applying it.
\end{entry}

\begin{entry}{%
\proto{filter}{ proc list}{procedure}
\proto{partition}{ proc list}{procedure}
}

\domain{\var{Proc} should accept one argument
  and return a single value. \var{Proc} should not mutate \var{list}.}

The {\cf filter} procedure applies
\var{proc} to each element of \var{list} and returns a list of
the elements of \var{list} for which \var{proc} returned a true
value.  The {\cf partition} procedure also applies \var{proc} to
each element of \var{list}, but returns two values, the first one a
list of the elements of \var{list} for which \var{proc} returned a
true value, and the second a list of the elements of \var{list} for
which \var{proc} returned \schfalse.
In both cases, the elements of the result list(s) are in the same
order as they appear in the input list.
\var{Proc} is always called in the same dynamic environment
as {\cf filter} or, respectively, {\cf partition} itself.
If multiple returns occur from {\cf filter} or {\cf partitions}, the return
values returned by earlier returns are not mutated.

\begin{scheme}
(filter even? '(3 1 4 1 5 9 2 6)) \lev (4 2 6)

(partition even? '(3 1 4 1 5 9 2 6)) \lev (4 2 6) (3 1 1 5 9) ; two values
\end{scheme}

\implresp The implementation must check the restrictions on \var{proc}
to the extent performed by applying it as described.
An
implementation may check whether \var{proc} is an appropriate argument
before applying it.
\end{entry}

\begin{entry}{%
\proto{fold-left}{ combine nil \vari{list} \varii{list} \dotsfoo \varn{list}}{procedure}}

\domain{The \var{list}s should all have the same
  length.  \var{Combine} must be a procedure.  It should accept one more
  argument than there are \var{list}s and return a single value.
  It should not mutate the \var{list} arguments.}
The {\cf fold-left} procedure iterates the \var{combine} procedure over an
accumulator value and the elements of the \var{list}s from left to
right, starting with an accumulator value of \var{nil}.  More
specifically, {\cf fold-left} returns \var{nil} if the \var{list}s are
empty.  If they are not empty, \var{combine} is first applied to
\var{nil} and the respective first elements of the \var{list}s in
order.  The result becomes the new accumulator value, and \var{combine}
is applied to the new accumulator value and the respective next elements
of the \var{list}.  This step is repeated until the end of the list is
reached; then the accumulator value is returned.
\var{Combine} is always called in the same dynamic environment
as {\cf fold-left} itself.

\begin{scheme}
(fold-left + 0 '(1 2 3 4 5)) \ev 15

(fold-left (lambda (a e) (cons e a)) '()
           '(1 2 3 4 5)) \lev (5 4 3 2 1)

(fold-left (lambda (count x)
             (if (odd? x) (+ count 1) count))
           0
           '(3 1 4 1 5 9 2 6 5 3)) \lev 7

(fold-left (lambda (max-len s)
             (max max-len (string-length s)))
           0
           '("longest" "long" "longer")) \lev 7

(fold-left cons '(q) '(a b c)) \lev ((((q) . a) . b) . c)

(fold-left + 0 '(1 2 3) '(4 5 6)) \lev 21
\end{scheme}

\implresp The implementation should check that the \var{list}s all
have the same length.  The implementation must check the restrictions
on \var{combine} to the extent performed by applying it as described.
An
implementation may check whether \var{combine} is an appropriate argument
before applying it.
\end{entry}

\begin{entry}{%
\proto{fold-right}{ combine nil \vari{list} \varii{list} \dotsfoo \varn{list}}{procedure}}

\domain{The \var{list}s should all have the same
  length.  \var{Combine} must be a procedure.  It should accept one more
  argument than there are \var{list}s and return a single value.
  \var{Combine} should not mutate the \var{list} arguments.}
The {\cf fold-right} procedure iterates the \var{combine} procedure over
the elements of the \var{list}s from right to left and an accumulator
value, starting with an accumulator value of \var{nil}.  More
specifically, {\cf fold-right} returns \var{nil} if the \var{list}s
are empty.  If they are not empty, \var{combine} is first applied to the
respective last elements of the \var{list}s in order and \var{nil}.
The result becomes the new accumulator value, and \var{combine} is
applied to the respective previous elements of the \var{list}s and the
new accumulator value.  This step is repeated until the beginning of the
list is reached; then the accumulator value is returned.
\var{Proc} is always called in the same dynamic environment
as {\cf fold-right} itself.

\begin{scheme}
(fold-right + 0 '(1 2 3 4 5)) \lev 15

(fold-right cons '() '(1 2 3 4 5)) \lev (1 2 3 4 5)

(fold-right (lambda (x l)
              (if (odd? x) (cons x l) l))
            '()
            '(3 1 4 1 5 9 2 6 5))
\ev (3 1 1 5 9 5)

(fold-right cons '(q) '(a b c)) \lev (a b c q)

(fold-right + 0 '(1 2 3) '(4 5 6)) \lev 21
\end{scheme}

\implresp The implementation should check that the \var{list}s all
have the same length.  The implementation must check the restrictions
on \var{combine} to the extent performed by applying it as described.
An
implementation may check whether \var{combine} is an appropriate argument
before applying it.
\end{entry}

\begin{entry}{%
\proto{remp}{ proc list}{procedure}
\proto{remove}{ obj list}{procedure}
\proto{remv}{ obj list}{procedure}
\proto{remq}{ obj list}{procedure}}

\domain{\var{Proc} should accept one argument
   and return a single value.
   \var{Proc} should not mutate \var{list}.}

Each of these procedures returns a list of the elements of \var{list}
that do not satisfy a given condition.  The {\cf remp} procedure
applies \var{proc} to each element of \var{list} and returns a
list of the elements of \var{list} for which \var{proc} returned
\schfalse.  \var{Proc} is always called in the same dynamic environment
as {\cf remp} itself.
The {\cf remove}, {\cf remv}, and {\cf remq} procedures return a list of
the elements that are not \var{obj}.  The {\cf remq} procedure uses {\cf eq?}\ to
compare \var{obj} with the elements of \var{list}, while {\cf remv}
uses {\cf eqv?}\ and {\cf remove} uses {\cf equal?}.
The elements of the result list are in the same
order as they appear in the input list.
If multiple returns occur from {\cf remp}, the return
values returned by earlier returns are not mutated.

\begin{scheme}
(remp even? '(3 1 4 1 5 9 2 6 5)) \lev (3 1 1 5 9 5)

(remove 1 '(3 1 4 1 5 9 2 6 5)) \lev (3 4 5 9 2 6 5)

(remv 1 '(3 1 4 1 5 9 2 6 5)) \lev (3 4 5 9 2 6 5)

(remq 'foo '(bar foo baz)) \ev (bar baz)
\end{scheme}

\implresp The implementation must check the restrictions on \var{proc}
to the extent performed by applying it as described.
An
implementation may check whether \var{proc} is an appropriate argument
before applying it.
\end{entry}

\begin{entry}{%
\proto{memp}{ proc list}{procedure}
\proto{member}{ obj list}{procedure}
\proto{memv}{ obj list}{procedure}
\proto{memq}{ obj list}{procedure}
}

\domain{\var{Proc} should accept one argument
  and return a single value.  \var{Proc} should not mutate \var{list}.}

These procedures return the first sublist of \var{list} whose car
satisfies a given condition, where the sublists of \var{lists} are the
lists returned by {\tt (list-tail \var{list} \var{k})} for
\var{k} less than the length of \var{list}.  The {\cf memp} procedure applies
\var{proc} to the cars of the sublists of \var{list} until it
finds one for which \var{proc} returns a true value.
\var{Proc} is always called in the same dynamic environment
as {\cf memp} itself.  The {\cf
  member}, {\cf memv}, and {\cf memq} procedures look for the first occurrence of
\var{obj}.  If \var{list} does not contain an element satisfying the
condition, then \schfalse{} (not the empty list) is returned.  The {\cf
  member} procedure uses {\cf equal?}\ to compare \var{obj} with the elements of
\var{list}, while {\cf memv} uses {\cf eqv?}\ and {\cf memq} uses
{\cf eq?}.

\begin{scheme}
(memp even? '(3 1 4 1 5 9 2 6 5)) \lev (4 1 5 9 2 6 5)

(memq 'a '(a b c))              \ev  (a b c)
(memq 'b '(a b c))              \ev  (b c)
(memq 'a '(b c d))              \ev  \schfalse
(memq (list 'a) '(b (a) c))     \ev  \schfalse
(member (list 'a)
        '(b (a) c))             \ev  ((a) c)
(memq 101 '(100 101 102))       \ev  \unspecified
(memv 101 '(100 101 102))       \ev  (101 102)%
\end{scheme}

\implresp The implementation must check that \var{list} is a chain of
pairs up to the found element, or that it is indeed a list if no
element is found.  It should not check that it is a chain of pairs
beyond the found element.  The implementation must check the restrictions on
\var{proc} to the extent performed by applying it as described.
An
implementation may check whether \var{proc} is an appropriate argument
before applying it.
\end{entry}

\begin{entry}{%
\proto{assp}{ proc alist}{procedure}
\proto{assoc}{ obj alist}{procedure}
\proto{assv}{ obj alist}{procedure}
\proto{assq}{ obj alist}{procedure}}

\domain{\var{Alist} (for ``association list'') should be a list of pairs.
  \var{Proc} should accept one argument
  and return a single value.  \var{Proc} should not mutate \var{alist}.}

These procedures find the first pair in \var{alist}
whose car field satisfies a given condition, and returns that pair
without traversing \var{alist} further.
If no pair in \var{alist} satisfies the condition, then \schfalse{}
is returned.  The {\cf assp} procedure successively applies
\var{proc} to the car fields of \var{alist} and looks for a pair
for which it returns a true value.
\var{Proc} is always called in the same dynamic environment
as {\cf assp} itself.  The {\cf assoc}, {\cf assv}, and {\cf
  assq} procedures look for a pair that has \var{obj} as its car.  The
{\cf assoc} procedure uses
{\cf equal?}\ to compare \var{obj} with the car fields of the pairs in
\var{alist}, while {\cf assv} uses {\cf eqv?}\ and {\cf assq} uses
{\cf eq?}.

\implresp The implementation must check that \var{alist} is a chain of
pairs containing pairs up to the found pair, or that it is indeed a
list of pairs if no element is found.  It should not check that it is
a chain of pairs beyond the found element.  The implementation must
check the restrictions on \var{proc} to the extent performed by
applying it as described.
An
implementation may check whether \var{proc} is an appropriate argument
before applying it.

\begin{scheme}
(define d '((3 a) (1 b) (4 c)))

(assp even? d) \ev (4 c)
(assp odd? d) \ev (3 a)

(define e '((a 1) (b 2) (c 3)))
(assq 'a e)     \ev  (a 1)
(assq 'b e)     \ev  (b 2)
(assq 'd e)     \ev  \schfalse
(assq (list 'a) '(((a)) ((b)) ((c))))
                \ev  \schfalse
(assoc (list 'a) '(((a)) ((b)) ((c))))
                           \ev  ((a))
(assq 5 '((2 3) (5 7) (11 13)))
                           \ev  \unspecified
(assv 5 '((2 3) (5 7) (11 13)))
                           \ev  (5 7)%
\end{scheme}

\end{entry}

\begin{entry}{%
\proto{cons*}{ \vari{obj} \dotsfoo{} \varn{obj} \var{obj}}{procedure}
\rproto{cons*}{ \var{obj}}{procedure}}

If called with at least two arguments, {\cf cons*} returns a freshly
allocated chain of pairs whose cars are \vari{obj}, \dotsfoo,
\varn{obj}, and whose last cdr is \var{obj}.  If called with only one
argument, {\cf cons*} returns that argument.

\begin{scheme}
(cons* 1 2 '(3 4 5)) \ev (1 2 3 4 5)
(cons* 1 2 3) \ev (1 2 . 3)
(cons* 1) \ev 1%
\end{scheme}

\end{entry}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "r6rs-lib"
%%% End:


%% This file is part of the DiffractionMicroscopy project
%% Copyright 2016 David W. Hogg

% To-Do list
% ----------
% - Generalize to photons on the Ewald sphere.
% - Write zeroth draft.
% - Deal with all HOGG notes.

% Style notes
% -----------
% - Always eqnarray never equation.

\documentclass[12pt]{article}
\usepackage{amsmath, amssymb, mathrsfs, hyperref, graphicx}
\input{vc}

% useless formatting
\linespread{1.08333} % 10/13 spacing
\setlength{\parindent}{1.08333\baselineskip}
\setlength{\parskip}{0ex}
\newcommand{\hoggcaption}[1]{\caption{\textsf{#1}}}
\renewcommand{\thefigure}{\textsf{\arabic{figure}}}
\renewcommand{\figurename}{\textsf{Figure}}
\newcommand{\equationname}{equation}

% math definitions
\newcommand{\setof}[1]{\left\{{#1}\right\}}
\newcommand{\given}{\,|\,}
\newcommand{\dd}{\mathrm{d}}

\begin{document}\sloppy\sloppypar

\section*{\raggedright%
  Derivatives of the likelihood function (with respect to parameters)
  for diffraction microscopy with noisy images at unknown orientations.}
\noindent
David W. Hogg

\noindent{\footnotesize%
Simons Center for Data Analysis, Simons Foundation\\
\texttt{david.hogg@nyu.edu}\\
repository: \texttt{\giturl}\\
hash: \texttt{\githash~(\gitdate)}}

\bigskip

\paragraph{Abstract:}
I write down a likelihood for diffraction microscopy imaging data,
where each image is of the same molecule, but each image contains a
small number of photons, and each image is of the molecule at an
unknown, random orientation.
In this work, at fixed orientation, the likelihood function is
parameterized by linear parameters (densities in three-dimensional
boxels in real space, or Fourier coefficients, or any other linear
representation), but the likelihood function becomes non-linear in
those parameters when the orientation is marginalized out.
Marginalization is performed by a sum over a (random or uniform)
sampling in orientation space.

\section{Introduction}

In diffraction imaging, the fundamental observable is the squared norm
of a slice of the Fourier transform of the object of interest.
In the noisy regime---but when the orientation of the sample in the
beam is known---the detected photons are independent draws from a
variable-rate Poisson process, with rate set by the squared norm of
the relevant slice of the Fourier transform (probably censored by a
beam stop).
When the orientation of the sample in the beam is unknown, the group
of detected photons can no longer be thought of as being independent
draws from a simple process.
While being conditionally independent given the orientation, they are
dependent when the orientation is thought of as an unobserved latent
variable.
This emerges because the orientation controls the slice, and the slice
controls the rate function for the Poisson process; the various
photons in a single image or exposure are generated by the same slice,
but the plane of the slice is not known.

For the purposes of definiteness, we will think of the real-space
object as being described by a density $\rho(x)$, where $x$ is
a three-vector position in real space (units of length).
This density has a Fourier transform $\hat{\rho}(k)$, where the hat
indicates the Fourier transform, and $k$ is a three-vector wave number
(units of inverse length).

We will make use of various properties of the density $\rho(x)$ and of
its Fourier transform $\hat{\rho}(k)$:
One might be that the density $\rho(x)$ has compact support---is
non-zero in a finite domain---which makes the Fourier transform
$\hat{\rho}(k)$ smooth in some corresponding way.
Another is that the density $\rho(x)$ will be real, which makes
$\hat{\rho}(k)$ symmetric in the sense of
$\hat{\rho}(k)=\hat{\rho}(-k)$.
Another might be that the density $\rho(x)$ is non-negative everywhere
(this will often---but not always---be true).
Non-negativity in real space has non-trivial implications for Fourier
space.

\section{Likelihood function}

For us, a probabilistic \emph{model} is a likelihood function (a
probability for the data given parameters) and a prior pdf over (at
least) any nuisance parameters.
This requires that we obtain a parameterization for (either) the
density $\rho(x)$ (or its Fourier transform or some function of
either).
Because our objective is to obtain a description of the real-space
function $\rho(x)$, we will parameterize this function simply as a
linear mixture of $M$ components
\begin{eqnarray}
       \rho(x)  &=& \sum_{m=1}^M a_m\,     g_m(x)
  \\
  \hat{\rho}(k) &=& \sum_{m=1}^M a_m\,\hat{g}_m(k)
\quad ,
\end{eqnarray}
where the $a_m$ are coefficients, the $g_m(x)$ are real-space basis
functions that linearly sum to make the density, and the
$\hat{g}_m(k)$ are the Fourier transforms of those basis functions.

Photons will be observed at transverse wave numbers $k_\perp$, in the
lab in the two-dimensional $k$-space perpendicular to the x-ray beam,
which itself is oriented at angles $\phi$ relative to the molecule.
That is, there is a 2-vector $k_\perp$ that is related to the full
3-vector $k$ by a projection and some rotations, which depend on a set
of three Euler angles, which we denote (as a set) $\phi$.
The three Euler angles can be thought of as a position on the sphere
plus an in-plane rotation.
Or they can be thought of as the three degrees of freedom of
orientation of a two-dimensional lab-frame $k_\perp$ coordinate system
with respect to a three-dimensional molecule-frame $k$ coordinate
system.
The relationship can be written as
\begin{eqnarray}
  k &=& P_\phi \cdot k_\perp
  \quad ,
\end{eqnarray}
where we think of $k$ as a three-element column vector, $P_\phi$ is a
$3\times 2$ deprojection matrix made up of two orthogonal unit
3-vectors (which are fully specified by the Euler angles $\phi$), and
$k_\perp$ is a two-element column vector.

If you set the density function $\rho(x)$ (and thus its Fourier
transform $\hat{\rho}(k)$) and the orientation $\phi$ of the molecule
with respect to the beam, the probability density of getting a photon
at observed lab-frame transverse wave number $k_\perp$ is proportional
to the squared norm of the Fourier transform evaluated at the relevant
$k$.  That is,
\begin{eqnarray}
  p(k_\perp\given\rho,\phi) &\propto& |\hat{\rho}|^2(P_\phi \cdot k_\perp)
  \label{eq:rhosquared} \\
  |\hat{\rho}|^2(k) &\equiv& \hat{\rho}(k)\,\hat{\rho}^{\ast}(k)
  \\
  |\hat{\rho}|^2(k) &=& \sum_{m=1}^M\sum_{m'=1}^M a_m\,a_{m'}\,\hat{g}_m(k)\,\hat{g}_{m'}^{\ast}(k)
  \label{eq:rhosquaredexpansion} \quad ,
\end{eqnarray}
where we have written the squared norm as the complex number times its
complex conjugate, but used the fact that the $a_m$ are real.

The fact that equation~(\ref{eq:rhosquared}) contains nothing more
complicated than a deprojection matrix (no integrals) is a consequence
of the Fourier slice theoem.
Equation~(\ref{eq:rhosquared}) embodies the fundamental fact of
diffraction: The observable is the square of the norm of the Fourier
transform.
This formulation also assumes that there is a ``beam stop'' or
equivalent: The probability density in equation~(\ref{eq:rhosquared})
only describes diffracted photons, not those (the majority)
transmitted without deflection.

HOGG: Need a terminology for the parameters and the data.
\begin{eqnarray}
  y &\equiv& \setof{y_n}_{n=1}^N
  \\
  y_n &\equiv& \setof{k_{\perp nq}}_{q=1}^{Q_n}
  \\
  a &\equiv& \setof{a_m}_{m=1}^M
  \quad,
\end{eqnarray}

HOGG: Marginalization.
\begin{eqnarray}
  \ln p(y\given a) &=& \sum_{n=1}^N \ln p(y_n\given a)
  \\
  p(y_n\given a) &=& \int p(y_n\given a,\phi)\,p(\phi)\,\dd\phi
  \\
  &\approx& \frac{1}{T}\,\sum_{t=1}^T p(y_n\given a,\phi_t)
  \\
  \ln p(y_n\given a) &\approx& \ln\left[\frac{1}{T}\,\sum_{t=1}^T \exp\left[\ln p(y_n\given a,\phi_t)\right]\right]
  \\
  \ln p(y_n\given a,\phi_t) &=& \sum_{q=1}^{Q_n} \ln p(k_{\perp nq}\given a,\phi_t)
  \\
  &=& \sum_{q=1}^{Q_n} \ln |\hat{\rho}|^2(P_{\phi_t}\cdot k_{\perp nq})
  \\
  &=& \sum_{q=1}^{Q_n} \ln\left[ \sum_{m=1}^M\sum_{m'=1}^M a_m\,a_{m'}\,\hat{g}_{ntqm}\,\hat{g}_{ntqm'}^{\ast} \right]
  \\
  \hat{g}_{ntqm} &\equiv& \hat{g}_m(P_{\phi_t}\cdot k_{\perp nq})
  \quad,
\end{eqnarray}
where...HOGG..., and we
have dropped constants in the logarithms.

HOGG: Implementation as logsumexp.

\section{Derivatives}

\begin{eqnarray}
  \frac{\dd}{\dd a_m}\ln p(y\given a) &=& \sum_{n=1}^N \frac{\dd}{\dd a_m}\ln p(y_n\given a)
  \\
  \frac{\dd}{\dd a_m}\ln p(y_n\given a)
    &=& \frac{\displaystyle
      \frac{1}{T}\,\sum_{t=1}^T \exp\left[\ln p(y_n\given a,\phi_t)\right]\,\frac{\dd}{\dd a_m}\ln p(y_n\given a,\phi_t)}%
             {\displaystyle
      \frac{1}{T}\,\sum_{t=1}^T \exp\left[\ln p(y_n\given a,\phi_t)\right]}
  \\
  \frac{\dd}{\dd a_m}\ln p(y_n\given a,\phi_t)
    &=& \sum_{q=1}^{Q_n} \frac{\displaystyle
      \sum_{m'=1}^M a_{m'}\,\left[\hat{g}_{ntqm}\,\hat{g}_{ntqm'}^{\ast}+\hat{g}_{ntqm'}\,\hat{g}_{ntqm}^{\ast}\right]}%
             {\displaystyle
      \sum_{m''=1}^M\sum_{m'=1}^M a_{m''}\,a_{m'}\,\hat{g}_{ntqm''}\,\hat{g}_{ntqm'}^{\ast}}
  \quad,
\end{eqnarray}
where...HOGG

\section{Priors or regularization}

This model is great! But it has the problem that the likelihood
increases without bound as the $|a_m|$ increase.
So we will have to add a Poisson-like penalty $G$ of a form
something like
\begin{eqnarray}
  G &=& -\sum_{m=1}^M a_m^2
  \\
  \frac{\dd}{\dd a_m} G &=& -2\,a_m
\end{eqnarray}
to the log-likelihoood and its gradient.

There are also various other degeneracies, such as rotation and
flip symmetries.
These could also be removed by penalizing the likelihood function
lightly...HOGG?

\section{Tangent space}

A (probably faulty) counting argument suggests that the
observable---the squared norm $|\hat{\rho}(x)\,\hat{\rho}^{\ast}(x)|$
of the Fourier transform of the density---has fewer degrees of freedom
than the real-space density $\rho(x)$.
If this is true, at any location in parameter space HOGG there might
be directions HOGG in parameter space in which we can move
(infinitesimally) and not change the observable (to linear order).
These vectors (or the subspace they span) might be useful for
optimization or parameter-space search.

\paragraph{acknowledgements:}
It is a pleasure to thank
  Charlie Epstein (Penn),
  Leslie Greengard (SCDA),
  Jeremy Magland (SCDA),
  and
  Marina Spivak (SCDA)
for valuable discussions (and patience!).

\end{document}


\documentclass[../../main]{subfiles}
\pagestyle{fancy}

\begin{document}

\chapter{Inner model direction}
\thispagestyle{fancy}

\section{Determinacy in mice from DI}

\prop[Folklore?][prop.mousereflection]{
  If $\omega_1$ carries a saturated ideal then mouse reflection holds at $\omega_1$.
}
\proof{
  Let $\N$ be a mouse operator defined on $\hc$ and fix some $x\in H_{\omega_2}$; we want to show that $\N(x)$ is defined. Let $j:V\to M$ be the generic ultrapower with $\crit j=\omega_1^V$ and note that $j(\omega_1^V)=\omega_1^M=\omega_1^{V[g]}=\omega_2^V$ by saturation of the ideal. This means in particular that $\hc\prec H_{\omega_2}^M$. Since
  \eq{
    \hc\models\godel{\text{$\N(y)$ exists for all sets $y$}}
  }

  we get that $H_{\omega_2}^M$ believes the same is true. But $H_{\omega_2}^V\subset H_{\omega_2}^M$ since $\crit j=\omega_1^V$, so that in particular $H_{\omega_2}^M$ believes that $x^\sharp$ exists. Since $M$ is closed under $\omega$-sequences in $V[g]$ by Proposition \ref{prop.ideal}, we get that $x^\sharp$ exists in $V[g]$ and hence also in $V$ as set forcing can't add sharps.\todo{Prove this or give a reference.}
}

\prop[Folklore?][prop.sharps]{
  If $\omega_1$ carries a precipitous ideal then $\hc$ is closed under sharps. If the ideal is furthermore saturated then $H_{\omega_2}$ is closed under sharps.
}
\proof{
  Proposition \ref{prop.mousereflection} gives the latter statement if we show the former, so fix an $x\in\hc$ and let $j:V\to M$ be the generic ultrapower from a precipitous ideal on $\omega_1^V$. Since $j(x)=x$ we get that $j:L[x]\to L[x]$ with $\crit j>\rk x$, implying that $x^\sharp$ exists in the generic extension. But set forcing can't add sharps \todo{Add argument or reference.} so $x^\sharp$ exists in $V$ as well.
}

\defi{
  Let $j:V\to M$ be an elementary embedding in some $V[g]$ and let $F$ be a model operator. Then $F$ is \textbf{$j$-radiant} if it condenses well, determines itself on generic extensions and satisfies the \textbf{extension property}, which says that $F\subset j(F)$ and $j(F)\restr\hc^{V[g]}$ is definable in $V[g]$.
}

\lemm[$\di$][lemm.m1f]{
  $M_1^F$ is total on $H_{\omega_2}$ for any $j$-radiant model operator $F$ on $H_{\omega_2}$.
}
\proof{
  We want to use the hybrid core model dichotomy \ref{theo.kdichotomy}, but the problem is that $F$ is not total. We solve this by going to a smaller model; the model $W:=L^F_{\omega_2^V}(\mathbb R)$ will be a first attempt (note that $\mathbb R\in\dom F$ as we're assuming $\ch$). To be able to apply the dichotomy in a model we need it to satisfy $\zfc$. The following claim is the first step towards this.

  \clai{
    Given any real $x$, $L^F_{\omega_2}(x)\models\godel{\text{$\omega_1^V$ is inaccessible}}$.
  }

  \cproof{
    Letting $j:V\to M$ be the generic elementary embedding, note that $j$ doesn't move $x$, so that
    \eq{
      j\restr L^F_{\omega_2^V}(x):L^F_{\omega_2^V}(x)\to L^{j(F)}_{\omega_2^M}(x).
    }
  Since $F$ has the extension property, $L^{j(F)}_{\omega_2^M}(x)$ is just an end-extension of $L^F_{\omega_2^V}(x)$. In particular $\omega_1^V$ is still a cardinal in there, meaning that, for every $\alpha<\omega_1^V$,
    \eq{
      L_{\omega_1^M}^{j(F)}(x)\models\godel{\text{there's a cardinal $>\alpha$}}.
    }

    By elementarity this makes $\omega_1^V$ a limit cardinal in $L^F_{\omega_2^V}(x)$ and by $\gch$ in $L^F_{\omega_2^V}(x)$ it's inaccessible.
  }

  This claim is now transferred to $M$, and as $\mathbb R^V$ is a real from the point of view of $M$, we get that
  \eq{
    L^{j(F)}_{\omega_2^M}(\mathbb R^V)\models\godel{\text{$\omega_1^M$ is inaccessible}}.
  }

  Noting that $\omega_1^M=\omega_2^V$ and again using the extension property of $F$, we get that $W\models\zf$. We don't get choice in $W$ as it doesn't contain a wellorder of the reals, so we we'll work with $W[h]$ instead, where $h\subset\col(\omega_1,\mathbb R)^W$ is $W$-generic. Since we're assuming $\ch$ we get that $g\in V$, making $W[h]\in V$ as well, $W[h]$ is still closed under $F$ since $F$ determines itself on generic extensions, and $W[h]\models\zfc$.

  \qquad We can now apply the hybrid core model dichotomy \ref{theo.kdichotomy} inside $W[h]$ to conclude that, for every real $x$, either $K^F(x)^{W[h]}$ exists or $M_1^F(x)$ exists (note that $(\omega_1,\omega_1)$-iterability is absolute between $W[h]$ and $V$ since $W[h]$ contains all the reals). Since mouse reflection holds at $\omega_1$ by Proposition \ref{prop.mousereflection} if the latter conclusion held at all reals $x$ then we would also get that $M_1^F$ is total on $H_{\omega_2}$ and we'd be done. So assume $K:=K^F(x)^{W[h]}$ exists.

  \clai{
    $j(K)\in V$.
  }

  \cproof{
    This is where we'll be using homogeneity of our ideal. Firstly $K$ is definable in $W[h]$ and thus also in $W$ by homogeneity of $\col(\omega_1,\mathbb R)$, so that $j(K)$ is definable in $j(W)$. But $j(W)$ is definable in $V[g]$ as the unique $j(F)$-premouse over $\mathbb R$ of height $\omega_1$, making $j(K)$ definable in $V[g]$ with $j(F)\restr\hc$ as a parameter. But $j(F)\restr\hc$ is definable in $V[g]$ since $F$ satisfies the extension property, so homogeneity of our ideal implies that $j(F)\in V$ and hence $j(K)\in V$ as well.
}

  This claim also implies that $\omega_1^V$ is inaccessible in $K$, as if it wasn't, say $\omega_1^V=\lambda^{+K}$, then $\omega_2^V=j(\omega_1^V)=j(\lambda)^{+j(K)}=\lambda^{+j(K)}$, so that $\omega_2^V$ isn't a cardinal in $V$, $\contr$.

  \qquad We then also get that $(\omega_1^V)^{+j(K)}<\omega_2^V$, since if they were equal then elementarity would imply that $\omega_1^V$ was a successor in $K$, $\contr$.

  \qquad Since $K|\omega_1^V=j(K)|\omega_1^V$, elementarity and the above implies that
  \eq{
    j^2(K)|(\omega_1^V)^{+j^2(K)}=j(K)|(\omega_1^V)^{+j(K)},
  }

  which makes sense as $j(K)\in V$.

  \qquad Let now $E$ be the $(\omega_1^V,\omega_2^V)$-extender derived from $j\restr j(K)$, and note that $E\restr\alpha\in M$ for every $\alpha<\omega_2^V=\omega_1^M$ as $M$ is closed under countable sequences in $V[g]$.

  \clai{
    $E\restr\alpha$ is on the $j(K)$-sequence for every $\alpha<\omega_2^V$.
  }

  \cproof{
    We need to show \todo{Why is this sufficient?} that
    \eq{
      j(W)\models\godel{\text{$\bra{\bra{j(K),\ult(j(K),E\restr\alpha)}, \alpha}$ is $\on$-iterable}}.
    }

    Assume not. Then by reflection \todo{What kind of reflection?} we get, in $j(W)$, a countable $\overline K$ and an elementary $\sigma:\overline K\to\ult(j(K),E\restr\alpha)$ with $\sigma\restr\alpha=\id$ and $\bra{\bra{j(K),\overline K},\alpha}$ isn't $\omega_1$-iterable.

    \qquad Let $k:\ult(j(K),E\restr\alpha)\to j^2(K)$ be the factor map with $k\restr\alpha=\id$ and define $\psi:=k\circ\sigma:\overline K\to j^2(K)$, so that $(k\circ\sigma)\restr\alpha=\id$. We have both $\psi$ and $\overline K$ in $M$, which is the generic ultrapower $\ult(V,g)$, so we also get that $\psi=[\vec\psi_\xi]_g$, $\overline K=[\vec K_\xi]_g$ and $\alpha=[\vec\alpha_\xi]_g$. We need to show that
    \eq{
      \text{For $g$-almost every $\xi<\omega_1^V$ it holds that }W\models\godel{\text{$\bra{\bra{K,K_\xi},\alpha_\xi}$ is $\omega_1$-iterable}}
    }

    By \L o\' s' Lemma we have that, in $V$ and hence also in $V[g]$, there are embeddings $\psi_\xi:K_\xi\to j(K)$ with $\psi_\xi\restr\alpha_\xi=\id$ for $g$-almost every $\xi<\omega_1^V$. As $j(W)$ is closed under countable sequences in $V[g]$ it sees that the $K_\xi$'s are countable, so that an application of absoluteness of wellfoundedness \todo{Include this argument perhaps.} shows that $j(W)$ also has elementary embeddings $\psi^*_\xi:K_\xi\to j(K)$ with $\psi^*_\xi\restr\alpha_\xi$.

    \qquad But $j(K)=K^{j(F)}(x)^{j(W[h])}$, so $j(W[h])$ sees that $\bra{\bra{K,K_\xi},\alpha_\xi}$ is $\omega_1$-iterable, which is therefore also true in $W$ since $W\cap\mathbb R\subset\mathbb R^{V[g]}=j(W[h])\cap\mathbb R$.
  }

  Our desired contradiction is then showing that $K$ has a Shelah cardinal, which is impossible\todo{Insert argument?}. Let $f:\omega_1^V\to\omega_1^V$ be a function in $j(K)$ and pick some $\alpha\in(j(f)(\kappa),\omega_2^V)$. Letting
  \eq{
    k:\ult(j(K),E\restr\alpha)\to j^2(K)
  }

  be the factor map, we get that $\crit k\geq\alpha$ by coherence of extenders on the $K$-sequence and hence that $i_{E\restr\alpha}(f)(\omega_1^V)<\alpha$ as well. This shows that $\omega_1^V$ is Shelah in $j(K)$ and hence $K$ has a Shelah cardinal by elementarity, $\contr$.
}

\theo[$\di$][theo.internalinduction]{
  $\lp^{\Gamma,\Sigma}(\mathbb R)\models\ad$ for all ``nice'' $\Gamma$ and $\Sigma$.\todo{Specify niceness.}
}
\proof{
  \todo[inline]{Show that all the operators occuring in the $\lp^{\Gamma,\Sigma}(\mathbb R)$ induction are $j$-radiant.}
}

\section{$\Omega$ is not zero}

\todo[inline]{Collapse all these $\Omega$ sections into one, where the abstract results are moved into the internal/external CMI chapters}

Define
\eq{
  \Gamma_0:=\{A\subset\mathbb R\mid L(A,\mathbb R)\models\ad+\Omega=0\}.
}

\lemm[$\di$][lemm.lpcontainsgammainfty]{
  $\Gamma_0=\lp(\mathbb R)\cap\p(\mathbb R)$.
}
\proof{
  $(\supset)$ Let $\M\pinit\lp(\mathbb R)$ and let $A\subset\mathbb R$ be an element of $\M$. Since $\M$ projects to $\mathbb R$ and is sound, we get that $A$ is $\od_x$ for a real $x$, so that everything in $L(A,\mathbb R)$ is also ordinal definable in a real as well. Since $\lp(\mathbb R)\models\ad$ we then get that $\ad+\Omega=0$ holds in $L(A,\mathbb R)$, making $A\in\Gamma_0$.\todo{Check this proof.}

  \qquad $(\subset)$ Let $A\in\Gamma_0$. Since we're assuming $\ch$ we get that $V[g]\models|\mathbb R|=\aleph_1^V=\aleph_0$, so fix a generic bijection $b:\omega\to\mathbb R^V$ in $V[g]$. Define $a_b\in\mathbb R$ as $n\in a_b$ iff $b(n)\in A$. As $L(A,\mathbb R)\models\ad+\theta_0=\Theta$ it holds that $A$ is $\od_z^{L(A,\mathbb R)}$ for $z\in\mathbb R$, so that
  \eq{
    A=j(A)\cap\mathbb R^V\in\od^{L(j(A),\mathbb R^{V[g]})}_{z,\mathbb R^V}.
  }

  In particular, as $A$ and $\mathbb R^V$ are definable from $b$ and $a_b$ is definable from $b$, we get that $a_b\in\od^{L(j(A),\mathbb R^{V[g]})}_b$. By $\mc$ we then get that there's some $b$-premouse $\M\in L(j(A),\mathbb R^{V[g]})$ projecting to $b$ with $a_b\in\M$ and a $\Sigma$ such that
  \eq{
    L(j(A),\mathbb R^{V[g]})\models\godel{\text{$\Sigma$ is an $\omega_1$-iteration strategy for $\M$}}.
  }

  \todo[inline]{Why is it that we have to go through $b$ in this fashion? Can't we just use $\mc$ and get $\N$ without going through $\M$? Is it because $L(j(A),\mathbb R^{V[g]})$ doesn't know that $\mathbb R^V$ is countable?}

  From this $\M$ we can then get an $\mathbb R^V$-premouse $\N\in L(j(A),\mathbb R^{V[g]})$ projecting to $\mathbb R^V$ with $A\in\N$ and
  \eq{
    L(j(A),\mathbb R^{V[g]})\models\godel{\text{$\Sigma$ is an $\omega_1$-iteration strategy for $\N$}}.
  }

  Now $\N$ is $\od^{L(j(A),\mathbb R^{V[g]})}_{\mathbb R^V}$, and since we don't have divergent models of $\ad^+$ it holds that, letting $\Theta^{j(A)}:=\Theta^{L(j(A),\mathbb R^{V[g]})}$,
  \eq{
    V[g]\models L(j(A),\mathbb R)=L(P_{\Theta^{j(A)}}(\mathbb R)).
  }

  This means that $\N\in\od^{V[g]}_{\mathbb R^V}$, so that homogeneity of $I$ we get that $\N\in V$. It remains to show that $\N\init\lp(\mathbb R^V)$, meaning that we need to show that $\N$ is countably $(\omega_1+1)$-iterable in $V$. But letting $\overline\N\to\N$ be a countable hull in $V$ we get that $j(\overline\N)=\overline\N$, so that elementarity of $j$ implies that $\Sigma\restr V\in V$ \todo{Why's this?} is an $\omega_1^{V[g]}=\omega_2^V$-iteration strategy for $\overline\N$ \todo{Is this really this iterable?} and we're done.
}

\prop[$\di$]{
  $\cof^V(\Theta^{\lp(\mathbb R)})=\omega$.
}
\proof{
  \todo[inline]{See Ketchersid`s Thesis 3.17 or 7.4.2 in the CMI book. Perhaps we don't need it though, following Wilson's thesis.}
}

\theo{
  Let $\Gamma$ be an inductive-like pointclass. If $\M$ is a suitable quasi-iterable premouse, $\A\in[\env(\Gamma)]^\omega$ is closed under recursive join and the $\A$-guided map $\pi_{\M,\infty}^{\A}$ is both total on $\M$ and has the full factors property, then there's a unique $\Gamma$-fullness preserving $(\omega_1,\omega_1)$-strategy $\Phi$ for $\M$ such that, for every quasi-iterate $\P$ of $\M$,
  \begin{itemize}
    \item $\P$ is a non-dropping $\Phi$-iterate of $\M$; and
    \item the $\Phi$-iteration map $i:\M\to\P$ equals the $\A$-guided map $\pi_{\M,\P}^{\A}$.
  \end{itemize}
}

Let $\Phi_{\M}$ be the unique strategy for $\M$ as in the above theorem. We now improve this to include branch condensation.

\todo[inline]{The 3d argument is quite similar to the proof of Theorem 7.19 in the outline.}

\begin{figure}
  \pix[0.8]{\string~/gitsky/phd/gfx/trangs_pic.png}
  \caption{The three-dimensional argument in Theorem \ref{theo.3d}}
  \label{fig.3d}
\end{figure}

\theo[][theo.3d]{
  Let $\Gamma$ be an inductive-like pointclass and assume that ${\bf\Delta}_\Gamma$ is determined and that $\Gamma$-$\mc$ holds. Let $\M$ be an $\omega$-suitable quasi-iterable premouse such that $\D(\M)\equiv\M_\Gamma$\todo{This is the companion of $\Gamma$, see Trevor's thesis. I'm not sure if we can find $\M$ like this, however.}, let $\A\in[\env(\Gamma)]^\omega$ be closed under recursive join, assume $\pi_{\M,\infty}^{\A}$ is total on $\M$ and that it has the full factors property. Let $\Phi:=\Phi_{\M}$. Then there's a $(\T,\P)\in\iterates(\M,\Phi)$ such that $\Phi_{\U,\Q}$ has $\A$-condensation, and hence also branch condensation, for every $(\U,\Q)\in\iterates(\P,\Phi_{\T,\P})$.
}
\proof{
  Assume not and fix $A\in\env(\Gamma)$ such that given any $(\T,\P)\in\iterates(\M,\Phi)$ there's a $(\U,\Q)\in\iterates(\P,\Phi_{\T,\P})$ such that $\Phi_{\U,\Q}$ doesn't have $A$-condensation. Applying this inductively, we get a sequences $\bra{\Q^0_n,\R^0_n,\T^0_n,\pi^0_n,\sigma^0_n,j^0_n\mid n<\omega}$ such that
  \begin{enumerate}
    \item $\Q^0_0:=\M$;
    \item $\pi^0_n:\Q^0_n\to\Q^0_{n+1}$ is the iteration map through a tree of successor length, according to $\Phi$;
    \item $\sigma^0_n:\Q^0_n\to\R^0_n$ an iteration map through a tree of limit length, according to $\Phi$;
    \item $j^0_n:\R^0_n\to\Q^0_{n+1}$ is elementary such that $\pi^0_n=j^0_n\circ\sigma^0_n$;
    \item $(j^0_n)^{-1}(\tau^{\Q^0_{n+1}}_{A,j^0_n(\kappa)})\neq\tau^{\R^0_n}_{A,\kappa}$ for every $\R^0_n$-cardinal $\kappa\geq\delta_0^{\R^0_n}$.\\
  \end{enumerate}

  Let $\Q^0_\omega$ be the direct limit of the $\Q^0_n$'s under the $\pi^0_n$ maps. Also let $\bra{x_n\mid n<\omega}$ enumerate the reals of $\M_\Gamma$ and pick $s\in[\on]^{<\omega}$ and a formula $\varphi$ such that
  \eq{
    \forall x\in\mathbb R(x\in A\Leftrightarrow\M_\Gamma\models\varphi[x,s]).
  }

  Our strategy now is now firstly to capture all the $x_n$'s so that the derived models of the resulting structures become equal to $\M_\Gamma$. See Figure \ref{fig.3d}.

  \qquad Perform a genericity iteration of $\Q^0_0$ above $\delta_0^{\Q^0_0}$ to $\Q^1_0$ to make $x_0$ generic over $\Q^1_0$ at $\delta_1^{\Q^1_0}$, while lifting the genericity iteration tree via the copy construction to the $\Q^0_n$'s and $\R^0_n$'s, and picking branches on the genericity iteration tree on $\Q^0_0$ by using $\Phi_{\Q^0_\omega}$ on the lifted tree on $\Q^0_\omega$. Let $\tau^0_0:\Q^0_0\to\Q^1_0$ be the genericity iteration map and $\W_0$ the last model of the lifted tree on $\Q^0_\omega$.

  \qquad Now perform another genericity iteration of the last model of the lifted iteration tree on $\R^0_0$ above its $\delta_0$ to $\R^1_0$ to make $x_0$ generic over $\R^1_0$ at $\delta_1^{\R^1_0}$, with branches being picked by lifting the iteration tree to $\W_0$ and using the branches according to $\Phi_{\W_0}$. Let $k^0_0:\R^0_0\to\R^1_0$ be the iteration embedding, $\sigma^1_0:\Q^1_0\to\R^1_0$ be the shift of $\sigma^0_0$ followed by latter genericity iteration, and $\W_1$ the last model of the lifted tree on $\W_0$.

  \qquad Do a third genericity iteration of the last model of the lifted stack on $\Q^0_1$ above its $\delta_0$ to $\Q^1_1$ to make $x_0$ generic at $\delta_1^{\Q^1_1}$, with branches being picked by lifting the tree to $\W_1$ and using branches picked by $\Phi_{\W_1}$. Let $\tau^0_1:\Q^0_1\to\Q^1_1$ be the iteration embedding, $j^1_0:\Q^1_0\to\R^1_1$ be the natural map, and $\pi^1_0:=j^1_0\circ\sigma^1_0$.

  \qquad Now continue this process to make $x_0$ generic over the $\Q^0_n$'s and $\R^0_n$'s, and let $\Q^1_\omega$ be the direct limit of the $\Q^1_n$'s under the $\pi^1_n$ maps. Then start at $\Q^1_0$ and repeat the same thing to make $x_1$ generic at the respective $\delta_2$'s and so on. Let $\Q^\omega_i$ be the direct limit of the $\Q^n_i$'s under the $\tau^n_i$ maps, $\R^\omega_i$ the direct limit of the $\R^n_i$'s under the $k^n_i$ maps and $\Q^n_\omega$ the direct limit of the $\Q^n_i$'s under the $\pi^n_i$ maps.

  \qquad By construction we get that the $\pi^0_n$'s and $\tau^n_\omega$'s are all by $\Phi$ and its tails, and that $\Q^\omega_\omega$ is wellfounded and $\lp^\Gamma$-full, so that the $\Q^\omega_n$'s and the $\R^\omega_n$'s are also wellfounded and $\lp^\Gamma$-full.

  \clai{
    \label{clai.fix_s}
    There exists some $k<\omega$ such that $\pi^\omega_n$ fixes $s$ for every $n\geq k$.
  }

  \begin{figure}
    \pix[0.5]{\string~/gitsky/phd/gfx/fix_s.png}
    \caption{The argument in Claim \ref{clai.fix_s}.}
    \label{fig.fix_s}
  \end{figure}

  \cproof{
    It suffices to show that $(\pi^{\omega}_{n}(\xi) \mid n < \omega)$ is eventually constant for all $\xi \in s$. Suppose this isn`t the case. Fix $\xi \in s$ and a strictly increasing sequence $(i_{n} \mid n < \omega)$ such that $\pi^{\omega}_{i_{n}}(\xi) > \xi$ for all $n < \omega$. For $m < n < \omega$ we then have
    \eq{
      \pi^{\omega}_{i_{m}, \infty}(\xi) = \pi^{\omega}_{i_{n}, \infty} \circ \pi^{\omega}_{i_{m}, i_{n}}(\xi) \ge \pi^{\omega}_{i_{n}, \infty} \circ \pi^{\omega}_{i_{m}}(\xi) > \pi^{\omega}_{i_{n},\infty}(\xi),
    }

    so that $(\pi^{\omega}_{i_{n}}(\xi) \mid n < \omega)$ is a strictly decreasing sequence of ordinals in $\mathcal{Q}^{\omega}_{\omega}$ -- contradicting its wellfoundedness.  See \autoref{fig.fix_s}.
  }

  Let $k<\omega$ be as in the claim, and note that the $j^\omega_n$'s also fix $s$ for $n\geq k$. Since $\D(\R^\omega_n)=\M_\Gamma$ for every $n<\omega$, the $\Q^\omega_n$'s and the $\R^\omega_n$'s have uniform definitions for the term relations for $A$ when $n\geq k$, yielding that $j^\omega_n$ pulls back the term relation correctly whenever $n\geq k$, $\contr$.
}

\theo[$\di^+$]{
  $\lp(\mathbb R)\models\godel{\text{there's a fullness preserving hod pair below $\omega_1$}}$.
}
\proof{
  \todo[inline]{Show the above requirements in Wilson's theorem is satisfied? Double check the statement.}
}

\theo[$\di^+$]{
  There is a model $M$ containing all the reals such that $M\models\ad^{+}+\theta_0<\Theta$.
}
\proof{
  \todo[inline]{Let $(\M,\Sigma)$ be a fullness preserving hod pair in $\lp(\mathbb R)$ given by the above theorem. Then $\Sigma\notin\lp(\mathbb R)$ by the proof of 7.4.3 in the CMI book, and in particular $\Sigma\notin\Gamma_0$. Then $M:=L(\Sigma,\mathbb R)$ is the wanted model.}
}

\section{$\Omega$ is not a successor}

\defi{
  Let $(\P,\Sigma)$ and $(\Q,\Lambda)$ be hod pairs below $\omega_1$. We then say that $(\Q,\Lambda)$ \textbf{extends} $(\P,\Sigma)$, or is an \textbf{extension} of $(\P,\Sigma)$, if there exists some $\alpha<\lambda^{\Q}$ such that
  \begin{enumerate}
    \item $\Q(\alpha)\in pI(\P,\Sigma)$; and
    \item $\Sigma_{\Q(\alpha)}=\Lambda_{\Q(\alpha)}$.
  \end{enumerate}

  We say that $(\P,\Sigma)$ \textbf{can be extended} if there exists an extension of $(\P,\Sigma)$.
}

\theo[$\di^+$]{
  Every hod pair below $\omega_1$ can be extended.
}

Rough steps in the proof:
\begin{enumerate}
  \item Show that $M_1^{\sharp,\Sigma}$ exists
  \item $\lp^\Sigma(\mathbb R)\models\ad^+$ for some appropriate definition of $\lp^\Sigma(\mathbb R)$
  \item The $\Omega>0$ argument should show that there's an $A\notin\lp^\Sigma(\mathbb R)$ such that $L(A,\mathbb R)\models\ad^+$ and $\Sigma <_W A$
  \item Show $L(A,\mathbb R)$ then has the desired $(\Q,\Lambda)$ (this step has already been done and can be black boxed)
\end{enumerate}

\section{$\Omega$ does not have countable cofinality}
\lipsum[1]

\section{$\Omega$ is not singular}

\theo[$\di^+$]{
  Assume there exists a sequence of hod pairs $(\P_\alpha,\Sigma_\alpha)$ below $\omega_1$ with $(\P_{\alpha+1},\Sigma_{\alpha+1})$ extending $(\P_\alpha,\Sigma_\alpha)$ for every $\alpha$. Then either
  \begin{enumerate}
    \item There exists a hod pair $(\h,\Lambda)$ below $\omega_1$ such that $\lambda^{\h}=\sup_\alpha\lambda^{\P_\alpha}$; or
    \item There exists an $\M$ containing all the reals such that $\M\models\ad_{\mathbb R}+\Theta\text{ is regular}$.
  \end{enumerate}
}

Rough steps in the proof:
\begin{enumerate}
  \item Do the easier countable cofinality case

  \item Coiterate all the hod pairs to some $(\P,\Sigma)$, which has $\lambda:=\lambda^{\P}=\sup_\alpha\lambda^{\P_\alpha}$

  \item If $\lambda$ has non-measurable cofinality then $(\P,\Sigma)$ is the hod pair that we're looking for, so assume this is not the case

  \item Take the derived model $\D(\P,\lambda)$, which then satisfies $\ad_{\mathbb R}+\dc+\Omega=\lambda$, where $\dc$ is because $\lambda$ has uncountable cofinality

  \todo[inline]{This is wrong, as we can't take this derived model. Instead we should form a directed system of all ``nice'' hod pairs having $\lambda$'s below $\lambda^{\P}$ and take the $\lp$-closure of that, which should then be an initial segment of hod; call it $\h$.}

  \item Show that $\h|\delta^{\h}$ is the union of $M_\infty^\alpha$ for $\alpha<\lambda$, where $M_\infty^\alpha$ is the hod limit of
    \eq{
      \F_\alpha:=\{(\Q,\Psi)\mid\ult(V,g)\models\godel{\text{$(\Q,\Psi)$ is a hod pair and $\lambda^{\Q}=\alpha$}}\}.\footnote{This makes sense because every $M_\infty^\alpha$ is an initial segment of $\h$.}
    }

    Let $\Phi$ be the join of the strategies of the $M_\infty^\alpha$'s and show that $\h=\lp^\Phi_\omega(\h|\delta^{\h})$.

  \item Show that $\h\models\godel{\text{$\delta^{\h}$ is singular}}$, since otherwise $\D(\h,\delta^{\h})\models\ad_{\mathbb R}+\Theta\text{ is regular}$ and we're done.

  \item We want to construct a strategy $\Lambda$ for $\h$ such that $(\h,\Lambda)$ is a hod pair below $\omega_1$, as then this is the hod pair that we're looking for.
\end{enumerate}

\defi{
  Let $(\mathcal{P}, \Sigma)$ be a hod pair. We let
  \begin{enumerate}
    \item $\iterates(\mathcal{P}, \Sigma) := \{ (\vec{\mathcal{T}}, \mathcal{Q}) \mid \vec{\mathcal{T}} \text{ is a stack on } \mathcal{P} \text{ via } \Sigma \text{ with last model } \mathcal{Q} \text{ such that } \pi^{\vec{\mathcal{T}}} \text{exists} \}$ be the collection of \textbf{$(\mathcal{P}, \Sigma)$-iterates},
    \item $\piterates(\mathcal{P}, \Sigma) := \{ \mathcal{Q} \mid (\vec{\mathcal{T}}, \mathcal{Q}) \in \iterates(\mathcal{P}, \Sigma) \text{ for some } \vec{\mathcal{T}} \}$
    \item $\blowups(\mathcal{P}, \Sigma) := \{ (\mathcal{T}, \mathcal{M}) \mid \mathcal{M} \lhod \mathcal{Q} \text{ and } (\vec{\mathcal{T}}, \mathcal{Q}) \in \iterates(\mathcal{P}, \Sigma) \}$ be the collection of \textbf{$(\mathcal{P}, \Sigma)$-blowups} and \item $\pblowups(\mathcal{P}, \Sigma) := \{ \mathcal{Q} \mid (\vec{\mathcal{T}}, \mathcal{Q}) \in \blowups(\mathcal{P}, \Sigma) \text{ for some } \vec{\mathcal{T}} \}$.
  \end{enumerate}
}

\defi{
  Let $(\mathcal{P}, \Sigma)$ be a hod pair and $\Gamma$ is a pointclass closed under Boolean operations and continuous images and preimages. Then $\Sigma$ is \textbf{$\Gamma$-fullness preserving} if for all $(\vec{\mathcal{T}}, \mathcal{Q}) \in I(\mathcal{P}, \Sigma)$, $\alpha + 1 \le \lambda^{\mathcal{Q}}$ and $\delta_{\alpha}^{\mathcal{Q}} < \eta$ which is a strong cutpoint of $\mathcal{Q}(\alpha+1)$ we have
  \begin{enumerate}
    \item $\mathcal{Q} | \eta^{+ \mathcal{Q}(\alpha + 1)} = \lp^{\Gamma, \Sigma_{\mathcal{Q}(\alpha), \vec{\mathcal{T}}}}(\mathcal{Q} | \eta)$ and
    \item $\mathcal{Q} | \delta_{\alpha}^{+ \mathcal{Q}} = \lp^{\Gamma, \oplus_{\beta < \alpha} \Sigma_{\mathcal{Q}(\beta+1)}, \vec{\mathcal{T}}}(\mathcal{Q}(\alpha))$.
  \end{enumerate}

  $\Sigma$ is \textbf{fullness preserving} iff it is $\mathcal{P}(\mathbb{R})$-fullness preserving.

  \todo[inline]{Provide a motivation for this definition.}
}

\lemm{
  \todo[inline]{This will be useful in the proof of the $A$-condensing lemma.}
  Let $M,N$ be transitive models of $\zfc^{-}$ with largest cardinals $\delta^{M}, \delta^{N}$ respectively. Let $\pi \colon M \to N$ be an elementary embedding, $\kappa := \crit(\pi)$ and let $E$ be the long $(\kappa, \delta^{N})$-extender derived from $\pi$. Then $N = \ult(M; E)$ and $\pi = \pi_{E}$ is the canonical ultrapower embedding.
}
\proofretard{
  We have the following commutative diagram

  \begin{center}
    % Feel free to replace this with a cd diagram instead
    \begin{tikzcd}[row sep=large, column sep=large]
      M \arrow[rrdd, "\pi_{E}"] \arrow[rr, "\pi"] & & N \\ & & \\ & & \ult(M;E) \arrow[uu, "k"]
    \end{tikzcd}
  \end{center}

  where $k$ satisfies $k \restriction \delta^{N} = \id$.  Let $\delta^{\ult(M; E)}$ be the largest cardinal of $\ult(M;E)$. By elementarity $k(\delta^{\ult(M;E)}) = \delta^{N}$, so that $\delta^{\ult(M;E)} \le \delta^{N}$. If $\delta^{\ult(M;E)} < \delta^{N}$, then $k \restriction \delta^{N} = \id$ yields $k(\delta^{\ult(M;E)}) = \delta^{\ult(M;E)} < \delta^{N}$, which is absurd. Hence $\delta^{\ult(M;E)} = \delta^{N}$ and $k \restriction (\delta^{\ult(M;E)} + 1) = \id$. Since $\delta^{\ult(M;E)}$ is the largest cardinal of $\ult(M;E)$, it follows that $k$ doesn`t have a critical point. Therefore $k = \id$, $N = \ult(M;E)$ and $\pi = \pi_{E}$. $\qed$
}

\begin{figure}
  \centering
  \begin{tikzcd}[row sep=large, column sep=large] & & j(\h) \\ & & \\
      \h \arrow[rr, "\pi"] \arrow[uurr, "j"] & & \R \arrow[uu, "\tau"]
    \end{tikzcd}
  \caption{Full Factors Property}
  \label{fig:full factors property}
\end{figure}

\lemm{
  \label{lemm.ff}
  $j\restr\h$ has the \textbf{full factors property}\footnote{This terminology was introduced in \cite{Wilson}; in \cite{GrigorUB} this was called \textit{weak condensation}.}, meaning that whenever $\R$ \todo[inline]{$R$ has to be countable in $V[g]$. How can we ensure that, as this only gives that it has size $\leq\aleph_1$? Do we have to resort to the (long) claim in Grigor's uB paper?} is a hod premouse and there are elementary embeddings $\pi:\h\to\R$ and $\tau:\R\to j(\h)$ such that $j\restr\h=\tau\circ\pi$, then $\R$ is $\Sigma^2_1(j(\Omega)^\tau)$-full.
}
\proofretard{
  Let $\Psi:=j(\Omega)^\tau$ and assume the lemma fails, meaning that we have a hod mouse $\R$ and elementary embeddings $\pi:\h\to\R$ and $\tau:\R\to j(\h)$ such that $j\restr\h=\tau\circ\pi$ and $\R\neq\lp_\omega^{\Psi}(\R|\delta^{\R})$, witnessed without loss of generality by an $\M\init\lp^{\Psi}(\R|\delta^{\R})$ such that $\rho(\M)=\delta^{\R}$ and which is not an initial segment of $\R$.
  \cd{
    (\h,\Omega) \ar[rr]^\pi \ar[drr]_{j\restr\h} && (\R,\Psi) \ar[d]^\tau \\ && (j(\h),j(\Omega))
  }

  We can then fix some hod pair $(\S^*,\Lambda^*)$ such that $\tau``\R|\delta^{\R}\subset\ran(\pi_{\S^*, \infty}^{\Lambda^*})$, and furthermore let $\xi\leq\lambda^{\S^*}$ be least such that $\tau``\R|\delta^{\R}\subset\ran(\pi_{\S^*(\xi), \infty}^{\Lambda^*})$. Lastly let $(\S,\Lambda)$ be an extension of $(\S^*,\Lambda^*)$ such that $\lambda^{\S}$ is a limit ordinal.

  \todo[inline]{Argue why $\S^*$ and $\S$ exist; we should be in the limit case to argue that $\S$ exists.}

  \qquad Let $\sigma:\R|\delta^{\R}\to\S|\delta_\gamma^{\S}$, where $\S^*(\xi)$ iterates to $\S(\gamma)$, be given by $\sigma(x)=y$ iff $\tau(x)=\pi^{\Lambda}_{\S(\gamma),\infty}(y)$.
  \cd{
    (\R|\delta^{\R}, \Psi) \ar[rr]^\tau \ar[dr]_\sigma && (j(\h)|\delta^{j(\h)}, j(\Omega))\\ & (S|\delta_\gamma^{\S}, \bigoplus_{\beta<\gamma}\Lambda_{\S(\beta)}) \ar[ur]_{\pi^\Lambda_{\S(\gamma),\infty}}
  }

  We can fix some hod pair $(\S',\Lambda')$ such that\todo{This should follow from generation of good pointclasses.}
  \eq{
    L(\Lambda',\mathbb R)\models\godel{\text{$\M$ is a $\Psi$-mouse}}.
  }

  By coiterating \todo{This requires us to work in an $\ad^+$ model, so we better assume that somewhere.} $\S$ and $\S'$ we may assume without loss of generality that $\S=\S'$.

  \clai{
    There exists a hod pair $(\Q,\Phi)$ such that $\lambda^{\Q}$ is a limit ordinal and $L(\Gamma(\Q,\Phi),\mathbb R)\models\godel{\text{$\M$ is a $\Psi$-mouse}}$.
  }

  \cproof{
    \todo[inline]{This claim shouldn't be needed, as we should be able to take $\Q$ to be $\S$ in our case, using facts about the $\Gamma$-pointclasses. Also ensure that $\Q\supset\h$, which is possible as we're stretching by $j$.}
  }

  Fix $(\Q,\Phi)$ as in the claim and let $\N$ be some mouse such that $\M\pinit\N$ and $\N$ has $\omega$ many Woodins on top of $\M$.

  \todo[inline]{Explain how this is done. In Grigor's paper he's using that ``$j(\eta)$ is closed under hybrid $\N_\omega$-operators''. In our measurable cofinality case there might be enough room to get this. Postpone until later, when we have an idea of how much operator closure we have at this point.}

  Then we get that

  \todo[inline]{Why is $\Gamma(\Q,\Phi)$ in $\D(\N)$?}

  \eq{
    \D(\N)\models\godel{L(\Gamma(\Q,\Phi),\mathbb R)\models\godel{\text{$\M$ is a $\Psi$-mouse which isn't an initial segment of $\R$}}}.
  }

  Now throw everything in sight into a countable hull\todo{In $V[g]$, I guess.}, so that
  \eq{
    \D(\overline{\N})\models\godel{L(\Gamma(\overline{\Q},\overline{\Phi}),\mathbb R)\models\godel{\text{$\M$ is a $\overline{\Psi}$-mouse which isn't an initial segment of $\R$}}}.
  }

  \todo[inline]{I think that now $\overline\Q$ are taking the role of ``$L[\T,\h]$'', as Grigor's paper seems to indicate that $\h\subset\overline\Q$.}

  Now lift $\pi$ to the ultrapower map $\pi^+$ given by the $(\delta^{\h},\delta^{\R})$-extender over $\overline\Q$ derived from $\pi$, and let $\R^+$ be the ultrapower. Lift also $\sigma,\tau$ to corresponding $\sigma^+,\tau^+$.\todo{A it hand-wavy.}
  \cd{
    (\overline{\Q}, \overline{\Phi}) \ar[rr]^{\pi^+} \ar[drr]_{\sigma^+} && (\R^+, \Phi^{**}) \ar[d]^{\tau^+}\\ && (j(\overline\Q), \Phi^*)
  }

  \qquad Let now $\Phi^*:=j(\overline{\Phi})$ and $\Phi^{**}:=(\Phi^*)^{\tau^+}$, which is then a strategy for $\R^+$. Since $\overline\Phi=(\Phi^{**})^{\pi^+}$\todo{Check this --- might be by definition of pullback consistency, which is implied by hull condensation.} we get that

  \todo[inline]{In Grigor's uB paper he uses a certain derived model $C$ instead of $\D(\overline\N)$, but I can't see how they're different from each other. Also, figure out why the following inclusion is true (it's probably folklore).}

  \eq{
    \D(\overline\N)\subset\D(\R^+,\Phi^{**}),
  }

  implying that\todo{Note sure what's going on here.}
  \eq{
    L(\Gamma(\R^+,\Phi^{**}),\mathbb R)\models\godel{\text{$\M$ is a $\Psi$-mouse which isn't an initial segment of $\R$}}.
  }

  Because $\R^+$ is a $\Psi$-mouse over $\R|\delta^{\R}$, it follows that\todo{Why's that?}
  \eq{
    \D(\R^+)\models\godel{\text{$\M$ is a $\Psi$-mouse which isn't an initial segment of $\R$}},
  }

  which then implies that $\M\in\R^+$, so that $\M\init\R$, a contradiction.\todo{I don't see how this last argument works.}$\qed$
}

\defi{
  For every $X\in\P_{\omega_1}(j(\h))$ define $Q_X:=\chull^{j(\h)}(X)$ and let
  \eq{
    \tau_X \colon Q_X\to j(\h)
  }

  be the uncollapse.

  Say that $Y\in\P_{\omega_1}(j(\h)|\delta^{j(\h)})$ \textbf{extends} $X$ if $X\cap j(\delta^{\h})\subset Y$ and in that case let
  \begin{enumerate}
    \item $\tau_{X, Y}:=\tau_{X \cup Y}$,
    \item $\Phi_{X,Y}:=j(\Phi)^{\tau_{X,Y}}$,
    \item $Q_{X,Y}:=Q_{X\cup Y}$ and
    \item $\pi_{X,Y} \colon Q_X\to Q_{X,Y}$ is the induced embedding given by
      \eq{
        \pi_{X,Y}(x) = \tau_{Y}^{-1}(\tau_{X}(x)).
      }
    % I don`t think we need $\pi_{X,Y,Z}$ but I will leave it here for
    % now, so we can add it back easily
    % \item $\pi_{X,Y,Z}:Q_{X,Y}\to Q_{X,Z}$ is the induced embedding for
    %   $Z \in \P_{\omega_1}(j(\h)|\delta^{j(\h)})$ extending $X \cup Y$.
  \end{enumerate}

  Furthermore define $T_{X}(A)$ for $A \in Q_X\cap\P(\delta^{Q_X})$ as
  \eq{
    T_{X}(A) :&= \{ (\varphi,s) \mid \text{$\varphi$ is a formula, $s\in[\delta^{Q_{X}}]^{<\omega}$ and $Q_X\models\varphi[s,A]$} \} \\ &= \{ (\varphi,s) \mid \text{$\varphi$ is a formula, $s\in[\delta^{Q_{X}}]^{<\omega}$ and $j(\h)\models\varphi[\tau_X(s),\tau_X(A)]$}\}
  }

  and let $T_{X,Y}(A)$ be given as
  \eq{
    T_{X,Y}(A) := \{ (\varphi,s) \mid & \ \text{$\varphi$ is a formula, $s\in[\delta^{Q_{X,Y}}]^{<\omega}$ and $j(\h)\models\varphi[\pi^{\Phi_{X,Y}}_{Q_{X,Y}(\alpha),\infty}(s),\tau_X(A)]$}, \\ & \ \text{where $\alpha$ is least such that $s \in [\delta_\alpha^{Q_{X,Y}}]^{<\omega}$}\}.
  }

  Here $\pi^{\Phi_{X,Y}}_{Q_{X,Y}(\alpha),\infty}:Q_{X,Y}\to j(\h)|\nu_{X,Y}$ \todo{What is $\nu_{X,Y}$?} is given by

  \todo[inline]{Missing! (It will be the iteration into an appropriate level of the directed system leading up to $j(\h)$ followed by the direct limit embedding into some initial segment of $j(\h)$)}
}

\defi{
  Let $X\in\P_{\omega_1}(j(\h))$ and $A\in Q_X\cap\P(\delta^{Q_X})$. Then $X$ is \textbf{$A$-condensing} if $\pi_{X,Y}(T_{X}(A))=T_{X,Y}(A)$ for every $Y$ extending $X$.
  We say that $X$ is \textbf{condensing} if $X$ is $A$-condensing for all such $A$.
}

We want to show that $j``\h$ is condensing. We first show that it suffices to show that it's $\alpha$-condensing for every $\alpha<\delta^{\h}$.

\lemm{
  If $j``\h$ is $\alpha$-condensing for every $\alpha<\delta^{\h}$ then $j``\h$ is condensing.
}
\proof{
  \todo[inline]{Missing!}
}

\theo{
  For every $\alpha<\delta^{\h}$ there exists an extension $Y$ of $j``\h$ such that $j``\h\cup Y$ is $\alpha$-condensing.\todo{Reduce this to $j``\h$ somehow?}
}
\proof{
  Set $X:=j``\h$ and assume the theorem fails. Fix some $\alpha<\delta^{\h}$ such that $X$ is not $\alpha$-condensing. Fix some $Y_0$ extending $X$ which witnesses this, meaning that $\pi^X_{Y_0}(T^X_\alpha)\neq T^{X,Y_0}_\alpha$. Since we're also assuming that $\tau^X_{Y_0}$ isn't $\alpha$-condensing we can find $Y_1$ extending $Y_0$ such that $\pi^{Y_0}_{Y_1}(T^{Y_0}_\alpha)\neq T^{Y_0,Y_1}_\alpha$. Continue doing this, generating a sequence $\bra{Y_n\mid n<\omega}$ with $Y_{n+1}$ extending $Y_n$ and
  \eq{
    \pi^{Y_n}_{Y_{n+1}}(T^{Y_n}_\alpha)\neq T^{Y_n,Y_{n+1}}_\alpha\tag*{$(1)$}
  }

  for all $n<\omega$. Let $\P_n:=Q^X_{Y_n}$, $\pi_{m,n}:=\pi^{Y_m}_{Y_n}$ and $\pi_n:=\pi_{0,n}$. We want to show that such a sequence can't exist. Towards getting a contradiction we first need to make everything in sight countable, as that will allow us to reason using derived models (the problem is that $j(\h)$ is too big, namely it has size $\aleph_1^{V[g]}$).

  \qquad Using that $\delta^{j(\h)}$ has uncountable cofinality we can find $\kappa<\delta^{j(\h)}$ such that
  \eq{
    \kappa=\hull^{j(\h)}(\kappa\cup X\cup\{\ran\tau^X_{Y_n}\mid n<\omega\})\cap\delta^{j(\h)}.
  }

  Set $\M:=\chull^{j(\h)}(\kappa\cup X\cup\{\ran\tau^X_{Y_n}\mid n<\omega\})$ and note that $\M=j(\h)|\kappa^{+j(\h)}$\todo{Missing argument}. Let $\pi:\M\to j(\h)$ be the uncollapse and note that $\crit\pi=\kappa$ and that $\kappa=\delta^{\M}$. Define $\iota:\h\to\M$ as $\iota:=\pi^{-1}\circ j$ and $\tau_n:\P_n\to\M$ as $\tau_n:=\pi^{-1}\circ\tau^X_{Y_n}$. Note that $\M$ is countable in $V[g]$ and is hence an element of $\ult(V,g)$.

  \qquad Now define $\h^+$ as the hod limit of iterates of $\h$\todo{Provide more details.}, so that $\h^+$ is a hod premouse with $\h\pinit_{\text{hod}}\h^+$, $\h^+$ has a strategy $\Psi$ extending $\Omega$ such that\todo{We probably need $\h^+$ to be countable here, so we should probably apply the induced ideal and work in $V[g][h]$.}
\eq{
  (\{B\subset\mathbb R\mid w(B)<\kappa\})^{j(\M)}\subset\D(\h^+,\Psi).
}

  Also define $(\P_n^+,\Psi_n)$ as $P_n^+:=\ult(\h^+,E_{\pi_n})$, so that we also get that\todo{Missing argument. This might need that $\h^+,\Psi\restr V\in V$, but we could probably also just work inside $\ult(V,g)$, or the second ultrapower, all along.}
  \eq{
    (\{B\subset\mathbb R\mid w(B)<\kappa\})^{j(\M)}\subset\D(\P_n^+,\Psi_n).
  }

  Now $\D(\P_n^+,\Psi_n)$ has a definition of $T^{X,Y_n}_\alpha$\todo{What is meant by this?}, so that $\pi^{Y_n}_{Y_{n+1}}(T^{Y_n}_\alpha)=T^{Y_n,Y_{n+1}}_{\pi_{n,n+1}(\alpha)}$. The three-dimensional argument \todo{Show this.} then shows that $\alpha$ must be fixed by $\pi_{n,n+1}$ for some $n<\omega$, so that $X\cup Y_n$ \textit{is} $\alpha$-condensing, $\contr$.
}

\todo[inline]{Define the strategy $\Lambda$ for $\h$ and show that $(\h,\Lambda)$ is a hod pair.}

\end{document}


\chapter{An application to sequences}
\label{ch:time_series}

Recall that the optimisation problem is stated as
\[
    P^*_{opt} = \argmin_{P \in \mathcal{P}^*} \sum_{T_i \in \mathcal{T}} \epsilon^*(s(T_i), O^*(P, T_i)),
\]
where the objects that need to defined are the input and solution formats $[D]$ and $[S]$, the problem set $\mathcal{P}^*$, the test data $\mathcal{T}$, the error function $\epsilon^*$, and the oracle $O$. The framework presented in the previous chapter makes the assumption that all relevant problems $P$ can be decomposed into a set of functions $P = (T_D, F_E, C, F_R, M, \Sigma, T_S)$.

In this chapter, the objects mentioned above are defined for the two most common tasks in anomaly detection in sequences. Furthermore, suitable choices of and restrictions on $T_D$, $F_E$, $C$, $F_R$, $M$, $\Sigma$ and $T_S$ for anomaly detection are discussed in depth.

From here on, a \emph{sequence} will be taken to mean any list ($[X]$ for some set $X$) for which the list order reflects the natural ordering of the elements. A \emph{time series} is defined to be any sequence in $[(\mathbb{R}^+, X)]$, where the elements are ordered such that their first component (the timestamp) is increasing.

In Section~\ref{sect:tasks}, the two anomaly detection tasks we will study are presented. Corresponding oracles are presented.

The remaining sections consist of a discussion of how the components $T_D$, $F_E$, $C$, $F_R$, $M$, $\Sigma$, and $T_S$ relate to anomaly detection in sequences, and which component choices are appropriate.

\section{Tasks}
\label{sect:tasks}

Two main tasks can be distinguished in anomaly detection in sequences: \emph{finding anomalous sequences in a set of sequences}, and \emph{finding anomalous subsequences in a long sequence}~\cite{chandola}. The former task can be seen as the detection of point anomalies in an unstructured set of sequences, while the latter corresponds to finding contextual anomalies in a totally ordered set.

\subsection{Finding anomalous sequences}

The task of finding anomalous sequences in a set of sequences involves taking a list of similar sequences and producing a list of corresponding anomaly scores. The input elements are not related, i.e.\ the input data is unstructured. Thus, the task can be seen as one of detection of point anomalies in a collection of sequences. This task has been the subject of intense research. Thorough reviews are found in~\cite{chandola2} and~\cite{chandola3}.

For an example of this task, see figure \ref{fig:example1}. Here, dataset consists of a set of sequences of user commands extracted from a system log, and task corresponds to detecting individual anomalous sequences in this dataset. While sequences $\mathbf{S_1}$ through $\mathbf{S_4}$ are originate from ordinary user sessions, sequence $\mathbf{S_5}$ could indicate an attack. Accurately detecting such anomalous sequences is an important problem in computer security.

The input data has the format $[D]$, where $D$ is itself a set of sequences, i.e.\ $D = [X]$ for some set $X$. In the example above $X$ is a set of commands, but it could just as well be $\mathbb{R}$ or any other set. The solution format is $[S]$, where either $S = \mathbb{R}^+$ or $S = \{0, 1\}$ depending on the application requirements.

Since the input data is unstructured, any transformation $T_D$ must produce lists with the same length as it is given. Correspondingly, we can let $S' = S$. This renders $T_S$ redundant, so it can be ignored.

Since the task deals with unstructured data, the components $F_E$, $F_R$, and $\Sigma$ can be ignored. An oracle can then be formulated as:

\begin{algorithmic}
    \Require{Some $X \in [D]$.}
    \State{$X' \gets T_D(X)$}
    \State{$A \gets []$ \Comment{initialize anomaly scores to empty list}}
    \For{$E \in X'$} \Comment{iterate over elements}
        \State{$append(A, M(E, C(X', E)))$ \Comment{compute and store anomaly scores}}
    \EndFor{}
    \State{\Return{$A$ \Comment{aggregate scores to form anomaly vector}}}
\end{algorithmic}

As per the discussion in the previous chapter, $C$ can only be one of two functions, corresponding to unsupervised and semi-supervised anomaly detection, respectively.

\subsection{Finding anomalous subsequences}

The task of finding anomalous subsequences of long sequences corresponds to finding anomalous contiguous sublists of the input data $[D]$. In contrast to the task of finding anomalous sequences, the input data is structured, and the sequence ordering naturally gives rise to concepts of proximity and context. This task is relatively poorly understood, but is highly relevant in many application domains. As a consequence, automated methods can be expected to be very useful for this task. Essentially any monitoring or diagnosis application could benefit from a better understanding of the task.

For examples of sequences to which this task might be applied, see Figures~\ref{fig:example2} and~\ref{fig:anomaly_types}. These are all real-valued sequences which contain anomalous items or subsequences.

As with the previous task, either $S = \mathbb{R}^+$ or $S = \{0, 1\}$ depending on the application. However, it here makes sense to allow $T_D$ to compress the data (i.e.\ return a shorter list than it is given). Correspondingly, a corresponding $T_S$ is required in order to transform the preliminary solution (in $[S']$) to a list of anomaly scores with the same length as the input data.

Since all components must be used for this task, the oracle is identical to the one presented in Section~\ref{sect:oracle}.

\section{The input data format \texorpdfstring{$\mathcal{D}$}{D}}

Categorical, discrete, and real-valued sequences have all been extensively studied. Categorical sequences arise naturally in applications such as bioinfomatics and intrusion detection. Discrete sequences are typically encountered when monitoring the frequency of events over time. Finally, real-valued sequences are encountered in any application that involves measuring physical phenomena (such as audio, video and other sensor-based applications).

Which the origins and nature of the data obviously differs heavily between these different categories of sequences, the choice of components (with the exception of the transformations and anomaly measures) can be made independently of the type of data. For this reason, we can disregard the data format in most of the following discussion.

\section{The transformations \texorpdfstring{$T_D$}{TD} and \texorpdfstring{$T_S$}{TS}}

\begin{figure}[htb]
  \begin{center}
    \leavevmode
    \includegraphics[width=\textwidth]{resources/types_of_data}
  \end{center}
  \caption{\small{Illustration of numerosity and dimensionality reduction in a conversion of a real-valued sequence to a symbolic sequence. The top frame shows a real-valued sequence sampled from a random walk. The second frame shows the resulting series after a (piecewise constant) dimensionality reduction has been performed. In the third frame, the series from the second frame has been numerosity-reduced through rounding. The bottom frame shows how a conversion to a symbolic sequence might work; the elements from the third series is mapped to the set $\{a,b,c,d,e,f\}$.}}
\label{fig:types_of_data}
\end{figure}

Transformations are commonly used to facilitate the analysis of sequences, and a large number of different such transformations are found in the literature.

Feature extraction is commonly performed to reduce the dimensionality of sequences, and especially of real-valued ones. Essentially, the task of feature extraction in real-valued sequences corresponds to, given a sequence $s = [s_1, s_2, \dots, s_n]$, finding a collection of basis functions $[\phi_1, \phi_2, \dots, \phi_m]$ where $m < n$ that $s$ can be projected onto, such that $s$ can be recovered with little error. Many different methods for obtaining such bases have been proposed, including the discrete Fourier transform~\cite{faloutsos1}, discrete wavelet transforms~\cite{pong}~\cite{fu}, various piecewise linear and piecewise constant functions~\cite{keogh3}~\cite{geurts}, and singular value decomposition~\cite{keogh3}. An overview of different representations is provided in~\cite{fabian}.

Arguably the simplest of these bases are piecewise constant functions $[\phi_1, \phi_2, \dots, \phi_n]$:
\[
  \phi_i(t) = \left\{
    \begin{array}{l l}
      1 & \quad \text{ if } \tau_i < t < \tau_{i+1} \\
      0 & \quad \text{ otherwise.} \\
    \end{array} \right.
\]
where $(\tau_1, \tau_2, \dots \tau_n)$ is a partition of $[t_1, t_n]$.

Different piecewise constant representations have been proposed, corresponding to different partitions. The simplest of these, corresponding to a partition with constant $\tau_{i+1} - \tau_i$ is proposed in~\cite{keogh4} and~\cite{faloutsos2} and is usually referred to as \emph{piecewise aggregate approximation (PAA)}. As shown in~\cite{keogh5},~\cite{keogh3} and~\cite{faloutsos2}, PAA rivals the more sophisticated representations listed above.

Numerosity reduction is also commonly utilised in analysis of real-valued sequences. One scheme that combines numerosity and dimensionality reduction in order to give real-valued sequences into a categorical representation is \emph{symbolic aggregate approximation} (SAX)~\cite{sax}. This representation has been used to apply categorical anomaly measures to real-valued data with good results. A simplified variant of SAX is demonstraded in figure~\ref{fig:types_of_data}.

In general, real-valued sequences are much easier to deal with than time series. For this reason, irregular time series are commonly transformed to form regular time series, which can be treated as sequences. Formally, such transformations map a sequence in $[(\mathbb{R}^+, X)]$ to a sequence in $[X]$.

The simplest such transformation involves simply dropping the timestamp component of each item. This is useful when the order of items is important, but how far apart they are in time is not. This is often the case when dealing with categorical sequences. An example of such an application is shown in figure~\ref{fig:example1}.

Another common class of transformations involves estimating the (weighted) frequency of events. This is useful in many scenarios, especially in applications involving machine-generated data. Several methods can be used to generate sequences appropriate for this task from time series, such as histograms, sliding averages, etc.

% Given a time series $[(t_1, x_1), (t_2, x_2), \dots, (t_n, x_n)]$ in $[(\mathbb{R}^+, X)]$, with associated weights $w_i$ and some envelope function $e(s, t): X \times \mathbb{R} \rightarrow X$, as well as a spacing and offset $\Delta, t_0 \in \mathbb{R}^+$, a sequence $[(s_{1}^{'}, \tau_1), (s_{2}^{'}, \tau_2), \dots]$ is constructed where $\tau_i = t_0 + \Delta \cdot i$ and $s_{i}^{'} = \sum_{(s_j, t_j) \in S} s_i w_i e(t_j - \tau_i)$.

% The $\tau_i$ can then be discarded and the time series treated as a sequence\footnote{Note that this method requires multiplication and addition to be defined for $X$, and is thus not applicable to most symbolic/categorical data. Also note that $\mathbf{s}'$ is really just a sequence of samples of the convolution $f_S \ast e$ where $f_S = \sum_i \delta(t_i) s_i w_i$.}. Histograms are recovered if $e(s, t) = 1$ when $|t| < \Delta/2$ and $e(x, t) = 0$ otherwise.

% How this aggregation is performed has a large and often poorly understood impact on the resulting sequence. As an example, when constructing histograms, the bin width and offset have implications for the speed and accuracy of the analysis. A small bin width leads to both small features and noise being more pronounced, while a large bin width might obscure smaller features. Similarly, the offset can greatly affect the appearance of the histograms, especially if the bin width is large. There is no `optimal' way to select these parameters, and various rules of thumb are typically used~\cite{density_estimation}.

% Furthermore, noisy data is often resampled to form regular time series. In this case, any of a number of resampling methods from the digital signal processing literature~\cite{TODO} may be employed.

% One commonly used transformation for real-valued data is the Z-normalization transform, which modifies a sequence to exhibit zero empirical mean and unit variance.\footnote{It has been argued that comparing time series is meaningless unless the Z-normalization transform is used~\cite{keogh5}. However, this is doubtful, as the transform masks sequences that are anomalous because they are displaced or scaled relative to other sequences.}

Transformations that transform the data into some alternative domain can also be useful. For example, transformations based on the \emph{discrete Fourier transform} (DFT) and \emph{discrete wavelet transform} (DWT)~\cite{fu} have shown promise. The DFT is parameter-free, while the DWT can be said to be parametrised due to the variety of possible wavelet transforms.

\section{The filters \texorpdfstring{$F_E$}{FE} and \texorpdfstring{$F_R$}{FR}}
\label{sect:filters}

As was previously mentioned, filters are really only interesting for the task of finding anomalous subsequences. Here, the role of the filter is to map a sequence in $[D']$ to a list candidate anomalies (subsequences of the input sequence).

By far the most frequently used filters are \emph{sliding window} filters. These map a sequence $X = [x_1, x_2, \dots, x_n]$ to
\[
    F_E(X) = [[x_1, x_2, \dots, x_w], [x_{s + 1}, x_{s + 2}, \dots, x_{s + w}], \dots, [x_{n - w}, x_{n - w + 1}, \dots, x_n]],
\]
where $w$ and $s$ are arbitrary integers (typically $s \leq w$)\footnote{We here assume that $s | n - w$. Otherwise, the last element above might look a bit different.}.

\section{The context function \texorpdfstring{$C$}{C}}
\label{sect:context}

The ordering present in sequences naturally give rise to a few interesting contexts, which are now demonstrated for a sequence $s = [s_1, s_2, \dots, s_n]$ and a candidate anomaly $s' [s_i, s_{i + 1}, \dots, s_j]$, where $1 \leq i \leq j \leq n$. It is here assumed that all candidate anomalies are contiguous. As mentioned in the previous chapter, contexts can be used to generalise the concept of training data. Semi-supervised anomaly detection corresponds to the \emph{semi-supervised context} $C(s, s') = T$, where $T$ is some fixed set of training data.

Likewise, traditional unsupervised anomaly detection for subsequences can be formulated using the \emph{trivial context} $C(s, s') = [[s_1, s_2, \dots, s_{i - 1}], [s_{j + 1}, s_{j + 2}, \dots, s_n]]$. This corresponds to finding either point anomalies or collective anomalies in a sequence.

Another interesting context is the \emph{novelty context} $C(s, s') = [[s_1, s_2, \dots, s_{i - 1}]]$. This context captures the task of novelty detection in sequences, which is especially interesting in monitoring applications.

Finally, a family of \emph{local contexts}
\[
    C(s, s') = [[s_{\max(1, i - a)}, s_{\max(2, i - a + 1)}, \dots, s_{i-1}], [s_{j+1}, s_{j+2}, \ldots s_{min(n, j+b)}]]
\]
may be defined for $a, b \in \mathbb{N}$, in order to handle anomalies such as the one in the last sequence of figure~\ref{fig:anomaly_types}.

\section{The anomaly measure \texorpdfstring{$M$}{M}}
\label{sect:anomeasure}

As was mentioned previously, an anomaly measure is a function $M: ([D'], [[D']]) \rightarrow \mathbb{R}^+$ that takes a candidate anomaly $c \in [D']$ and a reference set $R \in [[D']]$, and produces an anomaly score based on how anomalous $C$ is with regards to $R$. A large number of such measures have been used in the literature, and a thorough discussion of these is not possible within the scope of this report. Instead, we will limit our consideration to distance-based anomaly measures, since these are flexible and have been shown to perform well in general for sequences~\cite{chandola3}.

Distance-based anomaly measures operate by, given some distance measure $\delta: [D'] \times [D'] \rightarrow \mathbb{R}^+$, somehow aggregating the set $\{\delta(c, r) | r \in R\}$ into an anomaly score in $\mathbb{R}^+$. A class of especially interesting distance-based anomaly measure is k-nearest-neighbour-based anomaly measures. These assign as anomaly score the mean of the $k$ largest values of $\{\delta(c, r) | r \in R\}$.

Possible interesting choices of $\delta$ for real-valued data include the \emph{Euclidean distance} or the more general \emph{Minkowski distance}; measures focused on time series, such as \emph{dynamic time warping}~\cite{dtw}, \emph{autocorrelation measures}~\cite{autocorrelation}, or the \emph{Linear Predictive Coding cepstrum}~\cite{cepstrum}.

There are also several or measures developed for series of categorical data, such as the \emph{compression-based dissimilarity measure}~\cite{keogh2}. Often, coupling a distance measure with a data transformation step (in order to, for instance, to apply a distance measure defined on categorial data to a real-valued seqeuence) can yield good results.

\section{The aggregation function \texorpdfstring{$\Sigma$}{Sigma}}
\label{sect:aggregation_function_2}

Examples of anomaly detection problems which involve aggregation are hard to find in the literature. For this reason, suggesting appropriate choices of $\Sigma$ is difficult. A few choices which are likely to produce good results are $\Sigma$ on the form suggested in Section~\ref{sect:aggregation_function}, with $\sigma$ that produce either the \emph{maximum}, \emph{minimum}, \emph{median}, or \emph{mean} of its input values. The resulting $\Sigma$ will henceforth be referred to as $\Sigma_{max}$, $\Sigma_{min}$, $\Sigma_{median}$ and $\Sigma_{mean}$, respectively.


% !TEX root =  paper.tex
\section{Conclusions}

We present a novel method for improved neuronal reconstruction in connectomics that extends existing pixel-based reconstruction strategies using skeletonized 3D networks. We show significant accuracy improvements on datasets from two different species. The main benefits of our approach are that it enforces domain-specific constraints at the global graph level while incorporating pixel-based classification information.

There is significant room for additional research and improvements. We can augment the graph with additional information from the image data, such as synaptic locations, cell morphology, locations of mitochondria, etc. This would allow us to enforce additional biological constraints during graph partitioning. For example, we could then enforce the constraint that a given segment only has post- or pre-synaptic connections. An augmented graph would also be helpful for splitting improperly merged segments by adding additional terms to the partitioning cost function. Finally, we believe that the benefits of top-down enhancements from graph optimization can extend beyond connectomics to other domains, such as medical image segmentation.