gluonts.torch.distributions.isqf 模块#

class gluonts.torch.distributions.isqf.ISQF(spline_knots: torch.Tensor, spline_heights: torch.Tensor, beta_l: torch.Tensor, beta_r: torch.Tensor, qk_y: torch.Tensor, qk_x: torch.Tensor, tol: float = 0.0001, validate_args: bool = False)[源代码]#

基类: torch.distributions.distribution.Distribution

在 Park, Robinson, Aubet, Kan, Gasthaus, Wang 的论文 Learning Quantile Functions without Quantile Crossing for Distribution-free Time Series Forecasting 中提出的增量(样条)分位数函数的分布类 :param spline_knots: 张量,参数化样条结点的 x 坐标(y 坐标)

形状:(*batch_shape, (num_qk-1), num_pieces)

参数
  • spline_heights – 张量,参数化样条结点的 x 坐标(y 坐标) 形状:(*batch_shape, (num_qk-1), num_pieces)

  • qk_x – 张量,包含分位数结点的递增 x 坐标(y 坐标),形状:(*batch_shape, num_qk)

  • qk_y – 张量,包含分位数结点的递增 x 坐标(y 坐标),形状:(*batch_shape, num_qk)

  • beta_l – 张量,包含左(右)尾部的非负可学习参数,形状:(*batch_shape,)

  • beta_r – 张量,包含左(右)尾部的非负可学习参数,形状:(*batch_shape,)

property batch_shape: torch.Size#

返回参数批处理的形状。

cdf(z: torch.Tensor) torch.Tensor[源代码]#

计算分位数水平 alpha_tilde,使得 q(alpha_tilde) = z :param z: 形状为 (*batch_shape,) 的张量

返回

形状为 (*batch_shape,) 的张量

返回类型

alpha_tilde

cdf_spline(z: torch.Tensor) torch.Tensor[源代码]#

对于观测 z 和在 [qk_x[k], qk_x[k+1]] 中定义的样条,计算分位数水平 alpha_tilde,使得 alpha_tilde.

= q^{-1}(z) 如果 z 在 qk_x[k] 和 qk_x[k+1] 之间 = qk_x[k] 如果 zqk_x[k+1] :param z: 观测,形状为 (*batch_shape,)

返回

对应的分位数水平,形状为 (*batch_shape, num_qk-1)

返回类型

alpha_tilde

cdf_tail(z: torch.Tensor, left_tail: bool = True) torch.Tensor[源代码]#

计算分位数水平 alpha_tilde,使得 alpha_tilde.

= q^{-1}(z) 如果 z 在尾部区域 = qk_x_l 或 qk_x_r 如果 z 在非尾部区域 :param z: 观测,形状为 (*batch_shape,) :param left_tail: 如果为 True,计算左尾部的 alpha_tilde

否则,计算右尾部的 alpha_tilde

返回

对应的分位数水平,形状为 (*batch_shape,)

返回类型

alpha_tilde

crps(z: torch.Tensor) torch.Tensor[源代码]#

以解析形式计算 CRPS :param z: 要评估的观测。形状为 (*batch_shape,)

返回

包含 CRPS 的张量,形状与 z 相同

返回类型

张量

crps_spline(z: torch.Tensor) torch.Tensor[源代码]#

以解析形式计算样条的 CRPS :param z: 要评估的观测。形状为 (*batch_shape,)

返回

包含 CRPS 的张量,形状与 z 相同

返回类型

张量

crps_tail(z: torch.Tensor, left_tail: bool = True) torch.Tensor[源代码]#

以解析形式计算左/右尾部的 CRPS :param z: 要评估的观测。形状为 (*batch_shape,) :param left_tail: 如果为 True,计算左尾部的 CRPS

否则,计算右尾部的 CRPS

返回

包含 CRPS 的张量,形状与 z 相同

返回类型

张量

loss(z: torch.Tensor) torch.Tensor[源代码]#
static parameterize_qk(quantile_knots: torch.Tensor) Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor][源代码]#

函数,参数化 num_qk 分位数结点的 x 或 y 坐标 :param quantile_knots: 分位数结点的 x 或 y 坐标

形状:(*batch_shape, num_qk)

返回

  • qk – 分位数结点 (qk) 的 x 或 y 坐标,索引为 1, …, num_qk-1,形状:(*batch_shape, num_qk-1)

  • qk_plus – 分位数结点 (qk) 的 x 或 y 坐标,索引为 2, …, num_qk,形状:(*batch_shape, num_qk-1)

  • qk_l – 最左分位数结点 (qk) 的 x 或 y 坐标,形状:(*batch_shape)

  • qk_r – 最右分位数结点 (qk) 的 x 或 y 坐标,形状:(*batch_shape)

static parameterize_spline(spline_knots: torch.Tensor, qk: torch.Tensor, qk_plus: torch.Tensor, tol: float = 0.0001) Tuple[torch.Tensor, torch.Tensor][源代码]#

函数,参数化样条结点的 x 或 y 坐标 :param spline_knots: 参数化样条结点位置的变量 :param qk: 分位数结点 (qk) 的 x 或 y 坐标,

索引为 1, …, num_qk-1,形状:(*batch_shape, num_qk-1)

参数
  • qk_plus – 分位数结点 (qk) 的 x 或 y 坐标,索引为 2, …, num_qk,形状:(*batch_shape, num_qk-1)

  • num_pieces – 样条段的数量

  • tol – 用于数值稳定性的容差超参数

返回

  • sk – 样条结点 (sk) 的 x 或 y 坐标,形状:(*batch_shape, num_qk-1, num_pieces)

  • delta_sk – 样条结点 (sk) 的 x 或 y 坐标差,形状:(*batch_shape, num_qk-1, num_pieces)

static parameterize_tail(beta: torch.Tensor, qk_x: torch.Tensor, qk_y: torch.Tensor) Tuple[torch.Tensor, torch.Tensor][源代码]#

函数,参数化尾部参数 注意,指数尾部由 q(alpha) 给出

= a_l log(alpha) + b_l 如果是左尾部 = a_r log(1-alpha) + b_r 如果是右尾部 其中 a_l=1/beta_l, b_l=-a_l*log(qk_x_l)+q(qk_x_l) a_r=1/beta_r, b_r=a_r*log(1-qk_x_r)+q(qk_x_r) :param beta: 参数化左尾部或右尾部,形状:(*batch_shape,) :param qk_x: 分位数结点最左或最右的 x 坐标,

形状:(*batch_shape,)

参数

qk_y – 分位数结点最左或最右的 y 坐标,形状:(*batch_shape,)

返回

  • tail_a – 上述的 a_l 或 a_r

  • tail_b – 上述的 b_l 或 b_r

quantile(alpha: torch.Tensor) torch.Tensor[源代码]#
quantile_internal(alpha: torch.Tensor, dim: Optional[int] = None) torch.Tensor[源代码]#

在分位数水平 input_alpha 处评估分位数函数 :param alpha: 如果 axis=None,形状为 (*batch_shape,) 的张量,否则包含一个

在指定位置的额外轴

参数

dim – 包含要计算的不同分位数水平的轴索引。详情请阅读下面的描述

返回

分位数张量,形状与 alpha 相同

返回类型

张量

quantile_spline(alpha: torch.Tensor, dim: Optional[int] = None) torch.Tensor[源代码]#
quantile_tail(alpha: torch.Tensor, dim: Optional[int] = None, left_tail: bool = True) torch.Tensor[源代码]#
rsample(sample_shape: torch.Size = torch.Size([])) torch.Tensor[源代码]#

用于绘制随机样本的函数 :param num_samples: 样本数量 :param dtype: 数据类型

返回

如果 num_samples = None,形状为 (*batch_shape,) 的张量,否则为 (num_samples, *batch_shape)

返回类型

张量

class gluonts.torch.distributions.isqf.ISQFOutput(num_pieces: int, qk_x: List[float], tol: float = 0.0001)[源代码]#

基类: gluonts.torch.distributions.distribution_output.DistributionOutput

增量(样条)分位数函数的 DistributionOutput 类 :param num_pieces: 每个样条的样条段数量

当 num_pieces = 1 时,ISQF 退化为 IQF

参数
  • qk_x – 包含分位数结点 x 坐标的列表

  • tol – 用于数值安全性的容差

distr_cls#

别名 gluonts.torch.distributions.isqf.ISQF

distribution(distr_args, loc: Optional[torch.Tensor] = None, scale: Optional[torch.Tensor] = None) gluonts.torch.distributions.isqf.ISQF[源代码]#

输出分布类的函数 distr_args: 分布参数 loc: 数据均值的偏移 scale: 数据缩放

classmethod domain_map(spline_knots: torch.Tensor, spline_heights: torch.Tensor, beta_l: torch.Tensor, beta_r: torch.Tensor, quantile_knots: torch.Tensor, tol: float = 0.0001) Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor][源代码]#

域映射函数 此函数的输入由 self.args_dim 指定。

spline_knots, spline_heights: 参数化样条结点的 x-/ y-坐标,形状 = (*batch_shape, (num_qk-1)*num_pieces)

beta_l, beta_r: 参数化左/右尾部,形状 = (*batch_shape, 1)

quantile_knots: 参数化分位数结点 y 坐标,形状 = (*batch_shape, num_qk)

property event_shape: Tuple#

与输出对象兼容的每个独立事件的形状。

reshape_spline_args(distr_args, qk_x: List[float])[源代码]#

辅助函数,将 knots 和 heights 重塑为 (*batch_shape, num_qk-1, num_pieces),将 qk_x 重塑为 (*batch_shape, num_qk)

class gluonts.torch.distributions.isqf.TransformedISQF(base_distribution: gluonts.torch.distributions.isqf.ISQF, transforms: List[torch.distributions.transforms.AffineTransform], validate_args=None)[源代码]#

基类: torch.distributions.transformed_distribution.TransformedDistribution

crps(y: torch.Tensor) torch.Tensor[源代码]#