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 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef _SIMPLEKERNEL_H___ 00012 #define _SIMPLEKERNEL_H___ 00013 00014 #include "kernel/Kernel.h" 00015 #include "features/SimpleFeatures.h" 00016 #include "lib/io.h" 00017 00018 namespace shogun 00019 { 00026 template <class ST> class CSimpleKernel : public CKernel 00027 { 00028 public: 00032 CSimpleKernel() : CKernel() {} 00033 00038 CSimpleKernel(int32_t cachesize) : CKernel(cachesize) {} 00039 00045 CSimpleKernel(CFeatures* l, CFeatures* r) : CKernel(10) 00046 { 00047 init(l, r); 00048 } 00049 00060 virtual bool init(CFeatures* l, CFeatures* r) 00061 { 00062 CKernel::init(l,r); 00063 00064 ASSERT(l->get_feature_class()==C_SIMPLE); 00065 ASSERT(r->get_feature_class()==C_SIMPLE); 00066 ASSERT(l->get_feature_type()==this->get_feature_type()); 00067 ASSERT(r->get_feature_type()==this->get_feature_type()); 00068 00069 if ( ((CSimpleFeatures<ST>*) l)->get_num_features() != ((CSimpleFeatures<ST>*) r)->get_num_features() ) 00070 { 00071 SG_ERROR( "train or test features #dimension mismatch (l:%d vs. r:%d)\n", 00072 ((CSimpleFeatures<ST>*) l)->get_num_features(),((CSimpleFeatures<ST>*) r)->get_num_features()); 00073 } 00074 return true; 00075 } 00076 00081 inline virtual EFeatureClass get_feature_class() { return C_SIMPLE; } 00082 00087 inline virtual EFeatureType get_feature_type(); 00088 00089 00090 #ifdef HAVE_BOOST_SERIALIZATION 00091 private: 00092 00093 friend class ::boost::serialization::access; 00094 template<class Archive> 00095 void serialize(Archive & ar, const unsigned int archive_version) 00096 { 00097 00098 SG_DEBUG("archiving CSimpleKernel\n"); 00099 00100 ar & ::boost::serialization::base_object<CKernel>(*this); 00101 00102 SG_DEBUG("done with CSimpleKernel\n"); 00103 00104 } 00105 00106 #endif //HAVE_BOOST_SERIALIZATION 00107 }; 00108 00109 00110 template<> inline EFeatureType CSimpleKernel<float64_t>::get_feature_type() { return F_DREAL; } 00111 00112 template<> inline EFeatureType CSimpleKernel<float32_t>::get_feature_type() { return F_SHORTREAL; } 00113 00114 template<> inline EFeatureType CSimpleKernel<uint64_t>::get_feature_type() { return F_ULONG; } 00115 00116 template<> inline EFeatureType CSimpleKernel<int32_t>::get_feature_type() { return F_INT; } 00117 00118 template<> inline EFeatureType CSimpleKernel<uint16_t>::get_feature_type() { return F_WORD; } 00119 00120 template<> inline EFeatureType CSimpleKernel<int16_t>::get_feature_type() { return F_SHORT; } 00121 00122 template<> inline EFeatureType CSimpleKernel<uint8_t>::get_feature_type() { return F_BYTE; } 00123 00124 template<> inline EFeatureType CSimpleKernel<char>::get_feature_type() { return F_CHAR; } 00125 00126 } 00127 #endif /* _SIMPLEKERNEL_H__ */