You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Zev Hochberg (JIRA)" <ji...@apache.org> on 2012/10/30 18:10:11 UTC

[jira] [Created] (MATH-888) GammaDistribution returns infinite density when cdf = 1

Zev Hochberg created MATH-888:
---------------------------------

             Summary: GammaDistribution returns infinite density when cdf = 1
                 Key: MATH-888
                 URL: https://issues.apache.org/jira/browse/MATH-888
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 3.0
         Environment: Windows 7
            Reporter: Zev Hochberg


When GammaDistribution.cumulativeProbability = 1, then GammaDistribution.density may return Infinite - but it should return 0.
Here is sample java code which demonstrates this issue, with results. Note that when pass the point at which cumulativeProbability = 1, the density stays > 0, though very small (pdf should be 0 when cdf = 1) - but as continue, then cdf stays 1, but pdf becomes infinite. This is seen most clearly in the second set of data below.


package ApacheTester;

import org.apache.commons.math3.distribution.GammaDistribution;

public class GammaDistributionTester
{
    public static void main(String[] args)
    {
        double mean = 10.118627813856065;
        double std  = 0.8934747186204953;
        double alpha = (mean*mean)/(std*std);
        double beta = (std*std)/mean;
        System.out.println("alpha: " + alpha);
        System.out.println("beta: " + beta);
        
        GammaDistribution gd = new GammaDistribution(alpha, beta);
        
        for (int i=0; i<25; i++)
        {
            double pdf = gd.density(i);
            double cdf = gd.cumulativeProbability(i);
            System.out.println("i=" + i + "; pdf=" + pdf + "; cdf=" + cdf);            
        }
        System.out.println();
        
        for (int i=0; i<20; i++)
        {
            double x = 19.0 + (.1 * i);
            double pdf = gd.density(x);
            double cdf = gd.cumulativeProbability(x);
            System.out.println("x=" + x + "; pdf=" + pdf + "; cdf=" + cdf);            
        }
    }
}

Here's results of running above test:

alpha: 128.25629996917283
beta: 0.07889380729280462
i=0; pdf=0.0; cdf=0.0
i=1; pdf=8.663477060371509E-79; cdf=7.488555717749243E-81
i=2; pdf=5.5062704634862175E-46; cdf=1.0676382015037016E-47
i=3; pdf=4.413483488439264E-29; cdf=1.4607150065658644E-30
i=4; pdf=1.0945225959157887E-18; cdf=5.599255664602861E-20
i=5; pdf=7.35929647596093E-12; cdf=5.590805261026197E-13
i=6; pdf=2.7437881760964153E-7; cdf=3.0732983691238435E-8
i=7; pdf=2.8376132639470645E-4; cdf=4.7826733420766874E-5
i=8; pdf=0.021281179160656388; cdf=0.005695853765034336
i=9; pdf=0.2151187723352627; cdf=0.10175065472250033
i=10; pdf=0.44751658755472723; cdf=0.4586536845007119
i=11; pdf=0.259114059558244; cdf=0.8385256983930766
i=12; pdf=0.05218255030958943; cdf=0.9781383380332821
i=13; pdf=0.004329365023697574; cdf=0.9986058018679428
i=14; pdf=1.6878342979402664E-4; cdf=0.9999549514385939
i=15; pdf=3.431947471368873E-6; cdf=0.9999992047520807
i=16; pdf=3.9588967227014906E-8; cdf=0.9999999917873332
i=17; pdf=2.7752325350928474E-10; cdf=0.9999999999473412
i=18; pdf=1.2515801802459923E-12; cdf=0.9999999999997794
i=19; pdf=3.808710263354571E-15; cdf=0.9999999999999993
i=20; pdf=8.143130333262255E-18; cdf=1.0
i=21; pdf=Infinity; cdf=1.0
i=22; pdf=Infinity; cdf=1.0
i=23; pdf=Infinity; cdf=1.0
i=24; pdf=Infinity; cdf=1.0

x=19.0; pdf=3.808710263354571E-15; cdf=0.9999999999999993
x=19.1; pdf=2.0912827149653448E-15; cdf=0.9999999999999997
x=19.2; pdf=1.144280754920214E-15; cdf=0.9999999999999998
x=19.3; pdf=6.239549206021272E-16; cdf=0.9999999999999999
x=19.4; pdf=3.3907057624200243E-16; cdf=1.0
x=19.5; pdf=1.8363629496980252E-16; cdf=1.0
x=19.6; pdf=9.912278358035803E-17; cdf=1.0
x=19.7; pdf=5.332732516340122E-17; cdf=1.0
x=19.8; pdf=2.8595785047900534E-17; cdf=1.0
x=19.9; pdf=1.5284263208928833E-17; cdf=1.0
x=20.0; pdf=8.143130333262255E-18; cdf=1.0
x=20.1; pdf=4.324705899342647E-18; cdf=1.0
x=20.2; pdf=2.2895693394216285E-18; cdf=1.0
x=20.3; pdf=1.2083606178165914E-18; cdf=1.0
x=20.4; pdf=6.357672846520565E-19; cdf=1.0
x=20.5; pdf=Infinity; cdf=1.0
x=20.6; pdf=Infinity; cdf=1.0
x=20.7; pdf=Infinity; cdf=1.0
x=20.8; pdf=Infinity; cdf=1.0
x=20.9; pdf=Infinity; cdf=1.0



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (MATH-888) GammaDistribution returns infinite density when cdf = 1

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

Thomas Neidhart commented on MATH-888:
--------------------------------------

Hi Zev,

thanks for the feedback.

Could you attach a log of the mentioned test failure?

Thanks,

Thomas
                
> GammaDistribution returns infinite density when cdf = 1
> -------------------------------------------------------
>
>                 Key: MATH-888
>                 URL: https://issues.apache.org/jira/browse/MATH-888
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>         Environment: Windows 7
>            Reporter: Zev Hochberg
>
> When GammaDistribution.cumulativeProbability = 1, then GammaDistribution.density may return Infinite - but it should return 0.
> Here is sample java code which demonstrates this issue, with results. Note that when pass the point at which cumulativeProbability = 1, the density stays > 0, though very small (pdf should be 0 when cdf = 1) - but as continue, then cdf stays 1, but pdf becomes infinite. This is seen most clearly in the second set of data below.
> package ApacheTester;
> import org.apache.commons.math3.distribution.GammaDistribution;
> public class GammaDistributionTester
> {
>     public static void main(String[] args)
>     {
>         double mean = 10.118627813856065;
>         double std  = 0.8934747186204953;
>         double alpha = (mean*mean)/(std*std);
>         double beta = (std*std)/mean;
>         System.out.println("alpha: " + alpha);
>         System.out.println("beta: " + beta);
>         
>         GammaDistribution gd = new GammaDistribution(alpha, beta);
>         
>         for (int i=0; i<25; i++)
>         {
>             double pdf = gd.density(i);
>             double cdf = gd.cumulativeProbability(i);
>             System.out.println("i=" + i + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>         System.out.println();
>         
>         for (int i=0; i<20; i++)
>         {
>             double x = 19.0 + (.1 * i);
>             double pdf = gd.density(x);
>             double cdf = gd.cumulativeProbability(x);
>             System.out.println("x=" + x + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>     }
> }
> Here's results of running above test:
> alpha: 128.25629996917283
> beta: 0.07889380729280462
> i=0; pdf=0.0; cdf=0.0
> i=1; pdf=8.663477060371509E-79; cdf=7.488555717749243E-81
> i=2; pdf=5.5062704634862175E-46; cdf=1.0676382015037016E-47
> i=3; pdf=4.413483488439264E-29; cdf=1.4607150065658644E-30
> i=4; pdf=1.0945225959157887E-18; cdf=5.599255664602861E-20
> i=5; pdf=7.35929647596093E-12; cdf=5.590805261026197E-13
> i=6; pdf=2.7437881760964153E-7; cdf=3.0732983691238435E-8
> i=7; pdf=2.8376132639470645E-4; cdf=4.7826733420766874E-5
> i=8; pdf=0.021281179160656388; cdf=0.005695853765034336
> i=9; pdf=0.2151187723352627; cdf=0.10175065472250033
> i=10; pdf=0.44751658755472723; cdf=0.4586536845007119
> i=11; pdf=0.259114059558244; cdf=0.8385256983930766
> i=12; pdf=0.05218255030958943; cdf=0.9781383380332821
> i=13; pdf=0.004329365023697574; cdf=0.9986058018679428
> i=14; pdf=1.6878342979402664E-4; cdf=0.9999549514385939
> i=15; pdf=3.431947471368873E-6; cdf=0.9999992047520807
> i=16; pdf=3.9588967227014906E-8; cdf=0.9999999917873332
> i=17; pdf=2.7752325350928474E-10; cdf=0.9999999999473412
> i=18; pdf=1.2515801802459923E-12; cdf=0.9999999999997794
> i=19; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> i=20; pdf=8.143130333262255E-18; cdf=1.0
> i=21; pdf=Infinity; cdf=1.0
> i=22; pdf=Infinity; cdf=1.0
> i=23; pdf=Infinity; cdf=1.0
> i=24; pdf=Infinity; cdf=1.0
> x=19.0; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> x=19.1; pdf=2.0912827149653448E-15; cdf=0.9999999999999997
> x=19.2; pdf=1.144280754920214E-15; cdf=0.9999999999999998
> x=19.3; pdf=6.239549206021272E-16; cdf=0.9999999999999999
> x=19.4; pdf=3.3907057624200243E-16; cdf=1.0
> x=19.5; pdf=1.8363629496980252E-16; cdf=1.0
> x=19.6; pdf=9.912278358035803E-17; cdf=1.0
> x=19.7; pdf=5.332732516340122E-17; cdf=1.0
> x=19.8; pdf=2.8595785047900534E-17; cdf=1.0
> x=19.9; pdf=1.5284263208928833E-17; cdf=1.0
> x=20.0; pdf=8.143130333262255E-18; cdf=1.0
> x=20.1; pdf=4.324705899342647E-18; cdf=1.0
> x=20.2; pdf=2.2895693394216285E-18; cdf=1.0
> x=20.3; pdf=1.2083606178165914E-18; cdf=1.0
> x=20.4; pdf=6.357672846520565E-19; cdf=1.0
> x=20.5; pdf=Infinity; cdf=1.0
> x=20.6; pdf=Infinity; cdf=1.0
> x=20.7; pdf=Infinity; cdf=1.0
> x=20.8; pdf=Infinity; cdf=1.0
> x=20.9; pdf=Infinity; cdf=1.0

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (MATH-888) GammaDistribution returns infinite density when cdf = 1

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

Zev Hochberg commented on MATH-888:
-----------------------------------

Here's a unit test error log, when I copy trunk to c:\ACM\commons-math3, rather than to c:\commons-math3
There was also a unit test error when trunk was much "deeper" in the drive; in that case failed to open a file, which was in fact present.
I'll try and find my notes so I reproduce that one.

-------------------------------------------------------------------------------
Test set: org.apache.commons.math3.genetics.FixedElapsedTimeTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 3.488 sec <<< FAILURE!
testIsSatisfied(org.apache.commons.math3.genetics.FixedElapsedTimeTest)  Time elapsed: 3.487 sec  <<< FAILURE!
java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:92)
	at org.junit.Assert.assertTrue(Assert.java:43)
	at org.junit.Assert.assertTrue(Assert.java:54)
	at org.apache.commons.math3.genetics.FixedElapsedTimeTest.testIsSatisfied(FixedElapsedTimeTest.java:72)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:236)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)

                
> GammaDistribution returns infinite density when cdf = 1
> -------------------------------------------------------
>
>                 Key: MATH-888
>                 URL: https://issues.apache.org/jira/browse/MATH-888
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>         Environment: Windows 7
>            Reporter: Zev Hochberg
>
> When GammaDistribution.cumulativeProbability = 1, then GammaDistribution.density may return Infinite - but it should return 0.
> Here is sample java code which demonstrates this issue, with results. Note that when pass the point at which cumulativeProbability = 1, the density stays > 0, though very small (pdf should be 0 when cdf = 1) - but as continue, then cdf stays 1, but pdf becomes infinite. This is seen most clearly in the second set of data below.
> package ApacheTester;
> import org.apache.commons.math3.distribution.GammaDistribution;
> public class GammaDistributionTester
> {
>     public static void main(String[] args)
>     {
>         double mean = 10.118627813856065;
>         double std  = 0.8934747186204953;
>         double alpha = (mean*mean)/(std*std);
>         double beta = (std*std)/mean;
>         System.out.println("alpha: " + alpha);
>         System.out.println("beta: " + beta);
>         
>         GammaDistribution gd = new GammaDistribution(alpha, beta);
>         
>         for (int i=0; i<25; i++)
>         {
>             double pdf = gd.density(i);
>             double cdf = gd.cumulativeProbability(i);
>             System.out.println("i=" + i + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>         System.out.println();
>         
>         for (int i=0; i<20; i++)
>         {
>             double x = 19.0 + (.1 * i);
>             double pdf = gd.density(x);
>             double cdf = gd.cumulativeProbability(x);
>             System.out.println("x=" + x + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>     }
> }
> Here's results of running above test:
> alpha: 128.25629996917283
> beta: 0.07889380729280462
> i=0; pdf=0.0; cdf=0.0
> i=1; pdf=8.663477060371509E-79; cdf=7.488555717749243E-81
> i=2; pdf=5.5062704634862175E-46; cdf=1.0676382015037016E-47
> i=3; pdf=4.413483488439264E-29; cdf=1.4607150065658644E-30
> i=4; pdf=1.0945225959157887E-18; cdf=5.599255664602861E-20
> i=5; pdf=7.35929647596093E-12; cdf=5.590805261026197E-13
> i=6; pdf=2.7437881760964153E-7; cdf=3.0732983691238435E-8
> i=7; pdf=2.8376132639470645E-4; cdf=4.7826733420766874E-5
> i=8; pdf=0.021281179160656388; cdf=0.005695853765034336
> i=9; pdf=0.2151187723352627; cdf=0.10175065472250033
> i=10; pdf=0.44751658755472723; cdf=0.4586536845007119
> i=11; pdf=0.259114059558244; cdf=0.8385256983930766
> i=12; pdf=0.05218255030958943; cdf=0.9781383380332821
> i=13; pdf=0.004329365023697574; cdf=0.9986058018679428
> i=14; pdf=1.6878342979402664E-4; cdf=0.9999549514385939
> i=15; pdf=3.431947471368873E-6; cdf=0.9999992047520807
> i=16; pdf=3.9588967227014906E-8; cdf=0.9999999917873332
> i=17; pdf=2.7752325350928474E-10; cdf=0.9999999999473412
> i=18; pdf=1.2515801802459923E-12; cdf=0.9999999999997794
> i=19; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> i=20; pdf=8.143130333262255E-18; cdf=1.0
> i=21; pdf=Infinity; cdf=1.0
> i=22; pdf=Infinity; cdf=1.0
> i=23; pdf=Infinity; cdf=1.0
> i=24; pdf=Infinity; cdf=1.0
> x=19.0; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> x=19.1; pdf=2.0912827149653448E-15; cdf=0.9999999999999997
> x=19.2; pdf=1.144280754920214E-15; cdf=0.9999999999999998
> x=19.3; pdf=6.239549206021272E-16; cdf=0.9999999999999999
> x=19.4; pdf=3.3907057624200243E-16; cdf=1.0
> x=19.5; pdf=1.8363629496980252E-16; cdf=1.0
> x=19.6; pdf=9.912278358035803E-17; cdf=1.0
> x=19.7; pdf=5.332732516340122E-17; cdf=1.0
> x=19.8; pdf=2.8595785047900534E-17; cdf=1.0
> x=19.9; pdf=1.5284263208928833E-17; cdf=1.0
> x=20.0; pdf=8.143130333262255E-18; cdf=1.0
> x=20.1; pdf=4.324705899342647E-18; cdf=1.0
> x=20.2; pdf=2.2895693394216285E-18; cdf=1.0
> x=20.3; pdf=1.2083606178165914E-18; cdf=1.0
> x=20.4; pdf=6.357672846520565E-19; cdf=1.0
> x=20.5; pdf=Infinity; cdf=1.0
> x=20.6; pdf=Infinity; cdf=1.0
> x=20.7; pdf=Infinity; cdf=1.0
> x=20.8; pdf=Infinity; cdf=1.0
> x=20.9; pdf=Infinity; cdf=1.0

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (MATH-888) GammaDistribution returns infinite density when cdf = 1

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

Zev Hochberg commented on MATH-888:
-----------------------------------

I've built trunk, and I do get the results Thomas Neidhart shows below - problem is fixed.

One odd thing: for all unit tests to run correctly, I needed to download trunk to root of c:\ drive.
If I copied elsewhere, I would get a unit test failure - once, for example, of FixedElapsedTimeTest.java in genetics package.
                
> GammaDistribution returns infinite density when cdf = 1
> -------------------------------------------------------
>
>                 Key: MATH-888
>                 URL: https://issues.apache.org/jira/browse/MATH-888
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>         Environment: Windows 7
>            Reporter: Zev Hochberg
>
> When GammaDistribution.cumulativeProbability = 1, then GammaDistribution.density may return Infinite - but it should return 0.
> Here is sample java code which demonstrates this issue, with results. Note that when pass the point at which cumulativeProbability = 1, the density stays > 0, though very small (pdf should be 0 when cdf = 1) - but as continue, then cdf stays 1, but pdf becomes infinite. This is seen most clearly in the second set of data below.
> package ApacheTester;
> import org.apache.commons.math3.distribution.GammaDistribution;
> public class GammaDistributionTester
> {
>     public static void main(String[] args)
>     {
>         double mean = 10.118627813856065;
>         double std  = 0.8934747186204953;
>         double alpha = (mean*mean)/(std*std);
>         double beta = (std*std)/mean;
>         System.out.println("alpha: " + alpha);
>         System.out.println("beta: " + beta);
>         
>         GammaDistribution gd = new GammaDistribution(alpha, beta);
>         
>         for (int i=0; i<25; i++)
>         {
>             double pdf = gd.density(i);
>             double cdf = gd.cumulativeProbability(i);
>             System.out.println("i=" + i + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>         System.out.println();
>         
>         for (int i=0; i<20; i++)
>         {
>             double x = 19.0 + (.1 * i);
>             double pdf = gd.density(x);
>             double cdf = gd.cumulativeProbability(x);
>             System.out.println("x=" + x + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>     }
> }
> Here's results of running above test:
> alpha: 128.25629996917283
> beta: 0.07889380729280462
> i=0; pdf=0.0; cdf=0.0
> i=1; pdf=8.663477060371509E-79; cdf=7.488555717749243E-81
> i=2; pdf=5.5062704634862175E-46; cdf=1.0676382015037016E-47
> i=3; pdf=4.413483488439264E-29; cdf=1.4607150065658644E-30
> i=4; pdf=1.0945225959157887E-18; cdf=5.599255664602861E-20
> i=5; pdf=7.35929647596093E-12; cdf=5.590805261026197E-13
> i=6; pdf=2.7437881760964153E-7; cdf=3.0732983691238435E-8
> i=7; pdf=2.8376132639470645E-4; cdf=4.7826733420766874E-5
> i=8; pdf=0.021281179160656388; cdf=0.005695853765034336
> i=9; pdf=0.2151187723352627; cdf=0.10175065472250033
> i=10; pdf=0.44751658755472723; cdf=0.4586536845007119
> i=11; pdf=0.259114059558244; cdf=0.8385256983930766
> i=12; pdf=0.05218255030958943; cdf=0.9781383380332821
> i=13; pdf=0.004329365023697574; cdf=0.9986058018679428
> i=14; pdf=1.6878342979402664E-4; cdf=0.9999549514385939
> i=15; pdf=3.431947471368873E-6; cdf=0.9999992047520807
> i=16; pdf=3.9588967227014906E-8; cdf=0.9999999917873332
> i=17; pdf=2.7752325350928474E-10; cdf=0.9999999999473412
> i=18; pdf=1.2515801802459923E-12; cdf=0.9999999999997794
> i=19; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> i=20; pdf=8.143130333262255E-18; cdf=1.0
> i=21; pdf=Infinity; cdf=1.0
> i=22; pdf=Infinity; cdf=1.0
> i=23; pdf=Infinity; cdf=1.0
> i=24; pdf=Infinity; cdf=1.0
> x=19.0; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> x=19.1; pdf=2.0912827149653448E-15; cdf=0.9999999999999997
> x=19.2; pdf=1.144280754920214E-15; cdf=0.9999999999999998
> x=19.3; pdf=6.239549206021272E-16; cdf=0.9999999999999999
> x=19.4; pdf=3.3907057624200243E-16; cdf=1.0
> x=19.5; pdf=1.8363629496980252E-16; cdf=1.0
> x=19.6; pdf=9.912278358035803E-17; cdf=1.0
> x=19.7; pdf=5.332732516340122E-17; cdf=1.0
> x=19.8; pdf=2.8595785047900534E-17; cdf=1.0
> x=19.9; pdf=1.5284263208928833E-17; cdf=1.0
> x=20.0; pdf=8.143130333262255E-18; cdf=1.0
> x=20.1; pdf=4.324705899342647E-18; cdf=1.0
> x=20.2; pdf=2.2895693394216285E-18; cdf=1.0
> x=20.3; pdf=1.2083606178165914E-18; cdf=1.0
> x=20.4; pdf=6.357672846520565E-19; cdf=1.0
> x=20.5; pdf=Infinity; cdf=1.0
> x=20.6; pdf=Infinity; cdf=1.0
> x=20.7; pdf=Infinity; cdf=1.0
> x=20.8; pdf=Infinity; cdf=1.0
> x=20.9; pdf=Infinity; cdf=1.0

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (MATH-888) GammaDistribution returns infinite density when cdf = 1

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

Thomas Neidhart commented on MATH-888:
--------------------------------------

Several improvements to the Gamma function have already been implemented in trunk (see MATH-849).

Running your test program with the latest trunk gives the following results:

{noformat}
alpha: 128.25629996917283
beta: 0.07889380729280462
i=0; pdf=0.0; cdf=0.0
i=1; pdf=8.663477060372497E-79; cdf=7.488555717749243E-81
i=2; pdf=5.506270463486845E-46; cdf=1.0676382015037016E-47
i=3; pdf=4.4134834884397667E-29; cdf=1.4607150065658644E-30
i=4; pdf=1.0945225959159135E-18; cdf=5.599255664602861E-20
i=5; pdf=7.359296475961767E-12; cdf=5.590805261026197E-13
i=6; pdf=2.7437881760967277E-7; cdf=3.0732983691238435E-8
i=7; pdf=2.837613263947388E-4; cdf=4.7826733420766874E-5
i=8; pdf=0.021281179160658817; cdf=0.005695853765034336
i=9; pdf=0.21511877233528723; cdf=0.10175065472250033
i=10; pdf=0.4475165875547783; cdf=0.4586536845007119
i=11; pdf=0.25911405955827355; cdf=0.8385256983930767
i=12; pdf=0.052182550309595385; cdf=0.9781383380332821
i=13; pdf=0.004329365023698068; cdf=0.9986058018679428
i=14; pdf=1.6878342979404588E-4; cdf=0.9999549514385939
i=15; pdf=3.431947471369265E-6; cdf=0.9999992047520807
i=16; pdf=3.958896722701942E-8; cdf=0.9999999917873332
i=17; pdf=2.775232535093164E-10; cdf=0.9999999999473412
i=18; pdf=1.2515801802472468E-12; cdf=0.9999999999997794
i=19; pdf=3.808712290749614E-15; cdf=0.9999999999999993
i=20; pdf=8.266386718783014E-18; cdf=1.0
i=21; pdf=1.2660914223523828E-20; cdf=1.0
i=22; pdf=1.4746029859879733E-23; cdf=1.0
i=23; pdf=1.320017264979955E-26; cdf=1.0
i=24; pdf=9.28776702592028E-30; cdf=1.0

x=19.0; pdf=3.808712290749614E-15; cdf=0.9999999999999993
x=19.1; pdf=2.091282124070138E-15; cdf=0.9999999999999997
x=19.2; pdf=1.1442807873491891E-15; cdf=0.9999999999999998
x=19.3; pdf=6.239511895039934E-16; cdf=0.9999999999999999
x=19.4; pdf=3.3905614583343015E-16; cdf=1.0
x=19.5; pdf=1.8362803668472756E-16; cdf=1.0
x=19.6; pdf=9.92380512634114E-17; cdf=1.0
x=19.7; pdf=5.314805483145551E-17; cdf=1.0
x=19.8; pdf=2.8759196357817904E-17; cdf=1.0
x=19.9; pdf=1.528822526909328E-17; cdf=1.0
x=20.0; pdf=8.266386718783014E-18; cdf=1.0
x=20.1; pdf=7.797057331677706E-18; cdf=1.0
x=20.2; pdf=0.0; cdf=1.0
x=20.3; pdf=0.0; cdf=1.0
x=20.4; pdf=0.0; cdf=1.0
x=20.5; pdf=0.0; cdf=1.0
x=20.6; pdf=0.0; cdf=1.0
x=20.7; pdf=0.0; cdf=1.0
x=20.8; pdf=0.0; cdf=1.0
x=20.9; pdf=2.4498611525242454E-20; cdf=1.0
{noformat}

Could you please test yourself and report if the result is as expected?

Thanks,

Thomas
                
> GammaDistribution returns infinite density when cdf = 1
> -------------------------------------------------------
>
>                 Key: MATH-888
>                 URL: https://issues.apache.org/jira/browse/MATH-888
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>         Environment: Windows 7
>            Reporter: Zev Hochberg
>
> When GammaDistribution.cumulativeProbability = 1, then GammaDistribution.density may return Infinite - but it should return 0.
> Here is sample java code which demonstrates this issue, with results. Note that when pass the point at which cumulativeProbability = 1, the density stays > 0, though very small (pdf should be 0 when cdf = 1) - but as continue, then cdf stays 1, but pdf becomes infinite. This is seen most clearly in the second set of data below.
> package ApacheTester;
> import org.apache.commons.math3.distribution.GammaDistribution;
> public class GammaDistributionTester
> {
>     public static void main(String[] args)
>     {
>         double mean = 10.118627813856065;
>         double std  = 0.8934747186204953;
>         double alpha = (mean*mean)/(std*std);
>         double beta = (std*std)/mean;
>         System.out.println("alpha: " + alpha);
>         System.out.println("beta: " + beta);
>         
>         GammaDistribution gd = new GammaDistribution(alpha, beta);
>         
>         for (int i=0; i<25; i++)
>         {
>             double pdf = gd.density(i);
>             double cdf = gd.cumulativeProbability(i);
>             System.out.println("i=" + i + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>         System.out.println();
>         
>         for (int i=0; i<20; i++)
>         {
>             double x = 19.0 + (.1 * i);
>             double pdf = gd.density(x);
>             double cdf = gd.cumulativeProbability(x);
>             System.out.println("x=" + x + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>     }
> }
> Here's results of running above test:
> alpha: 128.25629996917283
> beta: 0.07889380729280462
> i=0; pdf=0.0; cdf=0.0
> i=1; pdf=8.663477060371509E-79; cdf=7.488555717749243E-81
> i=2; pdf=5.5062704634862175E-46; cdf=1.0676382015037016E-47
> i=3; pdf=4.413483488439264E-29; cdf=1.4607150065658644E-30
> i=4; pdf=1.0945225959157887E-18; cdf=5.599255664602861E-20
> i=5; pdf=7.35929647596093E-12; cdf=5.590805261026197E-13
> i=6; pdf=2.7437881760964153E-7; cdf=3.0732983691238435E-8
> i=7; pdf=2.8376132639470645E-4; cdf=4.7826733420766874E-5
> i=8; pdf=0.021281179160656388; cdf=0.005695853765034336
> i=9; pdf=0.2151187723352627; cdf=0.10175065472250033
> i=10; pdf=0.44751658755472723; cdf=0.4586536845007119
> i=11; pdf=0.259114059558244; cdf=0.8385256983930766
> i=12; pdf=0.05218255030958943; cdf=0.9781383380332821
> i=13; pdf=0.004329365023697574; cdf=0.9986058018679428
> i=14; pdf=1.6878342979402664E-4; cdf=0.9999549514385939
> i=15; pdf=3.431947471368873E-6; cdf=0.9999992047520807
> i=16; pdf=3.9588967227014906E-8; cdf=0.9999999917873332
> i=17; pdf=2.7752325350928474E-10; cdf=0.9999999999473412
> i=18; pdf=1.2515801802459923E-12; cdf=0.9999999999997794
> i=19; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> i=20; pdf=8.143130333262255E-18; cdf=1.0
> i=21; pdf=Infinity; cdf=1.0
> i=22; pdf=Infinity; cdf=1.0
> i=23; pdf=Infinity; cdf=1.0
> i=24; pdf=Infinity; cdf=1.0
> x=19.0; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> x=19.1; pdf=2.0912827149653448E-15; cdf=0.9999999999999997
> x=19.2; pdf=1.144280754920214E-15; cdf=0.9999999999999998
> x=19.3; pdf=6.239549206021272E-16; cdf=0.9999999999999999
> x=19.4; pdf=3.3907057624200243E-16; cdf=1.0
> x=19.5; pdf=1.8363629496980252E-16; cdf=1.0
> x=19.6; pdf=9.912278358035803E-17; cdf=1.0
> x=19.7; pdf=5.332732516340122E-17; cdf=1.0
> x=19.8; pdf=2.8595785047900534E-17; cdf=1.0
> x=19.9; pdf=1.5284263208928833E-17; cdf=1.0
> x=20.0; pdf=8.143130333262255E-18; cdf=1.0
> x=20.1; pdf=4.324705899342647E-18; cdf=1.0
> x=20.2; pdf=2.2895693394216285E-18; cdf=1.0
> x=20.3; pdf=1.2083606178165914E-18; cdf=1.0
> x=20.4; pdf=6.357672846520565E-19; cdf=1.0
> x=20.5; pdf=Infinity; cdf=1.0
> x=20.6; pdf=Infinity; cdf=1.0
> x=20.7; pdf=Infinity; cdf=1.0
> x=20.8; pdf=Infinity; cdf=1.0
> x=20.9; pdf=Infinity; cdf=1.0

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (MATH-888) GammaDistribution returns infinite density when cdf = 1

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

Thomas Neidhart commented on MATH-888:
--------------------------------------

ok, the test should be fixed, the sleep was larger than the test condition which could lead to a race condition.
                
> GammaDistribution returns infinite density when cdf = 1
> -------------------------------------------------------
>
>                 Key: MATH-888
>                 URL: https://issues.apache.org/jira/browse/MATH-888
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>         Environment: Windows 7
>            Reporter: Zev Hochberg
>
> When GammaDistribution.cumulativeProbability = 1, then GammaDistribution.density may return Infinite - but it should return 0.
> Here is sample java code which demonstrates this issue, with results. Note that when pass the point at which cumulativeProbability = 1, the density stays > 0, though very small (pdf should be 0 when cdf = 1) - but as continue, then cdf stays 1, but pdf becomes infinite. This is seen most clearly in the second set of data below.
> package ApacheTester;
> import org.apache.commons.math3.distribution.GammaDistribution;
> public class GammaDistributionTester
> {
>     public static void main(String[] args)
>     {
>         double mean = 10.118627813856065;
>         double std  = 0.8934747186204953;
>         double alpha = (mean*mean)/(std*std);
>         double beta = (std*std)/mean;
>         System.out.println("alpha: " + alpha);
>         System.out.println("beta: " + beta);
>         
>         GammaDistribution gd = new GammaDistribution(alpha, beta);
>         
>         for (int i=0; i<25; i++)
>         {
>             double pdf = gd.density(i);
>             double cdf = gd.cumulativeProbability(i);
>             System.out.println("i=" + i + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>         System.out.println();
>         
>         for (int i=0; i<20; i++)
>         {
>             double x = 19.0 + (.1 * i);
>             double pdf = gd.density(x);
>             double cdf = gd.cumulativeProbability(x);
>             System.out.println("x=" + x + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>     }
> }
> Here's results of running above test:
> alpha: 128.25629996917283
> beta: 0.07889380729280462
> i=0; pdf=0.0; cdf=0.0
> i=1; pdf=8.663477060371509E-79; cdf=7.488555717749243E-81
> i=2; pdf=5.5062704634862175E-46; cdf=1.0676382015037016E-47
> i=3; pdf=4.413483488439264E-29; cdf=1.4607150065658644E-30
> i=4; pdf=1.0945225959157887E-18; cdf=5.599255664602861E-20
> i=5; pdf=7.35929647596093E-12; cdf=5.590805261026197E-13
> i=6; pdf=2.7437881760964153E-7; cdf=3.0732983691238435E-8
> i=7; pdf=2.8376132639470645E-4; cdf=4.7826733420766874E-5
> i=8; pdf=0.021281179160656388; cdf=0.005695853765034336
> i=9; pdf=0.2151187723352627; cdf=0.10175065472250033
> i=10; pdf=0.44751658755472723; cdf=0.4586536845007119
> i=11; pdf=0.259114059558244; cdf=0.8385256983930766
> i=12; pdf=0.05218255030958943; cdf=0.9781383380332821
> i=13; pdf=0.004329365023697574; cdf=0.9986058018679428
> i=14; pdf=1.6878342979402664E-4; cdf=0.9999549514385939
> i=15; pdf=3.431947471368873E-6; cdf=0.9999992047520807
> i=16; pdf=3.9588967227014906E-8; cdf=0.9999999917873332
> i=17; pdf=2.7752325350928474E-10; cdf=0.9999999999473412
> i=18; pdf=1.2515801802459923E-12; cdf=0.9999999999997794
> i=19; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> i=20; pdf=8.143130333262255E-18; cdf=1.0
> i=21; pdf=Infinity; cdf=1.0
> i=22; pdf=Infinity; cdf=1.0
> i=23; pdf=Infinity; cdf=1.0
> i=24; pdf=Infinity; cdf=1.0
> x=19.0; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> x=19.1; pdf=2.0912827149653448E-15; cdf=0.9999999999999997
> x=19.2; pdf=1.144280754920214E-15; cdf=0.9999999999999998
> x=19.3; pdf=6.239549206021272E-16; cdf=0.9999999999999999
> x=19.4; pdf=3.3907057624200243E-16; cdf=1.0
> x=19.5; pdf=1.8363629496980252E-16; cdf=1.0
> x=19.6; pdf=9.912278358035803E-17; cdf=1.0
> x=19.7; pdf=5.332732516340122E-17; cdf=1.0
> x=19.8; pdf=2.8595785047900534E-17; cdf=1.0
> x=19.9; pdf=1.5284263208928833E-17; cdf=1.0
> x=20.0; pdf=8.143130333262255E-18; cdf=1.0
> x=20.1; pdf=4.324705899342647E-18; cdf=1.0
> x=20.2; pdf=2.2895693394216285E-18; cdf=1.0
> x=20.3; pdf=1.2083606178165914E-18; cdf=1.0
> x=20.4; pdf=6.357672846520565E-19; cdf=1.0
> x=20.5; pdf=Infinity; cdf=1.0
> x=20.6; pdf=Infinity; cdf=1.0
> x=20.7; pdf=Infinity; cdf=1.0
> x=20.8; pdf=Infinity; cdf=1.0
> x=20.9; pdf=Infinity; cdf=1.0

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Resolved] (MATH-888) GammaDistribution returns infinite density when cdf = 1

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

Gilles resolved MATH-888.
-------------------------

       Resolution: Fixed
    Fix Version/s: 3.1

Resolving, as the reporter confirmed that the issue had already been fixed in "trunk".

                
> GammaDistribution returns infinite density when cdf = 1
> -------------------------------------------------------
>
>                 Key: MATH-888
>                 URL: https://issues.apache.org/jira/browse/MATH-888
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>         Environment: Windows 7
>            Reporter: Zev Hochberg
>             Fix For: 3.1
>
>
> When GammaDistribution.cumulativeProbability = 1, then GammaDistribution.density may return Infinite - but it should return 0.
> Here is sample java code which demonstrates this issue, with results. Note that when pass the point at which cumulativeProbability = 1, the density stays > 0, though very small (pdf should be 0 when cdf = 1) - but as continue, then cdf stays 1, but pdf becomes infinite. This is seen most clearly in the second set of data below.
> package ApacheTester;
> import org.apache.commons.math3.distribution.GammaDistribution;
> public class GammaDistributionTester
> {
>     public static void main(String[] args)
>     {
>         double mean = 10.118627813856065;
>         double std  = 0.8934747186204953;
>         double alpha = (mean*mean)/(std*std);
>         double beta = (std*std)/mean;
>         System.out.println("alpha: " + alpha);
>         System.out.println("beta: " + beta);
>         
>         GammaDistribution gd = new GammaDistribution(alpha, beta);
>         
>         for (int i=0; i<25; i++)
>         {
>             double pdf = gd.density(i);
>             double cdf = gd.cumulativeProbability(i);
>             System.out.println("i=" + i + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>         System.out.println();
>         
>         for (int i=0; i<20; i++)
>         {
>             double x = 19.0 + (.1 * i);
>             double pdf = gd.density(x);
>             double cdf = gd.cumulativeProbability(x);
>             System.out.println("x=" + x + "; pdf=" + pdf + "; cdf=" + cdf);            
>         }
>     }
> }
> Here's results of running above test:
> alpha: 128.25629996917283
> beta: 0.07889380729280462
> i=0; pdf=0.0; cdf=0.0
> i=1; pdf=8.663477060371509E-79; cdf=7.488555717749243E-81
> i=2; pdf=5.5062704634862175E-46; cdf=1.0676382015037016E-47
> i=3; pdf=4.413483488439264E-29; cdf=1.4607150065658644E-30
> i=4; pdf=1.0945225959157887E-18; cdf=5.599255664602861E-20
> i=5; pdf=7.35929647596093E-12; cdf=5.590805261026197E-13
> i=6; pdf=2.7437881760964153E-7; cdf=3.0732983691238435E-8
> i=7; pdf=2.8376132639470645E-4; cdf=4.7826733420766874E-5
> i=8; pdf=0.021281179160656388; cdf=0.005695853765034336
> i=9; pdf=0.2151187723352627; cdf=0.10175065472250033
> i=10; pdf=0.44751658755472723; cdf=0.4586536845007119
> i=11; pdf=0.259114059558244; cdf=0.8385256983930766
> i=12; pdf=0.05218255030958943; cdf=0.9781383380332821
> i=13; pdf=0.004329365023697574; cdf=0.9986058018679428
> i=14; pdf=1.6878342979402664E-4; cdf=0.9999549514385939
> i=15; pdf=3.431947471368873E-6; cdf=0.9999992047520807
> i=16; pdf=3.9588967227014906E-8; cdf=0.9999999917873332
> i=17; pdf=2.7752325350928474E-10; cdf=0.9999999999473412
> i=18; pdf=1.2515801802459923E-12; cdf=0.9999999999997794
> i=19; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> i=20; pdf=8.143130333262255E-18; cdf=1.0
> i=21; pdf=Infinity; cdf=1.0
> i=22; pdf=Infinity; cdf=1.0
> i=23; pdf=Infinity; cdf=1.0
> i=24; pdf=Infinity; cdf=1.0
> x=19.0; pdf=3.808710263354571E-15; cdf=0.9999999999999993
> x=19.1; pdf=2.0912827149653448E-15; cdf=0.9999999999999997
> x=19.2; pdf=1.144280754920214E-15; cdf=0.9999999999999998
> x=19.3; pdf=6.239549206021272E-16; cdf=0.9999999999999999
> x=19.4; pdf=3.3907057624200243E-16; cdf=1.0
> x=19.5; pdf=1.8363629496980252E-16; cdf=1.0
> x=19.6; pdf=9.912278358035803E-17; cdf=1.0
> x=19.7; pdf=5.332732516340122E-17; cdf=1.0
> x=19.8; pdf=2.8595785047900534E-17; cdf=1.0
> x=19.9; pdf=1.5284263208928833E-17; cdf=1.0
> x=20.0; pdf=8.143130333262255E-18; cdf=1.0
> x=20.1; pdf=4.324705899342647E-18; cdf=1.0
> x=20.2; pdf=2.2895693394216285E-18; cdf=1.0
> x=20.3; pdf=1.2083606178165914E-18; cdf=1.0
> x=20.4; pdf=6.357672846520565E-19; cdf=1.0
> x=20.5; pdf=Infinity; cdf=1.0
> x=20.6; pdf=Infinity; cdf=1.0
> x=20.7; pdf=Infinity; cdf=1.0
> x=20.8; pdf=Infinity; cdf=1.0
> x=20.9; pdf=Infinity; cdf=1.0

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira