initSelector: Initialize Selector

View source: R/utils.R

initSelectorR Documentation

Initialize Selector

Description

Sample the vector.name variable such that the number of ones has a given distribution.

Usage

initSelector(
  individuals,
  vector.name = "selector.selection",
  distribution = function() floor(runif(1, 0, length(individuals[[1]][[vector.name]]) +
    1)),
  soften.op = NULL,
  soften.op.strategy = NULL,
  soften.op.repeat = 1,
  reject.condition = function(x) !any(x)
)

Arguments

individuals

[list of named lists] the individuals to initialize.

vector.name

[character(1)] the variable name, whose entries are sampled.

distribution

[function] function that returns a random integer from 0 to the length of each individual's vector.name slot. Defaults to the uniform distribution from 1 to length().

soften.op

[ecr_mutator] an optional mutator to apply to the vector.name variable.

soften.op.strategy

function an optional function that can set the soften.op's parameters. See combine.operators strategy parameters. Ignored if soften.op is not given.

soften.op.repeat

[integer(1)] how often to repeat soften.op application. Ignored if soften.op is not given.

reject.condition

[function | NULL] reject condition as a function applied to newly generated values of vector.name. If set to NULL, no rejection is done.

Value

list of named lists the individuals with initialized [[vector.name]].

Examples

library(mlrCPO)

# Initialize parameter set and sample candidates
ps <- pSS(
 maxdepth: integer[1, 30],
 minsplit: integer[2, 30],
 cp: numeric[0.001, 0.999], 
 selector.selection: logical^5)

initials <- sampleValues(ps, 15, discrete.names = TRUE)

# Resample logical vector selector.selection of initials 
# with binomial distribution 
initSelector(initials, distribution = function() rbinom(n = 5, size = 5, 
 prob = 0.5))


mosmafs documentation built on Nov. 3, 2022, 1:05 a.m.