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/SimpleFeatures.h"
00017
00026 class CLinearKernel: public CSimpleKernel<float64_t>
00027 {
00028 public:
00031 CLinearKernel();
00032
00038 CLinearKernel(CSimpleFeatures<float64_t>* l, CSimpleFeatures<float64_t>* r);
00039
00040 virtual ~CLinearKernel();
00041
00048 virtual bool init(CFeatures* l, CFeatures* r);
00049
00051 virtual void cleanup();
00052
00058 virtual bool load_init(FILE* src);
00059
00065 virtual bool save_init(FILE* dest);
00066
00071 virtual EKernelType get_kernel_type() { return K_LINEAR; }
00072
00077 virtual const char* get_name() const { return "Linear"; }
00078
00087 virtual bool init_optimization(
00088 int32_t num_suppvec, int32_t* sv_idx, float64_t* alphas);
00089
00094 virtual bool delete_optimization();
00095
00101 virtual float64_t compute_optimized(int32_t idx);
00102
00104 virtual void clear_normal();
00105
00111 virtual void add_to_normal(int32_t idx, float64_t weight);
00112
00118 inline const float64_t* get_normal(int32_t& len)
00119 {
00120 if (lhs && normal)
00121 {
00122 len = ((CSimpleFeatures<float64_t>*) lhs)->get_num_features();
00123 return normal;
00124 }
00125 else
00126 {
00127 len = 0;
00128 return NULL;
00129 }
00130 }
00131
00137 inline void get_w(float64_t** dst_w, int32_t* dst_dims)
00138 {
00139 ASSERT(lhs && normal);
00140 int32_t len = ((CSimpleFeatures<float64_t>*) lhs)->get_num_features();
00141 ASSERT(dst_w && dst_dims);
00142 *dst_dims=len;
00143 *dst_w=(float64_t*) malloc(sizeof(float64_t)*(*dst_dims));
00144 ASSERT(*dst_w);
00145 memcpy(*dst_w, normal, sizeof(float64_t) * (*dst_dims));
00146 }
00147
00153 inline void set_w(float64_t* src_w, int32_t src_w_dim)
00154 {
00155 ASSERT(lhs && src_w_dim==((CSimpleFeatures<float64_t>*) lhs)->get_num_features());
00156 clear_normal();
00157 memcpy(normal, src_w, sizeof(float64_t) * src_w_dim);
00158 }
00159
00160 protected:
00169 virtual float64_t compute(int32_t idx_a, int32_t idx_b);
00170
00171 protected:
00173 float64_t* normal;
00175 int32_t normal_length;
00176 };
00177
00178 #endif