Example gaussian models

# imports for this notebook only
import fastcore.test as fct

Locally constant model

The locally costant model is a very basic example of a gaussian state space model. It is a univariate model with the following dynamics:

\[ \begin{align*} X_{t + 1} &= X_t + \varepsilon_{t + 1} & & \varepsilon_{t + 1} \sim \mathcal N(0, \sigma^2_\varepsilon), \\ Y_t &= X_t + \eta_t && \eta_{t} \sim \mathcal N(0, \sigma^2_\eta). \end{align*} \]

In this model the states \(X_t\) perform a discrete time, univariate, random walk and are observed with noise \(\eta_t\).


source

lcm

 lcm (n:int, x0:jaxtyping.Float, s2_x0:jaxtyping.Float,
      s2_eps:jaxtyping.Float, s2_eta:jaxtyping.Float)
Type Details
n int number of time steps
x0 Float initial value
s2_x0 Float initial variance
s2_eps Float innovation variance
s2_eta Float observation noise variance
Returns GLSSM the locally constant model
n = 10
u, A, D, Sigma0, Sigma, v, B, Omega = lcm(n, 0.0, 1.0, 1.0, 1.0)

# assess that shapes are correct
fct.test_eq(u.shape, (n + 1, 1))
fct.test_eq(A.shape, (n, 1, 1))
fct.test_eq(D.shape, (n, 1, 1))
fct.test_eq(Sigma0.shape, (1, 1))
fct.test_eq(Sigma.shape, (n, 1, 1))
fct.test_eq(v.shape, (n + 1, 1))
fct.test_eq(B.shape, (n + 1, 1, 1))
fct.test_eq(Omega.shape, (n + 1, 1, 1))

Stationary AR(1) model

States form a stationary AR(1) process with stationary distribution \(\mathcal N(\mu, \tau^2)\), observed with noise \[ \begin{align*} \alpha &\in \left( -1, 1\right) \\ \sigma^2 &= (1 - \alpha^2)\tau^2\\ X_{t + 1} &= \mu + \alpha (X_t - \mu) + \varepsilon_{t + 1}\\ \varepsilon_t &\sim \mathcal N(0, \sigma^2)\\ Y_t &= X_t + \eta_t \\ \eta_t &\sim \mathcal N(0, \omega^2) \end{align*} \]


source

ar1

 ar1 (mu:jaxtyping.Float, tau2:jaxtyping.Float, alpha, omega2, n:int)
Type Details
mu Float stationary mean
tau2 Float stationary variance
alpha dampening factor
omega2 observation noise
n int number of time steps
Returns GLSSM

In the multivariate setting, the model reads

\[ \begin{align*} \alpha &\in \left( -1, 1\right) \\ \Sigma &= (1 - \alpha^2)\Tau\\ X_{t + 1} &= \mu + \alpha (X_t - \mu) + \varepsilon_{t + 1}\\ \varepsilon_t &\sim \mathcal N(0, \Sigma)\\ X_{0} &\sim \mathcal N(\mu, \Tau) \\ Y_t &= X_t + \eta_t \\ \eta_t &\sim \mathcal N(0, \Omega), \end{align*} \]

where now \(\Tau\) is the stationary covariance matrix.


source

mv_ar1

 mv_ar1 (mu:jaxtyping.Float[Array,'m'], Tau:jaxtyping.Float[Array,'mm'],
         alpha:jaxtyping.Float, omega2:jaxtyping.Float, n:int)
Type Details
mu Float[Array, ‘m’] stationary mean
Tau Float[Array, ‘m m’] stationary covariance
alpha Float dampening factor
omega2 Float observation noise
n int number of time steps
Returns GLSSM
import nbdev

nbdev.nbdev_export()