-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from garethjns/imperfect_immunity
Update readme, tidy
- Loading branch information
Showing
20 changed files
with
479 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ matplotlib | |
imageio | ||
dataclasses | ||
seaborn | ||
tqdm | ||
joblib | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Run a single population for 2 years with imperfect immunity and limited test rate.""" | ||
|
||
from joblib import Parallel, delayed | ||
|
||
from social_distancing_sim.disease.disease import Disease | ||
from social_distancing_sim.population.graph import Graph | ||
from social_distancing_sim.population.healthcare import Healthcare | ||
from social_distancing_sim.population.observation_space import ObservationSpace | ||
from social_distancing_sim.population.population import Population | ||
|
||
|
||
def run_and_replay(pop, *args, **kwargs): | ||
pop.run(*args, **kwargs) | ||
if save: | ||
pop.replay(duration=duration) | ||
|
||
|
||
if __name__ == "__main__": | ||
save = True | ||
duration = 0.1 | ||
|
||
common_args = {'plot_ts_fields_g2': ["Mean immunity (of immune nodes)", | ||
"Mean immunity (of all alive nodes)"], | ||
'plot_ts_obs_fields_g2': ["Known mean immunity (of immune nodes)", | ||
"Known mean immunity (of all alive nodes)"], | ||
'observation_space': ObservationSpace(graph=Graph(community_n=50, | ||
community_size_mean=15, | ||
community_p_in=0.08, | ||
community_p_out=0.04), | ||
test_rate=0.05), | ||
'healthcare': Healthcare(capacity=200)} | ||
|
||
pop_low_immunity = Population(name="Low immunity population", | ||
disease=Disease(name='COVID-19', | ||
virulence=0.005, | ||
recovery_rate=0.99, | ||
immunity_mean=0.66, | ||
immunity_decay_mean=0.1), | ||
**common_args) | ||
|
||
pop_high_immunity = Population(name="High immunity population", | ||
disease=Disease(name='COVID-19', | ||
virulence=0.005, | ||
recovery_rate=0.99, | ||
immunity_mean=0.98, | ||
immunity_decay_mean=0.01), | ||
**common_args) | ||
|
||
Parallel(n_jobs=2, | ||
backend='loky')(delayed(run_and_replay)(pop, | ||
steps=750, | ||
plot=False, | ||
save=True) for pop in [pop_low_immunity, pop_high_immunity]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Run a single population for 2 years with imperfect immunity and limited test rate.""" | ||
|
||
from joblib import Parallel, delayed | ||
|
||
from social_distancing_sim.disease.disease import Disease | ||
from social_distancing_sim.population.graph import Graph | ||
from social_distancing_sim.population.healthcare import Healthcare | ||
from social_distancing_sim.population.observation_space import ObservationSpace | ||
from social_distancing_sim.population.population import Population | ||
|
||
|
||
def run_and_replay(pop, *args, **kwargs): | ||
pop.run(*args, **kwargs) | ||
if save: | ||
pop.replay(duration=duration) | ||
|
||
|
||
if __name__ == "__main__": | ||
save = True | ||
duration = 0.1 | ||
|
||
common_args = {'plot_ts_fields_g2': ["Mean immunity (of immune nodes)", | ||
"Mean immunity (of all alive nodes)"], | ||
'plot_ts_obs_fields_g2': ["Known mean immunity (of immune nodes)", | ||
"Known mean immunity (of all alive nodes)"], | ||
'observation_space': ObservationSpace(graph=Graph(community_n=8, | ||
community_size_mean=5, | ||
community_p_in=0.2, | ||
community_p_out=0.1, | ||
seed=200), | ||
test_rate=0.05, | ||
seed=123), | ||
'healthcare': Healthcare(capacity=300), | ||
'seed': 124} | ||
|
||
pop_low_immunity = Population(name="Low immunity population (small)", | ||
disease=Disease(name='COVID-19', | ||
virulence=0.035, | ||
recovery_rate=0.99, | ||
immunity_mean=0.66, | ||
immunity_decay_mean=0.1, | ||
seed=125), | ||
**common_args) | ||
|
||
pop_high_immunity = Population(name="High immunity population (small)", | ||
disease=Disease(name='COVID-19', | ||
virulence=0.035, | ||
recovery_rate=0.99, | ||
immunity_mean=0.95, | ||
immunity_decay_mean=0.02, | ||
seed=125), | ||
**common_args) | ||
|
||
Parallel(n_jobs=2, | ||
backend='loky')(delayed(run_and_replay)(pop, | ||
steps=365, | ||
plot=False, | ||
save=True) for pop in [pop_low_immunity, pop_high_immunity]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,43 @@ | ||
from joblib import Parallel, delayed | ||
|
||
from social_distancing_sim.disease.disease import Disease | ||
from social_distancing_sim.population.graph import Graph | ||
from social_distancing_sim.population.healthcare import Healthcare | ||
from social_distancing_sim.population.observation_space import ObservationSpace | ||
from social_distancing_sim.population.population import Population | ||
|
||
|
||
def run_and_replay(pop, *args, **kwargs): | ||
pop.run(*args, **kwargs) | ||
if save: | ||
pop.replay() | ||
|
||
|
||
if __name__ == "__main__": | ||
save = True | ||
disease = Disease(name='COVID-19') | ||
healthcare = Healthcare() | ||
|
||
pop_close_tested = Population(name='A herd of cats', | ||
disease=disease, | ||
healthcare=healthcare, | ||
observation_space=ObservationSpace(graph=Graph(community_n=40, | ||
community_size_mean=16, | ||
seed=123), | ||
test_rate=1)) | ||
|
||
pop_close_untested = Population(name='A herd of cats, observed', | ||
disease=disease, | ||
healthcare=healthcare, | ||
observation_space=ObservationSpace(graph=Graph(community_n=40, | ||
community_size_mean=16, | ||
seed=123), | ||
test_rate=0.04)) | ||
|
||
pop_distanced_tested = Population(name='A socially responsible population', | ||
disease=disease, | ||
healthcare=healthcare, | ||
observation_space=ObservationSpace(graph=Graph(community_n=40, | ||
community_size_mean=16, | ||
community_p_in=0.05, | ||
community_p_out=0.04, | ||
seed=123), | ||
test_rate=1)) | ||
|
||
pop_distanced_untested = Population(name='A socially responsible population, observed', | ||
disease=disease, | ||
healthcare=healthcare, | ||
observation_space=ObservationSpace(graph=Graph(community_n=40, | ||
community_size_mean=16, | ||
community_p_in=0.05, | ||
community_p_out=0.04, | ||
seed=123), | ||
test_rate=0.04)) | ||
|
||
pop_close_tested.run(steps=130, | ||
plot=False) | ||
pop_close_tested.replay(duration=0.1) | ||
|
||
pop_close_untested.run(steps=130, | ||
plot=False) | ||
pop_close_untested.replay(duration=0.1) | ||
|
||
pop_distanced_tested.run(steps=130, | ||
plot=False) | ||
pop_distanced_tested.replay(duration=0.1) | ||
|
||
pop_distanced_untested.run(steps=130, | ||
plot=False) | ||
pop_distanced_untested.replay(duration=0.1) | ||
pop_close = Population(name='A herd of cats, observed', | ||
disease=disease, | ||
healthcare=healthcare, | ||
observation_space=ObservationSpace(graph=Graph(community_n=40, | ||
community_size_mean=16, | ||
seed=123), | ||
test_rate=0.04)) | ||
|
||
pop_distanced = Population(name='A socially responsible population, observed', | ||
disease=disease, | ||
healthcare=healthcare, | ||
observation_space=ObservationSpace(graph=Graph(community_n=40, | ||
community_size_mean=16, | ||
community_p_in=0.05, | ||
community_p_out=0.04, | ||
seed=123), | ||
test_rate=0.04)) | ||
|
||
Parallel(n_jobs=2, | ||
backend='loky')(delayed(run_and_replay)(pop, | ||
steps=130, | ||
plot=False, | ||
save=save) for pop in [pop_close, pop_distanced]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Run a single population for 2 years with imperfect immunity and limited test rate.""" | ||
from social_distancing_sim.disease.disease import Disease | ||
from social_distancing_sim.population.graph import Graph | ||
from social_distancing_sim.population.healthcare import Healthcare | ||
from social_distancing_sim.population.observation_space import ObservationSpace | ||
from social_distancing_sim.population.population import Population | ||
|
||
if __name__ == "__main__": | ||
save = True | ||
|
||
graph = Graph(community_n=50, | ||
community_size_mean=15, | ||
community_p_in=0.1, | ||
community_p_out=0.05) | ||
|
||
pop = Population(name="example population", | ||
disease=Disease(name='COVID-19', | ||
virulence=0.006, | ||
immunity_mean=0.6, | ||
immunity_decay_mean=0.15), | ||
healthcare=Healthcare(), | ||
observation_space=ObservationSpace(graph=graph, | ||
test_rate=0.05)) | ||
|
||
pop.run(steps=750, | ||
plot=True, | ||
save=True) | ||
|
||
# Save .gif to './example population/replay.gif' | ||
if save: | ||
pop.replay() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
MAJOR = 0 | ||
MINOR = 1 | ||
MINOR = 2 | ||
PATCH = 0 | ||
|
||
__version__ = ".".join(str(v) for v in [MAJOR, MINOR, PATCH]) |
Oops, something went wrong.