当前位置: 首页>>代码示例>>Java>>正文


Java BivariateFunction.value方法代码示例

本文整理汇总了Java中org.apache.commons.math3.analysis.BivariateFunction.value方法的典型用法代码示例。如果您正苦于以下问题:Java BivariateFunction.value方法的具体用法?Java BivariateFunction.value怎么用?Java BivariateFunction.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.analysis.BivariateFunction的用法示例。


在下文中一共展示了BivariateFunction.value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calculateNewValues

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
private static double[][] calculateNewValues(
	double[][] data, int interpolationLevel
) {
	final int initialRows = data.length;
	final int initialColumns = data[0].length;
	
	final BivariateGridInterpolator interpolator = new BilinearInterpolator();
	final BivariateFunction function = interpolator.interpolate(
		IntStream.range(0, initialRows).asDoubleStream().toArray(),
		IntStream.range(0, initialColumns).asDoubleStream().toArray(),
		data
	);
	
	final int newNumRows = CALCULATE_SIZE.applyAsInt(
		initialRows, interpolationLevel);
	final int newNumColumns = CALCULATE_SIZE.applyAsInt(
		initialColumns, interpolationLevel);
	
	final double[][] newValues = new double[newNumRows][newNumColumns];
	
	final double xFactor = ((double) initialRows - 1d) / ((double) newNumRows - 1d);
	final double yFactor = ((double) initialColumns - 1d) / ((double) newNumColumns - 1d);
	for (int i = 0; i < newValues.length; i++) {
		for (int j = 0; j < newValues[i].length; j++) {
			newValues[i][j] = function.value(
				(double) i * xFactor, (double) j * yFactor
			);
		}
	}
	
	return newValues;
}
 
开发者ID:sing-group,项目名称:la-images,代码行数:33,代码来源:Interpolator.java

示例2: testInterpolation1

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
     * Interpolating a plane.
     * <p>
     * z = 2 x - 3 y + 5
     */
    @Test
    public void testInterpolation1() {
        final int sz = 21;
        double[] xval = new double[sz];
        double[] yval = new double[sz];
        // Coordinate values
        final double delta = 1d / (sz - 1);
        for (int i = 0; i < sz; i++) {
            xval[i] = -1 + 15 * i * delta;
            yval[i] = -20 + 30 * i * delta;
        }

        // Function values
        BivariateFunction f = new BivariateFunction() {
                public double value(double x, double y) {
                    return 2 * x - 3 * y + 5;
                }
            };
        double[][] zval = new double[xval.length][yval.length];
        for (int i = 0; i < xval.length; i++) {
            for (int j = 0; j < yval.length; j++) {
                zval[i][j] = f.value(xval[i], yval[j]);
            }
        }

        BivariateGridInterpolator interpolator = new BicubicSplineInterpolator();
        BivariateFunction p = interpolator.interpolate(xval, yval, zval);
        double x, y;

        final RandomGenerator rng = new Well19937c(1234567L); // "tol" depends on the seed.
        final UniformRealDistribution distX
            = new UniformRealDistribution(rng, xval[0], xval[xval.length - 1]);
        final UniformRealDistribution distY
            = new UniformRealDistribution(rng, yval[0], yval[yval.length - 1]);

        final int numSamples = 50;
        final double tol = 6;
        for (int i = 0; i < numSamples; i++) {
            x = distX.sample();
            for (int j = 0; j < numSamples; j++) {
                y = distY.sample();
//                 System.out.println(x + " " + y + " " + f.value(x, y) + " " + p.value(x, y));
                Assert.assertEquals(f.value(x, y),  p.value(x, y), tol);
            }
//             System.out.println();
        }
    }
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:53,代码来源:BicubicSplineInterpolatorTest.java

示例3: testInterpolation2

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
     * Interpolating a paraboloid.
     * <p>
     * z = 2 x<sup>2</sup> - 3 y<sup>2</sup> + 4 x y - 5
     */
    @Test
    public void testInterpolation2() {
        final int sz = 21;
        double[] xval = new double[sz];
        double[] yval = new double[sz];
        // Coordinate values
        final double delta = 1d / (sz - 1);
        for (int i = 0; i < sz; i++) {
            xval[i] = -1 + 15 * i * delta;
            yval[i] = -20 + 30 * i * delta;
        }

        // Function values
        BivariateFunction f = new BivariateFunction() {
                public double value(double x, double y) {
                    return 2 * x * x - 3 * y * y + 4 * x * y - 5;
                }
            };
        double[][] zval = new double[xval.length][yval.length];
        for (int i = 0; i < xval.length; i++) {
            for (int j = 0; j < yval.length; j++) {
                zval[i][j] = f.value(xval[i], yval[j]);
            }
        }

        BivariateGridInterpolator interpolator = new BicubicSplineInterpolator();
        BivariateFunction p = interpolator.interpolate(xval, yval, zval);
        double x, y;

        final RandomGenerator rng = new Well19937c(1234567L); // "tol" depends on the seed.
        final UniformRealDistribution distX
            = new UniformRealDistribution(rng, xval[0], xval[xval.length - 1]);
        final UniformRealDistribution distY
            = new UniformRealDistribution(rng, yval[0], yval[yval.length - 1]);

        final int numSamples = 50;
        final double tol = 251;
        for (int i = 0; i < numSamples; i++) {
            x = distX.sample();
            for (int j = 0; j < numSamples; j++) {
                y = distY.sample();
//                 System.out.println(x + " " + y + " " + f.value(x, y) + " " + p.value(x, y));
                Assert.assertEquals(f.value(x, y),  p.value(x, y), tol);
            }
//             System.out.println();
        }
    }
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:53,代码来源:BicubicSplineInterpolatorTest.java

示例4: testPlane

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
 * Test for a plane.
 * <p>
 * z = 2 x - 3 y + 5
 */
@[email protected]
public void testPlane() {
    double[] xval = new double[] {3, 4, 5, 6.5};
    double[] yval = new double[] {-4, -3, -1, 2, 2.5};
    // Function values
    BivariateFunction f = new BivariateFunction() {
            public double value(double x, double y) {
                return 2 * x - 3 * y + 5;
            }
        };
    double[][] zval = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            zval[i][j] = f.value(xval[i], yval[j]);
        }
    }
    // Partial derivatives with respect to x
    double[][] dZdX = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            dZdX[i][j] = 2;
        }
    }
    // Partial derivatives with respect to y
    double[][] dZdY = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            dZdY[i][j] = -3;
        }
    }
    // Partial cross-derivatives
    double[][] dZdXdY = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            dZdXdY[i][j] = 0;
        }
    }

    BivariateFunction bcf = new BicubicSplineInterpolatingFunction(xval, yval, zval,
                                                                       dZdX, dZdY, dZdXdY);
    double x, y;
    double expected, result;

    x = 4;
    y = -3;
    expected = f.value(x, y);
    result = bcf.value(x, y);
    Assert.assertEquals("On sample point",
                        expected, result, 1e-15);

    x = 4.5;
    y = -1.5;
    expected = f.value(x, y);
    result = bcf.value(x, y);
    Assert.assertEquals("Half-way between sample points (middle of the patch)",
                        expected, result, 0.3);

    x = 3.5;
    y = -3.5;
    expected = f.value(x, y);
    result = bcf.value(x, y);
    Assert.assertEquals("Half-way between sample points (border of the patch)",
                        expected, result, 0.3);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:70,代码来源:BicubicSplineInterpolatingFunctionTest.java

示例5: testInterpolation1

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
     * Interpolating a plane.
     * <p>
     * z = 2 x - 3 y + 5
     */
    @Test
    public void testInterpolation1() {
        final int sz = 21;
        double[] xval = new double[sz];
        double[] yval = new double[sz];
        // Coordinate values
        final double delta = 1d / (sz - 1);
        for (int i = 0; i < sz; i++) {
            xval[i] = -1 + 15 * i * delta;
            yval[i] = -20 + 30 * i * delta;
        }

        // Function values
        BivariateFunction f = new BivariateFunction() {
                public double value(double x, double y) {
                    return 2 * x - 3 * y + 5;
                }
            };
        double[][] zval = new double[xval.length][yval.length];
        for (int i = 0; i < xval.length; i++) {
            for (int j = 0; j < yval.length; j++) {
                zval[i][j] = f.value(xval[i], yval[j]);
            }
        }
        // Partial derivatives with respect to x
        double[][] dZdX = new double[xval.length][yval.length];
        for (int i = 0; i < xval.length; i++) {
            for (int j = 0; j < yval.length; j++) {
                dZdX[i][j] = 2;
            }
        }
        // Partial derivatives with respect to y
        double[][] dZdY = new double[xval.length][yval.length];
        for (int i = 0; i < xval.length; i++) {
            for (int j = 0; j < yval.length; j++) {
                dZdY[i][j] = -3;
            }
        }
        // Partial cross-derivatives
        double[][] dZdXdY = new double[xval.length][yval.length];
        for (int i = 0; i < xval.length; i++) {
            for (int j = 0; j < yval.length; j++) {
                dZdXdY[i][j] = 0;
            }
        }

        final BivariateFunction bcf
            = new BicubicSplineInterpolatingFunction(xval, yval, zval,
                                                     dZdX, dZdY, dZdXdY);
        double x, y;

        final RandomGenerator rng = new Well19937c(1234567L); // "tol" depends on the seed.
        final UniformRealDistribution distX
            = new UniformRealDistribution(rng, xval[0], xval[xval.length - 1]);
        final UniformRealDistribution distY
            = new UniformRealDistribution(rng, yval[0], yval[yval.length - 1]);

        final int numSamples = 50;
        final double tol = 6;
        for (int i = 0; i < numSamples; i++) {
            x = distX.sample();
            for (int j = 0; j < numSamples; j++) {
                y = distY.sample();
//                 System.out.println(x + " " + y + " " + f.value(x, y) + " " + bcf.value(x, y));
                Assert.assertEquals(f.value(x, y),  bcf.value(x, y), tol);
            }
//             System.out.println();
        }
    }
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:75,代码来源:BicubicSplineInterpolatingFunctionTest.java

示例6: testInterpolation

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
 * @param minimumX Lower bound of interpolation range along the x-coordinate.
 * @param maximumX Higher bound of interpolation range along the x-coordinate.
 * @param minimumY Lower bound of interpolation range along the y-coordinate.
 * @param maximumY Higher bound of interpolation range along the y-coordinate.
 * @param numberOfElements Number of data points (along each dimension).
 * @param numberOfSamples Number of test points.
 * @param f Function to test.
 * @param meanTolerance Allowed average error (mean error on all interpolated values).
 * @param maxTolerance Allowed error on each interpolated value.
 */
private void testInterpolation(double minimumX,
                               double maximumX,
                               double minimumY,
                               double maximumY,
                               int numberOfElements,
                               int numberOfSamples,
                               BivariateFunction f,
                               double meanTolerance,
                               double maxTolerance) {
    double expected;
    double actual;
    double currentX;
    double currentY;
    final double deltaX = (maximumX - minimumX) / ((double) numberOfElements);
    final double deltaY = (maximumY - minimumY) / ((double) numberOfElements);
    final double[] xValues = new double[numberOfElements];
    final double[] yValues = new double[numberOfElements];
    final double[][] zValues = new double[numberOfElements][numberOfElements];

    for (int i = 0; i < numberOfElements; i++) {
        xValues[i] = minimumX + deltaX * (double) i;
        for (int j = 0; j < numberOfElements; j++) {
            yValues[j] = minimumY + deltaY * (double) j;
            zValues[i][j] = f.value(xValues[i], yValues[j]);
        }
    }

    final BivariateFunction interpolation
        = new PiecewiseBicubicSplineInterpolatingFunction(xValues,
                                                          yValues,
                                                          zValues);

    for (int i = 0; i < numberOfElements; i++) {
        currentX = xValues[i];
        for (int j = 0; j < numberOfElements; j++) {
            currentY = yValues[j];
            expected = f.value(currentX, currentY);
            actual = interpolation.value(currentX, currentY);
            Assert.assertTrue(Precision.equals(expected, actual));
        }
    }

    final RandomGenerator rng = new Well19937c(1234567L);
    final UniformRealDistribution distX = new UniformRealDistribution(rng, xValues[0], xValues[xValues.length - 1]);
    final UniformRealDistribution distY = new UniformRealDistribution(rng, yValues[0], yValues[yValues.length - 1]);

    double sumError = 0;
    for (int i = 0; i < numberOfSamples; i++) {
        currentX = distX.sample();
        currentY = distY.sample();
        expected = f.value(currentX, currentY);
        actual = interpolation.value(currentX, currentY);
        sumError += FastMath.abs(actual - expected);
        Assert.assertEquals(expected, actual, maxTolerance);
    }

    final double meanError = sumError / numberOfSamples;
    Assert.assertEquals(0, meanError, meanTolerance);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:71,代码来源:PiecewiseBicubicSplineInterpolatingFunctionTest.java

示例7: testInterpolation

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
 * @param numSamples Number of test samples.
 * @param tolerance Allowed tolerance on the interpolated value.
 * @param f Test function.
 * @param print Whether to print debugging output to the console.
 */
private void testInterpolation(int numSamples,
                               double tolerance,
                               BivariateFunction f,
                               boolean print) {
    final int sz = 21;
    final double[] xval = new double[sz];
    final double[] yval = new double[sz];
    // Coordinate values
    final double delta = 1d / (sz - 1);
    for (int i = 0; i < sz; i++) {
        xval[i] = -1 + 15 * i * delta;
        yval[i] = -20 + 30 * i * delta;
    }

    final double[][] zval = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            zval[i][j] = f.value(xval[i], yval[j]);
        }
    }

    final BicubicInterpolator interpolator = new BicubicInterpolator();
    final BicubicInterpolatingFunction p = interpolator.interpolate(xval, yval, zval);
    double x, y;

    final RandomGenerator rng = new Well19937c();
    final UniformRealDistribution distX = new UniformRealDistribution(rng, xval[0], xval[xval.length - 1]);
    final UniformRealDistribution distY = new UniformRealDistribution(rng, yval[0], yval[yval.length - 1]);

    int count = 0;
    while (true) {
        x = distX.sample();
        y = distY.sample();
        if (!p.isValidPoint(x, y)) {
            if (print) {
                System.out.println("# " + x + " " + y);
            }
            continue;
        }

        if (count++ > numSamples) {
            break;
        }
        final double expected = f.value(x, y);
        final double actual = p.value(x, y);

        if (print) {
            System.out.println(x + " " + y + " " + expected + " " + actual);
        }

        Assert.assertEquals(expected, actual, tolerance);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:60,代码来源:BicubicInterpolatorTest.java

示例8: testInterpolation1

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
     * Interpolating a plane.
     * <p>
     * z = 2 x - 3 y + 5
     */
    @Test
    public void testInterpolation1() {
        final int sz = 21;
        double[] xval = new double[sz];
        double[] yval = new double[sz];
        // Coordinate values
        final double delta = 1d / (sz - 1);
        for ( int i = 0; i < sz; i++ ){
            xval[i] = -1 + 15 * i * delta;
            yval[i] = -20 + 30 * i * delta;
        }

        // Function values
        BivariateFunction f = new BivariateFunction() {
                public double value( double x, double y ) {
                    return 2 * x - 3 * y + 5;
                }
            };
        double[][] zval = new double[xval.length][yval.length];
        for ( int i = 0; i < xval.length; i++ ) {
            for ( int j = 0; j < yval.length; j++ ) {
                zval[i][j] = f.value(xval[i], yval[j]);
            }
        }

        BivariateGridInterpolator interpolator = new PiecewiseBicubicSplineInterpolator();
        BivariateFunction p = interpolator.interpolate(xval, yval, zval);
        double x, y;

        final RandomGenerator rng = new Well19937c(1234567L); // "tol" depends on the seed.
        final UniformRealDistribution distX = new UniformRealDistribution( rng, xval[0], xval[xval.length - 1] );
        final UniformRealDistribution distY = new UniformRealDistribution( rng, yval[0], yval[yval.length - 1] );

        final int numSamples = 50;
        final double tol = 2e-14;
        for ( int i = 0; i < numSamples; i++ ) {
            x = distX.sample();
            for ( int j = 0; j < numSamples; j++ ) {
                y = distY.sample();
//                 System.out.println(x + " " + y + " " + f.value(x, y) + " " + p.value(x, y));
                Assert.assertEquals(f.value(x, y),  p.value(x, y), tol);
            }
//             System.out.println();
        }
    }
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:51,代码来源:PiecewiseBicubicSplineInterpolatorTest.java

示例9: testInterpolation2

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
     * Interpolating a paraboloid.
     * <p>
     * z = 2 x<sup>2</sup> - 3 y<sup>2</sup> + 4 x y - 5
     */
    @Test
    public void testInterpolation2() {
        final int sz = 21;
        double[] xval = new double[sz];
        double[] yval = new double[sz];
        // Coordinate values
        final double delta = 1d / (sz - 1);
        for ( int i = 0; i < sz; i++ ) {
            xval[i] = -1 + 15 * i * delta;
            yval[i] = -20 + 30 * i * delta;
        }

        // Function values
        BivariateFunction f = new BivariateFunction() {
                public double value( double x, double y ) {
                    return 2 * x * x - 3 * y * y + 4 * x * y - 5;
                }
            };
        double[][] zval = new double[xval.length][yval.length];
        for ( int i = 0; i < xval.length; i++ ) {
            for ( int j = 0; j < yval.length; j++ ) {
                zval[i][j] = f.value(xval[i], yval[j]);
            }
        }

        BivariateGridInterpolator interpolator = new PiecewiseBicubicSplineInterpolator();
        BivariateFunction p = interpolator.interpolate(xval, yval, zval);
        double x, y;

        final RandomGenerator rng = new Well19937c(1234567L); // "tol" depends on the seed.
        final UniformRealDistribution distX = new UniformRealDistribution( rng, xval[0], xval[xval.length - 1] );
        final UniformRealDistribution distY = new UniformRealDistribution( rng, yval[0], yval[yval.length - 1] );

        final int numSamples = 50;
        final double tol = 5e-13;
        for ( int i = 0; i < numSamples; i++ ) {
            x = distX.sample();
            for ( int j = 0; j < numSamples; j++ ) {
                y = distY.sample();
//                 System.out.println(x + " " + y + " " + f.value(x, y) + " " + p.value(x, y));
                Assert.assertEquals(f.value(x, y),  p.value(x, y), tol);
            }
//             System.out.println();
        }
    }
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:51,代码来源:PiecewiseBicubicSplineInterpolatorTest.java

示例10: testPlane

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
 * Test of interpolator for a plane.
 * <p>
 * z = 2 x - 3 y + 5
 */
@Test
public void testPlane() {
    BivariateFunction f = new BivariateFunction() {
            public double value(double x, double y) {
                return 2 * x - 3 * y + 5
                    + ((int) (FastMath.abs(5 * x + 3 * y)) % 2 == 0 ? 1 : -1);
            }
        };

    BivariateGridInterpolator interpolator = new SmoothingPolynomialBicubicSplineInterpolator(1);

    double[] xval = new double[] {3, 4, 5, 6.5, 7.5};
    double[] yval = new double[] {-4, -3, -1, 2, 2.5, 3.5};
    double[][] zval = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            zval[i][j] = f.value(xval[i], yval[j]);
        }
    }

    BivariateFunction p = interpolator.interpolate(xval, yval, zval);
    double x, y;
    double expected, result;
    
    x = 4;
    y = -3;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("On sample point", expected, result, 2);

    x = 4.5;
    y = -1.5;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("half-way between sample points (middle of the patch)", expected, result, 2);

    x = 3.5;
    y = -3.5;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("half-way between sample points (border of the patch)", expected, result, 2);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:48,代码来源:SmoothingPolynomialBicubicSplineInterpolatorTest.java

示例11: testParaboloid

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
 * Test of interpolator for a paraboloid.
 * <p>
 * z = 2 x<sup>2</sup> - 3 y<sup>2</sup> + 4 x y - 5
 */
@Test
public void testParaboloid() {
    BivariateFunction f = new BivariateFunction() {
            public double value(double x, double y) {
                return 2 * x * x - 3 * y * y + 4 * x * y - 5
                    + ((int) (FastMath.abs(5 * x + 3 * y)) % 2 == 0 ? 1 : -1);
            }
        };

    BivariateGridInterpolator interpolator = new SmoothingPolynomialBicubicSplineInterpolator(4);

    double[] xval = new double[] {3, 4, 5, 6.5, 7.5, 8};
    double[] yval = new double[] {-4, -3, -2, -1, 0.5, 2.5};
    double[][] zval = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            zval[i][j] = f.value(xval[i], yval[j]);
        }
    }

    BivariateFunction p = interpolator.interpolate(xval, yval, zval);
    double x, y;
    double expected, result;

    x = 5;
    y = 0.5;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("On sample point", expected, result, 2);

    x = 4.5;
    y = -1.5;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("half-way between sample points (middle of the patch)", expected, result, 2);

    x = 3.5;
    y = -3.5;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("half-way between sample points (border of the patch)", expected, result, 2);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:48,代码来源:SmoothingPolynomialBicubicSplineInterpolatorTest.java

示例12: testParaboloid

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
 * Test of interpolator for a paraboloid.
 * <p>
 * z = 2 x<sup>2</sup> - 3 y<sup>2</sup> + 4 x y - 5
 */
@Test
public void testParaboloid() {
    BivariateFunction f = new BivariateFunction() {
            public double value(double x, double y) {
                return 2 * x * x - 3 * y * y + 4 * x * y - 5
                    + ((int) (FastMath.abs(5 * x + 3 * y)) % 2 == 0 ? 1 : -1);
            }
        };

    BivariateGridInterpolator interpolator = new SmoothingPolynomialBicubicSplineInterpolator(4);

    double[] xval = new double[] {3, 4, 5, 6.5};
    double[] yval = new double[] {-4, -3, -2, -1, 0.5, 2.5};
    double[][] zval = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            zval[i][j] = f.value(xval[i], yval[j]);
        }
    }

    BivariateFunction p = interpolator.interpolate(xval, yval, zval);
    double x, y;
    double expected, result;

    x = 5;
    y = 0.5;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("On sample point", expected, result, 2);

    x = 4.5;
    y = -1.5;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("half-way between sample points (middle of the patch)", expected, result, 2);

    x = 3.5;
    y = -3.5;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("half-way between sample points (border of the patch)", expected, result, 2);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:48,代码来源:SmoothingPolynomialBicubicSplineInterpolatorTest.java

示例13: testPlane

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
 * Test for a plane.
 * <p>
 * z = 2 x - 3 y + 5
 */
@Test
public void testPlane() {
    double[] xval = new double[] {3, 4, 5, 6.5};
    double[] yval = new double[] {-4, -3, -1, 2, 2.5};
    // Function values
    BivariateFunction f = new BivariateFunction() {
            public double value(double x, double y) {
                return 2 * x - 3 * y + 5;
            }
        };
    double[][] zval = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            zval[i][j] = f.value(xval[i], yval[j]);
        }
    }
    // Partial derivatives with respect to x
    double[][] dZdX = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            dZdX[i][j] = 2;
        }
    }
    // Partial derivatives with respect to y
    double[][] dZdY = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            dZdY[i][j] = -3;
        }
    }
    // Partial cross-derivatives
    double[][] dZdXdY = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            dZdXdY[i][j] = 0;
        }
    }

    BivariateFunction bcf = new BicubicSplineInterpolatingFunction(xval, yval, zval,
                                                                       dZdX, dZdY, dZdXdY);
    double x, y;
    double expected, result;

    x = 4;
    y = -3;
    expected = f.value(x, y);
    result = bcf.value(x, y);
    Assert.assertEquals("On sample point",
                        expected, result, 1e-15);

    x = 4.5;
    y = -1.5;
    expected = f.value(x, y);
    result = bcf.value(x, y);
    Assert.assertEquals("Half-way between sample points (middle of the patch)",
                        expected, result, 0.3);

    x = 3.5;
    y = -3.5;
    expected = f.value(x, y);
    result = bcf.value(x, y);
    Assert.assertEquals("Half-way between sample points (border of the patch)",
                        expected, result, 0.3);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:70,代码来源:BicubicSplineInterpolatingFunctionTest.java

示例14: testPlane

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
 * Test of interpolator for a plane.
 * <p>
 * z = 2 x - 3 y + 5
 */
@Test
public void testPlane() {
    BivariateFunction f = new BivariateFunction() {
            public double value(double x, double y) {
                return 2 * x - 3 * y + 5
                    + ((int) (FastMath.abs(5 * x + 3 * y)) % 2 == 0 ? 1 : -1);
            }
        };

    BivariateGridInterpolator interpolator = new SmoothingPolynomialBicubicSplineInterpolator(1);

    double[] xval = new double[] {3, 4, 5, 6.5};
    double[] yval = new double[] {-4, -3, -1, 2, 2.5};
    double[][] zval = new double[xval.length][yval.length];
    for (int i = 0; i < xval.length; i++) {
        for (int j = 0; j < yval.length; j++) {
            zval[i][j] = f.value(xval[i], yval[j]);
        }
    }

    BivariateFunction p = interpolator.interpolate(xval, yval, zval);
    double x, y;
    double expected, result;
    
    x = 4;
    y = -3;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("On sample point", expected, result, 2);

    x = 4.5;
    y = -1.5;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("half-way between sample points (middle of the patch)", expected, result, 2);

    x = 3.5;
    y = -3.5;
    expected = f.value(x, y);
    result = p.value(x, y);
    Assert.assertEquals("half-way between sample points (border of the patch)", expected, result, 2);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:48,代码来源:SmoothingPolynomialBicubicSplineInterpolatorTest.java

示例15: evaluate

import org.apache.commons.math3.analysis.BivariateFunction; //导入方法依赖的package包/类
/**
 * Compute the value of the function
 * @param func The function
 * @param x Input x data
 * @param y Input y data
 * @return Function value
 */
public static double evaluate(BivariateFunction func, Number x, Number y) {
    return func.value(x.doubleValue(), y.doubleValue());
}
 
开发者ID:meteoinfo,项目名称:MeteoInfoLib,代码行数:11,代码来源:InterpUtil.java


注:本文中的org.apache.commons.math3.analysis.BivariateFunction.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。