From e56e1cbacba65ceaac0da0b96867d9fd9f0d51cc Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sat, 24 Sep 2011 21:39:37 +0100 Subject: [PATCH] small fixes --- packages/CLPBN/learning/aleph_params.yap | 8 ++++++-- packages/CLPBN/learning/em.yap | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/CLPBN/learning/aleph_params.yap b/packages/CLPBN/learning/aleph_params.yap index ea49bc0c3..dc2a6a165 100644 --- a/packages/CLPBN/learning/aleph_params.yap +++ b/packages/CLPBN/learning/aleph_params.yap @@ -35,6 +35,7 @@ clpbn_tabled_clause/2, clpbn_tabled_number_of_clauses/2, clpbn_is_tabled/1, + clpbn_reset_tables/0, clpbn_tabled_dynamic/1]). % @@ -90,7 +91,9 @@ store_theory(_,_,_) :- store_theory(_,(H:-_),_) :- clpbn_is_tabled(user:H), !, store_tabled_theory(H). -store_theory(_,(H:-_),_) :- +store_theory(_,(H:-_),_) :- !, + store_theory(H). +store_theory(_,H,_) :- store_theory(H). store_tabled_theory(H) :- @@ -163,6 +166,7 @@ user:cost((H :- B),Inf,Score) :- !, ( clpbn_is_tabled(user:H) -> + clpbn_reset_tables, clpbn_tabled_asserta(user:(H :- IB), R) ; asserta(user:(H :- IB), R) @@ -251,7 +255,7 @@ key_from_head(H,K,V) :- rewrite_body((A,B), (user:NA,NB), [V|Vs], [D|Ds], Tail) :- rewrite_goal(A, V, D, NA), !, rewrite_body(B, NB, Vs, Ds, Tail). -rewrite_body((A,B), (user:A,NB), Vs, Ds, Tail) :- +rewrite_body((A,B), (user:A,NB), Vs, Ds, Tail) :- !, rewrite_body(B,NB, Vs, Ds, Tail). rewrite_body(A,(user:NA,Tail), [V], [D], Tail) :- rewrite_goal(A, V, D, NA), !. diff --git a/packages/CLPBN/learning/em.yap b/packages/CLPBN/learning/em.yap index a09eac3f0..960e10ad5 100644 --- a/packages/CLPBN/learning/em.yap +++ b/packages/CLPBN/learning/em.yap @@ -203,6 +203,8 @@ compute_parameters([], [], _, Lik, Lik, _). compute_parameters([Id-Samples|Dists], [Id-NewTable|Tables], MDistTable, Lik0, Lik, LPs:MargVars) :- empty_dist(Id, Table0), add_samples(Samples, Table0, MDistTable), +%matrix_to_list(Table0,Mat), +%format(user_error, 'FINAL ~d ~w~n', [Id,Mat]), soften_sample(Table0, SoftenedTable), % matrix:matrix_sum(Table0,TotM), normalise_counts(SoftenedTable, NewTable), @@ -218,6 +220,7 @@ add_samples([i(_,_,[Case],[])|Samples], Table, MDistTable) :- !, add_samples([i(_,_,Cases,Hiddens)|Samples], Table, MDistTable) :- rb_lookup(Hiddens, Ps, MDistTable), run_sample(Cases, Ps, Table), +%matrix_to_list(Table,M), format(user_error, '~w ~w~n', [Cases,Ps]), add_samples(Samples, Table, MDistTable). run_sample([], [], _).