Core Types¶
Fundamental data structures used throughout dynaris. These are the building blocks that filters, smoothers, and the DLM class operate on.
StateSpaceModel¶
The central model representation. Holds the four system matrices (F, G, V, W)
following West and Harrison (1997) notation. Returned by all component
functions and composed via +.
- class dynaris.core.state_space.StateSpaceModel(observation_matrix, system_matrix, obs_cov, evolution_cov, input_matrix=None)[source]¶
Bases:
objectLinear-Gaussian Dynamic Linear Model.
Following West & Harrison (1997) notation:
System equation: theta_t = G @ theta_{t-1} + omega_t, omega_t ~ N(0, W) Observation eq: Y_t = F’ @ theta_t + nu_t, nu_t ~ N(0, V)
- Parameters:
observation_matrix (Array)
system_matrix (Array)
obs_cov (Array)
evolution_cov (Array)
input_matrix (Array | None)
- observation_matrix¶
F, shape (obs_dim, state_dim).
- Type:
Array
- system_matrix¶
G, shape (state_dim, state_dim).
- Type:
Array
- obs_cov¶
V, shape (obs_dim, obs_dim).
- Type:
Array
- evolution_cov¶
W, shape (state_dim, state_dim).
- Type:
Array
- input_matrix¶
B, shape (state_dim, input_dim) or None.
- Type:
Array | None
- initial_state(mean=None, cov=None)[source]¶
Create a default initial GaussianState for this model.
- Parameters:
mean (Array | None) – Initial state mean (m_0). Defaults to zeros.
cov (Array | None) – Initial state covariance (C_0). Defaults to 1e6 * I (diffuse prior).
- Returns:
GaussianState with the specified or default initial conditions.
- Return type:
GaussianState¶
Represents a Gaussian belief about the state: a mean vector and covariance matrix. Used internally by the Kalman filter and smoother at each time step.
FilterResult¶
Container returned by the Kalman filter. Holds filtered state means, covariances, log-likelihood, and forecast errors for all time steps.
- class dynaris.core.results.FilterResult(filtered_states, filtered_covariances, predicted_states, predicted_covariances, log_likelihood, observations)[source]
Bases:
NamedTupleOutput of a forward filtering pass.
All array fields have a leading time dimension T (number of observations).
- Parameters:
- filtered_states
Filtered state means, shape (T, state_dim).
- Type:
- filtered_covariances
Filtered state covariances, shape (T, state_dim, state_dim).
- Type:
- predicted_states
One-step-ahead predicted means, shape (T, state_dim).
- Type:
- predicted_covariances
One-step-ahead predicted covariances, shape (T, state_dim, state_dim).
- Type:
- log_likelihood
Total log-likelihood scalar, shape ().
- Type:
- observations
The input observations, shape (T, obs_dim).
- Type:
- filtered_states: jax.Array
Alias for field number 0
- filtered_covariances: jax.Array
Alias for field number 1
- predicted_states: jax.Array
Alias for field number 2
- predicted_covariances: jax.Array
Alias for field number 3
- log_likelihood: jax.Array
Alias for field number 4
- observations: jax.Array
Alias for field number 5
SmootherResult¶
Container returned by the RTS smoother. Holds smoothed state means and covariances for all time steps.
- class dynaris.core.results.SmootherResult(smoothed_states, smoothed_covariances, filtered_states, filtered_covariances, predicted_states, predicted_covariances, log_likelihood, observations)[source]
Bases:
NamedTupleOutput of a backward smoothing pass.
Extends filter output with smoothed estimates.
- Parameters:
- smoothed_states
Smoothed state means, shape (T, state_dim).
- Type:
- smoothed_covariances
Smoothed state covariances, shape (T, state_dim, state_dim).
- Type:
- filtered_states
Filtered state means, shape (T, state_dim).
- Type:
- filtered_covariances
Filtered state covariances, shape (T, state_dim, state_dim).
- Type:
- predicted_states
One-step-ahead predicted means, shape (T, state_dim).
- Type:
- predicted_covariances
One-step-ahead predicted covariances, shape (T, state_dim, state_dim).
- Type:
- log_likelihood
Total log-likelihood scalar, shape ().
- Type:
- observations
The input observations, shape (T, obs_dim).
- Type:
- smoothed_states: jax.Array
Alias for field number 0
- smoothed_covariances: jax.Array
Alias for field number 1
- filtered_states: jax.Array
Alias for field number 2
- filtered_covariances: jax.Array
Alias for field number 3
- predicted_states: jax.Array
Alias for field number 4
- predicted_covariances: jax.Array
Alias for field number 5
- log_likelihood: jax.Array
Alias for field number 6
- observations: jax.Array
Alias for field number 7
Protocols¶
Interfaces that filter and smoother implementations must satisfy. Useful for type checking and extending dynaris with custom algorithms.
- class dynaris.core.protocols.FilterProtocol(*args, **kwargs)[source]¶
Interface that all filtering algorithms must implement.
- predict(state, model, u=None)[source]¶
Predict the next state (time update / prior).
- Parameters:
state (GaussianState) – Current filtered state belief.
model (StateSpaceModel) – The state-space model defining dynamics.
u (Array | None) – Optional control input vector, shape (input_dim,).
- Returns:
Predicted (prior) GaussianState for the next time step.
- Return type:
- update(predicted, observation, model)[source]¶
Incorporate an observation (measurement update / posterior).
- Parameters:
predicted (GaussianState) – Predicted state from the predict step.
observation (jax.Array) – Observation vector, shape (obs_dim,).
model (StateSpaceModel) – The state-space model defining the observation equation.
- Returns:
Filtered (posterior) GaussianState.
- Return type:
- scan(model, observations, initial_state=None, inputs=None)[source]¶
Run the full forward filtering pass over a sequence.
- Parameters:
model (StateSpaceModel) – The state-space model.
observations (Array) – Observation sequence, shape (T, obs_dim).
initial_state (GaussianState | None) – Initial state belief. If None, uses model defaults.
inputs (Array | None) – Optional control inputs, shape (T, input_dim).
- Returns:
FilterResult containing all filtered and predicted states.
- Return type:
FilterResult
- class dynaris.core.protocols.SmootherProtocol(*args, **kwargs)[source]¶
Interface for backward smoothing algorithms.
- smooth(model, filter_result)[source]¶
Run backward smoothing given forward filter results.
- Parameters:
model (StateSpaceModel) – The state-space model.
filter_result (FilterResult) – Output from a forward filtering pass.
- Returns:
SmootherResult with smoothed state estimates.
- Return type:
SmootherResult