14 #ifndef MLPACK_METHODS_LINEAR_SVM_LINEAR_SVM_FUNCTION_HPP 15 #define MLPACK_METHODS_LINEAR_SVM_LINEAR_SVM_FUNCTION_HPP 27 template <
typename MatType = arma::mat>
42 const arma::Row<size_t>& labels,
43 const size_t numClasses,
44 const double lambda = 0.0001,
45 const double delta = 1.0,
46 const bool fitIntercept =
false);
64 const size_t featureSize,
65 const size_t numClasses,
66 const bool fitIntercept =
false);
75 arma::sp_mat& groundTruth);
83 double Evaluate(
const arma::mat& parameters);
94 double Evaluate(
const arma::mat& parameters,
96 const size_t batchSize = 1);
106 template <
typename GradType>
107 void Gradient(
const arma::mat& parameters,
120 template <
typename GradType>
121 void Gradient(
const arma::mat& parameters,
122 const size_t firstId,
124 const size_t batchSize = 1);
137 template <
typename GradType>
139 GradType& gradient)
const;
155 template <
typename GradType>
157 const size_t firstId,
159 const size_t batchSize = 1)
const;
167 const arma::sp_mat&
Dataset()
const {
return dataset; }
184 arma::mat initialPoint;
187 arma::sp_mat groundTruth;
209 #include "linear_svm_function_impl.hpp" 211 #endif // MLPACK_METHODS_LINEAR_SVM_LINEAR_SVM_FUNCTION_HPP The hinge loss function for the linear SVM objective function.
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.
double Lambda() const
Gets the regularization parameter.
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.
bool FitIntercept() const
Gets the intercept flag.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double EvaluateWithGradient(const arma::mat ¶meters, GradType &gradient) const
Evaluate the gradient of the hinge loss function, following the LinearFunctionType requirements on th...
arma::mat & InitialPoint()
Modify the initial point for the optimization.
arma::sp_mat & Dataset()
Modify the dataset.
void Shuffle()
Shuffle the dataset.
size_t NumFunctions() const
Return the number of functions.
void GetGroundTruthMatrix(const arma::Row< size_t > &labels, arma::sp_mat &groundTruth)
Constructs the ground truth label matrix with the passed labels.
const arma::mat & InitialPoint() const
Return the initial point for the optimization.
double & Lambda()
Sets the regularization parameter.
void Gradient(const arma::mat ¶meters, GradType &gradient)
Evaluate the gradient of the hinge loss function following the LinearFunctionType requirements on the...
double Evaluate(const arma::mat ¶meters)
Evaluate the hinge loss function for all the datapoints.
const arma::sp_mat & Dataset() const
Get the dataset.