Merge branch 'master' of https://github.com/tacgomes/yap6.3
Conflicts: packages/CLPBN/clpbn/horus.yap
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
|
||||
%conservative_city(nyc, t).
|
||||
|
||||
hair_color(joe, t).
|
||||
|
||||
car_color(joe, t).
|
||||
|
||||
shoe_size(joe, f).
|
||||
|
||||
/* Steps:
|
||||
|
||||
1. generate N facts lives(I, nyc), 0 <= I < N.
|
||||
|
||||
2. generate evidence on descn for N people, *** except for 1 ***
|
||||
|
||||
3. Run query ?- guilty(joe, Guilty), witness(joe, t), descn(2,t), descn(3, f), descn(4, f).
|
||||
|
||||
query(Guilty) :-
|
||||
guilty(joe, Guilty),
|
||||
witness(joe, t),
|
||||
descn(2,t),
|
||||
descn(3,f),
|
||||
descn(4,f), ....
|
||||
|
||||
*/
|
@@ -1,60 +0,0 @@
|
||||
|
||||
/* base file for school database. Supposed to be called from school_*.yap */
|
||||
|
||||
conservative_city(City, Cons) :-
|
||||
cons_table(City, ConsDist),
|
||||
{ Cons = cons(City) with p([y,n], ConsDist) }.
|
||||
|
||||
gender(X, Gender) :-
|
||||
gender_table(City, GenderDist),
|
||||
{ Gender = gender(City) with p([m,f], GenderDist) }.
|
||||
|
||||
hair_color(X, Color) :-
|
||||
lives(X, City),
|
||||
conservative_city(City, Cons),
|
||||
gender(X, Gender),
|
||||
color_table(X,ColorTable),
|
||||
{ Color = color(X) with
|
||||
p([t,f], ColorTable,[Gender,Cons]) }.
|
||||
|
||||
car_color(X, Color) :-
|
||||
hair_color(City, HColor),
|
||||
ccolor_table(X,CColorTable),
|
||||
{ Color = ccolor(X) with
|
||||
p([t,f], CColorTable,[HColor]) }.
|
||||
|
||||
height(X, Height) :-
|
||||
gender(X, Gender),
|
||||
height_table(X,HeightTable),
|
||||
{ Height = height(X) with
|
||||
p([t,f], HeightTable,[Gender]) }.
|
||||
|
||||
shoe_size(X, Shoesize) :-
|
||||
height(X, Height),
|
||||
shoe_size_table(X,ShoesizeTable),
|
||||
{ Shoesize = shoe_size(X) with
|
||||
p([t,f], ShoesizeTable,[Height]) }.
|
||||
|
||||
guilty(X, Guilt) :-
|
||||
guilt_table(X, GuiltDist),
|
||||
{ Guilt = guilt(X) with p([y,n], GuiltDist) }.
|
||||
|
||||
|
||||
descn(X, Descn) :-
|
||||
car_color(X, Car),
|
||||
hair_color(X, Hair),
|
||||
height(X, Height),
|
||||
guilty(X, Guilt),
|
||||
descn_table(X, DescTable),
|
||||
{ Descn = descn(X) with
|
||||
p([t,f], DescTable,[Car,Hair,Height,Guilt]) }.
|
||||
|
||||
witness(City, Witness) :-
|
||||
descn(joe, DescnJ),
|
||||
descn(1, Descn1),
|
||||
wit_table(WitTable),
|
||||
{ Witness = wit(City) with
|
||||
p([t,f], WitTable,[DescnJ, Descn1]) }.
|
||||
|
||||
|
||||
|
@@ -1,35 +0,0 @@
|
||||
|
||||
cons_table(amsterdam,[0.2,
|
||||
0.8]) :- !.
|
||||
cons_table(_, [0.8,
|
||||
0.2]).
|
||||
|
||||
color_table(_,
|
||||
/* tm tf fm ff */
|
||||
[ 0.05, 0.1, 0.3, 0.5 ,
|
||||
0.95, 0.9, 0.7, 0.5 ]).
|
||||
|
||||
ccolor_table(_,
|
||||
/* t f */
|
||||
[ 0.9, 0.2 ,
|
||||
0.1, 0.8 ]).
|
||||
|
||||
height_table(_,
|
||||
/* m f */
|
||||
[ 0.6, 0.4 ,
|
||||
0.4, 0.6 ]).
|
||||
|
||||
shoe_size_table(_,
|
||||
/* t f */
|
||||
[ 0.9, 0.1 ,
|
||||
0.1, 0.9 ]).
|
||||
|
||||
A: professor's ability;
|
||||
B: student's grade (for course registration).
|
||||
*/
|
||||
descn_table(_,
|
||||
/* color, hair, height, guilt */
|
||||
/* ttttt tttf ttft ttff tfttt tftf tfft tfff ttttt fttf ftft ftff ffttt fftf ffft ffff */
|
||||
/*t*/ [0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99,
|
||||
/*f*/ 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 ]).
|
||||
|
47
packages/CLPBN/examples/burglary-alarm.fg
Normal file
47
packages/CLPBN/examples/burglary-alarm.fg
Normal file
@@ -0,0 +1,47 @@
|
||||
5
|
||||
|
||||
1
|
||||
0
|
||||
2
|
||||
2
|
||||
0 0.001
|
||||
1 0.999
|
||||
|
||||
1
|
||||
1
|
||||
2
|
||||
2
|
||||
0 0.002
|
||||
1 0.998
|
||||
|
||||
3
|
||||
1 0 2
|
||||
2 2 2
|
||||
8
|
||||
0 0.95
|
||||
1 0.94
|
||||
2 0.29
|
||||
3 0.001
|
||||
4 0.05
|
||||
5 0.06
|
||||
6 0.71
|
||||
7 0.999
|
||||
|
||||
2
|
||||
2 3
|
||||
2 2
|
||||
4
|
||||
0 0.9
|
||||
1 0.05
|
||||
2 0.1
|
||||
3 0.95
|
||||
|
||||
2
|
||||
2 4
|
||||
2 2
|
||||
4
|
||||
0 0.7
|
||||
1 0.01
|
||||
2 0.3
|
||||
3 0.99
|
||||
|
28
packages/CLPBN/examples/burglary-alarm.uai
Normal file
28
packages/CLPBN/examples/burglary-alarm.uai
Normal file
@@ -0,0 +1,28 @@
|
||||
MARKOV
|
||||
5
|
||||
2 2 2 2 2
|
||||
5
|
||||
1 0
|
||||
1 1
|
||||
3 2 0 1
|
||||
2 3 2
|
||||
2 4 2
|
||||
|
||||
2
|
||||
.001 .999
|
||||
|
||||
2
|
||||
.002 .998
|
||||
|
||||
8
|
||||
.95 .94 .29 .001
|
||||
.05 .06 .71 .999
|
||||
|
||||
4
|
||||
.9 .05
|
||||
.1 .95
|
||||
|
||||
4
|
||||
.7 .01
|
||||
.3 .99
|
||||
|
23
packages/CLPBN/examples/burglary-alarm.yap
Normal file
23
packages/CLPBN/examples/burglary-alarm.yap
Normal file
@@ -0,0 +1,23 @@
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
%:- set_solver(fove).
|
||||
%:- set_solver(hve).
|
||||
%:- set_solver(bp).
|
||||
%:- set_solver(cbp).
|
||||
|
||||
:- yap_flag(write_strings, off).
|
||||
|
||||
bayes burglary::[b1,b2] ; [0.001, 0.999] ; [].
|
||||
|
||||
bayes earthquake::[e1,e2] ; [0.002, 0.998]; [].
|
||||
|
||||
bayes alarm::[a1,a2], burglary, earthquake ;
|
||||
[0.95, 0.94, 0.29, 0.001, 0.05, 0.06, 0.71, 0.999] ;
|
||||
[].
|
||||
|
||||
bayes john_calls::[j1,j2], alarm ; [0.9, 0.05, 0.1, 0.95] ; [].
|
||||
|
||||
bayes mary_calls::[m1,m2], alarm ; [0.7, 0.01, 0.3, 0.99] ; [].
|
||||
|
||||
% ?- john_calls(J), mary_calls(m1).
|
||||
|
105
packages/CLPBN/examples/city.yap
Normal file
105
packages/CLPBN/examples/city.yap
Normal file
@@ -0,0 +1,105 @@
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
%:- set_solver(fove).
|
||||
%:- set_solver(hve).
|
||||
%:- set_solver(bp).
|
||||
%:- set_solver(cbp).
|
||||
|
||||
:- multifile people/2.
|
||||
:- multifile ev/1.
|
||||
|
||||
people(joe,nyc).
|
||||
people(p2, nyc).
|
||||
people(p3, nyc).
|
||||
people(p4, nyc).
|
||||
people(p5, nyc).
|
||||
|
||||
ev(descn(p2, t)).
|
||||
ev(descn(p3, t)).
|
||||
ev(descn(p4, t)).
|
||||
ev(descn(p5, t)).
|
||||
|
||||
bayes city_conservativeness(C)::[y,n] ; cons_table(C) ; [people(_,C)].
|
||||
|
||||
bayes gender(P)::[m,f] ; gender_table(P) ; [people(P,_)].
|
||||
|
||||
bayes hair_color(P)::[t,f], city_conservativeness(C) ; hair_color_table(P) ; [people(P,C)].
|
||||
|
||||
bayes car_color(P)::[t,f], hair_color(P) ; car_color_table(P); [people(P,_)].
|
||||
|
||||
bayes height(P)::[t,f], gender(P) ; height_table(P) ; [people(P,_)].
|
||||
|
||||
bayes shoe_size(P):[t,f], height(P) ; shoe_size_table(P); [people(P,_)].
|
||||
|
||||
bayes guilty(P)::[y,n] ; guilty_table(P) ; [people(P,_)].
|
||||
|
||||
bayes descn(P)::[t,f], car_color(P), hair_color(P), height(P), guilty(P) ; descn_table(P) ; [people(P,_)].
|
||||
|
||||
bayes witness(C)::[t,f], descn(Joe), descn(P2) ; wit_table ; [people(_,C), Joe=joe, P2=p2].
|
||||
|
||||
% FIXME
|
||||
%cons_table(amsterdam, [0.2, 0.8]) :- !.
|
||||
cons_table(_, [0.8, 0.2]).
|
||||
|
||||
|
||||
gender_table(_, [0.55, 0.45]).
|
||||
|
||||
|
||||
hair_color_table(_,
|
||||
/* conservative_city */
|
||||
/* y n */
|
||||
[ 0.05, 0.1,
|
||||
0.95, 0.9 ]).
|
||||
|
||||
|
||||
car_color_table(_,
|
||||
/* t f */
|
||||
[ 0.9, 0.2,
|
||||
0.1, 0.8 ]).
|
||||
|
||||
|
||||
height_table(_,
|
||||
/* m f */
|
||||
[ 0.6, 0.4,
|
||||
0.4, 0.6 ]).
|
||||
|
||||
|
||||
shoe_size_table(_,
|
||||
/* t f */
|
||||
[ 0.9, 0.1,
|
||||
0.1, 0.9 ]).
|
||||
|
||||
|
||||
guilty_table(_, [0.23, 0.77]).
|
||||
|
||||
|
||||
descn_table(_,
|
||||
/* color, hair, height, guilt */
|
||||
/* ttttt tttf ttft ttff tfttt tftf tfft tfff ttttt fttf ftft ftff ffttt fftf ffft ffff */
|
||||
[ 0.99, 0.5, 0.23, 0.88, 0.41, 0.3, 0.76, 0.87, 0.44, 0.43, 0.29, 0.72, 0.23, 0.91, 0.95, 0.92,
|
||||
0.01, 0.5, 0.77, 0.12, 0.59, 0.7, 0.24, 0.13, 0.56, 0.57, 0.71, 0.28, 0.77, 0.09, 0.05, 0.08]).
|
||||
|
||||
|
||||
wit_table([0.2, 0.45, 0.24, 0.34,
|
||||
0.8, 0.55, 0.76, 0.66]).
|
||||
|
||||
|
||||
runall(G, Wrapper) :-
|
||||
findall(G, Wrapper, L),
|
||||
execute_all(L).
|
||||
|
||||
|
||||
execute_all([]).
|
||||
execute_all(G.L) :-
|
||||
call(G),
|
||||
execute_all(L).
|
||||
|
||||
|
||||
is_joe_guilty(Guilty) :-
|
||||
witness(nyc, t),
|
||||
runall(X, ev(X)),
|
||||
guilty(joe, Guilty).
|
||||
|
||||
|
||||
% ?- is_joe_guilty(Guilty)
|
||||
|
33
packages/CLPBN/examples/comp_workshops.yap
Normal file
33
packages/CLPBN/examples/comp_workshops.yap
Normal file
@@ -0,0 +1,33 @@
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
%:- set_solver(fove).
|
||||
%:- set_solver(hve).
|
||||
%:- set_solver(bp).
|
||||
%:- set_solver(cbp).
|
||||
|
||||
:- yap_flag(write_strings, off).
|
||||
|
||||
:- multifile c/2.
|
||||
|
||||
c(p1,w1).
|
||||
c(p1,w2).
|
||||
c(p1,w3).
|
||||
c(p2,w1).
|
||||
c(p2,w2).
|
||||
c(p2,w3).
|
||||
c(p3,w1).
|
||||
c(p3,w2).
|
||||
c(p3,w3).
|
||||
c(p4,w1).
|
||||
c(p4,w2).
|
||||
c(p4,w3).
|
||||
c(p5,w1).
|
||||
c(p5,w2).
|
||||
c(p5,w3).
|
||||
|
||||
markov attends(P)::[t,f], hot(W)::[t,f] ; [0.2, 0.8, 0.8, 0.8] ; [c(P,W)].
|
||||
|
||||
markov attends(P)::[t,f], series::[t,f] ; [0.501, 0.499, 0.499, 0.499] ; [c(P,_)].
|
||||
|
||||
% ?- series(X).
|
||||
|
21
packages/CLPBN/examples/fail1.yap
Normal file
21
packages/CLPBN/examples/fail1.yap
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
:- set_pfl_flag(solver,fove).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,ve).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,bp).
|
||||
%:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,cbp).
|
||||
|
||||
|
||||
t(ann).
|
||||
t(dave).
|
||||
|
||||
% p(ann,t).
|
||||
|
||||
markov p(X)::[t,f] ; [0.1, 0.3] ; [t(X)].
|
||||
|
||||
% use standard Prolog queries: provide evidence first.
|
||||
|
||||
?- p(ann,t), p(ann,X).
|
||||
% ?- p(ann,X).
|
||||
|
21
packages/CLPBN/examples/fail2.yap
Normal file
21
packages/CLPBN/examples/fail2.yap
Normal file
@@ -0,0 +1,21 @@
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
:- set_solver(fove).
|
||||
%:- set_solver(hve).
|
||||
%:- set_solver(bp).
|
||||
%:- set_solver(cbp).
|
||||
|
||||
:- yap_flag(write_strings, off).
|
||||
|
||||
:- clpbn_horus:set_horus_flag(verbosity,5).
|
||||
|
||||
people(p1,p1).
|
||||
people(p1,p2).
|
||||
people(p2,p1).
|
||||
people(p2,p2).
|
||||
|
||||
markov p(A,A)::[t,f] ; [1.0,4.5] ; [people(A,_)].
|
||||
|
||||
markov p(A,B)::[t,f] ; [1.0,4.5] ; [people(A,B)].
|
||||
|
||||
?- p(p1,p1,X).
|
31
packages/CLPBN/examples/social_domain1.yap
Normal file
31
packages/CLPBN/examples/social_domain1.yap
Normal file
@@ -0,0 +1,31 @@
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
%:- set_solver(fove).
|
||||
%:- set_solver(hve).
|
||||
%:- set_solver(bp).
|
||||
%:- set_solver(cbp).
|
||||
|
||||
:- yap_flag(write_strings, off).
|
||||
|
||||
:- multifile people/1.
|
||||
|
||||
people @ 5.
|
||||
|
||||
people(X,Y) :-
|
||||
people(X),
|
||||
people(Y),
|
||||
X \== Y.
|
||||
|
||||
markov smokes(X)::[t,f]; [1.0, 4.0552]; [people(X)].
|
||||
|
||||
markov cancer(X)::[t,f]; [1.0, 9.9742]; [people(X)].
|
||||
|
||||
markov friends(X,Y)::[t,f] ; [1.0, 99.48432] ; [people(X,Y)].
|
||||
|
||||
markov smokes(X)::[t,f], cancer(X)::[t,f] ; [4.48169, 4.48169, 1.0, 4.48169] ; [people(X)].
|
||||
|
||||
markov friends(X,Y)::[t,f], smokes(X)::[t,f], smokes(Y)::[t,f] ;
|
||||
[3.004166, 3.004166, 3.004166, 3.004166, 3.004166, 1.0, 1.0, 3.004166] ; [people(X,Y)].
|
||||
|
||||
% ?- friends(p1,p2,X).
|
||||
|
31
packages/CLPBN/examples/social_domain2.yap
Normal file
31
packages/CLPBN/examples/social_domain2.yap
Normal file
@@ -0,0 +1,31 @@
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
%:- set_solver(fove).
|
||||
%:- set_solver(hve).
|
||||
%:- set_solver(bp).
|
||||
%:- set_solver(cbp).
|
||||
|
||||
:- yap_flag(write_strings, off).
|
||||
|
||||
:- multifile people/1.
|
||||
|
||||
people @ 5.
|
||||
|
||||
people(X,Y) :-
|
||||
people(X),
|
||||
people(Y).
|
||||
% X \== Y.
|
||||
|
||||
markov smokes(X)::[t,f]; [1.0, 4.0552]; [people(X)].
|
||||
|
||||
markov asthma(X)::[t,f]; [1.0, 9.9742] ; [people(X)].
|
||||
|
||||
markov friends(X,Y)::[t,f]; [1.0, 99.48432] ; [people(X,Y)].
|
||||
|
||||
markov asthma(X)::[t,f], smokes(X)::[t,f]; [4.48169, 4.48169, 1.0, 4.48169] ; [people(X)].
|
||||
|
||||
markov asthma(X)::[t,f], friends(X,Y)::[t,f], smokes(Y)::[t,f];
|
||||
[3.004166, 3.004166, 3.004166, 3.004166, 3.004166, 1.0, 1.0, 3.004166] ; [people(X,Y)].
|
||||
|
||||
% ?- smokes(p1,t), smokes(p2,t), friends(p1,p2,X)
|
||||
|
29
packages/CLPBN/examples/workshop_attrs.yap
Normal file
29
packages/CLPBN/examples/workshop_attrs.yap
Normal file
@@ -0,0 +1,29 @@
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
%:- set_solver(fove).
|
||||
%:- set_solver(hve).
|
||||
%:- set_solver(bp).
|
||||
%:- set_solver(cbp).
|
||||
|
||||
:- yap_flag(write_strings, off).
|
||||
|
||||
:- multifile people/1.
|
||||
|
||||
people @ 5.
|
||||
|
||||
markov attends(P)::[t,f], attr1::[t,f] ; [0.7, 0.3, 0.3, 0.3] ; [people(P)].
|
||||
|
||||
markov attends(P)::[t,f], attr2::[t,f] ; [0.7, 0.3, 0.3, 0.3] ; [people(P)].
|
||||
|
||||
markov attends(P)::[t,f], attr3::[t,f] ; [0.7, 0.3, 0.3, 0.3] ; [people(P)].
|
||||
|
||||
markov attends(P)::[t,f], attr4::[t,f] ; [0.7, 0.3, 0.3, 0.3] ; [people(P)].
|
||||
|
||||
markov attends(P)::[t,f], attr5::[t,f] ; [0.7, 0.3, 0.3, 0.3] ; [people(P)].
|
||||
|
||||
markov attends(P)::[t,f], attr6::[t,f] ; [0.7, 0.3, 0.3, 0.3] ; [people(P)].
|
||||
|
||||
markov attends(P)::[t,f], series::[t,f] ; [0.501, 0.499, 0.499, 0.499] ; [people(P)].
|
||||
|
||||
% ?- series(X).
|
||||
|
Reference in New Issue
Block a user