% -*- root: 00-main.tex -*-
\section{Methods}\label{sec:regseg-methods}

\subsection{Registration framework and segmentation model}\label{sec:regseg-methods_map}
Let $\gammaset_R = \{\Gamma_m: m \in \mathbb{N}, m \leq N_S\}$ be the set of $N_S$ surfaces
  extracted from the undistorted \gls*{t1} image (the reference space $R$).
We reformulate the segmentation of the distorted \gls*{dmri} images (the moving space $M$)
  as a registration problem where we search for an underlying deformation field $U$ such that
  the structures in $R$ defined by $\gammaset_R$ align optimally with their corresponding
  structures in $M$:

  \begin{align}
  U\colon R \subset \mathbb{R}^n &\to M \subset \mathbb{R}^n \notag\\
  \vec{r} &\mapsto \vec{r}' =\vec{r}+\vec{u}(\vec{r}),
  \label{eq:regseg-transform}
  \end{align}
  where $\vec{r}$ denotes a position in $R$, $\vec{r}'$ is
  its corresponding location in $M$, and $n$ denotes the dimensionality of images.
Finally, $\vec{u} = \vec{u}(\vec{r})$ is the displacement of every point with respect
  to the reference domain.
The general overview of how the surfaces interact with the registration framework
  is presented in \autoref{fig:regseg-method}.

\begin{figure}
  \includegraphics[width=\linewidth]{figure01}
  \caption{The interfacing surfaces $\Gamma_m$ between the competing \glspl{roi} $\Omega_l$,
  play the role of active contours which drive the registration process.
  They evolve iteratively along the normal $\hat{\mathbf{n}}_i$ of the surface at each vertex
    $\vec{v}_i$ of the mesh.
  The gradient speeds $\bar{s}_i$ drive registration, which are computed as the disparity of the data
    energies with respect to the two limiting regions of $M(\vec{v}_i)$, the features of the image
    $M$ in the location of vertex $\vec{v}_i$.
  The computation of shape-gradients is developed in \ref{app:shape_gradients}.
  In this figure, the $\bar{s}_1$ derived from \autoref{eq:regseg-shape_gradient_disc2} is
    written in the lower box, with $\Omega_{wm}$ being the inner limiting region, $\Omega_{gm}$
    the outer region, and $w_{0,1}$ the relative area associated with vertex $\vec{v}_1$
    with respect to the total area of surface $\Gamma_0$.
  }\label{fig:regseg-method}
\end{figure}

\paragraph*{Cost-function derivation}
In a Bayesian framework for registration \citep{wyatt_map_2003,pohl_bayesian_2006,gass_simultaneous_2014},
  the mappings $U$ in \eqref{eq:regseg-transform} are
  evaluated based on their posterior probability given the observed data
  $M$.
Let $\omegaset = \{\Omega_l: l \in \mathbb{N}, l \leq N_L\}$ be the set of $N_L$ competing regions in
  which $M$ is partitioned by the projection of $\gammaset_R$.
Using Bayes' rule, the posterior likelihood is computed as:

  \begin{equation}
  P(U \mid M, \omegaset ) = \frac{P(M \mid U,\omegaset )\, P(U)}{P(M)},
  \label{eq:regseg-bayes_rule}
  \end{equation}
  where $P(M \mid U,\omegaset)$ is the data likelihood.
Since $\omegaset$ is mapped by $U$, we simplify
  $P(U, \omegaset) = P(U) \implies P(M \mid U,\omegaset) = P(M \mid U)$.
The best estimate $\hat{U}$ then satisfies the maximum a posteriori criterion
  and it aligns $\gammaset_R$ into $M$.
First, we assume independence between \revcomment[R\#3-C10]{voxel}s, and thus we break down the
  global data likelihood into a product of \revcomment[R\#3-C10]{voxel}-wise conditional probabilities:

  \begin{equation}
  P(M \mid U) = \underset{l}{\prod} \underset{\vec{r}'\in \Omega_l}{\prod}
    P\left( \vec{f}' \mid U \right),
  \label{eq:regseg-bayes_aposteriori}
  \end{equation}
  where $\vec{f}' = M(\vec{r}')$ is the feature vector at the displaced
  position $\vec{r}'$ \eqref{eq:regseg-transform} in the moving image.
For convenience and because it has been shown to be an appropriate approximation
  \citep{leemput_automated_1999,cuadra_comparison_2005}, we introduce two assumptions for each
  region $\Omega_l$:
  1) the features are i.i.d.; and 2) they can be modeled by multivariate normal
  distributions
  $\mathcal{N} (\vec{f}' \mid \boldsymbol{\mu}_l, \boldsymbol{\Sigma}_{l} )$, with parameters
  $\lbrace \boldsymbol{\mu}_l, \boldsymbol{\Sigma}_{l} \rbrace$
  for each region $\Omega_l$ \citep{esteban_mbis_2014}:

  \begin{align}
  P( M \mid U) &= \underset{l}{\prod} \underset{\vec{r}' \in \Omega_l}{\prod}
  \mathcal{N} (\vec{f}' \mid \boldsymbol{\mu}_l, \boldsymbol{\Sigma}_{l} )
  \ifthenelse{\boolean{review}}{=}{= \notag\\ &=}
  \underset{l}{\prod} \underset{\vec{r}' \in \Omega_l}{\prod} \frac{1}{ \sqrt{(2\pi)^{C}\,\left|\boldsymbol{\Sigma}_{l}\right|}}\,{e^{\left(-\frac{1}{2}
  \mdist{f'}{l} \right)}},
  \label{eq:regseg-pdf}
  \end{align}%
  using $\mdist{f'}{l}$ to denote the squared \emph{Mahalanobis distance} of $\vec{f}'$ with respect
  to the descriptors of region $l$ as
  $\mdist{f'}{l} = (\vec{f}' - \boldsymbol{\mu}_l)^T \, {\boldsymbol{\Sigma}_l}^{-1} \, (\vec{f}' - \boldsymbol{\mu}_l)$.
$C$ is the number of channels comprised in the image $M$.
Even though the features being segmented are not generally i.i.d., the
  spatial interdependency of voxels is implicitly supported by the piecewise smooth
  partition of the space \omegaset{}.
In fact, the projection of $\gammaset_R$ onto $M$ is an implicit segmentation model, for which
  the covariance matrix $\boldsymbol{\Sigma}_l$ of each region is minimized.
The \autoref{fig:regseg-model} shows how the joint distribution of
  the input images is approximated with a mixture of multivariate normal distributions,
  and this minimization is illustrated for the segmentation of the \gls*{fa} and the \gls*{adc} maps
  of one subject.

\begin{figure*}
\includestandalone[width=\textwidth]{figure02}
\caption{%
Evolution of the segmentation model defined by the homogeneous regions $\Omega_l$,
  for one real dataset.
Panel (A, left) shows the joint distribution of the \gls*{fa} and \gls*{adc} conditioned to
  the segmentation \omegaset{} defined by the surfaces $\gammaset_R$ extracted from
  the \gls*{t1} image.
The plot was generated for reference using undistorted diffusion data, and
  therefore, $\gammaset_R$ is aligned with the \gls*{fa} and the \gls*{adc}.
The problem arises when the diffusion data present deformation, and the
  contours $\gammaset_R$ do not fit within the data (A, center).
After registration with \regseg{}, the contours are mapped onto the
  diffusion data (A, right), and the joint density plot is closer to the reference
  situation.
In panel (B), the three plots in (A) are decomposed tissue-wise.
Using filled contours, the bivariate distribution of each tissue is highlighted in its designated color,
  and represented over the remaining tissues (in gray colors).
To help assessment, dashed contours in black-to-white colors represent
  the corresponding distribution in the reference plot.
The registration process optimizes the segmentation model of \regseg{},
  and thus, the distribution of each region after registration is located
  closer to that corresponding in the reference situation, the shape of the distribution
  is more similar to the reference, and their spread is also reduced.
The effects of optimization are more noticeable on the \gls*{gm} ($\Omega_\text{GM}$) and
  the \gls*{wm} ($\Omega_\text{WM}$).
Particularly, the \gls*{wm} typically shows a bimodal distribution when the contours
  \gammaset{} do not fit the data.
{\color{revcolor} The plots in (A) and (B) are provided at full-size in the
  \citetalias[figures S8, S9]{esteban_useful_2016}.}
}\label{fig:regseg-model}
\end{figure*}

\paragraph*{Regularization}
The smoothness of the resulting displacement field is induced
  by a Thikonov regularization prior:

  \begin{align}
  P(U) = \underset{\vec{r}}{\prod}\, p(\vec{u}) &=
  \underset{\vec{r}}{\prod}\, p_0(\vec{u}) \, p_1(\vec{u}), \text{ with} \\
  p_0(\vec{u}) &= \mathcal{N}( \vec{u} \mid 0, \mathbf{A}^{-1}), \notag\\
  p_1(\vec{u}) &= \mathcal{N}(  \nabla \vec{u} \mid 0, \mathbf{B}^{-1}),
  \label{eq:regseg-thikonov}
  \end{align}
 which requires that the distortion and its gradient have zero mean,
   and variance governed by the matrices $\mathbf{A}$ and $\mathbf{B}$.
Therefore, $\mathbf{A}$ and $\mathbf{B}$ are tensors that modulate the regularization, and
  produce deformations with preferential directions.
Finally, the maximum a posteriori problem is adapted to a variational problem where we search for
  the minimum of an energy functional by applying $E(\vec{u}) = -\log \{P( M \mid U) \, P(U)\}$:

  \begin{align}
  E(\vec{u}) &= -\log \underset{l}{\prod}
  \underset{\vec{r}' \in \Omega_l}{\prod}
  \mathcal{N} \left( \vec{f}' \mid \boldsymbol{\mu}_l, \boldsymbol{\Sigma}_l \right)\,p_0( \vec{u})\,p_1( \vec{u}) =
\notag\\ &= - \underset{l}{\sum} \int_{\Omega_l} \Big\{ \log \left[ \mathcal{N} \left( \vec{f}' \mid \boldsymbol{\mu}_l, \boldsymbol{\Sigma}_l \right) \right] \, + \log \left[ p_0( \vec{u})\,p_1( \vec{u}) \right] \Big\} \, d\vec{r}'
   = \notag\\ &=
  \const + \underset{l}{\sum} \Big\{ \int_{\Omega_l} \mdist{f'}{l} \,d\vec{r} \Big\} \,
  + \int_{\Omega} \frac12 \left[ \vec{u}^T \mathbf{A} \vec{u} + (\nabla \vec{u})^T \mathbf{B} (\nabla \vec{u}) \right] \,d\vec{r}'.
  \label{eq:regseg-energy}
  \end{align}%
This expression is the dual of the Mumford-Shah functional that corresponds
  to the framework of \acrlong*{acwe} \citep{chan_active_2001}
  with the anisotropic regularization term of \cite{nagel_investigation_1986}.

\subsection{Numerical Implementation}
\label{sec:regseg-numerical_implementation}

\paragraph*{Deformation model}\label{sec:regseg-deformation_model}
Since the vertices of the surfaces $\{\vec{v}_i: \vec{v}_i \subset \gammaset \}_{i=1 \ldots N_V}$
  are probably located off-grid, it is necessary to derive $\vec{u}_i = \vec{u}(\vec{v}_i)$ from a discrete set of parameters
  $\{\vec{u}_k\}_{k=1 \ldots K}$.
Densification is achieved using a set of associated basis functions $\psi_k$ \eqref{eq:regseg-nodes_tfm}.
In our implementation, $\psi_k$ is a tensor-product B-spline kernel of degree three.

  \begin{equation}
  \vec{v}_i' = \vec{v}_i + \vec{u}_i = \vec{v}_i + \sum_k \psi_k(\vec{r}) \: \vec{u}_k.
  \label{eq:regseg-nodes_tfm}
  \end{equation}

\paragraph*{Optimization}
\label{sec:regseg-gradient_descent}
To find the minimum of the energy functional \eqref{eq:regseg-energy},
  we propose a gradient-descent approach with respect to the underlying
  deformation field using the following \gls*{pde}:

  \begin{equation}
  \frac{\partial \vec{u}(\vec{r},t)}{\partial t} \propto - \frac{\partial E(\vec{u})}{\partial \vec{u}_k},
  \label{eq:regseg-general_gradient_descent}
  \end{equation}
  where $t$ is an artificial time parameter of the contour
  evolution and $\vec{u}_k$ are the parameters that support the estimate
  $\hat{U}$ of the transformation at the current time point.
Let us assume that the preferential directions of
  the displacement are aligned with the imaging axes to simplify \eqref{eq:regseg-energy} as expression
  \eqref{eq:regseg-app_energy} in \ref{app:reg_term}, and thus to compute its
  derivative \eqref{eq:regseg-general_gradient_descent}:

  \begin{align}
  \frac{\partial E(\vec{u})}{\partial \vec{u}_k} &=
  \frac{ \partial }{\partial \vec{u}_k} \Big\{
  \underset{l}{\sum} \big[ \int_{\Omega_l} \mdist{f'}{l} \,d\vec{r}' \big] \,
  + \int_{\Omega} \frac12 [ \boldsymbol{\alpha} \cdot \vec{u}^{\circ2}
  + \boldsymbol{\beta} \cdot (\nabla \vec{u})^{\circ2} ] \,d\vec{r}'
  \Big\},
  \label{eq:regseg-gradient_descent}
  \end{align}
  where $\vec{u}^{\circ2} = \vec{u}^T \cdot \vec{u}$,
  and $\{\boldsymbol{\alpha}, \boldsymbol{\beta}\}$ are the expected variances along
  the imaging axes of the displacement field and its gradient, respectively.
Then, the data and regularization terms are split and discretized to compute their
  derivatives.
The derivative of the data term is computed using explicit shape gradients (see \ref{app:shape_gradients}),
  which finally lead to obtain vertex-wise speeds of the gradient $\bar{s}_i$ as
  illustrated in \autoref{fig:regseg-method}.
\revcomment[R\#1-C4]{%
The shape gradient contributions $\vec{g}_k$ on the field coefficients $\vec{u}_k$
  can then be computed }%
using the expression \eqref{eq:regseg-gradient_wshape}
\revcomment[R\#1-C4]{of \ref{app:shape_gradients}, obtaining:

\begin{equation}
  \vec{g}_k = - \underset{i}{\sum} \bar{s}_i \cdot \psi_k(\vec{v}_i) \, \hat{\vec{e}}.
  \label{eq:regseg-shape_gradient_final}
\end{equation}

Then,} introducing the analytical derivative of the regularization term,
  the \autoref{eq:regseg-gradient_descent} is reformulated as:

  \begin{align}
  \frac{\partial E(\vec{u})}{\partial \vec{u}_k} &=
  \vec{g}_k  + \boldsymbol{\alpha} \cdot \vec{u}_k - \boldsymbol{\beta} \cdot (\Delta \vec{u}_k).
  \label{eq:regseg-final_gradient}
  \end{align}
Finally, to descend this gradient, we establish a semi-implicit Euler scheme
  \citepalias[see][section S1.3]{esteban_useful_2016},
  with a step size parameter $\delta$, which we solve in the spectral domain as follows:

  \begin{align}
  \vec{u}_k^{t+1} = \mathcal{F}^{-1}\left\{ \frac{\mathcal{F}\{\delta^{-1} \, \vec{u}_k^t - \vec{g}_k\} }
                    {\mathcal{F}\{(\delta^{-1} + \boldsymbol{\alpha})\, I - \boldsymbol{\beta}\Delta\}} \right\},
  \label{eq:regseg-update_equation}
  \end{align}
  where $I$ denotes the identity operator.

\paragraph*{Implementation details and convergence}%
\label{sec:regseg-conv_report}
The \regseg{} tool includes a multiresolution strategy on the free-form deformation field.
Registration pyramids are created by setting the spacing between the control points of the B-spline basis
  functions for each level of the multiresolution strategy.
As a rule of thumb, for a $\delta =$ 1.0, both $\boldsymbol{\alpha}$
  and $\boldsymbol{\beta}$ will typically be in the range [0.0, 1.0].
The parameters used ($\delta$, $\boldsymbol{\alpha}$, $\boldsymbol{\beta}$, the B-spline grid resolutions,
  and target image smoothing), the implementation details, and other features such as the sparse matrix
  approach to fast interpolation are discussed in the \citetalias[][section S1]{esteban_useful_2016}.

\subsection{Evaluation protocol}\label{sec:regseg-evaluation_protocol}
In order to assess the performance of \regseg{}, we defined the following general
  evaluation protocol:
1) Extract the set of undistorted surfaces $\gammaset_R$;
2) Compute a ground-truth field of displacements $U_\text{true}$, which is applied to
  generate warped images ($M$) for segmentation;
3) Execute \regseg{} with $\gammaset_R$ and use the warped data as inputs; and
4) Perform a visual assessment and compute the error metrics.

A first proof of concept is introduced to demonstrate \regseg{} in digital phantoms
  with simple geometries, using $U_\text{true}$ without directional restrictions.
Then, \regseg{} is evaluated in a framework using undistorted \gls*{dmri} datasets,
  and $U_\text{true}$ is derived from the corresponding inhomogeneity fieldmap of
  the subject.
Therefore, the deformation field is nonzero only in the \acrfull*{pe} axis,
  and reproduces a real \gls*{epi} distortion.
The adaptation of the evaluation protocol to the simulated phantoms and the real data is
  explained in the following sections.

\subsection{Simulated phantoms}\label{sec:regseg-digital_phantoms}
The workflow required to simulate the digital phantoms and to assess the performance of
  \regseg{} with them is presented in \autoref{fig:regseg-evphantoms}.
A set of four binary objects (i.e. ``box'', ``ball'', ``L'',
  and ``gyrus'') was generated by combining the binarization of
  analytical shapes and mathematical morphology.
The reference surfaces $\gammaset_R$ were extracted from the binary shapes
  using \emph{FreeSurfer} tools \citep{fischl_freesurfer_2012}.
The ground-truth distortion was generated using a chain of two displacement
  fields supported by grids of B-spline basis functions.
The coefficients of the basis functions were generated randomly for
  both levels in their three dimensions.
The three components of the displacements $\vec{u} = (u_d)$
  were bounded above by 40\% of the separation between the control points
  at each level to obtain diffeomorphic transforms
  after concatenation \citep{rueckert_diffeomorphic_2006}.
The first deformation field was applied to generate large warpings
  with control points separated by 50.50 mm in the three dimensions
  ($u_d\leq$ 20.20 mm).
With the second warping, we aimed to obtain a field with smoothness
  close to that found in a typical distortion field of \gls*{dmri} data
  \citep{irfanoglu_susceptibility_2011}.
Therefore, the control points were separated by 25.25 mm ($u_d\leq$ 10.10 mm).
After generating the ground-truth deformation, the original surfaces
  were warped by interpolating the displacement field at each vertex.
The warped surfaces $\gammaset_\text{true}$ were binarized to generate tissue fractions
  at low (\isores[mm]{2.0}) and high (\isores[mm]{1.0}) resolutions.
Using an \acrshort*{mri} simulator \citep{caruyer_phantomas_2014}, we synthesized
  \gls*{t1} (TE/TR= 10/1500 ms) and \gls*{t2} images (TE/TR= 90/5000 ms), which
  corresponded to each phantom type, with each at two resolutions
  (1.0 mm and 2.0 mm isotropic).
The field of view at both resolutions was \isores[mm]{100}.
Next, \regseg{} was applied to map $\gammaset_R$ onto the warped phantoms to
  obtain the registered surfaces ($\hat{\gammaset}_\text{test}$).
To quantify the misregistration error, we computed the Hausdorff distance between
 $\hat{\gammaset}_\text{test}$ and $\gammaset_\text{true}$ using \citep{commandeur_vtk_2011}.
In total, 1200 experiments (four phantom types $\times$ 150 random warpings $\times$ two resolutions) were
  performed according to the workflow illustrated in \autoref{fig:regseg-evphantoms}.

\begin{figure*}
\includegraphics[width=\linewidth]{figure03}
\caption{Evaluation of \regseg{} using phantom data according to the following instrumental workflow.
  1) The reference surfaces $\gammaset_R$ are triangle meshes extracted from the four binary shapes (i.e., ``box'', ``ball'', ``L'', ``gyrus'').
  2) A ground-truth displacement field was generated as described in \autoref{sec:regseg-digital_phantoms}, and applied to warp
      $\gammaset_R$, thereby obtaining $\gammaset_\text{true}$.
  3) After being warped, $\gammaset_\text{true}$ were projected onto the corresponding discrete 3D volume and downsampled to create partial volume effects at two resolutions,
     i.e., \isores[mm]{2.0} and \isores[mm]{1.0}, thereby producing sets of tissue fractions maps.
  4) The tissue fractions were fed into an \acrshort*{mri} simulator, which generated \acrfull*{t1} and \acrfull*{t2} -like images at the
     two possible resolutions.
  5) The \regseg{} tool was applied using the warped test images as multispectral moving images and $\gammaset_R$ as shape priors.
  6) The agreement between the surfaces fitted by \regseg{} ($\hat{\gammaset}_\text{test}$) and $\gammaset_\text{true}$ were assessed
     visually using automatically generated visual reports and quantitatively with the Hausdorff distance between the
     corresponding surfaces.}\label{fig:regseg-evphantoms}
\end{figure*}

\paragraph*{Segmentation model and settings}
The segmentation model of the phantoms is implicitly defined:
  all phantoms comprehend an inner surface enclosing a uniform \gls*{wm}-like region,
  and an outer surface wrapping a \gls*{gm}-like layer.
The outside is filled with uniform background (see \autoref{fig:regseg-evphantoms}).
All the experimental settings used for the phantoms are made available in
  a unique configuration file\footnote{\url{https://github.com/oesteban/RegSeg/blob/master/Scripts/pyacwereg/data/regseg_default.json}}.

\subsection{Real datasets} \label{sec:regseg-human_connectome}
The experimental framework for the real datasets is presented in \autoref{fig:regseg-evworkflows},
which extends our previous evaluation \citep{esteban_simulationbased_2014} of distortions
  using \gls*{dmri} phantoms.

\begin{figure*}
\includegraphics[width=\linewidth]{figure04}
\caption{Experimental workflow employed to process real data from the \acrfull*{hcp}.
  1) $\gammaset_R$ were extracted from the anatomical reference (\gls*{t1} image).
  2) For use as the ground truth, we generated a plausible synthetic distortion $U_\text{true}$
    from the fieldmap with \eqref{eq:regseg-fieldmap}.
  3) The \gls*{dmri} data were warped using $U_\text{true}$ to reproduce the effects of real
    susceptibility-derived distortions.
  Target diffusion scalars (\gls*{fa} and \gls*{adc}) were computed with the distorted data and
    stacked to feed the multivariate input required by \regseg{}.
  4) The method was run to obtain $U_\text{test} = \hat{U}_\text{true}$, i.e., the estimate of
    the ground-truth deformation.
  5) The results were evaluated visually and quantitatively.
  The arrows in the step (5) point to edges in the target images (light-yellow arrows for \gls*{fa}, blue for
    \gls*{adc}) that should be aligned with a surface, showing how distortion limits the direct mapping from
    the structural space in which the contours are defined.}\label{fig:regseg-evworkflows}
\end{figure*}

\paragraph*{Data}
To evaluate \regseg{} using real \gls*{dmri} data obtained from human brains,
  we collected 16 subjects from the \revcomment[R\#3-C9]{Q3 Release of the}
  \gls*{hcp} database.
The original acquisitions are released within ``unprocessed'' packages, whereas
  the ``minimally preprocessed'' packages contain the corresponding images after
  some processing (correction for several artifacts, brain-extraction, spatial
  normalization, etc.).
We refer the reader to \citet{essen_human_2012} for exact details of the acquisition
  parameters and \citet{glasser_minimal_2013} for the preprocessing issues.
These datasets comprise a large set of images, including \gls*{t1}, \gls*{t2}, and
  multi-shell \gls*{dmri} images.
Since we obtained the \gls*{dmri} data from the minimally preprocessed package, these
  images are corrected for \gls*{epi} distortions and spatially normalized in
  \gls*{t1} space.
\revcomment[R\#3-C9]{In the Q3 Release of the \gls*{hcp}, the \gls*{dmri} session includes
  six runs, two runs for each of three different gradient tables, and each table is acquired
  once with right-to-left and left-to-right encoding polarities, respectively.
Then, the diffusion datasets with opposed polarities are corrected for susceptibility
  distortions using the \emph{TOPUP} tool \citep{andersson_how_2003}
  before producing the released ``minimally preprocessed'' data}.

\paragraph*{Segmentation model}
Based on our experience % \citep{esteban_brain_2012}
  and previous studies \citep{ennis_orthogonal_2006},
  we defined the moving image as a stack of the \gls*{fa} and \gls*{adc} maps derived
  from \gls*{dmri} data.
After evaluating several alternative models, we empirically defined a partition \omegaset{}
  according to the following six regions:
  1) thalamus ($\Omega_\text{Tha}$);
  2) ventricular system and deep \gls*{gm} structures ($\Omega_\text{VdGM}$);
  3) cerebral \gls*{wm} ($\Omega_\text{WM}$);
  4) brain stem and cerebellar \gls*{wm} ($\Omega_\text{bst}$);
  5) cerebellar \gls*{gm} ($\Omega_\text{cbGM}$); and
  6) cortical \gls*{gm} ($\Omega_\text{GM}$).
Using tools in \emph{FreeSurfer} and appropriate selections of labels in the
  \emph{aparc} segmentation released with the \gls*{hcp} data, we extracted the $\gammaset_R$ set for the
  reference surfaces.
The segmentation model corresponding to this partition is shown in \autoref{fig:regseg-model}
  and discussed in greater detail in the \citetalias[section S4]{esteban_useful_2016}.

\paragraph*{Ground-truth generation}
Realistic deformation was achieved by generating displacement fields that satisfy the theoretical
  properties of distortion.
The displacements along the \gls*{pe} axis of the \gls*{dmri} image are related to the local
  deviation of the field $\Delta B_0(\vec{r})$ from its nominal value $B_0$  \citep{jezzard_correction_1995},
  as follows:

  \begin{equation}
  u_\text{PE} = \frac{\gamma \, T_{acq}\, s_\text{PE}}{2\pi}\Delta B_0(\vec{r})\text{ [mm]},
  \label{eq:regseg-fieldmap}
  \end{equation}
where $\gamma$ is the gyromagnetic ratio, $T_{acq}$ is the readout time, and
  $s_\text{PE}$ is the \revcomment[R\#3-C10]{voxel} size along \gls*{pe}.
Certain \acrshort*{mri} sequences are designed to estimate $\Delta B_0$, thereby obtaining
  the so-called fieldmap.
We derived the deformation $U_\text{true}$ from the fieldmap image released with
  the corresponding packages of each dataset in the \gls*{hcp}.
The fieldmap was unwrapped\footnote{fieldmaps are phase maps, which are intrinsically clipped in the interval
  of $[-\pi, \pi)$ [rads] or [rads/s].} and smoothed before applying \eqref{eq:regseg-fieldmap}.
Next, the original \gls*{dmri} was warped using the resulting displacement field and fed into
  a pipeline to process the corresponding \gls*{dti}, thereby computing the derived scalars of
  interest (\gls*{fa} and \gls*{adc}) using \emph{MRtrix} \citep{tournier_mrtrix_2012}.

\paragraph*{Metric assessment}
Initially, we investigated the appropriateness of the segmentation model.
For five test datasets, we uniformly sampled the space of distortions
  $\hat{U} = \epsilon \cdot U_\text{true} = \vec{r} + \epsilon \, u_\text{PE}$
  (with $\epsilon \in [-1.1, 1.1]$ and $u_\text{PE}$ from \eqref{eq:regseg-fieldmap}),
  and we evaluated the data term of the cost function \eqref{eq:regseg-energy}.
The minimum of the cost function (\autoref{sec:regseg-methods_map}) was consistently located at
  $\epsilon=0.0$ (the ground-truth) for all of the cases \citepalias[figure S2]{esteban_useful_2016}.

\paragraph*{Settings} %
\Regseg{} accepts an affine mapping from surface-space to the \gls*{dmri} data as initialization.
However, the images provided by the \gls*{hcp} are already spatially normalized.
Therefore, the initial estimation of distortion is zero in this experiment.
Since the distortion $U_\text{true}$ is aligned along the \gls*{pe} direction ($y$-axis in our settings),
  \regseg{} was configured to allow nonzero displacements only on that corresponding direction.
For the experiments on real data, \regseg{} established a multi-resolution pyramid of
  B-spline functions, with control points distributed on grids of the following spacings:
  40$\times$100$\times$40 [mm] for the first (coarser) level, \isores[mm]{30} for the second level,
  and 20$\times$30$\times$10 [mm] in the third level.
Only the first and second levels included Gaussian smoothing of the target image ($\sigma$ = [2.0, 0.5] mm,
  respectively).
The actual choices of the parameter settings are publicly distributed with the source code for the
  experiments\footnote{\url{https://github.com/oesteban/RegSeg/tree/master/Scripts/pyacwereg/data/regseg_hcp.json}}.
These settings were obtained manually, driven by the feedback obtained from the post-registration
  convergence reports \citepalias[like that found in][section S1.3]{esteban_useful_2016}.
We released \regseg{} along with the tool to generate such convergence reports.

\paragraph*{Cross-comparison} %
A dual workflow to the general evaluation used for \regseg{} (\autoref{fig:regseg-evworkflows}),
  was employed to integrate the alternate \gls*{t2b} registration scheme.
We reproduced the solution and settings provided with \emph{ExploreDTI}
  \citep{leemans_exploredti_2009}, which is a widely used toolkit for tractography analysis of
  \gls*{dti}.
\emph{ExploreDTI} internally employs \emph{elastix} \citep{klein_elastix_2010} to
  perform registration.
The deformation field is correspondingly restricted to the \gls*{pe} direction.
The settings file for \emph{elastix} is also
  available\footnote{\url{https://github.com/oesteban/RegSeg/blob/master/Scripts/pyacwereg/data/t2b_elastix_y.txt}}.
\revcomment[R\#3-C7\\R\#3-C8]{%
In this registration scheme, the \gls*{t2} image is the \emph{reference} and
  the \lowb{} plays the role of \emph{moving} image.
Therefore, the transform is defined in the coordinate system of the \gls*{t2} image,
  and for each point in this space it provides the location of the corresponding feature
  in the \lowb{} image.
Since the surfaces are defined in the \gls*{t2} --\emph{reference}-- space, their coordinates
  can be mapped to the \lowb{} space using this transform, obtaining the
  \emph{distorted surfaces} corresponding to the \lowb{}-to-\gls*{t2} registration.}

\paragraph*{Error measurement}\label{sec:regseg-experiments_evaluation}
Distortion only occurs along the \gls*{pe} axis of the image, so we computed the
  \gls*{swindex} as the area-weighted distance between the corresponding vertices of
  $\gammaset_\text{true}$ and their estimate obtained by the method under the test $\hat{\gammaset}_\text{test}$:

  \begin{equation}
  sWI = \frac{1}{\sum_i a_i} \sum\limits_i^{N_V} a_i\,\|
  \vec{v}_i - \hat{\vec{v}}_i \|,
  \label{eq:regseg-swindex}
  \end{equation}
  where $\vec{v}_i \subset \gammaset_\text{true}$ are the locations of the total $N_V$ vertices,
  $a_i$ is the area corresponding to each vertex $\vec{v}_i$,
  and $\hat{\vec{v}}_i \subset \hat{\gammaset}_\text{test}$ are the recovered locations
  that correspond to $\vec{v}_i$.
In practice, we only report the \gls*{swindex} for three surfaces (\{$\Gamma_\text{VdGM}, \Gamma_\text{WM}, \Gamma_\text{pial}$\})
  of crucial interest in whole-brain tractography.
\revcomment[R\#3-C7\\R\#3-C8]{%
The \gls*{swindex} is always computed on the \gls*{dmri} space.}


\chapter{}

跳过了1, 2题. 9不会.

\begin{ex}[Delta method]
    Let \(\left\{T_{n}\right\}\) be a sequence of random variables such that
    \[
        \sqrt{n}\left(T_{n}-\theta\right) \stackrel{d}{\rightarrow} \mathcal{N}\left(0, \tau^{2}\right), \quad n \rightarrow \infty.
    \]
    Let \(h\) be a twice differentiable function such that \(h^{\prime}(\theta)=0\) and \(h^{\prime \prime}(\theta) \neq 0\). Show that
    \[
        n\left(h\left(T_{n}\right)-h(\theta)\right) \stackrel{d}{\rightarrow} \frac{1}{2} \tau^{2} h^{\prime \prime}(\theta) \chi_{1}^{2}, \quad n \rightarrow \infty.
    \]
\end{ex}

\begin{solution}
    Expand $T_n$ at $\theta$,
    \[
            h(T_n)=h(\theta)+h'(\theta)(T_n-\theta)+\frac{1}{2}h''(\theta)(T_n-\theta)^2+R.
    \]
    \[
        \begin{aligned}
            n(h(T_n)-h(\theta))&=\frac{1}{2}h''(\theta)\tau^2\left(\sqrt{n}\left(\frac{T_{n}-\theta}{\tau}\right)\right)^2\stackrel{d}{\rightarrow}\frac{1}{2}h''(\theta)\tau^2\chi^2(1).
        \end{aligned}
    \]
\end{solution}

\begin{ex}
    Let \(X_{1}, \ldots, X_{n}\) be i.i.d. with \(\mathbb{E} X_{1}=\mu\) and \(Var\left(X_{1}\right)=\sigma^{2}\). Consider a sequence of constants \(c_{n}\) such that
    \[
        c_{n}=1+\frac{a}{n}+O\left(\frac{1}{n^{2}}\right) .
    \]
    \begin{enumerate}[(a)]
        \item Suppose that a function \(h\) is differentiable with \(h^{\prime}(\mu) \neq 0\). Prove that
        \[
            \sqrt{n}\left(h\left(c_{n} \bar{X}\right)-h(\mu)\right) \stackrel{d}{\rightarrow} \mathcal{N}\left(0, \sigma^{2}\left(h^{\prime}(\mu)\right)^{2}\right), \quad n \rightarrow \infty.
        \]
        \item Suppose that the function \(h\) is twice differentiable, that \(h^{\prime}(\mu)=0\), but \(h^{\prime \prime}(\mu) \neq 0\). Prove that
        \[
            n\left(h\left(c_{n} \bar{X}\right)-h(\mu)\right) \stackrel{d}{\rightarrow} \frac{1}{2} \sigma^{2} h^{\prime \prime}(\mu) \chi_{1}^{2}, \quad n \rightarrow \infty.
        \]
    \end{enumerate}
\end{ex}

\begin{solution}
    Let $g(\bar{X})=h(c_n\bar{X})$,
    \begin{enumerate}[(a)]
        \item $\bar{X}-\mu\stackrel{d}{\rightarrow} \mathcal{N}(0, \sigma^2/n)$,
        \[
            h(c_n\bar{X})=h(c_n\mu)+c_nh'(c_n\mu)(c_n\bar{X}-c_n\mu)+R.
        \]
        Let $n\to\infty$,
        \[
            \begin{aligned}
                \sqrt{n}(h(c_n\bar{X})-h(\mu))&=\sqrt{n}(h(c_n\mu)-h(\mu))+\sqrt{n}h'(\mu)(\bar{X}-\mu)c_n^2\\
                & =\sqrt{n}h'(\mu)\sigma/\sqrt{n}\frac{\bar{X}-\mu}{\sigma/\sqrt{n}}+O(1/n)\frac{\bar{X}-\mu}{\sigma/\sqrt{n}}\\
                &\stackrel{d}{\rightarrow} \mathcal{N}(0,\sigma^2(h'(\mu))^2+O(1/n^2))\to \mathcal{N}(0,\sigma^2(h'(\mu))^2).
            \end{aligned}
        \]
        \item Same as the Delta method.
    \end{enumerate}
\end{solution}

\begin{ex}
    Let \(X_{1}, \ldots, X_{n} \stackrel{\text { i.i.d. }}{\sim} B(1, p)\), and let \(T_{n}:=\frac{1}{n} \sum_{i=1}^{n} X_{i}\).
    \begin{enumerate}[(a)]
        \item Conclude that
        \[
            \sqrt{n}\left(T_{n}-p\right) \stackrel{d}{\rightarrow} \mathcal{N}(0, p(1-p)), \quad n \rightarrow \infty.
        \]
        \item We now look at the large sample behavior of \(\widehat{\sigma}^{2}:=T_{n}\left(1-T_{n}\right)\).
        \begin{enumerate}[(i)]
            \item Assume \(p \neq 1 / 2\). Prove that
            \[
                \sqrt{n}\left(\widehat{\sigma}^{2}-p(1-p)\right) \stackrel{d}{\rightarrow} \mathcal{N}\left(0,(1-2 p)^{2} p(1-p)\right).
            \]
            \item Assume \(p=1 / 2\). Prove that
            \begin{equation}
                \label{eq:6.3.b.2}
                n\left(\widehat{\sigma}^{2}-\frac{1}{4}\right) \stackrel{d}{\rightarrow}-\frac{1}{4} \chi_{1}^{2}.
            \end{equation}
            \item Justify the negative sign in the limiting distribution in (\ref{eq:6.3.b.2}) by proving that
            \[
                \widehat{\sigma}^{2} \leq \frac{1}{4} \quad \text { a.s. }
            \]
        \end{enumerate}
    \end{enumerate}
\end{ex}

\begin{solution}
    \begin{enumerate}[(a)]
        \item $T_n=\bar{X}\sim\mathcal{N}(p, pq/n)$. So,
        \[
            \sqrt{n}(T_n-p) \stackrel{d}{\rightarrow} \mathcal{N}(0, p(1-p)).
        \]
        \item $\sigma^2=h(\bar{X})=\bar{X}(1-\bar{X})$. Expand $h(\bar{X})$ at $p$,
        \[
            h(\bar{X})=h(p)+h'(p)(\bar{X}-p)+\frac{1}{2}h''(p)(\bar{X}-p)^2+R.
        \]
        \[
            h(\bar{X})=p(1-p)+(1-2p)(\bar{X}-p)-(\bar{X}-p)^2+R.
        \]
        \begin{enumerate}[(i)]
            \item \[
                \sqrt{n}\left(\widehat{\sigma}^{2}-p(1-p)\right)=\sqrt{n}(1-2p)(\bar{X}-p)\stackrel{d}{\to} \mathcal{N}(0,(1-2 p)^{2} p(1-p)).
            \]
            \item $p=1/2$, $h'(p)=0$.
            \[
                n(h(\bar{X})-1/4) =-n(\bar{X}-p)^2=-\sigma^2\left(\sqrt{n}\frac{\bar{X}-p}{\sigma}\right)^2\stackrel{d}{\to} -\frac{1}{4} \chi_{1}^{2}.
            \]
            \item When $T_n=1-T_n$, $T_n(1-Tn)$ is maximum, i.e. $T_n=1/2$, $\widehat{\sigma}^2=1/4$.
        \end{enumerate}
    \end{enumerate}
\end{solution}

\begin{ex}
    Please answer the following questions.
    \begin{enumerate}[(a)]
        \item Let \(\left\{X_{n}\right\}_{n \in \mathbb{N}}, X\) be Gaussian random variables. Assuming that \(X_{n} \stackrel{d}{\rightarrow} X\), show that
        \[
            \mathbb{E} X_{n} \rightarrow \mathbb{E} X, \quad Var X_{n} \rightarrow Var X, \quad n \rightarrow \infty
        \]
        (hint: use the Helly-Bray theorem).
        \item Recall that a characteristic function \(\phi\) is analytic when there exists a sequence \(\left\{a_{k}\right\}_{k \in \mathbb{N} \cup\{0\}}\) and a constant \(\delta_{0}>0\) such that \(\phi(t)=\sum_{k=0}^{\infty} a_{k} t^{k}\) for \(|t|<\delta\). So, let \(\left\{X_{n}\right\}_{n \in \mathbb{N}}, X\) be random variables such that \(X_{n} \stackrel{d}{\rightarrow} X\) as \(n \rightarrow \infty\). In addition, assume their respective characteristic functions \(\left\{\phi_{n}\right\}_{n \in \mathbb{N}}, \phi\) are analytic. Prove that, for all \(k \in \mathbb{N}, \lim _{n \rightarrow \infty} \mathbb{E} X_{n}^{k}=\mathbb{E} X^{k}\) (n.b.: this exercise generalizes (a)).
    \end{enumerate}
\end{ex}

\begin{solution}
    \begin{enumerate}[(a)]
        \item \begin{align*}
            EX_n =\int x f_n(x) \der x\to \int xf(x)\der x =EX.
        \end{align*}
        \[
            VarX_n=\int (x-\mu)^2 f_n(x) \der x\to \int (x-\mu)^2f(x)\der x =VarX.
        \]
        \item $X_n\stackrel{d}{\to}X$, then
        \[
            M_{X_n}(t)\stackrel{d}{\to}M_X(t),
        \]
        \[EX_n^k=M_{X_n}^{(k)}(0)\stackrel{d}{\to}M_X{(k)}(0)=EX^k. \]
    \end{enumerate}
\end{solution}

\begin{ex}
    Let \(\delta_{n}(\mathbf{X})\) be an estimator of \(g(\theta)\) with \(\operatorname{MSE} R\left(g(\theta), \delta_{n}(\mathbf{X})\right)=\mathbb{E}\left(\delta_{n}(\mathbf{X})-g(\theta)\right)^{2}\).
    \begin{enumerate}[(a)]
        \item If
        \[
            \mathbb{E}_{\theta}\left(\delta_{n}(\mathbf{X})-g(\theta)\right)^{2} \rightarrow 0, \quad \theta \in \Theta
        \]
        as \(n \rightarrow \infty\), prove that \(\delta_{n}(\mathbf{X})\) is consistent for estimating \(g(\theta)\).
        \item Conclude that, if
        \[
            Bias_{\theta}\left(\delta_{n}(\mathbf{X})\right) \rightarrow 0, \quad Var_{\theta}\left(\delta_{n}(\mathbf{X})\right) \rightarrow 0, \quad \theta \in \Theta
        \]
        as \(n \rightarrow \infty\), then \(\delta_{n}(\mathbf{X})\) is consistent for estimating \(g(\theta)\).
    \end{enumerate}
\end{ex}

\begin{solution}
    \begin{enumerate}[(a)]
        \item \[
            (E(\delta_n(X)-g(\theta)))^2\leqslant E(\delta_{n}(\mathbf{X})-g(\theta))^2\to 0.
        \]
        So, $E(\delta_n(X)-g(\theta))\to0$.
        \item \begin{align*}
            E(\delta_n(X)-g(\theta))^2&=E(\delta_{n}(X)-E(\delta_n(X))+E(\delta_n(X))-g(\theta))^2\\
            &=E(\delta_{n}(X)-E(\delta_n(X)))^2+(E(\delta_n(X))-g(\theta))^2\\
            &=Var(\delta_n(X))+(Bias(\delta_n(x))^2\to 0.
        \end{align*}
        Hence, $E(\delta_n(X)-g(\theta))^2\to 0$, $E(\delta_n(X)-g(\theta))\to0$.
    \end{enumerate}

\end{solution}

\begin{ex}
    In maximum likelihood estimation, we often observe that
    \[
        Bias_{\theta}\left(\widehat{\theta}_{n}(\mathbf{X})\right)=\frac{\beta(\theta)}{n}+O\left(\frac{1}{n^{2}}\right) \quad\left(``b i a s \text { of order } \frac{1}{n} "\right)
    \]
    where \(\beta(\theta)\) is some known and measurable function of \(\theta\). So, suppose \(\beta\) is twice differentiable with bounded second derivative and that \(Var_{\theta}\left(\sqrt{n}\left(\widehat{\theta}_{n}(\mathbf{X})-\theta\right)\right) \leq C, n \in \mathbb{N}\), which are mild conditions in practice. Show that the (bias-corrected) estimator
    \[
        \widehat{\widehat{\theta}}_{n}(\mathbf{X}):=\widehat{\theta}_{n}(\mathbf{X})-\frac{\beta\left(\widehat{\theta}_{n}(\mathbf{X})\right)}{n}
    \]
    has bias of order \(1 / n^{2}\).
\end{ex}

\begin{solution}
    \begin{align*}
        Bias\left(\hat{\theta}_n(X)-\frac{\beta(\hat{\theta}_n(X))}{n}\right)&=Bias(\hat{\theta}_n(X))-\frac{Bias(\beta(\hat{\theta}_n(X)))}{n}.
    \end{align*}
    Let $D=E(\beta(\hat{\theta}_n(X)))$, expand $\beta$ at $D$,
    \[
        E(\beta(\hat{\theta}_n(X))-\beta(D)=\frac{1}{2}\beta''(D)\left(\hat{\theta}_n(X)-D\right)^2+O(1/n^{2}).
    \]
    So, $Bias(\hat{\hat{\theta}}_n(X))$ has $O(1/n^3)$, and hence is of order \(1/n^{2}\).
\end{solution}

\begin{ex}
    Let \(X_{1}, \ldots, X_{n} \stackrel{\text { i.i.d. }}{\sim} U[0, \theta]\). We know that
    \[
        \widehat{\theta}_{\mathrm{ML}}(\mathbf{X})=X_{(n)}, \quad \delta_{n}:=\widehat{\theta}_{\mathrm{UMVU}}(\mathbf{X})=\frac{n+1}{n} X_{(n)}.
    \]
    \begin{enumerate}[(a)]
        \item Determine the limit distributions of
        \[
            n\left(\theta-X_{(n)}\right), \quad n\left(\theta-\delta_{n}(\mathbf{X})\right).
        \]
        \item Is \(X_{(n)}\) asymptotically unbiased? Is \(X_{(n)}\) unbiased in the limit?
        \item Calculate the MSEs of \(X_{(n)}\) and \(\delta_{n}(\mathbf{X})\) as estimators of \(\theta\) and show that
        \[
            \lim _{n \rightarrow \infty} \frac{\mathbb{E}_{\theta}\left(X_{(n)}-\theta\right)^{2}}{\mathbb{E}_{\theta}\left(\delta_{n}-\theta\right)^{2}}=2, \quad \theta>0.
        \]
    \end{enumerate}
\end{ex}

\begin{solution}
    \begin{enumerate}[(a)]
        \item \[
            F_{X_{(n)}}=\left(\frac{x}{\theta}\right)^n, \quad f(x_{(n)})=\frac{n}{\theta}\left(\frac{x}{\theta}\right)^{n-1}.
        \]
        Let $Y=n(\theta-X_{(n)})$, $X_{(n)}=\theta-\frac{Y}{n}$. $X'_{(n)}=-1/n$. So,
        \[
            f_{Y}=\frac{n}{\theta}\left(1-\frac{Y}{n\theta}\right)^{n-1}(1/n)\to \frac{e^{-Y/\theta}}{\theta}\text{ i.e. }Y\sim Exp(\theta)
        \]
        Same, Let $Z=n(\theta-(n+1)/n X_{(n)})=n\theta-(n+1)X_{(n)}$, $X_{(n)}=\frac{n}{n+1}\theta-\frac{Z}{n+1}$. $X'_{(n)}=-\frac{1}{n+1}$.
        \[
            f_{Z}=\frac{n}{\theta}\left(\frac{n}{n+1}-\frac{Z/\theta}{n+1}\right)^{n-1}(1/(n+1))\to \frac{e^{-Z/\theta-1}}{\theta}.
        \]
        \item $X_{(n)}$ is asymptotically biased but is unbiased in the limit.
        \item We know
        \[E(X_{(n)})=\frac{n}{n+1}\theta, \quad E(X_{(n)})^2=\frac{n}{n+2}\theta^2. \]
        Then,
        \[
            E(X_{(n)}-\theta)^2=\frac{n}{n+1}\theta^2-\frac{2n}{n+1}\theta^2+\theta^2.
        \]
        \[
            E(\delta_n-\theta)^2=\left(\frac{n+1}{n}\right)^2\frac{n}{n+2}\theta^2-\theta^2.
        \]
        So,
        \[
            \frac{E(X_{(n)}-\theta)^2}{E(\delta_n-\theta)^2}=\frac{2n}{n+1}\to2.
        \]
    \end{enumerate}
\end{solution}

\begin{ex}
    Let \(X_{1}, \ldots, X_{n}\) be an i.i.d. sample from a distribution with mean \(\mu \neq 0\) and variance \(\sigma^{2}\).
    \begin{enumerate}[(a)]
        \item Prove that
        \item \begin{equation}
            \label{eq:6.8.a}
            \sqrt{n}\left(\frac{1}{\bar{X}}-\frac{1}{\mu}\right) \stackrel{d}{\rightarrow} \mathcal{N}\left(0,\left(\frac{1}{\mu}\right)^{4} \sigma^{2}\right), \quad n \rightarrow \infty.
        \end{equation}
        \item Note that the limiting distribution in (\ref{eq:6.8.a}) depends on \(\mu\) and \(\sigma^{2}\), both of which are unknown (and thus, the limit above is not good enough for inference purposes). To "fix" this, prove that
        \[
            \sqrt{n} \frac{\left(\frac{1}{\bar{X}}-\frac{1}{\mu}\right)}{\left(\frac{1}{\bar{X}}\right)^{2} S} \stackrel{d}{\rightarrow} \mathcal{N}(0,1), \quad n \rightarrow \infty.
        \]
    \end{enumerate}
\end{ex}

\begin{solution}
    \begin{enumerate}[(a)]
        \item $h(\bar{X})=1/\bar{X}$, \[
            \sqrt{n}(h(\bar{X}) - h(\mu)) \stackrel{d}{\rightarrow} \mathcal{N}(0,\sigma^2(h'(\mu))^2)=\mathcal{N}\left(0,\sigma^2\left(\frac{1}{\mu^4}\right)\right).
        \]
        \item $\bar{X}$ and $S^2$ are both consistent, we can use Slutsky's theorem:
        \[
            Var(h(x))=Var(h(\mu)+h'(\mu)(X-\mu))=(h'(\mu))^2Var(X).
        \]
        \[
            Var(1/\bar{X})\approx (-1/\mu^2)^2S^2.
        \]
        So, \[
            \sqrt{n} \frac{\left(\frac{1}{\bar{X}}-\frac{1}{\mu}\right)}{\left(\frac{1}{\bar{X}}\right)^{2} S} \stackrel{d}{\rightarrow} \mathcal{N}(0,1), \quad n \rightarrow \infty.
        \]
    \end{enumerate}
\end{solution}

\begin{ex}
    Let \(\left\{X_{n}\right\}_{n \in \mathbb{N}}\) be an i.i.d. sample, where \(\operatorname{Var} X_{1}=\sigma^{2}\) and \(\mathbb{E} X_{1}^{4}<\infty\). Prove that \(S^{r}\) is asymptotically unbiased for \(\sigma^{r}\) (remark: note that this is not about showing that \(\lim _{n \rightarrow \infty} \mathbb{E} S^{r}=\sigma^{r} ;\) suggestion: you may want to try \(r=2\) first).
\end{ex}

\begin{ex}
    Let \(\delta_{n}(\mathbf{X})\) be an estimator with asymptotic variance \(\tau^{2}(\theta)\). A function \(h(\cdot)\) is variance stabilizing when the estimator \(h\left(\delta_{n}(\mathbf{X})\right)\) has asymptotic variance
    \begin{equation}
        \label{eq:6.12}
        \tau^{2}(\theta)\left[h^{\prime}(\theta)\right]^{2}=c
    \end{equation}
    where \(c\) is a constant independent of \(\theta\). For each of the following cases, find the asymptotic distribution of the transformed statistic and show that it is variance stabilizing.
    \begin{enumerate}[(a)]
        \item \(\left\{X_{n}\right\}_{n \in \mathbb{N}} \stackrel{\text { i.i.d. }}{\sim} \operatorname{Poi}(\lambda), \lambda>0, h\left(\bar{X}_{n}\right)=\sqrt{\bar{X}_{n}}\).
        \item \(\left\{X_{n}\right\}_{n \in \mathbb{N}} \stackrel{\text { i.i.d. }}{\sim} B(1, p), 0<p<1, h\left(\bar{X}_{n}\right)=\arcsin \sqrt{\bar{X}_{n}}\).
    \end{enumerate}
\end{ex}

\begin{solution}
    \begin{enumerate}[(a)]
        \item \[
            \sqrt{n}(\bar{X}-\lambda)\stackrel{d}{\to} \mathcal{N}(0, \lambda),
        \]
        \[
            \tau^2(\theta)(h'(\theta))^2=\lambda\left(\frac{1}{2}\lambda^{-1/2}\right)^2=1/4.
        \]
        Hence, it is variance stabilizing.
        \item \[
            \sqrt{n}(\bar{X}-p)\stackrel{d}{\to} \mathcal{N}(0, p(1-p)),
        \]
        \[
            \tau^2(\theta)(h'(\theta))^2=p(1-p)\left(\frac{1}{\sqrt{1-p}}\right)^2\left(\frac{1}{2}p^{-1/2}\right)^2=1/4.
        \]
        It is also variance stabilizing.
    \end{enumerate}
\end{solution}

\begin{ex}
    (this problem is about the so-called Box-Cox transformations, which are widely used in Applied Statistics)

    Starting from (\ref{eq:6.12}), consider the particular case \(\tau^{2}(\theta)=\theta^{n}, n \in \mathbb{N}\), and find a variance-stabilizing transformation \(h(\cdot)\). Be careful with the important case \(n=2\) (remark: this result can be extended to more general powers than \(n \in \mathbb{N}\) ).
\end{ex}

\begin{solution}
    If $n=2$, then
    \[
        h'(\theta)\propto 1/\theta.
    \]
    So, $h(\theta)=\log \theta$.

    Otherwise,
    \[
        h'(\theta)\propto \theta^{-n/2},
    \]
    $h(\theta)=\theta^{1-n/2}$.
\end{solution}


\chapter{Background}
\label{chap:background}

In this chapter, we provide background knowledge that is commonly used across this dissertation.
Preliminaries specific to each chapter will be introduced later when they are needed.
Symbols used in this dissertation are summarized in~\cref{tbl:background-symbols}.

\begin{table}[t]
    \centering
    \caption{Summary of the symbols used in the dissertation}
    \label{tbl:background-symbols}
    \begin{tabular}{c|c}
        Symbol                      & Description                                                   \\
        \hline
        $\booldom$                  & The Boolean domain $\{\bot,\top\}$                            \\
        $x$                         & A Boolean variable                                            \\
        $l$                         & A literal (a variable or its negation)                        \\
        $\vl{l}$                    & The variable of $l$                                           \\
        $\as$                       & An assignment (a mapping from a variable set to $\booldom$)   \\
        $\as(x)$                    & The assigned value of $x$                                     \\
        $\av{V}$                    & The set of all assignments over variable set $V$              \\
        $\pf$                       & A quantifier-free formula                                     \\
        $\vf{\pf}$                  & The set of variables appearing in $\pf$                       \\
        $\as\models\pf$             & $\as$ satisfies $\pf$                                         \\
        $\pf_1\limply\pf_2$         & Every satisfying assignment of $\pf_1$ also satisfies $\pf_2$ \\
        $\sat{\pf},\unsat{\pf}$     & $\pf$ is (un)satisfiable                                      \\
        $\model{\pf}$               & A satisfying assignment of $\pf$                              \\
        $\pcf{\pf}{x},\ncf{\pf}{x}$ & Positive and negative cofactors of $\pf$ w.r.t. $x$           \\
        $\pcf{\pf}{\as}$            & The resultant formula after cofactoring $\pf$ with $\as$      \\
        $C$                         & A clause (a disjunction of literals)                          \\
        $\Qf$                       & A quantified formula                                          \\
    \end{tabular}
\end{table}

\input{background/propositional-logic.tex}
\input{background/ssat.tex}
\input{background/model-counting.tex}


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

\marginpar{Monday\\ 2021-11-29}

The Bianchi identities read \(R_{\mu \nu [\rho \sigma ; \alpha ]} = 0\); if we contract them with \(g^{\mu \lambda } g^{\nu \rho }\) we find
%
\begin{align}
\qty(R^{\mu \nu } - \frac{1}{2} g^{\mu \nu } R)_{; \nu } = 0
\,.
\end{align}

This tells us that in order for the Einstein tensor to satisfy \(G^{\mu \nu }{}_{; \nu } = 0\) we should set \(c_2 / c_1 = - 1/2\).

How do we find the absolute scaling?
In the weak field limit, we know that \(\abs{T_{ij}} \ll \abs{T_{00} }\), since we can write
%
\begin{align}
T^{\mu \nu } &= c^2 \sum _{n} \frac{p^{\mu }_{n} p^{\nu }_{n}}{E_n} \delta^3(\vec{\xi} - \vec{\xi}_n(t))  \\
&= c^2 \sum _{n} m_n \dv{x^{\mu }}{\tau } \dv{x^{\nu }}{\tau } \delta^3(\vec{\xi} - \vec{\xi}_n(t))  \\
&= \rho c^2 \dv{x^{\mu }}{\tau } \dv{x^{\nu }}{\tau }
\,,
\end{align}
%
where \(\rho = \sum _{n} m_n \delta^3 (\vec{\xi} - \vec{\xi}_n (t))\) is the density.
Then we can use the fact that
%
\begin{align}
\dv{x^{i}}{\tau } =  \frac{v^{i}}{c} \dv{x^{0}}{\tau } \ll \dv{x^{0}}{\tau }
\,.
\end{align}

This means that, because of the equation we want to write, we must also have \(\abs{G_{ij}} = \abs{c_1 (R_{ij} - (1/2) g_{ij} R)} \ll \abs{G_{00} }\).

If we approximate \(g_{ij} \sim \eta_{ij}\), we must also have \(R_{ij} \sim (1/2) \eta_{ij} R\), so \(R_{ij}\) must also be approximately diagonal, with \(R_{kk} \sim (1/2) R\).

This means that
%
\begin{align}
R = g^{\mu \nu }R_{\mu \nu } = - R_{00} + \sum _{k} R_{kk } = - R_{00} + \frac{3}{2} R
\,,
\end{align}
%
so in this limit \(R \approx 2 R_{00} \).
Then, the 00 component of the weak field Einstein equation will read
%
\begin{align}
G_{00} &= c_1 \qty(R_{00} - \frac{1}{2} g_{00} R)  \\
&\approx 2 c_1 R_{00}
\,.
\end{align}

We can compute the \(R_{00} \) component explicitly:
%
\begin{align}
R_{00} = - \frac{1}{2} \nabla^2 g_{00}
\,,
\end{align}
%
where \(\nabla^2 = \eta^{ij} \partial_{i} \partial_{j}\).
This means that \(G_{00} = - c_1 \nabla^2 g_{00} \).

Together with the Newtonian limit expression we found, \(G_{00} = - \nabla^2 g_{00} \), this means that \(c_1 = 1\).

Finally, then, we can write the Einstein equation as
%
\begin{align}
G_{\mu \nu } = R_{\mu \nu } - \frac{1}{2} g_{\mu \nu } R = \frac{8 \pi G}{c^{4}} T_{\mu \nu }
\,.
\end{align}

It can also be written as
%
\begin{align}
R_{\mu \nu } = \frac{8 \pi G}{c^{4}} \qty(T_{\mu \nu } - \frac{1}{2} g_{\mu \nu } T)
\,,
\end{align}
%
since if we contract the Einstein equation with a \(g^{\mu \nu }\) we get \(-R = (8 \pi G / c^{4}) T\).

In a vacuum, \(T_{\mu \nu } = 0\), therefore \(R_{\mu \nu } = 0\), but in general \(R_{\mu \nu \rho \sigma } \neq 0\).

One could also add a term like
%
\begin{align}
R_{\mu \nu } - \frac{1}{2} g_{\mu \nu } R - \Lambda g_{\mu \nu } = \frac{8 \pi G}{c^{4}} T_{\mu \nu }
\,.
\end{align}

This cosmological constant term satisfies all the conditions, except for the Newtonian limit.
In order for this to be true, we need \(\Lambda \lesssim \SI{1.11e-52}{m^{-2}}\).
This is a new characteristic length scale!

\paragraph{Degrees of freedom}

There are 10 independent Einstein equations for the 10 degrees of freedom in \(g_{\mu \nu }\).

However, we know that \(T^{\mu \nu }{}_{;\nu } = 0\) implies \(G^{\mu \nu }{}_{; \nu } = 0\): this means that only 6 of the components of the Einstein tensor are independent.

It looks like the system is underdetermined, but
in fact the equations are uniquely determined
\emph{up to a gauge transformation}.

So, in fact, there are 6 equations.
If \(g_{\mu \nu }\) solves the Einstein Equations, and we transform it with a coordinate transformation to \(g_{\mu \nu }'\), we will still find something which satisfies these equations.

This is similar to the EM case: the potential \(A_{\mu }\) satisfies the equation
%
\begin{align}
\square A_{\mu } - \pdv{A_{\alpha }}{x^{\mu }}{x^{\alpha }} = - \frac{4 \pi }{c} J_\mu
\,,
\end{align}
%
but this equation does not uniquely determine \(A\), since \(J\) satisfies \(J^{\mu }{}_{, \mu } = 0\).
This is solved by the gauge invariance of the electromagnetic field, which is unchanged if we map \(A_{\mu } \to A_{\mu } - \partial_{\mu } \phi \).
(similarly, Maxwell's equation is unchanged in that case).

A common choice in EM theory is the Lorenz gauge, \(A^{\mu }_{; \mu }= 0\).

In gravitational theory, on the other hand, a gauge which  is often chosen is the \emph{harmonic gauge}: \(\Gamma^{\lambda } = g^{\alpha \beta } \Gamma^{\lambda }_{\alpha \beta } = 0\). More explicitly, this reads
%
\begin{align}
\pdv{}{x^{\mu }} \qty(\sqrt{-g} g^{\mu \lambda }) = 0
\,.
\end{align}

In curved coordinates, the Dalambertian reads
%
\begin{align}
\square \phi = g^{\alpha \beta } \nabla_\alpha \nabla_\beta \phi = g^{\alpha \beta } \partial_{\alpha } \partial_{\beta } \phi - \Gamma^{\alpha } \partial_{\alpha } \phi
\,.
\end{align}

In the harmonic gauge, this simplifies to \(g^{\alpha \beta } \nabla_\alpha \nabla_\beta \phi  = g^{\alpha \beta } \partial_{\alpha } \partial_{\beta } \phi \).

\section{Gravitational waves}

They are a prediction made by any relativistic theory of gravity: something needs to propagate in order to mediate the interaction.

The connection of the ``gravitational potential'' to the metric means that these are \emph{metric waves}, the proper distance between points itself changes when a GW passes by.

We assume that the metric is written like \(g_{\mu \nu } = g_{\mu \nu }^{(0)} + h_{\mu \nu }\).
To first order, the inverse metric will read \(g^{\mu \nu }= g^{\mu \nu (0)} - h^{\mu \nu }\), where \(h^{\mu \nu }\) is computed raising the indices with \(g^{\mu \nu (0)}\).

The first order contribution to the Christoffel symbols reads
%
\begin{align}
\Gamma^{\lambda }_{\mu \nu } &= \frac{1}{2} \qty[g^{\lambda \rho (0)} - g^{\lambda \rho }] \qty(2 g^{0}_{\rho (\mu , \nu )} + 2 h_{\rho (\mu , \nu )}- g^{(0)}_{\mu \nu , \rho } - h_{\mu \nu , \rho })
\\
&= \underbrace{\frac{1}{2} g^{\lambda \rho (0)} \qty(2g^{(0)}_{\rho (\mu , \nu )} - g^{(0)}_{\mu \nu , \rho })}_{\order{h^{0}}} +
\underbrace{\frac{1}{2} g^{\lambda \rho (0)} \qty(2h_{\rho (\mu , \nu )} - h_{\mu \nu , \rho }) +
\frac{1}{2} h^{\lambda \rho } \qty(2g^{(0)}_{\rho (\mu , \nu )} - g^{(0)}_{\mu \nu , \rho })}_{\order{h}} + \order{h^2}
\,.
\end{align}

The general expression for the Ricci tensor reads
%
\begin{align}
R_{\mu \nu } = \Gamma^{\alpha }_{\mu \nu , \alpha } - \Gamma^{\alpha }_{\mu \alpha , \nu } + \Gamma^{\alpha }_{\sigma \alpha } \Gamma^{\sigma }_{\mu \nu } - \Gamma^{\alpha }_{\sigma \nu } \Gamma^{\sigma }_{\mu \alpha}
\,.
\end{align}

In the \(\Gamma \Gamma \) terms we will have expressions like \((\Gamma^{(0)} + \Gamma^{(1)}) (\Gamma^{(0)} + \Gamma^{(1)})\), so we can also isolate 0th-order, 1st-order and 2nd-order terms;
similarly in the \(\partial \Gamma \) term we will have 0th and 1st-order terms.

The zeroth and first order EFE will read
%
\begin{align}
R^{(0)}_{\mu \nu } &= \kappa  \qty(T_{\mu \nu }^{(0)} - \frac{1}{2} g_{\mu \nu }^{(0)} T^{(0)}) \\
R^{(1)}_{\mu \nu } &= \kappa  \qty(T_{\mu \nu }^{(1)} - \frac{1}{2} g_{\mu \nu }^{(0)} T^{(1)} - \frac{1}{2} h^{\mu \nu } T^{(0)})
\,,
\end{align}
%
where \(\kappa = 8 \pi G / c^{4}\).

We now take Minkowski: \(\eta_{\mu \nu } = g_{\mu \nu }^{(0)}\).
With this, and substituting in \(h\) to the Ricci tensor, we get
%
\begin{align}
R_{\mu \nu } = \frac{1}{2} \qty[ - \square h_{\mu \nu } + \pdv{h^{\lambda }_{\mu }}{x^{\lambda }}{x^{\mu }} + \pdv{h^{\lambda }_{\nu }}{x^{\lambda }}{x^{\nu }} - \pdv{x^{\lambda }_{\lambda }}{x^{\mu }}{x^{\nu }}]
\,,
\end{align}
%
where \(\square = \eta^{\alpha \beta } \partial_{\alpha }\partial_{\beta }\).

With these, the equations already look quite similar to a wave equation.
We'd like to make a gauge transformation in order to cancel the second derivatives, but we must be careful to preserve the perturbative character of the metric --- we can do so by mapping \(x^{\mu } \to x^{\mu } + \epsilon^\mu \), where \(\epsilon_{\mu , \nu } = \order{h_{\mu \nu }}\).

The transformed metric perturbation will read
%
\begin{align}
h'_{\alpha \beta } = h_{\alpha \beta } - 2 \epsilon_{(\alpha , \beta )}
\,.
\end{align}

We then try to impose the harmonic gauge: \(0 = g^{\alpha \beta } \Gamma^{\lambda }_{\alpha \beta }\). This yields
%
\begin{align}
0 = h^{\mu }{}_{\kappa, \mu } - \frac{1}{2} h_{, \kappa }
\,.
\end{align}

This precisely means that the second derivatives in the Ricci tensor vanish.

So, we get \(R_{\mu \nu } = -(1/2) \square h_{\mu \nu }\), and the Einstein equations become
%
\begin{align}
\square h_{\mu \nu } = - \frac{16 \pi G}{c^{4}} \qty(T_{\mu \nu } - \frac{1}{2} \eta_{\mu \nu } T)
\,.
\end{align}

If we introduce \(\overline{h}_{\mu \nu } = h_{\mu \nu } - \eta_{\mu \nu } h / 2\), the \emph{trace-reversed perturbation}, we find
%
\begin{align}
\square \overline{h}_{\mu \nu } = - \frac{16 \pi G}{c^{4}} T_{\mu \nu}
\,,
\end{align}
%
to be computed under \(\overline{h}^{\mu }{}_{\nu , \mu } = 0\).

In a vacuum, we just have \(\square h_{\mu \nu } = 0\).
The solution to this equation will be given in terms of
retarded quantities
%
\begin{align}
\overline{h}_{\mu \nu } (t, \vec{x}) = \frac{4 G}{c^{4}}
\int_{V} \frac{T_{\mu \nu } (t - \abs{\vec{x} - \vec{x}'} / c, \vec{x}')}{\abs{\vec{x} - \vec{x}'}} \dd[3]{x'}
\,.
\end{align}

We have yet to show that choosing the harmonic gauge is indeed always possible with an infinitesimal coordinate transformation.
If we make the coordinate transformation for the Christoffel system, we get
%
\begin{align} \label{eq:christoffel-gauge-transformation}
\Gamma^{\lambda '} = \eta^{\lambda k } \qty[h^{\mu }{}_{\kappa, \mu } - \frac{1}{2} h_{, \kappa }] + \square \epsilon^{\lambda }
\,.
\end{align}

Since solving the Dalambertian equation is always possible,
we can always set this to zero.

A monochromatic plane wave in a vacuum reads
%
\begin{align}
\overline{h}_{\mu \nu } = \Re A_{\mu \nu } e^{i k_{\sigma } x^{\sigma }}
\,.
\end{align}

The Einstein equation means that \(k^2\) must vanish.
The gauge condition tells us that \(k^{\mu }A_{\mu \nu } = 0\).

\end{document}


\documentclass[12pt, letterpaper]{report}
\usepackage[margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{float}
\usepackage{subfig}
\graphicspath{ {./img/} }
\setlength\parindent{0pt}
\renewcommand{\thesection}{\Roman{section}.}
\renewcommand{\thesubsection}{\alph{subsection}.}

\title{CS1675 - Assignment 8}
\author{Zachary M. Mattis}

\begin{document}

\maketitle

\section{Problem 1 - Bayesian Belief Networks}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.4\columnwidth]{bbn.png}
	\caption{BBN}
\end{figure}

% A
\subsection{Blind Solution}

(1) \qquad P(B=T, E=T)

\begin{equation*}
\begin{split}
P(B=T, E=T) &= \sum_{a\in T,F}\sum_{c\in T,F}\sum_{d\in T,F,X}\sum_{f\in T,F} P(A=a,B=T,C=c,D=d,E=T,F=f)\\
&= \sum_{a\in T,F}\sum_{c\in T,F}\sum_{d\in T,F,X}\sum_{f\in T,F}P(F=f|D=d)P(D=d|A=a,B=T,C=c) * \\&\qquad\qquad\qquad\qquad P(E=T|C=c)P(A=a)P(B=T)P(C=c)
\end{split}
\end{equation*}

Computational Cost:

\begin{table}[H]
	\begin{tabular}{ |l|l|r| }
		\hline
		\textbf{Num. Additions} & $(3)(2^3)-1$ & 23 \\
		\hline
		\textbf{Num. Products} & $ [(3)(2^3)][(6-1)]$ & 120 \\
		\hline
	\end{tabular}
	%\caption{Blind Computation Cost}
\end{table}

(2) \qquad Full Joint Distribution

\begin{equation*}
\begin{split}
P &= \sum_{a\in T,F}\sum_{b\in T,F}\sum_{c\in T,F}\sum_{d\in T,F,X}\sum_{e\in T,F}\sum_{f\in T,F} P(A=a,B=b,C=c,D=d,E=e,F=f)\\
&= \sum_{a\in T,F}\sum_{b\in T,F}\sum_{c\in T,F}\sum_{d\in T,F,X}\sum_{e\in T,F}\sum_{f\in T,F} P(F=f|D=d)P(D=d|A=a,B=b,C=c) * \\&\qquad\qquad\qquad\qquad P(E=e|C=c)P(A=a)P(B=b)P(C=c)
\end{split}
\end{equation*}

Computational Cost:

\begin{table}[H]
	\begin{tabular}{ |l|l|r| }
		\hline
		\textbf{Num. Additions} & $(3)(2^5)-1$ & 95 \\
		\hline
		\textbf{Num. Products} & $ [(3)(2^5)][(6-1)]$ & 480 \\
		\hline
	\end{tabular}
	%\caption{Full Joint Computation Cost}
\end{table}

% B
\subsection{Efficient Solution}

(1) \qquad P(B=T, E=T)

\begin{equation*}
\begin{multlined}
P(B=T,E=T) = P(B=T)\sum_{a\in T,F}P(A=a)\sum_{c\in T,F}P(E=T|C=c)P(C=c)* \\
\sum_{d\in T,F,X}P(D=d|A=a,B=T,C=c)\sum_{f\in T,F}P(F=f|D=d)
\end{multlined}
\end{equation*}

Computational Cost:

\begin{table}[H]
	\begin{tabular}{ |l|r| }
		\hline
		\textbf{Num. Additions} & 9\\
		\hline
		\textbf{Num. Products} & 16	\\
		\hline
	\end{tabular}
	%\caption{Full Joint Computation Cost}
\end{table}

Given the reduction in computation complexity and cost for the efficient solution, this approach is much more desirable than the blind solution.

\section{Problem 2 - Pneumonia Diagnosis}

% A
\subsection{ML Estimation}

\begin{table}[H]
	\centering
	\begin{tabular}{ |r|r|r| }
		\hline
		& \textbf{T} & \textbf{F} \\
		\hline
		\textbf{Fever} & 0.9 & 0.1 \\
		\hline
		\textbf{Paleness} & 0.7 & 0.3 \\
		\hline
		\textbf{Cough} & 0.9 & 0.1 \\
		\hline
		\textbf{HighWBCcount} & 0.8 & 0.2 \\
		\hline
	\end{tabular}
	\caption{$P(Parameters \mid Pneumonia = T)$}
\end{table}

\begin{table}[H]
	\centering
	\begin{tabular}{ |r|r|r| }
		\hline
		& \textbf{T} & \textbf{F} \\
		\hline
		\textbf{Fever} & 0.6 & 0.4 \\
		\hline
		\textbf{Paleness} & 0.5 & 0.5 \\
		\hline
		\textbf{Cough} & 0.1 & 0.9 \\
		\hline
		\textbf{HighWBCcount} & 0.5 & 0.5 \\
		\hline
	\end{tabular}
	\caption{$P(Parameters \mid Pneumonia = F)$}
\end{table}

% B
\subsection{Fever, !Paleness, Cough, !HighWBCcount}

$P(Pneumonia = T | Fever = T,Paleness = F,Cough = T,HighWBCcount = F) = 0.2351$

% C
\subsection{Fever, ?Paleness, Cough, ?HighWBCcount}

$P(Pneumonia = T | Fever = T,Cough = T) = 0.0539$

% D
\subsection{Current Symptoms}

\begin{verbatim}
main7_2inference.m
\end{verbatim}

\end{document}


\documentclass{article}
\pdfinfo{
  /Title (TITLE)
  /Author (Xuanyi Chew)
}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{booktabs} % for \specialrule
\usepackage{bussproofs}
\usepackage{hyperref}
\usepackage{tikz}
\usepackage{tikz-cd}
\usetikzlibrary{shapes.geometric, arrows}
\hypersetup{
  colorlinks=true,
  linkcolor=magenta,
}
\urlstyle{same}
\newenvironment{example}{
  \textbf{Example.}
  \quad
}

\begin{document}
\title{A System of Shapes Makes For Simpler Array Programming}
\author{Xuanyi Chew \\
  \mbox{}
  chewxy@gmail.com
}
\maketitle

\begin{abstract}
  ABSTRACT HERE
\end{abstract}

That a system of shapes simplifies array programming.

\section{Introduction}

\href{https://gorgonia.org}{Gorgonia} is a family of libraries which brings the ability to create and manipulate deep neural networks to the Go programming language. This paper concerns two libraries in the family: \texttt{gorgonia.org/gorgonia} and \texttt{gorgonia.org/tensor}. The former is a library to define abstract mathematical expressions while the latter provides multidimensional array programming capabilities.

Recently both libaries were augmented with an algebra of shapes, which provides constraints to the array programming operations, leading to a more correct implementation of neural networks. This paper describes said algebra.

\section{Multidimensional Arrays, Their Shapes and Their Fundamental Operations}

Multidimensional arrays may be described by their shape.

\begin{example}
  For example, a matrix $\mathbf{A}$ can be described by the number of rows $r$ and the number of columns $c$. A shorthand notation would be $(r, c)$.
\end{example}

In the example above, $(r, c)$ is the \textbf{shape} of the matrix $\mathbf{A}$. We say the shape of $\mathbf{A}$ has two \textbf{dimensions}, or that it is \textbf{rank}-2. When addressing $r$ in the shape, we'll also call it \textbf{axis} 0, while $c$ is considered \textbf{axis} 1.

\begin{table}[ht]
  \centering
  \begin{tabular}{|p{0.3\linewidth}|c|c|}
    \hline
    \textbf{Name of Operation} & \textbf{Multidimensional Array} & \textbf{Unidimensional Array} \\
    \hline
     Size Descriptor & Shape & Length \\
    \hline
    How many elements to skip to the next index & Strides & 1 \\
    \hline
    Rank/Dimensions & D & 1 \\
    \hline
     Indexing & Takes a coordinate of size D & Index with one number \\
    \hline
    Slicing & Takes D ranges & Takes one range\\
    \specialrule{2.5pt}{1pt}{1pt}
    Transposition & Applies a permutation of D axes &  Only one permutation possible\\
    \hline
    Concatenation & Concatenation along a given axis & \texttt{append} at the end of the array\\
    \hline

  \end{tabular}
\caption{Analogies of operations}
\label{analogies}
\end{table}

The usual, single dimensional array is a special case of a multidimensional array. By way of analogy, one may interrogate the fundamental operations of multidimensional arrays. Table \ref{analogies} enumerates the analogies of fundamental operations between multidimensional arrays and unidimensional arrays. Operations after the thick line indicates utility functions that are best treated as fundamental operations.

\subsection{Size Descriptor}
The length of a unidimensional array denotes the size of the array. For multidimensional arrays, the length needs to be specified for each dimension. This is called a \textbf{shape}. The \texttt{.Shape()} method returns the shape of a multidimensional array. Built in slices are interpreted as unidimensional arrays, with the length acting as its shape. All other values, with the exception of maps are assumed to be scalar shaped.
\subsection{Ranks/Dimensions of}
A unidimensional array has only one dimension, hence the array is of rank-1, or it has 1 dimension. $D$ is a function that takes an array, unidimensional or multidimensional, and returns the number of dimensions. In code, it is written as a method, \texttt{.Dims()}.
\subsection{Indexing}

Indexing allows for access to a particular element of an array. In code, it is written \texttt{A[idx]} or \texttt{A.Index(idx)}, where \texttt{A} is the multidimensional array, and \texttt{idx} is a list of numbers denoting the indices. It is important to note that indexing is different from slicing. Indexing returns an element in the array, while slicing returns another array.

In a unidimensional array, indexing simply takes a single integer. Thus \texttt{A[1]} returns the first element of the array \texttt{A}. In a multidimensional array, the indices that are required are exactly the dimensions of the multidimensional array.

We can generalize the notion of indexing with the following function signature:

$$
Index : Array \ a \rightarrow [int] \rightarrow a\\
$$

The function signature - though inadequate to describe the operation in full -  nonetheless tells us that it is a function that takes a multidimensional array with elements of type $a$, a list of integers, and returns a single element of type $a$.

As an example, consider the following matrix of integers:

\begin{equation*}
  \mathbf{A} :=
\begin{bmatrix}
  1 & 2 & 3\\
  4 & 5 & 6
\end{bmatrix}
\end{equation*}

Assuming a 0-based indexing system, let's say we want the 1st element of the 1st row. The function call to perform indexing is as follows: \texttt{A.Index(1,1)}. This will result in \texttt{5}, which is the (1,1)-th element of the matrix $\mathbf{A}$. By analogy, the (0,1)-th element of $\mathbf{A}$ is \texttt{2}.

The shape signature of the indexing operation is as follows:

$$
Index: a \rightarrow idx \rightarrow () ,\ s.t.\ (D\ idx\ = D\ a\ \wedge \forall\ (idx < a))
$$

Read this as: $Index$ is a function that takes a shape (denoted by the variable $a$), and a list of indices (denoted by the variable $idx$), and returns $()$. This function is subject to the constraints that the dimensions of $a$ and dimensions of $idx$ are the same and that all values of $idx$ is smaller than the values of $a$.

\subsection{Slicing}

$$
Slice : Array\ a \rightarrow [range] \rightarrow Array\ a\\
$$

\subsection{Transposition}

Unidimensional arrays do not support the transposition operation. Thus there are no analogues for transposition. This is the first novel operation that can only occur in higher dimensions. This subsection briefly analyzes the operation.

We begin with a two dimensional array, commonly known as a matrix. Let us use this matrix for example:
\begin{equation*}
  \mathbf{A} :=
\begin{bmatrix}
  1 & 2 & 3\\
  4 & 5 & 6
\end{bmatrix}
\end{equation*}

The transposition of the matrix $\mathbf{A}$ is defined as reflecting the values of the matrix along its central diagonal, so that

\begin{equation*}
  \mathbf{A}^T =
  \begin{bmatrix}
    1 & 4\\
    2 & 5\\
    3 & 6\\
  \end{bmatrix}
\end{equation*}

Thus, if a matrix is of shape (a, b), the transposition would yield (b, a) as a resulting shape.

When involving multidimensional arrays where there are more than 2 dimensions, transposition requires additional parameters.

\section {The Algebra of Shapes}

The Shape Algebra is described by a BNF:

\begin{align*}
  E &::=\ a\ |\ S\ |\ E \rightarrow E\ |\ (E\ s.t.\ P)\ |\ F\ |\ U\\
  S &::=\ ()\ |\ (Sz,)\ |\ (Sz,\ S)\ |\ (S,\ Sz)\ |\ A \\
  A &::=\ (a,)\ |\ (a,\ A)\ |\ (A,\ a)\ |\ (B,)\ |\ (B,\ A)\ |\ (A,\ B)\\
  B &::=\ E\ O_A\ E\ |\ \Sigma\ E\ |\ \Pi\ E\ | \\
  O_A &::=\ +\ |\ \times\ |\ -\ |\ \div \\
  F &::=\ I\ G\ E\ |\ Sl\ G\ E\ |\ D\ E\ \\
  U &::=\ T\ Axs\ E\ |\ R\ Ax\ n\ E\ |\ Cat\ Ax\ E\ E \\
  G &::= Sz\ |\ Sz:Sz\ |\ Sz:Sz:Sz\ |\ G,G\ \\
  P &::= C_L\ O_c\ C_R\\
  C_L &::= E\ |\ Axs\ |\ D\ Axs\ |\ D\ E\ |\ D\ G\ |\ \Sigma\ E\ |\ \Pi\ E\ |\ C_L\ O_c\ C_L \\
  C_R &::= C_L\ |\ Sz\ |\ Axs\ |\ n\\
  O_c &::=\ \wedge\ |\ \vee\ |\ =\ |\ \neq\ |\ <\ |\ \leq\ |\ >\ |\ \geq\\
  Axs &::=\ Ax\ |\ Axs, Axs \\
  Sz, Ax, n &::=\ \mathbb{N}
\end{align*}

\begin{table}[ht]
  \centering
  \begin{tabular}{|c|c|}
    \hline
    Mnemonic & Name \\
    \hline
    E & \textbf{E}xpression \\
    \hline
    S & \textbf{S}hape \\
    \hline
    A & \textbf{A}bstract Shape \\
    \hline
    B & \\
    \hline
    $O_A$ & \textbf{A}rithmetic \textbf{O}peration \\
    \hline
    F & \textbf{F}undamental operation \\
    \hline
    U & \textbf{U}tility operations \\
    \hline
    I & \textbf{I}ndex of \\
    \hline
    T & \textbf{T}ranspose of \\
    \hline
    Sl & \textbf{Sl}ice of \\
    \hline
    G & Slice Ran\textbf{G}e \\
    \hline
    R & \textbf{R}epeat \\
    \hline
    Cat & Con\textbf{cat}enate \\
    \hline
    Ax & \textbf{Ax}is \\
    \hline
    P & \textbf{P}redicate \\
    \hline
    C & \textbf{C}onstraints (left and right) \\
    \hline
    $O_C$ & \textbf{C}omparison \textbf{O}peration (used in Subject-to Clauses)\\
    \hline
    D & \textbf{D}imensions of \\
    \hline
    Sz & \textbf{S}i\textbf{z}e\\
    \hline

  \end{tabular}
\caption{Mnemonics used in the BNF}
\label{mnemonics}
\end{table}

\section{Unification}
\begin{prooftree}
  \AxiomC{$a \not\in E$}
  \RightLabel{\scriptsize{(1)}\label{unif:def}}
  \UnaryInfC{$a \sim E : \{a/E\}$ }
\end{prooftree}
\begin{prooftree}
  \AxiomC{}
  \RightLabel{\scriptsize{(2)}\label{unif:var}}
  \UnaryInfC{$a \sim a : \{\} $}
\end{prooftree}
\begin{prooftree}
  \AxiomC{$E_1 = E_2$}
  \RightLabel{\scriptsize{(3)}\label{unif:eq}}
  \UnaryInfC{$E_1 \sim E_2 : \{\} $}
\end{prooftree}

Unification \ref{unif:def} \ref{unif:var} \ref{unif:eq} represents ...

\section{Inference}

We expect all functions to be well annotated, so inference for expresssions are less important.

Only variables and application really matters:

\begin{prooftree}
  \AxiomC{$x: E \in \Gamma$}
  \RightLabel{\quad \scriptsize{(Var)}}
  \UnaryInfC{$\Gamma \vdash x : E$}
\end{prooftree}

\begin{prooftree}
  \AxiomC{$\Gamma \vdash f := E_1 \rightarrow E_2$}
  \AxiomC{$\Gamma \vdash x : E_1$}
  \RightLabel{\quad \scriptsize{(App)}}
  \BinaryInfC{$\Gamma \vdash f@x: E_2$}
\end{prooftree}

\section{Semantics}

\section{Constraint Solving}

\section{Parsing}
The shape languaage is designed for a fairly straightforwards parsing algorithm. The shapes package comes with a parser. The code in its entirety can be found in \texttt{parser.go}. A brief description follows.

The parser works by using two stacks (one for values and one for operators) and a queue. The folowing flowchart presents the big-picture ideas:

\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{tikzcd}
stack &                                                                        & queue \arrow[ld] &                               \\
      & .compareCur() \arrow[d] \arrow[lu] \arrow[rr, two heads, dashed] &                  & .resolveXXX() \arrow[loop, distance=2em, in=305, out=235] \\
      & infixStack                                                             &                  &
\end{tikzcd}

The main entry point to parsing is the \texttt{Parse()} function. In it, a \texttt{parser} object is created. The parsing process starts by lexing -  turning a string into a slice of tokens, which forms the queue. Then an item is dequeued off the queue and is placed onto either the \texttt{stack} or \texttt{infixStack}. The rules of when and how each token is turned into a value is described by the methods of the \texttt{parser} object.

The main workhorse is the \texttt{.compareCur()} method, which compares the operator precedence of tokens of the current value off the queue to the top of the \texttt{infixStack}. The parser also has two main groups of methods, denoted by the prefix of the methods. The \texttt{.resolveXXX} methods generally use the existing values and operators on the \texttt{stack} and \texttt{infixStack} to create new values that are then pushed into the \texttt{stack}. The \texttt{.expectXXX} methods also does lookaheads in the queue and manage the queue pointers in order to create values and use them immediately. \textt{.compareCur()} calls these \texttt{.resolveXXX} and \texttt{expectXXX} methods in order to create values to put onto the \texttt{stack}.

\end{document}


\section{Lists} % (fold)
\label{sec:lists}

% This sheet is a little long

\begin{questions}

\titledquestion{Short questions} % (fold)
\label{sub:short_questions}

\begin{parts}
    \part Write a function that prints the elements of a list
    \part Write a function that prints the elements of a list in reverse
    \part Write your own implementation of the \verb|len| function
    that returns the number of elements in a list.
\end{parts}
% titledquestion short_questions (end)

\titledquestion{Copying lists} % (fold)
\label{sub:copying_lists}

\begin{parts}
    \part Create a list \verb|a| with some entries.
    \part Now set \verb|b = a|
    \part Change \verb|b[1]|
    \part What happened to \verb|a|?
    \part Now set \verb|c = a[:]|
    \part Change \verb|c[2]|
    \part What happened to \verb|a|?
\end{parts}

Now create a function \verb|set_first_elem_to_zero(l)| that takes a list, sets its
first entry to zero, and returns the list.

What happens to the original list?

\titledquestion{Lists of lists}

What is the difference between \texttt{a} and \texttt{b}:

\verb|a = [[]] * 3|

\verb|b = [[] for _ in xrange(3)]|

% titledquestion copying_lists (end)

\titledquestion{Lists and functions} % (fold)
\label{sub:lists_and_functions}

Write a function that takes a list and an index, and sets the value of the list
at the given index to 0.

% titledquestion lists_and_functions (end)

\titledquestion{Primes} % (fold)
\label{sub:primes}

In Section~\ref{sec:functions} you wrote a function that prints all primes up to $n$, and
a function that prints the first $n$ primes.
Update these functions such that they return lists instead.

% titledquestion primes (end)

\titledquestion{List comprehensions} % (fold)
\label{sub:list_comprehensions}

Let $i, j = 1,\ldots, n$

\begin{parts}
    \part Generate a list with elements \verb|[i,j]|.
    \part Generate a list with elements \verb|[i,j]| with $i < j$
    \part Generate a list with elements \verb|i + j| with both $i$ and $j$ prime and $i > j$.
    \part Write a function that evaluates an arbitrary polynomial $a_0 + a_1 x + a_2 x^2 + \ldots + a_n x^n$
    using a list comprehension, where you are given \verb|x| and a list with coefficients \verb|coefs|
    (hint: use enumerate)
\end{parts}

% titledquestion list_comprehensions (end)

\titledquestion{Filter} % (fold)
\label{sub:filter}

In lecture we have seen how to implement \texttt{map} using list comprehensions.
Implement \texttt{filter} using list comprehensions.
Name your functions \texttt{myfilter} so you can compare with Python's standard filter.
% titledquestion filter (end)

\titledquestion{Flatten a list of lists} % (fold)
\label{sub:flatten_a_list_of_lists}

Consider having a list with lists as elements, e.g.
\texttt{[[1,3], [3,6]]}.

Write a function that takes such a list, and returns a list with as elements the
elements of the sublists, e.g. \texttt{[1, 3, 3, 6]}.

% titledquestion flatten_a_list_of_lists (end)

\titledquestion{Finding the longest word} % (fold)
\label{sub:finding_longest_word}

Write a function that returns the longest word in a variable \texttt{text}
that contains a sentence.
While \texttt{text} may contain punctuation, these should not be taken into account.
What happens with ties?

As an example, consider: ``Hello, how was the football match earlier today???''

% titledquestion finding_longest_word (end)

\titledquestion{Collatz sequence, part 2} % (fold)
\label{sub:collatz_sequence_part_2}

Recall the Collatz sequence problem from Section~\ref{sub:collatz_sequence}.
Our goal is to find the number $n < 1,000,000$ that leads to the longest Collatz sequence.

\begin{parts}
    \part Write a function that for any $n$, returns its Collatz sequence as a list
    \part Write a function that finds the integer $x$ that leads to the longest
    Collatz sequence with $x < n$.
\end{parts}

% titledquestion collatz_sequence_part_2 (end)

\titledquestion{Pivots}
\label{sub:sorting}

Write a function that takes a value \texttt{x} and a list \texttt{ys},
and returns a list that contains the value \texttt{x} and all elements of \texttt{ys}
such that all values \texttt{y} in \texttt{ys} that are smaller than \texttt{x}
come first, then we element \texttt{x} and then the rest of the values in \texttt{ys}

For example, the output of
\texttt{f(3, [6, 4, 1, 7])} should be \texttt{[1, 3, 6, 4, 7]}

% titledquestion sorting (end)

\titledquestion{Prime challenge}
\label{sub:prime_challenge}

Write the function \texttt{primes(n)} that return a list with all prime numbers
up to \texttt{n} using three (or less) lines of code.

Hint 1: Use lambda functions and list comprehensions.

Hint 2: Use the first two lines to define two helper (lambda) functions.

% factors = lambda n: [x for x in xrange(1, n+1) if n % x == 0]
% prime = lambda n: factors(n) == [1, n]
% primes = lambda n: [x for x in xrange(2, n+1) if prime(x)]

\end{questions}

% section lists (end)


\section{Quantised fields}
\label{sec:quantised}

\subsection{Fields in Schwarzschild space-time}

\subsubsection{Linear, massless scalar field}

\cite{PhysRevD.21.2185}

\begin{nameddef}{Complete exterior modes}
\begin{align}
\rfun{u_{\omega lm}^{\rightarrow}}{x} &= \rbr{4\pp\omega}^{-\frac{1}{2}}
\ee^{-\ii\omega t} \rfun{R_l^{\rightarrow}}{\omega\middle| r}
\rfun{Y_{lm}}{\theta, \phi}, \\
\rfun{u_{\omega lm}^{\leftarrow}}{x} &= \rbr{4\pp\omega}^{-\frac{1}{2}}
\ee^{-\ii\omega t} \rfun{R_l^{\leftarrow}}{\omega\middle| r}
\rfun{Y_{lm}}{\theta, \phi},
\end{align}
where the in- and outgoing radial functions
$\rfun{R_l^{\leftrightarrow}}{\omega\middle| r}$ has the asymptotic forms
\begin{align}
\rfun{R_l^{\rightarrow}}{\omega\middle| r} &\sim r^{-1} \cdot
\begin{cases}
\ee^{i\omega r_*}
+ \rfun{A_l^\rightarrow}{\omega}\ee^{-\ii\omega r_*}, & r\to \rSch^+ \\
\rfun{B_l}{\omega}\ee^{+\ii\omega r_*}, & r\to +\infty
\end{cases}
\\
\rfun{R_l^{\leftarrow}}{\omega\middle| r} &\sim r^{-1} \cdot
\begin{cases}
\rfun{B_l}{\omega}\ee^{\ii\omega r_*}, & r\to \rSch^+ \\
\ee^{-i\omega r_*}
+ \rfun{A_l^\leftarrow}{\omega}\ee^{+\ii\omega r_*} & r\to +\infty
\end{cases}
\end{align}
in which the relation of $r_*$ and $r$ is given by \cref{eq:trsf-gtosc}.
\end{nameddef}

\begin{nameddef}{The Boulware state}
$\Ket{B}$ \cite{PhysRevD.11.1404} retarded propagator is given by
\begin{equation}
\begin{split}
\rfun{E_\text{B}^+}{x, x'} = \ii\sum_{lm}\int_0^{+\infty}
&\frac{\dif\omega}{4\pp\omega}\ee^{-\ii\omega\rbr{t-t'}}
\rfun{Y_{lm}}{\theta,\phi}\rfun{{Y_{lm}}^*}{\theta ',\phi '} \\
&\cdot\rbr{\rfun{R_l^{\rightarrow}}{\omega\middle| r}
\rfun{{R_l^{\rightarrow}}^*}{\omega\middle| r'} +
\rfun{R_l^{\leftarrow}}{\omega\middle| r}
\rfun{{R_l^{\leftarrow}}^*}{\omega\middle| r'}}
\end{split}
\end{equation}
\label{nmd:boulware_state}
\end{nameddef}

\begin{nameddef}{The Unruh state}
$\Ket{U}$ \cite{PhysRevD.14.870} retarded propagator is given by
\begin{equation}
\begin{split}
\rfun{E_\text{U}^+}{x, x'} = \ii\sum_{lm}\int_{-\infty}^{+\infty}
&\frac{\dif\omega}{4\pp\omega}\ee^{-\ii\omega\rbr{t-t'}}
\rfun{Y_{lm}}{\theta,\phi}\rfun{{Y_{lm}}^*}{\theta ',\phi '} \\
&\rbr{\frac{\rfun{R_l^{\rightarrow}}{\omega\middle| r}
\rfun{{R_l^{\rightarrow}}^*}{\omega\middle| r'}}{1-\ee^{-2\pp\omega/\kappa}} +
\rfun{\theta}{\omega}\rfun{R_l^{\leftarrow}}{\omega\middle| r}
\rfun{{R_l^{\leftarrow}}^*}{\omega\middle| r'}}
\end{split}
\end{equation}
\label{nmd:unruh_state}
\end{nameddef}

\begin{nameddef}{The Hartle-Hawking-Israel state}
$\Ket{H}$ \cite{PhysRevD.13.2188, ISRAEL1976107} retarded propagator is given by
\begin{equation}
\begin{split}
\rfun{E_\text{H}^+}{x, x'} =
 \ii \sum_{lm} & \int_{-\infty}^{+\infty}\frac{\dif\omega}{4\pp\omega} \\
\cdot\biggl( & \ee^{-\ii\omega\rbr{t-t'}}
\rfun{Y_{lm}}{\theta,\phi}\rfun{{Y_{lm}}^*}{\theta ',\phi '}
\frac{\rfun{R_l^{\rightarrow}}{\omega\middle| r}
\rfun{{R_l^{\rightarrow}}^*}{\omega\middle| r'}}{1-\ee^{-2\pp\omega/\kappa}}
\\
+ & \ee^{+\ii\omega\rbr{t-t'}}
\rfun{{Y_{lm}}^*}{\theta,\phi}\rfun{Y_{lm}}{\theta ',\phi '}
\frac{\rfun{{R_l^{\leftarrow}}^*}{\omega\middle| r}
\rfun{R_l^{\leftarrow}}{\omega\middle| r'}}{\ee^{+2\pp\omega/\kappa}-1}
\biggr) \\
\end{split}
\end{equation}
\label{nmd:hhi_state}
\end{nameddef}

\begin{ppty}
The symptotic values of $\abr{\rfun{\phi^2}{x}}_\text{ren}$ \cite{PhysRevD.21.2185}

$-\frac{1}{2\pp^2\rbr{1-\rSch/r}}\int_0^{+\infty}\frac{\dif\omega\,\omega}{\ee^{2\pp\omega/\kappa}-1}$,
$\frac{1}{48\pp^2\rSch^2}-\frac{1}{8\pp^2\rSch^2}\int_0^{+\infty}\frac{\dif\omega\,\sum \rbr{2l+1}\vbr{\rfun{B_l}{\omega}}^2}{\omega\rbr{\ee^{2\pp\omega/\kappa}-1}}$,
$\frac{1}{48\pp^2\rSch^2}$;
$0$,
$\frac{1}{2\pp^2 r^2}\int_0^{+\infty}\frac{\dif\omega\,\sum \rbr{2l+1}\vbr{\rfun{B_l}{\omega}}^2}{\omega\rbr{\ee^{2\pp\omega/\kappa}-1}}$,
$\frac{1}{2\pp^2}\int_0^{+\infty}\frac{\dif\omega\,\omega}{\ee^{2\pp\omega/\kappa}-1}$.
\end{ppty}

Stress-momentum tensors
\cite{PhysRevD.15.2088,PhysRevD.21.2185}

\subsection{Fields in space-time of collapsing body}

\cite{HAWKING1974,Hawking1975}

\cite{PhysRevD.12.1519}
\begin{equation}
_+\Braket{n_{\omega}, m_{\omega'} | \Omega}_- =
\delta_{nm}\delta_{\omega\omega'}\ee^{-n\pp \omega/\kappa}{}
_+\Braket{\Omega|\Omega}_-
\end{equation}


\section{Introduction}
\label{sec::introduction}

A monad represents a mathematical design pattern which encapsulates a given value and an additional computation or effect \cite{inproceedings}. Every monadic structure respects the following three laws

\begin{equation*}
\begin{gathered}
    unit :: x \rightarrow M x \\
    value :: M x \rightarrow x \\
    bind ::  M x \rightarrow (x \rightarrow M y) \rightarrow My
\end{gathered}
\end{equation*}

which helps us create a monad $M x$ from a given value $x$, transform our monad $M x$ to another monad of type $M y$ and return the value encapsulated in our structure. \cite{inproceedings}

In functional programming, monads are used to encapsulate effects, computations which at some point in time $t$ return a value. Due to their elegant properties, monads are a good way to abstract actions which may produce side-effects such as IO operations.

In different circumstances, a new programming paradigm named aspect-oriented programming evolved around the idea of encapsulating cross-cutting concerns (computations which affect multiple modules) into aspects.

Thus, our community had split into two groups, to try to popularise each method and promote it in each other's programming paradigm.

In this paper, we do a comparative analysis over those two approaches, providing a simplified context in which we are using them to encapsulate behaviours:

\begin{itemize}

    \item We describe the generic environment within monads and advices may help us to extend our code (section \ref{sec::problem}), and we simplify our generic model
    to provide a runnable implementation of our solutions.

    \item We present a monadic data structure which solves our initial problem, and we describe a couple of advantages and disadvantages when using a monad as a way to compose behaviours (section \ref{sec::solution}).

    \item We provide an aspect, containing a pointcut and an advice which resolves our challenging situation (section \ref{sec::aop}), and we evaluate the solution in contrast to a monadic structure.

    \item We discuss related work in section \ref{sec::related::work} and provide our evaluation's  conclusions in section \ref{sec::conclusions}.

\end{itemize}

Computer Science Research Methodologies/R03 MCSI Paper/sections/introduction.tex