[SciPy-user] problem with fmin_cobyla
Anne Archibald
peridot.faceted@gmail....
Thu Sep 6 23:26:45 CDT 2007
On 07/09/07, Josh Gottlieb <yosh_6@yahoo.com> wrote:
> Hey,
> A bit of a newbie to this, but I have a problem which
> requires a dynamic set of constraints (some of which
> are non-linear) and I tried two versions using
> fmin_cobyla (both examples attached)--
> one generates these constraints using lambda
> functions, but fmin seems to violate them (example in
> code).
> Then I tried generating them on the fly using exec on
> strings of functions, which observed the constraints,
> but failed to find the most optimal solution. (the
> third permutation should be higher)
> Can anyone help?
> Could not find any examples online which were more
> than trivial, and the docs dont seem very good.
> (apologies for the cryptic coding, I tried to minimize
> a real-world example into a shorter script)
Whipping up functions on the fly, with lambda or by using def() inside
a function, is a perfectly reasonable way to implement constraints.
You can also use a single constraint function that takes an extra
argument to tell it which constraints it should use, and pass that
extra argument in through fmin_cobyla.
Be warned that it's a non-trivial technical problem to implement a
constrained minimizer that never evaluates the function at a point
that violates the constraints; fmin_cobyla may do this, and I think
the other choices in scipy may as well.
Finally, remember that all the fmin_* functions are only *local*
minimizers - they are supposed to find points that are local minima of
the function, but if the function is not concave up, it may have many
minima, and the solver doesn't even try to arrange you wind up at the
lowest. You can improve your chances by starting close to the minimum,
but if there are several unknown minima, you need to look for a global
optimizer, which is a much more difficult problem. Scipy has a couple
of rudimentary ones.
Good luck,
Anne M. Archibald
More information about the SciPy-user
mailing list