refactor horus_ground and horus_lifted
This commit is contained in:
parent
992d06656d
commit
4afe6c8161
@ -52,13 +52,13 @@
|
||||
|
||||
|
||||
call_horus_ground_solver(QueryVars, QueryKeys, AllKeys, Factors, Evidence, Output) :-
|
||||
init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, Network),
|
||||
run_solver(Network, [QueryKeys], Solutions),
|
||||
init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, State),
|
||||
run_solver(State, [QueryKeys], Solutions),
|
||||
clpbn_bind_vals([QueryVars], Solutions, Output),
|
||||
finalize_horus_ground_solver(Network).
|
||||
finalize_horus_ground_solver(State).
|
||||
|
||||
|
||||
init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, ground(Network,Hash4,Id4)) :-
|
||||
init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, state(Network,Hash4,Id4)) :-
|
||||
get_factors_type(Factors, Type),
|
||||
keys_to_numbers(AllKeys, Factors, Evidence, Hash4, Id4, FactorIds, EvidenceIds),
|
||||
cpp_create_ground_network(Type, FactorIds, EvidenceIds, Network),
|
||||
@ -74,11 +74,11 @@ run_horus_ground_solver(_QueryVars, Solutions, horus(GKeys, Keys, Factors, Evide
|
||||
|
||||
|
||||
% TODO this is not beeing called!
|
||||
finalize_horus_ground_solver(ground(Network,_Hash,_Id)) :-
|
||||
finalize_horus_ground_solver(state(Network,_Hash,_Id)) :-
|
||||
cpp_free_ground_network(Network).
|
||||
|
||||
|
||||
run_solver(ground(Network,Hash,Id), QueryKeys, Solutions) :-
|
||||
run_solver(state(Network,Hash,Id), QueryKeys, Solutions) :-
|
||||
%get_dists_parameters(DistIds, DistsParams),
|
||||
%cpp_set_factors_params(Network, DistsParams),
|
||||
lists_of_keys_to_ids(QueryKeys, QueryIds, Hash, _, Id, _),
|
||||
|
@ -1,8 +1,10 @@
|
||||
/*******************************************************
|
||||
|
||||
Interface to Horus Lifted Solvers. Used by:
|
||||
- Lifted Variable Elimination
|
||||
- Generalized Counting First-Order Variable Elimination (GC-FOVE)
|
||||
- Lifted First-Order Belief Propagation
|
||||
- Lifted First-Order Knowledge Compilation
|
||||
|
||||
********************************************************/
|
||||
|
||||
:- module(clpbn_horus_lifted,
|
||||
@ -33,22 +35,33 @@
|
||||
]).
|
||||
|
||||
|
||||
call_horus_lifted_solver([[]], _, _) :- !.
|
||||
call_horus_lifted_solver([QueryVars], AllVars, Output) :-
|
||||
init_horus_lifted_solver(_, AllVars, _, ParfactorList),
|
||||
run_horus_lifted_solver([QueryVars], LPs, ParfactorList),
|
||||
finalize_horus_lifted_solver(ParfactorList),
|
||||
clpbn_bind_vals([QueryVars], LPs, Output).
|
||||
call_horus_lifted_solver(QueryVars, AllVars, Output) :-
|
||||
init_horus_lifted_solver(_, AllVars, _, State),
|
||||
run_horus_lifted_solver(QueryVars, Solutions, State),
|
||||
clpbn_bind_vals(QueryVars, Solutions, Output),
|
||||
finalize_horus_lifted_solver(State).
|
||||
|
||||
|
||||
init_horus_lifted_solver(_, AllAttVars, _, fove(ParfactorList, DistIds)) :-
|
||||
init_horus_lifted_solver(_, AllVars, _, state(ParfactorList, DistIds)) :-
|
||||
get_parfactors(Parfactors),
|
||||
get_dist_ids(Parfactors, DistIds0),
|
||||
sort(DistIds0, DistIds),
|
||||
get_observed_vars(AllAttVars, ObservedVars),
|
||||
get_observed_vars(AllVars, ObservedVars),
|
||||
%writeln(parfactors:Parfactors:'\n'),
|
||||
%writeln(evidence:ObservedVars:'\n'),
|
||||
cpp_create_lifted_network(Parfactors,ObservedVars,ParfactorList).
|
||||
cpp_create_lifted_network(Parfactors, ObservedVars, ParfactorList).
|
||||
|
||||
|
||||
run_horus_lifted_solver(QueryVars, Solutions, state(ParfactorList, DistIds)) :-
|
||||
get_query_keys(QueryVars, QueryKeys),
|
||||
get_dists_parameters(DistIds, DistsParams),
|
||||
%writeln(dists:DistsParams), writeln(''),
|
||||
cpp_set_parfactors_params(ParfactorList, DistsParams),
|
||||
cpp_run_lifted_solver(ParfactorList, QueryKeys, Solutions).
|
||||
|
||||
|
||||
finalize_horus_lifted_solver(state(ParfactorList, _)) :-
|
||||
cpp_free_lifted_network(ParfactorList).
|
||||
|
||||
|
||||
:- table get_parfactors/1.
|
||||
@ -76,7 +89,7 @@ is_factor(pf(Id, Ks, Rs, Phi, Tuples)) :-
|
||||
|
||||
|
||||
get_ranges([],[]).
|
||||
get_ranges(K.Ks, Range.Rs) :- !,
|
||||
get_ranges(K.Ks, Range.Rs) :- !,
|
||||
skolem(K,Domain),
|
||||
length(Domain,Range),
|
||||
get_ranges(Ks, Rs).
|
||||
@ -116,16 +129,16 @@ get_observed_vars(V.AllAttVars, ObservedVars) :-
|
||||
get_observed_vars(AllAttVars, ObservedVars).
|
||||
|
||||
|
||||
get_query_vars([], []).
|
||||
get_query_vars(E1.L1, E2.L2) :-
|
||||
get_query_vars_2(E1,E2),
|
||||
get_query_vars(L1, L2).
|
||||
get_query_keys([], []).
|
||||
get_query_keys(E1.L1, E2.L2) :-
|
||||
get_query_keys_2(E1,E2),
|
||||
get_query_keys(L1, L2).
|
||||
|
||||
|
||||
get_query_vars_2([], []).
|
||||
get_query_vars_2(V.AttVars, [RV|RVs]) :-
|
||||
get_query_keys_2([], []).
|
||||
get_query_keys_2(V.AttVars, [RV|RVs]) :-
|
||||
clpbn:get_atts(V,[key(RV)]), !,
|
||||
get_query_vars_2(AttVars, RVs).
|
||||
get_query_keys_2(AttVars, RVs).
|
||||
|
||||
|
||||
get_dists_parameters([], []).
|
||||
@ -133,16 +146,3 @@ get_dists_parameters([Id|Ids], [dist(Id, Params)|DistsInfo]) :-
|
||||
get_pfl_parameters(Id, Params),
|
||||
get_dists_parameters(Ids, DistsInfo).
|
||||
|
||||
|
||||
run_horus_lifted_solver(QueryVarsAtts, Solutions, fove(ParfactorList, DistIds)) :-
|
||||
get_query_vars(QueryVarsAtts, QueryVars),
|
||||
%writeln(queryVars:QueryVars), writeln(''),
|
||||
get_dists_parameters(DistIds, DistsParams),
|
||||
%writeln(dists:DistsParams), writeln(''),
|
||||
cpp_set_parfactors_params(ParfactorList, DistsParams),
|
||||
cpp_run_lifted_solver(ParfactorList, QueryVars, Solutions).
|
||||
|
||||
|
||||
finalize_horus_lifted_solver(fove(ParfactorList, _)) :-
|
||||
cpp_free_lifted_network(ParfactorList).
|
||||
|
||||
|
Reference in New Issue
Block a user