-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add solver for dynamic linear economies as LQ problem #426
Conversation
quantecon/dle.py
Outdated
|
||
import numpy as np | ||
from sympy import Matrix | ||
from pylab import array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this simply importing a numpy
array?
|
quantecon/dle.py
Outdated
def compute_steadystate(self, nnc=2): #nnc is the position of the constant in the state vector | ||
""" Find non-stochastic steady-state of the economy """ | ||
zx = Matrix(np.eye(self.A0.shape[0])-self.A0) | ||
self.zz = zx.nullspace() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be replaced with quantecon.nullspace
? Then the import of Matrix
from sympy
would be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oyamad I am in favour of this. Can you let me know what I need to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.zz = qe.nullspace(A0)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmcky What I had in mind is
zx = np.eye(self.A0.shape[0]) - self.A0
self.zz = qe.nullspace(zx)
Maybe the following is better?
zx = -self.A0
zx[np.diag_indices_from(zx)] += 1
self.zz = qe.nullspace(zx)
self.zz /= self.zz[nnc]
But please check whether this gives the same shape of self.zz
as the original code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @oyamad. I will make the update and then confirm.
lq = LQ(self.Q, self.R, self.A, self.B, | ||
self.C, N=self.W, beta=self.beta) | ||
|
||
self.P, self.F, self.d = lq.stationary_values() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomassargent30 this will default to using doubling
as the method for computing. Should we allow the pass through of the method of computation to be doubling
and qz
?
… solutions verified by matlab programs
…the same ... need to investigate
@oyamad the |
@mmcky Do you have an example that yields such a difference? |
Given the input matrix source = np.array([[ 0.1 , 0. , -0.5 , -0.1 , 0. ],
[ 0. , 0.05, 0. , 0. , 0. ],
[ 0. , 0. , 0. , 0. , 0. ],
[ 0. , 0. , 0. , 0.2 , 0. ],
[ 0. , 0. , 0. , 0. , 0.5 ]]) using null space method from the Matrix object in Simps from sympy import Matrix
Matrix(source).nullspace() yields [Matrix([
[5.0],
[ 0],
[ 1],
[ 0],
[ 0]])] while null space method in quantecon from quantecon import nullspace
nullspace(source) yields array([[ 9.80580676e-01],
[-2.77555756e-17],
[ 1.96116135e-01],
[ 1.38777878e-17],
[ 0.00000000e+00]]) |
What is the problem exactly? zz = qe.nullspace(source)
nnc = 2
zz /= zz[nnc]
zz array([[ 5.00000000e+00],
[-1.41526222e-16],
[ 1.00000000e+00],
[ 7.07631108e-17],
[ 0.00000000e+00]]) |
ah thanks @oyamad I didn't divide by the constant. I will update the |
@oyamad are you seeing |
thanks @oyamad for picking up my error. This has now been migrated to using the quantecon method and testing has been updating on a known problem. |
This PR adds
DLE
object for solving dynamic linear economic problems by converting to LQ problem. This code has been contributed by Sebastian Graves.Adjustments required for inclusion in
QuantEcon.py
:update docstring to conform to style guide. Need to document
Parameters
in similar fashion to https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/robustlq.pyreview inclusion of
pylab
. I would prefer to use the core librariesnumpy
,matplotlib
andscipy
add tests