| 1 | ;; Poisson distribution |
|---|
| 2 | ;; Liam Healy, Sat Nov 25 2006 - 16:00 |
|---|
| 3 | ;; Time-stamp: <2008-02-17 13:38:14EST poisson.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | (defmfun poisson (generator mu) |
|---|
| 9 | "gsl_ran_poisson" |
|---|
| 10 | (((generator generator) :pointer) (mu :double)) |
|---|
| 11 | :c-return :uint |
|---|
| 12 | :documentation ; FDL |
|---|
| 13 | "A random integer from the Poisson distribution with mean mu. |
|---|
| 14 | The probability distribution for Poisson variates is |
|---|
| 15 | p(k) = {\mu^k \over k!} \exp(-\mu) |
|---|
| 16 | k >= 0.") |
|---|
| 17 | |
|---|
| 18 | (defmfun poisson-pdf (k mu) |
|---|
| 19 | "gsl_ran_poisson_pdf" ((k :uint) (mu :double)) |
|---|
| 20 | :c-return :double |
|---|
| 21 | :documentation ; FDL |
|---|
| 22 | "The probability p(k) of obtaining k |
|---|
| 23 | from a Poisson distribution with mean mu using the formula |
|---|
| 24 | given in #'poisson.") |
|---|
| 25 | |
|---|
| 26 | (defmfun poisson-P (k mu) |
|---|
| 27 | "gsl_cdf_poisson_P" ((k :uint) (mu :double)) |
|---|
| 28 | :c-return :double |
|---|
| 29 | :documentation ; FDL |
|---|
| 30 | "The cumulative distribution functions |
|---|
| 31 | P(k) for the Poisson distribution with parameter mu.") |
|---|
| 32 | |
|---|
| 33 | (defmfun poisson-Q (k mu) |
|---|
| 34 | "gsl_cdf_poisson_Q" ((k :uint) (mu :double)) |
|---|
| 35 | :c-return :double |
|---|
| 36 | :documentation ; FDL |
|---|
| 37 | "The cumulative distribution functions |
|---|
| 38 | Q(k) for the Poisson distribution with parameter mu.") |
|---|
| 39 | |
|---|
| 40 | ;;; Examples and unit test |
|---|
| 41 | #| |
|---|
| 42 | (make-tests poisson |
|---|
| 43 | (letm ((rng (random-number-generator *mt19937* 0))) |
|---|
| 44 | (loop for i from 0 to 10 |
|---|
| 45 | collect |
|---|
| 46 | (poisson rng 10.0d0))) |
|---|
| 47 | (poisson-pdf 8 10.0d0) |
|---|
| 48 | (poisson-P 8 10.0d0) |
|---|
| 49 | (poisson-Q 8 10.0d0)) |
|---|
| 50 | |# |
|---|
| 51 | |
|---|
| 52 | (LISP-UNIT:DEFINE-TEST POISSON |
|---|
| 53 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 54 | (LIST (LIST 15 6 9 9 5 8 11 9 11 5 10)) |
|---|
| 55 | (MULTIPLE-VALUE-LIST |
|---|
| 56 | (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0))) |
|---|
| 57 | (LOOP FOR I FROM 0 TO 10 COLLECT |
|---|
| 58 | (POISSON RNG 10.0d0))))) |
|---|
| 59 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 60 | (LIST 0.11259903214902009d0) |
|---|
| 61 | (MULTIPLE-VALUE-LIST (POISSON-PDF 8 10.0d0))) |
|---|
| 62 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 63 | (LIST 0.3328196787507177d0) |
|---|
| 64 | (MULTIPLE-VALUE-LIST (POISSON-P 8 10.0d0))) |
|---|
| 65 | (LISP-UNIT::ASSERT-NUMERICAL-EQUAL |
|---|
| 66 | (LIST 0.6671803212492823d0) |
|---|
| 67 | (MULTIPLE-VALUE-LIST (POISSON-Q 8 10.0d0)))) |
|---|
| 68 | |
|---|