Giter Site home page Giter Site logo

friguzzi / cplint Goto Github PK

View Code? Open in Web Editor NEW
63.0 11.0 13.0 37.74 MB

cplint is a suite of programs for reasoning with probabilistic logic programs

License: Other

Prolog 100.00%
probabilistic-programming logic-programming probabilistic-logic-programming machine-learning inductive-logic-programming prolog

cplint's Introduction

  • ๐ŸŽŠ I'm a big fan of Prolog, Haskell, Java, and Python.
  • ๐Ÿ”ญ Iโ€™m currently working on probabilistic logic programming and statistical relational artificial intelligence
  • ๐ŸŒฑ Iโ€™m currently learning Copilot

cplint's People

Contributors

arvssynd avatar damianoazzolini avatar ebellodi avatar friguzzi avatar giuseta avatar janwielemaker avatar nickf93 avatar pmoura avatar rzese avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cplint's Issues

Wrong erase/1

save_samples(M,G):-

This is surely not good, but not used in the tests. erase/1 takes a db ref. I think what is meant is

save_samples(M,G):-
  forall(retract(M:sampled(R,Sub,V),
         assertz(M:mem(G,R,Sub,V)))).

call predicates outside of lpad scope

Hi Fabrizio,

I started working with your packages recently. I use your package in my local system and would like to import my probabilistic program into my other codes.
The document and examples are well defined. However, I was wondering how I can query on facts that I define them into LPAD module. I tried to declare the predicates in the module but it seems it can not get any arguments. sth like :- begin_lpad (test2, [path/2, move/3]).
for example, if I want to use my module into other programs, I usually declare the predicates into its module:
:- module(test_cplint,
[
path/2,
move/3
]).

So, it seems that I cannot call the predicates which I defined neither between begin_lpad and end_lpad nor outside of its scope. What is your suggestion to overcome my problem?

PS. I found how I can use the probability outside of the module.

Errors in examples

After installing cplint with all dependencies, I can't perform a query within the examples without an error occurring.

Running 64bit SWI-Prolog 8.0.3 on Ubuntu 16.04

Example coin.pl:

?- prob(heads(coin), Prob).
ERROR: Undefined procedure: 'toss tabled'/3
ERROR: In:
ERROR:   [20] throw(error(existence_error(procedure,...),context(...,_10794)))
ERROR:   [18] heads(coin,1490548,_10822) at /media/psf/Home/Documents/HiWi/Prolog_Learning/cplint/prolog/examples/coin.pl:21
ERROR:   [17] '$goal0'(1490548,_10848) 1-st clause of '$goal0'/2 <no source>
ERROR:   [16] pita:get_node(user:'$goal0',1490548,_10882) at /home/parallels/lib/swipl/pack/cplint/prolog/pita.pl:703
ERROR:   [15] pita:get_p(user:'$goal0',1490548,_10922) at /home/parallels/lib/swipl/pack/cplint/prolog/pita.pl:665
ERROR:   [14] '$bags':findall_loop((heads(coin),_10970),pita:get_p(...,1490548,_10988),_10962,[]) at /usr/lib/swi-prolog/boot/bags.pl:98
ERROR:   [13] setup_call_catcher_cleanup('$bags':'$new_findall_bag','$bags':findall_loop(...,...,_11038,[]),_11016,'$bags':'$destroy_findall_bag') at /usr/lib/swi-prolog/boot/init.pl:468
ERROR:    [9] pita:prob_meta(user:heads(coin),_11078) at /home/parallels/lib/swipl/pack/cplint/prolog/pita.pl:244
ERROR:    [7] <user>
ERROR: 
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

Debug-Mode output:

ERROR: Undefined procedure: 'toss tabled'/3
ERROR: In:
ERROR:   [20] throw(error(existence_error(procedure,...),context(...,_15850)))
ERROR:   [19] '$tabling':start_tabling(user:heads(coin,1381968,_15900),user:'heads tabled'(coin,1381968,_15914),user:'$heads$1'(coin,1381968),_15886) at /usr/lib/swi-prolog/boot/tabling.pl:139
ERROR:   [18] heads(coin,1381968,_15954) at /media/psf/Home/Documents/HiWi/Prolog_Learning/cplint/prolog/examples/coin.pl:21
ERROR:   [17] '$goal1'(1381968,_15980) 1-st clause of '$goal1'/2 <no source>
ERROR:   [16] pita:get_node(user:'$goal1',1381968,_16014) at /home/parallels/lib/swipl/pack/cplint/prolog/pita.pl:703
ERROR:   [15] pita:get_p(user:'$goal1',1381968,_16054) at /home/parallels/lib/swipl/pack/cplint/prolog/pita.pl:665
ERROR:   [14] '$bags':findall_loop((heads(coin),_16102),pita:get_p(...,1381968,_16120),_16094,[]) at /usr/lib/swi-prolog/boot/bags.pl:98
ERROR:   [13] setup_call_catcher_cleanup('$bags':'$new_findall_bag','$bags':findall_loop(...,...,_16170,[]),_16148,'$bags':'$destroy_findall_bag') at /usr/lib/swi-prolog/boot/init.pl:468
ERROR:   [12] setup_call_cleanup('$bags':'$new_findall_bag','$bags':findall_loop(...,...,_16226,[]),'$bags':'$destroy_findall_bag') at /usr/lib/swi-prolog/boot/init.pl:473
ERROR:   [11] '$bags':findall((heads(coin),_16276),pita:get_p(...,1381968,_16294),_16268,[]) at /usr/lib/swi-prolog/boot/bags.pl:92
ERROR:   [10] '$bags':findall((heads(coin),_16334),pita:get_p(...,1381968,_16352),_16328) at /usr/lib/swi-prolog/boot/bags.pl:89
ERROR:    [9] pita:prob_meta(user:heads(coin),_16384) at /home/parallels/lib/swipl/pack/cplint/prolog/pita.pl:244
ERROR:    [8] pita:prob(user:heads(coin),_16426) at /home/parallels/lib/swipl/pack/cplint/prolog/pita.pl:502
ERROR:    [7] <user>

Thanks in advance!

Negative Probability Values and Probability Bounds

Negative probabilities should not be allowed:

-0.3::a.
?- prob(a,P).
P = -0.3

Also with flexible probabilities:

p(S,C,P):P:-
  P is (C - S) / C.
q:- p(1.5,1,_).
? prob(q,P).
P = -0.5

Moreover, with flexible probabilities it is possible to define a probability value > 1:

p(S,C,P):P:-
  P is (C - S) / C.
q:- p(5,1,_).
? prob(q,P).
P = -4

Error while getting graphical result

Hi,
I was working with conditional inference yesterday. I have realized that the prob_bar predicate cannot recognize anymore.
I remembered I could see the histogram of the probability in the web application cplint and also in my local machine.
How can I fix this problem?

Building warnings

Warning: bddem.c:1580:28: warning: '__builtin___sprintf_chk' may write a terminating nul past the end of the destination [-Wformat-overflow=]
Warning:        sprintf(numberVar,"%d",i);
Warning:                             ^
Warning: In file included from /usr/include/stdio.h:862:0,
Warning:                  from bddem.c:13:
Warning: /usr/include/bits/stdio2.h:33:10: note: '__builtin___sprintf_chk' output between 2 and 11 bytes into a destination of size 10
Warning:    return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
Warning:           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Warning:        __bos (__s), __fmt, __va_arg_pack ());
Warning:        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Warning: bddem.c:1583:28: warning: '__builtin___sprintf_chk' may write a terminating nul past the end of the destination [-Wformat-overflow=]
Warning:        sprintf(numberBit,"%d",b);
Warning:                             ^
Warning: In file included from /usr/include/stdio.h:862:0,
Warning:                  from bddem.c:13:
Warning: /usr/include/bits/stdio2.h:33:10: note: '__builtin___sprintf_chk' output between 2 and 11 bytes into a destination of size 10
Warning:    return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
Warning:           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Warning:        __bos (__s), __fmt, __va_arg_pack ());
Warning:        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Warning: In file included from /usr/include/assert.h:35:0,
Warning:                  from util/util.h:70,
Warning:                  from util/cpu_stats.c:66:
Warning: /usr/include/features.h:183:3: warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
Warning:  # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
Warning:    ^~~~~~~
Warning: cudd/cuddWindow.c: In function 'ddPermuteWindow3':
Warning: cudd/cuddWindow.c:386:18: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case BCA: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:                   ^
Warning: cudd/cuddWindow.c:387:5: note: here
Warning:      case CBA: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:387:18: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case CBA: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:                   ^
Warning: cudd/cuddWindow.c:388:5: note: here
Warning:      case ABC: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:390:18: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case BAC: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:                   ^
Warning: cudd/cuddWindow.c:391:5: note: here
Warning:      case CAB: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c: In function 'ddPermuteWindow4':
Warning: cudd/cuddWindow.c:759:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case DBCA: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:760:5: note: here
Warning:      case BDCA: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:760:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case BDCA: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:761:5: note: here
Warning:      case CDBA: if (!cuddSwapInPlace(table,w,x)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:761:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case CDBA: if (!cuddSwapInPlace(table,w,x)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:762:5: note: here
Warning:      case ADBC: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:762:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case ADBC: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:763:5: note: here
Warning:      case ABDC: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:763:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case ABDC: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:764:5: note: here
Warning:      case ACDB: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:766:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case DCBA: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:767:5: note: here
Warning:      case BCDA: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:767:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case BCDA: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:768:5: note: here
Warning:      case CBDA: if (!cuddSwapInPlace(table,w,x)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:772:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case DBAC: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:773:5: note: here
Warning:      case DCAB: if (!cuddSwapInPlace(table,w,x)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:773:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case DCAB: if (!cuddSwapInPlace(table,w,x)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:774:5: note: here
Warning:      case DACB: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:774:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case DACB: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:775:5: note: here
Warning:      case BACD: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:775:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case BACD: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:776:5: note: here
Warning:      case CABD: if (!cuddSwapInPlace(table,w,x)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:778:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case DABC: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:779:5: note: here
Warning:      case BADC: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:779:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case BADC: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:780:5: note: here
Warning:      case CADB: if (!cuddSwapInPlace(table,w,x)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:783:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case BDAC: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:784:5: note: here
Warning:      case CDAB: if (!cuddSwapInPlace(table,w,x)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:784:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case CDAB: if (!cuddSwapInPlace(table,w,x)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:785:5: note: here
Warning:      case ADCB: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:785:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case ADCB: if (!cuddSwapInPlace(table,y,z)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:786:5: note: here
Warning:      case ABCD: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:      ^~~~
Warning: cudd/cuddWindow.c:788:19: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:      case BCAD: if (!cuddSwapInPlace(table,x,y)) return(0);
Warning:                    ^
Warning: cudd/cuddWindow.c:789:5: note: here
Warning:      case CBAD: if (!cuddSwapInPlace(table,w,x)) return(0);
Warning:      ^~~~
Warning: dddmp/dddmp.h:238:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:    if ((expr) == 1) { \
Warning:       ^
Warning: dddmp/dddmpStoreCnf.c:599:7: note: in expansion of macro 'Dddmp_Warning'
Warning:        Dddmp_Warning (1, "Wrong DDDMP Store Mode. Force DDDMP_MODE_BEST.");
Warning:        ^~~~~~~~~~~~~
Warning: dddmp/dddmpStoreCnf.c:600:5: note: here
Warning:      case DDDMP_CNF_MODE_BEST:
Warning:      ^~~~
Warning: In file included from dddmp/dddmpInt.h:39:0,
Warning:                  from dddmp/dddmpStoreCnf.c:29:
Warning: dddmp/dddmp.h:238:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
Warning:    if ((expr) == 1) { \
Warning:       ^
Warning: dddmp/dddmpStoreCnf.c:645:7: note: in expansion of macro 'Dddmp_Warning'
Warning:        Dddmp_Warning (1, "Wrong DDDMP Store Mode. Force DDDMP_MODE_BEST.");
Warning:        ^~~~~~~~~~~~~
Warning: dddmp/dddmpStoreCnf.c:646:5: note: here
Warning:      case DDDMP_CNF_MODE_BEST:
Warning:      ^~~~

Missing definition of add_decision_var and compute_best_strategy

I just updated cplint using pack_upgrade(cplint) and pack_rebuild(cpling) to play with the new Dtproblog, but it seems that it's not complete.

$ swipl
?- pack_upgrade(cplint).
% Running "git fetch" in '/home/hakank/lib/swipl/pack/cplint'
% Package "cplint" is up-to-date
true.

?- pack_rebuild(cplint).
true.

Testing with prolog/examples/dt_rock_papers_scissors.pl

$ swipl dt_rock_paper_scissors.pl
In swipl:
?- dt_solve(Strategy,Value).
Warning: Undefined procedure: pita:add_decision_var/3
Warning: Undefined procedure: pita:add_decision_var/3
Warning: Undefined procedure: pita:add_decision_var/3
Warning: Undefined procedure: pita:compute_best_strategy/5
false.

Searching for the definitions of add_decision_var and compute_best_strategy find just the calls, not the predicate definition:

$ cd /home/hakank/lib/swipl/pack/cplint
$ git grep add_decision_var
prolog/pita.pl: add_decision_var(Env,R,V),

$ git grep compute_best_strategy
prolog/pita.pl: compute_best_strategy(Env,LBDD,LUtils,St,Cost),

Problems in pita.pl : yield bddem errors

Today I wanted to test some cplint programs on my local machine, e.g. the program from http://cplint.eu/p/urns_and_balls1.swinb , and got a lot of errors. (There's no such error when running the cplint.eu SWISH programs.)

$ swipl urns_and_balls.pl
"""
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:42:
Exported procedure bddem:add_abd_var/4 is not defined
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:42:
Exported procedure bddem:end_ex/1 is not defined
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:42:
Exported procedure bddem:init_em/1 is not defined
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:42:
Exported procedure bddem:add_var/4 is not defined
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:42:
Exported procedure bddem:init_ex/2 is not defined
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:42:
Exported procedure bddem:add_query_var/4 is not defined
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:42:
Exported procedure bddem:em/9 is not defined
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:42:
Exported procedure bddem:init/1 is not defined
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:42:
Exported procedure bddem:end_em/1 is not defined

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.18-18-g82c1e9564-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
"""

I have removed/installed both the cplint and dbdem package in swipl and got the same errors. Here's the log of the upgrades:
"""
?- pack_upgrade(cplint).
% Running "git fetch" in '/home/hakank/lib/swipl/pack/cplint'
% Package "cplint" is up-to-date
true.

?- pack_upgrade(bddem).
% Running "git fetch" in '/home/hakank/lib/swipl/pack/bddem'
% Package "bddem" is up-to-date
true.
"""

My SWI Prolog version is 7.7.18-18-g82c1e9564-DIRTY.

Best,

Hakan

Where to post examples, etc?

Hi Fabrizio,

Thanks for making cplint available for SWIPL. I was previously using ProbLog, but I really like having a similar library available for swipl. I was playing around with cplint, and did a little example which possibly others might like. But I wasn't sure where best to post it (the review of cplint on SWI had problems).

Anyway, here's my little example: Monte Hall in basically 4 lines of probability logic:

% Monte Hall for swi-prolog + cplint

:- use_module(library(pita)).
:- pita.
:- begin_lpad.

picked(car):1/3.
picked(goat):- \+ picked(car).

revealed(goat):- picked(_).

switch_gets(car):- picked(goat), revealed(goat).

:- end_lpad.

main:-
    prob(switch_gets(car),P),
    format('Probability that switching gets the car is ~2f',[P]).

Flexible probabilities with ProbLog syntax

Flexible probabilities does not work using the ProbLog syntax.
For example, the current program yields a wrong probability value (0.5) for the query smokes(1):

person(1).
person(2).
person(3).
friend_of(1,2,0.51).
friend_of(2,1,0.56).

0.5::fp(X) :- person(X).
smokes(X) :- fp(X).

P::influences(X,Y) :- friend_of(X,Y,P).
smokes(X) :- smokes(Y), influences(X,Y).

while, if the line with the flexible probability is rewritten as

influences(X,Y):P :- friend_of(X,Y,P).

the computed probability is correct (0.6275).
Tested on cplint on swish (online).

?:: operator

pita defines ?:: as an operator but if one uses it instead of ? :: dt_solve does not work.
I would remove ?:: as on operator

duel.pl in examples directory throws an error

The program examples/prolog/duel.pl in the cplint distribution throws the following error when running the latest Git version (4.5.0).

?- survives([a,b,c],a,0).

survives_round([a,b,c],[a,b,c],a,0,_7682)
best_strategy(a,[b,c],[a,b,c],0,_7700,_7702)
l1=[b,c]
survives_rest(a,[b,c],0,[a,b,c],b),shoot(a,b,[b,c],[a,b,c],0,[c],[a,c])
survives_round([c],[a,c],a,0,_8000)
best_strategy(c,[],[a,c],0,_8018,_8020)
l1=[a]
ERROR: Type error: `db_reference' expected, found `user:sampled(0,[0],0)' (a compound)
ERROR: In:
ERROR:   [27] erase(user:sampled(0,...,0))
ERROR:   [26] mcintyre:save_samples(user,survives_rest(c,[],0,[a|...],a)) at /home/hakank/lib/swipl/pack/cplint/prolog/mcintyre.pl:309
ERROR:   [25] mcintyre:mc_sample(user:survives_rest(c,[],0,...,a),5,_10360,_10362,_10364) at /home/hakank/lib/swipl/pack/cplint/prolog/mcintyre.pl:571
ERROR:   [24] mcintyre:mc_sample(user:survives_rest(c,[],0,...,a),5,_10416,[]) at /home/hakank/lib/swipl/pack/cplint/prolog/mcintyre.pl:544
ERROR:   [22] '__aux_maplist/3_ev_action+4'([a,sky],[_10492-a|_10488],c,[],0,[a,c]) at /home/hakank/cplint/cplint/prolog/examples/duel.pl:67
ERROR:   [21] best_strategy(c,[],[a,c],0,_10538,_10540) at /home/hakank/cplint/cplint/prolog/examples/duel.pl:73
ERROR:   [20] table best_strategy(c,[],[a|...],0,_10588,_10590) at /home/hakank/cplint/cplint/prolog/examples/duel.pl:115
ERROR:   [19] survives_round_bounded([c],[a,c],a,0,_10628) at /home/hakank/cplint/cplint/prolog/examples/duel.pl:58
ERROR:   [18] survives_rest(a,[b,c],0,[a,b|...],b) at /home/hakank/cplint/cplint/prolog/examples/duel.pl:93
ERROR:   [17] mcintyre:montecarlo(5,0,0,user:survives_rest(a,...,0,...,b),_10740,_10742) at /home/hakank/lib/swipl/pack/cplint/prolog/mcintyre.pl:415
ERROR:   [16] mcintyre:mc_sample(user:survives_rest(a,...,0,...,b),5,_10794,_10796,_10798) at /home/hakank/lib/swipl/pack/cplint/prolog/mcintyre.pl:572
ERROR:   [15] mcintyre:mc_sample(user:survives_rest(a,...,0,...,b),5,_10850,[]) at /home/hakank/lib/swipl/pack/cplint/prolog/mcintyre.pl:544
ERROR:   [13] '__aux_maplist/3_ev_action+4'([b,c|...],[_10926-b|_10922],a,[b,c],0,[a,b|...]) at /home/hakank/cplint/cplint/prolog/examples/duel.pl:67
ERROR:   [12] best_strategy(a,[b,c],[a,b|...],0,_10984,_10986) at /home/hakank/cplint/cplint/prolog/examples/duel.pl:73
ERROR:   [11] table best_strategy(a,[b|...],[a|...],0,_11046,_11048) at /home/hakank/cplint/cplint/prolog/examples/duel.pl:115
ERROR:   [10] survives_round([a,b|...],[a,b|...],a,0,_11092) at /home/hakank/cplint/cplint/prolog/examples/duel.pl:36
ERROR:    [9] survives([a,b|...],a,0) at /home/hakank/cplint/cplint/prolog/examples/duel.pl:27
ERROR:    [8] '$tabling':'$wfs_call'(user:survives(...,a,0),user:_11208) at /usr/lib/swi-prolog/boot/tabling.pl:675

I have ensured that bddem is updated and rebuilt.

The Swish version ( http://cplint.eu/p/duel_from_dist.pl ) also throws an error, though it's not the same:

No permission to call sandboxed `assertz(sampled(0,[_1372],_1368))'
Reachable from:
	  sample_head(0,[A],'e924829f-5ed4-4570-8488-c2631e727d10',[hit(A,a):0.3333333333333333,'':0.6666666666666667],0)
	  hit(A,B)
	  shoot(A,B,C,D,E,F,G)
	  survives_round(A,B,C,D,E)
	  survives(A,B,C)

Bug in negation

The following program gives wrong probability (1) for query tdm. Correct prob is 0.75
See also
http://cplint.eu/p/baco_pita.pl
http://cplint.eu/p/neg.pl
The latter is working

:- use_module(library(pita)).
:- if(current_predicate(use_rendering/1)).
:- use_rendering(c3).
:- use_rendering(graphviz).
:- use_rendering(table,[header(['Multivalued variable index','Rule index','Grounding substitution'])]).
:- endif.
:- pita.
:- begin_lpad.

interest(brian,politics):0.5;interest(brian,sports):0.5.
interest(cheryl,politics):0.5;interest(cheryl,sports):0.5.

has_topic(P,politics):-P=p1.

topic_match(Post, Commenter) :- 
    has_topic(Post, politics), 
    interest(Commenter, politics).


tm:-
    topic_match(p1,brian),
    topic_match(p1,cheryl).

tdm:-
    \+ topic_match(p1,brian).

tdm:-
    %topic_match(p1,brian),
    \+ topic_match(p1,cheryl).
:- end_lpad.

/** <examples>

?- prob(tm,P).
?- prob(tdm,P).
?- prob((tdm,interest(brian,Ib),interest(cheryl,Ic)),P).


*/

Expensive use of findall/3

The following goal is costly and a bad programming idiom:

findall(_,find_exp(GL,M),_),

This is reported by the Logtalk linter (git version) as:

*     Suspicious call: findall(A,find_exp(B,C),D) instead of find_exp(B,C),fail;true
*       while compiling object viterbi
*       in file /Users/pmoura/Downloads/cplint-master/prolog/viterbi.pl between lines 48-62

As suggested in the warning message, using instead a (find_exp(B,C),fail;true) goal is both clear and faster.

Problems with master branch

Updated to the latest master branch using swipl version 8.1.6:

?- pack_upgrade(cplint).
?- pack_rebuild(cplint).
?- pack_upgrade(bddem).
?- pack_build(bddem).

No problems so far.

However, now most models give some errors. Here's the result from the test suite:
?- [library(cplint_test/test)].
"""
Warning: /home/hakank/lib/swipl/pack/cplint/prolog/kbest.pl:539:
Warning: Local definition of kbest:average/2 overrides weak import from cplint_util
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/examples/lemur/mach.pl:71:
ERROR: assert/1: No permission to modify static procedure plunit_mach_lm:fold/2' ERROR: Defined at /home/hakank/lib/swipl/pack/cplint/prolog/examples/lemur/mach.pl:62 Warning: /home/hakank/lib/swipl/pack/cplint/prolog/examples/lemur/mach.pl:71: Warning: Goal (directive) failed: plunit_mach_lm:(fold(all,_3760),sample(10,_3760,_3824,_3846),assert(fold(rand_train,_3824)),assert(fold(rand_test,_3846))) ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/examples/lemur/registration.pl:166: ERROR: assert/1: No permission to modify static procedure plunit_registration_lm:fold/2'
ERROR: Defined at /home/hakank/lib/swipl/pack/cplint/prolog/examples/lemur/registration.pl:80
Warning: /home/hakank/lib/swipl/pack/cplint/prolog/examples/lemur/registration.pl:166:
Warning: Goal (directive) failed: plunit_registration_lm:(fold(all,_6886),sample(4,_6886,_6950,_6972),assert(fold(rand_train,_6950)),assert(fold(rand_test,_6972)))
cplint test suite. To run all tests run ?- test.
"""

And then
?- test.
"""
?- test.
% PL-Unit: coin prob(heads(coin),A),close_to(A,0.51).
% 209 inferences, 0.000 CPU in 0.000 seconds (100% CPU, 906815 Lips)
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/cplint_test/test_pita.pl:87:
test h_c: received error: reset/3: Undefined procedure: plunit_coin:'toss tabled'/3
(prob(heads(coin),A),bar(A,B)),close_to(A,0.51),is_dict(B).
% 199 inferences, 0.000 CPU in 0.000 seconds (100% CPU, 1633102 Lips)
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/cplint_test/test_pita.pl:89:
test h_c_b: received error: reset/3: Undefined procedure: plunit_coin:'toss tabled'/3
(prob(heads(coin),A),bar1(A,B)),close_to(A,0.51),is_dict(B).
% 199 inferences, 0.000 CPU in 0.000 seconds (100% CPU, 1906550 Lips)
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/cplint_test/test_pita.pl:91:
test h_c_b2: received error: reset/3: Undefined procedure: plunit_coin:'toss tabled'/3
....
"""

And here's the result of good old alarm.pl:
$ swipl alarm.pl
?- prob(alarm(t),Prob).
"""
ERROR: Undefined procedure: 'burg tabled'/3
ERROR: In:
ERROR: [34] 'burg tabled'(t,1547324,_11126)
ERROR: [33] reset(user:'burg tabled'(t,1547324,_11168),_11152,_11154) at /usr/lib/swi-prolog/boot/init.pl:400
ERROR: [32] '$tabling':moded_delim(user:burg(t,1547324,_11220),user:'$burg$1'(t,1547324),user:'burg tabled'(t,1547324,_11246),1559724,[]) at /usr/lib/swi-prolog/boot/tabling.pl:332
ERROR: [31] '$tabling':moded_activate(user:burg(t,1547324,_11300),user:'$burg$1'(t,1547324),_11280,user:'burg tabled'(t,1547324,_11326),(0x55f54c1f3110),1559724) at /usr/lib/swi-prolog/boot/tabling.pl:320
ERROR: [30] '$tabling':run_leader(user:burg(t,1547324,_11382),user:'$burg$1'(t,1547324),_11360,user:'burg tabled'(t,1547324,_11408),(0x55f54c1f3110),1559696,_11368) at /usr/lib/swi-prolog/boot/tabling.pl:301
ERROR: [29] setup_call_catcher_cleanup('$tabling':true,'$tabling':run_leader(...,...,_11458,...,(0x55f54c1f3110),1559696,_11466),_11436,'$tabling':finished_leader(_11476,1559696,...)) at /usr/lib/swi-prolog/boot/init.pl:468
ERROR: [28] '$tabling':start_tabling(user:burg(t,1547324,_11530),user:'burg tabled'(t,1547324,_11544),user:'$burg$1'(t,1547324),_11516) at /usr/lib/swi-prolog/boot/tabling.pl:269
ERROR: [27] burg(t,1547324,_11584) at /home/hakank/cplint/cplint/prolog/examples/alarm.pl:17
ERROR: [26] 'alarm tabled'(t,1547324,_11612) at /home/hakank/cplint/cplint/prolog/examples/alarm.pl:23
ERROR: [25] reset(user:'alarm tabled'(t,1547324,_11654),_11638,_11640) at /usr/lib/swi-prolog/boot/init.pl:400
ERROR: [24] '$tabling':moded_delim(user:alarm(t,1547324,_11706),user:'$alarm$1'(t,1547324),user:'alarm tabled'(t,1547324,_11732),1559308,[]) at /usr/lib/swi-prolog/boot/tabling.pl:332
ERROR: [23] '$tabling':moded_activate(user:alarm(t,1547324,_11786),user:'$alarm$1'(t,1547324),_11766,user:'alarm tabled'(t,1547324,_11812),(0x55f54c1f29f0),1559308) at /usr/lib/swi-prolog/boot/tabling.pl:320
ERROR: [22] '$tabling':run_leader(user:alarm(t,1547324,_11868),user:'$alarm$1'(t,1547324),_11846,user:'alarm tabled'(t,1547324,_11894),(0x55f54c1f29f0),1559260,_11854) at /usr/lib/swi-prolog/boot/tabling.pl:301
ERROR: [21] setup_call_catcher_cleanup('$tabling':true,'$tabling':run_leader(...,...,_11944,...,(0x55f54c1f29f0),1559260,_11952),_11922,'$tabling':finished_leader(_11962,1559260,...)) at /usr/lib/swi-prolog/boot/init.pl:468
ERROR: [20] '$tabling':start_tabling(user:alarm(t,1547324,_12016),user:'alarm tabled'(t,1547324,_12030),user:'$alarm$1'(t,1547324),_12002) at /usr/lib/swi-prolog/boot/tabling.pl:269
ERROR: [19] alarm(t,1547324,_12070) at /home/hakank/cplint/cplint/prolog/examples/alarm.pl:21
ERROR: [18] '$goal0'(1547324,_12096) 1-st clause of '$goal0'/2
ERROR: [17] pita:get_node(user:'$goal0',1547324,_12130) at /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:701
ERROR: [16] pita:get_p(user:'$goal0',1547324,_12170) at /home/hakank/lib/swipl/pack/cplint/prolog/pita.pl:663
ERROR: [15] '$bags':findall_loop((alarm(t),_12218),pita:get_p(...,1547324,_12236),_12210,[]) at /usr/lib/swi-prolog/boot/bags.pl:98
"""

Redundant (and costly) use of call/1

In the following line, the use of call/1 is redundant but also expensive:

call(\+ H),

An example illustrating the cost:

?- time(true).
% 1 inferences, 0.000 CPU in 0.000 seconds (50% CPU, 200000 Lips)
true.

?- time((between(1,1000000,N), \+ float(N), fail; true)).
% 2,999,999 inferences, 0.085 CPU in 0.085 seconds (100% CPU, 35381936 Lips)
true.

?- time((between(1,1000000,N), call(\+ float(N)), fail; true)).
% 2,999,999 inferences, 0.239 CPU in 0.239 seconds (100% CPU, 12562915 Lips)
true.

Same issue in the same file around line 162. The Logtalk linter reports this issues as:

*     Suspicious call: call(\+A) instead of \+A
*       while compiling object viterbi
*       in file /Users/pmoura/Downloads/cplint-master/prolog/viterbi.pl between lines 114-117
*     
*     Suspicious call: call(\+A) instead of \+A
*       while compiling object viterbi
*       in file /Users/pmoura/Downloads/cplint-master/prolog/viterbi.pl between lines 160-163

typo in mc_prob/3

The code reads

oprion(bar(Chart),Options,no),

I guess it should be option.

Error "Exported procedure pita:randomize/2 is not defined"

After updating my cplint version via SWI-Prolog (pack_upgrade(cplint)), the following error is thrown for a slipcover model when running from command line on my local machine.

"""
ERROR: /home/hakank/lib/swipl/pack/cplint/prolog/slipcover.pl:48:
Exported procedure pita:randomize/2 is not defined
"""

And then - after running induce([train],P) - the following is thrown:

"""
N. of target clauses 196

Initial theory
Warning: Undefined procedure: pita:randomize/2
Warning: However, there are definitions for:
Warning: pita:randomize/1
Warning: randomize/1
"""

Pascal distribution

I was testing thebitcoin_attack.pl example and noticed that the mean of pascal(X,10.0.3) and poisson(X,10*0.3/0.7) are about the same: about 4.3 (10*0.3/0.7 ~ 4.2857). For Poisson this is correct, but I wonder about the result of the Pascal distribution.

According to Mathematica's PascalDistribution (https://reference.wolfram.com/language/ref/PascalDistribution.html) the mean should be

Mean@PascalDistribution[10,0.3] 
-> 33.33

(n/p = 10/0.3 = 33.33). Also see the Wolfram One notebook for this: https://www.wolframcloud.com/obj/hakank/Published/pascal_dist_10_0.3

Here's a test of cplint's pascal distribution:

:- use_module(library(mcintyre)).

:- mc.

:- begin_lpad.

d(X) : pascal(X,10,0.3).

:- end_lpad.

/** <examples> 
  ?- mc_expectation(d(X),1000,X,E).
*/

Also at https://cplint.eu/p/Pascal%20distribution%20test.pl

The result is about 4.2.

Have I missed something regarding the Pascal distribution?

Errors when loading examples

This is after installing exactly as the readme suggests, no errors have occured there.
Running SWI 64bit, v7.6.4:

?- [coin].
ERROR: /home/alt/lib/swipl/pack/cplint/prolog/pita.pl:1386:25: Syntax error: Operator expected
ERROR: /home/alt/lib/swipl/pack/cplint/prolog/examples/coin.pl:21:
	No permission to modify static procedure `(;)/2'
	Defined at /usr/lib/swi-prolog/boot/init.pl:209
ERROR: /home/alt/lib/swipl/pack/cplint/prolog/examples/coin.pl:24:
	No permission to modify static procedure `(;)/2'
	Defined at /usr/lib/swi-prolog/boot/init.pl:209
ERROR: /home/alt/lib/swipl/pack/cplint/prolog/examples/coin.pl:27:
	No permission to modify static procedure `(;)/2'
	Defined at /usr/lib/swi-prolog/boot/init.pl:209

Apologies in advance if this should be due to my local installation, I have not much knowledge of prolog's ecosystem.

Bug in `mc_mh_sample/4`

With this program

:- use_module(library(mcintyre)).
:- mc.
:- begin_lpad.

0.7::a.
0.1::b.
0.2::c.

q:- a,b,c.
:- end_lpad.

and the query mc_mh_sample(q,b,10,Prob) I often get false as answer.
This also happens with a higher number (100,1000) of samples.

Strange error in mc for SWI-Prolog version 8.1.14

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, found user: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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.