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

\chapter{The Zipf}
The zipf function \(z\) converts any document \(d \subseteq \D^m \) comprised of elements into a representative vector \(\bmv \subseteq \sqr{0, 1}^n, n \leq m \) based on the frequency of said elements in the given document. Taken in consideration the set of elements \(d \subseteq \D \) that comprise the document and \(d_{\neq} \subseteq d\) the set of distinct elements of the set \(d\), for any given element \(d_{\neq_{i}} \in d_{\neq}\), the value assigned by the zipf function is:
\[
  z(d_{\neq_{i}}):\D \rightarrow \R  = \frac{\arity{\forall d_i \in d: d_{\neq_{i}}=d_i}}{\#d}
\]

\end{document}


\section{Language}

A \emph{language} $\Lang$ consists of a set \textdom{Expr} of \emph{expressions} (metavariable $\expr$), a set \textdom{Val} of \emph{values} (metavariable $\val$), and a set \textdom{State} of \emph{states} (metvariable $\state$) such that
\begin{itemize}
\item There exist functions $\ofval : \textdom{Val} \to \textdom{Expr}$ and $\toval : \textdom{Expr} \pfn \textdom{val}$ (notice the latter is partial), such that
\begin{mathpar} {\All \expr, \val. \toval(\expr) = \val \Ra \ofval(\val) = \expr} \and {\All\val. \toval(\ofval(\val)) = \val}
\end{mathpar}
\item There exists a \emph{primitive reduction relation} \[(-,- \step -,-,-) \subseteq \textdom{Expr} \times \textdom{State} \times \textdom{Expr} \times \textdom{State} \times (\textdom{Expr} \uplus \set{()})\]
  We will write $\expr_1, \state_1 \step \expr_2, \state_2$ for $\expr_1, \state_1 \step \expr_2, \state_2, ()$. \\
  A reduction $\expr_1, \state_1 \step \expr_2, \state_2, \expr'$ indicates that, when $\expr_1$ reduces to $\expr$, a \emph{new thread} $\expr'$ is forked off.
\item All values are stuck:
\[ \expr, \_ \step  \_, \_, \_ \Ra \toval(\expr) = \bot \]
\item There is a predicate defining \emph{atomic} expressions satisfying
\let\oldcr\cr
\begin{mathpar}
  {\All\expr. \atomic(\expr) \Ra \toval(\expr) = \bot} \and
  {{
    \begin{inbox}
\All\expr_1, \state_1, \expr_2, \state_2, \expr'. \atomic(\expr_1) \land \expr_1, \state_1 \step \expr_2, \state_2, \expr' \Ra {}\\\qquad\qquad\qquad\quad~~ \Exists \val_2. \toval(\expr_2) = \val_2
    \end{inbox}
}}
\end{mathpar}
In other words, atomic expression \emph{reduce in one step to a value}.
It does not matter whether they fork off an arbitrary expression.
\end{itemize}

\begin{defn}[Context]
  A function $\lctx : \textdom{Expr} \to \textdom{Expr}$ is a \emph{context} if the following conditions are satisfied:
  \begin{enumerate}[itemsep=0pt]
  \item $\lctx$ does not turn non-values into values:\\
    $\All\expr. \toval(\expr) = \bot \Ra \toval(\lctx(\expr)) = \bot $
  \item One can perform reductions below $\lctx$:\\
    $\All \expr_1, \state_1, \expr_2, \state_2, \expr'. \expr_1, \state_1 \step \expr_2,\state_2,\expr' \Ra \lctx(\expr_1), \state_1 \step \lctx(\expr_2),\state_2,\expr' $
  \item Reductions stay below $\lctx$ until there is a value in the hole:\\
    $\All \expr_1', \state_1, \expr_2, \state_2, \expr'. \toval(\expr_1') = \bot \land \lctx(\expr_1'), \state_1 \step \expr_2,\state_2,\expr' \Ra \Exists\expr_2'. \expr_2 = \lctx(\expr_2') \land \expr_1', \state_1 \step \expr_2',\state_2,\expr' $
  \end{enumerate}
\end{defn}

\subsection{The concurrent language}

For any language $\Lang$, we define the corresponding thread-pool semantics.

\paragraph{Machine syntax}
\[
	\tpool \in \textdom{ThreadPool} \eqdef \bigcup_n \textdom{Exp}^n
\]

\judgment{Machine reduction} {\cfg{\tpool}{\state} \step
  \cfg{\tpool'}{\state'}}
\begin{mathpar}
\infer
  {\expr_1, \state_1 \step \expr_2, \state_2, \expr' \and \expr' \neq ()}
  {\cfg{\tpool \dplus [\expr_1] \dplus \tpool'}{\state} \step
     \cfg{\tpool \dplus [\expr_2] \dplus \tpool' \dplus [\expr']}{\state'}}
\and\infer
  {\expr_1, \state_1 \step \expr_2, \state_2}
  {\cfg{\tpool \dplus [\expr_1] \dplus \tpool'}{\state} \step
     \cfg{\tpool \dplus [\expr_2] \dplus \tpool'}{\state'}}
\end{mathpar}

\clearpage
\section{The logic}

To instantiate Iris, you need to define the following parameters:
\begin{itemize}
\item A language $\Lang$
\item A locally contractive functor $\iFunc : \COFEs \to \CMRAs$ defining the ghost state, such that for all COFEs $A$, the CMRA $\iFunc(A)$ has a unit
\end{itemize}

\noindent
As usual for higher-order logics, you can furthermore pick a \emph{signature} $\Sig = (\SigType, \SigFn, \SigAx)$ to add more types, symbols and axioms to the language.
You have to make sure that $\SigType$ includes the base types:
\[
	\SigType \supseteq \{ \textlog{Val}, \textlog{Expr}, \textlog{State}, \textlog{M}, \textlog{InvName}, \textlog{InvMask}, \Prop \}
\]
Elements of $\SigType$ are ranged over by $\sigtype$.

Each function symbol in $\SigFn$ has an associated \emph{arity} comprising a natural number $n$ and an ordered list of $n+1$ types $\type$ (the grammar of $\type$ is defined below, and depends only on $\SigType$).
We write
\[
	\sigfn : \type_1, \dots, \type_n \to \type_{n+1} \in \SigFn
\]
to express that $\sigfn$ is a function symbol with the indicated arity.

Furthermore, $\SigAx$ is a set of \emph{axioms}, that is, terms $\term$ of type $\Prop$.
Again, the grammar of terms and their typing rules are defined below, and depends only on $\SigType$ and $\SigFn$, not on $\SigAx$.
Elements of $\SigAx$ are ranged over by $\sigax$.

\subsection{Grammar}\label{sec:grammar}

\paragraph{Syntax.}
Iris syntax is built up from a signature $\Sig$ and a countably infinite set $\textdom{Var}$ of variables (ranged over by metavariables $x$, $y$, $z$):

\begin{align*}
  \type \bnfdef{}&
      \sigtype \mid
      1 \mid
      \type \times \type \mid
      \type \to \type
\\[0.4em]
  \term, \prop, \pred \bnfdef{}&
      \var \mid
      \sigfn(\term_1, \dots, \term_n) \mid
      () \mid
      (\term, \term) \mid
      \pi_i\; \term \mid
      \Lam \var:\type.\term \mid
      \term(\term)  \mid
      \munit \mid
      \mcore\term \mid
      \term \mtimes \term \mid
\\&
    \FALSE \mid
    \TRUE \mid
    \term =_\type \term \mid
    \prop \Ra \prop \mid
    \prop \land \prop \mid
    \prop \lor \prop \mid
    \prop * \prop \mid
    \prop \wand \prop \mid
\\&
    \MU \var:\type. \pred  \mid
    \Exists \var:\type. \prop \mid
    \All \var:\type. \prop \mid
\\&
    \knowInv{\term}{\prop} \mid
    \ownGGhost{\term} \mid
    \ownPhys{\term} \mid
    \always\prop \mid
    {\later\prop} \mid
    \pvs[\term][\term] \prop\mid
    \wpre{\term}{\Ret\var.\term}[\term]
\end{align*}
Recursive predicates must be \emph{guarded}: in $\MU \var. \pred$, the variable $\var$ can only appear under the later $\later$ modality.

Note that $\always$ and $\later$ bind more tightly than $*$, $\wand$, $\land$, $\lor$, and $\Ra$.
We will write $\pvs[\term] \prop$ for $\pvs[\term][\term] \prop$.
If we omit the mask, then it is $\top$ for weakest precondition $\wpre\expr{\Ret\var.\prop}$ and $\emptyset$ for primitive view shifts $\pvs \prop$.

\paragraph{Metavariable conventions.}
We introduce additional metavariables ranging over terms and generally let the choice of metavariable indicate the term's type:
\[
\begin{array}{r|l}
 \text{metavariable} & \text{type} \\\hline
  \term, \termB & \text{arbitrary} \\
  \val, \valB & \textlog{Val} \\
  \expr & \textlog{Expr} \\
  \state & \textlog{State} \\
\end{array}
\qquad\qquad
\begin{array}{r|l}
 \text{metavariable} & \text{type} \\\hline
  \iname & \textlog{InvName} \\
  \mask & \textlog{InvMask} \\
  \melt, \meltB & \textlog{M} \\
  \prop, \propB, \propC & \Prop \\
  \pred, \predB, \predC & \type\to\Prop \text{ (when $\type$ is clear from context)} \\
\end{array}
\]

\paragraph{Variable conventions.}
We often abuse notation, using the preceding \emph{term} meta-variables to range over (bound) \emph{variables}.
We omit type annotations in binders, when the type is clear from context.
We assume that, if a term occurs multiple times in a rule, its free variables are exactly those binders which are available at every occurrence.

\subsection{Types}\label{sec:types}

Iris terms are simply-typed.
The judgment $\vctx \proves \wtt{\term}{\type}$ expresses that, in variable context $\vctx$, the term $\term$ has type $\type$.

A variable context, $\vctx = x_1:\type_1, \dots, x_n:\type_n$, declares a list of variables and their types.
In writing $\vctx, x:\type$, we presuppose that $x$ is not already declared in $\vctx$.

\judgment{Well-typed terms}{\vctx \proves_\Sig \wtt{\term}{\type}}
\begin{mathparpagebreakable}
%%% variables and function symbols
	\axiom{x : \type \proves \wtt{x}{\type}}
\and
	\infer{\vctx \proves \wtt{\term}{\type}}
		{\vctx, x:\type' \proves \wtt{\term}{\type}}
\and
	\infer{\vctx, x:\type', y:\type' \proves \wtt{\term}{\type}}
		{\vctx, x:\type' \proves \wtt{\term[x/y]}{\type}}
\and
	\infer{\vctx_1, x:\type', y:\type'', \vctx_2 \proves \wtt{\term}{\type}}
		{\vctx_1, x:\type'', y:\type', \vctx_2 \proves \wtt{\term[y/x,x/y]}{\type}}
\and
	\infer{
		\vctx \proves \wtt{\term_1}{\type_1} \and
		\cdots \and
		\vctx \proves \wtt{\term_n}{\type_n} \and
		\sigfn : \type_1, \dots, \type_n \to \type_{n+1} \in \SigFn
	}{
		\vctx \proves \wtt {\sigfn(\term_1, \dots, \term_n)} {\type_{n+1}}
	}
%%% products
\and
	\axiom{\vctx \proves \wtt{()}{1}}
\and
	\infer{\vctx \proves \wtt{\term}{\type_1} \and \vctx \proves \wtt{\termB}{\type_2}}
		{\vctx \proves \wtt{(\term,\termB)}{\type_1 \times \type_2}}
\and
	\infer{\vctx \proves \wtt{\term}{\type_1 \times \type_2} \and i \in \{1, 2\}}
		{\vctx \proves \wtt{\pi_i\,\term}{\type_i}}
%%% functions
\and
	\infer{\vctx, x:\type \proves \wtt{\term}{\type'}}
		{\vctx \proves \wtt{\Lam x. \term}{\type \to \type'}}
\and
	\infer
	{\vctx \proves \wtt{\term}{\type \to \type'} \and \wtt{\termB}{\type}}
	{\vctx \proves \wtt{\term(\termB)}{\type'}}
%%% monoids
\and
        \infer{}{\vctx \proves \wtt\munit{\textlog{M}}}
\and
	\infer{\vctx \proves \wtt\melt{\textlog{M}}}{\vctx \proves \wtt{\mcore\melt}{\textlog{M}}}
\and
	\infer{\vctx \proves \wtt{\melt}{\textlog{M}} \and \vctx \proves \wtt{\meltB}{\textlog{M}}}
		{\vctx \proves \wtt{\melt \mtimes \meltB}{\textlog{M}}}
%%% props and predicates
\\
	\axiom{\vctx \proves \wtt{\FALSE}{\Prop}}
\and
	\axiom{\vctx \proves \wtt{\TRUE}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\term}{\type} \and \vctx \proves \wtt{\termB}{\type}}
		{\vctx \proves \wtt{\term =_\type \termB}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop} \and \vctx \proves \wtt{\propB}{\Prop}}
		{\vctx \proves \wtt{\prop \Ra \propB}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop} \and \vctx \proves \wtt{\propB}{\Prop}}
		{\vctx \proves \wtt{\prop \land \propB}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop} \and \vctx \proves \wtt{\propB}{\Prop}}
		{\vctx \proves \wtt{\prop \lor \propB}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop} \and \vctx \proves \wtt{\propB}{\Prop}}
		{\vctx \proves \wtt{\prop * \propB}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop} \and \vctx \proves \wtt{\propB}{\Prop}}
		{\vctx \proves \wtt{\prop \wand \propB}{\Prop}}
\and
	\infer{
		\vctx, \var:\type \proves \wtt{\term}{\type} \and
		\text{$\var$ is guarded in $\term$}
	}{
		\vctx \proves \wtt{\MU \var:\type. \term}{\type}
	}
\and
	\infer{\vctx, x:\type \proves \wtt{\prop}{\Prop}}
		{\vctx \proves \wtt{\Exists x:\type. \prop}{\Prop}}
\and
	\infer{\vctx, x:\type \proves \wtt{\prop}{\Prop}}
		{\vctx \proves \wtt{\All x:\type. \prop}{\Prop}}
\and
	\infer{
		\vctx \proves \wtt{\prop}{\Prop} \and
		\vctx \proves \wtt{\iname}{\textlog{InvName}}
	}{
		\vctx \proves \wtt{\knowInv{\iname}{\prop}}{\Prop}
	}
\and
	\infer{\vctx \proves \wtt{\melt}{\textlog{M}}}
		{\vctx \proves \wtt{\ownGGhost{\melt}}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\state}{\textlog{State}}}
		{\vctx \proves \wtt{\ownPhys{\state}}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop}}
		{\vctx \proves \wtt{\always\prop}{\Prop}}
\and
	\infer{\vctx \proves \wtt{\prop}{\Prop}}
		{\vctx \proves \wtt{\later\prop}{\Prop}}
\and
	\infer{
		\vctx \proves \wtt{\prop}{\Prop} \and
		\vctx \proves \wtt{\mask}{\textlog{InvMask}} \and
		\vctx \proves \wtt{\mask'}{\textlog{InvMask}}
	}{
		\vctx \proves \wtt{\pvs[\mask][\mask'] \prop}{\Prop}
	}
\and
	\infer{
		\vctx \proves \wtt{\expr}{\textlog{Expr}} \and
		\vctx,\var:\textlog{Val} \proves \wtt{\term}{\Prop} \and
		\vctx \proves \wtt{\mask}{\textlog{InvMask}}
	}{
		\vctx \proves \wtt{\wpre{\expr}{\Ret\var.\term}[\mask]}{\Prop}
	}
\end{mathparpagebreakable}

\subsection{Timeless propositions}

Some propositions are \emph{timeless}, which intuitively means that step-indexing does not affect them.
This is a \emph{meta-level} assertions about propositions, defined by the following judgment.

\judgment{Timeless Propositions}{\timeless{P}}

\ralf{Define a judgment that defines them.}

\subsection{Proof rules}

The judgment $\vctx \mid \pfctx \proves \prop$ says that with free variables $\vctx$, proposition $\prop$ holds whenever all assumptions $\pfctx$ hold.
We implicitly assume that an arbitrary variable context, $\vctx$, is added to every constituent of the rules.
Furthermore, an arbitrary \emph{boxed} assertion context $\always\pfctx$ may be added to every constituent.
Axioms $\prop \Ra \propB$ stand for judgments $\vctx \mid \cdot \proves \prop \Ra \propB$ with no assumptions.
(Bi-implications are analogous.)

\judgment{}{\vctx \mid \pfctx \proves \prop}
\paragraph{Laws of intuitionistic higher-order logic.}
This is entirely standard.
\begin{mathparpagebreakable}
\infer[Asm]
  {\prop \in \pfctx}
  {\pfctx \proves \prop}
\and
\infer[Eq]
  {\pfctx \proves \prop \\ \pfctx \proves \term =_\type \term'}
  {\pfctx \proves \prop[\term'/\term]}
\and
\infer[Refl]
  {}
  {\pfctx \proves \term =_\type \term}
\and
\infer[$\bot$E]
  {\pfctx \proves \FALSE}
  {\pfctx \proves \prop}
\and
\infer[$\top$I]
  {}
  {\pfctx \proves \TRUE}
\and
\infer[$\wedge$I]
  {\pfctx \proves \prop \\ \pfctx \proves \propB}
  {\pfctx \proves \prop \wedge \propB}
\and
\infer[$\wedge$EL]
  {\pfctx \proves \prop \wedge \propB}
  {\pfctx \proves \prop}
\and
\infer[$\wedge$ER]
  {\pfctx \proves \prop \wedge \propB}
  {\pfctx \proves \propB}
\and
\infer[$\vee$IL]
  {\pfctx \proves \prop }
  {\pfctx \proves \prop \vee \propB}
\and
\infer[$\vee$IR]
  {\pfctx \proves \propB}
  {\pfctx \proves \prop \vee \propB}
\and
\infer[$\vee$E]
  {\pfctx \proves \prop \vee \propB \\
   \pfctx, \prop \proves \propC \\
   \pfctx, \propB \proves \propC}
  {\pfctx \proves \propC}
\and
\infer[$\Ra$I]
  {\pfctx, \prop \proves \propB}
  {\pfctx \proves \prop \Ra \propB}
\and
\infer[$\Ra$E]
  {\pfctx \proves \prop \Ra \propB \\ \pfctx \proves \prop}
  {\pfctx \proves \propB}
\and
\infer[$\forall$I]
  { \vctx,\var : \type\mid\pfctx \proves \prop}
  {\vctx\mid\pfctx \proves \forall \var: \type.\; \prop}
\and
\infer[$\forall$E]
  {\vctx\mid\pfctx \proves \forall \var :\type.\; \prop \\
   \vctx \proves \wtt\term\type}
  {\vctx\mid\pfctx \proves \prop[\term/\var]}
\and
\infer[$\exists$I]
  {\vctx\mid\pfctx \proves \prop[\term/\var] \\
   \vctx \proves \wtt\term\type}
  {\vctx\mid\pfctx \proves \exists \var: \type. \prop}
\and
\infer[$\exists$E]
  {\vctx\mid\pfctx \proves \exists \var: \type.\; \prop \\
   \vctx,\var : \type\mid\pfctx , \prop \proves \propB}
  {\vctx\mid\pfctx \proves \propB}
\and
\infer[$\lambda$]
  {}
  {\pfctx \proves (\Lam\var: \type. \prop)(\term) =_{\type\to\type'} \prop[\term/\var]}
\and
\infer[$\mu$]
  {}
  {\pfctx \proves \mu\var: \type. \prop =_{\type} \prop[\mu\var: \type. \prop/\var]}
\end{mathparpagebreakable}

\paragraph{Laws of (affine) bunched implications.}
\begin{mathpar}
\begin{array}{rMcMl}
  \TRUE * \prop &\Lra& \prop \\
  \prop * \propB &\Lra& \propB * \prop \\
  (\prop * \propB) * \propC &\Lra& \prop * (\propB * \propC)
\end{array}
\and
\infer[$*$-mono]
  {\prop_1 \proves \propB_1 \and
   \prop_2 \proves \propB_2}
  {\prop_1 * \prop_2 \proves \propB_1 * \propB_2}
\and
\inferB[$\wand$I-E]
  {\prop * \propB \proves \propC}
  {\prop \proves \propB \wand \propC}
\end{mathpar}

\paragraph{Laws for ghosts and physical resources.}
\begin{mathpar}
\begin{array}{rMcMl}
\ownGGhost{\melt} * \ownGGhost{\meltB} &\Lra&  \ownGGhost{\melt \mtimes \meltB} \\
\TRUE &\Ra&  \ownGGhost{\munit}\\
\ownGGhost{\melt} &\Ra& \melt \in \mval % * \ownGGhost{\melt}
\end{array}
\and
\begin{array}{c}
\ownPhys{\state} * \ownPhys{\state'} \Ra \FALSE
\end{array}
\end{mathpar}

\paragraph{Laws for the later modality.}
\begin{mathpar}
\infer[$\later$-mono]
  {\pfctx \proves \prop}
  {\pfctx \proves \later{\prop}}
\and
\infer[L{\"o}b]
  {}
  {(\later\prop\Ra\prop) \proves \prop}
\and
\infer[$\later$-$\exists$]
  {\text{$\type$ is inhabited}}
  {\later{\Exists x:\type.\prop} \proves \Exists x:\type. \later\prop}
\\\\
\begin{array}[c]{rMcMl}
  \later{(\prop \wedge \propB)} &\Lra& \later{\prop} \wedge \later{\propB}  \\
  \later{(\prop \vee \propB)} &\Lra& \later{\prop} \vee \later{\propB} \\
\end{array}
\and
\begin{array}[c]{rMcMl}
  \later{\All x.\prop} &\Lra& \All x. \later\prop \\
  \Exists x. \later\prop &\Ra& \later{\Exists x.\prop}  \\
  \later{(\prop * \propB)} &\Lra& \later\prop * \later\propB
\end{array}
\end{mathpar}

\paragraph{Laws for the always modality.}
\begin{mathpar}
\infer[$\always$I]
  {\always{\pfctx} \proves \prop}
  {\always{\pfctx} \proves \always{\prop}}
\and
\infer[$\always$E]{}
  {\always{\prop} \Ra \prop}
\and
\begin{array}[c]{rMcMl}
  \always{(\prop * \propB)} &\Ra& \always{(\prop \land \propB)} \\
  \always{\prop} * \propB &\Ra& \always{\prop} \land \propB \\
  \always{\later\prop} &\Lra& \later\always{\prop} \\
\end{array}
\and
\begin{array}[c]{rMcMl}
  \always{(\prop \land \propB)} &\Lra& \always{\prop} \land \always{\propB} \\
  \always{(\prop \lor \propB)} &\Lra& \always{\prop} \lor \always{\propB} \\
  \always{\All x. \prop} &\Lra& \All x. \always{\prop} \\
  \always{\Exists x. \prop} &\Lra& \Exists x. \always{\prop} \\
\end{array}
\and
{ \term =_\type \term' \Ra \always \term =_\type \term'}
\and
{ \knowInv\iname\prop \Ra \always \knowInv\iname\prop}
\and
{ \ownGGhost{\mcore\melt} \Ra \always \ownGGhost{\mcore\melt}}
\end{mathpar}

\paragraph{Laws of primitive view shifts.}
\begin{mathpar}
\infer[pvs-intro]
{}{\prop \proves \pvs[\mask] \prop}

\infer[pvs-mono]
{\prop \proves \propB}
{\pvs[\mask_1][\mask_2] \prop \proves \pvs[\mask_1][\mask_2] \propB}

\infer[pvs-timeless]
{\timeless\prop}
{\later\prop \proves \pvs[\mask] \prop}

\infer[pvs-trans]
{\mask_2 \subseteq \mask_1 \cup \mask_3}
{\pvs[\mask_1][\mask_2] \pvs[\mask_2][\mask_3] \prop \proves \pvs[\mask_1][\mask_3] \prop}

\infer[pvs-mask-frame]
{}{\pvs[\mask_1][\mask_2] \prop \proves \pvs[\mask_1 \uplus \mask_f][\mask_2 \uplus \mask_f] \prop}

\infer[pvs-frame]
{}{\propB * \pvs[\mask_1][\mask_2]\prop \proves \pvs[\mask_1][\mask_2] \propB * \prop}

\infer[pvs-allocI]
{\text{$\mask$ is infinite}}
{\later\prop \proves \pvs[\mask] \Exists \iname \in \mask. \knowInv\iname\prop}

\infer[pvs-openI]
{}{\knowInv\iname\prop \proves \pvs[\set\iname][\emptyset] \later\prop}

\infer[pvs-closeI]
{}{\knowInv\iname\prop \land \later\prop \proves \pvs[\emptyset][\set\iname] \TRUE}

\infer[pvs-update]
{\melt \mupd \meltsB}
{\ownGGhost\melt \proves \pvs[\mask] \Exists\meltB\in\meltsB. \ownGGhost\meltB}
\end{mathpar}

\paragraph{Laws of weakest preconditions.}
\begin{mathpar}
\infer[wp-value]
{}{\prop[\val/\var] \proves \wpre{\val}{\Ret\var.\prop}[\mask]}

\infer[wp-mono]
{\mask_1 \subseteq \mask_2 \and \var:\textlog{val}\mid\prop \proves \propB}
{\wpre\expr{\Ret\var.\prop}[\mask_1] \proves \wpre\expr{\Ret\var.\propB}[\mask_2]}

\infer[pvs-wp]
{}{\pvs[\mask] \wpre\expr{\Ret\var.\prop}[\mask] \proves \wpre\expr{\Ret\var.\prop}[\mask]}

\infer[wp-pvs]
{}{\wpre\expr{\Ret\var.\pvs[\mask] \prop}[\mask] \proves \wpre\expr{\Ret\var.\prop}[\mask]}

\infer[wp-atomic]
{\mask_2 \subseteq \mask_1 \and \physatomic{\expr}}
{\pvs[\mask_1][\mask_2] \wpre\expr{\Ret\var. \pvs[\mask_2][\mask_1]\prop}[\mask_2]
 \proves \wpre\expr{\Ret\var.\prop}[\mask_1]}

\infer[wp-frame]
{}{\propB * \wpre\expr{\Ret\var.\prop}[\mask] \proves \wpre\expr{\Ret\var.\propB*\prop}[\mask]}

\infer[wp-frame-step]
{\toval(\expr) = \bot}
{\later\propB * \wpre\expr{\Ret\var.\prop}[\mask] \proves \wpre\expr{\Ret\var.\propB*\prop}[\mask]}

\infer[wp-bind]
{\text{$\lctx$ is a context}}
{\wpre\expr{\Ret\var. \wpre{\lctx(\ofval(\var))}{\Ret\varB.\prop}[\mask]}[\mask] \proves \wpre{\lctx(\expr)}{\Ret\varB.\prop}[\mask]}
\end{mathpar}

\subsection{Lifting of operational semantics}\label{sec:lifting}
~\\\ralf{Add this.}

% The following lemmas help in proving axioms for a particular language.
% The first applies to expressions with side-effects, and the second to side-effect-free expressions.
% \dave{Update the others, and the example, wrt the new treatment of $\predB$.}
% \begin{align*}
%  &\All \expr, \state, \pred, \prop, \propB, \mask. \\
%  &\textlog{reducible}(e) \implies \\
%  &(\All \expr', \state'. \cfg{\state}{\expr} \step \cfg{\state'}{\expr'} \implies \pred(\expr', \state')) \implies \\
%  &{} \proves \bigl( (\All \expr', \state'. \pred (\expr', \state') \Ra \hoare{\prop}{\expr'}{\Ret\val. \propB}[\mask]) \Ra \hoare{ \later \prop * \ownPhys{\state} }{\expr}{\Ret\val. \propB}[\mask] \bigr) \\
%  \quad\\
%  &\All \expr, \pred, \prop, \propB, \mask. \\
%  &\textlog{reducible}(e) \implies \\
%  &(\All \state, \expr_2, \state_2. \cfg{\state}{\expr} \step \cfg{\state_2}{\expr_2} \implies \state_2 = \state \land \pred(\expr_2)) \implies \\
%  &{} \proves \bigl( (\All \expr'. \pred(\expr') \Ra \hoare{\prop}{\expr'}{\Ret\val. \propB}[\mask]) \Ra \hoare{\later\prop}{\expr}{\Ret\val. \propB}[\mask] \bigr)
% \end{align*}
% Note that $\pred$ is a meta-logic predicate---it does not depend on any world or resources being owned.

% The following specializations cover all cases of a heap-manipulating lambda calculus like $F_{\mu!}$.
% \begin{align*}
%  &\All \expr, \expr', \prop, \propB, \mask. \\
%  &\textlog{reducible}(e) \implies \\
%  &(\All \state, \expr_2, \state_2. \cfg{\state}{\expr} \step \cfg{\state_2}{\expr_2} \implies \state_2 = \state \land \expr_2 = \expr') \implies \\
%  &{} \proves (\hoare{\prop}{\expr'}{\Ret\val. \propB}[\mask] \Ra \hoare{\later\prop}{\expr}{\Ret\val. \propB}[\mask] ) \\
%  \quad \\
%  &\All \expr, \state, \pred, \mask. \\
%  &\textlog{atomic}(e) \implies \\
%  &\bigl(\All \expr_2, \state_2. \cfg{\state}{\expr} \step \cfg{\state_2}{\expr_2} \implies \pred(\expr_2, \state_2)\bigr) \implies \\
%  &{} \proves (\hoare{ \ownPhys{\state} }{\expr}{\Ret\val. \Exists\state'. \ownPhys{\state'} \land \pred(\val, \state') }[\mask] )
% \end{align*}
% The first is restricted to deterministic pure reductions, like $\beta$-reduction.
% The second is suited to proving triples for (possibly non-deterministic) atomic expressions; for example, with $\expr \eqdef \;!\ell$ (dereferencing $\ell$) and $\state \eqdef h \mtimes \ell \mapsto \valB$ and $\pred(\val, \state') \eqdef \state' = (h \mtimes \ell \mapsto \valB) \land \val = \valB$, one obtains the axiom $\All h, \ell, \valB. \hoare{\ownPhys{h \mtimes \ell \mapsto \valB}}{!\ell}{\Ret\val. \val = \valB \land \ownPhys{h \mtimes \ell \mapsto \valB} }$.
% %Axioms for CAS-like operations can be obtained by first deriving rules for the two possible cases, and then using the disjunction rule.

\subsection{Adequacy}

The adequacy statement reads as follows:
\begin{align*}
 &\All \mask, \expr, \val, \pred, \state, \melt, \state', \tpool'.
 \\&(\All n. \melt \in \mval_n) \Ra
 \\&( \ownPhys\state * \ownGGhost\melt \proves \wpre{\expr}{x.\; \pred(x)}[\mask]) \Ra
 \\&\cfg{\state}{[\expr]} \step^\ast
     \cfg{\state'}{[\val] \dplus \tpool'} \Ra
     \\&\pred(\val)
\end{align*}
where $\pred$ is a \emph{meta-level} predicate over values, \ie it can mention neither resources nor invariants.

% RJ: If we want this section back, we should port it to primitive view shifts and prove it in Coq.
% \subsection{Unsound rules}

% Some rule suggestions (or rather, wishes) keep coming up, which are unsound. We collect them here.
% \begin{mathpar}
% 	\infer
% 	{P \vs Q}
% 	{\later P \vs \later Q}
% 	\and
% 	\infer
% 	{\later(P \vs Q)}
% 	{\later P \vs \later Q}
% \end{mathpar}

% Of course, the second rule implies the first, so let's focus on that.
% Since implications work under $\later$, from $\later P$ we can get $\later \pvs{Q}$.
% If we now try to prove $\pvs{\later Q}$, we will be unable to establish world satisfaction in the new world:
% We have no choice but to use $\later \pvs{Q}$ at one step index below what we are operating on (because we have it under a $\later$).
% We can easily get world satisfaction for that lower step-index (by downwards-closedness of step-indexed predicates).
% We can, however, not make much use of the world satisfaction that we get out, becaase it is one step-index too low.

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "iris"
%%% End:


\BoSSSopen{GridGeneration/GridGeneration}
\graphicspath{{GridGeneration/GridGeneration.texbatch/}}

\BoSSScmd{
restart
 }
\BoSSSexeSilent
\BoSSScmd{
/// This tutorial demostrates the creation, resp. the import of grids/meshes
/// into \BoSSS.
 }
\BoSSSexe
\BoSSScmd{
/// \section{Cartesian 2D grids}
/// A 2D Cartesian mesh can be created form an array of $x$- and $y$-nodes
/// via the method \code{Grid2D.Cartesian2DGrid}.
/// Note that the number of nodes needes to be equal to the
/// number of cells $+1$. For instance, for $10$ cells we need $11$ nodes.
 }
\BoSSSexe
\BoSSScmd{
int Res = 10;\newline
double[] xNodes = GenericBlas.Linspace(0, 1, Res + 1);\newline
double[] yNodes = GenericBlas.Linspace(0, 1, Res + 1);\newline
int J           = (xNodes.Length - 1)*(yNodes.Length - 1);\newline
string GridName = string.Format(WorkflowMgm.CurrentProject + "\_J" +J);\newline
 \newline
Console.WriteLine("Creating grid with " + J + " cells. ");\newline
 \newline
GridCommons g;\newline
g      = Grid2D.Cartesian2DGrid(xNodes, yNodes);\newline
g.Name = GridName;
 }
\BoSSSexe


\chapter{Code}

\section{recurrences.py}
\begin{adjustwidth}{-4cm}{0cm}
    \inputminted{python}{../src/recurrences.py}
\end{adjustwidth}

\section{sums.py}

\begin{adjustwidth}{-4cm}{0cm}
    \inputminted{python}{../src/sums.py}
\end{adjustwidth}

\section{doubly-indexed-recurrences.py}

\begin{adjustwidth}{-4cm}{0cm}
    \inputminted{python}{../src/doubly-indexed-recurrences.py}
\end{adjustwidth}

\section{Repository}

This project is under version control as a \emph{Git} repository
\footnote{\url{https://github.com/massimo-nocentini/recurrences-unfolding}}
and sandbox Jupyter notebooks are available on line about recurrence
unfoldings\footnote{\url{http://nbviewer.jupyter.org/github/massimo-nocentini/recurrences-unfolding/blob/master/sympy-notebook/recurrences-unfolding.ipynb?flush_cache=true}},
binomial transforms\footnote{\url{http://nbviewer.jupyter.org/github/massimo-nocentini/recurrences-unfolding/blob/master/sympy-notebook/binomial-transform-applied-to-fibonacci-numbers.ipynb?flush_cache=true}}
and doubly indexed recurrences\footnote{\url{http://nbviewer.jupyter.org/github/massimo-nocentini/recurrences-unfolding/blob/master/sympy-notebook/matrix-recurrences-unfolding.ipynb?flush_cache=True}}.


%!TEX root = ../TTT4150-Summary.tex
\section{GPS coordinate frames, time reference, and orbits}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Global coordinate systems}

\subsubsection{Conventional terrestrial reference system (CTRS)}
The \emph{pole of rotation} moves relative to the true pole. The \emph{Conventional terrestrial pole} (CTP) is a defined position corresponding to the average position of the pole of rotation between 1900 and 1905. With this, CTRS is defined with
\begin{itemize}
    \item origin at Earth mass center,
    \item $z$-axis through the CTP,
    \item $x$-axis through the intersection of CTP's equatorial plane and a reference meridian, and
    \item $y$-axis to complete a right-handed system.
\end{itemize}

In practice, this is implemented as the coordinate system that best fits a number of reference points with assigned coordinates.

\subsubsection{Conventional inertial reference system (CIRS)}
An inertial frame is nonaccelerating. CTRS spins with the Earth, and is therefore not inertial. Defined with
\begin{itemize}
    \item origin at Earth mass center,
    \item $z$-axis along the axis of rotation,
    \item $x$-axis in the equatorial plane, toward the vernal equinox,
    \item $y$-axis to complete a right-handed system.
\end{itemize}

\subsubsection{International terrestrial reference frame (ITRF)}
More accurate realization of CTRS than WGS 84 ECEF, used for research. Defined from a large number of reference stations around the world.

\subsubsection{WGS 84}
A realization of CTRS. It defines
\begin{itemize}
    \item an ECEF Cartesian coordinate frame,
    \item an ellipsoid model of the Earth,
    \item a characterization of Earth's gravity field and geoid, and
    \item some constants.
\end{itemize}
and its parameters are:
\begin{itemize}
    \item Semi-major axis $a$
    \item Reciprocal flattening $\frac{1}{f}$
    \item Earth's angular velocity $\omega_E$
    \item Earth's gravitational constant $GM$
    \item Speed of light in vacuum $c$
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{GPS orbits}

\begin{figure}[htbp]
    \centering
    \includegraphics[width=\linewidth]{img/satellite-anomalies.pdf}
    \caption{True anomaly $V$ and eccentric anomaly $E$}
    \label{fig:orbital-anomalies}
\end{figure}

\subsubsection{Kepler's laws}
The laws are modified for satellites orbiting Earth.

\begin{enumerate}
    \item The satellite orbit is an ellipse with Earth at one focus.
    \item The line between the satellite and Earth sweeps over equal areas during equal intervals of time. (I.e. faster close to Earth.)
    \item The square of the orbital period is proportional to the cube of the semi-major axis of the orbit: $T^2 \propto a^3$
\end{enumerate}

\subsubsection{Keplerian elements}

\begin{figure}[htbp]
    \centering
    \includegraphics[width=.9\linewidth]{img/kepler-elements.png}
    \caption{Some Kepler elements, expressed generally, not terrestrially}
    \label{fig:kepler}
\end{figure}

The Keplerian elements are given at a specific epoch, and are as follows:

\begin{enumerate}
    \item[$a$]
        \textbf{Semi-major axis} $a$: Length of the semi-major axis of the elliptical orbit.
    \item[$e$]
        \textbf{Eccentricity} $e$: The eccentricity of the elliptical orbit.
    \item[$i$]
        \textbf{Orbital inclination} $i$: The orbital plane intersects the Earth center, but usually at an angle relative to the equator. This angle is the inclinaton.
    \item[$\Omega$]
        \textbf{Right ascension of the ascending node} $\Omega$: First: The intersection between the equator and the orbital plane is called the line of nodes. The nodes are the two points where the line intersects the surface. The ascending node is the node above which the satellite ascends (passes in a south to north direction).

        The RAAN is then the angle from the direction of the vernal equinox to the ascending node. The vernal equinox is a fixed point in the sky above equator, not rotating with Earth. (The vernal equinox is actually the ascending node of the Sun, meaning the sun has $\Omega = 0$.)

        In Figure \ref{fig:kepler}, it is called ``longitude of ascending node''.
    \item
        \textbf{Argument of perigee} $\omega$: The perigee is the point of the orbit closest to Earth. The argument of perigee is the angle between the ascending node and the perigee, as seen from Earth.

        In Figure \ref{fig:kepler}, this is called ``argument of periapsis''.
    \item
        \textbf{True anomaly} $\nu$: The angle between the perigee and the satellite, as seen from Earth.
\end{enumerate}

\subsubsection{Satellite position and velocity}

The orbital plane is specified fully by $a$, $e$, $i$, $\Omega$, and $\omega$ defined above. If we know $\nu$ at an epoch, we can find the position at any given time. In addition to \emph{true} anomaly $\nu$, we have \emph{eccentric} anomaly and \emph{mean} anomaly are defined:
\begin{itemize}
    \item
        \textbf{Eccentric anomaly} $E$: The angle between the perigee and the projection of the satellite onto a circle of radius $a$, as seen from the center of the orbit. See angle ``E'' in Figure \ref{fig:orbital-anomalies}.
    \item
        \textbf{Mean anomaly} $M$: The angle between the perigee and the place the satellite would have been had it been on a circular orbit with the same focus and period. See angle ``M'' in Figure \ref{fig:orbital-anomalies}.
\end{itemize}

\paragraph{Kepler's equation}
$E$ and $M$ are related by \emph{Kepler's equation}:
\begin{equation}
    M = E - e \sin E
\end{equation}

\subsubsection{Perturbations}
\emph{Precession} (period \SI{25800}{years}) and \emph{nutation} (\SI{18.6}{years}) affect satellite orbits.


\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{listings}

\begin{document}
\title{Algorithms, Optimization, Optimization Package 1}

The Optimize package in Scipy has several types of optimizing algorithms. This lab will introduce some of the basic types of algorithms included.

You can learn about all of the functions at
%\url{http://docs.scipy.org/doc/scipy/reference/optimize.html}.

Last week, a word reached your village that the dread pirate Roberts buried some treasure at the lowest point of a nearby valley. $5$ men immediately prepared to reclaim the treasure. Afraid of the competition, they each asked the village sage for advice on how to reach the treasure faster than the others. Deciding that the pursuit of knowledge was more important than gold, the sage conducted an experiment on the men. Each man was given a different formula to reach the bottom.

The algorithms were
\begin{itemize}
\item Downhill Simplex
\item Conjugate Gradient
\item BFGS
\item Modified Powell
\item Newton Conjugate Gradient
\end{itemize}

You may recognize some of these algorithms, and several of them will be discussed in greater detail later. For this lab, you do not need to understand how they work.

The valley, seen in the topographical figure below, is represented by the Rosenbrock Function,
which satisfies the equation

\begin{center}
$f(x,y) = (1-x)^2 + 100(y-x^2)^2$

\includegraphics[height=50mm]{Rosenbrock_function.png}
\end{center}

\textbf{Problem 1}
Use the scipy optimizeu package to answer the following questions using

$x_0 = [1.3,.7,.8,1.9,1.2], x_0 = [21,15], x_0 = [-1.2, 3, 12]$:

\begin{itemize}
\item Where is the treasure buried?
\item In which order did they reach the treasure? Was this consistent from each $x_0$.
\item Where there any men who didn't reach treasure?
\end{itemize}

The Rosenbrock fuction is a common optimization algorithm checking function, so it is included in the optimize package. You can either define or import it.  Note that for some algorithms, you'll need the gradient and/or hessian.

\section*{Example}
Here's an example of the Nelder-Mead simplex and the Newton Conjugate Gradient algorithms.

\begin{lstlisting}
: def rosen(x):
: 		return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0))

: x0 = np.array([1.3, 0.7, 0.8, 1.9, 1.2])

: print opt.fmin(f, x0)

: f = opt.rosen
: fprime = opt.rosen_der
: print opt.fmin_ncg(rosen,x, fprime, fhess=opt.rosen_hess)
\end{lstlisting}

\end{document}


\chapterp{4p}{Performance quantification of online SWR detectors}
\label{ch:eval}

\Cref{ch:offline} described how we annotated our dataset with `reference' SWR segments, using an offline algorithm. These reference segments can now be used to benchmark the performance of an online SWR detection algorithm. This section describes how this is done.

% todo: compare with lit (notably Dutta)

\section{Generating online detections}

Each online SWR detection algorithm studied in this thesis generates an output envelope $n_t$, where samples $n_t$ of larger magnitude denote a higher belief that the corresponding input sample $\z_t$ is part of an SWR event. (See \panelref{fig:LSM-comp}{A} for three example output envelopes).

These output envelopes $n_t$ can be converted to a discrete set of detection times by applying a threshold $T$ to the envelope.\footnotemark{} Additionally, we require a certain minimum duration between online detections (which we will call the ``lockout time'', $L$). The set $D$ of detection times $t_d$ (with $d = 0, 1, \tdots$) is then:
\begin{equation}
D = \{ \ t_d \mid \  n_{t_d} > T  \quad
                  \text{and} \quad  t_d > t_{d-1} + L  \ \}.
\end{equation}

\footnotetext{In general, this threshold can be adaptive (based on a moving average of signal statistics, for example), and we should therefore write ``$T_t$'' to be precise. In this thesis we only evaluate online detectors using constant thresholds $T$.}

In our analysis, we chose a lockout time $L$ based on SWR durations. Specifically, we set $L$ to the 25-th percentile of the durations of all SWR segments detected in our dataset by the offline algorithm, resulting in a lockout time $L = $ 34 ms.
% Todo: lit review of lockout times (in Scraps already I think)

The threshold $T$ is generally set by the user of the online SWR detection algorithm (see the discussion in the next section).

\section{Quantifying accuracy}

In the following, we denote reference SWR segments as the closed intervals $s_r = [ t\start_r,\ t\eend_r ]$ (with $r = 0, 1, \tdots$). The set of all reference segments is denoted by $S = \{ s_r \}$.

To benchmark the performance of an online SWR detection algorithm (at a certain threshold $T$), we compare its detections $D$ with the offline reference segments $S$, and divide both sets into two subsets each: namely detected versus undetected reference segments, and correct versus incorrect detections. Formally:
%
\begin{align}
D\correct    &= \{ t_d \mid \exists s_r : t_d \in s_r \}   \\
D\incorrect  &= D \setminus D\correct                      \\
S\detected   &= \{ s_r \mid \exists t_d : t_d \in s_r \}   \\
S\undetected &= S \setminus S\detected,
\end{align}
%
i.e. correct online detections are contained within a reference segment, and detected reference segments contain at least one online detection. \Panelref{fig:LSM-comp}{A} shows some example correct and incorrect detections (green and red triangles, respectively).

Next, the number of detected reference segments is counted, and compared to the total number of reference segments. This fraction is the \textbf{recall $R$} of the SWR detector (also known as sensitivity, hit rate, or true positive rate):
\begin{equation}
R = \frac{\abs{S\detected}}{\abs{S}}
  = \frac{\text{\# of detected reference segments}}
         {\text{total \# of reference segments}}
\end{equation}

Similarly, the number of correct detections is counted, and compared to the total number of detections. This fraction is the \textbf{precision $P$} of the SWR detector (also known as the positive predictive value):
\begin{equation}
P = \frac{\abs{D\correct}}{\abs{D}}
  = \frac{\text{\# of correct detections}}
         {\text{total \# of detections}}
\end{equation}

Its opposite is the false discovery rate (FDR), which counts the number of so called ``false positive'' detections:
\begin{align}
FDR = \frac{\abs{D\incorrect}}{\abs{D}}
    = \frac{\text{\# of incorrect detections}}
           {\text{total \# of detections}}
   = 1 - P
\end{align}

Each detection threshold yields a different $(P, R)$-combination. This is often a trade-off: higher thresholds yield more precise detectors (less false positive detections), at the cost of a lower sensitivity (more missed reference SWR segments). Conversely, lower thresholds generally yield more sensitive but also less precise SWR detectors.

This is why the performance of a detection algorithm is often given for a \emph{range} of thresholds, instead of for just a single threshold: different users of the SWR detection algorithm may prefer different trade-offs between latency and precision. (One user might require a minimal amount of false detections, for example, while another may want to detect as many SWR events as possible, without minding false detections). When precision and recall are plotted against each other for a range of different thresholds, the result is a so called ``$PR$-curve'' (see the lower-left panel of \cref{fig:LSM-PR-and-latency} for an example). Generally, higher quality detectors have $PR$-curves that draw nearer to the top-right $(1, 1)$-corner.

\begin{figure}
\img{iso-F-lines}
\captionn{Iso-$F_\beta$-curves}{}
\label{fig:iso-F-lines}
\end{figure}

The precision $P$ and recall $R$ for a given threshold can be summarized in a single number: the so called $F$-score. It is defined as:
\begin{equation}
F_\beta = \frac{(1+\beta^2) P R}{\beta^2 P + R}.
\end{equation}
It is the mean of recall and precision (more precisely: their harmonic mean, as precision and recall are ratio's), with recall weighted by $\beta^2$. It measures detection performance ``for a user who attaches $\beta$ times as much importance to recall as to precision.'' \cite{Rijsbergen1979}

For example, the $F_1$-score weighs recall and precision equally. When we want to summarize the accuracy of a detector in a single number, we will often choose the \emph{maximum} $F_1$-score of the detector (over the entire threshold range) as this number.

For an idea of the relationship between $P$, $R$, and $F$-scores, see \cref{fig:iso-F-lines}.

A note on terminology: we will refer to the precision and sensitivity performance of a detector often simply as the `accuracy' of the detector. This is a shorthand, and does not refer to the technical definition of accuracy.\footnotemark{}

\footnotetext{Technically, accuracy is the sum of true positive and true negative cases, divided by the total number of cases. This concept does  does not readily apply to SWR detection, as there is no straightforward definition of "true negative" cases here. Only false positives ($D\incorrect$), true positives ($D\correct$ and $S\detected$), and false negatives ($S\undetected$) are clearly defined.\newline
Note that there are two types of ``true positives'': correct detections $\in D\correct$, and detected reference segments $\in S\detected$ (with $\abs{D\correct} \geq \abs{S\detected}$, because one reference segment may contain multiple detections).}

\section{Quantifying latency}

Besides counting how many SWR segments were detected, we are also interested in how early they were detected. For each detected reference segment $s_r = [ t\start_r,\ t\eend_r ]$, we note the first online detection $t_d$ contained within it (reference segments may contain multiple online detections).

The absolute detection latency of this SWR segment is then defined as:
\begin{equation}
L\abso_r = t_d - t\start_r
\end{equation}

We also define a detection latency relative to the duration of the SWR segment in question:
\begin{equation}
L\rela_r = \frac{L\abso_r}{t\eend_r - t\start_r}
\end{equation}

Whereas an SWR detector yields only a single precision and a single recall value for a given threshold, it yields two entire sets of absolute and relative detection latencies (namely an absolute and a relative latency value for each detected reference segment). This is why we often summarize latency performance using the median of one of these sets. When not otherwise specified, the latency distribution (or its median) corresponding to the threshold with maximal $F_1$-score is reported.


\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{url}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{geometry}
\usepackage[font=small,labelfont=bf]{caption}
\pdfpagewidth 8.5in
\pdfpageheight 11in
\setlength\topmargin{0in}
\setlength\headheight{0in}
\setlength\headsep{0in}
\setlength\textheight{9in}
\setlength\textwidth{6.5in}
\setlength\oddsidemargin{0in}
\setlength\evensidemargin{0in}
\setlength\headheight{0pt}
\setlength\headsep{0in}
\setlength\parskip{11pt}
\setlength\parindent{1in}

\title{RSA Encryption}
\author{Josh Cai}
\date{November 28, 2011}

\begin{document}
\maketitle
\section{Introduction}
Encryption has been studied thoroughly by militaries and governments for secure communication. Encyption, the process of altering data to render it undeciperable by other individuals, allows only users with a special "key" to read the encrypted texts by performing a reverse algorithm for decryption. There are two main types of encryption: private key encryption and public key encryption. In private key encryption, the sender and receiver both own seperate algorithms for encrypting and decrypting. The key, however, must be exchanged in person as people who obtain access to the key by other means can decode all messages from the sender. Public key encryption removes the need for this, as the sender contains a private key used to decode messages encrypted from the receiver using a public key. Public key encryption has become increasingly popular as it is viewed as the more secure option.

\section{RSA Encryption}
RSA encryption is a form of public key encryption created by Ron Rivest, Adi Shamir, and Leonard Adleman that works due to the inability of computers to factor very large integers. It was first developed by Clifford Cocks, who was an English mathematician working for the United Kingdom and kept the encryption technique private. It was later independently discovered by Rivest, Shamir, and Adleman and publicly released it in 1978. The actual process of the RSA algorithm follows three steps: key generation, encryption, and decryption.
\subsection{Key Generation}
The receiver begins by choosing two prime numbers, $p$ and $q$. For the RSA algorithm to be secure, $p$ and $q$ must be large enough such that $n = pq$ is hard for a computer to factor. After computing $n$, the person computes $\varphi(n)$. $\varphi(n)$ is Euler's totient function, defined to be the number of relatively prime integers less than or equal to $n$. Since $n$ is the product of two primes, we can see that $\varphi(n)$ is $(p-1)(q-1)$. Following this, the receiver chooses an integer $e$ such that $1<e<\varphi(n)$ and $e$ is relatively prime to $\varphi(n)$. Finally, the person finds an integer $d$ such that $d*e$ (mod $\varphi(n))$ is congruent to 1.
\subsection{Encryption}
The receiver transmits n and e to the sender as public keys. The sender then encrypts his message $m$, which is in the form of a number, by computing $m^e$ (mod $n$). The sender passes this ciphertext, labeled $c$, to the receiver.

\subsection{Decryption}
Since only the receiver has the private keys, only that person can decrypt $c$. The receiver decrypts message $c$ by computing $c^d$ (mod $n$). The receiver now has the message $m$ that the sender encrypted.

\section{Why It Works}
To show that the RSA algorithm works, we must show that $m \equiv m^{e^d} \pmod{n}$. We know that $m^{e^d}$ is the same as $m^{ed}$, and we chose $ed$ to be congruent to $1 \pmod{\varphi(n)}$. This means that $ed = 1+k\varphi(n)$, for some integer $k$. So $m^{e^d} \equiv m^{ed} \equiv m^{1+k\varphi(n)} \equiv m(m^{k\varphi(n)}) \equiv m((m^{\varphi(n))^k}) \equiv m(1^k) \equiv m \pmod{n}$. So $m \equiv m^{e^d} \pmod{n}$, which means that the algorithm works. ($m^{\varphi(n)}$ is congruent to $1 \pmod{n}$ by Euler's theorem.)

\section{Example One}

To see how the RSA algorithm works, we work through two examples with different prime numbers. For the first example, we use $p$ = 23 and $q$ = 41. We compute $n=pq$ to be (23)(41)=943. We now find $\varphi(943) = (p-1)(q-1) = (22)*(40) = 880$. We now choose $e$, which must be relatively to 880, so we pick 7. We find a number $d$, such that $7d  \equiv 1 \pmod{880}$: 503, since 7*503 = 3521, which is congruent to 1 $\pmod{880}$. We have finished the key generation step, and now proceed to the encryption and decryption of a message. A person wants to encrypt the message $m$ = 35 and send it to the person holding the private keys. Since the person encrypting knows the public keys $n$ and $e$, he computes $c = m^e$ (mod n) = $35^7$ (mod 943). $35^7$ (mod 943) is congruent to 64339296875 (mod 943), which is congruent to 545. This person sends the ciphertext 545 to the person holding the private keys, where he begins the decryption process. The second person now takes 545 and computes $545^{503}$ (mod 943). After reducing many times, we obtain 35, the original message $m$ sent by the first person.

\section{Example Two}
We choose primes $p$ = 5 and $q$ = 2. $n$ = 2*5 = 10. $\varphi(n)=(p-1)(q-1)=1*4 = 4$. We choose $e$ = 3, since 3 and 4 are relatively prime. We see that a choice of $d$=7 works, because 21 is 1 (mod 4). We choose to encrypt the string 'ABCD', taking the convention that A=1, B=2, etc. We first change the message into numeric form; while doing so, we must break the message into four seperate numbers. 'ABCD' becomes 1 2 3 4, and we encrypt each one separately. $1^3$ $\equiv$ 1 (mod 10), $2^3$ $\equiv$ 8 (mod 10), $3^3$ $\equiv$ 27 $\equiv$ 7 (mod 10), and $4^3$ $\equiv$ 64 $\equiv$ 4 (mod 10). Our encrypted message becomes 1 8 7 4. The person decrypting our message computes the following: $1^7$ $\equiv$ 1 (mod 10), $8^7$ $\equiv$ 2097152 $\equiv$ 2 (mod 10), $7^7$ $\equiv$ 823543 $\equiv$ 3 (mod 10), and $4^7$ $\equiv$ 16384 $\equiv$ 4 (mod 10). The decrypted message becomes 1 2 3 4, which he or she converts to 'ABCD' and receives the message successfully.

\section{References}
The following websites were used in creating this report:

\url{http://www.wdvl.com/Style/Tools/Tutorial/public_vs_private.html}

\url{http://en.wikipedia.org/wiki/RSA_%28algorithm%29}

\url{http://en.wikipedia.org/wiki/Euler%27s_totient_function}

\url{http://www.geometer.org/mathcircles/RSA.pdf}

\end{document}


\chapter{The Curvelet Transform}
\section{Introduction}
 Wavelets and related multiscale representations pervade  all
areas of signal processing. The recent inclusion of wavelet algorithms
in JPEG 2000, the new still-picture compression standard, testifies
to this lasting and significant impact.
The most used
wavelet transform algorithm is the decimated bi-orthogonal
wavelet transform (OWT). Using the OWT, a signal $s$ can be decomposed
by:
\begin{eqnarray}
  s(l) = \sum_{k} c_{J,k} \phi_{J,l}(k)
        +  \sum_{k} \sum_{j=1}^J \psi_{j,l}(k) w_{j,k}
 \end{eqnarray}
 with $\phi_{j,l}(x) = 2^{-j} \phi(2^{-j}x-l)$ and $\psi_{j,l}(x) =
 2^{-j} \psi(2^{-j}x-l)$, where $\phi$ and $\psi$ are respectively the
 scaling function and the wavelet function.  $J$ is the number of
 resolutions used in the decomposition, $w_{j}$ the wavelet (or
 detail) coefficients at scale $j$, and $c_{J}$ is a coarse or smooth
 version of the original signal $s$.  Thus, the algorithm outputs $J+1$
 subband arrays.  The indexing is such that, here, $j = 1$ corresponds
 to the finest scale (high frequencies).

The application of the OWT to image compression, using the 7-9 filters
 \cite{wave:antonini92} and the zerotree coding
\cite{compress:shapiro93,compress:said96} has lead to impressive
results, compared to previous methods like JPEG.

A series of recent papers
\cite{Roysoc,Curvelets-StMalo}, however, argued that wavelets and related
classical multiresolution ideas are playing with a limited dictionary
made up of roughly isotropic elements occurring at all scales and
locations. We view as a limitation the facts that those dictionaries
do not exhibit highly anisotropic elements and that there is only a
fixed number of directional elements, independent of scale.
Despite the success of the classical wavelet viewpoint, there are objects,
e.g.\  images, that do
not exhibit isotropic scaling and thus call for other kinds of
multiscale representation. In short, the theme of this line of
research is to show that classical multiresolution ideas only address
a portion of the whole range of interesting multiscale phenomena and
that there is an opportunity to develop a whole new range of
multiscale transforms.

Following on this theme, Cand\`es and Donoho in\-tro\-du\-ced new mul\-ti\-scale
systems like curvelets \cite{Curvelets-StMalo} and ridgelets \cite{Harmnet}
which are very different from wavelet-like systems. Curvelets and
ridgelets take the form of basis elements which exhibit very high
directional sensitivity and are highly anisotropic.  In
two-dimensions, for instance, curvelets are localized along curves, in
three dimensions along sheets, etc.  Continuing at this informal level
of discussion we will rely on an example to illustrate the fundamental
difference between the wavelet and ridgelet approaches, postponing
the mathematical description of these new systems.

We investigate in this document the best way to implement
the ridgelet and the curvelet transform for the purpose of image restoration.
The second and third sections describe respectively
the ridgelet transform and the curvelet transform.
Section four shows how the ridgelet and the wavelet coefficients can be
thresholded in order to filter an image. Comparisons with other methods
are presented. Instructions for using the programs are given in the last
section.

\begin{figure}[htb]
\centerline{
\vbox{
\hbox{
\psfig{figure=fig_bar_noise.ps,bbllx=1.7cm,bblly=12.5cm,bburx=14.7cm,bbury=25.5cm,width=6.5cm,height=6.5cm,clip=}
\psfig{figure=fig_bar_coupe.ps,bbllx=2.5cm,bblly=13.5cm,bburx=19.5cm,bbury=25.5cm,width=6.5cm,height=6.5cm,clip=}
}
\hbox{
\psfig{figure=fig_bar_wave.ps,bbllx=1.7cm,bblly=12.5cm,bburx=14.7cm,bbury=25.5cm,width=6.5cm,height=6.5cm,clip=}
\psfig{figure=fig_bar_rid.ps,bbllx=1.7cm,bblly=12.5cm,bburx=14.7cm,bbury=25.5cm,width=6.5cm,height=6.5cm,clip=}
}}}
\caption{Top left, original image containing a vertical band embedded in
white noise with relatively large amplitude.  Top right, row sums
illustrating the hardly perceptable band.  Bottom left,
reconstructed image using undecimated wavelet coefficients. Bottom right,
reconstructed image using ridgelet coefficients.}
\label{fig_bar}
\end{figure}

Consider an image which contains a vertical band embedded in white
noise with relatively large amplitude.  Figure~\ref{fig_bar} (top
left) represents such an image.  The parameters are as follows: the
pixel width of the band is 20 and the SNR (signal-to-noise ratio)
is set to be $0.1$. Note
that it is not possible to distinguish the band by eye. The wavelet
transform (undecimated wavelet transform) is also incapable of
detecting the presence of this object; roughly speaking, wavelet
coefficients correspond to averages over approximately isotropic
neighborhoods (at different scales) and those wavelets clearly do not
correlate very well with the very elongated structure (pattern) of
the object to be detected.

We now turn our attention towards procedures of a very different
nature which are based on line measurements. To be more specific,
consider an {\em ideal} procedure which consists of integrating the
image intensity over columns; that is, along the orientation of our
object.  We use the adjective ``ideal'' to emphasize the important
fact that this method of integration requires a priori knowledge about
the structure of our object. This method of analysis gives of course
an improved signal-to-noise ratio for our linear functional better
which is better correlated with the object in question:
see the top right panel of
Figure~\ref{fig_bar}.

This example will make our point. Unlike wa\-velet trans\-forms, the
rid\-gelet trans\-form pro\-cesses data by first computing integrals over
lines with all kinds of orientations and locations. We will explain in
the next section how the ridgelet transform further processes those
line integrals. For now, we apply naive thresholding of the ridgelet
coefficients and ``invert'' the ridgelet transform; the bottom right
panel of Figure~\ref{fig_bar} shows the reconstructed image. The
qualitative difference with the wavelet approach is striking. We
observe that this method allows the detection of our object even in
situations where the noise level (standard deviation of the white
noise) is five times superior to the object intensity.

\section{Continuous Ridgelet Transform}

The two-dimensional continuous ridgelet transform in $\bR^2$ can be
defined as follows \cite{Harmnet}. We pick a smooth univariate
function $\psi:\bR \goto \bR$ with sufficient decay and satisfying the
admissibility condition
\begin{equation}
\label{eq:admissibility}
\int |\hat{\psi}(\xi)|^2/|\xi|^2 \, d\xi < \infty,
\end{equation}
which holds if, say, $\psi$ has a vanishing mean $\int
\psi(t) dt = 0$.  We will suppose that $\psi$ is normalized so that
$\int |\hat{\psi}(\xi)|^2 \xi^{-2} d\xi = 1$.

For each $a > 0$, each $b \in \bR$ and each $\theta \in [0,2\pi)$, we
define the bivariate {\em ridgelet} $\psi_{a,b,\theta}: \bR^2 \goto
\bR^2$
by
\begin{equation}
\label{eq:ridgelet}
       \psi_{a,b,\theta} (x) = a^{-1/2} \cdot
     \psi( (x_1 \cos\theta + x_2 \sin\theta  - b)/a);
\end{equation}
this function is constant along lines $x_1 \cos\theta + x_2 \sin\theta
= const$. Transverse to these ridges it is a wavelet.

\begin{figure}[htb]
\centerline{
\vbox{
\hbox{
\psfig{figure=ridgelet.eps,bbllx=0.5cm,bblly=6cm,bburx=20.5cm,bbury=21cm,width=5.5cm,height=5.5cm,clip=}
\psfig{figure=ridgerotate.eps,bbllx=0.5cm,bblly=6cm,bburx=20.5cm,bbury=21cm,width=5.5cm,height=5.5cm,clip=}
}
\hbox{
\psfig{figure=ridgescale.eps,bbllx=0.5cm,bblly=6cm,bburx=20.5cm,bbury=21cm,width=5.5cm,height=5.5cm,clip=}
\psfig{figure=ridgeshift.eps,bbllx=0.5cm,bblly=6cm,bburx=20.5cm,bbury=21cm,width=5.5cm,height=5.5cm,clip=}
}
}}
\caption{A few ridgelets.}
\label{fig_rid_function}
\end{figure}

Figure~\ref{fig_rid_function} graphs a few ridgelets with different
parameter values. The top right, bottom left and right panels
are obtained after simple geometric manipulations of the upper left
ridgelet, namely rotation, rescaling, and shifting.

Given an
integrable bivariate function $f(x)$, we define its ridgelet
coefficients by
\[
\cR_f(a,b,\theta) = \int \psi_{a,b,\theta}(x) f(x) dx.
\]
We have the exact reconstruction formula
\begin{equation}
\label{eq:CRT}
f(x) = \int_0^{2\pi} \int_{-\infty}^\infty \int_0^\infty
\cR_f(a,b,\theta) {\psi}_{a,b,\theta}(x) \frac{da}{a^3} db
\frac{d\theta}{4\pi}
\end{equation}
valid a.e.\ (almost everywhere)
for functions which are both integrable and square
integrable. Furthermore, this formula is stable since we have a Parseval
relation
\begin{equation}
\label{eq:Parseval}
       \int |f(x)|^2 dx = \int_0^{2\pi} \int_{-\infty}^\infty
\int_0^\infty
|\cR_f(a,b,\theta)|^2 \frac{da}{a^3} db \frac{d\theta}{4\pi}.
\end{equation}
Hence, much like the wavelet or Fourier transforms, the identity
(\ref{eq:CRT}) expresses the fact that one can represent any arbitrary
function as a continuous superposition of ridgelets.  Discrete
analogs of (\ref{eq:CRT})-(\ref{eq:Parseval}) exist, see
\cite{Harmnet}, or \cite{Ortholinear} for a slightly different
approach.

\subsection{The Radon Transform}

A basic tool for calculating ridgelet coefficients is to view ridgelet
analysis as a form of wavelet analysis in the Radon domain. We recall
that the Radon transform of an object $f$ is the collection of line
integrals indexed by $(\theta,t) \in [0,2\pi) \times \bR$ given by
\begin{equation}
      \label{eq:Radon}
      Rf(\theta,t) = \int f(x_1,x_2)
\delta(x_1 \cos\theta + x_2 \sin\theta - t)\, dx_1 dx_2,
\end{equation}
where $\delta$ is the Dirac distribution. The ridgelet coefficients
$\cR_f(a,b,\theta)$ of an object $f$ are given by analysis of the Radon
transform via
\[
\cR_f(a,b,\theta) = \int Rf(\theta,t) a^{-1/2} \psi((t - b)/a) \, dt.
\]
Hence the ridgelet transform is precisely the application of a
1-dimensional wavelet transform to the slices of the Radon transform
where the angular variable $\theta$ is constant and $t$ is varying.

\subsection{Ridgelet Pyramids}
\label{sec:pyramid}

Let $Q$ denote a dyadic square $Q = [k_1/2^s,(k_1+1)/2^s) \times
[k_2/2^s, (k_2+1)/2^s)$ and let ${\cal Q}$ be the collection of all
such dyadic squares. We write ${\cal Q}_s$ for the collection of all
dyadic squares of scale $s$. Associated with the squares
$Q \in \cQ_s$ we construct a partition of energy
as follows. With $w$ a nice smooth window obeying
$ \sum_{k_1,k_2} w^2(x_1-k_1 , x_2 -k_2 ) = 1$,
we dilate and transport $w$ to all squares $Q$ at scale $s$,
producing a collection of windows $(w_Q)$ such that the
$w_Q^2$'s, $Q \in {\cal Q}_s$, make up a partition of unity.
We also let $T_Q$
denote the transport operator acting on
functions $g$ via
\[
(T_Q g)(x_1,x_2) = 2^s g(2^s x_1 - k_1,2^s x_2 - k_2).
\]
With this notation, it is not hard to see that
\[
f w_Q = \int \<f, w_Q T_Q {\psi}_{a,b,\theta} \>
     T_Q {\psi}_{a,b,\theta} \frac{da}{a^3} db
\frac{d\theta}{4\pi}
\]
and, therefore,
summing the above equality across squares at a given scale gives
\begin{equation}
      \label{eq:MRT}
f = \sum_{Q \in {\cal Q}_s} f w_Q^2 = \sum_Q \int \<f, w_Q T_Q
{\psi}_{a,b,\theta} \> w_Q T_Q {\psi}_{a,b,\theta} \frac{da}{a^3} db
\frac{d\theta}{4\pi}.
\end{equation}
The identity (\ref{eq:MRT}) expresses the fact that one can represent
any function as a superposition of elements of the form $w_Q T_Q
{\psi}_{a,b,\theta}$; that is, of ridgelet elements localized near the
squares $Q$. Associated with the
function $T_Q {\psi}_{a,b,\theta}$ is the ridgelet
$\psi_{a_Q,\theta_Q,b_Q}$ (\ref{eq:ridgelet}) with parameters obeying
\[
a_Q = 2^{-s} a, \quad \quad \theta_Q = \theta, \quad \quad b_Q = b +
k_1 2^{-s} \cos\theta + k_2 2^{-s}\sin\theta
\]
and thus $w_Q T_Q {\psi}_{a,b,\theta}$ is a windowed ridgelet,
supported near the square $Q$, hence the name {\em local ridgelet
      transform}.

The previous paragraph discussed the construction of local ridgelets
of fixed length, roughly $2^{-s}$ ($s$ fixed). Letting the scale $s$
vary defines the multiscale ridgelet dictionary
$\{\psi^Q_{a,b,\theta}: s \ge s_0, Q \in {\cal Q}_s, a > 0, b \in \bR,
\theta \in [0,2\pi)\}$ by
\[
\psi^Q_{a,b,\theta} = w_Q \, T_Q \psi_{a,b,\theta};
\]
that is, a whole pyramid of local ridgelets at various lengths and
locations. This is, of course, a massively overcomplete representation
system and no formula like (\ref{eq:MRT}) is available for this
multiscale ridgelet pyramid, because it is highly overcomplete.

\section{Digital Ridgelet Transform}
So the basic strategy for calculating the
continuous ridgelet transform is first to compute the Radon transform
$Rf(t,\theta)$ and second, to apply a one-dimensional wavelet
transform to the slices $Rf(\cdot,\theta)$.

Several digital ridgelet transforms have been proposed, and we will described
three of them in this section, based on different implementations of the
Radon transform.

\subsection{The RectoPolar Ridgelet transform}
In this section
we develop a digital procedure which is inspired by this viewpoint,
and is realizable on $n$ by $n$ numerical arrays.

 A fundamental fact about the Radon transform is the
projection-slice formula \cite{Deans}:
\[
\hat{f}(\lambda \cos\theta, \lambda \sin\theta) = \int Rf(t,\theta)
e^{-i\lambda t} dt.
\]
This says that the Radon transform can be obtained by applying the
one-dimensional inverse Fourier transform to the two-dimensional
Fourier transform restricted to radial lines going through the origin.

This of course suggests that approximate Radon transforms
for digital data can be based on discrete fast Fourier
transforms. This is a widely used approach,
in the literature of medical imaging and
synthetic aperture radar imaging, for which the
key approximation errors and artifacts have been widely discussed.
In outline, one
simply does the following, for
gridded data $(f(i_1,i_2))$, $0 \le i_1, i_2 < n-1$.
\begin{enumerate}
\item {\em 2D-FFT}. Compute the two-dimensional FFT of $f$ giving the
      array $(\hat{f}(k_1,k_2))$, $ -n/2 \le k_1, k_2 \le n/2 - 1$.
\item {\em Cartesian to Polar Conversion}. Using an interpolation
      scheme, substitute the sampled values of the Fourier transform
      obtained on the square lattice with sampled values of $\hat{f}$ on a
polar
      lattice: that is, on a lattice where the points fall on lines going
      through the origin.
\item {\em 1D-IFFT}. Compute the one-dimensional IFFT (inverse FFT)
     on each line,
      i.e.\ for each value of the angular parameter.
\end{enumerate}

The use of this strategy in connection with ridgelet transforms has
been discussed in the articles \cite{DRT,FRT,starck:sta01_3}.

\subsubsection{A Polar Sampling Scheme for Digital Data}

For our implementation of the Cartesian-to-polar
conversion, we have used a pseudo-polar
grid, in which the pseudo-radial variable has level sets which are squares
rather than circles. Starting with Oppenheim and Mersereau
\cite{MERSEREAU} this grid has often been called the {\it concentric
squares} grid in the signal processing literature; in the medical
tomography literature it is associated with the {\it linogram}
\cite{cur:edholm87,cur:edholm88}, while
in \cite{cur:averbuch01} it is called the rectopolar grid; see this  last
reference for a complete bibliographic treatment.  The geometry of the
rectopolar  grid is illustrated in Figure \ref{fig_radon}. We select $2
n$ radial lines in the frequency plane obtained by connecting the
origin to the vertices
$(k_1,k_2)$ lying on the boundary of the array $(k_1, k_2)$ , i.e. such
that $k_1$ or $k_2 \in \{-n/2, n/2\}$. The polar grid
$\xi_{\ell,m}$ ($\ell$ serves to index a given radial line while the
position of the point on that line is indexed by $m$) that we shall use
is the intersection between the set of radial lines and that of
Cartesian lines parallel to the axes.  To be more specific, the sample
points along a radial line ${\cal L}$ whose angle with the vertical
axis is less than or equal to $\pi/4$ are obtained by intersecting ${\cal
      L}$ with the set of horizontal lines $\{x_2 = k_2, \, k_2 = -n/2,
-n/2 + 1, \ldots, n/2\}$.  Similarly, the intersection with the
vertical lines $\{x_1 = k_1, \, k_1 = -n/2, -n/2 + 1, \ldots, n/2\}$
defines our sample points whenever the angle between ${\cal L}$ and the
horizontal axis is less than or equal to $\pi/4$.  The cardinality of the
rectopolar grid is equal to $2 n^2$ as there are $2 n$ radial lines and
$n$ sampled values on each of these lines. As a result,  data
structures associated with this grid will have a rectangular format. We
observe that this choice corresponds to irregularly spaced values of
the angular variable $\theta$.

\begin{figure}[htb]
\centerline{
\hbox{\psfig{figure=polar.eps,height=8cm,width=10cm,clip=}}
}
\caption{Illustration of the digital polar grid in the frequency domain for
          an $n$ by $n$ image $(n=8)$. The figure displays the set of
          radial lines joining pairs of symmetric points from the boundary
          of the square. The rectopolar grid is the set of points -- marked with
          circles -- at the intersection between those radial lines and
          those which are parallel to the axes.}
\label{fig_radon}
\end{figure}

\subsubsection{Interpolation to Rectopolar Grid}

To obtain samples on the rectopolar grid,
we should, in general, interpolate from
nearby samples at the Cartesian grid.
In principle, cf.\
\cite{cur:averbuch01,cur:donoho_02},
the interpolation of Fourier transforms is a
very delicate matter because of the well-known fact that
the Fourier transform of an image is highly oscillatory,
and the phase contains crucial information about the image.
In our approach, however, we use a crude interpolation method:
we simply impute for
$\hat{f}(\xi_{\ell,m})$ the value of the Fourier transform taken at
the point on the Cartesian grid nearest to
$\xi_{\ell,m}$.

There are, of course, more sophisticated ways to realize the
Cartesian-to-polar conversion; even simple bilinear interpolation
would offer better theoretical accuracy. A very high accuracy
approach used in \cite{FRT} consists of viewing the data
$(\hat{f}(k_1,k_2))$ as
samples of the trigonometric polynomial $F$ defined by

\begin{equation}
\label{eq:2d-poly}
F(\omega_1,\omega_2) = \sum_{i_1 = 0}^{n-1}  \sum_{i_2 =0}^{n-1}
    f(i_1,i_2) \exp\{-i(\omega_1 i_1 + \omega_2 i_2)\}
\end{equation}
on a square lattice; that is, with $\hat{f}(k_1,k_2) = F(\frac{2\pi
      k_1}{n},\frac{2\pi k_2}{n})$ with $ -n/2 \le k_1, k_2 < n/2$.
There turns out \cite{FRT,cur:averbuch01} to be an exact algorithm for
rapidly
finding the values of $F$ on the polar grid. The high-accuracy
approach can be used in reverse, allowing for exact reconstruction
of the original trigonometric polynomial from its rectopolar samples.

Our nearest-neighbor interpolation, although admittedly simple-minded,
happens to give  good results in our applications.
In fact numerical experiments show that in overall system
performance, it rivals the exact interpolation scheme.
This is explainable as follows.  Roughly speaking, the high-frequency
terms in the
trigonometric polynomial $F$ are associated with pixels at the boundary of
the underlying $n$ by $n$ grid.  Our crude interpolation evidently will
fail at reconstructing high-frequency terms. However, in the curvelet
application -- see below -- we use a window function to downweight
the contributions of our reconstruction near the boundary of the image
array.
So, inaccuracies in
reconstruction caused by our crude interpolation can be expected to
be located mostly in regions which make little visual
impact on the reconstruction.

A final point about our implementation. Since we are
interested in noise removal, avoiding
artifacts is very important.  At the  signal-to-noise ratios we
consider, high-order-accuracy interpolation formulas which  generate
substantial artifacts  (as many high-order formulas do) can be less
useful than  low-order-accuracy schemes which are relatively
artifact-free. A known artifact of exact interpolation of trigonometric
polynomials is as follows: substantial long-range disturbances can be
generated by local perturbations such as discontinuities. In this
sense, our crude interpolation may actually turn out to be preferable
for some purposes.

\subsubsection{Exact Reconstruction and Stability}

The Cartesian-to-rectopolar conversion we have suggested here
is reversible. That is to say, given the rectopolar values output from
this method, one can recover the original Cartesian values exactly.
To see this, take as given the following: {\it {\bf Claim:} the assignment
of Cartesian points as nearest neighbors of rectopolar points happens
in such a way that   each Cartesian point is assigned as the nearest
neighbor of at least one rectopolar point.}  It follows from this claim
that each value in the original Cartesian input array is copied into at
least one place in the output rectopolar array. Hence, perfect
reconstruction is obviously possible in principle -- just by keeping track
of where the entries are, have been copied to, and undoing the process.

Our reconstruction rule obtains, for each point on the Cartesian grid,
the {\it arithmetic mean of all the values in the rectopolar grid
  which have that Cartesian point as their nearest point}. This
provides a numerically stable left inverse.  Indeed, if applied to a
perturbed set of rectopolar values, this rule gives an approximate
reconstruction of the original unperturbed Cartesian values in which
the approximation errors are smaller than the size of the
perturbations suffered by the rectopolar values. (This final comment
is reassuring in the present de-noising context, where our
reconstructions will always be made by perturbing the empirical
rectopolar FT of the noisy data.) Phrased in mathematical terms
this gives
\[
x_C = 1/\# R(C) \sum_{R \in R(C)} y_R,
\]
where $C$ is a given point on the Cartesian grid and $R(C)$ is the set
of rectopolar points that are closest to $C$. Cardinality is denoted
$\#$. Stability in $\ell_2$,
for instance, follows from the observation
\[
|x_C|^2 \le 1/\# R(C) \sum_{R \in R(C)} |y_R|^2
\le \sum_{R \in R(C)} |y_R|^2;
\]
Since we have a partition of the set of rectopolar points,
summing this last inequality across the Cartesian grid gives $\|x\|^2
\le \|y\|^2$.

It remains to explain the italicized claim, because, as we have seen,
from it flows the exact reconstruction property and stability of the
inverse. Consider the rectopolar points in the hourglass region made of
`basically vertical lines', i.e. lines which make an angle
less than $\pi/4$ with vertical, and more specifically those
points on a single horizontal scan line. Assuming the scan line
is not at the extreme top or bottom of the array, these points are spaced {\it
strictly less than one unit apart}, where our unit is the spacing of
the Cartesian
grid. Therefore, when we consider a Cartesian grid point $C$ belonging to this
scan line and ask about the rectopolar points $R_L$ and $R_R$ which
are closest to
it on the left and right respectively, these two points cannot be as much as 1
unit apart:
$|| R_L - R_R || < 1$. Therefore at least one of the two points must be
strictly less than 1/2 unit away from the Cartesian point: i.e. either
$|| R_L - C || < 1/2$ or $|| R_R - C || < 1/2$. Without loss of
generality suppose that $|| R_L - C || < 1/2$. Then clearly $R_L$ has
$C$ as its closest Cartesian point. In short, every Cartesian point in
the strict interior of the `hourglass' associated with the `basically
vertical' lines arises as the strict closest Cartesian point of at
least one rectopolar point. Similar statements can be made about points
on the boundary of the hourglass, although the arguments supporting
those statements are much simpler, essentially mere inspection. Similar
statements can be made about the points in the transposed hourglass.
The italicized claim is established.

\subsubsection{One-dimensional Wavelet Transform}

To complete the ridgelet transform, we must take
a one-dimensional wavelet transform along the
radial variable in Radon space. We now discuss the choice of
digital one-dimensional wavelet transform.

Experience has shown that compactly-supported wavelets can lead to many
visual artifacts when  used in conjunction with nonlinear processing --
such as hard-thresholding of individual wavelet coefficients --
particularly for decimated wavelet schemes used at critical sampling.
Also, because of the lack of localization of such compactly-supported
wavelets in the frequency domain, fluctuations in coarse-scale wavelet
coefficients can introduce fine-scale fluctuations; this is
undesirable in our setting. Here we take a frequency-domain approach,
where the discrete Fourier transform is reconstructed from the inverse
Radon transform. These considerations lead us to use a band-limited
wavelet, whose support is compact in the Fourier domain rather than
the time domain. Other implementations have made a choice of compact
support in the frequency domain as well \cite{DRT,FRT}. However, we
have chosen a specific overcomplete system, based on work of Starck et
al. \cite{starck:sta94_3,starck:book98}, who constructed such  a
wavelet transform and applied it to interferometric image
reconstruction. The wavelet transform algorithm is based on a scaling
function $\phi$ such that $\hat{\phi}$ vanishes outside of the interval
$[-\nu_c, \nu_c]$.  We defined the scaling function
$\hat{\phi}$ as a renormalized $B_3$-spline
\[
\hat{\phi}(\nu)= {3\over 2} B_3(4\nu),
\]
and $\hat{\psi}$ as the difference between two consecutive resolutions
\[
\hat \psi(2\nu) = \hat \phi(\nu) - \hat \phi(2\nu).
\]
Because $\hat{\psi}$ is compactly supported, the sampling theorem
shows than one can easily build a pyramid of $n + n/2 + \ldots + 1 =
2n$ elements: see \cite{starck:book98} for details.

This transform enjoys the following features:
\begin{itemize}
\item The wavelet coefficients are directly calculated in the Fourier
      space. In the context of the ridgelet transform, this allows
      avoiding the computation of the one-dimensional inverse Fourier
      transform along each radial line.
\item Each subband is sampled above the Nyquist rate, hence
      avoiding aliasing -- a phenomenon typically encountered by critically
      sampled orthogonal wavelet transforms \cite{Steerable}.
\item The reconstruction is trivial. The wavelet coefficients simply
      need to be co-added to reconstruct the input signal at any given
      point. In our application, this implies that the ridgelet
coefficients
      simply need to be co-added to reconstruct Fourier coefficients.
\end{itemize}

This wavelet transform introduces an extra redundancy factor, which
might be viewed as an objection by advocates of orthogonality
and critical sampling. However,
we note that our goal in this implementation is not data
compression/efficient
coding -- for which critical sampling might be relevant -- but
instead
noise removal, for which it is well-known that overcompleteness
can provide substantial advantages
\cite{rest:donoho95}.

\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=fig_rid.ps,bbllx=4.5cm,bblly=5cm,bburx=21cm,bbury=22cm,width=10cm,height=10cm,clip=}
}}
\caption{Ridgelet transform flowgraph. Each of the $2n$  radial lines
      in the Fourier domain is processed separately. The 1D inverse FFT
      is calculated along each radial line followed by a 1D nonorthogonal
      wavelet transform.  In practice, the one-dimensional wavelet
      coefficients are directly calculated in the Fourier space. }
\label{fig_ridgelet}
\end{figure}

\subsubsection{Combining the Pieces}

Figure~\ref{fig_ridgelet} shows the flowgraph of the ridgelet
transform.  The ridgelet transform of an image of size $n \times n$ is
an image of size $2n \times 2n$, introducing a redundancy factor
equal to 4.

We note that, because our transform is made up of a chain
of steps, each one of which is invertible, the whole
transform is invertible, and so has the
exact reconstruction property. For the same
reason, the reconstruction
is stable under perturbations of the coefficients.

Last but not least, our discrete transform is computationally
attractive. Indeed, the algorithm we presented here has low complexity
since it runs in $O(n^2\log(n))$ flops for an $n \times n$ image.

\subsection{The Orthonormal Finite Ridgelet Transform}
The orthonormal finite ridgelet transform (OFRT)  has been
recently proposed
\cite{cur:do00,cur:do00b} for image compression and filtering.
The transform, based on the finite Radon transform \cite{cur:matus93} and
a 1D orthogonal wavelet transform, is not redundant, and reversible.
It would be a great alternative to the previously described ridgelet transform
if the OFRT were not based on a strange definition
of a line. In fact, a line in the OFRT is defined as
a set of periodic equidistant points \cite{cur:matus93}.
Figure~\ref{fig_cmp_backproj} shows the backprojection of a ridgelet
coefficient by the FFT-based ridgelet transform (left) and by the
 OFRT (right). It is clear that the backprojection
of the  OFRT is nothing like a ridge function.

\begin{figure}[htb]
\centerline{
\vbox{
\hbox{
\psfig{figure=fig_backproj_ridfft.ps,bbllx=2cm,bblly=13.5cm,bburx=13cm,bbury=24.5cm,width=7.cm,height=7.cm,clip=}
\psfig{figure=fig_backproj_fird.ps,bbllx=2cm,bblly=13.5cm,bburx=13cm,bbury=24.5cm,width=7.cm,height=7.cm,clip=}
}}}
\caption{Left, backprojection of a ridgelet coefficient by the
FFT-based ridgelet transform,
and right, backprojection of a finite ridgelet coefficient.}
\label{fig_cmp_backproj}
\end{figure}

\begin{figure}[htb]
\centerline{
\vbox{
\hbox{
\psfig{figure=fig_l257.ps,bbllx=2cm,bblly=13.5cm,bburx=13cm,bbury=24.5cm,width=7.cm,height=7.cm,clip=}
\psfig{figure=fig_ridl257.ps,bbllx=2cm,bblly=13.5cm,bburx=13cm,bbury=24.5cm,width=7.cm,height=7.cm,clip=}
}}}
\caption{Left, part of Lena image,
and right, reconstruction after finite ridgelet coefficient thresholding.}
\label{fig_cmp_recl257}
\end{figure}

Because of this specific definition of a line, the thresholding of the OFRT
coefficients produces strong artifacts.
Figure~\ref{fig_cmp_recl257} left shows a part
of the original standard Lena image, and
Figure~\ref{fig_cmp_recl257} right shows the reconstruction after the
hard thresholding of the OFRT. A kind of noise has been added to the
noise-free image!
Finally, the OFRT presents another limitation: the image size
must be a prime number. This last point is however not too restrictive,
because we generally use a partitioning when denoising the data, and a
prime number block size can be used.
The OFTR is interesting from the conceptual point of view, but will
certainly be of no help for real applications.

\subsection{The Slant Stack Ridgelet Transform}

\begin{figure}[htb]

\centerline{
\vbox{
\hbox{
\psfig{figure=fig_back_ssrad.ps,bbllx=8.8cm,bblly=13.7cm,bburx=12.1cm,bbury=16.cm,width=3cm,height=3cm,clip=}
\psfig{figure=fig_back_ssrad1.ps,bbllx=8.8cm,bblly=13.7cm,bburx=12.1cm,bbury=16.cm,width=3cm,height=3cm,clip=}
}
\hbox{
\psfig{figure=fig_back_ssrad2.ps,bbllx=8.8cm,bblly=13.7cm,bburx=12.1cm,bbury=16.cm,width=3cm,height=3cm,clip=}
\psfig{figure=fig_back_ssrad3.ps,bbllx=8.8cm,bblly=13.7cm,bburx=12.1cm,bbury=16.cm,width=3cm,height=3cm,clip=}
}}}
\caption{Backproject of a point at four different locations in the
Radon space.}
\label{fig_back_stack_radon}
\end{figure}

The Fast Slant Stack \cite{cur:averbuch01}
 is geometrically more accurate than the
previously decribed methods. The backprojection of a point
in Radon space is exactly a ridge function in the spatial domain
(see Figure~\ref{fig_back_stack_radon}).
The transformation of an $n \times n$ image is a $2n \times 2n$ image.
$n$ line integrals with angle between $[-\frac{\pi}{4}, \frac{\pi}{4}]$
are calculated from the zero padded image on the y-axis,
and $n$ line integrals with angle between $[\frac{\pi}{4}, \frac{3\pi}{4}]$
are computed by zero padding the image on the x-axis.
For a given angle inside $[-\frac{\pi}{4}, \frac{\pi}{4}]$,
$2n$ line integrals are calculated by first shearing the zero-padded image,
and then integrating the pixel values
along all horizontal lines (resp.\ vertical lines
for angles in $[\frac{\pi}{4}, \frac{3\pi}{4}]$). The shearing is
performed column per column (resp.\ line per line) by using the 1D FFT.
Figure~\ref{fig_stack_radon} shows an example of the image shearing step
with two different angles ($5\frac{\pi}{4}$  and $-\frac{\pi}{4}$).
A ridgelet transform based on the Fast Slant Stack transform has been
proposed in \cite{cur:donoho_02}. The connection between the Fast Slant Stack
and the linogram has been investigated in \cite{cur:averbuch01}, and
a Fast Slant Stack is proposed, based on the 2D Fourier transform.

\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=fig_slant_radon.ps,bbllx=3cm,bblly=9cm,bburx=18cm,bbury=21.cm,width=15cm,height=12cm,clip=}
}}
\caption{Slant Stack Transform of an image.}
\label{fig_stack_radon}
\end{figure}

\section{Local Ridgelet Transforms}

A digital version of the ideas presented in section \ref{sec:pyramid}
decomposes the original $n$ by $n$ image into smoothly overlapping
blocks of sidelength $b$ pixels in such a way that the overlap between
two vertically adjacent blocks is a rectangular array of size $b$ by
$b/2$; we use overlap to avoid blocking artifacts. For an $n$ by $n$
image, we count $2n/b$ such blocks in each direction.

The partitioning introduces redundancy, as a pixel belongs to 4
neighboring blocks. We present two competing strategies to perform the
analysis and synthesis:
\begin{enumerate}
\item The block values are weighted (analysis) in such a way that the
      co-addition of all blocks reproduce exactly the original pixel value
      (synthesis).
\item The block values are those of the image pixel values (analysis)
      but are weighted when the image is reconstructed (synthesis).
\end{enumerate}
Of course, there are intermediate strategies and one could apply
smooth windowing at both the analysis and synthesis stages as discussed
in Section \ref{sec:pyramid}, for example. In the first approach, the
data are smoothly windowed and this presents the advantage to limit
the analysis artifacts traditionally associated with boundaries.  The
drawback, however, is a loss of sensitivity. Indeed, suppose for the
sake of simplicity that a vertical line with intensity level $L$
intersects a given block of size $b$. Without loss of generality
assume that the noise standard deviation is equal to 1. When the
angular parameter of the Radon transform coincides with that of the
line,
we obtain a measurement with a signal intensity equal to $b L$ while
the noise standard deviation is equal to $\sqrt{b}$ (in this case, the
value of the signal-to-noise ratio (SNR) is $\sqrt{b} L$). If weights
are applied at the analysis stage, the SNR is roughly equal to $L \,
\sum_{i=1}^b w_i/\sqrt{\sum_{i=1}^b w_i^2} < \sqrt{b} L$. Experiments
have shown that this sensitivity loss may have substantial effects
in filtering applications and, therefore, the second approach
seems more appropriate since our goal is image restoration.

We calculate a pixel value $f(i,j)$ from its four corresponding block
values of half-size $\ell = b/2$, namely, $B_1(i_1,j_1)$,
$B_2(i_2,j_1)$, $B_3(i_1,j_2)$ and $B_4(i_2,j_2)$ with $i_1, j_1 >
b/2$ and $i_2 = i_1 - \ell, j_2 = j_1- \ell$, in the following way:
\begin{eqnarray}
      f_1 &  = &  w(i_2/\ell) B_1(i_1,j_1) + w(1-i_2/\ell)
B_2(i_2,j_1)\nonumber \\
      f_2 &  = &  w(i_2/\ell) B_3(i_1,j_2) + w(1-i_2/\ell)
B_4(i_2,j_2)\nonumber \\
      f(i,j) &  = &  w(j_2/\ell) f_1 +  w(1-j_2/\ell) f_2
\end{eqnarray}
with $w(x) = \cos^2(\pi x/2)$.  Of course, one might select any other
smooth, non-increasing function satisfying $w(0) = 1$, $w(1) = 0$,
$w'(0) = 0$ and obeying the symmetry property $w(x) + w(1-x) = 1$.

It is worth mentioning that the spatial partitioning introduces a
redundancy factor equal to 4.

Finally, we note that in order to be in better agreement with the
theory one should of course introduce a normalizing factor depending
on the block-size. However, since we are concerned about de-noising
and the thresholding of individual coefficients, the normalization is
a non-issue.  Renormalizing coefficients automatically renormalizes
corresponding thresholds in the exact same way: see section
\ref{sec:filtering}.

\section{Digital Curvelet Transform}
\label{sec:curvelet}

\subsection{Discrete Curvelet Transform of Continuum Functions}

We now briefly return to the continuum viewpoint of section
\ref{sec:pyramid}.
Suppose we set an initial goal to produce a decomposition using the
multiscale ridgelet pyramid. The hope is that this
would allow us to use thin `brushstrokes' to reconstruct
the image, with all lengths and widths available to us.
In particular, this would seem allow us to trace sharp edges precisely
using a few elongated elements with very narrow widths.

As mentioned in section \ref{sec:pyramid},
the full multiscale ridgelet pyramid is highly overcomplete.
As a consequence,  convenient algorithms like
simple thresholding will not find sparse
decompositions when such good decompositions exist.
An important ingredient of the curvelet
transform is to restore sparsity by reducing redundancy across scales.
In
detail, one introduces interscale orthogonality by means of
subband filtering. Roughly speaking, different levels of the
multiscale ridgelet pyramid are used to represent different
subbands of a filter bank output.  At the same time, this subband
decomposition imposes a relationship between the width and length
of the important frame elements so that they are anisotropic and obey
$width = length^2$.

The discrete curvelet transform of a continuum
function $f(x_1,x_2)$ makes use of a dyadic sequence of scales,
and a bank of filters $(P_0 f, \Delta_1 f ,
\Delta_2 f , \dots )$ with the property that the passband filter
$\Delta_s$ is concentrated near the frequencies $[2^{2s}, 2^{2s+2}]$,
e.g.
\[
\Delta_s = \Psi_{2s} * f, \quad \widehat{\Psi_{2s}}(\xi) =
\widehat{\Psi}(2^{-2s}\xi).
\]
In wavelet theory, one uses a decomposition into dyadic subbands
$[2^s, 2^{s+1}]$. In contrast, the subbands used
in the discrete curvelet transform of continuum functions have
the non-standard form
$[2^{2s}, 2^{2s+2}]$. This is a non-standard feature of the
discrete curvelet transform well worth remembering.

With the notation of section \ref{sec:pyramid}, the curvelet
decomposition is the sequence of the following steps:
\begin{itemize}
     \item {\it Subband Decomposition.}  The object $f$ is
     decomposed into subbands:
     \[
       f \mapsto (P_0 f, \Delta_1 f , \Delta_2 f , \dots ) .
     \]
\item {\it Smooth Partitioning.} Each subband is smoo\-thly win\-do\-wed
      into ``squares'' of an appropriate scale (of sidelength $\sim
      2^{-s}$):
     \[
        \Delta_s f \mapsto ( w_Q    \Delta_s f )_{Q \in {\cal Q}_s} .
     \]
     \item {\it Renormalization.} Each resulting square is renormalized to
unit scale
     \begin{equation}
      \label{eq:gQ}
        g_Q =  (T_Q)^{-1}(w_Q \Delta_s f ),  \qquad {Q \in {\cal Q}_s} .
     \end{equation}
\item {\it Ridgelet Analysis.} Each square is analyzed via the
      discrete ridgelet transform.
\end{itemize}

In this definition, the two dyadic subbands $[2^{2s}, 2^{2s+1}]$ and
$[2^{2s+1}, 2^{2s+2}]$ are merged before applying the ridgelet
transform.
\subsection{Digital Realization}

In developing a transform for digital $n$ by $n$ data
which is analogous to the discrete curvelet transform of a
continuous function $f(x_1,x_2)$,
we replace each of the continuum concepts
with the appropriate digital concept mentioned in the sections above.
In general, the translation is rather obvious and direct. However,
experience shows that one modification is essential;
we found that, rather than merging the two
dyadic subbands $[2^{2s}, 2^{2s+1}]$ and
$[2^{2s+1}, 2^{2s+2}]$ as in the theoretical work,
in the digital application, leaving these subbands separate,
applying spatial partitioning to each subband
and applying the ridgelet transform on
each subband separately led to improved visual and numerical results.

We believe that the ``\`a trous'' subband filtering algorithm is
especially
well-adapted to the needs of the digital curvelet transform.
The algorithm decomposes an $n$ by $n$ image $I$ as a superposition of
the form
\[
I(x,y) = c_{J}(x,y) + \sum_{j=1}^{J} w_j(x,y),
\]
where $c_{J}$ is a coarse or smooth version of the original image $I$
and $w_j$ represents ``the details of $I$'' at scale $2^{-j}$: see
\cite{starck:book98} for more information. Thus, the algorithm outputs
$J+1$ subband arrays of size $n \times n$. (The indexing is such that,
here, $j = 1$ corresponds to the finest scale, or high frequencies.)

\begin{figure}[htb]
\centerline{
\hbox{\psfig{figure=fig_cur.ps,width=8cm,height=10cm,clip=}}
}
\caption{Curvelet transform flowgraph. The figure illustrates
the decomposition of the original image  into subbands followed by
the spatial partitioning of each subband. The ridgelet transform
is then applied to each block.}
\label{fig_curvelet}
\end{figure}

\subsection{Algorithm}
We now present a sketch of the discrete curvelet transform algorithm:
\begin{enumerate}
\item Apply the \`a trous algorithm with $J$ scales,
\item set $B_1 = B_{min}$,
\item for $j = 1, \ldots, J$ do,
\begin{enumerate}
\item partition the subband $w_j$ with a block size $B_j$ and apply the
digital ridgelet transform to each block,
\item if $j \mbox{ modulo } 2 = 1$ then $B_{j+1} = 2B_{j}$,
\item else $B_{j+1} = B_{j}$.
\end{enumerate}
\end{enumerate}
The sidelength of the localizing windows is doubled {\em at every
      other} dyadic subband, hence maintaining the fundamental property of
the curvelet transform which says that elements of length about
$2^{-j/2}$ serve for the analysis and synthesis of the $j$-th subband
$[2^j, 2^{j+1}]$.  Note also that the coarse description of the image
$c_J$ is not processed. Figure~\ref{fig_curvelet}
gives an overview of the organization of the algorithm.

This implementation of the curvelet transform is also redundant. The
redundancy factor is equal to $16J+1$ whenever $J$ scales are employed.
Finally, the method enjoys exact reconstruction and stability,
because this invertibility holds for each element of the
processing chain.

\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=fig_sparse_s1.ps,bbllx=4cm,bblly=7cm,bburx=17cm,bbury=21cm,width=6.5cm,height=7cm,clip=}
\psfig{figure=fig_sparse_s2.ps,bbllx=4cm,bblly=7cm,bburx=17cm,bbury=21cm,width=6.5cm,height=7cm,clip=}
}}
\caption{A few curvelets.}
\label{fig_ex_curve}
\end{figure}
Figure~\ref{fig_ex_curve} shows a few curvelets at different scales,
orientations and locations.


\subsection{How can we use this massive amout of information?}
\begin{frame}{How can we use this massive amout of information?}
    \begin{itemize}[<+->]
        \item 625.3 million websites
        \item Wikipedia is one website and has several millions of pages
        \item[$\Rightarrow$] we need to rank websites!
    \end{itemize}
\end{frame}

\subsection{Idea}
\begin{frame}{Basics of PageRank}
    We all know that:
    \begin{itemize}[<+->]
        \item humans know what is good for them
        \item[\xmark] machines don't know what's good for humans
        \item humans create websites
        \item humans will only \href{http://en.wikipedia.org/wiki/Hyperlink}{link} to websites they like
        \item[$\Rightarrow$] hyperlinks are a quality indicator
    \end{itemize}
\end{frame}

\begin{frame}{How Could We Use That?}
    \begin{itemize}[<+->]
        \item simply count number of links to a website
        \item[\xmark] 10,000 links from only one page
        \item count number of websites that link to a website
        \item[\xmark] quality of the linking website matters
        \item[\xmark] total number of links on the source page matters
    \end{itemize}
\end{frame}

\framedgraphic{A Brilliant Idea}{../images/BrinPage.jpg}

\begin{frame}{Ideas of PageRank}
    \begin{itemize}[<+->]
        \item decisions of humans are complicated
        \item a lot of webpages get visited
        \item[$\Rightarrow$] modellize clicks on links as random behaviour
        \item links are important
        \begin{itemize}
            \item links of page A get less important, if A has many links
            \item links of page A get more important, if many link to A
        \end{itemize}
        \item[$\Rightarrow$] if B has a link from A, the rank of B increases by $\frac{Rank(A)}{Links(A)}$
    \end{itemize}

    \pause[\thebeamerpauses]

    \begin{algorithmic}
        \If{A links to B}
            \State $Rank(B)$ += $\frac{Rank(A)}{Links(A)}$
        \EndIf
    \end{algorithmic}
\end{frame}

\begin{frame}{What is PageRank?}
    The PageRank algorithm calculates the probability of a randomly
    clicking user ending up on a given page.
\end{frame}

\input{Animation}

%\begin{frame}{Ants}
%    \begin{itemize}[<+->]
%        \item Websites = nodes = anthill
%        \item Links = edges = paths
%        \item You place ants on each node
%        \item They walk over the paths
%        \item[] (at random, they are ants!)
%        \item After some time, some anthills will have more ants than
%              others
%        \item Those hills are more attractive than others
%        \item \# ants is probability that a random user would end on
%              a website
%    \end{itemize}
%\end{frame}

\begin{frame}{Mathematics}
    Let $x$ be a web page. Then
    \begin{itemize}
        \item $L(x)$ is the set of websites that link to $x$
        \item $C(y)$ is the out-degree of page $y$
        \item $\alpha$ is probability of random jump
        \item $N$ is the total number of websites
    \end{itemize}

    \[\displaystyle PR(x) := \alpha \left ( \frac{1}{N} \right ) + (1-\alpha) \sum_{y\in L(x)} \frac{PR(y)}{C(y)}\]
\end{frame}

\begin{frame}{Pseudocode}
        \begin{algorithmic}
\alertline<1>             \Function{PageRank}{Graph $web$, double $q=0.15$, int $iterations$} %q is a damping factor
%\alertline<2>                 \ForAll{$page \in web$}
%\alertline<3>                     \State $page.pageRank = \frac{1}{|web|}$ \Comment{intial probability}
%\alertline<2>                 \EndFor

\alertline<2>                 \While{$iterations > 0$}
\alertline<3>                     \ForAll{$page \in web$} \Comment{calculate pageRank of $page$}
\alertline<4>                         \State $page.pageRank = q$
\alertline<5>                         \ForAll{$y \in L(page)$}
\alertline<6>                             \State $page.pageRank$ += $\frac{y.pageRank}{C(y)}$
\alertline<5>                         \EndFor
\alertline<3>                     \EndFor
\alertline<2>                     \State $iterations$ -= $1$
\alertline<2>                 \EndWhile
\alertline<1>             \EndFunction
        \end{algorithmic}
\end{frame}