Cleaned up comments.

This commit is contained in:
SimpleArt
2020-11-27 20:03:43 -05:00
parent cbd0265cd8
commit 65a35e71dc

View File

@ -98,6 +98,9 @@ class GA(Attributes):
def adapt(self):
"""Modifies the parent ratio and mutation rates
based on the adapt rate and percent converged.
Attempts to balance out so that 25% of the desired
percent converged (50%*25% = 12.5% default)
is the amount converged at all times.
"""
# Don't adapt
@ -125,7 +128,7 @@ class GA(Attributes):
threshhold_fitness = self.population[round(self.percent_converged*len(self.population)/8)].fitness
# Way too few converged
# Way too few converged, adapt twice as fast
if abs(best_fitness - threshhold_fitness) > tol:
multiplier **= 2
limit = max_val / multiplier
@ -138,9 +141,9 @@ class GA(Attributes):
# Too many converged: cross less and mutate more
else:
threshhold_fitness = self.population[round(self.percent_converged*len(self.population)/2)].fitness
threshhold_fitness = self.population[round(self.percent_converged*len(self.population)*3/8)].fitness
# Way too many converged
# Way too many converged, adapt twice as fast
if abs(best_fitness - threshhold_fitness) < tol:
multiplier **= 2
limit = max_val / multiplier