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

Create a DoubleVectorVariable #52

Open
giovannic opened this issue Feb 17, 2021 · 1 comment
Open

Create a DoubleVectorVariable #52

giovannic opened this issue Feb 17, 2021 · 1 comment
Labels
enhancement New feature or request medium We have estimated that the issue should take an average amount of development time (2 points)

Comments

@giovannic
Copy link
Member

giovannic commented Feb 17, 2021

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
@giovannic
Copy link
Member Author

giovannic commented Feb 17, 2021

There's also the possibility for a different design. Something like:

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

# in process...
priors <- diarrhoea_priors$current() # gets the current matrix
# process your priors
diarrhoea_priors$set_next(new_priors) # will update the priors matrix at the end of the timestep

@giovannic giovannic reopened this Mar 1, 2021
@giovannic giovannic added enhancement New feature or request medium We have estimated that the issue should take an average amount of development time (2 points) labels Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request medium We have estimated that the issue should take an average amount of development time (2 points)
Projects
None yet
Development

No branches or pull requests

1 participant