Forum > Discussion Forum
Difference?
sunu:
Lets say we have some Credit and Runtime data from a few tasks and want to calculate Credit/sec. I see three possibilities:
1) sum(Credit) / sum(Runtime)
2) avg(Credit) / avg(Runtime)
3) avg(Credit / Runtime)
In the 3rd we calculate Credit/sec for each task and then we take the average of those.
1 and 2 give me the same result but not 3. What is the difference?
Miep:
You mean, apart from the random number generator called 'Credit new'?
I'll look inti the maths tomorrow.
[edit]1 and 2 are identical because avarage is sum divided by number of elements. as number of elements is identical they cancel each other out.
I need pen and paper for 3.
sunu:
Yes, don't think about that stuff. Let's say we have x and y. Why sum(x) / sum(y) or avg(x) / avg(y) is different from avg(x / y)?
Miep:
yes, sorry I did understand it as a purely mathematical question of formulas and why they produce different results.
probably to do with the way the sums are done and in what order the errr. operations are performed. but I'll have to write it out on paper and have a close look.
Jason G:
--- Quote from: sunu on 09 Jun 2011, 04:45:32 pm ---Yes, don't think about that stuff. Let's say we have x and y. Why sum(x) / sum(y) or avg(x) / avg(y) is different from avg(x / y)?
--- End quote ---
How much different ? with just a few numbers is it closer than if there are a lot ? If it's a fractional difference there are several opportunities for accumulated sum and rounding errors, which can look like random results, and changing the order of computation like that can make a big difference.
Keeping the division to a single operation at the last step will be far more accurate if you have many results, and there are ways to further improve the result accuracy by not summing long strings of numbers in a line too. summing in blocks of SQRT(N), then summing those block results, minimises accumulated roundoff error in the sums (one way).
[Edit:] Looking at the third equation with that in mind, it would basically maximise the accumulated summing error by adding smaller values, so the error has more effect on the average, Also having applied truncation to every element during the divisions ... So yeah, yuck
If you have trouble sleeping sometime you can read this:
What Every Computer Scientist Should Know about Floating Point Arithmetic, by David Goldberg
Navigation
[0] Message Index
[#] Next page
Go to full version