00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 1999-2009 Soeren Sonnenburg 00008 * Written (W) 1999-2008 Gunnar Raetsch 00009 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00010 */ 00011 00012 #include <shogun/features/CombinedFeatures.h> 00013 #include <shogun/io/SGIO.h> 00014 00015 using namespace shogun; 00016 00017 void 00018 CCombinedFeatures::init(void) 00019 { 00020 m_parameters->add(&num_vec, "num_vec", 00021 "Number of vectors."); 00022 m_parameters->add((CSGObject**) &feature_list, 00023 "feature_list", "Feature list."); 00024 } 00025 00026 CCombinedFeatures::CCombinedFeatures() 00027 : CFeatures(0) 00028 { 00029 init(); 00030 00031 feature_list=new CList(true); 00032 num_vec=0; 00033 } 00034 00035 CCombinedFeatures::CCombinedFeatures(const CCombinedFeatures & orig) 00036 : CFeatures(0) 00037 { 00038 init(); 00039 00040 feature_list=new CList(true); 00041 //todo copy features 00042 num_vec=orig.num_vec; 00043 } 00044 00045 CFeatures* CCombinedFeatures::duplicate() const 00046 { 00047 return new CCombinedFeatures(*this); 00048 } 00049 00050 CCombinedFeatures::~CCombinedFeatures() 00051 { 00052 SG_UNREF(feature_list); 00053 } 00054 00055 void CCombinedFeatures::list_feature_objs() 00056 { 00057 SG_INFO( "BEGIN COMBINED FEATURES LIST - "); 00058 this->list_feature_obj(); 00059 00060 CListElement* current = NULL ; 00061 CFeatures* f=get_first_feature_obj(current); 00062 00063 while (f) 00064 { 00065 f->list_feature_obj(); 00066 SG_UNREF(f); 00067 f=get_next_feature_obj(current); 00068 } 00069 00070 SG_INFO( "END COMBINED FEATURES LIST - "); 00071 } 00072 00073 bool CCombinedFeatures::check_feature_obj_compatibility(CCombinedFeatures* comb_feat) 00074 { 00075 bool result=false; 00076 00077 if (comb_feat && (this->get_num_feature_obj() == comb_feat->get_num_feature_obj()) ) 00078 { 00079 CFeatures* f1=this->get_first_feature_obj(); 00080 CFeatures* f2=comb_feat->get_first_feature_obj(); 00081 00082 if (f1 && f2 && f1->check_feature_compatibility(f2)) 00083 { 00084 SG_UNREF(f1); 00085 SG_UNREF(f2); 00086 while( ( (f1=this->get_next_feature_obj()) != NULL ) && 00087 ( (f2=comb_feat->get_next_feature_obj()) != NULL) ) 00088 { 00089 if (!f1->check_feature_compatibility(f2)) 00090 { 00091 SG_UNREF(f1); 00092 SG_UNREF(f2); 00093 SG_INFO( "not compatible, combfeat\n"); 00094 comb_feat->list_feature_objs(); 00095 SG_INFO( "vs this\n"); 00096 this->list_feature_objs(); 00097 return false; 00098 } 00099 SG_UNREF(f1); 00100 SG_UNREF(f2); 00101 } 00102 00103 SG_DEBUG( "features are compatible\n"); 00104 result=true; 00105 } 00106 else 00107 SG_WARNING( "first 2 features not compatible\n"); 00108 } 00109 else 00110 { 00111 SG_WARNING( "number of features in combined feature objects differs (%d != %d)\n", this->get_num_feature_obj(), comb_feat->get_num_feature_obj()); 00112 SG_INFO( "compare\n"); 00113 comb_feat->list_feature_objs(); 00114 SG_INFO( "vs this\n"); 00115 this->list_feature_objs(); 00116 } 00117 00118 return result; 00119 }