[SciPy-User] how to use properly the function fmin () to scipy.optimize
Tue Mar 13 12:35:25 CDT 2012
On Tue, Mar 13, 2012 at 8:02 AM, javi <firstname.lastname@example.org> wrote:
> Hello, I have been trying to find the right way to use the function fmin
> () to
> use downhill simplex.
> Mainly I have a problem with that is that the algorithm converges to good
> effect, ie as a solution with a value next to zero.
> To test the performance of the algorithm I used the following example:
> def minimize (x):
> min = x  + x  + x  + x 
> return min
> In which given a vector x would want to obtain the values of its elements
> when added give the minimum possible value.
> To do this use the following function call:
> solution = fmin (minimize, x0 = array ([1, 2, 3, 4]), args = "1", xtol =
> 0.21, =
> 0.21 ftol, full_output = 1)
> print "value parameters", solution , "\ n"
> and I get the following results:
> Optimization terminated successfully.
> Current function value: 10.000000
> Iterations: 1
> Function evaluations: 5
> value of the parameters: [1. 2. 3. 4.]
> As you can see the solution is VERY BAD, and I understand that due to large
> values of ftol and xtol that I gave it converges very quickly and gives a
> small value.
> Now, for that is a better result, ie, better than the 10 found understand
> that I
> must decrease and ftol xtol values, but in doing so I get:
> "Warning: Maximum number of function evaluations exceeded Has Been."
> Where I understand the algorithm before converging has made excessive
> calls to
> the function "minimize".
> Could you tell me what the correct use of the parameters ftol and xtol to
> a good minimum next to 0?. Sshould generally be used in subsequent cases
> of ftol
> and xtol values?, They differ?.
> A greeting and thank you very much.
It looks like you want to solve a *constrained* minimization problem, in
which all the components of x remain positive. The function fmin() is for
unconstrained optimization, and your objective function has no
You can try fmin_cobyla or fmin_slsqp. Here's a short demonstration:
from scipy.optimize import fmin_slsqp, fmin_cobyla
"""The objective function to be minized."""
"""Component constraint function for fmin_slsqp."""
# The following are the component constraint functions for fmin_cobyla.
if __name__ == "__main__":
print "Using fmin_slsqp"
result = fmin_slsqp(objective, [1,2,3,4], f_ieqcons=all_positive_constr)
print "Using fmin_cobyla"
result = fmin_cobyla(objective, [1,2,3,4], [x0_positive, x1_positive,
> SciPy-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User