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

scipy.stats distributions #1197

Merged
merged 41 commits into from
Jan 11, 2023
Merged

scipy.stats distributions #1197

merged 41 commits into from
Jan 11, 2023

Conversation

alanlujan91
Copy link
Member

@alanlujan91 alanlujan91 commented Jan 1, 2023

Please ensure your pull request adheres to the following guidelines:

  • 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.

@codecov-commenter
Copy link

codecov-commenter commented Jan 1, 2023

Codecov Report

Base: 73.38% // Head: 73.28% // Decreases project coverage by -0.10% ⚠️

Coverage data is based on head (dd10e24) compared to base (881aa06).
Patch coverage: 91.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1197      +/-   ##
==========================================
- Coverage   73.38%   73.28%   -0.11%     
==========================================
  Files          74       74              
  Lines       12150    12149       -1     
==========================================
- Hits         8916     8903      -13     
- Misses       3234     3246      +12     
Impacted Files Coverage Δ
HARK/ConsumptionSaving/ConsMedModel.py 73.99% <ø> (ø)
HARK/ConsumptionSaving/ConsPortfolioFrameModel.py 100.00% <ø> (ø)
HARK/ConsumptionSaving/ConsPrefShockModel.py 79.68% <ø> (ø)
HARK/ConsumptionSaving/ConsIndShockModel.py 86.40% <82.92%> (ø)
HARK/distribution.py 80.70% <90.38%> (-2.40%) ⬇️
HARK/ConsumptionSaving/ConsAggShockModel.py 89.64% <100.00%> (ø)
HARK/ConsumptionSaving/ConsRiskyAssetModel.py 41.03% <100.00%> (ø)
...RK/ConsumptionSaving/tests/test_ConsMarkovModel.py 86.56% <100.00%> (ø)
...K/ConsumptionSaving/tests/test_modelcomparisons.py 98.46% <100.00%> (ø)
HARK/core.py 91.48% <100.00%> (ø)
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

set probability in from_dataset method
DiscreteDistribution returns self
@sbenthall sbenthall added this to the 0.13.0 milestone Jan 4, 2023
@sbenthall sbenthall self-requested a review January 4, 2023 17:45
@alanlujan91 alanlujan91 removed their assignment Jan 7, 2023
@llorracc
Copy link
Collaborator

llorracc commented Jan 7, 2023

Only comment is that I'd like it if the invocations of .discretize (which replace the .approx) were to explicitly specify the method ("equiprobable").

@alanlujan91
Copy link
Member Author

Only comment is that I'd like it if the invocations of .discretize (which replace the .approx) were to explicitly specify the method ("equiprobable").

Ok, right now the default for every distribution is equiprobable except for Normal which has a default of hermite.

@llorracc
Copy link
Collaborator

llorracc commented Jan 9, 2023

OK, I'm happy with this now. (Actually, delighted).

Only two things I can think of:

  1. Update the changelog
  2. Figure out how to test it against the DemARKs BEFORE we merge into master
    • If all the DemARKs break, we will either need to fix them or to change the code so it works with the old code (maybe issuing a deprecation warning)
    • If only a few DemARKs break, they can be fixed

@alanlujan91 alanlujan91 added Ready-To-Merge Has been reviewed and when branch is updated and checks pass it should be merged Status: Review Needed and removed Ready-To-Merge Has been reviewed and when branch is updated and checks pass it should be merged labels Jan 9, 2023
@alanlujan91
Copy link
Member Author

@llorracc the only way I can think of checking this branch against DemARK's is locally. I will try that and see what the results are

@alanlujan91
Copy link
Member Author

@llorracc seems like DemARK's already broke with previous merge so I'll have to go and fix them anyway

"""
Construct a discrete approximation to a lognormal distribution with underlying
normal distribution N(mu,sigma). Makes an equiprobable distribution by
default, but user can optionally request augmented tails with exponentially
sized point masses. This can improve solution accuracy in some models.

TODO: add endpoints option
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an issue for this in the issue tracker?

Are you going to do it in this PR, or leave it to a later release?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking of leaving it for a different PR since I still need to discuss how to do this with the group.

I will make an issue for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

"tail_N": tail_N,
"tail_bound": tail_bound,
"tail_order": tail_order,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be implemented a little more generically using **kwargs to capture the arguments given the discretize method.

https://www.digitalocean.com/community/tutorials/how-to-use-args-and-kwargs-in-python-3

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point. Will think about this and leave it for a different PR.

HARK/distribution.py Outdated Show resolved Hide resolved
HARK/distribution.py Outdated Show resolved Hide resolved
`DiscreteDistribution` is already an approximation, so this method
returns a copy of the distribution.

TODO: print warning message?
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an issue for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will write an issue for this

Copy link
Member Author

Choose a reason for hiding this comment

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

@sbenthall
Copy link
Contributor

Looking good! See review comment inline. Please update the CHANGELOG in this PR.

@alanlujan91
Copy link
Member Author

Changes in this PR:

  • Reorganize Distribution class as seed manager with abstract draw and discretize methods. Random number generator _rng is now a private attribute.
  • New discretize method replaces approx, with parameters N, method, endpoints, and additional keywords. The recommended use is to be explicit about the discretization method being used by setting dist.discretize(N, method = "EXPLICIT"). The endpoints parameter has only been implemented for Uniform distribution so far but it should allow user to add points with infinitesimal probability in the Discrete Distribution.
  • Create new ContinuousFrozenDistribution which allows users to use any scipy.stats continuous distribution on HARK even if they have not been implemented in HARK.
  • All HARK distributions now inherit methods from scipy.stats such as rvs, pdf, cdf, sf, ppf, isf, stats, moment.
  • New Lognormal.discretize(N, method = "hermite") which uses Gauss Hermite method to discretize Lognormal and MeanOneLogNormal.
  • Create new DiscreteFrozenDistribution which allows users to use any scipy.stats discrete distribution on HARK even if they have not been implemented in HARK.
  • DiscreteDistribution and DiscreteDistributionLabeled now take parameter limit to indicate the Continuous Distribution it comes from and the method used for discretization.
  • Implement the use of dist.discretize with explicit method throughout the codebase.

@alanlujan91 alanlujan91 changed the title [WIP] scipy.stats distributions scipy.stats distributions Jan 11, 2023
@alanlujan91 alanlujan91 added the Ready-To-Merge Has been reviewed and when branch is updated and checks pass it should be merged label Jan 11, 2023
@sbenthall sbenthall merged commit 079839a into econ-ark:master Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready-To-Merge Has been reviewed and when branch is updated and checks pass it should be merged Status: Review Needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants