Skip to content

Commit

Permalink
add pure forecast case to test_robustlq
Browse files Browse the repository at this point in the history
  • Loading branch information
szokeb87 committed Oct 23, 2017
1 parent 776a8bf commit 245670c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions quantecon/tests/test_robustlq.py
@@ -1,8 +1,8 @@
"""
Author: Chase Coleman
Filename: test_lqcontrol
Filename: test_robustlq
Tests for lqcontrol.py file
Tests for robustlq.py file
"""
import sys
Expand Down Expand Up @@ -35,36 +35,54 @@ def setUp(self):

R = -R
Q = gamma / 2
Q_pf = 0.

A = np.array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., rho]])
B = np.array([[0.],
[1.],
[0.]])
B_pf = np.zeros((3, 1))

C = np.array([[0.],
[0.],
[sigma_d]])


# the *_pf endings refer to an example with pure forecasting
# (see p171 in Robustness)
self.rblq_test = RBLQ(Q, R, A, B, C, beta, theta)
self.rblq_test_pf = RBLQ(Q_pf, R, A, B_pf, C, beta, theta)
self.lq_test = LQ(Q, R, A, B, C, beta)

self.Fr, self.Kr, self.Pr = self.rblq_test.robust_rule()
self.Fr_pf, self.Kr_pf, self.Pr_pf = self.rblq_test_pf.robust_rule()

def tearDown(self):
del self.rblq_test
del self.rblq_test_pf

def test_pure_forecasting(self):
self.assertTrue(self.rblq_test_pf.pure_forecasting)

def test_robust_rule_vs_simple(self):
rblq = self.rblq_test
rblq_pf = self.rblq_test_pf
Fr, Kr, Pr = self.Fr, self.Kr, self.Pr
Fr_pf, Kr_pf, Pr_pf = self.Fr_pf, self.Kr_pf, self.Pr_pf

Fs, Ks, Ps = rblq.robust_rule_simple(P_init=Pr, tol=1e-12)
Fs_pf, Ks_pf, Ps_pf = rblq_pf.robust_rule_simple(P_init=Pr_pf, tol=1e-12)

assert_allclose(Fr, Fs, rtol=1e-4)
assert_allclose(Kr, Ks, rtol=1e-4)
assert_allclose(Pr, Ps, rtol=1e-4)

assert_allclose(Fr_pf, Fs_pf, rtol=1e-4)
assert_allclose(Kr_pf, Ks_pf, rtol=1e-4)
assert_allclose(Pr_pf, Ps_pf, rtol=1e-4)


def test_f2k_and_k2f(self):
rblq = self.rblq_test
Fr, Kr, Pr = self.Fr, self.Kr, self.Pr
Expand Down

0 comments on commit 245670c

Please sign in to comment.