Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

 Open In Colab

True Absolute Error

The True Absolute Error is the absolute difference between the true value and an approximation.

Et=∣True−Approximate∣E_t = |\text{True} - \text{Approximate}|

This metric is only useful when the true value is known.

Example: What is the derivative of 2sin⁡(x)2\sin(x) at x=0x=0?

Recall the definition of a derivative:

ddxf(x)=lim⁡Δx→0f(x+Δx)−f(x)Δx\frac{\mathrm{d}}{\mathrm{d}x} f(x) = \lim_{\Delta x \to 0} \frac{f(x+\Delta x) - f(x)}{\Delta x}

The true value of the derivative of 2sin⁡(x)2\sin(x) is 2cos⁡(x)2\cos(x).

The true value is: 2.0

Approximating the derivative

We can define a function to approximate the derivative using a finite Δx\Delta x, and use it with Δx=0.1\Delta x = 0.1, to find the approximate value and the true absolute error:

The approximate value is: 1.996668332936563
The true absolute error is: 0.003331667063436905

True Relative Error

Often, the absolute error is not as useful as the True Relative Error, because it does not account for the magnitude of the value. For example, a 1-meter error in GPS is insignificant for a long road trip but critical for a self-driving car.

The true relative error is defined as:

ϵt=EtTrue\epsilon_t = \frac{E_t}{\text{True}}

or as a percentage:

ϵt(%)=EtTrue×100%\epsilon_t (\%) = \frac{E_t}{\text{True}} \times 100\%

Example: What is the relative error from the previous calculation?

The true relative error is: 0.0016658335317184525

Approximate Absolute and Relative Error

What if we don’t know the true value? Numerical methods often have a tunable parameter that controls accuracy (like Δx\Delta x above). We can estimate the error by comparing sequential approximations, using the better approximation in place of the true value.

Ea=∣Better approximation−Approximation∣E_a = |\text{Better approximation} - \text{Approximation}|
ϵa=EaBetter approximation\epsilon_a = \frac{E_a}{\text{Better approximation}}

Example: Use a smaller step size to find the approximate errors.

This is the typical use-case you will encounter in numerical methods since the true function is not usually known.

Except for root finders because we are looking for xx for which f(x)=0f(x)=0!

Commonly the difference is disregarded and the meaning has to be taken in context.

The approximate absolute error is: 0.0032983338967698117
The approximate relative error is: 0.001649194434821387
Recall, The true absolute and relative errors were: 0.003331667063436905, and 0.0016658335317184525

Tolerance

So how can we know when we have an answer that is good enough? We can’t really (unless we know what the ‘true’ answer is!). Instead, the best we can do is compare our error indicators to a tolerance:

  • Absolute Tolerance (TolaTol_a): The threshold below which the absolute error is considered acceptable.

  • Relative Tolerance (TolrTol_r): The threshold below which the relative error is considered acceptable.

For approximate errors that are based on successive guesses, satisfying the tolerances doesn’t actually indicate we’ve found the right solution, just that our esimate is no longer improving.

Pseudocode Concept

parameter = initial_value
while True:
    result = run_algorithm(parameter)
    error = calculate_error(result, previous_result)
    if error < tolerance:
        break
    parameter = reduce_parameter(parameter)

Exploring EaE_a and ϵa\epsilon_a as a function of Δx\Delta x

Lets see how the errors behave with decreasing step size. One might expect the error to approach zero as Δx→0\Delta x \rightarrow 0.

Is this what you observe? What happens at Δx=10−8\Delta x = 10^{-8}? Why? Checking the avlue of the function evaulations might shed some light on this!

Loading...