Skip to content

Commit 6ace2e5

Browse files
kilianvolmercharlie0614mknaranja
authored
Improve messages related to parameter checks (#1414)
Co-authored-by: Carlotta Gerstein <carlotta-gerstein@web.de> Co-authored-by: Kühn <Martin.Kuehn@dlr.de>
1 parent b128e05 commit 6ace2e5

File tree

16 files changed

+231
-194
lines changed

16 files changed

+231
-194
lines changed

cpp/memilio/epidemiology/lct_populations.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ class LctPopulations
168168
bool corrected = false;
169169
for (int i = 0; i < m_y.array().size(); i++) {
170170
if (m_y.array()[i] < 0.0) {
171-
log_warning("Constraint check: Compartment size {:d} changed from {:.4f} to {:d}", i, m_y.array()[i],
172-
0);
171+
if (m_y.array()[i] > -1e-10) {
172+
log_warning("Constraint check: Compartment number {} changed from {} to {}", i, m_y.array()[i], 0);
173+
}
174+
else {
175+
log_error("Constraint check: Compartment number {} changed from {} to {}", i, m_y.array()[i], 0);
176+
}
173177
m_y.array()[i] = 0.;
174178
corrected = true;
175179
}

cpp/memilio/epidemiology/populations.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ class Populations : public CustomIndexArray<UncertainValue<FP>, Categories...>
231231
/**
232232
* @brief Checks whether all compartments have non-negative values.
233233
* This function can be used to prevent slighly negative function values in compartment sizes that came out
234-
* due to roundoff errors if, e.g., population sizes were computed in a complex way.
234+
* due to roundoff errors if, e.g., population sizes were computed in a complex way. If negative values
235+
* which are smaller than -1e-10 are found, an error is logged, otherwise, only a warning is logged.
235236
*
236237
* Attention: This function should be used with care. It can not and will not set model parameters and
237238
* compartments to meaningful values. In most cases it is preferable to use check_constraints,
@@ -245,8 +246,13 @@ class Populations : public CustomIndexArray<UncertainValue<FP>, Categories...>
245246
bool corrected = false;
246247
for (int i = 0; i < this->array().size(); i++) {
247248
if (this->array()[i] < 0.0) {
248-
log_warning("Constraint check: Compartment size {:d} changed from {:.4f} to {:d}", i, this->array()[i],
249-
0);
249+
if (this->array()[i] > -1e-10) {
250+
log_warning("Constraint check: Compartment number {} changed from {} to {}", i, this->array()[i],
251+
0);
252+
}
253+
else {
254+
log_error("Constraint check: Compartment number {} changed from {} to {}", i, this->array()[i], 0);
255+
}
250256
this->array()[i] = 0.0;
251257
corrected = true;
252258
}
@@ -263,7 +269,7 @@ class Populations : public CustomIndexArray<UncertainValue<FP>, Categories...>
263269
for (int i = 0; i < this->array().size(); i++) {
264270
FP value = this->array()[i];
265271
if (value < 0.0) {
266-
log_error("Constraint check: Compartment size {} is {} and smaller {}", i, value, 0);
272+
log_error("Constraint check: Compartment number {} is {} and smaller {}", i, value, 0);
267273
return true;
268274
}
269275
}

cpp/models/abm/parameters.h

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -799,177 +799,177 @@ class Parameters : public ParametersBase
799799

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

970970
if (this->get<GotoSchoolTimeMaximum>()[i].seconds() < this->get<GotoSchoolTimeMinimum>()[i].seconds() ||
971971
this->get<GotoSchoolTimeMaximum>()[i] > days(1)) {
972-
log_error("Constraint check: Parameter GotoWorkTimeMaximum of age group {:.0f} smaller {:d} or larger "
972+
log_error("Constraint check: Parameter GotoWorkTimeMaximum of age group {} smaller {} or larger "
973973
"than one day time span",
974974
(size_t)i, this->get<GotoSchoolTimeMinimum>()[i].seconds());
975975
return true;
@@ -979,31 +979,31 @@ class Parameters : public ParametersBase
979979
if (this->get<MaskProtection>()[MaskType::Community] < 0.0 ||
980980
this->get<MaskProtection>()[MaskType::Community] > 1.0) {
981981
log_error(
982-
"Constraint check: Parameter MaskProtection for MaskType Community is smaller {:d} or larger {:d}", 0,
982+
"Constraint check: Parameter MaskProtection for MaskType Community is smaller {} or larger {}", 0,
983983
1);
984984
return true;
985985
}
986986

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

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

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

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

cpp/models/glct_secir/parameters.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,24 +488,24 @@ class Parameters : public ParametersBase<FP>
488488
// --- Parameters affecting the transmission of the virus. ---
489489
if (this->template get<TransmissionProbabilityOnContact<FP>>() < 0.0 ||
490490
this->template get<TransmissionProbabilityOnContact<FP>>() > 1.0) {
491-
log_error("Constraint check: Parameter TransmissionProbabilityOnContact smaller {:d} or larger {:d}", 0, 1);
491+
log_error("Constraint check: Parameter TransmissionProbabilityOnContact smaller {} or larger {}", 0, 1);
492492
return true;
493493
}
494494

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

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

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

0 commit comments

Comments
 (0)