CNum 0.2.1
CPU-optimized ML library for C++
Loading...
Searching...
No Matches
Loss.h
Go to the documentation of this file.
1#ifndef LOSS_H
2#define LOSS_H
3
5
6#include <string>
7#include <functional>
8#include <cmath>
9
14namespace CNum::Model::Loss {
15 using GHFunction = std::function< double(double, double) >;
16 using LossFunction = std::function< double(const CNum::DataStructs::Matrix<double> &,
18
19
27
34
39 double MSE_gradient(double y,
40 double y_pred);
41
47 double MSE_hessian(double y,
48 double y_pred);
49
56
63
69 double y_pred);
70
76 double y_pred);
77
90 arena_view_t &g_out,
91 arena_view_t &h_out,
92 const arena_view_t &position_array,
93 GHFunction &grad_func,
94 GHFunction &hess_func);
95
103 LossFunction &loss_func);
104
108 LossProfile get_loss_profile(::std::string loss);
109
110};
111
112#endif
struct arena_view arena_view_t
2d array abstraction
Definition Matrix.h:43
Loss functions.
double MSE_gradient(double y, double y_pred)
Calculate the gradient value of the mean squared error.
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.
double RMSE_loss(const CNum::DataStructs::Matrix< double > &y, const CNum::DataStructs::Matrix< double > &y_pred)
Root mean squared error.
LossProfile get_loss_profile(::std::string loss)
Get the LossProfile associated with a string (i.e. "MSE" -> mean squared error function).
std::function< double(double, double) > GHFunction
Definition Loss.h:15
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.
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 MSE_hessian(double y, double y_pred)
Calculate the hessian (second order derivative) value of the mean squared error.
double binary_crossentropy_loss(const CNum::DataStructs::Matrix< double > &y, const CNum::DataStructs::Matrix< double > &y_pred)
Binary crossentropy (log loss).
std::function< double(const CNum::DataStructs::Matrix< double > &, const CNum::DataStructs::Matrix< double > &) > LossFunction
Definition Loss.h:16
double MSE_loss(const CNum::DataStructs::Matrix< double > &y, const CNum::DataStructs::Matrix< double > &y_pred)
Mean squared error.
The loss, gradient, and hessian functions associated with a loss function.
Definition Loss.h:22
GHFunction gradient_func
Definition Loss.h:24
LossFunction loss_func
Definition Loss.h:23
GHFunction hessian_func
Definition Loss.h:25