| | |
-
- ABCRand
class ABCRand(metaclass=ABCMeta) |
| |
This class contains everything that is common to the GeneralRandomStream
and InverseRandomStream classes. Since this is also an abstract base
class, it cannot be used in a standalone fashion. Its methods and
attributes can only be reached through its subclasses GeneralRandomStream
and InverseRandomStream, which inherit from this class.
ABCRand imports (and uses) some of the methods from Python's built-in
Random class including the "Mersenne Twister". This makes the Mersenne
Twister the basic rng of ABCRand and its heirs. All methods in ABCRand
that are not taken from Random are inverse-based, but the methods from
Random are generally not inverse-based. It may be noted that the Mersenne
Twister is a very reputable random number generator having a period of
2**19937-1.
The following methods from Python's own Random class are inheritable from
ABCRand: randrange, randint, choice, shuffle, sample, vonmisesvariate,
paretovariate and weibullvariate.
All the methods in ABCRand are inherited by GeneralRandomStream including
the ones imported from Random. The methods added by GeneralRandomStream do
NOT return the inverse of the [0.0, 1.0] random numbers from the basic rng.
InverseRandomStream inherits the methods in ABCRand with the EXCEPTION
of the methods from Random (the Mersenne Twister is still there, though),
making all the methods in InverseRandomStream inverse-based, including
the methods added in the latter.
The docstring documentation of Random, GeneralRandomStream and
InverseRandomStream must always be consulted before using the methods
inherited from ABCRand!
NB Some methods may return float('inf') or float('-inf') ! |
| |
Methods defined here:
- __init__(self, nseed=2147483647, heir=None)
- Initiates the random stream using the input seed 'nseed' and Python's
__init__ constructor method. Unless...
...the input seed 'nseed' happens to be a list or tuple of numbers
in [0.0, 1.0], in which case this external feed will be used as the
basis of all random variate generation for the instance and will be
used in place of consecutively sampled numbers from Python's built-in
"random" method!
- rcauchy(self, location, scale, xmin=-inf, xmax=inf, pmin=0.0, pmax=1.0)
- Generator of random variates from the Cauchy distribution:
f = 1 / [s*pi*(1 + [(x-l)/s]**2)]
F = (1/pi)*arctan((x-l)/s) + 1/2
(also known as the Lorentzian or Lorentz distribution)
scale must be >= 0
- rchistogram(self, values, qumul)
- Generates random variates from an input CUMULATIVE histogram.
'values' is a list/tuple with FLOATS in ascending order - A MUST!
These values represent bin end points and must be one more than
the number of cumulative frequencies, and where...
...'qumul' are the corresponding CUMULATIVE FREQUENCIES such that
qumul[k] = P(x<=values[k+1]).
The cumulative frequencies must of course obey qumul[k+1] >= qumul[k],
otherwise an exception will be raised!
The values of the random variate are assumed to be uniformly
distributed within each bin.
- rchistogram_int(self, values, qumul)
- Generates random variates from an input CUMULATIVE histogram.
'values' is a list/tuple with INTEGERS in ascending order - A MUST!
These values represent bin end points and must be one more than
the number of cumulative frequencies, and where...
...'qumul' are the corresponding CUMULATIVE FREQUENCIES such that
qumul[k] = P(x<=values[k+1]).
NB The first element of the values list is will never be returned!
The first integer to be returned is values[0] + 1 !!!!
The cumulative frequencies must of course obey qumul[k+1] >= qumul[k],
otherwise an exception will be raised!
The integer values of the random variate are assumed to be uniformly
distributed within each bin.
- remp_exp(self, values, npexp=0, ordered=False, xmax=inf, pmax=1.0)
- The mixed expirical/exponential distribution from Bratley, Fox and
Schrage. A polygon (piecewise linearly interpolated cdf) is used
together with a (shifted) exponential for the tail. The procedure
is designed so as to preserve the mean of the input sample.
The input is a set of observed points (vector) and an integer
representing the npexp largest points that will be used to formulate
the exponential tail.
NB it is assumed that x is in [0, inf) (with the usual cutoff
provisions) !!!!!
The function may also be used for a piecewise linear cdf without the
exponential tail - corrections are made to preserve the mean in this
case as well !!!
- rexpo_gen(self, a, b, c, xmin=-inf, xmax=inf, pmin=0.0, pmax=1.0)
- The generalized continuous double-sided exponential
distribution (x in R):
x <= c: f = [a*b/(a+b)] * exp(+a*[x-c])
F = [b/(a+b)] * exp(+a*[x-c])
x >= c: f = [a*b/(a+b)] * exp(-b*[x-c])
F = 1 - [a/(a+b)]*exp(-b*[x-c])
a > 0, b > 0
NB The symmetrical double-sided exponential sits in rlaplace!
- rextreme_I(self, type, mu, scale, xmin=-inf, xmax=inf, pmin=0.0, pmax=1.0)
- Extreme value distribution type I (aka the Gumbel distribution or
Gumbel distribution type I):
F = exp{-exp[-(x-mu)/scale]} (max variant)
f = exp[-(x-mu)/scale] * exp{-exp[-(x-mu)/scale]} / scale
F = 1 - exp{-exp[+(x-mu)/scale]} (min variant)
f = exp[+(x-mu)/scale] * exp{-exp[+(x-mu)/scale]} / scale
type must be 'max' or 'min'
scale must be > 0.0
- rextreme_gen(self, type, shape, mu, scale, xmin=-inf, xmax=inf, pmin=0.0, pmax=1.0)
- Generalized extreme value distribution:
F = exp{-[1-shape*(x-mu)/scale]**(1/shape)} (max version)
f = [1-shape*(x-mu)/scale]**(1/shape-1) *
exp{-[1-shape*(x-mu)/scale]**(1/shape)} / scale
F = 1 - exp{-[1+shape*(x-mu)/scale]**(1/shape)} (min version)
f = [1+shape*(x-mu)/scale]**(1/shape-1) *
exp{-[1+shape*(x-mu)/scale]**(1/shape)} / scale
shape < 0 => Type II
shape > 0 => Type III
shape -> 0 => Type I - Gumbel
type must be 'max' or 'min'
scale must be > 0.0
A REASONABLE SCHEME SEEMS TO BE mu = scale WHICH SEEMS TO LIMIT THE
DISTRIBUTION TO EITHER SIDE OF THE Y-AXIS!
- rgeometric(self, phi)
- The geometric distribution with p(K=k) = phi * (1-phi)**(k-1) and
P(K>=k) = sum phi * (1-phi)**k = 1 - q**k, where q = 1 - phi and
0 < phi <= 1 is the success frequency or "Bernoulli probability"
and K >= 1 is the number of trials to the first success in a series
of Bernoulli trials. It is easy to prove that P(k) = 1 - (1-phi)**k:
let q = 1 - phi. p(k) = (1-q) * q**(k-1) = q**(k-1) - q**k. Then P(1) =
p(1) = 1 - q. P(2) = p(1) + p(2) = 1 - q + q - q**2 = 1 - q**2.
Induction can be used to show that P(k) = 1 - q**k = 1 - (1-phi)**k
- rkodlin(self, gam, eta, xmax=inf, pmax=1.0)
- The Kodlin distribution, aka the linear hazard rate distribution:
f = (gam + eta*x) * exp{-[gam*x + (1/2)*eta*x**2]},
F = 1 - exp{-[gam*x + (1/2)*eta*x**2]}; x, gam, eta >= 0
- rkumaraswamy(self, a, b, x1, x2)
- The Kumaraswamy distribution f = a*b*x**(a-1) * (1-x**a)**(b-1)
F = 1 - (1-x**a)**b
a, b >= 0; 0 <= x <= 1
The Kumaraswamy is very similar to the beta distribution !!!
x2 >= x1 !!!!
- rlaplace(self, loc, scale, xmin=-inf, xmax=inf, pmin=0.0, pmax=1.0)
- The Laplace aka the symmetrical double-sided exponential distribution
f = ((1/2)/s)) * exp(-abs([x-l]/s))
F = (1/2)*exp([x-l]/s) {x <= 0}, F = 1 - (1/2)*exp(-[x-l]/s) {x >= 0}
s >= 0
- rlogistic(self, mu, scale, xmin=-inf, xmax=inf, pmin=0.0, pmax=1.0)
- The logistic distribution: F = 1 / {1 + exp[-(x-m)/s]}; x on R
m is the mean and mode, and s is a scale parameter (s >= 0)
- rpareto_zero(self, lam, xm, xmax=inf, pmax=1.0)
- The Pareto distribution with the support shifted to [0, inf):
f = lam * xm**lam / (x+xm)**(lam+1)
F = 1 - [xm/(x+xm)]**lam
x in [0, inf)
lam > 0
For lam < 1 all moments are infinite
For lam < 2 all moments are infinite except for the mean
- rrayleigh(self, sigma, xmax=inf, pmax=1.0)
- The Rayleigh distribution:
f = (x/s**2) * exp[-x**2/(2*s**2)]
F = 1 - exp[-x**2/(2*s**2)]
x, s >= 0
- rsign(self)
- Returns -1.0 or 1.0 with probability 0.5 for each.
- rsinus(self, left, right)
- The "sinus distribution".
- rtri_unif_tri(self, a, b, c, d)
- Triangular-uniform-triangular distribution with support on [a, d] and
with breakpoints in b and c.
- rtriang(self, left, mode, right)
- Generator of triangularly distributed random numbers on [left, right]
with the peak of the pdf at mode.
- rtukeylambda_gen(self, lam1, lam2, lam3, lam4, pmin=0.0, pmax=1.0)
- The Friemer-Mudholkar-Kollia-Lin generalized Tukey lambda distribution.
lam1 is a location parameter and lam2 a scale parameter. lam3 and lam4
are associated with the shape of the distribution.
- runif_int0N(self, number)
- Generator of uniformly distributed integers in [0, n) (also the basis
of some other procedures for generating random variates).
Numbers returned are 0 through n-1.
- runifab(self, left, right)
- Generator of uniformly distributed floats between 'left' and 'right'.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes defined here:
- __abstractmethods__ = frozenset(['__init__'])
| |