;(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) (bestlist nil) (bestval 0) (ctr -1) ;;(hashie (make-hash-table :test 'equalp)) (cutoffscore 0) (prob.bstbin 0) (prob.rstbin 0)) (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)) ;;(format t "bucket/binlist:~A~%" bucket.list) (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)))))))) ;;(format t"~%~%~A~%~%" 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)) (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)))))))))))) ;;(print bucket.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 demo-seheult () (asterisk (efbin (random-seheult 10000)))) (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)))