2

I'm trying to find the minimum on the following function:

function

Here's the call:

>>> optimize.fmin(residualLambdaMinimize, 0.01, args=(u, returnsMax, Param, residualLambdaExtended),
                               disp=False, full_output=True, xtol=0.00001, ftol = 0.0001)
Out[19]: (array([ 0.0104]), 0.49331109755304359, 10, 23, 0)
>>> residualLambdaMinimize(0.015, u, returnsMax, Param, residualLambdaExtended)
Out[22]: 0.46358005517761958
>>> residualLambdaMinimize(0.016, u, returnsMax, Param, residualLambdaExtended)
Out[23]: 0.42610470795409616

As you can see, there's points in the direct neighborhood which yield smaller values. Why doesn't my solver consider them?

3
  • can you give residualLambdaMinimize expression? It is also typically in this kind of hole where the minimization is tricky,bouncing like a ball between two narrow walls and arriving at bottom without really reaching it. The minimization algorithm should be selected accordingly so. Commented May 2, 2016 at 12:43
  • @ColonelBeauvel I would have added it here, if there was a quick way of finding a small working sample. It's several layers of function logic, unfortunately. Commented May 2, 2016 at 12:57
  • All solvers have their good points and their bad points. There is a reason there are so many, after all. But, few will operate flawlessly without some consideration for what they do and how your function impacts what they try to do. Sometimes, a simple thing like rescaling the x-axis will work. Sometimes picking an initial guess far away, but in a 'nice' direction (for the solver) helps. Ultimately, there is something of a black art to finding an 'optimal' solver/system combination. Commented May 2, 2016 at 19:40

1 Answer 1

1

Here is a suggestion which may help you debug the situation. If you add something like data.append((x, result)) to residualLambdaMinimize, you can collect all the points where optimize.fmin is evaluating residualLambdaMinimize:

data = []
def residualLambdaMinimize(x, u, returnsMax, Param, residualLambdaExtended):
    result = ...
    data.append((x, result))
    return result

Then we might be better able to understand what fmin is doing (and maybe reproduce the problem) if you post data without us having to see exactly how residualLambdaMinimize is defined.

Moreover, you can visualize the "path" fmin is taking as it tries to find the minimum:

import numpy as np
import scipy.optimize as optimize
import matplotlib.pyplot as plt

data = []

def residualLambdaMinimize(x, u, returnsMax, Param, residualLambdaExtended):
    result = (x-0.025)**2
    data.append((x, result))
    return result

u, returnsMax, Param, residualLambdaExtended = range(4)
retval = optimize.fmin(
    residualLambdaMinimize, 0.01, 
    args=(u, returnsMax, Param, residualLambdaExtended),
    disp=False, full_output=True, xtol=0.00001, ftol = 0.0001)

data = np.squeeze(data)
x, y = data.T
plt.plot(x, y)
plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.