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 a factory for Poisson / NegativeBinomial / Binomial / BetaBinomial #2450

Merged
merged 6 commits into from
Apr 28, 2020

Conversation

fritzo
Copy link
Member

@fritzo fritzo commented Apr 28, 2020

Addresses #2426

This creates a new helper infection_dist() that creates one of a Poisson, NegativeBinomial, Binomial, or BetaBinomial depending on the quantitative values of its arguments. Of these four distributions, I intend only to use the Binomial and BetaBinomial; the others are present more as a bridge to limiting parameterizations that are more common in epidemiology.

image

This PR also refactors the SIR and SEIR models to use the new helper. This refactoring prepares for overdispersed versions of these distributions in a follow-up PR #2451.

Tested

  • refactoring is covered by existing tests
  • added a new unit test confirming approximate agreement in four limiting cases
  • visually validated agreement in a notebook
  • ran sir.py -p 10000 -d 60 -f 30 --plot as a sanity check

# pair of individuals results in an infection at this time step.
p = torch.as_tensor(R / N).clamp(max=1 - 1e-6)
# Combine infections from all individuals.
combined_p = p.neg().log1p().mul(I).expm1().neg() # = 1 - (1 - p)**I
Copy link
Member

Choose a reason for hiding this comment

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

I think this is not consistent w.r.t. before. Previously, combined_p is 1 - (e^-rate_s) ** I = 1 - (e^-p) ** I.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right, I am changing the formula. This PR seems to make it more mathematically plausible.

Copy link
Member Author

Choose a reason for hiding this comment

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

@fehiepsi I am not super confident in these formulas, but the plots do show they are at least in agreement. Let me know if you have any suggestions.

Copy link
Member

@fehiepsi fehiepsi Apr 28, 2020

Choose a reason for hiding this comment

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

This seems to be similar to Reed-Frost model. I agree that this formula seems to be more reasonable when N is small. Two formulas are similar when N is large (when p is small: e^-p ~ 1-p).

Copy link
Member

@fehiepsi fehiepsi left a comment

Choose a reason for hiding this comment

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

The math seems to be consistent to me. For finite or infinite population, the mean of distributions with finite and infinite k are identical. I haven't checked if defining something like combined_k = k * I is plausible.

@martinjankowiak martinjankowiak merged commit cf0f0a8 into dev Apr 28, 2020
@fritzo
Copy link
Member Author

fritzo commented Apr 28, 2020

Thanks for reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants