root/trunk/random/logistic.lisp

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

Subversion version stamp.

  • Property svn:keywords set to Id
Line 
1;; Logistic distribution
2;; Liam Healy, Sat Oct  7 2006 - 16:13
3;; Time-stamp: <2008-02-17 13:20:11EST logistic.lisp>
4;; $Id$
5
6(in-package :gsl)
7
8(defmfun logistic (generator a)
9  "gsl_ran_logistic"
10  (((generator generator) :pointer) (a :double))
11  :c-return :double
12  :documentation                        ; FDL
13  "A random variate from the logistic distribution.  The distribution function is
14   p(x) dx = { \exp(-x/a) \over a (1 + \exp(-x/a))^2 } dx
15   for -\infty < x < +\infty.")
16
17(defmfun logistic-pdf (x a)
18  "gsl_ran_logistic_pdf" ((x :double) (a :double))
19  :c-return :double
20  :documentation                        ; FDL
21  "The probability density p(x) at x
22   for a logistic distribution with scale parameter a, using the
23   formula given in #'logistic.")
24
25(defmfun logistic-P (x a)
26  "gsl_cdf_logistic_P" ((x :double) (a :double))
27  :c-return :double
28  :documentation                        ; FDL
29  "The cumulative distribution functions
30  P(x) for the logistic distribution with scale parameter a.")
31
32(defmfun logistic-Q (x a)
33  "gsl_cdf_logistic_Q" ((x :double) (a :double))
34  :c-return :double
35  :documentation                        ; FDL
36  "The cumulative distribution functions
37  Q(x) for the logistic distribution with scale parameter a.")
38
39(defmfun logistic-Pinv (P a)
40  "gsl_cdf_logistic_Pinv" ((P :double) (a :double))
41  :c-return :double
42  :documentation                        ; FDL
43  "The inverse cumulative distribution functions
44  P(x) for the logistic distribution with scale parameter a.")
45
46(defmfun logistic-Qinv (Q a)
47  "gsl_cdf_logistic_Qinv" ((Q :double) (a :double))
48  :c-return :double
49  :documentation                        ; FDL
50  "The inverse cumulative distribution functions
51   Q(x) for the logistic distribution with scale parameter a.")
52
53;;; Examples and unit test
54#|
55(make-tests logistic
56  (letm ((rng (random-number-generator *mt19937* 0)))
57      (loop for i from 0 to 10
58            collect
59            (logistic rng 10.0d0)))
60  (logistic-pdf 0.5d0 1.0d0)
61  (logistic-P 0.5d0 1.0d0)
62  (logistic-Q 0.5d0 1.0d0)
63  (logistic-Pinv 0.6224593312018546d0 1.0d0)
64  (logistic-Qinv 0.37754066879814546d0 1.0d0))
65|#
66
67(LISP-UNIT:DEFINE-TEST LOGISTIC
68  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
69   (LIST
70    (LIST 82.6131993192451d0 -16.367346042668906d0
71          -9.31513272043762d0 28.87020708710654d0
72          -11.989809875784625d0 -0.6012364762000397d0
73          31.142555263622d0 10.684673721048895d0
74          1.6051840954024446d0 10.457241904701199d0
75          11.523714106294097d0))
76   (MULTIPLE-VALUE-LIST
77    (LETM ((RNG (RANDOM-NUMBER-GENERATOR *MT19937* 0)))
78      (LOOP FOR I FROM 0 TO 10 COLLECT
79            (LOGISTIC RNG 10.0d0)))))
80  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
81   (LIST 0.2350037122015945d0)
82   (MULTIPLE-VALUE-LIST (LOGISTIC-PDF 0.5d0 1.0d0)))
83  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
84   (LIST 0.6224593312018546d0)
85   (MULTIPLE-VALUE-LIST (LOGISTIC-P 0.5d0 1.0d0)))
86  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
87   (LIST 0.37754066879814546d0)
88   (MULTIPLE-VALUE-LIST (LOGISTIC-Q 0.5d0 1.0d0)))
89  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
90   (LIST 0.5000000000000001d0)
91   (MULTIPLE-VALUE-LIST
92    (LOGISTIC-PINV 0.6224593312018546d0 1.0d0)))
93  (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
94   (LIST 0.4999999999999998d0)
95   (MULTIPLE-VALUE-LIST
96    (LOGISTIC-QINV 0.37754066879814546d0 1.0d0))))
97
Note: See TracBrowser for help on using the browser.