-
Notifications
You must be signed in to change notification settings - Fork 6
/
long_csv_diversity.py
executable file
·229 lines (177 loc) · 12.5 KB
/
long_csv_diversity.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/python
import os, sys
# Set these before running:
## For EHC paper
# dirs = [("Baseline", "Results/bench-prog-synth/vector-average/ehc-experiments/tourney/standard/"),
# ("Ep0", "Results/bench-prog-synth/vector-average/ehc-experiments/tourney/standard-half-silenced/"),
# ("EHC1", "Results/bench-prog-synth/vector-average/ehc-experiments/tourney/EHC/"),
# ("Ep1M", "Results/bench-prog-synth/vector-average/ehc-experiments/tourney/epigenetic-silence-mutation/")
# ]
# dirs = [("Baseline", "Results/bench-prog-synth/replace-space-with-newline/ehc-experiments/epiline-without-hill-climbing/max-evals-3e10-silence-mut-off/tourney-7/"),
# ("Ep0", "Results/bench-prog-synth/replace-space-with-newline/ehc-experiments/tourney-7/standard-half-silenced/"),
# ("EHC1", "Results/bench-prog-synth/replace-space-with-newline/ehc-experiments/tourney-7/EHC/"),
# ("Ep1M", "Results/bench-prog-synth/replace-space-with-newline/ehc-experiments/epiline-without-hill-climbing/EHC-testing/tourney-7/")
# ]
# dirs = [("Baseline", "Results/bench-prog-synth/syllables/ehc-experiments/tourney/standard/"),
# ("Ep0", "Results/bench-prog-synth/syllables/ehc-experiments/tourney/standard-half-silenced/"),
# ("EHC1", "Results/bench-prog-synth/syllables/ehc-experiments/tourney/EHC/"),
# ("Ep1M", "Results/bench-prog-synth/syllables/ehc-experiments/tourney/epigenetic-silence-mutation/")
# ]
############ For GECCO16 Diversity Workshop - Diversity Recovery paper
######## Replace Space With Newline
### Div drop 25
# dirs = [("Drop25-Run0-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-drop-25/replace-space-with-newline/continuations/lexicase/run0/"),
# ("Drop25-Run0-tournament", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-drop-25/replace-space-with-newline/continuations/tournament/run0/")
# ]
# dirs = [("Drop25-Run8-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-drop-25/replace-space-with-newline/continuations/lexicase/run8/"),
# ("Drop25-Run8-tournament", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-drop-25/replace-space-with-newline/continuations/tournament/run8/")
# ]
### Div > 90
# dirs = [("Div90-Run6-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-90/replace-space-with-newline/continuations/lexicase/run6/"),
# ("Div90-Run6-tournament", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-90/replace-space-with-newline/continuations/tournament/run6/")
# ]
# dirs = [("Div90-Run10-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-90/replace-space-with-newline/continuations/lexicase/run10/"),
# ("Div90-Run10-tournament", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-90/replace-space-with-newline/continuations/tournament/run10/")
# ]
### tourney Div < 15
# dirs = [("Div15-Run0-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/tourney-div-15/replace-space-with-newline/continuations/lexicase/run0/"),
# ("Div15-Run0-tournament", "Results/GECCO16/diversity-recovery/storing-populations/tourney-div-15/replace-space-with-newline/continuations/tournament/run0/")
# ]
# dirs = [("Div15-Run1-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/tourney-div-15/replace-space-with-newline/continuations/lexicase/run1/"),
# ("Div15-Run1-tournament", "Results/GECCO16/diversity-recovery/storing-populations/tourney-div-15/replace-space-with-newline/continuations/tournament/run1/")
# ]
####### Double Letters
### Div drop 25
# dirs = [("Drop25-Run0-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-drop-25/double-letters/continuations/lexicase/run0/"),
# ("Drop25-Run0-tournament", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-drop-25/double-letters/continuations/tournament/run0/")
# ]
# dirs = [("Drop25-Run21-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-drop-25/double-letters/continuations/lexicase/run21/"),
# ("Drop25-Run21-tournament", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-drop-25/double-letters/continuations/tournament/run21/")
# ]
### Div > 90
# dirs = [("Div90-Run0-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-90/double-letters/continuations/lexicase/run0/"),
# ("Div90-Run0-tournament", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-90/double-letters/continuations/tournament/run0/")
# ]
# dirs = [("Div90-Run3-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-90/double-letters/continuations/lexicase/run3/"),
# ("Div90-Run3-tournament", "Results/GECCO16/diversity-recovery/storing-populations/lex-div-90/double-letters/continuations/tournament/run3/")
# ]
### tourney Div < 15
# dirs = [("Div15-Run0-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/tourney-div-15/double-letters/continuations/lexicase/run0/"),
# ("Div15-Run0-tournament", "Results/GECCO16/diversity-recovery/storing-populations/tourney-div-15/double-letters/continuations/tournament/run0/")
# ]
# dirs = [("Div15-Run1-lexicase", "Results/GECCO16/diversity-recovery/storing-populations/tourney-div-15/double-letters/continuations/lexicase/run1/"),
# ("Div15-Run1-tournament", "Results/GECCO16/diversity-recovery/storing-populations/tourney-div-15/double-letters/continuations/tournament/run1/")
# ]
############ For GPTP 17 - Sarah Troise's weighted lexicase paper
# dirs = [("Number-of-Zeros", "/home/stroise/results/weighted-lexicase/number-of-zeros/replace-space-with-newline/"),
# ("Number-of-Nonzeros-Inverse", "/home/stroise/results/weighted-lexicase/number-of-nonzero-inverse/replace-space-with-newline/"),
# ("Median-Inverse", "/home/thelmuth/Results/weighted-lexicase/weighted-lexicase/median-inverse/replace-space-with-newline/"),
# ("Number-of-Zeros-Inverse", "/home/stroise/results/weighted-lexicase/number-of-zeros-inverse/replace-space-with-newline/"),
# ("Number-of-Nonzeros", "/home/stroise/results/weighted-lexicase/number-of-nonzero/replace-space-with-newline/"),
# ("Median", "/home/stroise/results/weighted-lexicase/median/replace-space-with-newline/"),
# ("Average", "/home/thelmuth/Results/weighted-lexicase/weighted-lexicase/average/replace-space-with-newline/"),
# ("Variance", "/home/stroise/results/weighted-lexicase/variance/replace-space-with-newline/"),
# ("Variance-Inverse", "/home/thelmuth/Results/weighted-lexicase/weighted-lexicase/variance-inverse/replace-space-with-newline/")
# ]
# dirs = [("Number-of-Zeros", "/home/thelmuth/Results/weighted-lexicase/ranked-lexicase/number-of-zeros/replace-space-with-newline/"),
# ("Number-of-Nonzeros-Inverse", "/home/thelmuth/Results/weighted-lexicase/ranked-lexicase/number-of-nonzero-inverse/replace-space-with-newline/"),
# ("Median-Inverse", "/home/thelmuth/Results/weighted-lexicase/ranked-lexicase/median-inverse/replace-space-with-newline/"),
# ("Number-of-Zeros-Inverse", "/home/thelmuth/Results/weighted-lexicase/ranked-lexicase/number-of-zeros-inverse/replace-space-with-newline/"),
# ("Number-of-Nonzeros", "/home/thelmuth/Results/weighted-lexicase/ranked-lexicase/number-of-nonzero/replace-space-with-newline/"),
# ("Median", "/home/thelmuth/Results/weighted-lexicase/ranked-lexicase/median/replace-space-with-newline/"),
# ("Average", "/home/thelmuth/Results/weighted-lexicase/ranked-lexicase/average/replace-space-with-newline/"),
# ("Variance", "/home/thelmuth/Results/weighted-lexicase/ranked-lexicase/variance/replace-space-with-newline/"),
# ("Variance-Inverse", "/home/thelmuth/Results/weighted-lexicase/ranked-lexicase/variance-inverse/replace-space-with-newline/")
# ]
# dirs = [("Regular-Lexicase", "/home/thelmuth/Results/parent-selection-v2/lexicase/replace-space-with-newline"),
# ("Number-of-Zeros", "/home/thelmuth/Results/weighted-lexicase/bias-lexicase/number-of-zeros/replace-space-with-newline/"),
# ("Number-of-Nonzeros-Inverse", "/home/thelmuth/Results/weighted-lexicase/bias-lexicase/number-of-nonzero-inverse/replace-space-with-newline/"),
# ("Median-Inverse", "/home/thelmuth/Results/weighted-lexicase/bias-lexicase/median-inverse/replace-space-with-newline/"),
# ("Number-of-Zeros-Inverse", "/home/thelmuth/Results/weighted-lexicase/bias-lexicase/number-of-zeros-inverse/replace-space-with-newline/"),
# ("Number-of-Nonzeros", "/home/thelmuth/Results/weighted-lexicase/bias-lexicase/number-of-nonzero/replace-space-with-newline/"),
# ("Median", "/home/thelmuth/Results/weighted-lexicase/bias-lexicase/median/replace-space-with-newline/"),
# ("Average", "/home/thelmuth/Results/weighted-lexicase/bias-lexicase/average/replace-space-with-newline/"),
# ("Variance", "/home/thelmuth/Results/weighted-lexicase/bias-lexicase/variance/replace-space-with-newline/"),
# ("Variance-Inverse", "/home/thelmuth/Results/weighted-lexicase/bias-lexicase/variance-inverse/replace-space-with-newline/")
# ]
# dirs = [("Regular-Lexicase", "/home/thelmuth/Results/parent-selection-v2/lexicase/replace-space-with-newline"),
# ("Tournament", "/home/thelmuth/Results/parent-selection-v2/tourney-7/replace-space-with-newline")]
problems = ["compare-string-lengths",
"double-letters",
"replace-space-with-newline",
"string-lengths-backwards",
"last-index-of-zero",
"vector-average",
"mirror-image",
"x-word-lines",
"negative-to-zero",
"scrabble-score",
"smallest",
"syllables"
]
#basedir = "/home/thelmuth/Collab/thelmuth/Results/counterexample-driven-gp/no-generational-case-additions/%s/"
basedir = "/home/thelmuth/Collab/thelmuth/Results/counterexample-driven-gp/add-case-after-50-gens/%s/"
dirs = []
for problem in problems:
tup = (problem, basedir % problem)
dirs.append(tup)
outputFilePrefix = "log"
outputFileSuffix = ".txt"
# Main area
# def mean(nums):
# if len(nums) <= 0:
# return -1
# return sum(nums) / float(len(nums))
#max_gen = 0
def printBehavioralDiversitiesLong(method, outputDirectory):
#global max_gen
run_num = 0
if outputDirectory[-1] != '/':
outputDirectory += '/'
dirList = os.listdir(outputDirectory)
#bd_list_per_gen = []
while (outputFilePrefix + str(run_num) + outputFileSuffix) in dirList:
fileName = (outputFilePrefix + str(run_num) + outputFileSuffix)
f = open(outputDirectory + fileName)
gen = 0
done = False
behavioral_diversity = -1
point_evals = -1
for line in f:
if line.startswith(";; -*- Report"):
gen = int(line.split()[-1])
# if gen > max_gen:
# max_gen = gen
# while len(bd_list_per_gen) <= gen:
# bd_list_per_gen.append([])
if line.startswith("Behavioral diversity:"):
behavioral_diversity = float(line.split()[-1])
# bd_list_per_gen[gen].append(bd)
if line.startswith("Error (vector) diversity:"):
error_vector_diversity = float(line.split()[-1])
if line.startswith("Number of point (instruction) evaluations so far:"):
point_evals = int(line.split()[-1])
print("%s,%i,%i,%i,%0.3f,%0.3f" % (method, run_num, gen, point_evals, behavioral_diversity, error_vector_diversity))
if line.startswith("SUCCESS"):
done = "SUCCESS"
break
if line.startswith("FAILURE"):
done = "FAILURE"
break
run_num += 1
return
#print "method,run,generation,ptevals,behavioral_diversity"
print("method,trial,generation,ptevals,behavioral_diversity,error_vector_diversity")
for (method, directory) in dirs:
print(method, file=sys.stderr)
printBehavioralDiversitiesLong(method, directory)
# dir_bd_lists = [getBehavioralDiversities(d) for (n,d) in dirs]
# for g in range(max_gen+1):
# out_str = str(g) + ","
# for bd_list in dir_bd_lists:
# try:
# bd = "%0.3f," % bd_list[g]
# except:
# bd = ","
# out_str += bd
# print out_str[:-1]