Use tabs instead of spaces for consistency
This commit is contained in:
parent
d03ea1509e
commit
2738c0fb56
@ -5,34 +5,34 @@
|
||||
********************************************************/
|
||||
|
||||
:- module(clpbn_horus,
|
||||
[set_solver/1,
|
||||
set_horus_flag/1,
|
||||
cpp_create_lifted_network/3,
|
||||
cpp_create_ground_network/4,
|
||||
cpp_set_parfactors_params/2,
|
||||
cpp_set_factors_params/2,
|
||||
cpp_run_lifted_solver/3,
|
||||
cpp_run_ground_solver/3,
|
||||
cpp_set_vars_information/2,
|
||||
cpp_set_horus_flag/2,
|
||||
cpp_free_lifted_network/1,
|
||||
cpp_free_ground_network/1
|
||||
]).
|
||||
[set_solver/1,
|
||||
set_horus_flag/1,
|
||||
cpp_create_lifted_network/3,
|
||||
cpp_create_ground_network/4,
|
||||
cpp_set_parfactors_params/2,
|
||||
cpp_set_factors_params/2,
|
||||
cpp_run_lifted_solver/3,
|
||||
cpp_run_ground_solver/3,
|
||||
cpp_set_vars_information/2,
|
||||
cpp_set_horus_flag/2,
|
||||
cpp_free_lifted_network/1,
|
||||
cpp_free_ground_network/1
|
||||
]).
|
||||
|
||||
:- use_module(library(clpbn),
|
||||
[set_clpbn_flag/2]).
|
||||
[set_clpbn_flag/2]).
|
||||
|
||||
|
||||
patch_things_up :-
|
||||
assert_static(clpbn_horus:cpp_set_horus_flag(_,_)).
|
||||
assert_static(clpbn_horus:cpp_set_horus_flag(_,_)).
|
||||
|
||||
|
||||
warning :-
|
||||
format(user_error,"Horus library not installed: cannot use bp, fove~n.",[]).
|
||||
format(user_error,"Horus library not installed: cannot use bp, fove~n.",[]).
|
||||
|
||||
|
||||
:- catch(load_foreign_files([horus], [], init_predicates), _, patch_things_up)
|
||||
-> true ; warning.
|
||||
-> true ; warning.
|
||||
|
||||
|
||||
set_solver(ve) :- !, set_clpbn_flag(solver,ve).
|
||||
|
@ -1,46 +1,46 @@
|
||||
/*******************************************************
|
||||
|
||||
Interface to Horus Ground Solvers. Used by:
|
||||
- Variable Elimination
|
||||
- Belief Propagation
|
||||
- Counting Belief Propagation
|
||||
- Variable Elimination
|
||||
- Belief Propagation
|
||||
- Counting Belief Propagation
|
||||
|
||||
********************************************************/
|
||||
|
||||
:- module(clpbn_horus_ground,
|
||||
[call_horus_ground_solver/6,
|
||||
check_if_horus_ground_solver_done/1,
|
||||
init_horus_ground_solver/5,
|
||||
run_horus_ground_solver/3,
|
||||
finalize_horus_ground_solver/1
|
||||
]).
|
||||
[call_horus_ground_solver/6,
|
||||
check_if_horus_ground_solver_done/1,
|
||||
init_horus_ground_solver/5,
|
||||
run_horus_ground_solver/3,
|
||||
finalize_horus_ground_solver/1
|
||||
]).
|
||||
|
||||
:- use_module(horus,
|
||||
[cpp_create_ground_network/4,
|
||||
cpp_set_factors_params/2,
|
||||
cpp_run_ground_solver/3,
|
||||
cpp_set_vars_information/2,
|
||||
cpp_free_ground_network/1,
|
||||
set_solver/1
|
||||
]).
|
||||
[cpp_create_ground_network/4,
|
||||
cpp_set_factors_params/2,
|
||||
cpp_run_ground_solver/3,
|
||||
cpp_set_vars_information/2,
|
||||
cpp_free_ground_network/1,
|
||||
set_solver/1
|
||||
]).
|
||||
|
||||
:- use_module(library('clpbn/dists'),
|
||||
[dist/4,
|
||||
get_dist_domain/2,
|
||||
get_dist_domain_size/2,
|
||||
get_dist_params/2
|
||||
]).
|
||||
[dist/4,
|
||||
get_dist_domain/2,
|
||||
get_dist_domain_size/2,
|
||||
get_dist_params/2
|
||||
]).
|
||||
|
||||
:- use_module(library('clpbn/display'),
|
||||
[clpbn_bind_vals/3]).
|
||||
[clpbn_bind_vals/3]).
|
||||
|
||||
:- use_module(library('clpbn/numbers')).
|
||||
|
||||
:- use_module(library(charsio),
|
||||
[term_to_atom/2]).
|
||||
[term_to_atom/2]).
|
||||
|
||||
:- use_module(library(pfl),
|
||||
[skolem/2]).
|
||||
[skolem/2]).
|
||||
|
||||
:- use_module(library(maplist)).
|
||||
|
||||
@ -52,32 +52,32 @@
|
||||
|
||||
|
||||
call_horus_ground_solver(QueryVars, QueryKeys, AllKeys, Factors, Evidence, Output) :-
|
||||
init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, State),
|
||||
run_horus_ground_solver([QueryKeys], Solutions, State),
|
||||
clpbn_bind_vals([QueryVars], Solutions, Output),
|
||||
finalize_horus_ground_solver(State).
|
||||
|
||||
init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, State),
|
||||
run_horus_ground_solver([QueryKeys], Solutions, State),
|
||||
clpbn_bind_vals([QueryVars], Solutions, Output),
|
||||
finalize_horus_ground_solver(State).
|
||||
|
||||
|
||||
run_horus_ground_solver(QueryKeys, Solutions, state(Network,Hash,Id)) :-
|
||||
%get_dists_parameters(DistIds, DistsParams),
|
||||
%cpp_set_factors_params(Network, DistsParams),
|
||||
lists_of_keys_to_ids(QueryKeys, QueryIds, Hash, _, Id, _),
|
||||
cpp_run_ground_solver(Network, QueryIds, Solutions).
|
||||
%get_dists_parameters(DistIds, DistsParams),
|
||||
%cpp_set_factors_params(Network, DistsParams),
|
||||
lists_of_keys_to_ids(QueryKeys, QueryIds, Hash, _, Id, _),
|
||||
cpp_run_ground_solver(Network, QueryIds, Solutions).
|
||||
|
||||
|
||||
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),
|
||||
%writeln(network:(Type, FactorIds, EvidenceIds, Network)), writeln(''),
|
||||
maplist(get_var_information, AllKeys, StatesNames),
|
||||
maplist(term_to_atom, AllKeys, KeysAtoms),
|
||||
cpp_set_vars_information(KeysAtoms, StatesNames).
|
||||
get_factors_type(Factors, Type),
|
||||
keys_to_numbers(AllKeys, Factors, Evidence, Hash4, Id4, FactorIds, EvidenceIds),
|
||||
cpp_create_ground_network(Type, FactorIds, EvidenceIds, Network),
|
||||
%writeln(network:(Type, FactorIds, EvidenceIds, Network)), writeln(''),
|
||||
maplist(get_var_information, AllKeys, StatesNames),
|
||||
maplist(term_to_atom, AllKeys, KeysAtoms),
|
||||
cpp_set_vars_information(KeysAtoms, StatesNames).
|
||||
|
||||
|
||||
% TODO this is not beeing called!
|
||||
finalize_horus_ground_solver(state(Network,_Hash,_Id)) :-
|
||||
cpp_free_ground_network(Network).
|
||||
cpp_free_ground_network(Network).
|
||||
|
||||
|
||||
get_factors_type([f(bayes, _, _)|_], bayes) :- ! .
|
||||
@ -85,13 +85,13 @@ get_factors_type([f(markov, _, _)|_], markov) :- ! .
|
||||
|
||||
|
||||
get_var_information(_:Key, Domain) :- !,
|
||||
skolem(Key, Domain).
|
||||
skolem(Key, Domain).
|
||||
get_var_information(Key, Domain) :-
|
||||
skolem(Key, Domain).
|
||||
skolem(Key, Domain).
|
||||
|
||||
|
||||
%get_dists_parameters([],[]).
|
||||
%get_dists_parameters([Id|Ids], [dist(Id, Params)|DistsInfo]) :-
|
||||
% get_dist_params(Id, Params),
|
||||
% get_dists_parameters(Ids, DistsInfo).
|
||||
% get_dist_params(Id, Params),
|
||||
% get_dists_parameters(Ids, DistsInfo).
|
||||
|
||||
|
@ -1,67 +1,67 @@
|
||||
/*******************************************************
|
||||
|
||||
Interface to Horus Lifted Solvers. Used by:
|
||||
- Generalized Counting First-Order Variable Elimination (GC-FOVE)
|
||||
- Lifted First-Order Belief Propagation
|
||||
- Lifted First-Order Knowledge Compilation
|
||||
- Generalized Counting First-Order Variable Elimination (GC-FOVE)
|
||||
- Lifted First-Order Belief Propagation
|
||||
- Lifted First-Order Knowledge Compilation
|
||||
|
||||
********************************************************/
|
||||
|
||||
:- module(clpbn_horus_lifted,
|
||||
[call_horus_lifted_solver/3,
|
||||
check_if_horus_lifted_solver_done/1,
|
||||
init_horus_lifted_solver/4,
|
||||
run_horus_lifted_solver/3,
|
||||
finalize_horus_lifted_solver/1
|
||||
]).
|
||||
[call_horus_lifted_solver/3,
|
||||
check_if_horus_lifted_solver_done/1,
|
||||
init_horus_lifted_solver/4,
|
||||
run_horus_lifted_solver/3,
|
||||
finalize_horus_lifted_solver/1
|
||||
]).
|
||||
|
||||
:- use_module(horus,
|
||||
[cpp_create_lifted_network/3,
|
||||
cpp_set_parfactors_params/2,
|
||||
cpp_run_lifted_solver/3,
|
||||
cpp_free_lifted_network/1
|
||||
]).
|
||||
[cpp_create_lifted_network/3,
|
||||
cpp_set_parfactors_params/2,
|
||||
cpp_run_lifted_solver/3,
|
||||
cpp_free_lifted_network/1
|
||||
]).
|
||||
|
||||
:- use_module(library('clpbn/display'),
|
||||
[clpbn_bind_vals/3]).
|
||||
[clpbn_bind_vals/3]).
|
||||
|
||||
:- use_module(library('clpbn/dists'),
|
||||
[get_dist_params/2]).
|
||||
[get_dist_params/2]).
|
||||
|
||||
:- use_module(library(pfl),
|
||||
[factor/6,
|
||||
skolem/2,
|
||||
get_pfl_parameters/2
|
||||
]).
|
||||
[factor/6,
|
||||
skolem/2,
|
||||
get_pfl_parameters/2
|
||||
]).
|
||||
|
||||
|
||||
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(_, AllVars, _, State),
|
||||
run_horus_lifted_solver(QueryVars, Solutions, State),
|
||||
clpbn_bind_vals(QueryVars, Solutions, Output),
|
||||
finalize_horus_lifted_solver(State).
|
||||
|
||||
|
||||
init_horus_lifted_solver(_, AllVars, _, state(ParfactorList, DistIds)) :-
|
||||
get_parfactors(Parfactors),
|
||||
get_dist_ids(Parfactors, DistIds0),
|
||||
sort(DistIds0, DistIds),
|
||||
get_observed_vars(AllVars, ObservedVars),
|
||||
%writeln(parfactors:Parfactors:'\n'),
|
||||
%writeln(evidence:ObservedVars:'\n'),
|
||||
cpp_create_lifted_network(Parfactors, ObservedVars, ParfactorList).
|
||||
get_parfactors(Parfactors),
|
||||
get_dist_ids(Parfactors, DistIds0),
|
||||
sort(DistIds0, DistIds),
|
||||
get_observed_vars(AllVars, ObservedVars),
|
||||
%writeln(parfactors:Parfactors:'\n'),
|
||||
%writeln(evidence:ObservedVars:'\n'),
|
||||
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).
|
||||
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).
|
||||
cpp_free_lifted_network(ParfactorList).
|
||||
|
||||
|
||||
:- table get_parfactors/1.
|
||||
@ -77,72 +77,73 @@ finalize_horus_lifted_solver(state(ParfactorList, _)) :-
|
||||
% Tuples: ground bindings for variables in Vs, of the form [fv(x,y)]
|
||||
%
|
||||
get_parfactors(Factors) :-
|
||||
findall(F, is_factor(F), Factors).
|
||||
findall(F, is_factor(F), Factors).
|
||||
|
||||
|
||||
is_factor(pf(Id, Ks, Rs, Phi, Tuples)) :-
|
||||
factor(_Type, Id, Ks, Vs, Table, Constraints),
|
||||
get_ranges(Ks,Rs),
|
||||
Table \= avg,
|
||||
gen_table(Table, Phi),
|
||||
all_tuples(Constraints, Vs, Tuples).
|
||||
factor(_Type, Id, Ks, Vs, Table, Constraints),
|
||||
get_ranges(Ks,Rs),
|
||||
Table \= avg,
|
||||
gen_table(Table, Phi),
|
||||
all_tuples(Constraints, Vs, Tuples).
|
||||
|
||||
|
||||
get_ranges([],[]).
|
||||
get_ranges(K.Ks, Range.Rs) :- !,
|
||||
skolem(K,Domain),
|
||||
length(Domain,Range),
|
||||
get_ranges(Ks, Rs).
|
||||
skolem(K,Domain),
|
||||
length(Domain,Range),
|
||||
get_ranges(Ks, Rs).
|
||||
|
||||
|
||||
gen_table(Table, Phi) :-
|
||||
( is_list(Table)
|
||||
->
|
||||
Phi = Table
|
||||
;
|
||||
call(user:Table, Phi)
|
||||
).
|
||||
(
|
||||
is_list(Table)
|
||||
->
|
||||
Phi = Table
|
||||
;
|
||||
call(user:Table, Phi)
|
||||
).
|
||||
|
||||
|
||||
all_tuples(Constraints, Tuple, Tuples) :-
|
||||
setof(Tuple, Constraints^run(Constraints), Tuples).
|
||||
setof(Tuple, Constraints^run(Constraints), Tuples).
|
||||
|
||||
|
||||
run([]).
|
||||
run(Goal.Constraints) :-
|
||||
user:Goal,
|
||||
run(Constraints).
|
||||
user:Goal,
|
||||
run(Constraints).
|
||||
|
||||
|
||||
get_dist_ids([], []).
|
||||
get_dist_ids(pf(Id, _, _, _, _).Parfactors, Id.DistIds) :-
|
||||
get_dist_ids(Parfactors, DistIds).
|
||||
get_dist_ids(Parfactors, DistIds).
|
||||
|
||||
|
||||
get_observed_vars([], []).
|
||||
get_observed_vars(V.AllAttVars, [K:E|ObservedVars]) :-
|
||||
clpbn:get_atts(V,[key(K)]),
|
||||
( clpbn:get_atts(V,[evidence(E)]) ; pfl:evidence(K,E) ), !,
|
||||
get_observed_vars(AllAttVars, ObservedVars).
|
||||
clpbn:get_atts(V,[key(K)]),
|
||||
( clpbn:get_atts(V,[evidence(E)]) ; pfl:evidence(K,E) ), !,
|
||||
get_observed_vars(AllAttVars, ObservedVars).
|
||||
get_observed_vars(V.AllAttVars, ObservedVars) :-
|
||||
clpbn:get_atts(V,[key(_K)]), !,
|
||||
get_observed_vars(AllAttVars, ObservedVars).
|
||||
clpbn:get_atts(V,[key(_K)]), !,
|
||||
get_observed_vars(AllAttVars, ObservedVars).
|
||||
|
||||
|
||||
get_query_keys([], []).
|
||||
get_query_keys(E1.L1, E2.L2) :-
|
||||
get_query_keys_2(E1,E2),
|
||||
get_query_keys(L1, L2).
|
||||
get_query_keys_2(E1,E2),
|
||||
get_query_keys(L1, L2).
|
||||
|
||||
|
||||
get_query_keys_2([], []).
|
||||
get_query_keys_2(V.AttVars, [RV|RVs]) :-
|
||||
clpbn:get_atts(V,[key(RV)]), !,
|
||||
get_query_keys_2(AttVars, RVs).
|
||||
clpbn:get_atts(V,[key(RV)]), !,
|
||||
get_query_keys_2(AttVars, RVs).
|
||||
|
||||
|
||||
get_dists_parameters([], []).
|
||||
get_dists_parameters([Id|Ids], [dist(Id, Params)|DistsInfo]) :-
|
||||
get_pfl_parameters(Id, Params),
|
||||
get_dists_parameters(Ids, DistsInfo).
|
||||
get_pfl_parameters(Id, Params),
|
||||
get_dists_parameters(Ids, DistsInfo).
|
||||
|
||||
|
Reference in New Issue
Block a user