applyFitnessSharingToResults method
Iterates over members
and raises their fitness score according to
their uniqueness.
If fitnessSharing is false
, doesn't do anything.
Algorithm as described in Jeffrey Horn: The Nature of Niching, pp 20-21. http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.33.8352&rep=rep1&type=pdf
Implementation
void applyFitnessSharingToResults(Generation<P, G, R> generation) {
if (fitnessSharing == false) return;
for (final ph in generation.members) {
final similars =
generation.getSimilarPhenotypes(ph, fitnessSharingRadius);
var nicheCount = 0.0;
for (final other in similars) {
// TODO: stop computing hamming distance twice (in getSimilarPhenotypes
// and here)
final distance = ph.computeHammingDistance(other);
nicheCount +=
1 - math.pow(distance / fitnessSharingRadius, fitnessSharingAlpha);
}
// The algorithm is modified - we multiply the result instead of
// dividing it. (Because we count 0.0 as perfect fitness. The smaller
// the result number, the fitter the phenotype.)
ph.resultWithFitnessSharingApplied = ph.result!.evaluate() * nicheCount;
}
}