benedekrozemberczki / pytorch_geometric_temporal

PyTorch Geometric Temporal: Spatiotemporal Signal Processing with Neural Machine Learning Models (CIKM 2021)
MIT License
2.61k stars 367 forks source link

Multi-variate output Attention TGCN #219

Closed victorsergio closed 1 year ago

victorsergio commented 1 year ago

Hi, is it possible to adapt the code example for A3TGCN (Attention Temporal Graph Convolutional Cell) to support a multi-variate-output? Do you know what changes I must do?

In the example, A3TGCN2() returns a tensor of size (batch_size, nodes, out_channels); after, with the use of a linear layer, the output is formed by 12 values (12 timesteps).

This is ok for predicting an output sequence of one variable, but I need to output 12 timesteps of 2 variables simultaneously. (Batch_size, nodes, features, timesteps).

The current implementation of A3TGCN supports a multi-variable output?

Thanks in advance.

# Making the model 
class TemporalGNN(torch.nn.Module):
    def __init__(self, node_features, periods, batch_size):
        super(TemporalGNN, self).__init__()
        # Attention Temporal Graph Convolutional Cell
        self.tgnn = A3TGCN2(in_channels=node_features,  out_channels=32, periods=periods,batch_size=batch_size) # node_features=2, periods=12

        # Equals single-shot prediction
        self.linear = torch.nn.Linear(32, periods)

    def forward(self, x, edge_index):
        """
        x = Node features for T time steps
        edge_index = Graph edge indices
        """
        h = self.tgnn(x, edge_index) # x [b, 207, 2, 12]  returns h [b, 207, 12]

        print("tgn output shape",h.shape)

        h = F.relu(h) 
        h = self.linear(h)
        return h
tboussaid commented 1 year ago

Hi @victorsergio, I don't know if your thread is still. I kind of needed the same thing. To do so, I used a decoder-like linear layers after the tgnn layer. Hope this will help. Best.