Last active
August 29, 2018 15:51
-
-
Save kaivalyar/98ea2e31d1d6056d5dbff76a2146846e to your computer and use it in GitHub Desktop.
PracMLN full system test (for Logic module)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PYTHONPATH="${PYTHONPATH}:/home/kaivalya/ ... /PracMLN/python3/" | |
source ~/.prac3/bin/activate | |
python3 test.py | |
deactivate | |
PYTHONPATH="" | |
source ~/p3/bin/activate | |
python3 test.py | |
deactivate | |
PYTHONPATH="${PYTHONPATH}:/home/kaivalya/ ... /PracMLN/python3/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Created on Oct 28, 2015 | |
@author: nyga | |
""" | |
import os | |
from pracmln import MLN, Database | |
from pracmln import query, learn | |
from pracmln.mlnlearn import EVIDENCE_PREDS | |
import time | |
from pracmln.utils import locs | |
def test_inference_smokers(): | |
p = os.path.join(locs.examples, 'smokers', 'smokers.pracmln') | |
mln = MLN(mlnfile=('%s:wts.pybpll.smoking-train-smoking.mln' % p), | |
grammar='StandardGrammar') | |
db = Database(mln, dbfile='%s:smoking-test-smaller.db' % p) | |
for method in ('EnumerationAsk', | |
#'MC-SAT', | |
#'WCSPInference', | |
#'GibbsSampler' | |
): | |
for multicore in (False, True): | |
print('=== INFERENCE TEST:', method, '===') | |
query(queries='Cancer,Smokes,Friends', | |
method=method, | |
mln=mln, | |
db=db, | |
verbose=False, | |
multicore=multicore).run() | |
def test_inference_taxonomies(): | |
p = os.path.join(locs.examples, 'taxonomies', 'taxonomies.pracmln') | |
mln = MLN(mlnfile=('%s:wts.learned.taxonomy.mln' % p), | |
grammar='PRACGrammar', | |
logic='FuzzyLogic') | |
db = Database(mln, dbfile='%s:evidence.db' % p) | |
for method in ('EnumerationAsk',):# 'WCSPInference'): | |
print('=== INFERENCE TEST:', method, '===') | |
query(queries='has_sense, action_role', | |
method=method, | |
mln=mln, | |
db=db, | |
verbose=False, | |
cw=True).run().write() | |
def test_learning_smokers(): | |
p = os.path.join(locs.examples, 'smokers', 'smokers.pracmln') | |
mln = MLN(mlnfile=('%s:smoking.mln' % p), grammar='StandardGrammar') | |
mln.write() | |
db = Database(mln, dbfile='%s:smoking-train.db' % p) | |
for method in ('BPLL', 'BPLL_CG', 'CLL'): | |
for multicore in (True, False): | |
print('=== LEARNING TEST:', method, '===') | |
learn(method=method, | |
mln=mln, | |
db=db, | |
verbose=False, | |
multicore=multicore).run() | |
def test_learning_taxonomies(): | |
p = os.path.join(locs.examples, 'taxonomies', 'taxonomies.pracmln') | |
mln = MLN(mlnfile=('%s:senses_and_roles.mln' % p), grammar='PRACGrammar') | |
mln.write() | |
dbs = Database.load(mln, dbfiles='%s:training.db' % p) | |
for method in ('DPLL', 'DBPLL_CG', 'DCLL'): | |
for multicore in (True, False): | |
print('=== LEARNING TEST:', method, '===') | |
learn(method=method, | |
mln=mln, | |
db=dbs, | |
verbose=False, | |
multicore=multicore, | |
epreds='is_a', | |
discr_preds=EVIDENCE_PREDS).run() | |
def runall(): | |
start = time.time() | |
print("Start Smoker Inference") | |
test_inference_smokers() | |
print("Finish Smoker Inference") | |
print("Start Taxonomy Inference") | |
test_inference_taxonomies() | |
print("Finish Taxonomy Inference") | |
print("Start Smoker Learning") | |
test_learning_smokers() | |
print("Finish Smoker Learning") | |
print("Start Taxonomy Learning") | |
test_learning_taxonomies() | |
print("Finish Taxonomy Learning") | |
print() | |
print('all test finished after', time.time() - start, 'secs') | |
def main(): | |
print("PracMLN Generic Systems Test:\n") | |
runall() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment