;(defstruct fancy (progn (load "efbin.lisp") (load "randomseheult.lisp")) (defmacro while (test &body body) `(loop (when (not ,test) (return)) ,@body)) (defun asterisk (datalist &optional (part.best .1)); (num.to.report 1)) "alist is assumed to be fancy-pants etc. Returns a 2D list of size num.to.report." (labels ((get-bins (alist cutoff) (let ((blist ()) (tlist ()) (temp ())) (dotimes (i (- (list-length (car alist)) 1)) (dolist (row alist) (setf temp (find (nth i row) tlist :key #'(lambda (x) (car x)))) ; (if (> (car (last row)) 0) ; (print 'here!)) (if (not temp) (if (>= (car (last row)) cutoff) (setf tlist (append tlist (list (list (nth i row) 1 0 0)))) (setf tlist (append tlist (list (list (nth i row) 0 1 0))))) (if (>= (car (last row)) cutoff) (incf (second temp)) (incf (third temp))))) (setf blist (append blist `(,tlist)) tlist ())) blist))) (let* ((alist (copy-list datalist)) (first.row.a (pop alist)) (total (list-length alist)) (bucket.list 0) (newlist nil) (min most-positive-fixnum) (max (* -1 most-positive-fixnum)) (cutoffscore 0) (prob.bstbin 0) (prob.rstbin 0) (h (make-hash-table))) (setf alist (sort alist #'> :key #'(lambda (x) (car (last x))))) (setf cutoffscore (/ (+ (car (last (nth (floor (* total part.best)) alist))) (car (last (nth (+ 1 (floor (* total part.best))) alist)))) 2)) ;;(format t "cutoff:~A~%" cutoffscore) ;(print alist) (while (>= (car (last (nth prob.bstbin alist))) cutoffscore) (incf prob.bstbin)) ;;(print 'hello) (setf prob.bstbin (/ prob.bstbin total)) (setf prob.rstbin (- 1 prob.bstbin)) ;;(format t "best:~A rest:~A~%" prob.bstbin prob.rstbin) (setf bucket.list (get-bins alist cutoffscore)) (dolist (col.list bucket.list) (dolist (col.row col.list) (setf (fourth col.row) (float (/ (expt (* (/ (second col.row) prob.bstbin) (/ prob.bstbin total)) 2) (+ (* (/ (second col.row) prob.bstbin) (/ prob.bstbin total)) (* (/ (third col.row) prob.rstbin) (/ prob.rstbin total)))))))) ;(print bucket.list) (dolist (col.list bucket.list) (setf newlist (append newlist (list (sort col.list #'> :key #'(lambda (x) (car (last x)))))))) (setf bucket.list (copy-list newlist)) (dotimes (i (length bucket.list)) (if (> (car (last (first (nth i bucket.list)))) max) (setf max (car (last (first (nth i bucket.list)))))) (if (< (car (last (car (last (last (nth i bucket.list)))))) min) (setf min (car (last (car (last (last (nth i bucket.list))))))))) (format t "~A ~A~%" min max) (dolist (col.list bucket.list) (dolist (col.row col.list) (setf (car (last col.row)) (/ (- (car (last col.row)) min) (- max min))))) (dotimes (i (- (length first.row.a) 1)) (setf (gethash (nth i first.row.a) h) (mapcar #'(lambda (l) (append (parse-vals (car l)) (cdr l))) (nth i bucket.list)))) h))) #| ;;(dotimes (i (list-length bucket.list)) ;;(format t "~A:~A~%" (nth i first.row.a) (nth i bucket.list))) (dolist (col.list bucket.list) (incf ctr) (dotimes (i num.to.report) (if (< bestval (car (last (nth i col.list)))) (setf bestval (car (last (nth i col.list))) bestlist ;;(append bestlist (list (list (nth ctr first.row.a) (read-from-string (subseq (car (nth i col.list)) 0 (search "to" (car (nth i col.list))))) (read-from-string (subseq (car (nth i col.list)) (+ 2 (search "to" (car (nth i col.list))))))))))))|# #| bestlist|# (defun demo-asterisk () (asterisk '((married age money happiness) (yes 25 50 87) (yes 40 20 25) (no 65 100 15) (no 10 0 83) (no 7 0 76) (no 30 50 70) (yes 35 20 63) (no 44 80 33) (no 24 80 68) (yes 24 80 70)))) (defun parse-vals (str) (list (read-from-string (subseq str 0 (search "to" str))) (read-from-string (subseq str (+ 2 (search "to" str)))))) (defun demo-seheult () (let ((x (asterisk (efbin (random-seheult 10000))))) x)) (defun csl (&optional (randomcall (random-seheult 10000 1.4 1.6 1.4 1.6 1 25 1.5181932 15.181932 0.0036737733 0.036737733))) (asterisk (efbin randomcall)))