evolve2m: Evolve a Population with Advanced Selection, Crossover, and...

View source: R/terga2.lib.R

evolve2mR Documentation

Evolve a Population with Advanced Selection, Crossover, and Mutation

Description

This function performs one generation of evolution on a population, implementing selection, crossover, and mutation with customizable methods. It returns the evolved population after these operations.

Usage

evolve2m(X, y, clf, pop, featEval, generation)

Arguments

X

A matrix or data frame of feature values, where each row represents a feature and each column represents a sample.

y

A response vector or target variable for supervised learning. The length of y should match the number of columns in X.

clf

A classifier object containing parameters for evolutionary operations, including options for selection percentages, mutation size, population size, parallelization, and debugging.

pop

A list representing the population, where each individual has attributes like 'fit_', 'selected', 'mate', and 'toBeMutated'.

featEval

A vector or list containing feature evaluation metrics, used to guide mutation operations.

generation

An integer representing the current generation number in the evolutionary process.

Details

The 'evolve2m' function implements a detailed evolutionary cycle with the following steps:

1. **Population Sorting**: The population is sorted by fitness, and individuals are evaluated if necessary. 2. **Tagging for Selection**: Individuals are tagged for elite and random selection based on selection percentages in 'clf$params$select_percByMethod'. 3. **Tagging for Mutation**: Some individuals are tagged for mutation based on 'mutate_size'. 4. **Parallel and Sequential Processing**: If parallel processing is enabled ('clf$params$parallel.local'), crossover and mutation are performed in parallel; otherwise, they are processed sequentially. 5. **Mating and Mutation**: Selected individuals are paired for mating, and some are mutated based on the feature evaluation metrics ('featEval'). 6. **Population Pruning and Expansion**: The evolved population is pruned to retain the top 2/3 of individuals by fitness, then expanded by adding new individuals or retaining some from the previous population if necessary.

The population is further cleaned, sorted, and prepared for the next generation. If 'debug' mode is enabled in 'clf', various messages are printed to track the evolution process.

Value

The evolved population list, containing updated individuals with modified 'fit_', 'selected', 'mate', and 'toBeMutated' attributes.

Examples

## Not run: 
X <- matrix(rnorm(100), nrow = 10) # Random features
y <- sample(c(0, 1), 10, replace = TRUE) # Random binary response
clf <- list(params = list(
  select_perc = 50, select_percByMethod = c(30, 20), size_pop = 10,
  mutate_size = 10, cross = TRUE, mutate = TRUE, parallel.local = FALSE, debug = TRUE
))
pop <- list(
  list(fit_ = NA, indices_ = 1:5, selected = FALSE, toBeMutated = FALSE, mate = NULL),
  list(fit_ = NA, indices_ = 6:10, selected = FALSE, toBeMutated = FALSE, mate = NULL)
)
featEval <- runif(10)
evolved_pop <- evolve2m(X, y, clf, pop, featEval, generation = 1)

## End(Not run)


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