LinearKernel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _LINEARKERNEL_H___
00012 #define _LINEARKERNEL_H___
00013
00014 #include "lib/common.h"
00015 #include "kernel/SimpleKernel.h"
00016 #include "features/RealFeatures.h"
00017
00023 class CLinearKernel: public CSimpleKernel<float64_t>
00024 {
00025 public:
00028 CLinearKernel();
00029
00035 CLinearKernel(CRealFeatures* l, CRealFeatures* r);
00036
00037 virtual ~CLinearKernel();
00038
00045 virtual bool init(CFeatures* l, CFeatures* r);
00046
00048 virtual void cleanup();
00049
00055 virtual bool load_init(FILE* src);
00056
00062 virtual bool save_init(FILE* dest);
00063
00068 virtual EKernelType get_kernel_type() { return K_LINEAR; }
00069
00074 virtual const char* get_name() { return "Linear"; }
00075
00084 virtual bool init_optimization(
00085 int32_t num_suppvec, int32_t* sv_idx, float64_t* alphas);
00086
00091 virtual bool delete_optimization();
00092
00098 virtual float64_t compute_optimized(int32_t idx);
00099
00101 virtual void clear_normal();
00102
00108 virtual void add_to_normal(int32_t idx, float64_t weight);
00109
00115 inline const float64_t* get_normal(int32_t& len)
00116 {
00117 if (lhs && normal)
00118 {
00119 len = ((CRealFeatures*) lhs)->get_num_features();
00120 return normal;
00121 }
00122 else
00123 {
00124 len = 0;
00125 return NULL;
00126 }
00127 }
00128
00134 inline void get_w(float64_t** dst_w, int32_t* dst_dims)
00135 {
00136 ASSERT(lhs && normal);
00137 int32_t len = ((CRealFeatures*) lhs)->get_num_features();
00138 ASSERT(dst_w && dst_dims);
00139 *dst_dims=len;
00140 *dst_w=(float64_t*) malloc(sizeof(float64_t)*(*dst_dims));
00141 ASSERT(*dst_w);
00142 memcpy(*dst_w, normal, sizeof(float64_t) * (*dst_dims));
00143 }
00144
00150 inline void set_w(float64_t* src_w, int32_t src_w_dim)
00151 {
00152 ASSERT(lhs && src_w_dim==((CRealFeatures*) lhs)->get_num_features());
00153 clear_normal();
00154 memcpy(normal, src_w, sizeof(float64_t) * src_w_dim);
00155 }
00156
00157 protected:
00166 virtual float64_t compute(int32_t idx_a, int32_t idx_b);
00167
00168 protected:
00170 float64_t* normal;
00172 int32_t normal_length;
00173 };
00174
00175 #endif