tag_SelectRandom | R Documentation |
This function randomly selects a specified number of unselected individuals from a population and marks them as selected. The function can operate in parallel if specified in the classifier parameters.
tag_SelectRandom(clf, pop, nbToSelect)
clf |
A classifier object that contains parameters for selection, including 'params$warnings' (to control warnings) and 'params$parallel.local' (for parallel execution). |
pop |
A list representing the population, where each individual has a 'selected' attribute. |
nbToSelect |
An integer specifying the number of individuals to randomly select and mark as selected. |
The function identifies individuals in the population who have not been selected (i.e., their 'selected' attribute is 'FALSE'). It then randomly selects up to 'nbToSelect' of these unselected individuals and sets their 'selected' attribute to 'TRUE'. If fewer than 'nbToSelect' unselected individuals are available, it selects all unselected individuals.
If parallel processing is enabled ('clf$params$parallel.local' is 'TRUE'),
selection is performed in parallel using 'foreach' and 'doRNG'. If the
population is empty, the function issues a warning (if 'clf$params$warnings'
is 'TRUE') and returns NULL
.
The modified population list with randomly selected individuals marked as 'selected = TRUE'.
## Not run:
pop <- list(
list(fit_ = 0.9, selected = FALSE),
list(fit_ = 0.8, selected = FALSE),
list(fit_ = 0.7, selected = FALSE)
)
clf <- list(params = list(warnings = TRUE, parallel.local = FALSE))
pop <- tag_SelectRandom(clf, pop, nbToSelect = 2)
# Check which individuals are selected
sapply(pop, function(ind) ind$selected)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.