ML-KULeuven / problog

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

Testing Bayes #85

Closed rickshilling closed 2 years ago

rickshilling commented 2 years ago

% Running 0.3::h. 0.6::h:-e. % p(h|e) 0.7::e:-h. % p(e|h) query(e). % outputs .21.
% Yet isn't it really % p(e)=p(h)p(e|h)/p(h|e) % =(.3)(.7)/(.6) % =.35?
% What doesn't Problog divide by p(h|e)?

VincentDerk commented 2 years ago

Note that 0.6::h:-e. does NOT necessarily mean P(h|e) = 0.6. Specifically, when you have multiple non-mutually exclusive causes for h, then this does not hold. In your example you have both 0.3::h. and 0.6::h :- e, two non-mutually exclusive causes for h to become true.

To understand better the program you encoded, it may also be useful to realise that probabilistic clauses are syntactic sugar (see tutorial / ProbLog paper). So your example is equivalent to

0.3::h.
0.6::aux_1.
0.7::aux_2.
h:-e, aux_1.
e:-h, aux_2.

From this you can deduce all possible worlds, by assigning a truth value to each probabilistic fact and using the logical rules to derive the rest. The are 2^3 of them:

For each world you can compute its probability. E.g. P(h, aux_1, aux_2) = 0.3 0.6 0.7. To compute Probability(e), you sum up the probability for each world where e is true. This is equal to 0.21

If this is unclear, I highly recommend reading through the tutorial and the ProbLog paper.