SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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 <shogun/lib/config.h>
00016 
00017 #include <shogun/lib/common.h>
00018 #include <shogun/base/Parameter.h>
00019 #include <shogun/machine/LinearMachine.h>
00020 #include <shogun/optimization/liblinear/shogun_liblinear.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         L1R_L2LOSS_SVC,
00039         L1R_LR,
00041         L2R_LR_DUAL
00042     };
00043 
00045 class CLibLinear : public CLinearMachine
00046 {
00047     public:
00048         MACHINE_PROBLEM_TYPE(PT_BINARY)
00049 
00050         
00051         CLibLinear();
00052 
00057         CLibLinear(LIBLINEAR_SOLVER_TYPE liblinear_solver_type);
00058 
00065         CLibLinear(
00066             float64_t C, CDotFeatures* traindat,
00067             CLabels* trainlab);
00068 
00070         virtual ~CLibLinear();
00071 
00075         inline LIBLINEAR_SOLVER_TYPE get_liblinear_solver_type()
00076         {
00077             return liblinear_solver_type;
00078         }
00079 
00084         inline void set_liblinear_solver_type(LIBLINEAR_SOLVER_TYPE st)
00085         {
00086             liblinear_solver_type=st;
00087         }
00088 
00093         virtual EMachineType get_classifier_type() { return CT_LIBLINEAR; }
00094 
00100         inline void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; }
00101 
00106         inline float64_t get_C1() { return C1; }
00107 
00112         inline float64_t get_C2() { return C2; }
00113 
00118         inline void set_epsilon(float64_t eps) { epsilon=eps; }
00119 
00124         inline float64_t get_epsilon() { return epsilon; }
00125 
00130         inline void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; }
00131 
00136         inline bool get_bias_enabled() { return use_bias; }
00137 
00139         virtual const char* get_name() const { return "LibLinear"; }
00140 
00142         inline int32_t get_max_iterations()
00143         {
00144             return max_iterations;
00145         }
00146 
00148         inline void set_max_iterations(int32_t max_iter=1000)
00149         {
00150             max_iterations=max_iter;
00151         }
00152 
00154         void set_linear_term(const SGVector<float64_t> linear_term);
00155 
00157         SGVector<float64_t> get_linear_term();
00158 
00160         void init_linear_term();
00161 
00162     protected:
00171         virtual bool train_machine(CFeatures* data=NULL);
00172 
00173     private:
00175         void init();
00176 
00177         void train_one(const liblinear_problem *prob, const liblinear_parameter *param, double Cp, double Cn);
00178         void solve_l2r_l1l2_svc(
00179             const liblinear_problem *prob, double eps, double Cp, double Cn, LIBLINEAR_SOLVER_TYPE st);
00180 
00181         void solve_l1r_l2_svc(liblinear_problem *prob_col, double eps, double Cp, double Cn);
00182         void solve_l1r_lr(const liblinear_problem *prob_col, double eps, double Cp, double Cn);
00183         void solve_l2r_lr_dual(const liblinear_problem *prob, double eps, double Cp, double Cn);
00184 
00185 
00186     protected:
00188         float64_t C1;
00190         float64_t C2;
00192         bool use_bias;
00194         float64_t epsilon;
00196         int32_t max_iterations;
00197 
00199         SGVector<float64_t> m_linear_term;
00200 
00202         LIBLINEAR_SOLVER_TYPE liblinear_solver_type;
00203 };
00204 
00205 } /* namespace shogun  */
00206 
00207 #endif //_LIBLINEAR_H___
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation