chainer.functions.mean_absolute_error¶
-
chainer.functions.
mean_absolute_error
(x0, x1)[source]¶ Mean absolute error function.
The function computes the mean absolute error between two variables. The mean is taken over the minibatch. Args
x0
andx1
must have the same dimensions. This function first calculates the absolute value differences between the corresponding elements in x0 and x1, and then returns the mean of those differences.- Parameters
x0 (
Variable
or N-dimensional array) – Input variable.x1 (
Variable
or N-dimensional array) – Input variable.
- Returns
A variable holding an array representing the mean absolute error of two inputs.
- Return type
Example
1D array examples:
>>> x = np.array([1, 2, 3]).astype(np.float32) >>> y = np.array([0, 0, 0]).astype(np.float32) >>> F.mean_absolute_error(x, y) variable(2.) >>> x = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32) >>> y = np.array([7, 8, 9, 10, 11, 12]).astype(np.float32) >>> F.mean_absolute_error(x, y) variable(6.)
2D array example:
In this example, there are 4 elements, and thus 4 errors >>> x = np.array([[1, 2], [3, 4]]).astype(np.float32) >>> y = np.array([[8, 8], [8, 8]]).astype(np.float32) >>> F.mean_absolute_error(x, y) variable(5.5)
3D array example:
In this example, there are 8 elements, and thus 8 errors >>> x = np.reshape(np.array([1, 2, 3, 4, 5, 6, 7, 8]), (2, 2, 2)) >>> y = np.reshape(np.array([8, 8, 8, 8, 8, 8, 8, 8]), (2, 2, 2)) >>> x = x.astype(np.float32) >>> y = y.astype(np.float32) >>> F.mean_absolute_error(x, y) variable(3.5)