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

Day of the week tutorial #344

Merged
merged 26 commits into from
Aug 21, 2024
Merged

Day of the week tutorial #344

merged 26 commits into from
Aug 21, 2024

Conversation

gvegayon
Copy link
Member

@gvegayon gvegayon commented Jul 30, 2024

Implementation

  • The day-of-the-week [DOW] effect is implemented as a RandomVariable that returns a vector of length 7.
  • The RandomVariable latent.HospitalAdmissions takes care of broadcasting the seven values to match the length of the data (latent infections, in this case).
  • The PR replaces how latent.HospitalAdmissions.sample() is called; instead of passing a latent_infections array, it passes the corresponding SampledValue containing the latent infections.
  • Since SampledValues has t_start, we can correct for the offset of the infections wrt the observed data.
  • In addition, the constructor of latent.HospitalAdmissions receives a new argument indicating what's the first day of the week in the observed data. With the previous point, latent.HospitalAdmissions.sample() properly broadcasts the DOW effect.

The tutorial itself recycles the model built during the "Implementing a Hospital Admissions-only Model".

Draft Notes (not implemented, but here for future reference)

Current state:

  • The day-of-the-week [DOW] effect is applied via latent.HospitalAdmissions.
  • The sampling method of hospital admissions receives latent infections.
  • Those latent infections are a time series equal to the number of observed data points plus the infection seeding process.
  • Since the seeding process extends the observed time series to the left, the resulting broadcasting should account for that.
flowchart LR
   Seeding[Seeding\nprocess] -->|Input to| LatentI[Latent\nInfections]
   LatentI -->|Input to| HospitalAdmissions
   subgraph HospitalAdmissions["HospitalAdmissions.sample()"]
      dow["day_of_week_effect_rv(\n  n_timepoints=latent_hospital_admissions.size\n)"]
   end
Loading

To implement:

  • We would need to pass on the information about t_start resulting from the seeding process.
  • Currently, the seeding process has t_start=self.t_start, both None (see here).
  • The latent infections vector should have t_start=-I0.size.
  • Instead of passing the raw array to latent.HospitalAdmissions, we should pass the SampledValue object with the t_start=-I0.size.
  • With that accessible, instead of passing a n_timepoints to the DOW RV, we could pass the SampledValue latent infections.
  • The DOW RV sample method could then access the t_start and the number of time points to sample and adjust accordingly.
  • The DOW RV object should know what day of the week the first observation of the sample is; this information could be passed during the construction of the DOW RV.
flowchart LR
   Seeding[Seeding\nprocess] -->|Input to| LatentI[Latent\nInfections]
   LatentI -->|Input to| HospitalAdmissions
   subgraph HospitalAdmissions["HospitalAdmissions.sample()"]
      dow["day_of_week_effect_rv(\n  data=latent_hospital_admissions\n)"]
   end
Loading

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 93.06%. Comparing base (f891cb7) to head (249d975).
Report is 1 commits behind head on main.

Files Patch % Lines
src/pyrenew/latent/hospitaladmissions.py 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #344      +/-   ##
==========================================
- Coverage   93.09%   93.06%   -0.03%     
==========================================
  Files          37       37              
  Lines         941      952      +11     
==========================================
+ Hits          876      886      +10     
- Misses         65       66       +1     
Flag Coverage Δ
unittests 93.06% <91.66%> (-0.03%) ⬇️

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.

@gvegayon gvegayon marked this pull request as ready for review August 7, 2024 23:12
@gvegayon gvegayon requested a review from AFg6K7h4fhy2 August 7, 2024 23:12
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.

Thanks @gvegayon! Some required changes and some things open for discussion.

@gvegayon gvegayon requested a review from damonbayer August 13, 2024 23:40
@gvegayon gvegayon requested a review from damonbayer August 16, 2024 15:36
@gvegayon
Copy link
Member Author

Ready for review, @damonbayer and @dylanhmorris.

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.

Looks good. I think we just want to wait for #387 so we can avoid having to define MyDOWEffect.

We could also merge as is and address that later. Your call @gvegayon.

@gvegayon
Copy link
Member Author

Looks good. I think we just want to wait for #387 so we can avoid having to define MyDOWEffect.

We could also merge as is and address that later. Your call @gvegayon.

I'll wait

@damonbayer
Copy link
Collaborator

I'll wait

@gvegayon #387 is merged

@gvegayon
Copy link
Member Author

Just addressed conflicts. Once tests pass, I'll merge.

@gvegayon gvegayon merged commit 144d2b8 into main Aug 21, 2024
6 of 8 checks passed
@gvegayon gvegayon deleted the 304-day-of-the-week-tutorial branch August 21, 2024 15:35
@damonbayer
Copy link
Collaborator

damonbayer commented Aug 21, 2024

@gvegayon The point of waiting for #387 was so that your MyDOWEffect class could be replaced with a TransformedRandomVariable. Please make a new issue for this. I think it could/should be done in this sprint.

@gvegayon
Copy link
Member Author

@gvegayon The point of waiting for #387 was so that your MyDOWEffect class could be replaced with a TransformedRandomVariable. Please make a new issue for this. I think it could/should be done in this sprint.

Yes! Sorry I forgot that. Fixing now

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.

Demonstrate day of the week effect in Time handling in pyrenew tutorial
3 participants