root/trunk/random/pareto.lisp

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

Subversion version stamp.

  • Property svn:keywords set to Id
Line 
1;; Pareto distribution
2;; Liam Healy, Sat Oct  8 2006 - 21:23
3;; Time-stamp: <2008-02-17 13:23:00EST pareto.lisp>
4;; $Id$
5
6(in-package :gsl)
7
8(defmfun pareto (generator a b)
9  "gsl_ran_pareto"
10  (((generator generator) :pointer) (a :double) (b :double))
11  :c-return :double
12  :documentation                        ; FDL
13  "A random variate from the Pareto distribution of order a.
14   The distribution function is
15   p(x) dx = (a/b) / (x/b)^{a+1} dx
16   x >= b.")
17
18(defmfun pareto-pdf (x a b)
19  "gsl_ran_pareto_pdf" ((x :double) (a :double) (b :double))
20  :c-return :double
21  :documentation                        ; FDL
22  "The probability density p(x) at x
23   for a Pareto distribution with exponent a and scale b, using
24   the formula given in #'pareto.")
25
26(defmfun pareto-P (x a b)
27  "gsl_cdf_pareto_P" ((x :double) (a :double) (b :double))
28  :c-return :double
29  :documentation                        ; FDL
30  "The cumulative distribution functions
31  P(x) for the Pareto distribution with exponent a and scale b.")
32
33(defmfun pareto-Q (x a b)
34  "gsl_cdf_pareto_Q" ((x :double) (a :double) (b :double))
35  :c-return :double
36  :documentation                        ; FDL
37  "The cumulative distribution functions
38  Q(x) for the Pareto distribution with exponent a and scale b.")
39
40(defmfun pareto-Pinv (P a b)
41  "gsl_cdf_pareto_Pinv" ((P :double) (a :double) (b :double))
42  :c-return :double
43  :documentation                        ; FDL
44  "The inverse cumulative distribution functions
45  P(x) for the Pareto distribution with exponent a and scale b.")
46
47(defmfun pareto-Qinv (Q a b)
48  "gsl_cdf_pareto_Qinv" ((Q :double) (a :double) (b :double))
49  :c-return :double
50  :documentation                        ; FDL
51  "The inverse cumulative distribution functions
52   Q(x) for the Pareto distribution with exponent a and scale b.")
53
54;;; Examples and unit test
55#|
56(make-tests pareto
57  (letm ((rng (random-number-generator *mt19937* 0)))
58      (loop for i from 0 to 10
59            collect
60            (pareto rng 1.0d0 2.0d0)))
61  (pareto-pdf 1.5d0 1.3d0 1.0d0)
62  (pareto-P 3.5d0 1.3d0 2.0d0)
63  (pareto-Q 3.5d0 1.3d0 2.0d0)
64  (pareto-Pinv 0.5168849835182453d0 1.3d0 2.0d0)
65  (pareto-Qinv 0.4831150164817547d0 1.3d0 2.0d0))
66|#
67
68(LISP-UNIT:DEFINE-TEST PARETO
69  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
70   (LIST
71    (LIST 2.0005166356083666d0 12.276726596218747d0
72          7.076694965937239d0 2.111484074469764d0
73          8.633470811095883d0 4.123935696449152d0
74          2.0888231161547828d0 2.6870692498025632d0
75          3.703404287965457d0 2.7028744394290123d0
76          2.631773566385122d0))
77   (MULTIPLE-VALUE-LIST
78    (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0)))
79      (LOOP FOR I FROM 0 TO 10 COLLECT
80            (PARETO RNG 1.0d0 2.0d0)))))
81  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
82   (LIST 0.5116034405707658d0)
83   (MULTIPLE-VALUE-LIST (PARETO-PDF 1.5d0 1.3d0 1.0d0)))
84  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
85   (LIST 0.5168849835182453d0)
86   (MULTIPLE-VALUE-LIST (PARETO-P 3.5d0 1.3d0 2.0d0)))
87  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
88   (LIST 0.4831150164817547d0)
89   (MULTIPLE-VALUE-LIST (PARETO-Q 3.5d0 1.3d0 2.0d0)))
90  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
91   (LIST 3.5000000000000004d0)
92   (MULTIPLE-VALUE-LIST
93    (PARETO-PINV 0.5168849835182453d0 1.3d0 2.0d0)))
94  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
95   (LIST 3.5000000000000004d0)
96   (MULTIPLE-VALUE-LIST
97    (PARETO-QINV 0.4831150164817547d0 1.3d0 2.0d0))))
98
Note: See TracBrowser for help on using the browser.