SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
DotKernel.h
浏览该文件的文档.
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 
72  if (l->support_compatible_class())
73  {
75  "Right hand side of features (%s) must be compatible with left hand side features (%s)\n",
76  l->get_name(), r->get_name());
77  }
78  else
79  {
81  "Right hand side of features (%s) must be compatible with left hand side features (%s)\n",
82  l->get_name(), r->get_name())
83  }
84 
85  if ( ((CDotFeatures*) l)->get_dim_feature_space() != ((CDotFeatures*) r)->get_dim_feature_space() )
86  {
87  SG_ERROR("train or test features #dimension mismatch (l:%d vs. r:%d)\n",
88  ((CDotFeatures*) l)->get_dim_feature_space(),((CDotFeatures*) r)->get_dim_feature_space());
89  }
90  return true;
91  }
92 
99  virtual EFeatureClass get_feature_class() { return C_ANY; }
100 
107  virtual EFeatureType get_feature_type() { return F_ANY; }
108 
114  virtual const char* get_name() const { return "DotKernel"; }
115 
123  virtual EKernelType get_kernel_type()=0 ;
124 
125  protected:
134  virtual float64_t compute(int32_t idx_a, int32_t idx_b)
135  {
136  return ((CDotFeatures*) lhs)->dot(idx_a, ((CDotFeatures*) rhs), idx_b);
137  }
138 };
139 }
140 #endif /* _DOTKERNEL_H__ */
141 
virtual const char * get_name() const =0
virtual bool support_compatible_class() const
Definition: Features.h:323
EKernelType
Definition: Kernel.h:57
virtual bool get_feature_class_compatibility(EFeatureClass rhs) const
Definition: Features.cpp:355
CDotKernel(CFeatures *l, CFeatures *r)
Definition: DotKernel.h:50
#define SG_ERROR(...)
Definition: SGIO.h:129
#define REQUIRE(x,...)
Definition: SGIO.h:206
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
Definition: DotKernel.h:134
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:114
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:99
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:107
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 机器学习工具包 - 项目文档