OpenCV  4.1.0
Open Source Computer Vision
Public Types | Public Member Functions | Static Public Member Functions | List of all members
cv::ml::SVMSGD Class Referenceabstract

Stochastic Gradient Descent SVM classifier. More...

#include <opencv2/ml.hpp>

Inheritance diagram for cv::ml::SVMSGD:
cv::ml::StatModel cv::Algorithm

Public Types

enum  MarginType {
  SOFT_MARGIN,
  HARD_MARGIN
}
 
enum  SvmsgdType {
  SGD,
  ASGD
}
 
- Public Types inherited from cv::ml::StatModel
enum  Flags {
  UPDATE_MODEL = 1,
  RAW_OUTPUT =1,
  COMPRESSED_INPUT =2,
  PREPROCESSED_INPUT =4
}
 

Public Member Functions

virtual float getInitialStepSize () const =0
 Parameter initialStepSize of a SVMSGD optimization problem.
 
virtual float getMarginRegularization () const =0
 Parameter marginRegularization of a SVMSGD optimization problem.
 
virtual int getMarginType () const =0
 Margin type, one of SVMSGD::MarginType.
 
virtual float getShift ()=0
 
virtual float getStepDecreasingPower () const =0
 Parameter stepDecreasingPower of a SVMSGD optimization problem.
 
virtual int getSvmsgdType () const =0
 Algorithm type, one of SVMSGD::SvmsgdType.
 
virtual TermCriteria getTermCriteria () const =0
 Termination criteria of the training algorithm. You can specify the maximum number of iterations (maxCount) and/or how much the error could change between the iterations to make the algorithm continue (epsilon).
 
virtual Mat getWeights ()=0
 
virtual void setInitialStepSize (float InitialStepSize)=0
 
virtual void setMarginRegularization (float marginRegularization)=0
 
virtual void setMarginType (int marginType)=0
 
virtual void setOptimalParameters (int svmsgdType=SVMSGD::ASGD, int marginType=SVMSGD::SOFT_MARGIN)=0
 Function sets optimal parameters values for chosen SVM SGD model.
 
virtual void setStepDecreasingPower (float stepDecreasingPower)=0
 
virtual void setSvmsgdType (int svmsgdType)=0
 
virtual void setTermCriteria (const cv::TermCriteria &val)=0
 
- Public Member Functions inherited from cv::ml::StatModel
virtual float calcError (const Ptr< TrainData > &data, bool test, OutputArray resp) const
 Computes error on the training or test dataset.
 
virtual bool empty () const CV_OVERRIDE
 Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.
 
virtual int getVarCount () const =0
 Returns the number of variables in training samples.
 
virtual bool isClassifier () const =0
 Returns true if the model is classifier.
 
virtual bool isTrained () const =0
 Returns true if the model is trained.
 
virtual float predict (InputArray samples, OutputArray results=noArray(), int flags=0) const =0
 Predicts response(s) for the provided sample(s)
 
virtual bool train (const Ptr< TrainData > &trainData, int flags=0)
 Trains the statistical model.
 
virtual bool train (InputArray samples, int layout, InputArray responses)
 Trains the statistical model.
 
- Public Member Functions inherited from cv::Algorithm
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 Clears the algorithm state.
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 Reads algorithm parameters from a file storage.
 
virtual void save (const String &filename) const
 
virtual void write (FileStorage &fs) const
 Stores algorithm parameters in a file storage.
 
void write (const Ptr< FileStorage > &fs, const String &name=String()) const
 simplified API for language bindingsThis is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 

Static Public Member Functions

static Ptr< SVMSGDcreate ()
 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.
 
static Ptr< SVMSGDload (const String &filepath, const String &nodeName=String())
 Loads and creates a serialized SVMSGD from a file.
 
- Static Public Member Functions inherited from cv::ml::StatModel
template<typename _Tp >
static Ptr< _Tp > train (const Ptr< TrainData > &data, int flags=0)
 Create and train model with default parameters.
 
- Static Public Member Functions inherited from cv::Algorithm
template<typename _Tp >
static Ptr< _Tp > load (const String &filename, const String &objname=String())
 Loads algorithm from the file.
 
template<typename _Tp >
static Ptr< _Tp > loadFromString (const String &strModel, const String &objname=String())
 Loads algorithm from a String.
 
template<typename _Tp >
static Ptr< _Tp > read (const FileNode &fn)
 Reads algorithm from the file node.
 

Additional Inherited Members

- Protected Member Functions inherited from cv::Algorithm
void writeFormat (FileStorage &fs) const
 

Detailed Description

Stochastic Gradient Descent SVM classifier.

SVMSGD provides a fast and easy-to-use implementation of the SVM classifier using the Stochastic Gradient Descent approach, as presented inbottou2010large.

The classifier has following parameters:

The model type may have one of the following values: SGD and ASGD.

The recommended model type is ASGD (followingbottou2010large).

The margin type may have one of the following values: SOFT_MARGIN or HARD_MARGIN.

The other parameters may be described as follows:

Note that the parameters margin regularization, initial step size, and step decreasing power should be positive.

To use SVMSGD algorithm do as follows:

// Create empty object
// Train the Stochastic Gradient Descent SVM
svmsgd->train(trainData);
// Predict labels for the new samples
svmsgd->predict(samples, responses);

Member Enumeration Documentation

Margin type.

Enumerator
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.

SVMSGD type.

ASGD is often the preferable choice.

Enumerator
SGD 

Stochastic Gradient Descent.

ASGD 

Average Stochastic Gradient Descent.

Member Function Documentation

static Ptr<SVMSGD> cv::ml::SVMSGD::create ( )
static
Python:
retval=cv.ml.SVMSGD_create()

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.

virtual float cv::ml::SVMSGD::getInitialStepSize ( ) const
pure virtual
Python:
retval=cv.ml_SVMSGD.getInitialStepSize()

Parameter initialStepSize of a SVMSGD optimization problem.

See Also
setInitialStepSize
virtual float cv::ml::SVMSGD::getMarginRegularization ( ) const
pure virtual
Python:
retval=cv.ml_SVMSGD.getMarginRegularization()

Parameter marginRegularization of a SVMSGD optimization problem.

See Also
setMarginRegularization
virtual int cv::ml::SVMSGD::getMarginType ( ) const
pure virtual
Python:
retval=cv.ml_SVMSGD.getMarginType()

Margin type, one of SVMSGD::MarginType.

See Also
setMarginType
virtual float cv::ml::SVMSGD::getShift ( )
pure virtual
Python:
retval=cv.ml_SVMSGD.getShift()
Returns
the shift of the trained model (decision function f(x) = weights * x + shift).
virtual float cv::ml::SVMSGD::getStepDecreasingPower ( ) const
pure virtual
Python:
retval=cv.ml_SVMSGD.getStepDecreasingPower()

Parameter stepDecreasingPower of a SVMSGD optimization problem.

See Also
setStepDecreasingPower
virtual int cv::ml::SVMSGD::getSvmsgdType ( ) const
pure virtual
Python:
retval=cv.ml_SVMSGD.getSvmsgdType()

Algorithm type, one of SVMSGD::SvmsgdType.

See Also
setSvmsgdType
virtual TermCriteria cv::ml::SVMSGD::getTermCriteria ( ) const
pure virtual
Python:
retval=cv.ml_SVMSGD.getTermCriteria()

Termination criteria of the training algorithm. You can specify the maximum number of iterations (maxCount) and/or how much the error could change between the iterations to make the algorithm continue (epsilon).

See Also
setTermCriteria
virtual Mat cv::ml::SVMSGD::getWeights ( )
pure virtual
Python:
retval=cv.ml_SVMSGD.getWeights()
Returns
the weights of the trained model (decision function f(x) = weights * x + shift).
static Ptr<SVMSGD> cv::ml::SVMSGD::load ( const String filepath,
const String nodeName = String() 
)
static
Python:
retval=cv.ml.SVMSGD_load(filepath[, nodeName])

Loads and creates a serialized SVMSGD from a file.

Use SVMSGD::save to serialize and store an SVMSGD to disk. Load the SVMSGD from this file again, by calling this function with the path to the file. Optionally specify the node for the file containing the classifier

Parameters
filepathpath to serialized SVMSGD
nodeNamename of node containing the classifier
virtual void cv::ml::SVMSGD::setInitialStepSize ( float  InitialStepSize)
pure virtual
Python:
None=cv.ml_SVMSGD.setInitialStepSize(InitialStepSize)

Parameter initialStepSize of a SVMSGD optimization problem.

See Also
getInitialStepSize
virtual void cv::ml::SVMSGD::setMarginRegularization ( float  marginRegularization)
pure virtual
Python:
None=cv.ml_SVMSGD.setMarginRegularization(marginRegularization)

Parameter marginRegularization of a SVMSGD optimization problem.

See Also
getMarginRegularization
virtual void cv::ml::SVMSGD::setMarginType ( int  marginType)
pure virtual
Python:
None=cv.ml_SVMSGD.setMarginType(marginType)

Margin type, one of SVMSGD::MarginType.

See Also
getMarginType
virtual void cv::ml::SVMSGD::setOptimalParameters ( int  svmsgdType = SVMSGD::ASGD,
int  marginType = SVMSGD::SOFT_MARGIN 
)
pure virtual
Python:
None=cv.ml_SVMSGD.setOptimalParameters([, svmsgdType[, marginType]])

Function sets optimal parameters values for chosen SVM SGD model.

Parameters
svmsgdTypeis the type of SVMSGD classifier.
marginTypeis the type of margin constraint.
virtual void cv::ml::SVMSGD::setStepDecreasingPower ( float  stepDecreasingPower)
pure virtual
Python:
None=cv.ml_SVMSGD.setStepDecreasingPower(stepDecreasingPower)

Parameter stepDecreasingPower of a SVMSGD optimization problem.

See Also
getStepDecreasingPower
virtual void cv::ml::SVMSGD::setSvmsgdType ( int  svmsgdType)
pure virtual
Python:
None=cv.ml_SVMSGD.setSvmsgdType(svmsgdType)

Algorithm type, one of SVMSGD::SvmsgdType.

See Also
getSvmsgdType
virtual void cv::ml::SVMSGD::setTermCriteria ( const cv::TermCriteria val)
pure virtual
Python:
None=cv.ml_SVMSGD.setTermCriteria(val)

Termination criteria of the training algorithm. You can specify the maximum number of iterations (maxCount) and/or how much the error could change between the iterations to make the algorithm continue (epsilon).

See Also
getTermCriteria

The documentation for this class was generated from the following file: