    \filetitle{rngcmp}{Compare two IRIS date ranges}{dates/rngcmp}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
Flag = rngcmp(R1,R2)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{R1}, \texttt{R2} {[} numeric {]} - Two IRIS date ranges that
  will be compared.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{Flag} {[} \texttt{true} \textbar{} \texttt{false} {]} - True
  if the two date ranges are the same.
\end{itemize}

\paragraph{Description}\label{description}

An IRIS date range is distinct from a vector of dates in that only the
first and the last dates matter. Often, date ranges are context
sensitive. In that case, you can use \texttt{-Inf} for the start date
(meaning the earliest possible date in the given context) and
\texttt{Inf} for the end date (meaning the latest possible date in the
given context), or simply \texttt{Inf} for the whole range (meaning from
the earliest possible date to the latest possible date in the given
context).

\paragraph{Example}\label{example}

\begin{verbatim}
r1 = qq(2010,1):qq(2020,4);
r2 = [qq(2010,1),qq(2020,4)];

rngcmp(r1,r2)
ans =
    1
\end{verbatim}


% vim: set spell spelllang=en
\documentclass[10pt]{article}
\usepackage[pdftex]{graphicx}
\usepackage{amssymb, amsmath}
\usepackage{url}

\usepackage{fullpage}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

\title{Implementation of the Density Evolution method with
Fokker-Planck for L-NLIF Model in Python}
\author{Valentin Haenel \\
valentin.haenel@gmx.de \\
BCCN Berlin}

\begin{document}

\maketitle

\section{Introduction}

This report is a description of the work done by Valentin Haenel
for a Lab Rotation within the Bernstein Center for Computational
Neuroscience in Berlin. The rotation was completed under the
supervision of  Gabriel and Bartosz Telenczuk.

Throughout the project I have implemented a variant of the Leaky
Integrate and Fire Neuron (LIF), and a method to fit the parameters of this
neuron using a model of the input and extracellularly recorded spikes.
Primarily this involved solving a partial differential equation and constructing
a maximum likelihood objective function.

This project is motivated by the fact that recording intracellularly from awake
behaving animals is usually not possible, and extracellularly recorded spike
trains are much more common in this setting. The model implemented allows us to
gain at least some partial insight into the subthreshold voltage of such
neurons. A further motivation comes from the fact, that algorithms described are
not publicly available in the form of an easy to use software package.

\section{Model}
The original model is a L-NLIF model, which consists of a Linear
(L) Filter, followed by a probabilistic or Noisy (N) form of Leaky
Integrate and Fire spike generation (LIF) (Paninski et
al.\cite{PaninskiPillowSimoncelli}). For sake of completeness the
model is briefly described here.

The evolution of the Voltage $V$ is given by:
\begin{equation}
    dV = (-g(V(t) -V_{leak}) +I_{stim}(t) + I_{hist}(t)) dt + W_{t}
\end{equation}
Where $g$ is the leak conductance $V_{leak}$ is the leak reversal
potential $I_{stim}$ is the convolution of linear filter with the
input signal, $I_{hist}$ is the spike current history and $W_t$ is
standard Gaussian white noise. More precisely:
\begin{equation}
    I_{stim}(t) = \vec{k} \cdot  \vec{x}(t)
\end{equation}
\begin{equation}
    I_{hist}(t) = \sum_{j=0}^{i-1}h(t-t_j)
\end{equation}
Where $k$ is a linear filter and $h$ is a fixed postspike current waveform.

\section{Algorithms}

\subsection{PDE Solver}

\subsubsection{The Problem}
Let
\begin{equation}
    P(V,t) \equiv P(V(t) \cap  V(s) < V_{th} \forall s < t)
\end{equation}
This refers to the probability of $V(t)$, the membrane potential,
being less than $V_{th}$ the firing threshold until time $t$.

As stated in \cite{PaninskiPillowSimoncelli} the method of density
evolution requires us to solve the
following Fokker-Planck drift diffusion equation numerically.
\begin{equation}
    \frac{\partial P(V,t)}{\partial t} =
    \frac{\sigma^2}{2} \frac{\partial^2 P(V,t) } {\partial V^2} +
    g\frac{\partial[(V-V_{rest})P(V,t)]}{\partial V}
    \label{fokkerplanck}
\end{equation}

We will be solving the evolution of the probability density for a
given inter-spike interval (ISI). And therefore we will constrain the range
of $V$ and $t$.
\begin{equation}
    P(V_{th},t) = 0
    \label{boundarytop}
\end{equation}
\begin{equation}
    P(V,0) = \delta(V-V_{reset})
    \label{boundaryleft}
\end{equation}

Condition (\ref{boundarytop}) ensures that the probability of obtaining a spike
during an ISI is zero. Condition (\ref{boundaryleft}) ensures
that at the beginning of an ISI, i.e. at the time of the last spike,
the probability of the neuron being at reset potential is exactly one.
Thereby we have obtained the constraints for the top and the left hand
side of our solution grid, however, when solving numerically we also
need a lower bound on the voltage $V_{lb}$, so this becomes an
additional boundary condition, for the  bottom:
\begin{equation}
    P(V_{lb},t) = 0
    \label{boundarybottom}
\end{equation}

Ideally $V_{lb} = -\infty $.

$V_{rest}$ is defined as the stationary point of the noiseless
subthreshold dynamics:
\begin{equation}
    V_{rest}(t) = V_{leak} + \frac{1}{g}(\vec{k} \cdot \vec{x}(t) +
    \sum_{j=0}^{i-1}h(t-t_j))
\end{equation}

% This was just wasting space
%
%We can rewrite (\ref{fokkerplanck}) as:
%\begin{equation}
%    \frac{\sigma^2}{2} \frac{\partial^2 P(V,t) } {\partial V^2} +
%    g(V-V_{rest})\frac{\partial P(V,t)}{\partial V} +
%    gP(V,t) -
%    \frac{\partial P(V,t)}{\partial t} =
%    0
%\end{equation}
%Since we know that:
%\begin{equation}
%    \frac{\partial[(V-V_{rest})P(V,t)]}{\partial V} =
%    \frac{\partial (V-V_{rest})}{\partial V}  P +
%    \frac{\partial P}{\partial V} (V-V_{rest})
%\end{equation}
%and
%\begin{equation}
%    \frac{\partial (V-V_{rest})}{\partial V} = 1
%\end{equation}

\subsubsection{Finite Differencing}

In order to solve (\ref{fokkerplanck}) numerically we discretized time
and potential. We adopt the notation that Potential is discretized
into $W$ intervals of length $w$ and indexed
by $\nu= 0,1, \dots W $.  Time is discretized  into $U$ intervals of
length $u$ and indexed by: $\tau= 0,1, \dots U $.
We adopt the notation: $P_{\nu,\tau} = P(\nu w,\tau u)$

A forward finite differencing scheme would like:
\begin{eqnarray}
    \hat{P}(v,t) =& P_{\nu,\tau}\\
%
\frac{\partial \hat{P}(v,t)}{\partial t} =& \frac{P_{\nu,\tau +1 } -
    P_{\nu,\tau}}{u} \\
%
    \frac{\partial \hat{P}(v,t)}{\partial V} =&
    \frac{P_{\nu +1,\tau } -
    P_{\nu - 1,\tau } }
    {2w} \\
%
    \frac{\partial^2 \hat{P}(v,t)}{\partial V^2} =&
    \frac{P_{\nu+1,\tau} - 2 P_{\nu,\tau} + P_{\nu-1,\tau}}
    {w^2}
\end{eqnarray}

However as suggested in \cite{PaninskiHaithSzirtes} we will use the
computationally more stable Crank-Nicolson scheme \cite{press}.
We rewrite the derivatives using the new scheme which is centered around $t +
u/2$.

\begin{eqnarray}
    P_{CN}(v,t) =& \frac{P_{\nu,\tau} + P_{\nu,\tau + 1}}{2} \\
    %
    \frac{\partial P_{CN}(v,t)}{\partial t} =& \frac{P_{\nu,\tau +1 } -
    P_{\nu,\tau}}{u} \\
    %
    \frac{\partial P_{CN}(v,t)}{\partial V} =&
    \frac{P_{\nu +1,\tau } + P_{\nu +1,\tau +1 } -
    P_{\nu - 1,\tau } - P_{\nu -1,\tau +1}}
    {4w} \\
    %
    \frac{\partial^2 P_{CN}(v,t)}{\partial V^2} =&
    \frac{P_{\nu+1,\tau} - 2 P_{\nu,\tau} + P_{\nu-1,\tau} +
    P_{\nu+1,\tau+1} - 2 P_{\nu,\tau+1} + P_{\nu-1,\tau+1}}
    {2w^2}
\end{eqnarray}

\subsubsection{Tridiagonal Equations}

If we now let:
\begin{align*}
a &= \frac{\sigma^2}{2} \\
b &= g(V - V_{rest}) \\
c &= g \\
\end{align*}
and multiply throughout with $4w^2u$
we may rearrange all the $P_{*,\tau+1} $ terms on the left hand side:
\begin{multline}
    \overbrace{-(2au+bwu)}^{A_\nu} P_{\nu+1,\tau+1} +
    \overbrace{(4au - 2cw^2u + 4w^2)}^{B_\nu} P_{\nu,\tau+1}
    \overbrace{-(2au-bwu)}^{C_\nu} P_{\nu-1,\tau+1}
    =  \\
    \underbrace{(2au+bwu) P_{\nu+1,\tau} +
    (-4au +2cw^2u + 4w^2) P_{\nu,\tau} +
    (2au-bwu) P_{\nu-1,\tau}}_{D_{\nu}}
    \label{rearrange}
\end{multline}
For each $ \nu = 1 , \dots , W-1 $

Using (\ref{rearrange}) and incorporating the boundary conditions
\ref{boundarytop} and \ref{boundaryleft} we have obtain a complete system
of $W-1$ linear equations which we may now rewrite in the following
tridiagonal matrix notation.

\begin{equation}
\underbrace{
\begin{pmatrix}
    & B_1   & A_1    & 0      & \cdots   \\
    & C_2   & B_2    & A_2    & 0        \\
    &       & \ddots & \ddots & \ddots   \\
    & \cdots & 0      & C_{W-1}& B_{W-1} \\
\end{pmatrix}}_{\Lambda}
\underbrace{
\begin{pmatrix}
    P_{1,\tau+1}   \\
    P_{2,\tau+1}   \\
    \vdots         \\
    P_{W-1,\tau+1} \\
\end{pmatrix}}_{\chi}
=
\underbrace{
\begin{pmatrix}
    D_1     \\
    D_2     \\
    \vdots  \\
    D_{W-1} \\
\end{pmatrix}}_{\beta}
\end{equation}

We can then use a tridiagonal matrix algorithm to solve $\Lambda \chi
= \beta$. This allows us to iteratively obtain the density evolution $P(V,t)$ of the
membrane potential for a given ISI. Where the initial $\beta$ for an ISI is given by
(\ref{boundaryleft}) and the halting criterion is the time of the next
spike. So for the $i$th spike we obtain values for $V$ in the range
$[V_{lb}, V_{th}]$ and for $t$ in the range $[t_{i-1},t_{i}]$. An
example can be seen in figure \ref{P_vt}.

\subsection{First Passage Time}

The maximum likelihood optimizer proposed in
\cite{PaninskiPillowSimoncelli} however uses the first passage time
density at a given time point which is defined as:

\begin{equation}
    \mathrm{FPT}(t)  = -\frac{\partial}{\partial t} \int P(V,t)dV
    \label{eq:fpt}
\end{equation}

and this can be easily computed from a $P(V,t)$ matrix by a finite differences
/ sums scheme.

\subsection{Maximum Likelihood Estimator}

Putting together the PDE Solver and method for computing the First
Passage Time
The final likelihood is then simply

\begin{equation}
    L_{\vec{x},t_{i}} = \prod_{i} \mathrm{FPT}(t_{i})
\end{equation}

This is the product of the first passage time at the times of
spiking for all spikes.

The pseudocode for the objective function can be described as follows:

{\tt
for each spike interval do:
\begin{enumerate}
    \item compute $P(V,t)$ as matrix
    \item compute FPT$(t)$ as vector
\end{enumerate}
return the product of the last scalars in the FPT vectors.}

This objective function could be presented to a standard numerical
optimizer, for example the Nelder-Mead Downhill simplex \cite{press},
this needs no gradients and is fairly robust but slow.

\subsection{Monte Carlo Method}

To double check the results of the PDE Solver and the resulting First
Passage Time, we additionally implemented some basic Monte Carlo
simulations. The basic idea is to simulate a few thousand traces of the neuron
up to the first spike, with noise. The resulting potential traces, and spike
times were used to obtain both $P(V,t)$ and $fpt$. The density evolution is
compared qualitatively to the density evolution technique as can bee seen in:
\ref{P_vt}. The FPT is compared using a Kolmogorov-Smirnov (K-S)
test\cite{press}.

\section{Implementation}

This section describes the concrete implementation

\subsection{Availability and Design}

The algorithm has been implemented in Python, and the full source code
has been made available within a revision control system under a free
software license at: http://github.com/esc/molif/tree/master. Given
that the Python Language was named after the British Comedians Monty
Python we decided to call the software {\it Meaning Of LIF},
(abbreviated to {\it molif}) which is a reference to the Monty Python
movie {\it Meaning of Life}.

The software is structured into a series of modules contained within
the package {\tt molif}

\begin{itemize}
    \item {\tt model} implementation of the neuron model
    \item {\tt density} implementation of the PDE solver
    \item {\tt likelihood} connects the optimizer and the PDE solver
    \item {\tt montecarlo} implementation of Monte Carlo simulator
    \item {\tt plotting} methods used to generate plots
    \item {\tt util} methods to determine timing
\end{itemize}

The software uses the additional packages numpy, scipy for vector
based and scientific computing, and pylab/matplotlib for plotting the
results. We used the modules {\it scipy.sparse} and {\it
scipy.linsolve} for computing the solution to tridiagonal equations, and the
method {\it optimize.fmin}, which implements the Nelder-Mead Downhill
Simplex, for minimizing the negative likelihood.

\subsection{Limitations and Future Work}

The PDE solver uses sparse matrix algorithms to store and solve the
tridiagonal matrix. Ideally we would like to use the routine $TRIDAG$
described in \cite{press}, however an open source implementation in
python was not available, although feasible. This improvement could
possibly speed up the computation of $P(V,t)$.

There is a serious bug, whereby the value of sigma,
must be within a specific range of $0.1 - 0.05$, otherwise strange
oscillatory instabilities occur. Among the possible causes, are a
numerical instability in the finite differencing scheme, a bug in our
code, a bug in the solver for the linear equations or the
discretization of $V$ and $t$ being to large.

Currently the gradient of the objective function isn't implemented,
and any gradient based optimizer would need to compute their
approximation from the function values.

We used a Kolmogorov-Smirnov (K-S) test to check that the first
passage time computed by the PDE-solver and the Monte Carlo method
come from the same distribution. However the test currently returns a
negative result, although at first glance the distributions look very
similar.

Lastly we should mention that the objective function isn't fully
operational yet. A simple test is executed as follows: first we
generate some spikes with given parameters, and then we attempt to fit
parameters to these spikes. If the code operates correctly the
optimizer should not deviate away from the initial parameters vector.
However currently this is not the case and the optimizer finds a
minimum at a different position in parameter space.

\subsection{Results}

This section presents some plots.

Figure \ref{P_vt} shows a comparison of PDE Solver (top) and Monte Carlo
(bottom) method when computing the density evolution. As expected the two plots
look the same, and corresponds very nicely to what we would expect from the
iterative solution to a Fokker-Planck equation. The drift term is responsible for
the shift of the mean, and the diffusion is responsible for the flattening.

Figure \ref{fpt} shows the comparison of the PDE Solver and Monte
Carlo method when computing the first passage time. Unfortunately a
K-S test allows us to reject the hypothesis that these two come from
the same distribution, even though they look very much alike at a
first glance.

\begin{figure}[htp]
\centering
\includegraphics[scale=0.60]{P_vt}
\caption{Density Evolution}
\label{P_vt}
\end{figure}

\begin{figure}[htp]
\centering
\includegraphics[scale=0.60]{fpt.png}
\caption{First Passage Time Comparison}
\label{fpt}
\end{figure}

\begin{figure}[htp]
\centering
\includegraphics[scale=0.60]{traces.png}
\caption{Voltage Traces for 5000 Monte Carlo simulations }
\label{traces}
\end{figure}

\section{Conclusion}

Not all of the initial Project Goals were reached to my full
satisfaction. We did implement an Integrate and Fire
neuron, and a method to fit the parameters, however we did not get as
far as actually fitting real experimental data. None the less
useful code has been produced and solid numerical techniques (Solving
Partial Differential Equations) were
learnt, and I consider the lab rotation to be successful.

\bibliography{documentation}{ \bibliographystyle{abbrv} }

\end{document}


\section*{Results}

In order to demonstrate the efficacy of our approach, we experiment with D-NeRF's synthetic
dataset which contains 6 different scenes.

\subsection*{Quantitative Results}

Our method is able to slightly outperform D-NeRF on their synthetic dataset. This is likely because D-NeRF can predict non-realistic movement, such as jumping from frame-to-frame. In practice, D-NeRF does not do this, but the movement is not bound to have any smoothness properties, so it may not resemble real movement, by coming to full stops or suddenly accelerating. In contrast, our method enforces that movement is fluid, and thus is better able to reproduce missing frames. This only leads to a small improvement in PSNR, because the dataset contains relatively simple movement, but we expect that in longer sequences this difference would become more apparent.

\subsection*{Qualitative Results}

The difference between the architectures can be observed in the difference of flow between scenes. It's clear from Figure~\ref{fig:dnerf_cmp} that our method more accurately captures squashing and stretching of movement, as the top of the ball is not moving but the bottom of the ball is falling. In contrast, D-NeRF contains approximately equal flow for the entire ball. Since there is no forced prior on movement given by D-NeRF, there is also flow on rigid components.

The difference between the two is also more clearly seen in videos of reconstruction. $C^0$-NeRF visibly has the effect of 'tweening between views, slowing into stops, while D-NeRF has more abrupt starts and stops. While it's difficult to characterize the plausibility of this movement, future work may seek to characterize smoothness of the velocity, as well as smoothness of acceleration and use that as a way to characterize movement.

\begin{table*}[t]
    \centering
    \begin{tabular}{|c|c|c|c|c|}
    \hline
    \textbf{PSNR$^\uparrow$} & Bouncing Balls & Hellwarrior & Hook & Jumping Jacks \\
    \hline
    D-NeRF & 22.978 & 32.712 & 26.757 & 26.278 \\
    \hline
    $C^0$-NeRF & 24.251 & 33.504 & 27.705 & 27.432 \\
    \hline
    & Lego & Mutant & Standup & T-Rex \\
    \hline
    D-NeRF & 22.679 & 27.408 & 29.435 & 24.494 \\
    \hline
    $C^0$-NeRF & 22.945 & 28.486 & 31.050 & 25.421 \\
    \hline
    \end{tabular}
    \centering
    \begin{tabular}{|c|c|c|c|c|}
    \hline
    \textbf{MS-SSIM$^\uparrow$} & Bouncing Balls & Hellwarrior & Hook & Jumping Jacks \\
    \hline
    D-NeRF & 0.917 & 0.949 & 0.961 & 0.931 \\
    \hline
    $C^0$-NeRF & 0.971 & 0.966 & 0.976 & 0.978 \\
    \hline
    & Lego & Mutant & Standup & T-Rex \\
    \hline
    D-NeRF & 0.912 & 0.960 & 0.975 & 0.957  \\
    \hline
    $C^0$-NeRF & 0.935 & 0.980 & 0.988 & 0.972 \\
    \hline
    \end{tabular}
    \caption{
        Our method is able to recover movement with slightly improved accuracy in dynamic scenes as compared to D-NeRF~\cite{pumarola2020dnerf}. Despite, or maybe because of, the forced prior of continuous movement, we are able to learn a smooth interpolation through each frame. In our training regime which randomly samples all frames, we reconstruct each with much lower variance as compared to D-NeRF.
    }
\end{table*}

\begin{figure*}
    \includegraphics[width=\textwidth]{dnerf_compare}
    \caption{
        \label{fig:dnerf_cmp}
        Results comparing movement in D-NeRF~\cite{pumarola2020dnerf} versus our work for a small timestep. There is substantial qualitative difference in predicted flow, since D-NeRF cannot guarantee the initial frame has no movement. There is also a significant difference in rigidity, which is not easily explained. We assume that it may be significantly easier to model low movement with splines, thus there is less of a need for rigidity gating.
    }
\end{figure*}


The multi-model concept was introduced in \mf using GWF Model Exchange objects to support a tight coupling between any two groundwater flow models at the matrix level. This concept has proven to be successful and valued by the modeling community, but the implementation has had its drawbacks too. The information on the spatial discretization at the interface between models as it is available in the Model Exchange object is limited, designed to carry out the basic conductance calculation between connected cells but not sufficient for more advanced discretization schemes. For example, the XT3D option in the NPF package enables simulation of fully three-dimensional (3D) anisotropy by taking into account the full, three-dimensional conductivity tensor \cite{modflow6xt3d}. In doing so, it requires data not only from any pair of cells between which a flow needs to be calculated but also from their neighboring cells. These data are not available in the Model Exchange object and the XT3D option could not be applied across the model interface, at least not without a significant restructuring of the code.

The extension of \mf with the transport model (GWT) comes with the need for a more generic coupling of sub-models too. Here the XT3D option is used in a similar fashion for the dispersion calculation, and the TVD (total variation diminishing) scheme in the advective transport calculation has a computational stencil (i.e. the group of cells required to determine the flux through a particular cell face) that requires information from neighboring cells as well. Finally, the GWF Model Exchange object merely replicates logic already present in the standard GWF packages, e.g. the standard NPF conductance calculation, the Newton-Raphson formulation, or the cell rewetting algorithm, and is not easily adapted when additions or modifications to those packages are made. We introduce a generalized method for coupling of Numerical Models that addresses these challenges and extends \mf with the capability to couple GWT models.

The generalized coupling uses the concept of an Interface Model and is described in more detail below. In essence, this Interface Model uses the object-oriented paradigm in \mf to mimic a regular GWF or GWT model by means of type extension. This way it can use the existing packages and their algorithms in those models to calculate coefficients for the matrix and right-hand-side vector in the Numerical Solution, a responsibility it takes over from the Model Exchange object on which it relies. Its grid is constructed around the interface defined by the Model Exchange with a sufficiently large extent to perform the calculations. Note that the Interface Model is never being solved and neither its configuration data nor its solution vector have any independent meaning: they are merely an image of those parts of the actual Numerical Models that contribute to the interface grid. As a matter of fact, and this is probably the most important point to make here, this generalized coupling with the Interface Model does not introduce any new model functionality. It even avoids the need for the alternative formulations currently present in the GWF Model Exchange. However, it does enable the user to apply the well-tested concepts of existing \mf packages not only on a model’s interior domain, but also across the interface between connected models.

\subsection{The Interface Model}
Generalized coupling is based on the Interface Model to provide the coefficients for the linear system in Numerical Solution. In order to utilize the routines in the existing flow and transport packages to calculate these coefficients, the grid for the Interface Model is constructed from the individual model grids and the coupling information specified by the user and its package data is kept synchronized with the model data during each step of the simulation. Because the Model Exchange makes it possible to connect model grids of different type (DIS, DISV, and DISU), the resulting interface grid is always unstructured, i.e. of type DISU.

Connecting models such that the dynamics at the interface can be described properly by an Interface Model does impose a few conditions on the configuration. For more advanced functionality such as XT3D, it is required that the relative position of the model grids is specified. They should also share the cell faces over which they are connected, such that the resulting grid for the interface can be specified as a valid DISU discretization. Another consequence is that a certain compatibility is required with respect to the active processes and configuration in the individual models: enabling advection (ADV) or dispersion (DSP), for example, only in one of two connected models introduces ambiguity in how to construct the Interface Model for the transport process. Similar arguments hold when two groundwater models are connected and only one of them is configured with a buoyancy package (BUY). Such model setups are currently not supported.

\begin{figure}[!t]
	\begin{center}
	\includegraphics[width=0.5\textwidth]{./Figures/InterfaceModel/mt3dms-p10-modelgrid.png}
	\caption[A plan view of the model grid from MT3DMS problem 10]{A plan view of the model grid for the simulation as defined in MT3DMS problem 10. The green dashed rectangle shows the location of the interface that is used for decomposing this case into a system of coupled GWF and GWT models}
	\label{fig:gwtgwt-fullgrid}
	\end{center}
\end{figure}

To illustrate the concept of this new coupling, a well known, single-model case study (problem 10 in the MT3DMS manual \cite{zheng1999mt3dms}) is implemented as a coupled system where the connection between the GWT models is handled by the Interface Model framework. This study is part of the official set of examples that comes with every \mf software release\footnote{https://modflow6-examples.readthedocs.io/en/master/}. The coefficients for the flow coupling in this case are calculated with the basic GWF Model Exchange module and the following discussion will focus on the GWT-GWT exchange. Figure~\ref{fig:gwtgwt-fullgrid} shows a plan view of the grid and the location of the interface between the submodels. Note that changing only the composition of the grid and leaving the model configuration the same, does not affect the outcome of the simulation\footnote{At the highest level of detail, the outcome does change because the numbering of the grid nodes is different in both scenarios leading to a reordered matrix system to be solved. As expected, these differences turn out to be well within the configured (IMS) solver tolerance.} and therefore makes for a very suitable test case of this coupling.

\begin{figure}[!ht]
	\begin{center}
	\includegraphics[width=0.8\textwidth]{./Figures/InterfaceModel/gwt-ifmod-grid.png}
	\caption[A top view of the Interface Model grid]{A top view of the grid for the Interface Model belonging to the inner GWT model in the example described in the text. The blue cells are located in the outer model’s grid, the red cells are internal. Note that deeper layers have an identical horizontal structure.}
	\label{fig:gwtgwt-interface-grid}
	\end{center}
\end{figure}

Figure~\ref{fig:gwtgwt-interface-grid} shows a plan view of the grid that is reconstructed as part of the Interface Model for the inner GWT model. The red band with cells belong to the inner model’s grid and the blue cells are part of the outer, coarser grid. Because two Interface Models are constructed for every Exchange, (one for each of the models in it) a similar though not identical picture can be drawn for the outer GWT model. However, the extent of this grid is not necessarily equal on both sides of the exchange. The task of the Interface Model is twofold. First of all, it is designed to calculate the coefficients for the linear system for fluxes through the faces directly at the interface. Additionally, it can provide coefficients for those fluxes that would be affected by cells on the other side of the interface just as if the simulation would have been set up as a single model. It is the requirement to support the latter that causes the asymmetry. This becomes clearer when looking at Figure~\ref{fig:gwtgwt-stencils} which shows the XT3D computational stencils and how they determine what the required extent of the interface grid is. To determine the flux through a face at the model interface, the cells on either side and their immediate neighbors are sufficient (the circle). To correctly calculate the flux through cell faces not directly at the interface but influenced by the connection to another model, more additional levels of connectivity are required, depending on the exact size of the computation stencil (the diamond).

\begin{figure}[!ht]
	\begin{center}
	\includegraphics[width=0.8\textwidth]{./Figures/InterfaceModel/gwt-ifmod-stencils.png}
	\caption[Stencil size and the extent of the Interface Model grid]{Top view when zoomed in to the South-West corner of the interface grid. The dashed line surrounds the grid cells participating in the calculation of the dispersive XT3D flux directly at the interface (the white circle) and through a face in the model’s interior (the white diamond) which is nonetheless affected by the connection to the outer GWT model. The extension of the computational stencil in the vertical direction is omitted but straightforward.}
	\label{fig:gwtgwt-stencils}
	\end{center}
\end{figure}

This case study is used to demonstrate the concept of the generalized coupling method with the Interface Model. It serves as an excellent test case because the outcome should be identical to the known results, at least within the configured tolerance of the Numerical Solution. However, from a modeling perspective it would make more sense to redesign the model grid of the problem. With the new capability to use the multi-model approach also for problems containing solute transport, there is no longer a need to refine the study area by using varying column and row width as was done in the original MT3DMS problem. Both the study area and the surrounding domain can be configured as coupled models with a regularly structured (DIS) grid. The granularity of the inner grid can be independently refined to improve the resolution of the results without the need to set up the entire problem based on an unstructured (DISU) grid.

Finally, such a setup would allow to apply the Interface Model in another powerful way. A refinement of the grid is known to produce inaccuracies at the interface, as discussed in the introduction of \cite{modflow6xt3d}. This can be remedied by enabling the XT3D option in the GWF NPF package. The new coupling mechanism based on the Interface Model makes it now possible to enable this option \emph{only} at the interface, which will mitigate the distorting effects of such a grid refiniment on the calculated flow field and still avoids the computational overhead of calculating the XT3D terms on the entire domain.


\section{Joint SED modeling of Photometry and Spectra} \label{sec:methods}
\subsection{Stellar Population Synthesis Modeling} \label{sec:sps}
PROVABGS will provide galaxy properties inferred from joint SED modeling of
DESI photometry and spectra.
For the SED modeling, we use a state-of-the-art stellar population synthesis
(SPS) model that uses a non-parametric SFH with a starburst, a non-parametric
ZH that varies with time, and a flexible dust attenuation prescription.

% describe SFH prescription
The form of the SFH is one of the most important factors in the accuracy of an
SPS model.
In general, the form of the SFH requires balancing between being flexible enough
to describe the wide range of SFHs in observations while not being too flexible
that it can describe any SFH at the expense of constraining power.
If the model SFH is not flexible enough to describe actual SFHs of galaxies,
then unbiased galaxy properties cannot be inferred using the SPS model.
For instance, most SPS models~(\emph{e.g.} CIGALE,~\citealt{serra2011,
boquien2019}; BAGPIPES,~\citealt{carnall2017}) use parametric SFH such as the
exponentially declining $\tau$-model.
Such functional forms, however, produce biased estimates of galaxy properties
(\emph{e.g.} $M_*$ and SFR) when used to fit mock observations of simulated
galaxies~\citep{simha2014, pacifici2015, ciesla2017, carnall2018}.
On the other hand, many non-parametric forms of the SFH are overly flexible
and allow unphysical SFHs~\citep{leja2019}, which unncessarily increases
parameter degeneracies and discards constraining power.

In our SPS model, we use a non-parametric SFH with two components: one based on
non-negative matrix factorization (NMF) basis functions and a starburst component.
For the first component, SFH is a linear combination of four NMF SFH bases:
\begin{equation} \label{eq:nmf}
    {\rm SFH}^{\rm NMF} (t, t_{\rm age}) = \sum\limits_{i=1}^{4} \beta_i
    \frac{s_i^{\rm SFH}(t)}{\int\limits_0^{t_{\rm age}} s_i^{\rm SFH}(t) \,
    {\rm d}t}.
\end{equation}
$\{s^{\rm SFH}_i\}$ are the NMF basis functions and $\{\beta_i\}$ are the
coefficients.
The integral in the denominator normalizes the NMF basis functions to unity.
We constrain $\sum_i \beta_i = 1$, so the total SFH of the component over the
age of the galaxy ($t_{\rm age})$ is normalized to unity.
$\{s^{\rm SFH}_i\}$ are derived from the Illustris cosmological hydrodynamic
simulation~\citep{vogelsberger2014, genel2014, nelson2015}.
We compile, rebin, and smooth the SFHs of Illustris galaxies and then perform
non-negative matrix factorization~\citep{lee1999,cichocki2009, fevotte2011} on
them to derive $\{s^{\rm SFH}_i\}$.
We find that 4 components is sufficient to accurately reconstruct the SFHs
from Illustris.
We present the NMF SFH bases as a function of lookback time in
left panel of Figure~\ref{fig:nmf}.
\edits{
    By using NMF instead of \emph{e.g.} Principal Component Analysis (PCA), we
    ensure that all of the SFH bases are non-negative and, thus, physically
    meaningful.
}
For further details on the derivation of the NMF bases, we refer readers to
Appendix~\ref{sec:nmf}.
Assuming that the SFHs of Illustris galaxies resemble the SFHs of actual
observed galaxies, our NMF form provides a compact and flexible representation
of the SFHs.

The NMF basis functions are derived from smooth SFHs, which means that it does
not include any stochasticity.
However, observations and high resolution zoom-in hydrodyanmical simulations
both find significant stochasticity in galaxy SFHs~\citep{sparre2017,
caplar2019, hahn2019b, iyer2020}.
To include some stochasticity in our SPS model, we include a starburst
component that consists of a SSP.
Thus, for the total SFH, we use
\begin{equation} \label{eq:sfh}
    {\rm SFH} (t, t_{\rm age}) = (1 - f_{\rm burst})~{\rm SFH}^{\rm NMF} (t,
    t_{\rm age}) + f_{\rm burst}~\delta_{\rm D}(t - t_{\rm burst}).
\end{equation}
$f_{\rm burst}$ is the fraction of total stellar mass formed during the
starburst; $t_{\rm burst}$ is the time at which the starburst occurs;
$\delta_{\rm D}$ is the Dirac delta function.
In total we use 6 free parameters in our SFH: 4 NMF basis coefficients
($\beta_i$), $f_{\rm burst}$, and $t_{\rm burst}$.

% describe ZH
Another key part of an SPS model is the chemical enrichment history, or ZH.
Current SPS models mostly assume a
\edits{
    flat ZH, constant metallicity over time~\citep{carnall2017, leja2019}.
}
Since galaxies do not have constant metallicities throughout their history,
this assumption can significantly bias the inferred galaxy
properties~\citep{thorne2021}.
Instead, we take a similar approach to the SFH and use NMF basis functions for
our ZH:
\begin{equation}
    {\rm ZH}(t) = \sum\limits_{i=1}^2 \gamma_i s_i^{\rm ZH}(t).
\end{equation}
$\{s_i^{\rm ZH}(t)\}$ are the ZH NMF basis functions and $\{\gamma_i\}$ are the
coefficients.
$\{s_i^{\rm ZH}(t)\}$ are fit using the ZHs of simulated galaxies from
Illustris in the same fashion as the SFH.
In the right panel of Figure~\ref{fig:nmf}, we present the ZH NMF bases as a
function of lookback time.
We use two NMF components, so our ZH prescription has 2 free parameters.

\begin{figure}
\begin{center}
\includegraphics[width=0.8\textwidth]{figs/nmf_bases.pdf}
    \caption{
        Non-negative matrix factorization basis functions for the SFH (left)
        and ZH (right) used in the non-parametric SFH and ZH prescriptions of
        our SPS model.
        These basis functions are derived from the SFHs and ZHs of simulated
        galaxies in the Illustris cosmological hydrodynamic simulations.
        With the NMF basis functions, we can reproduce the wide range of SFHs
        and ZHs of Illustris galaxies (Appendix~\ref{sec:nmf}).
    }
    \label{fig:nmf}
\end{center}
\end{figure}

We use the SFH and ZH above to model the unattenuated rest-frame luminosity as
a linear combination of multiple SSPs, evaluated at logarithmically-spaced
lookback time bins.
We use a fixed log-binning with the bin egdes starting with $(0, 10^{6.05}{\rm
yr})$, $(10^{6.05}, 10^{6.15}{\rm yr})$, and continuing on with bins of width
0.1 dex.
The binning is truncated at the age of the model galaxy.
For a $z=0$ galaxy, this binning produces 43 $\tlb$ bins.
We use log-spaced $\tlb$ bins because it better reproduces galaxy luminosities
evaluated with much higher resolution $\tlb$ binning than linearly-spacing, for
the same number of bins.
\edits{At each of the 43 $\tlb$ bin $i$,}
we evaluate the luminosity of a SSP with ${\rm ZH}(t_i)$, where $t_i$ is the
center of $\tlb$ bin, and total stellar mass calculated by resampling the SFH
in Eq.~\ref{eq:sfh}.
\edits{
    We use \fsps~to evaluate the SSP luminosities and use the MIST isochrones, the
    combination of MILES and BaSeL spectral libraries, and the \cite{chabrier2003}
    IMF (same as in Section~\ref{sec:sed}).
}
Since we use MIST isochrones, we impose a minimum and maximum limit to ${\rm
ZH}$ based on its coverage: $4.49\times10^{-5}$ and $4.49\times10^{-2}$,
respectively.
\edits{
    These metallicity values are in units of absolute metallicity and can be
    converted to solar metallicity using $Z_\odot = 0.019$.
}
We note that our stellar metallicity range is significantly broader than
previous studies for additional flexibility~\citep[\emph{e.g.}][]{carnall2017,
leja2017, tacchella2021}.
\edits{
    Since we model galaxies solely as a linear combination of SSPs, we do not
    model nebular emission.
    We, therefore, exclude emission lines in our SED modeling by masking the
    wavelength ranges of emission lines.
}

Before we combine the SSP luminosities, we apply dust attenuation.
We use a two component \cite{charlot2000} dust attenuation model with birth
cloud (BC) and diffuse-dust (ISM) components.
The BC component represents the extra dust attenuation of young stars that are
embedded in modecular clouds and HII regions.
For SSPs younger than $t_i < 100{\rm Myr}$, we apply the
following BC dust attenuation:
\begin{equation}
    L_i(\lambda) = L_i^{\rm unatten.}(\lambda) \exp\left[-\tau_{\rm BC} \left(
    \frac{\lambda}{5500\AA} \right)^{-0.7} \right].
\end{equation}
$\tau_{\rm BC}$ is the BC optical depth that determines the strength of the BC
attenuation.
Afterwards, {\em all} SSPs are attenuated by the diffuse dust using the
\cite{kriek2013} attenuation curve parameterization:
\begin{equation}
    L_i(\lambda) = L_i^{\rm unatten.}(\lambda) \exp\left[-\tau_{\rm ISM} \left(
    \frac{\lambda}{5500\AA} \right)^{n_{\rm dust}} \left(k_{\rm Cal}(\lambda) +
    D(\lambda) \right) \right].
\end{equation}
$\tau_{\rm ISM}$ is the diffuse dust optical depth.
$n_{\rm dust}$ is the \cite{calzetti2001} dust index, which determines the
slope of the attenuation curve.
$k_{\rm Cal}(\lambda)$ is the \cite{calzetti2001} attenuation curve and
$D(\lambda)$ is the UV dust bump, parameterized using a Lorentzian-like Drude
profile:
\begin{equation}
    D(\lambda) = \frac{E_b(\lambda~\Delta \lambda)^2}{(\lambda^2 -
    \lambda_0^2)^2 + (\lambda~\Delta \lambda)^2}
\end{equation}
where $\lambda_0 = 2175 \AA$, $\Delta \lambda = 350\AA$, and
$E_b=0.85 - 1.9\,n_{\rm dust}$ are the central wavelength, full width at half
maximum, and strength of the bump, respectively.
Once dust attenuation is applied to the SSPs, we sum them up to get the
rest-frame luminosity of the galaxy.
In total, our SPS model has 12 free parameters: $M_*$, 4 SFH basis
coefficients, $f_{\rm burst}$, $t_{\rm burst}$, 2 ZH basis coefficients,
$\tau_{\rm BC}$, $\tau_{\rm ISM}$, and $n_{\rm dust}$.

%description of our speculator SED model \citep{alsing2019}, which is based on FSPS. We use Chabrier IMF \ch{do we need to justify htis?}.

In practice, evaluating each SSP using \fsps~requires \ch{X} seconds.
For each model evaluation, we evaluate $\sim 43$ SSPs in each of the log-spaced
$\tlb$ bins.
Though this is not a prohibitive computational cost on its own, sampling a
high dimensional parameter space for inference requires $>100,000$ evaluations
--- \emph{i.e.} \ch{$>100$} CPU hours \emph{per galaxy}.
For the >10 million BGS galaxies, this would require \ch{\emph{a billion}}
CPU hours.
Instead, we use an emulator for the model luminosity, which uses a PCA neural
network (NN) following the approach of \cite{alsing2019}.

%The NN provides a flexible and accurate mapping between the SPS model
%parameters and PCA coefficients --- \emph{i.e.} the NN predicts PCA
%coefficients for a given set of SPS parameters.
%Then the linear combination of the predicted coefficients and PCA basis
%functions give us the emulated model luminosity.
%The PCA basis functions and NN are trained using 1,000,000 SPS parameters and
%model luminosity pairs, $\{(\theta, L(\lambda;\theta))\}$.

\edits{
    To construct our emulator, we first generate $N_{\rm model} = 1,000,000$
    model luminosities, $L(\lambda;\theta)$, from unique SPS parameters,
    $\theta$, sampled from the prior (Section~\ref{sec:infer},
    Table~\ref{tab:params}).
    We then split the model luminosities into four wavelength bins: 2000 - 3600,
    3600 - 5500, 5500 - 7410, and 7410 - $60000\AA$ with $N_{\rm spec}$ = 127, 2109,
    2113, and 549 resolution elements, respectively.
    For each wavelength bin, a PCA is done in the $N_{\rm spec}$-dimensional
    space to yield PCA basis functions, or eigenspectra.
    We represent the model luminosity using the first $N_{\rm basis}$ = 50, 50, 50, and 30
    eigenspectra and their corresponding PCA coefficients.
    A NN is then trained on the set of $N_{\rm model}$ models to
    derive a mapping from the 12 SPS parameters to the $N_{\rm basis}$ PCA
    coefficients for each wavelength bin.
}

\edits{
    Once trained, our emulator works as follows.
    For a given set of SPS parameters, the NN for each wavelength bin predicts
    PCA coefficients.
    The coefficients are then linearly combined with the eigenspectra to
    predict the model luminosity in the wavelength bin.
    The luminosity in all four wavelength bins are concatenated to produce the
    full model luminosity.
}
Throughout the wavelength range relevant for BGS, $3000 < \lambda < 9800\AA$,
we achieve $< 1\%$ accurate with the emulator.
For details on the training, validation, and performance of our PCA NN
emulator, we refer readers to Kwon \etal~(in prep.).

From the rest-frame luminosity, we obtain the observed-frame, redshifted, flux
in the same way as Eq.~\ref{eq:sed}.
In our case, redshift is not a free parameter since we will have high quality
spectroscopic redshifts for every DESI BGS galaxy.
BGS redshifts will have small redshift error, $\sigma_z < 0.0005 (1+z)$
(150 km/s), and <5\% catastrophic failures, $\Delta z/(1+z) < 0.003$ (<1000
km/s).
To model DESI photometry, we convolve the model flux with the LS broadband
filters as in Eq.~\ref{eq:photo}.
To model DESI spectra, we first apply Gaussian velocity dispersion.
In this work, we keep velocity dispersion fixed at 0 km/s but in practice
velocity dispersion can be set as a free parameter.
Then the broadened flux is resampled into the DESI wavelength binning.
Since DESI spectra do not necessarily include all the light of a galaxy, we
include a nuisance parameter $f_{\rm fiber}$, a normalization factor on the
spectra to account for fiber aperture effects.
Finally, the SPS model photometry and spectrum can be directly compared to
observations.

\begin{table}
\caption{Parameters of the PROVABGS SPS model and their priors used for joint
    SED modeling of DESI photometry and spectroscopy.}
\begin{center}
    \begin{tabular}{ccc} \toprule
        name & description & prior \\[3pt]
        \hline
        $\log M_*$                              & log galaxy stellar mass & uniform over [7, 12.5] \\
        $\beta_1, \beta_2, \beta_3, \beta_4$    & NMF basis coefficients for SFH & Dirichlet prior \\
        $f_{\rm burst}$ & fraction of total stellar mass formed in starburst event & uniform over [0, 1] \\
        $t_{\rm burst}$ & time of starburst event & uniform over [10Myr, 13.2Gyr] \\
        $\gamma_1, \gamma_2$ & NMF basis coefficients for ZH & log uniform over
        [$4.5\times10^{-5}, 1.5\times10^{-2}$] \\
        $\tau_{\rm BC}$ & Birth cloud optical depth & uniform over [$0, 3$] \\
        $\tau_{\rm ISM}$ & diffuse-dust optical depth & uniform over [$0, 3$] \\
        $n_{\rm dust}$ & \cite{calzetti2001} dust index & unifrom over[$-2, 1$]\\
        $f_{\rm fiber}$ & spectrum fiber-aperture effect normalization &
        Gaussian $\mathcal{N}(\hat{f}^{\rm fiber}_r, \frac{f^{\rm fiber}_r}{f_r} \sigma_r)$\\
        \hline
\end{tabular} \label{tab:params}
\end{center}
\end{table}

\begin{figure}
\begin{center}
    \includegraphics[width=0.9\textwidth]{figs/mcmc_posterior_demo.pdf}
    \caption{
        \emph{Top}:
        Posterior probability distribution of our 12 SPS model parameters
        derived from joint SED modeling of the mock DESI photometry and
        spectrum.
        The contours mark the 68 and 95\% percentiles.
        We use a Gaussian likelihood and the prior specified in
        Table~\ref{tab:params} to evaluate the posterior and sample the
        distribution using ensemble slice MCMC.
        \emph{With our Bayesian SED modeling approach, we capture the significiant
        parameter degeneracies and multimodality of the posterior
        distribution.}\\
        \emph{Bottom}:
        We compare the best-fit model observables (orange) to the mock
        observations (black).
        We find excellent agreement for both the LS photometry (left) and the
        DESI spectrum (right).
    } \label{fig:posterior}
\end{center}
\end{figure}

\subsection{Bayesian Parameter Inference} \label{sec:infer}
Using the SPS model above, we perform Bayesian parameter inference to derive
posterior probability distributions of the SPS parameters from photometry and
spectroscopy.
From Bayes rule, we write down the posterior as
\begin{equation} \label{eq:bayes}
    p(\theta\given {\bf X}) \propto p(\theta)~p({\bf X} \given \theta)
\end{equation}
where ${\bf X}$ is the photometry or spectrum and $\theta$ is the set of SPS
parameters.
$p({\bf X} \given \theta)$ is the likelihood, which we calculate separately for
the photometry
\begin{equation}
    \mathcal{L}^{\rm photo} \propto \exp\left[-\frac{1}{2} \left(\frac{X^{\rm photo} -
    m^{\rm photo}(\theta)}{\sigma^{\rm photo}}\right)\right]
\end{equation}
and for the spectrum
\begin{equation}
    \mathcal{L}^{\rm spec} \propto \exp\left[-\frac{1}{2} \left(\frac{X^{\rm spec} -
    m^{\rm spec}(\theta)}{\sigma^{\rm spec}} \right)^2\right].
\end{equation}
$m^{\rm photo}$ and $m^{\rm spec}$ represent SPS model for photometry and
spectroscopy.
$\sigma^{\rm photo}$ and $\sigma^{\rm spec}$ respresent the uncertainties on
the measured photometry and spectrum.
In calculating $\mathcal{L}^{\rm spec}$, we exclude wavelength ranges of width
40\AA~surrounding the OII, H$\beta$, OIII, and H$\alpha$ emission lines since
our SED model does not model gas emissions.
We consider the photometry indepedent from the spectrum so we combine the
likelihoods when jointly modeling the spectrophotometry:
\begin{equation}
    \log \mathcal{L} \approx \log \mathcal{L}^{\rm photo} + \log
    \mathcal{L}^{\rm spec}.
\end{equation}
$p(\theta)$ in Eq.~\ref{eq:bayes} is the prior on the SPS parameters.
For most of our parameters, we use uninformative uniform priors with
conservatively chosen ranges that are listed in Table~\ref{tab:params}.
However, for the priors of $\{\beta_1, \beta_2, \beta_3, \beta_4 \}$, the NMF coefficients
for the SFH, we use a Dirichlet distribution to main the normalization of the SFH in Eq.~\ref{eq:nmf}.
With a Dirichlet distribution, $\beta_i$ are within $0 < \beta_i < 1$ and
satisfy the constraint $\sum_i \beta_i = 1$.

Now that we can evaluate the posterior at given $\theta$, we estimate the
posterior distributions using Markov Chain Monte Carlo (MCMC) sampling.
We use the \cite{karamanis2020} ensemble slice sampling MCMC algorithm with the
{\sc zeus} Python
package\footnote{\href{https://zeus-mcmc.readthedocs.io/}{https://zeus-mcmc.readthedocs.io/}}.
Ensemble slice sampling is an extension of standard slice sampling that does
not requires specifying the initial length scale or any further hand-tuning.
It generally converges faster than other MCMC algorithms (\emph{e.g.}
Metropolis) and generates chains with significantly lower autocorrelation.

When we sample the posterior, we do not directly sample our 12 dimensional
SPS parameter space because we use a Dirichlet prior on the SFH NMF
coefficients.
Dirichlet distributions are difficult to directly sample so we instead use the
\cite{betancourt2012} sampling method, which transforms an $N$ dimensional
Dirichlet distribution into an easier to sample $N-1$ dimensional space.
Hence, we sample the posterior in the transformed 11 dimensional space.
Given this dimensionality, we run our MCMC sampling with 30 walkers.
Overall, we find that the sampling converges after 2,500 iterations with a 500
iteration burn in.
Deriving the posterior distribution from a joint SED modeling of photometry and
spectra, with the emulator, takes \ch{0.5 CPU hours}.
In principle, since our emulator uses a PCA NN, we can further expedite our
paremeter inference using more efficient sampling methods that exploit gradient
information, such as Hamiltonian Monte Carlo.
We will explore further speed ups to our SED modeling in future works.

In Figure~\ref{fig:posterior} we present the posterior distribution of our 12
SPS model parameters for an arbitrarily chosen \lgal~mock observation.
We mark the 68 and 95 percentiles of the distribution with the contours.
The posterior distribution reveal there are significant degeneracies between
SPS parameters: \emph{e.g.} $\beta_2^{\rm SFH}$ and $f_{\rm burst}$.
Furthermore, the distribution is multimodal (see $f_{\rm burst}$ panels).
With our Bayesian SED modeling, we are able to capture such complexities in the
posterior that would be lost with point estimates or maximum likelihood
approaches.
In the bottom panels, we compare our SPS model evaluated at the best-fit
parameters (orange) with the \lgal~mock observations (black).
On the left, we compare the $g$, $r$, $z$ band magnitudes; on the right, we
compare spectra.
We find excellent agreement between the best-fit SPS model and mock
observations.
The entire PROVABGS SED modeling pipeline, including the neural emulators and
parameter inference framework, is publicly available at
\href{https://github.com/changhoonhahn/provabgs/}{https://github.com/changhoonhahn/provabgs/}.