CustomKernel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _CUSTOMKERNEL_H___
00012 #define _CUSTOMKERNEL_H___
00013
00014 #include "lib/Mathematics.h"
00015 #include "lib/common.h"
00016 #include "kernel/Kernel.h"
00017 #include "features/Features.h"
00018
00028 class CCustomKernel: public CKernel
00029 {
00030 public:
00032 CCustomKernel();
00033
00039 CCustomKernel(CKernel* k);
00040
00041 virtual ~CCustomKernel();
00042
00050 virtual float32_t* get_kernel_matrix_shortreal(
00051 int32_t &m, int32_t &n, float32_t* target=NULL);
00052
00063 virtual bool dummy_init(int32_t rows, int32_t cols);
00064
00071 virtual bool init(CFeatures* l, CFeatures* r);
00072
00074 virtual void cleanup();
00075
00081 virtual bool load_init(FILE* src);
00082
00088 virtual bool save_init(FILE* dest);
00089
00094 inline virtual EKernelType get_kernel_type() { return K_CUSTOM; }
00095
00100 inline virtual EFeatureType get_feature_type() { return F_ANY; }
00101
00106 inline virtual EFeatureClass get_feature_class() { return C_ANY; }
00107
00112 virtual const char* get_name() { return "Custom"; }
00113
00122 bool set_triangle_kernel_matrix_from_triangle(
00123 const float64_t* km, int32_t len);
00124
00133 bool set_triangle_kernel_matrix_from_full(
00134 const float64_t* km, int32_t rows, int32_t cols);
00135
00143 bool set_full_kernel_matrix_from_full(
00144 const float64_t* km, int32_t rows, int32_t cols);
00145
00146 protected:
00153 inline virtual float64_t compute(int32_t row, int32_t col)
00154 {
00155 ASSERT(row<num_rows);
00156 ASSERT(col<num_cols);
00157 ASSERT(kmatrix);
00158
00159 if (upper_diagonal)
00160 {
00161 if (row <= col)
00162 return kmatrix[row*num_cols - row*(row+1)/2 + col];
00163 else
00164 return kmatrix[col*num_cols - col*(col+1)/2 + row];
00165 }
00166 else
00167 return kmatrix[row*num_cols+col];
00168 }
00169
00170 private:
00172 void cleanup_custom();
00173
00174 protected:
00176 float32_t* kmatrix;
00178 int32_t num_rows;
00180 int32_t num_cols;
00182 bool upper_diagonal;
00183 };
00184 #endif