patrickdm

patrickdm

Genetic Algorithms in Elixir: Ch4. errata in evolve function (page 59)

At the beginning of page 59, in chapter 4

alter the evolve function to track a generation parameter, like this:

def evolve(problem, generation, opts \\ []) do
  # ...
  if terminate?(population, generation) do
    # ...
  else
    generation = generation + 1
    ...
    |> evolve(population, generation opts)
  end
end

The evolve definition is missing the first param population;
a comma is also missing between the last two params of the evolve call, at the end of the function’s body,

Edit: I guess problem should be in the params of the recursive call to evolve in place of population , and as prefix in the terminate? call.

We have also to include an initial value for generation in run/2’s evolve call, to avoid an>

(ArithmeticError) bad argument in arithmetic expression

due to an uninitialized generation in the + 1 operation. (I’m starting from generation 0)

Corrige:


def run(problem, opts \\ []) do
  population = initialize(&problem.genotype/0, opts)
  first_generation = 0

  population
  |> evolve(problem, first_generation, opts)
end

def evolve(population, problem, generation, opts \\ []) do
  # ...
  if problem.terminate?(population, generation) do
    # ...
  else
    generation = generation + 1
    ...
    |> evolve(problem, generation, opts)
  end
end

(Hope I’m not bothering anyone with this small corrections, I’m really enjoying the book)

Most Liked

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

Thank you for finding all these things :slight_smile:. I’m glad you’re enjoying the book! I’ll go back and fix this one as well.

patrickdm

patrickdm

It is a pleasure to be helpful, I’m just reading the book, studying the concepts and putting the code at work, so the small glitches in the redaction wake up the little debugger-daemon in me… :bug::smiling_imp: They actually help me to focus and understand the overall logic and goals! Also I know how hard is to spot them when you know every and each word of your book by memory. I’m glad to be of some help, while learning so much!

Popular Pragmatic Bookshelf topics Top

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
New
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
swlaschin
The book has the same “Problem space/Solution space” diagram on page 18 as is on page 17. The correct Problem/Solution space diagrams ar...
New
fynn
This is as much a suggestion as a question, as a note for others. Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
New
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New

Other popular topics Top

Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
Author Spotlight Erin Dees @undees Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
New

Sub Categories: