Fixed bracketing interval balancing in BracketingNthOrderBrentSolver.

Jira: MATH-716

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1209307 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2011-12-01 23:24:36 +00:00
parent b241c3962f
commit faa7785779
3 changed files with 27 additions and 3 deletions

View File

@ -232,10 +232,16 @@ public class BracketingNthOrderBrentSolver
double targetY; double targetY;
if (agingA >= MAXIMAL_AGING) { if (agingA >= MAXIMAL_AGING) {
// we keep updating the high bracket, try to compensate this // we keep updating the high bracket, try to compensate this
targetY = -REDUCTION_FACTOR * yB; final int p = agingA - MAXIMAL_AGING;
final double weightA = (1 << p) - 1;
final double weightB = p + 1;
targetY = (weightA * yA - weightB * REDUCTION_FACTOR * yB) / (weightA + weightB);
} else if (agingB >= MAXIMAL_AGING) { } else if (agingB >= MAXIMAL_AGING) {
// we keep updating the low bracket, try to compensate this // we keep updating the low bracket, try to compensate this
targetY = -REDUCTION_FACTOR * yA; final int p = agingB - MAXIMAL_AGING;
final double weightA = p + 1;
final double weightB = (1 << p) - 1;
targetY = (weightB * yB - weightA * REDUCTION_FACTOR * yA) / (weightA + weightB);
} else { } else {
// bracketing is balanced, try to find the root itself // bracketing is balanced, try to find the root itself
targetY = 0; targetY = 0;

View File

@ -52,6 +52,9 @@ The <action> type attribute can be add,update,fix,remove.
If the output is not quite correct, check for invisible trailing spaces! If the output is not quite correct, check for invisible trailing spaces!
--> -->
<release version="3.0" date="TBD" description="TBD"> <release version="3.0" date="TBD" description="TBD">
<action dev="luc" type="fix" issue="MATH-716">
Fixed bracketing interval balancing in BracketingNthOrderBrentSolver.
</action>
<action dev="erans" type="fix" issue="MATH-690"> <action dev="erans" type="fix" issue="MATH-690">
Removed unused or duplicate utility methods from "MathUtils". Removed unused or duplicate utility methods from "MathUtils".
Math functions with "double" arguments were moved to class "FastMath". Math functions with "double" arguments were moved to class "FastMath".

View File

@ -41,7 +41,7 @@ public final class BracketingNthOrderBrentSolverTest extends BaseSecantSolverAbs
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected int[] getQuinticEvalCounts() { protected int[] getQuinticEvalCounts() {
return new int[] {1, 3, 8, 1, 9, 4, 8, 1, 12, 1, 14}; return new int[] {1, 3, 8, 1, 9, 4, 8, 1, 12, 1, 16};
} }
@Test(expected=NumberIsTooSmallException.class) @Test(expected=NumberIsTooSmallException.class)
@ -81,6 +81,21 @@ public final class BracketingNthOrderBrentSolverTest extends BaseSecantSolverAbs
Assert.assertTrue(result + 0.5 < -solver.getAbsoluteAccuracy()); Assert.assertTrue(result + 0.5 < -solver.getAbsoluteAccuracy());
} }
@Test
public void testIssue716() {
BracketingNthOrderBrentSolver solver =
new BracketingNthOrderBrentSolver(1.0e-12, 1.0e-10, 1.0e-22, 5);
UnivariateFunction sharpTurn = new UnivariateFunction() {
public double value(double x) {
return (2 * x + 1) / (1.0e9 * (x + 1));
}
};
double result = solver.solve(100, sharpTurn, -0.9999999, 30, 15, AllowedSolution.RIGHT_SIDE);
Assert.assertEquals(0, sharpTurn.value(result), solver.getFunctionValueAccuracy());
Assert.assertTrue(sharpTurn.value(result) >= 0);
Assert.assertEquals(-0.5, result, 1.0e-10);
}
@Test @Test
public void testFasterThanNewton() { public void testFasterThanNewton() {
// the following test functions come from Beny Neta's paper: // the following test functions come from Beny Neta's paper: