tag_SelectElite | R Documentation |
This function selects a specified number of elite individuals from a population by marking them as selected. The population is sorted by fitness, and the top individuals are tagged based on the 'nbToSelect' parameter.
tag_SelectElite(clf, pop, nbToSelect)
clf |
A classifier object that may contain parameters for selection (though it is not directly used in this function). |
pop |
A list representing the population, where each individual is an element with a 'selected' attribute and a 'fit_' fitness attribute. |
nbToSelect |
An integer specifying the number of individuals to mark as elite in the population. |
The function sorts the population by the 'fit_' attribute
(presumably representing fitness) in descending order. It then iterates
through the sorted list, marking the top 'nbToSelect' individuals as
'selected' by setting their 'selected' attribute to 'TRUE'. If the population
is empty, a warning is issued and the function returns NULL
.
The modified population list with the 'selected' attribute set to
TRUE
for the top elite individuals.
## Not run:
pop <- list(
list(fit_ = 0.9, selected = FALSE),
list(fit_ = 0.8, selected = FALSE),
list(fit_ = 0.7, selected = FALSE)
)
clf <- list() # Placeholder for classifier object
pop <- tag_SelectElite(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.