Quantification of local similarity across two maps/embeddings.
Project description
flameplot
 Quantification of local similarity across two maps/embeddings.
Method
To compare the embedding of samples in two different maps, we propose a scale dependent similarity measure. For a pair of maps X and Y, we compare the sets of the, respectively, kx and ky nearest neighbours of each sample. We first define the variable rxij as the rank of the distance of sample j among all samples with respect to sample i, in map X. The nearest neighbor of sample i will have rank 1, the second nearest neighbor rank 2, etc. Analogously, ryij is the rank of sample j with respect to sample i in map Y. Now we define a score on the interval [0, 1], as (eq. 1)
where the variable n is the total number of samples, and the indicator function is given by (eq. 2)
The score sx,y(kx, ky) will have value 1 if, for each sample, all kx nearest neighbours in map X are also the ky nearest neighbours in map Y, or vice versa. Note that a local neighborhood of samples can be set on the minimum number of samples in the class. Alternatively, kxy can be also set on the average class size.
Schematic overview
Schematic overview to systematically compare local and global differences between two sample projections. For illustration we compare two input maps (x and y) in which each map contains n samples (step 1). The second step is the ranking of samples based on Euclidean distance. The ranks of map x are subsequently compared to the ranks of map y for kx and ky nearest neighbours (step 3). The overlap between ranks (step 4), is subsequently summarized in Score: Sx,y(kx,ky).
Functions in flameplot
scores = flameplot.compare(map1,map2) fig = flameplot.plot(scores) X,y = flameplot.import_example() fig = flameplot.scatter(Xcoord,Ycoord)
Contents
Installation
 Install flameplot from PyPI (recommended). flameplot is compatible with Python 3.6+ and runs on Linux, MacOS X and Windows.
 It is distributed under the MIT license.
Requirements
pip install numpy matplotlib or pip install r requirements.txt
Quick Start
pip install flameplot
 Alternatively, install flameplot from the GitHub source:
git clone https://github.com/erdogant/flameplot.git
cd flameplot
python setup.py install
Import flameplot package
import flameplot as flameplot
flameplot
Comparison between two maps follow the quantification of local similarity approach.
# Load libraries from sklearn import (manifold, decomposition) import pandas as pd import numpy as np # Load example data X,y=flameplot.import_example() # PCA top 50 PCs X_pca_50 = decomposition.TruncatedSVD(n_components=50).fit_transform(X) # PCA top 2 PCs X_pca_2 = decomposition.TruncatedSVD(n_components=2).fit_transform(X) # tSNE X_tsne = manifold.TSNE(n_components=2, init='pca').fit_transform(X) # Random X_rand=np.c_[np.random.permutation(X_tsne[:,0]), np.random.permutation(X_tsne[:,1])]
Scatter for illustrations purposes
import flameplot as flameplot flameplot.scatter(X_pca_2[:,0], X_pca_2[:,1], label=y, title='PCA') flameplot.scatter(X_tsne[:,0], X_tsne[:,1], label=y, title='tSNE') flameplot.scatter(X_rand[:,0], X_rand[:,1], label=y, title='Random')
Now we have the coordinates and can make the comparison and plot!
# Compare PCA(50) vs. tSNE scores1=flameplot.compare(X_pca_50, X_tsne, n_steps=5) # Compare PCA(2) vs. tSNE scores2=flameplot.compare(X_pca_2, X_tsne, n_steps=5) # Compare random vs. tSNE scores=flameplot.compare(X_rand, X_tsne, n_steps=5) # plot fig=flameplot.plot(scores1, xlabel='PCA (50d)', ylabel='tSNE (2d)') fig=flameplot.plot(scores, xlabel='PCA (2d)', ylabel='tSNE (2d)') fig=flameplot.plot(scores, xlabel='Random (2d)', ylabel='tSNE (2d)')
The comparison between the top 50D of PCA vs. 2D tSNE resulted in high similarities on local and global scales. The axis are the number of "neirest neighbors" (nn). What we see is that on local scales (low nn) high similarity is seen between the maps but also in higher scales.
The comparison between the top 2D of PCA vs. 2D tSNE resulted in much lower similarities compared to the 50D on local and global scales. What we see is that on local scales (low nn) there is low similarity which depicts that samples have different neighbors. On larger scale it becomes a bit more greenish and slightly more similarities are seen on average between the neighbors. This would basically suggest that the same digits are detected globally but are differently ordered on local scales.
The comparison between the Random data points vs. 2D tSNE resulted in low similarities on both local and global scales. This what we expect to see as we permuted the data.
Citation
Please cite flameplot in your publications if this is useful for your research. Here is an example BibTeX entry:
@misc{erdogant2019flameplot, title={flameplot}, author={Erdogan Taskesen}, year={2019}, howpublished={\url{https://github.com/erdogant/flameplot}}, }
 Taskesen, E. et al. Pancancer subtyping in a 2Dmap shows substructures that are driven by specific combinations of molecular characteristics. Sci. Rep. 6, 24949
Maintainers
 Erdogan Taskesen, github: erdogant
References
Licence
See LICENSE for details.
Project details
Release history Release notifications
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size  File type  Python version  Upload date  Hashes 

Filename, size flameplot0.1.2py3noneany.whl (52.8 kB)  File type Wheel  Python version py3  Upload date  Hashes View hashes 
Filename, size flameplot0.1.2.tar.gz (53.1 kB)  File type Source  Python version None  Upload date  Hashes View hashes 
Hashes for flameplot0.1.2py3noneany.whl
Algorithm  Hash digest  

SHA256  e0415f889ab5f173e2e222cf9f7cff62c4ebcc43265547b5522c75569f512d32 

MD5  321fb6c362e2d0a9c5d503a29b739cd9 

BLAKE2256  511c63f9ec2292d6d5d9d68975ab41ed67790819abe4a03f519ac872529839a7 