Skip to content
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

Add helper data PyrenewHEWData class to hold input data to PyrenewHewModels #283

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

dylanhmorris
Copy link
Contributor

@dylanhmorris dylanhmorris commented Jan 8, 2025

Main change

Add PyrenewHEWData

This:

  • facilitates date math
  • removes some if is None conditionals from the main model.sample() code.
  • Has a simple to_forecast_data() transformation helper for posterior prediction.

Additional changes:

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 0% with 109 lines in your changes missing coverage. Please review.

Project coverage is 15.63%. Comparing base (1c2e2cc) to head (d239a47).

Files with missing lines Patch % Lines
pyrenew_hew/pyrenew_hew_data.py 0.00% 67 Missing ⚠️
pyrenew_hew/pyrenew_hew_model.py 0.00% 29 Missing ⚠️
pipelines/build_pyrenew_model.py 0.00% 10 Missing ⚠️
pipelines/generate_predictive.py 0.00% 2 Missing ⚠️
pipelines/fit_pyrenew_model.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #283      +/-   ##
==========================================
- Coverage   15.87%   15.63%   -0.25%     
==========================================
  Files          21       22       +1     
  Lines        1537     1561      +24     
==========================================
  Hits          244      244              
- Misses       1293     1317      +24     
Flag Coverage Δ
hewr 47.68% <ø> (ø)
pipelines 0.00% <0.00%> (ø)
pyrenew_hew 1.59% <0.00%> (-0.07%) ⬇️

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

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

Copy link
Collaborator

@sbidari sbidari left a comment

Choose a reason for hiding this comment

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

This looks mostly good to me. Just few comments/questions for clarification.

pyrenew_hew/pyrenew_hew_model.py Outdated Show resolved Hide resolved
pyrenew_hew/pyrenew_hew_model.py Show resolved Hide resolved
pyrenew_hew/pyrenew_hew_model.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
]

@property
def last_data_dates(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this better as a dictionary?

)

@property
def first_data_dates(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this better as a dictionary?


@property
def first_data_date_overall(self):
return min([x for x in self.first_data_dates if x is not None])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return min([x for x in self.first_data_dates if x is not None])
return min(filter(None, self.first_data_dates))


@property
def last_data_date_overall(self):
return max([x for x in self.last_data_dates if x is not None])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return max([x for x in self.last_data_dates if x is not None])
return max(filter(None, self.last_data_dates))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we prune the data_for_model_fit.json object to only supply the info necessary to create pyrenew_hew_data?

n_init_days = self.latent_infection_process_rv.infection_initialization_process.infection_init_method.n_timepoints
first_latent_infection_dow = (
data.first_data_date_overall - datetime.timedelta(days=n_init_days)
).weekday()

sampled_ed_visits, sampled_admissions, sampled_wastewater = (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Slight preference for

Suggested change
sampled_ed_visits, sampled_admissions, sampled_wastewater = (
sampled_ed_visits = sampled_admissions = sampled_wastewater = None

or

Suggested change
sampled_ed_visits, sampled_admissions, sampled_wastewater = (
sampled_ed_visits = None
sampled_admissions = None
sampled_wastewater = None

Comment on lines +257 to +258
self.ihr_rv = ihr_rv
self.ihr_rel_iedr_rv = ihr_rel_iedr_rv
Copy link
Collaborator

@damonbayer damonbayer Jan 13, 2025

Choose a reason for hiding this comment

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

check that at most one of these is not None?


hospital_admissions_obs_rv = NegativeBinomialObservation(
"observed_hospital_admissions",
concentration_rv=self.hosp_admit_neg_bin_concentration_rv,
)
predicted_admissions = latent_hospital_admissions

sampled_admissions = hospital_admissions_obs_rv(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
sampled_admissions = hospital_admissions_obs_rv(
observed_hospital_admissions = hospital_admissions_obs_rv(

and rename in the return

else:
ihr = self.ihr_rv()

latent_admissions = population_size * ihr * latent_infections
Copy link
Collaborator

Choose a reason for hiding this comment

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

Needs a better name. Or just pass latent_incidence=population_size * ihr * latent_infections in to compute_delay_ascertained_incidence

@@ -227,61 +234,89 @@ def sample(
concentration_rv=self.ed_neg_bin_concentration_rv,
)

observed_ed_visits = ed_visit_obs_rv(
sampled_ed_visits = ed_visit_obs_rv(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
sampled_ed_visits = ed_visit_obs_rv(
observed_ed_visits = ed_visit_obs_rv(

also change the return

@damonbayer damonbayer self-requested a review January 13, 2025 18:11
Copy link
Collaborator

@damonbayer damonbayer left a comment

Choose a reason for hiding this comment

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

Left many comments, none of which are mandatory.

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.

3 participants