[英]Optimize.fmin does not find minimum on well-behaved continuous function
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?
为什么我的求解器不考虑它们?
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.append((x, result))
到residualLambdaMinimize
,您可以收集optimize.fmin
评估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.然后,如果您发布
data
而我们不必确切了解residualLambdaMinimize
是如何定义的,那么我们可能能够更好地了解fmin
正在做什么(并且可能会重现问题)。
Moreover, you can visualize the "path" fmin
is taking as it tries to find the minimum:此外,您可以想象
fmin
在尝试找到最小值时所采用的“路径”:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.