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 SIR model with unknown time of initial infection #2460

Merged
merged 9 commits into from
May 5, 2020

Conversation

fritzo
Copy link
Member

@fritzo fritzo commented May 1, 2020

Addreses #2426

This adds an UnknownStartSIRModel that models infections over pre_window + duration many time steps. During the initial pre_window-many steps there are zero observed infections but possible "spontaneous" infections from an external source, at a poisson rate of 1 / pre_window.

To make this model realistic I've also assumed two different detection rates: rho0 up until the first infection and rho1 thereafter. This new inhomogeneous functionality requires a new Index(-)[-] helper similar to our older Vindex(-)[-]. I plan to follow this up with another model with heterogeneous parameters for both of R0 and rho, possibly following brownian motion; this model will make heavier use of Index(-)[-].

Tested-

  • unit tests for UnknownStartSIRModel
  • unit tests for Index(-)[-]

@fritzo fritzo requested a review from fehiepsi May 2, 2020 05:35
@fritzo
Copy link
Member Author

fritzo commented May 2, 2020

@fehiepsi would you mind reviewing the Index logic?

Copy link
Collaborator

@martinjankowiak martinjankowiak left a comment

Choose a reason for hiding this comment

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

looks reasonable.

didn't review index magic.

pyro/contrib/epidemiology/sir.py Outdated Show resolved Hide resolved
pyro/contrib/epidemiology/sir.py Outdated Show resolved Hide resolved
self.pre_window = pre_window
self.post_window = len(data)

# Expect a single external infection during the pre_window.
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please explain this assumption?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

# after observations were made (in post_window).
rho0 = pyro.sample("rho0", dist.Uniform(0, 1))
rho1 = pyro.sample("rho1", dist.Uniform(0, 1))
rho = torch.cat([
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment on shape of rho?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

S2I = pyro.sample("S2I_{}".format(t),
infection_dist(individual_rate=R0 / tau,
num_susceptible=state["S"],
num_infectious=state["I"] + X,
Copy link
Collaborator

Choose a reason for hiding this comment

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

i guess the X contribution is active at all times?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. That modeling decision seems more parsimonious, simpler to code, and quantitatively close to the alternative (one initial infection at an unknown time) because during an outbreak, new infections should be dominated by local internal infections.

:rtype: dict
"""
samples = super().predict(forecast)
samples["first_infection"] = samples["I"].cumsum(-1).eq(0).sum(-1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please comment on this quantity?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

martinjankowiak
martinjankowiak previously approved these changes May 4, 2020
pyro/contrib/epidemiology/sir.py Outdated Show resolved Hide resolved
@martinjankowiak martinjankowiak merged commit 337f162 into dev May 5, 2020
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