-
Notifications
You must be signed in to change notification settings - Fork 856
Open
Description
Dear Leland McInnes,
trying to use the inverse_transform() method of umap-learn, following the tutorial on Inverse transforms, when calling inv_transformed_points = mapper.inverse_transform(test_pts), this exception is hit:
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
Cell In[5], line 1
----> 1 inv_transformed_points = mapper.inverse_transform(test_pts)
File /usr/lib/python3/dist-packages/umap/umap_.py:3332, in UMAP.inverse_transform(self, X)
3329 tail = graph.col
3330 weight = graph.data
-> 3332 inv_transformed_points = optimize_layout_inverse(
3333 inv_transformed_points,
3334 self._raw_data,
3335 head,
3336 tail,
3337 weight,
3338 self._sigmas,
3339 self._rhos,
3340 n_epochs,
3341 graph.shape[1],
3342 epochs_per_sample,
3343 self._a,
3344 self._b,
3345 rng_state,
3346 self.repulsion_strength,
3347 self._initial_alpha / 4.0,
3348 self.negative_sample_rate,
3349 self._inverse_distance_func,
3350 tuple(self._metric_kwds.values()),
3351 verbose=self.verbose,
3352 tqdm_kwds=self.tqdm_kwds,
3353 )
3355 return inv_transformed_points
File /usr/lib/python3/dist-packages/umap/layouts.py:850, in optimize_layout_inverse(head_embedding, tail_embedding, head, tail, weight, sigmas, rhos, n_epochs, n_vertices, epochs_per_sample, a, b, rng_state, gamma, initial_alpha, negative_sample_rate, output_metric, output_metric_kwds, verbose, tqdm_kwds, move_other)
847 tqdm_kwds["disable"] = not verbose
849 for n in tqdm(range(n_epochs), **tqdm_kwds):
--> 850 optimize_fn(
851 epochs_per_sample,
852 epoch_of_next_sample,
853 head,
854 tail,
855 head_embedding,
856 tail_embedding,
857 output_metric,
858 output_metric_kwds,
859 weight,
860 sigmas,
861 dim,
862 alpha,
863 move_other,
864 n,
865 epoch_of_next_negative_sample,
866 epochs_per_negative_sample,
867 rng_state,
868 n_vertices,
869 rhos,
870 gamma,
871 )
872 alpha = initial_alpha * (1.0 - (float(n) / float(n_epochs)))
874 return head_embedding
ZeroDivisionError: division by zero
A minimal Pythone code to reproduce the crash is:
import numpy as np
import sklearn.datasets
import umap
data, labels = sklearn.datasets.fetch_openml('mnist_784', version=1, return_X_y=True)
mapper = umap.UMAP(random_state=42).fit(data)
corners = np.array([
[-5, -10], # 1
[-7, 6], # 7
[2, -8], # 2
[12, 4], # 0
])
test_pts = np.array([
(corners[0]*(1-x) + corners[1]*x)*(1-y) +
(corners[2]*(1-x) + corners[3]*x)*y
for y in np.linspace(0, 1, 10)
for x in np.linspace(0, 1, 10)
])
inv_transformed_points = mapper.inverse_transform(test_pts)
Some informations regarding the test system, a Debian testing installation:
Python implementation: CPython
Python version: 3.13.9
IPython version: 8.35.0
Jupyter: 8.6.3
numba: 0.61.2
numpy: 2.3.4
pynndescent: 0.5.13
scipy: 1.16.3
sklearn: 1.7.2
tqdm: 4.67.1
umap: 0.5.9.post2
Any idea why it crashes?
Regards,
Jörg.
Metadata
Metadata
Assignees
Labels
No labels