-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvm.py
More file actions
45 lines (32 loc) · 971 Bytes
/
svm.py
File metadata and controls
45 lines (32 loc) · 971 Bytes
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
#!/usr/bin/env python3
import z3
import glob
import pickle
import numpy as np
from brute_force import probe
from time import process_time
from sklearn.svm import SVC
STRATEGIES = [
#TO BE HARDCODED
]
def strategy_test(problem, strategy):
start = process_time()
g = z3.Goal()
g.add(z3.parse_smt2_file(problem))
t = z3.Then(*strategy)
result = t(g).as_expr()
end = process_time()
if result == z3.unknown:
return float('inf')
return end - start
def svm(problems, timeout, filename):
problems = glob.glob(PROBLEMS, recursive=True)
problems = random.sample(problems, TRAINING)
data = []
for problem in problems:
data.append(probe(problem))
labels = [np.argmax([-1 * strategy_test(problem, strategy) for strategy in STRATEGIES]) for problem in problems]
clf = SVC(gamma='auto')
clf.fit(np.array(data), np.array(labels))
with open(filename, "wb") as f:
pickle.dump(clf, f)