Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange iteration results "error is nan" and RuntimeWarning using t-SNE

I am using t-SNE python implementation for dimensionality reduction on X which contains 100 instances each described by 1024 parameters for cnn visualization.

X.shape = [100, 1024]

X.dtype = float32

When I run :

Y = tsne.tsne(X)

The first warning pops out in tsne.py, line 23 :

RuntimeWarning: divide by zero encountered in log H = Math.log(sumP) + beta * Math.sum(D * P) / sumP

Then there is a couple more warnings like this one on the following lines :

RuntimeWarning: invalid value encountered in divide

And finally I get this result after each iteration during the processing :

Iteration xyz : error is nan

The code ends without "errors" and I get an empty scatter plot at the end.

EDIT:

-> I have tried it with a different data set and it worked perfectly. However I would need it to work on my first set as well (the one that seems to cause problems)

Question :

Does anyone know what might be causing this? Is there a workaround?

like image 270
Julep Avatar asked Apr 05 '16 01:04

Julep


1 Answers

sumP = sum(P)+np.finfo(np.double).eps
H = np.log(sumP) + beta * np.sum(D * P) / sumP;

This should fix the problem

like image 191
Debajyoti Chatterjee Avatar answered Sep 28 '22 17:09

Debajyoti Chatterjee