Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <shogun/features/CombinedFeatures.h>
00013 #include <shogun/io/SGIO.h>
00014
00015 using namespace shogun;
00016
00017 CCombinedFeatures::CCombinedFeatures()
00018 : CFeatures(0)
00019 {
00020 init();
00021
00022 feature_list=new CList(true);
00023 num_vec=0;
00024 }
00025
00026 CCombinedFeatures::CCombinedFeatures(const CCombinedFeatures & orig)
00027 : CFeatures(0)
00028 {
00029 init();
00030
00031 feature_list=new CList(true);
00032
00033 num_vec=orig.num_vec;
00034 }
00035
00036 CFeatures* CCombinedFeatures::duplicate() const
00037 {
00038 return new CCombinedFeatures(*this);
00039 }
00040
00041 CCombinedFeatures::~CCombinedFeatures()
00042 {
00043 SG_UNREF(feature_list);
00044 }
00045
00046 int32_t CCombinedFeatures::get_size()
00047 {
00048 CFeatures* f=(CFeatures*) feature_list
00049 ->get_current_element();
00050 if (f)
00051 {
00052 int32_t s=f->get_size();
00053 SG_UNREF(f)
00054 return s;
00055 }
00056 else
00057 return 0;
00058 }
00059
00060 void CCombinedFeatures::list_feature_objs()
00061 {
00062 SG_INFO( "BEGIN COMBINED FEATURES LIST - ");
00063 this->list_feature_obj();
00064
00065 CListElement* current = NULL ;
00066 CFeatures* f=get_first_feature_obj(current);
00067
00068 while (f)
00069 {
00070 f->list_feature_obj();
00071 SG_UNREF(f);
00072 f=get_next_feature_obj(current);
00073 }
00074
00075 SG_INFO( "END COMBINED FEATURES LIST - ");
00076 }
00077
00078 bool CCombinedFeatures::check_feature_obj_compatibility(CCombinedFeatures* comb_feat)
00079 {
00080 bool result=false;
00081
00082 if (comb_feat && (this->get_num_feature_obj() == comb_feat->get_num_feature_obj()) )
00083 {
00084 CFeatures* f1=this->get_first_feature_obj();
00085 CFeatures* f2=comb_feat->get_first_feature_obj();
00086
00087 if (f1 && f2 && f1->check_feature_compatibility(f2))
00088 {
00089 SG_UNREF(f1);
00090 SG_UNREF(f2);
00091 while( ( (f1=this->get_next_feature_obj()) != NULL ) &&
00092 ( (f2=comb_feat->get_next_feature_obj()) != NULL) )
00093 {
00094 if (!f1->check_feature_compatibility(f2))
00095 {
00096 SG_UNREF(f1);
00097 SG_UNREF(f2);
00098 SG_INFO( "not compatible, combfeat\n");
00099 comb_feat->list_feature_objs();
00100 SG_INFO( "vs this\n");
00101 this->list_feature_objs();
00102 return false;
00103 }
00104 SG_UNREF(f1);
00105 SG_UNREF(f2);
00106 }
00107
00108 SG_DEBUG( "features are compatible\n");
00109 result=true;
00110 }
00111 else
00112 SG_WARNING( "first 2 features not compatible\n");
00113 }
00114 else
00115 {
00116 SG_WARNING( "number of features in combined feature objects differs (%d != %d)\n", this->get_num_feature_obj(), comb_feat->get_num_feature_obj());
00117 SG_INFO( "compare\n");
00118 comb_feat->list_feature_objs();
00119 SG_INFO( "vs this\n");
00120 this->list_feature_objs();
00121 }
00122
00123 return result;
00124 }
00125
00126 CFeatures* CCombinedFeatures::get_first_feature_obj()
00127 {
00128 return (CFeatures*) feature_list->get_first_element();
00129 }
00130
00131 CFeatures* CCombinedFeatures::get_first_feature_obj(CListElement*& current)
00132 {
00133 return (CFeatures*) feature_list->get_first_element(current);
00134 }
00135
00136 CFeatures* CCombinedFeatures::get_next_feature_obj()
00137 {
00138 return (CFeatures*) feature_list->get_next_element();
00139 }
00140
00141 CFeatures* CCombinedFeatures::get_next_feature_obj(CListElement*& current)
00142 {
00143 return (CFeatures*) feature_list->get_next_element(current);
00144 }
00145
00146 CFeatures* CCombinedFeatures::get_last_feature_obj()
00147 {
00148 return (CFeatures*) feature_list->get_last_element();
00149 }
00150
00151 bool CCombinedFeatures::insert_feature_obj(CFeatures* obj)
00152 {
00153 ASSERT(obj);
00154 int32_t n=obj->get_num_vectors();
00155
00156 if (num_vec>0 && n!=num_vec)
00157 SG_ERROR("Number of feature vectors does not match (expected %d, obj has %d)\n", num_vec, n);
00158
00159 num_vec=n;
00160 return feature_list->insert_element(obj);
00161 }
00162
00163 bool CCombinedFeatures::append_feature_obj(CFeatures* obj)
00164 {
00165 ASSERT(obj);
00166 int32_t n=obj->get_num_vectors();
00167
00168 if (num_vec>0 && n!=num_vec)
00169 SG_ERROR("Number of feature vectors does not match (expected %d, obj has %d)\n", num_vec, n);
00170
00171 num_vec=n;
00172 return feature_list->append_element(obj);
00173 }
00174
00175 bool CCombinedFeatures::delete_feature_obj()
00176 {
00177 CFeatures* f=(CFeatures*)feature_list->delete_element();
00178 if (f)
00179 {
00180 SG_UNREF(f);
00181 return true;
00182 }
00183 else
00184 return false;
00185 }
00186
00187 int32_t CCombinedFeatures::get_num_feature_obj()
00188 {
00189 return feature_list->get_num_elements();
00190 }
00191
00192 void CCombinedFeatures::init()
00193 {
00194 m_parameters->add(&num_vec, "num_vec",
00195 "Number of vectors.");
00196 m_parameters->add((CSGObject**) &feature_list,
00197 "feature_list", "Feature list.");
00198 }