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 
00020 template <class ST> class CSparseKernel : public CKernel
00021 {
00022     public:
00027         CSparseKernel(int32_t cachesize) : CKernel(cachesize) {}
00028 
00034         CSparseKernel(CFeatures* l, CFeatures* r) : CKernel(10)
00035         {
00036             init(l, r);
00037         }
00038 
00045         virtual bool init(CFeatures* l, CFeatures* r)
00046         {
00047             CKernel::init(l,r);
00048 
00049             ASSERT(l->get_feature_class()==C_SPARSE);
00050             ASSERT(r->get_feature_class()==C_SPARSE);
00051             ASSERT(l->get_feature_type()==this->get_feature_type());
00052             ASSERT(r->get_feature_type()==this->get_feature_type());
00053 
00054             if (((CSparseFeatures<ST>*) lhs)->get_num_features() != ((CSparseFeatures<ST>*) rhs)->get_num_features())
00055             {
00056                 SG_ERROR( "train or test features #dimension mismatch (l:%d vs. r:%d)\n",
00057                         ((CSparseFeatures<ST>*) lhs)->get_num_features(),((CSparseFeatures<ST>*)rhs)->get_num_features());
00058             }
00059             return true;
00060         }
00061 
00066         inline virtual EFeatureClass get_feature_class() { return C_SPARSE; }
00067 
00072         inline virtual EFeatureType get_feature_type();
00073 };
00074 
00075 template<> inline EFeatureType CSparseKernel<float64_t>::get_feature_type() { return F_DREAL; }
00076 
00077 template<> inline EFeatureType CSparseKernel<uint64_t>::get_feature_type() { return F_ULONG; }
00078 
00079 template<> inline EFeatureType CSparseKernel<int32_t>::get_feature_type() { return F_INT; }
00080 
00081 template<> inline EFeatureType CSparseKernel<uint16_t>::get_feature_type() { return F_WORD; }
00082 
00083 template<> inline EFeatureType CSparseKernel<int16_t>::get_feature_type() { return F_SHORT; }
00084 
00085 template<> inline EFeatureType CSparseKernel<uint8_t>::get_feature_type() { return F_BYTE; }
00086 
00087 template<> inline EFeatureType CSparseKernel<char>::get_feature_type() { return F_CHAR; }
00088 
00089 #endif /* _SPARSEKERNEL_H__ */

SHOGUN Machine Learning Toolbox - Documentation