CLP(BN) stuff.
This commit is contained in:
parent
39f392be9c
commit
71a62307f4
@ -235,11 +235,7 @@ project_attributes(GVars, _AVars0) :-
|
||||
use_parfactors(on),
|
||||
clpbn_flag(solver, Solver), Solver \= fove, !,
|
||||
generate_network(GVars, GKeys, Keys, Factors, Evidence),
|
||||
(ground(GVars) ->
|
||||
true
|
||||
;
|
||||
call_ground_solver(Solver, GVars, GKeys, Keys, Factors, Evidence, _Avars0)
|
||||
).
|
||||
call_ground_solver(Solver, GVars, GKeys, Keys, Factors, Evidence, _Avars0).
|
||||
project_attributes(GVars, AVars) :-
|
||||
suppress_attribute_display(false),
|
||||
AVars = [_|_],
|
||||
@ -259,6 +255,14 @@ project_attributes(GVars, AVars) :-
|
||||
).
|
||||
project_attributes(_, _).
|
||||
|
||||
match([], _Keys).
|
||||
match([V|GVars], Keys) :-
|
||||
clpbn:get_atts(V,[key(GKey)]),
|
||||
member(GKey, Keys), ground(GKey), !,
|
||||
match(GVars, Keys).
|
||||
match([_V|GVars], Keys) :-
|
||||
match(GVars, Keys).
|
||||
|
||||
clpbn_vars(AVars, DiffVars, AllVars) :-
|
||||
sort_vars_by_key(AVars,SortedAVars,DiffVars),
|
||||
incorporate_evidence(SortedAVars, AllVars).
|
||||
|
@ -46,11 +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_bind_vals2([V],Ps,AllDiffs) :-
|
||||
use_parfactors(on), !,
|
||||
clpbn:get_atts(V, [key(K)]),
|
||||
pfl:skolem(K,Vals),
|
||||
put_atts(V, posterior([V], Vals, Ps)).
|
||||
put_atts(V, posterior([V], Vals, Ps, AllDiffs)).
|
||||
% complex case, we want a joint distribution, do it on a leader.
|
||||
% should split on cliques ?
|
||||
clpbn_bind_vals2(Vs,Ps,AllDiffs) :-
|
||||
|
@ -245,8 +245,7 @@ get_dist_domain_size(Id, DSize) :-
|
||||
|
||||
get_dist_domain(Id, Domain) :-
|
||||
recorded(clpbn_dist_db, db(Id, _, _, _, Domain, _, _), _), !.
|
||||
get_dist_domain(avg(Domain), Domain) :-
|
||||
recorded(clpbn_dist_db, db(Id, _, _, _, Domain, _, _), _), !.
|
||||
get_dist_domain(avg(Domain), Domain).
|
||||
|
||||
get_dist_key(Id, Key) :-
|
||||
use_parfactors(on), !,
|
||||
|
@ -41,11 +41,22 @@ do_network([], _, _, _) :- !.
|
||||
do_network(QueryVars, EVars, Keys, Factors) :-
|
||||
retractall(currently_defined(_)),
|
||||
retractall(f(_,_,_,_)),
|
||||
writeln(keys:Keys),
|
||||
run_through_factors(QueryVars),
|
||||
run_through_factors(EVars),
|
||||
findall(K, currently_defined(K), Keys),
|
||||
writeln(keys2:Keys),
|
||||
findall(f(FType,FId,FKeys,FCPT), f(FType,FId,FKeys,FCPT), Factors).
|
||||
|
||||
match([], _Keys).
|
||||
match([V|GVars], Keys) :-
|
||||
clpbn:get_atts(V,[key(GKey)]), !,
|
||||
member(GKey, Keys), ground(GKey),
|
||||
match(GVars, Keys).
|
||||
match([_V|GVars], Keys) :-
|
||||
match(GVars, Keys).
|
||||
|
||||
|
||||
%
|
||||
% look for attributed vars with evidence (should also search the DB)
|
||||
% verifiy if the evidence overlaps with query
|
||||
@ -85,14 +96,6 @@ keys([Var|QueryVars], [Key|QueryKeys]) :-
|
||||
clpbn:get_atts(Var,[key(Key)]),
|
||||
keys(QueryVars, QueryKeys).
|
||||
|
||||
run_through_factors([]).
|
||||
run_through_factors([Var|_QueryVars]) :-
|
||||
clpbn:get_atts(Var,[key(K)]),
|
||||
find_factors(K),
|
||||
fail.
|
||||
run_through_factors([_|QueryVars]) :-
|
||||
run_through_factors(QueryVars).
|
||||
|
||||
initialize_evidence([]).
|
||||
initialize_evidence([V|EVars]) :-
|
||||
clpbn:get_atts(V, [key(K)]),
|
||||
|
@ -20,9 +20,6 @@
|
||||
]).
|
||||
|
||||
|
||||
:- use_module(library(pfl),
|
||||
[set_pfl_flag/2]).
|
||||
|
||||
|
||||
patch_things_up :-
|
||||
assert_static(clpbn_horus:set_horus_flag(_,_)).
|
||||
@ -33,13 +30,13 @@ warning :-
|
||||
:- catch(load_foreign_files([horus], [], init_predicates), _, patch_things_up) -> true ; warning.
|
||||
|
||||
|
||||
set_solver(ve) :- set_pfl_flag(solver,ve).
|
||||
set_solver(jt) :- set_pfl_flag(solver,jt).
|
||||
set_solver(gibbs) :- set_pfl_flag(solver,gibbs).
|
||||
set_solver(fove) :- set_pfl_flag(solver,fove).
|
||||
set_solver(hve) :- set_pfl_flag(solver,bp), set_horus_flag(inf_alg, ve).
|
||||
set_solver(bp) :- set_pfl_flag(solver,bp), set_horus_flag(inf_alg, bp).
|
||||
set_solver(cbp) :- set_pfl_flag(solver,bp), set_horus_flag(inf_alg, cbp).
|
||||
set_solver(ve) :- pfl:set_pfl_flag(solver,ve).
|
||||
set_solver(jt) :- pfl:set_pfl_flag(solver,jt).
|
||||
set_solver(gibbs) :- pfl:set_pfl_flag(solver,gibbs).
|
||||
set_solver(fove) :- pfl:set_pfl_flag(solver,fove).
|
||||
set_solver(hve) :- pfl:set_pfl_flag(solver,bp), set_horus_flag(inf_alg, ve).
|
||||
set_solver(bp) :- pfl:set_pfl_flag(solver,bp), set_horus_flag(inf_alg, bp).
|
||||
set_solver(cbp) :- pfl:set_pfl_flag(solver,bp), set_horus_flag(inf_alg, cbp).
|
||||
set_solver(S) :- throw(error('unknow solver ', S)).
|
||||
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
/*
|
||||
total_professors(32).
|
||||
|
||||
@ -11,11 +13,15 @@ total_students(256).
|
||||
|
||||
:- style_check(all).
|
||||
|
||||
:- yap_flag(unknown,error).
|
||||
|
||||
:- yap_flag(write_strings,on).
|
||||
|
||||
:- ensure_loaded(parschema).
|
||||
|
||||
:- yap_flag(unknown,error).
|
||||
%:- clpbn_horus:set_solver(fove).
|
||||
%:- clpbn_horus:set_solver(hve).
|
||||
:- clpbn_horus:set_solver(bp).
|
||||
%:- clpbn_horus:set_solver(cbp).
|
||||
|
||||
:- ensure_loaded(school32_data).
|
||||
|
||||
|
@ -131,6 +131,7 @@ interface_predicate(Sk) :-
|
||||
append(SKAs, [Var], ESKAs),
|
||||
ESk =.. ESKAs,
|
||||
assert(preprocess(ESk, Sk, Var)),
|
||||
% transform from PFL to CLP(BN) call
|
||||
assert_static((user:ESk :-
|
||||
evidence(Sk,Ev) -> Ev = Var;
|
||||
var(Var) -> insert_atts(Var,Sk) ;
|
||||
|
Reference in New Issue
Block a user