@Test public void test() { assertEquals( Math.log(INTERPOLATOR.interpolate(MODEL, 3.4)), LINEAR.interpolate(TRANSFORMED_MODEL, 3.4), EPS); }
@Override public Double interpolate( final Map<Double, Interpolator1DDataBundle> dataBundle, final DoublesPair value) { ArgumentChecker.notNull(value, "value"); ArgumentChecker.notNull(dataBundle, "data bundle"); final Map<Double, Double> xData = new HashMap<>(); for (final Map.Entry<Double, Interpolator1DDataBundle> entry : dataBundle.entrySet()) { xData.put(entry.getKey(), _yInterpolator.interpolate(entry.getValue(), value.getSecond())); } return _xInterpolator.interpolate(_xInterpolator.getDataBundle(xData), value.getFirst()); }
@Test(enabled = false) public void test() { System.out.println("TransformedInterpolator1DTest"); for (int i = 0; i < 200; i++) { double x = 5.0 * i / 199.0; System.out.println( x + "\t" + INTERPOLATOR_BASE.interpolate(DATA_BUNDLE, x) + "\t" + INTERPOLATOR.interpolate(TRANS_DATA_BUNDLE, x) + "\t" + INTERPOLATOR.interpolate(DATA_BUNDLE, x)); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void samexNodesTest() { final double[] xData = new double[] {0.4, 0.7, 0.9, 0.9, 1.3, 1.8}; final double[] yData = new double[] {0.4, 0.5, 0.6, 0.7, 0.8, 1.0}; final Interpolator1DDataBundle data = INTERPOLATOR.getDataBundle(xData, yData); double y = INTERPOLATOR.interpolate(data, 1.0); assertTrue("y: " + y, !Double.isNaN(y)); }
@Test public void testInRange() { for (int i = 0; i < 200; i++) { double x = 5.0 * i / 199.0; double y = INTERPOLATOR.interpolate(TRANS_DATA_BUNDLE, x); assertTrue(y >= 0 && y <= 1); } }
@Test public void testCorrectAtNodes() { final int n = Y_DATA.length; for (int i = 0; i < n; i++) { double y = INTERPOLATOR.interpolate(TRANS_DATA_BUNDLE, X_DATA[i]); assertEquals(Y_DATA[i], y, 1e-12); } }
@Test public void montonicTest() { final boolean print = false; if (print) { System.out.println("MonotonicCubicInterpolator1DTest"); } final int n = 100; final double low = X_DATA[0]; final double range = X_DATA[X_DATA.length - 1] - X_DATA[0]; double value = INTERPOLATOR.interpolate(DATA, low); for (int i = 1; i < n; i++) { double x = low + i * range / (n - 1); double y = INTERPOLATOR.interpolate(DATA, x); assertTrue(y > value); value = y; if (print) { System.out.println(x + "\t" + y); } } }
@Override public double[] getNodeSensitivitiesForValue( final Interpolator1DDataBundle data, final Double value) { final double yStar = _base.interpolate(data, value); final double grad = _transform.inverseTransformGradient(yStar); final double[] temp = _base.getNodeSensitivitiesForValue(data, value); final int n = temp.length; for (int i = 0; i < n; i++) { temp[i] *= grad; } return temp; }
@Override public Map<DoublesPair, Double> getNodeSensitivitiesForValue( final Map<Double, Interpolator1DDataBundle> dataBundle, final DoublesPair value) { ArgumentChecker.notNull(value, "value"); ArgumentChecker.notNull(dataBundle, "data bundle"); final Map<Double, Double> xData = new HashMap<>(); final double[][] temp = new double[dataBundle.size()][]; int i = 0; for (final Map.Entry<Double, Interpolator1DDataBundle> entry : dataBundle.entrySet()) { // this is the sensitivity of the point projected onto a column of y-points to those points temp[i++] = _yInterpolator.getNodeSensitivitiesForValue(entry.getValue(), value.getSecond()); xData.put(entry.getKey(), _yInterpolator.interpolate(entry.getValue(), value.getSecond())); } // this is the sensitivity of the point to the points projected onto y columns final double[] xSense = _xInterpolator.getNodeSensitivitiesForValue( _xInterpolator.getDataBundle(xData), value.getFirst()); ArgumentChecker.isTrue( xSense.length == dataBundle.size(), "Number of x sensitivities {} must be equal to the data bundle size {}", xSense.length, dataBundle.size()); final Map<DoublesPair, Double> res = new HashMap<>(); double sense; i = 0; int j = 0; for (final Map.Entry<Double, Interpolator1DDataBundle> entry : dataBundle.entrySet()) { final double[] yValues = entry.getValue().getKeys(); for (j = 0; j < yValues.length; j++) { sense = xSense[i] * temp[i][j]; res.put(DoublesPair.of(entry.getKey().doubleValue(), yValues[j]), sense); } i++; } return res; }
@Test(expectedExceptions = IllegalArgumentException.class) public void testHighValue() { INTERPOLATOR.interpolate(MODEL, 12.); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { INTERPOLATOR.interpolate(MODEL, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDataBundle() { INTERPOLATOR.interpolate(null, 3.4); }
@Override public double firstDerivative(final Interpolator1DDataBundle data, final Double value) { return _transform.inverseTransformGradient(_base.interpolate(data, value)) * _base.firstDerivative(data, value); }
@Override public Double interpolate(final Interpolator1DDataBundle data, final Double value) { return _transform.inverseTransform(_base.interpolate(data, value)); }
@Override public Double extrapolate( Interpolator1DDataBundle data, Double value, Interpolator1D interpolator) { JodaBeanUtils.notNull(data, "data"); return interpolator.interpolate(data, value); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullValue() { INTERPOLATOR.interpolate(DATA, null); }