Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Averaging angles... Again

Tags:

I want to calculate the average of a set of angles, which represents source bearing (0 to 360 deg) - (similar to wind-direction)

I know it has been discussed before (several times). The accepted answer was Compute unit vectors from the angles and take the angle of their average.

However this answer defines the average in a non intuitive way. The average of 0, 0 and 90 will be atan( (sin(0)+sin(0)+sin(90)) / (cos(0)+cos(0)+cos(90)) ) = atan(1/2)= 26.56 deg

I would expect the average of 0, 0 and 90 to be 30 degrees.

So I think it is fair to ask the question again: How would you calculate the average, so such examples will give the intuitive expected answer.

Edit 2014:

After asking this question, I've posted an article on CodeProject which offers a thorough analysis. The article examines the following reference problems:

  • Given time-of-day [00:00-24:00) for each birth occurred in US in the year 2000 - Calculate the mean birth time-of-day
  • Given a multiset of direction measurements from a stationary transmitter to a stationary receiver, using a measurement technique with a wrapped normal distributed error – Estimate the direction.
  • Given a multiset of azimuth estimates between two points, made by “ordinary” humans (assuming to subject to a wrapped truncated normal distributed error) – Estimate the direction.
like image 507
Lior Kogan Avatar asked Nov 28 '09 19:11

Lior Kogan


People also ask

How do you average a angle?

To calculate the mean angle of several angles: Assume all angles are on the unit circle and convert them to complex numbers expressed in real and imaginary form. Compute the mean of the complex numbers. Convert the complex mean to polar coordinates whereupon the phase of the complex mean is the required angular mean.

How do you find the mean of two angles?

Taking the average like (a+b)/2 and then mod 180 is exactly the same as first doing (a+b) mod 360 and then divide by 2.

How do you average bearings?

Usually to find the average one would add them all up and divide by the number of items. The problem here is that doing that in the case of [1, 359], 2 bearings, would result in in 180, which in fact should be 360.

How do you find average direction?

To understand it intuitively, you could draw the two vectors down. Then draw a line segment between the endpoints of the two. The midpoint of this segment is the average vector. This works for any number of dimensions.


2 Answers

[Note the OP's question (but not title) appears to have changed to a rather specialised question ("...the average of a SEQUENCE of angles where each successive addition does not differ from the running mean by more than a specified amount." ) - see @MaR comment and mine. My following answer addresses the OP's title and the bulk of the discussion and answers related to it.]

This is not a question of logic or intuition, but of definition. This has been discussed on SO before without any real consensus. Angles should be defined within a range (which might be -PI to +PI, or 0 to 2*PI or might be -Inf to +Inf. The answers will be different in each case.

The world "angle" causes confusion as it means different things. The angle of view is an unsigned quantity (and is normally PI > theta > 0. In that cases "normal" averages might be useful. Angle of rotation (e.g. total rotation if an ice skater) might or might not be signed and might include theta > 2*PI and theta < -2*PI.

What is defined here is angle = direction whihch requires vectors. If you use the word "direction" instead of "angle" you will have captured the OP's (apparent original) intention and it will help to move away from scalar quantities.

Wikipedia shows the correct approach when angles are defined circularly such that

theta = theta+2*PI*N = theta-2*PI*N 

The answer for the mean is NOT a scalar but a vector. The OP may not feel this is intuitive but it is the only useful correct approach. We cannot redefine the square root of -4 to be -2 because it's more initutive - it has to be +-2*i. Similarly the average of bearings -90 degrees and +90 degrees is a vector of zero length, not 0.0 degrees.

Wikipedia (http://en.wikipedia.org/wiki/Mean_of_circular_quantities) has a special section and states (The equations are LaTeX and can be seen rendered in Wikipedia):

Most of the usual means fail on circular quantities, like angles, daytimes, fractional parts of real numbers. For those quantities you need a mean of circular quantities.

Since the arithmetic mean is not effective for angles, the following method can be used to obtain both a mean value and measure for the variance of the angles:

Convert all angles to corresponding points on the unit circle, e.g., α to (cosα,sinα). That is convert polar coordinates to Cartesian coordinates. Then compute the arithmetic mean of these points. The resulting point will lie on the unit disk. Convert that point back to polar coordinates. The angle is a reasonable mean of the input angles. The resulting radius will be 1 if all angles are equal. If the angles are uniformly distributed on the circle, then the resulting radius will be 0, and there is no circular mean. In other words, the radius measures the concentration of the angles.

Given the angles \alpha_1,\dots,\alpha_n the mean is computed by

M \alpha = \operatorname{atan2}\left(\frac{1}{n}\cdot\sum_{j=1}^n 

\sin\alpha_j, \frac{1}{n}\cdot\sum_{j=1}^n \cos\alpha_j\right)

using the atan2 variant of the arctangent function, or

M \alpha = \arg\left(\frac{1}{n}\cdot\sum_{j=1}^n 

\exp(i\cdot\alpha_j)\right)

using complex numbers.

Note that in the OP's question an angle of 0 is purely arbitrary - there is nothing special about wind coming from 0 as opposed to 180 (except in this hemisphere it's colder on the bicycle). Try changing 0,0,90 to 289, 289, 379 and see how the simple arithmetic no longer works.

(There are some distributions where angles of 0 and PI have special significance but they are not in scope here).

Here are some intense previous discussions which mirror the current spread of views :-)

http://mathforum.org/library/drmath/view/53924.html

How do you calculate the average of a set of circular data?

http://forums.xkcd.com/viewtopic.php?f=17&t=22435

http://www.allegro.cc/forums/thread/595008

like image 193
9 revs Avatar answered Sep 19 '22 12:09

9 revs


Thank you all for helping me see my problem more clearly.

I found what I was looking for. It is called Mitsuta method.

The inputs and output are in the range [0..360).

This method is good for averaging data that was sampled using constant sampling intervals.

The method assumes that the difference between successive samples is less than 180 degrees (which means that if we won't sample fast enough, a 330 degrees change in the sampled signal would be incorrectly detected as a 30 degrees change in the other direction and will insert an error into the calculation). Nyquist–Shannon sampling theorem anybody ?

Here is a c++ code:

double AngAvrg(const vector<double>& Ang) {     vector<double>::const_iterator iter= Ang.begin();          double fD   = *iter;     double fSigD= *iter;      while (++iter != Ang.end())     {         double fDelta= *iter - fD;               if (fDelta < -180.) fD+= fDelta + 360.;         else if (fDelta >  180.) fD+= fDelta - 360.;         else                     fD+= fDelta       ;          fSigD+= fD;     }      double fAvrg= fSigD / Ang.size();      if (fAvrg >= 360.) return fAvrg -360.;     if (fAvrg <  0.  ) return fAvrg +360.;                        return fAvrg      ; } 

It is explained on page 51 of Meteorological Monitoring Guidance for Regulatory Modeling Applications (PDF)(171 pp, 02-01-2000, 454-R-99-005)

Thank you MaR for sending the link as a comment.

If the sampled data is constant, but our sampling device has an inaccuracy with a Von Mises distribution, a unit-vectors calculation will be appropriate.

like image 31
Lior Kogan Avatar answered Sep 19 '22 12:09

Lior Kogan