Skip to content

Commit

Permalink
Centering the interval for vl uncertainty computation in report gener…
Browse files Browse the repository at this point in the history
…ator -> improving test accuracy
  • Loading branch information
nmounet committed Sep 1, 2023
1 parent 27da077 commit f8530d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion caimira/apps/calculator/report_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def conditional_prob_inf_given_vl_dist(infection_probability: models._Vectorised
upper_percentiles = []

for vl_log in viral_loads:
specific_prob = infection_probability[np.where((vl_log-specific_vl)*(vl_log+step-specific_vl)<0)[0]] #type: ignore
specific_prob = infection_probability[np.where((vl_log-step/2-specific_vl)*(vl_log+step/2-specific_vl)<0)[0]] #type: ignore
pi_means.append(specific_prob.mean())
lower_percentiles.append(np.quantile(specific_prob, 0.05))
upper_percentiles.append(np.quantile(specific_prob, 0.95))
Expand Down
10 changes: 5 additions & 5 deletions caimira/tests/test_conditional_probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def baseline_exposure_model():
)


@retry(tries=10)
@retry(tries=2)
def test_conditional_prob_inf_given_vl_dist(baseline_exposure_model):

viral_loads = np.array([3., 5., 7., 9.,])
Expand All @@ -67,11 +67,11 @@ def test_conditional_prob_inf_given_vl_dist(baseline_exposure_model):

infection_probability = mc_model.infection_probability() / 100
specific_vl = np.log10(mc_model.concentration_model.infected.virus.viral_load_in_sputum)
step = (max(viral_loads) - min(viral_loads))/100
step = 8/100
actual_pi_means, actual_lower_percentiles, actual_upper_percentiles = (
report_generator.conditional_prob_inf_given_vl_dist(infection_probability, viral_loads, specific_vl, step)
)

assert np.allclose(actual_pi_means, expected_pi_means, rtol=0.1)
assert np.allclose(actual_lower_percentiles, expected_lower_percentiles, rtol=0.1)
assert np.allclose(actual_upper_percentiles, expected_upper_percentiles, rtol=0.1)
assert np.allclose(actual_pi_means, expected_pi_means, atol=0.001)
assert np.allclose(actual_lower_percentiles, expected_lower_percentiles, atol=0.001)
assert np.allclose(actual_upper_percentiles, expected_upper_percentiles, atol=0.001)

0 comments on commit f8530d4

Please sign in to comment.