forked from thelmuth/Clojush-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_selection_probability.py
executable file
·65 lines (44 loc) · 1.46 KB
/
csv_selection_probability.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
#!/usr/bin/python
import os
import re
from sys import maxint
# Set these before running:
#dir1 = "Results/lexicase-paper/selection-probs/lexicase/"
dir1 = "Results/lexicase-paper/selection-probs/tourney7/"
outputFilePrefix = "log"
outputFileSuffix = ".txt"
# Main area
def getLogSelections(outputDirectory):
i = 0
if outputDirectory[-1] != '/':
outputDirectory += '/'
dirList = os.listdir(outputDirectory)
runs_selections = []
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
read = False
selections = []
for line in f:
pattern = re.compile(r'(\d*),(\d*)')
match = re.match(pattern, line)
if line.startswith("rank,selections"):
read = True
elif match and read:
rank = match.group(1)
count = match.group(2)
selections.append(count)
elif read:
read = False
break
runs_selections.append(selections)
i += 1
return runs_selections
all_selections = getLogSelections(dir1)
for i in range(0,len(all_selections[0])):
s = "%d," % i
for selections in all_selections:
s += "%s," % selections[i]
print s[:-1]