[
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