SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProductKernel.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  * Copyright (C) 2012 Jacob Walker
8  *
9  * Code adapted from CCombinedKernel
10  */
11 
12 #ifndef _PRODUCTKERNEL_H___
13 #define _PRODUCTKERNEL_H___
14 
15 #include <shogun/lib/config.h>
16 
18 #include <shogun/io/SGIO.h>
19 #include <shogun/kernel/Kernel.h>
20 
23 
24 namespace shogun
25 {
26 class CFeatures;
27 class CCombinedFeatures;
28 class CDynamicObjectArray;
29 
41 class CProductKernel : public CKernel
42 {
43  public:
48  CProductKernel(int32_t size=10);
49 
50  virtual ~CProductKernel();
51 
58  virtual bool init(CFeatures* lhs, CFeatures* rhs);
59 
61  virtual void cleanup();
62 
67  virtual EKernelType get_kernel_type() { return K_PRODUCT; }
68 
73  virtual EFeatureType get_feature_type() { return F_UNKNOWN; }
74 
80 
85  virtual const char* get_name() const { return "ProductKernel"; }
86 
88  void list_kernels();
89 
95  inline CKernel* get_kernel(int32_t idx)
96  {
97  return (CKernel*) kernel_array->get_element(idx);
98  }
99 
107  inline bool insert_kernel(CKernel* k, int32_t idx)
108  {
109  ASSERT(k)
111 
112  if (!(k->has_property(KP_LINADD)))
114 
115  return kernel_array->insert_element(k, idx);
116  }
117 
123  inline bool append_kernel(CKernel* k)
124  {
125  ASSERT(k)
127 
128  if (!(k->has_property(KP_LINADD)))
130 
131  int32_t n = get_num_subkernels();
133  return n+1==get_num_subkernels();
134  }
135 
141  inline bool delete_kernel(int32_t idx)
142  {
143  return kernel_array->delete_element(idx);
144  }
145 
150  inline int32_t get_num_subkernels()
151  {
152  return kernel_array->get_num_elements();
153  }
154 
159  virtual bool has_features()
160  {
161  return initialized;
162  }
163 
165  virtual void remove_lhs();
166 
168  virtual void remove_rhs();
169 
171  virtual void remove_lhs_and_rhs();
172 
174  bool precompute_subkernels();
175 
180  {
181  return dynamic_cast<CProductKernel*>(n);
182  }
183 
192  index_t index=-1);
193 
199  {
201  return kernel_array;
202  }
203 
204  protected:
211  virtual float64_t compute(int32_t x, int32_t y);
212 
219  {
220  ASSERT(k)
221 
222  if (k->get_num_vec_lhs())
223  {
224  if (num_lhs)
227 
228  if (!get_num_subkernels())
229  {
230  initialized=true;
231 #ifdef USE_SVMLIGHT
232  cache_reset();
233 #endif //USE_SVMLIGHT
234  }
235  }
236  else
237  initialized=false;
238 
239  if (k->get_num_vec_rhs())
240  {
241  if (num_rhs)
244 
245  if (!get_num_subkernels())
246  {
247  initialized=true;
248 #ifdef USE_SVMLIGHT
249  cache_reset();
250 #endif //USE_SVMLIGHT
251  }
252  }
253  else
254  initialized=false;
255  }
256 
257  private:
258  void init();
259 
260  protected:
265 };
266 }
267 #endif /* _PRODUCTKERNEL_H__ */

SHOGUN Machine Learning Toolbox - Documentation