def exp_gbrbm(exp_name, T=[]): dataset = dg.one_exception_dataset(N=6, n=1500, T=T, lam=5000, exc=1, noise_k=1) utils.write_data(dataset, exp_name, "generated_data") new_data = utils.tsne(dataset, exp_name, "generated_data", T, 2) utils.write_data(new_data, exp_name, "generated_data_for_tsne") _, recovery_sample, decode_res = decoder.gbrbm_decoder(dataset, learning_rate=0.1, training_epochs=50, batch_size=1001, n_hidden=2000, plot_every=1) utils.write_data(decode_res, exp_name, "decoded_data") new_data = utils.tsne(decode_res, exp_name, "decoded_data", T, 2) utils.write_data(new_data, exp_name, "decoded_tsne_data_for_tsne")
def exp_gbrbm(exp_name, T=[]): dataset = dg.one_exception_dataset( N=6, n=1500, T=T, lam=5000, exc=1, noise_k=1 ) utils.write_data(dataset, exp_name, "generated_data") new_data = utils.tsne(dataset, exp_name, "generated_data", T, 2) utils.write_data(new_data, exp_name, "generated_data_for_tsne") _, recovery_sample, decode_res = decoder.gbrbm_decoder( dataset, learning_rate=0.1, training_epochs=50, batch_size=1001, n_hidden=2000, plot_every=1 ) utils.write_data(decode_res, exp_name, "decoded_data") new_data = utils.tsne(decode_res, exp_name, "decoded_data", T, 2) utils.write_data(new_data, exp_name, "decoded_tsne_data_for_tsne")
def cluster(data, true_labels, n_clusters=3): km = KMeans(init='k-means++', n_clusters=n_clusters, n_init=10) km.fit(data) km_means_labels = km.labels_ km_means_cluster_centers = km.cluster_centers_ km_means_labels_unique = np.unique(km_means_labels) colors_ = cycle(colors.cnames.keys()) initial_dim = np.shape(data)[1] data_2 = tsne(data, 2, initial_dim, 30) plt.figure(figsize=(12, 6)) plt.scatter(data_2[:, 0], data_2[:, 1], c=true_labels) plt.title('True Labels') return km_means_labels
def generate_raw_image_pixels(list_of_demonstrations): """ PCA and t-SNE on raw image pixels """ # Design matrix of raw image pixels X = None for demonstration in list_of_demonstrations: print "Raw image pixels ", demonstration PATH_TO_ANNOTATION = constants.PATH_TO_DATA + constants.ANNOTATIONS_FOLDER + demonstration + "_" + str(constants.CAMERA) + ".p" start, end = utils.get_start_end_annotations(PATH_TO_ANNOTATION) for frm in range(start, end + 1): if ((frm % 6) == 0): PATH_TO_IMAGE = utils.get_full_image_path(constants.PATH_TO_DATA + constants.NEW_FRAMES_FOLDER + demonstration + "_" + constants.CAMERA + "/", frm) print demonstration, str(frm) img = utils.reshape(cv2.imread(PATH_TO_IMAGE).flatten()) X = utils.safe_concatenate(X, img) X_pca = utils.pca(X, PC = 2) X_tsne = utils.tsne(X) data_dimred = [X_pca, X_tsne] pickle.dump(X_tsne, open("raw_pixel_" + demonstration + "_dimred.p", "wb"))
def tsne(): utils.tsne(app.config['CROPPED_PATH'], app.config['TSNE_PATH']) files_tsne = os.listdir(app.config['TSNE_PATH']) print('files:',files_tsne) return render_template("tsne.html", files_tsne = files_tsne)
def generate_SIFT(): data = pickle.load(open("sift_features/SIFT_plane_9_1.p", "rb")) X_pca = utils.pca(data, PC = 2) X_tsne = utils.tsne(data) data_dimred = [X_pca, X_tsne] pickle.dump(data_dimred, open("SIFT_plane_9_dimred.p", "wb"))
parser.add_argument("--image", help="Parse image mode", default = None) args = parser.parse_args() if args.a_2 and args.PATH_TO_DATA_2 and not args.image: X1, label_map_1, index_map_1 = parse_annotations_pickle(args.a, args.PATH_TO_DATA, args.layer) X2, label_map_2, index_map_2 = parse_annotations_pickle(args.a_2, args.PATH_TO_DATA_2, args.layer) X1_pca = utils.pca(X1) X2_pca = utils.pca(X2) plot_annotated_joint(X1_pca, X2_pca, label_map_1, index_map_1, label_map_2, index_map_2, figure_name = args.file_name +".png", title = "PCA " + args.layer) elif args.image and not args.PATH_TO_DATA_2: X, label_map, index_map = utils.parse_annotations_images(args.a, args.PATH_TO_DATA) pickle.dump(X, open(args.file_name + "_allimages.p", "wb")) pickle.dump(label_map, open(args.file_name + "_labelmap.p", "wb")) pickle.dump(index_map, open(args.file_name + "_indexmap.p", "wb")) IPython.embed() X_pca = utils.pca(X) X_tsne = utils.tsne(X) X_tsne_pca = utils.tsne_pca(X) utils.plot_annotated_embedding(X_pca, label_map, index_map, args.file_name + '_' + args.layer + '_pca.png', 'PCA ' + args.layer) utils.plot_annotated_embedding(X_tsne, label_map, index_map, args.file_name + '_' + args.layer + '_tsne.png', 't-SNE ' + args.layer) utils.plot_annotated_embedding(X_tsne_pca, label_map, index_map, args.file_name + '_' + args.layer + '_tsne_pca.png', 't-SNE (PCA Input) ' + args.layer) else: if args.a: X, label_map, index_map = parse_annotations_pickle(args.a, args.PATH_TO_DATA, args.layer) else: X, label_map, index_map = parse_annotations(args) X_pca = utils.pca(X) X_tsne = utils.tsne(X) X_tsne_pca = utils.tsne_pca(X) utils.plot_annotated_embedding(X_pca, label_map, index_map, args.file_name + '_' + args.layer + '_pca.png', 'PCA - C3D ' + args.layer) utils.plot_annotated_embedding(X_tsne, label_map, index_map, args.file_name + '_' + args.layer + '_tsne.png', 't-SNE - C3D ' + args.layer)