From 6e17d8798bfc84adcab23faa3f635f852d3b9229 Mon Sep 17 00:00:00 2001 From: Liam Healy <liam@thinkpad.local> Date: Mon, 16 Feb 2009 19:11:28 -0500 Subject: [PATCH] GSL features added in version 1.9 Added definitions for GSL features that were added in version 1.9, and one from version 1.10: mminusp, mplusp, non-negative-p, +knuthran2002+, +vector-bfgs2+. Macros defmpar now has key instead of optional args. It and def-rng-type take a gsl-version argument; any symbols that are not defined in the user's version of GSL will be bound to an instance of 'obsolete-gsl-version but it is not signalled. --- data/both.lisp | 32 ++++++++++++++++- documentation/missing-features.text | 15 +------- init/interface.lisp | 23 ++++++++---- random/generators.lisp | 4 +-- random/rng-types.lisp | 14 ++++++-- solve-minimize-fit/minimization-multi.lisp | 26 ++++++++++++-- tests/minimization-multi.lisp | 41 +++++++++++++--------- 7 files changed, 110 insertions(+), 45 deletions(-) diff --git a/data/both.lisp b/data/both.lisp index 05361313..2881e76e 100644 --- a/data/both.lisp +++ b/data/both.lisp @@ -1,6 +1,6 @@ ;; Functions for both vectors and matrices. ;; Liam Healy 2008-04-26 20:48:44EDT both.lisp -;; Time-stamp: <2009-02-11 22:17:09EST both.lisp> +;; Time-stamp: <2009-02-16 18:59:47EST both.lisp> ;; $Id$ (in-package :gsl) @@ -320,3 +320,33 @@ :c-return :boolean :documentation ; FDL "All elements of a are zero.") + +(defmfun mplusp ((a both)) + ("gsl_" :category :type "_ispos") + (((mpointer a) :pointer)) + :definition :generic + :gsl-version (1 9) + :inputs (a) + :c-return :boolean + :documentation ; FDL + "All elements of a are positive.") + +(defmfun mminusp ((a both)) + ("gsl_" :category :type "_isneg") + (((mpointer a) :pointer)) + :definition :generic + :gsl-version (1 9) + :inputs (a) + :c-return :boolean + :documentation ; FDL + "All elements of a are negative.") + +(defmfun non-negative-p ((a both)) + ("gsl_" :category :type "_isnonneg") + (((mpointer a) :pointer)) + :definition :generic + :gsl-version (1 10) + :inputs (a) + :c-return :boolean + :documentation ; FDL + "All elements of a are non-negative.") diff --git a/documentation/missing-features.text b/documentation/missing-features.text index 2d7faf16..0f831c7b 100644 --- a/documentation/missing-features.text +++ b/documentation/missing-features.text @@ -6,21 +6,9 @@ All file input and output (fread, fwrite) functions. All submatrix functions and views. Stride is always set to 1 in GSL functions that take a stride. -Some things that have been added to GSL since 1.8 that should be added +Some things that have been added to GSL since 1.9 that should be added to GSLL: -GSL 1.9 -http://lists.gnu.org/archive/html/info-gsl/2007-02/msg00000.html -** Added a new BFGS2 minimisation method, requires substantially fewer -function and gradient evaluations that the existing BFGS minimiser. -** Added updated Knuth generator, gsl_rng_knuthran2002, from 9th -printing of "The Art of Computer Programming". Fixes various -weaknesses in the earlier version gsl_rng_knuthran. -** Added new functions for testing the sign of vectors and matrices, -gsl_vector_ispos, gsl_vector_isneg, gsl_matrix_ispos and -gsl_matrix_isneg. - - GSL 1.10 http://lists.gnu.org/archive/html/info-gsl/2007-09/msg00000.html ** Extended Cholesky routines to complex matrices (Patrick Alken) @@ -29,7 +17,6 @@ http://lists.gnu.org/archive/html/info-gsl/2007-09/msg00000.html of two datasets ** Added the new function gsl_sf_expint(n,x) for computing the n-th order exponential integral. -** Added functions gsl_vector_isnonneg and gsl_matrix_isnonneg. ** Added support in gsl_ieee_set_mode for controlling SSE exceptions and rounding through the MXCSR control word on x86 processors. [Modify existing GSLL function.] diff --git a/init/interface.lisp b/init/interface.lisp index b3abe0b4..f742db88 100644 --- a/init/interface.lisp +++ b/init/interface.lisp @@ -1,6 +1,6 @@ ;; Macros to interface GSL functions, including definitions necessary for defmfun. ;; Liam Healy -;; Time-stamp: <2009-02-15 12:45:17EST interface.lisp> +;; Time-stamp: <2009-02-16 18:39:59EST interface.lisp> ;; $Id$ (in-package :gsl) @@ -128,13 +128,22 @@ ;;;;**************************************************************************** (defmacro defmpar - (cl-symbol gsl-symbol documentation &optional (c-type :pointer) (read-only t)) + (cl-symbol gsl-symbol documentation + &key (c-type :pointer) (read-only t) gsl-version) "Define a library variable pointer." - `(progn - (cffi:defcvar (,gsl-symbol ,cl-symbol :read-only ,read-only) ,c-type - ,documentation) - (map-name ',cl-symbol ,gsl-symbol) - (export ',cl-symbol))) + (if (have-at-least-gsl-version gsl-version) + `(progn + (cffi:defcvar (,gsl-symbol ,cl-symbol :read-only ,read-only) ,c-type + ,documentation) + (map-name ',cl-symbol ,gsl-symbol) + (export ',cl-symbol)) + ;; Insufficient version number handled by binding a special of + ;; the same name to the condition. It would be nice to signal + ;; the error, but it least this will provide some information. + `(defparameter ,cl-symbol + (make-condition + 'obsolete-gsl-version :name ',cl-symbol :gsl-name + ,gsl-symbol :gsl-version ',gsl-version )))) ;;;;**************************************************************************** ;;;; GSL library version diff --git a/random/generators.lisp b/random/generators.lisp index f810f10c..cbcc3fc3 100644 --- a/random/generators.lisp +++ b/random/generators.lisp @@ -1,6 +1,6 @@ ;; Generators of random numbers. ;; Liam Healy, Sat Jul 15 2006 - 14:43 -;; Time-stamp: <2009-02-16 10:10:32EST generators.lisp> +;; Time-stamp: <2009-02-16 18:43:36EST generators.lisp> ;; $Id$ (in-package :gsl) @@ -36,7 +36,7 @@ (defmpar +default-seed+ "gsl_rng_default_seed" "The default seed for random number generators." - :ulong nil) + :c-type :ulong :read-only nil) ;;;;**************************************************************************** ;;;; Sampling diff --git a/random/rng-types.lisp b/random/rng-types.lisp index 442eb568..ec1f2abc 100644 --- a/random/rng-types.lisp +++ b/random/rng-types.lisp @@ -1,6 +1,6 @@ ;; Random number generation ;; Liam Healy, Tue Jul 11 2006 - 23:39 -;; Time-stamp: <2009-02-16 10:24:11EST rng-types.lisp> +;; Time-stamp: <2009-02-16 18:49:40EST rng-types.lisp> ;; $Id$ ;;; Random number generator types and information functions. @@ -38,7 +38,7 @@ ;;;; Defining RNGs and default ;;;;**************************************************************************** -(defmacro def-rng-type (lisp-name &optional documentation gsl-name) +(defmacro def-rng-type (lisp-name &optional documentation gsl-name gsl-version) "Define the random number generator type." (let ((cname (or gsl-name @@ -46,7 +46,7 @@ (substitute #\_ #\- (format nil "gsl_rng_~(~a~)" lisp-name)))))) - `(defmpar ,lisp-name ,cname ,documentation))) + `(defmpar ,lisp-name ,cname ,documentation :gsl-version ,gsl-version))) (def-rng-type +default-type+ "The default random number generator type, @@ -443,6 +443,14 @@ in Seminumerical Algorithms, 3rd Ed., Section 3.6. Knuth provides its C code.") +(def-rng-type +knuthran2002+ ; FDL + "Obsolete, use only for compatibility. + A second-order multiple recursive generator described by Knuth + in Seminumerical Algorithms, 3rd Ed., Section 3.6. Knuth + provides its C code. From the revised 9th printing and corrects + some weaknesses in the earlier version, which is implemented as + +knuthran+." "gsl_rng_knuthran2002" (1 9)) + (def-rng-type +knuthran2+ ; FDL "Obsolete, use only for compatibility. A second-order multiple recursive generator described by Knuth diff --git a/solve-minimize-fit/minimization-multi.lisp b/solve-minimize-fit/minimization-multi.lisp index 7022751c..af94fff6 100644 --- a/solve-minimize-fit/minimization-multi.lisp +++ b/solve-minimize-fit/minimization-multi.lisp @@ -1,6 +1,6 @@ ;; Multivariate minimization. ;; Liam Healy <Tue Jan 8 2008 - 21:28> -;; Time-stamp: <2009-02-16 09:54:29EST minimization-multi.lisp> +;; Time-stamp: <2009-02-16 18:58:26EST minimization-multi.lisp> ;; $Id$ (in-package :gsl) @@ -268,6 +268,27 @@ steps towards the function minimum, assuming quadratic behavior in that region.") +(defmpar +vector-bfgs2+ + "gsl_multimin_fdfminimizer_vector_bfgs2" + ;; FDL + "The vector Broyden-Fletcher-Goldfarb-Shanno (BFGS) conjugate + gradient algorithm. It is a quasi-Newton method which builds up an + approximation to the second derivatives of the function using the + difference between successive gradient vectors. By combining the + first and second derivatives the algorithm is able to take Newton-type + steps towards the function minimum, assuming quadratic behavior in + that region. + + This version is the most efficient version available, and is a + faithful implementation of the line minimization scheme described + in Fletcher's Practical Methods of Optimization, Algorithms 2.6.2 + and 2.6.4. It supercedes the original bfgs routine and requires + substantially fewer function and gradient evaluations. The + user-supplied tolerance tol corresponds to the parameter \sigma + used by Fletcher. A value of 0.1 is recommended for typical + use (larger values correspond to less accurate line searches)." + :gsl-version (1 9)) + (defmpar +simplex-nelder-mead+ "gsl_multimin_fminimizer_nmsimplex" ;; FDL @@ -414,4 +435,5 @@ (multimin-example-no-derivative +simplex-nelder-mead+ nil) (multimin-example-derivative +conjugate-fletcher-reeves+ nil) (multimin-example-derivative +conjugate-polak-ribiere+ nil) - (multimin-example-derivative +vector-bfgs+ nil)) + (multimin-example-derivative +vector-bfgs+ nil) + (multimin-example-derivative +vector-bfgs2+ nil)) diff --git a/tests/minimization-multi.lisp b/tests/minimization-multi.lisp index 54f337ac..fbbfb25d 100644 --- a/tests/minimization-multi.lisp +++ b/tests/minimization-multi.lisp @@ -3,19 +3,28 @@ (in-package :gsl) (LISP-UNIT:DEFINE-TEST MINIMIZATION-MULTI - (LISP-UNIT::ASSERT-NUMERICAL-EQUAL - (LIST 0.9920430849306285d0 1.9969168063253164d0 30.000823246638923d0) - (MULTIPLE-VALUE-LIST - (MULTIMIN-EXAMPLE-NO-DERIVATIVE +SIMPLEX-NELDER-MEAD+ NIL))) - (LISP-UNIT::ASSERT-NUMERICAL-EQUAL - (LIST 0.9999999999999997d0 2.0d0 30.0d0) - (MULTIPLE-VALUE-LIST - (MULTIMIN-EXAMPLE-DERIVATIVE +CONJUGATE-FLETCHER-REEVES+ NIL))) - (LISP-UNIT::ASSERT-NUMERICAL-EQUAL - (LIST 0.9999999999999997d0 2.0d0 30.0d0) - (MULTIPLE-VALUE-LIST - (MULTIMIN-EXAMPLE-DERIVATIVE +CONJUGATE-POLAK-RIBIERE+ NIL))) - (LISP-UNIT::ASSERT-NUMERICAL-EQUAL - (LIST 0.9999999999999997d0 2.0d0 30.0d0) - (MULTIPLE-VALUE-LIST - (MULTIMIN-EXAMPLE-DERIVATIVE +VECTOR-BFGS+ NIL)))) + (LISP-UNIT::ASSERT-NUMERICAL-EQUAL + (LIST 0.9920430849306285d0 1.9969168063253164d0 + 30.000823246638923d0) + (MULTIPLE-VALUE-LIST + (MULTIMIN-EXAMPLE-NO-DERIVATIVE +SIMPLEX-NELDER-MEAD+ + NIL))) + (LISP-UNIT::ASSERT-NUMERICAL-EQUAL + (LIST 0.9999999999999997d0 2.0d0 30.0d0) + (MULTIPLE-VALUE-LIST + (MULTIMIN-EXAMPLE-DERIVATIVE + +CONJUGATE-FLETCHER-REEVES+ NIL))) + (LISP-UNIT::ASSERT-NUMERICAL-EQUAL + (LIST 0.9999999999999997d0 2.0d0 30.0d0) + (MULTIPLE-VALUE-LIST + (MULTIMIN-EXAMPLE-DERIVATIVE +CONJUGATE-POLAK-RIBIERE+ + NIL))) + (LISP-UNIT::ASSERT-NUMERICAL-EQUAL + (LIST 0.9999999999999997d0 2.0d0 30.0d0) + (MULTIPLE-VALUE-LIST + (MULTIMIN-EXAMPLE-DERIVATIVE +VECTOR-BFGS+ NIL))) + (LISP-UNIT::ASSERT-NUMERICAL-EQUAL + (LIST 0.9999999999998208d0 1.9999999999995521d0 30.0d0) + (MULTIPLE-VALUE-LIST + (MULTIMIN-EXAMPLE-DERIVATIVE +VECTOR-BFGS2+ NIL)))) + -- GitLab