probability-distribution.lisp 1.81 KB
Newer Older
1 2
;; Histogram probability distribution.
;; Liam Healy, Mon Jan  1 2007 - 17:51
3
;; Time-stamp: <2008-12-26 18:38:41EST probability-distribution.lisp>
lhealy's avatar
lhealy committed
4
;; $Id$
liam's avatar
liam committed
5 6 7

(in-package :gsl)

8 9
;;; /usr/include/gsl/gsl_histogram.h
;;; /usr/include/gsl/gsl_histogram2d.h
liam's avatar
liam committed
10

11 12 13 14 15
(defmobject histogram-pdf
    "gsl_histogram_pdf"
  ((number-of-bins sizet))
  "one-dimensional histogram PDF"
  "Optionally initialize the probability distribution pdf with the contents
liam's avatar
liam committed
16
   of the histogram.  If any of the bins are negative then an
17
   input-domain error is signalled because a probability distribution
18 19 20 21 22 23 24 25 26
   cannot contain negative values."
  "init"
  (((mpointer histogram) :pointer)))

(defmobject histogram2d-pdf
    "gsl_histogram2d_pdf"
  ((number-of-bins-x sizet) (number-of-bins-y sizet))
  "two-dimensional histogram PDF"
  "Optionally initialize the probability distribution pdf with the contents
liam's avatar
liam committed
27
   of the histogram.  If any of the bins are negative then an
28
   input-domain error is signalled because a probability distribution
liam's avatar
liam committed
29
   cannot contain negative values."
30 31
  "init"
  (((mpointer histogram) :pointer)))
liam's avatar
liam committed
32

33 34 35 36
(export 'sample)
(defgeneric sample (pdf value)
  (:documentation ;; FDL
   "Given a uniform random number between zero and one,
liam's avatar
liam committed
37
   compute a single random sample from the probability distribution
liam's avatar
liam committed
38
   'pdf.  The algorithm used to compute the sample s is given by
liam's avatar
liam committed
39
   s = range[i] + delta * (range[i+1] - range[i])
liam's avatar
liam committed
40 41
   where i is the index which satisfies 
   sum[i] <=  r < sum[i+1] and delta is 
42 43 44 45 46 47 48
   (r - sum[i])/(sum[i+1] - sum[i])."))

(defmfun sample ((pdf histogram-pdf) value)
  "gsl_histogram_pdf_sample"
  (((mpointer pdf) :pointer) (value :double))
  :definition :method
  :c-return :double)
liam's avatar
liam committed
49

50
(defmfun sample ((pdf histogram2d-pdf) value)
liam's avatar
liam committed
51
  "gsl_histogram2d_pdf_sample"
Liam Healy's avatar
Liam Healy committed
52
  (((mpointer pdf) :pointer) (value :double))
53 54
  :definition :method
  :c-return :double)