Skip to contents

Function to mutate the offspring

Usage

mutation_cpp(offspring, mutation_rate)

Arguments

offspring

Numeric matrix representing the offspring.

mutation_rate

Probability of mutation for each individual.

Value

Numeric matrix representing the mutated offspring.

Examples

# example of usage
genomic_data <- matrix(rnorm(100), nrow = 10, ncol = 10)
population <- BioGA::initialize_population_cpp(genomic_data,
                population_size = 5)
fitness <- BioGA::evaluate_fitness_cpp(genomic_data, population)
selected_parents <- BioGA::selection_cpp(population,
                fitness, num_parents = 2)
offspring <- BioGA::crossover_cpp(selected_parents, offspring_size = 2)
BioGA::mutation_cpp(offspring, mutation_rate = 0)
#>            [,1]      [,2]     [,3]     [,4]       [,5]        [,6]       [,7]
#> [1,] -0.4709225 -0.133251 1.226682 0.332944 -0.3470885 -0.09855069 0.03476606
#> [2,] -0.4709225 -0.133251 1.226682 0.332944 -0.3470885 -0.09855069 0.03476606
#>          [,8]       [,9]       [,10]
#> [1,] 0.386127 0.02083123 0.007586777
#> [2,] 0.386127 0.02083123 0.007586777