tests for incidence rate
This commit is contained in:
parent
77c0c5f3a6
commit
df77bdd1b5
1 changed files with 54 additions and 15 deletions
|
|
@ -27,12 +27,16 @@ def full_exposure_model():
|
||||||
short_range=(),
|
short_range=(),
|
||||||
exposed=models.Population(
|
exposed=models.Population(
|
||||||
number=10,
|
number=10,
|
||||||
presence=models.SpecificInterval(((8, 12), (13, 17), )),
|
presence=models.SpecificInterval(((8, 12), (13, 17), )),
|
||||||
mask=models.Mask.types['No mask'],
|
mask=models.Mask.types['No mask'],
|
||||||
activity=models.Activity.types['Seated'],
|
activity=models.Activity.types['Seated'],
|
||||||
host_immunity=0.
|
host_immunity=0.
|
||||||
),
|
),
|
||||||
geographical_data=(),
|
geographical_data=models.Cases(
|
||||||
|
geographic_population=50_000,
|
||||||
|
geographic_cases=52,
|
||||||
|
ascertainment_bias=1,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -51,11 +55,37 @@ def baseline_infected_population_number():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def dynamic_single_exposure_model(full_exposure_model, baseline_infected_population_number):
|
def baseline_exposed_population_number():
|
||||||
|
return models.Population(
|
||||||
|
number=models.IntPiecewiseConstant(
|
||||||
|
(8, 12, 13, 17), (10, 0, 10)),
|
||||||
|
presence=None,
|
||||||
|
mask=models.Mask.types['No mask'],
|
||||||
|
activity=models.Activity.types['Seated'],
|
||||||
|
host_immunity=0.,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def dynamic_infected_single_exposure_model(full_exposure_model, baseline_infected_population_number):
|
||||||
return dc_utils.nested_replace(full_exposure_model,
|
return dc_utils.nested_replace(full_exposure_model,
|
||||||
{'concentration_model.infected': baseline_infected_population_number, })
|
{'concentration_model.infected': baseline_infected_population_number, })
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def dynamic_exposed_single_exposure_model(full_exposure_model, baseline_exposed_population_number):
|
||||||
|
return dc_utils.nested_replace(full_exposure_model,
|
||||||
|
{'exposed': baseline_exposed_population_number, })
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def dynamic_population_exposure_model(full_exposure_model, baseline_infected_population_number ,baseline_exposed_population_number):
|
||||||
|
return dc_utils.nested_replace(full_exposure_model, {
|
||||||
|
'concentration_model.infected': baseline_infected_population_number,
|
||||||
|
'exposed': baseline_exposed_population_number,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"time",
|
"time",
|
||||||
[4., 8., 10., 12., 13., 14., 16., 20., 24.],
|
[4., 8., 10., 12., 13., 14., 16., 20., 24.],
|
||||||
|
|
@ -91,16 +121,16 @@ def test_population_number(full_exposure_model: models.ExposureModel,
|
||||||
[4., 8., 10., 12., 13., 14., 16., 20., 24.],
|
[4., 8., 10., 12., 13., 14., 16., 20., 24.],
|
||||||
)
|
)
|
||||||
def test_concentration_model_dynamic_population(full_exposure_model: models.ExposureModel,
|
def test_concentration_model_dynamic_population(full_exposure_model: models.ExposureModel,
|
||||||
dynamic_single_exposure_model: models.ExposureModel,
|
dynamic_infected_single_exposure_model: models.ExposureModel,
|
||||||
time: float):
|
time: float):
|
||||||
|
|
||||||
assert full_exposure_model.concentration(time) == dynamic_single_exposure_model.concentration(time)
|
assert full_exposure_model.concentration(time) == dynamic_infected_single_exposure_model.concentration(time)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("number_of_infected",[1, 2, 3, 4, 5])
|
@pytest.mark.parametrize("number_of_infected",[1, 2, 3, 4, 5])
|
||||||
@pytest.mark.parametrize("time",[9., 12.5, 16.])
|
@pytest.mark.parametrize("time",[9., 12.5, 16.])
|
||||||
def test_linearity_with_number_of_infected(full_exposure_model: models.ExposureModel,
|
def test_linearity_with_number_of_infected(full_exposure_model: models.ExposureModel,
|
||||||
dynamic_single_exposure_model: models.ExposureModel,
|
dynamic_infected_single_exposure_model: models.ExposureModel,
|
||||||
time: float,
|
time: float,
|
||||||
number_of_infected: int):
|
number_of_infected: int):
|
||||||
|
|
||||||
|
|
@ -112,8 +142,8 @@ def test_linearity_with_number_of_infected(full_exposure_model: models.ExposureM
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
npt.assert_almost_equal(static_multiple_exposure_model.concentration(time), dynamic_single_exposure_model.concentration(time) * number_of_infected)
|
npt.assert_almost_equal(static_multiple_exposure_model.concentration(time), dynamic_infected_single_exposure_model.concentration(time) * number_of_infected)
|
||||||
npt.assert_almost_equal(static_multiple_exposure_model.deposited_exposure(), dynamic_single_exposure_model.deposited_exposure() * number_of_infected)
|
npt.assert_almost_equal(static_multiple_exposure_model.deposited_exposure(), dynamic_infected_single_exposure_model.deposited_exposure() * number_of_infected)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -171,10 +201,19 @@ def test_dynamic_dose(full_exposure_model, time):
|
||||||
npt.assert_almost_equal(dynamic_exposure, np.sum(static_exposure))
|
npt.assert_almost_equal(dynamic_exposure, np.sum(static_exposure))
|
||||||
|
|
||||||
|
|
||||||
def test_dynamic_total_probability_rule(dynamic_single_exposure_model: models.ExposureModel):
|
def test_dynamic_total_probability_rule(
|
||||||
with pytest.raises(
|
full_exposure_model: models.ExposureModel,
|
||||||
NotImplementedError,
|
dynamic_infected_single_exposure_model: models.ExposureModel,
|
||||||
match=re.escape("Cannot compute total probability "
|
dynamic_exposed_single_exposure_model: models.ExposureModel,
|
||||||
"(including incidence rate) with dynamic occupancy")
|
dynamic_population_exposure_model: models.ExposureModel):
|
||||||
):
|
|
||||||
dynamic_single_exposure_model.total_probability_rule()
|
full_model_total_prob_rule = full_exposure_model.total_probability_rule()
|
||||||
|
npt.assert_almost_equal(full_model_total_prob_rule,
|
||||||
|
dynamic_population_exposure_model.dynamic_total_probability_rule())
|
||||||
|
|
||||||
|
npt.assert_almost_equal(full_model_total_prob_rule,
|
||||||
|
dynamic_infected_single_exposure_model.dynamic_total_probability_rule())
|
||||||
|
|
||||||
|
npt.assert_almost_equal(full_model_total_prob_rule,
|
||||||
|
dynamic_exposed_single_exposure_model.dynamic_total_probability_rule())
|
||||||
|
|
||||||
Loading…
Reference in a new issue