crossing2: Generate Offspring by Pairing Parents in a Population

View source: R/terga2.lib.R

crossing2R Documentation

Generate Offspring by Pairing Parents in a Population

Description

This function generates a new set of offspring by pairing parents from a population. It randomly selects pairs of parents to create offspring through a specified crossover function. The result is a combined list of the original parents and their offspring.

Usage

crossing2(X, y, clf, pop, parents)

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 crossover, including 'parallel.local' (to enable parallel computation) and a 'crosser' function.

pop

A list representing the current population, where each individual can be selected for pairing.

parents

A list of selected parents (indices or individuals) from the population to be used for pairing and offspring generation.

Details

The function creates pairs of parents from 'parents' and uses the 'crosser' function defined in 'clf$functions' to generate offspring for each pair. If there aren’t enough unique parents, it reuses the full list to ensure the required number of couples. Offspring generation can be parallelized if 'clf$params$parallel.local' is set to 'TRUE'.

The process includes: - **Pairing**: Randomly pairs parents from 'parents'. - **Offspring Generation**: Calls the 'crosser' function to create offspring for each pair. - **Parallelization**: Uses parallel computation if enabled, otherwise processes sequentially.

Value

A combined list of the original parents and their offspring.

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(parallel.local = FALSE),
            functions = list(crosser = crossingIndividual_v3)) # Assume `crossingIndividual_v3` is defined
pop <- list(
  list(indices_ = c(1, 3, 5), fit_ = 0.8),
  list(indices_ = c(2, 4, 6), fit_ = 0.7)
)
parents <- 1:2
combined_population <- crossing2(X, y, clf, pop, parents)
print(combined_population)

## End(Not run)


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