python scipy fmin未成功完成

时间:2019-03-13 21:39:39

标签: python-3.x function scipy minimization

我有一个函数正在尝试最小化多个值。对于某些值,它成功终止,而对于其他值,错误

Warning: Maximum number of function evaluations has been exceeded.

是给出的错误。我不确定maxiter和maxfun的作用以及如何增加或减少它们以成功达到最低要求。我的理解是这些值是可选的,因此我不确定默认值是什么。

# create starting parameters, parameters equal to sin(x)
a = 1
k = 0
h = 0
wave_params = [a, k, h]

def wave_func(func_params):
    """This function calculates the difference between a sinewave (sin(x)) and raw_data (different sin wave)
    This is the function that will be minimized by modulating a, b, k, and h parameters in order to minimize
    the difference between curves."""
    a = func_params[0]
    b = 1
    k = func_params[1]
    h = func_params[2]

    y_wave = a * np.sin((x_vals-h)/b) + k
    error = np.sum((y_wave - raw_data) * (y_wave - raw_data))

    return error

wave_optimized = scipy.optimize.fmin(wave_func, wave_params)

0 个答案:

没有答案