SHOGUN
v3.2.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) 2012 Viktor Gal 00008 * Copyright (C) 2008 Chun-Nam Yu 00009 */ 00010 00011 #ifndef __CCSOSVM_H__ 00012 #define __CCSOSVM_H__ 00013 00014 #include <shogun/lib/config.h> 00015 #include <shogun/machine/LinearStructuredOutputMachine.h> 00016 #include <shogun/base/DynArray.h> 00017 00018 #ifdef USE_MOSEK 00019 #include <mosek.h> 00020 #endif 00021 00022 namespace shogun 00023 { 00024 00029 enum EQPType 00030 { 00031 MOSEK=1, 00032 SVMLIGHT=2 00033 }; 00034 00043 class CCCSOSVM : public CLinearStructuredOutputMachine 00044 { 00045 public: 00047 CCCSOSVM(); 00048 00053 CCCSOSVM(CStructuredModel* model, SGVector<float64_t> w = SGVector<float64_t>()); 00054 00056 virtual ~CCCSOSVM(); 00057 00059 inline virtual const char* get_name() const { return "CCSOSVM"; } 00060 00065 inline void set_w(SGVector< float64_t > W) 00066 { 00067 REQUIRE(W.vlen == m_model->get_dim(), "Dimension of the initial " 00068 "solution must match the model's dimension!\n"); 00069 m_w=W; 00070 } 00071 00076 inline void set_epsilon(float64_t eps) 00077 { 00078 m_eps = eps; 00079 } 00080 00085 inline float64_t get_epsilon() const 00086 { 00087 return m_eps; 00088 } 00089 00094 inline void set_C(float64_t C) 00095 { 00096 m_C = C; 00097 } 00098 00103 inline float64_t get_C() const 00104 { 00105 return m_C; 00106 } 00107 00112 inline void set_max_iter(index_t max_iter) 00113 { 00114 m_max_iter = max_iter; 00115 } 00116 00121 inline index_t get_max_iter() const 00122 { 00123 return m_max_iter; 00124 } 00125 00130 inline float64_t compute_primal_objective() 00131 { 00132 return m_primal_obj; 00133 } 00134 00139 inline float64_t get_max_rho() const 00140 { 00141 return m_max_rho; 00142 } 00143 00148 inline void set_max_rho(float64_t max_rho) 00149 { 00150 m_max_rho = max_rho; 00151 } 00152 00157 inline EQPType get_qp_type() const 00158 { 00159 return m_qp_type; 00160 } 00161 00166 inline void set_qp_type(EQPType type) 00167 { 00168 m_qp_type = type; 00169 } 00170 00175 virtual EMachineType get_classifier_type(); 00176 00177 protected: 00178 bool train_machine(CFeatures* data=NULL); 00179 00180 private: 00186 SGSparseVector<float64_t> find_cutting_plane(float64_t* margin); 00187 00188 int32_t resize_cleanup(int32_t size_active, SGVector<int32_t>& idle, SGVector<float64_t>&alpha, 00189 SGVector<float64_t>& delta, SGVector<float64_t>& gammaG0, 00190 SGVector<float64_t>& proximal_rhs, float64_t ***ptr_G, 00191 DynArray<SGSparseVector<float64_t> >& dXc, SGVector<float64_t>& cut_error); 00192 00193 int32_t mosek_qp_optimize(float64_t** G, float64_t* delta, float64_t* alpha, int32_t k, float64_t* dual_obj, float64_t rho); 00194 00196 void init(); 00197 00198 private: 00200 float64_t m_C; 00202 float64_t m_eps; 00204 float64_t m_primal_obj; 00205 float64_t m_alpha_thrld; 00206 float64_t m_max_rho; 00207 00209 index_t m_max_iter; 00211 index_t m_cleanup_check; 00213 index_t m_idle_iter; 00214 00216 EQPType m_qp_type; 00217 #ifdef USE_MOSEK 00218 00219 MSKenv_t m_msk_env; 00220 #endif 00221 }; 00222 } 00223 00224 #endif