DotKernel.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) 2009 Soeren Sonnenburg
00008  * Copyright (C) 2010 Berlin Institute of Technology
00009  */
00010 
00011 #ifndef _DOTKERNEL_H___
00012 #define _DOTKERNEL_H___
00013 
00014 #include <shogun/kernel/Kernel.h>
00015 #include <shogun/features/DotFeatures.h>
00016 #include <shogun/io/SGIO.h>
00017 
00018 namespace shogun
00019 {
00029 class CDotKernel : public CKernel
00030 {
00031     public:
00035         CDotKernel() : CKernel() {}
00036 
00041         CDotKernel(int32_t cachesize) : CKernel(cachesize) {}
00042 
00048         CDotKernel(CFeatures* l, CFeatures* r) : CKernel(10)
00049         {
00050             init(l, r);
00051         }
00052 
00063         virtual bool init(CFeatures* l, CFeatures* r)
00064         {
00065             CKernel::init(l,r);
00066 
00067             ASSERT(l->has_property(FP_DOT));
00068             ASSERT(r->has_property(FP_DOT));
00069             ASSERT(l->get_feature_type() == r->get_feature_type());
00070             ASSERT(l->get_feature_class() == r->get_feature_class());
00071 
00072             if ( ((CDotFeatures*) l)->get_dim_feature_space() != ((CDotFeatures*) r)->get_dim_feature_space() )
00073             {
00074                 SG_ERROR( "train or test features #dimension mismatch (l:%d vs. r:%d)\n",
00075                         ((CDotFeatures*) l)->get_dim_feature_space(),((CDotFeatures*) r)->get_dim_feature_space());
00076             }
00077             return true;
00078         }
00079 
00086         inline virtual EFeatureClass get_feature_class() { return C_ANY; }
00087 
00094         inline virtual EFeatureType get_feature_type() { return F_ANY; }
00095 
00101         virtual const char* get_name(void) const { return "DotKernel"; }
00102 
00110         virtual EKernelType get_kernel_type()=0 ;
00111 
00112     protected:
00121         virtual float64_t compute(int32_t idx_a, int32_t idx_b)
00122         {
00123             return ((CDotFeatures*) lhs)->dot(idx_a, ((CDotFeatures*) rhs), idx_b);
00124         }
00125 };
00126 }
00127 #endif /* _DOTKERNEL_H__ */
00128 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation