(defun dist-median (d) (dist-sort d) (print 1) (let* ((n (dist-n d)) (place 0) 50percent 75percent (50place (round (* n 0.5 ))) (75place (round (* n 0.75)))) (print (list :50p 50place :75p 75place)) (dolist (bar (dist-bars d)) (let ((key (car bar)) (value (cdr bar))) (print 3) (incf place value) (list key value place) (when (eql place 50place) (setf 50percent key)) (when (eql place 75place) (setf 75percent key)) (print place) )) (print place) (print (list :50 50percent :75 75percent)) (values 50percent (- 75percent 50percent)))) (defun dist-median-example () (let ((log (make-dist :fuzz 4))) (dotimes (i 100) (dotimes (i 20) (dist-add i log))) (distogram log :shrink 20) (multiple-value-bind (mid spread) (dist-median log) (list :median mid :spread spread)))) ;bits and piece sof old oding ideas (defun @ (key what) (let ((x (geta key (db-! *db*)))) (case (type-of x) (symbol x) (single-float x) (integer x) (bag (@bag x what)) (num (@num x what)) (sf (@sf x what)) (dr (@dr x what)) (em (@em x what)) (otherwise (warn "can't handle ~a of type ~a" x (type-of x)))))) ; cache in some, keep in all ;; (defun ==1 (key new old) ;; (if ;; (subsetp new old) ;; (setf *some* (seta key *some* new)) ;; (warn "~a won't fit in ~a" new old))) ;; (defun == (key constraint ;; &optional (*all* *all*) (*some* *some*) (*cache* *cache*)) ;; (let* ((constraints1 (coco (as-list constraint))) ;; (meta (geta key *all*))) ;; (typecase meta ;; (null (warn "~a not known" key)) ;; (bag (==1 key constraints1 ;; (bag-range ;; (bag-range meta)))) ;; (otherwise (warn "~a: can't 'is' on unknown type" meta))))) ;;; traffic cop, calls the right sub-sniffer