3

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?

Palle Due
  • 5,929
  • 4
  • 17
  • 32
theother
  • 307
  • 2
  • 16
  • please show some code for what you tried so far and provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – SuperKogito Jun 29 '19 at 15:47
  • I think my question is very basic, so I don't need to give executable code – theother Jun 30 '19 at 00:58
  • I asked for an example because I assumed that by method you were referring to the objective function but now that I get your point, I hope that my answer helps. – SuperKogito Jul 01 '19 at 01:13

1 Answers1

4

According to the scipy-optimize-minimize-docs: If no method is specified the default choice will be one of BFGS, L-BFGS-B, SLSQP, depending on whether the problem has constraints or bounds. To get more details on the methods deployement's order, you should take a look at the scipy-optimize-minimize-source-code-line-480. From the source code the order is the following:

if method is None:
    # Select automatically
    if constraints:
        method = 'SLSQP'
    elif bounds is not None:
        method = 'L-BFGS-B'
    else:
        method = 'BFGS'
SuperKogito
  • 2,998
  • 3
  • 16
  • 37
  • Ok, so I can't print it, I just know what is chosen automaticly. – theother Jul 01 '19 at 13:56
  • 1
    You can add a print statement to your local `scipy-optimize-minimize-source-file` for that or by using the knowledge of the algorithm and printing the `method` ahead in your main code. – SuperKogito Jul 01 '19 at 15:47