\section{Tracing Periodic Solutions, Predictor-Corrector Continuation}
\label{sec:cont}

%TODO bold convention

A central part of this project are numerical continuation methods.
Being a large topic, the details are out of the scope of this work, we thus concentrate on conveying a general idea of the concepts.
This is especially true for the wealth of methods from other fields, numerical continuation draws upon.
Among the things required in the following are basic knowledge of Newton's method in multiple dimensions, forward integrating differential equations (Runge-Kutta methods) and basic vector calculus (Jacobian matrix).
For a more thorough introduction to the topic, see \cite{allgower1990numerical}, on which the continuation part of project and this section of this document is based.
The following is a reduced introduction of the concepts used for this project. %TODO too much, reformulate

The base of numerical continuation is formed by the fact that in the vicinity of a solution of an underdetermined continuous system, there are almost always other, similar solutions. %almost? always?
Iterative application of this, in the context of systems having one constraint less than unknowns, yields that solutions of the system form a curve (which might be closed).
Continuation methods provide means to trace these curves, and thus to derive infinitely many other solutions from a single given solution.
A very central use-case of such a method is being able to numerically solve a system without requiring an otherwise needed good starting value.
This works by continuously blending two systems with equal numbers of unknowns and equations using a homotopy, which adds one degree of freedom.
This way, a known solution from a trivial system can be traced to one of the harder system.
However, in the context of this work, where the underdetermination occurs naturally, we are not interested in single solutions, but rather in obtaining the whole continua of solutions.

This project uses a single continuation method: The predictor-corrector method.
As the name suggests, it continues the solution curves, by predicting the next point on the curve through linearization at the current point, and afterwards correcting it, to compensate for the non-linear influences.

\paragraph{Davidenko Equation} For a matrix $\mathbf A \in \R^{N \times (N+1)}$ with full rank, let $\tang(\mathbf A) \in \R^{N+1}$ denote its \emph{tangent}, that is the unique vector with
	\begin{gather*}
		\mathbf A \cdot \tang(\mathbf A) = 0\\
		||\tang(\mathbf A)|| = 1\\
		\det \begin{pmatrix}
			\mathbf A\\
			\tang(\mathbf A)^T
		\end{pmatrix} > 0
	\end{gather*}
For a given function $\mathbf h: \R^{N+1} \to \R^N$ for $N \in \N$, let $\mathbf J: \R^{N+1} \to \R^{N \times (N+1)}$ denote its Jacobian.
The tangent can be used to define an initial value problem specific to $\mathbf H$, the Davidenko equation (\cite{davidenko1953new}): %TODO spacing?!
	\begin{gather*}
		\frac{d}{dt}\mathbf c = \tang(\mathbf J(\mathbf c))\\
		\mathbf c(0) = \mathbf c_0 \text,
	\end{gather*}
for a given $\mathbf c_0 \in \R^{N+1}$.
Solutions $\mathbf c: \R \to \R^{N+1}$ to this problem satisfy $\mathbf h(\mathbf c(t)) = \text{const}$ for all $t \in \R$, as can be seen on
	\[
		\frac{d}{dt} \mathbf h(\mathbf c) = \mathbf J(\mathbf c) \cdot \frac{d}{dt} \mathbf c = \mathbf J(\mathbf c) \cdot \tang(\mathbf J(\mathbf c)) = 0 \text.
	\]

From a theoretical perspective, the Davidenko equation is the sole thing needed for continuation.
Tracing solutions becomes a matter of finding a solution for the differential equation.
In a practical setting, this also includes the same numerical obstacles, and ignores that the underlying functions $\mathbf h$ and $\mathbf J$ are known.
Numerically integrating the Davidenko equation is the prediction part as indicated earlier.
It introduces errors, such that the constancy is no longer guaranteed.
However, since $\mathbf h$ and $\mathbf J$ are known, the point can be \emph{corrected} towards the constant solution curve.

\paragraph{Newton's Method} The correction part of the method uses a variant of Newton's method, working in multiple dimensions and with non-square Jacobians.
Finding zeros using Newton's method in multiple dimensions works similar to the single dimensional case: A function is linearized, and the zero of the linear problem is considered a good approximation of a zero of the more complex problem.
In non-degenerate cases, iterating this procedure quickly converges to a zero, the fixed points of this iteration.

First we consider function $\mathbf h: \R^N \to \R^N$ with square Jacobian $\mathbf J: \R^N \to \R^{N \times N}$.
In point $\mathbf x_i \in \R^N$ the next point $\mathbf x_{i+1} \in \R^N$ is defined as the root of the linearization in $\mathbf x_i$, $\mathbf x \mapsto \mathbf H(\mathbf x_i) + \mathbf J(\mathbf x_i) \cdot (\mathbf x - \mathbf x_i)$, which yields
	\[
		\mathbf x_{i+1} \coloneqq \mathbf x_i - \mathbf J^{-1}(\mathbf x_i) \mathbf H(\mathbf x_i) \text.
	\]

Generalizing the method to $N \times (N+1)$ Jacobians involves finding a substitute for inverting the Jacobian, which is not defined for non-square matrices.
This can be done using \emph{Moore-Penrose} pseudoinverse for a matrix $\mathbf A \in \R^{N \times (N+1)}$
	\[
		\mathbf A^+ \coloneqq \mathbf A^*(\mathbf A \mathbf A^*)^{-1} \text.
	\]
As $\mathbf A \mathbf A^+ = (\mathbf A \mathbf A^*)(\mathbf A \mathbf A^*)^{-1} = \mathbf I$ indicates, $\mathbf A^+$ is a right-inverse, such that
	\[
		\mathbf x_{i+1} \coloneqq \mathbf x_i - \mathbf J^+(\mathbf x_i) \mathbf H(\mathbf x_i)
	\]
can be considered Newtons Method for $N\times (N+1)$ systems.
The pseudoinverse allows to solve these underdetermined systems in a least squares sense (for details see \cite{allgower1990numerical}), that is,
	\[
		\mathbf x = \mathbf A^+ \mathbf b \quad \Leftrightarrow \quad \mathbf ||\mathbf x|| = \min \{ ||\mathbf x||\ |\ \mathbf A \mathbf x = \mathbf b\} \text.
	\]
In a practical setting, one can resort to simply solving
	\[
		\mathbf J(\mathbf x_i) \mathbf x = \mathbf H(\mathbf x_i)
	\]
in this manner, instead of costly inverting the Jacobian.

\paragraph{Broyden Updates} The formulation in terms of the Moore-Penrose pseudoinverse allows to employ the \emph{Broyden} update methods.
These make it possible to avoid having to calculate the entire Jacobian and solving the possibly huge systems, at the cost of using approximations of the Jacobian.
These updates have not been employed in the implementation of the methods for this project and are out of the scope of this document.
However, it should be noted, that the vast majority of processing time in the implementation is used for calculating the tangent of the Jacobian, which is required in every predictor and corrector step.
Broyden updates allow to update the tangent as well, making them a priority goal for a possible extension of the implementation.

%implicit function theorem


\chapter{Optimal Control in Two-Dimensional Space}\label{2d}

In this project \footnote{This particular application was completed as part of a group project undertaken by the author along with Evan Lamb and Jason Newton. Parts of this section are re-purposed from the project report.}, the principles of optimal control were applied to the uDrone. In order to simplify the process, the vehicle and world were modeled as a two-dimensional system with one control input. Dynamic programming was used with a cost function that satisfies the mapping goals of the vehicle while minimizing control input. This section lays out the methods, implementation, and results of this particular application.

\section{Methods}
\subsection{Simplification \& Assumptions}
In order to reduce the complexity of this problem, the vehicle and world are modeled in two dimensions. Since the goal of the vehicle is to move in a straight line along the reef in the X-Z plane (where Z is down and X is forward), this is a reasonable assumptions. To further simplify the problem, the forward thrust is assumed to be at a constant value and the only control input is pitch rate. More assumptions were made to simplify the dynamic model, including constant forward drag, no rotational drag, no Coriolis forces, neutral buoyancy, corresponding centers of buoyancy and mass, and discrete state transitions.

\subsection{Model}
The first step of this project involved generating a model for the uDrone, defining a cost function, and determining constraints.

% \begin{figure}[t]
%     \centerline{\includegraphics[width=\linewidth]{img/drone_pool.jpg}}
%     \caption{The uDrone}
%     \label{fig:drone}
% \end{figure}
\subsubsection{State Space Equations}
In order to generate state space equations, equations of motion for an underwater vehicle were used \parencite{thor_kin}.
\begin{equation}
    X=\left[ \begin{matrix} x\\ y\\ \theta \end{matrix} \right], \;\;
    u=\left[ \dot \theta \right]\label{eq:sspace}
\end{equation}
The set of equations \ref{eq:sspace} describe the state space, where $X$ is the state vector and $u$ is the control vector. $x$ is the horizontal position, $y$ is the vertical position, $\theta$ is the pitch, and $\dot \theta$ is the pitch rate of the vehicle.
\begin{align}
    \begin{split}
        \dot x&=\nu \cos \left( \theta \right) \\
        \dot y&=\nu \sin \left( \theta \right) \\
        \dot \theta&=u
    \end{split} \label{eq:state}
\end{align}
The set of equations \ref{eq:state} are the state space equation where $\dot x, \dot y,$ and $\dot \theta$ are the derivatives of $x, y,$ and $ \theta$ respectively and $v$ is the constant forward velocity.
\begin{align}
    \begin{split}
        x_{k+1}&=v\cos \theta _{k+1}\ast \Delta t+x_{k} \\
        y_{k+1}&=v\sin \theta _{k+1}\ast \Delta t+y_{k} \\
        \theta _{k+1}&= \dot \theta _{k}\ast \Delta t+\theta _{k}
    \end{split}\label{eq:disc}
\end{align}
The set of equations \ref{eq:disc} are the discretized state transition equations to go from time-step $k$ to time-step $k+1$. $\Delta t$ is the length of the time-step. This equation is derived from the state space equations \ref{eq:state}.

\subsubsection{Cost Function}
\begin{align}
    \begin{split}
        J&=\int _{t_{0}}^{t_{f}}\left\| f\left( x\left( \tau \right) \right) -y\left( \tau \right) \right\| ^{2} + \left\| g\left( u\left( \tau \right) \right) \right\| _{R}^{2}d\tau \\
        f\left( x\left( t \right) \right) &\overset{\Delta}{=} \text{desired } y \text{ at given } x\left( t \right)\\
        g\left( u\left( t \right) \right) &\overset{\Delta}{=} \text{motor control cost}\\
    \end{split}\label{eq:cost}
\end{align}
The cost function shown in equation \ref{eq:cost} is a combination of two costs. First, there is the tracking cost which is defined as a vertical deviation from a desired path at any given x value. Its weight is fixed at $Q = 1$. Second, there is the control cost which is defined as the required power output by the uDrone's motors to attain a specific pitch rate. Its weight is varied through three $R$ values: 0.01, 0.05, and 0.1. The function $f \left ( \cdot \right )$ is defined by the desired trajectory. The cost of the motor control is based on the parameters of the motors used in the uDrone \parencite{t200}. The continuous cost function shown above was discretized according to the temporal time step prior to simulation in MATLAB.

\subsubsection{Constraints}
\begin{align}
    \begin{split}
        0\leq & x \leq 10\\
        0\leq & y\leq 4\\
        \frac {-11\pi } {24}\leq & \theta\leq\frac {11\pi } {24}\\
        -70 \leq & \ddot \theta\leq 70
    \end{split}\label{eq:con}
\end{align}
The set of equations \ref{eq:con} show the constraints for the system. The constraints around $x$ and $y$ are based on the problem definition. The constraint on $\theta$ is in place to ensure forward movement of the uDrone and prevent circular references. The constraint on $\ddot \theta$ is based on the motor parameters and model of the uDrone \parencite{t200}. This value is multiplied by $\Delta t$ to determine the constraint on $u$. The constraints were discretized prior to simulation in MATLAB.
\subsection{Dynamic Programming}
To generate an optimal control policy, dynamic programming is used in MATLAB, using the methodology from \parencite{kirk2012optimal}. First, the program initializes all variables and the U*, J* matrices. Using the defined cost function, the cost (J) is computed for each of the final states (i.e. states having $(x=10)$). The code then takes a step backwards in x according to its spatial discretization. The program then computes the "tracking cost" for each state. A higher cost is implemented for going too far beneath the desired path--this is abstracted as hitting the reef. Next, the code checks each of the 15 permissible control inputs at the states and determines 1) what the next state will be based on the state equations, 2) the "control cost" for that control input based on the motor parameters, and 3) the total cost (J) for that choice by adding control cost and tracking cost. Comparing the costs for each of these states, the program chooses the state-action pair with the minimum cost and denotes it as the optimal control. This action is populated into the optimal control (U*) table. The cost associated with this action is populated in the optimal cost (J*) table. This process repeats until it has worked backwards to the initial state $(x=0)$. For each state along $x$, the values for $y, \theta, $ and $u$ are discretized as well.

In a traditional dynamic programming example, the program will use interpolation to determine the J* and U* values at a given state when the state values fall in between the discretized values. Given its high computational cost, interpolation was replaced with a nearest neighbor approach. In this approach, the state being evaluated is simply assigned the J* value of the state which is nearest. Given that we have a 3D grid, this can be likened to landing inside a box with eight corners. These corners represent points at which no interpolation is necessary. Instead of determining the state's exact J*, the program just accepts the J* of the nearest corner and assigns it to the state.

\section{Implementation \& Simulation}
This section details the specifics of the trials and simulations. Initial trials were conducted at courser discretization resolutions. The trails were made iterative finer until the step size described below was reached.

\subsection{Path}

The path set for the uDrone to follow is based on a piece-wise function shown in equation \ref{eq:pw} and show in figure \ref{fig:path}.

\begin{equation}
y =
    \begin{cases}
      1 & 0 \leq x < 1 \\
      2-\cos \left( \frac {\pi \left( x-1\right) } {4}\right)  & 1\leq x < 9 \\
      1 & 9 \leq x \leq 10
  \end{cases}\label{eq:pw}
\end{equation}

Additionally, in order to model hitting the reef, any location more than one meter below the curve was given a very high cost.

\begin{figure}[ht]
    \centerline{\includegraphics[width=\linewidth]{img/path.png}}
    \caption[Desired uDrone 2D path]{Desired uDrone path in defined state space}
    \label{fig:path}
\end{figure}

\subsection{Cost Function Parameters}

The cost function was determined directly from the motor parameters for the uDrone \parencite{t200}. Specifically, the force needed to pitch the vehicle was used to determine the angular velocity. The power necessary to create this force value is the control cost. Two methods were used for determining the cost, which are called "True" and "Zeroed" in this paper. The true method uses the exact motor values, including the constant force to move the vehicle forward. Therefore, this method takes into account drag. The zeroed approach normalizes the control cost to zero when there is no control input. This method will minimize control action, but not necessarily penalize the vehicle for following a path more closely if it also causes the vehicles to have a lower velocity in the X direction. The control cost curves can be seen in figure \ref{fig:cost}.

\begin{figure}[ht]
    \centerline{\includegraphics[width=\linewidth]{img/cost.png}}
    \caption[Control Cost]{Control cost for true (blue) and zeroed (orange) methods}
    \label{fig:cost}
\end{figure}

The ratio between control cost and tracking cost weight ($R$) was tested at three values, 0.01, 0.05, and 0.1. Since the values for control cost are in the double digit order of magnitudes and the value for tracking cost are in the single digit order of magnitudes, an $R$ value of 0.1 will treat the two costs as roughly equal. An $R$ value of 0.01 will make the tracking cost 10 times more important than control cost.

\subsection{Discretization}
When discretizing, first a coarse trial was run at 10 Hz. After this was successful, more fine trials were run, up to 20 Hz. This timestep drove the step size for other variables via the constraint on moving forward in equation \ref{eq:dx}.
\begin{equation}
    \Delta x \leq v \cos \theta _{max} * \Delta t
    \label{eq:dx}
\end{equation}
Additionally, from the timestep the limits on control input are established, as seen in equation \ref{eq:control}.
\begin{equation}
\begin{split}
    \dot \theta = \Delta t * \ddot \theta\\
    -3.5 \leq \dot \theta\leq 3.5
\end{split}\label{eq:control}
\end{equation}
This, along with a desire to maintain fine discretization for grater accuracy, led to the final decision for discrete steps, as shown in table
\begin{center}
 \begin{tabular}{||c c c||}
 \hline
 Value & Step Size & Step Count \\ [0.5ex]
 \hline\hline
 x & 0.005 m & 2001 \\
 \hline
 y & 0.01 m & 401 \\
 \hline
 $\theta$ & $\frac{\pi}{24}$ rad & 23 \\
 \hline
 U & 0.05 $\frac{rad}{s}$ & 15\\
 \hline
\end{tabular}
\end{center}

\begin{figure}[t]
\centering
\subfigure{\includegraphics[width=0.32\linewidth]{img/R0_01_true.png}}
\subfigure{\includegraphics[width=0.32\linewidth]{img/R0_05_true.png}}
\subfigure{\includegraphics[width=0.32\linewidth]{img/R0_1_true.png}}
\caption[Optimal path using true cost]{Optimal path using true cost method for various R values (Left) R = 0.01 (Center) R = 0.05 (Right) R = 0.1}
\label{fig:true}
\end{figure}

\begin{figure}[t]
\centering
\subfigure{\includegraphics[width=0.32\linewidth]{img/R0_01_zero.png}}
\subfigure{\includegraphics[width=0.32\linewidth]{img/R0_05_zero.png}}
\subfigure{\includegraphics[width=0.32\linewidth]{img/R0_1_zero.png}}
\caption[Optimal path using zero cost]{Optimal path using zero cost method for various R values (Left) R = 0.01 (Center) R = 0.05 (Right) R = 0.1}
\label{fig:zero}
\end{figure}
\section{Results}
Six total trials were run, each with a different cost function method and $R$ value. In each trial 3D optimal cost and optimal control tables are generated. Based on the size of discretization, each table had over 18 million entries and the full trial took approximately 5 hours to complete. Using this data, two graphs are generated: the optimal path and the optimal control law.
\subsection{Optimal Path}
The first graph demonstrates the optimal path of a vehicle at a given starting point. This is useful for visualizing the vehicle motion and how much it follows the path, as shown in figures \ref{fig:true} and \ref{fig:zero}. There are several conclusions that can be drawn from these figures: 1) As the $R$ value increases, the vehicle deviates from the path more. This can be seen by comparing the graphs in figures \ref{fig:true} and \ref{fig:zero}, where the $R$ value increases from left to right. This makes sense as a lower $R$ value increases the weight of the path following relative to the control cost. 2) The true cost method causes the vehicle to deviate from the path more than the zeroed method. The true cost method also maintains the vehicle at a more horizontal orientation, thus increasing the component velocity in the X direction. This is shown by comparing figure \ref{fig:true} to figure \ref{fig:zero}. The result of the cost method comparison is intuitive since the cost to move forward will cause the optimal path to take the vehicle through the simulation in the least number of steps.

\subsection{Control Law}
The second graph is a visualization of the control law computed by the run. A control law is a table containing the optimal control choice at each state. This table would be loaded on to a vehicle and used to determine control, as running any dynamic programming problem in real time would be to computationally intensive and slow. Since it is not practical to display the full three-dimensional graph in this format, a slice is presented here. Figure \ref{fig:Ustar} shows a single slice of the control law. Specifically, this figure shows the control law for a given $x$ and $y$ when $\theta$ is equal to zero. In this figure the red color represents areas of positive (counterclockwise) optimal control, the blue color areas of negative (clockwise) optimal control, and the white areas of zero optimal control.

\begin{figure}[h]
    \centerline{\includegraphics[width=0.5\linewidth]{img/U_star.png}}
    \caption{Optimal Control Law}
    \label{fig:Ustar}
\end{figure}

Clearly visible in the figure is the dark red lower parabola which is the very high cost area of hitting the reef that the control law tries to avoid. The lighter red areas are where the vehicle is behind or below the path and needs to pitch up to get on track. The light and dark blue areas are where the vehicle is above or in front of the path and needs to pitch down. The white band is when the vehicle is directly next to the path and should move straight in the body fixed axes.

% Two main methods of analysis were used - one with zeroed costs and one with the true cost. The true cost accounts for the cost associated with the constant movement of the drone. Since the the drone is always moving at a constant forward speed the true cost method penalized every movement step, so the optimal policy was in part searching for the shortest path. Zeroed cost was also helpful since the only considered input was the pitch rate, so it may be reasonable to ignore the cost of basic forward movements. Both were analyzed for varying values of R. There resulting optimal paths are shown in figure \ref{fig:zero} and in figure \ref{fig:true}. As can be seen, the analysis done with true cost cuts through the set path because there is a cost associated with travel distance. It is therefore optimal to make the trip in the shortest distance possible.

% In addition to plotting the optimal paths a plot showing the optimal control law is shown for each position $X$ and $Y$. where $theta$ is equal to $0$. The map is show in figure \ref{fig:Ustar}. The blue are represents a negative input while red represents a positive input. Note that this specific map is for the case with R = 0.01 and zeroed cost.

\section{Conclusions}
%The key conclusion is that a zeroed cost permits greater path following capacity. This is expected because there is no cost for a control input of 0. In other words, motion is not penalized as heavily in the zeroed cost case as in the true cost case. It is clear in the true cost case that the uDrone simply attempts to exit the grid as quickly as possible without hitting the reef even when $R$ is lowered. When considering the various $R$ values, the results are also as expected. The lower the R value, the greater the permissible control input which manifests itself in the results as greater path following. This is true in the zeroed and true cost cases, but is more evident in the latter case.

This project showed that dynamic programming is a valid method for creating an optimal control law for an underwater vehicle. Since this vehicle's mission is to travel in a straight plane, the simplifications from three to two dimensions would still allow for a usable control law. Additionally, the project showed the effects of the cost function on the optimal control policy. By varying the control cost calculation method (true versus zeroed) and changing the control weights (path following vs. control cost) the optimal trajectory changes. These trade offs need to be weighted based on the specific needs of the vehicle's mission. For example, if mapping fidelity and accuracy is paramount, a low $R$ value and zeroed cost would be best. But, if coverage is more important, a higher $R$ value and the true cost method are best.

The largest barrier to practical implementation is the compute time and static environment needed for dynamic programming. The compute time issue can be overcome by pre-computing a control law, such as mentioned above. Dynamic programming is useful when the path is known in advance. This occurs when there are existing maps of survey regions or the vehicle is returning to a site it previously visited. However, given the variable topography of reefs, it would be hard to pre-compute a control policy for exploration. In these cases, other optimal methods could be used such as model predictive control or optimal path generation with PID control.

% Some general conclusions which can be gleaned from these results are: the "nearest neighbor" apprproach sacrifices accuracy in favor of speed, discretization of the states and controls limit smooth action, simple models can yield great intuition, and that zeroing the cost permits greater path following capacity.

% Looking forward to future research, the team would explore this program running onboard the uDrone with a finite horizon. It would require precomputing the J* and U* tables. Other solution methods would also be explored, especially Model Predicitve Control (MPC) and Calculus of Variations.
% \begin{figure}[t]
%     \centerline{\includegraphics[width=\linewidth]{img/U_star.png}}
%     \caption{Optimal Control Law}
%     \label{fig:Ustar}
% \end{figure}


\documentclass[12pt]{article}
\usepackage{jansstylefile} % The option nobibliography does not print the bibliography. But bibliography can still be used.

\begin{document}

\section{Distribution of the posterior of a finite basis expansion with Gaussian coefficients}

\begin{lemma}
	Let \(X^T=\set{X_t:t\in[0,T]}\) be an observation of
	\begin{align*}
		dX_t=b(X_t)dt+\sigma(X_t)dW_t,
	\end{align*}
	where \(b\) is equipped with the prior distribution defined by
	\[
	b=\sum_{j=1}^k\theta_j\phi_j,
	\]
	where \(\set{\phi_1,\ldots,\phi_k}\) is a linearly independent basis, and \(\theta=(\theta_1,\ldots,\theta_k)^t\) has multivariate normal distribution \(N(\mu,\Sigma)\) and \(\sigma\) is a positive measurable function. Then the  posterior distribution of \(\theta\) is \(N((S+\Sigma^{-1})^{-1}(m+\mu), (S+\Sigma^{-1})^{-1})\), where the vector \(m=(m_1,\ldots,m_k)^t\) is defined by
	\[
	m_l=\int_0^T\frac{\phi_l(X_t)}{\sigma(X_t)^2}dX_t, \quad l=1,\ldots,k,
	\]
	and the symmetric \(k\times k\)-matrix \(S\) is given by
	\[
	S_{l,l'}=\int_0^T\frac{\phi_l(X_t)\phi_{l'}(X_t)}{\sigma^2(X_t)}dt,\quad l,l'=1,\ldots,k,
	\]
	provided \(S+\Sigma^{-1}\) is invertible.
\end{lemma}
\begin{proof}Almost surely we have by Girsanov's theorem\begin{equation}\label{eq:girsanov}
p(X^T\mid \theta)=\exp\left(\int_0^T\frac{b(X_t)}{\sigma(X_t)^2}dX_t-\frac12\int_0^T\rh{\frac{b(X_t)}{\sigma(X_t)}}^2dt\right),
\end{equation}with respect to the Wiener measure. So \(\log p(X^T\mid b)=\theta^tm - \frac 1 2 \theta^t S\theta\). And the log of the distribution of \(\theta\) with respect to the Lebesgue measure on \(\re^k\) is given by
\begin{align*}
	\log p(\theta)= &C_1 - \frac 1 2 (\theta-\mu)^t\Sigma^{-1}(\theta-\mu) \\
	= &C_2 - \frac 1 2 \theta\Sigma^{-1}\theta +\theta^t\Sigma^{-1}\mu,
\end{align*}
for some constants \(C_1\) and \(C_2\).

So, by the Bayes formula, for some constant \(C_3\), the posterior density of \(\theta\) is given by\begin{align*}
	\log p(\theta\mid X^T) = & C_3 + \theta^tm - \frac 1 2 \theta^t S\theta - \frac 1 2 \theta\Sigma^{-1}\theta +\theta^t\Sigma^{-1}\mu\\
	= & C_3 + \theta^t ( m + \Sigma^{-1} \mu ) - \frac 1 2 \theta^t (S+\Sigma^{-1}) \theta\\
	= & C_3 + \theta^t ( S + \Sigma^{-1} )  \Big  ( ( S + \Sigma^{-1} )^{-1} (m + \Sigma^{-1}\mu )\Big) - \frac 1 2 \theta^t (S+\Sigma^{-1}) \theta.
\end{align*}It follows that  \(p(\theta\mid X^T)\) is normally distributed with mean
\[( S + \Sigma^{-1} )^{-1} (m + \mu).\]
 and covariance matrix \[(S+\Sigma^{-1})^{-1}.\]
\end{proof}

\section{Distribution of the posterior of a finite basis expansion with Gaussian coefficients}

\begin{lemma}
	Let \(X^T=\set{X_t:t\in[0,T]}\) be an observation of
	\begin{align*}
		dX_t=b(X_t)dt+dW_t,
	\end{align*}
	where \(b\) is equipped with the prior distribution defined by
	\[
	b=\sum_{j=1}^k\theta_j\phi_j,
	\]
	where \(\set{\phi_1,\ldots,\phi_k}\) is a linearly independent basis, and \(\theta=(\theta_1,\ldots,\theta_k)^t\) has multivariate normal distribution \(N(\mu,\Sigma)\). Then the  posterior distribution of \(\theta\) is \(N((S+\Sigma^{-1})^{-1}(m+\mu), (S+\Sigma^{-1})^{-1})\), where the vector \(m=(m_1,\ldots,m_k)^t\) is defined by
	\[
	m_l=\int_0^T\phi_l(X_t)dX_t, \quad l=1,\ldots,k,
	\]
	and the symmetric \(k\times k\)-matrix \(S\) is given by
	\[
	S_{l,l'}=\int_0^T\phi_l(X_t)\phi_{l'}(X_t)dt,\quad l,l'=1,\ldots,k,
	\]
	provided \(S+\Sigma^{-1}\) is invertible.
\end{lemma}
\begin{proof}Almost surely we have by Girsanov's theorem\begin{equation}\label{eq:girsanov}
p(X^T\mid \theta)=\exp\left(\int_0^Tb(X_t)dX_t-\frac12\int_0^Tb(X_t)^2dt\right),
\end{equation}with respect to the Wiener measure. So \(\log p(X^T\mid b)=\theta^tm - \frac 1 2 \theta^t S\theta\). And the log of the distribution of \(\theta\) with respect to the Lebesgue measure on \(\re^k\) is given by
\begin{align*}
	\log p(\theta)= &C_1 - \frac 1 2 (\theta-\mu)^t\Sigma^{-1}(\theta-\mu) \\
	= &C_2 - \frac 1 2 \theta\Sigma^{-1}\theta +\theta^t\Sigma^{-1}\mu,
\end{align*}
for some constants \(C_1\) and \(C_2\).

So, by the Bayes formula, for some constant \(C_3\), the posterior density of \(\theta\) is given by\begin{align*}
	\log p(\theta\mid X^T) = & C_3 + \theta^tm - \frac 1 2 \theta^t S\theta - \frac 1 2 \theta\Sigma^{-1}\theta +\theta^t\Sigma^{-1}\mu\\
	= & C_3 + \theta^t ( m + \Sigma^{-1} \mu ) - \frac 1 2 \theta^t (S+\Sigma^{-1}) \theta\\
	= & C_3 + \theta^t ( S + \Sigma^{-1} )  \Big  ( ( S + \Sigma^{-1} )^{-1} (m + \Sigma^{-1}\mu )\Big) - \frac 1 2 \theta^t (S+\Sigma^{-1}) \theta.
\end{align*}It follows that  \(p(\theta\mid X^T)\) is normally distributed with mean
\[( S + \Sigma^{-1} )^{-1} (m + \mu).\]
 and covariance matrix \[(S+\Sigma^{-1})^{-1}.\]
\end{proof}

\end{document}


\documentclass{article}
\usepackage{enumerate}
\usepackage{amsmath, amsthm, amssymb}
\usepackage[margin=1in]{geometry}
\usepackage[parfill]{parskip}
\DeclareMathOperator*{\argmax}{arg\,max}

\title{Econ C103 Problem Set 8}
\author{Sahil Chinoy}
\date{April 11, 2017}

\begin{document}
\maketitle{}

\subsection*{Exercise 1}

\begin{enumerate}[(a)]
	\item

	With a reserve price of 1, $\mathbb{E}[\pi] = 2p_{11} + 2p_{10} + p_{00}$. With a reserve price of 2, $\mathbb{E}[\pi] = 2p_{11} + 4 p_{10}$.

	\item

	To maximize revenue, we want to extract all the agent's utility when they are of the lowest type. So, set $\mathbb{E}[u_i(\theta_i = 1)] = 0$. If the agent wins, their payoff will be $1 - t_i(\theta_i = 1)$, so $t_i(\theta_i) = 1$.

	For dominant strategy incentive compatibility, we need it to be in the agent's interest to report their true type regardless of the other agent's message. Consider the case $m_{-i} = 1$.

	If $\theta_i = 1$, $u_i(\theta_i=1, m_i =1) = \frac{1}{2}(1-t_i(\theta_i = 1)) = 0$, and $u_i(\theta_i=1, m_i =2) = (1-t_i(\theta_i = 2)) < 0$. So, if if $t_i(\theta_i = 2) \geq 1$, it is in the agent's interest to report their true type.

	If $\theta_i = 2$, $u_i(\theta_i=2, m_i =2) = (2-t_i(\theta_i = 2))$, and $u_i(\theta_i=2, m_i =1) = \frac{1}{2}(2-t_i(\theta_i = 1)) = \frac{1}{2}$. So, if $t_i(\theta_i = 2) \leq \frac{3}{2}$, it is in the agent's interest to report their true type.

	Now, consider the case $m_{-i} = 2$, with $t_i(\theta_i = 2) \in [1, \frac{3}{2}]$.

	If $\theta_i = 1$, $u_i(\theta_i=1, m_i =1) = 0$, and $u_i(\theta_i=1, m_i =2) = (1-t_i(\theta_i = 2)) < 0$. So it is in the agent's interest to report their true type.

	If $\theta_i = 2$, $u_i(\theta_i=2, m_i =1) = 0$, and $u_i(\theta_i=2, m_i =2) = \frac{1}{2}(2-t_i(\theta_i = 2)) > 0$. So it is in the agent's interest to report their true type.

	We want to maximize revenue, so set $t_i(\theta_i = 2) = \frac{3}{2}$. The mechanism is thus

	$$x_i(\theta) = \begin{cases}
		1 \text{ if } \theta_i > \theta_{-i} \\
		0 \text{ else}
	\end{cases}$$

	and

	$$t_i(\theta) = \begin{cases}
		1 \text{ if } x_i = 1 \text{ and } \theta_i = 1 \\
		\frac{3}{2} \text{ if } x_i = 1 \text{ and } \theta_i = 2 \\
		0 \text{ else.}
	\end{cases}$$

	The expected revenue from this mechanism is $\mathbb{E}[\pi] = p_{00} + \frac{3}{2}p_{11} + 3p_{10}$.

	It's not clear whether this mechanism raises more revenue than the second-price auction (with either reserve price 1 or 2) -- it depends on the joint distribution of types. For example, if $p_{00} = 0.5$, $p_{10} = 0.25$, and $p_{11} = 0$, this mechanism maximizes revenue, while if $p_{10} = 1$, $p_{00} =0$, and $p_{11} = 0$ the SPA with reserve price 2 maximizes revenue, and if $p_{00} = 0.5$, $p_{11} = 0.5$, and $p_{10} = 0$, the SPA with reserve price 1 maximizes revenue.

	\item

	Consider transfers conditional on having the higher type and thus being allocated the object, that is, if $x_i = 0$, then $t_i = 0$.

	Now, set $\mathbb{E}[u_i(\theta) | \theta_i =1] = 0$. This implies $\frac{p_{00}}{2(p_{10} + p_{00})}(1 - t_i(\theta_i = 1)) = 0$, or $t_i(\theta_i = 1) = 1$.

	For Bayes-Nash incentive compatibility to hold, it must be in agent $i$'s best interest to report their true type (given that the other agent also reports truthfully). Note that it wouldn't make sense for an agent with true type 1 to report a higher type, since if they won, they would receive negative utility. So, we consider the decision of an agent with true type 2

	\begin{gather*}
	\mathbb{E}[u_i(\theta_i = 2, m_i = 2) | m_{-i} = \theta_{-i}] \geq  \mathbb{E}[u_i(\theta_i = 2, m_i = 1) | m_{-i} = \theta_{-i}] \\
	\frac{p_{11}}{2(p_{11} + p_{10})}(2-t_i(\theta_i = 2)) + \frac{p_{10}}{p_{11} + p_{10}}(2-t_i(\theta_i = 2)) \geq \frac{p_{10}}{2(p_{11} + p_{10})}(2-t_i(\theta_i = 1)) \\
	\frac{p_{11}}{2(p_{11} + p_{10})}(2-t_i(\theta_i = 2)) + \frac{p_{10}}{p_{11} + p_{10}}(2-t_i(\theta_i = 2)) \geq \frac{p_{10}}{2(p_{11} + p_{10})}(2-t_i(\theta_i = 1)) \\
	(2-t_i(\theta_i = 2))(p_{11} + 2p_{10}) \geq p_{10} \\
	t_i(\theta_i = 2) \leq 2 - \frac{p_{10}}{p_{11} + 2p_{10}}.
	\end{gather*}

	To maximize revenue, we should maximize this transfer, so set $t_i(\theta_i = 2) = 2 - \frac{p_{10}}{p_{11} + 2p_{10}}$. Then the revenue-maximizing Bayes-Nash incentive compatible mechanism is

	$$x_i(\theta) = \begin{cases}
		1 \text{ if } \theta_i > \theta_{-i} \\
		0 \text{ else}
	\end{cases}$$

	and

	$$t_i(\theta) = \begin{cases}
		1 \text{ if } x_i = 1 \text{ and } \theta_i = 1 \\
		2 - \frac{p_{10}}{p_{11} + 2p_{10}} \text{ if } x_i = 1 \text{ and } \theta_i = 2 \\
		0 \text{ else.}
	\end{cases}$$

	\item

	Starting from the mechanism in part (c), we can construct an additional transfer $\tau_i(\theta_{-i})$ that depends only on the other agent's type and thus does not change the incentives of the agents. Further, we can set this transfer to extract all the agent's utility from participating in the mechanism defined in part (c).

	In (c), the expected utility derived by agent $i$ from the mechanism is $v_i(\theta_i = 1) = 0$, and $v_i(\theta_i = 2) = \frac{p_{11}}{2(p_{11} + p_{10})} (2 - t_i(\theta_i = 2)) + \frac{p_{10}}{p_{11} + p_{10}} (2 - t_i(\theta_i = 2)) = \frac{p_{10}}{2(p_{11} + p_{10})}$.

	We set the expected additional transfer equal to these expected utilities, so

	$$\mathbb{E}[\tau(\theta_{-i}) | \theta_i = 1] = \frac{p_{00}}{p_{10} + p_{00}} \tau(\theta_{-i} = 1) + \frac{p_{10}}{p_{10} + p_{00}} \tau(\theta_{-i} = 2) = 0$$

	and

	$$\mathbb{E}[\tau(\theta_{-i}) | \theta_i = 2] = \frac{p_{10}}{p_{10} + p_{11}} \tau(\theta_{-i} = 1) + \frac{p_{11}}{p_{10} + p_{11}} \tau(\theta_{-i} = 2) = \frac{p_{10}}{2(p_{11} + p_{10})}.$$

	Solving this system of equations, we find

	$$\tau(\theta_{-i} = 1) = \frac{-{p_{10}}^2}{2(p_{11}p_{00} - {p_{10}}^2)}$$

	and

	$$\tau(\theta_{-i} = 2) = \frac{p_{10}p_{00}}{2(p_{11}p_{00} - {p_{10}}^2)}.$$

	So the revenue-maximizing Bayes-Nash incentive compatible mechanism is $x_i(\theta)$ as in part (c) and $t_i^*(\theta) = t_i(\theta) + \tau(\theta_{-i})$ with $t_i(\theta)$ as in part (c).

 	\item

 	The mechanism in (d) generates more revenue than the mechanism in (c) because the principal uses the correlation across types to extract the information rent that the agent would receive in the uncorrelated case (which is equal to $\frac{p_{10}}{2(p_{11} + p_{10})}$ when $\theta_i = 2$, and 0 otherwise). Because information about the \textit{other} agent's type gives information about agent $i$'s type, there is no truly private information, and thus the agent cannot ``keep'' the extra utility he would otherwise derive from being incentivized to reveal his true type if it is $\theta_i = 2$.

\end{enumerate}

\subsection*{Exercise 2}

\begin{enumerate}[(a)]
	\item

	The social welfare is given by

	$$SWF = \sum_i \left[ \alpha \theta_i + \frac{1-\alpha}{n} \sum_{j = 1}^n \theta_j \right] x_i.$$

	The second term is the same for every agent. To maximize the first term, we should give the object to the agent with the greatest value. So the welfare maximizing allocation is

	$$x_i(\theta) = \begin{cases}
		1 \text{ if } \theta_i > \theta_{j \neq i} \\
		0 \text{ else.}
	\end{cases}$$

	\item

	The allocation is monotone in $\theta_i$ (strictly increasing differences), so it is implementable.

	As a check, we showed in class that an equivalent condition for the welfare-maximizing allocation to be implementable in dominant strategies is

	$$\frac{\partial h_i}{\partial \theta_i} \geq \max_{j \neq i} \frac{\partial h_i}{\partial \theta_j}.$$

	Here, we have $\frac{\partial h_i}{\partial \theta_i} = \alpha + \frac{1-\alpha}{n}$ and $\frac{\partial h_i}{\partial \theta_j} = \frac{1-\alpha}{n}$, so the allocation is indeed implementable.

	\item

	Define $v_i(\theta) = h_i(\theta)x_i - t_i$, where $x_i$ is the optimal allocation from (a). Using the envelope rule,

	$$\frac{\partial v_i(\theta)}{\partial \theta_i} = \frac{\partial h_i(\theta)}{\partial \theta_i} x_i = \left( \alpha + \frac{1-\alpha}{n} \right) x_i$$

	because $\frac{\partial x_i}{\partial \theta_i} = 0$ for the optimal allocation.

	\item Integrating,

	$$v_i(\theta_i, \theta_{-i}) = v_i(0, \theta_{-i}) + \left( \alpha + \frac{1-\alpha}{n} \right) \int \limits_0^{\theta_i} x_i(s, \theta_{-i}) ds$$

	and since $v_i(\theta) = h_i(\theta)x_i - t_i$,

	$$t_i(\theta) = h_i(\theta)x_i - \left( \alpha + \frac{1-\alpha}{n} \right) \int \limits_0^{\theta_i} x_i(s, \theta_{-i}) ds- v_i(0, \theta_{-i}).$$

	\item

	Consider the transfer in (d) with $v_i(0, \theta_{-i}) = 0$. Then, if $x_i = 0$, $t_i = 0$. If $x_i = 1$,

	\begin{gather*}
	t_i(\theta) = \alpha \theta_i + \frac{1-\alpha}{n} \sum_{j = 1}^n \theta_j - \left( \alpha + \frac{1-\alpha}{n} \right) (\theta_i - \tilde{\theta}) \\
	t_i(\theta) = \frac{1-\alpha}{n} \sum \limits_{j\neq i} \theta_j + \left( \alpha + \frac{1-\alpha}{n} \right) \tilde{\theta}
	\end{gather*}

	where $\tilde{\theta}$ is the second-highest type.

	The mechanism with the allocation in (a) is efficient, and with transfers as above, is dominant-strategy incentive compatible by construction. We still need to check that the participation constraint is satisfied.

	If $x_i = 0$, $v_i(\theta) = 0$. If $x_i = 1$, then $\theta_i > \theta_{j\neq i}$ and

	$$v_i(\theta) = \alpha \theta_i + \frac{1-\alpha}{n} \sum_{j = 1}^n \theta_j - \left[ \frac{1-\alpha}{n} \sum \limits_{j\neq i} \theta_j + \left( \alpha + \frac{1-\alpha}{n} \right) \tilde{\theta} \right] = \left( \alpha + \frac{1-\alpha}{n} \right)(\theta_i - \tilde{\theta}) \geq 0.$$

	So the agent derives nonnegative utility from the mechanism regardless of their type. This means the participation constraint is satisfied. To summarize, a welfare-maximizing mechanism is

	$$x_i(\theta) = \begin{cases}
		1 \text{ if } \theta_i > \theta_{j \neq i} \\
		0 \text{ else}
	\end{cases}$$

	and

	$$t_i(\theta) = \begin{cases}
		\frac{1-\alpha}{n} \sum \limits_{j\neq i} \theta_j + \left( \alpha + \frac{1-\alpha}{n} \right) \tilde{\theta} \text{ if } \theta_i > \theta_{j \neq i} \\
		0 \text{ else}
	\end{cases}$$

	where $\tilde{\theta}$ is the second-highest type.

\end{enumerate}

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{The QoI Map Relates Inputs and Outputs}

\only<1>{

\begin{figure}[h]
	\includegraphics[width=0.85\textwidth]{./figures/threelevels/schematic_lambda_solution_data.pdf}
\end{figure}

}

\only<2>{

\begin{figure}[h]
	\includegraphics[width=0.85\textwidth]{./figures/threelevels/schematic_lambda_data.pdf}
\end{figure}

}

\only<3>{

\begin{figure}[h]
	\includegraphics[width=0.85\textwidth]{./figures/threelevels/schematic_lambda_data_level1.pdf}
\end{figure}

}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{A Forward UQ Problem}

\begin{figure}[h]
	\includegraphics[width=0.85\textwidth]{./figures/threelevels/schematic_lambda_data_level3.pdf}
\end{figure}

{We denote the measurable spaces of parameters and data on the QoI as $(\pspace,\pborel)$ and $(\dspace,\dborel)$, respectively.}
\bigskip

\tdeepred{Given some prior density $\initial$ on $(\pspace,\pborel)$, we let $\predicted$ denote the push-forward of this density on $(\dspace,\dborel)$.}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{The Inverse QoI Map}

\begin{figure}[h]
	\includegraphics[width=0.85\textwidth]{./figures/threelevels/schematic_data_lambda_level1.pdf}
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{An Inverse UQ Problem}

\begin{figure}[h]
	\includegraphics[width=0.85\textwidth]{./figures/threelevels/schematic_data_lambda_level3.pdf}
\end{figure}

\tdeepred{Given $\obs$ on $(\dspace,\dborel)$, we let $\predicted$ denote the pullback (consistent) density on $(\pspace,\pborel)$.}

\end{frame}

\subsection{The Stochastic Inverse Problem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]

\begin{figure}
\centering
	\includegraphics[width=.65\textwidth]{images/illustration1.pdf}<1>
	\includegraphics[width=.65\textwidth]{images/illustration2.pdf}<2>
	\includegraphics[width=.7\textwidth]{images/illustration3.pdf}<3>
\end{figure}
\begin{center}
{\scriptsize Figure adopted from \cite{BET14+} and used with permission}
\end{center}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]

\begin{figure}
\centering
	\includegraphics[width=1\textwidth]{images/troy_mt3contour.png}
\end{figure}
\begin{center}

{\scriptsize Figure adopted from \cite{BET14+} and used with permission}

\tdeepred{Key Question:} Distinguish (assign probability to) events that belong to same contour.
\end{center}
\end{frame}


\section{Experiment 2: Simulated Data with Latent Structure}

In the second simulation experiment, we focused on data generated from a Factor Analysis model.
The data social scientists analyse are often a collection of items measuring different latent constructs,
a characteristic that is likely to impact imputation performances.
In Experiment 2, we investigated the performances of the missing data treatments in relation to three experimental factors.
First, the dimensionality of the data was controlled by the number of latent variables $l$ (10, 100).
5 items were generated as measurements of each latent variable, resulting in either 50 or 500 items.
Second, factor loadings were defined as a 2-level random experimental factor (high, low).
High factor loadings were drawn from a uniform distribution between (0.9, 0.97), while low factor loadings
were drawn from a uniform distribution between (0.5, 0.6).
Third, the proportion of missing values was defined as a fixed experimental factor with two levels: 0.1 or 0.3.
Table \ref{tab:condExp2} summarizes the eight resulting conditions.

Data with sample size $n=200$ were independently generated 1,000 times for each condition.
For each replicate, missing values were imposed and then each missing data treatment was used to obtain estimates
for the parameters of a complete-data analysis model.
With a sample size fixed at 200, conditions with $l = 10$ resulted in a low-dimensional settings, while conditions
with $l = 100$ resulted in a high-dimensional settings.

\begin{table}
\tbl{Summary of conditions for Experiment 2.}
	{
	\begin{tabular}{l c c c c c c }
		\toprule
		condition & label & n & p & l & pm & $\lambda$ range \\
		\midrule
		1 & low-dim-low-pm-high-$\lambda$ & 200 & 50 &  10 &  0.1 & [0.9, 0.97] \\
		2 & high-dim-low-pm-high-$\lambda$ & 200 & 500 & 100 & 0.1 & [0.9, 0.97] \\
		3 & low-dim-high-pm-high-$\lambda$ & 200 & 50 &  10 &  0.3 & [0.9, 0.97] \\
		4 & high-dim-high-pm-high-$\lambda$ & 200 & 500 & 100 & 0.3 & [0.9, 0.97] \\
		5 & low-dim-low-pm-low-$\lambda$ & 200 & 50 &  10 &  0.1 & [0.5, 0.6]  \\
		6 & high-dim-low-pm-low-$\lambda$ & 200 & 500 & 100 & 0.1 & [0.5, 0.6]  \\
		7 & low-dim-high-pm-low-$\lambda$ & 200 & 50 &  10 &  0.3 & [0.5, 0.6]  \\
		8 & high-dim-high-pm-low-$\lambda$ & 200 & 500 & 100 & 0.3 & [0.5, 0.6]  \\
		\bottomrule
	\end{tabular}
	}
\label{tab:condExp2}
\end{table}

\FloatBarrier % stops table:condSum leaving its own section

\subsection{Simulation Study Procedure}

%\paragraph{Data Generation}
	For each replication, an observed data matrix $\bm{Z}_{n \times p}$ was created based on a Confirmatory
	Factor Analysis model.
	Each of $l$ latent variables was assumed to be measured by 5 items, for a total of $p = 5*l$
	columns in $\bm{Z}$.
	Values on the items for the $i$-th observation were obtained with the following measurement
	model:
%
	\begin{equation}
		\bm{z}_i = \bm{\Lambda} \bm{\xi}_{i.} + \bm{\delta}_{i.}
	\end{equation}
%
	where $\bm{z}_i$ is a vector of $5*l$ items scores for observations $i = 1, ..., n$;
	$\bm{\Lambda}$ is the $(5*l) \times l$ matrix of factor loadings; $\bm{\xi}_{i.}$ is a vector of $l$ latent scores
	for observation $i$; and $\bm{\delta}_{i.}$ is a vector of $5*l$ uncorrelated measurement errors sampled from a
	multivariate normal distribution centered around a mean vector of 0s and with a diagonal covariance matrix $\bm{\Theta}$.
	All items were centered around a mean of 5.
	For notation and model specification the interested reader may refer to \cite{bollen:1989}.

	The latent scores in $\bm{\xi}_{i.}$ were sampled from a multivariate normal distribution centered around
	0, and with a covariance matrix $\bm{\Psi}$, with diagonal elements equal to 1 and off-diagonal elements
	equal to correlation between latent factors.
	In particular, the first 4 latent variables were highly correlated ($\rho = .6$), the second block of 4
	latent variables were weakly correlated ($\rho = .3$), while the remaining $l-8$ latent variables were
	uncorrelated.

	The matrix $\bm{\Lambda}$ defined a simple latent structure where each item loaded on only 1 factor (5 items
	for each latent variable).
	Both the item and latent factor variances were set to 1 so that the measurement error variance was defined as
	$var(\delta) = 1 - \lambda^{2}$.
	This specification allowed factor loadings $\lambda_{ij}$, with $i = 1, ..., n$ and $j = 1, ..., l$, to be
	defined as standardized values between 0 and 1.
	The exact values for the latent factors were drawn for each repetition from a uniform distribution
	with bounds defined by the condition.

%\paragraph{Missing Data Imposition}

	Item non-response was imposed on 10 items in $\bm{Z}$ using Equation \ref{eqn:rm} to define the probability
	of a value being missing.
	The items targeted by the missing data imposition measured the first two highly correlated latent variables
	($l = 1, 2$).
	The predictors included in $\tilde{Z}$ were the latent scores for the other two highly correlated latent
	variables ($l = 3, 4$).

%\paragraph{Imputation}

	Missing values were treated according to all the methods previously described.
	The imputation methods were parametrized as in Experiments 1.
	50 iterations were sufficient for convergence of all MI methods except blasso, which required approximately
	2,000 iterations for convergence.

%\paragraph{Analysis}

	The substantive model of interest in Experiment 2 was a saturated model that estimated means,
	variances, and covariances of the raw items with missing values.
	Furthermore, the true Factor Analysis model for the same items was estimated to see how the
	factor loadings were recovered after imputation.

\subsection{Results}
	To assess the performances of the methods, we used the same comparison criteria described for Experiment 1.
	Figures \ref{fig:exp2bias14} and \ref{fig:exp2cir14} report the maximum, average, and minimum $|\text{PRB}|$ and
	CIC obtained with each missing data treatment method for each parameter type (mean, variance, and covariance) in
	the conditions with high factor loadings.
	Figures \ref{fig:exp2bias58} and \ref{fig:exp2cir58} report the same results for the conditions with low
	factor loadings.
	In the supplementary material you may find the figures reporting the raw PRBs and CICs for every parameter.

	\paragraph{Means}
	All the imputation methods resulted in unbiased estimation of the item means with maximum $|\text{PRB}| < 10\%$
	in all conditions.
	In particular, IURR, MI-PCA, and MI-OP exhibited the smallest bias, and only CC analysis led to substantial
	bias of the means.
	When factor loadings were large, DURR, IURR and MI-PCA resulted in little to no deviations from nominal
	coverage, while blasso, bridge, MI-CART, MI-RF, and missForest led to significant under-coverage of the
	true means when the proportion of missing cases was high (columns 3 and 4 in the figures).
	In the conditions with lower factor loadings, all methods performed worse, but relative performances remain
	unchanged.
	IURR, MI-PCA, and MI-OP exhibited again the smallest bias and deviation from nominal coverage rates.
	However, MI-PCA and MI-OP were the only methods returning small deviations from nominal coverage rates in the
	high-dim-high-pm-low-$\lambda$ condition.

	\paragraph{Variances}
	All MI methods, except bridge, resulted in acceptable estimation bias for the item variances in all conditions
	with large factor loadings.
	The least biased estimates were obtained by IURR, MI-PCA, and MI-OP.
	As for CIC, for high-pm conditions (columns 3 and 4), only IURR and MI-PCA maintained CICs mostly within the
	range (0.94, 0.96), while blasso and the MI tree-based methods led to mild to extreme under-coverage
	(maximum CIC < 90\%).
	Single data approaches, missForest and CC, showed again extreme bias and large significant CI under-coverage
	in almost all conditions.
	The large bias and low coverage for the item variances that afflicted MI-PCA in the multivariate-normal set up
	(figures \ref{fig:exp1bias} and \ref{fig:exp1cir}) was not present in figures \ref{fig:exp2bias14} and
	\ref{fig:exp2cir14}.
	However, that pattern reappeared in the conditions with low factor loadings (see figures \ref{fig:exp2bias58}
	and \ref{fig:exp2cir58}).

	\paragraph{Covariances}
	For all the conditions with high factor loadings, IURR and DURR showed acceptable covariance biases
	(largest $|\text{PRB}|<10\%$).
	However, they led to large covariance bias in all the conditions with low factor loadings
	(see Figures \ref{fig:exp2bias58}).
	As in Experiment 1, MI-PCA resulted in the lowest bias and deviation from nominal coverage of the true
	item covariances.
	The largest $|\text{PRB}|$ with MI-PCA was smaller than the $10\%$ threshold in all conditions, and the
	average CIC fell within the interval (0.94, 0.96) in almost all conditions.
	All other methods led to large bias and mild-to-extreme significant covariance under-coverage
	in all conditions.

\begin{figure}
	\includegraphics{\pathFIG/exp2_semR_bias_14_summy.pdf}
\caption{
	Maximum, average, and minimum absolute Percent Relative Bias ($|\text{PRB}|$) for item means, variances,
	and covariances in the conditions of Experiment 2 with high factor loadings.
	For each method, the maximum, average, and minimum PRB are reported in this order.
}
\label{fig:exp2bias14}
\end{figure}

\begin{figure}
	\includegraphics{\pathFIG/exp2_semR_ci_14_summy.pdf}
\caption{
	Maximum, average, and minimum CIC for item means, variances, and covariances in Experiment 2
	in the conditions of Experiment 2 with high factor loadings.
	For each method, the maximum, average, and minimum are reported in this order.
}
\label{fig:exp2cir14}
\end{figure}

\begin{figure}
	\includegraphics{\pathFIG/exp2_semR_bias_58_summy.pdf}
\caption{
	Maximum, average, and minimum absolute Percent Relative Bias ($|\text{PRB}|$) for item means, variances,
	and covariances in the conditions of Experiment 2 with low factor loadings.
	For each method, the maximum, average, and minimum are reported in this order.
}
\label{fig:exp2bias58}
\end{figure}

\begin{figure}
	\includegraphics{\pathFIG/exp2_semR_ci_58_summy.pdf}
\caption{
	Maximum, average, and minimum CIC for item means, variances, and covariances in the conditions of
	Experiment 2 with low factor loadings.
	For each method, the maximum, average, and minimum are reported in this order.
}
\label{fig:exp2cir58}
\end{figure}

\FloatBarrier

	\paragraph{Factor Loadings}
	Figure \ref{fig:exp2fl14} reports the maximum, average, and minimum absolute PRB values for all the factor
	loadings estimated by the Confirmatory Factor Analysis described above.
	IURR, MI-PCA, and MI-OP, outperformed all other methods by producing virtually unbiased estimates of the
	factor loadings in all conditions.
	However, MI-PCA outperformed IURR when factor loadings were low (panel b), maintaining inconsequential
	biases even when data were high-dimensional and the proportion of missing values was high
	(high-dim-high-pm-low-$\lambda$).
	Blasso and MI-RF were the MI methods leading to the largest biases for this parameter type.
	Both of them resulted in extreme bias in the high-pm-low-$\lambda$ conditions with minimum $|\text{PRB}| > 10\%$.

\begin{figure}
	\includegraphics{\pathFIG/exp2_CFA_lambda_BPR_summy.pdf}
	\caption{
		Maximum, average, and minimum absolute Percent Relative Bias ($|\text{PRB}|$) for factor loadings
		in Experiment 2.
		For each method, the maximum, average, and minimum are reported in this order.
		}
\label{fig:exp2fl14}
\end{figure}

\FloatBarrier % stops fig:exp2fl to leave its section


\documentclass[10pt,letterpaper]{article}

\usepackage{booktabs}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{setspace}
\usepackage{hyperref}
\usepackage{multirow}
\usepackage{minted}
% \usepackage{lineno}
% \linenumbers
\usepackage{pslatex}
\usepackage{apacite}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[margin=1.0in]{geometry}

% \doublespace

\title{Analysis of the Simple Harmonic Oscillator \\
    {\small A foundational dynamical system}
}
\author{{\bf Matthew A.~Turner}}
\date{April 8, 2017}

\begin{document}

\maketitle

\section{1-dimensional simple harmonic oscillator: free and damped}
\label{sec:1d}

The simple harmonic oscillator is one of the first problems solved using
Newton's third law, $F=ma$. Usually this problem is framed as finding the
1-dimensional position of a mass on a spring, where the spring hangs from
a fixed surface with a mass on the other end.
The force is given by Hooke's law, which says that the restoring force
of a spring is proportional to the distance from equilibrium, $x$, giving
$F = -k x$, where $k$ is the spring constant. Since $a$ is the second
time derivative of position, Newton's third law can be written

\begin{align*}
    -k x &= m \ddot{x} \\
    \ddot{x} + \omega_0^2 x &= 0
    \label{eq:free-sho}
\end{align*}

\noindent
where $\omega_0 = \sqrt{k/m}$ is the \textit{angular frequency} of the motion,
or the number of cycles per second. $x$ is often referred to as ``displacement.''
In the case of a spring, $\omega$ is the
rate at which the mass goes from its minimum displacement to its maximum
displacement then returns to its minimum displacement. Because
sine and cosine have the negative of themselves as their second derivatives,
either can represent $x$ and as a solution to \ref{eq:free-sho}

\begin{subequations}
    \begin{align}
        x & = A \sin(\omega_0 t - \delta) \\
        x & = A \cos(\omega_0 t - \phi)
    \end{align}
\end{subequations}

\noindent
Note these are are identical if $\delta - \phi = \pi / 2$.

The damped harmonic oscillator adds a damping force to Newton's third law,
$F_d = -b \dot{x}$. Damping effects, such as friction or air resistance,
are always proportional to velocity. Now the equation of motion is

\begin{align*}
    m \ddot{x} + b \dot{x} + k x & = 0 \\
    \ddot{x} + 2\beta \dot{x} + \omega_0^2 x & = 0
    \label{eq:damped-sho}
\end{align*}

\noindent
where $\beta = b/2m$.
Now to solve the equations of motion, we consider the solution $x = e^{rt}$.
Substituting we find

\begin{align*}
    r^2 e^{rt} + 2 \beta r e^{rt} + \omega_0^2 e^{rt} & = 0 \\
    r^2 + 2 \beta r + \omega_0^2  & = 0
\end{align*}

\noindent
Thus,

\begin{align*}
    r = -\beta \pm \sqrt{\beta^2 - \omega_0^2}
\end{align*}

\noindent
There are three physically meaningful classifications of $r$:
$r = -\beta$, $r$ is real-valued ($\beta^2 > \omega_0^2$), or
$r$ is complex-valued ($\beta^2 < \omega_0^2$). These are referred to as
critical damping, overdamping, and underdamping, respectively. In the
critical or overdamped cases, all periodic behavior is removed from the system
and the displacement goes directly to zero without switching sign. In the
underdamped case, there is quasi-periodic behavior as the displacement
oscillates around zero, eventually settling to $x=0$. This is visualized
in the phase diagrams below.

\subsection{Phase diagrams}
\label{sub:phase-diagrams}

In the simple harmonic oscillator, the relevant state variables are the
displacement, $x$, and the velocity $\dot{x}$. First we will consider the
free harmonic oscillator, where the damping $b=0$. Taking the solution
$x(t) = A \sin(\omega_0 t - \delta)$, we find
$\dot{x}(t) = A\omega_0 \cos(\omega_0 t - \delta)$. We can square both equations
and divide the right-hand constants to get

\begin{align*}
    \frac{x^2}{A^2} & = \sin^2(\omega_0t - \delta) \\
    \frac{\dot{x}^2}{A^2\omega_0^2} & = \cos^2(\omega_0 t - \delta)
\end{align*}

\noindent
Adding the two equations and using the
relation $\sin^2(\theta) + \cos^2(\theta) = 1$ we recover the equation for
an ellipse

\begin{align*}
    \frac{x^2}{A^2} + \frac{\dot{x}^2}{A^2 \omega_0^2} = 1
\end{align*}

\noindent
A few phase diagrams for the free harmonic oscillator are shown in Figure \ref{fig:free}

\begin{figure}[h!]
\begin{center}
    \includegraphics[width=0.6\textwidth]{figures/free-sho.png}
\end{center}
\caption{Phase portrait for some values of $\beta$ for the underdamped harmonic oscillator}
\label{fig:free}
\end{figure}

\begin{figure}[h!]
\begin{center}
    \includegraphics[width=0.6\textwidth]{figures/underdamped-sho.png}
\end{center}
\caption{Phase portrait for some values of $\beta$ for the underdamped harmonic oscillator}
\label{fig:underdamped}
\end{figure}

In the case of the underdamped harmonic oscillator, it can be shown that
the solution is $x(t) = Ae^{-\beta t}\cos(\omega_1 t - \delta)$, where
$\omega_1 = \sqrt{\omega_0^2 - \beta^2}$. Using the chain rule for derivatives,
we find $\dot{x}(t)
= -Ae^{-\beta t} (\beta \cos(\omega_1 t - \delta)
+ \omega_1 \sin(\omega_1 t - \delta))$. A few phase diagrams for the underdamped
harmonic oscillator are shown in Figure~\ref{fig:underdamped}.

\rule{\textwidth}{1pt}

Thornton, S. T., \& Marion, J. B. (2004). \textit{Classical Dynamics of Particles and Systems}.
(5th ed.). Belmont, CA. Thompson Brooks/Cole.
\end{document}


\documentclass[11pt,a4wide]{article}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{a4wide}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[dvips]{epsfig}
\usepackage[T1]{fontenc}
\usepackage{cite} % [2,3,4] --> [2--4]
\usepackage{shadow}
\usepackage{hyperref}

\setcounter{tocdepth}{2}

\lstset{language=c++}
\lstset{alsolanguage=[90]Fortran}
\lstset{basicstyle=\small}
\lstset{backgroundcolor=\color{white}}
\lstset{frame=single}
\lstset{stringstyle=\ttfamily}
\lstset{keywordstyle=\color{red}\bfseries}
\lstset{commentstyle=\itshape\color{blue}}
\lstset{showspaces=false}
\lstset{showstringspaces=false}
\lstset{showtabs=false}
\lstset{breaklines}
\begin{document}
\section*{Warm up exercise}

We want you to compute the first derivative of
\[
   f(x)=tan^{-1}(x)
\]
for $x=\sqrt{2}$ with step lengths $h$.
The exact answer is
$1/3$.
We want you to code the derivative using the following two
formulae
\begin{equation}
    f'_{2c}(x)= \frac{f(x+h)-f(x)}{h}+O(h),
\label{eq:ex31a}
\end{equation}
and
\begin{equation}
   f'_{3c}=\frac{f_h-f_{-h}}{2h}+O(h^2),
\label{eq:ex31b}
\end{equation}
with $f_{\pm h}=f(x\pm h)$.

\begin{enumerate}
\item Find mathematical expressions for the total error due to loss
of precision and due to the numerical approximation made.
Find the step length which gives the smallest value.
Perform the analysis with both double and single precision.

\item Make thereafter a program
which computes the first derivative using Eqs.~(\ref{eq:ex31a}) and (\ref{eq:ex31b})
as function of various step lengths $h$ and let $h\rightarrow 0$.
Compare with the exact answer.

Your program should contain the following elements:
\begin{itemize}
 \item A vector (array)  which contains the step lengths.
Use dynamic memory allocation.
 \item Vectors for the computed derivatives of Eqs.~(\ref{eq:ex31a}) and (\ref{eq:ex31b})
for both single and double precision.
\item A function which computes the derivative and contains call by value and reference
(for C++ users only).

 \item Add a function which writes the results to file.
\end{itemize}
\item Compute thereafter
\[
   \epsilon=log_{10}\left(\left|\frac{f'_{\mathrm{computed}}-f'_{\mathrm{exact}}}
                 {f'_{\mathrm{exact}}}\right|\right),
\]
as function of  $log_{10}(h)$ for Eqs.~(\ref{eq:ex31a}) and (\ref{eq:ex31b})
for both single and double precision.
Plot the results and see if you can determine empirically
the behavior of the total error as function of $h$.
\end{enumerate}

\end{document}


\chapter{Lecture 15 Jun 04th 2018}%
\label{chp:lecture_15_jun_04th_2018}
% chapter lecture_15_jun_04th_2018

\section{Group Action}%
\label{sec:group_action}
% section group_action

\subsection{Cayley's Theorem}%
\label{sub:cayley_s_theorem}
% subsection cayley_s_theorem

\begin{thm}[Cayley's Theorem]
\index{Cayley's Theorem}
\label{thm:cayley_s_theorem}
  If $G$ is a finite group of order $n$, then $G$ is isomorphic to a subgroup of $S_n$.
\end{thm}

\begin{proof}
  Since $G$ is finite, let $G = \{g_1, g_2, ..., g_n\}$ and let $S_G$ be the permutation group of $G$. By identifying $g_i$ with $i$, where $1 \leq i \leq n$, we see that $S_G \cong S_n$ \sidenote{$S_G$ is the permutation group of $G$. We can think of $S_G$ as a group of permutations that permutes the index of the elements of $G$. Since there are $n$ indices, there are $n!$ ways to permute the indices, and so $\abs{S_G} = n! = \abs{S_n}$. Then we can certainly find some isomorphism from $S_G$ to $S_n$, and so $S_G \cong S_n$.}. Therefore, it suffices to find an injective homomorphism\sidenote{\hlwarn{Why do we need injectivity?} We need homomorphicity in order to invoke the \hyperref[thm:first_isomorphism_theorem]{First Isomorphism Theorem} so that we can get $G \cong \img \sigma \leq S_G \cong S_n$.} $\sigma : G \to S_G$.

  Consider the function $\mu_a : G \to G$, where $a \in G$, such that $\mu_a(g) = ag$ for all $g \in G$. Clearly, $\mu_a$ is surjective. Suppose $\mu_a = \mu_b$, where $b \in G$. Then $a = \mu_a (1) = \mu_b (1) = b$. Thus $\mu_a$ is also injective. It follows that $\mu_a \in S_G$ by definition.

  Now define the function $\sigma : G \to S_G$ such that $\sigma(a) = \mu_a$. Clearly, $\sigma$ is injective, since $\sigma(a) = \sigma(b) \implies \mu_a = \mu_b$. Observe that $\sigma(ab) = \mu_{ab} = ab = \mu_a \mu_b$. Thus $\sigma$ is a group homomorphism. Note that $\ker \sigma = \{1\}$, the trivial group. It follows from the \hyperref[thm:first_isomorphism_theorem]{First Isomorphism Theorem} that $G \cong \im \sigma \leq S_G \cong S_n$.\sidenote{We shall use $H \leq G$ to denote that $H$ is a subgroup of $G$ from here on.} \sidenote{This is a result from \cref{propo:image_of_hm_is_a_subgroup_n_kernel_of_hm_is_a_normal_subgroup}} \qed
\end{proof}

Cayley's Theorem is, however, too strong at times. We can certainly find a smaller integer $m$ such that $G$ is contained in $S_m$. Consider the following example.

\begin{eg}\label{eg:a_smaller_subgroup_of_Sn_that_is_iso_to_G}
  Let $H \leq G$ with $[G : H] = m < \infty$. Let $X = \{g_1 H, g_2 H, ..., g_m H\}$ be the set of all distinct left cosets of $H$ in $G$ \sidenote{This is simply a consequence of $[G : H] = m$.}. For $a \in G$, define $\lambda_a : X \to X$ by $\lambda_a (gH) = agH$, $gH \in X$.

  Note that $\lambda_a$ is a bijection\sidenote{This is true as shown in the proof above, but it can also serve as a tiny exercise.}, and so $\lambda_a \in S_X$, the permutation group of $X$. Consider the mapping $\tau : G \to S_X$ defined by $\tau (a) = \lambda_a$ for $a \in G$. Note that $\forall a, b \in G$, $\lambda_{ab} = \lambda_a \lambda_b$. Thus $\tau$ is a homomorphism. Note that if $a \in \ker \tau$, then $aH = H$ which implies $a \in H$ by \cref{propo:properties_of_cosets}. Thus $\ker \tau \subseteq H$.
\end{eg}

From the example above, if we apply the \hyperref[thm:first_isomorphism_theorem]{First Isomorphism Theorem}, then
\begin{equation*}
  \faktor{G}{\ker \tau} \cong \img \tau \leq S_X \cong S_m \leq S_n.
\end{equation*}
This is the result that we desired.

\begin{thm}[Extended Cayley's Theorem]
\index{Extended Cayley's Theorem}
\label{thm:extended_cayley_s_theorem}
  Let $H \leq G$ with $[G : H] = m < \infty$. If $G$ has no normal subgroup contained in $H$ except for the trivial subgroup $\{1\}$, then $G$ is isomorphic to a subgroup of $S_m$.
\end{thm}

\begin{proof}
  By our assumption, let $X$ be the set of all distinct left cosets of $H$ in $G$. Then we have that $\abs{X} = m$ and so $S_X \cong S_m$ \sidenote{This is as argued in the proof of \hyperref[thm:cayley_s_theorem]{Cayley's Theorem}.}. From \cref{eg:a_smaller_subgroup_of_Sn_that_is_iso_to_G}, we have that there exists a group homomorphism $\tau : G \to S_X$ with $K := \ker \tau \subseteq H$. So by the \hyperref[thm:first_isomorphism_theorem]{First Isomorphism Theorem}, we have that
  \begin{equation*}
    \faktor{G}{K} \cong \img \tau.
  \end{equation*}
  Since $K \subseteq H$ and $K \triangleleft G$, we have, by assumption, that $K = \{1\}$. It follows that
  \begin{equation*}
    G \cong \img \tau \leq S_X \cong S_m.
  \end{equation*}\qed
\end{proof}

\begin{crly}
\label{crly:subgroup_with_prime_index_dividing_order_of_group_is_normal}
  Let $\abs{G} = m \in \mathbb{N}$ and $p$ the smallest prime such that $p \big| m$. If $H \leq G$ with $[G : H] = p$, then $H \triangleleft G$.
\end{crly}

\begin{proof}
  Let $X$ be the set of all distinct left cosets of $H$ in $G$. We have $\abs{X} = p$ and so $S_X \cong S_p$. Let $\tau : G \to S_X \cong S_p$ be as defined in \cref{eg:a_smaller_subgroup_of_Sn_that_is_iso_to_G}, with $K := \ker \tau \subseteq H$. By the \hyperref[thm:first_isomorphism_theorem]{First Isomorphism Theorem}, we have that
  \begin{equation*}
    \faktor{G}{K} \cong \img \tau \leq S_X \cong S_p,
  \end{equation*}
  i.e. $\faktor{G}{K}$ is isomorphic to a subgroup of $S_p$. Therefore, by \hyperref[thm:lagrange_s_theorem]{Lagrange's Theorem}, we have that $\abs{\faktor{G}{K}} \Bigg| \; p!$.

  Also, since $K \subseteq H$, if $[H : K] = k \in \mathbb{N}$, then
  \begin{equation*}
    \abs{\faktor{G}{K}} \overset{(1)}{=}\frac{\abs{G}}{\abs{K}} = \frac{\abs{G}}{\abs{H}} \cdot \frac{\abs{H}}{\abs{K}} = pk,
  \end{equation*}
  where $(1)$ is by \cref{propo:propo_related_to_quotient_groups}. Therefore we have that $pk \, | p!$ and so $k \, | \, (p - 1)!$.

  Note that $k \, | \, \abs{H}$ \sidenote{This is clear since $\abs{H} = k \abs{K}$.}, which divides $\abs{G}$, and $p$ is the smallest prime dividing $\abs{G}$. Thus evrey prime divisor of $k$ must be $\geq p$.\sidenote{By the \hlnotea{Fundamental Theorem of Arithmetic}, and since $k$ is finite, let $k = p_1^{a_1} p_2^{a_2} ...p_m^{a_m}$, where $p_i$'s are distinct primes and $a_i \in \mathbb{N}$ are the multiplicities of the $i$\textsuperscript{th}, and by the \hlnotea{Well-Ordering Principle}, let $p_i < p_{i + 1}$. Then we have, for some $b = b_1^{c_1} b_2^{c_2} \hdots b_j^{c_j} \in \mathbb{N}$ where the $b_i$'s are distint primes, $b_i < b_{i + 1}$, and $c_i \in \mathbb{N} \cup \{0\}$,
  \begin{equation*}
    m = kb = p_1^{a_1} p_2^{a_2} \hdots p_m^{a_m} b_1^{c_1} b_2^{c_2} \hdots b_j^{c_j}.
  \end{equation*}
  Since $p$ is the smallest prime that divides $m$, we have
  \begin{align*}
    p &= \min \{p_1, p_2, ..., p_m, b_1, b_2, ..., b_j\} \\
      &= \min \{ p_1, b_1 \}
  \end{align*}
  } Thus $k = 1$, which implies that $K = H$. Therefore, $H \triangleleft G$ as desired.\qed
\end{proof}

% subsection cayley_s_theorem (end)

\subsection{Group Action}%
\label{sub:group_action}
% subsection group_action

\begin{defn}[Group Action]\index{Group Action}
\label{defn:group_action}
  Let $G$ be a group, $X$ a non-empty set. A \hlnoteb{group action} of $G$ on $X$ is a mapping $G \times X \to X$ denoted as $(a, x) \to ax$ such that
  \begin{enumerate}
    \item $1 \cdot x = x$, $x \in X$
    \item $a \cdot (b \cdot x) = (ab) \cdot x$, $a, b \in G, \, x \in X$
  \end{enumerate}
  In this case, we say $G$ \hldefn{acts on} $X$.
\end{defn}

% subsection group_action (end)

% section group_action (end)

% chapter lecture_15_jun_04th_2018 (end)


\documentclass
{article}
\input{../homework-problems}

\toggletrue{solutions}
%\togglefalse{solutions}
\toggletrue{answers}
\newtheorem{problem}{Problem}

\newcommand{\hide}[1]{}

\renewcommand{\fcProblemRef}{\theproblem.\theenumi}
\renewcommand{\fcSubProblemRef}{\theenumi.\theenumii}
\begin{document}
\begin{center}
\Large
Master Problem Sheet \\
Version \today \\
Calculus II
\end{center}

%\noindent \textbf{Name:} \hfill{~}
%\begin{tabular}{c|c|c|c|c|c|c|c|c||c}
%Problem&1 &2&3&4&5&6&7&8& $\sum$\\ \hline
%Score&&&&&&&&&\\ \hline
%Max&20&20&20&20&20&10&20&20&150
%\end{tabular}

This master problem sheet contains all freecalc problems on the topics studied in Calculus II. For a list of contributors/authors of the freecalc project (and in particular, the present problem collection) see file contributors.tex.

\fcLicenseContent

\tableofcontents

\section{Inverse trigonometry} \label{secInverseTrig}
\begin{problem}
\input{../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-1}
\end{problem}
\input{../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-1-solutions}

\begin{problem}
\input{../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-2}
\end{problem}
\input{../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-2-solutions}

\begin{problem}
\input{../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-3}
\end{problem}
\input{../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-3-solutions}

\begin{problem}
\input{../../modules/inverse-trig/homework/inverse-trig-derivatives}
\end{problem}

\begin{problem}
\input{../../modules/inverse-trig/homework/artan-sum-problem}
\end{problem}
\input{../../modules/inverse-trig/homework/artan-sum-problem-solution}

\section{Integration by parts}\label{secIntegrationByParts}
\begin{problem}
\input{../../modules/integration-by-parts/homework/integration-by-parts2}
\end{problem}
\input{../../modules/integration-by-parts/homework/integration-by-parts2-solutions}

\begin{problem}
\input{../../modules/integration-by-parts/homework/integration-by-parts}
\end{problem}
\input{../../modules/integration-by-parts/homework/integration-by-parts-solutions}

\begin{problem}
\input{../../modules/integration-by-parts/homework/integrate-x-power-n-e-power-x}
\end{problem}
\input{../../modules/integration-by-parts/homework/integrate-x-power-n-e-power-x-solution}

\section{Integration of rational functions}\label{secIntegrationRationalFunctions}
\subsection{Building block integrals}\label{secRationalFunctionBuildingBlocks}
\begin{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-building-blocks}
\end{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-building-blocks-solutions}

\begin{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-building-block-II-and-III-parametric}
\end{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-building-block-II-and-III-parametric-solution}

\begin{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-building-block-III-b-parametric}
\end{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-building-block-III-b-parametric-solution}

\subsection{Complete algorithm: partial fractions} \label{secPartialFractionsCompleteAlgorithm}
\subsubsection{Quadratic term in the denominator}
\begin{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-quadratics-in-denominator-1}
\end{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-quadratics-in-denominator-1-solutions}
\subsubsection{Complete algorithm}
\begin{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-complete-1}
\end{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-complete-1-solutions}

\subsubsection{A large example illustrating the complete algorithm}
\begin{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-complete-large-example-1}
\end{problem}
\input{../../modules/partial-fractions/homework/integration-rational-functions-complete-large-example-1-solution}
\section{Trigonometric integrals}\label{secTrigonometricIntegrals}
\begin{problem}
\input{../../modules/trig-integrals/homework/sinn-cosm-1}
\end{problem}

\begin{problem}
\input{../../modules/trig-integrals/homework/sin-cos-1}
\end{problem}

\begin{problem}
\input{../../modules/trig-integrals/homework/tan-sec-1}
\end{problem}

\begin{problem}
\input{../../modules/trig-integrals/homework/trig-integrals-collection-1}
\end{problem}
\subsection{Trigonometric integrals solved via general method $x=2\arctan t$}
\begin{problem}
\input{../../modules/trig-integrals/homework/rationalizing-substitution-1}
\end{problem}
\input{../../modules/trig-integrals/homework/rationalizing-substitution-1-solutions}

\section{Integrals of the form $R(x, \sqrt{ax^2+bx+c})$} \label{secIntegrationRadicalsQuadratics}
\subsection{Transforming radicals of quadratics to the forms $\sqrt{u^2+1}$, $\sqrt{1-u^2}$, $\sqrt{u^2-1}$}
\begin{problem}
\input{../../modules/trig-substitution/homework/prepare-radical-of-quadratic-for-integration-complete-square}
\end{problem}
\input{../../modules/trig-substitution/homework/prepare-radical-of-quadratic-for-integration-complete-square-solutions}

\subsection{Trig or Euler substitution, solutions use trig substitution}\label{secTrigSubstitution}
\subsubsection{Case 1: $\sqrt{x^2+1}$}
\begin{problem}
\input{../../modules/trig-substitution/homework/trig-substitution-tan-sec-1}
\end{problem}
\input{../../modules/trig-substitution/homework/trig-substitution-tan-sec-1-solutions}

\subsubsection{Case 2: $\sqrt{1-x^2}$}
\begin{problem}
\input{../../modules/trig-substitution/homework/trig-substitution-sin-cos-1}
\end{problem}
\input{../../modules/trig-substitution/homework/trig-substitution-sin-cos-1-solutions}

\subsection{Trig or Euler substitution, solutions use Euler substitution}
\subsubsection{Case 1: $\sqrt{x^2+1}$}\label{secEulerSubstitutions}

\begin{problem}
\input{../../modules/trig-substitution/homework/integration-euler-substitution-case1}
\end{problem}
\input{../../modules/trig-substitution/homework/integration-euler-substitution-case1-solutions}
\begin{problem}
\input{../../modules/trig-substitution/homework/integration-euler-substitution-case1-integral-radical-quadratic}
\end{problem}
\subsubsection{Case 2: $\sqrt{1-x^2}$}
\begin{problem}
\input{../../modules/trig-substitution/homework/integration-euler-substitution-case2}
\end{problem}
\input{../../modules/trig-substitution/homework/integration-euler-substitution-case2-solutions}

\subsubsection{Case 3: $\sqrt{x^2-1}$}
\begin{problem}
\input{../../modules/trig-substitution/homework/integration-euler-substitution-case3}
\end{problem}
\input{../../modules/trig-substitution/homework/integration-euler-substitution-case3-solutions}

\subsection{Theory through problems (Optional material)}
\subsection{Case 1: $\sqrt{x^2+1}$}
\subsubsection{$x=\cot \theta$}
\begin{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-cot}
\end{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-cot-solution}

\begin{problem}
\input{../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-cot}
\end{problem}

\input{../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-cot-solution}

\subsubsection{$x=\tan \theta$}
\begin{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-tan}
\end{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-tan-solution}
\begin{problem}
\input{../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-tan}
\end{problem}

\subsection{Case 2: $\sqrt{1-x^2}$}
\subsubsection{$x=\cos \theta$}
\begin{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-cos}
\end{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-cos-solution}

\begin{problem}
\input{../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-cos}
\end{problem}

\input{../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-cos-solution}

\subsubsection{$x=\sin \theta$}
\begin{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-sin}
\end{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-sin-solution}

\begin{problem}
\input{../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-sin}
\end{problem}

\subsection{Case 3: $\sqrt{x^2-1}$}
\subsubsection{$x=\sec \theta$}
\begin{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-sec}
\end{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-sec-solution}

\begin{problem}
\input{../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-sec}
\end{problem}

\input{../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-sec-solution}

\subsubsection{$x=\csc \theta$}
\begin{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-csc}
\end{problem}
\input{../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-csc-solution}

\begin{problem}
\input{../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-csc}
\end{problem}
\section{L'Hospital's rule}\label{secLHospitalsRule}

\begin{problem}
\input{../../modules/lhospital/homework/lhospital-rule-coming-from-Maclaurin-series-1}
\end{problem}
\input{../../modules/lhospital/homework/lhospital-rule-coming-from-Maclaurin-series-1-solutions}

\begin{problem}
\input{../../modules/lhospital/homework/lhospital-rule-collection-1}
\end{problem}

\subsection{The number $e$ as a limit}
\begin{problem}
\input{../../modules/logarithms/homework/e-as-a-limit-problems-2}
\end{problem}
\input{../../modules/logarithms/homework/e-as-a-limit-problems-2-solutions}
\begin{problem}
\input{../../modules/logarithms/homework/e-as-a-limit-problems}
\end{problem}
\begin{problem}
\input{../../modules/logarithms/homework/e-as-a-limit-and-compound-interest}
\end{problem}
\input{../../modules/logarithms/homework/e-as-a-limit-and-compound-interest-solutions}

\begin{problem}
\input{../../modules/logarithms/homework/e-as-a-limit-various-interesting-problems}
\end{problem}
\section{Improper Integrals}\label{secImproperIntegrals}
\begin{problem}
\input{../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-1}
\end{problem}
\input{../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-1-solutions}

\begin{problem}
\input{../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-2}
\end{problem}
\begin{problem}
\input{../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-3}
\end{problem}
\input{../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-3-solutions}

\begin{problem}
\input{../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-4}
\end{problem}

\section{Curves}\label{secCurves}
\begin{problem}
\input{../../modules/parametric-curves/homework/match-x-t-and-y-t-graph-to-x-y-graph-1}
\end{problem}
\subsection{Curves in polar coordinates}
\begin{problem}
\input{../../modules/polar-curves/homework/match-polar-curve-graph-to-formula}
\end{problem}
\begin{problem}
\input{../../modules/polar-curves/homework/sketch-the-curve-1}
\end{problem}
\input{../../modules/polar-curves/homework/sketch-the-curve-1-solutions}
\subsection{Curve tangents}
\begin{problem}
\input{../../modules/parametric-curves/homework/find-horizontal-vertical-tangents}
\end{problem}
\begin{problem}
\input{../../modules/parametric-curves/homework/show-multiple-tangents}
\end{problem}
\subsection{Curve lengths}\label{secCurveLength}
\begin{problem}
\input{../../modules/parametric-curves/homework/curve-length-1}
\end{problem}
\input{../../modules/parametric-curves/homework/curve-length-1-solutions}

\begin{problem}
\input{../../modules/parametric-curves/homework/curve-length-2}
\end{problem}
\subsection{Area under curve}
\begin{problem}
\input{../../modules/parametric-curves/homework/area-under-curve-1}
\end{problem}
\subsection{Area locked by curve}\label{secAreaLockedByPolarCurve}
\begin{problem}
\input{../../modules/polar-curves/homework/area-locked-by-curve-1}
\end{problem}
\input{../../modules/polar-curves/homework/area-locked-by-curve-1-solutions}

\begin{problem}
\input{../../modules/polar-curves/homework/area-locked-by-curve-2}
\end{problem}

\section{Sequences}\label{secSequences}
\subsection{Understanding sequence notation}
\begin{problem}
\input{../../modules/sequences/homework/guess-sequence-formula-1}
\end{problem}
\begin{problem}
\input{../../modules/sequences/homework/sequence-list-sequence-recursive-terms-1}
\end{problem}
\begin{problem}
\input{../../modules/sequences/homework/sequence-list-sequence-terms-1}
\end{problem}

\subsection{Convergence}
\begin{problem}
\input{../../modules/sequences/homework/convergent-or-divergent-sequence-1}
\end{problem}
\input{../../modules/sequences/homework/convergent-or-divergent-sequence-1-solutions}
\begin{problem}
\input{../../modules/sequences/homework/convergent-or-divergent-sequence-2}
\end{problem}
\section{Series}\label{secSeries}
\subsection{Some explicit series summations}
\subsubsection{Geometric series}\label{secGeometricSeries}
\begin{problem}
\input{../../modules/series/homework/express-infinite-decimal-as-rational-1}
\end{problem}
\input{../../modules/series/homework/express-infinite-decimal-as-rational-1-solutions}

\begin{problem}
\input{../../modules/series/homework/geometric-series-sum-1}
\end{problem}
\input{../../modules/series/homework/geometric-series-sum-1-solutions}
\subsubsection{Telescoping series}\label{secTelescopingSeries}
\begin{problem}
\input{../../modules/series/homework/telescoping-series-2}
\end{problem}
\input{../../modules/series/homework/telescoping-series-2-solutions}
\begin{problem}
\input{../../modules/series/homework/telescoping-series-1}
\end{problem}
\input{../../modules/series/homework/telescoping-series-1-solutions}

\subsection{Series convergence tests}
\subsubsection{Basic tests}\label{secBasicSeriesDivergenceTests}
\begin{problem}
\input{../../modules/series/homework/series-basic-tests-1}
\end{problem}
\input{../../modules/series/homework/series-basic-tests-1-solutions}

\subsubsection{Integral and comparison tests}\label{secSeriesComparisonAndIntegralTest}

\begin{problem}
\input{../../modules/series/homework/series-integral-or-comparison-test-1}
\end{problem}
\input{../../modules/series/homework/series-integral-or-comparison-test-1-solutions}

\subsubsection{Root, ratio tests}\label{secSeriesRootRatioTests}
\begin{problem}
\input{../../modules/series/homework/series-ratio-and-or-root-test-2}
\end{problem}
\input{../../modules/series/homework/series-ratio-and-or-root-test-2-solutions}

\begin{problem}
\input{../../modules/series/homework/convergence-x-to-the-nth-n-factorial-div-n-to-the-n-th}
\end{problem}
\subsection{Problems collection, all techniques}
\begin{problem}
\input{../../modules/series/homework/series-convergent-or-divergent-all-techniques-1}
\end{problem}

\section{Power series, Taylor and Maclaurin series}\label{PowerSeries}
\subsection{Interval of convergence}\label{secIntervalOfConvergence}
\begin{problem}
\input{../../modules/power-series/homework/interval-of-convergence-1}
\end{problem}
\input{../../modules/power-series/homework/interval-of-convergence-1-solutions}

\subsection{Taylor, Maclaurin series}\label{secTaylorMaclaurinSeries}
\begin{problem}
\input{../../modules/power-series/homework/find-maclaurin-series-1}
\end{problem}
\begin{problem}
\input{../../modules/power-series/homework/find-maclaurin-series-4}
\end{problem}
\begin{problem}
\input{../../modules/power-series/homework/find-maclaurin-series-5}
\end{problem}
\input{../../modules/power-series/homework/find-maclaurin-series-5-solutions}
\begin{problem}
\input{../../modules/power-series/homework/newton-binomial-integer-generalized}
\end{problem}
\input{../../modules/power-series/homework/newton-binomial-integer-generalized-solution}
\begin{problem}
\input{../../modules/power-series/homework/newton-binomial-generalized}
\end{problem}
\input{../../modules/power-series/homework/newton-binomial-generalized-solution}

\begin{problem}
\input{../../modules/power-series/homework/find-maclaurin-series-6}
\end{problem}
\input{../../modules/power-series/homework/find-maclaurin-series-6-solutions}

\begin{problem}
\input{../../modules/power-series/homework/find-taylor-series-1}
\end{problem}
\input{../../modules/power-series/homework/find-taylor-series-1-solutions}

\begin{problem}
\input{../../modules/power-series/homework/find-taylor-series-2}
\end{problem}
\subsection{Example of differentiable function not equal to its Maclaurin series}

\begin{problem}
\input{../../modules/power-series/homework/example-non-zero-function-with-zero-maclaurin-series}
\end{problem}

\section{Complex numbers}
\begin{problem}
\input{../../modules/complex-numbers/homework/complex-number-arithmetics-1}
\end{problem}
\input{../../modules/complex-numbers/homework/complex-number-arithmetics-1-solutions}

\begin{problem}
\input{../../modules/complex-numbers/homework/plot-complex-number-find-principal-argument-1}
\end{problem}
\input{../../modules/complex-numbers/homework/plot-complex-number-find-principal-argument-1-solutions}

\begin{problem}
\input{../../modules/complex-numbers/homework/find-nth-root-1}
\end{problem}
\input{../../modules/complex-numbers/homework/find-nth-root-1-solutions}
\begin{problem}
\input{../../modules/complex-numbers/homework/polar-form-complex-numbers-1}
\end{problem}
\begin{problem}
\input{../../modules/complex-numbers/homework/trig-identities-via-Euler-formula-1}
\end{problem}

\section{(Topic not covered as of Spring 2016) A Bit of Differential Equations  }

\subsection{Separable Differential equations}
\subsubsection{The Mixing Problem}
\begin{problem}
\input{../../modules/diff-eq-separable/homework/mixing-problem-1}
\end{problem}
\input{../../modules/diff-eq-separable/homework/mixing-problem-1-solution}

\subsubsection{General Separable Problems}
\begin{problem}
\input{../../modules/diff-eq-separable/homework/separable-DFQs-1}
\end{problem}
\input{../../modules/diff-eq-separable/homework/separable-DFQs-1-solution}

\end{document}


\section{Background}
\subsection{Word Embedding and The CBOW model}
Word embeddings, also referred to as distributed representations of words, is a more complex representation of words than the simpler way of letting words be represented by its index in the dictionary of words. Learning the meaning of words have demanded a better representation which can more effectively capture the the relationships of the words and its dimensionality. Word embedding achieves this by having each word represented by a real vector, and therefore maps each word into a multi-dimensional continuous space. In accordance to the distributional hypothesis, words which are used in similar contexts, and therefore have similar vector representations, should be mapped close to each other in the vector space, since they have similar meanings. One of the most basic and widely used models is the Continuous Bag of Word (CBOW) model as described in [4], which takes a context of words as input and computes the most likely target word in that context. The context words are encoded as 1-of-V vectors, where V is the size of the vocabulary, and these vectors are then averaged into one final context vector to be multiplied by the trained weight matrix of the network [4]. In other words, the order of the context words is lost and they are treated as a bag of words.


\section{Typing}
\label{sec:typing}

\langname is a strictly typed language, in which every term should have a
type in order to be wellformed and evaluated. Typing judgement of the form
$\Der{\Gamma}{e : T}$ say that $e$ is a term of type $T$ in the typing
context $\Gamma$.

\begin{figure}[h]
\input{figures/fig_typing.tex}
\caption{Typing rules of \langname}
\label{fig:typing}
\end{figure}

Note that each well-typed term has exactly one type hence we assume there
exists a funcion $termType: Term \to \mathcal{T}$ which relates each well-typed
term with the corresponding type.

Primitive operations can be parameterized with type variables, for example
addition (Table~\ref{table:primops}) has the signature $+~:~ (T,T) \to T$
where $T$ is numeric type (Table~\ref{table:predeftypes}). Function $ptype$, defined in Appendix~\ref{sec:appendix:primops} returns a type of primitive operation specialized for concrete types of its arguments, for example $ptype(+,\lst{Int}, \lst{Int}) = (\lst{Int}, \lst{Int}) \to \lst{Int}$.

Similarily, the function $mtype$ returns a type of method specialized for concrete types of the arguments of the \lst{MethodCall} term.

\lst{BlockExpr} rule defines a type of well-formed block expression. It
assumes a total ordering on \lst{val} definitions. If a block expression is
not well-formed than is cannot be typed and evaluated.

The rest of the rules are standard for typed lambda calculus.