tag_SelectRandom: Randomly Select Individuals in a Population

View source: R/terga2.lib.R

tag_SelectRandomR Documentation

Randomly Select Individuals in a Population

Description

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.

Usage

tag_SelectRandom(clf, pop, nbToSelect)

Arguments

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.

Details

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.

Value

The modified population list with randomly selected individuals marked as 'selected = TRUE'.

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


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