def _construct_edge_list_from_distance(X, k_neigh): """ construct edge_list (numpy array) from kNN distance for single modality :param X -> numpy array: feature :param k_neigh -> int: # of neighbors :return: N * k_neigh numpy array """ dis = cos_dis(X) dis = torch.Tensor(dis) _, k_idx = dis.topk(k_neigh, dim=-1, largest=False) return k_idx.numpy()
def construct_H_with_KNN(X, k_neig=10, is_probH=False, m_prob=1): """ init multi-scale hypergraph Vertex-Edge matrix from original node feature matrix :param X: N_object x feature_number :param K_neigs: the number of neighbor expansion :param is_probH: prob Vertex-Edge matrix or binary :param m_prob: prob :return: N_object x N_hyperedge """ if len(X.shape) != 2: X = X.reshape(-1, X.shape[-1]) dis_mat = cos_dis(X) H = construct_H_with_KNN_from_distance(dis_mat, k_neig, is_probH, m_prob) return H
def construct_H_with_KNN(X, K_neigs=[10], is_probH=False, m_prob=1): """ init multi-scale hypergraph Vertex-Edge matrix from original node feature matrix :param X: N_object x feature_number :param K_neigs: the number of neighbor expansion :param is_probH: prob Vertex-Edge matrix or binary :param m_prob: prob :return: N_object x N_hyperedge """ if len(X.shape) != 2: X = X.reshape(-1, X.shape[-1]) if type(K_neigs) == int: K_neigs = [K_neigs] dis_mat = cos_dis(X) H = None for k_neig in K_neigs: H_tmp = construct_H_with_KNN_from_distance(dis_mat, k_neig, is_probH, m_prob) H = hyperedge_concat(H, H_tmp) return H