gluonts.torch.model.patch_tst.estimator 模块#
- class gluonts.torch.model.patch_tst.estimator.PatchTSTEstimator(prediction_length: int, patch_len: int, context_length: Optional[int] = None, stride: int = 8, padding_patch: str = 'end', d_model: int = 32, nhead: int = 4, dim_feedforward: int = 128, dropout: float = 0.1, activation: str = 'relu', norm_first: bool = False, num_encoder_layers: int = 2, lr: float = 0.001, weight_decay: float = 1e-08, scaling: Optional[str] = 'mean', distr_output: gluonts.torch.distributions.output.Output = gluonts.torch.distributions.studentT.StudentTOutput(beta=0.0), batch_size: int = 32, num_batches_per_epoch: int = 50, trainer_kwargs: Optional[Dict[str, Any]] = None, train_sampler: Optional[gluonts.transform.sampler.InstanceSampler] = None, validation_sampler: Optional[gluonts.transform.sampler.InstanceSampler] = None)[源代码]#
基类:
gluonts.torch.model.estimator.PyTorchLightningEstimator
一个用于训练 PatchTST 模型进行预测的 Estimator,如 https://arxiv.org/abs/2211.14730 所述,并扩展为概率模型。
此类别使用
PatchTSTModel
中定义的模型,并将其包装到PatchTSTLightningModule
中用于训练目的:训练使用 PyTorch Lightning 的pl.Trainer
类进行。- 参数
prediction_length (int) – 预测范围的长度。
context_length – 模型作为输入的预测时间之前的时间步数(默认值:
10 * prediction_length
)。patch_len – 块(patch)的长度。
stride – 块(patch)的步长。
padding_patch – 块(patch)的填充方式。
d_model – Transformer 编码器中隐藏层的大小。
nhead – Transformer 编码器中的注意力头数量,必须能整除 d_model。
dim_feedforward – Transformer 编码器中隐藏层的大小。
dropout – Transformer 编码器中的 Dropout 概率。
activation – Transformer 编码器中的激活函数。
norm_first – 是否在注意力之后或之前应用归一化。
num_encoder_layers – Transformer 编码器中的层数。
lr – 学习率(默认值:
1e-3
)。weight_decay – 权重衰减正则化参数(默认值:
1e-8
)。scaling – 缩放参数可以是“mean”、“std”或 None。
distr_output – 用于评估观测值和采样预测的分布(默认值:StudentTOutput())。
batch_size – 用于训练的批次大小(默认值:32)。
num_batches_per_epoch –
- 每个训练 epoch 要处理的批次数
(默认值:50)。
trainer_kwargs – 为构造
pl.Trainer
提供的额外参数。train_sampler – 控制训练期间窗口的采样。
validation_sampler – 控制验证期间窗口的采样。
- create_lightning_module() lightning.pytorch.core.module.LightningModule [源代码]#
创建并返回用于训练(即计算损失)的网络。
- 返回值
根据输入数据计算损失的网络。
- 返回类型
pl.LightningModule
- create_predictor(transformation: gluonts.transform._base.Transformation, module) gluonts.torch.model.predictor.PyTorchPredictor [源代码]#
创建并返回一个预测器对象。
- 参数
transformation – 在数据进入模型之前应用的转换。
module – 一个已训练的 pl.LightningModule 对象。
- 返回值
包装用于推理的 nn.Module 的预测器。
- 返回类型
- create_training_data_loader(data: gluonts.dataset.Dataset, module: gluonts.torch.model.patch_tst.lightning_module.PatchTSTLightningModule, shuffle_buffer_length: Optional[int] = None, **kwargs) Iterable [源代码]#
为训练目的创建一个数据加载器。
- 参数
data – 用于创建数据加载器的数据集。
module – 将接收来自数据加载器的批次的 pl.LightningModule 对象。
- 返回值
数据加载器,即数据的批次的可迭代对象。
- 返回类型
Iterable
- create_transformation() gluonts.transform._base.Transformation [源代码]#
创建并返回训练和推理所需的转换。
- 返回值
在训练和推理时将逐条应用于数据集的转换。
- 返回类型
- create_validation_data_loader(data: gluonts.dataset.Dataset, module: gluonts.torch.model.patch_tst.lightning_module.PatchTSTLightningModule, **kwargs) Iterable [源代码]#
为验证目的创建一个数据加载器。
- 参数
data – 用于创建数据加载器的数据集。
module – 将接收来自数据加载器的批次的 pl.LightningModule 对象。
- 返回值
数据加载器,即数据的批次的可迭代对象。
- 返回类型
Iterable
- lead_time: int#
- prediction_length: int#