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 quadrature method #198

Merged
merged 10 commits into from
Dec 29, 2017
Merged

Conversation

Shunsuke-Hori
Copy link
Collaborator

@Shunsuke-Hori Shunsuke-Hori commented Dec 24, 2017

NOT READY FOR REVIEW The code seems to be working well basically, but let me finalize docs and potentially brush up the code

EDIT: Ready for review

This PR adds quadrature grid method for discrete_var, which is the last one of the three methods

@codecov-io
Copy link

codecov-io commented Dec 24, 2017

Codecov Report

Merging #198 into master will increase coverage by 0.29%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #198      +/-   ##
==========================================
+ Coverage   90.72%   91.02%   +0.29%     
==========================================
  Files          24       24              
  Lines        1682     1693      +11     
==========================================
+ Hits         1526     1541      +15     
+ Misses        156      152       -4
Impacted Files Coverage Δ
src/markov/markov_approx.jl 97.34% <100%> (+2.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 344619a...f69402e. Read the comment docs.

@Shunsuke-Hori Shunsuke-Hori changed the title [WIP] Add quadrature method Add quadrature method Dec 28, 2017
Copy link
Member

@sglyon sglyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

I have a few minor changes that I requested for you to make.

Also, I was wondering if we really need to introduce the FastGaussQuadrature dependency? Do the quadrature routines inside QuantEcon not satisfy the requirements? If they do work, did you opt for FastGaussQuadrature for performance reasons?

@@ -13,6 +13,7 @@ https://lectures.quantecon.org/jl/finite_markov.html

import Optim
import NLopt
import FastGaussQuadrature: gausshermite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change this to using FastGaussQuadrature: gausshermite. Import has two uses:

  1. Bring a module name into scope (as we do with Optim and NLopt above)
  2. Bring a specific function from a different module into scope so we can extend the function with our own methods. We don't add methods to gausshermite, so we should just call using instead of import.

@@ -371,17 +375,17 @@ function discrete_var(b::Union{Real, AbstractVector},
# Maximum entropy optimization
if n_moments == 1 # match only 1 moment
temp[:, jj], _, _ = discrete_approximation(y1D[jj, :],
X -> (reshape(X, 1, Nm)-cond_mean[jj, ii])/scaling_factor[jj],
X -> (X'-cond_mean[jj, ii])/scaling_factor[jj],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do ay of these operations need . in front of them to make them broadcasting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm..., I don't think so. X is always vector, cond_mean[jj, ii] and scaling_factor[jj] are always scalar.

Does it answer your question?

return nothing
end
warn_persistency(B::Real, method::Quadrature) = warn_persistency(fill(B, 1, 1), method)
warn_persistency(::Union{Real, AbstractMatrix}, ::Union{Even, Quantile}) = nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of ::Union{Even, Quantile}, let's have the second argument be ::VAREstimationMethod so that is the default for any additional VAREstimationMethod subtypes we might create in the future.

@Shunsuke-Hori
Copy link
Collaborator Author

@sglyon I removed FastGaussQuadrature from REQUIRE to reduce dependencies. I simply didn't know that QE has the same functionality. Regarding performance, the difference seems negligible.

@sglyon
Copy link
Member

sglyon commented Dec 29, 2017

Sounds great, thanks for the update!

@sglyon sglyon merged commit 84b961b into QuantEcon:master Dec 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants