mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
SF bug 130030: Claim of bad betavariate algorithm.
This commit is contained in:
parent
2786543b70
commit
85e2e4742d
2 changed files with 21 additions and 7 deletions
|
@ -461,14 +461,27 @@ class Random:
|
||||||
return mu + z*sigma
|
return mu + z*sigma
|
||||||
|
|
||||||
## -------------------- beta --------------------
|
## -------------------- beta --------------------
|
||||||
|
## See
|
||||||
|
## http://sourceforge.net/bugs/?func=detailbug&bug_id=130030&group_id=5470
|
||||||
|
## for Ivan Frohne's insightful analysis of why the original implementation:
|
||||||
|
##
|
||||||
|
## def betavariate(self, alpha, beta):
|
||||||
|
## # Discrete Event Simulation in C, pp 87-88.
|
||||||
|
##
|
||||||
|
## y = self.expovariate(alpha)
|
||||||
|
## z = self.expovariate(1.0/beta)
|
||||||
|
## return z/(y+z)
|
||||||
|
##
|
||||||
|
## was dead wrong, and how it probably got that way.
|
||||||
|
|
||||||
def betavariate(self, alpha, beta):
|
def betavariate(self, alpha, beta):
|
||||||
|
# This version due to Janne Sinkkonen, and matches all the std
|
||||||
# Discrete Event Simulation in C, pp 87-88.
|
# texts (e.g., Knuth Vol 2 Ed 3 pg 134 "the beta distribution").
|
||||||
|
y = self.gammavariate(alpha, 1.)
|
||||||
y = self.expovariate(alpha)
|
if y == 0:
|
||||||
z = self.expovariate(1.0/beta)
|
return 0.0
|
||||||
return z/(y+z)
|
else:
|
||||||
|
return y / (y + self.gammavariate(beta, 1.))
|
||||||
|
|
||||||
## -------------------- Pareto --------------------
|
## -------------------- Pareto --------------------
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ Sebastian Fernandez
|
||||||
Nils Fischbeck
|
Nils Fischbeck
|
||||||
Doug Fort
|
Doug Fort
|
||||||
Robin Friedrich
|
Robin Friedrich
|
||||||
Ivan Frohe
|
Ivan Frohne
|
||||||
Jim Fulton
|
Jim Fulton
|
||||||
Geoff Furnish
|
Geoff Furnish
|
||||||
Tadayoshi Funaba
|
Tadayoshi Funaba
|
||||||
|
@ -338,6 +338,7 @@ Joel Shprentz
|
||||||
Eric Siegerman
|
Eric Siegerman
|
||||||
Paul Sijben
|
Paul Sijben
|
||||||
Nathan Paul Simons
|
Nathan Paul Simons
|
||||||
|
Janne Sinkkonen
|
||||||
George Sipe
|
George Sipe
|
||||||
Kragen Sitaker
|
Kragen Sitaker
|
||||||
Rafal Smotrzyk
|
Rafal Smotrzyk
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue