fix gibbs EM in case we have 0 elements.

This commit is contained in:
Vítor Santos de Costa 2008-10-24 10:36:37 +01:00
parent 7f365f7377
commit 0028072865
3 changed files with 11 additions and 5 deletions

View File

@ -517,7 +517,6 @@ update_estimate_for_var(V0,[X|T],[X1|NT]) :-
).
check_if_gibbs_done(Var) :-
get_atts(Var, [dist(_)]), !.

View File

@ -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),
(
(

View File

@ -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).