SHOGUN  v3.2.0
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__ */
EKernelType
Definition: Kernel.h:51
int32_t index_t
Definition: common.h:60
int32_t num_rhs
number of feature vectors on right hand side
Definition: Kernel.h:714
The Product kernel is used to combine a number of kernels into a single ProductKernel object by eleme...
Definition: ProductKernel.h:39
virtual EFeatureClass get_feature_class()
Definition: ProductKernel.h:77
virtual EFeatureType get_feature_type()
Definition: ProductKernel.h:71
virtual bool has_features()
bool delete_kernel(int32_t idx)
bool insert_element(CSGObject *e, int32_t index)
SGMatrix< float64_t > get_parameter_gradient(const TParameter *param, index_t index=-1)
parameter struct
Definition: Parameter.h:26
CSGObject * get_element(int32_t index) const
CProductKernel(int32_t size=10)
virtual const char * get_name() const
Definition: ProductKernel.h:83
virtual void remove_lhs_and_rhs()
virtual EKernelType get_kernel_type()
Definition: ProductKernel.h:65
CDynamicObjectArray * get_array()
virtual int32_t get_num_vec_lhs()
Definition: Kernel.h:355
EFeatureClass
shogun feature class
Definition: FeatureTypes.h:35
virtual void remove_rhs()
bool has_property(EKernelProperty p)
Definition: Kernel.h:447
virtual void remove_lhs()
#define ASSERT(x)
Definition: SGIO.h:203
void adjust_num_lhs_rhs_initialized(CKernel *k)
double float64_t
Definition: common.h:48
#define SG_REF(x)
Definition: SGRefObject.h:34
void unset_property(EKernelProperty p)
Definition: Kernel.h:601
Dynamic array class for CSGObject pointers that creates an array that can be used like a list or an a...
int32_t num_lhs
number of feature vectors on left hand side
Definition: Kernel.h:712
virtual int32_t get_num_vec_rhs()
Definition: Kernel.h:364
EFeatureType
shogun feature type
Definition: FeatureTypes.h:16
CFeatures * rhs
feature vectors to occur on right hand side
Definition: Kernel.h:706
CDynamicObjectArray * kernel_array
bool insert_kernel(CKernel *k, int32_t idx)
CKernel * get_kernel(int32_t idx)
Definition: ProductKernel.h:93
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
CProductKernel * KernelToProductKernel(CKernel *n)
CFeatures * lhs
feature vectors to occur on left hand side
Definition: Kernel.h:704
The class Features is the base class of all feature objects.
Definition: Features.h:62
virtual float64_t compute(int32_t x, int32_t y)
The Kernel base class.
Definition: Kernel.h:150
bool append_kernel(CKernel *k)
virtual bool init(CFeatures *lhs, CFeatures *rhs)

SHOGUN Machine Learning Toolbox - Documentation