Skip to content

Commit

Permalink
ModelSIRD work OK
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Jul 25, 2023
1 parent 7b7ab20 commit e6d92a5
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ S3method(plot,epiworld_seir)
S3method(plot,epiworld_seirconn)
S3method(plot,epiworld_sir)
S3method(plot,epiworld_sirconn)
S3method(plot,epiworld_sird)
S3method(plot,epiworld_sis)
S3method(plot,epiworld_surv)
S3method(print,epiworld_agent)
Expand Down Expand Up @@ -75,6 +76,7 @@ export(ModelSEIR)
export(ModelSEIRCONN)
export(ModelSIR)
export(ModelSIRCONN)
export(ModelSIRD)
export(ModelSIRLogit)
export(ModelSIS)
export(ModelSURV)
Expand Down
4 changes: 4 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ ModelSIR_cpp <- function(name, prevalence, transmission_rate, recovery_rate) {
.Call(`_epiworldR_ModelSIR_cpp`, name, prevalence, transmission_rate, recovery_rate)
}

ModelSIRD_cpp <- function(name, prevalence, transmission_rate, recovery_rate, death_rate) {
.Call(`_epiworldR_ModelSIRD_cpp`, name, prevalence, transmission_rate, recovery_rate, death_rate)
}

ModelSEIRCONN_cpp <- function(name, n, prevalence, contact_rate, transmission_rate, incubation_days, recovery_rate) {
.Call(`_epiworldR_ModelSEIRCONN_cpp`, name, n, prevalence, contact_rate, transmission_rate, incubation_days, recovery_rate)
}
Expand Down
119 changes: 119 additions & 0 deletions inst/include/epiworld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16720,6 +16720,125 @@ inline ModelSEIRCONN<TSeq>::ModelSEIRCONN(
//////////////////////////////////////////////////////////////////////////////*/


/*//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Start of -include/epiworld//models/sird.hpp-
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////*/


#ifndef EPIWORLD_SIRD_H
#define EPIWORLD_SIRD_H

/**
* @brief Template for a Susceptible-Infected-Removed-Deceased (SIRD) model
*
* @param model A Model<TSeq> object where to set up the SIRD.
* @param vname std::string Name of the virus
* @param initial_prevalence epiworld_double Initial prevalence
* @param initial_efficacy epiworld_double Initial susceptibility_reduction of the immune system
* @param initial_recovery epiworld_double Initial recovery_rate rate of the immune system
* @param initial_death epiworld_double Initial death_rate of the immune system
*/
template<typename TSeq = int>
class ModelSIRD : public epiworld::Model<TSeq>
{
public:

ModelSIRD() {};

ModelSIRD(
ModelSIRD<TSeq> & model,
std::string vname,
epiworld_double prevalence,
epiworld_double transmission_rate,
epiworld_double recovery_rate,
epiworld_double death_rate
);

ModelSIRD(
std::string vname,
epiworld_double prevalence,
epiworld_double transmission_rate,
epiworld_double recovery_rate,
epiworld_double death_rate
);

};

template<typename TSeq>
inline ModelSIRD<TSeq>::ModelSIRD(
ModelSIRD<TSeq> & model,
std::string vname,
epiworld_double prevalence,
epiworld_double transmission_rate,
epiworld_double recovery_rate,
epiworld_double death_rate
)
{

// Adding statuses
model.add_state("Susceptible", epiworld::default_update_susceptible<TSeq>);
model.add_state("Infected", epiworld::default_update_exposed<TSeq>);
model.add_state("Recovered"),
model.add_state("Deceased")
;

// Setting up parameters
model.add_param(recovery_rate, "Recovery rate");
model.add_param(transmission_rate, "Transmission rate"),
model.add_param(death_rate, "Death rate");

// Preparing the virus -------------------------------------------
epiworld::Virus<TSeq> virus(vname);
virus.set_state(1,2,3);
virus.set_prob_recovery(&model("Recovery rate"));
virus.set_prob_infecting(&model("Transmission rate"));
virus.set_prob_death(&model("Death rate"));

model.add_virus(virus, prevalence);

model.set_name("Susceptible-Infected-Recovered-Deceased (SIRD)");

return;

}

template<typename TSeq>
inline ModelSIRD<TSeq>::ModelSIRD(
std::string vname,
epiworld_double prevalence,
epiworld_double transmission_rate,
epiworld_double recovery_rate,
epiworld_double death_rate
)
{

ModelSIRD<TSeq>(
*this,
vname,
prevalence,
transmission_rate,
recovery_rate,
death_rate
);

return;

}

#endif
/*//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
End of -include/epiworld//models/sird.hpp-
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////*/


/*//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions man/ModelDiffNet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ModelSEIR.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ModelSEIRCONN.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ModelSIR.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ModelSIRCONN.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ModelSIRLogit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ModelSIS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ModelSURV.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/epiworld-data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ extern "C" SEXP _epiworldR_ModelSIR_cpp(SEXP name, SEXP prevalence, SEXP transmi
END_CPP11
}
// epimodels.cpp
SEXP ModelSIRD_cpp(std::string name, double prevalence, double transmission_rate, double recovery_rate, double death_rate);
extern "C" SEXP _epiworldR_ModelSIRD_cpp(SEXP name, SEXP prevalence, SEXP transmission_rate, SEXP recovery_rate, SEXP death_rate) {
BEGIN_CPP11
return cpp11::as_sexp(ModelSIRD_cpp(cpp11::as_cpp<cpp11::decay_t<std::string>>(name), cpp11::as_cpp<cpp11::decay_t<double>>(prevalence), cpp11::as_cpp<cpp11::decay_t<double>>(transmission_rate), cpp11::as_cpp<cpp11::decay_t<double>>(recovery_rate), cpp11::as_cpp<cpp11::decay_t<double>>(death_rate)));
END_CPP11
}
// epimodels.cpp
SEXP ModelSEIRCONN_cpp(std::string name, unsigned int n, double prevalence, double contact_rate, double transmission_rate, double incubation_days, double recovery_rate);
extern "C" SEXP _epiworldR_ModelSEIRCONN_cpp(SEXP name, SEXP n, SEXP prevalence, SEXP contact_rate, SEXP transmission_rate, SEXP incubation_days, SEXP recovery_rate) {
BEGIN_CPP11
Expand Down Expand Up @@ -740,6 +747,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_epiworldR_ModelSEIRCONN_cpp", (DL_FUNC) &_epiworldR_ModelSEIRCONN_cpp, 7},
{"_epiworldR_ModelSEIR_cpp", (DL_FUNC) &_epiworldR_ModelSEIR_cpp, 5},
{"_epiworldR_ModelSIRCONN_cpp", (DL_FUNC) &_epiworldR_ModelSIRCONN_cpp, 6},
{"_epiworldR_ModelSIRD_cpp", (DL_FUNC) &_epiworldR_ModelSIRD_cpp, 5},
{"_epiworldR_ModelSIRLogit_cpp", (DL_FUNC) &_epiworldR_ModelSIRLogit_cpp, 10},
{"_epiworldR_ModelSIR_cpp", (DL_FUNC) &_epiworldR_ModelSIR_cpp, 4},
{"_epiworldR_ModelSIS_cpp", (DL_FUNC) &_epiworldR_ModelSIS_cpp, 4},
Expand Down
4 changes: 2 additions & 2 deletions src/epimodels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ SEXP ModelSIR_cpp(
cpp11::external_pointer<epiworld::epimodels::ModelSIRD<>> (a)

[[cpp11::register]]
SEXP ModelSIR_cpp(
SEXP ModelSIRD_cpp(
std::string name,
double prevalence,
double transmission_rate,
double recovery_rate,
double death_rate
) {

// Creating a pointer to a ModelSIR model
// Creating a pointer to a ModelSIRD model
WrapSIRD(ptr)(
new epiworld::epimodels::ModelSIRD<>(
name,
Expand Down

0 comments on commit e6d92a5

Please sign in to comment.