diff --git a/packages/CLPBN/clpbn.yap b/packages/CLPBN/clpbn.yap index 54a87a96a..605e9dd74 100644 --- a/packages/CLPBN/clpbn.yap +++ b/packages/CLPBN/clpbn.yap @@ -221,14 +221,14 @@ set_em_solver(Solver) :- % % we use a mutable variable to avoid unnecessary trailing. % -store_var(El) :- - nb_current(clpbn_qvars, Mutable), +store_var(El) :- + nb_current(clpbn_qvars, Mutable), nonvar(Mutable), !, get_mutable(Tail, Mutable), update_mutable(El.Tail, Mutable). -store_var(El) :- +store_var(El) :- init_clpbn_vars(El). - + init_clpbn_vars(El) :- create_mutable(El, Mutable), b_setval(clpbn_qvars, Mutable). @@ -278,7 +278,7 @@ project_attributes(GVars0, _AVars0) :- b_setval(clpbn_query_variables, f(GVars0,Evidence)), simplify_query(GVars0, GVars), ( - GKeys = [] + GKeys = [] -> GVars0 = [V|_], 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) :- % fall back to traditional solver 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(evidence_to_v, Evidence, _EVars, Hash1, Hash), %writeln(Keys:AllVars), @@ -432,7 +432,7 @@ write_out(Solver, _, _, _) :- % gvar_in_hash(V, Hash0, Hash) :- 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) :- b_hash_lookup(K, V, Hash0), !. @@ -496,12 +496,12 @@ process_vars([V|Vs], [K|Ks]) :- process_var(V, K), 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. 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) :- 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 % Vs is the full graph -% Ps are the probabilities on LVs. +% Ps are the probabilities on LVs. % clpbn_run_solver(LVs, LPs, State) :- solver(Solver), @@ -708,7 +708,7 @@ pfl_run_solver(LVs, LPs, State) :- pfl_run_solver(LVs, LPs, State, ve) :- !, run_ve_ground_solver(LVs, LPs, State). - + pfl_run_solver(LVs, LPs, State, hve) :- !, run_horus_ground_solver(LVs, LPs, State). @@ -732,7 +732,7 @@ add_keys(Key1+V1,_Key2,Key1+V1). probability(Goal, Prob) :- findall(Prob, do_probability(Goal, [], Prob), [Prob]). - + conditional_probability(Goal, ListOfGoals, Prob) :- \+ ground(Goal), throw(error(ground(Goal),conditional_probability(Goal, ListOfGoals, Prob))). @@ -766,7 +766,7 @@ evidence_to_var(Goal, C, VItem, V) :- Goal =.. [L|Args], variabilise_last(Args, C, NArgs, V), VItem =.. [L|NArgs]. - + variabilise_last([Arg], Arg, [V], V). variabilise_last([Arg1,Arg2|Args], Arg, Arg1.NArgs, V) :- variabilise_last(Arg2.Args, Arg, NArgs, V). diff --git a/packages/CLPBN/clpbn/aggregates.yap b/packages/CLPBN/clpbn/aggregates.yap index 71e08795b..90c1ef51e 100644 --- a/packages/CLPBN/clpbn/aggregates.yap +++ b/packages/CLPBN/clpbn/aggregates.yap @@ -96,11 +96,11 @@ find_ev(_Evs, Key, RemKeys, [Key|RemKeys], Ev, Ev). % +final CPT % - New Parents % + - list of new keys -% +% avg_table(Vars, OVars, Domain, Key, TotEvidence, Softness, Vars, Vs, Vs, Id) :- length(Domain, SDomain), int_power(Vars, SDomain, 1, TabSize), - TabSize =< 256, + TabSize =< 256, /* case gmp is not there !! */ TabSize > 0, !, 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) :- length(Domain, SDomain), int_power(Vars, SDomain, 1, TabSize), - TabSize =< 256, + TabSize =< 256, /* case gmp is not there !! */ TabSize > 0, !, average_cpt(Vars, OVars, Domain, TotEvidence, Softness, CPT). @@ -304,7 +304,7 @@ get_ds_lengths([],[]). get_ds_lengths([V|Vs],[Sz|Lengs]) :- get_vdist_size(V, Sz), get_ds_lengths(Vs,Lengs). - + fill_in_average(Lengs, N, Base, MCPT) :- generate(Lengs, Case), average(Case, N, Base, Val), diff --git a/packages/CLPBN/clpbn/bdd.yap b/packages/CLPBN/clpbn/bdd.yap index a7bc3abd7..b0335eb08 100644 --- a/packages/CLPBN/clpbn/bdd.yap +++ b/packages/CLPBN/clpbn/bdd.yap @@ -9,12 +9,12 @@ V = v(Va, Vb, Vc) The generic formula is -V <- X, Y +V <- X, Y Va <- P*X1*Y1 + Q*X2*Y2 + ... - + **************************************************/ :- module(clpbn_bdd, @@ -80,8 +80,8 @@ bdds(bdd). % % QVars: all query variables? -% -% +% +% 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). 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). add_edge(K, K0, Graph0, Graph) :- @@ -176,7 +176,7 @@ sort_vars(AllVars0, AllVars, Leaves) :- build_graph([], Graph, Graph). build_graph([V|AllVars0], Graph0, Graph) :- 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), build_graph(AllVars0, GraphI, Graph). build_graph(_V.AllVars0, Graph0, Graph) :- @@ -184,7 +184,7 @@ build_graph(_V.AllVars0, Graph0, Graph) :- add_parents([], _V, Graph, Graph). 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). 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), avg_exp(Vals, PVars, 0, P, MaxI, Size, Im, IM, HI, HF, Exp), simplify_exp(Exp, Simp). - + avg_exp([], _, _, _P, _Max, _Size, _Im, _IM, H, H, 0). avg_exp([Val|Vals], PVars, I0, P0, Max, Size, Im, IM, HI, HF, O) :- (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) :- vs_to_sums(Vs, Sums0), bin_sums(Sums0, Sums, F, []). - + vs_to_sums([], []). vs_to_sums([V|Vs], [Sum|Sums0]) :- Sum =.. [sum|V], @@ -536,7 +536,7 @@ sum_all([_V|Vs], Pos, I, Max0, Sums, List) :- gen_arg(J, Sums, Max, S0) :- gen_arg(0, Max, J, Sums, S0). - + gen_arg(Max, Max, J, Sums, S0) :- !, I is Max+1, arg(I, Sums, A), @@ -647,19 +647,19 @@ copy(N, [], [], Ms, Parms0, Parms, ParmVars) :-!, copy(N, Ms, NewMs, NewMs, Parms0, Parms, ParmVars). copy(N, D.Ds, ND.NDs, New, El.Parms0, NEl.Parms, V.ParmVars) :- N1 is N-1, - (El == 0.0 -> + (El == 0.0 -> NEl = 0, V = NEl, ND = D - ;El == 1.0 -> + ;El == 1.0 -> NEl = 1, V = NEl, ND = 0.0 - ;El == 0 -> + ;El == 0 -> NEl = 0, V = NEl, ND = D - ;El =:= 1 -> + ;El =:= 1 -> NEl = 1, V = NEl, ND = 0.0, @@ -818,7 +818,7 @@ get_key_evidence(V, Evs, _, Tree, Ev, F0, F, Leaves, Finals) :- %% deterministic(V, DistId), %% !, %% one_list(Ev), -%% eval_outs(F0). +%% eval_outs(F0). %% no evidence !!! get_key_evidence(V, _, _, Tree, _Values, F0, F1, Leaves, Finals) :- 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' ), !, one_list(Ev), - eval_outs(F0). + eval_outs(F0). %% no evidence !!! get_evidence(V, Tree, _Values, F0, F1, Leaves, Finals) :- insert_output(Leaves, V, Finals, Tree, Outs, SendOut), get_outs(F0, F1, SendOut, Outs). zero_pos(_, _Pos, []). -zero_pos(Pos, Pos, [1|Values]) :- !, +zero_pos(Pos, Pos, [1|Values]) :- !, I is Pos+1, zero_pos(I, Pos, Values). zero_pos(I0, Pos, [0|Values]) :- @@ -855,7 +855,7 @@ one_list(1.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._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) :- %(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, IVs = Indics, term_variables(CNF, Extra), diff --git a/packages/CLPBN/clpbn/bnt.yap b/packages/CLPBN/clpbn/bnt.yap index 9fd0d8d65..c09786b20 100644 --- a/packages/CLPBN/clpbn/bnt.yap +++ b/packages/CLPBN/clpbn/bnt.yap @@ -101,7 +101,7 @@ do_bnt(QueryVars, AllVars, AllDiffs) :- add_evidence(SortedVertices, Size, NumberedVertices), marginalize(QueryVars, SortedVertices, NumberedVertices, Ps), clpbn_bind_vals(QueryVars, Ps, AllDiffs). - + 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([_-V|NIds], NParents, Vs) :- extract_vars(NIds, [V|NParents], Vs). - + mkcpt(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]) :- clpbn:get_atts(V, [dist(Id,Parents)]), create_class_vector(Graph, Is,Classes,Sets). - + representatives([],[]). representatives([Class-Rep|Reps1],[Class-Rep|Reps]) :- 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). - + evidence_val(Ev,Val,[Ev|_],Val) :- !. evidence_val(Ev,I0,[_|Domain],Val) :- I1 is I0+1, diff --git a/packages/CLPBN/clpbn/discrete_utils.yap b/packages/CLPBN/clpbn/discrete_utils.yap index ebe8ab376..8ba385f4e 100644 --- a/packages/CLPBN/clpbn/discrete_utils.yap +++ b/packages/CLPBN/clpbn/discrete_utils.yap @@ -24,7 +24,7 @@ propagate_evidence(V, Evs) :- clpbn:get_atts(V, [evidence(Ev),dist(Id,_)]), !, get_dist_domain(Id, Out), generate_szs_with_evidence(Out,Ev,0,Evs,Found), - (var(Found) -> + (var(Found) -> clpbn:get_atts(V, [key(K)]), throw(clpbn(evidence_does_not_match,K,Ev,[Out])) ; diff --git a/packages/CLPBN/clpbn/display.yap b/packages/CLPBN/clpbn/display.yap index 5d6afb6ea..7ecba7880 100644 --- a/packages/CLPBN/clpbn/display.yap +++ b/packages/CLPBN/clpbn/display.yap @@ -78,7 +78,7 @@ clpbn_bind_vals([Vs|MoreVs],[Ps|MorePs],AllDiffs) :- clpbn_bind_vals2([],_,_) :- !. % 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), !, clpbn:get_atts(V, [key(K)]), pfl:skolem(K,Vals), diff --git a/packages/CLPBN/clpbn/dists.yap b/packages/CLPBN/clpbn/dists.yap index be4b63b20..ce796e524 100644 --- a/packages/CLPBN/clpbn/dists.yap +++ b/packages/CLPBN/clpbn/dists.yap @@ -90,7 +90,7 @@ where Id is the id, dna for [a,c,g,t] rna for [a,c,g,u] reals - + ********************************************/ diff --git a/packages/CLPBN/clpbn/evidence.yap b/packages/CLPBN/clpbn/evidence.yap index 8fd4ee9bc..4f6982a13 100644 --- a/packages/CLPBN/clpbn/evidence.yap +++ b/packages/CLPBN/clpbn/evidence.yap @@ -31,7 +31,7 @@ :- 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 % keep a precompiled version around. % @@ -51,9 +51,9 @@ compute_evidence(_,PreviousSolver) :- set_clpbn_flag(solver, PreviousSolver). get_clpbn_vars(G, Vars) :- -% attributes:all_attvars(Vars0), +% attributes:all_attvars(Vars0), once(G), - attributes:all_attvars(Vars). + attributes:all_attvars(Vars). evidence_error(Ball,PreviousSolver) :- set_clpbn_flag(solver,PreviousSolver), diff --git a/packages/CLPBN/clpbn/gibbs.yap b/packages/CLPBN/clpbn/gibbs.yap index 3349f4d29..ce45313f7 100644 --- a/packages/CLPBN/clpbn/gibbs.yap +++ b/packages/CLPBN/clpbn/gibbs.yap @@ -137,7 +137,7 @@ graph_representation([V|Vs], Graph, I0, Keys, [I-IParents|TGraph]) :- graph_representation(Vs, Graph, I, Keys, TGraph). write_pars([]). -write_pars([V|Parents]) :- +write_pars([V|Parents]) :- clpbn:get_atts(V, [key(K),dist(I,_)]),write(K:I),nl, write_pars(Parents). @@ -149,7 +149,7 @@ get_sizes([V|Parents], [Sz|Szs]) :- parent_indices([], _, []). parent_indices([V|Parents], Keys, [I|IParents]) :- - rb_lookup(V, I, Keys), + rb_lookup(V, I, Keys), parent_indices(Parents, Keys, IParents). @@ -174,7 +174,7 @@ propagate2parents([V|NewParents], Table, Variables, Graph, Keys) :- propagate2parents(NewParents,Table, Variables, 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)), arg(Index, Graph, var(V,Index,_,Vals,Sz,VarSlot,_,_,_)), member(tabular(Table,Index,IParents), VarSlot), !. @@ -239,7 +239,7 @@ mult_list([Sz|Sizes],Mult0,Mult) :- MultI is Sz*Mult0, 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) :- TotSize < 1024*64, TotSize > 0, !, 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) :- arg(V,Graph,var(_,I,_,_,Sz,_,_,_,_)), generate_est_mults(Vs, Is, Graph, Mults, M0), - M is M0*Sz. - + M is M0*Sz. + gen_e0(0,[]) :- !. gen_e0(Sz,[0|E0L]) :- Sz1 is Sz-1, @@ -531,7 +531,7 @@ add_up_mes(Counts,[me(_,_,Cs)|Chains], Add) :- sum_lists(Counts, Cs, NCounts), add_up_mes(NCounts, Chains, Add). -sum_lists([],[],[]). +sum_lists([],[],[]). sum_lists([Count|Counts], [C|Cs], [NC|NCounts]) :- NC is Count+C, sum_lists(Counts, Cs, NCounts). diff --git a/packages/CLPBN/clpbn/graphviz.yap b/packages/CLPBN/clpbn/graphviz.yap index 4a75e4022..2d0a10cda 100644 --- a/packages/CLPBN/clpbn/graphviz.yap +++ b/packages/CLPBN/clpbn/graphviz.yap @@ -50,7 +50,7 @@ output_parents1(Stream,[V|L]) :- put_code(Stream, 0' ), %' output_parents1(Stream,L). -output_v(V,Stream) :- +output_v(V,Stream) :- clpbn:get_atts(V,[key(Key)]), output_key(Stream,Key). diff --git a/packages/CLPBN/clpbn/horus.yap b/packages/CLPBN/clpbn/horus.yap index 5c4c7b688..344f11d86 100644 --- a/packages/CLPBN/clpbn/horus.yap +++ b/packages/CLPBN/clpbn/horus.yap @@ -1,7 +1,7 @@ /******************************************************* Horus Interface - + ********************************************************/ :- module(clpbn_horus, diff --git a/packages/CLPBN/clpbn/horus_ground.yap b/packages/CLPBN/clpbn/horus_ground.yap index f696bccc0..b4b3f8d25 100644 --- a/packages/CLPBN/clpbn/horus_ground.yap +++ b/packages/CLPBN/clpbn/horus_ground.yap @@ -4,7 +4,7 @@ - Variable Elimination - Belief Propagation - Counting Belief Propagation - + ********************************************************/ :- module(clpbn_horus_ground, diff --git a/packages/CLPBN/clpbn/jt.yap b/packages/CLPBN/clpbn/jt.yap index 7eb3c191f..d46f13430 100644 --- a/packages/CLPBN/clpbn/jt.yap +++ b/packages/CLPBN/clpbn/jt.yap @@ -98,7 +98,7 @@ jt(LLVs,Vs0,AllDiffs) :- init_jt_solver(LLVs, Vs0, _, State) :- - check_for_agg_vars(Vs0, Vs1), + check_for_agg_vars(Vs0, Vs1), init_influences(Vs1, G, RG), maplist(init_jt_solver_for_question(G, RG), LLVs, State). @@ -163,7 +163,7 @@ initial_graph(_,Parents, CPTs) :- % from the very beginning. dgraph_transpose(V1, V2), dgraph_to_ugraph(V2, Parents). - + problem_graph([], []). problem_graph([V|BNet], GraphF) :- diff --git a/packages/CLPBN/clpbn/matrix_cpt_utils.yap b/packages/CLPBN/clpbn/matrix_cpt_utils.yap index c12d5b6e6..a3d7d228f 100644 --- a/packages/CLPBN/clpbn/matrix_cpt_utils.yap +++ b/packages/CLPBN/clpbn/matrix_cpt_utils.yap @@ -87,7 +87,7 @@ evidence(V, Pos) :- clpbn:get_atts(V, [evidence(Pos)]). vnth([V1|Deps], N, V, N, Deps) :- - V == V1, !. + V == V1, !. vnth([V1|Deps], N0, V, N, [V1|NDeps]) :- N1 is N0+1, 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([V|DimsNew], Dims0, [Sz|Map]) :- 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). - + unit_CPT(V,CPT) :- clpbn:get_atts(V, [dist(Id,_)]), clpbn_dist:get_dist_domain_size(Id, Sz), @@ -287,7 +287,7 @@ uniform_CPT(Dims, M) :- normalise_possibly_deterministic_CPT(M1, M). normalise_CPT_on_lines(MAT0, MAT2, L1) :- - matrix_agg_cols(MAT0, +, MAT1), + matrix_agg_cols(MAT0, +, MAT1), matrix_sum(MAT1, SUM), matrix_op_to_all(MAT1, /, SUM, MAT2), matrix:matrix_to_list(MAT2,L1). diff --git a/packages/CLPBN/clpbn/numbers.yap b/packages/CLPBN/clpbn/numbers.yap index 88c65c915..15aad1e1f 100644 --- a/packages/CLPBN/clpbn/numbers.yap +++ b/packages/CLPBN/clpbn/numbers.yap @@ -1,7 +1,7 @@ :- module(clpbn_numbers, - [keys_to_numbers/7, - keys_to_numbers/9, + [keys_to_numbers/7, + keys_to_numbers/9, lists_of_keys_to_ids/6 ]). diff --git a/packages/CLPBN/clpbn/pgrammar.yap b/packages/CLPBN/clpbn/pgrammar.yap index f4739cb84..4c6829595 100644 --- a/packages/CLPBN/clpbn/pgrammar.yap +++ b/packages/CLPBN/clpbn/pgrammar.yap @@ -176,7 +176,7 @@ get_internal(S, InternalS, Arg) :- extract_probability(p(Id,Goals), P) :- id(Id,_,P0,_), - LogP0 is log(P0), + LogP0 is log(P0), extract_logprobability(Goals, LogP0, LogP), P is exp(LogP). diff --git a/packages/CLPBN/clpbn/table.yap b/packages/CLPBN/clpbn/table.yap index 748a2757d..155db3941 100644 --- a/packages/CLPBN/clpbn/table.yap +++ b/packages/CLPBN/clpbn/table.yap @@ -37,11 +37,11 @@ clpbn_tabled_clause_ref(:.?,?), clpbn_tabled_retract(:), clpbn_tabled_abolish(:), - clpbn_tabled_asserta(:), - clpbn_tabled_assertz(:), - clpbn_tabled_asserta(:,-), - clpbn_tabled_assertz(:,-), - clpbn_tabled_number_of_clauses(:,-), + clpbn_tabled_asserta(:), + clpbn_tabled_assertz(:), + clpbn_tabled_asserta(:,-), + clpbn_tabled_assertz(:,-), + clpbn_tabled_number_of_clauses(:,-), clpbn_is_tabled(:). :- use_module(library(terms), diff --git a/packages/CLPBN/clpbn/utils.yap b/packages/CLPBN/clpbn/utils.yap index 5bce1c943..d8179a69e 100644 --- a/packages/CLPBN/clpbn/utils.yap +++ b/packages/CLPBN/clpbn/utils.yap @@ -66,7 +66,7 @@ merge_same_key([K1-V1,K2-V2|Vs], SortedAVars, Ks, UnifiableVars) :- attributes:fast_unify_attributed(V1,V2), merge_same_key([K1-V1|Vs], SortedAVars, Ks, 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), merge_same_key([K2-V2|Vs], SortedAVars, NKs, 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). in_keys(K1,[K|_]) :- \+ \+ K1 = K, !. -in_keys(K1,[_|Ks]) :- +in_keys(K1,[_|Ks]) :- in_keys(K1,Ks). add_to_keys(K1, Ks, Ks) :- ground(K1), !. diff --git a/packages/CLPBN/clpbn/ve.yap b/packages/CLPBN/clpbn/ve.yap index b2e8d9ea4..21f0d931a 100644 --- a/packages/CLPBN/clpbn/ve.yap +++ b/packages/CLPBN/clpbn/ve.yap @@ -11,7 +11,7 @@ all tables they connect to; multiply their size order by size - + *********************************/ :- 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) :- I is I0+1, pfl:get_pfl_parameters(Id, Pars0), - init_CPT(Pars0, Sizes, CPT0), + init_CPT(Pars0, Sizes, CPT0), reorder_CPT(Nodes, CPT0, FIPs, CPT, _), F = f(I0, FIPs, CPT), 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_domain_size(D, DS), 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, _), rb_insert(Fs0, IF0, f(IF0, FIPs, CPT), Fs), IF is IF0+1. @@ -261,7 +261,7 @@ solve([_|LQVs], FIds, Bigraph, Ev, LPs) :- do_solve(IQVs, IVs, bigraph(OldVs, IF, _Fs), Ev, Ps) :- % 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 rb_visit(Ev, EvL), 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) :- % 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 - foldl2(clean_v_ev, Ev, Fs1, Fs2, SVs, EVs), + foldl2(clean_v_ev, Ev, Fs1, Fs2, SVs, EVs), % eliminate eliminate(IQVs, digraph(EVs, IF, Fs2), Dist), % 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) :- sort(IVs0, IVs), rb_new(Vs0), - foldl(cp_to_vs, IVs, Vs0, AuxVs), + foldl(cp_to_vs, IVs, Vs0, AuxVs), rb_new(NFs0), foldl(simplify_graph_node(OldVs, AuxVs), IVs, VFs, NFs0, NFs), 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 % 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 % % check_factor(V, NVs, F, NFs0, NFs, RemFs, NewRemFs) :- F = f(IF, [V|More], _), !, - ( + ( checklist(check_v(NVs), More) -> 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) :- F = f(Id, _, _), - ( + ( rb_lookup(Id, F, NFs) -> NewRemFs = [F|RemFs] diff --git a/packages/CLPBN/clpbn/vmap.yap b/packages/CLPBN/clpbn/vmap.yap index 98e3df357..79fd7f566 100644 --- a/packages/CLPBN/clpbn/vmap.yap +++ b/packages/CLPBN/clpbn/vmap.yap @@ -12,7 +12,7 @@ :- use_module(library(maplist)). % -% vmap: map V->I +% vmap: map V->I % contiguous Vs to contiguous integers % init_vmap(vmap(0,Empty)) :- diff --git a/packages/CLPBN/examples/School/parlearn.yap b/packages/CLPBN/examples/School/parlearn.yap index e722d8334..f089fb848 100644 --- a/packages/CLPBN/examples/School/parlearn.yap +++ b/packages/CLPBN/examples/School/parlearn.yap @@ -41,4 +41,4 @@ write_cpts([CPT|CPTs]) :- matrix_to_list(CPT,L), format('CPT=~w~n',[L]), write_cpts(CPTs). - + diff --git a/packages/CLPBN/examples/School/parschema.pfl b/packages/CLPBN/examples/School/parschema.pfl index 3d708936a..b799c60d7 100644 --- a/packages/CLPBN/examples/School/parschema.pfl +++ b/packages/CLPBN/examples/School/parschema.pfl @@ -55,7 +55,7 @@ professor_popularity(P,A) :- pop(P,A). course_difficulty(P,A) :- diff(P,A). student_intelligence(P,A) :- int(P,A). - + course_rating(C,X) :- rat(C,X). registration_grade(R,A) :- diff --git a/packages/CLPBN/examples/city.pfl b/packages/CLPBN/examples/city.pfl index c891ae163..37e0eeb22 100644 --- a/packages/CLPBN/examples/city.pfl +++ b/packages/CLPBN/examples/city.pfl @@ -75,17 +75,17 @@ hair_color_table( /* high low */ /* dark */ [ 0.05, 0.1, /* bright */ 0.95, 0.9 ]). - + car_color_table( /* dark bright */ /* dark */ [ 0.9, 0.2, /* bright */ 0.1, 0.8 ]). - + height_table( /* male female */ /* tall */ [ 0.6, 0.4, /* short */ 0.4, 0.6 ]). - + shoe_size_table( /* tall short */ /* big */ [ 0.9, 0.1, @@ -99,7 +99,7 @@ descn_table( /* 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.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 ]). witness_table( diff --git a/packages/CLPBN/horus/BayesBall.h b/packages/CLPBN/horus/BayesBall.h index 4efbd2ed1..2057b6f01 100644 --- a/packages/CLPBN/horus/BayesBall.h +++ b/packages/CLPBN/horus/BayesBall.h @@ -4,7 +4,6 @@ #include #include #include -#include #include "FactorGraph.h" #include "BayesBallGraph.h" @@ -15,8 +14,8 @@ using namespace std; struct ScheduleInfo { - ScheduleInfo (BBNode* n, bool vfp, bool vfc) : - node(n), visitedFromParent(vfp), visitedFromChild(vfc) { } + ScheduleInfo (BBNode* n, bool vfp, bool vfc) + : node(n), visitedFromParent(vfp), visitedFromChild(vfc) { } BBNode* node; bool visitedFromParent; @@ -30,7 +29,7 @@ typedef queue> Scheduling; class BayesBall { public: - BayesBall (FactorGraph& fg) + BayesBall (FactorGraph& fg) : fg_(fg) , dag_(fg.getStructure()) { dag_.clear(); @@ -63,7 +62,7 @@ inline void BayesBall::scheduleParents (const BBNode* n, Scheduling& sch) const { const vector& ps = n->parents(); - for (vector::const_iterator it = ps.begin(); + for (vector::const_iterator it = ps.begin(); it != ps.end(); ++it) { sch.push (ScheduleInfo (*it, false, true)); } diff --git a/packages/CLPBN/horus/BayesBallGraph.h b/packages/CLPBN/horus/BayesBallGraph.h index 72a0f90d0..68cd9effe 100644 --- a/packages/CLPBN/horus/BayesBallGraph.h +++ b/packages/CLPBN/horus/BayesBallGraph.h @@ -30,15 +30,15 @@ class BBNode : public Var void addChild (BBNode* c) { childs_.push_back (c); } bool isVisited (void) const { return visited_; } - + void setAsVisited (void) { visited_ = true; } bool isMarkedOnTop (void) const { return markedOnTop_; } - + void markOnTop (void) { markedOnTop_ = true; } bool isMarkedOnBottom (void) const { return markedOnBottom_; } - + void markOnBottom (void) { markedOnBottom_ = true; } void clear (void) { visited_ = markedOnTop_ = markedOnBottom_ = false; } diff --git a/packages/CLPBN/horus/BeliefProp.cpp b/packages/CLPBN/horus/BeliefProp.cpp index d96384cfd..f56752fe4 100644 --- a/packages/CLPBN/horus/BeliefProp.cpp +++ b/packages/CLPBN/horus/BeliefProp.cpp @@ -146,7 +146,7 @@ BeliefProp::getFactorJoint ( if (Globals::logDomain) { Util::exp (jointDist); } - return jointDist; + return jointDist; } @@ -185,7 +185,7 @@ BeliefProp::runSolver (void) } if (Globals::verbosity > 0) { if (nIters_ < BpOptions::maxIter) { - cout << "Belief propagation converged in " ; + cout << "Belief propagation converged in " ; cout << nIters_ << " iterations" << endl; } else { cout << "The maximum number of iterations was hit, terminating..." ; @@ -459,7 +459,7 @@ void BeliefProp::printLinkInformation (void) const { for (size_t i = 0; i < links_.size(); i++) { - BpLink* l = links_[i]; + BpLink* l = links_[i]; cout << l->toString() << ":" << endl; cout << " curr msg = " ; cout << l->message() << endl; diff --git a/packages/CLPBN/horus/BeliefProp.h b/packages/CLPBN/horus/BeliefProp.h index 64a41d916..87364355c 100644 --- a/packages/CLPBN/horus/BeliefProp.h +++ b/packages/CLPBN/horus/BeliefProp.h @@ -17,7 +17,7 @@ class BpLink { public: BpLink (FacNode* fn, VarNode* vn) - { + { fac_ = fn; var_ = vn; v1_.resize (vn->range(), LogAware::log (1.0 / vn->range())); @@ -46,7 +46,7 @@ class BpLink residual_ = LogAware::getMaxNorm (v1_,v2_); } - virtual void updateMessage (void) + virtual void updateMessage (void) { swap (currMsg_, nextMsg_); } diff --git a/packages/CLPBN/horus/ConstraintTree.cpp b/packages/CLPBN/horus/ConstraintTree.cpp index 0546d0852..3a9fe7b5e 100644 --- a/packages/CLPBN/horus/ConstraintTree.cpp +++ b/packages/CLPBN/horus/ConstraintTree.cpp @@ -190,7 +190,7 @@ ConstraintTree::ConstraintTree ( ConstraintTree::ConstraintTree (vector> names) { assert (names.empty() == false); - assert (names.front().empty() == false); + assert (names.front().empty() == false); unsigned nrLvs = names[0].size(); for (size_t i = 0; i < nrLvs; i++) { logVars_.push_back (LogVar (i)); @@ -201,7 +201,7 @@ ConstraintTree::ConstraintTree (vector> names) Tuple t; for (size_t j = 0; j < names[i].size(); j++) { assert (names[i].size() == nrLvs); - t.push_back (LiftedUtils::getSymbol (names[i][j])); + t.push_back (LiftedUtils::getSymbol (names[i][j])); } addTuple (t); } @@ -266,7 +266,7 @@ ConstraintTree::moveToTop (const LogVars& lvs) assert (pos != logVars_.size()); for (size_t j = pos; j-- > i; ) { swapLogVar (logVars_[j]); - } + } } } @@ -318,7 +318,7 @@ ConstraintTree::join (ConstraintTree* ct, bool oneTwoOne) } else { moveToTop (intersect.elements()); ct->moveToTop (intersect.elements()); - + Tuples tuples; CTNodes appendNodes; getTuples (ct->root(), Tuples(), intersect.size(), @@ -455,7 +455,7 @@ ConstraintTree::singletons (void) if (isSingleton (logVars_[i])) { singletons.insert (logVars_[i]); } - } + } return singletons; } @@ -585,13 +585,13 @@ ConstraintTree::isCountNormalized (const LogVarSet& Ys) if (countTuples (*it) != count) { return false; } - } + } return true; } -unsigned +unsigned ConstraintTree::getConditionalCount (const LogVarSet& Ys) { assert (isCountNormalized (Ys)); @@ -792,7 +792,7 @@ ConstraintTree::jointCountNormalize ( } for (size_t i = 0; i < normCts1.size(); i++) { - unsigned j; + unsigned j; for (j = 0; counts1[i] + counts2[j] != N; j++) ; // cout << "joint-count(" << counts1[i] ; // cout << "," << counts2[j] << ")" << endl; @@ -947,7 +947,7 @@ ConstraintTree::getNodesBelow (CTNode* fromHere) const CTNodes -ConstraintTree::getNodesAtLevel (unsigned level) const +ConstraintTree::getNodesAtLevel (unsigned level) const { assert (level <= logVars_.size()); if (level == 0) { @@ -1057,7 +1057,7 @@ ConstraintTree::join ( } else { tupleFounded = join (*it, tuple, currIdx + 1, appendNode); } - } + } return tupleFounded; } @@ -1065,7 +1065,7 @@ ConstraintTree::join ( void ConstraintTree::getTuples ( - CTNode* n, + CTNode* n, Tuples currTuples, unsigned stopLevel, Tuples& tuplesCollected, @@ -1147,7 +1147,7 @@ ConstraintTree::split ( CTNode* n2, CTChilds& commChilds, CTChilds& exclChilds, - unsigned stopLevel) + unsigned stopLevel) { CTChilds& childs1 = n1->childs(); for (CTChilds::const_iterator chIt1 = childs1.begin(); diff --git a/packages/CLPBN/horus/CountingBp.cpp b/packages/CLPBN/horus/CountingBp.cpp index d248c602c..b86d22f9f 100644 --- a/packages/CLPBN/horus/CountingBp.cpp +++ b/packages/CLPBN/horus/CountingBp.cpp @@ -47,8 +47,7 @@ CountingBp::printSolverFlags (void) const ss << ",max_iter=" << BpOptions::maxIter; ss << ",accuracy=" << BpOptions::accuracy; ss << ",log_domain=" << Util::toString (Globals::logDomain); - ss << ",chkif=" << - Util::toString (CountingBp::checkForIdenticalFactors); + ss << ",chkif=" << Util::toString (CountingBp::checkForIdenticalFactors); ss << "]" ; cout << ss.str() << endl; } @@ -139,7 +138,7 @@ CountingBp::setInitialColors (void) VarColorMap::iterator it = colorMap.find (range); if (it == colorMap.end()) { it = colorMap.insert (make_pair ( - range, Colors (range + 1, -1))).first; + range, Colors (range + 1, -1))).first; } unsigned idx = varNodes[i]->hasEvidence() ? varNodes[i]->getEvidence() diff --git a/packages/CLPBN/horus/ElimGraph.cpp b/packages/CLPBN/horus/ElimGraph.cpp index f617d8237..1942bfb85 100644 --- a/packages/CLPBN/horus/ElimGraph.cpp +++ b/packages/CLPBN/horus/ElimGraph.cpp @@ -28,7 +28,7 @@ ElimGraph::ElimGraph (const vector& factors) } if (neighbors (n1, n2) == false) { addEdge (n1, n2); - } + } } } if (vids.size() == 1) { @@ -86,7 +86,7 @@ ElimGraph::print (void) const cout << " " << neighs[j]->label(); } cout << endl; - } + } } @@ -142,7 +142,7 @@ ElimGraph::getEliminationOrder ( Factors::const_iterator first = factors.begin(); Factors::const_iterator end = factors.end(); for (; first != end; ++first) { - Util::addToVector (allVids, (*first)->arguments()); + Util::addToVector (allVids, (*first)->arguments()); } TinySet elimOrder (allVids); elimOrder -= TinySet (excludedVids); diff --git a/packages/CLPBN/horus/Factor.h b/packages/CLPBN/horus/Factor.h index 742f20f7a..dd004ee24 100644 --- a/packages/CLPBN/horus/Factor.h +++ b/packages/CLPBN/horus/Factor.h @@ -143,7 +143,7 @@ class TFactor assert (idx != args_.size()); assert (obsIdx < ranges_[idx]); Params newps; - newps.reserve (params_.size() / ranges_[idx]); + newps.reserve (params_.size() / ranges_[idx]); Indexer indexer (ranges_); for (unsigned i = 0; i < obsIdx; ++i) { indexer.incrementDimension (idx); @@ -285,7 +285,7 @@ class Factor : public TFactor void sumOutLastVariable (void); void sumOutArgs (const vector& mask); - + void clone (const Factor& f); }; diff --git a/packages/CLPBN/horus/FactorGraph.cpp b/packages/CLPBN/horus/FactorGraph.cpp index 8f5c446b5..df9dd7941 100644 --- a/packages/CLPBN/horus/FactorGraph.cpp +++ b/packages/CLPBN/horus/FactorGraph.cpp @@ -171,7 +171,7 @@ FactorGraph::readFromLibDaiFormat (const char* fileName) std::reverse (vids.begin(), vids.end()); Factor f (vids, ranges, params); std::reverse (vids.begin(), vids.end()); - f.reorderArguments (vids); + f.reorderArguments (vids); addFactor (f); } is.close(); @@ -188,7 +188,7 @@ FactorGraph::addFactor (const Factor& factor) for (size_t i = 0; i < vids.size(); i++) { VarMap::const_iterator it = varMap_.find (vids[i]); if (it != varMap_.end()) { - addEdge (it->second, fn); + addEdge (it->second, fn); } else { VarNode* vn = new VarNode (vids[i], fn->factor().range (i)); addVarNode (vn); @@ -293,7 +293,7 @@ FactorGraph::exportToGraphViz (const char* fileName) const } for (size_t i = 0; i < facNodes_.size(); i++) { out << '"' << facNodes_[i]->getLabel() << '"' ; - out << " [label=\"" << facNodes_[i]->getLabel(); + out << " [label=\"" << facNodes_[i]->getLabel(); out << "\"" << ", shape=box]" << endl; } for (size_t i = 0; i < facNodes_.size(); i++) { diff --git a/packages/CLPBN/horus/FactorGraph.h b/packages/CLPBN/horus/FactorGraph.h index b2b03369d..960f799cc 100644 --- a/packages/CLPBN/horus/FactorGraph.h +++ b/packages/CLPBN/horus/FactorGraph.h @@ -76,7 +76,7 @@ class FactorGraph const FacNodes& facNodes (void) const { return facNodes_; } void setFactorsAsBayesian (void) { bayesFactors_ = true; } - + bool bayesianFactors (void) const { return bayesFactors_; } size_t nrVarNodes (void) const { return varNodes_.size(); } diff --git a/packages/CLPBN/horus/Histogram.cpp b/packages/CLPBN/horus/Histogram.cpp index a9e96cfdd..d5cf729e9 100644 --- a/packages/CLPBN/horus/Histogram.cpp +++ b/packages/CLPBN/horus/Histogram.cpp @@ -59,10 +59,10 @@ HistogramSet::reset (void) -vector +vector HistogramSet::getHistograms (unsigned N, unsigned R) { - HistogramSet hs (N, R); + HistogramSet hs (N, R); unsigned H = hs.nrHistograms(); vector histograms; histograms.reserve (H); @@ -135,7 +135,7 @@ HistogramSet::maxCount (size_t idx) const } return size_ - sum; } - + void diff --git a/packages/CLPBN/horus/HorusCli.cpp b/packages/CLPBN/horus/HorusCli.cpp index 520603052..0997e4655 100644 --- a/packages/CLPBN/horus/HorusCli.cpp +++ b/packages/CLPBN/horus/HorusCli.cpp @@ -77,7 +77,7 @@ readFactorGraph (FactorGraph& fg, const char* s) } else if (extension == "fg") { fg.readFromLibDaiFormat (fileName.c_str()); } 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; exit (EXIT_FAILURE); } diff --git a/packages/CLPBN/horus/HorusYap.cpp b/packages/CLPBN/horus/HorusYap.cpp index 3c566b73a..77e900bb0 100644 --- a/packages/CLPBN/horus/HorusYap.cpp +++ b/packages/CLPBN/horus/HorusYap.cpp @@ -57,7 +57,7 @@ createLiftedNetwork (void) } ParfactorList* pfList = new ParfactorList (parfactors); - + if (Globals::verbosity > 2) { Util::printHeader ("SHATTERED PARFACTORS"); pfList->print(); @@ -91,7 +91,7 @@ createGroundNetwork (void) // read the ranges Ranges ranges = readUnsignedList (YAP_ArgOfTerm (2, factor)); // read the parameters - Params params = readParameters (YAP_ArgOfTerm (3, factor)); + Params params = readParameters (YAP_ArgOfTerm (3, factor)); // read dist id unsigned distId = (unsigned) YAP_IntOfTerm (YAP_ArgOfTerm (4, factor)); fg->addFactor (Factor (varIds, ranges, params, distId)); @@ -126,7 +126,7 @@ runLiftedSolver (void) LiftedNetwork* network = (LiftedNetwork*) YAP_IntOfTerm (YAP_ARG1); ParfactorList pfListCopy (*network->first); LiftedOperations::absorveEvidence (pfListCopy, *network->second); - + LiftedSolver* solver = 0; switch (Globals::liftedSolver) { case LiftedSolverType::LVE: solver = new LiftedVe (pfListCopy); break; @@ -181,7 +181,7 @@ int runGroundSolver (void) { FactorGraph* fg = (FactorGraph*) YAP_IntOfTerm (YAP_ARG1); - + vector tasks; YAP_Term taskList = YAP_ARG2; while (taskList != YAP_TermNil()) { @@ -407,7 +407,7 @@ readParfactor (YAP_Term pfTerm) } // read the parameters - const Params& params = readParameters (YAP_ArgOfTerm (4, pfTerm)); + const Params& params = readParameters (YAP_ArgOfTerm (4, pfTerm)); // read the constraint Tuples tuples; @@ -478,7 +478,7 @@ readLiftedEvidence ( obsFormulas.push_back (ObservedFormula (functor, evidence, args)); } observedList = YAP_TailOfTerm (observedList); - } + } } diff --git a/packages/CLPBN/horus/Indexer.h b/packages/CLPBN/horus/Indexer.h index db99cf1a7..cb8135866 100644 --- a/packages/CLPBN/horus/Indexer.h +++ b/packages/CLPBN/horus/Indexer.h @@ -167,7 +167,7 @@ class MapIndexer } } } - + template MapIndexer ( const vector& allArgs, diff --git a/packages/CLPBN/horus/LiftedKc.cpp b/packages/CLPBN/horus/LiftedKc.cpp index 45848ab70..46f42d5ec 100644 --- a/packages/CLPBN/horus/LiftedKc.cpp +++ b/packages/CLPBN/horus/LiftedKc.cpp @@ -128,7 +128,7 @@ double LeafNode::weight (void) const { assert (clause_->isUnit()); - if (clause_->posCountedLogVars().empty() == false + if (clause_->posCountedLogVars().empty() == false || clause_->negCountedLogVars().empty() == false) { if (SetOrNode::isSet() == false) { // return a NaN if we have a SetOrNode diff --git a/packages/CLPBN/horus/LiftedOperations.cpp b/packages/CLPBN/horus/LiftedOperations.cpp index e0da2dd3b..986a22c03 100644 --- a/packages/CLPBN/horus/LiftedOperations.cpp +++ b/packages/CLPBN/horus/LiftedOperations.cpp @@ -60,7 +60,7 @@ LiftedOperations::runWeakBayesBall ( const Grounds& query) { queue todo; // groups to process - set done; // processed or in queue + set done; // processed or in queue for (size_t i = 0; i < query.size(); i++) { ParfactorList::iterator it = pfList.begin(); while (it != pfList.end()) { @@ -225,7 +225,7 @@ LiftedOperations::absorve ( absorvedPfs.push_back (0); } break; - } + } g->constr()->moveToTop (formulas[i].logVars()); std::pair res; diff --git a/packages/CLPBN/horus/LiftedOperations.h b/packages/CLPBN/horus/LiftedOperations.h index fc25363d3..1f4b53d3a 100644 --- a/packages/CLPBN/horus/LiftedOperations.h +++ b/packages/CLPBN/horus/LiftedOperations.h @@ -10,7 +10,7 @@ class LiftedOperations ParfactorList& pfList, const Grounds& query); static void runWeakBayesBall ( - ParfactorList& pfList, const Grounds&); + ParfactorList& pfList, const Grounds&); static void absorveEvidence ( ParfactorList& pfList, ObservedFormulas& obsFormulas); diff --git a/packages/CLPBN/horus/LiftedUtils.cpp b/packages/CLPBN/horus/LiftedUtils.cpp index 9ad750f90..0233a8554 100644 --- a/packages/CLPBN/horus/LiftedUtils.cpp +++ b/packages/CLPBN/horus/LiftedUtils.cpp @@ -61,7 +61,7 @@ ostream& operator<< (ostream &os, const Symbol& s) ostream& operator<< (ostream &os, const LogVar& X) { const string labels[] = { - "A", "B", "C", "D", "E", "F", + "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "M" }; (X >= 12) ? os << "X_" << X.id_ : os << labels[X]; return os; diff --git a/packages/CLPBN/horus/LiftedUtils.h b/packages/CLPBN/horus/LiftedUtils.h index 1f563eaf7..de0782f1c 100644 --- a/packages/CLPBN/horus/LiftedUtils.h +++ b/packages/CLPBN/horus/LiftedUtils.h @@ -51,7 +51,7 @@ class LogVar } bool valid (void) const - { + { return id_ != Util::maxUnsigned(); } @@ -145,7 +145,7 @@ class Substitution return X; } - bool containsReplacementFor (LogVar X) const + bool containsReplacementFor (LogVar X) const { return Util::contains (subs_, X); } diff --git a/packages/CLPBN/horus/LiftedVe.cpp b/packages/CLPBN/horus/LiftedVe.cpp index 141006c46..bcce3e100 100644 --- a/packages/CLPBN/horus/LiftedVe.cpp +++ b/packages/CLPBN/horus/LiftedVe.cpp @@ -133,7 +133,7 @@ ProductOperator::toString (void) stringstream ss; ss << "just multiplicate " ; ss << (*g1_)->getAllGroups(); - ss << " x " ; + ss << " x " ; ss << (*g2_)->getAllGroups(); ss << " [cost=" << std::exp (getLogCost()) << "]" << endl; return ss.str(); @@ -155,7 +155,7 @@ ProductOperator::validOp (Parfactor* g1, Parfactor* g2) } size_t idx1 = g1->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; } } @@ -713,7 +713,7 @@ LiftedVe::getBestOperation (const Grounds& query) if ((bestOp == 0) || (cost < bestCost)) { bestOp = validOps[i]; bestCost = cost; - } + } } if (bestCost > largestCost_) { largestCost_ = bestCost; diff --git a/packages/CLPBN/horus/LiftedVe.h b/packages/CLPBN/horus/LiftedVe.h index 7d9974294..b747d9da3 100644 --- a/packages/CLPBN/horus/LiftedVe.h +++ b/packages/CLPBN/horus/LiftedVe.h @@ -9,7 +9,7 @@ class LiftedOperator { public: virtual ~LiftedOperator (void) { } - + virtual double getLogCost (void) = 0; virtual void apply (void) = 0; @@ -55,7 +55,7 @@ class ProductOperator : public LiftedOperator class SumOutOperator : public LiftedOperator { public: - SumOutOperator (PrvGroup group, ParfactorList& pfList) + SumOutOperator (PrvGroup group, ParfactorList& pfList) : group_(group), pfList_(pfList) { } double getLogCost (void); diff --git a/packages/CLPBN/horus/LiftedWCNF.cpp b/packages/CLPBN/horus/LiftedWCNF.cpp index ba7097dbf..a75741fa8 100644 --- a/packages/CLPBN/horus/LiftedWCNF.cpp +++ b/packages/CLPBN/horus/LiftedWCNF.cpp @@ -195,7 +195,7 @@ Clause::isPositiveCountedLogVar (LogVar X) const assert (constr_.logVarSet().contains (X)); return posCountedLvs_.contains (X); } - + bool @@ -235,7 +235,7 @@ Clause::ipgCandidates (void) const LogVarSet allLvs = constr_.logVarSet(); allLvs -= ipgLvs_; allLvs -= posCountedLvs_; - allLvs -= negCountedLvs_; + allLvs -= negCountedLvs_; for (size_t i = 0; i < allLvs.size(); i++) { bool valid = true; for (size_t j = 0; j < literals_.size(); j++) { @@ -262,7 +262,7 @@ Clause::logVarTypes (size_t litIdx) const if (posCountedLvs_.contains (lvs[i])) { types.push_back (LogVarType::POS_LV); } else if (negCountedLvs_.contains (lvs[i])) { - types.push_back (LogVarType::NEG_LV); + types.push_back (LogVarType::NEG_LV); } else { types.push_back (LogVarType::FULL_LV); } @@ -391,7 +391,7 @@ LiftedWCNF::LiftedWCNF (const ParfactorList& pfList) { addIndicatorClauses (pfList); addParameterClauses (pfList); - + /* // INCLUSION-EXCLUSION TEST clauses_.clear(); @@ -579,7 +579,7 @@ LiftedWCNF::addParameterClauses (const ParfactorList& pfList) // ¬θxi|u1,...,un v λu2 -> tempClause double posWeight = (**it)[indexer]; addWeight (paramVarLid, posWeight, LogAware::one()); - + Clause* clause1 = new Clause (*(*it)->constr()); for (unsigned i = 0; i < groups.size(); i++) { @@ -593,7 +593,7 @@ LiftedWCNF::addParameterClauses (const ParfactorList& pfList) tempClause->addLiteralComplemented (Literal ( paramVarLid, (*it)->constr()->logVars())); tempClause->addLiteral (Literal (lid, (*it)->argument(i).logVars())); - clauses_.push_back (tempClause); + clauses_.push_back (tempClause); } clause1->addLiteral (Literal (paramVarLid, (*it)->constr()->logVars())); clauses_.push_back (clause1); diff --git a/packages/CLPBN/horus/Parfactor.cpp b/packages/CLPBN/horus/Parfactor.cpp index ef2301b7b..fb5518d1b 100644 --- a/packages/CLPBN/horus/Parfactor.cpp +++ b/packages/CLPBN/horus/Parfactor.cpp @@ -8,7 +8,7 @@ Parfactor::Parfactor ( const ProbFormulas& formulas, - const Params& params, + const Params& params, const Tuples& tuples, unsigned distId) { @@ -221,7 +221,7 @@ Parfactor::countConvert (LogVar X) assert (constr_->isCountNormalized (X)); assert (constr_->getConditionalCount (X) > 1); assert (canCountConvert (X)); - + unsigned N = constr_->getConditionalCount (X); unsigned R = ranges_[fIdx]; unsigned H = HistogramSet::nrHistograms (N, R); @@ -336,7 +336,7 @@ Parfactor::fullExpand (LogVar X) sumIndexes.push_back (HistogramSet::findIndex (hist, originHists)); ++ indexer; } - + expandPotential (fIdx, std::pow (R, N), sumIndexes); ProbFormula f = args_[fIdx]; @@ -360,7 +360,7 @@ Parfactor::reorderAccordingGrounds (const Grounds& grounds) ProbFormulas newFormulas; for (size_t i = 0; i < grounds.size(); i++) { 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()) { constr_->moveToTop (args_[j].logVars()); if (constr_->containsTuple (grounds[i].args())) { @@ -424,7 +424,7 @@ Parfactor::indexOfGround (const Ground& ground) const { size_t idx = args_.size(); 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()) { constr_->moveToTop (args_[i].logVars()); if (constr_->containsTuple (ground.args())) { @@ -806,7 +806,7 @@ Parfactor::simplifyParfactor (size_t fIdx1, size_t fIdx2) while (indexer.valid()) { if (indexer[fIdx1] == indexer[fIdx2]) { params_.push_back (backup[indexer]); - } + } ++ indexer; } for (size_t i = 0; i < args_[fIdx2].logVars().size(); i++) { @@ -829,7 +829,7 @@ Parfactor::getAlignLogVars (Parfactor* g1, Parfactor* g2) TinySet matchedI; TinySet matchedJ; ProbFormulas& formulas1 = g1->arguments(); - ProbFormulas& formulas2 = g2->arguments(); + ProbFormulas& formulas2 = g2->arguments(); for (size_t i = 0; i < formulas1.size(); i++) { for (size_t j = 0; j < formulas2.size(); j++) { if (formulas1[i].group() == formulas2[j].group() && @@ -882,7 +882,7 @@ Parfactor::alignLogicalVars (Parfactor* g1, Parfactor* g2) LogVar freeLogVar (0); Substitution theta1, theta2; 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]); if (b1 == false && b2 == false) { theta1.add (alignLvs1[i], freeLogVar); @@ -911,11 +911,11 @@ Parfactor::alignLogicalVars (Parfactor* g1, Parfactor* g2) } // 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)} LogVars discardedLvs1 = theta1.getDiscardedLogVars(); 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->constr()->remove (discardedLvs1[i]); } else { diff --git a/packages/CLPBN/horus/Parfactor.h b/packages/CLPBN/horus/Parfactor.h index 1c65c2ea0..2f4b45cd7 100644 --- a/packages/CLPBN/horus/Parfactor.h +++ b/packages/CLPBN/horus/Parfactor.h @@ -115,7 +115,7 @@ class Parfactor : public TFactor static void alignLogicalVars (Parfactor*, Parfactor*); ConstraintTree* constr_; - + }; diff --git a/packages/CLPBN/horus/ParfactorList.cpp b/packages/CLPBN/horus/ParfactorList.cpp index 1de1ccc7d..2962f144e 100644 --- a/packages/CLPBN/horus/ParfactorList.cpp +++ b/packages/CLPBN/horus/ParfactorList.cpp @@ -9,7 +9,7 @@ ParfactorList::ParfactorList (const ParfactorList& pfList) while (it != pfList.end()) { addShattered (new Parfactor (**it)); ++ it; - } + } } @@ -74,7 +74,7 @@ ParfactorList::insertShattered ( list::iterator -ParfactorList::remove (list::iterator it) +ParfactorList::remove (list::iterator it) { return pfList_.erase (it); } @@ -418,7 +418,7 @@ ParfactorList::shatter (Parfactor* g1, Parfactor* g2) if (formulas1[i].sameSkeletonAs (formulas2[j])) { std::pair res; res = shatter (i, g1, j, g2); - if (res.first.empty() == false || + if (res.first.empty() == false || res.second.empty() == false) { return res; } @@ -470,7 +470,7 @@ ParfactorList::shatter ( ConstraintTree* exclCt1 = split1.second; if (commCt1->empty()) { - // disjoint + // disjoint delete commCt1; delete exclCt1; return { }; @@ -549,11 +549,11 @@ ParfactorList::shatter ( Parfactor* newPf = new Parfactor (g, cts[i]); if (cts[i]->nrLogVars() == g->constr()->nrLogVars() + 1) { 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_new2)); } else { - assert (g->constr()->getConditionalCount (f.countedLogVar()) == + assert (g->constr()->getConditionalCount (f.countedLogVar()) == cts[i]->getConditionalCount (f.countedLogVar())); } newPf->setNewGroups(); diff --git a/packages/CLPBN/horus/ProbFormula.cpp b/packages/CLPBN/horus/ProbFormula.cpp index fa2d26d05..081cccf95 100644 --- a/packages/CLPBN/horus/ProbFormula.cpp +++ b/packages/CLPBN/horus/ProbFormula.cpp @@ -61,7 +61,7 @@ ProbFormula::countedLogVar (void) const } - + void ProbFormula::setCountedLogVar (LogVar lv) { @@ -92,9 +92,10 @@ ProbFormula::rename (LogVar oldName, LogVar newName) } + bool operator== (const ProbFormula& f1, const ProbFormula& f2) -{ - return f1.group_ == f2.group_ && +{ + return f1.group_ == f2.group_ && f1.logVars_ == f2.logVars_; } diff --git a/packages/CLPBN/horus/ProbFormula.h b/packages/CLPBN/horus/ProbFormula.h index 63086266a..52bc7d4a0 100644 --- a/packages/CLPBN/horus/ProbFormula.h +++ b/packages/CLPBN/horus/ProbFormula.h @@ -12,11 +12,11 @@ typedef unsigned long PrvGroup; class ProbFormula { public: - ProbFormula (Symbol f, const LogVars& lvs, unsigned range) + ProbFormula (Symbol f, const LogVars& lvs, unsigned range) : functor_(f), logVars_(lvs), range_(range), countedLogVar_(), group_(numeric_limits::max()) { } - ProbFormula (Symbol f, unsigned r) + ProbFormula (Symbol f, unsigned r) : functor_(f), range_(r), group_(numeric_limits::max()) { } Symbol functor (void) const { return functor_; } @@ -76,10 +76,10 @@ typedef vector ProbFormulas; class ObservedFormula { public: - ObservedFormula (Symbol f, unsigned a, unsigned ev) + ObservedFormula (Symbol f, unsigned a, unsigned ev) : 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_) { constr_.addTuple (tuple); diff --git a/packages/CLPBN/horus/TinySet.h b/packages/CLPBN/horus/TinySet.h index 4b3c4bd83..f7ff6e083 100644 --- a/packages/CLPBN/horus/TinySet.h +++ b/packages/CLPBN/horus/TinySet.h @@ -21,7 +21,7 @@ class TinySet TinySet (const Compare& cmp = Compare()) : vec_(), cmp_(cmp) { } - TinySet (const T& t, const Compare& cmp = Compare()) + TinySet (const T& t, const Compare& cmp = Compare()) : vec_(1, t), cmp_(cmp) { } TinySet (const vector& elements, const Compare& cmp = Compare()) @@ -153,12 +153,12 @@ class TinySet { return vec_[i]; } - + T& operator[] (typename vector::size_type i) { return vec_[i]; } - + T front (void) const { return vec_.front(); @@ -219,7 +219,7 @@ class TinySet 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 << "{" ; typename vector::size_type i; diff --git a/packages/CLPBN/horus/Util.cpp b/packages/CLPBN/horus/Util.cpp index 0f3ce6544..6afd56f43 100644 --- a/packages/CLPBN/horus/Util.cpp +++ b/packages/CLPBN/horus/Util.cpp @@ -140,7 +140,7 @@ nrDigits (int num) { unsigned count = 1; while (num >= 10) { - num /= 10; + num /= 10; count ++; } return count; @@ -166,7 +166,7 @@ parametersToString (const Params& v, unsigned precision) { stringstream ss; ss.precision (precision); - ss << "[" ; + ss << "[" ; for (size_t i = 0; i < v.size(); i++) { if (i != 0) ss << ", " ; ss << v[i]; diff --git a/packages/CLPBN/horus/Util.h b/packages/CLPBN/horus/Util.h index 38a088714..1a4bfa441 100644 --- a/packages/CLPBN/horus/Util.h +++ b/packages/CLPBN/horus/Util.h @@ -373,8 +373,8 @@ void operator^=(std::vector& v, int iexp) -template -std::ostream& operator << (std::ostream& os, const vector& v) +template +std::ostream& operator<< (std::ostream& os, const vector& v) { os << "[" ; os << Util::elementsToString (v, ", "); diff --git a/packages/CLPBN/horus/Var.cpp b/packages/CLPBN/horus/Var.cpp index 44ab6b1e4..80fc0abe6 100644 --- a/packages/CLPBN/horus/Var.cpp +++ b/packages/CLPBN/horus/Var.cpp @@ -49,7 +49,7 @@ Var::isValidState (const string& stateName) void -Var::setEvidence (int ev) +Var::setEvidence (int ev) { assert (ev < (int) range_); evidence_ = ev; @@ -58,8 +58,8 @@ Var::setEvidence (int ev) void -Var::setEvidence (const string& ev) -{ +Var::setEvidence (const string& ev) +{ States states = Var::getVarInfo (varId_).states; for (size_t i = 0; i < states.size(); i++) { if (states[i] == ev) { diff --git a/packages/CLPBN/horus/VarElim.cpp b/packages/CLPBN/horus/VarElim.cpp index fb4eecf50..54ee18d20 100644 --- a/packages/CLPBN/horus/VarElim.cpp +++ b/packages/CLPBN/horus/VarElim.cpp @@ -70,7 +70,7 @@ VarElim::createFactorList (void) factorList_.push_back (new Factor (facNodes[i]->factor())); const VarNodes& neighs = facNodes[i]->neighbors(); for (size_t j = 0; j < neighs.size(); j++) { - unordered_map>::iterator it + unordered_map>::iterator it = varFactors_.find (neighs[j]->varId()); if (it == varFactors_.end()) { it = varFactors_.insert (make_pair ( diff --git a/packages/CLPBN/horus/WeightedBp.cpp b/packages/CLPBN/horus/WeightedBp.cpp index d8a32a246..8416c4592 100644 --- a/packages/CLPBN/horus/WeightedBp.cpp +++ b/packages/CLPBN/horus/WeightedBp.cpp @@ -132,7 +132,7 @@ WeightedBp::maxResidualSchedule (void) } } // 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(); for (size_t i = 0; i < links.size(); i++) { if (links[i]->varNode() != link->varNode()) { @@ -258,7 +258,7 @@ WeightedBp::getVarToFactorMsg (const BpLink* _link) const if ( ! (l->facNode() == dst && l->index() == link->index())) { msg *= l->powMessage(); if (Constants::SHOW_BP_CALCS) { - cout << " x " << l->nextMessage() << "^" << link->weight(); + cout << " x " << l->nextMessage() << "^" << link->weight(); } } } diff --git a/packages/CLPBN/horus/WeightedBp.h b/packages/CLPBN/horus/WeightedBp.h index 7794fd509..1e79fd4db 100644 --- a/packages/CLPBN/horus/WeightedBp.h +++ b/packages/CLPBN/horus/WeightedBp.h @@ -6,7 +6,7 @@ class WeightedLink : public BpLink { 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), pwdMsg_(vn->range(), LogAware::one()) { } @@ -16,7 +16,7 @@ class WeightedLink : public BpLink const Params& powMessage (void) const { return pwdMsg_; } - void updateMessage (void) + void updateMessage (void) { pwdMsg_ = *nextMsg_; swap (currMsg_, nextMsg_); diff --git a/packages/CLPBN/learning/aleph_params.yap b/packages/CLPBN/learning/aleph_params.yap index cb6070eb4..5fcf9be9d 100644 --- a/packages/CLPBN/learning/aleph_params.yap +++ b/packages/CLPBN/learning/aleph_params.yap @@ -50,7 +50,7 @@ % % 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). % @@ -123,7 +123,7 @@ add_new_clause(_,(H :- B),_,_) :- asserta(user:(H :- IB)) ), user:setting(verbosity,V), - ( V >= 1 -> + ( V >= 1 -> user:p_message('CLP(BN) Theory'), functor(H,N,Ar), listing(user:N/Ar) ; @@ -138,7 +138,7 @@ update_tabled_theory(H) :- clpbn_tabled_assertz((user:(H:-NB))), fail. update_tabled_theory(_). - + update_theory(H) :- clause(user:H,B,Ref), 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_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) :- domain(H, K, V, D), 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((A,B), (user:A,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_body(A, (user:A,Tail), [], [], Tail). diff --git a/packages/CLPBN/learning/em.yap b/packages/CLPBN/learning/em.yap index 8abe4e92d..7ace0b9b3 100644 --- a/packages/CLPBN/learning/em.yap +++ b/packages/CLPBN/learning/em.yap @@ -33,7 +33,7 @@ [generate_network/5, f/3 ]). - + :- use_module(library('clpbn/utils'), [check_for_hidden_vars/3, sort_vars_by_key/3 @@ -46,7 +46,7 @@ compute_likelihood/3, soften_sample/2 ]). - + :- use_module(library(bhash), [b_hash_new/1, b_hash_lookup/3, @@ -198,7 +198,7 @@ ltables([Id-T|Tables], [Key-LTable|FTables]) :- generate_dists(Factors, EList, AllDists, AllInfo, MargVars) :- - b_hash_new(Ev0), + b_hash_new(Ev0), foldl(elist_to_hash, EList, Ev0, Ev), maplist(process_factor(Ev), Factors, Dists0), sort(Dists0, Dists1), @@ -220,7 +220,7 @@ fetch_evidence(_Ev, K, Ns, NonEvs, [K|NonEvs]) :- domain_to_number(_, I0, I0, I) :- I is I0+1. - + % collect the different dists we are going to learn next. different_dists(AllVars, AllDists, AllInfo, MargVars) :- @@ -232,9 +232,9 @@ different_dists(AllVars, AllDists, AllInfo, MargVars) :- % % V -> to Id defining V. We get: % 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 -% [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 % all_dists([], _, []). diff --git a/packages/CLPBN/learning/mle.yap b/packages/CLPBN/learning/mle.yap index 14080fe69..4456db86e 100644 --- a/packages/CLPBN/learning/mle.yap +++ b/packages/CLPBN/learning/mle.yap @@ -57,7 +57,7 @@ mk_sample(AllVars, 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([V|Vs],[val(Id,[Ev|EParents])|Vals]) :- diff --git a/packages/CLPBN/pfl.yap b/packages/CLPBN/pfl.yap index 5272aa8f5..4c2a0efc6 100644 --- a/packages/CLPBN/pfl.yap +++ b/packages/CLPBN/pfl.yap @@ -50,7 +50,7 @@ append/3, member/2 ]). - + :- 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)) :- @@ -178,7 +178,7 @@ add_evidence(Sk,Var) :- 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), !, %% Keys = [Key|Parents], %% writeln(Key:Parents),