MATH-867
Modified "encode" and "decode" methods. Unit test "testFitAccuracyDependsOnBoundary" now passes and is thus enabled. Unit test "testConstrainedRosen" had to be modified in order to not fail with the new code (starting point is set closer to the solution). git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1391840 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
678377a1e8
commit
329cf9e8e6
|
@ -585,8 +585,8 @@ public class CMAESOptimizer
|
|||
// initialize sigma
|
||||
double[][] sigmaArray = new double[guess.length][1];
|
||||
for (int i = 0; i < guess.length; i++) {
|
||||
final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i];
|
||||
sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range;
|
||||
final double range = (boundaries == null) ? 1.0 : boundaries[1][i] - boundaries[0][i];
|
||||
sigmaArray[i][0] = ((inputSigma == null) ? 0.3 : inputSigma[i]) / range;
|
||||
}
|
||||
RealMatrix insigma = new Array2DRowRealMatrix(sigmaArray, false);
|
||||
sigma = max(insigma); // overall standard deviation
|
||||
|
@ -929,7 +929,7 @@ public class CMAESOptimizer
|
|||
double[] res = new double[x.length];
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
double diff = boundaries[1][i] - boundaries[0][i];
|
||||
res[i] = (x[i] - boundaries[0][i]) / diff;
|
||||
res[i] = x[i] / diff;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -955,7 +955,7 @@ public class CMAESOptimizer
|
|||
double[] res = new double[x.length];
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
double diff = boundaries[1][i] - boundaries[0][i];
|
||||
res[i] = diff * x[i] + boundaries[0][i];
|
||||
res[i] = diff * x[i];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -986,11 +986,15 @@ public class CMAESOptimizer
|
|||
if (boundaries == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final double[] bLoEnc = encode(boundaries[0]);
|
||||
final double[] bHiEnc = encode(boundaries[1]);
|
||||
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
if (x[i] < 0) {
|
||||
if (x[i] < bLoEnc[i]) {
|
||||
return false;
|
||||
}
|
||||
if (x[i] > 1.0) {
|
||||
if (x[i] > bHiEnc[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -350,8 +350,8 @@ public class CMAESOptimizerTest {
|
|||
|
||||
@Test
|
||||
public void testConstrainedRosen() {
|
||||
double[] startPoint = point(DIM, 0.1);
|
||||
double[] insigma = point(DIM, 1);
|
||||
double[] startPoint = point(DIM, 0.7);
|
||||
double[] insigma = point(DIM, 0.1);
|
||||
double[][] boundaries = boundaries(DIM, -1, 2);
|
||||
PointValuePair expected =
|
||||
new PointValuePair(point(DIM,1.0),0.0);
|
||||
|
@ -427,7 +427,7 @@ public class CMAESOptimizerTest {
|
|||
/**
|
||||
* Cf. MATH-867
|
||||
*/
|
||||
@Ignore@Test
|
||||
@Test
|
||||
public void testFitAccuracyDependsOnBoundary() {
|
||||
final CMAESOptimizer optimizer = new CMAESOptimizer();
|
||||
final MultivariateFunction fitnessFunction = new MultivariateFunction() {
|
||||
|
@ -439,7 +439,7 @@ public class CMAESOptimizerTest {
|
|||
};
|
||||
|
||||
final double[] start = { 1 };
|
||||
|
||||
|
||||
// No bounds.
|
||||
PointValuePair result = optimizer.optimize(100000, fitnessFunction, GoalType.MINIMIZE,
|
||||
start);
|
||||
|
|
Loading…
Reference in New Issue