Closed mac389 closed 3 years ago
line 13 and 14 are causing this, the Y
fails to ground. It works if you comment them out.
As to why it doesn't work for a probabilistic rule but it does for a deterministic one: for a deterministic rule you only need to find out one proof that makes the body (and hence the head) true. For a probabilistic rule you need all the proofs, all the ways a body can be true. For example, in
b(1).
b(2).
0.2::a :- b(X).
query(a).
the probability is 0.36 because it found b(1)
and b(2)
both can causea
to be true with some probability. When you find a probabilistic rule, you need to ground out the body and find all possible proofs: b(1) and b(2). In your example this means that in rule 5 and 6, it will try to use rule 13 and 14, unifies Z with Y and fails to ground it out. In case of a deterministic rule, you just need to find at least one proof, not all the possible proofs so grounding it out isn't required.
If you want to specify that person 1 is using all defined substances you can use property(1, use, Y) :- substance(Y).
as long as all substances are grounded out (but then don't use substance(Y).
as fact in your program).
Hope that helps.
for a deterministic rule you only need to find out one proof that makes the body (and hence the head) true. For a probabilistic rule you need all the proofs, all the ways a body can be true.
This explanation was very helpful. Thank you.
If you want to specify that person 1 is using all defined substances you can use property(1, use, Y) :- substance(Y). as long as all substances are grounded out (but then don't use substance(Y). as fact in your program).
How would I specify that person 1 is using at least one (i.e. any) substance?.
This should work. (I'm from the StackOverflow thread)
0.8::property(X,use,nicotine) :-
uses_atleast_one_substance(X).
uses_atleast_one_substance(X):-
property(X,use,Z),
substance(Z).
To continue on @krishnangovindraj 's reponse which encodes that if you use at least one substance, it increases the probability of nicotine usage.
If you have evidence that person 1 is using at least one substance, you can add evidence(uses_atleast_one_substance(1)).
For example:
substance(methadone).
substance(heroin).
% The probability of X using nicotine increases with each substance X uses.
%0.8::property(X,use,nicotine) :-
% property(X,use,Z),
% substance(Z).
% Indicates possibility of using nicotine if using at least one substance.
0.8::property(X,use,nicotine) :-
uses_atleast_one_substance(X).
% Indicates there is a probability for each substance that X is using it.
0.5::property(X,use,Z) :- substance(Z).
% Indicates X is using at least one substance.
uses_atleast_one_substance(X):-
property(X,use,Z),
substance(Z).
% Evidence that person 1 is using at least one substance.
evidence(uses_atleast_one_substance(1)).
% Query
query(property(1,use, nicotine)).
What explains the difference in behavior between the two versions of
property/3
? The probabilistic version does not seem to have the issues discussed in Problogs FAQs. I also posted this on StackOverflow