Table of Contents

Class ExponentialLoss<T>

Namespace
AiDotNet.LossFunctions
Assembly
AiDotNet.dll

Implements the Exponential Loss function, commonly used in boosting algorithms.

public class ExponentialLoss<T> : LossFunctionBase<T>, ILossFunction<T>

Type Parameters

T

The numeric type used for calculations (e.g., float, double).

Inheritance
ExponentialLoss<T>
Implements
Inherited Members
Extension Methods

Remarks

For Beginners: Exponential Loss is a loss function that heavily penalizes incorrect predictions, especially those that are far off from the true values.

The formula is: exp(-y * f(x)) Where:

  • y is the true label (usually -1 or 1 for binary classification)
  • f(x) is the model's prediction

Key properties:

  • It grows exponentially as the error increases
  • Correct predictions with high confidence result in values close to zero
  • Incorrect predictions result in very large values
  • It's especially sensitive to outliers and misclassifications

Exponential Loss is primarily used in:

  • AdaBoost and other boosting algorithms
  • Ensemble methods that need to focus on hard examples
  • Learning problems where avoiding mistakes is critical

The exponential nature makes the model pay more attention to difficult examples and outliers compared to other loss functions like hinge loss or log loss.

Methods

CalculateDerivative(Vector<T>, Vector<T>)

Calculates the derivative of the Exponential Loss function.

public override Vector<T> CalculateDerivative(Vector<T> predicted, Vector<T> actual)

Parameters

predicted Vector<T>

The predicted values vector.

actual Vector<T>

The actual (ground truth) values vector, typically -1 or 1.

Returns

Vector<T>

A vector containing the derivatives of the exponential loss with respect to each prediction.

CalculateLoss(Vector<T>, Vector<T>)

Calculates the Exponential Loss between predicted and actual values.

public override T CalculateLoss(Vector<T> predicted, Vector<T> actual)

Parameters

predicted Vector<T>

The predicted values vector.

actual Vector<T>

The actual (ground truth) values vector, typically -1 or 1.

Returns

T

The exponential loss value.

CalculateLossAndGradientGpu(IGpuTensor<T>, IGpuTensor<T>)

Calculates both Exponential loss and gradient on GPU in a single efficient pass.

public override (T Loss, IGpuTensor<T> Gradient) CalculateLossAndGradientGpu(IGpuTensor<T> predicted, IGpuTensor<T> actual)

Parameters

predicted IGpuTensor<T>

The predicted GPU tensor from the model.

actual IGpuTensor<T>

The actual (target) GPU tensor.

Returns

(T Loss, IGpuTensor<T> Gradient)

A tuple containing the loss value and gradient tensor.