%!TEX root = ../CombinatoricsNotes.tex

\section{Compression and Shadows} %\marginnote{Lecture 7: Wednesday, January 27, 2016.}
\lect{1}{27}
As an aside, let's consider Steiner symmetrization\sidenote{\cite{steiner1838einfache}}, a technique in geometry.
Given a shape $K\subset \R^2$, with a line of ``symmetry'' $L$, we obtain $S_L(K)$ from $K$ by replacing $K\cap L'$ for every line $L'$ orthogonal to $L$ by an interval of length equal to $|K\cap L'|$ centered at $L$.
\paragraph{Properties:}
\begin{enumerate}
	\item $\area(S_L(K)) = \area(K)$
	\item $\diam(S_L(K)) \leq \diam (K)$ \marginnote{The diameter is the largest distance between two points on $K$. We may prove this by drawing trapezoids between two lines $L'$ and $L''$, one of which passes through each point (close to) achieving the diameter.}
	\item $\perim(S_L(K)) \leq \perim(K)$.
\end{enumerate}
Given a shape in $\R^2$ with area 1, what is the smallest diameter? That's the diameter of the area 1 disc. Sketch of proof: take the shape acheiving minimum diameter. By a compactness argument, we could show that if we ``repeatedly'' symmetrize, eventually it is symmetric across every line.

If some bounded shape is symmetric with respect to reflection about three lines $L_1, L_2,$ and $L_3$, then $L_1,L_2,L_3$ all go through the same point. Why? The center of mass must lie on each line.
This will show us that we have a disk. Let us consider a discrete to this symmetrization process: \defn{compression}.
For $A\in [n]^{(r)}$, set
\[
R_{ij}(A) = \begin{cases}
(\A\setminus \{j\})\cup \{i\}, & \text{if } j\in A, i\not \in A\\
A, & \text{otherwise}.
\end{cases}
\]
For example,
\begin{gather*}
R_{15}(\{2,3,5\}) = \{1,2,3\}, \qquad
R_{15}(\{2,3,4\}) = \{2,3,4\},\\
R_{15}(\{1,3,5\}) = \{1,3,5\}.
\end{gather*}
Let $\tilde{R}_{ij}(\A) = \{R_{ij}(A): A\in \A\} \cup \{A: R_{ij}(A)\in \A \}$. \marginnote{Intuition: $\tilde{R}_{ij}$ applies $R_{ij}$ unless the resulting set is already in $\A$, to prevent collapse.}

\paragraph{Properties:}
\begin{enumerate}
	\item $|\tilde{R}_{ij}(\A)| = |\A|$.

	Let $P_{ij} \subset [n]^{(r)}$ denote the collection of all sets containing $j$ but not $i$. Then $R_{ij}: P_{ij} \to P_{ji}$  is bijection.
\end{enumerate}

\noindent We will say $\A$ is \defn{compressed} if $\tilde{R}_{ij}(\A)= \A$ for all $i<j$.
\begin{enumerate}\setcounter{enumi}{1}
\item Any set system $\A$ can be made compressed by applying finitely many compression operators $\tilde{R}_{ij}$, for $i<j$.

Let $w(A) = \sum_{i\in A} i$, and $w(\A) = \sum_{A\in \A} w(A)$. Then $w(R_{ij}(A)) \leq w(A)$ with equality iff $R_{ij}(A)=A$. Therefore, $w(\tilde{R}_{ij}(\A))\leq w(\A)$ with equality iff $\tilde{R}_{ij}(\A) = \A$. Therefore, the process must stop, because we start with finite integer weight and the weight may only decrease (and may not be negative).
\end{enumerate}

In human terms, a compressed set system is one where if we try to replace any element of a set with a smaller element, we end up with something already in the set system.
Let us define a natural partial order on $[n]^{(r)}$. If $A = \{a_1,\dotsc,a_r\}$ with $a_1 < a_2 < \dotsb < a_r$, and $B = \{b_1,\dotsc,b_r\}$ with $b_1<\dotsb < b_r$, then we say $A\preceq B$ if $a_i\leq b_i$ for all $i=1,\dotsc,r$.

\begin{enumerate} \setcounter{enumi}{2}
\item If $i<j$, then $R_{ij}(A) \preceq A$, and conversely if $A' \preceq A$, then $A'$ can be obtained from $A$ by using finitely many compression operators $R_{ij}$ for $i<j$.

\end{enumerate}
Therefore, $\A$ is compressed if and only if for every $A\prec B$ with $B\in \A$, we have that $A\in \A$. In otherwords, $\A$ is an ideal in this order. See \cref{fig:compressed_sets_partial_order} for an example.
\begin{marginfigure}
\begin{center}
\begin{tikzcd}
& \boxed{\{1,2\}} \arrow{d}\\
&\boxed{\{1,3\}} \arrow{ld} \arrow{rd}\\
\boxed{\{1,4\}} \arrow{d} \arrow{rrd}  & &\boxed{\{2,3\}} \arrow{d}\\
\boxed{\{1,5\}} \arrow{d}&& \boxed{\{2,4\}}\arrow{d} \arrow{lld}\\
\{2,5\} \arrow{rd} && \boxed{\{3,4\}} \arrow{ld}\\
&\{3,5\} \arrow{d}\\
&\{4,5\}
\end{tikzcd}
\end{center}
\caption{The partial order on $[5]^{(2)}$, where $A\rightarrow B$ means $a \prec b$, and different sets in the same row are incomparable. The boxed elements together form a compressed set.} \label{fig:compressed_sets_partial_order}
\end{marginfigure}

\begin{enumerate}\setcounter{enumi}{3}
	\item  If $\A$ is intersecting, then $\tilde{R}_{ij}(\A)$ is intersecting.
	Suppose not. Then there exists $A,B\in \tilde{R}_{ij}(\A)$ such that $A\cap B= \emptyset$. If both $A,B\in \A$, then they are intersecting, so let $A\not \in \A$. Then $A = R_{ij}(A')$ for some $ A'\in \A$ with $j\in A'$. Now, if $B \not \in \A$ too, then $B = R_{ij}(B')$ for some $B'\in \A$ with $j\in B'$, and we'd have $i\in A\cap B$, which is a contradiction. So $B\in \A$ with $i\not\in B$.  If $B= R_{ij}(B)$, then $R_{ij}(B)\in \A$. Otherwise, we have $j \in B$, and we must  have $B \neq R_{ij}(B')$ for every $B'\in \A$ (for   $B\in P_{ij}$, while the image of $R_{ij}$ is  $P_{ji}$ which is disjoint from $P_{ij}$). In this case then, since $B\in \tilde{R}_{ij}(\A)$, we must then have $R_{ij}(B)\in \A$ too. So in either case, $R_{ij}(B)\cap A'\in \A$ which is intersecting, so $R_{ij}(B)\cap A' \neq \emptyset$.

	% Now, $k\neq j$ has $k\in A'\cap B$, then  then $k \in R_{ij}(A') = A$, so $k\in A\cap B$, which is a contradiction. On the other hand, $A'\cap B\neq \emptyset$ since $A',B\in \A$ which is intersecting. So $A'\cap B = \{j\}$, and thus $j\in B$. So $B\in P_{ij}$. So $R_{ij}(B) \neq B$, and $B\in \tilde{R}_{ij}(\A)$, so $B$ is such that $R_{ij}(B) \in \A$ (otherwise $B$ would be the non-trivial image of some $B'$ under $R_{ij}$, which leads to a contradiction as showed earlier). Thus $R_{ij}(B)\cap A' \neq \emptyset$.

	%   So $A',B\in \A$, and thus $A'\cap B\neq \emptyset$.

	% Suppose not. Then there exists $A,B\in \tilde{R}_{ij}(\A)$ such that $A\cap B = \emptyset$. We may assume that $\A \not \ni A = R_{ij}(A')$ for some $A'\in \A$, and $B\in \A$\sidenote{Otherwise $i\in B$, so $A\cap B \ni i$.}, and $A'\cap B = \{j\}$. So $B\in P_{ij}$, and hence was unchanged by $R_{ij}$,

	% so $R_{ij}(B)\in \A$. Then $A'\cap R_{ij}(B) \neq \emptyset$, since $\A$ is intersecting.

	But $A'$ is obtained from $A$ by changing $j$ to $i$, and $R_{ij}(B)$ is obtained from $B$ by changing $j$ to $i$, so if $A'\cap R_{ij}(B) \neq \emptyset$, then we have $A\cap B\neq \emptyset$.

\end{enumerate}

\begin{proof}[Proof of \erdos-Ko-Rado theorem by compression]
We wish to show that if $r\leq n/2$, $\A\subset [n]^{(r)}$ is intersecting, then
\[
|\A| \leq {n-1 \choose r-1}.
\]
We will proceed by induction on $n$ and $r$. The case $r=n/2$ is easy: ${n-1\choose r-1} = \frac{1}{2}{n\choose r}$, and sets in $[n]^{(r)}]$ are just complementary pairs.

Assume $r<n/2$. By the facts we have proven, we may assume $\A$ is compressed. Let
\begin{align*}
\A_0 &= \{A\in \A: n\not\in \A\}, & \A_1 &= \{A\in \A: n\in A\}.
\end{align*}
Then by the IH,
\[
|\A| = |\A_0| + |\A_1| \leq {n-2 \choose r-1} + |\A_1|
\]
If $|\A_1| \leq {n-2 \choose r-2}$, then\sidenote{using ${n-2 \choose r-1} + {n-2 \choose r-2} = {n-1\choose r-1}$} we have $|\A| \leq {n-1\choose r-1}$.
Let
\[
\A_1 \setminus \{n\} := \{A-\{n\}: A\in \A_1\}.
\]
 If $\A_1\setminus \{n\}$ is intersecting, then $|\A_1\setminus \{n\}| \leq {n-2 \choose r-2}$ by the IH, since $\A_1\setminus \{n\} \subset [n-1]^{(r-1)}$.
Suppose $\A_1\setminus \{n\}$ is not intersecting. Then there exists $A,B\in \A$ such that
\[
A\cap B = \{n\}.
\]
Because $2r<n$, there exists $i<n$ such that $i\not \in A\cup B$. Then $R_{in}(B) \in \A$ since $\A$ is compressed.
But $A\cap R_{in}(B) = \emptyset$, contradicting that $\A$ is intersecting.
\end{proof}

Let $\A\subset [n]^{(r)}$, with $|\A| = m$. What is $\min |\partial \A|$? \marginnote{Recall:
\[
\partial A = \{B \in [n]^{(r-1)}: B\subset A \text{ for some } A\in \A\}.
\]}
We know the local LYM inequality:
\begin{equation*}	\tag{\cref{eq:local_LYM}}
\frac{|\partial A|}{{n\choose r-1}}\geq \frac{|\A|}{{n\choose r}}
\end{equation*}
but this is rarely tight.

Let's consider $m=1$, that is, $|\A|=1$. Then the answer is $r= {r\choose r-1}$. For $m=2$, the answer is $2r-1$, because their shadows can at most share 1 set.
For $r=2$, we have a simple graph with $m$ edges. What is the minimal number of verticies? We want the minimal $n$ so that $m\leq {n \choose 2}$.
\lect{2}{1}
% \marginnote{Lecture 8: Monday, February 1, 2016.}
Let us change our question to consider $\A\subset \N^{(r)}$ . Given $r$ and $m$, what is $\min |\partial \A|$ given $\A\subset \N^{(r)}$ with $|\A| = m$?

\begin{lemma} \label{lem:compression_decreases_size_of_shadow}We have that
\[
|\partial \tilde{R}_{ij}(\A)| \leq |\partial \A|
\]
for every $\A\subset \N^{(r)}$.
\end{lemma}
\begin{proof}

It suffices to show that
\marginnote{ $|X|\geq |Y| \iff |X\setminus Y| \geq |Y\setminus X| $ because $|X| = |X\setminus Y| + |X \cap Y|$ and $|Y| = |Y\setminus X| + |X\cap Y|$. }
\[
|\partial \tilde{R}_{ij}(\A)\setminus(\partial \A)| \leq | \partial A\setminus(\partial \tilde{R}_{ij}(\A))|.
\]
If $B\in \partial \tilde{R}_{ij}(\A)\setminus (\partial \A)$, then $i\in B$ but $j\not\in B$. Let's see why this is true. Let $A\in  \tilde{R}_{ij}(\A)\setminus (\A)$ such that $B = A\setminus\{k\}$ for some $k$. Then $i\in A$, $j\not \in A$ (and so $j\not \in B$ too). Now, if $i\not \in B$, then $k=i$. But then $B = R_{ji}(A)\setminus\{j\}$ so $B\in \partial \A$, a contradiction.

It is enough to show that
\[
R_{ji}(B)\in \partial \A\setminus(\partial \tilde{R}_{ij}(\A)).
\]
Clearly, $R_{ji}(B)\in \partial \A$, since $B= A\setminus\{k\}$ with $k\neq i,j$, so $R_{ji}(B) = R_{ji}(A)\setminus\{k\}$.

The last piece to check is that $R_{ji}(B)\not\in \partial \tilde{R}_{ij}(\A)$. If that were the case, then $R_{ji}(A)\setminus\{k\} \subset C$ for some $C \in \tilde{R}_{ij}(\A)$. Since $j\in R_{ji}(A)$ and $k\neq j$, we have $j\in C$. Then $R_{ij}(C) \in \A$. But then $B=A\setminus \{k\} \in R_{ij}(C) \in \A$, so $B \in \partial \A$, a contradiction.
% Assume $B= C \setminus \{\ell\} \in \partial \tilde{R}_{ij}(\A)$ for some $C \in \tilde{R}_{ij}(\A)$. Then $C\setminus\{\ell\} = R_{ji}(A)\setminus \{k\}$.
% \understand
\end{proof}
This lemma shows that for the purposes of minimizing $|\partial \A|$, we may start with a compressed set.

\newthought{We defined a partial order} on $\N^{(r)}$ by $A = \{a_1,\dotsc,a_r\}$, $a_1<a_2<\dotsb < a_r$, and $B=\{b_1,\dotsc,b_r\}$, and $b_1<b_2<\dotsb < b_r$, then $A\preceq B$ if $a_i\leq b_i$ for $i\in[r]$.
We may define the \defn{lexicographic order} on $\N^{(r)}$. We say $A\leq_L B$ if ($a_1<b_1$) or ($a_1=b_1$ and $a_2 < b_2$) or $(a_1 = b_1$ and $a_2=b_2$, but $a_3<b_3)$ etc. That is, either $A=B$, or if $s$ is the minimal index such that $a_s\neq b_s$, then $a_s<b_s$. See \cref{fig:53_lexographic_order} for an example.
\begin{marginfigure}
\begin{tikzcd}[column sep=small]
\boxed{\{1,2,3\}} \arrow{r} &
\boxed{\{1,2,4\}} \rar \snakesetup &
\{1,2,5\} \snakearrow{lld}  \\
\boxed{\{1,3,4\}} \rar &
\{1,3,5\} \rar \snakesetup&
\{1,4,5\}  \snakearrow{lld}\\
\boxed{\{2,3,4\}} \rar \snakesetup &
\{2,3,5\}  \rar   &
\{2,4,5\}   \snakearrow{lld}\\
\{3,4,5\}
\end{tikzcd}

\caption{Elements of $[5]^{(3)}$ in lexographic order, where $A\imp B$ means $A\leq_L B$. The subsets of $[4]^{(3)}$ are boxed; they appear in order, but not next to each other.} \label{fig:53_lexographic_order}
\end{marginfigure}

Consider the lexographic order on $\N^{(3)}$. What is the 100th smallest set in this order? $\{1,2,102\}$.

Now, let us define the \defn{colexicographic order} on $\N^{(r)}$. Define $A\leq B$ if $a_r<b_r$ or ($a_r=b_r$ and $a_{r-1} <b_{r-1}$) or \ldots etc. We may write this as $A=B$ or if $s$ is the maximal index such that $a_s\neq b_s$, then $a_s<b_s$.

% \begin{fullwidth}

\begin{figure*}[ht]
% \makeatletter\setlength\hsize{\@tufte@fullwidth}\setlength\linewidth{\@tufte@fullwidth}\let\caption\@tufte@orig@caption\makeatother
\centering

\begin{tikzcd}[column sep=small]
[3]^{(3)} &\{1,2,3\} \arrow{d} \\
 {[4]^{(3)}}\setminus[3]^{(3)} & \{1,2,4\} \arrow{r}& \{1,3,4\} \snakesetup \arrow{r}& \{2,3,4\} \snakearrow{lld}\\
{[5]^{(3)}}\setminus[4]^{(3)} & \{1,2,5\} \arrow{r} & \{1,3,5\}\arrow{r} & \{2,3,5\} \arrow{r}& \{1,4,5\} \arrow{r}& \{2,4,5\}\arrow{r} & \{3,4,5\}
\end{tikzcd}
\bigskip
\caption{Elements of $[5]^{(3)}$ in colexographic order. Note that $[n]^{(r)}$ is an initial segment of the colex order on $\N^{(r)}$. \label{fig:53_colexographic_order}}
\end{figure*}
% \end{fullwidth}

\begin{theorem}[\cite{kruskal1963,katona1968}] \label{thm:kruskal_katona}
If $\A\subset \N^{(r)}$ with $|\A| = m$, then $|\partial \A|$ is at least as large as the size of the shadow of the first $m$ elements of $\N^{(r)}$ in colexicographic order.
\end{theorem}
\begin{example}
If $A= \{10,7,3\}$ what is the position of $A$ in the colex order on $\N^{(3)}$? In the rows\sidenote{Referring to an analogous diagram to \cref{fig:53_colexographic_order}.} before $A$, there will be $|[9]^{(3)}| ={9\choose 3}$ elements.  In the row containing $A$, there are sets of the form $\{10,x,*\}$ with $x<7$, i.e. ${6\choose 2}$ sets. Next, there are sets of the form $\{10,7,y\}$ with $y<3$, i.e. ${2\choose 1}$ sets. Finally, we have our set, $\{10,7,3\}$. In total then,
\[
{9\choose 3} + {6\choose 2} + {2\choose 1} + 1 = 102.
\]

See \cref{fig:colex_near_A} for a diagram.
\begin{figure*}[ht]
\begin{center}
\begin{tikzcd}[column sep=tiny]
  \{10,6,5\} \rar&\{10,7,1\} \rar &\{10,7,2\} \rar &\{10,7,3\} \rar  & \{10,7,4\}  \rar & \{10,7,5\}\rar   & \{10,7,6\}  \rar & \{10,8,1\}.
\end{tikzcd}
\caption{The colex order near $A=\{10,7,3\} \subset \N^{(3)}$. The notation $A\imp B$ means $A\leq B$ in colex order. Since $A$ is the 102nd set in colex order on $\N^{(3)}$, $\{10,7,1\}$ is the 100th set which provides a nice comparison to $\{1,2,102\}$, the 100th set in lexicographic order. In particular, we note that in colex order, every set is finitely many positions away from the smallest set, while in lexicographic order many sets are infinitely far (like $\{1,3,4\}$).}\label{fig:colex_near_A}
\end{center}

\end{figure*}
% \improvement{Put captions of full-width figures below the figure in the main column.}
\end{example}

% \begin{definition}
For $A\in \N^{(r)}$, let the \defn{initial segment of $A$} be $I(A) =\{B: B\leq \A\}$ and let $i(A) = |I(A)|$.
% \end{definition}
\begin{lemma}
If $A = \{a_1,\dotsc,a_r\}$ with $a_r>a_{r-1}>\dotsb> a_1$ then
\[
i(A) = {a_{r}-1\choose r} + {a_{r-1}-1 \choose r-1} + \dotsb + {a_1-1 \choose 1} + 1.
\]
\end{lemma}
\begin{proof}
${a_{k} -1\choose k}$ counts sets $B\subset A$ which coincide with $A$ over
\[
 a_r,a_{r-1},\dotsc,a_{k+1}
\]
  but whose $k$th largest element is smaller.
\end{proof}

\begin{lemma} We have that the shadow of the inital segment $I(A)$ is the initial segment of $A\setminus\{\min A\}$. That is,
\[
\partial I(A) = I( A\setminus \{\min A\}).
\]
\end{lemma}
\begin{proof}
If $A = \{a_r,\dotsc,a_2,a_1\}$, then we wish to show that $B\subset \N^{(r-1)}$ is in $\partial I(A)$ if and only if $B \leq \{a_r,\dotsc,a_2\} = A\setminus \{\min A\}$ in colex order. This is left as an exercise. One way to proceed is by induction on $r$, splitting into cases where $B$ contains $a_r$ or not.
% \add{proof.}
\end{proof}

\begin{corollary}
If
\[
 i(A) = {a_r-1\choose r} + {a_{r-1} \choose r-1} + \dotsb + {a_1-1\choose 1} + 1,
 \]
then
\[
|\partial (I(A))| = {a_r -1\choose r-1} + {a_{r-1} -1 \choose r-2} + \dotsb + {a_2-1 \choose 1} + 1.
\]
\end{corollary}

Let us restate \cref{thm:kruskal_katona}:
\begin{theorem*}[Kruskal--Katona]
Let $\A\subset \N^{(r)}$ with
\[
|\A| = {a_r-1\choose r} + {a_{r-1} -1\choose r-1} + \dotsb + {a_1-1\choose 1} + 1
\]
for some $a_r>\dotsc>a_1$. Then
\[
|\partial \A| \geq{a_r -1\choose r-1} + {a_{r-1} -1 \choose r-2} + \dotsb + {a_2-1 \choose 1} + 1.
\]
\end{theorem*}
\begin{remark}
For every positive integer $m$, we may write $m$ as
\[
m={a_r-1\choose r} + {a_{r-1} \choose r-1} + \dotsb + {a_1-1\choose 1} + 1
\]
for some $a_r> a_{r-1} > \dotsm > a_1$. We have shown this already by considering the $m$th element in colex order of $\N^{(r)}$.
\end{remark}

\begin{proof}[Proof by induction on $r$; for fixed $r$, by induction on $|\A|$.] The base case $r=1$ is trivial. For the induction step, we will assume that $\A$ is compressed, by \cref{lem:compression_decreases_size_of_shadow}. Let
\begin{align*}
A_1 :\!&= \{A\in \A: 1\in A\}, & A_0 :\!&= \A\setminus \A_1.
\end{align*}

\begin{enumerate}[{Claim} 1:]
\item $|\A_1| \geq |\partial A_0|$.\marginnote{Compression pushes us towards smaller elements, so $\A_1$ should be large.}

\begin{subproof}
The map $A\mapsto A\cup\{1\}$ is an injection from $\partial \A_0$ to $\A_1$, by compression.
\end{subproof}
	\item
	\[
	|\A_1|\geq {a_r-2\choose r-1} + {a_{r-1}-2\choose r-2} + \dotsb + {a_2-2\choose 1} + 1.
	\]
	\begin{subproof}Assume not. Since $|\A_0| =|\A| - |\A_1|$, we have then have
	\begin{align*}
	|\A_0|&> \left( {a_r-1\choose r} - {a_r-2\choose r-1} \right) + \left( {a_{r-1}-1\choose r-1} - {a_{r-1}-2\choose r-2} \right) + \dotsb + {a_1-1 \choose 1}\\
	&= {a_{r}-2 \choose r} + {a_{r-1}-2\choose r-1} + \dotsb + {a_1-2 \choose 1}+1.
	\end{align*}
	By the IH\sidenote{Since $\A$ is compressed it must contain 1},
\[
|\partial \A_0| \geq {a_r-2\choose r-1} + \dotsb + {a_2-2\choose 1}+1
\]
Then claim 1 yields the result.
	\end{subproof}
\end{enumerate}
Let $B = \{A-\{1\}: A\in \A_1\}\subset \N^{(r-1)}$. Note $|B| = |\A_1|$.
\begin{enumerate}[{Claim} 1:]
\setcounter{enumi}{2}
	\item
	$|\partial \A|\geq |B| + |\partial B|$.

	\begin{subproof}
	Note $B\subset \partial \A$. Let $B' = \{B\cup \{1\}: B\in \partial B\} \subset \partial A$. Then $B\cup B' \subset \partial \A$. But since sets in $B'$ contain $1$ and sets in $B$ do not contain $1$, $|B\cup B'| = |B|+|B'|$.
	\end{subproof}
\end{enumerate}
By claims 2, 3, and the IH, we have
\begin{align*}
|\partial \A| &\geq |B| + |\partial B| \\
&\geq {a_r-2 \choose r-1} + {a_{r-1}-2\choose r-2} + \dotsb + {a_2-2\choose 1}+1 \\
&\qquad + {a_r-2 \choose r-2} + {a_{r-1}-2 \choose r-3} + \dotsb + {a_3-2\choose 1} + 1\\
&= {a_r-1\choose r-1} + \dotsb {a_3-1\choose 2} + {a_2-1\choose 1}+1.  \qedhere
\end{align*}
\end{proof}
\begin{theorem}[\cite{lovaszbook_hyper}]
Let $\A\subset \N^{(r)}$, where $|\A| = {x\choose r}$ for $x\in \R$.\marginnote{We define ${x\choose r} := \frac{x(x-1)\dotsm(x-r+1)}{r!}$. Since the polynomials
${x\choose r}$ and ${x-1\choose r} + {x-1\choose r-1}$ agree on the integers, they agree everywhere.}
Then $|\partial \A| \geq {x\choose r-1}$.\sidenote{If $x$ is an integer, then equality can be achieved by taking $\A=[x]^{(r)}$.}.
\end{theorem}
\begin{proof}
The proof follows that of the reformulated Kruskal--Katona. Claims 1 \& 3 have the same proof. For claim 2, there is a much simpler proof:
\begin{enumerate}[{Claim }1.]\setcounter{enumi}{1}
% \item $|\partial \A_0|\leq|\A_1|$
\item $|\A_1|\geq {x-1\choose r-1}$.
\begin{subproof}
If not, $|\A_0| = |\A| - |\A_1| \geq {x\choose r} - {x-1 \choose r-1} = {x-1\choose r}$. Then $|\partial \A_0| \geq {x-1\choose r-1} > |\A_1|$, a contradiction.
\end{subproof}
% \item
\end{enumerate}
The rest of the proof is the same.
\end{proof}

\begin{corollary} \label{cor:ell_shadows}
Let $\A\subset \N^{(r)}$ with $|\A| = {x\choose r}$ for $x\in \R$. Let
\[
\partial^{(\ell)}\A = \{B\in \N^{(r-\ell)}: B\subset A \text{ for some }A\in\A\}.
\]
Then
\[
|\partial^{(\ell)}A|\geq {x\choose r-\ell}.
\]
\end{corollary}
\begin{proof}[Proof by induction on $\ell$.] The base case is Lor\'asz's theorem. Then
\[
\partial^{(\ell)}\A = \partial ( \partial^{(\ell-1)}\A)
\]
so the IH and Lor\'asz's theorem yield the result.
\end{proof}

\begin{corollary}
Let $G$ be a 2-graph. Then \marginnote{$\edges (G)$ denotes the edge set of $G$. We identify $G$ with $\edges (G)$.}
\[
|G| = |\edges (G)| = {x\choose 2}
\]
for some $x\in \R$. Then $G$ contains at most ${x\choose k}$ complete subgraphs\sidenote{$k$-tuples of verticies pairwise joined by edges.} of size $k$.
\end{corollary}
\begin{remark}
We may reformulate this as follows, in a special case. Let $G$ be a graph with ${n\choose 2}$ edges (but possibly more than $n$ verticies). Then $G$ contains a maximum number of triangles when $G$ is a complete graph of $n$ verticies. We think of this as we are given a budget of edges, and are trying to maximize the number of triangles we make. Here it is intuitive that to do this, we make a complete graph.
\end{remark}
\begin{proof}
We may assume that $x\geq k$; otherwise we may not form any complete $k$-subgraphs. If the number of complete subgraphs of $G$ is strictly larger than ${x\choose k}$, then it is equal to ${x' \choose k}$ for some $x' > x$. So we choose $\A$ to be the family of verticies of complete subgraphs of $G$:
\[
\A = \{V(H): H \text{ is a complete subgraph of }G\} \subset V(G)^{(k)}.
\] Then each $\{x,y\} \in \partial^{(k-2)} \A$ is a two element subset of a complete subgraph of $G$,  so $\partial^{(k-2)} \A\subset \edges(G)$. Then by \cref{cor:ell_shadows}, we must have $|\edges (G)| \geq {x'\choose 2} > {x\choose 2}$, a contradiction.
% \understand
% Everything that lies in the shadow of order $k-2$ must
\end{proof}


\chapter{Mapping the Data}
\label{ch:mapping-the-data}

Imagine a foreign visitor to the US who knows nothing about the US geography. He doesn't even have a map; the only data he has is a list of distances between the cities. Oh, yes, and he attended the Introduction to Data Mining.

If we know distances between the cities, we can cluster them.\marginnote{For this example we retrieved the data from \url{http://www.mapcrow.info/united_states.html}, removed the city names from the first line and replaced it with "31 labelled".\break\break The file is available at \url{http://file.biolab.si/files/us-cities.dst.zip}. To load it, unzip the file and use the \widget{File Distance} widget.}

\begin{figure}[h]
    \centering
    \includegraphics[width=\linewidth]{dendrogram.png}
    \caption{$\;$}
\end{figure}

How much sense does it make? Austin and San Antonio are closer to each other than to Houston; the tree is then joined by Dallas. On the other hand, New Orleans is much closer to Houston than to Miami. And, well, good luck hitchhiking from Anchorage to Honolulu.

As for Anchorage and Honolulu, they are leftovers; when there were only three clusters left (Honolulu, Anchorage and the big cluster with everything else), Honolulu and Anchorage were closer to each other than to the rest. But not close — the corresponding lines in the dendrogram are really long.

The real problem is New Orleans and San Antonio: New Orleans is close to Atlanta and Memphis, Miami is close to Jacksonville and Tampa. And these two clusters are suddenly more similar to each other than to some distant cities in Texas.

\marginnote{We can't run k-means clustering on this data, since we only have distances, and k-means runs on real (tabular) data. Yet, k-means would have the same problem as hierarchical clustering.}In general, two points from different clusters may be more similar to each other than to some points from their corresponding clusters.

To get a better impression about the physical layout of cities, people have invented a better tool: a map! Can we reconstruct a map from a matrix of distances? Sure. Take any pair of cities and put them on a paper with the distance corresponding to some scale. Add the third city and put it at the corresponding distance from the two. Continue until done. Excluding, for the sake of scale, Anchorage, we get the following map.

\begin{figure*}[h]
    \centering
    \includegraphics[width=\linewidth]{mds-jitter.png}
    \caption{$\;$}
\end{figure*}

We have not constructed this map manually, of course. We used a widget called \widget{MDS}, which stands for Multidimensional scaling.

It is actually a rather exact map of the US from the Australian perspective. You cannot get the orientation from a map of distances, but now we have a good impression about the relations between cities. It is certainly much better than clustering.

\begin{marginfigure}
    \includegraphics[width=\linewidth]{distance-workflow.png}
\end{marginfigure}

\newpage

Remember the clustering of animals? Can we draw a map of animals?
Does the map make any sense? Are similar animals together? Color the points by the types of animals and you should see.

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.7]{zoo-workflow.png}
    \caption{$\;$}
\end{figure}

\begin{figure*}[h]
    \centering
    \includegraphics[width=\linewidth]{zoo-mds.png}
    \caption{$\;$}
\end{figure*}

The map of the US was accurate: one can put the points in a plane so that the distances correspond to actual distances between cities. For most data, this is usually impossible. What we get is a projection (a non-linear projection, if you care about mathematical finesses) of the data. You lose something, but you get a picture.

The MDS algorithm does not always find the optimal map. You may want to restart the MDS  from random positions. Use the slider "Show similar pairs" to see whether the points that are placed together (or apart) actually belong together. In the above case, the honeybee belongs closer to the wasp, but could not fly there as in the process of optimization it bumped into the hostile region of flamingos and swans.


\subsubsection{FastFourierTransform}
\label{FastFourierTransformPP}
The \xmlNode{FastFourierTransform} PostProcessor provides access to the Numpy fast Fourier transform function
\texttt{numpy.fft.fft}
and provides the frequencies, periods, and amplitudes from performing the transform. The periods are simply
the inverse of the frequencies, and the frequency units are the deltas between pivot values in the provided
input. For example, if data is collected every 3600 seconds, the units of frequency are per-hour.  This
PostProcessor expects uniformly-spaced pivot values. Note that for each realization in the input data object,
a separate fft will be created for each target.

The \xmlNode{FastFourierTransform} PostProcessor can act on any target in a DataObject that depends on a
single index, and generates three histories per sample per target: an independent variable
\xmlString{target\_fft\_frequency}, and two dependent values \xmlString{target\_fft\_period} and
\xmlString{target\_fft\_amplitude}, which both depend on the frequency by default. In all three outputs,
\emph{target} is replaced by the name of the target for which the fft was requested.

\ppType{FastFourierTransform}{FastFourierTransform}
%
\begin{itemize}
  \item \xmlNode{target}, \xmlDesc{comma separated strings, required field}, specifies the names of the
    target(s) for which the fast Fourier transform should be calculated.
 \end{itemize}
\textbf{Example:}

\begin{lstlisting}[style=XML]
<Simulation>
 ...
  <Models>
    ...
    <PostProcessor name="pp" subType="FastFourierTransform">
      <target>x, y</target>
    </PostProcessor>
    ...
  </Models>
 ...
</Simulation>
\end{lstlisting}


\subsubsection{EconomicRatio}
\label{EconomicRatio}
The \xmlNode{EconomicRatio} post-processor provides the economic metrics from the percent change
period return of the asset or strategy that is given as an input. These metrics measure the risk-adjusted returns.
%
\ppType{EconomicRatio}{EconomicRatio}

\begin{itemize}
  \item \xmlNode{"metric"}, \xmlDesc{comma separated string or node list, required field},
  specifications for the metric to be calculated. The name of each node is the requested metric.
  The text of the node is a comma-separated list of the parameters for which the metric should be calculated.

  Currently the scalar quantities available for request are:
  \begin{itemize}

  \item \textbf{sharpeRatio}: the Sharpe Ratio, measures the performance of an investment. It is defined as the  historical returns of the investment, divided by the standard deviation of the investment(Volatility).
  \item \textbf{sortinoRatio}: the Sortino ratio, measures the risk-adjusted return of an investment asset. Discounts the excess return of a portfolio above a target threshold by the volatility of downside returns. If this quantity is inputted as \textit{sortinoRatio} the threshold for separate upside and downside value will assign as $0$. Otherwise the user can specify this quantity with a parameter \xmlAttr{threshold='X'}, where the \xmlAttr{X} represents the requested threshold \xmlAttr{median} or \xmlAttr{zero}.

  \item \textbf{gainLossRatio}: the gain-loss ratio, discounts the first-order higher partial moment of a portfolio's returns, by the first-order lower partial moment of a portfolio's returns. If this quantity is inputted as \textit{gainLossRatio} the threshold for separate upside and downside value will assign as $0$. Otherwise the user can specify this quantity with a parameter \xmlAttr{threshold='X'}, where the \xmlAttr{X} represents the requested threshold \xmlAttr{median} or \xmlAttr{zero}.

  \item \textbf{expectedShortfall}: the expected shortfall (Es) or conditional value at risk (CVaR), the expected return on the portfolio in the worst q of cases. If this quantity is inputted as \textit{ExpectedShortfall} the q value will assign as $5\%$. Otherwise the user can specify this quantity with a parameter \xmlAttr{threshold='X'}, where the \xmlAttr{X} represents the requested q value (a floating point value between 0.0 and 1.0)
  \begin{equation}
    ES_\alpha = -\frac{1}{\alpha} \int_0^\alpha \operatorname{VaR}_\gamma(X) \, d\gamma
  \end{equation}
  \item \textbf{valueAtRisk}: the value at risk for investments. Estimates the maximum possible loss after exclude worse outcomes whose combined probability is at most $\alpha$. If this quantity is inputted as \textit{ValueAtRisk} the $\alpha$ value will assign as $5\%$. Otherwise the user can specify this quantity with a parameter \xmlAttr{threshold='X'}, where the \xmlAttr{X} represents the requested $\alpha$ value (a floating point value between 0.0 and 1.0)

  \begin{equation}
    \operatorname{VaR}_\alpha(X)=-\inf\big\{x\in\mathbb{R}:F_X(x)>\alpha\big\} = F^{-1}_Y(1-\alpha).
  \end{equation}
  \end{itemize}
  This XML node needs to contain the attribute:
  \begin{itemize}
    \itemsep0em
    \item \xmlAttr{prefix}, \xmlDesc{required string attribute}, user-defined prefix for the given \textbf{metric}.
      For scalar quantifies, RAVEN will define a variable with name defined as:  ``prefix'' + ``\_'' + ``parameter name''.
      For example, if we define ``mean'' as the prefix for \textbf{expectedValue}, and parameter ``x'', then variable
      ``mean\_x'' will be defined by RAVEN.
      For matrix quantities, RAVEN will define a variable with name defined as: ``prefix'' + ``\_'' + ``target parameter name'' + ``\_'' + ``feature parameter name''.
      For example, if we define ``sen'' as the prefix for \textbf{sensitivity}, target ``y'' and feature ``x'', then
      variable ``sen\_y\_x'' will be defined by RAVEN.
      \nb These variable will be used by RAVEN for the internal calculations. It is also accessible by the user through
      \textbf{DataObjects} and \textbf{OutStreams}.
  \end{itemize}

\end{itemize}

\textbf{Example:}
\begin{lstlisting}[style=XML,morekeywords={name,subType,class,type,steps}]
<Simulation>
  ...
    <Models>
    ...
    <PostProcessor name="EconomicRatio" subType="EconomicRatio" verbosity="debug">
      <sharpeRatio prefix="SR">x0,y0,z0,x,y,z</sharpeRatio>
      <sortinoRatio threshold='zero' prefix="stR">x01,y01,x,z</sortinoRatio>
      <sortinoRatio threshold='median' prefix="stR2">z01,x0,x01</sortinoRatio>
      <valueAtRisk threshold='0.07' prefix="VaR">z01,x0,x01</valueAtRisk>
      <expectedShortfall threshold='0.99' prefix="CVaR">z01,x0,x01</expectedShortfall>
      <gainLossRatio prefix="glR">x01,y01,z0,x,y,z</gainLossRatio>
    </PostProcessor>
    ...
  </Models>
  ...
</Simulation>
\end{lstlisting}


\subsection{Proposed Model}
\label{sec:models}

We designed a \emph{Convolutional Neural Network (CNN)} that takes as inputs
the sensor distances and colour data obtained from the laser scanner
(size: $180 \times 4$) and produces as output the left and the right wheel
target speeds.

One peculiarity is that we used convolutional layers with circular padding,
since the laser scanner returns a 360° view of the world around the robot.The
\emph{Rectified Linear Unit} (ReLU) activation function is applied after every
layer, except for the last one.

The input data are normalised by subtracting and dividing the channel-wise mean
and standard deviation over the training set. Furthermore, channel-wise
multiplicative $\alpha$ and additive $\beta$ parameters are learned during
training to rescale the input to the most convenient range for the network:
\begin{IEEEeqnarray}{lL}
	y &= (x - \mu) / \sigma \\
	z &= \alpha y + \beta
\end{IEEEeqnarray}
This is implemented in the code with a \texttt{BatchNorm1d} layer.

The training set data are shuffled at the beginning of each epoch, so the
mini-batches (that are of size $2^{14}$) are generated independently between
epochs.

The model is trained with the \emph{Adam} optimiser and learning rate $0.001$,
while the other parameters have their default values. The training is
interrupted using \emph{early stopping}, if the validation loss doesn't improve
for 20 epochs, or after 500 epochs.

During the various experiments, four different architectures are evaluated:
\begin{itemize}
	\item \emph{Baseline network}: 3 convolutional and 3 fully-connected
	layers (Table~\ref{tab: baseline})
	\item Baseline network plus one max pooling layer (Table~\ref{tab: maxpool})
	\item Baseline network plus dropout (Table~\ref{tab: baseline} +
	Table~\ref{tab: dropout})
	\item Baseline network plus one max pooling layer and dropout
	(Table~\ref{tab: maxpool} + Table~\ref{tab: dropout})
\end{itemize}

\begin{table}[htbp]
	\caption{Architecture of the Baseline Network}
	\begin{center}
		\begin{tabular}{|c|c|c|c|c|}
			\hline
			\textbf{Layer}&\textbf{Channels} &\textbf{Kernel size} &\textbf{Stride} &\textbf{Padding}\\
			\cline{1-5}
			conv1 &  4 $\rightarrow$ 16 & 5 & 2 & 2, circular \\ \hline
			conv2 & 16 $\rightarrow$ 32 & 5 & 2 & 2, circular \\ \hline
			conv3 & 32 $\rightarrow$  			 32 & 5 & 1 & 2, circular \\ \hline
			fc1 &   45 $\times$ 32 $\rightarrow$ 128 &  &  &  \\ \hline
			fc2 &  128 $\rightarrow$ 128 &  &  &  \\ \hline
			fc3 &  128 $\rightarrow$   2 &  &  &  \\ \hline
		\end{tabular}
		\label{tab: baseline}
	\end{center}
\end{table}

\begin{table}[htbp]
	\caption{Architecture of the Network with Max Pooling}
	\begin{center}
		\begin{tabular}{|c|c|c|c|c|}
			\hline
			\textbf{Layer}&\textbf{Channels} &\textbf{Kernel size} &\textbf{Stride} &\textbf{Padding}\\
			\cline{1-5}
			conv1  &   4 $\rightarrow$  \bfseries	32 & 5 & 2 & 2, circular \\ \hline
			conv2  & \bfseries 32 $\rightarrow$  	96 & 5 & 2 & 2, circular \\ \hline
			\bfseries mpool1 & 					   & \bfseries 3	& \bfseries 3 & \bfseries 1, circular \\
			\hline
			conv3  & \bfseries 96 $\rightarrow$  	96 & 5 & 1 & 2, circular \\ \hline
			fc1    & 15 $\times$ 96 $\rightarrow$ 128 &  &  &  \\ \hline
			fc2    & 128 $\rightarrow$ 128 &  &  &  \\ \hline
			fc3    & 128 $\rightarrow$   2 &  &  &  \\ \hline
			%\multicolumn{5}{l}{$^{\mathrm{a}}$Sample of a Table footnote.}
		\end{tabular}
		\label{tab: maxpool}
	\end{center}
\end{table}

\begin{table}[htbp]
	\caption{Architecture of the Network with Dropout}
	\begin{center}
		\begin{tabular}{|c|c|c|c|c|}
			\hline
			\textbf{Layer}&\textbf{Channels} &\textbf{Kernel size} &\textbf{Stride} &\textbf{Padding}\\
			\cline{1-5}
			\multicolumn{5}{|c|}{...} \\ \hline
			fc1 &  1440 $\rightarrow$ 128 &  &  &  \\ \hline
			\bfseries drop1 & \multicolumn{4}{c|}{\bfseries dropout with p = 0.5} \\ \hline
			fc2 &  128 $\rightarrow$ 128 &  &  &  \\ \hline
			\bfseries drop2 & \multicolumn{4}{c|}{\bfseries dropout with p = 0.5} \\ \hline
			fc3 &  128 $\rightarrow$   2 &  &  &  \\ \hline
			%\multicolumn{5}{l}{$^{\mathrm{a}}$Sample of a Table footnote.}
		\end{tabular}
		\label{tab: dropout}
	\end{center}
\end{table}


\section{Increasing Sparsity}
\label{sec:sparsity}

We noted that the 45 cluster spectral clustering result described in
the previous section assigned many more tags to each word than the
gold standard.  To quantify the difference we used a measure called
tag perplexity defined as follows:

\[ 2^{\frac{1}{N}\sum_{i=1}^N -\log_2 p(t_i | w_i)} \]

Here $N$ is the number of words in the corpus, $w_i$ is the i'th word,
$t_i$ is its assigned cluster or tag, and $p(t_i|w_i)$ is the fraction
of times word $w_i$ has been assigned $t_i$.  A model which had to
choose from $q$ equally likely tags for each word would have a tag
perplexity of $q$.  The tag perplexity of the gold standard 45-tag 24K
word test corpus is 1.09, whereas the tag perplexity of the spectral
clustering result is 2.76.

We experimented with two methods for reducing the number of tags
assigned to each word: collapsing and word penalties.  Collapsing
enforces the one-tag-per-word constraint by re-tagging the corpus,
whereas word penalties encourage it by increasing the distance between
instances with different target words.

To collapse a given tag assignment for a corpus, we re-tag each word
with its most frequent tag in the original assignment (we break ties
randomly).  This forcefully reduces the tag perplexity to 1 and
removes any ambiguity.  Collapsing improves the many-to-one accuracy
by more than 10\% from \spectralResult\% to \collapseResult\%.

Interestingly when we try to enforce the one-tag-per-word restriction
before clustering (by giving the average substitute vector for each
word type to spectral clustering) the results get worse (58.02\%
many-to-one accuracy).  The information in individual instances seems
to be necessary for good clusters to arise.

Word penalties include information about the target word in the
distance metric.  The substitute vectors and the KL2 distance metric
based on them carry no information about the target word, only its
context.  We used the following distance metric which increases the
distance between instances with different target words:

\[ D(i, j) = KL2(s_i,s_j)+\delta I(w_i \neq w_j) \]

Here $s_i$ is the substitute vector and $w_i$ is the target word for
the i'th position, $\delta$ is the regularization parameter, and $I$
is the indicator function that gives 1 if the two words are different
and 0 if they are the same.  Increasing the $\delta$ decreases the tag
perplexity, but the accuracy change is non-monotonic.  At $\delta=1$
we obtain a tag perplexity of 1.91 and the many-to-one accuracy
increases from \spectralResult\% to 64.35\%.  This demonstrates that
we can significantly increase the accuracy by including more
information on the target word without employing the full
one-tag-per-word constraint.
%% Table~\ref{tab:results} summarizes the results.

%% % do we need graph of delta vs accuracy? no does not look meaningful.

%% \begin{table}[h] \centering
%% \begin{tabular}{|lll|} \hline
%% algorithm & many-1 & tag-perp. \\ \hline
%% spectral & \spectralResult & 2.76 \\
%% word-penalty & 64.35 & 1.91 \\
%% collapsed & \collapseResult & 1.00 \\ \hline
%% gold & 100 & 1.09 \\ \hline
%% \end{tabular}
%% \caption{The many-to-one accuracy and tag perplexity of spectral
%%   clustering, word-penalty, and collapsed algorithms in comparison to
%%   the gold standard.}
%% \label{tab:results}
%% \end{table}

\begin{figure*}[t]
\includegraphics[width=\textwidth]{hinton.eps}
\vspace*{-10mm}
\caption{Hinton diagram of the most frequent tags (rows) and clusters
  (columns).  Area of each square is proportional to the joint
  probability of the given tag and cluster.}
\label{fig:hinton}
\end{figure*}


%% Chapter 8 : Generation Forecasting using

\section{Introduction to Artificial Neural Networks}
\
\
\
\
Artificial Neural Networks (ANN) are a type of machine learning model, they are inspired from the biological neural networks present in the brains of the animals. Being highly non-linear, data driven and with a self adaptive approach; ANN's are a powerful tool for modelling phenomenons whose underlying principles and/or data relationships are unknown. They try to imitate the learning process of the human brain, and when trained properly can correlate patterns between input data and the corresponding target data; moreover they can predict outcomes for new independent data. Their adaptive nature replaces traditional programming with learning in problem solving. This helps in developing computational models for applications where there is little or incomplete understanding of the problem to be solved but where training data is readily available.\\

\textbf{Characterisctics of ANN's:}

\begin{itemize}

\item ANNs possess mapping capability, hence they can map input data to the corresponding output data.

\item ANNs possess learning capability, hence they can be trained with available data of a problem and be tested for inference on unknown data. They can identify new outcomes for data sets on which they were previously never trained.

\item ANNs possess generalizing capability, hence they can predict new outcomes from past trends.

\item ANNs are robust and fault tolerant, hence they can capture capture complete patterns from partial and/or noisy patterns.

\item ANNs can process information in parallel, at high speed and in a distributed manner.

\end{itemize}

\newpage

\section{Artificial Neuron}
\
\
\
\
The artificial neuron is the building block of the ANN. The Fig (\ref{figc8h1}) shows the diagrammatic representation of an artificial neuron.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{ANNImg1}
\caption{Artificial Neuron Model}
\label{figc8h1} %% to refer use, \ref{}
\end{figure}

It consists of the weights one each for the connecting input signals, a summation unit which sums the product of the weight and the incoming input for all inputs and a activation function (which is usually a non-linear function). It also sometimes consist of a bias. The mathematical model of the artificial neuron is described by the following equations:

\begin{equation}
\label{ANN1}

\textit{f}(x_{j})=f \left (\alpha_{j} + \sum\limits_{i=1}^{k}w_{ij}y_{i}  \right )

\end{equation}\\
where,\\
$ \textit{f} $ = It is the activation function of the artificial neuron \\
$ \alpha_{j} $ = It is the bias associated with the $j^{th}$ neuron in the network \\
$ k $ = It is total number of inputs connected to the $j^{th}$ neuron in the network
$ w_{ij} $ = It is weight associated with the connection between the $i^{th}$ input and the $j^{th}$ neuron \\
$ y_{i} $ = It is the $i^{th}$ input connected to the neuron \\
$ \textit{f}(x_{j}) $ = It is the out put of the $j^{th}$ neuron

The Fig (\ref{ANNActFunc}) shows the different activation functions which can be used in the design of the artificial neurons.

\begin{figure}[H]
\begin{center}
\includegraphics[width=.4\textwidth]{ANNImg4}
\includegraphics[width=.4\textwidth]{ANNImg5}
\includegraphics[width=.4\textwidth]{ANNImg6}
\includegraphics[width=.4\textwidth]{ANNImg7}
\end{center}
\caption{Different Activation Functions: Upper Left - Unit Step, Upper Right - Sigmoid, LowerLeft - Piecewise Linear and LowerRight - Gaussian}
\label{ANNActFunc}
\end{figure}

These artificial neurons form the unit processing element s of an artificial neural network. The arrangement (network architectures) of these artificial neurons and its subsequent training leads to development of ANN models which solve real world problems whose principles and data relationships are little or incompletely understood.

\section{ANN Architectures}
\
\
\
\
Neural network architectures are the structures developed by the interconnection of artificial neurons. The two most widely used ANN architectures are: Feed Forward Network and Recurrent Network.

\textbf{Feed Forward Network:}\\

In these networks information flows in one direction i.e from the input layer passing through the hidden layers and finally to the output layer. There are no feedbacks i.e. the output of any layer does not affect the same or the preceding layer. The Fig (\ref{figc8h2}) illustrates a feed forward neural network.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{ANNImg2}
\caption{Schematic of Feed-Forward Network}
\label{figc8h2} %% to refer use, \ref{}
\end{figure}

\textbf{Recurrent Network:}\\

These artificial neural networks consist of feedbacks (atleast one). The possible feedbacks are: feedback between two layers or feedback to a single neuron (self-feedback links). The Fig (\ref{figc8h3}) shows a recurrent neural network where the feedback is provided from the output layer to input layer.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{ANNImg3}
\caption{Artificial Neuron Model}
\label{figc8h3} %% to refer use, \ref{}
\end{figure}

The more specific neural network architesctures used widely for real world problem solving are: Multi-Layer Perceptron Networks (MLP), Radial Bias Function Networks and Kohonen Self Organizing Feature Maps.

\textbf{Multi-Layer Perceptron Network:}\\

It is the most popular form of the ANN architecture. It has the following properties:

\begin{itemize}

\item Has any number of inputs

\item Has one or more hidden layers with any number of units

\item Uses linear combination functions in the input layers

\item Generally uses sigmoid activation functions in the hidden layers

\item Has any number of outputs with any activation function

\item Has connections between the input layer and the first hidden layer, hidden layer and hidden layer, and between hidden layer and output layer

\end{itemize}

The Fig (\ref{figc8h4}) illustrates a Multi-Layer Perceptron Network with a single hidden layer.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{ANN_MLP}
\caption{Multi-Layer Perceptron Architecture}
\label{figc8h4} %% to refer use, \ref{}
\end{figure}

MLP's are known as universal approximators and can  be used when we have little prior knowledge of the relationship between the inputs and the targets. Usually one hidden layer with sufficient number of neurons is enough for creating a good model, but sometimes more hidden layers with less number of neurons can improve generalization.\\

\textbf{Radial Bias Function Network:}\\

A Radial Bias Function Network (RBF) is similar to a MLP but with only one hidden layer. The properties of RBF are as follows:

\begin{itemize}

\item Has any number of inputs

\item Typically has only one hidden layer with any number of units

\item Uses radial combination functions in the hidden layers, based on the squared Euclidean distance between the input vector and the weight vector

\item Typically uses exponential or softmax activation functions in the hidden layer, in which the network is a Gaussian RBF Network

\item Has any number of outputs with any activation function

\item has connections between the input layer and the hidden layer, and between hidden layer and the output layer.

\end{itemize}

The Fig (figc8h5}) illustrates a RBF Network.

\begin{figure}[H]
\centering
\includegraphics[scale=0.25]{ANN_RBF}
\caption{Artificial Neuron Model}
\label{figc8h5} %% to refer use, \ref{}
\end{figure}

Gaussian RBF's are said to be local-processing networks as the  effect of a hidden unit is usually concentrated in a local area centered at the weight vector ; as opposed to the MLP's which are said to be distributed-processing networks as the effect of a hidden unit cn be distributed over the entire input space.\\

\textbf{Kohonen Self Organizing Feature Maps:}\\

These are used quite diffeently from other ANN networks. Most of the ANN networks are designed for supervised learning tasks, but the self organizing Maps (SOFM) are primarily designed for unsupervised learning tasks. They help to lear the structure of data and hence oten very useful for exploratory data analysis of complex data. They care also used for novelty detection. It learns to rcognize clusters in the training data and then respond to them in a fitting manner. A SOFM consists of only two layers: an input layer, and an output layer of radial units. The Fig (\ref{figc8h6}) illustrates a Kohonen (SOFM) network.

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANN_Kohonen}
\caption{Artificial Neuron Model}
\label{figc8h6} %% to refer use, \ref{}
\end{figure}

\section{Training Methods}
\
\
\
\
Learning methods for neural networks can be classified into three basic types, which are given as follows:

\begin{enumerate}

\item \blindtext \textbf{Supervised Learning:} In this learning method every input pattern that is used to train the network is associated with the target or the desired pattern. A teacher is assumed to be present during the learning/training process, when a comparison is made between the network's computed output and the correct expected output, to determine the error. The error can then be used to change the network parameters (weights and biases), which result in an improvement in performance.

\item \blindtext \textbf{Unsupervised Learning:}In this learning method, the target output is not presented to the network. It is as if there is no teacher to present the desired patterns. However, the network leans of its own by discovering and adapting to the structural features in the input patterns.

\item \blindtext \textbf{Reinforced Learning:} In this learning method, a teacher is available, but does not present the expected answer; however only indicates if the computed answer is correct or incorrect. The information provided helps the network in its learning process. A reward is given for a correct answer and a penalty for a wrong answer. But, this learning method is not very popular.

\end{enumerate

\section{ANN Applications}
\
\
\
\
The real world applications of ANN consist of a large spectrum of categories as listed below:

\begin{itemize}

\item Function approximation, or regression analysis, including time series prediction, fitness approximation and modeling

\item Classification, including pattern and sequenxce recognition, novelty detectiona nd sequential decision making

\item Data processing, including filtering, clustering, blind source separation and compression

\end{itemize}

\newpage

\section{Process Flow for Forecasting using ANN}
\
\
\
\
The Fig (\ref{figc8h7}) shows the schematic of the process flow for the development of the ANN model for forecasting.

\begin{figure}[H]
\centering
\includegraphics[scale=0.8]{ANN_Flow}
\caption{Schematic of ANN Model Development for Forecasting}
\label{figc8h7} %% to refer use, \ref{}
\end{figure}

\newpage

\section{Results}
\
\
\
\
The results for generation forecasting using ANN have been produced for the GSEC 1MW SPVP. The training data is of 11 months from November 2014 to September 2015. The ANN models trained on this data have been used to generate intra-hour weather variable forecasts for the month of October 2015. The ANN models have been developed using three different types of input data (Mode1, Mode2 and Mode3) with three different network architectures (Fitnet [FN], Feedforward Net [FF] and Cascaded Feedforward Net [CFF]) and five different hidden network configurations (5-Neurons, 10-Neurons, 15-Neurons, 10-10- Neurons and 10-10-10-neurons). All the results in the subsequent sections are for the $2^{nd}$ of October 2015 for all the modes, architectures and the hidden network configuration. The forecasted weather variables form the ANN models have been fed as inputs to the solar energy estimation app to generate the intra-hour generation forecast.

\subsection{Input Type - Mode1}
\
\
\
\
In Mode1 the Input training matrix consists of the [Day, Month, Year,Time] columns with the Target Training Matrix consisting of the corresponding [Wind Speed, Temperature, Irradiance] columns. The results are given in the following sections which are divided based on the hidden network configurations and each graph consists of the comparison of the actual variable with he forecasted variable from the three different ANN architectures.

\subsubsection{ANN Architecture - Hidden Nodes [5]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne5w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 1 With Network [5]}
\label{ANNResImg1} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne5t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 1 With Network [5]}
\label{ANNResImg2} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne5i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 1 With Network [5]}
\label{ANNResImg3} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne5e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 1 With Network [5]}
\label{ANNResImg4} %% to refer use, \ref{}
\end{figure}

\newpage

\subsubsection{ANN Architecture - Hidden Nodes [10]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 1 With Network [10]}
\label{ANNResImg5} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 1 With Network [10]}
\label{ANNResImg6} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 1 With Network [10]}
\label{ANNResImg7} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 1 With Network [10]}
\label{ANNResImg8} %% to refer use, \ref{}
\end{figure}

\subsubsection{ANN Architecture - Hidden Nodes [15]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne15w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 1 With Network [15]}
\label{ANNResImg9} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne15t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 1 With Network [15]}
\label{ANNResImg10} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne15i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 1 With Network [15]}
\label{ANNResImg11} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne15e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 1 With Network [15]}
\label{ANNResImg12} %% to refer use, \ref{}
\end{figure}

\subsubsection{ANN Architecture - Hidden Nodes [10-10]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10-10w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 1 With Network [10-10]}
\label{ANNResImg13} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10-10t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 1 With Network [10-10]}
\label{ANNResImg14} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10-10i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 1 With Network [10-10]}
\label{ANNResImg15} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10-10e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 1 With Network [10-10]}
\label{ANNResImg16} %% to refer use, \ref{}
\end{figure}

\subsubsection{ANN Architecture - Hidden Nodes [10-10-10]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10-10-10w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 1 With Network [10-10-10]}
\label{ANNResImg17} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10-10-10t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 1 With Network [10-10-10]}
\label{ANNResImg18} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10-10-10i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 1 With Network [10-10-10]}
\label{ANNResImg19} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmOne10-10-10e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 1 With Network [10-10-10]}
\label{ANNResImg20} %% to refer use, \ref{}
\end{figure}

\subsection{Input Type - Mode2}
\
\
\
\
In Mode2 the Input training matrix consists of the [Day, Month, Year,Time] columns with the Target Training Matrix consisting of the corresponding [Wind Speed, Temperature, Irradiance, Previous Wind Speed, Previous Temperature, Previous Irradiance] columns. The results are given in the following sections which are divided based on the hidden network configurations and each graph consists of the comparison of the actual variable with he forecasted variable from the three different ANN architectures.

\subsubsection{ANN Architecture - Hidden Nodes [5]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo5w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 2 With Network [5]}
\label{ANNResImg21} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo5t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 2 With Network [5]}
\label{ANNResImg22} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo5i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 2 With Network [5]}
\label{ANNResImg23} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo5e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 2 With Network [5]}
\label{ANNResImg24} %% to refer use, \ref{}
\end{figure}

\newpage

\subsubsection{ANN Architecture - Hidden Nodes [10]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 2 With Network [10]}
\label{ANNResImg25} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 2 With Network [10]}
\label{ANNResImg26} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 2 With Network [10]}
\label{ANNResImg27} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 2 With Network [10]}
\label{ANNResImg28} %% to refer use, \ref{}
\end{figure}

\subsubsection{ANN Architecture - Hidden Nodes [15]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo15w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 2 With Network [15]}
\label{ANNResImg29} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo15t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 2 With Network [15]}
\label{ANNResImg30} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo15i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 2 With Network [15]}
\label{ANNResImg31} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo15e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 2 With Network [15]}
\label{ANNResImg32} %% to refer use, \ref{}
\end{figure}

\subsubsection{ANN Architecture - Hidden Nodes [10-10]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10-10w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 2 With Network [10-10]}
\label{ANNResImg33} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10-10t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 2 With Network [10-10]}
\label{ANNResImg34} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10-10i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 2 With Network [10-10]}
\label{ANNResImg35} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10-10e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 2 With Network [10-10]}
\label{ANNResImg36} %% to refer use, \ref{}
\end{figure}

\subsubsection{ANN Architecture - Hidden Nodes [10-10-10]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10-10-10w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 2 With Network [10-10-10]}
\label{ANNResImg37} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10-10-10t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 2 With Network [10-10-10]}
\label{ANNResImg38} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10-10-10i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 2 With Network [10-10-10]}
\label{ANNResImg39} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmTwo10-10-10e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 2 With Network [10-10-10]}
\label{ANNResImg40} %% to refer use, \ref{}
\end{figure}

\subsection{Input Type - Mode3}
\
\
\
\
In Mode2 the Input training matrix consists of the [Day, Month, Year,Time] columns with the Target Training Matrix consisting of the corresponding [Wind Speed, Temperature, Irradiance, Previous Wind Speed, Previous Temperature, Previous Irradiance, Rate of Change of Previous Wind Speed, Rate of Change of Previous Temperature, Rate of Change of Previous Irradiance] columns. The results are given in the following sections which are divided based on the hidden network configurations and each graph consists of the comparison of the actual variable with he forecasted variable from the three different ANN architectures.

\subsubsection{ANN Architecture - Hidden Nodes [5]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree5w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 3 With Network [5]}
\label{ANNResImg41} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree5t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 3 With Network [5]}
\label{ANNResImg32} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree5i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 3 With Network [5]}
\label{ANNResImg33} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree5e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 3 With Network [5]}
\label{ANNResImg44} %% to refer use, \ref{}
\end{figure}

\newpage

\subsubsection{ANN Architecture - Hidden Nodes [10]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 3 With Network [10]}
\label{ANNResImg45} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 3 With Network [10]}
\label{ANNResImg46} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 3 With Network [10]}
\label{ANNResImg47} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 3 With Network [10]}
\label{ANNResImg48} %% to refer use, \ref{}
\end{figure}

\subsubsection{ANN Architecture - Hidden Nodes [15]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree15w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 3 With Network [15]}
\label{ANNResImg49} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree15t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 3 With Network [15]}
\label{ANNResImg50} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree15i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 3 With Network [15]}
\label{ANNResImg51} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree15e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 3 With Network [15]}
\label{ANNResImg52} %% to refer use, \ref{}
\end{figure}

\subsubsection{ANN Architecture - Hidden Nodes [10-10]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10-10w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 3 With Network [10-10]}
\label{ANNResImg53} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10-10t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 3 With Network [10-10]}
\label{ANNResImg54} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10-10i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 3 With Network [10-10]}
\label{ANNResImg55} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10-10e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 3 With Network [10-10]}
\label{ANNResImg56} %% to refer use, \ref{}
\end{figure}

\subsubsection{ANN Architecture - Hidden Nodes [10-10-10]}
\
\
\
\

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10-10-10w}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Wind Speed In Mode 3 With Network [10-10-10]}
\label{ANNResImg57} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10-10-10t}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Temperature In Mode 3 With Network [10-10-10]}
\label{ANNResImg58} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10-10-10i}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Irradiance In Mode 3 With Network [10-10-10]}
\label{ANNResImg59} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{ANNmThree10-10-10e}
\caption{Comparison Of Different ANN Architectures (FN,FF,CFF) For Forecasting Of Intra-Hour Energy In Mode 3 With Network [10-10-10]}
\label{ANNResImg60} %% to refer use, \ref{}
\end{figure}

\subsubsection{Conclusion from Graphs}
\
\
\
\
It is observed from the above graphs that as the input training set holds more and more data about the previous states of the weather variables to be forecasted the model learning for one-step ahead generation forecasting becomes better and better even with less complex network architectures. It is seen that the learning and model generalization are better with increasing complexity of the hidden network architecture as deep learning takes place. Moreover, the learning is least affected by the use of the different ANN architectures as FN, FF and CFF all fall in the same family of Multi-Layer Perceptron Models. The use of Radial Bias Functions has to be explored to have a more clear understanding of which ANN architecture is better suite for the job.


% !TEX root = ./Basilisk-Integrators20170724.tex

\section{Test Description and Success Criteria}

As the integrator functionality is not a regular BSK module with specified input/output behavior, the integration can only be tested in an integrated test.
The integrated test employed is located in:\\

{\tt src/tests/scenarios/test\_scenarioIntegrators.py}
\\

\subsection{Test inputs}
Each simulation uses the point-mass spacecraft equations of motion
\begin{equation}
	\ddot{\bm r} = - \frac{\mu}{r^{3}}{\bm r}
\end{equation}
with the initial orbit elements shown in Table~\ref{tbl:oeInitial}.  The only gravitational body considered is Earth.  The simulation time for each case is 3/4 of an orbit period.  Each implemented Integrator method is tested using the above initial conditions and a large time step of 120 seconds.  This large time step makes the integrator errors more easily visible between the integration methods.

\begin{table}[htbp]
	\caption{Initial Spacecraft Ephemeris}
	\label{tbl:oeInitial}
	\centering \fontsize{10}{10}\selectfont
	\begin{tabular}{c | r | r } % Column formatting,
		\hline
		\hline
		Element    & Description & Value \\
		\hline
		$a$      & Semi-Major Axis & 7000km \\
		$e$ & Eccentricity     &  0.0001 \\
		$i$       & Inclination Angle  & 33.3\dg \\
		$\Omega$       & Ascending Node   & 33.3\dg \\
		$\omega$       & Argument of Periapses  & 48.2\dg \\
		$f$       & True Anomaly   & 347.8\dg \\
		\hline
		\hline
	\end{tabular}
\end{table}

\subsection{Test sections}
The same simulation setup is run for each of the integration methods:
\begin{enumerate}
\item The first test uses the default RK4 integration method.  Here the simulation script does not specify the integration method, testing both that the RK4 integrator is the default integration method, and that that the integrator is implemented correctly.

\item The 2nd test uses the Euler's integration method.

\item the 3rd test uses Heun's integration method.

\end{enumerate}

\begin{figure}[t]
	\centerline{
	\includegraphics[]{Figures/intResults}
	}
	\caption{Illustration of the true orbit position samples (Black) versus the RK4 (Blue), RK2 (Green) and RK1 (Red) integration results.}
	\label{fig:intResults}
\end{figure}
The resulting data points are illustrated in Figure~\ref{fig:intResults}.  The large 120 second time step causes all the integration methods to significantly deviate from the truth locations (shown in black).  The integrated validation test ensures that the BSK integrations yield the same integration corruptions to validate the mathematical implementation.

\subsection{Test success criteria}
The integrated position states are checked at 5 even data points along the simulation time again pre-computed truth answers.  These truth answers were generated in Mathematica implementing the same initial conditions, and replicating the integration math.    The accuracy threshold is set to 1 meter, a small value compared to the 7,000,000 meter near-circular orbit radius.

\section{Test Parameters}
Three tests are run controlled through a single test parameter called {\tt integratorCase}.  The possible values are shown in Table~\ref{tbl:intCases}.

\begin{table}[htbp]
	\caption{Error tolerance for each test.}
	\label{tbl:intCases}
	\centering \fontsize{10}{10}\selectfont
	\begin{tabular}{ c | c } % Column formatting,
		\hline\hline
		\textbf{Test}   	      	               & \textbf{Tolerated Error} 						           \\ \hline
		``rk4"                           & 1 meter	  \\
		``euler"                           & 1 meter	  \\
		``rk2"                           & 1 meter	  \\
		\hline\hline
	\end{tabular}
\end{table}

\section{Test Results}
All integration checks within the integrated test {\tt scenarios/test\_scenarioIntegrators.py} passed.  Table~\ref{tbl:intResults} shows the test results, while Figure~\ref{fig:intResultsPython} shows the resulting trajectories for each integration test.

\input{AutoTeX/scenarioIntegrators.tex}

\begin{table}[h]
	\caption{Integration test results.}
	\label{tbl:intResults}
	\centering \fontsize{10}{10}\selectfont
	\begin{tabular}{c | c | p{4in} } % Column formatting,
		\hline\hline
		\textbf{Test} 			& \textbf{Pass/Fail} 	 & \textbf{BSK Error Notes}
		\\ \hline
		``rk4"		  	&
		\input{AutoTex/IntegratorsTestMsg-rk4}      	  &
		\input{AutoTex/IntegratorsMsg-rk4}
		\\ \hline
		``euler''	   	           	&
		\input{AutoTex/IntegratorsTestMsg-euler}           		&
		\input{AutoTex/IntegratorsMsg-euler}
		\\ \hline
		``rk2''      	&
		\input{AutoTex/IntegratorsTestMsg-rk2}
		&
		\input{AutoTex/IntegratorsMsg-rk2}
		\\
		\hline\hline
	\end{tabular}
\end{table}


\section{SSC Cashflow and NPV Models}
\label{sec:SSCNPV}

Imagine a portfolio of candidate projects, in which some of the decisions involve
either replacing an item now or postponing replacement and facing potentially higher
maintenance and replacement costs. We choose to assume that the item must either
be replaced now or in the future, and it is in this context we describe the
appropriate cashflow calculations. We then extend the discussion to allow the
planned replacement to occur in year 2 or 3, for example, rather than in year 1.

We assume that doing nothing is not an option, since the items under consideration
are of significant importance and, if not replaced in due course, would impose
an unacceptable risk to either safety or production.

Notation:

\begin{itemize}
	\item  \( p \) : probability of item failure for one year

	\item  \( C_{P} \) : cost of planned replacement

	\item  \( C_{U} \) : cost of unplanned replacement

	\item  \( C_{D} \) : cost of shutdown per day

	\item  \( D \) : number of days plant is off-line, if a shutdown occurs

	\item  \( N \) : number of years

	\item  \( R \) : discount rate
\end{itemize}

%\begin{comment}
We could incorporate additional parameters, such as weekly or monthly inspection costs,
fixed costs of shutdown in addition to the daily costs specified above, etc. That said,
the setting we describe allows us to illustrate key ideas in the cashflow
calculations for computing NPV.

We further assume that, if we do not replace the item, its failure time is a random
variable that follows a geometric distribution where the probability of failure in
one year is denoted by  \( p \) (i.e., the probability of survival over one year
is  \( 1-p \) ). Thus, if the plant faces a 20-year decision period, the probability
of survival up to year  \( t \) is  \(  \left( 1-p \right) ^{t} \), and the probability
of failing in year  \( t \)  is given by  \( p \left( 1-p \right) ^{t-1} \).

Here is pedantic but useful construct for thinking about the calculations that follow
is to visualize a {\it coin flip}  for each year, yielding a {\it fail}  or {\it no fail}
event for that given year. Immediately after the coin flip, appropriate costs are incurred.
In other words, this discrete view of time with Bernoulli trials is useful to simplify the
logic of the calculations, rather than viewing time as a continuum and teasing
out {\it what happened when} during a given year.

If the item is not replaced today (time  \( t=1 \) ), we can compute the expected
replacement cost in any year  \( t=1, 2, \ldots ,N-1 \)  as:\par

%\begin{comment}

\begin{equation}\label{npv_1}
\mbox{Expected Replacement Cost in Year } t=C_{U}p \left( 1-p \right) ^{t-1}
\end{equation}

Here, we incur this cost only if the coin flips yielded $``$no fail$"$  events in
years  \( t=1, 2, \ldots ,t-1 \), then a $``$fail$"$  event in year  \( t \)
(i.e., we incur the cost through the geometric random variable’s probability mass of having
the first failure in year  \( t \), which is given by  \( p \left( 1-p \right) ^{t-1} \)).

Since we assume the item must be replaced in year  \( N \)  if it has not already failed,
the expected replacement cost does \textit{not} depend on the result of a coin flip
in year  \( N \), in the same way that replacement in year 1 precludes dependence on
the year 1 coin flip. Rather, we incur this cost with certainty in year  \( N \),
as long as the item had not failed in previous years
\(  t=1, 2, \ldots ,N-1 \); In other words, the expected cost is given by:\par

%\begin{comment}

\begin{equation}\label{npv_2}
\mbox{Expected Replacement Cost in Year }N=C_{P} \left( 1-p \right) ^{N-1}
\end{equation}

where the planned replacement cost is used.

In order to illustrate the computation of the cash flows, we further assume that,
if the item is not replaced now, the plant faces a loss of revenue due to a shutdown
at a cost of  \( C_{D} \)  per day. In this case, the expected downtime cost incurred in
year  \( t=1, 2, \ldots ,N-1 \)  is given by:\par

\begin{equation}\label{npv_3}
\mbox{Expected Downtime Cost in Year }t=DC_{D}p \left( 1-p \right) ^{t-1}.
\end{equation}

Again, we assume that the planned replacement in year  \( t=N \)  precludes dependence
on the coin flip and therefore also precludes incurring any downtime cost in that year,
though we acknowledge other assumptions are possible. Thus, for practical purposes,
there is no coin flip in year  \( N. \)

More generally, if the item is not replaced now, the plant will face the possibility
of increased costs due to reliability issues. Such costs include increased
inspection costs, downtime costs for a week-long shutdown, lost revenue from a 6-hour
shutdown, costs associated with the emergency replacement of an item, etc. We can express
the above costs in the following functional form:
\( Re \_ Cost \left( p,t,C_{1},C_{2, \cdots , }C_{M} \right)  \),
where  \( C_{1},C_{2, \cdots, }C_{M} \)  are costs relevant for the considered item, and,
in general,  \( p \)  could be a vector that incorporates multiple types of shutdown. In
our case, the expected downtime cost in year  \( t=1, 2, \ldots ,N \)  is given by a function:
\( Re \_ Cost \left( p,t,C_{P},C_{U},C_{D},D,N \right)  \) , with just a scalar value for  \( p \).

There are two relevant time-series of cash flows: one for replacing the item now and
another for replacing it later, either at failure or at the horizon year  \( N \).
First, consider replacing the item today; in this case, we simply incur the cost of
planned replacement at time  \( t=1 \) (i.e., we incur cost  \( C_{P} \).)

The second time-series of cash flows is for replacing the item in the future.
In this case, for every year  \( t \), we have the expected replacement cost
and downtime cost. So, for any year  \( t=1, 2, \ldots ,N-1 \), the cash
flows will be computed as:\par

\begin{equation}\label{npv_4}
\mbox{Cash Flow Replaced in Year }t= - \left[  \left( C_{U}+DC_{D} \right)  p \left( 1-p \right) ^{t-1} \right]
\end{equation}

and for the final year as:\par

\begin{equation}\label{npv_5}
\mbox{Cash Flow Replaced in Year }N= - \left[ C_{P} \left( 1-p \right) ^{N-1} \right] .
\end{equation}

Note the minus sign in front of the cash flows because all of them are costs
(i.e., cash outflows). The timelines of the two options are illustrated as follows: \par

%%%%%%%%%%%%%%%%%%%% Figure/Image No: 1 starts here %%%%%%%%%%%%%%%%%%%%

\begin{figure}
    \centering
    \centerline{\includegraphics[scale=1]{image1.pdf}}
    \caption{Graphical representation of option 1: replace now.}
    \label{fig:_Graphical_representation_of_option_1_replace_now}
\end{figure}

%%%%%%%%%%%%%%%%%%%% Figure/Image No: 1 Ends here %%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%% Figure/Image No: 2 starts here %%%%%%%%%%%%%%%%%%%%

\begin{figure}
    \centering
    \centerline{\includegraphics[scale=1]{image2.pdf}}
    \caption{Graphical representation of option 2: replace later.}
    \label{fig:_Graphical_representation_of_option_1_replace_later}
\end{figure}

%%%%%%%%%%%%%%%%%%%% Figure/Image No: 2 Ends here %%%%%%%%%%%%%%%%%%%%

The NPV of option 1 is: \par

\begin{equation}\label{npv_6}
\mbox{NPV option 1}= -C_{P}
\end{equation}

The NPV of option 2 is:\par

\begin{equation}\label{npv_7}
\mbox{NPV option }2= - \left[  \sum _{t=1}^{N-1}\frac{ \left( C_{U}+DC_{D} \right) p \left( 1-p \right) ^{t-1}}{ \left( 1+R \right) ^{t-1}}+\frac{C_{P} \left( 1-p \right) ^{N-1}}{ \left( 1+R \right) ^{N-1}} \right]
\end{equation}

We can compare these options in two ways. The first is to simply compute the
NPV as the difference between the NPV of option 1 and that of option 2 (i.e.,
\( \mbox{NPV}=\mbox{NPV option }1-\mbox{NPV option }2 \)). The resulting equation is:\par

\begin{equation}\label{npv_7}
\mbox{NPV}= -C_{P}+ \left[  \sum _{t=1}^{N-1}\frac{ \left( C_{U}+DC_{D} \right) p \left( 1-p \right) ^{t-1}}{ \left( 1+R \right) ^{t-1}}+\frac{C_{P} \left( 1-p \right) ^{N-1}}{ \left( 1+R \right) ^{N-1}} \right]
\end{equation}

If the project in question is the only one under consideration, and if  \( \text{NPV} \)  $>$ 0,
the decision is to replace the item today; otherwise, we replace it later.
%As we discuss in detail in Section 6, we\ employ an optimization model when multiple projects are considered simultaneously, and we need to stay within annual budgets in terms of, for example, capital costs.  \par

We now extend the above logic to the planned replacement occurring in year \( ~T_{0} \).
We had assumed  \( ~T_{0}=1 \), but now we allow for
delaying this planned replacement to a later year, albeit at the risk of incurring
a failure prior to  \( ~T_{0} \), along with associated unplanned\ replacement
and downtime costs.  If the planned replacement happens at time  \( T_{0} \), the
corresponding time-series of cash flows will become as follows: one for replacing the item
either at failure before  \( T_{0} \)  or at  \( T_{0} \),
and another for replacing it later, either at failure or at the horizon year  \( N \).\par

The first time-series of cash flows is for replacing the item at  \( T_{0} \).
In this case, for every year  \( t=1, 2, \ldots, T_{0}-1 \), we have the expected
replacement cost and downtime cost. So, for any year  \( 1, 2,\ldots, T_{0}-1 \),
the cash flows will be computed as:\par

\begin{equation}\label{npv_8}
\mbox{Cash Flow Replaced in Year }t= - \left[  \left( C_{U}+DC_{D} \right)  p \left( 1-p \right) ^{t-1} \right]
\end{equation}

for  \( t=T_{0} \)  the expected cash flow is:\par

\begin{equation}\label{npv_9}
\text{Cash Flow Replaced in Year }T_{0}= - \left[ C_{P} \left( 1-p \right) ^{T_{0}-1} \right]
\end{equation}

The timeline of this option is illustrated as follows: \par

%%%%%%%%%%%%%%%%%%%% Figure/Image No: 3 starts here %%%%%%%%%%%%%%%%%%%%

\begin{figure}
    \centering
    \centerline{\includegraphics[scale=1]{image3.pdf}}
    \caption{Graphical representation of option 1: planned replacement at $T_0$.}
    \label{fig:_Graphical_representation_of_option_1_planned_replacement_at_}
\end{figure}

%%%%%%%%%%%%%%%%%%%% Figure/Image No: 3 Ends here %%%%%%%%%%%%%%%%%%%%

\begin{equation}\label{npv_10}
\mbox{NPV option }1= - \left[  \sum _{t=1}^{T_{0}-1}\frac{ \left( C_{U}+DC_{D} \right) p \left( 1-p \right) ^{t-1}}{ \left( 1+R \right) ^{t-1}}+\frac{C_{P} \left( 1-p \right) ^{T_{0}-1}}{ \left( 1+R \right) ^{T_{0}-1}} \right]
\end{equation}

Note that, if  \( T_{0}=1 \),  then the first term yields zero, and the NPV of
option 1 reduces to that discussed above (i.e., it equals  \( -C_{P} \).)\par

The second time-series of cash flow is for attempting to delay replacement of
the item to time  \( N \), and incurring the risk of unplanned replacement
and downtime in the meantime. It is the same as we calculated before. \par

\begin{equation}\label{npv_11}
\mbox{NPV option }2= - \left[  \sum _{t=1}^{N-1}\frac{ \left( C_{U}+DC_{D} \right) p \left( 1-p \right) ^{t-1}}{ \left( 1+R \right) ^{t-1}}+\frac{C_{P} \left( 1-p \right) ^{N-1}}{ \left( 1+R \right) ^{N-1}} \right]
\end{equation}

We can compute  \( \text{NPV} \)  as:\par

\begin{eqnarray}\label{npv_12}
\mbox{NPV}&=&\mbox{NPV Option }1-\mbox{NPV Option }2\\
&=& \left[  \sum _{t=T_{0}}^{N-1}\frac{ \left( C_{U}+DC_{D} \right) p \left( 1-p \right) ^{t-1}}{ \left( 1+R \right) ^{t-1}}+\frac{C_{P} \left( 1-p \right) ^{N-1}}{ \left( 1+R \right) ^{N-1}}-\frac{C_{P} \left( 1-p \right) ^{T_{0}-1}}{ \left( 1+R \right) ^{T_{0}-1}} \right]
\end{eqnarray}

A new RAVEN \textbf{External Model} with \xmlAttr{subType} \xmlString{LOGOS.IncrementalNPV}
was created to compute the NPV described above.

Example RAVEN Input \xmlNode{ExternalModel} XML:
\begin{lstlisting}[style=XML]
<ExternalModel name="rvi_model" subType="LOGOS.IncrementalNPV">
  <variables>fp,rvi_npv_a,rvi_npv_b</variables>
  <alias variable="rvi_p_failure" type="input">fp</alias>
  <Cp>19.82</Cp>
  <Cu>39.64</Cu>
  <fp>0.05</fp>
  <Cd>1.</Cd>
  <D>30</D>
  <options>
    1, 4
    <output>rvi_npv_a,rvi_npv_b</output>
  </options>
  <discountRate>0.03</discountRate>
  <startTime>2019</startTime>
  <lifetime>20</lifetime>
</ExternalModel>
\end{lstlisting}

In order to use this external model to compute NPV, \xmlString{LOGOS.IncrementalNPV}
should be always used for \xmlAttr{subType}. Except for the common nodes \xmlNode{variables}
and \xmlNode{alias}, this entity accepts the following sub-nodes:
\begin{itemize}
  \item \xmlNode{Cp}, \xmlDesc{float, required parameter}, specifies the cost of planned replacement.
  \item \xmlNode{Cu}, \xmlDesc{float, required parameter}, specifies the cost of unplanned replacement.
  \item \xmlNode{Cd}, \xmlDesc{float, required parameter}, specifies the cost of shutdown per day.
  \item \xmlNode{D}, \xmlDesc{integer, required parameter}, specifies the number of days
  plant is off-line, if a shutdown occurs.
  \item \xmlNode{fp}, \xmlDesc{float, required parameter}, specifies the probability
  of item failure over one year.
  \item \xmlNode{discountRate}, \xmlDesc{float, required parameter}, specifies the discount rate.
  \item \xmlNode{inflation}, \xmlDesc{float, optional parameter}, specifies the inflation rate.
  \default{0.0}
  \item \xmlNode{tax}, \xmlDesc{float, optional parameter}, specifies the tax rate.
  \default{0.0}
  \item \xmlNode{HardSavings}, \xmlDesc{float, optional parameter}, specifies the hard
  savings that would be added to the NPV calculation.
  \default{0.0}
  \item \xmlNode{count}, \xmlDesc{integer, optional parameter}, specifies the number
  of the same items/components that need to be replaced at the same time.
  \default{1.0}
  \item \xmlNode{startTime}, \xmlDesc{integer, required parameter}, specifies the
  start time of project.
  \item \xmlNode{lifetime}, \xmlDesc{integer, required parameter}, specifies the lifetime
  of the project.
  \item \xmlNode{options}, \xmlDesc{optional parameter}, specifies options to compute
  NPVs of planned replacements occurring in different years relative to the start time.
  \begin{itemize}
    \item \xmlNode{Td}, \xmlDesc{comma separated integers, required parameter},
    specifies the lengths of delaying the planned replacement.
    \item \xmlNode{output}, \xmlDesc{comma separated strings, required parameter},
    specifies the output variables corresponding to the different specified lengths of
    delays in \xmlNode{Td}. In order to communicate with RAVEN, these
    variables need to be listed under node \xmlNode{variables}.
    \nb These variables are defined by the user and would be used to store the
    calculated NPVs.
  \end{itemize}
\end{itemize}

The parameters \textbf{Cp, Cu, fp, Cd, inflation, and tax} can be sampled by RAVEN.
If the user specifies these parameters in the input XML \xmlNode{ExternalModel},
the values for these parameters will be replaced by the sampled values from RAVEN.

Example LOGOS Incremental NPV output CSV:
\begin{lstlisting}[language=python]
fp,rvi_npv_a,rvi_npv_b
...
\end{lstlisting}

\nb In order to compute the NPVs, the TEAL plugin is required.
Refer to ~\url{https://github.com/idaholab/raven/wiki/Plugins} for
details on how to access and install the plugins.

The whole calculation flow is depicted in Fig.~\ref{fig:LogosRAVEN}.

%%%%%%%%%%%%%%%%%%%% Figure/Image No: 4 starts here %%%%%%%%%%%%%%%%%%%%

\begin{figure}
    \centering
    \centerline{\includegraphics[scale=0.5]{image11.jpg}}
    \caption{Risk-informed capital budgeting via RAVEN and RAVEN plugins.}
    \label{fig:LogosRAVEN}
\end{figure}

%%%%%%%%%%%%%%%%%%%% Figure/Image No: 4 Ends here %%%%%%%%%%%%%%%%%%%%


% !TeX root = ../main.tex
\section{Conditional Term Rewrite Systems}
In this section, we study some basic notions covering \textit{conditional term rewriting systems}. This type of rewriting was first conceived to reason formally about abstract data types (in the context of algebraic specification). Also, and more important to the study we pretend to carry on, conditional rewriting plays an important role in the integration of functional and logic programming paradigms. The reader is referred to \cite{Ohlebusch:2010:ATT:1965591} (Chapter 7) for most of the statements we just give here without a proof and a more detailed discussion on the subject.

\begin{definition}
    A \textit{conditional term rewriting system} (abbreviated as CTRS) is a pair $(\signature, \trs)$ consisting of a signature $\signature$ and a set $\trs$ of \textit{conditional rewrite rules}. Each of these rewrite rules is of the form $l \contr r \Leftarrow s_1 = t_1, \dots, s_n = t_n$ with $l, r, s_i, t_i \in \terms$, for all $1 \leq i \leq n$. The term $l$ may not be a variable.
\end{definition}

Most of the time we abbreviate the conditional rule $l \contr r \Leftarrow s_1 = t_1, \dots, s_n = t_n$ as just $l \contr r \Leftarrow c$. If a rewrite rule has no conditions, we write $l \contr r$, require $\vars{l} \supseteq \vars{r}$, and call $l \contr r$ an unconditional rewrite rule.

As in \cite{Middeldorp1994}, rewrite rules $l \contr r \Leftarrow c$ will be classified according to their distribution of variables among $l, r$, and $c$, as follows:

\begin{table}[h!]
    \centering
    \begin{tabular}{c | l }
    \cline{1-2}
        Type & Requirement \\
    \hline
    1 & $\vars{r} \cup \vars{c} \subseteq \vars{l}$\\
    2 & $\vars{r} \subseteq  \vars{l}$ \\
    3 & $\vars{r} \subseteq \vars{l} \cup \vars{c}$ \\
    4 & No restrictions
    \end{tabular}
\end{table}

\begin{definition}
    For every CTRS $(\signature,\trs)$ we associate the system $(\signature, \trs_u)$, where
    $$\trs_u := \{ l \contr r \mid l \contr r \Leftarrow c \in \trs \} $$
\end{definition}

We can interpret $=$ in the rules of a conditional term in different ways, which leads to different rewrite relations.

\begin{definition}
    \begin{enumerate}
        \item In an \textit{oriented} CTRS $(\signature, \trs)$ the $=$ symbol in the conditions of the rewrite rules is interpreted as \textit{reachability}, i.e. $l \contr r \Leftarrow s_1 \contr t_1, \dots, s_n \contr t_n$.
        \item A \textit{normal} CTRS $(\signature, \trs)$ is an oriented CRTS in which the rewrite rules are subjected to the additional constraint that every $t_j$ is a ground normal form with respect to $\trs_u$. This rewrite rules will also be written as $l \contr r \Leftarrow s_1 \contr t_1, \dots, s_n \contr t_n$.
        \item In a \textit{join} CTRS $(\signature, \trs)$ the $=$ symbol in the conditions of the rewrite rules is interpreted as \textit{joinability}. Rewrite rules of a join CTRS will be written as $l \contr r \Leftarrow s_1 \downarrow t_1, \dots, s_n \downarrow t_n$.
        \item Interpreting the $=$ symbol in the conditions as \textit{conversion} leads to semiequational CTRSs.
    \end{enumerate}
\end{definition}

From now on we just consider \textit{oriented} CTRSs. Let us formally define the rewrite relation induced by this type of CTRS.
\begin{definition}
    Let $\trs$ be a CTRS. We inductively define \textit{unconditional} TRSs $\trs_n$ for $n \in \mathbb{N}$ by:
    \begin{align*}
        \trs_0 &= \emptyset \\
        \trs_{n+1} &= \{ l\sigma \contr r\sigma \mid l \contr r \Leftarrow s_1 \contr t_1, \dots, s_n \contr t_n \in \trs \text{ and } \\
        &s_j\sigma \contr_{\trs_n}^* t_j \sigma \text{ for all } j \in \{ 1, \dots, n \} \}
    \end{align*}
\end{definition}

The rewrite relation associated with a CTRS $\trs$ is defined by:
\begin{displaymath}
    \contr_\trs :=  \bigcup\limits_{n \in \mathbb{N}} \contr_{\trs_n}
\end{displaymath}

We say that $s \contr_{\trs_{n+1}} t$ iff there exists a rewrite rule $\rho : l \contr r \Leftarrow s_1 \contr t_1, \dots, s_n \contr t_n$ in $\trs$, a substitution $\sigma$, a position $p \in \pos{s}$ such that $\restr{s}{p} = l \sigma$ and $t = s[r\sigma]_p$, and $s_j \sigma \stc_{\trs_n} t_j \sigma$ for all $1 \leq j \leq n$. We say that $s \contr_\trs t$ is a rewrite step or reduction step using $\trs$ at the redex $l\sigma$. We also omits the subscript $\trs$ when $\trs$ is meaningful.

The depth of a rewrite step $s \contr t$ is the least $n$ such that $s \contr_{\trs_n} t$. This notion also extends to reduction sequences $s \stc t$.

In order to work on conditional narrowing later we define the following notion.
\begin{definition}\label{definition:ctrs-approximation-rewrite-relation}
    Let $(\signature, \trs)$ be a join CTRS.We assume that $eq$ and $true$ are function symbols that do not occur in $\sigma$. For every rewrite rule $\rho: l \contr r \Leftarrow s_1 \downarrow t_1, \dots, s_n \downarrow t_n$ in $\trs$, we define:
    $$n(\rho) := eq(s_1, t_1) \contr true, \dots, eq(s_n, t_n) \contr true$$
    Then define $$n(\trs) = \{ eq(x,x) \contr true \} \cup \bigcup\limits_{\rho \in \trs} \{ n(\rho) \}.$$
\end{definition}
Note that $n(\trs)$ is a normal CTRS. We will use it later on to define conditional narrowing.


%!TEX root = ../main.tex
\documentclass[../main.tex]{subfiles}
\begin{document}

\subsection{Derivation of the Optimal Task Choice} \label{app:derive_lmb_opt}
I start from the first order condition of the utility maximization:

\begin{equation}
	\frac{\partial u_{i, t}(b_i, \lambda_{i,t}, \phi, \theta, \tilde{w}_{i,t})}{\partial \lambda_{i,t}} = \tilde{w}_{i,t} + 2 \phi \theta \frac{(|b_i - \lambda_{i,t}|)^\phi}{b_i - \lambda_{i,t}} \overset{!}{=} 0 \tag{\ref{eq:first_derivative}}
\end{equation}
Defining $x \equiv b_i - \lambda_{i,t}$, this can be restated as follows.

\begin{alignat*}{3}
	{}					&& \tilde{w}_t + 2 \phi \theta \frac{(|x|)^\phi}{x} 	&\overset{!}{=} 0 \\
	\Leftrightarrow 	&& \frac{(|x|)^\phi}{x} 								&= - \frac{\tilde{w}_t}{2 \phi \theta} \label{eq:foc_restated} \\
\end{alignat*}
The absolute value function for any real number $x$ is defined as follows.

\begin{equation}
	|x| = \left\{
		\begin{array}{ll}
			x, \: & \: \text{if $x \geq 0$} \nonumber\\
			-x, \: & \: \text{if $x < 0$} \nonumber\\
		\end{array}
	\right.
\end{equation}
Using this definition, two cases can be distinguished when solving for the optimal task choice $\lambda^*_{i,t}$. \\

Case (1): $x \geq 0$ (i.e., $b_i \geq \lambda_{i,t}$).

\begin{alignat*}{3}
	{}				&& \frac{x^\phi}{x} 	&= - \frac{\tilde{w}_{i,t}}{2 \phi \theta} \\
	\Leftrightarrow && x					&= (- \frac{\tilde{w}_{i,t}}{2 \phi \theta})^{\frac{1}{\phi-1}}, \text{with $x = b_i - \lambda_{i,t}$} \\
	\Leftrightarrow && \lambda^*_{i,t} 		&= b_i - (- \frac{\tilde{w}_{i,t}}{2 \phi \theta})^{\frac{1}{\phi-1}}
\end{alignat*}

Case (2): $x < 0 $ (i.e., $b_i < \lambda_{i,t}$).

\begin{alignat*}{3}
	{}				&& \frac{(-x)^\phi}{x} 					&= - \frac{\tilde{w}_{i,t}}{2 \phi \theta} \\
	\Leftrightarrow && \frac{(-x)^\phi}{-x} 				&= \frac{\tilde{w}_{i,t}}{2 \phi \theta} \\
	\Leftrightarrow && - x 									&= (\frac{\tilde{w}_{i,t}}{2 \phi \theta})^\frac{1}{\phi-1}, \text{with $x = b_i - \lambda_{i,t}$} \\
	\Leftrightarrow && \lambda^*_{i,t}						&= b_i + (\frac{\tilde{w}_{i,t}}{2 \phi \theta})^\frac{1}{\phi-1} \\
\end{alignat*}
Which can be rearranged to the expression in equation (\ref{eq:lmb_opt}):
\begin{equation} \tag{\ref{eq:lmb_opt}}
	\lambda^*_{i,t} = \left\{
	\begin{array}{ll}
		b_i - (\frac{- \tilde{w}_{i,t}}{2 \phi \theta})^{\frac{1}{\phi -1}}, \: & \: \text{if $b_i \geq \lambda_{i,t}$}\\
		b_i + (\frac{\tilde{w}_{i,t}}{2 \phi \theta})^{\frac{1}{\phi - 1}}, \: & \: \text{if $b_i < \lambda_{i,t}$}
	\end{array}
\right.
\end{equation}
\end{document}