fove initial skeleton.w
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
|
||||
:- [school_128].
|
||||
:- ensure_loaded(school_128).
|
||||
|
||||
professor_popularity(p0,h) :- {}.
|
||||
professor_popularity(p3,h) :- {}.
|
||||
|
66
packages/CLPBN/examples/School/parschema.yap
Normal file
66
packages/CLPBN/examples/School/parschema.yap
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
:- use_module(library(pfl)).
|
||||
|
||||
/* base file for school database. Supposed to be called from school_*.yap */
|
||||
|
||||
%
|
||||
% bayes is a parfactor for a bayesian network,
|
||||
% first argument is target of other arguments pop(K) <- abi(K)
|
||||
% second argument is the name of a predicate to call for \phi (CPT)
|
||||
% last argument is a list of goals defining the constraints over the elements
|
||||
% of the
|
||||
%
|
||||
|
||||
%
|
||||
% these states that skolem variables abi(K) are in a parametric factor with
|
||||
% with \phi defined by abi_table(X) and whose domain and constraints
|
||||
% is obtained from professor/1.
|
||||
%
|
||||
bayes abi(K)::[h,m,l] ; abi_table ; [professor(K)].
|
||||
|
||||
bayes pop(K)::[h,m,l], abi(K) ; pop_table ; [professor(K)].
|
||||
|
||||
bayes grade(C,S)::[a,b,c,d], int(S), diff(C) ; grade_table ; [registration(_,C,S)].
|
||||
|
||||
bayes sat(C,S,P)::[h,m,l], abi(P), grade(C,S) ; sat_table ; [reg_sat(C,S,P)].
|
||||
|
||||
bayes rat(C) :: [h,m,l], avg(Sats) ; avg ; [course_rating(C, Sats)].
|
||||
|
||||
bayes diff(C) :: [h,m,l] ; diff_table ; [course(C,_)].
|
||||
|
||||
bayes int(S) :: [h,m,l] ; int_table ; [student(S)].
|
||||
|
||||
bayes rank(S) :: [a,b,c,d], avg(Grades) ; avg ; [student_ranking(S,Grades)].
|
||||
|
||||
|
||||
grade(Key, Grade) :-
|
||||
registration(Key, CKey, SKey),
|
||||
grade(CKey, SKey, Grade).
|
||||
|
||||
reg_sat(CKey, SKey, PKey) :-
|
||||
registration(_Key, CKey, SKey),
|
||||
course(CKey, PKey).
|
||||
|
||||
course_rating(CKey, Sats) :-
|
||||
course(CKey, _),
|
||||
setof(sat(CKey,SKey,PKey),
|
||||
reg_sat(CKey, SKey, PKey),
|
||||
Sats).
|
||||
|
||||
student_ranking(SKey, Grades) :-
|
||||
student(SKey),
|
||||
setof(grade(CKey,SKey), RKey^registration(RKey,CKey,SKey), Grades).
|
||||
|
||||
:- ensure_loaded(tables).
|
||||
|
||||
%
|
||||
% evidence
|
||||
%
|
||||
abi(p0, h).
|
||||
|
||||
pop(p1, m).
|
||||
pop(p2, h).
|
||||
|
||||
% Query
|
||||
% ?- abi(p0, X).
|
||||
|
@@ -18428,5 +18428,5 @@ registration(r13919,c221,s4095).
|
||||
registration(r13920,c39,s4095).
|
||||
|
||||
|
||||
% :- [evidence_128].
|
||||
:- [evidence_128].
|
||||
|
||||
|
@@ -15,9 +15,7 @@ total_students(256).
|
||||
|
||||
:- yap_flag(write_strings,on).
|
||||
|
||||
:- use_module(library(clpbn)).
|
||||
|
||||
:- [-schema].
|
||||
:- [-parschema].
|
||||
|
||||
professor(p0).
|
||||
professor(p1).
|
||||
|
@@ -1,27 +1,31 @@
|
||||
|
||||
int_table(_, [0.5,
|
||||
0.4,
|
||||
0.1],[h, m, l]).
|
||||
int_table(_,T ,[h, m, l]) :- int_table(T).
|
||||
|
||||
int_table([0.5,
|
||||
0.4,
|
||||
0.1]).
|
||||
|
||||
/* h h h m h l m h m m m l l h l m l l */
|
||||
grade_table([
|
||||
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 ]).
|
||||
|
||||
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])).
|
||||
p([a,b,c,d], T, [I,D])) :- grade_table(T).
|
||||
|
||||
|
||||
sat_table(
|
||||
/* h a h b h c h d m a m b m c m d l a l b l c l d */
|
||||
/*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: 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])).
|
||||
satisfaction_table(A, G, p([h,m,l], T, [A,G])) :- sat_table(T).
|
||||
|
||||
|
||||
% The idea is quite simple:
|
||||
@@ -35,11 +39,18 @@ rating_prob_table([0.9,0.05,0.01,
|
||||
0.09,0.9,0.09,
|
||||
0.01,0.05,0.9]).
|
||||
|
||||
abi_table( _, [0.50, 0.40, 0.10]).
|
||||
abi_table( [0.50, 0.40, 0.10]).
|
||||
|
||||
abi_table( _, T) :- abi_table(T).
|
||||
|
||||
|
||||
pop_table(_, [0.9, 0.2, 0.01,
|
||||
0.09, 0.6, 0.09,
|
||||
0.01, 0.2, 0.9]).
|
||||
pop_table( [0.9, 0.2, 0.01,
|
||||
0.09, 0.6, 0.09,
|
||||
0.01, 0.2, 0.9]).
|
||||
|
||||
pop_table(_, T) :- pop_table(T).
|
||||
|
||||
diff_table([0.25, 0.50, 0.25]).
|
||||
|
||||
dif_table(_, T) :- diff_table(T).
|
||||
|
||||
dif_table( _, [0.25, 0.50, 0.25]).
|
||||
|
Reference in New Issue
Block a user