Trait LossFunction

Source
pub trait LossFunction {
    // Required methods
    fn compute_loss(
        &self,
        predictions: &Array2<f64>,
        targets: &Array2<f64>,
    ) -> f64;
    fn compute_gradient(
        &self,
        predictions: &Array2<f64>,
        targets: &Array2<f64>,
    ) -> Array2<f64>;

    // Provided methods
    fn compute_batch_loss(
        &self,
        predictions: &Array2<f64>,
        targets: &Array2<f64>,
    ) -> f64 { ... }
    fn compute_batch_gradient(
        &self,
        predictions: &Array2<f64>,
        targets: &Array2<f64>,
    ) -> Array2<f64> { ... }
}
Expand description

Loss function trait for training neural networks

Required Methods§

Source

fn compute_loss(&self, predictions: &Array2<f64>, targets: &Array2<f64>) -> f64

Compute the loss between predictions and targets

Source

fn compute_gradient( &self, predictions: &Array2<f64>, targets: &Array2<f64>, ) -> Array2<f64>

Compute the gradient of the loss with respect to predictions

Provided Methods§

Source

fn compute_batch_loss( &self, predictions: &Array2<f64>, targets: &Array2<f64>, ) -> f64

Compute batch loss for multiple predictions and targets Default implementation computes average loss across batch

Source

fn compute_batch_gradient( &self, predictions: &Array2<f64>, targets: &Array2<f64>, ) -> Array2<f64>

Compute batch gradients for multiple predictions and targets Default implementation computes gradients for each sample and concatenates

Implementors§