我正在尝试使用SplineInterpolator 和PolynomialSplineFunction将数据集加倍。我想我已经走得很远了(我可能错过了一些异常处理):
SplineInterpolator splineInterp;
public double[] doubledArray(double[] y){
double[] yy = new double[y.length*2];
// make a double version of y w/ -1 for "null" values
for(int i = 0; i < yy.length; i++){
if(i%2 == 0)
yy[i] = y[i];
else if(i == yy.length-1)
yy[i] = yy[0];
else
yy[i] = -1;
}
// make a corresponding x array to satisfy SplineInterpolator.interpolate
double[] x = new double[y.length];
for(int i = 0; i < x.length; i++)
x[i] = i;
splineInterp = new SplineInterpolator();
PolynomialSplineFunction polySplineF = splineInterp.interpolate(x, y);
for(int i = 0; i < yy.length; i++){
if(yy[i] == -1){
yy[i] = polySplineF.value(i);
// breaks down halfway through polySplineF.value expects and array of y.length
}
}
return yy;
}
但是上面的内容最迟会在最后一个 for 循环中崩溃。那么,我的第一部分或多或少是对的吗?拥有多项式样条函数后,如何使用它来创建更大的数据集?