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 * Copyright (C) 2012 Soeren Sonnenburg 00008 */ 00009 00010 #ifndef _REGRESSIONLIBLINEAR_H___ 00011 #define _REGRESSIONLIBLINEAR_H___ 00012 #include <shogun/lib/config.h> 00013 #ifdef HAVE_LAPACK 00014 #include <shogun/lib/common.h> 00015 #include <shogun/features/DotFeatures.h> 00016 #include <shogun/machine/LinearMachine.h> 00017 #include <shogun/optimization/liblinear/shogun_liblinear.h> 00018 00019 namespace shogun 00020 { 00022 enum LIBLINEAR_REGRESSION_TYPE 00023 { 00025 L2R_L2LOSS_SVR, 00027 L2R_L1LOSS_SVR_DUAL, 00029 L2R_L2LOSS_SVR_DUAL 00030 }; 00031 00034 class CLibLinearRegression : public CLinearMachine 00035 { 00036 public: 00037 MACHINE_PROBLEM_TYPE(PT_REGRESSION) 00038 00039 00040 CLibLinearRegression(); 00041 00047 CLibLinearRegression(float64_t C, CDotFeatures* features, CLabels* labs); 00048 00050 virtual ~CLibLinearRegression(); 00051 00053 inline LIBLINEAR_REGRESSION_TYPE get_liblinear_regression_type() 00054 { 00055 return m_liblinear_regression_type; 00056 } 00057 00059 inline void set_liblinear_regression_type(LIBLINEAR_REGRESSION_TYPE st) 00060 { 00061 m_liblinear_regression_type=st; 00062 } 00063 00065 virtual const char* get_name() const 00066 { 00067 return "LibLinearRegression"; 00068 } 00069 00073 inline void set_C(float64_t C) 00074 { 00075 ASSERT(C>0); 00076 m_C = C; 00077 } 00078 00082 inline float64_t get_C() const { return m_C; } 00083 00088 inline void set_tube_epsilon(float64_t eps) { m_tube_epsilon=eps; } 00089 00094 inline float64_t get_tube_epsilon() { return m_tube_epsilon; } 00095 00096 00100 inline void set_epsilon(float64_t epsilon) 00101 { 00102 ASSERT(epsilon>0); 00103 m_epsilon = epsilon; 00104 } 00105 00109 inline float64_t get_epsilon() const { return m_epsilon; } 00110 00114 inline void set_use_bias(bool use_bias) 00115 { 00116 m_use_bias = use_bias; 00117 } 00121 inline bool get_use_bias() const 00122 { 00123 return m_use_bias; 00124 } 00125 00129 inline void set_max_iter(int32_t max_iter) 00130 { 00131 ASSERT(max_iter>0); 00132 m_max_iter = max_iter; 00133 } 00137 inline int32_t get_max_iter() const { return m_max_iter; } 00138 00139 protected: 00140 00142 virtual bool train_machine(CFeatures* data = NULL); 00143 00144 private: 00146 void solve_l2r_l1l2_svr(const problem *prob); 00147 00149 void init_defaults(); 00150 00152 void register_parameters(); 00153 00154 protected: 00155 00157 float64_t m_C; 00158 00160 float64_t m_epsilon; 00161 00163 float64_t m_tube_epsilon; 00164 00166 int32_t m_max_iter; 00167 00169 bool m_use_bias; 00170 00172 LIBLINEAR_REGRESSION_TYPE m_liblinear_regression_type; 00173 }; 00174 } 00175 #endif /* HAVE_LAPACK */ 00176 #endif