crossingIndividual_v3 | R Documentation |
This function generates a new individual by sampling genes from the combined gene pool of two parents, with controlled sparsity based on each parent's sparsity level. It ensures sufficient unique features in the gene pool to meet the child's sparsity requirements.
crossingIndividual_v3(X, y, clf, parent1, parent2)
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 generating a new individual. |
parent1 |
A list representing the first parent, containing attributes 'indices_' (gene indices) and 'eval.sparsity' (sparsity level). |
parent2 |
A list representing the second parent, also containing 'indices_' and 'eval.sparsity'. |
The function starts by creating a combined feature reservoir ('feat_reserv') from the gene indices of both parents. It checks for adequate unique features to satisfy the maximum sparsity of either parent. If either parent lacks enough unique genes to meet its declared sparsity, the function raises an error.
The child’s sparsity level is randomly chosen from the sparsity of one of the parents. If the feature reservoir has duplicates, probabilities are assigned based on feature frequency. The function then samples a subset of genes from the reservoir for the child, ensuring the child’s sparsity matches the chosen level.
A list representing the new individual, with a subset of genes sampled from both parents. If insufficient unique genes are available, the function raises an error.
## Not run:
X <- matrix(rnorm(100), nrow = 10) # Random features
y <- sample(c(0, 1), 10, replace = TRUE) # Random binary response
clf <- list() # Placeholder for classifier settings
parent1 <- list(indices_ = c(1, 3, 5, 7), eval.sparsity = 4)
parent2 <- list(indices_ = c(2, 4, 6, 8), eval.sparsity = 4)
child <- crossingIndividual_v3(X, y, clf, parent1, parent2)
print(child)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.