small pfl fixes.
This commit is contained in:
parent
c5f42cd7eb
commit
5a8cc421d2
@ -44,7 +44,7 @@
|
||||
check_if_bp_done/1,
|
||||
init_bp_solver/4,
|
||||
run_bp_solver/3,
|
||||
call_bp_ground/5,
|
||||
call_bp_ground/6,
|
||||
finalize_bp_solver/1
|
||||
]).
|
||||
|
||||
@ -69,10 +69,10 @@
|
||||
run_bdd_solver/3
|
||||
]).
|
||||
|
||||
:- use_module('clpbn/bnt',
|
||||
[do_bnt/3,
|
||||
check_if_bnt_done/1
|
||||
]).
|
||||
%% :- use_module('clpbn/bnt',
|
||||
%% [do_bnt/3,
|
||||
%% check_if_bnt_done/1
|
||||
%% ]).
|
||||
|
||||
:- use_module('clpbn/gibbs',
|
||||
[gibbs/3,
|
||||
@ -238,7 +238,7 @@ project_attributes(GVars, _AVars0) :-
|
||||
(ground(GVars) ->
|
||||
true
|
||||
;
|
||||
call_ground_solver(Solver, GKeys, Keys, Factors, Evidence, _Avars0)
|
||||
call_ground_solver(Solver, GVars, GKeys, Keys, Factors, Evidence, _Avars0)
|
||||
).
|
||||
project_attributes(GVars, AVars) :-
|
||||
suppress_attribute_display(false),
|
||||
@ -312,8 +312,8 @@ write_out(fove, GVars, AVars, DiffVars) :-
|
||||
fove(GVars, AVars, DiffVars).
|
||||
|
||||
% call a solver with keys, not actual variables
|
||||
call_ground_solver(bp, GoalKeys, Keys, Factors, Evidence, Answ) :-
|
||||
call_bp_ground(GoalKeys, Keys, Factors, Evidence, Answ).
|
||||
call_ground_solver(bp, GVars, GoalKeys, Keys, Factors, Evidence, Answ) :-
|
||||
call_bp_ground(GVars, GoalKeys, Keys, Factors, Evidence, Answ).
|
||||
|
||||
|
||||
get_bnode(Var, Goal) :-
|
||||
|
@ -10,7 +10,7 @@
|
||||
check_if_bp_done/1,
|
||||
init_bp_solver/4,
|
||||
run_bp_solver/3,
|
||||
call_bp_ground/5,
|
||||
call_bp_ground/6,
|
||||
finalize_bp_solver/1
|
||||
]).
|
||||
|
||||
@ -57,7 +57,8 @@
|
||||
]).
|
||||
|
||||
|
||||
call_bp_ground(QueryKeys, AllKeys, Factors, Evidence, _Output) :-
|
||||
call_bp_ground(QueryVars, QueryKeys, AllKeys, Factors, Evidence, Output) :-
|
||||
writeln(here:Factors),
|
||||
b_hash_new(Hash0),
|
||||
keys_to_ids(AllKeys, 0, Hash0, Hash),
|
||||
get_factors_type(Factors, Type),
|
||||
@ -74,7 +75,7 @@ call_bp_ground(QueryKeys, AllKeys, Factors, Evidence, _Output) :-
|
||||
%set_vars_information(AllKeys, StatesNames),
|
||||
run_solver(ground(Network,Hash), QueryKeys, Solutions),
|
||||
writeln(answer:Solutions),
|
||||
%clpbn_bind_vals([QueryKeys], Solutions, _Output).
|
||||
clpbn_bind_vals([QueryVars], Solutions, Output),
|
||||
free_ground_network(Network).
|
||||
|
||||
|
||||
@ -95,8 +96,8 @@ keys_to_ids([Key|AllKeys], I0, Hash0, Hash) :-
|
||||
keys_to_ids(AllKeys, I, HashI, Hash).
|
||||
|
||||
|
||||
get_factors_type([f(bayes, _, _)|_], bayes) :- ! .
|
||||
get_factors_type([f(markov, _, _)|_], markov) :- ! .
|
||||
get_factors_type([f(bayes, _, _, _)|_], bayes) :- ! .
|
||||
get_factors_type([f(markov, _, _, _)|_], markov) :- ! .
|
||||
|
||||
|
||||
list_of_keys_to_ids([], _, []).
|
||||
@ -106,9 +107,8 @@ list_of_keys_to_ids([Key|QueryKeys], Hash, [Id|QueryIds]) :-
|
||||
|
||||
|
||||
factors_to_ids([], _, []).
|
||||
factors_to_ids([f(_, Keys, CPT)|Fs], Hash, [f(Ids, Ranges, CPT, DistId)|NFs]) :-
|
||||
factors_to_ids([f(_, DistId, Keys, CPT)|Fs], Hash, [f(Ids, Ranges, CPT, DistId)|NFs]) :-
|
||||
list_of_keys_to_ids(Keys, Hash, Ids),
|
||||
DistId = 0,
|
||||
get_ranges(Keys, Ranges),
|
||||
factors_to_ids(Fs, Hash, NFs).
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
:- use_module(library(clpbn/dists), [get_dist_domain/2]).
|
||||
|
||||
:- use_module(library(clpbn), [use_parfactors/1]).
|
||||
|
||||
:- attribute posterior/4.
|
||||
|
||||
|
||||
@ -44,9 +46,11 @@ clpbn_bind_vals([Vs|MoreVs],[Ps|MorePs],AllDiffs) :-
|
||||
|
||||
clpbn_bind_vals2([],_,_) :- !.
|
||||
% simple case, we want a distribution on a single variable.
|
||||
%bind_vals([V],Ps) :- !,
|
||||
% clpbn:get_atts(V, [dist(Vals,_,_)]),
|
||||
% put_atts(V, posterior([V], Vals, Ps)).
|
||||
bind_vals([V],Ps) :-
|
||||
use_parfactors(on), !,
|
||||
clpbn:get_atts(V, [key(K)]),
|
||||
pfl:skolem(K,Vals),
|
||||
put_atts(V, posterior([V], Vals, Ps)).
|
||||
% complex case, we want a joint distribution, do it on a leader.
|
||||
% should split on cliques ?
|
||||
clpbn_bind_vals2(Vs,Ps,AllDiffs) :-
|
||||
|
@ -28,7 +28,7 @@
|
||||
:- use_module(library(clpbn/dists), [
|
||||
dist/4]).
|
||||
|
||||
:- dynamic currently_defined/1, f/3.
|
||||
:- dynamic currently_defined/1, f/4.
|
||||
|
||||
generate_network(QueryVars0, QueryKeys, Keys, Factors, Evidence) :-
|
||||
attributes:all_attvars(AVars),
|
||||
@ -40,11 +40,11 @@ generate_network(QueryVars0, QueryKeys, Keys, Factors, Evidence) :-
|
||||
do_network([], _, _, _) :- !.
|
||||
do_network(QueryVars, EVars, Keys, Factors) :-
|
||||
retractall(currently_defined(_)),
|
||||
retractall(f(_,_,_)),
|
||||
retractall(f(_,_,_,_)),
|
||||
run_through_factors(QueryVars),
|
||||
run_through_factors(EVars),
|
||||
findall(K, currently_defined(K), Keys),
|
||||
findall(f(FType,FKeys,FCPT), f(FType,FKeys,FCPT), Factors).
|
||||
findall(f(FType,FId,FKeys,FCPT), f(FType,FId,FKeys,FCPT), Factors).
|
||||
|
||||
%
|
||||
% look for attributed vars with evidence (should also search the DB)
|
||||
@ -110,11 +110,11 @@ find_factors(K) :-
|
||||
\+ currently_defined(K1),
|
||||
find_factors(K1).
|
||||
|
||||
add_factor(factor(Type, _Id, Ks, _, Phi, Constraints), Ks) :-
|
||||
F = f(Type, Ks, CPT),
|
||||
add_factor(factor(Type, Id, Ks, _, Phi, Constraints), Ks) :-
|
||||
F = f(Type, Id, Ks, CPT),
|
||||
( is_list(Phi) -> CPT = Phi ; call(user:Phi, CPT) ),
|
||||
run(Constraints),
|
||||
\+ f(Type, Ks, CPT),
|
||||
\+ f(Type, Id, Ks, CPT),
|
||||
assert(F).
|
||||
|
||||
run([Goal|Goals]) :-
|
||||
|
Reference in New Issue
Block a user