drnb notebooks
  • Notebooks
  • GitHub
  1. Articles
  2. UMAP with Annealed Neighbors. 3: PCA Initialization
  • 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

  • Part 3: PCA initialization
  1. Articles
  2. UMAP with Annealed Neighbors. 3: PCA Initialization

Annealing neighbors

  • Show All Code
  • Hide All Code
Code
import numpy as np

import drnb.embed.pipeline as pl
from drnb.experiment import Experiment

See part 1 for an introduction and default UMAP results and part 2 for a comparison with t-UMAP with spectral initialization.

Part 3: PCA initialization

Another difference between PaCMAP and UMAP is the type of initialization: PaCMAP uses PCA and UMAP uses spectral initialization (something close to Laplacian Eigenmaps). Both methods use randomized approaches to truncated SVD which implies the possibility of an effect of the random seed on the approximation. If I had to guess I would say that PCA gives less variable output because the spectral initialization puts a lot of emphasis on reproducing neighbors without repulsion so although the layout may be amenable to clustering it is visually unappealing and leads to long “arms” of points extending from a very compact core. Although you can see this kind of structure in PCA it’s not as pronounced.

But I don’t need to guess, as we can initialize UMAP from PCA as well as spectral methods. We will use the a=1, b=1 t-UMAP paramters as we did in part 2.

Code
experiment = Experiment(name="tumap-annealed-neighbors-pca")

seeds = np.random.SeedSequence(42).generate_state(5)

for i, seed in enumerate(seeds, 1):
    experiment.add_method(
        [
            pl.embedder(
                "umap",
                params={
                    "random_state": seed,
                    "n_neighbors": 150,
                    "a": 1,
                    "b": 1,
                    "init": "pca",
                },
            ),
            pl.embedder(
                "umap", params={"random_state": seed, "n_neighbors": 50, "a": 1, "b": 1}
            ),
            pl.embedder(
                "umap", params={"random_state": seed, "n_neighbors": 15, "a": 1, "b": 1}
            ),
        ],
        name=f"tumap-run-{i}",
    )

experiment.add_datasets(
    [
        "curve2d",
        "mammoth",
        "scurvehole",
        "isoswiss",
        "hierarchical",
        "spheres",
        "coil20",
        "coil100",
        "mnist",
        "fashion",
        "ng20pacmap",
        "macosko2015",
        "tasic2018",
        "lamanno2020",
        "kazer",
        "stuart",
        "kang",
    ]
)
experiment.run()
[22:29:31] INFO     Running tumap-run-1 on curve2d                                  experiment.py:67
[22:29:35] INFO     Running tumap-run-1 on mammoth                                  experiment.py:67
[22:30:50] INFO     Running tumap-run-1 on scurvehole                               experiment.py:67
[22:31:19] INFO     Running tumap-run-1 on isoswiss                                 experiment.py:67
[22:31:44] INFO     Running tumap-run-1 on hierarchical                             experiment.py:67
[22:33:35] INFO     Running tumap-run-1 on spheres                                  experiment.py:67
[22:34:13] INFO     Running tumap-run-1 on coil20                                   experiment.py:67
[22:34:20] INFO     Running tumap-run-1 on coil100                                  experiment.py:67
[22:35:12] INFO     Running tumap-run-1 on mnist                                    experiment.py:67
[22:37:12] INFO     Running tumap-run-1 on fashion                                  experiment.py:67
[22:39:18] INFO     Running tumap-run-1 on ng20pacmap                               experiment.py:67
[22:39:48] INFO     Running tumap-run-1 on macosko2015                              experiment.py:67
[22:41:23] INFO     Running tumap-run-1 on tasic2018                                experiment.py:67
[22:42:07] INFO     Running tumap-run-1 on lamanno2020                              experiment.py:67
[22:42:22] INFO     Running tumap-run-1 on kazer                                    experiment.py:67
[22:44:08] INFO     Running tumap-run-1 on stuart                                   experiment.py:67
[22:45:03] INFO     Running tumap-run-1 on kang                                     experiment.py:67
[22:45:26] INFO     Running tumap-run-2 on curve2d                                  experiment.py:67
[22:45:30] INFO     Running tumap-run-2 on mammoth                                  experiment.py:67
[22:46:44] INFO     Running tumap-run-2 on scurvehole                               experiment.py:67
[22:47:12] INFO     Running tumap-run-2 on isoswiss                                 experiment.py:67
[22:47:38] INFO     Running tumap-run-2 on hierarchical                             experiment.py:67
[22:49:26] INFO     Running tumap-run-2 on spheres                                  experiment.py:67
[22:50:03] INFO     Running tumap-run-2 on coil20                                   experiment.py:67
[22:50:10] INFO     Running tumap-run-2 on coil100                                  experiment.py:67
[22:51:02] INFO     Running tumap-run-2 on mnist                                    experiment.py:67
[22:53:01] INFO     Running tumap-run-2 on fashion                                  experiment.py:67
[22:55:05] INFO     Running tumap-run-2 on ng20pacmap                               experiment.py:67
[22:55:35] INFO     Running tumap-run-2 on macosko2015                              experiment.py:67
[22:57:05] INFO     Running tumap-run-2 on tasic2018                                experiment.py:67
[22:57:49] INFO     Running tumap-run-2 on lamanno2020                              experiment.py:67
[22:58:04] INFO     Running tumap-run-2 on kazer                                    experiment.py:67
[22:59:47] INFO     Running tumap-run-2 on stuart                                   experiment.py:67
[23:00:40] INFO     Running tumap-run-2 on kang                                     experiment.py:67
[23:01:03] INFO     Running tumap-run-3 on curve2d                                  experiment.py:67
[23:01:07] INFO     Running tumap-run-3 on mammoth                                  experiment.py:67
[23:02:18] INFO     Running tumap-run-3 on scurvehole                               experiment.py:67
[23:02:46] INFO     Running tumap-run-3 on isoswiss                                 experiment.py:67
[23:03:11] INFO     Running tumap-run-3 on hierarchical                             experiment.py:67
[23:04:58] INFO     Running tumap-run-3 on spheres                                  experiment.py:67
[23:05:35] INFO     Running tumap-run-3 on coil20                                   experiment.py:67
[23:05:43] INFO     Running tumap-run-3 on coil100                                  experiment.py:67
[23:06:37] INFO     Running tumap-run-3 on mnist                                    experiment.py:67
[23:08:53] INFO     Running tumap-run-3 on fashion                                  experiment.py:67
[23:11:05] INFO     Running tumap-run-3 on ng20pacmap                               experiment.py:67
[23:11:35] INFO     Running tumap-run-3 on macosko2015                              experiment.py:67
[23:13:05] INFO     Running tumap-run-3 on tasic2018                                experiment.py:67
[23:13:49] INFO     Running tumap-run-3 on lamanno2020                              experiment.py:67
[23:14:03] INFO     Running tumap-run-3 on kazer                                    experiment.py:67
[23:15:54] INFO     Running tumap-run-3 on stuart                                   experiment.py:67
[23:16:48] INFO     Running tumap-run-3 on kang                                     experiment.py:67
[23:17:10] INFO     Running tumap-run-4 on curve2d                                  experiment.py:67
[23:17:15] INFO     Running tumap-run-4 on mammoth                                  experiment.py:67
[23:18:27] INFO     Running tumap-run-4 on scurvehole                               experiment.py:67
[23:18:55] INFO     Running tumap-run-4 on isoswiss                                 experiment.py:67
[23:19:20] INFO     Running tumap-run-4 on hierarchical                             experiment.py:67
[23:21:07] INFO     Running tumap-run-4 on spheres                                  experiment.py:67
[23:21:44] INFO     Running tumap-run-4 on coil20                                   experiment.py:67
[23:21:51] INFO     Running tumap-run-4 on coil100                                  experiment.py:67
[23:22:43] INFO     Running tumap-run-4 on mnist                                    experiment.py:67
[23:24:44] INFO     Running tumap-run-4 on fashion                                  experiment.py:67
[23:26:52] INFO     Running tumap-run-4 on ng20pacmap                               experiment.py:67
[23:27:22] INFO     Running tumap-run-4 on macosko2015                              experiment.py:67
[23:28:54] INFO     Running tumap-run-4 on tasic2018                                experiment.py:67
[23:29:38] INFO     Running tumap-run-4 on lamanno2020                              experiment.py:67
[23:29:53] INFO     Running tumap-run-4 on kazer                                    experiment.py:67
[23:31:38] INFO     Running tumap-run-4 on stuart                                   experiment.py:67
[23:32:32] INFO     Running tumap-run-4 on kang                                     experiment.py:67
[23:32:54] INFO     Running tumap-run-5 on curve2d                                  experiment.py:67
[23:32:58] INFO     Running tumap-run-5 on mammoth                                  experiment.py:67
[23:34:10] INFO     Running tumap-run-5 on scurvehole                               experiment.py:67
[23:34:38] INFO     Running tumap-run-5 on isoswiss                                 experiment.py:67
[23:35:04] INFO     Running tumap-run-5 on hierarchical                             experiment.py:67
[23:36:59] INFO     Running tumap-run-5 on spheres                                  experiment.py:67
[23:37:36] INFO     Running tumap-run-5 on coil20                                   experiment.py:67
[23:37:43] INFO     Running tumap-run-5 on coil100                                  experiment.py:67
[23:38:34] INFO     Running tumap-run-5 on mnist                                    experiment.py:67
[23:40:38] INFO     Running tumap-run-5 on fashion                                  experiment.py:67
[23:42:43] INFO     Running tumap-run-5 on ng20pacmap                               experiment.py:67
[23:43:13] INFO     Running tumap-run-5 on macosko2015                              experiment.py:67
[23:44:54] INFO     Running tumap-run-5 on tasic2018                                experiment.py:67
[23:45:37] INFO     Running tumap-run-5 on lamanno2020                              experiment.py:67
[23:45:52] INFO     Running tumap-run-5 on kazer                                    experiment.py:67
[23:47:36] INFO     Running tumap-run-5 on stuart                                   experiment.py:67
[23:48:29] INFO     Running tumap-run-5 on kang                                     experiment.py:67
Code
experiment.plot()

It does seem possible that results are slightly more stable by initializing with PCA versus spectral methods. Low-dimensional manifolds (scurvehole and isoswiss) are not better off, but I’ve yet to see a convincing non-synthetic dataset where this mattered. On the other hand, mnist shows a bit more variability.