tag_SelectElite: Select Elite Individuals in a Population

View source: R/terga2.lib.R

tag_SelectEliteR Documentation

Select Elite Individuals in a Population

Description

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.

Usage

tag_SelectElite(clf, pop, nbToSelect)

Arguments

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.

Details

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.

Value

The modified population list with the 'selected' attribute set to TRUE for the top elite individuals.

Examples

## 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)


predomics/predomicspkg documentation built on Dec. 11, 2024, 11:06 a.m.