\documentclass[a4paper,12pt]{article}
\usepackage[left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{amsmath,amssymb,amsthm,algorithm,algorithmic,graphicx,yhmath,url,enumitem,lscape,hyperref}
\usepackage{wrapfig,subfigure}
\usepackage{lineno}

\newcounter{problem}
\newcounter{remark}
\newcounter{hint}
\newenvironment{remark}{\refstepcounter{remark} \vspace{0.1cm} \par \noindent {\bf Remark \arabic{remark}}}{\vspace{0.3cm}}
\newenvironment{hint}{\refstepcounter{hint} \vspace{0.1cm} \par \noindent {\bf Hint \arabic{hint}}}{\vspace{0.3cm}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Rn}{\mathbb{R}^n}
\newcommand{\Rnn}{\mathbb{R}^{n \times n}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bms}{\begin{multline*}}
\newcommand{\emults}{\end{multline*}}

% Matrices
\newcommand{\bbm}{\begin{bmatrix}}
\newcommand{\ebm}{\end{bmatrix}}
\newcommand{\bpm}{\begin{pmatrix}}
\newcommand{\epm}{\end{pmatrix}}

% Strecthing
\renewcommand{\arraystretch}{1.3}

\newcommand{\eps}{\epsilon}
\newcommand{\fl}{\text{fl}}
\newcommand{\Lp}{{L^p}}
\newcommand{\Ker}{\text{Ker}\,}
\newcommand{\loc}{{\text{loc}}}
\newcommand{\ccinf}{C_c^\infty}
\newcommand{\supp}{\text{supp}}
\newcommand{\dist}{\text{dist}}

% Gravitational acceleration
\newcommand{\bg}{\mathbf{g}}
% Friction force
\newcommand{\bFf}{\mathbf{F_f}}
% Gravitational force
\newcommand{\bFg}{\mathbf{F_g}}
% Force
\newcommand{\bF}{\mathbf{F}}
% Position, velocity, acceleration
\newcommand{\br}{\mathbf{r}}
\newcommand{\bv}{\mathbf{v}}
\newcommand{\ba}{\mathbf{a}}

% Jacobian
\newcommand{\bDF}{\mathbf{DF}}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}[theorem]{Definition}
\title{Robust and accurate root finding for real polynomials}
\author{Carl Christian Kjelgaard Mikkelsen}

\begin{document}

\pagenumbering{arabic}
% Turn off line numbering by commenting the following line.
\linenumbers
\thispagestyle{empty}

\noindent
Ume\aa{} University \hfill Fall 2018 \\
Department of Computing Science\\

\vskip 2.5cm

\begin{center} {\Huge {\bf Project 1}}\\{\Large Robust and accurate root finding for real polynomials}\end{center} \vskip 0.3cm
\begin{center}
  {\huge Scientific Computing}
  \vfill
  {\Large The deadline for this project can be found at: \href{http://www8.cs.umu.se/kurser/5DV005/HT18/planering.html}{http://www8.cs.umu.se/kurser/5DV005/HT18/planering.html}\\
  (Link \emph{Overview} on the course homepage.)}
\end{center}
  \vfill
  {% \large
\begin{itemize}
\item The submission should consist of:
  \begin{itemize}
  \item The complete report, including
    \begin{itemize}
    \item A front page with the following information:
      \begin{enumerate}
      \item Your {\bf name}.
      \item The {\bf course name}.
      \item Your {\bf username} at the Department of Computing
        Science.
      \item The {\bf project number}.
      \item The {\bf version} of the submission (in case of re-submissions).
      \end{enumerate}
    \end{itemize}
  \item An appendix with the source code.
  \item To simplify feedback, the main report (optionally excluding
    the appendix) must have {\bf numbered sections} and {\bf page
      numbers}.
  \end{itemize}
\item The submitted code must be Matlab-compatible. If you choose to
  work in Octave, verify that your code is Matlab-compatible before
  you submit your project.
\item If you write your report using \LaTeX, double-check that your
  references have been resolved correctly before you submit. ``Figure ??'' is useless to any reader.
\item Your report should be submitted as a pdf file uploaded via
  the\linebreak
  \href{https://webapps.cs.umu.se/labresults/v2/handin.php?courseid=337}{https://webapps.cs.umu.se/labresults/v2/handin.php?courseid=337}
  page, also available as the
\begin{center}
  \href{http://www8.cs.umu.se/kurser/5DV005/HT18/index2.html}{Submit/Check results}
\end{center} link at the bottom left of the course home page.
\item Furthermore, every scrap of MATLAB code developed by your team should be uploaded in a single zip file, {\tt P1Code.zip}.
\end{itemize}
  }
  \vfill

\newpage

\maketitle

\tableofcontents
\listoffigures

\section{What makes a good report?}

A good report has lasting value for end user as well as the author. A good reports can be read without referring to the assignment specification. A good report has a clear structure. It has a meaningful title, a list of contributors, a table of contents, a list of figures and a list of tables both with short meaningful titles. An introduction describes the overall purpose of the report and lists the topics that will be discussed. Subsequent sections are dedicated to individual topics. Relevant questions are clearly formulated and answered. The writer's reasoning is explained and all claims are carefully supported. Tables and pictures with meaningful labels and captions are presented and relevant details are discussed. Appropriate references are made to other reports, books, or appendices. A good report ends with a summary of the results obtained, a list of any unresolved issues and suggestions for future work.

\section{Purpose} In this project you will develop a function {\tt my\_root} which can be used to compute all real roots of a real polynomial $y = p(x)$ on the real line.
The function will automatically detect and abort if the sign of the computed value $\hat{y}$ can not be trusted. When developing software your priorities are robustness, accuracy and speed in that order. This project will demonstrate how to write numerical software which is aware of its own limitations and can issue appropriate warnings.

\section{Motivation}

Polynomials and rational functions are the only functions we can compute using the basic arithmetic operations. Fortunately, all other functions can be approximated using these operations. In the world of computational science there are two kinds of problems:
\begin{itemize}
\item computing function values, and
\item solving equations.
\end{itemize}
If we can not accomplish these task for polynomials in a manner which is robust, accurate and fast, then we should not attempt to solve more complicated problems.

\section{Construction of test cases}

When developing software one must also develop test cases which can be used to detect bugs. The test cases must be so complex that all branches of the code are executed. For numerical software, the examples must be chosen such that we know the correct result. Frequently, it is practical to compute all intermediate results by hand or using another program. Well chosen test cases can reveal bugs, but only careful analysis of the program can eliminate bugs.

In the context of root finding for polynomials, we require polynomials which are simple to define and have known roots which can be computed accurately. One such class of polynomials are the Chebyshev polynomials $T_n$ of the first kind. They are given by the following linear recurrence relation
\begin{align}
  T_0(x) &= 1 \\
  T_1(x) &= x \\
  T_{j+1} &= 2x T_j(x) - T_{j-1}(x), \quad j \in \{1,2,3,\dotsc\}.
\end{align}

\begin{enumerate}
\item Find the explicit formula for $T_n$ for $n=3,4,5,6$ by hand.
\item Show by induction that $T_n$ has degree $n$. Consult the examples given in Chapter 3 of \cite{mikkelsen2018} to see how proofs by induction are written properly.
\item Copy {\tt no1/scripts/a1f1.m} into {\tt no1/work/MyChebyshev.m} and complete the function according to the specifications. The function must compute $T_j(x)$ for $j=0,1,2,\dots,n-1$ and $x \in X$, where $X$ is an arbitrary array.
\item Copy {\tt no1/scripts/a1f2.m} into {\tt no1/work/MyChebyshevMWE1} and complete the script so that it generates a figure similar to Fig \ref{fig:PlotChebyshev}.
\end{enumerate}

\begin{figure}
  \centering
  \includegraphics[width=0.7\textwidth]{PlotChebyshev.pdf} \caption[Plot of the first few Chebyshev polynomials of the first kind.]{A plot of the first $n=6$ Chebyshev polynomials of the first kind.} \label{fig:PlotChebyshev}
\end{figure}

It is straightforward, but tedious to verify that, say, $T_{10}$ is given by
\be
T_{10}(x) = 512 x^{10} - 1280 x^8 + 1120 x^6 - 400 x^4 + 50 x^2 - 1,
\ee
but it is not at all obvious what the roots might be!

The following theorem can be used without proof.

\begin{theorem} The Chebyshev polynomials of the first kind satisfy the equation
  \be
T_n(\cos(\theta)) = \cos(n\theta), \quad \theta \in \R.
\ee
\end{theorem}

\begin{enumerate}[resume]
\item Show that the $n$ roots of $T_n$ are given by
  \be \label{equ:exact-roots}
  x_k = \cos\left(\frac{(2k-1)\pi}{2n}\right), \quad k = 1,2,\dots,n.
  \ee
\end{enumerate}

\begin{hint} If you do not exploit the fact that $T_n$ has degree $n$ and if you do not reference the Fundamental Theorem of Algebra, then your proof is not complete.
\end{hint}

\begin{remark} It is worth observing that the coefficients of $T_n$ are all integers. These integers are small enough to be exactly representable in, say, double precision floating point arithmetic, at least for small values of $n$. The roots of $T_n$ are contained in the interval $[-1,1]$, hence we know where our solver should look. Moreover, the roots can be computed accurately from formula \eqref{equ:exact-roots} except near the middle of the interval as $x \to \cos(x)$ is ill conditioned near $x = \frac{\pi}{2}$. These properties all excellent qualities for a test case.
\end{remark}

\section{Root finding software}

If $f : \mathbb{R} \rightarrow \mathbb{R}$ is continuous and $f(a)$ and $f(b)$ have different sign, then there exists a zero of $f$ between $a$ and $b$. We say that $a$ and $b$ bracket the root. In floating point we cannot necessarily trust the computed value of the sign of $y = f(x)$. If $f$ is a polynomial, then we can compute a running error bound, i.e., a number $\mu$ such that
\be
|y - \hat{y}| \leq \mu u
\ee
where $\hat{y}$ is the computed value of $y = f(x)$ and $u$ is the unit roundoff. If $|\hat{y}| > \mu u$, then $y$ and $\hat{y}$ have the same sign, i.e., the computed value of the sign of $y$ is correct. If $|\hat{y}| \leq \mu u$, then $y$ and $\hat{y}$ need not have the same sign. In particular, $y=0$ is a distinct possibility and $x$ could be a root.

\begin{enumerate}
\item Copy {\tt no1/scripts/a1f3.m} into {\tt no1/work/MyRoot.m} and complete the function according to its specification. In particular, {\tt MyRoot} must evaluate your polynomial $y=p(x)$ and error bounds using your function {\tt my\_horner} and it must use the bisection algorithm to refine a bracket around a root. {\tt MyRoot} must reject the initial bracket if the computed sign of $p(a)$ and $p(b)$ cannot be trusted or if the computed signs can be trusted and are identical. The function must terminate and return $x$ if the computed sign of $y=p(x)$ cannot be trusted.
\item Develop a minimal working example {\tt no1/work/MyRootMWE1} which finds good approximations of all roots of $T_{10}$ and displays all information in a nice table. The results for $T_6$ should be similar to Figure \ref{fig:MyRootMWE6}.

  \begin{hint} The class repository contains an auxiliary function {\tt displaytable} which can be used to print tables nicely. It is worth your time to learn who to use this function, see {\tt compute\_range} for an illustration.
\end{hint}

\begin{landscape}
\begin{figure}
  \begin{verbatim}
 Idx | flag | iter |              a |            b |         root |     residual |          REB | trust
   1 |    1 |   29 |    -9.6593e-01 |  -9.6593e-01 |  -9.6593e-01 |  -7.2711e-10 |   1.6115e-14 |     1
   2 |    2 |   26 |    -7.0711e-01 |  -7.0711e-01 |  -7.0711e-01 |   3.0926e-11 |   5.3291e-15 |     1
   3 |    2 |   26 |    -2.5882e-01 |  -2.5882e-01 |  -2.5882e-01 |   5.6922e-11 |   5.3867e-16 |     1
   4 |    2 |   26 |     2.5882e-01 |   2.5882e-01 |   2.5882e-01 |   5.6922e-11 |   5.3867e-16 |     1
   5 |    2 |   26 |     7.0711e-01 |   7.0711e-01 |   7.0711e-01 |   3.0926e-11 |   5.3291e-15 |     1
   6 |    1 |   29 |     9.6593e-01 |   9.6593e-01 |   9.6593e-01 |  -7.2711e-10 |   1.6115e-14 |     1
\end{verbatim} \caption[Root finding for $T_6$.]{The result of applying {\tt MyRoot} to the polynomial $T_6$. Initially, $m=101$ equidistant points in the interval $[-1,1]$ where used to define (potential) brackets. Tolerance {\tt delta = 1e-10} and {\tt eps=1e-10} were used to control the bisection process. Notice the variation in the flags and iteration counts returned by {\tt MyRoot} and the fact that the sign checks are positive.} \label{fig:MyRootMWE6}
  \end{figure}
\end{landscape}

\end{enumerate}

\section{Calculations}

\begin{enumerate}
\item Find all $n$ roots of $T_n$ for $n=10$ with a relative error less than $\tau = 10^{-13}$ using {\tt MyRoot}.
\item For each root explain, why your calculations can be trusted.
  \begin{hint}
    If your explanation does not refer to relevant brackets and running error bounds, then it not complete.
  \end{hint}
\end{enumerate}

\begin{remark}
  The vast majority of users are completely ignorant of floating point arithmetic and will blindly rely on the results produced by a computer program.  Sadly, many codes are written by intelligent people who are blissfully unaware of the limitations of floating point arithmetic. It is our responsibility to write code which is reliable, sufficiently accurate for the task at hand, and sufficiently fast.
\end{remark}

 \bibliographystyle{plain}
  \bibliography{../../../lecture-notes/refs}

\end{document}


\chapter{The Initial Mass Function: Theory}
\label{ch:imf_th}

\marginnote{
\textbf{Suggested background reading:}
\begin{itemize}
\item \href{http://adsabs.harvard.edu/abs/2014arXiv1402.0867K}{Krumholz, M.~R. 2014, Phys.~Rep., 539, 49}, section 6 \nocite{krumholz14c}
\end{itemize}
\textbf{Suggested literature:}
\begin{itemize}
\item \href{http://adsabs.harvard.edu/abs/2012MNRAS.423.2037H}{Hopkins, 2012, MNRAS, 423, 2037} \nocite{hopkins12d}
\item \href{http://adsabs.harvard.edu/abs/2012ApJ...754...71K}{Krumholz et al., 2012, ApJ, 754, 71} \nocite{krumholz12b}
\end{itemize}
}

The previous chapter discussed observations of the initial mass function, both how they are made and what they tell us. We now turn to theoretical attempts to explain the IMF. As with theoretical models of the star formation rate, there is at present no completely satisfactory theory for the origin of the IMF, just different ideas that do better or worse at various aspects of the problem. To recall, the things we would really like to explain most are (1) the slope of the powerlaw at high masses, and (2) the location of the peak mass. We would also like to explain the little-to-zero variation in these quantities with galactic environment. Furthermore, we would like to explain the origin of the distribution of binary properties.

\section{The Powerlaw Tail}

We begin by considering the powerlaw tail at high masses, $dn/dm \propto m^{-\Gamma}$ with $\Gamma \approx 2.3$. There are two main classes of theories for how this powerlaw tail is set: competitive accretion and turbulence. Both are scale-free processes that could plausibly produce a powerlaw distribution of masses comparable to what is observed.

\subsection{Competitive Accretion}

One hypothesis for how to produce a powerlaw mass distribution is to consider what will happen in a region where a collection of small "seed" stars form, and then begin to accrete at a rate that is a function of their current mass. Quantitatively, and for simplicity, suppose that every star accretes at a rate proportional to some power of its current mass, i.e.,
\begin{equation}
\frac{dm}{dt} \propto m^\eta.
\end{equation}
If we start with a mass $m_0$ and accretion rate $\dot{m}_0$ at time $t_0$, this ODE is easy to solve for the mass at later times. We get
\begin{equation}
m(t) = m_0 \left\{
\begin{array}{ll}
[1 - (\eta-1)\tau]^{1/(1-\eta)}, & \eta \neq 1 \\
\exp(\tau), & \eta = 1
\end{array}
\right.,
\end{equation}
where $\tau = t / (m_0/\dot{m}_0)$ is the time measured in units of the initial mass-doubling time. The case for $\eta = 1$ is the usual exponential growth, and the case for $\eta > 1$ is even faster, running away to infinite mass in a finite amount of time $\tau = 1/(\eta-1)$.

Now suppose that we start with a collection of stars that all begin at mass $m_0$, but have slightly different values of $\tau$ at which they stop growing, corresponding either to growth stopping at different physical times from one star to another, to stars stopping at the same time but having slightly different initial accretion rates $\dot{m}_0$, or some combination of both. What will the mass distribution of the resulting population be? If $dn/d\tau$ is the distribution of stopping times, then we will have
\begin{equation}
\frac{dn}{dm} \propto \frac{dn/d\tau}{dm/d\tau} \propto m(\tau)^{-\eta} \frac{dn}{d\tau}.
\end{equation}
Thus the final distribution of masses will be a powerlaw in mass, with index $-\eta$, going from $m(\tau_{\rm min})$ to $m(\tau_{\rm max})$; a powerlaw distribution naturally results.

The index of this powerlaw will depend on the index of the accretion law, $\eta$. What should this be? In the case of a point mass accreting from a uniform, infinite medium at rest, the accretion rate was worked out by \citet{hoyle46a} and \citet{bondi52a}, and the problem is known as Bondi-Hoyle accretion. The accretion rate scales as $\dot{m} \propto m^2$, so if this process describes how stars form, then the expected mass distribution should follow $dn/dm\propto m^{-2}$, not so far from the actual slope of $-2.3$ that we observe. A number of authors have argued that this difference can be made up by considering the effects of a crowded environment, where the feeding regions of smaller stars get tidally truncated, and thus the growth law winds up begin somewhat steeper than $\dot{m}\propto m^2$.

\begin{marginfigure}
\includegraphics[width=\linewidth]{imf_bate09}
\caption[IMF in a competitive accretion simulation]{
\label{fig:imf_bate09}
The IMF measured in a simulation of the collapse of a 500 $M_\odot$ initially uniform density cloud. The single-hatched histogram shows all objects in the simulation, while the double-hatched one shows objects that have stopped accreting. Credit: \citeauthor{bate09b}, 2009, MNRAS, 392, 590, reproduced by permission of Oxford University Press on behalf of the RAS.
}
\end{marginfigure}
This is an extremely simple model, requiring no physics but hydrodynamics and gravity, and thus it is easy to simulate. Simulations done based on this model do sometimes return a mass distribution that looks much like the IMF, as illustrated in Figure \ref{fig:imf_bate09}. However, this appears to depend on the choice of initial conditions. Generally speaking, one gets about the right IMF if one stars with something with a virial ratio $\alpha_{\rm vir} \sim 1$ and no initial density structure, just velocities. Simulations that start with either supervirial or sub-virial initial conditions, or that begin with turbulent density structures, do not appear to grow as predicted by competitive accretion (e.g., \citealt{clark08a}).

Another potential problem with this model is that it only seems to work in environments where there is no substantial feedback to drive the turbulence or eject the gas. In simulations where this is not true, there appears to be no competitive accretion. The key issue is that competitive accretion seems to require a global collapse where all the stars fall together into a region where they can compete, and this is hard to accomplish in the presence of feedback.

Yet a third potential issue is that this model has trouble making sense of the IMF peak, as we will discuss in Section \ref{sec:imfpeak}.

\subsection{Turbulent Fragmentation}

A second class of models for the origin of the powerlaw slope is based on the physics of turbulence. The first of these models was proposed by \citet{padoan97a}, and there have been numerous refinements since \citep[e.g.,][]{padoan02a, padoan07a, hennebelle08b, hennebelle09a, hopkins12e, hopkins12d}. The basic assumption in the turbulence models is that the process of shocks repeatedly passing through an isothermal medium leads to a broad range of densities, and that stars form wherever a local region happens to be pushed to the point where it becomes self-gravitating. We then proceed as follows. Suppose we consider the density field smoothed on some size scale $\ell$. The mass of an object of density $\rho$ in this smoothed field is
\begin{equation}
m \sim \rho \ell^3,
\end{equation}
and the total mass of objects with characteristic density between $\rho$ and $\rho+d\rho$ is
\begin{equation}
dM_{\rm tot} \sim \rho p(\rho) \,d\rho,
\end{equation}
where $p(\rho)$ is the density PDF. Then the total number of objects in the mass range from $m$ to $m+dm$ on size scale $\ell$ can be obtained just by dividing the total mass of objects at a given density by the mass per object, and integrating over the density PDF on that size scale
\begin{equation}
\frac{dn_\ell}{dm} = \frac{dM_{\rm tot}}{m} \sim  \ell^{-3} \int p(\rho) \,d\rho.
\end{equation}

Not all of these structures will be bound. To filter out the ones that are, we impose a density threshold, analogous to the one we used in computing the star formation rate in Section \ref{ssec:eff_th}.\footnote{Indeed, several of the models discussed there allow simultaneous computation of the star formation rate and the IMF.} We assert that an object will be bound only if its gravitational energy exceeds its kinetic energy, that is, only if the density exceeds a critical value given by
\begin{equation}
\frac{Gm^2}{\ell} \sim m \sigma(\ell)^2
\qquad\Longrightarrow\qquad
\rho_{\rm crit} \sim \frac{\sigma(\ell)^2}{G \ell^2},
\end{equation}
where $\sigma(\ell)$ is the velocity dispersion on size scale $\ell$, which we take from the linewidth-size relation, $\sigma(\ell) = c_s (\ell/\ell_s)^{1/2}$. Thus we have a critical density
\begin{equation}
\rho_{\rm crit} \sim \frac{c_s^2}{G \ell_s \ell},
\end{equation}
and this forms a lower limit on the integral.

There are two more steps in the argument. One is simple: just integrate over all length scales to get the total number of objects. That is,
\begin{equation}
\frac{dn}{dm} \propto \int \frac{dn_\ell}{dm} \, d\ell.
\end{equation}
The second is that we must know the functional form $p(\rho)$ for the smoothed density PDF. One can estimate this in a variety of ways, but to date no one has performed a fully rigorous calculation. For example, \citet{hopkins12e} assumes that the PDF is lognormal no matter what scale it is smoothed on, and all that changes as one alters the smoothing scale is the dispersion. He obtains this by setting the dispersion on some scale $\sigma_\ell$ equal to an integral over the dispersions on all smaller scales. In contrast, \citet{hennebelle08b, hennebelle09a} assume that the density power spectrum is a powerlaw, and derive the density PDF from that. These two assumptions yield similar but not identical results.

\begin{marginfigure}
\includegraphics[width=\linewidth]{imf_hopkins12}
\caption[IMF from an analytic model of turbulent fragmentation]{
\label{fig:imf_hopkins12}
The IMF predicted by an analytic model of turbulent fragmentation. Credit: \citeauthor{hopkins12d}, MNRAS, 423, 2037, reproduced by permission of Oxford University Press on behalf of the RAS.
}
\end{marginfigure}
At this point we will cease following the mathematical formalism in detail; interested readers can find it worked out in the papers referenced above. We will simply assert that one can at this point evaluate all the integrals to get an IMF. The result clearly depends only on two dimensional quantities: the sound speed $c_s$ and the sonic length $\ell_s$. However, at masses much greater than the sonic mass $M_s \approx c_s^2 \ell_s/G$, the result is close to a powerlaw with approximately the right index. Figure \ref{fig:imf_hopkins12} shows an example prediction.

As with the competitive accretion model, this hypothesis encounters certain difficulties. First, there is the technical problem that the choice of smoothed density PDF estimate is not at all rigorous, and there are noticeable differences in the result depending on how the choice is made. Second, the dependence on the sonic length is potentially problematic, because real molecular clouds do not have constant sonic lengths. Regions of massive star formation are observed to be systematically more turbulent. Third, the theory does not address the question of why gravitationally-bound regions do not sub-fragment as they collapse. Indeed, \citet{guszejnov15a} and \citet{guszejnov16a} argue that, when this effect is taken into account, the IMF (as opposed to the core mass distribution) becomes a pure powerlaw. As a result, the model has trouble explaining the IMF peak.

\section{The Peak of the IMF}
\label{sec:imfpeak}

\subsection{Basic Theoretical Considerations}

A powerlaw is scale-free, but the peak has a definite mass scale. This mass scale is one basic observable that any theory of star formation must be able to predict. Moreover, the presence of a characteristic mass scale immediately tells us something about the physical processes that must be involved in producing the IMF. We have thus far thought of molecular clouds as consisting mostly of isothermal, turbulent, magnetized, self-gravitating gas. However, we can show that there \textit{must} be additional processes beyond these at work in setting a peak mass.

We can see this in a few ways. First we can demonstrate it in a more intuitive but not rigorous manner, and then we can demonstrate it rigorously. The intuitive argument is as follows. In the system we have described, there are four energies in the problem: thermal energy, bulk kinetic energy, magnetic energy, and gravitational potential energy. From these energies we can define three dimensionless ratios, and the behavior of the system will be determined by these three ratios. As an example, we might define the Mach number, plasma beta, and Jeans number via
\begin{equation}
\mathcal{M} = \frac{\sigma}{c_s} \qquad \beta = \frac{8\pi \rho c_s^2}{B^2}
\qquad n_J = \frac{\rho L^3}{c_s^3/\sqrt{G^3\rho}}.
\end{equation}
The ratios describe the ratio of kinetic to thermal energy, the ratio of thermal to magnetic energy, and the ratio of thermal to gravitational energy. All other dimensionless numbers we normally use can be derived from these, e.g., the Alfv\'enic Mach number $\mathcal{M}_A = \mathcal{M}\sqrt{\beta/2}$ is simply the ratio of kinetic to magnetic energy.

Now notice the scalings of these numbers with density $\rho$, velocity dispersion $\sigma$, magnetic field strength $B$, and length scale $L$:
\begin{equation}
\mathcal{M} \propto \sigma
\qquad
\beta \propto \rho B^{-2}
\qquad
n_J \propto \rho^{3/2} L^3.
\end{equation}
If we scale the problem by $\rho\rightarrow x \rho$, $L\rightarrow x^{-1/2} L$, $B\rightarrow x^{1/2} B$, all of these dimensionless numbers remain fixed. Thus the behavior of two systems, one with density a factor of $x$ times larger than the other one, length a factor of $x^{-1/2}$ smaller, and magnetic field a factor of $x^{1/2}$ stronger, are simply rescaled versions of one another. If the first system fragments to make a star out of a certain part of its gas, the second system will too. Notice, however, that the {\it masses} of those stars will not be the same! The first star will have a mass that scales as $\rho L^3$, while the second will have a mass that scales as $(x\rho) (x^{-1/2} L)^3 = x^{-1/2} \rho L^3$. We learn from this an important lesson: isothermal gas is scale-free. If we have a model involving only isothermal gas with turbulence, gravity, and magnetic fields, and this model produces stars of a given mass $m_*$, then we can rescale the system to obtain an arbitrarily different mass.

Now that we understand the basic idea, we can show this a bit more formally. Consider the equations describing this system. For simplicity we will omit both viscosity and resistivity. These are
\begin{eqnarray}
\frac{\partial \rho}{\partial t} & = & -\nabla \cdot (\rho \vecv) \\
\frac{\partial}{\partial t}(\rho \vecv) & = & -\nabla \cdot (\rho\vecv\vecv) - c_s^2 \nabla \rho
\nonumber \\
& & {} + \frac{1}{4\pi} (\nabla \times \vecB) \times \vecB - \rho \nabla \phi \\
\frac{\partial\vecB}{\partial t} & = & -\nabla \times (\vecB\times\vecv) \\
\nabla^2 \phi & = & 4\pi G \rho
\end{eqnarray}
One can non-dimensionalize these equations by choosing a characteristic length scale $L$, velocity scale $V$, density scale $\rho_0$, and magnetic field scale $B_0$, and making a change of variables $\mathbf{x} = \mathbf{x}'L$, $t = t' L/V$, $\rho = r \rho_0$, $\mathbf{B} = \mathbf{b} B_0$, $\mathbf{v} = \mathbf{u} V$, and $\phi = \psi G\rho_0 L^2$. With fairly minimal algebra, the equations then reduce to
\begin{eqnarray}
\frac{\partial r}{\partial t'} & = & -\nabla'\cdot (r\mathbf{u}) \\
\frac{\partial}{\partial t'}(r \mathbf{u}) & = & -\nabla' \cdot \left(r\mathbf{uu}\right) - \frac{1}{\mathcal{M}^2}\nabla' r \nonumber \\
& & {} + \frac{1}{\mathcal{M}_A^2} (\nabla'\times\mathbf{b})\times\mathbf{b} - \frac{1}{\alpha_{\rm vir}} r \nabla' \psi \\
\frac{\partial\mathbf{b}}{\partial t'} & = & -\nabla'\times\left(\mathbf{b}\times\mathbf{u}\right) \\
\nabla'^2 \psi & = & 4\pi r,
\end{eqnarray}
where $\nabla'$ indicates differentiation with respect to $x'$. The dimensionless ratios appearing in these equations are
\begin{eqnarray}
\mathcal{M} & = & \frac{V}{c_s} \\
\mathcal{M}_A & = & \frac{V}{V_A} = V\frac{\sqrt{4\pi \rho_0}}{B_0} \\
\alpha_{\rm vir} & = & \frac{V^2}{G \rho_0 L^2},
\end{eqnarray}
which are simply the Mach number, Alfv\'{e}n Mach number, and virial ratio for the system. These equations are fully identical to the original ones, so any solution to them is also a valid solution to the original equations. In particular, suppose we have a system of size scale $L$, density scale $\rho_0$, magnetic field scale $B_0$, velocity scale $V$, and sound speed $c_s$, and that the evolution of this system leads to a star-like object with a mass
\begin{equation}
m \propto \rho_0 L^3.
\end{equation}
One can immediately see that system with length scale $L' = y L$, density scale $\rho_0' = \rho_0 / y^2$, magnetic field scale $B_0' = B_0/y$, and velocity scale $V' = V$ has exactly the same values of $\mathcal{M}$, $\mathcal{M}_A$, and $\alpha_{\rm vir}$ as the original system, and therefore has exactly the same evolution. However, in this case the star-like object will instead have a mass
\begin{equation}
m' \propto \rho' L'^3 = y m
\end{equation}
Thus we can make objects of arbitrary mass just by rescaling the system.

This analysis implies that explaining the IMF peak requires appealing to some physics beyond that of isothermal, magnetized turbulence plus self-gravity. This immediately shows that the competitive accretion and turbulence theories we outlined to explain the powerlaw tail of the IMF cannot be adequate to explaining the IMF peak, at least not by themselves. Something must be added, and models for the origin of the IMF peak can be broadly classified based on what extra physics they choose to add.

\subsection{The IMF From Galactic Properties}

One option is hypothesize that the IMF is set at the outer scale of the turbulence, where the molecular clouds join to the atomic ISM (in a galaxy like the Milky Way), or on sizes of the galactic scale-height (for a molecule-dominated galaxy). Something in this outer scale picks out the characteristic mass of stars at the IMF peak.

This hypothesis comes in two flavors. The simplest is that characteristic mass is simply set by the Jeans mass at the mean density $\overline{\rho}$ of the cloud, so that
\begin{equation}
m_{\rm peak} \propto \frac{c_s^3}{\sqrt{G^3 \overline{\rho}}}
\end{equation}
While simple, this hypothesis immediately encounters problems. Molecular clouds have about the same temperature everywhere, but they do not all have the same density -- indeed, based on our result that the surface density is about constant, the density should vary with cloud mass as $M^{-1/2}$. Thus at face value this hypothesis would seem to predict a factor of $\sim 3$ difference in characteristic peak mass between $10^4$ and $10^6$ $M_\odot$ clouds in the Milky Way. This is pretty hard to reconcile with observations. The problem is even worse if we think about other galaxies, where the range of density variation is much greater and thus the predicted IMF variation is too. One can hope for a convenient cancellation, whereby an increase in the density is balanced by an increase in temperature, but this seems to require a coincidence.

A somewhat more refined hypothesis, which is adopted by all the turbulence models, is that the IMF peak is set by the sound speed and the normalization of the linewidth-size relation. As discussed above, in the turbulence models the only dimensional free parameters are $c_s$ and $\ell_s$, and from them one can derive a mass in only one way:
\begin{equation}
m_{\rm peak} \sim \frac{c_s^2 \ell_s}{G}.
\end{equation}
\citet{hopkins12d} calls this quantity the sonic mass, but it's the same thing as the characteristic masses in the other models.

This value can be expressed in a few ways. Suppose that we have a cloud of characteristic mass $M$ and radius $R$. We can write the velocity dispersion in terms of the virial parameter:
\begin{equation}
\alpha_{\rm vir} \sim \frac{\sigma^2 R}{G M}
\qquad\Longrightarrow\qquad
\sigma \sim \sqrt{\alpha_{\rm vir} \frac{G M}{R}}.
\end{equation}
This is the velocity dispersion on the outer scale of the cloud, so we can also define the Mach number on this scale as
\begin{equation}
\mathcal{M} = \frac{\sigma}{c_s} \sim \sqrt{\alpha_{\rm vir} \frac{G M}{R c_s^2}}
\end{equation}
The sonic length is just the length scale at which $\mathcal{M} \sim 1$, so if the velocity dispersion scales with $\ell^{1/2}$, then we have
\begin{equation}
\ell_s \sim \frac{R}{\mathcal{M}^2} \sim \frac{c_s^2}{\alpha_{\rm vir} G \Sigma},
\end{equation}
where $\Sigma\sim M/R^2$ is the surface density. Substituting this in, we have
\begin{equation}
m_{\rm peak} \sim \frac{c_s^4}{\alpha_{\rm vir} G^2 \Sigma},
\end{equation}
and thus the peak mass simply depends on the surface density of the cloud. We can obtain another equivalent expression by noticing that
\begin{equation}
\frac{M_J}{\mathcal{M}} \sim \frac{c_s^3}{\sqrt{G^3 \overline{\rho}}} \sqrt{\frac{R c_s^2}{\alpha_{\rm vir} G M}}
\sim \frac{c_s^4}{\alpha_{\rm vir} G^2 \Sigma} \sim m_{\rm peak}
\end{equation}
Thus, up to a factor of order unity, this hypothesis is also equivalent to assuming that the characteristic mass is simply the Jeans mass divided by the Mach number.

An appealing aspect of this argument is that it naturally explains why molecular clouds in the Milky Way all make stars at about the same mass. A less appealing result is that it would seem to predict that the masses could be quite different in regions of different surface density, and we observe that there are star-forming regions where $\Sigma$ is indeed much higher than the mean of the Milky Way GMCs. This is doubly-true if we extend our range to extragalactic environments. One can hope that this will cancel because the temperature will be higher and thus $c_s$ will increase, but this again seems to depend on a lucky cancellation, and there is no \textit{a priori} reason why it should.

\subsection{Non-Isothermal Fragmentation}

The alternative to breaking the isothermality at the outer scale of the turbulence is to relax the assumption that the gas is isothermal on small scales. This has the advantage that it avoids any ambiguity about what constitutes the surface density or linewidth-size relation normalization for a "cloud".

\paragraph{Fixed equation of state models.}

\begin{marginfigure}
\includegraphics[width=\linewidth]{rhot_masunaga00}
\caption[Temperature versus density in a collapsing core]{
\label{fig:rhot_masunaga00}
Temperature versus density found in a one-dimensional calculation of the collapse of a $1$ $M_\odot$ gas cloud, at the moment immediately before a central protostar forms. Credit: \citet{masunaga00a}, \copyright AAS. Reproduced with permission.
}
\end{marginfigure}
The earliest versions of these models were proposed by \citet{larson05a}, and followed up by \citet{jappsen05a}. The basic idea of these models is that the gas in star-forming clouds is only approximately isothermal. Instead, there are small deviations from isothermality, which can pick out preferred mass scales. We will discuss these in more detail in Chapters \ref{ch:first_stars} and \ref{ch:protostar_form}, but for now we assert that there are two places where significant deviations from isothermality are expected (Figure \ref{fig:rhot_masunaga00}).

At low density the main heating source is cosmic rays and UV photons, both of which produce a constant heating rate per nucleus if attenuation is not significant. This is because the flux of CRs and UV photons is about constant, and the rate of energy deposition is just proportional to the number of target atoms or dust grains for them to interact with. Cooling is primarily by lines, either of CO once the gas is mostly molecular, or of C$^+$ or O where it is significantly atomic.

In both cases, at low density the gas is slightly below the critical density of the line, so the cooling rate per nucleus or per molecule is an increasing function of density. Since heating per nucleus is constant but cooling per nucleus increases, the equilibrium temperature decreases with density. As one goes to higher density and passes the CO critical density this effect ceases. At that point one generally starts to reach densities such that shielding against UV photons is significant, so the heating rate goes down and thus the temperature continues to drop with density.

This begins to change at a density of around $10^{-18}$ g cm$^{-3}$, $n\sim 10^5 - 10^6$ cm$^{-3}$. By this point the gas and dust have been thermally well-coupled by collisions, and the molecular lines are extremely optically thick, so dust is the main thermostat. As long as the gas is optically thin to thermal dust emission, which it is at these densities, the dust cooling rate per molecule is fixed, since the cooling rate just depends on the number of dust grains. Heating at these densities comes primarily from compression as the gas collapses, i.e., it is just $P\, dV$ work. If the compression were at a constant rate, the heating rate per molecule would be constant. However, the free-fall time decreases with density, so the collapse rate and thus the heating rate per molecule increase with density. The combination of fixed cooling rate and increasing heating rate causes the temperature to begin rising with density. At still higher densities, $\sim 10^{-13}$ g cm$^{-3}$, the gas becomes optically thick to dust thermal emission. At this point the gas simply acts adiabatically, with all the $P\,dV$ work being retained, so the heating rate with density rises again.

\citet{larson05a} pointed out that deviations from isothermality are particularly significant for filamentary structures, which dominate in turbulent flows.  It is possible to show that a filament cannot go into runaway collapse if $T$ varies with $\rho$ to a positive number, while it can collapse if $T$ varies as $\rho$ to a negative number. This suggests that filaments will collapse indefinitely in the low-density regime, but that their collapse will then halt around $10^{-18}$ g cm$^{-3}$, forcing them to break up into spheres in order to collapse further. The upshot of all these arguments is that the Jeans or Bonnor-Ebert mass one should be using to estimate the peak of the stellar mass spectrum is the one corresponding to the point where there is a changeover from sub-isothermal to super-isothermal.

In other words, the $\rho$ and $T$ that should be used to evaluate $M_J$ or $M_{\rm BE}$ are the values at that transition point. Larson proposes an approximate equation of state to represent the first break in the EOS:
Combining all these effects, \citet{larson05a} proposed a single simple equation of state
\begin{equation}
T = \left\{
\begin{array}{ll}
4.4 \,\rho_{18}^{-0.27}\mbox{ K}, \qquad & \rho_{18} < 1 \\
4.4 \,\rho_{18}^{0.07}\mbox{ K}, & \rho_{18} \ge 1
\end{array}
\right.
\end{equation}
where $\rho_{18}=\rho/(10^{-18}\mbox{ g cm}^{-3})$. Conveniently enough, the Bonnor-Ebert mass at the minimum temperature here is $M_{\rm BE} = 0.067$ $\msun$, which is not too far off from the observed peak of the IMF at $M=0.2$ $\msun$. (The mass at the second break is a bit less promising. At $\rho = 10^{-13}$ g cm$^{-3}$ and $T=10$ K, we have $M_{\rm BE} = 7\times 10^{-4}$ $\msun$.)

Simulations done adopting this proposed equation of state seem to verify the conjecture that the characteristic fragment mass does depend critically on the break on the EOS (Figure \ref{fig:imf_jappsen05}).

\begin{figure}
\includegraphics[width=\linewidth]{imf_jappsen05}
\caption[IMF from simulations of non-isothermal fragmentation]{
\label{fig:imf_jappsen05}
Measured stellar mass distributions in a series of simulations of turbulent fragmentation using non-isothermal equations of state. Each row shows a single simulation, measured at a series of times, characterized by a particular mass in stars as indicated in each panel. Different rows use different equations of state, with the vertical line in each panel indicating the Jeans mass evaluated at the temperature minimum of the equation of state. Histograms show the mass distributions measured for the stars. Credit: \citeauthor{jappsen05a}, A\&A, 435, 611, 2005, reproduced with permission \copyright\, ESO.
}
\end{figure}

\paragraph{Radiative models.}

While this is a very interesting result, there are two problems. First, the proposed break in the EOS occurs at $n=4\times 10^5$ cm$^{-3}$. This is a fairly high density in a low mass star-forming region, but it is actually quite a low density in more typical, massive star-forming regions. For example, the Orion Nebula cluster now consists of $\approx 2000$ $\msun$ of stars in a radius of $0.8$ pc, giving a mean density $n\approx 2\times 10^4$ cm$^{-3}$. Since the star formation efficiency was less than unity and the cluster is probably expanding due to mass loss, the mean density was almost certainly higher while the stars were still forming. Moreover, recall that, in a turbulent medium, the bulk of the mass is at densities above the volumetric mean density. The upshot of all this is that almost all the gas in Orion was probably over \citet{larson05a}'s break density while the stars were forming. Since Orion managed to form a normal IMF, it is not clear how the break temperature could be relevant.

A second problem is that, in dense regions like the ONC, the simple model proposed by \citet{larson05a} is a very bad representation of the true temperature structure, because it ignores the effects of radiative feedback from stars. In dense regions the stars that form will heat the gas around them, raising the temperature. Figure \ref{fig:rhot_krumholz11} shows the density-temperature distribution of gas in simulations that include radiative transfer, and that have conditions chosen to be similar to those of the ONC.

\begin{figure}
\includegraphics[width=\linewidth]{rhot_krumholz11}
\caption[Density-temperature distribution from a simulation of the formation of the ONC]{
\label{fig:rhot_krumholz11}
Density-temperature distributions measured from a simulation of the formation of an ONC-like star cluster, including radiative transfer and stellar feedback. The panels show the distribution at different times in the simulation, characterized by the fraction of mass that has been turned into stars. Doted lines show lines of constant Bonnor-Ebert mass (in $M_\odot$), while dashed lines show the threshold for sink particle formation in the simulation. Credit: \citet{krumholz11c}, \copyright AAS. Reproduced with permission.
}
\end{figure}

These two observations suggest that one can build a model for the IMF around radiative feedback. There are a few numerical and analytic papers that attempt to do so, including \citet{bate09a, bate12a}, \citet{krumholz11e}, \citet{krumholz12b}, and \citet{guszejnov16a}. The central idea for these models is that radiative feedback shuts off fragmentation at a characteristic mass scale that sets the peak of the IMF.

Suppose that we form a first, small protostellar that radiates at a rate $L$. The temperature of the material at a distance $R$ from it, assuming the gas is optically thick, will be roughly
\begin{equation}
L \approx 4 \pi \sigma_{\rm SB} R^2 T^4,
\end{equation}
where $\sigma_{\rm SB}$ is the Stefan-Boltzmann constant. Now let us compute the Bonnor-Ebert mass using the temperature $T$:
\begin{equation}
M_{\rm BE} \approx \frac{c_s^3}{\sqrt{G^3\rho}} = \sqrt{\left(\frac{k_B T}{\mu m_{\rm H} G}\right)^3 \frac{1}{\rho}},
\end{equation}
where $\mu=2.33$ is the mean particle mass, and we are omitting the factor of $1.18$ for simplicity. Note that $M_{\rm BE}$ here is a function of $R$. At small $R$, the temperature is large and thus $M_{\rm BE}$ is large, while at larger distances the gas is cooler and $M_{\rm BE}$ falls.

Now let us compare this mass to the mass enclosed within the radius $R$, which is $M=(4/3)\pi R^3 \rho$. At small radii, $M_{\rm BE}$ greatly exceeds the enclosed mass, while at large radii $M_{\rm BE}$ is much less than the enclosed mass. A reasonable hypothesis is that fragmentation will be suppressed out to the point where $M \approx M_{\rm BE}$. If we solve for the radius $R$ and mass $M$ at which this condition is met, we obtain
\begin{equation}
M  \approx \left(\frac{1}{36\pi}\right)^{1/10} \left(\frac{k_B}{G \mu m_{\rm H}}\right)^{6/5} \left(\frac{L}{\sigma_{\rm SB}}\right)^{3/10} \rho^{-1/5}.
\end{equation}

To go further, we need to know the luminosity $L$. The good news is that, for reasons to be discussed in Chapter \ref{ch:protostar_evol}, the luminosity is dominated by accretion, and the energy produced by accretion is simply the accretion rate multiplied by a roughly fixed energy yield per unit mass. In other words, we can write
\begin{equation}
L \approx \psi \dot{M},
\end{equation}
where $\psi \approx 10^{14}$ erg g$^{-1}$, and can in fact be written in terms of fundamental constants. Taking this on faith for now, if we further assume that stars form over a time of order a free-fall time, then
\begin{equation}
\dot{M} \approx M \sqrt{G\rho},
\end{equation}
and substituting this into the equation for $M$ above and solving gives
\begin{eqnarray}
M & \approx & \left(\frac{1}{36\pi}\right)^{1/7} \left(\frac{k_B}{G \mu m_{\rm H}}\right)^{12/7} \left(\frac{\psi}{\sigma_{\rm SB}}\right)^{3/7} \rho^{-1/14} \\
& = & 0.3 \left(\frac{n}{100\mbox{ cm}^{-3}}\right)^{-1/14} M_\odot,
\end{eqnarray}
where $n = \rho/(\mu m_{\rm H})$. Thus we get a characteristic mass that is a good match to the IMF peak, and that depends only very, very weaky on the ambient density.

Simulations including radiation seem to support the idea that this effect can pick out a characteristic peak ISM mass. The main downside to this hypothesis is that it has little to say by itself about the powerlaw tail of the IMF. This is not so much a problem with the model as an omission, and a promising area of research seems to be joining a non-isothermal model such as this onto a turbulent fragmentation or competitive accretion model to explain the full IMF.


%

\documentclass[twoside]{article}
\setlength{\oddsidemargin}{0.25 in}
\setlength{\evensidemargin}{-0.25 in}
\setlength{\topmargin}{-0.6 in}
\setlength{\textwidth}{6.5 in}
\setlength{\textheight}{8.5 in}
\setlength{\headsep}{0.75 in}
\setlength{\parindent}{0 in}
\setlength{\parskip}{0.1 in}

%
% ADD PACKAGES here:
%

\usepackage{amsmath,amsfonts,graphicx}

%
\newcounter{lecnum}
\renewcommand{\thepage}{\thelecnum-\arabic{page}}
\renewcommand{\thesection}{\thelecnum.\arabic{section}}
\renewcommand{\theequation}{\thelecnum.\arabic{equation}}
\renewcommand{\thefigure}{\thelecnum.\arabic{figure}}
\renewcommand{\thetable}{\thelecnum.\arabic{table}}

%
% The following macro is used to generate the header.
%
\newcommand{\lecture}[4]{
   \pagestyle{myheadings}
   \thispagestyle{plain}
   \newpage
   \setcounter{lecnum}{#1}
   \setcounter{page}{1}
   \noindent
   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 6.28in { {\bf EE302 - Feedback Systems
	\hfill Spring 2019} }
       \vspace{4mm}
       \hbox to 6.28in { {\Large \hfill Lecture #1 \hfill} }
       \vspace{2mm}
       \hbox to 6.28in { {\it Lecturer: #2 \hfill } }
      \vspace{2mm}}
   }
   \end{center}
   \markboth{Lecture #1}{Lecture #1}

   \vspace*{4mm}
}
%
\renewcommand{\cite}[1]{[#1]}
\def\beginrefs{\begin{list}%
        {[\arabic{equation}]}{\usecounter{equation}
         \setlength{\leftmargin}{2.0truecm}\setlength{\labelsep}{0.4truecm}%
         \setlength{\labelwidth}{1.6truecm}}}
\def\endrefs{\end{list}}
\def\bibentry#1{\item[\hbox{[#1]}]}

%Use this command for a figure; it puts a figure in wherever you want it.
%usage: \fig{NUMBER}{SPACE-IN-INCHES}{CAPTION}
\newcommand{\fig}[3]{
			\vspace{#2}
			\begin{center}
			Figure \thelecnum.#1:~#3
			\end{center}
	}
% Use these for theorems, lemmas, proofs, etc.
\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newenvironment{proof}{{\bf Proof:}}{\hfill\rule{2mm}{2mm}}

% **** IF YOU WANT TO DEFINE ADDITIONAL MACROS FOR YOURSELF, PUT THEM HERE:

\begin{document}

% Lecture Details
\lecture{18}{Asst. Prof. M. Mert Ankarali}

\par

\section{The Bode Plot}

Previously, we showed how to illustrate the frequency response
function of an LTI system, $G(j \omega)$, using the polar plot
and the Nyquist plot. In the Bode Plot gain, $| G(j \omega) |$ and phase
response, $\angle [ G(j \omega) ]$, of the system are illustrated
separately as a function of frequency, $\omega$. In both diagrams
logarithmic scale is used for frequency axis. On the other hand,
in magnitude axis we use a special logarithmic scale in dB units,
where as for phase axis we use linear scale. Specifically Magnitude
in dB scale, $M_{dB}$ and phase response, $\phi$ of a transfer
function, $G( j \omega)$ are computed as

\begin{align*}
 M_{dB}(\omega) &= 20 \mathrm{log}_{10} | G( j \omega ) |
  \\
  \phi(\omega) &= \angle [ G( j \omega )  ]
\end{align*}

Now let's write $G(s)$ in pole-zero-gain form and analyze the
magnitude (dB) and phase functions

\begin{align*}
  G(s) =& K \frac{ (s - z_1) \cdots (s - z_N) }{ (s - p_1) \cdots (s -
  p_N) }
\\
,
 \\
  M_{dB}\lbrace G(s) \rbrace =& 20 \mathrm{log}_{10} | G( j \omega ) |
  \\
  =& 20 \mathrm{log}_{10} K + \left[ 20 \mathrm{log}_{10} | (j \omega
    - z_1) |  + \cdots + 20 \mathrm{log}_{10} (j \omega - z_N) \right]
    \\
    & - \left[ 20 \mathrm{log}_{10} | (j \omega
    - p_1) |  + \cdots + 20 \mathrm{log}_{10} (j \omega - p_M) \right]
      \\
  =& K_{dB} + \left[ M_{dB} \lbrace s - z_1 \rbrace \cdots M_{dB}
     \lbrace s - z_N \rbrace \right]
     - \left[ M_{dB} \lbrace s - p_1 \rbrace \cdots M_{dB}
     \lbrace s - p_M \rbrace \right]
\\
,
\\
  \phi \lbrace G(s) \rbrace &= \angle [ G( j \omega )  ]
\\
     &=  \left( \angle [ j \omega - z_1) ]  + \cdots + \angle [ j
       \omega - z_N ] \right) - \left( \angle [ j \omega - p_1 ]  +
       \cdots + \angle [ j \omega - p_M] \right)
\\&=  \left( \phi \lbrace s - z_1 \rbrace + \cdots + \phi \lbrace s -
    z_N \rbrace \right) - \left( \phi \lbrace s - p_1 \rbrace  +
       \cdots + \phi \lbrace s- p_M \rbrace \right)
\end{align*}

In conclusion, in order to obtain a bode diagram, we can
first find phase and magnitude (dB) arguments associated
with each pole/zero/gain separately for a given frequency.
After that, final magnitude (dB) and phase arguments of $G(s)$
are found by simply adding (and subtracting) the individual components.

\newpage

\textbf{Bode Plots of $s$ and $\frac{1}{s}$:} Let's write the
magnitude and phase functions

\begin{align*}
s \ \Rightarrow \  M_{dB}(\omega) &= 20 \mathrm{log}_{10} ( \omega ) \quad \& \quad \phi (\omega) = 90^0
                                                        \\
\frac{1}{s} \ \Rightarrow \ M_{dB} ( \omega ) &= - 20 \mathrm{log}_{10} ( \omega ) \quad \& \quad \phi (\omega) = -90^0
\end{align*}

If we illustrate the responses in bode plot, we obtain the following Figure

\vspace{6 pt}

  \begin{minipage}[h]{1\linewidth}
    \begin{center}
      \includegraphics[width=0.8\textwidth]{bode_DandI}
    \end{center}
  \end{minipage}

\vspace{6pt}

\subsection*{Bode Plots of First-Order Forms}

First let's analyze the phase and magnitude (dB) response of $G(s) = s + 1$
%
\begin{align*}
  M_{dB} (\omega) &= 20 \, \mathrm{log}_{10} | G( j \omega) | = 20 \, \mathrm{log}_{10} \left( \omega^2 + 1 \right)^{1/2} = 10 \, \mathrm{log}_{10} \left( \omega^2 + 1 \right)
  \\
  \phi(\omega) &= \arctan \omega
\end{align*}
%
Now we will approximate the gain and phase curves using piece-wise continuous straight lines.
Firs approximate the magnitude response
%
\begin{align*}
  \mathrm{Low-Frequency} \ \Rightarrow \ M_{dB}(\omega)  &\approx 0 \
                                                   \mathrm{dB} \\
  \mathrm{High-Frequency} \ \Rightarrow \ M_{dB}(\omega)  &\approx 20 \,
                                                    \mathrm{log}_{10} ( \omega )
\end{align*}
%
Note that high-frequency and low-frequency approximations intersect at
$\omega = 1 \ rad/s$ and $M_{dB} = 0 \ \mathrm{dB}$ point. Now
let's approximate the phase response
%
\begin{align*}
  \mathrm{Low-Frequency} \ \Rightarrow \ \phi  &\approx 0^o  \\
  \mathrm{High-Frequency} \ \Rightarrow \ \phi &\approx 90^o \\
  \mathrm{Medium-Frequency} \ \Rightarrow \ \phi & \approx 45^0 + 45^0 \mathrm{log}_{10} ( \omega)
\end{align*}
%
Note that, low-frequency and mid-frequency approximations intersect when $\omega = 0.1 \ rad/s$,
whereas high-frequency and mid-frequency approximations intersect when $\omega = 10 \ rad/s$.
The corner frequency of this ``system'' is $\omega_c = 1 \ rad/s$. Note that it is very easy to obtain
the bode approximations of $G(s) = \frac{1}{s+1}$, if we know the bode approximations of $G(s) = s+1$. We
simple multiply both magnitude (dB) and phase responses of $s+1$ with $(-1)$. The figure below
illustrates the original bode plots (solid curves) of $G_1(s) = (s+1)$ and $G_2(s) = \frac{1}{s+1}$ as well as
their approximations (dashed lines).

\vspace{6 pt}

  \begin{minipage}[h]{1\linewidth}
    \begin{center}
      \includegraphics[width=0.9\textwidth]{sp1}
    \end{center}
  \end{minipage}

\vspace{6 pt}

Now let's analyze the phase and magnitude (dB) response of
%
\begin{align*}
  G(s) = T s + 1 = \frac{s + a}{a} \ \mathrm{where} \ a = \frac{1}{T}
\end{align*}
%
Magnitude and phase functions can be obtained as
\begin{align*}
  M_{dB}  &= 20 \, \mathrm{log}_{10} | G( j \omega) | = 20 \, \mathrm{log}_{10} \left( T^2 \omega^2 + 1 \right)^{1/2} = 10 \, \mathrm{log}_{10} \left( T^2 \omega^2 + 1 \right)
  \\
  \phi &= \arctan T \omega
\end{align*}
%
If we follow a similar approach, we can approximate the gain curves as
%
\begin{align*}
  \mathrm{Low-Frequency}: \omega \leq \frac{1}{T} = a  \ \Rightarrow \ M_{dB}  &\approx 0 \ \mathrm{dB} \\
  \mathrm{High-Frequency}: \omega \geq \frac{1}{T} = a \ \Rightarrow \ M_{dB}  &\approx 20 \, \mathrm{log}_{10} ( T \omega )
\end{align*}
%
Note that high-frequency and low-frequency approximations intersect at
$\omega = a \ rad/s = \frac{1}{T} \ rad/s$ and $M_{dB} = 0 \ \mathrm{dB}$ point. Now
let's approximate the phase response
%
\begin{align*}
  \mathrm{Low-Frequency}: \omega \leq \frac{0.1}{T} = 0.1 a \ \Rightarrow \ \phi  &\approx 0^o  \\
  \mathrm{High-Frequency}: \omega \geq \frac{10}{T} = 10 a  \ \Rightarrow \ \phi &\approx 90^o \\
  \mathrm{Medium-Frequency} \ \Rightarrow \ \phi & \approx 45^0 + 45^0 \mathrm{log}_{10} ( \omega)
\end{align*}
%
Note that low-frequency and mid-frequency approximations intersect
when $\omega = 0.1 a \ rad/s$,
whereas high-frequency and mid-frequency approximations intersect when
$\omega = 10 a \ rad/s$.
The corner freqency of this system is $\omega_c = a \ rad/s = 1/T \
rad/s$. Note that in order to obtin the bode plot of $T s + 1$, we
simply shift the bode plot of $s + 1$ (in $\omega$ axis).

\vspace{6pt}

\textbf{Ex:} The figure below
illustrates the original bode plots (solid curves) of $G_1(s) = (s+10)$ and $G_2(s) = \frac{1}{s+10}$ as well as
their approximations (dashed lines).

\vspace{6 pt}

  \begin{minipage}[h]{1\linewidth}
    \begin{center}
      \includegraphics[width=0.9\textwidth]{spa}
    \end{center}
  \end{minipage}

\vspace{6 pt}

\subsection*{Bode Plots of Second-Order Forms}

A unity gain standard second order system can be written in the form
%
\begin{align*}
	G(s) = \frac{\omega_n^2}{s^2 + 2 \zeta \omega_n s + \omega_n^2}
		= \frac{1}{\frac{1}{\omega_n^2} s^2 + \frac{2 \zeta}{\omega_n} s + 1}
\end{align*}
%
\textbf{Case 1 : $\zeta = 1$} First let's analyze the bode plots for the critically damped case,
%
\begin{align*}
	G(s) =  \frac{1}{\frac{1}{\omega_n^2} s^2 + \frac{2 \zeta}{\omega_n} s + 1}
		= \frac{1}{(\frac{s}{\omega_n} + 1)^2}
\end{align*}
%
We can easily observe that
%
Magnitude and phase functions can be obtained as
\begin{align*}
  M_{dB} \lbrace G(s) \rbrace &= 20 \, \mathrm{log}_{10} | G( j \omega) | =   20 \, \mathrm{log}_{10} \left| \frac{1}{\frac{s}{\omega_n} + 1} \right|^2
  \\
  	&= 2 M_{dB} \left\lbrace \frac{1}{\frac{s}{\omega_n} + 1}  \right\rbrace
	\\
  \phi \lbrace G(s) \rbrace &= 2 \phi \left\lbrace \frac{1}{\frac{s}{\omega_n} + 1}  \right\rbrace
\end{align*}

\textbf{Ex:} The figure below
illustrates the original bode plots (solid curves) of $G_1(s) = \frac{10}{s+10}$ and $G_2(s) = \frac{100}{(s+10)^2}$ as well as
their approximations (dashed lines).

\vspace{6 pt}

  \begin{minipage}[h]{1\linewidth}
    \begin{center}
      \includegraphics[width=0.9\textwidth]{second}
    \end{center}
  \end{minipage}

\vspace{6 pt}

\textbf{Case 2: $\zeta > 1$} Over-damped case is simply the combination of two identical first order
systems.

\textbf{Ex:}  Let's analyze the the bode plots for the following system
%
\begin{align*}
	G(s) =  \frac{10}{(s+1)(s+10)}
		= \frac{1}{ s + 1 } \frac{10}{ s + 10 }
\end{align*}
%
We can easily observe that
\begin{align*}
  M_{dB} \lbrace G(s) \rbrace &= M_{dB} \left\lbrace \frac{1}{s+1}  \right\rbrace +
   M_{dB} \left\lbrace \frac{10}{s+10}  \right\rbrace
	\\
  \phi \lbrace G(s) \rbrace &= \phi \left\lbrace \frac{1}{s + 1}  \right\rbrace +
   \phi \left\lbrace \frac{10}{s + 10}  \right\rbrace
\end{align*}
%
The figure below
illustrates the original bode plots (solid curves) of $G_1(s) = \frac{1}{s+1}$, $G_2(s) = \frac{10}{s+10}$ and $G_4(s) = \frac{10}{(s+1) (s+10)}$ as well as their approximations (dashed lines).

\vspace{6 pt}

  \begin{minipage}[h]{1\linewidth}
    \begin{center}
      \includegraphics[width=0.9\textwidth]{over}
    \end{center}
  \end{minipage}

\newpage

\textbf{Case 3 : $\zeta < 1$} For under-damped systems, corner frequencies
of the piece-wise linear approximations are unchanged. Thus, we use same
approximation with the critically damped case. However, as damping ratio
increases we may observe larger differences between the actual bode plot
and the approximations.

\textbf{Ex:} The figure below
illustrates the original bode plots (solid curves) of $G_1(s) = \frac{10}{s+10}$ and $G_2(s) = \frac{100}{(s+10)^2}$ as well as
their approximations (dashed lines).

\vspace{6 pt}

  \begin{minipage}[h]{1\linewidth}
    \begin{center}
      \includegraphics[width=0.9\textwidth]{under}
    \end{center}
  \end{minipage}

\vspace{6 pt}

We can see that best phase matching between the actual bode plot and approximation is achieved when
$\zeta = 1$, however surprisingly best magnitude matching between the actual bode plot and approximation is achieved when
$\zeta = 2$. Indeed, best match between the actual and approximate bode plots in magnitude is achieved when $\zeta = 1/\sqrt{2}$.

\newpage

\section{Gain \& Phase Margin from Bode Plots}

We already know that for a feedback system, phase and
gain margins can be computed based on the Frequency Response
function of the open-loop transfer function, $G_{OL}(j \omega)$ (under
some assumption regarding the system properties).
Specifically, the phase crossover frequency, $\omega_{pc}$ and the gain margin,
$g_m$ (linear scale) and $G_m$ (dB scale), can be computed as
%
\begin{align*}
  \angle [ G_{OL}(j \omega_{p}) ] &= \pm -180^0
  \quad \Rightarrow \quad
  g_m = \frac{1}{| G_{OL}(j \omega_{pc})| } \quad \mathrm{or} \quad G_m
  = -20 \, \mathrm{log}_{10} | G_{OL}(j \omega_{pc} ) |
\end{align*}
%
where as gain crossover frequency, $\omega_{gc}$, and the
phase margin can be computed as
%
\begin{align*}
  | G_{OL}(j \omega_{gc}) | &= 1 \quad \mathrm{or} \quad
  M_{dB} \lbrace G_{OL}(j \omega_{gc}) \rbrace = 0 \ \mathrm{dB}
   \quad \Rightarrow \quad
  \phi_m = \pi + \angle G_{OL} (j \omega_{gc})
\end{align*}
%
Indeed it is generally easier to derive the phase and gain margin of
a system from the bode plots compared to the Nyquist plot.

\textbf{Ex:} Compute the phase margin
for the following closed-loop system for $K = 2$ and $K = 4$,
both from the approximate and actual bode plots.

\begin{center}
\begin{minipage}[h]{\linewidth}
    \begin{center}
      \includegraphics[width=0.45\textwidth]{ex2block}
    \end{center}
\end{minipage}
\end{center}

Actual bode plots for both gains are illustrated
below.

\begin{center}
\begin{minipage}[h]{\linewidth}
    \begin{center}
      \includegraphics[width=0.7\textwidth]{marginactual}
    \end{center}
\end{minipage}
\end{center}

If we label the gain crossover frequencies and find the
corresponding phase values, we can easily compute the phase
margins as
%
\begin{align*}
  K &= 2 \Rightarrow \phi_m = 90^o \quad (\omega_{gc} = 1 \ rad/s)
  \\
  K &= 4 \Rightarrow \phi_m = 60^o \quad (\omega_{gc} \approx 1.8 \ rad/s)
\end{align*}
%
These results verify the actual phase margin values that we previously computed
using the Nyquist plot. Note that $G_m$ is infinity for both cases.

Now let's illustrate the approximate bode plots (dashed lines),
which are illustrated in the Figure below on top of the actual ones

\begin{center}
\begin{minipage}[h]{\linewidth}
    \begin{center}
      \includegraphics[width=0.7\textwidth]{margin}
    \end{center}
\end{minipage}
\end{center}

If we approximately compute the phase margins based
on the approximate bode plots we obtain that
%
\begin{align*}
  K &= 2 \Rightarrow \phi_m \approx 100^o
  \\
  K &= 4 \Rightarrow \phi_m \approx 63^o
\end{align*}

\newpage

\textbf{Ex:} Compute the gain margin and phase margin
for the following closed-loop system for $K = 1$ and $K = 8$
both from the actual and approximate bode plots.

\begin{center}
\begin{minipage}[h]{\linewidth}
    \begin{center}
      \includegraphics[width=0.5\textwidth]{ex3block}
    \end{center}
\end{minipage}
\end{center}

First let's analyze $K = 1$, the Figure below illustrates the
actual and approximate bode plots of $G(s) = \frac{1}{(s+1)^3}$.

\begin{center}
\begin{minipage}[h]{\linewidth}
    \begin{center}
      \includegraphics[width=0.75\textwidth]{margin2}
    \end{center}
\end{minipage}
\end{center}

We can see that phase margin is $180^o$ for the given system,
since $\omega_{gc} = 0 \ \rightarrow \ \phi (\omega_{gc} ) = 0^o$.
On the other hang we can derive the following gain margin estimates
from the actual and approximate bode plots
%
\begin{align*}
	&\mathrm{Actual:} \quad G_m \approx 18 \ \mathrm{dB} \quad \rightarrow \quad g_m \approx 8
	\\
	&\mathrm{Approximate:} \quad G_m \approx 20 \ \mathrm{dB} \quad \rightarrow \quad g_m \approx 10
\end{align*}
%
Now let's analyze $K = 8$, the Figure below illustrates the
actual Bode plots of $G(s) = \frac{8}{(s+1)^3}$.

\begin{center}
\begin{minipage}[h]{\linewidth}
    \begin{center}
      \includegraphics[width=0.7\textwidth]{margin3actual}
    \end{center}
\end{minipage}
\end{center}

We can see from the actual bode-plot that  $G_m =  0 \ \mathrm{dB}$
and $\phi_m = 0^o$.
However, if we draw the approximate bode plots

\begin{center}
\begin{minipage}[h]{\linewidth}
    \begin{center}
      \includegraphics[width=0.7\textwidth]{margin3}
    \end{center}
\end{minipage}
\end{center}

and estimate these margins we obtain
%
\begin{align*}
	&G_m \approx 2 \ \mathrm{dB} \quad \rightarrow \quad g_m \approx 1.2
	\\
	&\phi_m = 2^o
\end{align*}
%
As we can see, from the approximate, we compute positive
phase and gain margin and thus assume the system is stable.
But, these margins are very low. This indicates that if one
analyzes the stability of a system using approximate
bode plots, in order to comment on stability he/she should
observe significant phase and gain margins.

\textbf{Ex:} Compute  phase margin for the following closed-loop system
using the actual and approximate bode plots

\begin{center}
\begin{minipage}[h]{\linewidth}
    \begin{center}
      \includegraphics[width=0.3\textwidth]{ex4block}
    \end{center}
\end{minipage}
\end{center}

The Figure below illustrates the actual and approximate bode plots.

\begin{minipage}[h]{1\linewidth}
    \begin{center}
      \includegraphics[width=0.75\textwidth]{type1}
    \end{center}
\end{minipage}

We can derive the following phase margin computations from the
actual and approximate bode plots
%
%
\begin{align*}
	&\mathrm{Actual:} \quad \phi_m \approx 52.5^0 \quad (\omega_{gc} \approx 0.8 \ rad/s)
	\\
	&\mathrm{Approximate:} \quad \phi_m \approx 45^o \quad (\omega_{gc} = 1 \ rad/s)
\end{align*}
%

% **** This ENDS THE EXAMPLES. DON'T DELETE THE FOLLOWING LINE:
\end{document}


% !TEX TS-program = pdflatex
% !TeX program = pdflatex
% !TEX encoding = UTF-8
% !TEX spellcheck = en

\documentclass[xcolor=table]{beamer}

\input{options}

\title[ANN: CNN] %
{Advanced neural networks\\Convolutional neural networks}

\changegraphpath{../img/CNN/}

\begin{document}

\begin{frame}
\frametitle{Convolutional neural networks}
\framesubtitle{Motivation}

\end{frame}

\begin{frame}
\frametitle{Convolutional neural networks}
\framesubtitle{Plan}

\begin{multicols}{2}
	%	\small
	\tableofcontents
\end{multicols}
\end{frame}

\begin{frame}
	\frametitle{Convolutional neural networks}
	\framesubtitle{A little fun}

	\hgraphpage[\textwidth]{humour-convnet.jpg}

\end{frame}

\section{Traditional image processing}

\begin{frame}
\frametitle{Convolutional neural networks}
\framesubtitle{Traditional image processing}

\begin{center}
	\hgraphpage[\textwidth]{img-learn.pdf}
\end{center}

\end{frame}

\begin{frame}
\frametitle{Convolutional neural networks}
\framesubtitle{Traditional image processing}

\begin{itemize}
	\item Many preprocessing techniques exist (see \cite{2010-alginahi})
	\item Here, we are interested in convolution (modify the value of a pixel based on its neighbors)
	\item Two parameters: \optword{padding} (Surround the image with 0s in order to preserve the original size), \optword{stride} (the kernel/mask's scrolling step).
\end{itemize}

\begin{center}
	\hgraphpage[.8\textwidth]{conv.pdf}
\end{center}

\end{frame}

\begin{frame}
\frametitle{Convolutional neural networks}
\framesubtitle{Traditional image processing}

Ua example from \href{https://fr.wikipedia.org/wiki/Noyau\_(traitement\_d\%27image)}{Wikipedia}

\begin{tabular}{p{.3\textwidth}p{.1\textwidth}p{.2\textwidth}p{.2\textwidth}}
	\hline\hline
	Operation & original & Kernel & Transformed \\
	\hline
	Contour detection &
	\graphpage[valign=c]{Vd-Orig.png} &
	$\begin{bmatrix}
	-1 & -1 & -1\\
	-1 & 8 & -1\\
	-1 & -1 & -1
	\end{bmatrix}$ &
	\graphpage[valign=c]{Vd-Edge3.png} \\

	\hline
	Sharpness improvement &
	\graphpage[valign=c]{Vd-Orig.png} &
	$\begin{bmatrix}
	0 & -1 & 0\\
	-1 & 5 & -1\\
	0 & -1 & 0
	\end{bmatrix}$ &
	\graphpage[valign=c]{Vd-Sharp.png} \\

	\hline
	Box blur &
	\graphpage[valign=c]{Vd-Orig.png} &
	$\frac{1}{9}\begin{bmatrix}
	1 & 1 & 1\\
	1 & 1 & 1\\
	1 & 1 & 1
	\end{bmatrix}$ &
	\graphpage[valign=c]{Vd-Blur2.png} \\
	\hline\hline

\end{tabular}

\end{frame}

\begin{frame}
\frametitle{Convolutional neural networks: Traditional image processing}
\framesubtitle{Limitations}

According to LeCun and his colleagues \cite{1998-lecun}:
\begin{itemize}
	\item When image size is large, many parameters must be trained.
	\item To do so, a large training dataset must used.
	\item A large memory must be used to store all the parameters.
	\item To train a model on images, preprocessing tasks such as translations and distortions must be applied.
	\item Images variations, such as objects' positions, cannot be captured unless many layers are stacked.
\end{itemize}

\end{frame}

\section{Convolitional layers}

\begin{frame}
	\frametitle{Convolutional neural networks}
	\framesubtitle{Convolitional layers}

\end{frame}

\begin{frame}
	\frametitle{Convolutional neural networks: Convolitional layers}
	\framesubtitle{Conv2D layer}

\begin{minipage}{0.60\textwidth}
	\begin{itemize}
		\item Images spatial structure is preserved.
		\item One or many kernels are learned.
		\item $ w' = \frac{w - w_f + 2P}{S} + 1$,  $ h' = \frac{h - h_f + 2P}{S} + 1$
		\item Number of generated filters/kernels $k$ can be specified.
		\item Parameters size: $w_f * h_f * c * k$ plus $k$ bias.
		\item Example, \expword{Image: 32x32x3; Kernel : 5x5; s : 1; p: 0; k : 6}.
		In this case, \expword{81} parameters must be trained.
	\end{itemize}
\end{minipage}
%
\begin{minipage}{0.39\textwidth}
	\hgraphpage[\textwidth]{conv2d.pdf}

	\hgraphpage[.8\textwidth]{conv2d-exp_.pdf}
\end{minipage}

\end{frame}

\section{Pooling layers}

\begin{frame}
	\frametitle{Convolutional neural networks}
	\framesubtitle{Pooling layers}

\end{frame}

\begin{frame}
\frametitle{Convolutional neural networks}
\framesubtitle{Pooling layers}

\begin{minipage}{0.60\textwidth}
	\begin{itemize}
		\item Makes the representation smaller and more manageable.
		\item $ w' = \frac{w - w_f + 2P}{S} + 1$,  $ h' = \frac{h - h_f + 2P}{S} + 1$
		\item No parameters to train.
		\item \optword{Max Pool}: the gradient go back to the wining cell (the max).
		\item \optword{Average Pool}: the gradient passed to the participated cells is $\frac{\text{gradient}}{w_f * h_f}$.
	\end{itemize}
\end{minipage}
%
\begin{minipage}{0.39\textwidth}
	\hgraphpage[\textwidth]{maxpool.pdf}

	\hgraphpage[.8\textwidth]{pool-exp_.pdf}
\end{minipage}

\end{frame}

\end{document}


Since the Higgs boson was first observed in 2012 by the CMS and ATLAS collaborations~\cite{Aad:2012tfa, Chatrchyan:2012xdj, Chatrchyan:2013lba}, characterizing its properties has remained one of the highest priorities of the LHC research program.
The Standard Model predicts values for many properties of the Higgs boson, including the strength of its coupling to the other elementary particles.
Physics beyond the Standard Model, such as mechanisms of mass generation other than spontaneous symmetry breaking, could modify these coupling strengths.
Consequently, precise measurements of the Higgs boson's coupling to elementary particles are of great interest: any deviation from the Standard Model prediction could be indicative of the presence of new physics.
%
\subsection{The Top Quark Yukawa Coupling}
The coupling of the Higgs boson to the top quark, called the top quark Yukawa coupling, is of particular interest from a theoretical standpoint.
Specifically, the top quark Yukawa coupling could help give an indication about the scale of new physics~\cite{why_care_top_yukawa}.

A primary means of constraining the top quark Yukawa coupling is through the measurement of the \ttH production cross section, which is proportional its square:
\begin{equation}
\sigma_{\ttH} \propto y_{\text{t}}^2.
\end{equation}
The dominant tree-level diagram for \ttH production is shown in Fig.~\ref{fig:tth_feynman}.
\begin{figure} [htbp!]
    \centering
    \includegraphics[width=0.4\linewidth]{figures/tth/tth_feynman.png}
    \caption{Tree-level production of a Higgs boson in association with a top quark-antiquark pair.}
    \label{fig:tth_feynman}
\end{figure}

This is in fact the best method of \emph{directly} constraining the top quark Yukawa coupling at the LHC.
Indirect constraints on $y_\text{t}$ come from measurements of Higgs boson production via gluon fusion and \Hgg decay, both of which proceed primarily through a top quark loop, as in Fig. ~\ref{fig:hgg_feynman}.
However, these constraints are indirect because they make the assumption that no other BSM particles also contribute to the loops.

Complementary methods of constraining $y_\text{t}$ include extraction from the shapes of kinematic distributions in \ttb events~\cite{CMS:2020qzr}, reporting a measured value of $y_\text{t} = 1.16^{+0.24}_{-0.35}$.
This measurement does, however, rely on the aforementioned assumptions about the \Hgg branching ratio, and is said to be an indirect constraint on the top Yukawa coupling.
%The uncertainty on $y_\text{t}$ is more than a factor of 2 less than that obtained with a measurement of \ttH (\Hgg)\footnote{One caveat is that the \ttH (\Hgg) result does not quote an actual value of $y_\text{t}$, but rather the \ttH cross section, which is proportional to the square of $y_\text{t}$.}, but does not rely on assumptions about the \Hgg branching ratio.

\subsection{Landscape of \ttH Measurements}
The first observation of the \ttH process was reported in 2018 by the CMS experiment~\cite{Sirunyan:2018hoz}, using 36 \fbinv of data from pp collisions at $\sqrt{s} = 13$ TeV.
The first observation of \ttH production in a single H decay channel (\Hgg) was reported by the CMS collaboration~\cite{tth_observation}, with the ATLAS collaboration reporting a similar result shortly after~\cite{Aad:2020ivc}.
The CMS observation of \ttH (\Hgg) is detailed in the following sections of this thesis.

%\subsection{\ttH~Production as a Probe of the Top Quark Yukawa Coupling}


\section{Experimental Setup}

The measurement equipment consists of the following elements: springs, Jolly
balance, air track, electronic timer, electronic balance and masses.

\begin{figure}[H]
\centering
\begin{minipage}{8cm}
A: Sliding bar with metric scale;\\
H: Vernier for reading;\\
C: Small mirror with a horizontal line in the middle;\\
D: Fixed glass tube also with a horizontal line in the middle;\\
G: Knob for ascending and descending the sliding bar;\\
S: Spring attached to top of the bar A.\\
\end{minipage}
\hspace{0.5cm}
\begin{minipage}{6cm}
\label{jb}
\includegraphics[width=6cm]{fig/ejb}
\end{minipage}
\caption{Jolly balance.}
\end{figure}

In order to measure the spring constant using the Jolly balance, we need to
place the small mirror $C$ (see Figure~\ref{jb}) in the tube $D$ and make
three lines coincide: the line on the mirror, the line on the glass tube and its
reflection in the mirror. First, without adding any weight on the bottom end of
the spring, adjust the knob G and make the three lines coincide. Then read the
scale $L_1$.

Second, add mass m to the bottom of the spring. The spring is stretched and the
three lines no longer coincide. Adjust knob G to make them into one line again
and read the corresponding number on scale $L_2$. The spring constant may be
then found as

\begin{equation}
k=\frac{mg}{L_2-L_1}
\end{equation}

so that we can estimate the spring constant by finding a linear fit to the data
using the least squares method.

\begin{figure}[h]
\centering
\label{airtrack}
\includegraphics[width=10cm]{fig/eair}
\caption{The experimental setup}
\end{figure}

A photoelectric measuring system consists of two photoelectric gates and an
electronic timer. When a shutter on the object blocks the light, the computer
will record the time. For period measurements, we use the I-shape shutter.

When measuring the instantaneous speed, the U-shape shutter is required. $\Delta t$
presents the time interval when the object travels a distance of $\Delta
x=(x_{in}+x_{out})/2$. Hence we estimate the speed as $v=\Delta x/\Delta t$.

\begin{figure}[H]
\centering
\includegraphics[width=4cm]{fig/eushape}
\label{ushape}
\caption{The U-shape shutter}
\end{figure}


\section{Basic Tutorials 2}

%%%%%%%%%%%%%
\subsection{Filters}

%% Break
\begin{frame}{Basic Tutorial 2}
\fontsize{36pt}{36pt}\selectfont
\center
\begin{center}
Basic Tutorial 2
\end{center}
\end{frame}

\subsection{Example}
\begin{frame}{Hands On}
\fontsize{36pt}{36pt}\selectfont
\center
\begin{center}
Hands On
\end{center}
\vspace{20pt}
\begin{center}
\fontsize{11pt}{11pt}\selectfont
\texttt{Examples/BasicTutorial2/Filters.py}
\end{center}
\end{frame}

\begin{frame}[fragile]
\frametitle{What just happened?}
\lstpython
\begin{lstlisting}
# Simple smoothing
smooth = sitk.SmoothingRecursiveGaussian ( image, 2.0 )
sitk.Show ( sitk.Subtract ( image, smooth ) )
...
RuntimeError: Exception thrown in SimpleITK Subtract: ...
sitk::ERROR: Both images for SubtractImageFilter don't match type or dimension!
...
\end{lstlisting}

\begin{itemize}
  \item The output of SmoothingRecursiveGaussian is of type float
  \item The input image is signed short
  \item Most SimpleITK filters with 2 inputs require the same type
  \item Let's fix the problem
\end{itemize}

\end{frame}

\begin{frame}[fragile]
\frametitle{Introducing Cast}
\lstpython
\begin{lstlisting}
# Much better
print "Before: ", smooth.GetPixelIDTypeAsString()
smooth = sitk.Cast ( smooth, image.GetPixelIDValue() )
print "After: ", smooth.GetPixelIDTypeAsString()
sitk.Show ( sitk.Subtract ( image, smooth ), "DiffWithGaussian" )
\end{lstlisting}
Back to iPython (\texttt{Examples/BasicTutorial2/Filters.py})
\end{frame}

\begin{frame}[fragile]
\frametitle{Sizes and Indices}
\lstpython
\begin{lstlisting}
# Extract
size = [64, 64, 1]
start = [64, 0, 0]
sitk.Show ( sitk.Extract ( image, size, start ), "Extracted" )
\end{lstlisting}
in C++ / ITK code this would use
\lstcpp
\begin{lstlisting}
typedef unsigned char PixelType;
enum {ImageDimension = 2};
typedef itk::Image<PixelType,ImageDimension> ImageType;

typedef ImageType::IndexType  IndexType;
typedef ImageType::SizeType   SizeType;
typedef ImageType::RegionType RegionType;
\end{lstlisting}
\begin{itemize}
\item SimpleITK uses STL vectors
\item Wrapping converts to language-specific constructs (tuples/arrays)
\end{itemize}
\end{frame}

%% Morphology
\subsection{Morphology}

\begin{frame}{Morphology}
\fontsize{36pt}{36pt}\selectfont
\center
\begin{center}
Morphology
\end{center}
\vspace{20pt}
\begin{center}
\fontsize{11pt}{11pt}\selectfont
\texttt{Examples/BasicTutorial2/Morphology.py}
\end{center}
\end{frame}

\begin{frame}[fragile]
\frametitle{Operators}

\begin{columns}[c]

\column{0.25\textwidth}
\begin{center}
\includegraphics[width=1\textwidth]{Images/Erosion_shadow} \\
Erosion
\end{center}

\column{0.25\textwidth}
\begin{center}
\includegraphics[width=1\textwidth]{Images/Dilation_shadow} \\
Dilation
\end{center}

\column{0.25\textwidth}
\begin{center}
\includegraphics[width=1\textwidth]{Images/Closing_shadow} \\
Closing
\end{center}

\column{0.25\textwidth}
\begin{center}
\includegraphics[width=1\textwidth]{Images/Opening_shadow} \\
Opening
\end{center}
\end{columns}
\vspace{12pt}
Images from \url{http://en.wikipedia.org/wiki/Mathematical_morphology}
\end{frame}

\begin{frame}{Morphology in Action}
\center
\begin{center}
Back to iPython (\texttt{Examples/BasicTutorial2/Morphology.py})
\end{center}
\end{frame}

\begin{frame}[fragile]
\lstpython
\begin{lstlisting}
# Use pixel-wise operators
sitk.Show ( 127 * image + 127 * sitk.BinaryErode ( image ), "ThinErosion" )
\end{lstlisting}
\frametitle{Pixel-wise Operators}
\begin{threeparttable}
  \caption{SimpleITK Pixel-wise Operators}
  \begin{tabular}{c||l|l}
    Operator & Equivalant & Usage\tnote{$\dagger$} \\
    \hline
    $+$        & Add, AddConstantTo & $A + B$, $s+A$, $s+B$ \\
    $-$        & Subtract, SubtractConstantFrom & $A - B$, $s-A$, $s-B$ \\
    $*$        & Multiply, MultiplyByConstant & $A * B$, $s*A$, $s*B$ \\
    $/$        & Divide, DivideByConstant & $A / B$, $s/A$, $B/s$ \\
    $\&$        & And ``and'' & $A \& B$ \\
    $|$        & Or ``or'' & $A | B$ \\
    $\sim$        & Not ``not'' & $~A$ \\
    $**$\tnote{$\dagger\dagger$}  & Pow, PowToConstant & $A**B$, $A**s$
  \end{tabular}
  \begin{tablenotes}
    \item[$\dagger$] $A$ and $B$ are images (2D or 3D), $s$ is a scalar
    \item[$\dagger\dagger$] python only
  \end{tablenotes}
\end{threeparttable}
\end{frame}

\begin{frame}[fragile]
\frametitle{Operator Example}
\lstpython
\begin{lstlisting}
sitk.Hash ( image + 2 )
sitk.Hash ( sitk.AddConstantTo ( image, 2 ) )

sitk.Hash ( image * 2 )
sitk.Hash ( sitk.MultiplyByConstant ( image, 2 ) )
\end{lstlisting}

\begin{itemize}
  \item Hash calculates the MD5 or SHA1 hash of the \textit{image} data
  \item Used to tell if two images are exactly identical
\end{itemize}
Back to iPython (\texttt{Examples/BasicTutorial2/Morphology.py})
\end{frame}

%% \subsection{Label Maps}

%% %% Label maps
%% \begin{frame}{Label Maps}
%% \fontsize{36pt}{36pt}\selectfont
%% \center
%% \begin{center}
%% Label Maps
%% \end{center}
%% \end{frame}

%% Break
\begin{frame}{Break}
\fontsize{36pt}{36pt}\selectfont
\center
\begin{center}
Let's take a break
\end{center}
\end{frame}


\documentclass[dissertation.tex]{subfiles}
\begin{document}
\chapter{Introduction}
The design of \emph{motion planning} strategies plays a fundamental
role in different applications, from robotics to scientific
visualization. \emph{Path planning} problem is
more specific, it consists in identifying paths that do not
intersect any obstacle.

In this project we are interested in generating smooth
paths. Smoothness is a desirable property that is
frequently presented in literature for the planar case. Consider, for
instance, the papers \cite{maekawa}, \cite{ho-liu}, \cite{li} and
\cite{giannelli}. The first considers an interesting combined
approach to the problem: analytical to find a smooth curve, and
stochastic to locate a desired cusp on it. On the second, they
concentrate in finding a curvature bounded path starting from a
\acf{VD} constructed accordingly to the environment. The third work
focuses on
the process of transforming an existing polyline path in a smooth
curve. In the last, they used
\acf{PH} curves that have interesting features for the \acf{CAM} field
\cite{farouki}.

In regards of spatial path planning, the smoothing problem is less
covered in literature. For instance, in \cite{hrabar} it is not clear
how a smooth path is obtained from the initial polynomial chain. In
\cite{yang} the smoothness is considered, but the method is not
optimal because it consists in alternating smoothing and
obstacle-checking phases until an admissible solution is
obtained. Other works, like \cite{aghababa} and \cite{kroumov}, use
stochastic methods to achieve smoothness.

\bs curves are a reference standard in \acf{CAD} and \acf{CAGD}
\cite{hughes}\cite{foley}\cite{farin}\cite{farin2}. Thus, we decide to
develop a 3D path planning application using this kind of curves, as
\cite{yang} do. However, as earlier mentioned,
\cite{yang} uses a \emph{try and check} approach to the curve
smoothing, we present a method that finds a smooth
curve on the first
attempt instead.

The considered topic is highly interdisciplinary. In fact we integrate
in this project an extended set of
competencies acquired during the courses. We apply notions of
\emph{linear algebra} for the collision checks; \emph{numerical
  analysis} for the curves design; \emph{computational
  geometry},
\emph{graph theory}, \emph{probability} and \emph{algorithm theory}
for the algorithms design; and, finally, \emph{theoretical computer
  science} for cost analysis.

We focus on finding a trade-off between having a short curve, a
smooth curve, and keeping the time complexity low.
Different solutions are explored, with different qualitative effects
on the curve.

Regarding the scene representation, different kinds of
polyhedral obstacle are considered.

A framework in Python is developed using \acf{VTK} for the graphic
output. We use a roadmap method based on \acfp{VD} to create a
graph (details in
\cref{sec:baseGraph}) that is the base
structure for the project. Using such structure, three
different solutions are presented.
\begin{enumerate}
\item The first method benefits from the \acf{CHP} of \bs
  curves (\cref{sec:convexHull}). A transformation is applied on the
  graph such that every path in it can be used as a control polygon
  for an obstacle-free curve (\cref{sec:trigraph}). Therefore, the
  algorithm selects the shortest path in the transformed graph and
  builds the curve on it (\cref{sec:inter1}).
\item The second method still benefits from the \ac{CHP},
  but it picks the shortest path directly in the base graph. If
  violations of the \ac{CHP} emerge in it, then rectification
  measures are taken (\cref{sec:inter2}).
\item The third method uses a probabilistic approach. Starting from
  the shortest path in the original graph, it performs a simulated
  annealing optimization (\cref{sec:simulatedAnnealing}) that converges
  in a state where we have an optimal trade-off between having a short curve,
  and low curvature and torsion peaks (\cref{sec:inter3}).
\end{enumerate}

This document consists of three parts. The first
(\cref{prt:stateOfArt})
is dedicated to the state of the art: we provide a survey of
different topics and algorithms related to \emph{motion planning}.

The
second part (\cref{prt:project}) is committed to describing
all the different parts of the algorithm. In detail:
\begin{itemize}
\item \cref{cha:prerequisites} gives to the reader all the necessary notions
  to understand the rest of the chapter;
\item \cref{cha:scene} describes how the
  environment and the resulting curve are represented;
\item Finally in
\cref{cha:algorithm} we describe how to obtain the basic structures
(\cref{sec:polChain}), how to avoid the obstacles using the three
methods described before (\cref{sec:obsAvoid}), and how to improve the
obtained curve simplifying the control polygon (\cref{sec:postPro}),
increasing the curve degree (\cref{sec:degreeInc}) and changing the
\bs knot vector (\cref{sec:knotSel}).
\end{itemize}

The third part (\cref{prt:evaluation}) describes the instruments used
to implement the algorithms (\cref{cha:codeStructure}) and presents
a series of tests with
different scenes and configurations (\cref{cha:testing}) with their
conclusions (\cref{cha:conclusions}).

In conclusion, \cref{cha:appendix} contains all the source code of the
application.

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../dissertation"
%%% End: