vel -> ve
This commit is contained in:
parent
27dbe24b9e
commit
b3bd547f55
@ -51,7 +51,7 @@ CLPBN_PROGRAMS= \
|
|||||||
$(CLPBN_SRCDIR)/table.yap \
|
$(CLPBN_SRCDIR)/table.yap \
|
||||||
$(CLPBN_SRCDIR)/topsort.yap \
|
$(CLPBN_SRCDIR)/topsort.yap \
|
||||||
$(CLPBN_SRCDIR)/utils.yap \
|
$(CLPBN_SRCDIR)/utils.yap \
|
||||||
$(CLPBN_SRCDIR)/vel.yap \
|
$(CLPBN_SRCDIR)/ve.yap \
|
||||||
$(CLPBN_SRCDIR)/viterbi.yap \
|
$(CLPBN_SRCDIR)/viterbi.yap \
|
||||||
$(CLPBN_SRCDIR)/xbif.yap
|
$(CLPBN_SRCDIR)/xbif.yap
|
||||||
|
|
||||||
|
@ -29,11 +29,11 @@
|
|||||||
:- attribute key/1, dist/2, evidence/1, starter/0.
|
:- attribute key/1, dist/2, evidence/1, starter/0.
|
||||||
|
|
||||||
|
|
||||||
:- use_module('clpbn/vel',
|
:- use_module('clpbn/ve',
|
||||||
[vel/3,
|
[ve/3,
|
||||||
check_if_vel_done/1,
|
check_if_ve_done/1,
|
||||||
init_vel_solver/4,
|
init_ve_solver/4,
|
||||||
run_vel_solver/3
|
run_ve_solver/3
|
||||||
]).
|
]).
|
||||||
|
|
||||||
:- use_module('clpbn/bp',
|
:- use_module('clpbn/bp',
|
||||||
@ -110,8 +110,8 @@
|
|||||||
|
|
||||||
:- dynamic solver/1,output/1,use/1,suppress_attribute_display/1, parameter_softening/1, em_solver/1.
|
:- dynamic solver/1,output/1,use/1,suppress_attribute_display/1, parameter_softening/1, em_solver/1.
|
||||||
|
|
||||||
solver(vel).
|
solver(ve).
|
||||||
em_solver(vel).
|
em_solver(ve).
|
||||||
|
|
||||||
%output(xbif(user_error)).
|
%output(xbif(user_error)).
|
||||||
%output(gviz(user_error)).
|
%output(gviz(user_error)).
|
||||||
@ -215,7 +215,7 @@ project_attributes(GVars, AVars) :-
|
|||||||
clpbn_vars(AVars, DiffVars, AllVars),
|
clpbn_vars(AVars, DiffVars, AllVars),
|
||||||
get_clpbn_vars(GVars,CLPBNGVars0),
|
get_clpbn_vars(GVars,CLPBNGVars0),
|
||||||
simplify_query_vars(CLPBNGVars0, CLPBNGVars),
|
simplify_query_vars(CLPBNGVars0, CLPBNGVars),
|
||||||
(output(xbif(XBifStream)) -> clpbn2xbif(XBifStream,vel,AllVars) ; true),
|
(output(xbif(XBifStream)) -> clpbn2xbif(XBifStream,ve,AllVars) ; true),
|
||||||
(output(gviz(XBifStream)) -> clpbn2gviz(XBifStream,sort,AllVars,GVars) ; true),
|
(output(gviz(XBifStream)) -> clpbn2gviz(XBifStream,sort,AllVars,GVars) ; true),
|
||||||
(
|
(
|
||||||
Solver = graphs
|
Solver = graphs
|
||||||
@ -257,8 +257,8 @@ get_rid_of_ev_vars([V|LVs0],[V|LVs]) :-
|
|||||||
% do nothing if we don't have query variables to compute.
|
% do nothing if we don't have query variables to compute.
|
||||||
write_out(graphs, _, AVars, _) :-
|
write_out(graphs, _, AVars, _) :-
|
||||||
clpbn2graph(AVars).
|
clpbn2graph(AVars).
|
||||||
write_out(vel, GVars, AVars, DiffVars) :-
|
write_out(ve, GVars, AVars, DiffVars) :-
|
||||||
vel(GVars, AVars, DiffVars).
|
ve(GVars, AVars, DiffVars).
|
||||||
write_out(jt, GVars, AVars, DiffVars) :-
|
write_out(jt, GVars, AVars, DiffVars) :-
|
||||||
jt(GVars, AVars, DiffVars).
|
jt(GVars, AVars, DiffVars).
|
||||||
write_out(bp, GVars, AVars, DiffVars) :-
|
write_out(bp, GVars, AVars, DiffVars) :-
|
||||||
@ -349,14 +349,14 @@ bind_clpbn(_, Var, _, _, _, _, []) :-
|
|||||||
use(bnt),
|
use(bnt),
|
||||||
check_if_bnt_done(Var), !.
|
check_if_bnt_done(Var), !.
|
||||||
bind_clpbn(_, Var, _, _, _, _, []) :-
|
bind_clpbn(_, Var, _, _, _, _, []) :-
|
||||||
use(vel),
|
use(ve),
|
||||||
check_if_vel_done(Var), !.
|
check_if_ve_done(Var), !.
|
||||||
bind_clpbn(_, Var, _, _, _, _, []) :-
|
bind_clpbn(_, Var, _, _, _, _, []) :-
|
||||||
use(bp),
|
use(bp),
|
||||||
check_if_bp_done(Var), !.
|
check_if_bp_done(Var), !.
|
||||||
bind_clpbn(_, Var, _, _, _, _, []) :-
|
bind_clpbn(_, Var, _, _, _, _, []) :-
|
||||||
use(jt),
|
use(jt),
|
||||||
check_if_vel_done(Var), !.
|
check_if_ve_done(Var), !.
|
||||||
bind_clpbn(T, Var, Key0, _, _, _, []) :-
|
bind_clpbn(T, Var, Key0, _, _, _, []) :-
|
||||||
get_atts(Var, [key(Key)]), !,
|
get_atts(Var, [key(Key)]), !,
|
||||||
(
|
(
|
||||||
@ -421,8 +421,8 @@ clpbn_init_solver(LVs, Vs0, VarsWithUnboundKeys, State) :-
|
|||||||
|
|
||||||
clpbn_init_solver(gibbs, LVs, Vs0, VarsWithUnboundKeys, State) :-
|
clpbn_init_solver(gibbs, LVs, Vs0, VarsWithUnboundKeys, State) :-
|
||||||
init_gibbs_solver(LVs, Vs0, VarsWithUnboundKeys, State).
|
init_gibbs_solver(LVs, Vs0, VarsWithUnboundKeys, State).
|
||||||
clpbn_init_solver(vel, LVs, Vs0, VarsWithUnboundKeys, State) :-
|
clpbn_init_solver(ve, LVs, Vs0, VarsWithUnboundKeys, State) :-
|
||||||
init_vel_solver(LVs, Vs0, VarsWithUnboundKeys, State).
|
init_ve_solver(LVs, Vs0, VarsWithUnboundKeys, State).
|
||||||
clpbn_init_solver(bp, LVs, Vs0, VarsWithUnboundKeys, State) :-
|
clpbn_init_solver(bp, LVs, Vs0, VarsWithUnboundKeys, State) :-
|
||||||
init_bp_solver(LVs, Vs0, VarsWithUnboundKeys, State).
|
init_bp_solver(LVs, Vs0, VarsWithUnboundKeys, State).
|
||||||
clpbn_init_solver(jt, LVs, Vs0, VarsWithUnboundKeys, State) :-
|
clpbn_init_solver(jt, LVs, Vs0, VarsWithUnboundKeys, State) :-
|
||||||
@ -444,8 +444,8 @@ clpbn_run_solver(LVs, LPs, State) :-
|
|||||||
clpbn_run_solver(gibbs, LVs, LPs, State) :-
|
clpbn_run_solver(gibbs, LVs, LPs, State) :-
|
||||||
run_gibbs_solver(LVs, LPs, State).
|
run_gibbs_solver(LVs, LPs, State).
|
||||||
|
|
||||||
clpbn_run_solver(vel, LVs, LPs, State) :-
|
clpbn_run_solver(ve, LVs, LPs, State) :-
|
||||||
run_vel_solver(LVs, LPs, State).
|
run_ve_solver(LVs, LPs, State).
|
||||||
|
|
||||||
clpbn_run_solver(bp, LVs, LPs, State) :-
|
clpbn_run_solver(bp, LVs, LPs, State) :-
|
||||||
run_bp_solver(LVs, LPs, State).
|
run_bp_solver(LVs, LPs, State).
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
|
|
||||||
*********************************/
|
*********************************/
|
||||||
|
|
||||||
:- module(clpbn_vel, [vel/3,
|
:- module(clpbn_ve, [ve/3,
|
||||||
check_if_vel_done/1,
|
check_if_ve_done/1,
|
||||||
init_vel_solver/4,
|
init_ve_solver/4,
|
||||||
run_vel_solver/3]).
|
run_ve_solver/3]).
|
||||||
|
|
||||||
:- attribute size/1, all_diffs/1.
|
:- attribute size/1, all_diffs/1.
|
||||||
|
|
||||||
@ -64,39 +64,39 @@
|
|||||||
[check_for_agg_vars/2]).
|
[check_for_agg_vars/2]).
|
||||||
|
|
||||||
|
|
||||||
check_if_vel_done(Var) :-
|
check_if_ve_done(Var) :-
|
||||||
get_atts(Var, [size(_)]), !.
|
get_atts(Var, [size(_)]), !.
|
||||||
|
|
||||||
%
|
%
|
||||||
% implementation of the well known variable elimination algorithm
|
% implementation of the well known variable elimination algorithm
|
||||||
%
|
%
|
||||||
vel([[]],_,_) :- !.
|
ve([[]],_,_) :- !.
|
||||||
vel([LVs],Vs0,AllDiffs) :-
|
ve([LVs],Vs0,AllDiffs) :-
|
||||||
init_vel_solver([LVs], Vs0, AllDiffs, State),
|
init_ve_solver([LVs], Vs0, AllDiffs, State),
|
||||||
% variable elimination proper
|
% variable elimination proper
|
||||||
run_vel_solver([LVs], [LPs], State),
|
run_ve_solver([LVs], [LPs], State),
|
||||||
% bind Probs back to variables so that they can be output.
|
% bind Probs back to variables so that they can be output.
|
||||||
clpbn_bind_vals([LVs],[LPs],AllDiffs).
|
clpbn_bind_vals([LVs],[LPs],AllDiffs).
|
||||||
|
|
||||||
init_vel_solver(Qs, Vs0, _, LVis) :-
|
init_ve_solver(Qs, Vs0, _, LVis) :-
|
||||||
check_for_agg_vars(Vs0, Vs1),
|
check_for_agg_vars(Vs0, Vs1),
|
||||||
% LVi will have a list of CLPBN variables
|
% LVi will have a list of CLPBN variables
|
||||||
% Tables0 will have the full data on each variable
|
% Tables0 will have the full data on each variable
|
||||||
init_influences(Vs1, G, RG),
|
init_influences(Vs1, G, RG),
|
||||||
init_vel_solver_for_questions(Qs, G, RG, _, LVis).
|
init_ve_solver_for_questions(Qs, G, RG, _, LVis).
|
||||||
|
|
||||||
init_vel_solver_for_questions([], _, _, [], []).
|
init_ve_solver_for_questions([], _, _, [], []).
|
||||||
init_vel_solver_for_questions([Vs|MVs], G, RG, [NVs|MNVs0], [NVs|LVis]) :-
|
init_ve_solver_for_questions([Vs|MVs], G, RG, [NVs|MNVs0], [NVs|LVis]) :-
|
||||||
influences(Vs, _, NVs0, G, RG),
|
influences(Vs, _, NVs0, G, RG),
|
||||||
sort(NVs0, NVs),
|
sort(NVs0, NVs),
|
||||||
%clpbn_gviz:clpbn2gviz(user_error, test, NVs, Vs),
|
%clpbn_gviz:clpbn2gviz(user_error, test, NVs, Vs),
|
||||||
init_vel_solver_for_questions(MVs, G, RG, MNVs0, LVis).
|
init_ve_solver_for_questions(MVs, G, RG, MNVs0, LVis).
|
||||||
|
|
||||||
% use a findall to recover space without needing for GC
|
% use a findall to recover space without needing for GC
|
||||||
run_vel_solver(LVs, LPs, LNVs) :-
|
run_ve_solver(LVs, LPs, LNVs) :-
|
||||||
findall(Ps, solve_vel(LVs, LNVs, Ps), LPs).
|
findall(Ps, solve_ve(LVs, LNVs, Ps), LPs).
|
||||||
|
|
||||||
solve_vel([LVs|_], [NVs0|_], Ps) :-
|
solve_ve([LVs|_], [NVs0|_], Ps) :-
|
||||||
% length(NVs0, L), (L > 415 -> clpbn_gviz:clpbn2gviz(user_error,sort,NVs0,LVs) ; true ),
|
% length(NVs0, L), (L > 415 -> clpbn_gviz:clpbn2gviz(user_error,sort,NVs0,LVs) ; true ),
|
||||||
% length(NVs0, L), writeln(+LVs:L),
|
% length(NVs0, L), writeln(+LVs:L),
|
||||||
find_all_clpbn_vars(NVs0, NVs0, LV0, LVi, Tables0),
|
find_all_clpbn_vars(NVs0, NVs0, LV0, LVi, Tables0),
|
||||||
@ -109,8 +109,8 @@ solve_vel([LVs|_], [NVs0|_], Ps) :-
|
|||||||
% move from potentials back to probabilities
|
% move from potentials back to probabilities
|
||||||
normalise_CPT(Dist,MPs),
|
normalise_CPT(Dist,MPs),
|
||||||
list_from_CPT(MPs, Ps).
|
list_from_CPT(MPs, Ps).
|
||||||
solve_vel([_|MoreLVs], [_|MoreLVis], Ps) :-
|
solve_ve([_|MoreLVs], [_|MoreLVis], Ps) :-
|
||||||
solve_vel(MoreLVs, MoreLVis, Ps).
|
solve_ve(MoreLVs, MoreLVis, Ps).
|
||||||
|
|
||||||
exps([],[]).
|
exps([],[]).
|
||||||
exps([L|LD],[O|LDE]) :-
|
exps([L|LD],[O|LDE]) :-
|
||||||
@ -134,7 +134,7 @@ find_all_clpbn_vars([V|Vs], NVs0, [Var|LV], ProcessedVars, [table(I,Table,Parent
|
|||||||
% variables with evidence should not be processed.
|
% variables with evidence should not be processed.
|
||||||
(var(Ev) ->
|
(var(Ev) ->
|
||||||
Var = var(V,I,Sz,Vals,Parents,Ev,_,_),
|
Var = var(V,I,Sz,Vals,Parents,Ev,_,_),
|
||||||
vel_get_dist_size(V,Sz),
|
ve_get_dist_size(V,Sz),
|
||||||
ProcessedVars = [Var|ProcessedVars0]
|
ProcessedVars = [Var|ProcessedVars0]
|
||||||
;
|
;
|
||||||
ProcessedVars = ProcessedVars0
|
ProcessedVars = ProcessedVars0
|
||||||
@ -192,7 +192,7 @@ compute_size([tab(_,Vs,_)|Tabs],Vs0,K) :-
|
|||||||
|
|
||||||
multiply_sizes([],K,K).
|
multiply_sizes([],K,K).
|
||||||
multiply_sizes([V|Vs],K0,K) :-
|
multiply_sizes([V|Vs],K0,K) :-
|
||||||
vel_get_dist_size(V, Sz),
|
ve_get_dist_size(V, Sz),
|
||||||
KI is K0*Sz,
|
KI is K0*Sz,
|
||||||
multiply_sizes(Vs,KI,K).
|
multiply_sizes(Vs,KI,K).
|
||||||
|
|
||||||
@ -281,9 +281,9 @@ update_tables([tab(Tab0,Vs,Sz)|Tabs],[tab(Tab0,Vs,Sz)|NTabs],Table,V) :-
|
|||||||
update_tables([_|Tabs],NTabs,Table,V) :-
|
update_tables([_|Tabs],NTabs,Table,V) :-
|
||||||
update_tables(Tabs,NTabs,Table,V).
|
update_tables(Tabs,NTabs,Table,V).
|
||||||
|
|
||||||
vel_get_dist_size(V,Sz) :-
|
ve_get_dist_size(V,Sz) :-
|
||||||
get_atts(V, [size(Sz)]), !.
|
get_atts(V, [size(Sz)]), !.
|
||||||
vel_get_dist_size(V,Sz) :-
|
ve_get_dist_size(V,Sz) :-
|
||||||
clpbn:get_atts(V,dist(Id,_)), !,
|
clpbn:get_atts(V,dist(Id,_)), !,
|
||||||
get_dist_domain_size(Id,Sz),
|
get_dist_domain_size(Id,Sz),
|
||||||
put_atts(V, [size(Sz)]).
|
put_atts(V, [size(Sz)]).
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
%:- clpbn:set_clpbn_flag(em_solver,gibbs).
|
%:- clpbn:set_clpbn_flag(em_solver,gibbs).
|
||||||
%:- clpbn:set_clpbn_flag(em_solver,jt).
|
%:- clpbn:set_clpbn_flag(em_solver,jt).
|
||||||
:- clpbn:set_clpbn_flag(em_solver,vel).
|
:- clpbn:set_clpbn_flag(em_solver,ve).
|
||||||
%:- clpbn:set_clpbn_flag(em_solver,bp).
|
%:- clpbn:set_clpbn_flag(em_solver,bp).
|
||||||
|
|
||||||
timed_main :-
|
timed_main :-
|
||||||
|
@ -38,7 +38,7 @@ run_all(M:Gs) :-
|
|||||||
run_all([],_).
|
run_all([],_).
|
||||||
run_all([G|Gs],M) :-
|
run_all([G|Gs],M) :-
|
||||||
% (G = _:ge(ybr136w,t8,23,-1) -> nb_getval(clpbn_tables, Tab), writeln(Tab) ; true ),
|
% (G = _:ge(ybr136w,t8,23,-1) -> nb_getval(clpbn_tables, Tab), writeln(Tab) ; true ),
|
||||||
( call(M:G) -> true ; writeln(bad:M:G), start_low_level_trace, M:G ; halt ),
|
( call(M:G) -> true ; throw(bad_call(M:G)) ),
|
||||||
run_all(Gs,M).
|
run_all(Gs,M).
|
||||||
|
|
||||||
clpbn_vars(Vs,BVars) :-
|
clpbn_vars(Vs,BVars) :-
|
||||||
|
Reference in New Issue
Block a user