def make_test_globals(): """Prepare global objects used in the doctests""" print("Prepare doctest globals", flush=True) # Test using a small data sample of 10000 random integers 0-255 # with 16 dimensions hsne_data = np.random.randint(256, size=(10000, 16)) tsne_data = np.random.randint(256, size=(2000, 16)) # Create a sample hsne with 3 levels and # save this to a sample file hsne = nptsne.HSne(True) hsne.create_hsne(hsne_data, 3) file_name = "rnd10000x16.hsne" hsne.save(file_name) top_analysis = nptsne.hsne_analysis.Analysis(hsne, nptsne.hsne_analysis.EmbedderType.CPU) print("End prepare doctest globals", flush=True) return { "sample_hsne": hsne, "sample_analysis": top_analysis, "sample_scale0": hsne.get_scale(0), "sample_scale1": hsne.get_scale(1), "sample_scale2": hsne.get_scale(2), "sample_hsne_file": file_name, "sample_hsne_data": hsne_data, "sample_tsne_data": tsne_data, "sample_texture_tsne": nptsne.TextureTsne(), "sample_texture_tsne_extended": nptsne.TextureTsneExtended() }
def step_impl(context): context.tsne = nptsne.TextureTsneExtended(False)
'data': mnist_raw['data'].T, 'target': mnist_raw['label'][0], 'COL_NAMES': ['label', 'data'] } colors = [ '#EE3333', '#FF9900', '#FFEE00', '#AACC11', '#44AA77', '#0099EE', '#0066BB', '#443388', '#992288', '#EE0077' ] # norm = mcolors.Normalize(vmin=0, vmax=9) # mcolors.ListedColormap(colors) rc('lines', linewidth=2) rc('lines', markersize=1) tsne = nptsne.TextureTsneExtended(False) embeddings = [] if tsne.init_transform(mnist['data']): print('Init succeeded') for i in range(20): plt.figure(i + 1) start = timer() # reduce the forces from iteration 1000 if i == 10: tsne.start_exaggeration_decay() print(f'exaggeration stopping at {tsne.decay_started_at}') embedding = tsne.run_transform(verbose=False, iterations=100) end = timer() print(f'got embedding in {end - start}') print(f'iteration count {tsne.iteration_count}')
umap_embed = umap.UMAP().fit_transform(subData) print(umap_embed.shape) plt.figure(40) print(subLabel) print(umap_embed) plt.scatter(umap_embed[..., 0], umap_embed[..., 1], c=subLabel, cmap=mcolors.ListedColormap(colors), facecolors='None', marker='o') plt.draw() plt.savefig(f'testexum_00.png') tsne = nptsne.TextureTsneExtended(verbose=True) print(f'Init tSNE from umap, shape: {umap_embed.shape}') if tsne.init_transform(subData, umap_embed): print('Init from umap succeeded') step_size = 100 for i in range(20): plt.figure(i + 1) start = timer() exaggeration_iter = 100 # reduce the forces from 1000 if i == 10: tsne.start_exaggeration_decay() print(f'exaggeration stopping at {tsne.decay_started_at}')