def _compute_neighborhood_graph_hash(self, root, graph): # list all hashed labels at increasing distances hash_list = [] # for all distances root_dist_dict = graph.node[root]['remote_neighbours'] for node_set in root_dist_dict.itervalues(): # create a list of hashed labels hash_label_list = [] for v in node_set: # compute the vertex hashed label by hashing the hlabel # field # with the degree of the vertex (obtained as the size of # the adjacency dictionary for the vertex v) # or, in case positional is set, using the relative # position of the vertex v w.r.t. the root vertex if self.positional: vhlabel = fast_hash_2( graph.node[v]['hlabel'], root - v) else: vhlabel = fast_hash_2( graph.node[v]['hlabel'], len(graph[v])) hash_label_list.append(vhlabel) # sort it hash_label_list.sort() # hash it hashed_nodes_at_distance_d_in_neighborhood = fast_hash( hash_label_list) hash_list.append(hashed_nodes_at_distance_d_in_neighborhood) # hash the sequence of hashes of the node set at increasing # distances into a list of features hash_neighborhood = fast_hash_vec(hash_list) graph.node[root]['neigh_graph_hash'] = hash_neighborhood
def _compute_neighborhood_graph_hash(self, root, graph): # list all hashed labels at increasing distances hash_list = [] # for all distances root_dist_dict = graph.node[root]['remote_neighbours'] for node_set in root_dist_dict.itervalues(): # create a list of hashed labels hash_label_list = [] for v in node_set: # compute the vertex hashed label by hashing the hlabel # field # with the degree of the vertex (obtained as the size of # the adjacency dictionary for the vertex v) # or, in case positional is set, using the relative # position of the vertex v w.r.t. the root vertex if self.positional: vhlabel = fast_hash_2( graph.node[v]['hlabel'], root - v) else: vhlabel = \ fast_hash_2(graph.node[v]['hlabel'], len(graph[v])) hash_label_list.append(vhlabel) # sort it hash_label_list.sort() # hash it hashed_nodes_at_distance_d_in_neighborhood = fast_hash( hash_label_list) hash_list.append(hashed_nodes_at_distance_d_in_neighborhood) # hash the sequence of hashes of the node set at increasing # distances into a list of features hash_neighborhood = fast_hash_vec(hash_list) graph.node[root]['neigh_graph_hash'] = hash_neighborhood
def _compute_neighborhood_graph_hash(self, root, G): hash_neighborhood_list = [] # for all labels for label_index in range(G.graph['label_size']): # list all hashed labels at increasing distances hash_list = [] # for all distances root_dist_dict = G.node[root]['remote_neighbours'] for node_set in root_dist_dict.itervalues(): # create a list of hashed labels hash_label_list = [] for v in node_set: vhlabel = G.node[v]['hlabel'][label_index] hash_label_list.append(vhlabel) # sort it hash_label_list.sort() # hash it hashed_nodes_at_distance_d_in_neighborhood_set = fast_hash( hash_label_list, self.bitmask) hash_list.append( hashed_nodes_at_distance_d_in_neighborhood_set) # hash the sequence of hashes of the node set at increasing # distances into a list of features hash_neighborhood = fast_hash_vec(hash_list, self.bitmask) hash_neighborhood_list.append(hash_neighborhood) G.node[root]['neighborhood_graph_hash'] = hash_neighborhood_list
def _compute_neighborhood_graph_hash(self, root, G): hash_neighborhood_list = [] # for all labels for label_index in range(G.graph['label_size']): # list all hashed labels at increasing distances hash_list = [] # for all distances root_dist_dict = G.node[root]['remote_neighbours'] for node_set in root_dist_dict.itervalues(): # create a list of hashed labels hash_label_list = [] for v in node_set: vhlabel = G.node[v]['hlabel'][label_index] hash_label_list.append(vhlabel) # sort it hash_label_list.sort() # hash it hashed_nodes_at_distance_d_in_neighborhood_set = fast_hash(hash_label_list, self.bitmask) hash_list.append(hashed_nodes_at_distance_d_in_neighborhood_set) # hash the sequence of hashes of the node set at increasing # distances into a list of features hash_neighborhood = fast_hash_vec(hash_list, self.bitmask) hash_neighborhood_list.append(hash_neighborhood) G.node[root]['neighborhood_graph_hash'] = hash_neighborhood_list
def _compute_neighborhood_hash(self, seq, pos): subseq = seq[pos:pos + self.r + 1] return fast_hash_vec(subseq, self.bitmask)