#lang racket
(require scheme/unsafe/ops
"unsafe-ops-utils.rkt")
(define-values (struct:statistics
construct-statistics
statistics?
statistics-ref
statistics-set!)
(make-struct-type 'statistics #f 5 0))
(define (make-statistics)
(construct-statistics 0 +inf.0 -inf.0 0.0 0.0))
(define statistics-n
(make-struct-field-accessor statistics-ref 0 'n))
(define set-statistics-n!
(make-struct-field-mutator statistics-set! 0 'n))
(define statistics-min
(make-struct-field-accessor statistics-ref 1 'min))
(define set-statistics-min!
(make-struct-field-mutator statistics-set! 1 'min))
(define statistics-max
(make-struct-field-accessor statistics-ref 2 'max))
(define set-statistics-max!
(make-struct-field-mutator statistics-set! 2 'max))
(define statistics-M-n
(make-struct-field-accessor statistics-ref 3 'M-n))
(define set-statistics-M-n!
(make-struct-field-mutator statistics-set! 3 'M-n))
(define statistics-S-n
(make-struct-field-accessor statistics-ref 4 'S-n))
(define set-statistics-S-n!
(make-struct-field-mutator statistics-set! 4 'S-n))
(define (statistics-reset! statistics)
(set-statistics-n! statistics 0)
(set-statistics-min! statistics +inf.0)
(set-statistics-max! statistics -inf.0)
(set-statistics-M-n! statistics 0.0)
(set-statistics-S-n! statistics 0.0))
(define (statistics-tally! statistics x)
(let ((min (statistics-min statistics))
(max (statistics-max statistics)))
(when (< x min)
(set-statistics-min! statistics x))
(when (> x max)
(set-statistics-max! statistics x)))
(with-float (x)
(let ((n (unsafe-fx+ (statistics-n statistics) 1)))
(set-statistics-n! statistics n)
(if (unsafe-fx= n 1)
(begin
(set-statistics-M-n! statistics x)
(set-statistics-S-n! statistics 0.0))
(let* ((M-old (statistics-M-n statistics))
(M-new (unsafe-fl+
M-old
(unsafe-fl/ (unsafe-fl- x M-old) (exact->inexact n))))
(S-old (statistics-S-n statistics))
(S-new (unsafe-fl+
S-old
(unsafe-fl* (unsafe-fl- x M-old) (unsafe-fl- x M-new)))))
(set-statistics-M-n! statistics M-new)
(set-statistics-S-n! statistics S-new))))))
(define (statistics-mean statistics)
(if (unsafe-fx> (statistics-n statistics) 0)
(statistics-M-n statistics)
0.0))
(define (statistics-variance statistics)
(if (unsafe-fx> (statistics-n statistics) 1)
(unsafe-fl/ (statistics-S-n statistics)
(unsafe-fx->fl (unsafe-fx- (statistics-n statistics) 1)))
0.0))
(define (statistics-standard-deviation statistics)
(sqrt (statistics-variance statistics)))
(define-syntax dispatch-for
(syntax-rules (rewrite-for-clauses)
((dispatch-for
rewrite-for-clauses
general-for-clauses
()
vector-cond-expr-terms
vector-for-clauses
list-cond-expr-terms
list-for-clauses
expr ...)
(cond ((and . vector-cond-expr-terms)
(for vector-for-clauses
expr ...))
((and . list-cond-expr-terms)
(for list-for-clauses
expr ...))
(else
(for general-for-clauses
expr ...))))
((dispatch-for
rewrite-for-clauses
general-for-clauses
((id (sequence-type . sequence-args)) . rest-for-clauses)
vector-cond-expr-terms
vector-for-clauses
list-cond-expr-terms
list-for-clauses
expr ...)
(dispatch-for
rewrite-for-clauses
general-for-clauses
rest-for-clauses
vector-cond-expr-terms
((id (sequence-type . sequence-args)) . vector-for-clauses)
list-cond-expr-terms
((id (sequence-type . sequence-args)) . list-for-clauses)
expr ...))
((dispatch-for
rewrite-for-clauses
general-for-clauses
((id data) . rest-for-clauses)
vector-cond-expr-terms
vector-for-clauses
list-cond-expr-terms
list-for-clauses
expr ...)
(dispatch-for
rewrite-for-clauses
general-for-clauses
rest-for-clauses
((vector? data) . vector-cond-expr-terms)
((id (in-vector data)) . vector-for-clauses)
((pair? data) . list-cond-expr-terms)
((id (in-list data)) . list-for-clauses)
expr ...))
((dispatch-for
general-for-clauses
expr ...)
(dispatch-for
rewrite-for-clauses
general-for-clauses
general-for-clauses
()
()
()
()
expr ...))))
(define-syntax dispatch-for/fold
(syntax-rules (rewrite-for-clauses)
((dispatch-for/fold
rewrite-for-clauses
accumulator-clauses
general-for-clauses
()
vector-cond-expr-terms
vector-for-clauses
list-cond-expr-terms
list-for-clauses
expr ...)
(cond ((and . vector-cond-expr-terms)
(for/fold accumulator-clauses
vector-for-clauses
expr ...))
((and . list-cond-expr-terms)
(for/fold accumulator-clauses
list-for-clauses
expr ...))
(else
(for/fold accumulator-clauses
general-for-clauses
expr ...))))
((dispatch-for/fold
rewrite-for-clauses
accumulator-clauses
general-for-clauses
((id (sequence-type . sequence-args)) . rest-for-clauses)
vector-cond-expr-terms
vector-for-clauses
list-cond-expr-terms
list-for-clauses
expr ...)
(dispatch-for/fold
rewrite-for-clauses
accumulator-clauses
general-for-clauses
rest-for-clauses
vector-cond-expr-terms
((id (sequence-type . sequence-args)) . vector-for-clauses)
list-cond-expr-terms
((id (sequence-type . sequence-args)) . list-for-clauses)
expr ...))
((dispatch-for/fold
rewrite-for-clauses
accumulator-clauses
general-for-clauses
((id data) . rest-for-clauses)
vector-cond-expr-terms
vector-for-clauses
list-cond-expr-terms
list-for-clauses
expr ...)
(dispatch-for/fold
rewrite-for-clauses
accumulator-clauses
general-for-clauses
rest-for-clauses
((vector? data) . vector-cond-expr-terms)
((id (in-vector data)) . vector-for-clauses)
((pair? data) . list-cond-expr-terms)
((id (in-list data)) . list-for-clauses)
expr ...))
((dispatch-for/fold
accumulator-clauses
general-for-clauses
expr ...)
(dispatch-for/fold
rewrite-for-clauses
accumulator-clauses
general-for-clauses
general-for-clauses
()
()
()
()
expr ...))))
(define (mean data)
(dispatch-for/fold ((m-old 0.0))
((i (in-naturals 1))
(x data))
(with-float (x)
(unsafe-fl+ m-old
(unsafe-fl/ (unsafe-fl- x m-old)
(unsafe-fx->fl i))))))
(define (mean-and-variance data)
(let-values
(((n m s)
(dispatch-for/fold ((i-old 0)
(m-old 0.0)
(s-old 0.0))
((x data))
(with-float (x)
(let ((i-new (unsafe-fx+ i-old 1)))
(if (unsafe-fx= i-new 1)
(values i-new x 0.0)
(let* ((m-new (unsafe-fl+ m-old
(unsafe-fl/ (unsafe-fl- x m-old)
(exact->inexact i-new))))
(s-new (unsafe-fl+ s-old
(unsafe-fl* (unsafe-fl- x m-old)
(unsafe-fl- x m-new)))))
(values i-new m-new s-new))))))))
(values m (if (unsafe-fx> n 1)
(unsafe-fl/ s (exact->inexact (unsafe-fx- n 1)))
0.0))))
(define (compute-variance data mean)
(dispatch-for/fold ((i 0)
(v-old 0.0))
((x data))
(with-float (x)
(let* ((n (unsafe-fx+ i 1))
(delta (unsafe-fl- x mean))
(v-new (unsafe-fl+
v-old
(unsafe-fl/ (unsafe-fl- (unsafe-fl* delta delta) v-old)
(exact->inexact (unsafe-fx+ i 1))))))
(values n v-new)))))
(define (variance-with-fixed-mean data mean)
(with-float (mean)
(let-values
(((n V)
(compute-variance data mean)))
V)))
(define (standard-deviation-with-fixed-mean data mean)
(with-float (mean)
(let-values
(((n V)
(compute-variance data mean)))
(sqrt V))))
(define variance
(case-lambda
((data mean)
(with-float (mean)
(let-values
(((n V)
(compute-variance data mean)))
(unsafe-fl* V (unsafe-fl/ (exact->inexact n)
(exact->inexact (unsafe-fx- n 1)))))))
((data)
(let-values (((mean variance)
(mean-and-variance data)))
variance))))
(define standard-deviation
(case-lambda
((data mean)
(with-float (mean)
(let-values
(((n V)
(compute-variance data mean)))
(sqrt (unsafe-fl* V (unsafe-fl/ (exact->inexact n)
(exact->inexact (unsafe-fx- n 1))))))))
((data)
(let-values (((mean variance)
(mean-and-variance data)))
(sqrt variance)))))
(define (sum-of-squares data (mean (mean data)))
(with-float (mean)
(dispatch-for/fold ((tss-old 0.0))
((x data))
(with-float (x)
(let ((delta (unsafe-fl- x mean)))
(unsafe-fl+ tss-old (unsafe-fl* delta delta)))))))
(define (absolute-deviation data (mean (mean data)))
(with-float (mean)
(let-values
(((n S)
(dispatch-for/fold ((i 0)
(sum 0.0))
((x data))
(with-float (x)
(let ((delta (abs (unsafe-fl- x mean))))
(values (unsafe-fx+ i 1)
(unsafe-fl+ sum delta)))))))
(unsafe-fl/ S (exact->inexact n)))))
(define skew
(case-lambda
((data mean sd)
(with-float (mean sd)
(dispatch-for/fold ((skew 0.0))
((i (in-naturals))
(x data))
(with-float (x)
(let ((delta (unsafe-fl/ (unsafe-fl- x mean) sd)))
(unsafe-fl+ skew
(unsafe-fl/ (unsafe-fl- (unsafe-fl* delta
(unsafe-fl* delta delta))
skew)
(exact->inexact (unsafe-fx+ i 1)))))))))
((data)
(let-values (((mean variance) (mean-and-variance data)))
(skew data mean (sqrt variance))))))
(define kurtosis
(case-lambda
((data mean sd)
(with-float (mean sd)
(let* ((avg
(dispatch-for/fold ((avg 0.0))
((i (in-naturals))
(x data))
(with-float (x)
(let ((delta (unsafe-fl/ (unsafe-fl- x mean) sd)))
(unsafe-fl+ avg (unsafe-fl/
(unsafe-fl- (unsafe-fl* (unsafe-fl* delta delta)
(unsafe-fl* delta delta))
avg)
(exact->inexact (unsafe-fx+ i 1)))))))))
(unsafe-fl- avg 3.0))))
((data)
(let-values (((mean variance) (mean-and-variance data)))
(kurtosis data mean (sqrt variance))))))
(define (lag-1-autocorrelation data (mean (mean data)))
(with-float (mean)
(let-values
(((x-prev Q V)
(dispatch-for/fold ((x-prev 0.0)
(q-old 0.0)
(v-old 0.0))
((i (in-naturals))
(x data))
(with-float (x)
(if (unsafe-fx= i 0)
(let ((delta (unsafe-fl- x mean)))
(values x 0.0 (unsafe-fl* delta delta)))
(let* ((delta0 (unsafe-fl- x-prev mean))
(delta1 (unsafe-fl- x mean))
(q-new (unsafe-fl+
q-old
(unsafe-fl/ (unsafe-fl- (unsafe-fl* delta0 delta1)
q-old)
(exact->inexact (unsafe-fx+ i 1)))))
(v-new (unsafe-fl+
v-old
(unsafe-fl/ (unsafe-fl- (unsafe-fl* delta1 delta1)
v-old)
(exact->inexact (unsafe-fx+ i 1))))))
(values x q-new v-new)))))))
(unsafe-fl/ Q V))))
(define (covariance data1 data2 (mean1 (mean data1)) (mean2 (mean data2)))
(with-float (mean1 mean2)
(let-values
(((n covariance)
(dispatch-for/fold ((i 0)
(covariance 0.0))
((x1 data1)
(x2 data2))
(with-float (x1 x2)
(let* ((delta1 (unsafe-fl- x1 mean1))
(delta2 (unsafe-fl- x2 mean2))
(covariance-new
(unsafe-fl+ covariance
(unsafe-fl/ (unsafe-fl- (unsafe-fl* delta1 delta2)
covariance)
(exact->inexact (unsafe-fx+ i 1))))))
(values (unsafe-fx+ i 1) covariance-new))))))
(unsafe-fl* covariance (unsafe-fl/ (exact->inexact n)
(exact->inexact (unsafe-fx- n 1)))))))
(define (correlation data1 data2)
(let-values
(((sum-xsq sum-ysq sum-cross mean-x mean-y)
(dispatch-for/fold ((sum-xsq 0.0)
(sum-ysq 0.0)
(sum-cross 0.0)
(mean-x 0.0)
(mean-y 0.0))
((i (in-naturals))
(x data1)
(y data2))
(with-float (x y)
(if (unsafe-fx= i 0)
(values 0.0 0.0 0.0 x y)
(let* ((ratio (unsafe-fl/ (exact->inexact i)
(exact->inexact (unsafe-fx+ i 1))))
(delta-x (unsafe-fl- x mean-x))
(delta-y (unsafe-fl- y mean-y)))
(values (unsafe-fl+ sum-xsq
(unsafe-fl* (unsafe-fl* delta-x delta-x)
ratio))
(unsafe-fl+ sum-ysq
(unsafe-fl* (unsafe-fl* delta-y delta-y)
ratio))
(unsafe-fl+ sum-cross
(unsafe-fl* (unsafe-fl* delta-x delta-y)
ratio))
(unsafe-fl+ mean-x
(unsafe-fl/ delta-x
(exact->inexact (unsafe-fx+ i 1))))
(unsafe-fl+ mean-y
(unsafe-fl/ delta-y
(exact->inexact (unsafe-fx+ i 1)))))))))))
(unsafe-fl/ sum-cross (unsafe-fl* (sqrt sum-xsq) (sqrt sum-ysq)))))
(define (weighted-mean weights data)
(let-values
(((W M)
(dispatch-for/fold ((w-old 0.0)
(m-old 0.0))
((w weights)
(x data))
(with-float (w x)
(if (unsafe-fl> w 0.0)
(let* ((w-new (unsafe-fl+ w-old w))
(m-new (unsafe-fl+
m-old
(unsafe-fl* (unsafe-fl- x m-old)
(unsafe-fl/ w w-new)))))
(values w-new m-new))
(values w-old m-old))))))
M))
(define (compute-weighted-variance weights data wmean)
(with-float (wmean)
(dispatch-for/fold ((i 0)
(w-old 0.0)
(wv-old 0.0))
((w weights)
(x data))
(with-float (w x)
(if (unsafe-fl> w 0.0)
(let* ((delta (unsafe-fl- x wmean))
(w-new (unsafe-fl+ w-old w))
(wv-new (unsafe-fl+
wv-old
(unsafe-fl* (unsafe-fl- (unsafe-fl* delta delta)
wv-old)
(unsafe-fl/ w w-new)))))
(values (unsafe-fx+ i 1) w-new wv-new))
(values (unsafe-fx+ i 1) w-old wv-old))))))
(define (compute-factor weights)
(let-values
(((a b)
(dispatch-for/fold ((a-old 0.0)
(b-old 0.0))
((w weights))
(with-float (w)
(if (unsafe-fl> w 0.0)
(values (unsafe-fl+ a-old w) (unsafe-fl+ b-old (unsafe-fl* w w)))
(values a-old b-old))))))
(unsafe-fl/ (unsafe-fl* a a) (unsafe-fl- (unsafe-fl* a a) b))))
(define (weighted-variance-with-fixed-mean weights data wmean)
(with-float (wmean)
(let-values
(((n W wvariance)
(compute-weighted-variance weights data wmean)))
wvariance)))
(define (weighted-standard-deviation-with-fixed-mean weights data wmean)
(with-float (wmean)
(let-values
(((n W wvariance)
(compute-weighted-variance weights data wmean)))
(sqrt wvariance))))
(define (weighted-variance weights data (wmean (weighted-mean weights data)))
(with-float (wmean)
(let-values
(((n W wvariance)
(compute-weighted-variance weights data wmean)))
(let ((scale (compute-factor weights)))
(unsafe-fl* scale wvariance)))))
(define (weighted-standard-deviation weights data (wmean (weighted-mean weights data)))
(with-float (wmean)
(let-values
(((n W wvariance)
(compute-weighted-variance weights data wmean)))
(let ((scale (compute-factor weights)))
(sqrt (unsafe-fl* scale wvariance))))))
(define (weighted-sum-of-squares weights data (wmean (weighted-mean weights data)))
(with-float (wmean)
(dispatch-for/fold ((wtss-old 0.0))
((w weights)
(x data))
(with-float (w x)
(if (unsafe-fl> w 0.0)
(let ((delta (unsafe-fl- x wmean)))
(unsafe-fl+ wtss-old (unsafe-fl* w delta delta)))
wtss-old)))))
(define (weighted-absolute-deviation weights data (wmean (weighted-mean weights data)))
(with-float (wmean)
(let-values
(((W wabsdev)
(dispatch-for/fold ((w-old 0.0)
(wabsdev-old 0.0))
((w weights)
(x data))
(with-float (w x)
(if (unsafe-fl> w 0.0)
(let* ((delta (abs (unsafe-fl- x wmean)))
(w-new (unsafe-fl+ w-old w))
(wabsdev-new (unsafe-fl+
wabsdev-old
(unsafe-fl* (unsafe-fl- delta wabsdev-old)
(unsafe-fl/ w w-new)))))
(values w-new wabsdev-new))
(values w-old wabsdev-old))))))
wabsdev)))
(define weighted-skew
(case-lambda
((weights data wmean wsd)
(with-float (wmean wsd)
(let-values
(((W wskew)
(dispatch-for/fold ((w-old 0.0)
(wskew-old 0.0))
((w weights)
(x data))
(with-float (w x)
(if (unsafe-fl> w 0.0)
(let* ((delta (unsafe-fl/ (unsafe-fl- x wmean) wsd))
(w-new (unsafe-fl+ w-old w))
(wskew-new (unsafe-fl+
wskew-old
(unsafe-fl*
(unsafe-fl- (unsafe-fl* delta
(unsafe-fl* delta delta))
wskew-old)
(unsafe-fl/ w w-new)))))
(values w-new wskew-new))
(values w-old wskew-old))))))
wskew)))
((weights data)
(let* ((wmean (weighted-mean weights data))
(wsd (weighted-standard-deviation weights data wmean)))
(weighted-skew weights data wmean wsd)))))
(define weighted-kurtosis
(case-lambda
((weights data wmean wsd)
(with-float (wmean wsd)
(let-values
(((W wavg)
(dispatch-for/fold ((w-old 0.0)
(wavg-old 0.0))
((w weights)
(x data))
(with-float (w x)
(if (unsafe-fl> w 0.0)
(let* ((delta (unsafe-fl/ (unsafe-fl- x wmean) wsd))
(w-new (unsafe-fl+ w-old w))
(wavg-new (unsafe-fl+
wavg-old
(unsafe-fl* (unsafe-fl-
(unsafe-fl* (unsafe-fl* delta delta)
(unsafe-fl* delta delta))
wavg-old)
(unsafe-fl/ w w-new)))))
(values w-new wavg-new))
(values w-old wavg-old))))))
(unsafe-fl- wavg 3.0))))
((weights data)
(let* ((wmean (weighted-mean weights data))
(wsd (weighted-standard-deviation weights data wmean)))
(weighted-kurtosis weights data wmean wsd)))))
(define (minimum-maximum-and-indices data)
(dispatch-for/fold ((min +inf.0)
(max -inf.0)
(min-ndx -1)
(max-ndx -1))
((i (in-naturals))
(x data))
(let ((min-new (if (< x min) x min))
(max-new (if (> x max) x max))
(min-ndx-new (if (< x min) i min-ndx))
(max-ndx-new (if (> x max) i max-ndx)))
(values min-new max-new min-ndx-new max-ndx-new))))
(define (minimum-maximum data)
(let-values (((min max min-ndx max-ndx)
(minimum-maximum-and-indices data)))
(values min max)))
(define (minimum data)
(let-values (((min max min-ndx max-ndx)
(minimum-maximum-and-indices data)))
min))
(define (maximum data)
(let-values (((min max min-ndx max-ndx)
(minimum-maximum-and-indices data)))
max))
(define (minimum-maximum-index data)
(let-values (((min max min-ndx max-ndx)
(minimum-maximum-and-indices data)))
(values min-ndx max-ndx)))
(define (minimum-index data)
(let-values (((min max min-ndx max-ndx)
(minimum-maximum-and-indices data)))
min-ndx))
(define (maximum-index data)
(let-values (((min max min-ndx max-ndx)
(minimum-maximum-and-indices data)))
max-ndx))
(define (median-from-sorted-data sorted-data (n (vector-length sorted-data)))
(when (> n (vector-length sorted-data))
(error 'median-from-sorted-data
"expected integer less than ~a, given ~a"
(vector-length sorted-data) n))
(let* ((lhs (quotient (- n 1) 2))
(rhs (quotient n 2)))
(if (= lhs rhs)
(vector-ref sorted-data lhs)
(/ (+ (vector-ref sorted-data lhs)
(vector-ref sorted-data rhs))
2.0))))
(define (quantile-from-sorted-data sorted-data f (n (vector-length sorted-data)))
(when (> n (vector-length sorted-data))
(error 'median-from-sorted-data
"expected integer less than ~a, given ~a"
(vector-length sorted-data) n))
(let* ((index (* f (- n 1)))
(lhs (inexact->exact (truncate index)))
(delta (- index lhs)))
(if (= lhs (- n 1))
(vector-ref sorted-data lhs)
(+ (* (- 1.0 delta) (vector-ref sorted-data lhs))
(* delta (vector-ref sorted-data (+ lhs 1)))))))
(provide
(rename-out (mean unchecked-mean)
(mean-and-variance unchecked-mean-and-variance)
(variance-with-fixed-mean unchecked-variance-with-fixed-mean)
(standard-deviation-with-fixed-mean
unchecked-standard-deviation-with-fixed-mean)
(variance unchecked-variance)
(standard-deviation unchecked-standard-deviation)
(sum-of-squares unchecked-sum-of-squares)
(absolute-deviation unchecked-absolute-deviation)
(skew unchecked-skew)
(kurtosis unchecked-kurtosis)
(lag-1-autocorrelation unchecked-lag-1-autocorrelation)
(covariance unchecked-covariance)
(correlation unchecked-correlation)
(weighted-mean unchecked-weighted-mean)
(weighted-variance-with-fixed-mean
unchecked-weighted-variance-with-fixed-mean)
(weighted-standard-deviation-with-fixed-mean
unchecked-weighted-standard-deviation-with-fixed-mean)
(weighted-variance unchecked-weighted-variance)
(weighted-standard-deviation unchecked-weighted-standard-deviation)
(weighted-sum-of-squares unchecked-weighted-sum-of-squares)
(weighted-absolute-deviation unchecked-weighted-absolute-deviation)
(weighted-skew unchecked-weighted-skew)
(weighted-kurtosis unchecked-weighted-kurtosis)
(minimum-maximum unchecked-minimum-maximum)
(minimum unchecked-minimum)
(maximum unchecked-maximum)
(minimum-maximum-index unchecked-minimum-maximum-index)
(minimum-index unchecked-minimum-index)
(maximum-index unchecked-maximum-index)
(median-from-sorted-data unchecked-median-from-sorted-data)
(quantile-from-sorted-data unchecked-quantile-from-sorted-data)))
(define sequence-of-real?
(flat-named-contract
"sequence-of-real?"
(lambda (s)
(and (sequence? s)
(let/ec exit
(dispatch-for ((x s))
(unless (real? x)
(exit #f)))
#t)))))
(define nonempty-sequence-of-real?
(flat-named-contract
"nonempty-sequence-of-real?"
(lambda (s)
(and (sequence? s)
(let ((empty? #t))
(let/ec exit
(dispatch-for ((x s))
(set! empty? #f)
(unless (real? x)
(exit #f)))
(not empty?)))))))
(define nonempty-sorted-vector-of-real?
(flat-named-contract
"nonempty-sorted-vector-of-real?"
(lambda (v)
(and (vector v)
(let ((empty? #t))
(let/ec exit
(for/fold ((x-old -inf.0))
((x (in-vector v)))
(set! empty? #f)
(when (or (not (real? x))
(< x x-old))
(exit #f))
x)
(not empty?)))))))
(provide/contract
(statistics?
(-> any/c boolean?))
(make-statistics
(-> statistics?))
(statistics-reset!
(-> statistics? void?))
(statistics-tally!
(-> statistics? real? void?))
(statistics-n
(-> statistics? exact-nonnegative-integer?))
(statistics-min
(-> statistics? real?))
(statistics-max
(-> statistics? real?))
(statistics-mean
(-> statistics? inexact-real?))
(statistics-variance
(-> statistics? (and/c inexact-real? (>=/c 0.0))))
(statistics-standard-deviation
(-> statistics? (and/c inexact-real? (>=/c 0.0))))
(mean
(-> sequence-of-real? inexact-real?))
(mean-and-variance
(-> sequence-of-real?
(values inexact-real? (and/c inexact-real? (>=/c 0.0)))))
(variance-with-fixed-mean
(-> sequence-of-real? real? (and/c inexact-real? (>=/c 0.0))))
(standard-deviation-with-fixed-mean
(-> sequence-of-real? real? (and/c inexact-real? (>=/c 0.0))))
(variance
(case-> (-> sequence-of-real? real? (and/c inexact-real? (>=/c 0.0)))
(-> sequence-of-real? (and/c inexact-real? (>=/c 0.0)))))
(standard-deviation
(->* (sequence-of-real?) (real?) (and/c inexact-real? (>=/c 0.0))))
(sum-of-squares
(->* (sequence-of-real?) (real?) (and/c inexact-real? (>=/c 0.0))))
(absolute-deviation
(->* (sequence-of-real?) (real?) (and/c inexact-real? (>=/c 0.0))))
(skew
(case-> (-> sequence-of-real? real? (>=/c 0.0) inexact-real?)
(-> sequence-of-real? inexact-real?)))
(kurtosis
(case-> (-> sequence-of-real? real? (>=/c 0.0) inexact-real?)
(-> sequence-of-real? inexact-real?)))
(lag-1-autocorrelation
(->* (nonempty-sequence-of-real?) (real?) inexact-real?))
(covariance
(->* (sequence-of-real? sequence-of-real?)
(real? real?)
inexact-real?))
(correlation
(-> nonempty-sequence-of-real? nonempty-sequence-of-real?
(and/c inexact-real? (real-in -1.0 1.0))))
(weighted-mean
(-> sequence-of-real? sequence-of-real? inexact-real?))
(weighted-variance-with-fixed-mean
(-> sequence-of-real? sequence-of-real? real?
(and/c inexact-real? (>=/c 0.0))))
(weighted-standard-deviation-with-fixed-mean
(-> sequence-of-real? sequence-of-real? real?
(and/c inexact-real? (>=/c 0.0))))
(weighted-variance
(->* (sequence-of-real? sequence-of-real?) (real?)
(and/c inexact-real? (>=/c 0.0))))
(weighted-standard-deviation
(->* (sequence-of-real? sequence-of-real?) (real?)
(and/c inexact-real? (>=/c 0.0))))
(weighted-sum-of-squares
(->* (sequence-of-real? sequence-of-real?) (real?)
(and/c inexact-real? (>=/c 0.0))))
(weighted-absolute-deviation
(->* (sequence-of-real? sequence-of-real?) (real?)
(and/c inexact-real? (>=/c 0.0))))
(weighted-skew
(case-> (-> sequence-of-real? sequence-of-real? real? (>=/c 0.0) inexact-real?)
(-> sequence-of-real? sequence-of-real? inexact-real?)))
(weighted-kurtosis
(case-> (-> sequence-of-real? sequence-of-real? real? (>=/c 0.0) inexact-real?)
(-> sequence-of-real? sequence-of-real? inexact-real?)))
(minimum-maximum
(-> nonempty-sequence-of-real? (values real? real?)))
(minimum
(-> nonempty-sequence-of-real? real?))
(maximum
(-> nonempty-sequence-of-real? real?))
(minimum-maximum-index
(-> nonempty-sequence-of-real? (values exact-nonnegative-integer?
exact-nonnegative-integer?)))
(minimum-index
(-> nonempty-sequence-of-real? exact-nonnegative-integer?))
(maximum-index
(-> nonempty-sequence-of-real? exact-nonnegative-integer?))
(median-from-sorted-data
(->* (nonempty-sorted-vector-of-real?) (exact-nonnegative-integer?) real?))
(quantile-from-sorted-data
(->* (nonempty-sorted-vector-of-real? (real-in 0 1))
(exact-nonnegative-integer?) real?)))