Skip to content

Commit

Permalink
MATH-956
Browse files Browse the repository at this point in the history
Replaced hard-coded numbers with constants from class "Precision".


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1461197 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Gilles Sadowski committed Mar 26, 2013
1 parent e4c91be commit bb8a2a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ This is a minor release: It combines bug fixes and new features.
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
*/
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. */
Expand Down Expand Up @@ -518,14 +520,15 @@ protected PointVectorValuePair doOptimize() {
}

// 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);
}
Expand Down Expand Up @@ -630,8 +633,7 @@ private void determineLMParameter(double[] qy, double delta, double[] diag,
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),
Expand All @@ -645,7 +647,7 @@ private void determineLMParameter(double[] qy, double delta, double[] diag,

// 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) {
Expand Down

0 comments on commit bb8a2a6

Please sign in to comment.