2012-03-31 23:27:37 +01:00
|
|
|
/*******************************************************
|
2011-02-23 15:31:56 +00:00
|
|
|
|
2012-05-23 19:15:23 +01:00
|
|
|
Interface to Horus Ground Solvers. Used by:
|
2012-12-17 12:13:08 +00:00
|
|
|
- Variable Elimination
|
|
|
|
- Belief Propagation
|
|
|
|
- Counting Belief Propagation
|
2011-02-23 15:31:56 +00:00
|
|
|
|
2012-03-31 23:27:37 +01:00
|
|
|
********************************************************/
|
2011-05-17 12:00:33 +01:00
|
|
|
|
2012-05-23 19:15:23 +01:00
|
|
|
:- module(clpbn_horus_ground,
|
2012-12-17 12:13:08 +00:00
|
|
|
[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
|
|
|
|
]).
|
2011-02-23 15:31:56 +00:00
|
|
|
|
2012-05-23 19:15:23 +01:00
|
|
|
:- use_module(horus,
|
2012-12-17 12:13:08 +00:00
|
|
|
[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
|
|
|
|
]).
|
2011-05-17 12:00:33 +01:00
|
|
|
|
2011-02-23 15:31:56 +00:00
|
|
|
:- use_module(library('clpbn/dists'),
|
2012-12-17 12:13:08 +00:00
|
|
|
[dist/4,
|
|
|
|
get_dist_domain/2,
|
|
|
|
get_dist_domain_size/2,
|
|
|
|
get_dist_params/2
|
|
|
|
]).
|
2011-02-23 15:31:56 +00:00
|
|
|
|
|
|
|
:- use_module(library('clpbn/display'),
|
2012-12-17 12:13:08 +00:00
|
|
|
[clpbn_bind_vals/3]).
|
2011-02-23 15:31:56 +00:00
|
|
|
|
2012-12-17 11:53:57 +00:00
|
|
|
:- use_module(library('clpbn/numbers')).
|
2012-09-23 13:25:15 +01:00
|
|
|
|
2012-04-03 19:53:27 +01:00
|
|
|
:- use_module(library(charsio),
|
2012-12-17 12:13:08 +00:00
|
|
|
[term_to_atom/2]).
|
2011-05-17 12:00:33 +01:00
|
|
|
|
2012-04-03 19:53:27 +01:00
|
|
|
:- use_module(library(pfl),
|
2012-12-17 12:13:08 +00:00
|
|
|
[skolem/2]).
|
2011-12-10 22:58:43 +00:00
|
|
|
|
2012-09-23 13:25:15 +01:00
|
|
|
:- use_module(library(maplist)).
|
|
|
|
|
2012-04-03 19:53:27 +01:00
|
|
|
:- use_module(library(lists)).
|
2011-12-10 22:58:43 +00:00
|
|
|
|
2012-04-03 19:53:27 +01:00
|
|
|
:- use_module(library(atts)).
|
2011-12-10 22:58:43 +00:00
|
|
|
|
2012-04-03 16:22:40 +01:00
|
|
|
:- use_module(library(bhash)).
|
|
|
|
|
2011-12-10 22:58:43 +00:00
|
|
|
|
2012-05-23 21:23:03 +01:00
|
|
|
call_horus_ground_solver(QueryVars, QueryKeys, AllKeys, Factors, Evidence, Output) :-
|
2012-12-17 12:13:08 +00:00
|
|
|
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).
|
|
|
|
|
2012-12-15 15:56:05 +00:00
|
|
|
|
|
|
|
run_horus_ground_solver(QueryKeys, Solutions, state(Network,Hash,Id)) :-
|
2012-12-17 12:13:08 +00:00
|
|
|
%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).
|
2012-11-22 15:54:30 +00:00
|
|
|
|
|
|
|
|
2012-11-22 16:33:22 +00:00
|
|
|
init_horus_ground_solver(QueryKeys, AllKeys, Factors, Evidence, state(Network,Hash4,Id4)) :-
|
2012-12-17 12:13:08 +00:00
|
|
|
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).
|
2012-11-22 15:54:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
% TODO this is not beeing called!
|
2012-11-22 16:33:22 +00:00
|
|
|
finalize_horus_ground_solver(state(Network,_Hash,_Id)) :-
|
2012-12-17 12:13:08 +00:00
|
|
|
cpp_free_ground_network(Network).
|
2012-07-03 19:48:13 +01:00
|
|
|
|
|
|
|
|
2012-08-15 22:01:45 +01:00
|
|
|
get_factors_type([f(bayes, _, _)|_], bayes) :- ! .
|
|
|
|
get_factors_type([f(markov, _, _)|_], markov) :- ! .
|
2012-04-09 15:40:51 +01:00
|
|
|
|
|
|
|
|
2012-09-29 11:50:00 +01:00
|
|
|
get_var_information(_:Key, Domain) :- !,
|
2012-12-17 12:13:08 +00:00
|
|
|
skolem(Key, Domain).
|
2012-09-23 13:25:15 +01:00
|
|
|
get_var_information(Key, Domain) :-
|
2012-12-17 12:13:08 +00:00
|
|
|
skolem(Key, Domain).
|
2012-04-18 03:03:29 +01:00
|
|
|
|
|
|
|
|
2012-11-22 15:54:30 +00:00
|
|
|
%get_dists_parameters([],[]).
|
|
|
|
%get_dists_parameters([Id|Ids], [dist(Id, Params)|DistsInfo]) :-
|
2012-12-17 12:13:08 +00:00
|
|
|
% get_dist_params(Id, Params),
|
|
|
|
% get_dists_parameters(Ids, DistsInfo).
|
2011-05-17 12:00:33 +01:00
|
|
|
|