[英]How to use BicubicSplineInterpolator in Apache Commons Math?
I have three arrays x,y and value. 我有三个数组x,y和value。 for each x,y , f(x,y) = value; 对于每个x,y,f(x,y)=值;
I did not understand how to use the BicubicSplineInterpolator class. 我不明白如何使用BicubicSplineInterpolator类。 I need to find values for different x and y 我需要找到不同的x和y的值
Here is a link to the class http://commons.apache.org/proper/commons-math/javadocs/api-3.3/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolator.html 这是指向该类的链接http://commons.apache.org/proper/commons-math/javadocs/api-3.3/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolator.html
TIA TIA
From the doc, BicubicSplineInterpolator() requires the data points to form a grid-like pattern. 从文档开始,BicubicSplineInterpolator()要求数据点形成网格状图案。 Therefore, you should provide an array of x values (length = m) and an array of y values (length = m) and a matrix of function values (length= mxn). 因此,您应该提供一个x值数组(长度= m)和一个y值数组(长度= m)以及一个函数值矩阵(长度= mxn)。
I agree the docs are quite counter-intuitive. 我同意这些文档是违反直觉的。 To make things worse, BicubicSplineInterpolator() is buggy, see https://issues.apache.org/jira/browse/MATH-1166 , use instead BicubicInterpolator as documented at http://commons.apache.org/proper/commons-math/changes-report.html . 更糟的是,BicubicSplineInterpolator()有问题,请参阅https://issues.apache.org/jira/browse/MATH-1166 ,而应使用BicubicInterpolator,如http://commons.apache.org/proper/commons- math / changes-report.html 。
The interpolation works with a regular grid (eg a 3x3 grid, and you have a value at each grid point). 插值适用于常规网格(例如3x3网格,并且每个网格点都有一个值)。
You need to define the grid positions. 您需要定义网格位置。 (In this example, we have 0, 128, 256 in both x and y dimension. However these are just numbers, you can have on X eg temperature, and humidity on Y with different ranges.) (在此示例中,我们在x和y维度上都有0、128、256。但是,这些只是数字,您可以在X上使用,例如温度和湿度在Y上使用不同的范围。)
Then define a matrix with the actual values at each grid point, make an interpolator which returns an interpolating function, which can calculate any value at any x,y. 然后定义一个在每个网格点具有实际值的矩阵,制作一个插值器,该插值器返回一个插值函数,该函数可以计算任何x,y处的任何值。
final double[] xValues = new double[] {0,128,256};
final double[] yValues = new double[] {0,128,256};
final double[][] fValues = new double[][] {{1, 0, 1},
{0, 0, 1},
{0, 0, 1}};
final BivariateGridInterpolator interpolator = new BicubicInterpolator();
final BivariateFunction function = interpolator.interpolate(xValues, yValues,fValues);
for (int y=0;y<255;y++) {
for (int x=0;x<255;x++) {
double value=function.value(x, y);
// do something with this
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.