parameter_space.h Source File

CPP API: parameter_space.h Source File
ode_secirvvs/parameter_space.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Wadim Koslow, Daniel Abele, Martin J. Kühn
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 MIO_ODE_SECIRVVS_PARAMETER_SPACE_H
21 #define MIO_ODE_SECIRVVS_PARAMETER_SPACE_H
22 
24 #include "memilio/utils/logging.h"
25 #include "ode_secirvvs/model.h"
27 
28 #include <assert.h>
29 
30 namespace mio
31 {
32 namespace osecirvvs
33 {
39 template <typename FP>
41 {
42  using std::abs;
43 
44  model.parameters.template get<ICUCapacity<FP>>().draw_sample();
45  model.parameters.template get<TestAndTraceCapacity<FP>>().draw_sample();
46 
47  for (auto i = AgeGroup(0); i < model.parameters.get_num_groups(); i++) {
48  FP group_total = model.populations.get_group_total(i);
49 
50  //sample initial compartments (with exceptions)
51  for (auto inf_state = Index<InfectionState>(0); inf_state < InfectionState::Count; ++inf_state) {
52  if (inf_state != InfectionState::SusceptibleNaive && //not sampled, fixed after sampling everything else
53  inf_state != InfectionState::DeadNaive && //not sampled, fixed from data
54  inf_state != InfectionState::DeadPartialImmunity && //not sampled, fixed from data
55  inf_state != InfectionState::DeadImprovedImmunity) { //not sampled, fixed from data
56  model.populations[{i, inf_state}].draw_sample();
57  }
58  }
59 
60  //set susceptibles so the total number stays the same as before sampling.
61  //if the new total without susceptibles is already bigger than the previous total
62  //subtract the overflow from SusceptibleImprovedImmunity, susceptibles will then be approximately zero.
64  FP diff = model.populations.get_group_total(i) - group_total;
65  if (diff > 0) {
67  if (model.populations[{i, InfectionState::SusceptibleImprovedImmunity}] < 0.0) {
68  log_error("Negative Compartment after sampling.");
69  }
70  assert(abs(group_total - model.populations.get_group_total(i)) < 1e-10 && "Sanity check.");
71  }
72  model.populations.template set_difference_from_group_total<AgeGroup>({i, InfectionState::SusceptibleNaive},
73  group_total);
74  }
75 }
76 
82 template <typename FP>
84 {
85  model.parameters.template get<Seasonality<FP>>().draw_sample();
86 
87  //not age dependent
88  model.parameters.template get<TimeExposed<FP>>()[AgeGroup(0)].draw_sample();
89  model.parameters.template get<TimeInfectedNoSymptoms<FP>>()[AgeGroup(0)].draw_sample();
90  model.parameters.template get<RelativeTransmissionNoSymptoms<FP>>()[AgeGroup(0)].draw_sample();
91  model.parameters.template get<RiskOfInfectionFromSymptomatic<FP>>()[AgeGroup(0)].draw_sample();
92  model.parameters.template get<MaxRiskOfInfectionFromSymptomatic<FP>>()[AgeGroup(0)].draw_sample();
93 
94  model.parameters.template get<ReducExposedPartialImmunity<FP>>()[AgeGroup(0)].draw_sample();
95  model.parameters.template get<ReducExposedImprovedImmunity<FP>>()[AgeGroup(0)].draw_sample();
96  model.parameters.template get<ReducInfectedSymptomsPartialImmunity<FP>>()[AgeGroup(0)].draw_sample();
97  model.parameters.template get<ReducInfectedSymptomsImprovedImmunity<FP>>()[AgeGroup(0)].draw_sample();
98  model.parameters.template get<ReducInfectedSevereCriticalDeadPartialImmunity<FP>>()[AgeGroup(0)].draw_sample();
99  model.parameters.template get<ReducInfectedSevereCriticalDeadImprovedImmunity<FP>>()[AgeGroup(0)].draw_sample();
100  model.parameters.template get<ReducTimeInfectedMild<FP>>()[AgeGroup(0)].draw_sample();
101 
102  for (auto i = AgeGroup(0); i < model.parameters.get_num_groups(); i++) {
103  //not age dependent
104  model.parameters.template get<TimeExposed<FP>>()[i] =
105  model.parameters.template get<TimeExposed<FP>>()[AgeGroup(0)];
106  model.parameters.template get<TimeInfectedNoSymptoms<FP>>()[i] =
107  model.parameters.template get<TimeInfectedNoSymptoms<FP>>()[AgeGroup(0)];
108  model.parameters.template get<RelativeTransmissionNoSymptoms<FP>>()[i] =
110  model.parameters.template get<RiskOfInfectionFromSymptomatic<FP>>()[i] =
112  model.parameters.template get<MaxRiskOfInfectionFromSymptomatic<FP>>()[i] =
114 
115  model.parameters.template get<ReducExposedPartialImmunity<FP>>()[i] =
117  model.parameters.template get<ReducExposedImprovedImmunity<FP>>()[i] =
119  model.parameters.template get<ReducInfectedSymptomsPartialImmunity<FP>>()[i] =
121  model.parameters.template get<ReducInfectedSymptomsImprovedImmunity<FP>>()[i] =
123  model.parameters.template get<ReducInfectedSevereCriticalDeadPartialImmunity<FP>>()[i] =
125  model.parameters.template get<ReducInfectedSevereCriticalDeadImprovedImmunity<FP>>()[i] =
127  model.parameters.template get<ReducTimeInfectedMild<FP>>()[i] =
128  model.parameters.template get<ReducTimeInfectedMild<FP>>()[AgeGroup(0)];
129 
130  //age dependent
131  model.parameters.template get<TimeInfectedSymptoms<FP>>()[i].draw_sample();
132  model.parameters.template get<TimeInfectedSevere<FP>>()[i].draw_sample();
133  model.parameters.template get<TimeInfectedCritical<FP>>()[i].draw_sample();
134 
135  model.parameters.template get<TransmissionProbabilityOnContact<FP>>()[i].draw_sample();
136  model.parameters.template get<RecoveredPerInfectedNoSymptoms<FP>>()[i].draw_sample();
137  model.parameters.template get<DeathsPerCritical<FP>>()[i].draw_sample();
138  model.parameters.template get<SeverePerInfectedSymptoms<FP>>()[i].draw_sample();
139  model.parameters.template get<CriticalPerSevere<FP>>()[i].draw_sample();
140  }
141 }
142 
148 template <typename FP>
149 void draw_sample(Model<FP>& model)
150 {
151  draw_sample_infection(model);
153  model.parameters.template get<ContactPatterns<FP>>().draw_sample();
154  model.apply_constraints();
155 }
156 
167 template <typename FP>
169 {
170  Graph<Model<FP>, MobilityParameters<FP>> sampled_graph;
171 
172  //sample global parameters
173  auto& shared_params_model = graph.nodes()[0].property;
174  draw_sample_infection(shared_params_model);
175  auto& shared_contacts = shared_params_model.parameters.template get<ContactPatterns<FP>>();
176  shared_contacts.draw_sample_dampings();
177  auto& shared_dynamic_npis = shared_params_model.parameters.template get<DynamicNPIsInfectedSymptoms<FP>>();
178  shared_dynamic_npis.draw_sample();
179  auto& shared_dynamic_npis_delay = shared_params_model.parameters.template get<DynamicNPIsImplementationDelay<FP>>();
180  shared_dynamic_npis_delay.draw_sample();
181 
182  for (auto& params_node : graph.nodes()) {
183  auto& node_model = params_node.property;
184 
185  //sample local parameters
186  draw_sample_demographics(params_node.property);
187 
188  //copy global parameters
189  //save demographic parameters so they aren't overwritten
190  auto local_icu_capacity = node_model.parameters.template get<ICUCapacity<FP>>();
191  auto local_tnt_capacity = node_model.parameters.template get<TestAndTraceCapacity<FP>>();
192  auto local_holidays = node_model.parameters.template get<ContactPatterns<FP>>().get_school_holidays();
193  auto local_daily_v1 = node_model.parameters.template get<DailyPartialVaccinations<FP>>();
194  auto local_daily_v2 = node_model.parameters.template get<DailyFullVaccinations<FP>>();
195  node_model.parameters = shared_params_model.parameters;
196  node_model.parameters.template get<ICUCapacity<FP>>() = local_icu_capacity;
197  node_model.parameters.template get<TestAndTraceCapacity<FP>>() = local_tnt_capacity;
198  node_model.parameters.template get<ContactPatterns<FP>>().get_school_holidays() = local_holidays;
199  node_model.parameters.template get<DailyPartialVaccinations<FP>>() = local_daily_v1;
200  node_model.parameters.template get<DailyFullVaccinations<FP>>() = local_daily_v2;
201 
202  node_model.parameters.template get<ContactPatterns<FP>>().make_matrix();
203  node_model.apply_constraints();
204 
205  sampled_graph.add_node(params_node.id, node_model);
206  }
207 
208  for (auto& edge : graph.edges()) {
209  auto edge_params = edge.property;
210  //no dynamic NPIs
211  //TODO: add switch to optionally enable dynamic NPIs to edges
212  sampled_graph.add_edge(edge.start_node_idx, edge.end_node_idx, edge_params);
213  }
214 
215  return sampled_graph;
216 }
217 } // namespace osecirvvs
218 } // namespace mio
219 
220 #endif // MIO_ODE_SECIRVVS_PARAMETER_SPACE_H
generic graph structure
Definition: graph.h:153
requires std::constructible_from< EdgePropertyT, Args... > void add_edge(size_t start_node_idx, size_t end_node_idx, Args &&... args)
add an edge to the graph.
Definition: graph.h:238
requires std::constructible_from< NodePropertyT, Args... > void add_node(int id, Args &&... args)
add a node to the graph.
Definition: graph.h:223
An Index with more than one template parameter combines several Index objects.
Definition: index.h:181
parameters that influence mobility.
Definition: metapopulation_mobility_instant.h:123
FP get_group_total(mio::Index< T > group_idx) const
get_group_total returns the total population of a group in one category
Definition: populations.h:136
size_t get_num_groups() const
Get the number of the age groups.
Definition: abm/parameters.h:783
Definition: ode_secirvvs/model.h:94
ad::internal::unary_intermediate< AD_TAPE_REAL, ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 >, ad::operations::ad_fabs< AD_TAPE_REAL > > abs(const ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > &x1)
Definition: ad.hpp:1144
void draw_sample(Model< FP > &model)
Draws a sample from Model parameter distributions and stores sample values as Parameters parameter va...
Definition: ode_secirvvs/parameter_space.h:149
void draw_sample_demographics(Model< FP > &model)
draws a sample from the specified distributions for all parameters related to the demographics,...
Definition: ode_secirvvs/parameter_space.h:40
void draw_sample_infection(Model< FP > &model)
draws a sample from the specified distributions for all parameters related to the infection.
Definition: ode_secirvvs/parameter_space.h:83
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_error(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:100
constexpr std::tuple_element< I, std::tuple< Index< CategoryTags >... > >::type & get(Index< CategoryTags... > &i) noexcept
Retrieves the Index (by reference) at the Ith position of a MultiIndex.
Definition: index.h:294
The AgeGroup struct is used as a dynamically sized tag for all age dependent categories.
Definition: age_group.h:32
bool apply_constraints()
Checks whether the model satisfies all constraints.
Definition: compartmental_model.h:131
Populations populations
Definition: compartmental_model.h:156
ParameterSet parameters
Definition: compartmental_model.h:157
risk of infection from symptomatic cases increases as test and trace capacity is exceeded.
Definition: ode_secirvvs/parameters.h:356
Factor to reduce infection risk for persons with improved immunity.
Definition: ode_secirvvs/parameters.h:516
Factor to reduce infection risk for persons with partial immunity.
Definition: ode_secirvvs/parameters.h:500
Factor to reduce risk of hospitalization for persons with improved immunity.
Definition: ode_secirvvs/parameters.h:581
Factor to reduce risk of hospitalization for persons with partial immunity.
Definition: ode_secirvvs/parameters.h:565
Factor to reduce risk of developing symptoms for persons with improved immunity.
Definition: ode_secirvvs/parameters.h:548
Factor to reduce risk of developing symptoms for persons with partial immunity.
Definition: ode_secirvvs/parameters.h:532
Factor to reduce infectious time of persons with partial or improved immunity.
Definition: ode_secirvvs/parameters.h:597
the relative InfectedNoSymptoms infectability
Definition: ode_secirvvs/parameters.h:308
the risk of infection from symptomatic cases in the SECIR model
Definition: ode_secirvvs/parameters.h:340
the (mean) latent time in day unit
Definition: ode_secirvvs/parameters.h:208
the (mean) time in day unit for asymptomatic cases that are infected but have not yet developed sympt...
Definition: ode_secirvvs/parameters.h:225