You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2008/12/20 01:03:15 UTC

svn commit: r728186 [2/2] - in /commons/proper/math/trunk/src: java/org/apache/commons/math/estimation/ java/org/apache/commons/math/linear/ java/org/apache/commons/math/random/ java/org/apache/commons/math/stat/descriptive/moment/ java/org/apache/comm...

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SingularValueDecompositionImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SingularValueDecompositionImplTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SingularValueDecompositionImplTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SingularValueDecompositionImplTest.java Fri Dec 19 16:03:13 2008
@@ -79,7 +79,7 @@
 
     /** test dimensions */
     public void testDimensions() {
-        RealMatrixImpl matrix = new RealMatrixImpl(testSquare, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(testSquare);
         final int m = matrix.getRowDimension();
         final int n = matrix.getColumnDimension();
         SingularValueDecomposition svd = new SingularValueDecompositionImpl(matrix);
@@ -94,9 +94,9 @@
 
     /** test A = USVt */
     public void testAEqualUSVt() {
-        checkAEqualUSVt(new RealMatrixImpl(testSquare, false));
-        checkAEqualUSVt(new RealMatrixImpl(testNonSquare, false));
-        checkAEqualUSVt(new RealMatrixImpl(testNonSquare, false).transpose());
+        checkAEqualUSVt(MatrixUtils.createRealMatrix(testSquare));
+        checkAEqualUSVt(MatrixUtils.createRealMatrix(testNonSquare));
+        checkAEqualUSVt(MatrixUtils.createRealMatrix(testNonSquare).transpose());
     }
 
     public void checkAEqualUSVt(final RealMatrix matrix) {
@@ -111,16 +111,16 @@
 
     /** test that U is orthogonal */
     public void testUOrthogonal() {
-        checkOrthogonal(new SingularValueDecompositionImpl(new RealMatrixImpl(testSquare, false)).getU());
-        checkOrthogonal(new SingularValueDecompositionImpl(new RealMatrixImpl(testNonSquare, false)).getU());
-        checkOrthogonal(new SingularValueDecompositionImpl(new RealMatrixImpl(testNonSquare, false).transpose()).getU());
+        checkOrthogonal(new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare)).getU());
+        checkOrthogonal(new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testNonSquare)).getU());
+        checkOrthogonal(new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testNonSquare).transpose()).getU());
     }
 
     /** test that V is orthogonal */
     public void testVOrthogonal() {
-        checkOrthogonal(new SingularValueDecompositionImpl(new RealMatrixImpl(testSquare, false)).getV());
-        checkOrthogonal(new SingularValueDecompositionImpl(new RealMatrixImpl(testNonSquare, false)).getV());
-        checkOrthogonal(new SingularValueDecompositionImpl(new RealMatrixImpl(testNonSquare, false).transpose()).getV());
+        checkOrthogonal(new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare)).getV());
+        checkOrthogonal(new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testNonSquare)).getV());
+        checkOrthogonal(new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testNonSquare).transpose()).getV());
     }
 
     public void checkOrthogonal(final RealMatrix m) {
@@ -132,16 +132,16 @@
     /** test matrices values */
     public void testMatricesValues1() {
        SingularValueDecomposition svd =
-            new SingularValueDecompositionImpl(new RealMatrixImpl(testSquare, false));
-        RealMatrix uRef = new RealMatrixImpl(new double[][] {
+            new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare));
+        RealMatrix uRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 3.0 / 5.0, -4.0 / 5.0 },
                 { 4.0 / 5.0,  3.0 / 5.0 }
         });
-        RealMatrix sRef = new RealMatrixImpl(new double[][] {
+        RealMatrix sRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 3.0, 0.0 },
                 { 0.0, 1.0 }
         });
-        RealMatrix vRef = new RealMatrixImpl(new double[][] {
+        RealMatrix vRef = MatrixUtils.createRealMatrix(new double[][] {
                 { 4.0 / 5.0,  3.0 / 5.0 },
                 { 3.0 / 5.0, -4.0 / 5.0 }
         });
@@ -164,18 +164,18 @@
     /** test matrices values */
     public void testMatricesValues2() {
 
-        RealMatrix uRef = new RealMatrixImpl(new double[][] {
+        RealMatrix uRef = MatrixUtils.createRealMatrix(new double[][] {
             {  0.0 / 5.0,  3.0 / 5.0,  0.0 / 5.0 },
             { -4.0 / 5.0,  0.0 / 5.0, -3.0 / 5.0 },
             {  0.0 / 5.0,  4.0 / 5.0,  0.0 / 5.0 },
             { -3.0 / 5.0,  0.0 / 5.0,  4.0 / 5.0 }
         });
-        RealMatrix sRef = new RealMatrixImpl(new double[][] {
+        RealMatrix sRef = MatrixUtils.createRealMatrix(new double[][] {
             { 4.0, 0.0, 0.0 },
             { 0.0, 3.0, 0.0 },
             { 0.0, 0.0, 2.0 }
         });
-        RealMatrix vRef = new RealMatrixImpl(new double[][] {
+        RealMatrix vRef = MatrixUtils.createRealMatrix(new double[][] {
             {  80.0 / 125.0,  -60.0 / 125.0, 75.0 / 125.0 },
             {  24.0 / 125.0,  107.0 / 125.0, 60.0 / 125.0 },
             { -93.0 / 125.0,  -24.0 / 125.0, 80.0 / 125.0 }
@@ -183,7 +183,7 @@
 
         // check values against known references
         SingularValueDecomposition svd =
-            new SingularValueDecompositionImpl(new RealMatrixImpl(testNonSquare, false));
+            new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testNonSquare));
         RealMatrix u = svd.getU();
         assertEquals(0, u.subtract(uRef).getNorm(), normTolerance);
         RealMatrix s = svd.getS();
@@ -201,7 +201,7 @@
     /** test condition number */
     public void testConditionNumber() {
         SingularValueDecompositionImpl svd =
-            new SingularValueDecompositionImpl(new RealMatrixImpl(testSquare, false));
+            new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare));
         assertEquals(3.0, svd.getConditionNumber(), 1.0e-15);
     }
 

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SingularValueSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SingularValueSolverTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SingularValueSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/SingularValueSolverTest.java Fri Dec 19 16:03:13 2008
@@ -43,8 +43,8 @@
     /** test solve dimension errors */
     public void testSolveDimensionErrors() {
         SingularValueSolver solver =
-            new SingularValueSolver(new SingularValueDecompositionImpl(new RealMatrixImpl(testSquare, false)));
-        RealMatrix b = new RealMatrixImpl(new double[3][2]);
+            new SingularValueSolver(new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare)));
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[3][2]);
         try {
             solver.solve(b);
             fail("an exception should have been thrown");
@@ -74,12 +74,12 @@
     /** test solve singularity errors */
     public void testSolveSingularityErrors() {
         RealMatrix m =
-            new RealMatrixImpl(new double[][] {
+            MatrixUtils.createRealMatrix(new double[][] {
                                    { 1.0, 0.0 },
                                    { 0.0, 0.0 }
-                               }, false);
+                               });
         SingularValueSolver solver = new SingularValueSolver(new SingularValueDecompositionImpl(m));
-        RealMatrix b = new RealMatrixImpl(new double[2][2]);
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[2][2]);
         try {
             solver.solve(b);
             fail("an exception should have been thrown");
@@ -117,11 +117,11 @@
     /** test solve */
     public void testSolve() {
         SingularValueSolver solver =
-            new SingularValueSolver(new SingularValueDecompositionImpl(new RealMatrixImpl(testSquare, false)));
-        RealMatrix b = new RealMatrixImpl(new double[][] {
+            new SingularValueSolver(new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare)));
+        RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
                 { 1, 2, 3 }, { 0, -5, 1 }
         });
-        RealMatrix xRef = new RealMatrixImpl(new double[][] {
+        RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] {
                 { -8.0 / 25.0, -263.0 / 75.0, -29.0 / 75.0 },
                 { 19.0 / 25.0,   78.0 / 25.0,  49.0 / 25.0 }
         });
@@ -157,7 +157,7 @@
     /** test condition number */
     public void testConditionNumber() {
         SingularValueDecompositionImpl svd =
-            new SingularValueDecompositionImpl(new RealMatrixImpl(testSquare, false));
+            new SingularValueDecompositionImpl(MatrixUtils.createRealMatrix(testSquare));
         assertEquals(3.0, svd.getConditionNumber(), 1.0e-15);
     }
 

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/TriDiagonalTransformerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/TriDiagonalTransformerTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/TriDiagonalTransformerTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/TriDiagonalTransformerTest.java Fri Dec 19 16:03:13 2008
@@ -45,7 +45,7 @@
 
     public void testNonSquare() {
         try {
-            new TriDiagonalTransformer(new RealMatrixImpl(new double[3][2], false));
+            new TriDiagonalTransformer(MatrixUtils.createRealMatrix(new double[3][2]));
             fail("an exception should have been thrown");
         } catch (InvalidMatrixException ime) {
             // expected behavior
@@ -55,8 +55,8 @@
     }
 
     public void testAEqualQTQt() {
-        checkAEqualQTQt(new RealMatrixImpl(testSquare5, false));
-        checkAEqualQTQt(new RealMatrixImpl(testSquare3, false));
+        checkAEqualQTQt(MatrixUtils.createRealMatrix(testSquare5));
+        checkAEqualQTQt(MatrixUtils.createRealMatrix(testSquare3));
     }
 
     private void checkAEqualQTQt(RealMatrix matrix) {
@@ -79,23 +79,23 @@
             modifiedData[i] = data[i].clone();
             Arrays.fill(modifiedData[i], 0, i, Double.NaN);
         }
-        RealMatrix matrix = new RealMatrixImpl(modifiedData, false);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(modifiedData);
         TriDiagonalTransformer transformer = new TriDiagonalTransformer(matrix);
         RealMatrix q  = transformer.getQ();
         RealMatrix qT = transformer.getQT();
         RealMatrix t  = transformer.getT();
-        double norm = q.multiply(t).multiply(qT).subtract(new RealMatrixImpl(data, false)).getNorm();
+        double norm = q.multiply(t).multiply(qT).subtract(MatrixUtils.createRealMatrix(data)).getNorm();
         assertEquals(0, norm, 4.0e-15);
     }
 
     public void testQOrthogonal() {
-        checkOrthogonal(new TriDiagonalTransformer(new RealMatrixImpl(testSquare5, false)).getQ());
-        checkOrthogonal(new TriDiagonalTransformer(new RealMatrixImpl(testSquare3, false)).getQ());
+        checkOrthogonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare5)).getQ());
+        checkOrthogonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare3)).getQ());
     }
 
     public void testQTOrthogonal() {
-        checkOrthogonal(new TriDiagonalTransformer(new RealMatrixImpl(testSquare5, false)).getQT());
-        checkOrthogonal(new TriDiagonalTransformer(new RealMatrixImpl(testSquare3, false)).getQT());
+        checkOrthogonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare5)).getQT());
+        checkOrthogonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare3)).getQT());
     }
 
     private void checkOrthogonal(RealMatrix m) {
@@ -105,8 +105,8 @@
     }
 
     public void testTTriDiagonal() {
-        checkTriDiagonal(new TriDiagonalTransformer(new RealMatrixImpl(testSquare5, false)).getT());
-        checkTriDiagonal(new TriDiagonalTransformer(new RealMatrixImpl(testSquare3, false)).getT());
+        checkTriDiagonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare5)).getT());
+        checkTriDiagonal(new TriDiagonalTransformer(MatrixUtils.createRealMatrix(testSquare3)).getT());
     }
 
     private void checkTriDiagonal(RealMatrix m) {
@@ -149,11 +149,11 @@
                                      double[] mainDiagnonal,
                                      double[] secondaryDiagonal) {
         TriDiagonalTransformer transformer =
-            new TriDiagonalTransformer(new RealMatrixImpl(matrix, false));
+            new TriDiagonalTransformer(MatrixUtils.createRealMatrix(matrix));
 
         // check values against known references
         RealMatrix q = transformer.getQ();
-        assertEquals(0, q.subtract(new RealMatrixImpl(qRef, false)).getNorm(), 1.0e-14);
+        assertEquals(0, q.subtract(MatrixUtils.createRealMatrix(qRef)).getNorm(), 1.0e-14);
 
         RealMatrix t = transformer.getT();
         double[][] tData = new double[mainDiagnonal.length][mainDiagnonal.length];
@@ -166,7 +166,7 @@
                 tData[i][i + 1] = secondaryDiagonal[i];
             }
         }
-        assertEquals(0, t.subtract(new RealMatrixImpl(tData, false)).getNorm(), 1.0e-14);
+        assertEquals(0, t.subtract(MatrixUtils.createRealMatrix(tData)).getNorm(), 1.0e-14);
 
         // check the same cached instance is returned the second time
         assertTrue(q == transformer.getQ());

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java Fri Dec 19 16:03:13 2008
@@ -98,6 +98,7 @@
     } catch (ConvergenceException ce) {
         // expected behavior
     } catch (Exception e) {
+        e.printStackTrace(System.err);
         fail("wrong exception caught: " + e.getMessage());
     }
 

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/random/CorrelatedRandomVectorGeneratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/random/CorrelatedRandomVectorGeneratorTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/random/CorrelatedRandomVectorGeneratorTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/random/CorrelatedRandomVectorGeneratorTest.java Fri Dec 19 16:03:13 2008
@@ -17,14 +17,16 @@
 
 package org.apache.commons.math.random;
 
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
 import org.apache.commons.math.DimensionMismatchException;
+import org.apache.commons.math.linear.MatrixUtils;
 import org.apache.commons.math.linear.RealMatrix;
-import org.apache.commons.math.linear.RealMatrixImpl;
 import org.apache.commons.math.stat.descriptive.moment.VectorialCovariance;
 import org.apache.commons.math.stat.descriptive.moment.VectorialMean;
 
-import junit.framework.*;
-
 public class CorrelatedRandomVectorGeneratorTest
 extends TestCase {
 
@@ -48,7 +50,7 @@
                 { 2, 16, 38, -1 },
                 { 6, 2, -1, 197 }
         };
-        RealMatrix covRM = new RealMatrixImpl(cov, false);
+        RealMatrix covRM = MatrixUtils.createRealMatrix(cov);
         JDKRandomGenerator jg = new JDKRandomGenerator();
         jg.setSeed(5322145245211l);
         NormalizedRandomGenerator rg = new GaussianRandomGenerator(jg);
@@ -99,24 +101,21 @@
         try {
             mean = new double[] { 0.0, 1.0, -3.0, 2.3};
 
-            RealMatrixImpl b = new RealMatrixImpl(4, 3);
-            double[][] bData = b.getDataRef();
+            RealMatrix b = MatrixUtils.createRealMatrix(4, 3);
             int counter = 0;
-            for (int i = 0; i < bData.length; ++i) {
-                double[] bi = bData[i];
+            for (int i = 0; i < b.getRowDimension(); ++i) {
                 for (int j = 0; j < b.getColumnDimension(); ++j) {
-                    bi[j] = 1.0 + 0.1 * ++counter;
+                    b.setEntry(i, j, 1.0 + 0.1 * ++counter);
                 }
             }
             RealMatrix bbt = b.multiply(b.transpose());
-            covariance = new RealMatrixImpl(mean.length, mean.length);
-            double[][] covData = covariance.getDataRef();
+            covariance = MatrixUtils.createRealMatrix(mean.length, mean.length);
             for (int i = 0; i < covariance.getRowDimension(); ++i) {
-                covData[i][i] = bbt.getEntry(i, i);
+                covariance.setEntry(i, i, bbt.getEntry(i, i));
                 for (int j = 0; j < covariance.getColumnDimension(); ++j) {
                     double s = bbt.getEntry(i, j);
-                    covData[i][j] = s;
-                    covData[j][i] = s;
+                    covariance.setEntry(i, j, s);
+                    covariance.setEntry(j, i, s);
                 }
             }
 
@@ -145,7 +144,7 @@
     }
 
     private double[] mean;
-    private RealMatrixImpl covariance;
+    private RealMatrix covariance;
     private CorrelatedRandomVectorGenerator generator;
 
 }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/GLSMultipleLinearRegressionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/GLSMultipleLinearRegressionTest.java?rev=728186&r1=728185&r2=728186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/GLSMultipleLinearRegressionTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/GLSMultipleLinearRegressionTest.java Fri Dec 19 16:03:13 2008
@@ -63,7 +63,7 @@
         createRegression().newSampleData(y, x, null);
     }
     
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected=ArrayIndexOutOfBoundsException.class)
     public void cannotAddNullCovarianceData() {
         createRegression().newSampleData(new double[]{}, new double[][]{}, null);
     }