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

% \section*{Thu Oct 10 2019}
% \marginpar{Thursday\\ 2019-10-10, \\ compiled \\ \today}

% Today at 17 there is a colloquium at Aula Rostagni.

% Next week, also at 17, there is a meeting at San Gaetano (for the general public).

% We just had a Nobel prize in cosmology: he predicted the existence of the CMB, and two in astrophysics, they found the first exoplanet.

% Send the professor an e-mail to get access to his Dropbox folder with many relevant texts.

% We come back to the RW metric:

% \begin{equation}
%   \dd{s^2} = c^{2} \dd{t^{2}} - a^2(t) \qty(\frac{\dd{r^2}}{1-kr^2} + r^2 \dd{\Omega^2})\,,
% \end{equation}
% %
% where \(k=0, \pm 1\) and \(r\) is the dimensionless comoving radius.

Another way of defining a distance is the one we get by directly integrating the radial part of the line element: this way, we are effectively using a space-like measuring stick, working at fixed cosmic time and fixing both of the angles \(\theta \) and \(\varphi \).

% The distance can be calculated as:
% %
% \begin{equation}
%   d_P (t) = a(t)\frac{r}{\sqrt{1-kr^2}}\,.
% \end{equation}

% We are allowed to consider radial trajectories, however this does not account for the fact that we cannot actually measure with a space-like measuring stick.

\begin{definition}[Proper distance]
The proper distance \(d_P\) at a fixed cosmic time \(t \) to an object at a comoving radial coordinate \(r\) is given by:
%
\begin{equation}
d_P = a(t) \int_0^r \frac{\dd{\widetilde{r}}}{\sqrt{1-k \widetilde{r}^2}}\,.
\end{equation}
\end{definition}

% This is called the \emph{proper distance} (the subscript \(P\) is for ``proper''): the integration, at zero \(\dd{\Omega}\) and zero \(\dd{t}\), of the radial part of the metric.

% On the other hand (OTOH), the flux of photons can give us the \emph{luminosity distance}, which is actually measurable.

\subsubsection{A derivation of the Hubble law}

We want to derive the Hubble law (\(v = H_0 d\)) mathematically.
It can also be restated as \(cz = H_0 d\): the observed velocity of recession of the objects is measured through redshift, which is described (in  the nonrelativistic limit\footnote{The relativistic expression is
%
\begin{align}
1 + z = \sqrt{\frac{1 + v/c}{1 - v/c}} \gtrsim 1+ \frac{v}{c}
\,.
\end{align}

This will not be relevant for our discussion, however, since before the special-relativistic corrections become relevant we will need to use general-relativistic corrections: roughly speaking, the effects of spacetime expanding while the photon travels from its source to us.
})
by the formula
%
\begin{align}
\lambda _0 = \lambda _{e} \qty(1 \pm \frac{v}{c})
\,,
\end{align}
%
where the sign in the \(\pm\) is a plus if the object is receding from us.
We also defined \(z\) through \(\lambda_0 / \lambda_{e}  = 1+z\): this means that we can identify \(z = v/c\).

% For a fixed source at \(d = ar\), naïvely we would have:
% %
% \begin{equation}
%   \dot{d} = \dot{a} r = \frac{\dot{a} }{a} ar = H_0  d
% \end{equation}

Now, we are going to ``move away from the current epoch by Taylor expanding'':
the scale factor at a time \(t\), \(a(t)\), can be written as
%
\begin{subequations}
\begin{align}
    a(t) &= a_0 + \dot{a}_0 (t-t_0 ) + \frac{1}{2} \ddot{a}_{0}(t-t_0)^2 + \mathcal{O}\qty(\abs{t-t_0}^3)
    \marginnote{We drop the error term}\\
    &\approx a_0 \qty(1 + H_0 (t-t_0 ) - \frac{1}{2} q_0 H_0 ^2 (t-t_0 )^2)\,, \marginnote{Substituted \(H_0 = \dot{a}_{0} / a_0 \).} \label{eq:scale-factor-expansion-second-order}
\end{align}
\end{subequations}
%
where \(q_0 \defeq - \ddot{a}_0 a_0 / (\dot{a}_0 )^2\) is called the \emph{deceleration parameter} for historical reasons: people thought they would see deceleration (\(\ddot{a}<0\)) when first writing this, so a positive \(q_0 \), but
the deceleration parameter is instead measured to be negative.
The Hubble law is only correct up to first order, and we will show this by also calculating the second order correction.

% (the Hubble \emph{constant} is not constant wrt \emph{time} , but wrt \emph{direction}!)

Now, \(1 + z = a_0 / a\) can be expressed as:

\begin{equation}
    1+ z \simeq \qty(1 + H_0  (t-t_0 ) - \frac{1}{2} q_0 H_0 ^2 (t-t_0 )^2)^{-1}\,.
\end{equation}

Do note that this is derived starting with a formula which is correct up to second order in the time interval \(\Delta t = t - t_0 \): when expanding we cannot trust terms of order higher than second.
Expanding with this in mind we get:\footnote{We need to compute the first and second derivatives of
%
\begin{align}
\qty(1 + H_0 \Delta t - \frac{q_0}{2} H_0^2 \Delta t)^{-1}
= \qty(1 + a \Delta t + b \Delta t)^{-1} = f(\Delta t)
\,:
\end{align}
%
they are
%
\begin{align}
\dv{f}{\Delta t} &= - \qty(1 + a \Delta t + b \Delta t)^{-2} \qty(a + 2 b \Delta t)  \\
\dv[2]{f}{\Delta t} &= 2\qty(a + 2b \Delta t)^2 \qty(1 + a \Delta t + b \Delta t) - \qty(1 + a \Delta t + b \Delta t)^{-2} \qty(2 b)
\,,
\end{align}
%
so we have
%
\begin{align}
\eval{\dv{f}{\Delta t} }_{\Delta t = 0} = x
\qquad \text{and} \qquad
\frac{1}{2!}\eval{\dv[2]{d}{\Delta t}}_{\Delta t = 0} = \frac{1}{2!} \qty(2 a^2- 2b) = a^2 - b
\,.
\end{align}}
%
\begin{equation}
  1+ z \simeq
  1 - H_0 \Delta t + \frac{q_0 }{2} H_0^2 \Delta t^2 + H_0^2 \Delta t^2\,,
\end{equation}
%
therefore
%
\begin{align}
  z &= H_0 (t_0 - t) + \qty(1 + \frac{q_0}{2}) H_0^2 (t_0 - t)^2 \marginnote{Changed the time intervals to \(t_0 -t = - \Delta t\), the square of which is the same as before.}  \\
  &= (t_0 - t) \qty[H_0 + \qty(1 + \frac{q_0}{2})H_0^2(t_0 - t) z]
  \,.
\end{align}

Bringing the bracket to the other side we get
%
\begin{align}
  t_0 - t &= z \qty[H_0 + \qty(1+\frac{q_0}{2})H_0^2 (t_0 -t)]^{-1}  \\
  &= z \qty[H_0 + \qty(1+\frac{q_0}{2})H_0 z]^{-1}  \\
  &= \frac{z}{H_0}  \qty[1+ \qty(1+\frac{q_0}{2}) z]^{-1}
  \,,
\end{align}
%
where we substituted the first order expression \(t_0 -t = z/ H_0 \): we are allowed to make this substitution since the expression is multiplied by \(z\), which has the same asymptotic order as \(t_0 -t\) (since \(H_0 \) is finite): working to first order inside the brackets is equivalent to working to second order in the global expression.

By the same reasoning, we can expand the inverse bracket to first order:
%
\begin{align} \label{eq:time-difference-wrt-redshift}
t_0 - t = \frac{z}{H_0 } \qty[1 - \qty(1 + \frac{q_0}{2} z)]
= \frac{z}{H_0 } - \qty(1 + \frac{q_0}{2}) \frac{z^2}{H_0 }
\,,
\end{align}
%

% As before, when we expand we keep only the relevant orders:
% %
% \begin{equation}
%   t_0 - t = H_0 (t_0 - t) + \qty(1+ \frac{q_0}{2}H_0^2 (t_0 - t)^2)
% \end{equation}

We would like the time interval to disappear: we want a distance, not a time, so we should seek an expression for \(r\) instead of \(\Delta t\).
We are observing photons, for which \(\dd{s^2} =0\), which is equivalent \(c^2 \dd{t^2} = a^2 (t) \dd{r^2} / (1-kr^2) \).
Taking a square root and integrating we get:
\begin{equation}
\int_{t}^{t_0 } \frac{c \dd{t}}{a(t)}
= \pm \int_r^0 \frac{\dd{\widetilde{r}}}{\sqrt{1-k \widetilde{r}^2}}
\,,
\end{equation}
%
where we should select the negative sign since we want positive quantities on both sides. The other choice would correspond to the photon being emitted from the Earth and received at the comoving radius of the source.

The integral on the right hand side can be solved analytically: it is

\begin{equation} \label{eq:integral-radial-FLRW}
-\int_{r}^{0} \frac{ \dd{\widetilde{r}}}{\sqrt{1 - k \widetilde{r}^2}} =
\begin{cases}
  \arcsin r =r + \mathcal{O}(r^3) &k =1 \\
  r  &k=0 \\
  \operatorname{arcsinh} r =r + \mathcal{O}(r^3)\qquad\qquad  &k= -1
\end{cases}
\end{equation}
%
in all cases, it is just \(r\) up to \emph{second} order (since the next term in the expansion of an arcsine or hyperbolic arcsine is of third order).

On the left hand side, we can substitute in \(a(t)\) from equation \eqref{eq:scale-factor-expansion-second-order}:
\begin{align}
\int_{t}^{t_0} \frac{c\dd{t}}{a(t)}
&= \frac{c}{a_0 }
\int_{t }^{t_0 } \dd{\widetilde{t}} \qty[1 + H_0 (\widetilde{t} - t_0) + \mathcal{O}(\Delta \widetilde{t}^2)]^{-1}  \\
&= \frac{c}{a_0 } \qty[t_0  - t + \frac{H_0}{2} \qty(t-t_0 )^2] + \mathcal{O}(\Delta t^3)
\end{align}
%
where we used the expression for the scale factor to first order only since the integration raised the order of the estimate by one.
we have:
\begin{align}
\frac{c}{a_0 } \qty((t_0 - t) + \frac{1}{2} H_0 (t_0 - t)^2 + \mathcal{O}(\Delta t ^3)) &= r
\,,
\end{align}
%
since the term proportional to \(q_0 \) only gives a third order contribution.
We can now substitute the expression for the time difference with respect to the redshift \eqref{eq:time-difference-wrt-redshift}, only computed to second order:
%
\begin{align}
r &= \frac{c}{a_0 } \qty[\frac{z}{H_0 } \qty(1 -\qty(1 + \frac{q_0}{2})z)+ \frac{H_0 }{2} \qty(\frac{z}{H_0 } \qty(1 -\qty(1 + \frac{q_0}{2})z))^2]  \\
&= \frac{c}{a_0 } \qty[\frac{z}{H_0 } - \qty(1+\frac{q_0}{2})\frac{z^2}{H_0 } + \frac{H_0}{2} \frac{z^2}{H_0^2}] \marginnote{Ignored the third and higher order terms in the square.}  \\
&= \frac{c}{a_0 H_0 } \qty[z - \frac{1}{2} \qty(1 + q_0 )z]
\,.
\end{align}
%

Now, we can insert this expression for \(r\) into the formula for the luminosity distance \eqref{eq:luminosity-distance}:
\begin{align}
d_L &= a_0^2 \frac{r}{a} = a_0 (1+z) r \\
&= a_0 (1+z) \frac{c}{a_0 H_0 } \qty(z - \frac{1}{2} (1+ q_0 )z^2)
\,.
\end{align}

As we expect, the term \(a_0 \) disappears: it is a bookkeeping parameter, the physical properties of a universe described by a FLRW metric are invariant under a global rescaling of the scale factor.

Our expression also contains cubic terms in \(z\): removing these to get back to second order we find
\begin{align}
d_L &= \frac{cz}{H_0}
\qty(1+z) \qty(1- \frac{1}{2}\qty(1+q_0)z)  \\
&= \frac{cz}{H_0 } \qty(1 + \qty( 1 - \frac{1}{2} - \frac{1}{2}q_0 )z)  \\
&= \frac{cz}{H_0 } \qty(1 + \frac{1}{2}\qty(1 - q_0) z)
% \qty(z + \frac{1}{2} (1-q_0 ) z^2)
\,.
\end{align}

We can turn this into a relation for \(cz\) in terms of \(d_L\) by substituting in the first order expression \(d_L H_0 = cz\) into the second order term (the error we make by this approximation is of third order at least):
\begin{align}
cz &= d_L H_0 + \frac{q_0 -1}{2} cz^2 \\
cz &= H_0 \qty(d_L + \frac{1}{2} (q_0 -1 ) \frac{H_0}{c} d_L^2)\,,
\end{align}
%
and we can notice that the relation is approximately linear and independent of acceleration for low redshift, but we can detect the acceleration at higher redshift.
Typically we need to measure galaxies at least \SI{10}{\mega\parsec} away in order to detect these second order effects.
As we mentioned in the beginning, the data show the parameter \(q_0 \) to be negative.

This effect is similar to a Doppler effect, but the analogy is not perfect: the redshift is caused by the expansion of space itself, and the apparent velocities of the galaxies at high redshift would be superluminal.

\subsubsection{Interpretation of superluminal recession velocities}

What follows is a synthesis of the enlightening article by Davis and Lineweaver \cite[]{davisExpandingConfusionCommon2004}, which should be referred to for clarification.

The proper way to define velocities is directly through the metric: so, we will need to differentiate the relation \(d = a \chi \), where \(\chi \) is the distance in comoving coordinates and \(d\) is the physical distance, with respect to the cosmic time. This yields \(\dot{d} = \dot{a} \chi = H d\).
Note that we are assuming that the object is stationary with respect to the comoving coordinates (\(\dot{\chi} = 0\)), so we are ignoring what is called the \emph{peculiar velocity}.

This \(\dot{d}\) is precisely the recession velocity, and this definition can be extended to any redshift. As written it is quite implicit, since we do not know what the distance in comoving coordinates is to an object we observe with redshift \(z\). This will be treated in section \ref{sec:measuring-distances}, but for now the result is (see also the aforementioned paper \cite[eq. 1]{davisExpandingConfusionCommon2004}, and an older paper by Harrison \cite[eq. 13]{harrisonRedshiftdistanceVelocitydistanceLaws1993}) that the velocity now of an object observed with redshift \(z\) is
%
\begin{align}
v _{\text{rec}} = H_0 d_C(z) = c H_0  \int_{0}^{z} \frac{ \dd{\widetilde{z}}}{H(\widetilde{z})}
\,,
\end{align}
%
which can be greater than \(c\): doing the computation allows us to see that \(v>c\) for \(z \gtrsim 1.5\).\footnote{An interesting (although meaningless) fact: the current recession velocity of the CMB (\(z \approx 1090\)) is around \(\num{3.14} c \approx \pi c\), according to the latest Planck data \cite[]{adePlanck2015Results2016}. For more details on how the recession velocity scales with the redshift, see figure 2 in Davis \& Lineweaver \cite[]{davisExpandingConfusionCommon2004}.}

Does this result contradict General, or even Special Relativity?
It does not!
In General Relativity we cannot directly compare velocities of objects which are far away from each other: they lie in different vector spaces, and there can be no local inertial frame extending that far.
So, it is consistent to have superluminal recession velocities, while observers near the emission, as well as observers near Earth, always measure velocities locally to be \(\leq c\).

Now we can clear some common misconceptions:
\begin{enumerate}
  \item recession velocities can indeed exceed the speed of light;
  \item they can do so in periods of ``regular'' expansion of the universe: we did not consider inflation, which surely did not occur for \(z \sim 1.5\), which is the point at which the recession velocities start being superluminal;
  \item we can indeed see the light from objects which are currently receding superluminally: the formula for the comoving distance is derived by integrating a photon's trajectory.
\end{enumerate}

% \todo[inline]{The reasoning in \cite{paccianiAppuntiCorsoPhysical2018} is not completely convincing: extrapolating a superluminal velocity from \(cz \sim 10c\) is meaningless, since these formulas were derived in the nonrelativistic approximation. If we use the correct relativistic formula for the Doppler shift this issue does not arise. We might be able to show that the apparent speed of high-redshift galaxies is superluminal but we need another way to do it. (Decisamente hai ragione, aggiungi poi che la relazione vale per z piccolo e 10 non è piccolo solitamente. Ad ogni modo ha ragione a dire che il rate di espansione potrebbe essere maggiore di c senza creare problemi alla relatività)}

\begin{definition}[Angular diameter distance]
The angular diameter distance is defined as the ratio of the object's physical transverse size \(L\) to its angular size in radians \(\Delta \theta \):
%
\begin{align}
d_A = \frac{L}{\Delta \theta } = a(t) r
\,,
\end{align}
%
which is peculiar in that it is not monotonic in \(z\) \cite{hoggDistanceMeasuresCosmology2000}: at \(z \gtrsim 1\) it starts decreasing.
\end{definition}

% We can do better than that if we go from \emph{cosmography} to \emph{cosmology}, by understanding what causes the acceleration of the expansion of the universe.

\subsubsection{Redshift-scale factor relation}

Let us prove the statement from before, \(\lambda_0 / \lambda  = a_0 / a\):
photons are emitted with a certain wavelength \(\lambda_{e}\), at a comoving radius \(r\) from us, and detected at \(\lambda_{o}\).

The line element for the photon is \(\dd{s^2} =0\), therefore \(c\dd{t}/ a(t) = \pm \dd{r} / \sqrt{1-kr^2} \).

As before, we can integrate this relation from the emission to the absorption: we call it \(f(r)\) (it can be any of the functions shown in equation \eqref{eq:integral-radial-FLRW}):
\begin{equation}
  \int_{t}^{t_0 } = \frac{c\dd{\widetilde{t}}}{a(\widetilde{t})} = f(r)
\end{equation}

If we map \(t \rightarrow t + \delta t\) and \(t_0 \rightarrow \delta t_0 \) in the integration limits, the integral must be constant since it only depends on \(r\) --- do note that all the expansion of the universe is accounted for by the increasing scale factor, objects are stationary with respect to the comoving radial coordinate \(r\).
We are computing the integral for two successive wavefronts of the light.
Then, we equate the two:
%
\begin{align}
f(r) &= \int_{t}^{t_0 } \frac{c \dd{\widetilde{t} }}{a(\widetilde{t})} = \int_{t+\delta t}^{t_0 + \delta t_0 } \frac{c \dd{\widetilde{t} }}{a(\widetilde{t})}
\,,
\end{align}
%
which we can split into:
%
\begin{align}
\qty[\int_{t+ \delta t}^{t} + \int_{t}^{t_0} + \int_{t_0 }^{t_0 + \delta t_0 } - \int_{t}^{t_0 }] \frac{c \dd{\widetilde{t}}}{a(\widetilde{t})} = 0
\,,
\end{align}
%
where, since all the integrals have the same argument, we collect it at the end for clarity.
We simplify the original integral and swap the integration limits to get:
\begin{equation}
  \int_{t}^{t + \delta t} \frac{c\dd{\widetilde{t}}}{a(\widetilde{t})} = \int_{t_0 }^{t_0 + \delta t_0 } \frac{c\dd{\widetilde{t}}}{a(\widetilde{t})}\,,
\end{equation}
%
which can we approximate by
\begin{equation}
\frac{c \delta t}{a(t)} =   \frac{c \delta t_0 }{a(t_0 )}\,,
\end{equation}
%
since the periods of the photons we are considering are generally much smaller than the cosmic timescales.

Since the frequency of the emitted and observed photons must be proportional to the inverse of the time intervals \(\delta t\) or \(\delta t_0 \), we have
\begin{equation}
  \nu_{e} a(t_{e}) = \nu_{o} a(t_{o})\,,
\end{equation}
%
therefore
%
\begin{equation}
  1 + z = \frac{\lambda_{o}}{\lambda_{e}}
  = \frac{a_0 }{a}\,.
\end{equation}

\chapter{Friedmann models}

The Friedmann equations describe the dynamical evolution of the universe, as opposed to the static description given by the FLRW metric.

\section{A Newtonian derivation of the Friedmann equations}

The Friedmann equations are derived starting from the Einstein Field Equations for the FLRW metric, however we can derive them using an almost purely Newtonian argument.

We will not be able to recover the full equations, since a Newtonian fluid's pressure is \(P \ll \rho c^2\): its contribution to the stress-energy-momentum tensor is negligible \cite[eqs. 441--443]{tissinoGeneralRelativityNotes2020}.
So, through our argument we will recover the equations we would have with \(P=0\).

The only non-Newtonian step in our derivation is the justification of the Newtonian approximation: we wish to make use of the theorem attributed to Birkhoff, but first derived by the Norwegian physicist J.T. Jebsen \cite[]{johansenDiscoveryBirkhoffTheorem2005}.

\begin{proposition}[Jebsen-Birkhoff]
The only solution to the vacuum Einstein Field Equations which is spherically symmetric is given by the Schwarzschild metric \cite[sec. 32.2]{misnerGravitation1973}:\footnote{This is not relevant for what we will discuss here, but do note that there is no requirement of the generating (internal) mass distribution to be static: this is, in fact, the reason why spherically symmetric collapsing or pulsating stars cannot emit  gravitational waves.}
%
\begin{align}
\dd{s^2} =  \qty(1 - \frac{2GM}{c^2r}) c^2 \dd{t^2}
- \qty(1 - \frac{2GM}{c^2r})^{-1} \dd{r^2} - r^2 \dd{\Omega^2}
\,.
\end{align}
\end{proposition}

With this in mind, let us take a spacetime with uniform density \(\rho\).
We consider a sphere, and imagine taking all the mass inside the sphere away.
% Then, by Birkoff's theorem,

% \todo[inline]{It is claimed in \cite[]{paccianiAppuntiCorsoPhysical2018} that it is a corollary of the  JB theorem that the metric inside a spherical shell is Minkowski, this was not obvious to me so I looked for a reference.
%  actually claims that this is false, and that the metric inside the shell is indeed a slice of Schwarzschild spacetime but not necessarily with \(M=0\), and their reasoning seems to make sense.}

By the Jebsen-Birkhoff theorem, the internal geometry of this shell is only determined by the mass distribution inside the shell: since we took all the mass inside the sphere away, the inside spacetime is Minkowski, that is, Schwarzschild spacetime with \(M=0\).\footnote{There is actually some nuance to this: as is expounded upon in an article by Zhuang and Yi \cite{zhangCOMMONMISUNDERSTANDINGBIRKHOFF2012}, in general relativity the geometry inside the shell is actually influenced by the presence of the shell, in that its time coordinate is different to the one which would be measured by an outside observer. This is relevant, for instance, if we wish to compute the Shapiro delay of a ray of light passing through the shell and coming back out.
This is not an issue for us, since the geometry on the inside is locally indistinguishable from a pure vacuum Minkowski spacetime if we measure only inside the shell.}

% This can also be applied to a hole: in this case, it tells us that the metric inside the cavity is the Minkowski metric.

We describe this system through a mass coordinate: \(M(\ell)\) is the mass enclosed by a spherical shell of radius \(\ell\).

The mass taken away will be \(M(\ell) = \frac{4 \pi}{3} \rho \ell^{3}\), where \(\vec{l} = a(t) \vec{r}\) is the radius of the sphere, whose norm is \(\ell = \abs{\vec{l}}\), and \(\rho \), as mentioned before, is the constant density.

We suppose that the gravitational field is \emph{weak}: this is quantitatively expressed using the relation \(\ell \ll r_g\), where \(r_g\) is the Schwarzschild radius of the system: this relation becomes
%
\begin{equation}
  \frac{GM(\ell)}{\ell c^2} \ll 1\,,
\end{equation}
%
and is a necessary assumption in order to apply a Newtonian approximation.

Now, we ``put back'' the mass which was removed, in order to restore the initial situation.

We put a test mass on the surface of the sphere. What is the motion of the mass due to the gravitational field from the center? It will surely be radial, and since as we said we are in the Newtonian approximation we can calculate it using Newton's equation:
%
\begin{equation} \label{eq:newtonian-approx-acceleration}
\ddot{\ell} = - \frac{GM(\ell)}{\ell^2} = - \frac{4 \pi G}{3} \rho \ell
\,.
\end{equation}

This seems to give us a net force even though we expect everything to be stationary because of isotropy.
This is because we are not working in comoving coordinates: the radius of the sphere,  \(\ell\), can change with the scale factor, even when the comoving vector \(\vec{r}\) is constant.

Our final result will not depend on the unit vector we choose.

% there should be none, this is actually not an issue since the unit vectors in our equations will go away in the end.

Plugging in \(\ell = a r\) we find
\begin{align}
  \ddot{a} r &= - \frac{4 \pi G}{3} \rho a r \\
  \ddot{a} &= - \frac{4 \pi G}{3} \rho a\,.
\end{align}

This is the second Friedmann equation, \eqref{eq:friedmann-2}, without the pressure term for the reasons mentioned before.

% This is part of a Friedmann equation: the isotropic pressure term cannot be recovered, it's like the speed of light is infinite now.

Starting from the acceleration equation \eqref{eq:newtonian-approx-acceleration} we can get
\begin{equation}
  \dot{\ell} \ddot{\ell} = - \frac{GM}{\ell^2} \dot{\ell}\,,
  \marginnote{Multiplied by \(\dot{\ell}\)}
\end{equation}
%
and identifying \(2\dot{\ell} \ddot{\ell} = \dv*{(\dot{\ell})^2}{t}\) we find the conservation of energy equation:
%
\begin{align}
\frac{1}{2} \dv{}{t} \qty(\dot{\ell})^2 &= - \frac{GM\dot{\ell}}{\ell^2} \\
 \frac{1}{2} \qty(\dot{\ell})^2 &= -GM \int \frac{1}{\ell^2} \dv{\ell}{t} \dd{t}
 \marginnote{We integrate on both sides in \(\dd{t}\)} \\
  \frac{1}{2}\dot{\ell}^2 &=
  \frac{GM}{\ell}  + C
  =  \frac{4 \pi}{3} G \rho \ell^{2} + C\,, \marginnote{Used \(M = 4 \pi \rho \ell^3 /3 \).}
\end{align}
%
where \(C\) is an arbitrary constant, which we can express in terms of the scale factor:
%
\begin{equation}
  \dot{a}^2 r^2 = \frac{8 \pi G}{3} \rho a^2 r^2 + C
\end{equation}
%
or, removing the \(r^2\) term, which is a constant (since it is a comoving radius, with respect to which objects are stationary),
%
\begin{equation}
\dot{a}^2 = \frac{8 \pi G}{3} \rho a^2 + \frac{C}{r^2}\,.
\end{equation}

Now, the dimensions of this constant are those of a speed, therefore we can express it as \(C / r^2 = -k_N = -k c^2\), where \(k\) is dimensionless --- we are allowed to do this since \(k_N\), the Newtonian curvature constant, has the dimensions of an energy per unit mass, or equivalently a velocity squared.

This clarifies the statement that the magnitude of \(k\) is arbitrary: we get it by dividing the constant \(C\) (which is fixed) by the dimensionless comoving radius, whose magnitude is indeed arbitrary, therefore we can normalize it however we wish: so we choose \(\abs{k} = 1\) or 0.

\begin{bluebox}
The equation we found is of the form:
%
\begin{align}
E _{\text{kin}} + E _{\text{grav}} = -k c^2
\,,
\end{align}
%
where \(E _{\text{kin}}\) and \(E _{\text{grav}}\) are the energies per unit mass in the form of either kinetic or gravitational energy.
So we can directly see that \(k\), in a sense, describes the \emph{intrinsic} energy of a free, stationary (with respect to the comoving coordinates) test mass.

If it is positive (\(k<0\)) then the particles have an intrinsic positive energy, which causes expansion, while if it is negative (\(k>0\)) it is as if they were intrinsically gravitationally bound, which causes contraction.
\end{bluebox}

% The number \(k\) was badly defined to be only \(\pm 1\) or 0: its newtonian version is much better represented by \(k_N = kc^2\).

\end{document}


\section{Introduction}
Over the past several decades, a number of flat histogram Monte Carlo simulation
algorithms have been developed which calculate the thermodynamic properties of
various systems over a range of temperatures.  This development began with the
original histogram method, which used a single canonical Monte Carlo simulation
to predict properties for nearby temperatures~\cite{ferrenberg1988new}.  For
large systems, this approach is limited to a narrow temperature range because a
single canonical simulation explores only a small range of energies. Berg and
Neuhaus developed multicanonical methods that introduced a weight function to
enable flat histogram sampling which improved the exploration of configuration
space and allowed the system to overcome free energy
barriers~\cite{berg1991multicanonical, berg1992multicanonical}. These works led
to an explosion in the interest of ``flat'' (or ``broad'') histogram
methods~\cite{penna1996broad, penna1998broad, swendsen1999transition,
wang2001determining, wang2001efficient, landau2004new, schulz2003avoiding,
yan2003fast, trebst2004optimizing, belardinelli2007wang, belardinelli2007fast,
belardinelli2008analysis, belardinelli2014intrinsic, singh2012density,
zhou2008optimal, schneider2017convergence, liang2006theory, liang2007stochastic,
liang2009improving, werlich2015stochastic, kim2006statistical,
kim2007statistical, kim2009replica, junghans2014molecular}, which explore a
wider range of energies. In addition to simulating a range of temperatures, in
contrast with low-temperature canonical Monte Carlo, these approaches
avoid being trapped in a local energy minimum.

Wang and Landau introduced the most widely used flat histogram algorithm (WL)
that uses an update factor and a statistical histogram to compute the density of
states of a given system~\cite{wang2001determining, wang2001efficient}.  While
the method is incredibly powerful, it has a few disadvantages. The most
significant disadvantage is that the method requires the user to select the
range of energies to be studied~\cite{landau2004new, wang2001efficient,
schulz2003avoiding, yan2003fast}. This requirement adds an additional
hurdle to its application to systems for which the interesting range of energies
is not known \emph{a priori}.  The simulation violates detailed balance, albeit
briefly as the size of the violation decreases with time, which complicates
convergence analysis.  In fact, the error in a WL computation has been
demonstrated to saturate at a non-zero value~\cite{yan2003fast}, i.e. the method
does not converge to the true density of states~\cite{belardinelli2007wang,
belardinelli2007fast, belardinelli2008analysis, belardinelli2014intrinsic,
singh2012density, zhou2008optimal}.

Belardinelli and Pereyra demonstrated that allowing the update factor to
decrease faster than $1/t$ leads to nonconvergence~\cite{belardinelli2007wang},
where $t$ corresponds to the number of moves.
This leads to their $1/t$-WL algorithm which ensures that the error continues to
decrease asymptotically as $1/\sqrt{t}$, which they demonstrated avoids
error saturation and asymptotically approaches the true density of
states~\cite{belardinelli2008analysis}. Zhou \emph{et al.} further confirmed that the
original WL algorithm never converges exponentially and successfully bounded the
statistical error between $t^{-\frac12}$ and $1/t$~\cite{zhou2008optimal}.
Schneider \emph{et al.} outline minor refinements to the $1/t$-WL algorithm
including scaling the update factor with the number of energy
bins~\cite{schneider2017convergence}.

Liang began to consider Stochastic Approximation as a mathematical
generalization of the WL approach, with convergence that could be mathematically
proven~\cite{liang2006theory}. In 2007, Liang \emph{et al.}
developed Stochastic Approximation Monte Carlo (SAMC)~\cite{liang2007stochastic,
liang2009improving}, and proved its convergence, although the method still has a
system specific user-defined parameter which must be tuned when applying this
algorithm to a new system.  In contrast to the WL-based methods, the SAMC method
does not require users to determine the energy range of interest \emph{a
priori}. Werlich \emph{et al.} proposed the introduction of an additional tuning
parameter into SAMC~\cite{werlich2015stochastic}.

Kim \emph{et al.} introduced Statistical Temperature Monte Carlo (STMC) and the
related Statistical Temperature Molecular Dynamics (STMD) which is an
adaption of the WL method that approximates the entropy (or natural logarithm of the density of
states) as a piecewise linear function, which improves convergence for systems
with a continuously varying energy~\cite{kim2006statistical,
kim2007statistical}. STMC applied to WL requires a temperature range be
specified rather than an energy range.  Kim \emph{et al.} extended this work as
Replica Exchange Statistical Temperature Monte Carlo (RESTMC), which uses
replica exchange of multiple overlapping STMC simulations to improve
convergence~\cite{kim2009replica}. More recently, Junghans \emph{et al.} have
demonstrated a close connection between metadynamics, which was introduced by
Laio and Parinello~\cite{laio2002escaping}, and WL-based Monte Carlo methods,
with STMD forging the connection~\cite{junghans2014molecular}.

In this work, we have developed an improved algorithm based on SAMC that does
not require an array of non-physical, user-defined inputs and therefore should
be easily applicable to any system. The method (like STMC above) does require
the user to define a temperature range of interest ($T_\text{min}$ to
$T_\infty$) which we explain in Section~\ref{sec:sad}.  We call this method SAD (Stochastic Approximation with a Dynamic
update factor), and will discuss it in detail in the methods section. We compare
its convergence properties with three existing flat histogram methods: WL,
$1/t$-WL, and SAMC.

In this work, we compare four flat histogram methods.  We outline the
general workings of each algorithm that we developed in detail while
summarizing algorithms that were developed in other works.  The
following methods are discussed and simulated for the square-well
fluid and the 31-atom Lennard-Jones cluster: Wang-Landau (WL),
$1/t$-Wang-Landau ($1/t$-WL), Stochastic Approximation Monte Carlo
(SAMC), and SAD.

\section{Flat histogram methods}\label{sec:histogram}
The goal of flat histogram methods (also called \emph{broad histogram}
or \emph{multicanonical} methods) is to simulate each energy with
similar accuracy so as to accurately determine the density of states
over a broad range of energies---and thus to determine the thermodynamic
quantities such as heat capacity or internal energy
over a broad range of temperatures.
Properties that require more information---such as a spatial
correlation function or a response function---can still be computed
for any temperature, provided statistics are collected for each
individual energy, which can then be reweighted for any
temperature~\cite{panagiotopoulos1998phase, panagiotopoulos2000monte,
errington2003direct}.

All the flat histogram Monte Carlo methods begin with randomly chosen
``moves'' which change the state of the system and must satisfy
detailed balance.  Each algorithm differs in how it determines the
probability of accepting a move and in what additional statistics must
be collected in order to decide on that probability.

Flat histogram methods calculate the density of states $D(E)$ for a discrete set
of energies~\cite{wang2001determining, dayal2004performance, troyer2003flat,
trebst2004optimizing}. Therefore, energy binning becomes an important
consideration for systems with a continuum of possible energies.  Energy bins
are typically of uniform size for the entire energy
continuum~\cite{fasnacht2004adaptive}. Some methods such as
AdaWL~\cite{koh2013dynamically} employ a tunable mechanism for controlling the
binning for low entropic states in order to ensure the exploration of all
energies.  The method introduced in this paper is designed to scale appropriately
as bin size is changed.

In this section we will introduce four closely related flat histogram
methods each of which rely on a weight function $w(E)$.  In these
algorithms, the probability of accepting a move is given by
\begin{equation}
	\mathcal{P}(E_\text{old} \rightarrow E_\text{new})
	= \min\left[1,\frac{w(E_\text{old})}{w(E_\text{new})}\right]
\end{equation}
which biases the simulation in favor of energies with low weights.  A set of
weights that are proportional to the density of states $D(E)$ of the system will
result in an entirely flat histogram, which means that the weights should
converge to being proportional to the density of states.  The natural logarithm
of the weight is typically stored, since the density of states will often vary
over a few hundred orders of magnitude. In the microcanonical ensemble, the
entropy is defined as $S(E) \equiv \ln(D(E))$ (where $k_B \equiv 1$), the
logarithm of the weight is an approximation of the entropy.

Each approach uses a random walk in energy space to estimate the density of
states.  The core of these approaches is to update the weights at each step of
the simulation
\begin{equation}
	\ln{w_{t+1}(E)}=\ln{w_{t}(E)}
	+\gamma_t
\end{equation}
where $t$ is the number of the current move, $\gamma_t$ is an update factor
that varies over the simulation, and $E$ is the current energy.  This update
causes the random walk to avoid energies that have been frequently sampled,
enabling a rapid exploration of energy space. This approach violates detailed
balance, due to the acceptance probabilities changing with each move, but the
severity of this violation decreases as we decrease $\gamma_t$.  The four
methods differ primarily in how they schedule the decrease of $\gamma_t$.

\subsection{Wang-Landau}

The Wang-Landau approach~\cite{wang2001efficient,wang2001determining,
landau2014guide} begins with $\gamma^{\text{WL}}_{t=0}=1$, and then decreases
$\gamma^{\text{WL}}$ in discrete stages.  When the energy histogram is
sufficiently flat, $\gamma^{\text{WL}}$ is decreased by a specified factor of
$\frac12$.  The flatness is defined by the ratio between the minimum value of
the histogram and its average value.  When this flatness reaches a specified
threshold (typically 0.8), the $\gamma^{\text{WL}}$ value is decreased and the
histogram is reset to zero.  This approach requires that the energy range of
interest be known in advance, and difficulties can occur with this flatness
criteria due to the fact that some energies in this energy range might never be
sampled~\cite{troster2005wang}.  The entire process is repeated until
$\gamma^{\text{WL}}$ reaches a desired cutoff.

The Wang-Landau approach thus has three parameters that need be
specified: the factor by which to decrease $\gamma^{\text{WL}}$ when flatness is
achieved, the flatness criterion, and the cutoff that determines when
the computation is complete.  In addition, an energy range (or in
general, a \emph{set} of energies) must be supplied, so that the
flatness criterion can be defined.

\subsection{$1/t$-Wang-Landau}

The $1/t$-WL algorithm ensures convergence by preventing the $\gamma_t$ factor
from dropping below $N_S/t$~\cite{belardinelli2008analysis,
schneider2017convergence}. The method follows the standard WL algorithm with two
modifications.  Firstly, the histogram is considered flat, and $\gamma_t$ is
decreased by a factor of two, when every energy state has been visited once,
i.e. when the WL ``flatness'' becomes nonzero. Secondly, when
$\gamma^{\text{WL}} < N_S/t$ at time $t_0$, the algorithm switches to use
$\gamma_t = N_S/t$ for the remainder of the simulation:
\begin{align}
  \gamma_t^{1/t\text{-WL}} = \begin{cases}
     \gamma^{\text{WL}}_t & \gamma^{\text{WL}}_t > \frac{N_S}{t} \\
     \frac{N_S}{t} & t \ge t_0
 \end{cases}
\end{align}
where $t$ is the number of moves, $\gamma^{\text{WL}}_t$ is the Wang-Landau update factor
at move $t$, and $N_S$ is the number of energy bins.

\subsection{SAMC}
The Stochastic Approximation Monte Carlo (SAMC) algorithm addresses the lack of
convergence of Wang-Landau's approach with a simple schedule by which the update
factor $\gamma_t$ is continuously decreased~\cite{liang2007stochastic,
werlich2015stochastic, schneider2017convergence}.  The update factor is defined
in the original implementation~\cite{liang2007stochastic} in terms of an tunable
parameter $t_0$,
\begin{align}
\gamma_{t}^{\text{SA}} =\frac{t_0}{\max(t_0,t)}\label{eq:1}
\end{align}
where as above $t$ is the number of moves that have been attempted.
SAMC offers extreme simplicity, combined with is proven convergence.
Provided the update factor satisfies
\begin{align}
\sum_{t=1}^\infty \gamma_{t} = \infty \quad\textrm{and}\quad
\sum_{t=1}^\infty \gamma_{t}^\zeta < \infty
\end{align}
where $\zeta > 1$, Liang has proven that the weights converge to the true
density of states~\cite{liang2006theory, liang2007stochastic,
liang2009improving}.  In addition, the energy range need not be known \emph{a priori}.
The time to converge depends only on the choice of parameter $t_0$.
Unfortunately, there is no prescription for finding an acceptable value for
$t_0$, and while the algorithm formally converges, for a poor choice of $t_0$
that convergence can be far too slow to be practical. Liang \emph{et al.} give a
rule of thumb in which $t_0$ is chosen in the range from $2N_S$ to $100N_S$
where $N_S$ is the number of energy bins~\cite{liang2007stochastic}. Schneider
\emph{et al.} found that for the Ising model this heuristic is helpful for small
spin systems, but that larger systems require an even higher $t_0$
value~\cite{schneider2017convergence}.  We will describe below one case we
examined, in which $t_0$ needs to be as much as two orders of magnitude higher
than the rule of thumb of $100N_S$ in order to converge in $10^{12}$ moves.

Werlich \emph{et al.} proposed scaling the SAMC $\gamma_t^{\text{SA}}$
by a factor $\gamma_0$~\cite{werlich2015stochastic}.  While this may result in
an improved rate of convergence, it adds yet another parameter that must be
empirically determined, and we have not explored this additional degree of
freedom.

\subsection{SAMC convergence time}\label{sec:samc-convergence}
A primary difficulty in using the SAMC method lies in identifying an
appropriate value for $t_0$.  Although SAMC is proven to formally
converge regardless of the $t_0$ value, a choice that is either too
high or too low will result in prohibitively slow convergence to the true
entropy of the system.  It is instructive to consider separately
values of $t_0$ that are too low or too high.

We can place a rigorous \emph{lower} bound $t_{\min}$ on the number of
moves required to find the true entropy by considering the total change
that needs to be made to the entropy:
\begin{align}
  \Delta S_{\text{tot}} \equiv \sum_E S(E) - S_{\min}.
\end{align}
This connects with $\gamma_t$ because the $\ln w(E)$ (our approximation for entropy)
has $\gamma_t$ added to it on each move.  Thus a minimum number of moves
that could possibly result in the true entropy $S(E)$ starting with a flat set of
weights is determined by the total entropy change required.  We can estimate
this number of moves required by summing the $\gamma_t$,
which we can approximate using an integral:
\begin{align}
   \Delta S_{\text{tot}} &= \sum_{t=0}^{t_{\min}} \gamma_t^{\text{SA}} \\
  % &= \int_0^{t_{\min}} \gamma(t)dt \\
  &\approx t_0 + \int_{t_0}^{t_{\min}} \frac{t_0}{t}dt
  \\
  &= t_0\left(1 + \ln\left(\frac{t_{\min}}{t_0}\right)\right)
\end{align}
Solving for ${t_{\min}}$ we find that
\begin{align}
  {t_{\min}} &= t_0 e^{\frac{\Delta S_{\text{tot}}}{t_0} - 1}
\end{align}
which means that the minimum time to converge grows exponentially
as $t_0$ is made smaller.  You \emph{seriously} don't want to underestimate
$t_0$!

One might reasonably choose to err by selecting a large $t_0$. The rate of
convergence is harder to estimate when $t_0$ is large, but in general
$\gamma_t^{\text{SA}}$ itself forms a lower bound on the accuracy with which the
entropy may be known, with an unknown prefactor which is related to the
coherence time ($t = t_0$) of the Monte Carlo simulation.  Since
$\gamma_t^{\text{SA}}$ is given by $t_0/t$, the time to converge to a given
accuracy is increased in proportion to the ratio by which we overestimate $t_0$.
Thus, while it is exponentially painful to underestimate $t_0$, overestimating
by several orders of magnitude is also not acceptable.  We should note that
these extreme limiting cases do not preclude the possibility that there is a
wide range of $t_0$ values that lead to an acceptable convergence rate.

\section{SAD Algorithm}\label{sec:sad}
The Stochastic Approximation with Dynamic update factor (SAD) method
is a variant of the SAMC Algorithm that attempts to dynamically choose
the modification factor rather than relying on system dependent
parameters such as $t_0$ or $\gamma_0$.  There is an immediate
advantage of such an algorithm where parameters are chosen independent
of system size or type. Each flat-histogram method has unique
advantages and disadvantages.  Wang-Landau and $1/t$-WL require an
energy range for initialization.  SAMC removes this energy range
requirement but requires simulating every possible energy. Our
proposed method SAD requires the user to input $T_\text{min}$, the
lowest temperature of interest, which is an immediate disadvantage of
the method. However, identifying a minimum temperature of interest
$T_\text{min}$ may be easier for a user than determining in advance
an energy range of interest or the unphysical parameter $t_0$.

We set the maximum temperature of interest as $T=\infty$ for a couple
of reasons.  First, when this temperature is reached, the system is
maximally randomized, so allowing infinite temperature further ensures
that the system can surmount an energy barrier of any size.  Second,
the high temperatures tend to be ``easy'' to simulate, and tend to
converge very quickly.  We note, however, that this is under the
assumption that infinite temperature corresponds to a finite energy,
as is the case for configurational sampling.  Were we to include
kinetic energy in a simulation (as in molecular dynamics), or to
examine a system such as a high density Lennard-Jones fluid with an
entropy maximum at an energy that is far from the energy range of
physical interest, then we would need to apply either a maximum
temperature or a maximum energy, either of which could slow down the
rate at which state space is explored.

\begin{figure}
  \includegraphics[width=\columnwidth]{N50-lndos-comparison}
  \caption{The entropy of a square-well fluid with 50 atoms and filling fraction
        0.3 as the green line.  The green hatched area reflects the
        minimum entropy change needed to converge to the true value.
        The light blue area is the quadratic approximation
        for the change in entropy.  The vertical dotted lines represent
        the energy corresponding to $T=1/3$ and $T=\infty$.}
  \label{fig:entropy-cartoon}
\end{figure}

While for SAMC, the update factor is defined in the original
implementation (see equation~\eqref{eq:1}), for SAD the update factor $\gamma_{t}^{\text{SAD}}$ is
thought of as $\nicefrac{\text{d}S}{\text{d}t}$. This tells us that
the SAMC parameter
$t_0$ should have dimensions of entropy.
We begin with an estimate of the average value of the entropy (relative
to the lowest entropy at $T_{\min}$).  If we assume a quadratic
dependence on energy (see Fig.~\ref{fig:entropy-cartoon}), this is given by
\begin{align}
\langle S\rangle \approx \frac13 \frac{E({T=\infty}) - E(T_{\min})}{T_{\min}}
\end{align}
We approximate this energy difference by $E_H -E_L$ where $E_H$ and
$E_L$ are defined below. The entropy numerator of the update factor in
general should scale with the total number of interesting energy states
$N_S$, since updates to the weights are distributed between that many
energy states.  The product $N_S\langle S\rangle$ is the total change
of entropy required (starting from constant weights) to find the true
entropy, and puts a lower bound on the convergence time. After
\emph{long} times, when all the energies have been explored a long time ago, we
wish for a lower update factor in order to more rapidly refine the
remaining error in entropy.  We track the time at which we first visited
each possible energy.  We define $t_L$ to be the last time that we
encountered an energy that we currently believe is in the energy range
of interest, so a $t\gg t_L$ we feel confident that we have established
the true energy range of interest. We gradually transition to a lower
update factor (but still asymptotically scaling as $\gamma_t \propto
1/t$ to ensure eventual convergence).  Finally, we wish for an update
factor that is \emph{never} greater than 1, because a very large update
factor could introduce very large errors in entropy that may take many iterations
to remove.  The SAD expression for $\gamma_t$ which incorporates these
ideas is:
\begin{align}
  \gamma_{t}^{\text{SAD}} =
     \frac{
       \frac{E_{H}-E_{L}}{T_{\text{min}}} + \frac{t}{t_L}
     }{
       \frac{E_{H}-E_{L}}{T_{\text{min}}} + \frac{t}{N_S}\frac{t}{t_L}
     }
\end{align}
where $E_H$ and $E_L$ are the current estimates for the highest and
lowest energies of interest as defined below.  This factor
asymptotically has the same $1/t$ behavior as the original SAMC
algorithm and with the same $N_S$ prefactor used by the $1/t$-WL
method; however for earlier values of $t$, the update factor drops as
$1/t^2$ and jumps every time a new energy is determined to be of
interest.  This behavior allows SAD to dynamically prevent the update
factor from decreasing too rapidly.

\begin{figure}
  \includegraphics[width=\columnwidth]{gamma-n256}
  \caption{The update factor $\gamma_t$ versus iteration for the
    square-well fluid with 256 atoms, for four different methods: WL, $1/t$-WL, SAMC,
    and SAD.}
    \label{fig:gamma-vs-t}
\end{figure}
Figure~\ref{fig:gamma-vs-t} compares $\gamma_t$ for the related
methods SAD, WL, $1/t$-WL, and SAMC.  For SAMC, $\gamma_t$ remains
constant before dropping as $1/t$.  WL $\gamma_t$ remains at 1 for
many iterations, and then decreases very rapidly, with $1/t$-WL
behaving similarly but decreasing more aggressively before
transitioning to a more conservative $1/t$ behavior.  The update
factor for SAD fluctuates dynamically around a value less than 1 for
early MC moves, and then decreases as approximately $1/t$ while
continuing to fluctuate as new energies are found to be important.  At
intermediate times, the SAD $\gamma_t$ decreases as $1/t^2$ before
asymptoting to $N_S/t$, which is the same as $1/t$-WL.

Since SAD does not explore \emph{all} energy states, it needs to
determine what energy range corresponds to the temperature range of
interest defined by $T_{\min}<T<\infty$. The simulation is responsible
for determining and updating this energy range. Given the true entropy
$S(E)$, we can define the interesting energy range as
%\begin{align}
  $E(T_{\min}) <E< E(T=\infty)$
%\end{align}
where $E(T)$ is the energy that maximizes $S-E/T$.  During the course of the
simulation, this precise energy is challenging to evaluate accurately.
In order to ensure that we sample this entire energy range adequately,
we define two energy limits:  a high energy $E_H$ and a low
energy $E_L$, which define the range over which the energy histogram
is made flat. At move $t$, $E_H$ and $E_L$ are the greatest and lowest
energy that prior to that move
had the highest histogram value (i.e. been visited the most times) at some point
during the course of the simulation.
This definition results in a ``ratcheting'' effect, in which $E_H$
may only increase, while $E_L$ may only decrease over the course of the
simulation, which results in a conservative estimate of the range of
energies that need be sampled.

During the simulation when considering a move inside the energy
range of interest $E_L \le E \le E_H$, the weights are used as in the
three methods already described.  If $E\ge E_H$, the weight is taken
to be
\begin{align}\label{eq:highw}
  w(E>E_H) &= w(E_H),
\end{align}
which corresponds to an infinite temperature.  This choice ensures
that if the maximum in entropy is at an energy $E_{\max}>E_H$, then
the energy $E_{\max}$ will eventually have the highest number of
counts and the ratcheting will result in $E_H\ge E_{\max}$ .  At lower
energies, Boltzmann weights corresponding to the minimum temperature
are used:
\begin{align}\label{eq:loww}
  w(E<E_L) &= w(E_L)e^{-\frac{E_L-E}{T_{\min}}}.
\end{align}
This choice has the result that if the energy $E_{\min}$ at which the free
energy at $T_{\min}$ is minimized is less than $E_L$, the lower energy
limit will ratchet down to include $E_{\min}$.
Each time we change the value of $E_H$ or $E_L$, the weights outside the
new portion of the interesting energy range are set to the expressions
in Equations~\ref{eq:highw} and~\ref{eq:loww}.

%~ \paragraph{Energy binning with SAD}

A significant advantage of SAD over SAMC---which the $1/t$-WL and WL
methods share \emph{after} they have discovered all the energies---is that
the schedule for $\gamma_t$ automatically responds to the choice of bin
size.
SAD should perform similarly over a reasonable range of bin sizes
because $\gamma_t \propto \nicefrac{N_S}{t}$.  As the number of energy
states $N_S$ found increases (fine binning), the time spent $t$ in
each bin will decrease with the effect that the convergence should be
roughly independent of the bin size chosen.  SAMC could be used with a
prefactor $\gamma_0$ to aid in a similar
way~\cite{werlich2015stochastic} but this adds yet another parameter
for the user to choose.

%~ \paragraph{Scaling, step size, and SAD}
%~ Methods such as WL can fail to converge for complex systems in part
%~ because the same random MC moves are performed for the entire energy
%~ range.  The main problem lies in trying to determine how to optimize
%~ the step size such that the time to explore all energies is reasonable.
%~ Small step sizes lead to improved sampling at the expense of slow
%~ convergence. Koh et al. proposed multiplying $\gamma$ by an energy
%~ dependent factor in order to improve the converge of WL in regards to
%~ convergence and scaling~\cite{koh2013dynamically}.  Because the update
%~ factor for SAD has an energy dependent factor already present (and
%~ dynamically adjusted), we expect that SAD will perform consitently
%~ scaling free for a reasonable choice of step size.  SAD should perform
%~ extremely well compared with other flat histogram methods when applied
%~ to complex continuous systems such as polymers/proteins and spin models.

%~ \subsection{Convergence}
%~ Because SAD scales as $1/t$ for large $t$, it satisfies the SAMC
%~ convergence criteria.  However, we also want to ensure that SAD avoids
%~ the exponentially poor convergence time that SAMC suffers when $t_0$ is
%~ small as discussed in Section~\ref{sec:samc-convergence}.
%~ To place a lower bound on the convergence of SAD, we will again
%~ approximate the total entropy change using an integral.  To sidestep
%~ the dynamical nature of SAD, we ensure that \emph{after discovering the
%~ last important energy} at time $t_L$ the entropy change
%~ $\Delta S_{\text{tot}}$ can be made in a reasonable number of iterations.
%~ Thus we integrate the update factor from $t_L$ to some minimum time
%~ $t_{\min}$ necessary for convergence.  Technically this is not a lower
%~ bound as in the case of SAMC because the algorithm will already have a
%~ reasonable approximation for the entropy.
%~ \begin{align}
%~ \Delta S_{\text{tot}} &= \int_{t_L}^{t_{\min}}
     %~ \frac{
       %~ 3\langle S\rangle + \frac{t}{t_L}
     %~ }{
       %~ 3\langle S\rangle + \frac{t}{N_S}\frac{t}{t_L}
     %~ } dt \\
%~ &\approx 3\Delta S_{\text{tot}} \left(1-\frac{t_L}{t_{\min}}\right)
%~ \end{align}
%~ where we assumed that $t_L\gg N_S\langle S\rangle$, which is to say
%~ that it takes a long time to find all the interesting energy states.
%~ Furthermore, we omitted the $\frac{t}{t_L}$ in the numerator, which is
%~ of order unity.  This omission only makes our bound more conservative,
%~ and enables us to solve to find that
%~ \begin{align}
  %~ t_{\min} &= \frac32 t_L
%~ \end{align}
%~ which means that we only need to run fifty percent longer after we
%~ discover the final interesting energy state in order to have made
%~ sufficient updates to \emph{possibly} converge to the true entropy.

\section{Results}\label{sec:results}

\subsection{Square-well fluid}
As our first test case, we consider the square-well fluid i.e. a
system of particles whose interactions are governed by a square-well
potential~\cite{singh2003surface, barker2004perturbationSW}.  The
square-well potential is an ideal test-bed as it is a simple model for
a liquid, which includes both attractive and repulsive
interactions~\cite{barker1967-SW-perturbation, vega1992phase}.
To date, there have not been any published direct convergence comparison tests
for flat histogram methods applied to the square-well fluid.
The potential $U(\textbf{r})$ for such a system is given by
\begin{equation}
 U(\textbf{r})=\begin{cases} \infty &
 \lvert\textbf{r}\rvert< \sigma\\-\epsilon &
 \sigma<\lvert\textbf{r}\rvert<\lambda\sigma\\0 &
 \lvert\textbf{r}\rvert > \lambda\sigma\end{cases}
\end{equation}
where $\sigma$ is the hard-sphere diameter of the particle, $\lambda$ is the
reduced range of the potential well, and $\epsilon$ is its depth. This model has
the further advantage that binning is not required because the energy is
discrete.

\begin{figure*}
  \includegraphics[width=0.5\textwidth]{periodic-ww1_30-ff0_30-N50-gamma-and-entropy-error-default.pdf}%
\includegraphics[width=0.5\textwidth]{periodic-ww1_30-ff0_30-N50-gamma-and-entropy-error-slow.pdf}
  \caption{(a) The average entropy error for each MC method for $N=50$,
               $\delta_0 = 0.05\sigma$, $\eta = 0.3$, and $T_{\min} = 1/3$
               as a function of number of iterations run. The error is
               averaged over 8 independent simulations, and the best
               and worst simulations for each method are shown as a
               semi-transparent shaded area, and
           (b) the update factor $\gamma_t$ versus iteration number
               for the same simulations.
           (c) The average entropy error for each MC method for the
               same physical system with a smaller displacement distance
               $\delta_0 = 0.005\sigma$,
               as a function of number of iterations run, and
           (d) the update factor $\gamma_t$ versus iteration number
               for the same simulations.
  }\label{fig:fast-slow-gamma}
\end{figure*}

We tested the algorithms on two square-well fluid systems.  The first
is a smaller simulation with a particle number of 50, a well-width of
$\lambda = 1.3$, and a volume corresponding to a filling fraction
(defined as the fraction of volume filled by atoms) of $\eta =
0.3$. The second system is larger, with a particle number of 256, a
well-width of $\lambda = 1.5$, and a volume corresponding to a filling
fraction of $\eta = 0.17$.  For each system we use a reasonable
root-mean-square displacement distance $\delta_0 = 0.05\sigma$ for
proposed moves, and for the smaller system we also use an unreasonably
small displacement distance of $0.005\sigma$. The simulations explore
the energy space of the systems with minimum reduced temperatures of
$T_{\text{min}} = 1/3$ for simulations of the smaller system, and
$T_{\min}=1$ for the larger system.  All simulations lead to the
minimum important energy $E_{\min}$ and maximum entropy energy
$E_{\max}$ being calculated (with the exception of the WL methods
where both of these parameters are needed \emph{a priori}).

The SAMC simulations
computed the density of states for the entire range of possible
energies.  The SAD simulations determined the energy range of interest
dynamically as described above, based on a specified $T_{\min}$.  For
the WL and $1/t$-WL simulations, we constrained the simulation to
remain in the energy range corresponding to $T_{\min} < T < \infty$,
as determined by a previous SAMC simulation.  Thus the WL and $1/t$-WL
simulations were given extra information that in practice would not be
available without additional computational effort, and the SAMC simulations
computed the entropy over the entire range of possible energies, which
required more effort.

We use the average entropy error versus moves as a metric to compare
simulation runtimes and overall convergence. The overall accuracy
is determined by examining the fractional error of a particular method to
a precise reference system. For each simulation, the reference system
is chosen to be the final output of a SAMC simulation with a fixed energy range
corresponding to the temperature range of interest.
Although SAMC does not require an energy range as an input parameter,
we find that by limiting the simulation to this energy range, we can
achieve much faster convergence with a smaller $t_0$.  We compute an average
of the error by averaging the error in the entropy over the
interesting energy range, and then averaging \emph{this} error over several
simulations run with different random number seeds.
%~ \begin{align}
%~ \epsilon_\text{avg} =
  %~ \frac{1}{N_S \text{num seeds}}\sum_s^{\text{num seeds}}\sum_{i}^{N_S} \left|S_\text{ref}(E_i) - S_\text{method}(E_i)\right|
%~ \end{align}

\subsubsection{50 square-well atoms}
For this 50 atom simulation, we chose a minimum reduced
temperature of $1/3$, which corresponds to an interesting energy range
from $-248$ to $-120$.  The number of important energy states
for this system is therefore $N_S = 129$.  The entropy of this system is shown in
Fig.~\ref{fig:entropy-cartoon} above, which shows that over this
energy range the entropy differs by 198, corresponding to a ratio of
$10^{86}$ between the highest and lowest density of states.

In order to explore the effect of simulation details on convergence,
we consider two values for the displacement distance by which atoms
are moved during a Monte Carlo step.  We began with a reasonable
displacement distance of $\delta_0 = 0.05\sigma$, which corresponds to
an acceptance rate of proposed moves of 38\%.  We further ran
simulations with a much smaller displacement distance of $\delta_0 =
0.005\sigma$, which resulted in an acceptance rate of 86\%, which
converged more slowly.

Figure~\ref{fig:fast-slow-gamma}a shows the average error in the
entropy as a function of time for this system with the reasonable
displacement distance of $\delta_0 = 0.05\sigma$.  The solid/dashed lines
represent the average of the absolute value of the error in the
entropy averaged over eight simulations using different random number
seeds.  The range of average errors for each simulation is shown as a
shaded region around its mean error.  By the time $10^8$ moves have
been made all but the SAMC simulation with the shortest $t_0$ have
begun to converge as $1/\sqrt{t}$.  We then see the WL error
saturate around $10^{10}$ moves.

Figure~\ref{fig:fast-slow-gamma}c shows the average error in
the entropy as a function of time for this system with the
unreasonably small displacement distance of $\delta_0 = 0.005\sigma$.
%
The smaller translation scale causes all methods to take additional time to
explore all energies. Based on random walk scaling, the convergence time of an
ideal method should scale roughly as $\delta_0^{-2}$ in the limit of small
$\delta_0$, that is, one order of magnitude decrease in the displacement
distance should result in two order of magnitude increase in convergence time.
SAMC simulations with a $t_0$ value that rapidly converged for $\delta =
0.05\sigma$ do not converge at all in $10^{12}$ moves for a translation scale of
$\delta = 0.005\sigma$. It is also worth noting that for the smaller
displacement distance, the SAMC rule of thumb of choosing $t_0$ to be
approximately $100N_S$ is no longer valid. SAD, WL, and $1/t$-WL handle the
shift in displacement distance and converge roughly as expected.

The methods SAD, WL, and $1/t$-WL compensate for the smaller
displacement distance by reducing $\gamma_t$ more slowly, as can be seen from
Figure~\ref{fig:fast-slow-gamma}b and ~\ref{fig:fast-slow-gamma}d.
The update factors take approximately 10$\times$ longer to reach steady-state
for the smaller displacement distance. Because of this update behavior,
these methods are less sensitive to the choice of displacement
distance than SAMC is.

%~ SAMC methods that converge
%~ in a reasonable amount of moves in Figure~\ref{fig:fast-slow-gamma}a do not
%~ necessarily do so for Figure~\ref{fig:fast-slow-gamma}b.
%
%~ Sad performs similarly regardless of the displacement distance chosen although
%~ it transitions to $1/\sqrt{t}$ convergence after

\begin{figure}
\includegraphics[width=\columnwidth]{periodic-ww1_50-ff0_17-N256-entropy-error-default.pdf}
  \caption{
  The average entropy error for each MC method for $N=256$,
               $\delta_0 = 0.05\sigma$, $\eta = 0.17$, and $T_{\min} = 1$
               as a function of number of iterations run.  The error is
               averaged over 8 independent simulations, and the best
               and worst simulations for each method are shown as a
               semi-transparent shaded area.  The update factor for this
               system is in Fig.~\ref{fig:gamma-vs-t} above.}\label{fig:n256}
\end{figure}

\subsubsection{256 square-well atoms}
Next we introduce a considerably larger simulation containing 256
atoms which has a maximum entropy about 1500 greater than its minimum.
This makes exploring the entire range of energies extremely expensive,
and strongly favors the methods that restrict the energy (or
temperature) range of interest.  For this simulation, we chose a much
higher minimum reduced temperature of $1.0$, which corresponds to an
interesting energy range from $-915$ to $-509$.  The number of
important energy states for this system is then $N_S = 407$.  The
minimum entropy over this energy range is just 395 less than the
maximum, corresponding to a ratio of only $10^{118}$ between the
highest and lowest density of states.

%$395.2833013702813 - 4.754731035740479e^{-8}$ = $395.2833$ so $2^{396.2833}$
%gives us about $10^{118}$ from 'samc-1e4-256-s8.yaml'

Figure~\ref{fig:n256} shows the average error in the entropy as a
function of moves for this system with the reasonable displacement
distance of $\delta_0 = 0.05\sigma$.  The solid lines represent the
average of the absolute value of the error in the entropy averaged
over eight simulations using different random number seeds.  The range
of average errors for each simulation is shown as a shaded region
around its mean error.  By the time $10^8$ moves have been made all
but the SAMC simulation with the shortest $t_0$ shown have begun to
converge as $1/\sqrt{t}$.  We then see the WL error saturates around
$10^{10}$ moves.  Once again, the convergence of SAD is essentially
the same as that of the $1/t$-WL method.

\begin{figure}
  \includegraphics[width=\columnwidth]{lj-cv}
  \caption{The heat capacity of the LJ31 cluster after $10^{12}$ moves
    as calculated with each method.  Each simulation used a bin size
    of $\Delta E=0.01\epsilon$.}
  \label{fig:lj-cv}
\end{figure}

\subsection{31-atom Lennard-Jones cluster}

We also examined convergence of each algorithm on the 31-atom cluster
(LJ31), which is the smallest Lennard-Jones cluster that exhibits
broken ergodicity and a solid-solid phase transition at a low
temperature~\cite{doye1998thermodynamics,
  martiniani2014superposition}.  Clusters of Lennard-Jones atoms have
been frequently used for testing Monte Carlo
algorithms~\cite{wales1997global, neirotti2000phase,
  frantsuzov2005size, mandelshtam2006multiple}.  The LJ31 cluster
is commonly used for testing convergence of algorithms
because it features a two-funnel energy landscape with a significant
barrier between the two low-energy states~\cite{calvo2000entropic,
  calvo2000phase, poulain2006performances,
  martiniani2014superposition}.  In particular, the LJ31 cluster
features a low-temperature solid-solid phase transition that is challenging to
converge~\cite{mandelshtam2006multiple}.  Poulain \emph{et al.}
tested a number of variants of the WL algorithm on LJ31 and failed to
converge the spike in heat capacity corresponding to the solid-solid
phase transition~\cite{poulain2006performances}.

%% \jpcom{This \P\ should be commented once summarized.
%% Poulain \emph{et al.} found very poor convergence for a variety of
%% modified WL methods on the LJ31
%% cluster~\cite{poulain2006performances}.  Sadly, they don't mention the
%% energy range or bin size that was used in their simulation, so their
%% results cannot be reproduced.  They do mention that they use 1000
%% energy bins, which if they used an energy range of
%% $[-133.58\epsilon,0]$ would correspond to a bin size of $\Delta
%% E\approx 0.13\epsilon$, which we find to be too large to accurately
%% predict the heat capacity peak at $0.03\epsilon/k_B$.  Looks like they
%% only ran $\sim 10^{10}$ moves. We can't converge in that few moves either.}

Figure~\ref{fig:lj-cv} shows the heat capacity of the LJ31 cluster
over the temperature range from $k_BT=0.01\epsilon$ to
$k_BT=0.40\epsilon$.  There are two peaks, a large peak around $k_BT
\approx 0.3\epsilon$ corresponding to melting temperature, and a
small peak around $k_BT \approx 0.027\epsilon$ for the solid-solid
transition from a Mackay-to-anti-Mackay (M $\rightarrow$ aM)
transition~\cite{doye1997thermally, hendy2001molecular,
  mandelshtam2006multiple}.  We constrain our atoms within a spherical
box of radius 2.5$\sigma$, as is common in the
literature~\cite{poulain2006performances, mandelshtam2006multiple}.
We note that using a larger box (with radius $5\sigma$) has a large
effect on the melting peak, and a smaller but still significant effect
on the solid-solid transition.  Since our focus is on the convergence
rate, we will restrict ourselves to the smaller box size.  In addition, we
further restricted all our simulations to negative total potential energies.

\begin{figure}
  \includegraphics[width=\columnwidth]{lj-cv-error}
  \caption{The maximum error in the heat capacity of the LJ31 cluster
    in the temperature range 0.01~$\epsilon\le k_BT \le 0.05\epsilon$.
    Note that the value of $C_V$ ranges from 90$k_B$ to 120$k_B$, so
    the smallest (maximum) errors seen are around 1\%.  All WL methods
    shown were run with a histogram bin width of $\Delta
    E=0.01\epsilon$.  The converged reference heat capacity was
    computed with a $1/t$-WL simulation with the energy constrained to
    a range $-133.53\epsilon\le E\le -110\epsilon$.
  }
  \label{fig:lj-cv-error}
\end{figure}

In order to test the low-temperature convergence, we focused on the
heat capacity in the temperature range $0.01\epsilon \le k_BT \le
0.05\epsilon$ (see inset in Fig.~\ref{fig:lj-cv}), which contains
the solid-solid phase transition.
%
We compute the heat capacity from the entropy using a standard
canonical analysis, which gives
\begin{align}
  C_V &= 31\times\frac32k_B + \frac1{k_BT^2}\left< (E- \langle
  E\rangle)^2\right>
  \label{eq:cv}
\end{align}
where the first term represents the kinetic energy contribution, and
the second term is the potential energy contribution, with canonical
averages using the microcanonical entropy to compute multiplicities.
%
For our reference heat capacity, we ran a $1/t$-WL simulation with the
energy constrained to a range $-133.53\epsilon\le E\le -110\epsilon$.
We chose this energy range through experimentation, as we found the
convergence rate to be very sensitive to the minimum energy chosen.

%% \jpcom{this is a basically a repeat of above...
%% The heat capacity changes significantly even at these low temperatures
%% when the size of the cavity is increased.  We use a 2.5 cavity because
%% ``everyone else'' does~\cite{poulain2006performances}.  For purposes
%% of testing the convergence of the algorithm, we don't need to solve
%% for the true heat capacity.  Furthermore, the heat capacity at fixed
%% volume is not the most meaningful quantity to predict for a cluster.
%% }
We ran simulations with several bin widths using each algorithm we studied
and show results for $\Delta E=0.1\epsilon$ and
$0.01\epsilon$.
When examining the converged results, we saw that each bin size yielded a
measurably different low temperature heat capacity. The largest
bin size of $0.1\epsilon$ introduced a maximum error in heat capacity
of more than $20k_B$ compared with the smaller bin size.  We will focus on
the smaller bin size, and
used a bin size of $0.01\epsilon$ for our converged reference heat capacity.

Figure~\ref{fig:lj-cv-error} shows the maximum error in heat capacity
over the temperature range $0.01\epsilon\le k_BT\le 0.05\epsilon$ as a
function of the number of Monte Carlo moves performed.
%
We explored the convergence behavior of each algorithm at two energy
bin widths ($\Delta E=0.01\epsilon$ and $\Delta E=0.1\epsilon$).  We
were unable to converge the WL or $1/t$-WL algorithms with the larger
bin size.
%
The rate of convergence of SAD for the heat capacity seems to be roughly
independent of the bin width.  In contrast (but not shown) the entropy
itself shows much larger statistical fluctuations with smaller bin
sizes.  The canonical averaging process in Eq.~\ref{eq:cv} averages
out those statistical fluctuations, which reduces the penalty of using
a smaller bin size.

%% Dependence on bin width.  Figure~\ref{fig:lj-cv-error} shows that the
%% heat capacity converges just as well for bin widths varying over two
%% orders of magnitude, although for bins as large as $\Delta
%% E=0.1\epsilon$ the error in the heat capacity is significant, as is
%% apparent in Fig~\ref{fig:lj-cv}.  The entropy itself converges much
%% more slowly for a smaller $\Delta E$, but when summing over energies
%% the statistical fluctuations in the entropy cancel. WL and $1/t$-WL
%% show similar behavior, so this is not new, but is encouraging.

The convergence behavior of the WL and $1/t$-WL is incredibly
sensitive to the minimum energy chosen, which complicates the process of
obtaining a workable result.  The known ground state energy of this
cluster is $-133.586422\epsilon$~\cite{northby1987structure,
  wales1997global}.  With a minimum energy of $-133.58\epsilon$, none
of our WL or $1/t$-WL simulations converged in 10$^{12}$ moves.  With minimum
energies of $-133.54\epsilon$, $-133.53\epsilon$, and
$-133.52\epsilon$, the simulations do seem to converge, although the
lowest energy case was significantly slower.
This result highlights the advantage of being able to
specify a temperature range rather than an energy range when computing
properties as a function of temperature.  It is not only more
convenient, but also far more efficient due the the fact that only a
single simulation need be performed.

%% Specifying temperature range rather than energy range is beneficial.
%% Both WL and $1/t$-WL are incredibly sensitive to the minimum energy
%% chosen, as seen in Fig.~\ref{fig:lj-cv-error}.  Cite previous work
%% that showed them not converging because it chose too low a minimum
%% energy, proving that it is \emph{not} a trivial procedure to determine
%% an appropriate energy range.  Specifying the temperature range
%% \emph{does} matter! We had to do a whole bunch of $1/t$-WL
%% computations in order to determine what would be a sufficient
%% low-energy cutoff.

Finally, we want to mention our results for SAMC, which are not shown
in our plots in order to reduce clutter.  With a well-chosen power of ten value for
$t_0$, SAMC can converge to the correct result, but less rapidly than
either $1/t$-WL or SAD.  However, with a poor $t_0$
parameter, the method cannot converge in practice.  In addition, the
optimal $t_0$ parameter depends on the bin width as well as the energy
range chosen, further complicating matters.

%% SAMC is a major pain.  The $t_0$ value needs to be adjusted when
%% $\Delta E$ is changed or when the energy range is changed.  The energy
%% range has the same downsides as the WL methods, although it manifests
%% differently, with failure to converge as the problem, rather than
%% failure for $\gamma_t$ to decrease.

\section{Conclusions}
We have introduced a new algorithm, a variant of the SAMC method, which
effectively samples the
energy space corresponding to a desired range of temperatures for a
few systems.
%
We find that both SAD and $1/t$-WL converge more rapidly than SAMC, and
unlike WL consistently converge to the correct density of states. SAD requires
the user to specify a temperature range of interest rather than an
energy range of interest as $1/t$-WL does.  For use cases in which
a range of desired temperatures is known, this will make the SAD method
considerably more convenient.

We find that SAMC converges for a reasonable choice of
$t_0$ but this parameter can be difficult to tune especially across
significantly differing systems.  We find that even simple
changes to the Monte Carlo moves can have a dramatic effect on the
range of practical $t_0$ values.  Additionally, SAMC does not
converge as rapidly as either SAD or $1/t$-WL even for the best choice of $t_0$,
when a relatively small range of energies is required, because it always
simulates all possible energies.

Finally, we find that for examining a Lennard-Jones cluster the WL and
$1/t$-WL algorithms---versions of which had previously been found to
be unsuccessful on this problem~\cite{poulain2006performances}---have
convergence properties that are highly dependent on the choice of
energy range to be examined.  This is particularly problematic when
examining the low-temperature heat capacity, where it is difficult to
determine the lowest energy that will have a significant impact at the
temperatures of interest. This is an example of how SAD is more
powerful when the range of energies is not known in advance.


\documentclass{article}
\usepackage{hyperref}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[section]{placeins}
\renewcommand{\thesubsection}{\thesection.\alph{subsection}}
\usepackage{listings}

\title{\bf{CSE397: Group Assignment \#2}}
\author{Benjamin Crestel, Nicholas Malaya, Prabhakar Marepalli, Ajay Vadakkepatt}

 %\\ Institute for Computational Engineering and Sciences \\ University of Texas at Austin}
\date{}

\begin{document}
\maketitle

\newpage
\section*{Problem Statement}

\section{Uncertainty in the data}
\begin{enumerate}
 \item Ambient (and intermittent) winds
 \item Roughness of basketball and bowling ball (were they unusually
       rough?) (Bowling ball has holes in it)
 \item $C_d$ is varying in time, but we are not accounting for that.
 \item Dimension and weight of the balls:
\begin{itemize}
 \item Basket ball: Circumference and weight don't appear to correspond
       to any official values (Wikipedia + Google). That would indicates
       these characteristics were measured.
 \item Bowling ball: We can assume the bowling ball was also measured.
\end{itemize}

We are only dealing with measurement errors here. We can model both with
       additive Gaussian noise of mean zero and standard deviation
       defined by a 95\% confidence interval. We could assume the
       circumference is correct within $\pm 1$ cm with 95\%
       confidence. Whereas the weight is accurate within 0.1 oz.
 \item Height of the drop: This is represented by a uniform distribution
       between 34.5m and 35.5m.
 \item Position of the operator: The position is very uncertain. But it
       doesn't matter in the outcome of the experiment. As long as the
       operator is far enough to capture the whole drop sequence without
       having to move (which he is at 22.4m away from the action), it is
       not going to have an incidence on the results.
 \item Temperature: Mass density of the air depends on the
       temperature. Both experiments were performed in two different
       days. So most likely the temperature was different which affected
       the mass density of the air. We can assume the temperature was
       between 15C~(1.2250~kg/m$^3$) and 25C~(1.2041~kg/m$^3$) with 95\%
       confidence. We will directly translate this uncertainty into the
       mass density.
 \item Video acquisition: The time framing is assumed to be exactly
       accurate as this is based on the iPad internal clock and there is
       no reason to assume it was defective. However the distance of the
       ball is very uncertain for different reasons.
\begin{itemize}
 \item Reference distance: The distances are all relative to a reference
       distance. The experimentalists chose the height of the bridge as
       their reference distance. But on top of the large uncertainties
       on that exact distance (see above), we have uncertainties coming
       from the definition of that length in Logger Pro.
 \item Fixed position of the camera: The acquisition of the motion of
       the ball is done by selecting the ball (or the top of the ball to
       more accurate) on the screen at each frame you want to
       use. However, based on online videos, Logger Pro doesn't adjust
       the position of the object relative to its environment. So the
       position of the object is relative of the sides of the image (ie,
       the camera is assumed to be fixed in Logger Pro). Hence if the
       camera operator shifts the camera during the experiment he shifts
       the absolute position of the ball by the same amount. If he
       rotates the iPad, he shifts the absolute position of the ball by
       the distance between the camera and the ball times the rotation
       angle. That would indicate that the distance from the ball is
       actually relevant. Unless we adopt some general treatment as
       advised in the next section.
\end{itemize}
 \item Gravity of Earth: From Wikipedia (actually using Wolfram Alpha's
       city data), we found the gravity at Vancouver to be
       $9.81339$~m/s$^2$. The uncertainty will be estimated below.
\end{enumerate}

\section{Uncertainty on the position of the ball}

Working at the continuous level for now, we are interested in
characterizing the uncertainty on the measured position of the ball
$\tilde{h}(t)$.
We model this uncertainty with additive noise $\varepsilon(t)$ such that
\begin{align*}
 \tilde{h}(t) = h(t) + \varepsilon(t).
\end{align*}
Assuming we can estimate the mean and covariance matrix of that random
variables, the principle of maximum entropy relative to a uniform
distribution would lead us to using a Gaussian distribution for that
noise.
In the question we are advised to use the following form for the
mean~$\mu(t)$ and covariance matrix~$R(t,t')$ of the noise
\begin{align*}
 \mu(t) = \alpha t , \quad R(t,t') = \sigma^2 e^{-|t-t'|/\tau} .
\end{align*}

In practice for each experiment we are given a discrete set of times~$\{
t_i \}_i$ when position measurements occurred. This leads to the
following discrete representation of uncertainty for the measured vector
position
\begin{align*}
 \{ \tilde{h} \} = \{ h \} + \{ \varepsilon \},
\end{align*}
where
\begin{align*}
 \{ \varepsilon \} \sim \mathcal{N}\left( \{ \mu \} ,  R  \right),
\end{align*}
with
\begin{align*}
 \mu_i = \alpha t_i, \quad R_{ij} = \sigma^2 e^{-|t_i-t_j|/\tau}.
\end{align*}

\section{Prior on $C_d$, the coefficient of drag}

The coefficient of drag is a non-dimensionalization of the force that
results from a scaling analysis.
\begin{equation*}
 \frac{F_D}{\frac{1}{2} \rho V^2 A } = C_D(Re).
\end{equation*}
Thus, the coefficient depends only on the Reynolds number of the
flow. Let's estimate the Reynolds number to give us a sense of the range
we believe may be possible in this particular experiment.

The Reynolds number is defined as,
\begin{equation*}
 Re = \frac{V L}{\nu}
\end{equation*}
Let's estimate the characteristic velocity (V), and length (L) as well
as the viscosity, $\nu$. An upper bound for the velocity would be from
the calculating the velocity in the absense of drag. Here, $V = g
t_{\text{final}}$, and with $t_{\text{final}} \approx 3 $ seconds, our V
is $\approx 29.4 $ m/s. The characteristic length is the ball diameter,
which for the basketball is 23.33 cm. Finally, the kinematic viscosity
of air is $15.68 * 10^{-6} \text{m}^2/s$ according to
\url{http://www.engineeringtoolbox.com/air-properties-d_156.html}. Thus,
our $\text{Re} \approx 437,000$, which means the flow is certainly
turbulence. Furthermore, we expect roughness effects to become
significant around $Re \approx 10^5$. Given that we do not know, with
confidence, if the balls are rough or smooth, our prior must be
sufficiently broad to capture the possibilty of either condition.

Looking at a NASA chart for the measured drag coefficient on a sphere,
at low reynolds numbers (when we release the ball) we expect that our
drag coefficient might be as large as 2. Should the sphere be smooth,
the drag coefficient could be as small as 0.1 at the end. We also know
that our prior should not be capable of negative values, that would be
aphysical. For these reasons, we decided to define $C_d$ as
\begin{align*}
 C_d \sim \mathcal{U}(0,2).
\end{align*}

\section{Probabilistic model}

\begin{enumerate}
 \item The coefficient $\alpha$ defined above is said to be ``of order
       $0.5$~m/s with uncertainty of the same order''.
 Since we could not exclude negative values of $\alpha$ we can choose
       $\alpha$ to be Gaussian with mean $0.5$~m/s and $95\%$~confidence
       interval given by the interval of uncertainty. Here the
       uncertainty is said to be ``of the same order'' as the mean. In
       order to be conservative, we'll pick our $67\%$~confidence
       interval to be $[-1,1]$~m/s.
\[ \alpha \sim \mathcal{N}(0.5, 1). \]
 \item For $\sigma$, we know it has to be non-negative. We can therefore
       assume that $\sigma$ is uniformly distributed over the interval
       $[0, 0.2]$~m.
\[ \sigma \sim \mathcal{U}(0, 0.2) . \]
 \item The uncertainty on the height will impact the
       measurement. Assuming for a second that we have no errors due to
       the handling of the iPad, the height we measure is given
       proportionally to the reference height of the bridge and the
       ratio of the pixels for each object, that is
 \begin{align*}
  \tilde{h} = \frac{p_1}{p_2} \tilde{H},
 \end{align*}
where $\tilde{H}$ is the measured height of the bridge. As discussed
       earlier, the height of the bridge is a random variable sampled
       from a uniform distribution over $[34.5, 35.5]$~m.
For convenience we re-write $\tilde{H}$ as
\begin{align*}
 \tilde{H} = 35 + \tilde{\eta},
\end{align*}
where $\tilde{\eta}$ is sampled from a uniform distribution over $[-0.5,
       0.5]$~m. Plugging this into the equation for our measured height
       of the ball, we get
\begin{align*}
 \tilde{h} = \frac{p_1}{p_2} 35 + \frac{p_1}{p_2} \tilde{\eta}.
\end{align*}
Let's define the exact height of the ball as
\begin{align*}
 h \equiv \frac{p_1}{p_2} 35.
\end{align*}
We then get
\begin{align*}
 \tilde{h} = h \left( 1 + \frac{\tilde{\eta}}{35} \right).
\end{align*}
That is the uncertainty due to the height of the bridge acts on the
       measured height of the ball through a multiplicative noise.
Using the notations we defined in the previous questions for the
       uncertainty due to the handling of the iPad, we can write the
       measured height of the ball as
\begin{align*}
 \tilde{h} = \left( h + \varepsilon \right) (1 + \eta),
\end{align*}
where $\varepsilon$ is a multivariate Gaussian with mean and covariance
       matrix defined in earlier and
\begin{align*}
 \eta \sim \mathcal{U}\left( \frac{-0.5}{35}, \frac{+0.5}{35} \right) .
\end{align*}
Maybe a more informative way to formulate that problem would be to
       define the total height of the bridge directly as a random
       variable. This leads to the following data reduction model for
       the measured height of the ball
\begin{align*}
 \tilde{h} = ( h  + \varepsilon ) \frac{H}{35},
\end{align*}
where
\begin{align*}
 H \sim \mathcal{U} \left( 34.5, 35.5 \right).
\end{align*}
\end{enumerate}

\section{Likelihood and MCMC computations}

We will infer (at most) for the following parameters: $\alpha, \sigma,
C_d, H$. The likelihood gives us the probability that the results from
our simulation~$h_c$ match the data~$h_d$ we have.
\[ \pi\left( h_c = h_d \, | \, \alpha, \sigma, C_d, H \right) .\]
In the hypothetical case we'd know all parameters exactly ($\alpha,
\sigma, C_d, H$), the data would be connected to the results of our
simulation through the following relation
\begin{align*}
 h_d = \left( h^\text{ode} + \varepsilon \right) \frac{H}{35} ,
\end{align*}
where $h_c$ is given by
\begin{align*}
 h_c = h^\text{ode} \frac{H}{35}.
\end{align*}
For convenience, we re-write this relation as
\begin{align*}
\left( h_d - h_c \right)\frac{35}H  = \varepsilon.
\end{align*}
We already detailed the distribution of the random variable
$\varepsilon$. It is Gaussian with mean and covariance given by the time
measurements of each experiment and random variables $\alpha$ and
$\sigma$ (which are assumed to be sampled when evaluating the
likelihood). Calling $\mu$ and $R$ the mean and covariance matrix
corresponding to the right format of $h$ (ie, stacking information from
all 4 experiments 'on top of each other'), we get the following
distribution for the likelihood,
\begin{align*}
 \pi(h_c = h_d \, | \, \alpha, \sigma, C_d, H) = \frac1{\sqrt{(2\pi)^n |R|}} \exp \left\{ - \frac12 \left(  h_d \frac{35}H - h^\text{ode} - \mu \right)^T \cdotp R^{-1} \cdotp \left(  h_d \frac{35}H - h^\text{ode} - \mu \right) \right\} ,
\end{align*}
where $n = t_f^1 \times t_f^2 \times t_f^3 \times t_f^4$ is the number
of data (ie, the dimension of $h_d$) and $h_d$ is defined as
\begin{align*}
 h_d = \begin{bmatrix}
h_1(t_1^1) \\
h_1(t_2^1) \\
\vdots \\
h_1 (t_f^1) \\
h_2(t_1^2) \\
\vdots \\
h_2(t_f^2) \\
\vdots \\
h_4(t_f^4)
\end{bmatrix}.
\end{align*}
Note that the times used in $h_d$ (and hence $h_c, \mu, R$) can be a
subset of the times used in the actual experiments. For instance, the
last measurements look highly suspicious and should be probably excluded
from our inference.
$\mu$ and $R$ are defined as follows
\begin{align*}
 \mu = \alpha
 \begin{bmatrix}
  t_1^1 \\
  t_2^1 \\
  \vdots \\
  t_f^1 \\
  t_1^2 \\
  \vdots \\
  t_f^4
 \end{bmatrix}, \quad R =
 \begin{bmatrix}
  R_1 & 0 & 0 & 0 \\
  0 & R_2 & 0 & 0 \\
  0 & 0 & R_3 & 0 \\
  0 & 0 & 0 & R_4
 \end{bmatrix}
\end{align*}
where
\begin{align*}
 R_i = \sigma^2
 \begin{bmatrix}
  1 & e^{-|t_1^i - t_2^i|/\tau} & e^{-|t_1^i - t_3^i|/\tau} &  \ldots & e^{-|t_1^i - t_{f-1}^i|/\tau} & e^{-|t_1^1-t_f^i|/\tau} \\
\vdots & 1 & e^{-|t_2^i - t_3^i|/\tau} &   \ldots & e^{-|t_2^i - t_{f-1}^i|/\tau} & e^{-|t_2^i - t_f^i|/\tau} \\
\\
\vdots &  &  \ddots & &  & \vdots \\
\\
& \text{symm} & & & 1 & e^{-|t_{f-1}^i - t_f^i|/\tau}  \\
\\
& & \ldots & & & 1
 \end{bmatrix}
\end{align*}
Because of the very specific form of our covariance matrix (block-diagonal), we can simplify the expression for the likelihood as follows
\begin{align*}
 & \pi(h_c = h_d \, | \, \alpha, \sigma, C_d, H) =  \ldots \\
 & \frac1{\sqrt{(2\pi)^n \prod_{i=1}^4|R_i|}}  \exp \left\{ - \frac12 \sum_{i=1}^4 \left(  h_d \frac{35}H - h^\text{ode} - \mu \right)_i^T \cdotp R_i^{-1} \cdotp \left(  h_d \frac{35}H - h^\text{ode} - \mu \right)_i \right\} ,
\end{align*}
where
\begin{align*}
 \left(  h_d \frac{35}H - h^\text{ode} - \mu \right)_i
\end{align*}
corresponds to the data, computed results and mean for the $i^\text{th}$ experiment. This formulation clarifies the fact that we work experiment per experiment as each experiment is independent from the others.

\end{document}