I am working on genetic algorithm project. I need code to find out maxima/minima of Rastrigin function or Easom function (For y=0) using basic genetic algorithm.
Ok, we look at Easom function.
Problem statement
Finding minimum at:
f(x) = -cos(x1)cos(x2)exp(-(x1-phi)^2 - (x2-phi)^2)
Representation choose
For example vector of real numbers. Interval of values for each element is <-5; 5>.
Fitness
Main issue of GA. We have for example two individuals:
Individual1: [-1|2.7|-0.68|3.78||-2.14|1.63|-1.75|-3.8]
Individual2: [1|1|1|1||-0.5|-0.5|-0.5|-0.5]
First individual is decoded as 4.8 and -6.06. His fitness function is -9.23073... × 10^-40.
Second individual is decoded as 4 and -2. His fitness is -4.30104456071396041116767479151655914468678005731098... × 10^-13
And now the issue. Fitness is so low, so we can considerate both as 0. You have two options. Waiting for Godot(maybe at some generation born the divination individual with global minimum value). Or you can use heuristic. Heuristic is based on dividing fitness on two values, major fitness and minor fitness. Major fitness is value of x in function. This value is always 0 so start can't search. Minor fitness is heuristic with purpose give the search a way. You defines some function, for example average of x. So minor fitness for individual1 is -0.63 and individual2 is 1. So individual2 is "better" and he will have higher probability for selection etc.
Minor fitness only give your search a way.
Can be this way wrong? Yes, it's heuristic.
Important, minor function purpose is create preference for individuals with same major function. When major fitness is different, we use major fitness as value for orientation.
Example:
Individual1 fitness: Major: -0.1| Minor: 3
Individual2 fitness: Major: 0| Minor: 8
First one is better because of major fitness.