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-2008 Soeren Sonnenburg 00008 * Copyright (C) 1999-2008 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 00023 class CSparseLinearKernel: public CSparseKernel<DREAL> 00024 { 00025 public: 00031 CSparseLinearKernel(INT size, DREAL scale=1.0); 00032 00040 CSparseLinearKernel( 00041 CSparseFeatures<DREAL>* l, CSparseFeatures<DREAL>* r, 00042 DREAL scale=1.0, INT size=10); 00043 00044 virtual ~CSparseLinearKernel(); 00045 00052 virtual bool init(CFeatures* l, CFeatures* r); 00053 00055 virtual void cleanup(); 00056 00062 virtual bool load_init(FILE* src); 00063 00069 virtual bool save_init(FILE* dest); 00070 00075 virtual EKernelType get_kernel_type() { return K_SPARSELINEAR; } 00076 00081 virtual const CHAR* get_name() { return "SparseLinear" ; } ; 00082 00091 virtual bool init_optimization(INT num_suppvec, INT* sv_idx, 00092 DREAL* alphas); 00093 00098 virtual bool delete_optimization(); 00099 00105 virtual DREAL compute_optimized(INT idx); 00106 00108 virtual void clear_normal(); 00109 00115 virtual void add_to_normal(INT idx, DREAL weight); 00116 00122 inline const double* get_normal(INT& len) 00123 { 00124 len=normal_length; 00125 return normal; 00126 } 00127 00128 protected: 00137 virtual DREAL compute(INT idx_a, INT idx_b); 00138 00140 virtual void init_rescale(); 00141 00142 protected: 00144 double scale; 00146 bool initialized; 00147 00149 DREAL* normal; 00151 INT normal_length; 00152 }; 00153 00154 #endif /* _SPARSELINEARKERNEL_H__ */