\documentclass[11pt, a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\usetikzlibrary{shapes}
\usepackage{multirow}
\usepackage{commath}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{placeins}

\begin{document}

\title{DECISION TREES}
\date{}
\maketitle

One of the most widely used and effective learning method to approximate discrete valued target functions.

\section{Algorithm}

\begin{enumerate}
	\item Use a heuristic to select an attribute for the root node.
	\item Create branches for each possible value of the attribute.
	\item Split the instances having a particular attribute value to the corresponding branch's node.
	\item Repeat recursively for each branch and stop recursion for a branch if all instances have the same class.
\end{enumerate}

\section{Attribute Selection Heuristic}

Prefer attribute which splits the data into purest successor nodes. Entropy is such a measure of disorder. For a set of items belonging to two classes positive and negative,

\begin{align*}
	\mathbf{E}(p, n) = -\frac{p}{p + n} \times log_2(\frac{p}{p + n}) -\frac{n}{p + n} \times log_2(\frac{n}{p + n})
\end{align*}

\begin{figure}
	\centering
	\resizebox{20em}{10em}{
		\begin{tikzpicture}
			\draw[step = 0.2 cm, gray, very thin] (0, 0) grid ( 1, 1);
			\datavisualization [school book axes,
				visualize as smooth line,
				y axis={label={$y=\mathbf{E}(p, n)$}},
			x axis={label={$x=\frac{p}{p + n}$}} ]

			data [format=function] {
				var x : interval [0.001:1] samples 100;
				func y = -\value x * log2(\value x) - (1 -\value x) * log2(1 -\value x);
			};
		\end{tikzpicture}
	}
	\caption{Entropy in two class distribution}
\end{figure}

Generally for $n$ classes,

\begin{align*}
	\mathbf{E}(S) = \mathbf{E}(p_1,\ p2,\ ...,\ p_n) = -\sum_{i=1}^{n} p_i \times log_2(p_i) \\
	                                                                               \\
\end{align*}

Entropy only calculates the quality of a single split sub-set. To calculate the quality of the entire split over the attribute $A$,

\begin{align*}
	\mathbf{Gain}(S, A) = \mathbf{E}(S) -\sum_i \frac{\abs{S_i}}{\abs{S}} \times \mathbf{E}(S_i)
\end{align*}

The attribute that maximizes the information gain is selected.

\section{Example}

\begin{table}[h!]
	\centering
	\caption{Training data}
	\label{tab:table1}
	\begin{tabular}{c|cccc|c}
		\toprule
		\textbf{Sr.} & \textbf{Outlook} & \textbf{Temperature} & \textbf{Humidity} & \textbf{Windy} & \textbf{PlayGolf} \\
		\midrule
		1            & Sunny            & Hot                  & High              & False          & No                \\
		2            & Sunny            & Hot                  & High              & True           & No                \\
		3            & Overcast         & Hot                  & High              & False          & Yes               \\
		4            & Rainy            & Cool                 & Normal            & False          & Yes               \\
		5            & Overcast         & Cool                 & Normal            & True           & Yes               \\
		6            & Sunny            & Mild                 & High              & False          & No                \\
		7            & Sunny            & Cool                 & Normal            & False          & Yes               \\
		8            & Rainy            & Mild                 & Normal            & False          & Yes               \\
		9            & Sunny            & Mild                 & Normal            & True           & Yes               \\
		10           & Overcast         & Mild                 & High              & True           & Yes               \\
		11           & Overcast         & Hot                  & Normal            & False          & Yes               \\
		12           & Rainy            & Mild                 & High              & True           & No                \\
		13           & Rainy            & Cool                 & Normal            & True           & No                \\
		14           & Rainy            & Mild                 & High              & False          & Yes               \\
		\bottomrule
	\end{tabular}
\end{table}
~\\
All four attributes - \textbf{Outlook}, \textbf{Temperature}, \textbf{Humidity} and \textbf{Windy} are candidates for evaluation to choose the best splitting attribute.
~\\

\begin{align*}
	\textbf{E}(S) & = -\frac{9}{14}\times log2(\frac{9}{14}) - \frac{5}{14} \times log2(\frac{5}{14}) \\
	              & = 0.940\ \textbf{bits}
\end{align*}

\subsection*{Outlook Gain}

\FloatBarrier
\begin{table}[h]
	\centering
	\label{tab:table2}
	\begin{tabular}{c|cc|c|c}
		\toprule
		\textbf{Outlook}        & \textbf{Yes} & \textbf{No} & \textbf{Split\ Entropy}                                                              & \textbf{Split Weight} \\
		\midrule
		\rule{0pt}{1ex}Rainy    & 3            & 2           & $-\frac{3}{5}\times log_2(\frac{3}{5})-\frac{2}{5}\times log_2(\frac{2}{5}) = 0.971$ & $\frac{5}{14}$        \\ [1ex]

		\rule{0pt}{1ex}Overcast & 4            & 0           & $-\frac{4}{4}\times log_2(\frac{4}{4})-\frac{0}{4}\times log_2(\frac{0}{4}) = 0$     & $\frac{4}{14}$        \\ [1ex]

		\rule{0pt}{1ex}Sunny    & 2            & 3           & $-\frac{2}{5}\times log_2(\frac{2}{5})-\frac{3}{5}\times log_2(\frac{3}{5}) = 0.971$ & $\frac{5}{14}$        \\ [1ex]

	\end{tabular}
\end{table}

\begin{align*}
	\textbf{Gain}(S, Outlook) & = \mathbf{E}(S) - (\frac{5}{14}\times 0.971 + \frac{4}{14} \times 0 + \frac{5}{14} \times 0.971) \\
	                          & = 0.940 - 0.694                                                                                \\
	                          & = 0.246\ \textbf{bits}                                                                           \\
\end{align*}

\subsection*{Temperature Gain}

\FloatBarrier
\begin{table}[h]
	\centering
	\label{tab:table3}
	\begin{tabular}{c|cc|c|c}
		\toprule
		\textbf{Temperature} & \textbf{Yes} & \textbf{No} & \textbf{Split\ Entropy}                                                              & \textbf{Split Weight} \\
		\midrule
		\rule{0pt}{1ex}Cool  & 3            & 1           & $-\frac{3}{4}\times log_2(\frac{3}{4})-\frac{1}{4}\times log_2(\frac{1}{4}) = 0.811$ & $\frac{4}{14}$        \\ [1ex]

		\rule{0pt}{1ex}Hot   & 2            & 2           & $-\frac{2}{4}\times log_2(\frac{2}{4})-\frac{2}{4}\times log_2(\frac{2}{4}) = 1$     & $\frac{4}{14}$        \\ [1ex]

		\rule{0pt}{1ex}Mild  & 4            & 2           & $-\frac{4}{6}\times log_2(\frac{4}{6})-\frac{2}{6}\times log_2(\frac{2}{6}) = 0.918$ & $\frac{6}{14}$        \\ [1ex]

	\end{tabular}
\end{table}

\begin{align*}
	\textbf{Gain}(S, Temperature) & = \mathbf{E}(S) - (\frac{4}{14}\times 0.811 + \frac{4}{14} \times 1 + \frac{6}{14} \times 0.918) \\
	                              & = 0.940 - 0.911                                                                                \\
	                              & = 0.029\ \textbf{bits}                                                                           \\
\end{align*}

\subsection*{Humidity Gain}

\FloatBarrier\clearpage
\begin{table}[h]
	\centering
	\label{tab:table4}
	\begin{tabular}{c|cc|c|c}
		\toprule
		\textbf{Humidity}     & \textbf{Yes} & \textbf{No} & \textbf{Split\ Entropy}                                                              & \textbf{Split Weight} \\
		\midrule
		\rule{0pt}{1ex}High   & 3            & 4           & $-\frac{3}{7}\times log_2(\frac{3}{7})-\frac{4}{7}\times log_2(\frac{4}{7}) = 0.985$ & $\frac{7}{14}$        \\ [1ex]

		\rule{0pt}{1ex}Normal & 6            & 1           & $-\frac{6}{7}\times log_2(\frac{6}{7})-\frac{1}{7}\times log_2(\frac{1}{7}) = 0.592$ & $\frac{7}{14}$        \\ [1ex]

	\end{tabular}
\end{table}

\begin{align*}
	\textbf{Gain}(S, Humidity) & = \mathbf{E}(S) - (\frac{7}{14}\times 0.985 + \frac{7}{14} \times 0.592) \\
	                           & = 0.940 - 0.789                                                          \\
	                           & = 0.151\ \textbf{bits}                                                   \\
\end{align*}

\subsection*{Windy Gain}

\FloatBarrier
\begin{table}[h]
	\centering
	\label{tab:table5}
	\begin{tabular}{c|cc|c|c}
		\toprule
		\textbf{Windy}       & \textbf{Yes} & \textbf{No} & \textbf{Split\ Entropy}                                                              & \textbf{Split Weight} \\
		\midrule
		\rule{0pt}{1ex}False & 6            & 2           & $-\frac{6}{8}\times log_2(\frac{6}{8})-\frac{2}{8}\times log_2(\frac{2}{8}) = 0.811$ & $\frac{8}{14}$        \\ [1ex]

		\rule{0pt}{1ex}True  & 3            & 3           & $-\frac{3}{6}\times log_2(\frac{3}{6})-\frac{3}{6}\times log_2(\frac{3}{6}) = 1$     & $\frac{6}{14}$        \\ [1ex]

	\end{tabular}
\end{table}

\begin{align*}
	\textbf{Gain}(S, Windy) & = \mathbf{E}(S) - (\frac{8}{14}\times 0.811 + \frac{6}{14} \times 1) \\
	                        & = 0.940 - 0.892                                                      \\
	                        & = 0.048\ \textbf{bits}                                               \\
\end{align*}

Since $\textbf{Gain}(S, Outlook)$ represents the highest information gain, the root is split by \textbf{Outlook} as visualized below.

\FloatBarrier
\begin{figure}
	\centering
	\begin{tikzpicture}[scale = 3]

		\node (v0) at (0,0) [shape=ellipse, draw] {\begin{tabular}{c} \textbf{Outlook} \\ 9 Yes, 5 No\end{tabular}};
		\node (v1) at (210 : 1.80)[shape=ellipse, draw] {3 Yes, 2 No};
		\node (v2) at (270 : 1)[shape=ellipse, draw] {4 Yes, 0 No};
		\node (v3) at (330 : 1.70)[shape=ellipse, draw] {2 Yes, 3 No};

		\draw
		(v0) -- (v1) node[draw=none,fill=none, midway, left] {Rainy};
		\draw
		(v0) -- (v2) node[draw=none,fill=none, midway, left] {Overcast};
		\draw
		(v0) -- (v3) node[draw=none,fill=none, midway, left] {Sunny};
	\end{tikzpicture}
\end{figure}

\FloatBarrier
\section{Gain Ratio}

Information gain favours attributes with many values over those with few values. If an attribute is highly branching, the splits generally tend to be small and heterogeneous causing the split entropies to be close to zero and thus resulting in very high information gain.

To avoid this difficulty, information gain is divided by a quantity called intrinsic information that is sensitive to highly branching attribues to give the gain ratio which is maximized instead.

\begin{align*}
	\textbf{IntrinsicInfo}(S, A) & = \sum_{i} \frac{|S_i|}{|S|} \times log_2(\frac{|S_i|}{|S|}) \\
	\textbf{GainRatio}(S, A)     & = \frac{\textbf{Gain}(S, A)}{\textbf{IntrinsicInfo}(S, A)}
\end{align*}
\section{Refinements}

\subsection{Continuous Attributes}

For a continuous attribute $\textbf{A}$, define a boolean attribute $\textbf{A}_c$ which is $True$ if $\textbf{A} < c$ and $False$ otherwise. To pick the optimal value of the threshold $c$ that maximizes the information gain, values of $\textbf{A}$ are sorted and candidate thresholds are generated midway of each consecutive pair.

\begin{table}[h]
	\centering
	\begin{tabular}{c|cccccc}
		\toprule
		\textbf{Temperature} & 40 & 48 & 60  & 72  & 80  & 90 \\
		\midrule
		\textbf{PlayGolf}    & No & No & Yes & Yes & Yes & No \\
	\end{tabular}
\end{table}

Candidate thresholds and their information gain is computed as below. It is clear from the table below that $\textbf{Temperature} = 54$ is the optimal value for the threshold $c$.

\FloatBarrier
\begin{table}
	\centering
	\begin{tabular}{ |c|c|c|c| }
		\hline
		\textbf{Split} & \textbf{Yes} & \textbf{No} & \textbf{Gain}                     \\
		\hline
		$< 44$         & 0            & 1           & \multirow{2}{*}{0.191}            \\
		$>= 44$        & 3            & 2           &                                   \\
		\hline
		$< 54$         & 0            & 2           & \multirow{2}{*}{$\mathbf{0.459}$} \\
		$>= 54$        & 3            & 1           &                                   \\
		\hline
		$< 66$         & 1            & 2           & \multirow{2}{*}{0.082}            \\
		$>= 66$        & 2            & 1           &                                   \\
		\hline
		$< 76$         & 2            & 2           & \multirow{2}{*}{0}                \\
		$>= 76$        & 1            & 1           &                                   \\
		\hline
		$< 85$         & 3            & 2           & \multirow{2}{*}{0.191}            \\
		$>= 85$        & 0            & 1           &                                   \\
		\hline
	\end{tabular}
\end{table}

\FloatBarrier\clearpage

\subsection{Overfitting}

A hypothesis is said to overfit the training data if it performs very accurately on the training data but fares poorly on unseen test data. Two major approaches to avoid overfitting in decision tree learning are as follows:

\begin{itemize}
	\item Stop growing the tree before it starts to overfit.
	\item Grow tree fully but post prune it.
\end{itemize}

\subsubsection{Reduced Error Pruning}
Data is divided into training and validation sets. The training set is used to form the decision tree. Now, each decision node is considered for pruning.

Pruning a decision tree consists of removing the subtree rooted at that node, making it a leaf node, and assigning it the most common classification of the training examples affiliated with that node. Nodes are removed only if the resulting tree performs no worse than the original tree over the validation set.

Nodes are pruned iteratively, always choosing the node whose removal most increases the accuracy over the validation set. Pruning continues until further removal of nodes is harmful.

In case of limited data, the prospects of this pruning scheme are relatively dim.

\subsubsection{Rule Post Pruning}

\begin{enumerate}
	\item Infer the decision tree from the training set allowing overfitting.
	\item Convert tree into equivalent set of rules by creating one rule per one path from root to a leaf node.
	\item Prune each rule by removing any preconditions that results in improving its estimated accuracy on the validation set. If a rule is of the form
	      \begin{align*}
	      	  & IF\ (\textbf{Outlook}=Sunny)\wedge(\textbf{Humidity}=High) \\
	      	  & THEN\ \textbf{PlayGolf} = No
	      \end{align*}
	      then $(\textbf{Outlook}=Sunny)$ and $(\textbf{Humidity}=High)$ are preconditions.
	\item Sort the pruned rules by their estimated accuracy, and consider them in this sequence when classifying subsequent instances.
\end{enumerate}

\subsection{Missing Attributes Values}

\FloatBarrier\clearpage
\begin{figure}
	\centering
	\begin{tikzpicture}[scale = 3]

		\node (v0) at (0,0) [shape=ellipse, draw] {\begin{tabular}{c}
			14 instances \\
			6 \textbf{Windy} = True \\
			7 \textbf{Windy} = False \\
			1 \textbf{Windy} = Unknown \\
			\end{tabular}};
		\node (v1) at (220 : 1.60)[shape=ellipse, draw] {$6 + \frac{6}{13}$ instances};
		\node (v2) at (320 : 1.60)[shape=ellipse, draw] {$7 + \frac{7}{13}$ instances};

		\draw
		(v0) -- (v1) node[draw=none,fill=none, midway, left] {True};
		\draw
		(v0) -- (v2) node[draw=none,fill=none, midway, left] {False};
	\end{tikzpicture}
\end{figure}

\subsection{Attribute With Differing Costs}
Instead of maximizing information gain ratio, a quantity like $\frac{f(\textbf{Gain}(S, A))}{g(\textbf{Cost}(S, A))}$ is maximized where $f$ and $g$ are chosen on a case by case basis.

\section{Comments}

\begin{itemize}
	\item Decision trees provide a practical method for concept learning and for learning other discrete-valued functions.
	\item A complete hyphothesis space is searched because the space of decision trees can represent any dicsrete-valued function defined over discrete valued instances. It therby avoids major difficulty associated with approaches that consider only restricted sets of hypothesis.
\end{itemize}

\end{document}


\documentclass{article}
\usepackage[utf8]{inputenc}

\title{Principal Component Analysis (PCA)}
\author{Tara Mirmira }
\date{July 2017}

\usepackage{natbib}
\usepackage{graphicx}
\usepackage{amsmath}

\begin{document}

\maketitle

\section{Problem}
We want to build a linear model for the variable $\boldsymbol{y}$ using the explanatory variables $\boldsymbol{x_1}, \ldots, \boldsymbol{x_p}$. The coefficient for the explanatory variable $x_j$ is $\hat{\boldsymbol{\beta_j}}$. The standard error for the coefficient is:
$$
SE(\hat{\boldsymbol{\beta_j}}) = \dfrac{1}{\sqrt{1 - {R_j}^2}}\dfrac{\sigma}{\sqrt{\sum_{i=1}^n (x_{ji} - \overline{x_j})^2}}
$$
where
\begin{itemize}
    \item $R$ is the multiple correlation coefficient from regressing $\boldsymbol{x_j}$ on the other explanatory variables $\boldsymbol{x_1}, \ldots, \boldsymbol{x_{j-1}}, \boldsymbol{x_{j+1}}, \ldots, \boldsymbol{x_p}$
    \item $n$ is the number of observations in the data set
    \item $\sigma$ is the standard deviation of the residuals from fitting the full model to the data
    \item $Var(x_{ji}) = \frac{1}{n-1}\sum_{i=1}^n (x_{ji} - \overline{x_j})^2$ so $\sum_{i=1}^n (x_{ji} - \overline{x_j})^2 = (n-1)*Var(x_{ji})$
\end{itemize}

If the explanatory variables are collinear, the fit from regressing $\boldsymbol{x_j}$ on the other explanatory variables improves, which means $R_j$ becomes larger. When $R_j$ increases, the term $\frac{1}{\sqrt{1-{R_j}^2}}$, also called the Variance Inflation Factor (VIF), increases so $SE(\hat{\boldsymbol{\beta_j}})$ increases. As the variance of the coefficients increases, the the coefficients become unstable, meaning they can vary greatly. In the most extreme case where one explanatory variable is perfectly collinear with another, there is no unique solution $\boldsymbol{\hat{\beta}}$ for the coefficients.

\section{Solution}

To remedy the problem described above, we will try to find a new set of vectors $\boldsymbol{W} = \{\boldsymbol{w_1}, \ldots, \boldsymbol{w_p}\}$ that spans the same vector space as the columns of the design matrix $\boldsymbol{X}$. Recall that
$$
\boldsymbol{X} = \begin{bmatrix}
    \boldsymbol{1}       & \boldsymbol{x_1} & \dots & \boldsymbol{x_p}
\end{bmatrix}
$$

\noindent We will replace the design matrix $\boldsymbol{X}$ with $\boldsymbol{W}$ to build the model. The $\boldsymbol{w_i} \in \boldsymbol{W}$ are called principal components. There are two special features about the vectors in $\boldsymbol{W}$:
\begin{itemize}
    \item The vectors are orthogonal
    \item The vectors are in order of decreasing variance for their respective coefficient. This means:
    \begin{itemize}
        \item The coefficient for $\boldsymbol{w_1}$ has the greatest variance
        \item The coefficient for $\boldsymbol{w_p}$ has the smallest variance
    \end{itemize}
\end{itemize}

\begin{figure}[hbtp]
        \centering
        \includegraphics[width=4.5in]{pca.png}
        \caption{principal Components Diagram}
        \label{Newton Raphson}
    \end{figure}

\noindent In the above picture, we can see that the two principal components are orthogonal. The first component, PC1, covers more spread, showing that PC1 has the greatest variability. In two dimensions, PC1 is the major axis of an ellipse and PC2 is the minor axis.

\section{How to Find $\boldsymbol{W}$}

Note: the method described here is not efficient for data with many explanatory variables (large $p$).

\begin{enumerate}
    \item Standardize the data.
    $$
    \boldsymbol{X} =
    \begin{bmatrix}
    \boldsymbol{x_1} & \dots & \boldsymbol{x_p}
\end{bmatrix} \rightarrow
\boldsymbol{Z} =
    \begin{bmatrix}
    \boldsymbol{z_1} & \dots & \boldsymbol{z_p}
\end{bmatrix}
    $$

    $$
    \text{where } \boldsymbol{z_i} = \frac{\boldsymbol{x_i} - \overline{x_i}\boldsymbol{1}}{SD(x_i)\boldsymbol{1}} \text{and} SD(x_i) = \sqrt{\frac{1}{n-1}\sum_{j=1}^n (x_ij - \overline{x_i})^2}
    $$

   If the original data had variances that are very different, we will lean towards including the variables with larger variances in the first few principal components. To eliminate this effect, the data should first be standardized.

   \item Find a new set of basis vectors for $span\{\boldsymbol{z_1}, \ldots, \boldsymbol{z_p}\}$

    The first principal component $\boldsymbol{w_1}$ can be written as a linear combination of the $\boldsymbol{z_i}'s$.
    $$
    \boldsymbol{w_1} = a_{11}\boldsymbol{z_1} + a_{12}\boldsymbol{z_2} + \ldots + a_{1p}\boldsymbol{z_p}
    $$

    \noindent We want to find the $a_{1i}'s$ such that $Var(\boldsymbol{w_1})$ is the greatest of all the $\boldsymbol{w_i}'s$.\\

    $\overline{\boldsymbol{w_1}} = 0$ because all the $\boldsymbol{z_i}'s$ have mean $0$ since they have been standardized\\

    $$Var(\boldsymbol{w_1}) = \frac{1}{n-1}\sum_{i=1}^n (w_{1i} - \overline{\boldsymbol{w_1}})^2 = \frac{1}{n-1}\sum_{i=1}^n w_{1i}^2 = \frac{1}{n-1}\boldsymbol{w_1^T w_1}$$

Calculations:

$$
\boldsymbol{Z^T}\boldsymbol{Z} =
\begin{bmatrix}
\sum z_{1i}^2 & \sum z_{1i}z_2i & \ldots \\
\sum z_{2i}z_{1i} & \sum z_{2i}^2 & \ldots \\
\vdots & \vdots & \ddots \\
\end{bmatrix}
$$

$\sum z_{1i}^2 = \dfrac{\sum (x_{1i} - \overline{x_1})^2}{s_1^2}$ \\

$\frac{1}{n-1}\sum z_{1i}^2 = \frac{1}{n-1}\dfrac{\sum (x_{1i} - \overline{x_1})^2}{s_1^2} = 1$ because $\boldsymbol{z_1}$ is standardized $\boldsymbol{x_1}$

Using the above calculation:

$$
\frac{1}{n-1}\boldsymbol{Z^T}\boldsymbol{Z} =
\begin{bmatrix}
1 & r_{12} & \ldots & r_{1p}\\
r_{21} & 1 & \ldots & r_{2p}\\
\vdots & \vdots & \ddots \\
r_{p1} & r_{p2} & \ldots & 1 \\
\end{bmatrix} = \boldsymbol{R_{xx}} \text{ (the correlations of the $\boldsymbol{x_i}'s$)}
$$

where $$r_{ij} = \frac{1}{n-1}\sum_{k=1}^n \frac{z_{ik} - \overline{z_i}}{SD(z_i)}\frac{z_{jk} - \overline{z_j}}{SD(z_j)} = \frac{1}{n-1}\sum_{k=1}^n \frac{z_{ik} - 0}{1}\frac{z_{jk} - 0}{1} = \frac{1}{n-1}\sum_{k=1}^n z_{ik}z_{jk}$$ is the correlation coefficient between $\boldsymbol{z_i}$ and $\boldsymbol{z_j}$\\

\noindent Note that $\boldsymbol{R_{xx}}$ is also the Variance-Covariance matrix for the matrix $\boldsymbol{Z}$.
\\\\
$
\max_{\boldsymbol{a_1}} (\boldsymbol{a_1}^t\boldsymbol{R_{xx}}\boldsymbol{a_1}) \text{ where } \boldsymbol{a_1}^t\boldsymbol{a_1} = 1 \quad (1)
$
\\\\
\noindent We include the constraint $\boldsymbol{a_1}^t\boldsymbol{a_1} = 1$ so that when taking the maximum with respect to $\boldsymbol{a_1}$, $\boldsymbol{a_1}$ does not increase to infinity.\\\\

\noindent Equation $(1)$ above is equivalent to:\\\\

$\max_{\boldsymbol{a_1}, \lambda} \boldsymbol{a_1}^t\boldsymbol{R_{xx}}\boldsymbol{a_1} - \lambda(\boldsymbol{a_1}^t\boldsymbol{a_1} - 1)$\\\\

\noindent Taking the derivative with respect to $\boldsymbol{a_1}$:\\\\

$
2\boldsymbol{R_{xx}} - 2\lambda \boldsymbol{a_1} = 0
$\\\\

$
\boldsymbol{R_{xx}a_1} = \lambda \boldsymbol{a_1}
$
\\\\
What the above calculation shows is that the principal components are the eigenvectors of the matrix $\boldsymbol{R_{xx}}$. The first principal component is the eigenvector corresponding to the largest eigenvector. We order the eigenvalues $\lambda_1 \geq \lambda_2 \geq \ldots \geq \lambda_p > 0$ and the corresponding eigenvectors $\boldsymbol{w_1}, \ldots, \boldsymbol{w_p}$ are the orthogonal principal components in order of decreasing variance.

\item Find the eigenvectors and eigenvalues of $\boldsymbol{R_{xx}}$, the variance-covariance matrix for $\boldsymbol{Z}$.
\end{enumerate}

Summary of the calculations and steps:
\begin{enumerate}
    \item Standardize the input: $\boldsymbol{X} \rightarrow \boldsymbol{Z}$
    \item Find the $\boldsymbol{R_{xx}}$, the variance-covariance matrix for $\boldsymbol{Z}$
    \item Find the eigenvectors and eigenvalues of $\boldsymbol{R_{xx}}$
\end{enumerate}

\end{document}


% This LaTeX was auto-generated from MATLAB code.
% To make changes, update the MATLAB code and republish this document.

\documentclass{article}
\usepackage{graphicx}
\usepackage{color}

\sloppy
\definecolor{lightgray}{gray}{0.5}
\setlength{\parindent}{0pt}

\begin{document}

\section*{Gradient Descent}

\subsection*{Contents}

\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item Gradient
   \item Gradient Descent
   \item Fail situation
   \item Plot contour
   \item Reference
\end{itemize}

\subsection*{Gradient}

\begin{par}
Gradient descent method is based on gradient
\end{par} \vspace{1em}
\begin{par}
$$ \nabla f  = \frac{\partial f}{\partial x_1 }\mathbf{e}_1 + \cdots +
\frac{\partial f}{\partial x_n }\mathbf{e}_n $$
\end{par} \vspace{1em}
\begin{par}
gradient always point to the asent direction
\end{par} \vspace{1em}

\subsection*{Gradient Descent}

\begin{par}
f is object function, and this is unconstrained
\end{par} \vspace{1em}
\begin{par}
$$\min_{x} f $$
\end{par} \vspace{1em}
\begin{verbatim}
f = (@(X) (exp(X(1,:)-1) + exp(1-X(2,:)) + (X(1,:) - X(2,:)).^2));
%f = (@(X) (sin(0.5*X(1,:).^2 - 0.25 * X(2,:).^2 + 3) .* cos(2*X(1,:) + 1 - exp(X(2,:))) ))
\end{verbatim}

\subsection*{Fail situation}

\begin{par}
Rosenbrock function Gradient descent/ascent algorithm zig-zags, because the gradient is nearly orthogonal to the direction of the local minimum in these regions. It's hard to convergence
\end{par} \vspace{1em}
\begin{par}
$$ f(x, y) = (1-x)^2 + 100 * (y - x^2) ^ 2 $$
\end{par} \vspace{1em}
\begin{verbatim}
%f = (@(X) (1-X(1,:)).^2 + 100 * (X(2,:) - X(1,:).^2).^2);
\end{verbatim}

\subsection*{Plot contour}

\begin{verbatim}
[X, Y] = meshgrid(-2:0.1:2);
XX = [reshape(X, 1, numel(X)); reshape(Y, 1, numel(Y))];
%surf(X, Y, reshape(f(XX), length(X), length(X)))
contour(X, Y, reshape(f(XX), length(X), length(X)), 50);

hold on;
\end{verbatim}

\includegraphics [width=4in]{test_01.eps}
\begin{par}
plot gradient of function
\end{par} \vspace{1em}
\begin{verbatim}
for i=1:5:length(XX)
    tmp = XX(:,i);
    g = gradient_of_function(f, tmp);
    %plot([tmp(1),tmp(1)+g(1)*0.02],[tmp(1),tmp(2)+g(1)*0.02]);
    quiver(tmp(1),tmp(2),g(1)*0.02,g(2)*0.02);
end
\end{verbatim}

\includegraphics [width=4in]{test_02.eps}
\begin{par}
calculation
\end{par} \vspace{1em}
\begin{verbatim}
x0 = [-1; -1];
[x, v, h] = gradient(f, x0)

% built-in method
[x_in, v_in] = fminunc(f, x0)
\end{verbatim}

        \color{lightgray} \begin{verbatim}
x =

    0.7960
    1.2038

v =

    1.7974

h =

  Columns 1 through 7

   -1.0000   -1.0271   -0.4515    0.6432    0.8185    0.7755    0.7859
   -1.0000    0.4778    0.2130    1.0809    1.1279    1.1801    1.2059

  Columns 8 through 12

    0.7925    0.7963    0.7956    0.7959    0.7960
    1.2007    1.2024    1.2033    1.2039    1.2038

Warning: Gradient must be provided for trust-region algorithm;
  using line-search algorithm instead.

Local minimum found.

Optimization completed because the size of the gradient is less than
the default value of the function tolerance.

x_in =

    0.7961
    1.2039

v_in =

    1.7974

\end{verbatim} \color{black}
    \begin{par}
plot descent steps
\end{par} \vspace{1em}
\begin{verbatim}
for i=2:length(h)
    tmp1 = h(:,i-1);
    tmp2 = h(:,i);
    quiver(tmp1(1),tmp1(2),tmp2(1)-tmp1(1),tmp2(2)-tmp1(2), 0, 'r','LineWidth',2)
end
\end{verbatim}

\includegraphics [width=4in]{test_03.eps}

\subsection*{Reference}

\begin{enumerate}
\setlength{\itemsep}{-1ex}
   \item \begin{verbatim}http://www.onmyphd.com/?p=gradient.descent\end{verbatim}
   \item Convex Optimization
   \item \begin{verbatim}https://en.wikipedia.org/wiki/Gradient\end{verbatim}
   \item \begin{verbatim}https://en.wikipedia.org/wiki/Gradient_descent\end{verbatim}
   \item \begin{verbatim}http://stronglyconvex.com/blog/gradient-descent.html\end{verbatim}
\end{enumerate}

\end{document}


    \filetitle{stdise}{Standardise tseries data by subtracting mean and dividing by std deviation}{tseries/stdise}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
[X,M,S] = stdise(X)
[X,M,S] = stdise(X,Flag)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\item
  \texttt{X} {[} tseries {]} - Input tseries object whose data will be
  normalised.
\item
  \texttt{Flag} {[} 0 \textbar{} 1 {]} - \texttt{flag==0} normalises by
  N-1, \texttt{flag==1} normalises by \texttt{N}, where \texttt{N} is
  the sample length.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\item
  \texttt{X} {[} tseries {]} - Output tseries object with standardised
  data.
\item
  \texttt{XMeam} {[} numeric {]} - Estimated mean subtracted from the
  input tseries observations.
\item
  \texttt{XStd} {[} numeric {]} - Estimated std deviation by which the
  input tseries observations have been divided.
\end{itemize}

\paragraph{Description}\label{description}

\paragraph{Example}\label{example}


\section {Gen and Kill Sets}
\setlength{\parindent}{0pt}

(Prepared by Sameer V. Pande)

\vspace{0.3cm}

\subsection{Transfer and Meet Functions}
In previous module we discussed about how a DFA can be expressed with help of transfer and meet functions.
Transfer function computes the value of out[s] as a function f(in[s]). And for forward dfa, when there are multiple incoming edges at a node,
the meet operator computes the in[s] as a function of outsets of the predecessors.

\subsection{Using GEN and KILL sets to represent transfer functions}
In most cases, it is possible to represent transfer function with help of gen-sets and kill-sets which depend only on the statement (hence, can be computed statically).
Transfer function 'f' can be written as: \textbf{f(V) = (V - Kill(s)) $\bigcup$ Gen(s)}. The first part of expression
\textbf{ V - Kill(S)} is called "propagate" part and \textbf{Gen(S)} is called 'generate' part.

\subsection{Examples of Gen and Kill Sets}
We'll see two examples of gen/kill sets
\subsubsection{Constant Propataion}
\includegraphics[scale=0.5]{images/89_1.png}
\newline
The gen-set for constant-assignment is just \{(x,c)\}. The kill-set ensures that any previous value of the variable x is removed from the set, before new value is added via gen.
When x is assigned a value via a complex function/expression, then gen-set is empty-set but kill-set removes the old value of x, if any.
\subsubsection{Available Expressions Analysis}
\includegraphics[scale=0.5]{images/89_2.png}
\newline
Consider case when variable x is assigned an expression. The gen-set is similar to that of constant propgation (but now it has expressions as well, instead of just constants). The kill-set takes care of two things
\begin{enumerate}
    \item Remove the expressions corresponding to variable x
    \item Remove the variables which have expressions corresponding to older-value of x.
\end{enumerate}

\subsection{Gen/Kill Summaries for Basic Blocks}
One of the advantages of using basic-blocks is that it generates summaries over the entire block. We can take a sequential composition of transfer function of all statements in the basic-block to give us a block-level transfer function.
A block level transfer function can be represented using block level genset and killset.
\includegraphics[scale=0.5]{images/89_3.png}

For a basic block B, Gen$_B$ and Kill$_B$ can be interpreted as follows:
\begin{itemize}
    \item Gen$_B$: Locally exposed constant definitions,i.e., the definitions available at the end of basic-block B.
    \item Kill$_B$: Set of constant definitions killed by B.
\end{itemize}


\section{Universality and descent for pushouts}\label{chap:descent}

We begin this lecture with the idea that pushouts can be presented as higher inductive types. The general idea behind higher inductive types is that we can introduce new inductive types not only with constructors at the level of points, but also with constructors at the level of identifications. Pushouts form a basic class of examples that can be obtained as higher inductive types, because they come equipped with the structure of a cocone. The cocone $(i,j,H)$ in the commuting square
\begin{equation*}
  \begin{tikzcd}
    S \arrow[r,"g"] \arrow[d,swap,"f"] & B \arrow[d,"j"] \\
    A \arrow[r,swap,"i"] & C
  \end{tikzcd}
\end{equation*}
equips the type $C$ with two \emph{point constructors}
\begin{align*}
  i & : A \to C \\
  j & : B \to C \\
  \intertext{and a \emph{path constructor}}
  H & : \prd{s:S}i(f(s)) = j(g(s))
\end{align*}
that provides an identification $H(s):i(f(s))=j(g(s))$ for every $s:S$. The induction principle then specifies how to construct sections of families over $C$. Naturally, it takes not only the point constructors $i$ and $j$, but also the path constructor $H$ into account.

The induction principle is one of several equivalent characterizations of pushouts. We will prove a theorem providing five equivalent characterizations of homotopy pushouts. Two of those we have already seen in \cref{thm:pushout_up}: the universal property and the pullback property. The other three are
\begin{enumerate}
\item the \emph{dependent pullback property},
\item the \emph{dependent universal property},
\item the \emph{induction principle}.
\end{enumerate}

An implication that is particularly useful among our five characterizations of pushouts, is the fact that the pullback property implies the dependent pullback property. We use the dependent pullback property to derive the \emph{universality of pushouts} (not to be confused with the universal property of pushouts), showing that for any commuting cube
\begin{equation*}
  \begin{tikzcd}
    & S' \arrow[dl] \arrow[d] \arrow[dr] \\
    A' \arrow[d] & S \arrow[dl] \arrow[dr] & B' \arrow[d] \arrow[dl,crossing over] \\
    A \arrow[dr] & D' \arrow[from=ul,crossing over] \arrow[d] & B \arrow[dl] \\
    & D
  \end{tikzcd}
\end{equation*}
in which the back left and right squares are pullback squares, if the front left and right squares are also pullback squares, then so is the induced square
\begin{equation*}
  \begin{tikzcd}
    A'\sqcup^{\mathcal{S}'}B' \arrow[r,densely dotted] \arrow[d,densely dotted] & D' \arrow[d] \\
    A\sqcup^S B \arrow[r,densely dotted] & D
  \end{tikzcd}
\end{equation*}

We then observe that the univalence axiom can be used together with the universal property of pushouts to obtain such families over pushouts in the first place. We prove the descent theorem, which asserts that for any diagram of the form
\begin{equation*}
  \begin{tikzcd}
    & S' \arrow[dl] \arrow[d] \arrow[dr] \\
    A' \arrow[d] & S \arrow[dl] \arrow[dr] & B' \arrow[d] \\
    A \arrow[dr] & & B \arrow[dl] \\
    & C
  \end{tikzcd}
\end{equation*}
in which the bottom square is a pushout square and the back left and right squares are pullback squares, there is a unique way of extending this to a commuting cube
\begin{equation*}
  \begin{tikzcd}
    & S' \arrow[dl] \arrow[d] \arrow[dr] \\
    A' \arrow[d] & S \arrow[dl] \arrow[dr] & B' \arrow[d] \\
    A \arrow[dr] & C' \arrow[from=ul,crossing over,densely dotted] \arrow[from=ur,crossing over,densely dotted] \arrow[d,densely dotted] & B \arrow[dl] \\
    & C
  \end{tikzcd}
\end{equation*}
in which also the front left and right squares are pullback squares. Thus the converse of the universality theorem for pushouts also follows. The descent property used to show that pullbacks distribute over pushouts, and to compute the fibers of maps out of pushouts (the source of many exercises).

We note that the computation rules in our treatment for the induction principle of homotopy pushouts are weak. In other words, they are identifications. In this course we have no need for judgmental computation rules. Our focus is instead on universal properties. We refer the reader who is interested in the more `traditional' higher inductive types with judgmental computation rules to \cite{hottbook}.

\subsection{Five equivalent characterizations of homotopy pushouts}

Consider a commuting square
\begin{equation}\label{eq:descent-pushout-square}
  \begin{tikzcd}
    S \arrow[r,"g"] \arrow[d,swap,"f"] & B \arrow[d,"j"] \\
    A \arrow[r,swap,"i"] & H
  \end{tikzcd}
\end{equation}
with $H:i\circ f \htpy j \circ g$, where we will sometimes write $\mathcal{S}$ for the span $A\leftarrow S\rightarrow B$. Our first goal is to formulate the induction
principle for pushouts, which specifies how to construct a section of an arbitrary type family $P$ over $X$. Like the induction principle for the circle, the induction principle of pushouts has to take both the point constructors and the path constructors of $X$ into account. In our case, the point constructors are the maps
\begin{align*}
  i & : A \to X \\
  j & : B \to X,
  \intertext{and the path constructor is the homotopy}
  H & : \prd{s:S}i(f(s))=j(g(s)).
\end{align*}
Therefore, we obtain for any section $h:\prd{x:X}P(x)$ a triple $(h_A,h_B,h_S)$ consisting of
\begin{align*}
  h_A & : \prd{a:A}P(i(a)) \\
  h_B & : \prd{b:B}P(j(b)) \\
  h_S & : \prd{s:S} \mathsf{tr}_P(H(s),h(i(f(s))))=h(j(g(s))).
\end{align*}
The dependent functions $h_A$ and $h_B$ are simply given by
\begin{align*}
  h_A & \defeq h\circ i \\
  h_B & \defeq h\circ j.
\end{align*}
The homotopy $h_S$ is defined by $h_S(s)\defeq\apd{h}{H(s)}$, using the dependent action on paths of $h$. We call such triples $(h_A,h_B,h_S)$ \define{dependent cocones} on $P$ over the cocone $(i,j,H)$, and will write $\mathsf{dep\usc{}cocone}_{(i,j,H)}(P)$ for this type of dependent cocones. Thus, we have a function
\begin{equation*}
  \mathsf{ev\usc{}pushout}(P):\Big(\prd{x:X}P(x)\Big)\to \mathsf{dep\usc{}cocone}_{(i,j,H)}(P).
\end{equation*}
We are now in position to define the induction principle and the dependent universal property of pushouts.

\begin{defn}
  We say that $X$ satisfies the \define{induction principle of the pushout of $\mathcal{S}$} if the function
  \begin{equation*}
  \mathsf{ev\usc{}pushout}(P):\Big(\prd{x:X}P(x)\Big)\to \mathsf{dep\usc{}cocone}_{(i,j,H)}(P).
  \end{equation*}
  has a section for every type family $P$ over $X$.
\end{defn}

\begin{defn}
  We say that $X$ satisfies the \define{dependent universal property of the pushout of $\mathcal{S}$} if the function
  \begin{equation*}
  \mathsf{ev\usc{}pushout}(P):\Big(\prd{x:X}P(x)\Big)\to \mathsf{dep\usc{}cocone}_{(i,j,H)}(P).
  \end{equation*}
  is an equivalence for every type family $P$ over $X$.
\end{defn}

\begin{rmk}\label{rmk:comp-pushout}
  For $(h_A,h_B,h_S)$ and $(h'_A,h'_B,h'_S)$ in $\mathsf{dep\usc{}cocone}_{(i,j,H)}(P)$, the type of identifications $(h_A,h_B,h_S)=(h'_A,h'_B,h'_S)$ is equivalent to the type of triples $(K_A,K_B,K_S)$ consisting of
  \begin{align*}
    K_A & : \prd{a:A}h_A(a)=h'_A(a) \\
    K_B & : \prd{b:B}h_B(b)=h'_B(b),
  \end{align*}
  and a homotopy $K_S$ witnessing that the square
  \begin{equation*}
    \begin{tikzcd}[column sep=8em]
      \mathsf{tr}_P(H(s),h_A(f(s))) \arrow[r,equals,"\ap{\mathsf{tr}_P(H(s))}{K_A(f(s))}"] \arrow[d,equals,swap,"h_S(s)"] & \mathsf{tr}_P(H(s),{h'_A(f(s))}) \arrow[d,equals,"h'_S(s)"] \\
      h_B(g(s)) \arrow[r,equals,swap,"K_B(g(s))"] & h_B(g(s))
    \end{tikzcd}
  \end{equation*}
  commutes for every $s:S$.

  Therefore we see that the induction principle of the pushout of $\mathcal{S}$ provides us, for every dependent cocone $(h_A,h_B,h_S)$ of $P$ over $(i,j,H)$, with a dependent function $h:\prd{x:A}P(x)$ equipped with homotopies
  \begin{align*}
    K_A & : \prd{a:A}h(i(a))=h_A(a) \\
    K_B & : \prd{b:B}h(j(b))=h_B(b),
  \end{align*}
  and a homotopy $K_S$ witnessing that the square
  \begin{equation*}
    \begin{tikzcd}[column sep=8em]
      \mathsf{tr}_P(H(s),h(i(f(s)))) \arrow[r,equals,"\ap{\mathsf{tr}_P(H(s))}{K_A(f(s))}"] \arrow[d,equals,swap,"\apd{h}{H(s)}"] & \mathsf{tr}_P(H(s),{h_A(f(s))}) \arrow[d,equals,"h_S(s)"] \\
      h(j(g(s))) \arrow[r,equals,swap,"K_B(g(s))"] & h_B(g(s))
    \end{tikzcd}
  \end{equation*}
  commutes for every $s:S$. These homotopies are the \define{computation rules} for pushouts\index{computation rules!for pushouts}. The dependent universal property is equivalent to the assertion that for every dependent cocone $(h_A,h_B,h_S)$, the type of quadruples $(h,K_A,K_B,K_S)$ is contractible.
\end{rmk}

\begin{thm}\label{thm:dependent-pullback-property-pushout}
  Consider a commuting square
  \begin{equation}\label{eq:dppp1}
    \begin{tikzcd}
      S \arrow[d,swap,"f"] \arrow[r,"g"] & B \arrow[d,"j"] \\
      A \arrow[r,swap,"i"] & C
    \end{tikzcd}
  \end{equation}
  with $H:(i\circ f) \htpy (j \circ g)$. Then the following are equivalent:
  \begin{enumerate}
  \item The square in \cref{eq:dppp1} is a pushout square.
  \item The square in \cref{eq:dppp1} satisfies the pullback property of pushouts.
  \item The square satisfies the \define{dependent pullback property} of pushouts: For every family $P$ over $C$, the square
    \begin{equation}\label{eq:dppp2}
      \begin{tikzcd}[column sep=large]
        \prd{z:C}P(z) \arrow[rr,"h\mapsto h\circ j"] \arrow[d,swap,"h\mapsto h\circ i"] & &[1em] \prd{y:B}P(j(y)) \arrow[d,"h\mapsto h\circ g"] \\
        \prd{x:A}P(i(x)) \arrow[r,swap,"{h\mapsto h \circ f}"] & \prd{s:S}P(i(f(s))) \arrow[r,swap,"{\lam{h}{s}\mathsf{tr}_P(H(s),h(s))}" yshift=-2ex] & \prd{s:S}P(j(g(s))),
      \end{tikzcd}
    \end{equation}
    which commutes by the homotopy
    \begin{equation*}
      \lam{h}\mathsf{eq\usc{}htpy}(\lam{s}\apd{h}{H(s)}),
    \end{equation*}
    is a pullback square.
  \item The type $C$ satisfies the \define{dependent universal property} of pushouts.
  \item The type $C$ satisfies the \define{induction principle} of pushouts.
  \end{enumerate}
\end{thm}

\begin{proof}
  We have already seen in \cref{thm:pushout_up} that (i) and (ii) are equivalent.

  To see that (ii) implies (iii), note that we have a commuting cube
  \begin{equation*}
    \begin{tikzcd}[column sep=tiny]
      &  \sm{h:C\to C}\prd{c:C}P(h(c)) \arrow[dl] \arrow[d] \arrow[dr] \\
      \sm{h:A\to C}\prd{a:A}P(h(a)) \arrow[d] & \big(\sm{c:C}P(c)\big)^C \arrow[dl] \arrow[dr] & \sm{h:B\to C}\prd{b:B}P(h(b)) \arrow[d] \arrow[dl,crossing over] \\
      \big(\sm{c:C}P(c)\big)^A \arrow[dr] & \sm{h:S\to C}\prd{s:S}P(h(s)) \arrow[d] \arrow[from=ul,crossing over] & \big(\sm{c:C}P(c)\big)^B \arrow[dl] \\
      & \big(\sm{c:C}P(c)\big)^S
    \end{tikzcd}
  \end{equation*}
  in which the vertical maps are equivalences. Moreover, the bottom square is a pullback square by the pullback property of pushouts, so we conclude that the top square is a pullback square. Since this is a square of total spaces over a pullback square, we invoke \cref{lem:fiberwise-pullback} to conclude that for each $h:C \to C$, the square
  \begin{equation*}
    \begin{tikzcd}
      \prd{c:C}P(h(c)) \arrow[rr] \arrow[d] & &[2em] \prd{b:B} P(h(j(b))) \arrow[d] \\
      \prd{a:A}P(h(i(a))) \arrow[r] & \prd{s:S}P(h(i(f(s)))) \arrow[r,swap,"\mathsf{tr}_{((k:S\to C)\mapsto \prd{s:S}P(k(s)))}(\mathsf{eq\usc{}htpy}(h\cdot H))" yshift=-2ex] & \prd{s:S}P(h(j(g(s))))
    \end{tikzcd}
  \end{equation*}
  is a pullback square. Note that the transport with respect to the family $k\mapsto \prd{s:S}(Pk(s))$ along the identification $\mathsf{eq\usc{}htpy}(h\cdot H)$ is homotopic to the map
  \begin{equation*}
    \lam{h}{s}\mathsf{tr}_{P\circ h}(H(s),h(s)):\prd{s:S}P(h(i(f(s)))) \to \prd{s:S}P(h(j(g(s)))).
  \end{equation*}
  Therefore we conclude that the square
  \begin{equation*}
    \begin{tikzcd}
      \prd{c:C}P(h(c)) \arrow[rr] \arrow[d] & &[2em] \prd{b:B} P(h(j(b))) \arrow[d] \\
      \prd{a:A}P(h(i(a))) \arrow[r] & \prd{s:S}P(h(i(f(s)))) \arrow[r,swap,"{\lam{h}{s}\mathsf{tr}_{P\circ h}(H(s),h(s))}" yshift=-2ex] & \prd{s:S}P(h(j(g(s))))
    \end{tikzcd}
  \end{equation*}
  is a pullback square for each $h:C\to C$. Using the case $h\jdeq\idfunc : C \to C$ we conclude that the cocone $(i,j,H)$ satisfies the dependent pullback property.

  To see that (iii) implies (ii) we recall that transport with respect to a trivial family is homotopic to the identity function. Thus we obtain the pullback property from the dependent pullback property using the trivial family $\lam{c}T$ over $C$.

  To see that (iii) implies (iv) we note that $\mathsf{ev\usc{}pushout}(P)$ is an equivalence if and only if the gap map of the square in \cref{eq:dppp2} is an equivalence.

  It is clear that (iv) implies (v), so it remains to show that (v) implies (iv). If $X$ satisfies the induction principle of pushouts, then the map
  \begin{equation*}
    \mathsf{ev\usc{}pushout}:\Big(\prd{x:X}P(x)\Big)\to\mathsf{dep\usc{}cocone}_{(i,j,H)}(P)
  \end{equation*}
  has a section, i.e., it comes equipped with
  \begin{align*}
    \mathsf{ind\usc{}pushout} & :\mathsf{dep\usc{}cocone}_{(i,j,H)}(P)\to\Big(\prd{x:X}P(x)\Big) \\
    \mathsf{comp\usc{}pushout} & : \mathsf{ev\usc{}pushout}\circ\mathsf{ind\usc{}pushout} \htpy\idfunc.
  \end{align*}
  To see that $\mathsf{ev\usc{}pushout}$ is an equivalence it therefore suffices to construct a homotopy
  \begin{equation*}
    \mathsf{ind\usc{}pushout}(\mathsf{ev\usc{}pushout}(h))\htpy h
  \end{equation*}
  for any $h:\prd{x:X}P(x)$. From the fact that $\mathsf{ind\usc{}pushout}$ is a section of $\mathsf{ev\usc{}pushout}$ we obtain an identification
  \begin{equation*}
    \mathsf{ev\usc{}pushout}(\mathsf{ind\usc{}pushout}(\mathsf{ev\usc{}pushout}(h)))= \mathsf{ev\usc{}pushout}(h).
  \end{equation*}
  Therefore we observe that it suffices to construct a homotopy $h\htpy h'$ for any two functions $h,h':\prd{x:X}P(x)$ that come equipped with an identification
  \begin{equation*}
    \mathsf{ev\usc{}pushout}(h)=\mathsf{ev\usc{}pushout}(h').
  \end{equation*}
  Now we recall from \cref{rmk:comp-pushout} that this type of identifications is equivalent to the type of triples $(K_A,K_B,K_S)$ consisting of
  \begin{align*}
    K_A & : \prd{a:A}h(i(a))=h'(i(a)) \\
    K_B & : \prd{b:B}h(j(b))=h'(j(b))
  \end{align*}
  and a homotopy $K_S$ witnessing that the square
  \begin{equation*}
    \begin{tikzcd}[column sep=8em]
      \mathsf{tr}_P(H(s),h(i(f(s)))) \arrow[r,equals,"\ap{\mathsf{tr}_P(H(s))}{K_A(f(s))}"] \arrow[d,equals,swap,"\apd{h}{H(s)}"] & \mathsf{tr}_P(H(s),{h'(i(f(s)))}) \arrow[d,equals,"\apd{h'}{H(s)}"] \\
      h(j(g(s))) \arrow[r,equals,swap,"K_B(g(s))"] & h'(j(g(s)))
    \end{tikzcd}
  \end{equation*}
  commutes for every $s:S$. Note that from such an identification $K_S(s)$ we also obtain an identification
  \begin{equation*}
    \mathsf{K'_S(s)} : \mathsf{tr}_{x\mapsto h(x)=h'(x)}(H(s),K_A(f(s)))=K_B(g(s)).
  \end{equation*}
  Indeed, by path inducgtion on $p:x=x'$ we obtain an identification $\mathsf{tr}_{x\mapsto h(x)=h'(x)}(p,q)=q'$, for any $p:x=x'$, any $q:h(x)=h'(x)$ and any $q':h(x')=h'(x')$ for which the square
  \begin{equation*}
    \begin{tikzcd}[column sep=huge]
      \mathsf{tr}_P(p,h(x)) \arrow[r,equals,"\ap{\mathsf{tr}_P(p)}{q}"] \arrow[d,equals,swap,"\apd{h}{p}"] & \mathsf{tr}_P(p,h'(x)) \arrow[d,equals,"\apd{h'}{p}"] \\
      h(x') \arrow[r,equals,swap,"{q'}"] & h'(x')
    \end{tikzcd}
  \end{equation*}
  Now we see that the triple $(K_A,K_B,K'_S)$ forms a dependent cocone on the family $x\mapsto h(x)=h'(x)$. Therefore we obtain a homotopy $h\htpy h'$ as an application of the induction principle for pushouts at the family $x\mapsto h(x)=h'(x)$.
\end{proof}

\subsection{Type families over pushouts}

Given a pushout square
\begin{equation*}
\begin{tikzcd}
S \arrow[r,"g"] \arrow[d,swap,"f"] & B \arrow[d,"j"] \\
A \arrow[r,swap,"i"] & X.
\end{tikzcd}
\end{equation*}
with $H:i\circ f\htpy j\circ g$, and a family $P:X\to\UU$, we obtain
\begin{align*}
P\circ i & : A \to \UU \\
P\circ j & : B \to \UU \\
\lam{x}\mathsf{tr}_P(H(x)) & : \prd{x:S} \eqv{P(i(f(x)))}{P(j(g(x)))}.
\end{align*}
Our goal in the current section is to show that the triple $(P_A,P_B,P_S)$ consisting of $P_A\defeq P\circ i$, $P_B\defeq P\circ j$, and $P_S\defeq \lam{x}\mathsf{tr}_P(H(x))$ characterizes the family $P$ over $X$.

\begin{defn}
Consider a commuting square
\begin{equation*}
\begin{tikzcd}
S \arrow[r,"g"] \arrow[d,swap,"f"] & B \arrow[d,"j"] \\
A \arrow[r,swap,"i"] & X.
\end{tikzcd}
\end{equation*}
with $H:i\circ f\htpy j\circ g$, where all types involved are in $\UU$. The type $\mathsf{Desc}(\mathcal{S})$\index{Desc@{$\mathsf{Desc}(\mathcal{S})$}|textbf} of \define{descent data}\index{descent data|textbf} for $X$, is defined defined to be the type of triples $(P_A,P_B,P_S)$ consisting of
\begin{align*}
P_A & : A \to \UU \\
P_B & : B \to \UU \\
P_S & : \prd{x:S} \eqv{P_A(f(x))}{P_B(g(x))}.
\end{align*}
\end{defn}

\begin{defn}
Given a commuting square
\begin{equation*}
\begin{tikzcd}
S \arrow[r,"g"] \arrow[d,swap,"f"] & B \arrow[d,"j"] \\
A \arrow[r,swap,"i"] & X.
\end{tikzcd}
\end{equation*}
with $H:i\circ f\htpy j\circ g$, we define the map\index{desc_fam@{$\mathsf{desc\usc{}fam}_{\mathcal{S}}$}|textbf}
\begin{equation*}
\mathsf{desc\usc{}fam}_{\mathcal{S}}(i,j,H) : (X\to \UU)\to \mathsf{Desc}(\mathcal{S})
\end{equation*}
by $P\mapsto (P\circ i,P\circ j,\lam{x}\mathsf{tr}_P(H(x)))$.
\end{defn}

\begin{thm}\label{thm:desc_fam}
Consider a pushout square
\begin{equation*}
\begin{tikzcd}
S \arrow[r,"g"] \arrow[d,swap,"f"] & B \arrow[d,"j"] \\
A \arrow[r,swap,"i"] & X.
\end{tikzcd}
\end{equation*}
with $H:i\circ f\htpy j\circ g$, where all types involved are in $\UU$, and suppose we have
\begin{align*}
P_A & : A \to \UU \\
P_B & : B \to \UU \\
P_S & : \prd{x:S} \eqv{P_A(f(x))}{P_B(g(x))}.
\end{align*}
Then the function\index{desc_fam@{$\mathsf{desc\usc{}fam}_{\mathcal{S}}$}!is an equivalence|textit}
\begin{equation*}
\mathsf{desc\usc{}fam}_{\mathcal{S}}(i,j,H) : (X\to \UU)\to \mathsf{Desc}(\mathcal{S})
\end{equation*}
is an equivalence.
\end{thm}

\begin{proof}
By the 3-for-2 property of equivalences it suffices to construct an equivalence $\varphi:\mathsf{cocone}_{\mathcal{S}}(\UU)\to\mathsf{Desc}(\mathcal{S})$ such that the triangle
\begin{equation*}
\begin{tikzcd}[column sep=tiny]
& \UU^X \arrow[dl,swap,"{\mathsf{cocone\usc{}map}_{\mathcal{S}}(i,j,H)}"] \arrow[dr,"{\mathsf{desc\usc{}fam}_{\mathcal{S}}(i,j,H)}"] & \phantom{\mathsf{cocone}_{\mathcal{S}}(\UU)} \\
\mathsf{cocone}_{\mathcal{S}}(\UU) \arrow[rr,densely dotted,"\eqvsym","\varphi"'] & & \mathsf{Desc}(\mathcal{S})
\end{tikzcd}
\end{equation*}
commutes.

Since we have equivalences
\begin{equation*}
\mathsf{equiv\usc{}eq}:\eqv{\Big(P_A(f(x))=P_B(g(x))\Big)}{\Big(\eqv{P_A(f(x))}{P_B(g(x))}\Big)}
\end{equation*}
for all $x:S$, we obtain by \cref{ex:equiv_pi} an equivalence on the dependent products
\begin{equation*}
{\Big(\prd{x:S}P_A(f(x))=P_B(g(x))\Big)}\to{\Big(\prd{x:S}\eqv{P_A(f(x))}{P_B(g(x))}\Big)}.
\end{equation*}
We define $\varphi$ to be the induced map on total spaces. Explicitly, we have
\begin{equation*}
\varphi\defeq \lam{(P_A,P_B,K)}(P_A,P_B,\lam{x}\mathsf{equiv\usc{}eq}(K(x))).
\end{equation*}
Then $\varphi$ is an equivalence by \cref{thm:fib_equiv}, and the triangle commutes by \cref{ex:tr_ap}.
\end{proof}

\begin{cor}\label{cor:desc_fam}
Consider descent data $(P_A,P_B,P_S)$ for a pushout square as in \cref{thm:desc_fam}.
Then the type of quadruples $(P,e_A,e_B,e_S)$ consisting of a family $P:X\to\UU$ equipped with two families of equivalences
\begin{samepage}
\begin{align*}
e_A & : \prd{a:A}\eqv{P_A(a)}{P(i(a))} \\
e_B & : \prd{b:B}\eqv{P_B(a)}{P(j(b))}
\end{align*}
\end{samepage}%
and a homotopy $e_S$ witnessing that the square
\begin{equation*}
\begin{tikzcd}[column sep=huge]
P_A(f(x)) \arrow[r,"e_A(f(x))"] \arrow[d,swap,"P_S(x)"] & P(i(f(x))) \arrow[d,"\mathsf{tr}_P(H(x))"] \\
P_B(g(x)) \arrow[r,swap,"e_B(g(x))"] & P(j(g(x)))
\end{tikzcd}
\end{equation*}
commutes, is contractible.
\end{cor}

\begin{proof}
The fiber of this map at $(P_A,P_B,P_S)$ is equivalent to the type of quadruples $(P,e_A,e_B,e_S)$ as described in the theorem, which are contractible by \cref{thm:contr_equiv}.
\end{proof}

\subsection{The flattening lemma for pushouts}

In this section we consider a pushout square
\begin{equation*}
\begin{tikzcd}
S \arrow[r,"g"] \arrow[d,swap,"f"] & B \arrow[d,"j"] \\
A \arrow[r,swap,"i"] & X.
\end{tikzcd}
\end{equation*}
with $H:i\circ f\htpy j\circ g$, descent data
\begin{align*}
P_A & : A \to \UU \\
P_B & : B \to \UU \\
P_S & : \prd{x:S} \eqv{P_A(f(x))}{P_B(g(x))},
\end{align*}
and a family $P:X\to\UU$ equipped with
\begin{align*}
e_A & : \prd{a:A}\eqv{P_A(a)}{P(i(a))} \\
e_B & : \prd{b:B}\eqv{P_B(a)}{P(j(b))}
\end{align*}
and a homotopy $e_S$ witnessing that the square
\begin{equation*}
\begin{tikzcd}[column sep=huge]
P_A(f(x)) \arrow[r,"e_A(f(x))"] \arrow[d,swap,"P_S(x)"] & P(i(f(x))) \arrow[d,"\mathsf{tr}_P(H(x))"] \\
P_B(g(x)) \arrow[r,swap,"e_B(g(x))"] & P(j(g(x)))
\end{tikzcd}
\end{equation*}
commutes.

\begin{defn}
We define a commuting square
\begin{equation*}
\begin{tikzcd}
\sm{x:S}P_A(f(x)) \arrow[d,swap,"{f'}"] \arrow[r,"{g'}"] & \sm{b:B}P_B(b) \arrow[d,"{j'}"] \\
\sm{a:A}P_A(a) \arrow[r,swap,"{i'}"] & \sm{x:X}P(x)
\end{tikzcd}
\end{equation*}
with a homotopy $H':i'\circ f'\htpy j'\circ g'$. We will write $\mathcal{S'}$ for the span
\begin{equation*}
\begin{tikzcd}
\sm{a:A}P_A(a) & \sm{x:S}P_A(f(x)) \arrow[l,swap,"{f'}"] \arrow[r,"{g'}"] & \sm{b:B}P_B(b).
\end{tikzcd}
\end{equation*}
\end{defn}

\begin{constr}
We define
\begin{align*}
f' & \defeq \total[f]{\lam{x}\idfunc[P_A(f(x))]} \\
g' & \defeq \total[g]{e_S} \\
i' & \defeq \total[i]{e_A} \\
j' & \defeq \total[j]{e_B}.
\end{align*}
Then it remains to construct a homotopy $H':i'\circ f'\htpy j'\circ g'$. In order to construct this homotopy, we have to construct an identification
\begin{equation*}
(i(f(x)),e_A(y))=(j(g(x)),e_B(e_S(y)))
\end{equation*}
for any $x:S$ and $y:P_A(f(x))$. Note that have the identification
\begin{equation*}
\mathsf{eq\usc{}pair}(H(x),e_S(x,y)^{-1})
\end{equation*}
of this type.
\end{constr}

\begin{lem}[The flattening lemma]\label{lem:flattening}
The commuting square\index{flattening lemma!for pushouts|textit}
\begin{equation*}
\begin{tikzcd}
\sm{x:S}P_A(f(x)) \arrow[d,swap,"{f'}"] \arrow[r,"{g'}"] & \sm{b:B}P_B(b) \arrow[d,"{j'}"] \\
\sm{a:A}P_A(a) \arrow[r,swap,"{i'}"] & \sm{x:X}P(x)
\end{tikzcd}
\end{equation*}
is a pushout square.
\end{lem}

\begin{proof}
  To show that the square of total spaces satisfies the pullback property of pullbacks, note that we have a commuting cube
  \begin{equation*}
    \begin{tikzcd}
      & T^{\sm{x:X}P(x)} \arrow[dl] \arrow[d] \arrow[dr] \\
      T^{\sm{a:A}P_A(a)} \arrow[d] & \prd{x:X}T^{P(x)} \arrow[dl] \arrow[dr] & T^{\sm{b:B}P_B(b)} \arrow[dl,crossing over] \arrow[d] \\
      \prd{a:A}T^{P_A(a)} \arrow[dr] & T^{\sm{x:S}P_A(f(x))} \arrow[from=ul,crossing over] \arrow[d] & \prd{b:B}T^{P_B(b)} \arrow[dl] \\
      & \prd{x:S}T^{P_A(f(x))}
    \end{tikzcd}
  \end{equation*}
  for any type $T$. In this cube, the vertical maps are all equivalences, and the bottom square is a pullback square by the dependent pullback property of pushouts. Therefore it follows that the top square is a pullback square.
\end{proof}

\subsection{The universality theorem}
\begin{thm}
  Consider two pushout squares
  \begin{equation*}
    \begin{tikzcd}
      S' \arrow[r] \arrow[d] & B' \arrow[d] & S \arrow[r] \arrow[d] & B \arrow[d] \\
      A' \arrow[r] & C' & A \arrow[r] & C
    \end{tikzcd}
  \end{equation*}
  and a commuting cube
  \begin{equation*}
    \begin{tikzcd}
      & S' \arrow[dl] \arrow[d] \arrow[dr] \\
      A' \arrow[d] & S \arrow[dl] \arrow[dr] & B' \arrow[d] \arrow[dl,crossing over] \\
      A \arrow[dr] & D' \arrow[from=ul,crossing over] \arrow[d] & B \arrow[dl] \\
      & D
    \end{tikzcd}
  \end{equation*}
  in which the back left and right squares are pullback squares. The following are equivalent:
  \begin{enumerate}
  \item The front left and right squares are pullback squares.
  \item The induced commuting square
    \begin{equation*}
      \begin{tikzcd}
        C' \arrow[r,densely dotted] \arrow[d,densely dotted] & D' \arrow[d] \\
        C \arrow[r,densely dotted] & D
      \end{tikzcd}
    \end{equation*}
    is a pullback square.
  \end{enumerate}
\end{thm}

\subsection{The descent property for pushouts}

In the previous section there was a significant role for families of equivalences, and we know by \cref{thm:pb_fibequiv,cor:pb_fibequiv}: families of equivalences indicate the presence of pullbacks. In this section we reformulate the results of the previous section using pullbacks where we used families of equivalences before, to obtain new and useful results. We begin by considering the type of descent data from the perspective of pullback squares.

\begin{defn}
Consider a span $\mathcal{S}$ from $A$ to $B$, and a span $\mathcal{S}'$ from $A'$ to $B'$. A \define{cartesian transformation} of spans\index{cartesian transformation!of spans|textbf} from $\mathcal{S}'$ to $\mathcal{S}$ is a diagram of the form
\begin{equation*}
\begin{tikzcd}
A' \arrow[d,swap,"h_A"]  & S' \arrow[l,swap,"{f'}"] \arrow[r,"{g'}"] \arrow[d,swap,"h_S"] & B' \arrow[d,"h_B"] \\
A & S \arrow[l,"f"] \arrow[r,swap,"g"] & B
\end{tikzcd}
\end{equation*}
with $F:f\circ h_S\htpy h_A\circ f'$ and $G:g\circ h_S\htpy h_B\circ g'$, where both squares are pullback squares.

The type $\mathsf{cart}(\mathcal{S}',\mathcal{S})$\index{cart(S,S')@{$\mathsf{cart}(\mathcal{S},\mathcal{S}')$}|textbf} of cartesian transformation is the type of tuples
\begin{equation*}
(h_A,h_S,h_B,F,G,p_f,p_g)
\end{equation*}
where $p_f:\mathsf{is\usc{}pullback}(h_S,h_A,F)$ and $p_g:\mathsf{is\usc{}pullback}(h_S,h_B,G)$, and we write
\begin{equation*}
\mathsf{Cart}(\mathcal{S}) \defeq \sm{A',B':\UU}{\mathcal{S}':\mathsf{span}(A',B')}\mathsf{cart}(\mathcal{S}',\mathcal{S}).
\end{equation*}
\end{defn}

\begin{lem}\label{lem:cart_desc}
There is an equivalence\index{cart_desc@{$\mathsf{cart\usc{}desc}_{\mathcal{S}}$}|textit}
\begin{equation*}
\mathsf{cart\usc{}desc}_{\mathcal{S}}:\mathsf{Desc}(\mathcal{S})\to \mathsf{Cart}(\mathcal{S}).
\end{equation*}
\end{lem}

\begin{proof}
Note that by \cref{thm:pb_fibequiv_complete} it follows that the types of triples $(f',F,p_f)$ and $(g',G,p_g)$ are equivalent to the types of families of equivalences
\begin{align*}
& \prd{x:S}\eqv{\fib{h_S}{x}}{\fib{h_A}{f(x)}} \\
& \prd{x:S}\eqv{\fib{h_S}{x}}{\fib{h_B}{g(x)}}
\end{align*}
respectively. Furthermore, by \cref{thm:fam_proj} the types of pairs $(S',h_S)$, $(A',h_A)$, and $(B',h_B)$ are equivalent to the types $S\to \UU$, $A\to \UU$, and $B\to \UU$, respectively. Therefore it follows that the type $\mathsf{Cart}(\mathcal{S})$ is equivalent to the type of tuples $(Q,P_A,\varphi,P_B,P_S)$ consisting of
\begin{align*}
Q & : S\to \UU \\
P_A & : A \to \UU \\
P_B & : B \to \UU \\
\varphi & : \prd{x:S}\eqv{Q(x)}{P_A(f(x))} \\
P_S & : \prd{x:S}\eqv{Q(x)}{P_B(g(x))}.
\end{align*}
However, the type of $\varphi$ is equivalent to the type $P_A\circ f=Q$. Thus we see that the type of pairs $(Q,\varphi)$ is contractible, so our claim follows.
\end{proof}

\begin{defn}
We define an operation\index{cart map!{$\mathsf{cart\usc{}map}_{\mathcal{S}}$}|textbf}
\begin{equation*}
\mathsf{cart\usc{}map}_{\mathcal{S}}:{\Big(\sm{X':\UU}X'\to X\Big)}\to \mathsf{Cart}(\mathcal{S}).
\end{equation*}
\end{defn}

\begin{constr}
Let $X':\UU$ and $h_X:X'\to X$. Then we define the types
\begin{align*}
A' & \defeq A\times_X X' \\
B' & \defeq B\times_X X'.
\end{align*}
Next, we define a span $\mathcal{S'}\defeq(S',f',g')$ from $A'$ to $B'$. We take
\begin{align*}
S' & \defeq S\times_A A' \\
f' & \defeq \pi_2.
\end{align*}
To define $g'$, let $s:S$, let $(a,x',p):A\times_X X'$, and let $q:f(s)=a$. Our goal is to construct a term of type $B\times_X X'$. We have $g(s):B$ and $x':X'$, so it remains to show that $j(g(s))=h_X(x')$. We construct such an identification as a concatenation
\begin{equation*}
\begin{tikzcd}
j(g(s)) \arrow[r,equals,"H(s)^{-1}"] &[1ex] i(f(s)) \arrow[r,equals,"\ap{i}{q}"] &[1ex] i(a) \arrow[r,equals,"p"] & h_X(x').
\end{tikzcd}
\end{equation*}
To summarize, the map $g'$ is defined as
\begin{equation*}
g' \defeq \lam{(s,(a,x',p),q)}(g(s),x',\ct{H(s)^{-1}}{(\ct{\ap{i}{q}}{p})}).
\end{equation*}
Then we have commuting squares
\begin{equation*}
\begin{tikzcd}
A\times_X X' \arrow[d] & S\times_A A' \arrow[d] \arrow[l] \arrow[r] & B\times_X X' \arrow[d] \\
A & S \arrow[l] \arrow[r] & B.
\end{tikzcd}
\end{equation*}
Moreover, these squares are pullback squares by \cref{thm:pb_pasting}.
\end{constr}

The following theorem is analogous to \cref{thm:desc_fam}.

\begin{thm}[The descent theorem for pushouts]\label{thm:cart_map}\index{descent theorem!for pushouts|textit}
The operation $\mathsf{cart\usc{}map}_{\mathcal{S}}$\index{cart map!{$\mathsf{cart\usc{}map}_{\mathcal{S}}$}!is an equivalence|textit} is an equivalence
\begin{equation*}
\eqv{\Big(\sm{X':\UU}X'\to X\Big)}{\mathsf{Cart}(\mathcal{S})}
\end{equation*}
\end{thm}

\begin{proof}
It suffices to show that the square
\begin{equation*}
\begin{tikzcd}[column sep=huge]
X\to \UU \arrow[r,"{\mathsf{desc\usc{}fam}_{\mathcal{S}}(i,j,H)}"] \arrow[d,swap,"\mathsf{map\usc{}fam}_X"] & \mathsf{Desc}(\mathcal{S}) \arrow[d,"\mathsf{cart\usc{}desc}_{\mathcal{S}}"] \\
\sm{X':\UU}X'\to X \arrow[r,swap,"\mathsf{cart\usc{}map}_{\mathcal{S}}"] & \mathsf{Cart}(\mathcal{S})
\end{tikzcd}
\end{equation*}
commutes. To see that this suffices, note that the operation $\mathsf{map\usc{}fam}_X$ is an equivalence by \cref{thm:fam_proj}, the operation $\mathsf{desc\usc{}fam}_{\mathcal{S}}(i,j,H)$ is an equivalence by \cref{thm:desc_fam}, and the operation $\mathsf{cart\usc{}desc}_{\mathcal{S}}$ is an equivalence by \cref{lem:cart_desc}.

To see that the square commutes, note that the composite
\begin{equation*}
\mathsf{cart\usc{}map}_{\mathcal{S}}\circ \mathsf{map\usc{}fam}_X
\end{equation*}
takes a family $P:X\to \UU$ to the cartesian transformation of spans
\begin{equation*}
\begin{tikzcd}
A\times_X\tilde{P} \arrow[d,swap,"\pi_1"] & S\times_A\Big(A\times_X\tilde{P}\Big) \arrow[l] \arrow[r] \arrow[d,swap,"\pi_1"] & B\times_X\tilde{P} \arrow[d,"\pi_1"] \\
A & S \arrow[l] \arrow[r] & B,
\end{tikzcd}
\end{equation*}
where $\tilde{P}\defeq\sm{x:X}P(x)$.

The composite
\begin{equation*}
\mathsf{cart\usc{}desc}_{\mathcal{S}}\circ \mathsf{desc\usc{}fam}_X
\end{equation*}
takes a family $P:X\to \UU$ to the cartesian transformation of spans
\begin{equation*}
\begin{tikzcd}
\sm{a:A}P(i(a)) \arrow[d] & \sm{s:S}P(i(f(s))) \arrow[l] \arrow[r] \arrow[d] & \sm{b:B}P(j(b)) \arrow[d] \\
A & S \arrow[l] \arrow[r] & B
\end{tikzcd}
\end{equation*}
These cartesian natural transformations are equal by \cref{lem:pb_subst}
\end{proof}

Since $\mathsf{cart\usc{}map}_{\mathcal{S}}$ is an equivalence it follows that its fibers are contractible. This is essentially the content of the following corollary.

\begin{cor}
Consider a diagram of the form
\begin{equation*}
\begin{tikzcd}
& S' \arrow[d,swap,"h_S"] \arrow[dl,swap,"{f'}"] \arrow[dr,"{g'}"] \\
A' \arrow[d,swap,"h_A"] & S \arrow[dl,swap,"f"] \arrow[dr,"g"] & B' \arrow[d,"{h_B}"] \\
A \arrow[dr,swap,"i"] & & B \arrow[dl,"j"] \\
& X
\end{tikzcd}
\end{equation*}
with homotopies
\begin{align*}
F & : f\circ h_S \htpy h_A\circ f' \\
G & : g\circ h_S \htpy h_B\circ g' \\
H & : i\circ f \htpy j\circ g,
\end{align*}
and suppose that the bottom square is a pushout square, and the top squares are pullback squares.
Then the type of tuples $((X',h_X),(i',I,p),(j',J,q),(H',C))$ consisting of
\begin{enumerate}
\item A type $X':\UU$ together with a morphism
\begin{equation*}
h_X : X'\to X,
\end{equation*}
\item A map $i':A'\to X'$, a homotopy $I:i\circ h_A\htpy h_X\circ i'$, and a term $p$ witnessing that the square
\begin{equation*}
\begin{tikzcd}
A' \arrow[d,swap,"h_A"] \arrow[r,"{i'}"] & X' \arrow[d,"h_X"] \\
A \arrow[r,swap,"i"] & X
\end{tikzcd}
\end{equation*}
is a pullback square.
\item A map $j':B'\to X'$, a homotopy $J:j\circ h_B\htpy h_X\circ j'$, and a term $q$ witnessing that the square
\begin{equation*}
\begin{tikzcd}
B' \arrow[d,swap,"h_B"] \arrow[r,"{j'}"] & X' \arrow[d,"h_X"] \\
B \arrow[r,swap,"j"] & X
\end{tikzcd}
\end{equation*}
is a pullback square,
\item A homotopy $H':i'\circ f'\htpy j'\circ g'$, and a homotopy
\begin{equation*}
C : \ct{(i\cdot F)}{(\ct{(I\cdot f')}{(h_X\cdot H')})} \htpy \ct{(H\cdot h_S)}{(\ct{(j\cdot G)}{(J\cdot g')})}
\end{equation*}
witnessing that the cube
\begin{equation*}
\begin{tikzcd}
& S' \arrow[dl] \arrow[dr] \arrow[d] \\
A' \arrow[d] & S \arrow[dl] \arrow[dr] & B' \arrow[dl,crossing over] \arrow[d] \\
A \arrow[dr] & X' \arrow[d] \arrow[from=ul,crossing over] & B \arrow[dl] \\
& X,
\end{tikzcd}
\end{equation*}
commutes,
\end{enumerate}
is contractible.
\end{cor}

The following theorem should be compared to the flattening lemma, \cref{lem:flattening}.\index{flattening lemma!for pushouts}

\begin{thm}
Consider a commuting cube
\begin{equation*}
\begin{tikzcd}
& S' \arrow[dl,swap,"{f'}"] \arrow[dr,"{g'}"] \arrow[d,"h_S"] \\
A' \arrow[d,swap,"h_A"] & S \arrow[dl,swap,"f" near start] \arrow[dr,"g" near start] & B' \arrow[dl,crossing over,"{j'}" near end] \arrow[d,"h_B"] \\
A \arrow[dr,swap,"i"] & X' \arrow[d,"h_X" near start] \arrow[from=ul,crossing over,"{i'}"' near end] & B \arrow[dl,"j"] \\
& X.
\end{tikzcd}
\end{equation*}
If each of the vertical squares is a pullback, and the bottom square  is a pushout, then the top square is a pushout.
\end{thm}

\begin{proof}
By \cref{cor:pb_fibequiv} we have families of equivalences
\begin{align*}
F & : \prd{x:S}\eqv{\fib{h_S}{x}}{\fib{h_A}{f(x)}} \\
G & : \prd{x:S}\eqv{\fib{h_S}{x}}{\fib{h_B}{g(x)}} \\
I & : \prd{a:A}\eqv{\fib{h_A}{a}}{\fib{h_X}{i(a)}} \\
J & : \prd{b:B}\eqv{\fib{h_B}{b}}{\fib{h_X}{j(b)}}.
\end{align*}
Moreover, since the cube commutes we obtain a family of homotopies
\begin{equation*}
K : \prd{x:S} I(f(x))\circ F(x) \htpy J(g(x))\circ G(x).
\end{equation*}
We define the descent data $(P_A,P_B,P_S)$ consisting of $P_A:A\to\UU$, $P_B:B\to\UU$, and $P_S:\prd{x:S}\eqv{P_A(f(x))}{P_B(g(x))}$ by
\begin{align*}
P_A(a) & \defeq \fib{h_A}{a} \\
P_B(b) & \defeq \fib{h_B}{b} \\
P_S(x) & \defeq G(x)\circ F(x)^{-1}.
\end{align*}
We have
\begin{align*}
P & \defeq \fibf{h_X} \\
e_A & \defeq I \\
e_B & \defeq J \\
e_S & \defeq K.
\end{align*}
Now consider the diagram
\begin{equation*}
\begin{tikzcd}
\sm{s:S}\fib{h_S}{s} \arrow[r] \arrow[d] & \sm{s:S}\fib{h_A}{f(s)} \arrow[r] \arrow[d] & \sm{b:B}\fib{h_B}{b} \arrow[d] \\
\sm{a:A}\fib{h_A}{a} \arrow[r] & \sm{a:A}\fib{h_A}{a} \arrow[r] & \sm{x:X}\fib{h_X}{x}
\end{tikzcd}
\end{equation*}
Since the top and bottom map in the left square are equivalences, we obtain from \cref{ex:pushout_equiv} that the left square is a pushout square. Moreover, the right square is a pushout by \cref{lem:flattening}. Therefore it follows by \cref{thm:pushout_pasting} that the outer rectangle is a pushout square.

Now consider the commuting cube
\begin{equation*}
\begin{tikzcd}
& \sm{s:S}\fib{h_S}{s} \arrow[dl] \arrow[dr] \arrow[d] \\
\sm{a:A}\fib{h_A}{a} \arrow[d] & S' \arrow[dl] \arrow[dr] & \sm{b:B}\fib{h_B}{b} \arrow[dl,crossing over] \arrow[d] \\
A' \arrow[dr,swap] & \sm{x:X}\fib{h_X}{x} \arrow[d] \arrow[from=ul,crossing over] & B' \arrow[dl] \\
& X'.
\end{tikzcd}
\end{equation*}
We have seen that the top square is a pushout. The vertical maps are all equivalences, so the vertical squares are all pushout squares. Thus it follows from one more application of \cref{thm:pushout_pasting} that the bottom square is a pushout.
\end{proof}

%\begin{cor}
%For any map $f:A\sqcup^S B\to X$, and any $x:X$, the square
%\begin{equation*}
%\begin{tikzcd}
%\fib{f_S}{x} \arrow[r] \arrow[d] & \fib{f_B}{x} \arrow[d] \\
%\fib{f_A}{x} \arrow[r] & \fib{f}{x}
%\end{tikzcd}
%\end{equation*}
%is a pushout square.
%\end{cor}

\begin{thm}
Consider a commuting cube of types
\begin{equation*}\label{eq:cube}
\begin{tikzcd}
& S' \arrow[dl] \arrow[dr] \arrow[d] \\
A' \arrow[d] & S \arrow[dl] \arrow[dr] & B' \arrow[dl,crossing over] \arrow[d] \\
A \arrow[dr] & X' \arrow[d] \arrow[from=ul,crossing over] & B \arrow[dl] \\
& X,
\end{tikzcd}
\end{equation*}
and suppose the vertical squares are pullback squares. Then the commuting square
\begin{equation*}
\begin{tikzcd}
A' \sqcup^{S'} B' \arrow[r] \arrow[d] & X' \arrow[d] \\
A\sqcup^{S} B \arrow[r] & X
\end{tikzcd}
\end{equation*}
is a pullback square.
\end{thm}

\begin{proof}
It suffices to show that the pullback
\begin{equation*}
(A\sqcup^{S} B)\times_{X}X'
\end{equation*}
has the universal property of the pushout. This follows by the descent theorem, since the vertical squares in the cube
\begin{equation*}
\begin{tikzcd}
& S' \arrow[dl] \arrow[dr] \arrow[d] \\
A' \arrow[d] & S \arrow[dl] \arrow[dr] & B' \arrow[dl,crossing over] \arrow[d] \\
A \arrow[dr] & (A\sqcup^{S} B)\times_{X}X' \arrow[d] \arrow[from=ul,crossing over] & B \arrow[dl] \\
& A\sqcup^{S} B
\end{tikzcd}
\end{equation*}
are pullback squares by \cref{thm:pb_pasting}.
\end{proof}

\subsection{Applications of the descent theorem}

\begin{thm}
  Consider a commuting cube
  \begin{equation*}
    \begin{tikzcd}
      & S' \arrow[dl] \arrow[dr] \arrow[d] \\
      A' \arrow[d] & S \arrow[dl] \arrow[dr] & B' \arrow[dl,crossing over] \arrow[d] \\
      A \arrow[dr] & C' \arrow[from=ul,crossing over] \arrow[d] & B \arrow[dl] \\
      & C
    \end{tikzcd}
  \end{equation*}
  in which the bottom square is a pushout square. If the vertical sides are pullback squares, then for each $c:C$ the square of fibers
  \begin{equation*}
    \begin{tikzcd}
      \fib{i\circ f\circ h_S}{c} \arrow[d] \arrow[r] & \fib{j\circ g\circ h_S}{c} \arrow[r] & \fib{j\circ h_B}{c} \arrow[d] \\
      \fib{i\circ h_A}{c} \arrow[rr] & & \fib{h_C}{c}
    \end{tikzcd}
  \end{equation*}
  is a pushout square.
\end{thm}

\begin{exercises}
\item Use the characterization of the circle\index{circle} as a pushout given in \cref{eg:circle_pushout} to show that the square
\begin{equation*}
\begin{tikzcd}[column sep=large]
\sphere{1}+\sphere{1} \arrow[r,"{[\idfunc,\idfunc]}"] \arrow[d,swap,"{[\idfunc,\idfunc]}"] & \sphere{1} \arrow[d,"{\lam{t}(t,\base)}"] \\
\sphere{1} \arrow[r,swap,"{\lam{t}(t,\base)}"] & \sphere{1}\times\sphere{1}
\end{tikzcd}
\end{equation*}
is a pushout square.
\item Let $f:A\to B$ be a map. The \define{codiagonal}\index{codiagonal}\index{nabla@{$\nabla_f$}} $\nabla_f$ of $f$ is the map obtained from the universal property of the pushout, as indicated in the diagram
\begin{equation*}
\begin{tikzcd}
A \arrow[d,swap,"f"] \arrow[r,"f"] \arrow[dr, phantom, "\ulcorner", very near end] & B \arrow[d,"\inr"] \arrow[ddr,bend left=15,"{\idfunc[B]}"] \\
A \arrow[r,"\inl"] \arrow[drr,bend right=15,swap,"{\idfunc[B]}"] & B\sqcup^{A} B \arrow[dr,densely dotted,near start,swap,"\nabla_f"] \\
& & B
\end{tikzcd}
\end{equation*}
Show that $\fib{\nabla_f}{b}\eqvsym \susp(\fib{f}{b})$ for any $b:B$.
\item \label{ex:fib_join}Consider two maps $f:A\to X$ and $g:B\to X$. The \define{fiberwise join}\index{fiberwise join} $\join{f}{g}$ is defined by the universal property of the pushout as the unique map rendering the diagram
\begin{equation*}
\begin{tikzcd}
A\times_X B \arrow[d,"\pi_1"] \arrow[r,"\pi_2"] \arrow[dr, phantom, "\ulcorner", very near end] & B \arrow[d,"\inr"] \arrow[ddr,bend left=15,"g"] \\
A \arrow[r,"\inl"] \arrow[drr,bend right=15,swap,"f"] & \join[X]{A}{B} \arrow[dr,densely dotted,near start,swap,"\join{f}{g}"] \\
& & X
\end{tikzcd}
\end{equation*}
commutative, where $\join[X]{A}{B}$ is defined as a pushout, as indicated.
Construct an equivalence
\begin{equation*}
\eqv{\fib{\join{f}{g}}{x}}{\join{\fib{f}{x}}{\fib{g}{x}}}
\end{equation*}
for any $x:X$.
\item Consider two maps $f:A\to B$ and $g:C\to D$.
The \define{pushout-product}\index{pushout-product}
\begin{equation*}
f\square g : (A\times D)\sqcup^{A\times C} (B\times C)\to B\times D
\end{equation*}
of $f$ and $g$ is defined by the universal property of the pushout as the unique map rendering the diagram
\begin{equation*}
\begin{tikzcd}
A\times C \arrow[r,"{f\times \idfunc[C]}"] \arrow[d,swap,"{\idfunc[A]\times g}"] & B\times C \arrow[d,"\inr"] \arrow[ddr,bend left=15,"{\idfunc[B]\times g}"] \\
A\times D \arrow[r,"\inl"] \arrow[drr,bend right=15,swap,"{f\times\idfunc[D]}"] & (A\times D)\sqcup^{A\times C} (B\times C) \arrow[dr,densely dotted,swap,near start,"f\square g"] \\
& & B\times D
\end{tikzcd}
\end{equation*}
commutative. Construct an equivalence
\begin{equation*}
\eqv{\fib{f\square g}{b,d}}{\join{\fib{f}{b}}{\fib{g}{d}}}
\end{equation*}
for all $b:B$ and $d:D$.
\item Let $A$ and $B$ be pointed types with base points $a_0:A$ and $b_0:B$. The \define{wedge inclusion}\index{wedge inclusion} is defined as follows by the universal property of the wedge:
\begin{equation*}
\begin{tikzcd}[column sep=huge]
\unit \arrow[r] \arrow[d] & B \arrow[d,"\inr"] \arrow[ddr,bend left=15,"{\lam{b}(a_0,b)}"] \\
A \arrow[r,"\inl"] \arrow[drr,bend right=15,swap,"{\lam{a}(a,b_0)}"] & A\vee B \arrow[dr,densely dotted,swap,"{\mathsf{wedge\usc{}in}_{A,B}}"{near start,xshift=1ex}] \\
& & A\times B
\end{tikzcd}
\end{equation*}
Show that the fiber of the wedge inclusion $A\vee B\to A\times B$ is equivalent to $\join{\loopspace{B}}{\loopspace{A}}$.
\item Let $f:X\vee X\to X$ be the map defined by the universal property of the wedge as indicated in the diagram
\begin{equation*}
\begin{tikzcd}
\unit \arrow[d,swap,"x_0"] \arrow[r,"x_0"] \arrow[dr, phantom, "\ulcorner", very near end] & X \arrow[d,"\inr"] \arrow[ddr,bend left=15,"{\idfunc[X]}"] \\
X \arrow[r,"\inl"] \arrow[drr,bend right=15,swap,"{\idfunc[X]}"] & X\vee X \arrow[dr,densely dotted,near start,swap,"f"] \\
& & X.
\end{tikzcd}
\end{equation*}
\begin{subexenum}
\item Show that $\eqv{\fib{f}{x_0}}{\susp\loopspace{X}}$.
\item Show that $\eqv{\mathsf{cof}_f}{\susp X}$.
\end{subexenum}
\item Consider a pushout square
\begin{equation*}
\begin{tikzcd}
S \arrow[r,"g"] \arrow[d,swap,"f"] & B \arrow[d,"j"] \\
A \arrow[r,swap,"i"] & X,
\end{tikzcd}
\end{equation*}
and suppose that $f$ is an embedding. Show that $j$ is an embedding, and that the square is also a pullback square.
\end{exercises}


\subsection{Calculating Vertical Velocities}

\subsubsection{Grid Velocity}
The vertical grid moves as a consequence of using a $\sigma$--coordinate system. The grid velocity is
\begin{equation}
  \label{kin.eq.grid_velo}
  w^{\text{grid}}(\sigma)=\frac{\pd s}{\pd t}+\vec u\cdot\vec\nabla s-\sigma\left(\frac{\pd H}{\pd t}+\vec u\cdot\vec\nabla H\right)
\end{equation}
The numerical implementation of Equation \eqref{kin.eq.grid_velo} is straight--forward.

\subsubsection{Vertical Velocity}
The discretised version of the vertical velocity equation \eqref{kin.eq.vert_velo_scaled} is slightly more compilicated because the horizontal velocities are calculated on the $(r,s)$ grid. The vertical velocity at the ice base is $w_{i,j,N}=w^{\text{grid}}_{i,j,N}-b_{i,j}$, where $b_{i,j}$ is the basal melt rate. Integrating from the bottom, the vertical velocity is then
\begin{equation}
  \label{kin.eq.wvel_unc}
  \begin{split}
  w_{i,j,k}=-\sum_{\tilde{k}=N-1}^1\left\{\mathcal{H}_{i,j}\left(\frac{u^x_{i,j,k}+u^x_{i,j,k+1}}{2}+\frac{v^y_{i,j,k}+v^y_{i,j,k+1}}{2}\right)(\sigma_{k+1}-\sigma_k)\right. \\
     +(\tilde{u}_{i,j,k+1}-\tilde{u}_{i,j,k})  \left(\tilde{s}^x_{i,j}-\frac12(\sigma_{k+1}+\sigma_k)\tilde{H}^x_{i,j}\right)  \\
     \left.+(\tilde{v}_{i,j,k+1}-\tilde{v}_{i,j,k})  \left(\tilde{s}^y_{i,j}-\frac12(\sigma_{k+1}+\sigma_k)\tilde{H}^y_{i,j}\right)\right\} + w_{i,j,N}
  \end{split}
\end{equation}
with the weighted ice thickness
\begin{equation*}
  \begin{split}
  \mathcal{H}_{i,j}=\frac{4H_{i,j}+2(H_{i-1,j}+H_{i+1,j}+H_{i,j-1}+H_{i,j+1})}{16}\\
  +\frac{H_{i-1,j-1}+H_{i+1,j-1}+H_{i+1,j+1}+H_{i-1,j+1}}{16}
  \end{split}
\end{equation*}

This scheme produces vertical velocities at the ice divide which are too small. The vertical velocities on the ice surface are given by the upper kinematic boundary condition, Equation \eqref{kin.eq.upper_bc}. Equation \eqref{kin.eq.wvel_unc} can be corrected with:
\begin{equation}
  \label{kin.eq.wvel_cor}
   w^\ast_{i,j,k}=w_{i,j,k}-(1-\sigma_k)(w_{i,j,k}-{w_s}_{i,j}),
\end{equation}
where ${w_s}_{i,j}$ is the vertical velocity at the ice surface given by \eqref{kin.eq.upper_bc}. Figure \ref{kin.fig.w_profile} shows the different vertical velocities at the ice surface.
\begin{figure}[htbp]
  \centering
  \includegraphics{\dir/gnu/w_profile.eps}
  \caption{Vertical ice surface velocities of the EISMINT-1 moving margin experiment.}
  \label{kin.fig.w_profile}
\end{figure}
The difference between the vertical velocities calculated by the model and the vertical velocities given by \eqref{kin.eq.upper_bc} at the ice margin are due to the fact that temperatures and velocities are only calculated when the ice is thicker than a certain threshold value which is not met at the ice margin.

Figure \ref{kin.fig.wt_sigma} shows vertical profiles of the vertical velocity at the ice divide and a point half--way between the divide and the domain margin. A corresponding temperature profile is also shown since the vertical velocity determines the vertical temperature advection (see Section \ref{temp.sec.vert_ad}).
\begin{figure}[htbp]
  \centering
  \includegraphics{\dir/gnu/wt_sigma.eps}
  \caption{Vertical velocity and temperature distribution for columns at the ice divide and a point half--way between the divide and the domain margin.}
  \label{kin.fig.wt_sigma}
\end{figure}


%---------------------------Shape and Size-----------------------------
\section{Shape and Size\label{s:quad-shape-and-size}}

Let $R$ be the relative size squared as defined in \S\ref{s:quad-rel-size-squared}
and $S$ be the shape as defined in \S\ref{s:quad-shape}.
The shape and size metric is the product of these two numbers:
\[
q = R S.
\]

\quadmetrictable{shape and size}%
{$1$}%                                      Dimension
{$[0.2,1]$}%                                Acceptable range
{$[0,1]$}%                                  Normal range
{$[0,1]$}%                                  Full range
{Dependent on $\overline{A}$}%              Unit square
{\cite{knu:03}}%                            Citation
{v\_quad\_shape\_and\_size}%                Verdict function name


\documentclass[en,12pt]{elegantpaper}

\begin{document}
    \section*{1}
    \noindent Because $\mu_i=\beta_1+\beta_2z_i$, then
    \begin{align*}
        f(y_i|\mu_i,\sigma)&=\frac{1}{\sqrt{2\pi}\sigma}\exp\left(-\frac{(y_i-(\beta_1+\beta_2z_i))^2}{2\sigma^2}\right)\\
        &=\frac{1}{\sqrt{2\pi}\sigma}\exp\left(-\frac{1}{2\sigma^2}y_i^2+\frac{\beta_1}{\sigma^2}y_i+\frac{\beta_2z_i}{\sigma^2}y_i-\frac{(\beta_1+\beta_2z_i)^2}{\sigma^2}\right).
    \end{align*}
    $\eta=(\frac{\beta_1}{\sigma^2}, \frac{\beta_2z_i}{\sigma^2}, -\frac{1}{\sqrt{2\pi}\sigma})$. So, $\mathcal{E}=\mathbb{R}\times\mathbb{R}\times(-\infty,0)$.
\end{document}


\subsection{The Crank--Nicolson Method}
\begin{frame}{The Crank-Nicolson Method}

\begin{block}{}
   \center{symmetry in the construction of difference equations \\ $\rightarrow$
better accurancy}
 \end{block}

\begin{equation}\underline{\frac{\partial u}{\partial t} \Big \vert _{A}\cong \frac{u(x,t) - u(x,t - h)}{k}}\end{equation} w oparciu o punkty symetryczne wzgl. A

 \centerline{\includegraphics[width = 1 \linewidth]{img/23/crank}}
\end{frame}

\begin{frame}
\begin{equation} \frac{\partial ^2 u}{\partial x^2} \Big \vert _{4}\approx \frac{u(x - h,t - k) - 2 \cdot u(x,t - h) + u(x + h, t-k)}{h^2}\end{equation}
\begin{equation} \frac{\partial ^2 u}{\partial x^2} \Big \vert _{0}\approx \frac{u(x - h,t) - 2 \cdot u(x,t) + u(x + h, t)}{h^2} \end{equation}
to:
\begin{equation} \frac{\partial ^2 u}{\partial x^2} \big \vert _{A} = \frac{1}{2} \cdot \left ( \frac{\partial ^2 u}{\partial x^2} \Big \vert _{0} + \frac{\partial ^2 u}{\partial x^2} \Big \vert _{4} \right )\end{equation}
\textbf{W met. ,,Implicit'' wprowadzamy:}
\begin{multline} \lambda \cdot u(x-h,t) - 2 \cdot (1+\lambda)\cdot u(x,t) + \lambda \cdot (x+h,t) = \\
 -\lambda \cdot (x-h,t-k) - 2 \cdot (1-\lambda)u(x,t-k) - \lambda \cdot u(x+h,t-k)\end{multline}
czyli:
$$ \underline{\lambda \cdot u_3 - 3\cdot (1+\lambda)u_0 + \lambda u_1 = -\lambda \cdot u_7 - 2(1-\lambda)u_4 - \lambda u_8}$$
\end{frame}