Skip to content

Commit

Permalink
Merge pull request #202 from QuantEcon/whitener
Browse files Browse the repository at this point in the history
Whitener
  • Loading branch information
thomassargent30 committed Oct 15, 2015
2 parents 2c3b081 + cd5ea9f commit de7eed7
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions quantecon/kalman.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as np
from numpy import dot
from scipy.linalg import inv
from quantecon.lss import LinearStateSpace
from quantecon.matrix_eqn import solve_discrete_riccati


Expand Down Expand Up @@ -83,6 +84,70 @@ def __str__(self):
"""
return dedent(m.format(n=self.ss.n, k=self.ss.k))

def whitener_lss(self):
r"""
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
\tilde{A} = [A 0 0
KG A-KG KH
0 0 0]
\tilde{C} = [C 0
0 0
0 I]
\tilde{G} = [G -G H]
with A, C, G, H coming from the linear state space system
that defines the Kalman instance
Returns
-------
whitened_lss : LinearStateSpace
This is the linear state space system that represents
the whitened system
"""
# Check for steady state Sigma and K
if self.K_infinity is None:
Sig, K = self.stationary_values()
self.Sigma_infinity = Sig
self.K_infinity = K
else:
K = self.K_infinity

# Get the matrix sizes
n, k, m, l = self.ss.n, self.ss.k, self.ss.m, self.ss.l
A, C, G, H = self.ss.A, self.ss.C, self.ss.G, self.ss.H

Atil = np.vstack([np.hstack([A, np.zeros((n, n)), np.zeros((n, l))]),
np.hstack([dot(K, G), A-dot(K, G), dot(K, H)]),
np.zeros((l, 2*n + l))])

Ctil = np.vstack([np.hstack([C, np.zeros((n, l))]),
np.zeros((n, m+l)),
np.hstack([np.zeros((l, m)), np.eye(l)])])

Gtil = np.hstack([G, -G, H])

whitened_lss = LinearStateSpace(Atil, Ctil, Gtil)
self.whitened_lss = whitened_lss

return whitened_lss


def prior_to_filtered(self, y):
r"""
Updates the moments (x_hat, Sigma) of the time t prior to the
Expand Down

0 comments on commit de7eed7

Please sign in to comment.