You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Joris (JIRA)" <ji...@apache.org> on 2010/03/25 16:23:27 UTC

[jira] Created: (MATH-359) Normal Distribution implementation gives false cumulative probabilities

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.


[jira] Commented: (MATH-359) Normal Distribution implementation gives false cumulative probabilities

Posted by "Christian Winter (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12856335#action_12856335 ] 

Christian Winter commented on MATH-359:
---------------------------------------

This issue is has the reason as [Math-282|https://issues.apache.org/jira/browse/MATH-282] and is resolved in Version 2.1. Thus it can be closed.

> 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.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Closed: (MATH-359) Normal Distribution implementation gives false cumulative probabilities

Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-359?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Steitz closed MATH-359.
----------------------------

    Resolution: Duplicate

Duplicates MATH-282

> 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.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (MATH-359) Normal Distribution implementation gives false cumulative probabilities

Posted by "Roman Werpachowski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852790#action_12852790 ] 

Roman Werpachowski commented on MATH-359:
-----------------------------------------

The problem arises from the way Normal Gaussian CDF is computed in ACM: via an iterative computation of the Gamma function. It is better, I think, to use a specialized approximation for the Normal Gaussian CDF, such as (highly accurate) http://www.netlib.org/specfun/erf. I checked that for the arguments given it simply returns 1.

> 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.