Skip to content
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

Merged
merged 15 commits into from
Sep 11, 2018
Merged

add solver for dynamic linear economies as LQ problem #426

merged 15 commits into from
Sep 11, 2018

Conversation

mmcky
Copy link
Contributor

@mmcky mmcky commented Aug 13, 2018

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:

@mmcky mmcky added the in-work label Aug 13, 2018
quantecon/dle.py Outdated

import numpy as np
from sympy import Matrix
from pylab import array
Copy link
Contributor Author

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?

@oyamad
Copy link
Member

oyamad commented Aug 13, 2018

  • Comply with PEP8.

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()
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

@mmcky mmcky Aug 23, 2018

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)?

Copy link
Member

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.

Copy link
Contributor Author

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.

@coveralls
Copy link

coveralls commented Aug 23, 2018

Coverage Status

Coverage decreased (-0.8%) to 94.389% when pulling 54be06a on add-dle into 9a47420 on master.

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()
Copy link
Contributor Author

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?

@mmcky
Copy link
Contributor Author

mmcky commented Sep 7, 2018

@oyamad the nullspace method attached to Sympy Matrix Returns list of vectors (Matrix objects) that span nullspace of self. The quantecon nullspace returns an approximate basis for the nullspace of A. I have reverted to using the sympy Matrix object for now and will open an issue to remove.

@oyamad
Copy link
Member

oyamad commented Sep 7, 2018

@mmcky Do you have an example that yields such a difference?

@mmcky
Copy link
Contributor Author

mmcky commented Sep 10, 2018

@oyamad

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]])

@oyamad
Copy link
Member

oyamad commented Sep 10, 2018

What is the problem exactly?
The approximation looks good:

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]])

@mmcky
Copy link
Contributor Author

mmcky commented Sep 11, 2018

ah thanks @oyamad I didn't divide by the constant. I will update the dle class now.

@mmcky
Copy link
Contributor Author

mmcky commented Sep 11, 2018

@oyamad are you seeing Travis in your browser? It appears to be running on Travis but not showing status on this github PR for me.

@mmcky
Copy link
Contributor Author

mmcky commented Sep 11, 2018

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.

@mmcky mmcky added ready and removed in-work labels Sep 11, 2018
@mmcky mmcky merged commit 72bd401 into master Sep 11, 2018
@mmcky mmcky deleted the add-dle branch September 11, 2018 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants