I’m trying to use SplineInterpolator
and PolynomialSplineFunction to double a dataset. I think I’m fairly far along the path (I’m probably missing some exception handling):
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;
}
But the above is gonna crash in the last for loop at the latest. So, do I have the first part more or less right? After I have my polynomial spline function, how do I use that to create a larger dataset?
In case anybody is following along at home, here is the implementation I came up with for this:
I also figured out how to do the probably more useful fill-in-blanks use if anybody needs it.