-
Notifications
You must be signed in to change notification settings - Fork 6
/
csv_homology.py
executable file
·96 lines (68 loc) · 3.01 KB
/
csv_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python
import os
from sys import maxint
# Set these before running:
######## 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/")]
######## For EHC paper
dirs = [("standard", "Results/bench-prog-synth/vector-average/ehc-experiments/tourney/standard/"),
("standardHalfSilenced", "Results/bench-prog-synth/vector-average/ehc-experiments/tourney/standard-half-silenced/" ),
("ESM", "Results/bench-prog-synth/vector-average/ehc-experiments/tourney/epigenetic-silence-mutation/"),
("EHC", "Results/bench-prog-synth/vector-average/ehc-experiments/tourney/EHC/")]
outputFilePrefix = "log"
outputFileSuffix = ".txt"
# Main area
def mean(nums):
if len(nums) <= 0:
return -1
return sum(nums) / float(len(nums))
max_gen = 0
def getHomologies(outputDirectory):
global max_gen
i = 0
if outputDirectory[-1] != '/':
outputDirectory += '/'
dirList = os.listdir(outputDirectory)
homology_list_per_gen = []
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 = 0
done = False
for line in f:
if line.startswith(";; -*- Report"):
gen = int(line.split()[-1])
if gen > max_gen:
max_gen = gen
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: "):
homology = float(line.split()[-1])
homology_list_per_gen[gen].append(homology)
if line.startswith("Standard deviation: "):
a = 5
i += 1
return [mean(x) for x in homology_list_per_gen]
print "generation," + str([n for (n,d) in dirs]).replace(" ","").replace("]","").replace("[","").replace("'","")
dir_homology_lists = [getHomologies(d) for (n,d) in dirs]
for g in range(max_gen+1):
out_str = str(g) + ","
for homology_list in dir_homology_lists:
try:
homology = "%0.3f," % homology_list[g]
except:
homology = ","
out_str += homology
print out_str[:-1]