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.3 kB

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