Formatting.
This commit is contained in:
parent
301ad59214
commit
f8a8ea748a
|
@ -16,9 +16,6 @@
|
|||
*/
|
||||
package org.apache.commons.math3.analysis.interpolation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.InsufficientDataException;
|
||||
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
|
||||
|
@ -134,13 +131,14 @@ public final class PiecewiseBicubicSplineInterpolatingFunctionTest {
|
|||
* z = 2 x - 3 y + 5
|
||||
*/
|
||||
@Test
|
||||
public void testInterpolatePlane() {
|
||||
public void testPlane() {
|
||||
final int numberOfElements = 10;
|
||||
final double minimumX = -10;
|
||||
final double maximumX = 10;
|
||||
final double minimumY = -10;
|
||||
final double maximumY = 10;
|
||||
final int numberOfSamples = 100;
|
||||
|
||||
final double interpolationTolerance = 7e-15;
|
||||
final double maxTolerance = 6e-14;
|
||||
|
||||
|
@ -151,8 +149,15 @@ public final class PiecewiseBicubicSplineInterpolatingFunctionTest {
|
|||
}
|
||||
};
|
||||
|
||||
testInterpolation( minimumX, maximumX, minimumY, maximumY, numberOfElements, numberOfSamples, f,
|
||||
interpolationTolerance, maxTolerance );
|
||||
testInterpolation(minimumX,
|
||||
maximumX,
|
||||
minimumY,
|
||||
maximumY,
|
||||
numberOfElements,
|
||||
numberOfSamples,
|
||||
f,
|
||||
interpolationTolerance,
|
||||
maxTolerance);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,13 +166,14 @@ public final class PiecewiseBicubicSplineInterpolatingFunctionTest {
|
|||
* z = 2 x<sup>2</sup> - 3 y<sup>2</sup> + 4 x y - 5
|
||||
*/
|
||||
@Test
|
||||
public void testInterpolationParabaloid() {
|
||||
public void testParabaloid() {
|
||||
final int numberOfElements = 10;
|
||||
final double minimumX = -10;
|
||||
final double maximumX = 10;
|
||||
final double minimumY = -10;
|
||||
final double maximumY = 10;
|
||||
final int numberOfSamples = 100;
|
||||
|
||||
final double interpolationTolerance = 2e-14;
|
||||
final double maxTolerance = 6e-14;
|
||||
|
||||
|
@ -178,12 +184,36 @@ public final class PiecewiseBicubicSplineInterpolatingFunctionTest {
|
|||
}
|
||||
};
|
||||
|
||||
testInterpolation( minimumX, maximumX, minimumY, maximumY, numberOfElements, numberOfSamples, f,
|
||||
interpolationTolerance, maxTolerance );
|
||||
testInterpolation(minimumX,
|
||||
maximumX,
|
||||
minimumY,
|
||||
maximumY,
|
||||
numberOfElements,
|
||||
numberOfSamples,
|
||||
f,
|
||||
interpolationTolerance,
|
||||
maxTolerance);
|
||||
}
|
||||
|
||||
private void testInterpolation( double minimumX, double maximumX, double minimumY, double maximumY,
|
||||
int numberOfElements, int numberOfSamples, BivariateFunction f, double tolerance,
|
||||
/**
|
||||
* @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;
|
||||
|
@ -191,9 +221,9 @@ public final class PiecewiseBicubicSplineInterpolatingFunctionTest {
|
|||
double currentY;
|
||||
final double deltaX = (maximumX - minimumX) / ((double) numberOfElements);
|
||||
final double deltaY = (maximumY - minimumY) / ((double) numberOfElements);
|
||||
double xValues[] = new double[numberOfElements];
|
||||
double yValues[] = new double[numberOfElements];
|
||||
double zValues[][] = new double[numberOfElements][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;
|
||||
|
@ -203,7 +233,10 @@ public final class PiecewiseBicubicSplineInterpolatingFunctionTest {
|
|||
}
|
||||
}
|
||||
|
||||
BivariateFunction interpolation = new PiecewiseBicubicSplineInterpolatingFunction( xValues, yValues, zValues );
|
||||
final BivariateFunction interpolation
|
||||
= new PiecewiseBicubicSplineInterpolatingFunction(xValues,
|
||||
yValues,
|
||||
zValues);
|
||||
|
||||
for (int i = 0; i < numberOfElements; i++) {
|
||||
currentX = xValues[i];
|
||||
|
@ -211,11 +244,11 @@ public final class PiecewiseBicubicSplineInterpolatingFunctionTest {
|
|||
currentY = yValues[j];
|
||||
expected = f.value(currentX, currentY);
|
||||
actual = interpolation.value(currentX, currentY);
|
||||
assertTrue( Precision.equals( expected, actual ) );
|
||||
Assert.assertTrue(Precision.equals(expected, actual));
|
||||
}
|
||||
}
|
||||
|
||||
final RandomGenerator rng = new Well19937c( 1234567L ); // "tol" depends on the seed.
|
||||
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]);
|
||||
|
||||
|
@ -226,9 +259,10 @@ public final class PiecewiseBicubicSplineInterpolatingFunctionTest {
|
|||
expected = f.value(currentX, currentY);
|
||||
actual = interpolation.value(currentX, currentY);
|
||||
sumError += FastMath.abs(actual - expected);
|
||||
assertEquals( expected, actual, maxTolerance );
|
||||
Assert.assertEquals(expected, actual, maxTolerance);
|
||||
}
|
||||
|
||||
assertEquals( 0.0, ( sumError / (double) numberOfSamples ), tolerance );
|
||||
final double meanError = sumError / numberOfSamples;
|
||||
Assert.assertEquals(0, meanError, meanTolerance);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue