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 <shogun/lib/common.h>
00016 #include <shogun/machine/LinearMachine.h>
00017 #include <shogun/features/DotFeatures.h>
00018 #include <shogun/labels/Labels.h>
00019 
00020 namespace shogun
00021 {
00023 class CSubGradientSVM : public CLinearMachine
00024 {
00025     public:
00026 
00028         MACHINE_PROBLEM_TYPE(PT_BINARY);
00029 
00031         CSubGradientSVM();
00032 
00039         CSubGradientSVM(
00040             float64_t C, CDotFeatures* traindat,
00041             CLabels* trainlab);
00042         virtual ~CSubGradientSVM();
00043 
00048         virtual EMachineType get_classifier_type() { return CT_SUBGRADIENTSVM; }
00049 
00055         inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
00056 
00057 
00062         inline float64_t get_C1() { return C1; }
00063 
00068         inline float64_t get_C2() { return C2; }
00069 
00074         inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00075 
00080         inline bool get_bias_enabled() { return use_bias; }
00081 
00086         inline void set_epsilon(float64_t eps) { epsilon=eps; }
00087 
00092         inline float64_t get_epsilon() { return epsilon; }
00093 
00098         inline void set_qpsize(int32_t q) { qpsize=q; }
00099 
00104         inline int32_t get_qpsize() { return qpsize; }
00105 
00110         inline void set_qpsize_max(int32_t q) { qpsize_max=q; }
00111 
00116         inline int32_t get_qpsize_max() { return qpsize_max; }
00117 
00118     protected:
00121         int32_t find_active(
00122             int32_t num_feat, int32_t num_vec, int32_t& num_active,
00123             int32_t& num_bound);
00124 
00127         void update_active(int32_t num_feat, int32_t num_vec);
00128 
00130         float64_t compute_objective(int32_t num_feat, int32_t num_vec);
00131 
00134         float64_t compute_min_subgradient(
00135             int32_t num_feat, int32_t num_vec, int32_t num_active,
00136             int32_t num_bound);
00137 
00139         float64_t line_search(int32_t num_feat, int32_t num_vec);
00140 
00142         void compute_projection(int32_t num_feat, int32_t num_vec);
00143 
00145         void update_projection(float64_t alpha, int32_t num_vec);
00146 
00148         void init(int32_t num_vec, int32_t num_feat);
00149 
00151         void cleanup();
00152 
00154         virtual const char* get_name() const { return "SubGradientSVM"; }
00155 
00156     protected:
00165         virtual bool train_machine(CFeatures* data=NULL);
00166 
00167     protected:
00169         float64_t C1;
00171         float64_t C2;
00173         float64_t epsilon;
00175         float64_t work_epsilon;
00177         float64_t autoselected_epsilon;
00179         int32_t qpsize;
00181         int32_t qpsize_max;
00183         int32_t qpsize_limit;
00185         bool use_bias;
00186 
00188         int32_t last_it_noimprovement;
00190         int32_t num_it_noimprovement;
00191 
00192         //idx vectors of length num_vec
00194         uint8_t* active;
00196         uint8_t* old_active;
00198         int32_t* idx_active;
00200         int32_t* idx_bound;
00202         int32_t delta_active;
00204         int32_t delta_bound;
00206         float64_t* proj;
00208         float64_t* tmp_proj;
00210         int32_t* tmp_proj_idx;
00211 
00212         //vector of length num_feat
00214         float64_t* sum_CXy_active;
00216         float64_t* v;
00218         float64_t* old_v;
00220         float64_t sum_Cy_active;
00221 
00222         //vector of length num_feat
00224         float64_t* grad_w;
00226         float64_t grad_b;
00228         float64_t* grad_proj;
00230         float64_t* hinge_point;
00232         int32_t* hinge_idx;
00233 
00234         //vectors/sym matrix of size qpsize_limit
00236         float64_t* beta;
00238         float64_t* old_beta;
00240         float64_t* Zv;
00242         float64_t* old_Zv;
00244         float64_t* Z;
00246         float64_t* old_Z;
00247 
00249         float64_t tim;
00250 };
00251 }
00252 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation