SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
EKernelType
Definition: Kernel.h:57
CDotKernel(CFeatures *l, CFeatures *r)
Definition: DotKernel.h:50
#define SG_ERROR(...)
Definition: SGIO.h:129
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
Definition: DotKernel.h:123
virtual EKernelType get_kernel_type()=0
Features that support dot products among other operations.
Definition: DotFeatures.h:44
virtual const char * get_name() const
Definition: DotKernel.h:103
EFeatureClass
shogun feature class
Definition: FeatureTypes.h:38
Template class DotKernel is the base class for kernels working on DotFeatures.
Definition: DotKernel.h:31
#define ASSERT(x)
Definition: SGIO.h:201
double float64_t
Definition: common.h:50
virtual bool init(CFeatures *l, CFeatures *r)
Definition: DotKernel.h:65
virtual EFeatureClass get_feature_class() const =0
virtual EFeatureClass get_feature_class()
Definition: DotKernel.h:88
EFeatureType
shogun feature type
Definition: FeatureTypes.h:19
CFeatures * rhs
feature vectors to occur on right hand side
Definition: Kernel.h:1061
virtual EFeatureType get_feature_type()
Definition: DotKernel.h:96
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CDotKernel(int32_t cachesize)
Definition: DotKernel.h:43
CFeatures * lhs
feature vectors to occur on left hand side
Definition: Kernel.h:1059
The class Features is the base class of all feature objects.
Definition: Features.h:68
The Kernel base class.
Definition: Kernel.h:158
bool has_property(EFeatureProperty p) const
Definition: Features.cpp:295
virtual EFeatureType get_feature_type() const =0

SHOGUN Machine Learning Toolbox - Documentation