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

Multilevel model tutorial with dynamical systems #542

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

SamWitty
Copy link
Collaborator

@SamWitty SamWitty commented May 1, 2024

This tutorial demonstrates how ChiRho's dynamical systems module composes with existing techniques in Bayesian hierarchical modeling. Specifically, this tutorial shows how to represent joint dependencies between parameters of non-interacting SIR models for different towns, and how ordinary probabilistic inference reflects reasonable intuition about how observations from one stratum inform our predictions for another.

Subsumes #351 .

TODO:

  • Render graphical model
  • Add basic intervention on stratum without observations
  • Clean up figures
  • Add explainer text throughout

@SamWitty SamWitty added documentation Improvements or additions to documentation status:WIP Work-in-progress not yet ready for review module:dynamical labels May 1, 2024
@SamWitty SamWitty self-assigned this May 1, 2024
@SamWitty SamWitty marked this pull request as draft May 1, 2024 13:51
Copy link
Collaborator

Choose a reason for hiding this comment

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

When initializing the cadence of observations, you say:

obs_sample_rate = torch.tensor(1/7) # Take measurements one per week

However, since the timescale is months, not days, it should be

obs_sample_rate = torch.tensor(1/4) # Take measurements one per week

If you meant for the timestep to be days, then it should be:

obs_sample_rate = torch.tensor(7.0) # Take measurements one per week

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the obs_sample_rate is still 1/7, not 1/4.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since time is measured in units of months, a weekly obs_sample rate should be 1/4, not 1/7.

@djinnome
Copy link
Collaborator

djinnome commented Nov 6, 2024

Why is sir_observation_model a recursive function?

Edit: Nevermind. I now see that single_observation_model calls sir_observation_model with one less dimension.

@djinnome
Copy link
Collaborator

djinnome commented Nov 6, 2024

In bayesian_multilevel_sir_prior the variable called plate should be called strata

@SamWitty SamWitty requested review from eb8680 and djinnome and removed request for djinnome January 23, 2025 14:44
@SamWitty SamWitty added status:awaiting review Awaiting response from reviewer and removed status:WIP Work-in-progress not yet ready for review labels Jan 23, 2025
@SamWitty SamWitty marked this pull request as ready for review January 23, 2025 14:44
Copy link
Collaborator

Choose a reason for hiding this comment

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

The prior marginal and conditional distributions of the parameters should be a different color for each town. Currently, they are all the same color. This could be fixed by introducing:

town_colors = ["cyan", "magenta", "chartreuse"]
...
for i in range(3):
    sns.kdeplot(
        parameter_prior_samples['beta'][:, i],
        ax=ax[1,0],
        alpha=0.4,
        color=town_colors[i],
        label=f"Town {i} $\\beta$ - Marginal Probability",
        linewidth=1.5,
        bw_adjust=.6,
        clip=(0, 1),
    )

Copy link
Collaborator

@djinnome djinnome left a comment

Choose a reason for hiding this comment

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

Just a couple minor plotting issues, but otherwise, it looks ready to go.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since time is measured in units of months, a weekly obs_sample rate should be 1/4, not 1/7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation module:dynamical status:awaiting review Awaiting response from reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants