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.Exponential.rst 4.0 kB

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