analyze_result.h Source File

CPP API: analyze_result.h Source File
models/ode_secirvvs/analyze_result.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_ANALYZE_RESULT_H
21 #define MIO_ODE_SECIRVVS_ANALYZE_RESULT_H
22 
25 
26 namespace mio
27 {
28 namespace osecirvvs
29 {
36 template <class Model>
37 std::vector<Model> ensemble_params_percentile(const std::vector<std::vector<Model>>& ensemble_params, double p)
38 {
39  assert(p > 0.0 && p < 1.0 && "Invalid percentile value.");
40 
41  auto num_runs = ensemble_params.size();
42  auto num_nodes = ensemble_params[0].size();
43  auto num_groups = (size_t)ensemble_params[0][0].parameters.get_num_groups();
44  auto num_days = ensemble_params[0][0]
45  .parameters.template get<DailyPartialVaccinations<double>>()
46  .template size<mio::SimulationDay>();
47 
48  std::vector<double> single_element_ensemble(num_runs);
49 
50  // lambda function that calculates the percentile of a single parameter
51  std::vector<Model> percentile(num_nodes, Model((int)num_groups));
52  auto param_percentil = [&ensemble_params, p, num_runs, &percentile](auto n, auto get_param) mutable {
53  std::vector<double> single_element(num_runs);
54  for (size_t run = 0; run < num_runs; run++) {
55  auto const& params = ensemble_params[run][n];
56  single_element[run] = get_param(params);
57  }
58  std::sort(single_element.begin(), single_element.end());
59  auto& new_params = get_param(percentile[n]);
60  new_params = single_element[static_cast<size_t>(num_runs * p)];
61  };
62 
63  for (size_t node = 0; node < num_nodes; node++) {
64  percentile[node].parameters.template get<DailyPartialVaccinations<double>>().resize(num_days);
65  percentile[node].parameters.template get<DailyFullVaccinations<double>>().resize(num_days);
66 
67  for (auto i = AgeGroup(0); i < AgeGroup(num_groups); i++) {
68  //Population
69  for (auto compart = Index<InfectionState>(0); compart < InfectionState::Count; ++compart) {
70  param_percentil(
71  node, [ compart, i ](auto&& model) -> auto& {
72  return model.populations[{i, compart}];
73  });
74  }
75  // times
76  param_percentil(
77  node, [i](auto&& model) -> auto& { return model.parameters.template get<TimeExposed<double>>()[i]; });
78  param_percentil(
79  node, [i](auto&& model) -> auto& {
80  return model.parameters.template get<TimeInfectedNoSymptoms<double>>()[i];
81  });
82  param_percentil(
83  node, [i](auto&& model) -> auto& {
84  return model.parameters.template get<TimeInfectedSymptoms<double>>()[i];
85  });
86  param_percentil(
87  node, [i](auto&& model) -> auto& {
88  return model.parameters.template get<TimeInfectedSevere<double>>()[i];
89  });
90  param_percentil(
91  node, [i](auto&& model) -> auto& {
92  return model.parameters.template get<TimeInfectedCritical<double>>()[i];
93  });
94  //probs
95  param_percentil(
96  node, [i](auto&& model) -> auto& {
97  return model.parameters.template get<TransmissionProbabilityOnContact<double>>()[i];
98  });
99  param_percentil(
100  node, [i](auto&& model) -> auto& {
101  return model.parameters.template get<RelativeTransmissionNoSymptoms<double>>()[i];
102  });
103  param_percentil(
104  node, [i](auto&& model) -> auto& {
105  return model.parameters.template get<RiskOfInfectionFromSymptomatic<double>>()[i];
106  });
107  param_percentil(
108  node, [i](auto&& model) -> auto& {
109  return model.parameters.template get<MaxRiskOfInfectionFromSymptomatic<double>>()[i];
110  });
111  param_percentil(
112  node, [i](auto&& model) -> auto& {
113  return model.parameters.template get<RecoveredPerInfectedNoSymptoms<double>>()[i];
114  });
115  param_percentil(
116  node, [i](auto&& model) -> auto& {
117  return model.parameters.template get<SeverePerInfectedSymptoms<double>>()[i];
118  });
119  param_percentil(
120  node, [i](auto&& model) -> auto& {
121  return model.parameters.template get<CriticalPerSevere<double>>()[i];
122  });
123  param_percentil(
124  node, [i](auto&& model) -> auto& {
125  return model.parameters.template get<DeathsPerCritical<double>>()[i];
126  });
127  //vaccinations
128  param_percentil(
129  node, [i](auto&& model) -> auto& {
130  return model.parameters.template get<ReducExposedPartialImmunity<double>>()[i];
131  });
132  param_percentil(
133  node, [i](auto&& model) -> auto& {
134  return model.parameters.template get<ReducExposedImprovedImmunity<double>>()[i];
135  });
136  param_percentil(
137  node, [i](auto&& model) -> auto& {
138  return model.parameters.template get<ReducInfectedSymptomsPartialImmunity<double>>()[i];
139  });
140  param_percentil(
141  node, [i](auto&& model) -> auto& {
142  return model.parameters.template get<ReducInfectedSymptomsImprovedImmunity<double>>()[i];
143  });
144  param_percentil(
145  node, [i](auto&& model) -> auto& {
146  return model.parameters.template get<ReducInfectedSevereCriticalDeadPartialImmunity<double>>()[i];
147  });
148  param_percentil(
149  node, [i](auto&& model) -> auto& {
150  return model.parameters.template get<ReducInfectedSevereCriticalDeadImprovedImmunity<double>>()[i];
151  });
152  param_percentil(
153  node, [i](auto&& model) -> auto& {
154  return model.parameters.template get<ReducTimeInfectedMild<double>>()[i];
155  });
156  param_percentil(
157  node, [i](auto&& model) -> auto& {
158  return model.parameters.template get<VaccinationGap<double>>()[i];
159  });
160  param_percentil(
161  node, [i](auto&& model) -> auto& {
162  return model.parameters.template get<DaysUntilEffectivePartialImmunity<double>>()[i];
163  });
164  param_percentil(
165  node, [i](auto&& model) -> auto& {
166  return model.parameters.template get<DaysUntilEffectiveImprovedImmunity<double>>()[i];
167  });
168 
169  for (auto day = SimulationDay(0); day < num_days; ++day) {
170  param_percentil(
171  node, [ i, day ](auto&& model) -> auto& {
172  return model.parameters.template get<DailyPartialVaccinations<double>>()[{i, day}];
173  });
174  param_percentil(
175  node, [ i, day ](auto&& model) -> auto& {
176  return model.parameters.template get<DailyFullVaccinations<double>>()[{i, day}];
177  });
178  }
179  //virus variants
180  param_percentil(
181  node, [i](auto&& model) -> auto& {
182  return model.parameters.template get<InfectiousnessNewVariant<double>>()[i];
183  });
184  }
185  // group independent params
186  param_percentil(
187  node, [](auto&& model) -> auto& { return model.parameters.template get<Seasonality<double>>(); });
188  param_percentil(
189  node, [](auto&& model) -> auto& { return model.parameters.template get<TestAndTraceCapacity<double>>(); });
190  param_percentil(
191  node, [](auto&& model) -> auto& { return model.parameters.template get<ICUCapacity<double>>(); });
192 
193  for (size_t run = 0; run < num_runs; run++) {
194  auto const& params = ensemble_params[run][node];
195  single_element_ensemble[run] =
196  params.parameters.template get<ICUCapacity<double>>() * params.populations.get_total();
197  }
198  std::sort(single_element_ensemble.begin(), single_element_ensemble.end());
199  percentile[node].parameters.template set<ICUCapacity<double>>(
200  single_element_ensemble[static_cast<size_t>(num_runs * p)]);
201  }
202  return percentile;
203 }
204 
205 } // namespace osecirvvs
206 } // namespace mio
207 
208 #endif //MIO_ODE_SECIRVVS_ANALYZE_RESULT_H
An Index with more than one template parameter combines several Index objects.
Definition: index.h:191
Represents the simulation time as an integer index.
Definition: simulation_day.h:32
Definition: ode_secirvvs/model.h:94
std::vector< Model > ensemble_params_percentile(const std::vector< std::vector< Model >> &ensemble_params, double p)
computes the p percentile of the parameters for each node.
Definition: models/ode_secirvvs/analyze_result.h:37
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:810
Typesafe index representing an age group.
Definition: age_group.h:40