/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void wrongDatalengthTest() { double[] xValues = new double[] {1., 2., 3. }; double[] yValues = new double[] {1., 2., 3., 4. }; INTERP.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(); LinearInterpolator underlying = new LinearInterpolator(); this.poly = underlying.interpolate(xValues.toArray(), getProduct(this.xValues, this.yValues)); this.polySens = Suppliers.memoize( () -> underlying.interpolateWithSensitivity(xValues.toArray(), getProduct(this.xValues, this.yValues))); }
final int keyDim = xKey.length; LinearInterpolator interp = new LinearInterpolator(); double value = interp.interpolate(xValues, yValues[0], xKey[0][0]); DoubleArray valuesVec1 = interp.interpolate(xValues, yValues, xKey[0][0]); for (int i = 0; i < yDim; ++i) { final double ref = resultValuesExpected[0][i][0] == 0. ? 1. : Math.abs(resultValuesExpected[0][i][0]); DoubleArray valuesVec2 = interp.interpolate(xValues, yValues[0], xKey[0]); for (int k = 0; k < keyLength; ++k) { final double ref = resultValuesExpected[k][0][0] == 0. ? 1. : Math.abs(resultValuesExpected[k][0][0]); DoubleMatrix valuesMat1 = interp.interpolate(xValues, yValues[0], xKey); for (int j = 0; j < keyDim; ++j) { for (int k = 0; k < keyLength; ++k) { DoubleMatrix valuesMat2 = interp.interpolate(xValues, yValues, xKey[0]); for (int i = 0; i < yDim; ++i) { for (int k = 0; k < keyLength; ++k) { DoubleMatrix[] valuesMat3 = interp.interpolate(xValues, yValues, xKey); for (int i = 0; i < yDim; ++i) { for (int j = 0; j < keyDim; ++j) {
private void testSensitivity(double[] xValues, double[] yValues, double[] keys, double delta) { PiecewisePolynomialWithSensitivityFunction1D func = new PiecewisePolynomialWithSensitivityFunction1D(); PiecewisePolynomialResultsWithSensitivity resultSensi = INTERP.interpolateWithSensitivity(xValues, yValues); DoubleArray[] computedArray = func.nodeSensitivity(resultSensi, keys); for (int i = 0; i < keys.length; ++i) { double base = func.evaluate(resultSensi, keys[i]).get(0); DoubleArray computed = func.nodeSensitivity(resultSensi, keys[i]); assertEquals(computed, computedArray[i]); for (int j = 0; j < yValues.length; ++j) { double[] yValuesBump = Arrays.copyOf(yValues, yValues.length); yValuesBump[j] += delta; PiecewisePolynomialResult resultBump = INTERP.interpolate(xValues, yValuesBump); double expected = (func.evaluate(resultBump, keys[i]).get(0) - base) / delta; assertEquals(computed.get(j), expected, delta); } } } }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void notReconnectedTest() { double[] xValues = new double[] {1., 2.000000000001, 2.000000000002, 4. }; double[] yValues = new double[] {2., 4.e10, 3.e-5, 5.e11 }; PiecewisePolynomialInterpolator interpPos = new LinearInterpolator(); interpPos.interpolate(xValues, yValues); }
DoubleArrayMath.sortPairs(xValuesSrt, yValuesSrt); coefMatrix[i] = solve(xValuesSrt, yValuesSrt);
DoubleArrayMath.sortPairs(xValuesSrt, yValuesSrt); DoubleMatrix[] res = solveSensitivity(xValuesSrt, yValuesSrt); DoubleMatrix coefMatrix = res[nDataPts - 1]; DoubleMatrix[] coefSenseMatrix = Arrays.copyOf(res, nDataPts - 1);
/** * */ public void recov2ptsMultiTest() { final double[] xValues = new double[] {1., 2. }; final double[][] yValues = new double[][] { {6., 1. }, {2., 5. } }; final int nIntervalsExp = 1; final int orderExp = 2; final int dimExp = 2; final double[][] coefsMatExp = new double[][] { {-5., 6. }, {3., 2. } }; LinearInterpolator interpMatrix = new LinearInterpolator(); PiecewisePolynomialResult result = interpMatrix.interpolate(xValues, yValues); assertEquals(result.getDimensions(), dimExp); assertEquals(result.getNumberOfIntervals(), nIntervalsExp); assertEquals(result.getDimensions(), dimExp); for (int i = 0; i < nIntervalsExp * dimExp; ++i) { for (int j = 0; j < orderExp; ++j) { final double ref = coefsMatExp[i][j] == 0. ? 1. : Math.abs(coefsMatExp[i][j]); assertEquals(result.getCoefMatrix().get(i, j), coefsMatExp[i][j], ref * EPS); } } for (int j = 0; j < nIntervalsExp + 1; ++j) { assertEquals(result.getKnots().get(j), xValues[j]); } }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void notReconnectedMultiTest() { double[] xValues = new double[] {1., 2.000000000001, 2.000000000002, 4. }; double[][] yValues = new double[][] {{2., 4.e10, 3.e-5, 5.e11 } }; PiecewisePolynomialInterpolator interpPos = new LinearInterpolator(); interpPos.interpolate(xValues, yValues); }
DoubleArrayMath.sortPairs(xValuesSrt, yValuesSrt); DoubleMatrix coefMatrix = solve(xValuesSrt, yValuesSrt);
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void NullKeyMatrixTest() { double[] xValues = new double[] {1., 2., 3. }; double[] yValues = new double[] {1., 3., 4. }; double[][] xKey = new double[3][3]; xKey = null; INTERP.interpolate(xValues, yValues, xKey); }
/** * */ public void recov4ptsMultiTest() { final double[] xValues = new double[] {1., 2., 3., 4 }; final double[][] yValues = new double[][] { {6., 1., 8., -2. }, {1., 1. / 3., 2. / 11., 1. / 7. } }; final int nIntervalsExp = 3; final int orderExp = 2; final int dimExp = 2; final double[][] coefsMatExp = new double[][] { {-5., 6. }, {-2. / 3., 1. }, {7., 1. }, {-5. / 33., 1. / 3. }, {-10., 8. }, {-3. / 77., 2. / 11. } }; LinearInterpolator interpMatrix = new LinearInterpolator(); PiecewisePolynomialResult result = interpMatrix.interpolate(xValues, yValues); assertEquals(result.getDimensions(), dimExp); assertEquals(result.getNumberOfIntervals(), nIntervalsExp); assertEquals(result.getDimensions(), dimExp); for (int i = 0; i < nIntervalsExp * dimExp; ++i) { for (int j = 0; j < orderExp; ++j) { final double ref = coefsMatExp[i][j] == 0. ? 1. : Math.abs(coefsMatExp[i][j]); assertEquals(result.getCoefMatrix().get(i, j), coefsMatExp[i][j], ref * EPS); } } for (int j = 0; j < nIntervalsExp + 1; ++j) { assertEquals(result.getKnots().get(j), xValues[j]); } }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void lowDegreeMultiTest() { final double[] xValues = new double[] {1., 2., 3. }; final double[][] yValues = new double[][] { {0., 0.1, 0.05 }, {0., 0.1, 1.05 } }; PiecewisePolynomialInterpolator interp = new LinearInterpolator(); PiecewisePolynomialInterpolator interpPos = new NonnegativityPreservingCubicSplineInterpolator(interp); interpPos.interpolate(xValues, yValues); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void NaNxValuesTest() { double[] xValues = new double[] {1., 2., Double.NaN, 4. }; double[] yValues = new double[] {1., 2., 3., 4. }; INTERP.interpolate(xValues, yValues); }
/** * */ public void recov4ptsTest() { double[] xValues = new double[] {1., 2., 4., 7.}; double[] yValues = new double[] {6., 1., 8., -2.}; int nIntervalsExp = 3; int orderExp = 2; int dimExp = 1; double[][] coefsMatExp = new double[][] {{-5., 6.}, {7. / 2., 1.}, {-10. / 3., 8.}}; LinearInterpolator interpMatrix = new LinearInterpolator(); PiecewisePolynomialResult result = interpMatrix.interpolate(xValues, yValues); assertEquals(result.getDimensions(), dimExp); assertEquals(result.getNumberOfIntervals(), nIntervalsExp); assertEquals(result.getDimensions(), dimExp); for (int i = 0; i < nIntervalsExp; ++i) { for (int j = 0; j < orderExp; ++j) { double ref = coefsMatExp[i][j] == 0. ? 1. : Math.abs(coefsMatExp[i][j]); assertEquals(result.getCoefMatrix().get(i, j), coefsMatExp[i][j], ref * EPS); } } for (int j = 0; j < nIntervalsExp + 1; ++j) { assertEquals(result.getKnots().get(j), xValues[j]); } // sensitivity double delta = 1.0e-6; double[] keys = new double[] {-1.5, 2.43, 4.0, 7.0, 12.7}; testSensitivity(xValues, yValues, keys, delta); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void lowDegreeMultiTest() { final double[] xValues = new double[] {1., 2., 3. }; final double[][] yValues = new double[][] { {0., 0.1, 0.05 }, {0., 0.1, 1.05 } }; PiecewisePolynomialInterpolator interp = new LinearInterpolator(); PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingCubicSplineInterpolator(interp); interpPos.interpolate(xValues, yValues); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void InfyValuesTest() { double[] xValues = new double[] {1., 2., 3., 4. }; double[] yValues = new double[] {1., 2., 3., INF }; INTERP.interpolate(xValues, yValues); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void coincideXvaluesTest() { double[] xValues = new double[] {1., 2., 3., 3. }; double[] yValues = new double[] {1., 2., 3., 4. }; INTERP.interpolate(xValues, yValues); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void NullKeyTest() { double[] xValues = new double[] {1., 2., 3. }; double[] yValues = new double[] {1., 3., 4. }; double[] xKey = new double[3]; xKey = null; INTERP.interpolate(xValues, yValues, xKey); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void NullXvaluesTest() { double[] xValues = new double[4]; double[] yValues = new double[] {1., 2., 3., 4. }; xValues = null; INTERP.interpolate(xValues, yValues); }