Fix incorrect usage of "ROSENBROCK" test function (unit tests).
This commit is contained in:
parent
cc5ae51f98
commit
6f33d5f0a7
|
@ -40,48 +40,53 @@ public class BOBYQAOptimizerTest {
|
|||
|
||||
@Test(expected=NumberIsTooLargeException.class)
|
||||
public void testInitOutOfBounds() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM, 3);
|
||||
double[][] boundaries = boundaries(DIM, -1, 2);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, boundaries,
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 3);
|
||||
double[][] boundaries = boundaries(dim, -1, 2);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, boundaries,
|
||||
GoalType.MINIMIZE,
|
||||
1e-13, 1e-6, 2000, null);
|
||||
}
|
||||
|
||||
@Test(expected=DimensionMismatchException.class)
|
||||
public void testBoundariesDimensionMismatch() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM, 0.5);
|
||||
double[][] boundaries = boundaries(DIM + 1, -1, 2);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, boundaries,
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.5);
|
||||
double[][] boundaries = boundaries(dim + 1, -1, 2);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, boundaries,
|
||||
GoalType.MINIMIZE,
|
||||
1e-13, 1e-6, 2000, null);
|
||||
}
|
||||
|
||||
@Test(expected=NumberIsTooSmallException.class)
|
||||
public void testProblemDimensionTooSmall() {
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(1, 0.5);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, null,
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, null,
|
||||
GoalType.MINIMIZE,
|
||||
1e-13, 1e-6, 2000, null);
|
||||
}
|
||||
|
||||
@Test(expected=TooManyEvaluationsException.class)
|
||||
public void testMaxEvaluations() {
|
||||
final int dim = 12;
|
||||
final int lowMaxEval = 2;
|
||||
double[] startPoint = OptimTestUtils.point(DIM, 0.1);
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.1);
|
||||
double[][] boundaries = null;
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, boundaries,
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, boundaries,
|
||||
GoalType.MINIMIZE,
|
||||
1e-13, 1e-6, lowMaxEval, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRosen() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM,0.1);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.1);
|
||||
double[][] boundaries = null;
|
||||
PointValuePair expected = new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, boundaries,
|
||||
PointValuePair expected = new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, boundaries,
|
||||
GoalType.MINIMIZE,
|
||||
1e-13, 1e-6, 2000, expected);
|
||||
1e-13, 1e-6, 3000, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -213,14 +218,15 @@ public class BOBYQAOptimizerTest {
|
|||
|
||||
@Test
|
||||
public void testConstrainedRosen() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM,0.1);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.1);
|
||||
|
||||
double[][] boundaries = boundaries(DIM,-1,2);
|
||||
double[][] boundaries = boundaries(dim, -1, 2);
|
||||
PointValuePair expected =
|
||||
new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, boundaries,
|
||||
new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, boundaries,
|
||||
GoalType.MINIMIZE,
|
||||
1e-13, 1e-6, 2000, expected);
|
||||
1e-13, 1e-6, 3000, expected);
|
||||
}
|
||||
|
||||
// See MATH-728
|
||||
|
@ -228,9 +234,10 @@ public class BOBYQAOptimizerTest {
|
|||
// makes it run for several hours before completing
|
||||
@Ignore @Test
|
||||
public void testConstrainedRosenWithMoreInterpolationPoints() {
|
||||
final double[] startPoint = OptimTestUtils.point(DIM, 0.1);
|
||||
final double[][] boundaries = boundaries(DIM, -1, 2);
|
||||
final PointValuePair expected = new PointValuePair(OptimTestUtils.point(DIM, 1.0), 0.0);
|
||||
final int dim = 12;
|
||||
final double[] startPoint = OptimTestUtils.point(dim, 0.1);
|
||||
final double[][] boundaries = boundaries(dim, -1, 2);
|
||||
final PointValuePair expected = new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
|
||||
// This should have been 78 because in the code the hard limit is
|
||||
// said to be
|
||||
|
@ -240,7 +247,7 @@ public class BOBYQAOptimizerTest {
|
|||
final int maxAdditionalPoints = 47;
|
||||
|
||||
for (int num = 1; num <= maxAdditionalPoints; num++) {
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, boundaries,
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, boundaries,
|
||||
GoalType.MINIMIZE,
|
||||
1e-12, 1e-6, 2000,
|
||||
num,
|
||||
|
|
|
@ -49,71 +49,77 @@ public class CMAESOptimizerTest {
|
|||
|
||||
@Test(expected = NumberIsTooLargeException.class)
|
||||
public void testInitOutofbounds1() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM,3);
|
||||
double[] insigma = OptimTestUtils.point(DIM, 0.3);
|
||||
double[][] boundaries = boundaries(DIM,-1,2);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 3);
|
||||
double[] insigma = OptimTestUtils.point(dim, 0.3);
|
||||
double[][] boundaries = boundaries(dim, -1, 2);
|
||||
PointValuePair expected =
|
||||
new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, LAMBDA, true, 0, 1e-13,
|
||||
1e-13, 1e-6, 100000, expected);
|
||||
}
|
||||
@Test(expected = NumberIsTooSmallException.class)
|
||||
public void testInitOutofbounds2() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM, -2);
|
||||
double[] insigma = OptimTestUtils.point(DIM, 0.3);
|
||||
double[][] boundaries = boundaries(DIM,-1,2);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, -2);
|
||||
double[] insigma = OptimTestUtils.point(dim, 0.3);
|
||||
double[][] boundaries = boundaries(dim, -1, 2);
|
||||
PointValuePair expected =
|
||||
new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, LAMBDA, true, 0, 1e-13,
|
||||
1e-13, 1e-6, 100000, expected);
|
||||
}
|
||||
|
||||
@Test(expected = DimensionMismatchException.class)
|
||||
public void testBoundariesDimensionMismatch() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM,0.5);
|
||||
double[] insigma = OptimTestUtils.point(DIM, 0.3);
|
||||
double[][] boundaries = boundaries(DIM+1,-1,2);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.5);
|
||||
double[] insigma = OptimTestUtils.point(dim, 0.3);
|
||||
double[][] boundaries = boundaries(dim + 1,-1,2);
|
||||
PointValuePair expected =
|
||||
new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, LAMBDA, true, 0, 1e-13,
|
||||
1e-13, 1e-6, 100000, expected);
|
||||
}
|
||||
|
||||
@Test(expected = NotPositiveException.class)
|
||||
public void testInputSigmaNegative() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM,0.5);
|
||||
double[] insigma = OptimTestUtils.point(DIM,-0.5);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.5);
|
||||
double[] insigma = OptimTestUtils.point(dim, -0.5);
|
||||
double[][] boundaries = null;
|
||||
PointValuePair expected =
|
||||
new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, LAMBDA, true, 0, 1e-13,
|
||||
1e-13, 1e-6, 100000, expected);
|
||||
}
|
||||
|
||||
@Test(expected = OutOfRangeException.class)
|
||||
public void testInputSigmaOutOfRange() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM,0.5);
|
||||
double[] insigma = OptimTestUtils.point(DIM, 1.1);
|
||||
double[][] boundaries = boundaries(DIM,-0.5,0.5);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.5);
|
||||
double[] insigma = OptimTestUtils.point(dim, 1.1);
|
||||
double[][] boundaries = boundaries(dim, -0.5,0.5);
|
||||
PointValuePair expected =
|
||||
new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, LAMBDA, true, 0, 1e-13,
|
||||
1e-13, 1e-6, 100000, expected);
|
||||
}
|
||||
|
||||
@Test(expected = DimensionMismatchException.class)
|
||||
public void testInputSigmaDimensionMismatch() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM,0.5);
|
||||
double[] insigma = OptimTestUtils.point(DIM + 1, 0.5);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.5);
|
||||
double[] insigma = OptimTestUtils.point(dim + 1, 0.5);
|
||||
double[][] boundaries = null;
|
||||
PointValuePair expected =
|
||||
new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, LAMBDA, true, 0, 1e-13,
|
||||
1e-13, 1e-6, 100000, expected);
|
||||
}
|
||||
|
@ -121,15 +127,16 @@ public class CMAESOptimizerTest {
|
|||
@Test
|
||||
@Retry(3)
|
||||
public void testRosen() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM,0.1);
|
||||
double[] insigma = OptimTestUtils.point(DIM,0.1);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.1);
|
||||
double[] insigma = OptimTestUtils.point(dim, 0.1);
|
||||
double[][] boundaries = null;
|
||||
PointValuePair expected =
|
||||
new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, LAMBDA, true, 0, 1e-13,
|
||||
1e-13, 1e-6, 100000, expected);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, LAMBDA, false, 0, 1e-13,
|
||||
1e-13, 1e-6, 100000, expected);
|
||||
}
|
||||
|
@ -346,27 +353,29 @@ public class CMAESOptimizerTest {
|
|||
|
||||
@Test
|
||||
public void testConstrainedRosen() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM, 0.1);
|
||||
double[] insigma = OptimTestUtils.point(DIM, 0.1);
|
||||
double[][] boundaries = boundaries(DIM, -1, 2);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.1);
|
||||
double[] insigma = OptimTestUtils.point(dim, 0.1);
|
||||
double[][] boundaries = boundaries(dim, -1, 2);
|
||||
PointValuePair expected =
|
||||
new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, 2*LAMBDA, true, 0, 1e-13,
|
||||
1e-13, 1e-6, 100000, expected);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, 2*LAMBDA, false, 0, 1e-13,
|
||||
1e-13, 1e-6, 100000, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiagonalRosen() {
|
||||
double[] startPoint = OptimTestUtils.point(DIM,0.1);
|
||||
double[] insigma = OptimTestUtils.point(DIM,0.1);
|
||||
final int dim = 12;
|
||||
double[] startPoint = OptimTestUtils.point(dim, 0.1);
|
||||
double[] insigma = OptimTestUtils.point(dim, 0.1);
|
||||
double[][] boundaries = null;
|
||||
PointValuePair expected =
|
||||
new PointValuePair(OptimTestUtils.point(DIM,1.0),0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(DIM), startPoint, insigma, boundaries,
|
||||
new PointValuePair(OptimTestUtils.point(dim, 1.0), 0.0);
|
||||
doTest(TestFunction.ROSENBROCK.withDimension(dim), startPoint, insigma, boundaries,
|
||||
GoalType.MINIMIZE, LAMBDA, false, 1, 1e-13,
|
||||
1e-10, 1e-4, 1000000, expected);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue