Genetic Algorithms in Elixir: Chapter 2

I am really enjoying the book (B2) so far.

The version of evolve/4 on page 27 takes genotype as an argument, but it doesn’t seem to need it for anything other than to pass it to itself again recursively. The version on page 28 looks like it was corrected in this regard.

If that isn’t needed, it seems like a slightly prettier way to write run/3 would be:

def run(genotype, fitness_function, max_fitness) do
  genotype
  |> initialize() # maybe call this `initialize_population`
  |> evolve(fitness_function, max_fitness)
end

An even more pedantic suggestion - use verbs for all the function names in the pipeline, i.e., mutate instead of mutation and maybe cross instead of crossover.

2 Likes