theother
theother

Reputation: 317

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?

Upvotes: 3

Views: 1594

Answers (1)

SuperKogito
SuperKogito

Reputation: 2966

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'

Upvotes: 7

Related Questions