LibLinear.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-2010 Soeren Sonnenburg
00008  * Copyright (c) 2007-2009 The LIBLINEAR Project.
00009  * Copyright (C) 2007-2010 Fraunhofer Institute FIRST and Max-Planck-Society
00010  */
00011 
00012 #ifndef _LIBLINEAR_H___
00013 #define _LIBLINEAR_H___
00014 
00015 #include "lib/config.h"
00016 
00017 #ifdef HAVE_LAPACK
00018 #include "lib/common.h"
00019 #include "classifier/LinearClassifier.h"
00020 #include "classifier/svm/SVM_linear.h"
00021 
00022 namespace shogun
00023 {
00025     enum LIBLINEAR_SOLVER_TYPE
00026     {
00028         L2R_LR,
00030         L2R_L2LOSS_SVC_DUAL,
00032         L2R_L2LOSS_SVC,
00034         // (default since this is the standard SVM)
00035         L2R_L1LOSS_SVC_DUAL,
00037         MCSVM_CS,
00039         L1R_L2LOSS_SVC,
00041         L1R_LR
00042     };
00043 
00045 class CLibLinear : public CLinearClassifier
00046 {
00047     public:
00052         CLibLinear(LIBLINEAR_SOLVER_TYPE liblinear_solver_type);
00053 
00060         CLibLinear(
00061             float64_t C, CDotFeatures* traindat,
00062             CLabels* trainlab);
00063 
00064         virtual ~CLibLinear();
00065 
00066         inline LIBLINEAR_SOLVER_TYPE get_liblinear_solver_type()
00067         {
00068             return liblinear_solver_type;
00069         }
00070 
00071         inline void set_liblinear_solver_type(LIBLINEAR_SOLVER_TYPE st)
00072         {
00073             liblinear_solver_type=st;
00074         }
00075 
00084         virtual bool train(CFeatures* data=NULL);
00085 
00090         virtual inline EClassifierType get_classifier_type() { return CT_LIBLINEAR; }
00091 
00097         inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
00098 
00103         inline float64_t get_C1() { return C1; }
00104 
00109         inline float64_t get_C2() { return C2; }
00110 
00115         inline void set_epsilon(float64_t eps) { epsilon=eps; }
00116 
00121         inline float64_t get_epsilon() { return epsilon; }
00122 
00127         inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00128 
00133         inline bool get_bias_enabled() { return use_bias; }
00134 
00136         inline virtual const char* get_name() const { return "LibLinear"; }
00137 
00139         inline int32_t get_max_iterations()
00140         {
00141             return max_iterations;
00142         }
00143 
00145         inline void set_max_iterations(int32_t max_iter=1000)
00146         {
00147             max_iterations=max_iter;
00148         }
00149 
00150     private:
00151         void train_one(const problem *prob, const parameter *param, double Cp, double Cn);
00152         void solve_l2r_l1l2_svc(
00153             const problem *prob, double eps, double Cp, double Cn, LIBLINEAR_SOLVER_TYPE st);
00154 
00155         void solve_l1r_l2_svc(problem *prob_col, double eps, double Cp, double Cn);
00156         void solve_l1r_lr(const problem *prob_col, double eps, double Cp, double Cn);
00157 
00158 
00159     protected:
00161         float64_t C1;
00163         float64_t C2;
00165         bool use_bias;
00167         float64_t epsilon;
00169         int32_t max_iterations;
00170 
00172         LIBLINEAR_SOLVER_TYPE liblinear_solver_type;
00173 };
00174 }
00175 #endif //HAVE_LAPACK
00176 #endif //_LIBLINEAR_H___
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation