MSE¶
Description¶
Calculating the error and the gradient on the batch: (mean squared error - MSE), which is the average sum of the squared differences between the network responses and the real labels.
It is used in regression tasks.
The error function formula is:
MSE = \frac{1}{N}\sum_{i=1}^N(y_i-y_i^p)^2
where
N - number of objects in the sample;
y_i - real value for the i-th object;
y_i^p - predicted value for the i-th object.
Initializing¶
def __init__(self):
Parametrs
-
Explanations
-
Examples¶
Necessary imports:
import numpy as np
from PuzzleLib.Backend import gpuarray
from PuzzleLib.Cost import MSE
Info
gpuarray
is required to properly place the tensor in the GPU.
is required to properly place the tensor in the GPU.
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 tensors is the size of the batch
Initializing the error function:
mse = MSE()
Calculating the error and the gradient on the batch:
error, grad = mse(predictions, targets)