/** * */ @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); }
/** * */ @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); }
/** * */ @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 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); }
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))); }
/** * */ 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]); } }
/** * */ 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]); } }
/** * */ 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); }
final int keyDim = xKey.length; LinearInterpolator interp = new LinearInterpolator();