拟合2D函数的误差估计

时间:2018-12-03 14:13:05

标签: python scipy data-analysis

我遇到了一个问题,我有一个微分方程的数值解算器,并且已经测量了该方程的许多参数,但是我需要拟合3。我该如何在将σ的估计中包括被测自变量的误差拟合参数中的错误?

我正在使用scipy.optimize.leastsq来估算拟合误差。我的代码基本上是这样的:

import scipy.optimize as opt
def solve(x,y,parameters,arguments):
    #Not important, but I do not know the functional relationship between F(x,y) and the parameters and the arguments
# data is just my data
def difference(params,arguments)
    solutions = solve(data,params,arguments)
    return solutions-data
# p0 is just an array of initial conditions
fit,cov,info,mesg,ier = opt.leastsq(difference,p0,full_output=True,args=measured_values)

但是,这只给我拟合参数带来的误差,但是我知道我的测量值也具有不确定性。有没有办法估计由这些参数引起的拟合参数中的误差?

1 个答案:

答案 0 :(得分:0)

从那时起,我意识到我可以使用偏导数公式并自己计算拟合的偏导数来估计误差。有问题的公式当然是:

# partial(F,x) is the partial derivative of F with respect to x
err_F = sqrt((partial(F,a)*err_a)**2+(partial(F,b)*err_b)**2+(partial(F,c)*err_c)**2)

由于我没有在函数中查找错误,因此必须定义三个函数(每个适合的参数一个),并据此计算它们的错误。希望这对可能遇到类似问题的人有所帮助。