12#ifndef MLPACK_METHODS_LINEAR_SVM_LINEAR_SVM_HPP
13#define MLPACK_METHODS_LINEAR_SVM_LINEAR_SVM_HPP
16#include <ensmallen.hpp>
79template <
typename MatType = arma::mat>
101 template <
typename OptimizerType,
typename... CallbackTypes>
103 const arma::Row<size_t>& labels,
104 const size_t numClasses,
107 const bool fitIntercept,
108 OptimizerType optimizer,
109 CallbackTypes&&... callbacks);
126 template <
typename OptimizerType = ens::L_BFGS>
128 const arma::Row<size_t>& labels,
129 const size_t numClasses = 2,
130 const double lambda = 0.0001,
131 const double delta = 1.0,
132 const bool fitIntercept =
false,
133 OptimizerType optimizer = OptimizerType());
147 const size_t numClasses = 0,
148 const double lambda = 0.0001,
149 const double delta = 1.0,
150 const bool fitIntercept =
false);
162 const double lambda = 0.0001,
163 const double delta = 1.0,
164 const bool fitIntercept =
false);
176 arma::Row<size_t>& labels)
const;
190 arma::Row<size_t>& labels,
191 arma::mat& scores)
const;
200 arma::mat& scores)
const;
210 template<
typename VecType>
223 const arma::Row<size_t>& testLabels)
const;
238 template <
typename OptimizerType,
typename... CallbackTypes>
240 const arma::Row<size_t>& labels,
241 const size_t numClasses,
242 OptimizerType optimizer,
243 CallbackTypes&&... callbacks);
255 template <
typename OptimizerType = ens::L_BFGS>
257 const arma::Row<size_t>& labels,
258 const size_t numClasses = 2,
259 OptimizerType optimizer = OptimizerType());
275 double Delta()
const {
return delta; }
287 {
return fitIntercept ? parameters.n_rows - 1 :
293 template<
typename Archive>
296 ar & BOOST_SERIALIZATION_NVP(parameters);
297 ar & BOOST_SERIALIZATION_NVP(numClasses);
298 ar & BOOST_SERIALIZATION_NVP(lambda);
299 ar & BOOST_SERIALIZATION_NVP(fitIntercept);
304 arma::mat parameters;
319#include "linear_svm_impl.hpp"
The LinearSVM class implements an L2-regularized support vector machine model, and supports training ...
size_t NumClasses() const
Gets the number of classes.
arma::mat & Parameters()
Set the model parameters.
LinearSVM(const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses=2, const double lambda=0.0001, const double delta=1.0, const bool fitIntercept=false, OptimizerType optimizer=OptimizerType())
Construct the LinearSVM class with the provided data and labels.
const arma::mat & Parameters() const
Get the model parameters.
LinearSVM(const size_t numClasses=0, const double lambda=0.0001, const double delta=1.0, const bool fitIntercept=false)
Initialize the Linear SVM without performing training.
double & Lambda()
Sets the regularization parameter.
double Lambda() const
Gets the regularization parameter.
void Classify(const MatType &data, arma::mat &scores) const
Classify the given points, returning class scores for each point.
double ComputeAccuracy(const MatType &testData, const arma::Row< size_t > &testLabels) const
Computes accuracy of the learned model given the feature data and the labels associated with each dat...
double & Delta()
Sets the margin between the correct class and all other classes.
size_t FeatureSize() const
Gets the features size of the training data.
double Train(const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses, OptimizerType optimizer, CallbackTypes &&... callbacks)
Train the Linear SVM with the given training data.
size_t & NumClasses()
Sets the number of classes.
void Classify(const MatType &data, arma::Row< size_t > &labels, arma::mat &scores) const
Classify the given points, returning class scores and predicted class label for each point.
double Train(const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses=2, OptimizerType optimizer=OptimizerType())
Train the Linear SVM with the given training data.
void Classify(const MatType &data, arma::Row< size_t > &labels) const
Classify the given points, returning the predicted labels for each point.
size_t Classify(const VecType &point) const
Classify the given point.
LinearSVM(const size_t inputSize, const size_t numClasses=0, const double lambda=0.0001, const double delta=1.0, const bool fitIntercept=false)
Initialize the Linear SVM without performing training.
double Delta() const
Gets the margin between the correct class and all other classes.
bool & FitIntercept()
Sets the intercept term flag.
LinearSVM(const MatType &data, const arma::Row< size_t > &labels, const size_t numClasses, const double lambda, const double delta, const bool fitIntercept, OptimizerType optimizer, CallbackTypes &&... callbacks)
Construct the LinearSVM class with the provided data and labels.
void serialize(Archive &ar, const unsigned int)
Serialize the LinearSVM model.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.