gluonts.mx.model.deepvar_hierarchical 包#
- class gluonts.mx.model.deepvar_hierarchical.DeepVARHierarchicalEstimator(freq: str, prediction_length: int, S: numpy.ndarray, D: Optional[numpy.ndarray] = None, num_samples_for_loss: int = 200, likelihood_weight: float = 0.0, CRPS_weight: float = 1.0, sample_LH: bool = False, coherent_train_samples: bool = True, coherent_pred_samples: bool = True, warmstart_epoch_frac: float =0.0, seq_axis: Optional[List[int]] = None, log_coherency_error: bool = True, trainer: gluonts.mx.trainer._base.Trainer = gluonts.mx.trainer._base.Trainer(add_default_callbacks=True, callbacks=None, clip_gradient=10.0, ctx=None, epochs=100, hybridize=True, init='xavier', learning_rate=0.001, num_batches_per_epoch=50, weight_decay=1e-08), context_length: Optional[int] = None, num_layers: int = 2, num_cells: int = 40, cell_type: str = 'lstm', num_parallel_samples: int = 100, dropout_rate: float = 0.1, use_feat_dynamic_real: bool = False, cardinality: List[int] = [1], embedding_dimension: int = 5, scaling: bool = True, pick_incomplete: bool = False, lags_seq: Optional[List[int]] = None, time_features: Optional[List[Callable[[pandas.core.indexes.period.PeriodIndex], numpy.ndarray]]] = None, batch_size: int = 32, **kwargs)[source]#
基类:
gluonts.mx.model.deepvar._estimator.DeepVAREstimator
构建 DeepVARHierarchical 估计器,它是 DeepVAR 的分层扩展。
该模型已在 ICML 2021 的论文中描述:http://proceedings.mlr.press/v139/rangapuram21a.html
- 参数
freq – 用于训练和预测的数据频率
prediction_length (int) – 预测范围的长度
S – 求和或聚合矩阵。
D – 正定矩阵(通常是对角矩阵)。可选。如果提供,则基于由 D 引起的范数计算调整后预测与未调整预测之间的距离。这对于在层次结构的每个级别上以不同方式衡量距离非常有用。默认使用欧几里得距离。
num_samples_for_loss – 从预测分布中提取用于计算训练损失的样本数。
likelihood_weight – 负对数似然损失的权重。默认值:0.0。如果不为零,则将负对数似然(乘以
likelihood_weight
)添加到 CRPS 损失(乘以CRPS_weight
)。CRPS_weight – CRPS 损失分量的权重。默认值:1.0。如果为零,则损失仅为负对数似然(乘以
likelihood_weight
)。如果不为零,则将 CRPS 损失(乘以 ‘CRPS_weight’)添加到负对数似然损失(乘以likelihood_weight
)。sample_LH – 布尔标志,用于指定是否应使用基于(相干)样本的分布计算似然。默认值:False(在这种情况下,似然是使用网络预测的参数分布计算的)。
coherent_train_samples – 标志,指示在训练期间是否应强制实施一致性(coherence)。默认值:True。
coherent_pred_samples – 标志,指示在预测期间是否应强制实施一致性(coherence)。默认值:True。
warmstart_epoch_frac – 指定(占总 epoch 数的分数)从何时开始在训练期间强制实施一致性。
seq_axis – 指定应按顺序处理的轴列表(仅在训练期间)。参考轴为:(num_samples_for_loss, batch, seq_length, target_dim)。如果由于内存不足(例如,num_samples_for_loss 和 target_dim 都非常大)导致无法进行批处理,则此参数很有用。在这种情况下,使用 seq_axis = [1]。默认情况下,所有轴都并行处理。
log_coherency_error – 标志,指示是否计算和显示预测期间生成的样本上的一致性(coherency)误差。
trainer – 要使用的 Trainer 对象(默认值:Trainer())
context_length – 在计算预测之前展开 RNN 的步数(默认值:None,在这种情况下 context_length = prediction_length)
num_layers – RNN 层数(默认值:2)
num_cells – 每层的 RNN 单元数(默认值:40)
cell_type – 要使用的循环单元类型(可用:‘lstm’ 或 ‘gru’;默认值:‘lstm’)
num_parallel_samples – 每个时间序列的评估样本数,用于增加推理期间的并行性。这是一种模型优化,不会影响准确性(默认值:100)
dropout_rate – Dropout 正则化参数(默认值:0.1)
use_feat_dynamic_real – 是否使用数据中的
feat_dynamic_real
字段(默认值:False)cardinality – 每个类别特征的值的数量(默认值:[1])
embedding_dimension – 类别特征嵌入的维度(默认值:5])
scaling – 是否自动缩放目标值(默认值:true)
pick_incomplete – 训练示例是否可以仅采样部分 past_length 时间单位
lags_seq – 用作 RNN 输入的滞后目标值索引(默认值:None,在这种情况下,会根据 freq 自动确定)
time_features – 用作 RNN 输入的时间特征(默认值:None,在这种情况下,会根据 freq 自动确定)
batch_size – 训练和预测使用的批量大小。
- create_predictor(transformation: gluonts.transform._base.Transformation, trained_network: mxnet.gluon.block.HybridBlock) gluonts.model.predictor.Predictor [source]#
创建并返回一个预测器对象。
- 参数
transformation – 应用于数据进入模型之前的转换。
module – 经过训练的
HybridBlock
对象。
- 返回值
一个包装用于推理的
HybridBlock
的预测器。- 返回类型
- create_training_network() gluonts.mx.model.deepvar_hierarchical._network.DeepVARHierarchicalTrainingNetwork [source]#
创建并返回用于训练(即计算损失)的网络。
- 返回值
给定输入数据计算损失的网络。
- 返回类型
HybridBlock
- lead_time: int#
- output_transform: Optional[Callable]#
- prediction_length: int#
- gluonts.mx.model.deepvar_hierarchical.coherency_error(S: numpy.ndarray, samples: numpy.ndarray) float [source]#
计算最大相对一致性(coherency)误差。
\[\max_i | (S @ y_b)_i - y_i | / y_i\]其中 \(y\) 指的是 samples,\(y_b\) 指的是底层样本。
- 参数
S – 求和矩阵 S。形状:(total_num_time_series, num_bottom_time_series)
samples – 样本。形状:(*batch_shape, target_dim)。
- 返回值
一致性(Coherency)误差
- 返回类型
浮点数
- gluonts.mx.model.deepvar_hierarchical.projection_mat(S: numpy.ndarray, D: Optional[numpy.ndarray] = None) numpy.ndarray [source]#
计算用于将基础预测 :math: bar{y} 投影到一致(coherent)预测空间的投影矩阵 :math: P::math: P bar{y}。
更精确地说,
\[\begin{split}P = S (S^T S)^{-1} S^T, if D is None,\\ P = S (S^T D S)^{-1} S^T D, otherwise.\end{split}\]- 参数
S – 求和或聚合矩阵。形状:(total_num_time_series, num_bottom_time_series)
D – 对称正定矩阵(通常是对角矩阵)。形状:(total_num_time_series, total_num_time_series)。可选。如果提供,则基于由 D 引起的范数计算调整后预测与未调整预测之间的距离。这对于在层次结构的每个级别上以不同方式衡量距离非常有用。默认使用欧几里得距离。
- 返回值
投影矩阵,形状 (total_num_time_series, total_num_time_series)
- 返回类型
Numpy ND 数组
- gluonts.mx.model.deepvar_hierarchical.reconcile_samples(reconciliation_mat: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], samples: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], seq_axis: Optional[List] = None) Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol] [source]#
通过将无约束的 samples 与 reconciliation_mat 相乘来计算一致(coherent)样本。
- 参数
reconciliation_mat – 形状:(target_dim, target_dim)
samples – 无约束样本 形状:(*batch_shape, target_dim) 训练期间:(num_samples, batch_size, seq_len, target_dim) 预测期间:(num_parallel_samples x batch_size, seq_len, target_dim)
seq_axis – 指定应按顺序调整的轴列表。默认情况下,所有轴都并行处理。
- 返回值
一致(Coherent)样本
- 返回类型
张量,形状与 samples 相同