commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1167612 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java site/xdoc/changes.xml
Date Sat, 10 Sep 2011 21:53:50 GMT
Author: erans
Date: Sat Sep 10 21:53:49 2011
New Revision: 1167612

URL: http://svn.apache.org/viewvc?rev=1167612&view=rev
Log:
MATH-664
Allow to pass a singularity threshold value to "getCovariances".

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

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=1167612&r1=1167611&r2=1167612&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
Sat Sep 10 21:53:49 2011
@@ -23,8 +23,8 @@ import org.apache.commons.math.analysis.
 import org.apache.commons.math.analysis.MultivariateMatrixFunction;
 import org.apache.commons.math.exception.util.LocalizedFormats;
 import org.apache.commons.math.linear.LUDecompositionImpl;
+import org.apache.commons.math.linear.DecompositionSolver;
 import org.apache.commons.math.linear.MatrixUtils;
-import org.apache.commons.math.linear.RealMatrix;
 import org.apache.commons.math.optimization.ConvergenceChecker;
 import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer;
 import org.apache.commons.math.optimization.VectorialPointValuePair;
@@ -51,6 +51,8 @@ import org.apache.commons.math.util.Fast
 public abstract class AbstractLeastSquaresOptimizer
     extends BaseAbstractVectorialOptimizer<DifferentiableMultivariateVectorialFunction>
     implements DifferentiableMultivariateVectorialOptimizer {
+    /** Singularity threshold (cf. {@link #getCovariances(double)}). */
+    private static final double DEFAULT_SINGULARITY_THRESHOLD = 1e-14;
     /**
      * Jacobian matrix of the weighted residuals.
      * This matrix is in canonical form just after the calls to
@@ -180,10 +182,22 @@ public abstract class AbstractLeastSquar
      * if the covariance matrix cannot be computed (singular problem).
      */
     public double[][] getCovariances() {
-        // set up the jacobian
+        return getCovariances(DEFAULT_SINGULARITY_THRESHOLD);
+    }
+
+    /**
+     * Get the covariance matrix of the optimized parameters.
+     *
+     * @param threshold Singularity threshold.
+     * @return the covariance matrix.
+     * @throws org.apache.commons.math.linear.SingularMatrixException
+     * if the covariance matrix cannot be computed (singular problem).
+     */
+    public double[][] getCovariances(double threshold) {
+        // Set up the jacobian.
         updateJacobian();
 
-        // compute transpose(J).J, avoiding building big intermediate matrices
+        // Compute transpose(J)J, without building intermediate matrices.
         double[][] jTj = new double[cols][cols];
         for (int i = 0; i < cols; ++i) {
             for (int j = i; j < cols; ++j) {
@@ -196,10 +210,10 @@ public abstract class AbstractLeastSquar
             }
         }
 
-        // compute the covariances matrix
-        RealMatrix inverse =
-            new LUDecompositionImpl(MatrixUtils.createRealMatrix(jTj)).getSolver().getInverse();
-        return inverse.getData();
+        // Compute the covariances matrix.
+        final DecompositionSolver solver
+            = new LUDecompositionImpl(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=1167612&r1=1167611&r2=1167612&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sat Sep 10 21:53:49 2011
@@ -52,6 +52,10 @@ 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="erans" type="fix" issue="MATH-664">
+        In class "AbstractLeastSquaresOptimizer": Allow to specify a singularity
+        threshold in call to "getCovariances" method.
+      </action>
       <action dev="gregs" type="fix" issue="MATH-649">
         Added the ability to suppress the estimation of the intercept.
       </action>



Mime
View raw message