-
Notifications
You must be signed in to change notification settings - Fork 6
/
homology.py
executable file
·78 lines (54 loc) · 2.03 KB
/
homology.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
#!/usr/bin/python
import os
from sys import maxint
# Set these before running:
print_homology = True
outputDirectory = "Results/bench-prog-synth/replace-space-with-newline/parent-selection/lexicase/"
outputDirectory = "Results/bench-prog-synth/replace-space-with-newline/parent-selection/tourney-7/"
outputDirectory = "Results/bench-prog-synth/replace-space-with-newline/parent-selection/ifs-7/"
outputDirectory = "Results/bench-prog-synth/mirror-image/parent-selection/lexicase/"
outputDirectory = "Results/bench-prog-synth/mirror-image/parent-selection/tourney-7/"
outputDirectory = "Results/bench-prog-synth/mirror-image/parent-selection/ifs-7/"
outputFilePrefix = "log"
outputFileSuffix = ".txt"
# Main area
i = 0
def mean(nums):
if len(nums) <= 0:
return -1
return sum(nums) / float(len(nums))
if outputDirectory[-1] != '/':
outputDirectory += '/'
dirList = os.listdir(outputDirectory)
homology_list_per_gen = []
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)
gen = 0
done = False
for line in f:
if line.startswith(";; -*- Report"):
gen = int(line.split()[-1])
while len(homology_list_per_gen) <= gen:
homology_list_per_gen.append([])
if line.startswith("SUCCESS"):
done = "SUCCESS"
break
if line.startswith("FAILURE"):
done = "FAILURE"
break
if line.startswith("Average (sample 1)"):
homology = float(line.split()[-1])
homology_list_per_gen[gen].append(homology)
i += 1
print
print outputDirectory
if print_homology:
print
print "Mean of Average Edit Distance Each Generation Across Runs"
for gen_homology in homology_list_per_gen:
print "%0.3f" % (mean(gen_homology))