mirror of
https://github.com/apache/commons-math.git
synced 2025-03-05 16:09:09 +00:00
MATH-956
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
This commit is contained in:
parent
e4c91be8c9
commit
bb8a2a68ec
@ -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>
|
||||
|
@ -112,6 +112,8 @@ import org.apache.commons.math3.util.FastMath;
|
||||
*/
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user