On 2010-01-23 05:52 , Steven D'Aprano wrote:
On Fri, 22 Jan 2010 22:09:54 -0800, Steve Howell wrote:

On Jan 22, 5:12 pm, MRAB<pyt...@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?

Then don't define the median that way. Instead, define the median as the point that minimizes the sum of the absolute deviations of the data from that point (the L1 norm of the deviations, for those familiar with that terminology). For 1-D data on the real number line, that corresponds to sorting the data and taking the middle element (or the artithmetic mean of the middle two in the case of even-numbered data). My definition applies to other spaces, too, that don't have a total order attached to them including the space of angles.

The "circular median" is a real, well-defined statistic that is used for exactly what the OP intends to use it for.

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.

<puts on statistics hat>
Same answer with my statistics hat on or off. :-)
</puts on statistics hat>

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to