필터 지우기
필터 지우기

Arithmetical mean above max

조회 수: 2 (최근 30일)
Claire
Claire 2013년 8월 16일
Is it possible that, due to precision matter, arithmetical mean of an array is above max of same array ?
Is Matlab then limiting mean to min-max interval (at least for display) ?
Regards Claire
  댓글 수: 1
Image Analyst
Image Analyst 2013년 8월 18일
I doubt it - have you actually observed this? If so, what is the code?

댓글을 달려면 로그인하십시오.

답변 (3개)

David Sanchez
David Sanchez 2013년 8월 16일
The mean value ( either geometric or arithmetic ) of an array can never be above the maximum value of the array. Matlab does not have to limit the result of the operation.

Claire
Claire 2013년 8월 16일
Is there no case where precision can produce some error as
mean = 1.000000012
max = 1.00
  댓글 수: 1
David Sanchez
David Sanchez 2013년 8월 16일
I don't know of any case. However, if dealing with very small numbers, the result will be prone to some error. In any case, achieving an average of a set above the maximum value of that set, (beside being against its definition) is extremely unlikely even when working with very small numbers.

댓글을 달려면 로그인하십시오.


Jan
Jan 2013년 8월 17일
편집: Jan 2013년 8월 17일
Matlab's mean(x) uses the calculation sum(x) / numel(x). Therefore it suffers from the numerical instabilities of sum:
x = [1e17, 1, -1e17]
sum(x)
This replies 0 instead of 1, because the limited floating point precision does not allow to distinguish 1e17 and 1e17+1. This means, that in sum() small values can vanish, when they are surrounded by large numbers with different sign, and of course this matters partial sums also. But this cannot lead to the situation, that the sum is larger than numel(x)*max(x), except if you reach the overflow such that sum() replies Inf. Then sum(x)/n differs from sum(x/n).
v = [realmax, realmax]
mean(v)
(What does this reply? I cannot check this currently.)
So perhaps this would be a better implementation of MEAN:
function m = meanX(x)
m = sum(x) / numel(x);
if ~isfinite(m)
m = sum(x / numel(x));
end
A furter effect appears for large arrays, when Matlab distributes the partial sums to different threads. Then the floating point effects depend on the number of cores also, but here the sum cannot exceed numel(x)*max(x) also, except for the above mentioned exception.
See FEX: XSum for a summation with higher accuracy.
  댓글 수: 2
Image Analyst
Image Analyst 2013년 8월 18일
v = [realmax, realmax]
mean(v)
says "ans = inf".
Jan
Jan 2013년 8월 18일
Thanks, Image Analyst.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by