drnb notebooks
  • Notebooks
  • GitHub
  1. Articles
  2. Leopold: Lightweight Estimate of Preservation of Local Density
  • 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

  • Calculating the precision
  • Choosing \(\alpha\)
  • Other deviations from UMAP
  • MNIST
  • 2D clusters
  • s-curve-with-a-hole
  1. Articles
  2. Leopold: Lightweight Estimate of Preservation of Local Density

Leopold: Lightweight Estimate of Preservation of Local Density

  • Show All Code
  • Hide All Code
Code
import drnb.embed.pipeline as pl

I invented this method for uwot as an approximation to densMAP. The version here differs slightly in implementation to that in uwot but is similar in spirit: the nearest neighbor distances are used to estimate the local density at each point and a per-pair “precision” parameter, \(\beta\) is applied to the Cauchy kernel. I think that similar approach is used by annembed. No attempt is made to “match” high and low-dimensional densities in any kind of consistent scheme that would take account of the difference of distance vs volume in different intrinsic and embedded dimensions or anything like that. All I want to see is that if two clusters exist in the ambient dimension and one is more dense than the other, then in the embedded space the more dense cluster should be smaller than the larger cluster – or at least the more dense cluster is smaller than it would look with plain UMAP.

Additionally I add a degree-of-freedom parameter, \(\alpha\) to give rise to a heavy-tail kernel like that used by Kobak and co-workers with t-SNE.

The kernel is therefore:

\[ w_{ij} = 1/\left(1 + \frac{\beta_{ij}}{\alpha} d_{ij}^2\right)^\alpha \]

The gradients are:

\[ \frac{\partial{C_{\mathrm{leopold}}^+}}{\partial{\mathbf{y_i}}} = 2 \beta_{ij} w_{ij}^{1/\alpha}\left(\mathbf{y_i} - \mathbf{y_j}\right) = \frac{2 \beta_{ij}}{\left(1 + \frac{\beta}{\alpha} d_{ij}^2\right)}\left(\mathbf{y_i} - \mathbf{y_j}\right) \]

\[ \frac{\partial{C_{\mathrm{leopold}}^-}}{\partial{\mathbf{y_i}}} = \frac{-2 \beta_{ij} w_{ij}^{\left(\alpha + 1 \right) / \alpha}}{1 - w_{ij} + \varepsilon}\left(\mathbf{y_i} - \mathbf{y_j}\right) = \frac{-2 \beta_{ij} w_{ij}}{\left(1 + \frac{\beta}{\alpha} d_{ij}^2\right)\left(1 - w_{ij} + \varepsilon \right)}\left(\mathbf{y_i} - \mathbf{y_j}\right) \]

The second versions are probably a bit more efficient because they save on some power calculations. For the repulsive gradient, \(\varepsilon = 0.001\) and is there to prevent division by zero just like in UMAP.

Calculating the precision

This following bit seems like a lot of work but the idea is conceptually simple: use the nearest neighbor distances to get an idea of the local density around each point. Subsequent steps are numerical busywork: scale the densities so that they fit into a numerical range that won’t cause horrific under/overflow and other instabilities. Finally, allow a parameterization that smoothly goes from “ignore local density” to “strongly use local density”.

The precision calculated as follows:

  1. Calculate the average nearest neighbor distance for each point: \(r_i\)
  2. The initial precision is \(\beta_{i}^{\prime} = 1 / r_i\)
  3. The initial precisions are scaled (let’s call these ones \(\beta_{i}^{*}\)) be in the range \(\left[\sqrt{10^{-2}}, \sqrt{100}\right]\) (by basic range scaling). The square root is there so that multiplying \(\beta_i\) and \(\beta_j\) gives the harmonic mean and ranging betweeen \(10^{-2}\) and \(100\) was chosen arbitrarily to give something that seemed numerically stable.
  4. Finally the scaled precisions are scaled again to form a weighted average between \(\beta_i^{*}\) and having all \(\beta_i=1\): \(\beta_i = \left(1 - d\right) + d\beta_i^{*}\). The dens_scale parameter controls \(d\) in the implementation: dens_scale=0.0 is equivalent to all \(\beta_i=1\), i.e. like normal UMAP. dens_scale=1.0 uses the full range of \(\beta_{i}^{*}\). So you can control how much you want the local density to affect the results by setting dens_scale appropriately.

Choosing \(\alpha\)

The degree-of-freedom parameter, \(\alpha\) is global and has to be chosen manually. There’s no reason it couldn’t be point-wise like \(\beta\), I just haven’t thought of a good way to assign it yet (maybe there are some good ideas to take from SpaceMAP). The dof parameter controls it. Set dof=1.0 to get Cauchy-kernel-like behavior. Larger dof gives progressively more Gaussian-like behavior, but above dof=10.0 I can’t see much difference. Smaller values will give even more heavy-tailed behavior which tends to make any clusters smaller or break them up into smaller structures. Things start to breakdown with values smaller than dof=0.5.

Other deviations from UMAP

  • To make the implementation easier I don’t generate any high-dimensional affinities, so no perplexity-like calibration. Effectively all neighbor affinities are 1.
  • This also means no sampling scheme: every edge gets sampled in every epoch and gets the same number of repulsive interactions calculated.
  • The symmetrization step on the input affinities takes an unweighted adjacency matrix and carries out an ‘OR’ operation on it and its transpose: if i is a neighbor of j or j is a neighbor of i, then both (i, j) and (j, i) appear in the symmetrized matrix. This effectively converts the nearest neighbor graph to an undirected neighbor graph.
  • No asynchronous Hogwild!-style optimization: the gradients are accumulated in each epoch and then Adam is used as the optimizer, similar to what PaCMAP does. This is probably a bit less efficient, but a bit more stable.

MNIST

For the MNIST digits, most of the clusters have a pretty similar “density” if you measure by the UMAP or t-SNE-style calibration. The big exception is the 1 cluster, which is noticeably more dense than the others. This isn’t something I see reflected in most embeddings. densMAP does it. The annembed examples also show it. Weirdly, the trimap example makes the one cluster much bigger than the others, which I have never understood.

Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=1.0, dens_scale=0.0, n_neighbors=15),
    dataset="mnist",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.6123742857142856), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.3370356857776642, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.10097523809523808), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.17489057142857142), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.2691066666666666), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=1.0, dens_scale=0.5, n_neighbors=15),
    dataset="mnist",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.6340057142857142), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.43101945519447327, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.10433714285714288), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.17809914285714284), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.27240533333333333), info={'metric': 'euclidean', 'n_neighbors': 150})]

Phew, the 1 cluster got smaller. Does it also work with dof value closer to a Gaussian?

Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=10.0, dens_scale=0.0, n_neighbors=15),
    dataset="mnist",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.6377685714285716), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.41706809401512146, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.060458095238095234), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.11557085714285716), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.1921214285714286), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=10.0, dens_scale=0.5, n_neighbors=15),
    dataset="mnist",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.6684742857142858), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.5317366123199463, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.07184952380952382), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.13314542857142858), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.217518380952381), info={'metric': 'euclidean', 'n_neighbors': 150})]

This is still not a very nice looking result compared to the heavier-tailed version, but the 1 cluster is still able to be resized compared to the others.

And what about going the other way, with an even heavier tail?

Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=0.5, dens_scale=0.0, n_neighbors=15),
    dataset="mnist",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.597742857142857), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.291769415140152, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.12000761904761902), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.19487800000000002), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.2844551428571428), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=0.5, dens_scale=0.5, n_neighbors=15),
    dataset="mnist",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.6258885714285713), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.4063589870929718, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.12303142857142858), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.19807171428571432), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.28723314285714285), info={'metric': 'euclidean', 'n_neighbors': 150})]

Visually, the 1 cluster is smaller (compare to the 2 and the 8 cluster). However, for both the dof=0.5 cases, the clusters of digits are broken up. Starting the optimization with dof=1.0 can help. In addition the decay_alpha=False optimization argument is used for the initial stage which doesn’t anneal the learning rate. This usually results in fuzzier looking results but tends to give a more reliable optimization overall so as we follow up with an optimization that does reduce the learning rate over the course of the optimization it’s useful to get the most out of the initial stage of the optimization:

Code
pl.standard_eval(
    [
        pl.embedder(
            "leopold",
            params=dict(
                dof=1.0,
                dens_scale=0.0,
                n_neighbors=15,
                n_epochs=200,
                optargs=dict(decay_alpha=False),
            ),
        ),
        pl.embedder(
            "leopold",
            params=dict(
                dof=0.5,
                dens_scale=0.0,
                n_neighbors=15,
                n_epochs=300,
            ),
        ),
    ],
    dataset="mnist",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.6063514285714284), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.320115864276886, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.11744666666666666), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.19320028571428574), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.283571619047619), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    [
        pl.embedder(
            "leopold",
            params=dict(
                dof=1.0,
                dens_scale=0.0,
                n_neighbors=15,
                n_epochs=200,
                optargs=dict(decay_alpha=False),
            ),
        ),
        pl.embedder(
            "leopold",
            params=dict(
                dof=0.5,
                dens_scale=0.5,
                n_neighbors=15,
                n_epochs=300,
            ),
        ),
    ],
    dataset="mnist",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.6228228571428571), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.39443618059158325, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.12056190476190475), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.1961954285714286), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.2852488571428572), info={'metric': 'euclidean', 'n_neighbors': 150})]

These look better visually even if there isn’t a huge change in the metrics.

2D clusters

A synthetic 2D dataset consisting of two clusters embedded in some uniformly distributed noise, from a google colab notebook by Pavlin Poličar. Here is the actual ground truth:

Code
pl.standard_eval(
    method="pca",
    dataset="embdensity",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(1.0), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.9999998807907104, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.9999111111111112), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(1.0), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(1.0), info={'metric': 'euclidean', 'n_neighbors': 150})]

And here are some runs with leopold with and without density scaling and using the Cauchy versus a more Gaussian-like kernel. The Gaussian kernel should be a bit more appropriate here as a 2D dataset shouldn’t need a heavy-tailed kernel.

Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=1.0, dens_scale=0.0, n_neighbors=15),
    dataset="embdensity",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.8594666666666667), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.8455966114997864, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.8004000000000001), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.8100933333333332), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8126222222222222), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=1.0, dens_scale=0.2, n_neighbors=15),
    dataset="embdensity",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.912), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.9393623471260071, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.7984000000000001), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.8218399999999998), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8660222222222222), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=10.0, dens_scale=0.0, n_neighbors=15),
    dataset="embdensity",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.8717333333333332), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.861001193523407, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.7677333333333334), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.77972), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.7845377777777778), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=10.0, dens_scale=0.2, n_neighbors=15),
    dataset="embdensity",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.9287999999999998), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.9564359784126282, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.815288888888889), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.8470799999999999), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8773244444444445), info={'metric': 'euclidean', 'n_neighbors': 150})]

The dof=10.0 results seem to do better at avoiding tearing the more uniform grey points, but the blue cluster poking out of the side is odd. Maybe we can be more aggressive with dens_scale? Let’s use the full range of densities, which seems like it would be helpful here as we know the blue and red cluster have a much smaller density than the grey points:

Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=1.0, dens_scale=1.0, n_neighbors=15),
    dataset="embdensity",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.8932000000000001), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.9327138066291809, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.7573333333333333), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.7722266666666666), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8521911111111111), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=10.0, dens_scale=1.0, n_neighbors=15),
    dataset="embdensity",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.9305333333333333), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.965092122554779, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.7932444444444445), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.8189466666666667), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8917466666666666), info={'metric': 'euclidean', 'n_neighbors': 150})]

Again, the dof=10.0 result is slightly better and the blue cluster isn’t bulging out of the enclosing grey background points. In UMAP-like methods, where there is a “containment”-like relationship in the data, like we have here with the small clusters contained in the grey uniform points, increasing n_neighbors can also help capture longer-range changes in density. Admittedly, it’s not a very efficient way to do this and the biggest effect is usually with synthetic low-dimensional datasets like this one. Anyway, let’s see what happens with n_neighbors=50:

Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=1.0, dens_scale=0.0, n_neighbors=50),
    dataset="embdensity",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.8322666666666667), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.7781021595001221, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.721288888888889), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.8064933333333335), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8120266666666667), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=1.0, dens_scale=1.0, n_neighbors=50),
    dataset="embdensity",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.93), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.9757490158081055, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.7057777777777778), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.7893066666666668), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8533777777777778), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=10.0, dens_scale=0.0, n_neighbors=50),
    dataset="embdensity",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.9076000000000001), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.9229562282562256, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.7343999999999999), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.8075333333333334), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.821568888888889), info={'metric': 'euclidean', 'n_neighbors': 150})]
Code
pl.standard_eval(
    method="leopold",
    dataset="embdensity",
    params=dict(dof=10.0, dens_scale=1.0, n_neighbors=50),
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.9477333333333333), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.9805440902709961, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.7454666666666667), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.8219066666666668), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8906577777777778), info={'metric': 'euclidean', 'n_neighbors': 150})]

dof=1.0 results still tend to clump the grey points too much. Using dens_scale helps. But dof=10.0 is an improvement. Meanwhile the dens_scale=0.0 results for either value of dof seem to cause the clusters to form a ring-like shape. So dens_scale is certainly helpful there.

For this low-dimensional dataset, while being of less importance than setting dens_scale, manually setting a value of dof that is larger than the typical Cauchy kernel seems like it can be helpful.

s-curve-with-a-hole

This is a swiss roll with a hole in, used in evaluating PaCMAP and SpaceMAP. UMAP has a tendency to rip the manifold, so I expect dof=1.0 to also do so:

Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=1.0, dens_scale=0.0, n_neighbors=70),
    dataset="scurvehole",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.8280273540241978), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.8388955593109131, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.7266842012975627), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.8002819568648081), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8456468525337542), info={'metric': 'euclidean', 'n_neighbors': 150})]

Does dens_scale=0.2 help:

Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=1.0, dens_scale=0.2, n_neighbors=70),
    dataset="scurvehole",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.8535086796422936), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.8676684498786926, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.73176223040505), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.7975654918463967), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8476927932667017), info={'metric': 'euclidean', 'n_neighbors': 150})]

A tiny bit. Hopefully using a less heavy-tailed kernel improves matters:

Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=10.0, dens_scale=0.0, n_neighbors=70),
    dataset="scurvehole",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.8473645449763283), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.847743570804596, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.7648044888655094), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.8354802735402419), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.8833848851481675), info={'metric': 'euclidean', 'n_neighbors': 150})]

The manifold is less ripped and twisted but not perfect. Now to see if adding some density info helps:

Code
pl.standard_eval(
    method="leopold",
    params=dict(dof=10.0, dens_scale=0.2, n_neighbors=70),
    dataset="scurvehole",
)

[EvalResult(eval_type='RTE', label='rte-5-euclidean', value=np.float64(0.8719621251972646), info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='RPC', label='rpc-5-euclidean', value=0.8728796243667603, info={'metric': 'euclidean', 'ntpp': 5}),
 EvalResult(eval_type='NNP', label='nnp-15-noself-euclidean', value=np.float64(0.8008627038400843), info={'metric': 'euclidean', 'n_neighbors': 15}),
 EvalResult(eval_type='NNP', label='nnp-50-noself-euclidean', value=np.float64(0.8581315097317201), info={'metric': 'euclidean', 'n_neighbors': 50}),
 EvalResult(eval_type='NNP', label='nnp-150-noself-euclidean', value=np.float64(0.9111422058565666), info={'metric': 'euclidean', 'n_neighbors': 150})]

The dof=10.0, dens_scale=0.2 result definitely looks the best.