-
-
Notifications
You must be signed in to change notification settings - Fork 988
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
Conversation
# 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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
).
There was a problem hiding this 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.
Thanks for reviewing! |
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.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
sir.py -p 10000 -d 60 -f 30 --plot
as a sanity check