minor refactoring of CvMLData interface
This commit is contained in:
@@ -48,7 +48,6 @@ CvTrainTestSplit::CvTrainTestSplit()
|
||||
{
|
||||
train_sample_part_mode = CV_COUNT;
|
||||
train_sample_part.count = -1;
|
||||
class_part = 0;
|
||||
mix = false;
|
||||
}
|
||||
|
||||
@@ -56,7 +55,6 @@ CvTrainTestSplit::CvTrainTestSplit( int _train_sample_count, bool _mix )
|
||||
{
|
||||
train_sample_part_mode = CV_COUNT;
|
||||
train_sample_part.count = _train_sample_count;
|
||||
class_part = 0;
|
||||
mix = _mix;
|
||||
}
|
||||
|
||||
@@ -64,7 +62,6 @@ CvTrainTestSplit::CvTrainTestSplit( float _train_sample_portion, bool _mix )
|
||||
{
|
||||
train_sample_part_mode = CV_PORTION;
|
||||
train_sample_part.portion = _train_sample_portion;
|
||||
class_part = 0;
|
||||
mix = _mix;
|
||||
}
|
||||
|
||||
@@ -83,14 +80,12 @@ CvMLData::CvMLData()
|
||||
miss_ch = '?';
|
||||
//flt_separator = '.';
|
||||
|
||||
class_map = new std::map<std::string, int>();
|
||||
rng = &cv::theRNG();
|
||||
}
|
||||
|
||||
CvMLData::~CvMLData()
|
||||
{
|
||||
clear();
|
||||
delete class_map;
|
||||
}
|
||||
|
||||
void CvMLData::free_train_test_idx()
|
||||
@@ -102,8 +97,7 @@ void CvMLData::free_train_test_idx()
|
||||
|
||||
void CvMLData::clear()
|
||||
{
|
||||
if ( !class_map->empty() )
|
||||
class_map->clear();
|
||||
class_map.clear();
|
||||
|
||||
cvReleaseMat( &values );
|
||||
cvReleaseMat( &missing );
|
||||
@@ -244,16 +238,29 @@ int CvMLData::read_csv(const char* filename)
|
||||
return 0;
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_values()
|
||||
const CvMat* CvMLData::get_values() const
|
||||
{
|
||||
return values;
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_missing()
|
||||
const CvMat* CvMLData::get_missing() const
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_missing" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
|
||||
__END__;
|
||||
|
||||
return missing;
|
||||
}
|
||||
|
||||
const std::map<std::string, int>& CvMLData::get_class_labels_map() const
|
||||
{
|
||||
return class_map;
|
||||
}
|
||||
|
||||
void CvMLData::str_to_flt_elem( const char* token, float& flt_elem, int& type)
|
||||
{
|
||||
|
||||
@@ -270,12 +277,12 @@ void CvMLData::str_to_flt_elem( const char* token, float& flt_elem, int& type)
|
||||
{
|
||||
if ( (*stopstring != 0) && (*stopstring != '\n') && (strcmp(stopstring, "\r\n") != 0) ) // class label
|
||||
{
|
||||
int idx = (*class_map)[token];
|
||||
int idx = class_map[token];
|
||||
if ( idx == 0)
|
||||
{
|
||||
total_class_count++;
|
||||
idx = total_class_count;
|
||||
(*class_map)[token] = idx;
|
||||
class_map[token] = idx;
|
||||
}
|
||||
flt_elem = (float)idx;
|
||||
type = CV_VAR_CATEGORICAL;
|
||||
@@ -296,7 +303,7 @@ void CvMLData::set_delimiter(char ch)
|
||||
__END__;
|
||||
}
|
||||
|
||||
char CvMLData::get_delimiter()
|
||||
char CvMLData::get_delimiter() const
|
||||
{
|
||||
return delimiter;
|
||||
}
|
||||
@@ -314,7 +321,7 @@ void CvMLData::set_miss_ch(char ch)
|
||||
__END__;
|
||||
}
|
||||
|
||||
char CvMLData::get_miss_ch()
|
||||
char CvMLData::get_miss_ch() const
|
||||
{
|
||||
return miss_ch;
|
||||
}
|
||||
@@ -339,8 +346,14 @@ void CvMLData::set_response_idx( int idx )
|
||||
__END__;
|
||||
}
|
||||
|
||||
int CvMLData::get_response_idx()
|
||||
int CvMLData::get_response_idx() const
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_response_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
__END__;
|
||||
return response_idx;
|
||||
}
|
||||
|
||||
@@ -536,7 +549,7 @@ const CvMat* CvMLData::get_var_types()
|
||||
return var_types_out;
|
||||
}
|
||||
|
||||
int CvMLData::get_var_type( int var_idx )
|
||||
int CvMLData::get_var_type( int var_idx ) const
|
||||
{
|
||||
return var_types->data.ptr[var_idx];
|
||||
}
|
||||
@@ -572,9 +585,6 @@ void CvMLData::set_train_test_split( const CvTrainTestSplit * spl)
|
||||
|
||||
int sample_count = 0;
|
||||
|
||||
if ( spl->class_part )
|
||||
CV_ERROR( CV_StsBadArg, "this division type is not supported yet" );
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
|
||||
@@ -627,19 +637,41 @@ void CvMLData::set_train_test_split( const CvTrainTestSplit * spl)
|
||||
__END__;
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_train_sample_idx()
|
||||
const CvMat* CvMLData::get_train_sample_idx() const
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_train_sample_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
__END__;
|
||||
|
||||
return train_sample_idx;
|
||||
}
|
||||
|
||||
const CvMat* CvMLData::get_test_sample_idx()
|
||||
const CvMat* CvMLData::get_test_sample_idx() const
|
||||
{
|
||||
CV_FUNCNAME( "CvMLData::get_test_sample_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
__END__;
|
||||
|
||||
return test_sample_idx;
|
||||
}
|
||||
|
||||
void CvMLData::mix_train_and_test_idx()
|
||||
{
|
||||
if ( !values || !sample_idx) return;
|
||||
CV_FUNCNAME( "CvMLData::mix_train_and_test_idx" );
|
||||
__BEGIN__;
|
||||
|
||||
if ( !values )
|
||||
CV_ERROR( CV_StsInternal, "data is empty" );
|
||||
__END__;
|
||||
|
||||
if ( !sample_idx)
|
||||
return;
|
||||
|
||||
if ( train_sample_count > 0 && train_sample_count < values->rows )
|
||||
{
|
||||
|
Reference in New Issue
Block a user