slope 6.5.4
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) override
 Calculates the loss for the multinomial loss function.
 
double dual (const Eigen::MatrixXd &theta, const Eigen::MatrixXd &y, const Eigen::VectorXd &w) override
 Calculates the dual for the multinomial loss function.
 
Eigen::MatrixXd dualPoint (const Eigen::MatrixXd &eta, const Eigen::MatrixXd &y, bool fit_intercept) override
 Constructs a dual candidate from a linear predictor.
 
Eigen::MatrixXd preprocessResponse (const Eigen::MatrixXd &y) override
 Preprocesses the response for the Multinomial model.
 
Eigen::MatrixXd hessianDiagonal (const Eigen::MatrixXd &eta) override
 Calculates the hessian diagonal.
 
Eigen::MatrixXd link (const Eigen::MatrixXd &mu) override
 The link function.
 
Eigen::MatrixXd inverseLink (const Eigen::MatrixXd &eta) override
 The inverse link function.
 
Eigen::MatrixXd predict (const Eigen::MatrixXd &eta) override
 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.
 
Eigen::MatrixXd domainSafePoint (const Eigen::MatrixXd &mean, const Eigen::MatrixXd &y, double lower, double upper) const
 Enforces scalar intercept stationarity without leaving a mean domain.
 

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 
)
overridevirtual

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.

◆ dualPoint()

Eigen::MatrixXd slope::Multinomial::dualPoint ( const Eigen::MatrixXd &  eta,
const Eigen::MatrixXd &  y,
bool  fit_intercept 
)
overridevirtual

Constructs a dual candidate from a linear predictor.

When an intercept is fitted, the candidate must satisfy the corresponding zero-sum constraint. Losses with restricted conjugate domains override this method to preserve those domains while enforcing the constraint.

Parameters
etaLinear predictor.
yResponse.
fit_interceptWhether the model has an unpenalized intercept.
Returns
A candidate dual point before regularizer scaling.

Reimplemented from slope::Loss.

◆ hessianDiagonal()

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

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)
overridevirtual

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)
overridevirtual

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 
)
overridevirtual

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)
overridevirtual

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)
overridevirtual

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: