SHOGUN  v3.2.0
LinearKernel.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) 1999-2010 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  * Copyright (C) 2010 Berlin Institute of Technology
10  */
11 
12 #ifndef _LINEARKERNEL_H___
13 #define _LINEARKERNEL_H___
14 
15 #include <shogun/lib/common.h>
19 
20 namespace shogun
21 {
22  class CKernelMachine;
23  class CDotFeatures;
24 
34 {
35  public:
38  CLinearKernel();
39 
46 
47  virtual ~CLinearKernel();
48 
55  virtual bool init(CFeatures* l, CFeatures* r);
56 
58  virtual void cleanup();
59 
64  virtual EKernelType get_kernel_type() { return K_LINEAR; }
65 
70  virtual const char* get_name() const { return "LinearKernel"; }
71 
80  virtual bool init_optimization(
81  int32_t num_suppvec, int32_t* sv_idx, float64_t* alphas);
82 
86  virtual bool init_optimization(CKernelMachine* km);
87 
92  virtual bool delete_optimization();
93 
99  virtual float64_t compute_optimized(int32_t idx);
100 
101  virtual void clear_normal()
102  {
103  normal = SGVector<float64_t>(((CDotFeatures*)lhs)->get_dim_feature_space());
104  normal.zero();
105  set_is_initialized(true);
106  }
107 
113  virtual void add_to_normal(int32_t idx, float64_t weight);
114 
120  {
121  ASSERT(lhs)
122  return normal;
123  }
124 
130  {
131  ASSERT(lhs && w.size()==((CDotFeatures*) lhs)->get_dim_feature_space())
132  this->normal = w;
133  }
134 
135  protected:
138 };
139 }
140 #endif /* _LINEARKERNEL_H__ */
Computes the standard linear kernel on CDotFeatures.
Definition: LinearKernel.h:33
SGVector< float64_t > get_w() const
Definition: LinearKernel.h:119
EKernelType
Definition: Kernel.h:51
virtual const char * get_name() const
Definition: LinearKernel.h:70
virtual float64_t compute_optimized(int32_t idx)
virtual bool delete_optimization()
void set_is_initialized(bool p_init)
Definition: Kernel.h:610
A generic KernelMachine interface.
Definition: KernelMachine.h:50
Features that support dot products among other operations.
Definition: DotFeatures.h:41
Template class DotKernel is the base class for kernels working on DotFeatures.
Definition: DotKernel.h:29
virtual void clear_normal()
Definition: LinearKernel.h:101
#define ASSERT(x)
Definition: SGIO.h:203
double float64_t
Definition: common.h:48
virtual void add_to_normal(int32_t idx, float64_t weight)
SGVector< float64_t > normal
Definition: LinearKernel.h:137
virtual bool init(CFeatures *l, CFeatures *r)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
CFeatures * lhs
feature vectors to occur on left hand side
Definition: Kernel.h:704
void set_w(SGVector< float64_t > w)
Definition: LinearKernel.h:129
The class Features is the base class of all feature objects.
Definition: Features.h:62
virtual EKernelType get_kernel_type()
Definition: LinearKernel.h:64
virtual void cleanup()
virtual bool init_optimization(int32_t num_suppvec, int32_t *sv_idx, float64_t *alphas)
int32_t size() const
Definition: SGVector.h:54

SHOGUN Machine Learning Toolbox - Documentation