List of usage examples for org.apache.commons.math.analysis SplineInterpolator SplineInterpolator
SplineInterpolator
From source file:magma.agent.behavior.function.SplineFunction.java
/** * Creates a spline function from the previously set x and y values */// w w w.j a v a 2 s . c o m public void initialize() { try { SplineInterpolator interpolator = new SplineInterpolator(); spline = (PolynomialSplineFunction) interpolator.interpolate(xValues, yValues); xMin = xValues[0]; xMax = xValues[xValues.length - 1]; } catch (IllegalArgumentException e) { System.out.println(e + "\n" + Arrays.toString(xValues)); throw e; } }
From source file:org.xenmaster.scheduler.analytics.Modeler.java
public static void main(String[] args) { try {/* ww w . ja v a2s . co 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); } }