7
$\begingroup$

Currently, I'm using a Python library, StellarGraph, to implement GCN. And I now have a situation where I have graphs with weighted edges. Unfortunately, StellarGraph doesn't support those graphs

I'm looking for an open-source implementation for graph convolution networks for weighted graphs. I've searched a lot, but mostly they assumed unweighted graphs. Is there an open-source implementation for GCNs for weighted graphs?

$\endgroup$
1
  • 1
    $\begingroup$ You can take a look at "Diffusion Convolutional Recurrent Neural Network: Data-Driven Traffic Forecasting" (you can find it on Github). In there you can find an implementation of the diffusion convolution which is applied to a weighted graph, the traffic adjacency matrix. $\endgroup$
    – razvanc92
    Nov 28, 2019 at 12:56

3 Answers 3

2
$\begingroup$

A Comprehensive Survey on Graph Neural Networks (2019) presents a list of ConvGNN's. All of the following accept weighted graphs, and three accept those with edge weights as well:

enter image description here

And below is a series of open source implementations of many of the above:

enter image description here

$\endgroup$
0
4
$\begingroup$

You can use Pytorch_Geometric library for your projects. Its supports weighted GCNs. It is a rapidly evolving open-source library with easy to use syntax. It is mentioned in the landing page of Pytorch. It is the most starred Pytorch github repo for geometric deep learning. Creating a GCN model which can process graphs with weights is as simple as:

import torch
import torch.nn.functional as F
from torch_geometric.nn import GCNConv

class Net(torch.nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = GCNConv(dataset.num_node_features, 16)
        self.conv2 = GCNConv(16, dataset.num_classes)

    def forward(self, data):

        # data has the following 3 attributes
        x, edge_index, edge_weight = data.x, data.edge_index, data.edge_weight

        x = self.conv1(x, edge_index, edge_weight)
        x = F.relu(x)
        x = F.dropout(x, training=self.training)
        x = self.conv2(x, edge_index, edge_weight)

        return F.log_softmax(x, dim=1)

See this for getting started. Check out its documentation on different variants of GCNs for further details. One of the best thing is that like Pytorch, its documentation are self-sufficient.

$\endgroup$
1
  • $\begingroup$ Is there any reason why Pytorch Geometric wouldn't deal with negative weights in GCNConv()? When I use positive weights it works just fine. When I use negative ones it sometimes returns nans and causes problems. Any ideas why? $\endgroup$
    – Michael
    Dec 16, 2021 at 21:21
0
$\begingroup$

You can use Graph Attention Networks for weighted graphs. This model can handle negative weights. Check out its documentation.

$\endgroup$
1
  • $\begingroup$ While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review $\endgroup$
    – Rob
    Oct 21, 2022 at 2:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .