KalmanFilter
Kalman Filter Wiki Page
You can refer to the Wikipedia page for derivations and the underlying process. The documentation only includes the user-facing interface.
dataclass storing the results of a Kalman Filter application.
Fields:
| Name | Type | Description |
|---|---|---|
| x_pred | np.ndarray |
State prediction before observing \(y_t\). |
| x_filt | np.ndarray |
State estimate after observing \(y_t\). |
| P_pred | np.ndarray |
Predicted state covariance \(P_{t\mid t-1}\) |
| P_filt | np.ndarray |
Filtered state covariance \(P_{t\mid t}\). |
| y_pred | np.ndarray |
Predicted observation. Shape (T, m) |
| innov | np.ndarray |
Innovations (measurement residuals). Shape (T, m). |
| S | np.ndarray |
Innovation covariance. Shape (T, m, m). |
| eps_hat | np.ndarray, optional |
Estimated shocks. |
| loglik | float, optional |
Total log-likelihood of the observed data under the filter. |
Static class containing methods necessary for filter application.
Methods:
KalmanFilter.run(
A: np.ndarray[float64 | complex128],
B: np.ndarray[float64 | complex128],
C: np.ndarray[float64 | complex128],
d: np.ndarray[float64 | complex128],
Q: np.ndarray[float64 | complex128],
R: np.ndarray[float64 | complex128],
y: np.ndarray[float64 | complex128],
x0: np.ndarray[float64] | None = None,
P0: np.ndarray[float64] | None = None,
return_shocks: bool = False,
symmetrize: bool = True,
jitter: float = 0.0,
) -> FilterResult
FilterResult object.
Inputs:
| Name | Description |
|---|---|
| A | State transition matrix. |
| B | Shock loading matrix. |
| C | Observation matrix. |
| d | Observation intercept. |
| Q | Shock covariance matrix. |
| R | Observation noise covariance matrix. |
| y | Observed data over time. |
| x0 (optional) | Initial state mean. Defaults to zero vector. |
| P0 (optional) | Initial state covariance. Defaults to large diagonal. |
| return_shocks | If True, compute and return estimated shocks. |
| symmetrize | Symmetrize the covariance matrices at each step if True |
| jitter | Jitter term added to \(S_t\) if Cholesky solution fails. |
Jitter
Though its default is 0.0, running the method with a small jitter is strongly recommended. Using 1e-8 (or similar) can prevent fallback to matrix inversion when Cholesky fails. (Inversion much slower in comparison)
Returns:
| Type | Description |
|---|---|
FilterResult |
dataclass containing results of the Kalman Filter run. |