colors = ['red', 'blue', 'darkgreen', 'orange', 'purple', 'gray'] cmaps = [ plt.cm.Reds, plt.cm.Blues, plt.cm.Greens, plt.cm.Oranges, plt.cm.Purples, plt.cm.gray_r ] i = 0 for k, v, in res.iteritems(): plt.subplot(1, 3, i + 1) i += 1 xmin = np.min(v[:, 0]) xmax = np.max(v[:, 0]) ymin = np.min(v[:, 1]) ymax = np.max(v[:, 1]) for l in range(nstrains): idx = label == l fplt.plot_embedding(v[idx], title=k, color=colors[l]) fplt.plot_embedding_contours(v[idx], cmap=cmaps[l], contours=15, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) #fig.suptitle('Embeddings JS-Diverence all') if fig_dir is not None: fig.savefig( os.path.join(fig_dir, 'new_JSD_embedding_all_tbins=%d.pdf' % (tbins))) fig.savefig( os.path.join(fig_dir, 'new_JSD_embedding_all_tbins=%d.png' % (tbins)))
for algo_name in algorithms: assert(algo_name in ALGORITHMS, "Unknown algorithm: %s" % algo_name) title = algo_name.title() + "-" + dataset.title() algo_class = getattr(algos, algo_name) algo = algo_class(n_components=2, **ALGORITHMS.get(algo_name, {})) try: logging.info("Running " + " ".join(title.split("-"))) if type == ARTIFICIAL: X_data = X[0] X_data.dtype='float64' X_reduced = algo.run(X_data) plot_artificial_dataset(X_data, X_reduced, color=X[1], title=title, save=args.save, saveDir=output_dir) else: X_data = X["data"] X_reduced = algo.run(X_data) # For 2 dimensional plot_embedding(X_reduced, X["target"], X["images"], X['target'], title, save=args.save, saveDir=output_dir) if args.threeD: # For 3 dimensional algo = algo_class(n_components=3, n_neighbors=30) X_reduced = algo.run(X_data) title = title + "-" + "3D" plot_embedding_3D(X_reduced, X["target"], title, save=args.save, saveDir=output_dir) except Exception, e: logging.error("Dataset: %s, Algorithm: %s crashed. Error::%s" % (dataset, algo_name, e))