root/trunk/random/gaussian-bivariate.lisp

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

Subversion version stamp.

  • Property svn:keywords set to Id
Line 
1;; Gaussian bivariate distribution
2;; Liam Healy, Sat Sep  2 2006 - 16:32
3;; Time-stamp: <2008-02-17 12:32:10EST gaussian-bivariate.lisp>
4;; $Id$
5
6(in-package :gsl)
7
8(defmfun bivariate-gaussian (generator sigma-x sigma-y rho)
9  "gsl_ran_bivariate_gaussian"
10  (((generator generator) :pointer) (sigma-x :double) (sigma-y :double) (rho :double)
11   (x :double) (y :double))
12  :c-return :void
13  :documentation                        ; FDL
14  "Generate a pair of correlated Gaussian variates, with
15   mean zero, correlation coefficient rho and standard deviations
16   sigma_x and sigma_y in the x and y directions.
17   The probability distribution for bivariate Gaussian random variates is,
18   p(x,y) dx dy
19   = {1 \over 2 \pi \sigma_x \sigma_y \sqrt{1-\rho^2}}
20   \exp \left(-{(x^2/\sigma_x^2 + y^2/\sigma_y^2 - 2 \rho x y/(\sigma_x\sigma_y))
21   \over 2(1-\rho^2)}\right) dx dy
22   for x,y in the range -\infty to +\infty.  The
23   correlation coefficient rho should lie between 1 and -1.")
24
25(defmfun bivariate-gaussian-pdf (x y sigma-x sigma-y rho)
26  "gsl_ran_bivariate_gaussian_pdf"
27  ((x :double) (y :double) (sigma-x :double) (sigma-y :double) (rho :double))
28  :c-return :double
29  :documentation                        ; FDL
30  "The probability density p(x,y) at
31   (x,y) for a bivariate Gaussian distribution with standard
32   deviations sigma_x, sigma_y and correlation coefficient
33   rho, using the formula given for bivariate-gaussian.")
34
35;;; Examples and unit test
36#|
37(make-tests gaussian-bivariate
38  (letm ((rng (random-number-generator *mt19937* 0)))
39      (loop for i from 0 to 10
40            collect
41            (bivariate-gaussian rng 1.0d0 0.75d0 0.25d0)))
42  (bivariate-gaussian-pdf 0.25d0 0.5d0 0.25d0
43                           0.4d0 0.2d0))
44|#
45
46(LISP-UNIT:DEFINE-TEST GAUSSIAN-BIVARIATE
47  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
48   (LIST
49    (LIST -0.06509716124488897d0 -1.5733207749096374d0
50          0.27942740172325414d0 1.2021528358889673d0
51          -0.6041530626907894d0 0.07582702719413444d0
52          -0.5446229412165632d0 -0.6592026841613081d0
53          -0.11029516610819164d0 0.17931840412143885d0
54          2.1025104980291696d0))
55   (MULTIPLE-VALUE-LIST
56    (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0)))
57      (LOOP FOR I FROM 0 TO 10 COLLECT
58            (BIVARIATE-GAUSSIAN RNG 1.0d0 0.75d0 0.25d0)))))
59  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
60   (LIST 0.5548265557970462d0)
61   (MULTIPLE-VALUE-LIST
62    (BIVARIATE-GAUSSIAN-PDF 0.25d0 0.5d0 0.25d0 0.4d0 0.2d0))))
63
Note: See TracBrowser for help on using the browser.