Line data Source code
1 : /*
2 : * Copyright (C) 2020-2025 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 MIO_GLCT_SECIR_PARAMS_H
22 : #define MIO_GLCT_SECIR_PARAMS_H
23 :
24 : #include "memilio/config.h"
25 : #include "memilio/utils/parameter_set.h"
26 : #include "memilio/math/eigen.h"
27 : #include "memilio/math/floating_point.h"
28 : #include "memilio/epidemiology/uncertain_matrix.h"
29 : #include "memilio/utils/logging.h"
30 :
31 : namespace mio
32 : {
33 : namespace glsecir
34 : {
35 :
36 : /***********************************************
37 : * Define Parameters of the GLCT-SECIHURD model *
38 : ***********************************************/
39 :
40 : /// @brief Vector with the probability to start in any of the subcompartments of the Exposed compartment.
41 : struct StartingProbabilitiesExposed {
42 : using Type = Eigen::VectorX<ScalarType>;
43 : /**
44 : * @brief Default parameters can be used to get an Erlang distributed stay time in the Exposed compartment.
45 : * @param[in] numExposed Number of subcompartments of the Exposed compartment.
46 : */
47 7 : static Type get_default(size_t numExposed)
48 : {
49 7 : Eigen::VectorX<ScalarType> def = Eigen::VectorX<ScalarType>::Zero(numExposed);
50 7 : def[0] = 1.;
51 14 : return def;
52 7 : }
53 : static std::string name()
54 : {
55 : return "StartingProbabilitiesExposed";
56 : }
57 : };
58 :
59 : /// @brief Transition matrix of the Exposed compartment.
60 : struct TransitionMatrixExposedToInfectedNoSymptoms {
61 : using Type = Eigen::MatrixXd;
62 : /**
63 : * @brief Default parameters can be used to get an Erlang distributed stay time in the Exposed compartment.
64 : * @param[in] numExposed Number of subcompartments of the Exposed compartment.
65 : * @param[in] timeExposed Average time spent in Exposed compartment in day unit.
66 : */
67 5 : static Type get_default(size_t numExposed, ScalarType timeExposed = 1.)
68 : {
69 5 : Eigen::MatrixXd def =
70 5 : Eigen::VectorX<ScalarType>::Constant(numExposed, -(ScalarType)numExposed / timeExposed).asDiagonal();
71 5 : def.diagonal(1).setConstant((ScalarType)numExposed / timeExposed);
72 10 : return def;
73 5 : }
74 : static std::string name()
75 : {
76 : return "TransitionMatrixExposedToInfectedNoSymptoms";
77 : }
78 : };
79 :
80 : /// @brief Vector with the probability to start in any of the subcompartments of the InfectedNoSymptoms compartment.
81 : struct StartingProbabilitiesInfectedNoSymptoms {
82 : using Type = Eigen::VectorX<ScalarType>;
83 : /**
84 : * @brief Default parameters can be used to get an Erlang distributed stay time in InfectedNoSymptoms compartment.
85 : * @param[in] numInfectedNoSymptoms Number of subcompartments of the InfectedNoSymptoms compartment.
86 : */
87 2 : static Type get_default(size_t numInfectedNoSymptoms)
88 : {
89 2 : Eigen::VectorX<ScalarType> def = Eigen::VectorX<ScalarType>::Zero(numInfectedNoSymptoms);
90 2 : def[0] = 1.;
91 4 : return def;
92 2 : }
93 : static std::string name()
94 : {
95 : return "StartingProbabilitiesInfectedNoSymptoms";
96 : }
97 : };
98 :
99 : /**
100 : * @brief Transition matrix of the phase-type distribution describing the stay time in the InfectedNoSymptoms
101 : * compartment before developing symptoms.
102 : */
103 : struct TransitionMatrixInfectedNoSymptomsToInfectedSymptoms {
104 : using Type = Eigen::MatrixXd;
105 : /**
106 : * @brief Default parameters can be used to get an Erlang distributed stay time in InfectedNoSymptoms compartment
107 : * before developing symptoms.
108 : * @param[in] dimension Number of rows/columns of the transition matrix.
109 : * @param[in] time Average time spent in InfectedNoSymptoms before developing symptoms in day unit.
110 : */
111 5 : static Type get_default(size_t dimension, ScalarType time = 1.)
112 : {
113 5 : Eigen::MatrixXd def =
114 5 : Eigen::VectorX<ScalarType>::Constant(dimension, -(ScalarType)dimension / time).asDiagonal();
115 5 : def.diagonal(1).setConstant((ScalarType)dimension / time);
116 10 : return def;
117 5 : }
118 : static std::string name()
119 : {
120 : return "TransitionMatrixInfectedNoSymptomsToInfectedSymptoms";
121 : }
122 : };
123 :
124 : /**
125 : * @brief Transition matrix of the phase-type distribution describing the stay time in the InfectedNoSymptoms
126 : * compartment before recovery.
127 : */
128 : struct TransitionMatrixInfectedNoSymptomsToRecovered {
129 : using Type = Eigen::MatrixXd;
130 : /**
131 : * @brief Default parameters can be used to get an Erlang distributed stay time in InfectedNoSymptoms compartment
132 : * before recovery.
133 : * @param[in] dimension Number of rows/columns of the transition matrix.
134 : * @param[in] time Average time spent in InfectedNoSymptoms before recovery in day unit.
135 : */
136 5 : static Type get_default(size_t dimension, ScalarType time = 1.)
137 : {
138 5 : Eigen::MatrixXd def =
139 5 : Eigen::VectorX<ScalarType>::Constant(dimension, -(ScalarType)dimension / time).asDiagonal();
140 5 : def.diagonal(1).setConstant((ScalarType)dimension / time);
141 10 : return def;
142 5 : }
143 : static std::string name()
144 : {
145 : return "TransitionMatrixInfectedNoSymptomsToInfectedSymptomsToRecovered";
146 : }
147 : };
148 :
149 : /// @brief Vector with the probability to start in any of the subcompartments of the InfectedSymptoms compartment.
150 : struct StartingProbabilitiesInfectedSymptoms {
151 : using Type = Eigen::VectorX<ScalarType>;
152 : /**
153 : * @brief Default parameters can be used to get an Erlang distributed stay time in InfectedSymptoms compartment.
154 : * @param[in] numInfectedSymptoms Number of subcompartments of the InfectedSymptoms compartment.
155 : */
156 2 : static Type get_default(size_t numInfectedSymptoms)
157 : {
158 2 : Eigen::VectorX<ScalarType> def = Eigen::VectorX<ScalarType>::Zero(numInfectedSymptoms);
159 2 : def[0] = 1.;
160 4 : return def;
161 2 : }
162 : static std::string name()
163 : {
164 : return "StartingProbabilitiesInfectedSymptoms";
165 : }
166 : };
167 :
168 : /**
169 : * @brief Transition matrix of the phase-type distribution describing the stay time in the InfectedNoSymptoms
170 : * compartment before going to hospital.
171 : */
172 : struct TransitionMatrixInfectedSymptomsToInfectedSevere {
173 : using Type = Eigen::MatrixXd;
174 : /**
175 : * @brief Default parameters can be used to get an Erlang distributed stay time in the InfectedSymptoms compartment
176 : * before going to hospital.
177 : * @param[in] dimension Number of rows/columns of the transition matrix.
178 : * @param[in] time Average time spent in InfectedSymptoms before going to hospital in day unit.
179 : */
180 5 : static Type get_default(size_t dimension, ScalarType time = 1.)
181 : {
182 5 : Eigen::MatrixXd def =
183 5 : Eigen::VectorX<ScalarType>::Constant(dimension, -(ScalarType)dimension / time).asDiagonal();
184 5 : def.diagonal(1).setConstant((ScalarType)dimension / time);
185 10 : return def;
186 5 : }
187 : static std::string name()
188 : {
189 : return "TransitionMatrixInfectedSymptomsToInfectedSevere";
190 : }
191 : };
192 :
193 : /**
194 : * @brief Transition matrix of the phase-type distribution describing the stay time in the InfectedSymptoms
195 : * compartment before recovery.
196 : */
197 : struct TransitionMatrixInfectedSymptomsToRecovered {
198 : using Type = Eigen::MatrixXd;
199 : /**
200 : * @brief Default parameters can be used to get an Erlang distributed stay time in the InfectedSymptoms compartment
201 : * before recovery.
202 : * @param[in] dimension Number of rows/columns of the transition matrix.
203 : * @param[in] time Average time spent in InfectedSymptoms before recovery in day unit.
204 : */
205 5 : static Type get_default(size_t dimension, ScalarType time = 1.)
206 : {
207 5 : Eigen::MatrixXd def =
208 5 : Eigen::VectorX<ScalarType>::Constant(dimension, -(ScalarType)dimension / time).asDiagonal();
209 5 : def.diagonal(1).setConstant((ScalarType)dimension / time);
210 10 : return def;
211 5 : }
212 : static std::string name()
213 : {
214 : return "TransitionMatrixInfectedSymptomsToRecovered";
215 : }
216 : };
217 :
218 : /// @brief Vector with the probability to start in any of the subcompartments of the InfectedSevere compartment.
219 : struct StartingProbabilitiesInfectedSevere {
220 : using Type = Eigen::VectorX<ScalarType>;
221 : /**
222 : * @brief Default parameters can be used to get an Erlang distributed stay time in InfectedSevere compartment.
223 : * @param[in] numInfectedSevere Number of subcompartments of the InfectedSevere compartment.
224 : */
225 2 : static Type get_default(size_t numInfectedSevere)
226 : {
227 2 : Eigen::VectorX<ScalarType> def = Eigen::VectorX<ScalarType>::Zero(numInfectedSevere);
228 2 : def[0] = 1.;
229 4 : return def;
230 2 : }
231 : static std::string name()
232 : {
233 : return "StartingProbabilitiesInfectedSevere";
234 : }
235 : };
236 :
237 : /**
238 : * @brief Transition matrix of the phase-type distribution describing the stay time in the InfectedSevere
239 : * compartment before treated by ICU.
240 : */
241 : struct TransitionMatrixInfectedSevereToInfectedCritical {
242 : using Type = Eigen::MatrixXd;
243 : /**
244 : * @brief Default parameters can be used to get an Erlang distributed stay time in InfectedSevere compartment
245 : * before treated by ICU.
246 : * @param[in] dimension Number of rows/columns of the transition matrix.
247 : * @param[in] time Average time spent in InfectedSevere before treated by ICU in day unit.
248 : */
249 5 : static Type get_default(size_t dimension, ScalarType time = 1.)
250 : {
251 5 : Eigen::MatrixXd def =
252 5 : Eigen::VectorX<ScalarType>::Constant(dimension, -(ScalarType)dimension / time).asDiagonal();
253 5 : def.diagonal(1).setConstant((ScalarType)dimension / time);
254 10 : return def;
255 5 : }
256 : static std::string name()
257 : {
258 : return "TransitionMatrixInfectedSevereToInfectedCritical";
259 : }
260 : };
261 :
262 : /**
263 : * @brief Transition matrix of the phase-type distribution describing the stay time in the InfectedSevere
264 : * compartment before recovery.
265 : */
266 : struct TransitionMatrixInfectedSevereToRecovered {
267 : using Type = Eigen::MatrixXd;
268 : /**
269 : * @brief Default parameters can be used to get an Erlang distributed stay time in InfectedSevere compartment
270 : * before recovery.
271 : * @param[in] dimension Number of rows/columns of the transition matrix.
272 : * @param[in] time Average time spent in InfectedSevere before recovery in day unit.
273 : */
274 5 : static Type get_default(size_t dimension, ScalarType time = 1.)
275 : {
276 5 : Eigen::MatrixXd def =
277 5 : Eigen::VectorX<ScalarType>::Constant(dimension, -(ScalarType)dimension / time).asDiagonal();
278 5 : def.diagonal(1).setConstant((ScalarType)dimension / time);
279 10 : return def;
280 5 : }
281 : static std::string name()
282 : {
283 : return "TransitionMatrixInfectedSevereToRecovered";
284 : }
285 : };
286 :
287 : /// @brief Vector with the probability to start in any of the subcompartments of the InfectedCritical compartment.
288 : struct StartingProbabilitiesInfectedCritical {
289 : using Type = Eigen::VectorX<ScalarType>;
290 : /**
291 : * @brief Default parameters can be used to get an Erlang distributed stay time in InfectedCritical compartment.
292 : * @param[in] numInfectedCritical Number of subcompartments of the InfectedCritical compartment.
293 : */
294 2 : static Type get_default(size_t numInfectedCritical)
295 : {
296 2 : Eigen::VectorX<ScalarType> def = Eigen::VectorX<ScalarType>::Zero(numInfectedCritical);
297 2 : def[0] = 1.;
298 4 : return def;
299 2 : }
300 : static std::string name()
301 : {
302 : return "StartingProbabilitiesInfectedCritical";
303 : }
304 : };
305 :
306 : /**
307 : * @brief Transition matrix of the phase-type distribution describing the stay time in the InfectedCritical
308 : * compartment before death.
309 : */
310 : struct TransitionMatrixInfectedCriticalToDead {
311 : using Type = Eigen::MatrixXd;
312 : /**
313 : * @brief Default parameters can be used to get an Erlang distributed stay time in InfectedCritical compartment
314 : * before death.
315 : * @param[in] dimension Number of rows/columns of the transition matrix.
316 : * @param[in] time Average time treated by ICU before dying in day unit.
317 : */
318 5 : static Type get_default(size_t dimension, ScalarType time = 1.)
319 : {
320 5 : Eigen::MatrixXd def =
321 5 : Eigen::VectorX<ScalarType>::Constant(dimension, -(ScalarType)dimension / time).asDiagonal();
322 5 : def.diagonal(1).setConstant((ScalarType)dimension / time);
323 10 : return def;
324 5 : }
325 : static std::string name()
326 : {
327 : return "TransitionMatrixInfectedCriticalToDead";
328 : }
329 : };
330 :
331 : /**
332 : * @brief Transition matrix of the phase-type distribution describing the stay time in the InfectedCritical
333 : * compartment before recovery.
334 : */
335 : struct TransitionMatrixInfectedCriticalToRecovered {
336 : using Type = Eigen::MatrixXd;
337 : /**
338 : * @brief Default parameters can be used to get an Erlang distributed stay time in InfectedCritical compartment
339 : * before recovery.
340 : * @param[in] dimension Number of rows/columns of the transition matrix.
341 : * @param[in] time Average time treated by ICU before recovery in day unit.
342 : */
343 6 : static Type get_default(size_t dimension, ScalarType time = 1.)
344 : {
345 6 : Eigen::MatrixXd def =
346 6 : Eigen::VectorX<ScalarType>::Constant(dimension, -(ScalarType)dimension / time).asDiagonal();
347 6 : def.diagonal(1).setConstant((ScalarType)dimension / time);
348 12 : return def;
349 6 : }
350 : static std::string name()
351 : {
352 : return "TransitionMatrixInfectedCriticalToRecovered";
353 : }
354 : };
355 :
356 : /// @brief Probability of getting infected from a contact.
357 : struct TransmissionProbabilityOnContact {
358 : using Type = ScalarType;
359 5 : static Type get_default()
360 : {
361 5 : return 1.0;
362 : }
363 : static std::string name()
364 : {
365 : return "TransmissionProbabilityOnContact";
366 : }
367 : };
368 :
369 : /// @brief The contact patterns within the society are modelled using an UncertainContactMatrix.
370 : struct ContactPatterns {
371 : using Type = UncertainContactMatrix<ScalarType>;
372 :
373 5 : static Type get_default()
374 : {
375 5 : ContactMatrixGroup contact_matrix = ContactMatrixGroup(1, 1);
376 5 : contact_matrix[0] = mio::ContactMatrix(Eigen::MatrixXd::Constant(1, 1, 10.));
377 10 : return Type(contact_matrix);
378 5 : }
379 : static std::string name()
380 : {
381 : return "ContactPatterns";
382 : }
383 : };
384 :
385 : /// @brief The relative InfectedNoSymptoms infectability.
386 : struct RelativeTransmissionNoSymptoms {
387 : using Type = ScalarType;
388 5 : static Type get_default()
389 : {
390 5 : return 0.5;
391 : }
392 : static std::string name()
393 : {
394 : return "RelativeTransmissionNoSymptoms";
395 : }
396 : };
397 :
398 : /// @brief The risk of infection from symptomatic cases in the GLCT-SECIR model.
399 : struct RiskOfInfectionFromSymptomatic {
400 : using Type = ScalarType;
401 5 : static Type get_default()
402 : {
403 5 : return 0.5;
404 : }
405 : static std::string name()
406 : {
407 : return "RiskOfInfectionFromSymptomatic";
408 : }
409 : };
410 :
411 : /**
412 : * @brief The start day in the GLCT-SECIR model.
413 : * The start day defines in which season the simulation is started.
414 : * If the start day is 180 and simulation takes place from t0=0 to
415 : * tmax=100 the days 180 to 280 of the year are simulated.
416 : */
417 : struct StartDay {
418 : using Type = ScalarType;
419 5 : static Type get_default()
420 : {
421 5 : return 0.;
422 : }
423 : static std::string name()
424 : {
425 : return "StartDay";
426 : }
427 : };
428 :
429 : /**
430 : * @brief The seasonality in the GLCT-SECIR model.
431 : * The seasonality is given as (1+k*sin()) where the sine
432 : * curve is below one in summer and above one in winter.
433 : */
434 : struct Seasonality {
435 : using Type = ScalarType;
436 5 : static Type get_default()
437 : {
438 5 : return Type(0.);
439 : }
440 : static std::string name()
441 : {
442 : return "Seasonality";
443 : }
444 : };
445 :
446 : using ParametersBase =
447 : ParameterSet<StartingProbabilitiesExposed, TransitionMatrixExposedToInfectedNoSymptoms,
448 : StartingProbabilitiesInfectedNoSymptoms, TransitionMatrixInfectedNoSymptomsToInfectedSymptoms,
449 : TransitionMatrixInfectedNoSymptomsToRecovered, StartingProbabilitiesInfectedSymptoms,
450 : TransitionMatrixInfectedSymptomsToInfectedSevere, TransitionMatrixInfectedSymptomsToRecovered,
451 : StartingProbabilitiesInfectedSevere, TransitionMatrixInfectedSevereToInfectedCritical,
452 : TransitionMatrixInfectedSevereToRecovered, StartingProbabilitiesInfectedCritical,
453 : TransitionMatrixInfectedCriticalToDead, TransitionMatrixInfectedCriticalToRecovered,
454 : TransmissionProbabilityOnContact, ContactPatterns, RelativeTransmissionNoSymptoms,
455 : RiskOfInfectionFromSymptomatic, StartDay, Seasonality>;
456 :
457 : /// @brief Parameters of an GLCT-SECIR model.
458 : class Parameters : public ParametersBase
459 : {
460 : public:
461 : /// @brief Default constructor.
462 5 : Parameters()
463 5 : : ParametersBase()
464 : {
465 5 : }
466 :
467 : /**
468 : * @brief Checks that all parameters satisfy their corresponding constraints and logs an error
469 : * if constraints are not satisfied.
470 : *
471 : * @return Returns true if one or more constraints are not satisfied, false otherwise.
472 : */
473 25 : bool check_constraints() const
474 : {
475 : // --- Parameters affecting the transmission of the virus. ---
476 50 : if (this->get<TransmissionProbabilityOnContact>() < 0.0 ||
477 25 : this->get<TransmissionProbabilityOnContact>() > 1.0) {
478 1 : log_error("Constraint check: Parameter TransmissionProbabilityOnContact smaller {:d} or larger {:d}", 0, 1);
479 1 : return true;
480 : }
481 :
482 24 : if (this->get<RelativeTransmissionNoSymptoms>() < 0.0 || this->get<RelativeTransmissionNoSymptoms>() > 1.0) {
483 1 : log_error("Constraint check: Parameter RelativeTransmissionNoSymptoms smaller {:d} or larger {:d}", 0, 1);
484 1 : return true;
485 : }
486 :
487 23 : if (this->get<RiskOfInfectionFromSymptomatic>() < 0.0 || this->get<RiskOfInfectionFromSymptomatic>() > 1.0) {
488 1 : log_error("Constraint check: Parameter RiskOfInfectionFromSymptomatic smaller {:d} or larger {:d}", 0, 1);
489 1 : return true;
490 : }
491 :
492 22 : if (this->get<Seasonality>() < 0.0 || this->get<Seasonality>() > 0.5) {
493 1 : log_warning("Constraint check: Parameter Seasonality should lie between {:0.4f} and {:.4f}", 0.0, 0.5);
494 1 : return true;
495 : }
496 :
497 : // --- Parameters affecting the phase-type distributions. ---
498 : // --- Check that the dimensions are consistent. ---
499 21 : if ((this->get<TransitionMatrixExposedToInfectedNoSymptoms>().cols() !=
500 42 : this->get<TransitionMatrixExposedToInfectedNoSymptoms>().rows()) ||
501 21 : (this->get<TransitionMatrixInfectedNoSymptomsToInfectedSymptoms>().cols() !=
502 42 : this->get<TransitionMatrixInfectedNoSymptomsToInfectedSymptoms>().rows()) ||
503 21 : (this->get<TransitionMatrixInfectedNoSymptomsToRecovered>().cols() !=
504 42 : this->get<TransitionMatrixInfectedNoSymptomsToRecovered>().rows()) ||
505 21 : (this->get<TransitionMatrixInfectedSymptomsToInfectedSevere>().cols() !=
506 42 : this->get<TransitionMatrixInfectedSymptomsToInfectedSevere>().rows()) ||
507 21 : (this->get<TransitionMatrixInfectedSymptomsToRecovered>().cols() !=
508 42 : this->get<TransitionMatrixInfectedSymptomsToRecovered>().rows()) ||
509 21 : (this->get<TransitionMatrixInfectedSevereToInfectedCritical>().cols() !=
510 42 : this->get<TransitionMatrixInfectedSevereToInfectedCritical>().rows()) ||
511 21 : (this->get<TransitionMatrixInfectedSevereToRecovered>().cols() !=
512 42 : this->get<TransitionMatrixInfectedSevereToRecovered>().rows()) ||
513 21 : (this->get<TransitionMatrixInfectedCriticalToDead>().cols() !=
514 63 : this->get<TransitionMatrixInfectedCriticalToDead>().rows()) ||
515 21 : (this->get<TransitionMatrixInfectedCriticalToRecovered>().cols() !=
516 21 : this->get<TransitionMatrixInfectedCriticalToRecovered>().rows())) {
517 1 : log_error("Constraint check: At least one of the matrices used for the TransitionMatrix parameters is not "
518 : "quadratic.");
519 1 : return true;
520 : }
521 :
522 40 : if (this->get<StartingProbabilitiesExposed>().rows() !=
523 20 : this->get<TransitionMatrixExposedToInfectedNoSymptoms>().rows()) {
524 1 : log_error("Constraint check: Dimensions of StartingProbabilitiesExposed and "
525 : "TransitionMatrixExposedToInfectedNoSymptoms are not matching.");
526 1 : return true;
527 : }
528 :
529 19 : if (this->get<StartingProbabilitiesInfectedNoSymptoms>().rows() !=
530 38 : this->get<TransitionMatrixInfectedNoSymptomsToInfectedSymptoms>().rows() +
531 19 : this->get<TransitionMatrixInfectedNoSymptomsToRecovered>().rows()) {
532 1 : log_error("Constraint check: Dimensions of StartingProbabilitiesInfectedNoSymptoms and "
533 : "TransitionMatrices of InfectedNoSymptoms compartment are not matching.");
534 1 : return true;
535 : }
536 :
537 18 : if (this->get<StartingProbabilitiesInfectedSymptoms>().rows() !=
538 36 : this->get<TransitionMatrixInfectedSymptomsToInfectedSevere>().rows() +
539 18 : this->get<TransitionMatrixInfectedSymptomsToRecovered>().rows()) {
540 1 : log_error("Constraint check: Dimensions of StartingProbabilitiesInfectedSymptoms and "
541 : "TransitionMatrices of InfectedSymptoms compartment are not matching.");
542 1 : return true;
543 : }
544 :
545 17 : if (this->get<StartingProbabilitiesInfectedSevere>().rows() !=
546 34 : this->get<TransitionMatrixInfectedSevereToInfectedCritical>().rows() +
547 17 : this->get<TransitionMatrixInfectedSevereToRecovered>().rows()) {
548 1 : log_error("Constraint check: Dimensions of StartingProbabilitiesInfectedSevere and "
549 : "TransitionMatrices of InfectedSevere compartment are not matching.");
550 1 : return true;
551 : }
552 :
553 16 : if (this->get<StartingProbabilitiesInfectedCritical>().rows() !=
554 32 : this->get<TransitionMatrixInfectedCriticalToDead>().rows() +
555 16 : this->get<TransitionMatrixInfectedCriticalToRecovered>().rows()) {
556 1 : log_error("Constraint check: Dimensions of StartingProbabilitiesInfectedCritical and "
557 : "TransitionMatrices of InfectedCritical compartment are not matching.");
558 1 : return true;
559 : }
560 :
561 : // --- Check constraints of the starting probability vectors. ---
562 15 : if ((!floating_point_equal(1., this->get<StartingProbabilitiesExposed>().sum())) ||
563 15 : (!floating_point_equal(1., this->get<StartingProbabilitiesInfectedNoSymptoms>().sum())) ||
564 15 : (!floating_point_equal(1., this->get<StartingProbabilitiesInfectedSymptoms>().sum())) ||
565 44 : (!floating_point_equal(1., this->get<StartingProbabilitiesInfectedSevere>().sum())) ||
566 14 : (!floating_point_equal(1., this->get<StartingProbabilitiesInfectedCritical>().sum()))) {
567 1 : log_warning(
568 : "Constraint check: At least one of the vectors for the starting probabilities does not sum to one.");
569 1 : return true;
570 : }
571 :
572 42 : if ((this->get<StartingProbabilitiesExposed>().array() < -1e-10).any() ||
573 28 : (this->get<StartingProbabilitiesInfectedNoSymptoms>().array() < -1e-10).any() ||
574 28 : (this->get<StartingProbabilitiesInfectedSymptoms>().array() < -1e-10).any() ||
575 69 : (this->get<StartingProbabilitiesInfectedSevere>().array() < -1e-10).any() ||
576 27 : (this->get<StartingProbabilitiesInfectedCritical>().array() < -1e-10).any()) {
577 1 : log_warning("Constraint check: At least one of the vectors for the starting probabilities has at least one "
578 : "negative entry.");
579 1 : return true;
580 : }
581 :
582 : // --- Check that we have no flows back from one compartment to the previous one
583 : // (only in between of the subcompartments). ---
584 52 : if (((this->get<TransitionMatrixExposedToInfectedNoSymptoms>() *
585 26 : Eigen::VectorX<ScalarType>::Ones(this->get<TransitionMatrixExposedToInfectedNoSymptoms>().rows()))
586 52 : .array() > 1e-10)
587 26 : .any()) {
588 1 : log_warning(
589 : "Constraint check: The entries of TransitionMatrixExposedToInfectedNoSymptoms lead to a negative "
590 : "flow ExposedToInfectedNoSymptoms.");
591 1 : return true;
592 : }
593 48 : if (((this->get<TransitionMatrixInfectedNoSymptomsToInfectedSymptoms>() *
594 24 : Eigen::VectorX<ScalarType>::Ones(
595 12 : this->get<TransitionMatrixInfectedNoSymptomsToInfectedSymptoms>().rows()))
596 48 : .array() > 1e-10)
597 24 : .any()) {
598 1 : log_warning("Constraint check: The entries of TransitionMatrixInfectedNoSymptomsToInfectedSymptoms lead to "
599 : "a negative "
600 : "flow InfectedNoSymptomsToInfectedSymptoms.");
601 1 : return true;
602 : }
603 44 : if (((this->get<TransitionMatrixInfectedNoSymptomsToRecovered>() *
604 22 : Eigen::VectorX<ScalarType>::Ones(this->get<TransitionMatrixInfectedNoSymptomsToRecovered>().rows()))
605 44 : .array() > 1e-10)
606 22 : .any()) {
607 1 : log_warning(
608 : "Constraint check: The entries of TransitionMatrixInfectedNoSymptomsToRecovered lead to a negative "
609 : "flow InfectedNoSymptomsToRecovered.");
610 1 : return true;
611 : }
612 40 : if (((this->get<TransitionMatrixInfectedSymptomsToInfectedSevere>() *
613 20 : Eigen::VectorX<ScalarType>::Ones(this->get<TransitionMatrixInfectedSymptomsToInfectedSevere>().rows()))
614 40 : .array() > 1e-10)
615 20 : .any()) {
616 1 : log_warning(
617 : "Constraint check: The entries of TransitionMatrixInfectedSymptomsToInfectedSevere lead to a negative "
618 : "flow InfectedSymptomsToInfectedSevere.");
619 1 : return true;
620 : }
621 36 : if (((this->get<TransitionMatrixInfectedSymptomsToRecovered>() *
622 18 : Eigen::VectorX<ScalarType>::Ones(this->get<TransitionMatrixInfectedSymptomsToRecovered>().rows()))
623 36 : .array() > 1e-10)
624 18 : .any()) {
625 1 : log_warning(
626 : "Constraint check: The entries of TransitionMatrixInfectedSymptomsToRecovered lead to a negative "
627 : "flow InfectedSymptomsToRecovered.");
628 1 : return true;
629 : }
630 32 : if (((this->get<TransitionMatrixInfectedSevereToInfectedCritical>() *
631 16 : Eigen::VectorX<ScalarType>::Ones(this->get<TransitionMatrixInfectedSevereToInfectedCritical>().rows()))
632 32 : .array() > 1e-10)
633 16 : .any()) {
634 1 : log_warning(
635 : "Constraint check: The entries of TransitionMatrixInfectedSevereToInfectedCritical lead to a negative "
636 : "flow InfectedSevereToInfectedCritical.");
637 1 : return true;
638 : }
639 28 : if (((this->get<TransitionMatrixInfectedSevereToRecovered>() *
640 14 : Eigen::VectorX<ScalarType>::Ones(this->get<TransitionMatrixInfectedSevereToRecovered>().rows()))
641 28 : .array() > 1e-10)
642 14 : .any()) {
643 1 : log_warning("Constraint check: The entries of TransitionMatrixInfectedSevereToRecovered lead to a negative "
644 : "flow InfectedSevereToRecovered.");
645 1 : return true;
646 : }
647 24 : if (((this->get<TransitionMatrixInfectedCriticalToDead>() *
648 12 : Eigen::VectorX<ScalarType>::Ones(this->get<TransitionMatrixInfectedCriticalToDead>().rows()))
649 24 : .array() > 1e-10)
650 12 : .any()) {
651 1 : log_warning("Constraint check: The entries of TransitionMatrixInfectedCriticalToDead lead to a negative "
652 : "flow InfectedCriticalToDead.");
653 1 : return true;
654 : }
655 20 : if (((this->get<TransitionMatrixInfectedCriticalToRecovered>() *
656 10 : Eigen::VectorX<ScalarType>::Ones(this->get<TransitionMatrixInfectedCriticalToRecovered>().rows()))
657 20 : .array() > 1e-10)
658 10 : .any()) {
659 1 : log_warning(
660 : "Constraint check: The entries of TransitionMatrixInfectedCriticalToRecovered lead to a negative "
661 : "flow InfectedCriticalToRecovered.");
662 1 : return true;
663 : }
664 :
665 4 : return false;
666 : }
667 :
668 : private:
669 : Parameters(ParametersBase&& base)
670 : : ParametersBase(std::move(base))
671 : {
672 : }
673 :
674 : public:
675 : /**
676 : * deserialize an object of this class.
677 : * @see mio::deserialize
678 : */
679 : template <class IOContext>
680 : static IOResult<Parameters> deserialize(IOContext& io)
681 : {
682 : BOOST_OUTCOME_TRY(auto&& base, ParametersBase::deserialize(io));
683 : return success(Parameters(std::move(base)));
684 : }
685 : };
686 :
687 : } // namespace glsecir
688 : } // namespace mio
689 :
690 : #endif // MIO_GLCT_SECIR_PARAMS_H
|