dict_selectors_maybe {miesmuschel} | R Documentation |
Selector-Combination that Selects According to Two Selectors
Description
Selector
that wraps two other Selector
s given during construction and uses both for selection proportionally.
Each of the resulting n_select
individuals is chosen either from $selector
, or from $selector_not
.
This makes it possible to implement selection methods such as random interleaving, where only a fraction of p
individuals were selected by a criterion, while the others are taken randomly.
Algorithm
To perform selection, n_selector_in
rows of values
are given to $selector
, and the remaining
nrow(values) - n_selector_in
rows are given to $selector_not
. Both selectors are used to generate
a subset of selected individuals: $selector
generates n_selector_out
individuals, and $selector_not
generates
n_select - n_selector_out
individuals.
n_selector_in
is either set to
round(nrow(values) * p_in)
when proportion_in
is "exact"
, or to rbinom(1, nrow(values), p_in)
when proportion_in
is "random"
.
n_selector_out
is set to round(n_select * p_out)
when proportion_out
is "exact"
, or to rbinom(1, n_select, p_out)
when proportion_out
is "random"
.
When odds_correction
is TRUE
, then p_out
is adjusted depending on the used n_selector_in
value before being applied. Let odds(p) = p/(1-p)
.
Then the effective p_out
is set such that odds(effective p_out) = odds(p_out) * n_selector_in / (nrow(values) - n_selector_in) / odds(p_in)
.
This corrects for the discrepancy between the chosen p_in
and the effective proportion of n_selector_in / nrow(values)
caused either by rounding
errors or when proportion_in
is "random"
.
When p_in
is exactly 1 or exactly 0, and p_out
is not equal to p_in
, then an error is given.
If nrow(values)
is 1, then this individuum is returned and $selector
/ $selector_not
are not called.
If try_unique
is TRUE
, then n_selector_out
is set to at most n_selector_in
and at least n_select - nrow(values) + n_selector_in
,
and an error is generated when nrow(values)
is less than n_select
.
If try_unique
is FALSE
and odds_correction
is TRUE
and n_selector_in
is either 0 or nrow(values)
, then $p_out
is set to either 0 or 1, respectively.
If try_unique
is FALSE
and odds_correction
is FALSE
and n_selector_in
is either 0 or nrow(values)
, and n_selector_out
is not equal
to 0 or n_select
, respectively, then
n_selector_in
is increased / decreased by 1 to give $selector_not
/ $selector
at least one individuum to choose from. While this behaviour
may seem pathological, it is to ensure continuity with sampled values of n_selector_in
that are close to 0 or n_select
.
If n_selector_out
is n_select
or 0, or if n_selector_in
is nrows(values) - 1
or 1,
then only $selector
/ $selector_not
is executed, respectively; possibly with a subset
of values
if n_selector_in
differs from nrow(values)
/ 0.
Configuration Parameters
This operator has the configuration parameters of the Selector
s that it wraps: The configuration parameters of the operator given to the selector
construction argument
are prefixed with "maybe."
, the configuration parameters of the operator given to the selector_not
construction argument are prefixed with "maybe_not."
.
Additional configuration parameters:
-
p_in
::numeric(1)
Probability per individual (whenrandom_choise
isTRUE
), or fraction of individuals (whenrandom_choice
isFALSE
), that are given to$selector
instead of$selector_not
. This may be overriden whentry_unique
isTRUE
, in which case at least as many rows are given to$selector
and$selector_not
as they are generating output values respectively. When this is exactly 1 or exactly 0, thenp_out
must be equal top_in
. Must be set by the user. -
p_out
::numeric(1)
Probability per output value (whenrandom_choise
isTRUE
), or fraction of output values (whenrandom_choice
isFALSE
), that are generated by$selector
instead of$selector_not
. When this values is not given, it defaults top_in
. -
shuffle_input
::logical(1)
Whether to distribute input values randomly to$selector
/$selector_not
. IfFALSE
, then the first part ofvalues
is given to$selector
. This only randomizes which lines ofvalues
are given to$selector
/$selector_not
, but it does not necessarily reorder the lines of values given to each. In particular, ifp_out
is 0 or 1, then no shuffling takes place. Initialized toTRUE
. -
proportion_in
::character(1)
When set to"random"
, sample the number of individuals given to$selector
according torbinom(1, nrow(values), p_in)
. When set to"exact"
, give$selector
round(nrow(values) * p_in)
individuals. Initialized to"exact"
. -
proportion_out
::character(1)
When set to"random"
, sample the number of individuals generated by$selector
according torbinom(1, n_select, p_out)
. When set to"exact"
, have$selector
generateround(n_select * p_out)
individuals. -
odds_correction
::logical(1)
When set, the effectively used value ofp_out
is set to1 / (1 + ((nrow(values) - n_selector_in) * p_in * (1 - p_out)) / (n_selector_in * p_out * (1 - p_in)))
, see the Algorithm section. Initialized toFALSE
. -
try_unique
::logical(1)
Whether to give at least as many rows ofvalues
to each of$selector
and$selector_not
as they are generating output values. This should be set toTRUE
wheneverSelectorMaybe
is used to select unique values, and can be set toFALSE
when selecting values multiple times is acceptable. When this isTRUE
, then havingn_select > nrow(values)
generates an error. Initialized toTRUE
.
Supported Operand Types
Supported Domain
classes are the set intersection of supported classes of selector
and selector_not
.
Dictionary
This Filtor
can be created with the short access form ftr()
(ftrs()
to get a list), or through the the dictionary
dict_filtors
in the following way:
# preferred: ftr("maybe", <selector> [, <selector_not>]) ftrs("maybe", <selector> [, <selector_not>]) # takes vector IDs, returns list of Filtors # long form: dict_filtors$get("maybe", <selector> [, <selector_not>])
Super classes
miesmuschel::MiesOperator
-> miesmuschel::Selector
-> SelectorMaybe
Active bindings
selector
(
Selector
)
Selector
being wrapped. This operator gets run with probability / proportionp_in
and generates output with probability / proportionp_out
(configuration parameters).selector_not
(
Selector
)
AlternativeSelector
being wrapped. This operator gets run with probability / proportion1 - p_in
and generates output with probability / proportion1 - p_out
(configuration parameters).
Methods
Public methods
Inherited methods
Method new()
Initialize the SelectorMaybe
object.
Usage
SelectorMaybe$new(selector, selector_not = SelectorRandom$new())
Arguments
selector
(
Selector
)
Selector
to wrap. This operator gets run with probability / fractionp_in
(Configuration parameter).
The constructed object gets a clone of this argument. The$selector
field will reflect this value.selector_not
(
Selector
)
AnotherSelector
to wrap. This operator runs whenselector
is not chosen. By default, this isSelectorRandom
, i.e. selecting randomly.
The constructed object gets a clone of this argument. The$selector_not
field will reflect this value.
Method prime()
See MiesOperator
method. Primes both this operator, as well as the wrapped operators
given to selector
and selector_not
during construction.
Usage
SelectorMaybe$prime(param_set)
Arguments
param_set
(
ParamSet
)
Passed toMiesOperator
$prime()
.
Returns
invisible self
.
Method clone()
The objects of this class are cloneable with this method.
Usage
SelectorMaybe$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other selectors:
Selector
,
SelectorScalar
,
dict_selectors_best
,
dict_selectors_null
,
dict_selectors_proxy
,
dict_selectors_random
,
dict_selectors_sequential
,
dict_selectors_tournament
Other selector wrappers:
dict_selectors_proxy
,
dict_selectors_sequential