9
9
"""
10
10
from textwrap import dedent
11
11
import numpy as np
12
- from numpy import dot
13
12
from scipy .linalg import inv
14
13
from quantecon .lss import LinearStateSpace
15
14
from quantecon .matrix_eqn import solve_discrete_riccati
@@ -163,7 +162,9 @@ def whitener_lss(self):
163
162
A , C , G , H = self .ss .A , self .ss .C , self .ss .G , self .ss .H
164
163
165
164
Atil = np .vstack ([np .hstack ([A , np .zeros ((n , n )), np .zeros ((n , l ))]),
166
- np .hstack ([dot (K , G ), A - dot (K , G ), dot (K , H )]),
165
+ np .hstack ([np .dot (K , G ),
166
+ A - np .dot (K , G ),
167
+ np .dot (K , H )]),
167
168
np .zeros ((l , 2 * n + l ))])
168
169
169
170
Ctil = np .vstack ([np .hstack ([C , np .zeros ((n , l ))]),
@@ -204,11 +205,11 @@ def prior_to_filtered(self, y):
204
205
# === and then update === #
205
206
y = np .atleast_2d (y )
206
207
y .shape = self .ss .k , 1
207
- E = dot (self .Sigma , G .T )
208
- F = dot (dot (G , self .Sigma ), G .T ) + R
209
- M = dot (E , inv (F ))
210
- self .x_hat = self .x_hat + dot (M , (y - dot (G , self .x_hat )))
211
- self .Sigma = self .Sigma - dot (M , dot (G , self .Sigma ))
208
+ E = np . dot (self .Sigma , G .T )
209
+ F = np . dot (np . dot (G , self .Sigma ), G .T ) + R
210
+ M = np . dot (E , inv (F ))
211
+ self .x_hat = self .x_hat + np . dot (M , (y - np . dot (G , self .x_hat )))
212
+ self .Sigma = self .Sigma - np . dot (M , np . dot (G , self .Sigma ))
212
213
213
214
def filtered_to_forecast (self ):
214
215
"""
@@ -222,8 +223,8 @@ def filtered_to_forecast(self):
222
223
Q = np .dot (C , C .T )
223
224
224
225
# === and then update === #
225
- self .x_hat = dot (A , self .x_hat )
226
- self .Sigma = dot (A , dot (self .Sigma , A .T )) + Q
226
+ self .x_hat = np . dot (A , self .x_hat )
227
+ self .Sigma = np . dot (A , np . dot (self .Sigma , A .T )) + Q
227
228
228
229
def update (self , y ):
229
230
"""
@@ -268,9 +269,9 @@ def stationary_values(self, method='doubling'):
268
269
269
270
# === solve Riccati equation, obtain Kalman gain === #
270
271
Sigma_infinity = solve_discrete_riccati (A .T , G .T , Q , R , method = method )
271
- temp1 = dot (dot (A , Sigma_infinity ), G .T )
272
- temp2 = inv (dot (G , dot (Sigma_infinity , G .T )) + R )
273
- K_infinity = dot (temp1 , temp2 )
272
+ temp1 = np . dot (np . dot (A , Sigma_infinity ), G .T )
273
+ temp2 = inv (np . dot (G , np . dot (Sigma_infinity , G .T )) + R )
274
+ K_infinity = np . dot (temp1 , temp2 )
274
275
275
276
# == record as attributes and return == #
276
277
self ._Sigma_infinity , self ._K_infinity = Sigma_infinity , K_infinity
@@ -300,14 +301,14 @@ def stationary_coefficients(self, j, coeff_type='ma'):
300
301
P_mat = A
301
302
P = np .identity (self .ss .n ) # Create a copy
302
303
elif coeff_type == 'var' :
303
- coeffs .append (dot (G , K_infinity ))
304
- P_mat = A - dot (K_infinity , G )
304
+ coeffs .append (np . dot (G , K_infinity ))
305
+ P_mat = A - np . dot (K_infinity , G )
305
306
P = np .copy (P_mat ) # Create a copy
306
307
else :
307
308
raise ValueError ("Unknown coefficient type" )
308
309
while i <= j :
309
- coeffs .append (dot (dot (G , P ), K_infinity ))
310
- P = dot (P , P_mat )
310
+ coeffs .append (np . dot (np . dot (G , P ), K_infinity ))
311
+ P = np . dot (P , P_mat )
311
312
i += 1
312
313
return coeffs
313
314
@@ -317,4 +318,4 @@ def stationary_innovation_covar(self):
317
318
R = np .dot (H , H .T )
318
319
Sigma_infinity = self .Sigma_infinity
319
320
320
- return dot (G , dot (Sigma_infinity , G .T )) + R
321
+ return np . dot (G , np . dot (Sigma_infinity , G .T )) + R
0 commit comments