eekenpiet

eekenpiet

Genetic Algorithms in Elixir: Chapter5 pag82 ebook-1.0.2 Hanging of "tournament_no-duplicates"

The function tournament_no_duplicates keeps hanging, because it will never reach n winners.
In a selection of n chromosomes you can never have n winners.
Maybe you will ever reach n-(tournsize-1) winners.
So I propose a different function.

def tournament_no_duplicates(problem, population, n, tournsize) do
  set =
    tournament(problem, population, n, tournsize)
    |> MapSet.new()
    |> MapSet.to_list()
# you get an error in crossover if this selection is not even.
# therefore I delete the weakest of the list
  if rem(length(set), 2) == 0 do
    set
  else
    Enum.sort_by(set, &problem.fitness_function(&1), :desc)
    List.delete_at(set, -1)
  end
end

Your selection could go to [ ],
therefore the population must be much bigger then the number of generations you run.
Yet you can reach good results.

I added this to the first part of evolve() in Genetic:

if population == [] do
  IO.write("\n\nYou should make your population bigger\n\n")
  raise "Watch it! Population is empty"
end

best = hd(population)
IO.inspect(best, label: "\n\nCurrent best:")
IO.write("Generation: #{generation}")

Where Next?

Popular Pragmatic Bookshelf topics Top

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
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! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
New
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
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
New
ggerico
I got this error when executing the plot files on macOS Ventura 13.0.1 with Python 3.10.8 and matplotlib 3.6.1: programming_ML/code/03_...
New
gorkaio
root_layout: {PentoWeb.LayoutView, :root}, This results in the following following error: no “root” html template defined for PentoWeb...
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
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
New
AstonJ
Or looking forward to? :nerd_face:
498 13326 269
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
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
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New

Sub Categories: