logic-and-learning-lab / Popper

An inductive logic programming system
MIT License
206 stars 36 forks source link

pi+rec - ancestor #69

Closed celinehocquette closed 1 year ago

celinehocquette commented 1 year ago

fix #68

yangdinglou commented 1 year ago

@celinehocquette Thank you. It helps but the PI is still not complete as far as I find. Here is one worked setting in Popper v1. I try making our project's backend upgraded, but no program are found in the current version.

%% bias.pl

% p(This, Sz) :- nullptr(This), zero(Sz).

% p(This) :- next(This, Nxt), p(Nxt), child(This, tail), q(tail).

% q(This) :- nullptr(This), zero(Sz).

% q(This) :- next(This, Nxt),value(This, n), nullptr(n), q(Nxt).

%learned:
% BEST PROG 13:
% p(A):-nullptr(A).
% p(A):-inv1(B),child(A,B),next(A,C),p(C).
% inv1(A):-nullptr(A).
% inv1(A):-value(A,B),is_value(B),next(A,C),inv1(C).
% Precision:1.00, Recall:1.00, TP:10, FN:0, TN:5, FP:0
max_vars(4).
max_body(4).
max_clauses(4).
enable_pi.
enable_recursion.

head_pred(p,1).
body_pred(next,2).
body_pred(child,2).
body_pred(value,2).
body_pred(nullptr,1).
% body_pred(node,1).
body_pred(is_value,1).

type(p,(element,)).
type(next,(element,element)).
type(child,(element,element)).
type(value,(element, int)).
type(nullptr,(element,)).
% type(node,(element,)).
type(is_value,(int,)).

direction(p,(in,)).
direction(next,(in,out)).
direction(child,(in,out)).
direction(value,(out,out)).
direction(nullptr,(out,)).
% direction(node,(in,)).
direction(is_value,(in,)).

:-
    not clause(1).
:-
    not clause(2).
:-
    not clause(3).

:-
    head_literal(0,P,_,_),
    not head_literal(1,P,_,_).

:-
    head_literal(1,P,_,_),
    head_literal(2,P,_,_).

:-
    head_literal(2,P,_,_),
    not head_literal(3,P,_,_).

:-
    #count{P,A,Vars : body_literal(P,p,A,Vars)} = 0.
:-
    #count{A,Vars : body_literal(1,next,A,Vars)} != 1.
:-
    #count{A,Vars : body_literal(1,child,A,Vars)} != 1.

:-
    head_literal(1,_,_,(Var1,)),
    not body_literal(1,next,_,(Var1,_)).
:-
    head_literal(1,_,_,(Var1,)),
    not body_literal(1,child,_,(Var1,_)).

:- 
    head_literal(2,P,_,_),
    body_literal(0,P,_,_).

:-
    #count{A,Vars : body_literal(3,next,A,Vars)} != 1.
:-
    #count{A,Vars : body_literal(3,value,A,Vars)} != 1.

:-
    head_literal(3,_,_,(Var1,)),
    not body_literal(3,next,_,(Var1,_)).
:-
    head_literal(3,_,_,(Var1,)),
    not body_literal(3,value,_,(Var1,_)).

:-
    #count{P,A,Vars : body_literal(P,child,A,Vars)} != 1.

:-
    #count{P,A,Vars : body_literal(P,next,A,Vars)} != 2.

:-
    #count{P,A,Vars : body_literal(P,value,A,Vars)} != 1.
%% bk.pl
node(p1).
node(p2).
node(p3).

next(p1, p2).
next(p2, p3).
next(p3, null).

child(p1, p11).
child(p2, p21).
child(p3, p31).

node(p11).
node(p12).
node(p13).
node(p21).
node(p22).
node(p31).
node(p32).
node(p33).

next(p11, p12).
next(p12, p13).
next(p13, null).
next(p21, p22).
next(p22, null).
next(p31, p32).
next(p32, p33).
next(p33, null).

value(p11, v).
value(p12, v).
value(p13, v).
value(p21, v).
value(p22, v).
value(p31, v).
value(p32, v).
value(p33, v).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
node(n1).
node(n2).
node(n3).

next(n1, n2).
next(n2, n3).
next(n3, null).

child(n1, n11).
child(n2, n21).
child(n3, n31).

node(n11).
node(n12).
node(n13).
node(n14).%
node(n21).
node(n22).
node(n31).
node(n32).
node(n33).
node(n33).

next(n11, n12).
next(n12, n13).
next(n13, n14).%
next(n21, n22).
next(n22, null).
next(n31, n32).
next(n32, n33).
next(n33, null).

value(n11, v).
value(n12, v).
value(n13, v).
value(n21, v).
value(n22, v).
value(n31, v).
value(n32, v).
value(n33, v).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
node(np1).
node(np2).
node(np3).

next(np1, np2).
next(np2, np3).
next(np3, null).

child(np1, np11).
child(np2, np21).
child(np3, np31).

node(np11).
node(np12).
node(np13).
node(np14).%
node(np21).
node(np22).
node(np31).
node(np32).
node(np33).

next(np11, np12).
next(np12, np13).
next(np13, null).
next(np21, np22).
next(np22, null).
next(np31, np32).
next(np32, np33).
next(np33, null).

value(np11, np14).%
value(np12, v).
value(np13, v).
value(np21, v).
value(np22, v).
value(np31, v).
value(np32, v).
value(np33, v).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
node(npp1).
node(npp2).
node(npp3).
node(npp4).%

next(npp1, npp2).
next(npp2, npp3).
next(npp3, npp4).%

child(npp1, npp11).
child(npp2, npp21).
child(npp3, npp31).

node(npp11).
node(npp12).
node(npp13).
node(npp21).
node(npp22).
node(npp31).
node(npp32).
node(npp33).

next(npp11, npp12).
next(npp12, npp13).
next(npp13, null).
next(npp21, npp22).
next(npp22, null).
next(npp31, npp32).
next(npp32, npp33).
next(npp33, null).

value(npp11, v).
value(npp12, v).
value(npp13, v).
value(npp21, v).
value(npp22, v).
value(npp31, v).
value(npp32, v).
value(npp33, v).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
node(pp1).
node(pp2).
node(pp3).

next(pp1, pp2).
next(pp2, pp3).
next(pp3, null).

child(pp1, null).
child(pp2, pp21).
child(pp3, pp31).

node(pp21).
node(pp22).
node(pp31).
node(pp32).
node(pp33).

next(pp21, pp22).
next(pp22, null).
next(pp31, pp32).
next(pp32, pp33).
next(pp33, null).

value(pp21, v).
value(pp22, v).
value(pp31, v).
value(pp32, v).
value(pp33, v).

nullptr(null).

is_value(v).
zero(0).
%% exs.pl

pos(p(p1)).
pos(p(p2)).
pos(p(p3)).

pos(p(pp1)).
pos(p(pp2)).
pos(p(pp3)).

pos(p(n2)).
pos(p(n3)).

pos(p(np2)).
pos(p(np3)).

neg(p(n1)).
neg(p(np1)).
neg(p(npp1)).
neg(p(npp2)).
neg(p(npp3)).
andrewcropper commented 1 year ago

@yangdinglou do you know what the intended program is? I used the fix from @celinehocquette and Popper learns this program:

inv1(A):- nullptr(A).
inv1(A):- value(A,B),next(A,C),is_value(B),inv1(C).
p(A):- nullptr(A).
p(A):- next(A,B),child(A,C),inv1(C),p(B).

Is this program incorrect?

yangdinglou commented 1 year ago

@andrewcropper Wow, that's exactly what I want. Sorry that I can't test now since my laptop was suddenly broken, but the problem should be from my side. I will feedback after fetch my laptop. Thank you!

andrewcropper commented 1 year ago

@yangdinglou no problem, it was a fix by @celinehocquette because I stupidly introduced a bug in previous commit. I hope it works when you pull the latest code.

Thanks

yangdinglou commented 1 year ago

Should be my fault, it works. Thank you @celinehocquette