Commit 275af07d authored by Anze Vavpetic's avatar Anze Vavpetic

added essential algorithm parameters as widget parameters.

parent 227ff4a7
......@@ -28,6 +28,17 @@ class Aleph(object):
YAP = '/usr/local/bin/yap'
RULES_SUFFIX = 'Rules'
SCRIPT = 'run_aleph.pl'
ESSENTIAL_PARAMS = {
'depth' : 10,
'evalfn' : 'coverage',
'i' : 2,
'language' : 'inf',
'm' : 0.0,
'max_features' : 'inf',
'minpos' : 1,
'noise' : 0
}
def __init__(self, verbosity=logging.NOTSET):
"""
......
This diff is collapsed.
......@@ -12,9 +12,12 @@ def ilp_aleph(input_dict):
pos = input_dict['pos']
neg = input_dict['neg']
b = input_dict['b']
# Parse settings
# Parse settings provided via file
if settings:
aleph.settingsAsFacts(settings)
# Parse settings provided as parameters (these have higher priority)
for setting, def_val in Aleph.ESSENTIAL_PARAMS.items():
aleph.set(setting, input_dict.get(setting, def_val))
# Run aleph
theory = aleph.induce(mode, pos, neg, b)
return {'theory' : theory}
......@@ -30,6 +33,9 @@ def ilp_rsd(input_dict):
# Parse settings
if settings:
rsd.settingsAsFacts(settings)
# Parse settings provided as parameters (these have higher priority)
for setting, def_val in RSD.ESSENTIAL_PARAMS.items():
rsd.set(setting, input_dict.get(setting, def_val))
# Run rsd
features, arff, rules = rsd.induce(b, examples=examples, pos=pos, neg=neg, cn2sd=subgroups)
return {'features' : features, 'arff' : arff, 'rules' : rules}
......@@ -32,6 +32,14 @@ class RSD(object):
SCRIPTS = [CONSTRUCT, SAVE, SUBGROUPS]
ESSENTIAL_PARAMS = {
'clauselength' : 8,
'depth' : 4,
'negation' : 'none',
'min_coverage' : 1,
'filtering' : 'true'
}
def __init__(self, verbosity=logging.NOTSET):
"""
Creates an RSD object.
......
......@@ -5,6 +5,12 @@ Classes for handling DBContexts for ILP systems.
'''
class ILP_DBContext:
'''
Base class for converting between a given database context (selected tables, columns, etc)
to inputs acceptable by a specific ILP system.
If possible, all subclasses should use lazy selects by forwarding the DB connection.
'''
def __init__(self, dbcontext, settings={}):
self.db = dbcontext
self.connection = dbcontext.connection.connect()
......@@ -19,6 +25,9 @@ class ILP_DBContext:
return [cols for cols in self.cursor]
class RSD_DBContext(ILP_DBContext):
'''
Converts the database context to RSD inputs.
'''
def all_examples(self):
target = self.db.target_table
examples = self.rows(target, [self.db.target_att, self.db.pkeys[target]])
......@@ -81,6 +90,11 @@ class RSD_DBContext(ILP_DBContext):
return [':- set(%s,%s).' % (key,val) for key, val in self.settings.items()]
class Aleph_DBContext(ILP_DBContext):
'''
Converts the database context to Aleph inputs.
TODO.
'''
def positive_examples(self):
pass
def negative_examples(self):
......@@ -88,21 +102,23 @@ class Aleph_DBContext(ILP_DBContext):
def background_knowledge(self):
pass
from context import DBConnection, DBContext
context = DBContext(DBConnection('root','','localhost','test'))
context.target_table = 'trains'
context.target_att = 'direction'
if __name__ == '__main__':
from context import DBConnection, DBContext
context = DBContext(DBConnection('root','','localhost','test'))
context.target_table = 'trains'
context.target_att = 'direction'
rsd = RSD_DBContext(context)
ex, bk = rsd.all_examples(), rsd.background_knowledge()
print ex
print bk
rsd = RSD_DBContext(context)
ex, bk = rsd.all_examples(), rsd.background_knowledge()
print ex
print bk
f = open('trains_mysql.pl','w')
f.write(ex)
f.close()
f = open('trains_mysql.pl','w')
f.write(ex)
f.close()
f = open('trains_mysql.b','w')
f.write(bk)
f.close()
\ No newline at end of file
f = open('trains_mysql.b','w')
f.write(bk)
f.close()
\ No newline at end of file
......@@ -5,7 +5,7 @@ MySQL connectivity library.
'''
import mysql.connector as sql
from context import DBConnection, DBContext
from ilp_db_context import RSD_DBContext
from ilp_db_context import RSD_DBContext, Aleph_DBContext
def mysql_connect(input_dict):
user = str(input_dict['user'])
......@@ -26,4 +26,8 @@ def mysql_db_context_finished(postdata, input_dict, output_dict):
def mysql_rsd_converter(input_dict):
rsd = RSD_DBContext(input_dict['context'])
return {'examples' : rsd.all_examples(), 'bk' : rsd.background_knowledge()}
\ No newline at end of file
return {'examples' : rsd.all_examples(), 'bk' : rsd.background_knowledge()}
def mysql_aleph_converter(input_dict):
aleph = Aleph_DBContext(input_dict['context'])
return {'pos_examples' : aleph.positive_examples(), 'neg_examples' : aleph.negative_examples(), 'bk' : aleph.background_knowledge()}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment