mindspore.nn.probability.distribution.Beta
- class mindspore.nn.probability.distribution.Beta(concentration1=None, concentration0=None, seed=None, dtype=mstype.float32, name='Beta')[源代码]
- Beta 分布(Beta Distribution)。 连续随机分布,取值范围为 \([0, 1]\) ,概率密度函数为 \[f(x, \alpha, \beta) = x^\alpha (1-x)^{\beta - 1} / B(\alpha, \beta)\]- 其中 \(B\) 为 Beta 函数。 - 参数:
- concentration1 (int, float, list, numpy.ndarray, Tensor) - Beta 分布的alpha。默认值: - None。
- concentration0 (int, float, list, numpy.ndarray, Tensor) - Beta 分布的beta。默认值: - None。
- seed (int) - 采样时使用的种子。如果为None,则使用全局种子。默认值: - None。
- dtype (mindspore.dtype) - 采样结果的数据类型。默认值: - mstype.float32。
- name (str) - 分布的名称。默认值: - 'Beta'。
 
 - 说明 - concentration1 和 concentration0 中元素必须大于零。 
- dist_spec_args 是 concentration1 和 concentration0。 
- dtype 必须是float,因为 Beta 分布是连续的。 
 - 异常:
- ValueError - concentration1 或者 concentration0 中元素小于0。 
- TypeError - dtype 不是float的子类。 
 
- 支持平台:
- Ascend
 - 样例: - >>> import mindspore >>> import mindspore.nn as nn >>> import mindspore.nn.probability.distribution as msd >>> from mindspore import Tensor >>> # To initialize a Beta distribution of the concentration1 3.0 and the concentration0 4.0. >>> b1 = msd.Beta([3.0], [4.0], dtype=mindspore.float32) >>> # A Beta distribution can be initialized without arguments. >>> # In this case, `concentration1` and `concentration0` must be passed in through arguments. >>> b2 = msd.Beta(dtype=mindspore.float32) >>> # Here are some tensors used below for testing >>> value = Tensor([0.1, 0.5, 0.8], dtype=mindspore.float32) >>> concentration1_a = Tensor([2.0], dtype=mindspore.float32) >>> concentration0_a = Tensor([2.0, 2.0, 2.0], dtype=mindspore.float32) >>> concentration1_b = Tensor([1.0], dtype=mindspore.float32) >>> concentration0_b = Tensor([1.0, 1.5, 2.0], dtype=mindspore.float32) >>> # Private interfaces of probability functions corresponding to public interfaces, including >>> # `prob` and `log_prob`, have the same arguments as follows. >>> # Args: >>> # value (Tensor): the value to be evaluated. >>> # concentration1 (Tensor): the concentration1 of the distribution. Default: self._concentration1. >>> # concentration0 (Tensor): the concentration0 of the distribution. Default: self._concentration0. >>> # Examples of `prob`. >>> # Similar calls can be made to other probability functions >>> # by replacing 'prob' by the name of the function >>> ans = b1.prob(value) >>> print(ans.shape) (3,) >>> # Evaluate with respect to the distribution b. >>> ans = b1.prob(value, concentration1_b, concentration0_b) >>> print(ans.shape) (3,) >>> # `concentration1` and `concentration0` must be passed in during function calls >>> ans = b2.prob(value, concentration1_a, concentration0_a) >>> print(ans.shape) (3,) >>> # Functions `mean`, `sd`, `mode`, `var`, and `entropy` have the same arguments. >>> # Args: >>> # concentration1 (Tensor): the concentration1 of the distribution. Default: self._concentration1. >>> # concentration0 (Tensor): the concentration0 of the distribution. Default: self._concentration0. >>> # Example of `mean`, `sd`, `mode`, `var`, and `entropy` are similar. >>> ans = b1.mean() >>> print(ans.shape) (1,) >>> ans = b1.mean(concentration1_b, concentration0_b) >>> print(ans.shape) (3,) >>> # `concentration1` and `concentration0` must be passed in during function calls. >>> ans = b2.mean(concentration1_a, concentration0_a) >>> print(ans.shape) (3,) >>> # Interfaces of 'kl_loss' and 'cross_entropy' are the same: >>> # Args: >>> # dist (str): the type of the distributions. Only "Beta" is supported. >>> # concentration1_b (Tensor): the concentration1 of distribution b. >>> # concentration0_b (Tensor): the concentration0 of distribution b. >>> # concentration1_a (Tensor): the concentration1 of distribution a. >>> # Default: self._concentration1. >>> # concentration0_a (Tensor): the concentration0 of distribution a. >>> # Default: self._concentration0. >>> # Examples of `kl_loss`. `cross_entropy` is similar. >>> ans = b1.kl_loss('Beta', concentration1_b, concentration0_b) >>> print(ans.shape) (3,) >>> ans = b1.kl_loss('Beta', concentration1_b, concentration0_b, concentration1_a, concentration0_a) >>> print(ans.shape) (3,) >>> # Additional `concentration1` and `concentration0` must be passed in. >>> ans = b2.kl_loss('Beta', concentration1_b, concentration0_b, concentration1_a, concentration0_a) >>> print(ans.shape) (3,) >>> # Examples of `sample`. >>> # Args: >>> # shape (tuple): the shape of the sample. Default: () >>> # concentration1 (Tensor): the concentration1 of the distribution. Default: self._concentration1. >>> # concentration0 (Tensor): the concentration0 of the distribution. Default: self._concentration0. >>> ans = b1.sample() >>> print(ans.shape) (1,) >>> ans = b1.sample((2,3)) >>> print(ans.shape) (2, 3, 1) >>> ans = b1.sample((2,3), concentration1_b, concentration0_b) >>> print(ans.shape) (2, 3, 3) >>> ans = b2.sample((2,3), concentration1_a, concentration0_a) >>> print(ans.shape) (2, 3, 3) - property concentration0
- 返回concentration0(也称为 Beta 分布的 beta)。 - 返回:
- Tensor,concentration0 的值。 
 
 - property concentration1
- 返回concentration1(也称为 Beta 分布的 alpha)。 - 返回:
- Tensor,concentration1 的值。 
 
 - cdf(value, concentration1, concentration0)
- 在给定值下计算累积分布函数(Cumulatuve Distribution Function, CDF)。 - 参数:
- value (Tensor) - 要计算的值。 
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,累积分布函数的值。 
 
 - cross_entropy(dist, concentration1_b, concentration0_b, concentration1, concentration0)
- 计算分布a和b之间的交叉熵。 - 参数:
- dist (str) - 分布的类型。 
- concentration1_b (Tensor) - 对比 Beta 分布的 alpha。 
- concentration0_b (Tensor) - 对比 Beta 分布的 beta。 
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,交叉熵的值。 
 
 - entropy(concentration1, concentration0)
- 计算熵。 - 参数:
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,熵的值。 
 
 - kl_loss(dist, concentration1_b, concentration0_b, concentration1, concentration0)
- 计算KL散度,即KL(a||b)。 - 参数:
- dist (str) - 分布的类型。 
- concentration1_b (Tensor) - 对比 Beta 分布的 alpha。 
- concentration0_b (Tensor) - 对比 Beta 分布的 beta。 
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,KL散度。 
 
 - log_cdf(value, concentration1, concentration0)
- 计算给定值对于的累积分布函数的对数。 - 参数:
- value (Tensor) - 要计算的值。 
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,累积分布函数的对数。 
 
 - log_prob(value, concentration1, concentration0)
- 计算给定值对应的概率的对数。 - 参数:
- value (Tensor) - 要计算的值。 
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,累积分布函数的对数。 
 
 - log_survival(value, concentration1, concentration0)
- 计算给定值对应的生存函数的对数。 - 参数:
- value (Tensor) - 要计算的值。 
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,生存函数的对数。 
 
 - mean(concentration1, concentration0)
- 计算期望。 - 参数:
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,概率分布的期望。 
 
 - mode(concentration1, concentration0)
- 计算众数。 - 参数:
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,概率分布的众数。 
 
 - prob(value, concentration1, concentration0)
- 计算给定值下的概率。对于连续是计算概率密度函数(Probability Density Function)。 - 参数:
- value (Tensor) - 要计算的值。 
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,概率值。 
 
 - sample(shape, concentration1, concentration0)
- 采样函数。 - 参数:
- shape (tuple) - 样本的shape。 
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,根据概率分布采样的样本。 
 
 - sd(concentration1, concentration0)
- 计算标准差。 - 参数:
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,概率分布的标准差。 
 
 - survival_function(value, concentration1, concentration0)
- 计算给定值对应的生存函数。 - 参数:
- value (Tensor) - 要计算的值。 
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,生存函数的值。 
 
 - var(concentration1, concentration0)
- 计算方差。 - 参数:
- concentration1 (Tensor) - Beta 分布的 alpha。默认值: - None。
- concentration0 (Tensor) - Beta 分布的 beta。默认值: - None。
 
- 返回:
- Tensor,概率分布的方差。