Skip to content

Commit 1b2394b

Browse files
committed
update tests
1 parent 8745cbd commit 1b2394b

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

quantecon/tests/test_kalman.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def setup_method(self):
1717
self.G = np.eye(2) * .5
1818
self.H = np.eye(2) * np.sqrt(0.2)
1919

20-
self.Q = np.dot(self.C, self.C.T)
21-
self.R = np.dot(self.H, self.H.T)
20+
self.Q = self.C @ self.C.T
21+
self.R = self.H @ self.H.T
2222

2323
ss = LinearStateSpace(self.A, self.C, self.G, self.H)
2424

@@ -38,13 +38,13 @@ def test_stationarity(self):
3838
for method in self.methods:
3939
sig_inf, kal_gain = kf.stationary_values(method=method)
4040

41-
mat_inv = np.linalg.inv(G.dot(sig_inf).dot(G.T) + R)
41+
mat_inv = np.linalg.inv(G @ sig_inf @ G.T + R)
4242

4343
# Compute the kalmain gain and sigma infinity according to the
4444
# recursive equations and compare
45-
kal_recursion = np.dot(A, sig_inf).dot(G.T).dot(mat_inv)
46-
sig_recursion = (A.dot(sig_inf).dot(A.T) -
47-
kal_recursion.dot(G).dot(sig_inf).dot(A.T) + Q)
45+
kal_recursion = A @ sig_inf @ G.T @ mat_inv
46+
sig_recursion = (A @ sig_inf @ A.T -
47+
kal_recursion @ G @ sig_inf @ A.T + Q)
4848

4949
assert_allclose(kal_gain, kal_recursion, rtol=1e-4, atol=1e-2)
5050
assert_allclose(sig_inf, sig_recursion, rtol=1e-4, atol=1e-2)
@@ -75,12 +75,12 @@ def test_update_nonstationary(self):
7575
kf.set_state(curr_x, curr_sigma)
7676
kf.update(y_observed)
7777

78-
mat_inv = np.linalg.inv(G.dot(curr_sigma).dot(G.T) + R)
79-
curr_k = np.dot(A, curr_sigma).dot(G.T).dot(mat_inv)
80-
new_sigma = (A.dot(curr_sigma).dot(A.T) -
81-
curr_k.dot(G).dot(curr_sigma).dot(A.T) + Q)
78+
mat_inv = np.linalg.inv(G @ curr_sigma @ G.T + R)
79+
curr_k = A @ curr_sigma @ G.T @ mat_inv
80+
new_sigma = (A @ curr_sigma@ A.T -
81+
curr_k @ G @ curr_sigma @ A.T + Q)
8282

83-
new_xhat = A.dot(curr_x) + curr_k.dot(y_observed - G.dot(curr_x))
83+
new_xhat = A @ curr_x + curr_k @ (y_observed - G @ curr_x)
8484

8585
assert_allclose(kf.Sigma, new_sigma, rtol=1e-4, atol=1e-2)
8686
assert_allclose(kf.x_hat, new_xhat, rtol=1e-4, atol=1e-2)

quantecon/tests/test_lqcontrol.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55
import numpy as np
66
from numpy.testing import assert_allclose, assert_raises
7-
from numpy import dot
87
from quantecon import LQ, LQMarkov
98

109

@@ -49,7 +48,7 @@ def test_scalar_sequences(self):
4948
(2*lq_scalar.Q+lq_scalar.beta*lq_scalar.Rf*2*lq_scalar.B**2) \
5049
* x0
5150
x_1 = lq_scalar.A * x0 + lq_scalar.B * u_0 + \
52-
dot(lq_scalar.C, w_seq[0, -1])
51+
np.dot(lq_scalar.C, w_seq[0, -1])
5352

5453
assert_allclose(u_0, u_seq, rtol=1e-4)
5554
assert_allclose(x_1, x_seq[0, -1], rtol=1e-4)
@@ -83,7 +82,7 @@ def test_stationary_mat(self):
8382

8483
for method in self.methods:
8584
P, F, d = lq_mat.stationary_values(method=method)
86-
val_func_lq = np.dot(x0, P).dot(x0)
85+
val_func_lq = x0 @ P @ x0
8786

8887
assert_allclose(f_answer, F, atol=1e-3)
8988
assert_allclose(val_func_lq, val_func_answer, atol=1e-3)

quantecon/tests/test_lqnash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ def test_nnash(self):
8686
f1, f2, p1, p2 = nnash(a, b1, b2, r1, r2, q1, q2, s1, s2, w1, w2, m1,
8787
m2)
8888

89-
aaa = a - b1.dot(f1) - b2.dot(f2)
89+
aaa = a - b1 @ f1 - b2 @ f2
9090
aa = aaa[:2, :2]
9191
tf = np.eye(2)-aa
9292
tfi = np.linalg.inv(tf)
93-
xbar = tfi.dot(aaa[:2, 2])
93+
xbar = tfi @ aaa[:2, 2]
9494

9595
# Define answers from matlab. TODO: this is ghetto
9696
f1_ml = np.array([

quantecon/tests/test_matrix_eqn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ def test_solve_discrete_lyapunov_complex():
3434

3535
X = qme.solve_discrete_lyapunov(A, B)
3636

37-
assert_allclose(np.dot(np.dot(A, X), A.conj().transpose()) - X, -B,
37+
assert_allclose( A @ X @ A.conj().transpose() - X, -B,
3838
atol=1e-15)

quantecon/tests/test_ricatti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def dare_tjm_3(method):
6262
B = I
6363
R = [[1, r],
6464
[r, r*r]]
65-
Q = I - np.dot(A.T, A) + np.dot(A.T, np.linalg.solve(R + I, A))
65+
Q = I - A.T @ A + A.T @ np.linalg.solve(R + I, A)
6666
X = solve_discrete_riccati(A, B, Q, R, method=method)
6767
Y = np.identity(2)
6868
assert_allclose(X, Y, atol=1e-07)

0 commit comments

Comments
 (0)