parameters.h Source File

CPP API: parameters.h Source File
sde_sirs/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_SIRS_PARAMETERS_H
22 #define MIO_SDE_SIRS_PARAMETERS_H
23 
27 
28 namespace mio
29 {
30 namespace ssirs
31 {
32 
33 /***************************************
34  * Define Parameters of the SIRS model *
35  ***************************************/
36 
40 template <typename FP>
43  static Type get_default()
44  {
45  return Type(1.0);
46  }
47  static std::string name()
48  {
49  return "TransmissionProbabilityOnContact";
50  }
51 };
52 
56 template <typename FP>
57 struct TimeInfected {
59  static Type get_default()
60  {
61  return Type(6.0);
62  }
63  static std::string name()
64  {
65  return "TimeInfected";
66  }
67 };
68 
72 template <typename FP>
73 struct TimeImmune {
75  static Type get_default()
76  {
77  return Type(6.0);
78  }
79  static std::string name()
80  {
81  return "TimeImmune";
82  }
83 };
84 
88 template <typename FP>
91  static Type get_default()
92  {
93  return Type{1};
94  }
95  static std::string name()
96  {
97  return "ContactPatterns";
98  }
99 };
100 
107 template <typename FP>
108 struct StartDay {
109  using Type = FP;
110  static Type get_default()
111  {
112  return Type(0.0);
113  }
114  static std::string name()
115  {
116  return "StartDay";
117  }
118 };
119 
125 template <typename FP>
126 struct Seasonality {
128  static Type get_default()
129  {
130  return Type(0.);
131  }
132  static std::string name()
133  {
134  return "Seasonality";
135  }
136 };
137 
138 template <typename FP>
141 
145 template <typename FP>
146 class Parameters : public ParametersBase<FP>
147 {
148 public:
150  : ParametersBase<FP>()
151  {
152  }
153 
168  {
169  FP tol_times = 1e-1;
170 
171  int corrected = false;
172  if (this->template get<Seasonality<FP>>() < 0.0 || this->template get<Seasonality<FP>>() > 0.5) {
173  log_warning("Constraint check: Parameter Seasonality changed from {} to {}",
174  this->template get<Seasonality<FP>>(), 0);
175  this->template set<Seasonality<FP>>(0);
176  corrected = true;
177  }
178  if (this->template get<TimeInfected<FP>>() < tol_times) {
179  log_warning("Constraint check: Parameter TimeInfected changed from {} to {}. Please note that "
180  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
181  "and reset parameters.",
182  this->template get<TimeInfected<FP>>(), tol_times);
183  this->template get<TimeInfected<FP>>() = tol_times;
184  corrected = true;
185  }
186  if (this->template get<TimeImmune<FP>>() < tol_times) {
187  log_warning("Constraint check: Parameter TimeInfected 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<TimeImmune<FP>>(), tol_times);
191  this->template get<TimeImmune<FP>>() = tol_times;
192  corrected = true;
193  }
194  if (this->template get<TransmissionProbabilityOnContact<FP>>() < 0.0 ||
195  this->template get<TransmissionProbabilityOnContact<FP>>() > 1.0) {
196  log_warning("Constraint check: Parameter TransmissionProbabilityOnContact changed from {} to {} ",
197  this->template get<TransmissionProbabilityOnContact<FP>>(), 0.0);
198  this->template get<TransmissionProbabilityOnContact<FP>>() = 0.0;
199  corrected = true;
200  }
201  return corrected;
202  }
203 
209  bool check_constraints() const
210  {
211  FP tol_times = 1e-1;
212 
213  if (this->template get<Seasonality<FP>>() < 0.0 || this->template get<Seasonality<FP>>() > 0.5) {
214  log_error("Constraint check: Parameter Seasonality smaller {} or larger {:4f}", 0, 0.5);
215  return true;
216  }
217  if (this->template get<TimeInfected<FP>>() < tol_times) {
218  log_error("Constraint check: Parameter TimeInfected {} smaller or equal {}. Please note that "
219  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
220  "and reset parameters.",
221  this->template get<TimeInfected<FP>>(), 0.0);
222  return true;
223  }
224  if (this->template get<TimeImmune<FP>>() < tol_times) {
225  log_error("Constraint check: Parameter TimeInfected {} smaller or equal {}. Please note that "
226  "unreasonably small compartment stays lead to massively increased run time. Consider to cancel "
227  "and reset parameters.",
228  this->template get<TimeImmune<FP>>(), 0.0);
229  return true;
230  }
231  if (this->template get<TransmissionProbabilityOnContact<FP>>() < 0.0 ||
232  this->template get<TransmissionProbabilityOnContact<FP>>() > 1.0) {
233  log_error("Constraint check: Parameter TransmissionProbabilityOnContact {} smaller {} or greater {}",
234  this->template get<TransmissionProbabilityOnContact<FP>>(), 0.0, 1.0);
235  return true;
236  }
237  return false;
238  }
239 
240 private:
242  : ParametersBase<FP>(std::move(base))
243  {
244  }
245 
246 public:
251  template <class IOContext>
252  static IOResult<Parameters> deserialize(IOContext& io)
253  {
254  BOOST_OUTCOME_TRY(auto&& base, ParametersBase<FP>::deserialize(io));
255  return success(Parameters(std::move(base)));
256  }
257 };
258 
259 } // namespace ssirs
260 } // namespace mio
261 
262 #endif // MIO_SDE_SIRS_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 SIR model.
Definition: sde_sirs/parameters.h:147
bool check_constraints() const
Checks whether all Parameters satisfy their corresponding constraints and logs an error if constraint...
Definition: sde_sirs/parameters.h:209
Parameters(ParametersBase< FP > &&base)
Definition: sde_sirs/parameters.h:241
Parameters()
Definition: sde_sirs/parameters.h:149
bool apply_constraints()
Checks whether all Parameters satisfy their corresponding constraints and applies them,...
Definition: sde_sirs/parameters.h:167
static IOResult< Parameters > deserialize(IOContext &io)
deserialize an object of this class.
Definition: sde_sirs/parameters.h:252
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_sirs/parameters.h:89
static std::string name()
Definition: sde_sirs/parameters.h:95
static Type get_default()
Definition: sde_sirs/parameters.h:91
The seasonality in the SIRS model.
Definition: sde_sirs/parameters.h:126
UncertainValue< FP > Type
Definition: sde_sirs/parameters.h:127
static Type get_default()
Definition: sde_sirs/parameters.h:128
static std::string name()
Definition: sde_sirs/parameters.h:132
The start day in the SIRS model The start day defines in which season the simulation can be started I...
Definition: sde_sirs/parameters.h:108
static Type get_default()
Definition: sde_sirs/parameters.h:110
static std::string name()
Definition: sde_sirs/parameters.h:114
FP Type
Definition: sde_sirs/parameters.h:109
the infectious time in day unit
Definition: sde_sirs/parameters.h:73
static std::string name()
Definition: sde_sirs/parameters.h:79
static Type get_default()
Definition: sde_sirs/parameters.h:75
UncertainValue< FP > Type
Definition: sde_sirs/parameters.h:74
the infectious time in day unit
Definition: sde_sirs/parameters.h:57
static std::string name()
Definition: sde_sirs/parameters.h:63
static Type get_default()
Definition: sde_sirs/parameters.h:59
UncertainValue< FP > Type
Definition: sde_sirs/parameters.h:58
probability of getting infected from a contact
Definition: sde_sirs/parameters.h:41
static std::string name()
Definition: sde_sirs/parameters.h:47
UncertainValue< FP > Type
Definition: sde_sirs/parameters.h:42
static Type get_default()
Definition: sde_sirs/parameters.h:43