OpenCV 4.12.0
开源计算机视觉
加载中...
搜索中...
无匹配项
cv::ml::SVMSGD 类参考abstract

随机梯度下降 SVM 分类器。 更多...

#include <opencv2/ml.hpp>

cv::ml::SVMSGD 协作图

公共类型

枚举  裕度类型 {
  SOFT_MARGIN ,
  HARD_MARGIN
}
 
枚举  Svmsgd类型 {
  SGD ,
  ASGD
}
 
- 从 cv::ml::StatModel 继承的公共类型
枚举  标志 {
  UPDATE_MODEL = 1 ,
  RAW_OUTPUT =1 ,
  COMPRESSED_INPUT =2 ,
  PREPROCESSED_INPUT =4
}
 

公共成员函数

virtual float getInitialStepSize () const =0
 SVMSGD 优化问题的 initialStepSize 参数。
 
virtual float getMarginRegularization () const =0
 SVMSGD 优化问题的 marginRegularization 参数。
 
virtual int getMarginType () const =0
 裕度类型,SVMSGD::MarginType 之一。
 
virtual float getShift ()=0
 
virtual float getStepDecreasingPower () const =0
 SVMSGD 优化问题的 stepDecreasingPower 参数。
 
virtual int getSvmsgdType () const =0
 算法类型,SVMSGD::SvmsgdType 之一。
 
virtual TermCriteria getTermCriteria () const =0
 训练算法的终止条件。您可以指定最大迭代次数 (maxCount) 和/或迭代之间错误变化的程度,以使算法继续执行 (epsilon)。
 
virtual Mat getWeights ()=0
 
virtual void setInitialStepSize (float InitialStepSize)=0
 SVMSGD 优化问题的 initialStepSize 参数。
 
virtual void setMarginRegularization (float marginRegularization)=0
 SVMSGD 优化问题的 marginRegularization 参数。
 
virtual void setMarginType (int marginType)=0
 裕度类型,SVMSGD::MarginType 之一。
 
virtual void setOptimalParameters (int svmsgdType=SVMSGD::ASGD, int marginType=SVMSGD::SOFT_MARGIN)=0
 此函数为所选的 SVM SGD 模型设置最佳参数值。
 
virtual void setStepDecreasingPower (float stepDecreasingPower)=0
 SVMSGD 优化问题的 stepDecreasingPower 参数。
 
virtual void setSvmsgdType (int svmsgdType)=0
 算法类型,SVMSGD::SvmsgdType 之一。
 
virtual void setTermCriteria (const cv::TermCriteria &val)=0
 训练算法的终止条件。您可以指定最大迭代次数 (maxCount) 和/或迭代之间错误变化的程度,以使算法继续执行 (epsilon)。
 
- 从 cv::ml::StatModel 继承的公共成员函数
virtual float calcError (const Ptr< TrainData > &data, bool test, OutputArray resp) const
 计算训练或测试数据集上的误差。
 
virtual bool empty () const CV_OVERRIDE
 如果算法为空(例如,在开始时或读取不成功后),则返回 true。
 
virtual int getVarCount () const =0
 返回训练样本中变量的数量。
 
virtual bool isClassifier () const =0
 如果模型是分类器,则返回 true。
 
virtual bool isTrained () const =0
 如果模型已训练,则返回 true。
 
virtual float predict (InputArray samples, OutputArray results=noArray(), int flags=0) const =0
 预测提供的样本的响应
 
virtual bool train (const Ptr< TrainData > &trainData, int flags=0)
 训练统计模型。
 
virtual bool train (InputArray samples, int layout, InputArray responses)
 训练统计模型。
 
- 从 cv::Algorithm 继承的公共成员函数
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 清除算法状态。
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 从文件存储中读取算法参数。
 
virtual void save (const String &filename) const
 
void write (const Ptr< FileStorage > &fs, const String &name=String()) const
 
virtual void write (FileStorage &fs) const
 将算法参数存储到文件存储中。
 
void write (FileStorage &fs, const String &name) const
 

静态公共成员函数

static Ptr< SVMSGDcreate ()
 创建空模型。使用 StatModel::train 训练模型。由于 SVMSGD 有多个参数,您可能需要为问题找到最佳参数,或使用 setOptimalParameters() 设置一些默认参数。
 
static Ptr< SVMSGDload (const String &filepath, const String &nodeName=String())
 从文件中加载并创建一个序列化的 SVMSGD
 
- 从 cv::ml::StatModel 继承的静态公共成员函数
template<typename _Tp >
static Ptr< _Tptrain (const Ptr< TrainData > &data, int flags=0)
 使用默认参数创建并训练模型。
 
- 从 cv::Algorithm 继承的静态公共成员函数
template<typename _Tp >
static Ptr< _Tpload (const String &filename, const String &objname=String())
 从文件中加载算法。
 
template<typename _Tp >
static Ptr< _TploadFromString (const String &strModel, const String &objname=String())
 从字符串加载算法。
 
template<typename _Tp >
static Ptr< _Tpread (const FileNode &fn)
 从文件节点读取算法。
 

附加继承成员

- 从 cv::Algorithm 继承的保护成员函数
void writeFormat (FileStorage &fs) const
 

详细描述

随机梯度下降 SVM 分类器。

SVMSGD 提供了使用随机梯度下降方法实现 SVM 分类器的快速易用实现,如 [36] 中所述。

该分类器具有以下参数

  • 模型类型,
  • 裕度类型,
  • 裕度正则化 ( \(\lambda\)),
  • 初始步长 ( \(\gamma_0\)),
  • 步长递减幂 ( \(c\)),
  • 和终止条件。

模型类型可以具有以下值之一: SGDASGD

  • SGDSVMSGD 分类器的经典版本:每个后续步骤通过以下公式计算

    \[w_{t+1} = w_t - \gamma(t) \frac{dQ_i}{dw} |_{w = w_t}\]

    其中
    • \(w_t\) 是步骤 \(t\) 处决策函数的权重向量,
    • \(\gamma(t)\) 是迭代 \(t\) 时模型参数的步长,它在每个步骤中通过公式 \(\gamma(t) = \gamma_0 (1 + \lambda \gamma_0 t) ^ {-c}\) 递减
    • \(Q_i\) 是 SVM 任务中编号为 \(i\) 的样本的目标函数,该样本在算法的每个步骤中随机选择。
  • ASGD 是平均随机梯度下降 SVM 分类器。ASGD 分类器在算法的每个步骤中通过公式 \(\widehat{w}_{t+1} = \frac{t}{1+t}\widehat{w}_{t} + \frac{1}{1+t}w_{t+1}\) 平均权重向量

推荐的模型类型是 ASGD(参见 [36])。

裕度类型可以具有以下值之一: SOFT_MARGINHARD_MARGIN

  • 如果您有线性可分离集,则应使用 HARD_MARGIN 类型。
  • 如果您有非线性可分离集或含有异常值的集,则应使用 SOFT_MARGIN 类型。
  • 在一般情况下(如果您对集合的线性可分离性一无所知),请使用 SOFT_MARGIN。

其他参数可描述如下

  • 裕度正则化参数负责每一步的权重递减以及对异常值的限制强度(参数越小,异常值被忽略的可能性越小)。SGD 模型的推荐值为 0.0001,ASGD 模型的推荐值为 0.00001。
  • 初始步长参数是步长 \(\gamma(t)\) 的初始值。您需要为您的问题找到最佳初始步长。
  • 步长递减幂是根据上述公式递减 \(\gamma(t)\) 的幂参数。SGD 模型的推荐值为 1,ASGD 模型的推荐值为 0.75。
  • 终止条件可以是 TermCriteria::COUNTTermCriteria::EPSTermCriteria::COUNT + TermCriteria::EPS。您需要为您的问题找到最佳终止条件。

请注意,参数裕度正则化、初始步长和步长递减幂应为正值。

要使用 SVMSGD 算法,请按以下步骤操作

// 创建空对象
// 训练随机梯度下降 SVM
svmsgd->train(trainData);
// 预测新样本的标签
svmsgd->predict(samples, responses);
static Ptr< SVMSGD > create()
创建空模型。使用 StatModel::train 训练模型。由于 SVMSGD 有多个参数,...
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23

成员枚举文档

◆ 裕度类型

裕度类型。

枚举器
SOFT_MARGIN 

一般情况,适用于非线性可分离集的情况,允许异常值。

HARD_MARGIN 

对于线性可分离集的情况更准确。

◆ Svmsgd类型

SVMSGD 类型。ASGD 通常是首选。

枚举器
SGD 

随机梯度下降。

ASGD 

平均随机梯度下降。

成员函数文档

◆ create()

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

创建空模型。使用 StatModel::train 训练模型。由于 SVMSGD 有多个参数,您可能需要为问题找到最佳参数,或使用 setOptimalParameters() 设置一些默认参数。

◆ getInitialStepSize()

virtual float cv::ml::SVMSGD::getInitialStepSize ( ) const
纯虚函数
Python
cv.ml.SVMSGD.getInitialStepSize() -> retval

SVMSGD 优化问题的 initialStepSize 参数。

另请参见
setInitialStepSize

◆ getMarginRegularization()

virtual float cv::ml::SVMSGD::getMarginRegularization ( ) const
纯虚函数
Python
cv.ml.SVMSGD.getMarginRegularization() -> retval

SVMSGD 优化问题的 marginRegularization 参数。

另请参见
setMarginRegularization

◆ getMarginType()

virtual int cv::ml::SVMSGD::getMarginType ( ) const
纯虚函数
Python
cv.ml.SVMSGD.getMarginType() -> retval

裕度类型,SVMSGD::MarginType 之一。

另请参见
setMarginType

◆ getShift()

virtual float cv::ml::SVMSGD::getShift ( )
纯虚函数
Python
cv.ml.SVMSGD.getShift() -> retval
返回
训练模型的偏移量(决策函数 f(x) = 权重 * x + 偏移)。

◆ getStepDecreasingPower()

virtual float cv::ml::SVMSGD::getStepDecreasingPower ( ) const
纯虚函数
Python
cv.ml.SVMSGD.getStepDecreasingPower() -> retval

SVMSGD 优化问题的 stepDecreasingPower 参数。

另请参见
setStepDecreasingPower

◆ getSvmsgdType()

virtual int cv::ml::SVMSGD::getSvmsgdType ( ) const
纯虚函数
Python
cv.ml.SVMSGD.getSvmsgdType() -> retval

算法类型,SVMSGD::SvmsgdType 之一。

另请参见
setSvmsgdType

◆ getTermCriteria()

virtual TermCriteria cv::ml::SVMSGD::getTermCriteria ( ) const
纯虚函数
Python
cv.ml.SVMSGD.getTermCriteria() -> retval

训练算法的终止条件。您可以指定最大迭代次数 (maxCount) 和/或迭代之间错误变化的程度,以使算法继续执行 (epsilon)。

另请参见
setTermCriteria

◆ getWeights()

virtual Mat cv::ml::SVMSGD::getWeights ( )
纯虚函数
Python
cv.ml.SVMSGD.getWeights() -> retval
返回
训练模型的权重(决策函数 f(x) = 权重 * x + 偏移)。

◆ load()

static Ptr< SVMSGD > cv::ml::SVMSGD::load ( const String & filepath,
const String & nodeName = String() )
static
Python
cv.ml.SVMSGD.load(filepath[, nodeName]) -> retval
cv.ml.SVMSGD_load(filepath[, nodeName]) -> retval

从文件中加载并创建一个序列化的 SVMSGD

使用 SVMSGD::saveSVMSGD 序列化并存储到磁盘。通过使用文件路径调用此函数,再次从该文件加载 SVMSGD。可选地指定包含分类器的文件节点

参数
filepath序列化 SVMSGD 的路径
nodeName包含分类器的节点的名称

◆ setInitialStepSize()

virtual void cv::ml::SVMSGD::setInitialStepSize ( float InitialStepSize)
纯虚函数
Python
cv.ml.SVMSGD.setInitialStepSize(InitialStepSize) ->

SVMSGD 优化问题的 initialStepSize 参数。

另请参见
getInitialStepSize

◆ setMarginRegularization()

virtual void cv::ml::SVMSGD::setMarginRegularization ( float marginRegularization)
纯虚函数
Python
cv.ml.SVMSGD.setMarginRegularization(marginRegularization) ->

SVMSGD 优化问题的 marginRegularization 参数。

另请参见
getMarginRegularization

◆ setMarginType()

virtual void cv::ml::SVMSGD::setMarginType ( int marginType)
纯虚函数
Python
cv.ml.SVMSGD.setMarginType(marginType) ->

裕度类型,SVMSGD::MarginType 之一。

另请参见
getMarginType

◆ setOptimalParameters()

virtual void cv::ml::SVMSGD::setOptimalParameters ( int svmsgdType = SVMSGD::ASGD,
int marginType = SVMSGD::SOFT_MARGIN )
纯虚函数
Python
cv.ml.SVMSGD.setOptimalParameters([, svmsgdType[, marginType]]) ->

此函数为所选的 SVM SGD 模型设置最佳参数值。

参数
svmsgdTypeSVMSGD 分类器的类型。
marginType是裕度约束的类型。

◆ setStepDecreasingPower()

virtual void cv::ml::SVMSGD::setStepDecreasingPower ( float stepDecreasingPower)
纯虚函数
Python
cv.ml.SVMSGD.setStepDecreasingPower(stepDecreasingPower) ->

SVMSGD 优化问题的 stepDecreasingPower 参数。

另请参见
getStepDecreasingPower

◆ setSvmsgdType()

virtual void cv::ml::SVMSGD::setSvmsgdType ( int svmsgdType)
纯虚函数
Python
cv.ml.SVMSGD.setSvmsgdType(svmsgdType) ->

算法类型,SVMSGD::SvmsgdType 之一。

另请参见
getSvmsgdType

◆ setTermCriteria()

virtual void cv::ml::SVMSGD::setTermCriteria ( const cv::TermCriteria & val)
纯虚函数
Python
cv.ml.SVMSGD.setTermCriteria(val) ->

训练算法的终止条件。您可以指定最大迭代次数 (maxCount) 和/或迭代之间错误变化的程度,以使算法继续执行 (epsilon)。

另请参见
getTermCriteria

此类的文档是从以下文件生成的