-
Notifications
You must be signed in to change notification settings - Fork 4
/
EET.py
73 lines (56 loc) · 2.2 KB
/
EET.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
#!/usr/bin/python
import argparse
import itertools
import re
def isect(a, b):
return a.intersection(b)
class exhaustive_test(object):
def __init__(self):
super(exhaustive_test, self).__init__()
def file_to_sets(self, compfile):
set_dict = {}
with open(compfile, 'r') as f:
for line in f:
line.strip
key, failset = line.replace(' ', '').split(';', 1)
try:
failset = list(map(int, failset.split(',')))
failset = set(failset)
except:
failset = set()
set_dict[key] = failset
return set_dict
def test_combinations(self, dictionary, runsPerTest=3, nRunFails=2):
sims = list(dictionary.keys())
passed = failed = 0
for compset in itertools.combinations(sims, runsPerTest):
# This block is slightly slower than manually
# specifying the pairs, but it generalizes
# easily.
failsets = [dictionary[s] for s in compset]
# The following three lines are adapted from
# user doug's answer in
# http://stackoverflow.com/questions/27369373/pairwise-set-intersection-in-python
pairs = itertools.combinations(failsets, 2)
isect_list = [isect(t[0], t[1]) for t in pairs]
isect_tot = set()
[isect_tot.update(x) for x in isect_list]
if len(isect_tot) > nRunFails:
# print statements for debugging
# print("this set failed")
# print(compset)
failed += 1
else:
# print("this set passed")
# print(compset)
passed += 1
return passed, failed
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='script to calculate all combinations of ensemble tests'
)
parser.add_argument('-f', dest='compfile', help='compfile location', metavar='PATH')
args = parser.parse_args()
eet = exhaustive_test()
compare_dict = eet.file_to_sets(args.compfile)
print(('failure percent is %s' % eet.test_combinations(compare_dict)))