[SciPy-user] Optimization / fitting routines

Robert Kern robert.kern at gmail.com
Mon Mar 20 00:37:40 CST 2006


Webb Sprague wrote:
> Hi all,
> 
> (I am a little bit over my head, so if I say things that sound stupid,
> please excuse.)
> 
> (1) Could someone point me toward documentation for optimization
> routines in numpy?  I need the routine to be very general, excepting
> an arbitrary Python function that accepts a test value, and a target
> value for that function. We can assume that the function will be
> monotonic.

It seems like you have a root-finding problem. I'm not really sure; your
description is vague. Do you mean that you have a function f(x) taking a scalar
real number and returning a scalar real number? And you want to find the x such
that f(x) equals some given number y? In that case, recast your problem a
little: define g(x) = (f(x) - y) and use one of the root-finding routines in
scipy.optimize to find the x that makes g(x) = 0.

In [5]: scipy.optimize?

Type:           module
Base Class:     <type 'module'>
String Form:    <module 'scipy.optimize' from
'/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-pack
ages/scipy-0.4.7.1607-py2.4-macosx-10.4-ppc.egg/scipy/optimize/__init__.pyc'>
Namespace:      Interactive
File:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/scipy-0.4.7.1607-py2.4-mac
osx-10.4-ppc.egg/scipy/optimize/__init__.py
Docstring:
    Optimization Tools
    ==================

...

     Also a collection of general_purpose root-finding routines.

       fsolve      --  Non-linear multi-variable equation solver.

      Scalar function solvers

       brentq      --  quadratic interpolation Brent method
       brenth      --  Brent method (modified by Harris with
                         hyperbolic extrapolation)
       ridder      --  Ridder's method
       bisect      --  Bisection method
       newton      --  Secant method or Newton's method

       fixed_point -- Single-variable fixed-point solver.

> (2)  Could someone point me or recommend a book that clearly describes
> these problems mathematically at an "advanced undergrad" level?

_Numerical Recipes_ does a reasonable job of describing the problems. I don't
like their code, but the discussions are pretty good. You can even read it
online, if you like:

  http://www.numerical-recipes.com/nronline_switcher.html

-- 
Robert Kern
robert.kern at gmail.com

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco



More information about the SciPy-user mailing list