Code
import drnb.embed.pipeline as pl
from drnb.experiment import Experiment, merge_experiments, read_experimentPaCMAP uses locally-scaled neighbors by default, but it can also use k-nearest neighbors. Let’s see if there are any datasets where we can see a big difference. Note that we expect to see some variability in the results just due to the vagaries of the random number generator. See pacmap-repeats.ipynb for more details on that.
A potential use for local scaling is to reduce hubness, so apart from the typical datasets I tend to use with PaCMAP, I thought it would be good to try it on some datasets which are known to have hubness issues (see the hubness notebook for more details).
tasic2018 and lamanno2020 are transcriptomic datasets like macosko2015, iclr is a TF-IDF dataset, and we will swap out ng20pacmap for ng20, a 3000D version of the same underlying newsgroups TF-IDF data.
[23:42:37] INFO Running pacmap-lsn on curve2d experiment.py:65
[23:42:38] INFO Running pacmap-lsn on mammoth experiment.py:65
[23:42:56] INFO Running pacmap-lsn on scurvehole experiment.py:65
[23:42:59] INFO Running pacmap-lsn on isoswiss experiment.py:65
[23:43:05] INFO Running pacmap-lsn on hierarchical experiment.py:65
[23:43:29] INFO Running pacmap-lsn on spheres experiment.py:65
WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 101 to 100 dimensions.
[23:43:35] INFO Running pacmap-lsn on coil20 experiment.py:65
[23:43:36] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 16384 to 100 dimensions.
[23:43:40] INFO Running pacmap-lsn on coil100 experiment.py:65
[23:43:47] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 49152 to 100 dimensions.
[23:44:12] INFO Running pacmap-lsn on macosko2015 experiment.py:65
[23:44:14] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 3000 to 100 dimensions.
[23:44:46] INFO Running pacmap-lsn on tasic2018 experiment.py:65
[23:44:47] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 3000 to 100 dimensions.
[23:45:02] INFO Running pacmap-lsn on lamanno2020 experiment.py:65
WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 1999 to 100 dimensions.
[23:45:06] INFO Running pacmap-lsn on iclr experiment.py:65
[23:45:11] INFO Running pacmap-lsn on mnist experiment.py:65
[23:45:12] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 784 to 100 dimensions.
[23:45:54] INFO Running pacmap-lsn on fashion experiment.py:65
[23:45:55] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 784 to 100 dimensions.
[23:46:37] INFO Running pacmap-lsn on ng20 experiment.py:65
[23:46:38] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 2500 to 100 dimensions.
[23:46:51] INFO Running pacmap-knn on curve2d experiment.py:65
[23:46:52] INFO Running pacmap-knn on mammoth experiment.py:65
[23:47:09] INFO Running pacmap-knn on scurvehole experiment.py:65
[23:47:11] INFO Running pacmap-knn on isoswiss experiment.py:65
[23:47:17] INFO Running pacmap-knn on hierarchical experiment.py:65
[23:47:39] INFO Running pacmap-knn on spheres experiment.py:65
WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 101 to 100 dimensions.
[23:47:44] INFO Running pacmap-knn on coil20 experiment.py:65
[23:47:45] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 16384 to 100 dimensions.
[23:47:49] INFO Running pacmap-knn on coil100 experiment.py:65
[23:47:56] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 49152 to 100 dimensions.
[23:48:20] INFO Running pacmap-knn on macosko2015 experiment.py:65
[23:48:23] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 3000 to 100 dimensions.
[23:48:54] INFO Running pacmap-knn on tasic2018 experiment.py:65
[23:48:56] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 3000 to 100 dimensions.
[23:49:11] INFO Running pacmap-knn on lamanno2020 experiment.py:65
[23:49:12] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 1999 to 100 dimensions.
[23:49:16] INFO Running pacmap-knn on iclr experiment.py:65
[23:49:20] INFO Running pacmap-knn on mnist experiment.py:65
[23:49:22] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 784 to 100 dimensions.
[23:50:03] INFO Running pacmap-knn on fashion experiment.py:65
[23:50:04] WARNING Precomputed knn cannot be used: dimensionality will be reduced pacmap.py:146 from 784 to 100 dimensions.
[23:50:45] INFO Running pacmap-knn on ng20 experiment.py:65
I don’t see huge differences in the results here, within the natural variability that we saw in pacmap-repeats.ipynb.
PaCMAP uses PCA in two places by default: first, it reduces the dimensionality of the input data to 100D, and second it uses PCA to initialize coordinates.
The hubness notebook mentions that local scaling is effective reducing hubness, but hubness tends to have the largest effect on high-dimensional datasets. So maybe by applying the PCA preprocessing on the input data we are missing most of the benefit of local scaling with PaCMAP specifically for high dimensional datasets?
Let’s repeat the analysis and turn off the PCA preprocessing. A warning will be emitted that the nearest neighbor search will be slow, but in the current version of PaCMAP this is emitted even if we are providing a precomputed knn. We will still use PCA to initialize the coordinates.
If the dataset has less than 100 columns then the PCA isn’t applied, so we will remove all datasets that have fewer than 100 dimensions.
I expect results will look bad with the Euclidean metric with such high dimensionality, but I am curious if they will at least look different once local scaling goes to work on them.
[23:51:52] INFO Running pacmap-lsn-nopca on hierarchical experiment.py:65
[23:51:55] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:52:15] INFO Running pacmap-lsn-nopca on spheres experiment.py:65
WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:52:18] INFO Running pacmap-lsn-nopca on coil20 experiment.py:65
[23:52:19] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:52:21] INFO Running pacmap-lsn-nopca on coil100 experiment.py:65
[23:52:29] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:52:55] INFO Running pacmap-lsn-nopca on macosko2015 experiment.py:65
[23:52:59] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:53:21] INFO Running pacmap-lsn-nopca on tasic2018 experiment.py:65
[23:53:23] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:53:35] INFO Running pacmap-lsn-nopca on lamanno2020 experiment.py:65
[23:53:36] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:53:38] INFO Running pacmap-lsn-nopca on mnist experiment.py:65
[23:53:40] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:54:07] INFO Running pacmap-lsn-nopca on fashion experiment.py:65
[23:54:10] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:54:37] INFO Running pacmap-lsn-nopca on ng20 experiment.py:65
[23:54:38] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:54:47] INFO Running pacmap-knn-nopca on hierarchical experiment.py:65
[23:54:49] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:55:08] INFO Running pacmap-knn-nopca on spheres experiment.py:65
[23:55:09] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:55:11] INFO Running pacmap-knn-nopca on coil20 experiment.py:65
[23:55:12] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:55:15] INFO Running pacmap-knn-nopca on coil100 experiment.py:65
[23:55:22] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:55:48] INFO Running pacmap-knn-nopca on macosko2015 experiment.py:65
[23:55:51] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:56:14] INFO Running pacmap-knn-nopca on tasic2018 experiment.py:65
[23:56:16] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:56:28] INFO Running pacmap-knn-nopca on lamanno2020 experiment.py:65
[23:56:29] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:56:31] INFO Running pacmap-knn-nopca on mnist experiment.py:65
[23:56:32] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:56:59] INFO Running pacmap-knn-nopca on fashion experiment.py:65
[23:57:01] WARNING Running ANNOY Indexing on high-dimensional data. Nearest-neighbor pacmap.py:881 search may be slow!
[23:57:28] INFO Running pacmap-knn-nopca on ng20 experiment.py:65
As usual PCA has a big effect on macosko2015, but the effect is subtler on the other datasets. Not really obvious what local scaling achieves structurally as a whole, so I will merge these two experiments and plot them together (only datasets present in both experiments are retained).

Still not sure I see any systematic effect with local scaling. For example with PCA, going from the knn to lsn on lamanno2020 seems to create more separated clusters, but that isn’t the pattern when not using PCA. In the non-PCA case with macosko2015 maybe local scaling does separate some of the clusters out from the big cyan blob better, but the opposite might be true for ng20.
Jury’s out on this one. The effects on hubness seem undeniable, but that doesn’t seem to translate to an obvious effect on the embeddings.