1. MLP

多层感知机


源文件

MLP

 MLP (in_features, out_features, activation, hidden_size, num_layers,
      dropout)

*多层感知机类

参数
in_features: int,输入维度。
out_features: int,输出维度。
activation: str,使用的激活函数。
hidden_size: int,隐藏层维度。
num_layers: int,隐藏层数量。
dropout: float,丢弃率。
*

2. 时序卷积

长期以来,在深度学习中,序列建模一直与循环网络同义,然而一些论文表明,简单的卷积架构通过展示更长的有效记忆,可以胜过 LSTMs 等典型循环网络。

参考文献
-van den Oord, A., Dieleman, S., Zen, H., Simonyan, K., Vinyals, O., Graves, A., Kalchbrenner, N., Senior, A. W., & Kavukcuoglu, K. (2016). Wavenet: A generative model for raw audio. Computing Research Repository, abs/1609.03499. URL: http://arxiv.org/abs/1609.03499. arXiv:1609.03499.
-Shaojie Bai, Zico Kolter, Vladlen Koltun. (2018). An Empirical Evaluation of Generic Convolutional and Recurrent Networks for Sequence Modeling. Computing Research Repository, abs/1803.01271. URL: https://arxiv.org/abs/1803.01271.


Chomp1d

 Chomp1d (horizon)

*Chomp1d

接收维度为 [N,C,T] 的 x 输入,并对其进行裁剪,以便仅使用“时间可用”信息。由一维因果卷积 CausalConv1d 使用。

参数
horizon: int,要跳过的样本外值的长度。*


CausalConv1d

 CausalConv1d (in_channels, out_channels, kernel_size, padding, dilation,
               activation, stride:int=1)

*一维因果卷积

接收维度为 [N,C_in,T] 的 x 输入,并在时间维度上计算因果卷积。通过其扩张跳过预测范围的 H 步。考虑一个单元素批次,在 tt 时间步上的扩张卷积操作定义为

Conv1D(x,w)(t)=(x[d]w)(t)=k=1Kwkxtdk\mathrm{Conv1D}(\mathbf{x},\mathbf{w})(t) = (\mathbf{x}_{[*d]} \mathbf{w})(t) = \sum^{K}_{k=1} w_{k} \mathbf{x}_{t-dk}

其中 dd 是扩张系数,KK 是核大小,tdkt-dk 是考虑的过去观测值的索引。扩张有效地应用了一个带有跳跃连接的滤波器。如果 d=1d=1,则恢复正常的卷积。

参数
in_channels: int,x 输入初始通道的维度。
out_channels: int,x 输出通道的维度。
activation: str,用于识别 PyTorch 激活函数。选择范围包括 ‘ReLU’,‘Softplus’,‘Tanh’,‘SELU’, ‘LeakyReLU’,‘PReLU’,‘Sigmoid’。
padding: int,左侧使用的零填充数量。
kernel_size: int,卷积核大小。
dilation: int,扩张跳跃连接。

返回
x: tensor,维度为 [N,C_out,T] 的 torch tensor,即 activation(conv1d(inputs, kernel) + bias)。
*


TemporalConvolutionEncoder

 TemporalConvolutionEncoder (in_channels, out_channels, kernel_size,
                             dilations, activation:str='ReLU')

*时序卷积编码器

接收维度为 [N,T,C_in] 的 x 输入,将其转置为 [N,C_in,T],并应用深层指数扩张因果卷积堆栈。卷积的指数增加扩张允许创建指数级大长期记忆的加权平均值。

参数
in_channels: int,x 输入初始通道的维度。
out_channels: int,x 输出通道的维度。
kernel_size: int,卷积核的大小。
dilations: int list,控制核点之间的时序间距。
activation: str,用于识别 PyTorch 激活函数。选择范围包括 ‘ReLU’,‘Softplus’,‘Tanh’,‘SELU’, ‘LeakyReLU’,‘PReLU’,‘Sigmoid’。

返回
x: tensor,维度为 [N,T,C_out] 的 torch tensor。
*

3. Transformers

参考文献
- Haoyi Zhou, Shanghang Zhang, Jieqi Peng, Shuai Zhang, Jianxin Li, Hui Xiong, Wancai Zhang. “Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting”
- Haixu Wu, Jiehui Xu, Jianmin Wang, Mingsheng Long.


TransEncoder

 TransEncoder (attn_layers, conv_layers=None, norm_layer=None)

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


TransEncoderLayer

 TransEncoderLayer (attention, hidden_size, conv_hidden_size=None,
                    dropout=0.1, activation='relu')

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


TransDecoder

 TransDecoder (layers, norm_layer=None, projection=None)

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


TransDecoderLayer

 TransDecoderLayer (self_attention, cross_attention, hidden_size,
                    conv_hidden_size=None, dropout=0.1, activation='relu')

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


AttentionLayer

 AttentionLayer (attention, hidden_size, n_heads, d_keys=None,
                 d_values=None)

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


FullAttention

 FullAttention (mask_flag=True, factor=5, scale=None,
                attention_dropout=0.1, output_attention=False)

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


TriangularCausalMask

 TriangularCausalMask (B, L, device='cpu')

TriangularCausalMask


源文件

DataEmbedding_inverted

 DataEmbedding_inverted (c_in, hidden_size, dropout=0.1)

DataEmbedding_inverted


DataEmbedding

 DataEmbedding (c_in, exog_input_size, hidden_size, pos_embedding=True,
                dropout=0.1)

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


TemporalEmbedding

 TemporalEmbedding (d_model, embed_type='fixed', freq='h')

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


FixedEmbedding

 FixedEmbedding (c_in, d_model)

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


TimeFeatureEmbedding

 TimeFeatureEmbedding (input_size, hidden_size)

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


源文件

TokenEmbedding

 TokenEmbedding (c_in, hidden_size)

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


PositionalEmbedding

 PositionalEmbedding (hidden_size, max_len=5000)

*所有神经网络模块的基类。

您的模型也应继承此类。

模块也可以包含其他模块,使其可以嵌套在树状结构中。您可以将子模块指定为常规属性:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

以这种方式指定的子模块将被注册,并且在您调用 :meth:to 等方法时,它们的参数也会被转换。

.. 注意:: 如上例所示,必须在子类中进行赋值之前调用父类的 __init__() 方法。

:ivar training: 布尔值,表示此模块是处于训练模式还是评估模式。 :vartype training: bool*


源文件

SeriesDecomp

 SeriesDecomp (kernel_size)

序列分解块


源文件

MovingAvg

 MovingAvg (kernel_size, stride)

用于突出时间序列趋势的移动平均块


RevIN

 RevIN (num_features:int, eps=1e-05, affine=False, subtract_last=False,
        non_norm=False)

RevIN(可逆实例归一化)


RevINMultivariate

 RevINMultivariate (num_features:int, eps=1e-05, affine=False,
                    subtract_last=False, non_norm=False)

用于多元模型的 ReversibleInstanceNorm1d