66import numpy as np
77from .lqcontrol import LQ
88from .quadsums import var_quadratic_sum
9- from numpy import dot , log , sqrt , identity , hstack , vstack , trace
109from scipy .linalg import solve , inv , det
1110from .matrix_eqn import solve_discrete_lyapunov
1211
@@ -108,10 +107,10 @@ def d_operator(self, P):
108107 """
109108 C , theta = self .C , self .theta
110109 I = np .identity (self .j )
111- S1 = dot (P , C )
112- S2 = dot (C .T , S1 )
110+ S1 = np . dot (P , C )
111+ S2 = np . dot (C .T , S1 )
113112
114- dP = P + dot (S1 , solve (theta * I - S2 , S1 .T ))
113+ dP = P + np . dot (S1 , solve (theta * I - S2 , S1 .T ))
115114
116115 return dP
117116
@@ -143,12 +142,12 @@ def b_operator(self, P):
143142
144143 """
145144 A , B , Q , R , beta = self .A , self .B , self .Q , self .R , self .beta
146- S1 = Q + beta * dot (B .T , dot (P , B ))
147- S2 = beta * dot (B .T , dot (P , A ))
148- S3 = beta * dot (A .T , dot (P , A ))
145+ S1 = Q + beta * np . dot (B .T , np . dot (P , B ))
146+ S2 = beta * np . dot (B .T , np . dot (P , A ))
147+ S3 = beta * np . dot (A .T , np . dot (P , A ))
149148 F = solve (S1 , S2 ) if not self .pure_forecasting else np .zeros (
150149 (self .k , self .n ))
151- new_P = R - dot (S2 .T , F ) + S3
150+ new_P = R - np . dot (S2 .T , F ) + S3
152151
153152 return F , new_P
154153
@@ -188,7 +187,7 @@ def robust_rule(self, method='doubling'):
188187 beta , theta = self .beta , self .theta
189188 k , j = self .k , self .j
190189 # == Set up LQ version == #
191- I = identity (j )
190+ I = np . identity (j )
192191 Z = np .zeros ((k , j ))
193192
194193 if self .pure_forecasting :
@@ -200,8 +199,8 @@ def robust_rule(self, method='doubling'):
200199 K = - f [:k , :]
201200
202201 else :
203- Ba = hstack ([B , C ])
204- Qa = vstack ([hstack ([Q , Z ]), hstack ([Z .T , - beta * I * theta ])])
202+ Ba = np . hstack ([B , C ])
203+ Qa = np . vstack ([np . hstack ([Q , Z ]), np . hstack ([Z .T , - beta * I * theta ])])
205204 lq = LQ (Qa , R , A , Ba , beta = beta )
206205
207206 # == Solve and convert back to robust problem == #
@@ -281,8 +280,8 @@ def F_to_K(self, F, method='doubling'):
281280
282281 """
283282 Q2 = self .beta * self .theta
284- R2 = - self .R - dot (F .T , dot (self .Q , F ))
285- A2 = self .A - dot (self .B , F )
283+ R2 = - self .R - np . dot (F .T , np . dot (self .Q , F ))
284+ A2 = self .A - np . dot (self .B , F )
286285 B2 = self .C
287286 lq = LQ (Q2 , R2 , A2 , B2 , beta = self .beta )
288287 neg_P , neg_K , d = lq .stationary_values (method = method )
@@ -309,10 +308,10 @@ def K_to_F(self, K, method='doubling'):
309308 The value function for a given K
310309
311310 """
312- A1 = self .A + dot (self .C , K )
311+ A1 = self .A + np . dot (self .C , K )
313312 B1 = self .B
314313 Q1 = self .Q
315- R1 = self .R - self .beta * self .theta * dot (K .T , K )
314+ R1 = self .R - self .beta * self .theta * np . dot (K .T , K )
316315 lq = LQ (Q1 , R1 , A1 , B1 , beta = self .beta )
317316 P , F , d = lq .stationary_values (method = method )
318317
@@ -349,9 +348,9 @@ def compute_deterministic_entropy(self, F, K, x0):
349348 The deterministic entropy
350349
351350 """
352- H0 = dot (K .T , K )
351+ H0 = np . dot (K .T , K )
353352 C0 = np .zeros ((self .n , 1 ))
354- A0 = self .A - dot (self .B , F ) + dot (self .C , K )
353+ A0 = self .A - np . dot (self .B , F ) + np . dot (self .C , K )
355354 e = var_quadratic_sum (A0 , C0 , H0 , self .beta , x0 )
356355
357356 return e
@@ -389,13 +388,13 @@ def evaluate_F(self, F):
389388 K_F , P_F = self .F_to_K (F )
390389 I = np .identity (self .j )
391390 H = inv (I - C .T .dot (P_F .dot (C )) / theta )
392- d_F = log (det (H ))
391+ d_F = np . log (det (H ))
393392
394393 # == Compute O_F and o_F == #
395- AO = sqrt (beta ) * (A - dot (B , F ) + dot (C , K_F ))
396- O_F = solve_discrete_lyapunov (AO .T , beta * dot (K_F .T , K_F ))
397- ho = (trace (H - 1 ) - d_F ) / 2.0
398- tr = trace (dot (O_F , C .dot (H .dot (C .T ))))
394+ AO = np . sqrt (beta ) * (A - np . dot (B , F ) + np . dot (C , K_F ))
395+ O_F = solve_discrete_lyapunov (AO .T , beta * np . dot (K_F .T , K_F ))
396+ ho = (np . trace (H - 1 ) - d_F ) / 2.0
397+ tr = np . trace (np . dot (O_F , C .dot (H .dot (C .T ))))
399398 o_F = (ho + beta * tr ) / (1 - beta )
400399
401400 return K_F , P_F , d_F , O_F , o_F
0 commit comments