Represents a categorical variable for an individual. This class should be used for discrete variables taking values in a finite set, such as infection, health, or behavioral state. It should be used in preference to IntegerVariable if possible because certain operations will be faster.

Methods


Method new()

Create a new CategoricalVariable

Usage

CategoricalVariable$new(categories, initial_values)

Arguments

categories

a character vector of possible values

initial_values

a character vector of the initial value for each individual


Method get_index_of()

return a Bitset for individuals with the given values

Usage

CategoricalVariable$get_index_of(values)

Arguments

values

the values to filter


Method get_size_of()

return the number of individuals with the given values

Usage

CategoricalVariable$get_size_of(values)

Arguments

values

the values to filter


Method get_categories()

return a character vector of possible values. Note that the order of the returned vector may not be the same order that was given when the variable was intitialized, due to the underlying unordered storage type.

Usage

CategoricalVariable$get_categories()


Method queue_update()

queue an update for this variable

Usage

CategoricalVariable$queue_update(value, index)

Arguments

value

the new value

index

the indices of individuals whose value will be updated to the one specified in value. This may be either a vector of integers or a Bitset.


Method queue_extend()

extend the variable with new values

Usage

CategoricalVariable$queue_extend(values)

Arguments

values

to add to the variable


Method queue_shrink()

shrink the variable

Usage

CategoricalVariable$queue_shrink(index)

Arguments

index

a bitset or vector representing the individuals to remove


Method size()

get the size of the variable

Usage

CategoricalVariable$size()


Method .update()

Usage

CategoricalVariable$.update()


Method .resize()

Usage

CategoricalVariable$.resize()


Method save_state()

save the state of the variable

Usage

CategoricalVariable$save_state()


Method restore_state()

restore the variable from a previously saved state.

Usage

CategoricalVariable$restore_state(timestep, state)

Arguments

timestep

the timestep at which simulation is resumed. This parameter's value is ignored, it only exists to conform to a uniform interface with events.

state

the previously saved state, as returned by the save_state method. NULL is passed when restoring from a saved simulation in which this variable did not exist.


Method clone()

The objects of this class are cloneable with this method.

Usage

CategoricalVariable$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.