Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

algorithm - Averaging angles... Again

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

[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}cdotsum_{j=1}^n

sinalpha_j, frac{1}{n}cdotsum_{j=1}^n cosalpha_j ight)

using the atan2 variant of the arctangent function, or

M alpha = argleft(frac{1}{n}cdotsum_{j=1}^n

exp(icdotalpha_j) ight)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...