什么是数值最好的方法来计算平均值 [英] What's the numerically best way to calculate the average

查看:214
本文介绍了什么是数值最好的方法来计算平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的计算平均值的方法?有了这个问题,我想知道用于计算平均值的算法在数值意义上是最好的。它应该有最小的舍入误差,不应该对上溢或下溢等敏感。

what's the best way to calculate the average? With this question I want to know which algorithm for calculating the average is the best in a numerical sense. It should have the least rounding errors, should not be sensitive to over- or underflows and so on.

谢谢。

其他信息:增量方法首选,因为值的数量可能不适合RAM(对大于4 GB的文件进行多个并行计算)。

Additional information: incremental approaches preferred since the number of values may not fit into RAM (several parallel calculations on files larger than 4 GB).

推荐答案

您可以查看 http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.43.3535 (Nick Higham,The accuracy of floating point summation,SIAM Journal of Scientific Computation, 1993)。

You can have a look at http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.43.3535 (Nick Higham, "The accuracy of floating point summation", SIAM Journal of Scientific Computation, 1993).

如果我记得正确,如果所有数字都是正的,补偿求和(Kahan求和)是好的,至少排序它们并按升序添加有非常非常多的数字)。如果一些数字是积极的,有些是负数,那么这个故事会更加复杂,这样你就可以取消。在这种情况下,有一个参数可以按降序来添加它们。

If I remember it correctly, compensated summation (Kahan summation) is good if all numbers are positive, as least as good as sorting them and adding them in ascending order (unless there are very very many numbers). The story is much more complicated if some numbers are positive and some are negative, so that you get cancellation. In that case, there is an argument for adding them in descending order.

这篇关于什么是数值最好的方法来计算平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆