2013-01-07 14:59:51 +00:00
|
|
|
/*
|
|
|
|
Model from the paper "First-order
|
|
|
|
probabilistic inference"
|
|
|
|
*/
|
|
|
|
|
2012-05-23 14:56:01 +01:00
|
|
|
:- use_module(library(pfl)).
|
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
%:- set_solver(ve).
|
2013-01-10 23:02:34 +00:00
|
|
|
%:- set_solver(hve).
|
2012-12-11 23:06:09 +00:00
|
|
|
%:- set_solver(jt).
|
|
|
|
%:- set_solver(bdd).
|
2012-05-23 14:56:01 +01:00
|
|
|
%:- set_solver(bp).
|
|
|
|
%:- set_solver(cbp).
|
2012-12-11 23:06:09 +00:00
|
|
|
%:- set_solver(gibbs).
|
|
|
|
%:- set_solver(lve).
|
|
|
|
%:- set_solver(lkc).
|
|
|
|
%:- set_solver(lbp).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-01-07 14:59:51 +00:00
|
|
|
:- multifile person/2.
|
2012-05-23 14:56:01 +01:00
|
|
|
:- multifile ev/1.
|
|
|
|
|
2013-01-07 14:59:51 +00:00
|
|
|
person(joe,nyc).
|
|
|
|
person(p2, nyc).
|
|
|
|
person(p3, nyc).
|
|
|
|
person(p4, nyc).
|
|
|
|
person(p5, nyc).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
ev(descn(p2, fits)).
|
|
|
|
ev(descn(p3, fits)).
|
|
|
|
ev(descn(p4, fits)).
|
|
|
|
ev(descn(p5, fits)).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
bayes city_conservativeness(C)::[high,low] ;
|
2013-01-07 14:59:51 +00:00
|
|
|
cons_table ;
|
|
|
|
[person(_,C)].
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
bayes gender(P)::[male,female] ;
|
2013-01-07 14:59:51 +00:00
|
|
|
gender_table ;
|
|
|
|
[person(P,_)].
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
bayes hair_color(P)::[dark,bright], city_conservativeness(C) ;
|
2013-01-07 14:59:51 +00:00
|
|
|
hair_color_table ;
|
|
|
|
[person(P,C)].
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
bayes car_color(P)::[dark,bright], hair_color(P) ;
|
2013-01-07 14:59:51 +00:00
|
|
|
car_color_table ;
|
|
|
|
[person(P,_)].
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
bayes height(P)::[tall,short], gender(P) ;
|
2013-01-07 14:59:51 +00:00
|
|
|
height_table ;
|
|
|
|
[person(P,_)].
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
bayes shoe_size(P)::[big,small], height(P) ;
|
2013-01-07 14:59:51 +00:00
|
|
|
shoe_size_table ;
|
|
|
|
[person(P,_)].
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
bayes guilty(P)::[y,n] ;
|
2013-01-07 14:59:51 +00:00
|
|
|
guilty_table ;
|
|
|
|
[person(P,_)].
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
bayes descn(P)::[fits,dont_fit], car_color(P),
|
2013-01-07 14:59:51 +00:00
|
|
|
hair_color(P), height(P), guilty(P) ;
|
|
|
|
descn_table ;
|
|
|
|
[person(P,_)].
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
bayes witness(C), descn(Joe), descn(P2) ;
|
2013-01-07 14:59:51 +00:00
|
|
|
witness_table ;
|
|
|
|
[person(_,C), Joe=joe, P2=p2].
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
|
2012-12-13 16:50:39 +00:00
|
|
|
cons_table(
|
2012-12-11 23:06:09 +00:00
|
|
|
/* y */ [ 0.8,
|
|
|
|
/* n */ 0.2 ]).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-13 16:50:39 +00:00
|
|
|
gender_table(
|
2012-12-11 23:06:09 +00:00
|
|
|
/* male */ [ 0.55,
|
|
|
|
/* female */ 0.45 ]).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-13 16:50:39 +00:00
|
|
|
hair_color_table(
|
2012-12-11 23:06:09 +00:00
|
|
|
/* high low */
|
|
|
|
/* dark */ [ 0.05, 0.1,
|
|
|
|
/* bright */ 0.95, 0.9 ]).
|
2012-12-20 23:19:10 +00:00
|
|
|
|
2012-12-13 16:50:39 +00:00
|
|
|
car_color_table(
|
2012-12-11 23:06:09 +00:00
|
|
|
/* dark bright */
|
|
|
|
/* dark */ [ 0.9, 0.2,
|
|
|
|
/* bright */ 0.1, 0.8 ]).
|
2012-12-20 23:19:10 +00:00
|
|
|
|
2012-12-13 16:50:39 +00:00
|
|
|
height_table(
|
2012-12-11 23:06:09 +00:00
|
|
|
/* male female */
|
|
|
|
/* tall */ [ 0.6, 0.4,
|
|
|
|
/* short */ 0.4, 0.6 ]).
|
2012-12-20 23:19:10 +00:00
|
|
|
|
2012-12-13 16:50:39 +00:00
|
|
|
shoe_size_table(
|
2012-12-11 23:06:09 +00:00
|
|
|
/* tall short */
|
|
|
|
/* big */ [ 0.9, 0.1,
|
|
|
|
/* small */ 0.1, 0.9 ]).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-13 16:50:39 +00:00
|
|
|
guilty_table(
|
2012-12-11 23:06:09 +00:00
|
|
|
/* yes */ [ 0.23,
|
|
|
|
/* no */ 0.77 ]).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-13 16:50:39 +00:00
|
|
|
descn_table(
|
2012-12-11 23:06:09 +00:00
|
|
|
/* car_color(P), hair_color(P), height(P), guilty(P) */
|
|
|
|
/* fits */ [ 0.99, 0.5, 0.23, 0.88, 0.41, 0.3, 0.76, 0.87,
|
|
|
|
/* fits */ 0.44, 0.43, 0.29, 0.72, 0.23, 0.91, 0.95, 0.92,
|
2012-12-20 23:19:10 +00:00
|
|
|
/* dont_fit */ 0.01, 0.5, 0.77, 0.12, 0.59, 0.7, 0.24, 0.13,
|
2012-12-11 23:06:09 +00:00
|
|
|
/* dont_fit */ 0.56, 0.57, 0.71, 0.28, 0.77, 0.09, 0.05, 0.08 ]).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-11 23:06:09 +00:00
|
|
|
witness_table(
|
|
|
|
/* descn(Joe), descn(P2) */
|
|
|
|
/* t */ [ 0.2, 0.45, 0.24, 0.34,
|
|
|
|
/* f */ 0.8, 0.55, 0.76, 0.66 ]).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
runall(G, Wrapper) :-
|
2013-01-07 14:59:51 +00:00
|
|
|
findall(G, Wrapper, L),
|
|
|
|
execute_all(L).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
execute_all([]).
|
|
|
|
execute_all(G.L) :-
|
2013-01-07 14:59:51 +00:00
|
|
|
call(G),
|
|
|
|
execute_all(L).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
is_joe_guilty(Guilty) :-
|
2013-01-07 14:59:51 +00:00
|
|
|
witness(nyc, t),
|
|
|
|
runall(X, ev(X)),
|
|
|
|
guilty(joe, Guilty).
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
|
2012-12-12 17:03:11 +00:00
|
|
|
% ?- is_joe_guilty(Guilty).
|
2012-05-23 14:56:01 +01:00
|
|
|
|