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.1);
248  }
249  static std::string name()
250  {
251  return "DeathsPerCritical";
252  }
253 };
254 
261 template <typename FP>
262 struct StartDay {
263  using Type = FP;
264  static Type get_default(size_t)
265  {
266  return Type(0.0);
267  }
268  static std::string name()
269  {
270  return "StartDay";
271  }
272 };
273 
279 template <typename FP>
280 struct Seasonality {
281  using Type = ScalarType;
282  static Type get_default(size_t)
283  {
284  return Type(0.0);
285  }
286  static std::string name()
287  {
288  return "Seasonality";
289  }
290 };
291 
292 template <typename FP>
299 
303 template <typename FP>
304 class Parameters : public ParametersBase<FP>
305 {
306 public:
311  Parameters(size_t num_groups)
312  : ParametersBase<FP>(num_groups)
313  , m_num_groups{num_groups}
314  {
315  }
316 
317  size_t get_num_groups() const
318  {
319  return m_num_groups;
320  }
321 
326  bool check_constraints() const
327  {
328  if (this->template get<Seasonality<FP>>() < 0.0 || this->template get<Seasonality<FP>>() > 0.5) {
329  log_warning("Constraint check: Parameter Seasonality should lie between {} and {}", 0.0, 0.5);
330  return true;
331  }
332 
333  for (size_t i = 0; i < m_num_groups; ++i) {
334  if (this->template get<TimeExposed<FP>>()[i] < 1.0) {
335  log_error("Constraint check: Parameter TimeExposed is smaller than {}", 1.0);
336  return true;
337  }
338 
339  if (this->template get<TimeInfectedNoSymptoms<FP>>()[i] < 1.0) {
340  log_error("Constraint check: Parameter TimeInfectedNoSymptoms is smaller than {}", 1.0);
341  return true;
342  }
343 
344  if (this->template get<TimeInfectedSymptoms<FP>>()[i] < 1.0) {
345  log_error("Constraint check: Parameter TimeInfectedSymptoms is smaller than {}", 1.0);
346  return true;
347  }
348 
349  if (this->template get<TimeInfectedSevere<FP>>()[i] < 1.0) {
350  log_error("Constraint check: Parameter TimeInfectedSevere is smaller than {}", 1.0);
351  return true;
352  }
353 
354  if (this->template get<TimeInfectedCritical<FP>>()[i] < 1.0) {
355  log_error("Constraint check: Parameter TimeInfectedCritical is smaller than {}", 1.0);
356  return true;
357  }
358 
359  if (this->template get<TransmissionProbabilityOnContact<FP>>()[i] < 0.0 ||
360  this->template get<TransmissionProbabilityOnContact<FP>>()[i] > 1.0) {
361  log_error("Constraint check: Parameter TransmissionProbabilityOnContact smaller {} or larger {}", 0, 1);
362  return true;
363  }
364 
365  if (this->template get<RelativeTransmissionNoSymptoms<FP>>()[i] < 0.0 ||
366  this->template get<RelativeTransmissionNoSymptoms<FP>>()[i] > 1.0) {
367  log_error("Constraint check: Parameter RelativeTransmissionNoSymptoms smaller {} or larger {}", 0, 1);
368  return true;
369  }
370 
371  if (this->template get<RiskOfInfectionFromSymptomatic<FP>>()[i] < 0.0 ||
372  this->template get<RiskOfInfectionFromSymptomatic<FP>>()[i] > 1.0) {
373  log_error("Constraint check: Parameter RiskOfInfectionFromSymptomatic smaller {} or larger {}", 0, 1);
374  return true;
375  }
376 
377  if (this->template get<RecoveredPerInfectedNoSymptoms<FP>>()[i] < 0.0 ||
378  this->template get<RecoveredPerInfectedNoSymptoms<FP>>()[i] > 1.0) {
379  log_error("Constraint check: Parameter RecoveredPerInfectedNoSymptoms smaller {} or larger {}", 0, 1);
380  return true;
381  }
382 
383  if (this->template get<SeverePerInfectedSymptoms<FP>>()[i] < 0.0 ||
384  this->template get<SeverePerInfectedSymptoms<FP>>()[i] > 1.0) {
385  log_error("Constraint check: Parameter SeverePerInfectedSymptoms smaller {} or larger {}", 0, 1);
386  return true;
387  }
388 
389  if (this->template get<CriticalPerSevere<FP>>()[i] < 0.0 ||
390  this->template get<CriticalPerSevere<FP>>()[i] > 1.0) {
391  log_error("Constraint check: Parameter CriticalPerSevere smaller {} or larger {}", 0, 1);
392  return true;
393  }
394 
395  if (this->template get<DeathsPerCritical<FP>>()[i] < 0.0 ||
396  this->template get<DeathsPerCritical<FP>>()[i] > 1.0) {
397  log_error("Constraint check: Parameter DeathsPerCritical smaller {} or larger {}", 0, 1);
398  return true;
399  }
400  }
401 
402  return false;
403  }
404 
405 private:
407  : ParametersBase<FP>(std::move(base))
408  , m_num_groups(this->template get<ContactPatterns<FP>>().get_cont_freq_mat().get_num_groups())
409  {
410  }
411 
412  size_t m_num_groups;
413 
414 public:
419  template <class IOContext>
420  static IOResult<Parameters> deserialize(IOContext& io)
421  {
422  BOOST_OUTCOME_TRY(auto&& base, ParametersBase<FP>::deserialize(io));
423  return success(Parameters(std::move(base)));
424  }
425 };
426 
427 } // namespace lsecir
428 } // namespace mio
429 
430 #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:305
static IOResult< Parameters > deserialize(IOContext &io)
deserialize an object of this class.
Definition: lct_secir/parameters.h:420
size_t m_num_groups
Definition: lct_secir/parameters.h:412
size_t get_num_groups() const
Definition: lct_secir/parameters.h:317
Parameters(size_t num_groups)
Constructor.
Definition: lct_secir/parameters.h:311
Parameters(ParametersBase< FP > &&base)
Definition: lct_secir/parameters.h:406
bool check_constraints() const
Checks whether all parameters satisfy their corresponding constraints and throws errors,...
Definition: lct_secir/parameters.h:326
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:809
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 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:243
Eigen::VectorX< UncertainValue< FP > > Type
Definition: lct_secir/parameters.h:244
static Type get_default(size_t size)
Definition: lct_secir/parameters.h:245
static std::string name()
Definition: lct_secir/parameters.h:249
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:280
static Type get_default(size_t)
Definition: lct_secir/parameters.h:282
static std::string name()
Definition: lct_secir/parameters.h:286
ScalarType Type
Definition: lct_secir/parameters.h:281
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:262
static std::string name()
Definition: lct_secir/parameters.h:268
static Type get_default(size_t)
Definition: lct_secir/parameters.h:264
FP Type
Definition: lct_secir/parameters.h:263
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