\chapter{Gravitational Instability and Collapse}
\label{ch:collapse}

\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 3.4 \nocite{krumholz14c}
\end{itemize}
}

The previous two chapters provided a whirlwind tour of fluid dynamics and turbulence. However, in that discussion we completely omitted gravity, which is obviously critical to the process of star formation. We will now remedy that omission by bringing gravity back into the discussion.

\section{The Virial Theorem}

To open this topic, we will start by proving a powerful and general theorem about the behavior of fluids, known as the virial theorem.\footnote{Like the equations of motion, there is both an Eulerian form and a Lagrangian form of the virial theorem, depending on which version of the equations of motion we start with. We will derive the Eulerian form here, following the original proof by \citet{mckee92a}, but the derivation of the Lagrangian form proceeds in a similar manner, and can be found in many standard textbooks, for example \citet{shu92a}.} To derive the virial theorem, we begin with the MHD equations of motion, without either viscosity or resistivity (since neither of these are important for GMCs on large scales) but with gravity. We leave in the pressure forces, even though they are small, because they are also trivial to include. Thus we have
\begin{eqnarray}
\frac{\partial\rho}{\partial t} & = & -\nabla \cdot (\rho \vecv) \\
\frac{\partial}{\partial t}(\rho \vecv) & = & -\nabla\cdot(\rho\vecv\vecv) -\nabla P + \frac{1}{4\pi} (\nabla\times\vecB)\times\vecB - \rho \nabla \phi.
\end{eqnarray}
Here $\phi$ is the gravitational potential, so $-\rho \nabla \phi$ is the gravitational force per unit volume. These equations are the Eulerian equations written in conservative form.

Before we begin, life will be a bit easier if we re-write the entire second equation in a manifestly tensorial form -- this simplifies the analysis tremendously. To do so, we define two tensors: the fluid pressure tensor $\vecPi$ and the Maxwell stress tensor $\vecT_M$, as follows:
\begin{eqnarray}
\vecPi & \equiv & \rho \vecv\vecv + P\vecI \\
\vecT_M & \equiv & \frac{1}{4\pi} \left(\vecB\vecB - \frac{B^2}{2}\vecI\right)
\end{eqnarray}
Here $\vecI$ is the identity tensor. In tensor notation, these are
\begin{eqnarray}
(\vecPi)_{ij} & \equiv & \rho v_i v_j + P \delta_{ij} \\
(\vecT_M)_{ij} & \equiv & \frac{1}{4\pi} \left(B_i B_j - \frac{1}{2}B_k B_k \delta_{ij}\right).
\end{eqnarray}
With these definitions, the momentum equation just becomes
\begin{equation}
\frac{\partial}{\partial t}(\rho \vecv) = -\nabla\cdot(\vecPi-\vecT_M) - \rho \nabla\phi.
\end{equation}

The substitution for $\vecPi$ is obvious. The equivalence of $\nabla\cdot\vecT_M$ to $1/(4\pi) (\nabla\times\vecB)\times\vecB$ is easy to establish with a little vector manipulation, which is most easily done in tensor notation:
\begin{eqnarray}
(\nabla\times\vecB)\times\vecB & = & \epsilon_{ijk} \epsilon_{jmn} \left(\frac{\partial}{\partial x_m}B_n\right) B_k \\
& = & -\epsilon_{jik} \epsilon_{jmn} \left(\frac{\partial}{\partial x_m}B_n\right) B_k \\
& = & (\delta_{in}\delta_{km}-\delta_{im}\delta_{kn})\left(\frac{\partial}{\partial x_m}B_n\right) B_k \\
& = & B_k\frac{\partial}{\partial x_k} B_i - B_k\frac{\partial}{\partial x_i} B_k \\
& = & \left(B_k\frac{\partial}{\partial x_k} B_i + B_i \frac{\partial}{\partial x_k} B_k\right) - B_k\frac{\partial}{\partial x_i} B_k \\
& = & \frac{\partial}{\partial x_k}\left(B_i B_k\right) -\frac{1}{2} \frac{\partial}{\partial x_i} \left(B_k^2\right)\\
& = & \nabla\cdot \left(\vecB\vecB - \frac{B^2}{2}\vecI\right).
\end{eqnarray}

To derive the virial theorem, we begin by imagining a cloud of gas enclosed by some fixed volume $V$. The surface of this volume is $S$. We want to know how the overall distribution of mass changes within this volume, so we begin by writing down a quantity the represents the mass distribution. This is the moment of inertia,
\begin{equation}
I = \int_V \rho r^2\, dV.
\end{equation}

We want to know how this changes in time, so we take its time derivative:
\begin{eqnarray}
\dot{I} & = & \int_V \frac{\partial\rho}{\partial t} r^2 \,dV \\
& = & -\int_V \nabla \cdot (\rho \vecv) r^2\, dV \\
& = & -\int_V \nabla \cdot (\rho \vecv r^2)\, dV + 2\int_V \rho \vecv\cdot \vecr\, dV \\
& = & -\int_S (\rho \vecv r^2)\cdot d\vecS + 2\int_V \rho \vecv\cdot \vecr\, dV.
\end{eqnarray}
In the first step we used the fact that the volume $V$ does not vary in time to move the time derivative inside the integral. Then in the second step we used the equation of mass conservation to substitute. In the third step we brought the $r^2$ term inside the divergence. Finally in the fourth step we used the divergence theorem to replace the volume integral with a surface integral.

Now we take the time derivative again, and multiply by $1/2$ for future convenience:
\begin{eqnarray}
\frac{1}{2}\ddot{I} & = & -\frac{1}{2} \int_S r^2 \frac{\partial}{\partial t}(\rho\vecv)\cdot d\vecS +
\int_V \frac{\partial}{\partial t}(\rho\vecv)\cdot\vecr \, dV \\
& = & -\frac{1}{2} \frac{d}{dt} \int_S r^2 (\rho\vecv)\cdot d\vecS
\nonumber \\
& & \quad {} -
\int_V \vecr \cdot \left[\nabla\cdot(\vecPi-\vecT_M)+ \rho\nabla \phi \right] \, dV.
\end{eqnarray}
The term involving the tensors is easy to simplify using a handy identity, which applies to an arbitrary tensor. This is a bit easier to follow in tensor notation:
\begin{eqnarray}
\int_V \vecr\cdot \nabla\cdot \vecT \, dV & = & \int_V x_i \frac{\partial}{\partial x_j} T_{ij}\,dV \\
& = & \int_V \frac{\partial}{\partial x_j}(x_i T_{ij})\,dV - \int_V T_{ij} \frac{\partial}{\partial x_j}x_i \, dV \\
& = & \int_S x_i T_{ij} \,dS_j - \int_V \delta_{ij} T_{ij} \, dV \\
& = & \int_S \vecr\cdot\vecT\cdot d\vecS - \int_V \mbox{Tr}\; \vecT \, dV,
\end{eqnarray}
where $\mbox{Tr}\;\vecT = T_{ii}$ is the trace of the tensor $\vecT$.

Applying this to our result our tensors, we note that
\begin{eqnarray}
\mbox{Tr}\; \vecPi & = & 3P + \rho v^2 \\
\mbox{Tr}\; \vecT_M & = & -\frac{B^2}{8\pi}
\end{eqnarray}
Inserting this result into our expression for $\ddot{I}$ gives the virial theorem, which we will write in a more suggestive form to make its physical interpretation clearer:
\begin{equation}
\frac{1}{2}\ddot{I} = 2(\mathcal{T} - \mathcal{T}_S) + \mathcal{B} + \mathcal{W} - \frac{1}{2}\frac{d}{dt} \int_S (\rho\vecv r^2)\cdot d\vecS,
\end{equation}
where
\begin{eqnarray}
\mathcal{T} & = & \int_V\left(\frac{1}{2}\rho v^2 + \frac{3}{2} P\right)\, dV \\
\mathcal{T}_S & = & \int_S \vecr \cdot \vecPi \cdot d\vecS\\
\mathcal{B} & = & \frac{1}{8\pi} \int_V B^2 \,dV + \int_S \vecr\cdot \vecT_M\cdot d\vecS\\
\mathcal{W} & = & -\int_V \rho \vecr\cdot\nabla\phi\,dV.
\end{eqnarray}

Written this way, we can give a clear interpretation to what these terms mean. $\mathcal{T}$ is just the total kinetic plus thermal energy of the cloud. $\mathcal{T}_S$ is the confining pressure on the cloud surface, including both the thermal pressure and the ram pressure of any gas flowing across the surface. $\mathcal{B}$ is the the difference between the magnetic pressure in the cloud interior, which tries to hold it up, and the magnetic pressure plus magnetic tension at the cloud surface, which try to crush it. $\mathcal{W}$ is the gravitational energy of the cloud. If there is no external gravitational field, and $\phi$ comes solely from self-gravity, then $\mathcal{W}$ is just the gravitational binding energy. The final integral represents the rate of change of the momentum flux across the cloud surface.

$\ddot{I}$ is the integrated form of the acceleration. For a cloud of fixed shape, it tells us the rate of change of the cloud's expansion or contraction. If it is negative, the terms that are trying to collapse the cloud (the surface pressure, magnetic pressure and tension at the surface, and gravity) are larger, and the cloud accelerates inward. If it is positive, the terms that favor expansion (thermal pressure, ram pressure, and magnetic pressure) are larger, and the cloud accelerates outward. If it is zero, the cloud neither accelerates nor decelerates.

We get a particularly simple form of the virial theorem if there is no gas crossing the cloud surface (so $\vecv=0$ at $S$) and if the magnetic field at the surface to be a uniform value $B_0$. In this case the virial theorem reduces to
\begin{equation}
\frac{1}{2}\ddot{I} = 2(\mathcal{T} - \mathcal{T}_S) + \mathcal{B} + \mathcal{W}
\end{equation}
with
\begin{eqnarray}
\mathcal{T}_S & = & \int_S rP \,dS\\
\mathcal{B} & = & \frac{1}{8\pi} \int_V (B^2-B_0^2) \,dV.
\end{eqnarray}
For this simplified physical setup, $\mathcal{T}_S$ just represents the mean radius times pressure at the virial surface, and $\mathcal{B}$ just represents the total magnetic energy of the cloud minus the magnetic energy of the background field over the same volume. Notice that, if a cloud is in equilibrium ($\ddot{I}=0$) and magnetic and surface forces are negligible, then we have $2\mathcal{T} = -\mathcal{W}$. Based on this result, we define the virial ratio
\begin{equation}
\label{eq:alpha_vir_th}
\alpha_{\rm vir} = \frac{2\mathcal{T}}{|\mathcal{W}|}.
\end{equation}
For an object for which magnetic and surface forces are negligible, and with no flow across the virial surface, a value of $\alpha_{\rm vir} > 1$ implies $\ddot{I} > 0$, and a value $\alpha_{\rm vir} < 1$ implies $\ddot{I}<0$. Thus $\alpha_{\rm vir} = 1$ roughly divides clouds that have enough internal pressure or turbulence to avoid collapse from those that do not.

\section{Stability Conditions}

Armed with the virial theorem, we are now in a position to understand, at least qualitatively, under what conditions a cloud of gas will be stable against gravitational contraction, and under what conditions it will not be. If we examine the terms on the right hand side of the virial theorem, we can group them into those that are generally or always positive, and thus oppose collapse, and those that are generally or always negative, and thus encourage it. The main terms opposing collapse are $\mathcal{T}$, which contains parts describing both thermal pressure and turbulent motion, and $\mathcal{B}$, which describes magnetic pressure and tension. The main terms favoring collapse are $\mathcal{W}$, representing self-gravity, and $\mathcal{T}_S$, representing surface pressure. The final term, the surface one, could be positive or negative depending on whether mass is flowing into our out of the virial volume. We will begin by examining the balance among these terms, and the forces they represent.

\subsection{Thermal Support and the Jeans Instability}

Gas pressure is perhaps the most basic force in opposing collapse. Unlike turbulent motions, which can compress in some places even as they provide overall support, gas pressure always tries to smooth out the gas. Similarly, self-gravity is the most reliable promoter of collapse. A full, formal analysis of the interaction between pressure and self-gravity was provided by James Jeans in 1902 \citep{jeans02a}, and we will go through it below. However, we can already see what the basic result will have to look like just from the virial theorem. We expect the dividing line between stability and instability to lie at $\alpha_{\rm vir} \approx 1$. For an isolated, isothermal cloud of mass $M$ and radius $R$ with only thermal pressure, we have
\begin{eqnarray}
\mathcal{T} & = & \frac{3}{2} M c_s^2 \\
\mathcal{W} & = & -a \frac{GM^2}{R},
\end{eqnarray}
where $a$ is a factor of order unity that depends on the internal density structure. Thus the condition $\alpha_{\rm vir} \gtrsim 1$ corresponds to
\begin{equation}
M c_s^2 \gtrsim \frac{GM^2}{R} \qquad\Longrightarrow\qquad R \gtrsim \frac{GM}{c_s^2},
\end{equation}
or, rewriting in terms of the mean density $\rho \sim M/R^3$,
\begin{equation}
R \lesssim \frac{c_s}{\sqrt{G\rho}}.
\end{equation}

The formal analysis proceeds as follows. Consider a uniform, infinite, isothermal medium at rest. The density is $\rho_0$, the pressure is $P_0 = \rho_0 c_s^2$, and the velocity is $\vecv_0 = 0$. We will write down the equations of hydrodynamics and self-gravity for this gas:
\begin{eqnarray}
\frac{\partial}{\partial t}\rho + \nabla\cdot (\rho \vecv) & = & 0 \\
\frac{\partial}{\partial t}(\rho\vecv) + \nabla\cdot(\rho \vecv\vecv) & = & -\nabla P - \rho \nabla \phi \\
\nabla^2 \phi & = & 4\pi G\rho.
\end{eqnarray}

Here the first equation represents conservation of mass, the second represents conservation of momentum, and the third is the Poisson equation for the gravitational potential $\phi$. We take the background density $\rho_0$, velocity $\vecv_0 = 0$, pressure $P_0$, and potential $\phi_0$ to be an exact solution of these equations, so that all time derivatives are zero as long as the gas is not disturbed.

Note that this involves the "Jeans swindle": this assumption is actually not really consistent, because the Poisson equation cannot be solved for an infinite uniform medium unless $\rho_0 = 0$. In other words, there is no function $\phi_0$ such that $\nabla^2\phi_0$ is equal to a non-zero constant value on all space. That said, we will ignore this complication, since the approximation of a uniform infinite medium is a reasonable one for a very large but finite uniform medium. It is possible to construct the argument without the Jeans swindle, but doing so adds mathematical encumbrance without physical insight, so we will not do so.

That digression aside, now let us consider what happens if we perturb this system. We will write the density as $\rho = \rho_0 + \epsilon \rho_1$, where $\epsilon\ll 1$. Similarly, we write $\vecv=\epsilon \vecv_1$ and $\phi=\phi_0 + \epsilon \phi_1$. Since we can always use Fourier analysis to write an arbitrary perturbation as a sum of Fourier components, without loss of generality we will take the perturbation to be a single, simple Fourier mode. The reason to do this is that, as we will see, differential equations are trivial to solve when the functions in question are simple plane waves.

Thus we write $\rho_1 = \rho_a \exp[i(kx - \omega t)]$. Note that we implicitly understand that we use only the real part of this exponential. It is just easier to write things in terms of an $e^{i(kx-\omega t)}$ than it is to keep track of a bunch of sines and cosines. In writing this equation, we have chosen to orient our coordinate system so that the wave vector $\veck$ of the perturbation is in the $\vecx$ direction. Again, there is no loss of generality in doing so.

Given this density perturbation, what is the corresponding perturbation to the potential? From the Poisson equation, we have
\begin{equation}
\nabla^2 (\phi_0 + \epsilon \phi_1) = 4\pi G (\rho_0 + \epsilon \rho_1).
\end{equation}
Since by assumption $\rho_0$ and $\phi_0$ are exact solutions to the Poisson equation, we can cancel the $\phi_0$ and $\rho_0$ terms out of the equation, leaving
\begin{equation}
\nabla^2 \phi_1 = 4 \pi G \rho_1 = 4\pi G \rho_a e^{i(kx-\omega t)}.
\end{equation}
This equation is trivial to solve, since it is just of the form $y'' = a e^{bx}$. The solution is
\begin{equation}
\phi_1 = -\frac{4\pi G \rho_a}{k^2} e^{i(kx - \omega t)}.
\end{equation}
By analogy to what we did for $\rho_1$, we write this solution as $\phi_1 = \phi_a e^{i(kx-\omega t)}$, with
\begin{equation}
\phi_a = -\frac{4\pi G \rho_a}{k^2}.
\end{equation}

Now that we have found the perturbed potential, let us determine what motion this will induce in the fluid. To do so, we first take the equations of mass and momentum conservation and we linearize them. This means that we substitute in $\rho = \rho_0 + \epsilon \rho_1$, $\vecv=\epsilon \vecv_1$, $P=P_0+\epsilon P_1=c_s^2 (\rho_0 + \epsilon \rho_1)$, and $\phi=\phi_0+\epsilon \phi_1$. Note that $\vecv_0 = 0$. We then expand the equations in powers of $\epsilon$, and we drop all the terms that are of order $\epsilon^2$ or higher on the grounds that they become negligible in the limit of small $\epsilon$.

Linearizing the equation of mass conservation we get
\begin{eqnarray}
\frac{\partial}{\partial t} (\rho_0 + \epsilon \rho_1) + \nabla\cdot [(\rho_0 + \epsilon \rho_1)(\epsilon\vecv_1)] & = & 0 \\
\frac{\partial}{\partial t} \rho_0 + \epsilon \frac{\partial}{\partial t} \rho_1 + \epsilon \nabla \cdot (\rho_0\vecv_1) & = & 0 \\
\frac{\partial}{\partial t} \rho_1+ \nabla \cdot (\rho_0\vecv_1) & = & 0.
\label{eq:masscons_linear}
\end{eqnarray}
In the second step, we dropped a term of order $\epsilon^2$. In the third step we used the fact that $\rho_0$ is constant, i.e., that the background density has zero time derivative, to drop that term. Applying the same procedure to the momentum equation, we get
\begin{eqnarray}
\nonumber
\lefteqn{
\frac{\partial}{\partial t} [(\rho_0 + \epsilon \rho_1)(\epsilon\vecv_1)] + \nabla\cdot [(\rho_0 + \epsilon \rho_1)(\epsilon\vecv_1)(\epsilon\vecv_1)]
}
\qquad\qquad\qquad
\\
& = & -c_s^2 \nabla (\rho_0 + \epsilon \rho_1) \nonumber \\
& & \qquad {} - (\rho_0 + \epsilon\rho_1)\nabla (\phi_0 + \epsilon \phi_1)
\\
\epsilon \frac{\partial}{\partial t} (\rho_0\vecv_1) & = & -c_s^2 \nabla \rho_0 - \rho_0 \nabla\phi_0
\nonumber \\
& & \qquad {}
- \epsilon \left(c_s^2 \nabla \rho_1 + \rho_1\nabla \phi_0 + \rho_0\nabla \phi_1\right) \\
\frac{\partial}{\partial t} (\rho_0\vecv_1) & = & -c_s^2 \nabla \rho_1 - \rho_0\nabla\phi_1.
\label{eq:momcons_linear}
\end{eqnarray}
In the second step we dropped terms of order $\epsilon^2$, and in the third step we used the fact that the background state is uniform to drop terms involving gradients of $\rho_0$ and $\phi_0$.

Now that we have our linearized equations, we're ready to find out what $\vecv_1$ must be. By analogy to what we did for $\rho_1$ and $\phi_1$, we take $\vecv_1$ to be a single Fourier mode, of the form
\begin{equation}
\vecv_1 = \vecv_a e^{i(kx-\omega t)}
\end{equation}
Substituting for $\rho_1$, $\phi_1$, and $\vecv_1$ into the linearized mass conservation equation (\ref{eq:masscons_linear}), we get
\begin{eqnarray}
\frac{\partial}{\partial t} \left(\rho_a e^{i(kx-\omega t)}\right) + \nabla\cdot (\rho_0 \vecv_a e^{i(kx-\omega t)}) & = & 0 \\
-i\omega \rho_a e^{i(kx-\omega t)} + i k \rho_0 v_{a,x} e^{i(kx-\omega t)} & = & 0 \\
-\omega\rho_a + k\rho_0 v_{a,x} & = & 0 \\
\frac{\omega\rho_a}{k\rho_0} & = & v_{a,x}
\end{eqnarray}
where $v_{a,x}$ is the $x$ component of $\vecv_a$.

We have now found the velocity perturbation in terms of $\rho_a$, $\omega$, and $k$. Similarly substituting into the linearized momentum equation (\ref{eq:momcons_linear}) gives
\begin{eqnarray}
\frac{\partial}{\partial t} \left(\rho_0 \vecv_a e^{i(kx-\omega t)}\right) & = & -c_s^2 \nabla(\rho_a e^{i(kx-\omega t)})
\nonumber \\
& & \qquad {}
 - \rho_0 \nabla (\phi_a e^{i(kx-\omega t)}) \\
-i\omega \rho_0 \vecv_a e^{i(kx-\omega t)} & = & -i k c_s^2 \rho_a \hat{\mathbf{x}} e^{i(kx-\omega t)}
\nonumber \\
& & \qquad {}
- i k \rho_0 \phi_a e^{i(kx-\omega t)} \hat{\mathbf{x}}\\
\omega \rho_0 v_{a,x} & = & k \left(c_s^2 \rho_a + \rho_0 \phi_a\right).
\end{eqnarray}
Now let us take this equation and substitute in the values for $\phi_a$ and $v_{a,x}$ that we previously determined:
\begin{eqnarray}
\omega \rho_0 \left(\frac{\omega\rho_a}{k\rho_0}\right) & = & k c_s^2 \rho_a - k\rho_0 \left(\frac{4\pi G \rho_a}{k^2}\right) \\
\omega^2 & = & c_s^2 k^2 - 4\pi G \rho_0
\end{eqnarray}
This expression is known as a dispersion relation, because it describes the dispersion of the plane wave solution we have found, i.e., how that wave's spatial frequency $k$ relates to its temporal frequency $\omega$.

To see what this implies, let us consider what happens when we put in a perturbation with a short wavelength or a large spatial frequency. In this case $k$ is large, and $c_s^2 k^2 - 4\pi G \rho_0>0$, so $\omega$ is a positive or negative real number. The density is $\rho=\rho_0 + \rho_a e^{i(kx-\omega t)}$, which represents a uniform background density with a small oscillation in space and time on top of it. Since $|e^{i(kx-\omega t)}| < 1$ at all times and places, the oscillation does not grow.

On the other hand, suppose that we impose a perturbation with a large spatial range, or a small spatial frequency. In this case $c_s^2 k^2 - 4\pi G \rho_0<0$, so $\omega$ is a positive or negative imaginary number. For an imaginary $\omega$, $|e^{-i\omega t}|$ either decays to zero or grows infinitely large in time, depending on whether we take the positive or negative imaginary root. Thus at least one solution for the perturbation will not remain small. It will grown in amplitude without limit.

This represents an instability: if we impose an arbitrarily small amplitude perturbation on the density at a sufficiently large wavelength, that perturbation will eventually grow to be large. Of course once $\rho_1$ becomes large enough, our linearization procedure of dropping terms proportional to $\epsilon^2$ becomes invalid, since these terms are no longer small. In this case we must follow the full non-linear behavior of the equations, usually with simulations.

We have, however, shown that there is a critical size scale beyond which perturbations that are stabilized only by pressure must grow to non-linear amplitude. The critical length scale is set by the value of $k$ for which $\omega=0$,
\begin{equation}
k_J = \sqrt{\frac{4\pi G\rho_0}{c_s^2}}.
\end{equation}
The corresponding wavelength is
\begin{equation}
\lambda_J = \frac{2\pi}{k_J} = \sqrt{\frac{\pi c_s^2}{G\rho_0}}.
\end{equation}
This is known as the Jeans length. One can also define a mass scale associated with this: the Jeans mass, $M_J=\rho\lambda_J^3/8$.\footnote{The definition of the Jeans mass is somewhat ambiguous, and multiple definitions can be found in the literature. The one we have chosen corresponds to considering the mass within a cube of half a Jeans length in size. Possible alternatives include choosing a cube one Jeans length in size or choosing a sphere one Jeans length in radius or diameter, to name just two possibilities. These definitions all scale with density and Jeans length in the same way, and differ only in their coefficients.}

If we plug in some typical numbers for a GMC, $c_s=0.2$ km s$^{-1}$ and $\rho_0 = 100 m_p\mbox{ cm}^{-3}$, we get $\lambda_J = 3.4$ pc. Since every GMC we have seen is larger than this size, and there are clearly always perturbations present, this means that molecular clouds cannot be stabilized by gas pressure against collapse. Of course one could have guessed this result just by evaluating terms in the virial theorem: the gas pressure term is very small compared to the gravitational one. Ultimately, the virial theorem and the Jeans instability analysis are just two different ways of extracting the same information from the equations of motion.

One nice thing about the Jeans analysis, however, is that it makes it obvious how fast we should expect gravitational instabilities to grow. Suppose we have a very unstable system, where $c_s^2 k^2 \ll 4 \pi G \rho_0$. This is the case for GMC, for example. There are perturbations on the size of the entire cloud, which might be 50 pc in size. This is a spatial frequency $k=2\pi/(50\mbox{ pc}) = 0.12$ pc$^{-1}$. Plugging this in with $c_s = 0.2$ km s$^{-1}$ and $\rho_0=100 m_p\mbox{ cm}^{-3}$ gives $c_s^2 k^2 / (4\pi G \rho) = 0.005$.
In this case we have
\begin{equation}
\omega \approx \pm i \sqrt{4\pi G\rho_0}.
\end{equation}

Taking the negative $i$ root, which corresponds to the growing mode, we find that
\begin{equation}
\rho_1 \propto \exp([4\pi G \rho_0]^{1/2} t).
\end{equation}
Thus the $e$-folding time for the disturbance to grow is $\sim 1/\sqrt{G\rho_0}$. We define the free-fall time as
\begin{equation}
t_{\rm ff} = \sqrt{\frac{3\pi}{32 G \rho_0}},
\end{equation}
where the numerical coefficient of $\sqrt{3\pi/32}$ comes from doing the closely related problem of the collapse of a pressureless sphere, which we will cover in Section \ref{sec:pressureless_collapse}. The free-fall time is the characteristic time scale required for a medium with negligible pressure support to collapse.

The Jeans analysis is of course only appropriate for a uniform medium, and it requires the Jeans swindle. Problem Set 2 contains a calculation of the maximum mass of a spherical cloud that can support itself against collapse by thermal pressure, called the Bonnor-Ebert mass \citep{ebert55a, bonnor56a}. Not surprisingly, the Bonnor-Ebert mass is simply $M_J$ times factors of order unity.

\subsection{Magnetic Support and the Magnetic Critical Mass}

We now examine another term that generally opposes collapse: the magnetic one. Let us consider a uniform spherical cloud of radius $R$ threaded by a magnetic field $\vecB$. We imagine that $\vecB$ is uniform inside the cloud, but that outside the cloud the field lines quickly spread out, so that the magnetic field drops down to some background strength $\vecB_0$, which is also uniform but has a magnitude much smaller than $\vecB$.

Here it is easiest to work directly with the virial theorem. The magnetic term in the virial theorem is
\begin{equation}
\mathcal{B} = \frac{1}{8\pi} \int_V B^2 \,dV + \int_S \vecr \cdot \vecT_M \cdot d\vecS
\end{equation}
where
\begin{equation}
\vecT_M = \frac{1}{4\pi} \left(\vecB\vecB - \frac{B^2}{2}\vecI\right).
\end{equation}

If the field inside the cloud is much larger than the field outside it, then the first term, representing the integral of the magnetic pressure within the cloud, is
\begin{equation}
\frac{1}{8\pi} \int_V B^2\, dV \approx \frac{B^2 R^3}{6}.
\end{equation}
Here we have dropped any contribution from the field outside the cloud. The second term, representing the surface magnetic pressure and tension, is
\begin{equation}
\int_S \vecx \cdot \vecT_M \cdot d\vecS = \int_S \frac{B_0^2}{8\pi} \vecx \cdot d\vecS
\approx \frac{B_0^2 R_0^3}{6}
\end{equation}

Since the field lines that pass through the cloud must also pass through the virial surface, it is convenient to rewrite everything in terms of the magnetic flux. The flux passing through the cloud is $\Phi_B = \pi B R^2$, and since these field lines must also pass through the virial surface, we must have $\Phi_B = \pi B_0 R_0^2$ as well. Thus, we can rewrite the magnetic term in the virial theorem as
\begin{equation}
\mathcal{B} \approx \frac{B^2 R^3}{6} - \frac{B_0^2 R_0^3}{6} = \frac{1}{6\pi^2} \left(\frac{\Phi_B^2}{R} - \frac{\Phi_B^2}{R_0}\right) \approx \frac{\Phi_B^2}{6\pi^2 R}.
\end{equation}

In the last step we used the fact that $R \ll R_0$ to drop the $1/R_0$ term. Now let us compare this to the gravitational term, which is
\begin{equation}
\mathcal{W} = -\frac{3}{5} \frac{GM^2}{R}
\end{equation}
for a uniform cloud of mass $M$. Comparing these two terms, we find that
\begin{equation}
\mathcal{B}+\mathcal{W} = \frac{\Phi_B^2}{6\pi^2 R} - \frac{3}{5} \frac{GM^2}{R} \equiv \frac{3}{5}\frac{G}{R} \left(M_{\Phi}^2-M^2\right)
\end{equation}
where
\begin{equation}
\label{eq:mphi}
M_{\Phi} \equiv \sqrt{\frac{5}{2}} \left(\frac{\Phi_B}{3 \pi G^{1/2}}\right)
\end{equation}
We call $M_{\Phi}$ the magnetic critical mass. Since $\Phi_B$ does not change as a cloud expands or contracts (due to flux-freezing), this magnetic critical mass does not change either.

The implication of this is that clouds that have $M>M_{\Phi}$ always have $\mathcal{B}+\mathcal{W} < 0$. The magnetic force is unable to halt collapse no matter what. Clouds that satisfy this condition are called magnetically supercritical, because they are above the magnetic critical mass $M_{\Phi}$. Conversely, if $M<M_{\Phi}$, then $\mathcal{B}+\mathcal{W} > 0$, and gravity is weaker than magnetism. Clouds satisfying this condition are called subcritical.

For a subcritical cloud, since $\mathcal{B}+\mathcal{W} \propto 1/R$, this term will get larger and larger as the cloud shrinks. In other words, not only is the magnetic force resisting collapse is stronger than gravity, it becomes larger and larger without limit as the cloud is compressed to a smaller radius. Unless the external pressure is also able to increase without limit, which is unphysical, then there is no way to make a magnetically subcritical cloud collapse. It will always stabilize at some finite radius. The only way to get around this is to change the magnetic critical mass, which requires changing the magnetic flux through the cloud. This is possible only via ion-neutral drift or some other non-ideal MHD effect that violates flux-freezing.

Of course our calculation is for a somewhat artificial configuration of a spherical cloud with a uniform magnetic field. In reality a magnetically-supported cloud will not be spherical, since the field only supports it in some directions, and the field will not be uniform, since gravity will always bend it some amount. Figuring out the magnetic critical mass in that case requires solving for the cloud structure numerically. A calculation of this effect by \citet{tomisaka98a} gives
\begin{equation}
M_{\Phi} = 0.12\frac{\Phi_B}{G^{1/2}}
\end{equation}
for clouds for which pressure support is negligible. The numerical coefficient we obtained for the uniform cloud case (equation \ref{eq:mphi}) is $0.17$, so this is obviously a small correction. It is also possible to derive a combined critical mass that incorporates both the flux and the sound speed, and which limits to the Bonnor-Ebert mass for negligible field and the magnetic critical mass for negligible pressure.

It is not so easy to determine observationally whether the magnetic fields are strong enough to hold up molecular clouds.  The observations are somewhat complicated by the fact that, using the most common technique of Zeeman splitting, one can only measure the line of sight component of the field. This therefore gives only a lower limit on the magnetic critical mass. Nonetheless, for a large enough sample, one can estimate true magnetic field strengths statistically under the assumption of random orientations. When this analysis is performed, the current observational consensus is that magnetic fields in molecular clouds are not, by themselves, strong enough to prevent gravitation collapse. Figure \ref{fig:bfields} shows a summary of the current observations. Clearly atomic gas is magnetically subcritical, but molecular gas is supercritical.

\begin{figure}
\includegraphics[width=\linewidth]{bfields_crutcher12}
\caption[Magnetic field strength measurements]{
\label{fig:bfields}
Measurements of the line of sight magnetic field strength from the Zeeman effect, versus total gas column density in H atoms cm$^{-2}$ (data from the compilation of \citealt{crutcher12a}). The three clumps of points represent, from left to right, measurements from the Zeeman splitting of H~\textsc{i}, OH, and CN. The dashed black line indicates the separation between field strengths that are large enough to render the gas subcritical, and those weak enough for it to be supercritical.
}
\end{figure}

\subsection{Turbulent Support}

There is one more positive term in the virial theorem, which is the turbulent component of $\mathcal{T}$. This one is not at all well understood, largely because we don't understand turbulence itself. This term almost certainly provides some support against collapse, but the amount is not well understood, and we will defer any further discussion of this effect until we get to our discussions of the star formation rate in Chapter \ref{ch:sflaw_th}.

\section{Pressureless Collapse}
\label{sec:pressureless_collapse}

As a final topic for this chapter, let us consider what we should expect to happen if gas does begin to collapse, in the simplest case of an initially-spherical cloud with an initial density distribution $\rho(r)$. We would like to know how the gas moves under the influence of gravity and thermal pressure, under the assumption of spherical symmetry. For convenience we define the enclosed mass
\begin{equation}
M_r =  \int_0^r 4\pi r'^2 \rho(r') \, dr'
\end{equation}
or equivalently
\begin{equation}
\frac{\partial M_r}{\partial r} = 4\pi r^2 \rho.
\end{equation}
The equation of mass conservation for the gas in spherical coordinates is
\begin{eqnarray}
\frac{\partial}{\partial t} \rho + \nabla\cdot (\rho \vecv) & = & 0 \\
\frac{\partial}{\partial t} \rho + \frac{1}{r^2}\frac{\partial}{\partial r}(r^2 \rho v) & = & 0,
\end{eqnarray}
where $v$ is the radial velocity of the gas. It is useful to write the equations in terms of $M_r$ rather than $\rho$, so we take the time derivative of $M_r$ to get
\begin{eqnarray}
\frac{\partial}{\partial t}M_r & = & 4\pi \int_{0}^{r} r'^2 \frac{\partial}{\partial t} \rho \,dr' \\
& = & -4\pi \int_{0}^{r} \frac{\partial}{\partial r'}(r'^2 \rho v)\, dr' \\
& = & -4\pi r^2 \rho v \\
& = & -v \frac{\partial}{\partial r}M_r.
\end{eqnarray}
In the second step we used the mass conservation equation to substitute for $\partial \rho/\partial t$, and in the final step we used the definition of $M_r$ to substitute for $\rho$.

To figure out how the gas moves, we write down the Lagrangean version of the momentum equation:
\begin{equation}
\rho \frac{Dv}{Dt} = -\frac{\partial}{\partial r}P - \mathbf{f}_g,
\end{equation}
where $\mathbf{f}_g$ is the gravitational force per unit mass. For the momentum equation, we take advantage of the fact that the gas is isothermal to write $P=\rho c_s^2$. The gravitational force is $\mathbf{f}_g = -G M_r / r^2$. Thus we have
\begin{equation}
\frac{Dv}{Dt}= \frac{\partial}{\partial t}v + v\frac{\partial}{\partial r} v= -\frac{c_s^2}{\rho} \frac{\partial}{\partial r}{\rho} - \frac{G M_r}{r^2}.
\end{equation}

To go further, let us make one more simplifying assumption: that the sound speed $c_s$ is zero. This is not as bad an approximation as one might think. Consider the virial theorem: the thermal pressure term is just proportional to the mass, since the gas sound speed stays about constant. On the other hand, the gravitational term varies as $1/R$. Thus, even if pressure starts out competitive with gravity, as the core collapses the dominance of gravity will increase, and before too long the collapse will resemble a pressureless one.

In this case the momentum equation is trivial:
\begin{equation}
\frac{Dv}{Dt} = -\frac{GM_r}{r^2}.
\end{equation}
This just says that a shell's inward acceleration is equal to the gravitational force per unit mass exerted by all the mass interior to it, which is constant. We can then solve for the velocity as a function of position:
\begin{equation}
v = \dot{r} = -\sqrt{2GM_r}\left(\frac{1}{r}-\frac{1}{r_0}\right)^{1/2},
\end{equation}
where $r_0$ is the position at which a particular fluid element starts.

The integral can be evaluated by the trigonometric substitution $r=r_0 \cos^2\xi$. The solution, first obtained by Hunter (1962), is
\begin{eqnarray}
-2 r_0 (\cos\xi \sin\xi) \dot{\xi} & = & -\sqrt{\frac{2GM_r}{r_0}} \left(\frac{1}{\cos^2\xi}-1\right)^{1/2} \\
2 (\cos\xi\sin\xi) \dot{\xi} & = & \sqrt{\frac{2GM_r}{r_0^3}}\tan\xi \\
2 \cos^2\xi\, d\xi & = & \sqrt{\frac{2GM_r}{r_0^3}} dt \\
\xi+\frac{1}{2}\sin 2\xi & = & t \sqrt{\frac{2GM_r}{r_0^3}}.
\end{eqnarray}
We are interested in the time at which a given fluid element reaches the origin, $r=0$. This corresponds to $\xi = \pi/2$, so this time is
\begin{equation}
t = \frac{\pi}{2}\sqrt{\frac{r_0^3}{2 G M_r}}.
\end{equation}

Suppose that the gas we started with was of uniform density $\rho$, so that $M_r = (4/3)\pi r_0^3 \rho$.
In this case we have
\begin{equation}
t = t_{\rm ff} = \sqrt{\frac{3\pi}{32 G \rho}},
\end{equation}
where we have defined the free-fall time $t_{\rm ff}$: it is the time required for a uniform sphere of pressureless gas to collapse to infinite density. This is of course just the characteristic growth time for the Jeans instability in the regime of negligible pressure, up to a factor of order unity.

For a uniform fluid this means that the collapse is synchronized -- all the mass reaches the origin at the exact same time. A more realistic case is for the initial state to have some level of central concentration, so that the initial density rises inward. Let us take the initial density profile to be $\rho = \rho_c (r/r_c)^{-\alpha}$, where $\alpha > 0$ so the density rises inward. The corresponding enclosed mass is
\begin{equation}
M_r = \frac{4}{3-\alpha}\pi \rho_c r_c^3 \left(\frac{r}{r_c}\right)^{3-\alpha}
\end{equation}

Plugging this in, the collapse time is
\begin{equation}
t = \sqrt{\frac{(3-\alpha)\pi}{32 G \rho_c}} \left(\frac{r_0}{r_c}\right)^{\alpha/2}.
\end{equation}
Since $\alpha>0$, this means that the collapse time increases with initial radius $r_0$. This illustrates one of the most basic features of a collapse, which will continue to hold even in the case where the pressure is non-zero. Collapse of centrally concentrated objects occurs inside-out, meaning that the inner parts collapse before the outer parts.

Within the collapsing region near the star, the density profile also approaches a characteristic shape. If the radius of a given fluid element $r$ is much smaller than its initial radius $r_0$, then its velocity is roughly
\begin{equation}
v \approx v_{\rm ff}\equiv -\sqrt{\frac{2GM_r}{r}},
\end{equation}
where we have defined the free-fall velocity $v_{\rm ff}$ as the characteristic speed achieved by an object collapsing freely onto a mass $M_r$. The mass conservation equation is
\begin{equation}
\frac{\partial M_r}{\partial t} = -v\frac{\partial M_r}{\partial r}  = -4\pi r^2 v \rho
\end{equation}

If we are near the star so that $v\approx v_{\rm ff}$, then this implies that
\begin{equation}
\rho = \frac{(\partial M_r/\partial t) r^{-3/2}}{4\pi\sqrt{2 G M_r}}.
\end{equation}
To the extent that we look at a short interval of time, over which the accretion rate does not change much (so that $\partial M_r /\partial t$ is roughly constant), this implies that the density near the star varies as $\rho\propto r^{-3/2}$.

What sort of accretion rate do we expect from a collapse like this? For a core of mass $M_c = [4/(3-\alpha)]\pi \rho_c r_c^3$, the last mass element arrives at the center at a time
\begin{equation}
t_c = \sqrt{\frac{(3-\alpha)\pi}{32 G \rho_c}} = \sqrt{\frac{3-\alpha}{3}}t_{\rm ff}(\rho_c),
\end{equation}
so the time-averaged accretion rate is
\begin{equation}
\langle\dot{M}\rangle = \sqrt{\frac{3}{3-\alpha}} \frac{M_c}{t_{\rm ff}(\rho_c)}.
\end{equation}

In order to get a sense of the numerical value of this, let us suppose that our collapsing object is a marginally unstable Bonnor-Ebert sphere (see Problem Set 2). Such an object does not have negligible pressure, but the pressure will only change the collapse rate at order unity. Problem Set 2 includes a calculation of the structure of a maximum-mass Bonnor-Ebert sphere, so we will just quote the value. The maximum mass is
\begin{equation}
M_{\rm BE} = 1.18 \frac{c_s^4}{\sqrt{G^3 P_s}},
\end{equation}
where $P_s$ is the pressure at the surface of the sphere and $c_s$ is the thermal sound speed in the core.

Let us suppose that the surface of the core, at radius $r_c$, is in thermal pressure balance with its surroundings. Thus $P_s = \rho_c c_s^2$, so we may rewrite the Bonnor-Ebert mass as
\begin{equation}
M_{\rm BE} = 1.18 \frac{c_s^3}{\sqrt{G^3 \rho_c}}.
\end{equation}
A Bonnor-Ebert sphere does not have a powerlaw structure, but if we substitute into our equation for the accretion rate and say that the factor of $\sqrt{3/(3-\alpha)}$ is a number of order unity, we find that the accretion rate is
\begin{equation}
\langle\dot{M}\rangle \approx \frac{c_s^3/\sqrt{G^3\rho_c}}{1/\sqrt{G\rho_c}} = \frac{c_s^3}{G}.
\end{equation}

This is an extremely useful expression, because we know the sound speed $c_s$ from microphysics. Thus, we have calculated the rough accretion rate we expect to be associated with the collapse of any object that is marginally stable based on thermal pressure support. Plugging in $c_s=0.19$ km s$^{-1}$, we get $\dot{M} \approx 2\times 10^{-6}$ $\msun$ yr$^{-1}$ as the characteristic accretion rate for these objects. Since the typical stellar mass is a few tenths of $\msun$, based on the peak of the IMF, this means that the characteristic star formation time is of order $10^5-10^6$ yr. Of course this conclusion about the accretion rate only applies to collapsing objects that are supported mostly by thermal pressure. Other sources of support produce higher accretion rates, as we will see when we get to massive stars.


\section{Method}
An overview of the method is presented in figure 2. There are three main routines: feature extraction, classification of vegetation, and segmentation of linear objects. In the feature extraction we use the data of the point and its neighbors to get additional information that can help determine to what class a point belongs to. We then use this information to classify which points belong to higher than herb vegetation. These points we subsequently segment into rectangular region, which can be checked for linearity. Details of the various steps which will be described in the following sections.

\begin{figure}[t]
	\centering
	\begin{tikzpicture}[node distance=0.70cm, scale=0.7, every node/.style={transform shape}]

	\node (pro0) [process, fill=darkorange!20] {Point-based feature extraction};
	\node (pro1) [process, right=of pro0, fill=darkorange!20] {Neighborhood-based geometry feature extraction};
	\node (pro2) [process, right=of pro1, fill=darkorange!20] {Neighborhood-based eigenvalue feature extraction};

	\node (param) [title, above=0.4cm of pro1] {Feature extraction};

	\begin{scope}[on background layer]
	\node (fit1) [fit=(pro0)(pro1)(pro2)(param), inner sep=4pt, transform shape=false, draw=black!80, fill=darkorange, fill opacity=0.5] {};
	\end{scope}

	\node (in1) [io, left=of fit1] {Unclassified point cloud};
	\node (out1) [io, below right=0.9cm and 11.7cm=of fit1] {Point cloud with features};

	\node (class) [title, below=1.2cm of pro1] {Vegetation classification};

	\node (pro5) [process, below=0.2cm of class, fill=lightblue!20] {Supervised classification (random forest)};
	\node (pro4) [process, right=of pro5, fill=lightblue!20] {Data trimming};
	\node (in2) [io, below=of pro5] {Manually classified point cloud};
	\node (pro6) [process, left=of pro5, fill=lightblue!20] {Accuracy assessment (cross validation)};

	\begin{scope}[on background layer]
	\node (fit2) [fit=(class)(pro4)(pro5)(pro6), inner sep=4pt, transform shape=false, draw=black!80, fill=lightblue, fill opacity=0.5] {};
	\end{scope}

	\node (out2) [io, below left=4.9cm and 3.7=of fit2] {Classified point cloud};

	\node (lin) [title, below=of in2] {Linear object segmentation};
	\node (pro11) [process, below=0.2cm of lin, fill=turquoise!20] {Clustering (using DBSCAN)};
	\node (pro10) [process, left=of pro11, fill=turquoise!20] {Preprocessing (2D conversion and downsampling)};
	\node (pro12) [process, right=of pro11, fill=turquoise!20] {Region growing (based on rectangularity)};
	\node (pro13) [process, below=of pro10, fill=turquoise!20] {Object merging};
	\node (pro14) [process, right=of pro13, fill=turquoise!20] {Elongatedness assessment};
	\node (pro15) [process, right=of pro14, fill=turquoise!20] {Accuracy assessment};

	\begin{scope}[on background layer]
	\node (fit3) [fit=(lin)(pro10)(pro11)(pro12)(pro13)(pro14)(pro15), inner sep=4pt, transform shape=false, draw=black!80, fill=turquoise, fill opacity=0.5] {};
	\end{scope}

	\node (in3) [io, below=of pro15] {Manually segmented vegetation objects};

	\node (out3) [io, right=of fit3] {Linear vegetation objects};
%	\node (out3) [io, right=3.2cm of pro14] {Linear vegetation objects};

	\draw [arrow] (in1) -- (fit1);
	\draw [arrow] (fit1) -| (out1);
	\draw [arrow] (out1) |- (fit2);
	\draw [arrow] (in2) -- (fit2);

	\draw [arrow] (pro0) -- (pro1);
	\draw [arrow] (pro1) -- (pro2);

	\draw [arrow] (pro4) -- (pro5);
	\draw [arrow] (pro5) -- (pro6);
	\draw [arrow] (pro6) -- (pro5);

	\draw [arrow] (fit2) -| (out2);
	\draw [arrow] (out2) |- (fit3);

	\draw [arrow] (pro10) -- (pro11);
	\draw [arrow] (pro11) -- (pro12);
	\draw [arrow] (pro12.south) -| +(0,-0.3) -| (pro13.north);
	\draw [arrow] (pro13) -- (pro14);
	\draw [arrow] (pro14) -- (pro15);

	\draw [arrow] (in3) -- (in3 |- fit3.south);

	\draw [arrow] (fit3) -- (out3);
%	\draw [arrow] (out3 -| fit3.east) -- (out3);

	\end{tikzpicture}
	\caption{Workflow for feature extraction (orange), classification (blue), and segmentation of linear objects (green), with datasets represented as parallelograms and processes as rectangles.}
	\label{fig:workflow}
\end{figure}

\subsection{Feature extraction}

The relevance of the various input features has extensively been studied to separate urban from vegetation objects \citep{chehata2009airborne, guo2011relevance, mallet2011relevance}, but concise information for vegetation classification is scarce. After reviewing relevant literature, we selected fourteen features (table \ref{tbl:features}). These features are based on information from echo and local neighborhood information (geometric and eigenvalue based) and their qualities are considered to be efficient for discriminating vegetation objects from point clouds \citep{chehata2009airborne}.

\subsubsection{Point-based features}
The point cloud \(\mathcal{P}\) is a set of points \(\{p_{1}, p_{2}, \dots, p_{n}\}\) \(\in \mathbb{R}^3\), where each point \(p_{i}\) has x, y and z coordinates. In addition, an intensity value (\(I\)), a return number (\(R\)), and a number of returns (\(R_{t}\)) of the returned signal are stored. Since we do not have all the data required to do a radiometric correction of the intensity data we omitted this feature for the classification \citep{kashani2015review}. As an additional echo-based feature we calculated a normalized return number (\(R_{n}\)) (table \ref{tbl:features}).

\subsubsection{Neighborhood-based features}
In addition to point-based features, we calculated four geometric features related to local neighborhoods. We defined a neighborhood set \(\mathcal{N}_{i}\) of points \(\{q_{1}, q_{2}, \dots, q_{k}\}\) for each point \(p_{i}\), where \(q_{1} = p_{i}\), by using the k-nearest neighbors method with \(k = 10\) points. This method performs well for datasets that vary in point densities (Weinmann et al., 2014). The four geometric features were: the height difference, the height standard deviation, the local radius and local point density (table \ref{tbl:features}).

We further calculated eigenvalue-based features which are used to describe the distribution of points in a neighborhood \citep{hoppe1992surface, chehata2009airborne}. We used the local structure tensor to estimate the surface normal and to define surface variation \citep{pauly2002efficient}. The structure tensor describes the dominant directions of the neighborhood of a point by determining the covariance matrix of the x, y and z coordinates of the set of neighborhood points and computing the eigenvalues (\(\lambda_{1}, \lambda_{2}, \lambda_{3}\), where \(\lambda_{1} > \lambda_{2} > \lambda_{3}\)) of this matrix and ranking them based on the eigenvalue values. Hence, the magnitude of the eigenvalues of this covariance matrix describe the spread of points in the direction of the eigenvector. The points are linearly distributed if the eigenvalue of the first principle direction is significantly bigger than the other two (\(\lambda_{1} \gg \lambda_{2} \approx \lambda_{3}\)), planarly distributed if the eigenvalues of the first two principle directions are about equal and significantly larger than the third (\(\lambda_{1} \approx \lambda_{2} \gg \lambda_{3}\)), and the points are scattered in all directions if all eigenvalues are about equal (\(\lambda_{1} \approx \lambda_{2} \approx \lambda_{3}\)). These and additional properties are quantified using formulas (table \ref{tbl:features}). The eigenvector belonging to the third eigenvalue is equal to the normal vector (\(\vec{N} = (N_{x}, N_{y}, N_{z})\)) \citep{pauly2002efficient}.

\begin{table}[t]
	\caption{The features used for classification, split into two main groups: point-based and neighborhood-based. The point-based features are based on echo information and the neighborhood-based features are based on the local geometry and eigenvalue characteristics.}
	\label{tbl:features}
	\footnotesize
	\begin{tabular}{l l l l l}
		\toprule
		\textbf{Feature group} & \textbf{Feature} & \textbf{Symbol} & \textbf{Formula} & \textbf{Reference} \\
		\midrule
		\textbf{Point} \\ \\
		- Echo & Number of returns & \(R_{t}\) & \\ \\
		& Normalized return number & \(R_{n}\) & \(R/R_{t}\) & \citet{guo2011relevance} \\ \\
		\textbf{Neighborhood} \\ \\
		- Geometric & Height difference & \(\Delta_{z}\) & \(\max_{j:\mathcal{N}_{i}}(q_{z_{j}}) - \min_{j:\mathcal{N}_{i}}(q_{z_{j}})\) & \cite{weinmann2015semantic} \\ \\
		& Height standard deviation & \(\sigma_{z}\) & \(\sqrt{\frac{1}{k} \sum_{j=1}^k (q_{z_{j}} - \overline{q_{z}})^2}\) & \cite{weinmann2015semantic} \\ \\
		& Local radius & \(r_{l}\) & \(\max_{j: \mathcal{N}_{i}}(|p_{i} - q_{j}|)\) & \cite{weinmann2015semantic} \\ \\
		& Local point density & \(D\) & \(k/(\frac{4}{3} \pi r_{l}^3)\) & \cite{weinmann2015semantic} \\ \\
		- Eigenvalue & Normal vector Z & \(N_{z}\) & & \citet{pauly2002efficient} \\ \\
		& Linearity & \(L_{\lambda}\) & \(\frac{\lambda_{1} - \lambda_{2}}{\lambda_{1}}\) & \citet{west2004context} \\ \\
		& Planarity & \(P_{\lambda}\) & \(\frac{\lambda_{2} - \lambda_{3}}{\lambda_{1}}\) & \citet{west2004context} \\ \\
		& Scatter & \(S_{\lambda}\) & \(\frac{\lambda_{3}}{\lambda_{1}}\) & \citet{west2004context} \\ \\
		& Omnivariance & \(O_{\lambda}\) & \(\sqrt[3]{\lambda_{1} \lambda_{2} \lambda_{3}}\) & \citet{west2004context} \\ \\
		& Eigenentropy & \(E_{\lambda}\) & \(-\lambda_{1}\ln(\lambda_{1}) -\lambda_{2}\ln(\lambda_{2}) -\lambda_{3}\ln(\lambda_{3})\) & \citet{west2004context} \\ \\
		& Sum of eigenvalues & \(\sum_{\lambda}\) & \(\lambda_{1} + \lambda_{2} + \lambda_{3}\) & \cite{mallet2011relevance} \\ \\
		& Curvature & \(C_{\lambda}\) & \(\frac{\lambda_{3}}{\lambda_{1} + \lambda_{2} + \lambda_{3}}\) & \citet{pauly2002efficient} \\ \\
		\bottomrule
	\end{tabular}
\end{table}

\subsection{Vegetation classification}
The fourteen features served as input for the classification of vegetation, which required data trimming, a supervised vegetation classifier and accuracy assessment.

\subsubsection{Data trimming}
To facilitate efficient processing, points that certainly do not belong to higher than herb vegetation were removed from the dataset. These points are characterized by a locally planar neighborhood and are selected on the basis of sphericity feature (table \ref{tbl:features}). In this way, points with a scatter value \(S_{\lambda} < 0.05\) were removed. This threshold was conservative to ensure a large reduction of the data size, while still preserving the higher than herb vegetation points.

\subsubsection{Supervised classification}
A random forest classifier provides a good trade-off between classification accuracy and computational efficiency \citep{breiman2001random, weinmann2015semantic}. The random forest algorithm creates a collection of decision trees, where each tree is based on a random subset of the training data \citep{ho1998random}. Random forest parameters such as the maximum number of features, minimal samples per leaf, minimal samples per split and the ratio between minority and majority samples were optimized using a cross validated grid search. During the grid search a range of applicable values were chosen for each parameter and all combinations were tested and evaluated for performance using cross validation. To save time first a course grid was created to identify the region of best performance and subsequently a finer grid was made to find the best performing parameter set in that region \citep{hsu2003practical}.

The trimmed point cloud is imbalanced, and includes a lot more vegetation than `other' points. Imbalanced training data can lead to undesirable classification results \citep{he2009learning}. Therefore, we used a balanced random forest algorithm. In this algorithm the subsets are created by taking a bootstrap sample from the minority class and a random sample from the majority class with the same sample size as the minority class sample \citep{chen2004using}. By employing enough trees eventually all majority class data are used, while still maintaining a balance between the two classes. The decision trees were created using a Classification and Regression Tree (CART) algorithm \citep{breiman1984classification}. A manual annotation of the trimmed point cloud into `vegetation' and `other' classes was done using an interpretation of the point cloud and high resolution aerial photos.

%The point cloud and high resolution aerial photos  were interpreted and used to manually annotate part of the trimmed 3D point cloud as `vegetation' and `other' classes.

\subsubsection{Accuracy assessment}
The receiver operating characteristic (ROC) curve \citep{bradley1997use}, the Matthew’s correlation coefficient (MCC) \citep{matthews1975comparison} and the geometric mean \citep{kubat1998machine} were used in the accuracy assessment. This allowed to have good performance metrics even when dealing with an imbalanced dataset \citep{kohavi1995study, sun2009classification, lopez2013insight}. To create a ROC curve, the true positive (TP) rate is plotted against the false positive (FP) rate at various decision thresholds. The area under a ROC curve (AUROCC) is a measure for the performance of the classifier \citep{bradley1997use}. The MCC analyzes the correlation between the observed and the predicted data and is defined as:
\begin{equation}
	\label{eq:MCC}
	{\text{MCC}}={\frac{TP\times TN-FP\times FN}{{\sqrt{(TP+FP)(TP+FN)(TN+FP)(TN+FN)}}}}
\end{equation}
where TN are the true negatives and FN the false negatives. The geometric mean is defined as:

\begin{equation}
	\label{eq:geom}
	{\text{Geometric mean}}={\sqrt{\text{producer's accuracy class 1} \times \text{producer's accuracy class 2}}}
\end{equation}

The MCC, AUROCC and the geometric mean were obtained using a 10-fold cross validation. This is done by splitting the data into 10 randomly mutually exclusive subsets and using a subset as testing data and a classifier trained on the remaining data \citep{kohavi1995study}.

\subsection{Linear object segmentation}
To segment the vegetation points into linear regions we did a preprocessing step, clustered the points using a DBSCAN, applied a region growing algorithm, merged nearby and aligned objects, evaluated their elongatedness and assessed the accuracy.

\subsubsection{Preprocessing}
The point cloud was converted to 2D by removing the z-coordinate of the vegetation points. In addition, the data were spatially downsampled to 1 meter distance between vegetation points. This substantially decreased computation time without losing too much precision (figure \ref{fig:downsampling}).

\begin{figure}
	\centering
	\includegraphics[scale=0.80]{./img/downsampling.pdf}
	\caption{The vegetation points of a piece of tree line within the research area before (blue) and after (red) downsampling the point cloud, plotted on top of the high resolution orthophoto, in RD coordinates.}
	\label{fig:downsampling}
\end{figure}

\subsubsection{Clustering}
After reducing the amount of points we clustered the remaining points together using a DBSCAN clustering algorithm \citep{ester1996density}. This algorithm is able to quickly cluster points together based on density and removes outlying points in the process. This decreases the processing time needed in the subsequent region growing step, since the amount of possible neighboring points is reduced.

\subsubsection{Region growing}
Region growing is an accepted way of decomposing point clouds \citep{rabbani2006segmentation, vosselman2013point} or raster imagery \citep{blaschke2014geographic} into homogeneous objects. Normally, seed locations are selected and regions are grown based on proximity and similarity of the attributes of the points. In our method, seed selection was based on the coordinates and regions were grown based on proximity and a rectangularity constraint. The proximity is constrained by taking the eight nearest neighbors of each point during the growing process. The rectangularity of an object is described as the ratio between the area of an object and the area of its minimum bounding rectangle (Rosin, 1999). The minimum bounding rectangle (figure \ref{fig:hulls}b) is computed with rotating calipers \citep{toussaint1983solving}. First a convex hull is constructed (figure \ref{fig:hulls}a) by using the QuickHull algorithm \citep{preparata1985computational}. The minimum bounding rectangle has a side collinear with one of the edges of the convex hull \citep{freeman1975determining}. Hence the minimum bounding rectangle can be found by rotating the system by the angle the edges of the convex hull make with the x-axis and checking the bounding rectangles of each rotation. The area of the object can be calculated by computing the concave hull of the set of points belonging to the object (figure \ref{fig:hulls}c). For this we use a concave hull algorithm using a \(k\)-nearest neighbors approach \citep{moreira2007concave}. This algorithm starts with finding a point with a minimum or maximum of one of the coordinates. Subsequently it goes around the points by repeatably finding the neighbor which makes an edge that makes the largest counterclockwise angle with the previous edge. This process is continued until the current point is the starting point. % Finally a check is done to ensure all the points fall within the hull. If this is not the case the \(k\) is increased by 1 and the algorithm repeated until an acceptable concave hull has been found.

In this way, for each cluster, points with the minimum x-coordinate and its 20 closest neighbors were used as the starting region. Subsequent points were added as long as the region’s rectangularity did not drop below a set threshold of 0.55 (figure \ref{fig:regiongrowing}). Then, the growing procedure was repeated for the next region until the entire cluster is segmented into rectangular regions.

%\begin{figure}
%	\centering
%	\includegraphics[scale=0.50]{./img/hulls.pdf}
%	\caption{The vegetation points of a piece of tree line within the research area are plotted on top of the high resolution orthophoto, showing the effect of downsampling the point cloud (a) and the different hulls used during the region growing algorithm: the convex hull (b), the minimal oriented bounding box (c), and the concave hull (d). During the region growing the rectangularity is calculated by dividing the area of the concave hull (d) by the area of the bounding box (c).}
%\end{figure}

\begin{figure}
	\centering
	\includegraphics[width=\columnwidth]{./img/hulls.pdf}
	\caption{The downsampled vegetation points of a piece of tree line within the research area  plotted on top of the high resolution orthophoto in RD coordinates, showing the different hulls used during the region growing algorithm: the convex hull (a), the minimal oriented bounding box (b), and the concave hull (c). During the region growing the rectangularity is calculated by dividing the area of the concave hull (c) by the area of the bounding box (b).}
	\label{fig:hulls}
\end{figure}

\begin{figure}
	\centering
	\includegraphics[width=\columnwidth]{./img/region_growing.pdf}
	\caption{An example of the region growing process for one point. First the eight nearest neighbors are computed and the neighbors which are not already part of the region are considered to be added to the region (a). A bounding box and concave hull is computed for the region with the considered point added and the rectangularity is calculated (b). If this rectangularity is above a certain threshold the point is added to the region. Subsequently the process is repeated for the other points to consider (c, d). When all points to consider are checked, a next point of the region is check for nearest neighbors and the whole process is repeated until all points of the region, including the ones which are added during the growing process, have been checked once.}
	\label{fig:regiongrowing}
\end{figure}

\subsubsection{Object merging}
The resulting objects can be fragmented as the result of minor curves in the linear vegetation or small interruptions in vegetation. These objects were merged when they were in close proximity, faced a similar compass direction, and were aligned. The compass direction was determined by computing the angle between one of the long sides of the minimum bounding box and the x-axis. The alignment was checked by comparing the angle of the line between the two center points with the directions of the objects. Once merged the lengths of the objects were added and the maximum of the widths taken as the new width.

\subsubsection{Elongatedness}
The merged objects were assessed for linearity by resolving the elongatedness of an object, which is defined as the ratio between its length and its width \citep{nagao2013structural}. The definition of a linear object is not clearly defined and consequently somewhat arbitrary. After trial and error, we set the minimum elongatedness at 2.5 and, to exclude long and wide patches from the resulting linear objects, a maximum width of 60 meters.

\subsubsection{Accuracy assessment}
The accuracy of the delineated linear objects was assessed by calculating the user’s, producer’s and overall accuracy, as well as the harmonic mean of the precision and recall (F1), kappa and MCC scores \citep{congalton2008assessing}. We manually annotated the vegetation data into linear and nonlinear objects, after converting the classified vegetation points into polygons. Consequently this assessment evaluates the accuracy of the segmentation given the accuracy of the vegetation points. Differencing of the automated and manually constructed data resulted in confusion matrices to compare true positives, true negatives, false positives and false negatives in the area.


\documentclass[main.tex]{subfiles}
\begin{document}

\section*{Mon Oct 14 2019}

% Summary of past lectures: we discussed:

% \begin{enumerate}
%     \item the different time scales of stellar evolution, and their impact on the adiabatic approximation;
%     \item easy approximations for stellar pulsation;
%     \item acoustic approximations;
%     \item Ritter's relation;
%     \item linearized structure equations: the adiabatic approximation (arguments for it!), deriving the LAWE;
%     \item examples of solutions to the LAWE and stability conditions;
%     \item the LNAWE: today.
% \end{enumerate}

\subsection{The LNAWE}

First of all, let us recall the linearized equations of stellar structure:
%
\boxalign{
\begin{subequations}
\begin{align}
\frac{ \delta \rho }{\rho } &= - 3 \zeta - 4 \pi r^3 \rho \pdv{\zeta }{m}  \label{eq:linearized-cont}\\
r \ddot{\zeta} &= - 4 \pi r^2 \qty[\qty(4 \zeta + \frac{ \delta P}{P})\pdv{P}{m} + P \pdv{}{m} \qty(\frac{ \delta P}{P})]  \label{eq:linearized-mom}\\
\pdv{}{t} \qty(\frac{ \delta P}{P}) &= \Gamma_1 \pdv{}{t} \qty(\frac{ \delta \rho }{\rho }) + \frac{\rho }{P} \qty(\Gamma_3 - 1) \delta \qty(\epsilon_{\text{eff}} - \pdv{L}{m})  \label{eq:linearized-E1}\\
\pdv{}{t} \qty(\frac{ \delta T}{T}) &= \qty(\Gamma_3-1) \pdv{}{t} \qty(\frac{ \delta \rho }{\rho }) + \frac{1}{c_V T} \delta \qty(\epsilon_{\text{eff}} - \pdv{L}{m})  \label{eq:linearized-E2}\\
\frac{ \delta L}{L} &= 4 \zeta - n \frac{ \delta \rho }{\rho } + (s+4) \frac{ \delta T}{T} + \qty(\pdv{\log T}{m})^{-1} \pdv{}{m} \qty(\frac{ \delta T}{T}) \label{eq:linearized-RT}
\,,
\end{align}
\end{subequations}}

%
using which we can derive after long manipulations the Linear Non-Adiabatic Wave Equation, which in its Lagrangian formulation reads:
%
\begin{align}
\dot{\ddot{\zeta}}
=
4 \pi r \qty(\dot{z} \pdv{}{m} \qty((3 \Gamma_1 - 4)P)
-  \pdv{}{m} \qty(\rho (\Gamma_3 - 1) \delta \qty(\dv{Q}{t})))
+ \frac{1}{r^2} \pdv{}{m} \qty(16 \pi^2 \Gamma_1 P \rho r^{6} \pdv{\dot{\zeta}}{m})
\,,
\end{align}
%
where we used the fact that \(\dv*{Q}{t} = \epsilon _{\text{eff}} - \pdv*{L}{m}\). On the other hand, the Eulerian formulation is
%
\begin{align}
\dot{\ddot{\zeta}} = \frac{1}{r \rho } \qty(\dot{\zeta}\pdv{}{r} \qty((3\Gamma_1 -4) P ) - \pdv{}{r} \qty(\rho (\Gamma_3 -1) \delta \qty(\dv{Q}{t})))
+ \frac{1}{r^4 \rho}\pdv{}{r}\qty(r^{4} \Gamma_1 P \pdv{\dot{\zeta}}{r})
\,.
\end{align}

\begin{bluebox}
The procedure to derive the LNAWE is as follows:
\begin{enumerate}
  \item substitute the continuity equation \eqref{eq:linearized-cont} into the \(P, \rho \) form of the energy conservation equation \eqref{eq:linearized-E1};
  \item substitute the \(P, \rho \) form of the energy conservation equation \eqref{eq:linearized-E1} into the time derivative of the Eulerian form of the momentum conservation equation \eqref{eq:linearized-mom};
  \item simplify.
\end{enumerate}
\end{bluebox}

\subsection{Solving the LNAWE}

Our ansatz for the LNAWE will still be of the form \(\zeta (r, t) = \eta (r) e^{i \sigma t}\), but now we insert \(\sigma = \omega + i \kappa \): this means we also consider \emph{damped} exponential solutions and \emph{diverging} exponential solutions.
We want to simplify the exponentials, so we must assume that
%
\begin{align}
\delta \qty(\dv{Q}{t}) = \delta \qty(\dv{Q}{t}) _{\text{sp}} e^{i \sigma t}
\,.
\end{align}

\todo[inline]{Why do we assume that the heat derivative perturbation is \emph{in phase} with the displacement? Maybe we do not, and the \(_{\text{sp}}\) heat variation is complex?}

With this substitution we get:
%
\begin{align}
- i \sigma^3 \eta = \frac{i \sigma \eta }{r \rho }
\pdv{}{r} \qty((3 \Gamma_1 -4)P) - \frac{1}{r \rho }
\pdv{}{r} \qty(\rho (\Gamma_3 -1) \delta \qty(\pdv{Q}{t})_{\text{sp}})
+ \frac{i \sigma}{r^{4} \rho } \pdv{}{r} \qty(r^{4} \Gamma_1 P \pdv{\eta }{r})
\,.
\end{align}

The time scales for these parameters are \(\omega \sim \omega _{\text{ad}} \sim \tau _{\text{dyn}}\), while \(\kappa \sim 1/ \tau _{\text{th}}\): therefore \(\omega \gg \abs{\kappa } \).

Using this result, we can make some useful \emph{quasi-adiabatic} approximations: in the LNAWE we will identify the LAWE operator \(\mathcal{L}\), and replace its application to the wavefunction with the corrisponding eigenvalue. Basically, we will consider the thermal contribution to be small and work ``to first order'' with  it.
%
\begin{subequations}
\begin{align}
\begin{split}
- i \sigma^3 \eta  &=
-i \sigma \qty(- \frac{1}{r \rho } \pdv{}{r} \qty((3\Gamma_1 -4) P) - \frac{1}{r^{4} \rho } \pdv{}{r} r^{4} \Gamma_1 P \pdv{\eta }{r}) + \\
&\phantom{=}\
 - \frac{1}{r \rho } \pdv{}{r}
\qty(\rho (\Gamma_3 -1) \delta \qty(\pdv{Q}{t})_{\text{sp}})
\end{split}
\\
- i \sigma^3 \eta &=
- i \sigma \mathcal{L}(\eta )
- \frac{1}{r \rho } \pdv{}{r}
\qty(\rho (\Gamma_3 -1) \delta \qty(\pdv{Q}{t})_{\text{sp}}) \\
\mathcal{L}(\eta ) - \sigma^2 \eta &=
\frac{i}{r \sigma  \rho } \pdv{}{r}
\qty(\rho (\Gamma_3 -1) \delta \qty(\pdv{Q}{t})_{\text{sp}})
\,,
\end{align}
\end{subequations}
%
so we can see that the eigenvalue of the LAWE operator cannot be \(\sigma^2\) now. We take this equation, multiply it by \(\eta r^2\) and integrate it over the whole star in \(\dd{m}\): we get
%
\begin{align}
i \sigma^3 \int \eta^2r^2 \dd{m}
- i \sigma \int \eta \mathcal{L}(\eta) r^2 \dd{m}
= \int \frac{r}{\rho } \pdv{}{r} \qty(\rho (\Gamma_3 -1) \delta \qty(\pdv{Q}{r}) _{\text{sp}}) \eta \dd{m}
\overset{\text{def}}{=} C
\,,
\end{align}
%
where we defined the \emph{work integral} \(C\).
We only look at the first order terms in \(\kappa \): so we make the approximation \(i \sigma^3 \approx \omega^2 \qty(i \omega - 3 \kappa )\), while (to first order, but also exactly) \(i \sigma = i \omega - \kappa \). We substitute these two, and then make the key manipulation: we substitute \(\mathcal{L}(\eta )\) with \(\omega^2 \eta \).
The only thing missing is the definition: \(J \overset{\text{def}}{=} \int \eta^2 r^2 \dd{m}\).
So we get
%
\begin{subequations}
\begin{align}
\omega^2 \qty(i \omega - 3 \kappa ) J
- (i \omega - \kappa ) \omega^2 J &= C \\
- 3 \kappa + \kappa &= \frac{C}{J \omega^2} \\
\kappa &= - \frac{C}{2 \omega^2 J }
\,.
\end{align}
\end{subequations}

Now we make some considerations on the expression of \(C\) and integrate by parts, getting:
%
\begin{subequations}
\begin{align}
C &= \int_{M} \frac{1}{r \rho } \pdv{}{r} \qty(\rho(\Gamma_3 -1) \delta \qty(\dv{Q}{t})_{\text{sp}}) \eta r^2 \dd{m}  \\
&= \int_{R} \pdv{}{r}  \qty(\rho(\Gamma_3 -1) \delta \qty(\dv{Q}{t})_{\text{sp}})
4 \pi r^3 \eta  \dd{r}
\marginnote{\(\dd{m} = 4 \pi r^2\rho \dd{r}\)} \\
&=  \eval{\rho (\Gamma_3 -1) \delta \qty(\dv{Q}{t})_{\text{sp}}
4 \pi r^3\eta }_{r=0}^{r=R}
- \int_{R} \rho (\Gamma_3 -1) \delta \qty(\dv{Q}{t})_{\text{sp}} \pdv{}{r} \qty(4 \pi r^3 \eta ) \dd{r}
\\
&= - \int_{R} \rho (\Gamma_3 -1) \delta \qty(\dv{Q}{t})_{\text{sp}} 4 \pi r^2 \qty(3 \eta + r \pdv{\eta }{r}) \dd{r} \marginnote{\(\rho =0\) if \(r=R\)}
\\
&= \int_{R} \rho (\Gamma_3 -1) \delta \qty(\dv{Q}{t})_{\text{sp}} 4 \pi r^2 \qty(\frac{ \delta \rho }{\rho})_{\text{sp}}
\dd{r}
\marginnote{From equation \eqref{eq:linearized-cont}: \(\frac{ \delta \rho }{\rho } = -3\zeta - r \pdv{\zeta }{r}\)}
\\
&= \int_{R} (\Gamma_3 -1) \qty(\frac{ \delta \rho }{\rho })_{\text{sp}} \delta \qty(\dv{Q}{t})_{\text{sp}}
 \dd{m}
\\
&= \int_M \qty(\frac{\delta T}{T})_{\text{sp}} \delta \qty(\epsilon _{\text{eff}}- \pdv{L}{m} ) \dd{m}
\marginnote{From the time-integrated equation \eqref{eq:linearized-E2}, neglecting the heat transfer term}
\,,
\end{align}
\end{subequations}
%
and now this expression allows us to study the mechanisms which create perturbations: the coefficient to calculate is \(\kappa \), which we now know to be given by
%
\begin{align} \label{eq:kappa-driven-oscillations}
\kappa = - \frac{1}{2 \omega^2 J}
\int_M \qty(\frac{\delta T}{T})_{\text{sp}} \delta \qty(\epsilon _{\text{eff}}- \pdv{L}{m} ) \dd{m}
\,,
\end{align}
%
which we will study in the next section.

\subsection{Driving mechanisms}

The energy of the vibrations comes from the internal thermal energy of the star, which ultimately comes from thermonuclear reactions. We can rewrite equation \eqref{eq:kappa-driven-oscillations} as
%
\begin{align} \label{eq:kappa-driving-mechanisms}
\kappa = - \frac{1}{2 \omega^2 J} \underbrace{\int_{M} \qty(\frac{ \delta T}{T})_{\text{sp}} \delta \epsilon _{\text{eff}} \dd{m}}_{\text{energy generation}}
+ \frac{1}{2 \omega^2J} \underbrace{\int_{M} \qty(\frac{ \delta T}{T})_{\text{sp}}
\pdv{ \delta L}{m} \dd{m}}_{\text{energy transfer}}
\,.
\end{align}

The \(\epsilon \)-mechanism is about energy generation, which is assumed to be due to nuclear reactions, without considering neutrino processes:
this can happen if the magnitude of the temperature and density perturbations are large enough.

The \(\kappa \)-\(\gamma \)-mechanism is about considering the regions where the luminosity gradient and temperature gradient are discordant.
This means that the considered stellar layer is absorbing or emitting; this is usually assumed to be happening through free-free interactions (bremsstrahlung and inverse bremsstrahlung).

\end{document}


\chapter{Introduction}
\label{chpr:intro}
Associate dates with events is the essential medium to write history.
In the distant past it was appanage of a restricted elite of powerful individuals, with the evolution and progress of society, the amount of people able to write their own history has increased.
This lead to the emergence of different versions: not a crucial concern because, as for several human constructions, history can be a distortion of reality.
Converge to a single version is a tough matter, yet it is grounded into the ability of everyone to write their own history.
Precluding some individuals from the ability to state and record their viewpoint does compromise the natural interaction between history and reality.
In this work we focus on the primary obstacle: the ability of recording arbitrary events.

Using proper semantics, an event is mapped into data, which are then embedded in an item suitable for storing and sharing, finally on the resulting object a date is attached.
Each step can be performed in a variety of manners and has its own optimal choices to fulfil the given requirements.
In this work we assume the meaning of the data is given and we refer to the procedure of binding a date to data as timestamping.
We focus on weaknesses and strengths of every choice, starting from physical to digital timestamping, with particular emphasis on the trust issue.
If a third party is placing the date on the item containing the data, it may behave maliciously, e.g. compromising the data or setting a wrong date. This issue can be addressed using distributed consensus technologies, like Bitcoin, allowing anyone to write his own version of the events: oppressed people have the possibility to record what they witness even in hostile environments, reducing powers and responsibilities of central authorities.

How to make this approach viable and accessible on large scale presents tough technical steps, resulting in best practices \cite{OTSWeb} that have been used to define an open protocol standard. This protocol has emerged as the first (along with very few others) non-financial blockchain-related working application \cite{ESMAresponse}.

Our contribution starts with a deep investigation of an improvement proposal \cite{PoePR, PoeIs} to the standard that allows the inclusion of a timestamp inside a regular bitcoin transaction without increasing its size and hence its cost.
We aim to provide guidelines to properly understand what is behind this technique and the implications it carries.
Finally we present a practical implementation of this new feature we have developed as integration inside a popular bitcoin open source wallet: users can create timestamps within transactions with no additional charge.

\section{Structure}
In this work we aim to describe exhaustively foundations, benefits and issues of arising from the new proposed technique.
It requires to traverse different subjects, mainly cryptography, computer science and distributed systems.
In this section we outline the path we are going to undertake.

In Chapter \ref{chpr:timestamping} we define what a timestamp is and we exploit the essential characteristics of its components: operations and attestations.

In Chapter \ref{chpr:trustless}, after a brief introduction on Bitcoin, we show how it can be used to achieve digital timestamping without relying on trusted third parties.

In Chapter \ref{chpr:state-of-art}, we show the state of the art of trustless digital timestamping, with the open source project OpenTimestamps.
We provide a description of the standard it defines and the solution to address scalability issues.

In Chapter \ref{chpr:ec-commitments} we plunge into the core of the work, analysing the technique of elliptic curve commitment, with main focus on timestamping applications, particularly \textit{sign-to-contract}.

In Chapter \ref{chpr:s2c} we highlight the practical implications of \textit{sign-to-contract}, both benefits and issues. Finally we show a plugin for a popular open source wallet that implements the technique described.

To conclude, in Chapter \ref{chpr:conclusions}, we summarize what has been discussed and draw attention to which future works can start from the point reached.


% !TeX encoding = UTF-8
% !TeX program = lualatex
% !TeX spellcheck = en_US
% !TeX root = thesis.tex

\chapter{Computational Fluid Dynamics}
\label{chap:CFD}
\index{CFD}
%\todo{This should be $\leq$ 10 pages;work in progress}

This chapter aims to provide a concise introduction to \gls{CFD}.
The main focus are the governing equations of \CFD\ and the assumptions and approximations needed to model natural ventilation.
This chapter does not attempt to cover numerical methods in great detail\textemdash for further information, refer to the relevant literature \citep{Wilcox2006, Etheridge2012, Nielsen2007, Ferziger}.

\Fref{fig:schema_cfd} illustrates the usual work-flow necessary to solve \gls{CFD} problems.
The work-flow can be summarized in 3 parts, namely (1) pre-processing, (2) numerical simulation and (3) post-processing:

\begin{enumerate}

\item Pre-processing entails the real-world problem definition, which has to be simplified as far as possible to be sufficiently captured by the physical and mathematical model. Once this is done, the \gls{CAD} geometry has to be meshed appropriately (discretization) into a finite number of discrete regions, called cells. Where high pressure gradients are expected, the mesh should be appropriately refined to capture important flow features. This work-flow is illustrated in  \fref{fig:cadboundary}.

\begin{sidefigure}[2][htb]
	\centering
	\includegraphics[width=0.6\linewidth, trim= 0cm 1cm 1cm 0, clip]{images/CAD_boundary}
	\captionsetup{format=plain,labelsep=newline}
	\caption[Relation between \gls{CAD} geometry, computational grid and boundary conditions]{Illustration of the relation between a \gls{CAD} geometry, the computational grid and its boundaries, and the boundary conditions applied. Adapted from \citep{Maric2014}.}
	\label{fig:cadboundary}
\end{sidefigure}

\item Before the simulation starts, physically appropriate boundary conditions as well as numerical settings have to be specified. The simulation eventually solves the algebraic set of equations by a solver that is tailored to capture the physical problem. The simulation ends after the simulation has reached either the final number of iterations or the specified convergence criteria.

\item Finally, the variables of interest need to be post-processed by visualizing the fluid flow with appropriate plots or further calculations. This should be supplemented by a verification/validation study in which the simulation is compared against measured values. An error estimation and sensibility analysis is needed to finally discuss the results. \CFD\ studies are usually of an iterative nature, which means the conclusions drawn will influence the pre-processing of the following simulation. This will procedure will be repeated until results are compliant with verification \& validation guidelines.

\end{enumerate}

\begin{figure}[htb]
	\includegraphics[width=1\linewidth, trim=1.1cm 0cm 1.1cm 0, clip]{images/cfd_schematic}
	\caption[Work-flow schematic for \CFD]{Work-flow schematic for \CFD. Adapted from \citep{Giglmaier2016}.}
	\label{fig:schema_cfd}
\end{figure}

%
% %
% % %
% % % %
% % %
% %
%

\clearpage
\section{Governing equations}
\label{sec:CFD:governing_equations}
\index{CFD!governing equations}

The \glsplural{NSE} describe the conservation of (1) mass , (2) momentum  and (3) energy.
The \glsplural{NSE} are derived from (1) the continuity equation, (2) Newton's second law and (3) the first law of thermodynamics.
These equations treat the flow as a continuum and can be solved analytically only for several specific cases.
It is, however, possible to discretize the equations and solve them with regard to time and space.
The following notations $u$, $\bar{u}$, $u^{\prime}$ denote the instantaneous, mean, and fluctuating terms, respectively.

The continuity equation, also referred to as mass balance, is defined as:

\begin{equation}
\frac{\delta }{\delta t}\rho +\nabla (\rho \vec{u})= 0
\label{eq:theory:continuity}
\end{equation}

For a steady flow through a control volume, this equation shows that the net mass flux in the control volume must be zero.
The equation for linear momentum conservation, also know as the \gls{NSE} in its non-conservative form, is defined as:

\begin{equation}
\rho\left[\frac{\delta \vec{u}}{\delta t}+(\vec{u}\cdot\nabla)\vec{u} \right ]=-\nabla p + \nabla \bar{\bar{\tau}}+\rho \vec{f}
\label{eq:theory:momentum_conservation}
\end{equation}

where $\vec{f}$ is the body force per unit mass. If the weight of the fluid happens to be the only force present, $\vec{f}$ may be replaced with the gravitational vector $\vec{g}$.
$\bar{\bar{\tau}}$ is the symmetrical viscous stress tensor. For Newtonian fluids it is defined as:

\begin{equation}
\tau_{ij} = \mu \left(\frac{\delta u_i}{\delta x_j} +\frac{\delta u_j}{\delta x_i}\right )-\frac{2}{3} (\nabla \vec{u})\delta_{ij} ,\quad i,j = 1,2,3
\label{eq:CFD:stress_tensor}
\end{equation}

where $\delta_{ij}$ is the Kronecker-Delta operator, and \gls{symb:mu} is the \glsdesc{symb:mu} \citep{Sert2012}.

\paragraph*{Incompressible flows}
\index{CFD!incompressible flows}

For incompressible flows, density is defined as a constant, which leads to a simplified set of equations. Consequently,  \fref{eq:theory:continuity} reduces to:

\begin{equation}
\nabla \vec{u} = 0
\label{eq:CFD:continuity_imcompressible}
\end{equation}

\Fref{eq:CFD:continuity_imcompressible} states that the velocity field for incompressible flows is divergence-free. For the conservation of momentum, using \fref{eq:CFD:continuity_imcompressible} in  \fref{eq:CFD:stress_tensor}  cancels the second term in the stress tensor. Moreover, if viscous effects are negligible, \fref{eq:theory:momentum_conservation} simplifies to:

\begin{equation}
\rho\left[\frac{\delta \vec{u}}{\delta t}+(\vec{u}\cdot\nabla)\vec{u} \right ]=-\nabla p + \mu \nabla^2 \vec{u} +\rho \vec{f}
\label{eq:Navier_incompressible}
\end{equation}

\glsdesc{symb:mu} and \glsdesc{symb:nu} are related by the density.

\begin{equation}
\nu= \frac{\mu}{\rho}
\end{equation}

Thus, if we normalize \fref{eq:Navier_incompressible} by the density, we obtain the form of the \gls{NSE} that is commonly referred to when using this method.

\begin{equation}
\frac{\delta \vec{u}}{\delta t}+\underbrace{(\vec{u}\cdot\nabla)\vec{u}}_{\text{convective term}} =-\frac{1}{\rho}\nabla p + \underbrace{\nu \nabla^2 \vec{u}}_{\text{diffusion term}}+\vec{f}
\end{equation}

\gls{symb:nu} is the \glsdesc{symb:nu}, which is considered to be constant.

In a 3-dimensional space, this yields \num{4} equations with \num{4} unknowns, namely the pressure and \num{3} velocity components.

%\section{Finite volume method}

The process of representing differential equations as a set of algebraic equations with equivalent properties is called discretization. In OpenFOAM, this is done with an approach called \gls{FVM}. This is necessary to solve the equations numerically.
After setting the appropriate \BC, it can be expressed in a linear equation system of the form:

\begin{equation}
\underline{A}\, \vec{x} = \vec{b}
\end{equation}

where $\vec{x}$ is the vector of the variable of interest, $\underline{A}$ is the square matrix and $\vec{b}$ is the source vector \citep{Sert2012}.

%
% %
% % %
% % % %
% % %
% %
%


\documentclass[10pt,leqno]{amsart}

% Les packages
\usepackage{amssymb,amsbsy}
\usepackage{mathrsfs}
\usepackage{color}
\usepackage{soul}
\usepackage{graphicx}
\usepackage{booktabs}
%\setlength{\heavyrulewidth}{1.5pt}
%\setlength{\abovetopsep}{4pt}
\usepackage[pdfborder={0 0 0}]{hyperref}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\setlength{\parskip}{3pt} % 1ex plus 0.5ex minus 0.2ex}
%\setlength{\parindent}{15pt}

% La profondeur de la table des matieres
\setcounter{tocdepth}{1}

% Les principaux ensembles
\newcommand{\Abs}[1]{\left\lvert#1\right\rvert}
\newcommand\N{{\mathbb N}}
\newcommand\R{{\mathbb R}}
\newcommand\T{{\mathbb T}}
\newcommand\C{{\mathbb C}}
\newcommand\Q{{\mathbb Q}}
\newcommand\Z{{\mathbb Z}}
\newcommand\Pp{{\mathbb P}}
\newcommand\Ee{{\mathbb E}}
\def\x{{\mathbf x}}
\def\w{{\mathbf w}}
\def\xxi{{\pmb \xi}}

% Quelques definitions raccourcis pour les calculs
\DeclareMathOperator{\diver}{div}
\DeclareMathOperator{\Supp}{Supp}
\newcommand{\dbm}{\mathbf{d}}
\def\esssup{\mathop{\rm ess\,sup\,}}
\def\essinf{\mathop{\rm ess\,inf\,}}
\newcommand{\indiq}{{\bf 1}}

% Les defs, theo, et equations
\newtheorem{theo}{Theorem}
\newtheorem{prop}[theo]{Proposition}
\newtheorem{lem}[theo]{Lemma}
\newtheorem{cor}[theo]{Corollary}
\newtheorem{rem}[theo]{Remark}
\newtheorem{rems}[theo]{Remarks}
\newtheorem{defin}[theo]{Definition}
\newtheorem{ex}[theo]{Example}
\newtheorem{notation}[theo]{Notations}
\renewcommand{\theequation}{\thesection.\arabic{equation}}
\renewcommand{\thetheo}{\thesection.\arabic{theo}}

\newcommand{\PM}[1]{\textcolor{red}{#1}}
\newcommand{\CQ}[1]{\textcolor{blue}{#1}}

%%%%%%%%%%      Document     %%%%%%%%%%%%%%%

\begin{document}

\title[]{Machine learning for Social Ideology Recognition: An Experimental Case Study.}

\author{H. Bahamondes \and C. Quininao}

\begin{abstract}

\end{abstract}

\maketitle

\begin{center} {\bf Preliminary version of \today}
\end{center}

\bigskip
\textbf{Keywords}: Vote Selling - Machine Learning

\vspace{0.3cm}
\bigskip

\tableofcontents

\section{Materials and methods}

The overall model training and validation process consists in a three phases. First we clean the database by eliminating repeated observations, and we normalize using a MinMax scaler. We perform two different experiments, first we use machine learning algorithms to classify participants as vary liberals or not, and later we do the same for very conservative. Since our resulting training pairs datasets are strongly imbalanced, prior to the construction of learning models, we use the SMOTE~\cite{chawla2002smote} oversampling procedure with five nearest neighbors for each vote-selling sample~\cite{artetxe2020balanced}. The resulting training data pairs is then used for validation in a repeated cross-validation (RCV) process. This process consists in construct several machine learning models by using the same dataset but under the idea of generate folds and repetition. In particular, each cross-validation repetition consists in: partitioning the dataset in a particular number of folds, using each fold as a test dataset while using all remaining data for model training. Finally, we report average performance measures across all repetitions. In this manuscript, the reported results are the average of the 30 repetitions of the CV models.

\subsection{Classification Methods}

Several machine learning approaches can be used for analyze the present data, in a predictive model framework~\cite{vapnik2013nature,witten2002data,maimon2005data}. Due to the nature of the experiment and the data, and since we do not have a large dataset, we discard the application of deep learning algorithms~\cite{balas2019handbook}. Therefore, we focus in the following classical well-known methods: \textit{Support Vector Machines, Multilayer Perceptron and Na\"ive Bayes method.}

\subsubsection{Support Vector Machines (SVM)} As stated in~\cite[Chapter 12]{maimon2005data}, support vector machines (SVMs) are a set of related methods for supervised learning, which has applications to classification (the output data is a sequence of tags) and regression (the output data is a continuous variable) problems. When using SVM for the classifying problem, we look for linear functions that can separate the data based on the support vectors or boundaries of the classes. The idea of the algorithm is to find the optimal hyperplane, i.e., the hyperplane that maximizes the distance to the boundaries of each class. This can be done by stating a quadratic programming problem~\cite{vapnik2013nature}. When the classes are not linearly separable, then it is possible place the data into a space of superior dimensionality using a kernel trick~\cite{vapnik2013nature,maimon2005data}, so that the transformed dataset might become linearly separable. We used the SVM module from Python Sklearn library for training and estimation. We try linear and Radial Bases Function (RBF).

\subsubsection{Multilayer Perceptron} Multilayer perceptron (MLP) is the classical feed-forward artificial neural networks (ANN) composed of multiple densely interconnected layers of computational units, aka artificial neurons~\cite{wolff2019machine}. It corresponds to a supervised learning algorithm that finds a function that maps our multidimensional samples (socio demographic data) into the vote-selling response of the experimental participants. Any MLP is constructed as follows: (i) we fix a number of hidden layers, (ii) the architecture starts with $m$ artificial neurons corresponding to the features of the input data corresponding to the input layer, (iii) any artificial neuron in the first hidden layer integrates the inputs from the input layer and combines the input values with a weighted linear summation (the weights become part of the parameters to be tuned in the learning phase), (iv) the result of this summation is nonlinearly transformed through an activation function (for instance an hyperbolic $\tanh$ function). The procedure is repeated for each hidden layer, until the output layer is reached. The connection weights can be learned from data applying the back-propagation algorithm~\cite{haykin2004comprehensive}. Concerning the implementation of the MLP, we used the MLPClassifier module from Python Sklearn library for training and estimation. The MLPClassifier implements a MLP algorithm that trains using back-propagation through a stochastic gradient descent. We used the rectified linear unit function for the activation of the hidden layers. The MLP model constructed has two hidden layer, each of 50 neurons.

\subsubsection{Na\"ive Bayes Method} Na\"ive Bayes methods are a set of supervised learning algorithms based on applying Bayes’ theorem with the ``naive'' assumption that all features of an individual are independent. Bayes’ theorem provides a rule to calculate the conditional probability of an event given some knowledge, in terms of the conditional probability of the knowledge given the event. This idea along with the naive independent assumption allows the model to estimate the joint probability distribution of a  feature vector as the product of the unidimensional distribution probabilities of each feature~\cite{wolff2019machine}. In our study we use the GaussianNB module from Sklearn library, which implements the Gaussian Naive Bayes algorithm for classification. The likelihood of the features is assumed to be Gaussian.

\subsection{Classification Performance Metrics} We illustrate the chosen metrics with only liberal classification machines, the conservative situation is straightforward. At the end of each cross-validation fold we have two different vectors: $y_{test}$ corresponding to the responses of the participants to the very liberal question restricted to the fold used for testing, and $y_{pred}$ corresponding to the predicted answers given by the model for the input features. With these two vectors at hand we compute the
\begin{itemize}
\item True positive counts (tp): number of participants such that the model predicts as very liberal and they actually belong to the very liberal class
\item True negative counts (tn): number of participants such that the model predicts as not very liberal and they do not belong to the very liberal class
\item False positive counts (fp): number of participants such that the model predicts as very liberal but they do not belong to the very liberal class
\item False negative counts (fn): number of participants such that the model predicts as not very liberal but they actually belong to the very liberal class
\end{itemize}
with this numbers, we compute the Recall or sensitivity $R$\footnote{The fraction of examples classified as very liberal, among the total number of very liberal examples.}, the positive predictive value $PPV$ or precision\footnote{The fraction of true very liberal examples among the examples that the model classified as very liberal.} and the $f$-score\footnote{A perfect model has an $f$-score of 1.} with the relationships
$$
R=\frac{tp}{tp+fn},\quad PPV=\frac{tp}{tp+fp},\quad F=\frac{2}{1/R+1/PPV},
$$
and finally report the average and the standard deviation across all cross-validation folds. Notice one could use the accuracy metric defined as
$$
A = \frac{tp+tn}{tp+tn+fp+fn}=\frac{tp+tn}{\text{size of the fold}},
$$
but considering that the dataset is strongly imbalanced, previous measures are more informative. Another metric widely used to compare binary classifiers~\cite{wolff2019machine,artetxe2020balanced} is the Receiver Operating Curve or ROC, which corresponds to a plot of sensitivity $R$ versus the false positive rate
$
FPR = \frac{fp}{fp+tn}.
$
ROC is computed as a probability curve and, and the area under ROC curve of AUC represents the degree of separability. In other words, it quantifies in a number how much the model is capable of distinguishing between classes. In our setting, the higher the AUC, the better the model is at predicting liberals as liberals and non liberals as non liberals. Remark that (i) a perfect model has AUC equals to 1, (ii) a model with AUC approximately 0, means that the model is actually reciprocating the classes, therefore a simple relabelling is enough to get good results; and (iii) the worst case scenario is when the AUC equals 0.5, meaning that the model has no class separation capacity.

The methodology we use to compute previously explained metrics is as follows: at each fold test, we use the remaining folds as training dataset. Since the resulting training data set is imbalanced, we use the oversampling technique SMOTE with five neighbors on the minority class. Remark that the test set remains imbalanced which has some consequences. In particular, even one misclassified sample translates into large reductions of the performance measures. Moreover, the number of remaining liberal samples in each fold depends on the number of folds, thus having consequences in the imbalance ratio. We report results with decreasing number of RVC folds in order to test the stability of the results.

\section{Results}

Tables~\ref{tab:r_ppv} and~\ref{tab:f_auc} show the results for  metrics mentioned above of the machine learning techniques after 40 repetitions (3 fold), 10 repetitions (4 fold), 8 repetitions (5 fold) and 4 repetitions (10 fold) of the RCV experiments with SMOTE class imbalance correction. There is no statistical evidence to argument that the number of folds has an effect on the performance of each method. An F- test over the number of folds shows that there is no statistically significant difference $p\gg0.1$.

If we test the performance of each methods we find some differences, specially on the PPV, f-Score and AUC metrics. SVM with RBF kernel is above SVM Linear, MLP, and NB independently of the number of folds. On the other hand, the recall metric (R), shown in Table~\ref{tab:r_ppv} (left), shows no sufficient evidence to affirm that methods perform differently. Indeed, applying an F-test over the different type of machines for the each folds number we find no strong statistical evidence, and it would depend on the confidence level whether or not we reject the null hypothesis  (for instance, the p-value es approx $0.026$ for 10 folds). However, the result changes dramatically, if we discard the MLP model which performs below any other model ($p\approx0.77$ for 10 folds). We conclude that according to the recall metric, all methods except for MLP have similar performance. Figure 2 shows the ROC curves for all approaches in the case of RCV with 5 folders.

The f-scores shown in Table~\ref{tab:f_auc} confirm that SVM with RBF kernel improves over SVM Linear, MLP and NB regardless of RCV number of folders. An F-test carried out over these results confirms that the performance differences between predictive models are statistically significant  ($p\approx0.002$) . Specific one-sided t-tests comparing each pair of modeling approaches confirms that SVM with RBF kernel perform better than SVM Linear, MLP and NB. However, the superiority of SVM with RBF kernel relative to MLP is less pronounced ($p\approx0.05$). On the contrary, the effect is more pronounced for the AUC metric. The F-test carried out over these results confirms ($p\ll0.001$), t-test pairwise tests ($p<0.001$).
\begin{table}[!htbp]
\centering
\footnotesize
\caption{Average $\pm$ standard deviation Recall R (left) and positive predictive value PPV (right) performance of SVM (linear), SVM (RBF), MLP and NB for decreasing number of folders in the repeated cross validation process. All results are calculated with SMOTE oversampling correction of class imbalance.}
\label{tab:r_ppv}
\begin{tabular}{*5c}
\toprule
  \multicolumn{5}{c}{SMOTE} \\
nfolds & SVM (linear) & SVM (RBF) & MLP & NB
\\
\midrule
10 & 0.68$\pm$0.07 & 0.67$\pm$0.08 & 0.65$\pm$0.07 & 0.68$\pm$0.08
\\
5 & 0.68$\pm$0.05 & 0.67$\pm$0.04 & 0.65$\pm$0.06 & 0.66$\pm$0.06
\\
4 & 0.67$\pm$0.03 & 0.66$\pm$0.04 & 0.64$\pm$0.04 & 0.67$\pm$0.04
\\
3 & 0.68$\pm$0.03 & 0.67$\pm$0.05 & 0.67$\pm$0.05 & 0.67$\pm$0.05
\\
\bottomrule
\end{tabular}
\quad
\begin{tabular}{*5c}
\toprule
  \multicolumn{5}{c}{SMOTE} \\
nfolds & SVM (linear) & SVM (RBF) & MLP & NB
\\
\midrule
10 & 0.45$\pm$0.06 & 0.52$\pm$0.08 & 0.47$\pm$0.07 & 0.44$\pm$0.07
\\
5 & 0.46$\pm$0.05 & 0.52$\pm$0.07 & 0.48$\pm$0.05 & 0.44$\pm$0.05
\\
4 & 0.45$\pm$0.04 & 0.52$\pm$0.06 & 0.47$\pm$0.04 & 0.43$\pm$0.05
\\
3 & 0.45$\pm$0.03 & 0.52$\pm$0.04 & 0.45$\pm$0.03 & 0.44$\pm$0.04
\\
\bottomrule
\end{tabular}
\end{table}

\begin{table}[!htbp]
\centering
\footnotesize
\caption{Average $\pm$ standard deviation f-score (left) and AUC (right) performance of SVM (linear), SVM (RBF), MLP and NB for decreasing number of folders in the repeated cross validation process. All results are calculated with SMOTE oversampling correction of class imbalance.}
\label{tab:f_auc}
\begin{tabular}{*5c}
\toprule
  \multicolumn{5}{c}{SMOTE} \\
nfolds & SVM (linear) & SVM (RBF) & MLP & NB
\\
\midrule
10 & 0.54$\pm$0.06 & 0.58$\pm$0.07 & 0.54$\pm$0.06 & 0.53$\pm$0.06
\\
5 & 0.55$\pm$0.05 & 0.59$\pm$0.05 & 0.55$\pm$0.05 & 0.53$\pm$0.05
\\
4 & 0.54$\pm$0.03 & 0.58$\pm$0.04 & 0.54$\pm$0.03 & 0.52$\pm$0.04
\\
3 & 0.54$\pm$0.02 & 0.58$\pm$0.03 & 0.54$\pm$0.03 & 0.53$\pm$0.04
\\
\bottomrule
\end{tabular}
\quad
\begin{tabular}{*5c}
\toprule
  \multicolumn{5}{c}{SMOTE} \\
nfolds & SVM (linear) & SVM (RBF) & MLP & NB
\\
\midrule
10 & 0.68$\pm$0.04 & 0.72$\pm$0.05 & 0.68$\pm$0.04 & 0.67$\pm$0.04
\\
5 & 0.67$\pm$0.03 & 0.72$\pm$0.03 & 0.68$\pm$0.03 & 0.67$\pm$0.03
\\
4 & 0.67$\pm$0.02 & 0.72$\pm$0.04 & 0.67$\pm$0.03 & 0.67$\pm$0.03
\\
3 & 0.68$\pm$0.02 & 0.71$\pm$0.02 & 0.68$\pm$0.02 & 0.67$\pm$0.02
\\
\bottomrule
\end{tabular}

\end{table}
%$$
%0.000001
%Ttest_indResult(statistic=4.705128336546723, pvalue=1.0954486268281921e-05)
%Ttest_indResult(statistic=4.044118570892123, pvalue=0.00012315327310524272)
%Ttest_indResult(statistic=4.82778883801976, pvalue=6.762417354421785e-06)
%$$
\bibliographystyle{abbrv}
\bibliography{biblio_conjoint.bib}

\end{document}