-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_and_train_rmse.py
executable file
·137 lines (103 loc) · 3.88 KB
/
test_and_train_rmse.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
#import math
import os
#import sys
# Set these before running:
#outputDirectory = "Results/GECCO13/bio-normal/"
#outputDirectory = "Results/GECCO13/bio-ultra/"
#outputDirectory = "Results/GECCO13/bio-normal-env/"
#outputDirectory = "Results/GECCO13/bio-45/"
#outputDirectory = "Results/lexicase-paper/ultra/bio-lex/"
#outputDirectory = "Results/gecco13/equal-size-ULTRA/bio/"
#outputDirectory = "Results/GECCO14/order-lexicase/bio-88/"
#outputDirectory = "Results/GECCO14/order-lexicase/rmse-bio-subtree-81-9/"
#outputDirectory = "Results/GECCO14/order-lexicase/rmse-bio-subtree-45-45/"
#outputDirectory = "Results/GECCO14/order-lexicase/rmse-bio-tourney/"
#outputDirectory = "Results/GECCO14/order-lexicase/rmse-bio-lexicase/"
#outputDirectory = "Results/GECCO14/order-lexicase/rmse-bio-88/"
#outputDirectory = "Results/GECCO14/order-lexicase/rmse-bio-78/"
outputDirectory = "Results/GECCO14/order-lexicase/rmse-bio-ol-72/"
outputDirectory = "Results/GECCO14/order-lexicase/rmse-bio-ol-61/"
outputFilePrefix = "log"
outputFileSuffix = ".txt"
errorType = "float"
# Main area
i = 0
if outputDirectory[-1] != '/':
outputDirectory += '/'
dirList = os.listdir(outputDirectory)
bestFitnessesOfRuns = []
while (outputFilePrefix + str(i) + outputFileSuffix) in dirList:
#sys.stdout.write('.')
#if i % 50 == 49:
# print
runs = i + 1 # After this loop ends, runs should be correct
fileName = (outputFilePrefix + str(i) + outputFileSuffix)
f = open(outputDirectory + fileName)
#final = False
gen = 0
train = -1
test = 0
cur_gen_train = -1
done = False
for line in f:
if line.startswith(";; -*- Report"):
gen = int(line.split()[-1])
if line.startswith("SUCCESS") or line.startswith("FAILURE"):
done = True
if line.startswith("RMS-error:"):
if errorType == "float":
cur_gen_train = float(line.split()[-1])
elif errorType == "int" or errorType == "integer":
cur_gen_train = int(line.split()[-1])
else:
raise Exception("errorType of %s is not recognized" % errorType)
if train == -1 or cur_gen_train < train:
train = cur_gen_train
if train == cur_gen_train:
if line.startswith("Test RMSE:"):
if errorType == "float":
test = float(line.split()[-1])
elif errorType == "int" or errorType == "integer":
test = int(line.split()[-1])
else:
raise Exception("errorType of %s is not recognized" % errorType)
bestFitnessesOfRuns.append((gen, train, test, done))
i += 1
for i, (gen, train, test, done) in enumerate(bestFitnessesOfRuns):
print "Run %s: At generation %s" % (i, gen)
print "These are best of run - not necessarily from last generation:"
print " Train RMSE = %s" % train
print " Test RMSE = %s\n" % test
totalTrainRMSE = 0
totalTestRMSE = 0
inds = 0
testRMSEs = []
trainRMSEs = []
for (gen, train, test, done) in bestFitnessesOfRuns:
if done:
totalTrainRMSE += train
trainRMSEs.append(train)
totalTestRMSE += test
testRMSEs.append(test)
inds += 1
if inds > 0:
print "-----"
print "Mean of best train RMSE across %i runs: %.5f" % (inds, totalTrainRMSE / float(inds))
print "Mean of best test RMSE across %i runs: %.5f" % (inds, totalTestRMSE / float(inds))
#testRMSEs.sort()
#for test in testRMSEs:
# print "-- %.2f" % test
#trainRMSEs.sort()
#for train in trainRMSEs:
# print "-- %.2f" % train
def median(lst):
sorts = sorted(lst)
length = len(lst)
if not length % 2:
return (sorts[length / 2] + sorts[length / 2 - 1]) / 2.0
return sorts[length / 2]
print
print "---------"
print
print "Median of train = %.2f" % (median(trainRMSEs))
print "Median of test = %.2f" % (median(testRMSEs))