[Python-bugs-list] [Bug #130030] Claim of bad betavariate algorithm
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 25 Jan 2001 13:36:08 -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: None
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.
"""
Follow-Ups:
Date: 2001-Jan-25 13:36
By: tim_one
Comment:
I have no idea why the Group was set to Irreproducible, but have seen that
on other recent new bug reports too -- maybe a new SF buglet.
Anyway, changed group to None. Ivan Frohne helpfully investigated this,
and made what looks to be a very strong case for adopting the algorithm
Janne suggests.
-------------------------------------------------------
For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=130030&group_id=5470