sonar fix: Ensure checkFeasableCount is not negative.

Change loop condition to 'i <= checkFeasableCount' from 'i <
checkFeasableCount + 1'

This ensures the loop to identify a new feasible column (RealMatrix
arxk) always executes at least once even with checkFeasibleCount at the
limit of 0 or Integer.MAX_VALUE.
This commit is contained in:
Alex Herbert 2021-08-21 08:16:20 +01:00 committed by Gilles Sadowski
parent 228a832532
commit 30aa597f1e
1 changed files with 2 additions and 2 deletions

View File

@ -236,7 +236,7 @@ public class CMAESOptimizer
this.stopFitness = stopFitness; this.stopFitness = stopFitness;
this.isActiveCMA = isActiveCMA; this.isActiveCMA = isActiveCMA;
this.diagonalOnly = diagonalOnly; this.diagonalOnly = diagonalOnly;
this.checkFeasableCount = checkFeasableCount; this.checkFeasableCount = Math.max(0, checkFeasableCount);
this.random = new NormalDistribution(0, 1).createSampler(rng); this.random = new NormalDistribution(0, 1).createSampler(rng);
this.generateStatistics = generateStatistics; this.generateStatistics = generateStatistics;
} }
@ -398,7 +398,7 @@ public class CMAESOptimizer
// generate random offspring // generate random offspring
for (int k = 0; k < lambda; k++) { for (int k = 0; k < lambda; k++) {
RealMatrix arxk = null; RealMatrix arxk = null;
for (int i = 0; i < checkFeasableCount + 1; i++) { for (int i = 0; i <= checkFeasableCount; i++) {
if (diagonalOnly <= 0) { if (diagonalOnly <= 0) {
arxk = xmean.add(BD.multiply(arz.getColumnMatrix(k)) arxk = xmean.add(BD.multiply(arz.getColumnMatrix(k))
.scalarMultiply(sigma)); // m + sig * Normal(0,C) .scalarMultiply(sigma)); // m + sig * Normal(0,C)