concision_core/loss/traits/
loss.rs

1/*
2    appellation: loss <module>
3    authors: @FL03
4*/
5
6/// The [`Loss`] trait defines a common interface for any custom loss function implementations.
7/// This trait requires the implementor to define their algorithm for calculating the loss
8/// between two values, `lhs` and `rhs`, which can be of different types, `X` and `Y`
9/// respectively. These terms are used generically to allow for flexibility in the allowed
10/// types, such as tensors, scalars, or other data structures while clearly defining the "order"
11/// in which the operations are performed. It is most common to expect the `lhs` to be the
12/// predicted output and the `rhs` to be the actual output, but this is not a strict requirement.
13/// The trait also defines an associated type `Output`, which represents the type of the loss
14/// value returned by the `loss` method. This allows for different loss functions to return
15/// different types of loss values, such as scalars or tensors, depending on the specific
16/// implementation of the loss function.
17pub trait Loss<X, Y> {
18    type Output;
19    /// compute the loss between two values, `lhs` and `rhs`
20    fn loss(&self, lhs: &X, rhs: &Y) -> Self::Output;
21}