QuantileLoss<T>

Models & Types · AiDotNet.LossFunctions

Implements the Quantile loss function for quantile regression.

Inheritance: LossFunctionBase<T> → QuantileLoss<T>

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.

Example

using AiDotNet.LossFunctions;
using AiDotNet.Tensors.LinearAlgebra;

var loss = new QuantileLoss<float>();
var predicted = new Vector<float>(new[] { 0.9f, 0.2f, 0.7f });
var actual = new Vector<float>(new[] { 1.0f, 0.0f, 1.0f });

float value = loss.CalculateLoss(predicted, actual);
Console.WriteLine($"QuantileLoss = {value:F4}");

Constructors

Constructor Summary
QuantileLoss(double quantile) Initializes a new instance of the QuantileLoss class.

Methods

Method Summary
T CalculateLoss(Vector<T> predicted, Vector<T> actual) Calculates the Quantile loss between predicted and actual values.
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target)
ValueTuple<T, Tensor<T>> CalculateLossAndGradientGpu(Tensor<T> predicted, Tensor<T> actual) Calculates both Quantile loss and gradient on GPU in a single efficient pass.