-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
102 lines (73 loc) · 2.52 KB
/
test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import pylab
from main import *
PROBS_CROSSOVER = range(1, 10)
PROBS_MUTATION = range(0, 40, 5)
PROBS_SELECTION = range(1, 9)
REPEAT_COUNT = 100
SIZES = range(400, 700, 50)
ALL_PROBS = sorted(PROBS_CROSSOVER + PROBS_MUTATION + PROBS_SELECTION)
print ALL_PROBS
values = []
pylab.figure(1)
pylab.title('Crossove (red), Mutation (green), Selection (blue) Probs/Avg population')
pylab.xlabel('%')
pylab.ylabel('Avg Generations')
pylab.grid(True)
lasagna = ["tomatoes", "steam", "cheese", "melt", "sweet Italian sausage", "mix", "garlic"]
def plot_crossover():
pylab.title('Crossove (red) Probs/Avg population')
for prob in PROBS_CROSSOVER:
results = []
for i in range(REPEAT_COUNT):
result = GeneticAlgorithm(GuessRecipe(lasagna, prob_crossover = 0.1 * prob)).run()
results.append(result)
values.append(sum(results) / len(results))
print values
pylab.plot(PROBS_CROSSOVER, values, 'r--')
def plot_mutation():
pylab.title('Mutation (green) Probs/Avg population')
for prob in PROBS_MUTATION:
results = []
for i in range(REPEAT_COUNT):
result = GeneticAlgorithm(GuessRecipe(lasagna, prob_mutation = 0.01 * prob)).run()
results.append(result)
values.append(sum(results) / len(results))
print values
pylab.plot(PROBS_MUTATION, values, 'g--')
def plot_selection():
pylab.title('Selection (blue) Probs/Avg population')
for prob in PROBS_SELECTION:
results = []
for i in range(REPEAT_COUNT):
result = GeneticAlgorithm(GuessRecipe(lasagna, prob_selection = 0.1 * prob)).run()
results.append(result)
values.append(sum(results) / len(results))
print values
pylab.plot(PROBS_SELECTION, values, 'b--')
def plot_size():
pylab.title('Sizes/Avg population')
for size in SIZES:
results = []
for i in range(REPEAT_COUNT):
result = GeneticAlgorithm(GuessRecipe(lasagna, size = size)).run()
results.append(result)
values.append(sum(results) / len(results))
print values
pylab.plot(SIZES, values, 'y--')
def hist():
pylab.title('Hist')
pylab.xlabel('Generations')
pylab.ylabel('Freq')
results = []
for i in range(100):
result = GeneticAlgorithm(GuessRecipe(lasagna)).run()
results.append(result)
print values
pylab.hist(results, 30, facecolor='g', alpha=0.75)
# plot_crossover()
# plot_mutation()
# plot_selection()
# plot_size()
hist()
pylab.savefig('allprob')
pylab.show()