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 Pragmatic Bookshelf topics Top

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: question about get_component (page 295) (feel free to respond. “You dug you’re own hole… good luck”) I have somet...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
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
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

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
AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
AstonJ
Or looking forward to? :nerd_face:
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
PragmaticBookshelf
Author Spotlight Mike Riley @mriley This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
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: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
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

Sub Categories: