Code
import numpy as np
import drnb.embed.pipeline as pl
from drnb.experiment import ExperimentI compared the consistency of repeating runs of PaCMAP versus UMAP in the PaCMAP repeats notebook. PaCMAP was more stable across multiple runs.
Can using a larger value for n_neighbors help? In this experiment I look at running UMAP three times consecutively, going from 150 to 50 to 15 neighbors. I have chosen 150 and 50 as the larger values fairly arbitrarily. More neighbors means more edges means a longer run time, and setting n_neighbors too large would be counterproductive for a method that wants to retain manifold structure. When using t-SNE, a perplexity of 50 is a not unreasonable value, and that usually involves finding the 150 nearest neighbors.
experiment = Experiment(name="umap-annealed-neighbors")
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}),
pl.embedder("umap", params={"random_state": seed, "n_neighbors": 50}),
pl.embedder("umap", params={"random_state": seed, "n_neighbors": 15}),
],
name=f"umap-run-{i}",
)
experiment.add_datasets(
[
"curve2d",
"mammoth",
"scurvehole",
"isoswiss",
"hierarchical",
"spheres",
"coil20",
"coil100",
"mnist",
"fashion",
"ng20pacmap",
"macosko2015",
"tasic2018",
"lamanno2020",
"kazer",
"stuart",
"kang",
]
)
experiment.run()[15:11:09] INFO Running umap-run-1 on curve2d experiment.py:67
[15:11:18] INFO Running umap-run-1 on mammoth experiment.py:67
[15:13:57] INFO Running umap-run-1 on scurvehole experiment.py:67
[15:14:44] INFO Running umap-run-1 on isoswiss experiment.py:67
[15:15:31] INFO Running umap-run-1 on hierarchical experiment.py:67
/home/james/dev/drnb3/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:328: UserWarning:
Graph is not fully connected, spectral embedding may not work as expected.
[15:18:37] INFO Running umap-run-1 on spheres experiment.py:67
[15:19:38] INFO Running umap-run-1 on coil20 experiment.py:67
[15:19:48] INFO Running umap-run-1 on coil100 experiment.py:67
[15:20:50] INFO Running umap-run-1 on mnist experiment.py:67
[15:24:17] INFO Running umap-run-1 on fashion experiment.py:67
[15:27:56] INFO Running umap-run-1 on ng20pacmap experiment.py:67
[15:28:46] INFO Running umap-run-1 on macosko2015 experiment.py:67
[15:31:11] INFO Running umap-run-1 on tasic2018 experiment.py:67
[15:32:25] INFO Running umap-run-1 on lamanno2020 experiment.py:67
[15:32:48] INFO Running umap-run-1 on kazer experiment.py:67
[15:35:45] INFO Running umap-run-1 on stuart experiment.py:67
[15:37:12] INFO Running umap-run-1 on kang experiment.py:67
[15:37:49] INFO Running umap-run-2 on curve2d experiment.py:67
[15:37:55] INFO Running umap-run-2 on mammoth experiment.py:67
[15:40:36] INFO Running umap-run-2 on scurvehole experiment.py:67
[15:41:24] INFO Running umap-run-2 on isoswiss experiment.py:67
[15:42:11] INFO Running umap-run-2 on hierarchical experiment.py:67
/home/james/dev/drnb3/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:328: UserWarning:
Graph is not fully connected, spectral embedding may not work as expected.
[15:45:11] INFO Running umap-run-2 on spheres experiment.py:67
[15:46:11] INFO Running umap-run-2 on coil20 experiment.py:67
[15:46:20] INFO Running umap-run-2 on coil100 experiment.py:67
[15:47:18] INFO Running umap-run-2 on mnist experiment.py:67
[15:50:37] INFO Running umap-run-2 on fashion experiment.py:67
[15:54:10] INFO Running umap-run-2 on ng20pacmap experiment.py:67
[15:55:00] INFO Running umap-run-2 on macosko2015 experiment.py:67
[15:57:21] INFO Running umap-run-2 on tasic2018 experiment.py:67
[15:58:33] INFO Running umap-run-2 on lamanno2020 experiment.py:67
[15:58:57] INFO Running umap-run-2 on kazer experiment.py:67
[16:01:50] INFO Running umap-run-2 on stuart experiment.py:67
[16:03:16] INFO Running umap-run-2 on kang experiment.py:67
[16:03:52] INFO Running umap-run-3 on curve2d experiment.py:67
[16:03:59] INFO Running umap-run-3 on mammoth experiment.py:67
[16:06:37] INFO Running umap-run-3 on scurvehole experiment.py:67
[16:07:24] INFO Running umap-run-3 on isoswiss experiment.py:67
[16:08:10] INFO Running umap-run-3 on hierarchical experiment.py:67
/home/james/dev/drnb3/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:328: UserWarning:
Graph is not fully connected, spectral embedding may not work as expected.
[16:11:09] INFO Running umap-run-3 on spheres experiment.py:67
[16:12:09] INFO Running umap-run-3 on coil20 experiment.py:67
[16:12:19] INFO Running umap-run-3 on coil100 experiment.py:67
[16:13:21] INFO Running umap-run-3 on mnist experiment.py:67
[16:16:49] INFO Running umap-run-3 on fashion experiment.py:67
[16:20:23] INFO Running umap-run-3 on ng20pacmap experiment.py:67
[16:21:12] INFO Running umap-run-3 on macosko2015 experiment.py:67
[16:23:38] INFO Running umap-run-3 on tasic2018 experiment.py:67
[16:24:50] INFO Running umap-run-3 on lamanno2020 experiment.py:67
[16:25:14] INFO Running umap-run-3 on kazer experiment.py:67
[16:28:15] INFO Running umap-run-3 on stuart experiment.py:67
[16:29:44] INFO Running umap-run-3 on kang experiment.py:67
[16:30:23] INFO Running umap-run-4 on curve2d experiment.py:67
[16:30:29] INFO Running umap-run-4 on mammoth experiment.py:67
[16:33:07] INFO Running umap-run-4 on scurvehole experiment.py:67
[16:33:55] INFO Running umap-run-4 on isoswiss experiment.py:67
[16:34:40] INFO Running umap-run-4 on hierarchical experiment.py:67
/home/james/dev/drnb3/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:328: UserWarning:
Graph is not fully connected, spectral embedding may not work as expected.
[16:37:40] INFO Running umap-run-4 on spheres experiment.py:67
[16:38:40] INFO Running umap-run-4 on coil20 experiment.py:67
[16:38:49] INFO Running umap-run-4 on coil100 experiment.py:67
[16:39:51] INFO Running umap-run-4 on mnist experiment.py:67
[16:43:21] INFO Running umap-run-4 on fashion experiment.py:67
[16:47:02] INFO Running umap-run-4 on ng20pacmap experiment.py:67
[16:47:51] INFO Running umap-run-4 on macosko2015 experiment.py:67
[16:50:13] INFO Running umap-run-4 on tasic2018 experiment.py:67
[16:51:31] INFO Running umap-run-4 on lamanno2020 experiment.py:67
[16:51:54] INFO Running umap-run-4 on kazer experiment.py:67
[16:54:51] INFO Running umap-run-4 on stuart experiment.py:67
[16:56:18] INFO Running umap-run-4 on kang experiment.py:67
[16:56:55] INFO Running umap-run-5 on curve2d experiment.py:67
[16:57:02] INFO Running umap-run-5 on mammoth experiment.py:67
[16:59:42] INFO Running umap-run-5 on scurvehole experiment.py:67
[17:00:31] INFO Running umap-run-5 on isoswiss experiment.py:67
[17:01:18] INFO Running umap-run-5 on hierarchical experiment.py:67
/home/james/dev/drnb3/.venv/lib/python3.12/site-packages/sklearn/manifold/_spectral_embedding.py:328: UserWarning:
Graph is not fully connected, spectral embedding may not work as expected.
[17:04:22] INFO Running umap-run-5 on spheres experiment.py:67
[17:05:23] INFO Running umap-run-5 on coil20 experiment.py:67
[17:05:32] INFO Running umap-run-5 on coil100 experiment.py:67
[17:06:30] INFO Running umap-run-5 on mnist experiment.py:67
[17:09:51] INFO Running umap-run-5 on fashion experiment.py:67
[17:13:20] INFO Running umap-run-5 on ng20pacmap experiment.py:67
[17:14:09] INFO Running umap-run-5 on macosko2015 experiment.py:67
[17:16:33] INFO Running umap-run-5 on tasic2018 experiment.py:67
[17:17:46] INFO Running umap-run-5 on lamanno2020 experiment.py:67
[17:18:09] INFO Running umap-run-5 on kazer experiment.py:67
[17:21:03] INFO Running umap-run-5 on stuart experiment.py:67
[17:22:29] INFO Running umap-run-5 on kang experiment.py:67
Differences are not stark if you compare with the default UMAP results from the PaCMAP notebook. In some cases, e.g. mnist and fashion there is a bit less variability. mammoth definitely benefits from a run at a higher n_neighbors. In the kazer run, here UMAP never breaks up the small red cluster (the dendritic cell types) that is usually at the center-bottom of the plot. That’s an improvement over the results in the PaCMAP notebook, where one of the four runs there split the cluster in two, an effect also observed by the PaCMAP authors when they compared UMAP to PaCMAP on that dataset. So I’d call this a win for neighbor annealing, although you will obviously pay the price in run time for finding a larger number of neighbors and the longer optimization phases.
In part 2, I look to see if gentler relative forces in the update of each pair, has an effect on reproducibility.