From 21050891ee6cba38e922dfcf3f025a914fea294e Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sat, 2 Jul 2011 09:49:12 +0100 Subject: [PATCH] city example. --- packages/CLPBN/examples/City/db_128.yap | 25 +++++++++++ packages/CLPBN/examples/City/schema.yap | 60 +++++++++++++++++++++++++ packages/CLPBN/examples/City/tables.yap | 35 +++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 packages/CLPBN/examples/City/db_128.yap create mode 100644 packages/CLPBN/examples/City/schema.yap create mode 100644 packages/CLPBN/examples/City/tables.yap diff --git a/packages/CLPBN/examples/City/db_128.yap b/packages/CLPBN/examples/City/db_128.yap new file mode 100644 index 000000000..6eea3954a --- /dev/null +++ b/packages/CLPBN/examples/City/db_128.yap @@ -0,0 +1,25 @@ + +%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), .... + +*/ \ No newline at end of file diff --git a/packages/CLPBN/examples/City/schema.yap b/packages/CLPBN/examples/City/schema.yap new file mode 100644 index 000000000..ff1950b40 --- /dev/null +++ b/packages/CLPBN/examples/City/schema.yap @@ -0,0 +1,60 @@ + +/* 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]) }. + + + \ No newline at end of file diff --git a/packages/CLPBN/examples/City/tables.yap b/packages/CLPBN/examples/City/tables.yap new file mode 100644 index 000000000..94ab3d016 --- /dev/null +++ b/packages/CLPBN/examples/City/tables.yap @@ -0,0 +1,35 @@ + +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 ]). +