gluonts.mx.distribution.categorical 模块#

class gluonts.mx.distribution.categorical.Categorical(log_probs: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol])[源代码]#

基类: gluonts.mx.distribution.distribution.Distribution

一个覆盖 num_cats 个类别的分类分布。

参数
  • log_probs – 包含各个类别对数概率的张量,形状为 (*batch_shape, num_cats)

  • F

property F#
arg_names: Tuple#
property args: List#
property batch_shape: Tuple#

分布所考虑的事件集合的布局。

调用分布的 sample() 方法会产生一个形状为 batch_shape + event_shape 的张量,而对该样本计算 log_prob(或更一般的 loss)会产生一个形状为 batch_shape 的张量。

此属性通常仅在 mx.ndarray 模式下可用,此时可以访问分布参数的形状。

property event_dim: int#

事件维度的数量,即 event_shape 元组的长度。

对于标量分布,此值为 0;对于向量分布,此值为 1;对于矩阵分布,此值为 2,依此类推。

property event_shape: Tuple#

分布所考虑的每个独立事件的形状。

例如,标量分布的 event_shape = (),向量分布的 event_shape = (d, ),其中 d 是向量的长度,矩阵分布的 event_shape = (d1, d2),依此类推。

调用分布的 sample() 方法会产生一个形状为 batch_shape + event_shape 的张量。

此属性通常仅在 mx.ndarray 模式下可用,此时可以访问分布参数的形状。

log_prob(x)[源代码]#

计算分布在 x 处的对数密度。

参数

x – 形状为 (*batch_shape, *event_shape) 的张量。

返回值

形状为 batch_shape 的张量,包含分布在 x 中每个事件的对数密度。

返回类型

张量

property mean#

包含分布均值的张量。

property probs#
sample(num_samples=None, dtype=<class 'numpy.int32'>)[源代码]#

从分布中抽取样本。

如果指定了 num_samples,则输出的第一个维度将是 num_samples。

参数
  • num_samples – 要抽取的样本数量。

  • dtype – 样本的数据类型。

返回值

包含样本的张量。如果 num_samples = None,则形状为 (*batch_shape, *eval_shape);否则为 (num_samples, *batch_shape, *eval_shape)

返回类型

张量

property stddev#

包含分布标准差的张量。

class gluonts.mx.distribution.categorical.CategoricalOutput(num_cats: int, temperature: float = 1.0)[源代码]#

基类: gluonts.mx.distribution.distribution_output.DistributionOutput

distr_cls#

别名 gluonts.mx.distribution.categorical.Categorical

distribution(distr_args, loc=None, scale=None, **kwargs) gluonts.mx.distribution.distribution.Distribution[源代码]#

根据构造函数参数集合以及可选的尺度张量,构造关联的分布。

参数
  • distr_args – 底层 Distribution 类型的构造函数参数。

  • loc – 可选张量,形状与结果分布的 batch_shape+event_shape 相同。

  • scale – 可选张量,形状与结果分布的 batch_shape+event_shape 相同。

domain_map(F, probs)[源代码]#

将参数转换为正确的形状和领域。

领域取决于分布的类型,而正确的形状是通过重塑尾部轴来实现的,以便返回的张量定义具有正确 event_shape 的分布。

property event_shape: Tuple#

此对象构造的分布所考虑的每个独立事件的形状。