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-2009 Soeren Sonnenburg
00008  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _SPARSEKERNEL_H___
00012 #define _SPARSEKERNEL_H___
00013 
00014 #include <shogun/kernel/Kernel.h>
00015 #include <shogun/features/SparseFeatures.h>
00016 
00017 namespace shogun
00018 {
00024 template <class ST> class CSparseKernel : public CKernel
00025 {
00026     public:
00031         CSparseKernel(int32_t cachesize) : CKernel(cachesize) {}
00032 
00038         CSparseKernel(CFeatures* l, CFeatures* r) : CKernel(10)
00039         {
00040             init(l, r);
00041         }
00042 
00049         virtual bool init(CFeatures* l, CFeatures* r)
00050         {
00051             CKernel::init(l,r);
00052 
00053             ASSERT(l->get_feature_class()==C_SPARSE);
00054             ASSERT(r->get_feature_class()==C_SPARSE);
00055             ASSERT(l->get_feature_type()==this->get_feature_type());
00056             ASSERT(r->get_feature_type()==this->get_feature_type());
00057 
00058             if (((CSparseFeatures<ST>*) lhs)->get_num_features() != ((CSparseFeatures<ST>*) rhs)->get_num_features())
00059             {
00060                 SG_ERROR( "train or test features #dimension mismatch (l:%d vs. r:%d)\n",
00061                         ((CSparseFeatures<ST>*) lhs)->get_num_features(),((CSparseFeatures<ST>*)rhs)->get_num_features());
00062             }
00063             return true;
00064         }
00065 
00070         inline virtual EFeatureClass get_feature_class() { return C_SPARSE; }
00071 
00076         inline virtual EFeatureType get_feature_type();
00077 
00083         virtual const char* get_name(void) const {
00084             return "SparseKernel"; }
00085 
00093         virtual EKernelType get_kernel_type()=0;
00094 };
00095 
00096 template<> inline EFeatureType CSparseKernel<float64_t>::get_feature_type() { return F_DREAL; }
00097 
00098 template<> inline EFeatureType CSparseKernel<uint64_t>::get_feature_type() { return F_ULONG; }
00099 
00100 template<> inline EFeatureType CSparseKernel<int32_t>::get_feature_type() { return F_INT; }
00101 
00102 template<> inline EFeatureType CSparseKernel<uint16_t>::get_feature_type() { return F_WORD; }
00103 
00104 template<> inline EFeatureType CSparseKernel<int16_t>::get_feature_type() { return F_SHORT; }
00105 
00106 template<> inline EFeatureType CSparseKernel<uint8_t>::get_feature_type() { return F_BYTE; }
00107 
00108 template<> inline EFeatureType CSparseKernel<char>::get_feature_type() { return F_CHAR; }
00109 }
00110 #endif /* _SPARSEKERNEL_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation