mrc-ide / individual

R Package for individual based epidemiological models
https://mrc-ide.github.io/individual
Other
30 stars 16 forks source link

MultiCategory Variable #47

Open giovannic opened 3 years ago

giovannic commented 3 years ago

Create an optimised variable to represent individuals who could be in a combination of states.

So we can have something like:

vaccinated_with = MulitCategory$new(
  c('AstraZeneca', 'Pfizer', 'Moderna'),
  matrix(FALSE, ncol=3, nrow=population) # initialise with a boolean matrix of shape (category, population)
)

vaccination_process <- function(timestep) {
  ...
  # add a new vaccine without overwriting existing vaccines
  vaccinated_with$queue_update(vaccine_type, vaccinated_population)
  ...
}

waning_process <- function(timestep) {
  ...
  # remove vaccine after it's no longer effective
  vaccinated_with$queue_removal(vaccine_type, vaccinated_population)
  ...
}

immunity_process <- function(timestep) {
  ...
  # do something with patients who have been vaccinated with a combination
  az <- vaccinated_with$get_index_of('AstraZeneca')
  pf <- vaccinated_with$get_index_of('Pfizer')
  both <- az$and(pf) # bitset and operator
  ...
}

This kind of behaviour requires bitset. Which is currently WIP. Issue to track

TODO:

slwu89 commented 3 years ago

What kind of data structure do you envision to implement this? I was thinking about this recently too. If there's a lot of individual strata arising in the possible combinations of states, does that mean storing a bitset for each possible combination will lead to many bitsets with almost all bits set to 0?

giovannic commented 3 years ago

I imagine using the same data structure as for CategoricalVariable. All you have to do is not enforce 1 category per individual