% !TeX root = ./apxthy.tex

\section{Introduction}
%
\label{sec:intro}
%
\begin{quote}
In mathematics, approximation theory is concerned with how functions can best be
approximated with simpler functions, and with quantitatively characterizing the
errors introduced thereby. Note that what is meant by best and simpler will
depend on the application. (Wikipedia)
\end{quote}

Approximation theory underpins much of numerical computation and arises also  in
several other branches of mathematics. It is one of the most mature disciplines
of computational mathematics, to the extent that is can even be treated as a branch
of pure mathematics for those who like to make this distinction. This course takes a more computational
perspective. While it still focuses primarily on mathematics and theory, the
choice of material is with an eye to applications in numerical simulation, modelling
and machine learning rather than purely for its own sake. Theory and computational
experiments will be developed in close collaboration.
We will sometimes sacrifice optimality of the results for simplicity and
 stronger intuition.

The first question is to address what we mean by ``simple functions''. Briefly,
we mean functions that are efficient and accurate (numerical stability!) to
evaluate in (typically) floating point arithmetic on a modern processor. This
simple  observation already shows that approximation theory cannot be detached
from numerical analysis and computer simulation. In Part I we will focus on
univariate approximation initially with
trigonometric polynomials ($e^{i n x}$), algebraic polynomials ($x^n$) and then
time permitting extend to splines and rational functions.
In some PDEs but in particular in
ML the approximation problems are often high-dimensional. In Part II of this
course we will explore the challenges that one encounters in this setting
and some classical and modern attempts to overcome them.

\bigskip
\noindent {\bf Motivation / Applications:}
\begin{itemize}
  \item Solving (partial) differential and integral equations
  \item machine learning, data-driven modelling, data assembly: The recent
  explosion in machine learning has given the field a new boost.
\end{itemize}

\bigskip \noindent {\bf Themes:}
\begin{enumerate}
\item Approximation spaces: what are ``good'' functions that we can combine
    to approximate general functions well; e.g.,
  \begin{itemize}
    \item Global approximation: trigonometric and algebraic  polynomials
    \item Piecewise approximation: splines
    \item rational functions
    \item Ridge functions
    \item Radial basis functions
    \item sparse grids
    \item artificial neural networks
  \end{itemize}

\item Algorithms, constructive approximation:
  \begin{itemize}
    \item best approximation, $L^2$-projection
    \item interpolation
    \item kernel methods
    \item least squares
    \item adaptive grids
    \item Inverse problems, parameter estimation
  \end{itemize}

\item Miscellaneous
  \begin{itemize}
    \item Regularity
    \item Numerical stability
    \item Curse of dimensionality
  \end{itemize}
\end{enumerate}

\subsection{Literature \& Acknowledgements}
%
\label{sec:acknowledgements}
%
Section~\ref{sec:trig} is largely based on random online available lecture notes
but partly motivated by \cite{Trefethen2000-fr,Trefethen2013-rg}.

Section~\ref{sec:poly} largely follows \cite{Trefethen2013-rg}, adding only the
Chebyshev transform and Jackson's theorem which are natural consequences of the
material on trigonometric approximation. The book \cite{Trefethen2013-rg} is
available for free online at
\begin{quote}
  {\tt http://www.chebfun.org/ATAP/}
\end{quote}

The section on splines is fairly standard material, but is based to some extend
on the classical text \cite{Powell1981-bg}.

Exercises are partly based on gaps in the lecture material, partly adapted from
these references.

% All of these texts are good references for further reading.

\section{Preliminaries}
%
\label{sec:prelims}
%

\subsection{Abstract Approximation Problems}
%
We are concerned with approximating specific functions given to us, or classes
of functions with specific properties, such as some given regularity,
periodicity, symmetries, etc. To study generic approximation schemes it is
therefore useful to begin by specifying a class $Y \subset X$ of functions of
interest. Typically $X$ will be an infinite-dimensional linear space,  and $Y$
an infinite-dimensional non-trivial subset of $X$. $X$ will be endowed with
a notion of distance $d$. We will later always assume this is given by a norm,
but this is not important for now.

In linear approximation (which is what most of this module is about)
we are given a set $B_N \subset X$, consisting of $N$ linearly independent
{\em basis functions}. Given some $f \in Y$ we then wish to find
an approximation to $f$ from ${\rm span} B_N =: Y_N$.

Fundamental questions/problem arising in this are, e.g.,
\begin{itemize}
\item Convergence: $\inf_{p \in Y_N} d(p, f) \to 0$ as $N \to \infty$
\item Best approximation: Find $p_N \in Y_N$ such that $d(p_N, f)$ is minimal.
\item Approximation to within some tolerance: given $\tau > 0$ find $N$ (minimal?)
  and $p_N \in Y_N$ such that $d(p_N, f) < \tau$.
\item Rates of approximation: $\inf_{p \in Y_N} d(p, f) \leq \epsilon_N$
  and characterise the rate, possibly uniformly for all $f \in Y$
\item Construction of approximations: Given $f$ give an algorithm to
  construct an approximation $p_N$ e.g., the best approximant.
\item Evaluation: efficient and numerically stable construction and
  evaluation of $p_N$.
\end{itemize}

In the exercises of Section~\ref{sec:prelims} we will collect a few basic
examples and generic facts.

\subsection{Basics}
%
In this section we briefly review some fact from analysis and linear algebra,
and most importantly, complex analysis. Facts about function spaces, measure theory and functional analysis will be used only minimally throughout this course and lack of background in those topics should not dissuade anybody from participating!

\subsubsection{$\R^N$}
%
The majority of the analysis in this module is for general
$N$-dimensional systems of ODEs. We will use the structure of $\R^N$
as a vector space, supplied with the Euclidean norm and inner product
\begin{displaymath}
  x \cdot y := x^T y = \sum_{i = 1}^N x_i y_i, \quad \text{and} \quad
  |x| := \sqrt{x \cdot x}
\end{displaymath}
Key inequalities that we will use on a regular basis are the {\em
  triangle inequality}
\begin{equation}
  \label{eq:triangle_ineq}
  |x + y| \leq |x| + |y| \qquad \text{ for } x, y \in \R^N,
\end{equation}
the {\em Cauchy--Schwarz inequality}
\begin{equation}
  \label{eq:cauchyschwarz_ineq}
  |x \cdot y| \leq |x| |y| \qquad \text{ for } x, y \in \R^N,
\end{equation}
and  {\em Cauchy's inequalities},
\begin{align}
  \label{eq:cauchy_ineq}
  a b &\leq \smfrac12 a^2 + \smfrac12 b^2 \qquad \text{ for } a, b \in
  \R, \\
  \label{eq:cauchy_eps_ineq}
  a b &\leq \smfrac\eps{2} a^2 + \smfrac1{2\eps} b^2 \qquad \text{ for
  } a, b \in \R, \eps > 0.
\end{align}

\subsubsection{Smooth functions}
%
Recall from the introductory analysis modules the definitions of
continuous functions and of uniform convergence. Here, we define the
spaces, for an interval $D \subset \R$,
\begin{align*}
  C(D) &:= \b\{ f : D \to \R \bsep f \text{ is continuous on } D \b\}
\end{align*}
If $D$ is compact ($D = [a, b]$ for $a, b \in \R$), then $C(D)$
is {\em complete} when equipped with the sup-norm
\begin{align*}
  \| f \|_{\infty} := \|f\|_{L^\infty} := \|f\|_{L^\infty(D)} := \sup_{x \in D} |f(x)|.
\end{align*}
We will more typically write $\|f\|_\infty$ if it is clear over which set the
supremum is taken. Note also that $D$ need not be compact in the
definition of $\|\cdot\|_{\infty, D}$.

Moreover, we define the spaces of $j$ times continuously differentiable functions
\[
  C^j(D) := \b\{ f : D \to \R \bsep f \text{ is $j$ times continuously
                differentiable on } D \b\},
\]
and the associated norms
\[
   \|f \|_{C^j} :=  \|f \|_{C^j(D)} :=
    \max_{n = 0, \dots j} \| f^{(n)} \|_{\infty, D},
\]
where $f^{(n)}$ denotes the $n$th derivative.

We also define $C^\infty(D) := \bigcup_{j > 0} C^j(D)$.

We say $f : D \to \R$ is H\"{o}lder continuous if there exists $\sigma \in (0, 1]$
such that
\[
    |f(x) - f(x')| \leq C |x - x'|^\sigma \qquad \forall x, x' \in D.
\]
The associated space is denoted by $C^{0,\sigma}$. If $\sigma = 1$ then
we call $f$ {\em Lipschitz continuous}. Further, we define the space
$C^{j,\sigma}(D) := \{ u \in C^j(D) \sep u^{(j)} \in C^{0,\sigma}(D)\}$.

The right-hand side in the definition of H\"{o}lder  continuity is
a special case of a {\em modulus of continuity}. We say that $f \in C([a,b])$ has a
{\em modulus of continuity} $\omega : [0, \infty) \to \R$ if
$\omega$ is monotonically increasing, $\omega(r) \to 0$ as $r \to 0$ and
\[
  |f(x) - f(x')| \leq \omega(|x-x'|) \qquad \forall x, x' \in [a,b].
\]
Indeed, any $f$ that is continuous on a closed interval has a modulus of continuity, which can simply be defined by
\[
  \omega(r) := \sup_{x \neq y \in [a, b], |x - y| \leq r} |f(x) - f(y)|.
\]

\subsubsection{Integrable functions}
%
Sometimes it will be convenient to consider measurable functions, and
for the sake of precision we briefly review the relevant definitions.
For $D = (a, b)$ an interval and $f : D \to \R$ measurable (i.e.,
$f^{-1}(B)$ is a Lebesgue set whenever $B$ is a Lebesgue set), we define
\[
    \| f \|_{L^p} := \|f \|_{L^p(D)} :=
      \left(\int_D |f|^p \,dx\right)^{1/p}, \qquad 1 \leq p < \infty,
\]
and
\[
    \|f\|_{L^\infty} := \|f\|_{L^\infty(D)} :=
    {\rm ess.}\sup_{x \in D} |f(x)|.
\]
We define the spaces
\[
  L^p(D) := \big\{ f : D \to \R \bsep \text{$f$ is measureable
                  and $\|f\|_{L^p(D)} < \infty$} \b\}.
\]

Finally, we recall the concept of absolutely continuous functions and weak derivatives.
If $g \in L^1(a,b)$ and
\[
  f(x) = c + \int_a^x g(t) \,dt,
\]
then we say that $f$ is absolutely continuous and write $f' = g$. Note that this derivative is now no longer defined in a pointwise sense, but it is normally defined via integration by parts,
\[
  \int_a^b f(x) \varphi'(x) \,dx = - \int_a^b f'(x) \varphi(x) \,dx
  \qquad \forall \varphi \in C^1(a,b), \varphi(a) = \varphi(b) = 0.
\]
If $f$ is absolutely continous, then we also write $f \in W^{1,1}(a,b)$. If $f$ is absolutely continuous and $f' \in L^p$, then we say $f \in W^{1,p}(a,b)$. These are the so-called Sobolev spaces. An immediate generalisation is that, if $f \in C^{m-1}(a,b)$, with $f^{(m-1)}$ absolutely continous and $f^{(m)} \in L^p$ then we write $f \in W^{m, p}$.

We will only make {\em minimal} use of Lebesgue and Sobolev spaces, but it is occasionally convenient to use them. A student who is deeply uncomfortable with these spaces should feel confident to substitute technical rigour for intuition gained through examples and discuss this with the instructor.

\subsubsection{Normed Spaces and Hilbert spaces}
%
A tuple $(X, \|\cdot\|)$ is called a normed space or normed vector space if
it is a linear space over the field $\mathbb{F}$ and
$\|\cdot\| : X \to \R$ defines a norm, i.e., for all $f, g \in X, \lambda \in \mathbb{F}$
\begin{itemize}
  \item $\|f + \lambda g\| \leq \|f\| + |\lambda| \|g\|$
  \item $\|f\| \geq 0$ and $\|f\| = 0$ iff $f = 0$.
\end{itemize}
$X$ is called a Banach space if it is complete (i.e. all Cauchy sequences
in $X$ have a limit in $X$).

If $D$ is compact then the spaces $(C^j, \|\cdot\|_{C^j})$ and
$(L^p, \|\cdot\|_{L^p})$ are Banach spaces. $C^{j,\sigma}$ may also be made
into Banach spaces, though we won't need this.

A tuple $(X, \<\cdot, \cdot\>)$ is called a Hilbert space over $\mathbb{F} \in
\{\R, \C\}$ if the following conditions are satisfied:
\begin{itemize}
  \item $X$ is a linear vector space
  \item $\<\cdot, \cdot\> : X \times X \to \mathbb{F}$ is an inner product, i.e.,
  for all $f, g, h \in X, \lambda \in \mathbb{F}$ we have
  \begin{itemize}
      \item $\<f, g\> = \overline{\< g, f\>}$
      \item $\< f + \lambda g, h \> = \<f, h \> + \lambda \< g, h \>$
      \item $\< f, f \> \geq 0$
      \item $\< f,f \> = 0$ iff. $f = 0$.
  \end{itemize}
  \item $X$ is complete under the norm $\|f\| := \<f,f\>^{1/2}$.
\end{itemize}

The most common example we will encounter are $L^2$-type spaces. In particular,
if $D$ is an interval (or in fact any measurable set), then $L^2(D)$ equipped
with the inner product
\[
  \< f, g \>_{L^2} := \int_D f \overline{g} \,dx
\]
is a Hilbert space.

% avoid $H^k$, $H^s$??? Or make this an exercise???

\subsection{Analytic functions}
%
A proper study of analytic functions requires far more time than we have
available. But some basics will suffice for the most important ideas.
To save time (and unfortunately skip some beautiful structures of
complex numbers) we will work exclusively with the definitions via power
series.

Recall therefore that each power series
\[
    \sum_{n = 0}^\infty c_n (z - z_0)^n
\]
has a radius of convergence
\[
    r = \frac{1}{\limsup_{n \to \infty} \sqrt[n]{|c_n|}}
\]
That is, the series converges absolutely and uniformly for $|z - z_0| < r$. It is an easy consequence to show that the function defined by the power series is differentiable in that ball. (in fact, $C^\infty$, but of course in complex analysis this always follows.)

\begin{definition}
  Let $D \subset \C$ be open and $f : D \to \C$. We say that $f$ is
  analytic at a point $z_0 \in D$ if there exists a power series
  $\sum_{n = 0}^\infty c_n (z - z_0)^n$ with  positive radius
  of convergence $r > 0$ such that
  \[
    f(z) = \sum_{n = 0}^\infty c_n (z - z_0)^n \qquad \forall
    z \in D, |z - z_0| < r.
  \]
  We say $f$ is analytic in $D$ if it is analytic in each point
  $z_0 \in D$ and write $f \in A(D)$.
\end{definition}

\medskip

We will need two simple concepts around analytic functions: (1) continuations;
and (2) path integrals. We will formulate simplified versions that are
sufficient for our purposes and only give rough ideas of the proofs
in the lectures (these are not contained in these lecture notes).

\begin{proposition}[Analytic Continuation]
  \begin{enumerate} \ilist
    %
    \item Let $D \subset \C$ be open, $f : D \to \C$ and let $D' \subset D$ be the
    set of points in which $f$ is analytic. Then $D'$ is open.
    %
    \item Let $D' \subset D \subset \C$, with $D$ open and connected and $D'$
    contains a line segment $\{(1-t) z_0 + t z_1 | t \in [0,1] \}$ with $z_0
    \neq z_1$. Let $f : D' \to \C$ be analytic and let $f_1, f_2 : D \to \C$ be
    two analytic continuations of $f$ to $D$ i.e., $f_j$ are analytic on $D$ and
    $f_j = f$ on $D'$. Then, $f_1 = f_2$.

    (Note: this result can be significantly generalised, but we will only need it for the case when $D'$ is a line segment, and this case is fairly straightforward and intuitive to prove.)
    %
    \item Let $f \in A([a, b])$ then there exists $D \supset [a,b]$ open in $\C$
    such that $f$ can be uniquely extended to a function $f \in A(D)$.
  \end{enumerate}
\end{proposition}

\def\calC{\mathcal{C}}

Concerning path integrals, let $\calC$ be a continuous and piecewise smooth
oriented  curve in $\C$, i.e., we identify $\calC$ with a parametrisation $(\zeta(t))_{t \in [0, 1]}$, then we define
\[
    \int_{\calC} f(z) \, dz := \int_{t = 0}^1 f(\zeta(t)) \zeta'(t) \, dt.
\]
Note that this definition makes sense even if $\zeta$ is not $C^1$, but
only piecewise $C^1$, and least with finitely many pieces.

If $\calC$ is a Jordan curve (simple and closed), then we assume that the orientation is counter-clockwise and we will write
\[
    \oint_{\calC} f(z) \,dz := \int_{\calC} f(z) \, dz
    = \int_{t = 0}^1 f(\zeta(t)) \zeta'(t) \, dt
\]
and call this a {\em contour integral}.

\begin{proposition}[Cauchy's Integral Theorem]
  Let $D \subset \C$ be open and simply connected, $f$ analytic in $D$ and
    $\calC \subset D$ a Jordan curve, then
    \[
        \oint_{\calC} f(z) \, dz = 0.
    \]
    %
\end{proposition}

\subsection{Exercises}

\begin{exercise}[Best Approximations]
  \label{exr:prelims:bestapprox}
  \begin{enumerate} \ilist
  \item Let $X$ be a vector space endowed with a norm $\|\cdot\|$,
  $X_N \subset X$ with ${\rm dim} X_N = N < \infty$ and let
  $Y_N \subset X_N$ be closed. (E.g. $Y_N=X_N$ is admissible.)
  Prove that for all $f \in X$ there exists a best approximation
  $p_N \in Y_N$, i.e.,
  \[
    \| p_N - f \|  = \inf_{y_N \in Y_N} \|y_N - f\|.
  \]

  \item Suppose $\|\cdot\|$ is strictly convex, i.e., for $f_0, f_1 \in X, \lambda \in (0, 1)$,
  \[
    \| (1-\lambda) f_0 + \lambda f_1 \| \leq (1-\lambda) \|f_0\| + \lambda \|f_1 \|
  \]
  with equality if and only if $f_0 \propto f_1$. Suppose also that $Y_N$ is
  convex. Under these two conditions prove that the best approximation from (i)
  is unique.

  \item Suppose that the {\em best approximation operator}
    $\Pi_N : f \mapsto p_N$ where $p_N$ is the unique best approximation to $f$
    is well-defined (e.g. in the setting of (ii)). Prove that $\Pi_N : X \to
    Y_N$ is continuous.
  \end{enumerate}
\end{exercise}

\begin{exercise}[Best Approx. in max-norms]
  \label{exr:prelims:bestapprox_maxnorms}
  \begin{enumerate}\ilist
  \item Consider $X = \R^2$ equipped with the $\ell^\infty$-norm. Show that
  this norm is {\em not} strictly convex. Consider the best approximation
  from $Y_N := \{ x \in \R^2 | |x|_\infty \leq 1 \}$. Show that
  \begin{itemize}
    \item $f = (2, 0)$, then the best-approximation is non-unique.
    \item $f = (2,2)$, then the best-approximation is unique.
  \end{itemize}
  {\it Hint: A geometric approach to this question is easiest. }

  \item Now consider $X = C([-1,1])$ and
  \[
    X_0 = Y_0 = \{ x \mapsto a | a \in \R \}
  \]
  i.e., approximation by constant functions. Prove that $\|\cdot\|_C =
  \|\cdot\|_{L^\infty}$ is {\em not} strictly convex, but nevertheless the best
  approximation problem for $Y_0$ has a unique solution.

  {\it Hint: An easy way to prove this is
  to simply construct the best approximation operator explicitly, which also
  helps with (iii).}

  \item {Bonus: } Now replace $X_0 = Y_0$ in (ii) with
  \[
      X_1 = Y_1 = \{ x \mapsto a + bx | a,b \in \R \},
  \]
  i.e., best approximation by affine functions. First, construct explicitly a
  best approximant from that space. Try to prove it is unique. This should
  be difficult; at least I don't see an elementary proof. (Please share if
   you find one!)  We will return to this problem later in the course. \qedhere
  \end{enumerate}
\end{exercise}

The last exercise should show that already for affine approximation the proof is not entirely trivial. We will return to best polynomial approximation in the max-norm in \S~\ref{sec:poly}; a classical and mathematically beautiful but in practise rather useless subject. In general, best approximation in non-Hilbert space norms is an unpleasant business. By contrast, best approximation in Hilbert spaces is straightforward, at least in theory:

\begin{exercise}[Best Approximation in a Hilbert Space]
  \label{exr:prelims:bestapprox_hilbert}
  Let $X$ be a Hilbert space with inner product $\<\cdot,\cdot\>$ and
  $Y_N = X_N \subset X$ an $N$-dimensional subspace.
  \begin{enumerate} \ilist
  \item Show that the best approximation $p_N$ of $f \in X$ in $X_N$ is characterised
    by the variational equation
    \[
         \< p_N, u \> = \< f, u \> \qquad \forall u \in X_N.
    \]
    Show that this has a unique solution.

    \item Let $\Pi_N f = p_N$ denote the best approximation operator. Show
    that it is an orthogonal projection.

    \item Deduce that
    \[
        \| f - \Pi_N f \|^2 = \|f\|^2 - \| \Pi_N f \|^2.
    \]

    \item {\bf Linear Approximation: }  Let $\{ e_j \}_{j \in \N}$ be an
    orthonormal basis of $X$, i.e., $\<e_j, e_n \> = \delta_{jn}$ and ${\rm
    clos}\,{\rm span}\{e_j\}_j = X$. Let $X_N := {\rm span}\{e_1, \dots, e_N\}$, then prove that
    \[
        \Pi_N f = \sum_{j = 1}^N \< f, e_j \> e_j. \qedhere
    \]
  \end{enumerate}
\end{exercise}

\begin{exercise} \label{exr:prelims:inequalities}
  \begin{enumerate} \ilist
  \item Prove \eqref{eq:cauchy_ineq} and
  \eqref{eq:cauchy_eps_ineq}.
  \item Use \eqref{eq:cauchy_ineq} to prove
  \eqref{eq:cauchyschwarz_ineq}.
  \item Use \eqref{eq:cauchyschwarz_ineq} to prove \eqref{eq:triangle_ineq}.
  \qedhere
  \end{enumerate}
\end{exercise}

\begin{exercise}   \label{exr:prelims:functions}
  For the following functions $f$, specify to which of the following
  spaces they belong: $C^{j,\sigma}([-1,1])$ (specify $j$ and $\sigma$),
  $C^\infty([-1,1])$, $A([-1,1])$, $L^p(-1,1)$. No rigorous proofs are
  required.
  %
  \begin{enumerate} \ilist
    \item $f(x) = x^n$, $n \in \N$
    \item $f(x) = |x|$
    \item $f(x) = |x|^{3}$
    \item $f(x) = |x|^{3/2}$
    \item $f(x) = (1+x^2)^{-1}$
    \item $f(x) = \exp( - 1 / (1/2-x) ) \chi_{[-1,1/2)}(x)$
    \item $f(x) = e^{-x^2}$
    \item $f(x) = \cos(1.23 x)$ \qedhere
  \end{enumerate}
\end{exercise}

\begin{exercise} \label{exr:prelims:extensions}
  Construct the analytic extensions of the following functions
  to a maximal set $D$ in  the complex plane, which you should specify:
  \begin{enumerate} \ilist
    \item $f(x) = e^{-x^2}$ on $\R$
    \item $f(x) = (1+x^2)^{-1}$ on $\R$
    \item $f(x) = \sum_{j = 0}^\infty x^j$ for $x \in (-1,1)$
    \item $f(x) = \int_0^\infty e^{-t (1-x)} \,dt$ for $x < 1$
  \end{enumerate}
\end{exercise}


\section{DeepSurv}

\begin{frame}{\insertsec}
    Paper published by Jared L.Katzman \emph{et al.} (2017) using a deep learning approach for
    the Survival Prediction problem.

    \begin{itemize}
        \item Shows an application of deep learning to survival analysis
        \item It uses this deep learning model to create a personalized treatment
        recommender system
        \item Uses the Cox Proportional Hazards Model
    \end{itemize}

\end{frame}

\begin{frame}{The Survival Prediction Problem}
    Survival data has three elements: patient's baseline data \( x \), a failure event
    time \( T \) and an event indicator \( E \).

    There's the survival function (\( S(t) = \Pr(T > t) \)) and the hazard function
    \( \lambda(t) \):
    \[
        \lambda(t) = \lim_{\delta \rightarrow 0}
        \frac{\Pr(t \le T < t + \delta | T \ge t)}{\delta}
    \]

    Given baseline data \( x \) the hazard function is assumed to have the form:
    \[
        \lambda(t | x) = \lambda_0 (t) \cdot e^{\bm{h(x)}}
    \]
\end{frame}

\begin{frame}{Linear Survival Models}
Cox Proportional Hazards model estimates that the risk function \( h(x) \) is linear
\( \hat{h}_{\beta}(x) = \beta^T x \). The partial likelihood, parameterized by \( \beta \) is
defined:

\[
    L_c (\beta) = \prod_{i:E_i = 1} \frac{\exp(\hat{h}_{\beta}(x_i))}
    {\sum_{j \in \mathfrak{R}(T_i)} \exp(\hat{h}_{\beta}(x_j))}
\]
\[
    \mathfrak{R}(t) = \{i: T_i \ge t\}
\]

\end{frame}

\begin{frame}[fragile]{Loss function}
The paper loss equation is the following one:
\[
    l(\theta) := -\sum_{i:E_i = 1} \left(
    \hat{h}_{\theta}(x_i) - \log \sum_{j \in \mathfrak{R}(T_i)} e^{\hat{h}_{\theta} (x_j)}
    \right)
\]

The code function is the following one:
\[
    l(\theta) := - \frac{1}{m} \sum_{i:E_i = 1} \left(
    \hat{h}_{\theta}(x_i) - \log \sum_{j} e^{\hat{h}_{\theta} (x_j)}
    \right)
\]

\footnotesize
\begin{verbatim}
risk = self.risk(deterministic)
hazard_ratio = T.exp(risk)
log_risk = T.log(T.extra_ops.cumsum(hazard_ratio))
uncensored_likelihood = risk.T - log_risk
censored_likelihood = uncensored_likelihood * E
num_observed_events = T.sum(E)
neg_likelihood = -T.sum(censored_likelihood)/num_observed_events
return neg_likelihood
\end{verbatim}
\end{frame}

\begin{frame}{DeepSurv Results}

\begin{center}
    \begin{tabular}{l|rrr}
        Experiment & CPH & DeepSurv & RSF \\
        \hline
        Simulated Linear & 0.774 & 0.774 & 0.765 \\
        Simulated Non-linear &  0.507 & 0.649 & 0.646 \\
        WHAS & 0.818 & 0.863 & 0.894 \\
        SUPPORT & 0.583 & 0.618 & 0.613 \\
        METABRIC & 0.631 & 0.643 & 0.624 \\
        Simulated Treatment & 0.482 & 0.583 & 0.570 \\
        Rotterdam \& GBSG & 0.658 & 0.668 & 0.651
    \end{tabular}
\end{center}

\end{frame}


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{September 19, 2014}
\maketitle
we use cauchy sequence to prove convergence when we don't know the value of the limit.
\section*{example 2.8.8}
read exmple, we are doing something similar
excercise I

show that \begin{align*}
  1+\frac{1}{1+\frac{1}{1+\frac{1}{1+\dots}}}
\end{align*}
is convergnt.

\begin{align*}
  a_1=1\\
  a_2=1+\frac{1}{1+1}=\frac{3}{2}\\
  a_3=1+\frac{1}{1+\frac{1}{1+1}}=\frac{5}{3}\\
  a_{n+1}=1+\frac{1}{a_n}\forall n\ge 2\\
  a_4=\frac{8}{5}\\
  a_5=\frac{13}{8}
  a_2<a3\\
  a_3>a_4
\end{align*}
next term is numerator+denominator divided by numerator

fibanocci sequence
\end{document}


% Created 2021-10-15 Fri 07:39
% Intended LaTeX compiler: pdflatex
\documentclass[presentation,aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{pifont}
\newcommand{\cmark}{\textcolor{green!80!black}{\ding{51}}}
\usepackage{amssymb}
\usepackage{pgfplotstable}
\DeclareMathOperator{\shift}{q}
\DeclareMathOperator{\diff}{p}
\usepackage{khpreamble, euscript, mathtools}
\DeclareMathOperator{\atantwo}{atan2}
\newcommand*{\ctrb}{\EuScript{C}}
\newcommand*{\obsv}{\EuScript{O}}
\usetheme{default}
\author{Kjartan Halvorsen}
\date{\today}
\title{State feedback}
\hypersetup{
 pdfauthor={Kjartan Halvorsen},
 pdftitle={State feedback},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 26.3 (Org mode 9.4.6)},
 pdflang={English}}
\begin{document}

\maketitle

\section{Apollo moon lander}
\label{sec:orgf2ea2b4}

\begin{frame}[label={sec:org348834a}]{The Apollo lunar module}
\begin{center}
\includegraphics[width=0.7\linewidth]{../../figures/fig-apollo}
\end{center}

\pause

\alert{Activity} Which is the transfer function of the system?
   \[1: \; G(s) = \frac{\frac{g}{J} }{s^2}\qquad 2: \; G(s) = \frac{\frac{g}{J} }{s(s^2 + 1)} \qquad 3: \; G(s) = \frac{\frac{g}{J} }{s^3}\]
\end{frame}

\begin{frame}[label={sec:orgfaa9732}]{State variables}
\begin{columns}
\begin{column}{0.65\columnwidth}
\begin{center}
\includegraphics[width=\linewidth]{../../figures/fig-apollo}
\end{center}

State variables: \(x = \begin{bmatrix} x_1 & x_2 & x_3 \end{bmatrix}^T = \begin{bmatrix} \dot{\theta} & \theta & \dot{z} \end{bmatrix}^T\).
\end{column}

\begin{column}{0.45\columnwidth}
With dynamics
  \[ \begin{cases} \dot{x}_1 =  \ddot{\theta} = \frac{1}{J} u\\ \dot{x}_2 = \dot{\theta} = x_1\\ \dot{x}_3 = \ddot{z} = g\theta = gx_2 \end{cases} \]
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:orgc9f7ee6}]{State-space model}
State variables: \(x = \begin{bmatrix} x_1 & x_2 & x_3 \end{bmatrix}^T = \begin{bmatrix} \dot{\theta} & \theta & \dot{z} \end{bmatrix}^T\). With dynamics
\[ \begin{cases} \dot{x}_1 =  \ddot{\theta} = \frac{1}{J} u\\ \dot{x}_2 = \dot{\theta} = x_1\\ \dot{x}_3 = \ddot{z} = g\theta = gx_2 \end{cases} \]

\alert{Activity} Fill the matrix \(A\) and vector \(B\).

\[ \dot{x} = \begin{bmatrix} \dot{x}_1\\\dot{x}_2\\\dot{x}_3\end{bmatrix} = \underbrace{\begin{bmatrix} \textcolor{white}{0} & \textcolor{white}{0} &\textcolor{white}{0} \\\textcolor{white}{1} & \textcolor{white}{0}& \textcolor{white}{0}\\ \textcolor{white}{0}& \textcolor{white}{g} &\textcolor{white}{0} \end{bmatrix}}_{A} \begin{bmatrix} x_1\\x_2\\x_3\end{bmatrix} + \underbrace{\begin{bmatrix} \textcolor{white}{\frac{1}{J}} \\ \textcolor{white}{0} \\\textcolor{white}{0}  \end{bmatrix}}_{B} u \]
\end{frame}

\begin{frame}[label={sec:org0597e2b}]{State-space model}
\end{frame}
\begin{frame}[label={sec:org2af19a2}]{State-space model}
State variables: \(x = \begin{bmatrix} x_1 & x_2 & x_3 \end{bmatrix}^T = \begin{bmatrix} \dot{\theta} & \theta & \dot{z} \end{bmatrix}^T\). With dynamics
\[ \begin{cases} \dot{x}_1 =  \ddot{\theta} = \frac{1}{J} u\\ \dot{x}_2 = \dot{\theta} = x_1\\ \dot{x}_3 = \ddot{z} = g\theta = gx_2 \end{cases} \]

\[ \dot{x} = \begin{bmatrix} \dot{x}_1\\\dot{x}_2\\\dot{x}_3\end{bmatrix} = \underbrace{\begin{bmatrix} \textcolor{red!60!black}{0} & \textcolor{red!60!black}{0} &\textcolor{red!60!black}{0} \\\textcolor{red!60!black}{1} & \textcolor{red!60!black}{0}& \textcolor{red!60!black}{0}\\ \textcolor{red!60!black}{0}& \textcolor{red!60!black}{g} &\textcolor{red!60!black}{0} \end{bmatrix}}_{A} \begin{bmatrix} x_1\\x_2\\x_3\end{bmatrix} + \underbrace{\begin{bmatrix} \textcolor{red!60!black}{\frac{1}{J}} \\ \textcolor{red!60!black}{0} \\\textcolor{red!60!black}{0}  \end{bmatrix}}_{B} u \]

\pause

\alert{Activity} What are the poles of the system?
\end{frame}

\begin{frame}[label={sec:org76223fa}]{Sensors}
\begin{center}
\includegraphics[width=0.8\linewidth]{../../figures/fig-apollo}
\end{center}
\alert{Activity} What sensors are needed for state feedback?
\end{frame}

\begin{frame}[label={sec:orgb7c22f6}]{Controllability}
\[ \dot{x} = \begin{bmatrix} \dot{x}_1\\\dot{x}_2\\\dot{x}_3\end{bmatrix} = \underbrace{\begin{bmatrix} \textcolor{black!60!black}{0} & \textcolor{black!60!black}{0} &\textcolor{black!60!black}{0} \\\textcolor{black!60!black}{1} & \textcolor{black!60!black}{0}& \textcolor{black!60!black}{0}\\ \textcolor{black!60!black}{0}& \textcolor{black!60!black}{g} &\textcolor{black!60!black}{0} \end{bmatrix}}_{A} \begin{bmatrix} x_1\\x_2\\x_3\end{bmatrix} + \underbrace{\begin{bmatrix} \textcolor{black!60!black}{\frac{1}{J}} \\ \textcolor{black!60!black}{0} \\\textcolor{black!60!black}{0}  \end{bmatrix}}_{B} u \]

Forming the controllability matrix. Note that
\[ A^2 = \begin{bmatrix} 0 &  0 & 0\\ 0 & 0 & 0\\ g & 0 & 0 \end{bmatrix} \]
\[ \mathcal{C} = \begin{bmatrix} B & AB & A^2B\end{bmatrix}
   = \begin{bmatrix} \frac{1}{J} & 0 & \textcolor{white}{0}\\0 & \frac{1}{J} & \textcolor{white}{0} \\0 & 0 & \textcolor{white}{\frac{1}{J}g} \end{bmatrix} \]

\pause
\alert{Activity} Is the system controllable?
\end{frame}

\begin{frame}[label={sec:org827db36}]{Linear state feedback}
\begin{columns}
\begin{column}{0.6\columnwidth}
\[ \dot{x} = \begin{bmatrix} \dot{x}_1\\\dot{x}_2\\\dot{x}_3\end{bmatrix} = \underbrace{\begin{bmatrix} \textcolor{black!60!black}{0} & \textcolor{black!60!black}{0} &\textcolor{black!60!black}{0} \\\textcolor{black!60!black}{1} & \textcolor{black!60!black}{0}& \textcolor{black!60!black}{0}\\ \textcolor{black!60!black}{0}& \textcolor{black!60!black}{g} &\textcolor{black!60!black}{0} \end{bmatrix}}_{A} \begin{bmatrix} x_1\\x_2\\x_3\end{bmatrix} + \underbrace{\begin{bmatrix} \textcolor{black!60!black}{\frac{1}{J}} \\ \textcolor{black!60!black}{0} \\\textcolor{black!60!black}{0}  \end{bmatrix}}_{B} u \]

Introduce linear state feedback

\[ u = -\textcolor{morange}{L}x + \textcolor{mbluegreen}{l_0} r,\]
where \(r\) is a reference signal.
\end{column}

\begin{column}{0.4\columnwidth}
Closed-loop system

\[\dot{x} = (A-B\textcolor{morange}{L})x + \textcolor{mbluegreen}{l_0}Br\]

Since the system is \alert{controllable}, we can find a gain vector \(\textcolor{morange}{L}\) that places the eigenvalues of \(A-B\textcolor{morange}{L}\) (the poles of the closed-loop system) at desired locations.
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org17d03c2}]{Linear state feedback}
\small

The poles of
\(\dot{x} = (A-B\textcolor{morange}{L})x + \textcolor{mbluegreen}{l_0}Br\)
are given by the solutions to the characteristic equation

\begin{align*}
\det \Big(sI - (A-B\textcolor{morange}{L})\Big) &= 0\\
\det \left(\begin{bmatrix} s & 0 & 0\\ 0 & s & 0\\ 0 & 0 & s
\end{bmatrix}
- \begin{bmatrix} 0 & 0 & 0\\1 & 0 & 0\\0 & g & 0\end{bmatrix}
+ \begin{bmatrix} \frac{1}{J}\textcolor{morange}{l_1} & \frac{1}{J}\textcolor{morange}{l_2} & \frac{1}{J}\textcolor{morange}{l_3}\\0 & 0 & 0\\0 & 0 & 0\end{bmatrix}\right) &= 0\\
\det \begin{bmatrix} s+\frac{1}{J}\textcolor{morange}{l_1} & \frac{1}{J}\textcolor{morange}{l_2} & \frac{1}{J}\textcolor{morange}{l_3}\\-1 & s & 0\\0 & -g & s \end{bmatrix} &= 0\\
(s+\frac{1}{J}\textcolor{morange}{l_1})s^2  + \frac{1}{J}\textcolor{morange}{l_2}s +\frac{1}{J}g\textcolor{morange}{l_3} &= 0\\
s^3 + \frac{1}{J}\textcolor{morange}{l_1}s^2 + \frac{1}{J}\textcolor{morange}{l_2}s +\frac{1}{J}g\textcolor{morange}{l_3} &= 0
\end{align*}
\end{frame}

\begin{frame}[label={sec:orga0df4f2}]{Where to place the closed-loop poles}
\begin{columns}
\begin{column}{0.35\columnwidth}
\begin{center}
  \begin{tikzpicture}[scale=0.7]
  \pgfmathsetmacro{\wc}{2}
  \pgfmathsetmacro{\rp}{\wc*cos(45)}
    \draw[->] (-4,0) to (2,0) node[below] {Re};
    \draw[->] (0,-3) to (0,3) node[left] {Im};

    \draw[dashed, black!80] (0,\wc) arc[radius=\wc{}cm, start angle=90, end angle=270];

    \node[anchor=center, red!80!black] at (-\rp, \rp) {\Large $\times$ };
    \node[anchor=center, red!80!black] at (-\rp, -\rp) {\Large $\times$ };
    \node[anchor=center, red!80!black] at (-\wc, 0) {\Large $\times$ };

    \draw[thin, <->] (0,0) -- node[above] {$\frac{1}{\tau_c}$} (-\rp, \rp);
    \end{tikzpicture}
\end{center}
\end{column}

\begin{column}{0.65\columnwidth}
Desired closed-loop characteristic polynomial

\begin{align*}
  (s-p_1)(s-p_2)(s-p_3) &= (s+\frac{1}{\tau_c})(s^2 + \frac{\sqrt{2}}{\tau_c}s + \frac{1}{\tau_c^2})\\
   &= s^3 + \frac{1 + \sqrt{2}}{\tau_c}s^2 + \frac{1+\sqrt{2}}{\tau_c^2}s + \frac{1}{\tau_c^3}
\end{align*}
\end{column}
\end{columns}
\end{frame}

\begin{frame}[label={sec:org6f6ed56}]{Determining the state feedback gain}
By linear state feedback we have characteristic polynomial
\[\det \Big(sI - (A-B\textcolor{morange}{L})\Big) =  s^3 + \frac{1}{J}\textcolor{morange}{l_1}s^2 + \frac{1}{J}\textcolor{morange}{l_2}s + \frac{1}{J}g\textcolor{morange}{l_3}.\]

And we want to achieve the characteristic polynomial
\[ s^3 + \frac{1 + \sqrt{2}}{\tau_c}s^2 + \frac{1+\sqrt{2}}{\tau_c^2}s + \frac{1}{\tau_c^3}. \]

\alert{Activity} What do we do next?
\end{frame}

\begin{frame}[label={sec:org2393acf}]{Determining the state feedback gain}
Set the characteristic polynomial obtained from \(\det\) \Big(sI - (A-B\textcolor{morange}{L})\Big) equal to the desired characteristic polynomial

\[ s^3 + \frac{1}{J}\textcolor{morange}{l_1}s^2 + \frac{1}{J}\textcolor{morange}{l_2}s + \frac{1}{J}g\textcolor{morange}{l_3} =  s^3 + \frac{1 + \sqrt{2}}{\tau_c}s^2 + \frac{1+\sqrt{2}}{\tau_c^2}s + \frac{1}{\tau_c^3} \]

Solve for the gains by setting corresponding coefficients equal.

\begin{equation*}
\begin{rcases}
s^2: \quad & \frac{1}{J}\textcolor{morange}{l_1} = \frac{1 + \sqrt{2}}{\tau_c}\\
s^1: \quad & \frac{1}{J}\textcolor{morange}{l_2} = \frac{1 + \sqrt{2}}{\tau_c^2}\\
s^0: \quad & \frac{1}{J}g\textcolor{morange}{l_3} = \frac{1}{\tau_c^3}
\end{rcases} \Rightarrow
\begin{rcases}
 \quad \textcolor{morange}{l_1} &= \frac{J(1 + \sqrt{2})}{\tau_c}\\
 \quad \textcolor{morange}{l_2} &= \frac{J(1 + \sqrt{2})}{\tau_c^2}\\
 \quad \textcolor{morange}{l_3} &= \frac{J}{g\tau_c^3}
\end{rcases}
\end{equation*}
\end{frame}

\begin{frame}[label={sec:org8879e69}]{The gain \(l_0\)}
\begin{center}
\includegraphics[width=0.6\linewidth]{../../figures/block-apollo}
\end{center}

\[ G(s) = \frac{\frac{g}{J}}{s^3}\]
It can be shown that state feedback does not change the numerator of the transfer function, only the denominator, so

\[G_c(s) = \textcolor{mbluegreen}{l_0}\frac{\frac{g}{J}}{s^3 + \frac{1 + \sqrt{2}}{\tau_c}s^2 + \frac{1+\sqrt{2}}{\tau_c^2}s + \frac{1}{\tau_c^3}}\]

We want unit static gain,  \(G_c(0) = 1\)

\pause

\alert{Activity} Determine the gain \(\textcolor{mbluegreen}{l_0}\)
\end{frame}
\end{document}