Skip to main content

True Circular Mean

Theory of Circular Means

When computing the mean of angles the conventional approach is to take the arctangent of the mean of the sine and cosine of the angles. However, this is not true circular mean.

The mean M of a discrete set a={a_i} is formally defined as

M = argmin_m Sum_i distance_function(a_i,m) (Eq. 1)

where the distance_function(a_i,m) is some metric appropriate to the set.

For a linear mean, the one we are used to for linear values, the distance function is given by distance_function(a_i,m)=abs(a_i-m). However, for the conventional method commonly used for computing an average angle, i.e., the arctangent of the mean of the sine and cosine olf the angles, it can be shown that the distance function is distance_function(a_i,m)=1-cos(a_i-m), which is quite different than a linear measure. To illustrate this, consider Fig. 1, which shows three angles as stars on the unit circle. The average angle computed using the conventional method is given by the black line. The dashed red line shows the circular mean angle computed using the linear distance metric, which is visually much closer to the "middle" or mean angle than is the conventional angle average.

To solve for the mean using Eq. (1), we take the derivative and set it to zero. The conventional method has the advantage of being easily differentiable. The angle distance distance_function(1-cos(a_i-m)) yields the conventional formula for an "average angle" Ma given by:

Ma = atan2(sum_i(sin(a*π/180)), sum_i(cos(a*π/180))) -which is equivalent to-
Ma = atan2(mean(sin(a*π/180)), mean(cos(a*π/180)))

This works where the arctangent of its input arguments are defined. Note that it involves transcendential functions and that the distance function is related to the cosine of the angle difference. Further, when using circular sets such day of year, the value (which might be an integer) has to be converted to an angle [0..2π), which involves the irrational number π.

However, when considering the difference between two angles, the distance function can be better defined as what might called the minimum arc distance, i.e., the minimum of the two possible angles or arcs between the two angles. That is, the minimum angle moving clockwise or counterclockwise from one angle to the other. This minimum arc distance is between 0 and 180 deg. This is the linear distance as defined on a circular set. Computationally, this distance is the minimum of abs(a_i-m), abs(a_i-m-360), and abs(a_i-m+360), which can be written succintly as

distance_function(a_i,m)=180-abs(180-abs(mod(a_i-m,360))) (Eq. 2)

where mod is defined as used in Matlb, i.e., mod(a,b)=a-floor(a/b)*b. Note: the signed (+CCW vs -CW) distance_function for two angles a_i and m can be written as

distance_function(a_i,m)=mod(m-a_i+180,360)-180 (Eq. 3)

Eq. (2) appears to be hard to differentiate. However, by dividing the modulo and absolute value functions into sets, the derivative of the linear circular distance function can be determined, which can be used to solve Eq. (1) for the true circular mean as shown by Kogan [1]. This is computationally a little complicated [1] since it requires sorting parts of the data, but it involves no transcendential functions. Further, Kogan's implementation [1] of this solution avoids the angle sampling limitations of Matsuti's method [2]. Computation in degrees avoids irrational numbers such as π and so is well-suited for other circular data sets. Note that Kogan's method is not a "single-pass" algorithm [2,3], i.e., it requires the entire list of input angles. Other writeups include [5,6].

The weighted circular mean Mw is defined as

Mw = argmin_m Sum_i w_i*distance_function(a_i,m) (Eq. 4)

where {w_i} is the set weights associated with {a_i}.

The true circular standard deviation S is given by

S=sqrt( Sum_i distance_function(a_i,Mt)^2 / N) (5)

where Mt is the true circular mean and N is the number of angles in the set {a_i}. Note that this differs from common approximations for the angle standard deviation used by others [2],[3]. In computing both the conventional and circular standard deviation, this code uses the definition in Eq. (5) The weighted true circular standard deviation is given by

S=sqrt( Sum_i w_i*distance_function(a_i,Mt)^2 / Sum_i w_i). (Eq. 6)

Also of interest is the circular median, which has several potential definitions. Here, the circular median is defined as the input angle which has the smallest summed absolute angular distance between it and all other input angles.

Code is available for computing the circular mean, standard deviation, and median. Also provided is code to compute the conventional angle mean and standard deviation.

Available code implementations:

References:
[1] L. Kogan, 2013, "Circular Values Math and Statistics with C++11", https://www.codeproject.com/Articles/190833/Circular-Values-Math-and-Statistics-with-Cplusplus
[2] Y. Mori, 1986. "Evaluation of Several Single-Pass Estimators of the Mean and the Standard Deviation of Wind Direction." J Climate Appl. Metro., Vol. 25, pp. 1387-1397.
[3] Yamartino, R.J., 1984. "A Comparison of Several "Single-Pass" Estimators of the Standard Deviation of Wind Direction". Journal of Climate and Applied Meteorology. Vol. 23(9), pp. 1362-1366. doi:10.1175/1520-0450(1984)023<1362:ACOSPE>2.0.CO;2.
[4] Long, D.G., 2023 "True Circular Mean", MATLAB Central File Exchange, https://www.mathworks.com/matlabcentral/fileexchange/132118-true-circular-mean
[5] Allinger, A., 2015. "Circular values math and statistics with FORTRAN", https://www.codeproject.com/Articles/695494/Circular-Values-Math-and-Statistics-with-FORTRAN
[6] Olson, E. 2011. "On computing the average orientation of vectors and lines," http://wpril.eecs.umich.edu/pdfs/olson2011orientation.pdf

Maintained by David Long long@ee.byu.edu
Last modified: 14 Aug 2023