fix gibbs EM in case we have 0 elements.
This commit is contained in:
parent
7f365f7377
commit
0028072865
@ -517,7 +517,6 @@ update_estimate_for_var(V0,[X|T],[X1|NT]) :-
|
|||||||
).
|
).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
check_if_gibbs_done(Var) :-
|
check_if_gibbs_done(Var) :-
|
||||||
get_atts(Var, [dist(_)]), !.
|
get_atts(Var, [dist(_)]), !.
|
||||||
|
|
||||||
|
@ -65,7 +65,6 @@ init_em(Items, state(AllVars, AllDists, AllDistInstances, MargVars)) :-
|
|||||||
em_loop(Its, Likelihood0, State, MaxError, MaxIts, LikelihoodF, FTables) :-
|
em_loop(Its, Likelihood0, State, MaxError, MaxIts, LikelihoodF, FTables) :-
|
||||||
estimate(State, LPs),
|
estimate(State, LPs),
|
||||||
maximise(State, Tables, LPs, Likelihood),
|
maximise(State, Tables, LPs, Likelihood),
|
||||||
(recorded(clpbn_dist_db, DB, _), writeln(DB), fail ; true),
|
|
||||||
writeln(Likelihood:Tables),
|
writeln(Likelihood:Tables),
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
matrix_op_to_lines/4,
|
matrix_op_to_lines/4,
|
||||||
matrix_to_logs/2,
|
matrix_to_logs/2,
|
||||||
matrix_op/4,
|
matrix_op/4,
|
||||||
matrix_sum/2]).
|
matrix_sum/2,
|
||||||
|
matrix_to_list/2]).
|
||||||
|
|
||||||
:- meta_predicate run_all(:).
|
:- meta_predicate run_all(:).
|
||||||
|
|
||||||
@ -55,7 +56,14 @@ normalise_counts(MAT,NMAT) :-
|
|||||||
|
|
||||||
compute_likelihood(Table0, NewTable, DeltaLik) :-
|
compute_likelihood(Table0, NewTable, DeltaLik) :-
|
||||||
matrix_to_logs(NewTable, Logs),
|
matrix_to_logs(NewTable, Logs),
|
||||||
matrix_op(Table0, Logs, *, Logs),
|
matrix_to_list(Table0,L1),
|
||||||
matrix_sum(Logs, DeltaLik).
|
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).
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user