Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
623 views
in Technique[技术] by (71.8m points)

prolog - Why does this give a NonGroundProbabilisticClause error, but not the deterministic counterpart?

I want the program to represent that if person 1 uses one out of a particular list of substances then there is an 80% chance that person uses nicotine.

As in the example below, I have defined substance/1 to be true only for a few atoms.

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.

substance(methadone). 
substance(heroin).

P::property(X,use,nicotine) :-  %gives  NonGroundProbabilisticClause error
    property(X,use,Z),
    substance(Z),
    P is 0.8.

property(X,use,nicotine) :-  %appropriately infers nicotine use
    property(X,use,Z),
    substance(Z).
    
person(1).
substance(Y).
property(1, use, Y).

query(property(1,use, nicotine)).

Update

Discussion with @2bigpips brings out a related issue. Assigning a probability at the head of a probabilistic clause doesn't mean that you are clamping the probability at that value. This is important to realize if you are linking the probabilities to estimated quantities, for example, from experiments.

question from:https://stackoverflow.com/questions/65865561/why-does-this-give-a-nongroundprobabilisticclause-error-but-not-the-determinist

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Short answer: Deterministic clauses and probabilistic clauses have different semantics. Long answer in part 2.

Part 1: What your program means

substance(Y).        % means everything is a substance.
property(1, use, Y). % means: 1 uses everything (whatever 1 is)

As indicated in Paulo's answer to your previous question, the scope of the variable is limited to the clause. The Y in these facts are not the same variable. From a logic perspective, you have 2 separate clauses:

(forall Y: substance(Y))
 (forall Z: person(1, use, Z))

His suggestion will work and means person 1 uses all substances. substance(methadone). substance(heroin).

substance(methadone). 
substance(heroin).


0.8::property(X,use,nicotine) :-  %gives  NonGroundProbabilisticClause error
    property(X,use,Z),
    substance(Z).

% person(1).
% property(1, use, Y):- substance(Y). % person1 uses all substances

query(property(1,use, nicotine)).
% property(1,use,nicotine):       0.96

EDIT after seeing what you meant Since you want it to be 0.8 whether uses 1 or many substances, you can just do this:

argument-in-prolog-using-a-series-of-facts
substance(methadone). 
substance(heroin).

0.8::property(X,use,nicotine) :- 
    uses_atleast_one_substance(X).

uses_atleast_one_substance(X):-
    property(X,use,Z),
    substance(Z).


person(1).
property(1, use, Y):- substance(Y).

query(property(1,use, nicotine)).

Part 2: What's happening

I have to make a guess here: The non-probabilistic clause may work because it's non-probabilistic and hence not an annotated-disjunction. It may have prolog-like semantics.

Probabilistic clauses follow the semantics of annotated disjunctions. Every probabilistic clause is implicitly an annotated disjunction - p::head:- body. is p::head ; (1-p)not_head:- body.

Here's a paper with the semantics of "Logic Programs with Annotated Disjunctions". It says every grounding of the body independently causes the head to be true with the specified probability.

With that in mind, The reason you're getting the error is because there is indeed a non-ground BODY in the proof.

P::property(X,use,nicotine) :-  %gives  NonGroundProbabilisticClause error
    property(X,use,W), % This can unify with person(1,use,Z), leaving Z free
    substance(Z),      % This can unify with substance(Y), leaving Z free
    P is 0.8.

You can't have variables in the body because you don't know how many causes there are. It breaks the semantics and problog detects it and throws an error. That's what's happening.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...