1/* 
    2The task is to decide whether a machine should be fixed, sent back or is ok.
    3Machines dataset from The ACE Data Mining System User's Manual
    4https://dtai.cs.kuleuven.be/ACE/doc/ACEuser-1.2.16.pdf
    5
    6Downloaded from 
    7https://dtai.cs.kuleuven.be/static/ACE/doc/
    8*/

?- induce_lm([train],P),test_lm(P,[test],LL,AUCROC,ROC,AUCPR,PR). ?- induce_lm([train],P). */

   15:-use_module(library(lemur)).   16
   17:- if(current_predicate(use_rendering/1)).   18:- use_rendering(c3).   19:- use_rendering(lpad).   20:- endif.   21
   22:-lemur.   23
   24:- set_lm(depth_bound,false).   25:- set_lm(neg_ex,given).   26:- set_lm(mcts_iter,20).   27:- set_lm(verbosity,1).   28
   29
   30:- begin_in.   31class(sendback):0.5 :-
   32  worn(A),
   33  not_replaceable(A).
   34
   35class(fix):0.6 :-
   36  worn(A),
   37  replaceable(A).
   38
   39class(ok):0.5 :-
   40  not_worn(_A).
   41:- end_in.  
   42
   43:- begin_bg.   44component(C):-
   45  replaceable(C).
   46component(C):-
   47  not_replaceable(C).
   48replaceable(gear).
   49replaceable(wheel).
   50replaceable(chain).
   51not_replaceable(engine).
   52not_replaceable(control_unit).
   53not_worn(C):-
   54  component(C),
   55  \+ worn(C).
   56one_worn:-
   57  worn(_).
   58none_worn:-
   59  \+ one_worn.
   60:- end_bg.   61
   62fold(train,[1,2,3,4,5,6,7,8,9,10]).
   63
   64fold(test,[11,12,13,14,15]).
   65
   66fold(all,F):-
   67  fold(train,FTr),
   68  fold(test,FTe),
   69  append(FTr,FTe,F).
   70
   71:- fold(all,F),
   72   sample(10,F,FTr,FTe),
   73   assert(fold(rand_train,FTr)),
   74   assert(fold(rand_test,FTe)).   75
   76output(class_fix/0).
   77output(class_sendback/0).
   78output(class_ok/0).
   79
   80input_cw(replaceable/1).
   81input_cw(not_replaceable/1).
   82input_cw(worn/1).
   83input_cw(not_worn/1).
   84input_cw(none_worn/0).
   85input(class/1).
   86
   87determination(class/1,replaceable/1).
   88determination(class/1,not_replaceable/1).
   89determination(class/1,worn/1).
   90determination(class/1,not_worn/1).
   91determination(class/1,none_worn/0).
   92
   93class_fix(M):-
   94  class(M,fix).
   95
   96class_sendback(M):-
   97  class(M,sendback).
   98
   99class_ok(M):-
  100  class(M,ok).
  101
  102neg(class_fix(M)):-
  103  neg(class(M,fix)).
  104
  105neg(class_sendback(M)):-
  106  neg(class(M,sendback)).
  107
  108neg(class_ok(M)):-
  109  neg(class(M,ok)).
  110
  111modeh(*,class_fix).
  112modeh(*,class_ok).
  113modeh(*,class_sendback).
  114
  115
  116/*modeh(*,[class(fix),class(ok),class(sendback)],
  117  [class(fix),class(ok),class(sendback)],
  118  [replaceable/1,not_replaceable/1,worn/1]).
  119*/
  120
  121modeb(*,not_replaceable(-comp)).
  122modeb(*,replaceable(-comp)).
  123modeb(*,worn(-comp)).
  124modeb(*,not_worn(-comp)).
  125modeb(*,none_worn).
  126
  127begin(model(1)).
  128testnr(1).
  129class(sendback).
  130neg(class(fix)).
  131neg(class(ok)).
  132worn(gear).
  133worn(engine).
  134end(model(1)).
  135
  136begin(model(2)).
  137testnr(2).
  138class(ok).
  139neg(class(sendback)).
  140neg(class(fix)).
  141end(model(2)).
  142
  143begin(model(3)).
  144testnr(3).
  145class(fix).
  146neg(class(sendback)).
  147neg(class(ok)).
  148worn(gear).
  149end(model(3)).
  150
  151begin(model(4)).
  152testnr(4).
  153class(sendback).
  154neg(class(fix)).
  155neg(class(ok)).
  156worn(engine).
  157end(model(4)).
  158
  159begin(model(5)).
  160testnr(5).
  161class(fix).
  162neg(class(sendback)).
  163neg(class(ok)).
  164worn(gear).
  165worn(chain).
  166end(model(5)).
  167
  168begin(model(6)).
  169testnr(6).
  170class(fix).
  171neg(class(sendback)).
  172neg(class(ok)).
  173worn(wheel).
  174end(model(6)).
  175
  176begin(model(7)).
  177testnr(7).
  178class(sendback).
  179neg(class(fix)).
  180neg(class(ok)).
  181worn(wheel).
  182worn(control_unit).
  183end(model(7)).
  184
  185begin(model(8)).
  186testnr(8).
  187class(ok).
  188neg(class(sendback)).
  189neg(class(fix)).
  190end(model(8)).
  191
  192begin(model(9)).
  193testnr(9).
  194class(fix).
  195neg(class(sendback)).
  196neg(class(ok)).
  197worn(wheel).
  198worn(chain).
  199end(model(9)).
  200
  201begin(model(10)).
  202testnr(10).
  203class(sendback).
  204neg(class(fix)).
  205neg(class(ok)).
  206worn(engine).
  207worn(chain).
  208end(model(10)).
  209
  210begin(model(11)).
  211testnr(11).
  212class(sendback).
  213neg(class(fix)).
  214neg(class(ok)).
  215worn(engine).
  216worn(control_unit).
  217end(model(11)).
  218
  219begin(model(12)).
  220testnr(12).
  221class(fix).
  222neg(class(sendback)).
  223neg(class(ok)).
  224worn(chain).
  225worn(wheel).
  226worn(gear).
  227end(model(12)).
  228
  229begin(model(13)).
  230testnr(13).
  231class(sendback).
  232neg(class(fix)).
  233neg(class(ok)).
  234worn(chain).
  235worn(wheel).
  236worn(gear).
  237worn(engine).
  238end(model(13)).
  239
  240begin(model(14)).
  241testnr(14).
  242class(ok).
  243neg(class(sendback)).
  244neg(class(fix)).
  245end(model(14)).
  246
  247begin(model(15)).
  248testnr(15).
  249class(fix).
  250neg(class(sendback)).
  251neg(class(ok)).
  252worn(wheel).
  253worn(gear).
  254end(model(15))