[WIP] Class representing discretized transitions#1548
[WIP] Class representing discretized transitions#1548Mv77 wants to merge 2 commits intoecon-ark:mainfrom
Conversation
|
This is a work in progress, do not merge yet. I need to, for example, add tests. |
|
I finally had a chance to look at this. Main comments are related to both prongs of For the infinite horizon version, you don't need to loop on For the lifecycle model, your steady state age distribution is wrong. You can't just take the cumulative survival probabilities and normalize them, because that ignores death and replacement. Instead, make a square array A of "age transitions", with two non-zero elements in each row: A_{i,i+1} = LivPrb_i and A_{i,0} = 1-LivPrb_i. Just like above, take the transpose of A, then find the eigenvector associated with its largest eigenvalue and normalize it. That's the steady state age distribution. Your survival-conditional state distributions are correct. See L168-202 of estimation.py in the DistributionOfWealthMPC REMARK for where this was done in cstwMPC, but note that when I wrote the function there, I didn't know that the largest eigenvalue is always 1 and/or EDIT: Ignore that last paragraph, it's wrong. |
|
Addendum to the above: The lifecycle method assumes that you want a constant population, with newborns exactly replacing decedents. If you instead want a constant growth rate of the population, the math is slightly different (but you can probably work it out). |
|
Hit pause on my comment about the steady state age distribution. Normalized cumulative survival probabilities and the first normalized eigenvector might be equivalent. I'm on a train right now and can't check. |
|
Yeah nevermind, the methods are equivalent. |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces the DiscreteTransitions class for simulating population transitions in discretized state spaces for both life-cycle and infinite-horizon models. Key changes include the addition of a new dataclass with methods to iterate distributions forward, calculate conditional age distributions, and compute steady-state distributions.
| ) | ||
| else: | ||
| return _iterate_dstn_forward_ih( | ||
| dstn_init[0], self.living_tmat[0], self.surv_prob[0], self.newborn_dstn |
There was a problem hiding this comment.
In infinite-horizon mode, the properties 'self.living_tmat' and 'self.surv_prob' are referenced, but the class defines 'living_tmats' and 'surv_probs'. Please update the variable names to ensure consistency.
| dstn_init[0], self.living_tmat[0], self.surv_prob[0], self.newborn_dstn | |
| dstn_init[0], self.living_tmats[0], self.surv_probs[0], self.newborn_dstn |
| The class assumes that: | ||
| - Death is exogenous and independent of every state. | ||
| - Agents that die are replaced by newborns. | ||
| - Newborns draw their state from a distribution that is constatn over time. |
There was a problem hiding this comment.
Correct the typo 'constatn' to 'constant'.
| - Newborns draw their state from a distribution that is constatn over time. | |
| - Newborns draw their state from a distribution that is constant over time. |
I'm making public versions of a few methods that I have used to work for simulations with discretized/matrix transitions.
The idea is to have a simple class that holds all the ingredients needed to, say, find the steady state distribution of an infinite horizon or life-cycle model, or to iterate a distribution forward a single time period.
Ideally, people will use this and make it more efficient and find useful sparse representations and who knows what else.