diff --git a/CLPBN/clpbn/gibbs.yap b/CLPBN/clpbn/gibbs.yap index 3f1b13d7c..24e0fca6f 100644 --- a/CLPBN/clpbn/gibbs.yap +++ b/CLPBN/clpbn/gibbs.yap @@ -517,7 +517,6 @@ update_estimate_for_var(V0,[X|T],[X1|NT]) :- ). - check_if_gibbs_done(Var) :- get_atts(Var, [dist(_)]), !. diff --git a/CLPBN/learning/em.yap b/CLPBN/learning/em.yap index 5cf154af7..30d9456dc 100644 --- a/CLPBN/learning/em.yap +++ b/CLPBN/learning/em.yap @@ -65,7 +65,6 @@ init_em(Items, state(AllVars, AllDists, AllDistInstances, MargVars)) :- em_loop(Its, Likelihood0, State, MaxError, MaxIts, LikelihoodF, FTables) :- estimate(State, LPs), maximise(State, Tables, LPs, Likelihood), - (recorded(clpbn_dist_db, DB, _), writeln(DB), fail ; true), writeln(Likelihood:Tables), ( ( diff --git a/CLPBN/learning/learn_utils.yap b/CLPBN/learning/learn_utils.yap index 03d96a4a7..be0fe4306 100644 --- a/CLPBN/learning/learn_utils.yap +++ b/CLPBN/learning/learn_utils.yap @@ -12,7 +12,8 @@ matrix_op_to_lines/4, matrix_to_logs/2, matrix_op/4, - matrix_sum/2]). + matrix_sum/2, + matrix_to_list/2]). :- meta_predicate run_all(:). @@ -55,7 +56,14 @@ normalise_counts(MAT,NMAT) :- compute_likelihood(Table0, NewTable, DeltaLik) :- matrix_to_logs(NewTable, Logs), - matrix_op(Table0, Logs, *, Logs), - matrix_sum(Logs, DeltaLik). + matrix_to_list(Table0,L1), + matrix_to_list(Logs,L2), + sum_prods(L1,L2,0,DeltaLik). +sum_prods([],[],DeltaLik,DeltaLik). +sum_prods([0.0|L1],[_|L2],DeltaLik0,DeltaLik) :- !, + sum_prods(L1,L2,DeltaLik0,DeltaLik). +sum_prods([Count|L1],[Log|L2],DeltaLik0,DeltaLik) :- !, + DeltaLik1 is DeltaLik0+Count*Log, + sum_prods(L1,L2,DeltaLik1,DeltaLik).