New Version From Tiago
This commit is contained in:
parent
2ab4ce503e
commit
dbcb6e530c
@ -8,6 +8,8 @@
|
||||
:- module(clpbn_bp,
|
||||
[bp/3,
|
||||
check_if_bp_done/1,
|
||||
set_solver_parameter/2,
|
||||
use_log_space/0,
|
||||
init_bp_solver/4,
|
||||
run_bp_solver/3,
|
||||
finalize_bp_solver/1
|
||||
@ -34,12 +36,30 @@
|
||||
|
||||
:- attribute id/1.
|
||||
|
||||
:- dynamic num_bayes_nets/1.
|
||||
:- dynamic network_counting/1.
|
||||
|
||||
|
||||
check_if_bp_done(_Var).
|
||||
|
||||
num_bayes_nets(0).
|
||||
network_counting(0).
|
||||
|
||||
|
||||
:- set_solver_parameter(run_mode, normal).
|
||||
%:- set_solver_parameter(run_mode, convert).
|
||||
%: -set_solver_parameter(run_mode, compress).
|
||||
|
||||
:- set_solver_parameter(schedule, seq_fixed).
|
||||
%:- set_solver_parameter(schedule, seq_random).
|
||||
%:- set_solver_parameter(schedule, parallel).
|
||||
%:- set_solver_parameter(schedule, max_residual).
|
||||
|
||||
:- set_solver_parameter(accuracy, 0.0001).
|
||||
|
||||
:- set_solver_parameter(max_iter, 1000).
|
||||
|
||||
:- set_solver_parameter(always_loopy_solver, false).
|
||||
|
||||
% :- use_log_space.
|
||||
|
||||
|
||||
bp([[]],_,_) :- !.
|
||||
@ -51,14 +71,15 @@ bp([QueryVars], AllVars, Output) :-
|
||||
|
||||
|
||||
init_bp_solver(_, AllVars, _, (BayesNet, DistIds)) :-
|
||||
%inc_num_bayes_nets,
|
||||
%(showprofres(50) -> true ; true),
|
||||
%inc_network_counting,
|
||||
process_ids(AllVars, 0, DistIds0),
|
||||
get_vars_info(AllVars, VarsInfo),
|
||||
sort(DistIds0, DistIds),
|
||||
%(num_bayes_nets(0) -> writeln(vars:VarsInfo) ; true),
|
||||
%(num_bayes_nets(0) -> writeln(dists:DistsInfo) ; true),
|
||||
%(network_counting(0) -> writeln(vars:VarsInfo) ; true),
|
||||
%(network_counting(0) -> writeln(distsids:DistIds) ; true),
|
||||
create_network(VarsInfo, BayesNet).
|
||||
%get_extra_vars_info(AllVars, ExtraVarsInfo),
|
||||
%(network_counting(0) -> writeln(extra:ExtraVarsInfo) ; true),
|
||||
%set_extra_vars_info(BayesNet, ExtraVarsInfo).
|
||||
|
||||
|
||||
@ -103,6 +124,8 @@ get_extra_vars_info([V|Vs], [v(VarId, Label, Domain)|VarsInfo]) :-
|
||||
get_dist_domain(DistId, Domain0),
|
||||
numbers2atoms(Domain0, Domain),
|
||||
get_extra_vars_info(Vs, VarsInfo).
|
||||
get_extra_vars_info([_|Vs], VarsInfo) :-
|
||||
get_extra_vars_info(Vs, VarsInfo).
|
||||
|
||||
|
||||
numbers2atoms([], []).
|
||||
@ -118,8 +141,7 @@ run_bp_solver(QVsL0, LPs, (BayesNet, DistIds)) :-
|
||||
get_dists_parameters(DistIds, DistsParams),
|
||||
set_parameters(BayesNet, DistsParams),
|
||||
process_query_list(QVsL0, QVsL),
|
||||
%writeln(' qvs':QVsL),
|
||||
%(num_bayes_nets(1506) -> writeln(qvs:QVsL) ; true),
|
||||
%(network_counting(0) -> writeln(qvs:QVsL) ; true),
|
||||
run_solver(BayesNet, QVsL, LPs).
|
||||
|
||||
|
||||
@ -139,11 +161,11 @@ get_dists_parameters([Id|Ids], [dist(Id, Params)|DistsInfo]) :-
|
||||
|
||||
|
||||
finalize_bp_solver((BayesNet, _)) :-
|
||||
delete_bayes_net(BayesNet).
|
||||
free_bayesian_network(BayesNet).
|
||||
|
||||
|
||||
inc_num_bayes_nets :-
|
||||
retract(num_bayes_nets(Count0)),
|
||||
inc_network_counting :-
|
||||
retract(network_counting(Count0)),
|
||||
Count is Count0 + 1,
|
||||
assert(num_bayes_nets(Count)).
|
||||
assert(network_counting(Count)).
|
||||
|
||||
|
Reference in New Issue
Block a user