-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistics_utilities.py
79 lines (51 loc) · 1.93 KB
/
statistics_utilities.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
import numpy as np
import csv
def distanceFrom(pos1,pos2):
return np.linalg.norm(np.array(pos1)-np.array(pos2))
def dumpTableToCsv(filename, table):
csv_file = open(filename,"w")
csv_writer = csv.writer(csv_file)
header_row = None
for row_name, data in table.items():
fieldnames = [""]
fieldnames.extend(sorted(data.keys()))
if header_row is None:
header_row = fieldnames
csv_writer.writerow(header_row)
assert (header_row == fieldnames), "Malformed table"
s = map(lambda x: x[1][0], sorted(data.items(), key=lambda x: x[0]))
row = [row_name]
row.extend(s)
csv_writer.writerow(row)
csv_file.close()
def configToText(config):
s = ",".join(map(lambda x: " ".join(map(str,x)),config))
return s.replace("_"," ")
def dumpTableToLatex(table):
print
print "Latex table"
headers = [""]
headers.extend(table.items()[0][1].keys())
print " & ".join(headers), "\\\\"
for row_name, data in table.items():
row = []
row.append(row_name)
row.extend(data.values())
row = map(str, row)
print " & ".join(row), "\\\\"
def findConfigs(algorithm, purge_common=False):
configs = set()
for trial in algorithm.listTrials():
conf = trial.getConfig()
configs.add(frozenset(conf.items()))
if purge_common:
common_fields = set(configs.pop())
for config in configs:
common_fields.intersection_update(set(config))
new_frozensets = set()
for config in configs:
new_config = set(config) - common_fields
new_frozensets.add(frozenset(new_config))
return new_frozensets
else:
return configs