With customisation in mind, users will now use edo by creating an instance of the edo.optimiser.DataOptimiser class and the run method with parameters.
The parameters for stopping conditions and mutation adjustment have now been moved to be methods. By default, these methods do nothing but they can be set to use any of the EA's attributes either by defining a subclass of DataOptimiser, or by setting the attribute manually with a user-defined function.
Note also that pdfs are now known as families when talking about classes, i.e. pdf refers to an instance of a family.
from edo import DataOptimiser
from edo.families import Uniform
def my_dwindle(self, threshold=0.01):
""" Halve the mutation probability every 50 generations
if the mean fitness is less than `threshold`. """
if (
sum(self.pop_fitness) / len(pop_fitness) < threshold
and self.generation % 50 == 0
):
self.mutation_prob /= 2
do = DataOptimiser(
lambda df: df.iloc[0,0] ** 2, 100, [0, 0], [0, 0], [Uniform]
)
setattr(do, "dwindle", my_dwindle)
With customisation in mind, users will now use
edo
by creating an instance of theedo.optimiser.DataOptimiser
class and therun
method with parameters.The parameters for stopping conditions and mutation adjustment have now been moved to be methods. By default, these methods do nothing but they can be set to use any of the EA's attributes either by defining a subclass of
DataOptimiser
, or by setting the attribute manually with a user-defined function.Note also that
pdfs
are now known asfamilies
when talking about classes, i.e.pdf
refers to an instance of afamily
.