minor change (moved methods implementation from hpp to cpp)

This commit is contained in:
Maria Dimashova 2011-06-16 12:35:40 +00:00
parent 74f1162a41
commit 0209d72534
2 changed files with 79 additions and 41 deletions

View File

@ -2092,28 +2092,26 @@ public:
// returns: // returns:
// 0 - OK // 0 - OK
// 1 - file can not be opened or is not correct // 1 - file can not be opened or is not correct
int read_csv(const char* filename); int read_csv( const char* filename );
const CvMat* get_values(){ return values; }
const CvMat* get_values();
const CvMat* get_responses(); const CvMat* get_responses();
const CvMat* get_missing();
const CvMat* get_missing(){ return missing; }
void set_response_idx( int idx ); // old response become predictors, new response_idx = idx void set_response_idx( int idx ); // old response become predictors, new response_idx = idx
// if idx < 0 there will be no response // if idx < 0 there will be no response
int get_response_idx() { return response_idx; } int get_response_idx();
const CvMat* get_train_sample_idx() { return train_sample_idx; } const CvMat* get_train_sample_idx();
const CvMat* get_test_sample_idx() { return test_sample_idx; } const CvMat* get_test_sample_idx();
void mix_train_and_test_idx(); void mix_train_and_test_idx();
void set_train_test_split( const CvTrainTestSplit * spl); void set_train_test_split( const CvTrainTestSplit * spl );
const CvMat* get_var_idx(); const CvMat* get_var_idx();
void chahge_var_idx( int vi, bool state ); // state == true to set vi-variable as predictor void chahge_var_idx( int vi, bool state ); // state == true to set vi-variable as predictor
const CvMat* get_var_types(); const CvMat* get_var_types();
int get_var_type( int var_idx ) { return var_types->data.ptr[var_idx]; } int get_var_type( int var_idx );
// following 2 methods enable to change vars type // following 2 methods enable to change vars type
// use these methods to assign CV_VAR_CATEGORICAL type for categorical variable // use these methods to assign CV_VAR_CATEGORICAL type for categorical variable
// with numerical labels; in the other cases var types are correctly determined automatically // with numerical labels; in the other cases var types are correctly determined automatically
@ -2123,10 +2121,10 @@ public:
void change_var_type( int var_idx, int type); // type in { CV_VAR_ORDERED, CV_VAR_CATEGORICAL } void change_var_type( int var_idx, int type); // type in { CV_VAR_ORDERED, CV_VAR_CATEGORICAL }
void set_delimiter( char ch ); void set_delimiter( char ch );
char get_delimiter() { return delimiter; } char get_delimiter();
void set_miss_ch( char ch ); void set_miss_ch( char ch );
char get_miss_ch() { return miss_ch; } char get_miss_ch();
protected: protected:
virtual void clear(); virtual void clear();

View File

@ -44,7 +44,7 @@
#define MISS_VAL FLT_MAX #define MISS_VAL FLT_MAX
#define CV_VAR_MISS 0 #define CV_VAR_MISS 0
CvTrainTestSplit :: CvTrainTestSplit() CvTrainTestSplit::CvTrainTestSplit()
{ {
train_sample_part_mode = CV_COUNT; train_sample_part_mode = CV_COUNT;
train_sample_part.count = -1; train_sample_part.count = -1;
@ -52,7 +52,7 @@ CvTrainTestSplit :: CvTrainTestSplit()
mix = false; mix = false;
} }
CvTrainTestSplit :: CvTrainTestSplit( int _train_sample_count, bool _mix ) CvTrainTestSplit::CvTrainTestSplit( int _train_sample_count, bool _mix )
{ {
train_sample_part_mode = CV_COUNT; train_sample_part_mode = CV_COUNT;
train_sample_part.count = _train_sample_count; train_sample_part.count = _train_sample_count;
@ -60,7 +60,7 @@ CvTrainTestSplit :: CvTrainTestSplit( int _train_sample_count, bool _mix )
mix = _mix; mix = _mix;
} }
CvTrainTestSplit :: CvTrainTestSplit( float _train_sample_portion, bool _mix ) CvTrainTestSplit::CvTrainTestSplit( float _train_sample_portion, bool _mix )
{ {
train_sample_part_mode = CV_PORTION; train_sample_part_mode = CV_PORTION;
train_sample_part.portion = _train_sample_portion; train_sample_part.portion = _train_sample_portion;
@ -70,7 +70,7 @@ CvTrainTestSplit :: CvTrainTestSplit( float _train_sample_portion, bool _mix )
//////////////// ////////////////
CvMLData :: CvMLData() CvMLData::CvMLData()
{ {
values = missing = var_types = var_idx_mask = response_out = var_idx_out = var_types_out = 0; values = missing = var_types = var_idx_mask = response_out = var_idx_out = var_types_out = 0;
train_sample_idx = test_sample_idx = 0; train_sample_idx = test_sample_idx = 0;
@ -87,20 +87,20 @@ CvMLData :: CvMLData()
rng = &cv::theRNG(); rng = &cv::theRNG();
} }
CvMLData :: ~CvMLData() CvMLData::~CvMLData()
{ {
clear(); clear();
delete class_map; delete class_map;
} }
void CvMLData :: free_train_test_idx() void CvMLData::free_train_test_idx()
{ {
cvReleaseMat( &train_sample_idx ); cvReleaseMat( &train_sample_idx );
cvReleaseMat( &test_sample_idx ); cvReleaseMat( &test_sample_idx );
sample_idx = 0; sample_idx = 0;
} }
void CvMLData :: clear() void CvMLData::clear()
{ {
if ( !class_map->empty() ) if ( !class_map->empty() )
class_map->clear(); class_map->clear();
@ -244,7 +244,17 @@ int CvMLData::read_csv(const char* filename)
return 0; return 0;
} }
void CvMLData :: str_to_flt_elem( const char* token, float& flt_elem, int& type) const CvMat* CvMLData::get_values()
{
return values;
}
const CvMat* CvMLData::get_missing()
{
return missing;
}
void CvMLData::str_to_flt_elem( const char* token, float& flt_elem, int& type)
{ {
char* stopstring = NULL; char* stopstring = NULL;
@ -273,9 +283,9 @@ void CvMLData :: str_to_flt_elem( const char* token, float& flt_elem, int& type)
} }
} }
void CvMLData :: set_delimiter(char ch) void CvMLData::set_delimiter(char ch)
{ {
CV_FUNCNAME( "CvMLData :: set_delimited" ); CV_FUNCNAME( "CvMLData::set_delimited" );
__BEGIN__; __BEGIN__;
if (ch == miss_ch /*|| ch == flt_separator*/) if (ch == miss_ch /*|| ch == flt_separator*/)
@ -286,9 +296,14 @@ void CvMLData :: set_delimiter(char ch)
__END__; __END__;
} }
void CvMLData :: set_miss_ch(char ch) char CvMLData::get_delimiter()
{ {
CV_FUNCNAME( "CvMLData :: set_miss_ch" ); return delimiter;
}
void CvMLData::set_miss_ch(char ch)
{
CV_FUNCNAME( "CvMLData::set_miss_ch" );
__BEGIN__; __BEGIN__;
if (ch == delimiter/* || ch == flt_separator*/) if (ch == delimiter/* || ch == flt_separator*/)
@ -299,9 +314,14 @@ void CvMLData :: set_miss_ch(char ch)
__END__; __END__;
} }
void CvMLData :: set_response_idx( int idx ) char CvMLData::get_miss_ch()
{ {
CV_FUNCNAME( "CvMLData :: set_response_idx" ); return miss_ch;
}
void CvMLData::set_response_idx( int idx )
{
CV_FUNCNAME( "CvMLData::set_response_idx" );
__BEGIN__; __BEGIN__;
if ( !values ) if ( !values )
@ -319,9 +339,14 @@ void CvMLData :: set_response_idx( int idx )
__END__; __END__;
} }
void CvMLData :: change_var_type( int var_idx, int type ) int CvMLData::get_response_idx()
{ {
CV_FUNCNAME( "CvMLData :: change_var_type" ); return response_idx;
}
void CvMLData::change_var_type( int var_idx, int type )
{
CV_FUNCNAME( "CvMLData::change_var_type" );
__BEGIN__; __BEGIN__;
int var_count = 0; int var_count = 0;
@ -347,9 +372,9 @@ void CvMLData :: change_var_type( int var_idx, int type )
return; return;
} }
void CvMLData :: set_var_types( const char* str ) void CvMLData::set_var_types( const char* str )
{ {
CV_FUNCNAME( "CvMLData :: set_var_types" ); CV_FUNCNAME( "CvMLData::set_var_types" );
__BEGIN__; __BEGIN__;
const char* ord = 0, *cat = 0; const char* ord = 0, *cat = 0;
@ -472,9 +497,9 @@ void CvMLData :: set_var_types( const char* str )
__END__; __END__;
} }
const CvMat* CvMLData :: get_var_types() const CvMat* CvMLData::get_var_types()
{ {
CV_FUNCNAME( "CvMLData :: get_var_types" ); CV_FUNCNAME( "CvMLData::get_var_types" );
__BEGIN__; __BEGIN__;
uchar *var_types_out_ptr = 0; uchar *var_types_out_ptr = 0;
@ -511,9 +536,14 @@ const CvMat* CvMLData :: get_var_types()
return var_types_out; return var_types_out;
} }
const CvMat* CvMLData :: get_responses() int CvMLData::get_var_type( int var_idx )
{ {
CV_FUNCNAME( "CvMLData :: get_responses_ptr" ); return var_types->data.ptr[var_idx];
}
const CvMat* CvMLData::get_responses()
{
CV_FUNCNAME( "CvMLData::get_responses_ptr" );
__BEGIN__; __BEGIN__;
int var_count = 0; int var_count = 0;
@ -535,9 +565,9 @@ const CvMat* CvMLData :: get_responses()
return response_out; return response_out;
} }
void CvMLData :: set_train_test_split( const CvTrainTestSplit * spl) void CvMLData::set_train_test_split( const CvTrainTestSplit * spl)
{ {
CV_FUNCNAME( "CvMLData :: set_division" ); CV_FUNCNAME( "CvMLData::set_division" );
__BEGIN__; __BEGIN__;
int sample_count = 0; int sample_count = 0;
@ -597,7 +627,17 @@ void CvMLData :: set_train_test_split( const CvTrainTestSplit * spl)
__END__; __END__;
} }
void CvMLData :: mix_train_and_test_idx() const CvMat* CvMLData::get_train_sample_idx()
{
return train_sample_idx;
}
const CvMat* CvMLData::get_test_sample_idx()
{
return test_sample_idx;
}
void CvMLData::mix_train_and_test_idx()
{ {
if ( !values || !sample_idx) return; if ( !values || !sample_idx) return;
@ -614,9 +654,9 @@ void CvMLData :: mix_train_and_test_idx()
} }
} }
const CvMat* CvMLData :: get_var_idx() const CvMat* CvMLData::get_var_idx()
{ {
CV_FUNCNAME( "CvMLData :: get_var_idx" ); CV_FUNCNAME( "CvMLData::get_var_idx" );
__BEGIN__; __BEGIN__;
int avcount = 0; int avcount = 0;
@ -654,9 +694,9 @@ const CvMat* CvMLData :: get_var_idx()
return var_idx_out; return var_idx_out;
} }
void CvMLData :: chahge_var_idx( int vi, bool state ) void CvMLData::chahge_var_idx( int vi, bool state )
{ {
CV_FUNCNAME( "CvMLData :: get_responses_ptr" ); CV_FUNCNAME( "CvMLData::get_responses_ptr" );
__BEGIN__; __BEGIN__;
int var_count = 0; int var_count = 0;