| 1 | ;; The Gumbel type 2 random number distribution |
|---|
| 2 | ;; Liam Healy, Sun Oct 29 2006 |
|---|
| 3 | ;; Time-stamp: <2008-02-17 13:32:16EST gumbel2.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | (defmfun gumbel2 (generator a b) |
|---|
| 9 | "gsl_ran_gumbel2" |
|---|
| 10 | (((generator generator) :pointer) (a :double) (b :double)) |
|---|
| 11 | :c-return :double |
|---|
| 12 | :documentation ; FDL |
|---|
| 13 | "A random variate from the Type-2 Gumbel |
|---|
| 14 | distribution, p(x) dx = a b x^{-a-1} \exp(-b x^{-a}) dx |
|---|
| 15 | for 0 < x < \infty.") |
|---|
| 16 | |
|---|
| 17 | (defmfun gumbel2-pdf (x a b) |
|---|
| 18 | "gsl_ran_gumbel2_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 Type-2 Gumbel distribution with parameters a and b, |
|---|
| 23 | using the formula given in #'gumbel2.") |
|---|
| 24 | |
|---|
| 25 | (defmfun gumbel2-P (x a b) |
|---|
| 26 | "gsl_cdf_gumbel2_P" ((x :double) (a :double) (b :double)) |
|---|
| 27 | :c-return :double ; FDL |
|---|
| 28 | :documentation "The cumulative distribution functions |
|---|
| 29 | P(x) for the Type-2 Gumbel distribution with |
|---|
| 30 | parameters a and b.") |
|---|
| 31 | |
|---|
| 32 | (defmfun gumbel2-Q (x a b) |
|---|
| 33 | "gsl_cdf_gumbel2_Q" ((x :double) (a :double) (b :double)) |
|---|
| 34 | :c-return :double |
|---|
| 35 | :documentation ; FDL |
|---|
| 36 | "The cumulative distribution functions |
|---|
| 37 | Q(x) for the Type-2 Gumbel distribution with |
|---|
| 38 | parameters a and b.") |
|---|
| 39 | |
|---|
| 40 | (defmfun gumbel2-Pinv (P a b) |
|---|
| 41 | "gsl_cdf_gumbel2_Pinv" ((P :double) (a :double) (b :double)) |
|---|
| 42 | :c-return :double |
|---|
| 43 | :documentation ; FDL |
|---|
| 44 | "The inverse cumulative distribution functions |
|---|
| 45 | P(x) for the Type-2 Gumbel distribution with |
|---|
| 46 | parameters a and b.") |
|---|
| 47 | |
|---|
| 48 | (defmfun gumbel2-Qinv (Q a b) |
|---|
| 49 | "gsl_cdf_gumbel2_Qinv" ((Q :double) (a :double) (b :double)) |
|---|
| 50 | :c-return :double |
|---|
| 51 | :documentation ; FDL |
|---|
| 52 | "The inverse cumulative distribution functions |
|---|
| 53 | Q(x) for the Type-2 Gumbel distribution with |
|---|
| 54 | parameters a and b.") |
|---|
| 55 | |
|---|
| 56 | ;;; Examples and unit test |
|---|
| 57 | #| |
|---|
| 58 | (make-tests gumbel2 |
|---|
| 59 | (letm ((rng (random-number-generator *mt19937* 0))) |
|---|
| 60 | (loop for i from 0 to 10 |
|---|
| 61 | collect |
|---|
| 62 | (gumbel2 rng 1.0d0 2.0d0))) |
|---|
| 63 | (gumbel2-pdf 5.0d0 1.0d0 2.0d0) |
|---|
| 64 | (gumbel2-P 10.0d0 1.0d0 2.0d0) |
|---|
| 65 | (gumbel2-Q 10.0d0 1.0d0 2.0d0) |
|---|
| 66 | (gumbel2-Pinv 0.8187307530779818d0 1.0d0 2.0d0) |
|---|
| 67 | (gumbel2-Qinv 0.18126924692201815d0 1.0d0 2.0d0)) |
|---|
| 68 | |# |
|---|
| 69 | |
|---|
| 70 | (LISP-UNIT:DEFINE-TEST GUMBEL2 |
|---|
| 71 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 72 | (LIST |
|---|
| 73 | (LIST 7743.400858519516d0 1.102196701680339d0 |
|---|
| 74 | 1.5827044520998628d0 36.87052393317972d0 |
|---|
| 75 | 1.3675219066608615d0 2.7637257945633085d0 |
|---|
| 76 | 46.026080060263446d0 6.772683525074477d0 |
|---|
| 77 | 3.2461983686562204d0 6.640797807286079d0 |
|---|
| 78 | 7.285687897019733d0)) |
|---|
| 79 | (MULTIPLE-VALUE-LIST |
|---|
| 80 | (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0))) |
|---|
| 81 | (LOOP FOR I FROM 0 TO 10 COLLECT |
|---|
| 82 | (GUMBEL2 RNG 1.0d0 2.0d0))))) |
|---|
| 83 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 84 | (LIST 0.053625603682851145d0) |
|---|
| 85 | (MULTIPLE-VALUE-LIST (GUMBEL2-PDF 5.0d0 1.0d0 2.0d0))) |
|---|
| 86 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 87 | (LIST 0.8187307530779818d0) |
|---|
| 88 | (MULTIPLE-VALUE-LIST (GUMBEL2-P 10.0d0 1.0d0 2.0d0))) |
|---|
| 89 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 90 | (LIST 0.18126924692201815d0) |
|---|
| 91 | (MULTIPLE-VALUE-LIST (GUMBEL2-Q 10.0d0 1.0d0 2.0d0))) |
|---|
| 92 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 93 | (LIST 9.999999999999998d0) |
|---|
| 94 | (MULTIPLE-VALUE-LIST |
|---|
| 95 | (GUMBEL2-PINV 0.8187307530779818d0 1.0d0 2.0d0))) |
|---|
| 96 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 97 | (LIST 10.0d0) |
|---|
| 98 | (MULTIPLE-VALUE-LIST (GUMBEL2-QINV 0.18126924692201815d0 1.0d0 2.0d0)))) |
|---|
| 99 | |
|---|