Kyle->GetThoughts();



Running Average Equation
9 April 2007 @ 09:58 PM MST
Current Music: Death Cab For Cutie - I Will Follow You Into The Dark
Current Mood: Good
So I've done the algebra for this little equation about 6 times in the last year, so I figured I'd put it here so I won't have to do it again, and so anyone else in the world can get it, since I haven't been able to find it online.

Suppose you need to calculate an average value; but it's the average of A LOT of values, so many that you can't just add them all up and divide because round-off errors will hurt if you keep multiplying up a huge number every time. You can keep a running average. One benefit is that you have the average of all values so far seen at every step of the way, and you never need to calculate a really big number, you do have to keep track of the number of values already entered, but that's simple enough:

new_ave = cur_ave - (cur_ave / num_vals) + (new_val / num_vals)
-- where num_vals = the number of values input including the new_val

Example:
For values 1, 3, 8, 4
0 - (0/1) + (1/1) = 1
1 - (1/2) + (3/2) = 2
2 - (2/3) + (8/3) = 4
4 - (4/4) + (4/4) = 4

[This Entry]

Replies: 2 Comments

 On Tuesday, April 10th @ 07:09, Courtney said:
That is so thoughtful of you! wink

 On Tuesday, April 10th @ 07:13, Courtney said:
So very kind of you! ;-)