I have an adjacency matrix A(nn) and a node feature matrix X(nm) that represent graph connections, how complex is the computation involved in converting it to graph data in DGL. ps: The method I use is nx.from_numpy_matrix() and dgl.from_network(), if there is a simpler way, I hope someone can tell me and help me analyze its computational complexity
As note here, creating a DGLGraph from a NetworkX graph is not fast especially for large scales. Constructing with tuple of tensor via dgl.graph()
is more efficient.
But for your case, you have adj matrix in numpy array, I think it always take O(N*N)
to obtain edges in src, dst
format no matter you choose networkx or scipy. Once edges are obtained, it takes O(E)
to construct DGL graph. Converting edges to tensor beforehand could have benefit of storage share thus more efficient.
Maybe you could try with sparse matrix like below:
adj = numpy.random.randint(0, 3, (5, 5))
sp_coo = scipy.sparse.coo_matrix()
g = dgl.from_scipy(sp_coo)
In further, you probably need to take computation invoked into consideration when choose the underlying format(csc, csr, coo) for efficiency as well.
as for feature data, you could just attach it via g.ndata['feat'] = xxx
. For efficient in future processing, converting xxx
into tensor is desirable.
If I use scipy.sparse.coo_matrix() to manipulate the adjacency matrix, wouldn’t it be out of the node order, because I still want to add node features via the g.ndata[] method
I think node order is preserved.
Thank you for your reply, I’m going to try it in the next experiment
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.