SHOGUN  v3.1.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/kernel/Kernel.h>
16 #include <shogun/io/SGIO.h>
17 
18 namespace shogun
19 {
29 class CDotKernel : public CKernel
30 {
31  public:
36 
41  CDotKernel(int32_t cachesize) : CKernel(cachesize) {}
42 
49  {
50  init(l, r);
51  }
52 
63  virtual bool init(CFeatures* l, CFeatures* r)
64  {
65  CKernel::init(l,r);
66 
71 
72  if ( ((CDotFeatures*) l)->get_dim_feature_space() != ((CDotFeatures*) r)->get_dim_feature_space() )
73  {
74  SG_ERROR("train or test features #dimension mismatch (l:%d vs. r:%d)\n",
75  ((CDotFeatures*) l)->get_dim_feature_space(),((CDotFeatures*) r)->get_dim_feature_space());
76  }
77  return true;
78  }
79 
86  virtual EFeatureClass get_feature_class() { return C_ANY; }
87 
94  virtual EFeatureType get_feature_type() { return F_ANY; }
95 
101  virtual const char* get_name() const { return "DotKernel"; }
102 
110  virtual EKernelType get_kernel_type()=0 ;
111 
112  protected:
121  virtual float64_t compute(int32_t idx_a, int32_t idx_b)
122  {
123  return ((CDotFeatures*) lhs)->dot(idx_a, ((CDotFeatures*) rhs), idx_b);
124  }
125 };
126 }
127 #endif /* _DOTKERNEL_H__ */
128 
EKernelType
Definition: Kernel.h:51
CDotKernel(CFeatures *l, CFeatures *r)
Definition: DotKernel.h:48
#define SG_ERROR(...)
Definition: SGIO.h:131
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
Definition: DotKernel.h:121
virtual EKernelType get_kernel_type()=0
Features that support dot products among other operations.
Definition: DotFeatures.h:41
virtual const char * get_name() const
Definition: DotKernel.h:101
EFeatureClass
shogun feature class
Definition: FeatureTypes.h:35
Template class DotKernel is the base class for kernels working on DotFeatures.
Definition: DotKernel.h:29
#define ASSERT(x)
Definition: SGIO.h:203
double float64_t
Definition: common.h:48
virtual bool init(CFeatures *l, CFeatures *r)
Definition: DotKernel.h:63
virtual EFeatureClass get_feature_class() const =0
virtual EFeatureClass get_feature_class()
Definition: DotKernel.h:86
EFeatureType
shogun feature type
Definition: FeatureTypes.h:16
CFeatures * rhs
feature vectors to occur on right hand side
Definition: Kernel.h:706
virtual EFeatureType get_feature_type()
Definition: DotKernel.h:94
CDotKernel(int32_t cachesize)
Definition: DotKernel.h:41
CFeatures * lhs
feature vectors to occur on left hand side
Definition: Kernel.h:704
The class Features is the base class of all feature objects.
Definition: Features.h:62
The Kernel base class.
Definition: Kernel.h:150
bool has_property(EFeatureProperty p) const
Definition: Features.cpp:292
virtual EFeatureType get_feature_type() const =0

SHOGUN Machine Learning Toolbox - Documentation