From 3fe5d6a012759240dd27e15f55fef4ce1e21f0df Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Thu, 7 Sep 2023 14:01:45 -0600 Subject: [PATCH] Prob of recovery wasnt in the other models --- epiworld.hpp | 101 ++++++++++++++---------------- include/epiworld/models/seir.hpp | 6 +- include/epiworld/models/seird.hpp | 95 +++++++++++++--------------- 3 files changed, 96 insertions(+), 106 deletions(-) diff --git a/epiworld.hpp b/epiworld.hpp index 5b7d7e70c..47dc1e24f 100644 --- a/epiworld.hpp +++ b/epiworld.hpp @@ -15488,14 +15488,13 @@ inline ModelSIR::ModelSIR( template class ModelSEIR : public epiworld::Model { -private: + +public: static const int SUSCEPTIBLE = 0; static const int EXPOSED = 1; static const int INFECTED = 2; static const int REMOVED = 3; -public: - ModelSEIR() {}; ModelSEIR( @@ -15573,6 +15572,7 @@ inline ModelSEIR::ModelSEIR( virus.set_prob_infecting(&model("Transmission rate")); virus.set_incubation(&model("Incubation days")); + virus.set_prob_recovery(&model("Recovery rate")); // Adding the tool and the virus model.add_virus(virus, prevalence); @@ -16986,15 +16986,14 @@ inline ModelSISD::ModelSISD( template class ModelSEIRD : public epiworld::Model { -private: + +public: static const int SUSCEPTIBLE = 0; static const int EXPOSED = 1; static const int INFECTED = 2; static const int REMOVED = 3; static const int DECEASED = 4; -public: - ModelSEIRD() {}; ModelSEIRD( @@ -17037,65 +17036,60 @@ class ModelSEIRD : public epiworld::Model ) -> void { auto state = p->get_state(); - - if (state == ModelSEIRD::INFECTED) + + // Odd: Die, Even: Recover + epiworld_fast_uint n_events = 0u; + for (const auto & v : p->get_viruses()) { + // Die + m->array_double_tmp[n_events++] = + v->get_prob_death(m) * (1.0 - p->get_death_reduction(v, m)); - // Odd: Die, Even: Recover - epiworld_fast_uint n_events = 0u; - for (const auto & v : p->get_viruses()) - { - - // Die - m->array_double_tmp[n_events++] = - v->get_prob_death(m) * (1.0 - p->get_death_reduction(v, m)); - - // Recover - m->array_double_tmp[n_events++] = - 1.0 - (1.0 - v->get_prob_recovery(m)) * (1.0 - p->get_recovery_enhancer(v, m)); - - } + // Recover + m->array_double_tmp[n_events++] = + 1.0 - (1.0 - v->get_prob_recovery(m)) * (1.0 - p->get_recovery_enhancer(v, m)); + } + #ifdef EPI_DEBUG - if (n_events == 0u) - { - printf_epiworld( - "[epi-debug] agent %i has 0 possible events!!\n", - static_cast(p->get_id()) - ); - throw std::logic_error("Zero events in exposed."); - } + if (n_events == 0u) + { + printf_epiworld( + "[epi-debug] agent %i has 0 possible events!!\n", + static_cast(p->get_id()) + ); + throw std::logic_error("Zero events in exposed."); + } #else - if (n_events == 0u) - return; + if (n_events == 0u) + return; #endif + + + // Running the roulette + int which = roulette(n_events, m); + + if (which < 0) + return; + + // Which roulette happen? + if ((which % 2) == 0) // If odd + { + size_t which_v = std::ceil(which / 2); + p->rm_agent_by_virus(which_v, m); - // Running the roulette - int which = roulette(n_events, m); - - if (which < 0) - return; + } else { - // Which roulette happen? - if ((which % 2) == 0) // If odd - { - - size_t which_v = std::ceil(which / 2); - p->rm_agent_by_virus(which_v, m); - - } else { - - size_t which_v = std::floor(which / 2); - p->rm_virus(which_v, m); - - } + size_t which_v = std::floor(which / 2); + p->rm_virus(which_v, m); - return ; + } + + return ; - } else - throw std::logic_error("This function can only be applied to exposed or infected individuals. (SEIRD)") ; + return; @@ -17136,6 +17130,7 @@ inline ModelSEIRD::ModelSEIRD( virus.set_prob_infecting(&model("Transmission rate")); virus.set_incubation(&model("Incubation days")); virus.set_prob_death(&model("Death rate")); + virus.set_prob_recovery(&model("Recovery rate")); // Adding the tool and the virus model.add_virus(virus, prevalence); diff --git a/include/epiworld/models/seir.hpp b/include/epiworld/models/seir.hpp index 25f240855..e310a1697 100644 --- a/include/epiworld/models/seir.hpp +++ b/include/epiworld/models/seir.hpp @@ -14,14 +14,13 @@ template class ModelSEIR : public epiworld::Model { -private: + +public: static const int SUSCEPTIBLE = 0; static const int EXPOSED = 1; static const int INFECTED = 2; static const int REMOVED = 3; -public: - ModelSEIR() {}; ModelSEIR( @@ -99,6 +98,7 @@ inline ModelSEIR::ModelSEIR( virus.set_prob_infecting(&model("Transmission rate")); virus.set_incubation(&model("Incubation days")); + virus.set_prob_recovery(&model("Recovery rate")); // Adding the tool and the virus model.add_virus(virus, prevalence); diff --git a/include/epiworld/models/seird.hpp b/include/epiworld/models/seird.hpp index adf121e2d..a89e038b7 100644 --- a/include/epiworld/models/seird.hpp +++ b/include/epiworld/models/seird.hpp @@ -15,15 +15,14 @@ template class ModelSEIRD : public epiworld::Model { -private: + +public: static const int SUSCEPTIBLE = 0; static const int EXPOSED = 1; static const int INFECTED = 2; static const int REMOVED = 3; static const int DECEASED = 4; -public: - ModelSEIRD() {}; ModelSEIRD( @@ -66,65 +65,60 @@ class ModelSEIRD : public epiworld::Model ) -> void { auto state = p->get_state(); - - if (state == ModelSEIRD::INFECTED) + + // Odd: Die, Even: Recover + epiworld_fast_uint n_events = 0u; + for (const auto & v : p->get_viruses()) { + // Die + m->array_double_tmp[n_events++] = + v->get_prob_death(m) * (1.0 - p->get_death_reduction(v, m)); - // Odd: Die, Even: Recover - epiworld_fast_uint n_events = 0u; - for (const auto & v : p->get_viruses()) - { - - // Die - m->array_double_tmp[n_events++] = - v->get_prob_death(m) * (1.0 - p->get_death_reduction(v, m)); - - // Recover - m->array_double_tmp[n_events++] = - 1.0 - (1.0 - v->get_prob_recovery(m)) * (1.0 - p->get_recovery_enhancer(v, m)); - - } + // Recover + m->array_double_tmp[n_events++] = + 1.0 - (1.0 - v->get_prob_recovery(m)) * (1.0 - p->get_recovery_enhancer(v, m)); + } + #ifdef EPI_DEBUG - if (n_events == 0u) - { - printf_epiworld( - "[epi-debug] agent %i has 0 possible events!!\n", - static_cast(p->get_id()) - ); - throw std::logic_error("Zero events in exposed."); - } + if (n_events == 0u) + { + printf_epiworld( + "[epi-debug] agent %i has 0 possible events!!\n", + static_cast(p->get_id()) + ); + throw std::logic_error("Zero events in exposed."); + } #else - if (n_events == 0u) - return; + if (n_events == 0u) + return; #endif + + + // Running the roulette + int which = roulette(n_events, m); + + if (which < 0) + return; + + // Which roulette happen? + if ((which % 2) == 0) // If odd + { + size_t which_v = std::ceil(which / 2); + p->rm_agent_by_virus(which_v, m); - // Running the roulette - int which = roulette(n_events, m); - - if (which < 0) - return; + } else { - // Which roulette happen? - if ((which % 2) == 0) // If odd - { - - size_t which_v = std::ceil(which / 2); - p->rm_agent_by_virus(which_v, m); - - } else { - - size_t which_v = std::floor(which / 2); - p->rm_virus(which_v, m); - - } + size_t which_v = std::floor(which / 2); + p->rm_virus(which_v, m); - return ; + } + + return ; - } else - throw std::logic_error("This function can only be applied to exposed or infected individuals. (SEIRD)") ; + return; @@ -165,6 +159,7 @@ inline ModelSEIRD::ModelSEIRD( virus.set_prob_infecting(&model("Transmission rate")); virus.set_incubation(&model("Incubation days")); virus.set_prob_death(&model("Death rate")); + virus.set_prob_recovery(&model("Recovery rate")); // Adding the tool and the virus model.add_virus(virus, prevalence);