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

Labeled income process #1189

Merged
merged 20 commits into from Jan 4, 2023
Merged

Labeled income process #1189

merged 20 commits into from Jan 4, 2023

Conversation

Mv77
Copy link
Contributor

@Mv77 Mv77 commented Nov 23, 2022

This PR changes the income process constructor in ConsIndShockModel to use @alanlujan91's DiscreteDistributionLabeled class. This:

  • Allows for more expressive code (e.g. shocks[0] becomes shocks['PermShk']) when taking expectations.
  • Might make the code faster, since it uses Alan's vectorized expectation operator.

I have marked it as WIP because I want to extend the change to portfolio models, but tests are currently passing.

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 Nov 23, 2022

Codecov Report

Base: 73.61% // Head: 73.66% // Increases project coverage by +0.05% 🎉

Coverage data is based on head (1f6a416) compared to base (65c76c8).
Patch coverage: 96.36% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1189      +/-   ##
==========================================
+ Coverage   73.61%   73.66%   +0.05%     
==========================================
  Files          73       73              
  Lines       11998    12024      +26     
==========================================
+ Hits         8832     8858      +26     
  Misses       3166     3166              
Impacted Files Coverage Δ
HARK/ConsumptionSaving/ConsRiskyAssetModel.py 41.03% <80.00%> (+0.43%) ⬆️
HARK/distribution.py 83.10% <88.88%> (+0.30%) ⬆️
HARK/ConsumptionSaving/ConsIndShockModel.py 86.50% <100.00%> (ø)
HARK/ConsumptionSaving/ConsMarkovModel.py 85.83% <100.00%> (ø)
HARK/ConsumptionSaving/ConsPortfolioModel.py 89.88% <100.00%> (+0.13%) ⬆️
...RK/ConsumptionSaving/tests/test_ConsMarkovModel.py 86.56% <100.00%> (ø)
...K/ConsumptionSaving/tests/test_modelcomparisons.py 98.46% <100.00%> (ø)
HARK/tests/test_distribution.py 100.00% <100.00%> (ø)

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.

@alanlujan91 alanlujan91 self-requested a review November 23, 2022 15:48
@@ -1192,6 +1192,10 @@ def RNG(self):
"""
return self.dataset.RNG

@RNG.setter
def RNG(self,value):
self.dataset.attrs['RNG'] = value
Copy link
Member

Choose a reason for hiding this comment

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

Should this be np.random.RandomState(value)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure? What does this property do?

I wrote as it is because I thought that the get and set method should deal with exactly the same object. Since the getter is

HARK/HARK/distribution.py

Lines 1188 to 1193 in daf2afd

@property
def RNG(self):
"""
Returns the distribution's random number generator.
"""
return self.dataset.RNG

I wrote the setter to the RNG property directly. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I think this is how we initialize a random state with a seed. When we initialize a DiscreteDsitribution object, we set RNG as follows

attrs["RNG"] = np.random.RandomState(seed)

so I guess we would have to do dist.RNG = np.random.RandomState(seed).

Actually I guess this isn't a problem, you just have to be more explicit that the value parameter should be of type RandomState. Maybe just a type check?

But also if we have a setter for dist.seed = value it should also generate a new RNG.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the typecheck solution.

You did not add a setter for the seed property (I think?) Should I create one? Would that go in a different PR?

Copy link
Member

Choose a reason for hiding this comment

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

It might be useful to have a seed setter. I think it would be fine to go in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alrighty, added a typecheck.

I could not remember why I had to add this setter in the first place, but just ran some tests and found out. The reason was that methods like initialize_sim call Distribution.reset() on things like the income distribution. That method is

def reset(self):
"""
Reset the random number generator of this distribution.
Parameters
----------
"""
self.RNG = np.random.RandomState(self.seed)

So without a setter, it failed

@alanlujan91
Copy link
Member

@Mv77 is this done? I can merge it once you resolve conflicts

@Mv77
Copy link
Contributor Author

Mv77 commented Dec 7, 2022 via email

@Mv77 Mv77 changed the title [WIP] Labeled income process Labeled income process Jan 3, 2023
@Mv77 Mv77 requested a review from alanlujan91 January 3, 2023 17:47
@Mv77
Copy link
Contributor Author

Mv77 commented Jan 3, 2023

This is ready for review and merge if it passes review.

@llorracc I checked locally that it does not break DemARKs. It's much harder to know for REMARKs, but afaik version control for REMARKs is in the works.

@Mv77 Mv77 added Needs: Revision Ready-To-Merge Has been reviewed and when branch is updated and checks pass it should be merged labels Jan 3, 2023
@llorracc
Copy link
Collaborator

llorracc commented Jan 3, 2023

Yes, version control for REMARKs is in the works.

I've asked @sbenthall to work on preparing for a new release (0.13) by the end of this month, and I hope by that time we will have nailed down the status of all the REMARKs: Either pinned to earlier versions of HARK, or added to the tests that are run when new PRs are submitted.

PS. I'm a bit puzzled by the combination of the "Needs: Revision" and the "Ready-To-Merge" labels. Could you clarify what revisions you view as needed? I guess it's hard to see how to keep track of whether we get those revisions done after the PR is merged. Maybe the right approach is to make an "issue" containing the revisions that are needed, and link to the issue in this discussion of the merge request?

@Mv77
Copy link
Contributor Author

Mv77 commented Jan 3, 2023

What I wanted to express was "This is ready from my point of view. It would be good to get someone to look at it. If that someone approves, they can go ahead and merge without further questions."

@llorracc
Copy link
Collaborator

llorracc commented Jan 3, 2023

OK, I guess the right "someone" is @alanlujan91

Alan, go for it!

@sbenthall
Copy link
Contributor

I've removed the "Needs:revision" label.

@sbenthall sbenthall added this to the 0.13.0 milestone Jan 4, 2023
@Mv77 Mv77 merged commit a07e355 into econ-ark:master Jan 4, 2023
@Mv77 Mv77 deleted the plumbing/label-income branch March 17, 2023 13:38
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants