Parameter Learning in cplint similar to ProbLog

I’m studying various Probabilistic Logic Programming (PLP) languages such as ProbLog and cplint. I mainly interested in using cplint as it has SWI-Prolog support. I’m trying to translate this parameter learning example from ProbLog to cplint.


t(_)::stress(X) :- person(X).
t(_)::influences(X,Y) :- person(X), person(Y).

smokes(X) :- stress(X).
smokes(X) :- friend(X,Y), influences(Y,X), smokes(Y).

person(1).
person(2).
person(3).
person(4).

friend(1,2).
friend(2,1).
friend(2,4).
friend(3,2).
friend(4,2).

evidence(smokes(2),false).
evidence(smokes(4),true).
evidence(influences(1,2),false).
evidence(influences(4,2),false).
evidence(influences(2,3),true).
evidence(stress(1),true).

In the above ProbLog program, the parameters of stress/1 and influences/2 are learned from the evidence.

After reading the cplit documentation, I translated the above program into the following:

:- use_module(library(slipcover)).

:- if(current_predicate(use_rendering/1)).
:- use_rendering(c3).
:- use_rendering(lpad).
:- endif.

:-sc.

:- begin_bg.

person(1).
person(2).
person(3).
person(4).

friend(1,2).
friend(2,1).
friend(2,4).
friend(3,2).
friend(4,2).

smokes(4).
influences(2,3).
stress(1).

smokes(X) :- stress(X).
smokes(X) :- friend(X,Y), influences(Y,X), smokes(Y).

:- end_bg.

:- begin_in.

stress(X):t(_) :- person(X).
influences(X,Y):t(_) :- person(X), person(Y).


:- end_in.

fold(train, [1, 2, 3, 4]).
fold(test, [5, 6]).

fold(all, F) :-
    fold(train, FTr),
    fold(test, FTe),
    append(FTr, FTe, F).

output(stress/1).
output(influences/2).

input_cw(person/1).
input_cw(friend/2).

modeh(*, stress(-obj)).
modeh(*, influences(-obj, -obj)).
modeb(*, person(-obj)).
modeb(*, friend(-obj, -obj)).

begin(model(1)).
neg(smokes(2)).
end(model(1)).

begin(model(2)).
smokes(4).
end(model(2)).

begin(model(3)).
neg(influences(1, 2)).
end(model(3)).

begin(model(4)).
neg(influences(4, 2)).
end(model(4)).

begin(model(5)).
influences(2, 3).
end(model(5)).

begin(model(6)).
stress(1).
end(model(6)).

Running induce_par([train],P),test(P,[test],LL,AUCROC,ROC,AUCPR,PR). on SWISH to start parameter learning throws the following error.

No permission to modify static procedure `smokes/2’
Defined at line 64
In:
[14] assertz((… :- true),_1856)
[13] slipcover:assert_all([(… :- true),…|…],‘5208b620-073d-40ba-b11a-f598d87c613a’,[_1940|_1942]) at /home/mlunife/.local/share/swi-prolog/pack/cplint/prolog/slipcover.pl:2157
[3] slipcover:induce_parameters([train],_1992) at /home/mlunife/.local/share/swi-prolog/pack/cplint/prolog/slipcover.pl:451
[2] slipcover:induce_par(‘<garbage_collected>’,_2052) at /home/mlunife/.local/share/swi-prolog/pack/cplint/prolog/slipcover.pl:434
[1] ‘’(‘<garbage_collected>’)
Note: some frames are missing due to last-call optimization.
Re-run your program in debug mode (:- debug.) to get more detail

The error is a bit odd because there is no smokes/2 but there is smokes/1. What am I doing wrong in the above cplint version? Any suggestions? Thanks.

You should also add input_cw(smokes/1). to suppress the error.
Then, your bg should be written as

:- begin_in.

stress(X):0.5 :- person(X).
influences(X,Y):0.5 :- person(X), person(Y).

:- end_in.

where 0.5 are the initial probabilities.
Then, ?- induce_par([train],P),test(P,[test],LL,AUCROC,ROC,AUCPR,PR).

1 Like

Thanks. Declaring input_cw(smokes/1) fixes the error.

One question I have is whether it is possible to use facts loaded into SWI-Prolog as background knowledge. If so, how? This is what I tried so far:

:- begin_bg.

consult('db.pl').

:- end_bg.

But the above doesn’t seem to work as the parameters aren’t learned. What I’m looking for generally is a way to decouple background knowledge declaration and metaexample interpretations into separate files. Even better if cplint can use facts already loaded in the top-level during learning. Is there a way to specify this?

EDIT

I’m able to separate the background knowledge and the model file by adding the :- begin_bg and :- end_bg directives to the db.pl instead of the file that defines the model.

If you are interested in parameter estimation in PLP settings, note that SWI also has pack pepl, which implements parameter estimation for stochastic logic programs using James Cussen’s Failure Adjusted Maximisation algorithm.

Hope it helps,

Nicos Angelopoulos