Loss Functions

Loss functions measure how well a neural network’s predictions match the expected outputs. They guide the optimisation process by providing a scalar value to minimise during training.

The athena library provides several commonly used loss functions for different types of problems.

Overview

Choosing the Right Loss Function

  • Binary Classification: Use BCE (Binary Cross Entropy)

  • Multi-class Classification: Use CCE or NLL

  • Regression: Use MSE, MAE, or Huber

Loss Function Properties

All loss functions in athena:

  • Extend base_loss_type

  • Implement a compute method

  • Work with differentiable array_type for automatic gradient computation

  • Support batch processing

Usage Example

use athena__loss
use athena__network

! Create a network
type(network_type) :: net
type(mse_loss_type) :: loss

! Initialise loss function
loss = mse_loss_type()

! Use in training
call net%train(train_data, train_labels, loss=loss)

Creating custom loss functions

The athena library is designed with extensibility in mind, allowing users to create custom loss functions by extending the base_loss_type.

See the tutorial: Creating Custom Loss Functions