Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making a Predicate/fact that depends on an inequality #92

Closed
rickshilling opened this issue Sep 29, 2022 · 2 comments
Closed

Making a Predicate/fact that depends on an inequality #92

rickshilling opened this issue Sep 29, 2022 · 2 comments

Comments

@rickshilling
Copy link

% Consider
.85::color(b1,purple); .15::color(b1,yellow).
.90::color(b2,purple); .10::color(b2,yellow).
.05::color(b3,purple); .95::color(b3,yellow).

% This computes that all balls are all the same color
same_color([],_).
same_color([Ball|Tail],Color) :- color(Ball,Color), same_color(Tail,Color).

query(same_color([b1,b2,b3],purple)). % Probability == 0.03825
query(same_color([b1,b2,b3],yellow)). % Probability == 0.01425

% How can I create a predicate majority_color(Group,Color) so that it
% compares the same-color probabailities so that
% query(majority_color([b1,b2,b3],purple)) with prob 1.0
% query(majority_color([b1,b2,b3],yellow)) with prob 0.0?

% I was trying
majority_color(G,purple) :- same_color(G,purple) > same_color(G,yellow).
majority_color(G,yellow) :- same_color(G,yellow) > same_color(G,purple).
query(majority_color([b1,b2,b3],purple)).
% but an error is reported:
% ArithmeticError: Error while evaluating '>'(same_color([b1, b2, b3],purple),same_color
% ([b1, b2, b3],yellow)): Unknown function 'same_color'/2 at 19:50.

@rmanhaeve
Copy link
Contributor

The probables of 2 atoms cannot be compared like that. This requires a meta-query, which is offered in ProbLog through the subquery(Goal,Probability) predicate. I've included an example below, is this what you wanted to do?

% Consider
.85::color(b1,purple); .15::color(b1,yellow).
.90::color(b2,purple); .10::color(b2,yellow).
.05::color(b3,purple); .95::color(b3,yellow).

% This computes that all balls are all the same color
same_color([],_).
same_color([Ball|Tail],Color) :- color(Ball,Color), same_color(Tail,Color).

query(same_color([b1,b2,b3],purple)). % Probability == 0.03825
query(same_color([b1,b2,b3],yellow)). % Probability == 0.01425

majority_color(G,X) :- 
    subquery(same_color(G,X),P1),
    subquery(same_color(G,Y),P2),
    X \== Y,
    P1 > P2.
query(majority_color([b1,b2,b3],purple)).
query(majority_color([b1,b2,b3],yellow)).

@rickshilling
Copy link
Author

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants