Skip to content

Commit

Permalink
Adding initial states function
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Oct 17, 2023
1 parent f799249 commit f2394d9
Show file tree
Hide file tree
Showing 50 changed files with 1,009 additions and 190 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Package: epiworldRdev
Package: epiworldR
Type: Package
Title: Fast Agent-Based Epi Models
Version: 0.0-3.9000
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export(globalaction_tool)
export(globalaction_tool_logit)
export(has_tool)
export(has_virus)
export(initial_states)
export(make_saver)
export(plot_generation_time)
export(plot_incidence)
Expand Down Expand Up @@ -189,4 +190,4 @@ importFrom(stats,aggregate)
importFrom(stats,quantile)
importFrom(stats,sd)
importFrom(utils,read.table)
useDynLib(epiworldRdev, .registration = TRUE)
useDynLib(epiworldR, .registration = TRUE)
5 changes: 5 additions & 0 deletions R/ModelSEIR.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#' @export
#' @family Models
#' @aliases epiworld_seir
#' @details
#' The [initial_state] function allows the user to set the initial state of the
#' model. The user must provide a vector of proportions indicating the following
#' values: (1) Proportion of non-infected agents who are removed, and (2)
#' Proportion of exposed agents to be set as infected.
#' @returns
#' - The `ModelSEIR`function returns a model of class [epiworld_model].
#' @examples
Expand Down
6 changes: 6 additions & 0 deletions R/ModelSEIRD.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#' @param x Object of class SEIRD.
#' @param ... Currently ignore.
#' @export
#' @details
#' The [initial_state] function allows the user to set the initial state of the
#' model. The user must provide a vector of proportions indicating the following
#' values: (1) Proportion of exposed agents who are infected, (2)
#' proportion of non-infected agents already removed, and (3) proportion of
#' non-ifected agents already deceased.
#' @family Models
#' @aliases epiworld_seird
#' @returns
Expand Down
6 changes: 6 additions & 0 deletions R/ModelSEIRDCONN.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
#' @param ... Currently ignore.
#' @param n Number of individuals in the population.
#' @export
#' @details
#' The [initial_state] function allows the user to set the initial state of the
#' model. The user must provide a vector of proportions indicating the following
#' values: (1) Proportion of exposed agents who are infected, (2)
#' proportion of non-infected agents already removed, and (3) proportion of
#' non-ifected agents already deceased.
#' @family Models
#' @aliases epiworld_seirdconn
#' @returns
Expand Down
4 changes: 4 additions & 0 deletions R/ModelSIR.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#' @param ... Additional arguments passed to [graphics::plot].
#' @export
#' @family Models
#' @details
#' The [initial_state] function allows the user to set the initial state of the
#' model. In particular, the user can specify how many of the non-infected
#' agents have been removed at the beginning of the simulation.
#' @aliases epiworld_sir
#' @returns
#' - The `ModelSIR` function returns a model of class [epiworld_model].
Expand Down
4 changes: 4 additions & 0 deletions R/ModelSIRCONN.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#' @param n Number of individuals in the population.
#' @export
#' @family Models
#' @details
#' The [initial_state] function allows the user to set the initial state of the
#' model. In particular, the user can specify how many of the non-infected
#' agents have been removed at the beginning of the simulation.
#' @returns
#' - The `ModelSIRCONN`function returns a model of class [epiworld_model].
#' @aliases epiworld_sirconn
Expand Down
5 changes: 5 additions & 0 deletions R/ModelSIRD.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#' @param x Object of class SIR.
#' @param ... Additional arguments passed to [graphics::plot].
#' @export
#' @details
#' The [initial_state] function allows the user to set the initial state of the
#' model. The user must provide a vector of proportions indicating the following
#' values: (1) proportion of non-infected agents already removed, and (2) proportion of
#' non-ifected agents already deceased.
#' @family Models
#' @aliases epiworld_sird
#' @returns
Expand Down
5 changes: 5 additions & 0 deletions R/ModelSIRDCONN.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#' @param ... Currently ignore.
#' @param n Number of individuals in the population.
#' @export
#' @details
#' The [initial_state] function allows the user to set the initial state of the
#' model. The user must provide a vector of proportions indicating the following
#' values: (1) proportion of non-infected agents already removed, and (2) proportion of
#' non-ifected agents already deceased.
#' @family Models
#' @returns
#' - The `ModelSIRDCONN`function returns a model of class [epiworld_model].
Expand Down
4 changes: 4 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ get_network_cpp <- function(model) {
.Call(`_epiworldR_get_network_cpp`, model)
}

initial_states_cpp <- function(model, proportions) {
.Call(`_epiworldR_initial_states_cpp`, model, proportions)
}

tool_cpp <- function(name, susceptibility_reduction, transmission_reduction, recovery_enhancer, death_reduction) {
.Call(`_epiworldR_tool_cpp`, name, susceptibility_reduction, transmission_reduction, recovery_enhancer, death_reduction)
}
Expand Down
4 changes: 2 additions & 2 deletions R/epiworldR-package.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' epiworldRdev
#' @useDynLib epiworldRdev, .registration = TRUE
#' epiworldR
#' @useDynLib epiworldR, .registration = TRUE
#' @importFrom graphics boxplot plot
"_PACKAGE"

14 changes: 14 additions & 0 deletions R/model-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,17 @@ get_tool <- function(model, tool_pos) {
class = "epiworld_tool"
)
}

#' @export
#' @param proportions Numeric vector. Proportions in which agents will be
#' distributed (see details).
#' @return
#' - `inital_states` returns the model with an updated initial state.
#' @rdname epiworld-methods
initial_states <- function(model, proportions) {

stopifnot_model(model)
invisible(initial_states_cpp(model, proportions))

}

6 changes: 3 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ This R package includes several popular epidemiological models including
This Susceptible-Infected-Recovered model features a population of 100,000 agents simulated in a small-world network. Each agent is connected to ten other agents. One percent of the population has the virus, with a 70% chance of transmission. Infected individuals recover at a 0.3 rate:

```{r example}
library(epiworldRdev)
library(epiworldR)
# Creating a SIR model
sir <- ModelSIR(
Expand Down Expand Up @@ -204,8 +204,8 @@ sir <- ModelSIR(
net <- get_transmissions(sir)
# Plotting
library(epiworldRdev)
library(epiworldRdev)
library(epiworldR)
library(epiworldR)
x <- graph_from_edgelist(as.matrix(net[,2:3]) + 1)
nplot(x, edge.curvature = 0, edge.color = "gray", skip.vertex=TRUE)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ virus, with a 70% chance of transmission. Infected individuals recover
at a 0.3 rate:

``` r
library(epiworldRdev)
library(epiworldR)

# Creating a SIR model
sir <- ModelSIR(
Expand Down Expand Up @@ -345,9 +345,9 @@ sir <- ModelSIR(
net <- get_transmissions(sir)

# Plotting
library(epiworldRdev)
library(epiworldR)
#> Loading required package: grid
library(epiworldRdev)
library(epiworldR)
#>
#> Attaching package: 'igraph'
#> The following object is masked from 'package:netplot':
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -4519,7 +4519,7 @@ sed -i -E 's/^useDynLib\([a-zA-Z]+/useDynLib('"${epiworldname}"'/g' NAMESPACE
sed -i -E 's/^Package:.+/Package: '"${epiworldname}"'/g' DESCRIPTION
sed -i -E 's/^\\(name|alias|title)\{[a-zA-Z]+/\\\1{'"${epiworldname}"'/g' man/epiworldRfaster-package.Rd
sed -i -E 's/^\\(name|alias|title)\{[a-zA-Z]+/\\\1{'"${epiworldname}"'/g' man/epiworldR-package.Rd
# configure is writing to config.log, and then calls config.status.
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ AC_CONFIG_COMMANDS_POST(
)

AC_CONFIG_COMMANDS_POST(
[sed -i -E 's/^\\(name|alias|title)\{[[a-zA-Z]]+/\\\1{'"${epiworldname}"'/g' man/epiworldRfaster-package.Rd]
[sed -i -E 's/^\\(name|alias|title)\{[[a-zA-Z]]+/\\\1{'"${epiworldname}"'/g' man/epiworldR-package.Rd]
)

AC_OUTPUT
2 changes: 0 additions & 2 deletions inst/include/epiworld/agent-bones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ class Agent {
std::vector< ToolPtr<TSeq> > tools;
epiworld_fast_uint n_tools = 0u;

epiworld_fast_uint action_counter = 0u;

std::vector< Agent<TSeq> * > sampled_agents;
size_t sampled_agents_n = 0u;
std::vector< size_t > sampled_agents_left;
Expand Down
5 changes: 1 addition & 4 deletions inst/include/epiworld/agent-meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ inline Agent<TSeq>::Agent(Agent<TSeq> && p) :
state_last_changed(p.state_last_changed),
id(p.id),
tools(std::move(p.tools)), /// Needs to be adjusted
n_tools(p.n_tools),
action_counter(p.action_counter)
n_tools(p.n_tools)
{

state = p.state;
Expand Down Expand Up @@ -138,8 +137,6 @@ inline Agent<TSeq> & Agent<TSeq>::operator=(
tools[i] = std::make_shared<Tool<TSeq>>(*other_agent.tools[i]);
tools[i]->set_agent(this, i);
}

action_counter = other_agent.action_counter;

return *this;

Expand Down
Loading

0 comments on commit f2394d9

Please sign in to comment.