XCSF  1.4.7
XCSF learning classifier system
loss.h File Reference

Loss functions for calculating prediction error. More...

#include "xcsf.h"
Include dependency graph for loss.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LOSS_INVALID   (-1)
 Error code for invalid loss type. More...
 
#define LOSS_MAE   (0)
 Mean absolute error. More...
 
#define LOSS_MSE   (1)
 Mean squared error. More...
 
#define LOSS_RMSE   (2)
 Root mean squared error. More...
 
#define LOSS_LOG   (3)
 Log loss. More...
 
#define LOSS_BINARY_LOG   (4)
 Binary log loss. More...
 
#define LOSS_ONEHOT   (5)
 One-hot encoding classification error. More...
 
#define LOSS_HUBER   (6)
 Huber loss. More...
 
#define LOSS_NUM   (7)
 Total number of selectable loss functions. More...
 
#define LOSS_STRING_MAE   ("mae\0")
 Mean absolute error. More...
 
#define LOSS_STRING_MSE   ("mse\0")
 Mean squared error. More...
 
#define LOSS_STRING_RMSE   ("rmse\0")
 Root mean squared error. More...
 
#define LOSS_STRING_LOG   ("log\0")
 Log loss. More...
 
#define LOSS_STRING_BINARY_LOG   ("binary_log\0")
 Binary log loss. More...
 
#define LOSS_STRING_ONEHOT   ("onehot\0")
 One-hot classification error. More...
 
#define LOSS_STRING_HUBER   ("huber\0")
 Huber loss. More...
 
#define LOSS_OPTIONS   "mae, mse, rmse, log, binary_log, one_hot, huber"
 

Functions

double loss_huber (const struct XCSF *xcsf, const double *pred, const double *y)
 Huber loss function. More...
 
double loss_mae (const struct XCSF *xcsf, const double *pred, const double *y)
 Mean absolute error loss function. More...
 
double loss_mse (const struct XCSF *xcsf, const double *pred, const double *y)
 Mean squared error loss function. More...
 
double loss_rmse (const struct XCSF *xcsf, const double *pred, const double *y)
 Root mean squared error loss function. More...
 
double loss_log (const struct XCSF *xcsf, const double *pred, const double *y)
 Logistic log loss for multi-class classification. More...
 
double loss_binary_log (const struct XCSF *xcsf, const double *pred, const double *y)
 Binary logistic log loss for binary-class classification. More...
 
double loss_onehot (const struct XCSF *xcsf, const double *pred, const double *y)
 One-hot classification error. More...
 
int loss_set_func (struct XCSF *xcsf)
 Sets the XCSF error function to the implemented function. More...
 
const char * loss_type_as_string (const int type)
 Returns a string representation of a loss type from the integer. More...
 
int loss_type_as_int (const char *type)
 Returns the integer representation of a loss type given a name. More...
 

Detailed Description

Loss functions for calculating prediction error.

Author
Richard Preen rpree.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om
Date
2019–2022.

Definition in file loss.h.

Macro Definition Documentation

◆ LOSS_BINARY_LOG

#define LOSS_BINARY_LOG   (4)

Binary log loss.

Definition at line 33 of file loss.h.

◆ LOSS_HUBER

#define LOSS_HUBER   (6)

Huber loss.

Definition at line 35 of file loss.h.

◆ LOSS_INVALID

#define LOSS_INVALID   (-1)

Error code for invalid loss type.

Definition at line 28 of file loss.h.

◆ LOSS_LOG

#define LOSS_LOG   (3)

Log loss.

Definition at line 32 of file loss.h.

◆ LOSS_MAE

#define LOSS_MAE   (0)

Mean absolute error.

Definition at line 29 of file loss.h.

◆ LOSS_MSE

#define LOSS_MSE   (1)

Mean squared error.

Definition at line 30 of file loss.h.

◆ LOSS_NUM

#define LOSS_NUM   (7)

Total number of selectable loss functions.

Definition at line 36 of file loss.h.

◆ LOSS_ONEHOT

#define LOSS_ONEHOT   (5)

One-hot encoding classification error.

Definition at line 34 of file loss.h.

◆ LOSS_OPTIONS

#define LOSS_OPTIONS   "mae, mse, rmse, log, binary_log, one_hot, huber"

Definition at line 46 of file loss.h.

◆ LOSS_RMSE

#define LOSS_RMSE   (2)

Root mean squared error.

Definition at line 31 of file loss.h.

◆ LOSS_STRING_BINARY_LOG

#define LOSS_STRING_BINARY_LOG   ("binary_log\0")

Binary log loss.

Definition at line 42 of file loss.h.

◆ LOSS_STRING_HUBER

#define LOSS_STRING_HUBER   ("huber\0")

Huber loss.

Definition at line 44 of file loss.h.

◆ LOSS_STRING_LOG

#define LOSS_STRING_LOG   ("log\0")

Log loss.

Definition at line 41 of file loss.h.

◆ LOSS_STRING_MAE

#define LOSS_STRING_MAE   ("mae\0")

Mean absolute error.

Definition at line 38 of file loss.h.

◆ LOSS_STRING_MSE

#define LOSS_STRING_MSE   ("mse\0")

Mean squared error.

Definition at line 39 of file loss.h.

◆ LOSS_STRING_ONEHOT

#define LOSS_STRING_ONEHOT   ("onehot\0")

One-hot classification error.

Definition at line 43 of file loss.h.

◆ LOSS_STRING_RMSE

#define LOSS_STRING_RMSE   ("rmse\0")

Root mean squared error.

Definition at line 40 of file loss.h.

Function Documentation

◆ loss_binary_log()

double loss_binary_log ( const struct XCSF xcsf,
const double *  pred,
const double *  y 
)

Binary logistic log loss for binary-class classification.

Parameters
[in]xcsfThe XCSF data structure.
[in]predThe predicted values.
[in]yThe true values.
Returns
The log error.

Definition at line 102 of file loss.c.

Referenced by loss_set_func().

Here is the caller graph for this function:

◆ loss_huber()

double loss_huber ( const struct XCSF xcsf,
const double *  pred,
const double *  y 
)

Huber loss function.

Parameters
[in]xcsfThe XCSF data structure.
[in]predThe predicted values.
[in]yThe true values.
Returns
The Huber loss.

Definition at line 137 of file loss.c.

Referenced by loss_set_func().

Here is the caller graph for this function:

◆ loss_log()

double loss_log ( const struct XCSF xcsf,
const double *  pred,
const double *  y 
)

Logistic log loss for multi-class classification.

Precondition
The sum of predictions = 1 and a single target y_i has a value of 1.
Parameters
[in]xcsfThe XCSF data structure.
[in]predThe predicted values.
[in]yThe true values.
Returns
The log error.

Definition at line 85 of file loss.c.

Referenced by loss_set_func().

Here is the caller graph for this function:

◆ loss_mae()

double loss_mae ( const struct XCSF xcsf,
const double *  pred,
const double *  y 
)

Mean absolute error loss function.

Parameters
[in]xcsfThe XCSF data structure.
[in]predThe predicted values.
[in]yThe true values.
Returns
The mean absolute error.

Definition at line 35 of file loss.c.

Referenced by loss_set_func().

Here is the caller graph for this function:

◆ loss_mse()

double loss_mse ( const struct XCSF xcsf,
const double *  pred,
const double *  y 
)

Mean squared error loss function.

Parameters
[in]xcsfThe XCSF data structure.
[in]predThe predicted values.
[in]yThe true values.
Returns
The mean squared error.

Definition at line 53 of file loss.c.

Referenced by loss_rmse(), and loss_set_func().

Here is the caller graph for this function:

◆ loss_onehot()

double loss_onehot ( const struct XCSF xcsf,
const double *  pred,
const double *  y 
)

One-hot classification error.

Parameters
[in]xcsfThe XCSF data structure.
[in]predThe predicted values.
[in]yThe true values.
Returns
The one-hot classification error.

Definition at line 120 of file loss.c.

References argmax().

Referenced by loss_set_func().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loss_rmse()

double loss_rmse ( const struct XCSF xcsf,
const double *  pred,
const double *  y 
)

Root mean squared error loss function.

Parameters
[in]xcsfThe XCSF data structure.
[in]predThe predicted values.
[in]yThe true values.
Returns
The root mean squared error.

Definition at line 71 of file loss.c.

References loss_mse().

Referenced by loss_set_func().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loss_set_func()

int loss_set_func ( struct XCSF xcsf)

Sets the XCSF error function to the implemented function.

Parameters
[in]xcsfThe XCSF data structure.
Returns
Integer representation of the loss function.

Definition at line 159 of file loss.c.

References loss_binary_log(), LOSS_BINARY_LOG, loss_huber(), LOSS_HUBER, LOSS_INVALID, loss_log(), LOSS_LOG, loss_mae(), LOSS_MAE, loss_mse(), LOSS_MSE, loss_onehot(), LOSS_ONEHOT, loss_rmse(), and LOSS_RMSE.

Referenced by param_load(), param_set_loss_func(), and param_set_loss_func_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loss_type_as_int()

int loss_type_as_int ( const char *  type)

Returns the integer representation of a loss type given a name.

Parameters
[in]typeString representation of a loss function type.
Returns
Integer representing the loss function type.

Definition at line 223 of file loss.c.

References LOSS_BINARY_LOG, LOSS_HUBER, LOSS_INVALID, LOSS_LOG, LOSS_MAE, LOSS_MSE, LOSS_ONEHOT, LOSS_RMSE, LOSS_STRING_BINARY_LOG, LOSS_STRING_HUBER, LOSS_STRING_LOG, LOSS_STRING_MAE, LOSS_STRING_MSE, LOSS_STRING_ONEHOT, and LOSS_STRING_RMSE.

Referenced by param_set_loss_func_string().

Here is the caller graph for this function:

◆ loss_type_as_string()

const char* loss_type_as_string ( const int  type)

Returns a string representation of a loss type from the integer.

Parameters
[in]typeInteger representation of a loss function type.
Returns
String representing the name of the loss function type.

Definition at line 194 of file loss.c.

References LOSS_BINARY_LOG, LOSS_HUBER, LOSS_LOG, LOSS_MAE, LOSS_MSE, LOSS_ONEHOT, LOSS_RMSE, LOSS_STRING_BINARY_LOG, LOSS_STRING_HUBER, LOSS_STRING_LOG, LOSS_STRING_MAE, LOSS_STRING_MSE, LOSS_STRING_ONEHOT, and LOSS_STRING_RMSE.

Referenced by param_json_export().

Here is the caller graph for this function: