SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LinearKernel.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) 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/config.h>
16 
17 #include <shogun/lib/common.h>
21 
22 namespace shogun
23 {
24  class CKernelMachine;
25  class CDotFeatures;
26 
36 {
37  public:
40  CLinearKernel();
41 
48 
49  virtual ~CLinearKernel();
50 
57  virtual bool init(CFeatures* l, CFeatures* r);
58 
60  virtual void cleanup();
61 
66  virtual EKernelType get_kernel_type() { return K_LINEAR; }
67 
72  virtual const char* get_name() const { return "LinearKernel"; }
73 
82  virtual bool init_optimization(
83  int32_t num_suppvec, int32_t* sv_idx, float64_t* alphas);
84 
88  virtual bool init_optimization(CKernelMachine* km);
89 
94  virtual bool delete_optimization();
95 
101  virtual float64_t compute_optimized(int32_t idx);
102 
103  virtual void clear_normal()
104  {
105  normal = SGVector<float64_t>(((CDotFeatures*)lhs)->get_dim_feature_space());
106  normal.zero();
107  set_is_initialized(true);
108  }
109 
115  virtual void add_to_normal(int32_t idx, float64_t weight);
116 
122  {
123  ASSERT(lhs)
124  return normal;
125  }
126 
132  {
133  ASSERT(lhs && w.size()==((CDotFeatures*) lhs)->get_dim_feature_space())
134  this->normal = w;
135  }
136 
137  protected:
140 };
141 }
142 #endif /* _LINEARKERNEL_H__ */
Computes the standard linear kernel on CDotFeatures.
Definition: LinearKernel.h:35
EKernelType
Definition: Kernel.h:57
virtual float64_t compute_optimized(int32_t idx)
virtual bool delete_optimization()
void set_is_initialized(bool p_init)
Definition: Kernel.h:899
A generic KernelMachine interface.
Definition: KernelMachine.h:51
Features that support dot products among other operations.
Definition: DotFeatures.h:44
int32_t size() const
Definition: SGVector.h:115
Template class DotKernel is the base class for kernels working on DotFeatures.
Definition: DotKernel.h:31
virtual void clear_normal()
Definition: LinearKernel.h:103
#define ASSERT(x)
Definition: SGIO.h:201
double float64_t
Definition: common.h:50
SGVector< float64_t > get_w() const
Definition: LinearKernel.h:121
virtual void add_to_normal(int32_t idx, float64_t weight)
SGVector< float64_t > normal
Definition: LinearKernel.h:139
virtual bool init(CFeatures *l, CFeatures *r)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CFeatures * lhs
feature vectors to occur on left hand side
Definition: Kernel.h:1059
void set_w(SGVector< float64_t > w)
Definition: LinearKernel.h:131
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual EKernelType get_kernel_type()
Definition: LinearKernel.h:66
virtual const char * get_name() const
Definition: LinearKernel.h:72
virtual void cleanup()
virtual bool init_optimization(int32_t num_suppvec, int32_t *sv_idx, float64_t *alphas)

SHOGUN Machine Learning Toolbox - Documentation