;;;; srfi.27.levys.scm ;;;; Kon Lovett, Dec '17 ;;;; Kon Lovett, Jun '17 ;;;; Kon Lovett, May '06 ; Chicken Generic Arithmetic! (would use fp routines, except for the "real" constraint) (module srfi.27.levys (;export *make-random-levys make-random-levys) (import scheme (chicken base) (chicken type) (only (type-checks-numbers scheme) check-real) (only type-checks-structured check-procedure) (srfi 27) srfi-27-distributions-support) ;;; (include-relative "srfi-27-common-types") (: *make-random-levys (number number random-real-function -> number-function)) (: make-random-levys (#!rest -> number-function procedure)) ;;; Levy distribution ;; See Stable Distributions - John P. Nolan, Formula 1.12 (define (*make-random-levys gamma delta randoms) (if (and (= 1 gamma) (= 0 delta)) (lambda () (let ((r (randoms))) (*reciprocal (* r r)))) (lambda () (let ((r (randoms))) (+ delta (* gamma (*reciprocal (* r r))))))) ) (define (make-random-levys #!key (gamma 1) (delta 0) (randoms (current-random-real))) (check-nonnegative-real 'make-random-levys delta 'delta) (check-positive-real 'make-random-levys gamma 'gamma) (check-procedure 'make-random-levys randoms 'randoms) (values (*make-random-levys gamma delta randoms) (lambda () (values gamma delta randoms))) ) ) ;module srfi.27.levys