mlpack
master
|
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 ¶meters) 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 ¶meters, arma::mat &probabilities) const |
Evaluate the probabilities matrix with the passed parameters. More... | |
void | Gradient (const arma::mat ¶meters, 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... | |
Private Attributes | |
const arma::mat & | data |
Training data matrix. More... | |
bool | fitIntercept |
Intercept term flag. More... | |
arma::sp_mat | groundTruth |
Label matrix for the provided data. More... | |
arma::mat | initialPoint |
Initial parameter point. More... | |
double | lambda |
L2-regularization constant. More... | |
size_t | numClasses |
Number of classes. More... | |
Definition at line 21 of file softmax_regression_function.hpp.
mlpack::regression::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.
data | Input training data, each column associate with one sample |
labels | Labels associated with the feature data. |
inputSize | Size of the input feature vector. |
numClasses | Number of classes for classification. |
lambda | L2-regularization constant. |
fitIntercept | Intercept term flag. |
double mlpack::regression::SoftmaxRegressionFunction::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 | Current values of the model parameters. |
|
inline |
Gets the features size of the training data.
Definition at line 121 of file softmax_regression_function.hpp.
References fitIntercept, and initialPoint.
|
inline |
Gets the intercept flag.
Definition at line 133 of file softmax_regression_function.hpp.
References fitIntercept.
void mlpack::regression::SoftmaxRegressionFunction::GetGroundTruthMatrix | ( | const arma::Row< size_t > & | labels, |
arma::sp_mat & | groundTruth | ||
) |
Constructs the ground truth label matrix with the passed labels.
labels | Labels associated with the training data. |
groundTruth | Pointer to arma::mat which stores the computed matrix. |
|
inline |
Return the initial point for the optimization.
Definition at line 115 of file softmax_regression_function.hpp.
References initialPoint.
void mlpack::regression::SoftmaxRegressionFunction::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 | Current values of the model parameters. |
probabilities | Pointer to arma::mat which stores the probabilities. |
void mlpack::regression::SoftmaxRegressionFunction::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 | Current values of the model parameters. |
gradient | Matrix where gradient values will be stored. |
const arma::mat mlpack::regression::SoftmaxRegressionFunction::InitializeWeights | ( | ) |
Initializes the parameters of the model to suitable values.
|
static |
Initialize Softmax Regression weights (trainable parameters) with the given parameters.
featureSize | The number of features in the training set. |
numClasses | Number of classes for classification. |
fitIntercept | If true, an intercept is fitted. |
|
static |
Initialize Softmax Regression weights (trainable parameters) with the given parameters.
weights | This will be filled with the initialized model weights. |
featureSize | The number of features in the training set. |
numClasses | Number of classes for classification. |
fitIntercept | Intercept term flag. |
|
inline |
Sets the regularization parameter.
Definition at line 128 of file softmax_regression_function.hpp.
References lambda.
|
inline |
Gets the regularization parameter.
Definition at line 130 of file softmax_regression_function.hpp.
References lambda.
|
inline |
Gets the number of classes.
Definition at line 118 of file softmax_regression_function.hpp.
References numClasses.
|
private |
Training data matrix.
Definition at line 137 of file softmax_regression_function.hpp.
|
private |
Intercept term flag.
Definition at line 147 of file softmax_regression_function.hpp.
Referenced by FeatureSize(), and FitIntercept().
|
private |
Label matrix for the provided data.
Definition at line 139 of file softmax_regression_function.hpp.
|
private |
Initial parameter point.
Definition at line 141 of file softmax_regression_function.hpp.
Referenced by FeatureSize(), and GetInitialPoint().
|
private |
L2-regularization constant.
Definition at line 145 of file softmax_regression_function.hpp.
Referenced by Lambda().
|
private |
Number of classes.
Definition at line 143 of file softmax_regression_function.hpp.
Referenced by NumClasses().