List of usage examples for org.apache.commons.math3.analysis.interpolation SplineInterpolator SplineInterpolator
SplineInterpolator
From source file:gdsc.smlm.ij.plugins.TraceMolecules.java
@SuppressWarnings("unused") private void interpolateZeroCrossingPoints() { double[] x = new double[zeroCrossingPoints.size()]; double[] y = new double[zeroCrossingPoints.size()]; for (int i = 0; i < x.length; i++) { double[] point = zeroCrossingPoints.get(i); x[i] = point[0];/*from ww w . j ava 2 s .c om*/ y[i] = point[1]; } PolynomialSplineFunction fx = new SplineInterpolator().interpolate(x, y); double minX = x[0]; double maxX = x[x.length - 1]; double xinc = (maxX - minX) / 50; for (minX = minX + xinc; minX < maxX; minX += xinc) { zeroCrossingPoints.add(new double[] { minX, fx.value(minX) }); } sortPoints(); }
From source file:org.apache.solr.client.solrj.io.eval.SplineEvaluator.java
@Override public Object doWork(Object... objects) throws IOException { Object first = objects[0];/*from www . java2s .c om*/ double[] x = null; double[] y = null; if (objects.length == 1) { //Only the y values passed y = ((List) first).stream().mapToDouble(value -> ((Number) value).doubleValue()).toArray(); x = new double[y.length]; for (int i = 0; i < y.length; i++) { x[i] = i; } } else if (objects.length == 2) { Object second = objects[1]; x = ((List) first).stream().mapToDouble(value -> ((Number) value).doubleValue()).toArray(); y = ((List) second).stream().mapToDouble(value -> ((Number) value).doubleValue()).toArray(); } SplineInterpolator interpolator = new SplineInterpolator(); PolynomialSplineFunction spline = interpolator.interpolate(x, y); List<Number> list = new ArrayList(); for (double xvalue : x) { list.add(spline.value(xvalue)); } VectorFunction vec = new VectorFunction(spline, list); vec.addToContext("x", x); vec.addToContext("y", y); return vec; }
From source file:org.dawnsci.spectrum.ui.utils.PolynomialInterpolator1D.java
public static IDataset interpolate(IDataset oldx, IDataset oldy, IDataset newx) { //TODO more sanity checks on inputs DoubleDataset dx = (DoubleDataset) DatasetUtils.cast(oldx, Dataset.FLOAT64); DoubleDataset dy = (DoubleDataset) DatasetUtils.cast(oldy, Dataset.FLOAT64); boolean sorted = true; double maxtest = dx.getDouble(0); int count = dx.getSize(); for (int i = 1; i < count; i++) { if (maxtest > dx.getDouble(i)) { sorted = false;//from www . j a v a2s. co m break; } maxtest = dx.getDouble(i); } double[] sortedx = null; double[] sortedy = null; if (!sorted) { IntegerDataset sIdx = getIndiciesOfSorted(dx); sortedx = new double[dx.getData().length]; sortedy = new double[dy.getData().length]; for (int i = 0; i < sIdx.getSize(); i++) { sortedx[i] = dx.getDouble(sIdx.get(i)); sortedy[i] = dy.getDouble(sIdx.get(i)); } } else { sortedx = dx.getData(); sortedy = dy.getData(); } SplineInterpolator si = new SplineInterpolator(); PolynomialSplineFunction poly = si.interpolate(sortedx, sortedy); Dataset newy = DatasetFactory.zeros(newx.getShape(), Dataset.FLOAT64); count = newy.getSize(); newy.setName(oldy.getName() + "_interpolated"); for (int i = 0; i < count; i++) { newy.set(poly.value(newx.getDouble(i)), i); } return newy; }
From source file:org.libreplan.business.planner.entities.StretchesFunctionTypeEnum.java
public static int[] hoursForEachDayUsingSplines(double[] x, double[] y, LocalDate startInclusive, LocalDate endExclusive) { UnivariateFunction accumulatingFunction = new SplineInterpolator().interpolate(x, y); int[] extractAccumulated = extractAccumulated(accumulatingFunction, startInclusive, endExclusive); return extractHoursShouldAssignForEachDay(ValleyFiller.fillValley(extractAccumulated)); }
From source file:org.meteoinfo.math.interpolate.InterpUtil.java
/** * Make interpolation function/*from ww w . j a va 2 s . c o m*/ * @param x X data * @param y Y data * @param kind Specifies the kind of interpolation as a string (linear, 'spline'). * @return Interpolation function */ public static UnivariateFunction getInterpFunc(Array x, Array y, String kind) { double[] xd = (double[]) ArrayUtil.copyToNDJavaArray(x); double[] yd = (double[]) ArrayUtil.copyToNDJavaArray(y); UnivariateInterpolator li; switch (kind) { case "spline": case "cubic": li = new SplineInterpolator(); break; case "akima": li = new AkimaSplineInterpolator(); break; case "divided": li = new DividedDifferenceInterpolator(); break; case "loess": li = new LoessInterpolator(); break; case "neville": li = new NevilleInterpolator(); break; default: li = new LinearInterpolator(); break; } UnivariateFunction psf = li.interpolate(xd, yd); return psf; }
From source file:org.powertac.producer.pvfarm.IrradianceModelTest.java
@Test public void dataTrSpline() throws IOException { double[] airmass = { 0.5, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 10.0, 30.0, 40 }; double[] Tr = { 0.9385, 0.8973, 0.8830, 0.8696, 0.8572, 0.8455, 0.8344, 0.7872, 0.7673, 0.7493, 0.7328, 0.7177, 0.7037, 0.6907, 0.6108, 0.4364, 0.41 }; assert (Tr.length == airmass.length); PolynomialSplineFunction spline = new SplineInterpolator().interpolate(airmass, Tr); File file = new File("data/dataTrSpline.txt"); file.createNewFile();/*from ww w .j a va2 s. c o m*/ PrintWriter pw = new PrintWriter(new File("data/dataTrSpline.txt")); for (double i = 0.5; i < 40.0; i += 0.1) { pw.printf(Locale.UK, "%f,%f%n", i, spline.value(i)); } pw.close(); }
From source file:org.ratchetrobotics.algorithms.ai.ResponseCurve.java
/** * Constructs a <code>ResponseCurve</code> by interpolating arrays of curve points. * * @param x x-values of curve points// www . jav a 2 s. c o m * @param y y-values of curve points */ public ResponseCurve(double[] x, double[] y) { this.splineInterpolator = new SplineInterpolator(); this.splineFunction = this.splineInterpolator.interpolate(x, y); }
From source file:org.ratchetrobotics.algorithms.ai.ResponseCurve.java
/** * Constructs a <code>ResponseCurve</code> by interpolating arrays of curve points. * * @param points points in the curve/*from w ww . ja v a 2s . c o m*/ */ public ResponseCurve(List<Vector2D> points) { PointsConverterDoubleArray doublePoints = new PointsConverter(points).toDoubleArrays(); this.splineInterpolator = new SplineInterpolator(); this.splineFunction = this.splineInterpolator.interpolate(doublePoints.getX(), doublePoints.getY()); }
From source file:uk.ac.diamond.scisoft.analysis.dataset.function.Interpolation1D.java
public static Dataset splineInterpolation(IDataset x, IDataset y, IDataset xnew) { return interpolate(x, y, xnew, new SplineInterpolator()); }
From source file:uk.ac.diamond.scisoft.analysis.diffraction.powder.PixelIntegrationUtils.java
public static Dataset generate2Dfrom1D(IDataset[] xy1d, Dataset array2Dx) { DoubleDataset[] inXy1D = new DoubleDataset[2]; inXy1D[0] = (DoubleDataset) DatasetUtils.cast(xy1d[0], Dataset.FLOAT64); inXy1D[1] = (DoubleDataset) DatasetUtils.cast(xy1d[1], Dataset.FLOAT64); double min = inXy1D[0].min().doubleValue(); double max = inXy1D[0].max().doubleValue(); SplineInterpolator si = new SplineInterpolator(); PolynomialSplineFunction poly = si.interpolate(inXy1D[0].getData(), inXy1D[1].getData()); Dataset image = DatasetFactory.zeros(array2Dx.getShape(), Dataset.FLOAT64); double[] buf = (double[]) image.getBuffer(); IndexIterator iterator = array2Dx.getIterator(); while (iterator.hasNext()) { double e = array2Dx.getElementDoubleAbs(iterator.index); if (e <= max && e >= min) buf[iterator.index] = poly.value(e); }/* w w w.j av a 2s . c o m*/ return image; }