如何用卡方检验法找出拟合参数的不确定度?

2024-05-19 07:41:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我想比较两种光谱。这两个光谱因比例因子而不同。我想找出由于光谱中的不确定性而导致的标度因子和与标度因子确定相关的统计不确定性(即,实际上,两个光谱将不是另一个光谱的精确标度版本。)

下面是缩放的代码

def scalespec(origspec, factor, startidx, endidx):

    #Scale a histogram *origspec* by a factor, between startidx and endidx.

    scaledspec = np.zeros_like(origspec)
    for i in np.linspace(startidx, endidx - 1, endidx - startidx):
        i = int(i)
        NumBins = int(1 + (floor((i+1)*factor) - floor(i*factor)))
        for j in range(NumBins):
            if j == 0:
                #first bin
                scaledspec[int(floor(factor*i))] += (1/factor)*(1 + floor(factor*i)
                                                        - factor*i)*origspec[i]
            elif j == NumBins-1:
                #last bin
                scaledspec[int(floor(factor*(i+1)))] += (1/factor)*(factor*(i + 1)
                                                        - floor(factor*(i+1)))*origspec[i]
            else:
                #intermediate bins
                scaledspec[int(floor(factor*i + j))] += (1/factor)*origspec[i]
    return scaledspec

我尝试使用scipy.optimize.curve_fit(),但由于factor是上述函数中使用的参数,下面的代码将无法工作

popt = np.zeros(15)
pcov = np.zeros(15)

def func(origspec, factor):
    scaletest = LYtest.scalespec(origspec, factor, 750, 1750)
    return(scaletest[int(factor*750):int(factor*1750)])
#ydata = ref[startidx:endidx]
for i in range (0,15):
    xdata = twoDdata[i,:]
    popt[i], pcov[i] = curve_fit(func, xdata, ref[int(factor*750):int(factor*1750)])

运行上述程序的输出。 NameError:未定义名称“factor”


Tags: infornpzeros光谱int不确定性factor

热门问题