You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.nn.probability.distribution.Poisson.rst 3.6 kB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. mindspore.nn.probability.distribution.Poisson
  2. ================================================
  3. .. py:class:: mindspore.nn.probability.distribution.Poisson(rate=None, seed=None, dtype=mstype.float32, name='Poisson')
  4. 泊松分布(Poisson Distribution)。
  5. 离散随机分布,取值范围为正自然数集,概率质量函数为
  6. .. math::
  7. P(X = k) = \lambda^k \exp(-\lambda) / k!, k = 1, 2, ...
  8. 其中 :math:`\lambda` 为率参数(rate)。
  9. **参数:**
  10. - **rate** (int, float, list, numpy.ndarray, Tensor) - 泊松分布的率参数。默认值:None。
  11. - **seed** (int) - 采样时使用的种子。如果为None,则使用全局种子。默认值:None。
  12. - **dtype** (mindspore.dtype) - 事件样例的类型。默认值:mindspore.float32。
  13. - **name** (str) - 分布的名称。默认值:'Poisson'。
  14. **支持平台:**
  15. ``Ascend``
  16. .. note::
  17. `rate` 必须大于0。
  18. **异常:**
  19. - **ValueError** - `rate` 中元素小于0。
  20. **样例:**
  21. >>> import mindspore
  22. >>> import mindspore.nn as nn
  23. >>> import mindspore.nn.probability.distribution as msd
  24. >>> from mindspore import Tensor
  25. >>> # 初始化rate为0.5的泊松分布。
  26. >>> p1 = msd.Poisson([0.5], dtype=mindspore.float32)
  27. >>> # 泊松分布可以在没有参数的情况下初始化。
  28. >>> # 在这种情况下,`rate`必须在函数调用期间通过`args`传入。
  29. >>> p2 = msd.Poisson(dtype=mindspore.float32)
  30. >>>
  31. >>> # 下面是用于测试的Tensor
  32. >>> value = Tensor([1, 2, 3], dtype=mindspore.int32)
  33. >>> rate_a = Tensor([0.6], dtype=mindspore.float32)
  34. >>> rate_b = Tensor([0.2, 0.5, 0.4], dtype=mindspore.float32)
  35. >>>
  36. >>> # 公共接口对应的概率函数的私有接口,包括`prob`、`log_prob`、`cdf`、`log_cdf`、`survival_function`、`log_survival`,如下所示。
  37. >>> # 参数:
  38. >>> # value (Tensor):要评估的值。
  39. >>> # rate (Tensor):分布的率参数。默认值:self.rate.
  40. >>> # `prob`示例。
  41. >>> # 通过将`prob`替换为其他概率函数的名称,可以对其他概率函数进行类似的调用。
  42. >>> ans = p1.prob(value)
  43. >>> print(ans.shape)
  44. (3,)
  45. >>> # 根据分布b进行评估。
  46. >>> ans = p1.prob(value, rate_b)
  47. >>> print(ans.shape)
  48. (3,)
  49. >>> # `rate`必须在函数调用期间传入。
  50. >>> ans = p2.prob(value, rate_a)
  51. >>> print(ans.shape)
  52. (3,)
  53. >>> # 函数`mean`、`mode`、`sd`和'var'具有相同的参数,如下所示。
  54. >>> # 参数:
  55. >>> # rate (Tensor):分布的率参数。默认值:self.rate.
  56. >>> # `mean`、`sd`、`mode`和`var`的示例都类似。
  57. >>> ans = p1.mean() # return 2
  58. >>> print(ans.shape)
  59. (1,)
  60. >>> ans = p1.mean(rate_b) # return 1 / rate_b
  61. >>> print(ans.shape)
  62. (3,)
  63. >>> # `rate`必须在函数调用期间传入。
  64. >>> ans = p2.mean(rate_a)
  65. >>> print(ans.shape)
  66. (1,)
  67. >>> # `sample`示例。
  68. >>> # 参数:
  69. >>> # shape (tuple):样本的shape。默认值:()
  70. >>> # probs1 (Tensor):分布的率参数。默认值:self.rate.
  71. >>> ans = p1.sample()
  72. >>> print(ans.shape)
  73. (1, )
  74. >>> ans = p1.sample((2,3))
  75. >>> print(ans.shape)
  76. (2, 3, 1)
  77. >>> ans = p1.sample((2,3), rate_b)
  78. >>> print(ans.shape)
  79. (2, 3, 3)
  80. >>> ans = p2.sample((2,3), rate_a)
  81. >>> print(ans.shape)
  82. (2, 3, 1)
  83. .. py:method:: rate
  84. :property:
  85. 返回分布的 `rate` 参数。
  86. **返回:**
  87. Tensor, rate 参数的值。