This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/CLPBN/examples/learning/sprinkler_params.yap

50 lines
808 B
Plaintext
Raw Normal View History

2012-12-12 15:16:30 +00:00
/* Learn distribution for a sprinkler database. */
2012-06-22 19:00:12 +01:00
:- ['../sprinkler.pfl'].
:- use_module(library(clpbn/learning/em)).
2012-12-17 21:19:47 +00:00
:- set_em_solver(ve).
%:- set_em_solver(hve).
%:- set_em_solver(bdd).
%:- set_em_solver(bp).
%:- set_em_solver(cbp).
2012-12-12 15:16:30 +00:00
:- dynamic id/1.
2012-09-29 11:50:00 +01:00
data(t,t,t,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).
2012-06-22 19:00:12 +01:00
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),
2012-12-12 15:16:30 +00:00
em(L,0.01,10,_,Lik).
2012-06-22 19:00:12 +01:00
2012-09-29 11:50:00 +01:00
scan_data(I:[wet_grass(W),sprinkler(S),rain(R),cloudy(C)]) :-
data(W, S, R, C),
new_id(I).
new_id(I) :-
2012-12-12 15:16:30 +00:00
retract(id(I)),
I1 is I+1,
assert(id(I1)).
2012-09-29 11:50:00 +01:00
id(0).
2012-06-22 19:00:12 +01:00