daffidwilde / edo

A library for generating artificial datasets through genetic evolution.
https://doi.org/10.1007/s10489-019-01592-4
MIT License
13 stars 0 forks source link

Implement optimiser class and move to `families` #122

Closed daffidwilde closed 5 years ago

daffidwilde commented 5 years ago

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)
coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 242


Totals Coverage Status
Change from base Build 241: 0.0%
Covered Lines: 543
Relevant Lines: 543

💛 - Coveralls
coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 77


Totals Coverage Status
Change from base Build 241: 0.0%
Covered Lines: 543
Relevant Lines: 543

💛 - Coveralls