文档反馈

问题文档片段

问题文档片段包含公式时,显示为空格。

提交类型
issue

有点复杂...

找人问问吧。

请选择提交类型

问题类型
规范和低错类

- 规范和低错类:

- 错别字或拼写错误,标点符号使用错误、公式错误或显示异常。

- 链接错误、空单元格、格式错误。

- 英文中包含中文字符。

- 界面和描述不一致,但不影响操作。

- 表述不通顺,但不影响理解。

- 版本号不匹配:如软件包名称、界面版本号。

易用性

- 易用性:

- 关键步骤错误或缺失,无法指导用户完成任务。

- 缺少主要功能描述、关键词解释、必要前提条件、注意事项等。

- 描述内容存在歧义指代不明、上下文矛盾。

- 逻辑不清晰,该分类、分项、分步骤的没有给出。

正确性

- 正确性:

- 技术原理、功能、支持平台、参数类型、异常报错等描述和软件实现不一致。

- 原理图、架构图等存在错误。

- 命令、命令参数等错误。

- 代码片段错误。

- 命令无法完成对应功能。

- 界面错误,无法指导操作。

- 代码样例运行报错、运行结果不符。

风险提示

- 风险提示:

- 对重要数据或系统存在风险的操作,缺少安全提示。

内容合规

- 内容合规:

- 违反法律法规,涉及政治、领土主权等敏感词。

- 内容侵权。

请选择问题类型

问题描述

点击输入详细问题描述,以帮助我们快速定位问题。

mindspore.nn.probability.distribution.Gamma

class mindspore.nn.probability.distribution.Gamma(concentration=None, rate=None, seed=None, dtype=mstype.float32, name='Gamma')[源代码]

伽马分布(Gamma distribution)。 连续随机分布,取值范围为 (0,inf) ,概率密度函数为

f(x,α,β)=βα/Γ(α)xα1exp(βx).

其中 G 为 Gamma 函数,αβ 为分别 Gamma 函数的浓度参数和逆尺度参数。

参数:
  • concentration (int, float, list, numpy.ndarray, Tensor) - 浓度参数,也被称为伽马分布的alpha。默认值: None

  • rate (int, float, list, numpy.ndarray, Tensor) - 逆尺度参数,也被称为伽马分布的beta。默认值: None

  • seed (int) - 采样时使用的种子。如果为None,则使用全局种子。默认值: None

  • dtype (mindspore.dtype) - 事件样例的类型。默认值:mstype.float32。

  • name (str) - 分布的名称。默认值: 'Gamma'

说明

  • concentrationrate 中的元素必须大于零。

  • dtype 必须是float,因为伽马分布是连续的。

异常:
  • ValueError - concentration 或者 rate 中元素小于0。

  • TypeError - dtype 不是float的子类。

支持平台:

Ascend

样例:

>>> import mindspore
>>> import mindspore.nn as nn
>>> import mindspore.nn.probability.distribution as msd
>>> from mindspore import Tensor
>>> # To initialize a Gamma distribution of the concentration 3.0 and the rate 4.0.
>>> g1 = msd.Gamma([3.0], [4.0], dtype=mindspore.float32)
>>> # A Gamma distribution can be initialized without arguments.
>>> # In this case, `concentration` and `rate` must be passed in through arguments.
>>> g2 = msd.Gamma(dtype=mindspore.float32)
>>> # Here are some tensors used below for testing
>>> value = Tensor([1.0, 2.0, 3.0], dtype=mindspore.float32)
>>> concentration_a = Tensor([2.0], dtype=mindspore.float32)
>>> rate_a = Tensor([2.0, 2.0, 2.0], dtype=mindspore.float32)
>>> concentration_b = Tensor([1.0], dtype=mindspore.float32)
>>> rate_b = Tensor([1.0, 1.5, 2.0], dtype=mindspore.float32)
>>>
>>> # Private interfaces of probability functions corresponding to public interfaces, including
>>> # `prob`, `log_prob`, `cdf`, `log_cdf`, `survival_function`, and `log_survival`,
>>> # have the same arguments as follows.
>>> # Args:
>>> #     value (Tensor): the value to be evaluated.
>>> #     concentration (Tensor): the concentration of the distribution. Default: self._concentration.
>>> #     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 = g1.prob(value)
>>> print(ans.shape)
(3,)
>>> # Evaluate with respect to the distribution b.
>>> ans = g1.prob(value, concentration_b, rate_b)
>>> print(ans.shape)
(3,)
>>> # `concentration` and `rate` must be passed in during function calls for g2.
>>> ans = g2.prob(value, concentration_a, rate_a)
>>> print(ans.shape)
(3,)
>>> # Functions `mean`, `sd`, `mode`, `var`, and `entropy` have the same arguments.
>>> # Args:
>>> #     concentration (Tensor): the concentration of the distribution. Default: self._concentration.
>>> #     rate (Tensor): the rate of the distribution. Default: self._rate.
>>> # Example of `mean`, `sd`, `mode`, `var`, and `entropy` are similar.
>>> ans = g1.mean()
>>> print(ans.shape)
(1,)
>>> ans = g1.mean(concentration_b, rate_b)
>>> print(ans.shape)
(3,)
>>> # `concentration` and `rate` must be passed in during function calls.
>>> ans = g2.mean(concentration_a, rate_a)
>>> print(ans.shape)
(3,)
>>> # Interfaces of 'kl_loss' and 'cross_entropy' are the same:
>>> # Args:
>>> #     dist (str): the type of the distributions. Only "Gamma" is supported.
>>> #     concentration_b (Tensor): the concentration of distribution b.
>>> #     rate_b (Tensor): the rate of distribution b.
>>> #     concentration_a (Tensor): the concentration of distribution a. Default: self._concentration.
>>> #     rate_a (Tensor): the rate of distribution a. Default: self._rate.
>>> # Examples of `kl_loss`. `cross_entropy` is similar.
>>> ans = g1.kl_loss('Gamma', concentration_b, rate_b)
>>> print(ans.shape)
(3,)
>>> ans = g1.kl_loss('Gamma', concentration_b, rate_b, concentration_a, rate_a)
>>> print(ans.shape)
(3,)
>>> # Additional `concentration` and `rate` must be passed in.
>>> ans = g2.kl_loss('Gamma', concentration_b, rate_b, concentration_a, rate_a)
>>> print(ans.shape)
(3,)
>>> # Examples of `sample`.
>>> # Args:
>>> #     shape (tuple): the shape of the sample. Default: ()
>>> #     concentration (Tensor): the concentration of the distribution. Default: self._concentration.
>>> #     rate (Tensor): the rate of the distribution. Default: self._rate.
>>> ans = g1.sample()
>>> print(ans.shape)
(1,)
>>> ans = g1.sample((2,3))
>>> print(ans.shape)
(2, 3, 1)
>>> ans = g1.sample((2,3), concentration_b, rate_b)
>>> print(ans.shape)
(2, 3, 3)
>>> ans = g2.sample((2,3), concentration_a, rate_a)
>>> print(ans.shape)
(2, 3, 3)
property concentration

返回分布的浓度(也称为伽马分布的alpha)。

返回:

Tensor,分布的浓度。

property rate

返回分布的逆尺度(也称为伽马分布的beta)。

返回:

Tensor,分布的逆尺度。

cdf(value, concentration, rate)

在给定值下计算累积分布函数(Cumulatuve Distribution Function, CDF)。

参数:
  • value (Tensor) - 要计算的值。

  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,累积分布函数的值。

cross_entropy(dist, concentration_b, rate_b, concentration, rate)

计算分布a和b之间的交叉熵。

参数:
  • dist (str) - 分布的类型。

  • concentration_b (Tensor) - 对比分布的alpha。

  • rate_b (Tensor) - 对比分布的beta。

  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,交叉熵的值。

entropy(concentration, rate)

计算熵。

参数:
  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,熵的值。

kl_loss(dist, concentration_b, rate_b, concentration, rate)

计算KL散度,即KL(a||b)。

参数:
  • dist (str) - 分布的类型。

  • concentration_b (Tensor) - 对比分布的alpha。

  • rate_b (Tensor) - 对比分布的beta。

  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,KL散度。

log_cdf(value, concentration, rate)

计算给定值对于的累积分布函数的对数。

参数:
  • value (Tensor) - 要计算的值。

  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,累积分布函数的对数。

log_prob(value, concentration, rate)

计算给定值对应的概率的对数。

参数:
  • value (Tensor) - 要计算的值。

  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,累积分布函数的对数。

log_survival(value, concentration, rate)

计算给定值对应的生存函数的对数。

参数:
  • value (Tensor) - 要计算的值。

  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,生存函数的对数。

mean(concentration, rate)

计算期望。

参数:
  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,概率分布的期望。

mode(concentration, rate)

计算众数。

参数:
  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,概率分布的众数。

prob(value, concentration, rate)

计算给定值下的概率。对于连续是计算概率密度函数(Probability Density Function)。

参数:
  • value (Tensor) - 要计算的值。

  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,概率值。

sample(shape, concentration, rate)

采样函数。

参数:
  • shape (tuple) - 样本的shape。

  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,根据概率分布采样的样本。

sd(concentration, rate)

计算标准差。

参数:
  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,概率分布的标准差。

survival_function(value, concentration, rate)

计算给定值对应的生存函数。

参数:
  • value (Tensor) - 要计算的值。

  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,生存函数的值。

var(concentration, rate)

计算方差。

参数:
  • concentration (Tensor) - 分布的alpha。默认值: None

  • rate (Tensor) - 分布的beta。默认值: None

返回:

Tensor,概率分布的方差。