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-2008 Soeren Sonnenburg 00008 * Copyright (C) 1999-2008 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 00019 template <class ST> class CSimpleKernel : public CKernel 00020 { 00021 public: 00026 CSimpleKernel(INT cachesize) : CKernel(cachesize) {} 00027 00033 CSimpleKernel(CFeatures* l, CFeatures* r) : CKernel(10) 00034 { 00035 init(l, r); 00036 } 00037 00048 virtual bool init(CFeatures* l, CFeatures* r) 00049 { 00050 CKernel::init(l,r); 00051 00052 ASSERT(l->get_feature_class()==C_SIMPLE); 00053 ASSERT(r->get_feature_class()==C_SIMPLE); 00054 ASSERT(l->get_feature_type()==this->get_feature_type()); 00055 ASSERT(r->get_feature_type()==this->get_feature_type()); 00056 00057 if ( ((CSimpleFeatures<ST>*) l)->get_num_features() != ((CSimpleFeatures<ST>*) r)->get_num_features() ) 00058 { 00059 SG_ERROR( "train or test features #dimension mismatch (l:%d vs. r:%d)\n", 00060 ((CSimpleFeatures<ST>*) l)->get_num_features(),((CSimpleFeatures<ST>*) r)->get_num_features()); 00061 } 00062 return true; 00063 } 00064 00069 inline virtual EFeatureClass get_feature_class() { return C_SIMPLE; } 00070 00075 inline virtual EFeatureType get_feature_type(); 00076 }; 00077 00078 00079 template<> inline EFeatureType CSimpleKernel<DREAL>::get_feature_type() { return F_DREAL; } 00080 00081 template<> inline EFeatureType CSimpleKernel<ULONG>::get_feature_type() { return F_ULONG; } 00082 00083 template<> inline EFeatureType CSimpleKernel<INT>::get_feature_type() { return F_INT; } 00084 00085 template<> inline EFeatureType CSimpleKernel<WORD>::get_feature_type() { return F_WORD; } 00086 00087 template<> inline EFeatureType CSimpleKernel<SHORT>::get_feature_type() { return F_SHORT; } 00088 00089 template<> inline EFeatureType CSimpleKernel<BYTE>::get_feature_type() { return F_BYTE; } 00090 00091 template<> inline EFeatureType CSimpleKernel<CHAR>::get_feature_type() { return F_CHAR; } 00092 00093 00094 #endif /* _SIMPLEKERNEL_H__ */