#coords = scale_to_interval(coords, max=100) print 'writing coordinates to csv' csv_writer = csv.writer(open(output_file, 'wb'), delimiter=',') for r in xrange(len(coords)): csv_writer.writerow(coords[r].astype('|S12')) # format with 10dp accuracy (but no '-e' format stuff) if __name__ == '__main__': codes_file = 'test/test_codes.csv' coords_file = 'out/test_coords.csv' codes = numpy.genfromtxt(codes_file, dtype=numpy.float32, delimiter=',') codes = codes[:,1:] for perplexity in xrange(20): try: tsne = TSNE(perplexity=perplexity, desired_dims=2) tsne.initialize_with_codes(codes) tsne.fit(iterations=500) tsne.save_coords_to_file(coords_file) density_plot_file = 'out/test_map_%i.png'%perplexity labels_file = 'test/test_labels.csv' render = Render(coords_file, labels_file) render.plot_density(density_plot_file) except: print 'failed to compute with perplexity %i'%perplexity
desired_dims = cfg.tsne.desired_dims target_iterations = cfg.tsne.initial_fit_iterations # FIXME2 slightly braindead way to work out epochs expected (just run through it) total_epochs = 0 if target_perplex >= (len(codes) / 2): total_epochs = 1 print len(codes) perplexity = len(codes) / 2 while perplexity > target_perplex: perplexity = perplexity / 2 total_epochs = total_epochs + 1 iterations_per = target_iterations / total_epochs print "will run for %i total epochs at %i iterations each " % (total_epochs, iterations_per) # initialize tsne = TSNE(desired_dims=desired_dims) tsne.initialize_with_codes(codes) # fit with reducing perplexity, ending up at target complexity perplexity = len(codes) / 2 while perplexity > target_perplex: print "training with perplexity", perplexity tsne.perplexity = perplexity tsne.fit(iterations_per) perplexity = perplexity / 2 print "done training" tsne.save_coords_to_file(coords_file)