friguzzi / cplint

cplint is a suite of programs for reasoning with probabilistic logic programs
Other
67 stars 14 forks source link

Strange error in mc for SWI-Prolog version 8.1.14 #30

Closed hakank closed 4 years ago

hakank commented 4 years ago

The following model (also here: http://cplint.eu/p/strange_error_in_mc_for_swipl_8_1_14.pl ) returns a strange error in SWI-Prolog version 8.1.14 (on Linux Ubuntu 18.04.03LTS) and is installed using apt's PPA.

 :- use_module(library(lists)).
 :- use_module(library(mcintyre)).

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

 :- mc.
 :- begin_lpad.

 gender(male).
 gender(female).

height(H,male):gaussian(H,180,8) :- gender(male).
height(H,female):gaussian(H,170,6) :- gender(female).

is_long(H,Gender) :- Gender = male, height(H,Gender), H >= 180.
is_long(H,Gender) :- Gender = female, height(H,Gender), H >= 170.

:- end_lpad.

(Yes, it's a silly program. :-) )

Running this query the first time in the SWI-Prolog shell version 8.1.14

?- mc_sample(is_long(H,G),10,[G,H],V).

it returns false.

However, running the query a second next time (in the same shell session) it throws the following: """ ERROR: Type error: db_reference' expected, founduser:sampled(0,[],182.02406802989248)' (a compound) ERROR: In: ERROR: [13] erase(user:sampled(0,[],182.02406802989248)) ERROR: [12] mcintyre:save_samples(user,is_long(A,B)) at /home/hakank/lib/swipl/pack/cplint/prolog/mcintyre.pl:309 ERROR: [11] mcintyre:mc_sample(user:is_long(_8908,_8910),10,_8894,_8896,[_8914,_8920]) at /home/hakank/lib/swipl/pack/cplint/prolog/mcintyre.pl:571 ERROR: [10] mcintyre:mc_sample(user:is_long(_8968,_8970),10,[_8974,_8980],[successes(_8992),...|_8998]) at /home/hakank/lib/swipl/pack/cplint/prolog/mcintyre.pl:544 ERROR: [9] Exception: (12) mcintyre:save_samples(user, is_long(A, B)) ? creep """

The SWI-Prolog version running the SWISH server (version 8.1.8-36-g91fd6bda8) don't have this problem, it returns false every time.

I have updated all the relevant libraries:

?- pack_upgrade(cplint).
?- pack_rebuild(cplint).
?- pack_upgrade(bddem).
?- pack_rebuild(bddem).
?- pack_upgrade(matrix).
?- pack_rebuild(matrix).
?- pack_upgrade(auc).
?- pack_rebuild(auc).
friguzzi commented 4 years ago

The reason is that mc_sample/4 has this signature

mc_sample(:Query:atom,+Samples:int,-Probability:float, Options:list) is det

so you are passing [H,V]for the probability. You should use

mc_sample_arg(is_long(H,G),10,[G,H],V).
hakank commented 4 years ago

Thanks for identifying why the query is false.

But why is there an error when running the query the second time?

friguzzi commented 4 years ago

Because the query asserts stuff in the database, if it fails midway it does not remove the temporary asserted stuff as it would if completed

hakank commented 4 years ago

Ah, OK now I understand.

Thanks.