[ojAlgo-user] apparent bug in Gamma distribution
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Chris L. <cg...@gm...> - 2012-06-05 22:36:09
|
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 |