# Genetic Algorithms in Elixir: Chapter 2

**URL:** <https://forum.devtalk.com/t/genetic-algorithms-in-elixir-chapter-2/3495>\
**Category:** PragProg Customers\
**Tags:** book-genetic-algorithms-in-elixir, errata\
**Created:** [27 October 2020 21:09 UTC](https://forum.devtalk.com/t/genetic-algorithms-in-elixir-chapter-2/3495 "2020-10-27T21:09:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chriseyre2000](https://forum.devtalk.com/user_avatar/forum.devtalk.com/chriseyre2000/32/1164_2.png) [@chriseyre2000](https://forum.devtalk.com/u/chriseyre2000)\
**Post date:** [27 October 2020 21:09 UTC](https://forum.devtalk.com/t/genetic-algorithms-in-elixir-chapter-2/3495/1 "2020-10-27T21:09:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![seanmor5](https://forum.devtalk.com/user_avatar/forum.devtalk.com/seanmor5/32/1169_2.png) [@seanmor5](https://forum.devtalk.com/u/seanmor5)\
**Post date:** [28 October 2020 12:00 UTC](https://forum.devtalk.com/t/genetic-algorithms-in-elixir-chapter-2/3495/2 "2020-10-28T12:00:58Z")

</div>

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:

```elixir
def initialize(opts \\ []) do
   # ...omitted...
end

```

It should say:

```elixir
def initialize(genotype, opts \\ []) do
   # ...omitted...
end

```

Thank you for the feedback 🙂 !

---

<div class="post-metadata">

**Author:** ![panchopico](https://forum.devtalk.com/user_avatar/forum.devtalk.com/panchopico/32/5147_2.png) [@panchopico](https://forum.devtalk.com/u/panchopico)\
**Post date:** [17 November 2020 01:03 UTC](https://forum.devtalk.com/t/genetic-algorithms-in-elixir-chapter-2/3495/3 "2020-11-17T01:03:01Z")

</div>

Good suggestions, but I don’t agree that an underscore is better than “…” as a placeholder. The underscore is used frequently in Elixir code, so it doesn’t stand out as something needed to be replace is “…” does to me.

---

<div class="post-metadata">

**Author:** ![srowley](https://forum.devtalk.com/user_avatar/forum.devtalk.com/srowley/32/652_2.png) [@srowley](https://forum.devtalk.com/u/srowley)\
**Post date:** [29 November 2020 14:47 UTC](https://forum.devtalk.com/t/genetic-algorithms-in-elixir-chapter-2/3495/4 "2020-11-29T14:47:19Z")

</div>

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:

```auto
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`.
