Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeWarning: divide by zero encountered in power #22

Closed
fedden opened this issue Nov 19, 2017 · 4 comments
Closed

RuntimeWarning: divide by zero encountered in power #22

fedden opened this issue Nov 19, 2017 · 4 comments

Comments

@fedden
Copy link

fedden commented Nov 19, 2017

Hi there, first of all, thanks loads for this exciting algorithm. I'm writing a blog post on comparing this to a couple of other dim reduction techniques. I noticed when I'm using umap on a dataset with entries such as:

array([  0.        ,   0.        ,   0.        ,   0.        ,
         0.        ,   0.        ,   0.        ,   0.        ,
         0.        ,   0.        ,   0.        ,   0.        ,
         0.        ,   0.        ,   0.        ,   0.        ,
        -1.88847315,  11.17503262,  -0.69157058,   5.85993528,
         0.98581624,  -1.14453554,   0.61075902,  -3.21815372,
         4.9411006 ,   5.51712704,  -1.7895503 ,   2.04580665,
         0.22949766,  -6.60904551,   8.11811924,   1.88291252,
         0.        ,   0.        ,   0.        ,   0.        ,
         0.        ,   0.        ,   0.        ,   0.        ,
         0.        ,   0.        ,   0.        ,   0.        ,
         0.        ,   0.        ,   0.        ,   0.        ])

I get the following runtime warning

/usr/local/lib/python3.5/dist-packages/umap/umap_.py:592: RuntimeWarning: divide by zero encountered in power
  return 1.0 / (1.0 + a * x ** (2 * b))
/usr/local/lib/python3.5/dist-packages/scipy/optimize/minpack.py:779: OptimizeWarning: Covariance of the parameters could not be estimated
  category=OptimizeWarning)

And less than satisfactory results such as this (plots of many neighbour and distance settings:
wah
Any thoughts?

@fedden
Copy link
Author

fedden commented Nov 19, 2017

Apologies! This was due to a typo in my code and I was sending crappy parameters to the umap method!
:)

sound

@fedden fedden closed this as completed Nov 19, 2017
@lmcinnes
Copy link
Owner

Hi -- glad the issue got resolved! Still it might be useful if UMAP could give better warnings or more informative errors about bad parameters. If you think this might be such a case please let me know what was wrong and I can try to catch it earlier with better inout validation and provide a more interpretable error.

Also, I am definitely looking forward to your blog post!

@fedden
Copy link
Author

fedden commented Nov 20, 2017

Ah thank you! I'll find the exact case where passed those runtime warnings and get back to you.

I've glossed over the technical details but really loved using this algorithm for this blog post here!

Thanks again for it!

@nathanielbd
Copy link

@lmcinnes I'm getting this same issue. Here's my stdout when I run with 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

I also get the same error when I change spread to 1 or 10.

Hope that helps now that you have an exact set of parameters. @fedden Do you remember/does this help you remember what was wrong with your parameters?

Here's my stderr:

/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)
            ^


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants