List of usage examples for org.apache.commons.collections.primitives DoubleList toArray
double[] toArray();
From source file:cz.cuni.lf1.lge.ThunderSTORM.results.ModifiedLoess.java
/** * Compute an interpolating function by performing a loess fit * on the data at the original abscissae and then building a cubic spline * with a//from ww w .j av a 2 s. co m * {@link org.apache.commons.math3.analysis.interpolation.SplineInterpolator} * on the resulting fit. * * @param xval the arguments for the interpolation points * @param yval the values for the interpolation points * @return A cubic spline built upon a loess fit to the data at the original abscissae * @throws NonMonotonicSequenceException if {@code xval} not sorted in * strictly increasing order. * @throws DimensionMismatchException if {@code xval} and {@code yval} have * different sizes. * @throws NoDataException if {@code xval} or {@code yval} has zero size. * @throws NotFiniteNumberException if any of the arguments and values are * not finite real numbers. * @throws NumberIsTooSmallException if the bandwidth is too small to * accomodate the size of the input data (i.e. the bandwidth must be * larger than 2/n). */ public final PolynomialSplineFunction interpolate(double[] xval, double[] yval) throws NonMonotonicSequenceException, DimensionMismatchException, NoDataException, NotFiniteNumberException, NumberIsTooSmallException { double[] smoothed = smooth(xval, yval); DoubleList newX = new ArrayDoubleList(); DoubleList newSmoothed = new ArrayDoubleList(); newX.add(xval[0]); newSmoothed.add(smoothed[0]); for (int i = 1; i < xval.length; i++) { if (xval[i] != xval[i - 1]) { newX.add(xval[i]); newSmoothed.add(smoothed[i]); } } xval = newX.toArray(); smoothed = newSmoothed.toArray(); return new SplineInterpolator().interpolate(xval, smoothed); }