Reputation: 16478
I'm trying to find the minimum on the following 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?
Upvotes: 2
Views: 442
Reputation: 879291
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()
Upvotes: 1