-
Notifications
You must be signed in to change notification settings - Fork 80
/
stopping_criterions.py
36 lines (29 loc) · 1.31 KB
/
stopping_criterions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# encoding=utf8
# This is temporary fix to import module from parent folder
# It will be removed when package is published on PyPI
import sys
sys.path.append('../')
# End of fix
from niapy.task import Task
from niapy.algorithms.basic import DifferentialEvolution
from niapy.problems import Sphere
# 1 Number of function evaluations (nFES) as a stopping criteria
for i in range(10):
task = Task(problem=Sphere(dimension=10), max_evals=10000)
algo = DifferentialEvolution(population_size=40, crossover_probability=0.9, differential_weight=0.5)
best = algo.run(task)
print('%s -> %s' % (best[0], best[1]))
print('---------------------------------------')
# 2 Number of generations (iterations) as a stopping criteria
for i in range(10):
task = Task(problem=Sphere(dimension=10), max_iters=1000)
algo = DifferentialEvolution(population_size=40, crossover_probability=0.9, differential_weight=0.5)
best = algo.run(task)
print('%s -> %s' % (best[0], best[1]))
print('---------------------------------------')
# 3 Reference value as a stopping criteria
for i in range(10):
task = Task(problem=Sphere(dimension=10), cutoff_value=50.0)
algo = DifferentialEvolution(population_size=40, crossover_probability=0.9, differential_weight=0.5)
best = algo.run(task)
print('%s -> %s' % (best[0], best[1]))