lferry007 / LargeVis

Apache License 2.0
706 stars 167 forks source link

LargeVis

This is the official implementation of the LargeVis model by the original authors, which is used to visualize large-scale and high-dimensional data (Tang, Liu, Zhang and Mei). It now supports visualizing both high-dimensional feature vectors and networks. The package also contains a very efficient algorithm for constructing K-nearest neighbor graph (K-NNG).

Contact person: Jian Tang, tangjianpku@gmail.com. This work is done when the author is in Microsoft Research Asia.

Install

Both C++ source codes and Python wrapper are provided on Linux, OS X and Windows. To install the package, external packages are required, including GSL (GNU Scientific Library) on Linux and OS X or BOOST on Windows for generating random numbers.

Linux

Compile the source files via:

g++ LargeVis.cpp main.cpp -o LargeVis -lm -pthread -lgsl -lgslcblas -Ofast -march=native -ffast-math

To install the Python wrapper, modify setup.py to make sure that the GSL path is correctly set and then run sudo python setup.py install.

OS X

Install gsl using Homebrew:

brew install gsl

Modify line 347 of annoylib.h to change lseek64 to lseek. Then compile the source files (in the Linux folder) via:

g++ LargeVis.cpp main.cpp -o LargeVis -lm -pthread -lgsl -lgslcblas -Ofast -march=native -ffast-math -L/usr/local/lib -I/usr/local/include

To install the Python wrapper, run sudo python setup.py install.

Windows

To compile the source files, use Microsoft Visual Studio, where you need to set the BOOST path.

To install the Python wrapper, modify setup.py to make sure that the BOOST path is correctly set and then run python setup.py install.

Usage

LargeVis is suitable for visualizing both high-dimensional feature vectors and networks. For high-dimensional feature vectors, the format of input file should be as follows: the first line specifies the number of feature vectors and the dimensionality (500 vectors with 10 dimensions in the following example), and each of the next 500 lines describes one feature vector with 10 float numbers.

500 10
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
...
...
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0

For networks, each line of the input file is a DIRECTED edge. For each undirected edge, users must use TWO DIRECTED edges to represent it. For example,

0 1 2.5
1 0 2.5
2 5 4.5
5 2 4.5
3 10 3.0
...
...
495 498 1.5

For C++ executable file,

./LargeVis -input -output

or for Python,

python LargeVis_run.py -input -output

Besides the two parameters, other optional parameters include:

Examples

We provide some examples including MNIST(high-dimensional feature vectors) and CondMat(networks) in the Examples/ folder.

For example, to visualize the MNIST dataset,

python LargeVis_run.py -input mnist_vec784D.txt -output mnist_vec2D.txt -threads 16
python plot.py -input mnist_vec2D.txt -label mnist_label.txt -output mnist_vec2D_plot

plot of mnist

Please cite the following paper if you use LargeVis to visualize your data.

Citation

@inproceedings{tang2016visualizing,
  title={Visualizing Large-scale and High-dimensional Data},
  author={Tang, Jian and Liu, Jingzhou and Zhang, Ming and Mei, Qiaozhu},
  booktitle={Proceedings of the 25th International Conference on World Wide Web},
  pages={287--297},
  year={2016},
  organization={International World Wide Web Conferences Steering Committee}
}

Acknowledgement

Some methods of this package are from a previous work of the LargeVis authors, LINE (Large-scale Information Network Embedding).