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-2008 Soeren Sonnenburg
00008  * Written (W) 2007-2008 Vojtech Franc
00009  * Copyright (C) 2007-2008 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/SparseLinearClassifier.h"
00017 #include "features/SparseFeatures.h"
00018 #include "features/Labels.h"
00019 
00021 class CSubGradientSVM : public CSparseLinearClassifier
00022 {
00023     public:
00025         CSubGradientSVM();
00026 
00033         CSubGradientSVM(DREAL C, CSparseFeatures<DREAL>* traindat, CLabels* trainlab);
00034         virtual ~CSubGradientSVM();
00035 
00040         virtual inline EClassifierType get_classifier_type() { return CT_SUBGRADIENTSVM; }
00041 
00046         virtual bool train();
00047 
00053         inline void set_C(DREAL c1, DREAL c2) { C1=c1; C2=c2; }
00054 
00059         inline DREAL get_C1() { return C1; }
00060 
00065         inline DREAL get_C2() { return C2; }
00066 
00071         inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00072 
00077         inline bool get_bias_enabled() { return use_bias; }
00078 
00083         inline void set_epsilon(DREAL eps) { epsilon=eps; }
00084 
00089         inline DREAL get_epsilon() { return epsilon; }
00090 
00095         inline void set_qpsize(INT q) { qpsize=q; }
00096 
00101         inline INT get_qpsize() { return qpsize; }
00102 
00107         inline void set_qpsize_max(INT q) { qpsize_max=q; }
00108 
00113         inline INT get_qpsize_max() { return qpsize_max; }
00114 
00115     protected:
00118         INT find_active(INT num_feat, INT num_vec, INT& num_active, INT& num_bound);
00119 
00122         void update_active(INT num_feat, INT num_vec);
00123 
00125         DREAL compute_objective(INT num_feat, INT num_vec);
00126 
00129         DREAL compute_min_subgradient(INT num_feat, INT num_vec, INT num_active, INT num_bound);
00130 
00132         DREAL line_search(INT num_feat, INT num_vec);
00133 
00135         void compute_projection(INT num_feat, INT num_vec);
00136 
00138         void update_projection(DREAL alpha, INT num_vec);
00139 
00141         void init(INT num_vec, INT num_feat);
00142         
00144         void cleanup();
00145 
00146     protected:
00148         DREAL C1;
00150         DREAL C2;
00152         DREAL epsilon;
00154         DREAL work_epsilon;
00156         DREAL autoselected_epsilon;
00158         INT qpsize;
00160         INT qpsize_max;
00162         INT qpsize_limit;
00164         bool use_bias;
00165 
00167         INT last_it_noimprovement;
00169         INT num_it_noimprovement;
00170 
00171         //idx vectors of length num_vec
00173         BYTE* active;
00175         BYTE* old_active;
00177         INT* idx_active;
00179         INT* idx_bound;
00181         INT delta_active;
00183         INT delta_bound;
00185         DREAL* proj;
00187         DREAL* tmp_proj;
00189         INT* tmp_proj_idx;
00190         
00191         //vector of length num_feat
00193         DREAL* sum_CXy_active;
00195         DREAL* v;
00197         DREAL* old_v;
00199         DREAL sum_Cy_active;
00200 
00201         //vector of length num_feat
00203         DREAL* grad_w;
00205         DREAL grad_b;
00207         DREAL* grad_proj;
00209         DREAL* hinge_point;
00211         INT* hinge_idx;
00212 
00213         //vectors/sym matrix of size qpsize_limit
00215         DREAL* beta;
00217         DREAL* old_beta;
00219         DREAL* Zv;
00221         DREAL* old_Zv;
00223         DREAL* Z;
00225         DREAL* old_Z;
00226 };
00227 #endif
00228 

SHOGUN Machine Learning Toolbox - Documentation