• 文档 >
  • 模块代码 >
  • torch >
  • torch.distributions.exponential
快捷键

torch.distributions.exponential 的源代码

# mypy: 允许未类型化定义
导入 火炬
来自 火炬 导入 张量
来自 torch.distributions 导入 约束
来自 torch.distributions.exp_family 导入 指数族
来自 torch.distributions.utils 导入 广播全部
来自 torch 的类型 导入 , _大小


全部 = [指数]


[文档] 指数(指数族): r"" 创建一个由 :attr:`rate` 参数化的指数分布。 示例:: >>> # xdoctest: +IGNORE_WANT("非确定性") >>> m = Exponential(torch.tensor([1.0])) >>> m.sample() # 指数分布,速率为 1 tensor([ 0.1046]) 参数: 率(浮点数或张量):rate = 分布的尺度倒数 "沉浸式翻译" 约束参数 = {: 约束.正面} 支持 = 约束.非负 has_rsample = 真实 _平均载波测量 = 0 @property def 均值(self) -> 张量: 返回 self..相互() @property def 模式(self) -> 张量: 返回 torch.等于零的(self.速率) @property def 标准差(self) -> 张量: 返回 self.速率.相互() @property def 方差(self) -> 张量: 返回 self.速率.pow(-2) def __init__(self, 速率, 验证参数=): (self.速率,) = 广播全部(速率) 批量形状 = torch.尺寸() 如果 isinstance(速率, ) 否则 .rate.尺寸() 超级().__init__(批量形状, 验证参数=验证参数)
[文档] def expand(self, batch_shape, _instance=None): new = self._get_checked_instance(Exponential, _instance) batch_shape = torch.Size(batch_shape) new.rate = self.rate.expand(batch_shape) super(Exponential, new).__init__(batch_shape, validate_args=False) new._validate_args = self._validate_args return new
[文档] def rsample(self, sample_shape: _size = torch.Size()): shape = self._extended_shape(sample_shape) return self.rate.new(shape).exponential_() / self.rate
[文档] def log_prob(self, value): if self._validate_args: self._validate_sample(value) return self.rate.log() - self.rate * value
[文档] def cdf(self, value): if self._validate_args: self._validate_sample(value) return 1 - torch.exp(-self.rate * value)
[文档] def icdf(self, value): return -torch.log1p(-value) / self.rate
[文档] def entropy(self): return 1.0 - torch.log(self.rate)
@property 定义
自然参数(自身) -> 元组[张量] 返回 (-自身.rate,) 定义 对数归一化器(自身, x): 返回 -torch.日志(-x)

© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

查看 PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源,获取您的疑问解答

查看资源