Several whitespace fixes

This commit is contained in:
Tiago Gomes 2012-12-17 17:57:00 +00:00
parent 409a230826
commit 2f2f88e571
27 changed files with 667 additions and 666 deletions

View File

@ -246,7 +246,8 @@ project_attributes(GVars0, _AVars0) :-
generate_network(GVars0, GKeys, Keys, Factors, Evidence),
b_setval(clpbn_query_variables, f(GVars0,Evidence)),
simplify_query(GVars0, GVars),
( GKeys = []
(
GKeys = []
->
GVars0 = [V|_],
clpbn_display:put_atts(V, [posterior([],[],[],[])])

View File

@ -1,4 +1,4 @@
%
%
% generate explicit CPTs
%
:- module(clpbn_aggregates,
@ -273,7 +273,9 @@ include_qevidence(_, MAT, MAT, NewParents, NewParents, _, Vs, Vs).
check_consistency(L1, Ev, MAT0, MAT1, L1, MAT, NewParents0, NewParents, Vs, IVs, NewVs) :-
sumlist(L1, Tot),
nth0(Ev, L1, Val),
(Val == Tot ->
(
Val == Tot
->
MAT1 = MAT,
NewParents = [],
Vs = NewVs

View File

@ -384,9 +384,9 @@ avg_exp([Val|Vals], PVars, I0, P0, Max, Size, Im, IM, HI, HF, O) :-
(Vals = [] -> O=O1 ; O = Val*O1+not(Val)*O2 ),
Im1 is max(0, Im-I0),
IM1 is IM-I0,
( IM1 < 0 -> O1 = 0, H2 = HI; /* we have exceed maximum */
Im1 > Max -> O1 = 0, H2 = HI; /* we cannot make to minimum */
Im1 = 0, IM1 > Max -> O1 = 1, H2 = HI; /* we cannot exceed maximum */
( IM1 < 0 -> O1 = 0, H2 = HI ; /* we have exceed maximum */
Im1 > Max -> O1 = 0, H2 = HI ; /* we cannot make to minimum */
Im1 = 0, IM1 > Max -> O1 = 1, H2 = HI ; /* we cannot exceed maximum */
P is P0+1,
avg_tree(PVars, P, Max, Im1, IM1, Size, O1, HI, H2)
),

View File

@ -428,4 +428,3 @@ mk_evidence_query([V|L], [H|T], [ar(1,Pos,El)|LN]) :-
nth(El,D,H),
mk_evidence_query(L, T, LN).

View File

@ -92,7 +92,8 @@ process_new_variable(V, Evs, G, RG, Vs0, Vs2) :-
throw_below(Evs, G, RG, Child, Vs0, Vs1) :-
rb_lookup(Child, [_|B], Vs0), !,
(
B == b ->
B == b
->
Vs0 = Vs1 % been there before
;
B = b, % mark it
@ -122,7 +123,8 @@ handle_ball_from_above(V, Evs, G, RG, Vs0, Vs1) :-
throw_above(Evs, G, RG, Parent, Vs0, Vs1) :-
rb_lookup(Parent, [T|_], Vs0), !,
(
T == t ->
T == t
->
Vs1 = Vs0 % been there before
;
T = t, % mark it

View File

@ -1,3 +1,4 @@
:- module(clpbn_display,
[clpbn_bind_vals/3]).

View File

@ -84,7 +84,6 @@ add_links([K0|TVs],K) :-
assert(edge(K,K0)),
add_links(TVs,K).
incorporate_evidence(Vs,AllVs) :-
rb_new(Cache0),
create_open_list(Vs, OL, FL, Cache0, CacheI),

View File

@ -458,7 +458,7 @@ get_estimate_pos([I|Is], Sample, [M|Mult], V0, V) :-
get_estimate_pos(Is, Sample, Mult, VI, V).
update_estimate_for_var(V0,[X|T],[X1|NT]) :-
( V0 == 0 ->
(V0 == 0 ->
X1 is X+1,
NT = T
;

View File

@ -47,21 +47,18 @@ hmm_state(N/A,Mod) :-
Key =.. [T|KArgs],
Head =.. [N|LArgs],
asserta_static( (Mod:Head :-
( First > 2 ->
(First > 2 ->
Last = Key, !
;
nb_getval(trie, Trie), trie_check_entry(Trie, Key, _)
->
nb_getval(trie, Trie), trie_check_entry(Trie, Key, _) ->
% leave work for solver!
%
Last = Key, !
;
% first time we saw this entry
nb_getval(trie, Trie), trie_put_entry(Trie, Key, _),
fail
)
)
).
)).
build_args(4,[A,B,C,D],[A,B,C],A,D).
build_args(3, [A,B,C], [A,B],A,C).

View File

@ -294,8 +294,7 @@ add_clique_edges([], _, _, Edges, Edges).
add_clique_edges([Clique1|Cliques], Clique, Sz, Edges0, EdgesF) :-
ord_intersection(Clique1, Clique, Int),
Int \== Clique,
(
Int = [] ->
(Int = [] ->
add_clique_edges(Cliques, Clique, Sz, Edges0, EdgesF)
;
% we connect
@ -362,7 +361,7 @@ get_cpts([], _, [], []).
get_cpts([CPT|CPts], [], [], [CPT|CPts]) :- !.
get_cpts([[I|MCPT]-Info|CPTs], [J|Clique], MyCPTs, MoreCPTs) :-
compare(C,I,J),
( C == < ->
(C == < ->
% our CPT cannot be a part of the clique.
MoreCPTs = [[I|MCPT]-Info|LeftoverCPTs],
get_cpts(CPTs, [J|Clique], MyCPTs, LeftoverCPTs)

View File

@ -1,3 +1,4 @@
:- module(clpbn_matrix_utils,
[init_CPT/3,
project_from_CPT/3,

View File

@ -108,30 +108,28 @@ clpbn_table(F/N,M) :-
L0 = [_|Args0],
IGoal =.. [NF|Args0],
asserta(clpbn_table(S, M, IGoal)),
assert(
(M:S :-
assert((M:S :-
!,
% write(S: ' ' ),
b_getval(clpbn_tables, Tab),
% V2 is unbound.
( b_hash_lookup(Key, V2, Tab) ->
(b_hash_lookup(Key, V2, Tab) ->
% (attvar(V2) -> writeln(ok:A0:V2) ; writeln(error(V2:should_be_attvar(S)))),
( var(A0) -> A0 = V2 ; put_evidence(A0, V2) )
(var(A0) -> A0 = V2 ; put_evidence(A0, V2))
;
% writeln(new),
b_hash_insert(Tab, Key, V2, NewTab),
b_setval(clpbn_tables,NewTab),
once(M:Goal), !,
% enter evidence after binding.
( var(A0) -> A0 = V2 ; put_evidence(A0, V2) )
(var(A0) -> A0 = V2 ; put_evidence(A0, V2))
;
clpbn:clpbn_flag(solver,none) ->
true
;
throw(error(tabled_clpbn_predicate_should_never_fail,S))
)
)
).
)).
take_tail([V], V, [], V1, [V1]) :- !.
take_tail([A|L0], V, [A|L1], V1, [A|L2]) :-
@ -154,19 +152,17 @@ clpbn_tableallargs(F/N,M) :-
atom_concat(F, '___tabled', NF),
NKey =.. [NF|Args],
asserta(clpbn_table(Key, M, NKey)),
assert(
(M:Key :-
assert((M:Key :-
!,
b_getval(clpbn_tables, Tab),
( b_hash_lookup(Key, Out, Tab) ->
(b_hash_lookup(Key, Out, Tab) ->
true
;
b_hash_insert(Tab, Key, Out, NewTab),
b_setval(clpbn_tables, NewTab),
once(M:NKey)
)
)
).
)).
clpbn_table_nondet(M:X) :- !,
clpbn_table_nondet(X,M).
@ -185,18 +181,17 @@ clpbn_table_nondet(F/N,M) :-
atom_concat(F, '___tabled', NF),
NKey =.. [NF|Args],
asserta(clpbn_table(Key, M, NKey)),
assert(
(M:Key :- % writeln(in:Key),
assert((M:Key :-
% writeln(in:Key),
b_getval(clpbn_tables, Tab),
( b_hash_lookup(Key, Out, Tab) ->
(b_hash_lookup(Key, Out, Tab) ->
fail
;
b_hash_insert(Tab, Key, Out, NewTab),
b_setval(clpbn_tables, NewTab),
M:NKey
)
)
).
)).
user:term_expansion((P :- Gs), NC) :-
clpbn_table(P, M, NP),

View File

@ -54,12 +54,10 @@ get_keys([_|AVars], KeysVars) :- % may be non-CLPBN vars.
merge_same_key([], [], _, []).
merge_same_key([K1-V1,K2-V2|Vs], SortedAVars, Ks, UnifiableVars) :-
K1 == K2, !,
(clpbn:get_atts(V1, [evidence(E)])
->
(clpbn:get_atts(V1, [evidence(E)]) ->
clpbn:put_atts(V2, [evidence(E)])
;
clpbn:get_atts(V2, [evidence(E)])
->
clpbn:get_atts(V2, [evidence(E)]) ->
clpbn:put_atts(V1, [evidence(E)])
;
true

View File

@ -11,7 +11,8 @@
%
:- module(clpbn_aleph,
[init_clpbn_cost/0,
random_type/2]).
random_type/2
]).
:- dynamic rt/2, inited/1.
@ -19,7 +20,8 @@
[{}/1,
clpbn_flag/2,
clpbn_flag/3,
set_clpbn_flag/2]).
set_clpbn_flag/2
]).
:- use_module(library('clpbn/learning/em')).
@ -42,7 +44,8 @@
clpbn_tabled_number_of_clauses/2,
clpbn_is_tabled/1,
clpbn_reset_tables/0,
clpbn_tabled_dynamic/1]).
clpbn_tabled_dynamic/1
]).
%
% Tell Aleph not to use default solver during saturation

View File

@ -8,20 +8,20 @@
:- module(bnt_parameters, [learn_parameters/2]).
:- use_module(library('clpbn'), [
clpbn_flag/3]).
:- use_module(library('clpbn'),
[clpbn_flag/3]).
:- use_module(library('clpbn/bnt'), [
create_bnt_graph/2]).
:- use_module(library('clpbn/bnt'),
[create_bnt_graph/2]).
:- use_module(library('clpbn/display'), [
clpbn_bind_vals/3]).
:- use_module(library('clpbn/display'),
[clpbn_bind_vals/3]).
:- use_module(library('clpbn/dists'), [
get_dist_domain/2
]).
:- use_module(library('clpbn/dists'),
[get_dist_domain/2]).
:- use_module(library(matlab), [matlab_initialized_cells/4,
:- use_module(library(matlab),
[matlab_initialized_cells/4,
matlab_call/2,
matlab_get_variable/2
]).

View File

@ -129,8 +129,7 @@ setup_em_network(Items, state(AllDists, AllDistInstances, MargVars, SolverState)
run_examples(user:Exs, Keys, Factors, EList) :-
Exs = [_:_|_], !,
findall(ex(EKs, EFs, EEs), run_example(Exs, EKs, EFs, EEs),
VExs),
findall(ex(EKs, EFs, EEs), run_example(Exs, EKs, EFs, EEs), VExs),
foldl4(join_example, VExs, [], Keys, [], Factors, [], EList, 0, _).
run_examples(Items, Keys, Factors, EList) :-
run_ex(Items, Keys, Factors, EList).

View File

@ -2,12 +2,14 @@
% Utilities for learning
%
:- module(clpbn_learn_utils, [run_all/1,
:- module(clpbn_learn_utils,
[run_all/1,
clpbn_vars/2,
normalise_counts/2,
compute_likelihood/3,
soften_sample/2,
soften_sample/3]).
soften_sample/3
]).
:- use_module(library(clpbn),
[clpbn_flag/2]).

View File

@ -5,9 +5,11 @@
% This assumes we have a single big example.
%
:- module(clpbn_mle, [learn_parameters/2,
:- module(clpbn_mle,
[learn_parameters/2,
learn_parameters/3,
parameters_from_evidence/3]).
parameters_from_evidence/3
]).
:- use_module(library('clpbn')).
@ -16,11 +18,13 @@
clpbn_vars/2,
normalise_counts/2,
soften_table/2,
normalise_counts/2]).
normalise_counts/2
]).
:- use_module(library('clpbn/dists'),
[empty_dist/2,
dist_new_table/2]).
dist_new_table/2
]).
:- use_module(library(matrix),
[matrix_inc/2]).

View File

@ -168,8 +168,7 @@ interface_predicate(Sk) :-
evidence(Sk,Ev) -> Ev = Var;
var(Var) -> insert_atts(Var,Sk) ;
add_evidence(Sk,Var)
)
).
)).
insert_atts(Var,Sk) :-
clpbn:put_atts(Var,[key(Sk)]).