绝对错误,相对错误

Last Updated: 2023-08-14 14:31:52 Monday

-- TOC --

Relative Error (RE) — when used as a measure of precision — is the ratio of the absolute error of a measurement to the measurement being taken. In other words, this type of error is relative to the size of the item being measured. RE is expressed as a percentage and has no units.

这两个概念,常用来检查测量或计算的精确度。

设测量值为\(a\),真实值为\(b\),

绝对错误,absolute error:

abs_err = abs(a-b)

相对错误,relative error = absolute error/real value:

rel_err = abs(a-b)/abs(b)

举个例子:

cs231n课程作业中,有一个检查计算的gradient是否正确的接口,里面用到了通过查看相对错误特别小的方式,来确定计算的gradient的正确性:

...
ix = tuple([randrange(m) for m in x.shape])
oldval = x[ix]
x[ix] = oldval + h  # increment by h
fxph = f(x)         # evaluate f(x + h)
x[ix] = oldval - h  # increment by h
fxmh = f(x)         # evaluate f(x - h)
x[ix] = oldval      # reset
grad_numerical = (fxph - fxmh) / (2 * h)
...
rel_error = abs(grad_numerical - grad_analytic) / abs(grad_numerical)

grad_numerical通过导数定义公式计算,一定是正确的,当grad_analytic非常接近前者时,也可认为正确。

本文链接:https://cs.pynote.net/math/202210254/

-- EOF --

-- MORE --