Skip to content

Make infection feedback a constructor option of the latent classes; remove infection_process - #906

Merged
dylanhmorris merged 3 commits into
mainfrom
mem_902_infection_process_redo
Oct 19, 2026
Merged

dylanhmorris merged 3 commits into
mainfrom
mem_902_infection_process_redo

Conversation

@cdc-mitzimorris

Copy link
Copy Markdown
Collaborator

PopulationInfections and SubpopulationInfections now compute their renewal step themselves. Infection feedback is a pair of optional constructor arguments, infection_feedback_strength_rv and infection_feedback_pmf_rv. The infection_process argument and the InfectionProcess protocol, added in #847, are removed.

The legacy classes Infections and InfectionsWithFeedback are unchanged (except for one docstring cleanup to mathjax).

What the user writes

Without feedback, nothing changes.

With feedback, before:

builder.configure_latent(
    PopulationInfections,
    ...,
    infection_process=InfectionsWithFeedback(
        name="infections",
        infection_feedback_strength=strength_rv,
        infection_feedback_pmf=feedback_pmf_rv,
    ),
)

After:

builder.configure_latent(
    PopulationInfections,
    ...,
    infection_feedback_strength_rv=strength_rv,
    infection_feedback_pmf_rv=feedback_pmf_rv,
)

SubpopulationInfections takes the same two arguments. Its strength can be a scalar, or have shape (n_subpops,), (n_days_post_init, 1), or (n_days_post_init, n_subpops).

Renamed recorded sites

Before After
{name}::rt_single_effective {name}::rt_single_adjusted
{name}::rt_subpop_effective {name}::rt_subpop_adjusted

rt_single and rt_subpop (raw Rt from the temporal processes) are unchanged. The adjusted Rt is the Rt the renewal equation uses; it equals raw Rt when feedback is off. "Adjusted" matches compute_infections_from_rt_with_feedback, which takes Rt_raw and returns Rt_adjusted.

Behavior

  • Given the same random variables and seed, every recorded value is identical to passing infection_process=InfectionsWithFeedback(...) before this change. This was checked by comparing all trace sites of five configurations, three seeds each, before and after the change.
  • One feedback argument without the other: ValueError at construction.
  • Feedback PMF length differs from the generation interval: ValueError at sample time. Before, this was a shape error from jnp.einsum.
  • Strength that does not broadcast to the shape of Rt: ValueError naming both shapes.
  • infection_process passed: TypeError at construction; through PyrenewBuilder, at build().
  • Extra keyword arguments to sample are unused.

Changes

  • pyrenew/latent/base.py: private helpers _validate_feedback_options and _compute_renewal.
  • pyrenew/latent/population_infections.py, subpopulation_infections.py: new constructor arguments, renewal through _compute_renewal, renamed sites, docstrings describing feedback.
  • pyrenew/latent/infection_process.py, __init__.py: InfectionProcess removed; InfectionProcessSample kept for the legacy classes.
  • Tests: tests of the removed argument removed; feedback tests rewritten for the new arguments; new tests for equivalence with InfectionsWithFeedback, zero strength, per-subpopulation strength, and each error. Factory fixtures in test/conftest.py.

Breaking change

infection_process, InfectionProcess, and the _effective sites were added in #847 and are in no tagged release.

@cdc-mitzimorris

Copy link
Copy Markdown
Collaborator Author

will close #902

@github-actions

github-actions Bot commented Oct 12, 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-10-22T00:04:46Z. You can re-generate it by re-running the workflow here.)

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.84%. Comparing base (0bd0853) to head (1a41c7e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #906   +/-   ##
=======================================
  Coverage   98.84%   98.84%           
=======================================
  Files          59       58    -1     
  Lines        2242     2249    +7     
=======================================
+ Hits         2216     2223    +7     
  Misses         26       26           
Flag Coverage Δ
unittests 98.84% <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
cdc-mitzimorris changed the base branch from main to mem_bugfix_903_subpop_scaling October 13, 2026 22:22
@cdc-mitzimorris
cdc-mitzimorris changed the base branch from mem_bugfix_903_subpop_scaling to main October 13, 2026 22:24
@cdc-mitzimorris
cdc-mitzimorris force-pushed the mem_902_infection_process_redo branch from 739a742 to 8158533 Compare October 14, 2026 22:19
@cdc-mitzimorris
cdc-mitzimorris marked this pull request as ready for review October 14, 2026 22:19
@cdc-mitzimorris

Copy link
Copy Markdown
Collaborator Author

@dylanhmorris now ready for review

Comment thread pyrenew/latent/base.py

@dylanhmorris dylanhmorris left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks @cdc-mitzimorris. Apologies for the slow review.

@dylanhmorris
dylanhmorris merged commit 2801946 into main Oct 19, 2026
8 checks passed
@dylanhmorris
dylanhmorris deleted the mem_902_infection_process_redo branch October 19, 2026 21:23
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