pyml.neural_network.loss.mean_absolute_error.MeanAbsoluteError#
- class MeanAbsoluteError[source]#
Bases:
_Loss
Mean Squared Error loss function.
This class defines the forward and backward pass computations for calculating the mean squared error loss and its gradient with respect to the predicted values.
- Variables:
dinputs (numpy.ndarray) – Gradient of the loss with respect to the predicted values.
Methods
__init__
Compute the backward pass to calculate the gradient of the loss with respect to the predicted values.
Calculate the total loss based on model output and ground truth values.
Calculate the accumulated loss over a training pass.
Compute the forward pass of the mean squared error loss.
Calculate the regularization loss based on L1 and L2 regularization terms of the trainable layers' weights and biases.
Reset the accumulated loss variables for a new training pass.
Set the list of trainable layers for loss calculations.
- backward(dvalues, y_true)[source]#
Compute the backward pass to calculate the gradient of the loss with respect to the predicted values.
- Return type:
- Parameters:
dvalues (numpy.ndarray) – Gradient of the loss with respect to the predicted values.
y_true (numpy.ndarray) – Ground truth values.
- calculate(output, y, *, include_regularization=False)#
Calculate the total loss based on model output and ground truth values.
- Return type:
- Parameters:
output (numpy.ndarray) – Predicted output from the model.
y (numpy.ndarray) – Ground truth values.
include_regularization (bool, optional) – Whether to include regularization loss, by default False.
- Returns:
Total loss value if include_regularization is False, or a tuple of data and regularization loss values if include_regularization is True.
- Return type:
numpy.ndarray or tuple
- calculate_accumulated(*, include_regularization=False)#
Calculate the accumulated loss over a training pass.
- forward(y_pred, y_true)[source]#
Compute the forward pass of the mean squared error loss.
- Return type:
ndarray
- Parameters:
y_pred (numpy.ndarray) – Predicted output from the model.
y_true (numpy.ndarray) – Ground truth values.
- Returns:
Array of sample-wise mean squared error losses.
- Return type:
numpy.ndarray
- regularization_loss()#
Calculate the regularization loss based on L1 and L2 regularization terms of the trainable layers’ weights and biases.