SubGradientSVM.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) 2007-2009 Soeren Sonnenburg
00008  * Written (W) 2007-2008 Vojtech Franc
00009  * Copyright (C) 2007-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00010  */
00011 
00012 #ifndef _SUBGRADIENTSVM_H___
00013 #define _SUBGRADIENTSVM_H___
00014 
00015 #include "lib/common.h"
00016 #include "classifier/LinearClassifier.h"
00017 #include "features/DotFeatures.h"
00018 #include "features/Labels.h"
00019 
00020 namespace shogun
00021 {
00023 class CSubGradientSVM : public CLinearClassifier
00024 {
00025     public:
00027         CSubGradientSVM();
00028 
00035         CSubGradientSVM(
00036             float64_t C, CDotFeatures* traindat,
00037             CLabels* trainlab);
00038         virtual ~CSubGradientSVM();
00039 
00044         virtual inline EClassifierType get_classifier_type() { return CT_SUBGRADIENTSVM; }
00045 
00054         virtual bool train(CFeatures* data=NULL);
00055 
00061         inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
00062 
00063 
00068         inline float64_t get_C1() { return C1; }
00069 
00074         inline float64_t get_C2() { return C2; }
00075 
00080         inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00081 
00086         inline bool get_bias_enabled() { return use_bias; }
00087 
00092         inline void set_epsilon(float64_t eps) { epsilon=eps; }
00093 
00098         inline float64_t get_epsilon() { return epsilon; }
00099 
00104         inline void set_qpsize(int32_t q) { qpsize=q; }
00105 
00110         inline int32_t get_qpsize() { return qpsize; }
00111 
00116         inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
00117 
00122         inline int32_t get_qpsize_max() { return qpsize_max; }
00123 
00124     protected:
00127         int32_t find_active(
00128             int32_t num_feat, int32_t num_vec, int32_t& num_active,
00129             int32_t& num_bound);
00130 
00133         void update_active(int32_t num_feat, int32_t num_vec);
00134 
00136         float64_t compute_objective(int32_t num_feat, int32_t num_vec);
00137 
00140         float64_t compute_min_subgradient(
00141             int32_t num_feat, int32_t num_vec, int32_t num_active,
00142             int32_t num_bound);
00143 
00145         float64_t line_search(int32_t num_feat, int32_t num_vec);
00146 
00148         void compute_projection(int32_t num_feat, int32_t num_vec);
00149 
00151         void update_projection(float64_t alpha, int32_t num_vec);
00152 
00154         void init(int32_t num_vec, int32_t num_feat);
00155 
00157         void cleanup();
00158 
00160         inline virtual const char* get_name() const { return "SubGradientSVM"; }
00161 
00162     protected:
00164         float64_t C1;
00166         float64_t C2;
00168         float64_t epsilon;
00170         float64_t work_epsilon;
00172         float64_t autoselected_epsilon;
00174         int32_t qpsize;
00176         int32_t qpsize_max;
00178         int32_t qpsize_limit;
00180         bool use_bias;
00181 
00183         int32_t last_it_noimprovement;
00185         int32_t num_it_noimprovement;
00186 
00187         //idx vectors of length num_vec
00189         uint8_t* active;
00191         uint8_t* old_active;
00193         int32_t* idx_active;
00195         int32_t* idx_bound;
00197         int32_t delta_active;
00199         int32_t delta_bound;
00201         float64_t* proj;
00203         float64_t* tmp_proj;
00205         int32_t* tmp_proj_idx;
00206 
00207         //vector of length num_feat
00209         float64_t* sum_CXy_active;
00211         float64_t* v;
00213         float64_t* old_v;
00215         float64_t sum_Cy_active;
00216 
00217         //vector of length num_feat
00219         float64_t* grad_w;
00221         float64_t grad_b;
00223         float64_t* grad_proj;
00225         float64_t* hinge_point;
00227         int32_t* hinge_idx;
00228 
00229         //vectors/sym matrix of size qpsize_limit
00231         float64_t* beta;
00233         float64_t* old_beta;
00235         float64_t* Zv;
00237         float64_t* old_Zv;
00239         float64_t* Z;
00241         float64_t* old_Z;
00242 
00244         float64_t tim;
00245 };
00246 }
00247 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation