joustava

joustava

Genetic Algorithms in Elixir: Genetic.crossover function, continuity in changes lost (page 93)

@seanmor5

On page 43, changes were made to the Genetic.crossover function to support a new shiny Chromosome struct.

On page 93, the code does not have these changes anymore, but the code should probably be in the same state as page 43 at this point.

0 898 1

Marked As Solved

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

You are correct, the code should show:

def crossover(population, opts \\ []) do
  population
  |> Enum.reduce([],
      fn {p1, p2}, acc ->
        cx_point = :rand.uniform(length(p1.genes))
        {{h1, t1}, {h2, t2}} =
          {Enum.split(p1.genes, cx_point),
            Enum.split(p2.genes, cx_point)}
        {c1, c2} =
          {%Chromosome{p1 | genes: h1 ++ t2},
            %Chromosome{p2 | genes: h2 ++ t1}}
        [c1, c2 | acc]
      end
    )
end

I’ll mark this change for the next version as well! Thank you so much!

Where Next?

Popular Pragmatic Bookshelf topics Top

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...
15 1543 13
New
HarryDeveloper
Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
0 2222 2
New
jeremyhuiskamp
Title: Web Development with Clojure, Third Edition, vB17.0 (p9) The create table guestbook syntax suggested doesn’t seem to be accepted ...
0 1835 1
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...
0 7996 6
New
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...
2 1378 4
New
NaplesDave
I am using Android Studio Chipmunk | 2021.2.1 Patch 2 Build #AI-212.5712.43.2112.8815526, built on July 10, 2022 Runtime version: 11.0....
0 1403 2
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
0 894 0
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...
0 2059 6
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 ...
1 974 3
New

Other popular topics Top

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...
51 4319 20
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...
49 5284 39
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
14 7927 8
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
116 8174 31
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...
166 7775 69
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 ...
37 2727 14
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...
4 4891 0
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 ...
1 3243 0
New
Fl4m3Ph03n1x
Background Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
6 2202 3
New

Sub Categories: