00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 1999-2009 Soeren Sonnenburg 00008 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef _SPARSELINEARKERNEL_H___ 00012 #define _SPARSELINEARKERNEL_H___ 00013 00014 #include "lib/common.h" 00015 #include "kernel/SparseKernel.h" 00016 #include "features/SparseFeatures.h" 00017 00027 class CSparseLinearKernel: public CSparseKernel<float64_t> 00028 { 00029 public: 00032 CSparseLinearKernel(); 00033 00039 CSparseLinearKernel( 00040 CSparseFeatures<float64_t>* l, CSparseFeatures<float64_t>* r); 00041 00042 virtual ~CSparseLinearKernel(); 00043 00050 virtual bool init(CFeatures* l, CFeatures* r); 00051 00053 virtual void cleanup(); 00054 00060 virtual bool load_init(FILE* src); 00061 00067 virtual bool save_init(FILE* dest); 00068 00073 virtual EKernelType get_kernel_type() { return K_SPARSELINEAR; } 00074 00079 virtual const char* get_name() const { return "SparseLinear"; } 00080 00089 virtual bool init_optimization(int32_t num_suppvec, int32_t* sv_idx, 00090 float64_t* alphas); 00091 00096 virtual bool delete_optimization(); 00097 00103 virtual float64_t compute_optimized(int32_t idx); 00104 00106 virtual void clear_normal(); 00107 00113 virtual void add_to_normal(int32_t idx, float64_t weight); 00114 00120 inline const float64_t* get_normal(int32_t& len) 00121 { 00122 len=normal_length; 00123 return normal; 00124 } 00125 00126 protected: 00135 virtual float64_t compute(int32_t idx_a, int32_t idx_b); 00136 00137 protected: 00139 float64_t* normal; 00141 int32_t normal_length; 00142 }; 00143 00144 #endif /* _SPARSELINEARKERNEL_H__ */