
chriseyre2000
Genetic Algorithms in Elixir: Chapter 2
Now working through chapter 2.
An underscore makes a better placeholder than …
Intialize is added above the two rum functions. We only have one so far…
The first evolve does not need opts.
Most of the new functions should start as defp
run does not need the population variable.
By Hyperparameters initialize already takes genotype so opts is an additional Param.
Most Liked

seanmor5
I’ll adjust the placeholder. As far as the reference to two run functions, I initially named run
and evolve
the same thing, I must have missed that reference. Most of the stuff in regards to passing hyperparameters via opts
is necessary for playing with some configurations later on. For example, opts
is used to specify :population_size
in initialize
. I believe there’s a mistake in the transcription of the signature of initialize
where it says:
def initialize(opts \\ []) do
# ...omitted...
end
It should say:
def initialize(genotype, opts \\ []) do
# ...omitted...
end
Thank you for the feedback !

srowley
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
.
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /haskell
- /java
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /centos
- /ash
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /slackware
- /julia
- /c
- /neovim