in seal_link_pred.py [0:0]
def __init__(self, root, data, split_edge, num_hops, percent=100, split='train',
use_coalesce=False, node_label='drnl', ratio_per_hop=1.0,
max_nodes_per_hop=None, directed=False, **kwargs):
self.data = data
self.split_edge = split_edge
self.num_hops = num_hops
self.percent = percent
self.use_coalesce = use_coalesce
self.node_label = node_label
self.ratio_per_hop = ratio_per_hop
self.max_nodes_per_hop = max_nodes_per_hop
self.directed = directed
super(SEALDynamicDataset, self).__init__(root)
pos_edge, neg_edge = get_pos_neg_edges(split, self.split_edge,
self.data.edge_index,
self.data.num_nodes,
self.percent)
self.links = torch.cat([pos_edge, neg_edge], 1).t().tolist()
self.labels = [1] * pos_edge.size(1) + [0] * neg_edge.size(1)
if self.use_coalesce: # compress mutli-edge into edge with weight
self.data.edge_index, self.data.edge_weight = coalesce(
self.data.edge_index, self.data.edge_weight,
self.data.num_nodes, self.data.num_nodes)
if 'edge_weight' in self.data:
edge_weight = self.data.edge_weight.view(-1)
else:
edge_weight = torch.ones(self.data.edge_index.size(1), dtype=int)
self.A = ssp.csr_matrix(
(edge_weight, (self.data.edge_index[0], self.data.edge_index[1])),
shape=(self.data.num_nodes, self.data.num_nodes)
)
if self.directed:
self.A_csc = self.A.tocsc()
else:
self.A_csc = None