|
24 | 24 | negative exponential
|
25 | 25 | gamma
|
26 | 26 | beta
|
27 |
| - binomial |
28 | 27 | pareto
|
29 | 28 | Weibull
|
30 | 29 |
|
|
33 | 32 | circular uniform
|
34 | 33 | von Mises
|
35 | 34 |
|
| 35 | + discrete distributions |
| 36 | + ---------------------- |
| 37 | + binomial |
| 38 | +
|
| 39 | +
|
36 | 40 | General notes on the underlying Mersenne Twister core generator:
|
37 | 41 |
|
38 | 42 | * The period is 2**19937-1.
|
@@ -731,6 +735,26 @@ def betavariate(self, alpha, beta):
|
731 | 735 | return y / (y + self.gammavariate(beta, 1.0))
|
732 | 736 | return 0.0
|
733 | 737 |
|
| 738 | + def paretovariate(self, alpha): |
| 739 | + """Pareto distribution. alpha is the shape parameter.""" |
| 740 | + # Jain, pg. 495 |
| 741 | + |
| 742 | + u = 1.0 - self.random() |
| 743 | + return u ** (-1.0 / alpha) |
| 744 | + |
| 745 | + def weibullvariate(self, alpha, beta): |
| 746 | + """Weibull distribution. |
| 747 | +
|
| 748 | + alpha is the scale parameter and beta is the shape parameter. |
| 749 | +
|
| 750 | + """ |
| 751 | + # Jain, pg. 499; bug fix courtesy Bill Arms |
| 752 | + |
| 753 | + u = 1.0 - self.random() |
| 754 | + return alpha * (-_log(u)) ** (1.0 / beta) |
| 755 | + |
| 756 | + |
| 757 | + ## -------------------- discrete distributions --------------------- |
734 | 758 |
|
735 | 759 | def binomialvariate(self, n=1, p=0.5):
|
736 | 760 | """Binomial random variable.
|
@@ -816,25 +840,6 @@ def binomialvariate(self, n=1, p=0.5):
|
816 | 840 | return k
|
817 | 841 |
|
818 | 842 |
|
819 |
| - def paretovariate(self, alpha): |
820 |
| - """Pareto distribution. alpha is the shape parameter.""" |
821 |
| - # Jain, pg. 495 |
822 |
| - |
823 |
| - u = 1.0 - self.random() |
824 |
| - return u ** (-1.0 / alpha) |
825 |
| - |
826 |
| - def weibullvariate(self, alpha, beta): |
827 |
| - """Weibull distribution. |
828 |
| -
|
829 |
| - alpha is the scale parameter and beta is the shape parameter. |
830 |
| -
|
831 |
| - """ |
832 |
| - # Jain, pg. 499; bug fix courtesy Bill Arms |
833 |
| - |
834 |
| - u = 1.0 - self.random() |
835 |
| - return alpha * (-_log(u)) ** (1.0 / beta) |
836 |
| - |
837 |
| - |
838 | 843 | ## ------------------------------------------------------------------
|
839 | 844 | ## --------------- Operating System Random Source ------------------
|
840 | 845 |
|
|
0 commit comments