List of usage examples for org.apache.commons.math3.analysis.interpolation AkimaSplineInterpolator AkimaSplineInterpolator
AkimaSplineInterpolator
From source file:org.apache.solr.client.solrj.io.eval.AkimaEvaluator.java
@Override public Object doWork(Object... objects) throws IOException { Object first = objects[0];/*from w w w. j av a 2 s. com*/ double[] x = null; double[] y = null; if (objects.length == 1) { //Only the y values passed y = ((List) first).stream().mapToDouble(value -> ((Number) value).doubleValue()).toArray(); x = new double[y.length]; for (int i = 0; i < y.length; i++) { x[i] = i; } } else if (objects.length == 2) { Object second = objects[1]; x = ((List) first).stream().mapToDouble(value -> ((Number) value).doubleValue()).toArray(); y = ((List) second).stream().mapToDouble(value -> ((Number) value).doubleValue()).toArray(); } AkimaSplineInterpolator interpolator = new AkimaSplineInterpolator(); PolynomialSplineFunction spline = interpolator.interpolate(x, y); List<Number> list = new ArrayList(); for (double xvalue : x) { list.add(spline.value(xvalue)); } VectorFunction vec = new VectorFunction(spline, list); vec.addToContext("x", x); vec.addToContext("y", y); return vec; }
From source file:org.meteoinfo.math.interpolate.InterpUtil.java
/** * Make interpolation function/*from www .j a v a2 s . co m*/ * @param x X data * @param y Y data * @param kind Specifies the kind of interpolation as a string (linear, 'spline'). * @return Interpolation function */ public static UnivariateFunction getInterpFunc(Array x, Array y, String kind) { double[] xd = (double[]) ArrayUtil.copyToNDJavaArray(x); double[] yd = (double[]) ArrayUtil.copyToNDJavaArray(y); UnivariateInterpolator li; switch (kind) { case "spline": case "cubic": li = new SplineInterpolator(); break; case "akima": li = new AkimaSplineInterpolator(); break; case "divided": li = new DividedDifferenceInterpolator(); break; case "loess": li = new LoessInterpolator(); break; case "neville": li = new NevilleInterpolator(); break; default: li = new LinearInterpolator(); break; } UnivariateFunction psf = li.interpolate(xd, yd); return psf; }