I'm fresh on genetic algorithm. Now, I wrote an python program based on genetic algorithm. The programming contain:
- Set the population and individuals(For my case, each individual is a list with 8-elements)
- Define the
evaluation functionto asses each individual's fitness(For my case, Larger is good.)
- Define the
grade functionto calculate each generation's average fitness.
- Each generation will sort by grade and leave higher ranked ones as parents.
- parents will undergo the mutation and crossover.(For example, if the population = 100, only 20 parents was left dut to its higher grade. The rest 80 individuals as children are generated by randomly choosing
motherfor crossover. Then, the 100 individuals as next generation will go through another evolution)
- After some generation, the ideal results should represent the highest grade.
My target was to get an 8-elements list with the highest fitness among the solution domain.
But in pratice, my program always got stuck into locally optimum. The result has many list containing he same number. By setting parameters correctly, it should solve my problem. But I want to modify them on target, not in eyeless.
The parameters I could change comprised by these:
- len(population): the whole scale of individuals. For now, I set the len(population) = 10.
- evolution time: It means the number of generations I will created by using subroutine like
next_generation = evolve(population)
- retain_fraction: After ranking by grade, the "outstanding" individuals' number would be determined by retain_fraction. For example, r_f = 0.2, len(pop)=10=> only 2 individual would be left.
- mutation_frequency: By modify this arguement, an random point of individual would be changed into an random value in range(min(individual),max(individual)).
I tried to adjust them to get an better solution. But the result which represent the grade(average fitness of the generation) shows like this:
118.833333333 126.833333333 165.0 201.0 201.0 201.0 201.0 201.0 201.0 201.0 201.0