root/trunk/random/beta.lisp

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

Subversion version stamp.

  • Property svn:keywords set to Id
Line 
1;; Beta distribution
2;; Liam Healy, Sat Sep 30 2006
3;; Time-stamp: <2008-02-17 13:18:37EST beta.lisp>
4;; $Id$
5
6(in-package :gsl)
7
8(defmfun beta-rd (generator a b)
9  ;; Named #'beta-rd to avoid confusion with the special function #'beta.
10  "gsl_ran_beta"
11  (((generator generator) :pointer) (a :double) (b :double))
12  :c-return :double
13  :documentation                        ; FDL
14  "A random variate from the beta distribution.  The distribution function is
15   p(x) dx = {\Gamma(a+b) \over \Gamma(a) \Gamma(b)} x^{a-1} (1-x)^{b-1} dx
16   0 <= x <= 1.")
17
18(defmfun beta-pdf (x a b)
19  "gsl_ran_beta_pdf" ((x :double) (a :double) (b :double))
20  :c-return :double
21  :documentation                        ; FDL
22  "The probability density p(x) at x
23   for a beta distribution with parameters a and b, using the
24   formula given in #'beta.")
25
26(defmfun beta-P (x a b)
27  "gsl_cdf_beta_P" ((x :double) (a :double) (b :double))
28  :c-return :double
29  :documentation                        ; FDL
30  "The cumulative distribution functions
31  P(x) for the beta distribution with parameters a and b.")
32
33(defmfun beta-Q (x a b)
34  "gsl_cdf_beta_Q" ((x :double) (a :double) (b :double))
35  :c-return :double
36  :documentation                        ; FDL
37  "The cumulative distribution functions
38  Q(x) for the beta distribution with parameters a and b.")
39
40(defmfun beta-Pinv (P a b)
41  "gsl_cdf_beta_Pinv" ((P :double) (a :double) (b :double))
42  :c-return :double
43  :documentation                        ; FDL
44  "The inverse cumulative distribution functions
45  P(x) for the beta distribution with parameters a and b.")
46
47(defmfun beta-Qinv (Q a b)
48  "gsl_cdf_beta_Qinv" ((Q :double) (a :double) (b :double))
49  :c-return :double
50  :documentation                        ; FDL
51  "The inverse cumulative distribution functions
52   Q(x) for the beta distribution with parameters a and b.")
53
54;;; Examples and unit test
55#|
56(make-tests beta
57  (letm ((rng (random-number-generator *mt19937* 0)))
58      (loop for i from 0 to 10
59            collect
60            (beta-rd rng 1.0d0 2.0d0)))
61  (beta-pdf 0.1d0 1.0d0 2.0d0)
62  (beta-P 0.1d0 1.0d0 2.0d0)
63  (beta-Q 0.1d0 1.0d0 2.0d0)
64  (beta-Pinv 0.19d0 1.0d0 2.0d0)
65  (beta-Qinv 0.81d0 1.0d0 2.0d0))
66|#
67
68(LISP-UNIT:DEFINE-TEST BETA
69  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
70   (LIST
71    (LIST 8.390009419017379d-5 0.024211646813900284d0
72          0.045507713472575685d0 0.30321144534029304d0
73          0.5693572151110255d0 0.5146515206667992d0
74          0.230096194772543d0 0.3928348825648452d0
75          0.5143874122537551d0 0.2337836858050161d0
76          0.19851288668620246d0))
77   (MULTIPLE-VALUE-LIST
78    (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0)))
79      (LOOP FOR I FROM 0 TO 10 COLLECT
80            (BETA-RD RNG 1.0d0 2.0d0)))))
81  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
82   (LIST 1.8000000000000016d0)
83   (MULTIPLE-VALUE-LIST (BETA-PDF 0.1d0 1.0d0 2.0d0)))
84  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
85   (LIST 0.19000000000000017d0)
86   (MULTIPLE-VALUE-LIST (BETA-P 0.1d0 1.0d0 2.0d0)))
87  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
88   (LIST 0.8099999999999998d0)
89   (MULTIPLE-VALUE-LIST (BETA-Q 0.1d0 1.0d0 2.0d0)))
90  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
91   (LIST 0.09999999999999988d0)
92   (MULTIPLE-VALUE-LIST (BETA-PINV 0.19d0 1.0d0 2.0d0)))
93  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
94   (LIST 0.09999999999999987d0)
95   (MULTIPLE-VALUE-LIST (BETA-QINV 0.81d0 1.0d0 2.0d0))))
96
Note: See TracBrowser for help on using the browser.