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 _SVM_H___ 00012 #define _SVM_H___ 00013 00014 #include <shogun/lib/common.h> 00015 #include <shogun/features/Features.h> 00016 #include <shogun/kernel/Kernel.h> 00017 #include <shogun/machine/KernelMachine.h> 00018 00019 namespace shogun 00020 { 00021 00022 class CMKL; 00023 00046 class CSVM : public CKernelMachine 00047 { 00048 public: 00052 CSVM(int32_t num_sv=0); 00053 00061 CSVM(float64_t C, CKernel* k, CLabels* lab); 00062 virtual ~CSVM(); 00063 00066 void set_defaults(int32_t num_sv=0); 00067 00068 00074 virtual SGVector<float64_t> get_linear_term(); 00075 00076 00082 virtual void set_linear_term(SGVector<float64_t> linear_term); 00083 00084 00088 bool load(FILE* svm_file); 00089 00093 bool save(FILE* svm_file); 00094 00099 inline void set_nu(float64_t nue) { nu=nue; } 00100 00101 00110 inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; } 00111 00112 00117 inline void set_epsilon(float64_t eps) { epsilon=eps; } 00118 00123 inline void set_tube_epsilon(float64_t eps) { tube_epsilon=eps; } 00124 00129 inline float64_t get_tube_epsilon() { return tube_epsilon; } 00130 00135 inline void set_qpsize(int32_t qps) { qpsize=qps; } 00136 00141 inline float64_t get_epsilon() { return epsilon; } 00142 00147 inline float64_t get_nu() { return nu; } 00148 00153 inline float64_t get_C1() { return C1; } 00154 00159 inline float64_t get_C2() { return C2; } 00160 00165 inline int32_t get_qpsize() { return qpsize; } 00166 00171 inline void set_shrinking_enabled(bool enable) 00172 { 00173 use_shrinking=enable; 00174 } 00175 00180 inline bool get_shrinking_enabled() 00181 { 00182 return use_shrinking; 00183 } 00184 00189 float64_t compute_svm_dual_objective(); 00190 00195 float64_t compute_svm_primal_objective(); 00196 00201 inline void set_objective(float64_t v) 00202 { 00203 objective=v; 00204 } 00205 00210 inline float64_t get_objective() 00211 { 00212 return objective; 00213 } 00214 00222 void set_callback_function(CMKL* m, bool (*cb) 00223 (CMKL* mkl, const float64_t* sumw, const float64_t suma)); 00224 00226 inline virtual const char* get_name() const { return "SVM"; } 00227 00228 protected: 00229 00235 virtual float64_t* get_linear_term_array(); 00236 00238 SGVector<float64_t> m_linear_term; 00239 00241 bool svm_loaded; 00243 float64_t epsilon; 00245 float64_t tube_epsilon; 00247 float64_t nu; 00249 float64_t C1; 00251 float64_t C2; 00253 float64_t objective; 00255 int32_t qpsize; 00257 bool use_shrinking; 00258 00261 bool (*callback) (CMKL* mkl, const float64_t* sumw, const float64_t suma); 00264 CMKL* mkl; 00265 }; 00266 } 00267 #endif