-
Notifications
You must be signed in to change notification settings - Fork 6
/
csv_program_sizes.py
executable file
·158 lines (113 loc) · 5.38 KB
/
csv_program_sizes.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
#import math
import os
#import sys
# Set these before running:
csv_format = "wide" # Can be wide or long
######## For GPTP Plush Paper
dirs = [("Replace Space With Newline", "Results/bench-prog-synth/replace-space-with-newline/parent-selection/lexicase/"),
("Syllables", "Results/bench-prog-synth/syllables/parent-selection/lexicase/"),
("Negative To Zero", "Results/bench-prog-synth/negative-to-zero/parent-selection/lexicase/"),
("X-Word Lines", "Results/bench-prog-synth/x-word-lines/parent-selection/lexicase/"),
("Count Odds", "Results/bench-prog-synth/count-odds/parent-selection/lexicase/")]
######## For dissertation
#dirs = [("lexicase", "Results/bench-prog-synth/replace-space-with-newline/parent-selection/lexicase/"),
# ("tourney7", "Results/bench-prog-synth/replace-space-with-newline/parent-selection/tourney-7/"),
# ("ifs7", "Results/bench-prog-synth/replace-space-with-newline/parent-selection/ifs-7/")]
# dirs = [("lexicase", "Results/bench-prog-synth/mirror-image/parent-selection/lexicase/"),
# ("tourney7", "Results/bench-prog-synth/mirror-image/parent-selection/tourney-7/"),
# ("ifs7", "Results/bench-prog-synth/mirror-image/parent-selection/ifs-7/")]
######### Old
#dir1 = "Results/GECCO13/bio-normal/"
#dir2 = "Results/GECCO13/bio-45/"
#dir3 = "Results/GECCO13/bio-ultra/"
#dir4 = "Results/equal-size-ULTRA/bio/"
#dir1 = "Results/GECCO13/pagie-no-erc-normal/"
#dir2 = "Results/GECCO13/pagie-hogeweg-no-erc-45/"
#dir3 = "Results/GECCO13/pagie-no-erc-ultra/"
#dir4 = "Results/equal-size-ULTRA/pagie-no-erc/"
#dir1 = "Results/GECCO13/mux6-normal/"
#dir2 = "Results/GECCO13/mux6-ultra/"
#dir4 = "Results/equal-size-ULTRA/mux6/"
#dir1 = "Results/GECCO13/factorial-normal/"
#dir2 = "Results/GECCO13/factorial-ultra/"
#dir3 = "Results/GECCO13/factorial-ultra-large/"
#dir1 = "Results/GECCO13/factorial-normal-500gens/"
#dir2 = "Results/GECCO13/factorial-ultra-500gens/"
#dir4 = "Results/equal-size-ULTRA/factorial/"
# dir1 = "Results/gecco13/DM/mom2-lex-ultra"
# dir2 = "Results/plush-testing/dm2-ultra-lex/"
# dir3 = "Results/plush-testing/dm2-zero-align-dev/"
# dir4 = "Results/plush-testing/dm2-noops/"
# prefix1 = "log"
# prefix2 = "bio-normallog"
#dirs = [("Normal", dir1, prefix1),
# ("Normal_45", dir2, prefix1),
# ("ULTRA", dir3, prefix1),
# ("ULTRA-Equal-Sizes", dir4, prefix1)]
# dirs = [("Push", dir1, prefix1),
# ("Plush", dir2, prefix1),
# ("PlushNoops", dir4, prefix1),
# ("PlushNoAlignDev", dir3, prefix1)]
## For Lia's honor's thesis
dirs = [("RSWN", "/home/thelmuth/Results/parent-selection-v2/lexicase/replace-space-with-newline/"),
("Syllables", "/home/thelmuth/Results/parent-selection-v2/lexicase/syllables/"),
("Vector Average", "/home/thelmuth/Results/parent-selection-v2/lexicase/vector-average/"),
("Double Letters", "/home/thelmuth/Results/parent-selection-v2/lexicase/double-letters/"),
("Mirror Image", "/home/thelmuth/Results/parent-selection-v2/lexicase/mirror-image/"),
("Last Index of Zero", "/home/thelmuth/Results/parent-selection-v2/lexicase/last-index-of-zero/"),
("Scrabble Score", "/home/thelmuth/Results/parent-selection-v2/lexicase/scrabble-score/")
]
outputFileSuffix = ".txt"
def my_mean(list_of_nums):
if len(list_of_nums) == 0:
return 0.0
return float(sum(list_of_nums)) / float(len(list_of_nums))
def getProgramSizes(outputDirectory, outputFilePrefix):
global max_gen
i = 0
if outputDirectory[-1] != '/':
outputDirectory += '/'
dirList = os.listdir(outputDirectory)
max_generations = 0
sizes_per_gen = []
while (outputFilePrefix + str(i) + outputFileSuffix) in dirList:
fileName = (outputFilePrefix + str(i) + outputFileSuffix)
f = open(outputDirectory + fileName)
gen = 0
mean_size = 0
for line in f:
if i == 0:
if line.startswith("max-generations"):
max_generations = int(line.split()[-1])
max_gen = max_generations
sizes_per_gen = [[] for x in range(max_generations + 1)]
if line.startswith(";; -*- Report"):
gen = int(line.split()[-1])
if line.startswith("Average program size in population"):
mean_size = float(line.split()[-1])
sizes_per_gen[gen].append(mean_size)
i += 1
return sizes_per_gen
if csv_format == "long":
print "Condition,Generation,MeanProgramSize"
# for (condition, directory, prefix) in dirs:
# sizes = getProgramSizes(directory, prefix)
for (condition, directory) in dirs:
sizes = getProgramSizes(directory, "log")
for gen, gen_sizes in enumerate(sizes):
print "%s,%i,%f" % (condition, gen, my_mean(gen_sizes))
elif csv_format == "wide":
print "generation," + str([n for (n,d) in dirs]).replace(" ","").replace("]","").replace("[","").replace("'","")
dir_size_lists = [getProgramSizes(d, "log") for (n,d) in dirs]
# print "dir_size_lists = ", dir_size_lists
for g in range(max_gen+1):
out_str = str(g) + ","
for size_list in dir_size_lists:
try:
size = "%0.3f," % my_mean(size_list[g])
except:
size = ","
out_str += size
print out_str[:-1]
else:
print "Invalid csv_format:", csv_format