SHOGUN  3.2.1
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ProductKernel.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  * Copyright (C) 2012 Jacob Walker
8  *
9  * Code adapted from CCombinedKernel
10  */
11 
12 #ifndef _PRODUCTKERNEL_H___
13 #define _PRODUCTKERNEL_H___
14 
16 #include <shogun/io/SGIO.h>
17 #include <shogun/kernel/Kernel.h>
18 
21 
22 namespace shogun
23 {
24 class CFeatures;
25 class CCombinedFeatures;
26 class CDynamicObjectArray;
27 
39 class CProductKernel : public CKernel
40 {
41  public:
46  CProductKernel(int32_t size=10);
47 
48  virtual ~CProductKernel();
49 
56  virtual bool init(CFeatures* lhs, CFeatures* rhs);
57 
59  virtual void cleanup();
60 
65  virtual EKernelType get_kernel_type() { return K_PRODUCT; }
66 
71  virtual EFeatureType get_feature_type() { return F_UNKNOWN; }
72 
78 
83  virtual const char* get_name() const { return "ProductKernel"; }
84 
86  void list_kernels();
87 
93  inline CKernel* get_kernel(int32_t idx)
94  {
95  return (CKernel*) kernel_array->get_element(idx);
96  }
97 
105  inline bool insert_kernel(CKernel* k, int32_t idx)
106  {
107  ASSERT(k)
109 
110  if (!(k->has_property(KP_LINADD)))
112 
113  return kernel_array->insert_element(k, idx);
114  }
115 
121  inline bool append_kernel(CKernel* k)
122  {
123  ASSERT(k)
125 
126  if (!(k->has_property(KP_LINADD)))
128 
129  int32_t n = get_num_subkernels();
131  return n+1==get_num_subkernels();
132  }
133 
139  inline bool delete_kernel(int32_t idx)
140  {
141  return kernel_array->delete_element(idx);
142  }
143 
148  inline int32_t get_num_subkernels()
149  {
150  return kernel_array->get_num_elements();
151  }
152 
157  virtual bool has_features()
158  {
159  return initialized;
160  }
161 
163  virtual void remove_lhs();
164 
166  virtual void remove_rhs();
167 
169  virtual void remove_lhs_and_rhs();
170 
172  bool precompute_subkernels();
173 
178  {
179  return dynamic_cast<CProductKernel*>(n);
180  }
181 
190  index_t index=-1);
191 
197  {
199  return kernel_array;
200  }
201 
202  protected:
209  virtual float64_t compute(int32_t x, int32_t y);
210 
217  {
218  ASSERT(k)
219 
220  if (k->get_num_vec_lhs())
221  {
222  if (num_lhs)
225 
226  if (!get_num_subkernels())
227  {
228  initialized=true;
229 
230  }
231  }
232  else
233  initialized=false;
234 
235  if (k->get_num_vec_rhs())
236  {
237  if (num_rhs)
240 
241  if (!get_num_subkernels())
242  {
243  initialized=true;
244 
245  }
246  }
247  else
248  initialized=false;
249  }
250 
251  private:
252  void init();
253 
254  protected:
259 };
260 }
261 #endif /* _PRODUCTKERNEL_H__ */

SHOGUN 机器学习工具包 - 项目文档