@Override public final double interpolate(double xValue) { if (xValue < firstXValue) { return extrapolatorLeft.leftExtrapolate(xValue); } else if (xValue > lastXValue) { return extrapolatorRight.rightExtrapolate(xValue); } else if (xValue == lastXValue) { return lastYValue; } return doInterpolate(xValue); }
@Override public final double firstDerivative(double xValue) { if (xValue < firstXValue) { return extrapolatorLeft.leftExtrapolateFirstDerivative(xValue); } else if (xValue > lastXValue) { return extrapolatorRight.rightExtrapolateFirstDerivative(xValue); } return doFirstDerivative(xValue); }
@Override public final DoubleArray parameterSensitivity(double xValue) { if (xValue < firstXValue) { return extrapolatorLeft.leftExtrapolateParameterSensitivity(xValue); } else if (xValue > lastXValue) { return extrapolatorRight.rightExtrapolateParameterSensitivity(xValue); } return doParameterSensitivity(xValue); }
public void test_firstDerivative() { BoundCurveInterpolator bci = DQ_INTERPOLATOR.bind(X_DATA, Y_DATA, FLAT_EXTRAPOLATOR, FLAT_EXTRAPOLATOR); double eps = 1e-8; double lo = bci.interpolate(0.2); double hi = bci.interpolate(0.2 + eps); double deriv = (hi - lo) / eps; assertEquals(bci.firstDerivative(0.2), deriv, 1e-6); }
@Override public double interpolate(double x, double y) { // use each y-interpolator to find the z-value for each unique x DoubleArray zValuesEffective = DoubleArray.of(yInterpolators.length, i -> yInterpolators[i].interpolate(y)); // interpolate unique x-values against derived z-values return xInterpolator.bind(xValuesUnique, zValuesEffective, xExtrapolatorLeft, xExtrapolatorRight).interpolate(x); }
@Override public Double apply(Double x) { return 0.5 * (bind.interpolate(x + EPS) * (x + EPS) - bind.interpolate(x - EPS) * (x - EPS)) / EPS; } };
@Override protected double doInterpolate(double xValue) { // x-value is less than the x-value of the last node (lowerIndex < intervalCount) int lowerIndex = lowerBoundIndex(xValue, xValues); double x1 = xValues[lowerIndex]; double y1 = yValues[lowerIndex]; return y1 + (xValue - x1) * gradients[lowerIndex]; }
@Override public BoundCurveInterpolator bind( BoundCurveExtrapolator extrapolatorLeft, BoundCurveExtrapolator extrapolatorRight) { return new Bound(this, extrapolatorLeft, extrapolatorRight); } }
@Override public BoundCurveInterpolator bind( BoundCurveExtrapolator extrapolatorLeft, BoundCurveExtrapolator extrapolatorRight) { return new Bound(this, extrapolatorLeft, extrapolatorRight); } }
@Override public BoundCurveInterpolator bind( BoundCurveExtrapolator extrapolatorLeft, BoundCurveExtrapolator extrapolatorRight) { return new Bound(this, extrapolatorLeft, extrapolatorRight); } }
@Override public BoundCurveInterpolator bind( BoundCurveExtrapolator extrapolatorLeft, BoundCurveExtrapolator extrapolatorRight) { return new Bound(this, extrapolatorLeft, extrapolatorRight); }
@Override public BoundCurveInterpolator bind( BoundCurveExtrapolator extrapolatorLeft, BoundCurveExtrapolator extrapolatorRight) { return new Bound(this, extrapolatorLeft, extrapolatorRight); } }
@Override public BoundCurveInterpolator bind( BoundCurveExtrapolator extrapolatorLeft, BoundCurveExtrapolator extrapolatorRight) { return new Bound(this, extrapolatorLeft, extrapolatorRight); } }
@Override public BoundCurveInterpolator bind(BoundCurveExtrapolator extrapolatorLeft, BoundCurveExtrapolator extrapolatorRight) { return new Bound(this, extrapolatorLeft, extrapolatorRight); } }
@Override public BoundCurveInterpolator bind( BoundCurveExtrapolator extrapolatorLeft, BoundCurveExtrapolator extrapolatorRight) { return new Bound(this, extrapolatorLeft, extrapolatorRight); } }
public void test_firstDerivative() { BoundCurveInterpolator bci = NATURAL_CUBLIC_SPLINE_INTERPOLATOR.bind(X_DATA, Y_DATA, FLAT_EXTRAPOLATOR, FLAT_EXTRAPOLATOR); double eps = 1e-8; double lo = bci.interpolate(0.2); double hi = bci.interpolate(0.2 + eps); double deriv = (hi - lo) / eps; assertEquals(bci.firstDerivative(0.2), deriv, 1e-6); }
@Override protected double doInterpolateFromExtrapolator(double xValue) { int lowerIndex = lowerBoundIndex(xValue, xValues); // check if x-value is at the last node if (lowerIndex == intervalCount) { // if value is at last node, calculate the gradient from the previous interval lowerIndex--; } double x1 = xValues[lowerIndex]; double y1 = yValues[lowerIndex]; return y1 + (xValue - x1) * gradients[lowerIndex]; }
public void test_lastNode() { BoundCurveInterpolator bci = LNDFC_INTERPOLATOR.bind(X_DATA, Y_DATA, FLAT_EXTRAPOLATOR, FLAT_EXTRAPOLATOR); assertEquals(bci.interpolate(5.0), 2.0, TOL); assertEquals(bci.firstDerivative(5.0), bci.firstDerivative(4.99999999), 1e-6); }
@Override protected double doFirstDerivative(double xValue) { int lowerIndex = lowerBoundIndex(xValue, xValues); // check if x-value is at the last node if (lowerIndex == intervalCount) { // if value is at last node, calculate the gradient from the previous interval lowerIndex--; } return gradients[lowerIndex]; }
public void test_firstNode() { BoundCurveInterpolator bci = LL_INTERPOLATOR.bind(X_DATA, Y_DATA, FLAT_EXTRAPOLATOR, FLAT_EXTRAPOLATOR); assertEquals(bci.interpolate(0.0), 3.0, TOL); assertEquals(bci.firstDerivative(0.0), bci.firstDerivative(0.00000001), 1e-6); }