\chapter{Hardware}
Hardware plays an important role in making a wireless sensor network low-cost and maintenance free. Designing a custom mote has advantages over using off-the-shelf motes in terms of ease of adding the energy harvesting circuit and the cost.

There are two basic strategies in designing a custom mote. First, the design could use (relatively) high-end integrated circuits, including an energy harvester, boost regulator, buck regulators, etc. The advantage of this approach is that it is easy to use integrated circuits, and the resulting circuits are small. The trade-off of this approach is that integrated circuits are expensive. Second, the design could use basic components, such as resistors, diodes, and capacitors. The advantage of this approach is a reduction in the cost of the device. The basic electronic components are less expensive than integrated circuits, and the resulting Printed Circuit Boards (PCB) are less expensive to produce. The disadvantage of this approach is that the size of the resulting circuit is typically larger. The device described in this thesis offers many of the benefits provided by devices designed using integrated circuits, except for the size. However, given that the size of the circuit is smaller than the size of our target solar panel, the circuit size is not a concern.

The hardware discussed in this thesis is a complete system, ready to be deployed in remote and hostile environments. The device is maintenance free and generates power by harvesting solar energy. The charging circuit is designed using basic electronic components, significantly reducing the cost of the device. The device works in two modes:
\begin{enumerate}
\item Solar Powered:
The device performs two tasks in solar powered mode. First, it supplies power to the circuit. Second, it charges the Li-Ion battery.
\item Battery Powered:
The circuit operates in battery powered mode whenever there is insufficient solar power. The circuit uses power from the Li-Ion battery in this mode.
\end{enumerate}

The device consists of a switching circuit which switches the circuit from solar powered mode to battery powered mode and vice-versa. The mode switches whenever the output power of the solar panel is less than the required value. The most important use of a switching circuit is to prevent power loss.

\begin{figure}[htbp]
\centering
\includegraphics[width=\columnwidth]{block_dia.png}
\caption{Block Diagram of the Mote Platform}
\label{img_blockDia}
\end{figure}

The block diagram of the mote platform as shown in Figure \ref{img_blockDia} is divided into four parts:
\begin{enumerate}
\item Solar power circuit
\item Battery circuit
\item Switching circuit
\item Circuit for processing, transmission, and reception of data
\end{enumerate}

\section{Solar Power Circuit}

\begin{figure}[htbp]
\centering
\includegraphics[width=110mm]{solar_pwr_ckt.PNG}
\caption{Solar Power Circuit}
\label{img_solarPowerCircuit}
\end{figure}

As shown in Figure \ref{img_solarPowerCircuit}, the solar power circuit consists of a 5 $volt$, 100 $mA$ solar cell, a 100 $ohm$ resistor, indicated by R1, and a 3.3 $volt$ zener diode, indicated by D1. The zener diode is connected in reverse biased mode as a voltage regulator. The zener diode ensures that the circuit receives a stable supply of 3.3 $volts$. The resistor is used as a current limiting element. It restricts the flow of current so that only a specified maximum amount of current flows through the circuit, and thus prevents the zener diode from being damaged. As shown in Figure \ref{img_solarPowerCircuit}, R1 and D1 form a voltage divider circuit, which ensures that the circuit connected parallel to the zener diode maintains a stable voltage of 3.3 $volts$ across it.% Here, we are not concerned about power loss in the resistor. since it is excess power which cannot be used to perform any useful work.

The resistance value is based on Ohm's law:
\begin{equation}
R = \frac{V_{s}-V_{z}}{I_{r}}
\end{equation}

%where,

%$R$ = Resistance($ohms$)

%$V_{s}$ = Output Voltage of solar cell($volts$)

%$V_{z}$ = Breakdown voltage of zener diode($volts$)

%$I_{r}$ = Amount of current required by circuit($mA$)

\begin{tabular}{lllp{10cm}}
where, & • & • & • \\
• & $R$ & = & Resistance ($ohms$) \\
• & $V_{s}$ & = & Output voltage of solar cell ($volts$) \\
• & $V_{z}$ & = & Breakdown voltage of zener diode ($volts$) \\
• & $I_{r}$ & = & Amount of current required by circuit ($mA$) \\
 &  &  &  \\
\end{tabular}

The solar power circuit performs two functions.
\begin{enumerate}
\item Provide the voltage and current required by the processing circuit.
\item Provide the excess current to the battery circuit to charge the battery.
\end{enumerate}

\section{Battery Circuit}

\begin{figure}[htbp]
\centering
\includegraphics[width=\columnwidth]{battery_ckt.PNG}
\caption{Battery Circuit}
\label{img_batteryCircuit}
\end{figure}

As shown in Figure \ref{img_batteryCircuit}, the battery circuit consists of an MCP73831 integrated circuit, an 850 $mAh$ Li-Ion battery, and two Schottky diodes \cite{bib_diode}, indicated in Figure \ref{img_batteryCircuit} as D3 and D4. The MCP73831 is used to charge the Li-Ion battery. Schottky diodes are usually used for fast switching of inputs, as their response time is faster, and their forward voltage drop is less than normal diodes. The Schottky diode has a low forward voltage drop of only 0.2 $volts$ and a high reverse breakdown voltage of 15 $volts$. In this circuit, we use the low forward voltage drop property of the Schottky diode to reduce the voltage. According to the discharge curve of the Li-Ion battery \cite{bib_battery}, the output voltage of the battery is fairly stable at 3.7 $volts$. The processing circuit operates properly at 3.3 $volts$. This voltage drop is provided by the diodes. As shown in Figure \ref{img_circuit}, if solar energy is not available, voltage at the cathode of diode D4 is less than the voltage at its anode. This makes diode D4 forward biased, and hence the circuit runs on battery power. If solar energy is available, and the output voltage of the battery is less than or equal to 3.7 $volts$, these diodes become reverse biased as voltage at the cathode of the Schottky diode is more than the voltage at the anode, and hence the circuit runs only on solar power while the battery charges. This helps conserve the battery whenever solar energy is available.

% ask Jason whether to mention about resistor or not to provide the voltage drop in place of diode and its disadvantage

The lifetime of a Li-Ion battery is directly proportional to how the battery is charged. There are three charging stages:

\begin{enumerate}
\item Precondition charging
\item Constant current charging
\item Constant voltage charging
\end{enumerate}

Depending on the state and capacity of the battery, we must decide on the maximum charging current that will not damage the battery. Li-Ion batteries are very sensitive to charging voltage; the charging voltage should not exceed 1.19\% of the rated value. To ensure the charging voltage is within an acceptable range, the circuit uses a MCP73831 \cite{bib_mcp73831} integrated circuit instead of basic electronic components. MCP73831 determines the charging stage of the battery. The MCP73831 is also fairly inexpensive (0.69 USD).%Another benefit of using the MCP73831 rather than basic electronic components, is the MCP73831 is less expensive.
%To overcome this problem, the circuit uses a MCP73831 \cite{bib_mcp73831} integrated circuit. The main reason to use MCP73831 in place of basic electronic components is the sensitivity of the Li-Ion battery towards charging voltage. Further, designing a Li-Ion battery charging circuit using basic electronic components is more expensive than MCP73831 integrated circuit.

\section{Switching Circuit}

\begin{figure}[htbp]
\centering
\includegraphics[width=\columnwidth]{correct_ckt.PNG}
\caption{Complete Circuit Diagram}
\label{img_circuit}
\end{figure}

\begin{figure}[htbp]
\centering
\includegraphics[width=110mm]{switchin_ckt.PNG}
\caption{Switching Circuit}
\label{img_switchingCircuit}
\end{figure}

Figure \ref{img_switchingCircuit} shows the switching circuit, which consists of a Schottky diode, indicated by D2. The Schottky diode is highly suitable for our application. Consider the situation when it is night; the solar panel will not source power; instead, it will sink power. If the Schottky diode shown in Figure \ref{img_circuit} as D2 is not present, the zener diode denoted as D1 will connect to the battery and it will continuously consume power from the battery, resulting in battery failure. In this situation, the Schottky diode D2 becomes reverse biased, resulting in high reverse breakdown voltage, causing the path between the battery circuit and solar power circuit to become (effectively) an open circuit, resulting in savings in battery power.

\section{Circuit for Processing, Transmission and Reception of Data}
This section describes the processing and transmission circuit, and the connection of the \textit{\textbf{root}} mote with the \textit{base station}. The processing circuit consists of an ATMEGA168 microcontroller \cite{bib_atmega}, and a radio frequency transceiver, the RFM12 \cite{bib_rfm12}. The RFM12 transmits and receives data. It offers many advantages over more costly radios, such as the CC2420, the CC2400, and others, including programmable variable data transmission rates, variable channel frequency, and most importantly, low power consumption and cost. The ATMEGA168 is used to sense and process data \textit{in situ}. The ATMEGA168 transmits the processed data using the RFM12 transceiver to the neighboring motes. If the mote is the  \textit{\textbf{root}}, it transmits the data to the base station using an FT232R \cite{bib_ftdi} chip, a UART to USB converter. The base station runs Python code that processes, analyzes, and stores the data.

The main motivation for creating this design and not using off-the-shelf hardware, such as the TelosB mote \cite{bib_telob}, is the hardware cost and the ease of adding the harvesting circuit. This thesis focuses on making an inexpensive network that provides all the basic functionality of off-the-shelf motes. Table \ref{table_costOfComponents} shows the cost of the individual components used to make the device, as well as the costs when the components are purchased in volume.

\begin{table}[htbp]
\begin{center}
\begin{tabular}{|l||c|c|c|}
\hline
 & \multicolumn{3}{ |c| }{\textbf{Quantity}} \\
\hline
\hline
\textbf{Components} & \textbf{1} & \textbf{100} & \textbf{1000} \\
\hline
\hline
Solar Panel & 6.90 & 5.50 & 5.50 \\
\hline
Li-Ion battery  & 11.61 & 3.87 & 3.22 \\
\hline
RFM12 & 6.95 & 5.56 & 5.56 \\
\hline
ATMEGA168 & 2.43 & 1.35 & 1.35 \\
\hline
MCP73831 & 0.68 & 0.42 & 0.42 \\
\hline
Resistor, Capacitor, and Diodes & 2.97 & 1.59 & 0.88 \\
\hline
% &  &  &  \\
\hline
Total & 31.54 & 18.29 & 16.93 \\
\hline
Cost of 1 unit & 31.54 &  &  \\
\hline
Cost of 100 units &  & 1829.00 &  \\
\hline
Cost of 1000 units &  &  & 16930.00 \\
\hline
\end{tabular}
\end{center}
\caption{Cost of Components (in USD) \cite{bib_cost}}
\label{table_costOfComponents}
\end{table}

\begin{figure}[htbp]
\centering
\includegraphics[width=110mm]{prototype.jpg}
\caption{Prototype Board}
\label{img_prototypeBoard}
\end{figure}

The prototype of the board is shown in Figure \ref{img_prototypeBoard}. The prototype board consists of a MCP73831 Li-Ion battery charger, Schottky diodes, an ATMEGA168 microcontroller to process data, and an RFM12 transceiver to transmit and receive data from other motes. In the future, the prototype board can be converted to a PCB to further reduce the size of the circuit. This circuit can be built on a PCB that is 1 square inch.
%This circuit can be built on 1 X 1 inch of square using PCB.

\begin{figure}[htbp]
\centering
\includegraphics[width=110mm]{box_ckt.jpg}
\caption{Safety Enclosure}
\label{img_boxCircuit}
\end{figure}

As shown in Figure \ref{img_boxCircuit}, the circuit is then enclosed in a plastic container to prevent it from being damaged by environmental factors like rain or dust. Figure \ref{img_boxCircuit} shows the prototype board and the solar panel enclosed in the plastic container.


\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{float}
\usepackage{listings}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage[hidelinks]{hyperref}
\usepackage[noabbrev,capitalize,nameinlink]{cleveref}
\usepackage{natbib}
\usepackage{setspace}
\usepackage{tikz-cd}

\newcommand{\argmin}{\ensuremath{\mathop{\arg\min}\limits}}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\title{Automatic Wound Analysis with Siamese Network}
\author{Alex Ruan \\ \texttt{runalex01@gmail.com} \and Siwei Wang \\ \texttt{siweiw9@gmail.com}}
\date{\today}

\begin{document}
\maketitle
\onehalfspacing

\section{Data Preprocessing} \label{sec:data_preprocessing}

Our system expects standard 3-channel images as input (dimensions \(W \times H \times 3\)). We trained our model on images consisting of a rat's abdominal section with one or more wounds. The background was white, and the rat was placed next to a ruler. However, the model can be trained on any labelled dataset to suit a variety of applications.

Each image is resized to a uniform \(40 \times 40 \times 3\) using bicubic interpolation. For best results, we recommend that input images be larger than this size. We then apply a Gaussian blur with a radius of 2. The Siamese model expects resampled and blurred images as input when predicting labels.

During training, the model expects image pairs. The training set is generated by taking all distinct image pairs and labelling the pair with 1 or 0 if the images have the same or different labels, respectively. Suppose our dataset consists of \(N\) labelled images with \(K\) possible labels. We represent the dataset as image-label pairs \((X_i, y_i)\) with \(0 \leq i < N\), \(X_i \in [0, 1]^{40 \times 40 \times 3}\), and \(0 \leq y_i < K\). We generate \(\binom{N}{2}\) pairs of the form \([(X_i, X_j), \delta(y_i, y_j)]\) where \(\delta\) denotes Kronecker delta and \(i \neq j\). Define \(N_i\) as the number of times label \(i\) appears in the training set. Then there are
\begin{equation}
    \sum_{i = 0}^{K - 1} \binom{N_i}{2} \label{eq:same_pairs}
\end{equation}
pairs with label 1. For a reasonably balanced dataset with \(K > 2\), this number will usually be less than half of \(\binom{N}{2}\). The resulting class imbalance is addressed by assigning appropriate class weights during training.

\section{Model Architecture} \label{sec:model_architecture}

\subsection{Overview} \label{subsec:overview}

Label predictions are the result of a 2-step process. The input image is first encoded as a vector representation. The encoding is then compared against a ``typical'' representation for each label. This comparison is carried out with a custom distance metric. The model predicts the label corresponding to the closest representation. In symbols, the model consists of an encoder \(\mathcal{E} \colon [0, 1]^{40 \times 40 \times 3} \to \mathbf{R}^{2048}\), a distance metric \(\mathcal{D} \colon \mathbf{R}^{2048} \times \mathbf{R}^{2048} \to (0, 1)\), and \(K\) ``typical'' representations \(C_0, \dotsc, C_{K - 1}\) with \(C_i \in \mathbf{R}^{2048}\). Given input image \(I \in [0, 1]^{40 \times 40 \times 3}\), the model predicts label
\begin{equation}
    \argmin_{i = 0}^{K - 1} \mathcal{D}(\mathcal{E}(I), C_i) \label{eq:prediction}
\end{equation}
We can interpret the prediction process as a generalization of \(K\)-means. The image \(I\) derives its label by comparing its representation \(\mathcal{E}(I)\) against against \(K\) ``centroids'' and choosing the closest one, where distance is defined by \(\mathcal{D}\).

To train the model, we construct a siamese network with contrastive loss. We would like \(P_{ij} \coloneqq \mathcal{D}(\mathcal{E}(X_i), \mathcal{E}(X_j))\) to approximate \(Y_{ij} \coloneqq \delta(y_i, y_j)\). Note that this problem is a binary classification task with instance \((X_i, X_j)\) and label \(Y_{ij}\). Hence, we use cross-entropy loss \(\mathcal{L}\), which is defined as
\begin{equation}
    \mathcal{L}[(X_i, X_j), Y_{ij}] \coloneqq -Y_{ij} \log P_{ij} - (1 - Y_{ij}) \log (1 - P_{ij}) \label{eq:cross_entropy}
\end{equation}
to tune our model parameters. The forward pass of the training process is summarized in the diagram below.
\begin{equation*}
    \begin{tikzcd}
        X_i \arrow[rr, "\text{encode}"] &  & \mathcal{E}(X_i) \arrow[rrd, "\text{dist}", bend left]   &  &                                  &  & Y_{ij} \arrow[d]                  \\
        &  &                                                          &  & P_{ij} \arrow[rr, "\text{loss}"] &  & {\mathcal{L}[(X_i, X_j), Y_{ij}]} \\
        X_j \arrow[rr, "\text{encode}"] &  & \mathcal{E}(X_j) \arrow[rru, "\text{dist}"', bend right] &  &                                  &  &
    \end{tikzcd} \label{eq:training}
\end{equation*}

We compiled our model with an Adams optimizer (initial learning rate of \(5 \times 10^{-5}\)), a batch size of 5, and saved the model with the lowest validation loss over 30 epochs.

\subsection{The Encoder} \label{subsec:the_encoder}

We use a deep CNN similar to \citet{tds} to encode an image \(I\) as a vector representation. The architecture is fairly standard, consisting of a series of convolutions with ReLU activation followed by max pools. At the end, the image is flattened and passed through a fully connected layer with sigmoid activation. A diagram of the encoder is displayed in \cref{fig:encoder}.

\begin{figure}[H]
    \centering
    \caption{Encoder (CNN) Architecture}
    \includegraphics[width=.9\textwidth]{encoder.png}
    \label{fig:encoder}
\end{figure}

The more detailed Keras model summary is reproduced below.
\begin{lstlisting}
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d (Conv2D)              (None, 40, 40, 64)        15616
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 20, 20, 64)        0
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 20, 20, 128)       401536
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 10, 10, 128)       0
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 10, 10, 128)       409728
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 5, 5, 128)         0
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 5, 5, 256)         295168
_________________________________________________________________
flatten (Flatten)            (None, 6400)              0
_________________________________________________________________
dense (Dense)                (None, 2048)              13109248
=================================================================
\end{lstlisting}

\subsection{The Distance Metric} \label{subsec:the_distance_metric}

Define a component-wise absolute value function \(\alpha \colon \mathbf{R}^n \to \mathbf{R}^n\) given by \((v_1, \dotsc, v_n) \mapsto (\abs{v_1}, \dotsc, \abs{v_n})\). The distance between two representation vectors \(U, V \in \mathbf{R}^{2048}\) is computed by passing \(\alpha(U - V)\) through a fully-connected layer \(F\) with a single output node and sigmoid activation. Then \(\mathcal{D}(U, V) \coloneqq F \circ \alpha(U - V)\). This is the approach used by \citet{cmu}.

The intuition is that we wish to jointly learn an encoding \(\mathcal{E}\) and a ``difference'' interpreter \(F\) that maps images with the same label close together and maps images with different labels far apart. Recall that \(F \coloneqq S \circ T\) consists of an affine transformation \(T \colon \mathbf{R}^{2048} \to \mathbf{R}\) followed by sigmoid activation \(S\). Hence, we see that \(F\) learns to affinely map large differences to very positive values and map small differences to very negative values. Then, \(S\) squeezes these values into the \((0, 1)\) range.

In this case, \(\alpha(U - V)\) quantifies how different the representations \(U\) and \(V\) are from one another. More rigorously, the \(L^1\) norm of \(\alpha(U - V)\) captures the \(L^1\) distance separating \(U\) and \(V\). Hence, we may interpret \(T\) as assigning a weight to each of the 2048 components that comprise a representation vector. This means that we can penalize a difference in certain components more heavily than in others.

The ``typical'' representations \(C_0, \dotsc, C_{K - 1}\) are computed after the model is trained. We used the mean encoding of the training images from each label.
\begin{equation}
    C_i \coloneqq \frac{1}{N_i} \sum_{j = 0}^{N - 1} \delta(y_j, i) \cdot \mathcal{E}(X_j) \label{eq:typical_rep}
\end{equation}
In this sense, \(C_i\) should be close to most images with label \(i\) and far away from most images with label \(j \neq i\), as measured by \(\mathcal{D}\).

\bibliographystyle{abbrvnat}
\bibliography{wound}
\end{document}


\section{Optimisation with linear equality constraints}


\documentclass{article}
%\usepackage{polski} %to replace latex keywords in the document to Polish
\usepackage[utf8]{inputenc} %sets input encoding to UTF-8, needed for Polish, Japanese, etc.
\usepackage[T1]{fontenc} %needed for Polish characters
\usepackage{lmodern} %this font handles Polish characters properly
\usepackage[cm]{fullpage} %very small margins (around 1.5cm)
\usepackage{multicol} %use \begin{multicols}{#} for # columns
\usepackage{amssymb} %big bracets and other useful symbols
\usepackage{amsmath} %some mathematical symbols
\usepackage{enumitem} %remove vertical space in itemize with: [noitemsep,nolistsep]
\usepackage{url} %use \url{} in the document
%\usepackage{tipa} % \textpolhook{a}

\newcommand{\nodata}{\emph{no data yet}}
\newcommand{\samplecustom}[2]{X_{#1}, \ldots, X_{#2}}
\newcommand{\sample}{\samplecustom{1}{n}}

\newcommand{\distbernoulli}{\textrm{Bern}}
\newcommand{\distbinomial}{\textrm{Bin}}
\newcommand{\distpoisson}{\textrm{Pois}}
\newcommand{\distgeometric}{\textrm{G}}
\newcommand{\disthypergeometric}{\textrm{Hy}}
\newcommand{\distuniform}{\textrm{U}}
\newcommand{\distnormal}{\textrm{N}}
\newcommand{\distexponential}{\textrm{Exp}}
\newcommand{\distgamma}{\Gamma}
\newcommand{\distchisquare}{\chi^2}
\newcommand{\diststudentt}{\textrm{t}}
\newcommand{\distf}{\textrm{F}}

\newcommand{\param}{\theta}
\newcommand{\estim}{\hat{\theta}}
\newcommand{\limit}[2]{\underset{#1 \rightarrow #2}{\lim}}
\newcommand{\mean}{\overline{X}}
\newcommand{\quantile}[2]{\textrm{#1-quantile}_{#2}}
\newcommand{\qquantile}[1]{\quantile{q}{#1}}
\newcommand{\qqquantile}[1]{\textrm{quantile}_{#1}}
\newcommand{\med}{\textrm{MED}}
\newcommand{\mad}{\textrm{MAD}}
\newcommand{\var}{\textrm{Var}}
\newcommand{\statspace}{\left( \mathcal{H}, \mathcal{A}, \mathcal{P} = \left\{ p_\theta : \theta \in \Theta \right\} \right)}

\begin{document}

\title{Theory and formulas for \emph{Computer Statistics} course on MiNI on WUT}
\date{\today}
\author{Mateusz Bysiek, Computer Science, MiNI, WUT}
\maketitle

%\pagebreak[4]

\tableofcontents

\newpage

\section{Theory}

\subsection{Review of probability theory}

\subsubsection{Review of basic probability distributions}
\begin{multicols}{2}
\input{cs_1_probability}
\end{multicols}

\newpage

\subsection{Descriptive statistics}

\subsubsection{Basic notions}
\input{cs_2a_basics}

\newpage

\begin{multicols}{2}

\subsubsection{Measures of location: central tendency}
\input{cs_2b_measures_central}

\vfill
\columnbreak

\subsubsection{Measures of location: position}
\input{cs_2c_measures_position}

\subsubsection{Measures of dispersion}
\input{cs_2d_measures_dispersion}

\subsubsection{Measures of shape}
\input{cs_2e_measures_shape}

\end{multicols}

\newpage

\subsection{Inferential statistics}

\subsubsection{Basics, more on probability distributions}

\begin{multicols}{2}
\input{cs_3_probability_adv}
\end{multicols}

\newpage

\subsubsection{Point estimation}

\begin{multicols}{2}
\input{cs_4_estim_point}
\end{multicols}

\newpage

\subsubsection{Interval estimation}

\begin{multicols}{2}
\input{cs_5a_estim_interval}
\end{multicols}

\subsubsection{Selected confidence intervals}

\begin{multicols}{3}
\input{cs_5b_estim_interval_example}
\end{multicols}

\subsubsection{Planning experiments}

\begin{multicols}{2}
\input{cs_6_planning}
\end{multicols}

\newpage

\subsubsection{Hypothesis testing}

\begin{multicols}{2}
\input{cs_7a_tests}
\end{multicols}

\newpage

\subsubsection{Selected parametric tests}

\begin{multicols}{2}
\input{cs_7b_tests_parametric_example}
\end{multicols}

\newpage

\subsubsection{Advanced hypothesis testing}

\begin{multicols}{2}
\input{cs_7c_tests_adv}
\end{multicols}

\subsubsection{Selected non-parametric tests}

\begin{multicols}{2}
\input{cs_7d_tests_nonparam_example}
\end{multicols}

\newpage

\subsubsection{Linear regression}

\begin{multicols}{2}
\input{cs_8_regression}
\end{multicols}

\newpage

\hspace{0pt}

\newpage

\thispagestyle{empty}

\section{Formulas for the exam}

\section*{Formulas: confidence intervals}
\begin{multicols}{3}
\input{cs_5b_estim_interval_example}
\end{multicols}

\section*{Formulas: non-parametric tests}
\begin{multicols}{2}
\input{cs_7d_tests_nonparam_example}
\end{multicols}

\newpage

\thispagestyle{empty}

\section*{Formulas: parametric tests}
\begin{multicols}{2}
\input{cs_7b_tests_parametric_example}
\end{multicols}

\newpage

\section{Sources, references}

If you find any mistakes, please send message to \url{bysiekm {at} student.mini.pw.edu.pl}

\vspace{10pt} \noindent Thanks to\ldots
\begin{itemize}
  \item P. Grzegorzewski and M. Gągolewski, for this whole theory and formulas
  \item group AP, for many of the formulas
  \item Karo, for notes
  \item lots of other people, for suggestions, corrections, etc.
  \item Wikipedia
\end{itemize}

\end{document}


\documentclass{article}

% the purpose of this particular document is to serve as a staging area potential blog posts, for the purpose of editing, revision, and review.

% packages
	\usepackage{amsmath, amsthm, mathtools}
	\usepackage{mdframed}
	\usepackage{geometry, enumerate}
	\usepackage{parskip}
	\usepackage{graphicx}

% theorems and such
  	\newtheorem{theorem}{Theorem}
  	\newtheorem{corollary}{Corollary}
  	\newtheorem{lemma}[theorem]{Lemma}
  	\newtheorem*{remark}{Remark}
  	\newtheorem*{exe}{Exercise}
  	\newtheorem{prop}{Proposition}
  	\newtheorem{example}{Example}

% custom commands
	\newcommand{\ceil}[1]{\left \lceil #1 \right \rceil}
	\newcommand{\floor}[1]{\lfloor #1 \rfloor}
	\newcommand{\X}[1]{\, \text{mod} \, #1}
	\newcommand{\divv}{\,|\,}
	\newcommand{\GCD}[2]{GCD\,(#1, #2)}
	\newcommand{\LCM}[2]{LCM\,(#1, #2)}

\begin{document}

\title{Elementary Number Theory : \S 2}
\author{Henry Slayer $|$ University of California, Santa Cruz}
\date{}
\maketitle

\section*{Linear Diophantine Equations}
The Euclidean algorithm studies the relationships between numbers, comparing their parts, and measuring how two integers can be decomposed into smaller and smaller portions of themselves. This decomposition is governed by the greatest common divisor, which exists hand in hand with the least common multiple, as we have seen. Rising more or less naturally from the interplay between various integers, we encounter linear Diophantine equations. A linear Diophantine equation is an equation of the form
\[ax + by = c\]
For integers $a, b, c, x, y$. This probably isn't the first time that you've seen an equation of this form. It's really nothing more than a line in $\mathbf{R}^2$. However, our approach to these types of equations will likely be different from what's typically done in high school algebra or calculus courses. We are interested in three things
\begin{enumerate}[(i)]
\item Does $ax + by = c$ have integer solutions?
\item Provided it does, how do we find them?
\item Given (i) and (ii), can we generalize infinite families of integer solutions?
\end{enumerate}
The answer to the first question is a blunt consequence of divisibility, and our method of solution will give us direction for the latter two questions.

\subsubsection*{Solubility of Linear Diophantine Equations}
We find that solubility os $ax + by = c$ is a direct consequence of $\GCD{a}{b}$.
\begin{mdframed}
\begin{theorem}
Let $a, b, c, x, y$ be integers. Then, the equation $ax + by = c$ has integer solutions $(x, y)$ if and only if $\GCD{a}{b}\divv c$.
\end{theorem}
\begin{proof}
First, assume that $ax + by = c$ has an integer solution. By the properties of the greatest common divisor, $\GCD{a}{b}\divv ax$, $\GCD{a}{b}\divv by$, and so $\GCD{a}{b}$ must also divide $c$. \\
Conversely, suppose that $\GCD{a}{b}\divv c$. In the penultimate line of Euclid's algorithm, when performed on $a$ and $b$, we will obtain something that looks like
\[r_i = q_{i+1}(r_{i+1}) + \GCD{a}{b}\]
Pulling the quotient to one side, we obtain
\[r_i = q_{i+1}(r_{i+1}) = \GCD{a}{b}\]
Now, the left-hand side of the equation above, through the iterative process of back-substitution, can bring us back to a linear combination of our initial values $a$ and $b$ (as we will show in a subsequent example). Thus, for integers $x_0, y_0$,
\[ax_0 + by_0 = \GCD{a}{b}\]
As $\GCD{a}{b}\divv c$, this equation can be scaled to
\[ax + by = c\]
for integers $x$ and $y$.
\end{proof}
\end{mdframed}
The converse of the theorem above suggests a method for finding a particular solution to linear diophantine equations. This method is effective, and we do most of the work in the beginning, when we're seeking to determine if $c$ is a multiple of the greatest common divisor.
\begin{mdframed}
\begin{example}
Does $763x + 129y = 1$ have integer solutions? If so, find a particular solution $(x, y)$.
\end{example}
\begin{proof}
We know that this equation will have integer solutions if 1 is a multiple of the greatest common divisor of 763 and 129. In this case, then, the greatest common divisor must be 1. So, we proceed by Euclid's algorithm.
\begin{align}
763 &= 5(129) + 118 \\
129 &= 1(118) + 11 \\
118 &= 10(11) + 8 \\
11 &= 1(8) + 3 \\
8 &= 2(3) + 2 \\
3 &= 1(2) + 1\\
2 &= 2(1) + 0
\end{align}
The second-to-last line tells us that 763 and 129 have a greatest common divisor of 1, which means that we can find integer solutions for the equation above. To find a particular solution, all that we need to do is reverse the Euclidean algorithm, working our way back up by reverse-substitution. Because Euclid's algorithm gives us a system of equations, we can 'look up' to the line above, and make substitutions to bring ourselves closer to our initial values of $a$ and $b$. Starting with the final line:
\begin{align*}
1 &= 3 - 2(1) \\
 &= 3 - (8 - 2(3)) = 3(3) - 8 \qquad \quad \textit{by line 5} \\
 &= 3(11 - 8) - 8 = 3(11) - 4(8) \qquad \quad \textit{by line 4} \\
 &= 3(11) - 4(118 - 10(11)) = 43(11) - 4(118) \qquad \textit{by line 3}  \\
 &= 43(129 - 118) - 4(118) = 34(129) - 47(118) \qquad \textit{by line 2}\\
 &= 43(129) - 47(763 - 5(129)) \qquad \quad \textit{by line 1} \\
 &= 278(129) - 47(763)
\end{align*}
So, our particular solution to the equation $736x + 129y = 1$ is $(-47, 278)$.
\end{proof}
\end{mdframed}
This method is extremely effective for finding particular solutions to linear diophantine equations. However, the bookkeeping can certainly get a bit tangled, and it's easy to get lost in the line-by-line calculations. Be sure to check your work along the way.

\subsubsection*{Families of Solutions}
So, we've determined that $ax + by = c$ is solvable, and we've found some integral solution $(x_0, y_0)$, all thanks to the Euclidean algorithm. To characterize \textit{all} solutions to a given linear diophantine equation, we turn our attention towards a clever use of \textit{homogeneous} linear diophantine equations, which look like
\[ax + by = 0\]
So, suppose that $ax + by = c$ is satisfied by a particular solution $(x_0, y_0)$. If we consider $x$ and $y$ to be 'general solution' terms, it follows, then, that
\[ax + by = ax_0 + by_0 = c\]
Which, in turn, means that
\[a(x-x_0) + b(y - y_0) = 0\]
\[a(x-x_0) = - b(y - y_0)\]
We interpret this equality to generate 'solution sets' for the linear diophantine form $ax +by = c$, provided that it is solvable. We'll prove the general case for one term, and the second follows by symmetry. \\
Because we have equality above, we know that $-b(y-y_0)$ must be a multiple of the $\LCM{a}{b}$. So, assume then that
\[a(x - x_0) = n \cdot \LCM{a}{b} \]
Which means
\[x = x_0 + \frac{n\cdot\LCM{a}{b}}{a}\]
Furthermore, the $GCD/LCM$ product formula tells us that $\frac{\LCM{a}{b}}{a} = \frac{b}{\GCD{a}{b}}$. So, given $ax + by = c$, and a particular solution $(x_0, y_0)$, we can generate all solutions for $x$ by
\[x = x_0 + \frac{n\cdot b}{\GCD{a}{b}}\]
A similar argument justifies the following for $y$
\[y = y_0 - \frac{n\cdot a}{\GCD{a}{b}}\]
Where the sign has been flipped, and $n$ is the same $n$ as above (as $a(x-x_0) = -b(y - y_0) = n \cdot \LCM{a}{b}.$
\begin{mdframed}
\begin{theorem}
Let $a, b, c, x, y$ be integers. Then, the equation $ax + by = c$ has integer solutions when $\GCD{a}{b}\divv c$. Based on a particular solution $(x_0, y_0)$, all solutions to this equation can be generated by
\[x = x_0 + \frac{n\cdot b}{\GCD{a}{b}}, \qquad y = y_0 - \frac{n\cdot a}{\GCD{a}{b}}\]
\end{theorem}
\end{mdframed}
Writing these expressions in terms of the $GCD$ is more out of preference rather than necessity. The $GCD$ arises naturally when we perform the Euclidean algorithm, and so it's favorable to capitalize on this construction's computational convenience.\\\\ We can extend our study of linear diophantine equations into three variables (and more!). The process is mostly the same, so we will simply conclude this section with an example.

\subsubsection*{Linear Diophantine Equations in 3 Variables}
Extending into a 3-variable case can be a bit tricky. For equations of the form $ax + by + cz = d$, we need to work in parts, solving for pariwise sub-relationships that tie the three-variable dynamic together. \\
\begin{mdframed}
\begin{example}
Let $x, y, z$ be integers. Characterize all integer solutions to the equation $3x + 5y + 4z = 9$, if such integer solutions exist.
\end{example}
\begin{proof}
The first thing that we want to do is ensure that the $GCD(a, b, c)$ is a divisor of 9. A quick look tells us that because 3 and 5 are prime, they share no common divisors, and neither divide 4. Thus, the three values are pairwise coprime, which means that $GCD(a, b, c) = 1$, and 1 certainly divides 9. So, we know that solutions certainly exist. In order to solve this equation, we're going to want to break it down into two smaller systems. We start by taking a look at $3x + 5y$. We know from solving two-variable LDE's that this linear combination will give us compound moves that are multiples of $\GCD{a}{b}$. So, we start by solving this subsystem for $\GCD{3}{5} = 1$. We find (and the reader should be sure to check) that $(2, -1)$ is a particular solution to $3x + 5y = 1$, which means that if $3x + 5y = v$, $x$ and $y$ will be characterized by $(2v, -v)$. So, we store that information for later. It will come in handy. \\
Now that we've established a connection between 3 and 5, we can use that 'common ratio' back in our original equation, which becomes
\[v + 4z = 9\]
A quick glance tells us that $(1, 2)$ is a particular $(v, z)$ solution, which implies that
\[v = 1 + 4n, \qquad z = 2 - n\]
Are our general solutions, which we obtained from the theorem proved earlier. Translating $v$ into the language of $x$ and $y$ by what we had previously established,
\[x = 2v = 2 + 8n, \quad y = -v = -1 -4n, \quad z = 2 - n\]
And so, we've obtained general sets of solutions for $3x + 5y + 4z = 9$, by first solving a smaller linear relationship, which we then used as a placeholder to shed light on the larger linear dynamics at play.
\end{proof}
\end{mdframed}
\end{document}


\section{The discretization of spatial differential operators}

\begin{myDef}[Conservative Operator]
For...
\begin{packed_itemize}
  \item a list of \emph{domain variables}, $U := (u_0,\cdots,u_{\Lambda-1}) \in \ceins(\Omega)^\Lambda$ and
  \item a list of \emph{codomain variables}, $W := (w_0,\cdots,w_{\Gamma-1}) \in L^2(\Omega)^\Gamma$
\end{packed_itemize}
a mapping
\[
Op:\ceins(\Omega)^\Lambda \rightarrow L^2(\Omega)^\Gamma, \ U \mapsto W = Op(U)
\]
is called \emph{conservative operator} if
every codomain variable $w_\gamma$ can be written as
\[
  w_\gamma = \divergence{ \vec{f}_\gamma(\vec{x},U) } + q_\gamma(\vec{x},U).
\]
The functions
\begin{packed_itemize}
 \item $ \vec{f}_\gamma(\vec{x},U) \in \left( \ceins (\real^D \times \real^\Lambda) \right)^D$
      are called the flux and
 \item $  q_\gamma(\vec{x},U) \in L^2(\real^D \times \real^\Lambda)$
      are called the source
\end{packed_itemize}
of codomain variable $w_\gamma$.
\label{ConservativeOp}
\end{myDef}

\begin{myNot}[Outer normal]
For $\vec{x} \in \partial K_j$, $\vec{n}_\vec{x} \in \partial \mathcal{S}_D$ denotes an outer normal
field for $K_{\tau(j)}$, for
those points of $\partial K$ where an outer normal is defined, which may not be the case
for a null-subset of $\partial K$
i.e. ``edges'' and ``corners''.
\end{myNot}

\begin{myDef}[Conservative operators on product spaces of $DG_p$]
Again, like in (\ref{ConservativeOp}), there is
a list of domain variables,
$U := (u_0,\cdots,u_{\Lambda-1}) \in DG_{(p_0, \cdots, p_{\Lambda-1})} =: Dom$
and a list of codomain variables
$W := (w_0,\cdots,w_{\Gamma-1}) \in DG_{(l_0, \cdots, l_{\Gamma-1})} =: Cod$.
A mapping
\[
 OP_h :
 DG_{p_0} \times \cdots \times DG_{p_{\Lambda-1}}
 \rightarrow
 DG_{l_0} \times \cdots \times DG_{l_{\Gamma-1}},
 \
 U \mapsto W = Op_h(U)
\]
is called a DG-discretization of the conservative operator $Op$
if the $n$-th DG coordinate of variable $w_\gamma$ in cell $K_{\tau(j)}$, $\tilde{w}_{\gamma,j,n}$
can be written as
\[
  \tilde{w}_{\gamma,j,n} =
  \int_{\partial K_{\tau(j)}}
       F_\delta \ \phi_{j,n}
  \ \textrm{dS}
  -
  \int_{K_{\tau(j)}} \left(
       \vec{f}_\gamma \cdot \nabla \phi_{j,n}
       -
       q_i \ \Phi_{j,n}
  \right) \ \textrm{d}\vec{x}
  .
\]
The function $F_\delta(\vec{x},U^\textrm{in},U^\textrm{out},\vec{n}_\vec{x})$ is called the \emph{Riemannian}
for the flux $\vec{f}_\gamma(\vec{x},U)$. Their properties are described in below, see (\ref{riemannians}).
Here, for $\vec{x} \in \partial K_{\tau(j)}$
\[
  U^\textrm{in} := \lim_{\stackrel{\vec{y} \rightarrow \vec{x}}{\vec{y} \in K_{\tau(j)}}}(U(\vec{y}))
  \textrm{ and }
  U^\textrm{out} := \lim_{\stackrel{\vec{y} \rightarrow \vec{x}}{\vec{y} \notin K_{\tau(j)}}}(U(\vec{y}))
  .
\]
By coordinate mappings, the conservative operator can be written as a mapping
\[
  Op_h: \real^{dim(Dom)} \rightarrow \real^{dim(Cod)}, \quad \tilde{U} \mapsto \tilde{W}.
\]
\label{ConservativeOp_h}
\end{myDef}

\begin{myRem}[On Riemannians]
The following properties are essential for proper defined Riemannians:
\begin{packed_itemize}
  \item $F_\gamma(\vec{x},U,U,\vec{n}_{\vec{x}}) = \vec{n}_{\vec{x}} \cdot \vec{f}_\gamma(\vec{x},U)$,
  i.e ``$F_\gamma$ is an approximation to $\vec{n}_{\vec{x}} \cdot \vec{f}_\gamma$''
  \item $F_\gamma(\vec{x},U,V,\vec{n}_{\vec{x}}) = -F_\gamma(\vec{x},V,U,-\vec{n}_{\vec{x}})$
  \item $\left| F_\gamma(\vec{x},U,V,\vec{n}_{\vec{x}}) - \vec{n}_{\vec{x}} \cdot \vec{f}_\gamma(\vec{x},U) \right| \leq L | U-V |$
  for some Lipschitz constant $L \in \realpos$
\end{packed_itemize}
\label{riemannians}
\end{myRem}

\begin{myDef}[Consistency of operators]
An operator $Op_h$ like in (\ref{ConservativeOp_h}) is called consistent
with an operator $Op$ like in (\ref{ConservativeOp}) with convergence
order $k$ if
\[
 \left\| Op_h(Proj_p(U)) - Proj_p( Op(U) ) \right\|_2 \leq h_\textrm{max}^k \cdot c(U)
\]
for any $U \in \ceins(\Omega)^\Lambda$ and a constant $c(U) \in \realpos$ which depends on $U$.
\label{consistency_of_operators}
\end{myDef}

\begin{myRem}
The motivation for (\ref{consistency_of_operators}) is the
following ``approximately'' commutative diagram:
%\begin{center}
\[
\begin{xy}
  \xymatrix{
      H^1(\Omega)^\Lambda \ar[r]^{Op} \ar[d]_{Proj}  &   (L^2(\Omega))^\Gamma  \ar[d]^{Proj}  \\
      \prod_\delta DG_{p_\delta} \ar[r]_{Op_h}       &  \prod_\gamma DG_{l_\gamma}
  }
\end{xy}
% ----------------------------------------#
\quad
\begin{xy}
  \xymatrix{
      U \ar@{|->}[rrrr]^{Op} \ar@{|->}[d]_{Proj} & &             &          &  W  \ar@{|->}[d]^{Proj}  \\
      U_h \ar@{|->}[rr]_{Op_h}                   & &  Op_h(U_h)  &  \approx &  W_h
  }
\end{xy}
\]
(Here, $Proj$ is an abbreviation for
$( Proj_{p_0}, \cdots, Proj_{p_{\Lambda-1}} )$
and
$( Proj_{l_0}, \cdots, Proj_{l_{\Gamma-1}} )$.
\end{myRem}

\begin{myRem}[Additive component decomposition of conservative operators in BoSSS]
In BoSSS, a conservative operator is called
\emph{spatial difference operator}\coderm{BoSSS.Foundation.SpatialDifferenceOperator}
and is specified as an additive composition of operators, which are called
\emph{equation components}\coderm{BoSSS.Foundation.IEquationComponent}.
The domain and codomain variables for the  spatial difference operator, are specified as lists
of symbolic names\coderm{BoSSS.Foundation.SpatialDifferentialOperator.DomainVar} \coderm{BoSSS.Foundation.SpatialDifferentialOperator.CodomainVar}.
Each equation component itself is a conservative operator with exactly one codomain variable,
i.e. it maps $\prod_\delta DG_{p_\gamma} \rightarrow DG_l$.
The domain variables of the equation components are specified as some
sub-list\coderm{BoSSS.Foundation.IEquationComponent.ArgumentOrdering}
of the domain variables list of the spatial difference operator.
The equation components may be classified into \emph{fluxes} and \emph{sources},
and wether they are either \emph{linear} or \emph{nonlinear}:
\begin{packed_itemize}
  \item nonlinear fluxes\coderm{BoSSS.Foundation.INonlinearFlux},\coderm{BoSSS.Foundation.INonlinearFluxEx};
  \item nonlinear sources\coderm{BoSSS.Foundation.INonlinearSource};
  \item linear fluxes\coderm{BoSSS.Foundation.ILinearFlux};
  \item linear sources\coderm{BoSSS.Foundation.ILinearSource};
\end{packed_itemize}
If more than one equation component is specified for one codomain variable, they are
added\coderm{BoSSS.Foundation.SpatialDifferentialOperator.EquationComponents}.
\end{myRem}

\begin{myRem}[Evaluation of conservative operators in BoSSS]
A conservative operator, or spatial differential operator $Op_h$ can be evaluated
in BoSSS
by\coderm{BoSSS.Foundation.SpatialDifferentialOperator.Evaluate(...)}
or\coderm{BoSSS.Foundation.SpatialDifferentialOperator.Evaluator.Evaluate(...)}.
If $Op_h$ is affine-linear, i.e.
\[
  Op_h(\tilde{U}) = \mathcal{M} \cdot \tilde{U} + b,
\]
the (sparse) matrix $\mathcal{M}$ and the affine vector $b$ can
be computed
by\coderm{BoSSS.Foundation.SpatialDifferentialOperator.ComputeMatrix(...)}.
\end{myRem}

%\subsection{Nonlinear fluxes}

%\subsection{Nonlinear sources}

%\subsection{Linear sources}

%\subsection{Fluxes for Interior Penalty Methods}


%!TEX root = morusAC.tex

\section{Trail for Full \MORUS}
\label{sec/fulltrails}

In the previous section, we presented a linear trail for the reduced ciphers \MiniMORUS[1280] and \MiniMORUS[640]. We now turn to the full ciphers \MORUS[1280] and \MORUS[640].

\subsection{Symmetrizing the Trail}
In order to build a trail for the full \MORUS, we proceed exactly as we did for \MiniMORUS, following the same path down to step and word rotation values, with one difference: in order to move from the one-word registers of \MiniMORUS to the four-word registers of full \MORUS, we make every term $S^t_{i,j}$ and $C^t_j$ symmetric, in the sense of \Cref{sec/introminimorus}.
That is, for every $S^t_{i,j}$ (resp. $C^t_j$) component in every trail fragment and every equation, we \emph{symmetrize} the term by adding in the terms $S^t_{i,j+w}$, $S^t_{i,j+2w}$, $S^t_{i,j+3w}$ (resp. $C^t_{j+w}$, $C^t_{j+2w}$, $C^t_{j+3w}$), where as usual $w$ denotes the word size. For example, if $w=64$ (for \MORUS[1280]), the term $S^3_{2,0}$ is symmetrized into:
\[
S^3_{2,0} \oplus S^3_{2,64} \oplus S^3_{2,128} \oplus S^3_{2,192}.
\]

Thus, translating the trail from one of the \MiniMORUS ciphers to the corresponding full \MORUS cipher amounts to making every linear combination symmetric---indeed, that was the point of introducing \MiniMORUS in the first place.
Concretely, in order to build the full trail equation for \MORUS, we write symmetric versions of equations $A^t_i$, $B^t_i$, $C^t_i$, $D^t_i$, $E^t_i$ from \Cref{sec:minitraileq}, and then combine them in exactly the same manner as before.
This way, the biased linear combination on \MiniMORUS[1280] given in \Cref{sec:minitraileq}, namely:
\begin{align*}
&C^0_{51} \oplus C^1_{0} \oplus C^1_{25} \oplus C^1_{33} \oplus C^1_{55} \oplus C^2_{4} \oplus C^2_{7} \oplus C^2_{29} \oplus C^2_{37}\\
\oplus\; &C^2_{38} \oplus C^2_{46} \oplus C^2_{51} \oplus C^3_{11} \oplus C^3_{20} \oplus C^3_{42} \oplus C^3_{50} \oplus C^4_{24}
\end{align*}
ultimately yields the following biased symmetrized linear combination on the full \MORUS[1280]:
\begin{align*}
&C^0_{51} \oplus C^0_{115} \oplus C^0_{179} \oplus C^0_{243} \oplus C^1_{0} \oplus C^1_{25} \oplus C^1_{33} \oplus C^1_{55} \oplus C^1_{64} \oplus C^1_{89}\\
\oplus\; & C^1_{97} \oplus C^1_{119} \oplus C^1_{128} \oplus C^1_{153} \oplus C^1_{161} \oplus C^1_{183} \oplus C^1_{192} \oplus C^1_{217} \oplus C^1_{225} \oplus C^1_{247}\\
\oplus\; & C^2_{4} \oplus C^2_{7} \oplus C^2_{29} \oplus C^2_{37} \oplus C^2_{38} \oplus C^2_{46} \oplus C^2_{51} \oplus C^2_{68} \oplus C^2_{71} \oplus C^2_{93}\\
\oplus\; & C^2_{101} \oplus C^2_{102} \oplus C^2_{110} \oplus C^2_{115} \oplus C^2_{132} \oplus C^2_{135} \oplus C^2_{157} \oplus C^2_{165} \oplus C^2_{166} \oplus C^2_{174}\\
\oplus\; & C^2_{179} \oplus C^2_{196} \oplus C^2_{199} \oplus C^2_{221} \oplus C^2_{229} \oplus C^2_{230} \oplus C^2_{238} \oplus C^2_{243} \oplus C^3_{11} \oplus C^3_{20}\\
\oplus\; & C^3_{42} \oplus C^3_{50} \oplus C^3_{75} \oplus C^3_{84} \oplus C^3_{106} \oplus C^3_{114} \oplus C^3_{139} \oplus C^3_{148} \oplus C^3_{170} \oplus C^3_{178}\\
\oplus\; & C^3_{203} \oplus C^3_{212} \oplus C^3_{234} \oplus C^3_{242} \oplus C^4_{24} \oplus C^4_{88} \oplus C^4_{152} \oplus C^4_{216}
\end{align*}
We refer the reader to \Cref{sec:traileq} for the corresponding linear combination on \MORUS[640].

\subsection{Correlation of the Full Trail}

The symmetrized trail on full \MORUS may be intuitively understood as consisting of four copies of the original trail on \MiniMORUS. Indeed, the only difference between full \MORUS (for either version of \MORUS) and four independent copies of \MiniMORUS comes from register-wise rotations, which permute words within a register. But as observed in \Cref{sec/introminimorus}, register-wise rotations leave symmetric linear combinations invariant; and so, insofar as we only ever use symmetric linear combinations on all registers along the trail, register-wise rotations have no effect.

Following the previous intuition, one may expect that the weight of the symmetrized trail should simply be four times the weight of the corresponding \MiniMORUS trail, namely 64 for both \MORUS[1280] and \MORUS[640]. However, reality is a little more complex, as the symmetrized trail does not exactly behave as four copies of the original trail when one considers nonlinear terms.

To understand why that might be the case, assume a nonlinear term $S^0_{2,0} \cdot S^0_{3,0}$ arising from some part of the trail, and another term $S^0_{2,0} \cdot S^0_{3,w}$ arising from a different part of the trail (where $w$ denotes the word size). Then when we XOR the various trail fragments together, in \MiniMORUS these two terms are actually equal and will cancel out, since register-wise rotations by multiples of $w$ bits are ignored. However in the real \MORUS these terms are of course distinct and do not cancel each other.

In the actual trail for (either version of) full \MORUS, this exact situation occurs when combining trail fragments $\beta^t_i$ and $\gamma^t_i$. Indeed, $\beta^t_i$ requires approximating the term $S^t_{2,i} \cdot S^t_{3,i}$, while $\gamma^t_i$ requires approximating the term $S^t_{2,i} \cdot S^t_{3,i-w}$ (cf. \Cref{fig:trailcollision}). While in \MiniMORUS, these terms cancel out, in the full \MORUS, when adding all symmetric copies of the trail, we end up with the sum:
{
\allowdisplaybreaks[0]
\begin{align}
&S^t_{2,i} \cdot S^t_{3,i} \oplus S^t_{3,i} \cdot S^t_{2,i+w}
\oplus S^t_{2,i+w} \cdot S^t_{3,i+w} \oplus S^t_{3,i+w} \cdot S^t_{2,i+2w}\notag\\
\oplus\; &S^t_{2,i+2w} \cdot S^t_{3,i+2w} \oplus S^t_{3,i+2w} \cdot S^t_{2,i+3w}
\oplus S^t_{2,i+3w} \cdot S^t_{3,i+3w} \oplus S^t_{3,i+3w} \cdot S^t_{2,i}.\label{eq:8circle}
\end{align}
}
It may be observed that the products occurring in the equation above involve eight terms forming a ring. The weight of this expression can be computed by brute force, and is equal to $3$.

\begin{figure}[t!]
  \substatesfalse
  % \substatesfalse to label state words and/or masks
  \centering
  \begin{subfigure}{.4\textwidth}
  \centering
  \begin{tikzpicture}[xscale=0.75,yscale=1.5]%{{{
    \printstate
    \draw[trail, beta]
      (C) -- node[right] {$i$} (lll-1)
      (lll-1) -- (tlll-1) (lll-1) -- (xor-1) (xor-1) -- (xnd-1)
      (tlll-1) -- (W-20) node[above] {$i$}
      (xor-1) -- (txor-1) %(txor-1) -- (W-21) node[above] {$i$}
      %(xnd-1) -- (and-1)
      (W40) node[below] {\phantom{$i$}}
      ;
    \draw[trail, gamma]
      %(W-21) node[above] {$i$}
      (txor-1) -- (xnd1)
      (xnd1) -- (xor1) (xor1) -- (lll1)
      %(xnd1) -- (and1)
      (xor1) -- (txor1)
      (txor1) -- (W-24) node[above] {$i$}
      (lll1) -- (W41) node[below] {$i+b_1$}
      ;
    %\draw[trail, beta,  dotted] (and-1) -- (and-1-|and1);
    %\draw[trail, gamma, dotted] (and1)  -- (and-1-|and1) node[above, black] {=};
    \node (eq) at ($(and-1|-and1)+(-1,-2.4pt)$) {=};
    \draw[beta,{Circle[sep=-1.8pt]}-]  ($(and-1)+(0,-2.4pt)$) -| (eq);
    \draw[gamma,{Circle[sep=-1.8pt]}-] ($(and1)+(0,-2.4pt)$) -- (eq);
  \end{tikzpicture}%}}}
  \caption*{\MiniMORUS: weight 0 (not 2)} %$S^{j,1}_i, S^{j,4}_i, S^{j+1,1}_{i-1}$ ($w\!=\!1$)}
  \end{subfigure}
  \qquad
  \begin{subfigure}{.4\textwidth}
  \centering
  \begin{tikzpicture}[xscale=0.75,yscale=1.5]%{{{
    \printstate
    \draw[trail, beta]
      (C) -- node[right] {$i$} (lll-1)
      (lll-1) -- (tlll-1) (lll-1) -- (xor-1) (xor-1) -- (xnd-1)
      (tlll-1) -- (W-20) node[above] {$i$}
      (xor-1) -- (txor-1) %(txor-1) -- (W-21) node[above] {$i$}
      (xnd-1) -- (and-1)
      (W40) node[below] {\phantom{$i$}}
      ;
    \draw[trail, gamma]
      %(W-21) node[above] {$i$}
      (txor-1) -- (xnd1)
      (xnd1) -- (xor1) (xor1) -- (lll1)
      (xnd1) -- (and1)
      (xor1) -- (txor1)
      (txor1) -- (W-24) node[above] {$i$}
      (lll1) -- (W41) node[below] {$i+b_1$}
      ;
    \draw[trail, beta,  dashed] (and-1.east|-tanB-1) -- (tanB-1);
    \draw[trail, gamma, dashed] (tanB-1)  -- (tanB1) -- (tanB1-|and1.east);
  \end{tikzpicture}%}}}
  \caption*{\MORUS: weight $4 \times 1$ (not $4 \times 2$)} %$S^{j,1}_i, S^{j,4}_i, S^{j+1,1}_{i-1}$ ($w\!=\!1$)}
  \end{subfigure}
  \caption{Weight of $\beta^t_i \oplus \gamma^t_i$ for \MiniMORUS and \MORUS.}
  \label{fig:trailcollision}
\end{figure}

For \MORUS[1280], since the trail fragment $\gamma^t_i$ is used four times, this phenomenon adds a contribution of $4 \cdot 3 = 12$ to the overall weight of the full trail. This results in a total weight of $4 \cdot 16 + 12 = 76$ (recall that the weight of the trail on \MiniMORUS[1280] is 16). We have confirmed this by explicitly computing the full trail equation in \Cref{sec:traileq}, and evaluating its exact weight like we did for \MiniMORUS in \Cref{sec:minibias}. That is, since the equation is quadratic, we may view it as a graph, which we split into connected components; we then compute the weight of each connected component separately by brute force, and then add up the weights of all components per the Piling-Up Lemma. Overall, the full trail equation given in \Cref{sec:traileq} yields a weight of 76 for the full trail on \MORUS[1280].

In the case of \MORUS[640], collisions between rotation constants further complicate the analysis. Specifically, when using trail fragment $\beta^t_i$, the term $S^t_{2,i} \cdot S^t_{3,i}$ occurs. As explained previously, a partial collision with the term $S^t_{2,i} \cdot S^t_{3,i-w}$ from trail fragment $\gamma^t_i$ results in \Cref{eq:8circle}. However trail fragment $\alpha^t_{i+d}$ is once used in the course of the full trail with an offset of $d = b_1+b_4-b_0-b_2$ (relative to $\gamma^t_i$), which in the case of \MORUS[640] is equal to $31+13-5-7 = 0 \;\text{mod}\; 32$. This creates another term $S^t_{2,i} \cdot S^t_{3,i}$, which ultimately destroys one of the four occurrences of \Cref{eq:8circle}. Therefore, when computing the full trail equation on \MORUS[640], we get that the weight of the trail is 73 (cf. \Cref{sec:traileq}).

%TODO: check $\alpha_i \oplus \beta_i \oplus \gamma_i$ in step 2 of $\cipher{MORUS-640}$
%(maybe not relevant due to overall complexity\dots)

\subsection{Taking Variable Plaintext into Account}
\label{subsec:variable}

In our analysis so far, for the sake of simplicity, we have assumed that all plaintext blocks are zero. We now examine what happens if we remove that assumption, and integrate plaintext variables into our analysis. What we show is that plaintext variables only contribute linearly to the trail. In other words, the full trail equation with plaintext variables is equal to the full trail equation with all-zero plaintext XORed with a linear combination of plaintext variables.

To see this, recall that plaintext bits contribute to the encryption process in two ways (cf. \Cref{subsec/Spec}):
\begin{enumerate}
\item They are added to some bits derived from the state to form the ciphertext.\label{item:1}
\item During each encryption step, the \StateUpdate{} function adds a plaintext block to every register except $S_0$.\label{item:2}
\end{enumerate}

The effect of \Cref{item:1} is that whenever we use a ciphertext bit in our full trail equation, the corresponding plaintext bit also needs to be XORed in. Because ciphertext bits only contribute linearly to the trail equation, this only adds a linear combination of plaintext bits to the equation.

Regarding \Cref{item:2}, recall that the full trail equation is a linear combination of (the symmetrized version of) equations $A^t_i$, $B^t_i$, $C^t_i$, $D^t_i$, $E^t_i$ in \Cref{sec:minitraileq}. Also observe that in each equation, state bits that are shifted by a word-wise rotation only contribute linearly. Because plaintext bits are XORed into each register at the same time word-wise rotation is performed, this implies that plaintext bits resulting from \Cref{item:2} also only contribute linearly.
In fact in all cases, it so happens that updating the equation to take plaintext variables into account simply involves XORing in the plaintext bit $M^t_i$.

It may be observed that message blocks in the \StateUpdate{} function only contribute linearly to the state, and in that regard play a role similar to key bits in an SPN cipher; and indeed in SPN ciphers, it is the case that key bits contribute linearly to linear trails \cite{eurocryptMatsui93}. In this light the previous result may not be surprising.

In the end, with variable plaintext, our trail yields a biased linear combination of ciphertext bits and plaintext bits.
In regards to attacks, this means the situation is effectively the same as with a biased stream cipher: in particular if the plaintext is known we obtain a distinguisher; and if a fixed unknown plaintext is encrypted multiple times (possibly also with some known variable part) then our trail yields a plaintext recovery attack.

%%% Local Variables:
%%% TeX-master: "morusAC"
%%% End:


% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.

      \subsection{predcost.m}

\begin{par}
\textbf{Summary:} Compute trajectory of expected costs for a given set of state distributions
\end{par} \vspace{1em}
\begin{par}
inputs: m0          mean of states, D-by-1 or D-by-K for multiple means S           covariance matrix of state distributions dynmodel    (struct) for dynamics model (GP) plant	      (struct) of system parameters policy      (struct) for policy to be implemented cost        (struct) of cost function parameters H           length of optimization horizon
\end{par} \vspace{1em}
\begin{par}
outputs: L            expected cumulative (discounted) cost s            standard deviation of cost
\end{par} \vspace{1em}
\begin{par}
Copyright (C) 2008-2013 by Marc Deisenroth, Andrew McHutchon, Joe Hall, and Carl Edward Rasmussen.
\end{par} \vspace{1em}
\begin{par}
Last modified: 2012-01-12
\end{par} \vspace{1em}

\subsection*{High-Level Steps}

\begin{enumerate}
\setlength{\itemsep}{-1ex}
   \item Predict successor state distribution
   \item Predict corresponding cost distribution
\end{enumerate}

\begin{lstlisting}
function [L, s] = predcost(m0, S, dynmodel, plant, policy, cost, H)
\end{lstlisting}

\subsection*{Code}

\begin{lstlisting}
L = zeros(size(m0,2),H); s = zeros(size(m0,2),H);
for k = 1:size(m0,2);
  m = m0(:,k);
  for t = 1:H
    [m, S] = plant.prop(m, S, plant, dynmodel, policy);	     % get next state
    [L(k,t), d1, d2, v] = cost.fcn(cost, m, S);              % compute cost
    s(k,t) = sqrt(v);
  end
end
L = mean(L,1); s = mean(s,1);
\end{lstlisting}


\documentclass{beamer}
\usefonttheme[onlymath]{serif}
\usepackage[english]{babel}							%For internationalization
\usepackage[utf8]{inputenc}							%For character encoding
\usepackage{amsmath}								%For mathematical typesetting
\usepackage{amssymb}								%For mathematical typesetting
\usepackage{graphicx}								%For handling graphics

\newcommand{\be}{\begin{equation}}
\newcommand{\bea}{\begin{equation*}}
\newcommand{\ben}[1]{\begin{equation}\label{#1}}
\newcommand{\ee}{\end{equation}}
\newcommand{\eea}{\end{equation*}}
\newcommand{\aq}{\overset{\sim}{q}}

\mathchardef\mhyphen="2D

\title
{An Introduction to Discontinuous Galerkin Methods}
\subtitle{Module 3B: To Higher-Orders - Discrete System}
\author[Bevan]
{J.~Bevan}
\institute[UMass Lowell]
{
  Department of Mechanical Engineering, Grad Student\\
  University of Massachusetts at Lowell
}
\date[Fall 2014]
{}
\subject{Discontinuous Galerkin}

\begin{document}
\frame{\titlepage}
\frame{\frametitle{Module 3B: To Higher-Orders - Discrete System}\tableofcontents}

%NEW SECTION
\section{Numerical Quadrature (Gauss)}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We now have a method for generating a robust arbitrary order solution approximation, but unlike before it isn't practical to analytically pre-calculate all the integrals.
\item We can use a numerical quadrature technique to do this instead, able to integrate arbitrary functions
\item If we call the interpolation of a function $In f$ then we assume that for a sufficiently accurate interpolation, we can use the interpolation of the function wherever we could use the function itself before. This is in general M-1 order accurate.
\be f \approx In f =\sum_{i=0}^M f(x_i)L_i(x) \ee
\end{itemize}
\be \int f \approx \int In f = \int \sum_{i=0}^M f(x_i)L_i(x) =  \sum_{i=0}^M f(x_i) \int L_i(x) =  \sum_{i=0}^M f(x_i)w_i\ee
}

%NEW SECTION
\section{Hermite Interpolation (and quadrature)}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item Recall: Hermite interpolation includes derivatives of interpolated function as well
\item Consider a Hermite interpolation polynomial that includes first derivatives as well, the interpolation would be $2M-1$ accurate. The quadrature using this polynomial would look like:
\be \int f \, dx \approx \sum_{i=0}^M f(x_i)w_i+\sum_{i=0}^M\left[ f'(x_i)\int (x-x_i)L_i^2(x) \, dx \right] \ee
\item It turns out if we choose our quadrature/interpolation points to be the Legendre roots, the integral for the second term is zero. Thus no first derivative terms are needed for the Hermite quadrature, even though it is $2M-1$ order accurate.
\end{itemize}
}

%NEW SECTION
\section{Truncation error/exact quadrature}
\frame[shrink]{\frametitle{\textbf{\secname}}
\begin{itemize}
\item It is important to consider error sources from the approximation to the solution and integrals, these can affect convergence
\item Three main error sources in quadrature: aliasing, truncation, and inexact quadrature
\item Aliasing occurs if the function is not sampled frequently enough, it is assumed that the sol'n is sufficiently smooth and the discretization suitably fine to avoid this in most cases
\item Truncation is unavoidable except where the exact function is of equal or lesser order than the interpolation/quadrature. Higher order terms present in the exact function are left off.
\item Inexact quadrature occurs when the total polynomial order of the product of the interpolated functions undergoing quadrature exceeds the exactness of the quadrature. For Gauss-Legendre quadrature this isn't a problem for one and even two functions in the integrand. Each function is of order M-1 and the quadrature is exact for 2M-1, so the quadrature is able to exactly integrate the interpolation
\end{itemize}
}

%NEW SECTION
\section{GL Lagrange Orthogonality}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item A final useful property of the Lagrange basis with Legendre interpolation points is orthogonality
\item The product of two $M-1$ order Lagrange bases can be rearranged to be a Legendre poly of order $M$ and a remainder polynomial of order $M-2$
\item The remainder polynomial can be expressed as a linear combination of Legendre polys all of order $<M$, all are orthogonal to the order $M$ Legendre, so
\be \int_{-1}^1 L_i(x)L_j(x) \,dx = \delta_{ij}w_i \ee
\end{itemize}
}

%NEW SECTION
\section{Local Mapping Function (Jacobian)}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item The domain of orthogonality for Legendre polynomials (and by extension GL Lagrange) is $[-1, 1]$
\item Elements may be arbitrary sizes though, we'd like to be able to transform $x \in [x_L, x_R] \rightarrow X \in [-1, 1]$ by means of a mapping $x=g(X)$ and it's inverse $X=G(x)$
\be x=g(X)=\frac{X+1}{2}\Delta x + x_L\quad ,\quad X=G(x)=\frac{2(x-x_L)}{\Delta x}+1 \ee
\item Applying a change of variables for the mapping
\be \int_{x_L}^{x_R} L_i(x) L_j(x) \,dx \rightarrow \int_{-1}^1 L_i(g(X))L_j(g(X)) g' \, dX \ee
\item $J=g'=\frac{\Delta x}{2}$ is called the determinant of the Jacobian matrix
\end{itemize}
}

%NEW SECTION
\section{Mass Matrix- Diagonalization}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We have done what seems like quite a bit of tangential work, but it now pays off
\be \sum_{i=0}^M \frac{d \aq_i}{dt} \int_k \psi_i(x) \phi_j(x) \,dx = \sum_{i=0}^M \frac{d \aq_i}{dt} \int_I L_i(X) L_j(X) \frac{\Delta x}{2} \,dX \ee
\be=   \frac{\Delta x}{2} \sum_{i=0}^M \frac{d q_i}{dt} \delta_{ij}w_i =  \frac{\Delta x}{2}q_j'w_j \quad for\,all\, j \ee
\item We've reduced the full mass matrix into a diagonal mass matrix with all other terms zero, compared to Module 2 solver case the mass matrix is trivially invertible. We have: $\frac{\Delta x}{2}\mathbf{q' \,M}$ where $\mathbf{M}_{jj} = w_j$
\end{itemize}
}

%NEW SECTION
\section{Log differentiation}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We can get a closed form expression for $L_j'(x)$ in the stiffness term by using logarithmic differentiation
\item The main idea is that in general $f'/f = ln(f)$ so applying this to our Lagrange basis
\be L_j'(x) = L_j \sum_{r=0,r\neq j}^N \frac{1}{x-x_r} \ee
\item using our previous function code for "\textit{Lag(x)}" we can get a general expression
\textit{dLag= @(x,nv) Lag(x,nv).*sum(1./bsxfun(@minus,x,nn(nv,:,:)),3)}
\item We need a more involved method for evaluation at the interp points (see dLagrange.m)
\end{itemize}
}

%NEW SECTION
\section{Stiffness Integral}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We now have a routine for calculating $L_j'$, and suitable quadrature; we can evaluate the stiffness integral
\be \int_k \, \sum_{i=0}^M\left[ c\aq_i \psi_i(x)\right] \phi'_j(x) \,dx = \sum_{i=0}^M c\aq_i \int_I L_i(X) L_j'(X) \,dX \ee
\item No Jacobian term from the mapping. The derivative in the integrand produces a complementary $1/J$ that cancels due to the change of variables.
\item No tricks to be had for reducing the stiffness matrix, it is a full matrix. We have: $c\mathbf{K}_{ji} \, \mathbf{\aq}$
\end{itemize}
}

%NEW SECTION
\section{Numerical Flux (Extrapolated)}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item One downside of using Gauss-Legendre points is there are no points on the boundary
\item It is easy to calculate the boundary solution values from the solution interpolation at the left end (same idea for the right)
\be \aq(x_L) = \sum_{i=0}^M \aq_i L_i(x_L) \ee
\item Call $L_i(x_L) = L_{iL}$, the vector notation is then $\aq_L = \mathbf{L}_{iL}^T \, \mathbf{\aq}$
\item So that our numerical flux vector is $\mathbf{\hat{f}} =c(\overset{k}{q}_R\mathbf{L}_{jR}-\overset{k-1}{q_R}\mathbf{L}_{jL})$
\item Lobatto alternative gives boundary points, but would make the mass matrix a full matrix. Inversion is likely more expensive than interpolation
\end{itemize}
}

%NEW SECTION
\section{Assembly of System}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item We can now combine the mass, stiffness, and numerical flux terms
\be \frac{\Delta x}{2}\mathbf{q' \,M} + \mathbf{\hat{f}} -  c\mathbf{K}_{ji} \, \mathbf{\aq}=0 \ee
\item solving for $q'$
\be \mathbf{\aq}' = \frac{2}{\Delta x} (c\mathbf{K}_{ji} \, \mathbf{\aq} -\mathbf{\hat{f}}) \mathbf{M}^{-1} \ee
\item it is also possible to represent it componentwise easily thanks to the diagonal mass matrix
\be \aq_j' = \frac{2}{w_j\Delta x }(c \mathbf{K}_{j\mhyphen}\mathbf{\aq}-\hat{f}_j)\ee
\end{itemize}
}

%NEW SECTION
\section{RK4 Time discretization}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item Compared to the simple linear DG solver, we'd like to use a higher order time discretization, Runge-Kutta 4th order: RK4. We can express as a function: $\mathbf{\aq}'(\mathbf{\aq})$ from our discrete system. RK4 consists of 4 trial steps:

$k_1 =  \mathbf{\aq}'(\mathbf{\aq}) \, \Delta t$\\
$k_2 =  \mathbf{\aq}'(\mathbf{\aq}+\frac{k_1}{2}) \, \Delta t$\\
$k_3 =  \mathbf{\aq}'(\mathbf{\aq}+\frac{k_2}{2}) \, \Delta t$\\
$k_4 =  \mathbf{\aq}'(\mathbf{\aq}+k_3) \, \Delta t$\\
$\mathbf{q}(t+1) = \mathbf{q} + \frac{k_1}{6}+ \frac{k_2}{3}+ \frac{k_3}{3}+ \frac{k_4}{6}$
\end{itemize}
}

%NEW SECTION
\section{Investigate p-Convergence}
\frame{\frametitle{\textbf{\secname}}
\begin{itemize}
\item How does the p-convergence rate compare with h-convergence?
\item Does the smoothness of the initial sol'n seem to effect the rate of convergence? (e.g. sin(x) vs gaussian curve)
\item Does h or p refinement seem to be more efficient?
\end{itemize}
}

\end{document}


\section{Introduction}

The interpretation of total-field anomalies on the surface of the Earth is an
important challenge in exploration geophysics due to the nonuniqueness of 3-D magnetic
inversion. It is well-known that several magnetization distributions in the subsurface
can reproduce the same magnetic data with the same accuracy.
To overcome this inherent ambiguity, a priori information needs to be introduced
for reducing the number of possible solutions that are coherent with the local geology.
The available a priori information determines the suitable inversion method to be applied.
As explained below, we identified, in the literature, three groups of 3-D magnetic inversion methods.

The first group of inverse methods approximates the source by a geometrically
simple causative body having its geometry defined by a small number of parameters
\cite[e.g., ][]{ballantyne-1980,bhattacharyya-1980,silva-1983,medeiros_silva1995}. These methods
estimate both the geometry and the physical property of the source by solving
a nonlinear inverse problem. Due to the very restrictive parametrization,
such methods usually do not have severe problems with ambiguity.

The second group of inverse methods is formed by the vast majority of methods.
These methods approximate the subsurface by a grid of juxtaposed rectangular prisms having
a constant total-magnetization direction. Some methods presume a purely induced
magnetization and the isotropic magnetic susceptibility of the prisms is the quantity estimated by solving a linear inverse problem.
Some examples of this linear inversion are presented by \cite{cribb-1976}, \cite{li_3-d_1996} and \cite{pilkington_3-d_1997}.
Different approaches have improved this linear inversion to obtain focused images of the subsurface.
For example, \cite{portniaguine_focusing_1999} and \cite{portniaguine_3d_2002} introduced the minimum gradient support functional, similar to the one proposed by
\cite{last-1983} that minimizes the volumes of the sources in a gravity data inversion.
By inverting magnetic anomaly and any component of the total anomalous field, this functional estimates a magnetization distribution that generates a non blurry (focused) 3-D image of the geologic bodies in the subsurface.
\cite{barbosa_interactive_2006} presented a method for inverting interfering magnetic anomalies produced by multiple sources by combining features of the forward modeling (the interactivity) and traditional inversion (the automatic data fitting). Other studies introduced strategies to constraint the nonuniqueness and delineate the source \cite[]{tontini,pilkington_3d_2009,shamsipour_3d_2011,cella_inversion_2012,abedi-2015}.
Some of these methods allowed remanent magnetization \cite[e.g., ][]{pignatelli-2006}.
In this case, the parameters to be estimated are the total-magnetization intensities
of the prisms.
In all these methods, the geometries of the magnetic sources are indirectly retrieved by interpreting the estimated total-magnetization intensity
distribution.
Theoretically, these inversion methods are capable of recovering the geometry of complex
sources. However, they require a plethora of a priori information to overcome
their nonuniqueness and instability due to the large number of parameters
to be estimated. Additionally, they are characterized by a high
computational cost associated with the solution of large linear systems.

The third group of 3-D magnetic inversion methods requires some knowledge about the
physical property distribution to estimate the geometry of the sources.
They are usually formulated as nonlinear inverse problems.
\cite{wang_inversion_1990} approximated the source by a polyhedron and estimate
the position of its vertices in the Fourier domain.
\cite{wenbin-2017} developed a multiple level-set method to estimate geometry
of a set of causative bodies with uniform magnetic susceptibility.
\cite{hidalgo-2019} inverted the total-field anomaly for estimating the depths to the top of a magnetic basement of a sedimentary basin with known magnetization intensity but unknown magnetization direction.
An inverse method in this third group has a small number of parameters to be estimated by inversion and has much less ambiguity in comparison to the second group.

By following the third group of 3-D magnetic inversion methods,
we present a method to estimate the geometry, position and total-magnetization
intensity of an isolated and uniformly magnetized 3-D source with known
total-magnetization direction.
Our method is an extension of the methods presented
by \cite{oliveirajr-etal2011} and \cite{oliveirajr-barbosa2013} for inverting, respectively,
gravity and gravity-gradient data, applied to the total-field anomaly.
We approximate the source by a stack of vertically juxtaposed
right prisms with polygonal horizontal cross-sections and the same number of vertices.
All prisms have the same thickness and total-magnetization intensity.
Differently from \cite{oliveirajr-etal2011} and \cite{oliveirajr-barbosa2013},
our method estimates not only the horizontal Cartesian coordinates of the origins and the radii of the vertices describing the horizontal cross-sections of all prisms but also the thickness of all prisms comprising the interpretation model, as well as
two additional parameters: the depth to the top of the shallowest prism and the
total-magnetization intensity of all prisms.
We perform a series of inversion runs using different value combinations of these two parameters and compute a goal function associated with each of the trial solutions.
Among the estimated models, those producing the
lowest values of goal function form the set of candidate models.
To obtain stable solutions, we use the same set of regularizing functions proposed by
\cite{oliveirajr-etal2011} and also propose a new one for constraining the
thickness of the prisms.
Following \cite{oliveirajr-etal2011} and \cite{oliveirajr-barbosa2013}, we refer to the proposed method as \textit{radial inversion} because our method estimates the radii of the vertices describing the horizontal cross-sections of all prisms.
Tests on synthetic data and on airborne magnetic data collected over the alkaline-carbonatitic complex of Anit{\'a}polis, in southern Brazil, show the potential of our method in retrieving 3-D magnetic bodies even if they exhibit a variety of shapes and depths.


\subsection{Trivial and twisted bundles}