From f6f8a48c30d2a8d4c95862378127205641f39b86 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Tue, 23 Apr 2024 10:21:23 -0600 Subject: [PATCH] Renaming model --- examples/11-entities/main.cpp | 2 +- include/epiworld/agent-meat.hpp | 2 +- include/epiworld/model-meat.hpp | 34 +--------- include/epiworld/models/models.hpp | 2 +- ...irentitiesconnected.hpp => seirmixing.hpp} | 68 +++++++++---------- 5 files changed, 40 insertions(+), 68 deletions(-) rename include/epiworld/models/{seirentitiesconnected.hpp => seirmixing.hpp} (85%) diff --git a/examples/11-entities/main.cpp b/examples/11-entities/main.cpp index b8b8d6e7..a0287e06 100644 --- a/examples/11-entities/main.cpp +++ b/examples/11-entities/main.cpp @@ -11,7 +11,7 @@ int main() { 0.05, 0.1, 0.7 }; - epimodels::ModelSEIREntitiesConn model( + epimodels::ModelSEIRMixing model( "Flu", // std::string vname, 100000, // epiworld_fast_uint n, 0.01,// epiworld_double prevalence, diff --git a/include/epiworld/agent-meat.hpp b/include/epiworld/agent-meat.hpp index a5006b5d..f6a36a83 100644 --- a/include/epiworld/agent-meat.hpp +++ b/include/epiworld/agent-meat.hpp @@ -242,7 +242,7 @@ inline void Agent::add_entity( -1, -1 ); - // default_add_entity(a, model); /* passing model makes nothing */ + default_add_entity(a, model); /* passing model makes nothing */ } diff --git a/include/epiworld/model-meat.hpp b/include/epiworld/model-meat.hpp index c6cfecd0..089b6dd1 100644 --- a/include/epiworld/model-meat.hpp +++ b/include/epiworld/model-meat.hpp @@ -1320,7 +1320,6 @@ inline void Model::load_agents_entities_ties( throw std::logic_error("The file " + fn + " was not found."); int linenum = 0; - std::vector< epiworld_fast_uint > source_; std::vector< std::vector< epiworld_fast_uint > > target_(entities.size()); target_.reserve(1e5); @@ -1361,34 +1360,6 @@ inline void Model::load_agents_entities_ties( } - // // Iterating over entities - // for (size_t e = 0u; e < entities.size(); ++e) - // { - - // // This entity will have individuals assigned to it, so we add it - // if (target_[e].size() > 0u) - // { - - // // Filling in the gaps - // prevalence_entity[e] = static_cast(target_[e].size()); - // prevalence_entity_as_proportion[e] = false; - - // // Generating the assignment function - // auto who = target_[e]; - // entities_dist_funs[e] = - // [who](Entity & e, Model* m) -> void { - - // for (auto w : who) - // m->population[w].add_entity(e, m, e.state_init, e.queue_init); - - // return; - - // }; - - // } - - // } - return; } @@ -1413,7 +1384,7 @@ inline void Model::load_agents_entities_ties( for (size_t i = 0u; i < n_entries; ++i) { - if (agents_id[i] >= this->population.size()) + if (agents_ids[i] >= this->population.size()) throw std::length_error( std::string("agents_ids[") + std::to_string(i) + @@ -1436,9 +1407,10 @@ inline void Model::load_agents_entities_ties( std::string(").") ); + // Adding the entity to the agent this->population[agents_ids[i]].add_entity( this->entities[entities_ids[i]], - nullptr + nullptr /* Immediately add it to the agent */ ); } diff --git a/include/epiworld/models/models.hpp b/include/epiworld/models/models.hpp index e3674f39..28a6d0bb 100644 --- a/include/epiworld/models/models.hpp +++ b/include/epiworld/models/models.hpp @@ -19,7 +19,7 @@ namespace epimodels { #include "seirdconnected.hpp" #include "sirlogit.hpp" #include "diffnet.hpp" - #include "seirentitiesconnected.hpp" + #include "seirmixing.hpp" } diff --git a/include/epiworld/models/seirentitiesconnected.hpp b/include/epiworld/models/seirmixing.hpp similarity index 85% rename from include/epiworld/models/seirentitiesconnected.hpp rename to include/epiworld/models/seirmixing.hpp index 75922c8c..0835f9f9 100644 --- a/include/epiworld/models/seirentitiesconnected.hpp +++ b/include/epiworld/models/seirmixing.hpp @@ -4,10 +4,10 @@ /** * @file seirentitiesconnected.hpp - * @brief Template for a Susceptible-Exposed-Infected-Removed (SEIR) model with entities + * @brief Template for a Susceptible-Exposed-Infected-Removed (SEIR) model with mixing */ template -class ModelSEIREntitiesConn : public epiworld::Model +class ModelSEIRMixing : public epiworld::Model { public: @@ -18,14 +18,14 @@ class ModelSEIREntitiesConn : public epiworld::Model std::shared_ptr< epiworld::GroupSampler > group_sampler; - ModelSEIREntitiesConn() {}; + ModelSEIRMixing() {}; /** - * @brief Constructs a ModelSEIREntitiesConn object. + * @brief Constructs a ModelSEIRMixing object. * - * @param model A reference to an existing ModelSEIREntitiesConn object. - * @param vname The name of the ModelSEIREntitiesConn object. + * @param model A reference to an existing ModelSEIRMixing object. + * @param vname The name of the ModelSEIRMixing object. * @param n The number of entities in the model. * @param prevalence The initial prevalence of the disease in the model. * @param contact_rate The contact rate between entities in the model. @@ -35,8 +35,8 @@ class ModelSEIREntitiesConn : public epiworld::Model * @param entities A vector of entity values. * @param entities_names A vector of entity names. */ - ModelSEIREntitiesConn( - ModelSEIREntitiesConn & model, + ModelSEIRMixing( + ModelSEIRMixing & model, std::string vname, epiworld_fast_uint n, epiworld_double prevalence, @@ -50,9 +50,9 @@ class ModelSEIREntitiesConn : public epiworld::Model ); /** - * @brief Constructs a ModelSEIREntitiesConn object. + * @brief Constructs a ModelSEIRMixing object. * - * @param vname The name of the ModelSEIREntitiesConn object. + * @param vname The name of the ModelSEIRMixing object. * @param n The number of entities in the model. * @param prevalence The initial prevalence of the disease in the model. * @param contact_rate The contact rate between entities in the model. @@ -61,7 +61,7 @@ class ModelSEIREntitiesConn : public epiworld::Model * @param recovery_rate The recovery rate of the disease in the model. * @param entities A vector of entity values. */ - ModelSEIREntitiesConn( + ModelSEIRMixing( std::string vname, epiworld_fast_uint n, epiworld_double prevalence, @@ -74,7 +74,7 @@ class ModelSEIREntitiesConn : public epiworld::Model std::vector< double > contact_matrix ); - ModelSEIREntitiesConn & run( + ModelSEIRMixing & run( epiworld_fast_uint ndays, int seed = -1 ); @@ -88,7 +88,7 @@ class ModelSEIREntitiesConn : public epiworld::Model * @param proportions_ Double vector with a single element: * - The proportion of non-infected individuals who have recovered. */ - ModelSEIREntitiesConn & initial_states( + ModelSEIRMixing & initial_states( std::vector< double > proportions_, std::vector< int > queue_ = {} ); @@ -96,7 +96,7 @@ class ModelSEIREntitiesConn : public epiworld::Model }; template -inline ModelSEIREntitiesConn & ModelSEIREntitiesConn::run( +inline ModelSEIRMixing & ModelSEIRMixing::run( epiworld_fast_uint ndays, int seed ) @@ -109,7 +109,7 @@ inline ModelSEIREntitiesConn & ModelSEIREntitiesConn::run( } template -inline void ModelSEIREntitiesConn::reset() +inline void ModelSEIRMixing::reset() { Model::reset(); @@ -126,11 +126,11 @@ inline void ModelSEIREntitiesConn::reset() } template -inline Model * ModelSEIREntitiesConn::clone_ptr() +inline Model * ModelSEIRMixing::clone_ptr() { - ModelSEIREntitiesConn * ptr = new ModelSEIREntitiesConn( - *dynamic_cast*>(this) + ModelSEIRMixing * ptr = new ModelSEIRMixing( + *dynamic_cast*>(this) ); return dynamic_cast< Model *>(ptr); @@ -149,8 +149,8 @@ inline Model * ModelSEIREntitiesConn::clone_ptr() * @param recovery_rate Probability of recovery */ template -inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( - ModelSEIREntitiesConn & model, +inline ModelSEIRMixing::ModelSEIRMixing( + ModelSEIRMixing & model, std::string vname, epiworld_fast_uint n, epiworld_double prevalence, @@ -180,8 +180,8 @@ inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( // Downcasting to retrieve the sampler attached to the // class - ModelSEIREntitiesConn * m_down = - dynamic_cast *>(m); + ModelSEIRMixing * m_down = + dynamic_cast *>(m); // Sampling from the agent's entities auto & samples = m->array_int_tmp; @@ -205,7 +205,7 @@ inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( continue; // If the neighbor is infected, then proceed - if (neighbor.get_state() == ModelSEIREntitiesConn::INFECTED) + if (neighbor.get_state() == ModelSEIRMixing::INFECTED) { auto & v = neighbor.get_virus(); @@ -240,7 +240,7 @@ inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( p->set_virus( *m->array_virus_tmp[which], m, - ModelSEIREntitiesConn::EXPOSED + ModelSEIRMixing::EXPOSED ); return; @@ -253,7 +253,7 @@ inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( auto state = p->get_state(); - if (state == ModelSEIREntitiesConn::EXPOSED) + if (state == ModelSEIRMixing::EXPOSED) { // Getting the virus @@ -263,13 +263,13 @@ inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( if (m->runif() < 1.0/(v->get_incubation(m))) { - p->change_state(m, ModelSEIREntitiesConn::INFECTED); + p->change_state(m, ModelSEIRMixing::INFECTED); return; } - } else if (state == ModelSEIREntitiesConn::INFECTED) + } else if (state == ModelSEIRMixing::INFECTED) { @@ -330,9 +330,9 @@ inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( // Preparing the virus ------------------------------------------- epiworld::Virus virus(vname); virus.set_state( - ModelSEIREntitiesConn::EXPOSED, - ModelSEIREntitiesConn::RECOVERED, - ModelSEIREntitiesConn::RECOVERED + ModelSEIRMixing::EXPOSED, + ModelSEIRMixing::RECOVERED, + ModelSEIRMixing::RECOVERED ); virus.set_prob_infecting(&model("Prob. Transmission")); @@ -346,14 +346,14 @@ inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( // Adding the empty population model.agents_empty_graph(n); - model.set_name("Susceptible-Exposed-Infected-Removed (SEIR) (connected)"); + model.set_name("Susceptible-Exposed-Infected-Removed (SEIR) with Mixing"); return; } template -inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( +inline ModelSEIRMixing::ModelSEIRMixing( std::string vname, epiworld_fast_uint n, epiworld_double prevalence, @@ -385,7 +385,7 @@ inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( group_sizes ); - ModelSEIREntitiesConn( + ModelSEIRMixing( *this, vname, n, @@ -404,7 +404,7 @@ inline ModelSEIREntitiesConn::ModelSEIREntitiesConn( } template -inline ModelSEIREntitiesConn & ModelSEIREntitiesConn::initial_states( +inline ModelSEIRMixing & ModelSEIRMixing::initial_states( std::vector< double > proportions_, std::vector< int > /* queue_ */ )