(defstruct range-details feature range size details) (defun splitter (x &key baseline detail debug (compare #'-) (overall #'range-details-weighted-sum)) (let (best (max -1) (classi (xindex-classi x)) (before (funcall baseline x))) (dotimes (feature (xindex-width x) best) (unless (= feature classi) (let* ((after (range-details-all feature x :detail detail :overall overall)) (delta (funcall compare before after))) (if debug (o feature delta)) (if (> delta max) (setf max delta best feature ))))))) (defun range-details-all (feature x &key detail overall) (let ((details (mapcar #'(lambda(range) (range-details-one feature range x detail)) (xindex-feature feature x)))) (funcall overall details feature x))) (defun range-details-one (feature range x detail) "collect information on one range" (let ((n (xindex-unique-n x feature range ))) (make-range-details :feature feature :range range :size n :details (funcall detail feature range n x)))) (defun range-details-weighted-sum (details feature x) "return the weighted sum of the details weighted sum" (let* ((total 0) (weights (mapcar #'(lambda (d) (let ((tmp (range-details-size d))) (incf total tmp) (cons tmp (range-details-details d)))) details))) (weighted-sum weights total)))