Skip to content

Abs

Description

The loss function that calculates the mean absolute error (mean absolute error - MAE), which is the average sum of the absolute differences between network responses and real labels.

It is applied in regression tasks and is resistant to outliers.

The error function formula is:

MAE = \frac{1}{N}\sum_{i=1}^N|y_i-y_i^p|

where

N - number of objects in the sample;
y_i - real value for the i-th object;
y_i^p - value predicted by the model for the i-th object.

Initializing

def __init__(self):

Parameters

-

Explanations

-

Examples


Necessary imports:

import numpy as np
from PuzzleLib.Backend import gpuarray
from PuzzleLib.Cost import Abs

Info

gpuarray is required to properly place the tensor in the GPU.

Synthetic target and prediction tensors:

targets = gpuarray.to_gpu(np.random.randn(10, 10).astype(np.float32))
predictions = gpuarray.to_gpu(np.random.randn(10, 10).astype(np.float32))

Important

Please remember that the first dimension of target and prediction tensors is the size of the batch.

Initializing the error function:

mae = Abs()

Calculating the error and the gradient on the batch:

error, grad = mae(predictions, targets)