*
% For a set of positive and negative examples Pxs and Nxs, compute the % information gain of Clause over a clause which produces a split % having Info, as it's "information value" on these examples. compute_gain(Nxs, Pxs, Info, Clause, Gain) :- covered_examples(Clause, Pxs, Retained), length(Retained, R), ( R =:= 0 -> Gain = 0 ; info_value(Clause, Pxs, Nxs, Info1), Gain is R * (Info - Info1) ).
% Compute the information matric for the set of positive and negative % tuples which result from applying Clause to the examples Pxs and % NXs. info_value(Clause, Pxs, Nxs, Value) :- tuples(Clause, Pxs, Ptuples), length(Ptuples, P), ( P =:= 0 -> Value = 0 ; tuples(Clause, Nxs, Ntuples), length(Ntuples, N), Temp is P / (P + N), log(Temp, Temp1), Value is Temp1 * -1.442695 ).
% Given a clause and a list of examples, construct the list of tuples % for the clause. A tuple is the binding of values to variables such % that the clause can be used to prove the example. tuples((A :- B), Xs, Tuples) :- variables_in((A :- B), Vars), variables_in(A, HeadVars), length(HeadVars, N1), length(Vars, N2), ( N1 =:= N2 -> %% shortcut - only need 1 proof if no new variables. findall(Vars, (member(A, Xs), \+(\+ B)), Tuples) ; findall(Vars, (member(A,Xs), call(B)), Tuples) ).
% Construct a list representing the set of variables in Term. variables_in(A, Vs) :- variables_in(A, [], Vs). variables_in(A, V0, V) :- var(A), !, ord_add_element(V0, A, V). variables_in(A, V0, V) :- ground(A), !, V = V0. variables_in(Term, V0, V) :- functor(Term, _, N), variables_in_args(N, Term, V0, V). variables_in_args(N, Term, V0, V) :- ( N =:= 0 -> V = V0 ; arg(N, Term, Arg), variables_in(Arg, V0, V1), N1 is N-1, variables_in_args(N1, Term, V1, V) ).
*