How to get the normalized adjacency matrix

Hi,
I got the graph adjacency matrix with sparse format by calling g.adj(), like this:

tensor(indices=tensor([[    3,     1,     2,  ..., 19775, 19792, 19791],
                       [    0,     0,     0,  ..., 19791, 19791, 19792]]),
       values=tensor([1., 1., 1.,  ..., 1., 1., 1.]),
       size=(19793, 19793), nnz=126842, layout=torch.sparse_coo)

then, I want values=tensor([1., 1., 1., ..., 1., 1., 1.]) to be normalized.

Is there any existing function in dgl to do this?
If no, I have to realize this by myself.

Hi, what does normalized mean here? If graph contains duplicate edges, edges with same src/dst nodes are summed up?

Sorry, what I mean is the symmetric normalized ajacency matrix.
D^(-1/2)AD^(-1/2)

Here is an example:
this is an original graph, in where the values are all 1

tensor(indices=tensor([[    3,     1,     2,  ..., 19775, 19792, 19791],
                       [    0,     0,     0,  ..., 19791, 19791, 19792]]),
       values=tensor([1., 1., 1.,  ..., 1., 1., 1.]),
       size=(19793, 19793), nnz=126842, layout=torch.sparse_coo)

what I want to get is:
the values are symmetric normalized

tensor(indices=tensor([[    1,     2,     3,  ..., 19790, 19792, 19791],
                       [    0,     0,     0,  ..., 19791, 19791, 19792]]),
       values=tensor([0.3333, 0.3333, 0.3333,  ..., 0.1091, 0.2182, 0.2182]),
       size=(19793, 19793), nnz=126842, layout=torch.sparse_coo)

and I have already solved this problem by realizing a function.

Thanks for your attention.

1 Like

You could achieve this via dgl.sparse or just utilize GCNNorm — DGL 1.1.2 documentation

Thanks, everything is done.
And I will upgrade my dgl version.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.