root/trunk/random/logarithmic.lisp

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

Subversion version stamp.

  • Property svn:keywords set to Id
Line 
1;; Logarithmic distribution
2;; Liam Healy, Sat Nov 25 2006 - 16:00
3;; Time-stamp: <2008-02-17 15:36:14EST logarithmic.lisp>
4;; $Id$
5
6(in-package :gsl)
7
8(defmfun logarithmic (generator p)
9  "gsl_ran_logarithmic"
10  (((generator generator) :pointer) (p :double))
11  :c-return :uint
12  :documentation                        ; FDL
13  "A random integer from the logarithmic distribution.
14   The probability distribution for logarithmic random variates
15   is p(k) = {-1 \over \log(1-p)} {\left( p^k \over k \right)}
16   for k >= 1.")
17
18(defmfun logarithmic-pdf (k p)
19  "gsl_ran_logarithmic_pdf" ((k :uint) (p :double))
20  :c-return :double
21  :documentation
22  "The probability p(k) of obtaining k
23   from a logarithmic distribution with probability parameter p,
24   using the formula given in #'logarithmic.")
25
26;;; Examples and unit test
27#|
28(make-tests logarithmic
29  (letm ((rng (random-number-generator *mt19937* 0)))
30     (loop for i from 0 to 10
31           collect
32           (logarithmic rng 0.9d0)))
33  (logarithmic-pdf 2 0.4d0))
34|#
35
36(LISP-UNIT:DEFINE-TEST LOGARITHMIC
37  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
38   (LIST (LIST 1 3 1 4 1 1 2 1 1 5 2))
39   (MULTIPLE-VALUE-LIST
40    (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0)))
41      (LOOP FOR I FROM 0 TO 10 COLLECT
42            (LOGARITHMIC RNG 0.9d0)))))
43  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
44   (LIST 0.15660921511769743d0)
45   (MULTIPLE-VALUE-LIST (LOGARITHMIC-PDF 2 0.4d0))))
46
Note: See TracBrowser for help on using the browser.