Skip to content

Commit

Permalink
Tom's edits of the comments in three files, kalman.py, lss.py, and lq…
Browse files Browse the repository at this point in the history
…control.py. Removed rst like phrases
  • Loading branch information
thomassargent30 committed Feb 26, 2015
1 parent 51d5930 commit e625d8e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 61 deletions.
25 changes: 11 additions & 14 deletions quantecon/kalman.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ class Kalman(object):
r"""
Implements the Kalman filter for the Gaussian state space model
.. math::
x_{t+1} = A x_t + w_{t+1}
y_t = G x_t + v_t.
x_{t+1} &= A x_t + w_{t+1}\\
y_t &= G x_t + v_t.
Here :math:`x_t` is the hidden state and :math:`y_t` is the
measurement. The shocks :math:`w_t` and :math:`v_t` are iid zero
Here x_t is the hidden state and y_t is the
measurement. The shocks w_t and v_t are iid zero
mean Gaussians with covariance matrices Q and R respectively.
Parameters
Expand Down Expand Up @@ -115,12 +113,11 @@ def prior_to_filtered(self, y):
The updates are according to
.. math::
x_{hat}^F &= x_{hat} + \Sigma G' (G \Sigma G' + R)^{-1}
(y - G x_{hat}) \\
\Sigma^F &= \Sigma - \Sigma G' (G \Sigma G' + R)^{-1} G
\Sigma
x_{hat}^F = x_{hat} + Sigma G' (G Sigma G' + R)^{-1}
(y - G x_{hat})
Sigma^F = Sigma - Sigma G' (G Sigma G' + R)^{-1} G
Sigma
Parameters
----------
Expand Down Expand Up @@ -158,7 +155,7 @@ def filtered_to_forecast(self):

def update(self, y):
"""
Updates `x_hat` and `Sigma` given k x 1 ndarray `y`. The full
Updates x_hat and Sigma given k x 1 ndarray y. The full
update, from one period to the next
Parameters
Expand All @@ -172,7 +169,7 @@ def update(self, y):

def stationary_values(self):
"""
Computes the limit of :math:`Sigma_t` as :math:`t \to \infty` by
Computes the limit of Sigma_t as t goes to infinity by
solving the associated Riccati equation. Computation is via the
doubling algorithm (see the documentation in
`matrix_eqn.solve_discrete_riccati`).
Expand Down
62 changes: 24 additions & 38 deletions quantecon/lqcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,23 @@ class LQ(object):
This class is for analyzing linear quadratic optimal control
problems of either the infinite horizon form
.. math::
\min E \sum_{t=0}^{\infty} \beta^t r(x_t, u_t)
. min E sum_{t=0}^{\infty} beta^t r(x_t, u_t)
with
.. math::
r(x_t, u_t) := x_t' R x_t + u_t' Q u_t + 2 u_t' N x_t
r(x_t, u_t) := x_t' R x_t + u_t' Q u_t + 2 u_t' N x_t
or the finite horizon form
.. math::
\min E \sum_{t=0}^{T-1} \beta^t r(x_t, u_t) + \beta^T x_T' R_f x_T
min E sum_{t=0}^{T-1} beta^t r(x_t, u_t) + beta^T x_T' R_f x_T
Both are minimized subject to the law of motion
.. math::
x_{t+1} = A x_t + B u_t + C w_{t+1}
x_{t+1} = A x_t + B u_t + C w_{t+1}
Here x is n x 1, u is k x 1, w is j x 1 and the matrices are
conformable for these dimensions. The sequence {w_t} is assumed to
be white noise, with zero mean and :math:`E w_t w_t' = I`, the j x j
be white noise, with zero mean and E w_t w_t = I, the j x j
identity.
If C is not supplied as a parameter, the model is assumed to be
Expand All @@ -53,44 +45,42 @@ class LQ(object):
For this model, the time t value (i.e., cost-to-go) function V_t
takes the form
.. math ::
x' P_T x + d_T
x' P_T x + d_T
and the optimal policy is of the form :math:`u_T = -F_T x_T`. In
and the optimal policy is of the form u_T = -F_T x_T. In
the infinite horizon case, V, P, d and F are all stationary.
Parameters
----------
Q : array_like(float)
Q is the payoff(or cost) matrix that corresponds with the
control variable u and is `k x k`. Should be symmetric and
control variable u and is k x k. Should be symmetric and
nonnegative definite
R : array_like(float)
R is the payoff(or cost) matrix that corresponds with the
state variable x and is `n x n`. Should be symetric and
state variable x and is n x n. Should be symetric and
non-negative definite
N : array_like(float)
N is the cross product term in the payoff, as above. It should
be `k x n`.
be k x n.
A : array_like(float)
A is part of the state transition as described above. It should
be `n x n`
be n x n
B : array_like(float)
B is part of the state transition as described above. It should
be `n x k`
be n x k
C : array_like(float), optional(default=None)
C is part of the state transition as described above and
corresponds to the random variable today. If the model is
deterministic then C should take default value of `None`
deterministic then C should take default value of None
beta : scalar(float), optional(default=1)
beta is the discount parameter
T : scalar(int), optional(default=None)
T is the number of periods in a finite horizon problem.
Rf : array_like(float), optional(default=None)
Rf is the final (in a finite horizon model) payoff(or cost)
matrix that corresponds with the control variable u and is `n x
n`. Should be symetric and non-negative definite
matrix that corresponds with the control variable u and is n x
n. Should be symetric and non-negative definite
Attributes
Expand Down Expand Up @@ -155,7 +145,7 @@ def __str__(self):
- k (number of control variables) : {k}
- j (number of shocks) : {j}
"""
t = "infinte" if self.T is None else self.T
t = "infinite" if self.T is None else self.T
return dedent(m.format(b=self.beta, n=self.n, k=self.k, j=self.j,
t=t))

Expand All @@ -164,14 +154,12 @@ def update_values(self):
This method is for updating in the finite horizon case. It
shifts the current value function
.. math::
V_t(x) = x' P_t x + d_t
V_t(x) = x' P_t x + d_t
and the optimal policy :math:`F_t` one step *back* in time,
replacing the pair :math:`P_t` and :math:`d_t` with
:math`P_{t-1}` and :math:`d_{t-1}`, and :math:`F_t` with
:math:`F_{t-1}`
and the optimal policy F_t one step *back* in time,
replacing the pair P_t and d_t with
P_{t-1} and d_{t-1}, and F_t with
F_{t-1}
"""
# === Simplify notation === #
Expand All @@ -195,9 +183,7 @@ def stationary_values(self):
Computes the matrix P and scalar d that represent the value
function
.. math::
V(x) = x' P x + d
V(x) = x' P x + d
in the infinite horizon case. Also computes the control matrix
F from u = - Fx
Expand Down Expand Up @@ -238,8 +224,8 @@ def stationary_values(self):
def compute_sequence(self, x0, ts_length=None):
"""
Compute and return the optimal state and control sequences
:math:`x_0,..., x_T` and :math:`u_0,..., u_T` under the
assumption that :math:`{w_t}` is iid and N(0, 1).
x_0, ..., x_T and u_0,..., u_T under the
assumption that {w_t} is iid and N(0, 1).
Parameters
===========
Expand Down
12 changes: 3 additions & 9 deletions quantecon/lss.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Filename: lss.py
Computes quantities related to the Gaussian linear state space model
Computes quantities associated with the Gaussian linear state space model
x_{t+1} = A x_t + C w_{t+1}
Expand All @@ -23,13 +23,9 @@ class LSS(object):
A class that describes a Gaussian linear state space model of the
form:
.. math::
x_{t+1} = A x_t + C w_{t+1}
x_{t+1} = A x_t + C w_{t+1}
.. math::
y_t = G x_t
y_t = G x_t
where {w_t} are iid and N(0, I). If the initial conditions mu_0
and Sigma_0 for x_0 ~ N(mu_0, Sigma_0) are not supplied, both
Expand Down Expand Up @@ -245,8 +241,6 @@ def geometric_sums(self, beta, x_t):
"""
Forecast the geometric sums
.. math::
S_x := E [sum_{j=0}^{\infty} beta^j x_{t+j} | x_t ]
S_y := E [sum_{j=0}^{\infty} beta^j y_{t+j} | x_t ]
Expand Down

0 comments on commit e625d8e

Please sign in to comment.