List of usage examples for org.apache.commons.math3.util MathArrays isMonotonic
public static boolean isMonotonic(double[] val, OrderDirection dir, boolean strict)
From source file:be.ugent.maf.cellmissy.analysis.singlecell.processing.impl.interpolation.TrackLinearInterpolator.java
@Override public InterpolatedTrack interpolateTrack(double[] time, double[] x, double[] y) { // create a new linear interpolator LinearInterpolator linearInterpolator = new LinearInterpolator(); int interpolationPoints = PropertiesConfigurationHolder.getInstance().getInt("numberOfInterpolationPoints"); // create arrays to hold the interpolant time, the interpolated X and the interpolated Y double[] interpolantTime = new double[interpolationPoints]; double[] interpolatedX = new double[interpolationPoints]; double[] interpolatedY = new double[interpolationPoints]; // the step used for the interpolation in both direction double interpolationStep = (time[time.length - 1] - time[0]) / interpolationPoints; // check for monotonicity boolean monotonic = MathArrays.isMonotonic(time, MathArrays.OrderDirection.INCREASING, false); // in case time is not monotonic, sort in place time, x and y coordinates if (!monotonic) { MathArrays.sortInPlace(time, x, y); }/* ww w .j av a 2s .c o m*/ // call the interpolator, and actually do the interpolation try { PolynomialSplineFunction functionX = linearInterpolator.interpolate(time, x); PolynomialSplineFunction functionY = linearInterpolator.interpolate(time, y); // get the polynomial functions in both directions PolynomialFunction polynomialFunctionX = functionX.getPolynomials()[0]; PolynomialFunction polynomialFunctionY = functionY.getPolynomials()[0]; for (int i = 0; i < interpolationPoints; i++) { interpolantTime[i] = time[0] + (i * interpolationStep); interpolatedX[i] = functionX.value(interpolantTime[i]); interpolatedY[i] = functionY.value(interpolantTime[i]); } for (int k = 0; k < interpolationPoints; k++) { if (Double.isNaN(interpolatedX[k]) | Double.isNaN(interpolatedY[k])) { return null; } } return new InterpolatedTrack(interpolantTime, interpolatedX, interpolatedY, polynomialFunctionX, polynomialFunctionY); } catch (NumberIsTooSmallException e) { LOG.error(e.getMessage()); return null; } }
From source file:be.ugent.maf.cellmissy.analysis.singlecell.processing.impl.interpolation.TrackLoessInterpolator.java
@Override public InterpolatedTrack interpolateTrack(double[] time, double[] x, double[] y) { // create a new interpolator LoessInterpolator loessInterpolator = new LoessInterpolator(); int interpolationPoints = PropertiesConfigurationHolder.getInstance().getInt("numberOfInterpolationPoints"); // create arrays to hold the interpolant time, the interpolated X and the interpolated Y double[] interpolantTime = new double[interpolationPoints]; double[] interpolatedX = new double[interpolationPoints]; double[] interpolatedY = new double[interpolationPoints]; // the step used for the interpolation in both direction double interpolationStep = (time[time.length - 1] - time[0]) / interpolationPoints; // check for monotonicity boolean monotonic = MathArrays.isMonotonic(time, MathArrays.OrderDirection.INCREASING, false); // in case time is not monotonic, sort in place time, x and y coordinates if (!monotonic) { MathArrays.sortInPlace(time, x, y); }/*w w w.ja v a 2 s .c o m*/ // call the interpolator, and actually do the interpolation try { PolynomialSplineFunction functionX = loessInterpolator.interpolate(time, x); PolynomialSplineFunction functionY = loessInterpolator.interpolate(time, y); // get the polynomial functions in both directions PolynomialFunction polynomialFunctionX = functionX.getPolynomials()[0]; PolynomialFunction polynomialFunctionY = functionY.getPolynomials()[0]; for (int i = 0; i < interpolationPoints; i++) { interpolantTime[i] = time[0] + (i * interpolationStep); interpolatedX[i] = functionX.value(interpolantTime[i]); interpolatedY[i] = functionY.value(interpolantTime[i]); } for (int k = 0; k < interpolationPoints; k++) { if (Double.isNaN(interpolatedX[k]) | Double.isNaN(interpolatedY[k])) { return null; } } return new InterpolatedTrack(interpolantTime, interpolatedX, interpolatedY, polynomialFunctionX, polynomialFunctionY); } catch (NumberIsTooSmallException e) { LOG.error(e.getMessage()); return null; } }
From source file:be.ugent.maf.cellmissy.analysis.singlecell.processing.impl.interpolation.TrackSplineInterpolator.java
@Override public InterpolatedTrack interpolateTrack(double[] time, double[] x, double[] y) { // create a new spline interpolator SplineInterpolator splineInterpolator = new SplineInterpolator(); int interpolationPoints = PropertiesConfigurationHolder.getInstance().getInt("numberOfInterpolationPoints"); // create arrays to hold the interpolant time, the interpolated X and the interpolated Y double[] interpolantTime = new double[interpolationPoints]; double[] interpolatedX = new double[interpolationPoints]; double[] interpolatedY = new double[interpolationPoints]; // the step used for the interpolation in both direction double interpolationStep = (time[time.length - 1] - time[0]) / interpolationPoints; // check for monotonicity boolean monotonic = MathArrays.isMonotonic(time, MathArrays.OrderDirection.INCREASING, false); // in case time is not monotonic, sort in place time, x and y coordinates if (!monotonic) { MathArrays.sortInPlace(time, x, y); }//from w w w .j a va 2 s . c om // call the interpolator, and actually do the interpolation try { PolynomialSplineFunction functionX = splineInterpolator.interpolate(time, x); PolynomialSplineFunction functionY = splineInterpolator.interpolate(time, y); // get the polynomial functions in both directions PolynomialFunction polynomialFunctionX = functionX.getPolynomials()[0]; PolynomialFunction polynomialFunctionY = functionY.getPolynomials()[0]; for (int i = 0; i < interpolationPoints; i++) { interpolantTime[i] = time[0] + (i * interpolationStep); interpolatedX[i] = functionX.value(interpolantTime[i]); interpolatedY[i] = functionY.value(interpolantTime[i]); } for (int k = 0; k < interpolationPoints; k++) { if (Double.isNaN(interpolatedX[k]) | Double.isNaN(interpolatedY[k])) { return null; } } return new InterpolatedTrack(interpolantTime, interpolatedX, interpolatedY, polynomialFunctionX, polynomialFunctionY); } catch (NumberIsTooSmallException e) { LOG.error(e.getMessage()); return null; } }
From source file:be.ugent.maf.cellmissy.analysis.singlecell.processing.impl.interpolation.TrackHermiteInterpolator.java
@Override public InterpolatedTrack interpolateTrack(double[] time, double[] x, double[] y) { // create interpolators for X and Y HermiteInterpolator xHermite = new HermiteInterpolator(); HermiteInterpolator yHermite = new HermiteInterpolator(); int interpolationPoints = PropertiesConfigurationHolder.getInstance().getInt("numberOfInterpolationPoints"); // create arrays to hold the interpolant time, the interpolated X and the interpolated Y double[] interpolantTime = new double[interpolationPoints]; double[] interpolatedX = new double[interpolationPoints]; double[] interpolatedY = new double[interpolationPoints]; // the step used for the interpolation in both direction double interpolationStep = (time[time.length - 1] - time[0]) / interpolationPoints; // check for monotonicity boolean monotonic = MathArrays.isMonotonic(time, MathArrays.OrderDirection.INCREASING, false); // in case time is not monotonic, sort in place time, x and y coordinates if (!monotonic) { MathArrays.sortInPlace(time, x, y); }/*from ww w . j a v a 2s .co m*/ double[] internalPointsDerivativeX = internalPointsDerivative(time, x); double[] internalPointsDerivativeY = internalPointsDerivative(time, y); double[] endPointsDerivativeX = endPointsDerivative(time, x); double[] endPointsDerivativeY = endPointsDerivative(time, y); // call the interpolator and add sample points to it // we do add only the values, and not their derivatives for (int i = 0; i < time.length; i++) { if (i == 0) { xHermite.addSamplePoint(time[i], new double[] { x[i] }, new double[] { endPointsDerivativeX[0] }); yHermite.addSamplePoint(time[i], new double[] { y[i] }, new double[] { endPointsDerivativeY[0] }); } else if (i == time.length - 1) { xHermite.addSamplePoint(time[i], new double[] { x[i] }, new double[] { endPointsDerivativeX[1] }); yHermite.addSamplePoint(time[i], new double[] { y[i] }, new double[] { endPointsDerivativeY[1] }); } else { xHermite.addSamplePoint(time[i], new double[] { x[i] }, new double[] { internalPointsDerivativeX[i - 1] }); yHermite.addSamplePoint(time[i], new double[] { y[i] }, new double[] { internalPointsDerivativeY[i - 1] }); } } for (int i = 0; i < interpolationPoints; i++) { interpolantTime[i] = time[0] + (i * interpolationStep); interpolatedX[i] = xHermite.value(interpolantTime[i])[0]; interpolatedY[i] = yHermite.value(interpolantTime[i])[0]; } // get the polynomial functions in both directions PolynomialFunction polynomialFunctionX = xHermite.getPolynomials()[0]; PolynomialFunction polynomialFunctionY = yHermite.getPolynomials()[0]; return new InterpolatedTrack(interpolantTime, interpolatedX, interpolatedY, polynomialFunctionX, polynomialFunctionY); }