Skip to content

Commit 3cb8989

Browse files
dabeleWadimKoslowmknaranja
authored
155 add vaccination model from paper (#233)
Added the new SECIRVVS model which accounts for three different paths or subpopulations. One naive population and two populations having different levels of immunity. These levels can be obtained by vaccination schemes. Infection, hospitalization etc. are possible for all subpopulations but with different probabilities. An undergone infection makes the individual go to the subpopulation which has the highest immunity level. (Re)infection is possible for all individuals. Co-authored-by: kosl_wa <[email protected]> Co-authored-by: Martin J. Kühn <[email protected]>
1 parent f2b0d02 commit 3cb8989

73 files changed

Lines changed: 12491 additions & 1417 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ add_subdirectory(memilio)
7474
if (MEMILIO_BUILD_MODELS)
7575
add_subdirectory(models/abm)
7676
add_subdirectory(models/secir)
77+
add_subdirectory(models/ode_secirvvs)
7778
add_subdirectory(models/ide_seir)
7879
add_subdirectory(models/ode_seir)
7980
endif()

cpp/examples/parameter_study_secir.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
*/
2020
#include "secir/secir_parameters_io.h"
2121
#include "secir/parameter_space.h"
22-
#include "secir/parameter_studies.h"
22+
#include "memilio/compartments/parameter_studies.h"
2323
#include "memilio/mobility/mobility.h"
24+
#include "memilio/io/result_io.h"
2425

2526
/**
2627
* @brief creates xml file with a single run parameter study with std 0 (used to save parameters of individual runs)
@@ -68,8 +69,10 @@ write_single_run_result(const int run,
6869
std::transform(graph.nodes().begin(), graph.nodes().end(), std::back_inserter(ids), [](auto& node) {
6970
return node.id;
7071
});
72+
auto num_groups = (int)(size_t)graph.nodes()[0].property.get_simulation().get_model().parameters.get_num_groups();
7173
BOOST_OUTCOME_TRY(
72-
mio::save_result(all_results, ids, mio::path_join(abs_path, ("Results_run" + std::to_string(run) + ".h5"))));
74+
mio::save_result(all_results, ids, num_groups,
75+
mio::path_join(abs_path, ("Results_run" + std::to_string(run) + ".h5"))));
7376

7477
return mio::success();
7578
}
@@ -163,17 +166,20 @@ int main()
163166

164167
//create study
165168
auto num_runs = size_t(1);
166-
mio::ParameterStudy<mio::SecirSimulation<>> parameter_study(model, t0, tmax, 0.2, num_runs);
169+
mio::ParameterStudy<mio::SecirSimulation<>> parameter_study(model, t0, tmax, num_runs);
167170

168171
//run study
169-
int run = 0;
170-
auto lambda = [&run](auto&& graph) {
172+
int run = 0;
173+
auto sample_graph = [](auto&& graph) {
174+
return mio::draw_sample(graph);
175+
};
176+
auto handle_result = [&run](auto&& graph) {
171177
auto write_result_status = write_single_run_result(run++, graph);
172178
if (!write_result_status) {
173179
std::cout << "Error writing result: " << write_result_status.error().formatted_message();
174180
}
175181
};
176-
parameter_study.run(lambda);
182+
parameter_study.run(sample_graph, handle_result);
177183

178184
return 0;
179185
}

cpp/examples/read_graph.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
* limitations under the License.
1919
*/
2020
#include "memilio/mobility/mobility.h"
21-
#include "secir/secir_parameters_io.h"
2221
#include "memilio/io/mobility_io.h"
22+
#include "memilio/compartments/parameter_studies.h"
23+
#include "secir/parameter_space.h"
24+
#include "secir/secir_parameters_io.h"
2325
#include <data_dir.h>
2426
#include <iostream>
2527

cpp/memilio/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ configure_file(config_internal.h.in memilio/config_internal.h)
22

33
add_library(memilio
44
config.h
5+
data/analyze_result.h
6+
data/analyze_result.cpp
7+
epidemiology/age_group.h
58
epidemiology/populations.h
69
epidemiology/damping.cpp
710
epidemiology/damping.h
@@ -15,16 +18,22 @@ add_library(memilio
1518
epidemiology/dynamic_npis.cpp
1619
epidemiology/regions.h
1720
epidemiology/regions.cpp
21+
epidemiology/simulation_day.h
1822
epidemiology/holiday_data_de.ipp
1923
compartments/compartmentalmodel.h
2024
compartments/simulation.h
25+
compartments/parameter_studies.h
2126
io/io.h
2227
io/io.cpp
2328
io/hdf5_cpp.h
2429
io/json_serializer.h
2530
io/json_serializer.cpp
2631
io/mobility_io.h
2732
io/mobility_io.cpp
33+
io/result_io.h
34+
io/result_io.cpp
35+
io/epi_data.h
36+
io/epi_data.cpp
2837
math/euler.cpp
2938
math/euler.h
3039
math/smoother.h

cpp/memilio/compartments/compartmentalmodel.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ template <class T>
5858
using has_apply_constraints_member_function = is_expression_valid<details::apply_constraints_expr_t, T>;
5959

6060
/**
61-
* @brief ComppartmentalModel is a template for a compartmental model for an
61+
* @brief CompartmentalModel is a template for a compartmental model for an
6262
* array of initial populations and a parameter set
6363
*
6464
* The Populations must be a concrete class derived from the Populations template,
@@ -71,9 +71,10 @@ using has_apply_constraints_member_function = is_expression_valid<details::apply
7171
* studies
7272
*
7373
*/
74-
template <class Pop, class Params>
74+
template <class Comp, class Pop, class Params>
7575
struct CompartmentalModel {
7676
public:
77+
using Compartments = Comp;
7778
using Populations = Pop;
7879
using ParameterSet = Params;
7980

cpp/models/secir/parameter_studies.h renamed to cpp/memilio/compartments/parameter_studies.h

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#ifndef PARAMETER_STUDIES_H
2121
#define PARAMETER_STUDIES_H
2222

23-
#include "secir/secir.h"
24-
#include "secir/parameter_space.h"
2523
#include "memilio/utils/time_series.h"
2624
#include "memilio/mobility/mobility.h"
2725
#include "memilio/compartments/simulation.h"
@@ -89,33 +87,18 @@ class ParameterStudy
8987
m_graph.add_node(0, model);
9088
}
9189

92-
/**
93-
* @brief create study for single compartment model with normal distributions.
94-
* Sets all parameters to normal distribution with specified relative deviation.
95-
* @param params SecirParams object
96-
* @param t0 start time of simulations
97-
* @param tmax end time of simulations
98-
* @param dev_rel relative deviation of parameters distributions
99-
* @param num_runs number of runs in ensemble run
100-
*/
101-
ParameterStudy(typename Simulation::Model const& model, double t0, double tmax, double dev_rel, size_t num_runs)
102-
: ParameterStudy(model, t0, tmax, num_runs)
103-
{
104-
set_params_distributions_normal(m_graph.nodes()[0].property, t0, tmax, dev_rel);
105-
}
106-
10790
/*
10891
* @brief Carry out all simulations in the parameter study.
10992
* Save memory and enable more runs by immediately processing and/or discarding the result.
11093
* @param result_processing_function Processing function for simulation results, e.g., output function.
11194
* Receives the result after each run is completed.
11295
*/
113-
template<class HandleSimulationResultFunction>
114-
void run(HandleSimulationResultFunction result_processing_function)
96+
template <class SampleGraphFunction, class HandleSimulationResultFunction>
97+
void run(SampleGraphFunction sample_graph, HandleSimulationResultFunction result_processing_function)
11598
{
11699
// Iterate over all parameters in the parameter space
117100
for (size_t i = 0; i < m_num_runs; i++) {
118-
auto sim = create_sampled_simulation();
101+
auto sim = create_sampled_simulation(sample_graph);
119102
sim.advance(m_tmax);
120103

121104
result_processing_function(std::move(sim).get_graph());
@@ -124,15 +107,16 @@ class ParameterStudy
124107

125108
/*
126109
* @brief Carry out all simulations in the parameter study.
127-
* Convinience function for a few number of runs, but uses a lot of memory.
110+
* Convenience function for a few number of runs, but uses a lot of memory.
128111
* @return vector of results of each run.
129112
*/
130-
std::vector<mio::Graph<mio::SimulationNode<Simulation>, mio::MigrationEdge>> run()
113+
template <class SampleGraphFunction>
114+
std::vector<mio::Graph<mio::SimulationNode<Simulation>, mio::MigrationEdge>> run(SampleGraphFunction sample_graph)
131115
{
132116
std::vector<mio::Graph<mio::SimulationNode<Simulation>, mio::MigrationEdge>> ensemble_result;
133117
ensemble_result.reserve(m_num_runs);
134118

135-
run([&ensemble_result](auto&& r) {
119+
run(sample_graph, [&ensemble_result](auto&& r) {
136120
ensemble_result.emplace_back(std::move(r));
137121
});
138122

@@ -219,47 +203,18 @@ class ParameterStudy
219203

220204
private:
221205
//sample parameters and create simulation
222-
mio::GraphSimulation<mio::Graph<mio::SimulationNode<Simulation>, mio::MigrationEdge>> create_sampled_simulation()
206+
template <class SampleGraphFunction>
207+
mio::GraphSimulation<mio::Graph<mio::SimulationNode<Simulation>, mio::MigrationEdge>>
208+
create_sampled_simulation(SampleGraphFunction sample_graph)
223209
{
224210
mio::Graph<mio::SimulationNode<Simulation>, mio::MigrationEdge> sim_graph;
225211

226-
//sample global parameters
227-
auto& shared_params_model = m_graph.nodes()[0].property;
228-
draw_sample_infection(shared_params_model);
229-
auto& shared_contacts = shared_params_model.parameters.template get<mio::ContactPatterns>();
230-
shared_contacts.draw_sample_dampings();
231-
auto& shared_dynamic_npis = shared_params_model.parameters.template get<DynamicNPIsInfected>();
232-
shared_dynamic_npis.draw_sample();
233-
234-
for (auto& params_node : m_graph.nodes()) {
235-
auto& node_model = params_node.property;
236-
237-
//sample local parameters
238-
draw_sample_demographics(params_node.property);
239-
240-
//copy global parameters
241-
//save demographic parameters so they aren't overwritten
242-
auto local_icu_capacity = node_model.parameters.template get<ICUCapacity>();
243-
auto local_tnt_capacity = node_model.parameters.template get<TestAndTraceCapacity>();
244-
auto local_holidays = node_model.parameters.template get<ContactPatterns>().get_school_holidays();
245-
node_model.parameters = shared_params_model.parameters;
246-
node_model.parameters.template get<ICUCapacity>() = local_icu_capacity;
247-
node_model.parameters.template get<TestAndTraceCapacity>() = local_tnt_capacity;
248-
node_model.parameters.template get<ContactPatterns>().get_school_holidays() = local_holidays;
249-
250-
node_model.parameters.template get<ContactPatterns>().make_matrix();
251-
node_model.apply_constraints();
252-
253-
sim_graph.add_node(params_node.id, node_model, m_t0, m_dt_integration);
212+
auto sampled_graph = sample_graph(m_graph);
213+
for (auto&& node : sampled_graph.nodes()) {
214+
sim_graph.add_node(node.id, node.property, m_t0, m_dt_integration);
254215
}
255-
256-
for (auto& edge : m_graph.edges()) {
257-
auto edge_params = edge.property;
258-
apply_dampings(edge_params.get_coefficients(), shared_contacts.get_dampings(), [&edge_params](auto& v) {
259-
return make_migration_damping_vector(edge_params.get_coefficients().get_shape(), v);
260-
});
261-
edge_params.set_dynamic_npis_infected(shared_dynamic_npis);
262-
sim_graph.add_edge(edge.start_node_idx, edge.end_node_idx, edge_params);
216+
for (auto&& edge : sampled_graph.edges()) {
217+
sim_graph.add_edge(edge.start_node_idx, edge.end_node_idx, edge.property);
263218
}
264219

265220
return make_migration_sim(m_t0, m_dt_graph_sim, std::move(sim_graph));

0 commit comments

Comments
 (0)