mutate: Mutate Selected Individuals in a Population

View source: R/terga1.lib.R

mutateR Documentation

Mutate Selected Individuals in a Population

Description

This function applies mutation to a selected set of individuals in a population by randomly modifying a specified percentage of genes. The mutation changes some genes to new, unique values from the gene pool.

Usage

mutate(clf, pop, selection, seed = NULL)

Arguments

clf

A classifier object containing parameters for mutation, including: - 'current_sparsity': The target sparsity level for each individual. - 'mutate_rate': The mutation rate as a percentage of the total genes in each individual. - 'size_world': The total number of genes available (size of the "world"). - 'parallel.local': Boolean indicating whether parallel processing should be used.

pop

A list representing the population, where each individual is a vector of gene indices.

selection

A vector of indices indicating which individuals in 'pop' should undergo mutation.

seed

Optional integer seed for random number generation to ensure reproducibility.

Details

The function: 1. Calculates the number of genes to mutate based on 'current_sparsity' and 'mutate_rate'. 2. For each selected individual, identifies genes to mutate and replaces them with new, unique genes from the remaining gene pool. 3. Uses parallel processing if specified by 'parallel.local'.

**Mutation Process**: - Genes are randomly selected for mutation from each individual’s current genes. - New genes are randomly chosen from a "reservoir" of available genes not currently in the individual, ensuring they are unique and do not exceed the specified mutation percentage.

Value

A list representing the population after mutation, with selected individuals modified.

Examples

## Not run: 
clf <- list(
  params = list(current_sparsity = 5, mutate_rate = 20, size_world = 10, parallel.local = FALSE)
)
pop <- list(1:5, 2:6, 3:7, 4:8)  # Example population
selection <- c(1, 3)  # Indices of individuals to mutate
mutated_population <- mutate(clf, pop, selection, seed = 42)
print(mutated_population)

## End(Not run)


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