beta.lisp 2.02 KB
Newer Older
1 2
;; Beta distribution
;; Liam Healy, Sat Sep 30 2006
Liam Healy's avatar
Liam Healy committed
3
;; Time-stamp: <2009-02-16 10:10:32EST beta.lisp>
lhealy's avatar
lhealy committed
4
;; $Id$
liam's avatar
liam committed
5 6 7

(in-package :gsl)

liam's avatar
liam committed
8
(defmfun beta-rd (generator a b)
liam's avatar
liam committed
9 10
  ;; Named #'beta-rd to avoid confusion with the special function #'beta.
  "gsl_ran_beta"
11
  (((mpointer generator) :pointer) (a :double) (b :double))
liam's avatar
liam committed
12
  :c-return :double
13
  :documentation			; FDL
liam's avatar
liam committed
14 15
  "A random variate from the beta distribution.  The distribution function is
   p(x) dx = {\Gamma(a+b) \over \Gamma(a) \Gamma(b)} x^{a-1} (1-x)^{b-1} dx
16
   0 <= x <= 1.")
liam's avatar
liam committed
17

liam's avatar
liam committed
18
(defmfun beta-pdf (x a b)
liam's avatar
liam committed
19 20
  "gsl_ran_beta_pdf" ((x :double) (a :double) (b :double))
  :c-return :double
21 22 23
  :documentation			; FDL
  "The probability density p(x) at x
   for a beta distribution with parameters a and b, using the
liam's avatar
liam committed
24 25
   formula given in #'beta.")

liam's avatar
liam committed
26
(defmfun beta-P (x a b)
liam's avatar
liam committed
27 28
  "gsl_cdf_beta_P" ((x :double) (a :double) (b :double))
  :c-return :double
29 30 31
  :documentation			; FDL
  "The cumulative distribution functions
  P(x) for the beta distribution with parameters a and b.")
liam's avatar
liam committed
32

liam's avatar
liam committed
33
(defmfun beta-Q (x a b)
liam's avatar
liam committed
34 35
  "gsl_cdf_beta_Q" ((x :double) (a :double) (b :double))
  :c-return :double
36 37 38
  :documentation			; FDL
  "The cumulative distribution functions
  Q(x) for the beta distribution with parameters a and b.")
liam's avatar
liam committed
39

liam's avatar
liam committed
40
(defmfun beta-Pinv (P a b)
liam's avatar
liam committed
41 42
  "gsl_cdf_beta_Pinv" ((P :double) (a :double) (b :double))
  :c-return :double
43 44 45
  :documentation			; FDL
  "The inverse cumulative distribution functions
  P(x) for the beta distribution with parameters a and b.")
liam's avatar
liam committed
46

liam's avatar
liam committed
47
(defmfun beta-Qinv (Q a b)
liam's avatar
liam committed
48 49
  "gsl_cdf_beta_Qinv" ((Q :double) (a :double) (b :double))
  :c-return :double
50 51 52
  :documentation			; FDL
  "The inverse cumulative distribution functions
   Q(x) for the beta distribution with parameters a and b.")
liam's avatar
liam committed
53 54

;;; Examples and unit test
Liam Healy's avatar
Liam Healy committed
55
(save-test beta
Liam Healy's avatar
Liam Healy committed
56
  (let ((rng (make-random-number-generator +mt19937+ 0)))
liam's avatar
liam committed
57 58
      (loop for i from 0 to 10
	    collect
liam's avatar
liam committed
59 60 61 62 63 64 65
	    (beta-rd rng 1.0d0 2.0d0)))
  (beta-pdf 0.1d0 1.0d0 2.0d0)
  (beta-P 0.1d0 1.0d0 2.0d0)
  (beta-Q 0.1d0 1.0d0 2.0d0)
  (beta-Pinv 0.19d0 1.0d0 2.0d0)
  (beta-Qinv 0.81d0 1.0d0 2.0d0))

Liam Healy's avatar
Liam Healy committed
66

liam's avatar
liam committed
67