CompositeLossWithLogits<T>

Models & Types ยท AiDotNet.LossFunctions

Applies a sigmoid to raw logits and then evaluates a weighted composite probability loss.

Inheritance: LossFunctionBase<T> โ†’ CompositeLossWithLogits<T>

How It Works

This is the logits-domain counterpart to CompositeLoss. Keeping the activation at the loss boundary prevents models from applying sigmoid in their output head (which would hide logits from numerically stable objectives) and prevents probability-domain terms such as focal and Dice loss from receiving unbounded values. The sigmoid is part of the autodiff graph, so gradients propagate through the transform on every engine backend.

Example

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

var loss = new CompositeLossWithLogits<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($"CompositeLossWithLogits = {value:F4}");

Constructors

Constructor Summary
CompositeLossWithLogits(ValueTuple<LossFunctionBase<T>, double>[] terms) Creates a logits-aware composite from probability-domain loss terms and their absolute coefficients.

Properties

Property Summary
int TermCount { get; } Gets the number of terms in the wrapped composite objective.

Methods

Method Summary
T CalculateLoss(Vector<T> predicted, Vector<T> actual)
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target)