root/trunk/random/tdist.lisp

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

Subversion version stamp.

  • Property svn:keywords set to Id
Line 
1;; Tdist distribution
2;; Liam Healy, Sat Oct  7 2006 - 16:13
3;; Time-stamp: <2008-02-17 13:16:23EST tdist.lisp>
4;; $Id$
5
6(in-package :gsl)
7
8(defmfun tdist (generator nu)
9  "gsl_ran_tdist"
10  (((generator generator) :pointer) (nu :double))
11  :c-return :double
12  :documentation                        ; FDL
13  "A random variate from the Student t-distribution.  The
14   distribution function is,
15   p(x) dx = {\Gamma((\nu + 1)/2) \over \sqrt{\pi \nu} \Gamma(\nu/2)}
16   (1 + x^2/\nu)^{-(\nu + 1)/2} dx
17   for -\infty < x < +\infty.")
18
19(defmfun tdist-pdf (x nu)
20  "gsl_ran_tdist_pdf" ((x :double) (nu :double))
21  :c-return :double
22  :documentation                        ; FDL
23  "The probability density p(x) at x
24   for a t-distribution with nu degrees of freedom, using the formula
25   given in #'tdist.")
26
27(defmfun tdist-P (x nu)
28  "gsl_cdf_tdist_P" ((x :double) (nu :double))
29  :c-return :double
30  :documentation                        ; FDL
31  "The cumulative distribution functions
32  P(x) for the tdist distribution with nu degrees of freedom.")
33
34(defmfun tdist-Q (x nu)
35  "gsl_cdf_tdist_Q" ((x :double) (nu :double))
36  :c-return :double
37  :documentation                        ; FDL
38  "The cumulative distribution functions
39   Q(x) for the tdist distribution with nu degrees of freedom.")
40
41(defmfun tdist-Pinv (P nu)
42  "gsl_cdf_tdist_Pinv" ((P :double) (nu :double))
43  :c-return :double
44  :documentation                        ; FDL
45  "The inverse cumulative distribution functions
46   P(x) for the tdist distribution with nu degrees of freedom.")
47
48(defmfun tdist-Qinv (Q nu)
49  "gsl_cdf_tdist_Qinv" ((Q :double) (nu :double))
50  :c-return :double
51  :documentation                        ; FDL
52  "The inverse cumulative distribution functions
53   Q(x) for the tdist distribution with nu degrees of freedom.")
54
55;;; Examples and unit test
56#|
57(make-tests tdist
58  (letm ((rng (random-number-generator *mt19937* 0)))
59      (rng-set rng 0)
60      (loop for i from 0 to 10
61            collect
62            (tdist rng 10.0d0)))
63  (tdist-pdf 0.5d0 1.0d0)
64  (tdist-P 0.5d0 1.0d0)
65  (tdist-Q 0.5d0 1.0d0)
66  (tdist-Pinv 0.6475836176504334d0 1.0d0)
67  (tdist-Qinv 0.3524163823495667d0 1.0d0))
68|#
69
70(LISP-UNIT:DEFINE-TEST TDIST
71  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
72   (LIST
73    (LIST 0.14989366374481017d0 0.6794142879291215d0
74          -1.615833951108472d0 -1.6008862825783456d0
75          -1.7010935505767397d0 -0.04370959749808691d0
76          0.12761159276595174d0 -0.019731218255494867d0
77          -0.6534666117199732d0 0.2035771324523077d0
78          1.77650300477611d0))
79   (MULTIPLE-VALUE-LIST
80    (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0)))
81      (RNG-SET RNG 0)
82      (LOOP FOR I FROM 0 TO 10 COLLECT
83            (TDIST RNG 10.0d0)))))
84  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
85   (LIST 0.2546479089470325d0)
86   (MULTIPLE-VALUE-LIST (TDIST-PDF 0.5d0 1.0d0)))
87  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
88   (LIST 0.6475836176504332d0)
89   (MULTIPLE-VALUE-LIST (TDIST-P 0.5d0 1.0d0)))
90  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
91   (LIST 0.35241638234956685d0)
92   (MULTIPLE-VALUE-LIST (TDIST-Q 0.5d0 1.0d0)))
93  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
94   (LIST 0.500000000000001d0)
95   (MULTIPLE-VALUE-LIST
96    (TDIST-PINV 0.6475836176504334d0 1.0d0)))
97  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
98   (LIST 0.5d0)
99   (MULTIPLE-VALUE-LIST (TDIST-QINV 0.3524163823495667d0 1.0d0))))
Note: See TracBrowser for help on using the browser.