-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
157 lines (122 loc) · 4.29 KB
/
example.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import os
import random
import math
from scipy import stats
root = os.path.dirname(os.path.realpath(__file__))
# generate n random numbers for sampling
def get_random(rcount_, total_):
def gen_random():
while True:
yield random.randrange(1, total_ + 1, 1)
def gen_n_unique(source, n__):
seen = set()
seenadd = seen.add
for i in (i for i in source() if i not in seen and not seenadd(i)):
yield i
if len(seen) == n__:
break
return [i for i in gen_n_unique(gen_random, min(rcount_, int(total_)))]
def num_features_smarch(samplefile_, n_):
_configs = list()
if os.path.exists(samplefile_):
with open(samplefile_, "r") as sf:
for line in sf:
raw = line.split(',')
config = raw[:len(raw) - 1]
_configs.append(config)
else:
return -1
_samples = list()
if n_ < 0:
_samples = _configs.copy()
else:
rands = get_random(n_, len(_configs))
for r in rands:
_samples.append(_configs[r - 1])
_fnums = list()
for sample in _samples:
fnum = 0
for v in sample:
if not v.startswith('-'):
fnum += 1
_fnums.append(fnum)
if n_ < 0:
avg = stats.tmean(_fnums)
std = stats.tstd(_fnums)
return avg, std
return stats.tmean(_fnums), stats.tstd(_fnums)
def num_features_DDbS(samplefile_, n_):
_configs = list()
init = True
if os.path.exists(samplefile_):
with open(samplefile_, 'r') as sf:
for line in sf:
if not init:
raw = line.split(";")
if len(raw) != 0:
raw = raw[1:]
config = list()
for i in range(0, len(raw)):
if raw[i] == '1':
config.append(i + 1)
_configs.append(config)
else:
init = False
else:
return -1
_fnums = list()
for sample in _configs:
fnum = 0
for v in sample:
if v > 0:
fnum += 1
_fnums.append(fnum)
return stats.tmean(_fnums), stats.tstd(_fnums)
def num_features_QS(samplefile_, n_):
i = 0
_configs = list()
if os.path.exists(samplefile_):
with open(samplefile_, 'r') as sf:
for line in sf:
raw = line.split(" ")
if len(raw) != 0:
config = raw[:len(raw) - 1]
_configs.append(config)
i += 1
else:
return -1
_samples = list()
rands = get_random(n_, len(_configs))
for r in rands:
_samples.append(_configs[r - 1])
_fnums = list()
for sample in _samples:
fnum = 0
for v in sample:
if not v.startswith('-'):
fnum += 1
_fnums.append(fnum)
return stats.tmean(_fnums), stats.tstd(_fnums)
if __name__ == "__main__":
targets = ("VP9", "JHipster") # , "toybox_0_7_5", "pati", "busybox_1_28_0")
repdir = os.path.dirname(os.path.realpath(__file__)) + "/Replication"
for target in targets:
print(target)
samplefile = root + "/Samples/enumeration/" + target + ".samples"
avg, std = num_features_smarch(samplefile, -1)
for n in (100, 200, 300, 400, 500, 600, 700, 800, 900, 1000):
print(str(n) + "," + str(avg), end=",")
low = avg - (1.96 * (std / math.sqrt(n)))
high = avg + (1.96 * (std / math.sqrt(n)))
print(str(low), end=",")
print(str(high), end=",")
samplefile = repdir + "/DbS/Samples_ex/" + target + "_" + str(n) + ".csv"
davg, dstd = num_features_DDbS(samplefile, n)
samplefile = repdir + "/QuickSampler/Samples_ex/" + target + ".dimacs.samples.valid"
qavg, qstd = num_features_QS(samplefile, n)
samplefile = root + "/Samples/smarch_opt/" + target + "_1000.samples"
savg, sstd = num_features_smarch(samplefile, n)
print(str(davg) + "," + str(qavg) + "," + str(savg), end=",")
print(str(dstd) + "," + str(qstd) + "," + str(sstd), end=",")
print()
print()