def test_no_kwargs(self, dummy_dmap, dim): mydmap = dummy_dmap fig = viz.embedding_plot(mydmap, dim=dim, scatter_kwargs=None, show=False) assert (fig)
def test_colormap(self, dummy_dmap, cmap): # This just tests if the code runs... # Replace with something more stringent? mydmap = dummy_dmap scatter_kwargs = {'c': mydmap.dmap[:, 0], 'cmap': cmap} fig = viz.embedding_plot(mydmap, scatter_kwargs=scatter_kwargs, show=False) assert(fig)
def test_size(self, dummy_dmap, size): mydmap = dummy_dmap scatter_kwargs = {'s': size} fig = viz.embedding_plot(mydmap, scatter_kwargs=scatter_kwargs, show=False) SC = fig.axes[0].collections[0] actual_sizes = SC.get_sizes() assert(np.all(actual_sizes == size))
def test_fixed_coloring(self, dummy_dmap): mydmap = dummy_dmap scatter_kwargs = {'c': 'r'} true_coloring = (1.0, 0., 0., 1) fig = viz.embedding_plot(mydmap, scatter_kwargs=scatter_kwargs, show=False) SC = fig.axes[0].collections[0] assert(np.all(SC._facecolors[0] == true_coloring))
eps = 0.01 mydmap = dm.DiffusionMap(n_evecs=2, epsilon=eps, alpha=1.0, k=400) mydmap.fit_transform(data) #real_evals = np.array([2, 2, 2, 6]) #test_evals = -4./eps*(mydmap.evals - 1) #eval_error = np.abs(test_evals-real_evals)/real_evals #print(test_evals) #print(eval_error) from pydiffmap.visualization import embedding_plot, data_plot embedding_plot(mydmap, dim=2, scatter_kwargs={ 'c': mydmap.dmap[:, 0], 'cmap': 'Spectral' }) plt.show() data_plot(mydmap, dim=3, scatter_kwargs={'cmap': 'Spectral'}) plt.show() northpole = np.argmax(mydmap.dmap[:, 0]) north = data[northpole, :] phi_n = Phi[northpole] theta_n = Theta[northpole] R = np.array([[ np.sin(theta_n) * np.cos(phi_n), np.sin(theta_n) * np.sin(phi_n), -np.cos(theta_n) ], [-np.sin(phi_n), np.cos(phi_n), 0],
plt.xlim([-2, 2]) plt.ylim([-2, 2]) plt.show() mydmap = dm.DiffusionMap(n_evecs=2, epsilon=.2, alpha=0.5, k=400, metric='euclidean') dmap = mydmap.fit_transform(X) from pydiffmap.visualization import embedding_plot embedding_plot(mydmap, scatter_kwargs={ 'c': X[:, 0], 's': 5, 'cmap': 'coolwarm' }) plt.show() from pydiffmap.visualization import data_plot data_plot(mydmap, scatter_kwargs={'s': 5, 'cmap': 'coolwarm'}) plt.show() V = DW beta = 1 target_distribution = np.zeros(len(X)) for i in range(len(X)): target_distribution[i] = np.exp(-beta * V(X[i]))
# initialize Diffusion map object. neighbor_params = {'n_jobs': -1, 'algorithm': 'ball_tree'} mydmap = dm.DiffusionMap(n_evecs=2, k=200, epsilon='bgh', alpha=1.0, neighbor_params=neighbor_params) # fit to data and return the diffusion map. dmap = mydmap.fit_transform(swiss_roll) from pydiffmap.visualization import embedding_plot, data_plot embedding_plot(mydmap, scatter_kwargs={ 'c': phi, 's': mydmap.q, 'cmap': 'Spectral' }) data_plot(mydmap, dim=3, scatter_kwargs={'cmap': 'Spectral'}) plt.show() print('Correlation between \phi and \psi_1') print(np.corrcoef(dmap[:, 0], phi)) plt.figure(figsize=(16, 6)) ax = plt.subplot(121) ax.scatter(phi, dmap[:, 0]) ax.set_title('First DC against $\phi$') ax.set_xlabel(r'$\phi$') ax.set_ylabel(r'$\psi_1$') ax.axis('tight')