(defun Train (ruleset noiseLevel numoforig RuleGenerator 1p global fmod &optional (level 0)) (gc :full t) ;(format t "(~A" level) (if (or (not 1p) (null (RDRule-parent ruleset))) ;(if (or (> (xindex-ns (RDRule-bad ruleset)) (ceiling (* numoforig noiseLevel))) (> (xindex-ns (RDRule-bad ruleset)) 5)) (if (> (xindex-ns (RDRule-bad ruleset)) 5) (progn ;(format t "t" level) (setf (RDRule-true ruleset) (funcall RuleGenerator ruleset (RDRule-good ruleset) (RDRule-bad ruleset) global fmod)) (let ((tmp (RDRule-true ruleset))) (setf (RDRule-ugly tmp) (cross-index (table-copy (xindex-table (RDRule-bad ruleset)) (mapcar #'(lambda (x) (eg-features x)) (remove-if (RDRule-fn tmp) (table-rows (xindex-table (RDRule-bad ruleset)))))))) (setf (RDRule-good tmp) (cross-index (table-copy (xindex-table (RDRule-bad ruleset)) (mapcar #'(lambda (x) (eg-features x)) (remove-if-not #'(lambda (x) (equal (eg-class x) (RDRule-class tmp))) (remove-if-not (RDRule-fn tmp) (table-rows (xindex-table (RDRule-bad ruleset))))))))) (setf (RDRule-bad tmp) (cross-index (table-copy (xindex-table (RDRule-bad ruleset)) (mapcar #'(lambda (x) (eg-features x)) (remove-if #'(lambda (x) (equal (eg-class x) (RDRule-class tmp))) (remove-if-not (RDRule-fn tmp) (table-rows (xindex-table (RDRule-bad ruleset))))))))) (Train tmp noiseLevel numoforig RuleGenerator 1p global fmod (1+ level)))))) ;(if (or (> (xindex-ns (RDRule-ugly ruleset)) (ceiling (* numoforig noiseLevel))) (> (xindex-ns (RDRule-ugly ruleset)) 5)) (if (> (xindex-ns (RDRule-ugly ruleset)) 5) (progn ;(format t "f" level) ;(setf (RDRule-false ruleset) (funcall RuleGenerator ruleset (cross-index (table-copy (xindex-table (RDRule-bad ruleset)) nil)) (RDRule-ugly ruleset) global fmod)) (setf (RDRule-false ruleset) (funcall RuleGenerator ruleset (RDRule-good ruleset) (RDRule-ugly ruleset) global fmod)) (let ((tmp (RDRule-false ruleset))) (setf (RDRule-ugly tmp) (cross-index (table-copy (xindex-table (RDRule-bad ruleset)) (mapcar #'(lambda (x) (eg-features x)) (remove-if (RDRule-fn tmp) (table-rows (xindex-table (RDRule-ugly ruleset)))))))) (setf (RDRule-good tmp) (cross-index (table-copy (xindex-table (RDRule-ugly ruleset)) (mapcar #'(lambda (x) (eg-features x)) (remove-if-not #'(lambda (x) (equal (eg-class x) (RDRule-class tmp))) (remove-if-not (RDRule-fn tmp) (table-rows (xindex-table (RDRule-ugly ruleset))))))))) (setf (RDRule-bad tmp) (cross-index (table-copy (xindex-table (RDRule-ugly ruleset)) (mapcar #'(lambda (x) (eg-features x)) (remove-if #'(lambda (x) (equal (eg-class x) (RDRule-class tmp))) (remove-if-not (RDRule-fn tmp) (table-rows (xindex-table (RDRule-ugly ruleset))))))))) (Train tmp noiseLevel numoforig RuleGenerator 1p global fmod (1+ level))))) ;(format t ")") (setf (RDRule-good ruleset) nil) (setf (RDRule-bad ruleset) nil) (setf (RDRule-ugly ruleset) nil) ruleset) (deftest test-Train () (check (samep (Train (make-RDRule :comment "Top Rule" :class (xindex-majority-class (cross-index (make-data3))) :bad (cross-index (make-data3)) :good (cross-index (table-copy (make-data3) nil)) :ugly (cross-index (table-copy (make-data3) nil)) :fn #'(lambda (x) (not (null x)))) .1 (counted-n (table-all (make-data3))) #'GenerateRuleMatchNB) "#(TRUE:#(TRUE:NIL, FALSE:#(TRUE:NIL, FALSE:#(TRUE:NIL, FALSE:NIL, CLASS:F, FN-SET:T, GOOD:1, BAD:0, UGLY:1, COMMENT:(F 0 NO)) , CLASS:H, FN-SET:T, GOOD:1, BAD:0, UGLY:2, COMMENT:(H 0 MAYBE)), CLASS:E, FN-SET:T, GOOD:1, BAD:0, UGLY:3, COMMENT:(E 0 YES)), FALSE:NIL, CLASS:E, FN-SET:T, GOOD:0, BAD:4, UGLY:0, COMMENT:Top Rule)")))