| 1 | ;; Weibull distribution |
|---|
| 2 | ;; Liam Healy, Sun Oct 22 2006 |
|---|
| 3 | ;; Time-stamp: <2008-02-17 13:30:33EST weibull.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | (defmfun weibull (generator a b) |
|---|
| 9 | "gsl_ran_weibull" |
|---|
| 10 | (((generator generator) :pointer) (a :double) (b :double)) |
|---|
| 11 | :c-return :double |
|---|
| 12 | :documentation ; FDL |
|---|
| 13 | "A random variate from the Weibull distribution. The distribution function is |
|---|
| 14 | p(x) dx = {b \over a^b} x^{b-1} \exp(-(x/a)^b) dx |
|---|
| 15 | for x >= 0.") |
|---|
| 16 | |
|---|
| 17 | (defmfun weibull-pdf (x a b) |
|---|
| 18 | "gsl_ran_weibull_pdf" ((x :double) (a :double) (b :double)) |
|---|
| 19 | :c-return :double |
|---|
| 20 | :documentation ; FDL |
|---|
| 21 | "The probability density p(x) at x |
|---|
| 22 | for a Weibull distribution with scale a and exponent b, |
|---|
| 23 | using the formula given in #'weibull.") |
|---|
| 24 | |
|---|
| 25 | (defmfun weibull-P (x a b) |
|---|
| 26 | "gsl_cdf_weibull_P" ((x :double) (a :double) (b :double)) |
|---|
| 27 | :c-return :double |
|---|
| 28 | :documentation ; FDL |
|---|
| 29 | "The cumulative distribution functions |
|---|
| 30 | P(x) for the Weibull distribution with scale a and exponent b.") |
|---|
| 31 | |
|---|
| 32 | (defmfun weibull-Q (x a b) |
|---|
| 33 | "gsl_cdf_weibull_Q" ((x :double) (a :double) (b :double)) |
|---|
| 34 | :c-return :double |
|---|
| 35 | :documentation ; FDL |
|---|
| 36 | "The cumulative distribution functions |
|---|
| 37 | Q(x) for the Weibull distribution with scale a and exponent b.") |
|---|
| 38 | |
|---|
| 39 | (defmfun weibull-Pinv (P a b) |
|---|
| 40 | "gsl_cdf_weibull_Pinv" ((P :double) (a :double) (b :double)) |
|---|
| 41 | :c-return :double |
|---|
| 42 | :documentation ; FDL |
|---|
| 43 | "The inverse cumulative distribution functions |
|---|
| 44 | P(x) for the Weibull distribution scale a and exponent b.") |
|---|
| 45 | |
|---|
| 46 | (defmfun weibull-Qinv (Q a b) |
|---|
| 47 | "gsl_cdf_weibull_Qinv" ((Q :double) (a :double) (b :double)) |
|---|
| 48 | :c-return :double |
|---|
| 49 | :documentation ; FDL |
|---|
| 50 | "The inverse cumulative distribution functions |
|---|
| 51 | Q(x) for the Weibull distribution exponent a and scale b.") |
|---|
| 52 | |
|---|
| 53 | ;;; Examples and unit test |
|---|
| 54 | #| |
|---|
| 55 | (make-tests weibull |
|---|
| 56 | (letm ((rng (random-number-generator *mt19937* 0))) |
|---|
| 57 | (loop for i from 0 to 10 |
|---|
| 58 | collect |
|---|
| 59 | (weibull rng 1.0d0 2.0d0))) |
|---|
| 60 | (weibull-pdf 1.5d0 1.3d0 1.0d0) |
|---|
| 61 | (weibull-P 3.5d0 1.3d0 2.0d0) |
|---|
| 62 | (weibull-Q 3.5d0 1.3d0 2.0d0) |
|---|
| 63 | (weibull-Pinv 0.9992887742799077d0 1.3d0 2.0d0) |
|---|
| 64 | (weibull-Qinv 7.112257200923508d-4 1.3d0 2.0d0)) |
|---|
| 65 | |# |
|---|
| 66 | |
|---|
| 67 | (LISP-UNIT:DEFINE-TEST WEIBULL |
|---|
| 68 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 69 | (LIST |
|---|
| 70 | (LIST 0.0160712303786595d0 1.347055359960668d0 |
|---|
| 71 | 1.1241262408795445d0 0.2329031397826649d0 |
|---|
| 72 | 1.209338423856536d0 0.8506825453443836d0 |
|---|
| 73 | 0.20845532973957762d0 0.5434187344070215d0 |
|---|
| 74 | 0.7849237503774361d0 0.5487883320132739d0 |
|---|
| 75 | 0.5239377808419179d0)) |
|---|
| 76 | (MULTIPLE-VALUE-LIST |
|---|
| 77 | (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0))) |
|---|
| 78 | (LOOP FOR I FROM 0 TO 10 COLLECT |
|---|
| 79 | (WEIBULL RNG 1.0d0 2.0d0))))) |
|---|
| 80 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 81 | (LIST 0.24263174972226745d0) |
|---|
| 82 | (MULTIPLE-VALUE-LIST (WEIBULL-PDF 1.5d0 1.3d0 1.0d0))) |
|---|
| 83 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 84 | (LIST 0.9992887742799077d0) |
|---|
| 85 | (MULTIPLE-VALUE-LIST (WEIBULL-P 3.5d0 1.3d0 2.0d0))) |
|---|
| 86 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 87 | (LIST 7.112257200923508d-4) |
|---|
| 88 | (MULTIPLE-VALUE-LIST (WEIBULL-Q 3.5d0 1.3d0 2.0d0))) |
|---|
| 89 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 90 | (LIST 3.5000000000000164d0) |
|---|
| 91 | (MULTIPLE-VALUE-LIST |
|---|
| 92 | (WEIBULL-PINV 0.9992887742799077d0 1.3d0 2.0d0))) |
|---|
| 93 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 94 | (LIST 3.5d0) |
|---|
| 95 | (MULTIPLE-VALUE-LIST (WEIBULL-QINV 7.112257200923508d-4 1.3d0 2.0d0)))) |
|---|