List of usage examples for org.apache.commons.math3.analysis.interpolation SplineInterpolator interpolate
public PolynomialSplineFunction interpolate(double x[], double y[]) throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException
From source file:com.github.vatbub.tictactoe.view.Main.java
private void updateAILevelLabel(boolean forceUpdate) { double sliderPos = 100 * Math.round(aiLevelSlider.getValue() * 3.0 / 100.0) / 3.0; if (sliderPos != aiLevelLabelPositionProperty.get() || forceUpdate) { aiLevelLabelPositionProperty.set(sliderPos); // request focus of the current ai label for accessibility aiLevelLabelHBox.getChildren().get((int) (sliderPos * 3 / 100)).requestFocus(); updateAccessibleTexts();/*from ww w . ja va 2 s.c om*/ // get the slider position double[] xDouble = new double[] { 0, 100.0 / 3.0, 200.0 / 3.0, 300.0 / 3.0 }; double[] translationYDouble = new double[4]; double[] widthYDouble = new double[4]; double[] trueWidthYDouble = new double[4]; for (int i = 0; i < translationYDouble.length; i++) { // {-getAILevelLabelCenter(0), -getAILevelLabelCenter(1), -getAILevelLabelCenter(2), -getAILevelLabelCenter(3)}; translationYDouble[i] = -getAILevelLabelCenter(i); widthYDouble[i] = Math.max(90, ((Label) aiLevelLabelHBox.getChildren().get(i)).getWidth() + 8 * aiLevelLabelHBox.getSpacing()); trueWidthYDouble[i] = ((Label) aiLevelLabelHBox.getChildren().get(i)).getWidth(); } SplineInterpolator splineInterpolator = new SplineInterpolator(); PolynomialSplineFunction translateFunction = splineInterpolator.interpolate(xDouble, translationYDouble); PolynomialSplineFunction widthFunction = splineInterpolator.interpolate(xDouble, widthYDouble); PolynomialSplineFunction trueWidthFunction = splineInterpolator.interpolate(xDouble, trueWidthYDouble); KeyValue hBoxLayoutXKeyValue1 = new KeyValue(aiLevelLabelHBox.layoutXProperty(), aiLevelLabelHBox.getLayoutX(), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleWidthKeyValue1 = new KeyValue( aiLevelLabelClipRectangle.widthProperty(), aiLevelLabelClipRectangle.getWidth(), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleXKeyValue1 = new KeyValue(aiLevelLabelClipRectangle.xProperty(), aiLevelLabelClipRectangle.getX(), Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineStartXKeyValue1 = new KeyValue(aiLevelCenterLine.startXProperty(), aiLevelCenterLine.getStartX(), Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineEndXKeyValue1 = new KeyValue(aiLevelCenterLine.endXProperty(), aiLevelCenterLine.getEndX(), Interpolator.EASE_BOTH); KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(0), hBoxLayoutXKeyValue1, aiLevelLabelClipRectangleWidthKeyValue1, aiLevelLabelClipRectangleXKeyValue1, aiLevelCenterLineStartXKeyValue1, aiLevelCenterLineEndXKeyValue1); double interpolatedLabelWidth = trueWidthFunction.value(sliderPos); KeyValue hBoxLayoutXKeyValue2 = new KeyValue(aiLevelLabelHBox.layoutXProperty(), translateFunction.value(sliderPos), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleWidthKeyValue2 = new KeyValue( aiLevelLabelClipRectangle.widthProperty(), widthFunction.value(sliderPos), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleXKeyValue2 = new KeyValue(aiLevelLabelClipRectangle.xProperty(), aiLevelLabelPane.getWidth() / 2 - widthFunction.value(sliderPos) / 2, Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineStartXKeyValue2 = new KeyValue(aiLevelCenterLine.startXProperty(), (aiLevelLabelPane.getWidth() - interpolatedLabelWidth) / 2, Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineEndXKeyValue2 = new KeyValue(aiLevelCenterLine.endXProperty(), (aiLevelLabelPane.getWidth() + interpolatedLabelWidth) / 2, Interpolator.EASE_BOTH); KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(animationSpeed * 0.9), hBoxLayoutXKeyValue2, aiLevelLabelClipRectangleWidthKeyValue2, aiLevelLabelClipRectangleXKeyValue2, aiLevelCenterLineStartXKeyValue2, aiLevelCenterLineEndXKeyValue2); Timeline timeline = new Timeline(keyFrame1, keyFrame2); timeline.play(); } }
From source file:org.apache.solr.client.solrj.io.eval.SplineEvaluator.java
@Override public Object doWork(Object... objects) throws IOException { Object first = objects[0];/* www . j a v a 2 s . c o m*/ 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 w ww. ja v a 2 s.c o 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: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); }//from w w w .j av a2 s . co m return image; }