# How to average cyclic quantities?

Looking on Internet, I mostly found this definition:

Given quantities on a cyclic domain D, first rescale the domain to [0;2$\pi$[, then, find $z_n$ the point on the unit circle corresponding to the $n$th value, and compute the average by:

$$z_m = \sum_{n=1}^N z_n$$

The average angle is then $\theta_m = \arg z_m$ and to obtain the average value you scale back to your original domain D.

I must say, I have problems with this definition. For simplicity, I will use oriented angles in degree for my examples (i.e. D = [0;360[). With this formula, having angles -90, 90 and 40 will give 40 as mean angle, when I would expect 13.33 as an answer (i.e. (90-90+40)/3).

For my own problems, I usually use:

$$v_m = \mathop{\rm arg\,min}_{v\in D} \sum_{n=1}^{N} d(v_n,v)^2$$

Where $d(x,y)$ is the distance in the cyclic domain, and $\{v_1, v_2, \ldots, v_n\}$ is the set of cyclic data I want to average of.

It has the advantage to work the same way whatever the domain (replace D by a non-cyclic domain and $d$ with the usual euclidean distance, and you find the usual definition of an average). However, it is expensive to compute and I don't know any exact method to do it in general.

So my question is: what is the appropriate way to deal with average of cyclic data? And do you have good pointers that explain the problem and its solutions?

-
en.wikipedia.org/wiki/Circular_mean –  Rasmus Dec 16 '10 at 19:35
I know about this page. However, there is no justification for it. Also, I left a comment in the discussion of this page in the hope of understanding. But for now, I still disagree with this method to calculate the average. –  PierreBdR Dec 17 '10 at 17:38
The choice of distance metric depends crucially on the application. Bearing data, for instance, might be derived from estimates of X and Y with normally distributed errors, and this leads naturally to the circular mean. For other cases this might not be a good choice. –  wnoise Apr 4 '11 at 18:52

Like all averages, the answer depends upon the choice of metric. For a given metric $M$, the average of some angles $a_j \in [-\pi,\pi]$ for $j \in [1,N]$ is that angle $\bar{a}_M$ which minimizes the sum of squared distances $d^2_M(\bar{a}_M,a_j)$. For a weighted mean, one simply includes in the sum the weights $w_j$ (such that $\sum_j w_j = 1$). That is,

$$\bar{a}_M = \mathop{\rm arg\,min}_{x} \sum_{j=1}^{N}\, w_j\, d^2_M(x,a_j)$$

Two common choices of metric are the Frobenius and the Riemann metrics. For the Frobenius metric, a direct formula exists that corresponds to the usual notion of average bearing in circular statistics. See "Means and Averaging in the Group of Rotations", Maher Moakher, SIAM Journal on Matrix Analysis and Applications, Volume 24, Issue 1, 2002, for details. http://lcvmwww.epfl.ch/new/publications/data/articles/63/simaxpaper.pdf

-
Thank you, it is exactly the kind of reference I was looking for! –  PierreBdR May 9 '11 at 13:54

The problem with expecting the mean of 90°, −90°, and 40° to be (90°−90°+40°)/3 = 13.33° is that you would then expect the mean of 10° and 350° to be (10°+350°)/2 = 180°, and not 0° which is the more reasonable answer. It only gets worse when you have more than two angles (What is the mean of 340°, 350°, 360°, 10°, and 20°? What about 340°, 350°, 0°, 10°, and 20°?). Essentially, what you're doing there is equivalent to setting $z_n = e^{i\theta_n}$ and computing $$\bar z = (z_1 z_2 \cdots z_N)^{1/N},$$ and the problem is of course that it's not obvious a priori which of the $N$ possible roots of that equation is the right one, if any.

The "circular mean" definition is not so bad. In fact, it corresponds to the point which minimizes the sum of its squared distances to the points corresponding to the data, $$\bar z = \underset{\lvert z \rvert = 1}{\arg\min} \sum_{n=1}^N \lvert z - z_n \rvert^2.$$ So this is almost the same as the formula you like to use; you only have to define the "distance" between angles as the distance between the corresponding points on the unit circle. That is, $d(\theta, \phi) = \sqrt{2 - 2\cos(\theta-\phi)} = 2 \sin(\lvert\theta-\phi\rvert/2)$. This metric is close to $\lvert\theta-\phi\rvert$ when $\theta$ and $\phi$ are close, and has the advantage of being really easy to find the solution to.

-
Of the $N$ possible roots, one will be the global minimum of his distance functions, so checking all of them is sufficient. (See the reference Rob Johnson gave). –  wnoise Apr 4 '11 at 19:02

The angle is supposed to be the independent variable, not the dependent variable. If your function is cyclic (using degrees), z(-90)=z(270) so it doesn't matter which you use. Then the average value of the function is $$z_m=\sum_{n=1}^Nz(\theta_n)$$ You are right that if you average the angles, it matters which lap of the circle you use (-90 vs 270) because the difference of 360 gets divided by N.

-
This is what I am reading on Internet, but I have issues with this definition (as described in my post) and there is never a good explanation on why we should use this also for cyclic data. Could you expand? –  PierreBdR Dec 16 '10 at 17:54
The definition of a cyclic function is that f(x+T)=f(x) for some period T. The recommendation you saw was to rescale the units of x so that the period is 2pi radians or 360 degrees. I don't think that is important, but was trying to stay with it. As the function is cyclic, it doesn't matter which cycle you take the data from. So if you want the average value over a cycle it would be (if we take T to be 360) $$\frac{1}{360}\int_a^{a+360}f(x)dx$$ You can then approximate this by a sum just by taking equally spaced steps like $$\frac{1}{n}\sum_{i=0}^{n-1}f(\frac{360i}{n})$$ –  Ross Millikan Dec 16 '10 at 22:06
It looks like I am working on a different problem than you. Did you check the Wikipedia page that Rasmus suggested? Is that what you are after? –  Ross Millikan Dec 16 '10 at 22:27

For angles, one can adapt the iterative way of computing means to angles, that is:

given angles v[1] .. v[n]

m[1] = v[1]

m[i] = remainder( m[i-1] + remainder( v[i]-m[i-1], C)/i, C) (i=2..n)

where remainder(x,y) gives the signed remainder on dividing x by y and C is the measure of a circle.

I suspect this gives your vm, but haven't been able to prove it.

-
A quick check indicates it might not work. Applying this formula to the same set of values, simply taking the elements in various order leads to different results. –  PierreBdR Dec 17 '10 at 17:44