Weighted mean of angles

For general rambling.
Post Reply
George
Veteran Doodler
Posts: 1267
Joined: Sun Jul 18, 2004 12:26 am
Location: Arlington, VA

Weighted mean of angles

Post by George »

Work-related question:

I have a group of several closely spaced angles, and an uncertainty/accuracy estimate for each angle. I want to find the average of the angles, and I want the average weighted by the uncertainties. For most quantities it's just Sum(i/uncertainty(i))/Sum(1/uncertainty(i), but for angles the simple implementation breaks down around 0 degrees (1+359/2 = 180 != mean). Is there an elegant and strightforward way to calculate a weighted mean of a wrapped quantity?

My current hack fix is to subtract off the first angle from all of the angles before applying the formula, thus getting deltas hopefully between -180 and 180. Then after computing the average of the deltas, I add the base angle back on. This seems to work, but is there a better way?
I feel like I just beat a kitten to death... with a bag of puppies.

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post by Peijen »

PI?

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

Yes. You're not trying to average scalars, you're trying to average vectors. Treat your weighted angles like vectors and you won't have this problem.

quantus
Tenth Dan Procrastinator
Posts: 4891
Joined: Fri Jul 18, 2003 3:09 am
Location: San Jose, CA

Post by quantus »

Without resorting to vectors, george is better off not introducing the discontinuity from 359.999.. to 0 until after the average is done. That means, use -1 for 359 for purposes of averaging, then make the number fit [0,360)
Have you clicked today? Check status, then: People, Jobs or Roads

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

There will be a discontinuity at -90 or -180 or wherever you choose to push it back to. Making no assumptions about your dataset, the only robust way to do this is to perform vector addition.

If you can guarantee all your angles will be within a single quadrant or two adjacent quadrants, then you can make these simplifications.

quantus
Tenth Dan Procrastinator
Posts: 4891
Joined: Fri Jul 18, 2003 3:09 am
Location: San Jose, CA

Re: Weighted mean of angles

Post by quantus »

George wrote:I have a group of several closely spaced angles...
Have you clicked today? Check status, then: People, Jobs or Roads

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

Subtracting 180 or 90 is cleaner than subtracting the first angle.

Jason
Veteran Doodler
Posts: 1520
Joined: Fri Jul 18, 2003 12:53 am
Location: Fairfax, VA

Post by Jason »

Simple use quaternions.

Jason
Veteran Doodler
Posts: 1520
Joined: Fri Jul 18, 2003 12:53 am
Location: Fairfax, VA

Post by Jason »

Seriously though, don't you remember from physics lab, you can't just add uncertainties. I think you're supposed to take the square root of the sum of the squares of the uncertainties.

George
Veteran Doodler
Posts: 1267
Joined: Sun Jul 18, 2004 12:26 am
Location: Arlington, VA

Post by George »

Dwindlehop wrote:Yes. You're not trying to average scalars, you're trying to average vectors. Treat your weighted angles like vectors and you won't have this problem.
So does that mean use unit vectors with the appropriate angles? That seems to work for the couple cases I just sketched. Still, I think I'll avoid doing that, since computing sinusoids is a lot more expensive than its probably worth.
Dwindlehop wrote:Subtracting 180 or 90 is cleaner than subtracting the first angle.
Hmm, I'll need to play around to figure out why this works. Subtracting the first angle seemed obvious because the resulting angles were all plus or minus a couple degrees. Once I convince myself subtracting a constant works, I'll probably use it instead.
Peijen wrote:PI?
Yes, of course, all of the calculations are actually done in radians, but I find degrees easier to think about.
Jason wrote:Seriously though, don't you remember from physics lab, you can't just add uncertainties. I think you're supposed to take the square root of the sum of the squares of the uncertainties.
While I rarely admit to remembering anything from physics, I do remember how to compute the uncertainty of a calculated value. However, this is a different problem. I'm trying to compute the most-likely mean angle by minimizing chi-squared.
I feel like I just beat a kitten to death... with a bag of puppies.

Guest

Post by Guest »

just add 2

Jonathan
Grand Pooh-Bah
Posts: 6722
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

By subtracting 180 or 90, what I really mean is force your values into the range [-90,270) or [-180,180). Move the discontinuity away from your angles.

Regarding sinusoids: premature optimization is the root of all evil.

Yes, unit vectors. Scaling them by your uncertainties is bonus.

2 has certain qualities, I have to admit.

Post Reply