Author: luc
Date: Thu Dec 1 23:24:36 2011
New Revision: 1209307
URL: http://svn.apache.org/viewvc?rev=1209307&view=rev
Log:
Fixed bracketing interval balancing in BracketingNthOrderBrentSolver.
Jira: MATH-716
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketingNthOrderBrentSolver.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BracketingNthOrderBrentSolverTest.java
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketingNthOrderBrentSolver.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketingNthOrderBrentSolver.java?rev=1209307&r1=1209306&r2=1209307&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketingNthOrderBrentSolver.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketingNthOrderBrentSolver.java
Thu Dec 1 23:24:36 2011
@@ -232,10 +232,16 @@ public class BracketingNthOrderBrentSolv
double targetY;
if (agingA >= MAXIMAL_AGING) {
// 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) {
// 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 {
// bracketing is balanced, try to find the root itself
targetY = 0;
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=1209307&r1=1209306&r2=1209307&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Thu Dec 1 23:24:36 2011
@@ -52,6 +52,9 @@ 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="luc" type="fix" issue="MATH-716">
+ Fixed bracketing interval balancing in BracketingNthOrderBrentSolver.
+ </action>
<action dev="erans" type="fix" issue="MATH-690">
Removed unused or duplicate utility methods from "MathUtils".
Math functions with "double" arguments were moved to class "FastMath".
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BracketingNthOrderBrentSolverTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BracketingNthOrderBrentSolverTest.java?rev=1209307&r1=1209306&r2=1209307&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BracketingNthOrderBrentSolverTest.java
(original)
+++
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/BracketingNthOrderBrentSolverTest.java
Thu Dec 1 23:24:36 2011
@@ -41,7 +41,7 @@ public final class BracketingNthOrderBre
/** {@inheritDoc} */
@Override
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)
@@ -82,6 +82,21 @@ public final class BracketingNthOrderBre
}
@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
public void testFasterThanNewton() {
// the following test functions come from Beny Neta's paper:
// "Several New Methods for solving Equations"