def test_gen_knn_hg(): X = np.random.rand(50, 100) hg = gen_knn_hg(X, n_neighbors=5) assert hg.num_nodes() == 50 assert hg.num_edges() == 50 assert hg.incident_matrix().nnz == 300
def test_fuse_multi_hg(): X = np.random.rand(200, 10) knn_hg = gen_knn_hg(X, n_neighbors=5) clu_hg = gen_clustering_hg(X, n_clusters=20) hg = concat_multi_hg([knn_hg, clu_hg]) assert hg.num_nodes() == knn_hg.num_nodes() assert hg.num_nodes() == clu_hg.num_nodes() assert hg.num_edges() == knn_hg.num_edges() + clu_hg.num_edges()
def main(): print_log("loading data") X_train, X_test, y_train, y_test = load_myocardium([3]) X = np.concatenate([X_train, X_test], axis=0) y = np.concatenate( [y_train.reshape(-1), -1 * np.ones_like(y_test).reshape(-1)]) print_log("generating hypergraph") # grid hg grid_hg_s = [gen_grid_neigh_hg(X[i].shape) for i in range(X.shape[0])] grid_hg = fuse_mutli_sub_hg(grid_hg_s) # knn hg X_patch_ft = np.stack([ gather_patch_ft(X[i][:, :, np.newaxis], (5, 5)) for i in range(X.shape[0]) ]) knn_hg = gen_knn_hg(X_patch_ft.reshape(-1, X_patch_ft.shape[-1]), n_neighbors=7) # concatfeat hg concat_hg = concat_multi_hg([grid_hg, knn_hg]) print_log("learning on hypergraph") y_predict = trans_infer(concat_hg, y, 100) print_log("iou: {}".format(iou_socre(y_predict, y_test.reshape(-1)))) print_log("postprocessing") y_postpro = postprocess(y_predict.reshape(y_test.shape)) print_log("iou(postprocess): {}".format( iou_socre(y_postpro.reshape(-1), y_test.reshape(-1)))) # visualize print_log("visualizing") fig = plt.figure() ax1 = fig.add_subplot(2, 2, 1) ax1.imshow(X_test.squeeze()) ax1.title.set_text('X_test') ax1.axis('off') ax2 = fig.add_subplot(2, 2, 2) ax2.imshow(y_test.squeeze()) ax2.title.set_text('y_test') ax2.axis('off') ax3 = fig.add_subplot(2, 2, 3) ax3.imshow(y_predict.reshape(y_test.squeeze().shape)) ax3.title.set_text('y_predict') ax3.axis('off') ax4 = fig.add_subplot(2, 2, 4) ax4.imshow(y_postpro.reshape(y_test.squeeze().shape)) ax4.title.set_text('y_postpro') ax4.axis('off') plt.show()
def main(): print_log("loading data") X_train, X_test, y_train, y_test = load_MSRGesture3D() X = np.concatenate([X_train, X_test]) y = np.concatenate([y_train, -1 * np.ones_like(y_test)]) print_log("generating hypergraph") hg = gen_knn_hg(X, n_neighbors=4) print_log("learning on hypergraph") y_predict = trans_infer(hg, y, lbd=100) print_log("accuracy: {}".format(accuracy_score(y_test, y_predict)))
def main(): print_log("loading data") X_train, X_test, y_train, y_test = load_modelnet(selected_mod=(0, 1)) X = [np.vstack((X_train[imod], X_test[imod])) for imod in range(len(X_train))] y = np.concatenate((y_train, -1 * np.ones_like(y_test))) print_log("generating hypergraph") hg_list = [ gen_knn_hg(X[imod], n_neighbors=10) for imod in range(len(X_train)) ] print_log("learning on hypergraph") y_predict = multi_hg_trans_infer(hg_list, y, lbd=100) print_log("accuracy: {}".format(accuracy_score(y_test, y_predict)))