ml: refactor non-virtual methods
This commit is contained in:
+28
-31
@@ -50,13 +50,6 @@ static const int VAR_MISSED = VAR_ORDERED;
|
||||
|
||||
TrainData::~TrainData() {}
|
||||
|
||||
Mat TrainData::getTestSamples() const
|
||||
{
|
||||
Mat idx = getTestSampleIdx();
|
||||
Mat samples = getSamples();
|
||||
return idx.empty() ? Mat() : getSubVector(samples, idx);
|
||||
}
|
||||
|
||||
Mat TrainData::getSubVector(const Mat& vec, const Mat& idx)
|
||||
{
|
||||
if( idx.empty() )
|
||||
@@ -119,6 +112,7 @@ Mat TrainData::getSubVector(const Mat& vec, const Mat& idx)
|
||||
return subvec;
|
||||
}
|
||||
|
||||
|
||||
class TrainDataImpl CV_FINAL : public TrainData
|
||||
{
|
||||
public:
|
||||
@@ -155,6 +149,12 @@ public:
|
||||
return layout == ROW_SAMPLE ? samples.cols : samples.rows;
|
||||
}
|
||||
|
||||
Mat getTestSamples() const CV_OVERRIDE
|
||||
{
|
||||
Mat idx = getTestSampleIdx();
|
||||
return idx.empty() ? Mat() : getSubVector(samples, idx);
|
||||
}
|
||||
|
||||
Mat getSamples() const CV_OVERRIDE { return samples; }
|
||||
Mat getResponses() const CV_OVERRIDE { return responses; }
|
||||
Mat getMissing() const CV_OVERRIDE { return missing; }
|
||||
@@ -987,6 +987,27 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void getNames(std::vector<String>& names) const CV_OVERRIDE
|
||||
{
|
||||
size_t n = nameMap.size();
|
||||
TrainDataImpl::MapType::const_iterator it = nameMap.begin(),
|
||||
it_end = nameMap.end();
|
||||
names.resize(n+1);
|
||||
names[0] = "?";
|
||||
for( ; it != it_end; ++it )
|
||||
{
|
||||
String s = it->first;
|
||||
int label = it->second;
|
||||
CV_Assert( label > 0 && label <= (int)n );
|
||||
names[label] = s;
|
||||
}
|
||||
}
|
||||
|
||||
Mat getVarSymbolFlags() const CV_OVERRIDE
|
||||
{
|
||||
return varSymbolFlags;
|
||||
}
|
||||
|
||||
FILE* file;
|
||||
int layout;
|
||||
Mat samples, missing, varType, varIdx, varSymbolFlags, responses, missingSubst;
|
||||
@@ -996,30 +1017,6 @@ public:
|
||||
MapType nameMap;
|
||||
};
|
||||
|
||||
void TrainData::getNames(std::vector<String>& names) const
|
||||
{
|
||||
const TrainDataImpl* impl = dynamic_cast<const TrainDataImpl*>(this);
|
||||
CV_Assert(impl != 0);
|
||||
size_t n = impl->nameMap.size();
|
||||
TrainDataImpl::MapType::const_iterator it = impl->nameMap.begin(),
|
||||
it_end = impl->nameMap.end();
|
||||
names.resize(n+1);
|
||||
names[0] = "?";
|
||||
for( ; it != it_end; ++it )
|
||||
{
|
||||
String s = it->first;
|
||||
int label = it->second;
|
||||
CV_Assert( label > 0 && label <= (int)n );
|
||||
names[label] = s;
|
||||
}
|
||||
}
|
||||
|
||||
Mat TrainData::getVarSymbolFlags() const
|
||||
{
|
||||
const TrainDataImpl* impl = dynamic_cast<const TrainDataImpl*>(this);
|
||||
CV_Assert(impl != 0);
|
||||
return impl->varSymbolFlags;
|
||||
}
|
||||
|
||||
Ptr<TrainData> TrainData::loadFromCSV(const String& filename,
|
||||
int headerLines,
|
||||
|
||||
@@ -453,6 +453,7 @@ public:
|
||||
inline void setRegressionAccuracy(float val) CV_OVERRIDE { impl.params.setRegressionAccuracy(val); }
|
||||
inline cv::Mat getPriors() const CV_OVERRIDE { return impl.params.getPriors(); }
|
||||
inline void setPriors(const cv::Mat& val) CV_OVERRIDE { impl.params.setPriors(val); }
|
||||
inline void getVotes(InputArray input, OutputArray output, int flags) const CV_OVERRIDE {return impl.getVotes(input,output,flags);}
|
||||
|
||||
RTreesImpl() {}
|
||||
virtual ~RTreesImpl() CV_OVERRIDE {}
|
||||
@@ -485,12 +486,6 @@ public:
|
||||
impl.read(fn);
|
||||
}
|
||||
|
||||
void getVotes_( InputArray samples, OutputArray results, int flags ) const
|
||||
{
|
||||
CV_TRACE_FUNCTION();
|
||||
impl.getVotes(samples, results, flags);
|
||||
}
|
||||
|
||||
Mat getVarImportance() const CV_OVERRIDE { return Mat_<float>(impl.varImportance, true); }
|
||||
int getVarCount() const CV_OVERRIDE { return impl.getVarCount(); }
|
||||
|
||||
@@ -519,15 +514,6 @@ Ptr<RTrees> RTrees::load(const String& filepath, const String& nodeName)
|
||||
return Algorithm::load<RTrees>(filepath, nodeName);
|
||||
}
|
||||
|
||||
void RTrees::getVotes(InputArray input, OutputArray output, int flags) const
|
||||
{
|
||||
CV_TRACE_FUNCTION();
|
||||
const RTreesImpl* this_ = dynamic_cast<const RTreesImpl*>(this);
|
||||
if(!this_)
|
||||
CV_Error(Error::StsNotImplemented, "the class is not RTreesImpl");
|
||||
return this_->getVotes_(input, output, flags);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
// End of file.
|
||||
|
||||
+3
-23
@@ -1250,7 +1250,7 @@ public:
|
||||
uncompressed_sv.release();
|
||||
}
|
||||
|
||||
Mat getUncompressedSupportVectors_() const
|
||||
Mat getUncompressedSupportVectors() const CV_OVERRIDE
|
||||
{
|
||||
return uncompressed_sv;
|
||||
}
|
||||
@@ -1982,10 +1982,10 @@ public:
|
||||
bool returnDFVal;
|
||||
};
|
||||
|
||||
bool trainAuto_(InputArray samples, int layout,
|
||||
bool trainAuto(InputArray samples, int layout,
|
||||
InputArray responses, int kfold, Ptr<ParamGrid> Cgrid,
|
||||
Ptr<ParamGrid> gammaGrid, Ptr<ParamGrid> pGrid, Ptr<ParamGrid> nuGrid,
|
||||
Ptr<ParamGrid> coeffGrid, Ptr<ParamGrid> degreeGrid, bool balanced)
|
||||
Ptr<ParamGrid> coeffGrid, Ptr<ParamGrid> degreeGrid, bool balanced) CV_OVERRIDE
|
||||
{
|
||||
Ptr<TrainData> data = TrainData::create(samples, layout, responses);
|
||||
return this->trainAuto(
|
||||
@@ -2353,26 +2353,6 @@ Ptr<SVM> SVM::load(const String& filepath)
|
||||
return svm;
|
||||
}
|
||||
|
||||
Mat SVM::getUncompressedSupportVectors() const
|
||||
{
|
||||
const SVMImpl* this_ = dynamic_cast<const SVMImpl*>(this);
|
||||
if(!this_)
|
||||
CV_Error(Error::StsNotImplemented, "the class is not SVMImpl");
|
||||
return this_->getUncompressedSupportVectors_();
|
||||
}
|
||||
|
||||
bool SVM::trainAuto(InputArray samples, int layout,
|
||||
InputArray responses, int kfold, Ptr<ParamGrid> Cgrid,
|
||||
Ptr<ParamGrid> gammaGrid, Ptr<ParamGrid> pGrid, Ptr<ParamGrid> nuGrid,
|
||||
Ptr<ParamGrid> coeffGrid, Ptr<ParamGrid> degreeGrid, bool balanced)
|
||||
{
|
||||
SVMImpl* this_ = dynamic_cast<SVMImpl*>(this);
|
||||
if (!this_) {
|
||||
CV_Error(Error::StsNotImplemented, "the class is not SVMImpl");
|
||||
}
|
||||
return this_->trainAuto_(samples, layout, responses,
|
||||
kfold, Cgrid, gammaGrid, pGrid, nuGrid, coeffGrid, degreeGrid, balanced);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user