SHOGUN
v1.1.0
|
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/features/Labels.h> 00019 00020 namespace shogun 00021 { 00023 class CSubGradientSVM : public CLinearMachine 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 00051 inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; } 00052 00053 00058 inline float64_t get_C1() { return C1; } 00059 00064 inline float64_t get_C2() { return C2; } 00065 00070 inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; } 00071 00076 inline bool get_bias_enabled() { return use_bias; } 00077 00082 inline void set_epsilon(float64_t eps) { epsilon=eps; } 00083 00088 inline float64_t get_epsilon() { return epsilon; } 00089 00094 inline void set_qpsize(int32_t q) { qpsize=q; } 00095 00100 inline int32_t get_qpsize() { return qpsize; } 00101 00106 inline void set_qpsize_max(int32_t q) { qpsize_max=q; } 00107 00112 inline int32_t get_qpsize_max() { return qpsize_max; } 00113 00114 protected: 00117 int32_t find_active( 00118 int32_t num_feat, int32_t num_vec, int32_t& num_active, 00119 int32_t& num_bound); 00120 00123 void update_active(int32_t num_feat, int32_t num_vec); 00124 00126 float64_t compute_objective(int32_t num_feat, int32_t num_vec); 00127 00130 float64_t compute_min_subgradient( 00131 int32_t num_feat, int32_t num_vec, int32_t num_active, 00132 int32_t num_bound); 00133 00135 float64_t line_search(int32_t num_feat, int32_t num_vec); 00136 00138 void compute_projection(int32_t num_feat, int32_t num_vec); 00139 00141 void update_projection(float64_t alpha, int32_t num_vec); 00142 00144 void init(int32_t num_vec, int32_t num_feat); 00145 00147 void cleanup(); 00148 00150 inline virtual const char* get_name() const { return "SubGradientSVM"; } 00151 00152 protected: 00161 virtual bool train_machine(CFeatures* data=NULL); 00162 00163 protected: 00165 float64_t C1; 00167 float64_t C2; 00169 float64_t epsilon; 00171 float64_t work_epsilon; 00173 float64_t autoselected_epsilon; 00175 int32_t qpsize; 00177 int32_t qpsize_max; 00179 int32_t qpsize_limit; 00181 bool use_bias; 00182 00184 int32_t last_it_noimprovement; 00186 int32_t num_it_noimprovement; 00187 00188 //idx vectors of length num_vec 00190 uint8_t* active; 00192 uint8_t* old_active; 00194 int32_t* idx_active; 00196 int32_t* idx_bound; 00198 int32_t delta_active; 00200 int32_t delta_bound; 00202 float64_t* proj; 00204 float64_t* tmp_proj; 00206 int32_t* tmp_proj_idx; 00207 00208 //vector of length num_feat 00210 float64_t* sum_CXy_active; 00212 float64_t* v; 00214 float64_t* old_v; 00216 float64_t sum_Cy_active; 00217 00218 //vector of length num_feat 00220 float64_t* grad_w; 00222 float64_t grad_b; 00224 float64_t* grad_proj; 00226 float64_t* hinge_point; 00228 int32_t* hinge_idx; 00229 00230 //vectors/sym matrix of size qpsize_limit 00232 float64_t* beta; 00234 float64_t* old_beta; 00236 float64_t* Zv; 00238 float64_t* old_Zv; 00240 float64_t* Z; 00242 float64_t* old_Z; 00243 00245 float64_t tim; 00246 }; 00247 } 00248 #endif