|
mlpack
|
The hinge loss function for the linear SVM objective function. More...
#include <linear_svm_function.hpp>
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... | |
| void | Shuffle () |
| Shuffle the dataset. More... | |
| void | GetGroundTruthMatrix (const arma::Row< size_t > &labels, arma::sp_mat &groundTruth) |
| Constructs the ground truth label matrix with the passed labels. 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 > | |
| 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... | |
| 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... | |
| const arma::mat & | InitialPoint () const |
| Return the initial point for the optimization. | |
| arma::mat & | InitialPoint () |
| Modify the initial point for the optimization. | |
| const arma::sp_mat & | Dataset () const |
| Get the dataset. | |
| arma::sp_mat & | Dataset () |
| Modify the dataset. | |
| double & | Lambda () |
| Sets the regularization parameter. | |
| double | Lambda () const |
| Gets the regularization parameter. | |
| bool | FitIntercept () const |
| Gets the intercept flag. | |
| size_t | NumFunctions () const |
| Return the number of functions. | |
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.
| mlpack::svm::LinearSVMFunction< MatType >::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. |
| double mlpack::svm::LinearSVMFunction< MatType >::Evaluate | ( | const arma::mat & | parameters | ) |
Evaluate the hinge loss function for all the datapoints.
| parameters | The parameters of the SVM. |
| double mlpack::svm::LinearSVMFunction< MatType >::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 mlpack::svm::LinearSVMFunction< MatType >::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 mlpack::svm::LinearSVMFunction< MatType >::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. |
| void mlpack::svm::LinearSVMFunction< MatType >::GetGroundTruthMatrix | ( | const arma::Row< size_t > & | labels, |
| arma::sp_mat & | groundTruth | ||
| ) |
Constructs the ground truth label matrix with the passed labels.
This is equivalent to applying the indicator function to the training labels.
| labels | Labels associated with the training data. |
| groundTruth | Pointer to arma::mat which stores the computed matrix. |
The output is in the form of a matrix, which leads to simpler calculations in the Evaluate() and Gradient() methods.
| void mlpack::svm::LinearSVMFunction< MatType >::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 mlpack::svm::LinearSVMFunction< MatType >::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.
Initializes parameter weights to random values taken from a scaled standard normal distribution.
| 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. |
The weights cannot be initialized to zero, as that will lead to each class output being the same.
| void mlpack::svm::LinearSVMFunction< MatType >::Shuffle | ( | ) |
Shuffle the dataset.
Shuffle the data.
1.8.13