本文介绍了线性曲线拟合有误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种在Javascript中执行线性曲线拟合的方法。我发现了几个库,但它们没有传播错误。我的意思是,我有数据和相关的测量误差,如:

I was looking for a way to perform a linear curve fit in Javascript. I found several libraries, but they don't propagate errors. What I mean is, I have data and associated measurement errors, like:

x = [ 1.0 +/- 0.1, 2.0 +/- 0.1, 3.1 +/- 0.2, 4.0 +/- 0.2 ]
y = [ 2.1 +/- 0.2, 4.0 +/- 0.1, 5.8 +/- 0.4, 8.0 +/- 0.1 ]

我的符号 a +/- b 表示 {值:a,错误:b}

我想将其纳入 y = mx + b ,找到 m b 及其传播错误。我知道我可以实现的最小二乘法算法,但它只对y变量产生错误,并且我在两者中都有明显的错误。

I want to fit this into y = mx + b, and find m and b with their propagated errors. I know the Least Square Method algorithm, that I could implement, but it only take errors on the y variable, and I have distinct errors in both.

我也找不到Javascript中的库来做到这一点;但如果有一个其他语言的开源库,我可以检查它以了解如何在JS中实现它。

I also could not find a library in Javascript to do that; but if there is an open source lib in other language, I can inspect it to find out how and implement it in JS.

像Origin或plotly这样的程序能够实现这个,但我不知道怎么做。此示例数据集的结果是:

Programs like Origin or plotly are able to implement this, but I don't know how. The result for this example dataset is:

m = 1.93 +/- 0.11
b = 0.11 +/- 0.30


推荐答案

非常有用的书提供了一种将数据拟合到直线上的方法,X和Y坐标都存在不确定性。在这两个版本中可以找到:

The very useful book Numerical Recipes provides a method to fit data to a straight line, with uncertainties in both X and Y coordinates. It can be found online in these two versions:


  • ,第15节-3

  • ,在

  • Numerical Recipes in C, in section 15-3
  • Numerical Recipes in Fortran 77, in section 15-3

该方法基于最小化χ (卡方),它与最小二乘法相似,但考虑了每个数据点的个体不确定性。当不确定性σ 仅在Y轴上时,与1 /σ 成比例的权重被分配给计算。当数据在X和Y坐标中存在不确定性时,分别由σ 和σ 给出,适合直线

The method is based on minimizing the χ (chi-square) which is similar to the least-square but takes into account the individual uncertainty of each data point. When the uncertainty σ is on the Y axis only, a weight proportional to 1/σ is assigned to the point in the calculations. When the data has uncertainties in the X and Y coordinates, given by σ and σ respectively, the fit to a straight line

使用χ ,其中每个点的权重与

uses a χ where each point has a weight proportional to

详细方法和代码(在C或Fortran中)可以在书中找到。由于,我无法在此处重现。

The detailed method and the code (in C or Fortran) can be found in the book. Due to copyright, I cannot reproduce them here.

这篇关于线性曲线拟合有误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:14