More whitespace cleanups

This commit is contained in:
Tiago Gomes 2012-12-20 23:19:10 +00:00
parent 421d6f72ee
commit 01d8f8e178
61 changed files with 209 additions and 210 deletions

View File

@ -221,14 +221,14 @@ set_em_solver(Solver) :-
% %
% we use a mutable variable to avoid unnecessary trailing. % we use a mutable variable to avoid unnecessary trailing.
% %
store_var(El) :- store_var(El) :-
nb_current(clpbn_qvars, Mutable), nb_current(clpbn_qvars, Mutable),
nonvar(Mutable), !, nonvar(Mutable), !,
get_mutable(Tail, Mutable), get_mutable(Tail, Mutable),
update_mutable(El.Tail, Mutable). update_mutable(El.Tail, Mutable).
store_var(El) :- store_var(El) :-
init_clpbn_vars(El). init_clpbn_vars(El).
init_clpbn_vars(El) :- init_clpbn_vars(El) :-
create_mutable(El, Mutable), create_mutable(El, Mutable),
b_setval(clpbn_qvars, Mutable). b_setval(clpbn_qvars, Mutable).
@ -278,7 +278,7 @@ project_attributes(GVars0, _AVars0) :-
b_setval(clpbn_query_variables, f(GVars0,Evidence)), b_setval(clpbn_query_variables, f(GVars0,Evidence)),
simplify_query(GVars0, GVars), simplify_query(GVars0, GVars),
( (
GKeys = [] GKeys = []
-> ->
GVars0 = [V|_], GVars0 = [V|_],
clpbn_display:put_atts(V, [posterior([],[],[],[])]) clpbn_display:put_atts(V, [posterior([],[],[],[])])
@ -378,7 +378,7 @@ call_ground_solver(cbp, GVars, GoalKeys, Keys, Factors, Evidence) :- !,
call_ground_solver(Solver, GVars, _GoalKeys, Keys, Factors, Evidence) :- call_ground_solver(Solver, GVars, _GoalKeys, Keys, Factors, Evidence) :-
% fall back to traditional solver % fall back to traditional solver
b_hash_new(Hash0), b_hash_new(Hash0),
foldl(gvar_in_hash, GVars, Hash0, HashI), foldl(gvar_in_hash, GVars, Hash0, HashI),
foldl(key_to_var, Keys, AllVars, HashI, Hash1), foldl(key_to_var, Keys, AllVars, HashI, Hash1),
foldl(evidence_to_v, Evidence, _EVars, Hash1, Hash), foldl(evidence_to_v, Evidence, _EVars, Hash1, Hash),
%writeln(Keys:AllVars), %writeln(Keys:AllVars),
@ -432,7 +432,7 @@ write_out(Solver, _, _, _) :-
% %
gvar_in_hash(V, Hash0, Hash) :- gvar_in_hash(V, Hash0, Hash) :-
get_atts(V, [key(K)]), get_atts(V, [key(K)]),
b_hash_insert(Hash0, K, V, Hash). b_hash_insert(Hash0, K, V, Hash).
key_to_var(K, V, Hash0, Hash0) :- key_to_var(K, V, Hash0, Hash0) :-
b_hash_lookup(K, V, Hash0), !. b_hash_lookup(K, V, Hash0), !.
@ -496,12 +496,12 @@ process_vars([V|Vs], [K|Ks]) :-
process_var(V, K), process_var(V, K),
process_vars(Vs, Ks). process_vars(Vs, Ks).
process_var(V, K) :- get_atts(V, [key(K)]), !. process_var(V, K) :- get_atts(V, [key(K)]), !.
% oops: this variable has no attributes. % oops: this variable has no attributes.
process_var(V, _) :- throw(error(instantiation_error,clpbn(attribute_goal(V)))). process_var(V, _) :- throw(error(instantiation_error,clpbn(attribute_goal(V)))).
% %
% unify a CLPBN variable with something. % unify a CLPBN variable with something.
% %
verify_attributes(Var, T, Goal) :- verify_attributes(Var, T, Goal) :-
get_atts(Var, [key(Key),dist(Dist,Parents)]), !, get_atts(Var, [key(Key),dist(Dist,Parents)]), !,
@ -641,7 +641,7 @@ clpbn_init_solver(pcg, LVs, Vs0, VarsWithUnboundKeys, State) :-
% %
% LVs is the list of lists of variables to marginalise % LVs is the list of lists of variables to marginalise
% Vs is the full graph % Vs is the full graph
% Ps are the probabilities on LVs. % Ps are the probabilities on LVs.
% %
clpbn_run_solver(LVs, LPs, State) :- clpbn_run_solver(LVs, LPs, State) :-
solver(Solver), solver(Solver),
@ -708,7 +708,7 @@ pfl_run_solver(LVs, LPs, State) :-
pfl_run_solver(LVs, LPs, State, ve) :- !, pfl_run_solver(LVs, LPs, State, ve) :- !,
run_ve_ground_solver(LVs, LPs, State). run_ve_ground_solver(LVs, LPs, State).
pfl_run_solver(LVs, LPs, State, hve) :- !, pfl_run_solver(LVs, LPs, State, hve) :- !,
run_horus_ground_solver(LVs, LPs, State). run_horus_ground_solver(LVs, LPs, State).
@ -732,7 +732,7 @@ add_keys(Key1+V1,_Key2,Key1+V1).
probability(Goal, Prob) :- probability(Goal, Prob) :-
findall(Prob, do_probability(Goal, [], Prob), [Prob]). findall(Prob, do_probability(Goal, [], Prob), [Prob]).
conditional_probability(Goal, ListOfGoals, Prob) :- conditional_probability(Goal, ListOfGoals, Prob) :-
\+ ground(Goal), \+ ground(Goal),
throw(error(ground(Goal),conditional_probability(Goal, ListOfGoals, Prob))). throw(error(ground(Goal),conditional_probability(Goal, ListOfGoals, Prob))).
@ -766,7 +766,7 @@ evidence_to_var(Goal, C, VItem, V) :-
Goal =.. [L|Args], Goal =.. [L|Args],
variabilise_last(Args, C, NArgs, V), variabilise_last(Args, C, NArgs, V),
VItem =.. [L|NArgs]. VItem =.. [L|NArgs].
variabilise_last([Arg], Arg, [V], V). variabilise_last([Arg], Arg, [V], V).
variabilise_last([Arg1,Arg2|Args], Arg, Arg1.NArgs, V) :- variabilise_last([Arg1,Arg2|Args], Arg, Arg1.NArgs, V) :-
variabilise_last(Arg2.Args, Arg, NArgs, V). variabilise_last(Arg2.Args, Arg, NArgs, V).

View File

@ -96,11 +96,11 @@ find_ev(_Evs, Key, RemKeys, [Key|RemKeys], Ev, Ev).
% +final CPT % +final CPT
% - New Parents % - New Parents
% + - list of new keys % + - list of new keys
% %
avg_table(Vars, OVars, Domain, Key, TotEvidence, Softness, Vars, Vs, Vs, Id) :- avg_table(Vars, OVars, Domain, Key, TotEvidence, Softness, Vars, Vs, Vs, Id) :-
length(Domain, SDomain), length(Domain, SDomain),
int_power(Vars, SDomain, 1, TabSize), int_power(Vars, SDomain, 1, TabSize),
TabSize =< 256, TabSize =< 256,
/* case gmp is not there !! */ /* case gmp is not there !! */
TabSize > 0, !, TabSize > 0, !,
average_cpt(Vars, OVars, Domain, TotEvidence, Softness, CPT), average_cpt(Vars, OVars, Domain, TotEvidence, Softness, CPT),
@ -170,7 +170,7 @@ cpt_min([_|Vars], Key, Els0, CPT, Vs, NewVs) :-
build_avg_table(Vars, OVars, Domain, _, TotEvidence, Softness, CPT, Vars, Vs, Vs) :- build_avg_table(Vars, OVars, Domain, _, TotEvidence, Softness, CPT, Vars, Vs, Vs) :-
length(Domain, SDomain), length(Domain, SDomain),
int_power(Vars, SDomain, 1, TabSize), int_power(Vars, SDomain, 1, TabSize),
TabSize =< 256, TabSize =< 256,
/* case gmp is not there !! */ /* case gmp is not there !! */
TabSize > 0, !, TabSize > 0, !,
average_cpt(Vars, OVars, Domain, TotEvidence, Softness, CPT). average_cpt(Vars, OVars, Domain, TotEvidence, Softness, CPT).
@ -304,7 +304,7 @@ get_ds_lengths([],[]).
get_ds_lengths([V|Vs],[Sz|Lengs]) :- get_ds_lengths([V|Vs],[Sz|Lengs]) :-
get_vdist_size(V, Sz), get_vdist_size(V, Sz),
get_ds_lengths(Vs,Lengs). get_ds_lengths(Vs,Lengs).
fill_in_average(Lengs, N, Base, MCPT) :- fill_in_average(Lengs, N, Base, MCPT) :-
generate(Lengs, Case), generate(Lengs, Case),
average(Case, N, Base, Val), average(Case, N, Base, Val),

View File

@ -9,12 +9,12 @@ V = v(Va, Vb, Vc)
The generic formula is The generic formula is
V <- X, Y V <- X, Y
Va <- P*X1*Y1 + Q*X2*Y2 + ... Va <- P*X1*Y1 + Q*X2*Y2 + ...
**************************************************/ **************************************************/
:- module(clpbn_bdd, :- module(clpbn_bdd,
@ -80,8 +80,8 @@ bdds(bdd).
% %
% QVars: all query variables? % QVars: all query variables?
% %
% %
init_bdd_ground_solver(QueryKeys, AllKeys, Factors, Evidence, bdd(QueryKeys, AllKeys, Factors, Evidence)). init_bdd_ground_solver(QueryKeys, AllKeys, Factors, Evidence, bdd(QueryKeys, AllKeys, Factors, Evidence)).
% %
@ -161,7 +161,7 @@ sort_keys(AllFs, AllVars, Leaves) :-
dgraph_top_sort(Graph, AllVars). dgraph_top_sort(Graph, AllVars).
add_node(f([K|Parents],_,_,_), Graph0, Graph) :- add_node(f([K|Parents],_,_,_), Graph0, Graph) :-
dgraph_add_vertex(Graph0, K, Graph1), dgraph_add_vertex(Graph0, K, Graph1),
foldl(add_edge(K), Parents, Graph1, Graph). foldl(add_edge(K), Parents, Graph1, Graph).
add_edge(K, K0, Graph0, Graph) :- add_edge(K, K0, Graph0, Graph) :-
@ -176,7 +176,7 @@ sort_vars(AllVars0, AllVars, Leaves) :-
build_graph([], Graph, Graph). build_graph([], Graph, Graph).
build_graph([V|AllVars0], Graph0, Graph) :- build_graph([V|AllVars0], Graph0, Graph) :-
clpbn:get_atts(V, [dist(_DistId, Parents)]), !, clpbn:get_atts(V, [dist(_DistId, Parents)]), !,
dgraph_add_vertex(Graph0, V, Graph1), dgraph_add_vertex(Graph0, V, Graph1),
add_parents(Parents, V, Graph1, GraphI), add_parents(Parents, V, Graph1, GraphI),
build_graph(AllVars0, GraphI, Graph). build_graph(AllVars0, GraphI, Graph).
build_graph(_V.AllVars0, Graph0, Graph) :- build_graph(_V.AllVars0, Graph0, Graph) :-
@ -184,7 +184,7 @@ build_graph(_V.AllVars0, Graph0, Graph) :-
add_parents([], _V, Graph, Graph). add_parents([], _V, Graph, Graph).
add_parents([V0|Parents], V, Graph0, GraphF) :- add_parents([V0|Parents], V, Graph0, GraphF) :-
dgraph_add_edge(Graph0, V0, V, GraphI), dgraph_add_edge(Graph0, V0, V, GraphI),
add_parents(Parents, V, GraphI, GraphF). add_parents(Parents, V, GraphI, GraphF).
get_keys_info([], _, _, _, Vs, Vs, Ps, Ps, _, _) --> []. get_keys_info([], _, _, _, Vs, Vs, Ps, Ps, _, _) --> [].
@ -378,7 +378,7 @@ avg_tree([Vals|PVars], P, Max, Im, IM, Size, O, H0, HF) :-
MaxI is Max-(Size-1), MaxI is Max-(Size-1),
avg_exp(Vals, PVars, 0, P, MaxI, Size, Im, IM, HI, HF, Exp), avg_exp(Vals, PVars, 0, P, MaxI, Size, Im, IM, HI, HF, Exp),
simplify_exp(Exp, Simp). simplify_exp(Exp, Simp).
avg_exp([], _, _, _P, _Max, _Size, _Im, _IM, H, H, 0). avg_exp([], _, _, _P, _Max, _Size, _Im, _IM, H, H, 0).
avg_exp([Val|Vals], PVars, I0, P0, Max, Size, Im, IM, HI, HF, O) :- avg_exp([Val|Vals], PVars, I0, P0, Max, Size, Im, IM, HI, HF, O) :-
(Vals = [] -> O=O1 ; O = Val*O1+not(Val)*O2 ), (Vals = [] -> O=O1 ; O = Val*O1+not(Val)*O2 ),
@ -434,7 +434,7 @@ bup_avg(V, Size, Domain, Parents0, Vs, Vs2, Lvs, Outs, DIST) :-
bin_sums(Vs, Sums, F) :- bin_sums(Vs, Sums, F) :-
vs_to_sums(Vs, Sums0), vs_to_sums(Vs, Sums0),
bin_sums(Sums0, Sums, F, []). bin_sums(Sums0, Sums, F, []).
vs_to_sums([], []). vs_to_sums([], []).
vs_to_sums([V|Vs], [Sum|Sums0]) :- vs_to_sums([V|Vs], [Sum|Sums0]) :-
Sum =.. [sum|V], Sum =.. [sum|V],
@ -536,7 +536,7 @@ sum_all([_V|Vs], Pos, I, Max0, Sums, List) :-
gen_arg(J, Sums, Max, S0) :- gen_arg(J, Sums, Max, S0) :-
gen_arg(0, Max, J, Sums, S0). gen_arg(0, Max, J, Sums, S0).
gen_arg(Max, Max, J, Sums, S0) :- !, gen_arg(Max, Max, J, Sums, S0) :- !,
I is Max+1, I is Max+1,
arg(I, Sums, A), arg(I, Sums, A),
@ -647,19 +647,19 @@ copy(N, [], [], Ms, Parms0, Parms, ParmVars) :-!,
copy(N, Ms, NewMs, NewMs, Parms0, Parms, ParmVars). copy(N, Ms, NewMs, NewMs, Parms0, Parms, ParmVars).
copy(N, D.Ds, ND.NDs, New, El.Parms0, NEl.Parms, V.ParmVars) :- copy(N, D.Ds, ND.NDs, New, El.Parms0, NEl.Parms, V.ParmVars) :-
N1 is N-1, N1 is N-1,
(El == 0.0 -> (El == 0.0 ->
NEl = 0, NEl = 0,
V = NEl, V = NEl,
ND = D ND = D
;El == 1.0 -> ;El == 1.0 ->
NEl = 1, NEl = 1,
V = NEl, V = NEl,
ND = 0.0 ND = 0.0
;El == 0 -> ;El == 0 ->
NEl = 0, NEl = 0,
V = NEl, V = NEl,
ND = D ND = D
;El =:= 1 -> ;El =:= 1 ->
NEl = 1, NEl = 1,
V = NEl, V = NEl,
ND = 0.0, ND = 0.0,
@ -818,7 +818,7 @@ get_key_evidence(V, Evs, _, Tree, Ev, F0, F, Leaves, Finals) :-
%% deterministic(V, DistId), %% deterministic(V, DistId),
%% !, %% !,
%% one_list(Ev), %% one_list(Ev),
%% eval_outs(F0). %% eval_outs(F0).
%% no evidence !!! %% no evidence !!!
get_key_evidence(V, _, _, Tree, _Values, F0, F1, Leaves, Finals) :- get_key_evidence(V, _, _, Tree, _Values, F0, F1, Leaves, Finals) :-
insert_output(Leaves, V, Finals, Tree, Outs, SendOut), insert_output(Leaves, V, Finals, Tree, Outs, SendOut),
@ -836,14 +836,14 @@ get_evidence(V, _Tree, Ev, F0, [], _Leaves, _Finals) :-
( Name = 'AVG' ; Name = 'MAX' ; Name = 'MIN' ), ( Name = 'AVG' ; Name = 'MAX' ; Name = 'MIN' ),
!, !,
one_list(Ev), one_list(Ev),
eval_outs(F0). eval_outs(F0).
%% no evidence !!! %% no evidence !!!
get_evidence(V, Tree, _Values, F0, F1, Leaves, Finals) :- get_evidence(V, Tree, _Values, F0, F1, Leaves, Finals) :-
insert_output(Leaves, V, Finals, Tree, Outs, SendOut), insert_output(Leaves, V, Finals, Tree, Outs, SendOut),
get_outs(F0, F1, SendOut, Outs). get_outs(F0, F1, SendOut, Outs).
zero_pos(_, _Pos, []). zero_pos(_, _Pos, []).
zero_pos(Pos, Pos, [1|Values]) :- !, zero_pos(Pos, Pos, [1|Values]) :- !,
I is Pos+1, I is Pos+1,
zero_pos(I, Pos, Values). zero_pos(I, Pos, Values).
zero_pos(I0, Pos, [0|Values]) :- zero_pos(I0, Pos, [0|Values]) :-
@ -855,7 +855,7 @@ one_list(1.Ev) :-
one_list(Ev). one_list(Ev).
% %
% insert a node with the disj of all alternatives, this is only done if node ends up to be in the output % insert a node with the disj of all alternatives, this is only done if node ends up to be in the output
% %
insert_output([], _V, [], _Out, _Outs, []). insert_output([], _V, [], _Out, _Outs, []).
insert_output(V._Leaves, V0, [Top|_], Top, Outs, [Top = Outs]) :- V == V0, !. insert_output(V._Leaves, V0, [Top|_], Top, Outs, [Top = Outs]) :- V == V0, !.
@ -1057,7 +1057,7 @@ generate_exclusions([V0|SeenVs], V) -->
build_cnf(CNF, IVs, Indics, AllParms, AllParmValues, Val) :- build_cnf(CNF, IVs, Indics, AllParms, AllParmValues, Val) :-
%(numbervars(CNF,1,_), writeln(cnf_to_ddnnf(CNF, Vars, IVs, [], F)), fail ; true ), %(numbervars(CNF,1,_), writeln(cnf_to_ddnnf(CNF, Vars, IVs, [], F)), fail ; true ),
cnf_to_ddnnf(CNF, AllParms, F), cnf_to_ddnnf(CNF, AllParms, F),
AllParms = AllParmValues, AllParms = AllParmValues,
IVs = Indics, IVs = Indics,
term_variables(CNF, Extra), term_variables(CNF, Extra),

View File

@ -101,7 +101,7 @@ do_bnt(QueryVars, AllVars, AllDiffs) :-
add_evidence(SortedVertices, Size, NumberedVertices), add_evidence(SortedVertices, Size, NumberedVertices),
marginalize(QueryVars, SortedVertices, NumberedVertices, Ps), marginalize(QueryVars, SortedVertices, NumberedVertices, Ps),
clpbn_bind_vals(QueryVars, Ps, AllDiffs). clpbn_bind_vals(QueryVars, Ps, AllDiffs).
create_bnt_graph(AllVars, Representatives) :- create_bnt_graph(AllVars, Representatives) :-
create_bnt_graph(AllVars, Representatives, _, _, _). create_bnt_graph(AllVars, Representatives, _, _, _).
@ -320,7 +320,7 @@ get_sizes_and_ids([V|Parents],[Id-V|Ids]) :-
extract_vars([], L, L). extract_vars([], L, L).
extract_vars([_-V|NIds], NParents, Vs) :- extract_vars([_-V|NIds], NParents, Vs) :-
extract_vars(NIds, [V|NParents], Vs). extract_vars(NIds, [V|NParents], Vs).
mkcpt(BayesNet, I, Tab) :- mkcpt(BayesNet, I, Tab) :-
(BayesNet.'CPD'({I})) <-- tabular_CPD(BayesNet,I,Tab). (BayesNet.'CPD'({I})) <-- tabular_CPD(BayesNet,I,Tab).
@ -336,7 +336,7 @@ create_class_vector([], [], [],[]).
create_class_vector([V|Graph], [I|Is], [Id|Classes], [Id-v(V,I,Parents)|Sets]) :- create_class_vector([V|Graph], [I|Is], [Id|Classes], [Id-v(V,I,Parents)|Sets]) :-
clpbn:get_atts(V, [dist(Id,Parents)]), clpbn:get_atts(V, [dist(Id,Parents)]),
create_class_vector(Graph, Is,Classes,Sets). create_class_vector(Graph, Is,Classes,Sets).
representatives([],[]). representatives([],[]).
representatives([Class-Rep|Reps1],[Class-Rep|Reps]) :- representatives([Class-Rep|Reps1],[Class-Rep|Reps]) :-
nonrepresentatives(Reps1, Class, Reps2), nonrepresentatives(Reps1, Class, Reps2),
@ -390,7 +390,7 @@ mk_evidence([V|L], [I|Is], [ar(1,I,EvVal1)|LN]) :-
mk_evidence(L, Is, LN). mk_evidence(L, Is, LN).
mk_evidence([_|L], [_|Is], LN) :- mk_evidence([_|L], [_|Is], LN) :-
mk_evidence(L, Is, LN). mk_evidence(L, Is, LN).
evidence_val(Ev,Val,[Ev|_],Val) :- !. evidence_val(Ev,Val,[Ev|_],Val) :- !.
evidence_val(Ev,I0,[_|Domain],Val) :- evidence_val(Ev,I0,[_|Domain],Val) :-
I1 is I0+1, I1 is I0+1,

View File

@ -24,7 +24,7 @@ propagate_evidence(V, Evs) :-
clpbn:get_atts(V, [evidence(Ev),dist(Id,_)]), !, clpbn:get_atts(V, [evidence(Ev),dist(Id,_)]), !,
get_dist_domain(Id, Out), get_dist_domain(Id, Out),
generate_szs_with_evidence(Out,Ev,0,Evs,Found), generate_szs_with_evidence(Out,Ev,0,Evs,Found),
(var(Found) -> (var(Found) ->
clpbn:get_atts(V, [key(K)]), clpbn:get_atts(V, [key(K)]),
throw(clpbn(evidence_does_not_match,K,Ev,[Out])) throw(clpbn(evidence_does_not_match,K,Ev,[Out]))
; ;

View File

@ -78,7 +78,7 @@ clpbn_bind_vals([Vs|MoreVs],[Ps|MorePs],AllDiffs) :-
clpbn_bind_vals2([],_,_) :- !. clpbn_bind_vals2([],_,_) :- !.
% simple case, we want a distribution on a single variable. % simple case, we want a distribution on a single variable.
clpbn_bind_vals2([V],Ps,AllDiffs) :- clpbn_bind_vals2([V],Ps,AllDiffs) :-
use_parfactors(on), !, use_parfactors(on), !,
clpbn:get_atts(V, [key(K)]), clpbn:get_atts(V, [key(K)]),
pfl:skolem(K,Vals), pfl:skolem(K,Vals),

View File

@ -90,7 +90,7 @@ where Id is the id,
dna for [a,c,g,t] dna for [a,c,g,t]
rna for [a,c,g,u] rna for [a,c,g,u]
reals reals
********************************************/ ********************************************/

View File

@ -31,7 +31,7 @@
:- dynamic node/3, edge/2, evidence/2. :- dynamic node/3, edge/2, evidence/2.
% %
% new evidence storage algorithm. The idea is that instead of % new evidence storage algorithm. The idea is that instead of
% redoing all the evidence every time we query the network, we shall % redoing all the evidence every time we query the network, we shall
% keep a precompiled version around. % keep a precompiled version around.
% %
@ -51,9 +51,9 @@ compute_evidence(_,PreviousSolver) :-
set_clpbn_flag(solver, PreviousSolver). set_clpbn_flag(solver, PreviousSolver).
get_clpbn_vars(G, Vars) :- get_clpbn_vars(G, Vars) :-
% attributes:all_attvars(Vars0), % attributes:all_attvars(Vars0),
once(G), once(G),
attributes:all_attvars(Vars). attributes:all_attvars(Vars).
evidence_error(Ball,PreviousSolver) :- evidence_error(Ball,PreviousSolver) :-
set_clpbn_flag(solver,PreviousSolver), set_clpbn_flag(solver,PreviousSolver),

View File

@ -137,7 +137,7 @@ graph_representation([V|Vs], Graph, I0, Keys, [I-IParents|TGraph]) :-
graph_representation(Vs, Graph, I, Keys, TGraph). graph_representation(Vs, Graph, I, Keys, TGraph).
write_pars([]). write_pars([]).
write_pars([V|Parents]) :- write_pars([V|Parents]) :-
clpbn:get_atts(V, [key(K),dist(I,_)]),write(K:I),nl, clpbn:get_atts(V, [key(K),dist(I,_)]),write(K:I),nl,
write_pars(Parents). write_pars(Parents).
@ -149,7 +149,7 @@ get_sizes([V|Parents], [Sz|Szs]) :-
parent_indices([], _, []). parent_indices([], _, []).
parent_indices([V|Parents], Keys, [I|IParents]) :- parent_indices([V|Parents], Keys, [I|IParents]) :-
rb_lookup(V, I, Keys), rb_lookup(V, I, Keys),
parent_indices(Parents, Keys, IParents). parent_indices(Parents, Keys, IParents).
@ -174,7 +174,7 @@ propagate2parents([V|NewParents], Table, Variables, Graph, Keys) :-
propagate2parents(NewParents,Table, Variables, Graph, Keys). propagate2parents(NewParents,Table, Variables, Graph, Keys).
add2graph(V, Vals, Table, IParents, Graph, Keys) :- add2graph(V, Vals, Table, IParents, Graph, Keys) :-
rb_lookup(V, Index, Keys), rb_lookup(V, Index, Keys),
(var(Vals) -> true ; length(Vals,Sz)), (var(Vals) -> true ; length(Vals,Sz)),
arg(Index, Graph, var(V,Index,_,Vals,Sz,VarSlot,_,_,_)), arg(Index, Graph, var(V,Index,_,Vals,Sz,VarSlot,_,_,_)),
member(tabular(Table,Index,IParents), VarSlot), !. member(tabular(Table,Index,IParents), VarSlot), !.
@ -239,7 +239,7 @@ mult_list([Sz|Sizes],Mult0,Mult) :-
MultI is Sz*Mult0, MultI is Sz*Mult0,
mult_list(Sizes,MultI,Mult). mult_list(Sizes,MultI,Mult).
% compile node as set of facts, faster execution % compile node as set of facts, faster execution
compile_var(TotSize,I,_Vals,Sz,CPTs,Parents,_Sizes,Graph) :- compile_var(TotSize,I,_Vals,Sz,CPTs,Parents,_Sizes,Graph) :-
TotSize < 1024*64, TotSize > 0, !, TotSize < 1024*64, TotSize > 0, !,
multiply_all(I,Parents,CPTs,Sz,Graph). multiply_all(I,Parents,CPTs,Sz,Graph).
@ -367,8 +367,8 @@ generate_est_mults([], [], _, [], 1).
generate_est_mults([V|Vs], [I|Is], Graph, [M0|Mults], M) :- generate_est_mults([V|Vs], [I|Is], Graph, [M0|Mults], M) :-
arg(V,Graph,var(_,I,_,_,Sz,_,_,_,_)), arg(V,Graph,var(_,I,_,_,Sz,_,_,_,_)),
generate_est_mults(Vs, Is, Graph, Mults, M0), generate_est_mults(Vs, Is, Graph, Mults, M0),
M is M0*Sz. M is M0*Sz.
gen_e0(0,[]) :- !. gen_e0(0,[]) :- !.
gen_e0(Sz,[0|E0L]) :- gen_e0(Sz,[0|E0L]) :-
Sz1 is Sz-1, Sz1 is Sz-1,
@ -531,7 +531,7 @@ add_up_mes(Counts,[me(_,_,Cs)|Chains], Add) :-
sum_lists(Counts, Cs, NCounts), sum_lists(Counts, Cs, NCounts),
add_up_mes(NCounts, Chains, Add). add_up_mes(NCounts, Chains, Add).
sum_lists([],[],[]). sum_lists([],[],[]).
sum_lists([Count|Counts], [C|Cs], [NC|NCounts]) :- sum_lists([Count|Counts], [C|Cs], [NC|NCounts]) :-
NC is Count+C, NC is Count+C,
sum_lists(Counts, Cs, NCounts). sum_lists(Counts, Cs, NCounts).

View File

@ -50,7 +50,7 @@ output_parents1(Stream,[V|L]) :-
put_code(Stream, 0' ), %' put_code(Stream, 0' ), %'
output_parents1(Stream,L). output_parents1(Stream,L).
output_v(V,Stream) :- output_v(V,Stream) :-
clpbn:get_atts(V,[key(Key)]), clpbn:get_atts(V,[key(Key)]),
output_key(Stream,Key). output_key(Stream,Key).

View File

@ -1,7 +1,7 @@
/******************************************************* /*******************************************************
Horus Interface Horus Interface
********************************************************/ ********************************************************/
:- module(clpbn_horus, :- module(clpbn_horus,

View File

@ -4,7 +4,7 @@
- Variable Elimination - Variable Elimination
- Belief Propagation - Belief Propagation
- Counting Belief Propagation - Counting Belief Propagation
********************************************************/ ********************************************************/
:- module(clpbn_horus_ground, :- module(clpbn_horus_ground,

View File

@ -98,7 +98,7 @@ jt(LLVs,Vs0,AllDiffs) :-
init_jt_solver(LLVs, Vs0, _, State) :- init_jt_solver(LLVs, Vs0, _, State) :-
check_for_agg_vars(Vs0, Vs1), check_for_agg_vars(Vs0, Vs1),
init_influences(Vs1, G, RG), init_influences(Vs1, G, RG),
maplist(init_jt_solver_for_question(G, RG), LLVs, State). maplist(init_jt_solver_for_question(G, RG), LLVs, State).
@ -163,7 +163,7 @@ initial_graph(_,Parents, CPTs) :-
% from the very beginning. % from the very beginning.
dgraph_transpose(V1, V2), dgraph_transpose(V1, V2),
dgraph_to_ugraph(V2, Parents). dgraph_to_ugraph(V2, Parents).
problem_graph([], []). problem_graph([], []).
problem_graph([V|BNet], GraphF) :- problem_graph([V|BNet], GraphF) :-

View File

@ -87,7 +87,7 @@ evidence(V, Pos) :-
clpbn:get_atts(V, [evidence(Pos)]). clpbn:get_atts(V, [evidence(Pos)]).
vnth([V1|Deps], N, V, N, Deps) :- vnth([V1|Deps], N, V, N, Deps) :-
V == V1, !. V == V1, !.
vnth([V1|Deps], N0, V, N, [V1|NDeps]) :- vnth([V1|Deps], N0, V, N, [V1|NDeps]) :-
N1 is N0+1, N1 is N0+1,
vnth(Deps, N1, V, N, NDeps). vnth(Deps, N1, V, N, NDeps).
@ -207,9 +207,9 @@ generate_map([V|DimsNew], [V0|Dims0], [0|Map]) :- V == V0, !,
generate_map(DimsNew, Dims0, Map). generate_map(DimsNew, Dims0, Map).
generate_map([V|DimsNew], Dims0, [Sz|Map]) :- generate_map([V|DimsNew], Dims0, [Sz|Map]) :-
clpbn:get_atts(V, [dist(Id,_)]), clpbn:get_atts(V, [dist(Id,_)]),
clpbn_dist:get_dist_domain_size(Id, Sz), clpbn_dist:get_dist_domain_size(Id, Sz),
generate_map(DimsNew, Dims0, Map). generate_map(DimsNew, Dims0, Map).
unit_CPT(V,CPT) :- unit_CPT(V,CPT) :-
clpbn:get_atts(V, [dist(Id,_)]), clpbn:get_atts(V, [dist(Id,_)]),
clpbn_dist:get_dist_domain_size(Id, Sz), clpbn_dist:get_dist_domain_size(Id, Sz),
@ -287,7 +287,7 @@ uniform_CPT(Dims, M) :-
normalise_possibly_deterministic_CPT(M1, M). normalise_possibly_deterministic_CPT(M1, M).
normalise_CPT_on_lines(MAT0, MAT2, L1) :- normalise_CPT_on_lines(MAT0, MAT2, L1) :-
matrix_agg_cols(MAT0, +, MAT1), matrix_agg_cols(MAT0, +, MAT1),
matrix_sum(MAT1, SUM), matrix_sum(MAT1, SUM),
matrix_op_to_all(MAT1, /, SUM, MAT2), matrix_op_to_all(MAT1, /, SUM, MAT2),
matrix:matrix_to_list(MAT2,L1). matrix:matrix_to_list(MAT2,L1).

View File

@ -1,7 +1,7 @@
:- module(clpbn_numbers, :- module(clpbn_numbers,
[keys_to_numbers/7, [keys_to_numbers/7,
keys_to_numbers/9, keys_to_numbers/9,
lists_of_keys_to_ids/6 lists_of_keys_to_ids/6
]). ]).

View File

@ -176,7 +176,7 @@ get_internal(S, InternalS, Arg) :-
extract_probability(p(Id,Goals), P) :- extract_probability(p(Id,Goals), P) :-
id(Id,_,P0,_), id(Id,_,P0,_),
LogP0 is log(P0), LogP0 is log(P0),
extract_logprobability(Goals, LogP0, LogP), extract_logprobability(Goals, LogP0, LogP),
P is exp(LogP). P is exp(LogP).

View File

@ -37,11 +37,11 @@
clpbn_tabled_clause_ref(:.?,?), clpbn_tabled_clause_ref(:.?,?),
clpbn_tabled_retract(:), clpbn_tabled_retract(:),
clpbn_tabled_abolish(:), clpbn_tabled_abolish(:),
clpbn_tabled_asserta(:), clpbn_tabled_asserta(:),
clpbn_tabled_assertz(:), clpbn_tabled_assertz(:),
clpbn_tabled_asserta(:,-), clpbn_tabled_asserta(:,-),
clpbn_tabled_assertz(:,-), clpbn_tabled_assertz(:,-),
clpbn_tabled_number_of_clauses(:,-), clpbn_tabled_number_of_clauses(:,-),
clpbn_is_tabled(:). clpbn_is_tabled(:).
:- use_module(library(terms), :- use_module(library(terms),

View File

@ -66,7 +66,7 @@ merge_same_key([K1-V1,K2-V2|Vs], SortedAVars, Ks, UnifiableVars) :-
attributes:fast_unify_attributed(V1,V2), attributes:fast_unify_attributed(V1,V2),
merge_same_key([K1-V1|Vs], SortedAVars, Ks, UnifiableVars). merge_same_key([K1-V1|Vs], SortedAVars, Ks, UnifiableVars).
merge_same_key([K1-V1,K2-V2|Vs], [V1|SortedAVars], Ks, [K1|UnifiableVars]) :- merge_same_key([K1-V1,K2-V2|Vs], [V1|SortedAVars], Ks, [K1|UnifiableVars]) :-
(in_keys(K1, Ks) ; \+ \+ K1 == K2), !, (in_keys(K1, Ks) ; \+ \+ K1 == K2), !,
add_to_keys(K1, Ks, NKs), add_to_keys(K1, Ks, NKs),
merge_same_key([K2-V2|Vs], SortedAVars, NKs, UnifiableVars). merge_same_key([K2-V2|Vs], SortedAVars, NKs, UnifiableVars).
merge_same_key([K-V|Vs], [V|SortedAVars], Ks, UnifiableVars) :- merge_same_key([K-V|Vs], [V|SortedAVars], Ks, UnifiableVars) :-
@ -74,7 +74,7 @@ merge_same_key([K-V|Vs], [V|SortedAVars], Ks, UnifiableVars) :-
merge_same_key(Vs, SortedAVars, NKs, UnifiableVars). merge_same_key(Vs, SortedAVars, NKs, UnifiableVars).
in_keys(K1,[K|_]) :- \+ \+ K1 = K, !. in_keys(K1,[K|_]) :- \+ \+ K1 = K, !.
in_keys(K1,[_|Ks]) :- in_keys(K1,[_|Ks]) :-
in_keys(K1,Ks). in_keys(K1,Ks).
add_to_keys(K1, Ks, Ks) :- ground(K1), !. add_to_keys(K1, Ks, Ks) :- ground(K1), !.

View File

@ -11,7 +11,7 @@
all tables they connect to; all tables they connect to;
multiply their size multiply their size
order by size order by size
*********************************/ *********************************/
:- module(clpbn_ve, :- module(clpbn_ve,
@ -134,7 +134,7 @@ evtotree(K=V,Ev0,Ev) :-
factor_to_graph( f(Nodes, Sizes, _Pars0, Id), Factors0, Factors, Edges0, Edges, I0, I) :- factor_to_graph( f(Nodes, Sizes, _Pars0, Id), Factors0, Factors, Edges0, Edges, I0, I) :-
I is I0+1, I is I0+1,
pfl:get_pfl_parameters(Id, Pars0), pfl:get_pfl_parameters(Id, Pars0),
init_CPT(Pars0, Sizes, CPT0), init_CPT(Pars0, Sizes, CPT0),
reorder_CPT(Nodes, CPT0, FIPs, CPT, _), reorder_CPT(Nodes, CPT0, FIPs, CPT, _),
F = f(I0, FIPs, CPT), F = f(I0, FIPs, CPT),
rb_insert(Factors0, I0, F, Factors), rb_insert(Factors0, I0, F, Factors),
@ -196,7 +196,7 @@ id_to_factor(VMap, V-I, IF0, IF, Fs0, Fs, Evs0, Evs) :-
get_dist_params(D, Pars0), get_dist_params(D, Pars0),
get_dist_domain_size(D, DS), get_dist_domain_size(D, DS),
maplist(parent_to_id(VMap), Ps, Sizes, IPs), maplist(parent_to_id(VMap), Ps, Sizes, IPs),
init_CPT(Pars0, [DS|Sizes], CPT0), init_CPT(Pars0, [DS|Sizes], CPT0),
reorder_CPT([I|IPs], CPT0, FIPs, CPT, _), reorder_CPT([I|IPs], CPT0, FIPs, CPT, _),
rb_insert(Fs0, IF0, f(IF0, FIPs, CPT), Fs), rb_insert(Fs0, IF0, f(IF0, FIPs, CPT), Fs),
IF is IF0+1. IF is IF0+1.
@ -261,7 +261,7 @@ solve([_|LQVs], FIds, Bigraph, Ev, LPs) :-
do_solve(IQVs, IVs, bigraph(OldVs, IF, _Fs), Ev, Ps) :- do_solve(IQVs, IVs, bigraph(OldVs, IF, _Fs), Ev, Ps) :-
% get only what is relevant to query, % get only what is relevant to query,
project_to_query_related(IVs, OldVs, SVs, Fs1), project_to_query_related(IVs, OldVs, SVs, Fs1),
% and also prune using evidence % and also prune using evidence
rb_visit(Ev, EvL), rb_visit(Ev, EvL),
foldl2(clean_v_ev, EvL, Fs1, Fs2, SVs, EVs), foldl2(clean_v_ev, EvL, Fs1, Fs2, SVs, EVs),
@ -300,9 +300,9 @@ run_ve_solver(_, LLPs, state(LQVs, LVs, _VMap, Bigraph, Ev)) :-
% %
solve_ve([IQVs|_], [IVs|_], bigraph(OldVs, IF, _Fs), Ev, Ps) :- solve_ve([IQVs|_], [IVs|_], bigraph(OldVs, IF, _Fs), Ev, Ps) :-
% get only what is relevant to query, % get only what is relevant to query,
project_to_query_related(IVs, OldVs, SVs, Fs1), project_to_query_related(IVs, OldVs, SVs, Fs1),
% and also prune using evidence % and also prune using evidence
foldl2(clean_v_ev, Ev, Fs1, Fs2, SVs, EVs), foldl2(clean_v_ev, Ev, Fs1, Fs2, SVs, EVs),
% eliminate % eliminate
eliminate(IQVs, digraph(EVs, IF, Fs2), Dist), eliminate(IQVs, digraph(EVs, IF, Fs2), Dist),
% writeln(m:Dist),matrix:matrix_to_list(Dist,LD),writeln(LD), % writeln(m:Dist),matrix:matrix_to_list(Dist,LD),writeln(LD),
@ -319,7 +319,7 @@ solve_ve([_|MoreLVs], [_|MoreLVis], Digraph, Ev, Ps) :-
project_to_query_related(IVs0, OldVs, NVs, NFs) :- project_to_query_related(IVs0, OldVs, NVs, NFs) :-
sort(IVs0, IVs), sort(IVs0, IVs),
rb_new(Vs0), rb_new(Vs0),
foldl(cp_to_vs, IVs, Vs0, AuxVs), foldl(cp_to_vs, IVs, Vs0, AuxVs),
rb_new(NFs0), rb_new(NFs0),
foldl(simplify_graph_node(OldVs, AuxVs), IVs, VFs, NFs0, NFs), foldl(simplify_graph_node(OldVs, AuxVs), IVs, VFs, NFs0, NFs),
list_to_rbtree(VFs, NVs). list_to_rbtree(VFs, NVs).
@ -343,14 +343,14 @@ simplify_graph_node(OldVs, NVs, V, V-RemFs, NFs0, NFs) :-
% %
% Two cases: first time factor comes up: all its vars must be in subgraph % Two cases: first time factor comes up: all its vars must be in subgraph
% second case: second time it comes up, it must be already in graph % second case: second time it comes up, it must be already in graph
% %
% args: +Factor F, +current V (int), +rbtree with all Vs, % args: +Factor F, +current V (int), +rbtree with all Vs,
% -Factors in new Graph, +factors in current graph, -rbtree of factors % -Factors in new Graph, +factors in current graph, -rbtree of factors
% %
% %
check_factor(V, NVs, F, NFs0, NFs, RemFs, NewRemFs) :- check_factor(V, NVs, F, NFs0, NFs, RemFs, NewRemFs) :-
F = f(IF, [V|More], _), !, F = f(IF, [V|More], _), !,
( (
checklist(check_v(NVs), More) checklist(check_v(NVs), More)
-> ->
rb_insert(NFs0, IF, F, NFs), rb_insert(NFs0, IF, F, NFs),
@ -361,7 +361,7 @@ check_factor(V, NVs, F, NFs0, NFs, RemFs, NewRemFs) :-
). ).
check_factor(_V, _NVs, F, NFs, NFs, RemFs, NewRemFs) :- check_factor(_V, _NVs, F, NFs, NFs, RemFs, NewRemFs) :-
F = f(Id, _, _), F = f(Id, _, _),
( (
rb_lookup(Id, F, NFs) rb_lookup(Id, F, NFs)
-> ->
NewRemFs = [F|RemFs] NewRemFs = [F|RemFs]

View File

@ -12,7 +12,7 @@
:- use_module(library(maplist)). :- use_module(library(maplist)).
% %
% vmap: map V->I % vmap: map V->I
% contiguous Vs to contiguous integers % contiguous Vs to contiguous integers
% %
init_vmap(vmap(0,Empty)) :- init_vmap(vmap(0,Empty)) :-

View File

@ -41,4 +41,4 @@ write_cpts([CPT|CPTs]) :-
matrix_to_list(CPT,L), matrix_to_list(CPT,L),
format('CPT=~w~n',[L]), format('CPT=~w~n',[L]),
write_cpts(CPTs). write_cpts(CPTs).

View File

@ -55,7 +55,7 @@ professor_popularity(P,A) :- pop(P,A).
course_difficulty(P,A) :- diff(P,A). course_difficulty(P,A) :- diff(P,A).
student_intelligence(P,A) :- int(P,A). student_intelligence(P,A) :- int(P,A).
course_rating(C,X) :- rat(C,X). course_rating(C,X) :- rat(C,X).
registration_grade(R,A) :- registration_grade(R,A) :-

View File

@ -75,17 +75,17 @@ hair_color_table(
/* high low */ /* high low */
/* dark */ [ 0.05, 0.1, /* dark */ [ 0.05, 0.1,
/* bright */ 0.95, 0.9 ]). /* bright */ 0.95, 0.9 ]).
car_color_table( car_color_table(
/* dark bright */ /* dark bright */
/* dark */ [ 0.9, 0.2, /* dark */ [ 0.9, 0.2,
/* bright */ 0.1, 0.8 ]). /* bright */ 0.1, 0.8 ]).
height_table( height_table(
/* male female */ /* male female */
/* tall */ [ 0.6, 0.4, /* tall */ [ 0.6, 0.4,
/* short */ 0.4, 0.6 ]). /* short */ 0.4, 0.6 ]).
shoe_size_table( shoe_size_table(
/* tall short */ /* tall short */
/* big */ [ 0.9, 0.1, /* big */ [ 0.9, 0.1,
@ -99,7 +99,7 @@ descn_table(
/* car_color(P), hair_color(P), height(P), guilty(P) */ /* car_color(P), hair_color(P), height(P), guilty(P) */
/* fits */ [ 0.99, 0.5, 0.23, 0.88, 0.41, 0.3, 0.76, 0.87, /* fits */ [ 0.99, 0.5, 0.23, 0.88, 0.41, 0.3, 0.76, 0.87,
/* fits */ 0.44, 0.43, 0.29, 0.72, 0.23, 0.91, 0.95, 0.92, /* fits */ 0.44, 0.43, 0.29, 0.72, 0.23, 0.91, 0.95, 0.92,
/* dont_fit */ 0.01, 0.5, 0.77, 0.12, 0.59, 0.7, 0.24, 0.13, /* dont_fit */ 0.01, 0.5, 0.77, 0.12, 0.59, 0.7, 0.24, 0.13,
/* dont_fit */ 0.56, 0.57, 0.71, 0.28, 0.77, 0.09, 0.05, 0.08 ]). /* dont_fit */ 0.56, 0.57, 0.71, 0.28, 0.77, 0.09, 0.05, 0.08 ]).
witness_table( witness_table(

View File

@ -4,7 +4,6 @@
#include <vector> #include <vector>
#include <queue> #include <queue>
#include <list> #include <list>
#include <map>
#include "FactorGraph.h" #include "FactorGraph.h"
#include "BayesBallGraph.h" #include "BayesBallGraph.h"
@ -15,8 +14,8 @@ using namespace std;
struct ScheduleInfo struct ScheduleInfo
{ {
ScheduleInfo (BBNode* n, bool vfp, bool vfc) : ScheduleInfo (BBNode* n, bool vfp, bool vfc)
node(n), visitedFromParent(vfp), visitedFromChild(vfc) { } : node(n), visitedFromParent(vfp), visitedFromChild(vfc) { }
BBNode* node; BBNode* node;
bool visitedFromParent; bool visitedFromParent;
@ -30,7 +29,7 @@ typedef queue<ScheduleInfo, list<ScheduleInfo>> Scheduling;
class BayesBall class BayesBall
{ {
public: public:
BayesBall (FactorGraph& fg) BayesBall (FactorGraph& fg)
: fg_(fg) , dag_(fg.getStructure()) : fg_(fg) , dag_(fg.getStructure())
{ {
dag_.clear(); dag_.clear();
@ -63,7 +62,7 @@ inline void
BayesBall::scheduleParents (const BBNode* n, Scheduling& sch) const BayesBall::scheduleParents (const BBNode* n, Scheduling& sch) const
{ {
const vector<BBNode*>& ps = n->parents(); const vector<BBNode*>& ps = n->parents();
for (vector<BBNode*>::const_iterator it = ps.begin(); for (vector<BBNode*>::const_iterator it = ps.begin();
it != ps.end(); ++it) { it != ps.end(); ++it) {
sch.push (ScheduleInfo (*it, false, true)); sch.push (ScheduleInfo (*it, false, true));
} }

View File

@ -30,15 +30,15 @@ class BBNode : public Var
void addChild (BBNode* c) { childs_.push_back (c); } void addChild (BBNode* c) { childs_.push_back (c); }
bool isVisited (void) const { return visited_; } bool isVisited (void) const { return visited_; }
void setAsVisited (void) { visited_ = true; } void setAsVisited (void) { visited_ = true; }
bool isMarkedOnTop (void) const { return markedOnTop_; } bool isMarkedOnTop (void) const { return markedOnTop_; }
void markOnTop (void) { markedOnTop_ = true; } void markOnTop (void) { markedOnTop_ = true; }
bool isMarkedOnBottom (void) const { return markedOnBottom_; } bool isMarkedOnBottom (void) const { return markedOnBottom_; }
void markOnBottom (void) { markedOnBottom_ = true; } void markOnBottom (void) { markedOnBottom_ = true; }
void clear (void) { visited_ = markedOnTop_ = markedOnBottom_ = false; } void clear (void) { visited_ = markedOnTop_ = markedOnBottom_ = false; }

View File

@ -146,7 +146,7 @@ BeliefProp::getFactorJoint (
if (Globals::logDomain) { if (Globals::logDomain) {
Util::exp (jointDist); Util::exp (jointDist);
} }
return jointDist; return jointDist;
} }
@ -185,7 +185,7 @@ BeliefProp::runSolver (void)
} }
if (Globals::verbosity > 0) { if (Globals::verbosity > 0) {
if (nIters_ < BpOptions::maxIter) { if (nIters_ < BpOptions::maxIter) {
cout << "Belief propagation converged in " ; cout << "Belief propagation converged in " ;
cout << nIters_ << " iterations" << endl; cout << nIters_ << " iterations" << endl;
} else { } else {
cout << "The maximum number of iterations was hit, terminating..." ; cout << "The maximum number of iterations was hit, terminating..." ;
@ -459,7 +459,7 @@ void
BeliefProp::printLinkInformation (void) const BeliefProp::printLinkInformation (void) const
{ {
for (size_t i = 0; i < links_.size(); i++) { for (size_t i = 0; i < links_.size(); i++) {
BpLink* l = links_[i]; BpLink* l = links_[i];
cout << l->toString() << ":" << endl; cout << l->toString() << ":" << endl;
cout << " curr msg = " ; cout << " curr msg = " ;
cout << l->message() << endl; cout << l->message() << endl;

View File

@ -17,7 +17,7 @@ class BpLink
{ {
public: public:
BpLink (FacNode* fn, VarNode* vn) BpLink (FacNode* fn, VarNode* vn)
{ {
fac_ = fn; fac_ = fn;
var_ = vn; var_ = vn;
v1_.resize (vn->range(), LogAware::log (1.0 / vn->range())); v1_.resize (vn->range(), LogAware::log (1.0 / vn->range()));
@ -46,7 +46,7 @@ class BpLink
residual_ = LogAware::getMaxNorm (v1_,v2_); residual_ = LogAware::getMaxNorm (v1_,v2_);
} }
virtual void updateMessage (void) virtual void updateMessage (void)
{ {
swap (currMsg_, nextMsg_); swap (currMsg_, nextMsg_);
} }

View File

@ -190,7 +190,7 @@ ConstraintTree::ConstraintTree (
ConstraintTree::ConstraintTree (vector<vector<string>> names) ConstraintTree::ConstraintTree (vector<vector<string>> names)
{ {
assert (names.empty() == false); assert (names.empty() == false);
assert (names.front().empty() == false); assert (names.front().empty() == false);
unsigned nrLvs = names[0].size(); unsigned nrLvs = names[0].size();
for (size_t i = 0; i < nrLvs; i++) { for (size_t i = 0; i < nrLvs; i++) {
logVars_.push_back (LogVar (i)); logVars_.push_back (LogVar (i));
@ -201,7 +201,7 @@ ConstraintTree::ConstraintTree (vector<vector<string>> names)
Tuple t; Tuple t;
for (size_t j = 0; j < names[i].size(); j++) { for (size_t j = 0; j < names[i].size(); j++) {
assert (names[i].size() == nrLvs); assert (names[i].size() == nrLvs);
t.push_back (LiftedUtils::getSymbol (names[i][j])); t.push_back (LiftedUtils::getSymbol (names[i][j]));
} }
addTuple (t); addTuple (t);
} }
@ -266,7 +266,7 @@ ConstraintTree::moveToTop (const LogVars& lvs)
assert (pos != logVars_.size()); assert (pos != logVars_.size());
for (size_t j = pos; j-- > i; ) { for (size_t j = pos; j-- > i; ) {
swapLogVar (logVars_[j]); swapLogVar (logVars_[j]);
} }
} }
} }
@ -318,7 +318,7 @@ ConstraintTree::join (ConstraintTree* ct, bool oneTwoOne)
} else { } else {
moveToTop (intersect.elements()); moveToTop (intersect.elements());
ct->moveToTop (intersect.elements()); ct->moveToTop (intersect.elements());
Tuples tuples; Tuples tuples;
CTNodes appendNodes; CTNodes appendNodes;
getTuples (ct->root(), Tuples(), intersect.size(), getTuples (ct->root(), Tuples(), intersect.size(),
@ -455,7 +455,7 @@ ConstraintTree::singletons (void)
if (isSingleton (logVars_[i])) { if (isSingleton (logVars_[i])) {
singletons.insert (logVars_[i]); singletons.insert (logVars_[i]);
} }
} }
return singletons; return singletons;
} }
@ -585,13 +585,13 @@ ConstraintTree::isCountNormalized (const LogVarSet& Ys)
if (countTuples (*it) != count) { if (countTuples (*it) != count) {
return false; return false;
} }
} }
return true; return true;
} }
unsigned unsigned
ConstraintTree::getConditionalCount (const LogVarSet& Ys) ConstraintTree::getConditionalCount (const LogVarSet& Ys)
{ {
assert (isCountNormalized (Ys)); assert (isCountNormalized (Ys));
@ -792,7 +792,7 @@ ConstraintTree::jointCountNormalize (
} }
for (size_t i = 0; i < normCts1.size(); i++) { for (size_t i = 0; i < normCts1.size(); i++) {
unsigned j; unsigned j;
for (j = 0; counts1[i] + counts2[j] != N; j++) ; for (j = 0; counts1[i] + counts2[j] != N; j++) ;
// cout << "joint-count(" << counts1[i] ; // cout << "joint-count(" << counts1[i] ;
// cout << "," << counts2[j] << ")" << endl; // cout << "," << counts2[j] << ")" << endl;
@ -947,7 +947,7 @@ ConstraintTree::getNodesBelow (CTNode* fromHere) const
CTNodes CTNodes
ConstraintTree::getNodesAtLevel (unsigned level) const ConstraintTree::getNodesAtLevel (unsigned level) const
{ {
assert (level <= logVars_.size()); assert (level <= logVars_.size());
if (level == 0) { if (level == 0) {
@ -1057,7 +1057,7 @@ ConstraintTree::join (
} else { } else {
tupleFounded = join (*it, tuple, currIdx + 1, appendNode); tupleFounded = join (*it, tuple, currIdx + 1, appendNode);
} }
} }
return tupleFounded; return tupleFounded;
} }
@ -1065,7 +1065,7 @@ ConstraintTree::join (
void void
ConstraintTree::getTuples ( ConstraintTree::getTuples (
CTNode* n, CTNode* n,
Tuples currTuples, Tuples currTuples,
unsigned stopLevel, unsigned stopLevel,
Tuples& tuplesCollected, Tuples& tuplesCollected,
@ -1147,7 +1147,7 @@ ConstraintTree::split (
CTNode* n2, CTNode* n2,
CTChilds& commChilds, CTChilds& commChilds,
CTChilds& exclChilds, CTChilds& exclChilds,
unsigned stopLevel) unsigned stopLevel)
{ {
CTChilds& childs1 = n1->childs(); CTChilds& childs1 = n1->childs();
for (CTChilds::const_iterator chIt1 = childs1.begin(); for (CTChilds::const_iterator chIt1 = childs1.begin();

View File

@ -47,8 +47,7 @@ CountingBp::printSolverFlags (void) const
ss << ",max_iter=" << BpOptions::maxIter; ss << ",max_iter=" << BpOptions::maxIter;
ss << ",accuracy=" << BpOptions::accuracy; ss << ",accuracy=" << BpOptions::accuracy;
ss << ",log_domain=" << Util::toString (Globals::logDomain); ss << ",log_domain=" << Util::toString (Globals::logDomain);
ss << ",chkif=" << ss << ",chkif=" << Util::toString (CountingBp::checkForIdenticalFactors);
Util::toString (CountingBp::checkForIdenticalFactors);
ss << "]" ; ss << "]" ;
cout << ss.str() << endl; cout << ss.str() << endl;
} }
@ -139,7 +138,7 @@ CountingBp::setInitialColors (void)
VarColorMap::iterator it = colorMap.find (range); VarColorMap::iterator it = colorMap.find (range);
if (it == colorMap.end()) { if (it == colorMap.end()) {
it = colorMap.insert (make_pair ( it = colorMap.insert (make_pair (
range, Colors (range + 1, -1))).first; range, Colors (range + 1, -1))).first;
} }
unsigned idx = varNodes[i]->hasEvidence() unsigned idx = varNodes[i]->hasEvidence()
? varNodes[i]->getEvidence() ? varNodes[i]->getEvidence()

View File

@ -28,7 +28,7 @@ ElimGraph::ElimGraph (const vector<Factor*>& factors)
} }
if (neighbors (n1, n2) == false) { if (neighbors (n1, n2) == false) {
addEdge (n1, n2); addEdge (n1, n2);
} }
} }
} }
if (vids.size() == 1) { if (vids.size() == 1) {
@ -86,7 +86,7 @@ ElimGraph::print (void) const
cout << " " << neighs[j]->label(); cout << " " << neighs[j]->label();
} }
cout << endl; cout << endl;
} }
} }
@ -142,7 +142,7 @@ ElimGraph::getEliminationOrder (
Factors::const_iterator first = factors.begin(); Factors::const_iterator first = factors.begin();
Factors::const_iterator end = factors.end(); Factors::const_iterator end = factors.end();
for (; first != end; ++first) { for (; first != end; ++first) {
Util::addToVector (allVids, (*first)->arguments()); Util::addToVector (allVids, (*first)->arguments());
} }
TinySet<VarId> elimOrder (allVids); TinySet<VarId> elimOrder (allVids);
elimOrder -= TinySet<VarId> (excludedVids); elimOrder -= TinySet<VarId> (excludedVids);

View File

@ -143,7 +143,7 @@ class TFactor
assert (idx != args_.size()); assert (idx != args_.size());
assert (obsIdx < ranges_[idx]); assert (obsIdx < ranges_[idx]);
Params newps; Params newps;
newps.reserve (params_.size() / ranges_[idx]); newps.reserve (params_.size() / ranges_[idx]);
Indexer indexer (ranges_); Indexer indexer (ranges_);
for (unsigned i = 0; i < obsIdx; ++i) { for (unsigned i = 0; i < obsIdx; ++i) {
indexer.incrementDimension (idx); indexer.incrementDimension (idx);
@ -285,7 +285,7 @@ class Factor : public TFactor<VarId>
void sumOutLastVariable (void); void sumOutLastVariable (void);
void sumOutArgs (const vector<bool>& mask); void sumOutArgs (const vector<bool>& mask);
void clone (const Factor& f); void clone (const Factor& f);
}; };

View File

@ -171,7 +171,7 @@ FactorGraph::readFromLibDaiFormat (const char* fileName)
std::reverse (vids.begin(), vids.end()); std::reverse (vids.begin(), vids.end());
Factor f (vids, ranges, params); Factor f (vids, ranges, params);
std::reverse (vids.begin(), vids.end()); std::reverse (vids.begin(), vids.end());
f.reorderArguments (vids); f.reorderArguments (vids);
addFactor (f); addFactor (f);
} }
is.close(); is.close();
@ -188,7 +188,7 @@ FactorGraph::addFactor (const Factor& factor)
for (size_t i = 0; i < vids.size(); i++) { for (size_t i = 0; i < vids.size(); i++) {
VarMap::const_iterator it = varMap_.find (vids[i]); VarMap::const_iterator it = varMap_.find (vids[i]);
if (it != varMap_.end()) { if (it != varMap_.end()) {
addEdge (it->second, fn); addEdge (it->second, fn);
} else { } else {
VarNode* vn = new VarNode (vids[i], fn->factor().range (i)); VarNode* vn = new VarNode (vids[i], fn->factor().range (i));
addVarNode (vn); addVarNode (vn);
@ -293,7 +293,7 @@ FactorGraph::exportToGraphViz (const char* fileName) const
} }
for (size_t i = 0; i < facNodes_.size(); i++) { for (size_t i = 0; i < facNodes_.size(); i++) {
out << '"' << facNodes_[i]->getLabel() << '"' ; out << '"' << facNodes_[i]->getLabel() << '"' ;
out << " [label=\"" << facNodes_[i]->getLabel(); out << " [label=\"" << facNodes_[i]->getLabel();
out << "\"" << ", shape=box]" << endl; out << "\"" << ", shape=box]" << endl;
} }
for (size_t i = 0; i < facNodes_.size(); i++) { for (size_t i = 0; i < facNodes_.size(); i++) {

View File

@ -76,7 +76,7 @@ class FactorGraph
const FacNodes& facNodes (void) const { return facNodes_; } const FacNodes& facNodes (void) const { return facNodes_; }
void setFactorsAsBayesian (void) { bayesFactors_ = true; } void setFactorsAsBayesian (void) { bayesFactors_ = true; }
bool bayesianFactors (void) const { return bayesFactors_; } bool bayesianFactors (void) const { return bayesFactors_; }
size_t nrVarNodes (void) const { return varNodes_.size(); } size_t nrVarNodes (void) const { return varNodes_.size(); }

View File

@ -59,10 +59,10 @@ HistogramSet::reset (void)
vector<Histogram> vector<Histogram>
HistogramSet::getHistograms (unsigned N, unsigned R) HistogramSet::getHistograms (unsigned N, unsigned R)
{ {
HistogramSet hs (N, R); HistogramSet hs (N, R);
unsigned H = hs.nrHistograms(); unsigned H = hs.nrHistograms();
vector<Histogram> histograms; vector<Histogram> histograms;
histograms.reserve (H); histograms.reserve (H);
@ -135,7 +135,7 @@ HistogramSet::maxCount (size_t idx) const
} }
return size_ - sum; return size_ - sum;
} }
void void

View File

@ -77,7 +77,7 @@ readFactorGraph (FactorGraph& fg, const char* s)
} else if (extension == "fg") { } else if (extension == "fg") {
fg.readFromLibDaiFormat (fileName.c_str()); fg.readFromLibDaiFormat (fileName.c_str());
} else { } else {
cerr << "Error: the probabilistic graphical model must be " ; cerr << "Error: the probabilistic graphical model must be " ;
cerr << "defined either in a UAI or libDAI file." << endl; cerr << "defined either in a UAI or libDAI file." << endl;
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }

View File

@ -57,7 +57,7 @@ createLiftedNetwork (void)
} }
ParfactorList* pfList = new ParfactorList (parfactors); ParfactorList* pfList = new ParfactorList (parfactors);
if (Globals::verbosity > 2) { if (Globals::verbosity > 2) {
Util::printHeader ("SHATTERED PARFACTORS"); Util::printHeader ("SHATTERED PARFACTORS");
pfList->print(); pfList->print();
@ -91,7 +91,7 @@ createGroundNetwork (void)
// read the ranges // read the ranges
Ranges ranges = readUnsignedList (YAP_ArgOfTerm (2, factor)); Ranges ranges = readUnsignedList (YAP_ArgOfTerm (2, factor));
// read the parameters // read the parameters
Params params = readParameters (YAP_ArgOfTerm (3, factor)); Params params = readParameters (YAP_ArgOfTerm (3, factor));
// read dist id // read dist id
unsigned distId = (unsigned) YAP_IntOfTerm (YAP_ArgOfTerm (4, factor)); unsigned distId = (unsigned) YAP_IntOfTerm (YAP_ArgOfTerm (4, factor));
fg->addFactor (Factor (varIds, ranges, params, distId)); fg->addFactor (Factor (varIds, ranges, params, distId));
@ -126,7 +126,7 @@ runLiftedSolver (void)
LiftedNetwork* network = (LiftedNetwork*) YAP_IntOfTerm (YAP_ARG1); LiftedNetwork* network = (LiftedNetwork*) YAP_IntOfTerm (YAP_ARG1);
ParfactorList pfListCopy (*network->first); ParfactorList pfListCopy (*network->first);
LiftedOperations::absorveEvidence (pfListCopy, *network->second); LiftedOperations::absorveEvidence (pfListCopy, *network->second);
LiftedSolver* solver = 0; LiftedSolver* solver = 0;
switch (Globals::liftedSolver) { switch (Globals::liftedSolver) {
case LiftedSolverType::LVE: solver = new LiftedVe (pfListCopy); break; case LiftedSolverType::LVE: solver = new LiftedVe (pfListCopy); break;
@ -181,7 +181,7 @@ int
runGroundSolver (void) runGroundSolver (void)
{ {
FactorGraph* fg = (FactorGraph*) YAP_IntOfTerm (YAP_ARG1); FactorGraph* fg = (FactorGraph*) YAP_IntOfTerm (YAP_ARG1);
vector<VarIds> tasks; vector<VarIds> tasks;
YAP_Term taskList = YAP_ARG2; YAP_Term taskList = YAP_ARG2;
while (taskList != YAP_TermNil()) { while (taskList != YAP_TermNil()) {
@ -407,7 +407,7 @@ readParfactor (YAP_Term pfTerm)
} }
// read the parameters // read the parameters
const Params& params = readParameters (YAP_ArgOfTerm (4, pfTerm)); const Params& params = readParameters (YAP_ArgOfTerm (4, pfTerm));
// read the constraint // read the constraint
Tuples tuples; Tuples tuples;
@ -478,7 +478,7 @@ readLiftedEvidence (
obsFormulas.push_back (ObservedFormula (functor, evidence, args)); obsFormulas.push_back (ObservedFormula (functor, evidence, args));
} }
observedList = YAP_TailOfTerm (observedList); observedList = YAP_TailOfTerm (observedList);
} }
} }

View File

@ -167,7 +167,7 @@ class MapIndexer
} }
} }
} }
template <typename T> template <typename T>
MapIndexer ( MapIndexer (
const vector<T>& allArgs, const vector<T>& allArgs,

View File

@ -128,7 +128,7 @@ double
LeafNode::weight (void) const LeafNode::weight (void) const
{ {
assert (clause_->isUnit()); assert (clause_->isUnit());
if (clause_->posCountedLogVars().empty() == false if (clause_->posCountedLogVars().empty() == false
|| clause_->negCountedLogVars().empty() == false) { || clause_->negCountedLogVars().empty() == false) {
if (SetOrNode::isSet() == false) { if (SetOrNode::isSet() == false) {
// return a NaN if we have a SetOrNode // return a NaN if we have a SetOrNode

View File

@ -60,7 +60,7 @@ LiftedOperations::runWeakBayesBall (
const Grounds& query) const Grounds& query)
{ {
queue<PrvGroup> todo; // groups to process queue<PrvGroup> todo; // groups to process
set<PrvGroup> done; // processed or in queue set<PrvGroup> done; // processed or in queue
for (size_t i = 0; i < query.size(); i++) { for (size_t i = 0; i < query.size(); i++) {
ParfactorList::iterator it = pfList.begin(); ParfactorList::iterator it = pfList.begin();
while (it != pfList.end()) { while (it != pfList.end()) {
@ -225,7 +225,7 @@ LiftedOperations::absorve (
absorvedPfs.push_back (0); absorvedPfs.push_back (0);
} }
break; break;
} }
g->constr()->moveToTop (formulas[i].logVars()); g->constr()->moveToTop (formulas[i].logVars());
std::pair<ConstraintTree*, ConstraintTree*> res; std::pair<ConstraintTree*, ConstraintTree*> res;

View File

@ -10,7 +10,7 @@ class LiftedOperations
ParfactorList& pfList, const Grounds& query); ParfactorList& pfList, const Grounds& query);
static void runWeakBayesBall ( static void runWeakBayesBall (
ParfactorList& pfList, const Grounds&); ParfactorList& pfList, const Grounds&);
static void absorveEvidence ( static void absorveEvidence (
ParfactorList& pfList, ObservedFormulas& obsFormulas); ParfactorList& pfList, ObservedFormulas& obsFormulas);

View File

@ -61,7 +61,7 @@ ostream& operator<< (ostream &os, const Symbol& s)
ostream& operator<< (ostream &os, const LogVar& X) ostream& operator<< (ostream &os, const LogVar& X)
{ {
const string labels[] = { const string labels[] = {
"A", "B", "C", "D", "E", "F", "A", "B", "C", "D", "E", "F",
"G", "H", "I", "J", "K", "M" }; "G", "H", "I", "J", "K", "M" };
(X >= 12) ? os << "X_" << X.id_ : os << labels[X]; (X >= 12) ? os << "X_" << X.id_ : os << labels[X];
return os; return os;

View File

@ -51,7 +51,7 @@ class LogVar
} }
bool valid (void) const bool valid (void) const
{ {
return id_ != Util::maxUnsigned(); return id_ != Util::maxUnsigned();
} }
@ -145,7 +145,7 @@ class Substitution
return X; return X;
} }
bool containsReplacementFor (LogVar X) const bool containsReplacementFor (LogVar X) const
{ {
return Util::contains (subs_, X); return Util::contains (subs_, X);
} }

View File

@ -133,7 +133,7 @@ ProductOperator::toString (void)
stringstream ss; stringstream ss;
ss << "just multiplicate " ; ss << "just multiplicate " ;
ss << (*g1_)->getAllGroups(); ss << (*g1_)->getAllGroups();
ss << " x " ; ss << " x " ;
ss << (*g2_)->getAllGroups(); ss << (*g2_)->getAllGroups();
ss << " [cost=" << std::exp (getLogCost()) << "]" << endl; ss << " [cost=" << std::exp (getLogCost()) << "]" << endl;
return ss.str(); return ss.str();
@ -155,7 +155,7 @@ ProductOperator::validOp (Parfactor* g1, Parfactor* g2)
} }
size_t idx1 = g1->indexOfGroup (intersect[i]); size_t idx1 = g1->indexOfGroup (intersect[i]);
size_t idx2 = g2->indexOfGroup (intersect[i]); size_t idx2 = g2->indexOfGroup (intersect[i]);
if (g1->range (idx1) != g2->range (idx2)) { if (g1->range (idx1) != g2->range (idx2)) {
return false; return false;
} }
} }
@ -713,7 +713,7 @@ LiftedVe::getBestOperation (const Grounds& query)
if ((bestOp == 0) || (cost < bestCost)) { if ((bestOp == 0) || (cost < bestCost)) {
bestOp = validOps[i]; bestOp = validOps[i];
bestCost = cost; bestCost = cost;
} }
} }
if (bestCost > largestCost_) { if (bestCost > largestCost_) {
largestCost_ = bestCost; largestCost_ = bestCost;

View File

@ -9,7 +9,7 @@ class LiftedOperator
{ {
public: public:
virtual ~LiftedOperator (void) { } virtual ~LiftedOperator (void) { }
virtual double getLogCost (void) = 0; virtual double getLogCost (void) = 0;
virtual void apply (void) = 0; virtual void apply (void) = 0;
@ -55,7 +55,7 @@ class ProductOperator : public LiftedOperator
class SumOutOperator : public LiftedOperator class SumOutOperator : public LiftedOperator
{ {
public: public:
SumOutOperator (PrvGroup group, ParfactorList& pfList) SumOutOperator (PrvGroup group, ParfactorList& pfList)
: group_(group), pfList_(pfList) { } : group_(group), pfList_(pfList) { }
double getLogCost (void); double getLogCost (void);

View File

@ -195,7 +195,7 @@ Clause::isPositiveCountedLogVar (LogVar X) const
assert (constr_.logVarSet().contains (X)); assert (constr_.logVarSet().contains (X));
return posCountedLvs_.contains (X); return posCountedLvs_.contains (X);
} }
bool bool
@ -235,7 +235,7 @@ Clause::ipgCandidates (void) const
LogVarSet allLvs = constr_.logVarSet(); LogVarSet allLvs = constr_.logVarSet();
allLvs -= ipgLvs_; allLvs -= ipgLvs_;
allLvs -= posCountedLvs_; allLvs -= posCountedLvs_;
allLvs -= negCountedLvs_; allLvs -= negCountedLvs_;
for (size_t i = 0; i < allLvs.size(); i++) { for (size_t i = 0; i < allLvs.size(); i++) {
bool valid = true; bool valid = true;
for (size_t j = 0; j < literals_.size(); j++) { for (size_t j = 0; j < literals_.size(); j++) {
@ -262,7 +262,7 @@ Clause::logVarTypes (size_t litIdx) const
if (posCountedLvs_.contains (lvs[i])) { if (posCountedLvs_.contains (lvs[i])) {
types.push_back (LogVarType::POS_LV); types.push_back (LogVarType::POS_LV);
} else if (negCountedLvs_.contains (lvs[i])) { } else if (negCountedLvs_.contains (lvs[i])) {
types.push_back (LogVarType::NEG_LV); types.push_back (LogVarType::NEG_LV);
} else { } else {
types.push_back (LogVarType::FULL_LV); types.push_back (LogVarType::FULL_LV);
} }
@ -391,7 +391,7 @@ LiftedWCNF::LiftedWCNF (const ParfactorList& pfList)
{ {
addIndicatorClauses (pfList); addIndicatorClauses (pfList);
addParameterClauses (pfList); addParameterClauses (pfList);
/* /*
// INCLUSION-EXCLUSION TEST // INCLUSION-EXCLUSION TEST
clauses_.clear(); clauses_.clear();
@ -579,7 +579,7 @@ LiftedWCNF::addParameterClauses (const ParfactorList& pfList)
// ¬θxi|u1,...,un v λu2 -> tempClause // ¬θxi|u1,...,un v λu2 -> tempClause
double posWeight = (**it)[indexer]; double posWeight = (**it)[indexer];
addWeight (paramVarLid, posWeight, LogAware::one()); addWeight (paramVarLid, posWeight, LogAware::one());
Clause* clause1 = new Clause (*(*it)->constr()); Clause* clause1 = new Clause (*(*it)->constr());
for (unsigned i = 0; i < groups.size(); i++) { for (unsigned i = 0; i < groups.size(); i++) {
@ -593,7 +593,7 @@ LiftedWCNF::addParameterClauses (const ParfactorList& pfList)
tempClause->addLiteralComplemented (Literal ( tempClause->addLiteralComplemented (Literal (
paramVarLid, (*it)->constr()->logVars())); paramVarLid, (*it)->constr()->logVars()));
tempClause->addLiteral (Literal (lid, (*it)->argument(i).logVars())); tempClause->addLiteral (Literal (lid, (*it)->argument(i).logVars()));
clauses_.push_back (tempClause); clauses_.push_back (tempClause);
} }
clause1->addLiteral (Literal (paramVarLid, (*it)->constr()->logVars())); clause1->addLiteral (Literal (paramVarLid, (*it)->constr()->logVars()));
clauses_.push_back (clause1); clauses_.push_back (clause1);

View File

@ -8,7 +8,7 @@
Parfactor::Parfactor ( Parfactor::Parfactor (
const ProbFormulas& formulas, const ProbFormulas& formulas,
const Params& params, const Params& params,
const Tuples& tuples, const Tuples& tuples,
unsigned distId) unsigned distId)
{ {
@ -221,7 +221,7 @@ Parfactor::countConvert (LogVar X)
assert (constr_->isCountNormalized (X)); assert (constr_->isCountNormalized (X));
assert (constr_->getConditionalCount (X) > 1); assert (constr_->getConditionalCount (X) > 1);
assert (canCountConvert (X)); assert (canCountConvert (X));
unsigned N = constr_->getConditionalCount (X); unsigned N = constr_->getConditionalCount (X);
unsigned R = ranges_[fIdx]; unsigned R = ranges_[fIdx];
unsigned H = HistogramSet::nrHistograms (N, R); unsigned H = HistogramSet::nrHistograms (N, R);
@ -336,7 +336,7 @@ Parfactor::fullExpand (LogVar X)
sumIndexes.push_back (HistogramSet::findIndex (hist, originHists)); sumIndexes.push_back (HistogramSet::findIndex (hist, originHists));
++ indexer; ++ indexer;
} }
expandPotential (fIdx, std::pow (R, N), sumIndexes); expandPotential (fIdx, std::pow (R, N), sumIndexes);
ProbFormula f = args_[fIdx]; ProbFormula f = args_[fIdx];
@ -360,7 +360,7 @@ Parfactor::reorderAccordingGrounds (const Grounds& grounds)
ProbFormulas newFormulas; ProbFormulas newFormulas;
for (size_t i = 0; i < grounds.size(); i++) { for (size_t i = 0; i < grounds.size(); i++) {
for (size_t j = 0; j < args_.size(); j++) { for (size_t j = 0; j < args_.size(); j++) {
if (grounds[i].functor() == args_[j].functor() && if (grounds[i].functor() == args_[j].functor() &&
grounds[i].arity() == args_[j].arity()) { grounds[i].arity() == args_[j].arity()) {
constr_->moveToTop (args_[j].logVars()); constr_->moveToTop (args_[j].logVars());
if (constr_->containsTuple (grounds[i].args())) { if (constr_->containsTuple (grounds[i].args())) {
@ -424,7 +424,7 @@ Parfactor::indexOfGround (const Ground& ground) const
{ {
size_t idx = args_.size(); size_t idx = args_.size();
for (size_t i = 0; i < args_.size(); i++) { for (size_t i = 0; i < args_.size(); i++) {
if (args_[i].functor() == ground.functor() && if (args_[i].functor() == ground.functor() &&
args_[i].arity() == ground.arity()) { args_[i].arity() == ground.arity()) {
constr_->moveToTop (args_[i].logVars()); constr_->moveToTop (args_[i].logVars());
if (constr_->containsTuple (ground.args())) { if (constr_->containsTuple (ground.args())) {
@ -806,7 +806,7 @@ Parfactor::simplifyParfactor (size_t fIdx1, size_t fIdx2)
while (indexer.valid()) { while (indexer.valid()) {
if (indexer[fIdx1] == indexer[fIdx2]) { if (indexer[fIdx1] == indexer[fIdx2]) {
params_.push_back (backup[indexer]); params_.push_back (backup[indexer]);
} }
++ indexer; ++ indexer;
} }
for (size_t i = 0; i < args_[fIdx2].logVars().size(); i++) { for (size_t i = 0; i < args_[fIdx2].logVars().size(); i++) {
@ -829,7 +829,7 @@ Parfactor::getAlignLogVars (Parfactor* g1, Parfactor* g2)
TinySet<size_t> matchedI; TinySet<size_t> matchedI;
TinySet<size_t> matchedJ; TinySet<size_t> matchedJ;
ProbFormulas& formulas1 = g1->arguments(); ProbFormulas& formulas1 = g1->arguments();
ProbFormulas& formulas2 = g2->arguments(); ProbFormulas& formulas2 = g2->arguments();
for (size_t i = 0; i < formulas1.size(); i++) { for (size_t i = 0; i < formulas1.size(); i++) {
for (size_t j = 0; j < formulas2.size(); j++) { for (size_t j = 0; j < formulas2.size(); j++) {
if (formulas1[i].group() == formulas2[j].group() && if (formulas1[i].group() == formulas2[j].group() &&
@ -882,7 +882,7 @@ Parfactor::alignLogicalVars (Parfactor* g1, Parfactor* g2)
LogVar freeLogVar (0); LogVar freeLogVar (0);
Substitution theta1, theta2; Substitution theta1, theta2;
for (size_t i = 0; i < alignLvs1.size(); i++) { for (size_t i = 0; i < alignLvs1.size(); i++) {
bool b1 = theta1.containsReplacementFor (alignLvs1[i]); bool b1 = theta1.containsReplacementFor (alignLvs1[i]);
bool b2 = theta2.containsReplacementFor (alignLvs2[i]); bool b2 = theta2.containsReplacementFor (alignLvs2[i]);
if (b1 == false && b2 == false) { if (b1 == false && b2 == false) {
theta1.add (alignLvs1[i], freeLogVar); theta1.add (alignLvs1[i], freeLogVar);
@ -911,11 +911,11 @@ Parfactor::alignLogicalVars (Parfactor* g1, Parfactor* g2)
} }
// handle this type of situation: // handle this type of situation:
// g1 = p(X), q(X) ; X in {(p1),(p2)} // g1 = p(X), q(X) ; X in {(p1),(p2)}
// g2 = p(X), q(Y) ; (X,Y) in {(p1,p2),(p2,p1)} // g2 = p(X), q(Y) ; (X,Y) in {(p1,p2),(p2,p1)}
LogVars discardedLvs1 = theta1.getDiscardedLogVars(); LogVars discardedLvs1 = theta1.getDiscardedLogVars();
for (size_t i = 0; i < discardedLvs1.size(); i++) { for (size_t i = 0; i < discardedLvs1.size(); i++) {
if (g1->constr()->isSingleton (discardedLvs1[i]) && if (g1->constr()->isSingleton (discardedLvs1[i]) &&
g1->nrFormulas (discardedLvs1[i]) == 1) { g1->nrFormulas (discardedLvs1[i]) == 1) {
g1->constr()->remove (discardedLvs1[i]); g1->constr()->remove (discardedLvs1[i]);
} else { } else {

View File

@ -115,7 +115,7 @@ class Parfactor : public TFactor<ProbFormula>
static void alignLogicalVars (Parfactor*, Parfactor*); static void alignLogicalVars (Parfactor*, Parfactor*);
ConstraintTree* constr_; ConstraintTree* constr_;
}; };

View File

@ -9,7 +9,7 @@ ParfactorList::ParfactorList (const ParfactorList& pfList)
while (it != pfList.end()) { while (it != pfList.end()) {
addShattered (new Parfactor (**it)); addShattered (new Parfactor (**it));
++ it; ++ it;
} }
} }
@ -74,7 +74,7 @@ ParfactorList::insertShattered (
list<Parfactor*>::iterator list<Parfactor*>::iterator
ParfactorList::remove (list<Parfactor*>::iterator it) ParfactorList::remove (list<Parfactor*>::iterator it)
{ {
return pfList_.erase (it); return pfList_.erase (it);
} }
@ -418,7 +418,7 @@ ParfactorList::shatter (Parfactor* g1, Parfactor* g2)
if (formulas1[i].sameSkeletonAs (formulas2[j])) { if (formulas1[i].sameSkeletonAs (formulas2[j])) {
std::pair<Parfactors, Parfactors> res; std::pair<Parfactors, Parfactors> res;
res = shatter (i, g1, j, g2); res = shatter (i, g1, j, g2);
if (res.first.empty() == false || if (res.first.empty() == false ||
res.second.empty() == false) { res.second.empty() == false) {
return res; return res;
} }
@ -470,7 +470,7 @@ ParfactorList::shatter (
ConstraintTree* exclCt1 = split1.second; ConstraintTree* exclCt1 = split1.second;
if (commCt1->empty()) { if (commCt1->empty()) {
// disjoint // disjoint
delete commCt1; delete commCt1;
delete exclCt1; delete exclCt1;
return { }; return { };
@ -549,11 +549,11 @@ ParfactorList::shatter (
Parfactor* newPf = new Parfactor (g, cts[i]); Parfactor* newPf = new Parfactor (g, cts[i]);
if (cts[i]->nrLogVars() == g->constr()->nrLogVars() + 1) { if (cts[i]->nrLogVars() == g->constr()->nrLogVars() + 1) {
newPf->expand (f.countedLogVar(), X_new1, X_new2); newPf->expand (f.countedLogVar(), X_new1, X_new2);
assert (g->constr()->getConditionalCount (f.countedLogVar()) == assert (g->constr()->getConditionalCount (f.countedLogVar()) ==
cts[i]->getConditionalCount (X_new1) + cts[i]->getConditionalCount (X_new1) +
cts[i]->getConditionalCount (X_new2)); cts[i]->getConditionalCount (X_new2));
} else { } else {
assert (g->constr()->getConditionalCount (f.countedLogVar()) == assert (g->constr()->getConditionalCount (f.countedLogVar()) ==
cts[i]->getConditionalCount (f.countedLogVar())); cts[i]->getConditionalCount (f.countedLogVar()));
} }
newPf->setNewGroups(); newPf->setNewGroups();

View File

@ -61,7 +61,7 @@ ProbFormula::countedLogVar (void) const
} }
void void
ProbFormula::setCountedLogVar (LogVar lv) ProbFormula::setCountedLogVar (LogVar lv)
{ {
@ -92,9 +92,10 @@ ProbFormula::rename (LogVar oldName, LogVar newName)
} }
bool operator== (const ProbFormula& f1, const ProbFormula& f2) bool operator== (const ProbFormula& f1, const ProbFormula& f2)
{ {
return f1.group_ == f2.group_ && return f1.group_ == f2.group_ &&
f1.logVars_ == f2.logVars_; f1.logVars_ == f2.logVars_;
} }

View File

@ -12,11 +12,11 @@ typedef unsigned long PrvGroup;
class ProbFormula class ProbFormula
{ {
public: public:
ProbFormula (Symbol f, const LogVars& lvs, unsigned range) ProbFormula (Symbol f, const LogVars& lvs, unsigned range)
: functor_(f), logVars_(lvs), range_(range), : functor_(f), logVars_(lvs), range_(range),
countedLogVar_(), group_(numeric_limits<PrvGroup>::max()) { } countedLogVar_(), group_(numeric_limits<PrvGroup>::max()) { }
ProbFormula (Symbol f, unsigned r) ProbFormula (Symbol f, unsigned r)
: functor_(f), range_(r), group_(numeric_limits<PrvGroup>::max()) { } : functor_(f), range_(r), group_(numeric_limits<PrvGroup>::max()) { }
Symbol functor (void) const { return functor_; } Symbol functor (void) const { return functor_; }
@ -76,10 +76,10 @@ typedef vector<ProbFormula> ProbFormulas;
class ObservedFormula class ObservedFormula
{ {
public: public:
ObservedFormula (Symbol f, unsigned a, unsigned ev) ObservedFormula (Symbol f, unsigned a, unsigned ev)
: functor_(f), arity_(a), evidence_(ev), constr_(a) { } : functor_(f), arity_(a), evidence_(ev), constr_(a) { }
ObservedFormula (Symbol f, unsigned ev, const Tuple& tuple) ObservedFormula (Symbol f, unsigned ev, const Tuple& tuple)
: functor_(f), arity_(tuple.size()), evidence_(ev), constr_(arity_) : functor_(f), arity_(tuple.size()), evidence_(ev), constr_(arity_)
{ {
constr_.addTuple (tuple); constr_.addTuple (tuple);

View File

@ -21,7 +21,7 @@ class TinySet
TinySet (const Compare& cmp = Compare()) TinySet (const Compare& cmp = Compare())
: vec_(), cmp_(cmp) { } : vec_(), cmp_(cmp) { }
TinySet (const T& t, const Compare& cmp = Compare()) TinySet (const T& t, const Compare& cmp = Compare())
: vec_(1, t), cmp_(cmp) { } : vec_(1, t), cmp_(cmp) { }
TinySet (const vector<T>& elements, const Compare& cmp = Compare()) TinySet (const vector<T>& elements, const Compare& cmp = Compare())
@ -153,12 +153,12 @@ class TinySet
{ {
return vec_[i]; return vec_[i];
} }
T& operator[] (typename vector<T>::size_type i) T& operator[] (typename vector<T>::size_type i)
{ {
return vec_[i]; return vec_[i];
} }
T front (void) const T front (void) const
{ {
return vec_.front(); return vec_.front();
@ -219,7 +219,7 @@ class TinySet
return ! (s1.vec_ == s2.vec_); return ! (s1.vec_ == s2.vec_);
} }
friend std::ostream& operator << (std::ostream& out, const TinySet& s) friend std::ostream& operator<< (std::ostream& out, const TinySet& s)
{ {
out << "{" ; out << "{" ;
typename vector<T>::size_type i; typename vector<T>::size_type i;

View File

@ -140,7 +140,7 @@ nrDigits (int num)
{ {
unsigned count = 1; unsigned count = 1;
while (num >= 10) { while (num >= 10) {
num /= 10; num /= 10;
count ++; count ++;
} }
return count; return count;
@ -166,7 +166,7 @@ parametersToString (const Params& v, unsigned precision)
{ {
stringstream ss; stringstream ss;
ss.precision (precision); ss.precision (precision);
ss << "[" ; ss << "[" ;
for (size_t i = 0; i < v.size(); i++) { for (size_t i = 0; i < v.size(); i++) {
if (i != 0) ss << ", " ; if (i != 0) ss << ", " ;
ss << v[i]; ss << v[i];

View File

@ -373,8 +373,8 @@ void operator^=(std::vector<T>& v, int iexp)
template <typename T> template <typename T>
std::ostream& operator << (std::ostream& os, const vector<T>& v) std::ostream& operator<< (std::ostream& os, const vector<T>& v)
{ {
os << "[" ; os << "[" ;
os << Util::elementsToString (v, ", "); os << Util::elementsToString (v, ", ");

View File

@ -49,7 +49,7 @@ Var::isValidState (const string& stateName)
void void
Var::setEvidence (int ev) Var::setEvidence (int ev)
{ {
assert (ev < (int) range_); assert (ev < (int) range_);
evidence_ = ev; evidence_ = ev;
@ -58,8 +58,8 @@ Var::setEvidence (int ev)
void void
Var::setEvidence (const string& ev) Var::setEvidence (const string& ev)
{ {
States states = Var::getVarInfo (varId_).states; States states = Var::getVarInfo (varId_).states;
for (size_t i = 0; i < states.size(); i++) { for (size_t i = 0; i < states.size(); i++) {
if (states[i] == ev) { if (states[i] == ev) {

View File

@ -70,7 +70,7 @@ VarElim::createFactorList (void)
factorList_.push_back (new Factor (facNodes[i]->factor())); factorList_.push_back (new Factor (facNodes[i]->factor()));
const VarNodes& neighs = facNodes[i]->neighbors(); const VarNodes& neighs = facNodes[i]->neighbors();
for (size_t j = 0; j < neighs.size(); j++) { for (size_t j = 0; j < neighs.size(); j++) {
unordered_map<VarId, vector<size_t>>::iterator it unordered_map<VarId, vector<size_t>>::iterator it
= varFactors_.find (neighs[j]->varId()); = varFactors_.find (neighs[j]->varId());
if (it == varFactors_.end()) { if (it == varFactors_.end()) {
it = varFactors_.insert (make_pair ( it = varFactors_.insert (make_pair (

View File

@ -132,7 +132,7 @@ WeightedBp::maxResidualSchedule (void)
} }
} }
// in counting bp, the message that a variable X sends to // in counting bp, the message that a variable X sends to
// to a factor F depends on the message that F sent to the X // to a factor F depends on the message that F sent to the X
const BpLinks& links = ninf(link->facNode())->getLinks(); const BpLinks& links = ninf(link->facNode())->getLinks();
for (size_t i = 0; i < links.size(); i++) { for (size_t i = 0; i < links.size(); i++) {
if (links[i]->varNode() != link->varNode()) { if (links[i]->varNode() != link->varNode()) {
@ -258,7 +258,7 @@ WeightedBp::getVarToFactorMsg (const BpLink* _link) const
if ( ! (l->facNode() == dst && l->index() == link->index())) { if ( ! (l->facNode() == dst && l->index() == link->index())) {
msg *= l->powMessage(); msg *= l->powMessage();
if (Constants::SHOW_BP_CALCS) { if (Constants::SHOW_BP_CALCS) {
cout << " x " << l->nextMessage() << "^" << link->weight(); cout << " x " << l->nextMessage() << "^" << link->weight();
} }
} }
} }

View File

@ -6,7 +6,7 @@
class WeightedLink : public BpLink class WeightedLink : public BpLink
{ {
public: public:
WeightedLink (FacNode* fn, VarNode* vn, size_t idx, unsigned weight) WeightedLink (FacNode* fn, VarNode* vn, size_t idx, unsigned weight)
: BpLink (fn, vn), index_(idx), weight_(weight), : BpLink (fn, vn), index_(idx), weight_(weight),
pwdMsg_(vn->range(), LogAware::one()) { } pwdMsg_(vn->range(), LogAware::one()) { }
@ -16,7 +16,7 @@ class WeightedLink : public BpLink
const Params& powMessage (void) const { return pwdMsg_; } const Params& powMessage (void) const { return pwdMsg_; }
void updateMessage (void) void updateMessage (void)
{ {
pwdMsg_ = *nextMsg_; pwdMsg_ = *nextMsg_;
swap (currMsg_, nextMsg_); swap (currMsg_, nextMsg_);

View File

@ -50,7 +50,7 @@
% %
% Tell Aleph not to use default solver during saturation % Tell Aleph not to use default solver during saturation
% %
% all work will be done by EM % all work will be done by EM
%:- set_clpbn_flag(solver,none). %:- set_clpbn_flag(solver,none).
% %
@ -123,7 +123,7 @@ add_new_clause(_,(H :- B),_,_) :-
asserta(user:(H :- IB)) asserta(user:(H :- IB))
), ),
user:setting(verbosity,V), user:setting(verbosity,V),
( V >= 1 -> ( V >= 1 ->
user:p_message('CLP(BN) Theory'), user:p_message('CLP(BN) Theory'),
functor(H,N,Ar), listing(user:N/Ar) functor(H,N,Ar), listing(user:N/Ar)
; ;
@ -138,7 +138,7 @@ update_tabled_theory(H) :-
clpbn_tabled_assertz((user:(H:-NB))), clpbn_tabled_assertz((user:(H:-NB))),
fail. fail.
update_tabled_theory(_). update_tabled_theory(_).
update_theory(H) :- update_theory(H) :-
clause(user:H,B,Ref), clause(user:H,B,Ref),
add_correct_cpt(B,NB), add_correct_cpt(B,NB),
@ -161,7 +161,7 @@ correct_tab(p(Vs,_,Ps),K,p(Vs,TDist,Ps)) :-
get_dist_key(Id, K), get_dist_key(Id, K),
get_dist_params(Id, TDist). get_dist_params(Id, TDist).
% user-defined cost function, Aleph knows about this (and only about this). % user-defined cost function, Aleph knows about this (and only about this).
user:cost((H :- B),Inf,Score) :- user:cost((H :- B),Inf,Score) :-
domain(H, K, V, D), domain(H, K, V, D),
check_info(Inf), check_info(Inf),
@ -261,7 +261,7 @@ rewrite_body((A,B), (user:NA,NB), [V|Vs], [D|Ds], Tail) :-
rewrite_body(B, NB, Vs, Ds, Tail). rewrite_body(B, NB, Vs, Ds, Tail).
rewrite_body((A,B), (user:A,NB), Vs, Ds, Tail) :- !, rewrite_body((A,B), (user:A,NB), Vs, Ds, Tail) :- !,
rewrite_body(B,NB, Vs, Ds, Tail). rewrite_body(B,NB, Vs, Ds, Tail).
rewrite_body(A,(user:NA,Tail), [V], [D], Tail) :- rewrite_body(A,(user:NA,Tail), [V], [D], Tail) :-
rewrite_goal(A, V, D, NA), !. rewrite_goal(A, V, D, NA), !.
rewrite_body(A, (user:A,Tail), [], [], Tail). rewrite_body(A, (user:A,Tail), [], [], Tail).

View File

@ -33,7 +33,7 @@
[generate_network/5, [generate_network/5,
f/3 f/3
]). ]).
:- use_module(library('clpbn/utils'), :- use_module(library('clpbn/utils'),
[check_for_hidden_vars/3, [check_for_hidden_vars/3,
sort_vars_by_key/3 sort_vars_by_key/3
@ -46,7 +46,7 @@
compute_likelihood/3, compute_likelihood/3,
soften_sample/2 soften_sample/2
]). ]).
:- use_module(library(bhash), :- use_module(library(bhash),
[b_hash_new/1, [b_hash_new/1,
b_hash_lookup/3, b_hash_lookup/3,
@ -198,7 +198,7 @@ ltables([Id-T|Tables], [Key-LTable|FTables]) :-
generate_dists(Factors, EList, AllDists, AllInfo, MargVars) :- generate_dists(Factors, EList, AllDists, AllInfo, MargVars) :-
b_hash_new(Ev0), b_hash_new(Ev0),
foldl(elist_to_hash, EList, Ev0, Ev), foldl(elist_to_hash, EList, Ev0, Ev),
maplist(process_factor(Ev), Factors, Dists0), maplist(process_factor(Ev), Factors, Dists0),
sort(Dists0, Dists1), sort(Dists0, Dists1),
@ -220,7 +220,7 @@ fetch_evidence(_Ev, K, Ns, NonEvs, [K|NonEvs]) :-
domain_to_number(_, I0, I0, I) :- domain_to_number(_, I0, I0, I) :-
I is I0+1. I is I0+1.
% collect the different dists we are going to learn next. % collect the different dists we are going to learn next.
different_dists(AllVars, AllDists, AllInfo, MargVars) :- different_dists(AllVars, AllDists, AllInfo, MargVars) :-
@ -232,9 +232,9 @@ different_dists(AllVars, AllDists, AllInfo, MargVars) :-
% %
% V -> to Id defining V. We get: % V -> to Id defining V. We get:
% the random variables that are parents % the random variables that are parents
% the cases that can happen, eg if we have A <- B, C % the cases that can happen, eg if we have A <- B, C
% A and B are boolean w/o evidence, and C is f, the cases could be % A and B are boolean w/o evidence, and C is f, the cases could be
% [0,0,1], [0,1,1], [1,0,0], [1,1,0], % [0,0,1], [0,1,1], [1,0,0], [1,1,0],
% Hiddens will be C % Hiddens will be C
% %
all_dists([], _, []). all_dists([], _, []).

View File

@ -57,7 +57,7 @@ mk_sample(AllVars, SortedSample) :-
msort(Sample, SortedSample). msort(Sample, SortedSample).
% %
% assumes we have full data, meaning evidence for every variable % assumes we have full data, meaning evidence for every variable
% %
add2sample([], []). add2sample([], []).
add2sample([V|Vs],[val(Id,[Ev|EParents])|Vals]) :- add2sample([V|Vs],[val(Id,[Ev|EParents])|Vals]) :-

View File

@ -50,7 +50,7 @@
append/3, append/3,
member/2 member/2
]). ]).
:- dynamic factor/6, skolem_in/2, skolem/2, preprocess/3, evidence/2, id/1. :- dynamic factor/6, skolem_in/2, skolem/2, preprocess/3, evidence/2, id/1.
user:term_expansion( bayes((Formula ; Phi ; Constraints)), pfl:factor(bayes,Id,FList,FV,Phi,Constraints)) :- user:term_expansion( bayes((Formula ; Phi ; Constraints)), pfl:factor(bayes,Id,FList,FV,Phi,Constraints)) :-
@ -178,7 +178,7 @@ add_evidence(Sk,Var) :-
clpbn:put_atts(_V,[key(Sk),evidence(E)]). clpbn:put_atts(_V,[key(Sk),evidence(E)]).
%% get_pfl_cpt(Id, Keys, Ev, NewKeys, Out) :- %% get_pfl_cpt(Id, Keys, Ev, NewKeys, Out) :-
%% factor(_Type,Id,[Key|_],_FV,avg,_Constraints), !, %% factor(_Type,Id,[Key|_],_FV,avg,_Constraints), !,
%% Keys = [Key|Parents], %% Keys = [Key|Parents],
%% writeln(Key:Parents), %% writeln(Key:Parents),