use of org.apache.commons.math3.analysis.interpolation.AkimaSplineInterpolator in project mafscaling by vimsh.
the class BilinearInterpolator method interpolate.
/**
* Method returns an interpolated/extrapolated value, based on
* @param x, array of x values
* @param y, array of y values
* @param xi, is x value you want to interpolate at
* @param type, interpolation method type
* @return interpolated value
* @throws Exception
*/
public static double interpolate(double[] x, double[] y, double xi, InterpolatorType type) throws Exception {
UnivariateInterpolator interpolator = null;
switch(type) {
case AkimaCubicSpline:
interpolator = new AkimaSplineInterpolator();
break;
case Linear:
interpolator = new LinearInterpolator();
break;
case Regression:
interpolator = new LoessInterpolator();
break;
case CubicSpline:
interpolator = new SplineInterpolator();
break;
default:
throw new Exception("Invalid interpolator type for this function");
}
UnivariateFunction function = interpolator.interpolate(x, y);
PolynomialFunction[] polynomials = ((PolynomialSplineFunction) function).getPolynomials();
if (xi > x[x.length - 1])
return polynomials[polynomials.length - 1].value(xi - x[x.length - 2]);
if (xi < x[0])
return polynomials[0].value(xi - x[0]);
return function.value(xi);
}
Aggregations