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

Recursion Error (Different from Previous Post) #23

Closed
nicolerg opened this issue Nov 21, 2017 · 11 comments
Closed

Recursion Error (Different from Previous Post) #23

nicolerg opened this issue Nov 21, 2017 · 11 comments
Labels

Comments

@nicolerg
Copy link

nicolerg commented Nov 21, 2017

EDIT: Is this just a version issue? RecursionError was RuntimeError before python 3.5.

I'm working with a large data set (~1,700,000 x ~400), and I'm getting the following error:

Traceback (most recent call last): File "umapping.py", line 25, in <module> u = umap.UMAP(metric="correlation").fit_transform(data) File "/users/nicolerg/anaconda2/lib/python2.7/site-packages/umap/umap_.py", line 1573, in fit_transform self.fit(X) File "/users/nicolerg/anaconda2/lib/python2.7/site-packages/umap/umap_.py", line 1534, in fit self.verbose File "/users/nicolerg/anaconda2/lib/python2.7/site-packages/umap/umap_.py", line 559, in rptree_leaf_array except RecursionError: NameError: global name 'RecursionError' is not defined

This is the relevant bit of code:

data = ps.read_csv(args.input, compression="gzip", header=1, sep=',') nrows = len(data) colors = np.random.rand(nrows, 3) # RGB colors u = umap.UMAP(metric="correlation", n_neighbors=25).fit_transform(data)

I increased n_neighbors from the default of 15 to 25 to see if that would help, but I got the same error. I do not expect that I have equivalent rows in my data. I am trying to cluster the ~1,700,000 instances in ~400 dimensions. Any suggestions?

@lmcinnes lmcinnes added the bug label Nov 21, 2017
@lmcinnes
Copy link
Owner

Hi, thanks for the report. You are correct that this is likely a version issue, well spotted. I should fix that up (my fault for only looking at the latest docs and going with RecursionError). Of course the other issue is that you are getting such a thing at all, but then with 1.7 million data points that might just be possible if they don't split too nicely. Still, expected is something like a depth of 21, so something is going seriously astray. If you can share the data I would be interested in trying to figure out what is going wrong exactly.

@nicolerg
Copy link
Author

nicolerg commented Nov 21, 2017

Now that I've got it running in 3.5, I got a much more detailed error:

`Traceback (most recent call last):
File "umapping.py", line 25, in
u = umap.UMAP(metric="correlation", n_neighbors=25).fit_transform(data)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/umap/umap_.py", line 1573, in fit_transform
self.fit(X)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/umap/umap_.py", line 1534, in fit
self.verbose
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/umap/umap_.py", line 553, in rptree_leaf_array
angular=angular)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/umap/umap_.py", line 359, in make_tree
rng_state)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/dispatcher.py", line 330, in _compile_for_args
raise e
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/dispatcher.py", line 307, in _compile_for_args
return self.compile(tuple(argtypes))
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/dispatcher.py", line 579, in compile
cres = self._compiler.compile(args, return_type)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/dispatcher.py", line 80, in compile
flags=flags, locals=self.locals)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/compiler.py", line 763, in compile_extra
return pipeline.compile_extra(func)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/compiler.py", line 360, in compile_extra
return self._compile_bytecode()
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/compiler.py", line 722, in _compile_bytecode
return self._compile_core()
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/compiler.py", line 709, in _compile_core
res = pm.run(self.status)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/compiler.py", line 246, in run
raise patched_exception
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/compiler.py", line 238, in run
stage()
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/compiler.py", line 452, in stage_nopython_frontend
self.locals)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/compiler.py", line 865, in type_inference_stage
infer.propagate()
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/typeinfer.py", line 844, in propagate
raise errors[0]
numba.errors.TypingError: Failed at nopython (nopython frontend)
Internal error at <numba.typeinfer.ArgConstraint object at 0x7f5325955b00>:
--%<-----------------------------------------------------------------
Traceback (most recent call last):
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/errors.py", line 259, in new_error_context
yield
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/typeinfer.py", line 189, in call
assert ty.is_precise()
AssertionError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/typeinfer.py", line 137, in propagate
constraint(typeinfer)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/typeinfer.py", line 190, in call
typeinfer.add_type(self.dst, ty, loc=self.loc)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/contextlib.py", line 77, in exit
self.gen.throw(type, value, traceback)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/errors.py", line 265, in new_error_context
six.reraise(type(newerr), newerr, sys.exc_info()[2])
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/errors.py", line 259, in new_error_context
yield
File "/users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/numba/typeinfer.py", line 189, in call
assert ty.is_precise()
numba.errors.InternalError:
[1] During: typing of argument at /users/nicolerg/anaconda2/envs/py35/lib/python3.5/site-packages/umap/umap_.py (248)
--%<-----------------------------------------------------------------

File "../../../../anaconda2/envs/py35/lib/python3.5/site-packages/umap/umap_.py", line 248

This error may have been caused by the following argument(s):

  • argument 0: cannot determine Numba type of <class 'pandas.core.frame.DataFrame'>`

I don't think I'm allowed to share the data, so I'll keep troubleshooting and let you know if I figure anything out. I'd appreciate if you have any insight from this more detailed error.

@lmcinnes
Copy link
Owner

lmcinnes commented Nov 21, 2017

That's fine, data is often not shareable.

This new error is a pre-error that is again my fault. There is no array checking in place as scikit-learn does yet, which means you can't pass in a pandas dataframe (at least not yet).. To get past this you shoudl be able to do

u = umap.UMAP(metric="correlation", n_neighbors=25).fit_transform(data.values)

but that may land you back in recursion error land. You can probably just change that by hand yourself in the code if you need to -- I won't be able to get a chance to test a commit a fix for a little while (a PR would be very welcome if you do get the fix sorted).

I'll also try and add in scikit-learn's checking to make this work better.

@lmcinnes
Copy link
Owner

After looking at options I went with the simplest possible thing I could do. Unfortunately I have had issues replicating the RecursionError so I admit my testing that this will actually fix the issue is quite inadequate. I would greatly appreciate it if, when you have available time, you could pull from master, rebuild and reinstall and see if this fixes the problem for you. Thanks again.

@nicolerg
Copy link
Author

The recursion error went away as soon as I changed the input from a data frame to an array (I didn't pull from master to get this result). The job does finish now, granted it takes some time, but the first result I got is really strange. This is with metric="correlation" and n_neighbors=25.
roadcode-all-umap

@lmcinnes
Copy link
Owner

The correlation metric actually has some issues (which I only very recently debugged). Try cosine instead and see if that helps. It certainly is an odd result, but may look stranger due to overplotting. Consider setting the s value on the scatterplot to 1, or something similar.

@KeithTheEE
Copy link

I might know something about that weird result. I haven't checked in with the latest version of the code for a while so I might be out of date here, but here goes.

Briefly: Those results pop up when the learning rate is 'bad' (there could be other causes, this is the cause I know about). Playing with the inputs a and b could help that.

In more depth: the program determines a learning rate (or embedding adjustment rate) based on a few values. The user has control over those values to various degrees (layers of abstraction). Using the defaults, the program determines this off of the spread and min_dist values, defaults being 1.0 and 0.1 respectively. From there it passes those values to a function which solves for a and b using a curve fit on an exponential decay. Using the default spread and min_dist, the fitted a and b values are about 1.577 and 0.895 respectively. After that those values--combined with the alpha and gamma parameter (defaults being 1.0 and 1.0) and the embedding data--are used in optimize_layout to determine grad_coeff and grad_d which impacts the embedding adjustments. If you need to use correlation, playing around with those values might help resolve a signal from the noise.
(also please correct me if I'm misunderstanding the implications of the code)

@nicolerg
Copy link
Author

nicolerg commented Dec 5, 2017

roadcode-all-umap-10n-cosine

Above is the result for using method "cosine." Looks similar to "correlation." (Groups are NOT labeled - color is random).

I ran t-SNE with a subset of 100k data points, and this is what it looks like (groups ARE labelled; color is not random).

100k-tsne-single

Perhaps UMAP would look similar if I only chose a subset of 100k data points? This update is for your benefit. I've moved on from this point.

@lmcinnes
Copy link
Owner

lmcinnes commented Dec 5, 2017

Thanks for the update, it does look like something is going astray. It may be related to issue #32 . It may also relate to hubness issues. I'm really not sure, but it is something I will continue to look into. I greatly appreciate the feedback, and am sorry that UMAP didn't seem to work for you. Hopefully I'll have some fixes in the future, so please don't write off the algorithm entirely just yet.

@lmcinnes
Copy link
Owner

I wanted to provide an update on this -- I know you have moved on to other issues, but just in case you run into another project where UMAP might be useful...

I believe this issue has finally been resolved. It proved remarkably tricky to get to the bottom of, but was, in the end, a code bug in the SGD optimization of the layout. The latest master branch (v0.2.0+) has a new SGD optimization layout algorithm that does not encounter this issue and should produce much better looking embeddings for large datasets.

@sleighsoft
Copy link
Collaborator

Looks resolved. Closing.

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

No branches or pull requests

4 participants