I have two functions $A(t)$ und $B(t)$ (given as a set of values) and I want to quantify how similar they are. In context: I want to check how good some approximation regarding the solution of an integro-differential equation is and it depends on some values $\gamma$. In order to compare the accuracy of this approximation, I want to compare the actual result with the approximation for different values of $\gamma$ in a given timeframe $T$. My approach was to use the maximal relative error, namely $\max_{t\in T}|\frac{A(t)-B(t)}{B(t)}|$, whereas $A(t)$ denotes the approximation and $B(t)$ is the actual solution.

However, it doesn't seem to be an appropriate way, as $B(t)$ as well as $A(t)$ become zero for some time $t\in T$, the relativ error explodes.

Is there any other error i could use to avoid this problem? As the range of $A(t)$ and $B(t)$ varies between one and minus one (most of the time), the absolute error wouldn't be a good method too....

Thanks already!

  • $\begingroup$ what about $\left| \frac{A(t)-B(t)}{A(t)+B(t)} \right|$ If both have the same value the error calculated is 0 (assuming you correctly handle the case when both are zero), if either $A(t)$ or $B(t)$ is zero the error is one, with all other values between 0 and 1. $\endgroup$ – James Arathoon Mar 13 '18 at 12:44
  • $\begingroup$ Sorry I didn't allow for the fact that A(t) and B(t) can take on positive and negative values. $\endgroup$ – James Arathoon Mar 13 '18 at 12:57
  • $\begingroup$ Yes...thats the problem, but thanks anyways! $\endgroup$ – Martin Mar 13 '18 at 13:52

Why not use a standard $2$-norm? If $A_t$ and $B_t$ are given as a set of discrete values with $t\in T$. Then the error, $\varepsilon$, can be computed as

$$ \varepsilon = \|A-B\|_{2} = \sqrt{\sum\limits_{t\in T} |A_t-B_t|^2}$$

I'm not exactly sure why you say that the absolute error wouldn't be a good method, but I hope this helps.

If you wish to have a "normalized" error measure, then you can either normalize with respect to the number of points, i.e. $$\varepsilon = \frac{1}{|T|} \|A-B\|_2$$ where $|T| = \sum_{t\in T}1$ is the number of points in the set $T$. Or you could normalize with respect to the total size of $A$ and $B$, i.e. $$\varepsilon = \frac{1}{\sum\limits_{t\in T}(|A_t|+|B_t|)} \|A-B\|_2.$$

There is no one "correct" way, it depends on the application. You can also try experimenting by replacing the $2$-norms above with max-norms (also known as $\infty$-norm) as you originally used, i.e. replace $\|\cdot\|_2$ with $$\|A-B\|_\infty = \max\limits_{t\in T}|A_t-B_t|.$$

  • $\begingroup$ Thanks! Shouldn't I divide by the amount of points i've taken into account? Also: in the end the function itself is very slowly changing and I will plot it in a log log plot. So I think the absolute error wouldnt work, would it? $\endgroup$ – Martin Mar 13 '18 at 13:55
  • $\begingroup$ @Martin "Should" you? There are no rules like that; it depends on what you wish to achieve. In some cases it may make sense to normalize by dividing by the number of points. It really depends on what the desired goal is. $\endgroup$ – Eff Mar 13 '18 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.