crossing2 | R Documentation |
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.
crossing2(X, y, clf, pop, parents)
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 |
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. |
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.
A combined list of the original parents and their offspring.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.