gluonts.torch.model.lag_tst 包#

gluonts.torch.model.lag_tst.LagTSTEstimator(freq: str, prediction_length: int, context_length: Optional[int] = None, d_model: int = 32, nhead: int =4, dim_feedforward: int =128, lags_seq: Optional[List[int]] = None, 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)[source]#

基类: gluonts.torch.model.estimator.PyTorchLightningEstimator

用于训练 LagTST 模型进行预测的估计器。

此类使用 SimpleFeedForwardModel 中定义的模型,并将其包装在 LagTSTLightningModule 中用于训练:训练是使用 PyTorch Lightning 的 pl.Trainer 类执行的。

参数
  • freq – 用于训练和预测的数据频率。

  • prediction_length (int) – 预测范围的长度。

  • context_length – 模型作为输入的预测时间之前的时间步数(默认值:10 * prediction_length)。

  • lags_seq – 用作 RNN 输入的滞后目标值的索引(默认值:None,在这种情况下会自动根据 freq 确定)。

  • d_model – Transformer 编码器中隐藏层的大小。

  • nhead – Transformer 编码器中注意力头部的数量。

  • 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[source]#

创建并返回用于训练(即计算损失)的网络。

返回值

给定输入数据计算损失的网络。

返回类型

pl.LightningModule

create_predictor(transformation: gluonts.transform._base.Transformation, module) gluonts.torch.model.predictor.PyTorchPredictor[source]#

创建并返回一个预测器对象。

参数
  • transformation – 应用于数据在进入模型之前的转换。

  • module – 一个训练好的 pl.LightningModule 对象。

返回值

一个包装了用于推理的 nn.Module 的预测器。

返回类型

预测器

create_training_data_loader(data: gluonts.dataset.Dataset, module: gluonts.torch.model.lag_tst.lightning_module.LagTSTLightningModule, shuffle_buffer_length: Optional[int] = None, **kwargs) Iterable[source]#

创建一个用于训练的数据加载器。

参数
  • data – 用于创建数据加载器的数据集。

  • module – 将接收数据加载器中批量数据的 pl.LightningModule 对象。

返回值

数据加载器,即一个包含数据批量数据的迭代器。

返回类型

Iterable

create_transformation() gluonts.transform._base.Transformation[source]#

创建并返回训练和推理所需的转换。

返回值

在训练和推理时,将逐条应用于数据集的转换。

返回类型

Transformation

create_validation_data_loader(data: gluonts.dataset.Dataset, module: gluonts.torch.model.lag_tst.lightning_module.LagTSTLightningModule, **kwargs) Iterable[source]#

创建一个用于验证的数据加载器。

参数
  • data – 用于创建数据加载器的数据集。

  • module – 将接收数据加载器中批量数据的 pl.LightningModule 对象。

返回值

数据加载器,即一个包含数据批量数据的迭代器。

返回类型

Iterable

lead_time: int#
prediction_length: int#
gluonts.torch.model.lag_tst.LagTSTLightningModule(model_kwargs: dict, lr: float =0.001, weight_decay: float =1e-08)[source]#

基类: lightning.pytorch.core.module.LightningModule

一个 pl.LightningModule 类,可用于使用 PyTorch Lightning 训练 LagTSTModel

这是 LagTSTModel(已包装)对象的一个薄层,公开了评估训练和验证损失的方法。

参数
  • model_kwargs – 用于构造要训练的 LagTSTModel 的关键字参数。

  • loss – 用于训练的损失函数。

  • lr – 学习率。

  • weight_decay – 权重衰减正则化参数。

configure_optimizers()[source]#

返回要使用的优化器。

forward(*args, **kwargs)[source]#

torch.nn.Module.forward() 相同。

参数
  • *args – 您决定传递给 forward 方法的任何参数。

  • **kwargs – 关键字参数也支持。

返回值

您的模型输出

training_step(batch, batch_idx: int)[source]#

执行训练步骤。

validation_step(batch, batch_idx: int)[source]#

执行验证步骤。

gluonts.torch.model.lag_tst.LagTSTModel(prediction_length: int, context_length: int, freq: str, d_model: int, nhead: int, dim_feedforward: int, dropout: float, activation: str, norm_first: bool, num_encoder_layers: int, scaling: str, lags_seq: Optional[List[int]] = None, distr_output=gluonts.torch.distributions.studentT.StudentTOutput(beta=0.0))[source]#

基类: torch.nn.modules.module.Module

实现 LagTST 模型用于预测的模块。

参数
  • prediction_length – 要预测的时间点数。

  • context_length – 模型预测时间之前的时间步数。

  • distr_output – 用于评估观测值和采样预测的分布。默认值:StudentTOutput()

describe_inputs(batch_size=1) gluonts.model.inputs.InputSpec[source]#
forward(past_target: torch.Tensor, past_observed_values: torch.Tensor) Tuple[Tuple[torch.Tensor, ...], torch.Tensor, torch.Tensor][source]#

定义每次调用时执行的计算。

应由所有子类重写。

注意

虽然 forward pass 的实现需要在该函数中定义,但之后应该调用 Module 实例而不是直接调用此函数,因为前者负责运行注册的钩子,而后者会静默忽略它们。

loss(past_target: torch.Tensor, past_observed_values: torch.Tensor, future_target: torch.Tensor, future_observed_values: torch.Tensor) torch.Tensor[source]#
training: bool#