50222
|
1 |
# Title: HOL/Tools/Sledgehammer/MaSh/src/predefined.py
|
|
2 |
# Author: Daniel Kuehlwein, ICIS, Radboud University Nijmegen
|
|
3 |
# Copyright 2012
|
|
4 |
#
|
|
5 |
# A classifier that uses the Meng-Paulson predictions.
|
|
6 |
|
50220
|
7 |
'''
|
|
8 |
Created on Jul 11, 2012
|
|
9 |
|
|
10 |
@author: Daniel Kuehlwein
|
|
11 |
'''
|
|
12 |
|
|
13 |
from cPickle import dump,load
|
|
14 |
|
|
15 |
class Predefined(object):
|
|
16 |
'''
|
|
17 |
A classifier that uses the Meng-Paulson predictions.
|
|
18 |
Only used to easily compare statistics between the old Sledgehammer algorithm and the new machine learning ones.
|
|
19 |
'''
|
|
20 |
|
|
21 |
def __init__(self,mpPredictionFile):
|
|
22 |
'''
|
|
23 |
Constructor
|
|
24 |
'''
|
|
25 |
self.predictionFile = mpPredictionFile
|
|
26 |
|
|
27 |
def initializeModel(self,_trainData,dicts):
|
|
28 |
"""
|
|
29 |
Load predictions.
|
|
30 |
"""
|
|
31 |
self.predictions = {}
|
|
32 |
IS = open(self.predictionFile,'r')
|
|
33 |
for line in IS:
|
|
34 |
line = line.split(':')
|
|
35 |
name = line[0].strip()
|
|
36 |
predId = dicts.get_name_id(name)
|
|
37 |
line = line[1].split()
|
|
38 |
preds = [dicts.get_name_id(x.strip())for x in line]
|
|
39 |
self.predictions[predId] = preds
|
|
40 |
IS.close()
|
|
41 |
return dicts
|
|
42 |
|
|
43 |
def update(self,dataPoint,features,dependencies):
|
|
44 |
"""
|
|
45 |
Updates the Model.
|
|
46 |
"""
|
|
47 |
# No Update needed since we assume that we got all predictions
|
|
48 |
pass
|
|
49 |
|
|
50 |
|
|
51 |
def predict(self,problemId):
|
|
52 |
"""
|
|
53 |
Return the saved predictions.
|
|
54 |
"""
|
|
55 |
return self.predictions[problemId]
|
|
56 |
|
|
57 |
def save(self,fileName):
|
|
58 |
OStream = open(fileName, 'wb')
|
|
59 |
dump((self.predictionFile,self.predictions),OStream)
|
|
60 |
OStream.close()
|
|
61 |
|
|
62 |
def load(self,fileName):
|
|
63 |
OStream = open(fileName, 'rb')
|
|
64 |
self.predictionFile,self.predictions = load(OStream)
|
|
65 |
OStream.close()
|
|
66 |
|