| 1 | ;; Exponential power distribution |
|---|
| 2 | ;; Liam Healy, Sat Sep 30 2006 |
|---|
| 3 | ;; Time-stamp: <2008-02-17 12:53:01EST exponential-power.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | (defmfun exponential-power (generator a b) |
|---|
| 9 | "gsl_ran_exppow" |
|---|
| 10 | (((generator generator) :pointer) (a :double) (b :double)) |
|---|
| 11 | :c-return :double |
|---|
| 12 | :documentation ; FDL |
|---|
| 13 | "A random variate from the exponential power distribution |
|---|
| 14 | with scale parameter a and exponent b. The distribution is |
|---|
| 15 | p(x) dx = {1 \over 2 a \Gamma(1+1/b)} \exp(-|x/a|^b) dx |
|---|
| 16 | for x >= 0. For b = 1 this reduces to the Laplace |
|---|
| 17 | distribution. For b = 2 it has the same form as a gaussian |
|---|
| 18 | distribution, but with a = \sqrt{2} \sigma.") |
|---|
| 19 | |
|---|
| 20 | (defmfun exponential-power-pdf (x a b) |
|---|
| 21 | "gsl_ran_exppow_pdf" |
|---|
| 22 | ((x :double) (a :double) (b :double)) |
|---|
| 23 | :c-return :double |
|---|
| 24 | :documentation ; FDL |
|---|
| 25 | "The probability density p(x) at x |
|---|
| 26 | for an exponential power distribution with scale parameter a |
|---|
| 27 | and exponent b, using the formula given for #'exponential-power.") |
|---|
| 28 | |
|---|
| 29 | (defmfun exponential-power-P (x a b) |
|---|
| 30 | "gsl_cdf_exppow_P" ((x :double) (a :double) (b :double)) |
|---|
| 31 | :c-return :double |
|---|
| 32 | :documentation ; FDL |
|---|
| 33 | "The cumulative distribution function |
|---|
| 34 | P(x), for the exponential power distribution with |
|---|
| 35 | parameters a and b.") |
|---|
| 36 | |
|---|
| 37 | (defmfun exponential-power-Q (x a b) |
|---|
| 38 | "gsl_cdf_exppow_Q" ((x :double) (a :double) (b :double)) |
|---|
| 39 | :c-return :double |
|---|
| 40 | :documentation ; FDL |
|---|
| 41 | "The cumulative distribution functions Q(x) |
|---|
| 42 | for the exponential power distribution with |
|---|
| 43 | parameters a and b.") |
|---|
| 44 | |
|---|
| 45 | ;;; Examples and unit test |
|---|
| 46 | #| |
|---|
| 47 | (make-tests exponential-power |
|---|
| 48 | (letm ((rng (random-number-generator *mt19937* 0))) |
|---|
| 49 | (loop for i from 0 to 10 |
|---|
| 50 | collect |
|---|
| 51 | (exponential-power rng 1.0d0 2.0d0))) |
|---|
| 52 | (exponential-power-pdf 0.0d0 1.0d0 2.0d0) |
|---|
| 53 | (exponential-power-P 1.0d0 1.0d0 2.0d0) |
|---|
| 54 | (exponential-power-Q 1.0d0 1.0d0 2.0d0)) |
|---|
| 55 | |# |
|---|
| 56 | |
|---|
| 57 | (LISP-UNIT:DEFINE-TEST EXPONENTIAL-POWER |
|---|
| 58 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 59 | (LIST |
|---|
| 60 | (LIST 0.09469475592777954d0 -0.06229680875327071d0 |
|---|
| 61 | 1.183985538537803d0 0.5187626019237904d0 |
|---|
| 62 | 0.7053564314063956d0 -0.9033303844569821d0 |
|---|
| 63 | -1.6947336289940842d0 -0.4803236108055401d0 |
|---|
| 64 | -0.027641736349912214d0 0.6318391856046153d0 |
|---|
| 65 | -0.012478875227423025d0)) |
|---|
| 66 | (MULTIPLE-VALUE-LIST |
|---|
| 67 | (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0))) |
|---|
| 68 | (LOOP FOR I FROM 0 TO 10 COLLECT |
|---|
| 69 | (EXPONENTIAL-POWER RNG 1.0d0 2.0d0))))) |
|---|
| 70 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 71 | (LIST 0.5641895835477557d0) |
|---|
| 72 | (MULTIPLE-VALUE-LIST |
|---|
| 73 | (EXPONENTIAL-POWER-PDF 0.0d0 1.0d0 2.0d0))) |
|---|
| 74 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 75 | (LIST 0.9213503964748571d0) |
|---|
| 76 | (MULTIPLE-VALUE-LIST |
|---|
| 77 | (EXPONENTIAL-POWER-P 1.0d0 1.0d0 2.0d0))) |
|---|
| 78 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 79 | (LIST 0.07864960352514248d0) |
|---|
| 80 | (MULTIPLE-VALUE-LIST |
|---|
| 81 | (EXPONENTIAL-POWER-Q 1.0d0 1.0d0 2.0d0)))) |
|---|