SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DotKernel.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2009 Soeren Sonnenburg
8  * Copyright (C) 2010 Berlin Institute of Technology
9  */
10 
11 #ifndef _DOTKERNEL_H___
12 #define _DOTKERNEL_H___
13 
14 #include <shogun/lib/config.h>
15 
16 #include <shogun/kernel/Kernel.h>
18 #include <shogun/io/SGIO.h>
19 
20 namespace shogun
21 {
31 class CDotKernel : public CKernel
32 {
33  public:
38 
43  CDotKernel(int32_t cachesize) : CKernel(cachesize) {}
44 
51  {
52  init(l, r);
53  }
54 
65  virtual bool init(CFeatures* l, CFeatures* r)
66  {
67  CKernel::init(l,r);
68 
73 
74  if ( ((CDotFeatures*) l)->get_dim_feature_space() != ((CDotFeatures*) r)->get_dim_feature_space() )
75  {
76  SG_ERROR("train or test features #dimension mismatch (l:%d vs. r:%d)\n",
77  ((CDotFeatures*) l)->get_dim_feature_space(),((CDotFeatures*) r)->get_dim_feature_space());
78  }
79  return true;
80  }
81 
88  virtual EFeatureClass get_feature_class() { return C_ANY; }
89 
96  virtual EFeatureType get_feature_type() { return F_ANY; }
97 
103  virtual const char* get_name() const { return "DotKernel"; }
104 
112  virtual EKernelType get_kernel_type()=0 ;
113 
114  protected:
123  virtual float64_t compute(int32_t idx_a, int32_t idx_b)
124  {
125  return ((CDotFeatures*) lhs)->dot(idx_a, ((CDotFeatures*) rhs), idx_b);
126  }
127 };
128 }
129 #endif /* _DOTKERNEL_H__ */
130 

SHOGUN Machine Learning Toolbox - Documentation