[Gsll-devel] Correct scalarsp form for gsl:make-multi-dimensional-minimizer-fdf?
Liam Healy
lhealy at common-lisp.net
Wed Jun 10 03:24:41 UTC 2009
On Tue, Jun 9, 2009 at 6:34 PM, James Wright<james at chumsley.org> wrote:
> Hi everyone,
>
> First of all, thanks very much for GSLL. It's impressively
> comprehensive, and it's making my life a lot easier.
Thanks. Slowly, still more is coming, not complete yet...
>
> I've been using `gsl:make-multi-dimensional-minimizer-f' in one of my
> projects for a while now, and I'm looking at switching to one of the
> gradient-based methods instead. However, I can't figure out how
> SCALARSP works with the f-and-gradient function.
>
> As a very simple example, consider the function F(x1 x2) = x1^2 + x2^3:
You're trying to minimize a cubic?
See below.
>
> (defun f (x1 x2)
> (+ (* x1 x1) (* x2 x2 x2)))
>
> For the function-and-gradient function, I need to return the value at
> [x1 x2], plus a vector of 2 partial derivatives. In total that's 3
> items, so I had thought that the following function would work:
>
> (defun h (x1 x2)
> (values (+ (* x1 x1) (* x2 x2 x2))
> (* 2 x1)
> (* 3 x2 x2)))
>
> However, when I try to use it like so:
>
> (gsl:make-multi-dimensional-minimizer-fdf gsl:+vector-bfgs2+ 2 '(f g
> h) #m(9.0 9.0) 0.1d0 0.1d0 t)
>
> I get a TYPE-ERROR: The value NIL is not of type DOUBLE-FLOAT. I'm
> fairly sure that my definition of H is the problem here, because when
> I trace F, G, and H, H is the only function that gets called.
>
> I've also tried having H return F(X) as the first value and the
> gradient vector as the second value, but no dice. (SBCL complains
> that a double-float vector is not a double-float, which is true. :)
>
> I'm running SBCL and the most recent version of GSLL (I pulled from
> the master branch about an hour ago). Could anyone give me a hint as
> to what I'm doing wrong here? I could always implement using
> non-scalarsp functions, but if that's the only fix, then it seems
> pointless for make-multi-dimensional-minimizer-fdf to take a scalarsp
> argument in the first place.
>
> Thanks very much!
> James
>
There was definitely a bug in the multidimensional minimizer code,
which I've now fixed, so do a fresh pull of master. Thanks for the
alert. However, you are giving it a function which has no minimum,
because the cubic is unbounded negative. I was kind of hoping GSL
would alert you to this fact, but in fact it gets a "solution" which
is a bit hard to explain (and definitely not a minimum).
I have created a scalar example which is the same as the vector case,
the parabaloid, at the end of the file minimization-multi.lisp. It
gets an answer identical to the vector result. It has been added to
the examples/tests 'minimization-multi.
Liam
More information about the gsll-devel
mailing list