...

/

Understanding the Flow of Genetic Algorithms

Understanding the Flow of Genetic Algorithms

Explore the initial structure of our genetic algorithm for the One-Max problem.

Recursive nature of genetic algorithms

We’re now ready to start writing our algorithm. But, before we begin, let us take a look at the following question:

1.

What do you notice about the structure of the genetic algorithm described in the previous lesson? Specifically, what happens after children are mutated?

Show Answer
Q1 / Q1
Did you find this helpful?

Having that knowledge in mind, we would add the following code snippet in our genetic algorithm below the initial population that we defined in the previous lesson:

Press + to interact
algorithm =
fn population, algorithm ->
# Algorithm here
end

The algorithm is an anonymous function that takes two parameters: population, which represents the current generation’s population, and the algorithm parameter, which is a reference to itself. This is a trick used to implement an anonymous recursive function. It’s not essential to understand why this works or why this is necessary. The most important information to know is that the algorithm is a reference to the algorithm function.

In other languages, ...