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) 2007-2010 Soeren Sonnenburg 00008 * Written (W) 2011 Shashwat Lal Das 00009 * Modifications (W) 2013 Thoralf Klein 00010 * Copyright (c) 2007-2009 The LIBLINEAR Project. 00011 * Copyright (C) 2007-2010 Fraunhofer Institute FIRST and Max-Planck-Society 00012 */ 00013 00014 #ifndef _ONLINELIBLINEAR_H__ 00015 #define _ONLINELIBLINEAR_H__ 00016 00017 #include <shogun/lib/config.h> 00018 00019 #include <shogun/lib/SGVector.h> 00020 #include <shogun/lib/common.h> 00021 #include <shogun/base/Parameter.h> 00022 #include <shogun/machine/OnlineLinearMachine.h> 00023 00024 namespace shogun 00025 { 00028 class COnlineLibLinear : public COnlineLinearMachine 00029 { 00030 public: 00031 00033 MACHINE_PROBLEM_TYPE(PT_BINARY); 00034 00036 COnlineLibLinear(); 00037 00043 COnlineLibLinear(float64_t C); 00044 00051 COnlineLibLinear(float64_t C, CStreamingDotFeatures* traindat); 00052 00057 COnlineLibLinear(COnlineLibLinear *mch); 00058 00060 virtual ~COnlineLibLinear(); 00061 00068 virtual void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; } 00069 00075 virtual float64_t get_C1() { return C1; } 00076 00082 float64_t get_C2() { return C2; } 00083 00089 virtual void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; } 00090 00096 virtual bool get_bias_enabled() { return use_bias; } 00097 00099 virtual const char* get_name() const { return "OnlineLibLinear"; } 00100 00102 virtual void start_train(); 00103 00105 virtual void stop_train(); 00106 00116 virtual void train_example(CStreamingDotFeatures *feature, float64_t label); 00117 00122 virtual void train_one(SGVector<float32_t> ex, float64_t label); 00123 00128 virtual void train_one(SGSparseVector<float32_t> ex, float64_t label); 00129 00130 private: 00132 void init(); 00133 00134 private: 00136 bool use_bias; 00138 float64_t C1; 00140 float64_t C2; 00141 00142 private: 00143 //======================================== 00144 // "local" variables used during training 00145 00146 float64_t C, d, G; 00147 float64_t QD; 00148 00149 // y and alpha for example being processed 00150 int32_t y_current; 00151 float64_t alpha_current; 00152 00153 // Cost constants 00154 float64_t Cp; 00155 float64_t Cn; 00156 00157 // PG: projected gradient, for shrinking and stopping 00158 float64_t PG; 00159 float64_t PGmax_old; 00160 float64_t PGmin_old; 00161 float64_t PGmax_new; 00162 float64_t PGmin_new; 00163 00164 // Diag is probably unnecessary 00165 float64_t diag[3]; 00166 float64_t upper_bound[3]; 00167 00168 // Objective value = v/2 00169 float64_t v; 00170 // Number of support vectors 00171 int32_t nSV; 00172 }; 00173 } 00174 #endif // _ONLINELIBLINEAR_H__