dmlc--dgl
68ec624782
* Add SH tutorials * setup sphinx-gallery; work on graph tutorial * draft dglgraph tutorial * update readme to include document url * rm obsolete file * Draft the message passing tutorial * Capsule code (#102) * add capsule example * clean code * better naming * better naming * [GCN]tutorial scaffold * fix capsule example code * remove previous capsule example code * graph struc edit * modified: 2_graph.py * update doc of capsule * update capsule docs * update capsule docs * add msg passing prime * GCN-GAT tutorial Section 1 and 2 * comment for API improvement * section 3 * Tutorial API change (#115) * change the API as discusses; toy example * enable the new set/get syntax * fixed pytorch utest * fixed gcn example * fixed gat example * fixed mx utests * fix mx utest * delete apply edges; add utest for update_edges * small change on toy example * fix utest * fix out in degrees bug * update pagerank example and add it to CI * add delitem for dataview * make edges() return form that is compatible with send/update_edges etc * fix index bug when the given data is one-int-tensor * fix doc
25 行
601 B
Python
25 行
601 B
Python
import networkx as nx
|
|
import torch
|
|
import dgl
|
|
import dgl.function as fn
|
|
|
|
N = 100
|
|
g = nx.nx.erdos_renyi_graph(N, 0.05)
|
|
g = dgl.DGLGraph(g)
|
|
|
|
DAMP = 0.85
|
|
K = 10
|
|
|
|
def compute_pagerank(g):
|
|
g.ndata['pv'] = torch.ones(N) / N
|
|
degrees = g.out_degrees(g.nodes()).type(torch.float32)
|
|
for k in range(K):
|
|
g.ndata['pv'] = g.ndata['pv'] / degrees
|
|
g.update_all(message_func=fn.copy_src(src='pv', out='m'),
|
|
reduce_func=fn.sum(msg='m', out='pv'))
|
|
g.ndata['pv'] = (1 - DAMP) / N + DAMP * g.ndata['pv']
|
|
return g.ndata['pv']
|
|
|
|
pv = compute_pagerank(g)
|
|
print(pv)
|