The hinge loss function for the linear SVM objective function. More...
Public Member Functions | |
| LinearSVMFunction (const MatType &dataset, const arma::Row< size_t > &labels, const size_t numClasses, const double lambda=0.0001, const double delta=1.0, const bool fitIntercept=false) | |
| Construct the Linear SVM objective function with given parameters. More... | |
| const arma::sp_mat & | Dataset () const |
| Get the dataset. More... | |
| arma::sp_mat & | Dataset () |
| Modify the dataset. More... | |
| double | Evaluate (const arma::mat ¶meters) |
| Evaluate the hinge loss function for all the datapoints. More... | |
| double | Evaluate (const arma::mat ¶meters, const size_t firstId, const size_t batchSize=1) |
| Evaluate the hinge loss function on the specified datapoints. More... | |
template < typename GradType > | |
| double | EvaluateWithGradient (const arma::mat ¶meters, GradType &gradient) const |
| Evaluate the gradient of the hinge loss function, following the LinearFunctionType requirements on the Gradient function followed by evaluation of the hinge loss function on all the datapoints. More... | |
template < typename GradType > | |
| double | EvaluateWithGradient (const arma::mat ¶meters, const size_t firstId, GradType &gradient, const size_t batchSize=1) const |
| Evaluate the gradient of the hinge loss function, following the LinearFunctionType requirements on the Gradient function followed by evaluation of the hinge loss function on the specified datapoints. 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... | |
template < typename GradType > | |
| void | Gradient (const arma::mat ¶meters, GradType &gradient) |
| Evaluate the gradient of the hinge loss function following the LinearFunctionType requirements on the Gradient function. More... | |
template < typename GradType > | |
| void | Gradient (const arma::mat ¶meters, const size_t firstId, GradType &gradient, const size_t batchSize=1) |
| Evaluate the gradient of the hinge loss function, following the LinearFunctionType requirements on the Gradient function. More... | |
| const arma::mat & | InitialPoint () const |
| Return the initial point for the optimization. More... | |
| arma::mat & | InitialPoint () |
| Modify the initial point for the optimization. More... | |
| double & | Lambda () |
| Sets the regularization parameter. More... | |
| double | Lambda () const |
| Gets the regularization parameter. More... | |
| size_t | NumFunctions () const |
| Return the number of functions. More... | |
| void | Shuffle () |
| Shuffle the dataset. More... | |
Static Public Member Functions | |
| static void | InitializeWeights (arma::mat &weights, const size_t featureSize, const size_t numClasses, const bool fitIntercept=false) |
| Initialize Linear SVM weights (trainable parameters) with the given parameters. More... | |
The hinge loss function for the linear SVM objective function.
This is used by various ensmallen optimizers to train the linear SVM model.
Definition at line 28 of file linear_svm_function.hpp.
| LinearSVMFunction | ( | const MatType & | dataset, |
| const arma::Row< size_t > & | labels, | ||
| const size_t | numClasses, | ||
| const double | lambda = 0.0001, |
||
| const double | delta = 1.0, |
||
| const bool | fitIntercept = false |
||
| ) |
Construct the Linear SVM objective function with given parameters.
| dataset | Input training data, each column associate with one sample |
| labels | Labels associated with the feature data. |
| numClasses | Number of classes for classification. |
| lambda | L2-regularization constant. |
| delta | Margin of difference between correct class and other classes. |
| fitIntercept | Intercept term flag. |
|
inline |
Get the dataset.
Definition at line 166 of file linear_svm_function.hpp.
|
inline |
Modify the dataset.
Definition at line 168 of file linear_svm_function.hpp.
| double Evaluate | ( | const arma::mat & | parameters | ) |
Evaluate the hinge loss function for all the datapoints.
| parameters | The parameters of the SVM. |
| double Evaluate | ( | const arma::mat & | parameters, |
| const size_t | firstId, | ||
| const size_t | batchSize = 1 |
||
| ) |
Evaluate the hinge loss function on the specified datapoints.
| parameters | The parameters of the SVM. |
| firstId | Index of the datapoints to use for function evaluation. |
| batchSize | Size of batch to process. |
| double EvaluateWithGradient | ( | const arma::mat & | parameters, |
| GradType & | gradient | ||
| ) | const |
Evaluate the gradient of the hinge loss function, following the LinearFunctionType requirements on the Gradient function followed by evaluation of the hinge loss function on all the datapoints.
| GradType | Type of the gradient matrix. |
| parameters | The parameters of the SVM. |
| gradient | Linear matrix to output the gradient into. |
| double EvaluateWithGradient | ( | const arma::mat & | parameters, |
| const size_t | firstId, | ||
| GradType & | gradient, | ||
| const size_t | batchSize = 1 |
||
| ) | const |
Evaluate the gradient of the hinge loss function, following the LinearFunctionType requirements on the Gradient function followed by evaluation of the hinge loss function on the specified datapoints.
| GradType | Type of the gradient matrix. |
| parameters | The parameters of the SVM. |
| firstId | Index of the datapoint to use for the gradient and function evaluation. |
| gradient | Linear matrix to output the gradient into. |
| batchSize | Size of the batch to process. |
|
inline |
Gets the intercept flag.
Definition at line 176 of file linear_svm_function.hpp.
References LinearSVMFunction< MatType >::NumFunctions().
| void 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. |
| void Gradient | ( | const arma::mat & | parameters, |
| GradType & | gradient | ||
| ) |
Evaluate the gradient of the hinge loss function following the LinearFunctionType requirements on the Gradient function.
| GradType | Type of the gradient matrix. |
| parameters | The parameters of the SVM. |
| gradient | Linear matrix to output the gradient into. |
| void Gradient | ( | const arma::mat & | parameters, |
| const size_t | firstId, | ||
| GradType & | gradient, | ||
| const size_t | batchSize = 1 |
||
| ) |
Evaluate the gradient of the hinge loss function, following the LinearFunctionType requirements on the Gradient function.
| GradType | Type of the gradient matrix. |
| parameters | The parameters of the SVM. |
| firstId | Index of the datapoint to use for the gradient evaluation. |
| gradient | Linear matrix to output the gradient into. |
| batchSize | Size of the batch to process. |
|
static |
Initialize Linear SVM 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 | If true, an intercept is fitted. |
|
inline |
Return the initial point for the optimization.
Definition at line 161 of file linear_svm_function.hpp.
|
inline |
Modify the initial point for the optimization.
Definition at line 163 of file linear_svm_function.hpp.
|
inline |
Sets the regularization parameter.
Definition at line 171 of file linear_svm_function.hpp.
|
inline |
Gets the regularization parameter.
Definition at line 173 of file linear_svm_function.hpp.
| size_t NumFunctions | ( | ) | const |
Return the number of functions.
Referenced by LinearSVMFunction< MatType >::FitIntercept().
| void Shuffle | ( | ) |
Shuffle the dataset.