The Beta distribution is a special case of the Dirichlet distribution,
and is related to the Gamma distribution. It has the probability
distribution function
It is often seen in Bayesian inference and order statistics.
Parameters:
a (float or array_like of floats) – Alpha, positive (>0).
b (float or array_like of floats) – Beta, positive (>0).
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if a and b are both scalars.
Otherwise, np.broadcast(a,b).size samples are drawn.
dtype ({'float16', 'float32', 'float64'}, optional) – Data type of output samples. Default is ‘float32’.
Dtype ‘float32’ or ‘float64’ is strongly recommended,
since lower precision might lead to out of range issue.
device (Device, optional) – Device context of output. Default is current device.
Notes
To use this operator with scalars as input, please run
npx.set_np() first.
Returns:
out – Drawn samples from the parameterized beta distribution.
When df independent random variables, each with standard normal
distributions (mean 0, variance 1), are squared and summed, the
resulting distribution is chi-square (see Notes). This distribution
is often used in hypothesis testing.
Parameters:
df (float or ndarray of floats) – Number of degrees of freedom, must be > 0.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if df is a scalar. Otherwise,
np.array(df).size samples are drawn.
dtype ({'float16', 'float32', 'float64'}, optional) – Data type of output samples. Default is ‘float32’.
device (Device, optional) – Device context of output. Default is current device.
Returns:
out – Drawn samples from the parameterized chi-square distribution [1]_.
a (1-D array-like or int) – If an ndarray, a random sample is generated from its elements.
If an int, the random sample is generated as if a were np.arange(a)
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. Default is None, in which case a
single value is returned.
replace (boolean, optional) – Whether the sample is with or without replacement
p (1-D array-like, optional) – The probabilities associated with each entry in a.
If not given the sample assumes a uniform distribution over all
entries in a.
device (Device, optional) – Device context of output. Default is current device.
scale (float or array_like of floats) – The scale parameter, \(\beta = 1/\lambda\). Must be
non-negative.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if scale is a scalar. Otherwise,
np.array(scale).size samples are drawn.
device (Device, optional) – Device context of output, default is current device.
out (ndarray, optional) – Store output to an existing ndarray.
Returns:
out – Drawn samples from the parameterized exponential distribution.
Samples are drawn from an F distribution with specified parameters,
dfnum (degrees of freedom in numerator) and dfden (degrees of
freedom in denominator), where both parameters must be greater than
zero.
The random variate of the F distribution (also known as the
Fisher distribution) is a continuous probability distribution
that arises in ANOVA tests, and is the ratio of two chi-square
variates.
Parameters:
dfnum (float or ndarray of floats) – Degrees of freedom in numerator, must be > 0.
dfden (float or ndarray of float) – Degrees of freedom in denominator, must be > 0.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if dfnum and dfden are both scalars.
Otherwise, np.broadcast(dfnum,dfden).size samples are drawn.
device (Device, optional) – Device context of output. Default is current device.
Returns:
out – Drawn samples from the parameterized Fisher distribution.
Two groups, children of diabetics (25 people) and children from people
without diabetes (25 controls). Fasting blood glucose was measured,
case group had a mean value of 86.1, controls had a mean value of
82.2. Standard deviations were 2.09 and 2.49 respectively. Are these
data consistent with the null hypothesis that the parents diabetic
status does not affect their children’s blood glucose levels?
Calculating the F statistic from the data gives a value of 36.01.
Draw samples from the distribution:
>>> dfnum=1.# between group degrees of freedom>>> dfden=48.# within groups degrees of freedom>>> s=np.random.f(dfnum,dfden,1000)
The lower bound for the top 1% of the samples is :
>>> np.sort(s)[-10]7.61988120985 # random
So there is about a 1% chance that the F statistic will exceed 7.62,
the measured value is 36, so the null hypothesis is rejected at the 1%
level.
Samples are drawn from a Gamma distribution with specified parameters,
shape (sometimes designated “k”) and scale (sometimes designated
“theta”), where both parameters are > 0.
The Gamma distribution is often used to model the times to failure of
electronic components, and arises naturally in processes for which the
waiting times between Poisson distributed events are relevant.
Parameters:
shape (float or array_like of floats) – The shape of the gamma distribution. Should be greater than zero.
scale (float or array_like of floats, optional) – The scale of the gamma distribution. Should be greater than zero.
Default is equal to 1.
dtype ({'float16', 'float32', 'float64'}, optional) – Data type of output samples. Default is ‘float32’.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if shape and scale are both scalars.
Otherwise, np.broadcast(shape,scale).size samples are drawn.
device (Device, optional) – Device context of output. Default is current device.
Returns:
out – Drawn samples from the parameterized gamma distribution.
Draw samples from a Gumbel distribution with specified location and
scale.
Parameters:
loc (float or array_like of floats, optional) – The location of the mode of the distribution. Default is 0.
scale (float or array_like of floats, optional) – The scale parameter of the distribution. Default is 1. Must be non-
negative.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if loc and scale are both scalars.
Otherwise, np.broadcast(loc,scale).size samples are drawn.
device (Device, optional) – Device context of output, default is current device.
out (ndarray, optional) – Store output to an existing ndarray.
Returns:
out – Drawn samples from the parameterized Gumbel distribution.
size (int or tuple of ints, optional. Output shape.) – If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn.
Default is None, in which case a single value is returned.
dtype ({'float16', 'float32', 'float64'}, optional) – Data type of output samples. Default is ‘float32’
device (Device, optional) – Device context of output. Default is current device.
out (ndarray, optional) – Store output to an existing ndarray.
Returns:
out – Drawn samples from the parameterized Laplace distribution.
Samples are drawn from a logistic distribution with specified
parameters, loc (location or mean, also median), and scale (>0).
Parameters:
loc (float or array_like of floats, optional) – Parameter of the distribution. Default is 0.
scale (float or array_like of floats, optional) – Parameter of the distribution. Must be non-negative.
Default is 1.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if loc and scale are both scalars.
Otherwise, np.broadcast(loc,scale).size samples are drawn.
device (Device, optional) – Device context of output, default is current device.
out (ndarray, optional) – Store output to an existing ndarray.
Returns:
out – Drawn samples from the parameterized logistic distribution.
Draw samples from a log-normal distribution [1]_ with specified mean,
standard deviation, and array shape. Note that the mean and standard
deviation are not the values for the distribution itself, but of the
underlying normal distribution it is derived from.
Parameters:
mean (float or array_like of floats, optional) – Mean value of the underlying normal distribution. Default is 0.
sigma (float or array_like of floats, optional) – Standard deviation of the underlying normal distribution. Must be
non-negative. Default is 1.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if mean and sigma are both scalars.
Otherwise, np.broadcast(mean,sigma).size samples are drawn.
dtype ({'float16', 'float32', 'float64'}, optional) – Data type of output samples. Default is ‘float32’
device (Device, optional) – Device context of output. Default is current device.
out (ndarray, optional) – Store output to an existing ndarray.
Returns:
out – Drawn samples from the parameterized log-normal distribution.
A variable x has a log-normal distribution if log(x) is normally
distributed. The probability density function for the log-normal
distribution [2]_ is:
\[p(x) = \frac{1}{\sigma x \sqrt{2\pi}}
e^{(-\frac{(ln(x)-\mu)^2}{2\sigma^2})}\]
where \(\mu\) is the mean and \(\sigma\) is the standard
deviation of the normally distributed logarithm of the variable.
A log-normal distribution results if a random variable is the product
of a large number of independent, identically-distributed variables in
the same way that a normal distribution results if the variable is the
sum of a large number of independent, identically-distributed
variables.
References
Examples
Draw samples from the distribution:
>>> mu, sigma = 3., 1. # mean and standard deviation
>>> s = np.random.lognormal(mu, sigma, 1000)
Draw samples from a multinomial distribution.
The multinomial distribution is a multivariate generalisation of the binomial distribution.
Take an experiment with one of p possible outcomes. An example of such an experiment is throwing a dice,
where the outcome can be 1 through 6. Each sample drawn from the distribution represents n such experiments.
Its values, X_i=[X_0,X_1,...,X_p], represent the number of times the outcome was i.
pvals (sequence of floats, length p) – Probabilities of each of the p different outcomes. These should sum to 1.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then m*n*k samples
are drawn. Default is None, in which case a single value is returned.
Returns:
out – The drawn samples, of shape size, if that was provided. If not, the shape is (N,).
In other words, each entry out[i,j,...,:] is an N-dimensional value drawn from the distribution.
Draw random samples from a multivariate normal distribution.
The multivariate normal, multinormal or Gaussian distribution is a
generalization of the one-dimensional normal distribution to higher
dimensions. Such a distribution is specified by its mean and
covariance matrix. These parameters are analogous to the mean
(average or “center”) and variance (standard deviation, or “width,”
squared) of the one-dimensional normal distribution.
This operator is a little different from the one in official NumPy.
The official NumPy operator only accepts 1-D ndarray as mean and 2-D ndarray as cov,
whereas the operator in MXNet np supports batch operation and auto-broadcasting.
Both mean and cov may have any number of leading dimensions, which correspond
to a batch shape. They are not necessarily assumed to have the same batch shape,
just ones which can be broadcasted.
Parameters:
mean (K-D ndarray, of shape (..., N)) – Mean of the N-dimensional distribution.
cov ((K+1)-D ndarray, of shape (..., N, N)) – Covariance matrix of the distribution. The last two dimensions must be symmetric and
positive-semidefinite for proper sampling.
size (int or tuple of ints, optional) – Given a shape of, for example, (m,n,k),
m*n*k identically distributed batchs of samples are
generated, and packed in an m-by-n-by-k arrangement.
If no shape is specified, a batch of (N-D) sample is returned.
check_valid ({ 'warn', 'raise', 'ignore' }, optional) – Behavior when the covariance matrix is not positive semidefinite.
(Not supported)
tol (float, optional) – Tolerance when checking the singular values in covariance matrix.
cov is cast to double before the check.
(Not supported)
Returns:
out – The input shape of mean and cov should satisfy the requirements of broadcasting.
If the parameter size is not provided,
the output shape is np.broadcast(mean.shape,cov.shape[:-1]).
Otherwise, the output shape is size+np.broadcast(mean.shape,cov.shape[:-1])
Draw random samples from a normal (Gaussian) distribution.
Samples are distributed according to a normal distribution parametrized
by loc (mean) and scale (standard deviation).
Parameters:
loc (float, optional) – Mean (centre) of the distribution.
scale (float, optional) – Standard deviation (spread or “width”) of the distribution.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m, n, k), then m * n * k
samples are drawn. If size is None (default), a scalar tensor containing
a single value is returned if loc and scale are both scalars. Otherwise,
np.broadcast(low,high).size samples are drawn.
dtype ({'float16', 'float32', 'float64'}, optional) – Data type of output samples.
When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
device (Device, optional) – Device context of output, default is current device.
out (ndarray, optional) – Store output to an existing ndarray.
Returns:
out – Drawn samples from the parameterized normal distribution [1]_.
where \(\mu\) is the mean and \(\sigma\) the standard
deviation. The square of the standard deviation, \(\sigma^2\),
is called the variance.
The function has its peak at the mean, and its “spread” increases with
the standard deviation (the function reaches 0.607 times its maximum at
\(x + \sigma\) and \(x - \sigma\)[2]_). This implies that
numpy.random.normal is more likely to return samples lying close to
the mean, rather than those far away.
References
Examples
>>> mu,sigma=0,0.1# mean and standard deviation>>> s=np.random.normal(mu,sigma,1000)
Draw samples from a Pareto II or Lomax distribution with specified shape a.
Parameters:
a (float or array_like of floats) – Shape of the distribution. Must be > 0.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if a is a scalar. Otherwise,
np.array(a).size samples are drawn.
>>> np.random.pareto(a=5)array(0.12749612)>>> mx.numpy.random.pareto(a=5,size=[2,3])array([[0.06933999, 0.0344373 , 0.10654891], [0.0311172 , 0.12911797, 0.03370714]])>>> np.random.pareto(a=np.array([2,3])array([0.26636696, 0.15685666])The probability density for the Pareto distribution is f(x) = \frac{am^a}{x^{a+1}}where a is the shape and m the scale. Here m is assumed 1. The Pareto distributionis a power law distribution. Pareto created it to describe the wealth in the economy.
Draw samples in [0, 1] from a power distribution with given parameter a.
Parameters:
a (float or array_like of floats) – Shape of the distribution. Must be > 0.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if a is a scalar. Otherwise,
np.array(a).size samples are drawn.
>>> np.random.power(a=5)array(0.8602478)>>> np.random.power(a=5,size=[2,3])array([[0.988391 , 0.5153122 , 0.9383134 ], [0.9078098 , 0.87819266, 0.730635]])>>> np.random.power(a=np.array([2,3])array([0.7499419 , 0.88894516])The probability density function is f(x; a) = ax^{a-1}, 0 \le x \le 1, a>0.The power distribution is just the inverse of the Pareto distribution anda special case of the Beta distribution.
Return random integers from low (inclusive) to high (exclusive).
Return random integers from the “discrete uniform” distribution of
the specified dtype in the “half-open” interval [low, high). If
high is None (the default), then results are from [0, low).
Parameters:
low (int) – Lowest (signed) integer to be drawn from the distribution (unless
high=None, in which case this parameter is one above the
highest such integer).
high (int, optional) – If provided, one above the largest (signed) integer to be drawn
from the distribution (see above for behavior if high=None).
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. Default is None, in which case a
single value is returned.
dtype (dtype, optional) – Desired dtype of the result. All dtypes are determined by their
name, i.e., ‘int64’, ‘int’, etc, so byteorder is not available
and a specific precision may have different C types depending
on the platform. The default value is ‘np.int’.
device (Device, optional) – Device context of output. Default is current device.
out (ndarray, optional) – The output ndarray (default is None).
Returns:
out – size-shaped array of random integers from the appropriate
distribution, or a single such random int if size not provided.
Return a sample (or samples) from the “standard normal” distribution.
If positive, int_like or int-convertible arguments are provided,
randn generates an array of shape (d0,d1,...,dn), filled
with random floats sampled from a univariate “normal” (Gaussian)
distribution of mean 0 and variance 1 (if any of the \(d_i\) are
floats, they are first converted to integers by truncation). A single
float randomly sampled from the distribution is returned if no
argument is provided.
This is a convenience function. If you want an interface that takes a
tuple as the first argument, use numpy.random.standard_normal instead.
Parameters:
d0 (int, optional) – The dimensions of the returned array, should be all positive.
If no argument is given a single Python float is returned.
d1 (int, optional) – The dimensions of the returned array, should be all positive.
If no argument is given a single Python float is returned.
... (int, optional) – The dimensions of the returned array, should be all positive.
If no argument is given a single Python float is returned.
dn (int, optional) – The dimensions of the returned array, should be all positive.
If no argument is given a single Python float is returned.
Returns:
Z – A (d0,d1,...,dn)-shaped array of floating-point samples from
the standard normal distribution, or a single such float if
no parameters were supplied.
The \(\chi\) and Weibull distributions are generalizations of the
Rayleigh.
Parameters:
scale (float, optional) – Scale, also equals the mode. Must be non-negative. Default is 1.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if scale is a scalar. Otherwise,
np.array(scale).size samples are drawn.
device (Device, optional) – Device context of output, default is current device.
out (ndarray, optional) – Store output to an existing ndarray.
Returns:
out – Drawn samples from the parameterized Rayleigh distribution.
device (Device) – The device context of the generator. The default is “all” which means seeding random
number generators of all devices.
Notes
Random number generators in MXNet are device specific.
mx.random.seed(seed_state) sets the state of each generator using seed_state and the
device id. Therefore, random numbers generated from different devices can be different
even if they are seeded using the same seed.
To produce identical random number sequences independent of the device id,
set optional device argument. This produces the same sequence of random numbers independent
of the device id, but the sequence can be different on different kind of devices as MXNet’s
random number generators for CPU and GPU use different algorithms.
Example
>>> print(mx.np.random.normal(shape=(2,2)).asnumpy())[[ 1.36481571 -0.62203991] [-1.4962182 -0.08511394]]>>> print(mx.np.random.normal(shape=(2,2)).asnumpy())[[ 1.09544981 -0.20014545] [-0.20808885 0.2527658 ]]# Same results on the same device with the same seed>>> mx.np.random.seed(128)>>> print(mx.np.random.normal(shape=(2,2)).asnumpy())[[ 0.47400656 -0.75213492] [ 0.20251541 0.95352972]]>>> mx.np.random.seed(128)>>> print(mx.np.random.normal(shape=(2,2)).asnumpy())[[ 0.47400656 -0.75213492] [ 0.20251541 0.95352972]]# Different results on gpu(0) and gpu(1) with the same seed>>> mx.np.random.seed(128)>>> print(mx.np.random.normal(shape=(2,2),device=mx.gpu(0)).asnumpy())[[ 2.5020072 -1.6884501] [-0.7931333 -1.4218881]]>>> mx.np.random.seed(128)>>> print(mx.np.random.normal(shape=(2,2),device=mx.gpu(1)).asnumpy())[[ 0.24336822 -1.664805 ] [-1.0223296 1.253198 ]]# Seeding with `device` argument produces identical results on gpu(0) and gpu(1)>>> mx.np.random.seed(128,device=mx.gpu(0))>>> print(mx.np.random.normal(shape=(2,2),device=mx.gpu(0)).asnumpy())[[ 2.5020072 -1.6884501] [-0.7931333 -1.4218881]]>>> mx.np.random.seed(128,device=mx.gpu(1))>>> print(mx.np.random.normal(shape=(2,2),device=mx.gpu(1)).asnumpy())[[ 2.5020072 -1.6884501] [-0.7931333 -1.4218881]]
Modify a sequence in-place by shuffling its contents.
This function only shuffles the array along the first axis of a
multi-dimensional array. The order of sub-arrays is changed but
their contents remain the same.
Samples are uniformly distributed over the half-open interval
[low,high) (includes low, but excludes high). In other words,
any value within the given interval is equally likely to be drawn
by uniform.
Parameters:
low (float, ndarray, optional) – Lower boundary of the output interval. All values generated will be
greater than or equal to low. The default value is 0.
high (float, ndarray, optional) – Upper boundary of the output interval. All values generated will be
less than high. The default value is 1.0.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a scalar tensor containing a single value is returned if
low and high are both scalars. Otherwise,
np.broadcast(low,high).size samples are drawn.
dtype ({'float16', 'float32', 'float64'}, optional) – Data type of output samples.
When npx.is_np_default_dtype() returns False, default dtype is float32;
When npx.is_np_default_dtype() returns True, default dtype is float64.
device (Device, optional) – Device context of output. Default is current device.
Returns:
out – Drawn samples from the parameterized uniform distribution.
Convenience function that accepts dimensions as input, e.g., rand(2,2) would generate a 2-by-2 array of floats, uniformly distributed over [0,1).
Notes
The probability density function of the uniform distribution is
\[p(x) = \frac{1}{b - a}\]
anywhere within the interval [a,b), and zero elsewhere.
When high == low, values of low will be returned.
If high < low, the results are officially undefined
and may eventually raise an error, i.e. do not rely on this
function to behave when passed arguments satisfying that
inequality condition.
Draw samples from a 1-parameter Weibull distribution with given parameter a
via inversion.
Parameters:
a (float or array_like of floats) – Shape of the distribution. Must be non-negative.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m,n,k), then
m*n*k samples are drawn. If size is None (default),
a single value is returned if a is a scalar. Otherwise,
np.array(a).size samples are drawn.
Returns:
out – Drawn samples from the 1-parameter Weibull distribution.
>>> np.random.weibull(a=5)array(0.9553641)>>> np.random.weibull(a=5,size=[2,3])array([[1.0466299 , 1.1320982 , 0.98415005], [1.1430776 , 0.9532727 , 1.1344457 ]])>>> np.random.weibull(a=np.array([2,3])array([0.98843634, 1.0125613 ])The Weibull distribution is one of a class of Generalized ExtremeValue (GEV) distributions. This class includes the Gumbel and Frechetdistributions.The probability density for the Weibull distribution isf(x) = \frac{a}{\lambda}(\frac{x}{\lambda})^{a-1}e^{-(x/\lambda)^a},where a is the shape and \lambda the scale. The generated 1-parameter Weibullsample has the scale parameter \lambda = 1.The Weibull distribution is commonly used in reliability engineering tomodel time to failure, in modeling particle sizes, in information retrievalto model dwell time on pages, in quantitative finance to model risk etc.