Re: [ojAlgo-user] apparent bug in Gamma distribution
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Chris L. <cg...@gm...> - 2012-06-19 18:06:25
|
Thanks for the new snapshot. The gamma distribution looks good. I've extended RandomNumberTest a bit: * Added a template for checking the mean and variance of a sample against the analytic values for two-parameter distributions, using a tiny inner-class wrapper. * Applied said template to Gamma, Normal, and Weibull dists. * Added couple of miscellaneous tests. I noticed that the Weibull mean and variance are not computed analytically, which could be an issue for users of that distribution. The attached file contains those changes. Note that the package name is what I used in my own testing, and will need to be changed if you replace the current RandomNumberTest.java with it. Chris On Tue, Jun 5, 2012 at 6:35 PM, Chris Lucas <cg...@gm...> wrote: > Hi -- > > I've noticed what appears to be a bug in org.ojalgo.random.Gamma. I > noticed that a Gamma(1,2) getDoubleValue() was returning negative > values. After looking at the documentation (thinking it was just a > non-standard parameterization at work) and confirming that the > empirical means don't align with the value of getExpected(), I looked > at the source (via > http://ojalgo.cvs.sourceforge.net/viewvc/ojalgo/DevProj/src/org/ojalgo/random/Gamma.java?revision=1.14&view=markup) > and found the following definition for generate() [which is called by > getDoubleValue() in RandomNumber()]: > > 60 @Override > 61 protected double generate() { > 62 > 63 double tmpVal = ZERO; > 64 > 65 for (int i = 0; i < myCount; i++) { > 66 tmpVal += this.random().nextDouble(); > 67 } > 68 > 69 return -tmpVal / myLambda; > 70 } > > The function this.random() is inherited from RandomNumber, and appears > to be a uniform distribution. Am I missing something? If not, this > appears to be a fairly serious bug for anyone who wants to use the > random number libraries. > > More generally, it appears that the test coverage in the random number > unit tests (at > http://ojalgo.cvs.sourceforge.net/viewvc/ojalgo/TestProj/src/org/ojalgo/random/RandomNumberTest.java?revision=1.11&view=markup) > is fairly limited. Perhaps some tests could be added to establish that > large-sample means are within certain easy-to-satisfy tolerances of > the intended expected values? > > Chris |