\chapter{Methods}
\label{sec:methods}
The Methods section first introduces one of our main contributions, several new architectures based on supervised autoencoders, which we leveraged for multi-omics integration. Afterward, we overview how we benchmarked our new architectures, including the choice of benchmark datasets, reference models, performance metric, and validation strategy. Lastly, we briefly describe aspects related to the interpretability of our models, in particular the investigation of our models' latent spaces using absolute correlations and the fitting of global surrogate models to transfer our models to clinical settings.

\section{Architectures}
\label{sec:archs}
We developed several novel neural architectures based on a combination of \glsxtrlong{sgl} regularization and supervised autoencoders. Before moving on to the architectures, we begin with some brief notes on notation. Let \(X\) denote our input matrix. Further let \(m_1, ..., m_{|M|}\) denote our input variable groups (in particular, the different clinical and biological data groups). We then denote the portion of the input matrix belonging to a particular modality \(m_i\) as \(X^{(m_i)}\). Let \(\hat X\) denote a  reconstruction of \(X\) and denote the latent space of an autoencoder taking $X$ as its input as \(\tilde X\). Let \(\hat \varphi_i (\tilde X)\) denote the estimated log-partial hazard of patient \(i\) based on latent space of an autoencoder taking $X$ as its input. Furthermore, denote the set of all linear layers in each of our architectures as $A$ and denote the linear layer regularized with \gls{sgl} in each model as $B$.\footnote{Not all of our models used \gls{sgl}, in which case $B = \{\}$.} For all of our architectures in the following, we regularized all linear layers with L2 regularization, except for the layer which was already regularized with \gls{sgl} (blue edges in each architecture diagram). By slight abuse of notation, we will use $B$ for both the linear layer, which was regularized using \gls{sgl}, as well as its weight matrix.

\subsection{Naive \glsxtrfull{sae}}
Our first idea, termed Naive \glsxtrfull{sae}, was the most simple. We took an autoencoder and added a supervised loss from its latent space to survival $\hat \varphi (\tilde X)$. In addition, we regularized the first layer using \gls{sgl} (Figure \ref{fig:arch-sae}; blue edges denote \gls{sgl}).

\begin{figure}
\centering
    \includegraphics[scale=0.75]{./content/figures/fig_arch-sae.pdf} \caption{Architecture diagram of the Naive \glsxtrfull{sae}. Grey edges denote L2 regularization, blue edges \glsxtrlong{sgl} regularization. Let $X^{(m_i)}$ denote the part of $X$ which corresponds to the i-th input variable group, and $\hat X^{(m_i)}$ a reconstruction of the same. $\tilde X$ is the latent space of the autoencoder and $\hat \varphi(\tilde X)$ is a predicted log-partial hazard based on this latent space.}\label{fig:arch-sae}
\end{figure}

Our loss function for \gls{sae} is then (Equation \ref{eq:sae-loss}):

\begin{equation}
  \begin{split}
  &L_{\text{total}}  \left(\hat \varphi, X, \hat X\right) \\ &=  L_{\text{cox}}(T, \delta, \hat \varphi)  + \xi \cdot \text{MSE}(X, \hat X) \\&+ \lambda_1 \sum_{a \in A \setminus B} ||a||_F^2 +\lambda_2 (1 - \alpha) \sum_{m \in \{m_1, ..., m_{|M|}\}} \sqrt{|m| } ||B^{(m)}||_F  \\&+  \lambda_2  \alpha || B||_{1,1}
  \end{split}
  \label{eq:sae-loss}
\end{equation}

Where $\lambda_1$ is a regularization hyper-parameter controlling the amount of L2 regularization on all linear layers (except the one regularized with \gls{sgl}), $\lambda_2$ is a regularization hyper-parameter controlling the amount of \gls{sgl} regularization, $\xi$ is a regularization hyper-parameter controlling the weight of the reconstruction loss, and $\alpha$ is a trade-off hyper-parameter between the Lasso ($\alpha = 1$) and the Group-Lasso ($\alpha = 0$). $\hat \varphi$ is the predicted log-partial hazard based on the latent space $\tilde X$. $\text{MSE}$ is the mean-squared error (Equation \ref{eq:mse-matrix}) and $L_\text{cox}$ is the negative partial log-likelihood (Equation \ref{eq:pl-efron}), that is $L_\text{cox} = - \ell(\beta)$ (\emph{i.e.,} we used Breslow's approximation). $B^{(m)}$ is a submatrix of $B$ containing only columns corresponding to inputs of modality $m$.

Due to its naiveness, we, unfortunately, found \emph{SAE} exceedingly challenging to train in that the learning rate required meticulous tuning to not start diverging. For this reason, we did not run our final benchmarks with \gls{sae} and excluded it from further consideration. Next, we were interested in giving each input modality a separate autoencoder and afterward fusing the individual latent spaces, similar to \citet{tong2020deep} but using supervised autoencoders. For this, we chose the two most self-evident operations, both of which \citet{tong2020deep} investigated as well: Mean-pooling and concatenation. We first present our concatenated approach, the \gls{csae}, followed by the mean-pooling approach, the \gls{msae}.

\subsection{\glsxtrfull{csae}}
In the concatenated approach, we fitted one supervised autoencoder for each input modality, after which we concatenated all first-level latent spaces $\tilde m_1, ..., \tilde m_{|M|}$ to form $C = [\tilde m_1, ..., \tilde m_{|M|}]$. This concatenation was then used to predict a log-partial hazard \(\hat \varphi (C)\) (Figure \ref{fig:arch-csae}). In addition, we regularized the last linear layer with \gls{sgl} (blue edges in Figure \ref{fig:arch-csae}).

\begin{figure}
\centering
    \includegraphics[scale=0.75]{./content/figures/fig_arch-csae.pdf} \caption{Architecture diagram of the \glsxtrfull{csae}. Grey edges denote L2 regularization, blue edges \glsxtrlong{sgl} regularization. Let $X^{(m_i)}$ denote the part of $X$ which corresponds to the i-th input variable group, $\hat X^{(m_i)}$ a reconstruction of the same. $\tilde m_i$ is the latent space of an autoencoder taking $X^{(m_i)}$ as its input and $C=[\tilde m_1, ..., \tilde m_{|M|}]$ is a concatenation of all first level latent spaces. $\hat \phi_1, ..., \hat \phi_{m}$ as well as $\hat \varphi$ are predicted log-partial hazards based on their respective inputs.}
    \label{fig:arch-csae}
\end{figure}

Since \gls{csae} contained individual autoencoders for each input modality, we modified the loss function of \gls{sae} slightly to include the additional autoencoders (Equation \ref{eq:csae-loss}):

\begin{equation}
  \begin{split}
  &L_{\text{total}}  \left(\hat \varphi, \hat \phi_1, ..., \hat \phi_{|M|}, X, \hat X\right) \\ &=  L_{\text{cox}}(T, \delta, \hat \varphi)  \\&+ \sum_{q = 1}^{|M|}  \left(L_\text{cox}(T, \delta, \hat \phi_q) + \gamma \cdot \text{MSE}\left(X^{\left(m_q\right)}, \hat X^{\left(m_q\right)}\right)\right) \\&+ \lambda_1 \sum_{a \in A \setminus B} ||a||_F^2 +\lambda_2 (1 - \alpha) \sum_{m \in \{m_1, ..., m_{|M|}\}} \sqrt{|m| } ||B^{(m)}||_F  \\&+  \lambda_2  \alpha || B||_{1,1}
  \end{split}
  \label{eq:csae-loss}
\end{equation}

Where $\lambda_1, \lambda_2$ are again regularization hyper-parameters as in Equation \ref{eq:sae-loss} and $\alpha$ is again a trade-off hyper-parameter between the Lasso and the Group-Lasso. $\gamma$ is another regularization hyper-parameter controlling the strength of the reconstruction loss of each first-level autoencoder, and $\hat \phi_i$ is the predicted log-partial hazard from each first level supervised autoencoder, while $\hat \varphi$ is the predicted log-partial hazard based on $C$. $\text{MSE}$ is the mean-squared error (Equation \ref{eq:mse-matrix}) and $L_\text{cox}$ is the negative partial log-likelihood (Equation \ref{eq:pl-efron}), that is $L_\text{cox} = - \ell(\beta)$ (\emph{i.e.,} we used Breslow's approximation). $B^{(m)}$ is a submatrix of $B$ containing only columns corresponding to inputs of modality $m$.

\subsection{\glsxtrfull{msae}}
\gls{msae} was constructed identical to the concatenated policy, save that instead of concatenation, we mean-pooled the first level latent spaces (Figure \ref{fig:arch-msae}). In addition, since after mean-pooling, variables cannot be mapped back to their original input group, \gls{msae} does not use any \gls{sgl} regularization in its loss function (Equation \ref{eq:msae-loss}).

\begin{figure}
\centering
    \includegraphics[scale=0.75]{./content/figures/fig_arch-msae.pdf} \caption{Architecture diagram of the \glsxtrfull{msae}. Grey edges denote L2 regularization. Let $X^{(m_i)}$ denote the part of $X$ which corresponds to the i-th input variable group, $\hat X^{(m_i)}$ a reconstruction of the same. $\tilde m_i$ is the latent space of an autoencoder taking $X^{(m_i)}$ as its input and $C=[\tilde m_1, ..., \tilde m_{|M|}]$ is a concatenation of all first level latent spaces. $C_{\text{MP}}$ is a mean-pooled version of $C$, \emph{i.e.,} it takes the mean across all first level latent spaces for each of the dimensions. $\hat \phi_1, ..., \hat \phi_{m}$ as well as $\hat \varphi$ are predicted log-partial hazards based on their respective inputs.}\label{fig:arch-msae}
\end{figure}

\begin{equation}
  \begin{split}
  &L_{\text{total}}  \left(\hat \varphi, \hat \phi_1, ..., \hat \phi_{|M|}, X, \hat X\right) \\ &=  L_{\text{cox}}(T, \delta, \hat \varphi)  \\&+ \sum_{q = 1}^{|M|}  \left(L_\text{cox}(T, \delta, \hat \phi_q) + \gamma \cdot \text{MSE}\left(X^{\left(m_q\right)}, \hat X^{\left(m_q\right)}\right)\right) \\&+ \lambda_1 \sum_{a \in A \setminus B} ||a||_F^2
  \end{split}
  \label{eq:msae-loss}
\end{equation}

where all notation is as above.

\subsection{\glsxtrfull{shae}}
Our last architecture, termed \gls{shae} was built on hierarchical supervised multi-modal autoencoders and was partially inspired by \citet{simidjievski2019variational}, who provided an overview of different possible architectures of \gls{vae}s for multi-omics integration. \gls{shae} has two levels of autoencoders. After the first level, which is identical to \gls{msae} and \gls{csae}, there is a second level autoencoder that takes the concatenation of all first-level latent spaces as its input (Figure \ref{fig:arch-shae}). The second level autoencoder once again predicts a log-partial hazard $\hat \varphi$ from its latent space $\tilde C$ and tries to reconstruct $C$ from $\tilde C$. We again regularized the first layer after the concatenation of the first level latent spaces using \gls{sgl} (blue edges in Figure \ref{fig:arch-shae}).

In effect, \gls{shae} can be thought of as running \gls{sae} with the concatenated latent spaces of \gls{csae} (except that everything is trained jointly). The full loss for \emph{SHAE} is then (Equation \ref{eq:loss-shae}):

\begin{figure}
\centering
    \includegraphics[scale=0.75]{./content/figures/fig_arch-shae.pdf} \caption{Architecture diagram of the \glsxtrfull{shae}. Grey edges denote L2 regularization, blue edges \glsxtrlong{sgl} regularization. Let $X^{(m_i)}$ denote the part of $X$ which corresponds to the i-th input variable group, $\hat X^{(m_i)}$ a reconstruction of the same. $\tilde m_i$ is the latent space of an autoencoder taking $X^{(m_i)}$ as its input and $C=[\tilde m_1, ..., \tilde m_{|M|}]$ is a concatenation of all first level latent spaces. $\hat \phi_1, ..., \hat \phi_{m}$ as well as $\hat \varphi$ are predicted log-partial hazards based on their respective inputs. $\tilde C$ is the latent space of the second-level autoencoder that takes $C$ as its input.}\label{fig:arch-shae}
\end{figure}

\begin{equation}
  \begin{split}
  &L_{\text{total}}  \left(\hat \varphi, \hat \phi_1, ..., \hat \phi_{|M|}, X, \hat X, C, \hat C\right) \\ &=  L_{\text{cox}}(T, \delta, \hat \varphi)  + \xi \cdot \text{MSE}(C, \hat C) \\&+ \sum_{q = 1}^{|M|}  \left(L_{\text{cox}}(T, \delta, \hat \phi_q ) + \gamma \cdot \text{MSE}\left(X^{\left(m_q\right)}, \hat X^{\left(m_q\right)}\right)\right) \\&+ \lambda_1 \sum_{a \in A \setminus B} ||a||_F^2 +\lambda_2 (1 - \alpha) \sum_{m \in \{m_1, ..., m_{|M|}\}} \sqrt{|m| } ||B^{(m)}||_F  \\&+  \lambda_2  \alpha || B||_{1,1}
  \end{split}
  \label{eq:loss-shae}
\end{equation}

Where $\lambda_1, \lambda_2, \alpha$ are hyper-parameters as above controlling \gls{sgl} and L2 regularization. $\xi$ and $\gamma$ are once again hyper-parameters controlling the strength of the reconstruction loss. $\hat C$ is a reconstruction of the concatenation of the first level latent spaces ($C = [\tilde m_1, ..., \tilde m_{|M|}]$), $\hat \varphi$ is the log-partial hazard prediction from the second level latent space and $\hat \phi_1, ..., \hat \phi_{|M|}$ are the log-partial hazard predictions from each first level supervised autoencoder. $\text{MSE}$ is the mean-squared error (Equation \ref{eq:mse-matrix}) and $L_\text{cox}$ is the negative partial log-likelihood (Equation \ref{eq:pl-efron}), that is $L_\text{cox} = - \ell(\beta)$ (\emph{i.e.,} we used Breslow's approximation). $B^{(m)}$ is a submatrix of $B$ containing only columns corresponding to inputs of modality $m$.

\subsection{Residual architecture versions}
We also explored a residual variant of all of our architectures (see \emph{Optional residual layer} in Figures \ref{fig:arch-sae} - \ref{fig:arch-shae}). In these, we fed the first modality (\(m_1\), clinical data in our study) into the autoencoder and also skipped it to the final layer predicting the log-partial hazard $\hat \varphi$. Using this skipping, we hoped to achieve two goals:

\begin{enumerate}
    \item The model could still take clinical data into account within the autoencoder(s), which might help other features or whole input groups, both with the reconstruction and for learning a better latent space for survival prediction.
    \item This may aid performance since clinical data (in most datasets) contains valuable survival information, as shown by \citet{herrmann2021large} and \citet{hornung2019block}.
\end{enumerate}

Our residual idea was heavily inspired by the favoring approach of \gls{bf} \citep{hornung2019block} and \emph{resnets} \citep{he2016deep}. We applied the residual approach to each of our architectures within our benchmarks, choosing to skip clinical data each time. We thus included a total of $6$ of our architectures in the benchmark, each of \gls{csae}, \gls{msae}  and \gls{shae} plus their respective residual version.

\subsection{Implementation}
\label{sec:implementation}
We developed all neural nets using \emph{Pytorch} \citep{paszke2019pytorch} and \emph{skorch} \citep{skorch}. We defaulted to scaling the supervised loss by multiplying it by the batch size (\emph{i.e.,} $\xi = \gamma = \text{batch size}$) since we found this worked well initially and saved one hyper-parameter.

For all of our architectures, we performed z-score standardization (Algorithm \ref{alg:z-score-norm}) of all features using \emph{sklearn} \citep{scikit-learn} before fitting the model. Further, we used batch normalization \citep{ioffe2015batch} and the \gls{prelu} (\ref{eq:prelu}) for non-linear activations \citep{he2015delving}. We used the \emph{Adam} optimizer \citep{kingma2014adam} for training our models and trained for $25$ epochs, with a batch size equal to the size of the dataset (\emph{i.e.,} no batching) and an initial learning rate of $0.01$ (the highest learning rate before the training loss started diverging for most cancers). We tuned the regularization parameters $\lambda_1$ and $\lambda_2$ using five fold cross-validation for $\lambda_1, \lambda_2 \in \{1e-2, 1e-3, 1e-4\}$. In line with the \emph{SGL} package \citep{sgl2019}, we fixed the $\alpha$ trade-off parameter for \gls{sgl} to $\alpha = 0.95$.\footnote{\citet{simon2013sparse} suggest using $\alpha=0.95$ if "we we expect strong overall sparsity and would like to encourage grouping" \citep{simon2013sparse} and $\alpha=0.05$ "if we expect strong group-wise sparsity, but only mild sparsity within group" \citep{simon2013sparse}. Since we generally expect fairly strong sparsity within groups (although neural networks will never have true zeros for weights anyway) for multi-omics integration, we chose $\alpha=0.95$.}

Since our models employ batch normalization, the literature suggests that it may be possible to fix the learning rate given the proper weight decay due to their strong interdependence in the presence of batch normalization, even for adaptive methods like \emph{Adam} \citep{hoffer2018norm, van2017l2}. Thus, we tuned only the regularization parameters and not the learning rate. All latent space sizes were set to size $64$, and all encoders (and by symmetry decoders) were set to have one hidden layer with $128$ nodes. While all of these architectural hyper-parameters were trainable in our implementation, we did not tune these in order not to complicate the hyper-parameter search space.

\begin{algorithm}
\caption{Z-score normalization algorithm.}\label{alg:z-score-norm}
    \begin{algorithmic}
    \Require $X$
    \State $X_{\text{norm}} \gets X$
    \For{$j = 1, ..., p$}
        \State $X_{\text{norm}}[:, p] \gets (X[:, p] - \text{mean}(X[:, p])) / \text{sd}(X[:, p])$
    \EndFor
    \State \Return $X_{\text{norm}}$
    \end{algorithmic}
\end{algorithm}

\begin{equation}\label{eq:prelu}
    \text{\gls{prelu}}(x) = \begin{cases}
        x, &\text{if $x\geq 0$}\\
        ax, &\text{otherwise}
        \end{cases}
\end{equation}

\section{Reference models}
For reference models, we used the best performing model from the benchmark study of \citet{herrmann2021large}, \glsxtrfull{bf},  as well as \glsxtrfull{rbf}.\footnote{{\emph{RandomBlock} is an alternative version of \glsxtrfull{bf} - \citet{hornung2019block} showed that it outperformed \gls{bf} when clinical variables were favored with multi-omics data on \gls{tcga} in terms of Harrell's concordance.}} Favoring refers to the decision tree base learners always considering all variables from a specific input group in the split-point selection (most often clinical variables), indepdendent of $m$. \gls{bf} and \gls{rbf} were implemented using the \emph{blockForest} package \citep{blockforestpackage2021}. For \gls{rbf}, we favored clinical variables.

We also included a \glsxtrfull{rsf} and a \glsxtrfull{lasso} as two benchmark methods that did not use the group structure information present in the multi-omics variables.  Lastly, we included a \glsxtrfull{cox}, specifically a Ridge regularized Cox PH model using only clinical variables. We opted for a Ridge regularized model since this allowed us to prevent convergence issues sometimes seen with one-hot encoded categorical clinical variables. \gls{rsf} was implemented using \emph{ranger} \citep{ranger} while \gls{lasso} and \gls{cox} were both implemented using \emph{glmnet} \citep{glmnet, coxnet}. \gls{lasso} and \gls{cox} were set to standardize their input matrices, while no further preprocessing was performed for \gls{rbf}, \gls{bf} and \gls{rsf}.

\section{Datasets}
We benchmarked all models on the \gls{tcga} datasets. We followed the approach of \citet{herrmann2021large} in selecting cancers with at least 100 samples and an average event ratio $\geq 5\%$ to ensure there were enough patients and enough events to calculate meaningful concordance values.\footnote{We selected only datasets with $100$ samples \emph{after} preprocessing, while \citet{herrmann2021large} included all datasets with $100$ samples \emph{before} preprocessing. This led us to excluding one dataset relative to \citet{herrmann2021large}, namely \gls{laml}.} Further, we utilized \emph{GISTIC 2.0} for \gls{cnv} \citep{mermel2011gistic2} and the number of non-silent \emph{MC3} mutation calls per gene per patient for mutation \citep{ellrott2018scalable}.\footnote{Mutation calls were calculated from the \emph{PANCANATLAS} \emph{MAF} file using \emph{Maftools} \citep{mayakonda2018maftools}.} \gls{cnv} was taken directly from \emph{Xenabrowser} \citep{goldman2020visualizing}, with mutation coming from \emph{PANCANATLAS} \citep{chang2013cancer}. In addition, we considered \gls{mirna}, \gls{mrna}, \gls{dna} methylation, \gls{rppa}, and clinical data, all of which were also taken from \emph{PANCANATLAS}. We log-transformed both \gls{mrna} and \gls{mirna} expression. Otherwise, no further preprocessing of the datasets was performed.

For comparability, we used the same clinical variables as \citet{herrmann2021large}, with the caveat that we dropped clinical variables which were missing for more than five patients. Categorical clinical variables were one-hot encoded. We excluded molecular variables if they were missing for more than one patient to preserve as many patients as possible. Table \ref{tab:tcga-overview} shows an overview of all datasets used in our benchmarks.

\begin{table}

\caption{\label{tab:tcga-overview}Summary information of all $17$ considered \gls{tcga} datasets used in our study. \gls{tcga} cancer abbreviations used for space, please refer to https://gdc.cancer.gov/resources-tcga-users/tcga-code-tables/tcga-study-abbreviations for a full overview. n refers to the samples in each cancer, p the number of total variables. The censoring ratio is the percentage of all patients that were censored. All other columns denote the number of variables contained in each input group. Table format inspired by \citet{herrmann2021large}.}
\centering
\resizebox{\linewidth}{!}{
\begin{tabular}[t]{c c c c c c c c c c c}
\toprule
Cancer & n & p & Censoring ratio & Clinical & mRNA & CNV & DNA methylation & miRNA & Mutation & RPPA\\
\midrule
BLCA & 325 & 84380 & 0.56 & 9 & 20225 & 24776 & 22124 & 740 & 16317 & 189\\
BRCA & 765 & 80668 & 0.87 & 9 & 20227 & 24776 & 19371 & 737 & 15358 & 190\\
COAD & 284 & 82221 & 0.78 & 16 & 17507 & 24776 & 21424 & 740 & 17569 & 189\\
ESCA & 118 & 75752 & 0.64 & 17 & 19076 & 24776 & 21941 & 737 & 9012 & 193\\
HNSC & 201 & 79286 & 0.40 & 16 & 20169 & 24776 & 21647 & 735 & 11752 & 191\\
\addlinespace
KIRC & 309 & 74652 & 0.72 & 14 & 20230 & 24776 & 19456 & 735 & 9252 & 189\\
KIRP & 199 & 76294 & 0.85 & 5 & 20178 & 24776 & 21921 & 738 & 8486 & 190\\
LGG & 395 & 78254 & 0.78 & 15 & 20209 & 24776 & 21564 & 740 & 10760 & 190\\
LUAD & 338 & 82999 & 0.60 & 11 & 20165 & 24776 & 21059 & 739 & 16060 & 189\\
PAAD & 100 & 76654 & 0.42 & 26 & 19932 & 24776 & 21586 & 732 & 9412 & 190\\
\addlinespace
SARC & 190 & 76068 & 0.64 & 45 & 20206 & 24776 & 21724 & 739 & 8385 & 193\\
SKCM & 238 & 85254 & 0.48 & 3 & 20179 & 24776 & 21635 & 741 & 17731 & 189\\
STAD & 304 & 80860 & 0.58 & 7 & 16765 & 24776 & 21506 & 743 & 16870 & 193\\
UCEC & 392 & 84130 & 0.84 & 24 & 17507 & 24776 & 21692 & 743 & 19199 & 189\\
OV & 161 & 72763 & 0.42 & 17 & 19064 & 24776 & 19639 & 731 & 8347 & 189\\
\addlinespace
LIHC & 157 & 76247 & 0.49 & 3 & 20078 & 24776 & 21739 & 742 & 8719 & 190\\
LUSC & 280 & 82125 & 0.59 & 20 & 20232 & 24776 & 20659 & 739 & 15510 & 189\\
\bottomrule
\end{tabular}}
\vspace{-5pt}
\end{table}

\section{Performance metric}
Similar to other works \citep{cheerla2019deep, kim2020improved, tong2020deep}, we used Harrell's concordance (Equation \ref{eq:concordance}) \citep{harrell1982evaluating} to measure the performance of our models, where \(\hat \phi_i\) is an estimated score for patient \(i\) (where higher score implies higher risk), \(U_i\) is the observed time until patient \(i\) either experienced the event or was censored, and \(\delta=0\) for censored patients and \(\delta=1\) otherwise \citep{schmid2016use}. Equivalently, Harrell's concordance is the ratio of concordant pairs and all comparable pairs.

\begin{equation}
  C(U, \delta, \hat \phi) = \frac{\sum_{i=1}^n \sum_{j=1}^n \mathbbm{1}(U_i > U_j) \mathbbm{1}(\hat{\phi}_i < \hat{\phi}_j) \delta_j}{\sum_{i=1}^n \sum_{j=1}^n  \mathbbm{1}(U_i > U_j) \delta_j}
  \label{eq:concordance}
\end{equation}

Where $\mathbbm{1}$ is the indicator function, and $n$ is the total number of patients.

\section{Validation}
\label{sec:testing}
We tuned all models using nested cross-validation with five inner folds or out-of-bag error (for random forest-based methods) to choose the best parameters to refit on the outer fold. We used the \emph{glmnet} internal \emph{cv.glmnet} function to optimize the regularization parameter for \gls{cox} and \gls{lasso} using five fold cross-validation. \gls{bf} and \gls{rbf} were tuned using the \emph{blockForest::blockfor} function. For \gls{rsf}, we tuned the \emph{mtry} parameter (\emph{mtry} is equivalent to $m$ in Algorithm \ref{alg:random-forest}) using the \emph{tuneRanger::tuneMtryFast} function. As mentioned in Chapter \ref{sec:implementation}, for our supervised autoencoders, we tuned only the regularization parameters $\lambda_1, \lambda_2 \in \{1e-2, 1e-3, 1e-4\}$ using five fold cross-validation (for architectures which used \gls{sgl}), while setting the other parameters to the defaults detailed in Chapter \ref{sec:implementation}.

For all cancers in our dataset, we performed outer five-fold cross-validation, twice repeated, giving us a total of ten outer splits per cancer. For statistical significance testing, we tested for an overall difference between our models and all non-group aware baselines (that is, \gls{lasso}, \gls{rsf}, and \gls{cox}) by adopting the same approach as \citet{hornung2019block}. We calculated the mean concordance per model per cancer ($17$ in total) and treated these mean values as independent between datasets. We then ran a one-sided paired t-test with a null hypothesis of non-inferiority of each non-group aware benchmark model relative to our architectures. The alternative hypothesis was that our model performed better than the respective benchmark method. We thus performed a total of $18$ tests (each of our three architectures and their residual version compared to each of the three reference models), for which we corrected using Bonferroni-Holm \citep{holm1979simple}. We report both raw p-values and p-values after correction.

\section{Computation times}
We captured the computation times of all models using \emph{tictoc} \citep{tictoc2021} for models in \emph{R} and \emph{time.perf\_counter} in \emph{Python}. All benchmarks were performed on the Euler cluster of ETH Zurich using eight cores with $4096$ MHz per core. Models which offered multi-threading by default (in particular, \gls{rsf}, \gls{bf}, \gls{rbf} and all of our neural architectures) were allowed to use all available CPUs. We did not parallelize models based on \emph{glmnet} (\gls{lasso} and \gls{cox}) since their computation times were very short even without parallelization. We note that we did not use a GPU, even though it would have favored our neural models, to enable optimal comparability of computation times.

\section{Reproducibility}
We fixed the random seeds throughout our scripts to ensure reproducibility. The implementations include reproduction scripts that can be used to reproduce all of our results. The only model used which was not able to use the respective \emph{R} or \emph{Python} seed was \emph{glmnet}. There was no reliable way to make \emph{glmnet} reproducible without passing the cross-validation splits ourselves. Hence, we assigned the cross-validation splits outside of the \emph{cv.glmnet} function (using the same logic as \emph{glmnet} does internally) and then passed the splits to the function such that computation was reproducible across runs \citep{glmnetreproduce}.

Despite our seeds, rerunning \gls{bf}, \gls{rbf} and \gls{rsf} on a different operating system might result in slightly different result (although overall results are of course are expected to be extremely similar), as all of them are implemented using the \emph{ranger} package \citep{wright2015ranger}. \emph{ranger} may produce different results on different operating systems, even when run with the same seed \citep{ranger-seed2021}. Similarly, the neural models may produce slightly different results when rerun (even on the same machine) due to non-reproducibility when Pytorch uses multi-threading on CPU \citep{pytorch-rep-2021}. The surrogate results may also not be fully deterministic, both due to the \emph{Pytorch} multi-threading issue mentioned above and since the \emph{glmnet} solver is not fully deterministic according to the documentation of \emph{python-glmnet} \citep{python-glmnet-rep}. Nevertheless, any deviations when rerunning are expected to be minor but could unfortunately not be completely excluded.

\section{Latent space investigation}
To better understand the main features learned by our neural models, we investigated the latent space of our best model for a few cancers. Since the latent spaces of our models were non-sparse, we instead analyzed the correlations of each latent space dimension with specific input features. In particular, we considered all features with the highest absolute correlation with at least one latent space dimension.\footnote{Since some input variables had the highest absolute correlation for more than one dimension, this analysis generally produced less than $64$ features (recall that our latent spaces are fixed to size $64$).}

In addition, we investigated pathway activity captured by our models' latent space. We calculated the correlation of each gene with each latent space dimension and created a ranked gene list using these correlations. We then ran \gls{gsea} \citep{subramanian2005gene} on this ranked gene list for each latent dimension using \gls{fgsea} \citep{korotkevich2021fast} and the hallmarks of cancer \citep{hanahan2000hallmarks} gene sets from \emph{MSigDB} \citep{liberzon2011molecular}. We investigated the best split (by test concordance) for the model under consideration for every exemplary cancer considered since overall differences for the worse splits were negligible (data not shown).

\section{Permutation importance}
To get a secondary measure of how important each input group was for our models, we also leveraged group-wise permutation importance (Algorithm \ref{alg:fi-group}) introduced in Chapter \ref{alg:fi-group} as appropriate. To be precise, we calculated ten permutations for each input variable group to give us a reasonably robust measure of group feature importance.\footnote{Since concordance is not an error measurement, we define our error function $e$ as $e = 1 - \text{Harrell's concordance}$ when analyzing permutation importance.}

\section{Global surrogate models}
We chose to fit global surrogate Lasso regression models to approximate the predictions of our best architecture (recall that global surrogates were introduced in Chapter \ref{sec:global-surrogates}). In particular, we wanted to investigate whether a global surrogate model could replicate our models predictions well when only having had access to a subset of input variable groups as this would enormously improve clinical applicability while potentially maintaining high performance. We thus fitted our surrogate models on only clinical data and gene expression (the two most commonly available but at the same time among the most predictive input groups) but had them approximate our best full multi-omics models. The hope was that the models would learn some of the multi-omics information even without having had access to all input groups.

We were then interested in how well surrogate models could perform, both in terms of approximating the multi-omics neural models (measured by \emph{e.g.,} $R^2$) and absolute performance (that is, concordance on the test set). While these two goals are overlapping, they are not identical. Consider that our multi-omics neural models may have overfitted the training data. The surrogates' test concordance could thus benefit from a less than perfect fit to the multi-omics model by reducing overfitting. Lastly, we were also curious how sparse these surrogate models would be, especially compared to standard non-group aware methods such as the \gls{lasso}. We implemented our surrogate models using \emph{python-glmnet} \citep{py-glmnet}, the \emph{Python} wrapper of \emph{glmnet} \citep{glmnet}. Since clinical variables generally contain much prognostic relevant information \citep{herrmann2021large}, we penalized only the gene expression variables.

Our approach in predicting the log-partial hazard estimated by an upstream multi-omics model is reminiscent of pseudo-value methods in survival analysis, which replace right-censored survival data with \emph{jackknife} pseudo-observations, thus enabling a change in model class to perform regression instead of survival analysis \citep{zhao2020deep, klein2005regression, andersen2010pseudo}. However, we note that our approach does not have any statistical guarantees (as far as we know) that some of the other pseudo-value techniques do. We also emphasize that care must be taken when interpreting the pseudo hazard ratios obtainable by analyzing the coefficients of the surrogate models. In effect, these cannot be directly interpreted as hazard ratios but rather as a prediction of the hazard ratio which would have been predicted by the model the surrogates are approximating.

\section{Multi-omics integration as feature selection}
\label{sec:arch-search}
Last but not least, we were also interested in establishing whether the sparsity pattern recovered by our surrogate models was sufficient for arbitrary models to achieve similar performance to the surrogate models. Effectively, we were thus interested in whether multi-omics integration could be reduced to a feature selection task.

This question is somewhat reminiscent of a similar discussion in neural networks. Previous works had claimed that in structured pruning, what matters is not just the sparsity pattern (\emph{i.e.,} the architecture), but also the weights learned by the initial model, which could then be fine-tuned after pruning \citep{han2015learning}. \citet{liu2018rethinking} on the other hand, showed that after structured pruning, they could achieve as good or better results by retraining the sparsified architectures from random initializations. The results from \citet{liu2018rethinking} thus suggest that structured pruning in neural networks can, in effect, be treated as an \emph{architecture search} problem, meaning what matters is solely the sparsity pattern.

We reframed this question slightly to adapt it to our task of hand. For this, we fitted two models only on the subset of variables selected by one of our surrogate models:

\begin{enumerate}
    \item A Ridge penalized Cox PH model
    \item An \gls{rsf} model
\end{enumerate}

The Ridge model was fit and tuned using the \emph{cv.glmnet} function while the \gls{rsf} model was tuned and fit using \emph{tuneRanger::tuneMtryFast}. What we thus wanted to answer was essentially: Are the selected features from the surrogate models sufficient to reproduce their performance, or do the weights learned by our surrogates play a role (presumably because they were trained not on the actual survival data but the \gls{shae} predictions)?

This is an interesting question because, if true, it would allow the reframing of multi-omics integration as purely a feature-selection problem. In turn, this would enable researchers to treat multi-omics models merely as a modeling step rather than the final output. Following this reasoning, this hypothesis could greatly improve the clinical applicability of multi-omics models as they could then be replaced by interpretable models trained on the correct subset of variables. If disproven, the hypothesis could still prove interesting. In that case, it would essentially show that training surrogate models on the predictions of multi-omics models is one of the best ways to achieve interpretable models for clinical practice, as other models with the same sparsity pattern cannot match their performance.


% !TEX encoding = UTF-8 Unicode
% !TEX spellcheck = en_US
% !TEX root = ../../../ICMA2020.tex

\appendices
\label{sec:Appendix}
\section{Minimal Dynamics Parameter Vector}
\label{sec:MinparamVector}

The used Parameters are the mass $m_j$, the center of mass $\boldsymbol{r}_j$ in the coordinate system $(CS)_j$, the inertia $_{(j)}\boldsymbol{J}_j^{(j)}$ in the coordinate system $(CS)_j$ and referring to the frame origin, the motor and gear inertia $J_{Aj}$ as well as the Coulomb and viscous friction $f_{\mathrm{c}j}$ and $f_{\mathrm{v}j}$ for the joints $j=1,\ldots,6$ respectively.
The combined masses $m_{123456}$, $m_{23456}$, $m_{3456}$ and $m_{456}$ are defined in \eqref{eq:MassenSumme}.
The notation for $\boldsymbol{r}_j$ and $_{(j)}J_j^{(j)}$ is defined by

\begin{equation}
\label{eq:Komponentenschreibweise}
	\boldsymbol{r}_j =
		\begin{pmatrix}
		r_{jx} \\
		r_{jy} \\
		r_{jz} \\
		\end{pmatrix}
	\quad
	\mathrm{and}
	\quad
	_{(j)}\boldsymbol{J}_j^{(j)} =
		\begin{pmatrix}
		J_{jxx} & J_{jxy} & J_{jxz} \\
		J_{jxy} & J_{jyy} & J_{jyz} \\
		J_{jxz} & J_{jyz} & J_{jzz} \\
		\end{pmatrix}
		.
\end{equation}

{\footnotesize
\begin{equation}
\label{eq:Parametersatz}
%	\begin{pmatrix}
%	    \theta_1 \\
%	    \theta_2 \\
%	    \theta_3 \\
%	    \theta_4 \\
%	    \theta_5 \\
%	    \theta_6 \\
%	    \theta_7 \\
%	    \theta_8 \\
%	    \theta_9 \\
%	    \theta_{10} \\
%	    \theta_{11} \\
%	    \theta_{12} \\
%	    \theta_{13} \\
%	    \theta_{14} \\
%	    \theta_{15} \\
%	    \theta_{16} \\
%	    \theta_{17} \\
%	    \theta_{18} \\
%	    \theta_{19} \\
%	    \theta_{20} \\
%	    \theta_{21} \\
%	    \theta_{22} \\
%	    \theta_{23} \\
%	    \theta_{24} \\
%	    \vdots \\
%	    \theta_{29} \\
%	    \theta_{30} \\
%	    \vdots \\
%	    \theta_{36} \\
%	\end{pmatrix
	\boldsymbol{\theta}=
		\begin{pmatrix}
			J_{1yy} + 2 l_2 m_1 r_{1x} + l_2^2 m_{123456} + J_{\text{A}1} + J_{2yy} - l_3^2 m_{23456} + J_{3zz} - l_4^2 m_{3456} \\
			l_3^2 m_{23456} + J_{2xx} - J_{2yy} \\
			- l_3 m_2 r_{2z} + l_3 m_3 r_{3y} + J_{2xy} \\
			- l_3^2 m_{23456} + J_{2zz} + J_{\text{A}2} \\
			l_3 m_{23456} + m_2 r_{2x} \\
			J_{3xx} -J_{3zz} + l_4^2 m_3 + J_{4zz} + 2 l_5 m_4 r_{4y} + (l_4^2 +l_5^2) m_{456} \\
			-l_4 m_3 r_{3y} + J_{3xy} \\
			J_{3xz} \\
			J_{3yy} - l_4^2 m_{3456} + J_{4zz} + 2l_5 m_4 r_{4y} + l_5^2 m_{456} \\
			J_{3yz} \\
			l_4 m_{3456} + m_3 r_{3x} \\
			l_5 m_{456} + m_3 r_{3z} + m_4 r_{4y} \\
			J_{\text{A}3} \\
			J_{4xx} - J_{4zz} + J_{5zz} \\
			J_{4yy} + J_{5zz} \\
			J_{\text{A}4} \\
			l_6^2 m_6 + 2 l_6 m_6 r_{6z} + J_{5xx} - J_{5zz} + J_{6yy} \\
			l_6^2 m_6 + 2 l_6 m_6 r_{6z} + J_{5yy} + J_{6yy} \\
			l_6 m_6 + m_5 r_{5z} + m_6 r_{6z} \\
			J_{\text{A}5} \\
			J_{6xx} - J_{6yy} \\
			J_{6zz} \\
			J_{\text{A}6} \\

			f_{\mathrm{c},1} \\
			\vdots \\
			f_{\mathrm{c},6} \\

			f_{\mathrm{v},1} \\
            \vdots \\
			f_{\mathrm{v},6} \\
		\end{pmatrix}
\end{equation}
}

%\begin{equation}
%\label{eq:MassenSumme}
%    \begin{aligned}
%	m_{123456} &= m_1 + m_2 + m_3 + m_4 + m_5 + m_6 \text{ ,}\\
%	m_{23456} &= m_2 + m_3 + m_4 + m_5 + m_6 \text{ ,} \\
%	m_{3456} &= m_3 + m_4 + m_5 + m_6 \text{ ,} \\
%	m_{456} &= m_4 + m_5 + m_6 \\
%    \end{aligned}
%\end{equation}

\begin{equation}
\label{eq:MassenSumme}
    m_{j..6}=\sum_{i=j}^{6} m_i
\end{equation}


\section{A Universe of Inductive Families}
\label{sec:indexing-desc}

\newcommand{\vtup}[2]{\bigRedBracket{\begin{array}{@{}#1@{}}#2\end{array}}}

\begin{wstructure}
!!! Need Help !!!
<- Motivation
    <- Desc: expressivity of simply-typed datatypes: inductive types
        <- Values do not influence types
    /> Example: Vectors
        <- Cannot be defined by just induction
            <- Vectors of all size need to be defined at the *same* time
            -> Defined as a *family* of types
                -> Index
        -> I -> IDesc I: Inductive family
    ???
\end{wstructure}

So far, we have explored the realm of inductive types, building on
intuition from ML-like datatypes, using type dependency as a
descriptive tool in $\Desc$ and its interpretation. Let us now make
dependent types the object as well as the means of our study.

Dependent datatypes provide a way to work at higher level of
precision \emph{a priori}, reducing the sources of failure we
might otherwise need to manage. For the perennial
example, consider \emph{vectors}---lists indexed by length. By
making length explicit in the type, we can prevent hazardous
operations (the type of `head' demands vectors of length
$\NatSuc{\V{n}}$) and offer stronger guarantees (pointwise
addition of $\V{n}$-vectors yields an $\V{n}$-vector).

However, these datatypes are not \emph{individually} inductive. For
instance, we have to define the whole \emph{family} of vectors
mutually, in one go. In dependently typed languages, the basic grammar
of datatypes is that of inductive families. To capture this grammar,
we must account for \emph{indexing}.

%% \subsection{Desc, atomically}
%% \label{sec:idesc-atomic-desc}

%% \begin{wstructure}
%% [Outdated: type former presentation instead]
%% <- Adding hindx have introduced some duplication
%%     <- indx == hindx 1
%%     -> We can factor out commonalities
%%         /> Obtain an equivalent presentation
%%         /> Still embeddable (refer to the Agda model)
%% \end{wstructure}

%% \begin{wstructure}
%% <- Also replacing '1 by 'const  [figure]
%%     <- For convenience
%%         <- 'const X equivalent to 'sigma X (\_ -> '1)
%%         /> Easier to abstract
%%             <- Extensionally same
%%             /> 'const more useful in practice
%% \end{wstructure}

%% Before moving on to indexed descriptions, we have to carry out some
%% maintenance work on descriptions. We presented $\Desc$ as the grammar
%% of inductive types. Hence, the codes closely follow this grammar. In
%% the following, we adopt an alternative presentation. With
%% $\DSigma{\!}{\!}$, we are actually \emph{quoting} a standard
%% type-former, namely

%% $$\Bhab{\Sigma}{\PI{\V{S}}{\Set} \PI{\V{S}}{\Set} \Set}$$

%% In the alternative presentation, we go further and present all our
%% codes as quotations of standard type-formers. This presentation is
%% shown in Figure~\ref{fig:type-former-desc}. The reader will notice
%% that we replace $\DUnit$ by a more general $\DConst{\!}$ code. Whereas
%% $\DUnit$ was interpreted as the unit set, $\DConst{\V{X}}$ is
%% interpreted as $\V{X}$, for any $\Bhab{\V{X}}{\Set}$. Extensionally,
%% $\DConst{\V{X}}$ and $\DSigma{\V{X}}{\DUnit}$ are equivalent. However,
%% $\DConst{\!}$ is more succinct. More importantly, $\DConst$ is
%% \emph{first-order}, unlike its equivalent encoding. From a
%% definitional perspective, we are giving more opportunities to the
%% type-system, hence reducing the burden on the programmer. For the same
%% reason, we introduce $\DProd{\!}{\!}$ that overlaps with
%% $\DSigma{\!}{\!}$.

%% This reorganisation is strictly equivalent to the previous one
%% (Fig.~\ref{fig:hindx_desc}). Just as the previous version, it is also
%% self-descriptive. We refer the reader to the companion technical
%% report for details. In this finer-grained presentation, we can define
%% $\DIndx{\!}$ and $\DHindx{\!}{\!}$ as follow:

%% \[\begin{array}{l@{\:\mapsto\:\:}l}
%% \DIndx{\V{D}}         & \DProd{\DId}{\V{D}}                      \\
%% \DHindx{\V{H}}{\V{D}}     & \DProd{(\DPi{\V{H}}{(\LAM{\_} \DId)})}{\V{D}}
%% \end{array}
%% \]

%% Consequently, the examples previously developed can be
%% straightforwardly translated into this new presentation. For example,
%% here is the new definition of $\NatD$:

%% \[\stk{
%% \NatD : \Desc \\
%% \NatD \mapsto \DSigma{(\EnumT{[ \NatZero, \NatSuc{\!} ]})}
%%                      {[ \DUnit \quad \DId ]}
%% }\]

%% In the following, we adopt this last version as our de
%% facto universe of inductive types. In particular, we are going to
%% evolve this presentation into an indexed one.

%% \note{Shall we talk about the Type Theory being Desc Zero? or such story?}

%% \begin{figure}

%% \[\stk{
%% \begin{array}{ll}
%% \stk{
%% \data \Desc : \Set \where                                      \\
%% \;\;\begin{array}{@{}l@{\::\:\:}l@{\quad}l}
%%     \DId            & \Desc                                    \\
%%     \DConst{\!}     & \Set \To \Desc                           \\
%%     \DProd{\!}{\!}  & \PI{\V{D}, \V{D'}}{\Desc} \Desc          \\
%%     \DSigma{\!}{\!} & \PI{\V{S}}{\Set} \PIS{\V{S} \To \Desc} \Desc \\
%%     \DPi{\!}{\!}    & \PI{\V{S}}{\Set} \PIS{\V{S} \To \Desc} \Desc
%% \end{array}
%% }
%% \vspace{0.2in}
%% \\
%% \stk{
%% \descop{\_\:}{} : \Desc \To \Set \To \Set \\
%% \begin{array}{@{}l@{\:=\:\:}ll}
%% \descop{\DId}{\V{X}}          &  \V{X}                                           \\
%% \descop{\DConst{\V{Z}}}{\V{X}}    &  \V{Z}                                           \\
%% \descop{\DProd{\V{D}}{\V{D'}}}{\V{X}} &  \TIMES{\descop{\V{D}}{\V{X}}}{\descop{\V{D}\V{'}}{\V{X}}}       \\
%% \descop{\DSigma{\V{S}}{\V{D}}}{\V{X}} &  \SIGMA{\V{s}}{\V{S}} \descop{\V{D}\: \V{s}}{\V{X}}          \\
%% \descop{\DPi{\V{S}}{\V{D}}}{\V{X}}    &  \PI{\V{s}}{\V{S}} \descop{\V{D}\: \V{s}}{\V{X}}
%% \end{array}
%% }
%% \end{array}
%% }\]

%% \caption{Universe of descriptions based on Type-formers}
%% \label{fig:type-former-desc}

%% \end{figure}

\subsection{The universe of indexed descriptions}

\begin{wstructure}
<- Labelling Id
    <- We had: data Desc : Set -> Set
    -> We want: data IDesc : (I -> Set) -> Set
        <- Indexed functor (?)
        -> It is sufficient to label Id
            <- Where the functor is built
\end{wstructure}

\newcommand{\DotTo}{\mathop{\blue{\dot{\rightarrow}}}}

We presented the $\Desc$ universe as a
grammar of strictly positive endofunctors on $\Set$ and developed
inductive types by taking a fixpoint. To describe inductive families
indexed by some $\Bhab{\V{I}}{\Set}$, we play a similar game with
endofunctors on the category $\Set^{\V{I}}$,
families of sets \(\V{X},\V{Y}:\V{I}\To\Set\) for objects, and for morphisms,
families of functions in \(\V{X}\DotTo\V{Y}\), defined pointwise:
\[
\V{X}\DotTo\V{Y} \mapsto \PI{\V{i}}{\V{I}}\V{X}\:\V{i}\To\V{Y}\:\V{i}
\]

An \emph{indexed functor} in $\Set^{\V{I}}\To\Set^{\V{J}}$ has the
flavour of a device driver, characterising `responses' to a given
request in \(\V{J}\) where we may in turn make `subrequests' at indices
chosen from \(\V{I}\). When we use indexed functors to define inductive
families of datatypes,
\(\V{I}\) and \(\V{J}\) coincide: we explain how to make a node fit a given
index, including subnodes at chosen indices. E.g., if we are asked for a
vector of length 3, we choose to ask in turn for a tail of length 2.

To code up valid notions of response to a given request, we introduce
$\SYMBIDesc$ and its interpretation:
%
\[\stk{
\IDesc{(\Bhab{\V{I}}{\Set})} : \Set \smallskip \\
\idescop{\_}{}{} : _{\PI{\V{I}}{\Set}} \IDesc{\V{I}} \To (\V{I} \To \Set) \To \Set    \\
}\]

An \(\IDesc{\V{I}}\) specifies just \emph{one} response, but a
request-to-response \emph{function},
$\V{R}:\V{I} \To \IDesc{\V{I}}$, yields a strictly positive endofunctor
\[
  \LAM{\V{X}} \LAM{\V{i}} \idescop{\V{R}\:\V{i}}{\V{I}}{\V{X}} :
  \Set^{\V{I}} \To \Set^{\V{I}}
\]
whose fixpoint we then take:
%
\[\stkl{
\Rule{\Gamma \vdash \Bhab{\V{I}}{\Set} \qquad
      \Gamma \vdash \Bhab{\V{R}}{\V{I} \To \IDesc{\V{I}}}}
     {\Gamma \vdash \Bhab{\SYMBIMu_{\V{I}}{\V{R}}}{\V{I}\To\Set}} \qquad
\\
\Rule{\begin{array}{l@{\qquad}l}
          \Gamma \vdash \Bhab{\V{I}}{\Set} &
          \Gamma \vdash \Bhab{\V{R}}{\V{I} \To \IDesc{\V{I}}} \\
          \Gamma \vdash \Bhab{\V{i}}{\V{I}} &
          \Gamma \vdash \Bhab{\V{x}}{\idescop{\V{R}\:\V{i}}{\V{I}}{(\SYMBIMu_{\V{I}}{\V{R}})}}
      \end{array}}
     {\Gamma \vdash \Bhab{\Con{\V{x}}}{\IMu{\V{I}}{\V{R}}{\V{i}}}}
}\]

\newcommand{\upgrade}{\F{upgrade}}
\newcommand{\inductionI}{\F{indI}}
\newcommand{\cataI}{\F{cataI}}

We define the $\SYMBIDesc$ grammar in Figure~\ref{fig:idesc},
delivering only \emph{strictly positive} families. As well as
indexing our descriptions, we have refactored a little, adopting
a more compositional algebra of codes, where $\Desc$ is
biased towards the right-nested tuples. We now have
\(\DVar{i}\) for recursive `subrequests' at a chosen index \(i\),
with tupling by right-associative
\(\DProd{}{}\) and higher-order branching
by \(\DPi{\!}{\!}\).  Upgrade your old $\Desc$
to a trivially indexed $\IDesc{\Unit}$ as follows!
\[\begin{array}{@{}ll}
\upgrade :\Desc & \To\IDesc{\Unit} \\
\upgrade\:\DUnit & \mapsto \DConst{\Unit} \\
\upgrade\:(\DSigma{\V{S}}{\V{D}}) &
   \mapsto \DSigma{\V{S}}{\LAM{\V{s}}\upgrade\:(\V{D}\:\V{s})} \\
\upgrade\:(\DIndx{\V{D}}) & \mapsto
  \DProd{\DVar{\Void}}{\upgrade\:\V{D}} \\
\upgrade\:(\DHindx{\V{H}}{\V{D}}) & \mapsto
  \DProd{(\DPi{\V{H}}{\LAM{\_}\DVar{\Void}})}{\upgrade\:\V{D}} \\
\end{array}\]

To deliver induction for indexed datatypes, we need the `holds everywhere'
machinery. We present $\SYMBAllI$ and $\SYMBallI$ in
Figure~\ref{fig:allI-predicates}, with a twist---where
$\Desc$ admits the $\SYMBall$ construction, $\SYMBIDesc$ is \emph{closed}
under it! The $\SYMBAllI$
operator for a description indexed on \(\V{I}\) is strictly positive in
turn, and has a description indexed on
 some \(\SIGMA{\V{i}}{\V{I}}{\V{X}\: \V{i}}\).
Induction on indexed descriptions is then hardwired thus:
%
\[\stk{
\begin{array}{@{}ll}
\inductionI : & _{\PI{\V{I}}{\Set}}
                   \PITEL{\V{R}}{\V{I} \To \IDesc{\V{I}}}
                   \PI{\V{P}}{(\SIGMA{\V{i}}{\V{I}}{\IMu{\V{I}}{\V{R}}{\V{i}}}) \To \Set} \\
                 & (      \PITEL{\V{i}}{\V{I}}
                          \PI{\V{xs}}{\idescop{\V{R}\: \V{i}}{\V{I}}{(\SYMBIMu_{\V{I}}{\V{R}})}} \\
                 & \   \idescop{\AllI{}
                                     {(\V{R}\: \V{i})}
                                     {(\SYMBIMu_{\V{I}}{\V{R}})}
                                     {\V{xs}}}
                               {}
                               {\V{P}} \To
                       \V{P}\: \pair{\V{i}}{\Con{\V{xs}}}{}) \To \\
                 & \PITEL{\V{i}}{\V{I}}
                   \PI{\V{x}}{\IMu{\V{I}}{\V{R}}{\V{i}}}
                   \V{P}\: \pair{\V{i}}{\V{x}}{}
\end{array} \\
\inductionI\: \V{R}\: \V{P}\: \V{m}\: \V{i}\: (\Con{\V{xs}}) \mapsto
    \V{m}\: \V{i}\: \V{xs}\: (\allI{}
                                    {\V{R}\: \V{i}}
                                    {(\SYMBIMu_{\V{I}}{\V{R}})}
                                    {\V{P}}
                                    {(\spl{\LAM{\V{i}}\LAM{\V{xs}} \inductionI\: \V{R}\: \V{P}\: \V{m}})}
                                    {\V{xs}})
}\]
%
The generic catamorphism, $\cataI$, is constructed from $\inductionI$
as before. Its type becomes more elaborated, to deal with the
indexing:
%
\[
\begin{array}{@{}l@{}l}
\cataI :& \PITEL{\V{I}}{\Set}
          \PITEL{\V{R}}{\V{I} \To \IDesc{\V{I}}} \\
        & \PI{\V{T}}{\V{I} \To \Set}
          (\PI{\V{i}}{\V{I}}{\idescop{\V{R}\: \V{i}}{}{\V{T}} \To \V{T}\: \V{i}}) \To
          \SYMBIMu_{\V{I}}{\V{R}} \DotTo \V{T}
\end{array}
\]

\begin{figure*}

\[
\begin{array}{ll}
%%
\stk{
\begin{array}{@{}ll}
\SYMBAllI : & _{\PI{\V{I}}{\Set}}
              \PITEL{\V{D}}{\IDesc{\V{I}}}
              \PI{\V{X}}{\V{I} \To \Set} \\
            & \idescop{\V{D}}{\V{I}}{\V{X}} \To
              \IDesc{(\SIGMA{\V{i}}{\V{I}}{\V{X}\: \V{i}})}
\end{array} \\
\begin{array}{@{}l@{}l@{\:\mapsto\:\:}l}
\AllI{\:}{(\DVar{\V{i}})}{& \V{X}}{\V{x}} &
    \DVar{\pair{\V{i}}{\V{x}}{}} \\
\AllI{\:}{(\DConst{\V{K}})}{& \V{X}}{\V{k}} &
    \DConst{\Unit} \\
\AllI{\:}{(\DProd{\V{D}}{\V{D'}})}{& \V{X}}{\pair{\V{d}}{\V{d'}}{}} &
    \DProd{\AllI{}{\V{D}}{\V{X}}{\V{d}}}{\AllI{}{\V{D'}}{\V{X}}{\V{d'}}} \\
\AllI{\:}{(\DSigma{\V{S}}{\V{D}})}{& \V{X}}{\pair{\V{s}}{\V{d}}{}} &
    \AllI{}{(\V{D}\: \V{s})}{\V{X}}{\V{d}} \\
\AllI{\:}{(\DPi{\V{S}}{\V{D}})}{& \V{X}}{\V{f}} &
    \DPi{\V{S}}{\LAM{\V{s}} \AllI{}{(\V{D}\: \V{s})}{\V{X}}{(\V{f}\: \V{s})}}
\end{array}
}
&
%%
\stk{
\begin{array}{@{}ll}
\SYMBallI : & _{\PI{\V{I}}{\Set}}
              \PITEL{\V{D}}{\IDesc{\V{I}}}
              \PITEL{\V{X}}{\V{I} \To \Set}
              \PI{\V{P}}{(\SIGMA{\V{i}}{\V{I}}{\V{X}\: \V{i}}) \To \Set} \\
            & (\PI{\V{x}}{\SIGMA{\V{i}}{\V{I}}{\V{X}\: \V{i}}} \V{P}\: \V{x}) \To
              \PI{\V{xs}}{\idescop{\V{D}}{\V{I}}{\V{X}}}
              \idescop{\AllI{}{\V{D}}{\V{X}}{\V{xs}}}{}{\V{P}}
\end{array} \\
\begin{array}{@{}l@{}l@{\:\mapsto\:\:}l}
\allI{\:}{(\DVar{\V{i}})}{& \V{X}}{\V{P}}{\V{p}}{\V{x}} &
    \V{p}\: \pair{\V{i}}{\V{x}}{} \\
\allI{\:}{(\DConst{\V{K}})}{& \V{X}}{\V{P}}{\V{p}}{\V{k}} &
    \void \\
\allI{\:}{(\DProd{\V{D}}{\V{D'}})}{& \V{X}}{\V{P}}{\V{p}}{\pair{\V{d}}{\V{d'}}{}} &
    \pair{\allI{}{\V{D}}{\V{X}}{\V{P}}{\V{p}}{\V{d}}}
         {\allI{}{\V{D'}}{\V{X}}{\V{P}}{\V{p}}{\V{d'}}}{} \\
\allI{\:}{(\DSigma{\V{S}}{\V{D}})}{& \V{X}}{\V{P}}{\V{p}}{\pair{\V{s}}{\V{d}}{}} &
    \allI{}{(\V{D}\: \V{s})}{\V{X}}{\V{P}}{\V{p}}{\V{d}} \\
\allI{\:}{(\DPi{\V{S}}{\V{D}})}{& \V{X}}{\V{P}}{\V{p}}{\V{f}} &
    \LAM{\V{a}}\allI{}{(\V{D}\: \V{a})}{\V{X}}{\V{P}}{\V{p}}{(\V{f}\: \V{a})}
\end{array}
\end{array}
}
\]

\caption{Indexed induction predicates}
\label{fig:allI-predicates}

\end{figure*}

\begin{figure}

\[\stk{\begin{array}{@{}ll}
\IDesc{(\Bhab{\V{I}}{\Set})} &: \Set \\
\DVar{(\Bhab{\V{i}}{\V{I}})} &: \IDesc{\V{I}} \\
\DConst{(\Bhab{\V{A}}{\Set})} &:\IDesc{\V{I}}       \\
\DProd{(\Bhab{\V{D}}{\IDesc{\V{I}}})}{(\Bhab{\V{D}}{\IDesc{\V{I}}})}
  & :\IDesc{\V{I}}       \\
\DSigma{(\Bhab{\V{S}}{\Set})}{(\Bhab{\V{D}}{\V{S}\To\IDesc{\V{I}}})}
& : \IDesc{\V{I}}  \\
\DPi{(\Bhab{\V{S}}{\Set})}{(\Bhab{\V{D}}{\V{S}\To\IDesc{\V{I}}})}
& : \IDesc{\V{I}}  \\
\end{array}\smallskip \\
\idescop{\_\:}{}{} :_{\PI{\V{I}}{\Set}} \IDesc{\V{I}} \To (\V{\V{I}} \To \Set) \To \Set                  \\
\begin{array}{@{}l@{\V{X}}@{\:\mapsto\:\:}ll}
\idescop{\DVar{\V{i}}}{\V{I}}{&}      &  \V{X}\: \V{i}                                           \\
\idescop{\DConst{\V{K}}}{\V{I}}{&}    &  \V{K}                                                   \\
\idescop{\DProd{\V{D}}{\V{D'}}}{\V{I}}{&} &  \TIMES{\idescop{\V{D}}{\V{I}}{\V{X}}}{\idescop{\V{D'}}{\V{I}}{\V{X}}}       \\
\idescop{\DSigma{\V{S}}{\V{D}}}{\V{I}}{&} &  \SIGMA{\V{s}}{\V{S}} \idescop{\V{D}\: \V{s}}{\V{I}}{\V{X}}                    \\
\idescop{\DPi{\V{S}}{\V{D}}}{\V{I}}{&}    &  \PI{\V{s}}{\V{S}} \idescop{\V{D}\: \V{s}}{\V{I}}{\V{X}}
\end{array}
}
\]

\caption{Universe of indexed descriptions}
\label{fig:idesc}

\end{figure}

\subsection{Examples}
\label{sec:idesc-examples}

\paragraph{Natural numbers:}

\begin{wstructure}
<- Nat
    -> [equation]
    <- Non-indexed types lives in IDesc 1
        -> This applies to all previous examples
\end{wstructure}

For basic reassurance, we \(\upgrade\:\NatD\):
%
\[\stk{
\upgrade\:\NatD : \IDesc{\Unit} \\
\upgrade\:\NatD \mapsto \DSigma{(\EnumT{\sqr{\NatZero\: \SYMBNatSuc}})}
                     {\sqr{(\DConst{\Unit}) \;
                           (\DProd{\DVar{\Void}}{\DConst{\Unit}})}}
}\]
%
Note that trailing \(\Unit\)'s keep our right-nested, \(\void\)-terminated
tuple structure, and with it our elaboration machinery.
We can similarly \(\upgrade\) any inductive type.
Moreover, \(\IDesc{I}\) can now code a bunch of mutually
inductive types, if \(I\) enumerates the
bunch~\cite{paulin:habilitation, yakushev:mutual-def}.

\paragraph{Indexed descriptions:}

\begin{wstructure}
<- Levitation [figure]
    <- Following Desc encoding
        /> Note: simple datatype
            -> Live in IDesc 1
    -> Behind the scene, relies on the special purpose switchD
\end{wstructure}

Note that $\IDesc{\V{I}}$ is a plain inductive type, parametrised
by \(\V{I}\), but indexed trivially.
%
\[\stk{
\IDescD : \PI{\V{I}}{\Set} \IDesc{\Unit} \\
\IDescD\: \V{I} \mapsto \SYMBDSigma \\
\quad
 \EnumT\vtup{r}{\SYMBDVar\\
                \SYMBDConst\\
                \DProd{}{}\\
                \SYMBDSigma\\
                \SYMBDPi}
         \; \vtup{l@{}l}{
  (\DProd{\DConst{\V{I}} &}{\DConst{\Unit}})                  \\
  (\DProd{\DConst{\Set}  &}{\DConst{\Unit}})                  \\
  (\DProd{\DVar{\Void}}{\DProd{\DVar{\Void}&}{\DConst{\Unit}}})  \\
  (\DSigma{\Set}{\LAM{\V{S}}
     \DProd{( \DPi{\V{S}}{\LAM{\_} \DVar{\Void}}) &}{\DConst{\Unit}}})     \\
  (\DSigma{\Set}{\LAM{\V{S}}
     \DProd{( \DPi{\V{S}}{\LAM{\_} \DVar{\Void}}) &}{\DConst{\Unit}}})     \\
                                   }
}\]

Therefore, this universe is self-describing and can be
levitated. As before, we rely on a special purpose $\F{switchID}$
operator to build the finite function $\bigRedBracket{\ldots}$
without mentioning \(\SYMBIDesc\).

\paragraph{Vectors:}

\newcommand{\VecD}{\F{VecD}}
\newcommand{\VecNil}{\etag{\CN{vnil}}}
\newcommand{\SYMBVecCons}{\etag{\CN{vcons}}\xspace}
\newcommand{\VecCons}[2]{\SYMBVecCons\:#1\:#2}

So far, our examples live in $\IDesc{\Unit}$, with no interesting
indexing. Let us at least have vectors. Recall
that the constructors $\VecNil$ and $\SYMBVecCons$ are defined only for
$\NatZero$ and $\NatSuc$ respectively:
%
\[
\stk{
\data \D{Vec}\: \PITEL{\V{X}}{\Set} : \PI{\V{i}}{\Nat} \Set \where \\
\;\;\begin{array}{@{}l@{\::\:\:}l@{\quad}l}
    \VecNil          & \D{Vec}\:\V{X}\:{\NatZero}   \\
    \SYMBVecCons & _{\PI{\V{n}}{\Nat}}\V{X} \To \D{Vec}\:{\V{X}}\:{\V{n}} \To \D{Vec}\:{\V{X}}\:{(\NatSuc{\V{n}})}
\end{array}
}
\]

One way to code constrained datatypes is to appeal to a suitable
notion of propositional equality \(\PropEq\) on indices. The
constraints are expressed as `Henry Ford' equations in the datatype.
For vectors:
%
\[\stk{
\VecD : \Set \To \Nat \To \IDesc{\Nat} \\
\VecD\: \V{X}\: \V{i} \mapsto \SYMBDSigma\\
\quad
\EnumT{\vtup{r}{\VecNil\\ \SYMBVecCons}}
\; \vtup{r}{
                            (\DConst{(\NatZero\PropEq\V{i})}) \\
 ( \DSigma{\Nat}{\LAM{\V{n}}
   \DProd{\DConst{\V{X}}}
     {\DProd{\DVar{\V{n}}}{\DConst{(\NatSuc{\V{n}}\PropEq\V{i})}})}}
                          }
}\]

You may choose $\VecNil$ for any index you like as long as it is
$\NatZero$; in the $\SYMBVecCons$ case, the length of the tail is
given explicitly, and the index $\V{i}$ must be one more. Our previous
\(\Unit\)-terminated tuple types can now be seen as the trivial case
of constraint-terminated tuple types, with elaboration supplying the
witnesses when trivial.

In this paper, we remain anxiously agnostic about
propositional equality. Any will do, according to
conviction; many variations are popular. The
homogeneous identity type used in Coq is ill-suited to
dependent types, but its heterogeneous variant (forming equations
regardless of type) allows the translation of pattern
matching with structural recursion to
\(\F{indI}\)~\cite{goguen:pattern-matching}. The
extensional equality of \citet{altenkirch:ott} also sustains the translation.

\begin{wstructure}
!!! Need Help !!!
<- Brady optimisation: forcing
    <- Source to source translation
    <- Able to remove some constraints
    -> Example: Fin [figure]
    ??? More technical detail needed
\end{wstructure}

However, sometimes, the equations are redundant.
Looking back at $\D{Vec}$, we find that the equations constrain
the choice of constructor and stored tail index retrospectively.
But \emph{inductive families need not store their
  indices}~\cite{brady:index-inductive-families}!  If we
analyse the incoming index, we can tidy our description of $\D{Vec}$
as follows:
%
\[\stk{
\VecD \:\PITEL{\V{X}}{\Set} : \Nat \To \IDesc{\Nat} \\
\begin{array}{@{}lll}
\VecD\:\V{X}\: \NatZero     & \mapsto & \DConst{\Unit} \\
\VecD\:\V{X}\: (\NatSuc{\V{n}}) & \mapsto &
 \DProd{\DConst{\V{X}}}{\DVar{\V{n}}}
\end{array}

}\]
%
The constructors and equations have simply disappeared. A similar
example is $\SYMBFin$ (bounded numbers), specified by:
%
\[
\stk{
\data \SYMBFin : \PI{\V{n}}{\Nat} \Set \where \\
\;\;\begin{array}{@{}l@{\::\:\:}l@{\quad}l}
    \FinZero      & _{\PI{\V{n}}{\Nat}}\Fin{(\NatSuc{\V{n}})}   \\
    \SYMBFinSuc   & _{\PI{\V{n}}{\Nat}}\Fin{\V{n}} \To \Fin{(\NatSuc{\V{n}})}
\end{array}
}\]
%
In this case, we can eliminate equations but not constructors, since both
$\FinZero$ and $\SYMBFinSuc$ both target $\SYMBNatSuc$:
%
\[\stk{
\FinD : \Nat \To \IDesc{\Nat} \\
\begin{array}{@{}lll}
\FinD\: \NatZero         & \mapsto & \DSigma{\EnumT{\Void}}{\Void} \\
\FinD\: (\NatSuc{\V{n}}) & \mapsto & \DSigma{\EnumT{\sqr{\FinZero\: \SYMBFinSuc}}}
                                            {\sqr{(\DConst{\Unit})\: (\DVar{\V{n}})}}
\end{array}
}\]

This technique of extracting information by case analysis on indices
applies to descriptions exactly where Brady's `forcing' and
`detagging' optimisations apply in compilation. They eliminate just
those constructors, indices and constraints which are redundant even
in \emph{open} computation. In \emph{closed} computation, where proofs
can be trusted, all constraints are dropped.

\paragraph{Tagged indexed descriptions:}

\newcommand{\SYMBmuide}{\D{\({\mu}^{\!+}\)}\xspace}
\newcommand{\muide}[2]{\SYMBmuide\!\!_{#1}\:#2}

Let us reflect this index analysis technique.
We can divide a description of tagged indexed data in two: first, the
constructors that do not depend on the index; then, the constructors
that do. The non-dependent part mirrors the definition for non-indexed
descriptions. The index-dependent part simply indexes the choice of
constructors by $\V{I}$. Hence, by inspecting the index, it is
possible to vary the `menu' of constructors.
%
\[
\begin{array}{@{}l@{\:\mapsto\:\:}l}
 \TagIDesc{\V{I}}  & \TIMES{\ATagIDesc{\V{I}}}{\ITagIDesc{\V{I}}} \\
 \ATagIDesc{\V{I}} & \SIGMA{\V{E}}{\EnumU} \PI{\V{i}}{\V{I}} \spi{\V{E}}{\LAM{\_} \IDesc{\V{I}}} \\
 \ITagIDesc{\V{I}} &
     \SIGMA{\V{F}}{\V{I} \To \EnumU} \PI{\V{i}}{\V{I}} \spi{(\V{F}\: \V{i})}{\LAM{\_} \IDesc{\V{I}}}
\end{array}
\]

\begin{wstructure}
<- Vectors
    Do we treat them in the end?
    What can we say here we haven't with Fin?
\end{wstructure}

In the case of a tagged $\D{Vec}$, for instance, for the index
$\NatZero$, we would only propose the constructor
$\ListNil$. Similarly, for $\NatSuc{n}$, we would only propose the
constructor $\SYMBListCons$.

We write $\toIDesc{\V{D}}\:\V{i}$ to denote the $\IDesc{\V{I}}$
computed from the tagged indexed description $\V{D}$ at index
$\V{i}$. Its expansion is similar to the definition of \(\SYMBtoDesc\)
for tagged descriptions, except that it must also append the two parts.
We again write $\muide{\V{I}}{\V{D}}$ for
$\IMu{\V{I}}{(\toIDesc{\V{D}})}$.

\paragraph{Typed expressions:}

\begin{wstructure}
<- Hutton's razor
    <- Types
        <- 'Nat
        <- 'Bool
    <- Term [figure]
        <- val : Val 'a -> 'a  for Val : Ty -> Set, mapping to Nat and Bool
        <- cond : 'Bool -> a -> a -> a
        <- plus : 'Nat -> 'Nat -> 'Nat
        <- le : 'Nat -> 'Nat -> 'Bool
\end{wstructure}

%% Types
\newcommand{\Ty}{\D{Ty}}
\newcommand{\Ebool}{\etag{\CN{bool}}}
\newcommand{\Enat}{\etag{\CN{nat}}}

%% Constructors
\newcommand{\SYMBEval}{\etag{\CN{val}}\xspace}
\newcommand{\SYMBEvar}{\etag{\CN{var}}\xspace}
\newcommand{\Eval}[1]{\SYMBEval\:#1}
\newcommand{\SYMBEcond}{\etag{\CN{cond}}\xspace}
\newcommand{\Econd}[3]{\SYMBEcond\:#1\:#2\:#3}
\newcommand{\SYMBEplus}{\etag{\CN{plus}}\xspace}
\newcommand{\Eplus}[2]{\SYMBEplus\:#1\:#2}
\newcommand{\SYMBEle}{\etag{\CN{le}}\xspace}
\newcommand{\Ele}[2]{\SYMBEle\:#1\:#2}

%% Index mapper (terminology?)
\newcommand{\SYMBVal}{\F{Val}\xspace}
\newcommand{\Val}[1]{\SYMBVal\:#1}
\newcommand{\SYMBVar}{\F{Var}\xspace}
\newcommand{\Var}[2]{\SYMBVar\: #1\: #2}

%% Hutton expressions
\newcommand{\HExprD}{\F{ExprD}}
\newcommand{\HExprAD}{\F{ExprAD}}
\newcommand{\HExprID}{\F{ExprID}}
\newcommand{\HExprVarD}[1]{\C{ExprD}_{\F{Var},#1}}
\newcommand{\HExprFreeD}{\C{ExprD}^{\C{Free}}}
\newcommand{\HExprAFreeD}{\C{ExprAD}^{\C{Free}}}

We are going to define a syntax for a small language with
two types, natural numbers and booleans:
%
\[
\Ty \mapsto \EnumT{\sqr{\Enat\: \Ebool}}
\]

\newcommand{\plusHost}{\mathop{\green{+_{\mathrm{H}}}}}
\newcommand{\leHost}{\mathop{\green{\leq_{\mathrm{H}}}}}

This language has values, conditional expression, addition and
comparison. Informally, their types are:
%
\[
\begin{array}{l@{\::\:\:}l}
\SYMBEval            & \Val{\V{ty}} \To \V{ty} \\
\SYMBEcond           & \Ebool \To \V{ty} \To \V{ty} \To \V{ty}  \\
\end{array}
\qquad
\begin{array}{l@{\::\:\:}l}
\SYMBEplus           & \Enat \To \Enat \To \Enat                           \\
\SYMBEle             & \Enat \To \Enat \To \Ebool                          \\
\end{array}
\]
%
The function $\SYMBVal$ interprets object language types in the
host language, so that arguments to $\SYMBEval$ fit their
expected type.
%
\[\stk{
\SYMBVal : \Ty \To \Set \\
\begin{array}{@{}l@{\:\mapsto\:\:}l}
\Val{\Enat}   & \Nat \\
\Val{\Ebool}  & \Bool
\end{array}
}\]
%
We take $\Nat$ and $\Bool$ to represent natural numbers and Booleans
in the host language, equipped with addition $\plusHost$ and
comparison $\leHost$.

We express our syntax as a tagged indexed description, indexing over
object language types $\Ty$. We note that some constructors are always
available, namely $\SYMBEval$ and $\SYMBEcond$. On the other hand,
$\SYMBEplus$ and $\SYMBEle$ constructors are index-dependent, with
$\SYMBEplus$ available just when building a $\Enat$, $\SYMBEle$ just
for $\Ebool$. The code, below, reflects this intuition, with the first
component uniformly offering $\SYMBEval$ and $\SYMBEcond$, the second
selectively offering $\SYMBEplus$ or $\SYMBEle$.
%
%%% \begin{figure}
%
\[\stk{
\stk{
\HExprD : \TagIDesc{\Ty} \\
\HExprD \mapsto \sqr{ \HExprAD , \HExprID } \\
} \smallskip\\
\stk{
\HExprAD : \ATagIDesc{\Ty} \\
\HExprAD \mapsto \vtup{l}{
   {\vtup{r}{\SYMBEval\\ \SYMBEcond \,}} \red{,} \;
      \LAM{\V{ty}}
      \vtup{l@{\:}l}{
      \DProd{\DConst{(\Val{\V{ty}})}&}{\DConst{\Unit}} \\
      \DProd{\DProd{\DVar{\Ebool}}{\DProd{\DVar{\V{ty}}}{\DVar{\V{ty}}}}&}
        {\DConst{\Unit}} \\
     }
   }
\smallskip\\
}
\\
\stk{
\HExprID : \ITagIDesc{\Ty} \\
\HExprID \mapsto \vtup{l}{
                   \vtup{r}{\sqr{\SYMBEplus} \\ \sqr{\SYMBEle}} \red{,} \;
  \LAM{\_} \sqr{\DProd{\DProd{\DVar{\Enat}}{\DVar{\Enat}}}{\DConst{\Unit}}}
                   }
}
}\]

%%%\caption{Syntax of typed expressions}
%%%\label{fig:hexpr-full}

%%%\end{figure}

\newcommand{\evalH}{\F{eval}_{\green{\Downarrow}}}
\newcommand{\evalOne}{\F{eval}_{\green{\downarrow}}}

Given the syntax, let us supply the semantics. We implement an
evaluator as a catamorphism:
%
\[\stk{
\evalH : \PI{\V{ty}}{\Ty}
         \muide{\Ty}{\HExprD}\: \V{ty} \To
         \Val{\V{ty}} \\
\evalH\: \V{ty}\: \V{term} \mapsto \cataI_{\Ty} \:
                                 (\toIDesc{\HExprD})\:
                                 \SYMBVal\:
                                 \evalOne\:
                                 \V{ty}\:
                                 \V{term}
}\]
%
To finish the job, we must supply the algebra which implements a single
step of evaluation, given subexpressions evaluated already.
%
\[\stk{
\evalOne : \PI{\V{ty}}{\Ty}
 \idescop{(\toIDesc{\HExprD})\:\V{ty}}{\Ty}{\SYMBVal}
           \To {\Val{\V{ty}}} \\
\begin{array}{@{}l@{}c@{}l@{\:\mapsto\:\:}l}
\evalOne\: & \_\: & (\SYMBEval\;\V{x})                                            & \V{x} \\
\evalOne\: & \_\: & (\SYMBEcond\:\BoolTrue\:\V{x}\:\_)   & \V{x} \\
\evalOne\: & \_\: & (\SYMBEcond\:\BoolFalse\:\_\:\V{y})  & \V{y} \\
\evalOne\: & \Enat\: & (\SYMBEplus\:\V{x}\:\V{y})   & \V{x} \plusHost \V{y} \\
\evalOne\: & \Ebool\: & (\SYMBEle\:\V{x}\:\V{y})  & \V{x} \leHost \V{y}
\end{array}
}\]

\begin{wstructure}
    /> Closed term
        <- only constants and operations on them
        -> Extend Val with Var : Ty -> Set, mapping to EnumU
            -> Open term
            -> Language of well-typed terms
                <- By construction
\end{wstructure}

Hence, we have a type-safe syntax and a tagless interpreter for our
language, in the spirit
of~\citet{augustsson.carlsson:dependent.interpreter}, with help from
the generic catamorphism. However, so far, we are only able to define
and manipulate \emph{closed} terms. Adding variables, it is possible
to build and manipulate \emph{open} terms, that is, terms in a
context. We shall get this representation, for free, thanks to the
\emph{free indexed monad} construction.

\subsection{Free indexed monad}

\begin{wstructure}
<- Variation on a theme: free imonad construction
    <- Recall existence of generic free monad construction
    -> Present its generalisation to IDesc [equation]
        <- \I -> IDesc I as describing an indexed endofunctor
        <- Free monad construction
    -> Still a suitable, generic notion of substitution
        <- show type signature
        <- show implementation?? (space! space!)
\end{wstructure}

In Section~\ref{sec:desc-free-monad}, we have built a free monad
operation for simple descriptions. The process is similar in the
indexed world. Namely, given an indexed functor, we derive the indexed
functor coding its free monad: \note{pwm: Whoa there. Maybe we should
  say something about IMonads in general before we get to this point?}
%
\[\stk{
\begin{array}{ll}
\FreeIMonad{\_}{} : & _{\PI{\V{I}}{\Set}}
                     \PITEL{\V{R}}{\TagIDesc{\V{I}}}
                     \PITEL{\V{X}}{\V{I} \To \Set}\To
                      \TagIDesc{\V{I}}
\end{array} \\
\FreeIMonad{\pair{\V{E}}{\V{F}}{}}{\V{I}}{\V{R}} \mapsto
    \pair{\pair{\ListCons{\SYMBDVar}{(\fst{\V{E}})}}
               {\LAM{\V{i}}
                \pair{\DConst{(\V{R}\: \V{i})}}
                     {(\snd{\V{E}})\: \V{i}}{}}{}}
         {\V{F}}{}
}\]

\newcommand{\substI}{\F{substI}}

Just as in the universe of descriptions, this construction comes with
an obvious \return and a substitution operation, the \bind. Its
definition is the following:
%
\[\stk{
\begin{array}{@{}ll}
\substI : & _{\PI{\V{I}}{\Set}}
            \PI{\V{X}, \V{Y}}{\V{I} \To \Set}
            \PITEL{\V{R}}{\TagIDesc{\V{I}}} \\
          & (\V{X} \DotTo
             \muide{\V{I}}{(\FreeIMonad{\V{R}}{\V{I}}{\V{Y}})}) \To
             \muide{\V{I}}{(\FreeIMonad{\V{R}}{\V{I}}{\V{X}})} \DotTo
             \muide{\V{I}}{(\FreeIMonad{\V{R}}{\V{I}}{\V{Y}})}
\end{array} \\
\substI\: \V{X}\: \V{Y}\: \V{R}\: \V{\sigma}\: \V{i}\: \V{t} \mapsto \\
\qquad    \cataI_{\V{I}}\: (\toIDesc{\FreeIMonad{\V{R}}{}{\V{X}}})\:
                      (\muide{\V{Y}}{(\FreeIMonad{\V{R}}{}{\V{Y}})})\:
                      (\F{applyI}\: \V{R}\: \V{X}\: \V{Y}\: \V{\sigma})\:
                      \V{i}\:
                      \V{t}
}\]
%
where  $\F{applyI}$ is defined as follows:
%
\[\stk{
\begin{array}{@{}ll}
\F{applyI} : & _{\PI{\V{I}}{\Set}}
            \PITEL{\V{R}}{\TagIDesc{\V{I}}}
            \PI{\V{X}, \V{Y}}{\V{I} \To \Set} \\
          & (\V{X} \DotTo \muide{\V{I}}{(\FreeIMonad{\V{R}}{\V{I}}{\V{Y}})}{}) \To \\
          & \idescop{\toIDesc{\FreeIMonad{\V{R}}
                                         {\V{I}}
                                         {\V{X}}}}
                    {\V{I}}
                    {\muide{\V{I}}{(\FreeIMonad{\V{R}}{\V{I}}{\V{Y}})}} \DotTo
            \muide{\V{I}}{(\FreeIMonad{\V{R}}{\V{I}}{\V{Y}})}{}
\end{array} \\
\begin{array}{@{}l@{\:\mapsto\:\:}l}
\F{applyI}\: \V{R}\: \V{X}\: \V{Y}\: \V{\sigma}\: \V{i}\: \pair{\SYMBDVar}{\V{x}}{}   & \V{\sigma}\: \V{i}\: \V{x}                   \\
\F{applyI}\: \V{R}\: \V{X}\: \V{Y}\: \V{\sigma}\: \V{i}\: \pair{\V{c}}{\V{ys}}{} & \Con{\pair{\V{c}}{\V{ys}}{}}
\end{array}
}\]

The subscripted types corresponds to implicit arguments that can be
automatically inferred, hence do not have to be typed in. Let us now
consider two examples of free indexed monads.

\paragraph{Typed expressions:}

\begin{wstructure}
    /> Closed term
        <- only constants and operations on them
        -> Extend Val with Var : Ty -> Set, mapping to EnumU
            -> Open term
            -> Language of well-typed terms
                <- By construction
\end{wstructure}

\newcommand{\Ctxt}{\D{Context}}
\newcommand{\SYMBCtxtEmpty}{\C{[]}\xspace}
\newcommand{\CtxtEmpty}{\SYMBCtxtEmpty}
\newcommand{\SYMBCtxtSnoc}{\C{snoc}\xspace}
\newcommand{\CtxtSnoc}[2]{\SYMBCtxtSnoc\:#1\:#2}
\newcommand{\SYMBEnv}{\F{Env}}
\newcommand{\Env}[1]{\SYMBEnv\: #1}
\newcommand{\SYMBlookup}{\F{lookup}}
\newcommand{\lookup}[4]{\SYMBlookup\: #1\: #2\: #3\: #4}

In the previous section, we presented a language of closed
arithmetic expressions. Using the free monad construction, we are
going to extend this construction to open terms. An open term is
defined with respect to a context, represented by a snoc-list of
types:
%
\[
\begin{array}{@{}l@{\::\:\:}l@{\quad}l}
\Ctxt           & \Set \\
\SYMBCtxtEmpty  & \Ctxt \\
\SYMBCtxtSnoc   & \Ctxt \To \Ty \To \Ctxt
\end{array}
\]
%
An environment realises the context, packing a value for each type:
%
\[
\stk{
\SYMBEnv : \Ctxt \To \Set \\
\begin{array}{@{}l@{\:\:\mapsto\:\:}l}
\Env{\CtxtEmpty}                & \Unit \\
\Env{(\CtxtSnoc{\V{G}}{\V{S}})} & \TIMES{\Env{\V{G}}}{\Val{\V{S}}}
\end{array}
}\]
%
In this setting, we define type variables, $\SYMBVar$ by:
%
\[\stk{
\Var{}{} : \Ctxt \To \Ty \To \Set \\
\begin{array}{@{}ll@{\:\:\mapsto\:\:}l}
\Var{\CtxtEmpty}{& \V{T}}                &
    \Void \\
\Var{(\CtxtSnoc{\V{G}}{\V{S}})}{& \V{T}} &
    \SUM{(\Var{\V{G}}{\V{T}})}{(\V{S} \PropEq \V{T})}
\end{array}
}\]
%
While $\SYMBVal$ maps the type to the corresponding host type,
$\SYMBVar$ indexes a value in the context, obtaining a proof that the
types match. The $\SYMBlookup$ function precisely follow this
semantics:
%
\[\stk{
\SYMBlookup : \PI{\V{G}}{\Ctxt}
          \Env{\V{G}} \To
          \PI{\V{T}}{\Ty}
          \Var{\V{G}}{\V{T}} \To
          \Val{\V{T}} \\
\begin{array}{@{}l@{}l@{}l@{}l@{}lll}
\lookup{& (\CtxtSnoc{\V{G}}{.T})}{& \pair{\V{g}}{\V{t}}{}}{& \V{T}}{& (\SumRight{\C{refl}})} & \mapsto & \V{t} \\
\lookup{& (\CtxtSnoc{\V{G}}{\V{S}})}{& \pair{\V{g}}{\V{t}}{}}{& \V{T}}{& (\SumLeft{\V{x}})} & \mapsto & \lookup{\V{G}}{\V{g}}{\V{T}}{\V{x}}
\end{array}
}\]

\newcommand{\SYMBEmpty}{\F{Empty}\xspace}
\newcommand{\Empty}[1]{\SYMBEmpty\:#1}

\newcommand{\SYMBopenTerm}{\F{openTm}\xspace}
\newcommand{\openTerm}[1]{\SYMBopenTerm\: #1}
\newcommand{\closeTerm}{\F{closeTm}}

\newcommand{\update}{\F{update}}

Consequently, taking the free monad of \(\HExprD\) by \(\SYMBVar\:
\V{G}\), we obtain the language of open terms in a context \(\V{G}\):
%
\[
\openTerm{\V{G}} \mapsto \FreeIMonad{\HExprD}{\Ty}{(\SYMBVar\:\V{G})}
\]
%
In this setting, the language of closed terms corresponds to the free
monad assigning an empty set of values to variables
%
\[
\closeTerm \mapsto \FreeIMonad{\HExprD}{\Ty}{\SYMBEmpty}
\quad
\mbox{where}
\quad
\stk{
\SYMBEmpty : \Ty \To \Set \\
\begin{array}{@{}l@{\:\:\mapsto\:\:}l}
\Empty{\_}   & \Zero \\
\end{array}
}\]
%
Allowing variables from an empty set is much like forbidding variables,
so \(\closeTerm\) and \(\HExprD\) describe isomorphic
datatypes. Correspondingly, you can update an old \(\HExprD\) to a shiny
\(\closeTerm\):
%
\[\stk{
\update : \muide{\Ty}{\HExprD} \DotTo \muide{\Ty}{\closeTerm} \\
\begin{array}{@{}l@{}l}
\update\: \V{ty}\: \V{tm} \mapsto \cataI_{\Ty}\: & (\toIDesc{\HExprD})\:
                                                  (\muide{\Ty}{\closeTerm})\: \\
                                                & (\LAM{\_} \LAM{\pair{\V{tag}}{\V{tm}}{}} \Con{\pair{\Su{\V{tag}}}{\V{tm}}{}})\:
                                                  \V{ty}\:
                                                  \V{tm}
\end{array}
}\]
%
The other direction of the isomorphism is straightforward, the
$\SYMBDVar$ case being impossible. Therefore, we are entitled to
reuse the $\evalH$ function to define the semantics of $\closeTerm$.

\newcommand{\discharge}{\F{discharge}}

Now we would like to give a semantics to the open term language. We
proceed in two steps: first, we substitute variables by their value in
the context; then, we evaluate the resulting closed term. Thanks to
$\evalH$, the second problem is already solved. Let us focus on
substituting variables from the context. Again, we can subdivide this
problem: first, discharging a single variable from the context; then,
applying this $\discharge$ function on every variables in the term.

The $\discharge$ function is relative to the required type and a
context of the right type. Its action is to map values to themselves,
and variables to their value in context. This corresponds to the
following function:
%
\[\stk{
\begin{array}{@{}ll}
\discharge : & \PI{\V{G}}{\Ctxt}
               \Env{\V{G}} \To
               \Var{\V{G}}{} \DotTo
               \muide{\Ty}{\closeTerm}
\end{array} \\
\begin{array}{@{}l@{\:\mapsto\:\:}l}
\discharge\: \V{G}\: \V{g}\: \V{ty}\: \V{v} &
    \Con{\pair{\SYMBEval}{\lookup{\V{G}}{\V{g}}{\V{ty}}{\V{v}}}{}}
\end{array}
}\]

\begin{wstructure}
            /> Then, perform subst everywhere in the term
                -> Show type [code]
                /> This is a bind!?
                -> There is some more structure
                    -> We should try to get it
\end{wstructure}

\newcommand{\substH}{\F{substExpr}}

We are now left with applying $\discharge$ over all variables of the
term.  We simply have to fill in the right arguments to $\substI$, the
type guiding us:
%
\[
\stk{
\begin{array}{@{}ll}
\substH  : & \PI{\V{G}}{\Ctxt} \\
           & (\Var{\V{G}}{} \DotTo
              \muide{\Ty}{\closeTerm}) \DotTo \\
          & \muide{\Ty}{(\openTerm{\V{G}})} \DotTo
            \muide{\Ty}{\closeTerm}
\end{array} \\
\substH\: \V{G}\:
          \V{ty}\:
          \V{g}\:
          \V{\sigma}\:
          \V{tm} \mapsto
\substI_{\Ty}\:
               (\SYMBVar\: \V{G})\:
               \SYMBEmpty\:
               \HExprD\:
               \V{\sigma}\:
               \V{ty}\:
               \V{tm}
}\]

Hence completing our implementation of the open terms
interpreter. Without much effort, we have described the syntax of a
well-typed language, together with its semantics.

\paragraph{Indexed descriptions:}

An interesting instance of free monad is $\SYMBIDesc$ itself. Indeed,
$\SYMBDVar$ is nothing but the \return. The remaining constructors form
the carrier functor, trivially indexed by $\Unit$. The signature functor
is described as follow:
%
\[\stk{
\IDescFreeD : \ATagIDesc{\Unit} \\
\begin{array}{@{}ll}
\IDescFreeD \mapsto \bigRedBracket{\begin{array}{l}
                                \sqr{\SYMBDConst\:\:
                                     \DProd\:\:
                                     \SYMBDSigma\:\:
                                     \SYMBDPi} \red{,}\\
                                  \LAM{\_}\bigRedBracket{\begin{array}{l}
                                        \DConst{\Set}               \\
                                        \DProd{\DVar{\Void}}{\DVar{\Void}}  \\
                                        \DSigma{\Set}{(\LAM{\V{S}} \DPi{\V{S}}{(\LAM{\_} \DVar{\Void})})} \\
                                        \DSigma{\Set}{(\LAM{\V{S}} \DPi{\V{S}}{(\LAM{\_} \DVar{\Void})})}
                                    \end{array}}\end{array}}
\end{array}
}\]
%
We get $\IDesc{\V{I}}$ by extending the signature with variables from \(\V{I}\):
%
\[\stk{
\IDescD : \PI{\V{I}}{\Set} \TagIDesc{\Unit} \\
\IDescD\: \V{I} \mapsto \FreeIMonad{\red{[}\IDescFreeD\red{,[}\LAM{\_}\sqr{}\red{,}\LAM{\_}\red{[]]]}}{\Unit}\LAM{\_}\V{I}
}\]

The fact that indexed descriptions are closed under substitution
is potentially of considerable utility, if we can exploit this fact:
\[
\idescop{\V{\sigma} \V{D}}{\V{J}}{\V{X}}
    \mapsto
        \idescop{\V{D}}
                {\V{I}}
                {\LAM{\V{i}}
                     {\idescop{\V{\sigma} \V{i}}
                              {\V{J}}
                              {\V{X}}}}
        \quad \mbox{where}\;\V{\sigma}:\V{I}\To\IDesc{\V{J}}
\]
By observing that a description can be decomposed via substitution, we
split its meaning into a superstructure of substructures, e.g. a
`database containing salaries', ready for traversal operations
preserving the former and targeting the latter.

%\newpage


\subsection{\texttt{smooth\_box.py}}\label{geocode:smooth_box}

\begin{verbatim}
# --- geometry setup script for block with smooth sides ---
from gengeo import *

# - input parameters --
# block dimensions
xdim=10
ydim=20
zdim=10

# particle size range
minRadius = 0.2
maxRadius = 1.0
# ---------------------

# corner points
minPoint = Vector3(0.0,0.0,0.0)
maxPoint = Vector3(xdim,ydim,zdim)

# neighbour table
mntable = MNTable3D(minPoint,maxPoint,2.5*maxRadius,1)

# block volume
box = BoxWithPlanes3D(minPoint,maxPoint)

# boundary planes
bottomPlane=Plane(minPoint,Vector3(0.0,1.0,0.0))
leftPlane=Plane(minPoint,Vector3(1.0,0.0,0.0))
frontPlane=Plane(minPoint,Vector3(0.0,0.0,1.0))
topPlane=Plane(maxPoint,Vector3(0.0,-1.0,0.0))
rightPlane=Plane(maxPoint,Vector3(-1.0,0.0,0.0))
backPlane=Plane(maxPoint,Vector3(0.0,0.0,-1.0))

# add them to the box
box.addPlane(bottomPlane)
box.addPlane(leftPlane)
box.addPlane(frontPlane)
box.addPlane(topPlane)
box.addPlane(rightPlane)
box.addPlane(backPlane)

# -- setup packer --
# iteration parameters
insertFails = 1000
maxIter = 1000
tol = 1.0e-6

# packer
packer = InsertGenerator3D( minRadius,maxRadius,insertFails,maxIter,tol,False)

# pack particles into volume
packer.generatePacking(box,mntable,0,1)

# create bonds between neighbouring particles:
mntable.generateBonds(0,1.0e-5,0)

# calculate and print the porosity:
volume = xdim*ydim*zdim
porosity = (volume - mntable.getSumVolume(groupID=0))/volume
print "Porosity:  ", porosity

# write a geometry file
mntable.write("smooth_box.geo", 1)
mntable.write("smooth_box.vtu", 2)
\end{verbatim}


\subsubsection*{Two-dimensional plane strain problem}
% A two-dimensional rectangular plate made of the compressible hyperelastic neo-Hookean material is considered here in the plane strain case.
% Unlike for the Saint-Venant-Kirchhoff model, the polyconvexity of the neo-Hookean stored energy function ensures the hyperbolicity of the problem (see section \ref{sec:constitutive-equations}).
%Geometry, boundary and loading conditions are given in figure \ref{fig:2d_heDomain}.
% \begin{figure}[h!]
%   \centering
%   \input{chapter4/pgfFigures/2d_heDomain}
%   \caption{Geometry, boundary and loading conditions of the two-dimensional problem in plane strain with a hyperelastic neo-Hookean material.}
%   \label{fig:2d_heDomain}
% \end{figure}
The plane strain problem studied in sections \ref{subsec:el_planestrain} and \ref{subsec:ep_planestrain} is now considered in a compressible hyperelastic neo-Hookean material submitted to an imposed velocity $v_1=-1000 \: m/s$ on the bottom part of its left end.
The solid is discretized such that material points are equivalent to $Q1$-finite element nodes.
Thus, the plate is represented with $l \times h \equiv 28 \times 28$ material points, only with the 1ppc configuration.
The finite element computation is performed with the software \textit{Abaqus} \cite{Abaqus} using an explicit time discretization with no artificial viscosity added.
These numerical results are compared to those obtained from MPM and DGMPM using CTU computations.
The Courant number is set to unity in DGMPM and to $0.5$ in MPM leading to \textit{average} time steps $\Delta t_{CTU}=1.41 \times 10^{-5}s$ and $\Delta t_{MPM}=6.13 \times 10^{-6}s$, whereas the \textit{constant} time step used in the FEM simulation is $\Delta t_{FEM}=1.27 \times 10^{-5} s$.
Figure \ref{fig:2dhe_stress} shows numerical results in terms of the Cauchy stress tensor isovalues exported from Abaqus to the software Paraview \cite{Paraview} with the code developed in \cite{Export_Abaqus}, particularized to the present two-dimensional plane strain case.
Cauchy stress is plotted on the current configuration in such a way that figure \ref{fig:2dhe_stress} also enables the comparison of the deformed shape of the body.
\begin{figure}[h!]
  \centering
  \input{chapter4/pgfFigures/2Dhestress}
  \caption{Isovalues of Cauchy stress tensor component $\sigma_{11}$ in a two-dimensional plate made of a neo-Hookean material, submitted to a velocity $\vect{v}\cdot\vect{e}_1=-1000 \: m/s$ on a part of its left end.}
  \label{fig:2dhe_stress}
\end{figure}
\begin{figure}[h!]
  \centering
  \input{chapter4/pgfFigures/linePlotshyp_stress}
  %\input{chapter4/pgfFigures/linePlotshyp_velo}
  \caption{Evolution of longitudinal Cauchy stress $\sigma_{11}$ along the bottom boundary of the domain.}
  \label{fig:he_lineplots_stress}
\end{figure}
At the beginning of the computation (first row in figure \ref{fig:2dhe_stress}), stress profiles are quite similar despite slight oscillations visible in FEM and MPM solutions.
This can also be seen in figure \ref{fig:he_lineplots_stress}, in which stress is plotted along the bottom boundary of the domain.
However, the MPM solution exhibits, as for small strain problems, a concentration of stress in the high gradients region on the left boundary.
%It is worth noticing that the DGMPM shows the same behavior that cannot be seen here due to the attenuation introduced by MPM stress values which are much higher.
It is worth noticing that the DGMPM shows the same behavior that cannot be seen here due to the MPM stress values which are much higher.
The deformed shapes of the plate resulting from the three numerical approaches hence remain close, except at the junction of the loaded and free zones of the left edge.
When the pressure wave reflects on the fixed boundary at time $t=5.0\times 10^{-4}\:s$ (second row in figures \ref{fig:2dhe_stress} and \ref{fig:2dhe_velo}), the stress profiles are still similar, though FEM and MPM solutions oscillate even more.
These spurious oscillations are more significant in the velocity fields depicted in figure \ref{fig:2dhe_velo} as well as in figures \ref{fig:he_lineplots_stress} and \ref{fig:he_lineplots_velo} which depict the velocity along the bottom boundary.
Furthermore, one can see in figure \ref{fig:he_lineplots_velo}\subref{subfig:he_velo2} that the homogeneous Dirichlet boundary condition is not exactly enforced in DGMPM when the incident wave hits the right end.
\begin{figure}[h!]
  \centering
  \input{chapter4/pgfFigures/2Dhevelo}
  \caption{Isovalues of velocity component $v_1$ in a two-dimensional plate made of a neo-Hookean material, submitted to a velocity $\vect{v}\cdot\vect{e}_1=-1000 \: m/s$ on a part of its left end.}
  \label{fig:2dhe_velo}
\end{figure}
\begin{figure}[h!]
  \centering
  {\phantomsubcaption \label{subfig:he_velo1}}
  {\phantomsubcaption \label{subfig:he_velo2}}
  {\phantomsubcaption \label{subfig:he_velo3}}
  \input{chapter4/pgfFigures/linePlotshyp_velo}
  \caption{Evolution of horizontal velocity $v_1$ along the bottom boundary of the domain.}
  \label{fig:he_lineplots_velo}
\end{figure}
This can be explained by considering a boundary cell of the arbitrary grid (\textit{i.e. containing one material point that belongs to the right end of the domain}) that is about to be reached by the wave through the upwind interface.
The intercell flux on the upwind interface resulting from the discontinuity, and subsequently the conserved quantities vector resulting from the solution of the discrete system on the grid, are non-zero.
In particular, the horizontal velocity at upwind nodes of the boundary cell does not vanish while that of the downwind edge satisfies the homogeneous Dirichlet condition.
Hence, the interpolation of the velocity from nodes to the particle yields a non-zero field at the material point level.
Note that this holds for the MPM as well in which the enforcement of boundary conditions is still a challenging question \cite{BC_MPM}.

Nevertheless, no significant displacements of particles can be seen on the right end in MPM and DGMPM solutions in figures \ref{fig:2dhe_stress} and \ref{fig:2dhe_velo}.
At last, oscillations remain in FEM and MPM solutions until the end of the simulation.
Since the velocity field depicted in figures \ref{fig:2dhe_velo} and \ref{fig:he_lineplots_velo} is used to update the shape of the solid in FEM, the numerical noise yields final configurations that are slightly different.
On the other hand, updating particle positions with the grid velocity within the MPM allows better results than if the oscillating material point velocity is used.

%%% Local Variables:
%%% mode: latex
%%% ispell-local-dictionary: "american"
%%% TeX-master: "../mainManuscript"
%%% End:


\chapter{Related work}
\label{chapter:related}

\section{An in-depth look to ``Human-level control through deep reinforcement learning'' paper}
This section is dedicated to analyzing the paper which is proposes a method for solving games using deep learning and reinforcement learning. The proposed agent, called Q-Network capable of playing 43 different games and adapting to each one without being modified.

\begin{figure}[h]
	\floatname{algorithm}{Algorithm}
	\begin{center}
		\includegraphics[width=334px,height=51px]{src/img/state/ataripic}
		\caption{Snapshots with five Atari 2600 Games: Pong, Breakout, Space Invaders, Seaquest, Beam Rider\cite{nature}} \label{fig:ataripic}
    \end{center}
\end{figure}

\section{Architecture}
The article\cite{nature} proposes a new type of network, Q-network which combines convolutional layers, a representation of the human receptive fields and pooling layers used for dimensionality reduction. The input layer is represented by \textbf{84x84x4} neurons for the image produced after preprocessing frames from the game and is followed by three convolutional layers(32 filters of 8x8 and stride 4 with ReLU, 64 filters of 4x4 and stride 2 with ReLU, 64 filters of 3x3 and stride 1 with ReLU), two fully connected layers: a hidden layer with 512 units and the output layer which has a number of neurons equal to the number of actions corresponding to each game. Each hidden layer is followed by a rectified linear unit (ReLU).

\begin{figure}[h]
	\floatname{algorithm}{Algorithm}
	\begin{center}
		\includegraphics[width=442px,height=242px]{src/img/state/schematic-ilustration}
		\caption{Q-Network architecture\cite{nature}} \label{fig:arch}
    \end{center}
\end{figure}

The network is used to approximate the optimal action-value function $Q^{*}$\cite{nature}:
\begin{equation}
	Q^{*}(s,a) = \max_\pi E[r_t + \gamma\cdot r_{t+1} + \gamma^2\cdot r_{t+2} + \dotsc | s_t = s, a_t = a, \pi]
\end{equation}
The function Q is also parametrized with the weights and the agent state $e_t = (s_t,a_t,r_t,s_{t+1})$ is saved at each iteration in a set D_t = ${(e_1, e_2, \dotsc, e_t)}$
With all the necessary information here is the computation of the loss function\cite{nature}:

\begin{equation}
	L_i(\theta_i)=E_{(s,a,r,s^{\prime})}[(r + \gamma\cdot\max_{a^{\prime}}\cdot Q(s^{\prime},a^{\prime};{\theta_i}^-) - Q(s,a;\theta_i))^2]
\end{equation}

where $\gamma$ represents the discount factor and ${\theta_i}^-)$ is updated with $\theta_i$ every x defined steps and here is the gradient\cite{nature}:

\begin{equation}
\nabla_{\theta_i}L(\theta_i) = E_{s,a,r,{s^i}}[(r + \gamma\cdot\max_{a^{\prime}}Q(s^\prime, a^\prime;{\theta_i}^-)-Q(s,a;\theta_i))\nabla_{\theta_i}Q(s,a;\theta_i)]
\end{equation}

The Q-learning action-value function can be updates using ${\theta_i}^-$ = $\theta_{i-1}$ following the optimal policy with probability 1 - $\epsilon$ and selecting a random move with probability $\epsilon$.

For minimizing the loss function, Stochastic Gradient Descent is used in combination with the experience replay technique for preventing `dead' neurons and also, Q is not updated at each iteration. This avoids the instability of Q caused by the nonlinearity of network.

The $\epsilon$-greedy policy was set to 0.05 and the Q-values were scaled because of big range values from rewards.
\newpage
\section{Algorithm}

One of the techniques that Q-Network algorithm is using is called experience replay. This implies transitions between states to be stored. A number of N transitions (the previous state, the current state, reward and action) are stored in a pool of transitions. Until the network starts learning, we have to play many episodes. We begin from initializing the pool where we store the experiences and initialize two different networks(action-value network Q and target action-value network $Q^-$) with the same weights. For each episode we start by storing the current transition which at first will be composed by only one state. With probability $\epsilon$ we choose a random action and with probability $1-\epsilon$ we choose the best action. After that, we apply the action on the current state of the game and observe reward and new state of the game. We put it in the pool and randomize it. The target value is the reward if game is finished or the sum between the reward observed and maxim-value predicted by target action-value $Q^-$ multiplied with the discount factor. Then we propagate the error as the mean squared error between target value and action-value function Q. Once \textbf{x} steps had pass we update the weights of $Q^-$ with the weights of Q. The algorithm\cite{atari} used for training Q-Network is presented as it follows:

\begin{algorithm}
	\floatname{algorithm}{Algorithm}
	\caption{Q-Network} \label{sgd-code}
	\begin{algorithmic}[1]
		\State create replay memory D for storing N experiences
		\State choose $\epsilon$ between (0,1)
		\State init Q model weights with $\theta$
		\State save $Q^-$ model weights to $\theta^-$
		\State init variable episode to 0 and choose MAX_EPISODES
		\While{episode < MAX_EPISODES}{
			\State generate state $s_1$ from frame: $s_1$ = {$image_1$}
			\While{game not over}
				\State r = random number between (0,1)
				\If{r < $\epsilon$}
					\State $a_t$ = random action
				\Else
					\State $a_t$ = $argmax_a$ Q($s_t$, a; $\theta$)
				\EndIf

				\State $s_{t+1}$ = ($s_t$,$a_t$,$image_{t+1}$)

				\State D = D + \{($s_t$, $a_t$, $r_t$, $s_{t+1}$)\}

				\State shuffle D

				\State extract ($s_j$, $a_j$, $r_j$, $s_{j+1}$) from D

				\If{episode is finished at step j+1}
					\State $y_j$ = $r_j$
				\Else
					\State $y_j$ = $r_j$ + $\gamma\cdot\max_{a^{\prime}}\cdot {Q^-}(s_{j+1},a^{\prime};\theta^-)$
				\EndIf
				\State propagate error $(y_j - Q(s_j,a_j;\theta))^2$
				\State at each \textbf{x} steps save model weights $\theta$ to $\theta^-$
			\EndWhile
		}\EndWhile

	\end{algorithmic}
\end{algorithm}

\newpage

\section{Results}

Q-Network is capable of learning the optimal policy. For example, in Breakout what is being learned is to make a tunnel between blocks in order to send the ball into the back. Receiving only the pixel from the frames, rewards and using the same network structure it is capable of playing different games. The Q-Network can achieve 75\% of a score of a human test at 49 games\cite{nature}. The games where the algorithm performs poorly are the games where the memory is needed. For example, on Montezuma's Revenge\footnote{\url{https://atariage.com/software_page.php?SoftwareID=1158}} we go from room to another rooms so it is very hard for the algorithm taking into account multiple scenarios changing instead of only one changing. Below there are the results for different types of games from Atari compared to the results of a professional human tester.

\begin{figure}[h]
	\floatname{algorithm}{Algorithm}
	\begin{center}
		\includegraphics[width=367px,height=435px]{src/img/state/comparision}
		\caption{Comparison\cite{nature}} \label{fig:comp}
    \end{center}
\end{figure}


\documentclass[11pt,a4paper,british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{luainputenc}
\pagestyle{plain}
\setcounter{tocdepth}{2}
\usepackage{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{setspace}
\usepackage{microtype}
\onehalfspacing
\usepackage[unicode=true,pdfusetitle,bookmarks=true,bookmarksnumbered=true,bookmarksopen=false,breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=section,colorlinks=false]
 {hyperref}
\makeatletter
\@ifundefined{pageheight}{\let\pageheight\pdfpageheight}{}
\@ifundefined{pagewidth}{\let\pagewidth\pdfpagewidth}{}
\pageheight\paperheight
\pagewidth\paperwidth
\let\SF@@footnote\footnote
\def\footnote{\ifx\protect\@typeset@protect
    \expandafter\SF@@footnote
  \else
    \expandafter\SF@gobble@opt
  \fi
}
\expandafter\def\csname SF@gobble@opt \endcsname{\@ifnextchar[%]
  \SF@gobble@twobracket
  \@gobble
}
\edef\SF@gobble@opt{\noexpand\protect
  \expandafter\noexpand\csname SF@gobble@opt \endcsname}
\def\SF@gobble@twobracket[#1]#2{}

\@ifundefined{date}{}{\date{}}
\AtBeginDocument{
  \def\labelitemi{\(\star\)}
}

\makeatother

\begin{document}
\title{\textbf{\huge{}RSA KEY GENERATION ALGORITHM}}
\author{AGNI DATTA}
\maketitle
\begin{center}
	\rule[0.5ex]{0.5\columnwidth}{0.75pt}
	\par\end{center}

\medskip{}

\subsection{Select two huge primes numbers,}

\quad{}\quad{}\quad{}\quad{}$p\:\text{and}\:q$

\subsection{Calculate,}

\quad{}\quad{}\quad{}\quad{}$n=p\times q$

\subsection{Calculate Euler's Totient\protect\footnote{refer https://en.wikipedia.org/wiki/Euler\%27s\_totient\_function}
	Function,}

\quad{}\quad{}\quad{}\quad{}$\varphi(n)=(p-1)\times(q-1)$

\subsection{Choose the value of e such that,}

\quad{}\quad{}\quad{}\quad{}$d\equiv e^{-1}\bmod\varphi(n)\rightarrow ed\bmod\varphi(n)=1$

\subsection{Public Key Pair,}

\quad{}\quad{}\quad{}\quad{}$\{e,n\}$

\subsection{Private Key Pair,}

\quad{}\quad{}\quad{}\quad{}$\{d,n\}$\\

\vfill{}

\end{document}


\section{Generating Random Trees}
\label{sct_gen}

\gen{} generates clock-like random trees, with exponentially distributed branch
lengths. Nodes are sequentially labeled.

\verbatiminput{gen_1_svg.cmd}
\begin{center}
\includegraphics{gen_1_svg.pdf}
\end{center}

\noindent{}Here I pass option \texttt{-s}, whose argument is the pseudo-random
number generator's seed, so that I get the same tree every time I produce this
document. Normally, you will not use it if you want a different tree every time.
Other options are \texttt{-d}, which specifies the tree's depth, and
\texttt{-l}, which sets the average branch length.

I use random trees to test the other applications, and also as a kind of null
model to test to what extent a real tree departs from the null hypothesis.