%!TEX root = main.tex

\section{Driver strategies and optimization algorithms}
\label{sec:driver_strategies}
We now describe the different driver strategies, which are defined based on the
set of actions {\actionsset} at the driver's disposal. We also show how to
optimally solve
the {\originalproblem} problem in polynomial time for different sets {\actionsset}.

For the rest of the section, we will denote by
$\cumulativeearning{i}{b}{t}$ the \emph{total expected future earnings} of a driver who is in zone $i$ at time $t$ with
budget $b$ time units remaining. Hence,
the {\totalexpectedearnings} of a driver can be expressed as $\cumulativeearning{\homezone}{B}{N}$.

If a driver at zone $i$ at time $t$ with $b$ budget units remaining either takes a passenger ride to zone $j$
or relocates to zone $j$, that trip ends at time
$t' = t + \tau^t(i,j)$ with remaining budget $b' = b - \tau^t(i,j)$. The
total expected future earnings at that point for the driver
is: {\cumulativeearning{j}{b'}{t'}.
Let {\inducedearningvector{i}{b,t}} denotes the vector of such
cumulative earnings across different zones $j$ induced when a driver takes an  {\getpassengeraction}
action i.e., $\inducedearningvector{i}{b,t} = \big[\cumulativeearning{j}{b'}{t'}\big]_{j \in \cityzones}$.

%%Given the above,
We now define the driver strategies as well as the
solutions to the instances of the {\originalproblem} problem they induce.

\spara{The {\relocationflexible} strategy:}
This is the most general strategy where a driver has complete freedom for choices regarding work schedule as well relocation to different zones. Specifically, a driver has a budget constraint of $B$ time units to be consumed over a finite horizon $N$ time units. An idle driver in zone $i$ following this strategy has following set of available choices,
\begin{equation}
\actionsset =  \{\getpassengeraction, \gohomeaction\} \cup \{\relocateaction | \forall j \in \cityzones, j \neq i \}
\end{equation}
Note that we restrict the {\relocate} actions to ones which do not result in $t \geq N$ or $b < 0$.

A driver following the {\relocationflexible} strategy chooses the action that maximizes {\totalexpectedearnings}.
  For this strategy, the solution to
the {\originalproblem} problem can be found by the following dynamic programming (DP)
recurrence:
\begin{eqnarray}
\label{eq:relocationflexible_strategy}
\cumulativeearning{i}{b}{t} = \max_{a \in \actionsset}
    \begin{cases}
    \empiricaltransitionmatrix_{i} (\rewardsmatrix_{i} +  \inducedearningvector{i}{b,t}), &\textrm{  if } a = \getpassengeraction\\ \\
    -cost(i,\homezone) + \cumulativeearning{\homezone}{b}{t'}, &\textrm{  if } a = \gohomeaction \\ \\
    \max_{j} \{-cost(i,j) + \cumulativeearning{j}{b'}{t'}\}, &\textrm{  if } a = \relocateaction
    \end{cases}
\end{eqnarray}
Each of the $O(n N B)$ entries in the output of this dynamic program involves consideration of at most $O(n)$ actions.
Hence, the solution to the {\originalproblem} problem can be found in $O(n^2 N B)$ time.

\spara{Other strategies:} In addition to the general {\relocationflexible} strategy, we also
consider the following three special cases to model other plausible strategies of ride-hailing drivers:
the {\naive}, the {\relocation} and the {\flexible} strategies.

In the {\naive} strategy, a driver performs a random walk over the city on weekdays from 9AM - 5PM, with locations dictated exclusively by the passengers picked up. At the end of every passenger ride, the driver waits in the current zone for next passenger pickup.
Hence, the only allowable action is {\getpassenger}.

In the {\relocation} strategy, an idle driver in zone $i$ has two choices: {\getpassenger} and {\relocate}. Hence, the set of allowable actions for a driver contains $n$ different actions, one of which is {\getpassenger} and $(n-1)$ {\relocate} actions, one for each different city zone.  Thus: $
\actionsset =  \{\getpassengeraction\} \cup \{\relocateaction | \forall j \in \cityzones, j \neq i \}
$.
We remove from consideration the zones where relocating exhausts the budget or where $t \geq N$.

In the {\flexible} strategy, a driver has the flexibility to decide working times, modeling a driver who uses heuristics to decide the most profitable times to work.   As a result, we impose an additional constraint of a working time budget $B$ that a driver can split over a finite horizon of $N$ time units. Thus, this strategy aims to figure out an optimal
in-expectation work schedule for the driver.
At any stage, a driver can log out of the on-demand ride service and return to home zone. Hence, the set of allowable actions for a driver contains 2 different actions, {\getpassenger} and {\gohome}.  Thus: $
\actionsset = \{\getpassengeraction, \gohomeaction\}$.
It is common for drivers to structure their day around a desired target earning, rather than a time budget.
The {\flexible} strategy also naturally computes a schedule that
minimizes working time required for achieving the desired target earning.

Solving {\originalproblem} for the {\naive}, the {\relocation} and the
{\flexible} strategies can be done by streamlined versions of the DP presented in
Eq.~\eqref{eq:relocationflexible_strategy}; the details
are omitted due to space constraints.

\begin{comment}
\iffalse
We now consider strategic behavior, modeled through a set of strategies for how
a rational Uber driver might undertake to maximize profit over the course of a
40-hour workweek.

In the {\em naive} baseline strategy, a driver simply drives from 9-5,
waiting in place for each subsequent ride and returning home at the end of each day.  Next,
we introduce the ability of a driver to {\em relocate} to any preferred location in the
city before waiting for a subsequent ride.  Then, we allow each driver to maintain a
{\em flexible} schedule, by selectively choosing the specific hours worked (while
keeping the total work week constant).  When considered jointly, a driver who acts
strategically both by relocating and by using a flexible strategy is optimizing both
over time and space (location).  Finally, we consider an entirely different strategy,
modeling drivers who use a naive strategy to work towards an {\em earnings goal}, for
example, driving a five-day workweek, but stopping when they have earned \$100 a day.  Such a
strategy can be compared against the others on a ratable basis, i.e., \$/hour earned.

Formally, we model these driver behaviors as a set of $n+2$ actions $A$ they can potentially
take after completion of each ride:
\begin{equation}
\mbox{
$A$ = \{{\getpassenger}, {\gohome}, {\relocate} to zone $j$\}
}
\end{equation}

For a driver who may take all the available actions,
acting strategically about relocation and flexible scheduling, she maximizes total expected
earnings (at time $t$, location $i$, and remaining time budget $b$) over all actions as:

%\begin{eqnarray}
%\label{eq:relocationflexible_strategy}
%\cumulativeearning{i}{t,b} &=& \max %_{a \in \actionsset}
%    \begin{cases}
%    \empiricaltransitionmatrix_{i}^{t} (\rewardsmatrix_{i}^{t} +  \inducedearningvector{i}{t,b}{}), &\textrm{//  {\getpassenger }} \\ \\
%    r^t(i,\homezone) + \cumulativeearning{\homezone}{t',b}, &\textrm{//  {\gohome}} \\ \\
%    \max_{j} \bigg\{r^t(i,j) + \cumulativeearning{j}{t',b'}\bigg\} &\textrm{//  {\relocate} to zone $j$}
%    \end{cases}
%\end{eqnarray}

We can find an optimal in expectation policy by reasoning about Eq.(\ref{eq:relocationflexible_strategy}) as a dynamic programming (DP)
recurrence, and thus building up and tracking optimal action choices.  Since each of O$(n T B)$ entries involves consideration of at most
$n+2$ actions, computing the optimal policy takes O($n^2 T B$) time.  Solving for alternative strategic behavior entails similar, but
simpler, DP approaches.
\fi

In the relocation strategy, an idle driver in zone $i$ has two choices viz., {\getpassenger} and
Hence, the set of allowable actions for a driver contains $n$ different actions, one of which is {\getpassenger} and $(n-1)$ {\relocate} actions, one for each different city zone.

In the flexible schedule strategy, a driver has the flexibility to decided working times. As a result, we impose an additional constraint of a working time budget $B$ that a driver can split over a finite horizon of $N$ time units. Thus, this strategy aims to figure out an optimal in expectation work schedule for the driver. At any stage, a driver can log out of the on-demand ride service and return to home zone. Hence, the set of allowable actions for a driver contains 2 different actions, {\getpassenger} and

In this section, we discuss five kinds of on-demand ride service
driver strategies.
\begin{enumerate}
    \item {\relocation}
    \item {\flexible}
    \item {\relocationflexible}
    \item {\earningsgoal}
\end{enumerate}

In each of the above strategy, a driver has different sets of actions available to choose from at any stage. Our goal is to compare the optimal policies for each of the strategies, allowing us to devise an overall optimal in expectation strategy for a driver.

\subsection{\naive}
In the naive strategy, a driver performs a random walk over the city. At the end of every passenger ride, the driver waits in the current zone for next passenger pickup. Hence, the only allowable action is {\getpassenger}.
\begin{equation}
\end{equation}
We can calculate cumulative earnings of a driver following a naive strategy at any stage as follows,
\begin{eqnarray}
\label{eq:naive_strategy}
\cumulativeearning{i}{t} &=& \empiricaltransitionmatrix_{i}^{t} (\rewardsmatrix_{i}^{t} +  \inducedearningvector{i}{t}{\getpassengeraction})
\end{eqnarray}
The naive strategy accounts for unsuccessful cases where a driver fails to get a passenger in the current time unit as well. It should be noted that a driver in this strategy does not have the flexibility to choose working times. Hence, $B=N$. This allows us to drop the superscript $b$ from Eq.(\ref{eq:naive_strategy}) without any loss of generality.

\subsection{\relocation}
\begin{equation}
In the relocation strategy, an idle driver in zone $i$ has two choices viz., {\getpassenger} and {\relocate}. Hence, the set of allowable actions for a driver contains $n$ different actions, one of which is {\getpassenger} and $(n-1)$ {\relocate} actions, one for each different city zone.
\actionsset =  \{\getpassengeraction\} \cup \{\relocateaction | \forall j \in \cityzones, j \neq i \}
\end{equation}
We can further restrict the number of {\relocate} actions by removing from consideration the zones where relocating causes a situation where $t \geq N$.

A driver following relocation strategy chooses the action that maximises {\totalexpectedearnings}. This choice is expressed in recursive manner as follows,
\begin{eqnarray}
\label{eq:relocation_strategy}
\cumulativeearning{i}{t} &=& \max_{a \in \actionsset}
    \begin{cases}
    \empiricaltransitionmatrix_{i}^{t} (\rewardsmatrix_{i}^{t} +  \inducedearningvector{i}{t}{a}), &\textrm{  if } a = \getpassengeraction\\ \\
    \max_{j} \bigg\{r^t(i,j) + \cumulativeearning{j}{t'}\bigg\}, &\textrm{  if } a = \relocateaction
    \end{cases}
\end{eqnarray}
While solving Eq.(\ref{eq:relocation_strategy}), we also get an optimal policy for relocation strategy by keeping track of optimal action choices. Similar to the {\naive}, the driver does not have flexibility to choose work timings, hence we drop the superscript $b$ from Eq.(\ref{eq:relocation_strategy}).

\subsection{\flexible}

In the flexible schedule strategy, a driver has the flexibility to decided working times. As a result, we impose an additional constraint of a working time budget $B$ that a driver can split over a finite horizon of $N$ time units. Thus, this strategy aims to figure out an optimal in expectation work schedule for the driver. At any stage, a driver can log out of the on-demand ride service and return to home zone. Hence, the set of allowable actions for a driver contains 2 different actions, {\getpassenger} and {\gohome}.
\begin{equation}
\actionsset = \{\getpassengeraction, \gohomeaction\}
\end{equation}
A driver following this strategy chooses an action that maximizes {\totalexpectedearnings}. This choice is expressed in recursive manner as follows,
\begin{eqnarray}
\label{eq:flexible_strategy}
\cumulativeearning{i}{t,b} &=& \max_{a \in \actionsset}
    \begin{cases}
    \empiricaltransitionmatrix_{i}^{t} (\rewardsmatrix_{i}^{t} +  \inducedearningvector{i}{t,b}{a}), &\textrm{  if } a = \getpassengeraction\\ \\
    r^t(i,\homezone) + \cumulativeearning{\homezone}{t',b}, &\textrm{  if } a = \gohomeaction
    \end{cases}
\end{eqnarray}
Similar to the {\relocation}, we can find an optimal in expectation work schedule by keeping track of optimal action choices while solving Eq.(\ref{eq:flexible_strategy}).

\subsection{\relocationflexible}

This is the most general strategy formed by combining the {\relocation} as well as the {\flexible} described earlier. In this strategy, a driver has complete freedom for choices regarding work schedule as well relocation to different zones, in order to maximize {\totalexpectedearnings}. Just like the {\flexible}, a driver has a budget constraint of $B$ time units to be consumed over a finite horizon $N$ time units. An idle driver in zone $i$ following this strategy has folowing set of available choices,
\begin{equation}
\actionsset =  \{\getpassengeraction, \gohomeaction\} \cup \{\relocateaction | \forall j \in \cityzones, j \neq i \}
\end{equation}
Similar to {\relocation}, we restrict the {\relocate} actions to ones which do not result in $t \geq N$ or $b \geq B$.

A driver following the relocation with flexible schedule strategy chooses the action that maximises {\totalexpectedearnings}. This choice can be expressed as follows,
\begin{eqnarray}
\label{eq:relocationflexible_strategy}
\cumulativeearning{i}{t,b} &=& \max_{a \in \actionsset}
    \begin{cases}
    \empiricaltransitionmatrix_{i}^{t} (\rewardsmatrix_{i}^{t} +  \inducedearningvector{i}{t,b}{a}), &\textrm{  if } a = \getpassengeraction\\ \\
    r^t(i,\homezone) + \cumulativeearning{\homezone}{t',b}, &\textrm{  if } a = \gohomeaction \\ \\
    \max_{j} \bigg\{r^t(i,j) + \cumulativeearning{j}{t',b'}\bigg\}, &\textrm{  if } a = \relocateaction
    \end{cases}
\end{eqnarray}
As earlier, we can find an optimal in expectation policy by keeping track of optimal action choices while solving Eq.(\ref{eq:relocationflexible_strategy})

\subsection{\earningsgoal}
In the fixed earnings goal strategy, a driver sets an earnings goal before logging in into the on-demand ride service and drives until fixed goal is reached.
\todo[Harshal]{Write in this section how this strategy solution is a part of the previous strategies already discussed.}
\end{comment}


\documentclass[]{article}
\usepackage{amsmath}

%opening
\title{MTH 343 Numerical Analysis: Quiz 1}
\author{Sheikh Abdul Raheem Ali}

\begin{document}

\maketitle

\section*{PAGE 28/29:}

\begin{enumerate}
	\item[1C] Compute the absolute and relative error in approximations of $ p \text{ by } p^* $.
	\begin{align*}
	p = \pi && p^* = 3.1416
	\end{align*}
	\item[2A] Find the largest interval in which $ p^* $ must lie to approximate $ p $ with relative error at most $ 10^-4 $.
	\begin{align*}
		p = \sqrt{2}
	\end{align*}
	\item[3A,B] Suppose $ p^* $ must approximate $ p $ with relative error at most $ 10^{-3} $. Find the largest interval in which $ p^* $ must lie for:
	\begin{align*}
	p_a = 150 && p_b = 900
	\end{align*}
	\item[4] Perform the following computations (i) exactly, (ii) using three-digit chopping arithmetic, and (iii) using three-digit rounding arithmetic. (iv) Compute the relative errors in parts (ii) and (iii).
	\begin{align*}
	\frac{4}{5} + \frac{1}{3}
	\end{align*}
	\begin{align*}
	\frac{4}{5} \cdot \frac{1}{3}
	\end{align*}
	\begin{align*}
	(\frac{1}{3} - \frac{3}{11}) + \frac{3}{20}
	\end{align*}
	\begin{align*}
	(\frac{1}{3} + \frac{3}{11}) - \frac{3}{20}
	\end{align*}

	\item[5C,E,G] Use three-digit rounding arithmetic to perform the following calculations. Compute the absolute error and relative error with the exact value determined to at least five digits.

	\begin{align*}
		(121 - 0.327) - 119
	\end{align*}

	\begin{align*}
		\frac{\frac{13}{14} - \frac{6}{7}}{2e - 5.4}
	\end{align*}

	\begin{align*}
		(\frac{2}{9})\cdot(\frac{9}{7})
	\end{align*}

	\item[6E] Repeat exercise 5 using four digit rounding arithmetic.

	\item[15 A,B] Use the 64-bit long real format to find the decimal equivalent of the following floating-point machine numbers:

	\begin{enumerate}
		\item 0 10000001010 1001001 100000000000000000000000000000000000000000
		\item 1 10000001010 1001001 100000000000000000000000000000000000000000
	\end{enumerate}
\end{enumerate}

\section*{PAGE 54/55:}

\begin{enumerate}
	\item[1] Use the Bisection method to find $ p_3 $ for $ f(x) = \sqrt{x} - \cos x \text{on} [0,1]$.
	\item[3 A,B] Use the Bisection method to find solutions accurate to within $ 10^{-2} $ for $ x^4 - 2x^3 - 4x^2 + 4x +4 = 0 $ on the intervals [-2,-1] and [0, 2].
	\item[5 B,C 6B] Use the Bisection method to find solutions, accurate to within $ 10^{-5} $ for the following problems:
	\begin{itemize}
		\item $ 2x + 3\cos x - e^x = 0 $ for $ 1 \le x \le 2 $ and $ 2 \le x \le 4 $
		\item $ x^2 - 4x + 4 - \ln x = 0 $ for $ 0 \le x \le 0.5 $ and $ 0.5 \le x \le 1 $
		\item $ e^x - x^2 +3x - 2 = 0 $ for $ 0 \le x \le 1 $
	\end{itemize}

	\item[11A] Let $ f(x) = (x+2)(x+1)x(x-1)^3(x-2). $ To which zero of f does the Bisection method converge when applied on the interval $ [-1.5, 2.5] $
	\item[13] Find an approximation to $ \sqrt{25} $ correct to within $ 10^{-4} $ using the Bisection Algorithm.
\end{enumerate}

\end{document}


% !TEX options=--shell-escape
\documentclass [12pt]{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{float}
\usepackage{multirow}
\usepackage{xcolor}
\usepackage{algorithmic}
\usepackage [ruled,vlined,commentsnumbered,titlenotnumbered]{algorithm2e} \usepackage{array}
\usepackage{booktabs}
\usepackage{url}
\usepackage{parskip}
\usepackage [margin=1in]{geometry}
\usepackage [T1]{fontenc}
\usepackage{cmbright}
\usepackage [many]{tcolorbox}
\usepackage [colorlinks = true,
            linkcolor = blue,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = blue]{hyperref}
\usepackage{enumitem}
\usepackage{xparse}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{csquotes}
\usepackage[cache=false]{minted}
\usepackage{mdframed}
\usepackage{tikz}
\usetikzlibrary{shapes.symbols}
\newtheorem{theorem}{Theorem}

\BeforeBeginEnvironment{minted}{\begin{mdframed}}
\AfterEndEnvironment{minted}{\end{mdframed}}

\DeclareTColorBox{Solution}{}{breakable, title={Solution}}
\DeclareTColorBox{Solution*}{}{breakable, title={Solution (provided)}}
\DeclareTColorBox{Instruction}{}{boxrule=0pt, boxsep=0pt, left=0.5em, right=0.5em, top=0.5em, bottom=0.5em, arc=0pt, toprule=1pt, bottomrule=1pt}
\DeclareDocumentCommand{\Expecting }{+m}{\textbf{[We are expecting:} #1\textbf{]}}
\DeclareDocumentCommand{\Points }{m}{\textbf{(#1 pt.)}}
\newcommand{\hint }[1]{\noindent{[\textbf{HINT:} \em #1 \em ]}} \newcommand{\pts }[1]{\textbf{(#1 pt.)}}

\begin{document}

{\LARGE \textbf{COMP 285 (NC A\&T, Spr `22)}\hfill \textbf{Homework 8} }
\vspace{1em}
\begin{Instruction}

\paragraph{Due.} Wednesday, April 13th, 2022 @ 11:59 PM!
\end{Instruction}

\vspace{1em}
\begin{Instruction} \paragraph{Homework Expectations:} Please see \href{https://www.comp285.ml/homework/#general-homework-information}{Homework}.
\end{Instruction}

\vspace{1em}
\begin{Instruction}

\paragraph{Exercises} The following questions are exercises. We encourage you to work with a group and discuss solutions to make sure you understand the material.

\paragraph{Points} This assignment is graded out of 50 points. However, you can get up to 60 points if you complete everything. These are not bonus points, but rather points to help make-up any parts you miss.

\end{Instruction}

\begin{centering}
\section*{Fun with Dynamic Programming}
\end{centering}

\begin{Instruction}

\paragraph{Written Problems} The following questions are to be submitted in written/typed form to gradescope.

\end{Instruction}

\section{Longest Increasing Subsequence \Points{10}}

Let $A$ be an array of length $n$ containing real numbers. A \em longest increasing subsequence \em (LIS) of $A$ is a sequence $0 \leq i_1 < i_2 < \ldots i_\ell < n$ so that $A[i_1] < A[i_2] < \cdots < A[i_\ell ]$, so that $\ell $ is as large as possible. For example, if $A = [6,3,2,5,6,4,8]$, then a LIS is $i_0 = 1, i_1 = 3, i_2 = 4, i_3 = 6$ corresponding to the subsequence $3,5,6,8$. (Notice that a longest increasing subsequence doesn't need to be unique).

In the following parts, we'll walk through the recipe that we saw in class for coming up with DP algorithms to develop an $O(n^2)$-time algorithm for finding an LIS. \footnote{If you're having trouble with this problem, take a look at Lecture 26 where we cover the Longest Common Subsequence problem. This problem is \textbf{not the same}, but is similar.}

\begin{enumerate}
  \item \Points{2} \textbf{(Identify optimal sub-structure and a recursive relationship).}

  We'll come up with the sub-problems and recursive relationship for you, although you will have to justify it. Let $D[i]$ be the length of the longest increasing subsequence of $[A[0], \ldots , A[i]]$ that ends on $A[i]$. Explain why
  $$
    D[i] = \max \left (\{ D[k] + 1\,:\, 0 \leq k < i, A[k] < A[i] \} \cup \{1\} \right ).
  $$
  \Expecting{A short informal explanation.}

  \item \Points{4} \textbf{(Develop a DP algorithm to find the value of the optimal solution)} Use the relationship about to design a dynamic programming algorithm returns the \em length \em of the longest increasing subsequence. Your algorithm should run in time $O(n^2)$ and should fill in the array $D$ defined above.

  \Expecting{Pseudocode. No justification is required.}

  \item \Points{4} \textbf{(Adapt your DP algorithm to return the optimal solution)} Adapt your algorithm above to return an actual LIS instead of its length. Your algorithm should run in time $O(n^2)$.

  \Expecting{Pseudocode \textbf{AND} a short English explanation of what your algorithm is doing. You do not need to justify that it is correct.}

\end{enumerate}

\textbf{Note:} Actually, there is an $O(n\log (n))$-time algorithm to find an LIS, which is faster than the DP solution in this exercise! This algorithm uses divide-and-conquer! While not required for this exercise, you might find it helpful to think about this problem and see if you can come up with a solution!

\section{Getting Greedy! \Points{5}}
Sometimes it can be tricky to tell when a greedy algorithm applies. Say whether or not the greedy solution would work. If it wouldn’t, give a counter example.

You have unlimited objects of different sizes, and you want to completely fill a bag with as few objects as possible.

\textbf{Proposed Greedy Solution:} Keep putting in the largest object possible given the space you have left.

\Expecting{Either 'WORKS' or 'DOES NOT WORK'. If it does not work, an example of where it doesn't work should be given as well.}

\pagebreak
\section{Housing Layout \Points{20}}
\label{sec:last}
You own $n \geq 1$ consecutive plots of lands that you can build on, and you want to build a number of houses on these plots, with each plot having at most one house. However, due to some strange laws in your city, you cannot build two houses on two consecutive plots of lands. (The other plots of lands will just be wasted, unused.)

Each plot of land is different, so building the house in the right plots is important. You have estimated the profit you would get from building a house on each plot of land to be $p[1],\dots ,p[n]$, where $p[i]$ is a positive integer representing the profit, in dollars, you would get from building a house on the $i^{\text{th}}$ plot of land.

\paragraph{Example} if the input was $ p = [21,4,6,20,2,5],$ then you should build houses in the pattern
\begin{center}
  \begin{tikzpicture}
    \foreach \i in{1,2,3,4,5,6}{
      \draw (\i -1, 0) rectangle (\i , 1);
    }
    \foreach \i in{1,4,6}{
      \node at (\i -.5, .5){\includegraphics [width=.8cm]{OpenClipArt_House_1.png}};
    }
  \end{tikzpicture}
\end{center} and you would profit by $21+20+5 = 46$ dollars. You would \textbf{not} be allowed to build houses in the pattern

\begin{center}
  \begin{tikzpicture}
    \foreach \i in{1,2,3,4,5,6}{
      \draw (\i -1, 0) rectangle (\i , 1);
    }
    \foreach \i in{1,2,4,6}{
      \node at (\i -.5, .5){\includegraphics [width=.8cm]{OpenClipArt_House_1.png}};
    }
  \end{tikzpicture}
\end{center} because there are two houses next to each other.

In this question, you will design a dynamic programming algorithm which runs in time $O(n)$ which takes as input the array $p$ and returns the maximum profit possible given $p$.\footnote{If you're having trouble with this question, revisit your `pickBerries' problem from \href{https://replit.com/@COMP285/HW2-Code}{HW2}. It's actually quite similar, but now you will implement it so that its efficient!}

\subsection{Step 1 - Optimal Substructure \Points{4}}
What sub-problems will you use in your dynamic programming algorithm? To get you started, let use define $P[i]$ (an array of length $n$) which will start will all \texttt{NULL} values. What does $P[i]$ represent?

\Expecting{A clear \textbf{English} description of the meaning of $P[i]$}.

\subsection{Step 2 - Recursive Relation \Points{4}}
What is the recursive relationship which is satisfied between the sub-problems? That is to say, how can we compute $P[i]$ using answers to ``smaller'' subproblems (depending on how you define $P[i]$, this expression will either involve $P[i-1], P[i-2]$ or $P[i+1], P[i+2]$).

\Expecting{A mathematical expression for how to compute $P[i]$.}

\subsection{Step 2 - Base Cases! \Points{2}}
What are the base cases for this recursive relationship you defined above?

\Expecting{The base cases for your recursion.}

\subsection{Step 3 - The algorithm \Points{5}}
Write pseudocode for your algorithm. Your algorithm should take as input the array $p$, and return a single number which is the maximum profit possible. Your algorithm \textbf{does not} need to output the optimal way to build houses.

\Expecting{Pseudocode \textbf{AND} a clear English description. You do not need to justify that your algorithm is correct, but correctness should follow from your reasoning in the previous part.}

\subsection{Step 4 - Where do I build? \Points{3}}
Suppose we want to know not only the maximum profit possible, but I also want to know \textbf{which} houses to build. How would you modify your solution above to answer this question?

\Expecting{A short description of what changes you'd make to your algorithm to track the houses we need to build}.

\subsection{Step 5 - Saving Space \Points{2}}
What is the space-complexity of your proposal above? If it is not $O(1)$, how would you improve your algorithm to use less space.

\Expecting{A solution above that uses $O(1)$ space, or a short description of how you'd modify the algorithm to use only $O(1)$ space.}

\pagebreak
\begin{Instruction}

\paragraph{Coding Problems} The following questions are to be submitted as a ".zip" file on Gradescope.

\end{Instruction}

\section{Coding \Points{25}}
After completing the written portion of the assignment, you should submit it to \href{https://www.gradescope.com/courses/350304}{Gradescope}.

For the coding portion, get your starter \href{https://replit.com/team/COMP285/HW8-Code}{C++ code} or \href{https://replit.com/team/COMP285/HW8-Code-Python}{Python code}.

Note that the starter code also include a few test cases you can run on repl.it. However, the full test suite is the one run on Gradescope.

Please reference the \texttt{README.md} included in your starter code for detailed instructions.

\section*{Submitting the Assignment}

This assignment is a combination of written and programming questions. Both portions of the assignment should be submitted through \href{https://www.gradescope.com/courses/350304}{Gradescope}.

The "Homework 8: Fun with Dynamic Programming" assignment is the written portion, for which you should submit a \textbf{typed} response to the non-coding questions (questions 1-\ref{sec:last}). Each response should clearly be marked with its corresponding number. You are free to use the provided templates, print the questions and write your answers, or to simply type your responses on a blank document (whatever works for you).

The "Homework 8: Coding" is the programming portion of the assignment. For this portion, download the "answers.cpp", "answers.h" (or just "answers.py") and "citations.txt" from your repl.it these files to \href{https://www.gradescope.com/courses/350304}{Gradescope}. You can upload the assignment as many times as you want.

\end{document}


%!TEX root = ../COSCFair.tex
\section{The COSCFair Framework} \label{sec:framework}

In this section, we explain how the COSCFair framework is constructed and introduce the type of components used to implement each step. Our framework consists of four main steps and components. It starts with pre-processing step for the dataset, where we identify the \textbf{subgroup IDs} of each sample. Then, we apply a clustering algorithm on the training set to discover the natural groups (clusters) it contains, where the samples in each of these groups are closer to each other than the others. The next step is dividing the training set into \textbf{cluster sets}, where the training samples are grouped according to their cluster IDs. Then, we oversample each of these cluster sets based on the subgroup IDs of the samples to achieve an equal number of samples for each subgroup that exists in the cluster. The final step is the classification step, where the classifier training and class label predictions of the test set occur. Here, we have studied three possible strategies for classifier training and label prediction, which are discussed further in Section \ref{ssec:str_classf}. The pseudocode of COSCFair is given in Algorithm \ref{alg1}.

\subsection{Data Preparation}\label{ssec:dataprep}

The data preparation step consists of several sub-steps, which are identifying the subgroup IDs, adding this information as a new variable to the dataset, and splitting the dataset as training and test. However, identifying the subgroup labels of each sample is one of the most important components of the framework, which we will discuss here in more detail. The subgroups in datasets are discovered based on the total number of binary sensitive attributes and the binary decision label, which corresponds to 2\textsuperscript{n}. In our experiments, we have two binary sensitive attributes and one binary class label in all the datasets, which corresponds to eight subgroups per dataset. Without considering the class labels (2\textsuperscript{n-1}), these subgroups are later identified as the privileged and unprivileged subgroups. For example, there are four main subgroups in each dataset that we use in our experiments.

There are two base groups that are always privileged or unprivileged. If a subgroup has unfavorable values in both sensitive attributes, that subgroup becomes the most unprivileged subgroup in the dataset. If a subgroup has favorable values for both sensitive attributes, then that subgroup becomes the most privileged subgroup. The other subgroups that have different combinations of favorable and unfavorable values for different sensitive attributes should be interpreted as both potentially privileged and unprivileged subgroups. Thus, while investigating their position in a dataset, they should be tested as both privileged and unprivileged groups (see Table \ref{Table5}).

After the subgroup ID variable is added, the sensitive attributes are removed from the dataset since the new subgroup IDs contain information regarding these sensitive attributes. Finally, if a dataset contains a set of numerical variables, these variables should be standardized in training and test sets separately so that they will not have domination over other variables in clustering and classification steps.

\input{Sections/pseudocode.tex}\label{alg1}

\subsection{Clustering}\label{ssec:clust}

Clustering step in COSCFair framework is implemented with the \textbf{fuzzy c-means clustering} \cite{fuzzyc}, which is a soft clustering algorithm that allows each sample in a dataset to be assigned to more than one cluster. In fuzzy clustering, each sample belongs to a cluster with a certain probability which adds up to 1 in total. The algorithm works with the core idea of assigning the samples to clusters in a way that the samples in the same cluster are as similar as possible, while the samples in different clusters are as dissimilar as possible. Clusters are formed based on a distance measure (such as Euclidean distance), which is used to calculate (and minimize sum of) the distances between the samples and the assigned cluster centroids. Thus, it is important to apply standardization on the numerical features of the datasets in data preparation step to prevent the unjustified domination these features.

Fuzzy c-means requires the number of clusters to be given as an input. Thus, we run the fuzzy c-means multiple times using predefined list of values for the number of clusters. In each run, compute the \textbf{fuzzy partition coefficient} (FPC) and the \textbf{silhouette score}. We choose the number that yields the best combination of these two values as the optimal number of clusters. Before using fuzzy c-means, it is recommended to use a dimensionality reduction technique such as principal component analysis (PCA) if the whole dataset consists of numerical variables, or the Factor Analysis of Mixed Data (FAMD) if the dataset consists of both categorical and numerical variables.

\subsection{Oversampling}\label{ssec:oversamp}

After splitting the training set into cluster sets using the cluster memberships of training samples, we oversample each cluster set, where the oversampling criterion is the subgroup IDs of the samples(2\textsuperscript{n}). We use subgroup IDs to oversample so that we can obtain an equal representation for each subgroup in each cluster, where they all have precisely the same number of samples with both positive and negative outcomes. We use Synthetic Minority Oversampling Technique (SMOTE) \cite{smote} to oversample our cluster sets, although different oversampling algorithms can also be used in this step. SMOTE creates new synthetic samples by drawing a line in between two samples that are closer to each other in feature space that belongs to the class which needs to be oversampled, then it produces the synthetic samples along these lines. Since these synthetic samples are created based on the line between two existing samples, these two samples must be close enough to each other to ensure good quality of synthetic sample production. Therefore, we cluster the training set into smaller cluster sets where the samples used for oversampling in these clusters are closer to each other, which decreases the distances between the samples that belong to the same subgroup for a better quality of oversampling procedure.

The main reason why oversampling is used to mitigate bias is because most of the datasets containing bias are actually imbalanced, where different subgroups are not represented equally in terms of number of positive and negative samples per subgroup. This problem can easily be spotted on Table \ref{Table2} in all of the datasets. The most privileged subgroups have the most number of samples in German and Adult datasets, in which of these samples have more positive class labeled samples than other subgroups. This situation is different in COMPAS dataset, where the most privileged group has the least number of samples while the most unprivileged group has the most. However, it is important to note that while all other subgroups have more positive labeled samples, the most unprivileged group has more negative labeled sentences, which is still an imbalance problem that requires oversampling for equal representation of each subgroup with both positive and negative outcomes.

\input{Tables/Table2}

\subsection{Classification}\label{ssec:str_classf}

In this step, a classification algorithm of choice or multiple classification algorithms of the same type (i.e. logistic regression) are trained depending on the strategy that will be followed. After the classifiers are trained, the class labels of the test set are predicted. However, every strategy has its own unique prediction procedure, which will be described in detail in their respective sections. We should note that during classifier training and test set prediction, the sensitive attributes and the subgroup IDs are not used, which ensures \textit{Fairness Through Unawareness}.

\stitle{Strategy 1:} This strategy is the most similar one to the mainstream classification training and prediction. After each cluster set is oversampled, they are concatenated back together to form a single large training set. Then, only one classifier is trained with this training set and the class labels are predicted based on only this classifier.

\stitle{Strategy 2:} This strategy requires training multiple classifiers, which means that one classifier will be trained based on each oversampled cluster set. Before the class labels of the test set are predicted, each sample's cluster membership is predicted by using the fuzzy c-means clustering object created in the second step. The clustering object will retrieve the ID of a cluster for the sample in which the sample has the highest probability of membership. At the beginning of this process, the classifiers that are trained based on the cluster sets which do not contain samples from the same subgroup as the test sample are discarded. After that, the remaining classifiers are considered for the rest of the process. Next, the classifier object that is trained based on the cluster set which has the same ID as the predicted cluster ID for the given test sample is used to predict the class label of that sample.

\stitle{Strategy 3:} Similar to the second strategy, our final strategy also requires training multiple classifiers using the oversampled cluster sets. However, instead of choosing one classifier this time, all the trained classifiers are taken into consideration while predicting the class label of a test sample. First, the fuzzy c-means clustering object is used to retrieve the probabilities of the test sample belonging to each cluster. After that, some of the cluster IDs are discarded if their cluster sets did not contain samples from the same subgroup as the test sample. Next, the classifiers are trained with the remaining cluster sets. Finally, in the prediction step, the cluster membership probabilities of a sample that are retrieved for the remaining clusters are used as a weight for the predicted class label from each corresponding classifier. The weighting is applied to the predicted outcomes by dividing the probability of each eligible cluster \textit{c} by the sum of the probabilities of all eligible clusters and multiplying it with the predicted outcome of the classifier that is trained with the cluster set having the same ID as the cluster \textit{c}. Then, all of the weighted prediction values are summed into a single value. If this value is greater or equal to 0.5, the weighted prediction label becomes 1, otherwise 0. Our experimental results show that the best strategy for COSCFair framework is Strategy3, and thus it is used in the final comparison with the other baseline methods.
% This weighing process can be formulated as:
% \[\sum_{i=0}^{i_{clusts}}[(Prob_{cluster_{i}}/\sum_{n=0}^{n_{clusts}}Prob_{cluster_{n}})*PredictedLabel_{classifier_{i}}]\]

% Where i\textsubscript{clusts} indicates the number of eligible clusters left after some of the clusters are discarded and it is equal to n\textsubscript{clusts}.


%% SECTION HEADER /////////////////////////////////////////////////////////////////////////////////////
\section{Data acquisition}
\label{sec41}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In this work, we have generated a large dataset of \(475\) cases of a full wavefield of propagating Lamb waves in a plate made of carbon fibre-reinforced plastic (CFRP).
The in-house code of the time-domain spectral element method was used for simulation of Lamb wave interaction with delamination~\cite{Kudela2020}.
It should be added that despite the utilisation of the parallel code of the spectral element method which was run on the Tesla K20X GPU card, the computation of the dataset (consisting of 475 cases) took about 3 months.
For each case, single delamination was modelled by using the method of splitting nodes between appropriate spectral elements.
It was assumed that the composite laminate is made of eight layers of a total thickness of 3.9 mm.
The delamination was modelled between the third and fourth layer (see Fig.~\ref{fig:plate_setup} for details).
It should be noted that Fig.~\ref{fig:plate_setup} shows an exaggerated cross-section through the delamination.
Zero-volume delamination was assumed in the model.
Delamination spatial location was selected randomly so that the interaction of guided waves with delamination is different for each case.
It includes cases when delamination is located at the edge of the plate which is the most difficult to identify by signal processing methods.
Additionally, the size of the delamination of elliptic shape was randomly simulated by selecting the size of ellipse minor and major axis.
Also, the angle between the delamination major axis and the horizontal axis was randomly selected.
In summary the following random factors were simulated in each case:
\begin{itemize}
	\item delamination geometrical size	(ellipse minor and major axis randomly selected from the interval \(\left[10 \, \textrm{mm}, 40\, \textrm{mm}\right]\)),
	\item delamination angle (randomly selected from the interval \( \left[ 0^{\circ}, 180^{\circ} \right]\)),
	\item coordinates of the centre of delamination (randomly selected from the interval \(\left[0\, \textrm{mm}, 250\, \textrm{mm} -\delta \right]\) and \( \left[250\, \textrm{mm}+\delta, 500\, \textrm{mm} \right] \), where \(\delta = 10\, \textrm{mm}\)).
\end{itemize}
It resulted in random spatial placement of delaminations. The plate with overlayed 475 delamination cases is shown in Fig.~\ref{fig:random_delam}.
\begin{figure}
	\centering
	\includegraphics[scale=0.8]{Figures/Chapter_3/plate_delam_arrangement_MSSP.PNG}
	\caption{Setup for computing Lamb wave interactions with delamination.}
	\label{fig:plate_setup}
\end{figure}
\begin{figure}
	\centering
	\includegraphics[scale=1]{Figures/Chapter_3/dataset2_labels_ellipses.png}
	\caption{The plate with 475 cases of random delaminations.}
	\label{fig:random_delam}
\end{figure}

Guided waves were excited at the plate centre by applying equivalent piezoelectric forces.
The excitation signal had a form of sinusoid modulated by Hann window.
It was assumed that the carrier frequency is 50 kHz and the modulation frequency is 10 kHz.
A relatively low carrier frequency allowed for lower mesh density and significant computation time reduction in comparison to simulations of higher frequencies.
Additionally, the excitation signal was selected so that interaction of generated A0 Lamb wave mode with the smallest delamination can be still used as a feature for damage identification.

The output from the top and bottom surfaces of the plate in the form of particle velocities at the nodes of spectral elements were interpolated on the uniform grid of 500\(\times\)500 points by using shape functions of elements (see~\cite{Kudela2020} for more details).
It essentially resembles measurements acquired by SLDV in the transverse direction (perpendicular to the plate surface).
An example of the simulated full wavefield data on the top and bottom surfaces is presented in Fig.~\ref{fig:wavefield}.
It should be noted that stronger wave entrapment at delamination can be observed for the case of the wavefield at the top surface.
It is because the delamination within cross-section is located closer to the top surface.
It makes it easier to detect delamination by processing wavefield at the top surface.
It is better visible if the root mean square (RMS) according to Eq.~(\ref{eq:rms}) is applied to the wavefield.
The result of this operation is presented in Fig.~\ref{fig:rms}.
Based on the image analysis, the shape of the delamination can be easier to discern for the top case.
However, the methodology presented in this paper was applied to the more difficult case i.e. wavefield registered at the bottom surface of the plate.

%The dataset consisting of RMS images which were used in this research paper is available online~\cite{Kudela2020d}.

\begin{figure} [h!]
	\centering
	\begin{subfigure}[b]{0.32\textwidth}
		\centering
		\includegraphics[scale=1]{Figures/Chapter_3/96_flat_shell_Vz_1_500x500top.png}
		\caption{\(t=0.141\) ms}
		\label{fig:frame96top}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.32\textwidth}
		\centering
		\includegraphics[scale=1]{Figures/Chapter_3/128_flat_shell_Vz_1_500x500top.png}
		\caption{\(t=0.188\) ms}
		\label{fig:frame128top}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.32\textwidth}
		\centering
		\includegraphics[scale=1]{Figures/Chapter_3/164_flat_shell_Vz_1_500x500top.png}
		\caption{\(t=0.240\) ms}
		\label{fig:frame164top}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.32\textwidth}
		\centering
		\includegraphics[scale=1]{Figures/Chapter_3/96_flat_shell_Vz_1_500x500bottom.png}
		\caption{\(t=0.141\) ms}
		\label{fig:frame96bottom}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.32\textwidth}
		\centering
		\includegraphics[scale=1]{Figures/Chapter_3/128_flat_shell_Vz_1_500x500bottom.png}
		\caption{\(t=0.188\) ms}
		\label{fig:frame128bottom}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.32\textwidth}
		\centering
		\includegraphics[scale=1]{Figures/Chapter_3/164_flat_shell_Vz_1_500x500bottom.png}
		\caption{\(t=0.240\) ms}
		\label{fig:frame164bottom}
	\end{subfigure}

	\caption{Full wavefield at the top surface (a)--(c) and the bottom surface (d)--(f), respectively, at selected time instances showing the interaction of guided waves with delamination.}
	\label{fig:wavefield}
\end{figure}

\begin{figure} [h!]
	\centering
	\begin{subfigure}[b]{0.47\textwidth}
		\centering
		\includegraphics[scale=1]{Figures/Chapter_3/RMS_flat_shell_Vz_1_500x500top.png}
		\caption{top}
		\label{fig:rmstop}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.47\textwidth}
		\centering
		\includegraphics[scale=1]{Figures/Chapter_3/RMS_flat_shell_Vz_1_500x500bottom.png}
		\caption{bottom}
		\label{fig:rmsbottom}
	\end{subfigure}
	\caption{RMS of the full wavefield from the top surface of the plate (a) and the bottom surface of the plate (b).}
	\label{fig:rms}
\end{figure}


\documentclass[12pt]{article}

\usepackage{setspace}

\usepackage{xcolor, amsmath, amsfonts, amssymb, graphicx, color, fancyhdr, lipsum, scalerel, stackengine, mathrsfs, tikz-cd, mdframed, enumitem}
\usepackage[amsthm]{ntheorem}
\usepackage[mathscr]{euscript}
%set margins
\usepackage[
top    = 1.0in,
bottom = 1.0in,
left   = 1.0in,
right  = 1.0in]{geometry}

%header stuff
\setlength{\headsep}{24pt}  % space between header and text
\pagestyle{fancy}     % set pagestyle for document
\lhead{ {William Waterhouse's \it Introduction to Affine Group Schemes} } % put text in header (left side)
\rhead{Nico Courts} % put text in header (right side)
\cfoot{\it p. \thepage}
\setlength{\headheight}{15pt}
\allowdisplaybreaks

%Set of Integers
\newcommand*{\Z}{
\mathbb{Z}
}
%Set of Natural Numbers
\newcommand*{\N}{
\mathbb{N}
}
%Set of Real Numbers
\newcommand*{\R}{
\mathbb{R}
}
%Set of Complex Numbers
\newcommand*{\C}{
\mathbb{C}
}
%Field
\newcommand*{\F}{
\mathbb{F}
}
%Rationals
\newcommand*{\Q}{
\mathbb{Q}
}

%Section break
\newcommand*{\brk}{
\rule{2in}{.1pt}
}

\DeclareMathOperator{\Aut}{Aut}

%raise that Chi!
\DeclareRobustCommand{\Chi}{{\mathpalette\irchi\relax}}
\newcommand{\irchi}[2]{\raisebox{\depth}{$#1\chi$}}

%Image
\DeclareMathOperator{\im}{Im}

%Hom
\DeclareMathOperator{\Hom}{Hom}

%Coker
\DeclareMathOperator{\coker}{coker}

%characteristic
\DeclareMathOperator{\ch}{char}

%restriction
\DeclareMathOperator{\Res}{Res_H}

%socle
%restriction
\DeclareMathOperator{\Soc}{Soc}

%induction
\DeclareMathOperator{\Ind}{Ind_H^G}

%fix tilde
\let\tilde\relax
\newcommand*{\tilde}[1]{\widetilde{#1}}

\newtheorem{lem}{Lemma}[section]
\newtheorem{thm}[lem]{Theorem}
\newtheorem{defn}[lem]{Definition}

\setenumerate[0]{label=(\alph*)}

%New environments for problem solving
\newenvironment{prob}[1]{\par\smallskip
	\noindent\begin{mdframed}\small \textbf{Problem~\thesection.#1} \rmfamily\quad}{\end{mdframed}\medskip}
\newenvironment{sol}{\noindent \textbf{Solution.} \,}{\\\hspace*{\fill}$\square$\medskip}

%\onehalfspacing
\begin{document}
%make the title page
\title{ Problems from William Waterhouse's\\ \textit{Introduction to Affine Group Schemes}\vspace{-1ex}}
\author{Nico Courts}
\date{}
\maketitle

%begin problems

\section{Affine Group Schemes}
\begin{prob}{1}
	\begin{enumerate}
		\item If $R$ and $S$ are two $k$ algebras and $F$ is a representable functor, show $F(R\times S)\cong F(R)\times F(S)$.
		\item Show there is no representable functor $R$ such that every $F(R)$ has exactly two elements.
		\item Let $F$ be the functor represented by $k\times k$. Show that $F(R)$ has two elements exactly when $R$ has no idempotents besides 0 and 1.
	\end{enumerate}
\end{prob}

\begin{sol}
	\subsubsection*{(a)}
	Let $A$ be the $k$-algebra representing $F$. Thus $F(R)$ is naturally isomorphic to
	$\Hom_k(A,R)$ and $F(S)\simeq\Hom(A,S)$. Then define the map $\Phi:\Hom(A,R\times S)\to\Hom(A,R)\times\Hom(A,S)$
	via
	\[\Phi(\varphi)=(\pi_R\circ\varphi,\pi_S\circ\varphi)\]
	where $\pi_X$ is the canonical projection onto $X$.

	This is surjective since (by the universal property of products) any pair of maps
	$\varphi_R:A\to R$ and $\varphi_S:A\to S$ factors through the product $R\times S$
	and furthermore it does so \textit{uniquely}, giving us injectivity. Thus this map
	(which is clearly a homomorphism since $\pi_X$ is) is a bijection.
	\subsubsection*{(b)}
	By the last problem this is impossible since there are more than 2 $k$-algebras for any $k$.
	\subsubsection*{(c)}
	Let $F$ be such a functor. Consider any $\varphi\in\Hom(k\times k, R)\simeq F(R)$.
	Assume first that $F(R)\cong \Z/2$ and let $r$ be an idempotent in $R$.
\end{sol}

\begin{prob}{2}
	Let $E$ be a functor represented by $A$ and let $F$ be any functor. Show that the natural
	maps $\eta:E\to F$ correspond to elements in $F(A)$.
\end{prob}
\begin{sol}
	Consider the map $\Phi$ from natural maps $E\to F$ to elements in $F(A)$ defined by
	(again leveraging the representability of $E$)
	\[\eta\mapsto \eta(\operatorname{id}_A)\in F(A).\]
	Conversely, consider the map $\Psi$ from $F(A)$ to the natural maps $E\to F$ via
	\[x\mapsto \xi_x\]
	where $\xi_x$ where for any $Y$ and $y\in E(Y)\cong \Hom(A,Y)$ we define the $Y^{th}$ component of $\xi_x$
	as
	\[\xi_x(y)=F(y)(x)\in F(Y)\]
	where (for clarity while I get a grasp here) $F(y):F(A)\to F(Y)$.

	Since we are only looking for a bijection, we only need that these maps are inverses.
	Consider that for all $Y$ and $y\in E(Y)$,
	\begin{align*}
		\Psi\circ\Phi(\eta)(y)&=\Psi\left(\eta(\operatorname{id}_A)\right)(y)\\
		&= \xi_{\eta(\operatorname{id}_A)}(y)\\
		&= F(y)\circ \eta (\operatorname{id}_A)\\
		&= \eta\circ E(y) (\operatorname{id}_A)\\
		&= \eta(y\circ\operatorname{id}_A)=\eta(y)
	\end{align*}
	where above we used the naturality of $\eta$ along with the fact that $E(y)$ is just
	precomposition with $y$. Thus $\Psi\circ\Phi(\eta)=\eta.$

	But then for any $x\in F(A)$,
	\begin{align*}
		\Phi\circ\Psi(x)&=\Phi\circ\xi_x\\
		&=\xi_x(\operatorname{id}_A)\\
		&=F(\operatorname{id}_A)(x)\\
		&=\operatorname{id}_{F(A)}(x)=x
	\end{align*}
	completing the proof.
\end{sol}

\begin{prob}{3}
	Let $E$ be a functor represented by $A$, and let $F$ be any functor. Let $\Psi:F\to E$
	be a natural map with surjective component maps. Show there is a natural map $\Phi:E\to F$
	with $\Psi\circ\Phi=\operatorname{id}_E$.
\end{prob}
\begin{sol}
	Since in particular $\Psi_A$ is surjective, there is an $x\in F(A)$ such that $\Psi(x)=\operatorname{id}_A$.
	Then using the map from the last problem, let $\Phi=\xi_x$. Then we can compute for any $R$ and $g\in E(R)$
	\begin{align*}
		\Psi\circ\Phi (g) &= \Psi\circ F(g) (x)\\
		&=E(g)\circ \Psi(x)\\
		&=E(g)(\operatorname{id}_A)\\
		&=g\circ \operatorname{id}_A=g
	\end{align*}
	since $g:A\to R$, so $E(g):E(A)\to E(R)$, which is just composition with $g$.
\end{sol}

\begin{prob}{5}
	Write out $\Delta,\varepsilon,$ and $S$ for the Hopf algebras representing $SL_2, \mu_n,$ and $\alpha_p$.
\end{prob}
\begin{sol}
	\subsubsection*{$SL_2$:}
	Notice $SL_2$ is represented by $A=k[X_1,X_2,X_3,X_4]/(X_1X_4-X_3X_2-1)$ so take two elements
	$f,g\in\Hom(A,R)$ where $f(X_i)=a_i\in R$ and $g(X_i)=b_i\in R$ and notice that we want
	\[(f,g)\Delta=h\]
	where since
	\[\begin{pmatrix}
		a_1 & a_2\\ a_3 & a_4
	\end{pmatrix}\begin{pmatrix}
		b_1 & b_2\\ b_3 & b_4
	\end{pmatrix}=\begin{pmatrix}
		a_1b_1+a_2b_3 & a_1b_2+a_2b_4\\ a_3b_1+a_4b_3 & a_3b_2+a_4b_4
	\end{pmatrix}=\begin{pmatrix}
		c_1 & c_2\\ c_3 & c_4
	\end{pmatrix}\]
	we want to have that $h(X_i)=c_i.$

	So then if $\Delta:A\to A\otimes A$ is defined as follows:
	\begin{align*}
		X_1&\mapsto X_1\otimes X_1+X_2\otimes X_3
	\end{align*}
\end{sol}

\begin{prob}{6}
	In $A=k[X_{11},\dots,X_{nn},1/\operatorname{det}]$ representing $GL_n$, show that $\Delta(X_{ij})=\sum X_{ik}\otimes X_{kj}$.
	What is $\varepsilon(X_{ij})$?
\end{prob}
\begin{sol}
	Due to the uniqueness of $\Delta,\varepsilon,$ and $S$, we need only find maps satisfying
	the diagrams. I claim that $\varepsilon(X_{ij})=\delta_{ij}$. In this case, notice
	\[(\varepsilon\otimes\operatorname{id})\circ\Delta(X_{ij})=\varepsilon\otimes\operatorname{id}\left( \sum X_{ik}\otimes X_{kj} \right)=\sum \delta_{ik}\otimes X_{kj}=1\otimes X_{ij}\]
	exactly as we want.

	For associativity, notice
	\[(\Delta\otimes \operatorname{id})\circ \Delta (X_{ij})=\Delta\otimes\operatorname{id}\left( \sum_k X_{ik}\otimes X_{kj} \right)=\sum_k\left(\sum_l X_{il}\otimes X_{lk}\right)\otimes X_{kj}\]
	and then the associativity of $\Delta$ follows simply from the associativity of the tensor product.

	For the last axiom, we compute $S$ such that $(S,\operatorname{id})\circ\Delta=\iota\circ\varepsilon$ where $\iota:K\to A$ is the map sending $k\mapsto k\cdot 1_A$.
	That is, we define $S:A\to A$ so that
	\[\sum_k S(X_{ik})X_{kj}=\delta_{ij}.\]

	We want to leverage the fact that for a fixed $i$ and $j$, the determinant is
	\begin{align*}
		\operatorname{det} &= \sum_{\sigma\in S_n}\operatorname{sgn}(\sigma)\prod_l X_{\sigma(l)l}\\
		&=\sum_\sigma \operatorname{sgn}(\sigma)X_{\sigma{j}j}\prod_{l\ne j} X_{\sigma(l)l}\\
		&=\sum_i X_{ij}\left(\sum_{\sigma(j)=i}\operatorname{sgn}(\sigma)\prod_{l\ne j}X_{\sigma(l)l}\right)
	\end{align*}
	and so we want that
	\[S(X_{ik})=\frac{1}{\operatorname{det}}\sum_{\sigma(i)=k}\operatorname{sgn}(\sigma)\prod_{l\ne k}X_{\sigma(l)l}\]
	so that when $i=j$,
	\[\sum_k S(X_{ik})X_{kj}=\frac{1}{\operatorname{det}}\sum_k X_{kj}\sum_{\sigma(j)=k}\operatorname{sgn}(\sigma)\prod_{l\ne k}X_{\sigma(l)l}=1=\delta_{ij}\]
	whenever $i\ne j$, however, this equation is the determinant of the matrix where we have replaced
	the $j^{th}$ column with a copy of the $i^{th}$ column. This is linearly dependent, so
	\[\frac{1}{\operatorname{det}}\sum_k S(X_{ik})S_{kj}=0=\delta_{ij}.\]
	Thus these are precisely the maps we desire.
\end{sol}

\section{Examples}
\begin{defn}[Closed Embedding]
	If $G$ and $H$ are affine group schemes represented by $A$ and $B$, respectively and
	if $\psi:H\to G$ is a homomorphism of affine group schemes (locally a group homomorphism)
	then if the corresponding algebra map $A\to B$ is surjective, then $\psi$ is called
	a \textbf{closed embedding.}
\end{defn}

\end{document}


\section{Preliminary}
\label{sec:pre}

\begin{definition}
\textbf{ Heterogeneous Information Networks (HIN)}\cite{JiSDHG10}.
Let $T = \{T_1,\ldots, T_m\}$ be a set of $m$ object types.
For each type $T_i$, let $n_i$ and $X_i = {x_i1,\ldots, x_{in_i} }$ be the number and the set of objects of type $Ti$, respectively. An HIN
is a graph $G = (V, E)$, where $V =
\bigcup\limits_{i=1}^{m} X_i$, and $E$ is a set of
links, each represents a binary relation between two objects
in $V$. If $m = 1$ (i.e., there is only one object type), G reduces
to a homogeneous information network.
\end{definition}

\begin{figure}
    \centering
        \includegraphics[width = 0.7\linewidth]{figure/example1.pdf}
        \caption{An example of a heterogeneous information network (DBLP). There are three types of nodes (i.e. author, paper, conference).}
        \label{figure:example}
\end{figure}

\begin{example}
In Fig.~\ref{figure:example}, we give an example of HIN. There are three types of nodes, Author, Paper and Conference. And we illustrate two types of edges: Author-Paper, Paper-Conference.
\end{example}

\begin{definition}
\textbf{Metapath}\citep{SunHYYW11}.
A meta-path $\Phi$ is a path defined on a graph schema. Meta-path $\Phi$: $T_1 \stackrel{R_1}{\longrightarrow} \cdots \stackrel{R_l}{\longrightarrow} T_{l+1}$ defines a composite relation $R = R_1 \circ \cdots \circ R_l$ that relates objects of type $T_1$ to objects of type $T_{l+1}$.
%If two objects $x_u$ and $x_v$ are related by the composite relation $R$, then there is a path, denoted by $p_{x_u \rightsquigarrow x_v}$, that connects $x_u$ to $x_v$ in $G$.
We say a path $p = (x_1x_2\ldots x_{l+1})$ between $x_1$ and $x_{l+1}$ in network $G$ follows the meta-path $\Phi$, if each object is of type $T_i$ and each link $ei = \langle x_ix_{i+1}\rangle$ belongs to each relation $R_i$ in $\Phi$.
We say that $p_{x_1 \rightsquigarrow x_{l+1}}$ is an instance of meta-path $\Phi$, denoted by $p_{x_1 \rightsquigarrow x_{l+1}} \vdash \Phi$.
%We call these paths as path instances of $\Phi$, which are denoted as $p \in \Phi$.
Moreover, in this paper we say $x_v$ is a meta-path $\Phi$ related neighbor of $x_u$, denoted by $x_v \in N^\Phi(x_u)$

\end{definition}

\begin{example}
In Fig.~\ref{figure:example}, $a_3$ is an $APA$-related neighbor of $a_1$, and $a_5$ is an $APCPA$-related neighbor of $a_1$.
%We have $a_3 \in N^{APA}(a_1)$ and $a_5 \in N^{APCPA}(a_1)$
\end{example}

The notations throughout the rest of paper are shown in Table \ref{table:notation}.

\begin{table}[]
\caption{Description of symbols}
\centering
\begin{tabular}{cc}
\hline
Symbol       & Description                                                       \\ \hline
$\Phi$         & Meta-path                                                         \\
$N^\Phi$       & Set of neighbors with respect to a given meta-path $\Phi$          \\
$h^{(t)}$        & Node embedding at layer $t$; $h^{(0)}$ is input node feature \\
$r^{(t)}$        & Edge embedding at layer $t$; $r^{(0)}$ is input edge feature \\
%$e_{i,j}^\Phi$ & Similarity of node pair ($i$,$j$) under meta-path $\Phi$   \\
$a_{i,j}^\Phi$ & Attention of node pair ($i$,$j$) under meta-path $\Phi$    \\
$w_i^{\Phi_p}$   &  Weight of meta-path $\Phi_p$  related component of $w_i$\\
$z_i$            & Output embedding for node $i$                                     \\
$W_F$          & Learnable weight matrix of fully connected layer $F$  \\
$\sigma$       & Sigmoid function                                                  \\
$\oplus$       & Concatenate function \\
$\odot$       & Hadamard (element-wise) product function \\
\hline
\end{tabular}
\label{table:notation}
\end{table}


\chapter{Non-local similarity-based propagation model}
\label{chap_NLM}

This chapter proposes a novel model that combines low-resolution measurements in space and time in order to reconstruct fully resolved turbulent fields. This method tackles the problem of fusing high-time-low-space and low-time-high-space resolution measurements mentioned in section \ref{sec:probdef2}. The model exploits local structures in large scale measurements to reconstruct small scales. The idea is to assume that small scales are essentially advected by large scales. This is based on the scale similarity hypothesis, where information at adjacent ranges of scales are strongly correlated. The model is further developed from the non-local means (NLM) denoising filter \citep{buades2005review}, which is very simple but efficient, and widely used in image processing.

The proposed model is applied to the streamwise velocity fields from DNS data of isotropic turbulence as described in section \ref{sec:data_isotropic}. Due to the absence of time resolved fields, \textit{the streamwise direction is associated to the time dimension}, while the other two spatial directions are the spanwise and the vertical ones. Within this chapter, parameters of the model will be optimized. Model performances are also investigated by fixing one subsampling ratio in either space or time (spanwise) while varying the other. Detailed analysis of model performances are presented, but further comparisons with other methods will be investigated in chapter \ref{chap_comparisons}.

\section{Non-local means}
Non-local means (NLM) was originally proposed by \citet{buades2005review} to deal with the single image denoising problem. It has been then extended to solve other inverse problems of image reconstruction such as inpainting (to fill in missing pixels) or super-resolution (to increase image resolution). The model assumes that image content is likely to repeat in many regions. The estimate of each pixel is a weighted average of its neighbors assigned with different weights. These weights are estimated as the similarity of the denoised/inpainted/super-resolved pixel with its neighbors. By proposing several estimates of a single pixel, NLM yields redundancy by using several observations of similar scenes obtained from different locations within the same image. These multiple observations of underlying ground truth help in solving the ill-posed inverse problem.

\subsection{Non-local means filter for denoising}
\begin{figure}
	\centering
	\includegraphics[width=\columnwidth]{./images/NLM/lena.png}
	\caption{\label{fig:lena} Image denoising using non-local means. Four sample patches in red extracted from noisy image and centered at blue dots. The estimate of each point are weighted average of its neighbors, and weights are computed as the similarity of the moving patches compared to the reference patch. Photo credit: \citet{foi2016foveated}.}
\end{figure}

The NLM denoising filter is simple but rather robust. Figure \ref{fig:lena} illustrates how the NLM filter works on a sample image. Denoting $ \mybold{z}_t \in \R^{\dimsh} $ as the column vector of a 2D noisy image, the NLM filter denoises the $ k- $th pixel as a weighted average of its neighboring noisy pixels:
\begin{equation}
	\hat{\mybold{z}}_t[k]=\frac{\displaystyle \sum_{i\in\neighbor_k}w[k,i]\mybold{z}_t[i]}{\displaystyle \sum_{i\in\neighbor_k}w[k,i]}
\end{equation}
$ \neighbor_k $ is the set of neighboring pixels of the $ k- $th pixel. The local weight coefficient $ w[k,i] $ is the similarity between the $ k- $th and $ i- $th pixels:
\begin{equation}
	w[k,i] = \myexp{ -\frac{\|\mathcal{R}_s^k\mybold{z}_t-\mathcal{R}_s^i\mybold{z}_t\|^2_2}{2\nlmfilparam^2}}
\end{equation}
where the operator $ \mathcal{R}_s^k: \R^{\dimsh} \mymapto \R^\dimpsh$ extracts 2D patches of size $ \sqrt{\dimpsh}\times \sqrt{\dimpsh} $ centered at the $ k- $th pixel. These patches are then arranged in a column vector in lexicographical order. When $ \dimpsh=1 $, the NLM filter becomes a bilateral one. The global filter parameter $ \sigma $ regulates the decay of the exponential expression. It controls the contribution of the $ i- $th pixel on the estimation of the $ k- $th pixel. Geometrical priority can also be introduced, where high weights are given to closer neighbors than further ones.

\subsection{Generalized non-local means for super-resolution}
The idea of the NLM filter has been generalized to perform video super-resolution \citep{protter2009generalizing} by introducing time dimension. The aim is to estimate HR sequence of images $ \mybold{z}_t \in \R^{\dimsh}, t=1,2,...,\dimth , $ from corresponding LR sequence of images $ \mybold{y}_t \in \R^{\dimsl}$ ($ \dimsl <\dimsh $). NLM exploits the self-similarity property of natural images in the sequence. The model assumes that common scenes are shared by many snapshots in the sequence. Derivation and mathematical explanation can be found in \citet{protter2009generalizing}. The closed form solution is simplified, where each HR pixel is estimated as a weighted average of neighboring LR pixel in a space-time window:
\begin{equation}
	\hat{\mybold{z}}_{t_\knot}[k]=\cfrac{\displaystyle \sum_{t\in\neighbor_{t_\knot}}\sum_{i\in\neighbor_k}w[k,i,t]\mybold{y}_t[i]}{\displaystyle \sum_{t\in\neighbor_{t_\knot}}\sum_{i\in\neighbor_k}w[k,i,t]}
\end{equation}
where $ \neighbor_{t_\knot} $ is the set of neighboring snapshots in time of the $ t_\knot$-th one. The weight $ w[k,i,t] $, defined as the probability of the $ k- $th HR pixel estimation coming from the $ i $-th LR pixel, is estimated as:
\begin{equation}
	w[k,i,t] = \myexp{ -\frac{\normtwo{\mathcal{R}_s^k\mybold{y}_{t_\knot}-\mathcal{R}_s^i\mybold{y}_t}}{2\nlmfilparam^2}}
\end{equation}
This solution exits when there is at least one non-zero weight $ w[k,i,t] $.

It is natural to test this idea to reconstruct HTHS turbulent fields $ \Z $ of size $ \dimth \times \dimsh $ from the corresponding HTLS measurements $ \Y $ of size $ \dimth \times \dimsl $ ($ \dimsl < \dimsh $) subsampled directly from $ \Z $. However, the NLM model by \citet{protter2009generalizing} is not able to improve the reconstruction accuracy compared to the single interpolation of HTLS velocity fields. This is potentially due to the differences between video of natural images and turbulence. The generalized NLM was originally illustrated most successful for video of human with small motions, where the same scene is obtained for successive snapshots. Turbulent fields are fundamentally different, where no sharp edge exists, sizes of structures make a continuous spectrum, and all scales move and distort randomly. Also, since turbulence fields have a decreasing power law spectrum, large scales contain most of the kinetic energy. The reconstruction of these information plays the dominant role in total error. The current NLM model re-estimates large scales, which are probably not as good as by spline interpolation.

\section{Similarity-based model to propagate small scales}
\begin{figure}
\centering
	\includegraphics[width=0.8\columnwidth]{./images/NLM/propagation_scheme.png}
	\caption{\label{fig:propagation_scheme} A sketch of \textit{greedy} and \textit{non-greedy} propagation models. The two LTHS planes are at the border including small scales $ \boundHF_{t_\knot} = \h_0 $ and $ \boundHF_{t_\knot+1} = \h_{\dimth/\dimtl} $ defined in equation \ref{eq:greddy1}. All small scales to be estimated from other planes $ \h_1, \h_2,...,\h_{\dimsh/\dimsl-1} $ will be propagated either directly from LTHS planes (greedy, red arrows) or in a plane-by-plane manner (non-greedy, blue arrows). To simplify the plot, the propagation is shown from LTHS planes till the central plane only.}
\end{figure}

We propose a similarity-based model in the spirit of the NLM model for video super-resolution with important modifications. Since large scales are well reconstructed also with spline interpolation, we leave these information unchanged while propagating small scales only. Two models, the so-call ``\textit{greedy}'' and ``\textit{non-greedy}'' propagations, are proposed. Figure \ref{fig:propagation_scheme} illustrates the idea of the two propagation schemes. While the greedy model propagates small scales from LTHS planes directly toward other instant, the non-greedy one does the propagation plane-by-plane.

\subsection{Greedy propagation of small scales from key planes}
LTHS measured snapshots are crucial to recover some spatial HF contents, since these are the only place where small scales are available. In the configuration presented in figure \ref{fig:space-time_measurements}, HTLS snapshots give only information of large scales in space, while small ones are only accessible from LTHS snapshots. The idea is to bring these small-scale information and aggregate them on top of the measured large scales. The propagation model is based on the similarity of large scales at different instants, while assuming that small scales are advected by large ones.

LTHS snapshots $ \{\x_{t_\knot} \} \in \R^{\dimsh}, t_\knot = 1,2,...,\dimtl$, also called \textit{key frames}, include both large and small scales. HTLS snapshots $ \{\y_t \}  \in \R^{\dimsh}, t=1,2,...,\dimth$ contain only large scales. The propagation model aims at propagating the small-scale content from the key frames and aggregating with the interpolation $ \Interp_s\y_t $ to reconstruct $  \myhat{\z}_t $, which contains information of all scales. $ \Interp_s: \R^{\dimsl} \mymapto \R^{\dimsh} $ is the 2D cubic spline interpolator to reconstruct large scales from LR measurements.

The propagation is based on the similarity of the large scales between the key frames and the measured planes to reconstruct. Large and small scales could be separated from the key frames using ideal Fourier filter. However, these large scales are not consistent with those from the measured planes obtained by interpolations. It is more consistent to subsample and re-interpolate LTHS fields the same way as HTLS ones. Small scales of each key frame are then defined as:
\begin{equation}
\boundHF_{t_\knot} = \mybold{x}_{t_\knot} - \Interp_s\Sub_s\mybold{x}_{t_\knot}
\label{eq:greddy1}
\end{equation}
$ \Sub_s $ is the subsampling operator in space, $ \Sub_s: \R^{\dimsh} \mymapto \R^{\dimsl} $, and $ \boundHF_{t_\knot} $ should contain some aliasing. The greedy propagation model estimates small scales $ \h_t $ at the $ t- $th time step from the given small scales  $ \boundHF_{t_\knot} $ and $ \boundHF_{t_\knot+1} $ of the two bounded LTHS planes, ones just before and after the $ t $-th HTLS plane in time:
\begin{equation}
	\hat{\h}_t[k]=\cfrac{\displaystyle \sum_{i\in\neighbor_k}w_0[k,i,t]\boundHF_{t_\knot}[i] + \sum_{i\in\neighbor_k}w_1[k,i,t]\boundHF_{t_\knot+1}[i]}{\displaystyle\sum_{i\in\neighbor_k}w_0[k,i,t] + \sum_{i\in\neighbor_k}w_1[k,i,t]}
\label{eq:greddy2}
\end{equation}
The weight $ w_0[k,i,t] $ measures the similarity of $ k-th $ pixel of $ \hat{\h}_t $ and the $ i $-th pixel of $ \boundHF_{t_\knot} $, and analogously for $ w_1[k,i,t] $. It is estimated as the similarity of large scales in the two snapshots:
\begin{equation}
w_0[k,i,t] = \myexp{ -\frac{\|\mathcal{R}_s^k\Interp_s\mybold{y}_t-\mathcal{R}_s^i\Interp_s\Sub_s\mybold{x}_{t_\knot} \|^2_2}{2\nlmfilparam^2}}
\label{eq:greddy3}
\end{equation}
The term $ \Interp_s\Sub_s\mybold{x}_{t_\knot} $ is the conjugate large scales of $ \boundHF_{t_\knot} $, i.e. $ \mybold{x}_{t_\knot} = \Interp_s\Sub_s\mybold{x}_{t_\knot} + \boundHF_{t_\knot} $. $ w_1[k,i,t] $ is estimated analogously. The final reconstruction of all scales is:
\begin{equation}
\myhat{\z}_t = \Interp_s \y_t + \myhat{\h}_t
\label{eq:greddy4}
\end{equation}
Since $ \Interp_s \y_t $ contains some aliasing, so does $ \myhat{\h}_t $ due to the presence of aliasing in $ \boundHF_{t_\knot} $ and $ \boundHF_{t_\knot+1} $, we could hope the two aliasing terms cancel and make the estimate of $ \myhat{\z}_t $ more accurate. This can explain also the benefit when considering $ \boundHF_{t_\knot} $ as the residual of the interpolation instead of ideal small scales.

The propagation in the formulation \ref{eq:greddy2} is point-wise, where each point is estimated as a weighted average of its neighbors. Instead, a small patch centered at $ i- $th pixel of $ \boundHF_{t_\knot} $ and $ \boundHF_{t_\knot+1} $ can be accumulated over the patch centered at the $ k- $th pixel of $ \hat{\h}_t $ using the same weights $ w_0[k,i,t] $ and $ w_1[k,i,t] $. Since the same pixel belongs to several patches, the overlapping as in the patch-based approach (section \ref{subsec:patch_based_estimation}) is used. The overlapping will ensure the continuity of neighboring points and increase the consistence of all existing structures. There will be also more degree of freedom, where the number of estimates at each location increases significantly. The accumulation of scales and weights are as:
\begin{equation}
\begin{split}
\hat{\h}_t &= \sum_{k = 1}^{\dimsh} \left( \left(\mathcal{R}_a^k\right)^{\mytrans}\left(\sum_{i\in\neighbor_k}w_0[k,i,t]\mathcal{R}_a^i\boundHF_{t_\knot}[i] + \sum_{i\in\neighbor_k}w_1[k,i,t]\mathcal{R}_a^i\boundHF_{t_\knot+1}[i]\right) \right)\\
W_t &= \sum_{k = 1}^{\dimsh} \left(\left(\mathcal{R}_a^k\right)^{\mytrans}\mathcal{R}_a^k\mybold{1} \left(\sum_{i\in\neighbor_k}w_0[k,i,t] + \sum_{i\in\neighbor_k}w_1[k,i,t]\right) \right)
\end{split}
\label{eq:greddy5}
\end{equation}
where $ \mathcal{R}_a^k $ and $ \mathcal{R}_a^i $ extract a small patch of size $ \sqrt{\dimpacc} \times \sqrt{\dimpacc} $ centered at the $ k- $th and $ i- $th pixel respectively. The transpose operator $ \left(\mathcal{R}_a^k\right)^{\mytrans} $ is to put back this small patch into the large field, centered at $ k- $th pixel. $ \mybold{1} $ is the vector of size $ \dimsh \times 1 $ of ones. The term $ \left(\mathcal{R}_a^k\right)^{\mytrans}\mathcal{R}_a^k\mybold{1} $ puts ones at the position of each patch. The whole procedure is to accumulate the sum of all small scales estimates and their corresponding weights. The final step is the normalization:
\begin{equation}
\hat{\h}_t[k] \mymapfrom \cfrac{\hat{\h}_t[k]}{W_t[k]}
\label{eq:greddy6}
\end{equation}

\subsection{Non-greedy propagation of small scales}
The greedy model aims at propagating directly small scales from the two key frames to the HTLS planes. The performance of such a model is very limited when the similarity level decays rapidly with time far from the LTHS planes. A non-greedy propagation of small-scale information plane-by-plane from the two neighboring LTHS fields toward further planes is expected to improve the reconstruction.

\begin{algorithm}[t]
\caption{Estimating small scales of $ \dimth/\dimtl - 1 $ planes by non-greedy NLM propagation from the two key frames at $ t_\knot $ and $ t_\knot+1 $} \label{algo_NLM_timepropagation}
\begin{algorithmic}[1]
	\State Input: $ \h_0 \mydef \boundHF_{t_\knot} $, $  \h_{\dimth/\dimtl} \mydef \boundHF_{t_\knot+1} $
	\State $ t_c = round(\dimth/2\dimtl) $ \Comment{Centered snapshot}
	\For {$ i = 1, ..., t_c-1$}
		\State $ j = \dimth/\dimtl - i$
		\State $ \h_i = g(i, \h_{i - 1},\h_{j + 1})$
		\State $ \h_j = g(j, \h_{i - 1},\h_{j + 1})$
	\EndFor

	\If{$ rem(\dimth/\dimtl - 1) == 0 $} \Comment{Check if even, there are 2 centered snapshots}
		\State $ \h_{t_c} = g(t_c, \h_s[t_c-1],\h_s[t_c+2])$
		\State $ \h_{t_c+1} = g(t_c+1, \h_s[t_c-1],\h_s[t_c+2])$
	\Else
		\State $ \h_{t_c} = g(t_c, \h_{t_c-1},\h_{t_c+1})$ \Comment{Estimate centered snapshot}
	\EndIf
\end{algorithmic}
\end{algorithm}

The main step to propagate the small scales from the two key frames at $ \boundHF_{t_\knot} $ and $ \boundHF_{t_\knot+1} $ is presented in algorithm \ref{algo_NLM_timepropagation}. $ g(t,\h_1,\h_2) $ is denoted as the similarity-based estimation of small-scale information at $ t- $th plane from the two bounded planes, with scales to propagate being $ \h_1 $ and $ \h_2 $. The procedure starts by propagating small scales from these two frames to their first two neighboring planes, $ \h_1 $ and $ \h_{\dimth/\dimtl - 1} $ in algorithm \ref{algo_NLM_timepropagation}, following the formula \ref{eq:greddy5}. The next step considers these two estimated $ \h_1 $ and $ \h_{\dimth/\dimtl - 1} $ as the new key frames and propagate them further. This procedure is repeated till the central planes that are equally far from $ \boundHF_{t_\knot} $ and $ \boundHF_{t_\knot+1} $.

\section{Applying the propagation model to isotropic turbulence}
\subsection{The choice of model parameters}
The propagation model uses several parameters (see equations \ref{eq:greddy3} and \ref{eq:greddy5}), including the filter parameter $ \sigma $, the size $ \dimpsr $,  $ \dimpsh $, and $ \dimpacc $ of the searching region $ \mathcal{N}_s $, the similarity patch extracted by $ \mathcal{R}_s $, and the accumulation patch extracted by $ \mathcal{R}_a $ respectively. Optimization of these parameters is done by varying one while fixing the remaining three. The parameter-tunning is carried out by investigating the error between the reconstructed fields and the reference ones. These tests give an idea on the optimal set of parameters, which can be used in new situations where reference fields are not available.

\begin{table}
	\caption{\label{tab:NLMparams}
	Set of parameters to do simple grid search (try out all possible combinations from this set): the global filter parameter $ \sigma $, size of similarity patches $ \dimpsh $, size of accumulation patches $ \dimpacc $, and size of searching region $ \dimpsr $. The search is performed on the DNS data of isotropic turbulence, with the subsampling ratios are $ \dimsh/\dimsl = 3 \times 3 $ in space and $ \dimth/\dimtl = 4 $ in time.}
	\vspace{.5cm}
	\centering
	\begin{tabular}{S[table-format=1.2]S[table-format=2.0]S[table-format=2.0]S[table-format=2.0]}
		\toprule
		{$\sigma$} & $\sqrt{\dimpsh}$ & {$\sqrt{\dimpacc}$} & {$\sqrt{\dimpsr}$}\\
		\midrule
		0.05  &  9  & 1  & 5  \\ %\addlinespace
		0.1 & 17  & 3  & 11 \\ %\addlinespace
		0.2   & 25  & 13 & 17 \\ %\addlinespace
		0.4  &    & 25 &  \\ %\addlinespace
		\bottomrule
	\end{tabular}
\end{table}

Table \ref{tab:NLMparams} gathers all parameters to test. The DNS data of isotropic turbulence are used. HTLS and LTHS measurements are virtually extracted from the fully resolved fields as discussed in section \ref{sec:probdef2}. The subsampling ratios are $ \dimsh/\dimsl = 3 \times 3 $ in space, equally distributed in spanwise and vertical direction, and $ \dimth/\dimtl = 4 $ in time (streamwise). These subsamplings correspond to energy losses of about $ 1\% $ both in space and time (see table \ref{tab:energyloss_isotropic}). The configuration is chosen to have a moderate loss of information to facilitate all numerical experiments. Other configurations with various losses are investigated later in this section.

Three measures are used to study the effects of different parameters on the reconstruction accuracy. One is the average normalized root mean square error (NRMSE) $ \bar{\epsilon} $, which represents an overall measure of the reconstruction accuracy, as in equation \ref{eq:NRMSE}. The two other quantities are the power spectra $ E(k) $ and the spectra of the error $ E^{\epsilon}(k) $. Power spectra show streamwise energy contents, while error spectra show the squared errors at each frequency. These two measures give more insights about the model performances when reconstructing turbulent fields at different scales.

\begin{figure}[t]
	\centering
	\includegraphics[width=\columnwidth]{./images/NLM/interpdiff/NLmean_propag1dir_spacing3_tspacing4_allparams_NRMSE.eps}
	\caption{\label{fig:NLM_various_params_NRMSE} Average NRMSEs over the whole dataset: each estimate of NRMSE is computed by comparing the reconstructed plane with the reference at each $ t/\delta t $. The bars show the average NRMSEs, while the error bars are standard deviations of NRMSE estimates.}
\end{figure}

Figure \ref{fig:NLM_various_params_NRMSE} shows average NRMSEs for different parameters as a function of $ t/\delta t $, the time distance from the previous LTHS plane to the estimated one. Two LTHS planes are at $ t/\delta t = 0 $ and $ t/\delta t = \dimth/\dimtl = 4 $. Average NRMSEs are shown as bars, with the standard deviation of each estimate shown by the error bars. The average and standard deviation of NRMSEs at each $ t/\delta t $ are computed using $ 37 \times 23 $ estimates from all blocks between the two successive key frames. Parameters are varied by changing one and keeping the remaining three constant around a reference parameters set ($ \sigma=0.1 $, $ \dimpsh=\dimpacc=25 \times 25 $ and $ \dimpsr = 11 \times 11$). This set is close to the optimal values used later in this section and chapter \ref{chap_comparisons} when comparing with other models.

\begin{figure}[t]
	\centering
	\includegraphics[width=\columnwidth]{./images/NLM/interpdiff/NLmean_propag1dir_spacing3_tspacing4_allparams_spectra.eps}
	\caption{\label{fig:NLM_various_params_spectra} Normalized error spectra of reconstructed planes at $ t/\delta t = 2 $ (the most remote from the two neighboring LTHS planes). Three cases of varying $ \dimpsh $, $\dimpacc$ and $\dimpsr$, all curves are almost collapsed.}
\end{figure}

Figure \ref{fig:NLM_various_params_spectra} shows the 2D spectra of the errors $ E^{\epsilon}(k) $ normalized by the energy spectra of the reference $ E(k) $. These spectra are estimated as an average of all planes at $ t/\delta t =2$, the most difficult planes to reconstruct. For all reconstructions, the spectra exhibit very small errors at large scales, which grow sharply when approaching the cutoff wave number defined by the spacing of the low sampling measurements. At very small scales, errors can reach $ 100 \% $. This level of error means that no information has been reconstructed.

Among all parameters, the filter parameter $ \sigma $ is the most sensitive. The optimal value is $ \sigma \approx [ 0.1,0.2 ] $. Small values of $ \sigma $ narrow the searching region by shrinking weights of patches with low similarity levels to zero. Less estimates are taken into account when doing the weighted averaging. In the extreme situation $ \sigma = 0 $, the number of estimates is reduced to one pixel only, which is the center of the most correlated patch. The propagation model is simplified to the shifting of a single pixel. Otherwise, too large values of $ \sigma $ put weights on all the neighboring patches. Models with very large $ \sigma $ lead to a simple averaging with approximately equal weights. For these reasons, NRMSE is high for both small and large $ \sigma $, while a moderate value of $ \sigma $ is a good compromise to minimize the reconstruction error. This is shown in the error spectra (figure \ref{fig:NLM_various_params_spectra}) where the optimal $ \sigma $ gives similar large-scale reconstruction errors but lower ones at small scales.

Other model parameters are less sensitive. Searching region $ \mathcal{N}_k $ defines how large is the neighborhood to seek the small-scale information. However, the filter parameter $ \sigma $ plays a similar role by dumping the contribution of irrelevant patches to zero. Sizes of similarity and accumulation patches are more important. Similarity patches directly define the quality of weight estimates. Small patches are necessary to keep small-scale details of the flow. Larger patches improve the robustness of the models against noise and ill-posed conditions of the inverse problem. Ideally, we want the model to work well with small patches. However, experiments show slight improvements with larger patches. Similar results are observed when increasing the size of accumulation patches. Taking more pixels into the averaging helps in reducing the estimation noise, hence improving the reconstruction.

\subsection{Comparing to spline interpolation}
The proposed propagation models, either greedy or non-greedy algorithm in time, are compared to cubic spline interpolations either in time $\Interp_t \mybold{x}_t $ or in space $\Interp_s \mybold{y}_t$. Apparently, $ \Interp_t \mybold{x}_t $ contains no temporal small-scales information, while $ \Interp_s \mybold{y}_t $ provides only large scales in space.

\begin{figure}
	\centering
	\includegraphics[width=.6\columnwidth]{./images/NLM/interpdiff/NLmean_interps_sspacing3_tspacing4_NRMSE.eps}
	\caption{\label{fig:NLmean_interps_sspacing3_tspacing4_NRMSE} Comparison of averaged NRMSEs as functions of time distances to the previous bounded LTHS plane by spatial/temporal interpolation, greedy and non-greedy propagation for the configuration where subsampling ratios are $ 3 \times 3 $ in space and $ 4 $ in time.}
\end{figure}

Figure \ref{fig:NLmean_interps_sspacing3_tspacing4_NRMSE} shows the mean NRMSEs by different methods as a function of time spacing to the previous LTHS plane $ t/\delta t $. The error bars are also shown, telling how these errors are different from one plane to another. These errors are estimated analogously as in figure \ref{fig:NLM_various_params_NRMSE}. NRMSEs of reconstructed fields obtained by propagation models or time interpolation are necessarily small close to the LTHS planes ($ t /\delta t = 1 $ and $ t /\delta t = 3 $), and increase toward the center. The error remains constant for spatial interpolation as it is only a function of the subsampling ratio in space. Greedy and non-greedy algorithms essentially give the same errors at the closest two planes from the LTHS ones. At these time steps, propagation models improve significantly (about $ 40 \% $) compared to spatial interpolation. At the middle plane, errors by propagation increase, but remain $ 20\% $ lower than both the interpolations. The non-greedy propagation model further decrease the error compared to the greedy one.

\begin{figure}[t]
	\centering
	\includegraphics[width=\columnwidth]{./images/NLM/interpdiff/NLmean_interps_sspacing3_tspacing4_spectra2d.eps}
	\caption{\label{fig:NLmean_interps_sspacing3_tspacing4_spectra2d} Comparison of energy spectra and error spectra for various reconstructions by spatial/temporal interpolation, greedy and non-greedy propagation. Subsampling ratios are $ 3 \times 3 $ in space and $ 4 $ in time. The spectra are averaged over all planes of the same distance to the closest LTHS plane, i.e. $ t/\delta t= 1 $ (left) or $t/\delta t= 2  $ (right).}
\end{figure}

Figure \ref{fig:NLmean_interps_sspacing3_tspacing4_spectra2d} shows the spectral analysis of the reconstruction by different models. Energy spectra and error spectra are shown for the two positions, either close or far from LTHS planes. From the first two spectra, it is shown that spatial interpolation captures only large-scale information. Time interpolation gives an estimate with a good energy spectrum, while propagation schemes are subject to a certain energy loss at small scales. However, the error spectra shows that time interpolation gives good energy spectra with poorly reconstructed small scales. Propagation models yield compromise estimates. Certain amount of small scales are captured, while error spectra illustrate improvements at all frequencies compared to both interpolations.

\subsection{Model performances in various configurations}
\begin{table}
	\caption{\label{tab:NLM_various_cases}
	Configuration parameters of six testing cases. The subsampling ratios of HTLS measurements are $ \sqrt{\dimsh/\dimsl} $ and equal in both spatial directions. The ratios of LTHS measurements in time are $ \dimth/\dimtl $. The normalized energy losses in space $\Delta\kappa_s$ and in time $\Delta\kappa_t$ are defined in Eq.~(\ref{eq:RMS_losses}).}
	\vspace{.5cm}
	\centering
	\begin{tabular}{ccS[table-format=1.0]S[table-format=1.0]cS[table-format=1.2]S[table-format=1.2]}
		\toprule
		\multirow{2}{*}{Case}&\multicolumn{1}{c}{}&\multicolumn{2}{c}{Subsampling ratios}&\multicolumn{1}{c}{}&\multicolumn{2}{c}{Energy loss}\\
		\cmidrule{3-4} \cmidrule{6-7}
		 & & {$\sqrt{\dimsh/\dimsl}$} & $\dimth/\dimtl$ & & {$\Delta\kappa_s(\%)$} & {$\Delta\kappa_t (\%)$}\\
		\midrule
		1 &  & 3  & 4 & & 1.03 & 1.23 \\ %\addlinespace
		2 &  & 3  & 6 & & 1.03 & 3.56 \\ %\addlinespace
		3 &  & 3  & 8 & & 1.03 & 6.53 \\ %\addlinespace
		4 &  & 3  & 4 & & 1.03 & 1.23 \\ %\addlinespace
		5 &  & 4  & 4 & & 2.63 & 1.23 \\ %\addlinespace
		6 &  & 6  & 4 & & 7.29 & 1.23 \\ %\addlinespace
		\bottomrule
	\end{tabular}
\end{table}

To characterize the proposed propagation models, various configurations at different subsampling ratios in either space or time are investigated. Model performances depend on the ratio in space, since it defines how much information is missing. The performances also depend on the ratio in time, since small-scale information will necessarily be lost when similarity between large scales die off with increasing time spacings.

\begin{figure}[t]
	\centering
	\includegraphics[width=0.65\columnwidth]{./images/NLM/interpdiff/NLmean_interps_NRMSE_vary_timespacing.eps}
	\caption{\label{fig:NLmean_interps_NRMSE_vary_timespacing} Averaged NRMSEs of reconstruction by spatial/temporal interpolation, greedy and non-greedy propagation models. The errors are shown for three cases, with a fixed ratio in space $ (\dimsh/\dimsl = 3 \times 3) $ and varied ratios in time $(\dimth/\dimtl=4,6,8) $. The reference plane is chosen to be the mid-plane, and $ \Delta t_c/\delta t $ is the distance of each other plane from the reference one. Different colors refer to different methods, while the marker shapes vary for different $ \dimth/\dimtl $.}
\end{figure}

To test the model performances when increasing time distances between LTHS snapshots, the subsampling ratio $ \dimsh/\dimsl=3 \times 3 $ in space, while varying those in time as $ \dimth/\dimtl=4,6 $ and $ 8 $. The amount of missing information to recover due to the subsampling in space is about $ 1 \% $ of the total energy of the flow. Average NRMSEs as a function of the position in time are shown in figure \ref{fig:NLmean_interps_NRMSE_vary_timespacing}. In all three cases, the central plane is at $ \Delta t_c/\delta t = 0 $, while other planes are at different distances $ \Delta t_c/\delta t$ to this plane, both negative (planes before) or positive (plane after).

In the figure \ref{fig:NLmean_interps_NRMSE_vary_timespacing}, NRMSE for spatial interpolation remains constant, since it is independent of time. Errors by time interpolations or propagation models increase when moving toward the center. For time interpolations, these errors increase dramatically when the time subsampling ratio is high. The proposed propagation models are able to bring down the errors compared to interpolation for small to moderate distances between LTHS planes. For very large ones ($ \dimth/\dimtl=8 $, diamond shape), the propagated small scales even slightly downgrade the given large-scale information from the spatial interpolation.

\begin{figure}[t]
	\centering
	\includegraphics[width=0.65\columnwidth]{./images/NLM/interpdiff/NLmean_interps_NRMSE_vary_spacespacing.eps}
	\caption{\label{fig:NLmean_interps_NRMSE_vary_spacespacing} Averaged NRMSEs of reconstruction by spatial/temporal interpolation, greedy and non-greedy propagation models. The errors are shown for different space spacing $ (\dimsh/\dimsl=3 \times , 4 \times 4, 6 \times 6) $, while in time the ratio is fixed $ (\dimth/\dimtl =4) $. The reference plane is chosen to be the mid-plane, and $ \Delta t_c/\delta t $ is the distance of each other plane from the reference one. Different colors refer to different methods, while the marker shapes vary for different $ \dimsh/\dimsl $.}
\end{figure}

Figure \ref{fig:NLmean_interps_NRMSE_vary_spacespacing} shows NRMSEs of the proposed propagation models (both greedy and non-greedy), spatial and temporal interpolations when varying the subsampling ratio in space as $ \dimsh/\dimsl = 3 \times 3, 4 \times 4 $ and $ 6 \times 6 $ while keeping a fixed distance between LTHS planes of $ \dimth/\dimtl=4 $. Time interpolation gives the same error for all three cases, while errors of spatial interpolations are independent of the position in time. For a small subsampling ratio in time, temporal interpolation and propagation models are always better than spatial interpolation. For a small ratio of $ \dimsh/\dimsl = 3 \times 3 $, the non-greedy propagation scheme give the most accurate reconstruction. In the case of moderate ratio ($ \dimsh/\dimsl=4 \times 4 $), the energy loss in space is already three times larger than that in time (see table \ref{tab:NLM_various_cases}). Propagation models start with large scales from spatial interpolation and reconstruct small-scale information to give the same accuracy as time interpolation. For a large subsampling ratio of $ \dimsh/\dimsl = 6 \times 6 $, propagation models improves significantly compared to spatial interpolation but remains worse than temporal interpolation. This is due to severe information losses after the subsampling in space, which cannot be  completely recovered.

\section{Concluding remarks}
The similarity-based propagation model, also called NLM-based propagation model, is proposed to reconstruct small scales in a configuration where measurements of all scales are given at key frames (LTHS planes). Small scales from these planes are propagated toward other instants in time. The proposed model takes benefits from the local/nonlocal similarity among scales and  among neighboring fields. Large-scale information is used as initial estimates and kept unchanged, while small scales are propagated as a weighted sum within a small neighborhood from one plane to another. The weights are estimated as the similarity of large scales in small patches. They are interpreted as the probabilities of an estimate to be its neighbors from nearby planes or key frames.

The model works very well in the situation where the subsampling ratios are not severe. In such case, it is able to bring small scales of the flow and add to initial large scales given by the coarse measurements. It also performs better than temporal interpolation from key frames, which is point-wise and disregards the spatial structures of the flow. Among the models, the non-greedy propagation works the most accurately by gradually bringing small-scale information from the bounded planes toward the center.

This model is not robust when the subsampling ratios remain moderate. When the time distance between LTHS planes increases, model performances are getting worse than spatial interpolation. This is because when the key frames are far from each other, similarities of large scales decay, making propagation models becomes inefficient. Reconstructed small-scale information even downgrades the initial large scales from spatial interpolation. The discrepancies are also found with large subsampling ratios in space. In such cases, the model suffers from severe information loss that can not be recovered completely.

More sophisticated models can be further investigated to improve the reconstruction. First, it's worth mentioning the idea of multi-scale propagation, which has been investigated during this work but gives no improvement. However, in the case where the range of scales is extremely wide, there might be potential gain from a non-greedy propagation in space as the one in time presented in this chapter. Second, since structures in turbulence distort and rotate in a disorder manner, it maybe better to propose adapted methods that compute similarity of rotating patches. This idea has been started by \citet{zimmer2008rotationally}, but further investigation is required to adapt to our problem.