Line data Source code
1 : /*
2 : * Copyright (C) 2020-2024 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"
26 : #include "memilio/epidemiology/uncertain_matrix.h"
27 : #include "memilio/utils/parameter_set.h"
28 : #include "memilio/utils/logging.h"
29 : #include "memilio/utils/uncertain_value.h"
30 :
31 : namespace mio
32 : {
33 : namespace lsecir
34 : {
35 :
36 : /**********************************************
37 : * Define Parameters of the LCT-SECIHURD model *
38 : **********************************************/
39 :
40 : /**
41 : * @brief Average time spent in the Exposed compartment for each group.
42 : */
43 : struct TimeExposed {
44 : using Type = Vector<UncertainValue<ScalarType>>;
45 20 : static Type get_default(size_t size)
46 : {
47 40 : return Type::Constant(size, 1, 2.);
48 : }
49 : static std::string name()
50 : {
51 : return "TimeExposed";
52 : }
53 : };
54 :
55 : /**
56 : * @brief Average time spent in the TimeInfectedNoSymptoms before developing
57 : * symptoms or recover for each group in the SECIR model in day unit.
58 : */
59 : struct TimeInfectedNoSymptoms {
60 : using Type = Vector<UncertainValue<ScalarType>>;
61 20 : static Type get_default(size_t size)
62 : {
63 40 : return Type::Constant(size, 1, 1.);
64 : }
65 : static std::string name()
66 : {
67 : return "TimeInfectedNoSymptoms";
68 : }
69 : };
70 :
71 : /**
72 : * @brief Average time spent in the TimeInfectedSymptoms before going to hospital
73 : * or recover for each group in the SECIR model in day unit.
74 : */
75 : struct TimeInfectedSymptoms {
76 : using Type = Vector<UncertainValue<ScalarType>>;
77 20 : static Type get_default(size_t size)
78 : {
79 40 : return Type::Constant(size, 1, 1.5);
80 : }
81 : static std::string name()
82 : {
83 : return "TimeInfectedNoSymptoms";
84 : }
85 : };
86 :
87 : /**
88 : * @brief Average time being in the Hospital before treated by ICU or recover for each group in the
89 : * SECIR model in day unit.
90 : */
91 : struct TimeInfectedSevere {
92 : using Type = Vector<UncertainValue<ScalarType>>;
93 20 : static Type get_default(size_t size)
94 : {
95 40 : return Type::Constant(size, 1, 1.);
96 : }
97 : static std::string name()
98 : {
99 : return "TimeInfectedSevere";
100 : }
101 : };
102 :
103 : /**
104 : * @brief Average time treated by ICU before dead or recover for each group in the SECIR model in day unit.
105 : */
106 : struct TimeInfectedCritical {
107 : using Type = Vector<UncertainValue<ScalarType>>;
108 20 : static Type get_default(size_t size)
109 : {
110 40 : return Type::Constant(size, 1, 1.);
111 : }
112 : static std::string name()
113 : {
114 : return "TimeInfectedCritical";
115 : }
116 : };
117 :
118 : /**
119 : * @brief Probability of getting infected from a contact for each group.
120 : */
121 : struct TransmissionProbabilityOnContact {
122 : using Type = Vector<UncertainValue<ScalarType>>;
123 20 : static Type get_default(size_t size)
124 : {
125 40 : return Type::Constant(size, 1, 1.);
126 : }
127 : static std::string name()
128 : {
129 : return "TransmissionProbabilityOnContact";
130 : }
131 : };
132 :
133 : /**
134 : * @brief The contact patterns within the society are modelled using an UncertainContactMatrix.
135 : */
136 : struct ContactPatterns {
137 : using Type = UncertainContactMatrix<ScalarType>;
138 :
139 20 : static Type get_default(size_t size)
140 : {
141 20 : mio::ContactMatrixGroup contact_matrix(1, (Eigen::Index)size);
142 20 : contact_matrix[0] = mio::ContactMatrix(Eigen::MatrixXd::Constant((Eigen::Index)size, (Eigen::Index)size, 10.));
143 40 : return Type(contact_matrix);
144 20 : }
145 : static std::string name()
146 : {
147 : return "ContactPatterns";
148 : }
149 : };
150 :
151 : /**
152 : * @brief The relative InfectedNoSymptoms infectability for each group.
153 : */
154 : struct RelativeTransmissionNoSymptoms {
155 : using Type = Vector<UncertainValue<ScalarType>>;
156 20 : static Type get_default(size_t size)
157 : {
158 40 : return Type::Constant(size, 1, 1.);
159 : }
160 : static std::string name()
161 : {
162 : return "RelativeTransmissionNoSymptoms";
163 : }
164 : };
165 :
166 : /**
167 : * @brief The risk of infection from symptomatic cases for each group in the SECIR model.
168 : */
169 : struct RiskOfInfectionFromSymptomatic {
170 : using Type = Vector<UncertainValue<ScalarType>>;
171 20 : static Type get_default(size_t size)
172 : {
173 40 : return Type::Constant(size, 1, 1.);
174 : }
175 : static std::string name()
176 : {
177 : return "RiskOfInfectionFromSymptomatic";
178 : }
179 : };
180 :
181 : /**
182 : * @brief The percentage of asymptomatic cases for each group in the SECIR model.
183 : */
184 : struct RecoveredPerInfectedNoSymptoms {
185 : using Type = Vector<UncertainValue<ScalarType>>;
186 20 : static Type get_default(size_t size)
187 : {
188 40 : return Type::Constant(size, 1, 0.5);
189 : }
190 : static std::string name()
191 : {
192 : return "RecoveredPerInfectedNoSymptoms";
193 : }
194 : };
195 :
196 : /**
197 : * @brief The percentage of hospitalized patients per infected patients for each group in the SECIR model.
198 : */
199 : struct SeverePerInfectedSymptoms {
200 : using Type = Vector<UncertainValue<ScalarType>>;
201 20 : static Type get_default(size_t size)
202 : {
203 40 : return Type::Constant(size, 1, 0.5);
204 : }
205 : static std::string name()
206 : {
207 : return "SeverePerInfectedSymptoms";
208 : }
209 : };
210 :
211 : /**
212 : * @brief The percentage of ICU patients per hospitalized patients for each group in the SECIR model.
213 : */
214 : struct CriticalPerSevere {
215 : using Type = Vector<UncertainValue<ScalarType>>;
216 20 : static Type get_default(size_t size)
217 : {
218 40 : return Type::Constant(size, 1, 0.5);
219 : }
220 : static std::string name()
221 : {
222 : return "CriticalPerSevere";
223 : }
224 : };
225 :
226 : /**
227 : * @brief The percentage of dead patients per ICU patients for each group in the SECIR model.
228 : */
229 : struct DeathsPerCritical {
230 : using Type = Vector<UncertainValue<ScalarType>>;
231 20 : static Type get_default(size_t size)
232 : {
233 40 : return Type::Constant(size, 1, 0.1);
234 : }
235 : static std::string name()
236 : {
237 : return "DeathsPerCritical";
238 : }
239 : };
240 :
241 : /**
242 : * @brief The start day in the LCT SECIR model.
243 : * The start day defines in which season the simulation is started.
244 : * If the start day is 180 and simulation takes place from t0=0 to
245 : * tmax=100 the days 180 to 280 of the year are simulated.
246 : */
247 : struct StartDay {
248 : using Type = ScalarType;
249 20 : static Type get_default(size_t)
250 : {
251 20 : return 0.;
252 : }
253 : static std::string name()
254 : {
255 : return "StartDay";
256 : }
257 : };
258 :
259 : /**
260 : * @brief The seasonality in the LCT-SECIR model.
261 : * The seasonality is given as (1+k*sin()) where the sine
262 : * curve is below one in summer and above one in winter.
263 : */
264 : struct Seasonality {
265 : using Type = ScalarType;
266 20 : static Type get_default(size_t)
267 : {
268 20 : return 0.;
269 : }
270 : static std::string name()
271 : {
272 : return "Seasonality";
273 : }
274 : };
275 :
276 : using ParametersBase =
277 : ParameterSet<TimeExposed, TimeInfectedNoSymptoms, TimeInfectedSymptoms, TimeInfectedSevere, TimeInfectedCritical,
278 : TransmissionProbabilityOnContact, ContactPatterns, RelativeTransmissionNoSymptoms,
279 : RiskOfInfectionFromSymptomatic, RecoveredPerInfectedNoSymptoms, SeverePerInfectedSymptoms,
280 : CriticalPerSevere, DeathsPerCritical, StartDay, Seasonality>;
281 :
282 : /**
283 : * @brief Parameters of an LCT-SECIR model.
284 : */
285 : class Parameters : public ParametersBase
286 : {
287 : public:
288 : /**
289 : * @brief Constructor.
290 : * @param num_groups The number of groups considered in the LCT model.
291 : */
292 20 : Parameters(size_t num_groups)
293 20 : : ParametersBase(num_groups)
294 20 : , m_num_groups{num_groups}
295 : {
296 20 : }
297 :
298 : size_t get_num_groups() const
299 : {
300 : return m_num_groups;
301 : }
302 :
303 : /**
304 : * @brief Checks whether all parameters satisfy their corresponding constraints and throws errors, if they do not.
305 : * @return Returns true if one (or more) constraint(s) are not satisfied, otherwise false.
306 : */
307 23 : bool check_constraints() const
308 : {
309 23 : if (this->get<Seasonality>() < 0.0 || this->get<Seasonality>() > 0.5) {
310 2 : log_warning("Constraint check: Parameter Seasonality should lie between {:0.4f} and {:.4f}", 0.0, 0.5);
311 1 : return true;
312 : }
313 :
314 39 : for (size_t i = 0; i < m_num_groups; ++i) {
315 29 : if (this->get<TimeExposed>()[i] < 1.0) {
316 2 : log_error("Constraint check: Parameter TimeExposed is smaller than {:.4f}", 1.0);
317 1 : return true;
318 : }
319 :
320 28 : if (this->get<TimeInfectedNoSymptoms>()[i] < 1.0) {
321 2 : log_error("Constraint check: Parameter TimeInfectedNoSymptoms is smaller than {:.4f}", 1.0);
322 1 : return true;
323 : }
324 :
325 27 : if (this->get<TimeInfectedSymptoms>()[i] < 1.0) {
326 2 : log_error("Constraint check: Parameter TimeInfectedSymptoms is smaller than {:.4f}", 1.0);
327 1 : return true;
328 : }
329 :
330 26 : if (this->get<TimeInfectedSevere>()[i] < 1.0) {
331 2 : log_error("Constraint check: Parameter TimeInfectedSevere is smaller than {:.4f}", 1.0);
332 1 : return true;
333 : }
334 :
335 25 : if (this->get<TimeInfectedCritical>()[i] < 1.0) {
336 2 : log_error("Constraint check: Parameter TimeInfectedCritical is smaller than {:.4f}", 1.0);
337 1 : return true;
338 : }
339 :
340 47 : if (this->get<TransmissionProbabilityOnContact>()[i] < 0.0 ||
341 23 : this->get<TransmissionProbabilityOnContact>()[i] > 1.0) {
342 2 : log_error("Constraint check: Parameter TransmissionProbabilityOnContact smaller {:d} or larger {:d}", 0,
343 2 : 1);
344 1 : return true;
345 : }
346 :
347 46 : if (this->get<RelativeTransmissionNoSymptoms>()[i] < 0.0 ||
348 23 : this->get<RelativeTransmissionNoSymptoms>()[i] > 1.0) {
349 2 : log_error("Constraint check: Parameter RelativeTransmissionNoSymptoms smaller {:d} or larger {:d}", 0,
350 2 : 1);
351 1 : return true;
352 : }
353 :
354 44 : if (this->get<RiskOfInfectionFromSymptomatic>()[i] < 0.0 ||
355 22 : this->get<RiskOfInfectionFromSymptomatic>()[i] > 1.0) {
356 2 : log_error("Constraint check: Parameter RiskOfInfectionFromSymptomatic smaller {:d} or larger {:d}", 0,
357 2 : 1);
358 1 : return true;
359 : }
360 :
361 42 : if (this->get<RecoveredPerInfectedNoSymptoms>()[i] < 0.0 ||
362 21 : this->get<RecoveredPerInfectedNoSymptoms>()[i] > 1.0) {
363 2 : log_error("Constraint check: Parameter RecoveredPerInfectedNoSymptoms smaller {:d} or larger {:d}", 0,
364 2 : 1);
365 1 : return true;
366 : }
367 :
368 20 : if (this->get<SeverePerInfectedSymptoms>()[i] < 0.0 || this->get<SeverePerInfectedSymptoms>()[i] > 1.0) {
369 2 : log_error("Constraint check: Parameter SeverePerInfectedSymptoms smaller {:d} or larger {:d}", 0, 1);
370 1 : return true;
371 : }
372 :
373 19 : if (this->get<CriticalPerSevere>()[i] < 0.0 || this->get<CriticalPerSevere>()[i] > 1.0) {
374 2 : log_error("Constraint check: Parameter CriticalPerSevere smaller {:d} or larger {:d}", 0, 1);
375 1 : return true;
376 : }
377 :
378 18 : if (this->get<DeathsPerCritical>()[i] < 0.0 || this->get<DeathsPerCritical>()[i] > 1.0) {
379 2 : log_error("Constraint check: Parameter DeathsPerCritical smaller {:d} or larger {:d}", 0, 1);
380 1 : return true;
381 : }
382 : }
383 :
384 10 : return false;
385 : }
386 :
387 : private:
388 : Parameters(ParametersBase&& base)
389 : : ParametersBase(std::move(base))
390 : , m_num_groups(this->template get<ContactPatterns>().get_cont_freq_mat().get_num_groups())
391 : {
392 : }
393 :
394 : size_t m_num_groups;
395 :
396 : public:
397 : /**
398 : * deserialize an object of this class.
399 : * @see mio::deserialize
400 : */
401 : template <class IOContext>
402 : static IOResult<Parameters> deserialize(IOContext& io)
403 : {
404 : BOOST_OUTCOME_TRY(auto&& base, ParametersBase::deserialize(io));
405 : return success(Parameters(std::move(base)));
406 : }
407 : };
408 :
409 : } // namespace lsecir
410 : } // namespace mio
411 :
412 : #endif // LCT_SECIR_PARAMS_H
|