Browse Source

improved the docs in the distribution classes

tags/v1.1.0
Xun Deng 5 years ago
parent
commit
1ae473c192
12 changed files with 44 additions and 21 deletions
  1. +2
    -1
      mindspore/nn/probability/distribution/bernoulli.py
  2. +4
    -2
      mindspore/nn/probability/distribution/beta.py
  3. +1
    -1
      mindspore/nn/probability/distribution/categorical.py
  4. +2
    -2
      mindspore/nn/probability/distribution/cauchy.py
  5. +1
    -1
      mindspore/nn/probability/distribution/exponential.py
  6. +4
    -2
      mindspore/nn/probability/distribution/gamma.py
  7. +2
    -1
      mindspore/nn/probability/distribution/geometric.py
  8. +6
    -0
      mindspore/nn/probability/distribution/gumbel.py
  9. +17
    -4
      mindspore/nn/probability/distribution/log_normal.py
  10. +2
    -2
      mindspore/nn/probability/distribution/logistic.py
  11. +1
    -3
      mindspore/nn/probability/distribution/poisson.py
  12. +2
    -2
      mindspore/nn/probability/distribution/uniform.py

+ 2
- 1
mindspore/nn/probability/distribution/bernoulli.py View File

@@ -163,7 +163,8 @@ class Bernoulli(Distribution):
@property
def probs(self):
"""
Return the probability of that the outcome is 1.
Return the probability of that the outcome is 1
after casting to self.dtype.
"""
return self._probs



+ 4
- 2
mindspore/nn/probability/distribution/beta.py View File

@@ -190,14 +190,16 @@ class Beta(Distribution):
@property
def concentration1(self):
"""
Return the concentration1, also know as the alpha of the Beta distribution.
Return the concentration1, also know as the alpha of the Beta distribution,
after casting to self.dtype.
"""
return self._concentration1

@property
def concentration0(self):
"""
Return the concentration0, also know as the beta of the Beta distribution.
Return the concentration0, also know as the beta of the Beta distribution,
after casting to self.dtype.
"""
return self._concentration0



+ 1
- 1
mindspore/nn/probability/distribution/categorical.py View File

@@ -190,7 +190,7 @@ class Categorical(Distribution):
@property
def probs(self):
"""
Return the probability.
Return the probability after casting to self.dtype.
"""
return self._probs


+ 2
- 2
mindspore/nn/probability/distribution/cauchy.py View File

@@ -181,14 +181,14 @@ class Cauchy(Distribution):
@property
def loc(self):
"""
Return the location of the distribution.
Return the location of the distribution after casting to self.dtype.
"""
return self._loc

@property
def scale(self):
"""
Return the scale of the distribution.
Return the scale of the distribution after casting to self.dtype.
"""
return self._scale



+ 1
- 1
mindspore/nn/probability/distribution/exponential.py View File

@@ -167,7 +167,7 @@ class Exponential(Distribution):
@property
def rate(self):
"""
Return `rate` of the distribution.
Return `rate` of the distribution after casting to self.dtype.
"""
return self._rate



+ 4
- 2
mindspore/nn/probability/distribution/gamma.py View File

@@ -188,14 +188,16 @@ class Gamma(Distribution):
@property
def concentration(self):
"""
Return the concentration, also know as the alpha of the Gamma distribution.
Return the concentration, also know as the alpha of the Gamma distribution,
after casting to self.dtype.
"""
return self._concentration

@property
def rate(self):
"""
Return the rate, also know as the beta of the Gamma distribution.
Return the rate, also know as the beta of the Gamma distribution,
after casting to self.dtype.
"""
return self._rate



+ 2
- 1
mindspore/nn/probability/distribution/geometric.py View File

@@ -172,7 +172,8 @@ class Geometric(Distribution):
@property
def probs(self):
"""
Return the probability of success of the Bernoulli trail.
Return the probability of success of the Bernoulli trail,
after casting to self.dtype.
"""
return self._probs



+ 6
- 0
mindspore/nn/probability/distribution/gumbel.py View File

@@ -127,10 +127,16 @@ class Gumbel(TransformedDistribution):

@property
def loc(self):
"""
Return the location of the distribution after casting to self.dtype.
"""
return self._loc

@property
def scale(self):
"""
Return the scale of the distribution after casting to self.dtype.
"""
return self._scale

def extend_repr(self):


+ 17
- 4
mindspore/nn/probability/distribution/log_normal.py View File

@@ -165,27 +165,35 @@ class LogNormal(msd.TransformedDistribution):
self.log_2pi = np.log(2 * np.pi)

#ops needed for the class
self.dtypeop = P.DType()
self.exp = exp_generic
self.expm1 = P.Expm1()
self.log = log_generic
self.const = P.ScalarToArray()
self.erf = P.Erf()
self.fill = P.Fill()
self.greater = P.Greater()
self.select = P.Select()
self.shape = P.Shape()
self.sq = P.Square()
self.sqrt = P.Sqrt()
self.cast = P.Cast()
self.squeeze = P.Squeeze(0)
self.zeroslike = P.ZerosLike()

@property
def loc(self):
"""Distribution parameter for the pre-transformed mean."""
"""
Distribution parameter for the pre-transformed mean
after casting to self.dtype.
"""
return self._loc

@property
def scale(self):
"""Distribution parameter for the pre-transformed standard deviation."""
"""
Distribution parameter for the pre-transformed standard deviation
after casting to self.dtype.
"""
return self._scale

def _get_dist_type(self):
@@ -254,7 +262,12 @@ class LogNormal(msd.TransformedDistribution):
"""
mean, sd = self._check_param_type(loc, scale)
inverse_value = self.bijector("inverse", value)
return self.distribution("cdf", inverse_value, mean, sd)
cdf = self.distribution("cdf", inverse_value, mean, sd)

# to increase numerical stability, set cdf = 0 when value <= 0
zeros = self.fill(self.dtypeop(cdf), self.shape(cdf), 0.0)

return self.select(self.greater(value, 0.), cdf, zeros)

def _log_prob(self, value, loc=None, scale=None):
r"""


+ 2
- 2
mindspore/nn/probability/distribution/logistic.py View File

@@ -181,14 +181,14 @@ class Logistic(Distribution):
@property
def loc(self):
"""
Return the location of the distribution.
Return the location of the distribution after casting to self.dtype.
"""
return self._loc

@property
def scale(self):
"""
Return the scale of the distribution.
Return the scale of the distribution after casting to self.dtype.
"""
return self._scale



+ 1
- 3
mindspore/nn/probability/distribution/poisson.py View File

@@ -157,7 +157,7 @@ class Poisson(Distribution):
@property
def rate(self):
"""
Return `rate` of the distribution.
Return `rate` of the distribution after casting to self.dtype.
"""
return self._rate

@@ -212,7 +212,6 @@ class Poisson(Distribution):
"""
value = self._check_value(value, "value")
value = self.cast(value, self.dtype)
value = self.floor(value)
rate = self._check_param_type(rate)
log_rate = self.log(rate)
zeros = self.fill(self.dtypeop(value), self.shape(value), 0.0)
@@ -240,7 +239,6 @@ class Poisson(Distribution):
"""
value = self._check_value(value, 'value')
value = self.cast(value, self.dtype)
value = self.floor(value)
rate = self._check_param_type(rate)
zeros = self.fill(self.dtypeop(value), self.shape(value), 0.0)
comp = self.less(value, zeros)


+ 2
- 2
mindspore/nn/probability/distribution/uniform.py View File

@@ -181,14 +181,14 @@ class Uniform(Distribution):
@property
def low(self):
"""
Return the lower bound of the distribution.
Return the lower bound of the distribution after casting to self.dtype.
"""
return self._low

@property
def high(self):
"""
Return the upper bound of the distribution.
Return the upper bound of the distribution after casting to self.dtype..
"""
return self._high



Loading…
Cancel
Save