| 1 | ;; Histogram probability distribution. |
|---|
| 2 | ;; Liam Healy, Mon Jan 1 2007 - 17:51 |
|---|
| 3 | ;; Time-stamp: <2008-02-17 18:39:49EST probability-distribution.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | (defclass histogram-pdf () |
|---|
| 9 | ((pointer |
|---|
| 10 | :initarg :pointer :accessor pointer |
|---|
| 11 | :documentation |
|---|
| 12 | "A C pointer to the GSL representation of the histogram.") |
|---|
| 13 | (number-of-bins :initarg :number-of-bins :accessor number-of-bins)) |
|---|
| 14 | (:documentation |
|---|
| 15 | "A histogram, including bin boundaries and bin contents.")) |
|---|
| 16 | |
|---|
| 17 | (defmfun alloc-1 (object) |
|---|
| 18 | "gsl_histogram_pdf_alloc" |
|---|
| 19 | (((number-of-bins object) size)) |
|---|
| 20 | :export nil |
|---|
| 21 | :index alloc |
|---|
| 22 | :c-return (cr :pointer) |
|---|
| 23 | :return ((assign-pointer object cr))) |
|---|
| 24 | |
|---|
| 25 | (defmfun alloc-2 (object) |
|---|
| 26 | "gsl_histogram2d_pdf_alloc" |
|---|
| 27 | (((number-of-bins object) size)) |
|---|
| 28 | :export nil |
|---|
| 29 | :index alloc |
|---|
| 30 | :c-return (cr :pointer) |
|---|
| 31 | :return ((assign-pointer object cr))) |
|---|
| 32 | |
|---|
| 33 | (defmethod alloc ((object histogram-pdf)) |
|---|
| 34 | (histo-1d2d object alloc)) |
|---|
| 35 | |
|---|
| 36 | (defmfun free-1 (object) |
|---|
| 37 | "gsl_histogram_pdf_free" |
|---|
| 38 | (((pointer object) :pointer)) |
|---|
| 39 | :export nil |
|---|
| 40 | :index free |
|---|
| 41 | :c-return :void) |
|---|
| 42 | |
|---|
| 43 | (defmfun free-2 (object) |
|---|
| 44 | "gsl_histogram2d_pdf_free" |
|---|
| 45 | (((pointer object) :pointer)) |
|---|
| 46 | :export nil |
|---|
| 47 | :index free |
|---|
| 48 | :c-return :void) |
|---|
| 49 | |
|---|
| 50 | (defmethod free ((object histogram-pdf)) |
|---|
| 51 | (histo-1d2d object free)) |
|---|
| 52 | |
|---|
| 53 | (defmfun pdf-init-1 (pdf histogram) |
|---|
| 54 | "gsl_histogram_pdf_init" |
|---|
| 55 | (((pointer pdf) :pointer) ((pointer histogram) :pointer)) |
|---|
| 56 | :return () |
|---|
| 57 | :export nil |
|---|
| 58 | :index pdf-init |
|---|
| 59 | :documentation ; FDL |
|---|
| 60 | "Initialize the probability distribution pdf with the contents |
|---|
| 61 | of the histogram. If any of the bins are negative then an |
|---|
| 62 | EDOM error is signalled because a probability distribution |
|---|
| 63 | cannot contain negative values.") |
|---|
| 64 | |
|---|
| 65 | (defmfun pdf-init-2 (pdf histogram) |
|---|
| 66 | "gsl_histogram2d_pdf_init" |
|---|
| 67 | (((pointer pdf) :pointer) ((pointer histogram) :pointer)) |
|---|
| 68 | :return () |
|---|
| 69 | :export nil |
|---|
| 70 | :index pdf-init |
|---|
| 71 | :documentation ; FDL |
|---|
| 72 | "Initialize the probability distribution pdf with the contents |
|---|
| 73 | of the histogram. If any of the bins are negative then an |
|---|
| 74 | EDOM error is signalled because a probability distribution |
|---|
| 75 | cannot contain negative values.") |
|---|
| 76 | |
|---|
| 77 | (export 'pdf-init) |
|---|
| 78 | (defun pdf-init (pdf histogram) ; FDL |
|---|
| 79 | "Initialize the probability distribution pdf with the contents |
|---|
| 80 | of the histogram. If any of the bins are negative then an |
|---|
| 81 | EDOM error is signalled because a probability distribution |
|---|
| 82 | cannot contain negative values." |
|---|
| 83 | (histo-1d2d pdf pdf-init (histogram))) |
|---|
| 84 | |
|---|
| 85 | (defmfun sample-1 (pdf value) |
|---|
| 86 | "gsl_histogram_pdf_sample" |
|---|
| 87 | (((pointer pdf) :pointer) (value :double)) |
|---|
| 88 | :c-return :double |
|---|
| 89 | :export nil |
|---|
| 90 | :index sample |
|---|
| 91 | :documentation ; FDL |
|---|
| 92 | "Given a uniform random number between zero and one, |
|---|
| 93 | compute a single random sample from the probability distribution |
|---|
| 94 | 'pdf. The algorithm used to compute the sample s is given by |
|---|
| 95 | s = range[i] + delta * (range[i+1] - range[i]) |
|---|
| 96 | where i is the index which satisfies |
|---|
| 97 | sum[i] <= r < sum[i+1] and delta is |
|---|
| 98 | (r - sum[i])/(sum[i+1] - sum[i]).") |
|---|
| 99 | |
|---|
| 100 | (defmfun sample-2 (pdf value) |
|---|
| 101 | "gsl_histogram2d_pdf_sample" |
|---|
| 102 | (((pointer pdf) :pointer) (value :double)) |
|---|
| 103 | :c-return :double |
|---|
| 104 | :export nil |
|---|
| 105 | :index sample |
|---|
| 106 | :documentation ; FDL |
|---|
| 107 | "Given a uniform random number between zero and one, |
|---|
| 108 | compute a single random sample from the probability distribution |
|---|
| 109 | 'pdf. The algorithm used to compute the sample s is given by |
|---|
| 110 | s = range[i] + delta * (range[i+1] - range[i]) |
|---|
| 111 | where i is the index which satisfies |
|---|
| 112 | sum[i] <= r < sum[i+1] and delta is |
|---|
| 113 | (r - sum[i])/(sum[i+1] - sum[i]).") |
|---|