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.Geometric.rst 4.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. mindspore.nn.probability.distribution.Geometric
  2. ================================================
  3. .. py:class:: mindspore.nn.probability.distribution.Geometric(probs=None, seed=None, dtype=mindspore.int32, name='Geometric')
  4. 几何分布(Geometric Distribution)。
  5. 它代表在第一次成功之前有k次失败,即在第一次成功实现时,总共有k+1个伯努利试验。
  6. **参数:**
  7. - **probs** (float, list, numpy.ndarray, Tensor) - 成功的概率。默认值:None。
  8. - **seed** (int) - 采样时使用的种子。如果为None,则使用全局种子。默认值:None。
  9. - **dtype** (mindspore.dtype) - 事件样例的类型。默认值:mindspore.int32.
  10. - **name** (str) - 分布的名称。默认值:'Geometric'。
  11. **支持平台:**
  12. ``Ascend`` ``GPU``
  13. .. note::
  14. `probs` 必须是合适的概率(0<p<1)。
  15. **样例:**
  16. >>> import mindspore
  17. >>> import mindspore.nn as nn
  18. >>> import mindspore.nn.probability.distribution as msd
  19. >>> from mindspore import Tensor
  20. >>> # 初始化probability为0.5的几何分布。
  21. >>> g1 = msd.Geometric(0.5, dtype=mindspore.int32)
  22. >>> # 几何分布可以在没有参数的情况下初始化。
  23. >>> # 在这种情况下,`probs`必须在函数调用过程中通过参数传入。
  24. >>> g2 = msd.Geometric(dtype=mindspore.int32)
  25. >>>
  26. >>> # 下面是用于测试的Tensor
  27. >>> value = Tensor([1, 0, 1], dtype=mindspore.int32)
  28. >>> probs_a = Tensor([0.6], dtype=mindspore.float32)
  29. >>> probs_b = Tensor([0.2, 0.5, 0.4], dtype=mindspore.float32)
  30. >>>
  31. >>> # 公共接口对应的概率函数的私有接口,包括`prob`、`log_prob`、`cdf`、`log_cdf`、`survival_function`、`log_survival`,具有以下相同的参数。
  32. >>> # 参数:
  33. >>> # value (Tensor):要评估的值。
  34. >>> # probs1 (Tensor):伯努利试验成功的概率。默认值:self.probs.
  35. >>> # `prob`示例。
  36. >>> # 通过将`prob`替换为函数的名称,可以对其他概率函数进行类似的调用。
  37. >>> ans = g1.prob(value)
  38. >>> print(ans.shape)
  39. (3,)
  40. >>> # 根据分布b进行评估。
  41. >>> ans = g1.prob(value, probs_b)
  42. >>> print(ans.shape)
  43. (3,)
  44. >>> # `probs`必须在函数调用期间传入。
  45. >>> ans = g2.prob(value, probs_a)
  46. >>> print(ans.shape)
  47. (3,)
  48. >>> # 函数`mean`、`sd`、`var`和`entropy`具有相同的参数。
  49. >>> # 参数:
  50. >>> # probs1 (Tensor):伯努利试验成功的概率。默认值:self.probs.
  51. >>> # `mean`示例。`sd`、`var`和`entropy`是相似的。
  52. >>> ans = g1.mean() # return 1.0
  53. >>> print(ans.shape)
  54. ()
  55. >>> ans = g1.mean(probs_b)
  56. >>> print(ans.shape)
  57. (3,)
  58. >>> # 函数调用时必须传入probs。
  59. >>> ans = g2.mean(probs_a)
  60. >>> print(ans.shape)
  61. (1,)
  62. >>> # 'kl_loss'和'cross_entropy'的接口相同。
  63. >>> # 参数:
  64. >>> # dist (str):分布的名称。仅支持'Geometric'。
  65. >>> # probs1_b (Tensor):伯努利分布b试验成功的概率。
  66. >>> # probs1_a (Tensor):伯努利分布a试验成功的概率。
  67. >>> # `kl_loss`示例。`cross_entropy`也类似。
  68. >>> ans = g1.kl_loss('Geometric', probs_b)
  69. >>> print(ans.shape)
  70. (3,)
  71. >>> ans = g1.kl_loss('Geometric', probs_b, probs_a)
  72. >>> print(ans.shape)
  73. (3,)
  74. >>> # 必须传入额外的`probs`。
  75. >>> ans = g2.kl_loss('Geometric', probs_b, probs_a)
  76. >>> print(ans.shape)
  77. (3,)
  78. >>> # `sample`示例。
  79. >>> # 参数:
  80. >>> # shape (tupler):样本的shape。默认值:()
  81. >>> # probs1 (Tensor):伯努利试验成功的概率。默认值:self.probs.
  82. >>> ans = g1.sample()
  83. >>> print(ans.shape)
  84. ()
  85. >>> ans = g1.sample((2,3))
  86. >>> print(ans.shape)
  87. (2, 3)
  88. >>> ans = g1.sample((2,3), probs_b)
  89. >>> print(ans.shape)
  90. (2, 3, 3)
  91. >>> ans = g2.sample((2,3), probs_a)
  92. >>> print(ans.shape)
  93. (2, 3, 1)
  94. .. py:method:: probs
  95. :property:
  96. 返回伯努利试验成功的概率。