% !TEX root = as_grf_sopt.tex
\cite{wang2013active} proposed an active search algorithm for graphs, building on label propagation and semi-supervised
learning using Gaussian random fields \citep{zhu2003semi,zhu2003combining}. Despite decent empirical performances, this approach does not have any theoretical guarantee.
\cite{vanchinathanadaptively} proposed a Gaussian-Process (GP) based algorithm,
GP-SELECT, for sequentially selecting instances with high user scores or ratings (rewards).
%, whose nodes are instances and edges encode pairwise similarity
%between instances. An application, for example, can be finding publications related to a certain subject based on a citation network.
This algorithm extends the popular GP-UCB algorithm \citep{cox1997sdo,auer2003using} for stochastic optimization and
inherits nice theoretical guarantees \citep{srinivas2012information}.
When applied to graphs, however, it tends to select nodes at the periphery of the graph because they have
large predictive variances, leading to large exploration factors in the GP-UCB selection rule.
Yet the rewards of these nodes
reveal little information about the reward distribution over the whole graph.

Similar issues have been observed in active learning on graphs as well.
In their experiments, \cite{ma_2013} found that
selection rules based on mutual information gain \citep{MIG}, which is closely related to
per-node predictive variances, usually end up selecting nodes at the periphery of a graph.
\cite{mingji} proposed a selection criterion based on one-step lookahead decrease of the average variance of all remaining nodes, which effectively considers not only the predictive variance of the search node itself,
but also its covariances with all remaining nodes.
This criterion corresponds to standard V-optimality
in experiment design. \cite{ma_2013} further improved the state of the art by using
the $\Sigma$-optimality criterion, which demonstrates greater robustness against outliers and
better empirical performances than V-optimality. Motivated by these recent advances, we propose
new active search algorithms that combine GP-UCB with $\Sigma$-optimality.

\cite{valko2014spectral} considered bandit problems where arms correspond to nodes on a graph
and the reward is a smooth function over the graph. Their algorithm can be viewed as a special
case of GP-UCB with a kernel defined by the inverse of a graph Laplacian (augmented with an identity matrix).
To analyze the performance of their UCB-style algorithm, they propose the notion of
\textit{effective dimension} of a graph, which can be viewed as a measure of the spectral decay
of the kernel, thereby determining the performance of the algorithm \citep{srinivas2012information}.
We also use the effective dimension to analyze our proposed methods.

% As shown later, we benefit from the analysis techniques of \cite{contal2014gaussian} in proving
% theoretical guarantees of one of the proposed algorithms. They developed a GP optimization algorithm that achieves
% better theoretical guarantees than GP-UCB. By using their techniques, we are able to make a connection
% between exploration in the bandit optimization setting and the variance minimization principle in active learning.

%it may not be robust against outliers, such as
%nodes at the boundary of a graph, because of the way it decides the amount of exploration.

%\subsection{Gaussian Process Bandit Optimization}
%
%
%We use the following kernel matrix
%\begin{equation}
%	\bK = (\cLap + \omega_0 \bI)^{-1},
%	\label{eq:kernel}
%\end{equation}
%where $\omega_0$ is a regularization parameter set to $|\bA|^{-1}$.%\todo{why and which norm?}
%
%If we apply the set of priors,
%\begin{equation}
%	y(v_i) = f(v_i) + \epsilon
%	,\quad
%	\mathbf{f} \sim \mathcal{N}(0, \bK)
%	,\quad
%	\epsilon \stackrel{iid}{\sim} \mathcal{N}(0,\sigma^2)
%	,
%\end{equation}
%where $\mathbf{f} = \begin{pmatrix}f(v_1),\dotsc,f(v_n)\end{pmatrix}^\top$,
%then the posterior inference, after pulling
%$S_t=\{v_1,\dotsc,v_t\}$
% and observing
%$\by_t=\begin{pmatrix} y_1,\dotsc,y_t \end{pmatrix}^\top$, becomes
%\begin{align*}
%	\mathbf{f}_t &\sim \mathcal{N}(\bmu_t, \bC_t),\quad
%	y(v_i) = f_t(v_i) + \epsilon,
%	\\
%	{\rm s.t.} &\left\{\begin{aligned}
%		\mu_t(v)  &= \bk_{S_t,v}^\top(\sigma^2 \bI+\bK_{S_t,S_t})^{-1}\by_t
%		\\
%		 C_t(v,v') &= k_{v,v'}
%		-\bk_{S_t,v}^\top (\sigma^2 \bI+\bK_{S_t,S_t})^{-1}\bk_{S_t,v'}.
%	\end{aligned}\right.
%	\numberthis
%	\label{eq:graph_update}
%\end{align*}
%
%For the posterior covariance, define
%\begin{equation}
%	C_t(v,v') = \rho_t(v,v')\sigma_t(v)\sigma_t(v'),
%\end{equation}
%which implies that $\rho_t^2(v) = C_t(v,v)$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\subsection{Search Heuristics}

%Based on the posterior distribution of node labels, there are several criteria for the selection rule of the next node to acquire labels.
%We list three criteria in the following, all in the form of
%\begin{equation}
%	\argmax_v \; \mu_t(v) + c_t \cdot g_t(v),
%\end{equation}
%where $\mu_t(v)$ is a greedy term, $c_t$ is an iteration-dependent constant which controls risks, and $g_t(v)$ is the objective function for a specific exploration heuristic.%
%\todo{introduce cumulative regret.}
%\todo{not sure if true: The cumulative regret can all be bounded by pure exploration algorithms applying only the $g_t(v)$ term.}

%%%%%%%%%%%%%%%%%%%%%%%%

%\textbf{Spectral-UCB criterion} applies the following selection rule,
%\begin{equation}
%	v_{t+1} = \argmax_v \, \mu_t(v) + c_t\cdot\sigma_t(v),
%	\label{eq:ucb_criterion}
%\end{equation}
%where $\sigma_t(v)=\sqrt{C_t(v,v)}$ is the exploration objective.
%In this case, exploration is connected to mutual information gain, because $g_v(t)$ by itself has the same argmax as the following,
%\begin{align*}
%	I_t(y(v_t); \mathbf{f})
%	&=
%	H_t(y(v_t)) - H_t(y(v_t) \mid \mathbf{f})
%	\\
%	&=
%	\frac{1}{2}\log\left(1 + \frac{\sigma_t^2(v)}{\sigma^2}\right)
%	.
%%	  \geq
%%  \frac{1}{2}\frac{\sigma_t^2(v)}{\sigma^2}
%%  \frac{\log(1+M)}{M},
%\end{align*}
%
%Standard UCB analysis shows that the cumulative regret%
%\todo{not sure if true}
%is indeed bounded by a pure exploration algorithm that maximizes information gain (\appref{app:sec:spectral_regret}).

%%%%%%%%%%%%%%%%%%%%%%%%

%\textbf{V-Optimality} uses the following objective,
%\begin{equation}
%	g_t(v) =
%	\frac{\sigma_t(v)}{\sqrt{1+\sigma_t^2(v)}}
%	\cdot
%	\sqrt{\frac{1}{n} \sum_{j=1}^{n}\rho_t^2(v,v_j)\sigma_t^2(v_j)},
%\end{equation}
%where the exploration component is related to the reduction of expected Bayes risk,
%\begin{equation}
%	\mathcal{R}_t = \mathbb{E} \sum_{j=1}^n \left( f_t(v_j)-\mu_t(v_j) \right)^2 = \sum_{j=1}^n C_t(v_j,v_j)
%\end{equation}
%because the rank-one update rule of \eqref{eq:var_update} indicates,
%\begin{equation}
%	\mathcal{R}_{t+1} = \mathcal{R}_t -
%	\sum_{j=1}^n
%	\frac{\left( \rho_{t}(v_t,v_j)\sigma_{t}(v_t)\sigma_t(v_j) \right)^2}{\sigma^2+\sigma_t^2(v)}.
%\end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\subsection{Analysis of Spectral UCB}
%
%With probability no less than $\Phi(c_t)^2$, the true regret at time $t$,
%\begin{equation}
%	r_t = f(v_\ast) - f(v_t)\leq 2c_t\sigma_t,
%\end{equation}
%which coincidentally is also involved in the computation of expected information gain (i.e., mutual information) as,
%\begin{align*}
%	I_t(y(v_t); \mathbf{f})
%	=
%	H_t(y(v_t)) - H_t(y(v_t) \mid \mathbf{f})
%	\\
%	=
%	\frac{1}{2}\log\left(1 + \frac{\sigma_t^2(v)}{\sigma^2}\right)
%	\geq
%	\frac{1}{2}\frac{\sigma_t^2(v)}{\sigma^2}
%	\frac{\log(1+M)}{M},
%\end{align*}
%
%
%\hrule
%\textbf{(appendix: No regret)}
%
%\input{appendix_spectral_ucb_regret.tex}
%
%\hrule
%where the last inequality comes from concavity of the logarithm function and holds for any fixed $M$ that satisfies,
%\begin{equation}
%	M
%	\geq\sup_{v}\frac{\sigma_0^2(v)}{\sigma^2}
%	\geq\sup_{t,v}\frac{\sigma_t^2(v)}{\sigma^2}.
%\end{equation}
%A simple choice is $M=\omega_0^{-1}$.
%
%Since the information gain can be concatenated, we have a natural bound for cumulative regret,
%\begin{align*}
%	&\sum_{t=1}^T r_t
%	\leq
%	2 c_{\max_T} \sum_{t=1}^T \sigma_t(v_t)
%	\leq
%	2 c_{ \max_T } \sqrt{T \sum_{t=1}^T \sigma_t^2(v_t) }
%	\\
%	&\leq
%	2 c_{ \max_T } \sqrt{T \frac{2\sigma^2 M}{\log(1+M)} \sum_{t=1}^T I_t(y(v_t);\mathbf{f})}
%	\\
%	&=
%	2 c_{ \max_T } \sqrt{T \frac{2\sigma^2 M}{\log(1+M)} I(y(v_1),\dotsc,y(v_T);\mathbf{f})}
%	\numberthis
%	,
%\end{align*}
%with probability no less than,
%\begin{equation}
%	\prod_{t=1}^T\Phi(c_t)^2
%	\geq
%	\dotsc,
%\end{equation}
%where $c_{\max_T}=\max_{t=1,\dotsc,T}c_t$.


\documentclass[a4paper, 11pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{amssymb}
\renewcommand{\familydefault}{\ttdefault}
\setlength\parindent{0pt}

\begin{document}
\section*{Axioms}
\subsection*{Field Axioms}

\begin{enumerate}
  \item COMMUTATIVE LAWS: $x + y = y + x$ and $xy = yx$
  \item ASSOCIATIVE LAWS: $x + (y + z) = (x + y) + z$ and $x(yz) = (xy)z$
  \item DISTRIBUTIVE LAW: $x(y + z) = xy + xz$
  \item EXISTENCE OF IDENTITY ELEMENTS: there exists two distinct real numbers: 0 and 1,\\ such that $x + 0 = x$ and $1x = x$
  \item EXISTENCE OF NEGATIVES: for $x \in \mathbb{R}$ there is $y \in \mathbb{R}$ such that $x + y = 0$
  \item EXISTENCE OF RECIPROCALS for $x \in \mathbb{R} \ | \ x \ne 0$ there is $y \in \mathbb{R}$ such that $xy = 1$
\end{enumerate}

\subsection*{Order Axioms}
\begin{enumerate}
  \item If $x, y \in \mathbb{R}^+$, so are $x + y$ and $xy$
  \item $\forall x \in \mathbb{R} \ | \ x \ne 0$ either $x \in \mathbb{R}^+$ or $-x \in \mathbb{R}^+$
  \item $0 \notin \mathbb{R}^+$
\end{enumerate}

\subsection*{Least uppper bound Axiom}
\begin{enumerate}
  \item $\forall S: S \ne \emptyset, S \subset \mathbb{R}$, if S is bounded above, then S has a \emph{supremum}, i.e. $\exists B: B = sup\ S$
\end{enumerate}

\hrulefill

\section*{Exercises 1.3.12}

\hrulefill

1. If $x \in \mathbb{R}$ and $y \in \mathbb{R}$ with $x < y$, prove that there is at least one $z \in \mathbb{R}$, so that it satisfies $x < z < y$.

\emph{Proof:} If $x < y$ then $y - x > 0$ adding $y - x$ to both sides of inequality, we have:

$$2(y - x) > y - x \ \textrm{or} \ y - x > \frac{y - x}{2}$$

because $y - x > 0$ and $\frac{1}{2} > 0$, then
$$\frac{y - x}{2} > 0$$

Hence, adding x to inequality:

$$0 < \frac{y - x}{2} < y - x \Rightarrow x < \frac{y - x}{2} < y$$

setting $z = \frac{y - x}{2}$ we prove $x < z < y$

\hrulefill

2. If $x \in R$, prove that there are $m, n \in \mathbb{Z}$ such that $m < x < n$.

\emph{Proof:} By theorem 1.32 we have there exists $n \in \mathbb{Z}$ such that
$n > x$, also by the same way we can prove that there exists $m \in \mathbb{Z}$
such that $m < x$, because if it didn't exist then $x$ would be the lower bound
for $\mathbb{Z}$

\hrulefill

3. If $x > 0$, prove that there are $n \in \mathbb{Z}^+$ such that $n^{-1} < x$.

\emph{Proof:} By theorem 1.30 we have: if $x > 0$ then $\forall y \in \mathbb{R}, \exists n : nx > y$,
letting $y = 1$ we have $nx > 1$ and $x > \frac{1}{n}$

\hrulefill

\emph{BREAKING HERE. APOSTOL IS KINDA TOO HARD ON PROOFS. MIGHT RETURN TO IT LATER}

\section*{SPIVAK ONE VARIABLE CALCULUS}
\section*{CHAPTER 1}
\subsection*{Properties of numbers}
\begin{enumerate}
  \item $\forall (a, b, c),  a + (b + c) = (a + b) + c$
  \item $\forall a,  a + 0 = 0 + a = a$
  \item $\forall a, a + (-a) = 0$
  \item $\forall (a, b), a + b = b + a$
  \item $\forall (a, b, c), a(bc) = (ab)c$
  \item $\forall a, a1 = 1a = a$ and $1 \ne 0$
  \item $\forall a: a \ne 0, \exists a^{-1}$ such that $aa^{-1} = 1$
  \item $\forall (a, b), ab = ba$
  \item $\forall (a, b, c), a(b + c) = ab + ac$
  \item $\forall a, a = 0$ or $a \in \mathbb{R}^+$ or $-a \in \mathbb{R}^+$
  \item $\forall (a, b)$ if $a \in \mathbb{R}^+$ and $b \in \mathbb{R}^+$ then $a + b \in \mathbb{R}^+$
  \item $\forall (a, b)$ if $a \in \mathbb{R}^+$ and $b \in \mathbb{R}^+$ then $ab \in \mathbb{R}^+$
\end{enumerate}

\subsection*{Theorems related to numbers}
\begin{enumerate}
  \item $\forall (a, b), |a + b| \leq |a| + |b|$
\end{enumerate}

\subsection*{\underline{Exercises}}
1.1 IF $ax = a$ for some $a \ne 0$, then $x = 1$\\
\emph{Proof:}
By multiplying both sides of equation by reciprocal of $a$ we have:
$$aa^{-1}x = aa^{-1} \Rightarrow 1x = 1 \ [P7]$$
applying P6 we get $x = 1$

\hrulefill

1.2 $x^2 - y^2 = (x - y)(x + y)$\\
\emph{Proof:}
Apply P9 twice, let $(x + y) = c$ then
$$(x - y)c = xc - yc$$
substitute back $c = (x + y)$ and reapply P9
$$x(x + y) - y(x + y) = xx + xy - yx - yy$$
using P8 and P3 we have:
$$xx + xy - yx - yy = xx + xy - xy - yy = xx - yy = x^2 - y^2$$

\hrulefill

1.3 $x^2 = y^2 \Rightarrow x = y \ or \ x = -y$\\
\emph{Proof:}
We can observe the fact that:
$$\sqrt{x^2} = |x|$$
then we can take square roots of both sides of equation:
$$\sqrt{x^2} = \sqrt{y^2} = |x| = |y|$$
then we have 4 cases:
$$x \geq 0, y \geq 0$$
$$x \leq 0, y \geq 0$$
$$x \leq 0, y \leq 0$$
$$x \geq 0, y \leq 0$$
if the 1st or 3rd case is true, then $x = y$, if 2nd or 4th case is true, then $x = - y$

\hrulefill

1.4 $x^3 - y^3 = (x - y)(x^2 + xy + y^2)$\\
\emph{Proof:}
Triple application of P9:
$$(x - y)(x^2 + xy + y^2) = x^3 + x^2y + xy^2 - x^2y - xy^2 - y^3$$
using P8 and P3 again we have:
$$x^3 + x^2y + xy^2 - x^2y - xy^2 - y^3 = x^3 + x^2y - x^2y + xy^2 - xy^2 - y^3 = x^3 - y^3$$

\hrulefill

1.5 $x^n - y^n = (x - y)(x^{n-1} + x^{n-2}y + x^{n-3}y^2 + \ldots + xy^{n-2} + y^{n-1})$\\
\emph{Proof:}
We can rewrite the right hand side as as
$$(x - y) \sum_{i=0}^{n-1}x^iy^{n-1-i} = x\sum_{i=0}^{n-1}x^iy^{n-1-i} - y\sum_{i=0}^{n-1}x^iy^{n-1-i} = $$
$$x^n + \sum_{i=0}^{n-2}x^{i+1}y^{n-1-i} - (y^n + \sum_{i=1}^{n-1}x^iy^{n-i}) = $$
from here, we should be able to prove that
$$\sum_{i=0}^{n-2}x^{i+1}y^{n-1-i} = \sum_{i=1}^{n-1}x^iy^{n-i}$$
if we were to substitute $i - 1$ with $k$ then
$$\sum_{i=0}^{n-2}x^{i+1}y^{n-1-i} = \sum_{k=0}^{n-2}x^{k+1}y^{n-(k+1)} = \sum_{k=0}^{n-2}x^{k+1}y^{n-1-k}$$
then, it's possible to rewrite our original equation as
$$x^n - y^n + (\sum_{i=0}^{n-2}x^{i+1}y^{n-1-i} - \sum_{i=1}^{n-1}x^iy^{n-i} ) = x^n - y^n + 0$$

\hrulefill

1.6 $x^3 + y^3 = (x + y)(x^2 - xy + y^2)$\\
\emph{Proof:}
Using proof of in 1.4 we can replace $y$ with $-y$ and as a result we have
$$(x - (-y))(x^2 + x(-y) + y^2) = x^3 + x^2(-y) + xy^2 - x^2(-y) - xy^2 - (-y)^3$$
which can be simplified as
$$(x + y)(x^2 - xy + y^2) = x^3 - x^2y + xy^2 + x^2y - xy^2 + y^3 = x^3 + y^3$$

\hrulefill

2 what's wrong with the following proof? Let $x = y$, then
$$xy = x^2$$
$$x^2 - y^2 = xy - y^2$$
$$(x - y)(x + y) = y(x - y)$$
$$(x + y) = y$$
$$2y = y$$
$$2 = 1$$
\emph{Solution:}
At step 3, both sides of equation was divided by $(x - y)$ as a common factor.\\
But from initial conditions $x = y$, it follows, that $x - y = 0$, so what
actually happened, is division by zero (which is undefined), that's why the answer is nonsense.

\hrulefill

3.1 $\frac{a}{b} = \frac{ac}{bc}$, where $b, c \ne 0$\\
\emph{Proof:}
Let's multiply the left hand side of the equation by number $c \ne 0$ and it's\\
multiplicative inverse $c^{-1}$, and according to P7 $cc^{-1} = 1$, and according to P6 $a1 = a$.
$$\frac{a}{b}1 = \frac{a}{b}cc^{-1} = acb^{-1}c^{-1}$$
Which can be rewritten as
$$acb^{-1}c^{-1} = ac(bc)^{-1} = \frac{ac}{bc}$$

\hrulefill

3.2 $\frac{a}{b} + \frac{c}{d} = \frac{ad + cb}{bd}$, where $b, d \ne 0$\\
\emph{Proof:}
Using the same technique as in 3.1 multiply lhs of equation by $dd^{-1}$ and $bb^{-1}$
$$(\frac{a}{b} + \frac{c}{d})dd^{-1}bb^{-1} = ab^{-1}bb^{-1}dd^{-1} + cd^{-1}bb^{-1}dd^{-1} = $$
$$(ad)(b^{-1}d^{-1}) + cb(b^{-1}d^{-1}) = (ad + cb)(b^{-1}d^{-1}) = \frac{ad + cb}{bd}$$

\hrulefill

3.5 $\frac{a}{b} / \frac{c}{d} = \frac{ad}{bc}$, where $b, d, c \ne 0$\\
\emph{Proof:}
Let's rewrite it in a different form
$$ab^{-1}(cd^{-1})^{-1} = ab^{-1}(c^{-1}(d^{-1})^{-1})$$
because $(d^{-1})^{-1} = d$, then we can make final rearrangement
$$ab^{-1}(c^{-1}(d^{-1})^{-1}) = adb^{-1}c^{-1} = \frac{ad}{bc}$$

\hrulefill

4.4 find $x$ such that $(x - 1)(x - 3) > 0$\\
\emph{Solution:}
For a product of two numbers to be positive, they both need to be positive or\\
both should be negative. Thus:
$$x - 1 > 0, x - 3 > 0$$ or $$x - 1 < 0, x - 3 < 0$$
solving those inequalities, we have:
$$x > 1, x > 3 \Rightarrow x > 3$$ or $$x < 1, x < 3 \Rightarrow x < 1$$
i.e $x > 3, x < 1$

\hrulefill

4.7 Find $x$ such that $x^2 - x + 10 > 16$\\
\emph{Solution:}
Let's try to solve quadratic equation of the form $x^2 - x - 6 = 0$, and if it
does not have roots, then $\forall x \in \mathbb{R}$ the
inequality will hold true, if does have roots, then it's possible to factor
the lhs and try to solve inequality by parts
$$x^2 - x - 6 = 0$$
$$x = \frac{1 \pm \sqrt{1 + 24}}{2} = (-2, 3)$$
Hence the factore version of original inequality has the form:
$$(x + 2)(x - 3) > 0$$
which has the solution of $x > 3, x < -2$

\hrulefill

4.11 Find $x$ such that $2^x < 8$\\
\emph{Solution:}
Lets take $\log_2$ of both sides of inequality:
$$\log_2{2^x} < \log_2{8} \Rightarrow x < 3$$

\hrulefill

4.14 Find $x$ such that $\frac{x - 1}{x + 1} > 0$\\
\emph{Solution:}
Let's rewrite the inequality:
$$(x - 1)(x + 1)^{-1} > 0$$
so, either $x - 1 > 0, (x + 1)^{-1} > 0$ or $x - 1 < 0, (x + 1)^{-1} < 0$, which resolves to
$$x > 1, (x + 1)^{-1} > 0 \Rightarrow (x + 1) > 0 \Rightarrow x > - 1$$
$$x < 1, (x + 1)^{-1} < 0 \Rightarrow (x + 1) < 0 \Rightarrow x < - 1$$
i.e the final answer is $x > 1, x < -1$

\hrulefill

5.1 $a < b, c < d \Rightarrow a + c < b + d$\\
\emph{Solution:}
$$a < b \Rightarrow b - a > 0$$
$$c < d \Rightarrow d - c > 0$$
adding those inequalities:
$$b - a + d - c > 0 \Rightarrow (b + d) - (a + c) > 0 \Rightarrow a + c < b + d$$

\hrulefill

5.2 $a < b \Rightarrow -a < -b$\\
\emph{Solution:}
$$a < b \Rightarrow b - a > 0 \Rightarrow -(-(b - a)) > 0 \Rightarrow -a - (-b) > 0 \Rightarrow -b < -a$$

\hrulefill

5.4 $a < b, c > 0 \Rightarrow  ac < bc$\\
\emph{Solution:}
$$a < b \Rightarrow b - a > 0$$
multiplying both sides by c:
$$c(b - a) > 0 \Rightarrow bc - ac > 0 \Rightarrow ac < bc$$

\hrulefill

5.7 $0 < a < 1 \Rightarrow a^2 > a $\\
\emph{Solution:}
$$a < 1 \Rightarrow 1 - a > 0$$
multiplying both sides by a:
$$a(1 - a) > 0 \Rightarrow 1a - aa > 0 \Rightarrow a^2 < a$$

\hrulefill

6 IF $0 < a < b$, then
$$a < \sqrt{ab} < \frac{a + b}{2} < b$$
\emph{Solution:}

\hrulefill

12.4 $|x - y| \leq |x| + |y|$\\
\emph{Proof:}
$$|x - y| = |x + (-y)| \leq |x| + |-y| = |x| + |y|$$

\hrulefill

17.2 If $b^2 - 4c < 0$ show that $\nexists x \in \mathbb{R}$ such that $x^2 + bx + c = 0$\\
\emph{Proof:}
Note that $b^2 - 4c < 0 \Rightarrow 4c - b^2 > 0 \Rightarrow c - b^2/4$. Then
$$x^2 + bx + c = 0 \Rightarrow (x + \frac{b}{2})^2 + (c - \frac{b^2}{4})$$
$$(x + \frac{b}{2})^2 + (c - \frac{b^2}{4}) \geq (c - \frac{b^2}{4}) > 0$$
Thus $(x + \frac{b}{2})^2 + (c - \frac{b^2}{4}) = x^2 + bx + c > 0, \forall x \in \mathbb{R}$

\hrulefill

\underline{\emph{Shwartz inequality}}:
$$x_1y_1 + x_2y_2 \leq \sqrt{x_1^2 + x_2^2}\sqrt{y_1^2 + y_2^2}$$
18.1 \underline{Proof 1}
$$(x_1^2 + x_2^2)(y_1^2 + y_2^2) = (x_1y_1 + x_2y_2)^2 + (x_1y_2 - x_2y_1)^2$$
$$(x_1^2 + x_2^2)(y_1^2 + y_2^2) = x_1^2y_1^2 + x_1^2y_2^2 + x_2^2y_1^2 + x_2^2y_2^2$$
$$(x_1^2y_1^2 + 2x_2y_2 + x_2^2y_2^2) + (x_1^2y_2^2 - 2x_2y_2 + x_2^2y_1^2) = (x_1y_1 + x_2y_2)^2 + (x_1y_2 - x_2y_1)^2$$
Let's rewrite the inequality a bit
$$x_1y_1 + x_2y_2 \leq \sqrt{x_1^2 + x_2^2}\sqrt{y_1^2 + y_2^2} = \sqrt{(x_1^2 + x_2^2)(y_1^2 + y_2^2)} = $$
$$\sqrt{(x_1y_1 + x_2y_2)^2 + (x_1y_2 - x_2y_1)^2}$$
because $(x_1y_2 - x_2y_1)^2 \geq 0, \forall x \in \mathbb{R}$
$$\sqrt{(x_1y_1 + x_2y_2)^2} \leq \sqrt{(x_1y_1 + x_2y_2)^2 + (x_1y_2 - x_2y_1)^2}$$
$$x_1y_1 + x_2y_2 \leq \sqrt{(x_1y_1 + x_2y_2)^2 + (x_1y_2 - x_2y_1)^2} = \sqrt{x_1^2 + x_2^2}\sqrt{y_1^2 + y_2^2}$$

\hrulefill

18.2 \underline{Proof 2}
If $x_1 = \lambda y_1$ and $x_2 = \lambda y_2$ then \emph{Shwartz inequality} holds, it actually becomes an equality
$$\lambda y_1^2 + \lambda y_2^2 \leq \sqrt{\lambda^2 y_1^2 + \lambda^2 y_2^2}\sqrt{y_1^2 + y_2^2}$$
$$\lambda (y_1^2 + y_2^2) \leq \lambda \sqrt{(y_1^2 + y_2^2)(y_1^2 + y_2^2)}$$
$$\lambda (y_1^2 + y_2^2) = \lambda \sqrt{(y_1^2 + y_2^2)^2}$$

If $y_1 = y_2 = 0$ then equality still holds:
$$x_1 0 + x_2 0 \leq \sqrt{x_1^2 + x_2^2}\sqrt{0^2 + 0^2}$$
$$0 = \sqrt{x_1^2 + x_2^2} \sqrt{0}$$

Now if neither $\exists \lambda$, such that $x_1 = \lambda y_1, x_2 = \lambda y_2$ nor $y_1 = 0, y_2 = 0$ then
$$0 < (\lambda y_1 - x_1)^2 + (\lambda y_2 - x_2)^2 = \lambda^2(y_1^2 + y_2^2) - 2\lambda(x_1y_1 + x_2y_2) + (x_1^2 + x_2^2)$$
which is a quadratic equation of variable $\lambda$,\\
thus because $\lambda^2(y_1^2 + y_2^2) - 2\lambda(x_1y_1 + x_2y_2) + (x_1^2 + x_2^2) \ne 0, \forall \lambda \in \mathbb{R}$,\\
we can say that $b^2 - 4ac < 0$, i.e the discriminant is negative, substituting:
$$a = (y_1^2 + y_2^2), b = 2(x_1y_1 + x_2y_2), c = (x_1^2 + x_2^2)$$
$$[2(x_1y_1 + x_2y_2)]^2 - 4(y_1^2 + y_2^2)(x_1^2 + x_2^2) < 0$$
$$(x_1y_1 + x_2y_2)^2 - (y_1^2 + y_2^2)(x_1^2 + x_2^2) < 0$$
$$(x_1y_1 + x_2y_2)^2 < (y_1^2 + y_2^2)(x_1^2 + x_2^2)$$
$$x_1y_1 + x_2y_2 < \sqrt{(y_1^2 + y_2^2)(x_1^2 + x_2^2)}$$
which is Shwartz inequality

\hrulefill

18.3 \underline{Proof 3} Let's start with the following inequality:
$$0 \leq (x - y)^2 = x^2 - 2xy + y^2$$
$$2xy \leq x^2 + y^2$$
now let's consider following numbers $x$ and $y$
$$x = \frac{x_i}{\sqrt{x_1^2 + x_2^2}}, y = \frac{y_i}{\sqrt{y_1^2 + y_2^2}}, i = 1, 2$$
let's substitute them into $2xy \leq x^2 + y^2$
$$2\frac{x_1}{\sqrt{x_1^2 + x_2^2}} \frac{y_1}{\sqrt{y_1^2 + y_2^2}} \leq \left(\frac{x_1}{\sqrt{x_1^2 + x_2^2}}\right)^2 + \left(\frac{y_1}{\sqrt{y_1^2 + y_2^2}}\right)^2$$
$$2\frac{x_2}{\sqrt{x_1^2 + x_2^2}} \frac{y_2}{\sqrt{y_1^2 + y_2^2}} \leq \left(\frac{x_2}{\sqrt{x_1^2 + x_2^2}}\right)^2 + \left(\frac{y_2}{\sqrt{y_1^2 + y_2^2}}\right)^2$$
adding those inequalities together we have
$$\frac{2x_1y_1 + 2x_2y_2}{\sqrt{x_1^2 + x_2^2}\sqrt{y_1^2 + y_2^2}} \leq \left(\frac{x_1^2 + x_2^2}{(\sqrt{x_1^2 + x_2^2})^2}\right) + \left(\frac{y_1^2 + y_2^2}{(\sqrt{y_1^2 + y_2^2})^2}\right)$$
$$\frac{2(x_1y_1 + x_2y_2)}{\sqrt{x_1^2 + x_2^2}\sqrt{y_1^2 + y_2^2}} \leq 1 + 1$$
$$\frac{(x_1y_1 + x_2y_2)}{\sqrt{x_1^2 + x_2^2}\sqrt{y_1^2 + y_2^2}} \leq 1$$
and because $\sqrt{x_1^2 + x_2^2}\sqrt{y_1^2 + y_2^2} > 0$, we can multiply both sides by it
$$x_1y_1 + x_2y_2 \leq \sqrt{x_1^2 + x_2^2}\sqrt{y_1^2 + y_2^2}$$

\end{document}


\section{Termination Analysis}\label{sec:termination}
\subsection{Theory}

We refer again to \undeclang
and extend it with stratified types.
%
We can prove correctness of type-checking, in that
typing judgements respect denotational typing:
%
\begin{theorem}[Denotation Typing]\label{thm:typing}
If $\hastype{}{e}{\tau}$ then $e \in \interp{\tau}$
\end{theorem}
%
Stratification of types preserves Theorem \ref{thm:typing},
as all primitives in \undeclang preserves the stratum,
\ie there is no way to construct a diverging computation.
%
Moreover the above theorem implies that
expressions with finite (resp. WHNF) types
are indeed finite (resp. reduce to WHNF).

\mypara{Recursive Functions}
We use the \efix{} operator to allow recursive definitions,
%
$$\ceval{\efix{\tau}}{f} \doteq f\ (\efix{\tau}\ f) $$
%
Systems without stratified types, like \hlang,
type \efix{\tau} as
$\constty{\efix{\tau}}\doteq{\fixtype{\tau}}$,
and can prove~\citep{PLC} that it belongs
into the interpretation of its type:
$\efix{\tau} \in \interp{\fixtype{\tau}}$.

In our system, the usual type for \efix{\tau}
cannot be proven correct,
as the result expression of a \efix{\tau}
application may diverge.
%
For example, the diverging computation
$\efix{{(\tfunbasic{\tint^\ltrivial}{\tint^\ltrivial})}}\
	(\efun{f}{}{\efun{x}{}{f\ x}})\  4$
would type as $\tint^\ltrivial$
which is unsound.
%
Taking account of such cases we constraint
the type parameter $\tau$ to return a unlabelled type,
\ie the result of a \efix{\tau} application \textit{may}
diverge:
%
$$\constty{\efix{\tau}} \doteq {\fixtype{\tau}},
	\text{if the result of}\ \tau\ \text{is Div type}$$
%
and prove that this type of \efix{\tau}
is sound, or $\efix{\tau} \in \interp{\constty{\efix{\tau}}}$.

\mypara{Finite Recursive Functions}
%
Not all recursive functions diverge
and we would like to allow provably terminating
recursive functions return finite types.
%
Consider the fibonnaci function:
$$
\efib \doteq
\efun{n}{}{\efun{f}{}{
	\ecaseinstance{\_}{n}{
		 \begin{array}{l}
			 \ealt{0}{1}\\
			 \ealt{\_}{f \ (n-1) + f\ (n-2)}
		\end{array}
	}
}}$$
We know that the recursive function $f$
is called with arguments less that the actual parameter $n$.
We encode this information to \efib 's type:
\begin{align*}
\tnat &\doteq \tref{v}{\tint}{}{0 \leq v}\\
\efib &\colon\colon n\colon\tnat^\lfinite
	\rightarrow
		\tfunbasic{(\tfunbasic{\tref{n'}{\tnat}{\lfinite}{v < n}}{\tint^\lfinite})}
			{\tint^\lfinite}
\end{align*}
%
Note that in order to express the fact $f$ accepts arguments less that
$n$ we need an order of arguments, so that $n$ is in scope on $f$'s type.
%
This modification precludes the natural fixpoint definition,
instead we use \etfix{\tau} and some intermediate constants
that behave as follows:
%
\begin{align*}
\etfix{\tau}\ \efib\ n
& \hookrightarrow
	\etfixf{\tau}{\efib}{??}\ n \\
& \hookrightarrow
    \efib\ n\ (\etfixn{\tau}{\efib}{n}\ \efib) \\
& \hookrightarrow
    (\etfixn{\tau}{f}{n}\ \efib \ (n-1))  + \dots \\
%    + (\etfixn{\tau}{f}{n}\ \efib \ (n-2)) \\
& \hookrightarrow
    (\etfixfn{\tau}{\efib}{n}\ (n-1)) + \dots \\
%    + (\etfixfn{\tau}{\efib}{n} \ (n-2)) \\
& \hookrightarrow
    (\efib\ (n-1)\ (\etfixn{\tau}{\efib}{n-1}\ \efib))
    +\dots \\
%     (\etfixfn{\tau}{\efib}{n} \ (n-2)) \\
& \hookrightarrow \dots
\end{align*}
%
Intuitively,
the parameter $n$
means that $\mathtt{fix}^n$ can call itself
at most $n$ times,
while $f$ tracks the function that should
be called when applied the function's
first argument $n$.
%
Formally,  we define the following families of constants:
\begin{align*}
\ceval{\etfix{\tau}}{f} & \doteq \etfixf{\tau}{f}{??}\\
\ceval{\etfixf{\tau}{f}{??}}{n} &\doteq
f\ n\ (\etfixn{\tau}{f}{n}\ f) \\
\ceval{\etfixn{\tau}{f}{n}}{f} & \doteq
    \etfixfn{\tau}{f}{n}\\
\ceval{\etfixfn{\tau}{f}{n}}{m} &\doteq
f\ m\ (\etfixn{\tau}{f}{m}\ f) \\
\end{align*}
%
We define the appropriate types for the above constants
%
\begin{align*}
\decr{\tau}{n} & \doteq \decrtypefull{\tau}{n}\\
\constty{\etfix{\tau}} &\doteq (\decrty{\tau})\\
	& \rightarrow
	\tfun{m}{\tnat^\lfinite}{\tau\sub{x}{m}}\\
\constty{\etfixf{\tau}{f}{n}} &\doteq
	 \etfixfty{\tau}{f}{n}\\
\constty{\etfixn{\tau}{f}{n}} &\doteq
	(\decrty{\tau})\\&
	\rightarrow\adecrty{\tau}{n}\\
\constty{\etfixfn{\tau}{f}{n}} &\doteq
	 \etfixfty{\tau}{f}{n}\\
\end{align*}
and prove that the constants belong to the
meanings of their types:
%
\begin{theorem}\textbf{Fixpoint.}\label{thm:fixpoint}
\begin{itemize}
\item$\forall n. \etfixn{\tau}{f}{n} \in \constty{\etfixn{\tau}{f}{n}}$
\item$\etfix{\tau} \in \constty{\etfix{\tau}}$
\end{itemize}
\end{theorem}
\begin{proof}
\begin{itemize}
\item 1.
We prove that for all
%$f \in \interp{\decrty{\tau}}$
appropriate $f$
and $ m \in \interp{\tref{v}{\tnat}{\lfinite}{v < n}}$,
$e \equiv \etfixn{\tau}{f}{n}\ f \ m \in \interp{\tau\sub{x}{m}}$
%
by induction on $n$.

For $n=0$,
it is trivial, as
there is no $m$ such that
$m \in \interp{\tref{v}{\tnat}{\lfinite}{v < 0}}$.

For the inductive step, $e$ reduces to
$$
\etfixn{\tau}{f}{n}\ f\ m
\hookrightarrow
\etfixfn{\tau}{f}{n}\ m
\hookrightarrow
f\ m\ (\etfixn{\tau}{f}{m}\ f)\\
$$
By IH, since $m < n$,
$\etfixn{\tau}{f}{m} \in \constty{\etfixn{\tau}{f}{m}}$,
so $f$ receives the appropriate arguments,
and returns the appropriate result that proves the theorem.
%
\item 2.
We prove that
for all appropriate $f$
% \\$f \in \interp{\decrty{\tau}}$
and     $ m \in \interp{\tnat^\lfinite}$,
$\etfix{\tau}\ f \ m \in \interp{\tau\sub{x}{m}}$.
%
Since $m \in \interp{\tref{v}{\tnat}{\lfinite}{v < m+1}}$
$$\etfixn{\tau}{f}{m+1}\ f \ m \in \interp{\tau\sub{x}{m}}$$
%
But operationally,
$\etfixn{\tau}{f}{m+1}\ f \ m$
and
$\etfix{\tau}\ f \ m$
behave equivalently, which proves the theorem.
\end{itemize}
\end{proof}
%
Note that we used a similar proof for
$\efix{\tau} \in \constty{\efix{\tau}}$.
%
The only difference is that for the base case
\efixn{\tau}{0} should be defined to belong
into the interpretation of any type.
%
Thus, it is defined as a diverging expression.
%
With refinement types we prove that the basic
\etfixn{\tau}{f}{0} operator
cannot be called, so we omit
the definition of this basic case.

\mypara{Downgrade Labels}
%
With \etfix{\tau} we can construct recursive expressions
and prove them terminating.
%
But how do we prove that an expression is in WHNF?
%
Every terminating expression is in WHNF,
thus, we define \edown{l_1}{l_2}, an id function that
\textbf{downgrades} the stratum of from $l_1$ to $l_2$:
%
\begin{align*}
\ceval{\edown{l_1}{l_2}}{e} &\doteq e\\
\constty{\edown{l_1}{l_2}} & \equiv
\tfunbasic{\tref{v}{b}{l_1}{p}}{\tref{v}{b}{l_2}{p}}
\end{align*}
We can show that $\edown{\lfinite}{\ltrivial}
\in \interp{\constty{\edown{\lfinite}{\ltrivial}}}$
and use this constant in \undeclang to downgrade stata.


% !TeX spellcheck = en_US
% !TeX root = DynELA.tex
%
% LaTeX source file of DynELA FEM Code
%
% (c) by Olivier Pantalé 2020
%
\chapter{DynELA plasticity sample cases}

\startcontents[chapters]
\printmyminitoc[1]\LETTRINE{T}his chapter deals with some numerical applications of
the \DynELA~for plasticity applications in 2D, axi-symmetric and
3D cases. In the subsequent tests, if not specified, a Johnson-Cook
constitutive law is used to model the behavior of the material. The
Johnson-Cook hardening flow law is probably the most widely used flow
law for the simulation of high strain rate deformation processes taking
into account plastic strain, plastic strain rate and temperature effects.
Since a lot of efforts have been made in the past to identify the
constitutive flow law parameters for many materials, it is implemented
in numerous Finite Element codes such as Abaqus \cite{abaqus20146}.
The general formulation of the Johnson-Cook law $\sigma^{y}(\overline{\varepsilon}^{p},\stackrel{\bullet}{\overline{\varepsilon}^{p}},T)$
is given by the following equation:

\begin{equation}
\sigma^{y}=\left(A+B\overline{\varepsilon}^{p^{n}}\right)\left[1+C\ln\left(\frac{\stackrel{\bullet}{\overline{\varepsilon}^{p}}}{\stackrel{\bullet}{\overline{\varepsilon}_{0}}}\right)\right]\left[1-\left(\frac{T-T_{0}}{T_{m}-T_{0}}\right)^{m}\right]\label{eq:Samples!Johnson-Cook}
\end{equation}
where $\stackrel{\bullet}{\overline{\varepsilon}_{0}}$ is the reference
strain rate, $T_{0}$ and $T_{m}$ are the reference temperature and
the melting temperature of the material respectively and $A$, $B$,
$C$, $n$ and $m$ are the five constitutive flow law parameters.
A 42CrMo4 steel following the Johnson-Cook behavior law has been selected
for all those tests, and material properties are reported in Table
\ref{tab:Samples!JohnsonCookParameters}.

\begin{table}[h]
\begin{center}\begin{tcolorbox}[width=.75\textwidth,myTab,tabularx={C|C|C|C|C|C|C}]
$E$ & $\nu$ & $A$ & $B$ & $C$ & $n$ & $m$ \\
\small{($Gpa$)} &  & \small{($MPa$)} & \small{($MPa$)} &  &  & \\ \hline
$206.9$ & $0.3$ & $806$ & $614$ & $0.0089$ & $0.168$ & $1.1$ \\ \hline\hline
$\rho$ & $\lambda$ & $C_{p}$ & $\eta$ & $\stackrel{\bullet}{\overline{\varepsilon}_{0}}$ & $T_{0}$ & $T_{m}$ \\
\small{$(kg/m^{3})$} & \small{$(W/m^{\circ}C)$} & \small{$(J/Kg^{\circ}C)$} & & \small{$(s^{-1})$} & \small{$(^{\circ}C)$} & \small{$(^{\circ}C)$} \\ \hline
$7830$ & $34.0$ & $460$ & $0.9$ & $1.0$ & $20$ & $1540$
\end{tcolorbox}\end{center}\caption{Material parameters of the Johnson-Cook behavior for the numerical
tests\label{tab:Samples!JohnsonCookParameters}}
\end{table}

\section{Necking of a circular bar}

\subsection{Axisymmetric Bar Necking}

The necking of a circular bar test is useful to evaluate the performance
of VUMAT subroutine for materials in presence of plasticity and large
deformation \cite{ponthot_unified_2002, j_c_simo_computational_1998}. Because of the symmetric
structure, an axisymmetric quarter model of the specimen is established.
Dimensions of the specimen are reported in Figure \ref{fig:Samples!Plasticity!NeckingAxi}.
The loading is realized through an imposed total displacement of $7\,mm$
along the $\overrightarrow{z}$ axis on the left side of the specimen
while the radial displacement of the same edge is supposed to remain
zero. On the opposite side the axial displacement is restrained while
the radial displacement is free. The mesh consists of $400$ CAX4RT
elements with a refined zone of $200$ elements on the right side
on $1/3$ of the total height. Again, the total simulation time is
set to $t=0.01\,s$ because of the explicit integration scheme adopted.

\begin{figure}[h]
\begin{centering}
\includegraphics[width=0.75\columnwidth]{Figures/BarNecking}
\par\end{centering}
\caption{Numerical model for the necking of a circular bar\label{fig:Samples!Plasticity!NeckingAxi}}
\end{figure}

Figures \ref{fig:Samples!Plasticity!BarAxi-temp-contour} and \ref{fig:Samples!Plasticity!BarAxi-mises-contour}
shows the temperature $T$ and the von Mises stress $\overline{\sigma}$
contourplots of the deformed rod for both the \DynELA~and Abaqus.
The distributions of the temperatures and stresses are almost the
same for both models. The maximum temperature $T$ is located into
the center element of the model (the red element in Figure \ref{fig:Samples!Plasticity!NeckingAxi})
and the models give quite the same results as reported in Table \ref{tab:Samples!Plasticity!BarAxi-comparison}
for $\overline{\varepsilon}^{p}$, $T$ and the final dimensions of
the specimen $D_{f}$ (final diameter of the necking zone).

Figure \ref{fig:Samples!Plasticity!BarAxi-comparison} shows the evolution
of the the final dimensions of the specimen $L_{f}$ (final length)
and $R_{f}$ (final radius of the impacting face), the equivalent
plastic strain $\overline{\varepsilon}^{p}$, the temperature $T$,
the von Mises stress $\overline{\sigma}$ and the timeStep $\Delta t$
for the different models for the element at the center of the impacting
face (the red element in Figure \ref{fig:Samples!Plasticity!NeckingAxi}).

As reported in this figure and according to the results presented
in Table \ref{tab:Samples!Plasticity!BarAxi-comparison}, a quite
good agreement between the results is obtained.

\begin{figure}[h]
\begin{centering}
\includegraphics[height=0.5\columnwidth]{Figures/Samples/Plasticity/BarNecking_temperatureCP}\hspace*{3cm}\includegraphics[height=0.5\columnwidth]{Figures/Samples/Plasticity/BarNecking-Abaqus_temperature}
\par\end{centering}
\caption{Temperature $T$ contourplot for the necking of a circular bar (DynELA
left and Abaqus right)\label{fig:Samples!Plasticity!BarAxi-temp-contour}}
\end{figure}

\begin{figure}[h]
\begin{centering}
\includegraphics[height=0.5\columnwidth]{Figures/Samples/Plasticity/BarNecking_vonMisesCP}\hspace*{3cm}\includegraphics[height=0.5\columnwidth]{Figures/Samples/Plasticity/BarNecking-Abaqus_vonMises}
\par\end{centering}
\caption{von Mises stress $\overline{\sigma}$ contourplot for the necking
of a circular bar (DynELA left and Abaqus right)\label{fig:Samples!Plasticity!BarAxi-mises-contour}}
\end{figure}

\begin{table}[h]
\begin{center}\begin{tcolorbox}[width=.75\textwidth,myTab,tabularx={C|C|C|C}]
code & $D_f$ & $T$ & $\overline{\varepsilon}^{p}$ \\
 & \small{($mm$)} & \small{($^{\circ}C$)} & \\ \hline\hline
DynELA & $2.71$ & $642.78$ & $2.07$ \\ \hline
Abaqus & $2.35$ & $658.91$ & $2.12$
\end{tcolorbox}\end{center}\caption{Comparison of numerical results for the necking of a circular bar
test\label{tab:Samples!Plasticity!BarAxi-comparison}}
\end{table}

\begin{figure}[h]
\begin{centering}
\begin{tabular}{cc}
\includegraphics[width=0.45\columnwidth]{Figures/Samples/Plasticity/BarNecking_radius} & \includegraphics[width=0.45\columnwidth]{Figures/Samples/Plasticity/BarNecking_kineticEnergy}\tabularnewline
\includegraphics[width=0.45\columnwidth]{Figures/Samples/Plasticity/BarNecking_temperature} & \includegraphics[width=0.45\columnwidth]{Figures/Samples/Plasticity/BarNecking_plasticStrain}\tabularnewline
\includegraphics[width=0.45\columnwidth]{Figures/Samples/Plasticity/BarNecking_vonMises} & \includegraphics[width=0.45\columnwidth]{Figures/Samples/Plasticity/BarNecking_timeStep}\tabularnewline
\end{tabular}
\par\end{centering}
\caption{Comparison of numerical and analytical results necking of a circular
bar test\label{fig:Samples!Plasticity!BarAxi-comparison}}
\end{figure}


\subsection{Univariate Statistics}

\noindent{\bf Description}
\smallskip

\emph{Univariate statistics} are the simplest form of descriptive statistics in data
analysis.  They are used to quantitatively describe the main characteristics of each
feature in the data.  For a given dataset matrix, script \UnivarScriptName{} computes
certain univariate statistics for each feature column in the
matrix.  The feature type governs the exact set of statistics computed for that feature.
For example, the statistic \emph{mean} can only be computed on a quantitative (scale)
feature like `Height' and `Temperature'.  It does not make sense to compute the mean
of a categorical attribute like `Hair Color'.

\smallskip
\noindent{\bf Usage}
\smallskip

{\hangindent=\parindent\noindent\it%\tolerance=0
{\tt{}-f } \UnivarScriptName{}
{\tt{} -nvargs}
{\tt{} X=}path/file
{\tt{} TYPES=}path/file
{\tt{} STATS=}path/file
% {\tt{} fmt=}format

}

\medskip
\pagebreak[2]
\noindent{\bf Arguments}
\begin{Description}
\item[{\tt X}:]
Location (on HDFS) to read the data matrix $X$ whose columns we want to
analyze as the features.
\item[{\tt TYPES}:] % (default:\mbox{ }{\tt " "})
Location (on HDFS) to read the single-row matrix whose $i^{\textrm{th}}$
column-cell contains the type of the $i^{\textrm{th}}$ feature column
\texttt{X[,$\,i$]} in the data matrix.  Feature types must be encoded by
integer numbers: $1 = {}$scale, $2 = {}$nominal, $3 = {}$ordinal.
% The default value means ``treat all $X$-columns as scale.''
\item[{\tt STATS}:]
Location (on HDFS) where the output matrix of computed statistics
will be stored.  The format of the output matrix is defined by
Table~\ref{table:univars}.
% \item[{\tt fmt}:] (default:\mbox{ }{\tt "text"})
% Matrix file output format, such as {\tt text}, {\tt mm}, or {\tt csv};
% see read/write functions in SystemML Language Reference for details.
\end{Description}

\begin{table}[t]\hfil
\begin{tabular}{|rl|c|c|}
\hline
\multirow{2}{*}{Row}& \multirow{2}{*}{Name of Statistic} & \multicolumn{2}{c|}{Applies to:} \\
                            &                            & Scale & Categ.\\
\hline
\OutputRowIDMinimum         & Minimum                    &   +   &       \\
\OutputRowIDMaximum         & Maximum                    &   +   &       \\
\OutputRowIDRange           & Range                      &   +   &       \\
\OutputRowIDMean            & Mean                       &   +   &       \\
\OutputRowIDVariance        & Variance                   &   +   &       \\
\OutputRowIDStDeviation     & Standard deviation         &   +   &       \\
\OutputRowIDStErrorMean     & Standard error of mean     &   +   &       \\
\OutputRowIDCoeffVar        & Coefficient of variation   &   +   &       \\
\OutputRowIDSkewness        & Skewness                   &   +   &       \\
\OutputRowIDKurtosis        & Kurtosis                   &   +   &       \\
\OutputRowIDStErrorSkewness & Standard error of skewness &   +   &       \\
\OutputRowIDStErrorCurtosis & Standard error of kurtosis &   +   &       \\
\OutputRowIDMedian          & Median                     &   +   &       \\
\OutputRowIDIQMean          & Inter quartile mean        &   +   &       \\
\OutputRowIDNumCategories   & Number of categories       &       &   +   \\
\OutputRowIDMode            & Mode                       &       &   +   \\
\OutputRowIDNumModes        & Number of modes            &       &   +   \\
\hline
\end{tabular}\hfil
\caption{The output matrix of \UnivarScriptName{} has one row per each
univariate statistic and one column per input feature.  This table lists
the meaning of each row.  Signs ``+'' show applicability to scale or/and
to categorical features.}
\label{table:univars}
\end{table}

\pagebreak[1]

\smallskip
\noindent{\bf Details}
\smallskip

Given an input matrix \texttt{X}, this script computes the set of all
relevant univariate statistics for each feature column \texttt{X[,$\,i$]}
in~\texttt{X}.  The list of statistics to be computed depends on the
\emph{type}, or \emph{measurement level}, of each column.
The \textrm{TYPES} command-line argument points to a vector containing
the types of all columns.  The types must be provided as per the following
convention: $1 = {}$scale, $2 = {}$nominal, $3 = {}$ordinal.

Below we list all univariate statistics computed by script \UnivarScriptName.
The statistics are collected by relevance into several groups, namely: central
tendency, dispersion, shape, and categorical measures.  The first three groups
contain statistics computed for a quantitative (also known as: numerical, scale,
or continuous) feature; the last group contains the statistics for a categorical
(either nominal or ordinal) feature.

Let~$n$ be the number of data records (rows) with feature values.
In what follows we fix a column index \texttt{idx} and consider
sample statistics of feature column \texttt{X[}$\,$\texttt{,}$\,$\texttt{idx]}.
Let $v = (v_1, v_2, \ldots, v_n)$ be the values of \texttt{X[}$\,$\texttt{,}$\,$\texttt{idx]}
in their original unsorted order: $v_i = \texttt{X[}i\texttt{,}\,\texttt{idx]}$.
Let $v^s = (v^s_1, v^s_2, \ldots, v^s_n)$ be the same values in the sorted order,
preserving duplicates: $v^s_1 \leq v^s_2 \leq \ldots \leq v^s_n$.

\paragraph{Central tendency measures.}
Sample statistics that describe the location of the quantitative (scale) feature distribution,
represent it with a single value.
\begin{Description}
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Mean]
\OutputRowText{\OutputRowIDMean}
The arithmetic average over a sample of a quantitative feature.
Computed as the ratio between the sum of values and the number of values:
$\left(\sum_{i=1}^n v_i\right)\!/n$.
Example: the mean of sample $\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$
equals~5.2.

Note that the mean is significantly affected by extreme values in the sample
and may be misleading as a central tendency measure if the feature varies on
exponential scale.  For example, the mean of $\{$0.01, 0.1, 1.0, 10.0, 100.0$\}$
is 22.222, greater than all the sample values except the~largest.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{figure}[t]
\setlength{\unitlength}{10pt}
\begin{picture}(33,12)
\put( 6.2, 0.0){\small 2.2}
\put(10.2, 0.0){\small 3.2}
\put(12.2, 0.0){\small 3.7}
\put(15.0, 0.0){\small 4.4}
\put(18.6, 0.0){\small 5.3}
\put(20.2, 0.0){\small 5.7}
\put(21.75,0.0){\small 6.1}
\put(23.05,0.0){\small 6.4}
\put(26.2, 0.0){\small 7.2}
\put(28.6, 0.0){\small 7.8}
\put( 0.5, 0.7){\small 0.0}
\put( 0.1, 3.2){\small 0.25}
\put( 0.5, 5.7){\small 0.5}
\put( 0.1, 8.2){\small 0.75}
\put( 0.5,10.7){\small 1.0}
\linethickness{1.5pt}
\put( 2.0, 1.0){\line(1,0){4.8}}
\put( 6.8, 1.0){\line(0,1){1.0}}
\put( 6.8, 2.0){\line(1,0){4.0}}
\put(10.8, 2.0){\line(0,1){1.0}}
\put(10.8, 3.0){\line(1,0){2.0}}
\put(12.8, 3.0){\line(0,1){1.0}}
\put(12.8, 4.0){\line(1,0){2.8}}
\put(15.6, 4.0){\line(0,1){1.0}}
\put(15.6, 5.0){\line(1,0){3.6}}
\put(19.2, 5.0){\line(0,1){1.0}}
\put(19.2, 6.0){\line(1,0){1.6}}
\put(20.8, 6.0){\line(0,1){1.0}}
\put(20.8, 7.0){\line(1,0){1.6}}
\put(22.4, 7.0){\line(0,1){1.0}}
\put(22.4, 8.0){\line(1,0){1.2}}
\put(23.6, 8.0){\line(0,1){1.0}}
\put(23.6, 9.0){\line(1,0){3.2}}
\put(26.8, 9.0){\line(0,1){1.0}}
\put(26.8,10.0){\line(1,0){2.4}}
\put(29.2,10.0){\line(0,1){1.0}}
\put(29.2,11.0){\line(1,0){4.8}}
\linethickness{0.3pt}
\put( 6.8, 1.0){\circle*{0.3}}
\put(10.8, 1.0){\circle*{0.3}}
\put(12.8, 1.0){\circle*{0.3}}
\put(15.6, 1.0){\circle*{0.3}}
\put(19.2, 1.0){\circle*{0.3}}
\put(20.8, 1.0){\circle*{0.3}}
\put(22.4, 1.0){\circle*{0.3}}
\put(23.6, 1.0){\circle*{0.3}}
\put(26.8, 1.0){\circle*{0.3}}
\put(29.2, 1.0){\circle*{0.3}}
\put( 6.8, 1.0){\vector(1,0){27.2}}
\put( 2.0, 1.0){\vector(0,1){10.8}}
\put( 2.0, 3.5){\line(1,0){10.8}}
\put( 2.0, 6.0){\line(1,0){17.2}}
\put( 2.0, 8.5){\line(1,0){21.6}}
\put( 2.0,11.0){\line(1,0){27.2}}
\put(12.8, 1.0){\line(0,1){2.0}}
\put(19.2, 1.0){\line(0,1){5.0}}
\put(20.0, 1.0){\line(0,1){5.0}}
\put(23.6, 1.0){\line(0,1){7.0}}
\put( 9.0, 4.0){\line(1,0){3.8}}
\put( 9.2, 2.7){\vector(0,1){0.8}}
\put( 9.2, 4.8){\vector(0,-1){0.8}}
\put(19.4, 8.0){\line(1,0){3.0}}
\put(19.6, 7.2){\vector(0,1){0.8}}
\put(19.6, 9.3){\vector(0,-1){0.8}}
\put(13.0, 2.2){\small $q_{25\%}$}
\put(17.3, 2.2){\small $q_{50\%}$}
\put(23.8, 2.2){\small $q_{75\%}$}
\put(20.15,3.5){\small $\mu$}
\put( 8.0, 3.75){\small $\phi_1$}
\put(18.35,7.8){\small $\phi_2$}
\end{picture}
\label{fig:example_quartiles}
\caption{The computation of quartiles, median, and interquartile mean from the
empirical distribution function of the 10-point
sample $\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$.  Each vertical step in
the graph has height~$1{/}n = 0.1$.  Values $q_{25\%}$, $q_{50\%}$, and $q_{75\%}$ denote
the $1^{\textrm{st}}$, $2^{\textrm{nd}}$, and $3^{\textrm{rd}}$ quartiles correspondingly;
value~$\mu$ denotes the median.  Values $\phi_1$ and $\phi_2$ show the partial contribution
of border points (quartiles) $v_3=3.7$ and $v_8=6.4$ into the interquartile mean.}
\end{figure}

%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Median]
\OutputRowText{\OutputRowIDMedian}
The ``middle'' value that separates the higher half of the sample values
(in a sorted order) from the lower half.
To compute the median, we sort the sample in the increasing order, preserving
duplicates: $v^s_1 \leq v^s_2 \leq \ldots \leq v^s_n$.
If $n$ is odd, the median equals $v^s_i$ where $i = (n\,{+}\,1)\,{/}\,2$,
same as the $50^{\textrm{th}}$~percentile of the sample.
If $n$ is even, there are two ``middle'' values $v^s_{n/2}$ and $v^s_{n/2\,+\,1}$,
so we compute the median as the mean of these two values.
(For even~$n$ we compute the $50^{\textrm{th}}$~percentile as~$v^s_{n/2}$,
not as the median.)  Example: the median of sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$
equals $(5.3\,{+}\,5.7)\,{/}\,2$~${=}$~5.5, see Figure~\ref{fig:example_quartiles}.

Unlike the mean, the median is not sensitive to extreme values in the sample,
i.e.\ it is robust to outliers.  It works better as a measure of central tendency
for heavy-tailed distributions and features that vary on exponential scale.
However, the median is sensitive to small sample size.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Interquartile mean]
\OutputRowText{\OutputRowIDIQMean}
For a sample of a quantitative feature, this is
the mean of the values greater than or equal to the $1^{\textrm{st}}$ quartile
and less than or equal the $3^{\textrm{rd}}$ quartile.
In other words, it is a ``truncated mean'' where the lowest 25$\%$ and
the highest 25$\%$ of the sorted values are omitted in its computation.
The two ``border values'', i.e.\ the $1^{\textrm{st}}$ and the $3^{\textrm{rd}}$
quartiles themselves, contribute to this mean only partially.
This measure is occasionally used as the ``robust'' version of the mean
that is less sensitive to the extreme values.

To compute the measure, we sort the sample in the increasing order,
preserving duplicates: $v^s_1 \leq v^s_2 \leq \ldots \leq v^s_n$.
We set $j = \lceil n{/}4 \rceil$ for the $1^{\textrm{st}}$ quartile index
and $k = \lceil 3n{/}4 \rceil$ for the $3^{\textrm{rd}}$ quartile index,
then compute the following weighted mean:
\begin{equation*}
\frac{1}{3{/}4 - 1{/}4} \left[
\left(\frac{j}{n} - \frac{1}{4}\right) v^s_j \,\,+
\sum_{j<i<k} \left(\frac{i}{n} - \frac{i\,{-}\,1}{n}\right) v^s_i
\,\,+\,\, \left(\frac{3}{4} - \frac{k\,{-}\,1}{n}\right) v^s_k\right]
\end{equation*}
In other words, all sample values between the $1^{\textrm{st}}$ and the $3^{\textrm{rd}}$
quartile enter the sum with weights $2{/}n$, times their number of duplicates, while the
two quartiles themselves enter the sum with reduced weights.  The weights are proportional
to the vertical steps in the empirical distribution function of the sample, see
Figure~\ref{fig:example_quartiles} for an illustration.
Example: the interquartile mean of sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$ equals the sum
$0.1 (3.7\,{+}\,6.4) + 0.2 (4.4\,{+}\,5.3\,{+}\,5.7\,{+}\,6.1)$,
which equals~5.31.
\end{Description}

\paragraph{Dispersion measures.}
Statistics that describe the amount of variation or spread in a quantitative
(scale) data feature.
\begin{Description}
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Variance]
\OutputRowText{\OutputRowIDVariance}
A measure of dispersion, or spread-out, of sample values around their mean,
expressed in units that are the square of those of the feature itself.
Computed as the sum of squared differences between the values
in the sample and their mean, divided by one less than the number of
values: $\sum_{i=1}^n (v_i - \bar{v})^2\,/\,(n\,{-}\,1)$ where
$\bar{v}=\left(\sum_{i=1}^n v_i\right)\!/n$.
Example: the variance of sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$ equals~3.24.
Note that at least two values ($n\geq 2$) are required to avoid division
by zero.  Sample variance is sensitive to outliers, even more than the mean.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Standard deviation]
\OutputRowText{\OutputRowIDStDeviation}
A measure of dispersion around the mean, the square root of variance.
Computed by taking the square root of the sample variance;
see \emph{Variance} above on computing the variance.
Example: the standard deviation of sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$ equals~1.8.
At least two values are required to avoid division by zero.
Note that standard deviation is sensitive to outliers.

Standard deviation is used in conjunction with the mean to determine
an interval containing a given percentage of the feature values,
assuming the normal distribution.  In a large sample from a normal
distribution, around 68\% of the cases fall within one standard
deviation and around 95\% of cases fall within two standard deviations
of the mean.  For example, if the mean age is 45 with a standard deviation
of 10, around 95\% of the cases would be between 25 and 65 in a normal
distribution.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Coefficient of variation]
\OutputRowText{\OutputRowIDCoeffVar}
The ratio of the standard deviation to the mean, i.e.\ the
\emph{relative} standard deviation, of a quantitative feature sample.
Computed by dividing the sample \emph{standard deviation} by the
sample \emph{mean}, see above for their computation details.
Example: the coefficient of variation for sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$
equals 1.8$\,{/}\,$5.2~${\approx}$~0.346.

This metric is used primarily with non-negative features such as
financial or population data.  It is sensitive to outliers.
Note: zero mean causes division by zero, returning infinity or \texttt{NaN}.
At least two values (records) are required to compute the standard deviation.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Minimum]
\OutputRowText{\OutputRowIDMinimum}
The smallest value of a quantitative sample, computed as $\min v = v^s_1$.
Example: the minimum of sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$
equals~2.2.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Maximum]
\OutputRowText{\OutputRowIDMaximum}
The largest value of a quantitative sample, computed as $\max v = v^s_n$.
Example: the maximum of sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$
equals~7.8.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Range]
\OutputRowText{\OutputRowIDRange}
The difference between the largest and the smallest value of a quantitative
sample, computed as $\max v - \min v = v^s_n - v^s_1$.
It provides information about the overall spread of the sample values.
Example: the range of sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$
equals 7.8$\,{-}\,$2.2~${=}$~5.6.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Standard error of the mean]
\OutputRowText{\OutputRowIDStErrorMean}
A measure of how much the value of the sample mean may vary from sample
to sample taken from the same (hypothesized) distribution of the feature.
It helps to roughly bound the distribution mean, i.e.\
the limit of the sample mean as the sample size tends to infinity.
Under certain assumptions (e.g.\ normality and large sample), the difference
between the distribution mean and the sample mean is unlikely to exceed
2~standard errors.

The measure is computed by dividing the sample standard deviation
by the square root of the number of values~$n$; see \emph{standard deviation}
for its computation details.  Ensure $n\,{\geq}\,2$ to avoid division by~0.
Example: for sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$
with the mean of~5.2 the standard error of the mean
equals 1.8$\,{/}\sqrt{10}$~${\approx}$~0.569.

Note that the standard error itself is subject to sample randomness.
Its accuracy as an error estimator may be low if the sample size is small
or \mbox{non-i.i.d.}, if there are outliers, or if the distribution has
heavy tails.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
% \item[\it Quartiles]
% \OutputRowText{\OutputRowIDQuartiles}
% %%% dsDefn %%%%
% The values of a quantitative feature
% that divide an ordered/sorted set of data records into four equal-size groups.
% The $1^{\textrm{st}}$ quartile, or the $25^{\textrm{th}}$ percentile, splits
% the sorted data into the lowest $25\%$ and the highest~$75\%$.  In other words,
% it is the middle value between the minimum and the median.  The $2^{\textrm{nd}}$
% quartile is the median itself, the value that separates the higher half of
% the data (in the sorted order) from the lower half.  Finally, the $3^{\textrm{rd}}$
% quartile, or the $75^{\textrm{th}}$ percentile, divides the sorted data into
% lowest $75\%$ and highest~$25\%$.\par
% %%% dsComp %%%%
% To compute the quartiles for a data column \texttt{X[,i]} with $n$ numerical values
% we sort it in the increasing order, preserving duplicates, then return
% \texttt{X}${}^{\textrm{sort}}$\texttt{[}$k$\texttt{,i]}
% where $k = \lceil pn \rceil$ for $p = 0.25$, $0.5$, and~$0.75$.
% When $n$ is even, the $2^{\textrm{nd}}$ quartile (the median) is further adjusted
% to equal the mean of two middle values
% $\texttt{X}^{\textrm{sort}}\texttt{[}n{/}2\texttt{,i]}$ and
% $\texttt{X}^{\textrm{sort}}\texttt{[}n{/}2\,{+}\,1\texttt{,i]}$.
% %%% dsWarn %%%%
% We assume that the feature column does not contain \texttt{NaN}s or coded non-numeric values.
% %%% dsExmpl %%%
% \textbf{Example(s).}
\end{Description}

\paragraph{Shape measures.}
Statistics that describe the shape and symmetry of the quantitative (scale)
feature distribution estimated from a sample of its values.
\begin{Description}
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Skewness]
\OutputRowText{\OutputRowIDSkewness}
It measures how symmetrically the values of a feature are spread out
around the mean.  A significant positive skewness implies a longer (or fatter)
right tail, i.e. feature values tend to lie farther away from the mean on the
right side.  A significant negative skewness implies a longer (or fatter) left
tail.  The normal distribution is symmetric and has a skewness value of~0;
however, its sample skewness is likely to be nonzero, just close to zero.
As a guideline, a skewness value more than twice its standard error is taken
to indicate a departure from symmetry.

Skewness is computed as the $3^{\textrm{rd}}$~central moment divided by the cube
of the standard deviation.  We estimate the $3^{\textrm{rd}}$~central moment as
the sum of cubed differences between the values in the feature column and their
sample mean, divided by the number of values:
$\sum_{i=1}^n (v_i - \bar{v})^3 / n$
where $\bar{v}=\left(\sum_{i=1}^n v_i\right)\!/n$.
The standard deviation is computed
as described above in \emph{standard deviation}.  To avoid division by~0,
at least two different sample values are required.  Example: for sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$
with the mean of~5.2 and the standard deviation of~1.8
skewness is estimated as $-1.0728\,{/}\,1.8^3 \approx -0.184$.
Note: skewness is sensitive to outliers.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Standard error in skewness]
\OutputRowText{\OutputRowIDStErrorSkewness}
A measure of how much the sample skewness may vary from sample to sample,
assuming that the feature is normally distributed, which makes its
distribution skewness equal~0.
Given the number~$n$ of sample values, the standard error is computed as
\begin{equation*}
\sqrt{\frac{6n\,(n-1)}{(n-2)(n+1)(n+3)}}
\end{equation*}
This measure can tell us, for example:
\begin{Itemize}
\item If the sample skewness lands within two standard errors from~0, its
positive or negative sign is non-significant, may just be accidental.
\item If the sample skewness lands outside this interval, the feature
is unlikely to be normally distributed.
\end{Itemize}
At least 3~values ($n\geq 3$) are required to avoid arithmetic failure.
Note that the standard error is inaccurate if the feature distribution is
far from normal or if the number of samples is small.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Kurtosis]
\OutputRowText{\OutputRowIDKurtosis}
As a distribution parameter, kurtosis is a measure of the extent to which
feature values cluster around a central point.  In other words, it quantifies
``peakedness'' of the distribution: how tall and sharp the central peak is
relative to a standard bell curve.

Positive kurtosis (\emph{leptokurtic} distribution) indicates that, relative
to a normal distribution:
\begin{Itemize}
\item observations cluster more about the center (peak-shaped),
\item the tails are thinner at non-extreme values,
\item the tails are thicker at extreme values.
\end{Itemize}
Negative kurtosis (\emph{platykurtic} distribution) indicates that, relative
to a normal distribution:
\begin{Itemize}
\item observations cluster less about the center (box-shaped),
\item the tails are thicker at non-extreme values,
\item the tails are thinner at extreme values.
\end{Itemize}
Kurtosis of a normal distribution is zero; however, the sample kurtosis
(computed here) is likely to deviate from zero.

Sample kurtosis is computed as the $4^{\textrm{th}}$~central moment divided
by the $4^{\textrm{th}}$~power of the standard deviation, minus~3.
We estimate the $4^{\textrm{th}}$~central moment as the sum of the
$4^{\textrm{th}}$~powers of differences between the values in the feature column
and their sample mean, divided by the number of values:
$\sum_{i=1}^n (v_i - \bar{v})^4 / n$
where $\bar{v}=\left(\sum_{i=1}^n v_i\right)\!/n$.
The standard deviation is computed as described above, see \emph{standard deviation}.

Note that kurtosis is sensitive to outliers, and requires at least two different
sample values.  Example: for sample
$\{$2.2, 3.2, 3.7, 4.4, 5.3, 5.7, 6.1, 6.4, 7.2, 7.8$\}$
with the mean of~5.2 and the standard deviation of~1.8,
sample kurtosis equals $16.6962\,{/}\,1.8^4 - 3 \approx -1.41$.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Standard error in kurtosis]
\OutputRowText{\OutputRowIDStErrorCurtosis}
A measure of how much the sample kurtosis may vary from sample to sample,
assuming that the feature is normally distributed, which makes its
distribution kurtosis equal~0.
Given the number~$n$ of sample values, the standard error is computed as
\begin{equation*}
\sqrt{\frac{24n\,(n-1)^2}{(n-3)(n-2)(n+3)(n+5)}}
\end{equation*}
This measure can tell us, for example:
\begin{Itemize}
\item If the sample kurtosis lands within two standard errors from~0, its
positive or negative sign is non-significant, may just be accidental.
\item If the sample kurtosis lands outside this interval, the feature
is unlikely to be normally distributed.
\end{Itemize}
At least 4~values ($n\geq 4$) are required to avoid arithmetic failure.
Note that the standard error is inaccurate if the feature distribution is
far from normal or if the number of samples is small.
\end{Description}

\paragraph{Categorical measures.}  Statistics that describe the sample of
a categorical feature, either nominal or ordinal.  We represent all
categories by integers from~1 to the number of categories; we call
these integers \emph{category~IDs}.
\begin{Description}
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Number of categories]
\OutputRowText{\OutputRowIDNumCategories}
The maximum category~ID that occurs in the sample.  Note that some
categories with~IDs \emph{smaller} than this maximum~ID may have
no~occurrences in the sample, without reducing the number of categories.
However, any categories with~IDs \emph{larger} than the maximum~ID with
no occurrences in the sample will not be counted.
Example: in sample $\{$1, 3, 3, 3, 3, 4, 4, 5, 7, 7, 7, 7, 8, 8, 8$\}$
the number of categories is reported as~8.  Category~IDs 2 and~6, which have
zero occurrences, are still counted; but if there is a category with
ID${}=9$ and zero occurrences, it is not counted.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Mode]
\OutputRowText{\OutputRowIDMode}
The most frequently occurring category value.
If several values share the greatest frequency of occurrence, then each
of them is a mode; but here we report only the smallest of these modes.
Example: in sample $\{$1, 3, 3, 3, 3, 4, 4, 5, 7, 7, 7, 7, 8, 8, 8$\}$
the modes are 3 and~7, with 3 reported.

Computed by counting the number of occurrences for each category,
then taking the smallest category~ID that has the maximum count.
Note that the sample modes may be different from the distribution modes,
i.e.\ the categories whose (hypothesized) underlying probability is the
maximum over all categories.
%%%%%%%%%%%%%%%%%%%% DESCRIPTIVE STATISTIC %%%%%%%%%%%%%%%%%%%%
\item[\it Number of modes]
\OutputRowText{\OutputRowIDNumModes}
The number of category values that each have the largest frequency
count in the sample.
Example: in sample $\{$1, 3, 3, 3, 3, 4, 4, 5, 7, 7, 7, 7, 8, 8, 8$\}$
there are two category IDs (3 and~7) that occur the maximum count of 4~times;
hence, we return~2.

Computed by counting the number of occurrences for each category,
then counting how many categories have the maximum count.
Note that the sample modes may be different from the distribution modes,
i.e.\ the categories whose (hypothesized) underlying probability is the
maximum over all categories.
\end{Description}

\smallskip
\noindent{\bf Returns}
\smallskip

The output matrix containing all computed statistics is of size $17$~rows and
as many columns as in the input matrix~\texttt{X}.  Each row corresponds to
a particular statistic, according to the convention specified in
Table~\ref{table:univars}.  The first $14$~statistics are applicable for
\emph{scale} columns, and the last $3$~statistics are applicable for categorical,
i.e.\ nominal and ordinal, columns.

\pagebreak[2]

\smallskip
\noindent{\bf Examples}
\smallskip

{\hangindent=\parindent\noindent\tt
\hml -f \UnivarScriptName{} -nvargs X=/user/biadmin/X.mtx
  TYPES=/user/biadmin/types.mtx
  STATS=/user/biadmin/stats.mtx

}


\documentclass[twocolumn]{IEEEtran}

\begin{document}
\title{Coevolutionary Aproach to Biobjective Traveling Thief Problem}
\author{Angel David Corredor}
\date{}
\maketitle

\begin{abstract}
    The paper presents a technique for solve the Biobjective Traveling Thief Problem using a Coevolutionary approach.
    There are 2 different populations that resolves separately the subproblems of TTP but work together
    to solve BO-TTP using the friend concept. Finally experiments will be presented using TTP benchmark.
\end{abstract}

\section{Introduction}

The problem is a combination of two well-known optimization problems (TSP and KP).
Two models of TTP are introduced and their characteristics are investigated.
These two models are different from each other based on the way in which the sub-problems are
interdependent. It is shown that solving each sub-problem in isolation is not effective and the
two sub-problems have to be considered together.

\subsection{Traveling Salesman Problem}

The travelling salesman problem is one of the classic NP-hard optimization problems.
In this problem, there are $n$ cities and the distances between the cities are given by a
distance matrix $D=d_{ij}$ ($d_{ij}$ the distance between city $i$ and $j$).
There is a salesman who must visit each city exactly once and minimize the time of the complete tour.
It is assumed that the speed of the salesman is constant ($v_c$) and he tries to minimize
the time of the tour.
The objective function is given by:

\begin{equation}
    f(\bar{x}) =
    \sum_{i=1}^{n-1} (t_{x_i,x_{i+1}})
    + t_{x_n,x_1},
    \bar{x}=(x_1,...,x_n)
\end{equation}

where $\bar{x}$ represents a tour, which contains all of the cities exactly once,
$t_{x_i,x_{i+1}}$ is the time of the travel between $x_i$ and $x_{i+1}$ and it is calculated by:

\begin{equation}
    t_{x_i,x_{i+1}} =
    \frac{d_{x_i,x_{i+1}}}{v_c}
\end{equation}

Clearly, $f$ is the total time of the tour. The aim is to find $x$ which minimizes $f$.

\subsection{Knapsack Problem}

The knapsack problem is another NP-hard optimization problem.
In this problem, there are $m$ items $I_1, ..., I_m$, each of
which has a value ($p_i$) and a weight ($w_i$).
Also, there is a thief who wants to fill his knapsack by taking some of these items.
The capacity of the knapsack is limited ($W$).
The aim of the thief is to pick the items to maximize their total value while
their total weight does not exceed the knapsack capacity.
The problem is modelled as follows:

\begin{equation}
    maximize \; g(\bar{y}) =
    \sum_{i=1}^m p_iy_i,
    \bar{y} = (y_1, ..., y_m)
\end{equation}

\begin{equation}
    subject \; to
    \sum_{i=1}^m w_iy_i \leq W
\end{equation}

where $y_i \in \{0,1\}$ and $y_i = 1$ indicates picking item $i$ and
$g(y)$ is the total value of the picked items. The aim is to
maximize $g$ in a way that the total weight of the items does not
exceed the capacity of the knapsack.

\subsection{Treveling Thief Problem}
In $TTP_2$  there are two objectives, namely maximizing the
total value while minimizing the travel time. However, three
new parameters are added to interconnect two sub-problems:

\begin{itemize}
    \item The speed of the travel ($v_c$ in (2)) is related to the
    knapsack’s current weight,
    ($v_c = (v_{max} - W_c \frac{v_{max}-v_{min}}{W})$)
    where $W_c$ is the current weight of knapsack, $v_{max}$ and $v_{min}$
    are the maximum and minimum velocity of the thief, and
    $W$ is the maximum capacity of knapsack. Note that the
    time of the travel between two cities is calculated via (2).
    According to this formulation, the speed of the thief ($v_c$)
    decreases when the weight of the knapsack increases. Note
    that the thief travels in $v_{max}$ when the knapsack is empty
    ($W_c=0$) and in $v_min$ when the knapsack is full ($W_c=W$).

    The thief has rented the knapsack and he has to pay the rent.
    The knapsack’s rent rate is $\$R$ per time unit.
    The aim of $TTP_2$ is to maximize the following function:

    \begin{equation}
        G(x,z) = g(z) - R*f(x,z)
    \end{equation}

    where $g$ is the total value of all picked items, $R$ is the rent
    per time unit, and $f$ is the total time of the tour. $x$ and $z$ are the
    tour and the picking plan (the solutions of TSP and KP subproblems), respectively.
    Note that the travel time and weight of the picked items have been connected through the changes
    of the speed of travel. Thus, the function $f$ needs to get both $x$
    and $z$ as inputs to calculate the total time. Also, the total value
    of the picked items has been connected to the travel time by
    the rent rate.

    \item The value of the picked items drops by time.
    In fact, the final value of the item at the end of the travel is not the
    same as its value when the thief picked the item. This
    value is dependent on travel time. The dropping rate is
    defined by $Dr^{\lceil \frac{T_i}{C} \rceil}$ where $T_i$ is the total time that the item i
    is carried by the thief and C is a constant. The new value
    of the item i at the end of the tour is calculated by
    $p_i*Dr^{\lceil \frac{T_i}{C} \rceil}$ where $i$ is the item number. \\
\end{itemize}

Note that the rule is to pick the items before the tour is
completed. Hence, the thief cannot pick any more items when
he gets back in the starting city. The aim of $TTP_2$ is to satisfy
the following objectives:

\begin{equation}
    G(x,z) =
\left\{
	\begin{array}{ll}
		min & f(x,z)  \\
		max & g(x,z)
	\end{array}
\right.
\end{equation}

where $x$ and $z$ are the tour and picking plan, respectively. \\

The function $f$ is the time of the tour which is calculated
according to the distance of the cities and the weight of the
picked items. Also, $g$ is the total value of all picked items after
completing the tour (note that the value of the items drops by
the time that they were in the knapsack). The function $f$ is
related to the knapsack weight, in such a way that the heavier
the knapsack gets, the slower the thief can travel, resulting in
greater time being taken to complete the tour. Also, the value
of the picked items after completing the tour depends on the
time of the tour and the original value of the items. The aim is
to maximize the total value of the picked items and minimize
the time for completing the tour.

\section{Problem Encoding}

There are 2 independant populations solving each problem independently but linked with a friend in the other population. %%Pendiente citacion

\subsection{TSP population}
The encoding of each individual is a permutation of $n$ elements called tour,
this represents the order in which the traveler visit the cities.
Aditionaly each individual have a number that identify his friend in the KP population.

\subsection{KP population}
The encoding of each individual is a bit-array with size $m$ that represents the desition of picking each item.
In adition have a number that identify his friend in the TSP population (Encoded in base-2).

\subsection{Friends}
...

\section{Conclutions}

%\begin{thebibliography}{X}
    %Main https://cs.adelaide.edu.au/~zbyszek/Papers/TTP.pdf (este da una proposicion mejor de multiobjetivo)

    %%Instancias del problema https://cs.adelaide.edu.au/~optlog/CEC2014COMP_InstancesNew/
    %%Benchmark https://cs.adelaide.edu.au/~ec/research/ttp/2014gecco-ttp.pdf
    %%BO-TTP https://cs.adelaide.edu.au/~markus/pub/2018gecco-emottp.pdf
    %%Mas cosas https://cs.adelaide.edu.au/~ec/research/combinatorial.php
%\end{thebibliography}

\end{document}


% declare document class and geometry
\documentclass[12pt]{article} % use larger type; default would be 10pt
\usepackage[margin=1in]{geometry} % handle page geometry

\input{../header2.tex}

\title{Phys 220A -- Classical Mechanics -- Lec12}
\author{UCLA, Fall 2014}
\date{\formatdate{18}{11}{2014}} % Activate to display a given date or no date (if empty),
         % otherwise the current date is printed

\begin{document}
\setlength{\unitlength}{1mm}
\maketitle

\section{More HJE: Separability}

As our first realistic example, we'll take a look at motion in a central potential from a new perspective. Given Hamiltonian
\begin{eqn}
H = \frac{p_r^2}{2m} + \frac{p_\theta}{2mr^2} + V(r)
\end{eqn}
the HJE equation
\begin{eqn}
H(\pd{F}{q_i}, q_i,  t) + \pd{F}{t} = 0
\end{eqn}
is just
\begin{eqn}
\frac{1}{2m} \left( \pd{F}{r} \right)^2 + \frac{1}{2mr^2} \left( \pd{F}{\theta} \right)^2 + V(r) + \pd{F}{t} = 0.
\end{eqn}

Since we know that energy is conserved we can actually separate out the time dependence in the generating function
\begin{eqn}
F = W(r, \theta) - \alpha_1 t
\end{eqn}
where $\alpha$ is the constant energy,
\begin{eqn}
H(\pd{W}{q_i}, q_i, t) = \alpha_1.
\end{eqn}
Then our HJE equation reduces to
\begin{eqn}
\frac{1}{2m} \left( \pd{W}{r} \right)^2 + \frac{1}{2mr^2} \left( \pd{W}{\theta} \right)^2 + V(r) = \alpha_1,
\end{eqn}
which we can rewrite as
\begin{eqn}
\left( \pd{W}{\theta} \right)^2 = 2mr^2 (\alpha_1 - V(r)) - r^2 \left( \pd{W_r}{r} \right)^2.
\end{eqn}
We can further separate our ansatz as
\begin{eqn}
W = W_r(r) + w_\theta(\theta)
\end{eqn}
which allows us to separate our equation into separate parts dependent on each coordinate
\begin{eqn}
\left( \pd{W_\theta}{\theta} \right)^2 = \alpha_2^2
\end{eqn}
and
\begin{eqn}
2mr^2 (\alpha_1 - V(r)) - r^2 \left( \pd{W_r}{r} \right)^2 = \alpha_2^2.
\end{eqn}
The first one then just gives us a constant for $\tpd{W_\theta}{\theta}$, and for the other part we have
\begin{eqn}
\pd{W_r}{r} = \frac{1}{r} \sqrt{ 2mr^2(\alpha_1 - V(r)) - \alpha_2^2}.
\end{eqn}
So we have solutions
\begin{eqn}
W_\theta = \alpha_2 \theta, \qquad
W_r = \int \dif{r} \sqrt{2m(\alpha_1 - V(r)) - \alpha_2^2 / r^2}.
\end{eqn}

Of course the HJE equation only gives us the generating function
\begin{eqn}
F = W_r + W_\theta - \alpha_1 t.
\end{eqn}
To solve for the dynamics, we get from the canonical transformation (from the generating function formalism),
\begin{align}
\beta_1 &= \pd{F}{\alpha_1} = -t + \int \dif{r} \, m \left[ 2m(\alpha_1 - V(r)) + \alpha_2^2 / r^2 \right]^{-1/2}, \\
\beta_2 &= \pd{F}{\alpha_2} = \theta - \int \dif{r} \, \frac{\alpha_2}{r^2} \left[ 2m (\alpha_1 - V(r)) + \alpha_2^2 / r^2 \right]^{-1/2}.
\end{align}
So we can interpret $\beta_1$ as initial time $-t_0$ and $\beta_2$ as initial angle $\theta_0$. Furthermore, the angular momentum is just
\begin{eqn}
p_\theta = \pd{W}{\theta} = \alpha_2.
\end{eqn}

\section{Semi-classical approximation}

Recall the Schroedinger equation
\begin{eqn}
i \hbar \pd{\psi}{t} = -\frac{\hbar^2}{2m} \pd[2]{\psi}{q}^2 + V(q) \psi(q,t).
\end{eqn}
If we write an ansatz
\begin{eqn}
\psi(q,t) = R(q,t) e^{i W(q,t) / \hbar}
\end{eqn}
the Schroedinger equation reduces to
\begin{eqn}
\pd{W}{t} + \frac{1}{2m} \left( \pd{W}{q} \right)^2 + V(q) = \bigO(\hbar).
\end{eqn}
If we take $\hbar \rightarrow 0$ then this just reduces to the HJE! So the Hamilton-Jacobi formalism actually gives us ``waves'' with wavefronts of constant action, so the HJE is about as close to a ``particle-wave duality'' in classical mechanics.

\section{Mathematics of Lagrangian and Hamiltonian Mechanics}

In the Lagrangian $L(q_i, \dot q_i, t)$ the $q_i$ are coordinates on a configuration manifold $V$. Then the velocity
\begin{eqn}
\dot q_i(t) = \lim_{\epsilon \rightarrow 0} \frac{q_i(t+\epsilon) - q_i(t)}{\epsilon}
\end{eqn}
is actually just a vector in the tangent space $T_{q(t)}V$, which is the vector space of all tangent vectors at the point $q(t)$. If we consider the collection of all tangent spaces on the manifold $V$ we get the tangent bundle $TV$.

Things get more complicated when we go to Hamiltonian mechanics. When we write the Hamiltonian
\begin{eqn}
H = \sum_i p_i \cdot \dot q_i - L,
\end{eqn}
the velocity $\vd q$ is an element of the tangent space, $\vd q \in T_{q(t)}V$, while the canonical momentum $\v p$ is really a covector, an element of the cotangent space $\v p \in T^*_{q(t)}V$, which is the vector space of all cotangent vectors at the point $q(t)$. Similar to the tangent bundle, the collection of all cotangent spaces is called the cotangent bundle $T^*V$.

We can reformulate the symplectic tensor
\begin{eqn}
J_{IJ} = \pmat{ 0 & 1 \\ -1 & 0}
\end{eqn}
as a 2-form on $T^* V$
\begin{eqn}
\omega = \sum_i \dif p_i \wedge \dif q_i,
\end{eqn}
for which we have $\dif \omega = 0$. It turns out that all of the symplectic geometry we've been discussing can be formulated in terms of this 2-form.

\section{More on integrable systems}

Integrable systems are very important, particularly in statistical mechanics where we have constant energy
\begin{eqn}
H(p_i, q_i) = E.
\end{eqn}
This gives us ``Ergodic behavior'', meaning that every configuration in phase space is equally probable. Since the constant energy surface is a $2n-1$ dimensional subspace of the phase space, we reason that the when the trajectories are evolved to $t = \infty$, the path should trace out every point in the phase space. This is the ``Ergodic hypothesis''.

[Something something, baking analogy]

We can define some interesting subsets of phase space. The Poincare section is defined as the surface which is everywhere orthogonal to the flow at time $t$. In an integrable system, the trajectories instead trace out the Poincare section. [??? but the Poincare section is orthogonal to the flow?]

[something something chaos]

\end{document}