QuantEcon / QuantEcon.jl

Julia implementation of QuantEcon routines
https://quantecon.org/quantecon-jl/
BSD 3-Clause "New" or "Revised" License
506 stars 303 forks source link

Initial condition for stationary distribution of LSS with a constant term #201

Open jlperla opened 6 years ago

jlperla commented 6 years ago

A couple of students were having trouble with the LSS model and calling stationary_distributions because they hadn't created it with an initial condition. So the following works

using QuantEcon
A1 = 0.6;
a = 1.0
A = [A1 a; 0 1]
C1 = 4
C = [C1;0]
G = [1 0]
x_0 = [0; 1.0] #Important that the initial condition is in the correct place!
lss = LSS(A, C, G; mu_0 = x_0)
#If you look at the notes and the documents, it says you need an initial condition
μ_x, μ_y, Σ_x, Σ_y = stationary_distributions(lss)

But changing it to lss = LSS(A, C, G) does not

The issue is that the code doesn't warn them that this wouldn't work and doesn't correct the default initial condition (which I assume is just 0s)?

So, is there any way to either warn them that this is not kosher with a constant term, or (even better!) adjust the default initial condition to include the constants? You are already detecting the constant terms with the remove_constants(lss) function?

jlperla commented 6 years ago

Just an update on this: this caused a great deal of confusion in the assignments for people when the state space had a constant term. Also, using the initial prior mean for the initial condition of the stationary distribution algorithm is a little hard to understand for some. I think that adjusting the default initial condition for the steady state algorithm to put in any of the constant terms would help a great deal with that confusion.

jstac commented 6 years ago

I didn't fully understand the second comment but certainly it should be possible to call stationary_distributions after lss = LSS(A, C, G) .

In fact I would have thought we should be computing these stationary moments with linear algebra routines rather than iteratively. The expressions are available here:

https://lectures.quantecon.org/jl/linear_models.html

For the variance-covariance matrices we should be using solve_discrete_lyapunov from this package.

jlperla commented 6 years ago

Great, I think that calling stationary_distributions on LSS(A, C, G) directly would be great (and I think it is easy enough to do since you are already identifying constant. My second comment was that it was tricky for them to understand that optional parameter called mu_0 was the initial condition for the solution to the stationary_distributions.

For a user, the nice thing about the iterative method instead of solving the lyapunov directly is that it works for a state space with the constant term in it. That way they don't need to do the transformation to a state space representation that removes the constant term.