population: Population class

populationR Documentation

Population class

Description

The 'population' R6 class regroups different individuals profiles. It serves as a wrapper for simultaneous interactions with multiple individual profiiles. The object is used for population description and generation procedures.

Public fields

profiles

A list of individual profile.

n

A list of individuals' numbers per profile (repecting the profiles' order).

Methods

Public methods


Method new()

Create a new 'population' object. The function allows to create an object populated with individual profiles.

Usage
population$new(profiles = list(NULL), n = list(NULL))
Arguments
profiles

A list of individual profiles for population.

n

The associated numbers for each profile to appear in the dataset.


Method add_profile()

Add new individual profile and respective desired number of individuals.

Usage
population$add_profile(individual, n, profile_name = NULL)
Arguments
individual

Individual profile to be added

n

A number associate to the added profile

profile_name

An added profile name, not required. Is NULL by default.


Method get_chars()

Get a vector of available characteristics' names across all individual profiles in population.

Usage
population$get_chars()
Returns

Character vector with unique characteristics names within populatoin.


Method get_n()

Get a vector regroupping individuals' numbers per profile

Usage
population$get_n()
Returns

Numeric vector with numbers of n by individual profile.


Method get_rules()

Extract 'decision_rule' objects across individual profiles

Usage
population$get_rules()
Returns

A list of rules present within population.


Method clone()

The objects of this class are cloneable with this method.

Usage
population$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

# Create individuals
ind1 <- individual$new()
ind1$add_characteristics(Age = rnorm(mean = 40, sd = 10))
ind1$add_decision_rule(drule <- decision_rule$new())
ind2 <- individual$new()
ind2$add_characteristics(Age = rnorm(mean = 30, sd = 5))
ind2$add_decision_rule(drule <- decision_rule$new())

# Regroup individuals into population
pop <- population$new(profiles = list(ind1, ind2), n = list(10, 15))

# Add new profile
ind3 <- individual$new()
ind3$add_characteristics(Age = rnorm(mean = 50, sd = 4), Salary = runif(min = 1, max = 5))
ind3$add_decision_rule(drule <- decision_rule$new())
pop$add_profile(ind3, 5)
pop$get_chars()
pop$get_n()
pop$get_rules()

nikitagusarov/dcesimulatr documentation built on Jan. 7, 2023, 4:27 p.m.