Page 1 of 1
Weighted mean of angles
Posted: Thu Aug 12, 2004 2:54 pm
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?
Posted: Thu Aug 12, 2004 4:40 pm
by Peijen
PI?
Posted: Thu Aug 12, 2004 5:00 pm
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.
Posted: Thu Aug 12, 2004 11:20 pm
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)
Posted: Thu Aug 12, 2004 11:26 pm
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.
Re: Weighted mean of angles
Posted: Thu Aug 12, 2004 11:28 pm
by quantus
George wrote:I have a group of several closely spaced angles...
Posted: Thu Aug 12, 2004 11:50 pm
by Jonathan
Subtracting 180 or 90 is cleaner than subtracting the first angle.
Posted: Fri Aug 13, 2004 2:07 am
by Jason
Simple use quaternions.
Posted: Fri Aug 13, 2004 2:08 am
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.
Posted: Fri Aug 13, 2004 3:31 pm
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.
Posted: Fri Aug 13, 2004 3:46 pm
by Guest
just add 2
Posted: Fri Aug 13, 2004 5:47 pm
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.