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 "features/CombinedFeatures.h" 00013 #include "lib/io.h" 00014 00015 using namespace shogun; 00016 00017 CCombinedFeatures::CCombinedFeatures() 00018 : CFeatures(0) 00019 { 00020 feature_list=new CList<CFeatures*>(true); 00021 num_vec=0; 00022 } 00023 00024 CCombinedFeatures::CCombinedFeatures(const CCombinedFeatures & orig) 00025 : CFeatures(0) 00026 { 00027 feature_list=new CList<CFeatures*>(true); 00028 //todo copy features 00029 num_vec=orig.num_vec; 00030 } 00031 00032 CFeatures* CCombinedFeatures::duplicate() const 00033 { 00034 return new CCombinedFeatures(*this); 00035 } 00036 00037 CCombinedFeatures::~CCombinedFeatures() 00038 { 00039 SG_UNREF(feature_list); 00040 } 00041 00042 void CCombinedFeatures::list_feature_objs() 00043 { 00044 SG_INFO( "BEGIN COMBINED FEATURES LIST - "); 00045 this->list_feature_obj(); 00046 00047 CListElement<CFeatures*> * current = NULL ; 00048 CFeatures* f=get_first_feature_obj(current); 00049 00050 while (f) 00051 { 00052 f->list_feature_obj(); 00053 SG_UNREF(f); 00054 f=get_next_feature_obj(current); 00055 } 00056 00057 SG_INFO( "END COMBINED FEATURES LIST - "); 00058 } 00059 00060 bool CCombinedFeatures::check_feature_obj_compatibility(CCombinedFeatures* comb_feat) 00061 { 00062 bool result=false; 00063 00064 if (comb_feat && (this->get_num_feature_obj() == comb_feat->get_num_feature_obj()) ) 00065 { 00066 CFeatures* f1=this->get_first_feature_obj(); 00067 CFeatures* f2=comb_feat->get_first_feature_obj(); 00068 00069 if (f1 && f2 && f1->check_feature_compatibility(f2)) 00070 { 00071 SG_UNREF(f1); 00072 SG_UNREF(f2); 00073 while( ( (f1=this->get_next_feature_obj()) != NULL ) && 00074 ( (f2=comb_feat->get_next_feature_obj()) != NULL) ) 00075 { 00076 if (!f1->check_feature_compatibility(f2)) 00077 { 00078 SG_UNREF(f1); 00079 SG_UNREF(f2); 00080 SG_INFO( "not compatible, combfeat\n"); 00081 comb_feat->list_feature_objs(); 00082 SG_INFO( "vs this\n"); 00083 this->list_feature_objs(); 00084 return false; 00085 } 00086 SG_UNREF(f1); 00087 SG_UNREF(f2); 00088 } 00089 00090 SG_DEBUG( "features are compatible\n"); 00091 result=true; 00092 } 00093 else 00094 SG_WARNING( "first 2 features not compatible\n"); 00095 } 00096 else 00097 { 00098 SG_WARNING( "number of features in combined feature objects differs (%d != %d)\n", this->get_num_feature_obj(), comb_feat->get_num_feature_obj()); 00099 SG_INFO( "compare\n"); 00100 comb_feat->list_feature_objs(); 00101 SG_INFO( "vs this\n"); 00102 this->list_feature_objs(); 00103 } 00104 00105 return result; 00106 }