| 1 | ;; Cauchy distribution |
|---|
| 2 | ;; Liam Healy, Sat Sep 30 2006 |
|---|
| 3 | ;; Time-stamp: <2008-02-17 12:55:30EST cauchy.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | (defmfun cauchy (generator a) |
|---|
| 9 | "gsl_ran_cauchy" |
|---|
| 10 | (((generator generator) :pointer) (a :double)) |
|---|
| 11 | :c-return :double |
|---|
| 12 | :documentation ; FDL |
|---|
| 13 | "A random variate from the Cauchy distribution with |
|---|
| 14 | scale parameter a. The probability distribution for Cauchy |
|---|
| 15 | random variates is, |
|---|
| 16 | p(x) dx = {1 \over a\pi (1 + (x/a)^2) } dx |
|---|
| 17 | for x in the range -\infty to +\infty. The Cauchy |
|---|
| 18 | distribution is also known as the Lorentz distribution.") |
|---|
| 19 | |
|---|
| 20 | (defmfun cauchy-pdf (x a) |
|---|
| 21 | "gsl_ran_cauchy_pdf" ((x :double) (a :double)) |
|---|
| 22 | :c-return :double |
|---|
| 23 | :documentation ; FDL |
|---|
| 24 | "The probability density p(x) at x |
|---|
| 25 | for a Cauchy distribution with scale parameter a, using the formula |
|---|
| 26 | given for #'cauchy.") |
|---|
| 27 | |
|---|
| 28 | (defmfun cauchy-P (x a) |
|---|
| 29 | "gsl_cdf_cauchy_P" ((x :double) (a :double)) |
|---|
| 30 | :c-return :double |
|---|
| 31 | :documentation ; FDL |
|---|
| 32 | "The cumulative distribution functions |
|---|
| 33 | P(x) for the Cauchy distribution with scale parameter a.") |
|---|
| 34 | |
|---|
| 35 | (defmfun cauchy-Q (x a) |
|---|
| 36 | "gsl_cdf_cauchy_Q" ((x :double) (a :double)) |
|---|
| 37 | :c-return :double |
|---|
| 38 | :documentation ; FDL |
|---|
| 39 | "The cumulative distribution functions |
|---|
| 40 | Q(x) for the Cauchy distribution with scale parameter a.") |
|---|
| 41 | |
|---|
| 42 | (defmfun cauchy-Pinv (P a) |
|---|
| 43 | "gsl_cdf_cauchy_Pinv" ((P :double) (a :double)) |
|---|
| 44 | :c-return :double |
|---|
| 45 | :documentation ; FDL |
|---|
| 46 | "The inverse cumulative distribution functions |
|---|
| 47 | P(x) for the Cauchy distribution with scale parameter a.") |
|---|
| 48 | |
|---|
| 49 | (defmfun cauchy-Qinv (Q a) |
|---|
| 50 | "gsl_cdf_cauchy_Qinv" ((Q :double) (a :double)) |
|---|
| 51 | :c-return :double |
|---|
| 52 | :documentation ; FDL |
|---|
| 53 | "The inverse cumulative distribution functions |
|---|
| 54 | Q(x) for the Cauchy distribution with scale parameter a.") |
|---|
| 55 | |
|---|
| 56 | ;;; Examples and unit test |
|---|
| 57 | #| |
|---|
| 58 | (make-tests cauchy |
|---|
| 59 | (letm ((rng (random-number-generator *mt19937* 0))) |
|---|
| 60 | (loop for i from 0 to 10 |
|---|
| 61 | collect |
|---|
| 62 | (cauchy rng 10.0d0))) |
|---|
| 63 | (cauchy-pdf 0.0d0 10.0d0) |
|---|
| 64 | (cauchy-P 1.0d0 2.0d0) |
|---|
| 65 | (cauchy-Q 1.0d0 2.0d0) |
|---|
| 66 | (cauchy-Pinv 0.6475836176504333d0 2.0d0) |
|---|
| 67 | (cauchy-Qinv 0.35241638234956674d0 2.0d0)) |
|---|
| 68 | |# |
|---|
| 69 | |
|---|
| 70 | (LISP-UNIT:DEFINE-TEST CAUCHY |
|---|
| 71 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 72 | (LIST |
|---|
| 73 | (LIST -0.00811319915595434d0 5.617196410586812d0 |
|---|
| 74 | 12.292369828923075d0 -1.6741088357812182d0 |
|---|
| 75 | 8.909104486260928d0 211.6765861544609d0 |
|---|
| 76 | -1.3439049184367153d0 -10.364363282910663d0 |
|---|
| 77 | -79.0709314248171d0 -10.652071087998578d0 |
|---|
| 78 | -9.393948243493877d0)) |
|---|
| 79 | (MULTIPLE-VALUE-LIST |
|---|
| 80 | (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0))) |
|---|
| 81 | (LOOP FOR I FROM 0 TO 10 COLLECT |
|---|
| 82 | (CAUCHY RNG 10.0d0))))) |
|---|
| 83 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 84 | (LIST 0.03183098861837907d0) |
|---|
| 85 | (MULTIPLE-VALUE-LIST (CAUCHY-PDF 0.0d0 10.0d0))) |
|---|
| 86 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 87 | (LIST 0.6475836176504333d0) |
|---|
| 88 | (MULTIPLE-VALUE-LIST (CAUCHY-P 1.0d0 2.0d0))) |
|---|
| 89 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 90 | (LIST 0.35241638234956674d0) |
|---|
| 91 | (MULTIPLE-VALUE-LIST (CAUCHY-Q 1.0d0 2.0d0))) |
|---|
| 92 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 93 | (LIST 0.9999999999999998d0) |
|---|
| 94 | (MULTIPLE-VALUE-LIST |
|---|
| 95 | (CAUCHY-PINV 0.6475836176504333d0 2.0d0))) |
|---|
| 96 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 97 | (LIST 1.0000000000000002d0) |
|---|
| 98 | (MULTIPLE-VALUE-LIST |
|---|
| 99 | (CAUCHY-QINV 0.35241638234956674d0 2.0d0)))) |
|---|