I'm programming a genetic algorithm using grammatical evolution. My problem is that I reach local optimal values (premature convergence) and when that happens, I don't know what to do. I'm thinking about increasing the mutation ratio (5% is it's default value), but I don't know how to decide when it is necessary.
The data I have on every generation is a bidimensional array whose first column is its fitness
adn[i][0] ← fitness
row → is the values of the Grammar
column ↓ Each indiviual result
If you need clarification, please ask and I'll be pleased of modifying. Note that this is not my mother language and sorry for the mistakes and for the inconvenience.
Answering a request, my operations are the following, and exactly in this order:
- I generate a random Population (A matrix with random numbers)
- I generate a matrix that contains the desired result. For doing this, i have implemented a couple functions that have aditionally a +-5% of variation, for example: fun(x)= (2*cos(x) + sen(x) - 2X) * (0,95+(a number oscillating between 0 and 0,1), the x contains every f(x) with sequentially from 0 to N (Being N the size of row), the y contains exactly the same (more results)
- Starts algorithm (generations beginning to change
The actions that make every generation are:
- Mutation: A random number of every cromosome can mutate on any gene → adn[i][random] = random number (with a 5% of probability of this happening)
- Crossover: I cross every adn with other adn (80% is the chance of mutation for every pair), for the pairing I pick a random number and face adn[i] and adn[(i+j) mod NumADNs]
Translate. I get a matrix that contains the values f(0 to N) making in one step transcription and translate aplying the grammar on the image
-fitness: I compare the values obtained with the expected ones and update the fitness.
-Elitism: After that, i choose the best 4 adn's and get it to the top, they will be selected
-Selection: Any non elitist adn will face a totally random adn, and if its fitness is lower (Lower is better) will prevail, being a possibilities of the worse one surviving