You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2011/04/05 07:52:22 UTC

svn commit: r1088902 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/CMAESOptimizer.java

Author: psteitz
Date: Tue Apr  5 05:52:21 2011
New Revision: 1088902

URL: http://svn.apache.org/viewvc?rev=1088902&view=rev
Log:
Changed to use, rathern than duplicate Realmatrix Frobenius norm.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/CMAESOptimizer.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/CMAESOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/CMAESOptimizer.java?rev=1088902&r1=1088901&r2=1088902&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/CMAESOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/CMAESOptimizer.java Tue Apr  5 05:52:21 2011
@@ -579,7 +579,7 @@ public class CMAESOptimizer extends
         diagC = square(diagD);
         pc = zeros(dimension, 1); // evolution paths for C and sigma
         ps = zeros(dimension, 1); // B defines the coordinate system
-        normps = norm(ps);
+        normps = ps.getFrobeniusNorm();
 
         B = eye(dimension, dimension);
         D = ones(dimension, 1); // diagonal D defines the scaling
@@ -605,7 +605,7 @@ public class CMAESOptimizer extends
         ps = ps.scalarMultiply(1. - cs).add(
                 B.multiply(zmean).scalarMultiply(
                         Math.sqrt(cs * (2. - cs) * mueff)));
-        normps = norm(ps);
+        normps = ps.getFrobeniusNorm();
         boolean hsig = normps /
             Math.sqrt(1. - Math.pow(1. - cs, 2. * iterations)) /
                 chiN < 1.4 + 2. / (dimension + 1.);
@@ -1059,21 +1059,6 @@ public class CMAESOptimizer extends
     /**
      * @param m
      *            Input matrix.
-     * @return Norm of the matrix.
-     */
-    private static double norm(final RealMatrix m) {
-        double sum = 0;
-        for (int r = 0; r < m.getRowDimension(); r++)
-            for (int c = 0; c < m.getColumnDimension(); c++) {
-                double e = m.getEntry(r, c);
-                sum += e*e;
-            }
-        return Math.sqrt(sum);
-    }
-
-    /**
-     * @param m
-     *            Input matrix.
      * @return Row matrix representing the sums of the rows.
      */
     private static RealMatrix sumRows(final RealMatrix m) {