Repository navigation
[MRG+1] TSNE: Avoid power computation if exponent is 1 - #10610
Conversation
| # is about 10-15x more expensive than the | ||
| # following for loop | ||
| exponent = (dof + 1.0) / -2.0 | ||
| exponent = (dof + 1.0) / 2.0 |
There was a problem hiding this comment.
It doesn't look like this has a cdef!! It should also be set at the beginning of the function.
Should probably use cython -a to check for other untyped variables...
bfa9de5 to
db56103
Compare
jnothman
left a comment
There was a problem hiding this comment.
Thanks. I'm not sure if things like m deserve typing, nor if summary would've been implicitly typed because it's assigned a pointer... But this is good. I assume those typings didn't make a big dent on the benchmark
| dij += buff[ax] * buff[ax] | ||
| qij = ((1.0 + dij / dof) ** exponent) | ||
| qij = dof / (dof + dij) | ||
| if exponent != 1: |
There was a problem hiding this comment.
Careful, comparison with a float, that could suck :)
|
I was checking a bit more and there is no real reasoning to have scikit-learn/sklearn/manifold/t_sne.py Line 765 in a24c8b4 So basically, it will always be an integer. Then the comparison that you made will be ok. It required to change a bit more code but this is internal code. My only issue is when computing |
|
Is it better @glemaitre ? |
|
@TomDLT You forgot to change the signature of |
|
and |
| quad_tree._QuadTree qt, | ||
| float theta, | ||
| float dof, | ||
| int dof, |
| int n_dimensions, | ||
| int verbose, | ||
| float dof = 1.0, | ||
| int dof=1, |
|
This pull request introduces 37 alerts and fixes 18 - view on lgtm.com new alerts:
fixed alerts:
Comment posted by lgtm.com |
|
Ups sorry. Too much gradient everywhere. I misread :) |
| # Q is a heavy-tailed distribution: Student's t-distribution | ||
| dist = pdist(X_embedded, "sqeuclidean") | ||
| dist /= degrees_of_freedom | ||
| dist /= float(degrees_of_freedom) |
There was a problem hiding this comment.
I would let it as is ensuring that we have from __future__ import division on the top
|
by the way, I don't get why LGTM is complaining :) |
|
Rerunning the benchmark (on a different computer): The ~24% speed improvement is still there. |
|
Great merging when it's green |
|
This pull request introduces 37 alerts and fixes 18 - view on lgtm.com new alerts:
fixed alerts:
Comment posted by lgtm.com |
|
Thanks Tom |
|
Thanks for the reviews ! |
|
nice work!
I suspect lgtm.com added some new queries to the default set of alerts and
didn't fix it to compare to the right baseline
|
|
Thanks for flagging this up @jnothman — I'll try to figure out what went wrong here on the lgtm.com side. |


Follows #10593
This is a second speed improvement for TSNE with "barnes_hut" solver.
The idea is to avoid an exponent computation.
This exponent is almost always equal to -1.
Indeed, the embedded space is equal to 2 in almost every application, and:
This PR changes
exponentinto-exponentwhich is now equal to 1 in most cases.It leads to a 24% speed improvement on the gradient descent.
or total TSNE duration including NearestNeighbors (NN):

The benchmark is available here, where I used
--pca-components 0and a single CPU.