benedekrozemberczki / pytorch_geometric_temporal

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

Predicting Path Failure via LRGCN #163

Closed renesass closed 1 year ago

renesass commented 2 years ago

Hey,

thank you very much for providing this nice framework. I came across Predicting Path Failure In Time-Evolving Graphs and wanted to use it within this framework (as it is cited in the docs).

However, looking at the example at LRGCN, I'm quite confused about the passed parameters and the dissimilarity to the tensorflow implementation.

The original implementation calculates the loss using path classes whether they fail or not. In pytorch geometric temporal the model returns only future node values. How do I incorporate the "precited path failure" here? Is it possible at all to make it work?

Your help would be much appreciated.

Best, René

I added the code for quick reference:

class RecurrentGCN(torch.nn.Module):
    def __init__(self, node_features):
        super(RecurrentGCN, self).__init__()
        self.recurrent = LRGCN(node_features, 32, 1, 1)
        self.linear = torch.nn.Linear(32, 1)

    def forward(self, x, edge_index, edge_weight, h_0, c_0):
        h_0, c_0 = self.recurrent(x, edge_index, edge_weight, h_0, c_0)
        h = F.relu(h_0)
        h = self.linear(h)
        return h, h_0, c_0

model = RecurrentGCN(node_features=4)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
model.train()

for epoch in tqdm(range(200)):
    cost = 0
    h, c = None, None
    for time, snapshot in enumerate(train_dataset):
        y_hat, h, c = model(snapshot.x, snapshot.edge_index, snapshot.edge_attr, h, c)
        cost = cost + torch.mean((y_hat - snapshot.y) ** 2)
    cost = cost / (time + 1)
    cost.backward()
    optimizer.step()
    optimizer.zero_grad()