Don't pass around the Solver for EM
This commit is contained in:
parent
81ac6f1913
commit
9ff9be2f49
@ -6,11 +6,9 @@
|
||||
clpbn_key/2,
|
||||
clpbn_init_solver/4,
|
||||
clpbn_run_solver/3,
|
||||
pfl_init_solver/6,
|
||||
pfl_run_solver/4,
|
||||
pfl_init_solver/5,
|
||||
pfl_run_solver/3,
|
||||
clpbn_finalize_solver/1,
|
||||
clpbn_init_solver/5,
|
||||
clpbn_run_solver/4,
|
||||
clpbn_init_graph/1,
|
||||
probability/2,
|
||||
conditional_probability/3,
|
||||
@ -589,21 +587,26 @@ clpbn_run_solver(pcg, LVs, LPs, State) :-
|
||||
%
|
||||
% This is a routine to start a solver, called by the learning procedures (ie, em).
|
||||
%
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, ve) :-
|
||||
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State) :-
|
||||
solver(Solver),
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, Solver).
|
||||
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, ve) :- !,
|
||||
init_ve_ground_solver(QueryKeys, AllKeys, Factors, Evidence, State).
|
||||
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, bdd) :-
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, bdd) :- !,
|
||||
init_bdd_ground_solver(QueryKeys, AllKeys, Factors, Evidence, State).
|
||||
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, hve) :-
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, hve) :- !,
|
||||
clpbn_horus:set_horus_flag(ground_solver, ve),
|
||||
init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, State).
|
||||
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, bp) :-
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, bp) :- !,
|
||||
clpbn_horus:set_horus_flag(ground_solver, bp),
|
||||
init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, State).
|
||||
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, cbp) :-
|
||||
pfl_init_solver(QueryKeys, AllKeys, Factors, Evidence, State, cbp) :- !,
|
||||
clpbn_horus:set_horus_flag(ground_solver, cbp),
|
||||
init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, State).
|
||||
|
||||
@ -611,20 +614,24 @@ pfl_init_solver(_, _, _, _, _, Solver) :-
|
||||
write('Error: solver `'),
|
||||
write(Solver),
|
||||
write('\' cannot be used for learning').
|
||||
|
||||
pfl_run_solver(LVs, LPs, State) :-
|
||||
solver(Solver),
|
||||
pfl_run_solver(LVs, LPs, State, Solver).
|
||||
|
||||
pfl_run_solver(LVs, LPs, State, ve) :-
|
||||
pfl_run_solver(LVs, LPs, State, ve) :- !,
|
||||
run_ve_ground_solver(LVs, LPs, State).
|
||||
|
||||
pfl_run_solver(LVs, LPs, State, bdd) :-
|
||||
pfl_run_solver(LVs, LPs, State, bdd) :- !,
|
||||
run_bdd_ground_solver(LVs, LPs, State).
|
||||
|
||||
pfl_run_solver(LVs, LPs, State, hve) :-
|
||||
pfl_run_solver(LVs, LPs, State, hve) :- !,
|
||||
run_horus_ground_solver(LVs, LPs, State).
|
||||
|
||||
pfl_run_solver(LVs, LPs, State, bp) :-
|
||||
pfl_run_solver(LVs, LPs, State, bp) :- !,
|
||||
run_horus_ground_solver(LVs, LPs, State).
|
||||
|
||||
pfl_run_solver(LVs, LPs, State, cbp) :-
|
||||
pfl_run_solver(LVs, LPs, State, cbp) :- !,
|
||||
run_horus_ground_solver(LVs, LPs, State).
|
||||
|
||||
|
||||
|
@ -15,10 +15,10 @@
|
||||
|
||||
:- use_module(library(clpbn),
|
||||
[clpbn_init_graph/1,
|
||||
clpbn_init_solver/5,
|
||||
clpbn_run_solver/4,
|
||||
pfl_init_solver/6,
|
||||
pfl_run_solver/4,
|
||||
clpbn_init_solver/4,
|
||||
clpbn_run_solver/3,
|
||||
pfl_init_solver/5,
|
||||
pfl_run_solver/3,
|
||||
clpbn_finalize_solver/1,
|
||||
conditional_probability/3,
|
||||
clpbn_flag/2]).
|
||||
@ -110,7 +110,7 @@ setup_em_network(Items, Solver, state( AllDists, AllDistInstances, MargKeys, Sol
|
||||
% get the EM CPT connections info from the factors
|
||||
generate_dists(Factors, EList, AllDists, AllDistInstances, MargKeys),
|
||||
% setup solver, if necessary
|
||||
pfl_init_solver(MargKeys, Keys, Factors, EList, SolverState, Solver).
|
||||
pfl_init_solver(MargKeys, Keys, Factors, EList, SolverState).
|
||||
setup_em_network(Items, Solver, state( AllDists, AllDistInstances, MargVars, SolverVars)) :-
|
||||
% create the ground network
|
||||
call_run_all(Items),
|
||||
@ -121,7 +121,7 @@ setup_em_network(Items, Solver, state( AllDists, AllDistInstances, MargVars, Sol
|
||||
% remove variables that do not have to do with this query.
|
||||
different_dists(AllVars, AllDists, AllDistInstances, MargVars),
|
||||
% setup solver by doing parameter independent work.
|
||||
clpbn_init_solver(Solver, MargVars, AllVars, _, SolverVars).
|
||||
clpbn_init_solver(MargVars, AllVars, _, SolverVars).
|
||||
|
||||
run_examples(user:Exs, Keys, Factors, EList) :-
|
||||
Exs = [_:_|_], !,
|
||||
@ -297,11 +297,9 @@ compact_mvars([X|MargVars], [X|CMVars]) :- !,
|
||||
|
||||
estimate(state(_, _, Margs, SolverState), LPs) :-
|
||||
clpbn:use_parfactors(on), !,
|
||||
clpbn_flag(em_solver, Solver),
|
||||
pfl_run_solver(Margs, LPs, SolverState, Solver).
|
||||
pfl_run_solver(Margs, LPs, SolverState).
|
||||
estimate(state(_, _, Margs, SolverState), LPs) :-
|
||||
clpbn_flag(em_solver, Solver),
|
||||
clpbn_run_solver(Solver, Margs, LPs, SolverState).
|
||||
clpbn_run_solver(Margs, LPs, SolverState).
|
||||
|
||||
maximise(state(_,DistInstances,MargVars,_), Tables, LPs, Likelihood) :-
|
||||
rb_new(MDistTable0),
|
||||
|
@ -23,8 +23,8 @@
|
||||
[clpbn_flag/2 as pfl_flag,
|
||||
set_clpbn_flag/2 as set_pfl_flag,
|
||||
conditional_probability/3,
|
||||
pfl_init_solver/6,
|
||||
pfl_run_solver/4]).
|
||||
pfl_init_solver/5,
|
||||
pfl_run_solver/3]).
|
||||
|
||||
:- reexport(library(clpbn/horus),
|
||||
[set_solver/1]).
|
||||
|
Reference in New Issue
Block a user