Table of Contents

Class QuantileLoss<T>

Namespace
AiDotNet.LossFunctions
Assembly
AiDotNet.dll

Implements the Quantile loss function for quantile regression.

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

Type Parameters

T

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

Inheritance
QuantileLoss<T>
Implements
Inherited Members
Extension Methods

Remarks

For Beginners: Quantile loss helps predict specific percentiles of data rather than just the average.

For example:

  • With quantile=0.5, it predicts the median value (50th percentile)
  • With quantile=0.9, it predicts the 90th percentile
  • With quantile=0.1, it predicts the 10th percentile

This is useful when you care more about certain parts of the distribution, such as:

  • Predicting worst-case scenarios (high quantiles)
  • Ensuring predictions don't fall below a certain threshold (low quantiles)
  • Creating prediction intervals (by predicting multiple quantiles)

The loss function applies different penalties for overestimation versus underestimation, which forces the model to learn the specific quantile rather than just the average.

Constructors

QuantileLoss(double)

Initializes a new instance of the QuantileLoss class.

public QuantileLoss(double quantile = 0.5)

Parameters

quantile double

The quantile value between 0 and 1 to estimate. Default is 0.5 (median).

Methods

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

Calculates the derivative of the Quantile loss function.

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

Parameters

predicted Vector<T>

The predicted values from the model.

actual Vector<T>

The actual (target) values.

Returns

Vector<T>

A vector containing the derivatives of Quantile loss for each prediction.

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

Calculates the Quantile loss between predicted and actual values.

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

Parameters

predicted Vector<T>

The predicted values from the model.

actual Vector<T>

The actual (target) values.

Returns

T

The Quantile loss value.

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

Calculates both Quantile 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.