diff --git a/gsll.asd b/gsll.asd index 893577edde43bdabf6faa76d87df2de567d67024..f05c8c5b0fd3c71ec107ff6adaebfc5c84bc593e 100644 --- a/gsll.asd +++ b/gsll.asd @@ -1,6 +1,6 @@ ;; Definition of GSLL system ;; Liam Healy -;; Time-stamp: <2008-08-17 09:39:54EDT gsll.asd> +;; Time-stamp: <2008-08-20 22:35:48EDT gsll.asd> ;; $Id$ (asdf:defsystem "gsll" @@ -134,7 +134,6 @@ (:file "hypergeometric" :depends-on (rng-types)) (:file "logarithmic" :depends-on (rng-types)) (:file "shuffling-sampling" :depends-on (rng-types)))) - #+no (:module statistics :depends-on (init data) :components diff --git a/init/defmfun.lisp b/init/defmfun.lisp index d2ff4c308f076d29fef659abddd9b3556013cab4..5bcf0b66ed87fd1abc9825600f7e1d3c94890451 100644 --- a/init/defmfun.lisp +++ b/init/defmfun.lisp @@ -1,6 +1,6 @@ ;; Macro for defining GSL functions. ;; Liam Healy 2008-04-16 20:49:50EDT defmfun.lisp -;; Time-stamp: <2008-08-17 18:14:19EDT defmfun.lisp> +;; Time-stamp: <2008-08-20 21:05:54EDT defmfun.lisp> ;; $Id$ (in-package :gsl) @@ -9,6 +9,14 @@ ;;;; Macro defmfun ;;;;**************************************************************************** +;;; Demfun is the main macro for defining functions (ordinary +;;; functions, generic functions, and methods) tthat call GSL +;;; functions. It takes care of mapping the data from CL to C and +;;; then back out from C to CL. Where the GSL function returns a +;;; condition code, it will insert a check that turns that result into +;;; a CL warning. For generic functions and methods, it will generate +;;; the interfaces to all the specific GSL functions. + ;;; Required arguments to defmfun: ;;; name The name of the function being defined in CL ;;; arglist The CL argument list for the function diff --git a/statistics/absolute-deviation.lisp b/statistics/absolute-deviation.lisp index 9401a9a9777e334fd54981d30e3680d7dbf6f21c..9eb1986ab2467a163f69c6edb7231cac898cc8ff 100644 --- a/statistics/absolute-deviation.lisp +++ b/statistics/absolute-deviation.lisp @@ -1,6 +1,6 @@ ;; Absolute deviation ;; Liam Healy, Sun Dec 31 2006 - 13:19 -;; Time-stamp: <2008-03-09 19:21:48EDT absolute-deviation.lisp> +;; Time-stamp: <2008-08-20 22:14:51EDT absolute-deviation.lisp> ;; $Id$ (in-package :gsl) @@ -8,70 +8,40 @@ ;;; To do: stride other than 1 when that information is availble from ;;; the vector. -(defmfun absolute-deviation-nom (data) - "gsl_stats_absdev" - (((gsl-array data) :pointer) (1 :int) ((dim0 data) size)) +(defmfun absolute-deviation ((data vector) &optional mean) + (("gsl_stats" :type "_absdev") + ("gsl_stats" :type "_absdev_m")) + ((((c-pointer data) :pointer) (1 :int) ((dim0 data) sizet)) + (((c-pointer data) :pointer) (1 :int) ((dim0 data) sizet) + (mean :double))) + :definition :generic + :element-types :no-complex :c-return :double - :index absolute-deviation - :export nil :documentation ; FDL - "The absolute deviation from the mean of data. The - absolute deviation from the mean is defined as - absdev = (1/N) \sum |x_i - \Hat\mu| - where x_i are the elements of the dataset data. The - absolute deviation from the mean provides a more robust measure of the - width of a distribution than the variance. This function computes the - mean of data via a call to #'mean.") + "The absolute deviation from the mean of data. The absolute + deviation from the mean is defined as absdev = (1/N) \sum |x_i - + \Hat\mu| where x_i are the elements of the dataset data. The + absolute deviation from the mean provides a more robust measure of + the width of a distribution than the variance. If 'mean is not + supplied, this function computes the mean of data via a call to + #'mean. With mean supplied, this function is useful if you have + already computed the mean of data (and want to avoid recomputing + it), or wish to calculate the absolute deviation relative to another + value (such as zero, or the median).") -(defmfun absolute-deviation-m (data mean) - "gsl_stats_absdev_m" - (((gsl-array data) :pointer) (1 :int) - ((dim0 data) size) (mean :double)) +(defmfun weighted-absolute-deviation ((data vector) (weights vector) &optional mean) + (("gsl_stats" :type "_wabsdev") + ("gsl_stats" :type "_wabsdev_m")) + ((((c-pointer weights) :pointer) (1 :int) + ((c-pointer data) :pointer) (1 :int) + ((dim0 data) sizet)) + (((c-pointer weights) :pointer) (1 :int) + ((c-pointer data) :pointer) (1 :int) + ((dim0 data) sizet) (mean :double))) + :definition :generic + :element-types :float :c-return :double - :index absolute-deviation - :export nil :documentation ; FDL - "The absolute deviation of the dataset data - relative to the given value of mean, - absdev = (1/N) \sum |x_i - mean|. - This function is useful if you have already computed the mean of - data (and want to avoid recomputing it), or wish to calculate the - absolute deviation relative to another value (such as zero, or the - median).") - -(export 'absolute-deviation) -(defun-optionals absolute-deviation (data &optional mean) - -nom -m - ;; FDL - "The absolute deviation from the mean of data. The - absolute deviation from the mean is defined as - absdev = (1/N) \sum |x_i - \Hat\mu| - where x_i are the elements of the dataset data. The - absolute deviation from the mean provides a more robust measure of the - width of a distribution than the variance. This function computes the - mean of data via a call to #'mean.") - -(defmfun weighted-absolute-deviation-nom (data weights) - "gsl_stats_wabsdev" - (((gsl-array weights) :pointer) (1 :int) - ((gsl-array data) :pointer) (1 :int) ((dim0 data) size)) - :c-return :double - :index weighted-absolute-deviation - :export nil) - -(defmfun weighted-absolute-deviation-m (data weights mean) - "gsl_stats_wabsdev_m" - (((gsl-array weights) :pointer) (1 :int) - ((gsl-array data) :pointer) (1 :int) - ((dim0 data) size) (mean :double)) - :c-return :double - :index weighted-absolute-deviation - :export nil) - -(export 'weighted-absolute-deviation) -(defun-optionals weighted-absolute-deviation (data weights &optional mean) - -nom -m - ;; FDL "The weighted absolute deviation from the weighted mean, defined as absdev = (\sum w_i |x_i - \Hat\mu|) / (\sum w_i).") @@ -87,7 +57,6 @@ (absolute-deviation vec) (weighted-absolute-deviation vec weights) (absolute-deviation vec mean))))) -|# (LISP-UNIT:DEFINE-TEST ABSOLUTE-DEVIATION (LISP-UNIT::ASSERT-NUMERICAL-EQUAL @@ -100,3 +69,4 @@ (WEIGHTED-ABSOLUTE-DEVIATION VEC WEIGHTS) (ABSOLUTE-DEVIATION VEC MEAN))))))) +|# diff --git a/statistics/autocorrelation.lisp b/statistics/autocorrelation.lisp index e65092bc4dd37da808597754d6acdbcf627753ef..809310aa4dbb3022834e813ed873d9817498fc63 100644 --- a/statistics/autocorrelation.lisp +++ b/statistics/autocorrelation.lisp @@ -1,6 +1,6 @@ ;; Autocorrelation ;; Liam Healy, Sun Dec 31 2006 - 13:19 -;; Time-stamp: <2008-03-09 19:21:48EDT autocorrelation.lisp> +;; Time-stamp: <2008-08-20 22:14:26EDT autocorrelation.lisp> ;; $Id$ (in-package :gsl) @@ -8,25 +8,16 @@ ;;; To do: stride other than 1 when that information is availble from ;;; the vector. -(defmfun autocorrelation-nom (data) - "gsl_stats_lag1_autocorrelation" - (((gsl-array data) :pointer) (1 :int) ((dim0 data) size)) +(defmfun autocorrelation ((data vector) &optional mean) + (("gsl_stats" :type "_lag1_autocorrelation") + ("gsl_stats" :type "_lag1_autocorrelation_m")) + ((((c-pointer data) :pointer) (1 :int) ((dim0 data) sizet)) + (((c-pointer data) :pointer) (1 :int) ((dim0 data) sizet) + (mean :double))) + :definition :generic + :element-types :no-complex :c-return :double - :index autocorrelation - :export nil) - -(defmfun autocorrelation-m (data mean) - "gsl_stats_lag1_autocorrelation_m" - (((gsl-array data) :pointer) (1 :int) - ((dim0 data) size) (mean :double)) - :c-return :double - :index autocorrelation - :export nil) - -(export 'autocorrelation) -(defun-optionals autocorrelation (data &optional mean) - -nom -m - ;; FDL + :documentation ; FDL "The lag-1 autocorrelation of the dataset data. a_1 = {\sum_{i = 1}^{n} (x_{i} - \Hat\mu) (x_{i-1} - \Hat\mu) \over @@ -41,7 +32,6 @@ (list (autocorrelation vec) (autocorrelation vec mean))))) -|# (LISP-UNIT:DEFINE-TEST AUTOCORRELATION (LISP-UNIT::ASSERT-NUMERICAL-EQUAL @@ -52,3 +42,5 @@ (LET ((MEAN (MEAN VEC))) (LIST (AUTOCORRELATION VEC) (AUTOCORRELATION VEC MEAN))))))) +|# + diff --git a/statistics/covariance.lisp b/statistics/covariance.lisp index 0f1b0131a6a294141c93208f534730f0bf3c2fbc..62f7d58e65bb3d02b47686746818dff9eb500782 100644 --- a/statistics/covariance.lisp +++ b/statistics/covariance.lisp @@ -1,6 +1,6 @@ ;; Covariance ;; Liam Healy, Sun Dec 31 2006 - 13:19 -;; Time-stamp: <2008-03-09 19:21:49EDT covariance.lisp> +;; Time-stamp: <2008-08-20 22:13:48EDT covariance.lisp> ;; $Id$ (in-package :gsl) @@ -8,27 +8,19 @@ ;;; To do: stride other than 1 when that information is availble from ;;; the vector. -(defmfun covariance-nom (data1 data2) - "gsl_stats_covariance" - (((gsl-array data1) :pointer) (1 :int) - ((gsl-array data2) :pointer) (1 :int) ((dim0 data2) size)) +(defmfun covariance + ((data1 vector) (data2 vector) &optional mean1 mean2) + (("gsl_stats" :type "_covariance") + ("gsl_stats" :type "_covariance_m")) + ((((c-pointer data1) :pointer) (1 :int) + ((c-pointer data2) :pointer) (1 :int) ((dim0 data2) sizet)) + (((c-pointer data1) :pointer) (1 :int) + ((c-pointer data2) :pointer) (1 :int) ((dim0 data2) sizet) + (mean1 :double) (mean2 :double))) + :definition :generic + :element-types :no-complex :c-return :double - :index covariance - :export nil) - -(defmfun covariance-m (data1 data2 mean1 mean2) - "gsl_stats_covariance_m" - (((gsl-array data1) :pointer) (1 :int) - ((gsl-array data2) :pointer) (1 :int) ((dim0 data2) size) - (mean1 :double) (mean2 :double)) - :c-return :double - :index covariance - :export nil) - -(export 'covariance) -(defun-optionals covariance (data1 data2 &optional mean1 mean2) - -nom -m - ;; FDL + :documentation ; FDL "The covariance of the datasets data1 and data2 which must be of the same length, covar = {1 \over (n - 1)} \sum_{i = 1}^{n} @@ -45,7 +37,6 @@ (list (covariance vec1 vec2) (covariance vec1 vec2 mean1 mean2))))) -|# (LISP-UNIT:DEFINE-TEST COVARIANCE (LISP-UNIT::ASSERT-NUMERICAL-EQUAL @@ -58,4 +49,4 @@ (LET ((MEAN1 (MEAN VEC1)) (MEAN2 (MEAN VEC2))) (LIST (COVARIANCE VEC1 VEC2) (COVARIANCE VEC1 VEC2 MEAN1 MEAN2))))))) - +|# diff --git a/statistics/higher-moments.lisp b/statistics/higher-moments.lisp index b57e52f05a38f2d833f93f72d9191c693743b963..e7b54a15c0fdba3a3de35e1dbeb9452aef989554 100644 --- a/statistics/higher-moments.lisp +++ b/statistics/higher-moments.lisp @@ -1,118 +1,80 @@ ;; Skewness and kurtosis. ;; Liam Healy, Sun Dec 31 2006 - 14:20 -;; Time-stamp: <2008-03-09 19:21:48EDT higher-moments.lisp> +;; Time-stamp: <2008-08-20 22:14:37EDT higher-moments.lisp> ;; $Id$ (in-package :gsl) ;;; To do: stride other than 1 when that information is availble from ;;; the vector. -(defmfun skewness-nomsd (data) - "gsl_stats_skew" - (((gsl-array data) :pointer) (1 :int) ((dim0 data) size)) +(defmfun skewness ((data vector) &optional mean standard-deviation) + (("gsl_stats" :type "_skew") + ("gsl_stats" :type "_skew_m_sd")) + ((((c-pointer data) :pointer) (1 :int) ((dim0 data) sizet)) + (((c-pointer data) :pointer) (1 :int) ((dim0 data) sizet) + (mean :double) (standard-deviation :double))) + :definition :generic + :element-types :no-complex :c-return :double - :index skewness - :export nil :documentation ; FDL - "The skewness of data, defined as - skew = (1/N) \sum ((x_i - \Hat\mu)/\Hat\sigma)^3 - where x_i are the elements of the dataset data. - The skewness measures the asymmetry of the tails of a distribution.") - -(defmfun skewness-msd (data mean standard-deviation) - "gsl_stats_skew_m_sd" - (((gsl-array data) :pointer) (1 :int) - ((dim0 data) size) (mean :double) (standard-deviation :double)) + "The skewness of data, defined as skew = (1/N) \sum ((x_i - + \Hat\mu)/\Hat\sigma)^3 where x_i are the elements of the dataset + data. The skewness measures the asymmetry of the tails of a + distribution. If mean and standard deviation are supplied, compute + skewness of the dataset data using the given values skew = (1/N) + \sum ((x_i - mean)/sd)^3. This is useful if you have + already computed the mean and standard deviation of data and want to + avoid recomputing them.") + +(defmfun kurtosis ((data vector) &optional mean standard-deviation) + (("gsl_stats" :type "_kurtosis") + ("gsl_stats" :type "_kurtosis_m_sd")) + ((((c-pointer data) :pointer) (1 :int) ((dim0 data) sizet)) + (((c-pointer data) :pointer) (1 :int) ((dim0 data) sizet) + (mean :double) (standard-deviation :double))) + :definition :generic + :element-types :no-complex :c-return :double - :index skewness - :export nil :documentation ; FDL - "The skewness of the dataset data using the - given values of the mean and standard deviation, - skew = (1/N) \sum ((x_i - mean)/sd)^3 - These functions are useful if you have already computed the mean and - standard deviation of data and want to avoid recomputing them.") - -(export 'skewness) -(defun-optionals skewness - (data &optional mean standard-deviation) - -nomsd -msd - ;; FDL - "The skewness of data defined as - skew = (1/N) \sum ((x_i - \Hat\mu)/\Hat\sigma)^3 - where x_i are the elements of the dataset data. - The skewness measures the asymmetry of the tails of a distribution.") - -(defmfun kurtosis-nomsd (data) - "gsl_stats_kurtosis" - (((gsl-array data) :pointer) (1 :int) ((dim0 data) size)) - :c-return :double - :index kurtosis - :export nil) - -(defmfun kurtosis-msd (data mean standard-deviation) - "gsl_stats_kurtosis_m_sd" - (((gsl-array data) :pointer) (1 :int) - ((dim0 data) size) (mean :double) (standard-deviation :double)) - :c-return :double - :index kurtosis - :export nil) - -(export 'kurtosis) -(defun-optionals kurtosis - (data &optional mean standard-deviation) - -nomsd -msd - ;; FDL "The kurtosis of data defined as kurtosis = ((1/N) \sum ((x_i - \Hat\mu)/\Hat\sigma)^4) - 3 The kurtosis measures how sharply peaked a distribution is, relative to its width. The kurtosis is normalized to zero for a gaussian distribution.") -(defmfun weighted-skewness-nomsd (data weights) - "gsl_stats_wskew" - (((gsl-array weights) :pointer) (1 :int) - ((gsl-array data) :pointer) (1 :int) ((dim0 data) size)) - :c-return :double - :index weighted-skewness - :export nil) - -(defmfun weighted-skewness-msd (data weights mean standard-deviation) - "gsl_stats_wskew_m_sd" - (((gsl-array data) :pointer) (1 :int) - ((dim0 data) size) (mean :double) (standard-deviation :double)) +(defmfun weighted-skewness + ((data vector) (weights vector) &optional mean standard-deviation) + (("gsl_stats" :type "_wskew") + ("gsl_stats" :type "_wskew_m_sd")) + ((((c-pointer weights) :pointer) (1 :int) + ((c-pointer data) :pointer) (1 :int) + ((dim0 data) sizet)) + (((c-pointer weights) :pointer) (1 :int) + ((c-pointer data) :pointer) (1 :int) + ((dim0 data) sizet) + (mean :double) (standard-deviation :double))) + :definition :generic + :element-types :float :c-return :double - :index weighted-skewness - :export nil) - -(export 'weighted-skewness) -(defun-optionals weighted-skewness - (data weights &optional mean standard-deviation) - -nomsd -msd - ;; FDL + :documentation ; FDL "The weighted skewness of the dataset. skew = (\sum w_i ((x_i - xbar)/\sigma)^3) / (\sum w_i).") -(defmfun weighted-kurtosis-nomsd (data weights) - "gsl_stats_wkurtosis" - (((gsl-array data) :pointer) (1 :int) ((dim0 data) size)) - :c-return :double - :index weighted-kurtosis - :export nil) - -(defmfun weighted-kurtosis-msd (data weights mean standard-deviation) - "gsl_stats_wkurtosis_m_sd" - (((gsl-array data) :pointer) (1 :int) - ((dim0 data) size) (mean :double) (standard-deviation :double)) +(defmfun weighted-kurtosis + ((data vector) (weights vector) &optional mean standard-deviation) + (("gsl_stats" :type "_wkurtosis") + ("gsl_stats" :type "_wkurtosis_m_sd")) + ((((c-pointer weights) :pointer) (1 :int) + ((c-pointer data) :pointer) (1 :int) + ((dim0 data) sizet)) + (((c-pointer weights) :pointer) (1 :int) + ((c-pointer data) :pointer) (1 :int) + ((dim0 data) sizet) + (mean :double) (standard-deviation :double))) + :definition :generic + :element-types :float :c-return :double - :index weighted-kurtosis - :export nil) - -(export 'weighted-kurtosis) -(defun-optionals weighted-kurtosis - (data weights &optional mean standard-deviation) - -nomsd -msd - ;; FDL + :documentation ; FDL "The weighted kurtosis of the dataset. kurtosis = ((\sum w_i ((x_i - xbar)/sigma)^4) / (\sum w_i)) - 3.") @@ -128,7 +90,6 @@ (skewness vec mean sd) (kurtosis vec) (kurtosis vec mean sd))))) -|# (LISP-UNIT:DEFINE-TEST HIGHER-MOMENTS (LISP-UNIT::ASSERT-NUMERICAL-EQUAL @@ -142,3 +103,4 @@ (LIST (SKEWNESS VEC) (SKEWNESS VEC MEAN SD) (KURTOSIS VEC) (KURTOSIS VEC MEAN SD))))))) +|# diff --git a/statistics/median-percentile.lisp b/statistics/median-percentile.lisp index 55f533485831a9723c0686df12fd6edb4e504a6e..432c1c9261786c629a083832156f0e16e9b6ceed 100644 --- a/statistics/median-percentile.lisp +++ b/statistics/median-percentile.lisp @@ -1,6 +1,6 @@ ;; Median and percentile ;; Liam Healy, Sun Dec 31 2006 - 13:19 -;; Time-stamp: <2008-03-09 19:19:28EDT median-percentile.lisp> +;; Time-stamp: <2008-08-20 22:35:08EDT median-percentile.lisp> ;; $Id$ (in-package :gsl) @@ -8,9 +8,11 @@ ;;; To do: stride other than 1 when that information is availble from ;;; the vector. -(defmfun median (sorted-data) - "gsl_stats_median_from_sorted_data" - (((gsl-array sorted-data) :pointer) (1 :int) ((dim0 sorted-data) size)) +(defmfun median ((sorted-data vector)) + ("gsl_stats" :type "_median_from_sorted_data") + (((c-pointer sorted-data) :pointer) (1 :int) ((dim0 sorted-data) sizet)) + :definition :generic + :element-types :no-complex :c-return :double :documentation ; FDL "The median value of sorted-data. The elements of the array @@ -24,13 +26,15 @@ computing the median involves interpolation this function always returns a floating-point number, even for integer data types.") -(defmfun quantile (sorted-data fraction) - "gsl_stats_quantile_from_sorted_data" - (((gsl-array sorted-data) :pointer) (1 :int) ((dim0 sorted-data) size) +(defmfun quantile ((sorted-data vector) fraction) + ("gsl_stats" :type "_quantile_from_sorted_data") + (((c-pointer sorted-data) :pointer) (1 :int) ((dim0 sorted-data) sizet) (fraction :double)) + :definition :generic + :element-types :no-complex :c-return :double :documentation ; FDL - "A quantile value of sorted-data, vector-double-float. The + "A quantile value of sorted-data. The elements of the array must be in ascending numerical order. The quantile is determined by a fraction between 0 and 1. For example, to compute the value of the 75th percentile @@ -55,7 +59,6 @@ (letm ((vec (vector-double-float #(-18.0d0 -12.0d0 -3.21d0 0.5d0 1.0d0 2.7d0 12.8d0)))) (quantile vec 0.75d0))) -|# (LISP-UNIT:DEFINE-TEST MEDIAN-PERCENTILE (LISP-UNIT::ASSERT-NUMERICAL-EQUAL @@ -69,4 +72,4 @@ (LETM ((VEC (VECTOR-DOUBLE-FLOAT #(-18.0d0 -12.0d0 -3.21d0 0.5d0 1.0d0 2.7d0 12.8d0)))) (QUANTILE VEC 0.75d0))))) - +|#