Skip to content

Use NumPyro's ZeroSumTransform for latent subpopulation infections. - #936

Open
cdc-mitzimorris wants to merge 79 commits into
mainfrom
mem_935_zero_sum_transform
Open

cdc-mitzimorris wants to merge 79 commits into
mainfrom
mem_935_zero_sum_transform

Conversation

@cdc-mitzimorris

@cdc-mitzimorris cdc-mitzimorris commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Replace mean subtraction with NumPyro’s ZeroSumTransform, sampling K - 1 trajectories for K subpopulations.

  • Preserve the existing deviation priors and support both state and innovation parameterizations.
  • Validate shared scalar process parameters and skip deviation sampling for a single subpopulation.
  • Add tests for prior equivalence, initialization, timing, and forecast replay.
  • Add integration tests for hospital–wastewater and mobility case–death models.
  • Update tutorials and API documentation.

Suggested review sequence:

  • Start with the implementation: temporal_processes.py:1021 (pyrenew/latent/temporal_processes.py:1021) samples K - 1 trajectories and applies NumPyro’s ZeroSumTransform to produce K zero-sum deviations. BaseSubpopulationInfections:132 (pyrenew/latent/subpopulation_infections.py:132) applies this to both subpopulation infection classes, replacing mean subtraction.
  • Review the tests: unit tests (test/test_zero_sum_deviations.py:55) cover the constraint, prior covariance, timing, and forecasting. New integration tests cover the tutorial’s hospital–wastewater model (test/integration/test_subpopulation_infections_hw.py:1) and a synthetic mobility model with cases and deaths (test/integration/test_mobility_subpopulation_infections_cases_deaths.py:1).
  • Finish with the documentation: Minor edits to the subpopulation tutorial (docs/tutorials/latent_subpopulation_infections.qmd:254) explain the new construction and its unchanged regional variance.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Thank you for your contribution @cdc-mitzimorris 🚀! Your github-pages is ready for download 👉 here 👈!
(The artifact expires on 2026-11-30T15:48:38Z. You can re-generate it by re-running the workflow here.)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Process reassignment can bypass the zero-sum constraint, already-adapted processes cannot be reused, and overly strict test tolerances can reject valid float32 results.

3 open issues
What changed in this PR

This PR replaces mean-centering in PyRenew’s subpopulation infection models with NumPyro’s ZeroSumTransform, sampling K - 1 coordinate trajectories for K regions while preserving the existing deviation priors.

Changes:

  • Supports both temporal parameterizations, validates shared scalar parameters, and skips deviation sampling for a single subpopulation.
  • Adds prior, initialization, timing, and forecast tests, including hospital–wastewater and mobility case–death integrations.
  • Updates documentation and test dependencies, including guidance to rerun previously saved fits.
File Description
uv.lock Records the added test-analysis dependencies.
test/​test_zero_sum_deviations.py Tests coordinates, prior equivalence, timing, replay, and parameter validation.
test/​test_subpopulation_infections.py Updates rejection tests for unsupported deviation processes.
test/​test_rt_initialization.py Adjusts initialization and calendar expectations for coordinate sampling.
test/​integration/​test_subpopulation_infections_hw.py Adds hospital–wastewater fitting, diagnostics, and forecast tests.
test/​integration/​test_mobility_subpopulation_infections_cases_deaths.py Adds synthetic mobility fitting, recovery, and forecast tests.
test/​integration/​conftest.py Adds tutorial-data and hospital–wastewater model fixtures.
pyrenew/​latent/​temporal_processes.py Implements zero-sum adapters and scalar parameter checks.
pyrenew/​latent/​subpopulation_infections.py Integrates adapted deviations and updates API docstrings.
pyrenew/​latent/​mobility_subpopulation_infections.py Documents the supported deviation processes and parameters.
pyproject.toml Declares analysis dependencies and updates dependency-check exceptions.
docs/​tutorials/​latent_subpopulation_infections.qmd Explains coordinate sampling, prior preservation, and refitting requirements.
docs/​tutorials/​latent_mobility_infections.qmd Documents the shared representation and saved-fit migration.

Review effort: Max

Comment thread pyrenew/latent/temporal_processes.py Resolved
Comment thread test/test_zero_sum_deviations.py Resolved
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.96%. Comparing base (0570596) to head (5f1e4e9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #936      +/-   ##
==========================================
+ Coverage   98.95%   98.96%   +0.01%     
==========================================
  Files          59       59              
  Lines        2395     2427      +32     
==========================================
+ Hits         2370     2402      +32     
  Misses         25       25              
Flag Coverage Δ
unittests 98.96% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cdc-mitzimorris

Copy link
Copy Markdown
Collaborator Author

@SamuelBrand1 - can you review? added a suggested review sequence to the issue description.

This branch has not been deployed

No deployments
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.

2 participants