Hi!

On Wed, 2011-01-05 at 10:08 +0100, Yury V. Zaytsev wrote:

> In such a case, what would be the recommended code to use for Python? 

As it turns out, the required code is already bundled with SciPy, so I
guess the recommended version for Python would look along the lines of
the following snippet (public domain):

    from scipy.misc import derivative

    # Objective function wrapper
    def f(x, g):

        # Compute the objective function
        ret = ...

        # If gradient was passed, it has to be assigned in-place
        if g.size > 0:

            # Approximate the gradient using SciPy built-in
            # central differences routine
            #
            g[:] = derivative(..., x,
                                 args = (..., ),
                                 dx = ...,
                                 order = 3,
                                 n = 1,
                                 )

        # Returns the value of the objective function
        return ret

I think that Python users would certainly appreciate if this could be
added to the wiki!

Thanks,
 
-- 
Sincerely yours,
Yury V. Zaytsev


_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to