Customizing Selection in Your Framework

Genetic Algorithms in Elixir — by Sean Moriarity (45 / 101)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Exploring Selection | TOC | Implementing Common Selection Strategies 👉

In Chapter 2, Breaking Down Genetic Algorithms, you briefly learned about hyperparameters and how to pass configuration options to your framework. At the time, the only hyperparameter you could change was population size.

Selection introduces two more hyperparameters: selection strategy and selection rate. In this section, you’ll tweak your framework to allow for changes in both.

Creating a Selection Toolbox

Before you begin, you’ll want a place to store some common selection strategies that you may need to solve some of the problems you encounter. Create a new folder called toolbox. toolbox is your toolbox of genetic operators. You’ll implement modules for selection, crossover, and mutation in the toolbox so you always have them available when you need them.

For now, create selection.ex and add the following module definition:

​ ​defmodule​ Toolbox.Selection ​do​

​ ​# ...strategies here​

​ ​end​

Whenever you implement a new selection strategy, add it to your toolbox so you never have to implement it again.

Changing Selection Strategies

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.