From a4113341915bb6854dcf4c4351f1c09e1bcfc366 Mon Sep 17 00:00:00 2001 From: Xun Deng Date: Mon, 30 Nov 2020 19:36:40 -0500 Subject: [PATCH] edited docs in distribution and bijector --- mindspore/nn/probability/bijector/bijector.py | 3 +++ mindspore/nn/probability/bijector/exp.py | 3 +++ mindspore/nn/probability/bijector/gumbel_cdf.py | 3 +++ mindspore/nn/probability/bijector/invert.py | 3 +++ .../nn/probability/bijector/power_transform.py | 3 +++ .../nn/probability/bijector/scalar_affine.py | 3 +++ mindspore/nn/probability/bijector/softplus.py | 3 +++ .../nn/probability/distribution/bernoulli.py | 3 +++ mindspore/nn/probability/distribution/beta.py | 3 +++ .../nn/probability/distribution/categorical.py | 3 +++ mindspore/nn/probability/distribution/cauchy.py | 3 +++ .../nn/probability/distribution/distribution.py | 6 +++++- .../nn/probability/distribution/exponential.py | 3 +++ mindspore/nn/probability/distribution/gamma.py | 17 +++++++++++++---- .../nn/probability/distribution/geometric.py | 3 +++ mindspore/nn/probability/distribution/gumbel.py | 3 +++ .../nn/probability/distribution/log_normal.py | 3 +++ .../nn/probability/distribution/logistic.py | 3 +++ mindspore/nn/probability/distribution/normal.py | 3 +++ .../nn/probability/distribution/poisson.py | 3 +++ .../distribution/transformed_distribution.py | 3 +++ .../nn/probability/distribution/uniform.py | 7 ++++++- 22 files changed, 81 insertions(+), 6 deletions(-) diff --git a/mindspore/nn/probability/bijector/bijector.py b/mindspore/nn/probability/bijector/bijector.py index 252daf1159..e0d7ed62ae 100644 --- a/mindspore/nn/probability/bijector/bijector.py +++ b/mindspore/nn/probability/bijector/bijector.py @@ -35,6 +35,9 @@ class Bijector(Cell): dtype (mindspore.dtype): The type of the distributions that the Bijector can operate on. Default: None. param (dict): The parameters used to initialize the Bijector. Default: None. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `dtype` of bijector represents the type of the distributions that the bijector could operate on. When `dtype` is None, there is no enforcement on the type of input value except that the input value diff --git a/mindspore/nn/probability/bijector/exp.py b/mindspore/nn/probability/bijector/exp.py index 49230b0099..0af3dc7df9 100644 --- a/mindspore/nn/probability/bijector/exp.py +++ b/mindspore/nn/probability/bijector/exp.py @@ -27,6 +27,9 @@ class Exp(PowerTransform): Args: name (str): The name of the Bijector. Default: 'Exp'. + Supported Platforms: + ``Ascend`` ``GPU`` + Examples: >>> import mindspore >>> import mindspore.nn as nn diff --git a/mindspore/nn/probability/bijector/gumbel_cdf.py b/mindspore/nn/probability/bijector/gumbel_cdf.py index 2095d69689..95bce7e233 100644 --- a/mindspore/nn/probability/bijector/gumbel_cdf.py +++ b/mindspore/nn/probability/bijector/gumbel_cdf.py @@ -32,6 +32,9 @@ class GumbelCDF(Bijector): scale (float, list, numpy.ndarray, Tensor): The scale. Default: 1.0. name (str): The name of the Bijector. Default: 'Gumbel_CDF'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: For `inverse` and `inverse_log_jacobian`, input should be in range of (0, 1). The dtype of `loc` and `scale` must be float. diff --git a/mindspore/nn/probability/bijector/invert.py b/mindspore/nn/probability/bijector/invert.py index f570359ae9..6f9fead973 100644 --- a/mindspore/nn/probability/bijector/invert.py +++ b/mindspore/nn/probability/bijector/invert.py @@ -25,6 +25,9 @@ class Invert(Bijector): bijector (Bijector): Base Bijector. name (str): The name of the Bijector. Default: Invert. + Supported Platforms: + ``Ascend`` ``GPU`` + Examples: >>> import mindspore >>> import mindspore.nn as nn diff --git a/mindspore/nn/probability/bijector/power_transform.py b/mindspore/nn/probability/bijector/power_transform.py index dc09fe54de..90b42392a6 100644 --- a/mindspore/nn/probability/bijector/power_transform.py +++ b/mindspore/nn/probability/bijector/power_transform.py @@ -36,6 +36,9 @@ class PowerTransform(Bijector): power (float, list, numpy.ndarray, Tensor): The scale factor. Default: 0. name (str): The name of the bijector. Default: 'PowerTransform'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: The dtype of `power` must be float. diff --git a/mindspore/nn/probability/bijector/scalar_affine.py b/mindspore/nn/probability/bijector/scalar_affine.py index e576c95ef9..d8b99f050c 100644 --- a/mindspore/nn/probability/bijector/scalar_affine.py +++ b/mindspore/nn/probability/bijector/scalar_affine.py @@ -32,6 +32,9 @@ class ScalarAffine(Bijector): shift (float, list, numpy.ndarray, Tensor): The shift factor. Default: 0.0. name (str): The name of the bijector. Default: 'ScalarAffine'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: The dtype of `shift` and `scale` must be float. If `shift`, `scale` are passed in as numpy.ndarray or tensor, they have to have diff --git a/mindspore/nn/probability/bijector/softplus.py b/mindspore/nn/probability/bijector/softplus.py index db8ccbf8a1..8725581eac 100644 --- a/mindspore/nn/probability/bijector/softplus.py +++ b/mindspore/nn/probability/bijector/softplus.py @@ -33,6 +33,9 @@ class Softplus(Bijector): sharpness (float, list, numpy.ndarray, Tensor): The scale factor. Default: 1.0. name (str): The name of the Bijector. Default: 'Softplus'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: The dtype of `sharpness` must be float. diff --git a/mindspore/nn/probability/distribution/bernoulli.py b/mindspore/nn/probability/distribution/bernoulli.py index ce6ed6c540..efadce7058 100644 --- a/mindspore/nn/probability/distribution/bernoulli.py +++ b/mindspore/nn/probability/distribution/bernoulli.py @@ -32,6 +32,9 @@ class Bernoulli(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.int32. name (str): The name of the distribution. Default: 'Bernoulli'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `probs` must be a proper probability (0 < p < 1). `dist_spec_args` is `probs`. diff --git a/mindspore/nn/probability/distribution/beta.py b/mindspore/nn/probability/distribution/beta.py index b4b7873f12..b37b5f0cc4 100644 --- a/mindspore/nn/probability/distribution/beta.py +++ b/mindspore/nn/probability/distribution/beta.py @@ -37,6 +37,9 @@ class Beta(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.float32. name (str): The name of the distribution. Default: 'Beta'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `concentration1` and `concentration0` must be greater than zero. `dist_spec_args` are `concentration1` and `concentration0`. diff --git a/mindspore/nn/probability/distribution/categorical.py b/mindspore/nn/probability/distribution/categorical.py index 6b986ce883..b9c9eed47b 100644 --- a/mindspore/nn/probability/distribution/categorical.py +++ b/mindspore/nn/probability/distribution/categorical.py @@ -36,6 +36,9 @@ class Categorical(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.int32. name (str): The name of the distribution. Default: Categorical. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `probs` must have rank at least 1, values are proper probabilities and sum to 1. diff --git a/mindspore/nn/probability/distribution/cauchy.py b/mindspore/nn/probability/distribution/cauchy.py index f1ae92b459..f72fdfc7e9 100644 --- a/mindspore/nn/probability/distribution/cauchy.py +++ b/mindspore/nn/probability/distribution/cauchy.py @@ -34,6 +34,9 @@ class Cauchy(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.float32. name (str): The name of the distribution. Default: 'Cauchy'. + Supported Platforms: + ``Ascend`` + Note: `scale` must be greater than zero. `dist_spec_args` are `loc` and `scale`. diff --git a/mindspore/nn/probability/distribution/distribution.py b/mindspore/nn/probability/distribution/distribution.py index 8dfda69af8..f95679b488 100644 --- a/mindspore/nn/probability/distribution/distribution.py +++ b/mindspore/nn/probability/distribution/distribution.py @@ -33,6 +33,9 @@ class Distribution(Cell): name (str): The name of the distribution. param (dict): The parameters used to initialize the distribution. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: Derived class must override operations such as `_mean`, `_prob`, and `_log_prob`. Required arguments, such as `value` for `_prob`, @@ -711,7 +714,8 @@ class Distribution(Cell): Note: Names of supported functions include: 'prob', 'log_prob', 'cdf', 'log_cdf', 'survival_function', 'log_survival', - 'var', 'sd', 'mode', 'mean', 'entropy', 'kl_loss', 'cross_entropy', and 'sample'. + 'var', 'sd', 'mode', 'mean', 'entropy', 'kl_loss', 'cross_entropy', 'sample', + 'get_dist_args', and 'get_dist_type'. Args: name (str): The name of the function. diff --git a/mindspore/nn/probability/distribution/exponential.py b/mindspore/nn/probability/distribution/exponential.py index 3582f96160..b72afbdfbc 100644 --- a/mindspore/nn/probability/distribution/exponential.py +++ b/mindspore/nn/probability/distribution/exponential.py @@ -33,6 +33,9 @@ class Exponential(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.float32. name (str): The name of the distribution. Default: 'Exponential'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `rate` must be strictly greater than 0. `dist_spec_args` is `rate`. diff --git a/mindspore/nn/probability/distribution/gamma.py b/mindspore/nn/probability/distribution/gamma.py index 056fe02bcc..dd426a7573 100644 --- a/mindspore/nn/probability/distribution/gamma.py +++ b/mindspore/nn/probability/distribution/gamma.py @@ -37,6 +37,9 @@ class Gamma(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.float32. name (str): The name of the distribution. Default: 'Gamma'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `concentration` and `rate` must be greater than zero. `dist_spec_args` are `concentration` and `rate`. @@ -69,10 +72,16 @@ class Gamma(Distribution): >>> # Similar calls can be made to other probability functions >>> # by replacing 'prob' by the name of the function >>> # ans = g1.prob(value) - >>> # # Evaluate with respect to the distribution b. - >>> # ans = g1.prob(value, concentration_b, rate_b) - >>> # # `concentration` and `rate` must be passed in during function calls - >>> # ans = g2.prob(value, concentration_a, rate_a) + >>> print(ans) + [0.58610016 0.0429392 0.00176953] + >>> # Evaluate with respect to the distribution b. + >>> ans = g1.prob(value, concentration_b, rate_b) + >>> print(ans) + [0.3678793 0.07468057 0.0049575 ] + >>> # `concentration` and `rate` must be passed in during function calls for g2. + >>> ans = g2.prob(value, concentration_a, rate_a) + >>> print(ans) + [0.54134095 0.14652506 0.02974501] >>> # Functions `mean`, `sd`, `mode`, `var`, and `entropy` have the same arguments. >>> # Args: >>> # concentration (Tensor): the concentration of the distribution. Default: self._concentration. diff --git a/mindspore/nn/probability/distribution/geometric.py b/mindspore/nn/probability/distribution/geometric.py index ffc8ce5a9f..ff914df87d 100644 --- a/mindspore/nn/probability/distribution/geometric.py +++ b/mindspore/nn/probability/distribution/geometric.py @@ -35,6 +35,9 @@ class Geometric(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.int32. name (str): The name of the distribution. Default: 'Geometric'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `probs` must be a proper probability (0 < p < 1). `dist_spec_args` is `probs`. diff --git a/mindspore/nn/probability/distribution/gumbel.py b/mindspore/nn/probability/distribution/gumbel.py index 2cb134ad89..c23c6186a2 100644 --- a/mindspore/nn/probability/distribution/gumbel.py +++ b/mindspore/nn/probability/distribution/gumbel.py @@ -35,6 +35,9 @@ class Gumbel(TransformedDistribution): 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`. diff --git a/mindspore/nn/probability/distribution/log_normal.py b/mindspore/nn/probability/distribution/log_normal.py index 28c1467e1d..7af51ec53a 100644 --- a/mindspore/nn/probability/distribution/log_normal.py +++ b/mindspore/nn/probability/distribution/log_normal.py @@ -35,6 +35,9 @@ class LogNormal(msd.TransformedDistribution): dtype (mindspore.dtype): type of the distribution. Default: mstype.float32. name (str): the name of the distribution. Default: 'LogNormal'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `scale` must be greater than zero. `dist_spec_args` are `loc` and `scale`. diff --git a/mindspore/nn/probability/distribution/logistic.py b/mindspore/nn/probability/distribution/logistic.py index e3983b3648..647a15b894 100644 --- a/mindspore/nn/probability/distribution/logistic.py +++ b/mindspore/nn/probability/distribution/logistic.py @@ -34,6 +34,9 @@ class Logistic(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.float32. name (str): The name of the distribution. Default: 'Logistic'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `scale` must be greater than zero. `dist_spec_args` are `loc` and `scale`. diff --git a/mindspore/nn/probability/distribution/normal.py b/mindspore/nn/probability/distribution/normal.py index 11eb588a86..70e28fa56e 100644 --- a/mindspore/nn/probability/distribution/normal.py +++ b/mindspore/nn/probability/distribution/normal.py @@ -34,6 +34,9 @@ class Normal(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.float32. name (str): The name of the distribution. Default: 'Normal'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `sd` must be greater than zero. `dist_spec_args` are `mean` and `sd`. diff --git a/mindspore/nn/probability/distribution/poisson.py b/mindspore/nn/probability/distribution/poisson.py index 592bd78c26..54899ed946 100644 --- a/mindspore/nn/probability/distribution/poisson.py +++ b/mindspore/nn/probability/distribution/poisson.py @@ -34,6 +34,9 @@ class Poisson(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.float32. name (str): The name of the distribution. Default: 'Poisson'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `rate` must be strictly greater than 0. `dist_spec_args` is `rate`. diff --git a/mindspore/nn/probability/distribution/transformed_distribution.py b/mindspore/nn/probability/distribution/transformed_distribution.py index 17809ace46..5e2f2f7016 100644 --- a/mindspore/nn/probability/distribution/transformed_distribution.py +++ b/mindspore/nn/probability/distribution/transformed_distribution.py @@ -37,6 +37,9 @@ class TransformedDistribution(Distribution): will use this seed; elsewise, the underlying distribution's seed will be used. name (str): The name of the transformed distribution. Default: 'transformed_distribution'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: The arguments used to initialize the original distribution cannot be None. For example, mynormal = nn.Normal(dtype=dtyple.float32) cannot be used to initialized a diff --git a/mindspore/nn/probability/distribution/uniform.py b/mindspore/nn/probability/distribution/uniform.py index c3d036eb04..09bd0269dc 100644 --- a/mindspore/nn/probability/distribution/uniform.py +++ b/mindspore/nn/probability/distribution/uniform.py @@ -13,6 +13,7 @@ # limitations under the License. # ============================================================================ """Uniform Distribution""" +import numpy as np from mindspore.ops import operations as P from mindspore.ops import composite as C from mindspore._checkparam import Validator @@ -33,6 +34,9 @@ class Uniform(Distribution): dtype (mindspore.dtype): The type of the event samples. Default: mstype.float32. name (str): The name of the distribution. Default: 'Uniform'. + Supported Platforms: + ``Ascend`` ``GPU`` + Note: `low` must be stricly less than `high`. `dist_spec_args` are `high` and `low`. @@ -296,7 +300,8 @@ class Uniform(Distribution): kl = self.log(high_b - low_b) - self.log(high_a - low_a) comp = self.logicaland(self.lessequal( low_b, low_a), self.lessequal(high_a, high_b)) - return self.select(comp, kl, self.log(self.zeroslike(kl))) + inf = self.fill(self.dtypeop(kl), self.shape(kl), np.inf) + return self.select(comp, kl, inf) def _cdf(self, value, low=None, high=None): r"""