Binary cross-entropy
Computes the binary cross-entropy loss for binary classification tasks.Vector of true binary labels (0 or 1)
Vector of predicted probabilities (values between 0 and 1)
The binary cross-entropy loss averaged over all samples
Template constraints
Tmust satisfy theArithmeticconcept (any arithmetic type)
Exceptions
Throwsstd::invalid_argument if y_true and y_pred have different sizes.
Implementation details
Predicted probabilities are clamped to the range[1e-12, 1 - 1e-12] to prevent log(0) errors.
Example
Multiclass cross-entropy
Computes the categorical cross-entropy loss for multiclass classification tasks.2D vector of true labels in one-hot encoded format. Outer dimension represents samples, inner dimension represents classes.
2D vector of predicted class probabilities. Outer dimension represents samples, inner dimension represents class probabilities.
The categorical cross-entropy loss averaged over all samples
Template constraints
Tmust satisfy theArithmeticconcept (any arithmetic type)
Exceptions
Throwsstd::invalid_argument if:
- Outer dimensions of
y_trueandy_preddiffer - Inner dimensions of any sample in
y_trueandy_preddiffer
Implementation details
Predicted probabilities are clamped to the range[1e-12, 1 - 1e-12] to prevent log(0) errors.
Example
Hinge loss
Computes the hinge loss for binary classification, commonly used with Support Vector Machines (SVM).Vector of true binary labels (-1 or +1)
Vector of predicted decision values (raw scores, not probabilities)
The hinge loss averaged over all samples
Template constraints
Tmust satisfy theArithmeticconcept (any arithmetic type)
Exceptions
Throwsstd::invalid_argument if y_true and y_pred have different sizes.
Example
Squared hinge loss
Computes the squared hinge loss, which penalizes misclassifications more heavily than standard hinge loss.Vector of true binary labels (-1 or +1)
Vector of predicted decision values (raw scores, not probabilities)
The squared hinge loss averaged over all samples
Template constraints
Tmust satisfy theArithmeticconcept (any arithmetic type)
Exceptions
Throwsstd::invalid_argument if y_true and y_pred have different sizes.