From 63b4afedc2ccd5bbc6da70886d8c4c9ab294bc99 Mon Sep 17 00:00:00 2001 From: Benjamin Maier Date: Thu, 23 Jan 2020 00:11:52 +0100 Subject: [PATCH] added possibility to save infection events in cluster-size-SIS --- _tacoma/_tacoma.cpp | 6 +++++- _tacoma/cluster_size_SIS.cpp | 6 ++++++ _tacoma/cluster_size_SIS.h | 5 +++++ tacoma/metadata.py | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/_tacoma/_tacoma.cpp b/_tacoma/_tacoma.cpp index 6c24079..a16a0ed 100644 --- a/_tacoma/_tacoma.cpp +++ b/_tacoma/_tacoma.cpp @@ -1414,7 +1414,7 @@ PYBIND11_MODULE(_tacoma, m) .def_readwrite("t_simulation", &SIS::t_simulation, "Absolute run time of the simulation."); py::class_(m, "cluster_size_SIS", R"pbdoc(Base class for the simulation of an SIS compartmental infection model on a temporal network. Pass this to :func:`tacoma.api.gillespie_epidemics` to simulate and retrieve the simulation results. This simulation runs until all initially infected nodes recovered at least once, which is useful to find the epidemic threshold by measuring the impact of the seed(s). If you want to sample the standard observables, set ``sampling_dt>=0.0``.)pbdoc") - .def(py::init(), + .def(py::init(), py::arg("N"), py::arg("t_simulation"), py::arg("infection_rate"), @@ -1423,6 +1423,7 @@ PYBIND11_MODULE(_tacoma, m) py::arg("number_of_initially_vaccinated") = 0, py::arg("sampling_dt") = -1.0, py::arg("seed") = 0, + py::arg("save_infection_events") = false, py::arg("verbose") = false, R"pbdoc( Parameters @@ -1450,6 +1451,8 @@ PYBIND11_MODULE(_tacoma, m) If it is 0.0, sample at every change. seed : int, default = 0 Seed for RNG initialization. If this is 0, the seed will be initialized randomly. + save_infection_events: bool, default = False + If true, the edge along which each infection event occurs is saved in the variable `infection_events`. verbose : bool, default = False Be talkative. )pbdoc") @@ -1464,6 +1467,7 @@ PYBIND11_MODULE(_tacoma, m) )pbdoc") .def_readwrite("SI", &cluster_size_SIS::SI, "A list containing the number of :math:`SI`-links at time :math:`t`.") .def_readwrite("I", &cluster_size_SIS::I, "A list containing the number of infected at time :math:`t`.") + .def_readwrite("infection_events", &cluster_size_SIS::infection_events, "A list containing the edges along which each infection event took place, in the form (infection_source, susceptible).") .def_readwrite("t_simulation", &cluster_size_SIS::t_simulation, "Absolute run time of the simulation."); py::class_(m, "coverage_SIS", R"pbdoc(Base class for the simulation of an SIS compartmental infection model on a temporal network. Pass this to :func:`tacoma.api.gillespie_SIS` to simulate and retrieve the simulation results. This simulation runs until a certain amount of nodes have been infected at least once, which is useful to fifind the epidemic threshold and thus, only the lifetime of the process is measured. If you want to sample the standard observables, set ``sampling_dt>=0.0``.)pbdoc") diff --git a/_tacoma/cluster_size_SIS.cpp b/_tacoma/cluster_size_SIS.cpp index 6ae0d63..a17054f 100644 --- a/_tacoma/cluster_size_SIS.cpp +++ b/_tacoma/cluster_size_SIS.cpp @@ -165,6 +165,12 @@ void cluster_size_SIS::infection_event() // change node status of this node node_status[this_susceptible] = EPI::I; + // save the infection edge in observable + if(save_infection_events) + { + infection_events.push_back(SI_edges.at(this_susceptible_index)); + } + // add node to the covered nodes covered_nodes.insert(this_susceptible); diff --git a/_tacoma/cluster_size_SIS.h b/_tacoma/cluster_size_SIS.h index b9006bb..815c721 100644 --- a/_tacoma/cluster_size_SIS.h +++ b/_tacoma/cluster_size_SIS.h @@ -54,6 +54,7 @@ class cluster_size_SIS size_t number_of_initially_infected; size_t number_of_initially_vaccinated; size_t seed; + bool save_infection_events; bool verbose; double sampling_dt; double lifetime; @@ -69,6 +70,7 @@ class cluster_size_SIS vector < double > R0; vector < size_t > SI; vector < size_t > I; + vector < pair > infection_events; cluster_size_SIS( size_t _N, @@ -79,6 +81,7 @@ class cluster_size_SIS size_t _number_of_initially_vaccinated = 0, double _sampling_dt = 0.0, size_t _seed = 0, + bool _save_infection_events = false, bool _verbose = false ) { @@ -88,6 +91,7 @@ class cluster_size_SIS recovery_rate = _recovery_rate; number_of_initially_vaccinated = _number_of_initially_vaccinated; number_of_initially_infected = _number_of_initially_infected; + save_infection_events = _save_infection_events; verbose = _verbose; seed = _seed; sampling_dt = _sampling_dt; @@ -106,6 +110,7 @@ class cluster_size_SIS R0.clear(); SI.clear(); I.clear(); + infection_events.clear(); covered_nodes.clear(); initially_infected.clear(); lifetime = -1; diff --git a/tacoma/metadata.py b/tacoma/metadata.py index a0dca3e..563b8c0 100644 --- a/tacoma/metadata.py +++ b/tacoma/metadata.py @@ -3,7 +3,7 @@ Contains a bunch of information about this package """ -__version__ = "0.1.17" +__version__ = "0.1.18" __author__ = "Benjamin F. Maier" __copyright__ = "Copyright 2018, Benjamin F. Maier"