Skip to content

Commit

Permalink
added possibility to save infection events in cluster-size-SIS
Browse files Browse the repository at this point in the history
  • Loading branch information
benmaier committed Jan 22, 2020
1 parent aab4acb commit 63b4afe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion _tacoma/_tacoma.cpp
Expand Up @@ -1414,7 +1414,7 @@ PYBIND11_MODULE(_tacoma, m)
.def_readwrite("t_simulation", &SIS::t_simulation, "Absolute run time of the simulation.");

py::class_<cluster_size_SIS>(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<size_t, double, double, double, size_t, size_t, double, size_t, bool>(),
.def(py::init<size_t, double, double, double, size_t, size_t, double, size_t, bool, bool>(),
py::arg("N"),
py::arg("t_simulation"),
py::arg("infection_rate"),
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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_<coverage_SIS>(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")
Expand Down
6 changes: 6 additions & 0 deletions _tacoma/cluster_size_SIS.cpp
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions _tacoma/cluster_size_SIS.h
Expand Up @@ -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;
Expand All @@ -69,6 +70,7 @@ class cluster_size_SIS
vector < double > R0;
vector < size_t > SI;
vector < size_t > I;
vector < pair <size_t, size_t>> infection_events;

cluster_size_SIS(
size_t _N,
Expand All @@ -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
)
{
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tacoma/metadata.py
Expand Up @@ -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"
Expand Down

0 comments on commit 63b4afe

Please sign in to comment.