0
$\begingroup$

I'm not certain if my error lies in my understanding of python's sklearn or of t-SNE, but I have (essentially), the following code:

import numpy as np
from sklearn.manifold import TSNE
...

latent_codes = np.asarray(latent_codes)
model = TSNE(n_components=2, random_state=0)
targets = model.fit_transform(latent_codes)

import pdb
pdb.set_trace()

Now, when I take advantage of pdb to examine latent_codes, I find it's a 40x50 zero matrix:

(Pdb) latent_codes.shape
(40, 50)

(Pdb) latent_codes
array([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        ..., 
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]])
(Pdb) np.count_nonzero(latent_codes)
0

However, the targets produced by model_fit_transform are all different:

(Pdb) targets
array([[ -68.17034118,   59.8387551 ],
   [ 154.31303231,  -65.25843496],
   [-116.26644151,  -19.97313287],
   [  25.15679123,  -96.2950044 ],
   [ -21.30201657,   15.49542397],
   [ 117.35081217,   44.15759738],
   [ -82.23108406,  -48.82985134],
   [-113.48912279,   26.86769182],
   [  63.0661867 ,  -77.18010188],
   [-214.31557952,  186.65681657],
   [  41.81882958,  128.70962697],
   [   4.56304673,  -14.75060863],
   [ -64.14735674,   21.53516755],
   [ -51.69388635, -159.27904258],
   [ -47.77084845, -115.1462873 ],
   [ 131.90001156,   -6.43364854],
   [  -0.83806249, -128.14477442],
   [-296.70119624, -119.19975211],
   [ -46.69551791,   95.57097896],
   [   5.87913502,   94.59336748],
   [  20.06775981,   29.26705814],
   [  50.24510794,    1.10575949],
   [  35.81033393,  -41.01231103],
   [ 273.79224551,  198.21000606],
   [ -28.41723332,  -40.45356725],
   [-109.32362451,   82.86647462],
   [ 133.32828608,   97.65628466],
   [-108.9115903 ,  -87.49420981],
   [ -48.84660715,  -76.67380263],
   [  14.60874986, -173.3446314 ],
   [  80.21260263,  -28.05786872],
   [  66.4516378 , -128.04476666],
   [  73.15296956,   35.96795971],
   [  80.93310524,   91.51665493],
   [ -56.73663254,  -15.00847778],
   [ 106.25595116,  -67.73558382],
   [   0.01308238,  -66.19634508],
   [ -16.16269284,   56.56122915],
   [ -24.14615918,  136.37358297],
   [  40.32559439,   67.55044349]])

If I'm trying to project the same 50-dim point to a 2-dim space 40 times, shouldn't I get the same 2-dim point 40 times?

$\endgroup$
1
  • $\begingroup$ t-SNE attempts to have the low dim projections of the high dimensional data reflect the distance between those points. The distance between each of my 50-dim points is zero. Clearly, these distances are not being preserved. If I had a non-degenerate case of 50-dim points, then I would not be surprised to get different projections from repeated t-SNE projections. As it is, I'm very uneasy that a single high-dim point, from a single run of t-SNE get projected to so many low-dim points. This does not seem to be very effective at preserving the inter-point distance. $\endgroup$ Commented Jul 19, 2016 at 1:37

1 Answer 1

-1
$\begingroup$

No you need to set up a random seed to get the same values .

$\endgroup$
2
  • $\begingroup$ This is a bit brief by our standards, although it does seem to be an answer to the question. I think it would benefit from mentioning why setting the seed is necessary. $\endgroup$
    – Silverfish
    Commented Jul 18, 2016 at 7:36
  • $\begingroup$ If I had multiple runs on the same dataset, I'd agree that I needed to set up a random seed. But, this is from a single run on a single dataset. $\endgroup$ Commented Jul 19, 2016 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.