You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/08/21 07:16:23 UTC

[commons-math] branch master updated: sonar fix: Ensure checkFeasableCount is not negative.

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git


The following commit(s) were added to refs/heads/master by this push:
     new 1fdd559  sonar fix: Ensure checkFeasableCount is not negative.
1fdd559 is described below

commit 1fdd55981d4445103ce37be16fbb440eaca0928e
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Aug 21 08:16:20 2021 +0100

    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.
---
 .../math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java
index a5b8e35..13e7480 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java
@@ -236,7 +236,7 @@ public class CMAESOptimizer
         this.stopFitness = stopFitness;
         this.isActiveCMA = isActiveCMA;
         this.diagonalOnly = diagonalOnly;
-        this.checkFeasableCount = checkFeasableCount;
+        this.checkFeasableCount = Math.max(0, checkFeasableCount);
         this.random = new NormalDistribution(0, 1).createSampler(rng);
         this.generateStatistics = generateStatistics;
     }
@@ -398,7 +398,7 @@ public class CMAESOptimizer
             // generate random offspring
             for (int k = 0; k < lambda; k++) {
                 RealMatrix arxk = null;
-                for (int i = 0; i < checkFeasableCount + 1; i++) {
+                for (int i = 0; i <= checkFeasableCount; i++) {
                     if (diagonalOnly <= 0) {
                         arxk = xmean.add(BD.multiply(arz.getColumnMatrix(k))
                                          .scalarMultiply(sigma)); // m + sig * Normal(0,C)