Example usage for org.apache.commons.math.analysis PolynomialSplineFunction value

List of usage examples for org.apache.commons.math.analysis PolynomialSplineFunction value

Introduction

In this page you can find the example usage for org.apache.commons.math.analysis PolynomialSplineFunction value.

Prototype

public double value(double v) throws FunctionEvaluationException 

Source Link

Document

Compute the value for the function.

Usage

From source file:org.xenmaster.scheduler.analytics.Modeler.java

public static void main(String[] args) {
    try {//from   ww w  . j  a va  2  s .c o m
        ArrayList<Double> vals;
        try (BufferedReader br = new BufferedReader(new FileReader("data.csv"))) {
            vals = new ArrayList<>();
            String line = br.readLine();
            while (line != null) {
                String[] split = StringUtils.split(line, ',');
                vals.add(Double.parseDouble(split[0]));
                line = br.readLine();
            }
        }

        double[] idx = new double[1440];
        for (int i = 0; i < idx.length; i++) {
            idx[i] = i;
        }
        double y[] = new double[1440];
        for (int i = 0; i < idx.length; i++) {
            y[i] = vals.get(i).doubleValue();
        }
        SplineInterpolator si = new SplineInterpolator();
        PolynomialSplineFunction psf = (PolynomialSplineFunction) si.interpolate(idx, y);

        for (int i = 0; i < 3; i++) {
            psf = psf.polynomialSplineDerivative();
        }

        try (BufferedWriter bw = new BufferedWriter(new FileWriter("derp.csv", false))) {
            for (double i = psf.getKnots()[0]; i < psf.getKnots()[psf.getKnots().length - 1]; i++) {
                bw.append("" + psf.value(i) + "\n");
            }
        } catch (ArgumentOutsideDomainException | IOException ex) {

        }

    } catch (IOException ex) {
        Logger.getLogger(Modeler.class.getName()).log(Level.SEVERE, null, ex);
    }
}