-
Notifications
You must be signed in to change notification settings - Fork 1
/
statistics.py
48 lines (33 loc) · 1.61 KB
/
statistics.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
import numpy as np
import pickle
import json
class Statistics:
params = None
def __init__(self, params):
self.params = params
self.adhoc = {'fitness': {'mins': [[], [], []],
'avgs': [[], [], []],
'maxs': [[], [], []]}}
self.posthoc = {'population': {'all': []}}
def setup(self):
self.adhoc = {'fitness': {'mins': [[], [], []],
'avgs': [[], [], []],
'maxs': [[], [], []]}}
self.posthoc = {'population': {'all': []}}
def update_dynamic(self, population):
self.set_fitt_mins(population)
self.set_fitt_avgs(population)
self.set_fitt_maxs(population)
def update_static(self, population):
self.set_pop(population)
def set_fitt_mins(self, population):
for i in range(self.params['num_objs']):
self.adhoc['fitness']['mins'][i].append(np.array([ind['fitness'][i] for ind in population]).min())
def set_fitt_maxs(self, population):
for i in range(self.params['num_objs']):
self.adhoc['fitness']['maxs'][i].append(np.array([ind['fitness'][i] for ind in population]).max())
def set_fitt_avgs(self, population):
for i in range(self.params['num_objs']):
self.adhoc['fitness']['avgs'][i].append(np.array([ind['fitness'][i] for ind in population]).mean())
def set_pop(self, population):
self.posthoc['population']['all'] = [ind['gene'] for ind in population]