SVM.h

Go to the documentation of this file.
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 "lib/common.h"
00015 #include "features/Features.h"
00016 #include "kernel/Kernel.h"
00017 #include "classifier/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 
00076         virtual float64_t* get_linear_term_ptr(index_t* len);
00077 
00078 
00085         virtual void set_linear_term(float64_t* linear_term, index_t len);
00086 
00087 
00091         bool load(FILE* svm_file);
00092 
00096         bool save(FILE* svm_file);
00097 
00102         inline void set_nu(float64_t nue) { nu=nue; }
00103 
00104 
00113         inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
00114 
00115 
00120         inline void set_epsilon(float64_t eps) { epsilon=eps; }
00121 
00126         inline void set_tube_epsilon(float64_t eps) { tube_epsilon=eps; }
00127 
00132         inline float64_t get_tube_epsilon() { return tube_epsilon; }
00133 
00138         inline void set_qpsize(int32_t qps) { qpsize=qps; }
00139 
00144         inline float64_t get_epsilon() { return epsilon; }
00145 
00150         inline float64_t get_nu() { return nu; }
00151 
00156         inline float64_t get_C1() { return C1; }
00157 
00162         inline float64_t get_C2() { return C2; }
00163 
00168         inline int32_t get_qpsize() { return qpsize; }
00169 
00174         inline void set_shrinking_enabled(bool enable)
00175         {
00176             use_shrinking=enable;
00177         }
00178 
00183         inline bool get_shrinking_enabled()
00184         {
00185             return use_shrinking;
00186         }
00187 
00192         float64_t compute_svm_dual_objective();
00193 
00198         float64_t compute_svm_primal_objective();
00199 
00204         inline void set_objective(float64_t v)
00205         {
00206             objective=v;
00207         }
00208 
00213         inline float64_t get_objective()
00214         {
00215             return objective;
00216         }
00217 
00225         void set_callback_function(CMKL* m, bool (*cb)
00226                 (CMKL* mkl, const float64_t* sumw, const float64_t suma));
00227 
00229         inline virtual const char* get_name() const { return "SVM"; }
00230 
00231     protected:
00232 
00238         virtual float64_t* get_linear_term_array();
00239 
00241         float64_t* m_linear_term;
00242         index_t m_linear_term_len;
00243 
00245         bool svm_loaded;
00247         float64_t epsilon;
00249         float64_t tube_epsilon;
00251         float64_t nu;
00253         float64_t C1;
00255         float64_t C2;
00257         float64_t objective;
00259         int32_t qpsize;
00261         bool use_shrinking;
00262 
00265         bool (*callback) (CMKL* mkl, const float64_t* sumw, const float64_t suma);
00268         CMKL* mkl;
00269 };
00270 }
00271 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation