def test_smart_society(): random.seed(42) o = Outbreak(StrategicTester(), Covid(), pop_size=5000, seed_size=50, n_days=150) o.simulate()
def test_two_track_society(): random.seed(42) o = Outbreak(TwoTrackTester(), Covid(), pop_size=5000, seed_size=50, n_days=150) o.simulate()
def test_two_track_hw_society(): random.seed(42) o = Outbreak(TwoTrackTester(), Covid(), pop_size=5000, seed_size=50, n_days=150, population_type=HouseholdWorkplacePopulation) o.simulate()
def test_two_track_hetero_society(): random.seed(42) o = Outbreak(TwoTrackTester(), Covid(), pop_size=5000, seed_size=50, n_days=150, population_type=RadialAgePopulation) o.simulate()
def test_two_track_city_society(): random.seed(42) o = Outbreak(LateralFlowUK(config=dict(SIMULATOR_PERIODS_PER_DAY=4, DAILY_TEST_CAPACITY_PER_HEAD=1)), Covid(), pop_size=8000, seed_size=8000 // 80, n_days=150, population_type=CityPopulation) o.simulate()
def test_toy_model(): random.seed(42) s = Society(episodes_per_day=5, encounter_size=2) d = Disease(days_infectious=10, pr_transmission_per_day=0.2) # seed size is the number of people in the population who we seed as being infected: o = Outbreak(s, d, pop_size=1000, seed_size=2, n_days=ALL_TIME_DAYS, population_type=Population, person_type=Person) # so, this is a village of 10000 people with 2 starting off infected o.simulate() np.testing.assert_allclose(o.recorder.story[90:95], [[18.2, 0.619, 0.57, 0.0, 0.0, 0.0], [18.4, 0.643, 0.592, 0.0, 0.0, 0.0], [18.6, 0.656, 0.603, 0.0, 0.0, 0.0], [18.8, 0.673, 0.618, 0.0, 0.0, 0.0], [19.0, 0.69, 0.635, 0.0, 0.0, 0.0]])
def test_draconian_population_model(): from codit.society.basic import DraconianSociety random.seed(42) s = DraconianSociety(episodes_per_day=5, encounter_size=2) d = Disease(days_infectious=10, pr_transmission_per_day=0.2) # seed size is the number of people in the population who we seed as being infected: o = Outbreak(s, d, pop_size=1000, seed_size=2, n_days=ALL_TIME_DAYS, population_type=Population, person_type=Person) # so, this is a village of 10000 people with 2 starting off infected o.simulate() np.testing.assert_allclose( o.recorder.story[90:95], [[18.2, 0.002, 0.0, 0.0, 0.0, 0.0], [18.4, 0.002, 0.0, 0.0, 0.0, 0.0], [18.6, 0.002, 0.0, 0.0, 0.0, 0.0], [18.8, 0.002, 0.0, 0.0, 0.0, 0.0], [19.0, 0.002, 0.0, 0.0, 0.0, 0.0]])
def test_covid_model(): s = TestingTracingSociety(episodes_per_day=2, config=dict(PROB_TEST_IF_REQUESTED=0.4)) random.seed(42) np.random.seed(42) o = Outbreak(s, Covid(), pop_size=8, seed_size=1, n_days=ALL_TIME_DAYS) o.simulate() # for k, v in o.pop.contacts.items(): # print(k, len(v)) # t cov risks tests isol np.testing.assert_allclose(o.recorder.story[:15], [ [0.5, 0.25, 0.125, 0.0, 0.125, 0.0], [1.0, 0.25, 0.125, 0.25, 0.0, 0.0], [1.5, 0.25, 0.125, 0.0, 0.0, 0.0], [2.0, 0.375, 0.125, 0.0, 0.0, 0.0], [2.5, 0.375, 0.125, 0.0, 0.0, 0.0], [3.0, 0.375, 0.125, 0.0, 0.0, 0.0], [3.5, 0.375, 0.125, 0.0, 0.0, 0.0], [4.0, 0.375, 0.125, 0.0, 0.0, 0.125], [4.5, 0.375, 0.25, 0.0, 0.0, 0.125], [5.0, 0.5, 0.25, 0.0, 0.0, 0.125], [5.5, 0.5, 0.125, 0.0, 0.0, 0.125], [6.0, 0.5, 0.25, 0.0, 0.0, 0.125], [6.5, 0.5, 0.25, 0.0, 0.0, 0.125], [7.0, 0.5, 0.25, 0.0, 0.0, 0.125], [7.5, 0.5, 0.25, 0.0, 0.0, 0.125] ])
def test_uk_ovespill_model(): from codit.society.alternatives import UKSociety from codit.disease import Covid random.seed(42) np.random.seed(42) o = Outbreak(UKSociety(config=dict(PROB_NON_C19_SYMPTOMS_PER_DAY=0.1)), Covid(), pop_size=1000, seed_size=20, n_days=ALL_TIME_DAYS) o.simulate() # Skip this test because the the simulator is not deterministic. # I believe it is because it uses np.random by calls multi-threaded numpy code. # TODO: I believe the correct solution is for the simulator to be constructed with its own np.random.RandomState class # return np.testing.assert_allclose( o.recorder.story[40:45] == [[41.0, 0.035, 0.0, 0.007, 0.467, 0.452], [42.0, 0.035, 0.0, 0.007, 0.458, 0.442], [43.0, 0.035, 0.0, 0.007, 0.461, 0.447], [44.0, 0.035, 0.0, 0.007, 0.458, 0.448], [45.0, 0.035, 0.0, 0.007, 0.457, 0.448]])
def test_covid_model(): from codit.society import TestingSociety from codit.disease import Covid s = TestingSociety(episodes_per_day=5, config={ "MEAN_NETWORK_SIZE": 2, "PROB_NON_C19_SYMPTOMS_PER_DAY": 0, "PROB_TEST_IF_REQUESTED": 0.4 }) d = Covid(days_infectious=10, pr_transmission_per_day=0.2) # seed size is the number of people in the population who we seed as being infected: random.seed(42) o = Outbreak(s, d, pop_size=1000, seed_size=20, n_days=ALL_TIME_DAYS) # so, this is a village of 10000 people with 2 starting off infected random.seed(42) o.simulate() np.testing.assert_allclose(o.recorder.story[90:95], [[18.2, 0.103, 0.044, 0.0, 0.0, 0.023], [18.4, 0.103, 0.046, 0.0, 0.0, 0.023], [18.6, 0.103, 0.045, 0.0, 0.0, 0.021], [18.8, 0.105, 0.043, 0.0, 0.0, 0.019], [19.0, 0.105, 0.043, 0.0, 0.0, 0.017]])
def test_two_track_model(): s = TwoTrackTester(episodes_per_day=2) random.seed(42) np.random.seed(42) o = Outbreak(s, Covid(), pop_size=8, seed_size=1, n_days=ALL_TIME_DAYS) o.simulate() # for k, v in o.pop.contacts.items(): # print(k, len(v)) # t cov risks tests tests_back isol np.testing.assert_allclose(o.recorder.story[:15], [[0.5, 0.25, 0.125, 0.0, 0.125, 0.0], [1.0, 0.25, 0.125, 0.0, 0.125, 0.0], [1.5, 0.25, 0.125, 0.0, 0.125, 0.0], [2.0, 0.25, 0.125, 0.0, 0.125, 0.0], [2.5, 0.25, 0.125, 0.0, 0.125, 0.0], [3.0, 0.25, 0.125, 0.0, 0.125, 0.0], [3.5, 0.25, 0.125, 0.0, 0.125, 0.0], [4.0, 0.375, 0.125, 0.0, 0.125, 0.0], [4.5, 0.375, 0.25, 0.0, 0.125, 0.0], [5.0, 0.5, 0.25, 0.0, 0.125, 0.0], [5.5, 0.5, 0.125, 0.0, 0.125, 0.0], [6.0, 0.5, 0.125, 0.0, 0.125, 0.0], [6.5, 0.5, 0.125, 0.0, 0.125, 0.0], [7.0, 0.5, 0.125, 0.0, 0.125, 0.0], [7.5, 0.5, 0.125, 0.0, 0.125, 0.0]])