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!

Where Next?

Popular Pragmatic Bookshelf topics Top

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New
mikecargal
Title: Hands-on Rust: question about get_component (page 295) (feel free to respond. “You dug you’re own hole… good luck”) I have somet...
New
gilesdotcodes
In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions: In Gemfile, change gem 'rails' t...
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1023 17214 380
New
AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
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
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New

Sub Categories: