timesead.models.reconstruction.stgat

Code taken from https://github.com/zhanjun717/STGAT

Classes

InputLayer

1-D Convolution layer to extract high-level features of each time-series input

StgatBlock

Base class for all neural network modules.

BiLSTMLayer

Base class for all neural network modules.

BiLSTMDecoder

Base class for all neural network modules.

ReconstructionModel

Base class for all neural network modules.

Forecasting_Model

Base class for all neural network modules.

STGAT

Base class for all neural network modules.

Functions

get_batch_edge_index(org_edge_index, batch_num, node_num)

get_fc_graph_struc(n_features)

get_tc_graph_struc(temporal_len)

Module Contents

class timesead.models.reconstruction.stgat.InputLayer(n_features, kernel_size=7)

Bases: torch.nn.Module

1-D Convolution layer to extract high-level features of each time-series input :param n_features: Number of input features/nodes :param window_size: length of the input sequence :param kernel_size: size of kernel to use in the convolution operation

Initialize internal Module state, shared by both nn.Module and ScriptModule.

padding
conv
relu
forward(x)
class timesead.models.reconstruction.stgat.StgatBlock(n_features, window_size, dropout, alpha, embed_dim=None)

Bases: torch.nn.Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:

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))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call to(), etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

Variables:

training (bool) – Boolean represents whether this module is in training or evaluation mode.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

n_features
window_size
dropout
alpha
embed_dim = None
feature_gat_layers
temporal_gat_layers
temporal_gcn_layers
forward(data, fc_edge_index, tc_edge_index)
class timesead.models.reconstruction.stgat.BiLSTMLayer(in_dim, hid_dim, n_layers, dropout)

Bases: torch.nn.Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:

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))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call to(), etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

Variables:

training (bool) – Boolean represents whether this module is in training or evaluation mode.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

hid_dim
n_layers
dropout = 0.0
bilstm
forward(x)
class timesead.models.reconstruction.stgat.BiLSTMDecoder(in_dim, hid_dim, n_layers, dropout)

Bases: torch.nn.Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:

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))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call to(), etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

Variables:

training (bool) – Boolean represents whether this module is in training or evaluation mode.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

in_dim
dropout = 0.0
bilstm
forward(x)
class timesead.models.reconstruction.stgat.ReconstructionModel(window_size, in_dim, hid_dim, out_dim, n_layers, dropout)

Bases: torch.nn.Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:

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))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call to(), etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

Variables:

training (bool) – Boolean represents whether this module is in training or evaluation mode.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

window_size
decoder
fc
forward(x)
class timesead.models.reconstruction.stgat.Forecasting_Model(in_dim, hid_dim, out_dim, n_layers, dropout)

Bases: torch.nn.Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:

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))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call to(), etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

Variables:

training (bool) – Boolean represents whether this module is in training or evaluation mode.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

layers
dropout
relu
forward(x)
timesead.models.reconstruction.stgat.get_batch_edge_index(org_edge_index, batch_num, node_num)
timesead.models.reconstruction.stgat.get_fc_graph_struc(n_features)
timesead.models.reconstruction.stgat.get_tc_graph_struc(temporal_len)
class timesead.models.reconstruction.stgat.STGAT(input_dim: int, window_size: int, embed_dim: int = None, layer_numb: int = 2, lstm_n_layers: int = 1, lstm_hid_dim: int = 150, recon_n_layers: int = 1, recon_hid_dim: int = 150, dropout: float = 0.2, alpha: float = 0.2)

Bases: timesead.models.BaseModel

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:

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))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call to(), etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

Variables:

training (bool) – Boolean represents whether this module is in training or evaluation mode.

Parameters:
  • input_dim (int)

  • window_size (int)

  • embed_dim (int)

  • layer_numb (int)

  • lstm_n_layers (int)

  • lstm_hid_dim (int)

  • recon_n_layers (int)

  • recon_hid_dim (int)

  • dropout (float)

  • alpha (float)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

layer_numb = 2
h_temp = []
input_1
input_2
input_3
stgat_1
stgat_2
stgat_3
bilstm
recon_model
forward(inputs)