You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2012/01/18 12:56:48 UTC

svn commit: r1232846 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/linear/ main/java/org/apache/commons/math/optimization/general/ site/xdoc/ test/java/org/apache/commons/math/optimization/general/

Author: erans
Date: Wed Jan 18 11:56:48 2012
New Revision: 1232846

URL: http://svn.apache.org/viewvc?rev=1232846&view=rev
Log:
MATH-664
Replaced "LUDecomposition" by "QRDecomposition" in the covariance matrix
computation.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/QRDecomposition.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/QRDecomposition.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/QRDecomposition.java?rev=1232846&r1=1232845&r2=1232846&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/QRDecomposition.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/QRDecomposition.java Wed Jan 18 11:56:48 2012
@@ -177,7 +177,7 @@ public class QRDecomposition {
             // R is supposed to be m x n
             final int n = qrt.length;
             final int m = qrt[0].length;
-            double[][] ra = new double[m][n];         
+            double[][] ra = new double[m][n];
             // copy the diagonal from rDiag and the upper triangle of qr
             for (int row = FastMath.min(m, n) - 1; row >= 0; row--) {
                 ra[row][row] = rDiag[row];

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java?rev=1232846&r1=1232845&r2=1232846&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java Wed Jan 18 11:56:48 2012
@@ -22,7 +22,7 @@ import org.apache.commons.math.exception
 import org.apache.commons.math.analysis.DifferentiableMultivariateVectorFunction;
 import org.apache.commons.math.analysis.MultivariateMatrixFunction;
 import org.apache.commons.math.exception.util.LocalizedFormats;
-import org.apache.commons.math.linear.LUDecomposition;
+import org.apache.commons.math.linear.QRDecomposition;
 import org.apache.commons.math.linear.DecompositionSolver;
 import org.apache.commons.math.linear.MatrixUtils;
 import org.apache.commons.math.optimization.ConvergenceChecker;
@@ -180,6 +180,8 @@ public abstract class AbstractLeastSquar
      * @return the covariance matrix.
      * @throws org.apache.commons.math.linear.SingularMatrixException
      * if the covariance matrix cannot be computed (singular problem).
+     *
+     * @see #getCovriances(double)
      */
     public double[][] getCovariances() {
         return getCovariances(DEFAULT_SINGULARITY_THRESHOLD);
@@ -187,6 +189,13 @@ public abstract class AbstractLeastSquar
 
     /**
      * Get the covariance matrix of the optimized parameters.
+     * <br/>
+     * Note that this operation involves the inversion of the
+     * <code>J<sup>T</sup>J</code> matrix, where {@code J} is the
+     * Jacobian matrix.
+     * The {@code threshold} parameter is a way for the caller to specify
+     * that the result of this computation should be considered meaningless,
+     * and thus trigger an exception.
      *
      * @param threshold Singularity threshold.
      * @return the covariance matrix.
@@ -212,7 +221,7 @@ public abstract class AbstractLeastSquar
 
         // Compute the covariances matrix.
         final DecompositionSolver solver
-            = new LUDecomposition(MatrixUtils.createRealMatrix(jTj), threshold).getSolver();
+            = new QRDecomposition(MatrixUtils.createRealMatrix(jTj), threshold).getSolver();
         return solver.getInverse().getData();
     }
 

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1232846&r1=1232845&r2=1232846&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Wed Jan 18 11:56:48 2012
@@ -52,7 +52,12 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
-      <action dev="psteitz" type="fixe" issue="MATH-724" due-to="Dennis Hendriks">
+      <action dev="erans" type="fix" issue="MATH-664">
+        Changed algorithm in computation of the covariance matrix in
+        "AbstractLeastSquares" (package "optimization.general"), from
+        "LUDecomposition" to "QRDecomposition".
+      </action>
+      <action dev="psteitz" type="fix" issue="MATH-724" due-to="Dennis Hendriks">
         Fixed rounding error in RandomDataImpl nextInt, nextLong methods causing lower
         endpoints to be excluded when negative. Also improved robustness of nextUniform
         for extreme values and changed its contract to throw IAE when provided bounds

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java?rev=1232846&r1=1232845&r2=1232846&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java Wed Jan 18 11:56:48 2012
@@ -216,7 +216,9 @@ public class LevenbergMarquardtOptimizer
                              new double[] { 0, 0, 0 });
         Assert.assertTrue(FastMath.sqrt(problem.target.length) * optimizer.getRMS() > 0.6);
 
-        optimizer.getCovariances();
+        // The default singularity threshold (1e-14) does not trigger the
+        // expected exception.
+        double[][] cov = optimizer.getCovariances(1.5e-14);
     }
 
     @Test