mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
Corrected spelling mistakes
This commit is contained in:
parent
5496dedd6a
commit
ff54952769
@ -1535,7 +1535,7 @@ The margin type may have one of the following values: \ref SOFT_MARGIN or \ref H
|
|||||||
|
|
||||||
- You should use \ref HARD_MARGIN type, if you have linearly separable sets.
|
- 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.
|
- 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 linearly separability of your sets), use SOFT_MARGIN.
|
- 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:
|
The other parameters may be described as follows:
|
||||||
- \f$\lambda\f$ parameter is responsible for weights decreasing at each step and for the strength of restrictions on outliers
|
- \f$\lambda\f$ parameter is responsible for weights decreasing at each step and for the strength of restrictions on outliers
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
// For Open Source Computer Vision Library
|
// For Open Source Computer Vision Library
|
||||||
//
|
//
|
||||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||||
// Copyright (C) 2014, Itseez Inc, all rights reserved.
|
// Copyright (C) 2016, Itseez Inc, all rights reserved.
|
||||||
// Third party copyrights are property of their respective owners.
|
// Third party copyrights are property of their respective owners.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without modification,
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||||
@ -103,7 +103,7 @@ public:
|
|||||||
CV_IMPL_PROPERTY_S(cv::TermCriteria, TermCriteria, params.termCrit)
|
CV_IMPL_PROPERTY_S(cv::TermCriteria, TermCriteria, params.termCrit)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateWeights(InputArray sample, bool isFirstClass, float gamma, Mat &weights);
|
void updateWeights(InputArray sample, bool isPositive, float gamma, Mat &weights);
|
||||||
|
|
||||||
std::pair<bool,bool> areClassesEmpty(Mat responses);
|
std::pair<bool,bool> areClassesEmpty(Mat responses);
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ private:
|
|||||||
|
|
||||||
void readParams( const FileNode &fn );
|
void readParams( const FileNode &fn );
|
||||||
|
|
||||||
static inline bool isFirstClass(float val) { return val > 0; }
|
static inline bool isPositive(float val) { return val > 0; }
|
||||||
|
|
||||||
static void normalizeSamples(Mat &matrix, Mat &average, float &multiplier);
|
static void normalizeSamples(Mat &matrix, Mat &average, float &multiplier);
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ std::pair<bool,bool> SVMSGDImpl::areClassesEmpty(Mat responses)
|
|||||||
|
|
||||||
for(int index = 0; index < limit_index; index++)
|
for(int index = 0; index < limit_index; index++)
|
||||||
{
|
{
|
||||||
if (isFirstClass(responses.at<float>(index)))
|
if (isPositive(responses.at<float>(index)))
|
||||||
emptyInClasses.first = false;
|
emptyInClasses.first = false;
|
||||||
else
|
else
|
||||||
emptyInClasses.second = false;
|
emptyInClasses.second = false;
|
||||||
@ -172,7 +172,7 @@ void SVMSGDImpl::normalizeSamples(Mat &samples, Mat &average, float &multiplier)
|
|||||||
average = Mat(1, featuresCount, samples.type());
|
average = Mat(1, featuresCount, samples.type());
|
||||||
for (int featureIndex = 0; featureIndex < featuresCount; featureIndex++)
|
for (int featureIndex = 0; featureIndex < featuresCount; featureIndex++)
|
||||||
{
|
{
|
||||||
Scalar scalAverage = mean(samples.col(featureIndex))[0];
|
Scalar scalAverage = mean(samples.col(featureIndex));
|
||||||
average.at<float>(featureIndex) = static_cast<float>(scalAverage[0]);
|
average.at<float>(featureIndex) = static_cast<float>(scalAverage[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,13 +190,13 @@ void SVMSGDImpl::normalizeSamples(Mat &samples, Mat &average, float &multiplier)
|
|||||||
|
|
||||||
void SVMSGDImpl::makeExtendedTrainSamples(const Mat &trainSamples, Mat &extendedTrainSamples, Mat &average, float &multiplier)
|
void SVMSGDImpl::makeExtendedTrainSamples(const Mat &trainSamples, Mat &extendedTrainSamples, Mat &average, float &multiplier)
|
||||||
{
|
{
|
||||||
Mat normalisedTrainSamples = trainSamples.clone();
|
Mat normalizedTrainSamples = trainSamples.clone();
|
||||||
int samplesCount = normalisedTrainSamples.rows;
|
int samplesCount = normalizedTrainSamples.rows;
|
||||||
|
|
||||||
normalizeSamples(normalisedTrainSamples, average, multiplier);
|
normalizeSamples(normalizedTrainSamples, average, multiplier);
|
||||||
|
|
||||||
Mat onesCol = Mat::ones(samplesCount, 1, CV_32F);
|
Mat onesCol = Mat::ones(samplesCount, 1, CV_32F);
|
||||||
cv::hconcat(normalisedTrainSamples, onesCol, extendedTrainSamples);
|
cv::hconcat(normalizedTrainSamples, onesCol, extendedTrainSamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SVMSGDImpl::updateWeights(InputArray _sample, bool firstClass, float gamma, Mat& weights)
|
void SVMSGDImpl::updateWeights(InputArray _sample, bool firstClass, float gamma, Mat& weights)
|
||||||
@ -231,7 +231,7 @@ float SVMSGDImpl::calcShift(InputArray _samples, InputArray _responses) const
|
|||||||
Mat currentSample = trainSamples.row(samplesIndex);
|
Mat currentSample = trainSamples.row(samplesIndex);
|
||||||
float dotProduct = static_cast<float>(currentSample.dot(weights_));
|
float dotProduct = static_cast<float>(currentSample.dot(weights_));
|
||||||
|
|
||||||
bool firstClass = isFirstClass(trainResponses.at<float>(samplesIndex));
|
bool firstClass = isPositive(trainResponses.at<float>(samplesIndex));
|
||||||
int index = firstClass ? 0 : 1;
|
int index = firstClass ? 0 : 1;
|
||||||
float signToMul = firstClass ? 1.f : -1.f;
|
float signToMul = firstClass ? 1.f : -1.f;
|
||||||
float curDistance = dotProduct * signToMul;
|
float curDistance = dotProduct * signToMul;
|
||||||
@ -297,11 +297,10 @@ bool SVMSGDImpl::train(const Ptr<TrainData>& data, int)
|
|||||||
int randomNumber = rng.uniform(0, extendedTrainSamplesCount); //generate sample number
|
int randomNumber = rng.uniform(0, extendedTrainSamplesCount); //generate sample number
|
||||||
|
|
||||||
Mat currentSample = extendedTrainSamples.row(randomNumber);
|
Mat currentSample = extendedTrainSamples.row(randomNumber);
|
||||||
bool firstClass = isFirstClass(trainResponses.at<float>(randomNumber));
|
|
||||||
|
|
||||||
float gamma = params.gamma0 * std::pow((1 + params.lambda * params.gamma0 * (float)iter), (-params.c)); //update gamma
|
float gamma = params.gamma0 * std::pow((1 + params.lambda * params.gamma0 * (float)iter), (-params.c)); //update gamma
|
||||||
|
|
||||||
updateWeights( currentSample, firstClass, gamma, extendedWeights );
|
updateWeights( currentSample, isPositive(trainResponses.at<float>(randomNumber)), gamma, extendedWeights );
|
||||||
|
|
||||||
//average weights (only for ASGD model)
|
//average weights (only for ASGD model)
|
||||||
if (params.svmsgdType == ASGD)
|
if (params.svmsgdType == ASGD)
|
||||||
|
@ -134,7 +134,7 @@ void CV_SVMSGDTrainTest::makeTestData(Mat weights, float shift)
|
|||||||
{
|
{
|
||||||
int testSamplesCount = 100000;
|
int testSamplesCount = 100000;
|
||||||
int featureCount = weights.cols;
|
int featureCount = weights.cols;
|
||||||
cv::RNG rng(0);
|
cv::RNG rng(42);
|
||||||
|
|
||||||
testSamples.create(testSamplesCount, featureCount, CV_32FC1);
|
testSamples.create(testSamplesCount, featureCount, CV_32FC1);
|
||||||
for (int featureIndex = 0; featureIndex < featureCount; featureIndex++)
|
for (int featureIndex = 0; featureIndex < featureCount; featureIndex++)
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
using namespace cv;
|
using namespace cv;
|
||||||
using namespace cv::ml;
|
using namespace cv::ml;
|
||||||
|
|
||||||
#define WIDTH 841
|
|
||||||
#define HEIGHT 594
|
|
||||||
|
|
||||||
struct Data
|
struct Data
|
||||||
{
|
{
|
||||||
@ -17,6 +15,8 @@ struct Data
|
|||||||
|
|
||||||
Data()
|
Data()
|
||||||
{
|
{
|
||||||
|
const int WIDTH = 841;
|
||||||
|
const int HEIGHT = 594;
|
||||||
img = Mat::zeros(HEIGHT, WIDTH, CV_8UC3);
|
img = Mat::zeros(HEIGHT, WIDTH, CV_8UC3);
|
||||||
imshow("Train svmsgd", img);
|
imshow("Train svmsgd", img);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user