torch.distributions.pareto 源代码
from
打字
导入
可选
from 火炬
导入
张量
from torch.distributions 导入
约束
from torch.distributions.exponential 导入
指数分布
from torch.distributions.transformed_distribution 导入
转换分布
from torch.distributions.transforms 导入
变换矩阵, ExpTransform
from torch.distributions.utils 导入
广播全部
from torch.types 导入
_大小
全部 = [
帕累托分布]
[文档]
类
帕累托(
转换分布):
r""
帕累托类型 1 分布的样本。
示例::
>>> # xdoctest: +IGNORE_WANT("非确定性")
>>> m = Pareto(torch.tensor([1.0]), torch.tensor([1.0]))
>>> m.sample() # 从尺度=1 和α=1 的帕累托分布中采样
tensor([ 1.5623])
参数:
scale (float 或 Tensor): 分布的尺度参数
alpha(浮点数或张量):分布的形状参数
""
约束参数 = {"alpha":
约束.
正的,
"缩放":
约束.
正的}
def __init__(
self, 比例:
张量,
阿尔法:
张量,
验证参数:
可选[
布尔] =
无
) 翻译
无:
self.比例, self.alpha =
广播全部(
比例,
阿尔法)
基础分布 =
指数(self.
阿尔法,
验证参数=
验证参数)
转换 = [
指数转换(),
变换矩阵(
位置=0,
比例=self.
比例)]
超级().__init__(base_dist,
转换,
验证参数=
验证参数)
[文档] def expand(
self, 批量形状: _size, _实例: Optional["Pareto"] = None
" -> "帕累托":
new = self._get_checked_instance(Pareto, _instance)
new.scale = self.scale.expand(batch_shape)
new.alpha = self.alpha.expand(batch_shape)
return super().expand(batch_shape, _instance=new)
@property
def 均值(self)
翻译
张量:
# 均值在 alpha <= 1 时为无穷大
a = self.阿尔法.
卡钳(
最小值=1)
返回 a * self.
缩放 / (a - 1)
@property
def 模式(self)
翻译
张量:
返回 self.
缩放
@property
def 方差(self)
翻译
张量:
# 方差在 alpha <= 2 时为无穷大
a = self.阿尔法.
卡钳(
最小值=2)
返回 self.
比例.pow(2) * a / ((a - 1).pow(2) * (a - 2))
@constraints.依赖属性(
是否离散=
错误,
事件维度=0)
def 支持(self)
翻译
约束.
约束:
返回
约束.
大于等于(self.
比例)
[文档] def entropy(self) -> Tensor:
返回 (self.scale / self.alpha).log() + (1 + self.alpha.reciprocal())