Gumbel¶
- class paddle.distribution. Gumbel ( loc: float | Tensor, scale: float | Tensor ) [source]
-
The Gumbel distribution with location loc and scale parameters.
Mathematical details
The probability density function (pdf) is
pdf(x;mu,sigma)=exp(−(x−mu)/sigma−exp(−(x−mu)/sigma))/sigmaIn the above equation:
loc=μ: is the mean.
scale=σ: is the std.
- Parameters
-
loc (int|float|tensor) – The mean of gumbel distribution.The data type is int, float, tensor.
scale (int|float|tensor) – The std of gumbel distribution.The data type is int, float, tensor.
Examples
>>> import paddle >>> from paddle.distribution.gumbel import Gumbel >>> # Gumbel distributed with loc=0, scale=1 >>> dist = Gumbel(paddle.full([1], 0.0), paddle.full([1], 1.0)) >>> >>> print(dist.sample([2])) Tensor(shape=[2, 1], dtype=float32, place=Place(cpu), stop_gradient=True, [[0.40484068], [3.19400501]]) >>> print(dist.rsample([2])) Tensor(shape=[2, 1], dtype=float32, place=Place(cpu), stop_gradient=True, [[-0.95093185], [ 0.32422572]]) >>> >>> value = paddle.full([1], 0.5) >>> print(dist.prob(value)) Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True, [0.33070430]) >>> print(dist.log_prob(value)) Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True, [-1.10653067]) >>> print(dist.cdf(value)) Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True, [0.54523921]) >>> print(dist.entropy()) Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True, [1.57721567])
- property mean : Tensor
-
Mean of distribution
The mean is
mean = \mu + \sigma * γIn the above equation:
loc = \mu: is the location parameter.
scale = \sigma: is the scale parameter.
γ: is the euler’s constant.
- Returns
-
mean value.
- Return type
-
Tensor
- property variance : Tensor
-
Variance of distribution.
The variance is
variance = \sigma^2 * \pi^2 / 6In the above equation:
scale = \sigma: is the scale parameter.
- Returns
-
The variance value.
- Return type
-
Tensor
- property stddev : Tensor
-
Standard deviation of distribution
The standard deviation is
stddev = \sqrt{\sigma^2 * \pi^2 / 6}In the above equation: * scale = \sigma: is the scale parameter.
- Returns
-
std value
- Return type
-
Tensor
- property batch_shape : Sequence[int]
-
Returns batch shape of distribution
- Returns
-
batch shape
- Return type
-
Sequence[int]
- property event_shape : Sequence[int]
-
Returns event shape of distribution
- Returns
-
event shape
- Return type
-
Sequence[int]
-
kl_divergence
(
other: Distribution
)
Tensor
[source]
kl_divergence¶
-
The KL-divergence between self distributions and other.
-
prob
(
value: Tensor
)
Tensor
prob¶
-
Probability density/mass function
- Parameters
-
value (Tensor) – The input tensor.
- Returns
-
probability.The data type is same with value.
- Return type
-
Tensor
-
probs
(
value: Tensor
)
Tensor
probs¶
-
Probability density/mass function.
Note
This method will be deprecated in the future, please use prob instead.
-
log_prob
(
value: Tensor
)
Tensor
log_prob¶
-
Log probability density/mass function.
- Parameters
-
value (Tensor) – The input tensor.
- Returns
-
log probability.The data type is same with value.
- Return type
-
Tensor
-
cdf
(
value: Tensor
)
Tensor
cdf¶
-
Cumulative distribution function. :param value: value to be evaluated. :type value: Tensor
- Returns
-
cumulative probability of value.
- Return type
-
Tensor
-
entropy
(
)
Tensor
entropy¶
-
Entropy of Gumbel distribution.
- Returns
-
Entropy of distribution.
-
sample
(
shape: Sequence[int] = []
)
Tensor
sample¶
-
Sample from
Gumbel
.- Parameters
-
shape (Sequence[int], optional) – The sample shape. Defaults to [].
- Returns
-
A tensor with prepended dimensions shape.The data type is float32.
- Return type
-
Tensor
-
rsample
(
shape: Sequence[int] = []
)
Tensor
rsample¶
-
reparameterized sample :param shape: 1D int32. Shape of the generated samples. Defaults to []. :type shape: Sequence[int], optional
- Returns
-
A tensor with prepended dimensions shape.The data type is float32.
- Return type
-
Tensor