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
00026 class CCustomKernel: public CKernel
00027 {
00028 public:
00030 CCustomKernel();
00031
00037 CCustomKernel(CFeatures* l, CFeatures* r);
00038
00039 virtual ~CCustomKernel();
00040
00048 virtual SHORTREAL* get_kernel_matrix_shortreal(INT &m, INT &n, SHORTREAL* target=NULL);
00049
00056 virtual bool init(CFeatures* l, CFeatures* r);
00057
00059 virtual void cleanup();
00060
00066 virtual bool load_init(FILE* src);
00067
00073 virtual bool save_init(FILE* dest);
00074
00079 inline virtual EKernelType get_kernel_type() { return K_CUSTOM; }
00080
00085 inline virtual EFeatureType get_feature_type() { return F_ANY; }
00086
00091 inline virtual EFeatureClass get_feature_class() { return C_ANY; }
00092
00097 virtual const CHAR* get_name() { return "Custom"; }
00098
00107 bool set_triangle_kernel_matrix_from_triangle(const DREAL* km, INT len);
00108
00117 bool set_triangle_kernel_matrix_from_full(const DREAL* km, INT rows, INT cols);
00118
00126 bool set_full_kernel_matrix_from_full(const DREAL* km, INT rows, INT cols);
00127
00128 protected:
00135 inline virtual DREAL compute(INT row, INT col)
00136 {
00137 ASSERT(row<num_rows);
00138 ASSERT(col<num_cols);
00139 ASSERT(kmatrix);
00140
00141 if (upper_diagonal)
00142 {
00143 if (row <= col)
00144 return kmatrix[row*num_cols - row*(row+1)/2 + col];
00145 else
00146 return kmatrix[col*num_cols - col*(col+1)/2 + row];
00147 }
00148 else
00149 return kmatrix[row*num_cols+col];
00150 }
00151
00152 private:
00154 void cleanup_custom();
00155
00156 protected:
00158 SHORTREAL* kmatrix;
00160 INT num_rows;
00162 INT num_cols;
00164 bool upper_diagonal;
00165 };
00166 #endif