Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Arbiter : Genetic Search Algorithm #7081
I have implemented a genetic search algorithm and I think others would find it useful.
For those unfamiliar with genetic algorithms (GA), the gist of it is to mimic biologic evolution. That is, a population of candidate solutions is bred and/or mutated to generate better solutions.
There are four building blocks to this algorithm: the crossover operators, the mutation operators, the cull operators and the population model. But the heart of the candidate generation is the SelectionOperator.
These are the currently implemented crossover operators:
The other popular model is the steady state model, in which a newly generated candidate takes the place of an old one in the population. This model solves one of the problem that the generational one has; the new chromosomes are immediately available for crossover. But it has a drawback of its own; if the culling strategy is not chosen carefully, this model has a tendency to reduce the genetic diversity and thus, will tend to favor local optima instead of the global optimum.
The implementation presented here is a compromise of the two. The population is allowed to grow to a certain size (population size) and then, is culled to a certain smaller size (the culled size). This way, new chromosomes are immediately available and, no matter what is our culling strategy, they will have an opportunity to be selected as a parent, thus helping to keep a diverse gene pool.
I'd like to implement a way to save and load the GA's state so the optimization can be stopped and restarted at will. I'd also like to have a better support for on-line optimization, that is to handle the scenario which new training/eval data arrives constantly and good but old candidates may not remain as good as time goes by.
My immediate next steps, however, will be to write examples and documentation.
Hi, sorry for not getting to this sooner. At first glance it looks good, thanks for submitting it!
AlexDBlack left a comment
Finally got to formally reviewing this.
Hi Alex, I should have had taken a moment to thank you for your review.
I've been scratching my head a bit about how to fix the
Another approach would be to monitor the diversity in the population. When near a optima, the algorithm will have a very similar gene pool and the fitness of all individuals will be very close. When that happens,
Instead, I decided to add a attempt counter in
What do you think would be a good way to fix
As for the "hasMoreCanditates()" issue - yeah, I gave that some thought, and came to basically the same conclusion that you did.
I did realize until that we actually do the same thing (return true) in RandomSearchCandidateGenerator, so in light of the fact that we don't even solve it there, let's ignore it (but maybe we should make a brief note in the javadoc). That's not exactly ideal, but in the absence of a better idea, we might have to just go with that.
Anyway, I scanned the code again, it looks good to me. The main thing is the final integration test.
Termination conditions aren't optional... you should be hitting this validation error instead:
Let's make sure that check (or something equivalent) is actually being triggered for that case.