| 1 | ;; Rayleigh distribution |
|---|
| 2 | ;; Liam Healy, Sat Sep 30 2006 |
|---|
| 3 | ;; Time-stamp: <2008-02-17 18:45:41EST rayleigh.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | (defmfun rayleigh (generator sigma) |
|---|
| 9 | "gsl_ran_rayleigh" |
|---|
| 10 | (((generator generator) :pointer) (sigma :double)) |
|---|
| 11 | :c-return :double |
|---|
| 12 | :documentation ; FDL |
|---|
| 13 | "A random variate from the Rayleigh distribution with |
|---|
| 14 | scale parameter sigma. The distribution is |
|---|
| 15 | p(x) dx = {x \over \sigma^2} \exp(- x^2/(2 \sigma^2)) dx |
|---|
| 16 | for x > 0.") |
|---|
| 17 | |
|---|
| 18 | (defmfun rayleigh-pdf (x sigma) |
|---|
| 19 | "gsl_ran_rayleigh_pdf" ((x :double) (sigma :double)) |
|---|
| 20 | :c-return :double |
|---|
| 21 | :documentation ; FDL |
|---|
| 22 | "The probability density p(x) at x |
|---|
| 23 | for a Rayleigh distribution with scale parameter sigma, using the |
|---|
| 24 | formula given for #'rayleigh.") |
|---|
| 25 | |
|---|
| 26 | (defmfun rayleigh-P (x sigma) |
|---|
| 27 | "gsl_cdf_rayleigh_P" ((x :double) (sigma :double)) |
|---|
| 28 | :c-return :double |
|---|
| 29 | :documentation ; FDL |
|---|
| 30 | "The cumulative distribution function |
|---|
| 31 | P(x) for the Rayleigh distribution with scale |
|---|
| 32 | parameter sigma.") |
|---|
| 33 | |
|---|
| 34 | (defmfun rayleigh-Q (x sigma) |
|---|
| 35 | "gsl_cdf_rayleigh_Q" ((x :double) (sigma :double)) |
|---|
| 36 | :c-return :double |
|---|
| 37 | :documentation ; FDL |
|---|
| 38 | "The cumulative distribution function |
|---|
| 39 | Q(x) for the Rayleigh distribution with scale |
|---|
| 40 | parameter sigma.") |
|---|
| 41 | |
|---|
| 42 | (defmfun rayleigh-Pinv (P sigma) |
|---|
| 43 | "gsl_cdf_rayleigh_Pinv" ((P :double) (sigma :double)) |
|---|
| 44 | :c-return :double |
|---|
| 45 | :documentation ; FDL |
|---|
| 46 | "The inverse cumulative distribution function |
|---|
| 47 | P(x)} for the Rayleigh distribution with scale |
|---|
| 48 | parameter sigma.") |
|---|
| 49 | |
|---|
| 50 | (defmfun rayleigh-Qinv (Q sigma) |
|---|
| 51 | "gsl_cdf_rayleigh_Qinv" ((Q :double) (sigma :double)) |
|---|
| 52 | :c-return :double |
|---|
| 53 | :documentation ; FDL |
|---|
| 54 | "The inverse cumulative distribution function |
|---|
| 55 | Q(x) for the Rayleigh distribution with scale |
|---|
| 56 | parameter sigma.") |
|---|
| 57 | |
|---|
| 58 | ;;; Examples and unit test |
|---|
| 59 | #| |
|---|
| 60 | (make-tests rayleigh |
|---|
| 61 | (letm ((rng (random-number-generator *mt19937* 0))) |
|---|
| 62 | (loop for i from 0 to 10 |
|---|
| 63 | collect |
|---|
| 64 | (rayleigh rng 10.0d0))) |
|---|
| 65 | (rayleigh-pdf 0.5d0 1.0d0) |
|---|
| 66 | (rayleigh-P 1.0d0 2.0d0) |
|---|
| 67 | (rayleigh-Q 1.0d0 2.0d0) |
|---|
| 68 | (rayleigh-Pinv 0.1175030974154046d0 2.0d0) |
|---|
| 69 | (rayleigh-Qinv 0.8824969025845955d0 2.0d0)) |
|---|
| 70 | |# |
|---|
| 71 | |
|---|
| 72 | (LISP-UNIT:DEFINE-TEST RAYLEIGH |
|---|
| 73 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 74 | (LIST |
|---|
| 75 | (LIST 0.22728151965522753d0 19.05023959323748d0 |
|---|
| 76 | 15.897545756713367d0 3.2937477899992147d0 |
|---|
| 77 | 17.102628005168157d0 12.030467929000928d0 |
|---|
| 78 | 2.9480035446666624d0 7.6851014424603274d0 |
|---|
| 79 | 11.100498132125239d0 7.76103902005281d0 |
|---|
| 80 | 7.409599155063027d0)) |
|---|
| 81 | (MULTIPLE-VALUE-LIST |
|---|
| 82 | (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0))) |
|---|
| 83 | (LOOP FOR I FROM 0 TO 10 COLLECT |
|---|
| 84 | (RAYLEIGH RNG 10.0d0))))) |
|---|
| 85 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 86 | (LIST 0.4412484512922977d0) |
|---|
| 87 | (MULTIPLE-VALUE-LIST (RAYLEIGH-PDF 0.5d0 1.0d0))) |
|---|
| 88 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 89 | (LIST 0.1175030974154046d0) |
|---|
| 90 | (MULTIPLE-VALUE-LIST (RAYLEIGH-P 1.0d0 2.0d0))) |
|---|
| 91 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 92 | (LIST 0.8824969025845955d0) |
|---|
| 93 | (MULTIPLE-VALUE-LIST (RAYLEIGH-Q 1.0d0 2.0d0))) |
|---|
| 94 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 95 | (LIST 1.0000000000000002d0) |
|---|
| 96 | (MULTIPLE-VALUE-LIST |
|---|
| 97 | (RAYLEIGH-PINV 0.1175030974154046d0 2.0d0))) |
|---|
| 98 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 99 | (LIST 0.9999999999999998d0) |
|---|
| 100 | (MULTIPLE-VALUE-LIST |
|---|
| 101 | (RAYLEIGH-QINV 0.8824969025845955d0 2.0d0)))) |
|---|
| 102 | |
|---|