-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.py
51 lines (50 loc) · 1.02 KB
/
simple.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
'''
Created on Apr 18, 2011
@author: erik
'''
#import math
#import numpy as np
#import matplotlib.pyplot as plt
#import structures
#
#pop = structures.Population()
#pop.make_operators()
#pop.make_constants(-2, 2, 2)
#pop.make_vars('x')
#pop.populate(1, 20)
#fitness = {}
#objective = 'x**2'
#domain = np.arange(-5, 5.1, .1)
#
##for ind in pop.individuals:
## print ind
#
#for ind in pop.individuals:
# whys = []
# for x in domain:
# diff = eval(objective) - ind([x])
# norm_diff = abs(diff)
# whys.append(norm_diff)
## print whys
# sum = 0
# for y in whys:
# sum += y
# fitness[ind] = sum
#
#pairs = fitness.items()
#best_pair = pairs[0]
#for pair in pairs:
# if pair[1] < best_pair[1]:
# best_pair = pair
##print pairs
##print best_pair
#best_indiv = best_pair[0]
#
#y_obj = []
#y_exp = []
#for x in domain:
# y_obj.append(eval(objective))
# y_exp.append(best_indiv([x]))
#
#plt.plot(domain, y_obj, domain, y_exp)
#plt.show()