Example usage for org.apache.commons.math3.analysis.interpolation AkimaSplineInterpolator interpolate

List of usage examples for org.apache.commons.math3.analysis.interpolation AkimaSplineInterpolator interpolate

Introduction

In this page you can find the example usage for org.apache.commons.math3.analysis.interpolation AkimaSplineInterpolator interpolate.

Prototype

public PolynomialSplineFunction interpolate(double[] xvals, double[] yvals)
        throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException 

Source Link

Document

Computes an interpolating function for the data set.

Usage

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  .  java  2  s  .c  o  m

    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;
}