medians for degree measurements

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Jan 23 06:52:43 EST 2010


On Fri, 22 Jan 2010 22:09:54 -0800, Steve Howell wrote:

> On Jan 22, 5:12 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
>> Steve Howell wrote:
>> > I just saw the thread for medians, and it reminded me of a problem
>> > that I need to solve.  We are writing some Python software for
>> > sailing, and we need to detect when we've departed from the median
>> > heading on the leg.  Calculating arithmetic medians is
>> > straightforward, but compass bearings add a twist.
[...]
> I like this implementation, and it would probably work 99.9999% of the
> time for my particular use case.  The only (very contrived) edge case
> that I can think of is when you have 10 bearings to SSW, 10 bearings to
> SSE, and the two outliers are unfortunately in the NE and NW quadrants. 
> It seems like the algorithm above would pick one of the outliers.

The trouble is that median of angular measurements is not a meaningful 
concept. The median depends on the values being ordered, but angles can't 
be sensibly ordered. Which is larger, 1 degree north or 359 degrees? Is 
the midpoint between them 0 degree or 180 degree?

The median of the number line 0 <= x <= 360 is 180, but what's the median 
of the circle 0 deg <= theta <= 360 deg? With no end points, it's 
meaningless to talk about the middle.

For this reason, I expect that taking the median of bearing measurements 
isn't well defined. You can probably get away with it so long as the 
bearings are "close", where "close" itself is ill-defined.

In any case, this isn't a programming problem, it's a mathematics 
problem. I think you're better off taking it to a maths or statistics 
forum, and see what they say.


-- 
Steven



More information about the Python-list mailing list