Repository navigation
[MRG+1] TSNE: only compute error when needed - #10593
Conversation
|
Tests failing... I've not looked, but hope it's minor, because this sounds great! |
1910079 to
794d790
Compare
|
Nice! |
| np.int64_t start, | ||
| int verbose) nogil: | ||
| int verbose, | ||
| int compute_error) nogil: |
| long start, | ||
| long stop) nogil: | ||
| long stop, | ||
| int compute_error) nogil: |
| for i in range(it, n_iter): | ||
| check_convergence = (i + 1) % n_iter_check == 0 | ||
| # only compute the error when needed | ||
| if 'compute_error' in kwargs: |
There was a problem hiding this comment.
why do we need this? What is the case where kwargs does not include compute_error? Do we need to be passing it in at all or just setting it here?
There was a problem hiding this comment.
It was to deal with this test.
I though it was safer to put this safe guard, but I am not sure anymore since _gradient_descent is private
There was a problem hiding this comment.
How about just put it comute_error=True in the default kwargs set above when kwargs is None? Then the logic in the loop is clearer and independent of the call params.
| check_convergence = (i + 1) % n_iter_check == 0 | ||
| # only compute the error when needed | ||
| if 'compute_error' in kwargs: | ||
| kwargs['compute_error'] = check_convergence |
There was a problem hiding this comment.
I think you need or i == n_iter - 1 here so that the verbose-printed KL-divergence and that set in kl_divergence_ is accurate.
| opt_args['kwargs']['angle'] = self.angle | ||
| # Repeat verbose argument for _kl_divergence_bh | ||
| opt_args['kwargs']['verbose'] = self.verbose | ||
| opt_args['kwargs']['compute_error'] = True |
There was a problem hiding this comment.
we can set this above where opt_args is defined, as it is invariant to method.
f1a999b to
67164ab
Compare
| "verbose": self.verbose, | ||
| "kwargs": dict(skip_num_points=skip_num_points), | ||
| "kwargs": dict(skip_num_points=skip_num_points, | ||
| compute_error=True), |
There was a problem hiding this comment.
I don't think this is needed anymore, as the default True will be upheld.
| kl_divergence = 2.0 * np.dot( | ||
| P, np.log(np.maximum(P, MACHINE_EPSILON) / Q)) | ||
| else: | ||
| kl_divergence = 0. |
There was a problem hiding this comment.
maybe return NaN so that this value is not mishandled?
76430c3 to
049af56
Compare
|
Merging. Thanks!!! |

This is a first speed improvement for TSNE with both solvers.
The idea is to compute the KL-divergence only every 50 iterations, when the stopping criterion is actually checked.
With
method='barnes_hut', it leads to a 40% speed improvement on the gradient descent.The benchmark is available here, where I used
--pca-components 0and a single CPU.