MarkovSwitchingSSM#
- class cultivars.state_space.regime_switching.MarkovSwitchingSSM(transition, intercepts, ar_params, variances, *, initial_prob=None)[source]#
A parameterized Markov-switching observation model over a latent chain.
The discrete counterpart of
_LinearGaussianStateSpace, and its peer in every structural respect: both hold a fully specified system, both filter and smooth data handed to them, and neither estimates anything. What differs is the state space. A linear-Gaussian model carries a continuous state and propagates a mean and a covariance; this one carries a state drawn from{0, ..., K-1}and propagates a probability vector.That difference is why the filter is Hamilton’s rather than Kalman’s, and why the likelihood is exact. Conditional on the observed lags, the density \(\Pr(y_t \mid S_t, y_{1:t-1})\) depends on \(S_t\) alone – the regime enters contemporaneously through the intercept, not through the lags – so the K-vector of filtered regime probabilities is a sufficient statistic and the sum over all \(K^T\) regime paths is carried out implicitly. Nothing here is approximated. That is a property of the intercept-switching form specifically: under Hamilton’s original mean-switching parameterization the density at \(t\) depends on \((S_t, \ldots, S_{t-p})\), and exact filtering then needs an augmented chain of \(K^{p+1}\) states.
Holding this as an object rather than as a pair of loose recursions is what lets a fitted model be re-applied: the same instance that produced an estimate can filter a different series, which the free functions in
cultivars.state_space.regime_switchingcannot do because they never see the data. They take a density matrix; this class owns the map that produces one.- Parameters:
transition (
ArrayLike) – Row-stochastic(K, K)matrix, \(P_{ij} = \Pr(S_t = j \mid S_{t-1} = i)\).intercepts (
ArrayLike) – Per-regime intercepts, shape(K,).ar_params (
ArrayLike) – Per-regime autoregressive coefficients, shape(K, p). A width of zero is a switching-mean model with no dynamics.variances (
ArrayLike) – Per-regime innovation variances, shape(K,), all strictly positive.initial_prob (
ArrayLike|None) – Distribution of \(S_1\), length \(K\). Defaults to the ergodic distribution oftransition.
- Raises:
DimensionError – If the blocks do not agree on \(K\), or a block has the wrong rank.
SpecificationError – If
transitionis not row-stochastic, a variance is not strictly positive, orinitial_probis not a distribution.NumericalError – If any block contains non-finite values.
See also
MarkovSwitchingSSM– the public name of this class.
Attributes#
Per-regime autoregressive coefficients, shape |
|
Distribution of the regime at the first modelled observation. |
|
Per-regime intercepts. |
|
Observed dimension; one, since the chain drives a scalar series. |
|
the number of regimes. |
|
The number of regimes, named as the chain rather than as a dimension. |
|
Autoregressive order of the per-regime observation equation. |
|
The row-stochastic regime transition matrix. |
|
Per-regime innovation variances. |
Methods#
|
Per-regime conditional means \(\mathbb{E}[y_t \mid S_t = j, \text{lags}]\). |
|
The |
Split a series into the modelled target and its lag block. |
|
|
Filter a series, returning regime probabilities and the likelihood. |
|
Run the Hamilton filter over an already-built density matrix. |
|
Gaussian log conditional densities, one column per regime. |
The exact log-likelihood of a series under this system. |
|
|
Filter, then smooth, returning full-sample regime probabilities. |
|
Run the Kim smoother over a completed forward pass. |