\documentclass[12]{scrartcl}
\usepackage{amssymb,amsmath,gensymb,dsfont,calc,multicol,fullpage}
\makeatletter
\newcommand\Aboxed[1]{
   \@Aboxed#1\ENDDNE}
\def\@Aboxed#1&#2\ENDDNE{%
   &
   \settowidth\@tempdima{$\displaystyle#1{}$}
   \setlength\@tempdima{\@tempdima+\fboxsep+\fboxrule}
   \kern-\@tempdima
   \boxed{#1#2}
}
\makeatother

\begin{document}

\title{Homework 9, Section 2.4: 4(b), 6, 7, 16 }
\author{Alex Gordon}
\date{\today}
\maketitle
\section*{Induction Murdering Time.}
\subsection*{4. B)}
For $n=1$ , it is given that $n^3-n=0 $ is divisible by 3. Let it be true for $n=k$.
So $k^3-k$ is divisible by $3k$. Let us check that it is also divisible for $n=k+1$.\
\begin{align*}
\\&= (k+1)^3-(k+1)
\\  &= k^3+3k^2+3k+1-k-1
\\ &=(k^3-k) + 3k(k+1)\\
\end{align*}
First factor is divisible by 3k. Second factor is multiple of 3 hence, divisible by 3. By induction it is true.
\subsection*{6.}
This proof will be mostly mathematical. However, for the first part of it, let us try some examples. Suppose that $n = 2$. It then follows that:\\
\begin{align*}
\\&= 2^6 - 1
\\  &= 63\\
\end{align*}
63 isn't prime. Let us supposed that $2^{3n} - 1$ isn't prime all the way through m + 1.
\begin{align*}
\\ & =  2^{3(m+1)} - 1
\\&= 2^3 \times 2^{3n} - 1
\\&= 7 \times 2^{3n} +  2^{3(n)} - 1
\\&= 7 \times 2^{3n} +  2^{3n} - 1\\
\end{align*}
Now before I continue, I'd just like to note that $a^n - 1 = (a - 1)(a^{n-1} + a^{n-2} + .. + 1)$. As such, it follows that;
\begin{align*}
\\2{3(n+1)}  &= 7 \times 2^{3n} + (2^3 -1)((2^3)^{n-1} + (n^3)^{n-2} + ... + 1)
\\&= 7 \times (2^{3n} + (2^3)^{n-1} + (2^3)^{n-2} + ... + 1)\\
\end{align*}
The math above shows that since $2^{3(n+1)}$ is a composite number, so it follows that  $2^{3n} - 1$ is a composite number for all $n \geq 2$ because $n + 1$ is equal to any integer.
\subsection*{7.}
The recurrence can be rewritten as\\
$p_n − p_n−1 = p_{n−1} + p_{n−2}$\\
This can also be written as
$(p_{n+1} − p_n)^2 − 2p_{n}{^2} = (−1)^n$\\
Let S(n) be the statement given by the previous equation. Let me no show that they are both true. Now assume that the first equation, the second and so on to S(m − 1) have all been validated. Now, continuing, we'll set the left side of the equation equal to
$−p^2_m + 2p_m p_m −1 + p^2_{m−1}$ Factoring out a 1 and completing the square, we get\\
$-(p_m -p_{m-1})^2$
\subsection*{16.}
Suppose that $n ≥ 28$ and $n = 8a + 5b$\\
for some nonnegative integers $a$ and $b$. \\
\\ If $a = 1$ then since $n \geq 28$, we must have $5b  \geq 20$, so that $b  \geq 4$. In this case we may replace 3 of the 5 cent stamps with 2 of the 8 cent stamps to get $n+1 = 8(a+2)+5(b−3)$.
If $a = 2$, then since $n \geq 28$, we must have $5b \geq 12$, and since $b$ is an integer, then $b \geq 3$. Again, in this case, we may replace 3 of the 5 cent stamps with 2 of the 8 cents stamps to get $n+1 = 8(a+2)+5(b−3)$.
 If $a \geq 3$, then we may replace 3 of the 8 cent stamps with 5 of the 5 cent stamps to get $n+1 = 8(a−3)+5(b+5)$.
Thus in all cases, we may write $n + 1 = 8a′ + 5b′$ for some nonnegative integers $a′$ and$ b′$.
Therefore, by the principle of mathematical induction, for any integer $n \geq  = 28$, we can use a combination of 5 cent and 8 cent stamps to obtain n cents in postage.\\ Take that induction.
\end{document}


\documentclass{report}
\input{preamble}

\begin{document}

\thispagestyle{FirstPage}
\begin{center}
\textbf{\large Notes}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TOPIC %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Solutions to the point reactor kinetics equations}

\subsection*{The inhour equation}

The point reactor kinetics equations (PRKEs) are given by the following equations for the rate of change of both power, $P(t)$ and concentration of delayed neutron precursor group $j$, $C_j(t)$:
\begin{align*}
\frac{dP(t)}{dt}	&= \frac{\rho_0 - \beta}{\Lambda} P(t) + \sum_{j=1}^6 \lambda_j C_j(t) \\
\frac{dC_j(t)}{dt}	&= \frac{\beta_j}{\Lambda} P(t) - \lambda_j C_j(t) , \qquad j= 1,2,3,...,6
\end{align*}
We assume here that we are using the conventional 6 delayed neutron precursor groups, each with delayed neutron fraction $\beta_j$, average decay constant $\lambda_j$, a mean generation time $\Lambda \equiv \frac{\ell}{k}$, and constant reactivity insertion $\rho_0$.

We had previously determined that the solutions of these equations are of the general form
$$ P(t) = Pe^{st} \quad\text{and}\quad C_j(t) = C_je^{st} ,$$
where $P$ and $C_j$ are constant coefficients, and $s$ is also a constant related to the time-dependent nature of the system. Note that since we have mutliple differential equations there will be an equivalent number of possible solutions. For the 6 group case there are 7 equations---1 power equation and 6 precursor equations. The complete solution will therefore be a combination (superposition) of all 7 possible solutions.
$$ P(t) = \sum_{i=1}^7 P_i \, e^{s_i t} $$
Frequently, reactor operators are interested in knowing what the effect would be of introducing something into the system that would change how the neutron population (or power production) evolves over time. For example, inserting a control rod or adding a soluble absorber to the moderator would constitute a reactivity adjustment of this type. If we decide not to solve for the constant coefficients for power and precursor group concentration, $P$ and $C_j$, we can instead make some simplifications to learn about the reactor's behavior over time for some arbitary reactivity insertion. We will solve for this reactivity, $\rho_0$.

First, we start by plugging the general form of the solutions back into the original PRKEs, taking the derivative on the left side of each equation, and dividing out the factor of $e^{st}$ from every term gives the following:
\begin{align*}
sP	&= \frac{\rho_0 - \beta}{\Lambda} P + \sum_{j=1}^6 \lambda_j C_j \\
sC_j	&= \frac{\beta_j}{\Lambda} P - \lambda_j C_j , \qquad j= 1,2,3,...,6
\end{align*}
Then, we take the second of these equations and solve for $C_j$ in terms of $P$,
$$ C_j = \frac{\beta_j}{\Lambda(s+\lambda_j)}P ,$$
and substitute this expression back into the first of these equations to eliminate the $C_j$ term altogether.
$$ sP = \frac{\rho_0 - \beta}{\Lambda} P + \sum_{j=1}^6 \frac{\beta_j \lambda_j}{\Lambda(s+\lambda_j)}P $$
At this point, we can eliminate $P$ by dividing it out of both sides of the equation, as well as factor out $\frac{1}{\Lambda}$ from all of the terms.
$$ s = \frac{1}{\Lambda}\left(\rho_0 - \beta + \sum_{j=1}^6 \frac{\beta_j \lambda_j}{(s+\lambda_j)}\right) $$
We note that $\beta = \sum_{j=1}^6 \beta_j$ and we can move the $\beta$ term into the summation as
$$ s = \frac{1}{\Lambda}\left(\rho_0 + \sum_{j=1}^6 \frac{\beta_j \lambda_j}{(s+\lambda_j)}-\beta_j\right) $$
or more simply
$$ s = \frac{1}{\Lambda}\left(\rho_0 - \sum_{j=1}^6 \frac{\beta_j s}{(s+\lambda_j)}\right) .$$
Here it is important to recall that $\Lambda \equiv \frac{\ell}{k}$, and $\rho_0 = \frac{k-1}{k}$. Since both terms are dependent on $k$ and our final goal is to solve for $\rho_0$, we will eliminate $\Lambda$. Manipulation of the reactivity formula leads us to the expression
$$ k = \frac{1}{1-\rho_0} $$
and so using this in our formula for the mean generation time gives
$$ \Lambda = \ell(1-\rho_0) $$
We substitute this in for $\Lambda$ in our equation for $s$ to get
$$ s = \frac{1}{\ell(1-\rho_0)}\left(\rho_0 - \sum_{j=1}^6 \frac{\beta_j s}{(s+\lambda_j)}\right) .$$
Finally, we solve algebraically for $\rho_0$ to get the \textbf{inhour equation}:
$$ \rho_0 = \frac{s\ell}{s\ell + 1} + \frac{1}{s\ell + 1}\sum_{j=1}^6 \frac{\beta_j s}{(s+\lambda_j)} .$$

When this equation is plotted, we can see that there are 7 possible solutions ($s_1$, $s_2$, $s_3$, ... $s_7$) for any value of $\rho_0$. There are also 7 vertical asymptotes, each corresponding to a value of $s$ for which the denominator of any term in the 6-group inhour equation goes to zero (at $s=-\frac{1}{\ell}$ and $s=-\lambda_j$ for all $j$).
%\includegraphic[width=10cm]{inhour-6group.jpg}

If we only had 1 delayed neutron group rather than 6, our equation would be
$$ \rho_0 = \frac{s\ell}{s\ell + 1} + \frac{1}{s\ell + 1}\frac{\beta_j s}{(s+\lambda)} .$$
There would now only be two possible solutions ($s_1$ and $s_2$) and two vertical asymptotes (at $s=-\frac{1}{\ell}$ and $s=-\lambda$).
%\includegraphic[width=10cm]{inhour-1group.jpg}

\end{document}


Figure \ref{fig:cooperation_M} shows cooperation levels achieved after $N=200$ iterations [i.e., $200 \times 49^2 = 480200$ Monte Carlo Steps (MCS)] for migration Moore's distances $M = \{1,3,5,7,9,11,13 \}$, as a function of the grid density $d$ and the probability of property violation $s$. At initialization ($i=0$), there is a $50\%$ chance that a player will be a cooperation (resp. defector). For all $M$, the cooperation exhibits a sharp drop for $d>d^*$  and $s > s^*$ with $(d^*,s^*)$ being a function of $M$. High levels of cooperation ($c > 0.8$) can be sustained for any migration range $M$ (note that for $0.02 < s < 0.05$, the cooperation level drops already to $c \approx 0.9$ for all $M$). However, the less migration capabilities (i.e., $M$ small), the more restrictive the space defined by $(d^*,s^*)$ and hence, the more sensitive the game to property violations (as shown on Figure  \ref{fig:cooperation_M}).\\

For high grid density ($d>0.9$), cooperation cannot be sustained for any level of migration $M>0$, even with low property violation ($s > 0$). Note that in the limit $d=1$, property violation reduces to swapping sites, since the only available site in the Moore area for the expelled player is the site left by the property violator.\\

\subsection*{Phase Transitions}
The smaller $M$, the sharper the transition between sustained cooperation and $c=0$: The probability to witness a given level of cooperation $c > 0$ (after $N=200$ iterations) decreases steadily (faster as $M \rightarrow 1$), until a point of abrupt break beyond which cooperation can no longer not strive (see Figure \ref{fig:phase_transition} for $0.4 < d < 0.6$). For $M \leqslant 5$, we observe a sharp phase transition from a high cooperation level $c \gtrsim 0.6$ to no cooperation left ($c=0$). For $M \geqslant 7$, we observe 3 possible states: high cooperation level $c \gtrapprox 0.6$ for property violation $s \lessapprox 0.4$ small, moderate cooperation $ 0.35 \lessapprox s  \lessapprox 0.5 $, and no cooperation.\\

These possible states and their stability are best represented (c.f., Figure \ref{fig:tseries}) from the cooperation time series for values $(M,d^*,s^*)$ with $M = \{ 5,7,11,13 \}$. For $M=5$, the intermediary state is not sustainable, and it seems that if a certain level of cooperation $c > 0.5$ cannot be achieved quickly cooperation ultimately disappears. For $M = \{7,11\}$ , an intermediary state appears with simulations displaying quasi-stationarity of cooperation $0.35 < c < 0.55$. Yet the stationary of this intermediary state may be broken after an arbitrary number of iterations (see e.g., simulation 12 for $M=7$, which drops after 170 iterations, or simulation 3 for $M=11$, which drops after 140 iterations). {\bf It also looks like that for $M=7$, the state of high cooperation is reached quickly and at high level, but this may be a pure selection bias}. For $M=13$ and for $s^* = 0.67(2)$, the intermediary state is stable (no deviation after an arbitrary number of iterations is observed), and the percentage of cooperators remains consistently below 0.5 (more precisely XX on average, standard deviation = XX). In other words, for a large enough migration range, cooperation can be sustained at rather high levels of property violation (e.g., $M=13, s^* = 0.67\pm0.2$), although cooperators are in minority.\\

\subsection*{Typical Spatial Configurations}

{\bf [Here we show typical spatial configurations]}

\begin{itemize}
  \item rapid extinction of cooperators in presence of $s > s^*$.
  \item well sustained cooperation in presence of property violators, yet with sufficiently high mobility $M$ and low enough grid density $d$ $\rightarrow$ $M=11$.
  \item cooperation at quasi-stationarity with level consistently below $0.5$ (e.g., $M=13$).
\end{itemize}

\subsection*{Case Study of Sudden Drops Cooperation Drops}

{\bf [Here, we study the 2 sudden changes of regime mentioned above] }


\chapter{Causality}

\begin{multicols}{2}[\subsubsection*{Contents of this chapter}]
   \printcontents{}{1}{\setcounter{tocdepth}{2}}
\end{multicols}

\section{Generalized Random Forests}
Notes on \citeasnoun{athey2016generalized}. Like most regression techniques, random forests are normally used to estimate the conditional mean of some data generating distribution, i.e. $\mu(x) = \mathbb{E}\left[Y|X=x \right]$. Athey, Tibshirani and Wager proposed generalized random forests, which estimate, more generally, some quantity $\theta(x)$. The main aim, and the reason why I am grouping this method under ``causality", is the estimation of heterogenous treatment effects.


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage{matlab-prettifier}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
%
% Basic Document Settings
%
\lstMakeShortInline[style=Matlab-editor]"

\topmargin=-1in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{AMATH 482 Homework 2: G\'abor transforms}
\newcommand{\hmwkDueDate}{January 25, 2019}
\newcommand{\hmwkClassInstructor}{Professor Nathan Kutz}
\newcommand{\hmwkAuthorName}{\textbf{Skyler Hallinan}}

%
% Title Page
%

\title{
    \textmd{\textbf{\text{ } \hmwkTitle}}\\
}

\author{\hmwkAuthorName}
\date{}

\begin{document}
\maketitle

\section*{\fontsize{19}{15}\selectfont Abstract}
	We started with data (music) in the time domain. Using the Gabor transform, we were able to translate this data into the time and frequency domain, creating a spectogram that allows us to visualize frequencies at specific points in time. We experimented with the different parameters used in the transform, and used it to transform to differentiate between the music of a piano and a recorder.
\section*{\fontsize{19}{15}\selectfont Introduction and Overview}
	In data such as music, we often collect it in in the time domain - Although we can tell when things happen, it is hard to tell what is going on in terms of frequencies. The Fourier Transform is a solution lets us transport this data into the frequency domain. However, with this transformed data, we now know what frequencies occur, but we have do not now when they occur in time. The Gabor transform allows us to take small chunks of data across our time domain, which are isolated by multiplying a filter around, then taking the Fourier transform of this data. Combining this frequency data across the small chunks of time allows us to have both a time and frequency visualization of data: We are now able to see what frequencies dominate at each small time interval. \\ \\
	In this project, we will first look at the effects of changing specific paramaters of the Gabor transform, like sampling rate, as well as window size (how much of the entire domain it captures at each timepoint). In addition, we will experiment with other filters other than the standardly used Gaussian one. Finally, we will look at data taken from a recorder and piano, remove the overtones, and then reproduce the music score, and note the differences between the two instruments.
\section*{\fontsize{19}{15}\selectfont Theoretical Background}
	We have seen that the fourier transform is an integral transform that decomposes a time defined function into its frequency components, and is defined by
	\begin{equation} \label{eq:2a}
		F(k) = \frac{1}{\sqrt2\pi} \int_{-\infty}^{\infty} e^{-ikx} f(x) dx
	\end{equation}
		\begin{equation} \label{eq:2b}
		f(x) = \frac{1}{\sqrt2\pi} \int_{-\infty}^{\infty} e^{ikx} F(k) dk
	\end{equation}
	The fast fourier transform, which is accessible in things like MATLAB, assumes that the user is working on a $2\pi$ periodic domain. "fftshift" must be used on the transformed data to undo the shifts naturally incurred by the fast fourier transform algorithm. \\ \\
A downside to the fourier transform is that in changing the domain to the frequency domain, it completely removes all time data from the equation. There is no way to visualize what is going on in terms of a time scale. G\'abor resolved this issue. \\
The Gabor transform is defined by $\mathcal { G } [ f ] ( t , \omega ) = \tilde { f } _ { g } ( t , \omega ) = \int _ { - \infty } ^ { \infty } f ( \tau ) \overline { g } ( \tau - t ) e ^ { - i \omega \tau } d \tau = \left( f , \overline { g } _ { t , \omega } \right)$. We see that this GAabor function localizes signal with the fourier transform over specific small windows of time. The $\tau$ paramater is able to slide the window across the entire domain, resulting in a capturing of both time and frequency domain. Because of the nature of this transform, it is also called the short time fourier transform. \\ \\
There are limitations to this method: It is not possible to have perfect resolution in both the frequency and the time domain; increasing time resolution decreases frequency resolution and vice versa. Just like the Heisenberg Uncertainty Principle, it is impossible to know both of these things at the same time. However, one can adjust the parameters of the transform in order to get more data towards one direction or the other. \\ \\
Wavelets are used in these transforms to highlight specific parts of the signal. Wavelets like the Gaussian and the Mexican Hat wavelet are shifted across the time domain and multiplied by the data so that specific fourier transform information can be taken, and then plotted later.
\section*{\fontsize{19}{15}\selectfont Algorithm Implementation and Development}
\textbf{Part One} \\
We first found the length of our data and the number of time points at which it occurred, then created a vector of time.
In addition, we rescaled our wavenumbers $k$ by $\frac{2\pi}{L}$ as the fast fourier transform assumes $2\pi$ periodic signals. We then defined a vector "tslide" which corresponded to the length of time of the recording of music, in 0.1 s increments. \\ \\
We then used a for loop to iterate through the length of "tslide", creating and adjusting a Gaussian filter so that it was centered around "t-tslide" the entire time. We multiplied this filter by our data, then took the fast fourier transform of it. Finally, we entered it back into our spectogram array after taking the absolute value of the "fftshift" of this. We repeated this with larger and smaller increments in our "tslide", different filters (Mexican Hat and Step function), and with different widths of our Gaussian filter. Finally, we used "pcolor" to visualize our G\'abor Transforms in the form of spectograms. We had to divide by $2pi$ to get accurate frequency information since we multiplied by $2pi$ in our original wavenumbers. \\ \\
\textbf{Part Two} \\
We repeated the same initial data preparation used for part one: Defining the length of the data, creating our "tslide" variable, and rescaling our wavenumbers. We did the same loop to fill our spectogram with data, using a Gaussian filter with a sigma value of -100. We then used $pcolor$ to plot the side by side spectograms, once again dividing by $2pi$ to get accurate frequency values. \\ \\
We also did some more work in the same G\'abor transform loop to generate the music scores. In order to remove overtones from the data, we found the index of the max value of the fourier transform at a certain time. The max value indicated that this particular frequency is the strongest at this time point, so we could effectively extract the corect frequency while removing some overtone noise. We did this by using the "max" command during the G\'abor transform loop, then plugging this index into "ks". We then, once again, divided by $2pi$ to get our frequency numbers.
\begin{figure}[H]
\begin{center}
\includegraphics[width = 10cm]{normal}
\caption{\label{fig:scaled_diss} (left) Spectogram of normally made data}
\end{center}
\end{figure}

\begin{figure}
\begin{center}
\includegraphics[width = 8cm]{undersampling}
\includegraphics[width = 8cm]{oversampling}
\caption{\label{fig:scaled_diss} (left) Spectogram of Undersampled Data}
\caption{\label{fig:scaled_diss} (right) Spectogram of Oversampled Data}
\end{center}
\end{figure}

\section*{\fontsize{19}{15}\selectfont Computational Results}
	\textbf{Part One} \\
	We were able to find a balance of the correct level of accuracy in the time and frequency domain by using a value of -100 for our sigma in our Gaussian filter. We first generated a spectogram of our data using this accurate filter, as well as a reasonable sampling amount (100). We then compared it to our undersampled and oversampled data. We see that in when we undersample, the quality of the data dramatically dips, and we are left with an incoherent spectogram, both in the time and the frequency domain. Oversampling, on the other hand, produces a slightly clearer spectogram. Although this may sound good in principle, the benefits of oversampling were minimal - the spectograms of the normally sampled and oversampled data looked almost identical - the negatives were that run time severely increased because we were introducing so much more data.\\ \\
\begin{figure}[h]
\begin{center}
\includegraphics[width = 8cm]{shannon}
\includegraphics[width = 8cm]{mxhat}
\caption{\label{fig:scaled_diss} (left) Spectogram of Shannon Filtered Data}
\caption{\label{fig:scaled_diss} (right) Spectogram of Mexican Hat Filtered Data}
\end{center}
\end{figure}

\begin{figure}[h]
\begin{center}
\includegraphics[width = 8cm]{largewindow}
\includegraphics[width = 8cm]{smallwindow}
\caption{\label{fig:scaled_diss} (left) Spectogram of Large Window Filtered Data}
\caption{\label{fig:scaled_diss} (right) Spectogram of Small Window Filtered Data}
\end{center}
\end{figure}
We see that when we decreased the window, we got very precise measurements in the frequency domain. This is because we were essentially taking the fourier transform of a huge area, which will give us lots of information about the frequency, but not the time data. The convserse was true for a large window; We were able to see lots of information in the time domain, but because our window size was so small, we couldn't get as precise frequency measurements. \\ \\
The Mexican Hat function and Step function (Shannon) performed similarly to the Gaussian filter. We see in the spectograms that although they are similar to eachother, while the Shannon filtered data seems to have a bit more accuracy in the frequency domain at the sacrifice of less resolution in the time domain. The time domain is more continuous for the Mexican Hat filtered data, but there is less resolution in the frequency domain. However, these are both useful filters like the Gaussian filter. In both of these, we used a sigma value of 0.05, which changed the width of the filter. We also observed the same window size and undersampling/oversampling effects with these filters.

\begin{figure}[h]
\begin{center}
\includegraphics[width = 16cm]{pianorecorder}
\caption{\label{fig:scaled_diss} (right) Piano and Recorder Spectogram}
\end{center}
\end{figure}

\begin{figure}[h]
\begin{center}
\includegraphics[width = 8cm]{piano}
\includegraphics[width = 8cm]{recorder}
\caption{\label{fig:scaled_diss} (left) Piano Score}
\caption{\label{fig:scaled_diss} (right) Recorder Score}
\end{center}
\end{figure}
\textbf{Part Two} \\
We were able to determine the score of the music from the piano data, after filtering out overtones, and see that they follow the same general pattern, but are at different frequencies. From the spectograms of the data between the recorder and the piano, we see that there seem to be more overtones and undertones on the piano than there are in a recorder. In the case of the piano, we see that outside of the brightly colored frequency areas, there are lots of residual frequencies above and below it. In recorders, we see that most of the other frequencies seem to be below the note.

\section*{\fontsize{19}{15}\selectfont Summary and Conclusions}
We started with music data purely in the time domain. In order to visualize this data in the time and frequency domain, we employed the Ga\'bor transform, which allowed us to create spectograms to visualize the data. We were able to see how changing parameters in the filter, as well as changing the filter itself, affected the transformation. Finally, from music data from a piano and a recorder, we took the G\'abor transform and filtered out overtones in order to reproduce the score.
\section*{\fontsize{19}{15}\selectfont Appendix A}
\subsection*{MATLAB functions used and implementation}
"abs(X)" : Returns the absolute value of every element in X, or complex magnitude if the element is complex. We used this function to normalize the data before plotting our spectogram.\\ \\
"fft(X)" : Performs a fast fourier transform on "X", a 2-D array. We used this fourier transform the filter multiplied by the data at each of our time points.\\ \\
"fftshift(X)" : Rearranges the contents of "X" by placing the zero-frequency component to the center of the array. If "X" is a vector, shifts the left and right halves of "X", while if "X" is a matrix, the $I$ and $III$ quadrants are switched, as well as the $II$ and $IV$ quadrants. We used this to change our transformed data and our axes for proper visualization.  \\ \\
"linspace(x1,x2,n)" : Creates a vector of "n" evenly spaced points from "x1" to "x2". We used this to create our linearly spaced data.  \\ \\
"[M,I] = max(A)" : Returns the maximum value "M" and the index "I"  of the matrix. We used this in part 2 to filter out the overtones by determining the index of the max value of a fourier transform of a time slice.
\pagebreak
\section*{\fontsize{19}{15}\selectfont Appendix B}
\subsection*{MATLAB code}
\begin{lstlisting}[style=Matlab-editor]
%Part One
clear all; close all; clc;
clear all; close all; clc;

load handel
v = y'/2;
v(end) = [];
vt = fft(v);

%My code
L = 9; n = length(v);
t2 = linspace(0, L, n+1); t= t2(1:n);
k = (2*pi/L) * [0:n/2-1 -n/2:-1]; ks = fftshift(k);

subplot(2,1,1)
plot(t,v);
xlabel('Time [sec]');
ylabel('Amplitude');
title('Signal of Interest, v(n)');

subplot(2,1,2)
plot(ks, abs(fftshift(vt)));

%Gaussian Window
tslide= 0:0.1:9;
spc = [];
spcsmallwindow = [];
spclargewindow = [];
spcmxhat = [];
spcshn = [];

figure(2)
for j=1:length(tslide)
    g = exp(-100*(t-tslide(j)).^2);
    gsm = exp(-1*(t-tslide(j)).^2);
    glg = exp(-1000*(t-tslide(j)).^2);

    omega = 0.05;
    mxhat = (2/ (sqrt(3*omega) * pi^(0.25))).* (1-((t-tslide(j))/omega).^2) .* exp(-((t-tslide(j)).^2)/(2 * omega^2));

    sig = 0.05;
    shn = abs(t-tslide(j)) <= sig/2;

    vg = g.*v;
    vgt = fft(vg);

    vgsm = gsm.*v;
    vgsmt =fft(vgsm);

    vglg = glg.*v;
    vglgt =fft(vglg);

    vmx = mxhat.*v;
    vmxt = fft(vmx);

    vshn = shn.*v;
    vshnt = fft(vshn);

%     subplot(2,1,1)
%     plot(t,v,'k-', t, mxhat, 'Linewidth', 2);
%     axis([0 9 -0.5 1])
%
%     subplot(2,1,2)
%     plot(t,vg, 'Linewidth', 2);
%     axis([0 9 -0.4 0.4])
%
    spc = [spc; abs(fftshift(vgt))];
    spcsmallwindow = [spcsmallwindow; abs(fftshift(vgsmt))];
    spclargewindow = [spclargewindow; abs(fftshift(vglgt))];
    spcmxhat = [spcmxhat; abs(fftshift(vmxt))];
    spcshn = [spcshn; abs(fftshift(vshnt))];
    pause(0.00001);
end

tslideover = 0:0.01:9;
spcover = []
for j=1:length(tslideover)
    g = exp(-200*(t-tslideover(j)).^2);
    vg = g.*v;
    vgt = fft(vg);

    spcover = [spcover; abs(fftshift(vgt))];
    pause(0.00001);
end

tslideunder = 0:1:9;
spcunder = []
for j=1:length(tslideunder)
    g = exp(-200*(t-tslideunder(j)).^2);
    vg = g.*v;
    vgt = fft(vg);

    spcunder = [spcunder; abs(fftshift(vgt))];
    pause(0.00001);
end

figure;
%frequency here?
pcolor(tslide,ks./(2*pi),spc.'), shading interp, colormap(hot)
xlabel("Time (s)");ylabel("Frequency (Hz)"); title("Normal sampling, normal window");

figure;
pcolor(tslide,ks./(2*pi),spcsmallwindow.'), shading interp, colormap(hot)
xlabel("Time (s)");ylabel("Frequency (Hz)"); title("Normal sampling, small window");

figure;
pcolor(tslide,ks./(2*pi),spclargewindow.'), shading interp, colormap(hot)
xlabel("Time (s)");ylabel("Frequency (Hz)"); title("Normal sampling, large window");

figure;
pcolor(tslide,ks./(2*pi),spcmxhat.'), shading interp, colormap(hot)
xlabel("Time (s)");ylabel("Frequency (Hz)"); title("Mexican Hat, omega = 0.05");

figure;
pcolor(tslide,ks./(2*pi),spcshn.'), shading interp, colormap(hot)
xlabel("Time (s)");ylabel("Frequency (Hz)"); title("Step Function (Shannon), sigma = 0.05");

figure;
pcolor(tslideover,ks./(2*pi),spcover.'), shading interp, colormap(hot)
xlabel("Time (s)");ylabel("Frequency (Hz)"); title("Oversampling");

figure;
pcolor(tslideunder,ks./(2*pi),spcunder.'), shading interp, colormap(hot)
xlabel("Time (s)");ylabel("Frequency (Hz)"); title("Undersampling");

%Part Two
close all; clear all; clc;

pia=(audioread('music1.wav')).';
% plot((1:length(pia))/Fs,pia);
% xlabel('Time [sec]'); ylabel('Amplitude');
% title('Mary had a little lamb (piano)'); drawnow

Lpia=16;  % record time in seconds%
n = length(pia);
Fspia=length(pia)/Lpia;
t2 = linspace(0, Lpia, n+1); tpia= t2(1:n);
kpia = (2*pi/Lpia) * [0:n/2-1 -n/2:-1]; kspia = fftshift(kpia);
tslidepia = 0:0.2:16;

spcpia = [];
pianotes = [];
for j=1:length(tslidepia)
    g = exp(-100*(tpia-tslidepia(j)).^2);

    vgpia = g.*pia;
    vgpiat = fft(vgpia);
    [M,I] = max(vgpiat);

    pianotes = [pianotes; abs(kpia(I))/(2*pi)];
    spcpia = [spcpia; abs(fftshift(vgpiat))];
end

%figure(2)
rec=(audioread('music2.wav')).';
% plot((1:length(rec))/Fs,rec);
% xlabel('Time [sec]'); ylabel('Amplitude');
% title('Mary had a little lamb (recorder)');

Lrec=14;  % record time in seconds
Fsrec=length(rec)/Lrec;
n = length(rec);
t2 = linspace(0, Lrec, n+1); trec= t2(1:n);
krec = (2*pi/Lpia) * [0:n/2-1 -n/2:-1]; ksrec = fftshift(krec);
tsliderec = 0:0.2:16;

spcrec = [];
recnotes = [];
for j=1:length(tsliderec)
    g = exp(-100*(trec-tsliderec(j)).^2);

    vgrec = g.*rec;
    vgrect = fft(vgrec);

    [M,I] = max(vgrect);
    recnotes = [recnotes; abs(krec(I))/(2*pi)];

    spcrec = [spcrec; abs(fftshift(vgrect))];
end

% figure;
%
subplot(2,1,1)
pcolor(tslidepia,(kspia/(2*pi)),spcpia.'), shading interp
xlabel("Time (s)");ylabel("Frequency (Hz)"); title("Piano");
ylim([0 400])
subplot(2,1,2)
pcolor(tsliderec,ksrec/(2*pi),spcrec.'), shading interp, colormap(hot)
xlabel("Time (s)");ylabel("Frequency (Hz)"); title("Recorder");
ylim([600 1000])

plot(tslidepia,pianotes,'o','MarkerFaceColor', 'b');
yticks([246.9417,261.6256,277.1826,293.6648,311.127,329.6276,349.2282]);
yticklabels({'B3','C4','C#4','D4','E4','F4'});
ylim([246 350])
title("Score for Piano Music (~250-350Hz");
xlabel("Time (s)"); ylabel("Notes corresponding to frequency (Hz)");

plot(tsliderec,recnotes,'o', 'MarkerFaceColor', 'b')
yticks([698.4565,739.9888,783.9909,830.6094,880,932.3275]);
yticklabels({'F5','F#5','G5','G#5','A5','A#5'});
ylim([680 950])
title("Score for Recorder Music (~680-950Hz)");
xlabel("Time (s)"); ylabel("Notes corresponding to frequency (Hz)");
\end{lstlisting}

\end{document}


\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{algpseudocode}
\usepackage{algorithm}

% Geometry
\usepackage{geometry}
\geometry{letterpaper, left=15mm, top=20mm, right=15mm, bottom=20mm}

% Fancy Header
\usepackage{fancyhdr}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}
\fancyhf{}
\chead{CSC 360 - Analysis of Algorithms}
\lfoot{CALU Fall 2021}
\rfoot{RDK}

% Add vertical spacing to tables
\renewcommand{\arraystretch}{1.4}

% Macros
\newcommand{\definition}[1]{\underline{\textbf{#1}}}

\newenvironment{rcases}
  {\left.\begin{aligned}}
  {\end{aligned}\right\rbrace}

% Begin Document
\begin{document}

\section*{Notes Week 6}

\begin{itemize}

    \item Read Chapters 22, Chapter 9 for Week 7

\end{itemize}

\subsection*{Rules for Big O Notation (Upper Bounds)}

\begin{itemize}

    \item \textbf{Transitivity}: If $f = O(g)$ and $g = O(h)$ then $f = O(h)$

    \item \textbf{Sums}: If $f_1 = O(g_1)$ and $f_2 = O(g_2)$ then $f_1(n) + f_2(n) = O( max(f, g) )$

    \item \textbf{Products}: If $f_1 = O(g_1)$ and $f_2 = O(g_2)$ then $f_1 \times f_2 = O(g_1 \times g_2)$

    \item If the largest term is a polynomial of degree $k$, then the whole thing is $\Theta(n^k)$

    \item $log^kn = O(n) \rightarrow$ a log raised to any constant power is still just $O(n)$

    \item $\lim{n\to\infty} \frac{f(n)}{g(n)} \rightarrow$ If the limit is:
    \begin{itemize}
        \item \textbf{0} $\rightarrow f=o(g) \rightarrow g(n) > f(n) \rightarrow g$ dominates $f$
        \item \textbf{$c \neq 0$} $\rightarrow f = \Theta(g(n)) \rightarrow g(n) = \Theta(f(n))$
        \item \textbf{$\infty$} $\rightarrow g(n) = o(f(n))$
    \end{itemize}

    \item Example: $f(n) = \frac{n}{log(n), g(n) = n^{\frac{1}{2}}log^2n}$

\end{itemize}

\subsection*{Rules for Big $\Omega$ Notation (Lower Bounding)}

\begin{itemize}

    \item \textbf{Comparison-based Solution} $\omega(nlogn) \rightarrow$ it's been proven that comparison-based sorting cannot be faster

    \item Some problems are $\Omega(2^n) \rightarrow$ Super slow

\end{itemize}

\subsection*{Quick Maths}

\begin{itemize}

    \item $b^{log_ba} = a$

    \item $a^{log_bn} = n^{log_ba}$

    \item Any exponential function dominates any polynomial
    \begin{itemize}
        \item Exponential function $\rightarrow 2^n \rightarrow$ variable in the exponent
        \item Polynomial function $\rightarrow n^{234} \rightarrow$ exponent is a constant
    \end{itemize}

    \item $\sum(ca_k + b_k) = c\sum(a_k) + \sum(b_k)$

\end{itemize}

\section*{Recurrences - Recurrence Relations}

\begin{itemize}

    \item A \definition{Recurrence} is used when dealing with recursion.

    \item Merge Sort: \\

    \begin{tabular}{l c c}
        \textbf{Case} & \textbf{Formula} & \textbf{Big O} \\
        base case & $T(n) = \Theta(1)$ & $\Theta(1)$ \\
        not base case & $2T(\frac{n}{2}) + \Theta(n)$ & ?
    \end{tabular}

    \item How does $2T(\frac{n}{2})$ explain the recurrence of merge sort?
    \begin{itemize}
        \item Each division splits the array in half
        \item There are two pieces in each call, one for each half
        \item So the array is split in half, and each is operated on recursively
    \end{itemize}

    \item So what is the $O($merge-sort$)$
    \begin{itemize}

        \item $T(n) = 2T(\frac{n}{2}) + n \rightarrow$ Merge Sort Recurrence
        \item Solve using iteration method: ``Unfold the recurrence''
        \begin{enumerate}

            \item If there's a constant, write out that constant with square brackets empty to indicate something needs done
            \begin{equation}
                2[\ \ \ ] + n
            \end{equation}

            \item Plug the $\frac{n}{2}$ back into the original
            \begin{equation}
                2[ 2T(\frac{n}{4}) + \frac{n}{2} ] + n
            \end{equation}

            \item Multiply it out
            \begin{equation*}
                4T(\frac{n}{4}) + 2n
            \end{equation*}

            \item Take the previous iteration (2) and repeat
            \begin{equation}
                4[ 2T(\frac{n}{8}) + \frac{n}{4} ] + 2n
            \end{equation}

            \item Simplify
            \begin{equation*}
                8T(\frac{n}{8}) + 3n
            \end{equation*}

            \item Repeat the process until you can spot the general case. The next iteration would be
            \begin{equation}
                16T(\frac{n}{16}) + 4n
            \end{equation}

            \item Write down the general case in terms of $k$
            \begin{equation*}
                2^k(\frac{n}{2^k}) + kn
            \end{equation*}

            \item How many times does the recurrence occur? $k = log_2n$

            \item Plug in k
            \begin{equation*}
                2^{log_2n} T(\frac{n}{2^{log_2n}}) + nlog_2n
            \end{equation*}

            \item Simplify
            \begin{equation*}
                n T(1) + nlog_2n = O(nlog_2n)
            \end{equation*}

        \end{enumerate}

    \end{itemize}

\end{itemize}

\end{document}


\documentclass{article}
%\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{color}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{mathrsfs}
\usepackage{enumerate}
\usepackage[margin=1in]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Final 04}
\rhead{Jon Allen}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\degree}{\ensuremath{^\circ}}

\begin{document}
\subsubsection*{PDE C.}
\begin{align*}
  \text{PDE.}&&\frac{\partial u}{\partial t}&=\frac{\partial^2u}{\partial x^2}&&\text{for}&0&<x<\infty,&0&<t<\infty\\
  \text{BC.}&&\frac{\partial u}{\partial x}(0,t)&=u(0,t)-\frac{1}{\sqrt{\pi t}}&&\text{for}&&&0&<t<\infty\\
  \text{IC.}&&u(x,0)&=0&&\text{for}&0&<x<\infty
\end{align*}

Solve PDE C completely by a Laplace transform with respect to $t$. Use the BC as stated -- do not transform to homogeneous BC. (The necessary inverse Laplace transform is not in the textbook table but is on the handout list of transforms.)

\begin{align*}
  sU(x)-0&=\frac{\mathrm{d}^2U}{\mathrm{d}x^2}(x)\\
  \frac{\mathrm{d}U}{\mathrm{d}x}(0)&=U(0)-\mathcal{L}\left\{\frac{1}{\sqrt{\pi t}}\right\}\\
  &=U(0)-\frac{1}{\sqrt{s}}\qquad\text{used computer}\\
  0&=\frac{\mathrm{d}^2U}{\mathrm{d}x^2}(x)-sU(x)\\
  0&=r^2+0r-s\\
  r&=\frac{\pm\sqrt{4s}}{2}=\pm\sqrt{s}\\
  U(x)&=c_1e^{x\sqrt{s}}+c_2e^{-x\sqrt{s}}\\
  U'(x)&=c_1\sqrt{s}e^{x\sqrt{s}}-c_2\sqrt{s}e^{-x\sqrt{s}}\\
  U'(0)&=c_1\sqrt{s}-c_2\sqrt{s}=c_1+c_2-\frac{1}{\sqrt{s}}\\
  c_1\sqrt{s}-c_1&=c_2+c_2\sqrt{s}-\frac{1}{\sqrt{s}}\\
  \intertext{used computer to help find convenient values}
  c_1(\sqrt{s}-1)&=\frac{1}{s+\sqrt{s}}+\frac{\sqrt{s}}{s+\sqrt{s}}-\frac{1}{\sqrt{s}}\\
  c_1(\sqrt{s}-1)&=\frac{\sqrt{s}+s}{\sqrt{s}(s+\sqrt{s})}-\frac{s+\sqrt{s}}{\sqrt{s}(s+\sqrt{s})}\\
  c_1=0\\
  c_2&=\frac{1}{s+\sqrt{s}}\\
  U(x)&=\frac{1}{s+\sqrt{s}}e^{-x\sqrt{s}}\\
  \intertext{from handout}
  u(x,t)&=e^{x+t}\text{erfc}\left(\sqrt{t}+\frac{x}{2\sqrt{t}}\right)
\end{align*}
\end{document}


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

Although Turing machines are a simple (but not quite simplistic) model of computation, there are not many \textit{rigorous} proofs about Turing
machines in the literature.  We think that the following points are reasons for that.  First, their semantics is \textit{unstructured}: from each
state of the machine, the execution can proceed in every other state, similar to the infamous \textit{goto} statement~\cite{dijkstra2002go}.  But even
worse, Turing machines are not \textit{compositional}.  Sequential composition or loops of Turing machines are not \textit{per~se} available.  Even
the formal specification of machines is a burden, because complex machines may have a huge number of internal states.  Last but not least, they are
\textit{low-level}, because the operation on tapes are primitive: read a symbol from the tape, write a symbol to the tape, or move the (read/write)
head in a direction.

For the above reasons, textbooks like Boolos et~al.~\cite{boolos2007computability} leave out detailed proofs of correctness.  They also often only
give an informal description of machines, which obviously makes formal reasoning impossible.  Even if they define the whole machine, they leave out
formal specifications of invariants to figure out for the reader.  To establish that a function is Turing computable, authors often give an informal
description of the algorithm and conclude, using the \textit{Church-Turing thesis}, that the function is Turing-computable. Or they switch to another
abstract machine model, but define the compilation function between the models of computation only informally.

In this thesis, we aim to define, specify, and formally verify Turing machines in a framework built in the theorem prover Coq~\cite{Coq}.  First of
all, we address the problems above.  Instead of defining machines in terms of transition tables, we compose machines using functions of Coq's
dependent type theory -- the \textit{Calculus of (Co)Inductive Constructions} (also known as CIC).  For example, we define a function that builds the
sequential composition of two machines.  To eliminate the need to reason about concrete machine states, we give all states a label (e.g.\ $\true$ or
$\false$) and only have to reason about these labels.  The number of labels is always reasonable small, compared to the potential huge amount of
states.  We address the problem that machines are low-level, by introducing abstractions, so that we can define Turing machines that directly
manipulate values of arbitrary encodable types.  This gives the advantages of register machines, but we are not restricted to natural numbers.

There are many variants of Turing machines.  All variants can be shown to be computationally equivalent.  In this thesis, we choose multi-tape Turing
machines with arbitrary finite alphabets.  Our plan is that each tape should contain a value.  We choose a finite model of tapes.  This means that
each tape has only finitely (but arbitrarily) many symbols.

\section{Contributions}
\label{sec:contributions}

We formalise a variant of deterministic multi-tape Turing machines in the interactive theorem prover Coq.  We build a framework for programming and
formally verifying correctness and time complexity of Turing machines.  Our framework extends the framework by Asperti and
Ricciotti~\cite{asperti2015} in the interactive theorem prover Matita~\cite{asperti2011matita}.  Compared to their framework, we eliminate the need to
reason about concrete machine states and introduce more general control-flow operators.  We increase the level of programming abstraction and make it
possible that Turing machines can directly manipulate values of arbitrary encodable types.  We show that our framework is strong enough to implement
and verify a Turing machine that simulates a two-stack machine for a variant of the $\lambda$-calculus.  We formally prove that the halting problem of
this abstract machine reduces to the halting problem of multi-tape Turing machines.  Thereby, this work is the last step to formally prove that
multi-tape Turing machines can simulate the $\lambda$-calculus.

\section{Related Work}
\label{sec:relatedwork}

Asperti and Ricciotti~\cite{asperti2012} formalise single-tape Turing machines over arbitrary finite alphabets in the interactive theorem prover
Matita.  Matita uses the same constructive type theoretic foundation as Coq.  In~\cite{asperti2015}, they formalise multi-tape Turing machines in
Matita.  They introduce the notion of \textit{realisation} for specifying the semantics of concrete Turing machines.  They define and verify a
universal Turing machine and also formalise the reduction from multi-tape Turing machines to single-tape Turing machines.  Furthermore, they propose
the formalisation of Turing machines as a benchmark for comparing proof assistants.

Xu, Zhang, and Urban~\cite{xu2013} formalise single-tape Turing machines over a binary alphabet in Isabelle/HOL.  They follow the textbook of Boolos
et~al.~\cite{boolos2007computability} and use Hoare-logic to specify the semantics of concrete Turing machines.  They implement formally verified
translation functions from \textit{abacus programs} and \textit{partial recursive functions} to Turing machines and prove the undecidability of the
halting problem of Turing machines.

Ciaffaglione et~al.~\cite{ciaffaglione2016} define tapes of Turing machines as infinite streams.  They verify Turing machines using induction and
co-induction and also show the undecidability of the halting problem in Coq.

Forster, Heiter, and Smolka~\cite{forster2018verification} formally reduce the halting problem of single-tape Turing machines to the \textit{Post
  correspondence problem} (PCP) in Coq.  They use the same definition of Turing machines as we use, but restricted to one tape.  This definition of
single-tape Turing machines was originally presented in~\cite{asperti2012}.

There are other mechanisations of abstract machine models.  For example, Forster and Smolka~\cite{forster2017weak} formalise the theory of computation
in Coq, based on the language~$L$, which is also known as the (weak) call-by-value $\lambda$-calculus.  Norrish~\cite{norrish2011mechanised}
formalises computability theory in HOL4.  He considers a variant of the $\lambda$-calculus and recursive functions, and show that both models of
computation are computationally equivalent.  Kunze et~al.~\cite{KunzeEtAl:2018:Formal} formalise reductions from the programming language $L$ to
several stack-machines.  The stack-machine for that we build a simulator is a variant of a machine of this paper.

\section{Outline}
\label{sec:outline}

In Chapter~\ref{chap:definitions}, we define the notion of multi-tape Turing machines.  We also introduce means to specify the semantics of concrete
machines.  In Chapter~\ref{chap:basic}, we define primitive machines, on which all our machines are based.  In Chapter~\ref{chap:combining}, we define
control-flow operators.  In Chapter~\ref{chap:lifting}, we show how to combine machines with different alphabets and numbers of tapes.  We build
simple machines in Chapter~\ref{chap:compound}.  In Chapter~\ref{chap:programming}, we introduce abstractions that enable the programmer to directly
manipulate values, and we show complex case-studies.  In Chapter~\ref{chap:heap}, we develop our final case-study where we implement and verify a
Turing machine that simulates a two-stack machine for $L$ and show that the halting problem of this machine reduces to the halting problem of
multi-tape Turing machines.  We conclude and discuss possible future work in Chapter~\ref{chap:conclusion}.  In the appendix, we present pearls of the
Coq development of this thesis.

Throughout the thesis, we use mathematical notation, the reader is not required to be expert in type theory.  In the PDF version of this thesis, all
definitions and lemmas are hyperlinked to the documented online source code of the Coq implementation.  The source code is tested to compile with Coq
versions 8.7 and 8.8.  The home page of this thesis contains the PDF version, the source code, and online documentation:
\begin{center}
  \url\homepage
\end{center}

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


\documentclass{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{listings}
\begin{document}
\section{GDA}
\subsection{Abstract}
In this chapter, we will learn an algorithm of linear classification - soft output - probability generation model: GDA (Gaussian Discriminant Analysis).
\subsection{Idea}
In the last chapter, the logistic regression algorithm we learned belongs to probability discriminant model, so the difference between the discriminant model and the generation model is:
\begin{itemize}
	\item the discriminant model is used to model the probability $p(y|x)$ directly to obtain its truly probability value.
	\item the generation model is used to model the joint distribution $(x,y)$ via converting $p(y|x)$ to $p(x|y)p(y)$ according to bayes theorem: $p(y|x)=\frac{p(x|y)p(y)}{p(x)}$. Since $p(x)$ has nothing to do with $y$, it can be omitted. So, finally we get:$$
p(y|x)\propto p(x|y)p(y)=p(x;y)
$$
\end{itemize}
when we are to predict any samples, we just need to compare $p(y=0|x)$ and $p(y=1|x)$.
\subsection{Algorithm}
Firstly, let's make some assumption about the model:
$$
y\in \{0,1\}\quad y\sim Bernuolli(\phi)\quad p(y)=\phi^y(1-\phi)^{1-y}\\\left \{\begin{aligned}x|y=1 \quad \sim \quad N(\mu_1,\Sigma)\\x|y=0 \quad \sim \quad N(\mu_2,\Sigma)\end{aligned}\right.
$$
$$
\Longrightarrow p(x|y)=N(\mu_1,\Sigma)^yN(\mu_2,\Sigma)^{1-y}
$$
so all the parameters $\theta$ of the model are:
$$
\theta=(\phi, \mu_1, \mu_2, \Sigma)
$$
Then given the loss function of the model:
$$
\begin{aligned}
J(\theta)=log(p(Y|X))&=log(\prod_{i=1}^n p(y_i|x_i))\\
&=\sum_{i=1}^n log(p(y_i|x_i))\\
\end{aligned}
$$
so:
$$
\begin{aligned}
\hat{\theta}=argmax(J(\theta))&=argmax(\sum_{i=1}^nlog(\frac{p(x_i|y_i)p(y_i)}{p(x_i)}))\\
&=argmax(\sum_{i=1}^n log(p(x_i|y_i)p(y_i)))\\
&=argmax(\sum_{i=1}^n y_i\ log(N(\mu_1,\Sigma))+(1-y_i)\ log(N(\mu_2,\Sigma))+log(\phi^{y_i} (1-\phi)^{1-y_i}))
\end{aligned}
$$
\subsubsection{Solve $\phi$}
differentiate $\phi$:
$$
\sum_{i=1}^{N} \frac{y_{i}}{\phi}+\frac{y_{i}-1}{1-\phi}=0
\Longrightarrow \phi=\frac{\sum_{i=1}^{N} y_{i}}{N}=\frac{N_{1}}{N}
$$
In the formula, $N,N_1,N_2$ denote the number of all samples, positive samples, negative samples.
\subsubsection{Solve $\mu$}
make some derivations based on $J(\theta)$:
$$
\begin{aligned} \hat{\mu_{1}}
&=\underset{\mu_{1}}{argmax} \sum_{i=1}^{N} y_{i} \log N\left(\mu_{1}, \Sigma\right) \\
&=\underset{\mu_1}{argmax} \sum_{i=1}^{N} y_i \log (\frac{1}{(2\pi)^{\frac{p}{2}}|\Sigma|^{\frac{1}{2}}}exp(-\frac{1}{2}(x_i-\mu_1)^T(\Sigma)^{-1}(x_i-\mu_1)))\\
&=\underset{\mu_{1}}{argmin} \sum_{i=1}^{N} y_{i}\left(x_{i}-\mu_{1}\right)^{T} \Sigma^{-1}\left(x_{i}-\mu_{1}\right)
\end{aligned}
$$
In the above derivations, we quote the probability density function of multivariate Gaussian distribution:
$$
p(x)=\frac{1}{(2\pi)^{\frac{p}{2}}|\Sigma|^{\frac{1}{2}}}exp(-\frac{1}{2}(x_i-\mu_1)^T(\Sigma)^{-1}(x_i-\mu_1))
$$
In the function, $p$ denote the number of random variables. Readers can multiply the probability density function of univariate Gaussian distribution, and derive the multivariate formula with the knowledge of linear algebra.\\
then differentiate the formula:
$$
\frac{\partial \Delta}{\partial \mu_1}=\sum_{i=1}^N -2y_i (\Sigma)^{-1}(x_i-\mu_1)=0\\
\Longrightarrow \mu_{1}=\frac{\sum_{i=1}^{N} y_{i} x_{i}}{\sum_{i=1}^{N} y_{i}}=\frac{\sum_{i=1}^{N} y_{i} x_{i}}{N_{1}}
$$
Since the positive samples and the negative samples are symmetrical, therefore:
$$
\mu_{2}=\frac{\sum_{i=1}^{N}\left(1-y_{i}\right) x_{i}}{N_{2}}
$$
\subsubsection{Solve $\Sigma$}
observe the first two terms of the formula:
$$
\hat{\theta}=argmax(\sum_{i=1}^n y_i\ log(N(\mu_1,\Sigma))+(1-y_i)\ log(N(\mu_2,\Sigma))+log(\phi^{y_i} (1-\phi)^{1-y_i}))
$$
We note that when $y=0$, the first term equals to $0$; when $y=1$, the second term equals to $0$.\\
thus the formula can be updated to:
$$
\begin{aligned}
\hat{\theta}
&=argmax(\sum_{(x_i,y_i)\in C_1} \ log(N(\mu_1,\Sigma))+\sum_{(x_i,y_i)\in C_2}\ log(N(\mu_2,\Sigma)))\\
&=argmax(\sum_{(x_i,y_i)\in C_1} -\frac{1}{2}\log|\Sigma|-\frac{1}{2}(x_i-\mu_1)^T(\Sigma)^{-1}(x_i-\mu_1)\ +\\
&\sum_{(x_i,y_i)\in C_2} -\frac{1}{2}|\Sigma|-\frac{1}{2}(x_i-\mu_2)^T(\Sigma)^{-1}(x_i-\mu_2))
\end{aligned}
$$
Note the shape of $(x_i-\mu)^T(\Sigma)^{-1}(x_i-\mu)$ : $(1,p)* (p,p) * (p,1)=(1,1)$, therefore, the trace(tr) operation can be applied to it, and it can be regarded as a matrix. Within the trace, the order of matrices can be exchanged at will.
$$
\begin{aligned}
\hat{\theta}
&=argmax(-\frac{N}{2}\log|\Sigma|-\frac{1}{2}tr(\sum_{(x_i,y_i)\in C_1}(x_i-\mu_1)^T(\Sigma)^{-1}(x_i-\mu_1))\\
&-\frac{1}{2}tr(\sum_{(x_i,y_i)\in C_2}(x_i-\mu_2)^T(\Sigma)^{-1}(x_i-\mu_2)))\\
&=argmax(-\frac{N}{2}\log|\Sigma|-\frac{1}{2}tr(\sum_{(x_i,y_i)\in C_1}(x_i-\mu_1)^T(x_i-\mu_1)(\Sigma)^{-1})\\
&-\frac{1}{2}tr(\sum_{(x_i,y_i)\in C_2}(x_i-\mu_2)^T(x_i-\mu_2)(\Sigma)^{-1}))\\
&=argmax(-\frac{N}{2}\log|\Sigma|-\frac{1}{2}tr(N_1 S_1(\Sigma)^{-1})
-\frac{1}{2}tr(N_2 S_2(\Sigma)^{-1}))\\
\end{aligned}
$$
In the formula, $S$ denote the co-variance matrix.\\
differentiate the formula:
$$
\frac{\partial \Delta}{\partial \Sigma}=-\frac{1}{2}(N \frac{1}{|\Sigma|}|\Sigma|(\Sigma)^{-1}-N_1S_1(\Sigma)^{-2}-N_2S_2(\Sigma)^{-2})=0
$$
then we obtain the $\hat{\Sigma}$:
$$
N \Sigma^{-1}-N_{1} S_{1}^{T} \Sigma^{-2}-N_{2} S_{2}^{T} \Sigma^{-2}=0\\
\Longrightarrow \hat{\Sigma}=\frac{N_{1} S_{1}+N_{2} S_{2}}{N}
$$
Finally, when we are to predict any samples, we just need to compare $p(x|y=0)p(y=0)$ and $p(x|y=1)p(y=1)$.
\subsection{Implement}
\begin{lstlisting}[language={python}]
import numpy as np
import os
os.chdir("../")
from models.linear_models import GDA

n1 = 1000
n_test = 100
x = np.linspace(0, 10, n1 + n_test)
w1, w2 = 0.3, 0.5
b1, b2 = 0.1, 0.2
x1 = x[:n1]
x_test = x[n1:]
v1 = x1 * w1 + b1
v2 = x1 * w2 + b2
cla_1 = np.c_[x1, v1]
cla_2 = np.c_[x1, v2]
l1 = np.ones(shape=(cla_1.shape[0], 1))
l2 = np.zeros(shape=(cla_2.shape[0], 1))
train_data = np.r_[cla_1, cla_2]
train_label = np.r_[l1, l2]

v_test = x_test * w2 + b2
data_test = np.c_[x_test, v_test]

model = GDA()
model.fit(train_data, train_label)
print(model.get_params())
print("accuary:", model.evaluate(data_test, 0))
\end{lstlisting}
\end{document}


\documentclass[../PHYS306Notes.tex]{subfiles}

\begin{document}
\section{Lecture 27}
\subsection{Lecture Notes - Scattering Theory}
\subsubsection{Motivation}
Scattering Theory is very useful for probing information on atomic scales, in condensed matter/nuclear/atomic physics. A familiar example is Rutherford scattering:
\begin{center}
    \includegraphics[scale=0.5]{Lecture-27/l27-img1.png}
    \includegraphics[scale=0.5]{Lecture-27/l27-img2.png}
\end{center}
Where $\alpha$ particles (Helium nuclei) were scattered off of gold atoms, and large deflections were observed.

\subsubsection{Fundamental parameters}
There are a couple quantities that are of relevance to consider. First, we have the impact parameter $b$, which is the perpendicular distance from the incoming trajectory to the parallel axis through the center of the target. Then, we have the scattering angle $\theta$, which is the angle between the initial and final velocities. The simplest possible interaction is the hard-sphere interaction:
\begin{center}
    \includegraphics[scale=0.8]{Lecture-27/l27-img3.png}
\end{center}
Now, lets consider a beam of area $A$ passing through a target of length $L$ and number density of particles $n$. Assume the target is larger in the cross sectional area than in the beam. What is the total number of target particles in the beam?
\begin{center}
    \includegraphics[scale=0.7]{Lecture-27/l27-img4.png}
\end{center}
\begin{s}
Since $n$ gives the volume number density, we have that $AL$ gives the volume of the beam in the target and hence the total number of target particles is given by $nAL$.
\end{s}
Next, the \textbf{cross-section} $\sigma$ is defined as the effective area of target for interacting with the particle. For hard spheres of radius $R$, we have that $\sigma = \pi R^2$ (the cross-sectional area of a circle).
\begin{center}
    \includegraphics[scale=0.8]{Lecture-27/l27-img5.png}
\end{center}
Now, given this cross section $\sigma$ of a single target particle, what is the probability that any one projectile makes a hit (assume the same scenario above with the beam of area $A$, the target of length $L$?)
\begin{s}
By dimensional analysis, since probability is dimensionless, since $n$ has units of inverse volume, then $L$ has units of length and $\sigma$ has units of area and hence this works out. This makes sense as the probability should scale with the cross-sectional area of a target particle, the length of the target, and the number density of the target. A way to see that the area $A$ of the beam drops out to see is that:
\[P(\text{hit}) = \frac{\text{Area of all targets}}{A} = \frac{n\sigma A L}{A} = n\sigma L\]
\end{s}
Given the beam has an incident rate $R_{inc}$ of incoming particles per unit time, what is the scattered rate (number of scattered particles per unit time?)
\begin{s}
The rate would just be $R_{inc}\sigma n L$, just multiply the scattering probability by the incoming rate.
\end{s}

\subsubsection{Example: Scattering Neutrons on Aluminum Foil}
Take $N_{\text{inc}} = 10000$. the alumnimum foil has thickness of $0.1\text{mm}$. For neutrons, we have that $\sigma = 1.5 \cdot 10^{-28}\text{m}^2$. Since this is such a common unit in nuclear physics, this is often denoted with a new unit, the \textit{barn} ($1 \text{barn} = 1\times 10^{-28}\text{m}^2$; i.e. $\sigma = 1.5\text{barns}$. For alumnimum, we have mass density $\rho_{Al} = 2.7\times 10^3 \text{kg/m}^3$ and we know that $m_{Al} = 27u$. Hence, the scattered number of particles is given by:
\[N_{\text{scatter}} = N_{\text{inc}}\frac{\rho_{\text{Al}}}{m_{Al}}L\sigma = 9\]

\subsubsection{Example: Scattering of Two Hard Spheres}
In this case, we have effective scattering area of $\pi(R_1 + R_2)^2$.
\begin{center}
    \includegraphics[scale=0.7]{Lecture-27/l27-img6.png}
\end{center}

\subsubsection{Example: Mean free path of air molecule}
Air molecules can be approximated as hard spheres with $R = 0.15\text{nm}$. Define the quantity \textbf{mean free path} $\lambda$ as the average distance between two collisions. For sigma, we take (from the formula above):
\[\sigma = \pi(2R)^2 = 4\pi R^2\]
We have number density:
\[n = \frac{N}{V}\]
The probability of a collision when travelling a distance $dx$ is given by:
\[P(\text{coll in dx}) = n\sigma dx\]
Hence the probability of having a first collision in $x$ and $x + dx$ as:
\[P(\text{first coll between in x and x + dx}) = P(\text{no coll in x})\cdot n \sigma dx\]
We can write this in another way as:
\[P(\text{first coll between in x and x + dx}) = P(\text{no coll in x}) - P(\text{no coll in x + dx})\]
Turning this small $dx$ into a differential, we have:
\[P(\text{first coll between in x and x + dx}) = -\dod{}{x}P(\text{no coll in x})\]
We call $P(\text{no coll in x})$ as $P(x)$ for notations. Setting the two expressions equal to each other, we have:
\[\dod{}{x}P(x) = -\frac{N\sigma}{V}P(x)\]
This has solution:
\[P(x) = \exp(-\frac{N\sigma}{V}x)\]
Then the mean free path can be calculated as the average value of x given this probaility distribution:
\[\lambda = \avg{x} = \int_{0}^{\infty}xP(x)dx = \int_0^\infty xn\sigma \exp(-\frac{N\sigma}{V}x)\]
Note that the $n\sigma$ is there as a normalization factor for the distribution. Taking this integral, we have:
\[\lambda = \frac{1}{n\sigma}\]
This makes sense intuitively; the larger the cross section and the larger the number density, the smaller the mean free path between collisions. Dimensionally, this also has units of length, which is good! At STP, we can calculate what this would be numerically:
\[\lambda = \frac{V_a}{N_a(4\pi R^2)} \approx 130\text{nm}\]

\subsubsection{Solid Angle}
\begin{center}
    \includegraphics[scale=0.5]{Lecture-27/l27-img7.png}
\end{center}
We are familiar with the normal angle, $\Delta \theta = \frac{s}{r}$, the ratio of the arc length to the radius. Generalizing this to 3D, we have the solid angle, $\Delta \Omega = \frac{A}{r^2}$ where $A$ is the "arc area" and $r$ the radius. For a cone with polar angles $\theta, \theta + d\theta$, $\phi, \phi + d\phi$. The expression is therefore given by:
\[d\Omega = \sin\theta d\theta d\phi\]
What is the integral of the solid angle increment $d\Omega$ over all possible solid angles (over the surface of a sphere?)
\begin{s}
$\int d\Omega = 4\pi$ (surface area of unit sphere). We could actually do the integral, or we could just recognize that the surface area of a sphere is given as $4\pi r^2$ and divide this by $r^2$.
\end{s}

\subsubsection{Differential Cross Section}
Typical scenario is we have that a detector covers some portion of a sphere around our target.
\begin{center}
    \includegraphics[scale=0.8]{Lecture-27/l27-img8.png}
\end{center}
We must have that:
\[N_{\text{scatter}}(\text{into d$\Omega$}) = N_{inc}n_{target}d\sigma(\text{into d$\Omega$}) = N_{inc}n_{target}\left(\dod{\sigma}{\Omega}(\theta, \phi)\right)d\Omega\]
The term $\od{\sigma}{\Omega}(\theta, \phi)$ is the differential cross section. This can be measured in experiment, or predicted in theory. We can also obtain the total cross section, which is the integral over all differnetial cross sections.
\[\sigma_{tot} = \int \dod{\sigma}{\Omega}(\theta, \phi) d\Omega = \int_0^\pi \sin\theta d\theta \int
_0^{2\pi}d\phi\dod{\sigma}{\Omega}\]
For a beam with area $A$ and total number of particles $N$, what is the total number of particles $dN$ that passes through the segment between $b$ and $b + db$ and $\phi$ and $\phi + d\phi$?
\begin{center}
    \includegraphics[scale=0.7]{Lecture-27/l27-img9.png}
\end{center}
\begin{s}
We know that the area of the segment is given by $b dbd\phi$, and then dividing this by the total area $A$ we get the fraction of particles that would hit that area. Hence, $dN = \frac{N}{A}bdbd\phi$.
\end{s}
Note that for the case with axial symmetry, we have:
\begin{center}
    \includegraphics[scale=0.7]{Lecture-27/l27-img10.png}
\end{center}
But we will continue this discussion next day.
\end{document}


\chapter{Viscoelastic Predictions}
%The ultrasound method \cite{Foiret2014} enables the simultaneous measurement of cortical thickness and tissue elastic properties where previous techniques such as DXA (the \textit{de facto} method) could archieve.
As explained before, factors of risk fracture such as thickness, porosity and particular quality elements of the extracellular matrix, define the bone quality assessed by DXA techniques and BMD values. The QUS method proposed by \textit{Minonzio and Foiret et al.} \cite{Foiret2014}, \cite{Minonzio2018} of axial transmission technique simulated in the chapter before, is based on recording from the guided-wave propagation over the media, where damping factors naturally affect the signal. This relates to a viscoelastic behavior of the cortical bone arising mainly from the presence of collagen fibers, specifically treated with Resonant Ultrasound Spectroscopy (RUS) techniques. Thus, it becomes natural to study the correspondence between such damping elements and their preponderance on the resulting homogenized coefficients by the two-scale homogenization theory.

Describing the damping effects on cortical bone is not new, \textit{Bernard} \textit{et al. }\cite{Bernard2015} studied a viscoelastic-type behavior on a frequency domain, in which he modelled the elastic tensor $C^*_{ij}$ with damping effect described by the formulas:
\begin{equation*}
C^*_{ij} = C_{ij} + i C_{ij}^{'} = C_{ij} (1+ iQ_{ij}^{-1}) \quad i,j = 1,\dots, 6
\end{equation*}
where the $Q^{-1}_{ij}$ are defined as ratios of the imaginary part ($C_{ij}'$) to the real part ($C_{ij}$), denoting the so-called quality factors.

In this section, I shall reformulate such quality factors following the two-scale homogenization formalism, recovering the homogenized coefficients in the elastic case at different porosity levels and particularly obtaining prediction for the quality factors at some interval. Using up-to-date references, such coefficients are yet to be validated since there isn't enough experimental literature to confirm nor further validate the predictions.

\section{Formalization of Q-factors}
The quality factors $Q_{ij}$ proposed by \textit{Bernard} in experimental fashion, provide an interesting formalization of the ratio between the real and imaginary constitutive coefficients of a full viscoelastic mechanical description of the bone, moreover it gives us a comparison using the existent literature and experimental results.

In the following, it is described the so-called Q-factors by means of the two-scale homogenization theory, derived from a \textit{Kelvin-Voigt} viscoelastic formulation of bone in frequency domain. More specifically, the mechanical behavior of bone is assumed as a multiphase viscoelastic material composed of two-phases, defined by a square cell unit on $\mathbf{R}^2$ with circular inclusion in the form $\mathbf{Y} = \mathbf{Y}_{m} \cup \mathbf{Y}_{f}$ being each the matrix and fluid parts respectively.
For the bone matrix, we associate an elastic behavior defined by the elastic coefficients:
\begin{equation*}
    C_{ijkl}(\mathbf{y}) = C_{ijkl}^m \mathbb{I}_{\mathbf{Y}_m}(\mathbf{y}) + C_{ijkl}^f \mathbb{I}_{\mathbf{Y}_f}(\mathbf{y})
\end{equation*}
while the porosity is modeled with a viscous contribution, associated to coefficients in the form:
\begin{equation*}
    D_{ijkl}(\mathbf{y}) =  D_{ijkl}^m \mathbb{I}_{\mathbf{Y}_m}(\mathbf{y}) + D_{ijkl}^f \mathbb{I}_{\mathbf{Y}_f}(\mathbf{y}).
\end{equation*}
Moreover, the relations between both behaviors are expressed with attenuation specified by parameters $\alpha^{(m)}, \alpha^{(f)} >0$ associated to the bone matrix and mesostructure respectively. Explicitly, it is assumed:
\begin{equation*}
    D_{ijkl}^m(\mathbf{y}) = \alpha^{m} C_{ijkl}^m(\mathbf{y}) , \quad D_{ijkl}^f (\mathbf{y}) = \alpha^{f} C_{ijkl}^f(\mathbf{y})
\end{equation*}

\begin{rem}
By assuming this kind of relation, the objective is to obtain a viscoelastic model in which the viscous part is modelled by a linear attenuation of the elastic one, so that the overall behavior is of transverse isotropic type defined by pair of parameters $(\alpha^m, \alpha^f)$ that mimic closely the experimental behavior of cortical bone.
\end{rem}

\subsection{Workflow Description}
Given the requirements of a viscous-like behavior, in time domain is considered a model of \textit{Kelvin-Voigt} type with mixed boundary conditions, described in the form:
\begin{equation*}
    \left \{
    \begin{array}{cc}
        \rho^{\epsilon}\partial_{tt}u^{\epsilon} - \nabla \cdot \sigma(u^{\epsilon}, \partial_t u^{\epsilon}) = \mathbf{0} & \text{ in } (0,T) \times \Omega\\
        \sigma^{\epsilon}(u^{\epsilon},\partial_t u^{\epsilon})  = \mathbf{C}:\mathbf{e}(u^{\epsilon}) + \mathbf{D}:\mathbf{e}(\partial_t u^{\epsilon}) & \text{ in } (0,T) \times \Omega\\
        \sigma^{\epsilon}(u^{\epsilon}, \partial_t u^{\epsilon})\cdot n = \mathbf{F} & \text{ on } (0,T) \times \Gamma_N\\
        u^{\epsilon} = \mathbf{0} & \text{ on } (0,T) \times \Gamma_D
    \end{array}
    \right .
    \label{ViscoElasticModel}
\end{equation*}
\begin{rem}
In the above and the next developments, we assume resting initial conditions, i.e., $\partial_t u^{\epsilon} = u^{\epsilon} = \mathbf{0}$ at $t = 0$, not written explicitly in the models and further deductions.
\end{rem}
Existence results can be derived similarly to the elastic case proposed before, by applying spectral decomposition on both: the elastic and viscoelastic operators. Similar mathematical description of viscous models are given by \cite{Abdessamad2009}, \cite{Boughammoura2013} on homogeneous \textit{Dirichlet} boundary condition cases.

The interest is regarded to the frequency-domain, thus applying \textit{Fourier} transform defined at frequency $\omega \in \mathbb{R}$ by assuming $u^{\epsilon}(t,\mathbf{x}) = \hat{u}^{\epsilon}(\mathbf{x}) e^{i\omega t}$ it follows the redefined problem in Fourier domain:
\begin{equation*}
    \left \{
    \begin{array}{cc}
        -\omega^2 \rho^{\epsilon} \hat{u}^{\epsilon} - \nabla \cdot \hat{\sigma}_{\epsilon,\omega}(\hat{u}^{\epsilon}) = \mathbf{0} & \text{ in } \Omega  \\
        \hat{\sigma}^{\epsilon} (\hat{u}^{\epsilon}) = (\mathbf{C} + i\omega \mathbf{D}):\mathbf{e}(\hat{u}^{\epsilon}) & \text{ in } \Omega \\
        \hat{\sigma}^{\epsilon} (\hat{u}^{\epsilon}) \cdot n = \hat{\mathbf{F}}(\omega) & \text{ on } \Gamma_N \\
        \hat{u}^{\epsilon} = \mathbf{0} & \text{ on } \Gamma_D
    \end{array}
    \right .
\end{equation*}
such that at $\omega = 0$ we have $\hat{u}^{\epsilon}=\mathbf{0}$ at $\Omega$. In particular, for easiness of exposure, it has been omitted dependencies on the frequency for the multiscale solution $u^{\epsilon}$.\\
Now, by the homogenization heuristic using the two-scale asymptotic method, it follows the effective (macroscopic) model defined at frequency $\omega$ in the form:
\begin{equation*}
    \left \{
    \begin{array}{cc}
        -\omega^2 \rho^{0} \hat{u}^0 - \nabla \cdot \hat{\sigma}^0(\hat{u}^0)  = \mathbf{0} & \text{ in } \Omega \\
        \hat{\sigma}^{0} (\hat{u}^0)  = (\mathbf{C} + i\omega \mathbf{D})^{hom}:\mathbf{e}(\hat{u}^0) & \text{ in } \Omega \\
        \hat{\sigma}^{0} (\hat{u}^0) \cdot n = \hat{\mathbf{F}}(\omega) & \text{ on } \Gamma_N \\
        \hat{u}^0 = \mathbf{0} & \text{ on } \Gamma_D
    \end{array}
    \right .
\end{equation*}

In particular, the homogenized coefficients are defined by the cell problem solutions $\mathbf{N}^{rs} \in \mathbf{H}^1_{0}(\mathbf{Y}, \mathbb{C})$, described for each $r,s \in \{1,2,3\}$ in the form
\begin{equation*}
    \left \{
    \begin{array}{cc}
         \partial_{y_j} \big[ \big( C_{ijkl} + i\omega D_{ijkl} \big) \mathbf{e}_{kl}(\mathbf{N}^{rs}) \big] &= - \partial_{y_j} \big[ C_{ijkl} + i\omega D_{ijkl} \big] \quad \forall y \in \mathbf{Y} \\
        \big \langle \mathbf{N}^{rs} \big \rangle_{\mathbf{Y}}  = \mathbf{0} &
    \end{array}
    \right.
\end{equation*}
Since the cell problems must be valid for each $\omega \in \mathbb{R}$ and for each $\mathbf{y} \in \mathbf{Y}$, a natural procedure would be to decouple the cell PDE problems thus being able the define viscosity-elasticity ratios, i.e. an expression to the so-called Q-factors.

The decoupling is then defined by considering the separation between real and imaginary parts associated to the cell solutions, i.e., by considering the following decomposition
\begin{equation*}
    \mathbf{N}^{rs}(\mathbf{y}) = \mathbf{N}_R^{rs}(\mathbf{y}) + i\mathbf{N}_I^{rs}(\mathbf{y})
\end{equation*}
being now the vectors functions $\mathbf{N}_R^{rs}, \mathbf{N}_I^{rs}$ in $\mathbf{H}^1_{0}(\mathbf{Y},\mathbb{R})$ solving the following PDE coupled system for each real and imaginary solution parts in the form:
\begin{equation*}
    \left \{
    \begin{array}{cc}
        \partial_{y_j} \big[ C_{ijkl} \mathbf{e}_{kl}(\mathbf{N}^{rs}_R) -\omega D_{ijkl} \mathbf{e}_{kl}(\mathbf{N}^{rs}_I) \big] = - \partial_{y_j} \big[ C_{ijrs} \big] & \forall \mathbf{y} \in \mathbf{Y} \\
        \partial_{y_j} \big[ C_{ijkl} \mathbf{e}_{kl}(\mathbf{N}^{rs}_I) +\omega D_{ijkl} \mathbf{e}_{kl}(\mathbf{N}^{rs}_R) \big] = - \partial_{y_j} \big[ \omega D_{ijrs} \big] & \forall \mathbf{y} \in \mathbf{Y} \\
        \big \langle \mathbf{N}^{rs}_R \big \rangle_{\mathbf{Y}}= \mathbf{0} \quad \big \langle \mathbf{N}^{rs}_I \big \rangle_{\mathbf{Y}} = \mathbf{0}.  &
    \end{array}
    \right.
\end{equation*}
\begin{rem}
Note that for the above cell problems, the existence and uniqueness of a weak solution is guaranteed since the problem can be rewritten as a fully elliptic operator, being the solution unique by applying a normalization condition of mean equal $\mathbf{0}$ type.
\end{rem}
With the solution to the cell problem, we can then define the homogenized coefficients associated to the elastic and viscous part by recalling first:
\begin{equation*}
    \hat{\sigma}_{ij}^0 (\hat{u}^0,\omega) = R_{ijkl}^{hom} (\omega) \mathbf{e}_{kl}(\hat{u}^0)
\end{equation*}
being the homogenized tensor
\begin{equation*}
    R^{hom}_{ijrs}= \big \langle  C_{ijrs} + i\omega D_{ijrs} + \big( C_{ijkl} + i \omega D_{ijkl} \mathbf{e}_{kl}(\mathbf{N}^{rs}) \big) \big \rangle
\end{equation*}
so that, using the decomposition of $N^{rs}$ it follows the full homogenized expression, described in (\ref{ViscoElasticDecom}) decomposed in real and imaginary parts characterizing the elastic and viscous contribution respectively.
\begin{equation}
    \begin{aligned}
        R^{hom}_{ijrs} &= \big \langle C_{ijrs} + \big( C_{ijkl}\mathbf{e}_{kl}( \mathbf{N}^{rs}_R) -\omega D_{ijkl}\mathbf{e}_{kl}(\mathbf{N}^{rs}_I) \big) \big \rangle \\
        & \, + i \big \langle \omega D_{ijrs} + \big( C_{ijkl} \mathbf{e}_{kl}(\mathbf{N}^{rs}_I) + \omega D_{ijkl}\mathbf{e}_{kl}(\mathbf{N}^{rs}_R) \big) \big \rangle \\
        & := C^{hom}_{ijrs} + \mathbf{i} \omega D^{hom}_{ijrs}
    \end{aligned}
    \label{ViscoElasticDecom}
\end{equation}

In particular, the definition of $Q_{ij}$ factors can be directly rewritten terms of a homogenized formulation, defined directly on the tensor coefficients described by (\ref{Qfactor-Def}). In particular, given the deduction done, the definition of such quality-factors becomes dependent on the frequency which derives from the multiscale \textit{Kelvin-Voigt} mechanical model assumed.
\begin{equation}
    \label{Qfactor-Def}
    Q_{ijrs}^{-1}(\omega) := \frac{D^{hom}_{ijrs}(\omega)}{ C^{hom}_{ijrs}(\omega)}
\end{equation}

\subsection{Nonlinear Decomposition}

An aspect that must be taken into account is the nonlinear effect added from the asymptotic assumption on the solution, expressed in the term $\mathbf{N}^{rs}$ at the homogenized coefficients definition that can be explicitly stated from (\ref{Qfactor-Def}).
It is possible to account for that effect by taking a decomposition on the linear part associated to the mean over the coefficient itself and the nonlinear effect produced from the solutions to the cell problems, i.e., from (\ref{Qfactor-Def}) the decomposition in their linear and nonlinear effects is obtained as:
\begin{equation}
    \label{Expansion-Qfactor}
        Q_{ijrs}^{-1} =  \frac{D_{hom}^{(0)}}{C_{hom}^{(0)}} + \frac{1}{C^{(0)}_{hom}\left( C^{(0)}_{hom} + C^{(1)}_{hom} \right)} \big[C^{(0)}_{hom} \big( D^{(0)}_{hom} + D^{(1)}_{hom}\big) - D^{(0)}_{hom}\big( C^{(0)}_{hom} + C^{(1)}_{hom} \big) \big]
\end{equation}
where the notation for the linear terms in $p \in [0,1]$ (porosity) in given by:
\begin{equation*}
    C^{(0)}_{hom} = \langle C_{ijrs} \rangle_{\mathbf{Y}} \quad  D^{(0)}_{hom} = \langle D_{ijrs} \rangle_{\mathbf{Y}}
\end{equation*}
and the nonlinear terms with respect to $p \in [0,1]$ associated to the solutions $N^{rs}$ is given by:
\begin{equation*}
    \begin{array}{cc}
        C^{(1)}_{hom} =& \langle C_{ijkl}\mathbf{e}_{kl}(N^{rs}_R) - \omega D_{ijkl}\mathbf{e}_{kl}(N^{rs}_I) \rangle_{\mathbf{Y}} \\
        D^{(1)}_{hom} =& \langle \omega^{-1} C_{ijkl}\mathbf{e}_{kl}(N^{rs}_I) + D_{ijkl}\mathbf{e}_{kl}(N^{rs}_R) \rangle_{\mathbf{Y}}
    \end{array}
\end{equation*}

\section{Predictions}

The explicit dependency on the frequency $\omega$, requires us to consider the frequency range in which the experimental setting take place. In this sense, after adjusting regards experimental data range, viscous factors with transverse isotropic behavior of the type are assumed in the form:
\begin{equation*}
    D^m_{ijkl} (\mathbf{y}) = 5\times10^{-2} C^{m}_{ijkl}(\mathbf{y}), \quad D^f_{ijkl}(\mathbf{y}) = 1 \times 10^{-3} C^{f}_{ijkl}(\mathbf{y})
\end{equation*}

Under such considerations, the figure (\ref{BernardPredictionHomCoeffs}) contains the prediction for the homogenized elastic coefficients and Q-factors associated to a fixed frequency $\omega = 0,5 \, [Mhz]$. It describes the behavior as function of density in the clinical range of interest. The main quality factors describing the axial-related behavior shows predictions comparable to up-to-date literature \cite{Bernard2015}. Moreover, homogenized elasticity coefficients are recovered with predictions regarding results obtained in fully elastic models \cite{Parnell2008}, therefore describing a generalization.
In particular, shear-like $C_{55}^{hom}, C_{66}^{hom}$ coefficients describe experimentally measured values validating the simulated model.

\begin{figure}[!h]
	\centering
	\includegraphics[width=\textwidth]{images/Qfactors/CellProb_QfactorCircular5E-2_Relations.pdf}
	\caption{Predicted behavior for the viscoelastic model. It is shown on the left figure the predicted quality factors for a \textit{Kelvin-Voigt} model; the center figure a prediction of homogenized coefficient ratios, and on the right figure some homogenized shear ratios with behavior as in \cite{Bernard2015}.}
	\label{BernardPredictionHomCoeffs}
\end{figure}

Nevertheless, figure (\ref{BernardPredictionHomCoeffs}) cannot be used to account for the nonlinearity effects which might not be preponderant on the definition of the quality factors. In this setting, the decomposition (\ref{Expansion-Qfactor}) can be used to describe characteristic behavior regarding the linear and nonlinear contribution and therefore, answering the question of dependency on preponderant linear behavior.  In this sense, figure (\ref{QfactorDecomposition}) shows a clear
direction-dependent strong non-linear preponderance on the overall behavior for the three cases, implying full cell-problem interactions to describe each factors. In particular, becoming the cell-problems the most relevant effect that describes the mechanical behavior.

\begin{figure}[!h]
	\centering
	\includegraphics[width=\textwidth]{images/Qfactors/PlotsVisc_Circular2DPart50EPS5-2_Ome5.pdf}
	\caption{The effects from cell-problem solutions is shown for some representative quality factors accounting the linear and non-linear contributions over the range of biomedical interest.}
	\label{QfactorDecomposition}
\end{figure}

Finally, a relevant dependency that must be taken into account from the Q-factors definition (\ref{Qfactor-Def}) is related to the frequency dependency. From the experimental setting proposed by \cite{Bernard2015}, such dependency is not taken into account on the viscoelastic operator nor in the quality-factor.
In this direction, figure (\ref{BernardPrediction-Freq}) describes the obtained factors for different frequency values. It shows a clear independent behavior at each frequency being used, therefore expressing the assumption proposed by \textit{Bernard et. al. (2015)} \cite{Bernard2015} in which given the frequency range under consideration, the overall behavior of the Q-factors remains the same, i.e., equal ratio of elastic and viscous part at each frequency
\begin{figure}[!h]
	\centering
	\includegraphics[width=\textwidth]{images/Qfactors/QfactorsFreqsEPS5-2.pdf}
	\caption{Predicted behavior for the viscoelastic model. It is shown in the left figure the predicted quality factors for a \textit{Kelvin-Voigt} model; the center figure a prediction of homogenized coefficient ratios, and in the right figure some homogenized shear ratios behaves as in \cite{Bernard2015} }
	\label{BernardPrediction-Freq}
\end{figure}.