For a project I'm working on, I have two sets of samples, where each set has N x length 7 vectors. For context, each vector represents the joint parameter setting for a robot (the angle each joint of the robot is set to).

I'm interested in comparing the similarity of the distributions from which the vectors were drawn from. I understand typically you can use KL-Divergence/MMD/etc., but these methods aren't appropriate (I don't think at least) because of the circular topology of the data - I.e. the value 0 and 2pi are the same, but would be considered far apart by a standard similarity measure for probability distributions.

How can I calculate a numeric similarity between the two distributions from which the samples were drawn from given this circular topology?


brief extra: An idea I had was to convert each angle into a (x, y) pair, $\theta \rightarrow (cos(\theta), sin(\theta))$. Then the problem becomes comparing the distributions of vectors of (x,y) pairs, not sure that thats a great path to head down though

  • $\begingroup$ These read like two very different questions. Could you please limit your post to one of them? $\endgroup$
    – whuber
    Jun 3, 2020 at 19:37
  • $\begingroup$ @whuber, the post has been edited to have one question ✅ $\endgroup$
    – jstm
    Jun 3, 2020 at 19:41

1 Answer 1


Your data lie on the 7-torus $T^7.$ It has many geometries, but two natural ones in this application would be based on the function

$$\delta(a) = \left(|a| + \pi \mod 2\pi\right) - \pi$$

with values in the interval $[-\pi, \pi).$ This is the unsigned value of the oriented angle $a.$

Where all variables are considered approximately of equal weight in the analysis, for the distance between two vectors $\mathrm{x}=(x_1, \ldots, x_7)$ and $\mathrm{y}=(y_1,\ldots, y_7)$ use a function of the vector

$$\delta(\mathrm{x}, \mathrm{y}) = (\delta(x_1-y_1), \ldots, \delta(x_7-y_7)),$$

such as its $L_p$ norm for $p \ge 1.$ You can weight this norm by multiplying the components by positive weights $\omega_1, \ldots, \omega_7$ before computing the norm.

These are all valid metrics: they are symmetric and satisfy the triangle inequality. One way to prove this follows your suggestion: these metrics can be expressed in terms of metrics on $\mathbb{R}^{14}$ induced by the embedding $\phi:T^7\to \mathbb{R}^{14}$ given by

$$\phi(\mathrm{x}) = (\cos(x_1), \sin(x_1), \cos(x_2), \ldots, \sin(x_7)).$$

However, you don't need actually to compute this embedding in order to compute $\delta,$ as you can see from its initial formula.

  • $\begingroup$ Thanks for the detailed description @whuber - from what I understand this allows me to measure the distance between specific samples. sorry if I didn't make it clear, but i'm what i'm interested in is the similarity between the distributions from which the samples are drawn from, not the distance between specific samples. Unless am I missing something for how this distance can be used to find similarity between the distributions? $\endgroup$
    – jstm
    Jun 3, 2020 at 20:12
  • $\begingroup$ ive updated the post to make it more clear $\endgroup$
    – jstm
    Jun 3, 2020 at 20:14
  • $\begingroup$ It isn't clear what more you might need because you are still vague about what you mean by "similar." Given that all methods to compare distributions require some metric to quantify how close their values are, my presumption is that a suitable distance will be the foundation of a solution. $\endgroup$
    – whuber
    Jun 3, 2020 at 20:28
  • $\begingroup$ so by similar I mean a measure of how one probability distribution is different from a second. A common measure is KL Divergence (en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence) $\endgroup$
    – jstm
    Jun 3, 2020 at 21:10
  • 1
    $\begingroup$ The answer you quote begins with the important caveat "we would need, maybe, some estimates of the density functions." (Those estimates implicitly rely on some measure of distances among the points, btw.) Therein lies the problem: unless you have relatively large amounts of data, your computation of a KL divergence will be exquisitely sensitive to those density estimates, which in turn depend on the distance metric. Other procedures will be better. $\endgroup$
    – whuber
    Jun 4, 2020 at 12:39

Your Answer

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

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