LCOV - code coverage report
Current view: top level - models/ode_secirvvs - analyze_result.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 123 123 100.0 %
Date: 2024-11-18 12:45:26 Functions: 94 94 100.0 %

          Line data    Source code
       1             : /* 
       2             : * Copyright (C) 2020-2024 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 ODESECIRVVS_ANALYZE_RESULT_H
      21             : #define ODESECIRVVS_ANALYZE_RESULT_H
      22             : 
      23             : #include "ode_secirvvs/infection_state.h"
      24             : #include "ode_secirvvs/parameters.h"
      25             : 
      26             : namespace mio
      27             : {
      28             : namespace osecirvvs
      29             : {
      30             : /**
      31             :     * @brief computes the p percentile of the parameters for each node.
      32             :     * @param ensemble_result graph of multiple simulation runs
      33             :     * @param p percentile value in open interval (0, 1)
      34             :     * @return p percentile of the parameters over all runs
      35             :     */
      36             : template <class Model>
      37           9 : std::vector<Model> ensemble_params_percentile(const std::vector<std::vector<Model>>& ensemble_params, double p)
      38             : {
      39           9 :     assert(p > 0.0 && p < 1.0 && "Invalid percentile value.");
      40             : 
      41           9 :     auto num_runs   = ensemble_params.size();
      42           9 :     auto num_nodes  = ensemble_params[0].size();
      43           9 :     auto num_groups = (size_t)ensemble_params[0][0].parameters.get_num_groups();
      44           9 :     auto num_days   = ensemble_params[0][0]
      45           9 :                         .parameters.template get<DailyFirstVaccination<double>>()
      46           9 :                         .template size<mio::SimulationDay>();
      47             : 
      48          18 :     std::vector<double> single_element_ensemble(num_runs);
      49             : 
      50             :     // lambda function that calculates the percentile of a single parameter
      51          27 :     std::vector<Model> percentile(num_nodes, Model((int)num_groups));
      52     3416256 :     auto param_percentil = [&ensemble_params, p, num_runs, &percentile](auto n, auto get_param) mutable {
      53      276993 :         std::vector<double> single_element(num_runs);
      54     1107972 :         for (size_t run = 0; run < num_runs; run++) {
      55     1846620 :             auto const& params  = ensemble_params[run][n];
      56      923310 :             single_element[run] = get_param(params);
      57             :         }
      58       92331 :         std::sort(single_element.begin(), single_element.end());
      59      184662 :         auto& new_params = get_param(percentile[n]);
      60      184662 :         new_params       = single_element[static_cast<size_t>(num_runs * p)];
      61       92331 :     };
      62             : 
      63          18 :     for (size_t node = 0; node < num_nodes; node++) {
      64           9 :         percentile[node].parameters.template get<DailyFirstVaccination<double>>().resize(num_days);
      65           9 :         percentile[node].parameters.template get<DailyFullVaccination<double>>().resize(num_days);
      66             : 
      67          54 :         for (auto i = AgeGroup(0); i < AgeGroup(num_groups); i++) {
      68             :             //Population
      69        1260 :             for (auto compart = Index<InfectionState>(0); compart < InfectionState::Count; ++compart) {
      70        1215 :                 param_percentil(
      71       13365 :                     node, [ compart, i ](auto&& model) -> auto& {
      72       13365 :                         return model.populations[{i, compart}];
      73             :                     });
      74             :             }
      75             :             // times
      76          45 :             param_percentil(
      77         495 :                 node, [i](auto&& model) -> auto& { return model.parameters.template get<TimeExposed<double>>()[i]; });
      78          45 :             param_percentil(
      79         495 :                 node, [i](auto&& model) -> auto& {
      80         495 :                     return model.parameters.template get<TimeInfectedNoSymptoms<double>>()[i];
      81             :                 });
      82          45 :             param_percentil(
      83         495 :                 node, [i](auto&& model) -> auto& {
      84         495 :                     return model.parameters.template get<TimeInfectedSymptoms<double>>()[i];
      85             :                 });
      86          45 :             param_percentil(
      87         495 :                 node, [i](auto&& model) -> auto& {
      88         495 :                     return model.parameters.template get<TimeInfectedSevere<double>>()[i];
      89             :                 });
      90          45 :             param_percentil(
      91         495 :                 node, [i](auto&& model) -> auto& {
      92         495 :                     return model.parameters.template get<TimeInfectedCritical<double>>()[i];
      93             :                 });
      94             :             //probs
      95          45 :             param_percentil(
      96         495 :                 node, [i](auto&& model) -> auto& {
      97         495 :                     return model.parameters.template get<TransmissionProbabilityOnContact<double>>()[i];
      98             :                 });
      99          45 :             param_percentil(
     100         495 :                 node, [i](auto&& model) -> auto& {
     101         495 :                     return model.parameters.template get<RelativeTransmissionNoSymptoms<double>>()[i];
     102             :                 });
     103          45 :             param_percentil(
     104         495 :                 node, [i](auto&& model) -> auto& {
     105         495 :                     return model.parameters.template get<RiskOfInfectionFromSymptomatic<double>>()[i];
     106             :                 });
     107          45 :             param_percentil(
     108         495 :                 node, [i](auto&& model) -> auto& {
     109         495 :                     return model.parameters.template get<MaxRiskOfInfectionFromSymptomatic<double>>()[i];
     110             :                 });
     111          45 :             param_percentil(
     112         495 :                 node, [i](auto&& model) -> auto& {
     113         495 :                     return model.parameters.template get<RecoveredPerInfectedNoSymptoms<double>>()[i];
     114             :                 });
     115          45 :             param_percentil(
     116         495 :                 node, [i](auto&& model) -> auto& {
     117         495 :                     return model.parameters.template get<SeverePerInfectedSymptoms<double>>()[i];
     118             :                 });
     119          45 :             param_percentil(
     120         495 :                 node, [i](auto&& model) -> auto& {
     121         495 :                     return model.parameters.template get<CriticalPerSevere<double>>()[i];
     122             :                 });
     123          45 :             param_percentil(
     124         495 :                 node, [i](auto&& model) -> auto& {
     125         495 :                     return model.parameters.template get<DeathsPerCritical<double>>()[i];
     126             :                 });
     127             :             //vaccinations
     128          45 :             param_percentil(
     129         495 :                 node, [i](auto&& model) -> auto& {
     130         495 :                     return model.parameters.template get<ReducExposedPartialImmunity<double>>()[i];
     131             :                 });
     132          45 :             param_percentil(
     133         495 :                 node, [i](auto&& model) -> auto& {
     134         495 :                     return model.parameters.template get<ReducExposedImprovedImmunity<double>>()[i];
     135             :                 });
     136          45 :             param_percentil(
     137         495 :                 node, [i](auto&& model) -> auto& {
     138         495 :                     return model.parameters.template get<ReducInfectedSymptomsPartialImmunity<double>>()[i];
     139             :                 });
     140          45 :             param_percentil(
     141         495 :                 node, [i](auto&& model) -> auto& {
     142         495 :                     return model.parameters.template get<ReducInfectedSymptomsImprovedImmunity<double>>()[i];
     143             :                 });
     144          45 :             param_percentil(
     145         495 :                 node, [i](auto&& model) -> auto& {
     146         495 :                     return model.parameters.template get<ReducInfectedSevereCriticalDeadPartialImmunity<double>>()[i];
     147             :                 });
     148          45 :             param_percentil(
     149         495 :                 node, [i](auto&& model) -> auto& {
     150         495 :                     return model.parameters.template get<ReducInfectedSevereCriticalDeadImprovedImmunity<double>>()[i];
     151             :                 });
     152          45 :             param_percentil(
     153         495 :                 node, [i](auto&& model) -> auto& {
     154         495 :                     return model.parameters.template get<ReducTimeInfectedMild<double>>()[i];
     155             :                 });
     156          45 :             param_percentil(
     157         495 :                 node, [i](auto&& model) -> auto& {
     158         495 :                     return model.parameters.template get<VaccinationGap<double>>()[i];
     159             :                 });
     160          45 :             param_percentil(
     161         495 :                 node, [i](auto&& model) -> auto& {
     162         495 :                     return model.parameters.template get<DaysUntilEffectivePartialImmunity<double>>()[i];
     163             :                 });
     164          45 :             param_percentil(
     165         495 :                 node, [i](auto&& model) -> auto& {
     166         495 :                     return model.parameters.template get<DaysUntilEffectiveImprovedImmunity<double>>()[i];
     167             :                 });
     168             : 
     169       45045 :             for (auto day = SimulationDay(0); day < num_days; ++day) {
     170       45000 :                 param_percentil(
     171      495000 :                     node, [ i, day ](auto&& model) -> auto& {
     172      495000 :                         return model.parameters.template get<DailyFirstVaccination<double>>()[{i, day}];
     173             :                     });
     174       45000 :                 param_percentil(
     175      495000 :                     node, [ i, day ](auto&& model) -> auto& {
     176      495000 :                         return model.parameters.template get<DailyFullVaccination<double>>()[{i, day}];
     177             :                     });
     178             :             }
     179             :             //virus variants
     180          45 :             param_percentil(
     181         495 :                 node, [i](auto&& model) -> auto& {
     182         495 :                     return model.parameters.template get<InfectiousnessNewVariant<double>>()[i];
     183             :                 });
     184             :         }
     185             :         // group independent params
     186           9 :         param_percentil(
     187          99 :             node, [](auto&& model) -> auto& { return model.parameters.template get<Seasonality<double>>(); });
     188           9 :         param_percentil(
     189          99 :             node, [](auto&& model) -> auto& { return model.parameters.template get<TestAndTraceCapacity<double>>(); });
     190           9 :         param_percentil(
     191          99 :             node, [](auto&& model) -> auto& { return model.parameters.template get<ICUCapacity<double>>(); });
     192           9 :         param_percentil(
     193          99 :             node, [](auto&& model) -> auto& {
     194          99 :                 return model.parameters.template get<DynamicNPIsImplementationDelay<double>>();
     195             :             });
     196             : 
     197          99 :         for (size_t run = 0; run < num_runs; run++) {
     198          90 :             auto const& params = ensemble_params[run][node];
     199          90 :             single_element_ensemble[run] =
     200          90 :                 params.parameters.template get<ICUCapacity<double>>() * params.populations.get_total();
     201             :         }
     202           9 :         std::sort(single_element_ensemble.begin(), single_element_ensemble.end());
     203          18 :         percentile[node].parameters.template set<ICUCapacity<double>>(
     204           9 :             single_element_ensemble[static_cast<size_t>(num_runs * p)]);
     205             :     }
     206          18 :     return percentile;
     207           9 : }
     208             : 
     209             : } // namespace osecirvvs
     210             : } // namespace mio
     211             : 
     212             : #endif //ODESECIRVVS

Generated by: LCOV version 1.14