Як обчислити відносну помилку, коли справжнє значення дорівнює нулю?


32

Як обчислити відносну помилку, коли справжнє значення дорівнює нулю?

Скажіть, у мене xtrue=0 і xtest . Якщо я визначаю відносну помилку як:

relative error=xtruextestxtrue

Тоді відносна похибка завжди не визначена. Якщо замість цього я використовую визначення:

relative error=xtruextestxtest

Тоді відносна похибка завжди 100%. Обидва методи здаються марними. Чи є інша альтернатива?


У мене було саме таке питання щодо зміщення параметрів у моделюваннях Монте-Карло, використовуючи ваше перше визначення. Одне з моїх значень параметрів було 0, тому я не обчислював зміщення параметрів для цього конкретного параметра ...
Патрік Куломбе

2
Рішення - не використовувати відносну помилку в цьому випадку.
Marc Claesen

2
Один з варіантів, який відповідає на наміри, якщо не літера вашого запитання, - це використовувати дещо інший захід, який тісно узгоджується з відносною помилкою, коли відносна помилка невелика, наприклад 2(xtruextest)/(|xtrue|+|xtest|) . (Використовуйте 0 коли xtrue=xtest=0 ) Цей конкретний розв'язок є універсальним тим, що він є інваріантним при зміні одиниці вимірювання (оскільки він не передбачає довільних констант).
whuber

@whuber Я думаю, що ви повинні розглянути публікацію цього коментаря як відповідь, оскільки він здається кращим за існуючий.
Срібна рибка

@Silver Ви маєте рацію - прошу вибачення за публікацію відповіді як коментар. Тому я трохи розширив цей коментар у відповідь.
whuber

Відповіді:


39

Є багато альтернатив, залежно від мети.


A common one is the "Relative Percent Difference," or RPD, used in laboratory quality control procedures. Although you can find many seemingly different formulas, they all come down to comparing the difference of two values to their average magnitude:

d1(x,y)=xy(|x|+|y|)/2=2xy|x|+|y|.

This is a signed expression, positive when x exceeds y and negative when y exceeds x. Its value always lies between 2 and 2. By using absolute values in the denominator it handles negative numbers in a reasonable way. Most of the references I can find, such as the New Jersey DEP Site Remediation Program Data Quality Assessment and Data Usability Evaluation Technical Guidance, use the absolute value of d1 because they are interested only in the magnitude of the relative error.


A Wikipedia article on Relative Change and Difference observes that

d(x,y)=|xy|max(|x|,|y|)

d1d may be generalized to

df(x,y)=xyf(x,y)

where the function f depends directly on the magnitudes of x and y (usually assuming x and y are positive). As examples it offers their max, min, and arithmetic mean (with and without taking the absolute values of x and y themselves), but one could contemplate other sorts of averages such as the geometric mean |xy|, the harmonic mean 2/(1/|x|+1/|y|) and Lp means ((|x|p+|y|p)/2)1/p. (d1 corresponds to p=1 and d corresponds to the limit as p.) One might choose an f based on the expected statistical behavior of x and y. For instance, with approximately lognormal distributions the geometric mean would be an attractive choice for f because it is a meaningful average in that circumstance.


Most of these formulas run into difficulties when the denominator equals zero. In many applications that either is not possible or it is harmless to set the difference to zero when x=y=0.

Note that all these definitions share a fundamental invariance property: whatever the relative difference function d may be, it does not change when the arguments are uniformly rescaled by λ>0:

d(x,y)=d(λx,λy).

It is this property that allows us to consider d to be a relative difference. Thus, in particular, a non-invariant function like

d(x,y)=? |xy|1+|y|

simply does not qualify. Whatever virtues it might have, it does not express a relative difference.


The story does not end here. We might even find it fruitful to push the implications of invariance a little further.

The set of all ordered pairs of real numbers (x,y)(0,0) where (x,y) is considered to be the same as (λx,λy) is the Real Projective Line RP1. In both a topological sense and an algebraic sense, RP1 is a circle. Any (x,y)(0,0) determines a unique line through the origin (0,0). When x0 its slope is y/x; otherwise we may consider its slope to be "infinite" (and either negative or positive). A neighborhood of this vertical line consists of lines with extremely large positive or extremely large negative slopes. We may parameterize all such lines in terms of their angle θ=arctan(y/x), with π/2<θπ/2. Associated with every such θ is a point on the circle,

(ξ,η)=(cos(2θ),sin(2θ))=(x2y2x2+y2,2xyx2+y2).

Any distance defined on the circle can therefore be used to define a relative difference.

As an example of where this can lead, consider the usual (Euclidean) distance on the circle, whereby the distance between two points is the size of the angle between them. The relative difference is least when x=y, corresponding to 2θ=π/2 (or 2θ=3π/2 when x and y have opposite signs). From this point of view a natural relative difference for positive numbers x and y would be the distance to this angle:

dS(x,y)=|2arctan(yx)π/2|.

To first order, this is the relative distance |xy|/|y|--but it works even when y=0. Moreover, it doesn't blow up, but instead (as a signed distance) is limited between π/2 and π/2, as this graph indicates:

Figure

This hints at how flexible the choices are when selecting a way to measure relative differences.


Thanks for the comprehensive answer, what do you think is the best reference for this line : "is frequently used as a relative tolerance test in floating point numerical algorithms. The same article also points out that formulas like d1d1 and d∞d∞ may be generalized to"
Hammad Haleem

1
btw, nevermind I found an academic reference for this :) tandfonline.com/doi/abs/10.1080/00031305.1985.10479385
Hammad Haleem

4
Why has this not been selected as the answer? (sorry if this is not an appropriate comment, but this is the better answer by far)
Brash Equilibrium

2
@Brash I appreciate the sentiment. Acceptance is uniquely the province of the original proposer: nobody can override that (except by deleting the accepted post). On some occasions when I feel as you do, I post comments that point out explicitly how and why I think some answers are better or more noteworthy than others. Even if that fails to change anything, such comments may make the material a little more useful or understandable to future readers: and that, ultimately, is the point of our work on this site.
whuber

1
@KutalmisB Thank you for noticing that: the "min" doesn't belong there at all. It looks like it may have been a vestige of a more complex formula that handled all possible signs of x and y that I later simplified. I have removed it.
whuber

11

First, note that you typically take the absolute value in computing the relative error.

A common solution to the problem is to compute

relative error=|xtruextest|1+|xtrue|.

3
This is problematic in that it varies depending on the units of measure chosen for the values.
whuber

1
That's absolutely true. This isn't a perfect solution to the problem, but it is a common approach that works reasonably well when x is well scaled.
Brian Borchers

Could you elaborate in your answer on what you mean by "well scaled"? For instance, suppose the data arise from calibration of an aqueous chemical measurement system designed for concentrations between 0 and 0.000001 moles/liter which can achieve a precision of, say, three significant digits. Your "relative error" would therefore be constantly zero except for obviously erroneous measurements. In light of this, how exactly would you rescale such data?
whuber

1
Your example is one where the variable isn't well scaled. By "well scaled", I mean that that variable is scaled so that it takes on values in a small range (of e.g. a couple of orders of magnitude) near 1. If your variable takes on values over many orders of magnitude than you've got more serious scaling issues and this simple approach isn't going to be adequate.
Brian Borchers

2
Any reference for this approach? The name of this method? Thank you.
CroCo

0

I was a bit confused on this for a while. In the end, its because if you are trying to measure relative error with respect to zero then you are trying to force something that simply does not exist.

If you think about it, you're comparing apples to oranges when you compare relative error to the error measured from zero, because the error measured from zero is equivalent to the measured value (that's why you get 100% error when you divide by the test number).

For example, consider measuring error of gauge pressure (the relative pressure from atmospheric) vs absolute pressure. Say that you use an instrument to measure the gauge pressure at perfect atmospheric conditions, and your device measured atmospheric pressure spot on so that it should record 0% error. Using the equation you provided, and first assuming we used the measured gauge pressure, to calculate relative error:

relative error=Pgauge,truePgauge,testPgauge,true
Then Pgauge,true=0 and Pgauge,test=0 and you do not get 0% error, instead it is undefined. That is because the actual percent error should be using the absolute pressure values like this:
relative error=Pabsolute,truePabsolute,testPabsolute,true
Now Pabsolute,true=1atm and Pabsolute,test=1atm and you get 0% error. This is the proper application of relative error. The original application that used gauge pressure was more like "relative error of the relative value" which is a different thing than "relative error". You need to convert the gauge pressure to absolute before measuring the relative error.

The solution to your question is to make sure you are dealing with absolute values when measuring relative error, so that zero is not a possibility. Then you are actually getting relative error, and can use that as an uncertainty or a metric of your real percent error. If you must stick with relative values, than you should be using absolute error, because the relative (percent) error will change depending on your reference point.

It's hard to put a concrete definition on 0... "Zero is the integer denoted 0 that, when used as a counting number, means that no objects are present." - Wolfram MathWorld http://mathworld.wolfram.com/Zero.html

Feel free to nit pick, but zero essentially means nothing, it is not there. This is why it does not make sense to use gauge pressure when calculating relative error. Gauge pressure, though useful, assumes there is nothing at atmospheric pressure. We know this is not the case though, because it has an absolute pressure of 1 atm. Thus, the relative error with respect to nothing, just does not exist, it's undefined.

Feel free to argue against this, simply put: any quick fixes, such as adding one to the bottom value, are faulty and not accurate. They can be still be usefully if you are simply trying to minimize error. If you are trying to make accurate measurements of uncertainty though, not so much...


0

MAPE Formula

Finding MAPE,

It is very debatable topic and many opensource contributors have discussed on the above topic. The most efficient approach till now is followed by the developers. Please refer to this PR to know more.

Використовуючи наш веб-сайт, ви визнаєте, що прочитали та зрозуміли наші Політику щодо файлів cookie та Політику конфіденційності.
Licensed under cc by-sa 3.0 with attribution required.