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

Tool to find the distribution of a function of a R.V. #1144

Merged
merged 5 commits into from
May 13, 2022

Conversation

Mv77
Copy link
Contributor

@Mv77 Mv77 commented May 9, 2022

Imagine x is a DiscreteDistribution object and you want to find the distribution of f(x) for some f.

This pr introduces a tool called distr_of_function. distr_of_function(x, f) will return a DiscreteDistribution object that represents the distribution of f(x). I wrote tests and made it work for f: 1->1, f: n->1, f: 1->n, and f: n->m. You only need f to return a np.array.

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.

@Mv77
Copy link
Contributor Author

Mv77 commented May 9, 2022

I see this being useful as we move toward the representation of models using transition equations.

Imagine I'm in period t and have:

  • A function for v[t+1] and its derivatives
  • A distribution for t+1 shocks ShockDstn.
  • A transition equation such that state[t+1] = transition(shocks, state[t]).

One could do something like FutureStateDstn = distr_of_function(ShockDstn, transition, state[t]). And then with calc_expectations compute the things we usually need, say, calc_expectations(FutureStateDstn, dvdm[t+1]).

@Mv77
Copy link
Contributor Author

Mv77 commented May 9, 2022

@sbenthall could you review? This is heavily inspired on your calc_expectations tool, which I am a huge fan of.

@codecov-commenter
Copy link

Codecov Report

Merging #1144 (21c6e21) into master (0bec58f) will increase coverage by 0.07%.
The diff coverage is 100.00%.

❗ Current head 21c6e21 differs from pull request most recent head b9a4377. Consider uploading reports for the commit b9a4377 to get more accurate results

@@            Coverage Diff             @@
##           master    #1144      +/-   ##
==========================================
+ Coverage   73.99%   74.07%   +0.07%     
==========================================
  Files          70       70              
  Lines       10776    10809      +33     
==========================================
+ Hits         7974     8007      +33     
  Misses       2802     2802              
Impacted Files Coverage Δ
HARK/distribution.py 85.39% <100.00%> (+0.30%) ⬆️
HARK/tests/test_distribution.py 100.00% <100.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 0bec58f...b9a4377. Read the comment docs.

@sbenthall sbenthall self-assigned this May 11, 2022
@sbenthall
Copy link
Contributor

Yes, I can review this.

@sbenthall
Copy link
Contributor

Looks great! Merging now...

@sbenthall sbenthall merged commit e865ae6 into econ-ark:master May 13, 2022
@Mv77 Mv77 deleted the plumbing/dist_of_func branch May 16, 2022 12:45
@sbenthall sbenthall added this to the 0.13.0 milestone Jan 4, 2023
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