root/trunk/random/exponential.lisp

Revision 26, 3.1 kB (checked in by lhealy, 9 months ago)

Subversion version stamp.

  • Property svn:keywords set to Id
Line 
1;; Exponential distribution
2;; Liam Healy, Sat Sep  2 2006 - 19:04
3;; Time-stamp: <2008-02-17 12:34:11EST exponential.lisp>
4;; $Id$
5
6(in-package :gsl)
7
8(defmfun exponential (generator mu)
9  "gsl_ran_exponential"
10  (((generator generator) :pointer) (mu :double))
11  :c-return :double
12  :documentation                        ; FDL
13  "A random variate from the exponential distribution
14   with mean mu. The distribution is
15   p(x) dx = {1 \over \mu} \exp(-x/\mu) dx
16   x >= 0.")
17
18(defmfun exponential-pdf (x mu)
19  "gsl_ran_exponential_pdf" ((x :double) (mu :double))
20  :c-return :double
21  :documentation                        ; FDL
22  "The probability density p(x) at x
23  for an exponential distribution with mean mu, using the formula
24  given for exponential.")
25
26(defmfun exponential-P (x mu)
27  "gsl_cdf_exponential_P" ((x :double) (mu :double))
28  :c-return :double
29  :documentation                        ; FDL
30  "The cumulative distribution function
31   P(x) for the exponential distribution with mean mu.")
32
33(defmfun exponential-Q (x mu)
34  "gsl_cdf_exponential_Q" ((x :double) (mu :double))
35  :c-return :double
36  :documentation                        ; FDL
37  "The cumulative distribution function
38   Q(x) for the exponential distribution with mean mu.")
39
40(defmfun exponential-Pinv (P mu)
41  "gsl_cdf_exponential_Pinv" ((P :double) (mu :double))
42  :c-return :double
43  :documentation                        ; FDL
44  "The inverse cumulative distribution function
45   P(x) for the exponential distribution with mean mu.")
46
47(defmfun exponential-Qinv (Q mu)
48  "gsl_cdf_exponential_Qinv" ((Q :double) (mu :double))
49  :c-return :double
50  :documentation                        ; FDL
51  "The inverse cumulative distribution function
52   Q(x) for the exponential distribution with mean mu.")
53
54;;; Examples and unit test
55#|
56(make-tests exponential
57  (letm ((rng (random-number-generator *mt19937* 0)))
58      (loop for i from 0 to 10
59            collect
60            (exponential rng 10.0d0)))
61  (exponential-pdf 0.0d0 10.0d0)
62  (exponential-p 1.0d0 2.0d0)
63  (exponential-q 1.0d0 2.0d0)
64  (exponential-pinv 0.3934693402873666d0 2.0d0)
65  (exponential-qinv 0.6065306597126334d0 2.0d0))
66|#
67
68(LISP-UNIT:DEFINE-TEST EXPONENTIAL
69  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
70   (LIST
71    (LIST 0.0025828444588394794d0 18.145581427987647d0
72          12.636598054339759d0 0.5424387252062355d0
73          14.624994234158105d0 7.236607929535993d0
74          0.4345362449683603d0 2.95303920904529d0
75          6.161052939065796d0 3.011686333539114d0
76          2.7451079819355364d0))
77   (MULTIPLE-VALUE-LIST
78    (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0)))
79      (LOOP FOR I FROM 0 TO 10 COLLECT
80            (EXPONENTIAL RNG 10.0d0)))))
81  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL (LIST 0.1d0)
82                                     (MULTIPLE-VALUE-LIST
83                                      (EXPONENTIAL-PDF
84                                       0.0d0 10.0d0)))
85  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
86   (LIST 0.3934693402873666d0)
87   (MULTIPLE-VALUE-LIST (EXPONENTIAL-P 1.0d0 2.0d0)))
88  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
89   (LIST 0.6065306597126334d0)
90   (MULTIPLE-VALUE-LIST (EXPONENTIAL-Q 1.0d0 2.0d0)))
91  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL (LIST 1.0d0)
92                                     (MULTIPLE-VALUE-LIST
93                                      (EXPONENTIAL-PINV
94                                       0.3934693402873666d0
95                                       2.0d0)))
96  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL (LIST 1.0d0)
97                                     (MULTIPLE-VALUE-LIST
98                                      (EXPONENTIAL-QINV
99                                       0.6065306597126334d0
100                                       2.0d0))))
Note: See TracBrowser for help on using the browser.