pyml.neural_network.loss.binary_cross_entropy.BinaryCrossentropy#
- class BinaryCrossentropy[source]#
Bases:
_Loss
Binary Cross-Entropy loss function for binary classification tasks.
This class defines the forward and backward pass computations for calculating the Binary Cross-Entropy 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 Binary Cross-Entropy 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, containing binary labels.
- 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 Binary Cross-Entropy loss.
- Return type:
ndarray
- Parameters:
y_pred (numpy.ndarray) – Predicted output from the model, representing class probabilities.
y_true (numpy.ndarray) – Ground truth values, containing binary labels.
- Returns:
Array of sample-wise binary cross-entropy 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.