Discrete components are mutated by sampling from a uniform distribution, either from all possible values of each component, or from all values except the original value.
Since the information loss is very high, this should in most cases be combined with MutatorCmpMaybe
.
can_mutate_to_same
:: logical(1)
Whether to sample from entire range of each parameter (TRUE
) or from all values except the
current value (FALSE
). Initialized to TRUE
.
This Mutator
can be created with the short access form mut()
(muts()
to get a list), or through the the dictionary
dict_mutators
in the following way:
miesmuschel::MiesOperator
-> miesmuschel::Mutator
-> miesmuschel::MutatorDiscrete
-> MutatorDiscreteUniform
set.seed(1)
mdu = mut("unif")
p = ps(x = p_lgl(), y = p_fct(c("a", "b", "c")))
data = data.frame(x = rep(TRUE, 5), y = rep("a", 5),
stringsAsFactors = FALSE) # necessary for R <= 3.6
mdu$prime(p)
mdu$operate(data)
#> x y
#> 1 TRUE c
#> 2 TRUE b
#> 3 TRUE c
#> 4 TRUE b
#> 5 FALSE c
mdu$param_set$values$can_mutate_to_same = FALSE
mdu$operate(data)
#> x y
#> 1 FALSE b
#> 2 FALSE b
#> 3 FALSE c
#> 4 FALSE c
#> 5 FALSE b