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(node, [compart, i](auto&& model) -> auto& {
76  return model.populations[{i, compart}];
77  });
78  }
79  // times
80  param_percentil(node, [i](auto&& model) -> auto& {
81  return model.parameters.template get<TimeExposed<FP>>()[i];
82  });
83  param_percentil(node, [i](auto&& model) -> auto& {
84  return model.parameters.template get<TimeInfectedNoSymptoms<FP>>()[i];
85  });
86  param_percentil(node, [i](auto&& model) -> auto& {
87  return model.parameters.template get<TimeInfectedSymptoms<FP>>()[i];
88  });
89  param_percentil(node, [i](auto&& model) -> auto& {
90  return model.parameters.template get<TimeInfectedSevere<FP>>()[i];
91  });
92  param_percentil(node, [i](auto&& model) -> auto& {
93  return model.parameters.template get<TimeInfectedCritical<FP>>()[i];
94  });
95  //probs
96  param_percentil(node, [i](auto&& model) -> auto& {
97  return model.parameters.template get<TransmissionProbabilityOnContact<FP>>()[i];
98  });
99  param_percentil(node, [i](auto&& model) -> auto& {
100  return model.parameters.template get<RelativeTransmissionNoSymptoms<FP>>()[i];
101  });
102  param_percentil(node, [i](auto&& model) -> auto& {
103  return model.parameters.template get<RiskOfInfectionFromSymptomatic<FP>>()[i];
104  });
105  param_percentil(node, [i](auto&& model) -> auto& {
106  return model.parameters.template get<MaxRiskOfInfectionFromSymptomatic<FP>>()[i];
107  });
108  param_percentil(node, [i](auto&& model) -> auto& {
109  return model.parameters.template get<RecoveredPerInfectedNoSymptoms<FP>>()[i];
110  });
111  param_percentil(node, [i](auto&& model) -> auto& {
112  return model.parameters.template get<SeverePerInfectedSymptoms<FP>>()[i];
113  });
114  param_percentil(node, [i](auto&& model) -> auto& {
115  return model.parameters.template get<CriticalPerSevere<FP>>()[i];
116  });
117  param_percentil(node, [i](auto&& model) -> auto& {
118  return model.parameters.template get<DeathsPerCritical<FP>>()[i];
119  });
120  //vaccinations
121  param_percentil(node, [i](auto&& model) -> auto& {
122  return model.parameters.template get<ReducExposedPartialImmunity<FP>>()[i];
123  });
124  param_percentil(node, [i](auto&& model) -> auto& {
125  return model.parameters.template get<ReducExposedImprovedImmunity<FP>>()[i];
126  });
127  param_percentil(node, [i](auto&& model) -> auto& {
128  return model.parameters.template get<ReducInfectedSymptomsPartialImmunity<FP>>()[i];
129  });
130  param_percentil(node, [i](auto&& model) -> auto& {
131  return model.parameters.template get<ReducInfectedSymptomsImprovedImmunity<FP>>()[i];
132  });
133  param_percentil(node, [i](auto&& model) -> auto& {
134  return model.parameters.template get<ReducInfectedSevereCriticalDeadPartialImmunity<FP>>()[i];
135  });
136  param_percentil(node, [i](auto&& model) -> auto& {
137  return model.parameters.template get<ReducInfectedSevereCriticalDeadImprovedImmunity<FP>>()[i];
138  });
139  param_percentil(node, [i](auto&& model) -> auto& {
140  return model.parameters.template get<ReducTimeInfectedMild<FP>>()[i];
141  });
142  param_percentil(node, [i](auto&& model) -> auto& {
143  return model.parameters.template get<DaysUntilEffectivePartialVaccination<FP>>()[i];
144  });
145  param_percentil(node, [i](auto&& model) -> auto& {
146  return model.parameters.template get<DaysUntilEffectiveImprovedVaccination<FP>>()[i];
147  });
148 
149  for (auto day = SimulationDay(0); day < num_days; ++day) {
150  param_percentil(node, [i, day](auto&& model) -> auto& {
151  return model.parameters.template get<DailyPartialVaccinations<FP>>()[{i, day}];
152  });
153  param_percentil(node, [i, day](auto&& model) -> auto& {
154  return model.parameters.template get<DailyFullVaccinations<FP>>()[{i, day}];
155  });
156  param_percentil(node, [i, day](auto&& model) -> auto& {
157  return model.parameters.template get<DailyBoosterVaccinations<FP>>()[{i, day}];
158  });
159  }
160  //virus variants
161  param_percentil(node, [i](auto&& model) -> auto& {
162  return model.parameters.template get<InfectiousnessNewVariant<FP>>()[i];
163  });
164  }
165  // group independent params
166  param_percentil(node, [](auto&& model) -> auto& {
167  return model.parameters.template get<Seasonality<FP>>();
168  });
169  param_percentil(node, [](auto&& model) -> auto& {
170  return model.parameters.template get<TestAndTraceCapacity<FP>>();
171  });
172  param_percentil(node, [](auto&& model) -> auto& {
173  return model.parameters.template get<ICUCapacity<FP>>();
174  });
175  param_percentil(node, [](auto&& model) -> auto& {
176  return model.parameters.template get<DynamicNPIsImplementationDelay<FP>>();
177  });
178 
179  for (size_t run = 0; run < num_runs; run++) {
180 
181  auto const& params = ensemble_params[run][node];
182  single_element_ensemble[run] =
183  params.parameters.template get<ICUCapacity<FP>>() * params.populations.get_total();
184  }
185  std::sort(single_element_ensemble.begin(), single_element_ensemble.end());
186  percentile[node].parameters.template set<ICUCapacity<FP>>(
187  single_element_ensemble[static_cast<size_t>(num_runs * p)]);
188  }
189  return percentile;
190 }
191 
192 } // namespace osecirts
193 } // namespace mio
194 
195 #endif //MIO_ODE_SECIRTS_ANALYZE_RESULT_H
An Index with more than one template parameter combines several Index objects.
Definition: index.h:181
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:809
The AgeGroup struct is used as a dynamically sized tag for all age dependent categories.
Definition: age_group.h:32