source: framspy/evolalg/numerical_example/numerical_example.py @ 1190

Last change on this file since 1190 was 1190, checked in by Maciej Komosinski, 15 months ago

Added the "evolalg" module for evolutionary optimization

File size: 628 bytes
Line 
1import numpy as np
2
3from ..base.experiment_abc import ExperimentABC
4from ..structures.hall_of_fame import HallOfFame
5
6
7class ExperimentNumerical(ExperimentABC):
8    def __init__(self, hof_size, popsize, save_only_best) -> None:
9        ExperimentABC.__init__(self,popsize=popsize,
10                               hof_size=hof_size,
11                               save_only_best=save_only_best)
12
13    def mutate(self, gen1):
14        return list(gen1 + np.random.randint(-10, 10, len(gen1)))
15
16    def cross_over(self, gen1, gen2):
17        return gen1
18
19    def evaluate(self, genotype):
20        return 1/sum([x*x for x in genotype])
Note: See TracBrowser for help on using the repository browser.