Skip to content
Open
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
8 changes: 6 additions & 2 deletions cpp/memilio/epidemiology/lct_populations.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ class LctPopulations
bool corrected = false;
for (int i = 0; i < m_y.array().size(); i++) {
if (m_y.array()[i] < 0.0) {
log_warning("Constraint check: Compartment size {:d} changed from {:.4f} to {:d}", i, m_y.array()[i],
0);
if (m_y.array()[i] > -1e-10) {
log_warning("Constraint check: Compartment number {} changed from {} to {}", i, m_y.array()[i], 0);
}
else {
log_error("Constraint check: Compartment number {} changed from {} to {}", i, m_y.array()[i], 0);
}
m_y.array()[i] = 0.;
corrected = true;
}
Expand Down
14 changes: 10 additions & 4 deletions cpp/memilio/epidemiology/populations.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ class Populations : public CustomIndexArray<UncertainValue<FP>, Categories...>
/**
* @brief Checks whether all compartments have non-negative values.
* This function can be used to prevent slighly negative function values in compartment sizes that came out
* due to roundoff errors if, e.g., population sizes were computed in a complex way.
* due to roundoff errors if, e.g., population sizes were computed in a complex way. If negative values
* which are smaller than -1e-10 are found, an error is logged, otherwise, only a warning is logged.
*
* Attention: This function should be used with care. It can not and will not set model parameters and
* compartments to meaningful values. In most cases it is preferable to use check_constraints,
Expand All @@ -245,8 +246,13 @@ class Populations : public CustomIndexArray<UncertainValue<FP>, Categories...>
bool corrected = false;
for (int i = 0; i < this->array().size(); i++) {
if (this->array()[i] < 0.0) {
log_warning("Constraint check: Compartment size {:d} changed from {:.4f} to {:d}", i, this->array()[i],
0);
if (this->array()[i] > -1e-10) {
log_warning("Constraint check: Compartment number {} changed from {} to {}", i, this->array()[i],
0);
}
else {
log_error("Constraint check: Compartment number {} changed from {} to {}", i, this->array()[i], 0);
}
this->array()[i] = 0.0;
corrected = true;
}
Expand All @@ -263,7 +269,7 @@ class Populations : public CustomIndexArray<UncertainValue<FP>, Categories...>
for (int i = 0; i < this->array().size(); i++) {
FP value = this->array()[i];
if (value < 0.0) {
log_error("Constraint check: Compartment size {} is {} and smaller {}", i, value, 0);
log_error("Constraint check: Compartment number {} is {} and smaller {}", i, value, 0);
return true;
}
}
Expand Down
86 changes: 43 additions & 43 deletions cpp/models/abm/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -799,177 +799,177 @@ class Parameters : public ParametersBase

if (this->get<TimeExposedToNoSymptoms>()[{v, i}].params()[0] < 0) {
log_error("Constraint check: Mean of parameter TimeExposedToNoSymptoms of virus variant {} and "
"age group {:.0f} smaller "
"than {:.4f}",
"age group {} smaller "
"than {}",
(uint32_t)v, (size_t)i, 0);
return true;
}

if (this->get<TimeInfectedNoSymptomsToSymptoms>()[{v, i}].params()[0] < 0.0) {
log_error("Constraint check: Mean of parameter TimeInfectedNoSymptomsToSymptoms "
"of virus variant "
"{} and age group {:.0f} smaller "
"than {:d}",
"{} and age group {} smaller "
"than {}",
(uint32_t)v, (size_t)i, 0);
return true;
}

if (this->get<TimeInfectedNoSymptomsToRecovered>()[{v, i}].params()[0] < 0.0) {
log_error("Constraint check: Mean of parameter TimeInfectedNoSymptomsToRecovered of "
"virus variant "
"{} and age group {:.0f} smaller "
"than {:d}",
"{} and age group {} smaller "
"than {}",
(uint32_t)v, (size_t)i, 0);
return true;
}

if (this->get<TimeInfectedSymptomsToSevere>()[{v, i}].params()[0] < 0.0) {
log_error("Constraint check: Mean of parameter TimeInfectedSymptomsToSevere of virus "
"variant {} "
"and age group {:.0f} smaller "
"than {:d}",
"and age group {} smaller "
"than {}",
(uint32_t)v, (size_t)i, 0);
return true;
}

if (this->get<TimeInfectedSymptomsToRecovered>()[{v, i}].params()[0] < 0.0) {
log_error("Constraint check: Mean of parameter TimeInfectedSymptomsToRecovered of virus "
"variant {} "
"and age group {:.0f} smaller "
"than {:d}",
"and age group {} smaller "
"than {}",
(uint32_t)v, (size_t)i, 0);
return true;
}

if (this->get<TimeInfectedSevereToCritical>()[{v, i}].params()[0] < 0.0) {
log_error("Constraint check: Mean of parameter TimeInfectedSevereToCritical of virus "
"variant {} "
"and age group {:.0f} smaller "
"than {:d}",
"and age group {} smaller "
"than {}",
(uint32_t)v, (size_t)i, 0);
return true;
}

if (this->get<TimeInfectedSevereToRecovered>()[{v, i}].params()[0] < 0.0) {
log_error("Constraint check: Mean of parameter TimeInfectedSevereToRecovered of virus "
"variant {} "
"and age group {:.0f} smaller "
"than {:d}",
"and age group {} smaller "
"than {}",
(uint32_t)v, (size_t)i, 0);
return true;
}

if (this->get<TimeInfectedSevereToDead>()[{v, i}].params()[0] < 0.0) {
log_error("Constraint check: Mean of parameter TimeInfectedSevereToDead of virus "
"variant {} "
"and age group {:.0f} smaller "
"than {:d}",
"and age group {} smaller "
"than {}",
(uint32_t)v, (size_t)i, 0);
return true;
}

if (this->get<TimeInfectedCriticalToDead>()[{v, i}].params()[0] < 0.0) {
log_error("Constraint check: Mean of parameter TimeInfectedCriticalToDead of virus variant {} "
"and age group {:.0f} smaller "
"than {:d}",
"and age group {} smaller "
"than {}",
(uint32_t)v, (size_t)i, 0);
return true;
}

if (this->get<TimeInfectedCriticalToRecovered>()[{v, i}].params()[0] < 0.0) {
log_error("Constraint check: Mean of parameter TimeInfectedCriticalToRecovered of virus "
"variant {} "
"and age group {:.0f} smaller "
"than {:d}",
"and age group {} smaller "
"than {}",
(uint32_t)v, (size_t)i, 0);
return true;
}

if (this->get<SymptomsPerInfectedNoSymptoms>()[{v, i}] < 0.0 ||
this->get<SymptomsPerInfectedNoSymptoms>()[{v, i}] > 1.0) {
log_error("Constraint check: Parameter SymptomsPerInfectedNoSymptoms of virus variant {} and age "
"group {:.0f} smaller than {:d} or larger than {:d}",
"group {} smaller than {} or larger than {}",
(uint32_t)v, (size_t)i, 0, 1);
return true;
}

if (this->get<SeverePerInfectedSymptoms>()[{v, i}] < 0.0 ||
this->get<SeverePerInfectedSymptoms>()[{v, i}] > 1.0) {
log_error("Constraint check: Parameter SeverePerInfectedSymptoms of virus variant {} and age group "
"{:.0f} smaller than {:d} or larger than {:d}",
"{} smaller than {} or larger than {}",
(uint32_t)v, (size_t)i, 0, 1);
return true;
}

if (this->get<CriticalPerInfectedSevere>()[{v, i}] < 0.0 ||
this->get<CriticalPerInfectedSevere>()[{v, i}] > 1.0) {
log_error("Constraint check: Parameter CriticalPerInfectedSevere of virus variant {} and age group "
"{:.0f} smaller than {:d} or larger than {:d}",
"{} smaller than {} or larger than {}",
(uint32_t)v, (size_t)i, 0, 1);
return true;
}

if (this->get<DeathsPerInfectedSevere>()[{v, i}] < 0.0 ||
this->get<DeathsPerInfectedSevere>()[{v, i}] > 1.0) {
log_error("Constraint check: Parameter DeathsPerInfectedSevere of age group {:.0f} smaller than "
"{:d} or larger than {:d}",
log_error("Constraint check: Parameter DeathsPerInfectedSevere of age group {} smaller than "
"{} or larger than {}",
(uint32_t)v, (size_t)i, 0, 1);
return true;
}

if ((this->get<DeathsPerInfectedSevere>()[{v, i}] + this->get<CriticalPerInfectedSevere>()[{v, i}]) >
1.0) {
log_error("Constraint check: Sum of parameters DeathsPerInfectedSevere and "
"CriticalPerInfectedSevere of age group {:.0f} larger than "
"{:d}",
"CriticalPerInfectedSevere of age group {} larger than "
"{}",
(uint32_t)v, (size_t)i, 1);
return true;
}

if (this->get<DeathsPerInfectedCritical>()[{v, i}] < 0.0 ||
this->get<DeathsPerInfectedCritical>()[{v, i}] > 1.0) {
log_error("Constraint check: Parameter DeathsPerInfectedCritical of age group {:.0f} smaller than "
"{:d} or larger than {:d}",
log_error("Constraint check: Parameter DeathsPerInfectedCritical of age group {} smaller than "
"{} or larger than {}",
(uint32_t)v, (size_t)i, 0, 1);
return true;
}

if (this->get<DetectInfection>()[{v, i}] < 0.0 || this->get<DetectInfection>()[{v, i}] > 1.0) {
log_error("Constraint check: Parameter DetectInfection of virus variant {} and age group {:.0f} "
"smaller than {:d} or "
"larger than {:d}",
log_error("Constraint check: Parameter DetectInfection of virus variant {} and age group {} "
"smaller than {} or "
"larger than {}",
(uint32_t)v, (size_t)i, 0, 1);
return true;
}
}

if (this->get<GotoWorkTimeMinimum>()[i].seconds() < 0.0 ||
this->get<GotoWorkTimeMinimum>()[i].seconds() > this->get<GotoWorkTimeMaximum>()[i].seconds()) {
log_error("Constraint check: Parameter GotoWorkTimeMinimum of age group {:.0f} smaller {:d} or "
"larger {:d}",
log_error("Constraint check: Parameter GotoWorkTimeMinimum of age group {} smaller {} or "
"larger {}",
(size_t)i, 0, this->get<GotoWorkTimeMaximum>()[i].seconds());
return true;
}

if (this->get<GotoWorkTimeMaximum>()[i].seconds() < this->get<GotoWorkTimeMinimum>()[i].seconds() ||
this->get<GotoWorkTimeMaximum>()[i] > days(1)) {
log_error("Constraint check: Parameter GotoWorkTimeMaximum of age group {:.0f} smaller {:d} or larger "
log_error("Constraint check: Parameter GotoWorkTimeMaximum of age group {} smaller {} or larger "
"than one day time span",
(size_t)i, this->get<GotoWorkTimeMinimum>()[i].seconds());
return true;
}

if (this->get<GotoSchoolTimeMinimum>()[i].seconds() < 0.0 ||
this->get<GotoSchoolTimeMinimum>()[i].seconds() > this->get<GotoSchoolTimeMaximum>()[i].seconds()) {
log_error("Constraint check: Parameter GotoSchoolTimeMinimum of age group {:.0f} smaller {:d} or "
"larger {:d}",
log_error("Constraint check: Parameter GotoSchoolTimeMinimum of age group {} smaller {} or "
"larger {}",
(size_t)i, 0, this->get<GotoWorkTimeMaximum>()[i].seconds());
return true;
}

if (this->get<GotoSchoolTimeMaximum>()[i].seconds() < this->get<GotoSchoolTimeMinimum>()[i].seconds() ||
this->get<GotoSchoolTimeMaximum>()[i] > days(1)) {
log_error("Constraint check: Parameter GotoWorkTimeMaximum of age group {:.0f} smaller {:d} or larger "
log_error("Constraint check: Parameter GotoWorkTimeMaximum of age group {} smaller {} or larger "
"than one day time span",
(size_t)i, this->get<GotoSchoolTimeMinimum>()[i].seconds());
return true;
Expand All @@ -979,31 +979,31 @@ class Parameters : public ParametersBase
if (this->get<MaskProtection>()[MaskType::Community] < 0.0 ||
this->get<MaskProtection>()[MaskType::Community] > 1.0) {
log_error(
"Constraint check: Parameter MaskProtection for MaskType Community is smaller {:d} or larger {:d}", 0,
"Constraint check: Parameter MaskProtection for MaskType Community is smaller {} or larger {}", 0,
1);
return true;
}

if (this->get<MaskProtection>()[MaskType::FFP2] < 0.0 || this->get<MaskProtection>()[MaskType::FFP2] > 1.0) {
log_error("Constraint check: Parameter MaskProtection for MaskType FFP2 is smaller {:d} or larger {:d}", 0,
log_error("Constraint check: Parameter MaskProtection for MaskType FFP2 is smaller {} or larger {}", 0,
1);
return true;
}

if (this->get<MaskProtection>()[MaskType::Surgical] < 0.0 ||
this->get<MaskProtection>()[MaskType::Surgical] > 1.0) {
log_error("Constraint check: Parameter MaskProtection for MaskType Surgical smaller {:d} or larger {:d}", 0,
log_error("Constraint check: Parameter MaskProtection for MaskType Surgical smaller {} or larger {}", 0,
1);
return true;
}

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

if (this->get<QuarantineEffectiveness>() < 0.0 || this->get<QuarantineEffectiveness>() > 1.0) {
log_error("Constraint check: Parameter QuarantineEffectiveness not between {:d,:d}", 0.0, 1.0);
log_error("Constraint check: Parameter QuarantineEffectiveness not between {:d,:d}", 0, 1);
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions cpp/models/glct_secir/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,24 +488,24 @@ class Parameters : public ParametersBase<FP>
// --- Parameters affecting the transmission of the virus. ---
if (this->template get<TransmissionProbabilityOnContact<FP>>() < 0.0 ||
this->template get<TransmissionProbabilityOnContact<FP>>() > 1.0) {
log_error("Constraint check: Parameter TransmissionProbabilityOnContact smaller {:d} or larger {:d}", 0, 1);
log_error("Constraint check: Parameter TransmissionProbabilityOnContact smaller {} or larger {}", 0, 1);
return true;
}

if (this->template get<RelativeTransmissionNoSymptoms<FP>>() < 0.0 ||
this->template get<RelativeTransmissionNoSymptoms<FP>>() > 1.0) {
log_error("Constraint check: Parameter RelativeTransmissionNoSymptoms smaller {:d} or larger {:d}", 0, 1);
log_error("Constraint check: Parameter RelativeTransmissionNoSymptoms smaller {} or larger {}", 0, 1);
return true;
}

if (this->template get<RiskOfInfectionFromSymptomatic<FP>>() < 0.0 ||
this->template get<RiskOfInfectionFromSymptomatic<FP>>() > 1.0) {
log_error("Constraint check: Parameter RiskOfInfectionFromSymptomatic smaller {:d} or larger {:d}", 0, 1);
log_error("Constraint check: Parameter RiskOfInfectionFromSymptomatic smaller {} or larger {}", 0, 1);
return true;
}

if (this->template get<Seasonality<FP>>() < 0.0 || this->template get<Seasonality<FP>>() > 0.5) {
log_warning("Constraint check: Parameter Seasonality should lie between {:0.4f} and {:.4f}", 0.0, 0.5);
log_warning("Constraint check: Parameter Seasonality should lie between {} and {}", 0.0, 0.5);
return true;
}

Expand Down
Loading