According to GSL documentation at http://www.gnu.org/software/gsl/manual/html_node/Initializing-the-Minimizer...., gsl_min_fminimizer_set_with_values has the following signature:
int gsl_min_fminimizer_set_with_values (gsl_min_fminimizer * s, gsl_function * f, double x_minimum, double f_minimum, double x_lower, double f_lower, double x_upper, double f_upper)
GSLL set-fminimizer-with-values is defined as follows:
(defmfun set-fminimizer-with-values (minimizer function x-minimum x-lower x-upper f-minimum f-lower f-upper) "gsl_min_fminimizer_set_with_values" (((mpointer minimizer) :pointer) (function :pointer) (x-minimum :double) (x-lower :double) (x-upper :double) (f-minimum :double) (f-lower :double) (f-upper :double)) :documentation ; FDL "Set, or reset, an existing minimizer to use the function and the initial search interval [lower, upper], with a guess for the location of the minimum, using supplied rather than computed values of the function.")
Note the different order of argument names. I often use #'describe to see function argument list and this discrepancy confuses me. Please, apply the patch in the attachement.
Also, can you advice me on how to create a callback for this function? The simplest solution I can come up with is the following:
(cffi:defcallback test :double ((x :double) (parameters :pointer)) (1+ (cos x)))
(cffi:with-foreign-object (callback 'gsl::fnstruct) (setf (cffi:foreign-slot-value callback 'gsl::fnstruct 'function) (cffi:callback test)) (let ((minimizer (gsl:make-one-dimensional-minimizer gsl:+brent-fminimizer+))) (gsl:set-fminimizer-with-values minimizer callback ...) ...))
But I don't like that the fnstruct symbol is not exported. What is the supposed way?
It would be nice to be able to provide ordinary Lisp function as callback for set-fminimizer-with-values instead of foreign pointer to gsl_function. I do understand why it is difficult to make though. Maybe you should use gsl_min_fminimizer_set_with_values instead of gsl_min_fminimizer_set as is suggested by the comment in the definition of one-dimensional-minimizer. GSL uses the latter function as conventional interface for the former. In Lisp this can be handled better via key arguments.
Evgeniy,
I've incorporated the set-with-values function into the make-one-dimensional-minimizer. The arglist is:
(DEFUN MAKE-ONE-DIMENSIONAL-MINIMIZER (TYPE &OPTIONAL FUNCTION X-MINIMUM X-LOWER X-UPPER F-MINIMUM F-LOWER F-UPPER) ...)
If you do not specify f-minimum (or specify it nil), then the GSL function gsl_min_fminimizer_set is called. If it is given, then gsl_min_fminimizer_set_with_values is called. In either case, the arguments of the call should be in the correct order.
Give this a try and see if it works. If so, and you can post a simple example, I will add it to gsll-tests.
Thank you.
Liam
It works fine. A patch for the testsuite is in the attachement. The order of arguments is still different from GSL but I'm happy as long as their names correspond to their meaning.
Thank you for your cooperation.