Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print chosen method of scipy.optimize.minimize

This is a short question, but google points me every time to the documentation where I can't find the answer.

I am using scipy.optimize.minimize. It works pretty good, all things are fine. I can define a method to use, but it works even if I don't specify the method.

Is there any way to get an output, which method was used? I know the result class, but the method isn't mentioned there.

Here's an example:

solution = opt.minimize(functitionTOminimize,initialGuess, \
                      constraints=cons,options={'disp':True,'verbose':2})
print(solution)

I could set the value method to something like slsqp or cobyla, but I want to see what the program is choosing. How can I get this information?

like image 767
theother Avatar asked Sep 12 '25 13:09

theother


1 Answers

According to the scipy.optimize.minimize() docs: If no method is specified the default choice will be one of BFGS, L-BFGS-B, SLSQP.

  • If the problem has no bounds and no constraints, BFGS will be chosen.
  • If the problem has bounds but no constraints, L-BFGS-B will be chosen.
  • If the problem has constraints, SLSQP will be chosen. SLSQP also supports bounds.

To get more details on how the method is chosen, you should take a look at the line 480 of minimize(). The method is chosen like this:

if method is None:
    # Select automatically
    if constraints:
        method = 'SLSQP'
    elif bounds is not None:
        method = 'L-BFGS-B'
    else:
        method = 'BFGS'
like image 60
SuperKogito Avatar answered Sep 14 '25 03:09

SuperKogito