%!TEX root = ../main.tex
%-------------------------------------------------------------------------------
\section{Example}\label{Example}
%-------------------------------------------------------------------------------
We now present an exemplifying analysis of a canonical EKW model on human capital investment. The model was initially studied in \citet{Keane.1997} to explore the career decisions of young men about their schooling, work, and occupational choice. We first outline the basic setup of the model, provide some descriptive statistics of the empirical data used for its calibration, and then explore selected economic insights.
%-------------------------------------------------------------------------------
\subsection{Basic setup}
%-------------------------------------------------------------------------------
We follow individuals over their working life from young adulthood at age 16 to retirement at age 65 where the decision period $t = 16, \dots, 65$  is a school year. \autoref{Decision tree} %
%\comment[id=HG]{I would use different colors in \autoref{Decision tree}: white background for ``white-collar jobs'' and brown for ``military''.}
illustrates the initial decision problem as individuals decide $a\in\mathcal{A}$ whether to work in a blue-collar or white-collar occupation ($a = 1, 2$), to serve in the military $(a = 3)$, to attend school $(a = 4)$, or to stay at home $(a = 5)$.

%
\begin{figure}[t!]\centering
	\scalebox{0.75}{%
		%\input{../material/fig-decision-tree-bw}%
		\input{../material/fig-decision-tree-bw}%
	}
	\caption{Decision tree}
	\label{Decision tree}
\end{figure}%\FloatBarrier%\vspace{1.0cm}
%

Individuals are already heterogeneous when entering the model. They differ with respect to their level of completed schooling $h_{16}$ and have one of four different $\mathcal{J} = \{1, \hdots, 4\}$ alternative-specific skill endowments $\bm{e} = \left(e_{j,a}\right)_{\mathcal{J} \times \mathcal{A}}$.

The immediate utility $u(\cdot)$ of each alternative consists of a non-pecuniary utility $\zeta_a(\cdot)$ and, at least for the working alternatives, an additional wage component $w_a(\cdot)$. Both depend on the level of human capital as measured by their occupation-specific work experience $\bm{k}_t = \left(k_{a,t}\right)_{a\in\{1, 2, 3\}}$, years of completed schooling $h_t$, and alternative-specific skill endowment $\bm{e}$. The immediate utilities are influenced by last-period choices $a_{t -1}$ and alternative-specific productivity shocks $\bm{\epsilon_t} = \left(\epsilon_{a,t}\right)_{a\in\mathcal{A}}$ as well. Their general form is given by:

%
\begin{align*}
u(\cdot) =
\begin{cases}
    \zeta_a(\bm{k}_t, h_t, t, a_{t -1})  + w_a(\bm{k}_t, h_t, t, a_{t -1}, e_{j, a}, \epsilon_{a,t})
    & \text{if}\quad a \in \{1, 2, 3\}  \\
    \zeta_a(\bm{k}_t, h_t, t, a_{t-1}, e_{j,a}, \epsilon_{a,t})
    & \text{if}\quad a \in \{4, 5\}
\end{cases}.
\end{align*}
%
\noindent Work experience $\bm{k}_t$  and years of completed schooling $h_t$ evolve deterministically.
%
\begin{align*}
k_{a,t+1} & = k_{a,t} + \ind[a_t = a] \quad \text{if}\quad a \in \{1, 2, 3\} \\
h_{t + 1\phantom{,a}} & = h_{t\phantom{,a}} +   \ind[a_t = 4].
\end{align*}
%
The productivity shocks $\bm{\epsilon}_t$ are uncorrelated across time and follow a multivariate normal distribution with mean $\bm{0}$ and covariance matrix $\bm{\Sigma}$. Given the structure of the utility functions and the distribution of the shocks, the state at time $t$ is $s_t = \{\bm{k}_t, h_t, t, a_{t -1}, \bm{e},\bm{\epsilon}_t\}$.

Theoretical and empirical research from specialized disciplines within economics informs the specification of each $u_a(\cdot)$ and we discuss the exact functional form of the per-period utility in the blue-collar occupation as an example.\footnote{All additional details are available in Appendix \ref{Computational implementation}.}

Equation~\eqref{Non-pecuniary benefits} shows the parameterization of the non-pecuniary utility from working in a blue-collar occupation:
%
\begin{align}\label{Non-pecuniary benefits}
\zeta_{1}(\bm{k}_t, h_t, a_{t-1})  = \alpha_1  &+ c_{1,1} \cdot \ind[a_{t-1} \neq 1] + c_{1,2} \cdot \ind[k_{1,t} = 0] \\ \nonumber
                            & + \vartheta_1 \cdot \ind[h_t \geq 12] + \vartheta_2 \cdot \ind[h_t \geq 16] + \vartheta_3 \cdot \ind[k_{3,t} = 1].
\end{align}
%
It includes job amenities $\alpha_1$ and mobility and search costs $(c_{1,1}, c_{1,2})$ that capture the extra effort for individuals who only recently started working in a blue-collar occupation. Additional components depend on whether an individual has a high school $\vartheta_1$ or college $\vartheta_2$ degree. There is a detrimental impact of leaving the military after a single year $\vartheta_3$.

The wage component $w_{1}(\cdot)$ is given by the product of the market-equilibrium rental price $r_{1}$ and an occupation-specific skill level $x_{1}(\cdot)$. The latter is determined by the overall level of human capital. This specification leads to a standard logarithmic wage equation in which the constant term is the skill rental price $\ln(r_{1})$ and wages follow a log-normal distribution.

The occupation-specific skill level $x_{1}(\cdot)$ is determined by a skill production function, which includes a deterministic component $\Gamma_1(\cdot)$ and a multiplicative stochastic productivity shock $\epsilon_{1,t}$:
%
\begin{align}
    x_{1}(\bm{k}_t, h_t, t, a_{t-1}, e_{j, 1}, \epsilon_{1,t}) & = \exp \big( \Gamma_{1}(\bm{k}_t,  h_t, t, a_{t-1}, e_{j,1}) \cdot \epsilon_{1,t} \big). \nonumber
\end{align}
%
\noindent Equation (\ref{Skill production function}) shows the parameterization of the deterministic component of the skill production function:
%
\begin{align}\label{Skill production function}
    \Gamma_1(\bm{k}_t, h_t, t, a_{t-1}, e_{j, 1}) = e_{j,1} & + \beta_{1,1} \cdot h_t + \beta_{1, 2} \cdot \ind[h_t \geq 12]   \\ \nonumber
                                  & + \gamma_{1, 1} \cdot  k_{1,t} + \gamma_{1,2} \cdot  (k_{1,t})^2  \\ \nonumber
                                & + \gamma_{1,3} \cdot  \ind[k_{1,t} > 0] + \gamma_{1,4} \cdot  t + \gamma_{1,5} \cdot \ind[t < 18]\\
                                  & + \gamma_{1,6} \cdot \ind[a_{t-1} = 1] + \gamma_{1,7} \cdot  k_{2,t} + \gamma_{1,8} \cdot  k_{3,t}. \nonumber
\end{align}

\noindent There are several notable features. Skills increase with schooling $\beta_{1,1}$ and blue-collar work experience ($\gamma_{1,1}, \gamma_{1,2}$). There are so-called sheep-skin effects \citep{Hungerford.1987, Jaeger.1996} associated with completing a high school $\beta_{1,2}$ and graduate $\beta_{1,3}$ education that capture the impact of completing a degree beyond just the associated years of schooling. Also, there is a first-year blue-collar experience effect $\gamma_{1,3}$ while skills depreciate when not employed in a blue-collar occupation in the preceding period $\gamma_{1,6}$. Other work experience ($\gamma_{1,7}, \gamma_{1,8}$) is transferable.
%-------------------------------------------------------------------------------
\subsection{Empirical data}
%-------------------------------------------------------------------------------
We analyze the original dataset used by \citet{Keane.1997} and thus only provide a brief description here.\footnote{We provide additional details in Appendix \ref{Empirical data}.} The authors construct their sample based on the National Longitudinal Survey of Youth 1979 (NLSY79) \citep{NLSY.2019}. The NLSY79 is a nationally representative sample of young men and women living in the United States in 1979 and born between 1957 and 1964. Individuals were followed from 1979 onwards and repeatedly interviewed about their schooling decisions and labor market experiences. Based on this information, individuals are assigned to either working in one of the three occupations, attending school, or simply staying at home.

\citet{Keane.1997} restrict attention to white males that turn 16 between 1977 and 1981 and exploit the information collected between 1979 and 1987. Thus individuals in the sample are all between 16 and 26 years old. While the sample initially consists of 1,373 individuals at age 16, this number drops to 256 at the age of 26 due to sample attrition, missing data, and the short observation period. Overall, the final sample consists of 12,359 person-period observations.

\autoref{Overview} summarizes our information about choices and wages by age. We show the distribution of choices on the left, and report average wages on the right. Initially, roughly 86\% of individuals enroll in school, but this share steadily declines with age. Nevertheless, about 39\% obtain more than a high school degree and continue their schooling for more than twelve years. As individuals leave school, most of them initially pursue a blue-collar occupation. But the relative share of the white-collar occupation increases as individuals entering the labor market later have higher levels of schooling. At age 26, about 48\% work in a blue-collar occupation and 34\% in a white-collar occupation. The share of individuals in the military peaks around age 20 when it amounts to 8\%. At its maximum around age 18, approximately 20\% of individuals stay at home.

%
\begin{figure}[t!]\centering
\caption{Data overview}\label{Overview}
\subfloat[Choices]{\scalebox{0.19}{\includegraphics{fig-data-choice-all-bw}}}\hspace{0.3cm}
\subfloat[Average wage]{\scalebox{0.19}{\includegraphics{fig-data-wage-occupations-bw}}}
\begin{center}
\begin{minipage}[t]{0.8\columnwidth}
\item \scriptsize{\textbf{Notes:} The wage is a full-time equivalent deflated by the gross national product deflator, with 1987 as the base year. We do not report the wage if less than ten observations are available.}
\end{minipage}
\end{center}
\end{figure}%\FloatBarrier
%

Overall, average wages start at about \$10,000 at age 16 but increase considerably up to about \$25,000 at age 26. While wages in the blue-collar occupation are initially highest with about \$10,286, wages in the white-collar occupation and military start around \$9,000. However, wages in the white-collar occupation increase steeper over time and overtake blue-collar wages around age 21. At the end of the observation period, wages in the white-collar occupation are about 50\% higher than blue-collar wages with \$32,756 as opposed to only \$20,739. Military wages remain lowest throughout.

We fit the model to the empirical data using maximum likelihood calibration. Figure \ref{Model fit} shows the overall agreement between the empirical data and a dataset simulated using the calibrated parameters within the support of the data. On the left, we show the choice probability of working in a blue-collar occupation, while we plot the average wage across all occupations on the right.

%
\begin{figure}[t!]\centering
\caption{Model fit}\label{Model fit}
\subfloat[Blue-collar]{\scalebox{0.19}{\includegraphics{fig-model-fit-choice-blue-bw}}}\hspace{0.3cm}
\subfloat[Average wage]{\scalebox{0.19}{\includegraphics{fig-model-fit-wage-all-bw}}}
\begin{center}
\begin{minipage}[t]{0.7\columnwidth}
\item \scriptsize{\textbf{Notes:} We simulate a sample of 1,000 individuals using the calibrated model.}
\end{minipage}\end{center}
\end{figure}%\FloatBarrier
%

Overall, the values of the calibrated parameters of the model are in broad agreement with the relevant literature. For example, individuals discount future utilities by $6\%$ per year, and wages increase by about $7\%$ with each additional year of schooling.
%-------------------------------------------------------------------------------
\subsection{Economic insights}
%-------------------------------------------------------------------------------
\autoref{Economic mechanism and policy forecast} illustrates the ability of the model to quantify the impact of economic mechanisms and to forecast the effect of public policies. On the left, we vary the discount factor capturing time preferences between $0.91$ and $0.95$ while we introduce a tuition subsidy of up to $\$4{,}000$ on the right. In both cases, we are interested in the changes to average final schooling.

Increases in the discount factor and the tuition subsidy both result in higher average final schooling. However, they do so for very different reasons. While individuals emphasize the future benefits of their schooling investment in the former, they react to a reduction of its immediate cost in the latter.

\begin{figure}[h!]\centering
	\caption{Economic mechanism and policy forecast}\label{Economic mechanism and policy forecast}
	\subfloat[Time preference]{\scalebox{0.19}{\includegraphics{fig-economic-mechanism-bw}}}\hspace{0.3cm}
	\subfloat[Tuition subsidy]{\scalebox{0.19}{\includegraphics{fig-policy-forecast-bw}}}
	\begin{center}
		\begin{minipage}[t]{0.675\columnwidth}
			\item \scriptsize{\textbf{Notes:} We simulate a sample of 1,000 individuals using the calibrated model.}
		\end{minipage}
	\end{center}
\end{figure}%\FloatBarrier


\documentclass{article}
\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{November 20, 2013}
\maketitle
\section*{exam 2}
4.4 has 1 problem for 20 points
4.7 has one problem for 20 points
5.1 has 1 problem for 10 points
8.1-8.3 has one point (technically from 8.3) for 20 points
8.5 has one problem for 30 points

most should be similar to class problems, one is exactly the same as in class even

\section*{section 5.1}
determine the spring constant of the spring with natural length 10 in that is stretched to a distance 13 in by an object weighing 5 lb
\begin{align*}
    m\frac{\mathrm{d}^2x}{\mathrm{d}t^2}+kx&=0\\
    x(0)&=\alpha\\
    x'(0)&=\beta
\end{align*}
\subsection*{solution}
``English'' units
\begin{align*}
    s&=3\text{in}\\
    &=\frac{3}{12}\text{ft}=\frac{1}{4}\text{ft}\\
    F&=ks\\
    5&=k\frac{1}{4}\\
    k&=20\text{lb/ft}\\
    F&=mg\\
    5&=m32\\
    m&=\frac{5}{32}\text{slug}
\end{align*}
\section*{random question example}
\begin{align*}
    \mathcal{L}^{-1}\left\{\frac{4s}{(s^2+16)^2}\right\}\\
    \sin 4t &\to \frac{4}{s^2+16}\\
    t\sin 4t &\to -\frac{\mathrm{d}}{\mathrm{d}x}(\frac{4}{s^2+16})\\
    &=\frac{4(2s)}{(s^2+16)^2}\\
    &=\frac{8s}{(s^2+16)^2}\\
    \mathcal{L}\{t^nf(t)&=(-1)^n\frac{\mathrm{d}^nF}{\mathrm{d}s^n}\}\\
    \frac{1}{2}t\sin 4t&\to \frac{4s}{(s^2+16)^2}
\end{align*}
\end{document}


\section{Specification Model}
\label{sec:performance-modeling-specification-model}
The typical modeling workflow requires to specify
(i) the statistical analysis of data collected from the real system in order to determine the input model to drive simulations,
(ii) the analytical model and equations to determine performance metrics,
(iii) the adopted simulation approach and
(iv) the algorithms involved in computations.

\paragraph{Statistical specifications}
We have been provided with the statistical characterization of the target system.
Tasks belonging to the $i$-th class arrive to the system according to an exponential arrival process with rate $ \lambda_{i}$.
The Cloudlet serves tasks belonging to the $i$-th class according to an exponential service process with rate $\mu_{clt,i}$.
The Cloud serves tasks belonging to the $i$-th class according to an exponential service process with rate $\mu_{cld,i}$.
We assume that
(i) $\mu_{clt,i}>\mu_{cld,i}\ \forall i=1,2$ and
(ii) the setup time $T_{setup}$ is exponentially distributed with expected value $E[T_{setup}]$.

In particular, we consider values shown in Equations~\ref{eqn:statistical-specifications}.

\begin{equation}
\begin{split}
\lambda_{1}  &=6.00\;tasks/sec \\
\lambda_{2}  &=6.25\;tasks/sec \\
\mu_{clt,1}  &=0.45\;tasks/sec \\
\mu_{clt,2}  &=0.27\;tasks/sec \\
\mu_{cld,1}  &=0.25\;tasks/sec \\
\mu_{cld,2}  &=0.22\;tasks/sec \\
E[T_{setup}] &=0.8\;sec \\
\end{split}
\label{eqn:statistical-specifications}
\end{equation}

\paragraph{Analytical Model}
Given the importance and complexity of the analytical model, we preferred to reserve the whole Section~\ref{sec:analytical-model} to present it.

\paragraph{Simulation Approach}
We decided to adopt the \textit{next-event simulation method}, which is the most effective discrete-event technique in terms of algorithmic modeling, time management and computational requirements.

\paragraph{Algorithmic specifications}
From the point of view of algorithms involved in the simulation, we need to specify:

\begin{itemize}

	\item \textit{Off-Loading Algorithm}: defines the off-loading policy implemented by the \textit{Cloudlet Controller (CTRL)}.
	%
	The first policy, defined in Algorithm~\ref{alg:off-loading-policy-1}, makes no distinction between classes of tasks, which are all served by the Cloudlet as long as it has available resources.
	%
	The second policy, defined in Algorithm~\ref{alg:off-loading-policy-2}, gives higher priority to the $1^{st}$ class tasks by
	(i) accepting in Cloudlet at most $S$ $2^{nd}$ class tasks and
	(ii) freeing up Cloudlet resources occupied by the $2^{nd}$ class tasks in favor of $1^{st}$ class tasks restarting the former on Cloud.
	Notice that the threshold $S$ plays a key role here.
	On one hand, a high $S$ increases the opportunity for  $2^{nd}$ class tasks to be served by the Cloudlet, that is faster than the Cloud.
	On the other hand, a high $S$ increases also the risk for $2^{nd}$ class tasks to incur in the overhead caused by the restart in Cloud.

	\item \textit{Simulation Algorithm}: defines the main execution flow of the simulator, as specified in Algorithm~\ref{alg:simulation-workflow}.
\end{itemize}

With reference to the simulation algorithm, it is worth focusing on the following aspects:

\begin{itemize}

	\item \textit{event generation}: a new \textit{arrival event} is generated every time an arrival is processed and the closed-door condition does not hold. We adopted Algorithm~\ref{alg:arrivals} to generate classed arrivals, whose statistical correctness relies on the properties of the exponential distribution.
	%
	A new \textit{completion event} is generated every time an arrival is processed.
	%
	A new \textit{interruption event} is generated when an arrival is processed and the Cloudlet Controller determines that a task must be interrupted in the Cloudlet and restarted in the Cloud~\footnote{the generation of interruption events is possible only when Off-Loading Policy 2 is adopted.}.
	%
	Notice that the interruption event is never mentioned in the simulation workflow in Algorithm~\ref{alg:simulation-workflow}; this is because the interruption event is not an external arrival, but an internal task switching between subsystems.

	\item \textit{event submission}: when a new event is submitted to the system, the simulator updates (i) the system state and (ii) the simulation counters, e.g. number of arrivals, number of completions and so on.

	\item \textit{closed-door condition}: when this condition holds true, no more arrivals will be generated and system will only handle remaining completion events until it reaches the idle state.
	This condition is crucial because it identifies the point in time when the simulator has collected enough data to achieve our goals.
	To this aim, this condition holds true when the simulator has collected the configured number of batches, i.e. 64 batches with 512 samples each.

	\item \textit{stop condition}: when this condition holds true, the simulation is terminated. The logical definition of this condition depends on whether the simulator is used for the performance analysis in the transient state or in the steady state.

	In transient analysis, the condition holds true when the simulation clock is greater than a given stop time because we want to study whether or not performance metrics to converge to stable values within the given amount of time.

	In performance analysis, the condition holds true when the closed-door condition does and the system has reached the idle state because we assume that the steady state exists and we want to collect enough data to generated meaningful confidence intervals.

	\item \textit{sampling condition}: when this condition holds true, performance metrics should be sampled.
	In particular, it holds true when the processed event is a completion.
	We did like this because
	(i) sampling, as any other operation within the simulator, should happen in correspondence of an event, by design, and
	(ii) a completion events brings a super set of insights w.r.t. an arrival.

	\item \textit{metrics management}: when an event is submitted to the system, all the simulation counters are updated, e.g. number of arrivals, service time, integral areas and so on.
	When the sampling condition holds true, those counters are used to compute a sample of performance metrics. Such a sample is then used to update performance statistics leveraging \textit{One-Pass Wellford algorithm, batch means and confidence intervals} with formulas and algorithms described in \cite{leemis2006discrete}.

	We decoupled counters updates and metrics sampling in this way in order to improve the simulator performances both in terms of timing and memory consumption.
	%
	In fact
	(i) the former is a low-effort operation that must be executed whenever a new event is processed,
	(ii) the latter is a higher-effort operation that should be executed in correspondence of the event type carrying the most complete set of information, i.e. completion events.
	%
	Furthermore, we preferred to compute metrics by executing metrics updates within the simulation loop rather than at the end of the simulation because in this way we can consume subsets of data points at every sampling operation rather than collecting all of them until the end, thus saving up memory.
\end{itemize}

\begin{algorithm}
	\SetAlgoLined
	\If{arrival of class 1 or class 2}{
		\eIf{$n_{clt,1}+n_{clt,2}=N$}{
			send to the Cloud
		}{
			accept on Cloudlet
		}
	}
	\caption{Off-Loading Policy 1 (OP1).}
	\label{alg:off-loading-policy-1}
\end{algorithm}

\begin{algorithm}
	\SetAlgoLined
	\If{arrival of class 1}{
		\If{$n_{clt,1}=N$}{
			send to the Cloud
		}
		\If{$n_{clt,1}+n_{clt,2}<S$}{
			accept on the Cloudlet
		}
		\eIf{$n_{clt,2} > 0$}{
			accept on the Cloudlet, interrupt a $2^{nd}$ class task in the Cloudlet and restart it in the Cloud
		}{
			accept on Cloudlet
		}
	}
	\If{arrival of class 2}{
		\eIf{$n_{clt,1}+n_{clt,2}>=S$}{
			send to the Cloud
		}{
			accept on the Cloudlet
		}
	}
	\caption{Off-Loading Policy 2 (OP2).}
	\label{alg:off-loading-policy-2}
\end{algorithm}

\begin{algorithm}
	\SetAlgoLined

	calendar.schedule\_arrival();

	\While{$\neg stop\_condition()$}{
		e = calendar.next\_event();

		\If{$e.type = completion$}{
			submit\_event(e);
		}

		\If{$e.type = arrival \land \neg close\_door\_condition()$}{
			e\_next = submit\_event(e);

			calendar.schedule(e\_next);

			calendar.schedule\_arrival();
		}

		update\_simulation\_counters();

		\If{$sampling\_condition()$}{
			sample = sampling();

			update\_metrics(sample);
		}
	}

\caption{Simulation Workflow.}
\label{alg:simulation-workflow}
\end{algorithm}

\begin{algorithm}
	\SetAlgoLined

	rndgen.select\_stream(ARRIVAL)

	$p_{1}=\frac{\lambda_{1}}{\lambda_{1}+\lambda_{2}}$

	u = rndgen.uniform(0.0,1.0)

	\eIf{$u\leq p_{1}$}{
		arrival\_type = TASK\_1

		rndgen.select\_stream(ARRIVAL\_TASK\_1)

		$t_{inter-arrival}$ = rndgen.exponential($\lambda_{1}$)
	}{
		arrival\_type = TASK\_2

		rndgen.select\_stream(ARRIVAL\_TASK\_2)

		$t_{inter-arrival}$ = rndgen.exponential($\lambda_{2}$)
	}

	$t_{arrival}=t_{last\_arrival}+t_{inter-arrival}$

	$t_{last\_arrival}=t_{arrival}$

	schedule(arrival\_type,$t_{arrival}$)
	\caption{Generation of arrivals.}
	\label{alg:arrivals}
\end{algorithm}


\documentstyle[12pt]{article}
\begin{document}
\begin{center} {\Large Polynomial Ideals} \end{center}
\begin{center} Arithmetic for polynomial ideals supported by
Gr\"obner bases \end{center}
\begin{center} Version 1.0 May 1992 \end{center}

\begin{center} Herbert Melenk \\ Konrad-Zuse-Zentrum f\"ur
Informationstechnik \\
Takustra\"se 7 \\ D14195 Berlin--Dahlem \\ Federal Republic of Germany \\
melenk@zib.de \\ May 1992 \end{center}

\section{Introduction}

This package implements the basic arithmetic for polynomial ideals
by exploiting the Gr\"obner bases package of REDUCE.
In order to save computing time all intermediate Gr\"obner bases
are stored internally such that time consuming repetitions
are inhibited. A uniform setting facilitates the access.

\section{Initialization}

Prior to any computation the set of variables has to be declared
by calling the operator $I\_setting$ . E.g. in order to initiate
computations in the polynomial ring $Q[x,y,z]$ call
\begin{verbatim}
    I_setting(x,y,z);
\end{verbatim}
A subsequent call to $I\_setting$ allows one to select another set
of variables; at the same time the internal data structures
are cleared in order to free memory resources.

\section{Bases}

An ideal is represented by a basis (set of polynomials) tagged
with the symbol $I$, e.g.
\begin{verbatim}
   u := I(x*z-y**2, x**3-y*z);
\end{verbatim}
Alternatively a list of polynomials can be used as input basis; however,
all arithmetic results will be presented in the above form. The
operator $ideal2list$ allows one to convert an ideal basis into a
conventional REDUCE list.

\subsection{Operators}

Because of syntactical restrictions in REDUCE, special operators
have to be used for ideal arithmetic:

\begin{verbatim}
         .+            ideal sum (infix)
         .*            ideal product (infix)
         .:            ideal quotient (infix)
         ./            ideal quotient (infix)
         .=            ideal equality test (infix)
         subset        ideal inclusion test (infix)
         intersection  ideal intersection (prefix,binary)
         member        test for membership in an ideal
                         (infix: polynomial and ideal)
         gb            Groebner basis of an ideal (prefix, unary)
         ideal2list    convert ideal basis to polynomial list
                         (prefix,unary)
\end{verbatim}

Example:

\begin{verbatim}
    I(x+y,x^2) .* I(x-z);

      2                      2    2
   I(X  + X*Y - X*Z - Y*Z,X*Y  - Y *Z)
\end{verbatim}

The test operators return the values 1 (=true) or 0 (=false)
such that they can be used in REDUCE $if-then-else$ statements
directly.

The results of $sum,product, quotient,intersction$ are ideals
represented by their Gr\"obner basis in the current setting and
term order. The term order can be modified using the operator
$torder$ from the Gr\"obner package. Note that ideal equality
cannot be tested with the REDUCE equal sign:

\begin{verbatim}

   I(x,y)  = I(y,x)       is false
   I(x,y) .= I(y,x)       is true

\end{verbatim}

\section{Algorithms}

The operators $groebner$, $preduce$ and $idealquotient$ of the
REDUCE Gr\"obner package support the basic algorithms:

$GB(Iu_1,u_2...) \rightarrow groebner(\{u_1,u_2...\},\{x,...\})$

$p \in I_1 \rightarrow p=0 \ mod \ I_1$

$I_1 : I(p) \rightarrow (I_1 \bigcap I(p)) / p \ elementwise$

\noindent
On top of these the Ideals package implements the following
operations:

$I(u_1,u_2...)+I(v_1,v_2...) \rightarrow GB(I(u_1,u_2...,v_1,v_2...))$

$I(u_1,u_2...)*I(v_1,v_2...)\rightarrow
 GB(I(u_1*v_1,u_1*v2,...,u_2*v_1,u_2*v_2...))$

$I_1 \bigcap I_2 \rightarrow
  Q[x,...] \bigcap GB_{lex}(t*I_1 + (1-t)*I_2,\{t,x,..\}) $

$I_1 : I(p_1,p_2,...) \rightarrow I_1 : I(p_1) \bigcap I_1 : I(p_2)
\bigcap ...$

$I_1 = I_2 \rightarrow GB(I_1)=GB(I_2)$

$I_1 \subseteq I_2
   \rightarrow \ u_i \in I_2 \ \forall \ u_i \in I_1=I(u_1,u_2...)$

\section{Examples}

Please consult the file $ideals.tst$.
\end{document}


\documentclass{beamer}

\usepackage{amsmath,amssymb,amsthm,graphicx}
\usepackage{caption,subcaption}
\usetheme{Copenhagen}
 \newcommand{\N}{\mathbb{N}}
 \newcommand{\Z}{\mathbb{Z}}
 \newcommand{\Q}{\mathbb{Q}}
 \newcommand{\R}{\mathbb{R}}
 \newcommand{\C}{\mathbb{C}}
 \newcommand{\bM}{\begin{bmatrix}}
 \newcommand{\eM}{\end{bmatrix}}
 \newcommand{\Ni}{\N\cup\{\infty\}}
  \newcommand{\rmD}[1]{\mathrm{d}#1}
\newcommand{\floor}[1]{\lfloor #1 \rfloor}
\title{Optimal Path Planning for Robotic Arms in Household Assistance}
\author{Vikram Sunder and Zachary Greenberg}

\begin{document}
\begin{frame}
\maketitle
\end{frame}

\section{Introduction}
\begin{frame}{The Robot}
\begin{itemize}
\item Irobot Create Base\\
\item 5-degree of freedom arm
\end{itemize}
\begin{figure}[htb]
\centering
\includegraphics[scale=.05]{PathPics/Robot_With_Arm.jpg}
\end{figure}
\end{frame}

\begin{frame}{The Problem}
Find the shortest path the arm should take to a point.\\
~\\
Explore different notions of ``shortest'' to get different paths.
\begin{itemize}
\item Euclidean Distance
\item Energy Required to Hold an Object
\item Kinetic Energy
\end{itemize}
\end{frame}
\begin{frame}{The Algorithm}
\begin{itemize}
\item Divide configuration space into a grid to make a graph.
\item We used $A^*$ to compute the shortest path in the graph.
\item Use different cost functions to simulate different metrics.
\item As long as the cost is at least the euclidean distance, then the euclidean distance to the target is an admissible heuristic.
\end{itemize}
\end{frame}
\begin{frame}{Kinematics}
Forward Kinematics is a mapping $FK$ from configuration space to work space.\\
The Jacobian $J$ is the derivative matrix for $FK$.\\
To get linear velocities from angular velocities $\dot{\theta}$ take $J\dot{\theta}$\\
The $J^T$ maps from workspace forces to torques. $\tau = J^TF$.\\
~\\
For our robot only the first 4 angles determine position.\\
In addition the first angle determines the plane the arm moves in. So we can solve for it first and only have to search 3 dimensional space for the path.
\end{frame}

\section{Results}
\begin{frame}{Euclidean Distance}
Compute distance between nodes in work space.\\
Considering the angle of the end effector gives a different path.
\begin{figure}[htb]
\centering
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[scale=.3]{PathPics/Basic_Path.jpg}
\caption{Orientation Path}
\end{subfigure}%
~
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[scale=.3]{PathPics/NoAlpha_Path.jpg}
\caption{No Orientation Path}
\end{subfigure}

\caption{Euclidean Distance Paths}
\label{fig:basicPaths}
\end{figure}

\end{frame}

\begin{frame}{Energy To Hold Up an Object (Next State)}
Add the energy to hold up an object of weight $m$ in the next state:\\
$$	d(u,v) =  \left\|(FK(u)-FK(v))\right\|^2 + \small\left\|J^T_v\bM 0 \\ 0 \\ mg \eM\right\|^2$$\normalsize
\begin{figure}[htb]
\centering
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[scale=.2]{PathPics/Wrench_Path.jpg}
\caption{Orientation Path}
\end{subfigure}%
~
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[scale=.2]{PathPics/Wrench_NoAlpha_Path.jpg}
\caption{No Orientation Path}
\end{subfigure}

\caption{Paths When Considering Energy To Hold Up an Object}
\label{fig:EnergyPaths1}
\end{figure}
\end{frame}

\begin{frame}{Energy to Hold Up an Object (Ratios)}
Using the ratio of torques between the states gives:
 $$	d(u,v) =  \left\|(FK(u)-FK(v))\right\|^2 + \Tiny\frac{\left\|J^T_v\bM 0 \\ 0 \\ mg \eM\right\|^2}{\left\|J^T_u\bM 0 \\ 0 \\ mg \eM\right\|^2}$$\normalsize
\begin{figure}[htb]
\centering
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[scale=.19]{PathPics/Wrench_Path.jpg}
\caption{Path When Only Considering The Next State}
\end{subfigure}%
~
\begin{subfigure}[b]{0.5\textwidth}
\centering
\includegraphics[scale=.19]{PathPics/Wrench_Ratio_Path.jpg}
\caption{Path When Considering a Ratio of Torques}
\end{subfigure}

\caption{Paths When Considering Energy To Hold Up an Object}
\label{fig:EnergyPaths2}
\end{figure}
\end{frame}
\begin{frame}{Kinetic Energy}
Let $J$ be the Jacobian. Let $\dot{\theta}$ be the angular velocity vector.
 \small\[E_{linear} = \frac{1}{2}m \|J_u\dot{\theta}\|^2\]. \\
\[E_{angular} = \frac{1}{2}m \left\|\frac{\Delta\theta_1+\Delta\theta_2+\Delta\theta_3)}{h}\right\|^2\]\normalsize
\begin{figure}[htb]
\centering
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[scale=.135]{PathPics/Energy_Linear_Path.jpg}
\caption{Linear Kinetic Engery Path}
\end{subfigure}%
~
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[scale=.135]{PathPics/Energy_Angular_Path.jpg}
\caption{Angular Kinetic Energy Path}
\end{subfigure}%
~
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[scale=.135]{PathPics/Energy_Kinetic_Path.jpg}
\caption{Total Kinetic Energy Path}
\end{subfigure}

\caption{Paths When Considering Kinetic Energy}
\label{fig:EnergyPaths2}
\end{figure}
\end{frame}

\section{Future Work}
\begin{frame}{Future Work}
\begin{itemize}
\item Consider other metrics\\
\begin{itemize}
\item Better angular kinetic energy metric
\item More accurate physics model of the arm
\end{itemize}
\item Using the robot base as part of the path finding
\item Increasing the grid size for smoother path
\item Move beyond simulation to the actual robot
\item Collision detection and obstacle avoidance
\end{itemize}
\end{frame}
\end{document}


\label{qft}
\begin{chapterbox}
\vspace{-60pt}
\chapter{Quantum Field Theory}
\vspace{-30pt}
\centering\normalsize\textit{Michaelmas Term 2017 - Professor B. Allanach}
\end{chapterbox}
\vspace{20pt}
%\begin{multicols*}{2}
\minitoc
\newpage
\section{Classical Field Theory}
\begin{definitionbox}
A field is a physical quantity defined at every point of spacetime $(\vec x, t)$. In field\index{field} theory we have a set of fields $\phi_a (\vec x, t)$, where both $\vec x$ and $a$ are labels, so there are an infinite number of degrees of freedom.
\end{definitionbox}
The dynamics of fields are governed by a Lagrangian\index{Lagrangian},
\begin{equation}
L = \int{\upd{^3 x} \mathcal{L}(\phi_a, \partial_\mu \phi_a)}
\end{equation}
where $\mathcal{L}$ is the Lagrangian density. Then the action is;
\begin{equation}
\mathcal{S} = \int_{t_0}^{t}{\upd{t} L} = \int{\upd{^4 x} \mathcal{L}(\phi_a, \partial_\mu \phi_a)}
\end{equation}
\subsection{Units}
We work in units where $c = \hbar = 1$ which implies that $\left[L\right] = \left[T\right] = \left[M\right]^{-1}$, so length and time are measured in units of inverse mass, or equivalently, energy. There are two things to note;
\begin{enumerate}
\item If a quantity $X$ has mass dimension $d$, then we say $X$ has dimension $d$
\item The action, $\mathcal{S}$ is dimensionless $\Rightarrow \left[\ud^4 x\right] = -4, \left[\mathcal{L}\right] = 4$
\end{enumerate}
\subsection{Dynamical Principles of Classical Field Theory}
Classical Field theory is built on the principle of stationary action; the fields evolve such that $\mathcal{S}$ is stationary with respect to variations in the fields;
\begin{dmath}
\delta \mathcal{S} = \sum_{a}{\int{\upd{^4 x} \left( \frac{\partial \mathcal{L}}{\partial \phi_a} \delta \phi_a +\frac{\partial \mathcal{L}}{\partial\left(\partial_\mu \phi_a \right)} \delta \left( \partial_\mu \phi_a \right)\right)}} = \sum_{a}{\int{\upd{^4 x} \left( \frac{\partial \mathcal{L}}{\partial \phi_a} \delta \phi_a - \partial_\mu \left(\frac{\partial \mathcal{L}}{\partial\left(\partial_\mu \phi_a \right)}\right) \delta  \phi_a \right) + \partial_\mu \left(\frac{\partial \mathcal{L}}{\partial\left(\partial_\mu \phi_a \right)} \delta \phi_a \right)}}
\end{dmath}
The last term vanishes for any Lagrangian that decays at spatial infinite and has $\delta \phi_a (\vec x, t_i) = \delta \phi_a (\vec x, t_f) = 0$. Thus $\delta \mathcal{S} = 0$ for all $\delta \phi_a$ gives us the Euler-Lagrange equations\index{equation!Euler-Lagrange} for the field:\footnote{For more on this, refer to Appendix \ref{sec:parttofield}.} \boxed{\textbf{I.i}}
\begin{equation}
\label{eq:EL}
\partial_\mu \left(\frac{\partial \mathcal{L}}{\del\left(\del_\mu \phi_a\right)}\right) - \frac{\partial \mathcal{L}}{\partial \phi_a} = 0
\end{equation}
As an example of this consider the Klein-Gordon field;
\begin{examplebox}[The Klein-Gordon Equation\index{equation!Klein-Gordon}]
Consider the Lagrangian;
\begin{equation*}
\mathcal{L} = \tfrac{1}{2}\etamn{^}\del_\mu \phi \del_\nu \phi - \tfrac{1}{2} m^2 \phi^2 = \tfrac{1}{2} \dot{\phi}^2 - \tfrac{1}{2}(\nabla \phi)^2 - \tfrac{1}{2} m^2 \phi^2
\end{equation*}
Then using \eqref{eq:EL} we find the Klein-Gordon equation;
\begin{equation}
\del_\mu \del^\mu \phi + m^2 \phi = 0
\end{equation}
\end{examplebox}
The realm of Quantum Field Theory are relativistic energies where quantum effects are important. The mass energy equivalence at these high energies mean that the quantum states are multi-particle ones, and the particle number is \emph{not fixed}. This is fundamentally different to normal quantum mechanics. The Schr{\"o}dinger equation is for a single particle, there is no mechanism to create more. Furthermore, interactions arise due to locality and symmetry, they do not arise from arbitrary potentials in the Lagrangian. Indeed, this is made explicit in \emph{Advanced Quantum Field Theory}, where symmetries of the path integral measure and the classical action remain manifest in the full quantum theory. This ensures that the interactions generated respect this symmetry. A special QFT is the free theory\index{free theory} where there are particles, but no interactions. This is a relativistic theory with an infinite number of quantised harmonic oscillators\index{harmonic oscillator}, at least one at each point in space. The interacting theory is then built perturbatively on top of this.
\subsubsection{Lorentz Invariance\index{Lorentz!invariance}}
The Lorentz matrices\footnotemark satisfy the relation; \boxed{\textbf{I.ii}}
\footnotetext{
Note that this expression implies the Lorentz invariance of quantities such as $p^\mu p_\mu$. Under a Lorentz transformation $p^{\mu} \rightarrow \Lambda\indices{^{\mu}_{\nu}}p^{\nu}$ so;
\begin{equation*}
p^\mu p_\mu = \eta_{\mu\nu}p^\mu p^\nu \rightarrow \eta_{\mu\nu} \Lambda\indices{^{\mu}_{\rho}}\Lambda\indices{^{\nu}_{\sigma}}\eta_{\rho\sigma}p^\rho p^\sigma = \eta_{\rho \sigma}p^{\rho} p^{\sigma}
\end{equation*}
}
\begin{equation}
\label{eq:LT}
\Lambda\indices{^\mu_\sigma}\eta\indices{^{\sigma \tau}}\Lambda\indices{_\tau ^\nu} = \etamn{^}
\end{equation}
Consider the Lorentz transformation\index{Lorentz!transformation} of a field, $\phi$ under the transformation;\footnotemark
\footnotetext{
This is really the statement that Lorentz transformations are isometries of the Minkowski metric, in other words, we can define the group in a co-ordinate free way via;
\begin{equation*}
\mO(3, 1) \coloneqq \set{M \in \text{GL}(\RR^{3, 1}) : \eta(M \vec{x}, M \vec{y}) = \eta(\vec{x}, \vec{y})}
\end{equation*}
}
\begin{equation*}
\Lambda : \phi \rightarrow \phi^{\prime}, \quad \phi^{\prime}(x^\mu) = \phi(x^{\prime \, \mu}), \quad x^{\prime \, \mu} = \left(\Lambda^{-1}\right)\indices{^\mu_\nu} x^\nu
\end{equation*}
This is an active transformation of the field, pulling the field value at $\Lambda^{-1} x$ to $x$. We say the Lorentz transformations have a \emph{representation} on the fields. For a scalar field\index{field!scalar}, this is just $\phi(x) \rightarrow \phi^{\prime}(x) = \phi(\Lambda^{-1} x)$. But we could equally have used a passive transformation where we relabel spacetime points, $\phi(x) \rightarrow \phi(\Lambda x)$. Since we work with Lorentz invariant theories it doesn't matter what we choose.

\paraskip
A Lorentz invariant theory is one where the action is invariant under a Lorentz transformation, e.g.
\begin{equation*}
\mathcal{S} = \int{\upd{^4 x} \tfrac{1}{2}\del_\mu \phi \del^\mu \phi - U(\phi)}
\end{equation*}
Under a Lorentz transformation;
\begin{itemize}
\item $U \rightarrow U\left(\phi(x^{\prime})\right) = U(x^{\prime})$
\item $\left(\del_\mu \phi\right)^{\prime} = \left(\Lambda^{-1}\right)\indices{^\sigma_\mu} \del^{\prime}_\sigma \phi(x^{\prime})$ (This is how a vector field transforms). But plugging this into the kinetic term, and using the relation in \eqref{eq:LT}, we see that the Lagrangian simply transforms as a scalar field.
\end{itemize}
So,
$$\mathcal{S}^{\prime} = \int{\upd{^4 x} \mathcal{L}(x^{\prime})}$$
The final step is to note that Lorentz transformations have determinants with modulus $1$. So,
\begin{equation}
\mathcal{S}^{\prime} = \int{\upd{^4 x^{\prime}} \mathcal{L}(x^{\prime})} = \mathcal{S}
\end{equation}
\subsection{Noether's Theorem\index{Noether's theorem} \& Symmetries}
\begin{thm}{Noether's Theorem}
Every continuous symmetry of the Lagrangian gives rise to a conserved current, $j^\mu (x)$ such that $\del_\mu j^\mu (x) = 0$. Furthermore, each conserved current has an associated conserved charge,
\begin{equation}
Q = \int_{\mathbb{R}^3}{\upd{^3 x} j^0 (x^{\mu})}
\end{equation}
which follows from the divergence theorem and the continuity equation as well as the assumption that $j$ decays sufficiently rapidly. Note that the current is only conserved \emph{on-shell}\index{on-shell} where the equations of motion hold. Furthermore, Noether's theorem holds for global symmetries \emph{as well as gauge symmetries} where $\alpha = \alpha(x)$. Indeed, the global symmetry is a special case of this.
\end{thm}
A transformation which induces a variation in the field, $\phi(x) \rightarrow \phi(x) + \alpha \Delta \phi(x)$, is a symmetry if it leaves the action invariant $\iff$ the Lagrangian is invariant up to a total derivative;
\begin{equation}
\label{eq:var}
\mathcal{L} \rightarrow \mathcal{L} + \alpha \del_\mu X^\mu (x)
\end{equation}
In detail,
\begin{dmath}
\mathcal{L}(x) \rightarrow \mathcal{L}(x) + \alpha \frac{\del \mathcal{L}}{\del \phi}\Delta \phi + \alpha \frac{\del \mathcal{L}}{\del \left(\del_\mu \phi\right)}\del_\mu \left(\Delta \phi\right) = \mathcal{L}(x) + \alpha\del_\mu \left(\frac{\del \mathcal{L}}{\del\left(\del_\mu \phi\right)} \Delta \phi \right)
\end{dmath}
where we have used the Euler Lagrange equations in the second line. So comparing to \eqref{eq:var}, we find the current, \boxed{\textbf{I.iii}}
\begin{equation}
\label{eq:current}
j^{\mu} = \frac{\del \mathcal{L}}{\del \left(\del_\mu \phi\right)} \Delta \phi - X^\mu, \quad \del_\mu j^\mu = 0
\end{equation}
We consider the example of a complex scalar\index{field!complex scalar} field to illustrate this,
\begin{examplebox}
We write the theory using $\psi$, $\psi^{\star}$ with Lagrangian;
\begin{equation}
\mathcal{L} = \del_\mu \psi^{\star} \del^\mu \psi - V\left( \left| \psi \right|^2 \right), \quad \textrm{e.g. } V\left( \left| \psi \right|^2 \right) = m^2 \psi^{\star} \psi - \tfrac{\lambda}{2}\left( \psi^{\star} \psi \right)^2
\end{equation}
The symmetry is a phase rotation $\psi \rightarrow e^{i \beta} \psi \rightarrow \Delta \psi = i \psi, \Delta \psi^{\star} = - i \psi^{\star}$. Lagrangian clearly invariant, so $X^{\mu} = 0$. Then we use \eqref{eq:current} to find,
\begin{equation}
j_\mu = i \left(\psi \del_\mu \psi^{\star} - \psi^{\star} \del_\mu \psi \right)
\end{equation}
and the conserved charge is the electric charge\index{electric charge}/particle number.
\end{examplebox}
Perhaps a more important example is that of translations, which leads to the energy-momentum tensor\index{tensor!energy-momentum};
\begin{examplebox}[The Energy-Momentum Tensor]
We consider the translation $x^\mu \rightarrow x^\mu - \xi^\mu$, so $\phi(x) \rightarrow \phi(x) + \xi^\mu \del_\mu \phi(x)$, where we use the fact that $\phi$ transforms under the inverse map. If $\mathcal{L}$ doesn't depend explicitly on time, then it transforms as a scalar field, then;
\begin{equation}
\mathcal{L}(x) \rightarrow \mathcal{L}(x) + \xi^\mu \del_\mu \mathcal{L} (x) = \mathcal{L}(x) + \xi^\nu \del_\mu \left( \delta\indices{^\mu_\nu}\mathcal{L}\right)
\end{equation}
We have one conserved current for each component of $\xi^\nu$, so identifying $\Delta \phi = \del_\mu \phi$, $X^\mu = \delta\indices{^\mu_\nu}\mathcal{L}$, we find;
\begin{equation}
j\indices{^\mu_\nu} \coloneqq T\indices{^\mu_\nu} = \frac{\del \mathcal{L}}{\del \left( \del_\mu \phi \right)}\del_\nu \phi - \delta\indices{^\mu_\nu}\mathcal{L}, \quad \del_\mu T\indices{^\mu_\nu} = 0
\end{equation}
This gives us the conserved charges;
\begin{itemize}
\item Total field energy, $E = \int{\upd{^3 x}} T^{00}$
\item Total field momentum, $P^{i} = \int{\upd{^3 x}} T^{0i}$
\end{itemize}
\end{examplebox}
\newpage
\section{Canonical Quantisation}
We can also use the Hamiltonian\index{Hamiltonian} formalism in field theories; the conjugate momentum\index{conjugate momentum} is defined by;
\begin{equation}
\pi_a (x) = \frac{\del \mL}{\del \dot{\phi}_a} \Rightarrow \hamilt = \sum_{a}{\pi_a (x) \dot{\phi}_a} - \mL(x)
\end{equation}
where $\hamilt$ is the Hamiltonian density\index{Hamiltonian!density}. For example, consider $\mL = \tfrac{1}{2} \dot{\phi}^2 - \tfrac{1}{2} \left(\nabla \phi \right)^2 - V(\phi) \Rightarrow \pi(x) = \dot{\phi}(x) \Rightarrow \hamilt = \tfrac{1}{2} \pi^2 + \tfrac{1}{2} \left(\nabla \phi \right)^2 + V(\phi)$. Hamilton's equations\index{equation!Hamilton's};
\begin{equation}
\dot{\phi} = \frac{\del \hamilt}{\del \pi}, \quad \dot{\pi} = - \frac{\del \hamilt}{\del \phi}
\end{equation}
In general it is not obvious that the Hamiltonian is manifestly Lorentz invariant, but the physics is unchanged, so it must be. Now, in quantum mechanics, the process of quantisation\index{canonical quantisation} takes co-ordinates $q_a$ and momenta $p_a$ and promotes them to operators, replacing the Poisson bracket\index{Poisson bracket} with commutators. We'll do the same here;
\begin{definitionbox}
A \emph{quantum field}\index{field!quantum} is an operator valued function of space obeying the commutation relations;
\begin{align}
\left[\phi_a(\vec x), \pi^b(\vec y)\right] &= i\delta\indices{^{a}_{b}}\delta^{(3)}(\vec x - \vec y) \\
\left[\phi_a(\vec x), \phi_b(\vec y)\right] &= 0 = \left[\pi^{a}(\vec x), \pi^{b}(\vec y)\right]
\end{align}
where we are in the Schr{\"o}dinger picture, so there is no time dependence in the fields.
\end{definitionbox}
It is usually not possible to know the spectrum of $\hamilt$ as there are an infinite number of degrees of freedom. In certain theories, the co-ordinates evolve independently, these are \emph{free theories}\index{free theory} where $\mL$ is quadratic in the fields, giving linear equations of motion. For example, the free theory of a scalar field leads to the Klein-Gordon equation\index{equation!Klein-Gordon} for the field $\phi(\vec, t)$;
\begin{equation}
\del_\mu \del^\mu + m^2 \phi = 0
\end{equation}
Taking the Fourier transform\index{Fourier transform};
\begin{equation}
\phi(\vec x, t) = \int{\frac{\ud^3 p}{(2\pi)^3} e^{i \vec p \cdot \vec x} \phi(\vec p, t)} \Rightarrow \left(\del^2_t + ( \vec{p}^2 + m^2 )\right) \phi(\vec p, t) = 0
\end{equation}
But this is just a harmonic oscillator with frequency $\omega_{p} = \sqrt{\vec{p}^2 + m^2}$. Then $\phi(\vec x, t)$ is just a superposition of an infinite number of harmonic oscillators that we need to quantise.
\subsection{Review of the Simple Harmonic Oscillator\index{harmonic oscillator}}
The main details of the harmonic oscillator can be found elsewhere, here we focus only on the concept of \emph{normal ordering}\index{normal ordering}. Often we are only interested in energy differences between states. So we set the zero point energy $\tfrac{1}{2} \omega \ket{n}$ to zero. This is not so drastic in the case of a single oscillator, it just results from fixing the Hamiltonian to be $\text{H} = \omega a\dagg a$. In the free theory of a full quantum field however, this zero point energy is infinite and thus in this context normal ordering represents a far more subtle process.
\subsection{Free Field Theory}
We take guidance from the simple harmonic oscillator where we write the position and momentum operators in terms of the ladder operators;
\begin{equation}
\label{eq:sho}
\phi = \tfrac{1}{\sqrt{2\omega}}\left(a + a\dagg\right), \quad \pi = -i \sqrt{\tfrac{\omega}{2}} \left(a - a\dagg\right)
\end{equation}
Then we can find the spectrum of the Klein-Gordon Hamiltonian using the same form, but now each Fourier mode of the field is treated as an independent oscillator with it's own $a$, $a\dagg$. So in analogy with \eqref{eq:sho}, we write;\footnote{Note that the second term in the expression for $\phi(\vec x)$ ensures that $\phi$ is a real field.}
\begin{definitionbox}[The Klein-Gordon Scalar Field]
\vspace{-10pt}
\begin{align}
\label{eq:kgfield}
\phi(\vec x) &= \int{\frac{\ud^3 p}{(2\pi)^3}\frac{1}{\sqrt{2\omega_p}} \left(a_{\vec p}\, e^{i\vec{p}
\cdot \vec{x}} + a_{\vec p}\dagg \,e^{-i\vec{p}\cdot\vec{x}}\right)} \\
\pi(\vec x) &= \int{\frac{\ud^3 p}{(2\pi)^3}(-i)\sqrt{\frac{\omega_p}{2}} \left(a_{\vec p}\, e^{i\vec{p}
\cdot \vec{x}} - a_{\vec p}\dagg\, e^{-i\vec{p}\cdot\vec{x}}\right)}
\end{align}
\end{definitionbox}
Importantly we can use this definition along with the identity;
\begin{equation}
\int{\frac{\ud^3 p}{(2\pi)^3}e^{i \vec{p} \cdot \vec{x}}} = \delta^{(3)}(\vec x)
\end{equation}
to show that;\footnote{It is the commutation relations in \eqref{eq:comm} that really motivate the definition in \eqref{eq:kgfield}. It is this algebraic structure that is the hallmark of the quantisation process, not the analogy with the simple harmonic oscillator}
\begin{multline}
\label{eq:comm}
\left[\phi(\vec x), \pi(\vec y)\right] = i\delta^{(3)}(\vec x - \vec y), \left[\phi(\vec x), \phi(\vec y)\right] = 0 = \left[\pi(\vec x), \pi(\vec y)\right] \\ \iff \left[a_{\vec p}, a_{\vec q}\right] = 0 = \left[a_{\vec p}\dagg, a_{\vec q}\dagg\right], \left[a_{\vec p}, a_{\vec q}\dagg\right] = (2\pi)^3 \delta^{(3)}(\vec p - \vec q)
\end{multline}
So, given these definitions, can we calculate the Hamiltonian in terms of the ladder operators? It is a lengthy, but relatively straightforward calculation to find that;
\begin{align}
\text{H} &= \frac{1}{2} \int{\upd{^3 x} \pi^2 + \left(\nabla \phi\right)^2 + m^2 \phi^2} \nonumber \\
&= \frac{1}{4} \int{\frac{\ud^3 p}{(2\pi)^3 \omega_p}\left(-\omega_p^2 + \vec{p}^2 + m^2\right)\left(a_{\vec p} a_{-\vec p} + a_{\vec p}\dagg a_{-\vec p}\dagg\right)} \nonumber \\
&\qquad\qquad\qquad+ \left(\omega_p^2 + \vec{p}^2 + m^2\right)\left(a_{\vec p} a_{\vec p}\dagg + a_{\vec p}\dagg a_{\vec p}\right)
\end{align}
But now we can use the fact that $\omega_p = \sqrt{\vec{p}^2 + m^2}$ to see that the first term vanishes and we are left with;
\begin{equation}
\text{H} = \int{\frac{\ud^3 p}{(2\pi)^3} \omega_p \left(a_{\vec p}\dagg a_{\vec p} + \frac{1}{2}\left[a_{\vec p}, a_{\vec p}\dagg\right]\right)}
\end{equation}
\subsubsection{The Vacuum}
We define the \emph{vacuum}\index{vacuum} of the theory, $\ket{0}$ by the condition that $a_{\vec p} \ket{0} = 0$ for all momenta $\vec p$. The energy is then given by $\text{H}\ket{0}$;
\begin{equation}
\text{H}\ket{0} = \frac{1}{2}\int{\frac{\ud^3 p}{(2\pi)^3} \omega_p (2\pi)^3 \delta^{(3)}(0) \ket{0}}
\end{equation}
but this is divergent (an \emph{ultra-violet divergence}\index{UV divergence}). To rectify this we apply the concept of normal ordering\index{normal ordering}. We are only interested in energy differences, so we redefine the normal ordered Hamiltonian to be;\footnotemark
\footnotetext{
There are actually two infinities here. The first is because space is infinitely large. If instead we put the system in a box of side length $L$, then;
\begin{equation*}
(2\pi)^3 \delta^{(3)}(0) = \lim_{L \rightarrow \infty}\int_{-L/2}^{L/2}{\upd{^3 x}\left.e^{i \vec{p}\cdot\vec{x}}\right|_{\vec{p} = 0}} = \lim_{L \rightarrow \infty}\int_{-L/2}^{L/2}{\upd{^3 x}} = V
\end{equation*}
This we can resolve then by simply considering the energy density $E/V \coloneqq \epsilon_0$. This still leaves;
\begin{equation*}8
\int{\frac{\ud^3 p}{(2\pi)^2}\frac{1}{2}\omega_{\vec{p}}} \rightarrow \infty
\end{equation*}
since $\omega_{\vec{p}}$ diverges. This is the UV divergence mentioned above.
}
\begin{equation}
\normord{\text{H}} = \int{\frac{\ud^3 p}{(2\pi)^3}\omega_p a_{\vec p}\dagg a_{\vec p}}
\end{equation}
\begin{definitionbox}[Normal Ordering]
In general, we define a normal ordering\index{normal ordering} string of operators $\phi_1(x_1)\cdots\phi_n(x_n)$ to be $\normord{\phi_1(x_1)\cdots\phi_n(x_n)}$ which is simply the normal product with all annihilation operators moved to the right of each term.
\end{definitionbox}
\subsubsection{Particles}
With this definition of normal ordering, we now have $\normord{\text{H}}\ket{0} = 0$. We can also verify that,
\begin{equation}
\left[\text{H}, a_{\vec p}\dagg\right] = \omega_p a_{\vec p}\dagg, \quad \left[\text{H}, a_{\vec p}\right] = -\omega_p a_{\vec p}
\end{equation}
So $a_{\vec p}\dagg$ increases the energy by $\omega_{\vec p}$. Let $\ket{\vec{p}\pr} = a_{\vec{p}\pr}\dagg \ket{0}$ then we may show that;
\begin{equation}
\text{H}\ket{\vec{p}\pr} = \omega_{\vec{p}\pr} a_{\vec{p}\pr}\dagg \ket{0} = \omega_{\vec{p}\pr}\ket{\vec{p}\pr}
\end{equation}
i.e. the energy is just $\omega_{\vec{p}\pr} = \sqrt{\vec{p}^{\prime^2} + m^2}$ which is the dispersions relation \index{dispersion relation} for a relativistic particle of mass $m$ and momentum $\vec{p}\pr$. We write $\omega_{\vec{p}} = E_{\vec{p}}$ from now on. We can also show that the total momentum and angular momentum operators;
\begin{align}
\vec P &= -\int{\upd{^3 x} \pi(\vec x) \nabla \phi(\vec x)} = \int{\frac{\ud^3 p}{(2\pi)^3} \vec p a_{\vec p}\dagg a_{\vec p}} \\
J_i &= -\frac{i}{2}\epsilon_{ijk}\int{\frac{\ud^3 p}{(2\pi)^3} a_{\vec p}\dagg\left(p_j \frac{\del}{\del p_k} - p_k \frac{\del}{\del p_j}\right)a_{\vec p}}
\end{align}
satisfy $\vec P \ket{\vec p} = \vec p \ket{\vec p}$ and $J_i \ket{\vec p = \vec 0} = 0$. This second equality tells us that the single particle states of the scalar field have spin $0$.

\paraskip
Now consider the more general multi-particle states, $\ket{\vec{p}_1, \ldots, \vec{p}_n} = a_{\vec{p}_1}\dagg \cdots a_{\vec{p}_n}\dagg\ket{0}$. The $a\dagg$ commute, so this is symmetric under interchange implying that the particles of the scalar field are also \emph{bosons}\index{boson}. The full Hilbert space\index{Hilbert space}, know as the \emph{Fock space}\index{Fock space} is spanned by
\begin{equation}
\set{\ket{0}, a_{\vec{p}_1}\dagg\ket{0}, a_{\vec{p}_1}\dagg a_{\vec{p}_2}\dagg\ket{0}, \ldots}
\end{equation}
The number operator\index{number operator} counts the number of particles;
\begin{equation}
N = \int{\frac{\ud^3 p}{(2\pi)^3} a_{\vec{p}}\dagg a_{\vec p}}, \quad N \ket{\vec{p}_1, \ldots, \vec{p}_n} = n\ket{\vec{p}_1, \ldots, \vec{p}_n}
\end{equation}
In the free theory, $\left[N, \text{H}\right] = 0$ so the particle number is actually conserved. This is certainly not true in the interacting theory\index{interacting theory} however.

\paraskip
Note that these momentum states are not localised in space, and even after taking a Fourier transform;
\begin{equation*}
\ket{\vec{x}} = \int{\frac{\ud^3 p}{(2\pi)^3}e^{i\vec{p}\cdot\vec{x}}\ket{\vec{p}}}
\end{equation*}
the localised states are still not normalisable; $\braket{\vec{x}}{\vec{x}} = \infty$. This is really the statement that $a_{\vec{p}}$ and $\phi(\vec{x})$ are not good operators on the Hilbert space. To construct well defined operators, we should consider a wave packet;
\begin{equation}
\ket{\varphi} = \int{\frac{\ud^3 p}{(2\pi)^3}e^{-i\vec{p}\cdot\vec{x}}\varphi(\vec{p})\ket{\vec{p}}} = \int{\frac{\ud^3 p}{(2\pi)^3}e^{-i\vec{p}\cdot\vec{x}}\varphi(\vec{p})a_{\vec{p}}\dagg \ket{0}}
\end{equation}
which we can show satisfies;
\begin{equation*}
\braket{\varphi}{\varphi} = \int{\upd{^3 p}\abs{\varphi(\vec{p})}^2}
\end{equation*}
So we deduce that states such that $\varphi(\vec{p})$ has a finite $L^2$ norm are good operators on the Hilbert space.
\subsection{Relativistic Normalisation}
We define the vacuum to be normalised; $\braket{0}{0} = 1$, then $\braket{\vec p}{\vec q} = \expval{a_{\vec p} a_{\vec q}\dagg}{0} = \expval{\left[a_{\vec p}, a_{\vec q}\dagg\right]}{0} = (2\pi)^3 \delta^{(3)}(\vec p - \vec q)$. We want to know if this is Lorentz invariant. Clearly the vacuum normalisation is since it is just a scalar but, a priori, the general one-particle state is not, and indeed it will need some modification. Consider a boost in the $3$-direction; then $p_3\pr = \gamma(p_3 + \beta E), E\pr = \gamma(E + \beta p_3)$. We can use a delta function identity;
\begin{equation}
\label{eq:deltaident}
\delta\left(f(x) - f(x_0)\right) = \frac{1}{\abs{f\pr(x_0)}} \delta(x - x_0)
\end{equation}
to deduce that;\footnote{Note that $E = \sqrt{p_i p^i + m^2} \Rightarrow \del_{p_3}E = \tfrac{p_3}{E}$ as claimed.}
\begin{align}
\delta^{(3)}(\vec p - \vec q) &= \delta(p_1 - q_1)\delta(p_2 - q_2)\delta(p_3 - q_3) \nonumber \\
&= \delta^{(3)}(\vec{p}\pr - \vec{q}\pr) \cdot \frac{\ud p_3\pr}{\ud p_3} = \delta^{(3)}(\vec{p}\pr - \vec{q}\pr) \gamma\left(1 + \beta \frac{\ud E}{\ud p_3}\right) \nonumber \\
&= \delta^{(3)}(\vec{p}\pr - \vec{q}\pr) \frac{\gamma}{E}(E + \beta p_3) = \delta^{(3)}(\vec{p}\pr - \vec{q}\pr)\frac{E\pr}{E}
\end{align}
We see then that whilst $\delta^{(3)}(\vec{p}- \vec{q})$ is not Lorentz invariant, $E_{\vec p}\delta^{(3)}(\vec{p} - \vec{q})$ is. Hence we define the normalised one particle states;
\begin{equation}
\ket{p} = \sqrt{2E_{\vec p}}a\dagg_{\vec p}\ket{0} \Rightarrow \braket{p}{q} = (2\pi)^3 \cdot 2\sqrt{E_{\vec p}E_{\vec q}} \delta^{(3)}(\vec p - \vec q)
\end{equation}
Because of this redefinition, we need to include factors of $\sqrt{2E_{\vec p}}$ elsewhere, for example. the identity on one particle states is now;
\begin{equation}
\left(\II\right)_{\text{one particle states}} = \int{\frac{\ud^3 p}{2 E_{\vec p}}\frac{1}{(2\pi)^3}\ket{p}\bra{p}}
\end{equation}
As a final point in this regard, note that, using \eqref{eq:deltaident};
\begin{equation}
\int{\upd{^4 p} \left.\delta(p_0^2 - \vec{p}^2 - m^2)\right|_{p_0 > 0}} = \int{\left.\frac{\ud^3 p}{2p_0}\right|_{p_0 = E_{\vec p}}}
\end{equation}
which justifies the fact that the integration measure $\left(\ud^3 p / 2E_{\vec p}\right)$ is Lorentz Invariant since the LHS is.\footnote{$\ud^4 p$ certainly is because $\det \text{M} = 1$ for $\text{M} \in \Orth{3,1}$, and the delta function is only dependent on Lorentz invariant quantities.}
\subsection{Complex Scalar Field\index{field!complex scalar}}
Consider now the Lagrangian;\footnote{If we write the complex field $\psi = \tfrac{1}{\sqrt{2}}(\phi_1 + i \phi_2)$, then expanding the Lagrangian gives the sum of the usual Lagrangian for two real scalar fields $\mL_i = \tfrac{1}{2}(\del \phi_i)^2 - \tfrac{1}{2}m^2 \phi_i^2$. Furthermore, this explains the presence of \emph{two} types of creation/annihilation operators, one for the real component of $\psi$ and one for the imaginary part.}
\begin{equation}
\mL = \del_\mu \psi^{\star} \del^\mu \psi - \mu^2 \psi^{\star} \psi
\end{equation}
which leads to the Euler-Lagrange equations\index{equation!Euler-Lagrange};
\begin{equation}
\del_\mu \del^\mu \psi + \mu^2 \psi = 0, \quad \del_\mu \del^\mu \psi^{\star} + \mu^2 \psi^{\star} = 0
\end{equation}
This allows us to expand;
\begin{align}
\psi &= \int{\frac{\ud^3 p}{(2\pi)^3}\frac{1}{\sqrt{2E_p}}\left(b_{\vec p}e^{i\vec{p}\cdot \vec{x}} + c\dagg_{\vec p}e^{-i \vec{p}\cdot \vec{x}}\right)} \\
\pi &=i \int{\frac{\ud^3 p}{(2\pi)^3}\sqrt{\frac{E_p}{2}}\left(b_{\vec p}\dagg e^{-i\vec{p}\cdot \vec{x}} + c_{\vec p}e^{i \vec{p}\cdot \vec{x}}\right)}
\end{align}
Then the commutation relations are $\left[\psi(\vec x), \pi(\vec y)\right] = i\delta^{(3)}(\vec x - \vec y)$ and $[\psi(\vec x), \pi\dagg(\vec y)] = 0$ etc. In terms of the creation and annihilation operators, $\left[b_{\vec p}, b\dagg_{\vec q}\right] = (2\pi)^3\delta^{(3)}(\vec p - \vec q) = \left[c_{\vec p}, c\dagg_{\vec q}\right]$ with all other commutators vanishing. The two Klein-Gordon equations\index{equation!Klein-Gordon} ensure that we have two types of creation operator, $b_{\vec p}\dagg, c_{\vec q}\dagg$, which we interpret as creating two types of particle with mass $\mu$; a particle and its anti-particle\index{anti-particle}. The conserved charge, after normal ordering is;
\begin{align}
Q &= i\int{\upd{^3 x} \dot{\psi}^{\star}\psi - \psi^{\star} \dot{\psi}} = i\int{\upd{^3 x}\pi\psi - \psi^{\star}\pi^{\star}} \nonumber \\
&= \int{\frac{\ud^3 p}{(2\pi)^3}\left(c_{\vec p}\dagg c_{\vec p} - b_{\vec p}\dagg b_{\vec p}\right)} \coloneqq N_c - N_b
\end{align}
We can also calculate the Hamiltonian;
\begin{equation}
\text{H} = \int{\frac{\ud^3 p}{(2\pi)^3} E_p \left(b\dagg_{\vec p} b_{\vec p} + c_{\vec p}\dagg c_{\vec p}\right)}
\end{equation}
from which we may deduce\footnotemark that $\left[\hamilt, Q\right] = 0$. In the free theory, it is true that $N_{c}$ and $N_{b}$ are conserved separately, however in the interacting theory (with the requisite symmetry), the total charge $Q$ still is.
\footnotetext{Define $B_{\vec p} \coloneqq b_{\vec p}\dagg b_{\vec p}$ and $C_{\vec p} \coloneqq c_{\vec p}\dagg c_{\vec p}$, then;
\begin{align*}
\left[\hamilt, Q\right] &= \int{\frac{\ud^3 p \ud^3 q}{(2\pi)^6}E_{p}\left[B_{\vec p} + C_{\vec p}, C_{\vec q} - B_{\vec q}\right]} \\
&= \int{\frac{\ud^3 p \ud^3 q}{(2\pi)^6}E_{p}\left(\left[C_{\vec p}, C_{\vec q}\right] - \left[B_{\vec p}, B_{\vec q}\right]\right)}
\end{align*}
Now, $\left[B_{\vec p}, B_{\vec q}\right] = b_{\vec p}\dagg b_{\vec p}b_{\vec q}\dagg b_{\vec q} - b_{\vec q}\dagg b_{\vec q}b_{\vec p}\dagg b_{\vec p} = b_{\vec p}\dagg \left[b_{\vec p}, b_{\vec q}\dagg\right] b_{\vec q} - b_{\vec q}\dagg \left[b_{\vec q}, b_{\vec p}\dagg\right] b_{\vec p}$, so;
\begin{equation*}
\left[\hamilt, Q\right] = \int{\frac{\ud^3 p \ud^3 q}{(2\pi)^3}E_p \delta^{(3)}(\vec p - \vec q)\left(c_{\vec p}\dagg c_{\vec q} - c_{\vec q}\dagg c_{\vec p} - b_{\vec p}\dagg b_{\vec q} + b_{\vec q}\dagg b_{\vec p}\right)}
\end{equation*}
which vanishes on integrating $\ud^3 p \ud^3 q$.
}
\subsection{The Heisenberg Picture\index{picture!Heisenberg}}
So far in the Schr{\"o}dinger picture\index{picture!Schr{\"o}dinger}, $\phi(\vec x)$ does not depend on time. In the Heisenberg picture all the time dependence is assigned to the operators;
\begin{equation}
\mO_{\hamilt}(t) = e^{iHt} \mO_{\mathcal{S}} e^{-iHt} \Rightarrow \frac{\ud \mO_{\hamilt}(t)}{\ud t} = i\left[\hamilt, \mO_{\hamilt}\right]
\end{equation}
Then the Heisenberg fields now satisfy equal time commutation relations;
\begin{equation}
\left[\phi(\vec x, t), \phi(\vec y, t)\right] = \left[\pi(\vec x, t), \pi(\vec y, t)\right] = 0
\end{equation}
\begin{equation}
\left[\phi(\vec x, t), \pi(\vec y, t)\right] = i\delta^{(3)}(\vec x - \vec y)
\end{equation}

%\end{multicols*}


\documentclass[10pt]{report}

\usepackage{subcaption} % for subfigures
\usepackage{amsthm} % for QED
%\usepackage{algpseudocode} % for pseudo-code
\usepackage{mathtools} % for delimiter

\usepackage{listings} % for code
\lstset
{
	language=Matlab,
	frame=single,
	basicstyle=\footnotesize,
	captionpos=b,
	numbers=left,
	stepnumber=1,
	showstringspaces=false,
	tabsize=4,
	breaklines=true,
	breakatwhitespace=false,
}

\usepackage{siunitx} % for scientific notation
% for `e' in scientific notation
\sisetup{output-exponent-marker=\ensuremath{\mathrm{e}}}

\usepackage{float} % for figure [H]
\usepackage{booktabs} % for tabular
\usepackage{caption} % for \caption*
\usepackage[export]{adjustbox} % for valign=t
\usepackage{array} % for column type m
\usepackage{verbatim}
\usepackage{graphicx}
\graphicspath{ {imgs/} }
\usepackage{fancyhdr}
\usepackage{amssymb}
\usepackage{amsmath}

%%%%%% Pagination
\setlength{\topmargin}{-.3 in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textheight}{9.in}
\setlength{\textwidth}{6.5in}

%Title page
\newcommand{\hwTitle}{Homework \#1}
\newcommand{\hwCourse}{Numerical Differential Equations/Computational Mathematics II}
\newcommand{\hmwkClassInstructor}{Professor Shuwang Li}

\title{
	\vspace{2in}
	\textmd{\textbf{\hwCourse\\\hwTitle}}\\
	\vspace{0.3in}\large{\textit{\hmwkClassInstructor}}
	\vspace{3in}
}

%\title{Homework 1}
\author{\textbf{Zhihao Ai}}
\date{}

%Header setting.
\pagestyle{fancy}
\fancyhead[L]{Zhihao Ai}
\fancyhead[C]{Math 478}
\fancyhead[R]{Homework 1}
%%%%%%

%Global setting.
\everymath{\displaystyle}
\setlength\parindent{0pt}

%Custom general commands.
\newcommand{\ds}{\displaystyle}
\newcommand{\f}[1] {f\left(#1\right)}
\newcommand{\eva}[2] {\left. #1 \right|_{#2}}
\newcommand{\dintt}[4] {\int_{#1}^{#2} #3 d#4}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{C}{M{3em}}
\newcolumntype{D}{M{5em}}

\DeclarePairedDelimiter{\paren}{(}{)}
\newcommand{\abs}[1] {\left| #1 \right|}

%Custom local commands
\newcommand{\varQa} {\sqrt{\frac{3}{5}}}

\begin{document}

\maketitle

\section*{Question 1.}
\begin{enumerate}
	\item
	(Section 6.1 Problem 23)\\
	Consider the data
	\\
	\[
		\begin{tabular}{l M{5em} M{2em} M{5em}}
			\toprule
			$x$ & $-\sqrt{\frac{3}{5}}$ & $0$ & $\sqrt{\frac{3}{5}}$ \\ \addlinespace[0.4em]
			\hline \addlinespace[0.4em]
			$f(x)$ & $\f{-\sqrt{\frac{3}{5}}}$ & $f(0)$ & $\f{\sqrt{\frac{3}{5}}}$ \\
			\bottomrule
		\end{tabular}
	\]
	\\
	What are the Newton interpolation polynomial and the Lagrange interpolation polynomial for these data?

	Newton:
	\[
	c_k = \frac{y_k - p_{k-1}(x_k)}{(x_k-x_0)(x_k-x_1)\cdots(x_k-x_{k-1})}
	\]
	\begin{align*}
		c_0 &= \f{-\sqrt{\frac{3}{5}}}
			& p_0(x)
			&= c_0
			\\
		c_1
			&= \frac{\f{0} - p_0(0)}{0 - \paren*{-\sqrt{\frac{3}{5}}}}
			& p_1(x)
			&= c_0 + c_1 \paren*{x - \paren*{-\sqrt{\frac{3}{5}}}}
			\\
		c_2
			&= \frac{\f{\sqrt{\frac{3}{5}}} - p_1\paren*{\sqrt{\frac{3}{5}}}}{\paren*{\sqrt{\frac{3}{5}} - \paren*{-\sqrt{\frac{3}{5}}}} \paren*{\sqrt{\frac{3}{5}} - 0}}
			& p_2(x)
			&= c_0 + c_1\paren*{x-\paren*{-\sqrt{\frac{3}{5}}}} + c_2\paren*{x-\paren*{-\sqrt{\frac{3}{5}}}} \paren*{x-0}
	\end{align*}

	Lagrange:
	\[
	l_i(x) = \prod_{\substack{j=0 \\ j\ne i}}^{n} \frac{x - x_j}{x_i - x_j}
	\]
	\begin{multline*}
	p_2(x) = \sum_{i=0}^{n} y_i l_i(x)
		= \f{-\sqrt{\frac{3}{5}}} \cdot \frac{\paren*{x-0} \paren*{x - \sqrt{\frac{3}{5}}}}{\paren*{-\sqrt{\frac{3}{5}} - 0} \paren*{-\sqrt{\frac{3}{5}} - \sqrt{\frac{3}{5}}}}
		+ \f{0} \cdot \frac{\paren*{x - \paren*{-\sqrt{\frac{3}{5}}}} \paren*{x - \sqrt{\frac{3}{5}}}}
		 {\paren*{0 - \paren*{-\sqrt{\frac{3}{5}}}} \paren*{0 - \sqrt{\frac{3}{5}}}}
		 \\
		+ \f{\sqrt{\frac{3}{5}}} \cdot \frac{\paren*{x - \paren*{-\sqrt{\frac{3}{5}}}} \paren*{x-0}} {\paren*{\sqrt{\frac{3}{5}} - \paren*{-\sqrt{\frac{3}{5}}}} \paren*{\sqrt{\frac{3}{5}} - 0}}
	\end{multline*}

	\item
	(Section 6.1 Problem 15)\\
	What is the final value of $v$ in the algorithm shown?

	$v \leftarrow c_{i-1}$\\
	\textbf{for} $j = i$ \textbf{to} $n$ \textbf{do}\\
	\hspace*{4ex} $v \leftarrow vx + c_j$\\
	\textbf{end do}

	What is the number of additions and substractions involved in this algorithm?
	\begin{align*}
		v &= ((((c_{i-1}x + c_i)x + c_{i+1})x + c_{i+2})x + \cdots c_{n-1})x + c_n\\
			&= c_{i-1}x^{n-i+1} + c_ix^{n-i} + \cdots + c_{n-1}x + c_n
	\end{align*}
	The number of additions is $n-i+1$; no substractions are involved.

	\item
	(Section 6.1 Problem 16)\\
	Write an efficient algorithm for evaluating
	\[
	u = \sum_{i=1}^{n} \prod_{j=1}^{i} d_j
	\]
	$u \leftarrow d_{n}$\\
	\textbf{for} $i = n-1$ \textbf{to} $1$ \textbf{step} $-1$ \textbf{do}\\
	\hspace*{4ex} $u \leftarrow d_i*(1+u)$\\
	\textbf{end do}
\end{enumerate}

\section*{Question 2.}
(Section 6.1 Problem 13)\\
Prove that if we take \textit{any} set of 23 nodes in the interval $[-1, 1]$ and interpolate the function $f(x) = \cosh{x}$ with a polynomial $p$ of degree 22, then the relative error $\abs{p(x)-f(x)}/\abs{f(x)}$ is no greater than $5 \times 10^{-16}$ on $[-1, 1]$.

Denote the nodes as $x_i, i=0,1,\cdots,22$. According to Theorem 2,
\[
f(x) - p(x) = \frac{1}{(n+1)!} \cdot f^{(n+1)}(\xi_x) \cdot \prod_{i=0}^{n} (x-x_i)
	= \frac{1}{23!} \cdot f^{(23)}(\xi_x) \cdot \prod_{i=0}^{22} (x-x_i)
\]
Since $f^{(23)}(\xi_x) = \sinh{\xi_x}$, which increases monotonically,
\[
f^{(23)}(\xi_x) < \sinh{1},\ \xi_x\in [-1, 1]
\]
Since $x\in [-1, 1]$,
\[
\prod_{i=0}^{22} (x-x_i) \le \prod_{i=0}^{22} 2 = 2^{23}
\]
Since $\cosh{x} \ge 1, f(x)\ge 1$. Therefore,
\[
\frac{\abs{p(x)-f(x)}}{\abs{f(x)}} < \frac{\frac{1}{23!} \cdot \sinh{1} \cdot 2^{23}}{1}
	\approx 3.81336\times 10^{-16}
	< 5 \times 10^{-16}
\]
\qed

\section*{Question 3.}
(Section 6.2 Problem 24)\\
Write the Newton interpolating polynomial for these data:
%\\
\[
	\begin{tabular}{lcccc}
		\toprule
		x & 4 & 2 & 0 & 3 \\ \midrule
		f(x) & 63 & 11 & 7 & 28 \\
		\bottomrule
	\end{tabular}
\]
\\
By Theorem 1,
\[
f[x_0, x_1, \cdots, x_n] = \frac{f[x_1, x_2, \cdots, x_n] - f[x_0, x_1, \cdots, x_{n-1}]}{x_n - x_0}
\]
we get the divided differences table:
\[
\begin{array}{cc|ccc}
4 & 63 & 26 & 6 & 1 \\
2 & 11  & 2   & 5 \\
0 & 7   & 7 \\
3 & 28
\end{array}
\]
Therefore the Newton polynomial is
\[
p(x) = 63 + 26(x-4) + 6(x-4)(x-2) + (x-4)(x-2)x
\]

\section*{Question 4.}
\begin{enumerate}
	\item
	(Section 6.4 Problem 14)\\
	Determine whether this function is a natural cubic spline:
	\[
	f(x) =
	\begin{cases}
		1+x-x^3, &x\in [0,1]\\
		1-2(x-1)-3(x-1)^2+4(x-1)^3, &x\in [1,2]\\
		4(x-2)+9(x-2)^2-3(x-2)^3, &x\in [2,3]\\
	\end{cases}
	\]
	By inspection, the order of $f(x)$ is no greater than 3.\\
	The first derivative of $f(x)$ is continuous:
	\[
	f'(x) =
	\begin{cases}
	1-3x^2, &x\in [0,1]\\
	-2-6(x-1)+12(x-1)^2, &x\in [1,2]\\
	4+18(x-2)-9(x-2)^2, &x\in [2,3]\\
	\end{cases}
	\]
	The second derivative of $f(x)$ is also continuous:
	\[
	f''(x) =
	\begin{cases}
	-6x, &x\in [0,1]\\
	-6+24x, &x\in [1,2]\\
	18-18(x-2), &x\in [2,3]\\
	\end{cases}
	\]
	Define $S_i(x),\ i=0,1,2$ as the sub-functions of $f(x)$ on $[0,1], [1,2], [2,3]$, respectively.
	\begin{align*}
		S_0(1) &= 1 = S_1(1) & S_1(2) &= 0 =S_2(2)\\
		S_0'(1) &= -1 = S_1'(1) & S_1'(2) &= 4 =S_2'(2)\\
		S_0''(1) &= -6 = S_1''(1) & S_1''(2) &= 18 =S_2''(2)
	\end{align*}
	Also we have
	\[
	f''(0) = f''(3) = 0
	\]
	Therefore, this function is a natural cubic spline.

	\item
	(Section 6.4 Problem 20)\\
	Determine whether the coefficients $a, b, c,$ and $d$ exist so that the function
	\[
	S(x) =
	\begin{cases}
	1-2x, &x\in (-\infty,-3]\\
	a+bx+cx^2+dx^3, &x\in [-3,4]\\
	157-32x, &x\in [4,+\infty)\\
	\end{cases}
	\]
	is a natural cubic spline for the interval $[-3, 4]$.

	Take the first and second derivatives of $S(x)$ and we have
	\[
	S'(x) =
	\begin{cases}
	-2, &x\in (-\infty,-3]\\
	b+2cx+3dx^2, &x\in [-3,4]\\
	-32, &x\in [4,+\infty)\\
	\end{cases}
	,\
	S''(x) =
	\begin{cases}
	0, &x\in (-\infty,-3]\\
	2c+6dx, &x\in [-3,4]\\
	0, &x\in [4,+\infty)\\
	\end{cases}
	\]
	For $S(x)$ to be a natural cubic spline, we need to satisfy
	\[
	\begin{cases}
	S_0(-3) = S_1(-3)\\
	S_0'(-3) = S_1'(-3)\\
	S_0''(-3) = S_1''(-3)\\
	S_1(4) = S_2(4)\\
	S_1'(4) = S_2'(4)\\
	S_1''(4) = S_2''(4)
	\end{cases}
	\Rightarrow
	\begin{cases}
	7 = a - 3 b + 9 c - 27 d\\
	-2 = b - 6 c + 27 d\\
	0 = 2 c - 18 d\\
	a + 4 b + 16 c + 64 d = 29\\
	b + 8 c + 48 d = -32\\
	2 c + 24 d = 0
	\end{cases}
	\]
	This system has no solution, as shown below:
	\[
	\left(
	\begin{array}{@{}cccc|c@{}}
		1& -3& 9& -27& 7\\
		0& 1& -6& 27& -2\\
		0& 0& 2& -18& 0\\
		1& 4& 16& 64& 29\\
		0& 1& 8& 48& -32\\
		0& 0& 2& 24& 0
	\end{array}
	\right)
	\xRightarrow{\text{R.R.}}
	\left(
	\begin{array}{@{}cccc|c@{}}
	1& 0& 0& 0& 0\\
	0& 1& 0& 0& 0\\
	0& 0& 1& 0& 0\\
	0& 0& 0& 1& 0\\
	0& 0& 0& 0& 1\\
	0& 0& 0& 0& 0
	\end{array}
	\right)
	\]
	Therefore, such $a,b,c,$ and $d$ do not exist.
\end{enumerate}

\section*{Question 5.}
(Section 6.1 Problem 37)\\
The first U.S. postage stamp was issued in 1885, with the cost to mail a letter set at 2 cents. In 1917, the cost was raised to 3 cents but then was returned to 2 cents in 1919. In 1932, it was upped to 3 cents again, where it remained for 26 years. Then a series of increases took place as follows: 1958 = 4 cents, 1963 = 5 cents, 1968 = 6 cents, 1971 = 8 cents, 1974 = 10 cents, 1978 = 15 cents, 1981 = 18 cents in March and 20 cents in October, 1985 = 22 cents, 1988 = 25 cents, 1991 = 29 cents, 1995 = 32 cents, 1999 = 33 cents, and 2001 = 34 cents. Determine the Newton interpolation polynomial for these data. Based on this, when will it cost \$1 to mail a letter? When will it cost \$10?

The following code is for calculating the coefficients and each $p(x)$:
\lstinputlisting[caption={Coefficients}]{coefficients.m}
\lstinputlisting[caption={Newton interpolation polynomial}]{newtonPoly.m}
The code below is for displaying coefficients and years when it will cost \$1 and \$10.
\lstinputlisting[caption={Find the year}]{q5p37stamp.m}

It produces the coefficent vector
\begin{multline*}
d=[2,
0.03125,
-0.015625,
1.15077741e-03,
-2.89440714e-05,
6.78486768e-07,
-1.52159492e-08,\\
8.18727496e-10,
-9.10167759e-11,
9.40668614e-12,
-9.18167360e-13,
1.69879421e-13,\\
-2.96877259e-14,
3.92879060e-15,
-3.91394609e-16,
2.83733707e-17,
-1.60579668e-18,\\
8.19150612e-20]
\end{multline*}
Therefore, the Newton interpolation polynomial is
\begin{multline*}
	p(x) = 2 + 0.03125(x-1885) - 0.015625(x-1885)(x-1917) + \cdots +
	\\ 8.19150612e-20(x-1885)(x-1917)\cdots(x-1999)(x-2001)
\end{multline*}
By this interpolation polynomial, it costs \$1 to mail a letter in 2001.030137, which is in January, 2001; it cost \$10 in 2001.309589, which is in April, 2001.

\section*{Computer Assignment}
(Section 6.1 Problem 36)\\
The function $1/(1+x^2)$ and $e^{-x^2}$ have a similar appearance. Do they behave similarly in the interpolation process for equally spaced nodes?\\
Use the Newton interpolating polynomial $p_n(x)$ with $n=5,10,15$ on $[-5, 5]$. In each case, compute the error $f(x) - p_n(x)$ for $N = 30$ equally spaced points on $[-5, 5]$. Comment on what you get.
\lstinputlisting[caption={Interpolation on {$[-5,5]$}}]{interp.m}
\lstinputlisting[caption={Plotting functions and calculating errors}]{runge.m}
Denote $1/(1+x^2)$ as $f_a(x)$ and $e^{-x^2}$ as $f_b(x)$. The code above produces the following plots:
\begin{figure}[H]
	\centering
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=\linewidth]{functiona.jpg}
		\caption*{$f_a(x)$ and its polynomial interpolations}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=\linewidth]{functionb.jpg}
		\caption*{$f_b(x)$ and its polynomial interpolations}
	\end{subfigure}%
\end{figure}
The errors for $N = 30$ equally spaced points on $[-5, 5]$ are:
\begin{align*}
	f_a(x) - p_{5}(x) &= 1.257120 & f_b(x) - p_{5}(x) &= 1.416331\\
	f_a(x) - p_{10}(x) &= -4.711533 & f_b(x) - p_{10}(x) &= -5.689687\\
	f_a(x) - p_{15}(x) &= -2.607657 & f_b(x) - p_{15}(x) &= -2.487981
\end{align*}
The interpolation process for equally spaced nodes for function $1/(1+x^2)$ and $e^{-x^2}$ behave similarly. For each function, the interpolating polynomial of degree 5 does not fit the curve well at the center, but on the other hand it is relatively close to the curve at the edges. In contrast, even though the polynomials of higher degree like $p_{10}(x)$ and $p_{15}(x)$ fit the curve nicely around the center, they oscillate dramatically at the edges of the interval, leading to errors even greater than the polynomial of degree 5. The comparison clearly demostrates Runge's phenomenon, which means using polynomials of high degree for interpolation can introduce much error.

\end{document}


\documentclass{article}
\usepackage{ws_template}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{a4wide}
\usepackage{graphicx}
\usepackage{booktabs}

\title{homework sheet 04}

\author{
	\name{Denys Sobchyshak}\\
	\imat{03636581}\\
	\email{denys.sobchyshak@gmail.com}
	\And
	\name{Sergey Zakharov}\\
	\imat{03636642}\\
	\email{ga39pad@mytum.de}
}

\begin{document}
\maketitle

\section{Still refreshing}
\textbf{Problem 1:} \\\\
	 Let X represent the number of flips which were made. Then the possible values of X
	are $1, 2, ... ,$ and the distribution function of X is deﬁned by.
	\[ m(i) =\frac{1}{2^i} \]
	Thus,
	\begin{eqnarray*}
  	E(X) & = & \sum_{i=1}^{\infty}{i \frac{1}{2^i}} \\
 	  & = & 1+ \frac{1}{2} +\frac{1}{2^2} + \dots \\
  	 & = & 2
	\end{eqnarray*}

	So, the expected number of flips until one head is thrown is 2. \\
	Now, Let T represent the expexted number of tails. The possible values of T are 0, 1 and 2. The corresponding probabilities are 1/4, 1/2 and 1/4. Thus,
	\[ E(T) = 0(\frac{1}{4}) + 1(\frac{1}{2}) + 2 (\frac{1}{4}) = 1\]
	The expected number of heads equals to the expected number of tails $E(T) = E(H) = 1$

\section{Parameter Estimation}
\subsection{Coins}
\textbf{Problem 2:}\\\\
	The likelihood function $L(\theta)$ is, by definition:
	\begin{eqnarray*}
  	L(\theta) & = &\prod_{i=i}^{n}{P(X_i = x_i|\theta)} \\
 	  & = & \theta^{x_1}(1-\theta)^{1-x_1} \times \theta^{x_2}(1-\theta)^{1-x_2} \times \dots \times \theta^{x_n}(1-\theta)^{1-x_n} \\
  	 & = & \theta^{\sum{x_i}}(1-\theta)^{n-\sum{x_i}}
	\end{eqnarray*}
Now, in order to implement the method of maximum likelihood, we need to find the $\theta$ that maximizes the likelihood $L(\theta)$.
\[ ln L(\theta) = (\sum{x_i})ln(\theta) + (n-\sum{x_i})ln(1-\theta) \]
Differentiating with respect to $\theta$ results in:
\[ \frac{d ln L(\theta)}{d\theta} = \frac{\sum{x_i}}{\theta} - \frac{n-\sum{x_i}}{1-\theta} \]
Setting the derivative to zero we get:
\begin{eqnarray*}
(\sum{x_i})(1- \theta) - (n-\sum{x_i})\theta = 0 \\
\sum{x_i} - n\theta = 0
\end{eqnarray*}
Therefore the MLE for $\theta$ is:
\[ \hat{\theta} = \frac{\sum{x_i}}{n} \]

\textbf{Problem 3:}\\\\
Given the observations and $\alpha$,$\beta$ as beta distribution parameters we can write the expected posterior mean for $\mu$ as follows:
\[ E_{\mu}[\mu|\mathcal{D}]=\frac{m+\alpha}{m+\ell+\alpha+\beta}=\frac{m}{m+\ell+\alpha+\beta}+
\frac{\alpha}{m+\ell+\alpha+\beta}\]
However:
\[\frac{m}{m+\ell+\alpha+\beta}=\frac{\frac{m}{m+\ell}}{\frac{m+\ell+\alpha+\beta}{m+\ell}}\]
\[\frac{\alpha}{m+\ell+\alpha+\beta}=\frac{\frac{\alpha}{\alpha+\beta}}{\frac{m+\ell+\alpha+\beta}{\alpha+\beta}}\]
Since $\frac{\alpha}{\alpha+\beta}$ is the prior mean value of $\mu$ and $\frac{m}{m+\ell}$ is the maximum likelyhood estimate we have shown what was being asked.

\subsection{Poisson distribution}
\textbf{Problem 4:}\\\\
The likelihood function is:
\[ L(\lambda) =\prod_{i=1}^{n}{\frac{\lambda^{x_i}e^{-\lambda}}{x_i !}} = \frac{\lambda^{\sum {x_i}}e^{-\lambda}}{\prod{x_i !}} \]
Then, taking the natural logarithm, we have:
\[ ln L(\lambda) = \sum_{i=1}^{n}{x_i ln \lambda} - n\lambda - \sum_{i=1}^{n}{ln(x_i !)} \]
Differentiating with respect to $\lambda$ results in:
\[ \frac{d ln L(\lambda)}{d\lambda} = \frac{\sum{x_i}}{\lambda} - n \]
Setting the derivative to zero we get:
\[ \frac{\sum{x_i}}{\lambda} - n = 0 \]
Therefore the MLE for $\lambda$ is:
\[  \hat{\lambda} = \frac{\sum{x_i}}{n}\]
To show that the maximum likelihood estimator is an unbiased estimator of $\lambda$ we have to show that $E(\hat{\lambda}) = p$.
\[ E(\hat{\lambda}) = E() = \frac{1}{n}\sum_{i=1}^{n}{E(X_i)} =\frac{1}{n}\sum_{i=1}^{n}{p} = \frac{1}{n}(np) = p \]
Thus, the estimator is unbiased.

\end{document}


\section{Solving and Estimating the Extended Model}

\subsection{Solution}

For this extended model I only use the Double Deep Q-Network agent, since it was shown with the simpler environment, to have comparable performance to the VFI implementation and Deep Q-network. The model is solved by running 3000 episodes. As was true for the simple model, the neural network has the best performance if states are scaled mean 0 and a standard deviation of 1. In practice this is done by implementing a transformer in my agent that scales the states.  The transformer is also capable of doing an inverse transformation. The rewards are also scaled. This slightly improves performance, but the primary reason is, that it helps track the learning. I scale the rewards to have a variance of about 1, and let them have the same mean conditional of the $\beta_L$  value! I train the algorithm for 3000 episodes, have the hyper parameters of the algorithm being: $\gamma=0.99$ representing the impatience of the agent. The agent is initialized with $\epsilon=1.0$ which decays by $0.9999$ for each step the agent performs. The learning rate is $\alpha=0.0005$. The size of the memory buffer is one million rows, and I train with a batch size=64. I let the minimum exploration rate in training be $0.01$.  The architecture of the network is identical to the one used previously: An input layer of same size as the state space, 2 fully connected layers of size 256 with rectified linear units as activation functions, and a linear output layer of the same size as the action space. At the beginning of each episode a random $\beta_L \sim Uniform(0, 60)$ is drawn, allowing the agent to step through an episode until termination with given $\beta_L$. Finally the target network inherits the policy weights every $100$'th step. A score for every 50'th episode is calculated, taking the average of the previous 50 episodes. If the current iteration of the model beats the high score, the weights of the neural network is saved. The estimation and simulation is performed with the weights that yields the highest score for 50 consecutive episodes.

\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.4]{figures/ddqn_extended_model_training_performance.png}
    \caption{Training Performance of Double DQN Agent - Extended Model}
    \label{fig:training_extended}
\end{figure}

Looking to figure \ref{fig:training_extended} the agent clearly learns to navigate in the environment. After about 1000 episodes the agent seems to have learned to navigate the environment! The maximum score appears at around episode 1400, which is the weights used for estimation and simulations. The asymptotic training performance is about 177 comparing to an initial score of approximately zero.

\subsection{Estimation}

As was the case with the simpler model, only a single parameter $\beta_L$ needs to be estimated. Again, just as was the case before with the simpler model, I extend the state space to contain $\beta_L$. I use a grid search in the range $\beta_L \in [0, 60]$, simulating $N=800$ observations, calculating the objective function. I use the same seed in each iteration of the optimization process. To address the short comings of the simple model, I expand the objective function of the optimization problem. In the initial model too many women choose not to be part of the labour force yielding unrealistic results. In response to this problem the new objective function extends to two broad goals: Let the right number of women be out of the labour force (around 15 \%) and fit the curve of number of working hours for women. The first objective, \textit{objective 1}, is formulated as:

\begin{equation}
    \text{objective 1} = \lsp\frac{\sum_{i=1}^{N} \sum_{q=Q_{\min}}^{Q_{\max}} \mathbf{1}\{H_{i,q} = 0\}}{ N \cdot (Q_{\max} - Q_{\min} )} - 15\% \rsp^2
\end{equation}

The second objective is formulated the same way as it was when first estimating the simple model, which correspond the conditional expectation of supplied number of working hours conditional on the age and of being in the labour force $ \E[H \mid Q=q, H>0]$. The desired outcome is for this to be true for all ages from 18 to 60. $\mu_q$ is the empirical moment found using the data \textbf{LIGEF15}:

\begin{equation}
    \text{Objective 2} = \sum_{q=Q_{\min}}^{Q_{\min}} \lsp \mu_q  - \frac{1}{\sum_{i=1}^{N} \mathbf{1}\{H_{i,q} > 0\}}\sum_{i=1}^N (H_{i,q})\rsp^2
\end{equation}
The description of the objectives can be translated into a more formal formulation. The number of moments are $\#_{moments} = 1 + (Q_{\max} - Q_{\min}) = 1 + 60 - 18 = 43$. The weighing of these moments would usually be done by some weight matrix $W$ in an equation of the form: $[\hat{m} - \tilde{m}]^{\top} W^{-1} [\hat{m} - \tilde{m}]$, where $\tilde{m}$ is a vector of empirical moments and $\hat{m}$ is a vector of simulated moments allowing for the methods of moments estimation. The choosing of the weight matrix is application specific. \textcite{eisenhauer_estimation_2015} suggests the choice in that setting should be the inverse variance of the empirical moments $\tilde{m}_j$, on the diagonal of the weight matrix (zeros else), letting the $j$'th moment correspond to the $j$'th weight. This is however not possible in this application, due to the fact, that I only have access to aggregated data from statistics Denmark. Instead, I manually choose scales such that \textit{objective 1} is equally weighted to \textit{objective 2}. This first and foremost requires a scaling of the moments. And secondly, all this requires a re-weighing since there are 42 moments composing \textit{objective 2} and only a single moment composing \textit{objective 1}. Since the distance between the empirical and the simulated moment is squared, the scaling must be performed before the squaring. Finally, since the weight matrix is chosen as it is, a transformation can be performed such that instead of a matrix product it can be considered a sum: $\sum_{j = 1}
^{43} ( \hat{m}_j - \tilde{m}_j )^2$, becoming a mean squared error optimization problem. It is implied that $N$ agents is simulated conditional on a value of $\beta_L$. The objective function is:

\begin{multline}
   \text{Objective}(\beta_L) =  \lsp 37 \cdot \lp\frac{\sum_{i=1}^{N} \sum_{q=Q_{\min}}^{Q_{\max}} \mathbf{1}\{H_{i,q} = 0\}}{ N \cdot (Q_{\max} - Q_{\min} )} - 15\% \rp \rsp^2 \\ + \frac{1}{Q_{\max} - Q_{\min}}\sum_{q=Q_{\min}}^{Q_{\max}} \lsp \mu_q - \frac{1}{\sum_{i=1}^{N} \mathbf{1}\{H_{i,q} > 0\}}\sum_{i=1}^N (H_{i,q})\rsp^2
\end{multline}

\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.4]{figures/ddqn_extended_model_estimation_beta_L.png}
    \caption{Estimation of $\beta_L$ for the Extended Model}
    \label{fig:estimation_extended}
\end{figure}

The estimated value of $\beta_L = 24.49$. Figure \ref{fig:estimation_extended} shows the grid search, and finds that optimization problem, contains a minimum at $\beta_L = 24.49$, suggesting that the range of the grid is adequate for the estimation problem. I take the $\log (\cdot)$ of the mean squared error to better represent it in figure \ref{fig:estimation_extended}.


\section{Functions between topologies}


\documentclass{parcfd2015}

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\title{PetIBM - A PETSc-based Immersed Boundary Method code}

\author{OLIVIER P. MESNARD$^{*}$, ANUSH KRISHNAN$^{*}$ \\ AND LORENA A. BARBA$^{*}$}

\heading{Olivier P. Mesnard, Anush Krishnan and Lorena A. Barba}

\address{$^{*}$ Mechanical and Aerospace Engineering, The George Washington University\\
Washington, DC, 20052, United-States\\
e-mail: mesnardo@gwu.edu, web page: lorenabarba.com}

\keywords{Immersed Boundary Method, PETSc, flying snake}

\abstract{A new, open-source \texttt{PETSc}-based immersed boundary method code is under development that uses a fully discrete projection formulation. Its initial purpose is to study the three-dimensional flow around an accurate cross-sectional shape of the flying snake species \textit{Chrysopelea paradisi}. We analyze vorticity structures in the wake and explain the enhanced lift generation of the snake at a particular angle of attack.}

\begin{document}
\maketitle

\section{IMMERSED BOUNDARY METHOD}

Immersed boundary methods (IBM) form a class of techniques in computational fluid dynamics where an immersed boundary is represented by a collection of Lagrangian points that do not coincide with the Eulerian grid nodes. They are particularly useful to simulate flows over complex and moving geometries. Simple, structured Cartesian meshes covering the entire physical domain (including the solid region) can be used, requiring low memory storage. The governing equations are solved over the whole domain and the key is finding a way to incorporate the boundary conditions on the immersed surface.

We use the method proposed by Taira and Colonius \cite{Taira_Colonius_2007} in which the momentum equations are augmented by a forcing term that acts as a Lagrange multiplier to bring the fluid to rest in the vicinity of the body surface. The fully-discrete modified Navier-Stokes equations produce an algebraic system that is solved via a projection method by performing a block LU decomposition \cite{Perot_1993}.

\section{PETIBM}

We use the open-source library \texttt{PETSc} \cite{PETSc_webpage_2014} to build the IBM code, taking advantage of its efficient data structures and routines to solve partial differential equations on multi-CPUs. The \texttt{PETSc} data structure \textit{distributed array} allows us to perform a logically Cartesian decomposition, such that nodal values spatially close in the physical domain are stored on the same process, thus, minimizing communications when using finite-difference stencils. Explicit terms of the Navier-Stokes system are stored using \textit{local vectors} that include ghost-cell values while \textit{global vectors} are used in sparse linear algebra routines.

The full code, named \texttt{PetIBM}, is open-source, released under an MIT License and hosted on the version-controlled platform GitHub \cite{PetIBM}.

\section{APPLICATION TO FLYING SNAKES}

We study the aerodynamics of the \textit{Chrysopelea paradisi}, a species of flying snake. Previous experimental work \cite{Holden_et_al_2014} reported enhanced lift force on a snake gliding at angle of attack of $35^o$ for flows with Reynolds number beyond $9000$. Two-dimensional numerical investigations confirmed a spike in the lift curve at this particular angle of attack ($Re=2000$) \cite{Krishnan_et_al_2014}. Using \texttt{PetIBM}, we aim to understand the three-dimensional wake structures responsible for high gliding performances of the paradise tree snake.

\begin{figure}[h!]
\centering
\includegraphics[width=8cm]{images/flying_snake_petibm.png}
\caption{Contours of the spanwise (red and blue) and streamwise (grey) components of the vorticity shed in the wake of an infinitely long cylinder with cross-section of the \textit{Chrysopelea paradisi}.}
\label{flying_snake_petibm}
\end{figure}

\begin{thebibliography}{99}
\bibitem{PETSc_webpage_2014} Balay S., Abhyankar S., Adams M.F., Brown J., Brune P., Buschelman K., Eijkhout V., Gropp W.D., Kaushik D., Knepley M.G., Curfman McInnes L., Rupp K., Smith B.F. and Zhang H. PETSc Web page. \texttt{http://www.mcs.anl.gov/petsc} (2014).
\bibitem{Holden_et_al_2014} Holden D., Socha J.J., Cardwell N.D. and Vlachos P.P. Aerodynamics of the flying snake Chrysopelea paradisi: how a bluff body cross-sectional shape contributes to gliding performance. \textit{J. Exp. Biol.} (2014) \textbf{217}:382--394.
\bibitem{PetIBM} Krishnan A. and Barba L.A. PetIBM - A 3D and parallel PETSc-based immersed boundary method code. \texttt{https://www.github.com/barbagroup/PetIBM}.
\bibitem{Krishnan_et_al_2014} Krishnan A., Socha J.J., Vlachos P.P. and Barba L.A. Lift and wakes of flying snakes. \textit{Phys. Fluids} (2014) \textbf{26(3)}:031901.
\bibitem{Perot_1993} Perot J.B. An analysis of the fractional step method. \textit{J. Comp. Phys.} (1993) \textbf{108(1)}:51--58.
\bibitem{Taira_Colonius_2007} Taira K. and Colonius T. The immersed boundary method: A projection approach. \textit{J. Comp. Phys.} (2007) \textbf{225(2)}:2118--2137.
\end{thebibliography}

\end{document}


\section{Instance models and instance graphs}
\label{sec:transformation_framework:instance_models_and_instance_graphs}

In the previous section, the structure of the framework was applied to type models and type graphs. In this section, the structure will be applied to instance models and instance graphs. Since instance models and instance graphs directly depend on type models and type graphs, some definitions will be borrowed from the previous section.

First, the general structure of the framework applied to instance models and instance graphs is discussed. Then the required definitions and theorems are given.

\begin{figure}
    \centering
    \begin{tikzpicture}
    \path
    (-3,4) node[circle,draw,minimum size=10mm,inner sep=0pt](ME) {$O$}
    (-4.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](MA) {$Im_A$}
    (-1.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](MB) {$Im_B$}
    (-3,0) node[circle,draw,minimum size=10mm,inner sep=0pt](MAB) {$Im_{AB}$}

    (3,4) node[circle,draw,minimum size=10mm,inner sep=0pt](GN) {$N$}
    (1.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](GA) {$IG_A$}
    (4.5,2) node[circle,draw,minimum size=10mm,inner sep=0pt](GB) {$IG_B$}
    (3,0) node[circle,draw,minimum size=10mm,inner sep=0pt](GAB) {$IG_{AB}$};

    \path[]
    (ME) [-, black, out=240, in=90] edge node[above] {} (MA)
    (ME) [-, black, out=300, in=90] edge node[above] {} (MB)

    (MA) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (MAB)
    (MB) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (MAB)

    (GN) [-, black, out=240, in=90] edge node[above] {} (GA)
    (GN) [-, black, out=300, in=90] edge node[above] {} (GB)

    (GA) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (GAB)
    (GB) [-{Latex[width=5]}, black, out=270, in=90] edge node[above] {} (GAB)

    (ME) [-{Latex[width=5]}, black, out=25, in=155] edge node[above] {$f$} (GN)
    (GN) [-{Latex[width=5]}, black, out=165, in=15] edge node[above] {} (ME)

    (MA) [-{Latex[width=5]}, black, out=35, in=145] edge node[above] {$f_A$} (GA)
    (GA) [-{Latex[width=5]}, black, out=155, in=25] edge node[above] {} (MA)

    (MB) [-{Latex[width=5]}, black, out=35, in=145] edge node[above] {$f_B$} (GB)
    (GB) [-{Latex[width=5]}, black, out=155, in=25] edge node[above] {} (MB)

    (MAB) [-{Latex[width=5]}, black, out=25, in=155] edge node[above] {$f_{A} \sqcup f_{B}$} (GAB)
    (GAB) [-{Latex[width=5]}, black, out=165, in=15] edge node[above] {} (MAB)
    ;
    \end{tikzpicture}
    \caption{Structure for transforming between instance models and instance graphs}
    \label{fig:transformation_framework:instance_models_and_instance_graphs:structure_instance_models_graphs}
\end{figure}

\cref{fig:transformation_framework:instance_models_and_instance_graphs:structure_instance_models_graphs} shows one more alternation of the structure proposed in \cref{sec:transformation_framework:structure}. This version of the structure is applied to instance models and instance graphs. As before, instance model $Im_A$ represents the partially build model which corresponds to instance graph $IG_A$ under the transformation function $f_A$. Instance model $Im_B$ represents the next building block to add to this model. It corresponds to instance graph $IG_B$ under the bijective transformation function $f_B$.

Instance models $Im_A$ and $Im_B$ are entirely distinct except for a set objects $O$, which means $O \subseteq Object_{Im_A} \land O \subseteq Object_{Im_B}$. In a similar way, instance graphs $IG_A$ and $IG_B$ are entirely distinct except for a set of nodes $N$, so $N \subseteq N_{IG_A} \land N \subseteq N_{IG_B}$.

Instance models $Im_A$ and $Im_B$ are combined into instance model $Im_{AB}$ using \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_instance_models:combine}. In a similar way instance graphs $IG_A$ and $IG_B$ are combined into instance graph $IG_{AB}$ using \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_instance_graphs:combine}. \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_instance_models:imod_combine_merge_correct} and \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_instance_graphs:ig_combine_merge_correct} respectively show that $Im_{AB}$ and $IG_{AB}$ are valid. Then \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:combination_transformation_function_instance_model_instance_graph} and \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:combination_transformation_function_instance_graph_instance_model} can be used to merge the transformation functions $f_A$ and $f_B$ into $f_{A} \sqcup f_{B}$, where \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:ig_combine_mapping_correct} and \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:ig_combine_mapping_function_correct} show that $f_{A} \sqcup f_{B}$ is again a valid transformation function transforming $Im_{AB}$ to $IG_{AB}$. Similarly, \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:imod_combine_mapping_correct} and \cref{defin:transformation_framework:instance_models_and_instance_graphs:combining_transformation_functions:imod_combine_mapping_function_correct} show that the inverse function of $f_{A} \sqcup f_{B}$ is again a valid transformation function transforming $IG_{AB}$ to $Im_{AB}$.

\input{tex/04_transformation_framework/04_instance_models_and_instance_graphs/01_combining_instance_models.tex}
\input{tex/04_transformation_framework/04_instance_models_and_instance_graphs/02_combining_instance_graphs.tex}
\input{tex/04_transformation_framework/04_instance_models_and_instance_graphs/03_combining_transformation_functions.tex}