[Python-bugs-list] [Bug #130030] Claim of bad betavariate algorithm

noreply@sourceforge.net noreply@sourceforge.net
Thu, 25 Jan 2001 03:03:09 -0800


Bug #130030, was updated on 2001-Jan-25 03:03
Here is a current snapshot of the bug.

Project: Python
Category: Python Library
Status: Open
Resolution: None
Bug Group: Irreproducible
Priority: 5
Submitted by: tim_one
Assigned to : tim_one
Summary: Claim of bad betavariate algorithm

Details: From c.l.py.  Beats me, but sounds credible.  random.py cites
Discrete Event Simulation in C, pp 87-88, for its algorithm.

"""
[Janne Sinkkonen (mailto:janne@mansikka.nnets.fi)]

At least in Python 2.0 and earlier, the samples returned by the function
betavariate() of random.py are not from a beta distribution although the
function name misleadingly suggests so.

The following would give beta-distributed samples:

def betavariate(alpha, beta):
     y = gammavariate(alpha,1)
     if y==0: return 0.0
     else: return  y/(y+gammavariate(beta,1))

This is from matlab. A comment in the original matlab code refers to
Devroye, L. (1986) Non-Uniform Random Variate Generation, theorem 4.1A (p.
430). Another reference would be Gelman, A. et al. (1995) Bayesian data
analysis, p. 481, which I have checked and found to agree with the code
above.
"""


For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=130030&group_id=5470