mindspore.nn.probability.distribution.Gumbel
- class mindspore.nn.probability.distribution.Gumbel(loc, scale, seed=0, dtype=mindspore.float32, name='Gumbel')[source]
Gumbel distribution.
- Parameters
loc (float, list, numpy.ndarray, Tensor) – The location of Gumbel distribution.
scale (float, list, numpy.ndarray, Tensor) – The scale of Gumbel distribution.
seed (int) – the seed used in sampling. The global seed is used if it is None. Default: None.
dtype (mindspore.dtype) – type of the distribution. Default: mstype.float32.
name (str) – the name of the distribution. Default: ‘Gumbel’.
- Supported Platforms:
Ascend
GPU
Note
scale must be greater than zero. dist_spec_args are loc and scale. dtype must be a float type because Gumbel distributions are continuous. kl_loss and cross_entropy are not supported on GPU backend.
Examples
>>> import mindspore >>> import mindspore.context as context >>> import mindspore.nn as nn >>> import mindspore.nn.probability.distribution as msd >>> from mindspore import Tensor >>> context.set_context(mode=1) >>> # To initialize a Gumbel distribution of `loc` 3.0 and `scale` 4.0. >>> gumbel = msd.Gumbel(3.0, 4.0, dtype=mindspore.float32) >>> # Private interfaces of probability functions corresponding to public interfaces, including >>> # `prob`, `log_prob`, `cdf`, `log_cdf`, `survival_function`, and `log_survival`, have the same >>> # arguments as follows. >>> # Args: >>> # value (Tensor): the value to be evaluated. >>> # Examples of `prob`. >>> # Similar calls can be made to other probability functions >>> # by replacing 'prob' by the name of the function. >>> value = Tensor([1.0, 2.0, 3.0], dtype=mindspore.float32) >>> ans = gumbel.prob(value) >>> print(ans.shape) (3,) >>> # Functions `mean`, `mode`, sd`, `var`, and `entropy` do not take in any argument. >>> ans = gumbel.mean() >>> print(ans.shape) () >>> # Interfaces of 'kl_loss' and 'cross_entropy' are the same: >>> # Args: >>> # dist (str): the type of the distributions. Only "Gumbel" is supported. >>> # loc_b (Tensor): the loc of distribution b. >>> # scale_b (Tensor): the scale distribution b. >>> # Examples of `kl_loss`. `cross_entropy` is similar. >>> loc_b = Tensor([1.0], dtype=mindspore.float32) >>> scale_b = Tensor([1.0, 1.5, 2.0], dtype=mindspore.float32) >>> ans = gumbel.kl_loss('Gumbel', loc_b, scale_b) >>> print(ans.shape) (3,) >>> # Examples of `sample`. >>> # Args: >>> # shape (tuple): the shape of the sample. Default: () >>> ans = gumbel.sample() >>> print(ans.shape) () >>> ans = gumbel.sample((2,3)) >>> print(ans.shape)
- property loc
Return the location of the distribution after casting to dtype.
- property scale
Return the scale of the distribution after casting to dtype.