ea module¶
This module defines the Evolutionary Algorithm (EA) class.
This module defines the EA class, used to configure, create and train an evolutionary algorithm. It defines the methods and processes currently supported including:
Evolution of a EA
4D visualisation of the evolution in the phenotype space.
Example
>>> import loss_functions
>>> import test_functions
>>> from gene import Gene
>>> genotype = {
... "x": (float, [-100,100]),
... "y":(float, [-20,20]),
... }
>>> config = {
... "pop_size":100,
... "elitism":0.3,
... "indiv": genotype,
... "generations": 100,
... "crossover": True,
... "crossover rate": 0.3,
... "constraint":"Hard",
... "fitness": loss_functions.Minimize,
... "optimization function": test_functions.easom_test,
... "verbose" : True,
... "print rate" : 10,
... }
>>> ea = EA(config)
>>> ea.evolve()
----- Begin Evolution -----
...
----- Evolution Over -----
Best individual:
fitness : ...
Worst individual:
fitness : ...
>>> ea.visualise()
...
-
class
ea.
EA
(config: Dict[str, Any])[source]¶ Bases:
object
The EA class, used to define an evolutionary process.
Defines an evolutionary process, performs the evolution of a population and the visualisation of the process.
-
evolve
() → None[source]¶ Evolves a population using the desired configuration.
Evolves a population of individuals with a given genotype through:
Random mutations
Crossovers (Optional)
Elitism (Optional)
-
visualise
(savefig: str = 'animation') → None[source]¶ Visualise the evolutionary process in 4D.
Makes a 4D (3d + time) visualisation of the evolutionary process by plotting the phenotype space. Saves the animation in a folder named
Visualisations
.- Parameters
savefig (str) – Name under which the animation will be saved.
-