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 00018 namespace shogun 00019 { 00029 class CSparseLinearKernel: public CSparseKernel<float64_t> 00030 { 00031 public: 00034 CSparseLinearKernel(); 00035 00041 CSparseLinearKernel( 00042 CSparseFeatures<float64_t>* l, CSparseFeatures<float64_t>* r); 00043 00044 virtual ~CSparseLinearKernel(); 00045 00052 virtual bool init(CFeatures* l, CFeatures* r); 00053 00055 virtual void cleanup(); 00056 00061 virtual EKernelType get_kernel_type() { return K_SPARSELINEAR; } 00062 00067 virtual const char* get_name() const { return "SparseLinear"; } 00068 00077 virtual bool init_optimization(int32_t num_suppvec, int32_t* sv_idx, 00078 float64_t* alphas); 00079 00084 virtual bool delete_optimization(); 00085 00091 virtual float64_t compute_optimized(int32_t idx); 00092 00094 virtual void clear_normal(); 00095 00101 virtual void add_to_normal(int32_t idx, float64_t weight); 00102 00108 inline const float64_t* get_normal(int32_t& len) 00109 { 00110 len=normal_length; 00111 return normal; 00112 } 00113 00114 protected: 00123 virtual float64_t compute(int32_t idx_a, int32_t idx_b); 00124 00125 protected: 00127 float64_t* normal; 00129 int32_t normal_length; 00130 }; 00131 } 00132 #endif /* _SPARSELINEARKERNEL_H__ */