analyze_result.h Source File

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