Last change
on this file since 1316 was
1290,
checked in by Maciej Komosinski, 11 months ago
|
Better mutation, crossover, and evaluation function for a simple minimalistic numerical optimization example
|
File size:
884 bytes
|
Rev | Line | |
---|
[1190] | 1 | import numpy as np |
---|
| 2 | |
---|
| 3 | from ..base.experiment_islands_model_abc import ExperimentIslands |
---|
| 4 | from ..structures.hall_of_fame import HallOfFame |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | class ExperimentNumericalIslands(ExperimentIslands): |
---|
| 8 | def __init__(self, hof_size, popsize, number_of_populations, migration_interval, save_only_best) -> None: |
---|
| 9 | ExperimentIslands.__init__(self,popsize=popsize, |
---|
| 10 | hof_size=hof_size, |
---|
| 11 | number_of_populations=number_of_populations, |
---|
| 12 | migration_interval=migration_interval, |
---|
| 13 | save_only_best=save_only_best) |
---|
| 14 | |
---|
[1290] | 15 | def mutate(self, gen): |
---|
| 16 | return gen + np.random.normal(0, 15, len(gen)) |
---|
[1190] | 17 | |
---|
| 18 | def cross_over(self, gen1, gen2): |
---|
[1290] | 19 | a = np.random.uniform() |
---|
| 20 | return a * gen1 + (1.0-a) * gen2 |
---|
[1190] | 21 | |
---|
[1290] | 22 | def evaluate(self, gen): |
---|
| 23 | return -sum([x*x for x in gen]) |
---|
Note: See
TracBrowser
for help on using the repository browser.