\documentclass[index]{subfiles}

\begin{document}
\title{Noise Cancellation}
\date{}
\author{}
\maketitle

\section{Research Question}

How does the difference in phase between two waves affect the sound intensity at the midpoint point between them?

\section{Background}

My home has always been slightly noisy, perhaps due to its positioning facing the living room or my little brother's whining. I've tried blocking the door with a mattress or blocking my ears with some headphones, but I've never thought of suppressing a sound wave with another sound wave until hearing the concept of wave interference of light in my physics class. I do have a set of speakers connected to my computer. This lab aims to explore both the mechanics and concepts behind noise-cancellation and explore at what delays between phases is noise-cancellation the most optimal.

\subsection{Wave Interference}

The waves explored in this lab both have the same frequency and wavelength, so the first thing that comes to mind between these two waves that might cause a change in sound intensity is wave interference.
Wave interference essentially occurs when two waves meet together. There are two types of wave interference, constructive and destructive interference. These types of interference occur situationally depending on the relative position of the two waves. When identical waves match up exactly, perfect constructive interference may occur, causing the amplitude of the resulting wave to double. Conversely, when the two waves are exactly \(\frac{1}{2}\lambda\) apart in position, they are out of phase, and perfect destructive interference occurs, which causes the effective amplitude of the resulting combined wave to be zero.\cite{openstax}

\subsection{Sound Intensity}

However, the amplitude changes caused by constructed and destructive interference don't necessarily translate directly to the sound level of the wave. Still, through background research, there is evidence that these values do correlate.

From the formula for simple harmonic motion of a particle in a wave moving up and down, we derive the equation \(E=2\pi^2dAvf^2x^2\)\cite{giancoli1995physics}. This equation effectively shows that the energy of the wave is proportional to the square of its amplitude\cite{openstax}.

Furthermore, the sound intensity of a wave depends both on the wave's energy and the area in which it travels. It's proportional to power and inversely proportional to the area as shown by the equation \(I=\frac{P}{A}\), where \(A\) is a square unit of area.\cite{openstax}. And power relates to energy because it is defined as energy over time \(P=\frac{W}{t}\).

Thus, it is reasonable to deduce that constructive and destructive interference influence the wave's amplitude, which affects the wave's energy, which subsequently affects the power and sound intensity.

\subsection{Sound Level}

In this lab, equipment measures the decibel sound level, not the sound intensity directly, so it is necessary to understand the relationship between sound level and sound intensity.

While sound intensity is helpful for calculating energy levels, humans don't react to sound intensity at a linear level. Instead, the relationship is more of an exponential nature. Decibels factor this in, as louder sounds need exponentially more energy to sound ``louder'' to humans, and conversely, quiet sounds need exponentially less energy to sound more quiet\cite{openstax}.

This equation can be given by
\[
    \beta\left(dB\right)=10\log_{10}\left(\frac{I}{I_{0}}\right)
    ,\] where \(I_{0}\) is a constant with a value of \(1\cdot10^{-14}\frac{W}{m^2}\) based off the human hearing threshold\cite{openstax}.

It should be noted that the average sound level of a normal conversation is around 70 decibels.\cite{speakers}.

\subsection{Speakers}

Because speakers will generate the sound waves of this experiment, it is necessary to understand, at least at a basic level, how speakers function.\cite{speakers}

Dynamic speakers use electric signals to general sound. When electric signals travel into a coil, a magnetic field is generated, and this causes an oscillatory motion between the cone and the coil\cites{openstax}{speakers}, resulting in air molecules being moved and, therefore, sound waves to be produced.

\section{Hypothesis}

The difference in displacement between two in-phase waves would have a sinusoidal relationship with the sound intensity due to constructive and destructive interference causing cyclic patterns of change in amplitude of the resulting sound.

\subsection{Prediction Graph}

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.3]{res/prediction.png}
    \caption{The red/center line is the predicted sound intensity when the second wave is phase-shifted exactly \(\frac{1}{2}\lambda \) away from each other.}
\end{figure}

\section{Variables and Explanations}

\subsection{Independent Variable}

The independent variable, in this case, would be the phase-shifted distance between the two waves. Its units would be in a decimal ratio of the wavelength of the sine wave (with a frequency of 264 Hz).

We use a computer program to generate this wave from speakers to change this variable.

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.2]{res/layout.png}
    \caption{Overview of the computer program}
\end{figure}

To produce a natural sound wave from the speakers, we have to input data points into the sound interface. Most data points for sound are stored before they are accessed (for example, in an \textit{.mp3} file). But in this case, to get a static noise, we chose to sample the \textbf{amplitude} of \(\sin\) function to create the data points needed for our sound wave.

We plug in the simple time for one function into sin, then plug in the time + the offset lambda (our \textbf{independent variable}), sampling one wave and outputting it to the left speaker, and sampling the other wave and outputting it to the right speaker, concurrently. \footnote[1]{the source code for the full program, as well as this paper, can be found at \href{https://github.com/SpicyRicecaker/2021.phase\_shift\_sound\_level}{https://github.com/SpicyRicecaker/2021.phase\_shift\_sound\_level}}\footnote[2]{see appendix}.

We increment our current time  by \verb+delta_t+ and its value is \(\frac{1}{48,000}(seconds)\), meaning we'll sample \(48,000\) points every second from our \(\sin\) wave.

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.15]{res/sampling.png}
    \caption{Example of how a sine wave is sampled over a period of 1s}
\end{figure}

The reason that our \verb+delta_t+ is that value is that the specific speaker used in this experiment has a maximum sample rate of \(48,000Hz\). The effect that higher and lower sample rates have on sound waves produced by the speaker is beyond the scope of this paper.

Finally we find the amplitude of the ``control wave'' (the wave in which there is no phase change is calculated) using the following function
\begin{equation*}
    A\cdot\sin\left(ft\cdot2\pi\right)
\end{equation*}, where \(f\) is the frequency of the wave (which is \(264\)), \(t\) is the current time, and \(A\) is the amplitude of the wave.

We also have \(2\pi\), because recall that the period of a \(\sin\) wave is \(\frac{2\pi}{B}\), where \(B\) is the coefficient modifying the \(X\). Since frequency is \(\frac{1}{T}\), that means the frequency of a wave is \(\frac{B}{2\pi}\). So if we want our frequency of \(264\) to be true, we add the \(2\pi\)
\begin{align*}
    frequency & =\frac{B}{2\pi}            \\
              & =\frac{264\cdot2\pi}{2\pi} \\
              & =264
\end{align*}

Finally, we calculate the phase-shifted wave by simply adding the phase shift to the time, divided by the frequency, \(f\).

\begin{equation*}
    A\cdot\sin\left(f\left(t+\frac{\lambda}{f}\right)\cdot2\pi\right)
\end{equation*}

We divide by the frequency because our phase shift is a ratio from 0 to 1, and a frequency of \(264\) means that the wave is going down 264 times a second, meaning its wavelength is not equal to 1.

The uncertainty in this independent variable is practically negligible, as the increments in phase shift of \(0.05\) are directly stored in the computer program as floating-point values, the inaccuracy of which is beyond the scope of this paper.

\subsection{Dependent Variable}

The sound intensity will be the dependent variable of the equation, measured in decibels. TO get this value, first the sound level will be measured will be taken with the microphone on a used Samsung Galaxy Note9, placed in exactly the center of the distance between the two speakers, measured by a ruler. The sound meter app will run for twenty seconds, and the average sound level during that time will be recorded.

The uncertainty here will arise from the microphone's sensitivity, the precision of the sound meter app, ambient noise, and other unexpected noise from the environment, which would heavily impact the data from the experiment if it is not controlled. Then, the sound level will be converted into sound intensity using the equation \(s=10\log(\frac{I}{I_0})\).

\subsection{Controlled Variable}

\textbf{The distance between the two speakers} must be kept constant in every trial. As sound spreads out, it loses power exponentially, so pulling the speakers too far apart will decrease the measured sound level, and positioning the speakers too close together would increase the measured sound level. The distance between the two speakers would also directly impact the \textit{phase shift} between the two waves. For example, for a \(\sin\) wave of 264 Hz (around middle C frequency), the wavelength is only around \(1.30m\) meters, so a slight shift in speaker distance in the tens of centimeters could invalidate the whole experiment. Therefore, to keep the distance between the two waves equivalent, a ruler will be used to measure precisely \(1.30m\) from the base of one speaker to the other.

\textbf{The position of the microphone} should be kept constant in every trial. For perfect destructive interference, the amplitude of the wave at any point between the two speakers would be zero. However, in other cases, the amplitude of the resulting wave could theoretically differ. Putting the microphone further away from the speakers would also decrease sound levels because energy travels away in a sphere, so much of it is lost to the environment further out.

Finally, the speakers should be positioned facing each other on the same axis. As the speakers are spherical, placing one speaker facing away would result in the waves not interacting. A ruler will be used to ensure that the tip of the phone is aligned precisely to \(0.65m\) and to mitigate position differences in the axis between speakers.

\textbf{The frequency and wavelength of the two waves} The frequency of two waves should be kept the same at \(264Hz\) throughout all trials. For perfect constructive and destructive interference to occur, the two waves must be perfectly in-phase with each other. Otherwise, the resulting wave would be very uneven, and there would be varying results every time.

\textbf{The temperature of the room} The temperature of the room should be kept constant because the temperature and movement of particles in the air affect the amount of energy lost as the wave propagates forward.

\textbf{Ambient Sound Level} The ambient sound level should be kept constant because otherwise, the dependent variable of sound level would be modified not just by the independent variable but also by the environment, which would invalidate the experiment. Four chairs will be placed surrounding the two speakers, and blankets draped over them and the top of the speakers, to decrease ambient sound levels' effects on the final experiment.

\textbf{Volume of the Speaker and Operating System} There are two places where the general output volume of the speaker can be modified. One avenue is via the operating system (when the press the volume up and volume down keys are pressed on the keyboard), and the other, volume buttons on the external speaker. As these sound levels vary across speakers and operating systems, this paper will not provide a constant value for assigning these two values. Still, the volume controls will be tuned to an acceptable midlevel volume that references that abides by the safe sound levels specified by NIOSH (see safety sections below). They will also be kept constant when the experiment is carried out.

\section{Method}

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.22]{res/sound_diagram.png}
    \caption{Sketch of experiment setup.}
\end{figure}

\begin{enumerate}
    \item Position two identical speakers 1.30 meters apart from each other, with their fronts aligned straight towards each other
    \item Connect both speakers via cable to a computer
    \item Put a phone face up on the midpoint of the distance between the two speakers
    \item Set the phase-shift of the wave to \(0\lambda\) through the computer program
    \item Run the computer program that plays a monotone sine wave at a frequency of 264 Hz through one speaker and an identical phase-shifted wave through the other speaker at the same time.
    \item After the speakers have started playing for at least 5 seconds, begin recording audio on the phone for 20 seconds.
    \item After 20 seconds, pause the recording app on the phone and record the average sound level displayed on the app
    \item Repeat this recording process 3 times and take the average of the three trials
    \item Repeat the entire experiment, incrementing the phase-shift defined in step 4 by \(0.05\lambda\), all the way up to and including a full phase shift of \(1\lambda\)
\end{enumerate}

\subsection{Safety}

Safety precautions should be made to ensure that the speaker sound levels do not go above maximal decibel sound levels that humans are tolerant of to preserve the ear's health. According to the NIOSH recommendations, a human should not be exposed to a constant sound level of 85 dBAs for greater than eight hours~\cite{cdc}. To make sure that sound levels never get close to 85 dBAs, the sound level when speakers are playing will be observed on the sound meter app at all times.

\section{Raw Data Table}

% \begin{table}[H]
%     % the @{} removes minimal padding
%     % llr stands for left and right centering
%     \begin{tabular}{@{}ccc@{}} \toprule
%                                                 % create a midrule spanning the first and second columns
%         \multicolumn{2}{c}{Item}             \\ \cmidrule(r){2-2}
%         Animal    & Description & Price (\$) \\ \midrule
%         Gnat      & per gram    & 13.65      \\
%                   & each        & 0.01       \\
%         Gnu       & stuffed     & 92.50      \\
%         Emu       & stuffed     & 33.33      \\
%         Armadillo & frozen      & 8.99       \\ \bottomrule
%     \end{tabular}
% \end{table}
% \begin{table}[]
%     \begin{tabular}{rrrrrr}
%         \multicolumn{1}{l}{Phase shift (ratio out of 1 wavelength)} & \multicolumn{1}{l}{Trial 1} & \multicolumn{1}{l}{Trial 2} & \multicolumn{1}{l}{Trial 3} & \multicolumn{1}{l}{Average} & \multicolumn{1}{l}{Uncertainty} \\
%     \end{tabular}
% \end{table}

\begin{table}[H]
    \caption{Effect of Phase Shift on Sound Level}
    \centering
    \begin{tabular}{@{}cccccc@{}} \toprule
                                             & \multicolumn{3}{c}{Sound Level (dB) \(\pm\ 0.1\)}                                             \\ \cmidrule(r){2-4}
        Phase shift (\(\lambda\)) \(\pm\ 0\) & Trial 1                                           & Trial 2 & Trial 3 & Average & Uncertainty \\ \midrule
        0.00                                 & 52.5                                              & 52.4    & 52.4    & 52.4    & 0.1         \\
        0.05                                 & 52.8                                              & 52.7    & 52.7    & 52.7    & 0.1         \\
        0.10                                 & 52.8                                              & 52.7    & 52.8    & 52.8    & 0.1         \\
        0.15                                 & 52.7                                              & 52.6    & 52.6    & 52.6    & 0.1         \\
        0.20                                 & 52.2                                              & 52.3    & 52.3    & 52.3    & 0.1         \\
        0.25                                 & 51.7                                              & 51.7    & 51.7    & 51.7    & 0.1         \\
        0.30                                 & 50.8                                              & 50.8    & 50.9    & 50.8    & 0.1         \\
        0.35                                 & 49.5                                              & 49.6    & 49.6    & 49.6    & 0.1         \\
        0.40                                 & 47.9                                              & 48.0    & 48.0    & 48.0    & 0.1         \\
        0.45                                 & 45.8                                              & 45.8    & 45.8    & 45.8    & 0.1         \\
        0.50                                 & 43.1                                              & 43.1    & 43.0    & 43.1    & 0.1         \\
        0.55                                 & 40.1                                              & 39.9    & 40.1    & 40.0    & 0.1         \\
        0.60                                 & 39.2                                              & 39.1    & 39.1    & 39.1    & 0.1         \\
        0.65                                 & 41.2                                              & 41.3    & 41.2    & 41.2    & 0.1         \\
        0.70                                 & 45.3                                              & 45.3    & 45.4    & 45.3    & 0.1         \\
        0.75                                 & 47.8                                              & 47.8    & 47.7    & 47.8    & 0.1         \\
        0.80                                 & 49.5                                              & 49.5    & 49.5    & 49.5    & 0.1         \\
        0.85                                 & 50.8                                              & 50.8    & 50.8    & 50.8    & 0.1         \\
        0.90                                 & 51.8                                              & 51.8    & 51.8    & 51.8    & 0.1         \\
        0.95                                 & 52.5                                              & 52.5    & 52.5    & 52.5    & 0.1         \\
        1.00                                 & 52.9                                              & 52.8    & 52.9    & 52.9    & 0.1
    \end{tabular}
\end{table}

\begin{table}[H]
    \caption{Ambient Sound Level (control)}
    \centering
    \begin{tabular}{@{}lll@{}} \toprule
        \multicolumn{3}{c}{Sound Level (dB) \(\pm\ 0.1\) } \\ \cmidrule(r){1-3}
        Trial 1 & Trial 2 & Trial 3                        \\ \midrule
        25.2    & 25.2    & 25.2
    \end{tabular}

\end{table}

\section{Sample Calculations}

For the sample calculations below, \(\sigma_x\) represents the uncertainty for value \(x\).

\begin{align*}
    \intertext{\textbf{Average Sound level}}
    \intertext{The formula for the sound level, \(T_{average}\) is given by}
    T_{average}          & = \frac{T_{1}+T_{2}+T_{3}}{3}
    \intertext{\textbf{Propogation of Uncertainty for \(T_{average}\)}}
    \intertext{The first way to propogate uncertainty is as follows}
    \sigma_{T_{average}} & = \frac{\sigma_{T_{1}} + \sigma_{T_{2}} + \sigma_{T_{3}}}{3}
    \intertext{\textit{Example} calculation of propogation of uncertainty given three sound levels at a phase shift of \(0.55\lambda\)}
                         & = \frac{.1 + .1 + .1}{3} = .1
    \intertext{\textbf{Conversion from sound level to sound intensity}}
    \intertext{The formula for equation for sound level is defined by}
    s                    & =10\log_{10}\left(\frac{I}{I_{0}}\right)                                                                                \\
    \intertext{We solve for intensity, then use this to solve for future intensity values.}
    I                    & =I_{0}\cdot10^{\frac{s}{10}}
    \intertext{\textit{Example} calculation of sound level to sound intensity for a sound level of \(50.8 dB\)}
    I                    & =I_{0}\cdot10^{\frac{s}{10}}                                                                                \\
                         & =\left(10\cdot10^{-12}\frac{W}{m^{2}}\right)\left(10^{\frac{50.8}{10}}\right)                                               \\
                         & =1.2\cdot10^{-6}\frac{W}{m^{2}}
    \intertext{\textbf{Propagation of uncertainty for Intensity \((I)\)}}
    \intertext{The uncertainty for sound intensity given the equation \(I=I_{0}\cdot10^{\frac{s}{10}}\) can be derived using}
    \sigma_{I}           & =I'\cdot\sigma_{s}                                                                                \\
                         & =\left(\frac{\ln\left(10\right)}{10}\left(1\cdot10^{-12}\frac{W}{m^{2}}\right)\cdot10^{\frac{s}{10}}\right)
    \intertext{\textit{Example} calculations for propagation of uncertainty for sound level of \(50.8\ dB\)}
    \sigma_{I}           & =\left(\frac{\ln\left(10\right)}{10}\left(1\cdot10^{-12}\frac{W}{m^{2}}\right)\cdot10^{\frac{\left(50.8\right)}{10}}\right) \\
                         & =2.8\cdot10^{-8}\frac{W}{m^{2}}
\end{align*}

\section{Calculated Data Table}

\begin{table}[H]
    \centering
    % the X in tabularx expands cell to fill
    % >{} applies command to every single cell
    \caption{The effect of phase shift on sound intensity}
    \begin{tabular}{@{}cS[table-format=1.2e-2]S[table-format=1.1e-2]@{}} \toprule
        {Phase shift \((\lambda) \pm 0\)} & {Sound Intensity \((\frac{W}{m^2})\)} & {Uncertainty \((\frac{W}{m^2})\)} \\ \midrule
        0.00                              & 1.75e-07                              & 4.0e-08                           \\
        0.05                              & 1.88e-07                              & 4.3e-08                           \\
        0.10                              & 1.89e-07                              & 4.4e-08                           \\
        0.15                              & 1.83e-07                              & 4.2e-08                           \\
        0.20                              & 1.69e-07                              & 3.9e-08                           \\
        0.25                              & 1.48e-07                              & 3.4e-08                           \\
        0.30                              & 1.21e-07                              & 2.8e-08                           \\
        0.35                              & 9.05e-08                              & 2.1e-08                           \\
        0.40                              & 6.26e-08                              & 1.4e-08                           \\
        0.45                              & 3.80e-08                              & 8.8e-09                           \\
        0.50                              & 2.03e-08                              & 4.7e-09                           \\
        0.55                              & 1.01e-08                              & 2.3e-09                           \\
        0.60                              & 8.19e-09                              & 1.9e-09                           \\
        0.65                              & 1.33e-08                              & 3.1e-09                           \\
        0.70                              & 3.41e-08                              & 7.9e-09                           \\
        0.75                              & 5.98e-08                              & 1.4e-08                           \\
        0.80                              & 8.91e-08                              & 2.1e-08                           \\
        0.85                              & 1.20e-07                              & 2.8e-08                           \\
        0.90                              & 1.51e-07                              & 3.5e-08                           \\
        0.95                              & 1.78e-07                              & 4.1e-08                           \\
        1.00                              & 1.93e-07                              & 4.5e-08
    \end{tabular}
\end{table}

\begin{figure}[H]
    \centering
    \textbf{The effect of phase shift on the sound intensity of resulting wave.}\medskip\par
    \includegraphics[scale=0.35]{res/graph-calc.png}
    \caption{\(I=9.31\cdot10^{-8}\sin\left(6.57\left(\lambda+0.14\right)\right)+9.95\cdot10^{-8}\), where \(I\) is intensity and \(\lambda\) is the phase shift.}
\end{figure}

\section{Graph and Analysis}

The line of best fit follows a curve that repetitively goes up and down, which suggests that phase shift has a sinusoidal relationship with the resulting sound level. This sinusoidal curve is representative of that of a regular wave.

The calculated sound intensity was highest at phase shift values of \(0.1\) and \(1.04\). It was lowest at the phase shift value of \(0.57\).

Another critical observation to note is the error bars of the graph, which represent uncertainty. At lower levels of sound intensity, the error uncertainty is very little, but the error bars become very large at higher levels of sound intensity. This shift in uncertainty makes sense because the sound level is a logarithmic value, so converting a logarithmic value into a scalar value such as sound intensity could incur greater uncertainty.

Earlier in the calculation section, it was shown that the uncertainty of intensity \(\sigma_{I}\) was calculated through multiplying the derivative of the function to get \(I=I_{0}10^{\frac{s}{10}}\), by the uncertainty of the measured sound level \(\sigma_{s}=0.1\). It takes exponentially more sound intensity to increase the sound level, so at a certain point, the recording device's accuracy of \(0.1 dBs\) wouldn't be able to represent minute changes in sound intensity at high sound levels. On the other hand, the decrease in uncertainty as sound levels decrease makes sense. Because it takes way less energy to reduce sound levels as sound level decreases, the recording device could much more easily pick up on changes to sound level even with its uncertainty of \(0.1 dBs\).

\section{Observations}

I noticed that the speakers radiated out their sound waves in a sphere outwards during the experiment. When I moved my ears to different areas as the speakers were running, I heard drastically different levels of loudness and quietness in other regions.

\section{Conclusion}

The experiment results confirmed my initial hypothesis that the phase shift of one wave affects the resulting recorded sound level in a sinusoidal relationship. The theory that when two waves in phase meet, their crests add up, such that overlaid waves become louder, and waves off by half a \(\lambda\) became less noisy was true.

Greater energy does result in greater amplitude, but it is essential to remember that the sound level relationship isn't purely sinusoidal because it includes logarithms and isn't uniform. Hence, it becomes harder to increase sound levels over time with constant increases in energy.
Concerning perfect destructive interference, the data suggests that sound level will decrease exponentially as the phase shift gets closer and closer to \(0.5\lambda\). In building an actual sound-cancellation device, this change should therefore be carefully inspected, as the silence is much deeper as the wavelengths line up to be around \(\frac{1}{2}\) apart.

\section{Evaluation of Strengths and Weaknesses}

\subsection{Strengths}

Using a computer program to generate the different phase-shifted waves resulted in data being collected in a smaller time frame, which minimized the impact of the environment in ambient noise level and temperature. Changing the value of the independent variable was accurate as well as simple.

\subsection{Weaknesses}

One significant source of the error was the angle between speakers. Initially, I thought it wouldn't be a problem and didn't include it in my controlled variables. However, after realizing that the speakers were spherical, the alignment of the speakers pointing directly to each other had to be done by eye. This change in alignment could have made it so that the two waves clashed at an angle. The angled waves could hold different properties than straight waves: their effective wavelengths could change, thereby throwing off the phase shift. This error could explain why the ideal phase shift for perfect destructive interference according to literature was not precisely at \(0.5\lambda\) but rather closer to \(0.6\lambda\), as well as why the effective period was not \(1\lambda\) but somewhat closer to \(0.95\lambda\).

Another primary source of error in this experiment was that it was done inside, and the sound dampening solution of four chairs and a blanket did not work out. When speakers were turned on with the blanket enclosing them, the blankets did not entirely cancel out the sound traveling towards them like I thought they would do, but rather, they seemed to \textbf{increase} the sound level if they were placed too close to the speakers. Perhaps the speakers were flatter than I thought they would be. Multiple waves bouncing together at different angles could've caused some measurable increase in peak and trough sound intensity.

% Another source of error was the \textbf{sensitivity} of the speaker. Due to limitations in physics and design, all speakers have a degree of error in the quality of sound that they can produce. Better quality speakers could be used, which would have a higher sensitivity and therefore result in fewer fluctuations in sound generated.

\section{Future Improvements}

To improve this experiment, the first step would be to conduct the experiment in a more controlled room and use better sound dampeners that would catch the sound waves instead of letting them bounce off right back towards the microphone. Improving the specificity of the microphone of the phone to include the thousandths of decibels would result in more accurate measurements. Using a protractor to ensure that the speakers are more aligned to each other would potentially get data values where the perfect destructive interference is closer to \(0.5\lambda\).

Lastly, testing greater wavelengths of phase shift, up to 2 or 3 \(\lambda\)s of phase shift, would better confirm the pattern that was concluded in this experiment.

\section{Works Cited}

\printbibliography\

\section{Appendix}

\appendix
\begin{minted}[linenos, breaklines]{rust}
    fn next(&mut self) -> Option<(f32, f32)> {
        // Add dt (sample rate) to time
        self.time += self.delta_t;
        let leading = ((self.freq * self.time * PI * 2.).sin() * self.amplitude) as f32;
        // Recall that y = sin(b(x+c))
        // Period is 2pi / b, so if we have 5 hz * 2pi, then period = 2pi / 10 pi = 1 / 5
        // This means if we want a phase shift of 1/2, we need to do 1/2 / 5, which would be 1/10
        let lagging = ((self.freq * (self.time + (self.phase_shift) / self.freq) * PI * 2.).sin()
            * self.amplitude) as f32;
        // the leading is outputted to the left speaker
        // the lagging is outputted to the right speaker
        Some((leading, lagging))
    }
\end{minted}

\end{document}


\subsection{Sparse networks}

Parameters are set to \(0\) and not trained.


% =============================================================================

The
Electronic CodeBook (ECB) mode
~\cite[Section 6.1]{NIST:sp.800.38a}
captures ``raw'' use of AES as is.  However, demand for enhanced security
properties and/or functionality, for example, has led to use of AES in a
variety of {\em other} constructions.
Although not our focus per se, such use-cases are subtly important in the
sense they inform or constrain the ISE interface: if the interface cannot
support standard constructions, for example, then it cannot be deemed fit
for purpose even {\em if} it supports AES as is.

% -----------------------------------------------------------------------------

\subsubsection{Modes of operation: ``AES plus insignificant extras''}

Some modes of operation use AES in combination with relatively
insignificant
additional operations
(e.g., XOR).
Pertinent examples include the following.

\begin{itemize}
\item Encryption
      and
      decryption
      using
      Cipher Block Chaining (CBC) mode
      ~\cite[Section 6.2]{NIST:sp.800.38a}
      is outlined in
      \REFALGO{alg:cbc:enc}
      and
      \REFALGO{alg:cbc:dec}
      respectively:
      note that it uses {\em both} AES encryption {\em and} decryption.
\item Encryption
      and
      decryption
      using
      Counter               (CTR) mode
      ~\cite[Section 6.5]{NIST:sp.800.38a}
      is outlined in
      \REFALGO{alg:ctr:enc}
      and
      \REFALGO{alg:ctr:dec}
      respectively:
      note that it uses {\em only} AES encryption, and that care re. choice
      of $iv$ and increment function~\cite[Appendix B]{NIST:sp.800.38a} $f$
      is required.
\end{itemize}

% -----------------------------------------------------------------------------

\subsubsection{Modes of operation: ``AES plus   significant extras''}

Some modes of operation use AES in combination with relatively
  significant
additional operations.
We pay particular attention to examples which combine the use of AES with
operations in the finite field $\F_{2^{128}}$ constructed as
$
\F_{2}[\IND{x}] / ( \IND{x}^{128} + \IND{x}^{7} + \IND{x}^{2} + \IND{x} + 1 ) .
$
Field
      addition
and
multiplication
are denoted by
$\oplus$
and
$\otimes$
respectively.
Whereas $\oplus$ can be realised in most ISAs using XOR, $\otimes$ can be
more problematic.  This has led many ISAs to include associated ISEs for
what is often termed ``carry-less'' multiplication;
examples include
Intel via \VERB{PCLMULQDQ}~\cite[Page 4-241]{X86:2:18},
ARM   via \VERB{PMULL} and \VERB{PMULL2}~\cite[Section C7.2.215]{ARMv8-A:20},
and
SPARC via \VERB{XMULX} and \VERB{XMULXHI}~\cite[Section 7.143]{SPARC:16}.

\begin{itemize}
\item The Galois/Counter Mode (GCM)
      ~\cite{NIST:sp.800.38d}
      supports authenticated encryption, using a parameterisable block cipher,
      e.g., as AES-GCM when using AES.
      AES-GCM is comprised of two components:
      1)    \ALG{GCTR}
            is responsible for
                encryption,
            using AES;
            a simplified description of
            ~\cite[Algorithm 3]{NIST:sp.800.38d}
            is presented in
            \REFALGO{alg:gctr}
            for completeness.
      2)    \ALG{GHASH}
            is responsible for
            authentication,
            using operations in $\F_{2^{128}}$;
            a simplified description of
            ~\cite[Algorithm 2]{NIST:sp.800.38d}
            is presented in
            \REFALGO{alg:ghash}
            for completeness,
            where the so-called hash key is
            $
            h = \SCOPE{\ID{AES}}{\ALG{Enc}}( k, 0 ) .
            $

        AES-GCM is the only block cipher mode
        mandated by TLS 1.3~\cite[Section 9.1]{rfc:8446};
        the importance of this construction means
        GCM and AES are frequently considered together
        from an
        implementation and evaluation perspective.
\item The XTS-AES mode
      ~\cite{NIST:sp.800.38e}
      is an AES-specific instantiation of the XEX (XOR Encrypt XOR) tweakable
      block cipher of Rogaway~\cite{Rogaway:04};
      rather than ``data in transit'', XTS-AES is designed to support access
      to ``data at rest'' on some block-addressable storage medium.
      \REFALGO{alg:xts:enc}
      and
      \REFALGO{alg:xts:dec}
      capture XTS-AES encryption and decryption respectively, noting that
      $
      \alpha = \IND{x} .
      $
      XTS-AES is the defacto standard for Disk Encryption, used in
      various software suites, including Windows 10's BitLocker software.
\end{itemize}

% -----------------------------------------------------------------------------

\subsubsection{Other}

Some constructions use components {\em in} AES, rather than AES {\em itself}.
For example,
the Gr{\o}stl~\cite{GKMMRST:11} hash function
(a SHA-3  candidate; see also~\cite{BBGR:09})
uses the S-box~\cite[Section 4.3]{GKMMRST:11},
and
the YAES~\cite{BosVer:14} authenticated encryption scheme
(a CAESAR candidate; see also~\cite[Section 4.1]{AnkAnk:16})
uses a full round~\cite[Section 1.3]{BosVer:14}.

% =============================================================================


\chapter{Proof schemes}

\section{Generation of induction principles with {\tt Scheme}}
\label{Scheme}
\index{Schemes}
\comindex{Scheme}

The {\tt Scheme} command is a high-level tool for generating
automatically (possibly mutual) induction principles for given types
and sorts.  Its syntax follows the schema:
\begin{quote}
{\tt Scheme {\ident$_1$} := Induction for \ident'$_1$ Sort {\sort$_1$} \\
  with\\
  \mbox{}\hspace{0.1cm} \dots\\
        with {\ident$_m$} := Induction for {\ident'$_m$} Sort
        {\sort$_m$}}
\end{quote}
where \ident'$_1$ \dots\ \ident'$_m$ are different inductive type
identifiers belonging to the same package of mutual inductive
definitions. This command generates {\ident$_1$}\dots{} {\ident$_m$}
to be mutually recursive definitions. Each term {\ident$_i$} proves a
general principle of mutual induction for objects in type {\term$_i$}.

\begin{Variants}
\item {\tt Scheme {\ident$_1$} := Minimality for \ident'$_1$ Sort {\sort$_1$} \\
    with\\
    \mbox{}\hspace{0.1cm} \dots\ \\
    with {\ident$_m$} := Minimality for {\ident'$_m$} Sort
    {\sort$_m$}}

  Same as before but defines a non-dependent elimination principle more
  natural in case of inductively defined relations.

\item {\tt Scheme Equality for \ident$_1$\comindex{Scheme Equality}}

  Tries to generate a Boolean equality and a proof of the
  decidability of the usual equality. If \ident$_i$ involves
  some other inductive types, their equality has to be defined first.

\item {\tt Scheme Induction for \ident$_1$ Sort {\sort$_1$} \\
  with\\
  \mbox{}\hspace{0.1cm} \dots\\
        with Induction for {\ident$_m$} Sort
        {\sort$_m$}}

  If you do not provide the name of the schemes, they will be automatically
  computed from the sorts involved (works also with Minimality).

\end{Variants}
\label{Scheme-examples}

\firstexample
\example{Induction scheme for \texttt{tree} and \texttt{forest}}

The definition of principle of mutual induction for {\tt tree} and
{\tt forest} over the sort {\tt Set} is defined by the command:

\begin{coq_eval}
Reset Initial.
Variables A B : Set.
\end{coq_eval}

\begin{coq_example*}
Inductive tree : Set :=
    node : A -> forest -> tree
with forest : Set :=
  | leaf : B -> forest
  | cons : tree -> forest -> forest.

Scheme tree_forest_rec := Induction for tree Sort Set
  with forest_tree_rec := Induction for forest Sort Set.
\end{coq_example*}

You may now look at the type of {\tt tree\_forest\_rec}:

\begin{coq_example}
Check tree_forest_rec.
\end{coq_example}

This principle involves two different predicates for {\tt trees} and
{\tt forests}; it also has three premises each one corresponding to a
constructor of one of the inductive definitions.

The principle {\tt forest\_tree\_rec} shares exactly the same
premises, only the conclusion now refers to the property of forests.

\begin{coq_example}
Check forest_tree_rec.
\end{coq_example}

\example{Predicates {\tt odd} and {\tt even} on naturals}

Let {\tt odd} and {\tt even} be inductively defined as:

% Reset Initial.
\begin{coq_eval}
Open Scope nat_scope.
\end{coq_eval}

\begin{coq_example*}
Inductive odd : nat -> Prop :=
    oddS : forall n:nat, even n -> odd (S n)
with even : nat -> Prop :=
  | evenO : even 0
  | evenS : forall n:nat, odd n -> even (S n).
\end{coq_example*}

The following command generates a powerful elimination
principle:

\begin{coq_example}
Scheme odd_even := Minimality for   odd Sort Prop
  with even_odd := Minimality for even Sort Prop.
\end{coq_example}

The type of {\tt odd\_even} for instance will be:

\begin{coq_example}
Check odd_even.
\end{coq_example}

The type of {\tt even\_odd} shares the same premises but the
conclusion is {\tt (n:nat)(even n)->(Q n)}.

\subsection{Automatic declaration of schemes
\optindex{Boolean Equality Schemes}
\optindex{Elimination Schemes}
\optindex{Nonrecursive Elimination Schemes}
\label{set-nonrecursive-elimination-schemes}
}

It is possible to deactivate the automatic declaration of the induction
 principles when defining a new inductive type  with the
 {\tt Unset Elimination Schemes} command. It may be
reactivated at any time with {\tt Set Elimination Schemes}.

The types declared with the keywords {\tt Variant} (see~\ref{Variant})
and {\tt Record} (see~\ref{Record}) do not have an automatic
declaration of the induction principles. It can be activated with the
command {\tt Set Nonrecursive Elimination Schemes}. It can be
deactivated again with {\tt Unset Nonrecursive Elimination Schemes}.
\\

You can also activate the automatic declaration of those Boolean equalities
(see the second variant of {\tt Scheme})
with respectively the commands {\tt Set Boolean Equality Schemes} and
{\tt Set Decidable Equality Schemes}.
However you have to be careful with this option since
\Coq~ may now reject well-defined inductive types because it cannot compute
a Boolean equality for them.

\subsection{\tt Combined Scheme}
\label{CombinedScheme}
\comindex{Combined Scheme}

The {\tt Combined Scheme} command is a tool for combining
induction principles generated by the {\tt Scheme} command.
Its syntax follows the schema :
\begin{quote}
{\tt Combined Scheme {\ident$_0$} from {\ident$_1$}, .., {\ident$_n$}}
\end{quote}
where
\ident$_1$ \ldots \ident$_n$ are different inductive principles that must belong to
the same package of mutual inductive principle definitions. This command
generates {\ident$_0$} to be the conjunction of the principles: it is
built from the common premises of the principles and concluded by the
conjunction of their conclusions.

\Example
We can define the induction principles for trees and forests using:
\begin{coq_example}
Scheme tree_forest_ind := Induction for tree Sort Prop
  with forest_tree_ind := Induction for forest Sort Prop.
\end{coq_example}

Then we can build the combined induction principle which gives the
conjunction of the conclusions of each individual principle:
\begin{coq_example}
Combined Scheme tree_forest_mutind from tree_forest_ind, forest_tree_ind.
\end{coq_example}

The type of {\tt tree\_forest\_mutrec} will be:
\begin{coq_example}
Check tree_forest_mutind.
\end{coq_example}

\section{Generation of induction principles with {\tt Functional Scheme}}
\label{FunScheme}
\comindex{Functional Scheme}

The {\tt Functional Scheme} command is a high-level experimental
tool for generating automatically induction principles
corresponding to (possibly mutually recursive) functions.  Its
syntax follows the schema:
\begin{quote}
{\tt Functional Scheme {\ident$_1$} := Induction for \ident'$_1$ Sort {\sort$_1$} \\
  with\\
  \mbox{}\hspace{0.1cm} \dots\ \\
        with {\ident$_m$} := Induction for {\ident'$_m$} Sort
        {\sort$_m$}}
\end{quote}
where \ident'$_1$ \dots\ \ident'$_m$ are different mutually defined function
names (they must be in the same order as when they were defined).
This command generates the induction principles
\ident$_1$\dots\ident$_m$, following the recursive structure and case
analyses of the functions \ident'$_1$ \dots\ \ident'$_m$.

\Rem
There is a difference between obtaining an induction scheme by using
\texttt{Functional Scheme} on a function defined by \texttt{Function}
or not. Indeed \texttt{Function} generally produces smaller
principles, closer to the definition written by the user.

\firstexample
\example{Induction scheme for \texttt{div2}}
\label{FunScheme-examples}

We define the function \texttt{div2} as follows:

\begin{coq_eval}
Reset Initial.
\end{coq_eval}

\begin{coq_example*}
Require Import Arith.
Fixpoint div2 (n:nat) : nat :=
  match n with
  | O => 0
  | S O => 0
  | S (S n') => S (div2 n')
  end.
\end{coq_example*}

The definition of a principle of induction corresponding to the
recursive structure of \texttt{div2} is defined by the command:

\begin{coq_example}
Functional Scheme div2_ind := Induction for div2 Sort Prop.
\end{coq_example}

You may now look at the type of {\tt div2\_ind}:

\begin{coq_example}
Check div2_ind.
\end{coq_example}

We can now prove the following lemma using this principle:

\begin{coq_example*}
Lemma div2_le' : forall n:nat, div2 n <= n.
intro n.
 pattern n , (div2 n).
\end{coq_example*}

\begin{coq_example}
apply div2_ind; intros.
\end{coq_example}

\begin{coq_example*}
auto with arith.
auto with arith.
simpl; auto with arith.
Qed.
\end{coq_example*}

We can use directly the \texttt{functional induction}
(\ref{FunInduction}) tactic instead of the pattern/apply trick:
\tacindex{functional induction}

\begin{coq_example*}
Reset div2_le'.
Lemma div2_le : forall n:nat, div2 n <= n.
intro n.
\end{coq_example*}

\begin{coq_example}
functional induction (div2 n).
\end{coq_example}

\begin{coq_example*}
auto with arith.
auto with arith.
auto with arith.
Qed.
\end{coq_example*}

\Rem There is a difference between obtaining an induction scheme for a
function by using \texttt{Function} (see Section~\ref{Function}) and by
using \texttt{Functional Scheme} after a normal definition using
\texttt{Fixpoint} or \texttt{Definition}. See \ref{Function} for
details.

\example{Induction scheme for \texttt{tree\_size}}

\begin{coq_eval}
Reset Initial.
\end{coq_eval}

We define trees by the following mutual inductive type:

\begin{coq_example*}
Variable A : Set.
Inductive tree : Set :=
    node : A -> forest -> tree
with forest : Set :=
  | empty : forest
  | cons : tree -> forest -> forest.
\end{coq_example*}

We define the function \texttt{tree\_size} that computes the size
of a tree or a forest. Note that we use \texttt{Function} which
generally produces better principles.

\begin{coq_example*}
Function tree_size (t:tree) : nat :=
  match t with
  | node A f => S (forest_size f)
  end
 with forest_size (f:forest) : nat :=
  match f with
  | empty => 0
  | cons t f' => (tree_size t + forest_size f')
  end.
\end{coq_example*}

\Rem \texttt{Function} generates itself non mutual induction
principles {\tt tree\_size\_ind} and {\tt forest\_size\_ind}:

\begin{coq_example}
Check tree_size_ind.
\end{coq_example}

The definition of mutual induction principles following the recursive
structure of \texttt{tree\_size} and \texttt{forest\_size} is defined
by the command:

\begin{coq_example*}
Functional Scheme tree_size_ind2 := Induction for tree_size Sort Prop
with forest_size_ind2 := Induction for forest_size Sort Prop.
\end{coq_example*}

You may now look at the type of {\tt tree\_size\_ind2}:

\begin{coq_example}
Check tree_size_ind2.
\end{coq_example}

\section{Generation of inversion principles with \tt Derive Inversion}
\label{Derive-Inversion}
\comindex{Derive Inversion}

The syntax of {\tt Derive Inversion} follows the schema:
\begin{quote}
{\tt Derive Inversion {\ident} with forall
  $(\vec{x} : \vec{T})$, $I~\vec{t}$ Sort \sort}
\end{quote}

This command generates an inversion principle for the
\texttt{inversion \dots\ using} tactic.
\tacindex{inversion \dots\ using}
Let $I$ be an inductive predicate and $\vec{x}$ the variables
occurring in $\vec{t}$. This command generates and stocks the
inversion lemma for the sort \sort~ corresponding to the instance
$\forall (\vec{x}:\vec{T}), I~\vec{t}$ with the name {\ident} in the {\bf
global} environment. When applied, it is equivalent to having inverted
the instance with the tactic {\tt inversion}.

\begin{Variants}
\item \texttt{Derive Inversion\_clear {\ident} with forall
  $(\vec{x}:\vec{T})$, $I~\vec{t}$ Sort \sort}\\
  \comindex{Derive Inversion\_clear}
  When applied, it is equivalent to having
  inverted the instance with the tactic \texttt{inversion}
  replaced by the tactic \texttt{inversion\_clear}.
\item \texttt{Derive Dependent Inversion {\ident} with forall
  $(\vec{x}:\vec{T})$, $I~\vec{t}$ Sort \sort}\\
  \comindex{Derive Dependent Inversion}
  When applied, it is equivalent to having
  inverted the instance with the tactic \texttt{dependent inversion}.
\item \texttt{Derive Dependent Inversion\_clear {\ident} with forall
  $(\vec{x}:\vec{T})$, $I~\vec{t}$ Sort \sort}\\
  \comindex{Derive Dependent Inversion\_clear}
  When applied, it is equivalent to having
  inverted the instance with the tactic \texttt{dependent inversion\_clear}.
\end{Variants}

\Example

Let us consider the relation \texttt{Le} over natural numbers and the
following variable:

\begin{coq_eval}
Reset Initial.
\end{coq_eval}

\begin{coq_example*}
Inductive Le : nat -> nat -> Set :=
  | LeO : forall n:nat, Le 0 n
  | LeS : forall n m:nat, Le n m -> Le (S n) (S m).
Variable P : nat -> nat -> Prop.
\end{coq_example*}

To generate the inversion lemma for the instance
\texttt{(Le (S n) m)} and the sort \texttt{Prop}, we do:

\begin{coq_example*}
Derive Inversion_clear leminv with (forall n m:nat, Le (S n) m) Sort Prop.
\end{coq_example*}

\begin{coq_example}
Check leminv.
\end{coq_example}

Then we can use the proven inversion lemma:

\begin{coq_eval}
Lemma ex : forall n m:nat, Le (S n) m -> P n m.
intros.
\end{coq_eval}

\begin{coq_example}
Show.
\end{coq_example}

\begin{coq_example}
inversion H using leminv.
\end{coq_example}


\chapter[CVAEs for real GW events]{Conditional variational autoencoders for detecting real GW signals}

In this chapter I will discuss some recent soon to be published work on using the \texttt{VItamin} machine learning for gravitational wave parameter estimation pipeline to do Bayesian PE on real \ac{GW} signals. In the first section I will introduce the problem, in the second I will discuss data pre-processing and generation, in the third section I will discuss results in both real and Gaussian noise cases on a variety of real \ac{GW} signals.

\section{Introduction}

\section{Signal pre-processing/generation}

\section{Training tricks}

\subsection{Data augmentation}

In addition to allowing the network to see multiple noise realizations
of the same signal multiple times, every time we give the network
a new chunk of signals, we also randomize the phase, time of arrival and
distance of the new loaded in training samples.

%
% Distance augmentation
%
For distance, we first choose values uniformly at random from 0 to 1 for
each distance training sample parameter. These values are then
converted to units of Mpc by

\begin{equation}\label{eq:dist_rescale}
    d_{\textrm{new}} = d_{\textrm{min}} + d_{\textrm{uni}}*(d_{\textrm{max}} - d_{\textrm{min}}),
\end{equation}

where $d_{\textrm{uni}}$ is a uniform set of numbers between 0 and 1,
$d_{\textrm{max}}$ represents the maximum allowed distance according to the prior and $d_{\textrm{min}}$ is the minimum allowed distance according to the prior. We then determine the factor by which the distance has changed from its old value for each training sample by dividing the old distance by the new distance value.

\begin{equation}
    d_{\textrm{corr}} = \frac{d_{\textrm{old}}}{d_{\textrm{new}}}
\end{equation}

where $d_{\textrm{old}}$ is the original distance value for the sample
and $d_{\textrm{new}}$ is the new value.

%
% Phase augmentation
%

In order to get the phase augmentation scale term
we do a similar process as the distance
augmentation above. We again choose a uniform value between 0 and 1 and
apply the same rescaling as that in equation \ref{eq:dist_rescale}, but
instead with bounds relavent to phase (0 to $\pi$). Bounds are only
up to a maximum of $\pi$ due an applied reparameterization trick
discussed below in subsection \ref{subsec:phipsi_repar}. A phase
correction term is then calculated

\begin{equation}
    \phi_{\textrm{corr}} = -1.0 \times (\cos(\phi_{\textrm{new}} - \phi_{\textrm{old}}) + \sin(\phi_{\textrm{new}} - \phi_{\textrm{old}}) \times i),
\end{equation}

where $\phi_{\textrm{corr}}$ is the phase correction factor we
will use to randomize the phase, $\phi_{\textrm{new}}$ is the new
randomized phase value and $\phi_{\textrm{old}}$ is the original
training sample phase value.

%
% time correction
%

The time scale term is then computed by again choosing a random value
between 0 and 1 for all training samples and rescaling those random
values to be in units of seconds which are between the allowable
prior bounds of time. We then convert the new randomized time
to radians and find the difference between the new and old
times

\begin{equation}
    t_{\textrm{corr}} = -2.0\pi (t_{\textrm{new}} - t_{\textrm{old}}),
\end{equation}

where $t_{\textrm{new}}$ is the new time of coalescence, $t_{\textrm{old}}$
is the old time of coalescence and $t_{\textrm{corr}}$ is the time of coalesence scale factor. The complex value for the time of coalesence
scale factor $t_{\textrm{corr}}$ is computed

\begin{equation}
    t_{\textrm{corr}} = -1.0 \times (\cos(t_{\textrm{corr}}) + \sin(t_{\textrm{corr}}) \times i).
\end{equation}

Finally, given all the correction factors for time $t_{\textrm{corr}}$,
distance $d_{\textrm{corr}}$ and phase $\phi_{\textrm{corr}}$ have been
calculated, we need only simply multiply
the phase correction term and the time correction term by the real
\ac{FFT} of the training sample time series

\begin{equation}
    y_{\phi \textrm{corr}} = \mathcal{F}(y) \times \phi_{\textrm{corr}} \times t_{\textrm{corr}},
\end{equation}

where $\mathcal{F}$ is the real \ac{FFT}. To apply the distance term
apply the inverse real \ac{FFT} and multiply by the distance correction
scale factor

\begin{equation}
    y_{\phi \textrm{corr}} = \mathcal{F}^{-1}(y_{\phi \textrm{corr}}) \times d_{\textrm{corr}}.
\end{equation}

Adding these randomized elements to the existing training workflow
was absolutely key in ensuring that the neural network model did
not overfit the training set.

\subsection{Phase and Psi reparameterization trick}\label{subsec:phipsi_repar}

One of the single biggest issues we have faced while training the neural network
has been dealing with the multi-modal nature of the phase ($\phi$) and psi
($\psi$) parameters. Along with the addition of the Gaussian mixture model
component of the network mentioned previously, we have also implemented
a reparameterization of both phase and psi in order to simplify the
search space for the neural network partly inspired by the work of Jones in \cite{10.1093/mnras/stv1584}.

In order to
go from $\psi$ and $\phi$ to a new representation $\psi$ and $X$, we first take the
remainder of $\psi + \phi$ divided by $\pi$ which then becomes a new parameter denoted as $X$.
We also take the remainder of $\psi$ divided by $\frac{\pi}{2}$.

\begin{equation}
    X = (\psi + \phi) \textrm{ mod } \pi.
\end{equation}
\begin{equation}
    \psi = \psi \textrm{ mod } \frac{\pi}{2}.
\end{equation}

In order to get back to the original $\psi, \phi$ representation, we choose a set of two random integers between zero
and $2$ ($D_1$) multiplied by $\pi$, as well as a set of two random integers between $0$ and $\frac{1}{2}$ ($D_2$)
multiplied by $\pi$ for each $\psi$ value and ensure both $\psi$ and $X$ are in radians.

\begin{equation}
    D_{1}=\left\{ x\in\mathbb{Z}|0\leq x\leq 2 \right\} \times \pi
\end{equation}

\begin{equation}
    D_{2}=\left\{ x\in\mathbb{Z}|0\leq x\leq \frac{1}{2} \right\} \times \pi
\end{equation}

We then subtract off $\psi$ from $X$, add both random radian integers and take the modulus
of the whole expression with respect to $2\pi$ in order to get back $\phi$.

\begin{equation}
    \phi = ((X - \psi) + D_{1} + D_{2}) \textrm{ mod } 2\pi
\end{equation}

For $\psi$ we add set $D_2$ and take the modulus with respect to $\pi$

\begin{equation}
    \psi = (\psi + D_2) \textrm{ mod } \pi.
\end{equation}

This essentially tessellates the $X-\psi$ and $\psi$ parameters across
four quadrants of the parameter space while maintaining the same number of samples and
 general distribution shape.

The reparameterization process is visually illustrated in Figure \ref{fig:Xpsi}. It can be clearly seen
that the 2D representation $X, \psi$ in both the upper left and lower right subplots, is vastly
simpler than the original 2D $\phi, \psi$ representation. The transformation also
is able to maintain the property of being fully-reversible. Although, we do note that
if one considers \ac{GW} template waveforms with higher order modes this degeneracy is
broken and the above reparameterization would not be necessary \cite{10.1093/mnras/stv1584}.

\begin{figure}
    \centering
    \includegraphics[width=16cm,height=20cm,keepaspectratio]{figures/Xpsi.png}
    \caption[An illustration of the $\psi$ and $\phi$ reparameterization trick.]{An illustration of the $\psi$ and $\phi$ reparameterization trick. Upper left
    plot: a random set of samples drawn from randomly generated multivariate Gaussian distributions for both $\psi$ and $\phi$. Red cross hairs denote Each Gaussian's mean and $X$ represents a reparameterization of $\psi$ and $\phi$. Upper right: Same plot as the upper right, but with $\psi$ subtracted off from the reparameterization in
    order to form a trapezoidal-like shape for tessellation purposes. Lower left: We then apply a tessellation of the samples in the upper right figure in order to convert the reparameterization back to the original units of $\psi$ and $\phi$. Lower right: We can get back to the reparameterized version by applying our reparameterization trick again without any change to the original in the upper left.}
    \label{fig:Xpsi}
\end{figure}

\section{Results}

\section{Conclusions}


\chapter{Introduction} \label{chap:introduction}

\section{Background and purpose} \label{sec:chap::introduction_background}

{\TeX}/{\LaTeX} is widely used when documents such as reports or theses is written.
This is because {\TeX}/{\LaTeX} is a system for markup language
so that users can easily separate
structure and appearance of documents.
In most laboratory, some {\LaTeX} templates is shared so that students can focus only on
the logical structure of these theses.

However, researchers is always not familiar with {\TeX}/{\LaTeX}.
This is why the templates is often too old.
Thus some error or bad appearance can occur in modern {\TeX}/{\LaTeX} system.

This template provides modern {\LaTeX} environment for theses using {\pdfLaTeX}.

\section{Feature} \label{sec:chap::introduction_feature}

Note that this template employs
\begin{itemize}
    \item \cls*{scrreprt} as document class,
    \item \verbcode{llmk} as build tool.
\end{itemize}

\section{Equation and Cross Reference} \label{sec:chap::introduction_equation}

If you want to typeset \emph{inline} mathematical formula,
you should write like \verbcode{$ formula $}
such as $x + y$ or $a = b$.

If you want to typeset single \emph{display} mathematical formula, you should write a pair of
\verbcode{\[} and \verbcode{\]} or \verbcode{equation} environment.
For example, if you use the pair of \verbcode{\[} and \verbcode{\]},
it will be
\[
    y = ax^2 + bx + c \text{,}
\]
if you use \env*{equation} environment%
\footnote{%
    If you use \env*{equation*} environment,
    the equation will not be put a number.
    Generally, if you use some environment for equation with stared,
    the equations will not be put any number.
}%
, it will be
\begin{equation}
    y = \sin x + 2 (x + y) + \sqrt{x} + \sqrt[3]{x} \text{.}
    \label{eq:chap::introduction_sec::background_sinparensqrt}
\end{equation}

The below equation is put a number and you can label by using a \cs*{label} command.
Then, you can reference a \cs*{ref} command
such as \ref{eq:chap::introduction_sec::background_sinparensqrt}.
You can refer to not only equation by \cs*{ref} command,
you can also refer to chapter, section, figure, table {\etc}
For equation, you can use a \cs*{eqref} command such as
\eqref{eq:chap::introduction_sec::background_sinparensqrt}.
However, I recommend \cs*{cref} or \cs*{Cref} command provided by \pkg*{cleveref} package,
where the \cs*{Cref} is used for the initial of sentences.

If you want to typeset multiline display mathematical formula,
you should use appropriate environment provided by \pkg*{amsmath} package.
Normally, you should use \env*{align} environment like
\begin{align}
    \sin^2 x + \cos^2 x = 1,
    \label{eq:chap::introduction_sec::equation_sincos} \\
    \tan x = \frac{\sin x}{\cos x} \text{.}
    \label{eq:chap::introduction_sec::equation_tan}
\end{align}
You can use a character ``\verbcode{&}'' into \env*{align} environment
and it makes the equations sorted:
\begin{align*}
    \cos 2x & = \cos^2 x - \sin^2 x     \\
            & = 1 - 2 \sin^2 x          \\
            & = 2 \cos^2 x - 1 \text{.}
\end{align*}

\section{Table and Figure} \label{sec:chap::introduction_table}

If you want to typeset table, you should write like this:
\begin{table}[htbp]
    \centering
    \caption{Production method of \ce{SiC} nanowire}
    \label{tab:chap::introduction_sec::introduction_sicnanowire}
    \begin{tabular}{ccc}
        \toprule
        Source    & Substrate & Catalyst \\ \midrule
        Saccharin & \ce{Si}   & \ce{Fe}  \\
        Saccharin & \ce{Si}   & \ce{Ni}  \\
        \bottomrule
    \end{tabular}
\end{table}

If you want to include figure, you should write like this:
\begin{figure}[htbp]
    \centering
    \includegraphics[width=100mm]{vicsek.pdf}
    \caption{The first, second, third part of construction of Vicsek snowflake.}
    \label{fig:chap::introduction_sec::introduction_vicseksnowflake}
\end{figure}

You can also refer to table and figure by a \cs*{cref} command
like \cref{tab:chap::introduction_sec::introduction_sicnanowire}
or \cref{fig:chap::introduction_sec::introduction_vicseksnowflake}.

\section{Citation} \label{sec:chap::introduction_citation}

You can cite other publications by \cs*{cite} command like
\cite{10.1093/jmicro/dfaa015}.
You can also cite multiple publications by single \cs*{cite} command
like \cite{10.1093/jmicro/dfaa015,Hayashi:2020:1533-4880:3038,Ishida_2019,doi:10.1063/1.4894003}.
Before citation, you must note the data of the publications
in \verbcode{.bib} file.
Then, you should include the \verbcode{.bib} file
by a \cs*{addbibresource} command provided by \pkg*{biblatex} package.
In this template, the ``phys'' style is employed.

If you use \pkg*{biblatex} package, you should build the document as follows:
\begin{itemize}
    \item Run ``\verbcode{pdflatex thesis}'' on your terminal,
    \item run ``\verbcode{biber thesis}'' on your terminal,
    \item run ``\verbcode{pdflatex thesis}'' on your terminal.
\end{itemize}

\section{Auto Build} \label{sec:chap::introduction_autobuild}

You can automate above procedure by \verbcode{llmk}.
If you want to use \verbcode{llmk},
you should clone the script from Github page of \verbcode{llmk}%
\footnote{\url{https://github.com/wtsnjp/llmk}},
and its document are there.


\subsection{Bayesian Additive Regression Trees (BART)}


\clearpage
\def\pageLang{c}
\section{Managing Multiple Values in C} % (fold)
\label{sec:arrays_in_c}

\input{topics/arrays/c/c-stats-calc}
\input{topics/arrays/c/c-array-decl}
\input{topics/arrays/c/c-array-copy}
\input{topics/arrays/c/c-for-loop}
\input{topics/arrays/c/c-strings}
\input{topics/arrays/c/c-fn-with-array}

% section more_data_types_in_c (end)


% !TeX root = ../main.tex
%Describe CFG in HCL
%The commented-out section is the section deemed as extraneous for the report.
\section{Context-free Grammar of HCL}
\label{CFGdescription}
The following section contains a method to describe the production rules of the CFG for HCL.
Two notational methods for describing production rules are typically used, Backus-Naur Form and Extended Backus-Naur form.
Both of these appear in this section.

\textbf{Backus-Naur Form} (BNF) is a method for visualizing the production rules of a Context-free grammar (CFG).
Below is an example of such a production rule.

\begin{align*}
	\texttt{<Sentence>}\to & \texttt{ <StringOfWords> \$}\\
	\texttt{<StringOfWords>}\to & \texttt{ word <StringOfWords>}\\
	| & \texttt{ }\lambda
\end{align*}

All non-terminals are presented using PascalCase in angle brackets.
Terminals are presented using camelCase.
Non-terminals can be rewritten to one of the strings on right-hand side of the production rule.
Option between multiple production rules is indicated with a "|" symbol.

\textbf{Extended BNF} (EBNF) is another way to visualize the production rules of a CFG.
It is designed to be more concise than BNF.
In BNF, if a non-terminal is structured in two or more different ways, each way has to be noted with a new rule.
In EBNF the number of rules can be reduced.
This is done by marking iterative and optional arguments, as well as choice of arguments, within that one rule.
\cite{SebestaEBNF}

The notation for EBNF is as follows:
\begin{align*}
	\text{Repetition (zero or more):} & \texttt{ \{arg\}}\\
	\text{Repetition (one or more):} & \texttt{ \{arg\}+}\\
	\text{Optional (zero or one):} & \texttt{ [arg]}\\
	\text{Choice:} & \texttt{ (arg1 | arg2)}
\end{align*}

The grammar for sentences can be written in EBNF as:
\begin{align*}
	\texttt{<Sentence>}\to & \texttt{ \{word\} \$}
\end{align*}

The grammar of HCL is described using EBNF, and is included in appendix \ref{AppendixEBNF}.


% !TEX root=../main.tex
\section{Experimental Results}
\label{sec:ocnnexperiment-results}

In this section, we present empirical results produced by OC-NN model on synthetic and real data sets. We perform a comprehensive set of experiments to demonstrate that on complex data sets OC-NN performs on par with state-of-the-art methods and outperformed conventional shallow methods in some scenarios.
%%%%% Synthetic Dataset
\subsection{ Synthetic Data}
Single cluster consisting of 190 data points using $\mu=0$ and $\sigma = 2$ are generated as normal points , along with 10 anomalous points drawn from normal distribution with $\mu=0$ and $\sigma = 10$ having  dimension $d=512$. Intuitively, the latter normally distributed points are treated as being anomalous, as the corresponding points have different distribution characteristics to the majority of the training data. Each data point is flattened as a row vector, yielding a 190 $\times$ 512 training matrix and 10 $\times$ 512 testing matrix. We use a simple feed-forward neural network model with one-class neural network  objective as per Equation~\ref{eqn:oc-nn}.\\
%using network parameter settings described in Section~\ref{sec:feed forward oc-nn-model-config}.\\
\textbf{Results}.
From Figure~\ref{fig:synthetic-histogram}, we see that it is a near certainty for all $10$ anomalous points, are accurately identified as outliers with decision scores being negative for anomalies. It is evident that, the OC-NN formulation performs on par with classical OC-SVM in detecting the anomalous data points. In the next sections we apply to image and sequential data and demonstrate its effectiveness.

%% Results for Synthetic dataset
\begin{figure}
    \centering
    \includegraphics[scale=0.38]{images/s1}
    \caption{Decision Score Histogram of anomalous vs normal data points, {\tt synthetic} dataset.}
    \label{fig:synthetic-histogram}
\end{figure}

  % Begin figure
  \begin{figure}[htp]
    % Fixed length
    \centering
    \subcaptionbox{Normal samples.\label{fig3:a}}{\includegraphics[height=8cm,width=1.6in]{images/mnistNormalRCAE}}\hspace{1em}%
    \subcaptionbox{In-class anomalies.\label{fig3:b}}{\includegraphics[height=8cm,width=1.6in]{images/mnistAnomalyRCAE}}
    \caption{MNIST Most normal and in-class anomalous MNIST digits detected by RCAE.}
    \label{fig:mnistRCAEresults}
  \end{figure}
  % End of figure

    % Begin figure
    \begin{figure}[htp]
      % Fixed length
      \centering
      \subcaptionbox{Normal samples.\label{fig3:a}}{\includegraphics[height=8cm,width=1.6in]{images/mnistnormalOCNN}}\hspace{1em}%
      \subcaptionbox{In-class anomalies.\label{fig3:b}}{\includegraphics[height=8cm,width=1.6in]{images/mnistOutlierOCNN}}
      \caption{MNIST Most normal and in-class anomalous MNIST digits detected by OC-NN.}
            \label{fig:mnistOCNNresults}
    \end{figure}
    % End of figure

%%%%% Mnist Dataset
\subsection{ OC-NN on MNIST and CIFAR-10}
\textbf{Setup}
Both MNIST and CIFAR-10  have ten different classes from which we construct one-class classification dataset.  One of the classes is the normal class and
samples from the remaining classes represent anomalies. We use the original training and test splits in our
experiments and only train with training set examples from
the respective normal class. This produces normal instances set of sizes
of n $\approx$ 6000 for MNIST and n $\approx$ 5000 for CIFAR-10 respectively.
Both MNIST and CIFAR-10 test sets have $10000$ samples per class.
The training set comprises of normal instances for each class along with anomalies sampled from
all the other nine classes. The number of anomalies used within training set consists of 1\% normal class for MNIST and  10\% of normal class for CIFAR-10 dataset respectively. We pre-process all images with global contrast normalization using the $L1$
norm and finally rescale to [0, 1] via min-max-scaling.\\
\textbf{Network architectures} For both MNIST and CIFAR-10 datasets, we employ LeNet type
CNNs, wherein each convolutional module consists of a convolutional layer followed by leaky ReLU activations and $2 \times 2$ max-pooling. On MNIST, we use a CNN with two modules, $8\times(5\times5\times1)$-filters followed by $4\times(5\times5\times1)$-filters, and a final dense layer of 32 units. On CIFAR-10,
we use a CNN with three modules, $32 \times (5 \times 5 \times3)$-filters,
$64\times(5\times5\times3)$-filters, and $128\times(5\times5\times3)$-filters, followed
by a final dense layer of $128$ units. We use a batch size of
$200$ and set the weight decay hyperparameter to $ \lambda= 10^{ - 5}$.\\
{\textbf{Results:}}
Results are presented in Table ~\ref{tab:ocnn_results}. RCAE
clearly outperforms both its shallow and deep competitors
on MNIST. On CIFAR-10 the results are convincing but for certain classes the shallow baseline methods outperform the deep models. OC-NN, Soft and One-class Deep SVDD however, shows an overall robust performance. On CIFAR-10 classes such as $AUTOMOBILE$, $BIRD$ and $DEER$ which have less global contrast, as illustrated in Table~\ref{tab:ocnn_results} (indicated in blue color)  OC-NN seems to outperform the shallow methods, Soft and One-class Deep SVDD methods, this is indicative of their future potential on similar data instances.  It is interesting to note that shallow OCSVM/SVDD and KDE perform better than deep methods on two of the ten CIFAR-10 classes. We can see that normal examples of the classes  such as $FROG$ and $TRUCK$ on which OCSVM/SVDD performs best as illustrated in Figure~\ref{fig:ocsvmresults} seem to have strong global structures. For example, TRUCK images are mostly divided horizontally into street and sky, and  $FROG$ have similar colors globally. For these classes,  the performance significantly depends on choice of network architecture. Notably, the One-Class Deep SVDD performs slightly better than its soft-boundary counterpart on both datasets. Figure ~\ref{fig:mnistRCAEresults},  Figure ~\ref{fig:cifar10_rcae_results}  and Figure ~\ref{fig:mnistOCNNresults}, Figure ~\ref{fig:cifar10_ocnn_results} show examples of the most normal and most anomalous in-class samples detected by RCAE and OC-NN for MNIST and CIFAR-10 dataset respectively.

% % Results for Most anomalous and most normal images detected for CIFAR10 dataset
% Figure Begin
\begin{figure}[htp]
    % Fixed length
    \centering
    \subcaptionbox{Normal samples.\label{fig3:a}}{\includegraphics[width=1.6in]{images/cifar10NormalRCAE}}\hspace{1em}%
    \subcaptionbox{In-class anomalies.\label{fig3:b}}{\includegraphics[width=1.6in]{images/cifar10AnomalyRCAE}}
  \caption{CIFAR-10 Most normal and in-class anomalous CIFAR10 digits detected by RCAE. }
  \label{fig:cifar10_rcae_results}
\end{figure}
  % End of figure

% Begin figure
\begin{figure}[htp]
      % Fixed length
      \centering
      \subcaptionbox{Normal samples.\label{fig3:a}}{\includegraphics[width=1.6in]{images/cifar10normalOCNN}}\hspace{1em}%
      \subcaptionbox{In-class anomalies.\label{fig3:b}}{\includegraphics[width=1.6in]{images/cifar10OutlierOCNN}}
    \caption{CIFAR-10 Most normal and in-class anomalous CIFAR10 digits detected by OC-NN. }
    \label{fig:cifar10_ocnn_results}
\end{figure}
% end of figure

% % Results for Most anomalous and most normal images detected for CIFAR10 dataset
% Figure Begin
\begin{figure}[htp]
          % Fixed length
          \centering
          \subcaptionbox{Normal samples.\label{fig3:a}}{\includegraphics[width=1.6in]{images/cifar10normalOCSVM}}\hspace{1em}%
          \subcaptionbox{In-class anomalies.\label{fig3:b}}{\includegraphics[width=1.6in]{images/cifar10OutlierOCSVM}}
       \caption{Most normal (left) and most anomalous (right) in-class
       examples determined by OCSVM-SVDD for in which OCSVM-SVDD performs best.}
        \label{fig:ocsvmresults}
 \end{figure}

\subsection{ Detecting Adversarial attacks on GTSRB stop signs using OC-NN }
\textbf{Setup:}
In many applications (eg. autonomous driving) it is of paramount interest to effectively detect the adversarial samples to ensure safety and security. In this experiment, we
examine  the performance of proposed algorithms on  detecting
adversarial examples. We consider the “stop sign”
class of the German Traffic Sign Recognition Benchmark
(GTSRB) dataset, for which we generate adversarial examples
from randomly drawn stop sign images of the test set
using Boundary Attack~\cite{brendel2017decision}. We create training dataset consists of n = 1150 examples obtained by combining the normal and anomalous samples in both train and test samples. The  number of normal instances n = 1050 stop signs ( 780  from train set +  270 test set ) alongwith  100
adversarial examples are added to obtain training set. We pre-process the
data by removing the 10\% border around each sign, and then resize every image to $32 \times 32$ pixels following the same setup as in ~\cite{pmlrv80ruff18a}. Furthermore, we  apply global contrast normalization using the $L1-norm$ and rescale to the unit interval $[0, 1]$.\\
\textbf{Network architecture} We use a CNN with LeNet architecture having three convolutional modules, $16\times(5\times5\times3)$-filters, $32 \times (5 \times 5 \times 3)$-filters, and $64 \times (5 \times 5 \times 3)$-filters, followed by a final dense layer of 32 units. We train with a smaller batch size of 64, due to the dataset size and set again hyperparamter $\lambda = 10^{ - 6}$.\\
\textbf{Results:}
Results Table ~\ref{tab:gtsrbresults} illustrates the AUC scores obtained. The RCAE outperforms all the other deep models. Figure ~\ref{fig:gtsrbrcaeresults} and Figure ~\ref{fig:gtsrbocnnresults}  shows the most anomalous samples detected by RCAE and OCNN methods respectively, the outliers in this experiment are the images in odd perspectives and the ones that are cropped incorrectly.

\begin{table*}[!t]
   \caption{Average AUCs in \% with StdDevs (over 10 seeds) per method on MNIST and CIFAR-10 dataset.}
   \label{tab:ocnn_results}
   \small % text size of table content
   \centering % center the table
   \scalebox{0.6}{
   \begin{tabular}{lccccccccr} % alignment of each column data
   \toprule[\heavyrulewidth]\toprule[\heavyrulewidth]
   \textsc{\pbox{20cm}{Normal \\ Class}} & \textsc{\pbox{20cm}{OCSVM / \\ SVDD}} & \textsc{KDE} &  \textsc{IF} & \textsc{DCAE} & \textsc{ANOGAN} & \textsc{\pbox{20cm}{SOFT-BOUND \\ DEEP SVDD}} & \textsc{\pbox{20cm}{ONE-CLASS \\ DEEP SVDD}} & \textsc{OC-NN} & \textsc{RCAE} \\
   \midrule
   0 & $96.75\pm0.5$ & $97.1\pm0.0$ & $95.32\pm1.2$  & $99.90\pm0.0$ & $96.6\pm1.3$ & $98.66\pm1.3$     & $97.78\pm0.0$ & $97.60\pm1.7$ &
   $\bf{99.92\pm0.0}$\\
   1 & $99.15\pm0.4$ & $98.9\pm0.0$ & $99.35\pm0.0$  & $99.96\pm2.1$ & $99.2\pm0.6$ & $99.15\pm0.0$     & $99.08\pm0.0$ & $\color[rgb]{0,0,1}99.53\pm0.0$ & $\bf{99.97\pm2.2}$\\
   2 & $79.34\pm2.2$ & $79.0\pm0.0$ & $73.15\pm4.5$  & $96.64\pm1.3$ & $85.0\pm2.9$ & $88.09\pm2.2$     & $88.74\pm1.2$ & $87.32\pm2.1$ & $\bf{98.01\pm1.2}$\\
   3 & $85.88\pm1.3$ & $86.2\pm0.0$ & $81.34\pm2.8$ & $98.42\pm0.0$ &  $88.7\pm2.1$ &  $88.93\pm3.4$     & $88.26\pm3.2$ & $86.52\pm3.9$ & $\bf{99.25\pm0.0}$\\
   4 & $94.18\pm1.5$ & $87.9\pm0.0$ & $87.40\pm2.6$  & $98.72\pm0.0$ & $89.4\pm1.3 $& $93.88\pm2.3$     & $95.24\pm1.4$ & $93.25\pm2.4$ & $\bf{99.23\pm0.0}$\\
   5 & $72.77\pm3.7$ & $73.8\pm0.0$ & $73.96\pm2.9 $ & $97.80\pm1.3$ & $88.3\pm2.9$ & $84.35\pm3.1$     & $83.76\pm3.1$ & $\color[rgb]{0,0,1}86.48\pm3.3$ &$ \bf{99.21\pm0.0}$\\
   6 & $95.14\pm1.1$ & $87.6\pm0.0$ & $88.65\pm0.0$  & $99.74\pm0.0$ & $94.7\pm2.7$ & $97.74\pm0.0$     & $97.99\pm0.0$ & $97.12\pm1.4$ & $\bf{99.81\pm1.1}$\\
   7 & $91.86\pm1.6$ & $91.4\pm0.0$ & $91.44\pm1.8$  & $99.08\pm2.2$ & $93.5\pm1.8$ & $92.60\pm1.2$     & $93.55\pm2.3$ & $93.64\pm2.1$ & $\bf{99.18\pm0.0}$\\
   8 & $88.65\pm1.2$ & $79.2\pm0.0$ & $75.10\pm3.7$  & $96.98\pm0.0$ & $84.9\pm2.1$ & $90.69\pm3.3$     & $90.25\pm3.1$ & $88.54\pm4.7$ & $\bf{98.50\pm2.2}$\\
   9 & $92.53\pm1.9$ & $88.2\pm0.0$ & $87.59\pm1.5$  & $98.04\pm1.3$ & $92.4\pm1.1$ & $94.28\pm2.5$     & $94.12\pm2.4$ & $93.54\pm3.3$ & $\bf{98.98\pm1.3}$\\
   \hline
  \textsc{Aeroplane}    & $60.37\pm1.3$ & $61.2\pm0.0$ & $63.99\pm1.1$  &$71.21\pm1.5$& $67.1\pm2.5$ & $66.15\pm1.1$ & $67.33\pm2.2$ & $60.42\pm1.9$  & $\bf{72.04\pm2.5}$\\
   \textsc{Automobile}  & $63.03\pm1.4$ & $63.0\pm0.0$ & $60.56\pm1.0$  &$63.05\pm2.3$& $54.7\pm3.4 $& $57.64\pm3.2$ & $58.14\pm3.1$ & $\color[rgb]{0,0,1}61.97\pm2.0$  & $\bf{63.08\pm2.1}$\\
   \textsc{Bird}        & $63.47\pm1.0 $& $50.1\pm0.0$ & $64.51\pm1.1$  &$71.50\pm1.1$& $52.9\pm3.0 $& $61.99\pm1.4$ & $61.35\pm1.5$ & $\color[rgb]{0,0,1} {63.66\pm1.4}$ & $\bf{71.67\pm1.3}$\\
   \textsc{Cat}         & $60.25\pm0.9$ & $56.4\pm0.0$ & $56.16\pm2.6$  &$60.57\pm0.0$& $54.5\pm1.9$ & $57.56\pm4.1$ & $55.72\pm1.4$ & $53.57\pm2.1$  & $\bf{60.63\pm1.1}$\\
  \textsc{Deer}         & $69.15\pm0.8$ & $66.2\pm0.0 $& $72.66\pm1.1 $ &$70.85\pm2.2$& $65.1\pm3.2$ & $63.36\pm1.3$ & $63.32\pm1.2$ & $\color[rgb]{0,0,1}67.40\pm1.7 $ & $\bf{72.75\pm3.3}$\\
   \textsc{Dog}         & $66.24\pm1.5$ & $62.4\pm0.0$ & $61.46\pm2.7 $ &$62.74\pm2.1$& $60.3\pm2.6$ & $58.58\pm1.2$ & $58.68\pm1.4$ & $56.11\pm2.1$  & $\bf{63.96\pm3.3}$\\
   \textsc{Frog}        & $\bf{71.57\pm1.5}$ & ${71.3\pm0.0}$ & $68.06\pm2.1 $ &$65.17\pm4.1$& $58.5\pm1.4 $& $63.93\pm3.1 $& $64.45\pm2.1$ & $63.31\pm3.0$  & ${64.88\pm4.2}$\\
   \textsc{Horse}       & $63.38\pm0.8 $& $62.6\pm0.0$ & $63.04\pm1.5$  &$61.11\pm1.4$& $62.5\pm0.8$ & $60.20\pm2.2$ & $59.80\pm2.6$ & $60.09\pm2.7$  &
   $\bf{63.64\pm0.0}$\\
  \textsc{Ship}         & $60.44\pm1.1$ & ${65.1\pm0.0}$ & $68.01\pm1.3$  &$74.18\pm1.2$& $74.68\pm4.1$ & $70.21\pm1.1$ & $67.44\pm2.2$ & $64.67\pm1.6$  & $\bf{74.72\pm1.1}$\\
  \textsc{Truck}        & $\bf{75.81\pm0.8}$ & ${74.0\pm0.0}$ & $72.83\pm1.1$  &$71.36\pm4.3$& $66.5\pm2.8 $& $72.91\pm3.3$ & $68.03\pm3.2$ &$ 60.32\pm4.9 $ & ${74.47\pm1.5}$\\
   \bottomrule[\heavyrulewidth]
   \end{tabular}}
\end{table*}
% end of the table

% begin of table
\begin{table}[ht]
\caption{Average AUCs in \% with StdDevs (over 10 seeds) per
method on GTSRB stop signs with adversarial attacks.} % title of Table
\centering % used for centering table
\scalebox{0.7}{
\begin{tabular}{l l } % centered columns (4 columns)
\hline\hline %inserts double horizontal lines
\bf{\textsc{Method}} & \bf{\textsc{AUC}}\\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
OC-SVM/SVDD & $52.5 \pm 1.3$ \\ % inserting body of the table
KDE & $51.5 \pm 1.6$ \\
IF & $53.37\pm 2.9$ \\
AnoGAN & - \\
DCAE & $79.1\pm3.0$ \\
SOFT-BOUND. DEEP SVDD & $67.53\pm4.7$ \\
ONE-CLASS. DEEP SVDD & $67.08\pm4.7$ \\
OC-NN & $63.53\pm2.5$ \\
\bf{\bf{RCAE $\lambda =0$}} &\bf{$87.45\pm3.1$} \\
\bf{RCAE} & {$\bf{87.39 \pm 2.7}$} \\ [1ex] % [1ex] adds vertical space
\hline %inserts single line
\end{tabular}}
\label{tab:gtsrbresults}
\end{table}
% end of table

% Begin figure
\begin{figure}[htp]
      % Fixed length
      \centering
      \subcaptionbox{Top 50 Normal.\label{fig3:a}}{\includegraphics[width=1.6in,height=1.6in]{images/most_normalGtsrb}}\hspace{1em}%
      \subcaptionbox{Top 50 anomalies.\label{fig3:b}}{\includegraphics[width=1.6in,height=1.6in]{images/most_anomalousGtsrb}}
      \caption{Most normal and anomalous stop signs detected by RCAE. Adversarial examples are highlighted in green, Normal samples are highlighted in blue}
      \label{fig:gtsrbrcaeresults}
   \end{figure}
% end of figure

% Begin figure
\begin{figure}[htp]
      % Fixed length
      \centering
      \subcaptionbox{Top 50 Normal.\label{fig3:a}}{\includegraphics[width=1.6in,height=1.6in]{images/most_normalGtsrbocnn}}\hspace{1em}%
      \subcaptionbox{Top 50 anomalies.\label{fig3:b}}{\includegraphics[width=1.6in,height=1.6in]{images/most_anomalousGtsrbocnn}}
      \caption{Most normal and anomalous stop signs detected by OC-NN.  Adversarial examples are highlighted in green, Normal samples are highlighted in blue}
      \label{fig:gtsrbocnnresults}
      \end{figure}
% end of figure


\documentclass{memoir}
\usepackage{notestemplate}

% \begin{figure}[ht]
%     \centering
%     \incfig{riemmans-theorem}
%     \caption{Riemmans theorem}
%     \label{fig:riemmans-theorem}
% \end{figure}

\begin{document}
% \section{}
\begin{thm}
	The Gaussian Integers form a Euclidean Domain.
\end{thm}
\begin{proof}
	We will show that \(f(\alpha) = N(\alpha)\) suffices. Observe that
	\begin{align*}
		\alpha = \beta \rho + \theta \iff\\
		\frac{\alpha}{\beta = \rho + \frac{\theta}{\beta}}\iff\\
		\frac{\alpha}{\beta}-\rho = \frac{\theta}{\beta} \iff\\
		\left| \frac{\alpha}{\beta} - \rho \right| < 1
	\end{align*}
	Of course, this is the distance between \(\frac{\alpha}{\beta}\) and \(\rho\). But there always exists a lattice point within distance \(1\) of any \(\C\), and so therefore the statement holds.
\end{proof}
Now we characterize all \(G\)-primes.
\begin{prop}
To every Gaussian prime \(\pi\), there exists exactly one positive prime number \(p\) satisfying \(\pi\mid p\). Furthermore, every positive prime \(p\) is either a Gaussian prime, or the product of two complex conjugate Gaussian primes with norm \(p\).
\end{prop}
\begin{thm}
	All Gaussian primes take on the form:
	\begin{itemize}
		\item \(\varepsilon(1+i)\)
		\item \(\varepsilon q\), with \(q\) a positive prime of the form \(4k-1\)
		\item \(\pi\) where \(N(\pi)\) is a positive prime of the form \(4k+1\)
	\end{itemize}
	where \(\varepsilon\) is a unit.
\end{thm}
\end{document}

Abstract Algebra - Introductory/Algebra I/Notes/source/2020-03-04-GaussianInt2.tex