fixed a bracketing issue due to inconsistent checks
JIRA: MATH-280 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@791766 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
26281773d8
commit
b9d8c68e2f
|
@ -131,7 +131,7 @@ public class UnivariateRealSolverUtils {
|
|||
/**
|
||||
* This method attempts to find two values a and b satisfying <ul>
|
||||
* <li> <code> lowerBound <= a < initial < b <= upperBound</code> </li>
|
||||
* <li> <code> f(a) * f(b) < 0 </code> </li>
|
||||
* <li> <code> f(a) * f(b) <= 0 </code> </li>
|
||||
* </ul>
|
||||
* If f is continuous on <code>[a,b],</code> this means that <code>a</code>
|
||||
* and <code>b</code> bracket a root of f.
|
||||
|
@ -141,7 +141,7 @@ public class UnivariateRealSolverUtils {
|
|||
* function at <code>a</code> and <code>b</code> and keeps moving
|
||||
* the endpoints out by one unit each time through a loop that terminates
|
||||
* when one of the following happens: <ul>
|
||||
* <li> <code> f(a) * f(b) < 0 </code> -- success!</li>
|
||||
* <li> <code> f(a) * f(b) <= 0 </code> -- success!</li>
|
||||
* <li> <code> a = lower </code> and <code> b = upper</code>
|
||||
* -- ConvergenceException </li>
|
||||
* <li> <code> maximumIterations</code> iterations elapse
|
||||
|
@ -195,7 +195,7 @@ public class UnivariateRealSolverUtils {
|
|||
} while ((fa * fb > 0.0) && (numIterations < maximumIterations) &&
|
||||
((a > lowerBound) || (b < upperBound)));
|
||||
|
||||
if (fa * fb >= 0.0 ) {
|
||||
if (fa * fb > 0.0 ) {
|
||||
throw new ConvergenceException(
|
||||
"number of iterations={0}, maximum iterations={1}, " +
|
||||
"initial={2}, lower bound={3}, upper bound={4}, final a value={5}, " +
|
||||
|
|
|
@ -65,7 +65,7 @@ public abstract class AbstractContinuousDistribution
|
|||
}
|
||||
|
||||
// by default, do simple root finding using bracketing and default solver.
|
||||
// subclasses can overide if there is a better method.
|
||||
// subclasses can override if there is a better method.
|
||||
UnivariateRealFunction rootFindingFunction =
|
||||
new UnivariateRealFunction() {
|
||||
public double value(double x) throws FunctionEvaluationException {
|
||||
|
|
|
@ -39,6 +39,9 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
</properties>
|
||||
<body>
|
||||
<release version="2.0" date="TBD" description="TBD">
|
||||
<action dev="luc" type="fix" issue="MATH-280">
|
||||
Fixed a bracketing issue in inverse cumulative probability computation
|
||||
</action>
|
||||
<action dev="luc" type="add" issue="MATH-279" due-to="Michael Bjorkegren">
|
||||
Added a check for too few rows with respect to the number of predictors in linear regression
|
||||
</action>
|
||||
|
|
|
@ -17,13 +17,12 @@
|
|||
|
||||
package org.apache.commons.math.analysis.solvers;
|
||||
|
||||
import org.apache.commons.math.ConvergenceException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.math.MathException;
|
||||
import org.apache.commons.math.analysis.SinFunction;
|
||||
import org.apache.commons.math.analysis.UnivariateRealFunction;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
|
@ -91,15 +90,6 @@ public class UnivariateRealSolverUtilsTest extends TestCase {
|
|||
assertTrue(sin.value(result[1]) > 0);
|
||||
}
|
||||
|
||||
public void testBracketCornerSolution() throws MathException {
|
||||
try {
|
||||
UnivariateRealSolverUtils.bracket(sin, 1.5, 0, 2.0);
|
||||
fail("Expecting ConvergenceException");
|
||||
} catch (ConvergenceException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testBadParameters() throws MathException {
|
||||
try { // null function
|
||||
UnivariateRealSolverUtils.bracket(null, 1.5, 0, 2.0);
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.apache.commons.math.distribution;
|
||||
|
||||
import org.apache.commons.math.MathException;
|
||||
|
||||
/**
|
||||
* Test cases for NormalDistribution.
|
||||
* Extends ContinuousDistributionAbstractTest. See class javadoc for
|
||||
|
@ -161,4 +163,11 @@ public class NormalDistributionTest extends ContinuousDistributionAbstractTest
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testMath280() throws MathException {
|
||||
NormalDistribution normal = new NormalDistributionImpl(0,1);
|
||||
double result = normal.inverseCumulativeProbability(0.9772498680518209);
|
||||
assertEquals(2.0, result, 1.0e-12);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue