Repository navigation
Add latent infection class "MobilitySubpopulationInfections" for contact-mixing models - #909
Merged
Merged
Conversation
Collaborator
|
Also tagging @KOVALW, @paigemiller, and @confunguido for awareness (no need to review/comment unless you feel inspired) |
Co-authored-by: Dylan H. Morris <dylanhmorris@users.noreply.github.com>
…PyRenew into mem_901_mobility_subpopulations
for more information, see https://pre-commit.ci
Co-authored-by: Dylan H. Morris <dylanhmorris@users.noreply.github.com>
Co-authored-by: Dylan H. Morris <dylanhmorris@users.noreply.github.com>
Co-authored-by: Dylan H. Morris <dylanhmorris@users.noreply.github.com>
for more information, see https://pre-commit.ci
Co-authored-by: Dylan H. Morris <dylanhmorris@users.noreply.github.com>
Co-authored-by: Dylan H. Morris <dylanhmorris@users.noreply.github.com>
for more information, see https://pre-commit.ci
…PyRenew into mem_901_mobility_subpopulations
Co-authored-by: Dylan H. Morris <dylanhmorris@users.noreply.github.com>
Co-authored-by: Dylan H. Morris <dylanhmorris@users.noreply.github.com>
…PyRenew into mem_901_mobility_subpopulations
Collaborator
Author
|
@dylanhmorris - ready for re-review.
|
|
|
||
| $$ | ||
| I_{t,i} = \sum_{j=1}^{n} \frac{m_{ji}\, S_{t,i}}{\sum_{l=1}^{n} m_{jl} N_l}\; R_{t,j} \left[ \sum_{k=1}^{n} m_{jk} \sum_{\tau} I_{\tau,k}\, g_{t-\tau} \right] | ||
| I_{t,i} = \sum_{j=1}^{n} \frac{m_{ji}\, S_{t,i}}{\sum_{l=1}^{n} m_{jl} N_l}\; R_j(t) \left[ \sum_{k=1}^{n} m_{jk} \sum_{\tau} I_{\tau,k}\, g_{t-\tau} \right] |
| - $N_k$ is the number of residents of region $k$ | ||
| - $S_{t,i}$ is the number of residents of region $i$ not infected before day $t$ | ||
| - $R_{t,j}$ is the reproduction number at location $j$, where transmission happens | ||
| - $R_j(t)$ is the reproduction number at location $j$, where transmission happens |
| With this ordering, the vector-matrix product pairs each day's infections with the generation-interval probability for that many days back, so `infectiousness` is the per-region weighted sum of recent new infections per resident. | ||
| - `cumulative` is the share of each region's residents infected before today, summed over every earlier day starting with the first day of the initialization period. | ||
| - `new_infections` is capped at `susceptible`. | ||
| - `rt` multiplies at each location, because $R_j(t)$ describes transmission where it happens. |
dylanhmorris
approved these changes
Oct 28, 2026
dylanhmorris
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, thanks @cdc-mitzimorris!
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
MobilitySubpopulationInfections: subpopulations are home regions whose residents spend part of each day at other locations, coupled by a fixed mobility matrix.infection_process#902log_rt_time_0_rvgive each subpopulation its own starting Rt #905Code
In file
pyrenew/latent/infection_functions.pyadds a new functioncompute_infections_from_rt_with_mobilitywhich does ajax.lax.scanover a private_mobility_renewal_step.With
M = mobility_matrixandp = subpop_fractions, one day is:pyrenew/latent/subpopulation_infections.py: abstractBaseSubpopulationInfectionsextracted fromSubpopulationInfections.I0and starting log Rt handling,validate, andsample._infections_from_rt.SubpopulationInfectionskeeps the infection feedback options. Its behavior and error order are unchanged.I0_rvdocstrings now say "new infections per resident on the first day of the initialization period", not "prevalence".pyrenew/latent/mobility_subpopulation_infections.py(new):mobility_matrix_rvmust be aDeterministicVariable.mobility_matrix[j, k]is the fraction of residents of regionkpresent at locationj, so each column sums to 1.susceptible_depletion: bool = True, as in Eq 2. WithFalse,rt_subpopabsorbs depletion.TypeError.rt_subpop[t, j]is the Rt at locationj. After initialization,rt_subpop_adjusted = rt_subpop * (share_present @ susceptible_fraction).susceptible_fraction, shape(n_initialization_points + n_days_post_init, n_subpops), starting at 1 and non-increasing, whether depletion is on or off._parse_and_validate_fractions: the matrix shape matchessubpop_fractions(always checked), and every location has people present,M @ p > 0(skipped under tracing).run()performs both checks throughvalidate_databefore MCMC starts.pyrenew/latent/__init__.pyexportsBaseSubpopulationInfections,MobilitySubpopulationInfections, andcompute_infections_from_rt_with_mobility.Tests
test/test_infection_functions.py:test/test_mobility_subpopulation_infections.py(new):SubpopulationInfections, for both a scalar and a per-region starting Rt.susceptible_fractionandrt_subpop_adjustedare correct.validate_dataandrunreject bad inputs before MCMC starts.test/test_interface_coverage.py: three interface tests for the new class.test/test_subpopulation_infections.py: not edited by this change; it is the regression check for the base class extraction.test/conftest.py, including the Roy et al. Fig 2b matrix and populations.Docs
docs/tutorials/latent_mobility_infections.qmd, forward simulation only:latent_subpopulation_infections.qmd, and navigation entries indocs/index.mdanddocs/tutorials/.pages.