def load_train(name): ''' Training file is numbered from 0 to n. Not all nodes in the training file have their own row. ''' g = Graph() node_ids = set() n = -1 for n, (node_id, neighbor_ids) in enumerate(iter_adj_list(name)): node_ids.add(node_id) node_ids.update(neighbor_ids) n += 1 g.add_vertex(len(node_ids)) for i, (node_id, neighbor_ids) in enumerate(iter_adj_list(name)): print('adding edge for vertex {}/{}'.format(i + 1, n)) for neighbor_id in neighbor_ids: g.add_edge(node_id, neighbor_id) return g
def load_train(name): ''' Training file is numbered from 0 to n. Not all nodes in the training file have their own row. ''' g = Graph() for node, neighbors in iter_adj_list(name): for neighbor in neighbors: g.add_edge(node, neighbor) g.compute_in_deg_dict() return g
def load_train(name): ''' Training file is numbered from 0 to n. Not all nodes in the training file have their own row. This converts the directed graph to an undirected bipartite one, by replace each vertex with an inbound (odd) and outbound (even) vertex. Returns a csc matrix, note that indexing rows is the same as indexing columns due to symmetry. ''' row = [] col = [] for node, neighbors in iter_adj_list(name): for neighbor in neighbors: add_edge(row, col, node*2, neighbor*2 + 1) for i in range(len(row)): add_edge(row, col, i*2, i*2 + 1) return sparse.csc_matrix((np.ones(len(row)), (row, col)))
def load_train(name): ''' Training file is numbered from 0 to n. Not all nodes in the training file have their own row. This converts the directed graph to an undirected bipartite one, by replace each vertex with an inbound (odd) and outbound (even) vertex. Returns a csc matrix, note that indexing rows is the same as indexing columns due to symmetry. ''' row = [] col = [] for node, neighbors in iter_adj_list(name): for neighbor in neighbors: add_edge(row, col, node * 2, neighbor * 2 + 1) for i in range(len(row)): add_edge(row, col, i * 2, i * 2 + 1) return sparse.csc_matrix((np.ones(len(row)), (row, col)))