SparseKernel.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-2008 Soeren Sonnenburg
00008  * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _SPARSEKERNEL_H___
00012 #define _SPARSEKERNEL_H___
00013 
00014 #include "kernel/Kernel.h"
00015 #include "features/SparseFeatures.h"
00016 
00018 template <class ST> class CSparseKernel : public CKernel
00019 {
00020     public:
00025         CSparseKernel(INT cachesize) : CKernel(cachesize) {}
00026 
00032         CSparseKernel(CFeatures* l, CFeatures* r) : CKernel(10)
00033         {
00034             init(l, r);
00035         }
00036 
00043         virtual bool init(CFeatures* l, CFeatures* r)
00044         {
00045             CKernel::init(l,r);
00046 
00047             ASSERT(l->get_feature_class()==C_SPARSE);
00048             ASSERT(r->get_feature_class()==C_SPARSE);
00049             ASSERT(l->get_feature_type()==this->get_feature_type());
00050             ASSERT(r->get_feature_type()==this->get_feature_type());
00051 
00052             if (((CSparseFeatures<ST>*) lhs)->get_num_features() != ((CSparseFeatures<ST>*) rhs)->get_num_features())
00053             {
00054                 SG_ERROR( "train or test features #dimension mismatch (l:%d vs. r:%d)\n",
00055                         ((CSparseFeatures<ST>*) lhs)->get_num_features(),((CSparseFeatures<ST>*)rhs)->get_num_features());
00056             }
00057             return true;
00058         }
00059 
00064         inline virtual EFeatureClass get_feature_class() { return C_SPARSE; }
00065 
00070         inline virtual EFeatureType get_feature_type();
00071 };
00072 
00073 template<> inline EFeatureType CSparseKernel<DREAL>::get_feature_type() { return F_DREAL; }
00074 
00075 template<> inline EFeatureType CSparseKernel<ULONG>::get_feature_type() { return F_ULONG; }
00076 
00077 template<> inline EFeatureType CSparseKernel<INT>::get_feature_type() { return F_INT; }
00078 
00079 template<> inline EFeatureType CSparseKernel<WORD>::get_feature_type() { return F_WORD; }
00080 
00081 template<> inline EFeatureType CSparseKernel<SHORT>::get_feature_type() { return F_SHORT; }
00082 
00083 template<> inline EFeatureType CSparseKernel<BYTE>::get_feature_type() { return F_BYTE; }
00084 
00085 template<> inline EFeatureType CSparseKernel<CHAR>::get_feature_type() { return F_CHAR; }
00086 
00087 #endif /* _SPARSEKERNEL_H__ */

SHOGUN Machine Learning Toolbox - Documentation