The recommended model type is ASGD (following @cite bottou2010large).
The margin type may have one of the following values: \ref SOFT_MARGIN or \ref HARD_MARGIN.
- You should use \ref HARD_MARGIN type, if you have linearly separable sets.
- You should use \ref SOFT_MARGIN type, if you have non-linearly separable sets or sets with outliers.
- In the general case (if you know nothing about linear separability of your sets), use SOFT_MARGIN.
The other parameters may be described as follows:
- Margin regularization parameter is responsible for weights decreasing at each step and for the strength of restrictions on outliers
(the less the parameter, the less probability that an outlier will be ignored).
Recommended value for SGD model is 0.0001, for ASGD model is 0.00001.
- Initial step size parameter is the initial value for the step size \f$\gamma(t)\f$.
You will have to find the best initial step for your problem.
- Step decreasing power is the power parameter for \f$\gamma(t)\f$ decreasing by the formula, mentioned above.
Recommended value for SGD model is 1, for ASGD model is 0.75.
- Termination criteria can be TermCriteria::COUNT, TermCriteria::EPS or TermCriteria::COUNT + TermCriteria::EPS.
You will have to find the best termination criteria for your problem.
Note that the parameters margin regularization, initial step size, and step decreasing power should be positive.
To use SVMSGD algorithm do as follows:
- first, create the SVMSGD object. The algoorithm will set optimal parameters by default, but you can set your own parameters via functions setSvmsgdType(),
setMarginType(), setMarginRegularization(), setInitialStepSize(), and setStepDecreasingPower().
- then the SVM model can be trained using the train features and the correspondent labels by the method train().
- after that, the label of a new feature vector can be predicted using the method predict().
@code
// Create empty object
cv::Ptr<SVMSGD> svmsgd = SVMSGD::create();
// Train the Stochastic Gradient Descent SVM
svmsgd->train(trainData);
// Predict labels for the new samples
svmsgd->predict(samples, responses);
@endcode
*/
classCV_EXPORTS_WSVMSGD:publiccv::ml::StatModel
{
public:
/** SVMSGD type.
ASGD is often the preferable choice. */
enumSvmsgdType
{
SGD,//!< Stochastic Gradient Descent
ASGD//!< Average Stochastic Gradient Descent
};
/** Margin type.*/
enumMarginType
{
SOFT_MARGIN,//!< General case, suits to the case of non-linearly separable sets, allows outliers.
HARD_MARGIN//!< More accurate for the case of linearly separable sets.
};
/**
* @return the weights of the trained model (decision function f(x) = weights * x + shift).
*/
CV_WRAPvirtualMatgetWeights()=0;
/**
* @return the shift of the trained model (decision function f(x) = weights * x + shift).
*/
CV_WRAPvirtualfloatgetShift()=0;
/** @brief Creates empty model.
* Use StatModel::train to train the model. Since %SVMSGD has several parameters, you may want to
* find the best parameters for your problem or use setOptimalParameters() to set some default parameters.
*/
CV_WRAPstaticPtr<SVMSGD>create();
/** @brief Function sets optimal parameters values for chosen SVM SGD model.
* @param svmsgdType is the type of SVMSGD classifier.
* @param marginType is the type of margin constraint.