Genetic Algorithms in Elixir (page 146)

The function for calculating the mean fitness of the tiger population is missing the part were we divide the sum of the fitness of the population by the length of the population.

In other words:

default_stats = [
    min_fitness: &Enum.min_by(&1, fn c -> c.fitness end).fitness,
    max_fitness: &Enum.max_by(&1, fn c -> c.fitness end).fitness,
    mean_fitness: &Enum.sum(Enum.map(&1, fn c -> c.fitness end))
]

Should look like so:

    mean_fitness = fn population ->
      population
      |> Enum.map(fn c -> c.fitness end)
      |> Enum.sum()
      |> Kernel./(length(population))
    end

    default_stats = [
      min_fitness: &Enum.min_by(&1, fn c -> c.fitness end).fitness,
      max_fitness: &Enum.max_by(&1, fn c -> c.fitness end).fitness,
      mean_fitness: mean_fitness
    ]