mindspore.nn.probability.distribution.Beta
- class mindspore.nn.probability.distribution.Beta(concentration1=None, concentration0=None, seed=None, dtype=mstype.float32, name='Beta')[source]
- Beta distribution. A Beta distributio is a continuous distribution with the range \([0, 1]\) and the probability density function: \[f(x, \alpha, \beta) = x^\alpha (1-x)^{\beta - 1} / B(\alpha, \beta)\]- Where \(B\) is the Beta function. - Parameters
- concentration1 (int, float, list, numpy.ndarray, Tensor) – The concentration1, also know as \(alpha\) of the Beta distribution. Default: - None.
- concentration0 (int, float, list, numpy.ndarray, Tensor) – The concentration0, also know as \(beta\) of the Beta distribution. Default: - None.
- seed (int) – The seed used in sampling. The global seed is used if it is None. Default: - None.
- dtype (mindspore.dtype) – The type of the event samples. Default: - mstype.float32.
- name (str) – The name of the distribution. Default: - 'Beta'.
 
 - Note - concentration1 and concentration0 must be greater than zero. 
- dist_spec_args are concentration1 and concentration0. 
- dtype must be a float type because Beta distributions are continuous. 
 - Raises
- ValueError – When concentration1 <= 0 or concentration0 >=1. 
- TypeError – When the input dtype is not a float or a subclass of float. 
 
 - Supported Platforms:
- Ascend
 - Examples - >>> 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
- Return concentration0, aka the beta parameter of the Beta distribution. - Returns
- Tensor, the value of concentration0. 
 
 - property concentration1
- Return concentration1, aka the alpha parameter of the Beta distribution. - Returns
- Tensor, the value of concentration1. 
 
 - cdf(value, concentration1, concentration0)[source]
- Compute the cumulatuve distribution function(CDF) of the given value. - Parameters
- value (Tensor) - the value to compute. 
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the value of the cumulatuve distribution function for the given input. 
 
 - cross_entropy(dist, concentration1_b, concentration0_b, concentration1, concentration0)[source]
- Compute the cross entropy of two distribution. - Parameters
- dist (str) - the type of the other distribution. 
- concentration1_b (Tensor) - the alpha parameter of the other Beta distribution b. 
- concentration0_b (Tensor) - the beta parameter of the other Beta distribution b. 
- concentration1 (Tensor) - the alpha parameter of the Beta distribution a. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution a. Default: - None.
 
- Returns
- Tensor, the value of the cross entropy. 
 
 - entropy(concentration1, concentration0)[source]
- Compute the value of the entropy. - Parameters
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the value of the entropy. 
 
 - kl_loss(dist, concentration1_b, concentration0_b, concentration1, concentration0)[source]
- Compute the value of the K-L loss between two distribution, namely KL(a||b). - Parameters
- dist (str) - the type of the other distribution. 
- concentration1_b (Tensor) - the alpha parameter of the other Beta distribution b. 
- concentration0_b (Tensor) - the beta parameter of the other Beta distribution b. 
- concentration1 (Tensor) - the alpha parameter of the Beta distribution a. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution a. Default: - None.
 
- Returns
- Tensor, the value of the K-L loss. 
 
 - log_cdf(value, concentration1, concentration0)[source]
- Compute the log value of the cumulatuve distribution function. - Parameters
- value (Tensor) - the value to compute. 
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the log value of the cumulatuve distribution function. 
 
 - log_prob(value, concentration1, concentration0)[source]
- the log value of the probability. - Parameters
- value (Tensor) - the value to compute. 
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the log value of the probability. 
 
 - log_survival(value, concentration1, concentration0)[source]
- Compute the log value of the survival function. - Parameters
- value (Tensor) - the value to compute. 
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the value of the K-L loss. 
 
 - mean(concentration1, concentration0)[source]
- Compute the mean value of the distribution. - Parameters
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the mean of the distribution. 
 
 - mode(concentration1, concentration0)[source]
- Compute the mode value of the distribution. - Parameters
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the mode of the distribution. 
 
 - prob(value, concentration1, concentration0)[source]
- The probability of the given value. For the continuous distribution, it is the probability density function. - Parameters
- value (Tensor) - the value to compute. 
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the value of the probability. 
 
 - sample(shape, concentration1, concentration0)[source]
- Generate samples. - Parameters
- shape (tuple) - the shape of the sample. 
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the sample following the distribution. 
 
 - sd(concentration1, concentration0)[source]
- The standard deviation. - Parameters
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the standard deviation of the distribution. 
 
 - survival_function(value, concentration1, concentration0)[source]
- Compute the value of the survival function. - Parameters
- value (Tensor) - the value to compute. 
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the value of the survival function. 
 
 - var(concentration1, concentration0)[source]
- Compute the variance of the distribution. - Parameters
- concentration1 (Tensor) - the alpha parameter of the Beta distribution. Default: - None.
- concentration0 (Tensor) - the beta parameter of the Beta distribution. Default: - None.
 
- Returns
- Tensor, the variance of the distribution.