\section{Reference Theory}
This section presents a summary of the theory behind Bayesian Dynamic Linear Models. For in-depth details, the reader should consult the following references:\\[4pt]

\noindent \emph{A Kernel-based Method for Modeling Non-Harmonic Periodic Phenomena in Bayesian Dynamic Linear Models}\\{\small
            Nguyen, L.H., Gaudot, I., Shervin Khazaeli and Goulet, J.-A.\\
            Frontiers in Built Environment. Vol. 5, pp8, 2019\\}
      [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/Nguyen_et_al_KR_BDLM_2019.pdf}{PDF}] [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/2019_Nguyen_BDLM_KR.enw}{EndNote}]  [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/2019_Nguyen_BDLM_KR.bib}{BibTex}] [\href{https://doi.org/10.3389/fbuil.2019.00008}{DOI link}] \cite{Nguyen2019KRBDLM}\\[4pt]

\noindent \emph{Uncertainty quantification for model parameters and hidden state variables in bayesian dynamic linear models}\\{\small
            Nguyen, L.H., Gaudot, I., and Goulet, J.-A.\\
            Structural Control and Health Monitoring. Vol. 26, Issue 3, pp.e2136, 2019\\}
      [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/Nguyen_Gaudot_Goulet_MCMC_BDLM_2018.pdf}{PDF}] [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/2019_Nguyen_BDLM_UC.xml}{EndNote}]  [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/2019_Nguyen_BDLM_UC.bib}{BibTex}] [\href{https://doi.org/10.1002/stc.2309}{DOI link}] \cite{Nguyen2018UncertaintyBDLM}\\[4pt]

      \noindent \emph{Anomaly Detection with the Switching Kalman Filter for Structural Health Monitoring}\\{\small
            Nguyen, L.H. and Goulet, J.-A.\\
            Structural Control and Health Monitoring. Vol. 24, Issue 4, pp.e2136, 2018\\}
      [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/2017_Nguyen_and_Goulet_AD-SKF.pdf}{PDF}] [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/Nguyen_SKF_2018.xml}{Endnote}]  [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/Nguyen_SKF_2018.ris}{BibTeX}] [\href{https://doi.org/10.1002/stc.2136}{DOI link}] \cite{Nguyen2018}\\[4pt]

\noindent \emph{Structural health monitoring with dependence on non-harmonic periodic hidden covariates}\\{\small
            Nguyen, L.H. and Goulet, J.-A.\\
            Engineering Structures, 166:187 Ð 194., 2018\\}
      [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/2018_Nguyen_et_Goulet_SHMHNHC.pdf}{PDF}] [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/2018_Nguyen_et_Goulet_HNHC.xml}{Endnote}]  [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/2018_Nguyen_et_Goulet_HNHC.bib}{BibTeX}] [\href{https://doi.org/10.1016/j.engstruct.2018.03.080}{DOI link}] \cite{Nguyen2018187}\\[4pt]

\noindent \emph{Empirical validation of Bayesian Dynamic Linear Models in the context of Structural Health Monitoring}\\{\small
            Goulet, J.-A. and Koo, K.\\
            Journal of Bridge Engineering. Vol. 23, Issue 2, pp. 05017017, 2018\\}
      [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/Goulet_BDLM_tamar_2017.pdf}{PDF}] [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/Goulet_BDLM_2018.xml}{Endnote}]  [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/Goulet_BDLM_2018.ris}{BibTeX}] [\href{https://doi.org/10.1061/\%28ASCE\%29BE.1943-5592.0001190}{DOI link}] \cite{Goulet2017BDLMEmprical}\\[4pt]

\noindent \emph{Bayesian dynamic linear models for structural health monitoring}\\{\small
            Goulet, J.-A.\\
            Structural Control and Health Monitoring. Vol. 24, Issue 12, pp.e2025, 2017\\}
      [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/Goulet_BDLM_SHM_2017_preprint.pdf}{PDF}] [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/Goulet_BDLM_2017.xml}{Endnote}]  [\href{https://www.polymtl.ca/cgm/jagoulet/Site/Papers/Goulet_BDLM_2017.ris}{BibTeX}] [\href{https://doi.org/10.1002/stc.2035}{DOI link}] \cite{STC:STC2035} \\

\subsection{Linear gaussian state-space model}
\label{SS:LGSSM}
OpenBDLM builds on Bayesian dynamic linear models (BDLMs).
Bayesian dynamic linear models \cite{west1999bayesian} are a class of linear gaussian state-space models which can be described from the transition and the observation equations.
The transition equation describes the dynamics of the system, and is formulated as
\begin{equation}
  \mathbf{x}_{t}=\mathbf{A}_{t}\mathbf{x}_{t-1}+\mathbf{w}_{t},\quad\left\{
  \begin{array}{l}
\mathbf{x}_{t}\sim \mathcal{N}(\bm{\mu}_{t},\bm{\Sigma}_{t})\\[4pt]
\mathbf{w}_{t}\sim \mathcal{N}(\mathbf{0},
\mathbf{Q}_{t}),
\end{array}\right.
\label{EQ:SSM_Transition}
\end{equation}
where, for each each time $t=1, \dots ,\mathtt{T}$, the variables $\mathbf{x}_{t}$ follow a Gaussian distribution with mean $\bm{\mu}_{t}$ and covariance matrix $\bm{\Sigma}_{t}$, $\mathbf{A}_{t}$ is the transition matrix, and $\mathbf{w}_{t}$ represents Gaussian model errors with zero mean and covariance matrix $\mathbf{Q}_{t}$.
The variables $\mathbf{x}_{t}$ are referred to as hidden states because they are not directly observed.
The relationship between the observations $\mathbf{y}_{t}$ and the hidden states $\mathbf{x}_{t}$ is given by the observation equation, such as
\begin{equation}
\mathbf{y}_{t}=\mathbf{C}_{t}\mathbf{x}_{t}+\mathbf{v}_{t},\quad\left\{\begin{array}{l}
\mathbf{v}_{t}\sim \mathcal{N}(\mathbf{0},\mathbf{R}_{t}),
\end{array}\right.
\label{EQ:SSM_Observation}
\end{equation}
where $\mathbf{C}_{t}$ is the observation matrix, and $\mathbf{v}_{t}$ is the Gaussian measurement error with zero mean and covariance matrix $\mathbf{R}_{t}$.
BDLMs are capable of analyzing multiple time series simultaneously.
In case of dependencies between the time series, regression coefficients are added in $\mathbf{C}_{t}$ (see Section~\ref{S:Dependencies} and \cite{STC:STC2035}).
One particularity of BDLMs is their capacity to update the current estimated state with the current observations, thus allowing to perform online state estimation for non-stationary time series.

\subsection{Kalman filter \& UD filters}
\label{SS:KFUD}
The analytical solutions for the prediction, observation and update step are available through either the Kalman filter (KF) or the UD filter, which can be expressed in its short form as
\begin{equation}
    \begin{split}
      (\bm{\mu}_{t|t},\bm{\Sigma}_{t|t}, \mathcal{L}_{t}) = \text{Filter}(\bm{\mu}_{t-1|t-1},\bm{\Sigma}_{t-1|t-1},\mathbf{y}_{t}, \mathbf{A}_{t},  \mathbf{Q}_{t},   \mathbf{C}_{t},  \mathbf{R}_{t}),
      \end{split}
\label{EQ:KF}
\end{equation}
where $\mathcal{L}_{t}$ is the marginal likelihood describing the probability of observing observations $\mathbf{y}_{t}$ at time $t$ given all the observations up to time $t-1$ \cite{sarkka2013bayesian}.
Note that the UD and Kalman filter are two different methods for calculating the same results. On one hand, the Kalman filter is faster and computationally simpler to implement, and on the other hand, the UD filter is more robust toward numerical instabilities.

The standard Kalman filter expressed in Eq.~\ref{EQ:KF} can process stationary, trend stationary, and acceleration stationary time series, but it is not capable of handling non-stationary time series, which is needed when it comes to anomaly detection (see \S\ref{S:ExampleDispAnomaly}).
The generalization of the Kalman Filter for non-stationary time series is found in the Switching Kalman filter (SKF) equations.

\subsection{Switching Kalman filter}
\label{SS:THSKF}
We may be interested in anomaly detection, that is, modelling and detecting the changes of regimes in the dynamics of the baseline response of the time series.
One way to model changing dynamics is to run in parallel a collection of ${\mathtt{S}}$ linear models, each having their own system dynamics $\mathbf{A}_{t}$ and $ \mathbf{Q}_{t}$.
%In the Switching Kalman filter (SKF) approach \citep{Murphy1998}, a collection of $S$ linear models are run in parallel.
%Each linear model has its own system dynamics (i.e their own $\mathbf{A}_{t}$ and $ \mathbf{Q}_{t}$ matrices).
In such approach, a discrete markovian switching variable $s_{t}= 1, ..,j,.. ,\mathtt{S}$ with a transition probabilities matrix $\mathbf{Z}_{t}$ and probabilities $\bm{\pi}_{t}$ is introduced to indicate which dynamics is used at time $t$.
The problem of incorporating switching dynamics into the model is that the state vector grows in a way that the dimension of the state vector at time $t$ is $\mathtt{S}^{t}$.
Therefore, the estimation quickly becomes intractable.
One solution is to merge at each time $t$ the states sharing the same dynamics using gaussian mixture.
This technique, known as the Switching Kalman filter, allows to keep the dimension of the state vector equal to $\mathtt{S}$ at each time $t$ \cite{murphy2012machine}.
The SKF algorithm can be divided into two successive steps, (i) the ``Filter'' and, (ii) the ``Collapse'' step.
Following the notation used in Eq.~\ref{EQ:KF} the first step can be expressed in its short form as
\begin{equation}
  \begin{split}
  (\bm{\mu}_{t|t}^{i(j)},\bm{\Sigma}_{t|t}^{i(j)}, \mathcal{L}_{t}^{i(j)}) = \text{Filter}(\bm{\mu}_{t-1|t-1}^{i},\bm{\Sigma}_{t-1|t-1}^{i}, \mathbf{y}_{t}, \mathbf{A}_{t}^{j},  \mathbf{Q}_{t}^{i(j)},   \mathbf{C}^{j}_{t},  \mathbf{R}^{j}_{t}),
    \end{split}
\label{EQ:SKF1}
\end{equation}
where the superscripts $i(j)$ indicates that the current state at time $t$ is $s_{t}=j$ given the state at time $t-1$ is $s_{t-1}=i$, and
$ \mathcal{L}_{t}^{i(j)}$  the marginal likelihood that describes the probability of observing observations $\mathbf{y}_{t}$ at time $t$ given all the observations up to time $t-1$, and given the state at time $t_1$ was $s_{t-1} = i$ and that it switches to $s_{t} = j$ at time $t$.
The state probability $\mathbf{\pi}_{t|t}^{j}$ at each time $t$ is computed from the previous state probabilities $\bm{\pi}_{t-1|t-1}$, the likelihood $\mathcal{L}_{t}^{i(j)}$, and the transition probability $Z_{t}^{i(j)}$, such as
\begin{equation}
\pi_{t|t}^{j} = \sum_{i=1}^{\mathtt{S}} \frac{\mathcal{L}_{t}^{i(j)} \pi_{t-1|t-1}^{i} Z^{i(j)}_{t} }{c},
\label{EQ:StateProbability}
\end{equation}
where $c$ is a normalization constant ensuring that $ \sum_{j=1}^{\mathtt{S}} \pi_{t|t}^{j} = 1 $.
Moreover, the state switching probability is defined as
\begin{equation}
W_{t-1|t}^{i(j)} = \frac{\mathcal{L}_{t}^{i(j)} \pi_{t-1|t-1}^{i} Z^{i(j)}_{t} }{c\pi_{t|t}^{j}}.
\label{EQ:StateSwitchingProbability}
\end{equation}
$W_{t|t-1}^{i(j)}$ are required to perform the ``Collapse'' step, which can be expressed in its short form as
\begin{equation}
  \begin{split}
  (\bm{\mu}_{t|t}^{j},\bm{\Sigma}_{t|t}^{j}) = \text{Collapse}(\bm{\mu}_{t|t}^{i(j)},\bm{\Sigma}_{t|t}^{i(j)}, W_{t-1|t}^{i(j)} ),
    \end{split}
\label{EQ:SKF2}
\end{equation}
where state switching probabilities $W_{t|t-1}^{i(j)}$ are used as weighting factors for the gaussian mixture.
From Eq.~\ref{EQ:SKF2}, the SKF algorithm provides a set a $\mathtt{S}$ state vectors at each time $t$.
However, for the ease of interpretation, it is generally more convenient to have a single state vector at each time $t$.
Therefore, we hereafter introduce the ``Merge'' step.
Similarly to the ``Collapse'' step of the SKF algorithm, the ``Merge'' step uses the gaussian mixture technique, and it can be expressed in its short form as
\begin{equation}
  \begin{split}
  (\bm{\mu}_{t|t},\bm{\Sigma}_{t|t}) = \text{Merge}(\bm{\mu}_{t|t}^{j},\bm{\Sigma}_{t|t}^{j},  \pi_{t|t}^{j} ),
    \end{split}
\label{EQ:SKFCollapse}
\end{equation}
where the state probabilities $\pi_{t|t}^{j}$ is used as weighting factors for the gaussian mixture \cite{Nguyen2018}.

\subsection{Model parameter estimation}
\label{SS:THModelParameterEstimation}
The model matrices $\left\{\mathbf{A}_{t}, \mathbf{Q}_{t}, \mathbf{C}_{t}, \mathbf{R}_{t}\right\}$ contain a vector of unknown model parameters $\bm{\theta}$ to be learned from data $\mathbf{y}_{1:\mathtt{Tr}}$.
This section presents different methods for optimizing the vector of model parameter in OpenBDLM.
\subsubsection{Likelihood}
The likelihood is the joint prior probability density of observations, i.e. the plausibility of the available observations $\mathbf{y}_{1:\mathtt{Tr}}$ given a vector of model parameters $\bm\theta$.
Assuming that the observations are conditionally independent from each other, the joint likelihood function is defined as the product of the marginal likelihoods such that
\begin{equation}
p(\mathbf{y}_{1:\mathtt{Tr}}|\bm\theta)  = \displaystyle\prod_{t=1}^{\mathtt{Tr}} p(\mathbf{y}_{t}|\mathbf{y}_{1:t-1},\bm \theta) = \displaystyle\prod_{t=1}^{\mathtt{Tr}}\prod_{j=1}^{\mathtt{S}} \prod_{i=1}^{\mathtt{S}} \mathcal{L}_{t}^{i(j)}\cdot Z_{t}^{i(j)}\cdot\pi_{t-1|t-1}^{i} ,
\label{EQ:LP}
\end{equation}
where $\mathcal{L}_{t}^{i(j)}$ is defined in Equation \ref{EQ:SKF1}, $\mathtt{S}$ is the number of model class (see \ref{SS:THSKF}), $Z_{t}^{i(j)}$ is the transition probability, and $\pi_{t-1|t-1}^{i}$ the previous state probability. In order to avoid the underflow and overflow issue, the joint likelihood function presented in Equation \ref{EQ:LP} is transformed into the nature logarithm space, so that
\begin{equation}
\ln p(\mathbf{y}_{1:\mathtt{Tr}}|\bm\theta)  =  \displaystyle\sum_{t=1}^{\mathtt{Tr}} \ln \left[ \sum_{j=1}^{\mathtt{S}} \sum_{i=1}^{\mathtt{S}} \mathcal{L}_{t}^{i(j)}\cdot Z_{t}^{i(j)}\cdot\pi_{t-1|t-1}^{i} \right],
\label{EQ:LP}
\end{equation}
where $\ln p(\mathbf{y}_{1:\mathtt{Tr}}|\bm\theta) $ is the log-likelihood function. Note that when a single regime is employed, Equation \ref{EQ:LP} simplifies to
\begin{equation}
\ln p(\mathbf{y}_{1:\mathtt{Tr}}|\bm\theta)  =  \displaystyle\sum_{t=1}^{\mathtt{Tr}} \ln  \mathcal{L}_{t},
\end{equation}

\subsubsection{Maximum Likelihood Estimation (MLE)}

The \emph{Maximum Likelihood Estimation} (MLE) \cite{gelman2014bayesian} consists in finding a single vector that maximizes the log-likelihood function presented in Equation \ref{EQ:LP},
\begin{equation*}
\bm\theta^{*} = \underset{\bm\theta}{\text{arg}\max}\left[\ln  p(\mathbf{y}_{1:\mathtt{Tr}}|\bm\theta) \right] \text{,}
\end{equation*}
where $\bm\theta^{*}$ is the optimal vector of model parameters. The optimization task can be done using the gradient-based optimization algorithm such as \emph{gradient ascent} and \emph{stochastic gradient ascent}  \cite{Goodfellow-et-al-2016}.

\subsubsection{Gradient-based optimization}
In OpenBDLM, the gradient-based optimization method available are  the \emph{batch gradient ascent algorithm} and \emph{stochastic gradient ascent algorithm}.  For the purpose of simplicity, the log-likelihood function presented in Equation \ref{EQ:LP} is denoted as $\mathcal{T}(\bm\theta, \mathbf{y}_{1:\mathtt{Tr}})$ that is a function of a vector of model parameter $\bm\theta$ and a training dataset $\mathbf{y}_{1:\mathtt{Tr}}$.

\paragraph{Batch Gradient Ascent  (BGA)}
The BGA algorithm is used to maximize the log-likelihood function by updating the vector of model parameters with a small step $\Delta_{\bm\theta}$ in the direction of gradient for the entire training data $\mathbf{y}_{1:\mathtt{Tr}}$,
\begin{equation}
\bm\theta^{n} = \bm\theta^{n-1} + \underbrace{\eta\cdot \nabla\mathcal{T}(\bm\theta^{n-1}, \mathbf{y}_{1:\mathtt{Tr}})}_{\Delta_{\bm\theta}},
\end{equation}
where $n$ corresponds the optimization loop, $\eta$ is the learning rate to be defined by the user, and $\nabla$ is the operator for evaluating the first derivative of the log-likelihood function. The BGA algorithm only optimizes one model parameters at a time. The parameter-wise Newton-Raphson (NR) algorithm \cite{gelman2014bayesian} that uses both the first and second derivatives for performing the model parameter updates is implemented for the BGA. For the BGA algorithm a converged vector $\bf{c}$ is defined following
\begin{equation}
\mathbf{c}(i) = \left\{\begin{array}{lll}
1&\text{if} ~\mathcal{T}(\bm\theta^{n}, \mathbf{y}_{1:\mathtt{Tr}})> \mathcal{T}(\bm\theta^{n-1}, \mathbf{y}_{1:\mathtt{Tr}})~\text{and}~\left|\tfrac{\mathcal{T}(\bm\theta^{n}, \mathbf{y}_{1:\mathtt{Tr}})- \mathcal{T}(\bm\theta^{n-1}, \mathbf{y}_{1:\mathtt{Tr}})}{\mathcal{T}(\bm\theta^{n-1}, \mathbf{y}_{1:\mathtt{Tr}})}\right|<\tau\\
0 &\text{otherwise},
\end{array}\right.
\end{equation}
where $\tau$ is a termination tolerance and $i$ corresponds to $i^{th}$ model parameter of $\bm\theta$. The convergence criteria is reached when all elements of $\bf{c}$ are equal to $1$, or if the number of iteration reaches the maximal number of specified by the user.

\paragraph{Stochastic Gradient Ascent (SGA)}  In order to improve the computational efficiency when using large datasets, OpenBDLM employs Stochastic Gradient Ascent SGA. The SGA optimization algorithms available in OpenBDLM are : \emph{momentum} and  \emph{adaptive moment estimation} \cite{Goodfellow-et-al-2016}. Instead of using a full batch dataset, the SGA algorithms employ mini-batches of the training data to update $\bm\theta$. The update equation is given by
\begin{equation}
\bm\theta^{n} = \bm\theta^{n-1} + \eta\cdot \nabla\mathcal{T}(\bm\theta^{n-1}, \mathbf{y}_{t:t+l_{\mathtt{MB}})},
\end{equation}
where $l_{\mathtt{MB}}$ is the length of the mini-batch. The SGA can update the model parameters either once at time, or all at once.  An epoch  is completed when the vector of  model parameters is updated $\mathtt{round}(\mathtt{Tr}/ l_{\mathtt{MB}})$ times, where $\mathtt{round}$ provides the closest integer. In order to avoid biasing the SGA algorithm, the mini-batch is randomly selected at every update. The SGA stops when the number of epochs reach the limit specified by the user.

\paragraph{Approximation of the derivatives}

In BDLMs, the derivatives of the log-likelihood function are  approximated numerically using the central differentiation scheme, so that
\begin{equation}
\begin{array}{lcl}
 \nabla \mathcal{T}(\bm\theta(i),\mathbf{y}_{1:\mathtt{Tr}}) & = &\dfrac{\mathcal{T}(\bm\theta(i) + \delta_{\theta}, \mathbf{y}_{1:\mathtt{Tr}}) - \mathcal{T}(\bm\theta(i) - \delta_{\theta}, \mathbf{y}_{1:\mathtt{Tr}})}{2\delta_{\theta}}\\[12pt]

 \nabla \nabla \mathcal{T}(\bm\theta(i),\mathbf{y}_{1:\mathtt{Tr}}) & = & \dfrac{\mathcal{T}(\bm\theta(i) + \delta_{\theta}, \mathbf{y}_{1:\mathtt{Tr}}) - \mathcal{T}(\bm\theta(i), \mathbf{y}_{1:\mathtt{Tr}}) + \mathcal{T}(\bm\theta(i) - \delta_{\theta}, \mathbf{y}_{1:\mathtt{Tr}})}{\delta_{\theta}^{2}},
\label{EQ:numericaldiff}
\end{array}
\end{equation}
where $\delta_{\theta}$ is a small perturbation to the value of the $i^{\text{th}}$ model parameter.
\subsubsection{Laplace Approximation}

The MLE approach are point estimation methods which do not take into account the uncertainty in the parameter estimates $\bm\theta^{*}$.
The model parameter uncertainties can be quantified using the Laplace approximation \cite{gelman2014bayesian} such that
$$p(\bm\theta|\mathbf{y}_{1:\mathtt{Tr}})  \approx  \mathcal{N}\left(\bm\theta;\bm\theta^{*},-\mathbf{H}(\bm\theta^{*})^{-1}\right),
\label{EQ: LaA}
$$
where $\mathbf{H}(\bm\theta^{*})$ is the second derivative of the negative log-likelihood function evaluated at the optimal vector of model parameters $\bm\theta^{*}$.

\subsubsection{Model parameter space transformation}
\label{SS:THSpaceTransformation}

In OpenBDLM, some model parameters  are defined in a bounded interval. During the learning procedure, it may happen that new model parameters $\bm\theta_{\text{new}}$ are proposed outside their valid interval.
Those parameters must be rejected, which hinders the computational efficiency of the optimization algorithm.
The solution to tackle this problem proposed for OpenBDLM is to transform these bounded model parameters into an unbounded space, where the parameters lie in the interval $[ -\infty, +\infty ]$. The transformation is done using a function $g(.)$ so that,
\begin{equation}
\theta^{\text{tr}} = g(\theta) \text{, }\quad \theta^{\text{tr}} \in [-\infty, +\infty ] \text{.}
\end{equation}
The choice of the function $g(.)$ depends on the bound of $\theta$.
Three cases generally occur:
\begin{itemize}
\item $ \theta \in [-\infty, +\infty ]$ , $g(\theta) = 1$, so that $\theta^{\text{tr}} = \theta$ and $\theta = \theta^{\text{tr}} $
\item $ \theta \in [0, +\infty ]$, $g(\theta) = \ln(\theta)$, so that $\theta^{\text{tr}} = \ln(\theta) $ and $\theta = e^{\theta^{\text{tr}}} $
\item $ \theta \in [\text{a}, \text{b}]$, $g(\theta) = \text{sigmoid}(\theta)$, so that $\theta^{\text{tr}} = -\ln \left( \frac{b-a}{\theta-a} - 1\right) $, and $\theta = \left( \frac{b-a}{1+e^{-\theta^{\text{tr}}}} + a \right).$
\end{itemize}
%For instance, the standard deviation model parameters are real numbers that lie in the $[0, +\infty]$ interval and the logarithm transformation is used.
%Moreover, the autoregression coefficient model parameters are real numbers that lie in the $[0, 1]$ interval, and the sigmoid transformation is used.

%\subsection{Model parameter estimation}
%\label{SS:THModelParameterEstimation}
%The matrices $\mathbf{A}_{t}$,  $\mathbf{Q}_{t}$,   $\mathbf{C}_{t}$ and  $\mathbf{R}_{t}$ depend on a set of model parameters $\bm{\theta}$.
%In most cases, $\bm{\theta}$ are unknown, and they can be learned from a training dataset $\mathbf{y}_{1:\mathtt{Tr}}$.
%The procedure of learning the model parameters is hereafter referred to as model parameters estimation.
%\subsubsection{Maximum log A Posteriori (MAP)}
%
%The log a posteriori probability density function (PDF) is defined as
%\begin{equation}
%%\begin{array}{rcl}
%\ln p(\bm\theta|\mathbf{y}_{1:\mathtt{Tr}}) \, \propto \, \ln p(\mathbf{y}_{1:\mathtt{Tr}}|\bm\theta) + \ln p(\bm\theta),
%%\end{array}
%\label{EQ:BT}
%\end{equation}
%where $p(\mathbf{y}_{1:\mathtt{Tr}}|\bm\theta)$ is the likelihood,  $p(\bm\theta)$ is the prior PDF.
%The likelihood PDF is the joint prior probability density of observations, that is, plausibility of the available observations $\mathbf{y}_{1:\mathtt{Tr}}$ given the parameter vector $\bm\theta$.
%Assuming that the observations errors are independent from each other, the joint log-likelihood function is defined as the sum of the marginal log-likelihoods, such as
%\begin{equation}
%\ln p(\mathbf{y}_{1:\mathtt{Tr}}|\bm\theta)  = \displaystyle\sum_{t=1}^{\mathtt{Tr}} \ln p(\mathbf{y}_{t}|\mathbf{y}_{1:t-1},\bm \theta) = \displaystyle\sum_{t=1}^{\mathtt{Tr}} \ln \left[ \sum_{j=1}^{\mathtt{S}} \sum_{i=1}^{\mathtt{S}} \mathcal{L}_{t}^{i(j)} \pi_{t-1|t-1}^{i} Z_{t}^{i(j)} \right] \text{,}
%\label{EQ:LP}
%\end{equation}
%where $\mathcal{L}_{t}^{i(j)}$ and  $\pi_{t-1|t-1}^{i}$ are computed at each time $t$ from the Switching Kalman Filter; $\mathtt{S}$ is the total number of model class, and the values of $Z_{t}^{i(j)}$ are known from the current set of model parameters.
%The maximum log a posteriori procedure consists in identifying the point estimates by maximizing the log A Posteriori PDF, such as
%\begin{equation*}
%\bm\theta^{*} = \underset{\bm\theta}{\text{arg}\max}\left[\ln p(\bm\theta|\mathbf{y}_{1:\mathtt{Tr}}) \right] \text{,}
%\end{equation*}
%where $\bm\theta^{*}$ are the optimized model parameters values.
%
%\subsubsection{Maximum log Likelihood Estimation (MLE)}
%
%The Maximum log Likelihood Estimation (MLE) is a special case of the MAP where the prior PDF $p(\bm\theta)$ is assumed to be uniform \cite{gelman2014bayesian}.
%Therefore, the Maximum log Likelihood procedure consists in identifying the point estimates by maximizing the log likelihood PDF, such as
%\begin{equation*}
%\bm\theta^{*} = \underset{\bm\theta}{\text{arg}\max}\left[\ln  p(\mathbf{y}_{1:\mathtt{Tr}}|\bm\theta) \right] \text{,}
%\end{equation*}
%where $\bm\theta^{*}$ are the optimized model parameters values.
%
%
%\subsubsection{Laplace Approximation}
%
%The MAP and MLE are point estimation methods which do not take into account the uncertainty in the parameter estimates $\bm\theta^{*}$.
%The estimation of the uncertainties in the model parameters estimates can be addressed using the Laplace approximation \cite{gelman2014bayesian} so that
%$$p(\bm\theta|\mathbf{y}_{1:\mathtt{Tr}})  \approx  \mathcal{N}\left(\bm\theta;\bm\theta^{*},-\mathbf{H}(\bm\theta^{*})^{-1}\right),
%\label{EQ: LaA}
%$$
%where $\mathbf{H}(\bm\theta^{*})$ is the second derivative of the log a posteriori or log likelihood PDF evaluated at the optimal parameter values $\bm\theta^{*}$.
%
%\subsubsection{Gradient-based optimization}
%
%The gradient-based optimizations techniques are iterative approaches which can be used to find the model parameters that correspond to the maximum of a target PDF, hereafter noted $\mathcal{T}(\bm{\theta})$.
%The function $\mathcal{T}(\bm{\theta})$  is either the log a posteriori or the log likelihood PDF computed from the data.
%One iteration of gradient based algorithm is
%
%\begin{equation}
%{\bm\theta}_{\text{new}}  = {\bm\theta}_{\text{old}} - \eta \nabla \mathcal{T}(\bm{\theta}_{\text{old}}),
%\label{EQ:GBA}
%\end{equation}
%
%where $\eta$ is the learning rate, and $\nabla$ the first derivative.
%
%\paragraph{Parameter-wise Newton-Raphson}
%
%The parameter-wise Newton-Raphson \cite{gelman2014bayesian} algorithm is an iterative approach which can be used to find the model parameters that correspond to the maximum of a target PDF, hereafter noted $\mathcal{T}_{1:\mathtt{Tr}}(\bm{\theta})$.
%The underscripts $1:\mathtt{Tr}$ indicate that the target function is evaluated using a \emph{training dataset} of length $\mathtt{Tr}$.
%%The function $\mathcal{T}_{1:\mathtt{Tr}}(\bm{\theta})$  is either the log a posteriori or the log likelihood PDF.
%The Newton-Raphson algorithm adaptively sets the learning rate using the second derivative and a factor noted $\lambda$.
%One \emph{iteration} of the Newton-Raphson algorithm is
%\begin{equation}
%{\theta}_{\text{new}}^{i}  = {\theta}_{\text{old}}^{i} - \lambda \frac{\nabla \mathcal{T}_{1:\mathtt{Tr}}(\bm{\theta}_{\text{old}}^{i}) }{  \nabla^{2} \mathcal{T}_{1:\mathtt{Tr}}(\bm{\theta}_{\text{old}}^{i})},
%\label{EQ:NR}
%\end{equation}
%where $i$ is the index of the parameter being learned, $\nabla$ the first derivative, $\nabla^{2}$ the second derivative.
%$\bm{\theta}_{\text{old}}$ and $\bm{\theta}_{\text{new}}$ are the previous and updated vector of model parameters.
%One parameter is updated at each iteration.
%The convergence of each model parameters is reached when the following conditions are satisfied
%\begin{equation}
%\left\{\begin{array}{ccc}
%\mathcal{T}_{1:\mathtt{Tr}}(\bm\theta^{i}_{\text{old}}) &<&\mathcal{T}_{1:\mathtt{Tr}}(\bm\theta^{i}_{\text{new}})\\[4pt]
%\left|\mathcal{T}_{1:\mathtt{Tr}}(\bm\theta^{i}_{\text{new}}) -  \mathcal{T}_{1:\mathtt{Tr}}(\bm\theta^{i}_{\text{old}})\right| &\leq& \tau \cdot \left|\mathcal{T}_{1:\mathtt{Tr}}(\bm\theta^{i}_{\text{old}})\right|
%\end{array}\right.,
%\label{EQ:STC}
%\end{equation}
%where $\tau$ is a termination tolerance.
%The Newton-Raphson algorithm stops when each model parameters has reached the convergence.
%
%\paragraph{Stochastic gradient}
%
%In the stochastic gradient technique, the target function and its derivatives are approximated at each iteration using a \emph{mini-batch} of data of length $\mathtt{Tb} \ll \mathtt{Tr}$.
%Therefore, the target function is noted $\mathcal{T}_{1:\mathtt{Tb}}(\bm{\theta})$.
%At each iteration, the beginning of the mini-batch is selected randomly.
%One \emph{epoch} consists in one pass over the full training dataset (i.e. all the training data have been seen once).
%Therefore, one epoch is made of many iterations.
%Note that more than one model parameters is usually updated during one epoch.
%Several epochs are needed to reach convergence.
%%Classical implementation of stochastic gradient algorithm includes momentum approach (e.g MMT optimizer) or adaptive learning rate (e.g. Adam optimizer) to increase the performance \cite{Goodfellow-et-al-2016}.
%The convergence is reached when the following condition between two successive epochs is satisfied
%\begin{equation}
%\mathcal{T}^{\text{epoch}} (\bm\theta) > \tau  \cdot \mathcal{T}^{\text{epoch-1}} (\bm\theta)
%\label{EQ:SGT}
%\end{equation}
%where $0 \le \tau \le 1$ is a termination tolerance.
%Classical implementation of stochastic gradient algorithm includes momentum approach (e.g MMT optimizer) or adaptive learning rate (e.g. Adam optimizer) to increase the performance \cite{Goodfellow-et-al-2016}.
%
%\paragraph{Approximation of the derivatives}
%
%In many cases, the derivatives of $\mathcal{T}(\bm{\theta})$ cannot be computed analytically.
%Therefore, the derivatives are approximated numerically using the central differentiation scheme, such as
%\begin{gather}
%\begin{aligned}
% \nabla \mathcal{T}(\bm\theta^{i}) & = \frac{\partial \mathcal{T} (\bm\theta) }{\partial \theta^{i}} \approx \frac{\mathcal{T} (\bm\theta + \mathbb{I}(i)\Delta \theta^{i} )  -  \mathcal{T} (\bm\theta - \mathbb{I}(i)\Delta \theta^{i} ) }{2\Delta \theta^{i}}  \\
% \nabla^{2} \mathcal{T}(\bm\theta^{i}) & = \frac{\partial^{2} \mathcal{T} (\bm\theta) }{\partial^{2} \theta^{i}} \approx \frac{\mathcal{T} (\bm\theta + \mathbb{I}(i)\Delta \theta^{i} )  -  2 \mathcal{T} (\bm\theta) +  \mathcal{T} (\bm\theta - \mathbb{I}(i)\Delta \theta^{i} ) }{(\Delta \theta^{i})^{2}},
%\label{EQ:numericaldiff}
%\end{aligned}
%\end{gather}
%where $\Delta \theta^{i}$ is a small perturbation to the value of the $i^{\text{th}}$ model parameters and $\mathbb{I}(i)$ is an indicator vector for which all values are equal to $0$, except the $i^{\text{th}}$ value which is equal to one.
%
%
%\subsubsection{Model parameter space transformation}
%\label{SS:THSpaceTransformation}
%
%There are some model parameters which are defined in a bounded interval.
%For instance, the standard deviation model parameters are real numbers that lie in the $[0, +\infty]$ interval.
%%The autoregression coefficient model parameters are real numbers that lie in the $[0, 1]$ interval.
%Therefore, during the learning procedure, it may happen that new model parameters $\bm\theta_{\text{new}}$ are proposed outside their valid interval.
%Those parameters must be rejected, which strongly hinders the computational efficiency of the learning algorithm.
%The solution employed in OpenBDLM is to transform the bounded space into an unbounded one, where the parameters lie in the interval $[ -\infty, +\infty ]$. The transformation is done using a function $g(.)$ so that,
%\begin{equation}
%\theta^{\text{tr}} = g(\theta) \text{, }\quad \theta^{\text{tr}} \in [-\infty, +\infty ] \text{.}
%\end{equation}
%The choice of the function $g(.)$ depends on the bound of $\theta$.
%Three cases generally occur:
%\begin{itemize}
%\item $ \theta \in [-\infty, +\infty ]$ , $g(\theta) = 1$, so that $\theta^{\text{tr}} = \theta$ and $\theta = \theta^{\text{tr}} $
%\item $ \theta \in [0, +\infty ]$, $g(\theta) = \ln(\theta)$, so that $\theta^{\text{tr}} = \ln(\theta) $ and $\theta = e^{\theta^{\text{tr}}} $
%\item $ \theta \in [\text{a}, \text{b}]$, $g(\theta) = \text{sigmoid}(\theta)$, so that $\theta^{\text{tr}} = -\ln \left( \frac{b-a}{\theta-a} - 1\right) $, and $\theta = \left( \frac{b-a}{1+e^{-\theta^{\text{tr}}}} + a \right)$
%\end{itemize}
%For instance, the standard deviation model parameters are real numbers that lie in the $[0, +\infty]$ interval and the logarithm transformation is used.
%Moreover, the autoregression coefficient model parameters are real numbers that lie in the $[0, 1]$ interval, and the sigmoid transformation is used.

\subsection{Block components}
\label{SS:BlockComponent}
The block components are pieces of the full model.
Each block component is used to describe a given dynamics for a given time series.
Therefore, each block component has its own transition and observation model, which are associated with some model parameters.
Each block component can be associated with one or more hidden states variables.
%The types of block components supported in the current OpenBDLM version are listed in the next sections.
The block components are then assembled to build the full model.
The block components associated with irreversible change in the time series belongs to the \emph{baseline} component.
The other block components are associated with reversible change in the time series.
The \emph{compatible} block component are needed to model switching dynamics in the baseline of the time series.

\subsubsection{Local level (baseline)}

The local level block component describes the local mean of a stationary time series (no trend and no acceleration) \cite{STC:STC2035}.
The local level describes irreversible changes.\\

\noindent
Number of hidden states: 1\\

Hidden states vector:
\begin{gather*}
\mathbf{x}^{\mathtt{LL}} = [x^{\mathtt{LL}}]
\end{gather*}
Transition matrix:
\begin{gather*}
\mathbf{A}^{\mathtt{LL}}=[1]
\end{gather*}
Observation matrix:
\begin{gather*}
\mathbf{C}^{\mathtt{LL}}=[1]
\end{gather*}
Process noise covariance matrix:
\begin{gather*}
\mathbf{Q}^{\mathtt{LL}}=[(\sigma_{w}^{\mathtt{LL}})^{2}]
\end{gather*}
Model parameters:
\begin{gather*}
\bm\theta^{\mathtt{LL}}=[\sigma_{w}^{\mathtt{LL}} ]
\end{gather*}

\noindent
$\sigma_{w}^{\mathtt{LL}}$ is the process noise standard deviation which can be learned from the data.

\subsubsection{Local trend (baseline)}

The local trend block component describes the local mean of a trend-stationary time series (trend and no acceleration) \cite{STC:STC2035}.
The local trend describes irreversible changes.\\

\noindent
Number of hidden states: 2\\

Hidden states vector:
\begin{gather*}
 \mathbf{x}^{\mathtt{LT}} = [x^{\mathtt{L}}, x^{\mathtt{LT}}]^{\intercal}
 \end{gather*}
Transition matrix:
\begin{gather*}
\mathbf{A}^{\mathtt{LT}}= \left[\begin{array}{cc}1 &\Delta t\\0&1\end{array}\right]
\end{gather*}
Observation matrix:
\begin{gather*}
\mathbf{C}^{\mathtt{LT}}=[1, 0]
\end{gather*}
Process noise covariance matrix:
\begin{gather*}
\mathbf{Q}^{\mathtt{LT}}= (\sigma_{w}^{\mathtt{LT}})^{2}\left[\begin{array}{cc}\tfrac{\Delta t^{4}}{4} &\tfrac{\Delta t^{3}}{2}\\\tfrac{\Delta t^{3}}{2}&\Delta t^{2}\end{array}\right]
\end{gather*}
Model parameters:
\begin{gather*}
\bm\theta^{\mathtt{LT}}=[\sigma_{w}^{\mathtt{LT}} ]
\end{gather*}

\noindent
$\sigma_{w}^{\mathtt{LT}}$ is the process noise standard deviation, which can be learned from the data, and $\Delta t$ is the local timestep computed from the data.

\subsubsection{Local acceleration (baseline)}

The local acceleration block component describes the local mean of a acceleration-stationary time series \cite{STC:STC2035}.
It describes irreversible changes.\\

\noindent
Number of hidden states: 3\\

Hidden states vector:
\begin{gather*}
\mathbf{x}^{\mathtt{LA}} = [x^{\mathtt{L}}, x^{\mathtt{T}} ,  x^{\mathtt{LA}}]^{\intercal}
\end{gather*}
Transition matrix:
\begin{gather*}
\mathbf{A}^{\mathtt{LA}}=  \left[\begin{array}{ccc}1 &\Delta t&\Delta t^{2}\\0&1&\Delta t\\0&0&1\end{array}\right]
\end{gather*}
Observation matrix:
\begin{gather*}
\mathbf{C}^{\mathtt{LA}}=[1, 0, 0]
\end{gather*}
Process noise covariance matrix:
\begin{gather*}
\mathbf{Q}^{\mathtt{LA}}=(\sigma_{w}^{\mathtt{LA}})^{2}\left[\begin{array}{ccc}\tfrac{\Delta t^{4}}{4} &\tfrac{\Delta t^{3}}{2} &\tfrac{\Delta t^{2}}{2}\\\tfrac{\Delta t^{3}}{2} &\Delta t^{2}&\Delta t\\\tfrac{\Delta t^{2}}{2}&\Delta t&1\end{array}\right]
\end{gather*}
Model parameters:
\begin{gather*}
\bm\theta^{\mathtt{LA}}=[\sigma_{w}^{\mathtt{LA}} ]
\end{gather*}

\noindent
$\sigma_{w}^{\mathtt{LA}}$ is the process noise standard deviation, which can be learned from the data, and $\Delta t$ is the local timestep computed from the data.

\subsubsection{Local level compatible trend (baseline)}

The local level trend compatible component must be used in case of model switching between a local level model and a local trend model \cite{Nguyen2018}.
The local level trend compatible block component describes the local mean of a stationary time series.
It describes irreversible changes.\\

\noindent
Number of hidden states: 1\\

Hidden states vector:
\begin{gather*}
 \mathbf{x}^{\mathtt{LcT}} = [x^{\mathtt{LL}}, x^{\mathtt{LTc}}=0]^{\intercal}
 \end{gather*}
Transition matrix:
\begin{gather*}
\mathbf{A}^{\mathtt{LcT}}= \left[\begin{array}{cc}1 & 0\\0&0\end{array}\right]
\end{gather*}
Observation matrix:
\begin{gather*}
\mathbf{C}^{\mathtt{LcT}}=[1, 0]
\end{gather*}
Process noise covariance matrix:
\begin{gather*}
\mathbf{Q}^{\mathtt{LcT}}=(\sigma_{w}^{\mathtt{LcT}})^{2}\left[\begin{array}{cc}1 &0\\0&0\end{array}\right]
\end{gather*}
Model parameters:
\begin{gather*}
\bm\theta^{\mathtt{LcT}}=[\sigma_{w}^{\mathtt{LcT}} ]
\end{gather*}

\noindent
$\sigma_{w}^{\mathtt{LcT}}$ is the process noise standard deviation, which can be learned from the data, and $\Delta t$ is the local timestep computed from the data.

\subsubsection{Local level compatible acceleration (baseline)}

The local level acceleration compatible component must be used in case of model switching between a local level model and a local acceleration model \cite{Nguyen2018}.
The local level acceleration compatible block component describes the local mean of a stationary time series.
It describes irreversible changes.\\

\noindent
Number of hidden states: 1\\

Hidden states vector:
\begin{gather*}
 \mathbf{x}^{\mathtt{LcA}} = [x^{\mathtt{LL}}, x^{\mathtt{LTc}}=0, x^{\mathtt{LAc}}=0]^{\intercal}
 \end{gather*}
Transition matrix:
\begin{gather*}
\mathbf{A}^{\mathtt{LcA}}= \left[\begin{array}{ccc}1&0&0\\0&0&0\\0&0&0\end{array}\right]
\end{gather*}
Observation matrix:
\begin{gather*}
\mathbf{C}^{\mathtt{LcA}}=[1, 0, 0]
\end{gather*}
Process noise covariance matrix:
\begin{gather*}
\mathbf{Q}^{\mathtt{LcA}}=(\sigma_{w}^{\mathtt{LcA}})^{2}\left[\begin{array}{ccc}1&0&0\\0&0&0\\0&0&0\end{array}\right]
\end{gather*}
Model parameters:
\begin{gather*}
\bm\theta^{\mathtt{LcA}}=[\sigma_{w}^{\mathtt{LcA}} ]
\end{gather*}

\noindent
$\sigma_{w}^{\mathtt{LcA}}$ is the process noise standard deviation, which can be learned from the data, and $\Delta t$ is the local timestep computed from the data.

\subsubsection{Local trend compatible acceleration (baseline)}
The local trend acceleration compatible component must be used in case of model switching between a local trend model and a local acceleration model \cite{Nguyen2018}.
The local trend acceleration compatible block component describes the local mean of a trend-stationary time series.
It describes irreversible changes.\\

\noindent
Number of hidden states: 2\\
Hidden states vector:
\begin{gather*}
 \mathbf{x}^{\mathtt{TcA}} = [x^{\mathtt{L}}, x^{\mathtt{LT}} , x^{\mathtt{LAc}}=0]^{\intercal}
 \end{gather*}
Transition matrix:
\begin{gather*}
\mathbf{A}^{\mathtt{TcA}}= \left[\begin{array}{ccc}1&\Delta t&0\\0&1&0\\0&0&0\end{array}\right]
\end{gather*}
Observation matrix:
\begin{gather*}
\mathbf{C}^{\mathtt{TcA}}=[1, 0, 0]
\end{gather*}
Process noise covariance matrix:
\begin{gather*}
\mathbf{Q}^{\mathtt{TcA}}=(\sigma_{w}^{\mathtt{TcA}})^{2}  \left[\begin{array}{ccc}\tfrac{\Delta t^{4}}{4} &\tfrac{\Delta t^{3}}{2}&0\\\tfrac{\Delta t^{3}}{2}&\Delta t^{2}&0\\0&0&0\end{array}\right]
\end{gather*}
Model parameters:
\begin{gather*}
\bm\theta^{\mathtt{TcA}}=[\sigma_{w}^{\mathtt{TcA}} ]
\end{gather*}

\noindent
$\sigma_{w}^{\mathtt{TcA}}$ is the process noise standard deviation, which can be learned from the data, and $\Delta t$ is the local timestep computed from the data.

\subsubsection{Periodic (Fourier form)}

The periodic (Fourier form) block component describes a periodic pattern in the time series using Fourier form \cite{west1999bayesian,STC:STC2035}.
The periodic Fourier form allows modelling sine-like periodic pattern in time series.
It describes reversible changes.\\

\noindent
Number of hidden states: 2\\

Hidden states vector:
\begin{gather*}
\mathbf{x}^{\mathtt{P}} = [x^{\mathtt{P}_ {1}}, x^{\mathtt{P}_{2}}]^{\intercal}
\end{gather*}
Transition matrix:
\begin{gather*}
\mathbf{A}^{\mathtt{P}}= \left[\begin{array}{cc}\cos \omega &\sin \omega\\-\sin \omega&\cos \omega\end{array}\right]
\end{gather*}
Observation matrix:
\begin{gather*}
\mathbf{C}^{\mathtt{P}}=[1, 0]
\end{gather*}
Process noise covariance matrix:
\begin{gather*}
\mathbf{Q}^{\mathtt{P}}=(\sigma_{w}^{\mathtt{P}})^{2}\left[\begin{array}{cc}1 &0\\0&1\end{array}\right]
\end{gather*}
Model parameters:
\begin{gather*}
\bm\theta^{\mathtt{P}}=[\sigma_{w}^{\mathtt{P}}, p^{\mathtt{P}} ]
\end{gather*}

\noindent
$\sigma_{w}^{\mathtt{P}}$ is the process noise standard deviation and $p$ the period in days, which can be learned from the data, and $\Delta t$ is the local timestep computed from the data.
 $\omega=\frac{2\pi \Delta t}{p}$ is the angular of frequency defined from the period $p$, given in days.

\subsubsection{Periodic (Kernel regression form)}\label{SSS:KR}

The periodic (Kernel regression form) block component describes a periodic pattern in the time series using periodic kernel regression  \cite{Nguyen2019KRBDLM}.
The periodic Kernel regression form allows modelling form-free periodic pattern in time series.
It describes reversible changes.
The periodic kernel measures the similarity between pairs of covariates, and it is defined as
\begin{gather*}
k(t_{i},t_{j})=\exp\left[-\frac{2}{\ell^2}\sin\left( \pi\frac{t_i-t_{j}}{p}\right)^{2}\right].
\end{gather*}
The kernel output $k(t_{i},t_{j})\in(0,1)$ measures the similarity between two timestamps $t_{i}$ and $t_{j}$ as a function of the distance between these, as well as a function of two parameters; the period and kernel length, $\bm{\theta}=[p,\ell]$.
\noindent\\
Number of hidden states:  $\mathtt{L}^{\mathtt{KR}}+1$\\

Hidden states vector:
\begin{gather*}
\mathbf{x}^{\mathtt{KR}} = [x^{\mathtt{KR}}_{0}, x^{\mathtt{KR}}_{1}, \dots, x^{\mathtt{KR}}_{\mathtt{L}^{\mathtt{KR}}}]^{\intercal}
\end{gather*}
Transition matrix:
\begin{gather*}
\mathbf{A}^{\mathtt{KR}}= \left[\begin{array}{cc}0 &\tilde{\bm k}^{\mathtt{KR}}(t, \mathbf{t}^{\mathtt{KR}})\\\mathbf{0}&\mathbf{I}_{\mathtt{L}^{\mathtt{KR}}}\end{array}\right]
\end{gather*}
Process noise covariance matrix:
\begin{gather*}
\mathbf{Q}^{\mathtt{KR}}=\left[\begin{array}{cc}(\sigma_{w,0}^{\mathtt{KR}})^{2} &\mathbf{0}\\\mathbf{0}&(\sigma_{w,1}^{\mathtt{KR}})^{2}\cdot\mathbf{I}_{\mathtt{L}^{\mathtt{KR}} }\end{array}\right]
\end{gather*}
Observation matrix:
\begin{gather*}
\mathbf{C}^{\mathtt{KR}}=[1, 0, \dots, 0]
\end{gather*}
Model parameters:
\begin{gather*}
\bm\theta^{\mathtt{KR}}=[ p^{\mathtt{KR}},\ell^{\mathtt{KR}},  \sigma_{w,0}^{\mathtt{KR}}, \sigma_{w,1}^{\mathtt{KR}}]
\end{gather*}

\noindent
In the transition matrix, $\tilde{\bm k}^{\mathtt{KR}}(t,\mathbf{t}^{\mathtt{KR}})$ corresponds to the normalized kernel, $k(t,\mathbf{t}^{\mathtt{KR}})/\sum_{t} k(t,\mathbf{t}^{\mathtt{KR}})$. $\tilde{\bm k}^{\mathtt{KR}}(t,\mathbf{t}^{\mathtt{KR}})$ is parameterized by the kernel width $\ell^{\mathtt{KR}}$, its period $p^{\mathtt{KR}}$, and a vector of $\mathtt{L}^{\mathtt{KR}}$ timestamps $\mathbf{t}^{\mathtt{KR}}=[t_{1}^{\mathtt{KR}},\cdots,t_{\mathtt{L}^{\mathtt{KR}}}^{\mathtt{KR}}]$ where each timestamp $t_{i}^{\mathtt{KR}}$ is associated with a hidden control point value $x_{i}^{\mathtt{KR}}$.
$\sigma_{w,1}^{\mathtt{KR}}$ controls the process noise  variance of the hidden control points between successive time steps and $\sigma_{w,0}^{\mathtt{KR}}$ controls the time-independent process noise in the hidden predicted pattern.
$p^{\mathtt{KR}}$ and $\ell^{\mathtt{KR}}$ give the period and correlation length of the kernel.

\subsubsection{First order autoregressive}

The first order autoregressive component describes the time-dependent model errors (i.e the residual between the model prediction and the data) \cite{STC:STC2035}.
It describes reversible changes.\\

\noindent
Number of hidden states: 1\\

Hidden states vector:
\begin{gather*}
\mathbf{x}^{\mathtt{AR}} = [x^{\mathtt{AR}}]
\end{gather*}
Transition matrix:
\begin{gather*}
\mathbf{A}^{\mathtt{AR}}=  [\phi^{\mathtt{AR}}]
\end{gather*}
Observation matrix:
\begin{gather*}
\mathbf{C}^{\mathtt{AR}}=[1]
\end{gather*}
Process noise covariance matrix:
\begin{gather*}
\mathbf{Q}^{\mathtt{AR}}=[(\sigma_{w}^{\mathtt{AR}})]
\end{gather*}
Model parameters:
\begin{gather*}
\bm\theta^{\mathtt{AR}}=[\sigma_{w}^{\mathtt{AR}}, \phi^{\mathtt{AR}} ]
\end{gather*}

\noindent
$\sigma_{w}^{\mathtt{AR}}$ is the process noise standard deviation, and $\phi^{\mathtt{AR}}$ the autoregressive coefficient.

\subsubsection{Local Intervention}\label{SSS:LI}

The local intervention block component describes the discrete shifts occurring in a time series. Shifts typically happens a sensor fails; when a sensor fails, the data start to be missing (i.e. \lstinline[basicstyle = \mlttfamily \small, backgroundcolor = \color{light-gray}]!NaN!) and it often takes from several weeks to several months before the sensor is replaced. When the sensor is replaced, it is in most cases re-initialized at a different initial value than the previous sensor which lead to a discrete shift in the time series, as depicted in Figure~\ref{fig:DataSummary1}. When using a Level intervention component, the user must provide discrete timestamps where it is required to estimate the magnitude of a discrete shift in the dataset. A user can do so by specifying in the configuration file \lstinline[basicstyle = \mlttfamily \small, backgroundcolor = \color{light-gray}]!data.interventions=[t_{1}, t_{2}, ... , t_{n}]!, where \lstinline[basicstyle = \mlttfamily \small, backgroundcolor = \color{light-gray}]!n! is the number of interventions.

The local intervention describes irreversible changes.\\

\noindent
Number of hidden states: 1\\

Hidden states vector:
\begin{gather*}
\mathbf{x}^{\mathtt{LI}} = [x^{\mathtt{LI}}]
\end{gather*}
Transition matrix:
\begin{gather*}
\mathbf{A}^{\mathtt{LI}}=[1]
\end{gather*}
Observation matrix:
\begin{gather*}
\mathbf{C}^{\mathtt{LI}}=[1]
\end{gather*}
Process noise covariance matrix:
\begin{gather*}
\mathbf{Q}^{\mathtt{LI}}=[(\sigma_{w}^{\mathtt{LI}})^{2}]
\end{gather*}
Model parameters:
\begin{gather*}
\bm\theta^{\mathtt{LI}}=[\mu_{b}^{\mathtt{LI}}, \sigma_{b}^{\mathtt{LI}} ]
\end{gather*}
\noindent
$\sigma_{w}^{\mathtt{LI}}$ is the standard deviation describing the uncertainty associated with the magnitude of the shift and $\mu_{b}^{\mathtt{LI}}$ is its expected magnitude;  Both parameters can be kept to their default values or be learned from the data.

For the Local intervention component, the Equation \ref{EQ:SSM_Transition} is modified to include an additional  intervention term $b_{t}$
\begin{equation}
  \mathbf{x}_{t}^{\mathtt{LI}}=\mathbf{A}_{t}^{\mathtt{LI}}\mathbf{x}_{t-1}^{\mathtt{LI}}+{w}_{t}^{\mathtt{LI}}+b_{t}^{\mathtt{LI}},\quad\left\{
  \begin{array}{l}
{w}_{t}^{\mathtt{LI}}\sim \mathcal{N}({0},
\mathbf{Q}_{t}^{\mathtt{LI}})\\[4pt]
b_{t}^{\mathtt{LI}}\sim\mathcal{N}(\mu_{b}^{\mathtt{LI}},
\sigma_{b}^{\mathtt{LI}})
\end{array}\right.
\end{equation}
The local Intervention component allows estimating the shifts $\mathbf{x}_{t|t}^{\mathtt{LI}}$ caused by the interventions for which the discrete timestamps are specified in \lstinline[basicstyle = \mlttfamily \small, backgroundcolor = \color{light-gray}]!data.interventions!.

\subsection{Handling non-uniform time vector and missing data}
\label{SS:HandlingNonUniformMissingData}

\subsubsection{Non-uniform time vector}
\label{SS:NonUniform}

Non uniform time vector occurs when the time between two successive data measurements (i.e. the timestep) varies with time.
In order to accommodate non-uniform time vector, OpenBDLM employs an approximate method which is based on a reference time step $\Delta t^{\text{ref}} $ \cite{STC:STC2035}.
The reference time-step is a value corresponding to the most frequent time step in the time series.
All parameter values in the parameter set $\bm \theta$ are estimated for the reference time step.
Therefore, for local time step $\Delta t$ different than the reference timestep $\Delta t^{\text{ref}} $, the parameters value must be adapted accordingly.
As an approximation, the model error standard deviations  $\sigma_{w}$ in $\mathbf{Q}_{t}$ are scaled proportionally to the ratio between the current time step and the reference time step so that,
\begin{gather*}
\sigma_{w}^{\Delta t}= \sigma_{w}^{\Delta t ^{\text{ref}}}\frac{\Delta t}{\Delta t ^{\text{ref}}}.
\end{gather*}
Therefore, the amount of process noise in the prediction model increases as the local time step increase with respect to the reference time step.

The transition matrix $\mathbf{A}^{\mathtt{AR}}$ contains the autoregressive coefficients $\phi^{\mathtt{AR}}$ that are recursively multiplied with the hidden state at each time step.
To account for time step changes, the autoregressive coefficients are elevated to the power of the ratio between the current time step and the reference time step, such as
\begin{gather*}
\phi^{\mathtt{AR}, \Delta t}=  (\phi^{\mathtt{AR}, \Delta t ^{\text{ref}}})^{\frac{\Delta t}{\Delta t ^{\text{ref}}}}.
\end{gather*}
Therefore, the autocorrelation between successive data samples in the autoregressive prediction model decreases as the local time step increase with respect to the reference time step.
Note that this procedure is an approximation.
\subsubsection{Missing data (NaN)}

The presence of missing data (\lstinline[basicstyle = \mlttfamily \small ]!NaN!) for specific timestamps prevents the completion of the Kalman update-step \cite{STC:STC2035}.
However, the prediction step using the current transition model can be done.
%No update is performed at times associated with missing data (NaN), and only the prediction step is performed.
Therefore, BDLM automatically fills gaps when data are missing using the transition model in the prediction step.

\subsection{Dependencies between time series}
\label{S:Dependencies}
The dependencies between time series are handled by adding regression coefficients $\phi^{i|j}$ in the observation matrix (See \S\ref{S:ExampleDispTemp}).
For a dataset with $\mathtt{D}$ time series, the observation matrix is
\begin{equation*}
\mathbf{C}=\left[\begin{array}{cccccc}
\mathbf{C}^{1}& \mathbf{C}_{1,2}^{c}&\cdots & \mathbf{C}_{1,j}^{c}&\cdots& \mathbf{C}_{1,\mathtt{D}}^{c}\\
\mathbf{C}_{2,1}^{c}& \mathbf{C}^{2}&\cdots& \mathbf{C}_{2,j}^{c}&\cdots& \mathbf{C}_{2,\mathtt{D}}^{c}\\
\vdots&\vdots& \vdots& \vdots& \ddots& \vdots\\
\mathbf{C}_{i,1}^{c}& \mathbf{C}_{i,2}^{c}&\cdots&\mathbf{C}_{i,j}^{c}&\cdots&\mathbf{C}_{i,\mathtt{D}}^{c}\\
\vdots&\vdots& \vdots& \vdots& \ddots& \vdots\\
\mathbf{C}_{\mathtt{D},1}^{c}& \mathbf{C}_{\mathtt{D},2}^{c}&\cdots& \mathbf{C}_{\mathtt{D},j}^{c}&\cdots& \mathbf{C}^{\mathtt{D}}
\end{array}\right] \text{.}
\end{equation*}
The dependence matrix is a matrix with $0$ and $1$ which is used to indicate which time series have dependencies between each others, such as

\begin{equation*}
\mathbf{D}=\left[\begin{array}{cccccc}
1&d_{1,2}&\cdots&d_{1,j}&\cdots&d_{1,\mathtt{D}}\\
d_{2,1}&1&\cdots&d_{2,j}&\cdots&d_{2,\mathtt{D}}\\
\vdots&\vdots&\vdots&\vdots&\ddots&\vdots\\
d_{i,1}&d_{i,2}&\cdots&1&\cdots&d_{i,\mathtt{D}}\\
\vdots&\vdots&\vdots&\vdots&\ddots&\vdots\\
d_{\mathtt{D},1}&d_{\mathtt{D},2}&\cdots&d_{\mathtt{D},j}&\cdots&1\\
\end{array}\right] \text{.}
\end{equation*}
Then,
\begin{itemize}
\item if $d_{i,j}=0$, $\mathbf{C}_{i,j}^{c}=[\mathbf{0}]$
\item if $d_{i,j}=1$, $\mathbf{C}_{i,j}^{c}=\left[\phi^{i|j}_{1},\phi^{i|j}_{2},\cdots,\phi^{i|j}_{k_{j}}\right]$ where $k_{j}$ is the number of hidden states associated with the $j^{th}$ time series.
\end{itemize}
The regression coefficient $\phi^{i|j}_{k}$ gives the linear dependence between the $k^{th}$ hidden states of the $j^{th}$ time series and the $i^{th}$ time series.
In OpenBDLM, a dependence model between time series assigns regression coefficient for the observed hidden states associated with block component describing reversible behavior (periodic and autoregressive patterns).


\subsection{Neural Net experiments}
\begin{frame}{Experiments}
    \textbf{Preprocessing:} Scaling, shifting and linear interpolation\\
    \textbf{Features:} Coordinates of 80 points (4 strokes with 20 points each)\\
    \textbf{Learning:} MLP, 300 epochs, LR of 0.1, Momentum 0.1

\begin{table}[h]
    \begin{tabular}{lrl}
    \toprule
    Topology                & Error    & Training time \\ \midrule
    160:500:369             & 30.62 \% & \hphantom{0}9min 08s      \\
    160:500:500:369         & 27.73 \% & 11min 49s     \\
    160:500:500:500:369     & 34.79 \% & 14min 09s     \\
    160:500:500:500:500:369 & 33.61 \% & 14min 06s     \\
    \bottomrule
    \end{tabular}
\end{table}

\end{frame}

\begin{frame}[fragile]{Examples of confusable symbols}
\begin{table}[ht]
    \centering
    \begin{tabular}{lc|lc}
        \textbf{\LaTeX}& \textbf{Rendered}   & \textbf{\LaTeX}& \textbf{Rendered} \\\midrule
        \verb+\sum+    & $\sum$         & \verb+$\Sigma$+        & $\Sigma$\\
        \verb+\coprod+ & $\coprod$      & \verb+$\amalg$+        & $\amalg$\\
        \verb+\perp+   & $\perp$        & \verb+$\bot$+          & $\bot$\\
        \verb+\models+ & $\models$      & \verb+$\vDash$+        & $\vDash$\\
        \verb+\emptyset+ & $\emptyset$  & \verb+$\diameter$+     & $\diameter$\\
        ~              & ~              & \verb+$\o$+            & $\o$\\
        ~              & ~              & \verb+$\varnothing$+   & $\varnothing$\\
        \verb+\Delta+  & $\Delta$       & \verb+$\triangle$+     & $\triangle$\\
        \verb+\varepsilon+ & $\varepsilon$ & \verb+$\mathcal{E}$+ & $\mathcal{E}$\\
    \end{tabular}
\end{table}

When those confusions are not counted as errors, the current best system
has an classification error rate of $12.7 \%$ (otherwise $22.2 \%$).

\end{frame}


% 20YangMillsFields.tex

\subsection{20.1. Noether's Theorem for Internal Symmetries }

\begin{quote}
\emph{How do symmetries yield conservation laws?}
\end{quote}

$\phi$ $N$-tuple $\phi^a(t,\mathbf{x}) = \phi^a(x)$, local representation of a section of some vector bundle $E$,

\begin{tikzpicture}
  \matrix (m) [matrix of math nodes, row sep=2em, column sep=3em, minimum width=1em]
  {
    E  &   \\
    M &    \\ };
  \path[->]  (m-1-1) edge node [auto] {$\pi$} (m-2-1);
\end{tikzpicture}

%\begin{tikzpicture}
%  \matrix (m) [matrix of math nodes, row sep=2em, column sep=3em, minimum width=1em]
%  {
%    U_i \subset \mathbb{R}^{n+1} - 0 &  \\
%    V_i \subset \mathbb{R}P^n  & \mathbb{R}^n  \\ };
%  \path[-stealth]
%  (m-1-1) edge node [right] {$\varphi_i \pi$} (m-2-2)
%  edge node [left] { $\pi$} (m-2-1)
%  (m-2-1) edge node [below] {$\varphi$} (m-2-2);
%\end{tikzpicture}

In the case of a Dirac electorn, we have seen that $E$ is the bundle of complex 4-component Dirac spinors over a perhaps curved spacetime. If $E$ is not a trivial bundle (or if we insist on using curvilinear coordinates) we shall have to deal with the fact that $\partial_j \phi^a$ do not form a tensor.

\subsubsection{ 20.1a. The Tensorial Nature of Lagrange's Equations }

Let $M^{n+1}$ (pseudo-) Riemannian manifold, let $E$ vector bundle over $M$; for definiteness, let fiber be $\mathbb{R}^N$. \\
section of this bundle over $U \subset M$ is described by $N$ real-valued functions $\lbrace \phi^a_U \rbrace$, \\
\quad where $\phi_V = c_{VU}\phi_U$ and \\
\quad \quad $c_{VU}(x)$ is $N\times N$ transition matrix function, $c^a_{VUb}$.   \\

notation $\begin{gathered} \quad \\
  \lbrace \Phi^a \rbrace \\
  \lbrace \Phi^a_{\alpha} \rbrace \\
\Phi^a_{\alpha} = \tau_{\alpha \beta} \Phi_{\beta} \end{gathered}$ \\

Lagrangian $L_0(x, \phi, \phi_x) \equiv L_0(x,\Phi, \partial_j \Phi^a)$

\subsection{20.2. Weyl's Gauge Invariance Revisited}

\subsubsection{ 20.2a. The Dirac Lagrangian }

\subsubsection{ 20.2b. Weyl's Gauge Invariance Revisited}

\subsubsection{ 20.2c. The Electromagnetic Lagrangian }

Instead of considering a change of (spacetime) coordinates $x$, we shall look at a change of the \emph{field} (fiber) coordinate $\psi$, i.e. \emph{a gauge transformation}.

Since the phase of $\psi$ is not measurable, we \emph{should} be able to have invariance under a \emph{local} gauge transformation, where $\alpha = \alpha(x)$ varies with the spacetime point $x$!  \\
\quad Clearly the Dirac equation and Lagrangian are \emph{not} invariant under such a substitution because of the appearance of terms involving $d\alpha$.  \\
\quad It must be that \emph{there is some background field that is interacting with the electron}.  This background field will manifest itself through the appearance of the connection.

\subsection{ The Yang-Mills Nucleon }

\begin{quote}
  How did the groups $SU(2)$ and $SU(3)$ appear in particle physics?
\end{quote}

\subsubsection{ 20.3a. The Heisenberg Nucleon }

\subsubsection{ 20.3b. The Yang-Mills Nucleon }

\subsubsection{ 20.3c. A Remark on Terminology }

We have related the connection matrices $\omega$ to the gauge potentials $A$ by
\[
\omega = -i q A
\]
$q$ is called a generalized \textbf{charge}.

LaTeX_and_pdfs/the geometry of physics problems/20YangMillsFields.tex


%% ----------------------------------------------------------------
%% Chapter 2: Theoretical background
%% ----------------------------------------------------------------
%!TeX root = subfile
\label{chapter:theoretical_background}
\documentclass[../main.tex]{subfiles}
% ----------------------------------------------------------------
\begin{document}

\vspace{0.25cm}
This chapter comprises high-level theoretical background in incompressible fluid flow and its numerical solution.
The incompressible flow dynamics is first presented yielding the governing system of equations.
The numerical method providing an approximate solution of the equation system is also explained as implemented in our in-house code, ``Lotus''.
A finite-volume method is employed to spatially discretise the system domain.
The flux-limited quadratic upstream interpolation for convective kinematics (QUICK) scheme numerically approximates the convective term of the momentum equations, which also serves as an implicit model for the subgrid scale (SGS) structures of the flow.
A central-difference scheme is used for the viscous term.
A predictor-corrector scheme integrates the numerical solution in time.
The boundary data immersion method is applied to account for solid boundaries.
Finally, a multigrid method is employed to iteratively solve the pressure-Poisson equation and enforce the continuity condition in the velocity field.

\section{Governing equations of incompressible fluid flow}

Incompressible fluid flow is governed by the conservation of mass and momentum, respectively the continuity equation and the Navier--Stokes momentum equations
\begin{gather}
\nabla\cdot\vect{u}=0,\label{eq:div_u}\\
\pd{\vect{u}}{t}+\pars{\vect{u}\cdot\nabla}\vect{u}=-\nabla p+\nu\nabla^2\vect{u},\label{eq:n-s}
\end{gather}
where $\vect{u}\left(\vect{x}, t\right) = \left(u, v, w\right)$ is the velocity vector field, $p\left(\vect{x}, t\right)$ is the pressure field, $t$ is the time, and $\vect{x}=\left(x,y,z\right)$ is the spatial vector.
The coupling of pressure and velocity arises from an additional relationship obtained by taking the divergence of the momentum equations, namely the pressure-Poisson equation
\begin{gather}
\nabla\cdot\pars{\pd{\vect{u}}{t}+\pars{\vect{u}\cdot\nabla}\vect{u}=-\nabla p+\nu\nabla^2\vect{u}},\\
\nabla^2 p = \nabla\cdot\pars{\vect{h}-\pd{\vect{u}}{t}},\label{eq:ppe}
\end{gather}
where $\vect{h}$ is the force combining convective and viscous terms.

The system of equations is bounded by case-dependant initial and boundary conditions of the system variables.
Importantly, the boundary condition with solid domains is the velocity no-slip condition, i.e. $\vect{u}_b=0$, which yields the flow boundary layer.

The Reynolds number is the non-dimensional parameter describing the ratio between convective and viscous forces,
\begin{equation}
Re=\frac{\rho U L}{\mu},
\end{equation}
where $\rho$ is the fluid density (assumed constant for incompressible flows), $\mu$ is the dynamic fluid viscosity, and $L$ and $U$ are the characteristic length and velocity of the system, respectively.
The Reynolds number defines the scales of motion of the flow.
When the convective forces are much greater than the viscous forces, turbulence develops.
The definition of turbulence is not straight forward, but (loosely) it can be thought as the turning point where the fluid dynamics transitions from ordered to \textit{chaotic} as a result of the nonlinear convective term.
Still, physical laws revealing certain order within the turbulence dynamics have been found in the past.
In particular, it is known that 3-D systems present a constant rate of kinetic energy transfer within a certain range of scales, from large to small structures, a.k.a. direct energy cascade \citep{Richardson1922,Kolmogorov1941}.
Similarly, a constant rate is also found in 2-D systems although energy is inversely transfered from small to large scales, a.k.a. inverse energy cascade \citep{Kraichnan1967,Leith1968,Batchelor1969}.
Such different dynamics will be subject of investigation in the following chapters.

\section{Numerical methods}
\label{sec:lotus}

\subsection{Spatial discretisation}

The governing equations comprising \eref{eq:div_u}, \eref{eq:n-s}, and \eref{eq:ppe} are spatially discretised in a structured rectilinear grid using a finite-volume method.
This grid facilitates the implementation of the immersed boundary method accounting for solid boundary conditions, as described in \sref{sec:bdim}.
The flow variables, pressure and velocity, are staggered: the pressure scalar field is stored in the cell centre and the velocity vector field is defined at the cell faces, as displayed in \fref{fig:grid}.

\begin{figure}[t]
\centering
\includegraphics[width=0.4\linewidth]{chapter2/staggered_grid}
\caption{Staggered grid.
The control volume for the pressure is defined in blue.
The control volume for the $u$ velocity component is defined in green.}
\label{fig:grid}
\end{figure}

The convective term of the momentum equations is numerically approximated using a flux-limited QUICK scheme.
This scheme interpolates the quantity of interest at the control volume face through a weighted quadratic function fitted with one upstream and two downstream points \citep{Leonard1979}.
The spatial derivative is then approximated using the numerical fluxes given by the cell-face values as defined by the finite-volume approach.

\subsection{Implicit modelling}

As previously exposed, high-Reynolds flows need to be sufficiently discretised in space and time to fully resolve all scales of motion.
The spatial SGS need to be modelled when the grid is not fine enough.
In this sense, we employ an implicit LES (iLES) model, in which the dissipative effect of the SGS is accounted by the numerical dissipation intrinsic in the discretisation scheme of the convective term (the QUICK scheme in the present solver).

Importantly, the instantaneous kinetic energy $(E)$ dissipation rate $(\epsilon)$
\begin{equation}
\dd{E}{t}=-\epsilon
\end{equation}
needs to match the natural dissipation mechanism of the flow.
This balance can be used to compute the iLES effective Reynolds number (or effective kinematic viscosity, $\nu_e$), which can be found through the following evaluation \citep{Domaradzki2003,Aspden2008,Zhou2014}
\begin{equation}
\dd{}{t}\int_\Omega\frac{1}{2}|\vect{u}|^2\,\mathrm{d}\Omega=-2\nu\int_\Omega S_{ij}S_{ij}\,\mathrm{d}\Omega,\label{eq:iles}
\end{equation}
where $S_{ij}$ is the velocity rate-of-strain tensor.
Note that the RHS is the energy dissipation term for incompressible flow arising naturally in the energy transport equation (formally derived from a dot product of the Navier--Stokes momentum equations and the velocity vector field) since \citep[p. 17]{Doering1995}
\begin{equation}
\frac{1}{2}\int_\Omega||\nabla\vect{u}||^2\,\mathrm{d}\Omega=\frac{1}{2}\int_\Omega|\boldsymbol{\omega}|^2\,\mathrm{d}\Omega\equiv Z,
\end{equation}
where $\boldsymbol\omega=\nabla\times\vect{u}$ is the vorticity vector field, $Z$ is the enstrophy, and $||\cdot||$ denotes the tensor Frobenius norm.

Using \eref{eq:iles}, the iLES effective viscosity is computed as
\begin{equation}
\nu_e=\frac{\avg{\epsilon}_{\scaleto{\Omega}{5pt}}}{2\avg{S_{ij}S_{ij}}_{\scaleto{\Omega}{5pt}}},
\end{equation}
where $\avg{\cdot}_{\scaleto{\Omega}{5pt}}$ denotes a volume average.
\cite{Hendrickson2019} verified the present in-house solver by monitoring the grid-scaled effective viscosity $\nu_e\Delta^{-1}$ for the Taylor--Green vortex case.
It was shown that the QUICK scheme linearly scales the effective viscosity with $\Delta$.

\subsection{Temporal discretisation}

The temporal evolution of the system of equations (\eref{eq:div_u}, \eref{eq:n-s} and \eref{eq:ppe}) is discretised using Chorin's projection method \citep{Chorin1967,Chorin1968}.
In short, the Navier--Stokes operator is split in two parts
\begin{gather}
\frac{\vect{u}^*-\vect{u}^n}{\delta t}=\nu\nabla^2\vect{u}^n-\pars{\vect{u}^n\cdot\nabla}\vect{u}^n,\\
\frac{\vect{u}^{n+1}-\vect{u}^*}{\delta t}=-\nabla p^{n+1},
\end{gather}
where the superscript $(\cdot)^n$ refers to the time step level and the intermediate velocity field is noted with the superscript $(\cdot)^*$.
The computation of a non-solenoidal intermediate velocity field allows to decouple the velocity and pressure equations.
In this way, a solenoidal velocity field $\vect{u}^{n+1}$ can be obtained by enforcing the continuity condition into the $p^{n+1}$ pressure-Poisson equation.
Otherwise, using $p^{n}$ to compute $\vect{u}^{n+1}$ would not enforce the velocity field to be divergence-free at the next time step.

The projection method is implemented in a predictor-corrector algorithm.
Next, we note $\vect{h}(\vect{u})=\nu\nabla^2\vect{u}-\pars{\vect{u}\cdot\nabla}\vect{u}$, and $\vect{h}^n=\vect{h}(\vect{u}^n$).
The $(\cdot)^s$ superscript refers to a solenoidal field.
With this, the predictor-corrector algorithm is implemented in two steps as follows

\begin{align}
\mathrm{Pred}&\mathrm{ictor\,\,step:}\nonumber\\
&1.\qquad \vect{u}^* = \vect{u}^n+\vect{h}^n\delta t,\\
&2.\qquad {\delta t}\,\nabla^2p^*=\nabla\cdot\vect{u}^*,\label{eq:ppe1}\\
&3.\qquad \vect{u}^{*,s}=\vect{u}^*-\delta t\nabla p^*.
\nonumber\\
\nonumber\\
\mathrm{Corr}&\mathrm{ector\,\,step:}\nonumber\\
&4.\qquad \vect{u}^{*} = \vect{u}^n+\frac{1}{2}\pars{\vect{h}^n+\vect{h}^{*,s}}\delta t,\\
&5.\qquad {\delta t}\,\nabla^2p^{n+1}=\nabla\cdot\vect{u}^{*},\label{eq:ppe2}\\
&6.\qquad \vect{u}^{n+1}=\vect{u}^{*}-\delta t\nabla p^{n+1}.
\end{align}

Note that the divergence-free constraint for both $\vect{u}^n$ and $\vect{u}^{n+1}$ has been considered.
Also note that the forward Euler time stepping scheme is implemented in the predictor step to compute the intermediate velocity field $\vect{u}^{*}$, finally projected into a solenoidal field by the pressure-Poisson equation yielding $\vect{u}^{*,s}$.
With this, the trapezoidal quadrature can be employed in the corrector step to integrate the solution from time $n$ to $n+1$, as described in step 4.
The solution is again projected into a divergence-free field by solving the pressure-Poisson equation for $p^{n+1}$ (step 5) and correcting the velocity field with the new pressure field (step 6) yielding $\vect{u}^{n+1}$.

The advantage of this method is that it exploits the benefits of both explicit and implicit time-marching schemes: it combines the natural stability of implicit schemes with the low memory requirements of explicit schemes.
It can be shown that the predictor-corrector algorithm is second-order accurate in time.
The reader is referred to \cite{Ferziger2002} for further details.

The time discretisation method is bounded to the limitation of the time step size $(\delta t)$.
For this, the local Courant number $(u\,\delta t/\delta x)$ and Péclet number $(\nu\,\delta t/(\delta x)^2)$ are evaluated at every time step yielding an adaptive step size.
These dimensionless parameters quantify the characteristic convection time and characteristic diffusivity time of the flow, respectively.
A combination of both yields to a time step size limit (for  one-dimensional flow) of
\begin{equation}
\delta t<\left[\frac{2\nu}{\min\left[(\delta x)^2\right]}+\max\pars{\frac{u}{\delta x}}\right]^{-1}.
\end{equation}

\subsection{Solid boundaries} \label{sec:bdim}

The velocity no-slip condition at solid boundaries is implemented using the boundary data immersion method (BDIM) from \cite{Weymouth2011}.
Immersed boundary (IB) methods, such as BDIM, take into account the solid wall effect in a rectilinear non-conforming grid.
The Dirichlet condition on the velocity field is interpolated at the grid nodes from its actual position.
The interpolation method is what differs among IB methods.

A clear advantage of IB methods is the trivial grid-generation process, in contrast to the complicated meshing process regularly encountered for body-conforming grids.
Also in this regard, the body geometry is practically irrelevant for the grid generation process.
Other advantages include the simulation of moving bodies since the grid does not need to be updated at every step, as well as the straightforward implementation of numerical schemes.
On the other hand, accuracy near the solid boundary can be compromised depending on the effective resolution of the non-conforming grid.
Also, the implementation of the solid boundary condition is not as trivial as in body-conforming grids \citep{Mittal2005}.

The BDIM consists in mapping the fluid governing equation $(\mathcal{F})$ and the solid governing equation $(\mathcal{B})$ into a single meta-equation $(\mathcal{M})$ discretised in a non-conforming rectilinear staggered grid.
A convolution kernel $(K_\epsilon)$ provides a smooth transition between the mediums enforcing the velocity condition at the interface (see \fref{fig:bdim}) while extending the fluid subdomain $(\Omega_f)$ and solid subdomain $(\Omega_b)$ to the full single domain $(\Omega)$.
Imposing the no-slip condition on a static body, this method can be summarised as follows
\begin{align}
&\mathcal{F}(\vect{u},p)=\partial_t\vect{u}-\vect{h}+\nabla p=0,\\
&\mathcal{B}(\vect{u})=\vect{u}=0,\\
&\mathcal{M}(\vect{u},p)=\mathcal{F}(\vect{u},p)\pars{1-\delta_\epsilon}+\mathcal{B}\pars{\vect{u}}\delta_\epsilon=0,
\end{align}
where the convolution between kernel and governing equation has been approximated using (e.g)
\begin{gather}
\mathcal{B}_\epsilon\pars{\vect{x}}=\int_{\Omega_b}\mathcal{B}\pars{\vect{x}_b}K_\epsilon\pars{\vect{x},\vect{x}_b}\,\mathrm{d}\vect{x}_b\approx \mathcal{B}\pars{\vect{x}}\int_{\Omega_b}K_\epsilon\pars{\vect{x},\vect{x}_b}\,\mathrm{d}\vect{x}_b,\\
\mathcal{B}_\epsilon\pars{\vect{x}}\approx\mathcal{B}\pars{\vect{x}}\delta_\epsilon,
\end{gather}
where $\delta_\epsilon$ is the integrated kernel over the subdomain which can take the approximated form
\begin{equation}
\delta_\epsilon(d)=
	\begin{cases}
		\frac{1}{2}[1+\sin(\frac{\pi}{2}\frac{d}{\epsilon})] & \mathrm{for} \left|d\right|<\epsilon\\
		1 & \mathrm{for}\,\,d<-\epsilon\\
		0 & \mathrm{else}
	\end{cases}
\end{equation}
where $d$ is a signed-distance function from a point $\vect{x}$ to the solid interface. This approximation results into a first-order accurate scheme, although high-order terms can be considered to improve the order of accuracy \citep{Maertens2015}.

The BDIM has been tested in multiple applications and the reader is referred to \cite{Maertens2015} for an extended mathematical description of the method, and to \cite{Schulmeister2017} for further validation on bluff body cases.

\begin{figure}[t]
\centering
\includegraphics[width=0.65\linewidth]{chapter2/bdim}
\caption{BDIM sketch adapted from \cite{Maertens2015}.
A convolution kernel with radius $\epsilon$ smooths the interface between solid $(\Omega_b)$ and fluid $(\Omega_f)$ subdomains.}
\label{fig:bdim}
\end{figure}

\subsection{Pressure solver}

A multigrid method is used to solve the pressure-Poisson equation as discretised in the pressure-corrector algorithm (\eref{eq:ppe1} and \eref{eq:ppe2}).
Algebraically, the pressure-Poisson equation can be written as a linear system of equations
\begin{equation}
\matr{A}\vect{x}=\vect{b},
\end{equation}
where $\matr{A}$ is a sparse matrix containing the discretised Laplacian operator, $\vect{x}$ is the pressure field arranged in a column vector, and $\vect{b}$ is the column vector of the intermediate velocity field divergence.

Contrary to direct methods, a multigrid solver is an iterative method in the sense that that a guessed solution $\vect{x}^n$ (at the iteration $n$) is evaluated yielding a residual
\begin{equation}
\vect{r}^n=\matr{A}\vect{x}^n-\vect{b},
\end{equation}
and an error
\begin{equation}
\boldsymbol\epsilon^n=\vect{x}-\vect{x}^n,
\end{equation}
which are related by
\begin{equation}
\matr{A}\boldsymbol\epsilon^n=\vect{r}^n.
\end{equation}
The objective is to iteratively minimise $\vect{r}^n$ so that $\vect{x}^n$ converges to $\vect{x}$.

In multigrid methods, iterations are performed from fine to coarse grids, transferring the residual across grid levels so that iterations become cheaper as the grid is coarsened.
Hence, multigrid methods yield a speed-up of the overall convergence process.
Iterations can be carried with any iterative method, e.g. Gauss--Seidel, Jacobi, conjugate gradient, etc.
In our solver, a single Jacobi iteration to smooth the solution is performed before downsampling the residual to a coarser level.
Downsampling (in one-dimensional form) is performed from
\begin{equation}
\frac{1}{(\delta x)^2}\pars{\epsilon_{i-1}^n-2\epsilon_{i}^n+\epsilon_{i+1}^n}=r_i^n,
\end{equation}
where the subscript $(\cdot)_i$ denotes the fine grid cell index, to
\begin{equation}
\frac{1}{(\delta X)^2}\pars{\epsilon_{I-1}^n-2\epsilon_{I}^n+\epsilon_{I+1}^n}=r_I^n,
\end{equation}
where the subscript $(\cdot)_I$ denotes the coarse grid cell index.
The relationship between both grids might be $\delta X = 2\delta x$, hence the $I$ (coarse grid) control volume is defined as the $i$ (fine grid) control volume plus half of its neighbour control volumes ($i+1$ and $i-1$) \citep{Ferziger2002}.

The residual can be gradually downsampled to an arbitrary coarse grid using linear interpolation for each downsampling step.
Similarly, the residual is upsampled from the coarsest grid to the original fine grid while iterating in the mid level grids to correct the fine grid solution.
We employ a conjugate gradient method after each upsampling step to update the solution.
This downsampling and upsampling process is known as a V-cycle.
Multiple V-cycles can be performed in a single time step to solve the pressure-Poisson equation.
The iterative method is stopped once the convergence tolerance is reached.
The following convergence tolerance criteria is defined in a grid with cell index $i$
\begin{gather}
\frac{1}{\Omega}\sum_i\Big|\oint \vect{u}\cdot\vect{\hat{n}}\,\mathrm{d}S\Big|<10^{-6}\\
\max_i\Big|\oint \vect{u}\cdot\vect{\hat{n}}\,\mathrm{d}S\Big|<10^{-5} \,\,\, \forall i \in \Omega ,
\end{gather}
establishing the allowed average velocity divergence error in $\Omega$ as well as its maximum local error.
% ----------------------------------------------------------------
\end{document}


\documentclass[10pt]{article}
\oddsidemargin = 0.2in
\topmargin = -0.5in
\textwidth 6in
\textheight 8.5in

\usepackage{graphicx,bm,hyperref,amssymb,amsmath,amsthm}

% -------------------------------------- macros --------------------------
% general ...
\newcommand{\bi}{\begin{itemize}}
\newcommand{\ei}{\end{itemize}}
\newcommand{\ben}{\begin{enumerate}}
\newcommand{\een}{\end{enumerate}}
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bea}{\begin{eqnarray}}
\newcommand{\eea}{\end{eqnarray}}
\newcommand{\ba}{\begin{align}}
\newcommand{\ea}{\end{align}}
\newcommand{\bse}{\begin{subequations}}
\newcommand{\ese}{\end{subequations}}
\newcommand{\bc}{\begin{center}}
\newcommand{\ec}{\end{center}}
\newcommand{\bfi}{\begin{figure}}
\newcommand{\efi}{\end{figure}}
\newcommand{\ca}[2]{\caption{#1 \label{#2}}}
\newcommand{\ig}[2]{\includegraphics[#1]{#2}}
\newcommand{\bmp}[1]{\begin{minipage}{#1}}
\newcommand{\emp}{\end{minipage}}
\newcommand{\pig}[2]{\bmp{#1}\includegraphics[width=#1]{#2}\emp} % mp-fig, nogap
\newcommand{\bp}{\begin{proof}}
\newcommand{\ep}{\end{proof}}
\newcommand{\ie}{{\it i.e.\ }}
\newcommand{\eg}{{\it e.g.\ }}
\newcommand{\etal}{{\it et al.\ }}
\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\pdc}[3]{\left. \frac{\partial #1}{\partial #2}\right|_{#3}}
\newcommand{\infint}{\int_{-\infty}^{\infty} \!\!}      % infinite integral
\newcommand{\tbox}[1]{{\mbox{\tiny #1}}}
\newcommand{\mbf}[1]{{\mathbf #1}}
\newcommand{\half}{\mbox{\small $\frac{1}{2}$}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\RR}{\mathbb{R}^2}
\newcommand{\ve}[4]{\left[\begin{array}{r}#1\\#2\\#3\\#4\end{array}\right]}  % 4-col-vec
\newcommand{\vt}[2]{\left[\begin{array}{r}#1\\#2\end{array}\right]} % 2-col-vec
\newcommand{\bigO}{{\mathcal O}}
\newcommand{\qqquad}{\qquad\qquad}
\newcommand{\qqqquad}{\qqquad\qqquad}
\DeclareMathOperator{\Span}{Span}
\DeclareMathOperator{\im}{Im}
\DeclareMathOperator{\re}{Re}
\DeclareMathOperator{\vol}{vol}
\newtheorem{thm}{Theorem}
\newtheorem{cnj}[thm]{Conjecture}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{pro}[thm]{Proposition}
\newtheorem{rmk}[thm]{Remark}
% this work...
\newcommand{\pO}{{\partial\Omega}}
\newcommand{\LpO}{\Delta_\pO}
\newcommand{\eps}{\epsilon}
\newcommand{\dn}{\partial_n}

\begin{document}

\title{Asymptotic expansion of a coupled surface-bulk diffusion problem in
  the reciprocal of the bulk diffusivity}

\author{Alex H. Barnett}
\date{\today}
\maketitle

\begin{abstract}
  In the spherical cell polarization model of Diegmiller et al (2018),
  the bulk diffusivity $D_C$ is taken as infinite.
  In fact $D_C$ is large but finite, being $1/\eps \sim 10^2$ times
  larger than the surface diffusivity.
  A full numerical solution of the coupled bulk and surface diffusion equations
  in a general cell geometry---either by finite difference or time-domain
  boundary integral methods---%
  would be daunting due to issues of discretization and possible small time steps.
  Here we apply the classical method of {\em singular perturbation} in powers of $\eps \ll 1$.
  The biologically relevant outer layer solution to a given order
  involves only bulk Poisson solves, so might make a more attractive numerical scheme.
\end{abstract}

\section{Introduction}

Let $\Omega \subset \R^3$ be a smooth bounded domain
representing a cell, with boundary $\pO$.
In \cite{diegmiller18} a cell polarization model is presented
with bulk concentration $C(x,t)$ diffusing in $\Omega$ with
diffusivity $D_C$,
coupled to a surface concentration $B(x,t)$ obeying a nonlinear
reaction-diffusion equation on $\pO$ with much lower diffusivity.
They consider the special case $\Omega$ a ball; we consider a general shape.
Non-dimensionalizing their model with length units of order the diameter,
and time units such that the surface diffusion is unity,
one gets the IBVP
\bea
\dot{B} - \LpO B   &=&  f(B,C)  \qquad \mbox{ on } \pO \times (0,\infty)
\label{surfpde}
\\
\eps \dot{C} - \Delta C   &=& 0   \qqquad \mbox{ in } \Omega \times (0,\infty)
\label{pde}
\\
\dn C  &=& -\eps f(B,C) \qquad \mbox{ on } \pO \times (0,\infty)
\label{fick}
\\
B(x,0) &=& B_i(x)  \qqquad x\in\pO
\label{Bi}
\\
C(x,0) &=& C_i(x)  \qqquad x\in\Omega ~,
\label{Ci}
\eea
where a dot indicates $\partial_t$, and $\dn = \mbf{n}\cdot\nabla$
where $\mbf{n}$ is the unit surface normal facing out of $\Omega$.
The given initial data are $B_i$ and $C_i$.
Here $\eps \ll 1$ is interpreted as $D_B/D_C$ (the ratio of surface
to bulk diffusivities), and in \cite{diegmiller18} is quoted to be about
$0.003$.
Fick's law relating Neumann boundary data to net flux is \eqref{fick}.
This flux is controlled by $f(B,C)$, a fixed function of two variables,
giving the local net flux from bulk to surface at a point on $\pO$, in terms of the local surface concentration $B$ and bulk concentration $C$ at that point.
It is generally nonlinear, the example from \cite{diegmiller18} being
$$
f(B,C) = (\beta + \frac{B^\nu}{B^\nu + \Gamma^\nu})C - k_d B~,
$$
where the two terms are binding and unbinding rates,
for constants $\beta$, $\Gamma$, and $k_d$. We will leave $f$ arbitrary.

The total amount of chemical (bulk plus surface) is conserved as follows.
%as follows \cite{diegmiller18}.
\begin{pro}[Conservation law]
  For any $\eps>0$,
  any solution of the above IBVP obeys
  \be
\int_\pO B(\cdot,t) + \int_\Omega C(\cdot,t) \; = \; A ~,  \qquad t>0~,
\label{cons}
\ee
with constant $A:=\int_\pO B_i + \int_\Omega C_i$.
\label{p:cons}
\end{pro}
\begin{proof}
Via the bulk and surface divergence theorems and the PDEs,
$$
\eps \int_\Omega \dot{C} = \int_\Omega \Delta C = \int_\pO \dn C =  -\eps
\int_\pO f(B,C) = -\eps \int_\pO (\dot{B}-\LpO B) = -\eps \int_\pO \dot{B}~,
$$
then one cancels $\eps$.
\end{proof}

% SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
\section{Singular perturbation and expansions in $\eps$}

For small $\eps$ the above IBVP is a singularly-perturbed problem in time,
so it is standard to split its analysis into initial layer
and outer layer solutions
\cite[Sec.~3.4]{logan} \cite[Sec.~10.2]{linsegel}
(note we reverse their convention of capital letters for inner and small
letters for outer).
We will see that the former is a relaxation phase of $C$ where $B$ is be essentially constant,
while in the latter $B$ will also change and $C$ stays nearly constant as a function of space.
Note that only the outer layer solution, to zeroth order in $\eps$, is
considered in \cite{diegmiller18}.

% iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
\subsection{Initial layer solution at zeroth and first order}

Rewriting using the rescaled time $\bar{t}:=t/\eps$, the IBVP
becomes, using small letters for the inner solution,
\bea
\dot{b} - \eps\LpO b   &=&  \eps f(b,c)  \qquad \mbox{ on } \pO \times (0,\infty)
\label{surfpdel}
\\
\dot{c} - \Delta c   &=& 0   \qqquad \mbox{ in } \Omega \times (0,\infty)
\label{pdel}
\\
\dn c  &=& -\eps f(b,c) \qquad \mbox{ on } \pO \times (0,\infty)
\eea
with IC \eqref{Bi}--\eqref{Ci} as before.

One can then expand the solution as $b = b_0 + \eps b_1 + \eps^2 b_2 + \dots$,
etc, and match powers of $\eps$.

At zeroth order \eqref{surfpdel} becomes $\dot{b_0}=0$.
And \eqref{pdel} with homogeneous Neumann BCs $\dn c_0 = 0$ means that
the zeroth order inner layer solution is analytic:
\be
b_0(x,\bar{t}) = B_i(x)~,
\quad x\in\pO, \; \bar{t}>0~,
\qqquad
c_0(x,\bar{t}) = \bar{C}_i + \sum_{j=1}^\infty \alpha_j e^{-\lambda_j \bar{t}} \psi_j(x) ~,
 \quad x\in\Omega, \; \bar{t}>0
\label{BCl0}
 \ee
where $\bar{C}_i := (\vol\Omega)^{-1} \int_\Omega C_i$ is the average of the
initial data,
and $(\lambda_j, \psi_j)$ are the non-trivial Neumann Laplace eigenpairs
of $\Omega$, ordered such that $0<\lambda_1\le\lambda_2\le\dots$.
The coefficients are given by the Euler--Fourier formula
$\alpha_j = \langle \psi_j,C_i\rangle_{L^2(\Omega)}$, assuming
$\|\psi_j\|=1$ $\forall j$.
Note that at this order, $b_0$ is constant, whereas $c_0$ equilibrates on
a slowest $\bar{t}$ timescale of $1/\lambda_1$, which (unless $\Omega$
has peculiar features such as narrow necks) is $\bigO(1)$.
This relaxation time for $C$ will thus be $\bigO(\eps)$
back in the original variable $t$.

At first order, we get a linear IBVP (recalling time-derivatives
are with respect to inner time $\bar{t}$),
\bea
\dot{b_1}  &=& \LpO c_0 + f(b_0,c_0)  \qquad \mbox{ on } \pO \times (0,\infty)
\\
\dot{c_1} - \Delta c_1   &=& 0   \qqqquad \mbox{ in } \Omega \times (0,\infty)
\\
\dn c_1  &=& -f(b_0,c_0) \qquad \mbox{ on } \pO \times (0,\infty)
\\
b_1(x,0) &=& 0  \qqquad x\in\pO
\label{Bi1}
\\
c_1(x,0) &=& 0  \qqquad x\in\Omega ~,
\label{Ci1}
\eea
where $b_0$ and $c_0$ are given by \eqref{BCl0}.
The solution is pointwise linear growth of $b_1$, and, independently,
the linear heat equation for $c_1$ with prescribed
Neumann boundary driving.
The nonlinear nature of $f$ has not yet kicked in at these short timescales.

A numerical solution for $c_1$ could either be done by timestepping
Duhamel ODEs for each above eigenmode, or via an immersed interface finite-difference
solver or time-domain boundary integral solver.
We are unsure of the biological relevance of this inner solution,
especially for the very rapid relaxation times that a spatially-complicated $C_i$ would bring.
%since $C$ is in practice likely to be equilibrated.
Hence we move to the outer solution.

% ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
\subsection{Outer layer at zeroth order and uniform approximation}

We return to the original time variable $t$,
and call the zeroth order solution $B_0$ and $C_0$.
Taking $\eps\to 0^+$ replaces \eqref{pde}--\eqref{fick}
by a static homogenous Neumann Laplace BVP at each time $t$,
so that
\bea
\dot{B_0} - \LpO B_0   &=&  f(B_0,C_0)  \qquad \mbox{ on } \pO \times (0,\infty)
\label{surfpde0}
\\
\Delta C_0   &=& 0   \qqquad \mbox{ in } \Omega \times (0,\infty)
\label{pde0}
\\
\dn C_0  &=& 0 \qqquad \mbox{ on } \pO \times (0,\infty)
\label{fick0}
\eea
thus $C_0$ is spatially constant at each time $t$.
However setting $\eps=0$ does {\em not} tell you how this
constant changes with $t$, since there is no PDE for $C$ involving time!
For this, curiously, Prop.~\ref{p:cons} (a result for $\eps>0$) is also needed,
giving the spatially-constant
\be
C_0(x,t) = \frac{1}{\vol\Omega}\biggl[ A_0 - \int_\pO B_0(\cdot,t) \biggr]
~, \qquad x\in\Omega
\label{C0}
\ee
where $A_0$ is some fixed total amount of chemical.
Substituting into \eqref{surfpde0} leaves a self-contained surface
PDE for $B_0$ alone,
\be
\dot{B_0} - \LpO B_0 =f \biggl( B_0 , \frac{1}{\vol\Omega} \biggl[ A_0 - \int_\pO B_0(\cdot,t) \biggr]
\biggr)
\label{B0only}
\ee
which is \cite[Eq.~(7)]{diegmiller18} and assumed throughout that paper
(note they use the symbol ``$C_0$'' to denote our $\frac{A_0}{\vol\Omega}$).

As is standard for outer layer solutions,
\eqref{surfpde0}--\eqref{fick0} cannot match arbitrary ICs:
the initial $C_0$ must be constant in space.
Instead the outer ICs (for $t\to 0^+$) are found by matching
to the inner layer (for $\bar{t}\to\infty$),
giving,
somewhat predictably,
$C_0(x,0)=\bar{C}_i$ for $x\in\Omega$, and
$B_0(x,0)=B_i(x)$ for $x\in\pO$.
As expected, $A_0 = \int_\Omega C_i + \int_\pO B_i$ is the total amount
of initial chemical.
The lowest-order uniform asymptotic expansion is then given by adding
inner and outer solutions and subtracting their common limit,
giving
\be
B^{(u)}(x,t) = B_0(x,t), \quad x\in\pO,\;t>0,
\qquad
C^{(u)}(x,t) = C_0(x,t) + \sum_{j=1}^\infty \alpha_j e^{-\lambda_j t/\eps} \psi_j(x),
\quad x\in\Omega, \; t>0.
\label{unif0}
\ee
This has $\bigO(\eps)$ error uniformly in time, formally justifying
the approximation in \cite{diegmiller18}.

\subsection{First order correction to outer layer solution}

Gathering terms in $\eps$, the PDEs and BC for the first order outer correction are
\bea
\dot{B_1} - f_B(B_0,C_0) B_1 - \LpO B_1
&=&  f_C(B_0,C_0) C_1  \qquad \mbox{ on } \pO \times (0,\infty)
\label{surfpde1}
\\
- \Delta C_1   &=& -\dot{C_0}   \qquad\qqquad \mbox{ in } \Omega \times (0,\infty)
\label{pde1}
\\
\dn C_1  &=& -f(B_0,C_0) \qquad \mbox{ on } \pO \times (0,\infty)
\label{fick1}
\eea
Here $f_B$ and $f_C$ are the partials of the fixed function $f$.
The form is a linear surface reaction-diffusion equation for $B_1$,
coupled to a family of static Neumann Poisson BVPs for $C_1$ at each $t>0$.
We leave the ICs open, to be found by matched asymptotics later.

Consider the static Poisson BVP \eqref{pde1}--\eqref{fick1}.
Its volume forcing $-\dot{C_0}$ is constant in space, by \eqref{C0}.
This constant is found by using \eqref{C0},
the surface divergence theorem, then
\eqref{surfpde0},
\be
-(\vol\Omega)\dot{C_0}(x,t) = \int_\pO \dot{B_0}(\cdot, t) =
\int_\pO [\dot{B_0}(\cdot, t) - \LpO B_0(\cdot,t) ]=
\int_\pO f(B_0(\cdot,t),C_0(\cdot,t))~, \quad x\in\Omega.
\label{C0d}
\ee
For a solution to the BVP to exist one must have (by the divergence theorem)
the total volume forcing matching the total outgoing flux,
i.e.
$$
-\int_\Omega \dot{C_0}(\cdot,t) = -\int_\pO \dn C_1(\cdot,t)~,  \quad \forall t>0~.
$$
Yet this follows since both sides are equal to
$\int_\pO f(B_0(\cdot,t),C_0(\cdot,t))$, by \eqref{C0d} and
\eqref{fick1} respectively.
Thus the BVP is {\em consistent} at each $t>0$.
It also has a nullspace of constant functions, so which solution
is selected at each $t>0$ ?
As with zeroth order, it is not contained in the PDE at this order,
so it seems we have to bring in
Prop.~\ref{p:cons} again, giving
\be
\int_\Omega C_1(\cdot,t) = -\int_\pO B_1(\cdot,t)~.
\label{C1}
\ee
Suppose that, at a given $t$,
a Poisson solution to \eqref{pde1}--\eqref{fick1} has been found,
$\tilde{C}_1(x,t)$.
Then, writing $C_1 = \tilde{C}_1 + \alpha$,
by \eqref{C1} one gets, in terms of known quantities at the current $t$,
$$
\alpha = -\frac{1}{\vol\Omega} \biggl[
  \int_\Omega \tilde{C}_1 + \int_\pO B_1
  \biggr]
$$
and then one substitutes this into \eqref{surfpde1} to give
the right-hand side for the surface PDE to timestep,
$$
\dot{B_1} - f_B(B_0,C_0) B_1 - \LpO B_1
=  f_C(B_0,C_0) (\tilde{C}_1 + \alpha)
~.
$$
Together, the last two equations (which could be combined by eliminating $\alpha$)
comprise the first-order equivalent of \eqref{B0only}.

A numerical solution of the Poisson BVP at this order is
quite easy, since a quadratic particular solution can be written down
(due to the spatially-constant forcing), then the boundary Neumann Laplace
problem solved via a 2nd-kind BIE.
A numerical scheme for evolving $B_1$ alongside $B_0$,
and $C_1$ alongside $C_0$, is thus clear,
at the effort of doubling the surface variables, and a Laplace Neumann
BVP solve per timestep.

%The solution $b=b_0+\eps b_1$ and $c=c_0+\eps c_1$ is already $\bigO(\eps^2)
%\sim 10^{-5}$
%accurate, so there is little point in higher-order solutions.

\section{Conclusions}

Using an asymptotic expansion in $\eps$ (essentially the reciprocal bulk diffusivity),
we wrote an approximate solution to the nonlinear coupled
interior-boundary cell diffusion IBVP that is uniformly accurate
to $\bigO(\eps)$, using zeroth-order inner and outer solutions.
This formally justifies the quasistatic bulk
approximation in \cite{diegmiller18}.
The inner layer is biologically irrelevant.
We also write the first-order outer solution.
The outer solution (at each order) has a curious extra condition on the change in average value due to the Neumann boundary condition for the coupling.

Numerically, a scheme for the outer solution
is to solve the zeroth order (i.e. solve for $B_0$ and $C_0$),
then first order (i.e. solve for $B_1$ and $C_1$, which could be
done at the same time as zeroth order, at the cost of one Laplace BVP
solve per timestep),
then add: $B_0+\eps B_1$ and $C_0 + \eps C_1$ is an outer solution
with error $\bigO(\eps^2)$.

However, we believe a cleaner and higher-order numerical scheme could be found;
see other notes.
This note remains mostly a theoretical foundation.

Future directions:
\bi
\item Matched asymptotics including all $\bigO(\eps)$ terms,
  to give an approximate solution with uniform error $\bigO(\eps^2)$.
  This will involve integrals over $f(b_0,c_0)$ with $b_0$ const in $\bar{t}$,
  but $c_0$ sweeping through prescribed values.
  It is not simple.
  It is unclear how $c_1$ matches to $C_1$.
\item Find a numerical method that doesn't require solving the
  zeroth- and then first-order correction sequentially.
  Explore 2nd-kind Volterra time-domain BIE here, although the
  $\eps$-expansion of heat potentials is proving to be a mess.
\ei

% BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
\bibliographystyle{abbrv}
\bibliography{localrefs}
\end{document}


\documentclass{article}

\usepackage[preprint]{./template/neurips_2020}

\usepackage[utf8]{inputenc} % allow utf-8 input
\usepackage[T1]{fontenc}    % use 8-bit T1 fonts
\usepackage{hyperref}       % hyperlinks
\usepackage{url}            % simple URL typesetting
\usepackage{booktabs}       % professional-quality tables
\usepackage{amsfonts}       % blackboard math symbols
\usepackage{nicefrac}       % compact symbols for 1/2, etc.
\usepackage{microtype}      % microtypography
\usepackage{amssymb}
\usepackage{physics}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{esvect}
\usepackage{tikz}
\usetikzlibrary{quantikz}

\title{Chapter 4: Quantum Circuits}

\author{
  John Martinez \\
  \texttt{john.r.martinez14@gmail.com} \\
}

\begin{document}
\maketitle

% \subsection{}
% \textbf{Solution}
% $\blacksquare$

\section{Quantum Circuits}

% 5.1 ------------------------------------------------------------------------
\subsection{Exercise}
Give a direct proof that

\begin{center}
  $\ket{j} \rightarrow
  \frac{1}{\sqrt{N}}\displaystyle\sum_{k=0}^{N-1}e^{2\pi i j k /N}\ket{k}$
\end{center}

is unitary.

\textbf{Solution}

$\blacksquare$

\end{document}


% This is part of the TFTB Reference Manual.
% Copyright (C) 1996 CNRS (France) and Rice University (US).
% See the file refguide.tex for copying conditions.

\markright{friedman}
\section*{\hspace*{-1.6cm} friedman}

\vspace*{-.4cm}
\hspace*{-1.6cm}\rule[0in]{16.5cm}{.02cm}
\vspace*{.2cm}

{\bf \large \sf Purpose}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
Instantaneous frequency density.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Synopsis}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
\begin{verbatim}
tifd = friedman(tfr,hat)
tifd = friedman(tfr,hat,t)
tifd = friedman(tfr,hat,t,method)
tifd = friedman(tfr,hat,t,method,trace)
\end{verbatim}
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Description}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
        {\ty friedman} computes the time-instantaneous frequency density
        (defined by Friedman [1]) of a reassigned time-frequency
        representation.\\

\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}
Name & Description & Default value\\
\hline
        {\ty tfr}   & time-frequency representation, {\ty (N,M)} matrix\\
        {\ty hat}   & complex matrix of the reassignment vectors\\
        {\ty t }    & time instant(s)     & {\ty (1:M)}\\
        {\ty method}& chosen representation   & {\ty 'tfrrsp'}\\
        {\ty trace} & if nonzero, the progression of the algorithm is shown
                                        & {\ty 0}\\
 \hline {\ty tifd}  & time instantaneous-frequency density. When called without
                output arguments, {\ty friedman} runs {\ty tfrqview}\\

\hline
\end{tabular*}
\vspace*{.1cm}

Warning : {\ty tifd} is not an energy distribution, but an estimated
               probability distribution.

\end{minipage}
\vspace*{1cm}

{\bf \large \sf Example}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
Here is an example of such an estimated probability distribution operated
on the reassigned pseudo-Wigner-Ville distribution of a linear frequency
modulation :
\begin{verbatim}
         sig=fmlin(128,0.1,0.4);
         [tfr,rtfr,hat]=tfrrpwv(sig);
         friedman(tfr,hat,1:128,'tfrrpwv',1);
\end{verbatim}
The result is almost perfectly concentrated on a line in the time-frequency
plane.
\end{minipage}

\newpage

{\bf \large \sf See Also}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
\begin{verbatim}
ridges.
\end{verbatim}
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Reference}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
[1] D.H. Friedman, "Instantaneous Frequency vs Time : An
Interpretation of the Phase Structure of Speech", Proc. IEEE
ICASSP, pp. 29.10.1-4, Tampa, 1985.
\end{minipage}