commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1173964 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/optimization/direct/ test/java/org/apache/commons/math/linear/
Date Thu, 22 Sep 2011 06:37:41 GMT
Author: celestin
Date: Thu Sep 22 06:37:41 2011
New Revision: 1173964

URL: http://svn.apache.org/viewvc?rev=1173964&view=rev
Log:
Replaced EigenDecomposition by EigenDecompositionImpl (preliminary cleaning for solving MATH-662).

Added:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenDecompositionTest.java
      - copied, changed from r1173471, commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenDecompositionImplTest.java
Removed:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenDecompositionImplTest.java
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/CMAESOptimizer.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenSolverTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SingularValueDecompositionImplTest.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=1173964&r1=1173963&r2=1173964&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
Thu Sep 22 06:37:41 2011
@@ -28,7 +28,6 @@ import org.apache.commons.math.exception
 import org.apache.commons.math.exception.OutOfRangeException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;
 import org.apache.commons.math.linear.Array2DRowRealMatrix;
-import org.apache.commons.math.linear.EigenDecomposition;
 import org.apache.commons.math.linear.EigenDecompositionImpl;
 import org.apache.commons.math.linear.MatrixUtils;
 import org.apache.commons.math.linear.RealMatrix;
@@ -769,7 +768,7 @@ public class CMAESOptimizer extends
             // to achieve O(N^2)
             C = triu(C, 0).add(triu(C, 1).transpose());
             // enforce symmetry to prevent complex numbers
-            EigenDecomposition eig = new EigenDecompositionImpl(C, 1.0);
+            EigenDecompositionImpl eig = new EigenDecompositionImpl(C, 1.0);
             B = eig.getV(); // eigen decomposition, B==normalized eigenvectors
             D = eig.getD();
             diagD = diag(D);

Copied: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenDecompositionTest.java
(from r1173471, commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenDecompositionImplTest.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenDecompositionTest.java?p2=commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenDecompositionTest.java&p1=commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenDecompositionImplTest.java&r1=1173471&r2=1173964&rev=1173964&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenDecompositionImplTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenDecompositionTest.java
Thu Sep 22 06:37:41 2011
@@ -28,7 +28,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-public class EigenDecompositionImplTest {
+public class EigenDecompositionTest {
 
     private double[] refValues;
     private RealMatrix matrix;
@@ -37,7 +37,8 @@ public class EigenDecompositionImplTest 
     public void testDimension1() {
         RealMatrix matrix =
             MatrixUtils.createRealMatrix(new double[][] { { 1.5 } });
-        EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         Assert.assertEquals(1.5, ed.getRealEigenvalue(0), 1.0e-15);
     }
 
@@ -48,7 +49,8 @@ public class EigenDecompositionImplTest 
                     { 59.0, 12.0 },
                     { 12.0, 66.0 }
             });
-        EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         Assert.assertEquals(75.0, ed.getRealEigenvalue(0), 1.0e-15);
         Assert.assertEquals(50.0, ed.getRealEigenvalue(1), 1.0e-15);
     }
@@ -61,7 +63,8 @@ public class EigenDecompositionImplTest 
                                    {  -4824.0,  8693.0,   7920.0 },
                                    { -16560.0,  7920.0,  17300.0 }
                                });
-        EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         Assert.assertEquals(50000.0, ed.getRealEigenvalue(0), 3.0e-11);
         Assert.assertEquals(12500.0, ed.getRealEigenvalue(1), 3.0e-11);
         Assert.assertEquals( 3125.0, ed.getRealEigenvalue(2), 3.0e-11);
@@ -75,7 +78,8 @@ public class EigenDecompositionImplTest 
                     { 10,   20,   30 },
                     { 15,   30,   45 }
             });
-        EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         Assert.assertEquals(70.0, ed.getRealEigenvalue(0), 3.0e-11);
         Assert.assertEquals(0.0,  ed.getRealEigenvalue(1), 3.0e-11);
         Assert.assertEquals(0.0,  ed.getRealEigenvalue(2), 3.0e-11);
@@ -90,7 +94,8 @@ public class EigenDecompositionImplTest 
                                    {  0.000,  0.000,  0.164, -0.048 },
                                    {  0.000,  0.000, -0.048,  0.136 }
                                });
-        EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         Assert.assertEquals(1.0, ed.getRealEigenvalue(0), 1.0e-15);
         Assert.assertEquals(0.4, ed.getRealEigenvalue(1), 1.0e-15);
         Assert.assertEquals(0.2, ed.getRealEigenvalue(2), 1.0e-15);
@@ -106,7 +111,8 @@ public class EigenDecompositionImplTest 
                                    {  0.1152, -0.2304,  0.3088, -0.1344 },
                                    { -0.2976,  0.1152, -0.1344,  0.3872 }
                                });
-        EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         Assert.assertEquals(1.0, ed.getRealEigenvalue(0), 1.0e-15);
         Assert.assertEquals(0.4, ed.getRealEigenvalue(1), 1.0e-15);
         Assert.assertEquals(0.2, ed.getRealEigenvalue(2), 1.0e-15);
@@ -137,8 +143,10 @@ public class EigenDecompositionImplTest 
             new ArrayRealVector(new double[] { -0.584677060845929,  0.367177264979103,  0.721453187784497,
-0.052971054621812,  0.005740715188257 })
         };
 
-        EigenDecomposition decomposition =
-            new EigenDecompositionImpl(mainTridiagonal, secondaryTridiagonal, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl decomposition;
+        decomposition = new EigenDecompositionImpl(mainTridiagonal,
+                                                   secondaryTridiagonal,
+                                                   MathUtils.SAFE_MIN);
 
         double[] eigenValues = decomposition.getRealEigenvalues();
         for (int i = 0; i < refEigenValues.length; ++i) {
@@ -180,8 +188,10 @@ public class EigenDecompositionImplTest 
         };
 
         // the following line triggers the exception
-        EigenDecomposition decomposition =
-            new EigenDecompositionImpl(mainTridiagonal, secondaryTridiagonal, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl decomposition;
+        decomposition = new EigenDecompositionImpl(mainTridiagonal,
+                                                   secondaryTridiagonal,
+                                                   MathUtils.SAFE_MIN);
 
         double[] eigenValues = decomposition.getRealEigenvalues();
         for (int i = 0; i < refEigenValues.length; ++i) {
@@ -225,8 +235,10 @@ public class EigenDecompositionImplTest 
         };
 
         // the following line triggers the exception
-        EigenDecomposition decomposition =
-            new EigenDecompositionImpl(mainTridiagonal, secondaryTridiagonal, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl decomposition;
+        decomposition = new EigenDecompositionImpl(mainTridiagonal,
+                                                   secondaryTridiagonal,
+                                                   MathUtils.SAFE_MIN);
 
         double[] eigenValues = decomposition.getRealEigenvalues();
         for (int i = 0; i < refEigenValues.length; ++i) {
@@ -255,10 +267,10 @@ public class EigenDecompositionImplTest 
         Arrays.sort(ref);
         TriDiagonalTransformer t =
             new TriDiagonalTransformer(createTestMatrix(r, ref));
-        EigenDecomposition ed =
-            new EigenDecompositionImpl(t.getMainDiagonalRef(),
-                                       t.getSecondaryDiagonalRef(),
-                                       MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(t.getMainDiagonalRef(),
+                                        t.getSecondaryDiagonalRef(),
+                                        MathUtils.SAFE_MIN);
         double[] eigenValues = ed.getRealEigenvalues();
         Assert.assertEquals(ref.length, eigenValues.length);
         for (int i = 0; i < ref.length; ++i) {
@@ -271,7 +283,8 @@ public class EigenDecompositionImplTest 
     @Test
     public void testDimensions() {
         final int m = matrix.getRowDimension();
-        EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         Assert.assertEquals(m, ed.getV().getRowDimension());
         Assert.assertEquals(m, ed.getV().getColumnDimension());
         Assert.assertEquals(m, ed.getD().getColumnDimension());
@@ -283,7 +296,8 @@ public class EigenDecompositionImplTest 
     /** test eigenvalues */
     @Test
     public void testEigenvalues() {
-        EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         double[] eigenValues = ed.getRealEigenvalues();
         Assert.assertEquals(refValues.length, eigenValues.length);
         for (int i = 0; i < refValues.length; ++i) {
@@ -300,8 +314,9 @@ public class EigenDecompositionImplTest 
             bigValues[i] = 2 * r.nextDouble() - 1;
         }
         Arrays.sort(bigValues);
-        EigenDecomposition ed =
-            new EigenDecompositionImpl(createTestMatrix(r, bigValues), MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(createTestMatrix(r, bigValues),
+                                        MathUtils.SAFE_MIN);
         double[] eigenValues = ed.getRealEigenvalues();
         Assert.assertEquals(bigValues.length, eigenValues.length);
         for (int i = 0; i < bigValues.length; ++i) {
@@ -312,7 +327,8 @@ public class EigenDecompositionImplTest 
     /** test eigenvectors */
     @Test
     public void testEigenvectors() {
-        EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         for (int i = 0; i < matrix.getRowDimension(); ++i) {
             double lambda = ed.getRealEigenvalue(i);
             RealVector v  = ed.getEigenvector(i);
@@ -324,7 +340,8 @@ public class EigenDecompositionImplTest 
     /** test A = VDVt */
     @Test
     public void testAEqualVDVt() {
-        EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
         RealMatrix v  = ed.getV();
         RealMatrix d  = ed.getD();
         RealMatrix vT = ed.getVT();
@@ -346,7 +363,8 @@ public class EigenDecompositionImplTest 
     public void testDiagonal() {
         double[] diagonal = new double[] { -3.0, -2.0, 2.0, 5.0 };
         RealMatrix m = createDiagonalMatrix(diagonal, diagonal.length, diagonal.length);
-        EigenDecomposition ed = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN);
         Assert.assertEquals(diagonal[0], ed.getRealEigenvalue(3), 2.0e-15);
         Assert.assertEquals(diagonal[1], ed.getRealEigenvalue(2), 2.0e-15);
         Assert.assertEquals(diagonal[2], ed.getRealEigenvalue(1), 2.0e-15);
@@ -363,7 +381,8 @@ public class EigenDecompositionImplTest 
                 {2,  0,  2},
                 {4,  2,  3}
         });
-        EigenDecomposition ed = new EigenDecompositionImpl(repeated, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(repeated, MathUtils.SAFE_MIN);
         checkEigenValues((new double[] {8, -1, -1}), ed, 1E-12);
         checkEigenVector((new double[] {2, 1, 2}), ed, 1E-12);
     }
@@ -378,7 +397,8 @@ public class EigenDecompositionImplTest 
                 {1, 3, -4},
                 {-4, -4, 8}
         });
-        EigenDecomposition ed = new EigenDecompositionImpl(distinct, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(distinct, MathUtils.SAFE_MIN);
         checkEigenValues((new double[] {2, 0, 12}), ed, 1E-12);
         checkEigenVector((new double[] {1, -1, 0}), ed, 1E-12);
         checkEigenVector((new double[] {1, 1, 1}), ed, 1E-12);
@@ -395,7 +415,8 @@ public class EigenDecompositionImplTest 
                 { 1.0, 1.0, 0.0 },
                 { -1.0,0.0, 1.0 }
         });
-        EigenDecomposition ed = new EigenDecompositionImpl(indefinite, MathUtils.SAFE_MIN);
+        EigenDecompositionImpl ed;
+        ed = new EigenDecompositionImpl(indefinite, MathUtils.SAFE_MIN);
         checkEigenValues((new double[] {2, 1, -1}), ed, 1E-12);
         double isqrt3 = 1/FastMath.sqrt(3.0);
         checkEigenVector((new double[] {isqrt3,isqrt3,-isqrt3}), ed, 1E-12);
@@ -410,7 +431,7 @@ public class EigenDecompositionImplTest 
      * values to differ by tolerance.
      */
     protected void checkEigenValues(double[] targetValues,
-            EigenDecomposition ed, double tolerance) {
+            EigenDecompositionImpl ed, double tolerance) {
         double[] observed = ed.getRealEigenvalues();
         for (int i = 0; i < observed.length; i++) {
             Assert.assertTrue(isIncludedValue(observed[i], targetValues, tolerance));
@@ -442,7 +463,7 @@ public class EigenDecompositionImplTest 
      * used to find vectors in one-dimensional eigenspaces.
      */
     protected void checkEigenVector(double[] eigenVector,
-            EigenDecomposition ed, double tolerance) {
+            EigenDecompositionImpl ed, double tolerance) {
         Assert.assertTrue(isIncludedColumn(eigenVector, ed.getV(), tolerance));
     }
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenSolverTest.java?rev=1173964&r1=1173963&r2=1173964&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenSolverTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/EigenSolverTest.java
Thu Sep 22 06:37:41 2011
@@ -32,7 +32,7 @@ public class EigenSolverTest {
     public void testNonInvertible() {
         Random r = new Random(9994100315209l);
         RealMatrix m =
-            EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.0, -1.0,
-2.0, -3.0 });
+            EigenDecompositionTest.createTestMatrix(r, new double[] { 1.0, 0.0, -1.0, -2.0,
-3.0 });
         DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
         Assert.assertFalse(es.isNonSingular());
         try {
@@ -48,7 +48,7 @@ public class EigenSolverTest {
     public void testInvertible() {
         Random r = new Random(9994100315209l);
         RealMatrix m =
-            EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.5, -1.0,
-2.0, -3.0 });
+            EigenDecompositionTest.createTestMatrix(r, new double[] { 1.0, 0.5, -1.0, -2.0,
-3.0 });
         DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
         Assert.assertTrue(es.isNonSingular());
         RealMatrix inverse = es.getInverse();
@@ -63,7 +63,7 @@ public class EigenSolverTest {
         final double[] refValues = new double[] {
             2.003, 2.002, 2.001, 1.001, 1.000, 0.001
         };
-        final RealMatrix matrix = EigenDecompositionImplTest.createTestMatrix(new Random(35992629946426l),
refValues);
+        final RealMatrix matrix = EigenDecompositionTest.createTestMatrix(new Random(35992629946426l),
refValues);
 
         DecompositionSolver es = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN).getSolver();
         RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SingularValueDecompositionImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SingularValueDecompositionImplTest.java?rev=1173964&r1=1173963&r2=1173964&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SingularValueDecompositionImplTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SingularValueDecompositionImplTest.java
Thu Sep 22 06:37:41 2011
@@ -308,11 +308,11 @@ public class SingularValueDecompositionI
     private RealMatrix createTestMatrix(final Random r, final int rows, final int columns,
                                         final double[] singularValues) {
         final RealMatrix u =
-            EigenDecompositionImplTest.createOrthogonalMatrix(r, rows);
+            EigenDecompositionTest.createOrthogonalMatrix(r, rows);
         final RealMatrix d =
-            EigenDecompositionImplTest.createDiagonalMatrix(singularValues, rows, columns);
+            EigenDecompositionTest.createDiagonalMatrix(singularValues, rows, columns);
         final RealMatrix v =
-            EigenDecompositionImplTest.createOrthogonalMatrix(r, columns);
+            EigenDecompositionTest.createOrthogonalMatrix(r, columns);
         return u.multiply(d).multiply(v);
     }
 



Mime
View raw message