(module data-synthesis (lib "frtime.ss" "frtime")
(require "distributions.ss"
(lib "math.ss")
)
(define (sample-mean data)
(let ([n (length data)]
[sum-y (apply + data)])
(/ sum-y n)))
(define (sample-variance data)
(let* ([n (length data)]
[sm (sample-mean data)]
[d2 (map (lambda (x)
(sqr (- x sm)))
data)])
(/ (apply + d2)
(- n 1))))
(define (fit-normal-distribution data)
(make-normal-distribution (sample-mean data)
(sqrt (sample-variance data))))
(define (fit-uniform-distribution data)
(let ([mean (sample-mean data)]
[variance (sample-variance data)])
(make-uniform-distribution (- mean
(sqrt (* 3 variance)))
(+ mean
(sqrt (* 3 variance))))))
(define (fit-exponential-distribution data)
(make-exponential-distribution (sample-mean data)))
(define (synthesize-random-data dist size)
(if (zero? size)
'()
(cons ((distribution-rand dist))
(synthesize-random-data dist (sub1 size)))))
(provide (all-defined))
)