@Override public double leftExtrapolateFirstDerivative(double xValue) { return interpolator.doFirstDerivative(xValue); }
/** * Method for {@code InterpolatorCurveExtrapolator} to calculate the interpolated value. * <p> * This is separated from {@link #doInterpolate(double)} to allow the check for x-values * beyond the last node to be treated separately. * * @param xValue the x-value * @return the interpolated y-value */ protected double doInterpolateFromExtrapolator(double xValue) { // calling this method may fail on right extrapolation depending on the implementation // if it fails, then this method should be overridden to fix the problem return doInterpolate(xValue); }
@Override public DoubleArray rightExtrapolateParameterSensitivity(double xValue) { return interpolator.doParameterSensitivity(xValue); } }
for (int j = 0; j < nKeys; ++j) { assertEquals(boundInterp.interpolate(keys[j]), baseInterp.doInterpolate(keys[j]), TOL); assertEquals(boundInterp.firstDerivative(keys[j]), baseInterp.doFirstDerivative(keys[j]), TOL); assertTrue(boundInterp.parameterSensitivity(keys[j]).equalWithTolerance(baseInterp.doParameterSensitivity(keys[j]), TOL));
return lowerBoundIndex(0d, xValues);
@Override public double rightExtrapolate(double xValue) { return interpolator.doInterpolateFromExtrapolator(xValue); }
public void sameIntervalsTest() { DoubleArray xValues = DoubleArray.of(-1., 0., 1., 2., 3., 4., 5., 6., 7., 8.); DoubleArray[] yValues = new DoubleArray[] { DoubleArray.of(1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001), DoubleArray.of(11., 11., 8., 5., 1.001, 1.001, 5., 8., 11., 11.), DoubleArray.of(1.001, 1.001, 5., 8., 9., 9., 11., 12., 18., 18.) }; int nKeys = 100; double[] keys = new double[nKeys]; double interval = 0.061; for (int i = 0; i < nKeys; ++i) { keys[i] = xValues.get(0) + interval * i; } CurveExtrapolator extrap = InterpolatorCurveExtrapolator.INSTANCE; int yDim = yValues.length; for (int k = 0; k < yDim; ++k) { BoundCurveInterpolator boundInterp = CurveInterpolators.SQUARE_LINEAR.bind(xValues, yValues[k], extrap, extrap); AbstractBoundCurveInterpolator baseInterp = (AbstractBoundCurveInterpolator) boundInterp; for (int j = 0; j < nKeys; ++j) { // value assertEquals(boundInterp.interpolate(keys[j]), baseInterp.doInterpolate(keys[j]), TOL); // derivative assertEquals(boundInterp.firstDerivative(keys[j]), baseInterp.doFirstDerivative(keys[j]), TOL); // sensitivity assertTrue(boundInterp.parameterSensitivity(keys[j]).equalWithTolerance(baseInterp.doParameterSensitivity(keys[j]), TOL)); } } }
public void test_lowerBound() { // bad input, but still produces good output assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(0.0d, new double[] {1, 2, 3}), 0); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(0.5d, new double[] {1, 2, 3}), 0); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(0.9999d, new double[] {1, 2, 3}), 0); // good input assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(1.0d, new double[] {1, 2, 3}), 0); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(1.0001d, new double[] {1, 2, 3}), 0); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(1.9999d, new double[] {1, 2, 3}), 0); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(2.0d, new double[] {1, 2, 3}), 1); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(2.0001d, new double[] {1, 2, 3}), 1); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(2.9999d, new double[] {1, 2, 3}), 1); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(3.0d, new double[] {1, 2, 3}), 2); // bad input, but still produces good output assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(3.0001d, new double[] {1, 2, 3}), 2); // check zero assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(-1.0d, new double[] {-1, 0, 1}), 0); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(-0.9999d, new double[] {-1, 0, 1}), 0); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(-0.0001d, new double[] {-1, 0, 1}), 0); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(-0.0d, new double[] {-1, 0, 1}), 1); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(0.0d, new double[] {-1, 0, 1}), 1); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(1.0d, new double[] {-1, 0, 1}), 2); assertEquals(AbstractBoundCurveInterpolator.lowerBoundIndex(1.5d, new double[] {-1, 0, 1}), 2); }
@Override public double leftExtrapolate(double xValue) { return interpolator.doInterpolateFromExtrapolator(xValue); }
@Override public DoubleArray leftExtrapolateParameterSensitivity(double xValue) { return interpolator.doParameterSensitivity(xValue); }
@Override public double rightExtrapolateFirstDerivative(double xValue) { return interpolator.doFirstDerivative(xValue); }
@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 DoubleArray parameterSensitivity(double xValue) { if (xValue < firstXValue) { return extrapolatorLeft.leftExtrapolateParameterSensitivity(xValue); } else if (xValue > lastXValue) { return extrapolatorRight.rightExtrapolateParameterSensitivity(xValue); } return doParameterSensitivity(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); }