This software package contains a Barnes-Hut implementation of the t-SNE algorithm. The implementation is described in this paper.
Compile the source using the following command:
g++ sptree.cpp tsne.cpp -o bh_tsne -O2
That's all!
The code comes with wrappers for Matlab and Python. These wrappers write your data to a file called data.dat
, run the bh_tsne
binary, and read the result file result.dat
that the binary produces. There are also external wrappers available for Torch and R. Writing your own wrapper should be straightforward; please refer to one of the existing wrappers for the format of the data and result files.
Demonstration of usage in Matlab:
filename = websave('mnist_train.mat', 'https://github.com/awni/cs224n-pa4/blob/master/Simple_tSNE/mnist_train.mat?raw=true');
load(filename);
numDims = 2; pcaDims = 50; perplexity = 50; theta = .5;
map = fast_tsne(digits', numDims, pcaDims, perplexity, theta);
gscatter(map(:,1), map(:,2), labels');