This is a follow up question to Can you use clpfd to implement a coverage algorithm?
I have put the code here: http://swish.swi-prolog.org/p/Coverage%20using%20Constraints%20%20.pl
There are two search procedures.
start_exhaustive_search(Positives,Negatives,r(Features, Value,cm(TP,FP)))
And a heuristic search :
start_search(Ps,Ns,Result).
The heuristic search will refine a rule until it does not cover any negatives. cm is for confusion matrix.
There are three ways to test the predicates, one with a small database accessible with pos(Ps)
and negs(Ns)
. Then a larger database accessible with approved(Ps)
and notapproved(Ns)
. This also has some predicates to turn the binary representation of used features into a list of named features.binary_to_features(Binary,Features)
.
You can also generate a random matrix of examples using random_binary_matrix_x_y(X,Y,R)
(With X as 9 the result will be compatible with the larger approved/notapproved example.).
Example exhaustive query:
?-approved(Ps),notapproved(Ns),start_exhaustive_search(Ps,Ns,Result).
Result = r([0, 0, 0, 0, 0, 0, 0, 1, 0, 0], 21, cm(6, 1)).
Example heuristic query:
?-approved(Ps),notapproved(Ns),start_search(Ps,Ns,Result).
Result = [r([0, 0, 0, 0, 0, 0, 0, 1, 0, 0], 21, cm(6, 1)), r([0, 0, 0, 0, 0, 0, 0, 1, 0, 1], 20, cm(4, 0))]
So both methods do not seem to be as fast as I would imagine is possible using the constraints. Is there a way to improve the speed?
Also I am curious why I cant use dif/2 but have to use \== on line 98?
I am using card/2 to count the number of examples covered, I cant see another way to use this?