Theory Practical Artificial Intelligence Programming With Java
Figure 6.1: The test function evaluated over the interval [0.0, 10.0]. The maximum value of 0.56 occurs at x=3.8
tion, and Machine Learning , David Goldberg, 1989.
• Provide a numeric fitness function that allows us to rate the fitness of each chromosome in a population. We will use these fitness values to determine
which chromosomes in the population are most likely to survive and repro- duce using genetic crossover and mutation operations.
The GA toolkit developed in this chapter treats genes as a single bit; while you can consider a gene to be an arbitrary data structure, the approach of using single
bit genes and specifying the number of genes or bits in a chromosome is very flexible. A population is a set of chromosomes. A generation is defined as one
reproductive cycle of replacing some elements of the chromosome population with new chromosomes produced by using a genetic crossover operation followed by
optionally mutating a few chromosomes in the population.
We will describe a simple example problem in this section, write a general purpose library in Section 6.2, and finish the chapter in Section 6.3 by solving the problem
posed in this section.
For a sample problem, suppose that we want to find the maximum value of the function F with one independent variable x in Equation 6.1 and as seen in Figure
6.1:
F x = sinx ∗ sin0.4 ∗ x ∗ sin3 ∗ x
6.1 The problem that we want to solve is finding a good value of x to find a near to
possible maximum value of F x. To be clear: we encode a floating point number
100
Figure 6.2: Crossover operation as a chromosome made up of a specific number of bits so any chromosome with
randomly set bits will represent some random number in the interval [0, 10]. The fitness function is simply the function in Equation 6.1.
Figure 6.2 shows an example of a crossover operation. A random chromosome bit index is chosen, and two chromosomes are “cut” at this this index and swap cut
parts. The two original chromosomes in generation
n
are shown on the left of the figure and after the crossover operation they produce two new chromosomes in
generation
n+1
shown on the right of the figure. In addition to using crossover operations to create new chromosomes from existing
chromosomes, we will also use genetic mutation: randomly flipping bits in chromo- somes. A fitness function that rates the fitness value of each chromosome allows
us to decide which chromosomes to discard and which to use for the next genera- tion: we will use the most fit chromosomes in the population for producing the next
generation using crossover and mutation.
We will implement a general purpose Java GA library in the next section and then solve the example problem posed in this section in Section 6.3.