Adds sweep capacity to test_test_prob_sensitivity and allows one more or less diagnoses per trial.
from unittest_support_classes import CovaSimTest
from unittest_support_classes import TestProperties
from math import sqrt
+import json
import numpy as np
import unittest
@@ -547,9 +548,13 @@ class InterventionTests(CovaSimTest):
target_pop_new_channel=None)
pass
- def test_test_prob_sensitivity(self, subtract_today_recoveries=True):
+ def test_test_prob_sensitivity(self, subtract_today_recoveries=False):
self.is_debugging = False
+ seed_list = range(0)
+ error_seeds = {}
+ for seed in seed_list:
params = {
+ SimKeys.random_seed: seed,
SimKeys.number_agents: 5000,
SimKeys.number_simulated_days: 31
}
@@ -592,16 +597,43 @@ class InterventionTests(CovaSimTest):
f"\tSensitivity: {sensitivity} \n"
f"\tIdeal: {ideal_diagnoses} \n"
f"\tActual diagnoses: {first_day_diagnoses}\n")
- self.assertGreaterEqual(first_day_diagnoses, min_tolerable_diagnoses,
- msg=f"Expected at least {min_tolerable_diagnoses} diagnoses with {target_count}"
- f" symptomatic and {sensitivity} sensitivity. Got {first_day_diagnoses}"
- f" diagnoses, which is too low.")
- self.assertLessEqual(first_day_diagnoses, max_tolerable_diagnoses,
- msg=f"Expected no more than {max_tolerable_diagnoses} diagnoses with {target_count}"
- f" symptomatic and {sensitivity} sensitivity. Got {first_day_diagnoses}"
- f" diagnoses, which is too high.")
pass
+
+ too_low_message = f"Expected at least {min_tolerable_diagnoses} diagnoses" \
+ f" with {target_count} symptomatic and {sensitivity}" \
+ f" sensitivity. Got {first_day_diagnoses} diagnoses," \
+ f" which is too low."
+ too_high_message = f"Expected no more than {max_tolerable_diagnoses} diagnoses" \
+ f" with {target_count} symptomatic and {sensitivity}" \
+ f" sensitivity. Got {first_day_diagnoses} diagnoses, which" \
+ f" is too high."
+
+ if len(seed_list) > 1:
+ local_errors = {}
+ if first_day_diagnoses + 1 < min_tolerable_diagnoses:
+ local_errors[sensitivity] = (f"LOW: {too_low_message} seed: {seed}")
+ elif first_day_diagnoses - 1 > max_tolerable_diagnoses:
+ local_errors[sensitivity] = (f"HIGH: {too_high_message} seed: {seed}")
+ if len(local_errors) > 0:
+ if seed not in error_seeds:
+ error_seeds[seed] = local_errors
+ else:
+ error_seeds[seed][sensitivity] = local_errors[sensitivity]
+ else:
+ self.assertGreaterEqual(first_day_diagnoses + 1, min_tolerable_diagnoses,
+ msg=too_low_message)
+ self.assertLessEqual(first_day_diagnoses - 1, max_tolerable_diagnoses,
+ msg=too_high_message)
+ pass
+ pass
+ if len(seed_list) > 1:
+ with open(f"DEBUG_test_prob_sensitivity_sweep.json",'w') as outfile:
+ json.dump(error_seeds, outfile, indent=4)
pass
+ acceptable_losses = len(seed_list) // 10
+ self.assertLessEqual(len(error_seeds),
+ acceptable_losses,
+ msg=error_seeds)
def test_test_prob_symptomatic_prob_of_test(self):
params = {
