tvanderpol

tvanderpol

Genetic Algorithms in Elixir: Ch 3 chromosome metadata not maintained (~p 144)

After creating the Chromosome type and updating the one_max script, the size attribute isn’t carried through. I realised that in both crossover() and mutation() the new Chromosome instance isn’t being populated by the relevant parent / existing chromosome. I updated the crossover code to

    {c1, c2} = {
      %Chromosome{p1 | genes: h1 ++ t2},
      %Chromosome{p2 | genes: h2 ++ t1}
    }

and similar for mutation:

      %Chromosome{chromosome | genes: Enum.shuffle(chromosome.genes)}

That sorted it out.

Unrelated I’m pretty sure there were some typos in the area where we updated all the framework code to carry the Problem definition through (initialise’s arguments were missing something, from memory) but I didn’t take notes.

Cheers,
Thomas

Marked As Solved

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

Thanks for pointing this out. I’ll go back through and ensure the metadata is retained correctly throughout implementations. I hope these mistakes aren’t detracting from your experience with the book! I appreciate the help in making the book better for everybody.

Also Liked

patrickdm

patrickdm

I’ve also stumped upon the missing size when I tried to use it in crossover/2 as p1.size instead of recalculating length(p1.genes) at each iteration. I took a while to figure out it was not retained after initializing the chromosome’s population.

About the chromosome update you mention, we can discuss if you really want the age to increase after a crossover (when you get a kind of new chromosome) or if we should consider a new generation only after a mutation. But I think this are not so relevant aspects in respect of the main code’s objective.

Similar consideration goes for the silly optimization I made in evaluate/3, when I opted to use the precalculated fitness for the last sorting step:

...
|> Enum.sort_by(& &1.fitness, &>=/2)
tvanderpol

tvanderpol

To be honest my Elixir is pretty rusty so having to do a bit of debugging and making sure the code is doing what I think it’s doing is added value for me right now. :smiley:

Popular Prag Prog topics Top

jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=> (create-...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
New
nicoatridge
Hi, I have just acquired Michael Fazio’s “Kotlin and Android Development” to learn about game programming for Android. I have a game in p...
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New
brunogirin
When trying to run tox in parallel as explained on page 151, I got the following error: tox: error: argument -p/–parallel: expected one...
New
s2k
Hi all, currently I wonder how the Tailwind colours work (or don’t work). For example, in app/views/layouts/application.html.erb I have...
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
dachristenson
I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New

Other popular topics Top

PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
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
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New
PragmaticBookshelf
Author Spotlight: Bruce Tate @redrapids Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New

Latest in PragProg

View all threads ❯