\documentclass{article}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%

\input{common_symbols_and_format.tex}%
\usepackage{tocloft}%
\renewcommand{\cfttoctitlefont}{\Large\bfseries}%
%
\begin{document}%
\normalsize%
\logo%
\rulename{Static Level Regression}%
\tblofcontents%
\ruledescription{Regresses the one-day price changes against the level of the signal for the specified number of days, using coefficients estimated from the start of the data.}%
\howtotrade

{Given default parameter values, if the asset drift is 0.001 and the error is 0.02 (2\% daily volatility), this rule will take a $0.001 / (0.02)^2  = 2.5$ or 250\% position (leveraged).}%
{
\begin{figure}[H]
\begin{multicols}{2}
  \centering
    \begin{subfigure}{\linewidth}
        \includegraphics[width=\linewidth]{\graphdir{market.png}}
        \caption{Market series data}
        \label{fig:01}
    \end{subfigure}
  \par
  \vspace{5mm}
  \begin{subfigure}{\linewidth}
    \includegraphics[width=\linewidth]{\graphdir{research.png}}
    \caption{Research series data}
    \label{fig:02}
  \end{subfigure}
  \par
  \begin{subfigure}{\linewidth}
    \includegraphics[width=\linewidth]{\graphdir{pa(StaticLevelRegression).png}}
    \caption{ Suggested volume to buy or sell}
    \label{fig:03}
  \end{subfigure}
  \par
  \vspace{5mm}
  \begin{subfigure}{\linewidth}
    \includegraphics[width=\linewidth]{\graphdir{pr(StaticLevelRegression).png}}
    \caption{Portfolio return}
    \label{fig:04}
  \end{subfigure}
  \end{multicols}
  \caption{Graphical depiction of the Static Level Regression algorithm. 20 Days of trading data is visualized in the graphs (\ref{fig:01}) A line chart showing changes in the market price for multiple trading days.(\ref{fig:02}) A chart displaying the research series data. (\ref{fig:03})Positive values indicate that buying the security by x\%. The negative values mean you are shorting the security by x\% (\ref{fig:04})Chart showing the portfolio return when using the Static Level Regression as the trading rule.}
  \label{fig:cps_graph}
\end{figure}
}

\ruleparameters{Kelly fraction}{1.0}{Amplitude weighting. 1.0 is maximum growth if regression is exact. <1.0 scales down positions taken.}{$\kellyfraction$}{Regression length}{50}{This is the number of days used to estimate the regression coefficients.}{$\lookbacklength$}%
\stoptable%

\section{Equation}
The following equations describe the static level regression rule:

\begin{equation}
\label{eq:predictedPrice}
    \regressionprice_\currenttime= \amplitudecoefficient\research_\currenttime + \constantc
\end{equation}
Using the equation (\ref{eq:predictedPrice}), it is possible to calculate the predicted price $\regressionprice_{\currenttime}$ at time $\currenttime$.
Here the values of the research series $\research_{\currenttime}$ and the $\constantc$ are fitted from the data. In order to calculate the resultant fractional portfolio allocation $\position_{\currenttime}$ we use Kelly fraction to obtain the maximum results for the long run.

\begin{equation}\label{eq:porfolio}
    \position_\currenttime = \kellyfraction \frac{\regressionprice_\currenttime}{ \rmserror_{\regressionprice}^{2}}
\end{equation}
\hspace{200mm}
where

$\research$ : is the value of the research series.

$\regressionprice_\currenttime$ : is the predicted price at time $\currenttime$.

$\rmserror$ : is the standard error between predicted and ground truth prices.

$\kellyfraction$ : is the Kelly Fraction.

$\position$ : is the resultant fractional portfolio allocation.
\hspace{200mm}
Additionally, the standard error $\rmserror_{\regressionprice}$ is calculated and included in equation (\ref{eq:porfolio}) to normalize the predicted price.
\hspace{200mm}
\\

\keyterms%
\furtherlinks%
\end{document}


\chapter{Conclusion and Discussion}
\label{conclusion}

This thesis presents evidence for electroweak single top quark production at the Tevatron. An analysis of nearly $1$~fb$^{-1}$ of Run~II data using the matrix element method to select single top quark-like events measures the combined $s+t$-channel production cross section to be
$$
\sigma\left({\ppbar}{\rargap}tb+tqb+X\right)
= 4.6 ^{+1.8}_{-1.5}~{\rm pb},
$$

\noindent where the probability of a background fluctuation is $0.21\%$, which corresponds to a Gaussian equivalent signal significance of $2.9\sigma$. This analysis is one of three single top searches performed by the $\dzero$~collaboration. The first analysis using boosted decision trees measures a combined $s+t$ cross section of $4.9\pm1.4$~pb with a signal significance of 3.4$\sigma$, while the second analysis uses Bayesian neural networks and measures a cross section of $5.0\pm1.9$~pb at 2.4$\sigma$ signal significance. The results of these three analyses were recently accepted for publication by Physical Review Letters~\cite{Abazov:2006gd}. More recently the three results were combined using the BLUE (Best Linear Unbiased Estimator)~\cite{1988NIMPA.270..110L} method; this resulted in a measured cross section of $4.8\pm1.3$~pb with $3.5\sigma$ signal significance~\cite{comb}. The cross sections from the three analyses as well as the combination are shown in Fig.~\ref{singletopanalysis}, where they are also compared with two next-to-leading order single top cross section calculations.

\begin{figure}[!h!tbp]
\begin{center}
\includegraphics[width=0.75\textwidth]{eps/Conclusion/ResultsComb.eps}
\end{center}
\vspace{-0.1in}
\caption{Results from the three single top quark analyses and the combined analysis compared with two NLO cross section calculations~\cite{comb}.}
\label{singletopanalysis}
\end{figure}

Several improvements to the matrix element analysis presented in this thesis are currently underway. First is the addition of a $\ttbar$~matrix element in the discriminant definition. This should dramatically enhance the signal significance in events with three jets where the $\ttbar$~background contribution is substantial. The second improvement is the use of the muon charge from a semi-leptonic $B$ decay to weight the jet-parton assignment of jets to $b$ and $\bar{b}$ quarks, while the third is the addition of the neural network $B$-tagging algorithm in the discriminant definition. Events with jets that are very $B$-jet like will receive a higher weight from background processes involving $b$~quarks \mbox{(e.g. $Wb\bar{b}$)} while the remaining events will receive a higher weight from processes involving light quarks \mbox{(e.g. $Wgg$ and $Wcg$)}.

$\dzero$ has already recorded more than $2$~fb$^{-1}$ of Run~II data. With this increased dataset several important measurements are possible. The first is an individual measurement of the $s$-channel and $t$-channel cross sections. Each production process is sensitive to different new physics models making a determination of the cross section for each channel an important test for physics beyond the Standard Model. Another important measurement using this dataset is a precise determination of $|V_{tb}|$. The current uncertainty on the combined single top cross section is $\sim30\%$, which leads to an uncertainty on $|V_{tb}|$ of $\sim20\%$. With this increased dataset the expected error on $|V_{tb}|$ will decrease to $15\%$.

A precise measurement of the single top quark production cross section is also important because single top events are one of the largest backgrounds for Higgs production. At the Tevatron one of the most sensitive channels for a low mass Higgs is $W$-associated Higgs production ($WH$). The $WH$ production cross section for $m_{H}=115$~GeV is nearly one-tenth of the single top cross section. Using the full Run~II dataset and employing advanced multivariate analysis techniques such as the method described in this thesis, $\dzero$ hopes to find evidence for the Higgs boson before the start of the Large Hadron Collider era.

The analysis presented in this thesis has shown that with a detailed understanding of the detector apparatus, an advanced multivariate technique to reduce backgrounds, and a sophisticated statistical analysis of the dataset, the measurement of a process which occurs in 1 out of every 10 billion collisions at the Tevatron is possible. With an increased dataset of $3-4$~fb$^{-1}$ a $5\sigma$ observation of single top production will be possible, thereby providing a stringent test of the Standard Model and possibly establishing the presence of new physics.


\documentclass[a4paper,11pt,twoside,openright]{article}

\usepackage[english]{babel}
\usepackage{color}
\usepackage{graphicx}
\usepackage[margin=3cm]{geometry}
\usepackage{hyperref}
\usepackage{epsfig,amsfonts}
\usepackage{xcolor,import}

\usepackage{subcaption}
\usepackage{amsmath,amssymb}  % Better maths support & more symbols
\usepackage{textcomp} % provide lots of new symbols\usepackage{natbib}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{array,multirow,makecell}
\usepackage{gensymb}
\setcellgapes{1pt}
\makegapedcells
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash }b{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash }b{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}}
\usepackage{geometry}
\geometry{hmargin=1.5cm,vmargin=2cm}

\pagestyle{plain}

\newcommand{\ud}[1]{\underline{#1}}
\newcommand{\e}[1]{\underline{e}_{#1}}
\newcommand{\lt}{\left}
\newcommand{\rt}{\right}
\DeclareMathOperator{\n}{\underline{n}}
\DeclareMathOperator{\ei}{\underline{e}_1}
\DeclareMathOperator{\et}{\underline{e}_2}
\DeclareMathOperator{\ex}{\underline{e}_x}
\DeclareMathOperator{\ey}{\underline{e}_y}
\DeclareMathOperator{\ez}{\underline{e}_z}
\DeclareMathOperator{\nin}{\underline{n}_{in}}
\DeclareMathOperator{\nout}{\underline{n}_{out}}
\DeclareMathOperator{\np}{\underline{n}_{P}}
\DeclareMathOperator{\bragg}{\theta_{bragg}}
\DeclareMathOperator{\DD}{\cos(\theta)^2 - \sin(\psi)^2}
\newcommand{\wdg}{\wedge}
\newcommand{\hypot}[1]{\textbf{\textcolor{green}{#1}}}

\begin{document}

\title{ToFu geometric tools \\ Take into account non-parallel crystal mesh}
\author{Adrien Da Ros}
\date{30/04/2021}
\maketitle

\tableofcontents
\newpage
\section{Problem details}
The definition into \textit{ToFu} geometrical tool of Bragg's crystals has been made to take into account geometrical, material and specific Bragg parameters. As we can see on Fig.\ref{fig:general_geom}, the crystal of curvature radius R has its center C on coordinates ($x_{c}$, $y_{c}$, $z_{c}$) in the Tokamak frame (O, $e_{x}$, $e_{y}$, $x_{z}$). \par

\begin{figure}[h]
    \centering
    \includegraphics[width=0.8\textwidth]{SpectroX2D_Crystal.pdf}
    \caption{Definition of the generalized geometry}
    \label{fig:general_geom}
\end{figure}

This general description is assumed to be true at any time of the experiment. But there is one major issue that the current definition of the Bragg's crystals doesn't take into account, the non-parallelism of each crystal. As we can see on Fig.\ref{fig:non_para}, crystals are industrially made and sold with an index of confidence about the parallelism between the diopter and the crystal mesh. Because every crystal are not perfect, a maximum angle is furnished by the manufacturer, generally in arc-seconds. This defect causes a deviation of the normal vector $\nout$ shown in both Fig.\ref{fig:general_geom} and Fig.\ref{fig:non_para} (a deviation a is drawn).

\begin{figure}[h]
    \centering
    \includegraphics[width=1.\textwidth]{dessin.png}
    \caption{Definition of the non-parallelism between diopter $\overrightarrow{n_{in}}$ and mesh $\overrightarrow{n_{in}}^{'}$ unit vectors with a deviation a=$\alpha$ and d the distance in Angstroms between each layer.}
    \label{fig:non_para}
\end{figure}
\newpage
\section{Suggested trigonometrical solution}
The main issue due to this property of non-parallelism in each crystal can cause a splitting of the spectral lines.
In order to take into account this property, we propose first to define a orthogonal basis in spherical geometry based on the summit S of the crystal, as shown in Fig.\ref{fig:new_basis}.
Here, we took the same orthodirect basis as seen in Fig.\ref{fig:general_geom} ($\nout$, $\ei$, $\et$) where $\nout = -\nin$, the $\alpha$ angle represents the deviation's amplitude and the angle $\beta$ the new direction.

\begin{figure}[h]
    \centering
    \includegraphics[width=0.8\textwidth]{nouvelle_base_cristal_non_para.PNG}
    \caption{Definition of the the new basis 3D}
    \label{fig:new_basis}
\end{figure}
\newpage
Thanks to that, we can define easily now the new normal vector to the crystal mesh, which will be useful for few calculations.

$$
\lt\{
	\begin{array}{ll}
		\nout' & = cos(\alpha).\nout + sin(\alpha).(cos(\beta).\e1 + sin(\beta).\e2) \\
		\e1' & = \cos(\alpha)\lt(\cos(\beta).\e1 + \sin(\beta).\e2\rt) - \sin(\alpha).\nout\\
		\e2' & = \nout' \wdg \e1'\\
	\end{array}
\rt.
$$
$$
\e2' = \lt(cos(\alpha).\begin{vmatrix}
   \nout \\
   0 \\
   0
\end{vmatrix} + sin(\alpha).\lt(cos(\beta).\begin{vmatrix}
   0 \\
   \e1 \\
   0
\end{vmatrix} + sin(\beta).\begin{vmatrix}
   0 \\
   0 \\
   \e2
\end{vmatrix})\rt)\rt \wdg
\lt(\cos(\alpha)\lt(\cos(\beta).\begin{vmatrix}
   0 \\
   \e1 \\
   0
\end{vmatrix} + \sin(\beta).\begin{vmatrix}
   0 \\
   0 \\
   \e2
\end{vmatrix}\rt) - \sin(\alpha).\begin{vmatrix}
   \nout \\
   0 \\
   0
\end{vmatrix}\rt)$$
$$
\e2' = \begin{vmatrix}
   0 \\
   -\cos²(\alpha).\sin(\beta) + \sin²(\alpha).\sin(\beta) \\
   \cos²(\alpha).\cos(\beta) + \sin²(\alpha).\cos(\beta)
\end{vmatrix}
= \begin{vmatrix}
   0 \\
   -\sin(\beta) \\
   \cos(\beta)
\end{vmatrix} = -\sin(\beta).\e1 + \cos(\beta).\e2
$$

So in the code, we shall propose the same notation according to Didier's work, ($\nout$, $\ei$, $\et$), in order to prevent some confusion between each set of parameters and to replace the original basis by the new one if the user does not assume perfect parallelism into its crystals. \par
The point is to let the user decide or not to give any parameter concerning the new basis and in this case the code will, if it's possible mathematically speaking, return all the parameters ($\nout$, $\ei$, $\et$, $\alpha$, $\beta$). If he doesn't, then a parallelism configuration will be assumed automatically and a warning notice will be shown in order to notice him about this point. Same thing about the missing of few parameters\par
In order to compute the new unit vectors, the angles providing will be assumed as essential.

\end{document}


% latexmk -pvc -pdf
\documentclass[9pt, a4paper]{article}
\usepackage[margin=0.65in]{geometry}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{amsmath,amsthm,amsfonts,amssymb}
\usepackage{blindtext}
\usepackage[english]{babel}
\newenvironment{Figure}
    {\par\medskip\noindent\minipage{\linewidth}}
    {\endminipage\par\medskip}

% \newcommand\II{\mathbb{}}
% \newcommand\PT{\textit{}}

\title{Simulating phase contrast imaging for materials with variable density}
\author{Ana C. Fabela Hinojosa \\
\small{Supervisors: Assoc. Prof. Marcus Kitchen}}
\small{\date{\today,  \\Due date: Friday 26\textsuperscript{th} August, 2021}}

\begin{document}
\maketitle
\section{Current objective}
In this project I study the theoretical perspective of coherent X-ray imaging. My current focus is to investigate via a simulation how the phase of incident X-rays changes as the density of a sample material in an arbitrary imaging system changes. My investigation will be extended by simulating two distinct materials under the same wave-field and see if and how distinctly phase contrast occurs. The eventual goal of this simulation is to verify if successful phase retrieval can be done of the imaged objects given their variable densities.

\section{The fundamentals of X-ray imaging theory}
The mathematical background of the field of X-ray optics lies with the Maxwell equations of electromagnetism\cite{PagsTutes}. Maxwell's equations describe electromagnetic field disturbances as waves.

\subsubsection{Helmholtz equation and the Angular spectrum formulation}
The Helmholtz equation represents a time-independent form of the wave equation and it is a central equation of diffraction theory\cite{CH49}\cite{Pags2006}\cite{Helmholtz}.
In general, radiological imaging is done with polychromatic X-rays with non-trivial spectra\cite{CH49}. It is possible to use spectral decomposition of the wave function into monochromatic components and therefore simplify the imaging process greatly. The separation of each component with an individual fixed angular frequency (i.e. a trivial dependence in time), transforms the wave equation into a time-independent partial differential equation (PDE) that is applied individually to each monochromatic component. After the analysis of each component is done, a recombination of the monochromatic components results in the complete description of the polychromatic process\cite{CH49}\cite{Pags2006}. This method is known as the \textit{angular spectrum formulation}.
% Here I present a derivation of the Helmholtz equation
The complex scalar wave-field function $\Psi(\vec{r},t) = \sqrt{I(\vec{r},t)} \mathrm{exp}(i \phi(\vec{r},t))$ obeys the wave equation in a vacuum
\begin{equation}\label{eq:1}
\left ( \frac{1}{c^2} \frac{\partial^2 }{\partial t^2} -\nabla^2 \right ) \Psi(\vec{r},t) = 0,
\end{equation}
where \textit{c} is the speed of light and $\nabla$ is the Laplacian operator.
The spectral decomposition of $\Psi(\vec{r},t)$ is done via the Fourier transform
\begin{equation}\label{eq:2}
\Psi(\vec{r},t) = \frac{1}{\sqrt{2 \pi}} \int_{0}^{\infty}\psi_{\omega}(\vec{r}) e^{-i\omega t}d\omega,
\end{equation}
notice that the integral only considers a positive integration range (due to analyticity concerns\cite{PagsTutes}). In this equation the spatial wave-function subscript $\omega$ indicates functional dependence on this quantity\cite{Pags2006}. Evaluating equation (\ref{eq:1}) using equation (\ref{eq:2}) yields the Helmholtz equation for the vacuum
% \begin{equation}\label{eq:3}
% \left ( \frac{1}{c^2}\frac{\partial^2}{\partial t^{2}} - \nabla^{2}  \right )\Psi(\vec{r},t) = 0,
% \end{equation}
% \begin{equation}\label{eq:4}
% \therefore \int_{0}^{\infty} \frac{1}{\sqrt{2 \pi}} \left ( \frac{1}{c^2}\frac{\partial^2}{\partial t^{2}} -\nabla^{2}  \right )
% \psi_{\omega}(\vec{r}) e^{-i\omega t}d\omega = 0,
% \end{equation}
% \begin{equation}\label{eq:5}
% \therefore \int_{0}^{\infty} \frac{1}{\sqrt{2 \pi}} \left ( \frac{-\omega^2}{c^2}\psi_{\omega}(\vec{r}) e^{-i\omega t} -\nabla^{2}\psi_{\omega}(\vec{r}) e^{-i\omega t} \right ) d\omega
%  = 0,
% \end{equation}
\begin{equation}\label{eq:6}
\left ( k^2 + \nabla^{2} \right ) \psi_{\omega}(\vec{r})
 = 0,
\end{equation}
where the wave vector $k = \omega/c$.

\subsubsection{Paraxial fields}
In most situations involving phase-contrast imaging, X-ray fields behave as paraxial fields. Electromagnetic energy in this context is concentrated within a small region about the beam axis. A beam is an EM wave propagating in free space with small divergence (i.e. spread) away from the propagation axis, hence the origin of the name \textit{paraxial}.
In the previous section I described $\Psi(\vec{r},t)$ as a complex scalar wave-field, I will now add to this description the paraxiality condition.
Under this approximation the complex disturbance $\psi_{\omega}(\vec{r})$ present in the Helmholtz equation is expressed as a product of a z-directed plane wave and a perturbing envelope\cite{PagsTutes}\cite{CH49}
\begin{equation}\label{eq:7}
\psi_{\omega}(\vec{r}) = \Phi(\vec{r})\mathrm{exp}(ikz),
\end{equation}
\begin{Figure}
\centering
\includegraphics[width=0.6\linewidth]{paraxial_beam.pdf}
\captionof{figure}{cartoon of a paraxial wave-field $\psi_{\omega}(\vec{r})$ displaying beam propagation properties along the z-axis. The slowly varying complex envelope is modulated by a carrying plane wave.}
\end{Figure}
Note that the longitudinal variation of the complex envelope $\Delta z = \lambda = 2 \pi/k$ is required to be smaller than the complex envelope itself
\begin{equation}\label{eq:8}
\frac{\Delta \Phi(\vec{r})}{\Phi(\vec{r})} \leq 1
\end{equation}
using equation (\ref{eq:8}) and the longitudinal variation $\Delta z$  in the Helmholtz equation yields the paraxial Helmholtz equation in the vacuum
\begin{equation}\label{eq:9}
\left (\nabla_{T}^{2} + 2 i k \frac{\partial }{\partial z}\right ) \Phi(\vec{x , y, z}) = 0
\end{equation}

\subsubsection{Refractive index and the projection approximation}
In the presence of static, non-magnetic, scattering material media the complex scalar X-ray wave-field can still be studied by using the inhomogeneous Helmholtz equation
\begin{equation}\label{eq:10}
\left ( k^2 n^2 (\vec{r}) + \nabla^{2}  \right )\Psi(\vec{r},t) = 0,
\end{equation}
where $n(\vec{r})$ is the position dependent and complex form for the refractive index, the real part of which corresponds to the refractive index and the imaginary part of this complexified refractive index can be related to the absorptive properties of a sample\cite{PagsTutes}.
\begin{equation}\label{eq:11}
n(x, y, z) = 1 - \delta(x, y, z) + i \beta(x, y, z),
\end{equation}
where $|\delta|, |\beta| << 1$. Using the complex refractive index in the inhomogeneous paraxial Helmholtz equation yields the \textit{projection approximation}, which is an expression that describes the phase shift and attenuation undergone by an X-ray wave moving across a sample
\begin{equation}\label{eq:12}
\Phi(x, y, z_0) = \mathrm{exp} \left ( -ik \int_{0}^{z_0}(\delta - i\beta)dz\right ) \Phi(x, y, 0)
\end{equation}
\begin{Figure}
\centering
\includegraphics[width=0.6\linewidth]{projection_approximation.pdf}
\captionof{figure}{Schematic diagram of the projection approximation adapted from references \cite{CH49} and \cite{Pags2006}. The sample and is contained within the space between $z = 0$ and $z = z_0$. The sample is described by its refractive index $n(\vec{r})$ which differs from the the refractive index of the air volume that surrounds the sample.In this figure one can see that the path of X-rays passing through an object can be described by defining a surface immediately downstream from the irradiated object (i.e. $z = z_0$) at which the transferred transverse intensity and phase changes of the incident X-rays are imprinted\cite{CH49}. }
\end{Figure}
The projection approximation assumes that X-ray flow may be well approximated by straight lines parallel to z\cite{PagsTutes} and that most X-rays passing through an object do not actually interact with the sample material (i.e. minimal to no scattering occurs within the sample, a fair assumption due to small magnitude of the complex \textit{refractive index} of X-rays). Neglecting scattering effects is mathematically equivalent to discarding the transverse Laplacian term in equation (\ref{eq:9})\cite{CH49}, in addition X-ray--matter interaction must be taken into account in equation (\ref{eq:9}) making it the inhomogeneous paraxial Helmholtz equation
\begin{equation}\label{eq:13}
\left ( 2 i \frac{\partial }{\partial z} + k ( n^2 (x, y, z) - 1 )\right ) \Phi(\vec{x , y, z}) = 0.
\end{equation}

\subsubsection{Intensity and phase-shift}
Refraction is a property that may be augmented by the intensity attenuation due to the imaged object. This latter quantity may be obtained by taking the squared
modulus of equation (\ref{eq:12}), to give the \textit{Beer-Lambert law}\cite{PagsTutes}
\begin{equation}\label{eq:14}
I(x, y, z_0) = \mathrm{exp}[-\int_{t} \mu(x, y, z) dz] I(x, y, 0),
\end{equation}
where the expression above relates the imaginary part of the refractive index $\beta$ to the \textit{linear attenuation coefficient} $\mu = 2k\beta$.

Since we are working with a wave picture, refraction is associated with wave-front deformation rather than ray deflection, therefore the projection approximation term involving the refractive index $\delta$ (associated refractive properties of the object), quantifies the deformation of the X-ray wave-fronts due to passage through the sample object. Physically, for each fixed transverse coordinate $(x, y)$, phase-shifts (and the associated wave-front deformations) are continuously accumulated along energy-flow streamlines\cite{PagsTutes}.
\begin{equation}\label{eq:15}
\Delta \phi(x, y) = -k \int_{t}\delta(x, y, z)dz,
\end{equation}
where $k$ is the X-ray wave-number, $t$ is the projected thickness of the object in the direction of the beam propagation.

\subsubsection{Transport-of-intensity equation}
The transport-of-intensity equation (TIE) expresses the intensity and phase evolution of a paraxial monochromatic scalar electromagnetic or matter wave on propagation\cite{Pags2002}. The TIE is also used to quantify the contrast (i.e. refractive (phase) effects) present in propagation-based X-ray phase contrast images\cite{PagsTutes}.

More concisely, the TIE physically describes the divergence of the transverse energy-flow vector known as the Poynting vector $(\textbf{S})$. If the divergence of this vector is positive, (i.e. the wave-field is locally expanding), optical energy moves away from the local optic axis and so the longitudinal derivative of
intensity will be negative. The converse occurs if the divergence of the Poynting vector is negative, and so the longitudinal derivative of intensity will be positive\cite{PagsTutes}.
\begin{equation}\label{eq:16}
-\nabla_{T} [I(x, y, z) \nabla_{T} \phi(x, y, z)] = k \frac{\partial I (x, y, z)}{\partial z}.
\end{equation}
where $k$ is the wave-number, $I(x, y, z)$ is the intensity and $\phi(x, y, z)$ is the phase of the X-ray beam, the Poynting vector $\textbf{S} \propto I(x, y, z) \nabla_{T} \phi(x, y, z)$.

\section{Investigations}
The simulation that I am presently working on involves a cylinder made of a single material (i.e. monomorphic) with constant density. My supervisor and I are curious to see if we can verify a claim in one of the texts I am using in my research. This claim concerns a propagation based phase contrast imaging (PBI) algorithm that was first developed by Paganin et al. (2002)\cite{Pags2002}\cite{CH49}. Specifically, the claim states that the stability of Paganin's algorithm is thought to be dependent among other factors in the ratio between $\delta$ and $\mu$, both of which are proportional to the density of the medium. The conclusion from this claim is essentially that: any changes in material density throughout the material would not affect the imaging process. My supervisor suspects that this statement might not be entirely correct and we want to verify if the stability of the Paganin et al. (2002) algorithm is dependent instead on the ratio of the differences in the refraction and attenuation coefficients $\Delta \delta$ and $\Delta \mu$.

\subsubsection{Current progress}
I am inspiring some of my work in a paper by Beltran et al. (2010) (see reference \cite{Beltran}), their approach requires just a single phase-contrast projection, and enables the user to focus on a material of interest. In the case of my simulation, I set the complex refractive index, and thickness of the imaged cylinder based on the parameters given in Beltran et al.(2010)\cite{CH49}. For simplicity, my supervisor and I decided that I should break my simulation into simpler tasks. Therefore my first simulation will be that of a single monomorphic cylinder, and later on I will work on 2 cylinders, one embedded on another, both these cylinders will have different densities, since I want to understand how much density difference is needed before I see phase contrast in my simulation.
To solve the transport-of-intensity equation (TIE) and go beyond the projection approximation I have designed a differential equation solver using the fourth order Runge-Kutta algorithm. Since there is an intrinsic link between the phase and the TIE, I decided to solve re-write equation (\ref{eq:15}) in differential form and solve it simultaneously to the TIE in my code.
So far I have been able to recover the phase gained by the incident X-ray wave-fronts as they cross the cylindrical material I simulated.
\subsubsection{Results}
\begin{Figure}
\centering
\includegraphics[width=0.6\linewidth]{cross_section.pdf}
\captionof{figure}{I made this 2D plot to verify that the cross-sectional are a of my simulated cylinder did indeed reflect the correct geometry. Here one can see a purple background representing the complex refractive index value of the vacuum $\delta = 0$ and that of the cylinder in yellow $\delta_0 = 462.8 \times 10^{-9}$ (as was reported in \cite{Beltran} for the PERSPEX sample).}
\end{Figure}
\begin{Figure}
\centering
\includegraphics[width=0.6\linewidth]{20000.pdf}
\captionof{figure}{The position-dependent phase shift I discovered by using fourth order Runge-Kutta.}
\end{Figure}

\section{Future Plans}
I aim to finish my simulation by creating a graphic user interface (GUI) that allows the user to modify interactively the density parameters of the imaged concentric cylinders in the simulation. The goal is to make a easily operated visual representation of the changes in phase and intensity of the X-rays as they interact with the object in-situ.

In the foreseeable future my supervisor and I plan to diversify my project by making me do some simulations about a topic known as speckle analysis. A speckle pattern is commonly produced by interference of coherent light wave-fronts as these transmit through or reflect from a random phase assigning object (scattering medium), the process is known to encode information about the scattering medium that created the speckle\cite{Specks}. The main goal of making me do the speckle simulations is for me to understand the possible sources and causes of speckles in X-ray imaging, and to be able to decode speckle patterns.

% I also plan to aid my supervisor with testing a newly obtained silver target source of X-rays for his lab apparatus. I aim to do data analysis to compare the results from the new silver target to the classic tungsten target used in the apparatus currently.

\section{Conclusion}
The present aim of my project is to create simulation to investigate how the phase of incident X-rays changes as the density of a sample material in an arbitrary imaging system changes. My investigation will be extended by simulating two distinct materials under the same wave-field and see if and how distinctly phase contrast occurs. The eventual goal of this simulation is to verify if successful phase retrieval can be done of the imaged objects given their variable densities. In this report I present a brief outline of the theoretical perspective of coherent X-ray imaging, a description of my current progress and future aims.

\bibliography{mybib}
\bibliographystyle{unsrt}
\end{document}

% MAXWELL'S equations
% \begin{equation}
% \left ( \frac{1}{c^2} \frac{\partial^2 }{\partial t^2} -\nabla^2 \right )\mathbf{E}(\vec{r},t) = 0,
% \end{equation}

% \begin{equation}
% \left ( \frac{1}{c^2} \frac{\partial^2 }{\partial t^2} -\nabla^2 \right )\mathbf{B}(\vec{r},t) = 0.
% \end{equation}


\chapter{Generating Control Flow Graphs}

   The control flow of a program is broken into {\em basic blocks}
as nodes with control flow forming edges between the basic blocks.
Thus the control flow forms a graph which often labeled edges (true
and false), and basic blocks representing sequentially executed code.
This chapter presents the Control Flow Graph (CFG) and the ROSE
application code for generating such graphs for any function in an
input code.  The CFG forms a fundamental building block for more
complex forms of program analysis.

\begin{figure}[!h]
{\indent
{\mySmallFontSize

% Do this when processing latex to generate non-html (not using latex2html)
\begin{latexonly}
   \lstinputlisting{\TutorialExampleDirectory/buildCFG.C}
\end{latexonly}

% Do this when processing latex to build html (using latex2html)
\begin{htmlonly}
   \verbatiminput{\TutorialExampleDirectory/buildCFG.C}
\end{htmlonly}

% end of scope in font size
}
% End of scope in indentation
}
\caption{Example source code showing visualization of control flow graph.}
\label{Tutorial:exampleBuildCFG}
\end{figure}

   Figure~\ref{Tutorial:exampleBuildCFG} shows the code required to generate
the control flow graph for each function of an application.  Using the input code shown in
figure~\ref{Tutorial:exampleInputCode_BuildCFG} the first function's control flow graph is
shown in figure~\ref{Tutorial:exampleBuildCFGGraph}.

\begin{figure}[!h]
{\indent
{\mySmallFontSize

% Do this when processing latex to generate non-html (not using latex2html)
\begin{latexonly}
   \lstinputlisting{\TutorialExampleDirectory/inputCode_ControlFlowGraphAnalysis.C}
\end{latexonly}

% Do this when processing latex to build html (using latex2html)
\begin{htmlonly}
   \verbatiminput{\TutorialExampleDirectory/inputCode_ControlFlowGraphAnalysis.C}
\end{htmlonly}

% end of scope in font size
}
% End of scope in indentation
}
\caption{Example source code used as input to build control flow graph.}
\label{Tutorial:exampleInputCode_BuildCFG}
\end{figure}

\begin{figure}
%\centerline{\epsfig{file=\TutorialExampleBuildDirectory/controlFlowGraph.ps,
%                    height=1.3\linewidth,width=1.0\linewidth,angle=0}}
\includegraphics[scale=0.5]{\TutorialExampleBuildDirectory/controlFlowGraph}
\caption{Control flow graph for function in input code file: inputCode\_1.C.}
\label{Tutorial:exampleBuildCFGGraph}
\end{figure}

   Figure~\ref{Tutorial:exampleBuildCFGGraph} shows the control flow graph for the
function in the input code in figure~\ref{Tutorial:exampleInputCode_BuildCFG}.


\begin{algorithm}
\caption{Simple Velocity Smoother}
\label{main:simple_v_smoother}
\If{Target Velocity < Control Velocity}{Control Velocity = $\min(Target Velocity, Control Velocity + v_c)$}
\ElseIf{Target Velocity > Control Velocity}{Control Velocity = $\max(Target Velocity, Control Velocity - v_c)$}
\Else{Control Velocity = Target Velocity}
\end{algorithm}

Essentially, ~\autoref{main:simple_v_smoother} is an acceleration limiting approach to motion control where a maximum acceleration is assumed. This generates a trapezoidal motion profile similar to ~\autoref{main:fig:motion_profile_1}.

\subsection{Map-less Navigation Problem}
The map-less navigation problem can be formulated as follows~\cite{xie_learning_2018}:

At time $t \in [0, T]$, the robot takes an action $a_{t} \in A$ according to input $x_{t}$. The input contains a view of the world (e.g. a stack of laser scans, the current speed of the robot, and the target position with respect to the robot's local frame). We assume that the robot can localize itself in the global coordinate frame with a map which enables the calculation of the target position in the local frame. After executing the action, the robot transitions to its next state in the environment and receives a reward $r_{t}$ according to the reward function. The goal of this decision-making process is to reach the maximum discounted accumulative future reward $R_{t} = \sum_{\tau = t}^{T} \gamma^{\tau - t} r_{\tau}$, where $\gamma$ is the discount factor.

\subsection{Smooth Motion Profile}
Consider the two commonly used motion profiles for point-to-point motion:
\begin{figure}[h]
  \centering
  \includegraphics[width=.9\linewidth]{\Pic{png}{motion_profile}}
  \vspace{\BeforeCaptionVSpace}
  \caption{S-curve profile and trapezoidal profile}
  \label{main:fig:motion_profile}
\end{figure}
\newpage

From ~\autoref{main:fig:motion_profile}, it is evident that an S-curve profile is smoother than a trapezoidal profile. However, why do S-curve profiles result in less load oscillation?

\section{Problem's Relation to Map-less Navigation Problem}
In addition to having a smooth velocity profile, the robot is expected to be able to perform local navigation; that is, the robot is required to avoid obstacles and reach a target position with smooth motion. The local navigation problem can be formulated as follows~\cite{xie_learning_2018}:

At time $t \in [0, T]$, the robot takes an action $a_{t} \in A$ according to input $x_{t}$. The input contains a view of the world (e.g. a stack of laser scans, the current speed of the robot, and the target position with respect to the robot's local frame). We assume that the robot can localize itself in the global coordinate frame with a map which enables the calculation of the target position in the local frame. After executing the action, the robot transitions to its next state in the environment and receives a reward $r_{t}$ according to the reward function. The goal of this decision-making process is to reach the maximum discounted accumulative future reward $R_{t} = \sum_{\tau = t}^{T} \gamma^{\tau - t} r_{\tau}$, where $\gamma$ is the discount factor.

Since the map-less navigation problem also involves its own set of reward features, another contribution of this work is \textbf{to demonstrate the negative impacts to training time that this learning-based approach may involve}.

###########################################################
DDPG interleaves learning an approximator to Q^*(s,a) with learning an approximator to a^*(s), and it does so in a way which is specifically adapted for environments with continuous action spaces. But what does it mean that DDPG is adapted specifically for environments with continuous action spaces? It relates to how we compute the max over actions in \max_a Q^*(s,a).

When there are a finite number of discrete actions, the max poses no problem, because we can just compute the Q-values for each action separately and directly compare them. (This also immediately gives us the action which maximizes the Q-value.) But when the action space is continuous, we can't exhaustively evaluate the space, and solving the optimization problem is highly non-trivial. Using a normal optimization algorithm would make calculating \max_a Q^*(s,a) a painfully expensive subroutine. And since it would need to be run every time the agent wants to take an action in the environment, this is unacceptable.

Because the action space is continuous, the function Q^*(s,a) is presumed to be differentiable with respect to the action argument. This allows us to set up an efficient, gradient-based learning rule for a policy \mu(s) which exploits that fact. Then, instead of running an expensive optimization subroutine each time we wish to compute \max_a Q(s,a), we can approximate it with \max_a Q(s,a) \approx Q(s,\mu(s)). See the Key Equations section details.
Quick Facts

    DDPG is an off-policy algorithm.
    DDPG can only be used for environments with continuous action spaces.
    DDPG can be thought of as being deep Q-learning for continuous action spaces.
    The Spinning Up implementation of DDPG does not support parallelization.

Key Equations

Here, we'll explain the math behind the two parts of DDPG: learning a Q function, and learning a policy.
The Q-Learning Side of DDPG

First, let's recap the Bellman equation describing the optimal action-value function, Q^*(s,a). It's given by

Q^*(s,a) = \underset{s' \sim P}{{\mathrm E}}\left[r(s,a) + \gamma \max_{a'} Q^*(s', a')\right]

where s' \sim P is shorthand for saying that the next state, s', is sampled by the environment from a distribution P(\cdot| s,a).

This Bellman equation is the starting point for learning an approximator to Q^*(s,a). Suppose the approximator is a neural network Q_{\phi}(s,a), with parameters \phi, and that we have collected a set {\mathcal D} of transitions (s,a,r,s',d) (where d indicates whether state s' is terminal). We can set up a mean-squared Bellman error (MSBE) function, which tells us roughly how closely Q_{\phi} comes to satisfying the Bellman equation:

L(\phi, {\mathcal D}) = \underset{(s,a,r,s',d) \sim {\mathcal D}}{{\mathrm E}}\left[
    \Bigg( Q_{\phi}(s,a) - \left(r + \gamma (1 - d) \max_{a'} Q_{\phi}(s',a') \right) \Bigg)^2
    \right]

Here, in evaluating (1-d), we've used a Python convention of evaluating True to 1 and False to zero. Thus, when d==True---which is to say, when s' is a terminal state---the Q-function should show that the agent gets no additional rewards after the current state. (This choice of notation corresponds to what we later implement in code.)

Q-learning algorithms for function approximators, such as DQN (and all its variants) and DDPG, are largely based on minimizing this MSBE loss function. There are two main tricks employed by all of them which are worth describing, and then a specific detail for DDPG.

Trick One: Replay Buffers. All standard algorithms for training a deep neural network to approximate Q^*(s,a) make use of an experience replay buffer. This is the set {\mathcal D} of previous experiences. In order for the algorithm to have stable behavior, the replay buffer should be large enough to contain a wide range of experiences, but it may not always be good to keep everything. If you only use the very-most recent data, you will overfit to that and things will break; if you use too much experience, you may slow down your learning. This may take some tuning to get right.

You Should Know

We've mentioned that DDPG is an off-policy algorithm: this is as good a point as any to highlight why and how. Observe that the replay buffer should contain old experiences, even though they might have been obtained using an outdated policy. Why are we able to use these at all? The reason is that the Bellman equation doesn't care which transition tuples are used, or how the actions were selected, or what happens after a given transition, because the optimal Q-function should satisfy the Bellman equation for all possible transitions. So any transitions that we've ever experienced are fair game when trying to fit a Q-function approximator via MSBE minimization.

Attempt at writing it without referring to any documents:
\section{Deep Learning}
The 'deep' part of deep learning refers to the idea of using multiple layers for a neural network model. In contrast, "shallow" neural networks only have about 2 layers.

How deep learning works is you have a computation graph. The computation graph consists of an input layer, additional layers, as well as an output layer. The input layer is as the name implies, it is the layer where the network receives input and the number of nodes at the input layer is typically defined in terms of the dimensions of the input (e.g. 3-dimensional input would have 3 nodes). The next layers also have nodes where each node is defined as follows: "Nodal value = f(Nodal value from previous layer * weight + bias)" where f is some non-linear function, w is some weight of the connection between the current node and the previous node, and the bias.

The output layer in general also involves some non-linear function. The number of nodes at the output layer also depends on the dimensions of the output.

Weights and biases are updated by optimizing some cost function (non-convex?).

Two operations are involved with deep learning: forward propagation and backward propagation. Forward propagation is the process of generating an output based on an input. An input is fed into the computation graph, and as the values pass through the layers and reaches the final layer an output is generated.

The generated output is compared against a desired output. This is known as supervised learning, where the inputs and outputs of a network are known, and the goal of deep learning is to learn the mapping between those inputs and outputs. The computation graph gets better at producing an output that matches the desired input through backpropagation. Backpropagation begins by calculating the error between the current output and the target (or desired) output. The derivative of this error with respect to the weights and biases of the network is then calculated. The weights and biases are then updated to minimize this error. To explain this, let's think about the derivatives. If the derivative (dError/dWeight) is positive, then a positive change in the weight will result in a positive change in the Error (increase in error). Conversely, if the derivative is negative, then a positive change in the weight will result in a negative change in the Error (decrease in error). Since error is root mean square error (and therefore always positive), a decrease in error will always lead to the minimum value (local or optimal, but never a negative value). The weights are updated based on a learning rate multiplied by the gradient of the error with respect to that weight.

As this process occurs over time, the network is said to "fit" or "learn" the data.

\section{Reinforcement Learning}

The goal of reinforcement learning is to learn some action, given a state, that maximises the expected reward. The state is represented by the input layer. The input layer captures data about the current state of affairs, and the network goal is to produce an output (which corresponds to action). This works by modelling phenomena as a markov decision process. That is, there is some state transition function that governs the world, and transitions between states occur as a result of actions taken by an agent. This state transition also results in some reward.


Our HA-DSGE model relaxes the simplifying assumption in the SOE model of a frictionless global capital market.
In this closed economy, factor prices $\Wage_t$ and $\rfree_t$ are determined in the usual way from the aggregate production function and aggregate state variables, including the stochastic aggregate shocks, putting the model in the (small, but rapidly growing) class of heterogeneous agent DSGE models.

For the HA-DSGE model, we set the discount factor to $\beta = {\Rprod}^{-1}=0.986$, roughly matching the target capital-to-output ratio.\footnote{The addition of aggregate and idiosyncratic risk implies that the capital-to-output ratio will be higher in the HA-DSGE model than the PF-DSGE calibration.  Moreover, the Markov growth process will move aggregate capital holdings away from the calibrated target.}
Households in the HA-DSGE model thus hold significantly more wealth than their counterparts in the baseline SOE model, who were calibrated to approximate the \textit{median} observed wealth-to-income ratio.
This reflects our goal of presenting results that span the full range of calibrations in the micro and macro literatures; the micro literature has often focused on trying to explain the wealth holdings of the median household, which are much smaller than average wealth holdings.
Experimentation has indicated that our results are not sensitive to such choices.

\subsection{Model and Solution}

We make the standard assumption that markets are competitive, and so factor prices are the
marginal product of (effective) labor and capital respectively. Denoting capital's share as $\kapShare$,
so that $\textbf{Y}_t = \KLevBF_t^\kapShare \LLevBF_t^{1-\kapShare}$, this yields the usual wage and interest rates:
\begin{eqnarray}
\Wage_t = \frac{\partial \textbf{Y}_t}{\partial \LLevBF_t} &=& (1-\kapShare) (\KLevBF_t/\LLevBF_t)^{-\kapShare}, \label{eq:MargProd} \\
\rfree_t = \frac{\partial \textbf{Y}_t}{\partial \KLevBF_t} &=& \kapShare (\underbrace{\KLevBF_t/\LLevBF_t}_{=\,\KLev_t/\Theta_t})^{\kapShare-1}. \nonumber
\end{eqnarray}
Net of depreciation, the return factor on capital is $\Rprod_t = 1 -\delta + \rfree_t$.

An agent's relevant state variables at the time of the consumption decision include the levels of household and aggregate market resources $(\mLevBF_{t,i},\MLevBF_t)$, as well as household and aggregate labor productivity $(p_{t,i},\PLev_t)$ and the aggregate growth rate $\PtyGro_t$.  We assume that agents correctly understand the operation of the economy, including the production and shock processes, and have \textit{beliefs} about aggregate saving---how aggregate market resources $\MLevBF_t$ become aggregate assets $\ALevBF_t$ (equivalently, next period's aggregate capital $\KLevBF_{t+1}$).  Following \cite{ksHetero} and \cite{cstwMPC}, we assume that households believe that the aggregate saving rule is linear in logs, conditional on the current aggregate growth rate:
\begin{equation}\label{eq:AggSaving}
\Ex[\ALevBF_t] = \aleph(\MLevBF_t,\PtyGro_t = \PtyGro_j) \equiv \exp\big(\aggrSavingRuleCoeff_{j,0} + \aggrSavingRuleCoeff_{j,1}\log(\MLevBF_t)\big).
\end{equation}

The growth-rate-conditional parameters $\aggrSavingRuleCoeff_{j,0}$ and $\aggrSavingRuleCoeff_{j,1}$ are exogenous to
the individual's (partial equilibrium) optimization problem, but are endogenous to the general
equilibrium of the economy.  Taking the aggregate saving rule $\aleph$ as given, the household's
problem can be written in Bellman form as:\footnote{Subject to definitions \eqref{eq:AggRandWalk},
\eqref{eq:IndRandWalk}, \eqref{eq:ell}, \eqref{eq:mDef}, \eqref{eq:aDef}, \eqref{eq:ktp1icompact},
\eqref{eq:Ktp1}, \eqref{eq:Lt}, \eqref{eq:Mtp1}, \eqref{eq:MargProd} and \eqref{eq:AggSaving}.}
\begin{eqnarray}
\textbf{v}(\mLevBF_{t,i},\MLevBF_t,p_{t,i},\PLev_t,\PtyGro_t) &=& \max_{\cLevBF_{t,i}} \big\{ \uFunc(\cLevBF_{t,i}) + \beta \Ex\big[(1-\pDies_{t,i})\textbf{v}(\mLevBF_{t+1,i},\MLevBF_{t+1},p_{t+1,i},\PLev_{t+1},\PtyGro_{t+1})\big] \big\}. \nonumber \\ \label{eq:DSGEproblem}
\end{eqnarray}

As in the SOE model, the household's problem can be normalized by the combined productivity level $\pLev_{t,i}$, reducing the state space by two continuous dimensions.  Dividing \eqref{eq:DSGEproblem} by $\pLev_{t,i}^{1-\CRRA}$ and substituting normalized variables, the reduced problem is:
\begin{eqnarray}
\vFunc(\mLev_{t,i},\MLev_t,\PtyGro_t) &=& \max_{\cLev_{t,i}} \big\{ \uFunc(\cLev_{t,i}) + \beta \PLives \Ex\big[(\PtyGro_{t+1} \pmb{\psi}_{t+1,i})^{1-\CRRA}\vFunc(\mLev_{t+1,i},\MLev_{t+1},\PtyGro_{t+1})\big] \big\} \nonumber \\
& \text{s.t.} & \label{eq:DSGEproblemNorm}\\
\aLev_{t,i} & = & \mLev_{t,i} - \cLev_{t,i}, \nonumber \\
\kLev_{t+1,i} & = & \aLev_{t,i}/\PLives, \nonumber \\
\mLev_{t+1,i} & = & \Rprod_{t+1} \kLev_{t+1,i}/(\PtyGro_{t+1}\pmb{\psi}_{t+1,i}) + \pmb{\theta}_{t+1,i} \Wage_{t+1}. \nonumber
\end{eqnarray}
Because household beliefs about the aggregate saving rule are linear in logs, \eqref{eq:AggSaving} holds with normalized market resources and aggregate assets as well as in levels.

The equilibrium of the HA-DSGE model is characterized by a (normalized) consumption function $\cFunc(\mLev,\MLev,\PtyGro)$ and an aggregate saving rule $\aleph$ such that when all households believe $\aleph$, the solution to their individual problem \eqref{eq:DSGEproblemNorm} is $\cFunc$; and when all agents act according to $\cFunc$, the best log-linear fit of $\ALev_t$ on $\MLev_t$ (conditional on $\PtyGro_t$) is $\aleph$.  The model is solved using a method similar to \cite{ksHetero}.\footnote{Details are in Appendix~\ref{app:Sol_DSGE}.}

\subsection{Frictionless vs Sticky Expectations}

The treatment of sticky beliefs in the HA-DSGE model is the natural extension of what we did in the SOE model presented in section \ref{sec:StickySOE}: Because the level of $\MLevBF_t$ now affects future wages and interest rates, a consumer's perceptions of that variable $\perc{\MLev}_{t,i} = \MLevBF_t/\perc{\PLev}_{t,i}$ now matter.  As households in our model do not necessarily observe the true aggregate productivity level, their perception of normalized aggregate market resources is
\begin{equation*}
\perc{\MLev}_{t,i} = \MLevBF_t\big/\perc{P}_{t,i} = \big(P_t\big/\perc{P}_{t,i}\big) \MLev_t .
\end{equation*}

Households in the DSGE model choose their level of consumption using their perception of their normalized state variables:
\begin{equation*}
\cLevBF_{t,i} = \perc{\pLev}_{t,i} \cFunc(\perc{\mLev}_{t,i},\perc{\MLev}_{t,i},\perc{\PtyGro}_{t,i}) = \cFuncLev(\mLevBF_{t,i},\MLevBF_{t},p_{t,i},\perc{\PLev}_{t,i},\perc{\PtyGro}_{t,i}).
\end{equation*}
Households who misperceive the aggregate productivity state will incorrectly predict aggregate saving at the end of the period, and thus aggregate capital and the distribution of factor prices next period.\footnote{This incorrect prediction is short-lived: all households will learn the true \textit{levels} of next period's aggregate capital and output.}

Because households who misperceive the aggregate productivity state will make (slightly) different consumption--saving decisions than they would have if fully informed, \textit{aggregate} saving behavior will be different under sticky than under frictionless expectations.  Consequently, the equilibrium aggregate saving rule $\aleph$ will be slightly different under sticky vs frictionless expectations.  When the HA-DSGE model is solved under sticky expectations, we implicitly assume that all households understand that all other households also have sticky expectations, and the equilibrium aggregate saving rule is the one that emerges from this belief structure.

\subsection{Results}
\label{appendix:HADSGEresults}

We report some of the equilibrium characteristics of the SOE and HA-DSGE models in Table~\ref{table:Eqbm}, to highlight their qualitatively similar patterns.
The table suggests a broad generalization that we have confirmed with extensive experimentation: With respect to either cross section statistics, mean outcomes, or idiosyncratic consumption dynamics, the frictionless expectations and sticky expectations models are virtually indistinguishable using microeconomic data, and very similar in most aggregate implications aside from the dynamics of aggregate consumption.
\input{"/$dstroot"/Tables/Eqbm.tex}

Table~\ref{tDSGEsim} reports the results of estimating regression \eqref{eq:CGrowBench} on data generated from the HA-DSGE model.  The results are substantially the same as the previous analysis for the SOE model (in Table~\ref{tPESOEsim}).\footnote{Essentially similar results are obtained if we assume that households have heterogeneous discount factors, in the style of \cite{cstwMPC}.  Using a calibration of the distribution of $\beta$ that approximately matches the distribution of net worth in the U.S., the results presented in Table~\ref{tDSGEsim} are effectively unchanged (table available upon request).  The main results hold whether $\beta$ is chosen to match aggregate asset holdings, the wealth of the median household, or the entire distribution of wealth; it is not sensitive to the particular calibration of the model.}

The model with frictionless expectations (top panel) implies aggregate consumption growth that is moderately (but not statistically significantly) serially correlated when examined in isolation (second row), but the effect ``washes out'' when expected income growth and the aggregate wealth to income ratio are included in the horse race regression (fourth row).  As expected in a closed economy model, the aggregate wealth-to-income ratio $\ALev_t$ is negatively correlated with consumption growth, but its predictive power is so slight that it is statistically insignificant in samples of only 200 quarters.

The model with sticky expectations (bottom panel) again implies a serial correlation coefficient of consumption growth not far from 0.75 in the univariate IV regression (second row).  As in the SOE simulation, the horserace regression (fifth row) indicates that the apparent success of the Campbell--Mankiw specification (third row) reflects the correlation of predicted current income growth with instrumented lagged consumption growth.

\input"/$dstroot"/Tables/DSGEmrkvSimReg.tex


\subsubsection{Yield Curves}

The top level XML elements for each \lstinline!YieldCurve! node are shown in Listing \ref{lst:top_level_yc}.

\begin{listing}[H]
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
<YieldCurve>
  <CurveId> </CurveId>
  <CurveDescription> </CurveDescription>
  <Currency> </Currency>
  <DiscountCurve> </DiscountCurve>
  <Segments> </Segments>
  <InterpolationVariable> </InterpolationVariable>
  <InterpolationMethod> </InterpolationMethod>
  <ZeroDayCounter> </ZeroDayCounter>
  <Tolerance> </Tolerance>
  <Extrapolation> </Extrapolation>
</YieldCurve>
\end{minted}
\caption{Top level yield curve node}
\label{lst:top_level_yc}
\end{listing}

The meaning of each of the top level elements in Listing \ref{lst:top_level_yc} is given below. If an element is labelled
as 'Optional', then it may be excluded or included and left blank.
\begin{itemize}
\item CurveId: Unique identifier for the yield curve.
\item CurveDescription: A description of the yield curve. This field may be left blank.
\item Currency: The yield curve currency.
\item DiscountCurve: If the yield curve is being bootstrapped from market instruments, this gives the CurveId of the
yield curve used to discount cash flows during the bootstrap procedure. If this field is left blank or set equal to the
current CurveId, then this yield curve itself is used to discount cash flows during the bootstrap procedure.
\item Segments: This element contains child elements and is described in the following subsection.
\item InterpolationVariable [Optional]: The variable on which the interpolation is performed. The allowable values are
given in Table \ref{tab:allow_interp_variables}. If the element is omitted or left blank, then it defaults to
\emph{Discount}.
\item InterpolationMethod [Optional]: The interpolation method to use. The allowable values are given in Table
\ref{tab:allow_interp_methods}. If the element is omitted or left blank, then it defaults to \emph{LogLinear}.
\item ZeroDayCounter [Optional]: The day count basis used internally by the yield curve to calculate the time between
dates. In particular, if the curve is queried for a zero rate without specifying the day count basis, the zero rate that
is returned has this basis. If the element is omitted or left blank, then it defaults to \emph{A365}.
\item Tolerance [Optional]: The tolerance used by the root finding procedure in the bootstrapping algorithm. If the
element is omitted or left blank, then it defaults to \num[scientific-notation=true]{1.0e-12}.
\item Extrapolation [Optional]: Set to \emph{True} or \emph{False} to enable or disable extrapolation respectively. If
the element is omitted or left blank, then it defaults to \emph{True}.
\end{itemize}

\begin{table}[h]
\centering
  \begin{tabu} to 0.9\linewidth {| X[-1.5,l,m] | X[-5,l,m] |}
    \hline
    \bfseries{Variable} & \bfseries{Description} \\
    \hline
    Zero & The continuously compounded zero rate \\ \hline
    Discount & The discount factor \\ \hline
    Forward & The instantaneous forward rate \\ \hline
  \end{tabu}
  \caption{Allowable interpolation variables.}
  \label{tab:allow_interp_variables}
\end{table}

\begin{table}[h]
\centering
  \begin{tabu} to 0.9\linewidth {| X[-1.5,l,m] | X[-5,l,m] |}
    \hline
    \bfseries{Method} & \bfseries{Description} \\
    \hline
    Linear & Linear interpolation \\ \hline
    LogLinear & Linear interpolation on the natural log of the interpolation variable \\ \hline
    NaturalCubic & Monotonic Kruger cubic interpolation with second derivative at left and right \\ \hline
    FinancialCubic & Monotonic Kruger cubic interpolation with second derivative at left and
                     first derivative at right \\ \hline
    ConvexMonotone & Convex Monotone Interpolation (Hagan, West) \\ \hline
  \end{tabu}
  \caption{Allowable interpolation methods.}
  \label{tab:allow_interp_methods}
\end{table}
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\subsubsection*{Segments Node} \label{ss:segments_node}
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The \lstinline!Segments! node gives the zero rates, discount factors and instruments that comprise the yield curve. This
node consists of a number of child nodes where the node name depends on the segment being described. Each node has a
\lstinline!Type! that determines its structure. The following sections describe the type of child nodes that are
available.

\subsubsection*{Direct Segment}
When the node name is \lstinline!Direct!, the \lstinline!Type! node has the value \emph{Zero} or \emph{Discount} and the
node has the structure shown in Listing \ref{lst:direct_segment}. We refer to this segment here as a direct segment
because the discount factors, or equivalently the zero rates, are given explicitly and do not need to be
bootstrapped. The \lstinline!Quotes! node contains a list of \lstinline!Quote! elements. Each \lstinline!Quote! element
contains an ID pointing to a line in the {\tt market.txt} file, i.e.\ in this case, pointing to a particular zero rate
or discount factor. The \lstinline!Conventions! node contains the ID of a node in the {\tt conventions.xml} file
described in section \ref{sec:conventions}. The \lstinline!Conventions! node associates conventions with the quotes.

\begin{listing}[H]
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
<Direct>
  <Type> </Type>
  <Quotes>
    <Quote> </Quote>
    <Quote> </Quote>
     <!--...-->
  </Quotes>
  <Conventions> </Conventions>
</Direct>
\end{minted}
\caption{Direct yield curve segment}
\label{lst:direct_segment}
\end{listing}

\subsubsection*{Simple Segment}
When the node name is \lstinline!Simple!, the \lstinline!Type! node has the value \emph{Deposit}, \emph{FRA},
\emph{Future}, \emph{OIS} or \emph{Swap} and the node has the structure shown in Listing \ref{lst:simple_segment}. This
segment holds quotes for a set of deposit, FRA, Future, OIS or swap instruments corresponding to the value in the
\lstinline!Type! node. These quotes will be used by the bootstrap algorithm to imply a discount factor, or equivalently
a zero rate, curve. The only difference between this segment and the direct segment is that there is a
\lstinline!ProjectionCurve! node. This node allows us to specify the CurveId of another curve to project floating rates
on the instruments underlying the quotes listed in the \lstinline!Quote! nodes during the bootstrap procedure. This is
an optional node. If it is left blank or omitted, then the projection curve is assumed to equal the curve being
bootstrapped i.e.\ the current CurveId.

\begin{listing}[H]
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
<Simple>
  <Type> </Type>
  <Quotes>
    <Quote> </Quote>
    <Quote> </Quote>
    <!--...-->
  </Quotes>
  <Conventions> </Conventions>
  <ProjectionCurve> </ProjectionCurve>
</Simple>
\end{minted}
\caption{Simple yield curve segment}
\label{lst:simple_segment}
\end{listing}

\subsubsection*{Average OIS Segment}
When the node name is \lstinline!AverageOIS!, the \lstinline!Type! node has the value \emph{Average OIS} and the node
has the structure shown in Listing \ref{lst:average_ois_segment}. This segment is used to hold quotes for Average OIS
swap instruments. The \lstinline!Quotes! node has the structure shown in Listing \ref{lst:average_ois_quotes}. Each
quote for an Average OIS instrument (a typical example in a USD Overnight Index Swap) consists of two quotes, a vanilla
IRS quote and an OIS-LIBOR basis swap spread quote.  The IDs of these two quotes are stored in the
\lstinline!CompositeQuote! node. The \lstinline!RateQuote! node holds the ID of the vanilla IRS quote and the
\lstinline!SpreadQuote! node holds the ID of the OIS-LIBOR basis swap spread quote.

\begin{listing}[H]
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
<AverageOIS>
  <Type> </Type>
  <Quotes>
    <CompositeQuote> </CompositeQuote>
    <CompositeQuote> </CompositeQuote>
    <!--...-->
  </Quotes>
  <Conventions> </Conventions>
  <ProjectionCurve> </ProjectionCurve>
</AverageOIS>
\end{minted}
\caption{Average OIS yield curve segment}
\label{lst:average_ois_segment}
\end{listing}

\begin{listing}[H]
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
<Quotes>
  <CompositeQuote>
    <SpreadQuote> </SpreadQuote>
    <RateQuote> </RateQuote>
  </CompositeQuote>
  <!--...-->
</Quotes>
\end{minted}
\caption{Average OIS segment's quotes section}
\label{lst:average_ois_quotes}
\end{listing}

\subsubsection*{Tenor Basis Segment}
When the node name is \lstinline!TenorBasis!, the \lstinline!Type! node has the value \emph{Tenor Basis Swap} or
\emph{Tenor Basis Two Swaps} and the node has the structure shown in Listing \ref{lst:tenor_basis_segment}. This segment
is used to hold quotes for tenor basis swap instruments. The quotes may be for a conventional tenor basis swap where
Ibor of one tenor is swapped for Ibor of another tenor plus a spread. In this case, the \lstinline!Type! node has the
value \emph{Tenor Basis Swap}. The quotes may also be for the difference in fixed rates on two fair swaps where one swap
is against Ibor of one tenor and the other swap is against Ibor of another tenor. In this case, the \lstinline!Type!
node has the value \emph{Tenor Basis Two Swaps}. Again, the structure is similar to the simple segment in Listing
\ref{lst:simple_segment} except that there are two projection curve nodes. There is a \lstinline!ProjectionCurveShort!
node for the index with the shorter tenor. This node holds the CurveId of a curve for projecting the floating rates on
the short tenor index. Similarly, there is a \lstinline!ProjectionCurveLong! node for the index with the longer
tenor. This node holds the CurveId of a curve for projecting the floating rates on the long tenor index. These are
optional nodes. If they are left blank or omitted, then the projection curve is assumed to equal the curve being
bootstrapped i.e.\ the current CurveId. However, at least one of the nodes needs to be populated to allow the bootstrap
to proceed.

\begin{listing}[H]
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
<TenorBasis>
  <Type> </Type>
  <Quotes>
    <Quote> </Quote>
    <Quote> </Quote>
    <!--...-->
  </Quotes>
  <Conventions> </Conventions>
  <ProjectionCurveLong> </ProjectionCurveLong>
  <ProjectionCurveShort> </ProjectionCurveShort>
</TenorBasis>
\end{minted}
\caption{Tenor basis yield curve segment}
\label{lst:tenor_basis_segment}
\end{listing}

\subsubsection*{Cross Currency Segment}
When the node name is \lstinline!CrossCurrency!, the \lstinline!Type! node has the value \emph{FX Forward} or
\emph{Cross Currency Basis Swap}. When the \lstinline!Type! node has the value \emph{FX Forward}, the node has the
structure shown in Listing \ref{lst:fx_forward_segment}. This segment is used to hold quotes for FX forward
instruments. The \lstinline!DiscountCurve! node holds the CurveId of a curve used to discount cash flows in the other
currency i.e.\ the currency in the currency pair that is not equal to the currency in Listing
\ref{lst:top_level_yc}. The \lstinline!SpotRate! node holds the ID of a spot FX quote for the currency pair that is
looked up in the {\tt market.txt} file.

\begin{listing}[H]
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
<CrossCurrency>
  <Type> </Type>
  <Quotes>
    <Quote> </Quote>
    <Quote> </Quote>
          ...
  </Quotes>
  <Conventions> </Conventions>
  <DiscountCurve> </DiscountCurve>
  <SpotRate> </SpotRate>
</CrossCurrency>
\end{minted}
\caption{FX forward yield curve segment}
\label{lst:fx_forward_segment}
\end{listing}

When the \lstinline!Type! node has the value \emph{Cross Currency Basis Swap} then the node has the structure shown in
Listing \ref{lst:xccy_basis_segment}. This segment is used to hold quotes for cross currency basis swap instruments. The
\lstinline!DiscountCurve! node holds the CurveId of a curve used to discount cash flows in the other currency i.e.\ the
currency in the currency pair that is not equal to the currency in Listing \ref{lst:top_level_yc}. The
\lstinline!SpotRate! node holds the ID of a spot FX quote for the currency pair that is looked up in the {\tt
  market.txt} file. The \lstinline!ProjectionCurveDomestic! node holds the CurveId of a curve for projecting the
floating rates on the index in this currency i.e.\ the currency in the currency pair that is equal to the currency in
Listing \ref{lst:top_level_yc}. It is an optional node and if it is left blank or omitted, then the projection curve is
assumed to equal the curve being bootstrapped i.e.\ the current CurveId. Similarly, the
\lstinline!ProjectionCurveForeign! node holds the CurveId of a curve for projecting the floating rates on the index in
the other currency. If it is left blank or omitted, then it is assumed to equal the CurveId provided in the
\lstinline!DiscountCurve! node in this segment.

\begin{listing}[H]
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
<CrossCurrency>
  <Type> </Type>
  <Quotes>
    <Quote> </Quote>
    <Quote> </Quote>
          ...
  </Quotes>
  <Conventions> </Conventions>
  <DiscountCurve> </DiscountCurve>
  <SpotRate> </SpotRate>
  <ProjectionCurveDomestic> </ProjectionCurveDomestic>
  <ProjectionCurveForeign> </ProjectionCurveForeign>
</CrossCurrency>
\end{minted}
\caption{Cross currency basis yield curve segment}
\label{lst:xccy_basis_segment}
\end{listing}

\subsubsection*{Zero Spread Segment}

When the node name is \lstinline!ZeroSpread!, the \lstinline!Type!
node has the only allowable value \emph{Zero Spread},  and the node has the structure shown in
Listing \ref{lst:zero_spread_segment}. This segment is used to build yield
curves which are expressed as a spread over some reference yield curve.

\begin{listing}[H]
%\hrule\medskip
\begin{minted}[fontsize=\footnotesize]{xml}
    <ZeroSpread>
          <Type>Zero Spread</Type>
          <Quotes>
            <Quote>ZERO/YIELD_SPREAD/EUR/BANK_EUR_LEND/A365/2Y</Quote>
            <Quote>ZERO/YIELD_SPREAD/EUR/BANK_EUR_LEND/A365/5Y</Quote>
            <Quote>ZERO/YIELD_SPREAD/EUR/BANK_EUR_LEND/A365/10Y</Quote>
            <Quote>ZERO/YIELD_SPREAD/EUR/BANK_EUR_LEND/A365/20Y</Quote>
          </Quotes>
          <Conventions>EUR-ZERO-CONVENTIONS-TENOR-BASED</Conventions>
          <ReferenceCurve>EUR1D</ReferenceCurve>
    </ZeroSpread>
\end{minted}
\caption{Zero spread yield curve segment}
\label{lst:zero_spread_segment}
\end{listing}


\SecDef{intro}{Introduction}

\subsection{Our Contribution}

{\bf Components of Protection.} We propose in \SecRef{method} a general method for designing a secure white-box implementation. The idea is to split the protection into two independent components: \emph{value hiding} and \emph{structure hiding}. The value hiding component must provide protection against passive DCA-style attacks - attacks that rely solely on analysis of computed values. In particular, it must provide security against the correlation attack and the algebraic attack. We suggest that security against these two attacks can be achieved by applying a classic linear masking scheme on top of a nonlinear masking scheme protecting against the algebraic attack. The structure hiding component must secure the implementation against circuit analysis attacks. The component must protect against circuit minimization, pattern recognition, pseudorandomness removal, fault injections, etc. Possibly this component may be splitted into more sub-components (e.g. an integrity protection). Development of a structure hiding protection is left as a future work.

{\bf Provably Secure Construction.} Classic $t$-th order masking schemes protect against adversaries that are allowed to probe $t$ intermediate values computed by the implementation. The complexity of the attack grows fast when $t$ increases. In the new algebraic attack the adversary is allowed to probe all intermediate values but she can combine them only with a function of low algebraic degree $d$. Similarly, the attack complexity grows fast when $d$ increases and also when the circuit size increases. We develop a framework for securing an implementation against the algebraic attack. It includes a formal security model and a proof of the composability of first-order secure circuits. Finally, I describe our first-order secure masking scheme implementing \txor{} and \tand{} operations. As a result, our framework provides provable security against the first-order algebraic attack. I show concrete security bounds for our construction. Finally, we implement the AES-128 block cipher protected using our new masking scheme.

A code implementing the attacks from \ChapRef{wba}, verification of the algebraic masking schemes and the masked AES-128 implementation is publicly available at~\cite{OurWhiteboxCode}:
\begin{center}
    \url{https://github.com/cryptolu/whitebox}
\end{center}

\subsection{Outline}
I describe our general method for securing a white-box design in \SecRef{method}. In \SecRef{framework} a framework is developed for countermeasures against the algebraic attack. In~\SecRef{minimalist} I describe a simple quadratic masking scheme following the proposed framework. Finally, I conclude and suggest future work in \SecRef{conclusions}.