parameters.h Source File

CPP API: parameters.h Source File
lct_secir/parameters.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Lena Ploetzke
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 LCT_SECIR_PARAMS_H
22 #define LCT_SECIR_PARAMS_H
23 
24 #include "memilio/config.h"
25 #include "memilio/math/eigen.h"
28 #include "memilio/utils/logging.h"
30 
31 namespace mio
32 {
33 namespace lsecir
34 {
35 
36 /**********************************************
37 * Define Parameters of the LCT-SECIHURD model *
38 **********************************************/
39 
43 template <typename FP>
44 struct TimeExposed {
45  using Type = Eigen::VectorX<UncertainValue<FP>>;
46  static Type get_default(size_t size)
47  {
48  return Type::Constant(size, 1, 1.);
49  }
50  static std::string name()
51  {
52  return "TimeExposed";
53  }
54 };
55 
60 template <typename FP>
62  using Type = Eigen::VectorX<UncertainValue<FP>>;
63  static Type get_default(size_t size)
64  {
65  return Type::Constant(size, 1, 1.);
66  }
67  static std::string name()
68  {
69  return "TimeInfectedNoSymptoms";
70  }
71 };
72 
77 template <typename FP>
79  using Type = Eigen::VectorX<UncertainValue<FP>>;
80  static Type get_default(size_t size)
81  {
82  return Type::Constant(size, 1, 1.);
83  }
84  static std::string name()
85  {
86  return "TimeInfectedNoSymptoms";
87  }
88 };
89 
94 template <typename FP>
96  using Type = Eigen::VectorX<UncertainValue<FP>>;
97  static Type get_default(size_t size)
98  {
99  return Type::Constant(size, 1, 1.);
100  }
101  static std::string name()
102  {
103  return "TimeInfectedSevere";
104  }
105 };
106 
110 template <typename FP>
112  using Type = Eigen::VectorX<UncertainValue<FP>>;
113  static Type get_default(size_t size)
114  {
115  return Type::Constant(size, 1, 1.);
116  }
117  static std::string name()
118  {
119  return "TimeInfectedCritical";
120  }
121 };
122 
126 template <typename FP>
128  using Type = Eigen::VectorX<UncertainValue<FP>>;
129  static Type get_default(size_t size)
130  {
131  return Type::Constant(size, 1, 1.);
132  }
133  static std::string name()
134  {
135  return "TransmissionProbabilityOnContact";
136  }
137 };
138 
142 template <typename FP>
145 
146  static Type get_default(size_t size)
147  {
148  mio::ContactMatrixGroup<FP> contact_matrix(1, (Eigen::Index)size);
149  contact_matrix[0] =
150  mio::ContactMatrix<FP>(Eigen::MatrixX<FP>::Constant((Eigen::Index)size, (Eigen::Index)size, 10.));
151  return Type(contact_matrix);
152  }
153  static std::string name()
154  {
155  return "ContactPatterns";
156  }
157 };
158 
162 template <typename FP>
164  using Type = Eigen::VectorX<UncertainValue<FP>>;
165  static Type get_default(size_t size)
166  {
167  return Type::Constant(size, 1, 1.);
168  }
169  static std::string name()
170  {
171  return "RelativeTransmissionNoSymptoms";
172  }
173 };
174 
178 template <typename FP>
180  using Type = Eigen::VectorX<UncertainValue<FP>>;
181  static Type get_default(size_t size)
182  {
183  return Type::Constant(size, 1, 1.);
184  }
185  static std::string name()
186  {
187  return "RiskOfInfectionFromSymptomatic";
188  }
189 };
190 
194 template <typename FP>
196  using Type = Eigen::VectorX<UncertainValue<FP>>;
197  static Type get_default(size_t size)
198  {
199  return Type::Constant(size, 1, 0.5);
200  }
201  static std::string name()
202  {
203  return "RecoveredPerInfectedNoSymptoms";
204  }
205 };
206 
210 template <typename FP>
212  using Type = Eigen::VectorX<UncertainValue<FP>>;
213  static Type get_default(size_t size)
214  {
215  return Type::Constant(size, 1, 0.5);
216  }
217  static std::string name()
218  {
219  return "SeverePerInfectedSymptoms";
220  }
221 };
222 
226 template <typename FP>
228  using Type = Eigen::VectorX<UncertainValue<FP>>;
229  static Type get_default(size_t size)
230  {
231  return Type::Constant(size, 1, 0.5);
232  }
233  static std::string name()
234  {
235  return "CriticalPerSevere";
236  }
237 };
238 
242 template <typename FP>
244  using Type = Eigen::VectorX<UncertainValue<FP>>;
245  static Type get_default(size_t size)
246  {
247  return Type::Constant(size, 1, 0.);
248  }
249  static std::string name()
250  {
251  return "DeathsPerSevere";
252  }
253 };
254 
258 template <typename FP>
260  using Type = Eigen::VectorX<UncertainValue<FP>>;
261  static Type get_default(size_t size)
262  {
263  return Type::Constant(size, 1, 0.1);
264  }
265  static std::string name()
266  {
267  return "DeathsPerCritical";
268  }
269 };
270 
277 template <typename FP>
278 struct StartDay {
279  using Type = FP;
280  static Type get_default(size_t)
281  {
282  return Type(0.0);
283  }
284  static std::string name()
285  {
286  return "StartDay";
287  }
288 };
289 
295 template <typename FP>
296 struct Seasonality {
297  using Type = ScalarType;
298  static Type get_default(size_t)
299  {
300  return Type(0.0);
301  }
302  static std::string name()
303  {
304  return "Seasonality";
305  }
306 };
307 
308 template <typename FP>
315 
319 template <typename FP>
320 class Parameters : public ParametersBase<FP>
321 {
322 public:
327  Parameters(size_t num_groups)
328  : ParametersBase<FP>(num_groups)
329  , m_num_groups{num_groups}
330  {
331  }
332 
333  size_t get_num_groups() const
334  {
335  return m_num_groups;
336  }
337 
342  bool check_constraints() const
343  {
344  if (this->template get<Seasonality<FP>>() < 0.0 || this->template get<Seasonality<FP>>() > 0.5) {
345  log_warning("Constraint check: Parameter Seasonality should lie between {} and {}", 0.0, 0.5);
346  return true;
347  }
348 
349  for (size_t i = 0; i < m_num_groups; ++i) {
350  if (this->template get<TimeExposed<FP>>()[i] < 1.0) {
351  log_error("Constraint check: Parameter TimeExposed is smaller than {}", 1.0);
352  return true;
353  }
354 
355  if (this->template get<TimeInfectedNoSymptoms<FP>>()[i] < 1.0) {
356  log_error("Constraint check: Parameter TimeInfectedNoSymptoms is smaller than {}", 1.0);
357  return true;
358  }
359 
360  if (this->template get<TimeInfectedSymptoms<FP>>()[i] < 1.0) {
361  log_error("Constraint check: Parameter TimeInfectedSymptoms is smaller than {}", 1.0);
362  return true;
363  }
364 
365  if (this->template get<TimeInfectedSevere<FP>>()[i] < 1.0) {
366  log_error("Constraint check: Parameter TimeInfectedSevere is smaller than {}", 1.0);
367  return true;
368  }
369 
370  if (this->template get<TimeInfectedCritical<FP>>()[i] < 1.0) {
371  log_error("Constraint check: Parameter TimeInfectedCritical is smaller than {}", 1.0);
372  return true;
373  }
374 
375  if (this->template get<TransmissionProbabilityOnContact<FP>>()[i] < 0.0 ||
376  this->template get<TransmissionProbabilityOnContact<FP>>()[i] > 1.0) {
377  log_error("Constraint check: Parameter TransmissionProbabilityOnContact smaller {} or larger {}", 0, 1);
378  return true;
379  }
380 
381  if (this->template get<RelativeTransmissionNoSymptoms<FP>>()[i] < 0.0 ||
382  this->template get<RelativeTransmissionNoSymptoms<FP>>()[i] > 1.0) {
383  log_error("Constraint check: Parameter RelativeTransmissionNoSymptoms smaller {} or larger {}", 0, 1);
384  return true;
385  }
386 
387  if (this->template get<RiskOfInfectionFromSymptomatic<FP>>()[i] < 0.0 ||
388  this->template get<RiskOfInfectionFromSymptomatic<FP>>()[i] > 1.0) {
389  log_error("Constraint check: Parameter RiskOfInfectionFromSymptomatic smaller {} or larger {}", 0, 1);
390  return true;
391  }
392 
393  if (this->template get<RecoveredPerInfectedNoSymptoms<FP>>()[i] < 0.0 ||
394  this->template get<RecoveredPerInfectedNoSymptoms<FP>>()[i] > 1.0) {
395  log_error("Constraint check: Parameter RecoveredPerInfectedNoSymptoms smaller {} or larger {}", 0, 1);
396  return true;
397  }
398 
399  if (this->template get<SeverePerInfectedSymptoms<FP>>()[i] < 0.0 ||
400  this->template get<SeverePerInfectedSymptoms<FP>>()[i] > 1.0) {
401  log_error("Constraint check: Parameter SeverePerInfectedSymptoms smaller {} or larger {}", 0, 1);
402  return true;
403  }
404 
405  if (this->template get<CriticalPerSevere<FP>>()[i] < 0.0 ||
406  this->template get<CriticalPerSevere<FP>>()[i] > 1.0) {
407  log_error("Constraint check: Parameter CriticalPerSevere smaller {} or larger {}", 0, 1);
408  return true;
409  }
410 
411  if (this->template get<DeathsPerSevere<FP>>()[i] < 0.0 ||
412  this->template get<DeathsPerSevere<FP>>()[i] > 1.0) {
413  log_error("Constraint check: Parameter DeathsPerSevere smaller {} or larger {}", 0, 1);
414  return true;
415  }
416 
417  if (this->template get<CriticalPerSevere<FP>>()[i] + this->template get<DeathsPerSevere<FP>>()[i] > 1.0) {
418  log_error("Constraint check: CriticalPerSevere + DeathsPerSevere exceed 1.0 for age group {}.",
419  static_cast<size_t>(i));
420  return true;
421  }
422 
423  if (this->template get<DeathsPerCritical<FP>>()[i] < 0.0 ||
424  this->template get<DeathsPerCritical<FP>>()[i] > 1.0) {
425  log_error("Constraint check: Parameter DeathsPerCritical smaller {} or larger {}", 0, 1);
426  return true;
427  }
428  }
429 
430  return false;
431  }
432 
433 private:
435  : ParametersBase<FP>(std::move(base))
436  , m_num_groups(this->template get<ContactPatterns<FP>>().get_cont_freq_mat().get_num_groups())
437  {
438  }
439 
440  size_t m_num_groups;
441 
442 public:
447  template <class IOContext>
448  static IOResult<Parameters> deserialize(IOContext& io)
449  {
450  BOOST_OUTCOME_TRY(auto&& base, ParametersBase<FP>::deserialize(io));
451  return success(Parameters(std::move(base)));
452  }
453 };
454 
455 } // namespace lsecir
456 } // namespace mio
457 
458 #endif // LCT_SECIR_PARAMS_H
represents a collection of contact frequency matrices that whose sum is the total number of contacts.
Definition: contact_matrix.h:536
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
The UncertainContactMatrix class consists of a ContactMatrix with fixed baseline and uncertain Dampin...
Definition: uncertain_matrix.h:43
Parameters of an LCT-SECIR model.
Definition: lct_secir/parameters.h:321
static IOResult< Parameters > deserialize(IOContext &io)
deserialize an object of this class.
Definition: lct_secir/parameters.h:448
size_t m_num_groups
Definition: lct_secir/parameters.h:440
size_t get_num_groups() const
Definition: lct_secir/parameters.h:333
Parameters(size_t num_groups)
Constructor.
Definition: lct_secir/parameters.h:327
Parameters(ParametersBase< FP > &&base)
Definition: lct_secir/parameters.h:434
bool check_constraints() const
Checks whether all parameters satisfy their corresponding constraints and throws errors,...
Definition: lct_secir/parameters.h:342
double ScalarType
Configuration of memilio library.
Definition: memilio/config.h:30
int size(Comm comm)
Return the size of the given communicator.
Definition: miompi.cpp:75
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
auto i
Definition: io.h:810
void log_warning(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:126
auto success()
Create an object that is implicitly convertible to a succesful IOResult<void>.
Definition: io.h:360
void log_error(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:114
boost::outcome_v2::unchecked< T, IOStatus > IOResult
Value-or-error type for operations that return a value but can fail.
Definition: io.h:354
Definition: io.h:95
The contact patterns within the society are modelled using an UncertainContactMatrix.
Definition: lct_secir/parameters.h:143
static std::string name()
Definition: lct_secir/parameters.h:153
UncertainContactMatrix< FP > Type
Definition: lct_secir/parameters.h:144
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:146
The percentage of ICU patients per hospitalized patients for each group in the SECIR model.
Definition: lct_secir/parameters.h:227
static std::string name()
Definition: lct_secir/parameters.h:233
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:228
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:229
The percentage of dead patients per ICU patients for each group in the SECIR model.
Definition: lct_secir/parameters.h:259
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:260
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:261
static std::string name()
Definition: lct_secir/parameters.h:265
The percentage of dead patients per hospitalized patients for each group in the SECIR model.
Definition: lct_secir/parameters.h:243
static std::string name()
Definition: lct_secir/parameters.h:249
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:244
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:245
The percentage of asymptomatic cases for each group in the SECIR model.
Definition: lct_secir/parameters.h:195
static std::string name()
Definition: lct_secir/parameters.h:201
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:196
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:197
The relative InfectedNoSymptoms infectability for each group.
Definition: lct_secir/parameters.h:163
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:165
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:164
static std::string name()
Definition: lct_secir/parameters.h:169
The risk of infection from symptomatic cases for each group in the SECIR model.
Definition: lct_secir/parameters.h:179
static std::string name()
Definition: lct_secir/parameters.h:185
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:180
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:181
The seasonality in the LCT-SECIR model.
Definition: lct_secir/parameters.h:296
static Type get_default(size_t)
Definition: lct_secir/parameters.h:298
static std::string name()
Definition: lct_secir/parameters.h:302
ScalarType Type
Definition: lct_secir/parameters.h:297
The percentage of hospitalized patients per infected patients for each group in the SECIR model.
Definition: lct_secir/parameters.h:211
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:212
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:213
static std::string name()
Definition: lct_secir/parameters.h:217
The start day in the LCT SECIR model.
Definition: lct_secir/parameters.h:278
static std::string name()
Definition: lct_secir/parameters.h:284
static Type get_default(size_t)
Definition: lct_secir/parameters.h:280
FP Type
Definition: lct_secir/parameters.h:279
Average time spent in the Exposed compartment for each group.
Definition: lct_secir/parameters.h:44
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:46
static std::string name()
Definition: lct_secir/parameters.h:50
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:45
Average time treated by ICU before dead or recover for each group in the SECIR model in day unit.
Definition: lct_secir/parameters.h:111
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:112
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:113
static std::string name()
Definition: lct_secir/parameters.h:117
Average time spent in the TimeInfectedNoSymptoms before developing symptoms or recover for each group...
Definition: lct_secir/parameters.h:61
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:62
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:63
static std::string name()
Definition: lct_secir/parameters.h:67
Average time being in the Hospital before treated by ICU or recover for each group in the SECIR model...
Definition: lct_secir/parameters.h:95
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:97
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:96
static std::string name()
Definition: lct_secir/parameters.h:101
Average time spent in the TimeInfectedSymptoms before going to hospital or recover for each group in ...
Definition: lct_secir/parameters.h:78
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:79
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:80
static std::string name()
Definition: lct_secir/parameters.h:84
Probability of getting infected from a contact for each group.
Definition: lct_secir/parameters.h:127
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:128
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:129
static std::string name()
Definition: lct_secir/parameters.h:133