parameters_io.h Source File
|
CPP API
|
models/ode_secirvvs/parameters_io.h
Go to the documentation of this file.
57 std::string const& path, std::vector<int> const& vregion, Date date, std::vector<std::vector<double>>& num_Exposed,
58 std::vector<std::vector<double>>& num_InfectedNoSymptoms, std::vector<std::vector<double>>& num_InfectedSymptoms,
61 const std::vector<std::vector<int>>& t_Exposed, const std::vector<std::vector<int>>& t_InfectedNoSymptoms,
62 const std::vector<std::vector<int>>& t_InfectedSymptoms, const std::vector<std::vector<int>>& t_InfectedSevere,
63 const std::vector<std::vector<int>>& t_InfectedCritical, const std::vector<std::vector<double>>& mu_C_R,
68 const std::vector<ConfirmedCasesDataEntry>& rki_data, std::vector<int> const& vregion, Date date,
69 std::vector<std::vector<double>>& num_Exposed, std::vector<std::vector<double>>& num_InfectedNoSymptoms,
70 std::vector<std::vector<double>>& num_InfectedSymptoms, std::vector<std::vector<double>>& num_InfectedSevere,
73 const std::vector<std::vector<int>>& t_InfectedNoSymptoms, const std::vector<std::vector<int>>& t_InfectedSymptoms,
74 const std::vector<std::vector<int>>& t_InfectedSevere, const std::vector<std::vector<int>>& t_InfectedCritical,
89 IOResult<void> read_confirmed_cases_data_fix_recovered(const std::vector<ConfirmedCasesDataEntry>& rki_data,
92 IOResult<void> read_confirmed_cases_data_fix_recovered(std::string const& path, std::vector<int> const& vregion,
113 assert(scaling_factor_inf.size() == num_age_groups); //TODO: allow vector or scalar valued scaling factors
148 std::round(model[county].parameters.template get<TimeInfectedNoSymptoms<double>>()[(AgeGroup)group])));
150 std::round(model[county].parameters.template get<TimeInfectedSymptoms<double>>()[(AgeGroup)group])));
152 std::round(model[county].parameters.template get<TimeInfectedSevere<double>>()[(AgeGroup)group])));
154 std::round(model[county].parameters.template get<TimeInfectedCritical<double>>()[(AgeGroup)group])));
157 model[county].parameters.template get<RecoveredPerInfectedNoSymptoms<double>>()[(AgeGroup)group]);
165 BOOST_OUTCOME_TRY(read_confirmed_cases_data(case_data, region, date, num_Exposed, num_InfectedNoSymptoms,
180 model[county].populations[{AgeGroup(i), InfectionState::ExposedNaive}] = num_Exposed[county][i];
191 model[county].populations[{AgeGroup(i), InfectionState::InfectedCriticalNaive}] = num_icu[county][i];
193 model[county].populations[{AgeGroup(i), InfectionState::SusceptibleImprovedImmunity}] = num_rec[county][i];
199 // Additionally, we set the number of reported deaths to DeadNaive since no information on that is
207 if (std::accumulate(num_InfectedSymptoms[county].begin(), num_InfectedSymptoms[county].end(), double(0.0),
212 "No infections for unvaccinated reported on date {} for region {}. Population data has not been set.",
237 double reduc_t = model[0].parameters.template get<ReducTimeInfectedMild<double>>()[(AgeGroup)group];
241 model[county].parameters.template get<TimeInfectedNoSymptoms<double>>()[(AgeGroup)group] * reduc_t)));
243 model[county].parameters.template get<TimeInfectedSymptoms<double>>()[(AgeGroup)group] * reduc_t)));
245 std::round(model[county].parameters.template get<TimeInfectedSevere<double>>()[(AgeGroup)group])));
247 std::round(model[county].parameters.template get<TimeInfectedCritical<double>>()[(AgeGroup)group])));
252 model[county].parameters.template get<ReducInfectedSymptomsPartialImmunity<double>>()[(AgeGroup)group];
255 .parameters.template get<ReducInfectedSevereCriticalDeadPartialImmunity<double>>()[(AgeGroup)group];
258 .parameters.template get<ReducInfectedSevereCriticalDeadPartialImmunity<double>>()[(AgeGroup)group];
273 BOOST_OUTCOME_TRY(read_confirmed_cases_data(case_data, region, date, num_Exposed, num_InfectedNoSymptoms,
288 model[county].populations[{AgeGroup(i), InfectionState::ExposedPartialImmunity}] = num_Exposed[county][i];
291 model[county].populations[{AgeGroup(i), InfectionState::InfectedNoSymptomsPartialImmunityConfirmed}] = 0;
294 model[county].populations[{AgeGroup(i), InfectionState::InfectedSymptomsPartialImmunityConfirmed}] = 0;
304 if (std::accumulate(num_InfectedSymptoms[county].begin(), num_InfectedSymptoms[county].end(), double(0.0),
334 double reduc_t = model[0].parameters.template get<ReducTimeInfectedMild<double>>()[(AgeGroup)group];
338 model[county].parameters.template get<TimeInfectedNoSymptoms<double>>()[(AgeGroup)group] * reduc_t)));
340 model[county].parameters.template get<TimeInfectedSymptoms<double>>()[(AgeGroup)group] * reduc_t)));
342 std::round(model[county].parameters.template get<TimeInfectedSevere<double>>()[(AgeGroup)group])));
344 std::round(model[county].parameters.template get<TimeInfectedCritical<double>>()[(AgeGroup)group])));
349 model[county].parameters.template get<ReducInfectedSymptomsImprovedImmunity<double>>()[(AgeGroup)group];
351 model[county].parameters.template get<ReducInfectedSevereCriticalDeadImprovedImmunity<double>>()[(
354 model[county].parameters.template get<ReducInfectedSevereCriticalDeadImprovedImmunity<double>>()[(
370 BOOST_OUTCOME_TRY(read_confirmed_cases_data(case_data, region, date, num_Exposed, num_InfectedNoSymptoms,
378 model[county].populations[{AgeGroup(i), InfectionState::ExposedImprovedImmunity}] = num_Exposed[county][i];
381 model[county].populations[{AgeGroup(i), InfectionState::InfectedNoSymptomsImprovedImmunityConfirmed}] = 0;
384 model[county].populations[{AgeGroup(i), InfectionState::InfectedSymptomsImprovedImmunityConfirmed}] = 0;
394 if (std::accumulate(num_InfectedSymptoms[county].begin(), num_InfectedSymptoms[county].end(), double(0.0),
423 BOOST_OUTCOME_TRY(set_confirmed_cases_data(model, case_data, region, date, scaling_factor_inf, set_death));
436 IOResult<void> set_divi_data(std::vector<Model>& model, const std::string& path, const std::vector<int>& vregion,
453 mu_I_U[region].push_back(model[region].parameters.template get<CriticalPerSevere<double>>()[i] *
480 IOResult<void> set_population_data(std::vector<Model>& model, const std::vector<std::vector<double>>& num_population,
485 std::vector<std::vector<double>> vnum_rec(model.size(), std::vector<double>(num_age_groups, 0.0));
487 BOOST_OUTCOME_TRY(read_confirmed_cases_data_fix_recovered(case_data, vregion, date, vnum_rec, 14.));
503 model[region].parameters.template get<DailyPartialVaccinations<double>>()[{i, SimulationDay(0)}] -
518 1 / (S + S_pv * model[region].parameters.template get<ReducExposedPartialImmunity<double>>()[i] +
521 1 / (S + S_pv * model[region].parameters.template get<ReducExposedPartialImmunity<double>>()[i] +
526 S_pv * model[region].parameters.template get<ReducInfectedSymptomsPartialImmunity<double>>()[i] +
527 S_v * model[region].parameters.template get<ReducInfectedSymptomsImprovedImmunity<double>>()[i]);
548 S_pv * model[region].populations[{i, InfectionState::InfectedNoSymptomsPartialImmunity}] * denom_C;
550 S_v * model[region].populations[{i, InfectionState::InfectedNoSymptomsImprovedImmunity}] * denom_C;
555 S_pv * model[region].populations[{i, InfectionState::InfectedNoSymptomsPartialImmunityConfirmed}] *
558 S_v * model[region].populations[{i, InfectionState::InfectedNoSymptomsImprovedImmunityConfirmed}] *
564 S_pv * model[region].parameters.template get<ReducInfectedSymptomsPartialImmunity<double>>()[i] *
567 S_v * model[region].parameters.template get<ReducInfectedSymptomsImprovedImmunity<double>>()[i] *
573 S_pv * model[region].parameters.template get<ReducInfectedSymptomsPartialImmunity<double>>()[i] *
574 model[region].populations[{i, InfectionState::InfectedSymptomsPartialImmunityConfirmed}] * denom_I;
576 S_v * model[region].parameters.template get<ReducInfectedSymptomsImprovedImmunity<double>>()[i] *
577 model[region].populations[{i, InfectionState::InfectedSymptomsImprovedImmunityConfirmed}] * denom_I;
583 model[region].parameters.template get<ReducInfectedSevereCriticalDeadPartialImmunity<double>>()[i] *
593 model[region].parameters.template get<ReducInfectedSevereCriticalDeadPartialImmunity<double>>()[i] *
631 std::max(0.0, double(model[region].populations[{i, InfectionState::SusceptibleImprovedImmunity}])));
675 IOResult<void> set_population_data(std::vector<Model>& model, const std::string& path, const std::string& path_rki,
696 IOResult<void> set_vaccination_data(std::vector<Model<FP>>& model, const std::vector<VaccinationDataEntry>& vacc_data,
703 static_cast<FP>(model[0].parameters.template get<DaysUntilEffectivePartialImmunity<FP>>()[AgeGroup(0)]));
705 static_cast<FP>(model[0].parameters.template get<DaysUntilEffectiveImprovedImmunity<FP>>()[AgeGroup(0)]));
707 static_cast<int>(static_cast<FP>(model[0].parameters.template get<VaccinationGap<FP>>()[AgeGroup(0)]));
714 model[i].parameters.template get<DailyPartialVaccinations<FP>>().resize(SimulationDay(num_days + 1));
715 model[i].parameters.template get<DailyFullVaccinations<FP>>().resize(SimulationDay(num_days + 1));
723 auto max_date_entry = std::max_element(vacc_data.begin(), vacc_data.end(), [](auto&& a, auto&& b) {
731 auto min_date_entry = std::min_element(vacc_data.begin(), vacc_data.end(), [](auto&& a, auto&& b) {
744 return r == 0 || (vacc_data_entry.county_id && vacc_data_entry.county_id == regions::CountyId(r)) ||
758 // d: day of simulation, counted from 0 to num_days (for which we need (approximated) vaccination numbers)
762 // An averaged distance between first and second doses (vaccination_distance) is assumed in the following
763 // and the first doses are computed based on the second doses given 'vaccination_distance' days later.
765 // a person whose second dose is reported at start_date + simulation_day - days_until_effective1 + vaccination_distance
766 // had the first dose on start_date + simulation_day - days_until_effective1. Furthermore, he/she has the full protection
770 // N susceptible individuals to 'Susceptible Partially Vaccinated' state at day d; see secir_vaccinated.h
786 // (where the latter is computed as the difference between the total number at max_date and max_date-1)
800 // a person whose second dose is reported at start_date + simulation_day - days_until_effective2
804 // N susceptible, partially vaccinated individuals to 'SusceptibleImprovedImmunity' state at day d; see secir_vaccinated.h
845 IOResult<void> set_vaccination_data(std::vector<Model<FP>>& model, const std::string& path, Date date,
896 std::vector<Model> models, const std::string& results_dir, const std::vector<int>& counties, Date date,
897 const std::vector<double>& scaling_factor_inf, const double scaling_factor_icu, const int num_days,
898 const std::string& divi_data_path, const std::string& confirmed_cases_path, const std::string& population_data_path,
906 models.size(), TimeSeries<double>::zero(num_days + 1, (size_t)InfectionState::Count * num_groups));
909 BOOST_OUTCOME_TRY(auto&& population_data, read_population_data(population_data_path, counties));
921 BOOST_OUTCOME_TRY(details::set_vaccination_data(models, vacc_data, offset_day, counties, num_days));
924 // TODO: Reuse more code, e.g., set_divi_data (in secir) and a set_divi_data (here) only need a different ModelType.
925 // TODO: add option to set ICU data from confirmed cases if DIVI or other data is not available.
926 BOOST_OUTCOME_TRY(details::set_divi_data(models, divi_data_path, counties, offset_day, scaling_factor_icu));
929 details::set_confirmed_cases_data(models, case_data, counties, offset_day, scaling_factor_inf, true));
930 BOOST_OUTCOME_TRY(details::set_population_data(models, population_data, case_data, counties, offset_day));
934 // in set_population_data the number of death individuals is subtracted from the SusceptibleImprovedImmunity compartment.
935 // Since we should be independent whether we consider them or not, we add them back here before we save the data.
939 extrapolated_data[r][t][(size_t)InfectionState::DeadNaive + age * (size_t)InfectionState::Count];
946 auto extrapolated_rki_data_sum = sum_nodes(std::vector<std::vector<TimeSeries<double>>>{extrapolated_data});
947 BOOST_OUTCOME_TRY(save_result({extrapolated_rki_data_sum[0][0]}, {0}, static_cast<int>(num_groups),
954 IOResult<void> export_input_data_county_timeseries(std::vector<Model>, const std::string&, const std::vector<int>&,
980 IOResult<void> read_input_data_county(std::vector<Model>& model, Date date, const std::vector<int>& county,
984 BOOST_OUTCOME_TRY(details::set_vaccination_data(model, path_join(pydata_dir, "vacc_county_ageinf_ma7.json"), date,
987 // TODO: Reuse more code, e.g., set_divi_data (in secir) and a set_divi_data (here) only need a different ModelType.
988 // TODO: add option to set ICU data from confirmed cases if DIVI or other data is not available.
990 details::set_divi_data(model, path_join(pydata_dir, "county_divi_ma7.json"), county, date, scaling_factor_icu));
992 BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(model, path_join(pydata_dir, "cases_all_county_age_ma7.json"),
994 BOOST_OUTCOME_TRY(details::set_population_data(model, path_join(pydata_dir, "county_current_population.json"),
1001 // (This only represents the vectorization of the previous function over all simulation days...)
1006 path_join(pydata_dir, "county_divi_ma7.json"), path_join(pydata_dir, "cases_all_county_age_ma7.json"),
1029 IOResult<void> read_input_data(std::vector<Model>& model, Date date, const std::vector<int>& node_ids,
1035 details::set_vaccination_data(model, path_join(pydata_dir, "vaccination_data.json"), date, node_ids, num_days));
1037 // TODO: Reuse more code, e.g., set_divi_data (in secir) and a set_divi_data (here) only need a different ModelType.
1038 // TODO: add option to set ICU data from confirmed cases if DIVI or other data is not available.
1039 BOOST_OUTCOME_TRY(details::set_divi_data(model, path_join(pydata_dir, "critical_cases.json"), node_ids, date,
1042 BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(model, path_join(pydata_dir, "confirmed_cases.json"), node_ids,
1044 BOOST_OUTCOME_TRY(details::set_population_data(model, path_join(pydata_dir, "population_data.json"),
1050 // (This only represents the vectorization of the previous function over all simulation days...)
1056 path_join(pydata_dir, "population_data.json"), path_join(pydata_dir, "vaccination_data.json")));
1083 // needs 2 converts as mio::UncertainValue<ScalarType> -> mio::UncertainValue<FP> does not work
1084 model_to[region_idx].property.populations = model_from[region_idx].property.populations.template convert<FP>();
static TimeSeries zero(Eigen::Index num_time_points, Eigen::Index num_elements)
constructs TimeSeries instance and initializes it with zeros
Definition: time_series.h:152
static min_max_return_type< ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 >, ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > >::type min(const ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > &a, const ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > &b)
Definition: ad.hpp:2599
static min_max_return_type< ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 >, ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > >::type max(const ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > &a, const ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > &b)
Definition: ad.hpp:2596
int size(Comm comm)
Return the size of the given communicator.
Definition: miompi.cpp:75
@ ExposedImprovedImmunity
@ InfectedNoSymptomsImprovedImmunityConfirmed
@ InfectedSeverePartialImmunity
@ InfectedNoSymptomsPartialImmunityConfirmed
@ DeadImprovedImmunity
@ InfectedNoSymptomsNaive
@ InfectedNoSymptomsImprovedImmunity
@ InfectedSevereImprovedImmunity
@ InfectedSymptomsPartialImmunityConfirmed
@ ExposedNaive
@ DeadPartialImmunity
@ ExposedPartialImmunity
@ InfectedSymptomsPartialImmunity
@ InfectedNoSymptomsNaiveConfirmed
@ InfectedSevereNaive
@ SusceptiblePartialImmunity
@ InfectedSymptomsImprovedImmunityConfirmed
@ InfectedCriticalPartialImmunity
@ SusceptibleNaive
@ InfectedNoSymptomsPartialImmunity
@ DeadNaive
@ SusceptibleImprovedImmunity
@ InfectedCriticalImprovedImmunity
@ InfectedCriticalNaive
@ InfectedSymptomsImprovedImmunity
@ InfectedSymptomsNaive
@ InfectedSymptomsNaiveConfirmed
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
requires details::IsElementReference< M > RowMajorIterator< M, false > end(M &m)
create a non-const end iterator for the matrix m.
Definition: eigen_util.h:449
auto failure(const IOStatus &s)
Create an object that is implicitly convertible to an error IOResult<T>.
Definition: io.h:380
@ InvalidFileFormat
void log_warning(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:112
std::conditional_t< std::is_const_v< T >, typename mio::Range< typename std::vector< std::remove_const_t< T > >::const_iterator >, typename mio::Range< typename std::vector< std::remove_const_t< T > >::iterator > > VectorRange
Defines generic Range type for IterPair of a vector.
Definition: stl_util.h:341
auto success()
Create an object that is implicitly convertible to a succesful IOResult<void>.
Definition: io.h:359
int get_offset_in_days(Date date1, Date date2)
Computes the offset in days given two dates: first date minus second date.
Definition: date.h:310
requires details::IsElementReference< M > RowMajorIterator< M, false > begin(M &m)
create a non-const iterator to first element of the matrix m.
Definition: eigen_util.h:421
Date offset_date_by_days(Date date, int offset_days)
Computes the new date corresponding to a given date and a offset in days.
Definition: date.h:242
std::string path_join(String &&base, Strings &&... app)
join one ore more strings with path separators.
Definition: stl_util.h:268
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
std::vector< std::vector< TimeSeries< FP > > > sum_nodes(const std::vector< std::vector< TimeSeries< FP >>> &ensemble_result)
Definition: memilio/data/analyze_result.h:268
Generated by