2
$\begingroup$

I have a dataset, where the features are comprised of points arranged in a regular grid on a simplex. Each of these points are defined as follows: A point $\mathbf{x}$ on the simplex can be represented as a vector in $\mathbb{R}^n$ such that:

\begin{equation} \mathbf{x} = \left( x_1, x_2, \ldots, x_n \right) \end{equation}

subject to the following conditions:

\begin{align*} \sum_{i=1}^{n} x_i &= 1, \quad \text{(Sum Constraint)} \\ x_i &\geq 0, \quad \text{for } i = 1, 2, \ldots, n. \quad \text{(Non-negativity Constraint)} \end{align*}

I came across a UMAP projections of such a space in the literature and I'm attempting to replicate those results. Unfortunately, there isn't much information available on the specific parameters used to create those plots. As a result, my UMAP projections seem to be somewhat distorted. I'm seeking ways to improve and accurately recreate the desired visualization.

Changing the number of neighbors or the seed does not significantly change the overall result.

The reference plot is:

Reference plot of a 6d space

My plot is however:

My plot

The corresponding code is:

import numpy as np
from matplotlib import pyplot as plt 
from scipy.special import comb
from umap import UMAP


def simplex_grid(m, n):
    L = comb(n + m - 1, m - 1, exact=True)
    out = np.empty((L, m), dtype=int)
    x = np.zeros(m, dtype=int)

    x[m - 1] = n
    out[0, :] = x[:]

    h = m

    for i in range(1, L):
        h -= 1

        val = x[h]
        x[h] = 0
        x[m - 1] = val - 1
        x[h - 1] += 1

        out[i, :] = x[:]

        if val != 1:
            h = m

    return out


grid = np.array(simplex_grid(6, 14)) / 14

reducer = UMAP(random_state=10, n_neighbors=80, target_metric="l2",
               min_dist=0.05)

trans_grid = reducer.fit_transform(grid)

fig = plt.scatter(trans_grid[:, 0], trans_grid[:, 1], c=grid[:, 0])

ax = plt.gca()
ax.set_aspect('equal', 'box')
plt.axis('off')
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)

plt.show()
$\endgroup$

1 Answer 1

2
$\begingroup$

UMAP is a stochastic algorithm. In order to reproduce their results, it's needed that they used the random_state and you need to set the same value as they did.

Given that

Unfortunately, there isn't much information available on the specific parameters used to create those plots

You don't have enough information to reproduce their results.

$\endgroup$
1
  • $\begingroup$ I know that UMAP exhibits stochastic behavior. However, altering the random state has minimal impact, as the overall shape remains remarkably consistent across different run with different seed. I want to get the nice hexagonal-shaped plot. $\endgroup$
    – pmu2022
    May 11, 2023 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.