commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r773230 - /commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java
Date Sat, 09 May 2009 15:05:42 GMT
Author: luc
Date: Sat May  9 15:05:42 2009
New Revision: 773230

URL: http://svn.apache.org/viewvc?rev=773230&view=rev
Log:
check computed variances in test

Modified:
    commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java?rev=773230&r1=773229&r2=773230&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/stat/regression/OLSMultipleLinearRegressionTest.java
Sat May  9 15:05:42 2009
@@ -19,8 +19,11 @@
 import static org.junit.Assert.assertEquals;
 
 import org.apache.commons.math.TestUtils;
+import org.apache.commons.math.linear.DefaultRealMatrixChangingVisitor;
 import org.apache.commons.math.linear.MatrixUtils;
+import org.apache.commons.math.linear.MatrixVisitorException;
 import org.apache.commons.math.linear.RealMatrix;
+import org.apache.commons.math.linear.RealMatrixImpl;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -82,13 +85,30 @@
     public void testPerfectFit() {
         double[] betaHat = regression.estimateRegressionParameters();
         TestUtils.assertEquals(betaHat, 
-          new double[]{11.0,0.5,0.666666666666667,0.75,0.8,0.8333333333333333},
-                1e-12);
+                               new double[]{ 11.0, 1.0 / 2.0, 2.0 / 3.0, 3.0 / 4.0, 4.0 /
5.0, 5.0 / 6.0 },
+                               1e-14);
         double[] residuals = regression.estimateResiduals();
         TestUtils.assertEquals(residuals, new double[]{0d,0d,0d,0d,0d,0d},
-                      1e-12);
-        double[][] errors = regression.estimateRegressionParametersVariance();
-        // TODO: translate this into standard error vector and check
+                               1e-14);
+        RealMatrix errors =
+            new RealMatrixImpl(regression.estimateRegressionParametersVariance(), false);
+        final double[] s = { 1.0, -1.0 /  2.0, -1.0 /  3.0, -1.0 /  4.0, -1.0 /  5.0, -1.0
/  6.0 };
+        RealMatrix referenceVariance = new RealMatrixImpl(s.length, s.length);
+        referenceVariance.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() {
+            private static final long serialVersionUID = -6071126933773694288L;
+            @Override
+            public double visit(int row, int column, double value)
+                throws MatrixVisitorException {
+                if (row == 0) {
+                    return s[column];
+                }
+                double x = s[row] * s[column];
+                return (row == column) ? 2 * x : x;
+            }
+        });
+       assertEquals(0.0,
+                     errors.subtract(referenceVariance).getNorm(),
+                     5.0e-16 * referenceVariance.getNorm());
     }
     
     



Mime
View raw message