source:
framspy/evolalg/numerical_example/numerical_example.py
@
1297
Last change on this file since 1297 was 1290, checked in by , 11 months ago | |
---|---|
File size: 609 bytes |
Line | |
---|---|
1 | import numpy as np |
2 | |
3 | from ..base.experiment_abc import ExperimentABC |
4 | |
5 | |
6 | class ExperimentNumerical(ExperimentABC): |
7 | def __init__(self, hof_size, popsize, save_only_best) -> None: |
8 | ExperimentABC.__init__(self,popsize=popsize, |
9 | hof_size=hof_size, |
10 | save_only_best=save_only_best) |
11 | |
12 | def mutate(self, gen): |
13 | return gen + np.random.normal(0, 15, len(gen)) |
14 | |
15 | def cross_over(self, gen1, gen2): |
16 | a = np.random.uniform() |
17 | return a * gen1 + (1.0-a) * gen2 |
18 | |
19 | def evaluate(self, gen): |
20 | return -sum([x*x for x in gen]) |
Note: See TracBrowser
for help on using the repository browser.