parameters.h Source File

CPP API: parameters.h Source File
ode_seirdb/parameters.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Daniel Abele, Jan Kleinert, 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 #ifndef SEIRDB_PARAMETERS_H
21 #define SEIRDB_PARAMETERS_H
22 
23 #include "memilio/config.h"
29 
30 namespace mio
31 {
32 namespace oseirdb
33 {
34 
35 /***************************************
36  * Define Parameters of the SEIRDB model *
37  ***************************************/
38 
42 template <typename FP>
46  {
47  return Type(size, 1.);
48  }
49  static std::string name()
50  {
51  return "TransmissionProbabilityOnContact";
52  }
53 };
54 
58 template <typename FP>
59 struct TimeExposed {
62  {
63  return Type(size, 5.2);
64  }
65  static std::string name()
66  {
67  return "TimeExposed";
68  }
69 };
70 
74 template <typename FP>
75 struct TimeInfected {
78  {
79  return Type(size, 6.0);
80  }
81  static std::string name()
82  {
83  return "TimeInfected";
84  }
85 };
86 
90 template <typename FP>
94  {
95  return Type(size, 0.5);
96  }
97  static std::string name()
98  {
99  return "ProbabilityToRecover";
100  }
101 };
102 
106 template <typename FP>
110  {
111  return Type(size, 0.05);
112  }
113  static std::string name()
114  {
115  return "TransmissionProbabilityFromDead";
116  }
117 };
118 
122 template <typename FP>
123 struct TimeToBurial {
126  {
127  return Type(size, 2.0);
128  }
129  static std::string name()
130  {
131  return "TimeToBurial";
132  }
133 };
134 
138 template <class FP>
142  {
143  return Type(1, static_cast<Eigen::Index>((size_t)size));
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:
163  Parameters(AgeGroup num_agegroups)
164  : ParametersBase<FP>(num_agegroups)
165  , m_num_groups{num_agegroups}
166  {
167  }
168 
170  {
171  return m_num_groups;
172  }
173 
188  {
189  const FP tol_times = 1e-1;
190 
191  int corrected = false;
192 
193  for (auto i = AgeGroup(0); i < AgeGroup(m_num_groups); ++i) {
194  if (this->template get<TimeExposed<FP>>()[i] < tol_times) {
195  log_warning(
196  "Constraint check: Parameter TimeExposed changed from {} to {}. Please note that "
197  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
198  "and reset parameters.",
199  this->template get<TimeExposed<FP>>()[i], tol_times);
200  this->template get<TimeExposed<FP>>()[i] = tol_times;
201  corrected = true;
202  }
203  if (this->template get<TimeToBurial<FP>>()[i] < tol_times) {
204  log_warning("Constraint check: Parameter TimeToBurial changed from {} to {}.",
205  this->template get<TimeToBurial<FP>>()[i], tol_times);
206  this->template get<TimeToBurial<FP>>()[i] = tol_times;
207  corrected = true;
208  }
209  if (this->template get<TimeInfected<FP>>()[i] < tol_times) {
210  log_warning(
211  "Constraint check: Parameter TimeInfected 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<TimeInfected<FP>>()[i], tol_times);
215  this->template get<TimeInfected<FP>>()[i] = tol_times;
216  corrected = true;
217  }
218  if (this->template get<TransmissionProbabilityOnContact<FP>>()[i] < 0.0 ||
219  this->template get<TransmissionProbabilityOnContact<FP>>()[i] > 1.0) {
220  log_warning("Constraint check: Parameter TransmissionProbabilityOnContact changed from {} to {} ",
221  this->template get<TransmissionProbabilityOnContact<FP>>()[i], 0.0);
222  this->template get<TransmissionProbabilityOnContact<FP>>()[i] = 0.0;
223  corrected = true;
224  }
225  if (this->template get<TransmissionProbabilityFromDead<FP>>()[i] < 0.0 ||
226  this->template get<TransmissionProbabilityFromDead<FP>>()[i] > 1.0) {
227  log_warning("Constraint check: Parameter TransmissionProbabilityFromDead changed from {} to {} ",
228  this->template get<TransmissionProbabilityFromDead<FP>>()[i], 0.0);
229  this->template get<TransmissionProbabilityFromDead<FP>>()[i] = 0.0;
230  corrected = true;
231  }
232  if (this->template get<ProbabilityToRecover<FP>>()[i] < 0.0 ||
233  this->template get<ProbabilityToRecover<FP>>()[i] > 1.0) {
234  log_warning("Constraint check: Parameter ProbabilityToRecover changed from {} to {} ",
235  this->template get<ProbabilityToRecover<FP>>()[i], 0.0);
236  this->template get<ProbabilityToRecover<FP>>()[i] = 0.0;
237  corrected = true;
238  }
239  }
240  return corrected;
241  }
242 
248  bool check_constraints() const
249  {
250  const FP tol_times = 1e-1;
251 
252  for (auto i = AgeGroup(0); i < m_num_groups; i++) {
253  if (this->template get<TimeExposed<FP>>()[i] < tol_times) {
254  log_warning(
255  "Constraint check: Parameter TimeExposed {} smaller or equal {}. Please note that "
256  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
257  "and reset parameters.",
258  this->template get<TimeExposed<FP>>()[i], 0.0);
259  return true;
260  }
261  if (this->template get<TimeInfected<FP>>()[i] < tol_times) {
262  log_warning(
263  "Constraint check: Parameter TimeInfected {} smaller or equal {}. Please note that "
264  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
265  "and reset parameters.",
266  this->template get<TimeInfected<FP>>()[i], 0.0);
267  return true;
268  }
269  if (this->template get<TimeToBurial<FP>>()[i] < tol_times) {
270  log_warning("Constraint check: Parameter TimeToBurial {} smaller or equal {}.",
271  this->template get<TimeToBurial<FP>>()[i], 0.0);
272  return true;
273  }
274  if (this->template get<TransmissionProbabilityOnContact<FP>>()[i] < 0.0 ||
275  this->template get<TransmissionProbabilityOnContact<FP>>()[i] > 1.0) {
276  log_warning("Constraint check: Parameter TransmissionProbabilityOnContact {} smaller {} or "
277  "greater {}",
278  this->template get<TransmissionProbabilityOnContact<FP>>()[i], 0.0, 1.0);
279  return true;
280  }
281  if (this->template get<TransmissionProbabilityFromDead<FP>>()[i] < 0.0 ||
282  this->template get<TransmissionProbabilityFromDead<FP>>()[i] > 1.0) {
283  log_warning("Constraint check: Parameter TransmissionProbabilityFromDead {} smaller {} or "
284  "greater {}",
285  this->template get<TransmissionProbabilityFromDead<FP>>()[i], 0.0, 1.0);
286  return true;
287  }
288  if (this->template get<ProbabilityToRecover<FP>>()[i] < 0.0 ||
289  this->template get<ProbabilityToRecover<FP>>()[i] > 1.0) {
290  log_warning("Constraint check: Parameter ProbabilityToRecover {} smaller {} or greater {}",
291  this->template get<ProbabilityToRecover<FP>>()[i], 0.0, 1.0);
292  return true;
293  }
294  }
295  return false;
296  }
297 
298 private:
300  : ParametersBase<FP>(std::move(base))
301  , m_num_groups(this->template get<ContactPatterns<FP>>().get_cont_freq_mat().get_num_groups())
302  {
303  }
304 
305 public:
310  template <class IOContext>
311  static IOResult<Parameters> deserialize(IOContext& io)
312  {
313  BOOST_OUTCOME_TRY(auto&& base, ParametersBase<FP>::deserialize(io));
314  return success(Parameters(std::move(base)));
315  }
316 
317 private:
319 };
320 } // namespace oseirdb
321 } // namespace mio
322 
323 #endif // SEIRDB_PARAMETERS_H
A class template for an array with custom indices.
Definition: custom_index_array.h:136
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 age-resolved SEIRDB model.
Definition: ode_seirdb/parameters.h:161
static IOResult< Parameters > deserialize(IOContext &io)
deserialize an object of this class.
Definition: ode_seirdb/parameters.h:311
Parameters(AgeGroup num_agegroups)
Definition: ode_seirdb/parameters.h:163
bool check_constraints() const
Checks whether all Parameters satisfy their corresponding constraints and logs an error if constraint...
Definition: ode_seirdb/parameters.h:248
bool apply_constraints()
Checks whether all Parameters satisfy their corresponding constraints and applies them,...
Definition: ode_seirdb/parameters.h:187
AgeGroup m_num_groups
Definition: ode_seirdb/parameters.h:318
Parameters(ParametersBase< FP > &&base)
Definition: ode_seirdb/parameters.h:299
AgeGroup get_num_groups() const
Definition: ode_seirdb/parameters.h:169
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
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 AgeGroup struct is used as a dynamically sized tag for all age dependent categories.
Definition: age_group.h:32
the contact patterns within the society are modelled using a ContactMatrix
Definition: ode_seirdb/parameters.h:139
static std::string name()
Definition: ode_seirdb/parameters.h:145
static Type get_default(AgeGroup size)
Definition: ode_seirdb/parameters.h:141
UncertainContactMatrix< FP > Type
Definition: ode_seirdb/parameters.h:140
probability to recover from the infected compartment
Definition: ode_seirdb/parameters.h:91
CustomIndexArray< UncertainValue< FP >, AgeGroup > Type
Definition: ode_seirdb/parameters.h:92
static Type get_default(AgeGroup size)
Definition: ode_seirdb/parameters.h:93
static std::string name()
Definition: ode_seirdb/parameters.h:97
the latent time in day unit
Definition: ode_seirdb/parameters.h:59
static std::string name()
Definition: ode_seirdb/parameters.h:65
CustomIndexArray< UncertainValue< FP >, AgeGroup > Type
Definition: ode_seirdb/parameters.h:60
static Type get_default(AgeGroup size)
Definition: ode_seirdb/parameters.h:61
the infectious time in day unit
Definition: ode_seirdb/parameters.h:75
CustomIndexArray< UncertainValue< FP >, AgeGroup > Type
Definition: ode_seirdb/parameters.h:76
static std::string name()
Definition: ode_seirdb/parameters.h:81
static Type get_default(AgeGroup size)
Definition: ode_seirdb/parameters.h:77
average time until a dead person is buried
Definition: ode_seirdb/parameters.h:123
static Type get_default(AgeGroup size)
Definition: ode_seirdb/parameters.h:125
static std::string name()
Definition: ode_seirdb/parameters.h:129
CustomIndexArray< UncertainValue< FP >, AgeGroup > Type
Definition: ode_seirdb/parameters.h:124
probability to infect from the dead but unburied compartment
Definition: ode_seirdb/parameters.h:107
CustomIndexArray< UncertainValue< FP >, AgeGroup > Type
Definition: ode_seirdb/parameters.h:108
static std::string name()
Definition: ode_seirdb/parameters.h:113
static Type get_default(AgeGroup size)
Definition: ode_seirdb/parameters.h:109
probability of getting infected from a contact
Definition: ode_seirdb/parameters.h:43
CustomIndexArray< UncertainValue< FP >, AgeGroup > Type
Definition: ode_seirdb/parameters.h:44
static std::string name()
Definition: ode_seirdb/parameters.h:49
static Type get_default(AgeGroup size)
Definition: ode_seirdb/parameters.h:45