NNFS
Neural network library from scratch
Loading...
Searching...
No Matches
NNFS::Loss Class Referenceabstract

Base class for all loss functions. More...

#include <Loss.hpp>

Inheritance diagram for NNFS::Loss:
[legend]

Public Member Functions

 Loss (LossType type)
 Construct a new Loss object.
 
virtual ~Loss ()=default
 Basic destructor.
 
virtual void forward (Eigen::MatrixXd &sample_losses, const Eigen::MatrixXd &predictions, const Eigen::MatrixXd &labels) const =0
 Forward pass of the loss function.
 
virtual void backward (Eigen::MatrixXd &out, const Eigen::MatrixXd &predictions, const Eigen::MatrixXd &labels) const =0
 Backward pass of the loss function.
 
void calculate (double &loss, const Eigen::MatrixXd &predictions, const Eigen::MatrixXd &labels)
 Calculate the loss.
 
double regularization_loss (const std::shared_ptr< Dense > &layer)
 Calculate l1 and l2 regularization loss.
 

Public Attributes

LossType type
 

Detailed Description

Base class for all loss functions.

This class is the base class for all losses. It provides the interface for all loss functions.

Constructor & Destructor Documentation

◆ Loss()

NNFS::Loss::Loss ( LossType  type)
inline

Construct a new Loss object.

Parameters
typeType of loss function

◆ ~Loss()

virtual NNFS::Loss::~Loss ( )
virtualdefault

Basic destructor.

Member Function Documentation

◆ backward()

virtual void NNFS::Loss::backward ( Eigen::MatrixXd &  out,
const Eigen::MatrixXd &  predictions,
const Eigen::MatrixXd &  labels 
) const
pure virtual

Backward pass of the loss function.

Parameters
[out]outOutput gradient
[in]predictionsPredictions
[in]labelsLabels

Implemented in NNFS::CCE, and NNFS::CCESoftmax.

◆ calculate()

void NNFS::Loss::calculate ( double &  loss,
const Eigen::MatrixXd &  predictions,
const Eigen::MatrixXd &  labels 
)
inline

Calculate the loss.

Parameters
[out]lossLoss
[in]predictionsPredictions
[in]labelsLabels

◆ forward()

virtual void NNFS::Loss::forward ( Eigen::MatrixXd &  sample_losses,
const Eigen::MatrixXd &  predictions,
const Eigen::MatrixXd &  labels 
) const
pure virtual

Forward pass of the loss function.

Parameters
[out]sample_lossesSample losses
[in]predictionsPredictions
[in]labelsLabels

Implemented in NNFS::CCE, and NNFS::CCESoftmax.

◆ regularization_loss()

double NNFS::Loss::regularization_loss ( const std::shared_ptr< Dense > &  layer)
inline

Calculate l1 and l2 regularization loss.

Parameters
layerLayer to calculate regularization loss
Returns
double Regularization loss

Member Data Documentation

◆ type

LossType NNFS::Loss::type

The documentation for this class was generated from the following file: