Structure Learning

Structure learning is not part of the ProbLog distribution but available as part of the ProbFOIL package. You can download the source code from the ProbFOIL repository or install it through pip install probfoil.

As an example you can define a set of predicates and a target to learn about family relations:

% Modes
mode(male(+)).
mode(parent(+,+)).
mode(parent(+,-)).
mode(parent(-,+)).

% Type definitions
base(parent(person,person)).
base(male(person)).
base(female(person)).
base(mother(person,person)).
base(grandmother(person,person)).
base(father(person,person)).
base(male_ancestor(person,person)).
base(female_ancestor(person,person)).

% Target
learn(grandmother/2).

% How to generate negative examples
example_mode(auto).

Next, data can be expressed as:

father(bart, stijn).
father(bart, pieter).
father(luc, soetkin).

mother(katleen, stijn).
mother(katleen, pieter).
mother(lieve, soetkin).

parent(bart,stijn).
parent(bart,pieter).
parent(luc,soetkin).

female(alice).
female(an).
female(esther).

male(bart).
male(etienne).
male(leon).

grandmother(esther,soetkin).
grandmother(esther,stijn).
grandmother(esther,pieter).
...

Finally, when feeding the settings and data to probfoil it returns a set of learned rules:

$ probfoil family.settings family.data
...
Candidates for iteration 4:
==================================
grandmother(A,B) :- parent(C,B), parent(A,C), parent(D,A) 0.503462603878
grandmother(A,B) :- parent(C,B), parent(A,C), parent(B,D) 0.457063711911
grandmother(A,B) :- parent(C,B), parent(A,C), male(C) 0.432528690146
grandmother(A,B) :- parent(C,B), parent(A,C), male(B) 0.432528690146
==================================
RULE LEARNED: grandmother(A,B) :- parent(C,B), parent(A,C), \+male(A) 1.0