CLP(BN) examples
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1519 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
2cc076bb10
commit
31f7623984
CLPBN/clpbn/examples
53
CLPBN/clpbn/examples/School/README
Normal file
53
CLPBN/clpbn/examples/School/README
Normal file
@ -0,0 +1,53 @@
|
||||
|
||||
This is a version of the school database, based on the PRM School example.
|
||||
|
||||
There are four main files:
|
||||
|
||||
school_128.yap: a school with 128 professors, 256 courses and 4096 students.
|
||||
school_64.yap: medium size school
|
||||
school_32.yap: small school
|
||||
|
||||
schema.yap: the schema
|
||||
tables: CPTs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
professor_ability(p0,X).
|
||||
|
||||
professor_popularity(p0,X).
|
||||
|
||||
professor_ability(p0,X), professor_popularity(p0,h).
|
||||
|
||||
professor_ability(p0,h), professor_popularity(p0,X).
|
||||
|
||||
registration_grade(r0,X).
|
||||
|
||||
registration_grade(r0,X), registration_course(r0,C), course_difficulty(C,h).
|
||||
|
||||
registration_grade(r0,X), registration_course(r0,C), course_difficulty(C,h), registration_student(r0,S), student_intelligence(S,h).
|
||||
|
||||
registration_grade(r0,X), registration_course(r0,C), course_difficulty(C,l), registration_student(r0,S), student_intelligence(S,h).
|
||||
|
||||
registration_satisfaction(r0,X).
|
||||
|
||||
registration_satisfaction(r0,X), registration_student(r0,S), student_intelligence(S,h).
|
||||
|
||||
registration_satisfaction(r0,X), registration_grade(r0,a).
|
||||
|
||||
registration_satisfaction(r0,X), registration_grade(r0,d).
|
||||
|
||||
registration_satisfaction(r0,h), registration_grade(r0,X).
|
||||
|
||||
course_rating(c0,X).
|
||||
|
||||
course_rating(c0,h), course_difficulty(c0,X).
|
||||
|
||||
course_difficulty(c0,X).
|
||||
|
||||
student_ranking(s0,X).
|
||||
|
||||
student_ranking(s0,X), student_intelligence(s0,h).
|
||||
|
||||
|
17
CLPBN/clpbn/examples/School/evidence_128.yap
Normal file
17
CLPBN/clpbn/examples/School/evidence_128.yap
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
:- [school_128].
|
||||
|
||||
professor_popularity(p0,h) :- {}.
|
||||
professor_popularity(p3,h) :- {}.
|
||||
professor_popularity(p5,l) :- {}.
|
||||
professor_popularity(p45,h) :- {}.
|
||||
professor_popularity(p15,m) :- {}.
|
||||
|
||||
course_rating(c0, a) :- {}.
|
||||
course_rating(c1, b) :- {}.
|
||||
course_rating(c2, c) :- {}.
|
||||
course_rating(c3, a) :- {}.
|
||||
course_rating(c4, a) :- {}.
|
||||
course_rating(c5, d) :- {}.
|
||||
course_rating(c62, b) :- {}.
|
||||
|
73
CLPBN/clpbn/examples/School/schema.yap
Normal file
73
CLPBN/clpbn/examples/School/schema.yap
Normal file
@ -0,0 +1,73 @@
|
||||
|
||||
/* base file for school database. Supposed to be called from school_*.yap */
|
||||
|
||||
professor_key(Key) :-
|
||||
professor(Key).
|
||||
|
||||
professor_ability(Key,Abi) :-
|
||||
abi_table(Key, AbiDist),
|
||||
{ Abi = ability(Key) with p([h,m,l], AbiDist) }.
|
||||
|
||||
professor_popularity(Key, Pop) :-
|
||||
professor_ability(Key, Abi),
|
||||
pop_table(Key,PopTable),
|
||||
{ Pop = popularity(Key) with
|
||||
p([h,m,l], PopTable,[Abi]) }.
|
||||
|
||||
registration_key(Key) :-
|
||||
registration(Key, _, _).
|
||||
|
||||
registration_course(Key, CKey) :-
|
||||
registration(Key, CKey, _).
|
||||
|
||||
registration_student(Key, SKey) :-
|
||||
registration(Key, _, SKey).
|
||||
|
||||
registration_grade(Key, Grade) :-
|
||||
registration(Key, CKey, SKey),
|
||||
course_difficulty(CKey, Dif),
|
||||
student_intelligence(SKey, Int),
|
||||
grade_table(Int, Dif, Table),
|
||||
{ Grade = grade(Key) with Table }.
|
||||
|
||||
% registration_satisfaction(r0, h) :- {}.
|
||||
registration_satisfaction(Key, Sat) :-
|
||||
registration_course(Key, CKey),
|
||||
course_professor(CKey, PKey),
|
||||
professor_ability(PKey, Abi),
|
||||
registration_grade(Key, Grade),
|
||||
satisfaction_table(Abi, Grade, Table),
|
||||
{ Sat = satisfaction(Key) with Table }.
|
||||
|
||||
course_key(Key) :-
|
||||
course(Key,_).
|
||||
|
||||
course_professor(Key, PKey) :-
|
||||
course(Key, PKey).
|
||||
|
||||
course_rating(CKey, Rat) :-
|
||||
setof(Sat, RKey^(registration_course(RKey,CKey), registration_satisfaction(RKey,Sat)), Sats),
|
||||
build_rating_table(Sats, rating(CKey), Table),
|
||||
{ Rat = rating(CKey) with Table }.
|
||||
|
||||
course_difficulty(Key, Dif) :-
|
||||
dif_table(Key, Dist),
|
||||
{ Dif = difficulty(Key) with p([h,m,l], Dist) }.
|
||||
|
||||
student_key(Key) :-
|
||||
student(Key).
|
||||
|
||||
student_intelligence(Key, Int) :-
|
||||
int_table(Key, IDist, Domain),
|
||||
{ Int = intelligence(Key) with p(Domain, IDist) }.
|
||||
|
||||
student_ranking(Key, Rank) :-
|
||||
setof(Grade, CKey^(registration_student(CKey,Key),
|
||||
registration_grade(CKey, Grade)), Grades),
|
||||
build_grades_table(Grades, ranking(Key), GradesTable),
|
||||
{ Rank = ranking(Key) with GradesTable }.
|
||||
|
||||
:- ensure_loaded(tables).
|
||||
|
||||
|
||||
|
18432
CLPBN/clpbn/examples/School/school_128.yap
Normal file
18432
CLPBN/clpbn/examples/School/school_128.yap
Normal file
File diff suppressed because it is too large
Load Diff
1238
CLPBN/clpbn/examples/School/school_32.yap
Normal file
1238
CLPBN/clpbn/examples/School/school_32.yap
Normal file
File diff suppressed because it is too large
Load Diff
4706
CLPBN/clpbn/examples/School/school_64.yap
Normal file
4706
CLPBN/clpbn/examples/School/school_64.yap
Normal file
File diff suppressed because it is too large
Load Diff
68
CLPBN/clpbn/examples/School/tables.yap
Normal file
68
CLPBN/clpbn/examples/School/tables.yap
Normal file
@ -0,0 +1,68 @@
|
||||
|
||||
:- use_module(library('clpbn/aggregates'),[cpt_average/5]).
|
||||
|
||||
int_table(_, [0.5, 0.4, 0.1],[h, m, l]).
|
||||
|
||||
grade_table(I, D,
|
||||
/* h h h m h l m h m m m l l h l m l l */
|
||||
p([a,b,c,d],
|
||||
[ 0.2, 0.7, 0.85, 0.1, 0.2, 0.5, 0.01, 0.05,0.1 ,
|
||||
0.6, 0.25, 0.12, 0.3, 0.6,0.35,0.04, 0.15, 0.4 ,
|
||||
0.15,0.04, 0.02, 0.4,0.15,0.12, 0.5, 0.6, 0.4,
|
||||
0.05,0.01, 0.01, 0.2,0.05,0.03, 0.45, 0.2, 0.1 ], [I,D])).
|
||||
|
||||
|
||||
/*
|
||||
A: professor's ability;
|
||||
B: student's grade (for course registration).
|
||||
*/
|
||||
satisfaction_table(A, G,
|
||||
/* h a h b h c h d m a m b m c m d l a l b l c l d */
|
||||
p([h,m,l],
|
||||
/*h*/ [0.98, 0.9,0.8 , 0.6, 0.9, 0.4, 0.2, 0.01, 0.5, 0.2, 0.01, 0.01,
|
||||
/*m*/ 0.01, 0.09,0.15, 0.3,0.05, 0.4, 0.3, 0.04,0.35, 0.3, 0.09, 0.01 ,
|
||||
/*l*/ 0.01, 0.01,0.05, 0.1,0.05, 0.2, 0.5, 0.95,0.15, 0.5, 0.9, 0.98], [A,G])).
|
||||
|
||||
|
||||
% The idea is quite simple:
|
||||
% hs = h -> r = ( 0.9, 0.1, 0)
|
||||
% hs = m -> r = ( 0.2, 0.6, 0.2)
|
||||
% hs = l -> r = ( 0, 0.1, 0.9)
|
||||
%
|
||||
% add all and divide on the number of elements on the table!
|
||||
%
|
||||
rating_prob_table([0.9,0.05,0.01,
|
||||
0.09,0.9,0.09,
|
||||
0.01,0.05,0.9]).
|
||||
|
||||
/*
|
||||
build_sats_table(LSats, Key, Table) :-
|
||||
cpt_average(LSats, Key, [h,m,l], AggTable),
|
||||
{ V = tmp1(Key) with AggTable},
|
||||
rating_prob_table(SatsTable),
|
||||
Table = p([h,m,l], SatsTable, [V]).
|
||||
*/
|
||||
|
||||
build_rating_table(LSats, Key, Table) :-
|
||||
cpt_average(LSats, Key, [h,m,l], 0.95, Table).
|
||||
|
||||
build_grades_table(LGrades, Key, Table) :-
|
||||
cpt_average(LGrades, Key, [a,b,c,d], 0.95, Table).
|
||||
|
||||
/*
|
||||
build_grades_table(LGrades, Key, Table) :-
|
||||
cpt_average(LGrades, Key, [a,b,c,d], AggTable),
|
||||
{ V = tmp2(Key) with AggTable},
|
||||
rating_prob_table(Tab),
|
||||
Table = p([a,b,c,d], Tab, [V]).
|
||||
*/
|
||||
|
||||
|
||||
abi_table( _, [0.50, 0.40, 0.10]).
|
||||
|
||||
|
||||
pop_table(_, [0.9, 0.2, 0.01,
|
||||
0.09, 0.6, 0.09,
|
||||
0.01, 0.2, 0.9]).
|
||||
|
||||
dif_table( _, [0.25, 0.50, 0.25]).
|
34
CLPBN/clpbn/examples/cg.yap
Normal file
34
CLPBN/clpbn/examples/cg.yap
Normal file
@ -0,0 +1,34 @@
|
||||
%
|
||||
% adapted from Hendrik Blockeel's ILP04 paper.
|
||||
%
|
||||
|
||||
:- use_module(library(clpbn)).
|
||||
|
||||
cg(X,1,C):-
|
||||
father(Y,X),
|
||||
cg(Y,1,C1),cg(Y,2,C2),
|
||||
parent_cpt(cg(X,1), C1, C2, C).
|
||||
|
||||
cg(X,2,C):-
|
||||
mother(Y,X),
|
||||
cg(Y,1,C1),cg(Y,2,C2),
|
||||
parent_cpt(cg(X,2), C1, C2, C).
|
||||
|
||||
|
||||
|
||||
cg(f,X,C) :-
|
||||
prior_cpt(cg(f,X),C).
|
||||
|
||||
cg(m,X,C) :-
|
||||
prior_cpt(cg(m,X),C).
|
||||
|
||||
|
||||
prior_cpt(CKEY, C) :-
|
||||
{ C = CKEY with p([p,w], [0.5,0.5])}.
|
||||
|
||||
parent_cpt(CKEY, C1, C2, C) :-
|
||||
{ C = CKEY with p([p,w], [ 1,0.5,0.5,0.0,
|
||||
0.0,0.5,0.5, 1],[C1,C2])}.
|
||||
|
||||
father(f,s).
|
||||
mother(m,s).
|
Reference in New Issue
Block a user