-
-
Notifications
You must be signed in to change notification settings - Fork 152
Add explicit preTP boundary objects to fix aggregate indexing #1117
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
Draft
SeaCelo
wants to merge
5
commits into
PSLmodels:master
Choose a base branch
from
SeaCelo:feature/pr1073-pretp-boundary
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
33c2a68
Add explicit preTP boundary objects to fix aggregate indexing
SeaCelo c25e37a
Apply ruff format to test_pretp_boundary
SeaCelo 52a257e
Limit aggregates boundary overrides to mortality and immigration
SeaCelo 798835d
Merge branch 'PSLmodels:master' into feature/pr1073-pretp-boundary
SeaCelo 6bbbd58
Declare preTP fields in default_parameters.json so downstream callers…
SeaCelo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SeaCelo Isn't the appending of$g_{n,preTP}$ inconsistent with Equation 173, which would have ${ g_{n,1},...g_{n,T} }$ in the denominator?
Maybe that equation is incorrect, but I can't see it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jdebacker . The change you noted is mostly to have a naming symmetry, not an actual change in the indexing. This is how I was thinking about it in this PR:
The first row of the TPI bequest calculation uses the pre-time-path population distribution. For the row to be internally consistent, the mortality and growth rate in it need to describe the same transition — pre-period into the first model period — so all three inputs refer to the same year boundary. Here is what each input is, before and after this PR:
p.omega_S_preTP(preTP)p.omega_S_preTP(unchanged)p.rho[0, :](period 0→1)p.rho_preTP(preTP→0)p.g_n[0](preTP→0)p.g_n_preTP(preTP→0)In that reading,$\tilde{g}_{n,1}$ in the equation's notation: the growth rate from the pre-period into the first TPI period.
g_n_preTPis not an additional term before the sequence in Eq. 173. It is the first term in that sequence,In the default flow,
g_n_preTPandg_n[0]come from the same source (g_n_path[0]indemographics.py). Sonp.hstack((g_n_preTP, g_n[1:p.T]))evaluates to the same vector as master'sp.g_n[:p.T]. No numerical change to the equation.The numerical fix in this PR is on
rho_preTP(andimm_rates_preTPinget_B) — those are the boundary fields master had pointing at the wrong year. Master'sg_n[0]was already correct. Theg_n_preTPrename is naming symmetry: all three boundary inputs read as named fields rather than mixing*_preTPwith[0]indexing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One source of why I was confused at first was the math-to-code mapping
I'm reading the theory equation as using model-period notation, where the first TPI bequest period has denominator$\tilde{g}_{n,1}$ . In Python, that same transition is zero-indexed and historically lives at
p.g_n[0], because it is the growth from the pre-period population intoomega[0]. The next transition, first-TPI-period to second-TPI-period, isp.g_n[1].g_n_preTP/ historicallyp.g_n[0]p.g_n[1]p.g_n[T-1]That's why$\lbrace \tilde{g}_{n,1}, \ldots, \tilde{g}_{n,T} \rbrace$ .
np.hstack((g_n_preTP, g_n[1:p.T]))is the code equivalent ofThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SeaCelo I do think there is a misunderstanding. Let me see if I can clarify.
In the${ g_{n,1},...g_{n,T} }$ . But also in
masterbranch, the indexing should beg_n[0:p.T]=master, sincedemographics.pydoesn't return ag_n_preTPwe are assuming thatg_n[0]=g_n_preTP.PR #1073 tries to avoid making that assumption be explicitly computing
g_n_preTP. Sog_n_preTPis the growth rate in the population from the year before the model start year andg[0]=$g_{n,1}$ is the growth rate in the first period of the model.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jdebacker. You're right that equation 173's denominator is
{g_{n,1}, ..., g_{n,T}}— no preTP term. The hstack I added was a cosmetic rename ofp.g_n[0]and didn't change any numbers, but it does make the PR look like it's taking a position on the broaderg_ncontract, which isn't the goal here.I'll narrow the change. The PR's only boundary overrides will be on mortality and immigration — the two inputs master was getting from the wrong year. Growth stays exactly as master wrote it. Concretely:
p.g_n[:p.T]get_Bandget_BQ) to usep.g_n[0]directlyg_n_preTPas a returned field fromget_pop_objs(symmetric withrho_preTPandimm_rates_preTP), butaggregates.pywon't read itWill push the narrower diff shortly.