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-2010 Soeren Sonnenburg 00008 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 * Copyright (C) 2010 Berlin Institute of Technology 00010 */ 00011 00012 #ifndef _LINEARKERNEL_H___ 00013 #define _LINEARKERNEL_H___ 00014 00015 #include <shogun/lib/common.h> 00016 #include <shogun/kernel/DotKernel.h> 00017 #include <shogun/features/DotFeatures.h> 00018 #include <shogun/machine/KernelMachine.h> 00019 00020 namespace shogun 00021 { 00022 class CKernelMachine; 00023 class CDotFeatures; 00024 00033 class CLinearKernel: public CDotKernel 00034 { 00035 public: 00038 CLinearKernel(); 00039 00045 CLinearKernel(CDotFeatures* l, CDotFeatures* r); 00046 00047 virtual ~CLinearKernel(); 00048 00055 virtual bool init(CFeatures* l, CFeatures* r); 00056 00058 virtual void cleanup(); 00059 00064 virtual EKernelType get_kernel_type() { return K_LINEAR; } 00065 00070 virtual const char* get_name() const { return "LinearKernel"; } 00071 00080 virtual bool init_optimization( 00081 int32_t num_suppvec, int32_t* sv_idx, float64_t* alphas); 00082 00086 virtual bool init_optimization(CKernelMachine* km); 00087 00092 virtual bool delete_optimization(); 00093 00099 virtual float64_t compute_optimized(int32_t idx); 00100 00101 virtual void clear_normal() 00102 { 00103 normal = SGVector<float64_t>(((CDotFeatures*)lhs)->get_dim_feature_space()); 00104 normal.zero(); 00105 set_is_initialized(true); 00106 } 00107 00113 virtual void add_to_normal(int32_t idx, float64_t weight); 00114 00120 SGVector<float64_t> get_w() const 00121 { 00122 ASSERT(lhs); 00123 return normal; 00124 } 00125 00130 void set_w(SGVector<float64_t> w) 00131 { 00132 ASSERT(lhs && w.size()==((CDotFeatures*) lhs)->get_dim_feature_space()); 00133 this->normal = w; 00134 } 00135 00136 protected: 00138 SGVector<float64_t> normal; 00139 }; 00140 } 00141 #endif /* _LINEARKERNEL_H__ */