/**
 * This function calculates the loss between the given labels and predictions.
 *
 * @param labels A list of labels.
 * @param predictions A list of predicted values.
 * @return The loss value.
 * @throws IllegalArgumentException If the lengths of labels and predictions are not equal.
 * @throws IllegalArgumentException If labels or predictions contain non-numeric values.
 */
fun calculateLoss(labels: List<Double>, predictions: List<Double>): Double {

    if (labels.size != predictions.size) {
        throw IllegalArgumentException("Lengths of labels and predictions must be equal")
    }

    var loss = 0.0

    for ((index, label) in labels.withIndex()) {
        val pred = predictions[index]
        if (!label.isFinite() || !pred.isFinite()) {
            throw IllegalArgumentException("Labels and predictions must contain numeric values")
        }

        if (label < 0 || pred < 0) {
            loss -= label * pred
        } else {
            loss += label * pred
        }
    }

    return loss
}
/**
 * This function calculates the loss between the given labels and predictions.
 *
 * @param labels A list of labels.
 * @param predictions A list of predicted values.
 * @return The loss value.
 * @throws IllegalArgumentException If the lengths of labels and predictions are not equal.
 * @throws IllegalArgumentException If labels or predictions contain non-numeric values.
 */
fun calculateLoss(labels: List<Double>, predictions: List<Double>): Double {
/**
 * This function calculates the loss between the given labels and predictions.
 *
 * @param labels A list of labels.
 * @param predictions A list of predicted values.
 * @return The loss value.
 * @throws IllegalArgumentException If the lengths of labels and predictions are not equal.
 * @throws IllegalArgumentException If labels or predictions contain non-numeric values.
 */
fun calculateLoss(labels: List<Double>, predictions: List<Double>): Double {

    if (labels.size != predictions.size) {
        throw IllegalArgumentException("Lengths of labels and predictions must be equal")
    }

    var loss = 0.0

    for ((index, label) in labels.withIndex()) {
        val pred = predictions[index]
        if (!label.isFinite() || !pred.isFinite()) {
            throw IllegalArgumentException("Labels and predictions must contain numeric values")
        }

        if (label < 0 || pred < 0) {
            loss -= label * pred
        } else {
            loss += label * pred
        }
    }

    return loss
}