You are on page 1of 2

What Are Genetic Algorithms

Over the past few years, there has been a terrific buzz around Artificial Intelligence (AI). Major companies
like Google, Apple, and Microsoft are actively working on the topic. In fact, AI is an umbrella that covers
lots of goals, approaches, tools, and applications. Genetic Algorithms (GA) is just one of the tools for
intelligent searching through many possible solutions.

GA is a metaheuristic search and optimization technique based on principles present in natural evolution.
It belongs to a larger class of evolutionary algorithms.

GA maintains a population of chromosomes—a set of potential solutions for the problem. The idea is that
“evolution” will find an optimal solution for the problem after a number of successive generations—similar
to natural selection.

GA mimics three evolutionary processes: selection, gene crossover, and mutation.

Similar to natural selection, the central concept of GA selection is fitness. The chromosomes that are
more fit have a better chance for survival. Fitness is a function that measures the quality of the solution
represented by the chromosome. In essence, each chromosome within the population represents the
input parameters. For example, if your problem contains two input parameters, such as price and volume
in trading, each chromosome will logically consist of two elements. How the elements are encoded within
the chromosome is a different topic.

During the selection, chromosomes form pairs of parents for breeding. Each child takes characteristics
from its parents. Basically, the child represents a recombination of characteristics from its parents: Some
of the characteristics are taken from one parent and some from another. In addition to the recombination,
some of the characteristics can mutate.

Because fitter chromosomes produce more children, each subsequent generation will have better fitness.
At some point, a generation will contain a chromosome that will represent a good enough solution for our
problem.

GA is powerful and broadly applicable for complex problems. There is a large class of optimization
problems that are quite hard to solve by conventional optimization techniques. Genetic algorithms are
efficient algorithms whose solution is approximately optimal. The well-known applications include
scheduling, transportation, routing, group technologies, layout design, neural network training, and many
others.

Putting Things into Practice


The example we’ll look at can be considered the “Hello World” of GA. This example was initially given by
J. Freeman in Simulating Neural Networks with Mathematica. I took it from Genetic Algorithms and
Engineering Design by Mitsuo Gen and Runwei Cheng.

The Word-Matching Problem tries to evolve an expression with a genetic algorithm. Initially, the algorithm
is supposed to “guess” the “to be or not to be” phrase from randomly-generated lists of letters.

“Since there are 26 possible letters for each of 13 locations [excluding whitespace] in the list, the
probability that we get the correct phrase in a pure random way is (1/26)^13=4.03038×10-19, which is
about two chances out of a [quintillion]” (Gen & Chong, 1997).
We’ll define the problem a bit more widely here, making the solution even more difficult. Let’s assume that
we are not limited to English language or a specific phrase. We can end up dealing with any alphabet, or
even any set of symbols. We have no knowledge of the language. We don’t even know if there is any
language at all.

Let’s say our opponent thought of an arbitrary phrase, including whitespace. We know the length of the
phrase and the count of symbols in the alphabet. That is the only knowledge we have. After each guess,
our opponent tells us how many letters are in place.

Each chromosome is a sequence of indices of the symbols in the alphabet. If we are talking about the
English alphabet, then ‘a’ will be represented by 0, ‘b’ by 1, ‘c’ by 2, and so on. So, for example, the word
“be” will be represented as [4, 1].

We will demonstrate all steps through Java code snippets, but knowledge of Java is not required to
understand each step.

You might also like