Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 15, 2025

Hospitalization was being sampled daily during the rash period. This PR changes it to pre-compute which agents will be hospitalized at simulation start, making the parameter easier to interpret as a true rate.

Model changes

  • Add hospitalize_if_infected vector pre-computed in reset() using the hospitalization rate parameter
  • m_update_rash and m_update_isolated now check this vector when recovering from rash:
    • If marked → transition to Hospitalized
    • Otherwise → transition to Recovered
  • Applied to ModelMeaslesMixingRiskQuarantine, ModelMeaslesMixing, ModelMeaslesSchool

Transition probability changes

Old (daily competing hazard):

Rash → Hospitalized = Hospitalization rate
Rash → Recovered = 1 - (1/RashPeriod + HospitalizationRate)

New (deterministic at recovery):

Rash → Hospitalized = (1/RashPeriod) × HospitalizationRate
Rash → Recovered = (1/RashPeriod) × (1 - HospitalizationRate)

Notes

  • Prodromal → Hospitalized transitions were already absent; no code changes needed there
  • Test expectations updated to match new probability calculations
Original prompt

This section details on the original issue you should resolve

<issue_title>Change how hospitalization works in measles</issue_title>
<issue_description>The current version of the measles models sets the hospitalization rate as a daily rate. A more sensible thing would be, like we do with quarantine willingness, to pre-compute the numbers at the beginning of each run, so these are easier to map. In other words, what we need is:

  • At the beginning of the simulation, sample which agents, if infected, will become hospitalized. This can take place during the reset() method. Who gets hospitalized can be stored as a std::vector< bool > private object that is redifine at the beginning of each simulation.
  • During the simulation, instead of sampling whether they will recover from the rash or not, they will automatically transition to the hospitalized state once they "recover" from the rash. In other words, the transition from rash will either be "Recovered" or "Hospitalized".

Another important thing that we currently have in the model (I think all): we allow the transition from prodromal to hospitalized. To make things simpler, we just want to allow for transitions from rash to hospitalized; from prodromal to hospitalized should be a rare case.

This PR would require modifying the tests that involve transition matrices. As the transition from prodromal to hospitalized should now be zero.</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: cpp_statistician
An expert in statistical analysis and modeling developer using C++.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…mpling

- Add `hospitalize_if_infected` vector to ModelMeaslesMixingRiskQuarantine,
  ModelMeaslesMixing, and ModelMeaslesSchool
- Pre-compute hospitalization status in reset() method for each agent
- Modify m_update_rash and m_update_isolated to use pre-computed vector:
  agents either go to Hospitalized or Recovered when recovering from rash
- Update test files to reflect new transition probability calculations:
  Rash→Hospitalized = (1/RashPeriod) × HospitalizationRate
  Rash→Recovered = (1/RashPeriod) × (1 - HospitalizationRate)

Co-authored-by: gvegayon <893619+gvegayon@users.noreply.github.com>
Copilot AI changed the title [WIP] Change hospitalization process in measles models Change hospitalization in measles models to pre-computed assignment Dec 15, 2025
Copilot AI requested a review from gvegayon December 15, 2025 23:45
@github-actions
Copy link

Thank you for your contribution @gvegayon 🚀! Your documentation-site-pr-143 is ready for download 👉 here 👈!
(The artifact expires on 2026-03-16T18:57:25Z. You can re-generate it by re-running the workflow here.)

@gvegayon gvegayon marked this pull request as ready for review December 16, 2025 18:58
@gvegayon gvegayon requested a review from Copilot December 16, 2025 18:58
@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.47%. Comparing base (e338e64) to head (8e85305).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #143      +/-   ##
==========================================
- Coverage   88.53%   88.47%   -0.06%     
==========================================
  Files          53       53              
  Lines        4647     4623      -24     
==========================================
- Hits         4114     4090      -24     
  Misses        533      533              

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request changes how hospitalization works in measles models by pre-computing hospitalization outcomes at simulation initialization rather than sampling daily during the rash period. This makes the hospitalization rate parameter more interpretable as a true population-level rate rather than a competing hazard probability.

Key changes:

  • Added hospitalize_if_infected boolean vector to all three measles models, sampled once during reset() based on the hospitalization rate parameter
  • Modified m_update_rash and m_update_isolated update functions to check pre-computed hospitalization status deterministically when agents recover from rash
  • Updated test expectations to reflect new probability model where hospitalization is determined at recovery rather than competing daily with recovery

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
include/epiworld/models/measlesschool.hpp Added hospitalize_if_infected vector, pre-computed in reset(), and modified rash/isolated update functions to use it deterministically
include/epiworld/models/measlesmixing.hpp Same pattern as measlesschool, plus added getter method for hospitalization vector and replaced resize()+std::fill() with assign()
include/epiworld/models/measlesmixingriskquarantine.hpp Same pattern as other models but with bug: hospitalization from isolated state ignores unisolate flag
epiworld.hpp Single header file reflecting all changes from individual headers, including the same bug in ModelMeaslesMixingRiskQuarantine
tests/14a-measles.cpp Updated probability calculations and fixed incorrect state labels in comments (prodromal→rash, rash→isolated)
tests/14b-measles.cpp Updated probability calculations and fixed incorrect state labels in comments
tests/19a-measles-mixing.cpp Updated probability calculations for new competing hazard model
tests/19b-measles-mixing.cpp Updated probability calculations for new competing hazard model
tests/20a-measles-mixing-risk-quarantine-basic.cpp Updated probability calculations for new competing hazard model
tests/20b-measles-mixing-risk-quarantine-transitions.cpp Updated probability calculations and transition expectations

// Check pre-computed hospitalization: if marked, go to hospitalized
if (model->hospitalize_if_infected[p->get_id()])
{
p->change_state(m, DETECTED_HOSPITALIZED);
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The hospitalization transition from isolated state should respect the unisolate flag. When unisolate is true, the agent should transition to HOSPITALIZED, not DETECTED_HOSPITALIZED. This is inconsistent with the implementations in ModelMeaslesSchool and ModelMeaslesMixing, which both use a ternary operator to check unisolate.

Suggested change
p->change_state(m, DETECTED_HOSPITALIZED);
p->change_state(m, unisolate ? HOSPITALIZED : DETECTED_HOSPITALIZED);

Copilot uses AI. Check for mistakes.
// Check pre-computed hospitalization: if marked, go to hospitalized
if (model->hospitalize_if_infected[p->get_id()])
{
p->change_state(m, DETECTED_HOSPITALIZED);
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The hospitalization transition from isolated state should respect the unisolate flag. When unisolate is true, the agent should transition to HOSPITALIZED, not DETECTED_HOSPITALIZED. This is inconsistent with the implementations in ModelMeaslesSchool and ModelMeaslesMixing, which both use a ternary operator to check unisolate.

Suggested change
p->change_state(m, DETECTED_HOSPITALIZED);
p->change_state(m, unisolate ? HOSPITALIZED : DETECTED_HOSPITALIZED);

Copilot uses AI. Check for mistakes.
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.

Change how hospitalization works in measles

2 participants