Science Score: 20.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
✓Committers with academic emails
1 of 6 committers (16.7%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.1%) to scientific vocabulary
Last synced: 11 months ago
·
JSON representation
Repository
TriMap: Large-scale Dimensionality Reduction Using Triplets
Basic Info
Statistics
- Stars: 318
- Watchers: 9
- Forks: 21
- Open Issues: 6
- Releases: 0
Created about 8 years ago
· Last pushed almost 4 years ago
Metadata Files
Readme
License
README.rst
======
TriMap
======
TriMap is a dimensionality reduction method that uses triplet constraints
to form a low-dimensional embedding of a set of points. The triplet constraints
are of the form "point *i* is closer to point *j* than point *k*". The triplets are
sampled from the high-dimensional representation of the points and a weighting
scheme is used to reflect the importance of each triplet.
TriMap provides a significantly better global view of the data than the
other dimensionality reduction methods such t-SNE, LargeVis, and UMAP. The global
structure includes relative distances of the clusters, multiple scales in
the data, and the existence of possible outliers. We define a global score to quantify the quality of an embedding in reflecting the global structure of the data.
CIFAR-10 dataset (test set) passed through a CNN (*n = 10,000, d = 1024*): Notice the semantic structure unveiled by TriMap.
.. image:: results/cifar10.png
:alt: Visualizations of the CIFAR-10 dataset
The following implementation is in Python. Further details and more experimental results are available in the `paper `_. See the `example colab `_ for some analysis.
-----------------
News!
-----------------
[Mar 16, 2022] An example colab using TriMap `JAX implementation `_ is now available at https://github.com/eamid/examples/blob/master/TriMap.ipynb. We analyze the results on S-curve, MNIST, Fashion MNIST, etc. using t-SNE, UMAP, TriMap, and PCA.
[Feb 17, 2022] A JAX implementation is now available at https://github.com/google-research/google-research/tree/master/trimap. More updates are coming soon!
-----------------
How to use TriMap
-----------------
TriMap has a transformer API similar to other sklearn libraries. To use
TriMap with the default parameters, simply do:
.. code:: python
import trimap
from sklearn.datasets import load_digits
digits = load_digits()
embedding = trimap.TRIMAP().fit_transform(digits.data)
To find the embedding using a precomputed pairwise distance matrix D, pass D as input and set use_dist_matrix to True:
.. code:: python
embedding = trimap.TRIMAP(use_dist_matrix=True).fit_transform(D)
You can also pass the precomputed k-nearest neighbors and their corresponding distances as a tuple (knn_nbrs, knn_distances). Note that the rows must be in order, starting from point 0 to n-1. This feature also requires X to compute the embedding
.. code:: python
embedding = trimap.TRIMAP(knn_tuple=(knn_nbrs, knn_distances)).fit_transform(X)
To calculate the global score, do:
.. code:: python
gs = trimap.TRIMAP(verbose=False).global_score(digits.data, embedding)
print("global score %2.2f" % gs)
-----------------
Parameters
-----------------
The list of parameters is given blow:
- ``n_dims``: Number of dimensions of the embedding (default = 2)
- ``n_inliers``: Number of nearest neighbors for forming the nearest neighbor triplets (default = 12).
- ``n_outliers``: Number of outliers for forming the nearest neighbor triplets (default = 4).
- ``n_random``: Number of random triplets per point (default = 3).
- ``distance``: Distance measure ('euclidean' (default), 'manhattan', 'angular' (or 'cosine'), 'hamming')
- ``weight_temp``: Temperature of the logarithm applied to the weights. Larger temperatures generate more compact embeddings. weight_temp=0. corresponds to no transformation (default=0.5).
- ``weight_adj`` (deprecated): The value of gamma for the log-transformation (default = 500.0).
- ``lr``: Learning rate (default = 0.1).
- ``n_iters``: Number of iterations (default = 400).
The other parameters include:
- ``knn_tuple``: Use the precomputed nearest-neighbors information in form of a tuple (knn_nbrs, knn_distances) (default = None)
- ``use_dist_matrix``: Use the precomputed pairwise distance matrix (default = False)
- ``apply_pca``: Reduce the number of dimensions of the data to 100 if necessary before applying the nearest-neighbor search (default = True).
- ``opt_method``: Optimization method {'sd' (steepest descent), 'momentum' (GD with momentum), 'dbd' (delta-bar-delta, default)}.
- ``verbose``: Print the progress report (default = False).
- ``return_seq``: Store the intermediate results and return the results in a tensor (default = False).
An example of adjusting these parameters:
.. code:: python
import trimap
from sklearn.datasets import load_digits
digits = load_digits()
embedding = trimap.TRIMAP(n_inliers=20,
n_outliers=10,
n_random=10).fit_transform(digits.data)
The nearest-neighbor calculation is performed using `ANNOY `_.
--------
Examples
--------
The following are some of the results on real-world datasets. The values of nearest-neighbor accuracy and global score are shown as a pair (NN, GS) on top of each figure. For more results, please refer to our `paper `_.
USPS Handwritten Digits (*n = 11,000, d = 256*)
.. image:: results/usps.png
:alt: Visualizations of the USPS dataset
20 News Groups (*n = 18,846, d = 100*)
.. image:: results/news20.png
:alt: Visualizations of the 20 News Groups dataset
Tabula Muris (*n = 53,760, d = 23,433*)
.. image:: results/tabula.png
:alt: Visualizations of the Tabula Muris Mouse Tissues dataset
MNIST Handwritten Digits (*n = 70,000, d = 784*)
.. image:: results/mnist.png
:alt: Visualizations of the MNIST dataset
Fashion MNIST (*n = 70,000, d = 784*)
.. image:: results/fmnist.png
:alt: Visualizations of the Fashion MNIST dataset
TV News (*n = 129,685, d = 100*)
.. image:: results/tvnews.png
:alt: Visualizations of the TV News dataset
Runtime of t-SNE, LargeVis, UMAP, and TriMap in the hh:mm:ss format on a single machine with 2.6 GHz Intel Core i5 CPU and 16 GB of memory is given in the following table. We limit the runtime of each method to 12 hours. Also, UMAP runs out of memory on datasets larger than ~4M points.
.. image:: results/runtime.png
:alt: Runtime of TriMap compared to other methods
----------
Installing
----------
Requirements:
* numpy
* scikit-learn
* numba
* annoy
**Installing annoy**
If you are having trouble with installing `annoy` on macOS using the command:
.. code:: bash
pip3 install annoy
you can alternatively try:
.. code:: bash
pip3 install git+https://github.com/sutao/annoy.git@master
**Install Options**
If you have all the requirements installed, you can use pip:
.. code:: bash
sudo pip install trimap
Please regularly check for updates and make sure you are using the most recent version. If you have TriMap installed and would like to upgrade to the newer version, you can use the command:
.. code:: bash
sudo pip install --upgrade --force-reinstall trimap
An alternative is to install the dependencies manually using anaconda and using pip
to install TriMap:
.. code:: bash
conda install numpy
conda install scikit-learn
conda install numba
conda install annoy
pip install trimap
For a manual install get this package:
.. code:: bash
wget https://github.com/eamid/trimap/archive/master.zip
unzip master.zip
rm master.zip
cd trimap-master
Install the requirements
.. code:: bash
sudo pip install -r requirements.txt
or
.. code:: bash
conda install scikit-learn numba annoy
Install the package
.. code:: bash
python setup.py install
------------------------
Support and Contribution
------------------------
This implementation is still a work in progress. Any comments/suggestions/bug-reports
are highly appreciated. Please feel free contact me at: eamid@ucsc.edu. If you would
like to contribute to the code, please `fork the project `_
and send me a pull request.
--------
Citation
--------
If you use TriMap in your publications, please cite our current reference on arXiv:
::
@article{2019TRIMAP,
author = {{Amid}, Ehsan and {Warmuth}, Manfred K.},
title = "{TriMap: Large-scale Dimensionality Reduction Using Triplets}",
journal = {arXiv preprint arXiv:1910.00204},
archivePrefix = "arXiv",
eprint = {1910.00204},
year = 2019,
}
-------
License
-------
Please see the LICENSE file.
Owner
- Name: Ehsan Amid
- Login: eamid
- Kind: user
- Company: @google
- Website: https://sites.google.com/view/eamid/
- Twitter: esiamid
- Repositories: 9
- Profile: https://github.com/eamid
Research Scientist at Google Brain Mountain View
GitHub Events
Total
- Issues event: 4
- Watch event: 16
- Issue comment event: 2
- Pull request event: 2
Last Year
- Issues event: 4
- Watch event: 16
- Issue comment event: 2
- Pull request event: 2
Committers
Last synced: over 3 years ago
All Time
- Total Commits: 91
- Total Committers: 6
- Avg Commits per committer: 15.167
- Development Distribution Score (DDS): 0.275
Top Committers
| Name | Commits | |
|---|---|---|
| Ehsan | e****n@g****m | 66 |
| Ehsan | E****n@E****l | 15 |
| Ehsan | E****n@e****u | 7 |
| Benson Muite | b****t@u****m | 1 |
| Evan Rees | 2****n@u****m | 1 |
| James Melville | j****e@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: about 1 year ago
All Time
- Total issues: 22
- Total pull requests: 6
- Average time to close issues: 21 days
- Average time to close pull requests: 2 days
- Total issue authors: 19
- Total pull request authors: 5
- Average comments per issue: 2.5
- Average comments per pull request: 0.5
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 1
- Average time to close issues: 16 days
- Average time to close pull requests: N/A
- Issue authors: 2
- Pull request authors: 1
- Average comments per issue: 0.0
- Average comments per pull request: 0.0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- 53845714nF (2)
- bkmgit (2)
- cciccole (2)
- shancarter (2)
- jochenater (1)
- jlmelville (1)
- WiscEvan (1)
- Voytech-0 (1)
- Vykintasj (1)
- taylori7 (1)
- groceryheist (1)
- ghost (1)
- YuXiaokang (1)
- owlisie (1)
- timjim333 (1)
Pull Request Authors
- mathematicalmichael (2)
- yaxu75 (2)
- jlmelville (1)
- WiscEvan (1)
- bkmgit (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 1,449 last-month
- Total docker downloads: 58
- Total dependent packages: 1
- Total dependent repositories: 8
- Total versions: 25
- Total maintainers: 1
pypi.org: trimap
TriMap: Large-scale Dimensionality Reduction Using Triplets
- Homepage: http://github.com/eamid/trimap
- Documentation: https://trimap.readthedocs.io/
- License: LICENSE.txt
-
Latest release: 1.1.4
published over 4 years ago
Rankings
Docker downloads count: 3.3%
Stargazers count: 3.9%
Dependent packages count: 4.8%
Dependent repos count: 5.2%
Average: 6.2%
Forks count: 8.7%
Downloads: 11.2%
Maintainers (1)
Last synced:
12 months ago
Dependencies
requirements.txt
pypi
- annoy ==1.16.3
- numba >=0.34
- numpy >=1.13
- scikit-learn >=0.18