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

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

Introduction

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

Prototype

public double[] getKnots() 

Source Link

Document

Returns an array copy of the knot points.

Usage

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

public static void main(String[] args) {
    try {/* w  w w  .  j  a v  a2s.  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);
    }
}