;Code's Author: Jamie Wood (defun hyperpipe (&optional (tbl (thetable))) (trainHP tbl) ) (defun trainHP (&optional (tbl (thetable))) (dolist (row (therows tbl)) (how-manysHP (thecols tbl) ; get the column headers (row-cells row) ; get the cells (row-class row) ; get the class of this row ))) (defun testHP (&optional (tbl (thetable))) (let ((pred (list))) (dolist (row (therows tbl)) (setf pred (append pred (list (mostcontained row (thecols tbl)))))) pred )) (defun how-manysHP (cols cells class) (labels ((worker (col cell) (how-manyHP class (col-name col) cell (if (typep col 'sym) (sym-counts col) col) ))) (mapcar #'worker cols cells))) ; run down cols and cells in parallel (defun how-manyHP (class what cell hash) (when (knownp cell) ; skip any cell labelled "?" (unless (eq class cell) (if (typep hash 'num) (inchNum `(,class ,what) cell hash) (inchSym `(,class ,what ,cell) hash))))) (defun inchSym (key hash) "increment a hash bucket from zero" (incf (gethash key hash 0) 1)) (defun inchNum (key val col) (if (> val (num-max col)) (setf (num-max col) val)) (if (< val (num-min col)) (setf (num-min col) val)) (if (> val (gethash key (num-maxs col) most-negative-fixnum)) (setf (gethash key (num-maxs col) most-negative-fixnum) val)) (if (< val (gethash key (num-mins col) most-positive-fixnum)) (setf (gethash key (num-mins col) most-positive-fixnum) val)) ) (defun contains (class what col val) (let ((ret 0)) ;;(format t "DBG::: ~a ~a ~a ~%" class what val) (if (typep col 'num) (progn (if (and (< val (gethash `(,class ,what) (num-maxs col))) (> val (gethash `(,class ,what) (num-mins col)))) (setf ret 1))) (progn (if (> (gethash `(,class ,what ,val) (sym-counts col) 0)) (setf ret 1)))) ret)) (defun mostcontained (row cols) (let ((what) (best -1) (count 0) (i 0) (col)) (dolist (class (theklasses)) (setf count 0) (setf i 0) (dolist (cell (row-cells row)) (setf col (nth i cols)) (unless (col-goalp col) (when (knownp cell) (progn (incf count (contains (klass-name class) (col-name col) col cell)) ))) (incf i)) (format t "Class: ~5a Count: ~3a ~%" (klass-name class) count) (if (> count best) (progn (setf best count) (setf what (klass-name class))))) what)) (defun !how-manysHP () (reset-seed) (data "../data/numeric-lisp/weatherN.lisp") (trainHP (thetable)) (with-output-to-string (s) (dolist (col (thecols)) (if (typep col 'num) (progn (showh (num-mins col) :stream s) (showh (num-maxs col) :stream s)) (print col)) )))