Bound(DoubleArray xValues, DoubleArray yValues) { super(xValues, yValues); this.xValues = xValues.toArrayUnsafe(); this.yValues = yValues.toArrayUnsafe(); PiecewisePolynomialInterpolator underlying = new NaturalSplineInterpolator(); this.poly = underlying.interpolate(xValues.toArray(), yValues.toArray()); this.polySens = Suppliers.memoize(() -> underlying.interpolateWithSensitivity(xValues.toArray(), yValues.toArray())); }
/** * @param coefs {a_n,a_{n-1},...} of f(x) = a_n x^{n} + a_{n-1} x^{n-1} + .... * @param x the x * @param leftknot the knot specifying underlying interpolation function * @return the value of the underlying interpolation function at the value of x */ protected double getValue(DoubleArray coefs, double x, double leftknot) { // needs to delegate as method is protected return getValue(coefs.toArrayUnsafe(), x, leftknot); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void coincideDataMultiTest() { final double[] xValues = new double[] {1., 2., 2. }; final double[][] yValues = new double[][] { {0., 0.1, 0.05 }, {0., 0.1, 1.05 } }; PiecewisePolynomialInterpolator interpPos = new ConstrainedCubicSplineInterpolator(); interpPos.interpolate(xValues, yValues); }
@Override public PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(double[] xValues, double[] yValues) { ArgChecker.notNull(xValues, "xValues"); ArgChecker.notNull(yValues, "yValues"); ArgChecker.isTrue(xValues.length == yValues.length, "xValues length = yValues length"); PiecewisePolynomialResultsWithSensitivity result; if (_isClamped) { double[][] xyValuesAll = getDataTotal(xValues, yValues); result = _baseMethod.interpolateWithSensitivity(xyValuesAll[0], xyValuesAll[1]); } else { double[] xyValues = getProduct(xValues, yValues); result = _baseMethod.interpolateWithSensitivity(xValues, xyValues); } return (PiecewisePolynomialResultsWithSensitivity) extrapolateByLinearFunction(result, xValues); }
ArgChecker.isFalse(Double.isInfinite(xKey), "xKey containing Infinity"); final PiecewisePolynomialResult result = this.interpolate(xValues, yValues); final DoubleArray knots = result.getKnots(); final int nKnots = knots.size(); res = getValue(coefs, xKey, knots.get(indicator)); ArgChecker.isFalse(Double.isInfinite(res), "Too large input"); ArgChecker.isFalse(Double.isNaN(res), "Too large input");
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void infYdataMultiTest() { double[] xValues = new double[] {1., 2., 3., 4. }; double[][] yValues = new double[][] { {0.1, 0.05, 0.2, 1. }, {0.1, 0.05, 0.2, INF } }; PiecewisePolynomialInterpolator interpPos = new ConstrainedCubicSplineInterpolator(); interpPos.interpolate(xValues, yValues); }
@Override public PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(double[] xValues, double[] yValues) { ArgChecker.notNull(xValues, "xValues"); ArgChecker.notNull(yValues, "yValues"); ArgChecker.isTrue(xValues.length == yValues.length, "xValues length = yValues length"); double[][] xyValuesAll = getDataTotal(xValues, yValues); return _baseMethod.interpolateWithSensitivity(xyValuesAll[0], xyValuesAll[1]); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void nanXdataMultiTest() { double[] xValues = new double[] {1., 2., 3., Double.NaN }; double[][] yValues = new double[][] { {0., 0.1, 0.05, 0.2 }, {0., 0.1, 0.05, 0.2 } }; PiecewisePolynomialInterpolator interpPos = new ConstrainedCubicSplineInterpolator(); interpPos.interpolate(xValues, yValues); }
Bound(DoubleArray xValues, DoubleArray yValues) { super(xValues, yValues); this.xValues = xValues.toArrayUnsafe(); this.yValues = yValues.toArrayUnsafe(); this.logYValues = getYLogValues(this.yValues); PiecewisePolynomialInterpolator underlying = new MonotonicityPreservingCubicSplineInterpolator(new LogNaturalSplineHelper()); this.poly = underlying.interpolate(xValues.toArray(), logYValues); this.polySens = Suppliers.memoize(() -> underlying.interpolateWithSensitivity(xValues.toArray(), logYValues)); }
public void testInterpolateWithSensitivity() { for (PiecewisePolynomialInterpolator baseInterp : BASE_INTERP) { ClampedPiecewisePolynomialInterpolator interp = new ClampedPiecewisePolynomialInterpolator(baseInterp, X_CLAMPED, Y_CLAMPED); PiecewisePolynomialResultsWithSensitivity computed = interp.interpolateWithSensitivity(X_VALUES, Y_VALUES); PiecewisePolynomialResultsWithSensitivity expected = baseInterp.interpolateWithSensitivity(X_VALUES_TOTAL, Y_VALUES_TOTAL); assertEquals(computed, expected); } }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void coincideDataTest() { final double[] xValues = new double[] {1., 1., 3. }; final double[] yValues = new double[] {0., 0.1, 0.05 }; PiecewisePolynomialInterpolator interpPos = new SemiLocalCubicSplineInterpolator(); interpPos.interpolate(xValues, yValues); }
Bound(DoubleArray xValues, DoubleArray yValues) { super(xValues, yValues); this.xValues = xValues.toArrayUnsafe(); this.yValues = yValues.toArrayUnsafe(); PiecewisePolynomialInterpolator underlying = new NonnegativityPreservingCubicSplineInterpolator(new NaturalSplineInterpolator()); this.poly = underlying.interpolate(xValues.toArray(), yValues.toArray()); this.polySens = Suppliers.memoize(() -> underlying.interpolateWithSensitivity(xValues.toArray(), yValues.toArray())); }
BoundCurveInterpolator bound = INTERP.bind(xValues, yValues); PiecewisePolynomialResultsWithSensitivity ppRes = BASE_INTERP.interpolateWithSensitivity(xValues.toArray(), pValues.toArray()); Function<Double, Double> funcDeriv = x -> bound.interpolate(x); for (int i = 0; i < nKeys; ++i) {
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void coincideDataMultiTest() { final double[] xValues = new double[] {1., 2., 2. }; final double[][] yValues = new double[][] { {0., 0.1, 0.05 }, {0., 0.1, 1.05 } }; PiecewisePolynomialInterpolator interpPos = new SemiLocalCubicSplineInterpolator(); interpPos.interpolate(xValues, yValues); }
Bound(DoubleArray xValues, DoubleArray yValues) { super(xValues, yValues); this.xValues = xValues.toArrayUnsafe(); this.yValues = yValues.toArrayUnsafe(); PiecewisePolynomialInterpolator underlying = new PiecewiseCubicHermiteSplineInterpolatorWithSensitivity(); PiecewisePolynomialResult poly = underlying.interpolate(xValues.toArray(), yValues.toArray()); this.knots = poly.getKnots(); this.coefMatrix = poly.getCoefMatrix(); this.coefMatrixSensi = Suppliers.memoize( () -> underlying.interpolateWithSensitivity(xValues.toArray(), yValues.toArray()).getCoefficientSensitivityAll()); }
BoundCurveInterpolator bound = INTERP.bind(xValues, yValues); PiecewisePolynomialResultsWithSensitivity ppRes = BASE_INTERP.interpolateWithSensitivity(xValues.toArray(), pValues.toArray()); Function<Double, Double> funcDeriv = x -> bound.interpolate(x); for (int i = 0; i < nKeys; ++i) {
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void infXdataMultiTest() { double[] xValues = new double[] {1., 2., 3., INF }; double[][] yValues = new double[][] { {0., 0.1, 0.05, 0.2 }, {0., 0.1, 0.05, 0.2 } }; PiecewisePolynomialInterpolator interpPos = new SemiLocalCubicSplineInterpolator(); interpPos.interpolate(xValues, yValues); }
Bound(DoubleArray xValues, DoubleArray yValues) { super(xValues, yValues); ArgChecker.isTrue(xValues.get(0) > 0d || xValues.get(xValues.size() - 1) < 0d, "xValues must have the same sign"); this.xValues = xValues.toArrayUnsafe(); this.yValues = yValues.toArrayUnsafe(); PiecewisePolynomialInterpolator underlying = new MonotonicityPreservingCubicSplineInterpolator(new LogNaturalSplineHelper()); this.poly = underlying.interpolate(xValues.toArray(), getProduct(this.xValues, this.yValues)); this.polySens = Suppliers.memoize( () -> underlying.interpolateWithSensitivity(xValues.toArray(), getProduct(this.xValues, this.yValues))); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void infYdataMultiTest() { double[] xValues = new double[] {1., 2., 3., 4. }; double[][] yValues = new double[][] { {0.1, 0.05, 0.2, 1. }, {0.1, 0.05, 0.2, INF } }; PiecewisePolynomialInterpolator interpPos = new SemiLocalCubicSplineInterpolator(); interpPos.interpolate(xValues, yValues); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void notReconnectedMultiTest() { double[] xValues = new double[] {1., 2., 4., 2.0000000001 }; double[][] yValues = new double[][] {{2., 3., 500000000., 400. } }; PiecewisePolynomialInterpolator interpPos = new SemiLocalCubicSplineInterpolator(); interpPos.interpolate(xValues, yValues); }