root/trunk/random/gaussian-tail.lisp

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

Subversion version stamp.

  • Property svn:keywords set to Id
Line 
1;; Gaussian tail distribution
2;; Liam Healy, Mon Aug 21 2006 - 21:52
3;; Time-stamp: <2008-02-17 12:28:20EST gaussian-tail.lisp>
4;; $Id$
5
6(in-package :gsl)
7
8(defmfun gaussian-tail (generator a sigma)
9  "gsl_ran_gaussian_tail"
10  (((generator generator) :pointer) (a :double) (sigma :double))
11  :c-return :double
12  :documentation                        ; FDL
13  "Random variates from the upper tail of a Gaussian
14   distribution with standard deviation sigma.  The values returned
15   are larger than the lower limit a, which must be positive.  The
16   method is based on Marsaglia's famous rectangle-wedge-tail algorithm (Ann.
17   Math. Stat. 32, 894--899 (1961)), with this aspect explained in Knuth, v2,
18   3rd ed, p139,586 (exercise 11).
19   The probability distribution for Gaussian tail random variates is,
20   p(x) dx = {1 \over N(a;\sigma) \sqrt{2 \pi \sigma^2}}
21                  \exp (- x^2 / 2\sigma^2) dx
22   for x > a where N(a;\sigma) is the normalization constant,
23   N(a;\sigma) = (1/2) erfc(a / sqrt(2 sigma^2)).")
24
25(defmfun gaussian-tail-pdf (x a sigma)
26  "gsl_ran_gaussian_tail_pdf" ((x :double) (a :double) (sigma :double))
27  :c-return :double
28  :documentation                        ; FDL
29  "The probability density p(x) at x
30  for a Gaussian tail distribution with standard deviation sigma and
31  lower limit a, using the formula given for gaussian-tail.")
32
33(defmfun ugaussian-tail (generator a)
34  "gsl_ran_ugaussian_tail"
35  (((generator generator) :pointer) (a :double))
36  :c-return :double
37  :documentation                        ; FDL
38  "Equivalent to gaussian-tail with sigma=1.")
39
40(defmfun ugaussian-tail-pdf (x a)
41  "gsl_ran_ugaussian_tail_pdf" ((x :double) (a :double))
42  :c-return :double
43  :documentation                        ; FDL
44  "Equivalent to gaussian-tail-pdf with sigma=1.")
45
46;;; Examples and unit test
47#|
48(make-tests
49 gaussian-tail
50 (letm ((rng (random-number-generator *mt19937* 0)))
51   (loop for i from 0 to 10
52         collect
53         (gaussian-tail rng 50.0d0 10.0d0)))
54 (gaussian-tail-pdf 52.0d0 50.0d0 10.0d0)
55 (letm ((rng (random-number-generator *mt19937* 0)))
56     (loop for i from 0 to 10
57           collect
58           (ugaussian-tail rng 5.0d0)))
59 (ugaussian-tail-pdf 5.2d0 5.0d0))
60|#
61
62(LISP-UNIT:DEFINE-TEST GAUSSIAN-TAIL
63  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
64   (LIST
65    (LIST 50.10837030381376d0 51.42695945309931d0
66          50.587160269982604d0 50.59875222444504d0
67          50.82830572864337d0 50.43343112125345d0
68          53.442286287287374d0 51.83761714183811d0
69          53.00107421429086d0 52.149774169929884d0
70          50.11572443504253d0))
71   (MULTIPLE-VALUE-LIST
72    (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0)))
73      (LOOP FOR I FROM 0 TO 10 COLLECT
74            (GAUSSIAN-TAIL RNG 50.0d0 10.0d0)))))
75  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
76   (LIST 0.18702270877331703d0)
77   (MULTIPLE-VALUE-LIST
78    (GAUSSIAN-TAIL-PDF 52.0d0 50.0d0 10.0d0)))
79  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
80   (LIST
81    (LIST 5.010837030381376d0 5.142695945309931d0
82          5.05871602699826d0 5.0598752224445045d0
83          5.082830572864337d0 5.043343112125345d0
84          5.344228628728738d0 5.183761714183811d0
85          5.300107421429086d0 5.214977416992989d0
86          5.011572443504253d0))
87   (MULTIPLE-VALUE-LIST
88    (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0)))
89      (LOOP FOR I FROM 0 TO 10 COLLECT
90            (UGAUSSIAN-TAIL RNG 5.0d0)))))
91  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
92   (LIST 1.8702270877331704d0)
93   (MULTIPLE-VALUE-LIST (UGAUSSIAN-TAIL-PDF 5.2d0 5.0d0))))
Note: See TracBrowser for help on using the browser.