Skip to content

Commit

Permalink
Prob of recovery wasnt in the other models
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Sep 7, 2023
1 parent 5abd1e5 commit 3fe5d6a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 106 deletions.
101 changes: 48 additions & 53 deletions epiworld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15488,14 +15488,13 @@ inline ModelSIR<TSeq>::ModelSIR(
template<typename TSeq = int>
class ModelSEIR : public epiworld::Model<TSeq>
{
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(
Expand Down Expand Up @@ -15573,6 +15572,7 @@ inline ModelSEIR<TSeq>::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);
Expand Down Expand Up @@ -16986,15 +16986,14 @@ inline ModelSISD<TSeq>::ModelSISD(
template<typename TSeq = int>
class ModelSEIRD : public epiworld::Model<TSeq>
{
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(
Expand Down Expand Up @@ -17037,65 +17036,60 @@ class ModelSEIRD : public epiworld::Model<TSeq>
) -> void {

auto state = p->get_state();

if (state == ModelSEIRD<TSeq>::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<int>(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<int>(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;

Expand Down Expand Up @@ -17136,6 +17130,7 @@ inline ModelSEIRD<TSeq>::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);
Expand Down
6 changes: 3 additions & 3 deletions include/epiworld/models/seir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
template<typename TSeq = int>
class ModelSEIR : public epiworld::Model<TSeq>
{
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(
Expand Down Expand Up @@ -99,6 +98,7 @@ inline ModelSEIR<TSeq>::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);
Expand Down
95 changes: 45 additions & 50 deletions include/epiworld/models/seird.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
template<typename TSeq = int>
class ModelSEIRD : public epiworld::Model<TSeq>
{
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(
Expand Down Expand Up @@ -66,65 +65,60 @@ class ModelSEIRD : public epiworld::Model<TSeq>
) -> void {

auto state = p->get_state();

if (state == ModelSEIRD<TSeq>::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<int>(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<int>(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;

Expand Down Expand Up @@ -165,6 +159,7 @@ inline ModelSEIRD<TSeq>::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);
Expand Down

0 comments on commit 3fe5d6a

Please sign in to comment.