start with pfl learning.
This commit is contained in:
71
packages/CLPBN/examples/learning/school_params.yap
Normal file
71
packages/CLPBN/examples/learning/school_params.yap
Normal file
File diff suppressed because one or more lines are too long
40
packages/CLPBN/examples/learning/sprinkler_params.yap
Normal file
40
packages/CLPBN/examples/learning/sprinkler_params.yap
Normal file
@@ -0,0 +1,40 @@
|
||||
% learn distribution for school database.
|
||||
|
||||
:- ['../sprinkler.pfl'].
|
||||
|
||||
:- use_module(library(clpbn/learning/em)).
|
||||
|
||||
%% data(t,t,t,t).
|
||||
data(t,f,_,t).
|
||||
%% data(_,t,_,t).
|
||||
%% data(t,t,f,f).
|
||||
%% data(t,t,f,t).
|
||||
%% data(t,_,_,t).
|
||||
%% data(t,f,t,t).
|
||||
%% data(t,t,f,t).
|
||||
%% data(t,_,f,f).
|
||||
%% data(t,t,f,f).
|
||||
%% data(f,f,t,t).
|
||||
%% data(t,t,_,f).
|
||||
%% data(t,f,f,t).
|
||||
%% data(t,f,t,t).
|
||||
|
||||
%:- clpbn:set_clpbn_flag(em_solver,gibbs).
|
||||
%:- clpbn:set_clpbn_flag(em_solver,jt).
|
||||
%:- clpbn:set_clpbn_flag(em_solver,ve).
|
||||
:- clpbn:set_clpbn_flag(em_solver,bp).
|
||||
|
||||
timed_main :-
|
||||
statistics(runtime, _),
|
||||
main(Lik),
|
||||
statistics(runtime, [T,_]),
|
||||
format('Took ~d msec and Lik ~3f~n',[T,Lik]).
|
||||
|
||||
main(Lik) :-
|
||||
findall(X,scan_data(X),L),
|
||||
em(L,0.01,10,_,Lik).
|
||||
|
||||
scan_data(example([wet_grass(W),sprinkler(S),rain(R),cloudy(C)])) :-
|
||||
data(W, S, R, C).
|
||||
|
||||
|
2433
packages/CLPBN/examples/learning/train.yap
Normal file
2433
packages/CLPBN/examples/learning/train.yap
Normal file
File diff suppressed because it is too large
Load Diff
33
packages/CLPBN/examples/sprinkler.pfl
Normal file
33
packages/CLPBN/examples/sprinkler.pfl
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
:- style_check(all).
|
||||
|
||||
:- ensure_loaded(library(pfl)).
|
||||
|
||||
% 1. define domain of random variables
|
||||
% not necessary if they are boolean.
|
||||
|
||||
% 2. define parfactors
|
||||
|
||||
bayes cloudy ; cloudy_table ; [].
|
||||
|
||||
bayes sprinkler, cloudy ; sprinkler_table ; [].
|
||||
|
||||
bayes rain, cloudy ; rain_table ; [].
|
||||
|
||||
bayes wet_grass, sprinkler, rain ; wet_grass_table ; [].
|
||||
|
||||
|
||||
% 3. define CPTs.
|
||||
|
||||
wet_grass_table([1.0,0.1,0.1,0.01,
|
||||
0.0,0.9,0.9,0.99]).
|
||||
|
||||
sprinkler_table([0.5,0.9,
|
||||
0.5,0.1]).
|
||||
|
||||
rain_table([0.8,0.2,
|
||||
0.2,0.8]).
|
||||
|
||||
cloudy_table([0.5,0.5]).
|
||||
|
||||
|
Reference in New Issue
Block a user