简体   繁体   English

在 MATLAB 中使用 Levenberg-Marquardt (lsqcurvefit) 时获取协方差矩阵

[英]Getting covariance matrix when using Levenberg-Marquardt (lsqcurvefit) in MATLAB

I am using the lsqcurvefit function in Matlab to model some experimental data.我在 Matlab 中使用 lsqcurvefit 函数来模拟一些实验数据。 The data takes a specific shape and so the algorithm is just adjusting the coefficients of this shape to change its amplitude etc.数据具有特定的形状,因此算法只是调整该形状的系数以改变其幅度等。

The model works fine and gives a good fit (I have calculated chi-sq).该模型工作正常,并提供了很好的拟合(我已经计算了 chi-sq)。 Other implementations of the Levenberg-Marquardt algorithm give covariance as an output but in Matlab it is not an option for output (only 1st order optimality, no of iterations, Lambda and Jaccobian along with the bounds) . Levenberg-Marquardt 算法的其他实现将协方差作为输出,但在 Matlab 中它不是输出的选项(只有一阶最优性,没有迭代,Lambda 和 Jaccobian 以及边界)。

Does anybody know how to calculate the covariance matrix either from the outputs given (I'm not 100% on what use lambda and jaccobian could be or 1st order optimallity) by lsqcurvefit or independantly?有没有人知道如何通过 lsqcurvefit 或独立地从给出的输出(我不是 100% 使用 lambda 和 jaccobian 或一阶最优性)来计算协方差矩阵?

Any help would be greatly appreciated, thanks!任何帮助将不胜感激,谢谢!

I think I have solved this myself but will post how here if anyone else is having the same trouble.我想我自己已经解决了这个问题,但如果其他人遇到同样的问题,我会在这里发布。

The covariance matrix can be calculated from the Jacobian by:协方差矩阵可以通过雅可比矩阵计算:

C = inv(J'*J)*MSE C = inv(J'*J)*MSE

Where MSE is mean-square error:其中 MSE 是均方误差:

MSE = (R'*R)/(Np) MSE = (R'*R)/(Np)

Where R = residuals, N = number of observations, p = number of coefficients estimated.其中 R = 残差,N = 观察次数,p = 估计系数的数量。

Or MSE can be calculated via iteration.或者 MSE 可以通过迭代计算。

Hopefully this will help someone else in the future.希望这会在将来对其他人有所帮助。

If anyone spots error please let me know.如果有人发现错误,请告诉我。 Thanks谢谢

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM