1% MODULE gencon EXPORTS 2:- module(gencon, 3 [ gilppi/12,gilppi/14 4 ]). 5 6 7 8% METAPREDICATES 9:- meta_predicate gilppi( , , , , , , , , , , , ), 10 gilppi( , , , , , , , , , , , , , ). 11 12 13% IMPORTS 14:- use_module(home(kb), 15 [store_clauses/2]). 16:- use_module(home(show_utils),[write_list/1,show_kb/0]). 17 18%*********************************************************************** 19%* 20%* module: gilppi.pl 21%* 22%* author: I.Stahl date:7/93 23%* 24%* description: generic control for induction a la GENCOL 25%* enhanced with PI capabilties 26%* Given: B, E+, E- 27%* Algorithm: 28%* Partial_Sols := initialize() 29%* Complete_Sols := {} 30%* while not(Stop_C(Complete_Sols)) do 31%* PS := Select(Partial_Sols) 32%* if Quality_C(PS) 33%* then Complete_Sols := Complete_Sols U {PS} 34%* Partial_Sols := Update(Partial_Sols) 35%* else if active(PS) 36%* then One_of(->Partial_Sols := Add(Partial_Sols,Spec(PS)) 37%* ->Partial_Sols := Add(Partial_Sols,Spec(PS))) 38%* all PS in spec(PS) (gen(PS)) marked active 39%* else Partial_Sols := Add(Partial_Sols,L_Newp(PS)) 40%* mark PS as passive 41%* Partial_Sols := Filter(Partial_Sols) 42%* Output(Complete_Sols) 43%* 44%* see also: 45%* 46%*********************************************************************** 47 48 49 50%*********************************************************************** 51%* 52%* predicates: gilppi/12 53%* 54%* syntax: gilppi(+Initialize, +Stop_C, +Quality_C, +Update, +Select, +Add, +Filter, 55%* +One_of, +Spec, +Gen, +L_newp, +Output) 56%* 57%* args: Initialize... name of a 1-place predicate that initializes the list 58%* of partial solutions 59%* Stop_C... name of a 1-place predicate that checks whether complete_sols 60%* contains a satisfactory solution 61%* Quality_C... name of a 1-place predicate that checks whether the current 62%* theory PS is satisfactory 63%* Update... name of a 2-place predicate that updates the list of partial 64%* solutions after a satisfactory solution has been found 65%* Select... name of a 4-place predicate that selects a promising partial 66%* solution from partial_sols 67%* Add... name of a 3-place predicate that adds the new partial solutions 68%* to the list partial_sols 69%* Filter... name of a two-place predicate that filters the most promising 70%* among partial_sols 71%* One_of... name of a two-place predicate that decides whether the current 72%* theory PS should be generalised or specialised 73%* Spec... name of a 2-place predicate that determines all specialisations 74%* of the current theory PS wrt the bias 75%* Gen... name of a 2-place predicate that determines all generalisations 76%* of the current theory PS wrt the bias 77%* L_newp... name of a 14-place predicate, the actual PI-module 78%* Output... name of a 1-place predicate that outputs the complete solutions 79%* 80%* 81%* description: implements a generic ILP algorithm (cf GENCOL) with PI capabilities 82%* the actual learning algorithm depends on the implementations of 83%* the argument predicates 84%* 85%* example: 86%* 87%*********************************************************************** 88 89 90gilppi(Initialize, Stop_C, Quality_C, Update, Select, Add, Filter, 91 One_of, Spec, Gen, L_newp,Output):- 92 c_call(Initialize,[Partial_Sols]), 93 gilppi(Partial_Sols, [], Initialize, Stop_C, Quality_C, Update, Select, 94 Add, Filter, One_of, Spec, Gen, L_newp,Output). 95 96 97gilppi(_, Complete_Sols, _, Stop_C, _, _, _, _, _, _, _, _, _,Output):- 98 c_call(Stop_C, [Complete_Sols]),!, 99 c_call(Output,[Complete_Sols]). 100 101gilppi(Partial_Sols, Complete_Sols, Initialize, Stop_C, Quality_C, Update, Select, 102 Add, Filter, One_of, Spec, Gen, L_newp,Output):- 103 c_call(Select, [Partial_Sols, PS, M, Partial_Sols1]), 104 ( c_call(Quality_C, [PS]) -> 105 c_call(Update,[Partial_Sols1,Partial_Sols2]), 106 gilppi(Partial_Sols2, [PS|Complete_Sols], Initialize, Stop_C, Quality_C, 107 Update,Select, Add, Filter, One_of, Spec, Gen, L_newp,Output) 108 ; ( M == active -> 109 c_call(One_of, [PS, GS]), 110 ( GS == spec -> 111 write('Specialising'),nl,write_list(PS),nl,nl, 112 c_call(Spec, [PS, PSL]) 113 ; write('Generalising'),nl,write_list(PS),nl,nl, 114 c_call(Gen, [PS, PSL]) 115 ) 116 ; c_call(L_newp,[PS,PSL, Initialize, Stop_C, Quality_C, Update, 117 Select, Add, Filter, One_of, Spec, Gen, L_newp,Output]) 118 ), 119 c_call(Add, [Partial_Sols1, PSL, Partial_Sols2]), 120 c_call(Filter, [Partial_Sols2, Partial_Sols3]), 121 gilppi(Partial_Sols3, Complete_Sols, Initialize, Stop_C, Quality_C, Update, 122 Select, Add, Filter, One_of, Spec, Gen, L_newp,Output) 123 ). 124 125 126c_call(MPred,Arglist):- 127 c_mod(MPred,M,Pred), 128 Call =.. [Pred|Arglist], 129 call(M:Call). 130 131c_mod(M:Pred,M,Pred):- 132 simple(Pred),!. 133c_mod(_:P,M1,Pred):- 134 !,c_mod(P,M1,Pred)