Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions quantecon/lqcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ def compute_sequence(self, x0, ts_length=None, method='doubling',
# == Preliminaries, infinite horizon case == #
else:
T = ts_length if ts_length else 100
self.stationary_values(method=method)
if self.P is None:
self.stationary_values(method=method)

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

# === solve for optimal policies === #
self.stationary_values()
if self.Ps is None:
self.stationary_values()

# === Simplify notation === #
As, Bs, Cs = self.As, self.Bs, self.Cs
Expand Down Expand Up @@ -605,6 +607,6 @@ def compute_sequence(self, x0, ts_length=None, random_state=None):
u_path[:, t] = - (Fs[state[t]] @ x_path[:, t])
Ax = As[state[T]] @ x_path[:, T-1]
Bu = Bs[state[T]] @ u_path[:, T-1]
x_path[:, T] = Ax + Bu + w_path[:, T]
x_path[:, T] = Ax + Bu + Cw_path[:, T]

return x_path, u_path, w_path, state
8 changes: 4 additions & 4 deletions quantecon/tests/test_lqcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TestLQMarkov(unittest.TestCase):

def setUp(self):

# Markove chain transition matrix
# Markov chain transition matrix
Π = np.array([[0.8, 0.2],
[0.2, 0.8]])

Expand Down Expand Up @@ -153,7 +153,7 @@ def test_scalar_sequences_with_seed(self):
lq_markov_scalar = self.lq_markov_scalar
x0 = 2

expected_x_seq = np.array([[2., 1.15977567, 1.20677567]])
expected_x_seq = np.array([[2., 1.15977567, 0.6725398]])
expected_u_seq = np.array([[1.28044866, 0.7425166]])
expected_w_seq = np.array([[1.3486939, 0.55721062, 0.53423587]])
expected_state = np.array([1, 1, 1])
Expand Down Expand Up @@ -188,8 +188,8 @@ def test_mat_sequences(self):
lq_markov_mat = self.lq_markov_mat1
x0 = np.array([[1000, 1, 25]])

expected_x_seq = np.array([[1.00000000e+03, 1.01490556e+03],
[1.00000000e+00, 2.18454431e+00],
expected_x_seq = np.array([[1.00000000e+03, 1.01372101e+03],
[1.00000000e+00, 1.00000000e+00],
[2.50000000e+01, 2.61845443e+01]])
expected_u_seq = np.array([[1013.72101253]])
expected_w_seq = np.array([[0.41782708, 1.18454431]])
Expand Down