[SciPy-user] Minimizing functions of two variables with fmin_bfgs

Christian Kristukat ckkart at hoc.net
Mon Nov 14 09:11:43 CST 2005


LOPEZ GARCIA DE LOMANA, ADRIAN wrote:
> Hi all, 
> 
> I have a problem using the optimization modules. I'm using fmin_bfgs. It works very well for minimizing functions of just one parameter:
> 
> import Numeric
> import scipy
> from scipy.optimize import fmin_bfgs
> 
> def fitness(p):
>     return p**2 
> 
> def fitness_der(p):
>     return 2 * p 
> 
> p = [158.0]
> popt = fmin_bfgs(fitness, p, fprime = fitness_der)
> print popt
> 
> but while I pretend to expand it to a multiparameter function using a vector,
> 
> import Numeric
> import scipy
> from scipy.optimize import fmin_bfgs
> 
> def fitness(p):
>     return p[0]**2 + p[1]
> 
> def fitness_der(p):
>     return [2 * p[0] + 1, 1] 
> 
> p = [158.0, 314.0]
> popt = fmin_bfgs(fitness, p, fprime = fitness_der)
> print popt
> 

Unfortunately the minimizers in scipy.optimize use different input types. 
fmin_bfgs needs that the derivatives are returned as a scipy.array, however e.g. 
fmin_tnc insists on recieving a python list.
Btw. the minimizer will fail with your function as it doesn't have a global minimum.

Regards, Christian



More information about the SciPy-user mailing list