Skip to content

Commit e65ad4d

Browse files
authored
Merge pull request #3392 from VesnaT/tsne_random_seed
TSNE: Set fixed random seed
2 parents adf7a26 + 7349c7f commit e65ad4d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Orange/projection/manifold.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ class TSNE(Projector):
308308
is also supported.
309309
callbacks_every_iters : int
310310
How often should the callback be called.
311+
random_state: Optional[Union[int, RandomState]]
312+
The random state parameter follows the convention used in scikit-learn.
313+
If the value is an int, random_state is the seed used by the random
314+
number generator. If the value is a RandomState instance, then it will
315+
be used as the random number generator. If the value is None, the random
316+
number generator is the RandomState instance used by `np.random`.
311317
preprocessors
312318
313319
"""
@@ -321,8 +327,9 @@ def __init__(self, n_components=2, perplexity=30, learning_rate=200,
321327
early_exaggeration_iter=250, early_exaggeration=12,
322328
n_iter=750, exaggeration=None, theta=0.5, min_num_intervals=10,
323329
ints_in_interval=1, initialization='random', metric='euclidean',
324-
n_jobs=1, neighbors='exact', negative_gradient_method='bh', callbacks=None,
325-
callbacks_every_iters=50, preprocessors=None):
330+
n_jobs=1, neighbors='exact', negative_gradient_method='bh',
331+
callbacks=None, callbacks_every_iters=50,
332+
random_state=None, preprocessors=None):
326333
super().__init__(preprocessors=preprocessors)
327334
self.tsne = fastTSNE.TSNE(
328335
n_components=n_components, perplexity=perplexity,
@@ -333,6 +340,7 @@ def __init__(self, n_components=2, perplexity=30, learning_rate=200,
333340
metric=metric, n_jobs=n_jobs, neighbors=neighbors,
334341
negative_gradient_method=negative_gradient_method,
335342
callbacks=callbacks, callbacks_every_iters=callbacks_every_iters,
343+
random_state=random_state
336344
)
337345

338346
def fit(self, X: np.ndarray, Y: np.ndarray = None) -> fastTSNE.TSNEEmbedding:

Orange/widgets/unsupervised/owtsne.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def compute_tsne_embedding(X, perplexity, iter, init):
3131
tsne = Orange.projection.TSNE(
3232
perplexity=perplexity, n_iter=iter, initialization=init, theta=.8,
3333
early_exaggeration_iter=0, negative_gradient_method=negative_gradient_method,
34-
neighbors=neighbor_method,
34+
neighbors=neighbor_method, random_state=0
3535
)
3636
tsne_model = tsne.fit(X)
3737
return np.asarray(tsne_model, dtype=np.float32)

0 commit comments

Comments
 (0)