@Override public PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(final double[] xValues, final double[] yValues) { final PiecewiseCubicHermiteSplineInterpolatorWithSensitivity interp = new PiecewiseCubicHermiteSplineInterpolatorWithSensitivity(); return interp.interpolateWithSensitivity(xValues, yValues); }
double[] temp = endpointSlope(h[0], h[1], delta[0], delta[1], false); d[0] = temp[0]; for (int i = 0; i < 3; i++) { jac[0][i] = temp[i + 1]; temp = endpointSlope(h[n - 2], h[n - 3], delta[n - 2], delta[n - 3], true); d[n - 1] = temp[0]; for (int i = 1; i < 4; i++) {
public void interpolationTest() { final int nExamples = Y.length; final int n = XX.length; for (int example = 0; example < nExamples; example++) { PiecewisePolynomialResult pp = PCHIP_S.interpolateWithSensitivity(X, Y[example]); for (int i = 0; i < n; i++) { final double y = PPVAL_S.evaluate(pp, XX[i]).get(0); assertEquals("example: " + example + ", index:" + i, YY[example][i], y, 1e-14); } } }
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()); }
DoubleMatrix[] temp = solve(xValuesSrt, yValuesSrt);
public void baseInterpolationTest() { int nExamples = Y.length; int n = XX.length; for (int example = 0; example < nExamples; example++) { PiecewisePolynomialResult pp = BASE.interpolate(X, Y[example]); BoundCurveInterpolator bound = PCHIP.bind( DoubleArray.ofUnsafe(X), DoubleArray.ofUnsafe(Y[example]), INTERPOLATOR, INTERPOLATOR); for (int i = 0; i < n; i++) { double computedValue = bound.interpolate(XX[i]); double expectedValue = PPVAL.evaluate(pp, XX[i]).get(0); assertEquals(computedValue, expectedValue, 1e-14); double computedDerivative = bound.firstDerivative(XX[i]); double expectedDerivative = PPVAL.differentiate(pp, XX[i]).get(0); assertEquals(computedDerivative, expectedDerivative, 1e-14); } } }
res[1] = DoubleMatrix.copyOf(coeffSense); } else { SlopeFinderResults temp = slopeFinder(h, delta, yValues); DoubleArray d = temp.getSlopes(); double[][] dDy = temp.getSlopeJacobian().toArray();
public void sensitivityTwoNodeTest() { int n = XX.length; double[] xValues = new double[] {-0.2, 3.63}; double[] yValues = new double[] {4.67, -1.22}; PiecewisePolynomialResultsWithSensitivity pp = PCHIP_S.interpolateWithSensitivity(xValues, yValues); DoubleArray[] fdRes = fdSenseCal(xValues, yValues, XX); for (int i = 0; i < n; i++) { DoubleArray res = PPVAL_S.nodeSensitivity(pp, XX[i]); for (int j = 0; j < 2; j++) { assertEquals(fdRes[j].get(i), res.get(j), 1e-4); } } }
public void sensitivityTest() { final int nExamples = Y.length; final int n = XX.length; final int nData = X.length; for (int example = 0; example < nExamples; example++) { PiecewisePolynomialResultsWithSensitivity pp = PCHIP_S.interpolateWithSensitivity(X, Y[example]); DoubleArray[] fdRes = fdSenseCal(X, Y[example], XX); for (int i = 0; i < n; i++) { DoubleArray res = PPVAL_S.nodeSensitivity(pp, XX[i]); for (int j = 0; j < nData; j++) { assertEquals("example: " + example + ", sample: " + i + ", node: " + j, fdRes[j].get(i), res.get(j), 1e-4); } } } }
public void sensitivityTest() { int nExamples = Y.length; int n = XX.length; int nData = X.length; for (int example = 0; example < nExamples; example++) { PiecewisePolynomialResultsWithSensitivity pp = BASE.interpolateWithSensitivity(X, Y[example]); BoundCurveInterpolator bound = PCHIP.bind( DoubleArray.ofUnsafe(X), DoubleArray.ofUnsafe(Y[example]), INTERPOLATOR, INTERPOLATOR); for (int i = 0; i < n; i++) { DoubleArray computed = bound.parameterSensitivity(XX[i]); DoubleArray expected = PPVAL.nodeSensitivity(pp, XX[i]); for (int j = 0; j < nData; j++) { assertTrue(DoubleArrayMath.fuzzyEquals(computed.toArray(), expected.toArray(), TOL)); } } } }