【问题标题】:'args not defined' error from leastsq function来自 minimumsq 函数的“未定义参数”错误
【发布时间】:2014-02-26 05:14:23
【问题描述】:

我尝试以数组 synthData[0,:]、synthData[1,:] 和 y 值 synthData[2,:] 的形式将函数拟合到来自矩阵 synthData 的数据。但是下面的 sn -p 返回“name 'args' not defined”

guess = [16.200000, -0.700000, 5.900000, -0.200000]

def func(x, a, b, c, d):
    # fitter will understand that x[0] equiv. to synthData[:,0], etc.
    return a + b*x[0] + c*x[1] + d*x[0]*x[1]
scipy.optimize.leastsq(func,guess,args(synthData,synthData[2,:]))

我已经摆弄它并在 SO 中搜索,但无法弄清楚它在做什么。

【问题讨论】:

    标签: python scipy curve-fitting least-squares args


    【解决方案1】:

    我认为您缺少等号:

    scipy.optimize.leastsq(func,guess,args=(synthData,synthData[2,:]))
    

    【讨论】:

    • 哦。这绝对是问题的一部分。谢谢。现在它说'func()正好需要5个参数(3个给定)'。如果我已经在函数中说明了其他参数,我想我只是不理解这些参数。如果我在 args() 中重新声明它们,它会显示“输入不当:N=%s 不得超过 M=%s”% (n, m))',其中 N 是数据点,M 是参数。
    • ... 并且帮助说 args 是“函数的额外参数”,但是我不清楚为什么只声明 args=(synthData,synthData[2,:]) 是不够的.
    • 你有没有试过明确地把args=(sunthData[0], synthData[1], synthData[2], synthData[3])放在那里。现在看起来它只认为你给了它 2 个参数 + 猜测的 x,因此它说你只给了函数 3 个参数。
    猜你喜欢
    • 2014-07-25
    • 2013-06-21
    • 2018-03-02
    • 2022-01-11
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多