\documentclass[twocolumn,aps,prd,floatfix,preprintnumbers,a4paper,nofootinbib,
superscriptaddress,10pt]{revtex4-1}

\usepackage{epsfig}
\usepackage{graphics}
\usepackage{graphicx}
\usepackage{amsmath,amssymb,mathtools}
\usepackage{amsfonts}
\usepackage{bm,soul}
\usepackage[usenames,dvipsnames]{color}
\usepackage{amssymb}
\usepackage{url}
\usepackage{psfrag}
\usepackage{times}
\usepackage[varg]{txfonts}
\usepackage[colorlinks, pdfborder={0 0 0}]{hyperref}
\usepackage{lineno}
\usepackage{verbatim}
\definecolor{LinkColor}{rgb}{0.75, 0, 0}
\definecolor{CiteColor}{rgb}{0.75, 0, 0}
\definecolor{UrlColor}{rgb}{0, 0, 0.75}
\hypersetup{linkcolor=LinkColor}
\hypersetup{citecolor=CiteColor}
\hypersetup{urlcolor=UrlColor}
\usepackage[utf8]{inputenc}
\usepackage{ulem}
\normalem
\hoffset -0.17in
\voffset 0.3in
\textheight 10in

\usepackage{algorithm}
\usepackage{algpseudocode} % in place of algorithmic. Conflicts with revtex4 unless [H] option passed
\usepackage{setspace} % for pleasent spacing in algorithm

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Useful Definitions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input{definitions}
\def\check#1{\red{#1}}
\def\new#1{\blue{#1}}
\def\remove#1{\hlred{#1}}
\newcommand{\cw}{\tilde{\omega}}
\newcommand{\CW}{\tilde{\Omega}}
\newcommand{\CWr}{{\Omega}^{\mathrm{r}}}
\newcommand{\CWc}{{\Omega}^{\mathrm{c}}}
\newcommand{\SC}{\mathcal{K}}
\newcommand{\CC}{\mathcal{C}}
\newcommand{\SCr}{\mathcal{K}^{\mathrm{r}}}
\newcommand{\SCc}{\mathcal{K}^{\mathrm{c}}}
\newcommand{\lalapprox}{\texttt{MMRDNS}}
\def\jf{j_f}
\def\mf{M_f}
\newcommand{\LL}{\bar{l}}
\newcommand{\MM}{\bar{m}}
\def\lmn{_{\ell m n}}
\def\LM{_{\bar{\ell} \bar{m}}}
\def\LMlmn{_{\bar{\ell} \bar{m} \ell m n}}
\def\gmvp#1{greedy-multivariate-polynomial#1
  (\texttt{GMVP}#1)\gdef\gmvp{\texttt{GMVP}}}
\def\gmvr#1{greedy-multivariate-rational#1
  (\texttt{GMVR}#1)\gdef\gmvr{\texttt{GMVR}}}

\newcommand{\lmtitle}[2]{\vspace{-0.80cm} \begin{center} \noindent\rule{0.35\paperwidth}{0.3pt} \end{center} \vspace{-0.3cm}}

% Numbers that may change from time to time
\def\CwFitCalibrationRegion{\red{0.995} }
\def\NumCalibrationPointsPlotted{\red{21} }
\def\NumCalibrationPoints{\red{61} }

\def\pgreedy{\texttt{PGREEDY}}

\newcommand{\Cardiff}{School of Physics and Astronomy, Cardiff University, Queens Buildings, Cardiff, CF24 3AA, United Kingdom}

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

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Title page %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title{On modeling for Kerr black holes: Basis learning, QNM frequencies, and spherical-spheroidal mixing coefficients }

\author{L. London}
\affiliation{\Cardiff}
\author{E. Fauchon-Jones}
\affiliation{\Cardiff}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Abstract %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{abstract}
  %
  Models of black hole properties play an important role in the ongoing direct detection of gravitational waves from black hole binaries. One important aspect of model based gravitational wave detection, and subsequent estimation of source parameters, are the low level modeling of information related to perturbed Kerr black holes. Here, we present new phenomenological methods to model the analytically understood gravitational wave spectra (quasi-normal mode frequencies), and harmonic structure of Kerr black holes (mixing coefficients between spherical and spheroidal harmonics). In particular, we present a greedy-multivariate-polynomial (GMVP) regression method and greedy-multivariate-rational (GMVR) regression method for the automated modeling of polynomial and rational functions respectively. GMVR is a quasi-linear numerical method for interpolating rational functions. It therefore represents a solution to Runge's phenomenon. GMVP is used to develop a model for QNM frequencies that explicitly enforces consistency with the extremal Kerr limit. GMVR is used to develop a model for harmonic mixing coefficients that extends previous results to dominant multipoles with $\ell \le 5$. Both models are the first of their kind to consider black hole spin to vary between -1 and 1, thus naturally connecting the pro and retrograde modes. We discuss the potential use of these models in current and future gravitational wave signal modeling.
	%
\end{abstract}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Preprint numbers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\preprint{LIGO-P1500185-v10}
\date{\today}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\maketitle

\section{Introduction}
%
In the coming years, expectations for frequent \gw{} detections of increasing \snr{} are high \cite{TheLIGOScientific:2016pea,Abbott:2016nhf}.
%
Concurrent with \virgo{}, the \aligo{} detectors will enter their third observing run in approximately early 2019.
%
During this period, a few to dozens of \bbh{} signals are likely to be detected \cite{Abbott:2016nhf,Abbott2018OS}.
%
In this context, signal detection and subsequent inference of physical parameters hinges upon efficient models for source properties and dynamics \cite{Abbott:2016wiq}.
%
Most prominently, there is ongoing interest in efficient and accurate signal models for \bbh{} \imr{} \cite{Blackman:2017dfb, London:2017bcn, Hannam:2013oca}.
%
As the merger of isolated \bh{s} is expected to result in a perturbed Kerr \bh{}, there is related interest in having computationally efficient models for perturbative parameters, namely those that enable evaluation of the related \rd{} radiation \cite{Berti:2005ys}.
%
\par In particular, a perturbed Kerr \bh{} (e.g. resulting from \bbh{} merger) will have \gw{} radiation that rings down with characteristic \textit{dimensionless} frequencies,
%
$%\begin{align}
	\cw\lmn = \omega\lmn + i/\tau\lmn
$%\end{align}
, where $\omega\lmn$ is the central frequency of the ringing, and $1/\tau\lmn$ is the damping rate.
%
These discrete frequencies have associated radial and spatial functions which are \textit{spheroidal} harmonic in nature \cite{Leaver85}.
%
Together, these harmonic functions and frequencies constitute the \qnm{} solutions to \ee{}.
%
Specifically, they are the eigen-solutions of the source free linearized \ee{} (i.e. \tk{'s} equations \cite{PhysRevLett.29.1114}) for a perturbed \bh{} with final mass, $\mf$, and dimensionless final spin, $\jf$.
%
These solutions allow \grad{} from generic perturbations to be well approximated by a spectral (multipolar) sum which combines the complex \qnm{} amplitude, $A\lmn$, with the spin $-2$ weighted -2 spheroidal harmonics, $_{-2}S\lmn$.
%
\begin{align}
	%
	\label{hrd}
	%
	h &= h_{+} - i \, h_{\times}
	  \\ \nonumber
	  &= \frac{1}{r} \sum\lmn A\lmn \; e^{i\,\cw\lmn t} \; _{-2}S\lmn( \jf \cw\lmn,\theta,\phi)
		\\ \nonumber
		&= \frac{1}{r} \sum\LM h\LM(t) \; _{-2}Y\LM(\theta,\phi) \;  .
	%
\end{align}
%
\par In the first and second lines of \eqn{hrd}, we relate the observable \gw{} polarizations, $h_+$ and $h_\times$, to the analytically understood morphology of the time domain \rd{} waveform.
%
Here, the labels $\ell$ and $m$ are polar and azimuthal eigenvalues of \tk{'s} angular equations, where total mass and the speed of light are set to unity (i.e. $M=c=1$).
%
Note that barred indices, namely $\bar{\ell}$ and $\bar{m}$, refer to \textit{spherical} harmonics of spin weight -2, leaving the unbarred indices to refer to the spheroidals.
%
In the third line of \eqn{hrd}, we represent $h$ in terms of {spherical} harmonic multipoles.
%
This latter form is ubiquitous for the development and implementation of \imr{} signal models for \bbh{s}.
%
%
\par Towards the development of these models, \eqn{hrd} enters in many incarnations.
%
In the \eob{} formalism, $h\LM$ is modeled such that, after its peak (near merger), the effective functional form reduces (asymptotically) to \eqn{hrd}'s second line \cite{Cotesta:2018fcv, Buonanno:2000ef,
Bohe:2016gbl,Pan:2013rra, Bohe:2016gbl, Nagar:2018zoe}.
%
This view currently comes with the added assumption that ${_{-2}}S_{\ell m n} = {_{-2}}Y_{\ell m}$, where ${_{-2}}Y_{\ell m}$ are the spins weighted -2 spherical harmonics.
%
Only where $\jf \cw\lmn=0$ do $_{-2}S\lmn( 0,\theta,\phi) = {_{-2}}Y_{\ell m}(\theta,\phi)$, which makes equating the spherical and spheroidal harmonics approximate at best for general values of $\jf \cw\lmn$.
%
The consequences of that approximation, in particular the mixing between spherical and spheroidal harmonics, are discussed in reference \cite{London:2014cma,Berti:2014fga,London:2018gaq,Kelly:2012nd}.
%
This approximation also applies to the \textit{Phenom} models,
where the frequency domain multipoles, $\tilde{h}\LM(f)$, are constructed such that their high frequency behavior is consistent with \eqn{hrd} in the time domain
%
\cite{Hannam:2013oca, London:2017bcn, Khan:2015jqa, Schmidt:2014iyl, Mehta:2017jpq,Khan:2018fmp}.
%
\par Both Phenom and \eob{} approaches either use phenomenological models of remnant \bh{} mass and spin to interpolate over tables of \qnm{} frequencies, or phenomenological models for \qnm{} frequencies are used directly.
%
Either approach typically incurs less computational cost that the direct numerical calculation of \qnm{} frequencies, which may involve, for example, the solving of continued fraction equations \cite{Leaver85}.
%
In the case of the higher multipole model \texttt{PhenomHM} and its derivative models, fits for the \qnm{} frequencies are used in the process of mapping $\tilde{h}_{22}(f)$ into other $\tilde{h}\LM(f)$ \cite{London:2017bcn}.
%
In that setting, it is demonstrated that \qnm{} frequencies are linked to the amplitude and phase of each $h\LM$ in not only \rd{}, but also merger and late inspiral, as is implied by the source's causal connectedness pre and post merger.
%
%
\par For models that assist tests of the \nht{} (e.g. \cite{Berti:2005ys,London:2018gaq,Carullo:2018sfu}), and thereby only include precise \rd{s}, the perspective of \eqn{hrd}'s second and third lines are used to write each spherical harmonic multipole moment as
%
\begin{align}
	\label{hlm}
	h\LM = \frac{1}{r} \sum\lmn \, A\lmn e^{i \cw\lmn t} \sigma\LMlmn
\end{align}
%
where, the spherical-spheroidal mixing coefficient, $\sigma\LMlmn$, is
%
\begin{align}
		\label{sigma}
		\sigma\LMlmn = \int_{\Omega} {_{-2}S}\lmn \,  {_{-2}}Y^*\LM \, \mathrm{d} \Omega \; .
\end{align}
%
In \eqn{sigma}, $*$ denotes complex conjugation, and $\Omega$ is the standard solid angle in spherical polar coordinates.
%
\par In practice, using \eqn{hlm} is computationally efficient:
%
Whereas the calculation of each ${_{-2}S}\lmn$ involves a series solution which slowly converges for $\jf$ near unity, the calculation of each ${_{-2}Y}\LM$ is achieved using closed form expressions.
%
It is therefore efficient to use accurate models for $\sigma\LMlmn$ to avoid convergence issues. These can then be used directly to calculate $h\LM$ via \eqn{hlm}, and thereby the \gw{} polarizations via \eqn{hrd}.
%
%
\par In this combined context, it is clear that the modeling of \qnm{} frequencies, $\cw\lmn$, and spherical-spheroidal mixing coefficients, $\sigma\LMlmn$, are relevant for a range of \gw{} signal models.
%
While models for $\cw\lmn$ and $\sigma\LMlmn$ are present in the literature (e.g. \cite{Berti:2005ys, Berti:2014fga, Cook:2014cta}), there exist minor shortcomings which we wish to address here.
%
\par For both the \qnm{} frequencies and the spherical-sphoidal mixing coefficients, we present the first models which treat \qnm{s} rotating with and against the rotation of the \bh{} as being a part of a single solution parameterized by dimensionless \bh{} spin ranging from -1 to 1.
%
This perspective reflects the empirical observation that the remnant spin of \bbh{} mergers smoothly connects regions of positive and negative spin relative to the direction of the initial oribital angular momentum \cite{Husa:2015iqa,London:2018gaq}.
%
\par For the \qnm{} frequencies, it is well known that for nearly extremal \bh{s} (i.e. $\jf \rightarrow 1$) some of the frequencies have zero-damping (i.e. $\tau\lmn \rightarrow \infty$) \cite{Yang:2012pj,Zimmerman:2015trm}.
%
In the context of \gw{} \da{}, where source parameters are estimated using routines which sample over the space of all possible \bh{} masses and spins, it is useful to have accurate physical behavior in the extremal limit \cite{TheLIGOScientific:2016wfe}.
%
Like Ref.~\cite{Cook:2014cta}, we present models for $\cw\lmn$ that explicitly account for zero-damping in the extremal Kerr limit.
%
The models presented here go further by applying outside of the nearly extremal Kerr regime while also accounting for non-zero-damping in modes such as $(\ell,m,n)=(2,1,0)$ and $(3,2,0)$\cite{Yang:2012pj}.
%
%
\par For the modeling of $\sigma\LMlmn$, we note that the models of Ref.~\cite{Berti:2014fga} do not appear to include the \qnm{s} which rotate counter to the \bh{} spin direction (i.e. ``mirror-modes'').
%
Here these \qnm{} are explicitly modeled on a continuation of the positive spin line to negative spin.
%
%
\par In parallel, the methods for modeling $\cw\lmn$ and $\sigma\LMlmn$ have been dispersed: different phenomenological techniques have been used under no coherent framework.
%
Here we will present linear modeling techniques, namely the \gmvp{} and \gmvr{} algorithms, in which model terms are iteratively learned with no initial guess.
%
The description of \gmvp{} given here is complementary to similar algorithms used to model \qnm{} excitation amplitudes, $A\lmn$, as present in reference \cite{Carullo:2018sfu,London:2018gaq,London:2014cma}.
%
As we will discuss, the \gmvr{} algorithm is an iterative approach to the (pseudo) linear modeling of multivariate rational functions, wherein iterations of linear inversions are used to refine the ultimately non-linear model.
%
\par In the rudimentary form presented here, both \gmvp{} and \gmvr{} are intended for use with low noise data (e.g. the results of analytic calculations), and each employs a reverse (or negative) greedy algorithm to counter over modeling \cite{Field:2011mf,Caudill:2011kv}.
%
As the underlying process for \gmvp{} and \gmvr{} is stepwise regression, highly correlated basis vectors (i.e. polynomial terms) are handled via an approach we will call \textit{degree tempering}.
%
It will be demonstrated that these approaches are readily capable of modeling the complex valued $\cw\lmn$ and $\sigma\LMlmn$.
%
Results suggest that the versions of \gmvp{} and \gmvr{} presented here may apply in instances where training data are approximately noiseless, and an initial guess is difficult to obtain.
%
Both algorithms are publicly available in \texttt{Python} via Ref. \cite{lionel_london_2018_1402516}.
%
While this paper's fits for the \qnm{} frequencies and mixing coefficients are presented in \eqns{eq:cw_fit_1}{eq:cw_fit_9} and \eqns{eq:ys22220}{eq:ys55550}  respectively, we encourage the reader to use the fits implemented in Ref.~\cite{lionel_london_2018_1402516}: \texttt{positive.physics.cw181003550} (\qnm{} frequencies) and in \texttt{positive.physics.ysprod181003550} (mixing coefficients).
%
%
\par The plan of the paper is as follows.
%
In section \sec{meth}, we outline the \gmvp{} and \gmvr{} algorithms.
%
In \sec{results}, we demonstrate the application of each algorithm.
%
We first consider the application of \gmvp{} to the modeling of \qnm{} frequencies.
%
We then consider the application of \gmvr{} to the modeling of spherical-spheroidal mixing coefficients.
%
Quantitative comparisons are made between our models and those presented in Refs.~\cite{Berti:2005ys, Berti:2014fga}.
%
In \sec{discuss}, we review the effectiveness of \gmvp{} and \gmvr{}, and we discuss current and potential applications for these methods.
%
%
\section{Methods}
\label{meth}
%
Within the topic of regression, linear regression has particular advantages.
%
Its matrix based formulation can be computationally efficient, and it does not require initial guesses for model parameters.
%
Perhaps most intriguingly, the formal series expansions of smooth functions support linear and rational models (e.g. Pad\'e approximants) that have application to many datasets.
%
With this in mind, here, we will develop algorithms for the linear (polynomial and rational) modeling of scalar functions (real or complex) of many variables.
%
\par If we consider a scalar function, $f$, of $N$ variables sampled in $j$, $\vec{x}_j = \{x_{\alpha j}\}_{\alpha=0}^{N}$, then $f(\vec{x}_j)$ can be represented (possibly inaccurately) as a sum over $K$ linearly independent basis functions, $\phi_k(\vec{x}_j)$:
%
\begin{align}
  \label{lin1}
  f({\vec{x}}_j) \; = \; \sum_{k=0}^{K} \; \mu_{k} \, \phi_k(\vec{x}_j)\; .
\end{align}
%
The central player in \eqn{lin1} is the set of basis coefficients $\mu_{k}$.
%
Typically, one chooses or derives $\phi_{k}(\vec{x}_j)$ to capture inherent features of $f(\vec{x}_j)$.
%
With $\phi_{k}(\vec{x}_j)$ assumed to be known, the linear representation (namely \ceqn{lin1}) is lastly defined the set of $\mu_k$.
%
\def\vecmu{\vec{\mu}}
\def\vecf{\vec{f}}
\def\hatU{\hat{U}}
\def\hatP{\hat{P}}
%
\par From here it is useful to note that \eqn{lin1} has a linear homogeneous matrix form.
%
In particular, defining ${U}_{jk} = \phi_k(\vec{x}_j)$, $f_j = f(\vec{x}_j)$ and $\vec{f} = \hat{U} \; \vec{\mu}$, implies that
%
\begin{align}
  \label{eq:linsol1}
  \vecmu = \hatP \; \vecf \; ,
\end{align}
%
where
%
\begin{align}
  %
  \label{pinv1}
  \hatP = \left( \hatU^{*} \hatU \right)^{-1}\hatU^{*}
\end{align}
%
is the \textit{pseudo-inverse} \cite{Moore1920,Penrose:1955} of $\hatU$, which exists if $\hatU^{*} \hatU$ is nonsingular.
%
Here ``$*$'' denotes the conjugate transpose.
%
\par Equations (\ref{lin1}), and related discussion through \eqn{pinv1} illustrate the most rudimentary solution to the linear modeling problem.
%
However, there are many ways to expand upon and refine the solution presented thus far.
%
In the following subsections we will consider two such approaches.
%
First we will consider the general polynomial modeling of multivariate scalar functions.
%
This will encompass the \gmvp{} algorithm.
%
Second, we will build upon the \gmvp{} approach by considering models of rational functions (polynomials divided by polynomials).
%
To consider these two approaches in a largely automated way (i.e. where the set of possible basis functions is known, but the select basis functions ultimately used are \textit{learned}), we will make use of the \textit{greedy} algorithm approach \cite{Field:2011mf, GVK022791892, 1978AnSta, Pandit84}.
%
\subsection{A Generic Greedy Algorithm}
%
While we most often want a single model for a given dataset (e.g. some approximation of $\vecf$ from numerical calculation or experiment), there are often many more modeling choices than desired.
%
In particular, if we refer to our set of all possible basis functions as our ``\textit{symbol space}'', then the problem of determining how many, and which basis vectors (i.e. symbols) to use is a problem of combinatoric complexity.
%
\par A well known method for finding an approximate solution to this problem is the so-called ``greedy'' algorithm (e.g. \cite{Field:2011mf, GVK022791892}):
%
We will iteratively construct models with increasing number of symbols.
%
The process begins by finding the single symbol (basis vector) that yields the most accurate model in the sense of minimizing the least-squares error.
%
That encompasses the first iteration of a process in which we will greedily add symbols to our model.
%
In each subsequent iteration, remaining symbols are added to the model one at a time, resulting in many trial models, each with its own representation error.
%
The trial model with smallest representation error is kept for the next greedy iteration.
%
In this way, a list of optimal model symbols is learned.
%
This forward greedy process ends when the model accuracy, and/or changes thereof, passes a previously specified threshold.
%
This rough algorithmic picture is encapsulated by Alg. \ref{alg:pgreedy}.
%
% Forward greedy algo
\hspace{1cm}
{\scriptsize
\begin{algorithm}[H]
  %
  \caption{A positive (forward) greedy algorithm, \pgreedy{}. Note that a required input, $\mathcal{A}$, is a function that takes in a list of basis symbols, and outputs an estimator of fit error (e.g. $L^2$ norm). In this setting, $\mathcal{A}$ is assumed to have access to peripheral information, such as the training data.}
  \label{alg:pgreedy}
  %
  \begin{algorithmic}[1]
    %
    \State {\bf Input:} $ \{ \mlam_{bulk} = \text{basis symbols}$, $\mathcal{A} = \text{action}$, $tol=\text{greedy tolerance}\}$
    \vskip 10pt
    \State Define empty list of kept symbols: $\mlam_{kept} = \{\}$
    \State Initialize estimator value and loop boolean: $\epsilon_{last} = \mathrm{inf}$, $done = \text{False}$
    %
    \While{not $done$}
      \State $\epsilon_{min} = \epsilon_{last}$
      %
      \For { $\mlam$ in $\mlam^{bulk}$ }
        \State $\mlam_{trial} = \mlam_{kept} \cup \mlam$ {\hskip0.525in} (add $\mlam$ to $\mlam_{kept}$)
        \State $\epsilon = \mathcal{A}(\mlam_{trial})$ {\hskip0.70in} (action returns fit error)
        \If { $\epsilon < \epsilon_{min}$ }
          \State $\epsilon_{min} = \epsilon$  {\hskip0.825in} (store trial min)
          \State $\mlam_{min} = \mlam_{trial}$
        \EndIf
      \EndFor
      %
      \State $done = |\epsilon_{min}-\epsilon_{last}|<tol$ %{\hskip0.4in} (determine if estimator has changed significantly)
      \If { not $done$ }
        \State $\epsilon_{last} = \epsilon_{min}$
        \State $\mlam_{kept} = \mlam_{kept} \cup \mlam_{min}$ {\hskip0.4in} (update kept symbols)
      \EndIf
      %
    \EndWhile
    \vskip 10pt
    \State {\bf Output:} $\{ \mlam_{kept} \}$ (the Greedy Basis)
    %
  \end{algorithmic}
  %
\end{algorithm}
}
%
\par The very similar ``negative'' greedy algorithm removes model symbols until representation error increases beyond a specified threshold.
%
%
% \par
%
%
\subsection{Greedy Multivariate Polynomial Fitting}
%
The study of smooth scalar functions (e.g. $f(\vec{x})$) often centers about the Taylor series expansion.
%
In that instance, it is clear that any infinitely differentiable scalar function of many variables can be represented in terms of its derivatives by
%
\begin{align}
  \label{eq:mvt}
  f( \vec{x} + \vec{h} ) &= e^{ \vec{x} \cdot \vec{\nabla}' } \, f(\vec{x}\,') |_{\vec{x}\,'=\vec{h}}
  \\ \nonumber
  &\approx \sum_{k=0}^{K} \, \frac{1}{k!} \, (\vec{x} \cdot \vec{\nabla}')^{k} \, f(\vec{x}\,') |_{\vec{x}\,'=\vec{h}}
\end{align}
%
From the first to second line of \eqn{eq:mvt}, we have used the definition of the exponential function (i.e. its series expansion).
%
In the second line, the equality has been replaced by an approximation as we have limited the linear representation to $K+1$ terms.
%
\par This latter point is key to the perspective of \gmvp{}:
%
given training data thought to be related to a smooth multivariate function, it may, particularly on small scales, be well approximated by a truncated series expansion in an appropriate coordinate basis.
%
% GMVP
\hspace{1cm}
{\scriptsize
\begin{algorithm}[H]
  %
  \caption{\gmvp{}, a degree tempered stepwise algorithm for multivariate polynomial modeling of scalar data.}
  \label{alg:gmvp}
  %
  \begin{algorithmic}[1]
    %
    \State {\bf Input:} $ \{ x, f, $max\_degree = 6$, tol \}$
    \vskip 10pt
    \State Define, $\mlam_{bulk}$, the bulk symbol space, to be the set of all multinomial combinations of basis vectors up to a predefined maximum order.
    \State Define $\mathcal{A}_{\gmvp{}}$ according to Alg. (\ref{alg:A_gmvp}).
    \State Given $max\_degree$, define, ${ D}$, a list of allowed polynomial degrees (e.g. $\{0,1,2,3,4,5,6\}$)
    \For {$d$ \textbf{in}  ${ D}$ }
      \State Define $\mlam_{bulk}^{(d)}$ as all symbols from $\mlam_{bulk}$ with degree less than or equal to current degree: $\mlam^{(d)}_{bulk}$
      \State Using $\mlam_{bulk}^{(d)}$, apply Alg. (\ref{alg:pgreedy}), \pgreedy{}, with $\mathcal{A}_{\gmvp{}}$ to get symbol subset, $\mlam^{(d)}_{opt}$ and estimator val, $\epsilon^{(d)}_{opt}$
      \If { $|\epsilon^{(d)}_{opt}-\epsilon^{(d-1)}_{opt}|<tol$ }
        \State \textbf{break}
      \EndIf
    \EndFor
    \vskip 10pt
    \State {\bf Output:} $\mlam^{(d)}_{opt}$
    %
  \end{algorithmic}
  %
\end{algorithm}
}
%
%
\par \eqn{eq:mvt}'s truncated expansion happens to be a polynomial in at most $N$ variables.
%
In this setting, the uncertainty of which and how many basis terms to include makes this a problem ripe for the application of linear modeling driven by a greedy process, namely \eqn{eq:linsol1} and Alg. (\ref{alg:pgreedy}) .
%
%
% Plots of QNM frequencies
\begin{figure*}[htb]
  %
  \begin{tabular}{ll}
    {\includegraphics[width=0.49\textwidth]{fits_w.pdf}} & {\includegraphics[width=0.49\textwidth]{fits_tau.pdf}}
    % \\
    % \includegraphics[width=0.49\textwidth]{res_w.pdf} & \includegraphics[width=0.49\textwidth]{res_tau.pdf}
    \\
    \hspace{0.35cm}\includegraphics[width=0.43\textwidth]{res_cw_0.pdf} & \hspace{0.3cm}\includegraphics[width=0.43\textwidth]{res_cw_1.pdf}
  \end{tabular}
  %
	\caption{ Fits of dimensionless \qnm{} central frequencies (solid lines) along with select numerical values (grey markers) computed using Leaver's method \cite{Leaver85}.
  %
  Before the application of $\kappa(\j{})$, points are spaced between -\CwFitCalibrationRegion and \CwFitCalibrationRegion according to \CwFitCalibrationRegion times the $\sin$ of a fiducial angle which is uniformly spaced between $-\pi/2$ and $\pi/2$. Values of $\j{}$ are shown in the upper axis for $\kappa$ at $l=m$.
  %
  The grey dashed line marks the value of $\kappa$ where $\j{}=0$. Fits of dimensionless \qnm{} decay rates (solid lines) along with select numerical values (grey markers) computed using Leaver's method \cite{Leaver85}. (Bottom) Percentage absolute residual errors for fits of dimensionless \qnm{} frequencies,, $\cw\lmn$ along with select numerical values (colored markers) computed using Leaver's method \cite{Leaver85}. For comparison, residuals using the models in Ref.~\cite{Berti:2005ys} are shown in gray. }
  %
  \label{fig:qnm}
  %
\end{figure*}
%
\par Here, the basis symbols required by Alg. (\ref{alg:pgreedy}) are the multinomial terms in \eqn{eq:mvt}.
%
Each term is an element of the tensor-product of the power-sets of each model dimension. That is $\mlam_{bulk} = \{x_0,x_1 .. x_N, ... x_0^1, x_0^2, x_0^3, ...  , (x_0^K x_1^K ... x_N^K) \}$.
%
Note that in practice it may be useful to encode elements of $\mlam_{bulk}$ with strings representing their constituents (e.g. $x_0 x_0 x_1 x_2 x_2 x_4$ could be represented by the string ``001224''). This provides a way of bijectively mapping between symbols and numerical basis vectors.
%
\par The action, $\mathcal{A}(\mlam_{trial})$, required by Alg. (\ref{alg:pgreedy}) encompasses the evaluation of \eqn{eq:linsol1} to solve for the basis coefficients, $\mu_k$, and the calculation of the modeling error.
%
An explicit sketch of this is given by Alg. (\ref{alg:A_gmvp}).
%
\par The combination of these two ideas alone results in an algorithm prone to a deficit of stepwise methods: the algorithm may confuse correlated basis vectors (e.g. $x^2$ may be confused with $x^4$).
%
To counter this, we may incrementally increase, or \textit{temper}, the maximum allowed multinomial degree.
%
For example, when iterating through allowed degrees, if the current maximum degree is 3, then degree 4 terms, such as $x_0x_1x_3^2$, will not be considered within the space of model symbols.
%
The degree tempering process halts when increasing the maximum allowed degree has no significant effect on model representation error.
%
\par The combination of degree tempering with the greedy approach results in the \gmvp{} algorithm as presented in Alg. (\ref{alg:gmvp}).
%
%
\subsection{Greedy Multivariate Rational Fitting}
%
%
\par Despite the apparent universality of \eqn{eq:mvt}, there are many cases where $K$ must be orders of magnitude greater than 1 in order for $\vec{f}$ to be accurately represented by a low order multinomial.
%
Worst, in cases where the underlying dataset is best described by a rational function, no polynomial of the same family describing the numerator and denominator will yield satisfactory results in low order (e.g. the well known ``Runge's phenomenon'' \cite{10.2307/2323093}).
%
In general, the optimal polynomial basis may not be clear, and so a more general set of ansatzes may be of use.
%
\par Of the simplest of such ansatzes are rational functions of the form
%
\def\muf{\bar{\mu}}
\def\sif{\bar{\sigma}_f}
\begin{align}
  \label{eq:rat1}
  f(\vec{x}) = \muf + \sif \; \frac{ \sum_{r=0}^{R} a_r \, \phi_{r}(\vec{x}) }{ 1 - \sum_{v=1}^{V} b_v \, \phi_{v}(\vec{x}) } \;,
\end{align}
%
where $\muf$ is the additive mean of $f(\vec{x})$, and $\sif$ is the standard deviation of $f(\vec{x})$, and $\phi_k$ are the multinomials basis functions considered in the previous section.
%
Note that, in \eqn{eq:rat1}, the sum over $v$ does not include the constant term associated with $\phi_0$.
%
\par While it is tempting to embrace \eqn{eq:rat1}'s $f({\vec{x}})$ as a nonlinear function and so resort to nonlinear modeling methods, a reformulation reveals an underlying linear structure \cite{Press:1992:NRC:148286}.
%
Namely, if we let
%
\begin{align}
  g = (f - \muf)/\sif
\end{align}
%
then algebraic manipulation of \eqn{eq:rat1} allows
%
\begin{align}
  \label{eq:rat2}
  g = \sum_{r=0}^{R} a_r \, \phi_{r}(\vec{x}) + g\, \sum_{v=1}^{V} b_v \, \phi_{v}(\vec{x}) \; .
\end{align}
%
We are free to relabel the indices such that \eqn{eq:rat2} is manifestly linear in a single index.
%
At this stage, we will also explicitly consider the $j^\mathrm{th}$ samples of the domain, and so refer to (e.g.) $\vec{x}$ as $\vec{x}_j$.
%
%
\begin{figure*}[htb]
  %
  \includegraphics[width=\textwidth]{issue3_summary.pdf}
  %
	\caption{ Standard summary plot for Greedy Multivariate Rational fitting algorithm (\gmvr) as implemented in \cite{lionel_london_2018_1402516}. (\textit{left}) 3D plot of training data (black dots) and final fit (red mesh). (\textit{center top}) Same as left most panel, but in index space. (\textit{center bottom}) {Percent residual error with respect to validation data (grey blocks) along with uniform (black) and gaussian (red) fits to error. The validation data were generated in the same manner as the training data.} (\textit{top right}) convergence of the $L^2$ norm during iterative refinement. (\textit{bottom right}) Same as top right, but on log scale, where $\epsilon_0$ is the value of $\epsilon$ at the final $k^{\mathrm{th}}$ iteration of refinement. }
  %
  \label{fig:gmvrtoy}
  %
\end{figure*}
%
These adjustments of perspective result in
%
\begin{align}
  \label{eq:rat3}
  g_j = \sum_{k=0}^{R+V} \, z_{k} \, \psi_k(\vec{x}_j) \;,
\end{align}
%
where
%
\begin{align}
  %
  z_k = \left\{ \begin{array}{cc}
        a_k,      & \text{for }0\leq k\leq R\\
        b_k, & \quad \;\; \;\text{for }R+1\leq k\leq R+V
      \end{array} \right\}
\end{align}
%
and
%
\begin{align}
  %
  \psi_k(\vec{x}_j) = \left\{\begin{array}{cc}
        \phi_k(\vec{x}_j),      & \text{for }0\leq k\leq R\\
        \phi_k(\vec{x}_j)\, g_j , & \quad \;\; \;\text{for }R+1\leq k\leq R+V
        \end{array} \right\}
\end{align}
%
\par Recalling \eqns{eq:linsol1}{pinv1}, it follows that the coefficients of interest ($a_k$ and $b_k$), may be estimated according to
%
\begin{align}
  \label{eq:pinv2}
  \vec{\alpha} = \hat{P} \; \vec{g} \;.
\end{align}
%
where, $\hat{P}$ is the pseudo-inverse of the matrix whose elements are $\psi_k(\vec{x}_j)$, $\vec\alpha = ( z_0, z_1, ... z_{R+V-1},z_{R+V} )$, and $\vec{g} = ( g_0, g_1, ... g_{R+V-1},g_{R+V} )$.
%
\par However, we note that $\hat{P}$ depends nontrivially on $g$, and is therefore susceptible to noise in the training data.
%
Let us briefly consider the effect of zero-mean noise on $g$, e.g. $g \rightarrow g+n$.
%
In this, it may be that shown that $n$ may be entirely relegated to $\hat{P}$.
%
It is in this sense that \eqn{eq:pinv2} is insufficient to generally solve for $\vec{\alpha}$, as $\hat{P}$ may be adversely affected by noise.
%
%
\par The key to robustly solving for $\vec{\alpha}$ lies in iterative refinement \cite{Press:1992:NRC:148286}.
%
Specifically, we note that \eqn{eq:rat2} may be modified to iteratively minimize the impact of numerical noise on $\hat{P}$.
%
That is, to reduce the impact of noise on $\hat{P}$, we are free to calculate it using model evaluations of $g$ rather than the original (noisy) training data.
%
If we define $g^{(0)}=g$ (i.e. $g$ is the training data), with $\hat{P} = \hat{P}( \vec{g}^{\,(n)} )$, then \eqn{eq:pinv2} generalizes to
%
\begin{align}
  \label{eq:pinv3}
  \vec{\alpha}^{(n+1)} = \hat{P}(\vec{g}^{\,(n)}) \, \vec{g}^{(0)}\;.
\end{align}
%
In practice, one solves \eqn{eq:pinv3} for $\vec{\alpha}^{(n+1)}$, and then uses the related $a_r^{(n+1)}$ and $b_v^{(n+1)}$ to calculate $g^{(n+1)}$ via
%
\begin{align}
  \label{eq:rat4}
  g^{(n+1)} =  \frac{ \sum_{r=0}^{R} a^{(n+1)}_r \, \phi_{r}(\vec{x}) }{ 1\;-\;  \sum_{v=1}^{V} b^{(n+1)}_v \, \phi_{v}(\vec{x}) } \; .
\end{align}
%
Subsequently, $g^{(n+1)}$ is then fed back into \eqn{eq:pinv3} for further refinement.
%
The refinement process is to terminate when a measure of model error (e.g. the $L^2$ norm $||g^{(0)}-g^{(n)}||$) passes a predetermined threshold.
%
%
%
% \hspace{1cm}
{\scriptsize
\begin{algorithm}[H]
  %
  \caption{$\mathcal{A}_{\gmvp}$, the action for \gmvp. Model calculation given basis symbols, and output of model error estimate.}
  %
  \label{alg:A_gmvp}
  \begin{algorithmic}[1]
    %
    \State {\bf Input:} $\mlam_{trial}$
    \vskip 10pt
    \State Calculate $\mu_k$ via \eqn{eq:linsol1}.
    \State Calculate the model representation error, e.g.: $\epsilon = ||\hatU \vecmu - \vec{f}||/||\vec{f}||$, where $||a||$ is the $L^2$ norm of $a$.
    \vskip 10pt
    \State {\bf Output:} $\epsilon$
  \end{algorithmic}
\end{algorithm}
}
%
\par Much as in the case of multivariate polynomial fitting, we are left with an unknown number and content of basis symbols.
%
In principle, the existence of $a_r$ and $b_v$ makes the problem more complicated, as one might imagine optimizing over each symbol space independently.
%
To broach this complications, we again use a greedy algorithm with degree tempering.
%
However, rather than independent greedy optimizations for the numerator and denominator bases symbols, \eqn{eq:rat3} suggests that the appropriate labeling of symbols (e.g. ``numerator'' or ``denominator'') may yield an effective flattening of the supposed 2D symbol selection problem.
%
Put another way, rather than two simultaneous greedy optimizations over $R+1$ and $V$ symbols (with $(R+1)V$ iterations), a single greedy process over $V+R+1$ symbols is performed, where each symbol is additionally labeled as being in the numerator or denominator.
%
\par With these conceptual tools in hand, we may proceed to constructing \gmvr{} by first defining its action, $\mathcal{A}_{\gmvr}$.
%
This is done in Alg. (\ref{alg:A_gmvr}).
%
\par The combination of \eqn{eq:pinv3} and \eqn{eq:rat4}, along with \pgreedy{} and degree tempering, results in the \gmvr{} algorithm as presented in Alg. (\ref{alg:gmvr}).
%
%
Both \gmvp{} and \gmvr{} are publicly available on Github through the \texttt{positive} repository (Ref. \cite{lionel_london_2018_1402516}), and may be imported in python via {\small{\texttt{positive.learning.gmvpfit}}} and {\small{\texttt{positive.learning.gmvrfit}}}.
%
%
\section{Results}
\label{results}
%
\par We briefly review the application of \gmvr{} to a toy problem wherein a scalar rational function of two variables is treated.
%
% Cross validation and removal of the last added basis symbol are used to assess model accuracy.
%
% \par
%
We then present two applications to \gw{s}.
%
First we apply \gmvp{} to the modeling of complex valued Kerr \qnm{} frequencies.
%
Second, we apply \gmvr{} to the modeling of spin -2 spherical-spheroidal harmonic mixing coefficients (\ceqn{sigma}).
%
While only 1D and 2D domains are treated here, we note that Ref. \cite{London:2018gaq} has used a version of \gmvp{} to model the \qnm{} excitation amplitudes in a 4D parameter space.
%
\subsection{\gmvr{} Toy Problem}
%
Here, our goal is to very briefly overview the functionality of the \gmvr{} algorithm as implemented in Ref. \cite{lionel_london_2018_1402516}.
%
While it is possible to investigate the output of \gmvr{} with varying hyper-parameters (such as the tolerance input to Alg. \ref{alg:gmvr}), we will focus only on a simple usage case.
%
Similarly, we note that \gmvr{} as implemented in Ref. \cite{lionel_london_2018_1402516} involves a negative greedy phase to counter over-modeling in cases where the aforementioned $tol$ is too low.
%
For relevance of presentation to physics examples in subsequent sections, we will restrict ourselves to a case where numerical noise is low, and the negative greedy step does not alter the output of Alg. \ref{alg:gmvr}.
%
%
\par Let us now consider the application of \gmvr{} to a fiducial scalar function of the form
%
\begin{align}
  %
  f(x_0,x_1) = \mu + \sigma \, \left( \, \frac{a_0 +a_1  x_0 + a_2 x_1 + a_3 x_0 x_1}{ 1 + b_1 \, x_0^2 +  b_2 x_1^2 } \, \right) + 0.05 \, n \; ,
\end{align}
%
where $n$ is a uniform random variable on $[-1,1]$.
%
Towards easily identifying test values for $a_j$ and $b_k$ with those recovered, it is more straightforward to distribute $\sigma$ to the denominator, yielding
%
\begin{align}
  \label{eq:gmvrtoy1}
  f(x_0,x_1) = \mu + \, \frac{a_0 +a_1  x_0 + a_2 x_1 + a_3 x_0 x_1}{ 1/\sigma + (b_1/\sigma) \, x_0^2 +  (b_2/\sigma) x_1^2 } + 0.05 \, n \; .
\end{align}
%
Under this perspective we will consider test data generated with the parameters listed in \tbl{tb:gmvrtoy}'s left two panels.
%
\par To generate the test data, \eqn{eq:gmvrtoy1} is evaluated with 25 points along $x_0$ and $x_1$ (with $25^2$ total points), where each is between -3 and 3. Though not a requirement of \gmvr{}, for simplicity of presentation, domain points are equally spaced.
%
\par \fig{fig:gmvrtoy} shows the application of \gmvr{} to this fiducial dataset.
%
\fig{fig:gmvrtoy}'s central bottom panel displays the distribution of percentage residuals with respect to validation data generated in the same manner as training data.
%
A gaussian fit to the fractional residuals is displayed for comparison.
%
In particular, despite the uniform nature of the underlying noise distribution, a biased fit will often have residuals that are approximately gaussian.
%
We see that this is not the case here, and that the uniformly random noise distribution is approximately recovered.
%
Moreover, when considering many noise realizations to generate validation data, we find that sample noise and residuals have an average correlation of $99.46\%$.
%
\par \fig{fig:gmvrtoy}'s right top and bottom panels show the convergence of Alg. (\ref{alg:A_gmvr})'s iterative refinement stage (i.e. its while-loop).
%
Here it is demonstrated that \gmvr{} converges in a way that is approximately exponential, owing to the underlying analytic nature of the training data.
%
\tbl{tb:gmvrtoy} demonstrates \gmvr{}'s accurate recovery of the underlying model parameters.
%
We note that \gmvr{}'s initial output contains terms in the numerator which correspond to the addition of a constant to the overall model, thus correcting for the difference between the offset parameter, $\mu$, and the true, but arbitrary, mean of the dataset.
%
\tbl{tb:gmvrtoy} presents recovered model parameters after this effect has been accounted for with simple algebraic manipulation.
%
%
% $\mu = 50.0$,
% %
% $a_0 = 1.1$,
% %
% $a_1 = 0.2$,
% %
% $a_2 = 0.5$,
% %
% $a_3 = 1.0$,
% %
% $1/\sigma = 0.9$,
% %
% $b_1/\sigma = b_2/\sigma = 1.0$.
%
\begin{table}
  \caption{Summary of recovered model parameters for \gmvr{} toy problem.}
  \label{tb:gmvrtoy}
  \begin{tabular}{|c|c|c|c|}
    \hline
    \hline
    Parameter & Training Value & Modeled Value & Difference \\ \hline \hline
    $\mu$ & 50.0 & 49.9915 & 0.0171 \% \\ \hline
    $a_0$ & 1.1 & 1.1374 & 3.4002 \% \\ \hline
    $a_1$ & 0.2 & 0.2000 & 0.0000 \% \\ \hline
    $a_2$ & 0.5 & 0.5068 & 1.36784 \% \\ \hline
    $a_3$ & 1.0 & 1.0063 & 0.6300 \% \\ \hline
    $1/\sigma$ & 0.9 & 0.9375 & 4.1612 \% \\ \hline
    $b_1/\sigma$ & 1.0 & 0.9941 & 0.5906 \% \\ \hline
    $b_2/\sigma$ & 1.0 & 1.0000 & 0.0000 \% \\ \hline
    \hline
  \end{tabular}

\end{table}
%
%
\par In this rudimentary example case, \gmvr{} correctly recovers the functional form of the input data, and accurately recovers the correct values of model parameters.
%
But, in general, \gmvr{} and related techniques, having no knowledge of the underlying noise distribution, will attempt to model minor correlations and offsets within the training data's noise.
%
However, we have demonstrated the utility of \gmvr{} in a relatively ideal usage case where the underlying function is rational, and the training data is only weakly contaminated with noise.
%
\par In the following sections, we consider realistic, but similarly ideal cases, where the functional form of the sample data is not known to be explicitly polynomial or rational, but the amount of noise within the training data is negligible.
%
\begin{figure}[htb]
  %
  \includegraphics[width=0.45\textwidth]{issue3_pgreedy.pdf}
	\caption{ Convergence of greedy process for \gmvr{} toy problem. }
  %
\end{figure}
%
%
%
%
% %%%%%%
\subsection{Modeling \qnm{} frequencies with \gmvp{}}
% %%%%%%
%
%
%
In seeking to apply \gmvp{} to select \qnm{} frequencies, we wish to account for the known extremal Kerr behavior of some modes.
%
Namely, we will impose a zero-damping constraint: some frequencies are real as $\jf \rightarrow 1$ \cite{Zimmerman:2015trm}.
%
We also wish to impose a domain transformation, $\kappa(\jf,\ell,m)$, such that $0 \leq \kappa \leq 1$ and the individual \qnm{} frequencies are made approx. polynomial in $\kappa$.
%
\par For the domain transformation, inspection of \qnm{} frequencies with $\ell \leq 5$ suggest that
%
\begin{align}
  \label{eq:kappa}
  \kappa(\jf,\ell,m) = \left( \log_3( 2 - \jf ) \right)^{1/(2+\ell-|m|)}
\end{align}
%
appropriately linearizes the sharp behavior of each frequency near $\jf=1$ while also mapping $-1 \le \jf \le 1$ onto $0 \le \kappa \le 1$.
%
\par Towards the zero-damping constraint, when considering a \qnm{} frequency $\cw_{\lmn}$, zero-damping at $\jf=1$ implies that $\cw_{\lmn}(\kappa \approx 0)-m/2 \propto \kappa$, where $m/2$ is the well known limiting value for each \qnm{} frequencies real part as $\jf\rightarrow 1$.
%
This implies that
%
\begin{align}
  \label{eq:zd}
  \cw_{\lmn} = m/2 + \kappa \sum_{j=1}^{J} c_j \kappa^k \; .
\end{align}
%
In the case of the non-zero damped \qnm{s}, (e.g. $(\ell,m)=(3,2)$), a more general polynomial form may be adopted, namely,
%
\begin{align}
  \label{eq:nzd}
  \cw_{\lmn} = \sum_{j=0}^{J} c_j \kappa^k \; .
\end{align}
%
\par The polynomial content of \eqn{eq:zd} and \eqn{eq:nzd} is determined by \gmvp{}.
%
\eqns{eq:cw_fit_1}{eq:cw_fit_9} display the resulting polynomial models.
%
In particular, the domain map allows most \qnm{} frequencies to be well modeled by 4th order polynomials which include all lower degree terms; concurrently, the real and imaginary parts of each $\cw\lmn$ are modeled simultaneously.
%
\par \fig{fig:qnm} displays select training points, as well as model fits for $\cw\lmn$'s real and imaginary parts.
%
For the top right and top left panels, the simple polynomial behavior of each curve is a result of the displayed linear domain in $\kappa(\jf,\ell,m)$.
%
In the top left panel, we have scaled $1/\tau\lmn$ by factors for $m/(n+1/2)$ to place the \qnm{s} with $n=0$ and $n=1$ at approximately the same scale.
%
% Equations for QNM frequency fits
\begin{widetext}
	\input{cwfit_eqns}
\end{widetext}
%
\par \fig{fig:qnm}'s top left and right panels' upper axes demonstrate the effect of mapping $\jf$ onto $\kappa$.
%
In particular, it is shown that the two branches (namely $\jf>0$ and $\jf<0$) naturally form a single family of solutions when accounting for the sign of the \bh{}'s oriented spin \cite{Husa:2007hp}.
%
Concurrently, the use of $\kappa$ as a domain variable has the desirable effect of making each $\cw\lmn$ and $\tau\lmn$ approximately polynomial.
%
We note that, in the asymptotic vicinity of $\jf=1$, the \qnm{} frequencies and decay times are known to have solutions that are asymptoticly degenerate \cite{Zimmerman:2015rua}.
%
{\scriptsize
\begin{algorithm}[H]
  %
  \caption{$\mathcal{A}_{\gmvr}$, the action for \gmvr. Model calculation given basis symbols, and output of model error estimate.}
  %
  \label{alg:A_gmvr}
  \begin{algorithmic}[1]
    %
    \State {\bf Input:} \{ $\mlam_{trial}$, $tol=10^{-3}$ \}
    \vskip 10pt
    \State Calculate $\alpha^{(1)}_k$ via \eqn{eq:pinv3}. Implicitly, $n=1$.
    \State Calculate the current model prediction $g^{(1)}$ via \eqn{eq:rat4}.
    \State Calculate the model representation error, e.g.: $\epsilon^{(1)}  = ||var(g^{(n)} - g^{(0)})||/||g^{(0)}||$, where $var$ is the variance.
    \State $done = False$
    \While { not $done$ }
      \State Calculate $\alpha^{n+1}_{k}$  via \eqn{eq:pinv3}.
      \State Calculate the current model prediction $g^{(n)}$ via \eqn{eq:rat4}.
      \State Calculate the model representation error, e.g. $\epsilon^{(n)} = ||g^{(n)} - g^{(0)}||/||g^{(0)}||$.
      \State $done = |\epsilon^{(n-1)}-\epsilon^{(n)}| < tol$
      \State (Implicitly, $n = n+1$)
    \EndWhile
    \vskip 10pt
    \State {\bf Output:} $\epsilon^{(n)}$
  \end{algorithmic}
\end{algorithm}
}
% \end{widetext}
%
In allowing \eqns{eq:cw_fit_1}{eq:cw_fit_9} to extrapolate to $\jf=1$, we do not explicitly account for this additional effect.
%
\par \fig{fig:qnm}'s bottom two panels show absolute fractional residual errors of the complex frequency, $\cw\lmn = \omega\lmn + i/\tau\lmn$.
%
Although each model's fractional error is within 1\% of the perturbation theory result, each is dominated by systematic error due to the choice fitting ansatz.
%
For comparison, the same residual errors are shown in gray for the model presented in Ref.~\cite{Berti:2005ys};
%
here, the sharp feature near $\jf=0$ results from their modeling counter and co-rotating \qnm{} as two different curves.
%
\par Together, \eqns{eq:cw_fit_1}{eq:cw_fit_9} along with \fig{fig:qnm} present precise and accurate fits for the real and imaginary parts of \qnm{} frequencies for gravitational perturbations of Kerr \qnm{s}.
%
A \texttt{Python} implementation of \eqns{eq:cw_fit_1}{eq:cw_fit_9} is available in Ref.~\cite{lionel_london_2018_1402516} via \texttt{positive.physics.cw181003550}.
%
%
\subsection{Modeling spherical-spheroidal inner-products with \gmvr{}}
%
%
Here we apply \gmvr{} to the spherical-spheroidal mixing coefficients, $\sigma_{\LMlmn}$.
%
As in the case of the \qnm{} frequencies, we use the domain transformation defined by \eqn{eq:kappa} to simplify the functional form of each $\sigma_{\LMlmn}$.
%
\par While it is possible to enforce extremal Kerr and Schwarzschild limiting conditions for $\sigma_{\LMlmn}$, we find it effective to first use \gmvr{} to determine a functional form that works for {individual} $\sigma_{\LMlmn}$, and then from these ansatz develop a single ansatz for all $\sigma_{\LMlmn}$.
%
\eqns{eq:ys22220}{eq:ys55550} present the resulting model equations.
%
A \texttt{Python} implementation of \eqns{eq:ys22220}{eq:ys55550} is available in Ref.~\cite{lionel_london_2018_1402516} via \texttt{positive.physics.ysprod181003550}.
%
%
\par \fig{fig:ys} displays fits, training data and related residuals.
%
For efficiency of presentation, each $\sigma_{\LMlmn}$ is plotted via its real and imaginary part.
%
% Plots of mixing coefficients
\begin{figure*}[htb]
  %
  \begin{tabular}{ll}
    \hspace{-0.21cm}\includegraphics[width=0.48\textwidth]{issue2_ysprod_1.pdf} & \includegraphics[width=0.48\textwidth]{issue2_ysprod_2.pdf} \\
    \includegraphics[width=0.48\textwidth]{issue2_ysprod_3v2.pdf} & \hspace{0.3cm}\includegraphics[width=0.48\textwidth]{issue2_ysprod_4v2.pdf}
  \end{tabular}
  %
	\caption{ Spherical-spheroidal harmonic mixing coefficients and percentage residual errors for spherical-spheroidal harmonic mixing coefficient fits. (\textit{Top Left}) Mixing coefficients for cases where $(\bar{\ell},\bar{m})=(\ell,m)$. The dashed horizontal intersects each curve at the Schwarzschild limit where $\jf=0$. (\textit{Top Right}) Mixing coefficients where $(\bar{\ell},\bar{m})\neq(\ell,m)$. (\textit{Bottom Left and Right}) Factional residuals for mixing coefficient fits. For comparison, residual errors for the fits in Ref.~\cite{Berti:2014fga} are also shown over their region of validity in \bh{} spin. Note that makers match between grey and colored data points. }
  %
  \label{fig:ys}
  %
\end{figure*}
%
In cases where $(\bar\ell,\bar{m})=(\ell,m)$, the real part of $\sigma_{\LMlmn}$ varies about unity in a manner consistent with the Schwarzschild limit, where $\sigma_{\LMlmn}=\delta_{\bar\ell}^{\ell}\;\delta_{\bar{m}}^{m}$.
%
Consistency with the Schwarzschild limit is equally true in cases where $(\bar\ell,\bar{m}) \neq (\ell,m)$.
%
As with the \qnm{} frequencies, residuals are dominated by small scale oscillations with amplitudes that are fractions of a percent of the central values, and largely result from the model asatz.
%
For comparison, fractional residual errors for models in Ref.~\cite{Berti:2014fga} are also shown.
%
\section{Discussion}
\label{discuss}
%
\par We have developed upon previous techniques for the linear and pseudo-linear modeling of low noise data.
%
In particular, the \gmvp{} algorithm performs multivariate polynomial modeling of real and complex valued scalar functions with no inherent limitation on the number of domain parameters.
%
The \gmvr{} algorithm does the same with multivariate rational functions.
%
When applied to the modeling of analytically computed quantities, both algorithms perform extremely well in producing accurate and precise representations of training data, suggesting extended applicability of \gmvr{} and \gmvp{} to similar problems.
%
\par Treating a toy problem with \gmvr{} demonstrates its ability to faithfully recover underlying model parameters for a plausible dataset.
%
This treatment also demonstrates the convergence of the algorithm's greedy phase with increasing iterations, as well as the convergence of an underlying iterative refinement phase (\ceqn{eq:rat4}).
%
%
%
\par Both \gmvp{} and \gmvr{} may be used to automatically determine the functional form and model for a given dataset that is expected to be respectively polynomial or rational.
%
An alternative use-strategy is to use either \gmvp{} or \gmvr{} to determine a fitting ansatz for individual cases (e.g. individual \qnm{s}), and then use these results to develop a single ansatz for all cases.
%
This is what as been done for the modeling of \qnm{} frequencies and spherical-spheroidal mixing coefficients.
%
%
\par \gmvp{} has been applied to the modeling of \qnm{} frequencies. The resulting models have been constrained in the extremal Kerr limit, and perform well compared to similar fits in the literature.
%
The fits presented here are of direct use in Ref. \cite{London:2017bcn}, where efficiently evaluable \qnm{} frequencies are required to generate template waveforms for \gw{} searches and parameter estimation.
%
The fits presented may find future use in Phenom or EOB based \gw{} models.
%
\par \gmvr{} has been applied to the modeling of mixing coefficients between the spherical and spheroidal harmonics.
%
% GMVR
% \hspace{1cm}
{\scriptsize
\begin{algorithm}[H]
  %
  \caption{\gmvr{}, a degree tempered stepwise algorithm for multivariate rational modeling of scalar data.}
  \label{alg:gmvr}
  %
  \begin{algorithmic}[1]
    %
    \State {\bf Input:} $ \{ x, f, $max\_degree = 6$, tol \}$
    \vskip 10pt
    \State Define, $\mlam_{bulk}$, the bulk symbol space, to be the set of all multinomial combinations of basis vectors up to a predefined maximum order. This is the combined symbol space for numerator and denominator symbols.
    \State Define $\mathcal{A}_{\gmvr{}}$ according to Alg. (\ref{alg:A_gmvr}).
    \State Given $max\_degree$, define, ${ D}$, a list of allowed polynomial degrees (e.g. $\{0,1,2,3,4,5,6\}$)
    \For {$d$ \textbf{in}  ${ D}$ }
      \State Define $\mlam_{bulk}^{(d)}$ as all symbols from $\mlam_{bulk}$ with degree less than or equal to current degree: $\mlam^{(d)}_{bulk}$
      \State Using $\mlam_{bulk}^{(d)}$, apply Alg. (\ref{alg:pgreedy}), \pgreedy{}, with $\mathcal{A}_{\gmvp{}}$ to get symbol subset, $\mlam^{(d)}_{opt}$ and estimator val, $\epsilon^{(d)}_{opt}$
      \If { $|\epsilon^{(d)}_{opt}-\epsilon^{(d-1)}_{opt}|<tol$ }
        \State \textbf{break}
      \EndIf
    \EndFor
    \vskip 10pt
    \State {\bf Output:} $\mlam^{(d)}_{opt}$
    %
  \end{algorithmic}
  %
\end{algorithm}
}
%
These fits are of direct use in Ref. \cite{Carullo:2018sfu}, and may be of future use in similar ringdown-only models for the purpose of testing \gr{}.
%
\par While \gmvr{} and \gmvp{} show promise in the cases shown here, in their presented rudimentary form, both posses a number of limitations.
%
If given sufficiently dense training data, neither currently performs cross-validation.
%
And perhaps most notably, neither method directly accounts for information about the noise distribution within the training data.
%
As such, the methods presented are recommended primarily for datasets where noise is very small or negligible.
%
Nevertheless, the \gmvr{} toy problem demonstrates \gmvr{}'s ability to handle moderately noisy training data, suggesting current applicability to a variety of problems where polynomial interpolation is insufficient.
%
\par Of relevance to current and future \gw{} science, the models presented for \qnm{} frequencies and harmonic mixing coefficients have aided (e.g. Refs. \cite{Carullo:2018sfu,London:2018gaq,London:2017bcn} ), and are expected to continue aiding the development and implementation of \gw{} signal models.

%--%%----%%----%%----%%----%%----%%----%%--%
\section*{Acknowledgements}
%--%%----%%----%%----%%----%%----%%----%%--%
%
The authors thank Mark Hannam for useful discussions.
%
The work presented in this paper was supported by Science and Technology Facilities Council (STFC)
grant ST/L000962/1, and European Research Council Consolidator Grant 647839.
%

\newpage

%
\appendix

%
\newpage
\section{Additional Equations}
\label{app:eqns}

%
% Equations for mixing coefficients
%
\begin{widetext}
  \input{ysprod_eqns}
\end{widetext}

% \section{Figures}
% \label{app:figs}

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

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\newpage
% \bibliographystyle{ieeetr}
\bibliographystyle{mnras}
\bibliography{mvf.bib}
\end{document}


\chapter{Exact inference for graphical models}


\documentclass{report}

\usepackage{color}
\usepackage{verbatim}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{esint}

\newcommand{\ket}[1]{\vert{#1}\rangle}
\newcommand{\bra}[1]{\langle{#1}\vert}
\newcommand{\rr}{{\bf r}}
\newcommand{\wvdw}{{$\tt{w90vdw}$}}
\newcommand{\wannier}{{$\tt{wannier90}$}}

\begin{document}

\normalsize

\chapter*{Calculating van der Waals energies using MLWFs}
\addtocounter {chapter} {1}

\section{Introduction}

This document describes the implementation of a method for calculating
van der Waals energies based on the idea of density decomposition. For
theoretical details, we refer the user to the following publication:\\

Lampros Andrinopoulos, Nicholas D. M. Hine and Arash A. Mostofi,
``Calculating dispersion interactions using maximally localized Wannier functions'',
\emph{J. Chem. Phys.} \textbf{135}, 154105 (2011), hereafter referred
to as ``AHM11''. \\

The code that calculates the van der Waals energy is called
\wvdw\ and should be run separately after a \wannier\ run.\\

Please report comments, bugs or suggestions to the \wannier\ mailing
list.

\section{Compilation}

\wvdw\ does not use any special mathematical libraries and may be
compiled simply using

\begin{verbatim}
$> ifort -o w90vdw.x w90vdw.f90
\end{verbatim}

or equivalent.

\section{Additional parameters in \wannier}

\subsection{$\tt{logical :: write\_vdw\_data}$}

Default value is $\tt{false}$. If $\tt{true}$, then \wannier\ will
write a prototype input file, $\tt{seedname.vdw}$, for
\wvdw.

Dependencies:
\begin{itemize}
\item Gamma-only sampling
\item If disentanglement is being used, then $\tt{num\_valance\_bands}$, the
  total number of valence bands in the calculation,
  must be set in $\tt{seedname.win}$.
\item If the system is spin-polarised, then
  $\tt{num\_elec\_per\_state}$, the number of electrons per band/state,
  should be set to $\tt{1}$ in
  $\tt{seedname.win}$. The default value is $\tt{2}$.
\end{itemize}

\section{The \wvdw\ utility}
The \wvdw\ utility can be used to calculate the van der Waals energy
using the centres, spreads and diagonal occupations obtained from
\wannier. This information is written by \wannier\ to
$\tt{seedname.vdw}$ if $\tt{write\_vdw\_data = true}$.

With only a few required modifications by the user (see below),
\wvdw\ reads $\tt{seedname.vdw}$ as an input file and outputs
the vdW energy and $C_{6\rm {eff}}$ of the system in atomic units (Ha
and Ha~a$_0^6$, respectively).

\subsection{Input file}

\wvdw\ reads the input file line by line, so care must be taken with
the ordering of the keywords and values!

The format of the input file is

\begin{verbatim}
disentangle T
amalgamate F
degeneracy  2
num_frag 2
num_wann
 18  18
tol_occ 0.9
pxyz
F F T
F F T
tol_dist 0.05
centres_spreads_occ
ang
 6.8742130670  9.1496672772  7.9865298439  0.5940909695   0.99883400
 5.8247042551  7.3317119345  7.9865426308  0.5941494255   0.99883324
 .
 .
 .
\end{verbatim}

Each line is described in more detail below:

\begin{itemize}
\item $\tt{disentangle}$: logical; allowed values $\tt{T}$ or
  $\tt{F}$; whether MLWFs are disentangled (ie, partially occupied) or
  not
\item $\tt{amalgamate}$: logical; allowed values $\tt{T}$ or
  $\tt{F}$; whether to amalgamate co-centric MLWFs into a single MLWF
  with averaged centre and spread
\item $\tt{degeneracy}$: real; for spin-polarised systems should be 1,
  for spin-degenerate systems 2
\item $\tt{num\_frag}$: integer; the number of molecular fragments in
    the system
\item $\tt{num\_wann}$: the following line contains
  a list of $\tt{num\_frag}$ integers that
  specify the number of MLWFs in each molecular fragment
\item $\tt{tol\_occ}$: real; MLWFs with occupancy less than this value
  will be assumed to be $p$-like atomic orbitals and will be split
  into two separate $s$-like orbitals. Only used if $\tt{disentangle
    T}$.
\item $\tt{pxyz}$: $\tt{num\_frag}$ following lines,
  each on a separate line, that specify the direction in which
  $p$-splitting should be performed for each molecular fragment. Each line
  is a logical vector of length 3. For example,
  ``$\tt{F\ F\ T}$" corresponds to the z-direction; `$\tt{T\ F\ F}$" to the x-direction,
  etc. Only used if $\tt{disentangle
    T}$.
\item $\tt{tol\_dist}$: real; distance threshold (in bohr) determining whether
  MLWFs are co-centric. Only used if $\tt{amalgamate T}$.
\item $\tt{centres\_spreads\_occ}$: the first following line
   specifies the units in which the subsequent entries
  and are specified. Allowed values are $\tt{ang}$,
  $\tt{bohr}$. The next lines, one line for each MLWF,
  specify the Cartesian co-ordinates of the centre, the quadratic
  spread, and the occupancy. \textbf{This data must be ordered by molecular
    fragment, i.e., the MLWFs of the first fragment sequentially grouped together
    first, those of the second fragment grouped next, etc.}
\end{itemize}

While \wannier\ will write the $\tt{seedname.vdw}$ file
automatically, a number of the parameters must checked and modified by hand
prior to running \wvdw. In particular, $\tt{amalgamate}$,
$\tt{num\_frag}$, $\tt{num\_wann}$, $\tt{tol\_occ}$, $\tt{pxyz}$,
  $\tt{tol\_dist}$ and the ordering of the
  $\tt{centres\_spreads\_occ}$ block of data.

The programme is then run simply as

$\tt{\$>}$ \wvdw$\tt{.x}$ $\tt{seedname.vdw}$

and the output is written to a file $\tt{seedname.vdw.out}$.

\section{Example: benzene dimer}

We use the example of a benzene dimer in the ``S''
configuration.

\subsection{Valence (fully occupied) MLWFs}

Directory for files: $\tt{utility/wvdw/examples/benzene\_s\_val/}$

Each benzene molecule has 15 valence MLWFs (see Fig.~8 of AHM11).  The
$\tt{.mmn}$, $\tt{.amn}$, $\tt{.eig}$ and $\tt{.win}$ files are
provided. The $\tt{.mmn}$ file will need to be gunzipped.

First, run

$\tt{\$>}$ \wannier\ $\tt{seedname}$

This will generate $\tt{seedname.vdw}$. Copy this to a new file
$\tt{seedname.in.vdw}$:

$\tt{\$> cp\ seedname.vdw\ seedname.in.vdw}$

and edit $\tt{seedname.in.vdw}$ to ensure that the two molecular
fragments are specified correctly, and to group the data corresponding
to the MLWF centres, spreads and occupancies by molecular fragment.

Then run

$\tt{\$>}$ \wvdw$\tt{.x}$ $\tt{seedname.in.vdw}$

The output is written to a file $\tt{seedname.in.vdw.out}$ and the van der Waals
energy and effective $C_6$ coefficient appears towards the bottom.

Reference output files can be found in  $\tt{utility/wvdw/examples/benzene\_s\_val/ref/}$.

\subsection{Disentangled (partially occupied) MLWFs}

Directory for files: $\tt{utility/wvdw/examples/benzene\_s\_cond/}$

If we now consider higher-lying states (keeping the valence manifold
explicitly included using a frozen window), we may disentangle 18
partially occupied MLWFs per molecule that, unlike the valence-only
case, retain the symmetry of the molecule.

First, run

$\tt{\$>}$ \wannier\ $\tt{seedname}$

This will generate $\tt{seedname.vdw}$. Copy this to a new file
$\tt{seedname.in.vdw}$:

$\tt{\$> cp\ seedname.vdw\ seedname.in.vdw}$

and edit $\tt{seedname.in.vdw}$ to ensure that the two molecular
fragments are specified correctly and to group the data corresponding
to the MLWF centres, spreads and occupancies by molecular fragment.

In addition, as disentanglement is being used, the direction for
$p$-orbital splitting for each fragment and occupancy threshold for
applying the splitting on MLWFs will need to be set appropriately.

The MLWFs centred on the C atoms are of atomic $p$-like character and,
according to the methods described in AHM11, they are split into two
lobes of $s$-like character, which is done by specifying in the input file
the direction in which the $p$-orbital lobes point.

In this particular example, the benzene molecules are in
the $x$-$y$ plane and the $p$-orbitals point along the $z$-direction,
hence this is the direction in which all the $p$-orbitals must be
split. Hence, the lines following $\tt{pxyz}$ in the input file
should read $\tt{F\ F\ T}$.

The orbitals that need to be split are easily identified in
$\tt{seedname.vdw}$ by their occupancies, which will be around
0.5. Hence a value of between 0.6 and 0.9 for $\tt{tol\_occ}$ should
enable the code to apply the splitting algorithms to the $p$-orbitals
and not the others.

Once $\tt{seedname.in.vdw}$ has been correctly modified, run

$\tt{\$>}$ \wvdw$\tt{.x}$ $\tt{seedname.in.vdw}$

As before, the output is written to a file $\tt{seedname.in.vdw.out}$
and the van der Waals energy and effective $C_6$ coefficient appears
towards the bottom.

Reference output files can be found in
$\tt{utility/wvdw/examples/benzene\_s\_cond/ref/}$.

\subsection{Spin polarised systems}

For spin-polarised systems, two separate W90 runs are required for
each spin channel (up/down), so care must be taken with the following:

\begin{itemize}
\item The number of electrons per cell, $\tt{num\_valence\_bands}$,
may differ in the up/down cases.

\item The number of electrons per state, $\tt{num\_elec\_per\_state}$,
has to be set to $\tt{1}$ ($\tt{2}$ is the default value).

\item There will be two input files generated, namely
$\tt{seedname\_up.vdw}$ and $\tt{seedname\_dn.vdw}$.
These have to be merged into one input file for the
vdW utility, and the centres sorted by fragment as before.

\item The $\tt{amalgamate}$ keyword in the input file has to be set
to $\tt{T}$ so that cocentric MLWFs are amalgamated into one.

\item The number of MLWFs per fragment, $\tt{num\_wann}$, should
be changed in the input file to the original number of MLWFs used
in Wannier90 for both up/down calculations.
\end{itemize}

\end{document}


\documentclass[12pt]{article}

\setlength\parindent{0pt}

\usepackage[margin=0.8in]{geometry}
\usepackage{graphicx}
\usepackage{framed}
\usepackage[tiny]{titlesec}
\usepackage{amsmath}
%\usepackage[toc,page]{appendix}

%\titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt %minus 2pt}

\title{Fluid simulation}
\author{Valentin Miu}
\date{}

%\titleformat{\section}
%{\normalfont\medium\bfseries}{\thesection}{1em}{}

\makeatletter
\setlength{\@fptop}{0pt}
\makeatother

\begin{document}
\maketitle

\begin{abstract}
This essay presents summarizes several basic concepts of fluid simulations, discusses treatment of different types of fluids, and ...
\end{abstract}

\section{Introduction}

...history

\section{The Navier-Stokes equations}

Liquid fluids, and to a lesser extend gases, can be considered incompressible in most simulations. The behaviour of incompressible fluids are given by the Navier-Stokes equations (\ref{eq:NS1},~\ref{eq:NS2}):

\begin{equation}
\frac{\delta\vec{u}}{\delta t}+\vec{u}\cdot\nabla\vec{u}+\frac{1}{\rho}\nabla p=\vec{g}+\nu\nabla\cdot\nabla\vec{u}
\label{eq:NS1}
\end{equation}
\begin{equation}
\nabla\cdot\vec{u}=0
\label{eq:NS2}
\end{equation}

%[eulerian vs semi-lagrangian]

The Navier-Stokes equation can be solved from the Eulerian or Lagrangian viewpoints. In the former, the quantities are sampled at fixed points; in the latter, the quantities are sampled at the positions of particles moving with the flow (the ``snowman POV" and the ``snowflake POV", respectively). As a result, fluid simulations can be grid-based (for Eulerian) or particle-based (for Lagrangian). In many cases, the two are used in combination or in hybrid algorithms[2-way coupled SPH]. ()

\section{A simple grid-based Navier-Stokes simulation method}

The method used in [] is described. Due to the velocity divergence dependency, it is useful in grid-based simulations to use a staggered Marker-and-Cell (MAC) grid. This stores the pressure values at the centre of the grid cells, and the $xyz$-components of the velocity $\vec{u}$ (u, v, and w) at the centres of the grid walls (as in Figure \ref{fig:MACgrid}). This allows for the numerical computation of velocity divergence at the center of the cell, exactly where the pressure is sampled (\ref{eq:velDiv}. The velocity value itself at this point is determined by trilinear (linear in three dimensions) interpolation.

\begin{figure}[h]
\centering
\includegraphics[width=0.7\linewidth]{mac_grid.pdf}
\caption{Data storage in one cell of a staggered MAC grid.}
\label{fig:MACgrid}
\end{figure}

\begin{equation}
\nabla\vec{u}_{i,j,k}\approx\frac{u_{i+\frac{1}{2},j,k}-u_{i-\frac{1}{2},j,k}}{2}+\frac{v_{i,j+\frac{1}{2},k}-v_{i,j-\frac{1}{2},k}}{2}+\frac{w_{i,j,k+\frac{1}{2}}-w_{i,j,k-\frac{1}{2}}}{2}
\label{eq:velDiv}
\end{equation}

Solving the Navier-Stokes equation can be simplified by breaking the equation down into three parts: the advection, body, and projection equations. Their respective processes \texttt{advect()}, \texttt{body()} and \texttt{project()} are applied in sequence for each time step.

When applied to the entire fluid, the advection equation enforces the conservation of energy (the fluid mass undergoes no net acceleration without the application of a net force). The \texttt{advect()} process applies the velocity field to the quantity $q$ for a time $dt$. This quantity may be velocity itself, pressure, or another quantity relevant to the particular fluid (such as temperature for smoke simulation).

Since in truth the fluid is acted on by the net force of gravity (and perhaps other forces), the body process simply adds $\vec{g}dt$ to the velocity field (all the members of the grid).

The incompressibility of the fluid is enforced by the \texttt{project()} process, which solves the Poisson equation by subtracting the correct pressure gradient from the output velocity grid of \texttt{body()} (\ref{eq:proj1}).

\begin{equation}
\vec{u}^{n+1}=\vec{u}_B^n-\Delta t\frac{1}{\rho}\nabla p
\label{eq:proj1}
\end{equation}

In numerical form, this results in a series of n equations, where n is the number of cells in the grid. If $\vec{p}$ is a column vector containing all the pressure unknowns, and $\vec{d}$ is a vector of the corresponding divergence values, the series of equations can be written as

\begin{equation}
Ap=d,
\label{eq:apd}
\end{equation}

where A is a symmetric sparse 3D matrix known as the seven-point Lagrangian matrix. This can be solved using the Modified Incomplete Cholesky Conjugate Gradient, Level Zero algorithm (MICCG(0)). This involves using the Preconditioned Conjugate Gradient algorithm (or PCG, shown in Figure \ref{fig:PCG}),

with the \texttt{applyPreconditioner()} function shown in Figure \ref{fig:precond}. Since $A$ is a symmetric sparse matrix with large-weight components only near and on the main diagonal, its storage can be optimized to $O(xSize*ySize*zSize)$ space.

If a fluid moves into a new space where the velocity has not been previously defined, it needs to be extrapolated from the nearest valid fluid cell. It is common for velocity to be sampled within a certain distance of the fluid surface in order to reduce such problems.

\section{Boundary conditions}

Fluid simulations are commonly expected to account for obstacles in the fluid volume.

\section{Smoke}

Different types of fluids require specific considerations. For smoke, the body force is replaced with a temperature-dependent buoyancy force. Using the Boussinesq approximation of constant pressure, and assuming a linear dependence on only the temperature and smoke concentration.  (\ref{eq:fBuoy}

\begin{equation}
1+1=2
\label{eq:fBuoy}
\end{equation}

When using the semi-Lagrangian advection scheme, numerical dissipation leads to rapid destruction of the interesting features of smoke, such as vortices. This can be counteracted by creating a dependence on the vorticity $\vec{\omega}=\nabla\times\vec{u}$ (to boost vortex strength), or by using a sharper tricubic interpolant instead of the trilinear one.

\section{Water}

For the simulation of water, the issue of keeping track of the surface arises. The most basic method, suggested by Marker-and-Cell in 1965, involves using marker particles inside the grid volume. The presence of such a particle marks the presence of water at that point as the particles are moved by advection in the velocity field of the grid. However, this leads to poorly-defined, "blobby" water surfaces.

A superior method is the use of level sets. In their case, a function $\phi(x)$ is defined by values sampled at grid cells; the surface is described by $\phi(x) = 0$. This allows for easy modelling of smooth surfaces, as well as determining whether a point is inside the fluid volume, by simple interpolation to find the value of $\phi(x)$ at that point.

Since a given surface may be defined by multiple level sets, the function $\phi(x)$ offering the most stability is chosen. It is given by the gradient condition \ref{eq:phigrad}.

\begin{equation}
\|\nabla\phi(\vec{x})\|=1
\label{eq:phigrad}
\end{equation}

This is enforced by using the signed distance function for $\phi(x)$. (what is that?)

A caveat of level sets is that when combined with the advection process, numerical dissipation leads to the rapid destruction of small features (like small droplets or ripples). This can be solved by using par

\section{Smoothed Particle Hydrodynamics}

Although not nearly as computationally efficient in dealing with incompressible fluid volume, Smoothed Particle Hydrodynamics is far better than grid-based methods at creating visually pleasing fluid surfaces. While small interesting features like fine droplets and thin films are removed by numerical dissipation and limited resolution in grids, SPH is unaffected by these issues. As a result, modern fluid simulations use grid-based Navier-Stokes combined with SPH with particles seeded near fluid boundaries.

In SPH, every particle has an associated normalized smoothing kernel function $W(r)$, where r is the distance from the particle. To reduce computational cost, the function is given a cutoff point $r_c$ beyond which it is zero. Therefore, for one particle, only the particles in a vicinity of radius $r_c$ need to be considered.

A commonly used smoothing kernel is the poly6 kernel (\ref{eq:poly6}):

\begin{equation}
W_{poly6}(r)=\frac{315}{64\pi d^9}\cdot\begin{cases}
(r_c^2-r^2) & 0\leq r\leq r_c\\
0 & r>r_c\\
\end{cases}
\label{eq:poly6}
\end{equation}

SPH makes the Navier-Stokes equations trivial, as mass conservation can be enforced simply by keeping the number of particles constant. For liquid fluids, the boundary is again found through the level set method applied to the particle field.

%what is particle level set?

SPH is also useful in modelling compressible fluids such as sea foam, leading to impressive results if properly coupled with

%Navier-Stokes and SPH can be used together by weighted influence based on the smoothed number density at a particle's position; the denser portion of the fluid is more affected by Navier-Stokes, while the more diffuse portions are more affected by SPH. This is known as particle slip.

%Grid-aided SPH methods can help in the simulation of dense and diffuse fluid mixtures and multiphase fluids. In the first case, a dependency on the number density of particles can be used to weigh the influence of Poisson solvers (the so).

\section{Other fluid simulation types}

For real-time simulations in games, the aforementioned methods are generally much too computationally expensive, although small-scale SPH methods are possible (the chinese dude citation).

Heightfield approximations use the two-dimensional wave equation as a displacement map in the z direction. This however does not allow for multiple z solutions per (x,y) point, as a breaking wave would for example require.

Ocean surfaces can also be generated using procedural animation, as the sum of various sinusoidal functions of varying direction, amplitude, and frequency. This is not well suited for interaction with boundaries or solid objects in the water; this shortcoming can be obfuscated by texturing foam onto the mesh near obstacles and/or using particle emitters.

These types of simulation are far less computationally expensive than 3D Navier-Stokes methods; this makes them suitable for real-time simulations in games. Still, small-scale SPH can also be used in real-time [chinese guy citation], and so can grid-based methods (by using the Jacobi method in the projection step.

\section{Fluid simulations through deep learning}

The most computationally demanding step of fluid simulations is projection. This has recently been shown to be surprisingly well handled by neural networks trained on exact fluid solvers, even when the initial conditions of fluid in the solver and network differ. Furthermore, unlike traditional exact solvers, the complexity of this approach is not dependent on boundary conditions.

[maybe put a picture here reflecting it]

\section*{Annex}
\renewcommand{\thefigure}{A\arabic{figure}}

\setcounter{figure}{0}

\begin{figure}[h]
\begin{framed}
\texttt{// "$\cdot$" is the dot product of two vectors; "*" is scalar multiplication}

\texttt{p = 0}

\texttt{r = d}

\texttt{z = applyPreconditioner(r)}

\texttt{s = z}

\texttt{$\sigma$ = z $\cdot$ r}

\texttt{iterations = 0}

\texttt{while (p not within tolerance) and (iterations < maximumIterations)}

\texttt{~~~~z = A $\cdot$ s}

\texttt{~~~~$\alpha$ = $\rho$ / (z $\cdot$ s)}

\texttt{~~~~p = p + $\alpha$ * s}

\texttt{~~~~r = r - $\alpha$ * z}

\texttt{~~~~// if the element of r with the greatest absolute value is within}

\texttt{~~~~// tolerance, take current p as the solution}

\texttt{~~~~if (max(|r|) $\leq$ tol) return p}

\texttt{~~~~$\sigma_{new}$ = z $\cdot$ r}

\texttt{~~~~$\beta$ = $\sigma_{new}$ / $\rho$}

\texttt{~~~~s = z + $\beta$ * s}

\texttt{~~~~$\sigma$ = $\sigma_{new}$}

\texttt{// maximum iterations have been exceeded}

\texttt{return r}

\end{framed}
%\centering
\vspace*{-3mm}\caption{The PCG algorithm.}
\label{fig:PCG}
\end{figure}

\begin{figure}[h]
\begin{framed}
\texttt{//set tuning constant}

\texttt{$\tau$ = 0.97}

\texttt{}

\texttt{//calculate the preconditioner}

\texttt{for i = 1 to xSize, j = 1 to ySize, k = 1 to zSize}

\texttt{~~if (grid cell has fluid in it)}

\texttt{~~~~e = A$_{(i,j,k)(i,j,k)}$ - (A$_{(i+1,j,k)(i-1,j,k)}$ * precon$_{i-1,j,k}$)$^2$}

\texttt{~~~~~~~~~~~~~~~~~- (A$_{(i,j+1,k)(i,j-1,k)}$ * precon$_{i,j-1,k}$)$^2$}

\texttt{~~~~~~~~~~~~~~~~~- (A$_{(i,j,k+1)(i,j,k-1)}$ * precon$_{i,j,k-1}$)$^2$}

\texttt{~~~~~~~~~~~~~- $\tau$ * (A$_{(i+1,j,k)(i-1,j,k)}$ * (A$_{(i,j+1,k)(i-1,j,k)}$ + A$_{(i,j,k+1)(i-1,j,k)}$) * precon$_{i-1,j,k}^2$}

\texttt{~~~~~~~~~~~~~- $\tau$ * (A$_{(i,j+1,k)(i,j-1,k)}$ * (A$_{(i+1,j,k)(i,j-1,k)}$ + A$_{(i,j,k+1)(i,j-1,k)}$) * precon$_{i,j-1,k}^2$}

\texttt{~~~~~~~~~~~~~- $\tau$ * (A$_{(i,j,k+1)(i,j,k-1)}$ * (A$_{(i+1,j,k)(i,j,k-1)}$ + A$_{(i,j+1,k)(i,j,k-1)}$) * precon$_{i,j,k-1}^2$}

\texttt{}

\texttt{//Solve Lq = r}

\texttt{for i = 1 to xSize, j = 1 to ySize, k = 1 to zSize}

\texttt{~~if (grid cell has fluid in it)}

\texttt{~~~~t = r$_{i,j,k}$ - A$_{(i+1,j,k)(i-1,j,k)}$ * precon$_{i-1,j,k}$ * q$_{i-1,j,k}$}

\texttt{~~~~~~~~~~~~~- A$_{(i,j+1,k)(i,j-1,k)}$ * precon$_{i,j-1,k}$ * q$_{i,j-1,k}$}

\texttt{~~~~~~~~~~~~~- A$_{(i,j,k+1)(i,j,k+1)}$ * precon$_{i,j,k-1}$ * q$_{i,j,k-1}$}

\texttt{~~~~q$_{i,j,k}$ = t * precon$_{i,j,k}$}

\texttt{}

\texttt{//Solve L$^T$z = q}

\texttt{for i = xSize to 1, j = ySize to 1, k = zSize to 1}

\texttt{~~if (grid cell has fluid in it)}

\texttt{~~~~t = r$_{i,j,k}$ - A$_{(i,j,k)(i,j,k)}$ * precon$_{i,j,k}$ * z$_{i+1,j,k}$}

\texttt{~~~~~~~~~~~~~- A$_{(i,j,k)(i,j,k)}$ * precon$_{i,j,k}$ * q$_{i,j+1,k}$}

\texttt{~~~~~~~~~~~~~- A$_{(i,j,k)(i,j,k)}$ * precon$_{i,j,k}$ * q$_{i,j,k+1}$}

\texttt{~~~~z$_{i,j,k}$ = t * precon$_{i,j,k}$}

\end{framed}
\centering
\vspace*{-3mm}\caption{An optimized preconditioner corresponding to the weighted average ($\tau$=97\%) between MICCG(0) and regular Incomplete Cholesky (ICCG(0)).}
\label{fig:precond}
\end{figure}

%\begin{thebibliography}
%\end{thebibliography}

\end{document}