drnb notebooks
  • Notebooks
  • GitHub
  1. Articles
  2. PaCMAP Repeats
  • Experiments in Dimensionality Reduction
  • Articles
    • Do Hubs Hurt?
    • How Does Dimensionality Reduction Transform Distances?
    • Hubness
    • Heavy-tailed UMAP
    • Leopold: Lightweight Estimate of Preservation of Local Density
    • Measuring Media Bias
    • Normalized Compression Distance with 20 Newsgroups
    • PaCMAP: local scaling vs. k-nearest neighbors
    • PaCMAP Repeats
    • Neighbor Overlap and PCA
    • Neighbor Recall: UMAP vs t-SNE
    • Approximating Isomap with k-Nearest Neighbors and Stochastic Metric Multidimensional Scaling
    • Stochastic Metric Multidimensional Scaling
    • Renormalizing after TF-IDF + SVD
    • t-SNE Consistency with Random Initialization
    • UMAP with Annealed Neighbors. 1: Defaults
    • UMAP with Annealed Neighbors. 2: t-UMAP
    • UMAP with Annealed Neighbors. 3: PCA Initialization
    • Spectral Embedding
    • UMATO Evaluation
    • t-SNE Affinity: Gaussian vs. Uniform

On this page

  • UMAP Comparison
  1. Articles
  2. PaCMAP Repeats

PaCMAP Repeats

  • Show All Code
  • Hide All Code

PaCMAP is pretty robust to the effect of random numbers, but to see just how robust it is, we can run it multiple times with the same parameters and see how the results vary. Because the defaults start with PCA initialization, this is a best case scenario, because usually results are most affected by the initialization.

Four repeats should be enough to get a sense of what’s going on without completely overwhelming our senses.

Code
from drnb.experiment import Experiment
Code
experiment = Experiment(name="pacmap-repeats")
[13:27:03] WARNING  Experiment directory already exists:                              __init__.py:85
                    /home/james/rdev/datasets/experiments/pacmap-repeats. Existing                  
                    shards may be reused; use a new name or clear_storage() if you                  
                    want a fresh run.                                                               
Code
for i in range(1, 5):
    experiment.add_method(
        "pacmap",
        name=f"pacmap-{i}",
    )

The datasets chosen for this are several which are used in the PaCMAP paper and also three transcriptomics data sets (kazer, kang and stuart) used in a follow-up paper on reproducibility on biological data (see the scrna-dr2020 notebook for more details). I also threw in three other transcriptomics datasets (macosko2015, tasic2018 and lamanno2020).

Code
datasets = [
    "curve2d",
    "mammoth",
    "scurvehole",
    "isoswiss",
    "synthetic-hierarchical",
    "spheres",
    "coil20",
    "coil100",
    "mnist",
    "fashion",
    "ng20pacmap",
    "macosko2015",
    "tasic2018",
    "lamanno2020",
    "kazer",
    "stuart",
    "kang",
]
Code
experiment.add_datasets(datasets)
Code
experiment.clear_storage()
experiment.run()
[14:22:18] WARNING  Deleting experiment storage at                                   __init__.py:359
                    /home/james/rdev/datasets/experiments/pacmap-repeats                            
[14:22:19] INFO     Experiment pacmap-repeats writing to                             __init__.py:169
                    /home/james/rdev/datasets/experiments/pacmap-repeats                            
           INFO     Running pacmap-1 on curve2d                                      __init__.py:235
[14:22:23] INFO     Running pacmap-1 on mammoth                                      __init__.py:235
[14:22:47] INFO     Running pacmap-1 on scurvehole                                   __init__.py:235
[14:22:53] INFO     Running pacmap-1 on isoswiss                                     __init__.py:235
[14:23:04] INFO     Running pacmap-1 on synthetic-hierarchical                       __init__.py:235
[14:23:31] INFO     Running pacmap-1 on spheres                                      __init__.py:235
[14:23:39] INFO     Running pacmap-1 on coil20                                       __init__.py:235
[14:23:47] INFO     Running pacmap-1 on coil100                                      __init__.py:235
[14:24:40] INFO     Running pacmap-1 on mnist                                        __init__.py:235
[14:25:36] INFO     Running pacmap-1 on fashion                                      __init__.py:235
[14:26:29] INFO     Running pacmap-1 on ng20pacmap                                   __init__.py:235
[14:26:39] INFO     Running pacmap-1 on macosko2015                                  __init__.py:235
[14:27:25] INFO     Running pacmap-1 on tasic2018                                    __init__.py:235
[14:27:49] INFO     Running pacmap-1 on lamanno2020                                  __init__.py:235
[14:27:56] INFO     Running pacmap-1 on kazer                                        __init__.py:235
[14:28:23] INFO     Running pacmap-1 on stuart                                       __init__.py:235
[14:28:38] INFO     Running pacmap-1 on kang                                         __init__.py:235
[14:28:46] INFO     Running pacmap-2 on curve2d                                      __init__.py:235
[14:28:51] INFO     Running pacmap-2 on mammoth                                      __init__.py:235
[14:29:14] INFO     Running pacmap-2 on scurvehole                                   __init__.py:235
[14:29:21] INFO     Running pacmap-2 on isoswiss                                     __init__.py:235
[14:29:31] INFO     Running pacmap-2 on synthetic-hierarchical                       __init__.py:235
[14:29:58] INFO     Running pacmap-2 on spheres                                      __init__.py:235
[14:30:07] INFO     Running pacmap-2 on coil20                                       __init__.py:235
[14:30:15] INFO     Running pacmap-2 on coil100                                      __init__.py:235
[14:31:07] INFO     Running pacmap-2 on mnist                                        __init__.py:235
[14:32:05] INFO     Running pacmap-2 on fashion                                      __init__.py:235
[14:32:59] INFO     Running pacmap-2 on ng20pacmap                                   __init__.py:235
[14:33:09] INFO     Running pacmap-2 on macosko2015                                  __init__.py:235
[14:33:56] INFO     Running pacmap-2 on tasic2018                                    __init__.py:235
[14:34:20] INFO     Running pacmap-2 on lamanno2020                                  __init__.py:235
[14:34:27] INFO     Running pacmap-2 on kazer                                        __init__.py:235
[14:34:54] INFO     Running pacmap-2 on stuart                                       __init__.py:235
[14:35:10] INFO     Running pacmap-2 on kang                                         __init__.py:235
[14:35:18] INFO     Running pacmap-3 on curve2d                                      __init__.py:235
[14:35:23] INFO     Running pacmap-3 on mammoth                                      __init__.py:235
[14:35:49] INFO     Running pacmap-3 on scurvehole                                   __init__.py:235
[14:35:56] INFO     Running pacmap-3 on isoswiss                                     __init__.py:235
[14:36:06] INFO     Running pacmap-3 on synthetic-hierarchical                       __init__.py:235
[14:36:33] INFO     Running pacmap-3 on spheres                                      __init__.py:235
[14:36:42] INFO     Running pacmap-3 on coil20                                       __init__.py:235
[14:36:50] INFO     Running pacmap-3 on coil100                                      __init__.py:235
[14:37:47] INFO     Running pacmap-3 on mnist                                        __init__.py:235
[14:38:44] INFO     Running pacmap-3 on fashion                                      __init__.py:235
[14:39:36] INFO     Running pacmap-3 on ng20pacmap                                   __init__.py:235
[14:39:46] INFO     Running pacmap-3 on macosko2015                                  __init__.py:235
[14:40:32] INFO     Running pacmap-3 on tasic2018                                    __init__.py:235
[14:40:56] INFO     Running pacmap-3 on lamanno2020                                  __init__.py:235
[14:41:03] INFO     Running pacmap-3 on kazer                                        __init__.py:235
[14:41:29] INFO     Running pacmap-3 on stuart                                       __init__.py:235
[14:41:44] INFO     Running pacmap-3 on kang                                         __init__.py:235
[14:41:52] INFO     Running pacmap-4 on curve2d                                      __init__.py:235
[14:41:56] INFO     Running pacmap-4 on mammoth                                      __init__.py:235
[14:42:19] INFO     Running pacmap-4 on scurvehole                                   __init__.py:235
[14:42:25] INFO     Running pacmap-4 on isoswiss                                     __init__.py:235
[14:42:35] INFO     Running pacmap-4 on synthetic-hierarchical                       __init__.py:235
[14:43:02] INFO     Running pacmap-4 on spheres                                      __init__.py:235
[14:43:10] INFO     Running pacmap-4 on coil20                                       __init__.py:235
[14:43:18] INFO     Running pacmap-4 on coil100                                      __init__.py:235
[14:44:09] INFO     Running pacmap-4 on mnist                                        __init__.py:235
[14:45:03] INFO     Running pacmap-4 on fashion                                      __init__.py:235
[14:45:55] INFO     Running pacmap-4 on ng20pacmap                                   __init__.py:235
[14:46:05] INFO     Running pacmap-4 on macosko2015                                  __init__.py:235
[14:46:53] INFO     Running pacmap-4 on tasic2018                                    __init__.py:235
[14:47:19] INFO     Running pacmap-4 on lamanno2020                                  __init__.py:235
[14:47:26] INFO     Running pacmap-4 on kazer                                        __init__.py:235
[14:47:52] INFO     Running pacmap-4 on stuart                                       __init__.py:235
[14:48:06] INFO     Running pacmap-4 on kang                                         __init__.py:235
Code
experiment.plot()

In general the results are quite stable. There is more variability in datasets where there are lots of small clusters e.g. coil20, coil100 and the transcriptomics datasets and in particular tasic2018. Those three datasets all have disconnected components at the default number of neighbors used in PaCMAP (10) so they are much more likely to have clusters which are not well anchored in a global context.

So even though in most cases the results are very similar, if you are comparing PaCMAP results with another embedding method (or examining the effect of different parameters), it is a good idea to run it multiple times or to account for one or two clusters moving around as not being significant.

UMAP Comparison

Let’s compare the PaCMAP to UMAP – a big selling point of PaCMAP is its improved consistency of output over UMAP, so I would expect to see clusters moving about more in the UMAP case.

Code
umap_experiment = Experiment(name="umap-repeats")
for i in range(1, 5):
    umap_experiment.add_method(
        "umap",
        name=f"umap-{i}",
    )
umap_experiment.add_datasets(datasets)
umap_experiment.run()
umap_experiment.plot()
[13:53:57] INFO     Experiment umap-repeats writing to                               __init__.py:169
                    /home/james/rdev/datasets/experiments/umap-repeats                              
[13:54:02] INFO     Running umap-1 on curve2d                                        __init__.py:235
[13:54:08] INFO     Running umap-1 on mammoth                                        __init__.py:235
[13:56:02] INFO     Running umap-1 on scurvehole                                     __init__.py:235
[13:56:05] INFO     Running umap-1 on isoswiss                                       __init__.py:235
[13:56:13] INFO     Running umap-1 on synthetic-hierarchical                         __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[13:56:21] INFO     Running umap-1 on spheres                                        __init__.py:235
[13:56:24] INFO     Running umap-1 on coil20                                         __init__.py:235
[13:56:26] INFO     Running umap-1 on coil100                                        __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[13:56:43] INFO     Running umap-1 on mnist                                          __init__.py:235
[13:57:02] INFO     Running umap-1 on fashion                                        __init__.py:235
[13:57:29] INFO     Running umap-1 on ng20pacmap                                     __init__.py:235
[13:57:33] INFO     Running umap-1 on macosko2015                                    __init__.py:235
[13:57:49] INFO     Running umap-1 on tasic2018                                      __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[13:58:06] INFO     Running umap-1 on lamanno2020                                    __init__.py:235
[13:58:08] INFO     Running umap-1 on kazer                                          __init__.py:235
[13:58:20] INFO     Running umap-1 on stuart                                         __init__.py:235
[13:58:29] INFO     Running umap-1 on kang                                           __init__.py:235
[13:58:31] INFO     Running umap-2 on curve2d                                        __init__.py:235
[13:58:32] INFO     Running umap-2 on mammoth                                        __init__.py:235
[14:00:55] INFO     Running umap-2 on scurvehole                                     __init__.py:235
[14:00:59] INFO     Running umap-2 on isoswiss                                       __init__.py:235
[14:01:13] INFO     Running umap-2 on synthetic-hierarchical                         __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[14:01:21] INFO     Running umap-2 on spheres                                        __init__.py:235
[14:01:24] INFO     Running umap-2 on coil20                                         __init__.py:235
[14:01:26] INFO     Running umap-2 on coil100                                        __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[14:01:44] INFO     Running umap-2 on mnist                                          __init__.py:235
[14:02:03] INFO     Running umap-2 on fashion                                        __init__.py:235
[14:02:32] INFO     Running umap-2 on ng20pacmap                                     __init__.py:235
[14:02:36] INFO     Running umap-2 on macosko2015                                    __init__.py:235
[14:02:50] INFO     Running umap-2 on tasic2018                                      __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[14:03:09] INFO     Running umap-2 on lamanno2020                                    __init__.py:235
[14:03:11] INFO     Running umap-2 on kazer                                          __init__.py:235
[14:03:23] INFO     Running umap-2 on stuart                                         __init__.py:235
[14:03:31] INFO     Running umap-2 on kang                                           __init__.py:235
[14:03:34] INFO     Running umap-3 on curve2d                                        __init__.py:235
[14:03:35] INFO     Running umap-3 on mammoth                                        __init__.py:235
[14:05:26] INFO     Running umap-3 on scurvehole                                     __init__.py:235
[14:05:31] INFO     Running umap-3 on isoswiss                                       __init__.py:235
[14:05:41] INFO     Running umap-3 on synthetic-hierarchical                         __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[14:05:49] INFO     Running umap-3 on spheres                                        __init__.py:235
[14:05:52] INFO     Running umap-3 on coil20                                         __init__.py:235
[14:05:54] INFO     Running umap-3 on coil100                                        __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[14:06:10] INFO     Running umap-3 on mnist                                          __init__.py:235
[14:06:29] INFO     Running umap-3 on fashion                                        __init__.py:235
[14:06:55] INFO     Running umap-3 on ng20pacmap                                     __init__.py:235
[14:06:59] INFO     Running umap-3 on macosko2015                                    __init__.py:235
[14:07:13] INFO     Running umap-3 on tasic2018                                      __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[14:07:30] INFO     Running umap-3 on lamanno2020                                    __init__.py:235
[14:07:31] INFO     Running umap-3 on kazer                                          __init__.py:235
[14:07:44] INFO     Running umap-3 on stuart                                         __init__.py:235
[14:07:53] INFO     Running umap-3 on kang                                           __init__.py:235
[14:07:56] INFO     Running umap-4 on curve2d                                        __init__.py:235
[14:07:57] INFO     Running umap-4 on mammoth                                        __init__.py:235
[14:09:57] INFO     Running umap-4 on scurvehole                                     __init__.py:235
[14:10:03] INFO     Running umap-4 on isoswiss                                       __init__.py:235
[14:10:20] INFO     Running umap-4 on synthetic-hierarchical                         __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[14:10:29] INFO     Running umap-4 on spheres                                        __init__.py:235
[14:10:32] INFO     Running umap-4 on coil20                                         __init__.py:235
[14:10:34] INFO     Running umap-4 on coil100                                        __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[14:10:52] INFO     Running umap-4 on mnist                                          __init__.py:235
[14:11:14] INFO     Running umap-4 on fashion                                        __init__.py:235
[14:11:43] INFO     Running umap-4 on ng20pacmap                                     __init__.py:235
[14:11:48] INFO     Running umap-4 on macosko2015                                    __init__.py:235
[14:12:02] INFO     Running umap-4 on tasic2018                                      __init__.py:235
/home/james/dev/drnb-plugin/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:329: UserWarning: Graph is not fully connected, spectral embedding may not work as expected.
  warnings.warn(
[14:12:22] INFO     Running umap-4 on lamanno2020                                    __init__.py:235
[14:12:24] INFO     Running umap-4 on kazer                                          __init__.py:235
[14:12:37] INFO     Running umap-4 on stuart                                         __init__.py:235
[14:12:44] INFO     Running umap-4 on kang                                           __init__.py:235

UMAP’s tendency to break up low-dimensional data structures is apparent with mammoth and scurvehole although the spectral initialization UMAP uses is better in the latter case (and isoswiss) in terms of global layout. On “real” higher-dimensional datasets we don’t really see that behavior and most of the difference between the performance of UMAP and PaCMAP is down to the PCA-initialization and (in particular) the pre-processing that PaCMAP does down to 100D via PCA.

Results are less consistent than PaCMAP however. And in the kazer dataset, the third replicate has split a small dendritic cell cluster (it’s the dark red one) into two. This was a behavior that was noted by the PaCMAP authors.

Code
experiment.versions()
{'pacmap-1': {'package': 'pacmap', 'version': '0.8.0'},
 'pacmap-2': {'package': 'pacmap', 'version': '0.8.0'},
 'pacmap-3': {'package': 'pacmap', 'version': '0.8.0'},
 'pacmap-4': {'package': 'pacmap', 'version': '0.8.0'}}
Code
umap_experiment.versions()
{'umap-1': {'package': 'umap-learn', 'version': '0.5.9.post2'},
 'umap-2': {'package': 'umap-learn', 'version': '0.5.9.post2'},
 'umap-3': {'package': 'umap-learn', 'version': '0.5.9.post2'},
 'umap-4': {'package': 'umap-learn', 'version': '0.5.9.post2'}}