Skip to main content

Quantification of local similarity across two maps/embeddings.

Project description


Python PyPI Version License Downloads Donate

  • Quantification of local similarity across two maps/embeddings.


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 =,map2)
fig    = flameplot.plot(scores)
X,y    = flameplot.import_example()
fig    = flameplot.scatter(Xcoord,Ycoord)



  • 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.


pip install numpy matplotlib
pip install -r requirements.txt

Quick Start

pip install flameplot
  • Alternatively, install flameplot from the GitHub source:
git clone
cd flameplot
python install

Import flameplot package

import flameplot as 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

# 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, X_tsne, n_steps=5)
# Compare PCA(2) vs. tSNE, X_tsne, n_steps=5)
# Compare random vs. tSNE, 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.


Please cite flameplot in your publications if this is useful for your research. Here is an example BibTeX entry:

  author={Erdogan Taskesen},
  • Taskesen, E. et al. Pan-cancer subtyping in a 2D-map shows substructures that are driven by specific combinations of molecular characteristics. Sci. Rep. 6, 24949




See LICENSE for details.


  • This package is created and maintained in my free time. If this package is usefull, you can show your gratitude :) Thanks!

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for flameplot, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size flameplot-0.1.3-py3-none-any.whl (53.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size flameplot-0.1.3.tar.gz (56.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page