Skip to content

Commit 7ea7b18

Browse files
authored
Merge pull request #498 from shizejin/fix_lqcontrol
FIX: two minor modifications in `lqcontrol`
2 parents 15b3b93 + cfd14dc commit 7ea7b18

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

quantecon/lqcontrol.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ def compute_sequence(self, x0, ts_length=None, method='doubling',
298298
# == Preliminaries, infinite horizon case == #
299299
else:
300300
T = ts_length if ts_length else 100
301-
self.stationary_values(method=method)
301+
if self.P is None:
302+
self.stationary_values(method=method)
302303

303304
# == Set up initial condition and arrays to store paths == #
304305
random_state = check_random_state(random_state)
@@ -570,7 +571,8 @@ def compute_sequence(self, x0, ts_length=None, random_state=None):
570571
"""
571572

572573
# === solve for optimal policies === #
573-
self.stationary_values()
574+
if self.Ps is None:
575+
self.stationary_values()
574576

575577
# === Simplify notation === #
576578
As, Bs, Cs = self.As, self.Bs, self.Cs
@@ -605,6 +607,6 @@ def compute_sequence(self, x0, ts_length=None, random_state=None):
605607
u_path[:, t] = - (Fs[state[t]] @ x_path[:, t])
606608
Ax = As[state[T]] @ x_path[:, T-1]
607609
Bu = Bs[state[T]] @ u_path[:, T-1]
608-
x_path[:, T] = Ax + Bu + w_path[:, T]
610+
x_path[:, T] = Ax + Bu + Cw_path[:, T]
609611

610612
return x_path, u_path, w_path, state

quantecon/tests/test_lqcontrol.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TestLQMarkov(unittest.TestCase):
9595

9696
def setUp(self):
9797

98-
# Markove chain transition matrix
98+
# Markov chain transition matrix
9999
Π = np.array([[0.8, 0.2],
100100
[0.2, 0.8]])
101101

@@ -153,7 +153,7 @@ def test_scalar_sequences_with_seed(self):
153153
lq_markov_scalar = self.lq_markov_scalar
154154
x0 = 2
155155

156-
expected_x_seq = np.array([[2., 1.15977567, 1.20677567]])
156+
expected_x_seq = np.array([[2., 1.15977567, 0.6725398]])
157157
expected_u_seq = np.array([[1.28044866, 0.7425166]])
158158
expected_w_seq = np.array([[1.3486939, 0.55721062, 0.53423587]])
159159
expected_state = np.array([1, 1, 1])
@@ -188,8 +188,8 @@ def test_mat_sequences(self):
188188
lq_markov_mat = self.lq_markov_mat1
189189
x0 = np.array([[1000, 1, 25]])
190190

191-
expected_x_seq = np.array([[1.00000000e+03, 1.01490556e+03],
192-
[1.00000000e+00, 2.18454431e+00],
191+
expected_x_seq = np.array([[1.00000000e+03, 1.01372101e+03],
192+
[1.00000000e+00, 1.00000000e+00],
193193
[2.50000000e+01, 2.61845443e+01]])
194194
expected_u_seq = np.array([[1013.72101253]])
195195
expected_w_seq = np.array([[0.41782708, 1.18454431]])

0 commit comments

Comments
 (0)