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 <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 class CMulticlassSVM;
00024 
00047 class CSVM : public CKernelMachine
00048 {
00049     public:
00050 
00052         MACHINE_PROBLEM_TYPE(PT_BINARY);
00053 
00057         CSVM(int32_t num_sv=0);
00058 
00066         CSVM(float64_t C, CKernel* k, CLabels* lab);
00067 
00068         virtual ~CSVM();
00069 
00072         void set_defaults(int32_t num_sv=0);
00073 
00074 
00080         virtual SGVector<float64_t> get_linear_term();
00081 
00082 
00088         virtual void set_linear_term(const SGVector<float64_t> linear_term);
00089 
00090 
00094         bool load(FILE* svm_file);
00095 
00099         bool save(FILE* svm_file);
00100 
00105         inline void set_nu(float64_t nue) { nu=nue; }
00106 
00107 
00116         inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
00117 
00118 
00123         inline void set_epsilon(float64_t eps) { epsilon=eps; }
00124 
00129         inline void set_tube_epsilon(float64_t eps) { tube_epsilon=eps; }
00130 
00135         inline float64_t get_tube_epsilon() { return tube_epsilon; }
00136 
00141         inline void set_qpsize(int32_t qps) { qpsize=qps; }
00142 
00147         inline float64_t get_epsilon() { return epsilon; }
00148 
00153         inline float64_t get_nu() { return nu; }
00154 
00159         inline float64_t get_C1() { return C1; }
00160 
00165         inline float64_t get_C2() { return C2; }
00166 
00171         inline int32_t get_qpsize() { return qpsize; }
00172 
00177         inline void set_shrinking_enabled(bool enable)
00178         {
00179             use_shrinking=enable;
00180         }
00181 
00186         inline bool get_shrinking_enabled()
00187         {
00188             return use_shrinking;
00189         }
00190 
00195         float64_t compute_svm_dual_objective();
00196 
00201         float64_t compute_svm_primal_objective();
00202 
00207         inline void set_objective(float64_t v)
00208         {
00209             objective=v;
00210         }
00211 
00216         inline float64_t get_objective()
00217         {
00218             return objective;
00219         }
00220 
00228         void set_callback_function(CMKL* m, bool (*cb)
00229                 (CMKL* mkl, const float64_t* sumw, const float64_t suma));
00230 
00232         virtual const char* get_name() const { return "SVM"; }
00233 
00234     protected:
00235 
00241         virtual float64_t* get_linear_term_array();
00242 
00244         SGVector<float64_t> m_linear_term;
00245 
00247         bool svm_loaded;
00249         float64_t epsilon;
00251         float64_t tube_epsilon;
00253         float64_t nu;
00255         float64_t C1;
00257         float64_t C2;
00259         float64_t objective;
00261         int32_t qpsize;
00263         bool use_shrinking;
00264 
00267         bool (*callback) (CMKL* mkl, const float64_t* sumw, const float64_t suma);
00270         CMKL* mkl;
00271 
00272     friend class CMulticlassSVM;
00273 };
00274 }
00275 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation