rework the examples and erase the city network in the old format

This commit is contained in:
Tiago Gomes
2012-04-11 15:36:50 +01:00
parent 8697fcd2b4
commit f2fbbf29d8
42 changed files with 290 additions and 1343361 deletions

View File

@@ -1,18 +0,0 @@
:- use_module(library(pfl)).
:- set_clpbn_flag(solver,fove).
c(x1,y1,z1).
c(x1,y1,z2).
c(x2,y2,z1).
c(x3,y2,z1).
bayes p(X)::[t,f] ; [0.2, 0.4] ; [c(X,_,_)].
bayes q(Y)::[t,f] ; [0.5, 0.6] ; [c(_,Y,_)].
bayes s(Z)::[t,f] , p(X) , q(Y) ; [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8] ; [c(X,Y,Z)].
% bayes series::[t,f] , attends(X) ; [0.5, 0.6, 0.7, 0.8] ; [c(X,_)].

View File

@@ -1,3 +1,5 @@
# example in counting belief propagation paper
MARKOV
3
2 2 2
@@ -5,7 +7,6 @@ MARKOV
2 0 1
2 2 1
4
1.2 1.4 2.0 0.4

View File

@@ -0,0 +1,98 @@
:- 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).
people(joe,nyc).
people(p2, nyc).
people(p3, nyc).
ev(descn(p2, t)).
ev(descn(p3, t)).
:- [city_7].
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].
cons_table(amsterdam, [0.2, 0.8]) :- !.
cons_table(_, [0.8, 0.2]).
gender_table(_, [0.55, 0.44]).
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.33, 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.61, 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).
?- witness(nyc, t), runall(X, ev(X)), guilty(joe, Guilty).

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
:- use_module(library(pfl)).
%:- set_clpbn_flag(solver,ve).
%:- set_clpbn_flag(solver,bp), clpbn_bp:set_horus_flag(inf_alg,ve).
:- set_clpbn_flag(solver,fove).
:- 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).
c(p1,w1).
c(p1,w2).
@@ -25,8 +25,5 @@ markov attends(P)::[t,f] , hot(W)::[t,f] ; [0.1, 0.2, 0.3, 0.4] ; [c(P,W)].
markov attends(P)::[t,f], series::[t,f] ; [0.5, 0.6, 0.7, 0.8] ; [c(P,_)].
:- clpbn_horus:set_horus_flag(use_logarithms,true).
?- series(X).

View File

@@ -2,7 +2,9 @@
:- use_module(library(pfl)).
:- set_pfl_flag(solver,fove).
%:- 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).
@@ -10,10 +12,10 @@ t(dave).
% p(ann,t).
bayes p(X)::[t,f] ; [0.1, 0.3] ; [t(X)].
markov p(X)::[t,f] ; [0.1, 0.3] ; [t(X)].
% use standard Prolog queries: provide evidence first.
?- p(dave,t), p(ann,X).
?- p(ann,t), p(ann,X).
% ?- p(ann,X).

View File

@@ -1,39 +1,23 @@
:- use_module(library(pfl)).
%:- set_pfl_flag(solver,ve).
:- set_pfl_flag(solver,bp), clpbn_horus:set_horus_flag(inf_alg,ve).
% :- set_pfl_flag(solver,fove).
:- 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).
:- yap_flag(write_strings, off).
friends(P1, P2) :-
person(P1),
person(P2),
P1 \= P2.
person(P1),
person(P2),
P1 \= P2.
person(john).
person(maggie).
%person(harry).
%person(bill).
%person(matt).
%person(diana).
%person(bob).
%person(dick).
%person(burr).
%person(ann).
% person @ 2.
person @ 3.
markov smokes(P)::[t,f] , cancer(P)::[t,f] ; [0.1, 0.2, 0.3, 0.4] ; [person(P)].
markov friend(P1,P2)::[t,f], smokes(P1)::[t,f], smokes(P2)::[t,f] ; [0.5, 0.6, 0.7, 0.8, 0.5, 0.6, 0.7, 0.8] ; [friends(P1, P2)].
% ?- smokes(person_0, t), smokes(person_1, t), friend(person_0, person_1, F).
% ?- smokes(john, t), smokes(maggie, f), friend(john, maggie, X).
?- smokes(john, t), friend(john, maggie, X).
% ?- friend(john, maggie, X).
?- smokes(person_1, t), smokes(person_2, f), friend(person_1, person_2, X).

View File

@@ -1,120 +0,0 @@
14
1
6
2
2
0 9.974182
1 1.000000
1
7
2
2
0 9.974182
1 1.000000
1
4
2
2
0 4.055200
1 1.000000
1
5
2
2
0 4.055200
1 1.000000
1
0
2
2
0 7.389056
1 1.000000
1
2
2
2
0 7.389056
1 1.000000
1
1
2
2
0 7.389056
1 1.000000
1
3
2
2
0 7.389056
1 1.000000
2
4 6
2 2
4
0 4.481689
1 1.000000
2 4.481689
3 4.481689
2
5 7
2 2
4
0 4.481689
1 1.000000
2 4.481689
3 4.481689
2
0 4
2 2
4
0 3.004166
1 3.004166
2 3.004166
3 3.004166
3
2 5 4
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
1 4 5
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
2
3 5
2 2
4
0 3.004166
1 3.004166
2 3.004166
3 3.004166

View File

@@ -1,239 +0,0 @@
27
1
12
2
2
0 9.974182
1 1.000000
1
13
2
2
0 9.974182
1 1.000000
1
14
2
2
0 9.974182
1 1.000000
1
9
2
2
0 4.055200
1 1.000000
1
10
2
2
0 4.055200
1 1.000000
1
11
2
2
0 4.055200
1 1.000000
1
0
2
2
0 7.389056
1 1.000000
1
3
2
2
0 7.389056
1 1.000000
1
6
2
2
0 7.389056
1 1.000000
1
1
2
2
0 7.389056
1 1.000000
1
4
2
2
0 7.389056
1 1.000000
1
7
2
2
0 7.389056
1 1.000000
1
2
2
2
0 7.389056
1 1.000000
1
5
2
2
0 7.389056
1 1.000000
1
8
2
2
0 7.389056
1 1.000000
2
9 12
2 2
4
0 4.481689
1 1.000000
2 4.481689
3 4.481689
2
10 13
2 2
4
0 4.481689
1 1.000000
2 4.481689
3 4.481689
2
11 14
2 2
4
0 4.481689
1 1.000000
2 4.481689
3 4.481689
2
0 9
2 2
4
0 3.004166
1 3.004166
2 3.004166
3 3.004166
3
3 10 9
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
6 11 9
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
1 9 10
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
2
4 10
2 2
4
0 3.004166
1 3.004166
2 3.004166
3 3.004166
3
7 11 10
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
2 9 11
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
5 10 11
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
2
8 11
2 2
4
0 3.004166
1 3.004166
2 3.004166
3 3.004166

View File

@@ -1,398 +0,0 @@
44
1
20
2
2
0 9.974182
1 1.000000
1
21
2
2
0 9.974182
1 1.000000
1
22
2
2
0 9.974182
1 1.000000
1
23
2
2
0 9.974182
1 1.000000
1
16
2
2
0 4.055200
1 1.000000
1
17
2
2
0 4.055200
1 1.000000
1
18
2
2
0 4.055200
1 1.000000
1
19
2
2
0 4.055200
1 1.000000
1
0
2
2
0 7.389056
1 1.000000
1
4
2
2
0 7.389056
1 1.000000
1
8
2
2
0 7.389056
1 1.000000
1
12
2
2
0 7.389056
1 1.000000
1
1
2
2
0 7.389056
1 1.000000
1
5
2
2
0 7.389056
1 1.000000
1
9
2
2
0 7.389056
1 1.000000
1
13
2
2
0 7.389056
1 1.000000
1
2
2
2
0 7.389056
1 1.000000
1
6
2
2
0 7.389056
1 1.000000
1
10
2
2
0 7.389056
1 1.000000
1
14
2
2
0 7.389056
1 1.000000
1
3
2
2
0 7.389056
1 1.000000
1
7
2
2
0 7.389056
1 1.000000
1
11
2
2
0 7.389056
1 1.000000
1
15
2
2
0 7.389056
1 1.000000
2
16 20
2 2
4
0 4.481689
1 1.000000
2 4.481689
3 4.481689
2
17 21
2 2
4
0 4.481689
1 1.000000
2 4.481689
3 4.481689
2
18 22
2 2
4
0 4.481689
1 1.000000
2 4.481689
3 4.481689
2
19 23
2 2
4
0 4.481689
1 1.000000
2 4.481689
3 4.481689
2
0 16
2 2
4
0 3.004166
1 3.004166
2 3.004166
3 3.004166
3
4 17 16
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
8 18 16
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
12 19 16
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
1 16 17
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
2
5 17
2 2
4
0 3.004166
1 3.004166
2 3.004166
3 3.004166
3
9 18 17
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
13 19 17
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
2 16 18
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
6 17 18
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
2
10 18
2 2
4
0 3.004166
1 3.004166
2 3.004166
3 3.004166
3
14 19 18
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
3 16 19
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
7 17 19
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
3
11 18 19
2 2 2
8
0 3.004166
1 3.004166
2 3.004166
3 1.000000
4 3.004166
5 1.000000
6 3.004166
7 3.004166
2
15 19
2 2
4
0 3.004166
1 3.004166
2 3.004166
3 3.004166

View File

@@ -1,9 +1,9 @@
:- use_module(library(pfl)).
%:- set_clpbn_flag(solver,ve).
%:- set_clpbn_flag(solver,bp), clpbn_bp:set_horus_flag(inf_alg,ve).
:- set_clpbn_flag(solver,fove).
:- 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).
c(p1).
c(p2).
@@ -26,7 +26,5 @@ markov attends(P)::[t,f] , attr6::[t,f] ; [0.1, 0.2, 0.3, 0.4] ; [c(P)].
markov attends(P)::[t,f], series::[t,f] ; [0.5, 0.6, 0.7, 0.8] ; [c(P)].
%:- clpbn_horus:set_horus_flag(use_logarithms,true).
?- series(X).