dmlc--dgl
44089c8b4d
* Merge * [Graph][CUDA] Graph on GPU and many refactoring (#1791) * change edge_ids behavior and C++ impl * fix unittests; remove utils.Index in edge_id * pass mx and th tests * pass tf test * add aten::Scatter_ * Add nonzero; impl CSRGetDataAndIndices/CSRSliceMatrix * CSRGetData and CSRGetDataAndIndices passed tests * CSRSliceMatrix basic tests * fix bug in empty slice * CUDA CSRHasDuplicate * has_node; has_edge_between * predecessors, successors * deprecate send/recv; fix send_and_recv * deprecate send/recv; fix send_and_recv * in_edges; out_edges; all_edges; apply_edges * in deg/out deg * subgraph/edge_subgraph * adj * in_subgraph/out_subgraph * sample neighbors * set/get_n/e_repr * wip: working on refactoring all idtypes * pass ndata/edata tests on gpu * fix * stash * workaround nonzero issue * stash * nx conversion * test_hetero_basics except update routines * test_update_routines * test_hetero_basics for pytorch * more fixes * WIP: flatten graph * wip: flatten * test_flatten * test_to_device * fix bug in to_homo * fix bug in CSRSliceMatrix * pass subgraph test * fix send_and_recv * fix filter * test_heterograph * passed all pytorch tests * fix mx unittest * fix pytorch test_nn * fix all unittests for PyTorch * passed all mxnet tests * lint * fix tf nn test * pass all tf tests * lint * lint * change deprecation * try fix compile * lint * update METIDS * fix utest * fix * fix utests * try debug * revert * small fix * fix utests * upd * upd * upd * fix * upd * upd * upd * upd * upd * trigger * +1s * [kernel] Use heterograph index instead of unitgraph index (#1813) * upd * upd * upd * fix * upd * upd * upd * upd * upd * trigger * +1s * [Graph] Mutation for Heterograph (#1818) * mutation add_nodes and add_edges * Add support for remove_edges, remove_nodes, add_selfloop, remove_selfloop * Fix Co-authored-by: Ubuntu <ubuntu@ip-172-31-51-214.ec2.internal> * upd * upd * upd * fix * [Transfom] Mutable transform (#1833) * add nodesy * All three * Fix * lint * Add some test case * Fix * Fix * Fix * Fix * Fix * Fix * fix * triger * Fix * fix Co-authored-by: Ubuntu <ubuntu@ip-172-31-51-214.ec2.internal> * [Graph] Migrate Batch & Readout module to heterograph (#1836) * dgl.batch * unbatch * fix to device * reduce readout; segment reduce * change batch_num_nodes|edges to function * reduce readout/ softmax * broadcast * topk * fix * fix tf and mx * fix some ci * fix batch but unbatch differently * new checkk * upd * upd * upd * idtype behavior; code reorg * idtype behavior; code reorg * wip: test_basics * pass test_basics * WIP: from nx/ to nx * missing files * upd * pass test_basics:test_nx_conversion * Fix test * Fix inplace update * WIP: fixing tests * upd * pass test_transform cpu * pass gpu test_transform * pass test_batched_graph * GPU graph auto cast to int32 * missing file * stash * WIP: rgcn-hetero * Fix two datasety * upd * weird * Fix capsuley * fuck you * fuck matthias * Fix dgmg * fix bug in block degrees; pass rgcn-hetero * rgcn * gat and diffpool fix also fix ppi and tu dataset * Tree LSTM * pointcloud * rrn; wip: sgc * resolve conflicts * upd * sgc and reddit dataset * upd * Fix deepwalk, gindt and gcn * fix datasets and sign * optimization * optimization * upd * upd * Fix GIN * fix bug in add_nodes add_edges; tagcn * adaptive sampling and gcmc * upd * upd * fix geometric * fix * metapath2vec * fix agnn * fix pickling problem of block * fix utests * miss file * linegraph * upd * upd * upd * graphsage * stgcn_wave * fix hgt * on unittests * Fix transformer * Fix HAN * passed pytorch unittests * lint * fix * Fix cluster gcn * cluster-gcn is ready * on fixing block related codes * 2nd order derivative * Revert "2nd order derivative" This reverts commit 523bf6c249bee61b51b1ad1babf42aad4167f206. * passed torch utests again * fix all mxnet unittests * delete some useless tests * pass all tf cpu tests * disable * disable distributed unittest * fix * fix * lint * fix * fix * fix script * fix tutorial * fix apply edges bug * fix 2 basics * fix tutorial Co-authored-by: yzh119 <expye@outlook.com> Co-authored-by: xiang song(charlie.song) <classicxsong@gmail.com> Co-authored-by: Ubuntu <ubuntu@ip-172-31-51-214.ec2.internal> Co-authored-by: Ubuntu <ubuntu@ip-172-31-7-42.us-west-2.compute.internal> Co-authored-by: Ubuntu <ubuntu@ip-172-31-1-5.us-west-2.compute.internal> Co-authored-by: Ubuntu <ubuntu@ip-172-31-68-185.ec2.internal>
104 行
3.2 KiB
Python
104 行
3.2 KiB
Python
import numpy as np
|
|
import random
|
|
import time
|
|
import tqdm
|
|
import dgl
|
|
import sys
|
|
import os
|
|
|
|
num_walks_per_node = 1000
|
|
walk_length = 100
|
|
path = sys.argv[1]
|
|
|
|
def construct_graph():
|
|
paper_ids = []
|
|
paper_names = []
|
|
author_ids = []
|
|
author_names = []
|
|
conf_ids = []
|
|
conf_names = []
|
|
f_3 = open(os.path.join(path, "id_author.txt"), encoding="ISO-8859-1")
|
|
f_4 = open(os.path.join(path, "id_conf.txt"), encoding="ISO-8859-1")
|
|
f_5 = open(os.path.join(path, "paper.txt"), encoding="ISO-8859-1")
|
|
while True:
|
|
z = f_3.readline()
|
|
if not z:
|
|
break
|
|
z = z.strip().split()
|
|
identity = int(z[0])
|
|
author_ids.append(identity)
|
|
author_names.append(z[1])
|
|
while True:
|
|
w = f_4.readline()
|
|
if not w:
|
|
break;
|
|
w = w.strip().split()
|
|
identity = int(w[0])
|
|
conf_ids.append(identity)
|
|
conf_names.append(w[1])
|
|
while True:
|
|
v = f_5.readline()
|
|
if not v:
|
|
break;
|
|
v = v.strip().split()
|
|
identity = int(v[0])
|
|
paper_name = 'p' + ''.join(v[1:])
|
|
paper_ids.append(identity)
|
|
paper_names.append(paper_name)
|
|
f_3.close()
|
|
f_4.close()
|
|
f_5.close()
|
|
|
|
author_ids_invmap = {x: i for i, x in enumerate(author_ids)}
|
|
conf_ids_invmap = {x: i for i, x in enumerate(conf_ids)}
|
|
paper_ids_invmap = {x: i for i, x in enumerate(paper_ids)}
|
|
|
|
paper_author_src = []
|
|
paper_author_dst = []
|
|
paper_conf_src = []
|
|
paper_conf_dst = []
|
|
f_1 = open(os.path.join(path, "paper_author.txt"), "r")
|
|
f_2 = open(os.path.join(path, "paper_conf.txt"), "r")
|
|
for x in f_1:
|
|
x = x.split('\t')
|
|
x[0] = int(x[0])
|
|
x[1] = int(x[1].strip('\n'))
|
|
paper_author_src.append(paper_ids_invmap[x[0]])
|
|
paper_author_dst.append(author_ids_invmap[x[1]])
|
|
for y in f_2:
|
|
y = y.split('\t')
|
|
y[0] = int(y[0])
|
|
y[1] = int(y[1].strip('\n'))
|
|
paper_conf_src.append(paper_ids_invmap[y[0]])
|
|
paper_conf_dst.append(conf_ids_invmap[y[1]])
|
|
f_1.close()
|
|
f_2.close()
|
|
|
|
hg = dgl.heterograph({
|
|
('paper', 'pa', 'author') : (paper_author_src, paper_author_dst),
|
|
('author', 'ap', 'paper') : (paper_author_dst, paper_author_src),
|
|
('paper', 'pc', 'conf') : (paper_conf_src, paper_conf_dst),
|
|
('conf', 'cp', 'paper') : (paper_conf_dst, paper_conf_src)})
|
|
return hg, author_names, conf_names, paper_names
|
|
|
|
#"conference - paper - Author - paper - conference" metapath sampling
|
|
def generate_metapath():
|
|
output_path = open(os.path.join(path, "output_path.txt"), "w")
|
|
count = 0
|
|
|
|
hg, author_names, conf_names, paper_names = construct_graph()
|
|
|
|
for conf_idx in tqdm.trange(hg.number_of_nodes('conf')):
|
|
traces, _ = dgl.sampling.random_walk(
|
|
hg, [conf_idx] * num_walks_per_node, metapath=['cp', 'pa', 'ap', 'pc'] * walk_length)
|
|
for tr in traces:
|
|
outline = ' '.join(
|
|
(conf_names if i % 4 == 0 else author_names)[tr[i]]
|
|
for i in range(0, len(tr), 2)) # skip paper
|
|
print(outline, file=output_path)
|
|
output_path.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
generate_metapath()
|