2:- module(test,
    3  [test/0,test_all/0]).    4:- use_module(library(plunit)).    5
    6test:-
    7  test_all.
    8
    9test_all:-
   10  tests(A),
   11  run_tests(A).
   12
   13tests([rank,carc,muta,bupa,mondial,nba,bongard]).
   14
   15:- begin_tests(rank, []).   16:-ensure_loaded(library(liftcover)).   17
   18test(rank1):-
   19  L=[8.0-spider,4.0-cat,4.0-dog,2.0-penguin,0.0-snake],
   20  rank(spider,L,1.0),
   21  rank(cat,L,2.5),
   22  rank(dog,L,2.5),
   23  rank(penguin,L,4.0),
   24  rank(snake,L,5.0).
   25
   26test(rank2):-
   27  L=[8.0-spider,8.0-crab,4.0-cat,4.0-dog,4.0-horse,2.0-penguin,0.0-snake],
   28  rank(spider,L,1.5),
   29  rank(crab,L,1.5),
   30  rank(cat,L,4.0),
   31  rank(dog,L,4.0),
   32  rank(horse,L,4.0),
   33  rank(penguin,L,6.0),
   34  rank(snake,L,7.0).
   35
   36test(rank3):-
   37  L=[8.0-spider,8.0-crab,4.0-cat,4.0-dog,4.0-horse,2.0-penguin,0.0-snake,0.0-snail],
   38  rank(snake,L,7.5),
   39  rank(snail,L,7.5),
   40  rank(cricket,L,+inf).
   41
   42:- end_tests(rank).   43
   44:- begin_tests(bupa, []).   45:-ensure_loaded(library(examples_lift/bupa)).   46:-use_module(library(cplint_test/cplint_test)).   47
   48test(induce_bupa):-
   49  set_lift(verbosity,0),
   50  induce_lift([f1,f2,f3,f4],P),test_lift(P,[f5],LL,AUCROC,_ROC,AUCPR,_PR),
   51  writeln('Result:'),
   52  writeln(P),
   53  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
   54  writeln(St),
   55  atomic_list_concat(['Expected:\n',
   56  '\nLL =', 0.0,
   57  '\nAUCROC =',1.0,
   58  '\nAUCPR =', 1.0],St1),
   59  writeln(St1).
   60
   61:- end_tests(bupa).   62
   63:- begin_tests(carc, []).   64:-ensure_loaded(library(examples_lift/carc)).   65:-use_module(library(cplint_test/cplint_test)).   66
   67test(in_carc):-
   68  in(P),test_lift(P,[all],LL,AUCROC,_ROC,AUCPR,_PR),
   69writeln('Result:'),
   70writeln(P),
   71atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
   72writeln(St),
   73atomic_list_concat(['Expected:\n', 
   74'\nLL =', -2501.635205175788,
   75'\nAUCROC =',0.43950726692662173,
   76'\nAUCPR =', 0.4962773673721876],St1),
   77writeln(St1).
   78
   79test(par_test_carc):-
   80  set_lift(threads,2),
   81  in(P),test_lift(P,[all],LL,AUCROC,_ROC,AUCPR,_PR),
   82writeln('Result:'),
   83writeln(P),
   84atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
   85writeln(St),
   86atomic_list_concat(['Expected:\n', 
   87'\nLL =', -2501.635205175788,
   88'\nAUCROC =',0.43950726692662173,
   89'\nAUCPR =', 0.4962773673721876],St1),
   90writeln(St1).
   91
   92test(sort_carc):-
   93  in(P),sort_rules(P,P1),
   94  subset(P,P1),
   95  subset(P1,P).
   96
   97test(filter_carc):-
   98  in(P),filter_rules(P,P1),
   99  subset(P,P1).
  100
  101test(filter_rules_carc):-
  102  filter_rules([rule(_Name,[_H:0.0,_],_B,_L)],[]).
  103
  104test(remove_zero_rule):-
  105  remove_zero([rule(_Name,[_H:0.0,_],_B,_L)],[]).
  106
  107test(remove_zero):-
  108  remove_zero([(_H:0.0 :- _)],[]).
  109
  110test(induce_par_carc):-
  111  set_lift(verbosity,0),
  112  induce_par_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  113  writeln('Result:'),
  114  writeln(P),
  115  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  116  writeln(St),
  117  atomic_list_concat(['Expected:\n',
  118  '\nLL =', -26.41604269110072,
  119  '\nAUCROC =',0.6710526315789473,
  120  '\nAUCPR =', 0.5989337661969046],St1),
  121  writeln(St1).
  122  
  123test(induce_par_gd_carc):-
  124  set_lift(verbosity,0),
  125  set_lift(parameter_learning,gd),
  126  set_lift(eta,0.01),
  127  induce_par_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  128  writeln('Result:'),
  129  writeln(P),
  130  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  131  writeln(St),
  132  atomic_list_concat(['Expected:\n',
  133  '\nLL =', -26.433804567011133,
  134  '\nAUCROC =',0.6710526315789473,
  135  '\nAUCPR =', 0.5989337661969046],St1),
  136  writeln(St1).
  137
  138:- end_tests(carc).  139
  140:- begin_tests(mondial, []).  141:-ensure_loaded(library(examples_lift/mondial)).  142:-use_module(library(cplint_test/cplint_test)).  143
  144
  145
  146
  147test(ranked_answers_mondial):-
  148  ranked_answers(christian_religion(f1,C),C,E),
  149  E=[-(0.409107,'XMAS'),-(0.409107,'WS'),-(0.409107,'WAFU'),-(0.409107,'VU'),-(0.409107,'TUV'),-(0.409107,'TO'),-(0.409107,'SLB'),-(0.409107,'RI'),-(0.409107,'REUN'),-(0.409107,'PNG'),-(0.409107,'PITC'),-(0.409107,'PAL'),-(0.409107,'NZ'),-(0.409107,'NORF'),-(0.409107,'NMIS'),-(0.409107,'NIUE'),-(0.409107,'NCA'),-(0.409107,'NAU'),-(0.409107,'MH'),-(0.409107,'KIR'),-(0.409107,'HELX'),-(0.409107,'GUAM'),-(0.409107,'FSM'),-(0.409107,'FPOL'),-(0.409107,'FJI'),-(0.409107,'COOK'),-(0.409107,'COCO'),-(0.409107,'AUS'),-(0.409107,'AMSA')].
  150
  151test(induce_mondial):-
  152  set_lift(verbosity,0),
  153  induce_lift([f1,f2,f3,f4],P),test_lift(P,[f5],LL,AUCROC,_ROC,AUCPR,_PR),
  154  writeln('Result:'),
  155  writeln(P),
  156  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  157  writeln(St),
  158  atomic_list_concat(['Expected:\n', 
  159  '\nLL =', -27.553592935066412,
  160  '\nAUCROC =',0.7250000000000001,
  161  '\nAUCPR =', 0.8568357523414214],St1),
  162  writeln(St1).
  163
  164test(induce_conc_mondial):-
  165  set_lift(verbosity,0),
  166  set_lift(threads,2),
  167  induce_lift([f1,f2,f3,f4],P),test_lift(P,[f5],LL,AUCROC,_ROC,AUCPR,_PR),
  168  writeln('Result:'),
  169  writeln(P),
  170  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  171  writeln(St),
  172  atomic_list_concat(['Expected:\n', 
  173  '\nLL =', -27.553592935066412,
  174  '\nAUCROC =',0.7250000000000001,
  175  '\nAUCPR =', 0.8568357523414214],St1),
  176  writeln(St1).
  177
  178test(prob_lift_sv_mondial):-
  179  set_lift(single_var,true),
  180  prob_lift(christian_religion(f1,C),P),
  181  C='AMSA',P=:=0.409107,!.
  182
  183:- end_tests(mondial).  184
  185:- begin_tests(muta, []).  186:-ensure_loaded(library(examples_lift/muta)).  187:-use_module(library(cplint_test/cplint_test)).  188
  189test(in_muta):-
  190  in(P),test_lift(P,[10],LL,AUCROC,_ROC,AUCPR,_PR),
  191writeln('Result:'),
  192writeln(P),
  193atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  194writeln(St),
  195atomic_list_concat(['Expected:\n', 
  196'\nLL =', -67.3970487803363,
  197'\nAUCROC =',0.46212121212121215,
  198'\nAUCPR =', 0.6901758247756261],St1),
  199writeln(St1).
  200
  201test(induce_par_muta):-
  202  set_lift(verbosity,0),
  203  induce_par_lift([1,2,3,4,5,6,7,8,9],P),test_lift(P,[10],LL,AUCROC,_ROC,AUCPR,_PR),
  204  writeln('Result:'),
  205  writeln(P),
  206  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  207  writeln(St),
  208  atomic_list_concat(['Expected:\n',
  209  '\nLL =',-50.3968461506984,
  210  '\nAUCROC =',0.4924242424242425,
  211  '\nAUCPR =', 0.7123209210586535],St1),
  212  writeln(St1).
  213
  214test(induce_par_gd_muta):-
  215  set_lift(verbosity,0),
  216  set_lift(parameter_learning,gd),
  217  set_lift(eta,0.01),
  218  induce_par_lift([1,2,3,4,5,6,7,8,9],P),test_lift(P,[10],LL,AUCROC,_ROC,AUCPR,_PR),
  219  writeln('Result:'),
  220  writeln(P),
  221  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  222  writeln(St),
  223  atomic_list_concat(['Expected:\n',
  224  '\nLL =',-48.955482123491436,
  225  '\nAUCROC =',0.6287878787878788,
  226  '\nAUCPR =', 0.8184241612528028],St1),
  227  writeln(St1).
  228
  229
  230:- end_tests(muta).  231
  232
  233:- begin_tests(nba, []).  234:-ensure_loaded(library(examples_lift/nba)).  235:-use_module(library(cplint_test/cplint_test)).  236
  237test(induce_nba):-
  238  set_lift(verbosity,0),
  239  set_lift(regularization,no),
  240  induce_lift([f1,f2,f3,f4],P),test_lift(P,[f5],LL,AUCROC,_ROC,AUCPR,_PR),
  241  writeln('Result:'),
  242  writeln(P),
  243  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  244  writeln(St),
  245  atomic_list_concat(['Expected:\n', 
  246  '\nLL =', -42.17028441718049,
  247  '\nAUCROC =',0.625,
  248  '\nAUCPR =', 0.8189102564102563],St1),
  249  writeln(St1).
  250
  251test(induce_nba_l1):-
  252  set_lift(verbosity,0),
  253  set_lift(regularization,l1),
  254  induce_lift([f1,f2,f3,f4],P),test_lift(P,[f5],LL,AUCROC,_ROC,AUCPR,_PR),
  255  writeln('Result:'),
  256  writeln(P),
  257  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  258  writeln(St),
  259  atomic_list_concat(['Expected:\n', 
  260  '\nLL =', -49.7938188339248,
  261  '\nAUCROC =',0.625,
  262  '\nAUCPR =', 0.8189102564102563],St1),
  263  writeln(St1).
  264
  265test(induce_nba_l2):-
  266  set_lift(verbosity,0),
  267  set_lift(regularization,l2),
  268  induce_lift([f1,f2,f3,f4],P),test_lift(P,[f5],LL,AUCROC,_ROC,AUCPR,_PR),
  269  writeln('Result:'),
  270  writeln(P),
  271  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  272  writeln(St),
  273  atomic_list_concat(['Expected:\n', 
  274  '\nLL =', -43.57330116702434,
  275  '\nAUCROC =',0.625,
  276  '\nAUCPR =', 0.8189102564102563],St1),
  277  writeln(St1).
  278
  279test(induce_nba_bayesian):-
  280  set_lift(verbosity,0),
  281  set_lift(regularization,bayesian),
  282  induce_lift([f1,f2,f3,f4],P),test_lift(P,[f5],LL,AUCROC,_ROC,AUCPR,_PR),
  283  writeln('Result:'),
  284  writeln(P),
  285  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  286  writeln(St),
  287  atomic_list_concat(['Expected:\n', 
  288  '\nLL =', -47.070639401222,
  289  '\nAUCROC =',0.625,
  290  '\nAUCPR =', 0.8189102564102563],St1),
  291  writeln(St1).
  292
  293:- end_tests(nba).  294
  295:- begin_tests(bongard, []).  296:-ensure_loaded(library(examples_lift/bongard)).  297:-use_module(library(cplint_test/cplint_test)).  298
  299
  300test(explain_bongard):-
  301  explain_lift(pos(2),Expl),
  302  Expl=[0.197575-(circle(2, o3), inside(2, o2, o3)), 
  303  0.000448807-(triangle(2, o5), circle(2, o3)), 
  304  0.000448807-(triangle(2, o2), circle(2, o3)), 
  305  0.000448807-(triangle(2, o1), circle(2, o3))].
  306
  307test(in_bongard):-
  308  in(P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  309writeln('Result:'),
  310writeln(P),
  311atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  312writeln(St),
  313atomic_list_concat(['Expected:\n', 
  314'\nLL =', -250.33054186204907,
  315'\nAUCROC =',0.7626436781609195,
  316'\nAUCPR =', 0.5615465293941269],St1),
  317writeln(St1).
  318
  319
  320
  321test(induce_par_bongard):-
  322  set_lift(verbosity,1),
  323  induce_par_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  324  writeln('Result:'),
  325  writeln(P),
  326  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  327  writeln(St),
  328  atomic_list_concat(['Expected:\n',
  329  '\nLL =',-219.68079672612654,
  330  '\nAUCROC =',0.7501277139208173,
  331  '\nAUCPR =', 0.5997247517658881],St1),
  332  writeln(St1).
  333
  334
  335test(induce_bongard):-
  336  set_lift(verbosity,1),
  337  induce_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  338  writeln('Result:'),
  339  writeln(P),
  340  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  341  writeln(St),
  342  atomic_list_concat(['Expected:\n',
  343  '\nLL =',-102.73759622946764,
  344  '\nAUCROC =',0.7045977011494252,
  345  '\nAUCPR =', 0.4424569868032866],St1),
  346  writeln(St1).
  347
  348test(induce_conc_par_bongard):-
  349  set_lift(verbosity,1),
  350  set_lift(threads,2),
  351  induce_par_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  352  writeln('Result:'),
  353  writeln(P),
  354  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  355  writeln(St),
  356  atomic_list_concat(['Expected:\n',
  357  '\nLL =',-219.68079672612654,
  358  '\nAUCROC =',0.7501277139208173,
  359  '\nAUCPR =', 0.5997247517658881],St1),
  360  writeln(St1).
  361
  362test(induce_par_lbfgs_bongard):-
  363  set_lift(verbosity,4),
  364  set_lift(parameter_learning,lbfgs),
  365  set_lift(eta,0.01),
  366  induce_par_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  367  writeln('Result:'),
  368  writeln(P),
  369  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  370  writeln(St),
  371  atomic_list_concat(['Expected:\n',
  372  '\nLL =',-219.6533450232687,
  373  '\nAUCROC =',0.7501277139208173,
  374  '\nAUCPR =', 0.5997247517658881],St1),
  375  writeln(St1).
  376
  377test(induce_par_gd_bongard):-
  378  set_lift(verbosity,4),
  379  set_lift(parameter_learning,gd),
  380  set_lift(eta,0.01),
  381  induce_par_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  382  writeln('Result:'),
  383  writeln(P),
  384  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  385  writeln(St),
  386  atomic_list_concat(['Expected:\n',
  387  '\nLL =',-218.22925642272494,
  388  '\nAUCROC =',0.7485951468710089,
  389  '\nAUCPR =', 0.5979409655734421],St1),
  390  writeln(St1).
  391
  392test(induce_gd_bongard):-
  393  set_lift(verbosity,1),
  394  set_lift(parameter_learning,gd),
  395  set_lift(regularization, no),
  396  set_lift(eta,0.01),
  397  set_lift(gamma,0.1),
  398  induce_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  399  writeln('Result:'),
  400  writeln(P),
  401  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  402  writeln(St),
  403  atomic_list_concat(['Expected:\n',
  404  '\nLL =',-88.11894369013643,
  405  '\nAUCROC =',0.8199872286079184,
  406  '\nAUCPR =',0.6676162174173899],St1),
  407  writeln(St1).
  408
  409test(induce_gd_l1_bongard):-
  410  set_lift(verbosity,1),
  411  set_lift(parameter_learning,gd),
  412  set_lift(regularization, l1),
  413  set_lift(eta,0.01),
  414  set_lift(gamma,1),
  415  induce_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  416  writeln('Result:'),
  417  writeln(P),
  418  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  419  writeln(St),
  420  atomic_list_concat(['Expected:\n',
  421  '\nLL =',-86.45340693767905,
  422  '\nAUCROC =',0.8247126436781609,
  423  '\nAUCPR =', 0.6620667885942804],St1),
  424  writeln(St1).
  425
  426test(induce_gd_l2_bongard):-
  427  set_lift(verbosity,1),
  428  set_lift(parameter_learning,gd),
  429  set_lift(regularization, l2),
  430  set_lift(eta,0.01),
  431  set_lift(gamma,1),
  432  induce_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  433  writeln('Result:'),
  434  writeln(P),
  435  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  436  writeln(St),
  437  atomic_list_concat(['Expected:\n',
  438  '\nLL =',-87.36727076138638,
  439  '\nAUCROC =',0.8188378033205619,
  440  '\nAUCPR =', 0.6550280976471973],St1),
  441  writeln(St1).
  442
  443
  444test(induce_par_gd_adam_bongard):-
  445  set_lift(verbosity,1),
  446  set_lift(parameter_learning,gd),
  447  set_lift(parameter_update, adam),
  448  set_lift(gamma,1),
  449  set_lift(iter,20),
  450  set_lift(adam_params,[0.2,0.8,0.9,1e-8]),
  451  induce_par_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  452  writeln('Result:'),
  453  writeln(P),
  454  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  455  writeln(St),
  456  atomic_list_concat(['Expected:\n',
  457  '\nLL =',-218.57571674633985,
  458  '\nAUCROC =',0.7485951468710089,
  459  '\nAUCPR =', 0.5979409655734421],St1),
  460  writeln(St1).
  461
  462test(prob_bongard):-
  463  prob_lift(pos(2),P),
  464  P=:=0.1986549170515436.
  465
  466test(prob_sv_bongard):-
  467  set_lift(single_var,true),
  468  prob_lift(pos(2),P),
  469  writeln(P),
  470  P=:=0.19793513395697515.
  471
  472test(induce_par_single_var_bongard):-
  473  set_lift(verbosity,1),
  474  set_lift(single_var,true),
  475  induce_par_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  476  writeln('Result:'),
  477  writeln(P),
  478  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  479  writeln(St),
  480  atomic_list_concat(['Expected:\n',
  481  '\nLL =',-219.68079672612654,
  482  '\nAUCROC =',0.7501277139208173,
  483  '\nAUCPR =', 0.5997247517658881],St1),
  484  writeln(St1).
  485
  486test(induce_single_var_bongard):-
  487  set_lift(verbosity,1),
  488  set_lift(single_var,true),
  489  induce_lift([train],P),test_lift(P,[test],LL,AUCROC,_ROC,AUCPR,_PR),
  490  writeln('Result:'),
  491  writeln(P),
  492  atomic_list_concat(['\nLL=',LL,'\nAUCROC=',AUCROC,'\nAUCPR=',AUCPR,'\n'],St),
  493  writeln(St),
  494  atomic_list_concat(['Expected:\n',
  495  '\nLL =',-219.68079672612654,
  496  '\nAUCROC =',0.7501277139208173,
  497  '\nAUCPR =', 0.5997247517658881],St1),
  498  writeln(St1).
  499
  500:- end_tests(bongard).