umap icon indicating copy to clipboard operation
umap copied to clipboard

RuntimeWarning: divide by zero encountered in power | return 1.0 / (1.0 + a * x ** (2 * b))

Open nathanielbd opened this issue 5 years ago • 1 comments

This is a duplicate of #22 opened by @fedden. It was apparently resolved by passing correct parameters, but no specific details are mentioned.

Some things I am adding upon which were unresolved in that issue:

Expanded stack trace

/project/csbio/envs_dirs/viz/lib/python3.6/site-packages/umap/umap_.py:1052: RuntimeWarning: divide by zero encountered in power
  return 1.0 / (1.0 + a * x ** (2 * b))
Traceback (most recent call last):
  File "pipeline.py", line 271, in <module>
    coords, nodes = umap(new_gi_df, args, out_dir)
  File "pipeline.py", line 141, in umap
    embedding = reducer.fit_transform(gi_df.values)
  File "/project/csbio/envs_dirs/viz/lib/python3.6/site-packages/umap/umap_.py", line 1598, in fit_transform
    self.fit(X, y)
  File "/project/csbio/envs_dirs/viz/lib/python3.6/site-packages/umap/umap_.py", line 1429, in fit
    self.verbose,
  File "/project/csbio/envs_dirs/viz/lib/python3.6/site-packages/umap/umap_.py", line 281, in nearest_neighbors
    verbose=verbose,
  File "/project/csbio/envs_dirs/viz/lib/python3.6/site-packages/numba/core/dispatcher.py", line 401, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/project/csbio/envs_dirs/viz/lib/python3.6/site-packages/numba/core/dispatcher.py", line 344, in error_rewrite
    reraise(type(e), e, None)
  File "/project/csbio/envs_dirs/viz/lib/python3.6/site-packages/numba/core/utils.py", line 80, in reraise
    raise value.with_traceback(tb)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<built-in function empty>) with argument(s) of type(s): (float64, dtype=class(int64))
 * parameterized
In definition 0:
    All templates rejected with literals.
In definition 1:
    All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<built-in function empty>)
[2] During: typing of call at /project/csbio/envs_dirs/viz/lib/python3.6/site-packages/umap/utils.py (94)


File "../../../envs_dirs/viz/lib/python3.6/site-packages/umap/utils.py", line 94:
def rejection_sample(n_samples, pool_size, rng_state):
    <source elided>
    """
    result = np.empty(n_samples, dtype=np.int64)
    ^

[1] During: resolving callee type: type(CPUDispatcher(<function rejection_sample at 0x7f51f9e38950>))
[2] During: typing of call at /project/csbio/envs_dirs/viz/lib/python3.6/site-packages/umap/nndescent.py (63)

[3] During: resolving callee type: type(CPUDispatcher(<function rejection_sample at 0x7f51f9e38950>))
[4] During: typing of call at /project/csbio/envs_dirs/viz/lib/python3.6/site-packages/umap/nndescent.py (63)

[5] During: resolving callee type: type(CPUDispatcher(<function rejection_sample at 0x7f51f9e38950>))
[6] During: typing of call at /project/csbio/envs_dirs/viz/lib/python3.6/site-packages/umap/nndescent.py (63)

[7] During: resolving callee type: type(CPUDispatcher(<function rejection_sample at 0x7f51f9e38950>))
[8] During: typing of call at /project/csbio/envs_dirs/viz/lib/python3.6/site-packages/umap/nndescent.py (63)

[9] During: resolving callee type: type(CPUDispatcher(<function rejection_sample at 0x7f51f9e38950>))
[10] During: typing of call at /project/csbio/envs_dirs/viz/lib/python3.6/site-packages/umap/nndescent.py (63)


File "../../../envs_dirs/viz/lib/python3.6/site-packages/umap/nndescent.py", line 63:
    def nn_descent(
        <source elided>
        for i in range(data.shape[0]):
            indices = rejection_sample(n_neighbors, data.shape[0], rng_state)
            ^


Reproducible Parameters

Output when verbose=True:

UMAP(a=None, angular_rp_forest=False, b=None, init='spectral',
     learning_rate=1.0, local_connectivity=1.0, metric='correlation',
     metric_kwds=None, min_dist=0.1, n_components=2, n_epochs=None,
     n_neighbors=2.0, negative_sample_rate=5, random_state=None,
     repulsion_strength=1.0, set_op_mix_ratio=1.0, spread=0.1,
     target_metric='categorical', target_metric_kwds=None,
     target_n_neighbors=-1, target_weight=0.5, transform_queue_size=4.0,
     transform_seed=42, verbose=True)
Construct fuzzy simplicial set
Wed Jul 22 23:28:22 2020 Finding Nearest Neighbors
Wed Jul 22 23:28:22 2020 Building RP forest with 9 trees
Wed Jul 22 23:28:24 2020 NN descent for 12 iterations

Same error occurs when spread is changed to 1 or 10. Same error also occurs when min_dist is 0.0, 0.1, or 0.99 while spread is default.

It may be helpful to add a more informative error message.

nathanielbd avatar Jul 27 '20 21:07 nathanielbd

Clue? - for me right now this is happening only when I increase spread. output seems sensible if i ignore it. 🤔

dribnet avatar Aug 15 '24 00:08 dribnet