You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The API of T-SNE have a metric argument to allow changing the metric in the input space. The original paper was developed using only the euclidean distance and changing the metric might change a bit the math.
The main issue is to understand what is going on with the computation of the conditional probabilities. The original paper states that if d_ij is the euclidean distance between x_i and x_j, then the conditional probability is given by
p(x_j | x_i) = exp{ d_ij^2 / sig_i} / Z
where Z is a normalization constant and sig_i is a parameter, computed to fix the perplexity of the model. If d_ij is not the euclidean distance, does it make sense to use this formula?
The current implementation for other metric than the euclidean uses the formula without the square, so
p(x_j | x_i) = exp{ d_ij / sig_i} / Z
If it is fine, this should be documented. Else, shall we change it to use the square or another distribution? Another solution is to deprecate the metric argument.
A second point is the use of init='pca'. It is a very natural initialization for the euclidean metric but should be benchmarked for other to see if it gives an interesting starting point or not.
Is sig_i negative? Presumably in order to get a probability you need to exp negative numbers.
It's mostly intuition, but I'm fairly sure this conditional probability definition (which is a softmax over squared distances) should apply just as well to other squared distances.
I've not understood why it should be squared, but obviously distance matrices have certain properties defined by the definition of proper distance metrics, and so squared distances would too.
I don't see why Euclidean should be distinguished. As far as I understand, for any distance matrix you can construct points in infinite-dimensional Euclidean space that have those distances.
So yes, we should be squaring other metrics IMO. How to make this change, and how to deal with precomputed, I'm not sure. So we should absolutely start with documentation.
TL;DR Changes in metric mostly still correspond to gaussian conditional probability, I think it's fine to "trust" the user with using a proper metric.
First we can discuss Euclidean distance as a special case of a family of distance metrics defined by matrices -- given a PSD matrix P, d_P(x,y) = sqrt[ (x-y)^T P (x-y) ]. Then the Euclidean distance is the case where P=I. Consider a distribution of points in any Euclidean space. Scaling the points' coordinates arbitrarily (but consistently for all points), e.g. x_i,j --> x_i,j * s_j, acts as a change of metric, where the corresponding matrix goes from I --> S = diag(s_1, s_2,...) -- if S is PSD. This is already considered fair-game for t-sne and is already put on the user.
I think you can generalize the choice of metric for t-sne to account for the fact that exp[ (-1/2)*d_P(x, m) ] defines a gaussian pdf when m is the mean and P is the covariance matrix. Therefore any invertible mapping f that can be viewed as a change to the underlying metric, e.g. x --> Ax where A is invertible which changes the underlying matrix P --> (A^T)P(A), also ensures that t-sne of f(X) is t-sne performed under some gaussian conditional probability, albeit potentially ill-conditioned.
In that sense, I think it's safe to generalize the "acceptable" metrics from just Euclidean to any PSD-matrix induced metric.
*Bonus: For a metric space (X, d) I'm pretty sure that any injective mapping f: X-->X also properly defines a new metric d_f(x, y) = d( f(x), f(y) )
Activity
amueller commentedon May 22, 2018
This is still open and we should at least document current behavior, right?
jnothman commentedon May 22, 2018
Is sig_i negative? Presumably in order to get a probability you need to exp negative numbers.
It's mostly intuition, but I'm fairly sure this conditional probability definition (which is a softmax over squared distances) should apply just as well to other squared distances.
I've not understood why it should be squared, but obviously distance matrices have certain properties defined by the definition of proper distance metrics, and so squared distances would too.
I don't see why Euclidean should be distinguished. As far as I understand, for any distance matrix you can construct points in infinite-dimensional Euclidean space that have those distances.
So yes, we should be squaring other metrics IMO. How to make this change, and how to deal with precomputed, I'm not sure. So we should absolutely start with documentation.
Micky774 commentedon Feb 5, 2022
TL;DR Changes in metric mostly still correspond to gaussian conditional probability, I think it's fine to "trust" the user with using a proper metric.
First we can discuss Euclidean distance as a special case of a family of distance metrics defined by matrices -- given a PSD matrix
P,d_P(x,y) = sqrt[ (x-y)^T P (x-y) ]. Then the Euclidean distance is the case whereP=I. Consider a distribution of points in any Euclidean space. Scaling the points' coordinates arbitrarily (but consistently for all points), e.g.x_i,j --> x_i,j * s_j, acts as a change of metric, where the corresponding matrix goes fromI --> S = diag(s_1, s_2,...)-- ifSis PSD. This is already considered fair-game fort-sneand is already put on the user.I think you can generalize the choice of metric for
t-sneto account for the fact thatexp[ (-1/2)*d_P(x, m) ]defines a gaussian pdf whenmis the mean andPis the covariance matrix. Therefore any invertible mappingfthat can be viewed as a change to the underlying metric, e.g.x --> AxwhereAis invertible which changes the underlying matrixP --> (A^T)P(A), also ensures thatt-sneoff(X)ist-sneperformed under some gaussian conditional probability, albeit potentially ill-conditioned.In that sense, I think it's safe to generalize the "acceptable" metrics from just Euclidean to any PSD-matrix induced metric.
*Bonus: For a metric space
(X, d)I'm pretty sure that any injective mappingf: X-->Xalso properly defines a new metricd_f(x, y) = d( f(x), f(y) )