Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing create_progression_process() rates to probs #295

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions R/disease_progression.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ create_progression_process <- function(
state,
from_state,
to_state,
rate,
prob,
infectivity,
new_infectivity
) {
Expand All @@ -31,13 +31,13 @@ create_progression_process <- function(
# Retrieve the indices of all individuals in the to_move state:
index <- state$get_index_of(from_state)

# If the length of rate is greater than 1 (when it's a variable):
if (inherits(rate, "DoubleVariable")) {
rate <- rate$get_values(index)
# If function receives a vector transition probabilities rather than a single value:
if (length(prob) > 1) {
prob <- prob[index$to_vector()]
}

# Sample the individuals to be moved into a new Bitset using the transition rate(s):
to_move <- index$sample(1/rate)
# Sample the individuals to be moved into a new Bitset using the transition probabilities:
to_move <- index$sample(prob)

# Update the infection status of those individuals who are moving:
update_infection(
Expand All @@ -52,12 +52,12 @@ create_progression_process <- function(

create_asymptomatic_progression_process <- function(
state,
rate,
prob,
variables,
parameters
) {
function(timestep) {
to_move <- state$get_index_of('D')$sample(1/rate)
to_move <- state$get_index_of('D')$sample(prob)
update_to_asymptomatic_infection(
variables,
parameters,
Expand Down
13 changes: 5 additions & 8 deletions R/processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,23 @@ create_processes <- function(
),
create_asymptomatic_progression_process(
variables$state,
parameters$dd,
1 - exp(-1/parameters$dd),
variables,
parameters
),
create_progression_process(
variables$state,
'A',
'U',
parameters$da,
1 - exp(-1/parameters$da),
variables$infectivity,
parameters$cu
),
create_progression_process(
variables$state,
'U',
'S',
parameters$du,
1 - exp(-1/parameters$du),
variables$infectivity,
0
)
Expand All @@ -109,16 +109,13 @@ create_processes <- function(
# =======================
# Antimalarial Resistance
# =======================
# Add an a new process which governs the transition from Tr to S when
# antimalarial resistance is simulated. The rate of transition switches
# from a parameter to a variable when antimalarial resistance == TRUE.

# Assign the dt input to a separate object with the default single parameter value:
dt_input <- parameters$dt

# If antimalarial resistance is switched on, assign dt variable values to the
if(parameters$antimalarial_resistance) {
dt_input <- variables$dt
dt_input <- variables$dt$get_values()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't dt vary over time?

It appears to me like we have to pass the DoubleVariable so that the disease progression process can calculate probabilities based on dt for that timestep.

}

# Create the progression process for Tr --> S specifying dt_input as the rate:
Expand All @@ -128,7 +125,7 @@ create_processes <- function(
variables$state,
'Tr',
'S',
dt_input,
1 - exp(-1/dt_input),
variables$infectivity,
0
)
Expand Down
Loading