对一个(或两个)数组进行插值
我正在寻找一个 java 库或一些帮助来编写我自己的插值函数.也就是说,我有两个双精度数组,它们的大小可能不同,但是是有序的.我需要能够估计中间值,并插入以便两个数组的大小相同.事实上,插值中出现的点总数是 2 个数组大小的总和减去 1.但是每个数组的范围必须保持不变,因此不需要外插.
I'm looking for a java library or some help to write my own interpolation function. That is I have two arrays of doubles which are potentially different sizes, but are ordered. I need to be able to make an estimate of intermediate values, and insert so that both arrays become the same size. In fact the total number of points appearing in the interpolation is the sum of the 2 array sizes minus 1. The range of each array must stay the same however, so there is no extrapolation needed.
例如.a1 = [1, 4, 9, 16, 25, 36] 和 a2 = [6, 9, 14, 30]
eg. a1 = [1, 4, 9, 16, 25, 36] and a2 = [6, 9, 14, 30]
结果可能是这样的.
a1 = [1, 2.25, 4, 6.25, 9, 12.25, 16, 25, 36]和a2 = [6, 6.5625, 7.25, 9, 10.0625, 11.25, 14, 25.25, 30]
a1 = [1, 2.25, 4, 6.25, 9, 12.25, 16, 25, 36] and a2 = [6, 6.5625, 7.25, 9, 10.0625, 11.25, 14, 25.25, 30]
这些例子是 f(x) = x^2 和 g(x) = x^2 + 5
,但是很容易是任何多项式 - 重点是能够估计/足够好地从数据集中逼近函数,以提供足够好的插值.这里的 x 值只是输入数组的索引.在输出中,只有 y 值很重要.
these examples are f(x) = x^2 and g(x) = x^2 + 5
, however could easily have been any polynomial - the point is to be able to estimate/approximate the function from the dataset well enough to provide decent enough interpolation. Here the x value is just the index of the input array. In the output only the y values are important.
推荐答案
其他答案为您提供线性插值 - 这些对于复杂的非线性数据实际上并不适用.你想要一个 样条拟合,(样条插值)我相信.
The other answers give you linear interpolations -- these don't really work for complex, nonlinear data. You want a spline fit, (spline interpolation) I believe.
样条拟合使用数据中的一组控制点来描述数据区域,然后在控制点之间应用多项式插值.更多控制点为您提供更准确的拟合,而不是更一般的拟合.样条曲线比线性拟合准确得多,比一般回归拟合使用更快,比高阶多项式更好,因为它不会在控制点之间做疯狂的事情.
Spline fits describe regions of the data using a set of control points from the data, then apply a polynomial interpolation between control points. More control points gives you a more accurate fit, less a more general fit. Splines are much more accurate than linear fits, faster to use than a general regression fit, better than a high-order polynomial because it won't do crazy things between control points.
我一时想不起来名字,但 Java 中有一些非常合适的库——我建议您寻找一个而不是编写自己的函数.
I can't remember names off the top of my head, but there are some excellent fitting libraries in Java -- I suggest you look for one rather than writing your own function.
**可能有用的库:**
** Libraries that might be useful: **
- JMSL
- JSpline+
- Curfiting 库(希望你能看懂德语)
- JMSL
- JSpline+
- Curfitting library (hope you can read German)
** 可能有用的理论/代码:**
** Theory/code that may be useful: **
- 带有代码的样条小程序:链接
- Arkan 将折线拟合为贝塞尔样条的样条
- 样条线理论,以及一些拟合数学.如果库不这样做,更多的数学,更少的代码可能会有所帮助.
- Spline applets with code: link
- Arkan spline fitting for poly-lines to bezier splines
- Theory of splines, and some math for fitting. More math, less code, might help if the libraries don't.
相关文章