SimpleKernel.h

Go to the documentation of this file.
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 
00024 template <class ST> class CSimpleKernel : public CKernel
00025 {
00026     public:
00031         CSimpleKernel(int32_t cachesize) : CKernel(cachesize) {}
00032 
00038         CSimpleKernel(CFeatures* l, CFeatures* r) : CKernel(10)
00039         {
00040             init(l, r);
00041         }
00042 
00053         virtual bool init(CFeatures* l, CFeatures* r)
00054         {
00055             CKernel::init(l,r);
00056 
00057             ASSERT(l->get_feature_class()==C_SIMPLE);
00058             ASSERT(r->get_feature_class()==C_SIMPLE);
00059             ASSERT(l->get_feature_type()==this->get_feature_type());
00060             ASSERT(r->get_feature_type()==this->get_feature_type());
00061 
00062             if ( ((CSimpleFeatures<ST>*) l)->get_num_features() != ((CSimpleFeatures<ST>*) r)->get_num_features() )
00063             {  
00064                 SG_ERROR( "train or test features #dimension mismatch (l:%d vs. r:%d)\n",
00065                         ((CSimpleFeatures<ST>*) l)->get_num_features(),((CSimpleFeatures<ST>*) r)->get_num_features());
00066             }
00067             return true;
00068         }
00069 
00074         inline virtual EFeatureClass get_feature_class() { return C_SIMPLE; }
00075 
00080         inline virtual EFeatureType get_feature_type();
00081 };
00082 
00083 
00084 template<> inline EFeatureType CSimpleKernel<float64_t>::get_feature_type() { return F_DREAL; }
00085 
00086 template<> inline EFeatureType CSimpleKernel<float32_t>::get_feature_type() { return F_SHORTREAL; }
00087 
00088 template<> inline EFeatureType CSimpleKernel<uint64_t>::get_feature_type() { return F_ULONG; }
00089 
00090 template<> inline EFeatureType CSimpleKernel<int32_t>::get_feature_type() { return F_INT; }
00091 
00092 template<> inline EFeatureType CSimpleKernel<uint16_t>::get_feature_type() { return F_WORD; }
00093 
00094 template<> inline EFeatureType CSimpleKernel<int16_t>::get_feature_type() { return F_SHORT; }
00095 
00096 template<> inline EFeatureType CSimpleKernel<uint8_t>::get_feature_type() { return F_BYTE; }
00097 
00098 template<> inline EFeatureType CSimpleKernel<char>::get_feature_type() { return F_CHAR; }
00099 
00100 
00101 #endif /* _SIMPLEKERNEL_H__ */

SHOGUN Machine Learning Toolbox - Documentation