Author: erans Date: Tue Mar 26 16:01:09 2013 New Revision: 1461197 URL: http://svn.apache.org/r1461197 Log: MATH-956 Replaced hard-coded numbers with constants from class "Precision".
Modified: commons/proper/math/trunk/src/changes/changes.xml commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/LevenbergMarquardtOptimizer.java Modified: commons/proper/math/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1461197&r1=1461196&r2=1461197&view=diff ============================================================================== --- commons/proper/math/trunk/src/changes/changes.xml (original) +++ commons/proper/math/trunk/src/changes/changes.xml Tue Mar 26 16:01:09 2013 @@ -55,6 +55,9 @@ This is a minor release: It combines bug Changes to existing features were made in a backwards-compatible way such as to allow drop-in replacement of the v3.1[.1] JAR file. "> + <action dev="erans" type="update" issue="MATH-956"> + Replaced hard-coded numbers in "LevenbergMarquardtOptimizer". + </action> <action dev="luc" type="update" issue="MATH-955" due-to="Evan Ward"> Fixed loading of test file when path contains a space. </action> Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/LevenbergMarquardtOptimizer.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/LevenbergMarquardtOptimizer.java?rev=1461197&r1=1461196&r2=1461197&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/LevenbergMarquardtOptimizer.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/LevenbergMarquardtOptimizer.java Tue Mar 26 16:01:09 2013 @@ -112,6 +112,8 @@ import org.apache.commons.math3.util.Fas */ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer { + /** Twice the "epsilon machine". */ + private static final double TWO_EPS = 2 * Precision.EPSILON; /** Number of solved point. */ private int solvedCols; /** Diagonal elements of the R matrix in the Q.R. decomposition. */ @@ -518,14 +520,15 @@ public class LevenbergMarquardtOptimizer } // tests for termination and stringent tolerances - // (2.2204e-16 is the machine epsilon for IEEE754) - if ((FastMath.abs(actRed) <= 2.2204e-16) && (preRed <= 2.2204e-16) && (ratio <= 2.0)) { + if (FastMath.abs(actRed) <= TWO_EPS && + preRed <= TWO_EPS && + ratio <= 2.0) { throw new ConvergenceException(LocalizedFormats.TOO_SMALL_COST_RELATIVE_TOLERANCE, costRelativeTolerance); - } else if (delta <= 2.2204e-16 * xNorm) { + } else if (delta <= TWO_EPS * xNorm) { throw new ConvergenceException(LocalizedFormats.TOO_SMALL_PARAMETERS_RELATIVE_TOLERANCE, parRelativeTolerance); - } else if (maxCosine <= 2.2204e-16) { + } else if (maxCosine <= TWO_EPS) { throw new ConvergenceException(LocalizedFormats.TOO_SMALL_ORTHOGONALITY_TOLERANCE, orthoTolerance); } @@ -630,8 +633,7 @@ public class LevenbergMarquardtOptimizer double gNorm = FastMath.sqrt(sum2); double paru = gNorm / delta; if (paru == 0) { - // 2.2251e-308 is the smallest positive real for IEE754 - paru = 2.2251e-308 / FastMath.min(delta, 0.1); + paru = Precision.SAFE_MIN / FastMath.min(delta, 0.1); } // if the input par lies outside of the interval (parl,paru), @@ -645,7 +647,7 @@ public class LevenbergMarquardtOptimizer // evaluate the function at the current value of lmPar if (lmPar == 0) { - lmPar = FastMath.max(2.2251e-308, 0.001 * paru); + lmPar = FastMath.max(Precision.SAFE_MIN, 0.001 * paru); } double sPar = FastMath.sqrt(lmPar); for (int j = 0; j < solvedCols; ++j) {