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 * Copyright (c) 2007-2009 The LIBLINEAR Project. 00010 * Copyright (C) 2007-2010 Fraunhofer Institute FIRST and Max-Planck-Society 00011 */ 00012 00013 #ifndef _ONLINELIBLINEAR_H__ 00014 #define _ONLINELIBLINEAR_H__ 00015 00016 #include <shogun/lib/config.h> 00017 00018 #include <shogun/lib/SGVector.h> 00019 #include <shogun/lib/common.h> 00020 #include <shogun/base/Parameter.h> 00021 #include <shogun/machine/OnlineLinearMachine.h> 00022 00023 namespace shogun 00024 { 00027 class COnlineLibLinear : public COnlineLinearMachine 00028 { 00029 public: 00030 00032 MACHINE_PROBLEM_TYPE(PT_BINARY); 00033 00035 COnlineLibLinear(); 00036 00042 COnlineLibLinear(float64_t C); 00043 00050 COnlineLibLinear(float64_t C, CStreamingDotFeatures* traindat); 00051 00056 COnlineLibLinear(COnlineLibLinear *mch); 00057 00059 virtual ~COnlineLibLinear(); 00060 00067 virtual void set_C(float64_t c_neg, float64_t c_pos) { C1=c_neg; C2=c_pos; } 00068 00074 virtual float64_t get_C1() { return C1; } 00075 00081 float64_t get_C2() { return C2; } 00082 00088 virtual void set_bias_enabled(bool enable_bias) { use_bias=enable_bias; } 00089 00095 virtual bool get_bias_enabled() { return use_bias; } 00096 00098 virtual const char* get_name() const { return "OnlineLibLinear"; } 00099 00101 virtual void start_train(); 00102 00104 virtual void stop_train(); 00105 00115 virtual void train_example(CStreamingDotFeatures *feature, float64_t label); 00116 00121 virtual void train_one(SGVector<float32_t> ex, float64_t label); 00122 00123 private: 00125 void init(); 00126 00127 private: 00129 bool use_bias; 00131 float64_t C1; 00133 float64_t C2; 00134 00135 private: 00136 //======================================== 00137 // "local" variables used during training 00138 00139 float64_t C, d, G; 00140 float64_t QD; 00141 00142 // y and alpha for example being processed 00143 int32_t y_current; 00144 float64_t alpha_current; 00145 00146 // Cost constants 00147 float64_t Cp; 00148 float64_t Cn; 00149 00150 // PG: projected gradient, for shrinking and stopping 00151 float64_t PG; 00152 float64_t PGmax_old; 00153 float64_t PGmin_old; 00154 float64_t PGmax_new; 00155 float64_t PGmin_new; 00156 00157 // Diag is probably unnecessary 00158 float64_t diag[3]; 00159 float64_t upper_bound[3]; 00160 00161 // Objective value = v/2 00162 float64_t v; 00163 // Number of support vectors 00164 int32_t nSV; 00165 }; 00166 } 00167 #endif // _ONLINELIBLINEAR_H__