Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions cpp/models/ode_secir/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class Model : public FlowModel<FP, InfectionState, Populations<FP, AgeGroup, Inf
//symptomatic are less well quarantined when testing and tracing is overwhelmed so they infect more people
auto riskFromInfectedSymptomatic =
smoother_cosine(test_and_trace_required, params.template get<TestAndTraceCapacity<FP>>(),
params.template get<TestAndTraceCapacity<FP>>() * 5,
params.template get<TestAndTraceCapacity<FP>>() *
params.template get<TestAndTraceCapacityMaxRisk<FP>>(),
params.template get<RiskOfInfectionFromSymptomatic<FP>>()[j],
params.template get<MaxRiskOfInfectionFromSymptomatic<FP>>()[j]);

Expand Down Expand Up @@ -454,15 +455,16 @@ IOResult<FP> get_reproduction_number(size_t t_idx, const Simulation<FP, Base>& s
}
divN[(size_t)k] = 1 / temp;

riskFromInfectedSymptomatic[(size_t)k] =
smoother_cosine(test_and_trace_required, params.template get<TestAndTraceCapacity<FP>>(),
(params.template get<TestAndTraceCapacity<FP>>()) * 5,
params.template get<RiskOfInfectionFromSymptomatic<FP>>()[k],
params.template get<MaxRiskOfInfectionFromSymptomatic<FP>>()[k]);
riskFromInfectedSymptomatic[(size_t)k] = smoother_cosine(
test_and_trace_required, params.template get<TestAndTraceCapacity<FP>>(),
(params.template get<TestAndTraceCapacity<FP>>()) * params.template get<TestAndTraceCapacityMaxRisk<FP>>(),
params.template get<RiskOfInfectionFromSymptomatic<FP>>()[k],
params.template get<MaxRiskOfInfectionFromSymptomatic<FP>>()[k]);

for (mio::AgeGroup l = 0; l < (mio::AgeGroup)num_groups; l++) {
if (test_and_trace_required < params.template get<TestAndTraceCapacity<FP>>() ||
test_and_trace_required > 5 * params.template get<TestAndTraceCapacity<FP>>()) {
test_and_trace_required > params.template get<TestAndTraceCapacityMaxRisk<FP>>() *
params.template get<TestAndTraceCapacity<FP>>()) {
riskFromInfectedSymptomatic_derivatives((size_t)k, (size_t)l) = 0;
}
else {
Expand Down Expand Up @@ -661,9 +663,11 @@ auto get_migration_factors(const Simulation<Base>& sim, FP /*t*/, const Eigen::R
auto test_and_trace_required =
((1 - p_asymp) / params.template get<TimeInfectedNoSymptoms<FP>>().array().template cast<FP>() * y_INS.array())
.sum();
auto test_and_trace_capacity = double(params.template get<TestAndTraceCapacity<FP>>());
auto riskFromInfectedSymptomatic = smoother_cosine(test_and_trace_required, test_and_trace_capacity,
test_and_trace_capacity * 5, p_inf.matrix(), p_inf_max.matrix());
auto test_and_trace_capacity = double(params.template get<TestAndTraceCapacity<FP>>());
auto test_and_trace_capacity_max_risk = double(params.template get<TestAndTraceCapacityMaxRisk<FP>>());
auto riskFromInfectedSymptomatic =
smoother_cosine(test_and_trace_required, test_and_trace_capacity,
test_and_trace_capacity * test_and_trace_capacity_max_risk, p_inf.matrix(), p_inf_max.matrix());

//set factor for infected
auto factors = Eigen::VectorXd::Ones(y.rows()).eval();
Expand Down
53 changes: 46 additions & 7 deletions cpp/models/ode_secir/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,29 @@ struct TestAndTraceCapacity {
}
};

/**
* @brief Multiplier for the test and trace capacity to determine when it is considered overloaded.
*/
template <typename FP = double>
struct TestAndTraceCapacityMaxRisk {
using Type = UncertainValue<FP>;
static Type get_default(AgeGroup)
{
return Type(5.0);
}
static std::string name()
{
return "TestAndTraceCapacityMaxRisk";
}
};

template <typename FP = double>
using ParametersBase =
ParameterSet<StartDay, Seasonality<FP>, ICUCapacity<FP>, TestAndTraceCapacity<FP>, ContactPatterns<FP>,
DynamicNPIsInfectedSymptoms<FP>, TimeExposed<FP>, TimeInfectedNoSymptoms<FP>, TimeInfectedSymptoms<FP>,
TimeInfectedSevere<FP>, TimeInfectedCritical<FP>, TransmissionProbabilityOnContact<FP>,
RelativeTransmissionNoSymptoms<FP>, RecoveredPerInfectedNoSymptoms<FP>,
RiskOfInfectionFromSymptomatic<FP>, MaxRiskOfInfectionFromSymptomatic<FP>,
SeverePerInfectedSymptoms<FP>, CriticalPerSevere<FP>, DeathsPerCritical<FP>>;
using ParametersBase = ParameterSet<
StartDay, Seasonality<FP>, ICUCapacity<FP>, TestAndTraceCapacity<FP>, TestAndTraceCapacityMaxRisk<FP>,
ContactPatterns<FP>, DynamicNPIsInfectedSymptoms<FP>, TimeExposed<FP>, TimeInfectedNoSymptoms<FP>,
TimeInfectedSymptoms<FP>, TimeInfectedSevere<FP>, TimeInfectedCritical<FP>, TransmissionProbabilityOnContact<FP>,
RelativeTransmissionNoSymptoms<FP>, RecoveredPerInfectedNoSymptoms<FP>, RiskOfInfectionFromSymptomatic<FP>,
MaxRiskOfInfectionFromSymptomatic<FP>, SeverePerInfectedSymptoms<FP>, CriticalPerSevere<FP>, DeathsPerCritical<FP>>;

/**
* @brief Parameters of an age-resolved SECIR/SECIHURD model.
Expand Down Expand Up @@ -445,6 +460,20 @@ class Parameters : public ParametersBase<FP>
corrected = true;
}

if (this->template get<TestAndTraceCapacity<FP>>() < 0.0) {
log_warning("Constraint check: Parameter TestAndTraceCapacity changed from {:0.4f} to {:d}",
this->template get<TestAndTraceCapacity<FP>>(), 0);
this->template get<TestAndTraceCapacity<FP>>() = 0;
corrected = true;
}

if (this->template get<TestAndTraceCapacityMaxRisk<FP>>() < 0.0) {
log_warning("Constraint check: Parameter TestAndTraceCapacityMaxRisk changed from {:0.4f} to {:d}",
this->template get<TestAndTraceCapacityMaxRisk<FP>>(), 0);
this->template get<TestAndTraceCapacityMaxRisk<FP>>() = 0;
corrected = true;
}

for (auto i = AgeGroup(0); i < AgeGroup(m_num_groups); ++i) {
if (this->template get<TimeExposed<FP>>()[i] < tol_times) {
log_warning("Constraint check: Parameter TimeExposed changed from {:.4f} to {:.4f}. Please "
Expand Down Expand Up @@ -567,6 +596,16 @@ class Parameters : public ParametersBase<FP>
return true;
}

if (this->template get<TestAndTraceCapacity<FP>>() < 0.0) {
log_error("Constraint check: Parameter TestAndTraceCapacity smaller {:d}", 0);
return true;
}

if (this->template get<TestAndTraceCapacityMaxRisk<FP>>() < 0.0) {
log_error("Constraint check: Parameter TestAndTraceCapacityMaxRisk smaller {:d}", 0);
return true;
}

const double tol_times = 1e-1; // accepted tolerance for compartment stays

for (auto i = AgeGroup(0); i < AgeGroup(m_num_groups); ++i) {
Expand Down
10 changes: 7 additions & 3 deletions cpp/models/ode_secirvvs/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,15 @@ class Model
//symptomatic are less well quarantined when testing and tracing is overwhelmed so they infect more people
auto riskFromInfectedSymptomatic =
smoother_cosine(test_and_trace_required, params.template get<TestAndTraceCapacity<FP>>(),
params.template get<TestAndTraceCapacity<FP>>() * 15,
params.template get<TestAndTraceCapacity<FP>>() *
params.template get<TestAndTraceCapacityMaxRiskSymptoms<FP>>(),
params.template get<RiskOfInfectionFromSymptomatic<FP>>()[i],
params.template get<MaxRiskOfInfectionFromSymptomatic<FP>>()[i]);

auto riskFromInfectedNoSymptoms =
smoother_cosine(test_and_trace_required, params.template get<TestAndTraceCapacity<FP>>(),
params.template get<TestAndTraceCapacity<FP>>() * 2,
params.template get<TestAndTraceCapacity<FP>>() *
params.template get<TestAndTraceCapacityMaxRiskNoSymptoms<FP>>(),
params.template get<RelativeTransmissionNoSymptoms<FP>>()[i], 1.0);

for (auto j = AgeGroup(0); j < n_agegroups; j++) {
Expand Down Expand Up @@ -835,7 +837,9 @@ auto get_migration_factors(const Simulation<Base>& sim, FP /*t*/, const Eigen::R
.sum();
auto riskFromInfectedSymptomatic =
smoother_cosine(test_and_trace_required, double(params.template get<TestAndTraceCapacity<FP>>()),
params.template get<TestAndTraceCapacity<FP>>() * 5, p_inf.matrix(), p_inf_max.matrix());
params.template get<TestAndTraceCapacity<FP>>() *
params.template get<TestAndTraceCapacityMaxRiskSymptoms<FP>>(),
p_inf.matrix(), p_inf_max.matrix());

//set factor for infected
auto factors = Eigen::VectorXd::Ones(y.rows()).eval();
Expand Down
99 changes: 83 additions & 16 deletions cpp/models/ode_secirvvs/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,38 @@ struct TestAndTraceCapacity {
}
};

/**
* @brief Multiplier for the test and trace capacity to determine when it is considered overloaded from cases without symptoms.
*/
template <typename FP = double>
struct TestAndTraceCapacityMaxRiskNoSymptoms {
using Type = UncertainValue<FP>;
static Type get_default(AgeGroup)
{
return Type(2.0);
}
static std::string name()
{
return "TestAndTraceCapacityMaxRiskNoSymptoms";
}
};

/**
* @brief Multiplier for the test and trace capacity to determine when it is considered overloaded by symptomatic cases.
*/
template <typename FP = double>
struct TestAndTraceCapacityMaxRiskSymptoms {
using Type = UncertainValue<FP>;
static Type get_default(AgeGroup)
{
return Type(15.0);
}
static std::string name()
{
return "TestAndTraceCapacityMaxRiskSymptoms";
}
};

/**
* @brief the contact patterns within the society are modelled using an UncertainContactMatrix
*/
Expand Down Expand Up @@ -573,19 +605,18 @@ struct InfectiousnessNewVariant {
};

template <typename FP = double>
using ParametersBase =
ParameterSet<StartDay, Seasonality<FP>, ICUCapacity<FP>, TestAndTraceCapacity<FP>, ContactPatterns<FP>,
DynamicNPIsInfectedSymptoms<FP>, TimeExposed<FP>, TimeInfectedNoSymptoms<FP>, TimeInfectedSymptoms<FP>,
TimeInfectedSevere<FP>, TimeInfectedCritical<FP>, TransmissionProbabilityOnContact<FP>,
RelativeTransmissionNoSymptoms<FP>, RecoveredPerInfectedNoSymptoms<FP>,
RiskOfInfectionFromSymptomatic<FP>, MaxRiskOfInfectionFromSymptomatic<FP>,
SeverePerInfectedSymptoms<FP>, CriticalPerSevere<FP>, DeathsPerCritical<FP>, VaccinationGap<FP>,
DaysUntilEffectivePartialImmunity<FP>, DaysUntilEffectiveImprovedImmunity<FP>,
DailyFullVaccination<FP>, DailyFirstVaccination<FP>, ReducExposedPartialImmunity<FP>,
ReducExposedImprovedImmunity<FP>, ReducInfectedSymptomsPartialImmunity<FP>,
ReducInfectedSymptomsImprovedImmunity<FP>, ReducInfectedSevereCriticalDeadPartialImmunity<FP>,
ReducInfectedSevereCriticalDeadImprovedImmunity<FP>, ReducTimeInfectedMild<FP>,
InfectiousnessNewVariant<FP>, StartDayNewVariant>;
using ParametersBase = ParameterSet<
StartDay, Seasonality<FP>, ICUCapacity<FP>, TestAndTraceCapacity<FP>, TestAndTraceCapacityMaxRiskNoSymptoms<FP>,
TestAndTraceCapacityMaxRiskSymptoms<FP>, ContactPatterns<FP>, DynamicNPIsInfectedSymptoms<FP>, TimeExposed<FP>,
TimeInfectedNoSymptoms<FP>, TimeInfectedSymptoms<FP>, TimeInfectedSevere<FP>, TimeInfectedCritical<FP>,
TransmissionProbabilityOnContact<FP>, RelativeTransmissionNoSymptoms<FP>, RecoveredPerInfectedNoSymptoms<FP>,
RiskOfInfectionFromSymptomatic<FP>, MaxRiskOfInfectionFromSymptomatic<FP>, SeverePerInfectedSymptoms<FP>,
CriticalPerSevere<FP>, DeathsPerCritical<FP>, VaccinationGap<FP>, DaysUntilEffectivePartialImmunity<FP>,
DaysUntilEffectiveImprovedImmunity<FP>, DailyFullVaccination<FP>, DailyFirstVaccination<FP>,
ReducExposedPartialImmunity<FP>, ReducExposedImprovedImmunity<FP>, ReducInfectedSymptomsPartialImmunity<FP>,
ReducInfectedSymptomsImprovedImmunity<FP>, ReducInfectedSevereCriticalDeadPartialImmunity<FP>,
ReducInfectedSevereCriticalDeadImprovedImmunity<FP>, ReducTimeInfectedMild<FP>, InfectiousnessNewVariant<FP>,
StartDayNewVariant>;

/**
* @brief Parameters of an age-resolved SECIR/SECIHURD model with paths for partial and improved immunity through vaccination.
Expand Down Expand Up @@ -685,6 +716,27 @@ class Parameters : public ParametersBase<FP>
corrected = true;
}

if (this->template get<TestAndTraceCapacity<FP>>() < 0.0) {
log_warning("Constraint check: Parameter TestAndTraceCapacity changed from {} to {}",
this->template get<TestAndTraceCapacity<FP>>(), 0);
this->template set<TestAndTraceCapacity<FP>>(0);
corrected = true;
}

if (this->template get<TestAndTraceCapacityMaxRiskSymptoms<FP>>() < 0.0) {
log_warning("Constraint check: Parameter TestAndTraceCapacityMaxRiskSymptoms changed from {} to {}",
this->template get<TestAndTraceCapacityMaxRiskSymptoms<FP>>(), 0);
this->template set<TestAndTraceCapacityMaxRiskSymptoms<FP>>(0);
corrected = true;
}

if (this->template get<TestAndTraceCapacityMaxRiskNoSymptoms<FP>>() < 0.0) {
log_warning("Constraint check: Parameter TestAndTraceCapacityMaxRiskNoSymptoms changed from {} to {}",
this->template get<TestAndTraceCapacityMaxRiskNoSymptoms<FP>>(), 0);
this->template set<TestAndTraceCapacityMaxRiskNoSymptoms<FP>>(0);
corrected = true;
}

const double tol_times = 1e-1; // accepted tolerance for compartment stays

for (auto i = AgeGroup(0); i < AgeGroup(m_num_groups); ++i) {
Expand Down Expand Up @@ -789,7 +841,7 @@ class Parameters : public ParametersBase<FP>
}

if (this->template get<DaysUntilEffectivePartialImmunity<FP>>()[i] < 0.0) {
log_warning("Constraint check: Parameter DeathsPerCritical changed from {} to {}",
log_warning("Constraint check: Parameter DaysUntilEffectivePartialImmunity changed from {} to {}",
this->template get<DaysUntilEffectivePartialImmunity<FP>>()[i], 0);
this->template get<DaysUntilEffectivePartialImmunity<FP>>()[i] = 0;
corrected = true;
Expand Down Expand Up @@ -877,12 +929,27 @@ class Parameters : public ParametersBase<FP>
{
const double tol_times = 1e-1; // accepted tolerance for compartment stays
if (this->template get<Seasonality<FP>>() < 0.0 || this->template get<Seasonality<FP>>() > 0.5) {
log_error("Constraint check: Parameter m_seasonality smaller {} or larger {}", 0, 0.5);
log_error("Constraint check: Parameter Seasonality smaller {} or larger {}", 0, 0.5);
return true;
}

if (this->template get<ICUCapacity<FP>>() < 0.0) {
log_error("Constraint check: Parameter m_icu_capacity smaller {}", 0);
log_error("Constraint check: Parameter ICUCapacity smaller {}", 0);
return true;
}

if (this->template get<TestAndTraceCapacity<FP>>() < 0.0) {
log_error("Constraint check: Parameter TestAndTraceCapacity smaller {}", 0);
return true;
}

if (this->template get<TestAndTraceCapacityMaxRiskSymptoms<FP>>() < 0.0) {
log_error("Constraint check: Parameter TestAndTraceCapacityMaxRiskSymptoms smaller {}", 0);
return true;
}

if (this->template get<TestAndTraceCapacityMaxRiskNoSymptoms<FP>>() < 0.0) {
log_error("Constraint check: Parameter TestAndTraceCapacityMaxRiskNoSymptoms smaller {}", 0);
return true;
}

Expand Down
Loading