Moritz
Moritz

Reputation: 5418

scipy: minimize vs. minimize.scalar; return F versus return F**2; shouldnt make a difference?

I just found a behavior which I cannot explain. Do I miss something ?

I have an implicit function:

def my_cost_fun(x,a,b,c):
    # x is a scalar; all variables are provided as numpy arrays
    F = some_fun(x,a,b,c) - x
    return F

I do minimize the function using:

Or by the mimimize function:

The strange thing is:

Can someone explain why ?

Upvotes: 1

Views: 1690

Answers (1)

Curt F.
Curt F.

Reputation: 4824

As I mentioned in the comments:

Here is one possible explaination of why L-BFGS-B is not working when you use return F: If the value of F can be negative, then optmize.minimize will try to find the most negative value it can. minimize isn't necessarily finding a root, it's finding the minimum. If you return F**2 instead, since for real-valued functions F**2 will always be positive, minima of F**2 will happen at F=0, i.e. the minima will be the roots.

This doesn't explain your timing issue, but that may be of secondary concern. I would still be curious to study the timing with your particular some_fun(x,a,b,c) if you get a chance to post a definition.

Upvotes: 1

Related Questions