\section{Implicit Differentiation}\label{sec:ImplicitDiff}
As we have seen, there is a close relationship
between the derivatives of $\ds e^x$ and $\ln x$ because these functions
are inverses. Rather than relying on pictures for our understanding,
we would like to be able to exploit this relationship
computationally.  In fact this technique can help us find derivatives
in many situations, not just when we seek the derivative of an inverse
function.

We will begin by illustrating the technique to find what we already
know, the derivative of $\ln x$. Let's write $y=\ln x$ and then
$\ds x=e^{\ln x}=e^y$, that is, $\ds x=e^y$. We say that this equation
defines the function $y=\ln x$
implicitly because while it is not an explicit expression $y=\ldots$, it is true
that if $\ds x=e^y$ then $y$ is in fact the natural logarithm
function. Now, for the time being, pretend that all we know of $y$ is
that $\ds x=e^y$; what can we say about derivatives? We can take the
derivative of both sides of the equation:
$$\frac{d}{dx}x=\frac{d}{dx}e^y.$$
Then using the chain rule on the right hand side:
$$1 = \left(\frac{d}{dx}y\right) e^y = y'e^y.$$
Then we can solve for $y'$:
$$y'=\frac{1}{e^y} = \frac{1}{x}.$$
There is one little difficulty here. To use the chain rule to compute
$\ds d/dx(e^y)=y'e^y$ we need to know that the function $y$ {\it has} a
derivative. All we have shown is that {\it if} it has a derivative
then that derivative must be $1/x$. When using this method we will
always have to assume that the desired derivative exists, but
fortunately this is a safe assumption for most such problems.

The example $y=\ln x$ involved an inverse function defined implicitly,
but other functions can be defined implicitly, and sometimes a single
equation can be used to implicitly define more than one
function.

Here's a familiar example.

\begin{example}{Derivative of Circle Equation}{impcircles}
The equation $\ds r^2=x^2+y^2$
describes a circle of radius $r$. The circle is not a function
$y=f(x)$ because for some values of $x$ there are two corresponding
values of $y$. If we want to work with a function, we can break the
circle into two pieces, the upper and lower semicircles, each of which
is a function. Let's call these $y=U(x)$ and $y=L(x)$; in fact this is
a fairly simple example, and it's possible to give explicit
expressions for these: $\ds U(x)=\sqrt{r^2-x^2\ }$ and
$\ds L(x)=-\sqrt{r^2-x^2\ }$.  But it's somewhat easier, and quite useful,
to view both functions as given implicitly by $\ds r^2=x^2+y^2$: both
$\ds r^2=x^2+U(x)^2$ and $\ds r^2=x^2+L(x)^2$ are true, and we can think of
$\ds r^2=x^2+y^2$ as defining both $U(x)$ and $L(x)$.

Now we can take the derivative of both sides as before, remembering
that $y$ is not simply a variable but a function---in this case, $y$
is either $U(x)$ or $L(x)$ but we're not yet specifying which one.
When we take the derivative we just have to remember to apply the
chain rule where $y$ appears.
\begin{eqnarray*}
\frac{d}{dx}r^2&=&\frac{d}{dx}(x^2+y^2)\\
0&=&2x+2yy'\\
y'&=&\frac{-2x}{2y}=-\frac{x}{y}
\end{eqnarray*}
Now we have an expression for $y'$, but it contains $y$ as well as
$x$. This means that if we want to compute $y'$ for some particular
value of $x$ we'll have to know or compute $y$ at that value of $x$ as
well. It is at this point that we will need to know whether $y$ is
$U(x)$ or $L(x)$. Occasionally it will turn out that we can avoid
explicit use of $U(x)$ or $L(x)$ by the nature of the problem.
\end{example}

\begin{example}{Slope of the Circle}{SlopeCircle}
Find the slope of the circle $\ds 4=x^2+y^2$ at the point
$\ds (1,-\sqrt{3})$.
\end{example}

\begin{solution}
Since we know both the $x$ and $y$ coordinates of the
point of interest, we do not need to explicitly recognize that this
point is on $L(x)$, and we do not need to use $L(x)$ to compute
$y$ -- but we could. Using the calculation of $y'$ from above,
$$y'=-\frac{x}{y}=-\frac{1}{-\sqrt{3}}=\frac{1}{\sqrt{3}}.$$
It is instructive to compare this approach to others.

We might have recognized at the start that $\ds (1,-\sqrt{3})$ is on the
function $\ds y=L(x)=-\sqrt{4-x^2}$. We could then take the derivative of
$L(x)$, using the power rule and the chain rule, to get
$$L'(x)=-{1\over 2}(4-x^2)^{-1/2}(-2x)={x\over\sqrt{4-x^2}}.$$
Then we could compute $\ds L'(1)=1/\sqrt{3}$ by substituting $x=1$.

Alternately, we could realize that the point is on $L(x)$, but use the
fact that $y'=-x/y$. Since the point is on $L(x)$ we can replace $y$
by $L(x)$ to get
$$y'=-\frac{x}{L(x)}=-\frac{x}{\sqrt{4-x^2}},$$
without computing the derivative of $L(x)$ explicitly. Then we
substitute $x=1$ and get the same answer as before.
\end{solution}

In the case of the circle it is possible to find the functions $U(x)$
and $L(x)$ explicitly, but there are potential advantages to using
implicit differentiation anyway. In some cases it is more difficult or
impossible to find an explicit formula for $y$ and implicit
differentiation is the only way to find the derivative.

\begin{example}{Derivative of Function defined Implicitly}{FunctionDefinedImplicitly}
Find the derivative of any function defined implicitly by
$\ds yx^2+y^2=x$.
\end{example}

\begin{solution}
We treat $y$ as an unspecified function and use the
chain rule:
\begin{eqnarray*}
\frac{d}{dx}(yx^2+y^2)&=&\frac{d}{dx}x\\
(y\cdot 2x+y'\cdot x^2)+2yy'&=1\\
y'\cdot x^2+2yy'&=&-y\cdot 2x\\
y'&=&\frac{-2xy}{x^2+2y}
\end{eqnarray*}
\end{solution}

\begin{example}{Derivative of Function defined Implicitly}{FunctionDefinedImplicitly2}
Find the derivative of any function defined implicitly by
$\ds yx^2+e^y=x$.
\end{example}

\begin{solution}
We treat $y$ as an unspecified function and use the
chain rule:
\begin{eqnarray*}
\frac{d}{dx}(yx^2+e^y)&=&\frac{d}{dx}x\\
(y\cdot 2x+y'\cdot x^2)+y'e^y &=& 1\\
y'x^2+y'e^y&=& 1-2xy\\
y'(x^2+e^y)&=& 1-2xy\\
y'&=&\frac{1-2xy}{x^2+e^y}
\end{eqnarray*}
\end{solution}

You might think that the step in which we solve for $y'$ could
sometimes be difficult---after all, we're using implicit
differentiation here because we can't solve the equation
$\ds yx^2+e^y=x$ for $y$, so maybe after taking the derivative we get
something that is hard to solve for $y'$. In fact, {\it this never
  happens.} All occurrences $y'$ come from applying the chain rule,
and whenever the chain rule is used it deposits a single $y'$
multiplied by some other expression. So it will always be possible to
group the terms containing $y'$ together and factor out the $y'$, just
as in the previous example. If you ever get anything more difficult
you have made a mistake and should fix it before trying to continue.

It is sometimes the case that a situation leads naturally to an
equation that defines a function implicitly.

\begin{example}{Equation and Derivative of Ellipse}{Ellipse}
Discuss the equation and derivative of the ellispe.
\end{example}

\begin{solution}
Consider all the points $(x,y)$ that have the property that
the distance from $(x,y)$ to $\ds (x_1,y_1)$ plus the distance
from $(x,y)$ to $\ds (x_2,y_2)$ is $2a$ ($a$ is some constant). These
points form an ellipse, which like a circle is not a function but can be
viewed as two functions pasted together. Since we know how to write
down the distance between two points, we can write down an implicit
equation for the ellipse:
$$\sqrt{(x-x_1)^2+(y-y_1)^2}+\sqrt{(x-x_2)^2+(y-y_2)^2}=2a.$$
Then we can use implicit differentiation to find the slope of the
ellipse at any point, though the computation is rather messy.
\end{solution}

\begin{example}{Derivative of Function defined Implicitly}{FunctionDefinedImplicitly3}
Find $\ds\frac{dy}{dx}$ by implicit differentiation if
$$2x^3+x^2y-y^9=3x+4.$$
\vspace{-0.5cm}
\end{example}

\begin{solution}
Differentiating both sides with respect to $x$ gives:
$$6x^2+\left(2xy+x^2\frac{dy}{dx}\right)-9y^8\frac{dy}{dx}=3,$$
$$x^2\frac{dy}{dx}-9y^8\frac{dy}{dx}=3-6x^2-2xy$$
$$\left(x^2-9y^8\right)\frac{dy}{dx}=3-6x^2-2xy$$
$$\frac{dy}{dx}=\frac{3-6x^2-2xy}{x^2-9y^8}.$$
\end{solution}

In the previous examples we had functions involving $x$ and $y$, and we
thought of $y$ as a function of $x$.  In these problems we
differentiated with respect to $x$. So when faced with $x$'s in the
function we differentiated as usual, but when faced with $y$'s we
differentiated as usual except we multiplied by a $\frac{dy}{dx}$ for
that term because we were using Chain Rule.

In the following example we will assume that both $x$ and $y$ are
functions of $t$ and want to differentiate the equation with respect
to $t$.  This means that every time we differentiate an $x$ we will be
using the Chain Rule, so we must multiply by $\frac{dx}{dt}$, and
whenever we differentiate a $y$ we multiply by $\frac{dy}{dt}$.

\begin{example}{Derivative of Function of an Additional Variable}{FunctionAdditionalVariable}
Thinking of $x$ and $y$ as functions of $t$, differentiate the following equation with respect to $t$:
$$x^2+y^2=100.$$
\vspace{-0.5cm}
\end{example}

\begin{solution}
Using the Chain Rule we have:
$$2x\frac{dx}{dt}+2y\frac{dy}{dt}=0.$$
\end{solution}

\begin{example}{Derivative of Function of an Additional Variable}{FunctionAdditionalVariable2}
If $y=x^3+5x$ and $\ds\frac{dx}{dt}=7$, find $\ds\frac{dy}{dt}$ when $x=1$.
\end{example}

\begin{solution}
Differentiating each side of the equation $y=x^3+5x$ with respect to $t$ gives:
$$\frac{dy}{dt}=3x^2\frac{dx}{dt}+5\frac{dx}{dt}.$$
When $x=1$ and $\frac{dx}{dt}=7$ we have:
$$\frac{dy}{dt}=3(1^2)(7)+5(7)=21+35=56.$$
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection*{Logarithmic Differentiation}
Previously we've seen how to do the derivative of a number to a function $(a^{f(x)})'$, and also a function to a number $[(f(x))^n]'$.
But what about the derivative of a function to a function $[(f(x))^{g(x)}]'$?

In this case, we use a procedure known as \dfont{logarithmic differentiation}.

\begin{formulabox}[Steps for Logarithmic Differentiation]
\begin{itemize}
\item Take $\ln$ of both sides of $y=f(x)$ to get $\ln y=\ln f(x)$ and simplify using logarithm properties,
\item Differentiate implicitly with respect to $x$ and solve for $\ds\frac{dy}{dx}$,
\item Replace $y$ with its function of $x$ (i.e., $f(x)$).
\end{itemize}
\end{formulabox}

\begin{example}{Logarithmic Differentiation}{LogarithmicDifferentiation}
Differentiate $y=x^x$.
\end{example}

\begin{solution}
We take $\ln$ of both sides:
$$\ln y=\ln x^x.$$
Using log properties we have:
$$\ln y = x\ln x.$$
Differentiating implicitly gives:
$$\frac{y'}{y}=(1)\ln x+x\frac{1}{x}.$$
$$\frac{y'}{y}=\ln x+1.$$
Solving for $y'$ gives:
$$y'=y(1+\ln x).$$
Replace $y=x^x$ gives:
$$y'=x^x(1+\ln x).$$

Another method to find this derivative is as follows:
\begin{eqnarray*}
\frac{d}{dx}x^x&=&\frac{d}{dx}e^{x\ln x}\\
&=&\left(\frac{d}{dx}x\ln x\right)e^{x\ln x}\\
&=&(x\frac{1}{x}+\ln x)x^x\\
&=&(1+\ln x)x^x
\end{eqnarray*}
\end{solution}

In fact, logarithmic differentiation can be used on more complicated
products and quotients (not just when dealing with functions to the
power of functions).

\begin{example}{Logarithmic Differentiation}{LogarithmicDifferentiation2}
Differentiate (assuming $x>0$):
$$y=\frac{(x+2)^3(2x+1)^9}{x^8(3x+1)^4}.$$
\vspace{-0.5cm}
\end{example}

\begin{solution}
Using product \& quotient rules for this problem is a complete nightmare!
Let's apply logarithmic differentiation instead.
Take $\ln$ of both sides:
$$\ln y=\ln\left(\frac{(x+2)^3(2x+1)^9}{x^8(3x+1)^4}\right).$$
Applying log properties:
$$\ln y=\ln\left((x+2)^3(2x+1)^9\right)-\ln\left(x^8(3x+1)^4\right).$$
$$\ln y=\ln\left((x+2)^3\right)+\ln\left((2x+1)^9\right)-\left[\ln\left(x^8\right)+\ln\left((3x+1)^4\right)\right].$$
$$\ln y=3\ln(x+2)+9\ln(2x+1)-8\ln x-4\ln(3x+1).$$
Now, differentiating implicitly with respect to $x$ gives:
$$\frac{y'}{y}=\frac{3}{x+2}+\frac{18}{2x+1}-\frac{8}{x}-\frac{12}{3x+1}.$$
Solving for $y'$ gives:
$$y'=y\left(\frac{3}{x+2}+\frac{18}{2x+1}-\frac{8}{x}-\frac{12}{3x+1}\right).$$
Replace $y=\frac{(x+2)^3(2x+1)^9}{x^8(3x+1)^4}$ gives:
$$y'=\frac{(x+2)^3(2x+1)^9}{x^8(3x+1)^4}\left(\frac{3}{x+2}+\frac{18}{2x+1}-\frac{8}{x}-\frac{12}{3x+1}\right).$$
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for Section \ref{sec:ImplicitDiff}}

\begin{enumialphparenastyle}

%%%%%%%%%%
\begin{ex}
Find a formula for the derivative $y'$ at the point $(x,y)$:
\begin{multicols}{2}
\begin{enumerate}
	\item	$\ds y^2=1+x^2$
	\item	$\ds x^2+xy+y^2=7$
	\item	$\ds x^3+xy^2=y^3+yx^2$
	\item	$\ds 4\cos x \sin y = 1$
	\item	$\ds\sqrt{x} + \sqrt{y} = 9$
	\item	$\ds \tan(x/y) = x+ y$
	\item	$\ds \sin (x+y ) =xy$
	\item	$\ds\frac{1}{x} + \frac{1}{y} = 7$
\end{enumerate}
\end{multicols}
\begin{sol}
\begin{enumerate}
	\item	$\ds x/y$
	\item	$\ds -(2x+y)/(x+2y)$
	\item	$\ds (2xy-3x^2-y^2)/(2xy-3y^2-x^2)$
	\item	$\ds \sin(x)\sin(y)/(\cos(x)\cos(y))$
	\item	$\ds-\sqrt{y}/\sqrt{x}$
	\item	$\ds (y\sec^2(x/y)-y^2)/(x\sec^2(x/y)+y^2)$
	\item	$\ds (y-\cos(x+y))/(\cos(x+y)-x)$
	\item	$\ds -y^2/x^2$
\end{enumerate}
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A hyperbola passing through $(8,6)$ consists of all points whose distance
from the origin is a constant more than its distance from the point (5,2).
Find the slope of the tangent line to the hyperbola at $(8,6)$.
\begin{sol}
	$1$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
The graph of the equation $\ds x^2 - xy + y^2 = 9$ is an ellipse.
Find the lines tangent to this curve at the two
 points where it intersects the $x$-axis. Show that these lines are
 parallel.
\begin{sol}
	$y=2x\pm6$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Repeat the previous problem for the points at which the
 ellipse intersects the $y$-axis.
\begin{sol}
	$y=x/2\pm3$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
	If $\ds y=\log_a x$ then $\ds a^y=x$. Use implicit
	differentiation to find $\ds y'$.
\end{ex}

%%%%%%%%%%
\begin{ex}
Find the points on the ellipse from the previous two problems
 where the slope is horizontal and where it is vertical.
\begin{sol}
	$\ds (\sqrt3,2\sqrt3)$, $\ds (-\sqrt3,-2\sqrt3)$, $\ds (2\sqrt3,\sqrt3)$,
$\ds (-2\sqrt3,-\sqrt3)$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Find an equation for the tangent line to
$\ds x^4 = y^2 + x^2$ at $\ds (2, \sqrt{12})$.
(This curve is the \dfont{kampyle of Eudoxus}.)
\begin{sol}
	$\ds y=7x/\sqrt3-8/\sqrt3$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Find an equation for the tangent line to $\ds x^{2/3} +
y^{2/3} = a^{2/3}$ at a point $\ds (x_1 ,y_1)$ on the curve,
with $\ds x_1 \neq 0$ and $\ds y_1 \neq 0$. (This curve is an {\dfont astroid}.)
\begin{sol}
	$\ds y=(-y_1^{1/3}x+y_1^{1/3}x_1+x_1^{1/3}y_1)/x_1^{1/3}$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Find an equation for the tangent line to $\ds (x^2 +y^2 )^2 =x^2
-y^2$ at a point $\ds (x_1 , y_1)$ on the curve, with $\ds x_1 \neq 0, -1, 1$.
(This curve is a \dfont{lemniscate}.)
\begin{sol}
	$\ds (y-y_1)/(x-x_1)=(2x_1^3+2x_1y_1^2-x_1)/(2y_1^3+2y_1x_1^2+y_1)$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Two curves are \dfont{orthogonal} if at each point of intersection,
the angle between their tangent lines is $\pi/2$. Two
families of curves, $\cal{A}$ and $\cal{B}$, are
\dfont{orthogonal trajectories} of each other if given any curve $C$
in $\cal{A}$ and any curve $D$ in $\cal{B}$ the curves $C$
and $D$ are orthogonal.
For example, the family of horizontal lines in the plane is
orthogonal to the family of vertical lines in the plane.
\begin{enumerate}
	\item	Show that $\ds x^2 -y^2 =5$ is orthogonal to $\ds 4x^2 +9y^2
	=72$. (Hint: You need to find the intersection points of the two
	curves and then show that the product of the derivatives at each
	intersection point is $-1$.)
	\item	Show that $\ds x^2 +y^2 = r^2$ is orthogonal to
	$y=mx$. Conclude that the family of circles centered at the origin is
	an orthogonal trajectory of the family of lines that pass through the
	origin.

	Note that there is a technical issue when $m=0$. The circles fail to
	be differentiable when they cross the $x$-axis. However, the circles
	are orthogonal to the $x$-axis. Explain why. Likewise, the vertical
	line through the origin requires a separate argument.
	\item	For $k\not= 0$ and $c \neq 0$ show that $\ds y^2 -x^2 =k$ is orthogonal to
	$yx =c$. In the case where $k$ and $c$ are both zero, the curves
	intersect at the origin. Are the curves $\ds y^2 -x^2 =0$ and $yx=0$
	orthogonal to each other?
	\item	Suppose that $m\neq 0$. Show that the family of curves
	$\ds \{y=mx+b \mid b\in \R \}$ is orthogonal to the
	family of curves $\ds \{y=-(x/m)+c \mid c \in \R\}$.
\end{enumerate}
\end{ex}

%%%%%%%%%%
\begin{ex}
Differentiate the function $\ds y={(x-1)^8 (x-23)^{1/2}\over 27 x^6(4x-6)^8 }$
\end{ex}

\begin{ex}
Differentiate the function $\ds f(x)=(x+1)^{\sin x}$.
\end{ex}

\begin{ex}
Differentiate the function $\ds g(x)=\frac{e^x(\cos x+2)^3}{\sqrt{x^2+4}}$.
\end{ex}

\end{enumialphparenastyle}


\section{Concepts and Background}\label{sec:backgroundML}
Machine learning refers to a set of techniques for understanding data. The theoretical subject of ``learning'' is related to prediction. Machine learning techniques involve building a statistical model for predicting, or estimating an output based on one or more inputs. Regression models are used when the output is a continuous value. In this work, we used three different machine learning methods: Linear Regression, Support Vector Machines and Random Forest. There exists other machine learning techniques with sophisticated learning process. However, in this work, we wanted to use simple models to prove that they achieve reasonable predictions.

\subsection{Linear Regression (LR)}
Linear regression is a straightforward technique for predicting a quantitative response $Y$ on the basis of a single or multiple predictor variables $X_p$. It assumes that there is approximately a linear relationship between each $X_p$ and $Y$. It gives to each predictor a separate slope coefficient in a single model. Mathematically, we can write the multiple linear regression model as
\begin{equation}
Y \approx \beta_0 + \beta_1 X_1 + + \beta_2 X_2 + \ldots + + \beta_p X_p + \epsilon
\end{equation}
where $X_p$ represents the $p$th predictor and $\beta_p$ quantifies the association between that variable and the response.

\subsection{Support Vector Machines (SVM)}
Support Vector Machines is a widely used technique for classification and regression problems. It belongs to the general category of kernel methods, which are algorithms that depend on the data only through dot-products. The dot product can be replaced by a kernel function which computes a dot product in some possibly high dimensional feature space $Z$. It maps the input vector $x$ into the feature space $Z$ though some nonlinear mapping.

\subsection{Random Forest (RF)}
Random Forests belong to decision tree methods, capable of performing both regression and classification tasks. In general, a decision tree with $M$ leaves divides the feature space into $M$ regions $R_m$, $1 \leq m \leq M$. The prediction function of a tree is then defined as $f(x) = \sum_{m=1}^{M} c_m I(x, R_m)$, where $M$ is the number of leaves in the tree, $R_m$ is a region in the features space, $c_m$ is a constant corresponding to region $m$ and $I$ is the indicator function, which is 1 if $x \in R_m$, 0 otherwise. The values of $c_m$ are determined in the training process. Random forest consists of an ensemble of decision trees and uses the mode of the decisions of individual trees.

\subsection{Extraction Features Techniques}\label{ssec:ML}

Correlation techniques and hierarchical clustering algorithm were used in the phase of extraction features to reduce dimensionality of the features. Here, we show a short theoretical background of the techniques used in this work.

There exist different correlation functions, among them, Pearson, Spearman and Kendal. The Pearson's correlation evaluates the linear relationship between two continuous variables, but omit variation in different scales. The Spearman's correlation evaluates the monotonic relationship between two continuous or ordinal variables. Besides Spearman correlation consider relations in different scales and spaces of the features due to the rank variables.

Pearson's correlation is commonly represented by the greek letter ($\rho$) when it is used for populations and by the letter $r$ when it is used for samples. We will denote it with the letter $r$, the formula for $r$ in a simplified form is
\begin{equation}
r=\frac{\text{cov}(X,Y)}{\sigma_{X}\sigma_{Y}},
\end{equation}
where, cov($X,Y$) is the covariance between two variables, $X$ and $Y$, $\sigma_{X}$ is the standard deviation of $X$ and $\sigma _{Y}$ is the standard deviation of $Y$.

The Spearman correlation coefficient is defined as the Pearson correlation coefficient between the ranked variables~\citep{myers2010research}, for a sample of size $n$, the $n$ raw scores $X_{i}$, $Y_{i}$ are converted to ranks rg$X_{i}$ rg$Y_{i}$. Here, this correlation is denoted as $r_s$, the formula for $r_s$ in a short manner is
\begin{equation}
r_{s}=\frac{\text{cov}(rgX,rgY)}{\sigma_{rgX}\sigma_{rgY}},
\end{equation}
where cov($rgX,rgY$) is the covariance of the rank variables, and $\sigma_{rgX}$ and $\sigma_{rgY}$ are the standard deviations of the rank variables.

Hierarchical clustering creates groups from a distance matrix. Different metrics or distance functions exist in the literature, among them, Euclidean, Manhattan, Canberra, Binary or Minkowski, however, correlation functions can be also used. A heatmap of pair-wise correlations is a simple way to discover relationships between  pairs of quantitative variables in a dataset. A dendrogram is a tree diagram frequently used to illustrate the arrangement of the clusters produced by a hierarchical clustering algorithm. In Figure \ref{fig:heatMaphClust} is shown a dendrogram with its respective distance matrix using a Spearman correlation function. We can see in this figure a dendrogram with 10 different features about the profile information. In this figure red cells have a high correlation while blue cells have a low correlation.

\begin{figure}[htpb]
    \centering
    \includegraphics[scale=.5]{./images/heatMap.pdf}
    \caption{Heatmap and Dendrogram of a correlation matrix with some features in the experiments}
    \label{fig:heatMaphClust}
\end{figure}

A dendrogram is a tree diagram frequently used to illustrate the arrangement of the clusters produced by hierarchical clustering algorithms. In Figure \ref{fig:heatMaphClust} is shown a dendrogram with its respective matrix of correlation. This dendrogram can be cut in a certain height to permit create a specific number of clusters.


\section*{Ex.34.2-8}
\subsection*{Show that TAUTOLOGY $\in$ co-NP}

The question is analog to showing that $\overline{\text{TAUTOLOGY}}\in$ NP, where $\overline{\text{TAUTOLOGY}}$ is the complement of TAUTOLOGY.
\\
$\overline{\text{TAUTOLOGY}}$ must be the language of boolean formulas, where changing the assignment of at least one variable will cause the formula $\phi$ to evaluate to 0.

If we can verify a certificate in polynomial time, then $\overline{\text{TAUTOLOGY}}\in$ NP. A certificate would be an assignment of variables, and we can check in polynomial time, that $\overline{\text{TAUTOLOGY}}$ evaluates to 0.

Since $\overline{\text{TAUTOLOGY}}$ has fewer connectives than SAT, and no connectives that SAT does not, then $\overline{\text{TAUTOLOGY}}$ is a proper subset of SAT, i.e. $\overline{\text{TAUTOLOGY}} \subset \text{SAT}$. As SAT $\in$ NP, this then implies that $\overline{\text{TAUTOLOGY}} \in$ NP, which then means that TAUTOLOGY $\in$ co-NP.


\section{The Derivative Function}\label{sec:TheDerivativeFunction}
In Section \ref{sec:Slope}, we have seen how to create, or derive, a new function $f'(x)$ from a
function $f(x)$, and that this new function carries important
information. In one example we saw that $f'(x)$ tells us how steep the
graph of $f(x)$ is; in another we saw that $f'(x)$ tells us the velocity
of an object if $f(x)$ tells us the  position of the object at time
$x$. As we said earlier, this same mathematical idea is useful
whenever $f(x)$ represents some changing quantity and we want to know
something about how it changes, or roughly, the ``rate'' at which it
changes. Most functions encountered in practice are built up from a
small collection of ``primitive'' functions in a few simple ways, for
example, by adding or multiplying functions together to get new, more
complicated functions. To make good use of the information provided by
$f'(x)$ we need to be able to compute it for a variety of such functions.

We will begin to use different notations for the derivative of a
function. While initially confusing, each is often useful so it is
worth maintaining multiple versions of the same thing.

Consider again the function $\ds f(x)=\sqrt{625-x^2}$.
We have computed the derivative $\ds f'(x)=-x/\sqrt{625-x^2}$, and have
already noted that if we use the alternate notation
$\ds y=\sqrt{625-x^2}$ then we might write $\ds y'=-x/\sqrt{625-x^2}$.
Another notation is quite different, and in time it will become clear
why it is often a useful one. Recall that to compute the the
derivative of $f$ we computed
$$
\lim_{\Delta x\to0} {\sqrt{625-(7+\Delta x)^2} - 24\over \Delta x}.
$$
The denominator here measures a distance in the $x$ direction,
sometimes called the ``run'', and the numerator measures a distance in
the $y$ direction, sometimes called the ``rise,'' and ``rise over
run'' is the slope of a line. Recall that sometimes such a numerator is
abbreviated $\Delta y$, exchanging brevity for a more detailed
expression. So in general, we define a derivative by the following equation.

\begin{definition}{Defnition of Derivative}{DerDefn}
The derivative of $y=f(x)$ with respect to $x$ is
$$y'=\lim_{\Delta x\to0} {\Delta y\over \Delta x}.$$
Some textbooks use $h$ in place of $\Delta x$ in the definition of
derivative: $$f'(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}.$$
\end{definition}

To recall the form of the limit, we sometimes say instead that
$$
{dy\over dx}=\lim_{\Delta x\to0} {\Delta y\over \Delta x}.
$$
In other words, $dy/dx$ is another notation for the derivative, and
it reminds us that it is related to an actual slope between two
points. This notation is called \dfont{Leibniz notation},
after Gottfried Leibniz, who developed the fundamentals
of calculus independently, at about the same time that Isaac Newton
did.  Again, since we often use $f$ and $f(x)$ to mean the original
function, we sometimes use $df/dx$ and $df(x)/dx$ to refer to the
derivative. If the function $f(x)$ is written out in full we often
write the last of these something like this
$$f'(x)={d\over dx}\sqrt{625-x^2}$$
with the function written to the side, instead of trying to fit it into
the numerator.

\begin{example}{Derivative of $y=t^2$}{Derivative1}
Find the derivative of $\ds y=f(t)=t^2$.
\end{example}

\begin{solution}
We compute
\[ \begin{array}{rll}
y' &=& \ds\lim_{\Delta t\to0}\ds\frac{\Delta y}{\Delta t}  \\
\\
	&=&\ds\lim_{\Delta t\to0}\ds\frac{(t+\Delta t)^2-t^2}{\Delta t} \\
	\\
&=&\ds\lim_{\Delta t\to0}\ds\frac{t^2+2t\Delta t+\Delta t^2-t^2}{\Delta t} \\
\\
&=&\ds\lim_{\Delta t\to0}\ds\frac{2t\Delta t+\Delta t^2}{\Delta t} \\
\\
&=&\ds\lim_{\Delta t\to0} 2t+\Delta t=2t. \\
\end{array}\]
\end{solution}

Remember that $\Delta t$ is a single quantity, not a ``$\Delta$''
times a ``$t$'', and so $\ds \Delta t^2$ is $\ds (\Delta t)^2$ not
$\ds \Delta (t^2)$.
Doing the same example using the second formula for the derivative with $h$ in place of $\Delta t$ gives the following.
Note that we compute $f(t+h)$ by substituting $t+h$ in place of $t$ everywhere we see $t$ in the expression $f(t)$,
\textit{while making no other changes} (at least initially). For example, if $f(t)=t+\sqrt{(t+3)^2-t}$ then $f(t+h)=(t+h)+\sqrt{((t+h)+3)^2-(t+h)}=t+h+\sqrt{(t+h+3)^2-t-h}$.

\begin{example}{Derivative of $y=t^2$}{Derivative1b}
Find the derivative of $\ds y=f(t)=t^2$.
\end{example}

\begin{solution}
We compute
\[ \begin{array}{rll}
f'(t) &=& \ds\lim_{h\to0}\ds\frac{f(t+h)-f(t)}{h}  \\
\\
	&=&\ds\lim_{h\to0}\ds\frac{(t+h)^2-t^2}{h} \\
	\\
&=&\ds\lim_{h\to0}\ds\frac{t^2+2th+h^2-t^2}{h} \\
\\
&=&\ds\lim_{h\to0}\ds\frac{2th+h^2}{h} \\
\\
&=&\ds\lim_{h\to0} 2t+h=2t. \\
\end{array}\]
\end{solution}

\begin{example}{Derivative}{Derivative2}
Find the derivative of $y=f(x)=1/x$.
\end{example}

\begin{solution}
The computation:
\begin{eqnarray*}
y' &=& \lim_{\Delta x\to0}{\Delta y\over\Delta x}\cr
\\
&=&\lim_{\Delta x\to0}{ {1\over x+\Delta x} - {1\over x}\over \Delta
  x}\cr
\\
&=&\lim_{\Delta x\to0}{ {x\over x(x+\Delta x)} -
{x+\Delta x\over x(x+\Delta x)}\over \Delta x}\cr
\\
&=&\lim_{\Delta x\to0}{ {x-(x+\Delta x)\over x(x+\Delta x)}\over \Delta x}\cr
\\
&=&\lim_{\Delta x\to0} {x-x-\Delta x\over x(x+\Delta x)\Delta x}\cr
\\
&=&\lim_{\Delta x\to0} {-\Delta x\over x(x+\Delta x)\Delta x}\cr
\\
&=&\lim_{\Delta x\to0} {-1\over x(x+\Delta x)}={-1\over x^2}\cr
\end{eqnarray*}
\end{solution}

{\bf Note:}  If you happen to know some ``derivative formulas'' from
an earlier course, for the time being you should pretend that you do
not know them.
In examples like the ones above and the exercises below, you are required
to know how to find the derivative formula starting from basic principles.
We will later develop some formulas so that we do not always need to
do such computations, but we will continue to need to know how to do
the more involved computations.

To recap, given any function $f$ and any number $x$ in the domain of $f$, we define
$f'(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$ wherever this limit exists, and we call
the number $f'(x)$ the derivative of $f$ at $x$. Geometrically, $f'(x)$ is the slope of
the tangent line to the graph of $f$ at the point $(x,f(x))$.  The following
symbols also represent the derivative:
$$f'(x)=y'=\frac{dy}{dx}=\frac{df}{dx}=\frac{d}{dx}f(x).$$ The symbol
$d/dx$ is called a differential operator which means to take the
derivative of the function $f(x)$ with respect to the variable $x$.

In the next example we emphasize the geometrical interpretation of derivative.

\begin{example}{Geometrical Interpretation of Derivative}{GeometricalInterpretationDerivative}
Consider the function $f(x)$ given by the graph below.
Verify that the graph of $f'(x)$ is indeed the derivative of $f(x)$ by analyzing slopes of tangent lines to the graph at different points.
$$\includegraphics[width=2.5in]{images/deriv1}$$
\end{example}

\begin{solution}
We must think about the tangent lines to the graph of $f$, because the slopes
of these lines are the values of $f'(x)$.

We start by checking the graph of $f$ for horizontal tangent lines, since horizontal
lines have a slope of 0. We find that the tangent line is horizontal at the points
where $x$ has the values -1.9 and 1.8 (approximately). At each of these values of $x$,
we must have $f'(x)=0$, which means that the graph of $f'$ has an $x$-intercept (a point
where the graph intersects the $x$-axis).

Note that horizontal tangent lines have a slope of zero and these
occur approximately at the points $(-1.9,-3.2)$ and $(1.8,3.2)$ of the
graph.  Therefore $f'(x)$ will cross the $x$-axis when $x=-1.9$ and
$x=1.8$.

Analyzing the slope of the tangent line of $f(x)$ at $x=0$ gives
approximately $3.0$, thus, $f'(0)=3.0$.  Similarly, analyzing the
slope of the tangent lines of $f(x)$ at $x=1$ and $x=-1$ give
approximately $2.0$ for both, thus, $f'(1)=f'(-1)=2.0$.
\end{solution}

In the next example we verify that the slope of a straight line is $m$.

\begin{example}{Derivative of a Linear Function}{DerivativeLinearFunction}
Let $m,b$ be any two real numbers.
Determine $f'(x)$ if $f(x)=mx+b$.
\end{example}

\begin{solution}
By the definition of derivative (using $h$ in place of $\Delta x$) we have,
$$f'(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}=\lim_{h\to 0}\frac{(m(x+h)+b)-(mx+b)}{h}$$
$$=\lim_{h\to 0}\frac{mh}{h}=\lim_{h\to 0}m=m.$$

This is not surprising. We know that $f'(x)$ always represents the slope of a tangent
line to the graph of $f$. In this example, since the graph of $f$ is a straight line $y=mx+b$
already, every tangent line is the same line $y=mx+b$. Since this line has a slope of $m$,
we must have $f'(x)=m$.
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Subsections to include
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{4-derivatives/4-3-1-differentiable}
\input{4-derivatives/4-3-2-second-other-derivatives}
\input{4-derivatives/4-3-3-velocities}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for Section \ref{sec:TheDerivativeFunction}}

\begin{enumialphparenastyle}

%%%%%%%%%%
\begin{ex}
Find the derivatives of the following functions.
\begin{enumerate}
	\item	$\ds y=f(x)=\sqrt{169-x^2}$
	\item	$\ds y=f(t)=80-4.9t^2$
	\item	$\ds y=f(x)=x^2-(1/x)$
	\item	$\ds y=f(x)=ax^2+bx+c$, where $a$, $b$, and $c$ are constants.
	\item	$\ds y=f(x)=x^3$
	\item	$\ds y=f(x)=2/\sqrt{2x+1}$
	\item	$y=g(t)=(2t-1)/(t+2)$
\end{enumerate}
\begin{sol}
\begin{enumerate}
	\item	$\ds -x/\sqrt{169-x^2}$
	\item	$-9.8t$
	\item	$\ds 2x+1/x^2$
	\item	$2ax+b$
	\item	$\ds 3x^2$
	\item	$\ds -2/(2x+1)^{3/2}$
	\item	$\ds 5/(t+2)^2$
\end{enumerate}
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Shown is the graph of a function $f(x)$. Sketch the graph of $f'(x)$
by estimating the derivative at a number of points in the interval:
estimate the derivative at regular intervals from one end of the
interval to the other, and also at ``special'' points, as when the
derivative is zero. Make sure you indicate any places where the
derivative does not exist.
$$\vbox{\beginpicture
\normalgraphs
\setcoordinatesystem units <4.5truecm,4.5truecm>
\setplotarea x from -1 to 1, y from 0 to 1.6
\axis left ticks numbered from 0.2 to 1.6 by 0.2 /
\axis left shiftedto x=0 /
\axis bottom ticks numbered from -1 to 1 by 0.2 /
\setquadratic
\plot -0.900 0.800 -0.810 1.003 -0.720 1.148 -0.630 1.242 -0.540 1.291
-0.450 1.301 -0.360 1.280 -0.270 1.232 -0.180 1.166 -0.090 1.086
0.000 1.000 0.090 0.914 0.180 0.834 0.270 0.768 0.360 0.720
0.450 0.699 0.540 0.709 0.630 0.758 0.720 0.852 0.810 0.997
0.900 1.200  /
\linethickness 0.1truept
\axis left ticks in andacross from 0.1 to 1.6 by 0.1 /
\axis bottom ticks in andacross from -1 to 1 by 0.1 /
\endpicture}$$
\end{ex}

%%%%%%%%%%
\begin{ex}
Shown is the graph of a function $f(x)$. Sketch the graph of $f'(x)$
by estimating the derivative at a number of points in the interval:
estimate the derivative at regular intervals from one end of the
interval to the other, and also at ``special'' points, as when the
derivative is zero. Make sure you indicate any places where the
derivative does not exist.
$$\vbox{\beginpicture
\normalgraphs
\setcoordinatesystem units <1.8truecm,1.8truecm>
\setplotarea x from 0 to 5, y from 0 to 4
\axis left ticks numbered from 0 to 4 by 1 /
\axis bottom ticks numbered from 0 to 5 by 1 /
\plot 0 0 2 2 /
\setquadratic
\plot 2.000 2.000 2.135 1.747 2.270 1.531 2.405 1.351 2.540 1.209
2.675 1.103 2.810 1.034 2.945 1.002 3.080 1.007 3.215 1.049
3.350 1.128 3.485 1.244 3.620 1.396 3.755 1.586 3.890 1.812
4.025 2.075 4.160 2.375 4.295 2.712 4.430 3.086 4.565 3.497
4.700 3.945  /
\linethickness 0.1truept
\axis left ticks in andacross from 0.2 to 4 by 0.2 /
\axis bottom ticks in andacross from 0.2 to 5 by 0.2 /
\endpicture}$$
\end{ex}

%%%%%%%%%%
\begin{ex}
Find an equation for the tangent line to the graph of $\ds f(x)=5-x-3x^2$ at the point $x=2$
\begin{sol}
	$y=-13x+17$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Find a value for $a$ so that the graph of $\ds f(x)=x^2+ax-3$ has a horizontal tangent line at $x=4$.
\begin{sol}
	$-8$
\end{sol}
\end{ex}

\end{enumialphparenastyle}


\section*{Exercises}

\begin{ex}
  Compute $e^A$ and $\cos A$ for the following matrices:
  \begin{equation*}
    (a)\quad
    A = \begin{mymatrix}{rr}
      1 & 0 \\
      0 & 2 \\
    \end{mymatrix},
    \quad
    (b)\quad
    A = \begin{mymatrix}{rr}
      4  & 2  \\
      -3 & -1 \\
    \end{mymatrix},
    \quad
    (c)\quad
    A = \begin{mymatrix}{rrr}
      0 & 1 & 1 \\
      1 & 0 & -1 \\
      -1 & 1 & 2 \\
    \end{mymatrix}.
  \end{equation*}
\end{ex}

\begin{ex}
  The cube root is an analytic function. Compute the cube root of the
  matrix
  \begin{equation*}
    A = \begin{mymatrix}{rr}
      22 & -21 \\
      14 & -13 \\
    \end{mymatrix}.
  \end{equation*}
\end{ex}

\begin{ex}
  Use matrix exponentials to find the solution to the
  first-order linear differential equation
  \begin{equation*}
    \begin{mymatrix}{c}
      x \\
      y
    \end{mymatrix}^{\prime} = \begin{mymatrix}{rr}
      0 & -1 \\
      6 & 5
    \end{mymatrix} \begin{mymatrix}{c}
      x \\
      y
    \end{mymatrix}
  \end{equation*}
  with initial value
  \begin{equation*}
    \begin{mymatrix}{c}
      x(0) \\
      y(0)
    \end{mymatrix} =\begin{mymatrix}{r}
      2 \\
      2
    \end{mymatrix}.
  \end{equation*}
  Hint: form the matrix exponential $e^{At}$ and then the solution is
  $e^{At}\,\vect{v}_0$, where $\vect{v}_0$ is the initial vector.
  \begin{sol}
    The solution is
    \begin{equation*}
      e^{At}C = \begin{mymatrix}{c}
        8e^{2t} - 6e^{3t} \\
        18e^{3t} - 16e^{2t}
      \end{mymatrix}.
    \end{equation*}
  \end{sol}
\end{ex}


\section{Stack axioms}
\Label{sec:stack-axioms}

To specify the interplay of the stack access functions,
we use a set of axioms\footnote{
There is an analogy in geometry:
Euclid (e.g.\ \cite{Fitzpatrick.2008}) invented the use of
axioms there, but still kept definitions of \emph{point},
\emph{line}, \emph{plane}, etc.
Hilbert \cite{Hilbert.1968} recognized that the latter are not
only unformalizable, but also unnecessary, and dropped them,
keeping only the formal descriptions of relations between them.
},
all but one of them having the form of a conditional equation.

Let $V$ denote an arbitrary type.
We denote by $S_c$ the type of stacks with capacity $c > 0$ of
elements of type $V$.
The aforementioned functions then have the following signatures.

\begin{align*}
\mathrm{init} &:  S_c \rightarrow S_c, \\
\mathrm{push} &: S_c\times V \rightarrow S_c, \\
\mathrm{pop} &: S_c \rightarrow S_c,\\
\mathrm{top} &: S_c \rightarrow V, \\
\mathrm{size} &: S_c \rightarrow \mathbb{N}.\\
\end{align*}

With $\mathbb{B}$ denoting the \emph{boolean}
type we will also define two auxiliary functions
\begin{align*}
\mathrm{empty} &: S_c \rightarrow \mathbb{B},\\
\mathrm{full} &: S_c \rightarrow \mathbb{B}.
\end{align*}

To qualify as a stack these functions must satisfy the following rules
which are also referred to as \emph{stack axioms}.

\subsection{Stack initialization}

After a stack has been initialized its size is~0.
\begin{align}
\Label{eq:stack-init-size}
\mathrm{size}(\mathrm{init}(s)) &= 0.
\end{align}

The auxiliary functions $\mathrm{empty}$ and $\mathrm{full}$
are defined as follows
\begin{align}
\Label{eq:empty-stack}
\mathrm{empty}(s), & \qquad\text{iff}\qquad \mathrm{size(s)} = 0,  \\
\Label{eq:full-stack}
\mathrm{full}(s), & \qquad\text{iff}\qquad  \mathrm{size(s)} = c.
\end{align}

We expect that for every stack $s$ the following condition holds
\begin{align}
\Label{eq:stack-invariant}
 0 \leq \mathrm{size}(s) \leq c.
\end{align}

\clearpage

\subsection{Adding an element to a stack}

To push an element $v$ on a stack the stack must not be full.
If an element has been pushed on an eligible stack, its size increases by~1
\begin{align}
\Label{eq:stack-size-push}
\mathrm{size}(\mathrm{push}(s, v)) &= \mathrm{size}(s)+1,
  &\text{if}\quad  \neg\mathrm{full}(s).\\
\intertext{Moreover, the element pushed on a stack is the top element of the resulting stack}
\Label{eq:stack-top-push}
\mathrm{top}(\mathrm{push}(s, v)) &= v,
  &\text{if}\quad \neg\mathrm{full}(s).
\end{align}

\subsection{Removing an element from a stack}

An element can only be removed from a non-empty stack.
If an element has been removed from an eligible stack the
stack size decreases by~1
\begin{align}
\Label{eq:stack-size-pop}
\mathrm{size}(\mathrm{pop}(s)) &= \mathrm{size}(s)-1,
  &&\text{if}\quad \neg\mathrm{empty}(s).
%
\intertext{
If an element is pushed on a stack and immediately afterwards
an element is removed from the resulting stack then the final stack
is equal to the original stack}
%
\Label{eq:stack-pop-push}
\mathrm{pop}(\mathrm{push}(s, v)) &= s,
  &&\text{if}\quad \neg\mathrm{full}(s). \\
\intertext{Conversely, if an element is removed from a non-empty stack
  and if afterwards the top element of the original stack is
  pushed on the new stack
  then the resulting stack is equal to the original stack.}
%
\Label{eq:stack-push-pop-top}
\mathrm{push}(\mathrm{pop}(s),\mathrm{top}(s)) &= s, &&\text{if}\quad \neg\mathrm{empty}(s).
\end{align}

\clearpage

\subsection{A note on exception handling}

We don't impose a requirement on \inl{push(s, v)} if \inl{s}
is a full stack, nor on \inl{pop(s)} or \inl{top(s)} if \inl{s} is an
empty stack.
%
Specifying the behavior in such \emph{exceptional} situations is a
problem by its own; a variety of approaches is discussed in the
literature.
%
We won't elaborate further on this issue, but only give an example to warn
about ``innocent-looking'' exception specifications that may lead to
undesired results.

If we'd introduce an additional error value \inl{err} in the element type
$V$ and require \inl{top(s) = err} if \inl{s} is empty, we'd be faced
with the problem of specifying the behavior of \inl{push(s, err)}.
%
At first glance, it would seem a good idea to have \inl{err} just been
ignored by \inl{push}, i.e.\ to require
\begin{align}
\Label{eq:err}
\mathrm{push}(s,\mathrm{err}) & = s.
\end{align}

However, we then could derive for any non-full and non-empty stack \inl{s}, that

\begin{align*}
\mathrm{size}(s)
   &=  \mathrm{size}(\mathrm{pop}(\mathrm{push}(s, \mathrm{err}))) && \text{by \ref{eq:stack-pop-push}}\\
   &=  \mathrm{size}(\mathrm{pop}(s)) && \text{as assumed in \ref{eq:err}}\\
   &=  \mathrm{size}(s) - 1 && \text{by \ref{eq:stack-size-pop}}\\
\end{align*}
%
i.e.\ no such stacks could exist, or all \inl{int} values would be equal.


%%% Title:    Formula for Post-2020 Standard Scoring Rule
%%% Author:   Kyle M. Lang
%%% Created:  2020-12-17
%%% Modified: 2020-12-17

\documentclass[12pt]{article}

\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{datetime2}

\title{Formula for Post-2020 Standard Scoring Formula}
\author{Kyle M. Lang}

\begin{document}

\maketitle

\section{Definition of Terms}

\begin{itemize}
\item Raw exam score: $X$
\item Minimum exam score: $X_0$
\item Number of questions: $N_q$
\item Number of response options: $N_o$
\item Score expected by guessing alone:\begin{align*}
    X_g = \frac{N_q}{N_o}
  \end{align*}
\item Latent knowledge score
  \begin{align*}
    K = \frac{X - X_g}{N_q - X_g}
  \end{align*}
\item Knowledge score required to pass the exam: $K_p$
\end{itemize}

\section{Grade Calculation}

\begin{align*}
  \textit{Grade} =
  \begin{cases}
    X_0 + \frac{K (5.5 - X_0)}{K_p},~\text{if}~K < K_p\\
    5.5 + \left[\frac{K - K_p}{1 - K_p}\right] \times 4.5,~\text{otherwise}
  \end{cases}
\end{align*}

\end{document}


\section{Background}
\label{sec:back}

Let $U = \{ v_1, v_2, \ldots , v_n \}$ be a finite set of variables, each with a finite domain, and $V$ be the domain of $U$.
A \emph{potential} on $V$ is a function $\phi$ such that $\phi(v) \geq 0$ for each $v \in V$, and at least one $\phi(v) > 0$.
Henceforth, we say $\phi$ is on $U$ instead of $V$.
A \emph{joint probability distribution} is a potential $P$ on $U$, denoted $P(U)$, that sums to one.
For disjoint $X,Y \subseteq U$, a \emph{conditional probability table} (CPT) $P(X|Y)$ is a potential over $X \cup Y$ that sums to one for each value $y$ of $Y$.
For simplified notation, $\{ v_1, v_2, \ldots, v_n \}$ may be written as $v_1 v_2 \cdots v_n$, and $X \cup Y$ as $XY$.

A \emph{Bayesian network} (BN) \cite{pear88} is a \emph{directed acyclic graph} (DAG) ${\cal B}$ on $U$ together with CPTs $P(v_1 | Pa(v_1))$, $P(v_2|Pa(v_2))$, $\ldots$, $P(v_n|Pa(v_n))$, where $Pa(v_i)$ denotes the parents (immediate predecessors) of $v_i$ in ${\cal B}$.
For example, Figure \ref{fig:dag} depicts a BN, where CPTs $P(a),P(b|a),\ldots,P(m|g,l)$ are not shown.
We call $\cal{B}$ a BN, if no confusion arises.
The product of the CPTs for $\cal{B}$ on $U$ is a joint probability distribution $P(U)$.

\begin{figure}[htb]
    \begin{center}
    	\includegraphics{figures/DAG.png}
		\caption{A BN extended from \cite{madsen99}.}
		\label{fig:dag}
    \end{center}
\end{figure}

\emph{Variable elimination} (VE) \cite{zhan94} computes $P(X|Y=y)$, where $X$ and $Y$ are disjoint subsets of $U$, and $Y$ is observed taking value $y$.
In VE (given as Algorithm \ref{alg:ve} below), $\Phi$ is the set of CPTs for ${\cal B}$, $X$ is a list of query variables, $Y$ is a list of observed variables, $y$ is the corresponding list of observed values, and $\sigma$ is an \emph{elimination ordering} \cite{Kja90} for variables $U - (XE)$.
All elimination orderings in this paper are determined using \emph{weighted-min-fill} (WMF), which tends to be one of the best heuristics in practice \cite{koll09}.
Evidence may not be denoted for simplified notation.

\begin{algorithm}
\caption{Variable elimination}
\label{alg:ve}
\begin{algorithmic}[1]
\Function{Variable Elimination}{$\Phi$, $X$, $Y$, $y$, $\sigma$}
    \State Delete rows disagreeing with $Y=y$ from $\phi \in \Phi$ \label{alg:ve_delete}
    \While{$\sigma$ is not empty} \label{alg:ve_while}
        \State Remove the first variable $v$ from $\sigma$
        \State $\Phi$$ ~=~$ \Call{sum-out}{$v,\Phi$}
    \EndWhile \label{alg:ve_end_while}
    \State $P(X,Y=y) ~=~ \prod_{\phi \in \Phi} \phi$ \label{alg:ve_posterior}
    \Return $P(X,Y=y) / \sum_X P(X,Y=y)$ \label{alg:ve_return}
\EndFunction
\end{algorithmic}
\end{algorithm}

VE calls the sum-out algorithm, which eliminates $v$ from a set $\Phi$ of potentials by multiplying together all potentials involving $v$ and then summing $v$ out of the product.

\begin{example}
Run Algorithm \ref{alg:ve} to compute $P(i,j,k,l,m | d=0)$ in the BN ${\cal B}$ of Figure \ref{fig:dag}.
\end{example}

\emph{d-Separation} \cite{pear88} tests independencies in DAGs and can be presented as follows \cite{darwiche09}.
Let $X$, $Y$, and $Z$ be pairwise disjoint sets of variables in a DAG ${\cal B}$.
We say $X$ and $Z$ are \emph{d-separated} by $Y$, denoted $I(X,Y,Z)$, if at least one variable on every undirected path from $X$ to $Z$ is closed.
On a path, there are three kinds of variable $v$:
\begin{inparaenum}[(i)]
	\item a \emph{sequential} variable means $v$ is a parent of one of its neighbours and a child of the other;
	\item a \emph{divergent} variable is when $v$ is a parent of both neighbours; and
	\item a \emph{convergent} variable is when $v$ is a child of both neighbours.
\end{inparaenum}
A variable $v$ is either open or closed.
A sequential or divergent variable is \emph{closed}, if $v \in Y$.
A convergent variable is \emph{closed}, if $( v \cup De(v) ) \cap Y = \emptyset$.
A path with a closed variable is \emph{blocked}; otherwise, it is \emph{active}.
[TODO] Inline example testing $I(a,d,k)$ with d-separation.

The linear implementation of d-separation given in Algorithm \ref{alg:dsep} \cite{koll09} has two phases.
Phase I determines the ancestors $An(Y)$ of $Y$ in the DAG ${\cal B}$ using the algorithm ANCESTORS (not shown).
Phase II, uses the output of Phase I to determine all variables reachable from $X$ via active paths.
This is more involved, since the algorithm must keep track of whether a variable $v$ is visited from a child, denoted $(\uparrow,v)$, or visited from a parent, denoted $(\downarrow,v)$.
In Algorithm \ref{alg:dsep}, $L$ is the set of variables to be visited, $R$ is the set of reachable variables via active paths, and $V$ is the set of variables that have been visited.

\begin{algorithm}[htb]
\caption{\cite{koll09} Find nodes reachable from $X$ given $Y$ via active paths in DAG ${\cal B}$}
\label{alg:dsep}
\begin{algorithmic}[1]
\Procedure{Reachable}{$X$,$Y$,${\cal B}$}
	\LineComment{Phase I: insert $Y$ and all ancestors of $Y$ into $A$}
	\State $An(Y) \leftarrow \Call{Ancestors}{Y,{\cal B}}$
	\State $A \leftarrow An(Y) \cup Y$
	\LineComment{Phase II: traverse active paths starting from $X$}
	\For{$v \in X$} \Comment{(Node,direction) to be visited}
		\State $L \leftarrow L \cup \{(\uparrow,v)\}$
	\EndFor
	\State $V \leftarrow \emptyset$ \Comment{(Node,direction) marked as visited}
	\State $R \leftarrow \emptyset$ \Comment{Nodes reachable via active path}
	\While{$L \neq \emptyset$} \Comment{While variables to be checked}
		\State Select $(d,v)$ in $L$ \label{alg:lin_select_dsep}
		\State $L \leftarrow L - \{(d,v)\}$
		\If{$(d,v) \notin V$}
			\If{$v \notin Y$}
				\State $R \leftarrow R \cup \{v\}$ \Comment{$v$ is reachable}
			\EndIf
			\State $V \leftarrow V \cup \{(d,v)\}$ \Comment{Mark $(d,v)$ as visited}
			\If{$d = \uparrow$ and $v \notin Y$}
				\For{$v_i \in Pa(v)$}
					\State $L \leftarrow L \cup \{(\uparrow,v_i)\}$
				\EndFor
				\For{$v_i \in Ch(v)$}
					\State $L \leftarrow L \cup \{(\downarrow,v_i)\}$
				\EndFor
			\ElsIf{$d = \downarrow$}
				\If{$v \notin Y$}
					\For{$v_i \in Ch(v)$}
						\State $L \leftarrow L \cup \{(\downarrow,v_i)\}$
					\EndFor
				\EndIf
				\If{$v \in A$}
					\For{$v_i \in Pa(v)$}
						\State $L \leftarrow L \cup \{(\uparrow,v_i)\}$
					\EndFor
				\EndIf
			\EndIf
		\EndIf
	\EndWhile
	\Return{$R$}
\EndProcedure
\end{algorithmic}
\end{algorithm}

\begin{example}
Run Algorithm \ref{alg:dsep} to test $I(a,d,k)$ in BN ${\cal B}$ illustrated in Figure \ref{fig:dag}.
\end{example}

B - The Platform/Paper/sections/background.tex


BFS and DFS are two of the most universal algorithms for solving practical problems. Each suits better than the other to specific type of problems.
 \begin{itemize}
     \item For BFS, it suits problems that ask the shortest paths( unweighted ) from a certain source node to a certain destination, whether it is single sourced or all-pairs. Or in some cases, the questions requires us only traverse the graph for a certain steps (levels). Because BFS is iterative and can traverse the nodes level by level.
     \item For DFS, it is better for the weighted optimization problem, that we are required to count all possible paths or to get the best out of all possible paths. Because DFS has the advantage of saving the result of overlapping subproblem to avoid extra computation.
     \item Use either BFS or DFS when we just need to check correctness (whether we can reach a given state to another.
 \end{itemize}

 \section{Bidirectional Search: Two-end BFS}
\label{sec_bidirectional_search}
\paragraph{Definition}
In normal graph search using BFS/DFS we begin our search in one direction usually from source vertex $s$ toward the goal vertex $t$, but what if we start search form both direction simultaneously. Bidirectional search is a graph search algorithm which find \textit{smallest path} from source to goal vertex. We just learned that Breadth-first-search suits well for shortest path problem. Because in Level-by-level BFS, it controls the visiting order of nodes by its order to the starting vertex. Therefore, Bidirectional search  runs \textit{two simultaneous level-by-level BFS searches} which eventually ``meet in the middle" (when two searches intersect) and terminates.
\begin{enumerate}
    \item Forward search starts form source/initial vertex $s$ toward goal vertex $t$.
    \item Backward search form goal/target vertex  $t$ toward source vertex $s$
\end{enumerate}

\paragraph{Time and Space Complexity}
Suppose if branching factor of tree is b and distance of goal vertex from source is h, then the normal BFS/DFS searching complexity would be $O(b^h)$. On the other hand, if we execute two search operation then the complexity would be $O(b^{h/2})$ for each search and total complexity would be $O(b^{h/2}+b^{h/2})$ which is far less than $O(b^h)$. Therefore,  in many cases bidirectional search is way faster and dramatically reduce the amount of required exploration. Because we need to save nodes at each level in the queue, the maximum nodes we get at the middle $h/2$ will be $b^h$, this makes the space complexity to $O(b^h)$.

\paragraph{When and How}
\textbf{When} Bidirectional search can find the shortest path successfully if all the paths are assigned uniform costs.

\textbf{How} When the graph from each side is not balanced: each node has various branch factors.  We take two queues: sourceQueue for BFS in forward direction from source to target and targetQueue which is used to do the BFS from the target towards the source in backward direction. We try to alternate between the two queues: sourceQueue and targetQueue; basically in every iteration we choose the smaller queue for the next iteration for the processing which effectively helps in alternating between the two queues only when the swapping between the two queues is profitable.

This helps in the following way: As we go deeper into a graph the number of edges can grow exponentially. Since we are approaching in a balanced way, selecting the queue which has smaller number of nodes for the next iteration, we are avoiding processing a large number of edges and nodes by trying to having the intersection point somewhere in the middle.

Since we are processing both the target and source queue we are not going to much depth from any direction, either in forward direction (i.e, while processing source queue) or in backward direction (i.e, target queue which searches from target to source in backward manner).

\paragraph{Implementation}


\chapter{Mathematical Background}\label{chap:AppA}
In this part of the appendix we want to discuss some of the mathematical tools we used during the calculations presented in the scope of this thesis in a more formal manner.
The part on the York decomposition is mainly inspired by \cite{Percacci2017}, whereas the conventions for the heat-kernel computations are taken from \cite{PawlowskiNPgaugeLecture} and extended for the matter part, using the conventions from \cite{CodelloPercacciRahmede2008}.

\section{York Decomposition}
In the discussion of gauge theories, it is often very useful to decompose the gauge field $A_{\mu}$ into transversal and longitudinal parts:
\begin{align}
	A_{\mu} = A_{\mu}^{\mathrm{T}} + \nabla_{\mu}\phi.
\end{align}
The transversal part is characterized by the fact, that $\nabla^{\mu}A_{\mu}^{\mathrm{T}} = 0$. Using this decomposition, we are able to separate the pure gauge spin-$0$ degrees of freedom from the physical ones, contained in the spin-$1$ part $A_{\mu}^{\mathrm{T}}$.\\
Assuming vanishing boundary terms, integration by parts allows us to change the integration variables in the functional integral, i.\,e.
\begin{align}
	\int_x \sqrt{g} \ A_{\mu}A^{\mu} = \int_x \sqrt{g} \ A_{\mu}^{\mathrm{T}}A^{\mathrm{T}, \mu} + \int_x \sqrt{g} \ \phi\left(-\nabla^2\right)\phi.
\end{align}
Note, that we have to take care of the Jacobian $J$ of this variable transformation:
\begin{align}
	\left(\dd A_{\mu}\right) \longrightarrow J\left(\dd A_{\mu}^{\mathrm{T}}\right)\left(\dd\phi\right).
\end{align}
To be able to determine the Jacobian for our transformation, the integration measure needs to be normalized. A quite convenient choice is to evaluate the Gaussian integral over the different fields $\psi$ and set the result to one:
\begin{align}\label{eqn:york_measure}
	\int\left(\dd\psi\right) \exp\left\{-\int\dd x \ \sqrt{g} \ \psi^2 \right\} = 1,
\end{align}
where we are assuming an Euclidean signature and a curved background metric. With this condition we find:
\begin{align}
	1&=J \int\left(\dd A_{\mu}^{\mathrm{T}}\right) \operatorname{e}^{-\int \dd x \sqrt{g} \ A_{\mu}^{\mathrm{T}} A^{\mathrm{T}, \mu}}
	\int(\dd\phi) \operatorname{e}^{-\int \dd x \sqrt{g} \  \phi\left(-\nabla^{2}\right) \phi} = J\left(\operatorname{det}_{\phi}^{\prime}\left(-\nabla^{2}\right)\right)^{-1/2}.
\end{align}
This allows us to determine the Jacobian $J$ as follows:
\begin{align}
	J = \left(\operatorname{det}_{\phi}^{\prime}\left(-\nabla^{2}\right)\right)^{1/2}.
\end{align}
The prime denotes the fact, that the zero mode has to be removed, when computing the determinant to obtain a consistent result. Physically this is in accordance with the fact, that a constant $\phi$ does not contribute to $A_{\mu}$.\\
For our computation in chapters \ref{chap:EHT} and \ref{chap:Matter}, we used the background field method, where we assume a linear split of the \textit{full} metric $g_{\mu\nu}$ into a background metric $\bar{g}_{\mu\nu}$ and a fluctuation field $h_{\mu\nu}$. There is an analogous way of decomposing the fluctuation field in the background field formalism. First, we split $h_{\mu\nu}$ into
\begin{align}
	h_{\mu\nu} = h_{\mu\nu}^{\mathrm{T}} + \frac{1}{d}\ \bar{g}_{\mu\nu}h,
\end{align}
where $h_{\mu\nu}^{\mathrm{T}}$ is traceless, i.\,e. $\bar{g}^{\mu\nu}h_{\mu\nu}^{\mathrm{T}}=0$ and $h=\bar{g}^{\mu\nu}h_{\mu\nu}$. The traceless part can be further decomposed in flat space using the irreducible representations of the Lorentz group with spins 0, 1 and 2 respectively, but in our case a more sophisticated approach, the so-called \textit{York decomposition} is chosen:
\begin{align}
	h_{\mu\nu} = h_{\mu\nu}^{\text{TT}} + \bar{\nabla}_{\mu}\xi_{\nu} + \bar{\nabla}_{\nu}\xi_{\mu} + \left(\bar{\nabla}_{\mu}\bar{\nabla}_{\nu} - \frac{1}{d} \ \bar{g}_{\mu\nu}\bar{\nabla}^2\right)\sigma + \frac{1}{d} \ \bar{g}_{\mu\nu}h.
\end{align}
Here, $ h_{\mu\nu}^{\text{TT}}$ is a transverse-traceless, spin-2 degree of freedom, $\xi_{\mu}$ is transverse and carries a spin-1 d.\,o.\,f. and $\sigma$ and $h$ possess spin-0. As before, we want to find the Jacobian $J$ for this variable transformation:
\begin{align}
	\left(\dd h_{\mu\nu}\right) \longrightarrow J	\left(\dd h_{\mu\nu}^{\mathrm{TT}}\right) \left(\dd\xi_{\mu}\right)\left(\dd\sigma\right)\left(\dd h\right).
\end{align}
This is again possible after specifying a suitable normalization of the functional measure as
\begin{align}
	\int (\dd h_{\mu\nu}) \exp\left\{-\mathcal{G}(h, h)\right\} = 1,
\end{align}
where $\mathcal{G}$ is an inner product in the space of symmetric two-tensors, defined as
\begin{equation}
\begin{aligned}
\mathcal{G}(h, h)&= \int_x \sqrt{\bar{g}} \ \left(h_{\mu \nu} h^{\mu \nu}+\frac{a}{2} h^{2}\right) \\[10pt]
&= \int_x \sqrt{\bar{g}} \ \left[h^{\mathrm{TT}}_{\mu \nu} h^{\mathrm{TT}, \mu \nu}+2 \xi_{\mu}\left(-\bar{\nabla}^{2}-\frac{\bar{R}}{d}\right) \xi^{\mu}\right. \\
&+\left.\frac{d-1}{d} \sigma\left(-\bar{\nabla}^{2}\right)\left(-\bar{\nabla}^{2}-\frac{\bar{R}}{d-1}\right) \sigma+\left(\frac{1}{d}+\frac{a}{2}\right) h^{2} \right]
\end{aligned}
\end{equation}
in the case of an Einstein type background metric\footnote{A metric is of Einstein type, if $R_{\mu\nu}$ is a constant multiple of $g_{\mu\nu}$, i.\,e. $R_{\mu\nu} = \frac{1}{d} \mathcal{R} g_{\mu\nu}$.}. This yields
\begin{align}
	J=\left(\operatorname{det}_{\xi}\left(-\bar{\nabla}^{2}-\frac{R}{d}\right)\right)^{1 / 2}\left(\operatorname{det}_{\sigma}^{\prime}\left(-\bar{\nabla}^{2}\right)\right)^{1 / 2}\left(\operatorname{det}_{\sigma}\left(-\bar{\nabla}^{2}-\frac{R}{d-1}\right)\right)^{1 / 2}.
\end{align}
Note, that the prime has the same meaning and physical interpretation as in the previous case: If $\sigma$ is constant, it does not contribute to $h_{\mu\nu}$. \\
 In both cases, the decomposition of the general gauge field and the York decomposition of the fluctuation field, appropriate rescalings of the fields $\phi$, $\xi_{\mu}$ and $\sigma$ respectively, help us to cancel the non-trivial Jacobians and to achieve, that all modes have the same mass dimension. For the sake of completeness, we present the rescaled versions of the fields:
 \begin{align}
\hat{\phi} &= \sqrt{-\nabla^2}\ \phi \\[10pt]
 \hat{\xi}_{\mu} &= \sqrt{-\bar{\nabla}^{2}-\frac{\bar{R}}{d}}\  \xi_{\mu} \\[10pt]
  \hat{\sigma} &= \sqrt{-\bar{\nabla}^{2}} \sqrt{-\bar{\nabla}^{2}-\frac{\bar{R}}{d-1}}\ \sigma.
 \end{align}
 The resulting graviton two-point function, after decomposition of the fluctuation field has the following structure:
\begin{equation} \Gamma^{(2)}_{hh} =
\begin{pmatrix}
\Gamma^{(2)}_{h^{\mathrm{TT}}h^{\mathrm{TT}}} & 0 & 0 & 0 \\[10pt]
0 & \Gamma^{(2)}_{\xi\xi}  & 0 & 0 \\[10pt]
0 & 0 & \Gamma^{(2)}_{h^{\mathrm{Tr}}h^{\mathrm{Tr}}}  & \Gamma^{(2)}_{h^{\mathrm{Tr}}\sigma} \\[10pt]
0 & 0 & \Gamma^{(2)}_{\sigma h^{\mathrm{Tr}}} & \Gamma^{(2)}_{\sigma\sigma} \\

\end{pmatrix}.
\end{equation}
 This concludes our discussion of the York decomposition, as a useful tool to simplify calculations in the background field method.
 \newpage
 \section{Heat-Kernel Techniques}\label{sec:heat-kernel}
\vspace{-0.2cm}
We use heat-kernel techniques to evaluate the r.\,h.\,s. of the flow equation (\ref{eqn:Wetterich}), where we need to compute the functional trace over functions depending on the Laplacian on a curved background. In general, the method can be understood as a curvature expansion on a flat background. \\
The general formula to compute such traces is given by
\begin{align}
	\operatorname{Tr} f(\Delta)= N \  \int\kern-1.3em\sum_{\ell} \rho(\ell) f(\lambda(\ell)),
	\label{eqn:heat-kernel}
\end{align}
with some normalization $N$, the spectral values $\lambda(\ell)$ and their corresponding multiplicities $\rho(\ell)$. \\
On flat backgrounds, the computation of (\ref{eqn:heat-kernel}) is simply a standard momentum integral, whereas on curved backgrounds, consider for example a four-sphere $\mathbb{S}^4$ with constant background curvature $r = \frac{\bar{\mathcal{R}}}{k^2} > 0$, the spectrum of the Laplacian is discrete and we need to sum over all spectral values. \\
For our example of $\mathbb{S}^4$, we have
\begin{align}
	\lambda(\ell) = \frac{\ell(3+\ell)}{12}r \qquad \text{and} \qquad \rho(\ell) = \frac{(2\ell + 3)(\ell+2)!}{6\ell!}.
\end{align}
The normalization is then given by the inverse of the four-sphere-volume $ \left(V_{\mathbb{S}^4}\right)^{-1} = \frac{k^4r^2}{384\pi^2}$. This leads us to the formula for our computation of the r.\,h.\,s. of the flow equation on a background with constant positive curvature:
\begin{align}
\operatorname{Tr} f(\Delta)=\frac{k^{4} r^{2}}{384 \pi^{2}} \sum_{\ell=0}^{\infty} \frac{(2 \ell+3)(\ell+2) !}{6 \ell !} f\left(\frac{\ell(3+\ell)}{12} r\right).
\end{align}
This is called spectral sum. For large curvatures $r$ the convergence of the series is rather fast, whereas in the limit $r\rightarrow 0$ one finds exponentially slow convergence.\\
The master equation for heat-kernel computations reads
\begin{align}
	\operatorname{Tr} f(\Delta)=\frac{1}{(4 \pi)^{\frac{d}{2}}}\left[\mathbf{B}_{0}(\Delta) Q_{2}[f(\Delta)]+\mathbf{B}_{2}(\Delta) Q_{1}[f(\Delta)]\right]+\mathcal{O}\left(\mathcal{R}^{2}\right),
\label{eqn:master-eqn}
\end{align}
with the heat-kernel coefficients
\begin{align}
	\mathbf{B}_{n}(\Delta)=\int_x  \sqrt{g} \  \operatorname{Tr} \mathbf{b}_{n}(\Delta)
\end{align}
and
\begin{align}
	Q_{n}[f(x)]=\frac{1}{\Gamma(n)} \int \dd x \ x^{n-1} f(x).\label{eqn:Qfunc}
\end{align}
\newpage
For computations on $\mathbb{S}^4$, the values for the heat kernel coefficients $\mathbf{B}_n(\Delta)$ are presented in the following:
\begin{table}[H]
	\centering
	\setlength{\tabcolsep}{5mm}
	\setlength\extrarowheight{2mm}
	\begin{tabular}{c | c c c}
	   & TT & TV & S\\ \hline
	   $\operatorname{Tr} \mathbf{b}_{0}$ & 5 &  3 & 1\\
	  $\operatorname{Tr} \mathbf{b}_{2}$ & $-\frac{5}{6}\mathcal{R}$ & $\frac{1}{4}\mathcal{R}$& $\frac{1}{6}\mathcal{R}$\\
	\end{tabular}
	\caption{Heat-kernel coefficients for transverse-traceless tensors (TT), transverse vectors (TV) and scalars (S) for computations on $\mathbb{S}^4$.}
\end{table}

The basic idea of the proof of equation (\ref{eqn:heat-kernel}) is based on the Laplace transform
\begin{align}
	f(\Delta) = \int_0^{\infty} \dd s \ \operatorname{e}^{-s\Delta}\tilde{f}(s).
\end{align}
We insert this definition of the Laplace transform into equation (\ref{eqn:heat-kernel}) and find
\begin{align}
	\operatorname{Tr} f(\Delta)=\int_{0}^{\infty} \dd s \ \tilde{f}(s) \operatorname{Tr} \operatorname{e}^{-s \Delta}.
\label{eqn:hk2}
\end{align}
The trace on the r.\,h.\,s. is explicitly the trace of the heat-kernel. We expand this term as follows:
\begin{align}
	\operatorname{Tr} \operatorname{e}^{-s \Delta}=\frac{1}{(4 \pi)^{\frac{d}{2}}} \sum_{n=0}^{\infty} s^{\frac{n-d}{2}} \mathbf{B}_{n}(\Delta).
\end{align}
This is where the heat-kernel coefficients $\mathbf{B}_n$ become important. We proceed by inserting this expanded version of the heat-kernel trace into equation (\ref{eqn:hk2}) and find:
\begin{equation}
\begin{aligned}
\operatorname{Tr} f(\Delta) &=\frac{1}{(4 \pi)^{\frac{d}{2}}} \sum_{n=0}^{\infty} \mathbf{B}_{n}(\Delta) \int_{0}^{\infty} \dd s \ s^{\frac{n-d}{2}} \tilde{f}(s) \\[10pt]
&=\frac{1}{(4 \pi)^{\frac{d}{2}}} \sum_{n=0}^{\infty} \frac{1}{\Gamma\left(\frac{d-k}{2}\right)} \mathbf{B}_{n}(\Delta) \int_{0}^{\infty} \dd t \ t^{\frac{d-n}{2}-1} f(t) \\[10pt]
 &=\frac{1}{(4 \pi)^{\frac{d}{2}}} \sum_{n=0}^{\infty} \mathbf{B}_{n}(\Delta) Q_{\frac{d-n}{2}}[f(t)].
\end{aligned}
\end{equation}
This completes the derivation of the master equation (\ref{eqn:master-eqn}) for heat-kernel computations. Note, that we used the definition of the $Q$-functionals, given in equation (\ref{eqn:Qfunc}) and the relation $\int_{s} s^{-x} \tilde{f}(x)=\frac{1}{\Gamma(x)} \int_{z} z^{x-1} f(z)$.

When investigating matter fields, such as in chapter \ref{chap:Matter}, we often encounter kinetic operators of the form $\tilde{\Delta} = -\nabla^2\cdot\mathbbm{1} +  \mathbf{E}$, where $\mathbf{E}$ is a linear map acting on the spacetime and the internal indices of the fields. In this notation, $\mathbbm{1}$ has to be understood as the identity in the respective field space. \\
If $\left[\Delta, \mathbf{E}\right] = 0$\footnote{In the case of $\left[\Delta, \mathbf{E}\right] \neq 0$, there would be additional terms including (higher order) commutators of $\Delta$ and $\mathbf{E}$ due to the Baker-Campbell-Hausdorff formula.}, we can relate the coefficients of the modified Laplacian $\tilde{\Delta}$ and those of the initially considered operator $-\nabla^2$ via
\begin{align}
	\operatorname{Tr} \operatorname{e}^{-s\left(-\nabla^{2}+\mathbf{E}\right)}=\frac{1}{(4 \pi)^{\frac{d}{2}}} \sum_{k, l=0}^{\infty} \frac{(-1)^{\ell}}{\ell !} \int_x \sqrt{g} \ \operatorname{Tr} \mathbf{b}_{k}(\Delta) \mathbf{E}^{\ell} s^{k+\ell-2}.
\end{align}
This results in the following, modified values for the coefficients we are interested in:
\begin{equation}
\begin{aligned}
	\mathbf{b}_0 &= \mathbbm{1} \\[10pt]
	\mathbf{b}_2 &= \frac{\mathcal{R}}{6}\cdot\mathbbm{1} - \mathbf{E}.
	\label{eqn:coefficients}
\end{aligned}
\end{equation}
For further study and a more general treatment of the modified Laplacians, including higher order coefficients,\ \cite{CodelloPercacciRahmede2008, Percacci2017} are recommended.


\chapter{Mathematical Functions}\label{math-functions.appendix}

This appendix provides the definition of several mathematical
functions used throughout the manual.

\section{Beta}\label{beta-appendix.section}

The beta function, $\mbox{B}(\alpha,\beta)$, computes the normalizing
constant for the beta distribution, and is defined for $a > 0$ and $b
> 0$ by
%
\[
\mbox{B}(a,b)
\ = \
\int_0^1 u^{a - 1} (1 - u)^{b - 1} \, du
\ = \
\frac{\Gamma(a) \, \Gamma(b)}{\Gamma(a+b)} \, .
\]

\section{Incomplete Beta}\label{inc-beta-appendix.section}

The incomplete beta function, $\mathrm{B}(x; a, b)$, is defined for
$x \in [0, 1]$ and $a, b \geq 0$ such that $a + b \neq 0$ by
\[
\mathrm{B}(x; \, a, b)
\ = \
\int_0^x u^{a -  1} \, (1 - u)^{b - 1} \, du,
\]
%
where $\mathrm{B}(a, b)$ is the beta function defined in
\refsection{beta-appendix}.  If $x = 1$, the incomplete beta function
reduces to the beta function, $\mathrm{B}(1; a, b) = \mathrm{B}(a,
b)$.

The regularized incomplete beta function divides the incomplete beta
function by the beta function,
\[
I_x(a, b) \ = \ \frac{\mathrm{B}(x; \, a, b)}{B(a, b)} \, .
\]

\section{Gamma}\label{gamma-appendix.section}

The gamma function, $\Gamma(x)$, is the generalization of the
factorial function to continuous variables, defined so that for
positive integers $n$,
\[
\Gamma(n+1) = n!
\]
%
Generalizing to all positive numbers and non-integer negative numbers,
\[
\Gamma(x) = \int_0^{\infty} u^{x - 1} \exp(-u) \, du.
\]

\section{Digamma}\label{digamma-appendix.section}

The digamma function $\Psi$ is the derivative of the $\log \Gamma$
function,
%
\[
\Psi(u)
\ = \
\frac{d}{d u} \log \Gamma(u)
\ = \
\frac{1}{\Gamma(u)} \ \frac{d}{d u} \Gamma(u).
\]


% !TEX root = main.tex

%-------------------------------------------------
\section{Sums of squares}\label{sec:chi-squared}

Let $X\sim N(\mu,\sigma^2)$ where $\mu$ is unknown, and let $X_1,X_2,\ldots,X_n$ be a random sample from the distribution of $X$. The usual test statistic for deciding between $H_0:\mu=\mu_0$ and a suitable alternative is the standardised sum
\[
Z = \sum_{i=1}^n\left(\frac{X_i-\mu_0}{\sigma}\right)\ \sim N(0,1)\text{ under $H_0$.}
\]

Another test statistic is provided the standardized \emph{sum-of-squares},
\[
T = \sum_{i=1}^n\left(\frac{X_i-\mu_0}{\sigma}\right)^2\ \sim\chi^2_n \text{ under $H_0$.}
\]
where $\chi^2_n$ is the \emph{chi-squared distribution} with $n$ degrees of freedom.
\begin{remark}
If $\sigma^2$ is unknown we replace it by the sample variance $s^2$, in which case $T\sim\chi^2_{n-1}$.
\end{remark}
%-----------------------------
\subsection{The $\chi^2$ distribution}

\begin{definition}\label{defn:chisquared_dist}
The $\chi^2_{n}$ distribution is defined by the PDF
\[
f(x) = \begin{cases}
	\displaystyle\frac{1}{\Gamma(n/2)2^{n/2}}\,x^{n/2-1} e^{-x/2} & \text{for $x>0$}, \\
	0																	& \text{otherwise,}
\end{cases}
\]
where the parameter $n$ is called the \emph{degrees of freedom}.
\end{definition}
The $\chi^2_{n}$ distribution is a special case of the $\Gamma(k,\theta)$ distribution, where $k=n/2$ and $\theta=2$ is a scale parameter. In particular, $\expe(X) = n$ and $\var(X)=2n$.
%
The following theorem (which we shall not prove) asserts that the sum-of-squares of $n$ independent standard normal variables has the $\chi^2_n$-distribution.
\begin{theorem}
If $Z_1,Z_2,\ldots,Z_n$ are independent standard normal variables then $\displaystyle\sum_{i=1}^n Z_i^2\sim\chi^2_n$.
\end{theorem}

\begin{example}
A quality control supervisor at a paint factory knows that the exact amount each tin contains will vary due to certain uncontrollable factors that affect the amount of fill. The mean fill is important, but equally important is the variation of each fill. If the variance $\sigma^2$ of the fill is large, some tins will contain too much paint, and others too little. A regulatory agency specifies that the variance of the amount of fill in $250ml$ tins should be less than $3ml$. To determine whether or not the process is meeting this specification, the supervisor randomly selects 10 tins and measures the contents of each tin. The mean fill over the sample is found to be $250.78ml$, and the sample variance is $s^2 = 1.03$. Do the data indicate that the factory is operating within the regulatory limits?
\begin{solution}
We wish to test the null hypothesis $H_0:\sigma^2 = 3$ against the alternative $H_1:\sigma^2 < 3$. We assume that the distribution of the fill amounts is approximately normal, and consider the test statistic
\[
T = \sum_{i=1}^{n} \left(\frac{X_i-\bar{X}}{\sigma}\right)^2 = \frac{(n-1)s^2}{\sigma^2},
\]
where $s^2$ is the sample variance of the fill amounts. Taking $n=10$, the distribution of our test statistic under the null hypothesis $H_0:\sigma^2 = 3$ is
\[
T \sim \chi^2_9.
\]
\bit
\it From tables, the critical value for a lower-tailed test at $\alpha=0.05$ is $T_{0.95} = 3.326$.
\it The observed value of the test statistic (under the null hypothesis) is
\[
T = \frac{(n-1)s^2}{\sigma^2} = \frac{9\times 1.03}{3} = 3.09.
\]
\eit
The test statistic lies in the rejection region, so the supervisor can reject $H_0:\sigma^2=3$ and conclude that the variance of the fill amounts is less than $3$. The supervisor can be confident that the factory is operating within the desired limits of variability.
\end{solution}
\end{example}

%-----------------------------
\subsection{The $F$ distribution}
\begin{definition}
Let $T_1$ and $T_2$ be independent random variables with $T_1\sim\chi^2_m$ and $T_2\sim\chi^2_n$. The distribution of the ratio
\[
F = \frac{T_1/m}{T_2/n}.
\]
is called the \emph{$F$-distribution with $m$ and $n$ degrees of freedom}, and denoted by $F\sim F_{m,n}$.
\end{definition}

\begin{example}
A researcher wants to compare the metabolic rates of mice subjected to different drugs. The weight of the mice may affect their metabolic rates, so the researcher wishes to obtain mice that are relatively homogeneous with respect to weight. Five hundred mice will be needed to complete the study. Currently, 16 mice from supplier 1 and another 13 mice from supplier 2 are available for comparison. The researcher weighs these mice and finds that the sample standard deviations are $s_1=0.2021$ and $s_2=0.0982$ respectively. Is there sufficient evidence to indicate a significant difference in the variance of the weight of mice obtained from the two suppliers at the $\alpha=0.1$ level?
\begin{solution}
Let $\sigma^2_1$ and $\sigma^2_2$ be the population variances for mice from Supplier 1 and Supplier 2 respectively. The null hypothesis is $H_0:\sigma^2_1=\sigma^2_2$, and our test statistic is the ratio of the sample variances,
\[
F = \frac{s^2_1}{s^2_2}
\qquad\text{where}\quad
\frac{(m-1)s^2_1}{\sigma_1}\sim\chi^2_{m-1}
\quad\text{and}\quad
\frac{(n-1)s^2_2}{\sigma_2}\sim\chi^2_{n-1}.
\]
with $m=16$ and $n=13$. Under $H_0:\sigma^2_1=\sigma^2_2$ we have that $F\sim F_{15,12}$.
\bit
\it We reject $H_0$ if the observed $F$-ratio exceeds the tabulated value $F_{1-\alpha/2}=F_{0.95} = 2.616$.
\it The observed value is $F=(0.2021)^2/(0.0982)^2=4.236$.
\eit
The observed value lies in the rejection region, so we reject the null hypothesis and conclude that the weights of mice from supplier 2 tend to be more homogeneous that the weights of mice from supplier 1.

\bigskip
Note: $F_{0.975} = 3.277$, $F_{0.99} = 4.155$,  $F_{0.995} = 4.721$. Thus we would reject $H_0$ at $\alpha=0.05$ and $\alpha=0.02$, but retain $H_0$ at $\alpha=0.01$.
\end{solution}
\end{example}

%-----------------------------
\subsection{The non-central $\chi^2$ distribution}

\begin{definition}
Let $X_1,X_2,\ldots,X_n$ be independent random variables with $X_i\sim N(\mu_i,1)$. The distribution of the sum-of-squares
\[
W=\sum_{i=1}^n X_i^2
\]
is called the \emph{non-central chi-squared distribution}, with $n$ degrees of freedom and non-centrality parameter
\[
\lambda = \sum_{i=1}^n \mu_i^2.
\]
\end{definition}
We write this as $W\sim\chi^2_n(\lambda)$, in which case
\[
\expe(W)=n+\lambda \quad\text{and}\quad \var(W)=2(n+2\lambda).
\]
When $\lambda=0$, all $\mu_i$ must be zero and the $\chi^2_n(\lambda)$ distribution reduces to the ordinary $\chi^2_n$ distribution. Any non-zero mean $\mu_i$ increases the value of $\lambda$ and hence increases $\expe(W)$ and $\var(W)$ compared to those of the ordinary $\chi^2_n$ distribution.

%%--------------------------------------------------
%\subsubsection*{Sums of squares}
%
%Let $X\sim N(\mu,\sigma^2)$. If $\mu$ is unknown but $\sigma^2$ is known, a test statistic for $H_0:\mu=\mu_0$ against a suitable alternative is the standardized \emph{sum-of-squares},
%\[
%T = \sum_{i=1}^n\left(\frac{X_i-\mu_0}{\sigma}\right)^2\ \sim\chi^2_n \text{ under $H_0$.}
%\]
%
%\bit
%\it If $\sigma^2$ is also unknown we replace it by the sample variance $s^2$, in which case $T\sim\chi^2_{n-1}$.
%\it If $\mu\neq\mu_0$, then $T\sim\chi^2_n(\lambda)$ where $\lambda= n(\mu-\mu_0)^2$.
%\eit


\section{Bézier curves}\label{sec:bezier-curves}
To achieve a smooth, parametric curve, widely used in computer graphics, animation and font creation, the Bézier curves are used.
They are named after Pierre Etienne Bézier (1910-1999) --- a French engineer and mathematician with merits in the field of mechanical engineering.

The Bézier curves are based on the \textit{Berenstein polynomial basis}, which was "introduced 100 years ago as a means to constructively prove the ability of polynomials to approximate any continuous function, to any desired accuracy, over a prescribed interval"~\cite{farouki2012bernstein}.
In other words, this is the constructive proof of the \textit{Weierstrass theorem} (\textit{approximation theorem}), which "states that the continuous function $f(x)$ on an interval $[a, b]$ and a tolerance $\epsilon > 0$, a polynomial $p_n(x)$ of sufficiently high degree $n$ exists, such that:

\begin{equation}
    \mid f(x) - p_n(x) \mid \leq \epsilon, \quad \forall x \in \left[ a,b \right]\label{eq:weierstrass-error}
\end{equation}

In other words, polynomials can uniformly approximate any function that is merely continuous over a closed interval"~\cite{farouki2012bernstein}.
If so, some of the properties for the Bézier curves are derived immediately, for example, it is known that the basis functions are real, the curve generally follows the shape of the control polygon, the first and last points on the curve are coincident with the first and last points of the control polygon, and so on~\cite{bezier-curves}.

The Bézier curve of $n+1$ control points are defined in~\cite{farouki2012bernstein} as:
\begin{equation}
    r(t) = \sum_{k=0}^n p_k b_k^n(t),  \quad t \in [0,1]\label{eq:bezier-control-points}
\end{equation}

Where the $p_0,\dots,p_n$ are the \textit{control points} and $b_k^n$ is the Berenstein polynomial:
\begin{equation}
    b_k^n(t) = \binom{n}{k} t^k (1-t)^{n-k}, \quad \binom{n}{k} = \frac{n!}{k!(n-k)!}\label{eq:berenstrain-polynomial}
\end{equation}

For example, the two-dimensional Bézier curve is described as a pair of a polynomials:
\begin{equation}
    (x,y) = \left( \sum_{k=0}^n x_{k} b_k^n(t), \sum_{k=0}^n y_{k} b_k^n(t) \right)\label{eq:bezier-point}
\end{equation}

\begin{figure}[h!]
    \centering
    \includegraphics[width=0.4\linewidth,scale=0.4]{resources/bezier-curve-example.png}
    \captionof{figure}{Example of Bézier curve fitting to the control points from~\cite{farouki2012bernstein}}
    \label{fig:bezier-example}
\end{figure}

The control points $p_0,\dots,p_n$ shape the control polygon for the Bézier curve, where the first and the last points on the Bézier curve are coincident with the control polygon (detailed proof and mathematical derivation can be found in~\cite{farouki2012bernstein}).
The properties of the Bézier curve allow for creating the smooth shape, that is going through a set of predefined points and the curve is trying to `follow' the polygon.
This makes this solution convenient from the point of view of this work because the prepared bot is expected to make moves in a human-like manner, so the moves should be smooth and look natural.An example of the control polygon with the Bézier curve shaped by it can be seen in Fig.~\ref{fig:bezier-example} from~\cite{farouki2012bernstein}.


\item \points{35} {\bf Semi-supervised EM}

\def\zsi{z^{(i)}}
\def\xsi{x^{(i)}}

Expectation Maximization (EM) is a classical algorithm for unsupervised learning (\emph{i.e.,} learning with hidden or latent variables). In this problem we will explore one of the ways in which EM algorithm can be adapted to the semi-supervised setting, where we have some labeled examples along with unlabeled examples.

In the standard unsupervised setting, we have $\nexp \in \mathbb{N}$ unlabeled examples $\{x^{(1)},\ldots,x^{(\nexp)}\}$. We wish to learn the parameters of $p(x,z;\theta)$ from the data, but $\zsi$'s are not observed. The classical EM algorithm is designed for this very purpose, where we maximize the intractable $p(x;\theta)$ indirectly by iteratively performing the E-step and M-step, each time maximizing a tractable lower bound of $p(x;\theta)$. Our objective can be concretely written as:

\begin{align*}
    \ell_{\text{unsup}}(\theta) &= \sum_{i=1}^\nexp \log p(\xsi;\theta) \\
    &= \sum_{i=1}^\nexp \log \sum_{\zsi} p(\xsi,\zsi;\theta)
\end{align*}

Now, we will attempt to construct an extension of EM to the semi-supervised setting. Let us suppose we have an \emph{additional} $\tilde{\nexp} \in \mathbb{N}$ labeled examples $\{(\tilde{x}^{(1)},\tilde{z}^{(1)}),\ldots,(\tilde{x}^{(\tilde{\nexp})},\tilde{z}^{(\tilde{\nexp})})\}$ where both $x$ and $z$ are observed. We want to simultaneously maximize the marginal likelihood of the parameters using the unlabeled examples, and full likelihood of the parameters using the labeled examples, by optimizing their weighted sum (with some hyperparameter $\alpha$). More concretely, our semi-supervised objective $\ell_\text{semi-sup}(\theta)$ can be written as:
%
\begin{align*}
    \ell_\text{sup}(\theta) &= \sum_{i=1}^{\tilde{\nexp}} \log p(\tilde{x}^{(i)},\tilde{z}^{(i)};\theta) \\
    \ell_{\text{semi-sup}}(\theta) &= \ell_\text{unsup}(\theta) + \alpha \ell_\text{sup}(\theta)
\end{align*}
%
We can derive the EM steps for the semi-supervised setting using the same approach and steps as before. You are \emph{strongly encouraged} to show to yourself (no need to include in the write-up) that we end up with:

\subsubsection*{E-step (semi-supervised)}

For each $i \in \{1,\ldots,\nexp\}$, set
\begin{align*}
    Q_i^{(t)}(\zsi) := p(\zsi|\xsi;\theta^{(t)})
\end{align*}

\subsubsection*{M-step (semi-supervised)}

\begin{align*}
    \theta^{(t+1)} &:= \arg\max_\theta\left[ \sum_{i=1}^\nexp\left( \sum_{\zsi} Q^{(t)}_i(\zsi) \log \frac{ p(\xsi, \zsi;\theta) }{ Q^{(t)}_i(\zsi)}\right)  + \alpha \left(\sum_{i=1}^{\tilde{\nexp}} \log p(\tilde{x}^{(i)},\tilde{z}^{(i)};\theta)\right)\right]
\end{align*}

\begin{enumerate}
  \input{semi_supervised_em/01-convergence}
\ifnum\solutions=1 {
  \input{semi_supervised_em/01-convergence-sol}
} \fi

\end{enumerate}

\subsubsection*{Semi-supervised GMM}
Now we will revisit the Gaussian Mixture Model (GMM), to apply our semi-supervised EM algorithm. Let us consider a scenario where data is generated from $k \in \mathbb{N}$ Gaussian distributions, with unknown means $\mu_j \in \R^\di$ and covariances $\Sigma_j \in \mathbb{S}_+^\di$ where $j \in \{1,\ldots,k\}$. We have $\nexp$ data points $\xsi \in \R^\di, i \in \{1,\ldots,\nexp\}$, and each data point has a corresponding latent (hidden/unknown) variable $\zsi \in \{1,\ldots,k\}$ indicating which distribution $\xsi$ belongs to. Specifically, $\zsi \sim \text{Multinomial}(\phi)$, such that $\sum_{j=1}^k\phi_j = 1$ and $\phi_j \ge 0$ for all $j$, and $\xsi|\zsi \sim \mathcal{N}\left(\mu_{\zsi}, \Sigma_{\zsi}\right)$ i.i.d. So, $\mu$, $\Sigma$, and $\phi$ are the model parameters.

We also have additional $\tilde{\nexp}$ data points $\tilde{x}^{(i)} \in \R^\di, i \in \{1,\ldots,\tilde{\nexp}\}$, and an associated \emph{observed} variable $\tilde{z}^{(i)} \in \{1,\ldots,k\}$ indicating the distribution $\tilde{x}^{(i)}$ belongs to. Note that $\tilde{z}^{(i)}$ are known constants (in contrast to $\zsi$ which are unknown \emph{random} variables). As before, we assume $\tilde{x}^{(i)}|\tilde{z}^{(i)} \sim \mathcal{N}\left(\mu_{\tilde{z}^{(i)}}, \Sigma_{\tilde{z}^{(i)}}\right)$ i.i.d.

In summary we have $\nexp$ + $\tilde{\nexp}$ examples, of which $\nexp$ are unlabeled data points $x$'s with unobserved $z$'s, and $\tilde{\nexp}$ are labeled data points $\tilde{x}^{(i)}$ with corresponding observed labels $\tilde{z}^{(i)}$. The traditional EM algorithm is designed to take only the $\nexp$ unlabeled examples as input, and learn the model parameters $\mu$, $\Sigma$, and $\phi$.

Our task now will be to apply the semi-supervised EM algorithm to GMMs in order to also leverage the additional $\tilde{\nexp}$ labeled examples, and come up with semi-supervised E-step and M-step update rules specific to GMMs. Whenever required, you can cite the lecture notes for derivations and steps.

\begin{enumerate}
  \setcounter{enumii}{1}
  \input{semi_supervised_em/02-e-step}
\ifnum\solutions=1 {
  \input{semi_supervised_em/02-e-step-sol}
} \fi

  \input{semi_supervised_em/03-m-step}
\ifnum\solutions=1 {
  \input{semi_supervised_em/03-m-step-sol}
} \fi

  \input{semi_supervised_em/04-impl-unsupervised}
\ifnum\solutions=1 {
  \input{semi_supervised_em/04-impl-unsupervised-sol}
} \fi

  \input{semi_supervised_em/05-impl-semi-supervised}
\ifnum\solutions=1 {
  \input{semi_supervised_em/05-impl-semi-supervised-sol}
} \fi

  \input{semi_supervised_em/06-comparison}
\ifnum\solutions=1 {
  \input{semi_supervised_em/06-comparison-sol}
} \fi

\end{enumerate}


\chapter{Set Theory}
\emph{Salute to Discrete Mathematics.}

\section{Sets}
\label{sec:Sets}
(Informally,) A set is a collection of elements.

\section{Relations and Functions}
\label{sec:RelationsAndFunctions}

\subsection{Relations}
\label{sub:Relation}
Given $n$ sets $A_1,\dots,A_n$, a relation $R$ over them is a subset of $A_1 \times \cdots \times A_n$.

\begin{definition}[Binary Relation]
    \label{def:BinaryRelation}
    A \textbf{binary relation} $R$ is a relation over $A \times B$ given some $A$ and $B$.
    \begin{itemize}
        \item The \textbf{domain} of $R$, denoted by $\textrm{dom}(R)$, is $\{ x | \exists y: \langle x,y \rangle \in R \}$
        \item The \textbf{range} of $R$, denoted by $\textrm{rng}(R)$, is $\{ y | \exists x: \langle x,y \rangle \in R \}$
    \end{itemize}
\end{definition}

A binary relation is
\begin{itemize}
    \item \textbf{Reflexive} iff $\langle x, x \rangle \in R$ for each $x \in A$.
    \item \textbf{Symmetric} iff $\langle x,y \rangle \in R \longrightarrow \langle y,x \rangle \in R$.
    \item \textbf{Transitive} iff $\langle x,y \rangle \in R \land \langle y,z \rangle \in R \longrightarrow \langle x,z \rangle \in R$.
\end{itemize}

A relation is an \textbf{equivalence relation} if it is reflexive, symmetric and transitive.

\subsection{Functions}
\label{sub:Function}
\begin{definition}[Functions]
    \label{def:Function}
    A \textbf{function} $f: A \rightarrow B$ is a binary relation over $A \times B$ satisfying:
    \begin{itemize}
        \item Its domain is $A$.
        \item For each $x \in A$, there is a unique $y \in B$ such that $\langle x, y \rangle \in f$.
    \end{itemize}
\end{definition}

\begin{definition}[One-to-One (injective)]
    \label{def:Injective}
    A function $f: A \rightarrow B$ is \textbf{one-to-one (injective)} if for each $x, y \in A$,
    \[ f(x) = f(y) \Longrightarrow x = y. \]
\end{definition}

\begin{definition}[Onto (surjective)]
    \label{def:Surjective}
    A function is \textbf{onto (surjective)} if for each $y \in B$, there is some $x \in A$ such that $f(x) = y$.
\end{definition}

\begin{definition}[One-to-One Correspondence (bijective)]
    \label{def:Bijective}
    A function is a \textbf{one-to-one correspondence (bijective)} between $A$ and $B$ if $f$ is both one-to-one and onto.
\end{definition}

\subsection{Finite Sets}
\label{sub:FiniteSets}
\begin{definition}[Finite sets]
    \label{def:FiniteSets}
    The set $X$ is \textbf{finite} if there is a natural number $n$ and a one-to-one correspondence between $X$ and $\{0, 1, \dots, n\}$。

    The set $X$ is \textbf{infinite} if it is not finite.
\end{definition}

We use the notion of one-to-one correspondence between infinite sets to talk about the ``sizes'' of these infinite sets.

\begin{definition}[Enumerable Sets]
    \label{def:EnumerableSets}
    The set $X$ is \textbf{enumerable} if there is a one-to-one correspondence between $X$ and $\mathbb{N}$.
\end{definition}

\begin{definition}[Listing of Sets]
    \label{def:ListingOfSets}
    Let $A$ be a set. The sequence $a_0, a_1, \dots, a_n, \dots$ is a \textbf{listing} of $A$ if
    \begin{enumerate}
        \item $a_i \in A$ for each $a_i$.
        \item Every member of $A$ is equal to $a_n$ for some $n \in \mathbb{N}$.
    \end{enumerate}
\end{definition}

\begin{theorem}
    \label{thm:ListingAndEnumerableSets}
    The set $A$ is enumerable iff there is some listing without repetitions of $A$.
\end{theorem}
\begin{proof}
    $\Rightarrow$.

    $\exists f: A \mapsto \mathbb{N}$, and $f$ is a one-to-one correspondence. Therefore there exists an inverse function $f^{-1}: \mathbb{N} \mapsto A$.

    Therefore we can construct a listing
    $$ f^{-1}(0), f^{-1}(1), f^{-1}(2), \cdots $$

    $\Leftarrow$.

    Let $g(i) = a_i$. $g$ is one-to-one because the listing has no identical elements. $g$ is onto because every member in $A$ is equal to some $a_n$ in the listing.

    $f = g^{-1}$.
\end{proof}

\begin{definition}[Countable Sets]
    \label{def:CountableSets}
    A set is \textbf{countable} if it is finite or enumerable. A set is \textbf{uncountable} if it is not countable.
\end{definition}

\begin{theorem}
    \label{thm:CountableSets}
    A set $X$ is countable iff there is a one-to-one mapping $f: X \mapsto \mathbb{N}$.

    A set $X$ is countably infinite iff it is enumerable.
\end{theorem}
\begin{sketchproof}
    $\Rightarrow$: Straightforward. Follows immediately from the definition of finite \ref{sub:FiniteSets} and enumerable \ref{def:EnumerableSets} sets.

    $\Leftarrow$: Let $B = \textrm{rng}(f)$. Notice that $f$ is a one-to-one correspondence between $X$ and $B$.
    \begin{itemize}
        \item If $B$ is finite, then there exists some function $h: B \mapsto \{1,2,\dots,n\}$ s.t. $h$ is a one-to-one correspondence. Let $g = h \circ f$, then $g$ is a one-to-one correspondence from $X$ to $\{1,2,\dots,n\}$. Therefore by definition \ref{def:FiniteSets}, $X$ is finite and is thus countable.

        \item If $B$ is infinite, since $B \subseteq \mathbb{N}$, we can sort elements of $B$ in ascending order:
        \[ b_0 < b_1 < b_2 < \cdots < b_n < \cdots \]

        We have constructed a listing of $B$, and therefore $B$ is enumerable. Therefore by definition \ref{def:EnumerableSets}, there exists a one-to-one correspondence $h:B \mapsto \mathbb{N}$. Construct $g = h \circ f$, then $g$ must also be a one-to-one correspondence between $X$ and $\mathbb{N}$. Therefore by definition \ref{def:EnumerableSets}, the set $X$ is enumerable and thus countable.
    \end{itemize}
\end{sketchproof}

\begin{theorem}
    \label{thm:ListingAndCountableSets}
    The set $A$ is countable and nonempty iff there is some listing with possible repetitions of $A$.
\end{theorem}
\begin{sketchproof}
    $\Rightarrow$. If $A$ is enumerable, we are done by Theorem \ref{thm:ListingAndEnumerableSets}. If $A$ is finite, we can construct a listing $a_0, a_1, \cdots, a_n, a_n, \cdots$.

    $\Leftarrow$. Let $a_0, a_1, \cdots, a_n, \cdots$ be the listing. Define $f:A \mapsto \mathbb{N}$ by $f(a_i) = \min_j\left\{ j: a_j=a_i \right\}$. $f$ is one-to-one and by Theorem \ref{thm:CountableSets} we can conclude that $A$ is countable.
\end{sketchproof}

\begin{proposition}
    \label{prop:SubsetOfEnumerableSetsIsCountable}
    If $A$ is enumerable and $B \subseteq A$, then $B$ is countable.
\end{proposition}

\begin{theorem}
    \label{thm:LotsOfCountableSets}
    ~{}
    \begin{itemize}
        \item If $A$ and $B$ are countable, then $A \cup B$, $A \cap B$, and $A \times B$ are all countable.
        \item If each of $A_0, \dots, A_n, \dots$ is countable, then the union of these sets is also countable.
        \item If $A$ is countable and nonempty, then the set of all finite sequences of members of $A$ is countable.
    \end{itemize}
\end{theorem}

\subsection{Constructing Infinite Sets}
\label{sub:ConstructingInfiniteSets}

\begin{definition}[Characteristic Functions]
    \label{def:CharacteristicFunctions}
    Let $X$ be a set and let $A \subseteq X$. FOr any $a \in A$, let
    $$ C_A(a) = \begin{cases}
        1, &\quad a \in A\\
        0, &\quad a \notin A
    \end{cases} $$
    $C_A(a)$ is called the characteristic function of $A$.
\end{definition}

\begin{definition}[Power Sets]    \label{def:PowerSets}
    Let $A$ be a set, the power set of $A$ is
    \[ \mathcal{P}(A) = \{ X|X \subseteq A \} \]
\end{definition}

\begin{theorem}[Cantor's Theorem]
    \label{thm:CantorsTheorem}
    $\mathcal{P}(\mathbb{N})$ is uncountable.
\end{theorem}
\begin{proof}
    Proof by contradiction. Suppose $\mathcal{P}(\mathbb{N})$ is countable. Obviously $\mathcal{P}(\mathbb{N})$ is not finite, so it must be enumerable.

    By Theorem \ref{thm:ListingAndEnumerableSets}, we can construct a listing with no repetitions.

    We can list all subsets of $A$ using characteristic functions.
    \[\begin{bmatrix}
        \emptyset & \begin{bmatrix} 0 & 0 & \cdots & 0 \end{bmatrix}\\
        \{0\} & \begin{bmatrix} 1 & 0 & \cdots & 0 \end{bmatrix}\\
        \{1\} & \begin{bmatrix} 0 & 1 & \cdots & 0 \end{bmatrix}\\
        \{0, 1\} & \begin{bmatrix} 1 & 1 & \cdots & 0 \end{bmatrix}\\
        \cdots & \cdots\\
    \end{bmatrix}\]

    We can then select all the bits along the diagonal and flip these bits to form a new bit sequence. This sequence can also be interpreted as a listing of some subset of $\mathcal{P}(\mathbb{N})$. However, this listing cannot exist in the listed listings, because it has at least one bit that is different from any existing listings. This listing fails to enumerate all subsets of $\mathcal{P}(\mathbb{N})$, and therefore the set $\mathcal{P}(\mathbb{N})$ is uncountable.
\end{proof}

\begin{corollary}
    $\mathbb{R}$ is uncountable.
\end{corollary}

\subsection{Domination of Sets}

\begin{definition}[Domination of Sets]
    \label{def:SetDomination}
    ~{}
    \begin{itemize}
        \item $A \preceq B$ if there is a one-to-one function $f: A \mapsto B$.
        \item $ A \prec B$ if $A \preceq B$ but $B \npreceq A$.
        \item $A \equiv B$ if $A \preceq B$ and $B \preceq A$.
    \end{itemize}
\end{definition}

\begin{theorem}[Cantor-Schr\"oder-Bernstein]
    \label{thm:CSB}
    $A \equiv B$ iff there is a one-to-one correspondence between $A$ and $B$.
\end{theorem}
\begin{proof}
    Refer to supplementary material on Canvas.
\end{proof}

\begin{theorem}[Cantor's Theorem]
    \label{thm:Cantor}
    For every set $A$,
    \[ A \prec \mathcal{P}(A) \]
\end{theorem}
\begin{proof}
    We need to prove 1) $A \preceq \mathcal{P}(A)$ and 2) $\mathcal{P}(A) \npreceq A$. 1) is easy because $\forall a \in A$, $\{a\} \subseteq A$ and therefore $\{a\} \in \mathcal{P}(A)$.

    To prove 2), assume $\mathcal{P}(A) \preceq A$, by theorem \ref{thm:CSB} we have $\mathcal{P}(A) \equiv A$, and therefore there should exist a one-to-one correspondence $f: A \mapsto \mathcal{P}(A)$.

    Let
    \[ B = \{x \in A|x \notin f(x)\} \]

    Then $B \subseteq A$, and $B \in \mathcal{P}(A)$. Since $f$ is onto, there must exist some $b \in A$ s.t. $f(b) = B$.

    \begin{enumerate}
        \item If $b \in f(b) = B$. Then $b \in f(b) \Rightarrow b \notin f(b)$. Boom.
        \item If $b \notin f(b)$. Then $b \in B = f(b)$. Boom.
    \end{enumerate}

    Therefore $\mathcal{P}(A) \npreceq A$.
\end{proof}
\begin{corollary}
    For every $A$ there exists a $B$ s.t. $A \prec B$.
\end{corollary}
\begin{corollary}
    $\mathcal{P}(\mathbb{N})$ is uncountable.
\end{corollary}
\begin{proof}
    $\mathcal{P}(\mathbb{N}) \npreceq \mathbb{N}$.
\end{proof}

\subsection{Sets of Functions}

\begin{definition}[Set of Functions]
    \label{def:SetOfFunction}
    $~^{A} B$ is the set of all functions that map $A$ into $B$.
\end{definition}
\begin{remark}
    The set $~^A\{0,1\}$ is the set of all characteristic functions (\ref{def:CharacteristicFunctions}).
\end{remark}

\begin{theorem}
    There is a one-to-one correspondence between $~^{\mathbb{N}}\{0,1\}$ and $\mathcal{P}(\mathbb{N})$.
\end{theorem}
\begin{remark}
    A generalized version: there is a one-to-one correspondence between $~^{\mathbb{A}}\{0,1\}$ and $\mathcal{P}(\mathbb{A})$
\end{remark}
\begin{corollary}
    \label{cor:RealIsUncountable}
    $\mathbb{R}$ is uncountable.
\end{corollary}
\begin{theorem}
    \label{thm:NNisUncountable}
    $~^\mathbb{N}\mathbb{N}$ is uncountable.
\end{theorem}
\begin{proof}
    Assume $~^\mathbb{N}\mathbb{N}$ is countable. Since $~^\mathbb{N}\{0,1\} \subseteq ~^\mathbb{N}\mathbb{N}$. $~^\mathbb{N}\{0,1\}$ must be countable. Boom.
\end{proof}

\subsection{Generalized Continuum Hypothesis}

\begin{center}
    \textbf{Is there a set $A$ s.t. $\mathbb{N} \prec A \prec \mathbb{R} \equiv \mathcal{P}(\mathbb{N})$?}
\end{center}


\section{Application to Bilinear Form}
We want to analyse bilinear forms by our study in spectral theory.
\begin{corollary}
    Let $A\in M_n(F)$ for $F=\mathbb R$ (resp. $\mathbb C$) be a symmetric (resp. Hermitian) matrix, then there is an orthogonal (resp. unitary) matrix $P$ such that $P^\top AP$ is a real diagonal matrix.
\end{corollary}
\begin{proof}
    Just take $P$ to be the basis of orthonormal eigenvectors that spans $V$ which exists by spectral theorem.
\end{proof}
\begin{corollary}
    Let $V$ be a finite dimensional inner product space over $F=\mathbb R$ (resp. $\mathbb C$) and $\phi:V\times V\to F$ be a symmetric bilinear (resp. Hermitian) form.
    Then there is an orthogonal basis of $V$ in which $\phi$ is diagonal.
\end{corollary}
\begin{proof}
    Follows directly from the preceding corollary and the change-of-basis formula for bilinear/sesquilinear forms.
\end{proof}
\begin{remark}
    The diagonal entries in above corollaries are, of course, the eigenvalues.
\end{remark}
\begin{corollary}[Simultaneous Diagonalisation]
    et $V$ be a finite dimensional inner product space over $F=\mathbb R$ (resp. $\mathbb C$) and $\phi,\psi:V\times V\to F$ be symmetric bilinear (resp. Hermitian) forms.
    Assume $\phi$ is positive definite, then there exists a basis of $V$ in which both are diagonalised.
\end{corollary}
\begin{proof}
    Define a new scalar product by $\langle v,w\rangle=\phi(v,w)$ which works as $\phi$ is positive definite.
    Then just take the basis to be the basis in which $\psi$ is diagonal under this new inner product.
\end{proof}
Note that in this new basis that we described, $\phi$ is actually represented the identity matrix.
\begin{corollary}
    Let $A,B\in M_n(F)$ where $F=\mathbb R$ (resp. $\mathbb C$).
    Suppose they are both symmetric (resp. Hermitian) and assume that for any $x\neq 0,x^\top Ax>0$, then there exists $Q\in M_n(F)$ such that both $Q^\top AQ$ and $Q^\top BQ$ are diagonal.
\end{corollary}
\begin{proof}
    Just a restatement of the preceding corollary.
\end{proof}


\subsection{Exponents}

Parentheses are required around negative exponents.
For example,

{\color{blue}
\begin{verbatim}
10^(-3)
\end{verbatim}
}

\noindent
instead of

{\color{blue}
\begin{verbatim}
10^-3
\end{verbatim}
}

\noindent
The reason for this is that the binding of the negative sign is not always obvious.
For example, consider

{\color{blue}
\begin{verbatim}
x^-1/2
\end{verbatim}
}

\noindent
It is not clear whether the exponent should be $-1$ or $-1/2$.
Hence the following syntax is required.

{\color{blue}
\begin{verbatim}
x^(-1/2)
\end{verbatim}
}

\noindent
In general, parentheses are always required when the exponent
is an expression.
For example, \verb$x^1/2$ is evaluated as $(x^1)/2$ which
is probably not the desired result.

{\color{blue}
\begin{verbatim}
x^1/2
\end{verbatim}
}

\noindent
$\displaystyle \tfrac{1}{2}x$

\bigskip
\noindent
Using \verb$x^(1/2)$ yields the desired result.

{\color{blue}
\begin{verbatim}
x^(1/2)
\end{verbatim}
}

\noindent
$\displaystyle x^{1/2}$