-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.py
56 lines (49 loc) · 1.39 KB
/
utility.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
#
# BBSA Auto-benchmark
from math import sqrt
def statistics(s):
'''min, max, mean, stddev'''
result = {'min': 0, 'max': 0, 'mean': 0, 'stddev': 0}
result['min'] = min(s)
result['max'] = max(s)
result['mean'] = sum(s) / float(len(s))
result['stddev'] = \
sqrt(sum((x - result['mean']) ** 2 for x in s) / float(len(s) - 1))
return result
def population_analyzer(population, state):
result = dict()
fits = [x.fitness for x in population]
for p in population:
if not hasattr(p, '__age'):
p.__age = -1
p.age += 1
ages = [x.__age for x in population]
result['fitness'] = statistics(fits)
result['ages'] = statistics(ages)
result['best_fitness'] = max(result['best_fitness'],
result['fitness']['max'])
result['worst_fitness'] = min(result['worst_fitness'],
result['fitness']['min'])
result['size'] = len(population)
return result
state = {
'evals': 0,
'max_evals': 10000,
'best_fitness': 0,
'worst_fitness': -1,
'population_stats': {
'fitness': {
'max': 10,
'min': -1,
'mean': 6,
'stddev': 3.4},
'age': {
'max': 10,
'min': 0,
'mean': 5,
'stddev': 3},
'size': 100,
'diversity': 12
}
}