[SciPy-user] Questions about scipy.optimize.fmin_cobyla

Anne Archibald peridot.faceted@gmail....
Mon Jul 16 13:00:24 CDT 2007


On 16/07/07, fdu.xiaojf@gmail.com <fdu.xiaojf@gmail.com> wrote:

> 2) In function f(X), there are item of log(xi). Although I have
> constrained the value of xi in the constrain functions, xi still may be
> equal or less than 0 during minimization, then "math domain error"
> occurred.
>
> What should I do ?
>
> My method is when "math domain error" occurred, catch it and set the
> return value of f to a very large number. Should this work or not?

This problem happens because while fmin_cobyla is able to handle
constraints, it nevertheless evaluates the objective function outside
those constraints. I think this is a very serious bug, which limits
the usefulness of fmin_cobyla. Unfortunately, I do not have a general
solution.

In your specific case, where you have positive numbers, I would
recommend (as another poster did) that you reparameterize: any
positive number xi can be written as exp(yi). If you write it this
way, yi may take any value and xi will still be positive. If you're
lucky, this may allow you to dispense with constraints entirely. For a
simple example:

Suppose we want to do least-squares fitting of an exponential to some
data points:

yvals = A*exp(b*xvals) + noise

Suppose further that we want to ensure A is positive. We could minimize
sum((yvals-A*exp(b*xvals))**2)
subject to the constraint A>0. But this will be tricky. Instead, write
A=exp(a), and minimize
sum((yvals-exp(a)*exp(b*xvals))**2).

Anne


More information about the SciPy-user mailing list