-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcsv_success_generations.py
executable file
·134 lines (95 loc) · 4.43 KB
/
csv_success_generations.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
#!/usr/bin/python
import os
from sys import maxint
# Set these before running:
error_threshold = 0
max_gens = 300
# Novelty Lexicase
#main_dir = "/home/thelmuth/Collab/thelmuth/Results/novelty-lexicase/gens-1000/genops-original/"
#main_dir = "/home/thelmuth/Collab/thelmuth/Results/novelty-lexicase/gens-1000/no-novelty-genops-original/"
main_dir = "/home/thelmuth/Results/specialists-and-lexicase/elitist-survival-2018-not-UMAD/rate-100/lexicase/"
probs = [#"compare-string-lengths",
#"double-letters",
"last-index-of-zero",
"mirror-image",
"negative-to-zero",
"replace-space-with-newline",
"string-lengths-backwards",
"syllables",
"vector-average",
"x-word-lines",
#"scrabble-score",
#pig-latin",
]
dirs = [(prob, main_dir + prob) for prob in probs]
outputFilePrefix = "log"
outputFileSuffix = ".txt"
def getSuccessGens(outputDirectory):
# Main area
i = 0
if outputDirectory[-1] != '/':
outputDirectory += '/'
dirList = os.listdir(outputDirectory)
train_success_generations = []
test_success_generations = []
simplified_test_success_generations = []
while (outputFilePrefix + str(i) + outputFileSuffix) in dirList:
runs = i + 1 # After this loop ends, runs should be correct
fileName = (outputFilePrefix + str(i) + outputFileSuffix)
f = open(outputDirectory + fileName)
gen = -1
trainSuccess = -1
testSuccess = -1
simpTestSuccess = -1
for line in reversed(f.readlines()):
if line.startswith("Test total error for best:") and simpTestSuccess == -1:
try:
simpBestTest = int(line.split()[-1].strip("Nn"))
except ValueError, e:
simpBestTest = float(line.split()[-1].strip("Nn"))
if simpBestTest <= error_threshold:
simpTestSuccess = True
else:
simpTestSuccess = False
if line.startswith("Test total error for best:") and simpTestSuccess != -1:
try:
bestTest = int(line.split()[-1].strip("Nn"))
except ValueError, e:
bestTest = float(line.split()[-1].strip("Nn"))
if bestTest <= error_threshold:
testSuccess = True
else:
testSuccess = False
if line.startswith("SUCCESS"):
trainSuccess = True
if line.startswith("FAILURE"):
trainSuccess = False
testSuccess = False
simpTestSuccess = False
if line.startswith(";; -*- Report") and gen == -1:
gen = int(line.split()[-1])
if gen >= 0 and trainSuccess != -1 and testSuccess != -1 and simpTestSuccess != -1:
break
if trainSuccess == True: # Might be -1, which would need to be False here
train_success_generations.append(gen)
if testSuccess == True: # Might be -1, which would need to be False here
test_success_generations.append(gen)
if simpTestSuccess == True: # Might be -1, which would need to be False here
simplified_test_success_generations.append(gen)
i += 1
return (train_success_generations, test_success_generations, simplified_test_success_generations)
def numbers_leq_x(nums, x):
"""Returns the count of the number of numbers <= x in list nums"""
return len(filter(lambda a: a <= x, nums))
#### Printing
#tab_sep_titles = str([n for (n,d) in dirs]).replace(" ","").replace("]","").replace("[","").replace("'","").replace(",","\t")
#print "run\tresult\tgeneration\t" + tab_sep_titles + "\tpoint-evaluations\t" + tab_sep_titles
print "problem,generation,number_of_train_successes,number_of_test_successes,number_of_simplified_test_successes"
#raise Exception("asdasd")
for (prob, directory) in dirs:
(train_success_generations, test_success_generations, simplified_test_success_generations) = getSuccessGens(directory)
for gen in range(0, max_gens + 1):
train_this_gen = numbers_leq_x(train_success_generations, gen)
test_this_gen = numbers_leq_x(test_success_generations, gen)
simp_this_gen = numbers_leq_x(simplified_test_success_generations, gen)
print "%s,%i,%i,%i,%i" % (prob, gen, train_this_gen, test_this_gen, simp_this_gen)