forked from mengzaiqiao/CAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_data.py
36 lines (32 loc) · 1.28 KB
/
input_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
import scipy.sparse as sp
def load_AN(dataset):
edge_file = open("data/{}.edge".format(dataset), 'r')
attri_file = open("data/{}.node".format(dataset), 'r')
edges = edge_file.readlines()
attributes = attri_file.readlines()
node_num = int(edges[0].split('\t')[1].strip())
edge_num = int(edges[1].split('\t')[1].strip())
attribute_number = int(attributes[1].split('\t')[1].strip())
print("dataset:{}, node_num:{},edge_num:{},attribute_num:{}".format(dataset, node_num, edge_num, attribute_number))
edges.pop(0)
edges.pop(0)
attributes.pop(0)
attributes.pop(0)
adj_row = []
adj_col = []
for line in edges:
node1 = int(line.split('\t')[0].strip())
node2 = int(line.split('\t')[1].strip())
adj_row.append(node1)
adj_col.append(node2)
adj = sp.csc_matrix((np.ones(edge_num), (adj_row, adj_col)), shape=(node_num, node_num))
att_row = []
att_col = []
for line in attributes:
node1 = int(line.split('\t')[0].strip())
attribute1 = int(line.split('\t')[1].strip())
att_row.append(node1)
att_col.append(attribute1)
attribute = sp.csc_matrix((np.ones(len(att_row)), (att_row, att_col)), shape=(node_num, attribute_number))
return adj, attribute