Sorry for the long post, the beginning part is mainly about the motivation for this question. At the end I give a specific problem I would like solved.

I am plotting the angle of a complex function over a 2D space using colour to represent different angles. Most of my data is clustered together around a single angle with a relatively small variance. As a rough estimate, 90% of the data is within 15 degrees or so. For this reason I don't want to associate a unique colour to each of the angles in 360 degrees because most of the colours will go unused, I thus see it fit to find the "mean" (I concept I don't really know how to define on a circle) and then choose that angle to be associated with the colour in the middle of my colour wheel and then associate angles greater or less than the mean with colours varying on the colour wheel in such a way as to most efficiently use the colours.

The main problem I have run into is calculating the mean. Imagine most of the data is clustered around 0 degrees. Then there will be about half the data just above 0 and the rest of it just below 360 because of the nature of angle. Thus the mean will be about 180. You could imagine shifting all the data points around the circle so as to cause the mean to not be near 0 degrees however this would require already knowing the mean.

I have solved this problem. I imagine each data point as being a point in the plane like so. A point corresponding to the angle ø would be imagined as the point (cosø,sinø). I then take the mean of the data as it would be calculated for any data set in R2 (I take the mean in the x and the mean in the y) then I take this new point of the form (x,y) and calculate its corresponding angle with ø = atan(y/x) there by projecting the point back into the original space.

Of course this isn't perfect, say x=0, then you need to look at the sign of y and then pick 90 or 270 degrees accordingly. If y=x=0 then you can't get a value however in this case the notion of a mean doesn't really make sense in my opinion because the data is evenly spaced around the circle. Although this isn't perfect, it works for my application so I am going to leave it as it is.

This now brings me to a more general question. Say you have some topology other than Rn, with a distribution over it (like in my case above the topology S1). How might one calculate/define the "mean".

An easy generalization of what I did above can be done for a sphere, simply imagine the points as being in R3 and then take the mean, then project the mean back onto the sphere. In general you could take a data set over a manifold, embed it in Rn, and then project it back down onto the manifold and call that the mean.

However this doesn't always work. Say you have a torus, if you embed this in R3 you can find the mean however there is not a unique way to project a point in R3 onto a torus. This is because if you draw a straight line through the origin and the mean it may cross the torus more than once, unlike with a sphere.

I hope you found this problem interesting. Any links to resources discussing how this might be done would be greatly appreciated. Also any original ideas would be good too. Thanks


One idea is the least-squares method to fit the data to a point. Suppose you have samples $x_1,\ldots, x_N \in X$. Define for each candidate mean point $y \in X$ the distance $D(y) = \sum d(x_i,y)^2$. The choice of mean is the $y$ which minimises the value of $D(y)$.

Note this will depend on the choice of metric for $X$ and there is no reason to think the minimisation problem has an easy algebraic solution. You might have to use a computer to numerically calculate the mean.

Let's do a sanity check for $X$ the real line with the absolute value metric. We want to minimise $D(y) = \sum (x_i -y)^2$. That means find $y$ where $D'(y)=0$ and $D''(y)\ge 0$.

We calculate. . . .

$D'(y) = -\sum 2(x_i -y) \\$

$-\sum 2(x_i -y) = 0 \\$

$\implies \sum (x_i -y) = 0$

$\implies \sum x_i -Ny = 0$

$\implies \sum x_i = N y$

$\implies y = \displaystyle \frac{1}{N} \sum x_i$

So the only extremum is at the centre of gravity $-$ which is the usual definition of the mean point for a real-valued sample.

Now calculate the second derivative . . .

$D''(y) = -\sum 2(-1) = 2N$ is always positive.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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