scipy.optimize.curve

您所在的位置:网站首页 sigma用法 scipy.optimize.curve

scipy.optimize.curve

2023-07-16 09:16| 来源: 网络整理| 查看: 265

scipy.optimize.curve_fit

函数参数列表

scipy.optimize.curve_fit(f, xdata, ydata, p0=None, sigma=None, absolute_sigma=False, check_finite=True, bounds=- inf, inf, method=None, jac=None, **kwargs)[source]

使用非线性最小二乘拟合函数f。 参数列表

f:callable可调用 模型函数,f(x, …)。它必须将自变量作为第一个参数,将拟合的参数作为单独的其余参数。

xdata:array_like or object矩阵或对象 测量的自变量数据。通常应该是一个M长度的序列或一个(k,M)形数组,用于具有k个预测器的函数,但实际上可以是任何对象。

ydata:array_like 因变量数据,一个长度为M的数组–名义上是f(xdata, …)。

p0:array_like, optional可选变量 参数的初始猜测(长度为N)。如果没有,那么初始值将全部为1(如果可以用自省法确定函数的参数数,否则将引发ValueError)。

sigma:None or M-length sequence or MxM array, optional 无或M长度的序列或MxM数组,可选 决定了ydata的不确定性。如果我们把残差定义为r = ydata - f(xdata, *popt),那么sigma的解释就取决于它的维数。 A 1-D sigma should contain values of standard deviations of errors in ydata. In this case, the optimized function is chisq = sum((r / sigma) ** 2). 一维数据sigma应该包含ydata中误差的标准偏差值。在这种情况下,优化后的函数是chisq = sum((r / sigma) ** 2)。 A 2-D sigma should contain the covariance matrix of errors in ydata. In this case, the optimized function is chisq = r.T @ inv(sigma) @ r. 二维数据sigma应该包含ydata中误差的协方差矩阵。在这种情况下,优化后的函数是chisq = r.T @ inv(sigma) @ r。

absolute_sigmabool, optional 如果是True,sigma是在绝对意义上使用的,估计的参数协方差pcov反映这些绝对值。 如果是False(默认),则只有sigma值的相对大小。返回的参数协方差矩阵pcov是基于sigma按常数缩放的结果。这个常数的设置是要求在使用缩放后的西格玛时,最优参数popt的减少的chisq等于统一。换句话说,sigma的比例与拟合后残差的样本方差一致。默认为假。 Mathematically, pcov(absolute_sigma=False) = pcov(absolute_sigma=True) * chisq(popt)/(M-N)

check_finitebool, optional 如果是True,检查输入数组是否包含infs的nans,如果包含则引发ValueError。如果将此参数设置为False,如果输入的数组确实包含nans,可能会默默地产生无意义的结果。默认为True。

bounds:2-tuple of array_like, optional 参数的下限和上限。默认为无界限。元组的每个元素必须是一个数组,其长度等于参数的数量,或者是一个标量(在这种情况下,所有参数的界限都是一样的)。使用带有适当符号的np.inf来禁用所有或部分参数的边界。

method{‘lm’, ‘trf’, ‘dogbox’}, optional 用于优化的方法。更多细节见最小二乘法。对于无约束的问题,默认为’lm’,如果提供了约束,则为’trf’。当观测值的数量少于变量的数量时,‘lm’方法将不起作用,在这种情况下使用’trf’或’dogbox’。

jaccal:lable, string or None, optional 名为jac(x, …)的函数,以密集数组的形式计算模型函数的雅各布矩阵。它将根据所提供的sigma进行缩放。如果没有(默认),雅各布矩阵将被数值估计。trf "和 "dogbox "方法的字符串关键字可以用来选择一个有限差分方案,见least_squares。

返回值

popt:array Optimal values for the parameters so that the sum of the squared residuals of f(xdata, *popt) - ydata is minimized.

pcov:2-D array The estimated covariance of popt. The diagonals provide the variance of the parameter estimate. To compute one standard deviation errors on the parameters use perr = np.sqrt(np.diag(pcov)). How the sigma parameter affects the estimated covariance depends on absolute_sigma argument, as described above.

If the Jacobian matrix at the solution doesn’t have a full rank, then ‘lm’ method returns a matrix filled with np.inf, on the other hand ‘trf’ and ‘dogbox’ methods use Moore-Penrose pseudoinverse to compute the covariance matrix.

https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html#scipy-optimize-curve-fit



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3