CNum 0.2.1
CPU-optimized ML library for C++
Loading...
Searching...
No Matches
CNum::Model::Loss Namespace Reference

Loss functions. More...

Classes

struct  LossProfile
 The loss, gradient, and hessian functions associated with a loss function. More...

Typedefs

using GHFunction = std::function< double(double, double) >
using LossFunction

Functions

double MSE_loss (const CNum::DataStructs::Matrix< double > &y, const CNum::DataStructs::Matrix< double > &y_pred)
 Mean squared error.
double MSE_gradient (double y, double y_pred)
 Calculate the gradient value of the mean squared error.
double MSE_hessian (double y, double y_pred)
 Calculate the hessian (second order derivative) value of the mean squared error.
double RMSE_loss (const CNum::DataStructs::Matrix< double > &y, const CNum::DataStructs::Matrix< double > &y_pred)
 Root mean squared error.
double binary_crossentropy_loss (const CNum::DataStructs::Matrix< double > &y, const CNum::DataStructs::Matrix< double > &y_pred)
 Binary crossentropy (log loss).
double binary_crossentropy_gradient (double y, double y_pred)
 Calculate the gradient of the log loss.
double binary_crossentropy_hessian (double y, double y_pred)
 Calculate the hessian (second order derivative) of the log loss.
void get_gradients_hessians (const CNum::DataStructs::Matrix< double > &y, const CNum::DataStructs::Matrix< double > &y_pred, arena_view_t &g_out, arena_view_t &h_out, const arena_view_t &position_array, GHFunction &grad_func, GHFunction &hess_func)
 Get the Gradients and Hessians of a Matrix.
double get_loss (const CNum::DataStructs::Matrix< double > &y, const CNum::DataStructs::Matrix< double > &y_pred, LossFunction &loss_func)
 Get the loss of a matrix of values.
LossProfile get_loss_profile (::std::string loss)
 Get the LossProfile associated with a string (i.e. "MSE" -> mean squared error function).

Detailed Description

Loss functions.

Typedef Documentation

◆ GHFunction

using CNum::Model::Loss::GHFunction = std::function< double(double, double) >

◆ LossFunction

Initial value:
std::function< double(const CNum::DataStructs::Matrix<double> &,
2d array abstraction
Definition Matrix.h:43

Function Documentation

◆ binary_crossentropy_gradient()

double CNum::Model::Loss::binary_crossentropy_gradient ( double y,
double y_pred )

Calculate the gradient of the log loss.

Parameters
yA true y sample
y_predA predicted y sample
Returns
The gradient value

◆ binary_crossentropy_hessian()

double CNum::Model::Loss::binary_crossentropy_hessian ( double y,
double y_pred )

Calculate the hessian (second order derivative) of the log loss.

Parameters
yA true y sample
y_predA predicted y sample
Returns
The hessian value

◆ binary_crossentropy_loss()

double CNum::Model::Loss::binary_crossentropy_loss ( const CNum::DataStructs::Matrix< double > & y,
const CNum::DataStructs::Matrix< double > & y_pred )

Binary crossentropy (log loss).

Parameters
yList of true y values (shape=(n,1))
y_predList of predicted values (shape=(n,1))
Returns
The loss

◆ get_gradients_hessians()

void CNum::Model::Loss::get_gradients_hessians ( const CNum::DataStructs::Matrix< double > & y,
const CNum::DataStructs::Matrix< double > & y_pred,
arena_view_t & g_out,
arena_view_t & h_out,
const arena_view_t & position_array,
GHFunction & grad_func,
GHFunction & hess_func )

Get the Gradients and Hessians of a Matrix.

Parameters
yList of true y values (shape=(n,1))
y_predList of predicted values (shape=(n,1))
g_outThe arena_view_t to output the gradient values to
h_outThe arena_view_t to output the hessian values to
position_arrayThe arena_view_t containing the partitioned indeces of the data (partitions are for keeping track of which samples tree nodes have to work with)
grad_funcThe GHFunction for the gradient of the loss
hess_funcThe GHFunction for the hessian of the loss

◆ get_loss()

double CNum::Model::Loss::get_loss ( const CNum::DataStructs::Matrix< double > & y,
const CNum::DataStructs::Matrix< double > & y_pred,
LossFunction & loss_func )

Get the loss of a matrix of values.

Parameters
yList of true y values (shape=(n,1))
y_predList of predicted values (shape=(n,1))
loss_funcThe LossFunction to use
Returns
The loss

◆ get_loss_profile()

LossProfile CNum::Model::Loss::get_loss_profile ( ::std::string loss)

Get the LossProfile associated with a string (i.e. "MSE" -> mean squared error function).

Parameters
lossThe name of the loss function
Returns
The LossProfile

◆ MSE_gradient()

double CNum::Model::Loss::MSE_gradient ( double y,
double y_pred )

Calculate the gradient value of the mean squared error.

Parameters
yA true y sample
y_predA predicted y sample
Returns
The gradient value

◆ MSE_hessian()

double CNum::Model::Loss::MSE_hessian ( double y,
double y_pred )

Calculate the hessian (second order derivative) value of the mean squared error.

Parameters
yA true y sample
y_predA predicted y sample
Returns
The hessian value

◆ MSE_loss()

double CNum::Model::Loss::MSE_loss ( const CNum::DataStructs::Matrix< double > & y,
const CNum::DataStructs::Matrix< double > & y_pred )

Mean squared error.

Parameters
yList of true y values (shape=(n,1))
y_predList of predicted values (shape=(n,1))
Returns
The loss

◆ RMSE_loss()

double CNum::Model::Loss::RMSE_loss ( const CNum::DataStructs::Matrix< double > & y,
const CNum::DataStructs::Matrix< double > & y_pred )

Root mean squared error.

Parameters
yList of true y values (shape=(n,1))
y_predList of predicted values (shape=(n,1))
Returns
The loss