slope 6.2.1
Loading...
Searching...
No Matches
slope::Multinomial Class Reference

The Multinomial class represents a multinomial logistic regression loss function. More...

#include <multinomial.h>

Inheritance diagram for slope::Multinomial:
Collaboration diagram for slope::Multinomial:

Public Member Functions

double loss (const Eigen::MatrixXd &eta, const Eigen::MatrixXd &y)
 Calculates the loss for the multinomial loss function.
 
double dual (const Eigen::MatrixXd &theta, const Eigen::MatrixXd &y, const Eigen::VectorXd &w)
 Calculates the dual for the multinomial loss function.
 
Eigen::MatrixXd preprocessResponse (const Eigen::MatrixXd &y)
 Preprocesses the response for the Multinomial model.
 
Eigen::MatrixXd hessianDiagonal (const Eigen::MatrixXd &eta)
 Calculates the hessian diagonal.
 
Eigen::MatrixXd link (const Eigen::MatrixXd &mu)
 The link function.
 
Eigen::MatrixXd inverseLink (const Eigen::MatrixXd &eta)
 The inverse link function.
 
Eigen::MatrixXd predict (const Eigen::MatrixXd &eta)
 Return predicted response, which is an integer class label based on the predicted probabilities.
 
- Public Member Functions inherited from slope::Loss
virtual ~Loss ()=default
 Destructor for the Loss class.
 
Eigen::MatrixXd residual (const Eigen::MatrixXd &eta, const Eigen::MatrixXd &y)
 Calculates the generalized residual.
 
virtual void updateWeightsAndWorkingResponse (Eigen::MatrixXd &w, Eigen::MatrixXd &z, const Eigen::MatrixXd &eta, const Eigen::MatrixXd &y)
 Updates weights and working response.
 
virtual void updateIntercept (Eigen::VectorXd &beta0, const Eigen::MatrixXd &eta, const Eigen::MatrixXd &y)
 Updates the intercept with a gradient descent update.
 
virtual double deviance (const Eigen::MatrixXd &eta, const Eigen::MatrixXd &y)
 Computes deviance, which is 2 times the difference between the loglikelihood of the model and the loglikelihood of the null (intercept-only) model.
 

Additional Inherited Members

- Protected Member Functions inherited from slope::Loss
 Loss (double lipschitz_constant)
 Constructs an loss function with specified Lipschitz constant.
 

Detailed Description

The Multinomial class represents a multinomial logistic regression loss function.

The multinomial loss function is used for multi-class classification problems. It calculates the loss, dual, residual, and updates weights and working response. It uses the non-redundant formulation of the loss with \( K - 1\) columns in the resulting response matrix.

Definition at line 21 of file multinomial.h.

Constructor & Destructor Documentation

◆ Multinomial()

slope::Multinomial::Multinomial ( )
inlineexplicit

Definition at line 24 of file multinomial.h.

Member Function Documentation

◆ dual()

double slope::Multinomial::dual ( const Eigen::MatrixXd &  theta,
const Eigen::MatrixXd &  y,
const Eigen::VectorXd &  w 
)
virtual

Calculates the dual for the multinomial loss function.

Parameters
thetaThe dual variables (n x m matrix).
yThe true labels (n x m matrix).
wThe weights vector.
Returns
The dual value.

Implements slope::Loss.

◆ hessianDiagonal()

Eigen::MatrixXd slope::Multinomial::hessianDiagonal ( const Eigen::MatrixXd &  eta)
virtual

Calculates the hessian diagonal.

Parameters
etaLinear predictor
Returns
The hessian diagonal, a matrix of size (n x m)

Implements slope::Loss.

◆ inverseLink()

Eigen::MatrixXd slope::Multinomial::inverseLink ( const Eigen::MatrixXd &  eta)
virtual

The inverse link function.

Parameters
eta
Returns
The modified softmax of the linear predictor: \( \frac{e^{\eta}}{1 + \sum_{j=1}^{k} e^{\eta_j}} \)

Implements slope::Loss.

◆ link()

Eigen::MatrixXd slope::Multinomial::link ( const Eigen::MatrixXd &  mu)
virtual

The link function.

Parameters
muMean.
Returns
The result of applying the link function.

Implements slope::Loss.

◆ loss()

double slope::Multinomial::loss ( const Eigen::MatrixXd &  eta,
const Eigen::MatrixXd &  y 
)
virtual

Calculates the loss for the multinomial loss function.

Parameters
etaThe predicted values (n x m matrix of linear predictors).
yThe true labels (n x m matrix of one-hot encoded class memberships).
Returns
The loss value.

Implements slope::Loss.

◆ predict()

Eigen::MatrixXd slope::Multinomial::predict ( const Eigen::MatrixXd &  eta)
virtual

Return predicted response, which is an integer class label based on the predicted probabilities.

Parameters
etaThe linear predictor
Returns
The predicted response

Implements slope::Loss.

◆ preprocessResponse()

Eigen::MatrixXd slope::Multinomial::preprocessResponse ( const Eigen::MatrixXd &  y)
virtual

Preprocesses the response for the Multinomial model.

Parameters
yVector of class labels (n x 1). Each entry is an integer representing the class label from 0 to m.
Returns
Matrix of response (n x m)

Implements slope::Loss.


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