diff --git a/packages/CLPBN/clpbn.yap b/packages/CLPBN/clpbn.yap index 91b148b66..53d31b653 100644 --- a/packages/CLPBN/clpbn.yap +++ b/packages/CLPBN/clpbn.yap @@ -10,9 +10,9 @@ clpbn_init_graph/1, clpbn_init_solver/4, clpbn_run_solver/3, - clpbn_finalize_solver/1, pfl_init_solver/5, pfl_run_solver/3, + pfl_end_solver/1, probability/2, conditional_probability/3, use_parfactors/1, @@ -662,17 +662,9 @@ clpbn_run_solver(gibbs, LVs, LPs, State) :- clpbn_run_solver(pcg, LVs, LPs, State) :- run_pcg_solver(LVs, LPs, State). -%clpbn_finalize_solver(State) :- -% solver(bp), !, -% functor(State, _, Last), -% arg(Last, State, Info), -% finalize_horus_ground_solver(Info). -clpbn_finalize_solver(_State). - % % This is a routine to start a solver, called by the learning procedures (ie, em). % - pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State) :- em_solver(Solver), (lifted_solver(Solver) -> @@ -729,6 +721,11 @@ pfl_run_solver(LVs, LPs, State, bp) :- !, pfl_run_solver(LVs, LPs, State, cbp) :- !, run_horus_ground_solver(LVs, LPs, State). +pfl_end_solver(State) :- + (em_solver(hve) ; em_solver(bp) ; em_solver(cbp)), + finalize_horus_ground_solver(State). +pfl_end_solver(_State). + add_keys(Key1+V1,_Key2,Key1+V1). diff --git a/packages/CLPBN/learning/em.yap b/packages/CLPBN/learning/em.yap index 0e28d3136..8abe4e92d 100644 --- a/packages/CLPBN/learning/em.yap +++ b/packages/CLPBN/learning/em.yap @@ -13,9 +13,9 @@ [clpbn_init_graph/1, clpbn_init_solver/4, clpbn_run_solver/3, - clpbn_finalize_solver/1, pfl_init_solver/5, pfl_run_solver/3, + pfl_end_solver/1, conditional_probability/3, clpbn_flag/2 ]). @@ -75,7 +75,7 @@ em(Items, MaxError, MaxIts, Tables, Likelihood) :- catch(init_em(Items, State),Error,handle_em(Error)), em_loop(0, 0.0, State, MaxError, MaxIts, Likelihood, Tables), - clpbn_finalize_solver(State), + end_em(State), assert(em_found(Tables, Likelihood)), fail. % get rid of new random variables the easy way :) @@ -89,6 +89,12 @@ handle_em(error(repeated_parents)) :- !, handle_em(Error) :- throw(Error). + +end_em(state(_AllDists, _AllDistInstances, _MargKeys, SolverState)) :- + clpbn:use_parfactors(on), !, + pfl_end_solver(SolverState). +end_em(_). + % This gets you an initial configuration. If there is a lot of evidence % tables may be filled in close to optimal, otherwise they may be % close to uniform.