Normal Distribution implementation gives false cumulative probabilities
-----------------------------------------------------------------------
Key: MATH-359
URL: https://issues.apache.org/jira/browse/MATH-359
Project: Commons Math
Issue Type: Bug
Environment: Ubuntu Linux
Reporter: Joris
Priority: Minor
Package: org.apache.commons.math.distribution
Class: NormalDistributionImpl
For a given mean and standard deviation, the class NormalDistributionImpl
implements a normal distribution. Per definition, the function
cumulativeProbability(double x) should return a value on the interval <0,1> (0
and 1 excluded), for any real value of x. However, the following test case
shows that the method cumulativeProbability(double x) gives for some values
wrong results:
NormalDistributionImpl ncdf=new
NormalDistributionImpl(0.06848215242239623,0.21287763557454142);
try{
System.out.println("Test:
"+ncdf.cumulativeProbability(2.636630902183101));
}catch(MathException e){ System.out.println("Exception has occurred: "+e);}
Result:
Test: 1.0000000000000064
Only in the case where x=Double.POSITIVE_INFINITY,
cumulativeProbability(double x) should return 1. For all other values of x, the
result should be <1.
The weird result from the above test case is quite likely caused by the data
type double. The 2 most straight forward ways to fix this behavior:
1. Use a more accurate data type
2. Build in checks which prevent bad results like:
if(x==Double.POSITIVE_INFINITY)
return 1;
else if(x==Double.NEGATIVE_INFINITY)
return 0;
else if(result >=1)
return 0.9999999999999; //A constant value which is stored correctly by a
double
else if(result <=0)
return 0.0000000000001;
Nevertheless, I believe that this issue should be noted in the Javadoc of the
NormalDistributionImpl class.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.