예제 #1
0
    def __init__(
            self,
            window, n_multiv, n_kernels, w_kernel,
            d_k, d_v, d_model, d_inner,
            n_layers, n_head, drop_prob=0.1):
        '''
        Args:

        window (int): the length of the input window size
        n_multiv (int): num of univariate time series
        n_kernels (int): the num of channels
        w_kernel (int): the default is 1
        d_k (int): d_model / n_head
        d_v (int): d_model / n_head
        d_model (int): outputs of dimension
        d_inner (int): the inner-layer dimension of Position-wise Feed-Forward Networks
        n_layers (int): num of layers in Encoder
        n_head (int): num of Multi-head
        drop_prob (float): the probability of dropout
        '''

        super(Single_Global_SelfAttn_Module, self).__init__()

        self.window = window
        self.w_kernel = w_kernel
        self.n_multiv = n_multiv
        self.d_model = d_model
        self.drop_prob = drop_prob
        self.conv2 = nn.Conv2d(1, n_kernels, (window, w_kernel))
        self.in_linear = nn.Linear(n_kernels, d_model)
        self.out_linear = nn.Linear(d_model, n_kernels)

        self.layer_stack = nn.ModuleList([
            EncoderLayer(d_model, d_inner, n_head, d_k, d_v, dropout=drop_prob)
            for _ in range(n_layers)])
    def __init__(self, hparams):
        """
		Args:

		window (int): the length of the input window size
		n_multiv (int): num of univariate time series
		n_kernels (int): the num of channels
		w_kernel (int): the default is 1
		d_k (int): d_model / n_head
		d_v (int): d_model / n_head
		d_model (int): outputs of dimension
		d_inner (int): the inner-layer dimension of Position-wise Feed-Forward Networks
		n_layers (int): num of layers in Encoder
		n_head (int): num of Multi-head
		drop_prob (float): the probability of dropout
		"""

        super(Single_Local_SelfAttn_Module, self).__init__()
        self.hparams = hparams
        self.window = hparams.window
        self.w_kernel = hparams.w_kernel
        self.n_multiv = hparams.n_multiv
        self.d_model = hparams.d_model
        self.drop_prob = hparams.drop_prob
        self.conv1 = nn.Conv2d(1, hparams.n_kernels,
                               (hparams.local, hparams.w_kernel))
        self.pooling1 = nn.AdaptiveMaxPool2d((1, hparams.n_multiv))
        self.in_linear = nn.Linear(hparams.n_kernels, hparams.d_model)
        self.out_linear = nn.Linear(hparams.d_model, hparams.n_kernels)

        self.layer_stack = nn.ModuleList(
            [EncoderLayer(hparams) for _ in range(hparams.n_layers)])