mindspore.nn.probability.distribution.Poisson
- class mindspore.nn.probability.distribution.Poisson(rate=None, seed=None, dtype=mstype.float32, name='Poisson')[source]
Poisson Distribution.
- Parameters
rate (list, numpy.ndarray, Tensor) – The rate of the Poisson distribution..
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: ‘Poisson’.
- Supported Platforms:
Ascend
Note
rate must be strictly greater than 0. dist_spec_args is rate.
Examples
>>> import mindspore >>> import mindspore.nn as nn >>> import mindspore.nn.probability.distribution as msd >>> from mindspore import Tensor >>> # To initialize an Poisson distribution of the rate 0.5. >>> p1 = msd.Poisson([0.5], dtype=mindspore.float32) >>> # An Poisson distribution can be initialized without arguments. >>> # In this case, `rate` must be passed in through `args` during function calls. >>> p2 = msd.Poisson(dtype=mindspore.float32) >>> >>> # Here are some tensors used below for testing >>> value = Tensor([1, 2, 3], dtype=mindspore.int32) >>> rate_a = Tensor([0.6], dtype=mindspore.float32) >>> rate_b = Tensor([0.2, 0.5, 0.4], dtype=mindspore.float32) >>> >>> # Private interfaces of probability functions corresponding to public interfaces, including >>> # `prob`, `log_prob`, `cdf`, `log_cdf`, `survival_function`, and `log_survival`, are the same as follows. >>> # Args: >>> # value (Tensor): the value to be evaluated. >>> # rate (Tensor): the rate of the distribution. Default: self.rate. >>> # Examples of `prob`. >>> # Similar calls can be made to other probability functions >>> # by replacing `prob` by the name of the function. >>> ans = p1.prob(value) >>> print(ans.shape) (3,) >>> # Evaluate with respect to distribution b. >>> ans = p1.prob(value, rate_b) >>> print(ans.shape) (3,) >>> # `rate` must be passed in during function calls. >>> ans = p2.prob(value, rate_a) >>> print(ans.shape) (3,) >>> # Functions `mean`, `mode`, `sd`, and 'var' have the same arguments as follows. >>> # Args: >>> # rate (Tensor): the rate of the distribution. Default: self.rate. >>> # Examples of `mean`, `sd`, `mode`, and `var` are similar. >>> ans = p1.mean() # return 2 >>> print(ans.shape) (1,) >>> ans = p1.mean(rate_b) # return 1 / rate_b >>> print(ans.shape) (3,) >>> # `rate` must be passed in during function calls. >>> ans = p2.mean(rate_a) >>> print(ans.shape) (1,) >>> # Examples of `sample`. >>> # Args: >>> # shape (tuple): the shape of the sample. Default: () >>> # probs1 (Tensor): the rate of the distribution. Default: self.rate. >>> ans = p1.sample() >>> print(ans.shape) (1, ) >>> ans = p1.sample((2,3)) >>> print(ans.shape) (2, 3, 1) >>> ans = p1.sample((2,3), rate_b) >>> print(ans.shape) (2, 3, 3) >>> ans = p2.sample((2,3), rate_a) >>> print(ans.shape) (2, 3, 1)
- property rate
Return rate of the distribution after casting to dtype.