Changeset 39739 in project


Ignore:
Timestamp:
03/18/21 18:12:29 (5 weeks ago)
Author:
Kon Lovett
Message:

sample dist (wip)

Location:
release/5/micro-stats/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/5/micro-stats/trunk/micro-stats.egg

    r39737 r39739  
    11((synopsis "Easily create micro-stats")
    2  (version "0.0.3")
     2 (version "0.0.4")
    33 (author "David Krentzlin")
    44 (maintainer "Kon Lovett")
  • release/5/micro-stats/trunk/micro-stats.scm

    r39737 r39739  
    4545(: percentile (seq #!optional real binary-predicate --> real))
    4646
    47 (: chi-sample (seq (or real seq) --> real))
     47(: chi-sample ((or real seq) (or real seq) --> real))
    4848(: chi-squares (seq seq --> seq))
    4949(: chi-square (seq (or real seq) --> real))
     
    298298      (/ acc (sub1 siz))) ) )
    299299
    300 ;;
     300;;FIXME chi^2 dist is ???
     301
     302(define (ensure-seq x) (if (seq:sequence? x) x (list x)))
    301303
    302304;observed : (seq-of real)
     
    315317;;
    316318
    317 (define (component o e) (let ((r (- o e))) (/ (* r r) e)))
    318 
    319 ;observed : (seq-of real)
     319(define (chi-component o e) (let ((r (- o e))) (/ (* r r) e)))
     320
     321;observed : (or real (seq-of real))
    320322;expected : (or real (seq-of real))
    321323;
     
    323325  (let (
    324326    (components
    325       (if (seq:sequence? expected)
    326         (seq:smap*
    327           *empty-vector*
    328           (lambda (value it) (component value (seq:elt expected (seq:index it))))
    329           observed)
    330         (seq:smap *empty-vector* (cut component <> expected) observed) ) ) )
     327      (cond
     328        ((not (seq:sequence? observed))
     329          (seq:smap *empty-vector* (cut chi-component observed <>) expected) )
     330        ((not (seq:sequence? expected))
     331          (seq:smap *empty-vector* (cut chi-component <> expected) observed) )
     332        (else
     333          (seq:smap*
     334            *empty-vector*
     335            (lambda (s it) (chi-component (seq:elt s it) (seq:elt expected (seq:index it))))
     336            observed) ) ) ) )
    331337    (seq:foldl + 0 components) ) )
    332338
  • release/5/micro-stats/trunk/tests/micro-stats-test.scm

    r39737 r39739  
    110110)
    111111
     112(test-group "chi-square"
     113  (define observed '(1003390.64498901 1003339.76300049 1002674.73300171))
     114  (define expected '(1000726.09802246 1004995.05200195 1000966.09100342))
     115  (chi-square observed expected) )
     116
    112117(test-end "micro-stats")
    113118
Note: See TracChangeset for help on using the changeset viewer.