Skip to contents

One generation is selection, crossover and mutation. The randomness is supplied by the van der Corput low-discrepancy sequence rather than a pseudo-random generator, so the run is exactly reproducible and both language arms visit the same individuals. Elitism makes the best fitness monotone, which the tests assert.

Usage

Ga_opt(f, population, generations = 20, mutation = 0.1)

Arguments

f

Fitness function to minimise, of a numeric vector.

population

Matrix of candidate vectors, one per row.

generations

Number of generations.

mutation

Mutation amplitude.

Value

List with estimate, best, best_fitness, best_path, generations, n, method.

Details

Formula: keep the best ceiling(m/2); each child takes a prefix from one parent and a suffix from another; a mutation is then added.

References

Holland (1975), Adaptation in Natural and Artificial Systems, University of Michigan Press.

Examples

set.seed(1)
Ga_opt(function(x) -sum(x^2), population = matrix(rnorm(20), 10, 2),
       generations = 10)
#> $estimate
#> [1] -12.10609
#> 
#> $best
#> [1]  2.112468 -2.764700
#> 
#> $best_fitness
#> [1] -12.10609
#> 
#> $best_path
#>  [1]  -7.449816  -7.449816  -8.106073  -8.402561  -8.979771  -9.356983
#>  [7]  -9.776015 -10.338083 -10.925826 -11.329436 -12.106088
#> 
#> $generations
#> [1] 10
#> 
#> $n
#> [1] 10
#> 
#> $method
#> [1] "elitist truncation selection, one-point crossover, van der Corput mutation; Holland (1975)"
#> 
#> attr(,"class")
#> [1] "morie_rich_result" "list"