Skip to content

Commit

Permalink
Adding new docker image for debugging. Fixed difference in rec rates
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Sep 7, 2023
1 parent 3a76c85 commit c1f9303
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 140 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ README\.html
\.gitattributes

paper\..+
docker
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Capture the current value of the version of the package in DESCRIPTION
VERSION := $(shell grep Version DESCRIPTION | sed -e 's/Version: //')

build: docs clean
cd .. && rm -f epiworldR_*.tar.gz & R CMD build epiworldR

debug: clean
EPI_CONFIG="-DEPI_DEBUG -Wall -pedantic -g" R CMD INSTALL .
docker run --rm -ti -w/mnt -v $(PWD):/mnt uofuepibio/epiworldr:debug make docker-debug

docker-debug:
EPI_CONFIG="-DEPI_DEBUG -Wall -pedantic -g" R CMD INSTALL \
--no-docs --build .

install: build
which R
Expand All @@ -26,7 +33,7 @@ clean:
docs:
Rscript --vanilla -e 'devtools::document()'

.PHONY: build update check clean docs
.PHONY: build update check clean docs docker-debug

checkv: build
R CMD check --as-cran --use-valgrind epiworldR*.tar.gz
Expand Down
10 changes: 8 additions & 2 deletions R/ModelSEIRD.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ ModelSEIRD <- function(
) {

structure(
ModelSEIRD_cpp(name, prevalence, transmission_rate, incubation_days,
recovery_rate, death_rate),
ModelSEIRD_cpp(
name = name,
prevalence = prevalence,
transmission_rate = transmission_rate,
incubation_days = incubation_days,
recovery_rate = recovery_rate,
death_rate = death_rate
),
class = c("epiworld_seird", "epiworld_model")
)

Expand Down
19 changes: 19 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM rocker/r-base:latest

RUN \
echo 'options(repos=c(CRAN="https://cloud.r-project.org"))' >> ~/.Rprofile && \
Rscript --vanilla -e 'getOption("repos")'


RUN Rscript --vanilla -e "install.packages('cpp11', dependencies = TRUE, repos = 'https://cloud.r-project.org')"



RUN mkdir ~/.R && \
echo "CXXFLAGS=-g -O0" > ~/.R/Makevars && \
echo "CXX14FLAGS=-g -O0" >> ~/.R/Makevars && \
echo "CXX17FLAGS=-g -O0" >> ~/.R/Makevars && \
echo "CXX11FLAGS=-g -O0" >> ~/.R/Makevars && \
echo "SAFE_FLAGS=-g -O0" >> ~/.R/Makevars

CMD ["bash"]
2 changes: 2 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
docker build -t uofuepibio/epiworldr:debug -f Dockerfile .
6 changes: 3 additions & 3 deletions inst/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 inst/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
Loading

0 comments on commit c1f9303

Please sign in to comment.