def runCode(generator): cpcode = generator.generate(m) cc = CPCompiler() runmodel = cc.compileCode(cpcode,d) runmodel.iterations = 1000 result = runmodel.run() return result
def doLearn(model,data): cm = LinearCPLogicGenerator() cpcode = cm.generate(model) cc = CPCompiler() runmodel = cc.compileCode(cpcode,data) runmodel.iterations = 500 return runmodel.run()
# -*- coding: utf-8 -*- from semcplogic.dataset import Dataset from semcplogic.cpmodel import TableResultInterpreter from semcplogic.cpcompiler import CPCompiler, ProblogExample from semcplogic.problogresult import GnuplotDrawer import pprint #We use "breaks" because break is a reserved keyword in problog cpcode = """t(_) : breaks <-- throws(mary). t(_) : breaks <-- throws(john). t(_) : throws(mary) <-- true. t(_) : throws(john) <-- true. """.split("\n") cc = CPCompiler() data = [] #Two ideas that don't work #i = 0 #for i in xrange(i+1,i+1+23): # data.append(ProblogExample(i,"throws(mary),throws(john),breaks")) #for i in xrange(i+1,i+1+2): # data.append(ProblogExample(i,"throws(mary),throws(john)")) #for i in xrange(i+1,i+1+15): # data.append(ProblogExample(i,"throws(john),breaks")) #for i in xrange(i+1,i+1+10): # data.append(ProblogExample(i,"throws(john)")) #i = 0 #for i in xrange(i+1,i+1+23):
from semcplogic.model import ModelBuilder from semcplogic.cpmodel import NonLinearCPLogicGenerator,TableResultInterpreter from semcplogic.cpcompiler import CPCompiler from semcplogic.problogresult import GnuplotDrawer import pprint b = ModelBuilder() b.addNode("a") b.addNode("b",0,0) b.addNode("c",0,0) b.setInfluence("a","b",5) b.setInfluence("a","c",5) m = b.consume() m.nodes["c"].setLevels(["laag","middel","hoog"]) d = m.sample(100) d2 = d.discretise({"a":["laag","hoog"],"b":["laag","hoog"],"c":["laag","middel","hoog"]}) cm = NonLinearCPLogicGenerator() cpcode = cm.generate(m) cc = CPCompiler() runmodel = cc.compileCode(cpcode,d2) runmodel.iterations = 100 result = runmodel.run() g = GnuplotDrawer() g.draw(result) t = TableResultInterpreter() r = t.interprete(m,result.latest()) pprint.pprint(r)