Skip to content

Rationalize metric argument in T-SNE #9695

Open

Description

@tomMoral

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.

This issue is a follow-up of #9623 .

Activity

  1. amueller commented on May 22, 2018

    @amueller
    Member

    This is still open and we should at least document current behavior, right?

  2. jnothman commented on May 22, 2018

    @jnothman
    Member

    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.

  3. Micky774 commented on Feb 5, 2022

    @Micky774
    Contributor

    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) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions