简体   繁体   English

scipy.optimize.least_squares 中雅可比矩阵的协方差数

[英]Covariance numbers from Jacobian Matrix in scipy.optimize.least_squares

I wanted to fit a logistic curve to some data.我想为一些数据拟合一条逻辑曲线。 I used the general equation of the logistic curve to fit to my data.我使用逻辑曲线的一般方程来拟合我的数据。 Find it here . 在这里找到它。

def generate_data(t, A, K, C, Q, B, v):

    y = A+ (K-A)*((C+Q*np.exp(-B*t))**(1/v))

    return y

Here A, K, C, Q, B and v were variables I wanted to find.这里 A、K、C、Q、B 和 v 是我想找到的变量。

I used the scipy.optimize.least_squares function to get the values to generate my curve.我使用scipy.optimize.least_squares function 来获取生成曲线的值。

This was the argument function.这是参数 function。

def fun(x, t, y):
    return x[0] + (x[1]-x[0])*((x[2]+x[3]*np.exp(-x[4]*t))**(1/x[5])) - y

And this is how I called he actual optimisation function.这就是我称他为实际优化 function 的方式。

res_lsq= least_squares(fun, x0, args=(x_coord, y_coord))

Visually, the curve fit the data excellently.从视觉上看,曲线非常适合数据。 在此处输入图像描述

I then calculated the Covariance matrix by this method.然后我通过这种方法计算了协方差矩阵。

J = res_lsq.jac
cov = np.linalg.inv(J.T.dot(J))

And then the variance using this method.然后使用这种方法的方差。

var = np.sqrt(np.diagonal(cov))

The problem is that for these were the values for my parameters.问题是这些是我的参数的值。

Parameters= [ 1.94624122  5.66832958  5.21005677 -4.87025481  0.02520876  0.15057123 ]

And these were my variance values.这些是我的方差值。

Variance= [3.38436210e-01 3.94262000e+03 8.30968350e+02 7.76773161e+02
 6.44604446e-05 6.49474460e-04]

One value is 3942 for a parameter rhat is 5.66 What do these values mean?一个值为 3942 的参数 rhat 是 5.66 这些值是什么意思? Does this data actually show how well the curve fits the data?这些数据是否真的显示了曲线与数据的拟合程度? How do I get such a quantity, like an analogue to a p-value etc. ?我如何获得这样的数量,例如 p 值的类似物等?

I was facing a similar issue.我面临着类似的问题。

I found a similar question .我发现了一个类似的问题

There they explain that you need to multiply the cov that you mentioned by the Mean Squared Error, that is ``sum[(f(x)-y)^2]/(Nn)```, where N is the length of the data and n is the number of parameters you are fitting.他们在那里解释说,您需要将您提到的cov乘以均方误差,即“sum[(f(x)-y)^2]/(Nn)”,其中 N 是数据和 n 是您要拟合的参数数量。 It will probably yield a small number and your variance will probably reduce.它可能会产生一个小数字,并且您的方差可能会减少。

All the best,一切顺利,

Murilo穆里洛

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 scipy.optimize.least_squares-雅可比评估的限制数量 - scipy.optimize.least_squares - limit number of jacobian evaluations 结合 Sympy 与 scipy.optimize.least_squares - Combining Sympy with scipy.optimize.least_squares scipy.optimize.least_squares确定性吗? - Is scipy.optimize.least_squares deterministic? 将字典传递给`scipy.optimize.least_squares` - Passing a dictonary to `scipy.optimize.least_squares` 等效于scipy.optimize.least_squares中(segy.optimize.leastsq中的(旧版)cov_x - Equivalent of cov_x from (legacy) scipy.optimize.leastsq in scipy.optimize.least_squares 从 scipy optimize.least_squares 方法获取拟合参数的协方差矩阵 - Getting covariance matrix of fitted parameters from scipy optimize.least_squares method SciPy.optimize.least_squares() 5PL曲线优化问题 - SciPy.optimize.least_squares() 5PL Curve Optimization problems 如何在“scipy.optimize.least_squares”中添加 Tikhonov 正则化? - How to add Tikhonov regularization in “scipy.optimize.least_squares”? 编写错误函数以在python中喂scipy.optimize.least_squares - Writing an error function to feed scipy.optimize.least_squares in python scipy.optimize.least_squares和MATLAB lsqnonlin的区别 - scipy.optimize.least_squares and matlab lsqnonlin difference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM