ML-KULeuven / problog

ProbLog is a Probabilistic Logic Programming Language for logic programs with probabilities.
https://dtai.cs.kuleuven.be/problog/
297 stars 34 forks source link

unexpected outcome for "compiling-once, evaluate-many" recipe #70

Closed twugithub closed 2 years ago

twugithub commented 2 years ago

Hello, My name is Tong Wu. I followed the instruction at https://dtai.cs.kuleuven.be/problog/tutorial/python/01-compile-once.html for one experiment. But when I used the following code

""" from problog.program import PrologString from problog import get_evaluatable from problog.logic import Term, Constant from problog.evaluator import SemiringLogProbability

model = """ aa(2). 1.0::b(X) :- a(X). a(1). evidence(a(2), false). query(b(_)). """

Parse the Prolog string

pl_model = PrologString(model)

Compile the Prolog model into

knowledge = get_evaluatable().create_from(pl_model)

print(knowledge.evaluate())

auxi_indicator = Term('a', Constant('2'))

print(knowledge.evaluate(evidence={auxi_indicator : True})) """

to see how it works, I saw the result is always "{b(1): 1.0}". That said, the object "2" does not seem to be in the query list (of course we cannot understand whether the evidence a(2) has been switched). Could you please tell us why it is happening and is there any way to make it work? Thanks!

Best,

rmanhaeve commented 2 years ago

Just to be sure. is the aa(2). a type in your post here, or is it also a type in the code you tried?

twugithub commented 2 years ago

The purpose of adding "aa(2)" is to just create an object called "2". But please feel free to ignore this line as it does not affect the outcomes.

rmanhaeve commented 2 years ago

In ProbLog, we only consider the relevant ground program with respect to the query. Since only b(1) can be derived from the program, all other parts are discarded.

twugithub commented 2 years ago

We wanted to query all the objects related to b, and because b(2) can be derived from a(2), the result should include both b(1) and b(2). Initially we set a(2) to be false, and later we changed it to be true, but all these operations are ignored.

rmanhaeve commented 2 years ago

a(2) cannot be derived from the program currently. Consider this program instead:

aa(2).
1.0::b(X) :- a(X).
a(1).
%evidence(a(2), false).
query(b(_)).
0.5::a(2).