exponential.lisp 2.99 KB
 liam committed Feb 03, 2008 1 2 ;; Exponential distribution ;; Liam Healy, Sat Sep 2 2006 - 19:04  Liam Healy committed May 25, 2010 3 ;; Time-stamp: <2010-05-24 20:46:09EDT exponential.lisp>  Liam Healy committed Dec 27, 2009 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ;; ;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy ;; Distributed under the terms of the GNU General Public License ;; ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see .  liam committed Sep 03, 2006 20   liam committed Sep 11, 2006 21 22 (in-package :gsl)  Liam Healy committed Dec 27, 2008 23 24 25 ;;; /usr/include/gsl/gsl_randist.h ;;; /usr/include/gsl/gsl_cdf.h  Liam Healy committed May 25, 2009 26 (defmfun sample  Liam Healy committed Jan 17, 2010 27  ((generator random-number-generator) (type (eql :exponential))  Liam Healy committed May 25, 2009 28  &key mu)  liam committed Sep 03, 2006 29  "gsl_ran_exponential"  Liam Healy committed Dec 27, 2008 30  (((mpointer generator) :pointer) (mu :double))  Liam Healy committed May 25, 2009 31  :definition :method  liam committed Sep 03, 2006 32  :c-return :double  liam committed Feb 03, 2008 33  :documentation ; FDL  liam committed Sep 03, 2006 34  "A random variate from the exponential distribution  liam committed Feb 03, 2008 35  with mean mu. The distribution is  liam committed Sep 03, 2006 36  p(x) dx = {1 \over \mu} \exp(-x/\mu) dx  liam committed Feb 03, 2008 37  x >= 0.")  liam committed Sep 03, 2006 38   liam committed Feb 18, 2008 39 (defmfun exponential-pdf (x mu)  liam committed Sep 03, 2006 40 41  "gsl_ran_exponential_pdf" ((x :double) (mu :double)) :c-return :double  liam committed Feb 03, 2008 42 43 44  :documentation ; FDL "The probability density p(x) at x for an exponential distribution with mean mu, using the formula  Liam Healy committed Jan 17, 2010 45  given for #'sample :exponential.")  liam committed Sep 03, 2006 46   liam committed Feb 18, 2008 47 (defmfun exponential-P (x mu)  liam committed Sep 03, 2006 48 49  "gsl_cdf_exponential_P" ((x :double) (mu :double)) :c-return :double  liam committed Feb 03, 2008 50 51 52  :documentation ; FDL "The cumulative distribution function P(x) for the exponential distribution with mean mu.")  liam committed Sep 03, 2006 53   liam committed Feb 18, 2008 54 (defmfun exponential-Q (x mu)  liam committed Sep 03, 2006 55 56  "gsl_cdf_exponential_Q" ((x :double) (mu :double)) :c-return :double  liam committed Feb 03, 2008 57 58 59  :documentation ; FDL "The cumulative distribution function Q(x) for the exponential distribution with mean mu.")  liam committed Sep 03, 2006 60   liam committed Feb 18, 2008 61 (defmfun exponential-Pinv (P mu)  liam committed Sep 03, 2006 62 63  "gsl_cdf_exponential_Pinv" ((P :double) (mu :double)) :c-return :double  liam committed Feb 03, 2008 64 65 66  :documentation ; FDL "The inverse cumulative distribution function P(x) for the exponential distribution with mean mu.")  liam committed Sep 03, 2006 67   liam committed Feb 18, 2008 68 (defmfun exponential-Qinv (Q mu)  liam committed Sep 03, 2006 69 70  "gsl_cdf_exponential_Qinv" ((Q :double) (mu :double)) :c-return :double  liam committed Feb 03, 2008 71 72 73  :documentation ; FDL "The inverse cumulative distribution function Q(x) for the exponential distribution with mean mu.")  liam committed Sep 03, 2006 74 75  ;;; Examples and unit test  Liam Healy committed Oct 25, 2008 76 (save-test exponential  Liam Healy committed Feb 16, 2009 77  (let ((rng (make-random-number-generator +mt19937+ 0)))  liam committed Sep 03, 2006 78 79  (loop for i from 0 to 10 collect  Liam Healy committed Jan 17, 2010 80  (sample rng :exponential :mu 10.0d0)))  Liam Healy committed May 25, 2010 81 82  ;; From randist/test.c ;;(testpdf (lambda (r) (exponential-pdf r 2.0d0)) :exponential :mu 2.0d0)  liam committed Feb 18, 2008 83 84 85 86 87 88  (exponential-pdf 0.0d0 10.0d0) (exponential-p 1.0d0 2.0d0) (exponential-q 1.0d0 2.0d0) (exponential-pinv 0.3934693402873666d0 2.0d0) (exponential-qinv 0.6065306597126334d0 2.0d0))