gpt4 book ai didi

python - Optimize.fmin 没有找到行为良好的连续函数的最小值

转载 作者:太空宇宙 更新时间:2023-11-04 05:31:35 27 4
gpt4 key购买 nike

我试图找到以下函数的最小值:

function

调用如下:

>>> 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

如您所见,直接邻域中的一些点产生较小的值。为什么我的求解器不考虑它们?

最佳答案

这是一个可以帮助您调试情况的建议。如果你添加类似data.append((x, result))residualLambdaMinimize,你可以收集所有optimize.fmin计算residualLambdaMinimize的点:

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

如果您发布 data 而我们不必确切地看到 residualLambdaMinimize 已定义。

此外,您可以想象 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()

enter image description here

关于python - Optimize.fmin 没有找到行为良好的连续函数的最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36982015/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com