kalman

class quantecon.kalman.Kalman(ss, x_hat=None, Sigma=None)[source]

Bases: object

Implements the Kalman filter for the Gaussian state space model

\[\begin{split}x_{t+1} = A x_t + C w_{t+1} \\ y_t = G x_t + H v_t\end{split}\]

Here \(x_t\) is the hidden state and \(y_t\) is the measurement. The shocks \(w_t\) and \(v_t\) are iid standard normals. Below we use the notation

\[Q := CC' R := HH'\]
Parameters:
ssinstance of LinearStateSpace

An instance of the quantecon.lss.LinearStateSpace class

x_hatscalar(float) or array_like(float), optional(default=None)

An n x 1 array representing the mean x_hat of the prior/predictive density. Set to zero if not supplied.

Sigmascalar(float) or array_like(float), optional(default=None)

An n x n array representing the covariance matrix Sigma of the prior/predictive density. Must be positive definite. Set to the identity if not supplied.

References

https://python.quantecon.org/kalman.html

Attributes:
Sigma, x_hatas above
Sigma_infinityarray_like or scalar(float)

The infinite limit of Sigma_t

K_infinityarray_like or scalar(float)

The stationary Kalman gain.

Methods

filtered_to_forecast()

Updates the moments of the time t filtering distribution to the moments of the predictive distribution, which becomes the time t+1 prior

prior_to_filtered(y)

Updates the moments (x_hat, Sigma) of the time t prior to the time t filtering distribution, using current measurement \(y_t\).

stationary_coefficients(j[, coeff_type])

Wold representation moving average or VAR coefficients for the steady state Kalman filter.

stationary_values([method])

Computes the limit of \(\Sigma_t\) as t goes to infinity by solving the associated Riccati equation.

update(y)

Updates x_hat and Sigma given k x 1 ndarray y.

whitener_lss()

This function takes the linear state space system that is an input to the Kalman class and it converts that system to the time-invariant whitener represenation given by

set_state

stationary_innovation_covar

property K_infinity
property Sigma_infinity
filtered_to_forecast()[source]

Updates the moments of the time t filtering distribution to the moments of the predictive distribution, which becomes the time t+1 prior

prior_to_filtered(y)[source]

Updates the moments (x_hat, Sigma) of the time t prior to the time t filtering distribution, using current measurement \(y_t\).

The updates are according to

\[\hat{x}^F = \hat{x} + \Sigma G' (G \Sigma G' + R)^{-1} (y - G \hat{x}) \Sigma^F = \Sigma - \Sigma G' (G \Sigma G' + R)^{-1} G \Sigma\]
Parameters:
yscalar or array_like(float)

The current measurement

set_state(x_hat, Sigma)[source]
stationary_coefficients(j, coeff_type='ma')[source]

Wold representation moving average or VAR coefficients for the steady state Kalman filter.

Parameters:
jint

The lag length

coeff_typestring, either ‘ma’ or ‘var’ (default=’ma’)

The type of coefficent sequence to compute. Either ‘ma’ for moving average or ‘var’ for VAR.

stationary_innovation_covar()[source]
stationary_values(method='doubling')[source]

Computes the limit of \(\Sigma_t\) as t goes to infinity by solving the associated Riccati equation. The outputs are stored in the attributes K_infinity and Sigma_infinity. Computation is via the doubling algorithm (default) or a QZ decomposition method (see the documentation in matrix_eqn.solve_discrete_riccati).

Parameters:
methodstr, optional(default=”doubling”)

Solution method used in solving the associated Riccati equation, str in {‘doubling’, ‘qz’}.

Returns:
Sigma_infinityarray_like or scalar(float)

The infinite limit of \(\Sigma_t\)

K_infinityarray_like or scalar(float)

The stationary Kalman gain.

update(y)[source]

Updates x_hat and Sigma given k x 1 ndarray y. The full update, from one period to the next

Parameters:
ynp.ndarray

A k x 1 ndarray y representing the current measurement

whitener_lss()[source]

This function takes the linear state space system that is an input to the Kalman class and it converts that system to the time-invariant whitener represenation given by

\[\tilde{x}_{t+1}^* = \tilde{A} \tilde{x} + \tilde{C} v a = \tilde{G} \tilde{x}\]

where

\[\tilde{x}_t = [x+{t}, \hat{x}_{t}, v_{t}]\]

and

\[\begin{split}\tilde{A} = \begin{bmatrix} A & 0 & 0 \\ KG & A-KG & KH \\ 0 & 0 & 0 \\ \end{bmatrix}\end{split}\]
\[\begin{split}\tilde{C} = \begin{bmatrix} C & 0 \\ 0 & 0 \\ 0 & I \\ \end{bmatrix}\end{split}\]
\[\begin{split}\tilde{G} = \begin{bmatrix} G & -G & H \\ \end{bmatrix}\end{split}\]

with \(A, C, G, H\) coming from the linear state space system that defines the Kalman instance

Returns:
whitened_lssLinearStateSpace

This is the linear state space system that represents the whitened system