gluonts.torch.model.simple_feedforward 包#

gluonts.torch.model.simple_feedforward.SimpleFeedForwardEstimator(prediction_length: int, context_length: Optional[int] = None, hidden_dimensions: Optional[List[int]] = None, lr: float = 0.001, weight_decay: float = 1e-08, distr_output: gluonts.torch.distributions.output.Output = gluonts.torch.distributions.studentT.StudentTOutput(beta=0.0), batch_norm: bool = False, 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

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

此类使用 SimpleFeedForwardModel 中定义的模型,并将其封装到 SimpleFeedForwardLightningModule 中进行训练:训练使用 PyTorch Lightning 的 pl.Trainer 类执行。

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

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

  • hidden_dimensions – 前馈网络中隐藏层的大小(默认值:[20, 20])。

  • lr – 学习率(默认值:1e-3)。

  • weight_decay – 权重衰减正则化参数(默认值:1e-08)。

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

  • batch_norm – 是否应用批量归一化。

  • 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 用于推理的预测器。

返回类型

Predictor

create_training_data_loader(data: gluonts.dataset.Dataset, module: gluonts.torch.model.simple_feedforward.lightning_module.SimpleFeedForwardLightningModule, 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.simple_feedforward.lightning_module.SimpleFeedForwardLightningModule, **kwargs) Iterable[source]#

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

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

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

返回

数据加载器,即数据批量的可迭代对象。

返回类型

Iterable

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

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

一个可用于使用 PyTorch Lightning 训练 SimpleFeedForwardModelpl.LightningModule 类。

这是围绕(封装的)SimpleFeedForwardModel 对象的薄层,暴露了评估训练损失和验证损失的方法。

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

  • 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.simple_feedforward.SimpleFeedForwardModel(prediction_length: int, context_length: int, hidden_dimensions: Optional[List[int]] = None, distr_output: gluonts.torch.distributions.output.Output = gluonts.torch.distributions.studentT.StudentTOutput(beta=0.0), batch_norm: bool = False)[source]#

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

实现前馈模型进行预测的模块。

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

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

  • hidden_dimensions – 前馈网络中隐藏层的大小。

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

  • batch_norm – 是否应用批量归一化。默认值:False

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

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

应由所有子类覆盖。

注意

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

loss(past_target: torch.Tensor, future_target: torch.Tensor, future_observed_values: torch.Tensor) torch.Tensor[source]#
training: bool#
gluonts.torch.model.simple_feedforward.make_linear_layer(dim_in, dim_out)[source]#