| 1 | ;; Exponential distribution |
|---|
| 2 | ;; Liam Healy, Sun Sep 17 2006 |
|---|
| 3 | ;; Time-stamp: <2008-02-17 12:50:28EST laplace.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | (defmfun laplace (generator a) |
|---|
| 9 | "gsl_ran_laplace" |
|---|
| 10 | (((generator generator) :pointer) (a :double)) |
|---|
| 11 | :c-return :double |
|---|
| 12 | :documentation ; FDL |
|---|
| 13 | "A random variate from the Laplace distribution with width a. |
|---|
| 14 | The distribution is |
|---|
| 15 | p(x) dx = {1 \over 2 a} \exp(-|x/a|) dx |
|---|
| 16 | for -\infty < x < \infty.") |
|---|
| 17 | |
|---|
| 18 | (defmfun laplace-pdf (x a) |
|---|
| 19 | "gsl_ran_laplace_pdf" ((x :double) (a :double)) |
|---|
| 20 | :c-return :double |
|---|
| 21 | :documentation ; FDL |
|---|
| 22 | "The probability density p(x) at x |
|---|
| 23 | for a Laplace distribution with width a, using the formula |
|---|
| 24 | given for #'laplace.") |
|---|
| 25 | |
|---|
| 26 | (defmfun laplace-P (x a) |
|---|
| 27 | "gsl_cdf_laplace_P" ((x :double) (a :double)) |
|---|
| 28 | :c-return :double |
|---|
| 29 | :documentation ; FDL |
|---|
| 30 | "The cumulative distribution function |
|---|
| 31 | P(x) for the laplace distribution with width a.") |
|---|
| 32 | |
|---|
| 33 | (defmfun laplace-Q (x a) |
|---|
| 34 | "gsl_cdf_laplace_Q" ((x :double) (a :double)) |
|---|
| 35 | :c-return :double |
|---|
| 36 | :documentation ; FDL |
|---|
| 37 | "The cumulative distribution function |
|---|
| 38 | Q(x) for the laplace distribution with width a.") |
|---|
| 39 | |
|---|
| 40 | (defmfun laplace-Pinv (P a) |
|---|
| 41 | "gsl_cdf_laplace_Pinv" ((P :double) (a :double)) |
|---|
| 42 | :c-return :double |
|---|
| 43 | :documentation ; FDL |
|---|
| 44 | "The inverse cumulative distribution function |
|---|
| 45 | P(x) for the laplace distribution with width a.") |
|---|
| 46 | |
|---|
| 47 | (defmfun laplace-Qinv (Q a) |
|---|
| 48 | "gsl_cdf_laplace_Qinv" ((Q :double) (a :double)) |
|---|
| 49 | :c-return :double |
|---|
| 50 | :documentation ; FDL |
|---|
| 51 | "The inverse cumulative distribution function |
|---|
| 52 | Q(x) for the laplace distribution with width a.") |
|---|
| 53 | |
|---|
| 54 | ;;; Examples and unit test |
|---|
| 55 | #| |
|---|
| 56 | (make-tests laplace |
|---|
| 57 | (letm ((rng (random-number-generator *mt19937* 0))) |
|---|
| 58 | (loop for i from 0 to 10 |
|---|
| 59 | collect |
|---|
| 60 | (laplace rng 10.0d0))) |
|---|
| 61 | (laplace-pdf 0.0d0 10.0d0) |
|---|
| 62 | (laplace-p 1.0d0 2.0d0) |
|---|
| 63 | (laplace-q 1.0d0 2.0d0) |
|---|
| 64 | (laplace-pinv 0.6967346701436833d0 2.0d0) |
|---|
| 65 | (laplace-qinv 0.3032653298563167d0 2.0d0)) |
|---|
| 66 | |# |
|---|
| 67 | |
|---|
| 68 | (LISP-UNIT:DEFINE-TEST LAPLACE |
|---|
| 69 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 70 | (LIST |
|---|
| 71 | (LIST 0.005166356198580803d0 -3.942577717493807d0 |
|---|
| 72 | -8.329510281601332d0 1.1159975704649974d0 |
|---|
| 73 | -6.2234038148786555d0 -35.04800398421181d0 |
|---|
| 74 | 0.8888158320028845d0 7.161892491969776d0 |
|---|
| 75 | 25.24637780914261d0 7.341651048064451d0 |
|---|
| 76 | 6.54142651602034d0)) |
|---|
| 77 | (MULTIPLE-VALUE-LIST |
|---|
| 78 | (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0))) |
|---|
| 79 | (LOOP FOR I FROM 0 TO 10 COLLECT |
|---|
| 80 | (LAPLACE RNG 10.0d0))))) |
|---|
| 81 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 82 | (LIST 0.05d0) |
|---|
| 83 | (MULTIPLE-VALUE-LIST (LAPLACE-PDF 0.0d0 10.0d0))) |
|---|
| 84 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 85 | (LIST 0.6967346701436833d0) |
|---|
| 86 | (MULTIPLE-VALUE-LIST (LAPLACE-P 1.0d0 2.0d0))) |
|---|
| 87 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 88 | (LIST 0.3032653298563167d0) |
|---|
| 89 | (MULTIPLE-VALUE-LIST (LAPLACE-Q 1.0d0 2.0d0))) |
|---|
| 90 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 91 | (LIST 1.0d0) |
|---|
| 92 | (MULTIPLE-VALUE-LIST (LAPLACE-PINV 0.6967346701436833d0 2.0d0))) |
|---|
| 93 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 94 | (LIST 1.0d0) |
|---|
| 95 | (MULTIPLE-VALUE-LIST (LAPLACE-QINV 0.3032653298563167d0 2.0d0)))) |
|---|