SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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/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 
102  virtual void clear_normal();
103 
109  virtual void add_to_normal(int32_t idx, float64_t weight);
110 
116  inline const float64_t* get_normal(int32_t& len)
117  {
118  if (lhs && normal)
119  {
120  len = ((CDotFeatures*) lhs)->get_dim_feature_space();
121  return normal;
122  }
123  else
124  {
125  len = 0;
126  return NULL;
127  }
128  }
129 
135  inline void get_w(float64_t** dst_w, int32_t* dst_dims)
136  {
137  ASSERT(lhs && normal);
138  int32_t len = ((CDotFeatures*) lhs)->get_dim_feature_space();
139  ASSERT(dst_w && dst_dims);
140  *dst_dims=len;
141  *dst_w=SG_MALLOC(float64_t, *dst_dims);
142  ASSERT(*dst_w);
143  memcpy(*dst_w, normal, sizeof(float64_t) * (*dst_dims));
144  }
145 
151  inline void set_w(float64_t* src_w, int32_t src_w_dim)
152  {
153  ASSERT(lhs && src_w_dim==((CDotFeatures*) lhs)->get_dim_feature_space());
154  clear_normal();
155  memcpy(normal, src_w, sizeof(float64_t) * src_w_dim);
156  }
157 
158  protected:
162  int32_t normal_length;
163 };
164 }
165 #endif /* _LINEARKERNEL_H__ */
Computes the standard linear kernel on CDotFeatures.
Definition: LinearKernel.h:33
EKernelType
Definition: Kernel.h:52
const float64_t * get_normal(int32_t &len)
Definition: LinearKernel.h:116
virtual float64_t compute_optimized(int32_t idx)
virtual bool delete_optimization()
A generic KernelMachine interface.
Definition: KernelMachine.h:43
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
#define ASSERT(x)
Definition: SGIO.h:102
double float64_t
Definition: common.h:56
virtual void clear_normal()
virtual void add_to_normal(int32_t idx, float64_t weight)
void get_w(float64_t **dst_w, int32_t *dst_dims)
Definition: LinearKernel.h:135
virtual bool init(CFeatures *l, CFeatures *r)
void set_w(float64_t *src_w, int32_t src_w_dim)
Definition: LinearKernel.h:151
CFeatures * lhs
feature vectors to occur on left hand side
Definition: Kernel.h:808
The class Features is the base class of all feature objects.
Definition: Features.h:56
virtual EKernelType get_kernel_type()
Definition: LinearKernel.h:64
virtual const char * get_name() const
Definition: LinearKernel.h:70
virtual void cleanup()
virtual bool init_optimization(int32_t num_suppvec, int32_t *sv_idx, float64_t *alphas)
#define SG_MALLOC(type, len)
Definition: memory.h:36

SHOGUN Machine Learning Toolbox - Documentation