Improving clpfd coverage algorithm speed?

This is the next question. Can you use clpfd to implement the coverage algorithm?

I posted 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 heuristic search:

start_search(Ps,Ns,Result).

A heuristic search will refine the rule until it covers any negatives. see for the matrix of confusion.

There are three ways to test predicates: one with a small database accessible with pos(Ps)and negs(Ns). Then a large database is available with approved(Ps)and notapproved(Ns). It also has predicates to turn a binary representation of used functions into a list of named functions. binary_to_features(Binary,Features). You can also create a random matrix of examples using random_binary_matrix_x_y(X,Y,R)(with X as 9, the result will be compatible with a larger approved / non-approved example.).

An example of an 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)).

An example of a heuristic request:

?-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))]

Thus, both methods do not look as fast as I could have imagined using restrictions. Is there a way to improve speed?

I am also wondering why I cannot use diff / 2, but do I need to use \ == on line 98?

card/2 , ?

+4

Source: https://habr.com/ru/post/1608124/


All Articles