@@ -338,6 +338,14 @@ class TSNE(BaseEstimator):
338
338
Maximum number of iterations for the optimization. Should be at
339
339
least 200.
340
340
341
+ n_iter_without_progress : int, optional (default: 30)
342
+ Maximum number of iterations without progress before we abort the
343
+ optimization.
344
+
345
+ min_grad_norm : float, optional (default: 1E-7)
346
+ If the gradient norm is below this threshold, the optimization will
347
+ be aborted.
348
+
341
349
metric : string or callable, optional
342
350
The metric to use when calculating distance between instances in a
343
351
feature array. If metric is a string, it must be one of the options
@@ -395,6 +403,7 @@ class TSNE(BaseEstimator):
395
403
"""
396
404
def __init__ (self , n_components = 2 , perplexity = 30.0 ,
397
405
early_exaggeration = 4.0 , learning_rate = 1000.0 , n_iter = 1000 ,
406
+ n_iter_without_progress = 30 , min_grad_norm = 1e-7 ,
398
407
metric = "euclidean" , init = "random" , verbose = 0 ,
399
408
random_state = None ):
400
409
if init not in ["pca" , "random" ]:
@@ -404,6 +413,8 @@ def __init__(self, n_components=2, perplexity=30.0,
404
413
self .early_exaggeration = early_exaggeration
405
414
self .learning_rate = learning_rate
406
415
self .n_iter = n_iter
416
+ self .n_iter_without_progress = n_iter_without_progress
417
+ self .min_grad_norm = min_grad_norm
407
418
self .metric = metric
408
419
self .init = init
409
420
self .verbose = verbose
@@ -504,6 +515,8 @@ def _tsne(self, P, alpha, n_samples, random_state, X_embedded=None):
504
515
P /= self .early_exaggeration
505
516
params , error , it = _gradient_descent (
506
517
_kl_divergence , params , it = it + 1 , n_iter = self .n_iter ,
518
+ min_grad_norm = self .min_grad_norm ,
519
+ n_iter_without_progress = self .n_iter_without_progress ,
507
520
momentum = 0.8 , learning_rate = self .learning_rate ,
508
521
verbose = self .verbose , args = [P , alpha , n_samples ,
509
522
self .n_components ])
0 commit comments