SHOGUN
v2.0.0
|
00001 /*----------------------------------------------------------------------- 00002 * 00003 * This program is free software; you can redistribute it and/or modify 00004 * it under the terms of the GNU General Public License as published by 00005 * the Free Software Foundation; either version 3 of the License, or 00006 * (at your option) any later version. 00007 * 00008 * Library for solving QP task required for learning SVM without bias term. 00009 * 00010 * Written (W) 1999-2008 Vojtech Franc, xfrancv@cmp.felk.cvut.cz 00011 * Copyright (C) 1999-2008 Center for Machine Perception, CTU FEL Prague 00012 * 00013 -------------------------------------------------------------------- */ 00014 00015 #ifndef QPBSVMLIB_H__ 00016 #define QPBSVMLIB_H__ 00017 00018 #include <math.h> 00019 #include <limits.h> 00020 00021 #include <shogun/base/SGObject.h> 00022 #include <shogun/io/SGIO.h> 00023 #include <shogun/lib/config.h> 00024 #include <shogun/lib/common.h> 00025 #include <shogun/kernel/Kernel.h> 00026 00027 namespace shogun 00028 { 00029 00030 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00031 enum E_QPB_SOLVER 00032 { 00033 QPB_SOLVER_SCA, // sequential coordinate wise (gaussian seidel based) 00034 QPB_SOLVER_SCAS, // sequential coordinate wise selecting the variable 00035 // gaining 'best' improved 00036 QPB_SOLVER_SCAMV, // sequential coordinate wise selecting variable most violating kkt's 00037 QPB_SOLVER_PRLOQO,// via pr_loqo 00038 QPB_SOLVER_CPLEX, // via cplex 00039 QPB_SOLVER_GS, // gaussian seidel 00040 QPB_SOLVER_GRADDESC // gaussian seidel 00041 }; 00042 #endif 00043 00045 class CQPBSVMLib: public CSGObject 00046 { 00047 public: 00049 CQPBSVMLib(); 00050 00059 CQPBSVMLib( 00060 float64_t* H, int32_t n, float64_t* f, int32_t m, float64_t UB=1.0); 00061 00063 int32_t solve_qp(float64_t* result, int32_t len); 00064 00069 inline void set_solver(E_QPB_SOLVER solver) 00070 { 00071 m_solver=solver; 00072 } 00073 00074 virtual ~CQPBSVMLib(); 00075 00076 protected: 00082 inline float64_t* get_col(int32_t col) 00083 { 00084 return &m_H[m_dim*col]; 00085 } 00086 00089 int32_t qpbsvm_sca( 00090 float64_t *x, float64_t *Nabla, int32_t *ptr_t, 00091 float64_t **ptr_History, int32_t verb); 00094 int32_t qpbsvm_scas( 00095 float64_t *x, float64_t *Nabla, int32_t *ptr_t, 00096 float64_t **ptr_History, int32_t verb); 00099 int32_t qpbsvm_scamv( 00100 float64_t *x, float64_t *Nabla, int32_t *ptr_t, 00101 float64_t **ptr_History, int32_t verb); 00104 int32_t qpbsvm_prloqo( 00105 float64_t *x, float64_t *Nabla, int32_t *ptr_t, 00106 float64_t **ptr_History, int32_t verb); 00109 int32_t qpbsvm_gauss_seidel( 00110 float64_t *x, float64_t *Nabla, int32_t *ptr_t, 00111 float64_t **ptr_History, int32_t verb); 00114 int32_t qpbsvm_gradient_descent( 00115 float64_t *x, float64_t *Nabla, int32_t *ptr_t, 00116 float64_t **ptr_History, int32_t verb); 00117 #ifdef USE_CPLEX 00118 00120 int32_t qpbsvm_cplex( 00121 float64_t *x, float64_t *Nabla, int32_t *ptr_t, 00122 float64_t **ptr_History, int32_t verb); 00123 #endif 00124 00126 inline virtual const char* get_name() const { return "QPBSVMLib"; } 00127 00128 protected: 00130 float64_t* m_H; 00132 float64_t* m_diag_H; 00134 int32_t m_dim; 00135 00137 float64_t* m_f; 00138 00140 float64_t m_UB; 00141 00143 int32_t m_tmax; 00145 float64_t m_tolabs; 00147 float64_t m_tolrel; 00149 float64_t m_tolKKT; 00151 E_QPB_SOLVER m_solver; 00152 }; 00153 } 00154 #endif //QPBSVMLIB_H__