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

Multivariate normal with discrete approximation #948

Merged
merged 9 commits into from May 26, 2021

Conversation

Mv77
Copy link
Contributor

@Mv77 Mv77 commented Feb 10, 2021

#120 Requests methods to deal with correlated discretized RVs.

This PR adds a multivariate normal distribution class, with a discretization method.

The idea for approximating an N-variate normal is:

  • Construct a discretization for N independent standard normals.
  • Join them as in CombineIndepDstns, taking the product of their grids (so you get an N-dimensional grid) and multiplying their pmfs.
  • Rotate the grid using the eigendecomposition so that the resulting grid has the VCOV matrix that you want.

I have not found a citation for this, and I'm not familiar with the literature, so I'm not sure if this is inaccurate or inefficient. It seems to work well in my tests.

A multivariate log-normal like the one requested in #120 should be easily derivable from this.

@llorracc @sbenthall what do you think?

  • Tests for new functionality/models or Tests to reproduce the bug-fix in code.
  • Updated documentation of features that add new functionality.
  • Update CHANGELOG.md with major/minor changes.

@project-bot project-bot bot added this to Needs Triage in Issues & PRs Feb 10, 2021
@Mv77 Mv77 changed the title Multivariate normal with discrete approximation [WIP] Multivariate normal with discrete approximation Feb 10, 2021
@Mv77
Copy link
Contributor Author

Mv77 commented Feb 10, 2021

Here's an example of how it looks:
image

The black dots are draws and the red are the discretized X's. Both from a negatively correlated multivariate normal.

@llorracc
Copy link
Collaborator

@Mv77 this looks great! I'd propose that a good test of it would be to implement the multivariate lognormal you mention as an easy application, because it should be easy to compare that to something that surely must exist which is some kind of tool for calculating the CDFs of continuous multivariate lognormals.

@sbenthall sbenthall added this to the 1.1.0 milestone Feb 18, 2021
@llorracc
Copy link
Collaborator

@Mv77, I'd like to merge this in if you will resolve the conflicts.

@Mv77
Copy link
Contributor Author

Mv77 commented May 26, 2021

@Mv77, I'd like to merge this in if you will resolve the conflicts.

Great, I've just resolved them. This should be ready to merge after tests pass.

@codecov-commenter
Copy link

Codecov Report

Merging #948 (54accc5) into master (6d157ea) will increase coverage by 0.09%.
The diff coverage is 87.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #948      +/-   ##
==========================================
+ Coverage   71.67%   71.76%   +0.09%     
==========================================
  Files          63       63              
  Lines        9197     9256      +59     
==========================================
+ Hits         6592     6643      +51     
- Misses       2605     2613       +8     
Impacted Files Coverage Δ
HARK/distribution.py 79.34% <74.19%> (-0.53%) ⬇️
HARK/tests/test_approxDstns.py 100.00% <100.00%> (ø)
HARK/tests/test_distribution.py 100.00% <100.00%> (ø)
HARK/ConsumptionSaving/ConsIndShockModelFast.py 51.05% <0.00%> (ø)

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 6d157ea...54accc5. Read the comment docs.

@Mv77 Mv77 changed the title [WIP] Multivariate normal with discrete approximation Multivariate normal with discrete approximation May 26, 2021
@llorracc llorracc merged commit 365949e into econ-ark:master May 26, 2021
Issues & PRs automation moved this from Needs Triage to Done May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Issues & PRs
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants