Skip to contents

Replace non-selected individuals in the population

Usage

replacement_cpp(population, offspring, num_to_replace)

Arguments

population

Numeric matrix representing the population of individuals.

offspring

Numeric matrix representing the offspring.

num_to_replace

Number of individuals to replace.

Value

Numeric matrix representing the updated population.

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)
mutated_offspring <- BioGA::mutation_cpp(offspring, mutation_rate = 0)
BioGA::replacement_cpp(population, mutated_offspring, num_to_replace = 1)
#>           [,1]      [,2]       [,3]     [,4]      [,5]       [,6]       [,7]
#> [1,] -2.645212 -1.032457 -0.7074664 -0.70056 0.5378854 -0.3163322 -0.8396228
#> [2,] -2.645212 -1.032457 -0.7074664 -0.70056 0.5378854 -0.3163322 -0.8396228
#> [3,] -2.645212 -1.032457 -0.7074664 -0.70056 0.5378854 -0.3163322 -0.8396228
#> [4,] -2.645212 -1.032457 -0.7074664 -0.70056 0.5378854 -0.3163322 -0.8396228
#> [5,] -2.645212 -1.032457 -0.7074664 -0.70056 0.5378854 -0.3163322 -0.8396228
#>           [,8]       [,9]   [,10]
#> [1,] -1.354928 -0.8175683 -0.6344
#> [2,] -1.354928 -0.8175683 -0.6344
#> [3,] -1.354928 -0.8175683 -0.6344
#> [4,] -1.354928 -0.8175683 -0.6344
#> [5,] -1.354928 -0.8175683 -0.6344