kristjan.rovsek

kristjan.rovsek

Genetic Algorithms in Elixir: Using reinsertions (source code)

Provided source code has some problems when dealing with the reinsertions.

  1. scripts/schedule.exs example has a default reinsertion strategy set to “elitist”. The problem is, it actually doesn’t and is always running the default “pure” strategy because the naming of the optional parameter has a typo. Changing “reinserton_strategy” to “reinsertion_strategy” does the trick.
  2. If we run the script again, correct strategy is used, but now we get an “ArgumentError” in “Toolbox.Reinsertion.elitist” function when trying to sort data based on fitness.
    The problem actually lies in the “Genetic.evolve” function. In it, “select” function is called which returns “parents” ( composed of pairs of chromosomes, ie: [{p1, p2}, {p3, p4}, …] ) and “leftovers” ( represented as a normal list of chromosomes, ie: [l1, l2, l3, …] ). These two get recombined in the
    “Toolbox.Reinsertion.elitist” function producing a list like [{p1, p2}, {p3, p4}, l5, l6] which is of wrong format.
    A solution then is to de-chunk the “parents” list before sending it to reinsertion function. Something like the following should do the trick:
      parents = parents
        |> Enum.reduce([],
          fn {p1, p2}, acc ->
            [p1, p2 | acc]
          end)
  1. While testing this I also found that the “population_size” parameter is not working. This is because “Genetic.run” does not pass optional parameters to function “Genetic.initialize”. Changing the call to:
population = initialize(&problem.genotype/0, opts)

solves it.

Popular Prag Prog topics Top

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
ianwillie
Hello Brian, I have some problems with running the code in your book. I like the style of the book very much and I have learnt a lot as...
New
yulkin
your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
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
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
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
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

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
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
AstonJ
I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl: The Ser...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
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
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
New

Latest in PragProg

View all threads ❯