SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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__ */

SHOGUN Machine Learning Toolbox - Documentation