Є багато альтернатив, залежно від мети.
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)=x−y(|x|+|y|)/2=2x−y|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)=|x−y|max(|x|,|y|)
d1d∞ may be generalized to
df(x,y)=x−yf(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)=? |x−y|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 x≠0 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θ))=(x2−y2x2+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 |x−y|/|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:
This hints at how flexible the choices are when selecting a way to measure relative differences.