parameters.h Source File

CPP API: parameters.h Source File
ode_seir/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 SEIR_PARAMETERS_H
21 #define SEIR_PARAMETERS_H
22 
23 #include "memilio/config.h"
29 
30 namespace mio
31 {
32 namespace oseir
33 {
34 
35 /***************************************
36  * Define Parameters of the SEIR 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 <class FP>
94  {
95  return Type(1, static_cast<Eigen::Index>((size_t)size));
96  }
97  static std::string name()
98  {
99  return "ContactPatterns";
100  }
101 };
102 
103 template <typename FP>
106 
110 template <typename FP>
111 class Parameters : public ParametersBase<FP>
112 {
113 public:
114  Parameters(AgeGroup num_agegroups)
115  : ParametersBase<FP>(num_agegroups)
116  , m_num_groups{num_agegroups}
117  {
118  }
119 
121  {
122  return m_num_groups;
123  }
124 
139  {
140  const FP tol_times = 1e-1;
141 
142  int corrected = false;
143 
144  for (auto i = AgeGroup(0); i < AgeGroup(m_num_groups); ++i) {
145  if (this->template get<TimeExposed<FP>>()[i] < tol_times) {
146  log_warning(
147  "Constraint check: Parameter TimeExposed changed from {} to {}. Please note that "
148  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
149  "and reset parameters.",
150  this->template get<TimeExposed<FP>>()[i], tol_times);
151  this->template get<TimeExposed<FP>>()[i] = tol_times;
152  corrected = true;
153  }
154  if (this->template get<TimeInfected<FP>>()[i] < tol_times) {
155  log_warning(
156  "Constraint check: Parameter TimeInfected changed from {} to {}. Please note that "
157  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
158  "and reset parameters.",
159  this->template get<TimeInfected<FP>>()[i], tol_times);
160  this->template get<TimeInfected<FP>>()[i] = tol_times;
161  corrected = true;
162  }
163  if (this->template get<TransmissionProbabilityOnContact<FP>>()[i] < 0.0 ||
164  this->template get<TransmissionProbabilityOnContact<FP>>()[i] > 1.0) {
165  log_warning("Constraint check: Parameter TransmissionProbabilityOnContact changed from {} to {} ",
166  this->template get<TransmissionProbabilityOnContact<FP>>()[i], 0.0);
167  this->template get<TransmissionProbabilityOnContact<FP>>()[i] = 0.0;
168  corrected = true;
169  }
170  }
171  return corrected;
172  }
173 
179  bool check_constraints() const
180  {
181  const FP tol_times = 1e-1;
182 
183  for (auto i = AgeGroup(0); i < m_num_groups; i++) {
184  if (this->template get<TimeExposed<FP>>()[i] < tol_times) {
185  log_warning(
186  "Constraint check: Parameter TimeExposed {} smaller or equal {}. Please note that "
187  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
188  "and reset parameters.",
189  this->template get<TimeExposed<FP>>()[i], tol_times);
190  return true;
191  }
192  if (this->template get<TimeInfected<FP>>()[i] < tol_times) {
193  log_warning(
194  "Constraint check: Parameter TimeInfected {} smaller or equal {}. Please note that "
195  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
196  "and reset parameters.",
197  this->template get<TimeInfected<FP>>()[i], tol_times);
198  return true;
199  }
200  if (this->template get<TransmissionProbabilityOnContact<FP>>()[i] < 0.0 ||
201  this->template get<TransmissionProbabilityOnContact<FP>>()[i] > 1.0) {
202  log_error("Constraint check: Parameter TransmissionProbabilityOnContact {} smaller {} or "
203  "greater {}",
204  this->template get<TransmissionProbabilityOnContact<FP>>()[i], 0.0, 1.0);
205  return true;
206  }
207  }
208  return false;
209  }
210 
211 private:
213  : ParametersBase<FP>(std::move(base))
214  , m_num_groups(this->template get<ContactPatterns<FP>>().get_cont_freq_mat().get_num_groups())
215  {
216  }
217 
218 public:
223  template <class IOContext>
224  static IOResult<Parameters> deserialize(IOContext& io)
225  {
226  BOOST_OUTCOME_TRY(auto&& base, ParametersBase<FP>::deserialize(io));
227  return success(Parameters(std::move(base)));
228  }
229 
230 private:
232 };
233 } // namespace oseir
234 } // namespace mio
235 
236 #endif // SEIR_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 SECIR/SECIHURD model.
Definition: ode_seir/parameters.h:112
static IOResult< Parameters > deserialize(IOContext &io)
deserialize an object of this class.
Definition: ode_seir/parameters.h:224
AgeGroup get_num_groups() const
Definition: ode_seir/parameters.h:120
bool apply_constraints()
Checks whether all Parameters satisfy their corresponding constraints and applies them,...
Definition: ode_seir/parameters.h:138
Parameters(AgeGroup num_agegroups)
Definition: ode_seir/parameters.h:114
Parameters(ParametersBase< FP > &&base)
Definition: ode_seir/parameters.h:212
bool check_constraints() const
Checks whether all Parameters satisfy their corresponding constraints and logs an error if constraint...
Definition: ode_seir/parameters.h:179
AgeGroup m_num_groups
Definition: ode_seir/parameters.h:231
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 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_seir/parameters.h:91
UncertainContactMatrix< FP > Type
Definition: ode_seir/parameters.h:92
static std::string name()
Definition: ode_seir/parameters.h:97
static Type get_default(AgeGroup size)
Definition: ode_seir/parameters.h:93
the latent time in day unit
Definition: ode_seir/parameters.h:59
static Type get_default(AgeGroup size)
Definition: ode_seir/parameters.h:61
CustomIndexArray< UncertainValue< FP >, AgeGroup > Type
Definition: ode_seir/parameters.h:60
static std::string name()
Definition: ode_seir/parameters.h:65
the infectious time in day unit
Definition: ode_seir/parameters.h:75
static Type get_default(AgeGroup size)
Definition: ode_seir/parameters.h:77
CustomIndexArray< UncertainValue< FP >, AgeGroup > Type
Definition: ode_seir/parameters.h:76
static std::string name()
Definition: ode_seir/parameters.h:81
probability of getting infected from a contact
Definition: ode_seir/parameters.h:43
static Type get_default(AgeGroup size)
Definition: ode_seir/parameters.h:45
CustomIndexArray< UncertainValue< FP >, AgeGroup > Type
Definition: ode_seir/parameters.h:44
static std::string name()
Definition: ode_seir/parameters.h:49