Skip to content

Create a DoubleVectorVariable #52

@giovannic

Description

@giovannic

DoubleVariables can only store one number per individual. But sometimes you want several numbers to represent a variable. So that you can access and update them together. e.g.

# there are 4 aspects of diarrhoea we want to model
diarrhoea_variables <- list(
  DoubleVariable$new(rep(0, parameters$population)), # diarrhoea_bacteria_prior 
  DoubleVariable$new(rep(0, parameters$population)), # diarrhoea_virus_prior
  DoubleVariable$new(rep(0, parameters$population)), # diarrhoea_parasite_prior
  DoubleVariable$new(rep(0, parameters$population)) # diarrhoea_rotavirus_prior
)

# in process...
for (v in diarrhoea_variables) {
  prior <- v$get_values()
  # do something with this aspect of diarrhoea (or perhaps combine with another aspect)
  v$queue_update(new_prior, changed_individuals)
}

It would be much easier to write:

diarrhoea_priors <- DoubleVectorVariable$new(matrix(0, ncol=4, nrow=parameters$population))

# in process...
priors <- diarrhoea_priors$get_values(
  individual_index = NULL, # get all individuals
  column_index = NULL # get all columns
)
# process your priors
diarrhoea_priors$queue_update(
  values = new_priors # matrix of updated priors
  individual_index = NULL, # update all individuals
  column_index = NULL # update all columns
) # will update the priors matrix at the end of the timestep

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmediumWe have estimated that the issue should take an average amount of development time (2 points)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions