15 def readLogFile(self, fileName):
17 logFile = open(fileName,
'r')
19 print(
"Couldn't open the file ", fileName)
30 readMax = readMin = readAvg = readStd =
False
31 readEval = readTime =
False
34 items = [word
for word
in line.split()]
37 if(items[0] ==
"Generation:"):
38 generation.append(int(items[1]))
40 if(
not readEval
and items[0] ==
"Evaluations:"):
41 eval.append(int(items[1]))
43 if(
not readTime
and items[0] ==
"Elapsed"):
44 time.append(int(items[2]))
46 if(
not readMax
and items[0] ==
"max:"):
47 max.append(float(items[1]))
49 if(
not readMin
and items[0] ==
"min:"):
50 min.append(float(items[1]))
52 if(
not readAvg
and items[0] ==
"avg:"):
53 avg.append(float(items[1]))
55 if(
not readStd
and items[0] ==
"stdev:"):
56 std.append(float(items[1]))
58 if(inGeneration
and readMax
and readMin
and readAvg
and readStd):
59 inGeneration = readMax = readMin = readAvg = readStd =
False
60 readEval = readTime =
False
64 self.
times.append(time)
65 self.
evals.append(eval)
76 def getPartialLog(self, percentage):
79 logNo = int((len(self.
generations[i]) - 1) * percentage);
81 stat.append(self.
mins[i][logNo])
82 stat.append(self.
maxs[i][logNo]);
83 stat.append(self.
avgs[i][logNo]);
85 stat.append(self.
evals[i][logNo]);
86 stat.append(self.
times[i][logNo]);
90 def getMean(self, values):
92 for i
in range(len(values)):
94 return sum / len(values)
97 def getStdDev(self, values):
102 for i
in range(len(values)):
103 numerator += ((values[i] - average) * (values[i] - average));
104 denominator = (len(values) - 1)
105 return math.sqrt(numerator / denominator)
108 def getMin(self, values):
110 for i
in range(len(values)):
116 def getMax(self, values):
118 for i
in range(len(values)):
124 def getMedian(self, values):
126 if len(values) % 2 == 0:
127 return (values[int(len(values) / 2) - 1] + values[int(len(values) / 2)]) / 2
129 return values[int(len(values) / 2)]
132def printStr(FloatNumber, Precision):
133 return "%0.*f" % (Precision, FloatNumber)
143outFile =
"convergence.txt";
149line = input(
" -- Log filename base (enter - \"" + logBase +
"\") : ")
153line = input(
" -- Starting log number (enter - " + str(logStartNum) +
") : ")
155 logStartNum = int(line)
157line = input(
" -- End log number (enter - read all): ")
159 logEndNum = int(line)
161line = input(
" -- Log filename num of digits (enter - 2) : ")
165line = input(
" -- Extension (enter - \"" + logExt +
"\") : ")
169line = input(
" -- Output file (enter - \"" + outFile +
"\") : ")
173line = input(
" -- Number of samples (enter - " + str(nSamples) +
") : ")
184 fileName += str(logNum).zfill(nDigits)
187 print(
"Log filename: ", fileName)
189 if path.exists(fileName):
192 rs.readLogFile(fileName)
194 print(
"File not found!")
198 if logEndNum >= logNum
or opened ==
True:
205vAvgMin, vAvgMax, vMedMin, vMedMax, vMaxMin, vMinMax, vMinMin, vMaxMax, vAvgAvg = ([]
for i
in range(9))
211while sample < nSamples:
212 percentage = 1. * sample / nSamples
213 stats = rs.getPartialLog(percentage)
220 for runId
in range(nRuns):
221 curr_min = stats[runId][0]
222 curr_max = stats[runId][1]
223 mins.append(stats[runId][0])
224 maxs.append(stats[runId][1])
225 avgs.append(stats[runId][2])
227 vAvgMin.append(rs.getMean(mins))
228 vAvgMax.append(rs.getMean(maxs))
229 vMedMin.append(rs.getMedian(mins))
230 vMedMax.append(rs.getMedian(maxs))
231 vMinMin.append(rs.getMin(mins))
232 vMaxMin.append(rs.getMax(mins))
233 vMinMax.append(rs.getMin(maxs))
234 vMaxMax.append(rs.getMax(maxs))
235 vAvgAvg.append(rs.getMean(avgs))
237 vGens.append(stats[0][3])
238 vEvals.append(stats[0][4])
242file = open(outFile,
"w")
243file.write(
"recId\tgen\teval\tmin_min\tavg_min\tmed_min\tmax_min\tmin_max\tavg_max\tmed_max\tmax_max\thits\tavg_avg\n")
244for sample
in range(nSamples):
245 output = str(sample) +
"\t" + str(vGens[sample]) +
"\t" + str(vEvals[sample]) +
"\t"
246 output += str(vMinMin[sample]) +
"\t" + str(vAvgMin[sample]) +
"\t" + str(vMedMin[sample]) +
"\t" + str(vMaxMin[sample]) +
"\t"
247 output += str(vMinMax[sample]) +
"\t" + str(vAvgMax[sample]) +
"\t" + str(vMedMax[sample]) +
"\t" + str(vMaxMax[sample]) +
"\t"
248 output += str(vHits[sample]) +
"\t" + str(vAvgAvg[sample]) +
"\n"