Initializing the Population

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

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Introducing the One-Max Problem | TOC | Understanding the Flow of Genetic Algorithms 👉

You need to start by initializing a population. Remember, the problem wants the maximum sum of bitstrings of length N. So your population will consist of some number of N-length bitstrings. For this example, N is 1000, so you need a population of 1000-length bitstrings.

The number of chromosomes in your population is irrelevant. A larger population means you’re currently looking at a larger area of the search space. Typically, the more chromosomes you have, the longer it takes to perform transformations on the entire population. Conversely, the fewer chromosomes you have, the longer it takes to produce a viable solution to your problem and the more susceptible your population is to premature convergence. For this example problem, a population size of 100 strikes a nice balance between the two.

Understanding Population Size

INFORMATION

In a traditional search method like depth-first search or breadth-first search, you examine one solution at a time and determine where to go next. Even in other informed search algorithms like A* or uniform-cost search, you examine one solution at a time. Genetic algorithms examine many solutions at once, ruling out large areas of the search space after every generation. The population size…

--

--

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.