parameters.h Source File

CPP API: parameters.h Source File
sde_seirvv/parameters.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Nils Wassmuth, Rene Schmieding, Martin J. Kuehn
5 *
6 * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 
21 #ifndef MIO_SDE_SEIRVV_PARAMETERS_H
22 #define MIO_SDE_SEIRVV_PARAMETERS_H
23 
27 
28 namespace mio
29 {
30 namespace sseirvv
31 {
32 
33 /******************************************
34  * Define Parameters of the SSEIRVV model *
35  ******************************************/
36 
41 template <typename FP>
44  static Type get_default()
45  {
46  return Type(1.0);
47  }
48  static std::string name()
49  {
50  return "TransmissionProbabilityOnContactV1";
51  }
52 };
53 
58 template <typename FP>
61  static Type get_default()
62  {
63  return Type(1.0);
64  }
65  static std::string name()
66  {
67  return "TransmissionProbabilityOnContactV2";
68  }
69 };
70 
74 template <typename FP>
75 struct TimeExposedV1 {
77  static Type get_default()
78  {
79  return Type(6.0);
80  }
81  static std::string name()
82  {
83  return "TimeExposedV1";
84  }
85 };
86 
90 template <typename FP>
91 struct TimeExposedV2 {
93  static Type get_default()
94  {
95  return Type(6.0);
96  }
97  static std::string name()
98  {
99  return "TimeExposedV2";
100  }
101 };
102 
106 template <typename FP>
109  static Type get_default()
110  {
111  return Type(6.0);
112  }
113  static std::string name()
114  {
115  return "TimeInfectedV1";
116  }
117 };
118 
122 template <typename FP>
125  static Type get_default()
126  {
127  return Type(6.0);
128  }
129  static std::string name()
130  {
131  return "TimeInfectedV2";
132  }
133 };
134 
138 template <typename FP>
141  static Type get_default()
142  {
143  return Type{1};
144  }
145  static std::string name()
146  {
147  return "ContactPatterns";
148  }
149 };
150 
151 template <typename FP>
155 
159 template <typename FP>
160 class Parameters : public ParametersBase<FP>
161 {
162 public:
164  : ParametersBase<FP>()
165  {
166  }
167 
182  {
183  FP tol_times = 1e-1;
184 
185  int corrected = false;
186  if (this->template get<TimeExposedV1<FP>>() < tol_times) {
187  log_warning("Constraint check: Parameter TimeExposedV1 changed from {} to {}. Please note that "
188  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
189  "and reset parameters.",
190  this->template get<TimeExposedV1<FP>>(), tol_times);
191  this->template get<TimeExposedV1<FP>>() = tol_times;
192  corrected = true;
193  }
194  if (this->template get<TimeExposedV2<FP>>() < tol_times) {
195  log_warning("Constraint check: Parameter TimeExposedV2 changed from {} to {}. Please note that "
196  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
197  "and reset parameters.",
198  this->template get<TimeExposedV2<FP>>(), tol_times);
199  this->template get<TimeExposedV2<FP>>() = tol_times;
200  corrected = true;
201  }
202  if (this->template get<TimeInfectedV1<FP>>() < tol_times) {
203  log_warning("Constraint check: Parameter TimeInfectedV1 changed from {} to {}. Please note that "
204  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
205  "and reset parameters.",
206  this->template get<TimeInfectedV1<FP>>(), tol_times);
207  this->template get<TimeInfectedV1<FP>>() = tol_times;
208  corrected = true;
209  }
210  if (this->template get<TimeInfectedV2<FP>>() < tol_times) {
211  log_warning("Constraint check: Parameter TimeInfectedV2 changed from {} to {}. Please note that "
212  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
213  "and reset parameters.",
214  this->template get<TimeInfectedV2<FP>>(), tol_times);
215  this->template get<TimeInfectedV2<FP>>() = tol_times;
216  corrected = true;
217  }
218  if (this->template get<TransmissionProbabilityOnContactV1<FP>>() < 0.0 ||
219  this->template get<TransmissionProbabilityOnContactV1<FP>>() > 1.0) {
220  log_warning("Constraint check: Parameter TransmissionProbabilityOnContactV1 changed from {} to {} ",
221  this->template get<TransmissionProbabilityOnContactV1<FP>>(), 0.0);
222  this->template get<TransmissionProbabilityOnContactV1<FP>>() = 0.0;
223  corrected = true;
224  }
225  if (this->template get<TransmissionProbabilityOnContactV2<FP>>() < 0.0 ||
226  this->template get<TransmissionProbabilityOnContactV2<FP>>() > 1.0) {
227  log_warning("Constraint check: Parameter TransmissionProbabilityOnContactV2 changed from {} to {} ",
228  this->template get<TransmissionProbabilityOnContactV2<FP>>(), 0.0);
229  this->template get<TransmissionProbabilityOnContactV2<FP>>() = 0.0;
230  corrected = true;
231  }
232  return corrected;
233  }
234 
240  bool check_constraints() const
241  {
242  FP tol_times = 1e-1;
243 
244  if (this->template get<TimeExposedV1<FP>>() < tol_times) {
245  log_warning("Constraint check: Parameter TimeExposedV1 {} smaller or equal {}. Please note that "
246  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
247  "and reset parameters.",
248  this->template get<TimeExposedV1<FP>>(), tol_times);
249  return true;
250  }
251  if (this->template get<TimeExposedV2<FP>>() < tol_times) {
252  log_warning("Constraint check: Parameter TimeExposedV2 {} smaller or equal {}. Please note that "
253  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
254  "and reset parameters.",
255  this->template get<TimeExposedV2<FP>>(), tol_times);
256  return true;
257  }
258  if (this->template get<TimeInfectedV1<FP>>() < tol_times) {
259  log_warning("Constraint check: Parameter TimeInfectedV1 {} smaller or equal {}. Please note that "
260  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
261  "and reset parameters.",
262  this->template get<TimeInfectedV1<FP>>(), tol_times);
263  return true;
264  }
265  if (this->template get<TimeInfectedV2<FP>>() < tol_times) {
266  log_warning("Constraint check: Parameter TimeInfectedV2 {} smaller or equal {}. Please note that "
267  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
268  "and reset parameters.",
269  this->template get<TimeInfectedV2<FP>>(), tol_times);
270  return true;
271  }
272  if (this->template get<TransmissionProbabilityOnContactV1<FP>>() < 0.0 ||
273  this->template get<TransmissionProbabilityOnContactV1<FP>>() > 1.0) {
274  log_error("Constraint check: Parameter TransmissionProbabilityOnContactV1 {} smaller {} or greater "
275  "{}",
276  this->template get<TransmissionProbabilityOnContactV1<FP>>(), 0.0, 1.0);
277  return true;
278  }
279  if (this->template get<TransmissionProbabilityOnContactV2<FP>>() < 0.0 ||
280  this->template get<TransmissionProbabilityOnContactV2<FP>>() > 1.0) {
281  log_error("Constraint check: Parameter TransmissionProbabilityOnContactV2 {} smaller {} or greater "
282  "{}",
283  this->template get<TransmissionProbabilityOnContactV2<FP>>(), 0.0, 1.0);
284  return true;
285  }
286  return false;
287  }
288 
289 private:
291  : ParametersBase<FP>(std::move(base))
292  {
293  }
294 
295 public:
300  template <class IOContext>
301  static IOResult<Parameters> deserialize(IOContext& io)
302  {
303  BOOST_OUTCOME_TRY(auto&& base, ParametersBase<FP>::deserialize(io));
304  return success(Parameters(std::move(base)));
305  }
306 };
307 
308 } // namespace sseirvv
309 } // namespace mio
310 
311 #endif // MIO_SDE_SEIRVV_PARAMETERS_H
represents time dependent contact frequencies between groups.
Definition: contact_matrix.h:505
a set of parameters defined at compile time
Definition: parameter_set.h:205
const ParameterTagTraits< Tag >::Type & get() const
get value of a parameter
Definition: parameter_set.h:262
Parameters of stochastic SEIRVV model.
Definition: sde_seirvv/parameters.h:161
bool check_constraints() const
Checks whether all Parameters satisfy their corresponding constraints and logs an error if constraint...
Definition: sde_seirvv/parameters.h:240
Parameters()
Definition: sde_seirvv/parameters.h:163
static IOResult< Parameters > deserialize(IOContext &io)
Deserialize an object of this class.
Definition: sde_seirvv/parameters.h:301
bool apply_constraints()
Checks whether all Parameters satisfy their corresponding constraints and applies them,...
Definition: sde_seirvv/parameters.h:181
Parameters(ParametersBase< FP > &&base)
Definition: sde_seirvv/parameters.h:290
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
void log_warning(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:112
auto success()
Create an object that is implicitly convertible to a succesful IOResult<void>.
Definition: io.h:359
void log_error(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:100
boost::outcome_v2::unchecked< T, IOStatus > IOResult
Value-or-error type for operations that return a value but can fail.
Definition: io.h:353
Definition: io.h:94
The contact patterns within the society are modelled using a ContactMatrix.
Definition: sde_seirvv/parameters.h:139
static Type get_default()
Definition: sde_seirvv/parameters.h:141
static std::string name()
Definition: sde_seirvv/parameters.h:145
The latent time of variant 1 in days.
Definition: sde_seirvv/parameters.h:75
UncertainValue< FP > Type
Definition: sde_seirvv/parameters.h:76
static Type get_default()
Definition: sde_seirvv/parameters.h:77
static std::string name()
Definition: sde_seirvv/parameters.h:81
The latent time of variant 2 in days.
Definition: sde_seirvv/parameters.h:91
static Type get_default()
Definition: sde_seirvv/parameters.h:93
UncertainValue< FP > Type
Definition: sde_seirvv/parameters.h:92
static std::string name()
Definition: sde_seirvv/parameters.h:97
The infectious time of variant 1 in days.
Definition: sde_seirvv/parameters.h:107
static Type get_default()
Definition: sde_seirvv/parameters.h:109
static std::string name()
Definition: sde_seirvv/parameters.h:113
UncertainValue< FP > Type
Definition: sde_seirvv/parameters.h:108
The infectious time of variant 2 in days.
Definition: sde_seirvv/parameters.h:123
static std::string name()
Definition: sde_seirvv/parameters.h:129
UncertainValue< FP > Type
Definition: sde_seirvv/parameters.h:124
static Type get_default()
Definition: sde_seirvv/parameters.h:125
Probability of getting infected from a contact with variant 1.
Definition: sde_seirvv/parameters.h:42
UncertainValue< FP > Type
Definition: sde_seirvv/parameters.h:43
static std::string name()
Definition: sde_seirvv/parameters.h:48
static Type get_default()
Definition: sde_seirvv/parameters.h:44
Probability of getting infected from a contact with variant 2.
Definition: sde_seirvv/parameters.h:59
static std::string name()
Definition: sde_seirvv/parameters.h:65
static Type get_default()
Definition: sde_seirvv/parameters.h:61
UncertainValue< FP > Type
Definition: sde_seirvv/parameters.h:60