mlpack  2.2.5
SoftmaxRegressionFunction Class Reference

Public Member Functions

 SoftmaxRegressionFunction (const arma::mat &data, const arma::Row< size_t > &labels, const size_t numClasses, const double lambda=0.0001, const bool fitIntercept=false)
 Construct the Softmax Regression objective function with the given parameters. More...

 
double Evaluate (const arma::mat &parameters) const
 Evaluates the objective function of the softmax regression model using the given parameters. More...

 
size_t FeatureSize () const
 Gets the features size of the training data. More...

 
bool FitIntercept () const
 Gets the intercept flag. More...

 
void GetGroundTruthMatrix (const arma::Row< size_t > &labels, arma::sp_mat &groundTruth)
 Constructs the ground truth label matrix with the passed labels. More...

 
const arma::mat & GetInitialPoint () const
 Return the initial point for the optimization. More...

 
void GetProbabilitiesMatrix (const arma::mat &parameters, arma::mat &probabilities) const
 Evaluate the probabilities matrix with the passed parameters. More...

 
void Gradient (const arma::mat &parameters, arma::mat &gradient) const
 Evaluates the gradient values of the objective function given the current set of parameters. More...

 
const arma::mat InitializeWeights ()
 Initializes the parameters of the model to suitable values. More...

 
double & Lambda ()
 Sets the regularization parameter. More...

 
double Lambda () const
 Gets the regularization parameter. More...

 
size_t NumClasses () const
 Gets the number of classes. More...

 

Static Public Member Functions

static const arma::mat InitializeWeights (const size_t featureSize, const size_t numClasses, const bool fitIntercept=false)
 Initialize Softmax Regression weights (trainable parameters) with the given parameters. More...

 
static void InitializeWeights (arma::mat &weights, const size_t featureSize, const size_t numClasses, const bool fitIntercept=false)
 Initialize Softmax Regression weights (trainable parameters) with the given parameters. More...

 

Detailed Description

Definition at line 21 of file softmax_regression_function.hpp.

Constructor & Destructor Documentation

◆ SoftmaxRegressionFunction()

SoftmaxRegressionFunction ( const arma::mat &  data,
const arma::Row< size_t > &  labels,
const size_t  numClasses,
const double  lambda = 0.0001,
const bool  fitIntercept = false 
)

Construct the Softmax Regression objective function with the given parameters.

Parameters
dataInput training data, each column associate with one sample
labelsLabels associated with the feature data.
inputSizeSize of the input feature vector.
numClassesNumber of classes for classification.
lambdaL2-regularization constant.
fitInterceptIntercept term flag.

Member Function Documentation

◆ Evaluate()

double Evaluate ( const arma::mat &  parameters) const

Evaluates the objective function of the softmax regression model using the given parameters.

The cost function has terms for the log likelihood error and the regularization cost. The objective function takes a low value when the model generalizes well for the given training data, while having small parameter values.

Parameters
parametersCurrent values of the model parameters.

◆ FeatureSize()

size_t FeatureSize ( ) const
inline

Gets the features size of the training data.

Definition at line 121 of file softmax_regression_function.hpp.

◆ FitIntercept()

bool FitIntercept ( ) const
inline

Gets the intercept flag.

Definition at line 133 of file softmax_regression_function.hpp.

◆ GetGroundTruthMatrix()

void GetGroundTruthMatrix ( const arma::Row< size_t > &  labels,
arma::sp_mat &  groundTruth 
)

Constructs the ground truth label matrix with the passed labels.

Parameters
labelsLabels associated with the training data.
groundTruthPointer to arma::mat which stores the computed matrix.

◆ GetInitialPoint()

const arma::mat& GetInitialPoint ( ) const
inline

Return the initial point for the optimization.

Definition at line 115 of file softmax_regression_function.hpp.

◆ GetProbabilitiesMatrix()

void GetProbabilitiesMatrix ( const arma::mat &  parameters,
arma::mat &  probabilities 
) const

Evaluate the probabilities matrix with the passed parameters.

probabilities(i, j) = exp( * data_j) / sum_k(exp( * data_j)). It represents the probability of data_j belongs to class i.

Parameters
parametersCurrent values of the model parameters.
probabilitiesPointer to arma::mat which stores the probabilities.

◆ Gradient()

void Gradient ( const arma::mat &  parameters,
arma::mat &  gradient 
) const

Evaluates the gradient values of the objective function given the current set of parameters.

The function calculates the probabilities for each class given the parameters, and computes the gradients based on the difference from the ground truth.

Parameters
parametersCurrent values of the model parameters.
gradientMatrix where gradient values will be stored.

◆ InitializeWeights() [1/3]

const arma::mat InitializeWeights ( )

Initializes the parameters of the model to suitable values.

◆ InitializeWeights() [2/3]

static const arma::mat InitializeWeights ( const size_t  featureSize,
const size_t  numClasses,
const bool  fitIntercept = false 
)
static

Initialize Softmax Regression weights (trainable parameters) with the given parameters.

Parameters
featureSizeThe number of features in the training set.
numClassesNumber of classes for classification.
fitInterceptIf true, an intercept is fitted.
Returns
Initialized model weights.

◆ InitializeWeights() [3/3]

static void InitializeWeights ( arma::mat &  weights,
const size_t  featureSize,
const size_t  numClasses,
const bool  fitIntercept = false 
)
static

Initialize Softmax Regression weights (trainable parameters) with the given parameters.

Parameters
weightsThis will be filled with the initialized model weights.
featureSizeThe number of features in the training set.
numClassesNumber of classes for classification.
fitInterceptIntercept term flag.

◆ Lambda() [1/2]

double& Lambda ( )
inline

Sets the regularization parameter.

Definition at line 128 of file softmax_regression_function.hpp.

◆ Lambda() [2/2]

double Lambda ( ) const
inline

Gets the regularization parameter.

Definition at line 130 of file softmax_regression_function.hpp.

◆ NumClasses()

size_t NumClasses ( ) const
inline

Gets the number of classes.

Definition at line 118 of file softmax_regression_function.hpp.


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