author | blanchet |
Thu, 27 Dec 2012 10:01:40 +0100 | |
changeset 50619 | b958a94cf811 |
parent 50388 | a5b666e0c3c2 |
child 53100 | 1133b9e83f09 |
permissions | -rw-r--r-- |
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 |
|
50388 | 26 |
|
50220 | 27 |
def initializeModel(self,_trainData,dicts): |
28 |
""" |
|
29 |
Load predictions. |
|
50388 | 30 |
""" |
50220 | 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 |
|
50619
b958a94cf811
new version of MaSh, with theory-level reasoning
blanchet
parents:
50388
diff
changeset
|
40 |
IS.close() |
50388 | 41 |
|
50220 | 42 |
def update(self,dataPoint,features,dependencies): |
43 |
""" |
|
44 |
Updates the Model. |
|
45 |
""" |
|
46 |
# No Update needed since we assume that we got all predictions |
|
47 |
pass |
|
50388 | 48 |
|
49 |
||
50220 | 50 |
def predict(self,problemId): |
51 |
""" |
|
52 |
Return the saved predictions. |
|
53 |
""" |
|
50388 | 54 |
return self.predictions[problemId] |
55 |
||
50220 | 56 |
def save(self,fileName): |
57 |
OStream = open(fileName, 'wb') |
|
50388 | 58 |
dump((self.predictionFile,self.predictions),OStream) |
50220 | 59 |
OStream.close() |
50388 | 60 |
|
50220 | 61 |
def load(self,fileName): |
62 |
OStream = open(fileName, 'rb') |
|
50388 | 63 |
self.predictionFile,self.predictions = load(OStream) |
50220 | 64 |
OStream.close() |