-
-
Notifications
You must be signed in to change notification settings - Fork 299
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
New features for mc_tools #56
Conversation
6f3c161
to
cf59a18
Compare
@ZacCranko Thanks, it looks very nice.
|
# Provide constructor that infers T from eltype of matrix | ||
MarkovChain{T<:Real}(p::Matrix{T}) = MarkovChain{T}(p) | ||
return MarkovChain{T}(p) | ||
end |
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.
We should restore the inner+outer constructor pair. The reason is that we never want to be able to create an instance of MarkovChain
without these 3 conditions holding -- these are the invariants referred to in the inner constructor section of the manual
WIth Version 0.3.10, I got the following error: julia> using QuantEcon
julia> mc = MarkovChain([0.4 0.6; 0.2 0.8])
Discrete Markov Chain
stochastic matrix:
2x2 Array{Float64,2}:
0.4 0.6
0.2 0.8
julia> mc_compute_stationary(mc)
ERROR: error compiling mc_compute_stationary: error compiling __mc_compute_stationary#140__: unsupported or misplaced expression => in function __mc_compute_stationary#140__ It works fine with Version 0.4.0. |
Thanks for the note. We'll take care of it |
:lu => lu_solve, | ||
:eigen => eigen_solve) | ||
function mc_compute_stationary{T}(mc::MarkovChain{T}; method=:gth) | ||
solvers = Dict(:gth => gth_solve, :lu => lu_solve, :eigen => eigen_solve) |
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.
This line needs @compat
to work on 0.3 -- as @oyamad noted
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.
We should also make sure that the method
argument is typed as ::Symbol
(anything else will throw an error when we try to access the dict)
(we should restore exactly what was here originally -- it reverts both changes)
00cb048
to
bbbe0df
Compare
Thanks guys, I believe I've addressed everything except for the |
@ZacCranko Thanks!
|
I don't really have much of an opinion on the solution methods. Though since this is a pedagogical tool, there is probably utility in allowing the the user to compare GTH and the other methods, especially if we, in the future, were to have a lecture on approaches to compute the stationary distribution of a Markov chain. This would be consistent with the fact that we're exporting |
I see, thanks. Makes sense for education purposes. |
Thanks for that, good to know! Comments fixed. |
Another issue: Why does |
I'm happy to have |
Right, then we might consider having |
The only convenience with the current orientation of the stochastic matrix is that it coincides with the definition of an adjacency matrix. |
Ah that's a good point. Would it be costly to transpose the column-stochastic input and pass it to |
Computing the transpose of a matrix is O(n), but this is somewhat unrelated to what this PR is addressing. If you really feel strongly about this I think it would be best to open an issue. |
Yes, that's right. |
Sorry if I get something wrong here as I'm just going by the thread, but I would recommend that we return the stationary distributions -- and all other distributions -- as row vectors, either by transposing them as they are passed out or some other approach. It's entirely conventional in the field of Markov chains that distributions are row vectors. Similarly, the matrix should be such that P[i, j] means prob of moving from state i to state j. (In fact that's why distributions end up being row vectors that we multiply from the left.) So the challenge is to implement this standard interface in the most efficient way. |
What if we return the stationary distributions as a |
I guess a flat array is fine. |
Ahoy hoy, is this ready to be merged? |
Hey sorry, I kinda forgot we hadn't merged this. I would love to see some tests of the new methods. i realize you want to change the tests. Will that happen soon? |
Yep, that'll happen pretty quick. |
Great, I'll break my rule of merging without tests this time... Thanks for the work on this. |
recurrent_classes(mc::MarkovChain)
communication_classes(mc::MarkovChain)
is_irreducible(mc::MarkovChain)
period(mc::MarkovChain)
Tests for these new functions are not included in this pull. I'm going to change up the tests file, so I'm submitting this pull and making those modifications separately, but all the old tests pass fine with the new code.